From: Michael Tremer Date: Sat, 4 Jun 2011 15:05:40 +0000 (+0000) Subject: Add IPv6 support for pppoe. X-Git-Tag: 001~9 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=201b7dff31fc3ae77d71b157494f01fe2910ac20;p=network.git Add IPv6 support for pppoe. --- diff --git a/Makefile b/Makefile index ae34aae2..63944b09 100644 --- a/Makefile +++ b/Makefile @@ -21,6 +21,8 @@ install: ln -svf ip-updown $(DESTDIR)/etc/ppp/ip-pre-up ln -svf ip-updown $(DESTDIR)/etc/ppp/ip-up ln -svf ip-updown $(DESTDIR)/etc/ppp/ip-down + ln -svf ip-updown ${DESTDIR}/etc/ppp/ipv6-up + ln -svf ip-updown ${DESTDIR}/etc/ppp/ipv6-down install -m 755 -v ppp/dialer $(DESTDIR)/etc/ppp dist: diff --git a/functions.ppp b/functions.ppp index ca6c4e03..ddc68f2e 100644 --- a/functions.ppp +++ b/functions.ppp @@ -34,7 +34,6 @@ function ppp_common_ip_pre_up() { return ${EXIT_ERROR} fi - # XXX protocol hardcoded routing_db_from_ppp ${zone} ipv4 # Request firewall reload @@ -52,7 +51,6 @@ function ppp_common_ip_up() { return ${EXIT_ERROR} fi - # XXX protocol is hardcoded routing_db_set ${zone} ipv4 active 1 routing_update ${zone} ipv4 @@ -71,6 +69,55 @@ function ppp_common_ip_down() { return ${EXIT_ERROR} fi + # Remove the information about this zone from the routing database + # and update the routing table. + routing_db_remove ${zone} ipv4 + routing_update ${zone} ipv4 + + # Save accounting information + ppp_accounting ${zone} + + # Emit interface-up event + event_interface_down ${zone} + + return ${EXIT_OK} +} + +function ppp_common_ipv6_up() { + local zone=${1} + shift + + if ! zone_exists ${zone}; then + error "Zone '${zone}' does not exist." + return ${EXIT_ERROR} + fi + + # Add information about this zone to the routing database. + routing_db_from_ppp ${zone} ipv6 + + routing_db_set ${zone} ipv6 active 1 + routing_update ${zone} ipv6 + + # Emit interface-up event + event_interface_up ${zone} + + return ${EXIT_OK} +} + +function ppp_common_ipv6_down() { + local zone=${1} + shift + + if ! zone_exists ${zone}; then + error "Zone '${zone}' does not exist." + return ${EXIT_ERROR} + fi + + # Remove the information about this zone from the routing database + # and update the routing table. + routing_db_remove ${zone} ipv6 + routing_update ${zone} ipv6 + # Save accounting information ppp_accounting ${zone} diff --git a/functions.routing b/functions.routing index 9d59e6d1..ac5c4da7 100644 --- a/functions.routing +++ b/functions.routing @@ -32,44 +32,49 @@ function routing_default_update() { fi local gateway + local proto local weight local zone - local proto="ipv4" + for proto in ${IP_SUPPORTED_PROTOCOLS}; do + # Clear routes + routes="" - for zone in ${zones}; do - # Skip if zone is not up - routing_db_exists ${zone} ${proto} || continue + for zone in ${zones}; do + # Skip if zone is not up + routing_db_exists ${zone} ${proto} || continue - if [ "$(routing_db_get ${zone} ${proto} active)" = "1" ]; then - gateway=$(routing_db_get ${zone} ${proto} remote-ip-address) - weight=$(routing_db_get ${zone} ${proto} weight) + if [ "$(routing_db_get ${zone} ${proto} active)" = "1" ]; then + gateway=$(routing_db_get ${zone} ${proto} remote-ip-address) + weight=$(routing_db_get ${zone} ${proto} weight) - routes="${routes} nexthop via ${gateway}" + routes="${routes} nexthop via ${gateway}" - if [ -n "${weight}" ]; then - routes="${routes} weight ${weight}" + if [ -n "${weight}" ]; then + routes="${routes} weight ${weight}" + fi + else + log DEBUG "Ignoring zone '${zone}' which is not active." fi - else - log DEBUG "Ignoring zone '${zone}' which is not active." - fi - done + done - if [ -z "${routes}" ]; then - log INFO "Removing default route." + if [ -z "${routes}" ]; then + log INFO "Removing default route for ${proto}." - if routing_has_default; then - ip route del default + if routing_has_default; then + ip route del default + fi + return ${EXIT_OK} fi - return ${EXIT_OK} - fi - # Remove too much spaces. - routes=$(echo ${routes}) + # Remove too much spaces. + routes=$(echo ${routes}) - log INFO "Setting default route: ${routes}" + log INFO "Setting default route for ${proto}: ${routes}" - ip route replace default ${routes} + ip $([ "${proto}" = "ipv6" ] && echo "-6") route replace default ${routes} + assert [ $? -eq 0 ] + done } function routing_table_exists() { @@ -154,8 +159,14 @@ function routing_db_from_ppp() { # Save ppp configuration routing_db_set ${zone} ${proto} type "ppp" - routing_db_set ${zone} ${proto} local-ip-address ${PPP_IPLOCAL} - routing_db_set ${zone} ${proto} remote-ip-address ${PPP_IPREMOTE} + + if [ "${proto}" = "ipv6" ]; then + routing_db_set ${zone} ${proto} local-ip-address ${PPP_LLLOCAL} + routing_db_set ${zone} ${proto} remote-ip-address ${PPP_LLREMOTE} + elif [ "${proto}" = "ipv4" ]; then + routing_db_set ${zone} ${proto} local-ip-address ${PPP_IPLOCAL} + routing_db_set ${zone} ${proto} remote-ip-address ${PPP_IPREMOTE} + fi routing_db_set ${zone} ${proto} dns ${PPP_DNS1} ${PPP_DNS2} diff --git a/header-zone b/header-zone index 9407c976..e2548fab 100644 --- a/header-zone +++ b/header-zone @@ -299,6 +299,34 @@ function _ppp-ip-down() { exit $? } +function _ppp-ipv6-up() { + local zone=${1} + shift + + if ! zone_exists ${zone}; then + error "Zone '${zone}' does not exist." + exit ${EXIT_ERROR} + fi + + ppp_common_ipv6_up ${zone} $@ + + exit $? +} + +function _ppp-ipv6-down() { + local zone=${1} + shift + + if ! zone_exists ${zone}; then + error "Zone '${zone}' does not exist." + exit ${EXIT_ERROR} + fi + + ppp_common_ipv6_down ${zone} $@ + + exit $? +} + function run() { # Replace all dashes by an underscore #action=${action//-/_} @@ -320,7 +348,7 @@ function run() { ;; # ppp daemon callbacks - ppp-ip-pre-up|ppp-ip-up|ppp-ip-down) + ppp-ip-pre-up|ppp-ip-up|ppp-ip-down|ppp-ipv6-up|ppp-ipv6-down) _${action} $@ ;; diff --git a/hooks/zones/pppoe b/hooks/zones/pppoe index c3640811..fb6b0a9c 100755 --- a/hooks/zones/pppoe +++ b/hooks/zones/pppoe @@ -27,6 +27,7 @@ HOOK_SETTINGS="HOOK AUTH LINKNAME USER SECRET PEERDNS DEFAULTROUTE MTU" AUTH= DEFAULTROUTE=1 +IPV6=1 LINKNAME="$(uuid)" MTU=1492 PEERDNS=1 @@ -53,6 +54,7 @@ function _check() { #assert isset DEVICE_TYPE assert isbool DEFAULTROUTE + assert isbool IPV6 assert isbool PEERDNS #assert ismac DEVICE #assert isoneof DEVICE_TYPE real virtual @@ -100,6 +102,9 @@ function _parse_cmdline() { --auth=*) AUTH=${1#--auth=} ;; + --ipv6=*) + IPV6=${1#--ipv6=} + ;; *) echo "Unknown option: $1" >&2 exit ${EXIT_ERROR} @@ -145,6 +150,9 @@ linkname ${LINKNAME} plugin ${PPPOE_PLUGIN} ${port} +# Enable/disable IPv6 +$(enabled IPV6 && echo "+" || echo "-")ipv6 + # User configuration user ${USER} @@ -244,6 +252,7 @@ function _status() { printf "${DEVICE_PRINT_LINE1}" "Secret:" "" echo printf "${DEVICE_PRINT_LINE1}" "MTU:" "${MTU}" + printf "${DEVICE_PRINT_LINE1}" "IPv6:" "$(enabled IPV6 && echo "enabled" || echo "disabled")" printf "${DEVICE_PRINT_LINE1}" "Use default route?" "$(enabled DEFAULTROUTE && echo "enabled" || echo "disabled")" printf "${DEVICE_PRINT_LINE1}" "Use peer DNS?" "$(enabled PEERDNS && echo "enabled" || echo "disabled")" echo @@ -262,12 +271,21 @@ function _status() { # XXX display time since connection started cli_headline " Point-to-Point-over-Ethernet protocol:" - echo " IP-Address : $(routing_db_get ${zone} local-ip-address)" - echo " Gateway : $(routing_db_get ${zone} remote-ip-address)" - echo " DNS-Server : $(routing_db_get ${zone} dns)" - echo - echo " MAC-Remote : $(routing_db_get ${zone} remote-address)" - echo + local proto + for proto in ${IP_SUPPORTED_PROTOCOLS}; do + routing_db_exists ${zone} ${proto} || continue + if [ "${proto}" = "ipv6" ]; then + echo " Internet Protocol Version 6:" + elif [ "${proto}" = "ipv4" ]; then + echo " Internet Protocol Version 4:" + fi + echo " IP-Address : $(routing_db_get ${zone} ${proto} local-ip-address)" + echo " Gateway : $(routing_db_get ${zone} ${proto} remote-ip-address)" + echo " DNS-Server : $(routing_db_get ${zone} ${proto} dns)" + echo + echo " MAC-Remote : $(routing_db_get ${zone} ${proto} remote-address)" + echo + done echo " MTU : $(device_get_mtu ${zone})" echo # Empty line exit ${EXIT_OK} diff --git a/ppp/ip-updown b/ppp/ip-updown index 8e9751a6..a4af6e99 100755 --- a/ppp/ip-updown +++ b/ppp/ip-updown @@ -23,7 +23,7 @@ umask 022 export PATH=/usr/sbin:/sbin:/usr/bin:/bin # Give the variables we get passed by pppd an own namespace -for i in IFNAME IPLOCAL IPREMOTE DNS1 DNS2 MACREMOTE; do +for i in IFNAME IPLOCAL IPREMOTE DNS1 DNS2 MACREMOTE LLLOCAL LLREMOTE; do export PPP_${i}=${!i} unset ${i} done @@ -41,4 +41,10 @@ HOOK=$(zone_get_hook ${ZONE}) assert isset HOOK assert hook_zone_exists ${HOOK} -hook_zone_exec ${HOOK} ppp-$(basename ${0}) ${ZONE} +PROGNAME=$(basename ${0}) +assert isset PROGNAME + +log DEBUG "${PROGNAME} was called with the following parameters:" +log DEBUG " $@" + +hook_zone_exec ${HOOK} ppp-${PROGNAME} ${ZONE}