From 031f41b62e9761276b2964840c22d6c6666f83be Mon Sep 17 00:00:00 2001 From: Darren 'Tadgy' Austin Date: Tue, 5 Nov 2019 23:28:16 +0000 Subject: New configuration methodology - see full commit log. It occurred to me that IPv6 addresses don't really need to have IP6ALIASES since all IPs are just added to the interface itself. So I've changed the syntax from using IP6ADDR + PREFIXLEN + IP6ALIASES to using just a single IP6ADDRS array, which takes a list of IP addresses with a prefix length in a space separated list. eg: IP6ADDRS[0]="a:b:c:d::1/64 1:2:3::1/48" If the prefix length is omitted a /64 length is assumed and a warning emitted. --- rc.inet1 | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) (limited to 'rc.inet1') diff --git a/rc.inet1 b/rc.inet1 index 9a6fd61..ae9280b 100644 --- a/rc.inet1 +++ b/rc.inet1 @@ -281,31 +281,35 @@ if_up() { fi fi if [ -e /proc/sys/net/ipv6 ] && [ "${USE_DHCP6[$i]}" != "yes" ] && [ "${USE_SLAAC[$i]}" != "yes" ] && \ - [ -n "${IP6ADDR[$i]}" ]; then # add a fixed v6 IP + [ -n "${IP6ADDRS[$i]}" ]; then # add fixed v6 IPs # IPv6's Duplicate Address Detection (DAD) causes a race condition when bringing up interfaces, as # described here: https://www.agwa.name/blog/post/beware_the_ipv6_dad_race_condition # Disable DAD while bringing up the interface - but note that this means the loss of detection of a # duplicate address. It's a trade off, unfortunately. echo "0" >/proc/sys/net/ipv6/conf/$1/accept_dad - if [ -z "${PREFIXLEN[$i]}" ]; then - echo "/etc/rc.d/rc.inet1: no PREFIXLEN set for ${1} - assuming 64" | $LOGGER - PREFIXLEN[$i]="64" - fi - echo "/etc/rc.d/rc.inet1: /sbin/ip -6 address add ${IP6ADDR[$i]}/${PREFIXLEN[$i]#/} dev ${1}" | $LOGGER - if /sbin/ip -6 address add ${IP6ADDR[$i]}/${PREFIXLEN[$i]#/} dev ${1} && \ - /sbin/ip link set dev ${1} up; then - # Enable accepting of RA packets if explicitly told to. - if [ "${USE_RA[$i]}" = "yes" ]; then - echo "1" >/proc/sys/net/ipv6/conf/$1/accept_ra + for v6ip in ${IP6ADDRS[$i]}; do + ip="${v6ip%/*}" + prefix="${v6ip#*/}" + if [ -z "$prefix" ] || [ "$ip" == "$prefix" ]; then + echo "/etc/rc.d/rc.inet1: no prefix length set for ${ip} - assuming 64" | $LOGGER + prefix="64" fi - IF_UP=1 - else - echo "/etc/rc.d/rc.inet1: failed to set IP ${IP6ADDR[$i]} for ${1}" | $LOGGER - if (($IF_UP != 1)); then # a v4 address was configured, don't flush it - /sbin/ip address flush dev ${1} - /sbin/ip link set dev ${1} down + echo "/etc/rc.d/rc.inet1: /sbin/ip -6 address add ${ip}/${prefix} dev ${1}" | $LOGGER + if /sbin/ip -6 address add ${ip}/${prefix} dev ${1} && \ + /sbin/ip link set dev ${1} up; then + # Enable accepting of RA packets if explicitly told to. + if [ "${USE_RA[$i]}" = "yes" ]; then + echo "1" >/proc/sys/net/ipv6/conf/$1/accept_ra + fi + IF_UP=1 + else + echo "/etc/rc.d/rc.inet1: failed to set IP ${ip} for ${1}" | $LOGGER + if (($IF_UP != 1)); then # a v4 address was configured, don't flush it + /sbin/ip address flush dev ${1} + /sbin/ip link set dev ${1} down + fi fi - fi + done fi if (($IF_UP == 1)); then # only do further config if the interface came up # Add extra IPv4 and v6 addresses to the interface: -- cgit v1.2.3