From 5adfd6bf126e28d1d007afa49173e6bfd28ecc69 Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Wed, 24 Feb 2016 17:25:47 +0100 Subject: [PATCH] interfaces: replace netgraph functions with portable alternatives --- Makefile | 1 + src/etc/inc/interfaces.inc | 10 +++++----- src/etc/inc/interfaces.lib.inc | 17 ++++++++++++++++- src/etc/inc/plugins.inc.d/vpn.inc | 6 +++--- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index a1ed7efb6..a160cc181 100644 --- a/Makefile +++ b/Makefile @@ -67,6 +67,7 @@ CORE_DEPENDS?= apinger \ miniupnpd \ mpd4 \ mpd5 \ + ngattach \ ntp \ openssh-portable \ openvpn \ diff --git a/src/etc/inc/interfaces.inc b/src/etc/inc/interfaces.inc index 67ec919ec..551e82a1d 100644 --- a/src/etc/inc/interfaces.inc +++ b/src/etc/inc/interfaces.inc @@ -202,7 +202,7 @@ function interface_netgraph_needed($interface = "wan") if (!$found) { $realif = get_real_interface($interface); - mwexecf('/usr/sbin/ngctl msg %s: detach', array($realif)); + legacy_netgraph_detach($realif); } } @@ -293,7 +293,7 @@ function interface_vlan_configure(&$vlan) } else { $tmpvlanif = legacy_interface_create('vlan'); legacy_interface_rename($tmpvlanif, $vlanif); - mwexecf('/usr/sbin/ngctl name %s: %s', array($tmpvlanif, $vlanif)); + legacy_netgraph_rename($tmpvlanif, $vlanif); } legacy_vlan_tag($vlanif, $if, $tag); @@ -338,8 +338,8 @@ function interface_qinq_configure(&$vlan, $fd = null) /* make sure the parent is converted to ng_vlan(4) and is up */ interfaces_bring_up($qinqif); + legacy_netgraph_attach($qinqif); - pfSense_ngctl_attach(".", $qinqif); if (!empty($vlanif) && does_interface_exist($vlanif)) { fwrite($fd, "shutdown {$qinqif}qinq:\n"); exec("/usr/sbin/ngctl msg {$qinqif}qinq: gettable", $result); @@ -1608,7 +1608,7 @@ function interface_ppps_configure($interface) case "pppoe": /* Bring the parent interface up */ interfaces_bring_up($port); - pfSense_ngctl_attach(".", $port); + legacy_netgraph_attach($port); /* Enable setautosrc to automatically change mac address if parent interface's changes */ mwexecf('/usr/sbin/ngctl msg %s: setautosrc 1', array($port)); break; @@ -1631,7 +1631,7 @@ function interface_ppps_configure($interface) log_error(sprintf(gettext('Could not get a PPTP/L2TP Remote IP address from %s for %s in interfaces_ppps_configure.'), $dhcp_gateway, $gway)); return 0; } - pfSense_ngctl_attach(".", $port); + legacy_netgraph_attach($port); break; case "ppp": if (!file_exists("{$port}")) { diff --git a/src/etc/inc/interfaces.lib.inc b/src/etc/inc/interfaces.lib.inc index dd7f02a2b..aa83ab82b 100644 --- a/src/etc/inc/interfaces.lib.inc +++ b/src/etc/inc/interfaces.lib.inc @@ -1,7 +1,7 @@ + Copyright (c) 2015-2016 Franco Fichtner All rights reserved. Redistribution and use in source and binary forms, with or without @@ -199,3 +199,18 @@ function legacy_interface_details($intf) } return $result; } + +function legacy_netgraph_attach($ifs) +{ + mwexecf('/usr/local/sbin/ngattach %s', array($ifs)); +} + +function legacy_netgraph_detach($ifs) +{ + mwexecf('/usr/sbin/ngctl msg %s: detach', array($ifs)); +} + +function legacy_netgraph_rename($tmpifs, $ifs) +{ + mwexecf('/usr/sbin/ngctl name %s: %s', array($tmpifs, $ifs)); +} diff --git a/src/etc/inc/plugins.inc.d/vpn.inc b/src/etc/inc/plugins.inc.d/vpn.inc index 4c3785e9b..b82fbdc67 100644 --- a/src/etc/inc/plugins.inc.d/vpn.inc +++ b/src/etc/inc/plugins.inc.d/vpn.inc @@ -310,7 +310,7 @@ EOD; chmod('/var/etc/pptp-vpn/mpd.secret', 0600); /* fixed to WAN elsewhere, no need to extend, but at least make it work */ - pfSense_ngctl_attach('.', get_real_interface('wan')); + legacy_netgraph_attach(get_real_interface('wan')); mwexec('/usr/local/sbin/mpd4 -b -d /var/etc/pptp-vpn -p /var/run/pptp-vpn.pid -s pptps pptps'); @@ -557,7 +557,7 @@ EOD; killbypid("/var/run/pppoe{$pppoecfg['pppoeid']}-vpn.pid"); - pfSense_ngctl_attach(".", $pppoe_interface); + legacy_netgraph_attach($pppoe_interface); mwexec("/usr/local/sbin/mpd4 -b -d /var/etc/pppoe{$pppoecfg['pppoeid']}-vpn -p /var/run/pppoe{$pppoecfg['pppoeid']}-vpn.pid -s poes poes"); @@ -747,7 +747,7 @@ EOD; unset($mpdsecret); chmod('/var/etc/l2tp-vpn/mpd.secret', 0600); - pfSense_ngctl_attach('.', get_real_interface($l2tpcfg['interface'])); + legacy_netgraph_attach(get_real_interface($l2tpcfg['interface'])); mwexec('/usr/local/sbin/mpd4 -b -d /var/etc/l2tp-vpn -p /var/run/l2tp-vpn.pid -s l2tps l2tps');