dhcpcd-discuss

Re: IPv6 hooks

Roy Marples

Thu Jul 10 09:35:42 2014

Hi Andrew

On 10/07/2014 9:47, Andrew Cooks wrote:
Hi

I'm using the dhcpcd.enter-hook to send dbus notifications when the ip
address changes, like so:

--snip--
log() {
        date=$(date +"%Y%m%d-%H%M%S")
        file="/tmp/dhcpcdlog"
        echo "$date $1" >> $file
}

log "dhcpcd hook: interface:[$interface] ifcarrier:[$ifcarrier]
reason:[$reason]"

if [ "$reason" = "STATIC" ] \
|| [ "$reason" = "BOUND" ] \
|| [ "$reason" = "REBIND" ] \
|| [ "$reason" = "REBOOT" ] \
|| [ "$reason" = "IPV4LL" ]; then
    log "Interface ${interface} UP. IPv4 address: ${new_ip_address}"
    /path_to/config_routes.sh postup ${interface}
    /path_to/config_firewall.sh dev-reconf ${interface}

    dbus-send --session --type="method_call" \
              --dest=com.our.application \
                /ObjectName \
                com.our.application.LinkUpDownMethod \
                string:${interface} \
                boolean:true \
                string:"IPChange" \
                string:${new_ip_address}
fi
--snip--

This seems to work well for IPv4, but not for IPv6. For IPv6, I get
unexpected calls for the "ROUTERADVERT" reason and I can't see a way
to detect the address change in a similar way to IPv4.

Is there a way to do this? Could someone explain it to me?

There's a diagram for the states as I currently understand it at:
https://plus.google.com/106809740510707559932/posts/3Vd4pCuiJRf

For IPv4 there is only ever one address. For IPv6, well, there are quite a few!

DHCPv6 reasons have the suffix of 6
BOUND6, REBIND6, REBOOT6, etc. They generally mirror the IPv4 reasons.
In this instance, the addresses are held within IA options as an array
dhcp6_ia_na1_ia_addr1=addr1
dhcp6_ia_na1_ia_addr2=addr2
dhcp6_ia_na2_ia_addr1=addr3
dhcp6_ia_ta1_ia_addr1=addr4
dhcp6_ia_pd1_ia_prefix1=prefix4

Basically, each IA type can have more than one IAID assigned - for example one interface required for whatever reason two addresses, you could set two IAIDS. On the other hand, for your one IAID the server might want to hand you two addresses as well. The above format allows for this.

For IPv6 Router Advertisements, there is just the ROUTERADVERT reason
in this instance, all the current valid addresses from all routers are an array
ra1_prefix=address
ra2_prefix=address

For the dhcpcd-dbus and dhcpcd-ui projects we only look at the 1st NA address. Others whilst may exist, typically they won't in real world usage. If they do, the chances are you won't be running a GUI on the device itself, web front end maybe.

Thanks

Roy

Follow-Ups:
Re: IPv6 hooksAndrew Cooks
Re: IPv6 hooksRoy Marples
References:
IPv6 hooksAndrew Cooks
Archive administrator: postmaster@marples.name