]> git.ipfire.org Git - network.git/commitdiff
Add IPv6 support for pppoe.
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 4 Jun 2011 15:05:40 +0000 (15:05 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 4 Jun 2011 15:05:40 +0000 (15:05 +0000)
Makefile
functions.ppp
functions.routing
header-zone
hooks/zones/pppoe
ppp/ip-updown

index ae34aae2c4ffad934c5c26e6f4b6038e9def2861..63944b09004832e739c493720f262990f9ae3414 100644 (file)
--- 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:
index ca6c4e0342183368cc355a3ad030fc2c775a767c..ddc68f2ec1413256cf4ab010422f5c5e3d61e6f7 100644 (file)
@@ -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}
 
index 9d59e6d1ede7dec71c6e2c1cf54ced3700ca4bda..ac5c4da71013c993822829163ed0fe8f87aecb40 100644 (file)
@@ -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}
 
index 9407c976f4d03993b5ae5fdf3739f32bc06cfa23..e2548fab5cd752769e8845d315e8b106843a0a96 100644 (file)
@@ -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} $@
                        ;;
 
index c3640811c0457fbf8ae757de5130c89e1d502e4f..fb6b0a9c761644c48e6e27674e08c36389dad8fa 100755 (executable)
@@ -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:" "<hidden>"
        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}
index 8e9751a69d5c88e0dbd0a1fcef31bddfde1536c3..a4af6e992d5f6334df032bf3b0e9b9bad74932eb 100755 (executable)
@@ -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}