diff options
author | Christian Poessinger <christian@poessinger.com> | 2020-03-05 17:23:26 +0100 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2020-03-05 17:23:26 +0100 |
commit | e8fc4cb5240fb637d25ea03e08df6c0267d052cf (patch) | |
tree | c752bab404e6cb82ddcceb0d191a93191e9255fb /src/conf_mode/interfaces-pppoe.py | |
parent | 17a9c0f1a0b73c192a5d64372595ddcb4ae19d71 (diff) | |
parent | 2242f7d8abcafcd1c1f33ad6b59e2b22979adb69 (diff) | |
download | vyos-1x-e8fc4cb5240fb637d25ea03e08df6c0267d052cf.tar.gz vyos-1x-e8fc4cb5240fb637d25ea03e08df6c0267d052cf.zip |
Merge branch 'ipv6-pppoe' of github.com:c-po/vyos-1x into current
* 'ipv6-pppoe' of github.com:c-po/vyos-1x:
pppoe: T1493: support IPv6 address negotiation which is required for DHCPv6-PD
macvlan: T1635: ensure 'link' interface really exists
vxlan: T1636: ensure 'link' interface really exists
pppoe: T1318: IPv6 support
Diffstat (limited to 'src/conf_mode/interfaces-pppoe.py')
-rwxr-xr-x | src/conf_mode/interfaces-pppoe.py | 91 |
1 files changed, 67 insertions, 24 deletions
diff --git a/src/conf_mode/interfaces-pppoe.py b/src/conf_mode/interfaces-pppoe.py index 8ec78bab3..0622e4c9a 100755 --- a/src/conf_mode/interfaces-pppoe.py +++ b/src/conf_mode/interfaces-pppoe.py @@ -23,6 +23,7 @@ from subprocess import Popen, PIPE from time import sleep from pwd import getpwnam from grp import getgrnam +from stat import S_IRUSR, S_IWUSR, S_IXUSR, S_IRGRP, S_IXGRP, S_IROTH, S_IXOTH from vyos.config import Config from vyos.ifconfig import Interface @@ -30,9 +31,7 @@ from vyos import ConfigError from netifaces import interfaces # Please be careful if you edit the template. -config_pppoe_tmpl = """ -### Autogenerated by interfaces-pppoe.py ### - +config_pppoe_tmpl = """### Autogenerated by interfaces-pppoe.py ### {% if description %} # {{ description }} {% endif %} @@ -92,6 +91,7 @@ usepeerdns {% endif %} {% if ipv6_enable -%} +ipv6 +ipv6cp-use-ipaddr {% endif %} {% if service_name -%} rp_pppoe_service "{{ service_name }}" @@ -99,6 +99,55 @@ rp_pppoe_service "{{ service_name }}" """ +# Please be careful if you edit the template. +# There must be no blank line at the top pf the script file +config_pppoe_ipv6_up_tmpl = """#!/bin/sh + +# As PPPoE is an "on demand" interface we need to re-configure it when it +# becomes up + +if [ "$6" != "{{ intf }}" ]; then + exit +fi + +# add some info to syslog +DIALER_PID=$(cat /var/run/{{ intf }}.pid) +logger -t pppd[$DIALER_PID] "executing $0" +logger -t pppd[$DIALER_PID] "configuring dialer interface $6 via $2" + +echo "{{ description }}" > /sys/class/net/{{ intf }}/ifalias + +{% if ipv6_autoconf -%} + + +# Configure interface-specific Host/Router behaviour. +# Note: It is recommended to have the same setting on all interfaces; mixed +# router/host scenarios are rather uncommon. Possible values are: +# +# 0 Forwarding disabled +# 1 Forwarding enabled +# +echo 1 > /proc/sys/net/ipv6/conf/{{ intf }}/forwarding + +# Accept Router Advertisements; autoconfigure using them. +# +# It also determines whether or not to transmit Router +# Solicitations. If and only if the functional setting is to +# accept Router Advertisements, Router Solicitations will be +# transmitted. Possible values are: +# +# 0 Do not accept Router Advertisements. +# 1 Accept Router Advertisements if forwarding is disabled. +# 2 Overrule forwarding behaviour. Accept Router Advertisements +# even if forwarding is enabled. +# +echo 2 > /proc/sys/net/ipv6/conf/{{ intf }}/accept_ra + +# Autoconfigure addresses using Prefix Information in Router Advertisements. +echo 1 > /proc/sys/net/ipv6/conf/{{ intf }}/autoconfigure +{% endif %} +""" + PPP_LOGFILE = '/var/log/vyatta/ppp_{}.log' default_config_data = { @@ -108,7 +157,7 @@ default_config_data = { 'on_demand': False, 'default_route': 'auto', 'deleted': False, - 'description': '', + 'description': '\0', 'disable': False, 'intf': '', 'idle_timeout': '', @@ -219,15 +268,16 @@ def verify(pppoe): return None if not pppoe['source_interface']: - raise ConfigError('PPPoE source interface is missing') + raise ConfigError('PPPoE source interface missing') - if pppoe['source_interface'] not in interfaces(): + if not pppoe['source_interface'] in interfaces(): raise ConfigError('PPPoE source interface does not exist') return None def generate(pppoe): config_file_pppoe = '/etc/ppp/peers/{}'.format(pppoe['intf']) + script_file = '/etc/ppp/ipv6-up.d/50-vyos-{}-autoconf'.format(pppoe['intf']) # Always hang-up PPPoE connection prior generating new configuration file cmd = 'systemctl stop ppp@{}.service'.format(pppoe['intf']) @@ -238,6 +288,9 @@ def generate(pppoe): if os.path.exists(config_file_pppoe): os.unlink(config_file_pppoe) + if os.path.exists(script_file): + os.unlink(config_file_pppoe) + else: # Create PPP configuration files tmpl = Template(config_pppoe_tmpl) @@ -245,6 +298,14 @@ def generate(pppoe): with open(config_file_pppoe, 'w') as f: f.write(config_text) + script_file = '/etc/ppp/ipv6-up.d/50-vyos-{}-autoconf'.format(pppoe['intf']) + tmpl = Template(config_pppoe_ipv6_up_tmpl) + config_text = tmpl.render(pppoe) + with open(script_file, 'w') as f: + f.write(config_text) + + os.chmod(script_file, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) + return None def apply(pppoe): @@ -263,24 +324,6 @@ def apply(pppoe): gid = getgrnam('vyattacfg').gr_gid os.chown(pppoe['logfile'], uid, gid) - # better late then sorry ... but we can only set interface alias after - # pppd has been launched and created the interface - cnt = 0 - while pppoe['intf'] not in interfaces(): - cnt += 1 - if cnt == 50: - break - - # sleep 250ms - sleep(0.250) - - try: - # we need to catch the exception if the interface is not up due to - # reason stated above - Interface(pppoe['intf']).set_alias(pppoe['description']) - except: - pass - return None if __name__ == '__main__': |