summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/conf_mode/interfaces-bonding.py22
-rwxr-xr-xsrc/conf_mode/interfaces-bridge.py22
-rwxr-xr-xsrc/conf_mode/interfaces-ethernet.py22
-rwxr-xr-xsrc/conf_mode/interfaces-pseudo-ethernet.py22
-rwxr-xr-xsrc/conf_mode/interfaces-tunnel.py36
-rwxr-xr-xsrc/conf_mode/interfaces-wireless.py22
-rw-r--r--src/etc/dhcp/dhclient-exit-hooks.d/vyatta-dhclient-hook7
-rwxr-xr-xsrc/op_mode/reset_vpn.py68
8 files changed, 59 insertions, 162 deletions
diff --git a/src/conf_mode/interfaces-bonding.py b/src/conf_mode/interfaces-bonding.py
index 32aa2826b..fd1f218d1 100755
--- a/src/conf_mode/interfaces-bonding.py
+++ b/src/conf_mode/interfaces-bonding.py
@@ -399,32 +399,20 @@ def apply(bond):
# update interface description used e.g. within SNMP
b.set_alias(bond['description'])
- # get DHCP config dictionary and update values
- opt = b.get_dhcp_options()
-
if bond['dhcp_client_id']:
- opt['client_id'] = bond['dhcp_client_id']
+ b.dhcp.v4.options['client_id'] = bond['dhcp_client_id']
if bond['dhcp_hostname']:
- opt['hostname'] = bond['dhcp_hostname']
+ b.dhcp.v4.options['hostname'] = bond['dhcp_hostname']
if bond['dhcp_vendor_class_id']:
- opt['vendor_class_id'] = bond['dhcp_vendor_class_id']
-
- # store DHCP config dictionary - used later on when addresses are aquired
- b.set_dhcp_options(opt)
-
- # get DHCPv6 config dictionary and update values
- opt = b.get_dhcpv6_options()
+ b.dhcp.v4.options['vendor_class_id'] = bond['dhcp_vendor_class_id']
if bond['dhcpv6_prm_only']:
- opt['dhcpv6_prm_only'] = True
+ b.dhcp.v6.options['dhcpv6_prm_only'] = True
if bond['dhcpv6_temporary']:
- opt['dhcpv6_temporary'] = True
-
- # store DHCPv6 config dictionary - used later on when addresses are required
- b.set_dhcpv6_options(opt)
+ b.dhcp.v6.options['dhcpv6_temporary'] = True
# ignore link state changes
b.set_link_detect(bond['disable_link_detect'])
diff --git a/src/conf_mode/interfaces-bridge.py b/src/conf_mode/interfaces-bridge.py
index 79247ee51..93c6db97e 100755
--- a/src/conf_mode/interfaces-bridge.py
+++ b/src/conf_mode/interfaces-bridge.py
@@ -300,32 +300,20 @@ def apply(bridge):
# update interface description used e.g. within SNMP
br.set_alias(bridge['description'])
- # get DHCP config dictionary and update values
- opt = br.get_dhcp_options()
-
if bridge['dhcp_client_id']:
- opt['client_id'] = bridge['dhcp_client_id']
+ br.dhcp.v4.options['client_id'] = bridge['dhcp_client_id']
if bridge['dhcp_hostname']:
- opt['hostname'] = bridge['dhcp_hostname']
+ br.dhcp.v4.options['hostname'] = bridge['dhcp_hostname']
if bridge['dhcp_vendor_class_id']:
- opt['vendor_class_id'] = bridge['dhcp_vendor_class_id']
-
- # store DHCPv6 config dictionary - used later on when addresses are aquired
- br.set_dhcp_options(opt)
-
- # get DHCPv6 config dictionary and update values
- opt = br.get_dhcpv6_options()
+ br.dhcp.v4.options['vendor_class_id'] = bridge['dhcp_vendor_class_id']
if bridge['dhcpv6_prm_only']:
- opt['dhcpv6_prm_only'] = True
+ br.dhcp.v6.options['dhcpv6_prm_only'] = True
if bridge['dhcpv6_temporary']:
- opt['dhcpv6_temporary'] = True
-
- # store DHCPv6 config dictionary - used later on when addresses are aquired
- br.set_dhcpv6_options(opt)
+ br.dhcp.v6.options['dhcpv6_temporary'] = True
# assign/remove VRF
br.set_vrf(bridge['vrf'])
diff --git a/src/conf_mode/interfaces-ethernet.py b/src/conf_mode/interfaces-ethernet.py
index 15e9b4185..5a977d797 100755
--- a/src/conf_mode/interfaces-ethernet.py
+++ b/src/conf_mode/interfaces-ethernet.py
@@ -301,32 +301,20 @@ def apply(eth):
# update interface description used e.g. within SNMP
e.set_alias(eth['description'])
- # get DHCP config dictionary and update values
- opt = e.get_dhcp_options()
-
if eth['dhcp_client_id']:
- opt['client_id'] = eth['dhcp_client_id']
+ e.dhcp.v4.options['client_id'] = eth['dhcp_client_id']
if eth['dhcp_hostname']:
- opt['hostname'] = eth['dhcp_hostname']
+ e.dhcp.v4.options['hostname'] = eth['dhcp_hostname']
if eth['dhcp_vendor_class_id']:
- opt['vendor_class_id'] = eth['dhcp_vendor_class_id']
-
- # store DHCP config dictionary - used later on when addresses are aquired
- e.set_dhcp_options(opt)
-
- # get DHCPv6 config dictionary and update values
- opt = e.get_dhcpv6_options()
+ e.dhcp.v4.options['vendor_class_id'] = eth['dhcp_vendor_class_id']
if eth['dhcpv6_prm_only']:
- opt['dhcpv6_prm_only'] = True
+ e.dhcp.v6.options['dhcpv6_prm_only'] = True
if eth['dhcpv6_temporary']:
- opt['dhcpv6_temporary'] = True
-
- # store DHCPv6 config dictionary - used later on when addresses are aquired
- e.set_dhcpv6_options(opt)
+ e.dhcp.v6.options['dhcpv6_temporary'] = True
# ignore link state changes
e.set_link_detect(eth['disable_link_detect'])
diff --git a/src/conf_mode/interfaces-pseudo-ethernet.py b/src/conf_mode/interfaces-pseudo-ethernet.py
index ce3d472c4..655006146 100755
--- a/src/conf_mode/interfaces-pseudo-ethernet.py
+++ b/src/conf_mode/interfaces-pseudo-ethernet.py
@@ -281,32 +281,20 @@ def apply(peth):
# update interface description used e.g. within SNMP
p.set_alias(peth['description'])
- # get DHCP config dictionary and update values
- opt = p.get_dhcp_options()
-
if peth['dhcp_client_id']:
- opt['client_id'] = peth['dhcp_client_id']
+ p.dhcp.v4.options['client_id'] = peth['dhcp_client_id']
if peth['dhcp_hostname']:
- opt['hostname'] = peth['dhcp_hostname']
+ p.dhcp.v4.options['hostname'] = peth['dhcp_hostname']
if peth['dhcp_vendor_class_id']:
- opt['vendor_class_id'] = peth['dhcp_vendor_class_id']
-
- # store DHCP config dictionary - used later on when addresses are aquired
- p.set_dhcp_options(opt)
-
- # get DHCPv6 config dictionary and update values
- opt = p.get_dhcpv6_options()
+ p.dhcp.v4.options['vendor_class_id'] = peth['dhcp_vendor_class_id']
if peth['dhcpv6_prm_only']:
- opt['dhcpv6_prm_only'] = True
+ p.dhcp.v6.options['dhcpv6_prm_only'] = True
if peth['dhcpv6_temporary']:
- opt['dhcpv6_temporary'] = True
-
- # store DHCPv6 config dictionary - used later on when addresses are aquired
- p.set_dhcpv6_options(opt)
+ p.dhcp.v6.options['dhcpv6_temporary'] = True
# ignore link state changes
p.set_link_detect(peth['disable_link_detect'])
diff --git a/src/conf_mode/interfaces-tunnel.py b/src/conf_mode/interfaces-tunnel.py
index 28b1cf60f..19538da72 100755
--- a/src/conf_mode/interfaces-tunnel.py
+++ b/src/conf_mode/interfaces-tunnel.py
@@ -26,41 +26,7 @@ from vyos.ifconfig.afi import IP4, IP6
from vyos.configdict import list_diff
from vyos.validate import is_ipv4, is_ipv6
from vyos import ConfigError
-
-
-class FixedDict(dict):
- """
- FixedDict: A dictionnary not allowing new keys to be created after initialisation.
-
- >>> f = FixedDict(**{'count':1})
- >>> f['count'] = 2
- >>> f['king'] = 3
- File "...", line ..., in __setitem__
- raise ConfigError(f'Option "{k}" has no defined default')
- """
- def __init__ (self, **options):
- self._allowed = options.keys()
- super().__init__(**options)
-
- def __setitem__ (self, k, v):
- """
- __setitem__ is a builtin which is called by python when setting dict values:
- >>> d = dict()
- >>> d['key'] = 'value'
- >>> d
- {'key': 'value'}
-
- is syntaxic sugar for
-
- >>> d = dict()
- >>> d.__setitem__('key','value')
- >>> d
- {'key': 'value'}
- """
- if k not in self._allowed:
- raise ConfigError(f'Option "{k}" has no defined default')
- super().__setitem__(k, v)
-
+from vyos.dicts import FixedDict
class ConfigurationState(Config):
"""
diff --git a/src/conf_mode/interfaces-wireless.py b/src/conf_mode/interfaces-wireless.py
index 138f27755..07c4537b4 100755
--- a/src/conf_mode/interfaces-wireless.py
+++ b/src/conf_mode/interfaces-wireless.py
@@ -722,32 +722,20 @@ def apply(wifi):
# update interface description used e.g. within SNMP
w.set_alias(wifi['description'])
- # get DHCP config dictionary and update values
- opt = w.get_dhcp_options()
-
if wifi['dhcp_client_id']:
- opt['client_id'] = wifi['dhcp_client_id']
+ w.dhcp.v4.options['client_id'] = wifi['dhcp_client_id']
if wifi['dhcp_hostname']:
- opt['hostname'] = wifi['dhcp_hostname']
+ w.dhcp.v4.options['hostname'] = wifi['dhcp_hostname']
if wifi['dhcp_vendor_class_id']:
- opt['vendor_class_id'] = wifi['dhcp_vendor_class_id']
-
- # store DHCP config dictionary - used later on when addresses are aquired
- w.set_dhcp_options(opt)
-
- # get DHCPv6 config dictionary and update values
- opt = w.get_dhcpv6_options()
+ w.dhcp.v4.options['vendor_class_id'] = wifi['dhcp_vendor_class_id']
if wifi['dhcpv6_prm_only']:
- opt['dhcpv6_prm_only'] = True
+ w.dhcp.v6.options['dhcpv6_prm_only'] = True
if wifi['dhcpv6_temporary']:
- opt['dhcpv6_temporary'] = True
-
- # store DHCPv6 config dictionary - used later on when addresses are aquired
- w.set_dhcpv6_options(opt)
+ w.dhcp.v6.options['dhcpv6_temporary'] = True
# ignore link state changes
w.set_link_detect(wifi['disable_link_detect'])
diff --git a/src/etc/dhcp/dhclient-exit-hooks.d/vyatta-dhclient-hook b/src/etc/dhcp/dhclient-exit-hooks.d/vyatta-dhclient-hook
index dcd06644f..eeb8b0782 100644
--- a/src/etc/dhcp/dhclient-exit-hooks.d/vyatta-dhclient-hook
+++ b/src/etc/dhcp/dhclient-exit-hooks.d/vyatta-dhclient-hook
@@ -22,8 +22,13 @@
# To enable this script set the following variable to "yes"
RUN="yes"
+proto=""
+if [[ $reason =~ (REBOOT6|INIT6|EXPIRE6|RELEASE6|STOP6|INFORM6|BOUND6|REBIND6|DELEGATED6) ]]; then
+ proto="v6"
+fi
+
if [ "$RUN" = "yes" ]; then
- LOG=/var/lib/dhcp/dhclient_"$interface"_lease
+ LOG=/var/lib/dhcp/dhclient_"$interface"."$proto"lease
echo `date` > $LOG
for i in reason interface new_expiry new_dhcp_lease_time medium \
diff --git a/src/op_mode/reset_vpn.py b/src/op_mode/reset_vpn.py
index 15908ee77..3a0ad941c 100755
--- a/src/op_mode/reset_vpn.py
+++ b/src/op_mode/reset_vpn.py
@@ -14,63 +14,49 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-# import os
import sys
import argparse
-#import re
from vyos.util import run
-from vyos.util import DEVNULL
-pptp_base = '/usr/bin/accel-cmd -p 2003 terminate {} {}'
-l2tp_base = '/usr/bin/accel-cmd -p 2004 terminate {} {}'
+cmd_dict = {
+ 'cmd_base' : '/usr/bin/accel-cmd -p {} terminate {} {}',
+ 'vpn_types' : {
+ 'pptp' : 2003,
+ 'l2tp' : 2004,
+ 'sstp' : 2005
+ }
+}
def terminate_sessions(username='', interface='', protocol=''):
- if username:
- if username == "all_users":
- if protocol == "pptp":
- pptp_cmd = pptp_base.format('all','')
- run(pptp_cmd)
- return
- elif protocol == "l2tp":
- l2tp_cmd = l2tp_base.format('all', '')
- run(l2tp_cmd)
- return
- else:
- pptp_cmd = pptp_base.format('all', '')
- run(pptp_cmd)
- l2tp_cmd = l2tp_base.format('all', '')
- run(l2tp_cmd)
- return
- if protocol == "pptp":
- pptp_cmd = pptp_base.format('username', username)
- run(pptp_cmd)
- return
- elif protocol == "l2tp":
- l2tp_cmd = l2tp_base.format('username', username)
- run(l2tp_cmd)
- return
+ # Reset vpn connections by username
+ if protocol in cmd_dict['vpn_types']:
+ if username == "all_users":
+ run(cmd_dict['cmd_base'].format(cmd_dict['vpn_types'][protocol], 'all', ''))
else:
- pptp_cmd = pptp_base.format('username', username)
- run(pptp_cmd)
- l2tp_cmd = l2tp_base.format('username', username)
- run(l2tp_cmd)
- return
+ run(cmd_dict['cmd_base'].format(cmd_dict['vpn_types'][protocol], 'username', username))
+
+ # Reset vpn connections by ifname
+ elif interface:
+ for proto in cmd_dict['vpn_types']:
+ run(cmd_dict['cmd_base'].format(cmd_dict['vpn_types'][proto], 'if', interface))
- # rewrite `terminate by interface` if pptp will have pptp%d interface naming
- if interface:
- pptp_cmd = pptp_base.format('if', interface)
- run(pptp_cmd)
- l2tp_cmd = l2tp_base.format('if', interface)
- run(l2tp_cmd)
+ elif username:
+ # Reset all vpn connections
+ if username == "all_users":
+ for proto in cmd_dict['vpn_types']:
+ run(cmd_dict['cmd_base'].format(cmd_dict['vpn_types'][proto], 'all', ''))
+ else:
+ for proto in cmd_dict['vpn_types']:
+ run(cmd_dict['cmd_base'].format(cmd_dict['vpn_types'][proto], 'username', username))
def main():
#parese args
parser = argparse.ArgumentParser()
parser.add_argument('--username', help='Terminate by username (all_users used for disconnect all users)', required=False)
parser.add_argument('--interface', help='Terminate by interface', required=False)
- parser.add_argument('--protocol', help='Set protocol (pptp|l2tp)', required=False)
+ parser.add_argument('--protocol', help='Set protocol (pptp|l2tp|sstp)', required=False)
args = parser.parse_args()
if args.username or args.interface: