Skip to content

Commit

Permalink
openvpn: use ifctl in link up/down scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
fichtner committed Oct 18, 2022
1 parent efd61d3 commit 14e14e5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/etc/inc/plugins.inc.d/openvpn/ovpn-linkdown
Expand Up @@ -2,5 +2,5 @@

/sbin/pfctl -i ${1} -Fs

/bin/rm -f /tmp/${1}_router
/bin/rm -f /tmp/${1}_routerv6
/usr/local/sbin/ifctl -4ci ${1}
/usr/local/sbin/ifctl -6ci ${1}
20 changes: 13 additions & 7 deletions src/etc/inc/plugins.inc.d/openvpn/ovpn-linkup
@@ -1,26 +1,32 @@
#!/bin/sh

ROUTERV4=
ROUTERV6=

if [ -n "${route_vpn_gateway}" ]; then
/bin/echo ${route_vpn_gateway} > /tmp/${1}_router
ROUTERV4="-a ${route_vpn_gateway}"
elif [ -n "${ifconfig_remote}" ]; then
/bin/echo ${ifconfig_remote} > /tmp/${1}_router
ROUTERV4="-a ${ifconfig_remote}"
elif [ -n "${ifconfig_local}" ]; then
# XXX: We can't reliably determine the tunnels endpoint, other than parsing ifconfig.
# Use our standard parser to request the tunnels other end. Eventually we could pass this to configd if
# needed, but openvpn has elevated rights anyway at the moment.
/usr/local/etc/inc/plugins.inc.d/openvpn/tunnel_endpoint.php ${1} > /tmp/${1}_router
ROUTERV4="-a $(/usr/local/etc/inc/plugins.inc.d/openvpn/tunnel_endpoint.php ${1})"
elif [ "${dev_type}" = "tun" -a -n "${5}" ]; then
/bin/echo ${5} > /tmp/${1}_router
ROUTERV4="-a ${5}"
fi

if [ -n "${route_ipv6_gateway_1}" ]; then
/bin/echo ${route_ipv6_gateway_1} > /tmp/${1}_routerv6
ROUTERV6="-a ${route_ipv6_gateway_1}"
elif [ -n "${ifconfig_ipv6_remote}" ]; then
/bin/echo ${ifconfig_ipv6_remote} > /tmp/${1}_routerv6
ROUTERV6="-a ${ifconfig_ipv6_remote}"
elif [ -n "${ifconfig_ipv6_local}" ]; then
/bin/echo ${ifconfig_ipv6_local} > /tmp/${1}_routerv6
ROUTERV6="-a ${ifconfig_ipv6_local}"
fi

/usr/local/sbin/ifctl -4rd ${ROUTERV4}
/usr/local/sbin/ifctl -6rd ${ROUTERV6}

/usr/local/sbin/configctl -d interface newip ${1}

exit 0

0 comments on commit 14e14e5

Please sign in to comment.