Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 309385 - net-misc/openvpn-2.1_rc15 wont allow usage of bridge in default setting
Summary: net-misc/openvpn-2.1_rc15 wont allow usage of bridge in default setting
Status: RESOLVED TEST-REQUEST
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: x86 Linux
: High normal (vote)
Assignee: William Hubbs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-03-14 16:28 UTC by niv
Modified: 2021-11-11 13:31 UTC (History)
3 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
openvpn init.d and up.sh patch to allow auto adding to bridge (openvpn.patch,4.60 KB, patch)
2010-11-23 23:44 UTC, niv
Details | Diff
openvpn init.d and up.sh patch to allow auto adding to bridge (openvpn.patch,3.94 KB, patch)
2010-11-24 01:14 UTC, niv
Details | Diff
openvpn init.d and up.sh patch to allow auto adding to bridge (openvpn.patch,5.50 KB, patch)
2010-11-24 01:28 UTC, niv
Details | Diff
patching openvpn files to add and remove tap device to bridge (openvpn.patch,5.30 KB, text/plain)
2011-01-08 18:22 UTC, niv
Details
patchs to add openvpn device to bridge (openvpn.patch,5.35 KB, patch)
2011-01-09 20:53 UTC, niv
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description niv 2010-03-14 16:28:08 UTC
Problem: when setting up openvpn to act as server and bridge the device, no communication is transmitted over the vpn channel.

looking at /var/log/messages I see this:
[ 3516.124757] device tap0 entered promiscuous mode
but these lines are missing:
                br0: port 2(tap0) entering listening state
[171340.112008] tap0: no IPv6 routers present
[171344.521010] br0: port 2(tap0) entering learning state
[171359.521007] br0: topology change detected, propagating
[171359.521015] br0: port 2(tap0) entering forwarding state


/etc/init.d/openvpn line 96 :
# Warn about the inability to change ip/route/dns information when
# dropping privs
		if grep -q "^[ \t]*user[ \t].*" "${VPNCONF}" ; then
			ewarn "WARNING: You are dropping root privileges!"
			ewarn "As such openvpn may not be able to change ip, routing"
			ewarn "or DNS configuration."
		fi
	else
		# So we're a server. Run as openvpn unless otherwise specified
		grep -q "^[ \t]*user[ \t].*" "${VPNCONF}" || args="${args} --user openvpn"
		grep -q "^[ \t]*group[ \t].*" "${VPNCONF}" || args="${args} --group openvpn"

so unless the user option appears in openvpn config it will start with an unprivileged user, and the tap device never goes on to being active.

I suggest to change the warning, or use "user=root" by default when used as bridge.
Comment 1 Dirkjan Ochtman (RETIRED) gentoo-dev 2010-08-23 14:24:37 UTC
So any suggestion on what the new warning should be?
Comment 2 niv 2010-11-14 22:53:53 UTC
(In reply to comment #1)
> So any suggestion on what the new warning should be?
> 

--- /etc/init.d/openvpn.orig 2010-11-15 00:34:44.000000000 +0200
+++ /etc/init.d/openvpn 2010-11-15 00:34:20.000000000 +0200
@@ -105,6 +105,11 @@
# So we're a server. Run as openvpn unless otherwise specified
grep -q "^[ ]*user[ ].*" "${VPNCONF}" || args="${args} --user openvpn"
grep -q "^[ ]*group[ ].*" "${VPNCONF}" || args="${args} --group openvpn"
+ einfo "niv changed these args: ${args}"
+ #args="${args} --up-delay --up-restart"
+ args="${args} --script-security 2"
+ args="${args} --up /etc/openvpn/up.sh"
+ args="${args} --down-pre --down /etc/openvpn/down.sh"
fi 

# Ensure that our scripts get the PEER_DNS variable

then create /etc/openvpn/openvpn.SRV-up.sh :

#!/bin/bash
sleep 2
ifconfig tap0 0.0.0.0
brctl addif br0 tap0
Comment 3 niv 2010-11-14 23:29:48 UTC
but this seem better:
--- /tmp/up.sh.orig	2010-11-15 01:27:20.000000000 +0200
+++ /tmp/up.sh	2010-11-15 01:26:55.000000000 +0200
@@ -60,6 +60,10 @@
 	fi
 fi
 
+# in case openvpn is in bridge mode bridge it to the appropriate bridge
+if ! grep -q "^[ 	]*dev[ 	].*tap0" "${VPNCONF}"
+	/sbin/brctl addif ${BRIDGE} ${DEVICE}
+fi
 # Below section is Gentoo specific
 # Quick summary - our init scripts are re-entrant and set the SVCNAME env var
 # as we could have >1 openvpn service


and then add these lines in /etc/conf.d/openvpn.SRV :
BRIDGE="br0"
DEVICE="tap0"
Comment 4 niv 2010-11-23 23:44:39 UTC
Created attachment 255269 [details, diff]
openvpn init.d and up.sh patch to allow auto adding to bridge
Comment 5 niv 2010-11-24 01:14:17 UTC
Created attachment 255273 [details, diff]
openvpn init.d and up.sh patch to allow auto adding to bridge

still two issues to mend in this patch, to make it perfect
Comment 6 niv 2010-11-24 01:28:18 UTC
Created attachment 255275 [details, diff]
openvpn init.d and up.sh patch to allow auto adding to bridge
Comment 7 Marcel Pennewiß 2010-11-24 05:22:30 UTC
> so unless the user option appears in openvpn config it will start with an
> unprivileged user, and the tap device never goes on to being active.

We're using OpenVPN with tap0/tap1 in a bridge - we just create the bridge before OpenVPN gets started. Maybe this could be a better approach?

/etc/conf.d/net
#VPN
bridge_vpn0="tap0 tap1"
config_vpn0=( "192.168.1.253 broadcast 192.168.1.255 netmask 255.255.255.0"
              "ABCD:EFAB:CDEF:ABCD:1/64"
              "fe80::253/64")

preup() {
  if [[ "${IFACE}" == "vpn0" ]]; then
        /usr/sbin/openvpn --dev tap0 --mktun
        /usr/sbin/openvpn --dev tap1 --mktun
  fi
}

postup() {
  if [[ "${IFACE}" == "vpn0" ]]; then
        echo 1 >/proc/sys/net/ipv4/conf/vpn0/forwarding
        echo 1 >/proc/sys/net/ipv6/conf/vpn0/forwarding
  fi
}

predown() {
  if [[ "${IFACE}" == "vpn0" ]]; then
        echo 0 >/proc/sys/net/ipv4/conf/vpn0/forwarding
        echo 0 >/proc/sys/net/ipv6/conf/vpn0/forwarding
  fi
}

postdown() {
  if [[ "${IFACE}" == "vpn0" ]]; then
        /usr/sbin/openvpn --dev tap0 --rmtun
        /usr/sbin/openvpn --dev tap1 --rmtun
  fi
}
Comment 8 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2010-12-15 07:28:02 UTC
openvpn shouldn't touching the interfaces managed by the normal gentoo network scripts. Specifically, it should NOT be adding interfaces to the bridge itself.

Does this sound like a reasonable order:
1. net creates bridge
2. openvpn starts and creates tapX devices.
3. net adds tapX devices to bridge

If it's more intricate than that, we should probably integrate more of openvpn into the network scripts.
Comment 9 Marcel Pennewiß 2010-12-15 08:01:00 UTC
(In reply to comment #8)
> openvpn shouldn't touching the interfaces managed by the normal gentoo network
> scripts. Specifically, it should NOT be adding interfaces to the bridge
> itself.

Full ACK.

> Does this sound like a reasonable order:
> 1. net creates bridge
> 2. openvpn starts and creates tapX devices.
> 3. net adds tapX devices to bridge

IMHO net supports everything needed...
You can also create tun/tap-devices in a more sofisticated way as using preup/postdown.

See /etc/conf.d/net.example...
#-----------------------------------------------------------------------------
# TUN/TAP
# For TUN/TAP support emerge net-misc/openvpn or sys-apps/usermode-utilities
#
# You must specify if we're a tun or tap device. Then you can give it any
# name you like - such as vpn
#tuntap_vpn="tun"
#config_vpn=( "192.168.0.1/24")

# Or stick wit the generic names - like tap0
#tuntap_tap0="tap"

Everything to create a bridged tap-interface is available. Why do you want do add the tapX to the bridge after openvpn was started?

IMHO the right order should be:
 
1. net creates tapX
2. net creates bridge
3. net adds tapX devices to bridge
4. openvpn starts and creates tapX devices.
 
> If it's more intricate than that, we should probably integrate more of openvpn
> into the network scripts.

Maybe, but i believe this is not necessary.
Comment 10 niv 2011-01-08 18:22:32 UTC
Created attachment 259305 [details]
patching openvpn files to add and remove tap device to bridge

/etc/conf.d/openvpn file should have this:
BRIDGE="br0"

in case bridge is br0
Comment 11 niv 2011-01-09 20:53:40 UTC
Created attachment 259416 [details, diff]
patchs to add openvpn device to bridge
Comment 12 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2012-02-09 10:02:28 UTC
From the latest patches, those are for openvpn only, no openrc changes needed.
dropping openrc from this bug.
Comment 13 Manuel Rüger (RETIRED) gentoo-dev 2016-09-01 12:40:34 UTC
This bug has gotten really old, can you please retry with openvpn-2.3.12 and see if the issue still exists?