From: <abe...@us...> - 2017-05-10 17:50:05
|
Revision: 8294 http://sourceforge.net/p/astlinux/code/8294 Author: abelbeck Date: 2017-05-10 17:50:03 +0000 (Wed, 10 May 2017) Log Message: ----------- wide-dhcpv6, rewrite the '/etc/dhcp6c.script' script to parse the dhcp6c config file instead of using /etc/rc.conf variables, and add a few more exported env variables. Ref: https://doc.astlinux-project.org/userdoc:tt-dhcpv6-prefix-delegation#dhcpv6_client_action_script Modified Paths: -------------- branches/1.0/package/wide-dhcpv6/dhcp6c.script Modified: branches/1.0/package/wide-dhcpv6/dhcp6c.script =================================================================== --- branches/1.0/package/wide-dhcpv6/dhcp6c.script 2017-05-09 22:28:10 UTC (rev 8293) +++ branches/1.0/package/wide-dhcpv6/dhcp6c.script 2017-05-10 17:50:03 UTC (rev 8294) @@ -6,50 +6,20 @@ SCRIPTFILE="/mnt/kd/dhcp6c.script" -find_first_autoconfig_if() +get_ipv6_global_addr() { - local interface="" iname IFS + local interface="$1" - unset IFS - for iname in $IPV6_AUTOCONF; do - case $iname in - INTIF) - if [ -n "$INTIF" -a "$INTIF" != "none" -a -n "$INTIP" -a -n "$INTNM" ]; then - interface="$INTIF" - fi - ;; - INT2IF) - if [ -n "$INT2IF" -a "$INT2IF" != "none" -a -n "$INT2IP" -a -n "$INT2NM" ]; then - interface="$INT2IF" - fi - ;; - INT3IF) - if [ -n "$INT3IF" -a "$INT3IF" != "none" -a -n "$INT3IP" -a -n "$INT3NM" ]; then - interface="$INT3IF" - fi - ;; - INT4IF) - if [ -n "$INT4IF" -a "$INT4IF" != "none" -a -n "$INT4IP" -a -n "$INT4NM" ]; then - interface="$INT4IF" - fi - ;; - DMZIF) - if [ -n "$DMZIF" -a "$DMZIF" != "none" -a -n "$DMZIP" -a -n "$DMZNM" ]; then - interface="$DMZIF" - fi - ;; - esac - if [ -n "$interface" ]; then - break - fi - done - - echo "$interface" + ip -6 -o addr show dev $interface scope global 2>/dev/null | \ + sed -n -r -e 's|^.* inet6 ([0-9a-fA-F:]+)/.*$|\1|p' | \ + head -n1 } -find_prefix_len() +use_prefix_len() { - case "${DHCPV6_CLIENT_PREFIX_LEN:-60}" in + local len="$1" + + case $len in 64) cut_chars="1-19" prefix_label="::/64" ;; @@ -73,26 +43,59 @@ setup_env() { - local ipv6 ipv6_ex cut_chars prefix_label + local conffile pd_1 prefix_len prefix_if first_if interface ipv6 ipv6_ex cut_chars prefix_label IFS - dhcp6c_interface="$(find_first_autoconfig_if)" + ## Globals to export + dhcp6c_interface="" + dhcp6c_address="" + dhcp6c_prefix_interfaces="" + dhcp6c_prefix_addresses="" dhcp6c_prefix="" dhcp6c_prefix_base="" + dhcp6c_prefix_len="" + ## - if [ -n "$dhcp6c_interface" ]; then - ipv6="$(ip -6 -o addr show dev $dhcp6c_interface scope global 2>/dev/null | \ - sed -n -r -e 's|^.* inet6 ([0-9a-fA-F:]+)/.*$|\1|p' | \ - head -n1)" + conffile="/etc/wide-dhcpv6/dhcp6c-${EXTIF}.conf" + if [ ! -f "$conffile" ]; then + return + fi - if [ -n "$ipv6" ]; then - ipv6_ex="$(netcalc "$ipv6" | sed -n -r -e 's/^Expanded IPv6 *: *([0-9a-fA-F:]+).*$/\1/p')" + dhcp6c_interface="$EXTIF" + dhcp6c_address="$(get_ipv6_global_addr $dhcp6c_interface)" - find_prefix_len - if [ -n "$cut_chars" -a -n "$prefix_label" ]; then - dhcp6c_prefix_base="$(echo "$ipv6_ex" | cut -c $cut_chars)" - if [ -n "$dhcp6c_prefix_base" ]; then - dhcp6c_prefix="$dhcp6c_prefix_base$prefix_label" - fi + pd_1="$(cat "$conffile" | sed -n '/^id-assoc pd 1 /,/^};/ p')" + + prefix_len="$(echo "$pd_1" | sed -n -r -e 's/^ +prefix +::\/([0-9]+) .*$/\1/p')" + prefix_if="$(echo "$pd_1" | sed -n -r -e 's/^ +prefix-interface +([^ ]+) .*$/\1/p')" + first_if="" + + unset IFS + for interface in $prefix_if; do + dhcp6c_prefix_interfaces="$dhcp6c_prefix_interfaces,$interface" + dhcp6c_prefix_addresses="$dhcp6c_prefix_addresses,$(get_ipv6_global_addr $interface)" + if [ -z "$first_if" ]; then + first_if="$interface" + fi + done + # remove leading comma, this method keeps the pairs comma-aligned + dhcp6c_prefix_interfaces="${dhcp6c_prefix_interfaces#,}" + dhcp6c_prefix_addresses="${dhcp6c_prefix_addresses#,}" + + if [ -z "$first_if" ]; then + return + fi + + ipv6="$(get_ipv6_global_addr $first_if)" + + if [ -n "$ipv6" ]; then + ipv6_ex="$(netcalc "$ipv6" | sed -n -r -e 's/^Expanded IPv6 *: *([0-9a-fA-F:]+).*$/\1/p')" + + use_prefix_len "$prefix_len" + if [ -n "$cut_chars" -a -n "$prefix_label" ]; then + dhcp6c_prefix_len="$prefix_len" + dhcp6c_prefix_base="$(echo "$ipv6_ex" | cut -c $cut_chars)" + if [ -n "$dhcp6c_prefix_base" ]; then + dhcp6c_prefix="$dhcp6c_prefix_base$prefix_label" fi fi fi @@ -100,7 +103,9 @@ if [ -x $SCRIPTFILE ]; then setup_env - export dhcp6c_interface dhcp6c_prefix dhcp6c_prefix_base + export dhcp6c_interface dhcp6c_address + export dhcp6c_prefix_interfaces dhcp6c_prefix_addresses + export dhcp6c_prefix dhcp6c_prefix_base dhcp6c_prefix_len $SCRIPTFILE >/dev/null 2>&1 & fi This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |