Pi-Star 4.1.0 RC5 IPv6 DUID Bug

All IP networking related issues
Post Reply
k2dls
Posts: 74
Joined: Mon Aug 20, 2018 5:24 pm

Pi-Star 4.1.0 RC5 IPv6 DUID Bug

Post by k2dls » Thu Sep 12, 2019 8:48 pm

I've been trying to track down why Pi-Star is not getting the statically assigned IPv6 address from the DHCP server on each boot. Something is changing the DUID between boots. I've verified on a non Pi-Star installation that this is not a generic Buster issue, rather it is specific to Pi-Star.

It is messy as Pi-Star gets a different IPv6 address on each boot and is ignoring DHCPv6.

Original DUID:
00010001250437e0b827eb4d6d1f

After boot DUID:
00010001250d693fb827eb4d6d1f

k2dls
Posts: 74
Joined: Mon Aug 20, 2018 5:24 pm

Re: Pi-Star 4.1.0 RC5 IPv6 DUID Bug

Post by k2dls » Thu Sep 12, 2019 9:03 pm

OK, the problem seems to be that /var/lib/dhcpcd5 is not a permanent filesystem. This is very bad, as DUID should be unique and never change between reboots. If /var/lib/dhcpcd5 MUST be a tmpfs, the duid needs to be stored somewhere on the sdcard and copied over at boot time.

KE7FNS
Posts: 415
Joined: Wed Apr 17, 2019 11:11 pm

Re: Pi-Star 4.1.0 RC5 IPv6 DUID Bug

Post by KE7FNS » Fri Sep 13, 2019 3:58 am

Well thats interesting.

Good find.
All views, comments, posts and opinions shared are entirely my own.

kc7ngc
Posts: 7
Joined: Fri Sep 21, 2018 2:47 am

Re: Pi-Star 4.1.0 RC5 IPv6 DUID Bug

Post by kc7ngc » Wed Nov 06, 2019 2:10 am

Not meaning to dig up an old thread, but since this is something I had solved on my own before I saw this thread figured would share. This could use some cleaning up. Apologize if I missed something in this post. As going back to document something I did a bit ago is always harder than had I documented it in the first place.

Explanation:

On boot the:

duidsave.service service is set to run after /var/lib/dhcpcd5 is mounted in tmpfs but before dhcpcd5 is ran.
Is runs /usr/local/sbin/duid-save.sh restore
If /usr/local/etc/dhcpcd5/duid file exists then it creates a ln from /var/lib/dhcpcd5/duid to /usr/local/etc/dhcpcd5/duid

Hourly:
duid-save runs by cron to see if duid needs to be save. I tried putting a service to run after dhcpcd5 came up and created a new duid on first boot but has race conditions so cron seemed a good compromise.
"duid-save.sh save" checks if different between /var/lib/dhcp5/duid and /usr/local/etc/dhcpcd5/duid
if their is a different then it makes sure that the /usr/local/etc/dhcpcd5 directory is created and dumps the duid into that directory.

Really this needs to be a oneshot deal, as once duid is saved to nonvolatile storage it doesn't need to run again. But right now it runs and checks if duid on disk is different than in tmp and will archive it away. Might be a better way to do a oneshot trigger to save duid after dhcpcd5 service creates it but I didn't put much effort into it as this worked for my purposes.



/etc/cron.hourly/duid-save

Code: Select all

#!/bin/bash
/usr/local/sbin/duid-save.sh save


/usr/local/sbin/duid-save.sh

Code: Select all

#!/bin/bash
function save {
  # check if persistent duid is different that tmpfs one
  if ! cmp -s /usr/local/etc/dhcpcd5/duid /var/lib/dhcpcd5/duid  ; then
        # check if we need to remount rw
        if fgrep -q "/dev/root / ext4 ro" /proc/mounts ; then
                # mounted ro so mount rw
                        mount -o remount,rw /
                        remountit=1
        fi
        if [ ! -d "/usr/local/etc/dhcpcd5" ]; then
                # if directory doesn't exist make it
                mkdir /usr/local/etc/dhcpcd5
        fi
        cp /var/lib/dhcpcd5/duid /usr/local/etc/dhcpcd5/
        if [[ $remountit == "1" ]]; then
                # if we mounted as RW then put back to RO
               mount -o remount,ro /
        fi
  fi
}

if [ "$1" = "restore" ]; then
        if [ -f "/usr/local/etc/dhcpcd5/duid" ]; then
               rm /var/lib/dhcpcd5/duid
               ln -s  /usr/local/etc/dhcpcd5/duid /var/lib/dhcpcd5/duid
        fi
fi

if [ "$1" = "save" ]; then
        save
fi

if [ "$1" = "new" ]; then
        # remove duid from tmpfs
        rm /var/lib/dhcpcd5/duid
        # restart dhcpcd5
        service dhcpcd5 restart
        # save new duid
        save
fi



/etc/systemd/system/duidsave.service

Code: Select all


[Unit]
Description=Populate dhcpcd4 DUID to tmpfs
After=var-lib-dhcpcd5.mount
Before=dhcpcd5.service

[Service]
Type=simple
ExecStart=/bin/bash -c "/usr/local/sbin/duid-save.sh restore"


[Install]
WantedBy=multi-user.target


Once those files are in place then:

Code: Select all

sudo chmod +x /etc/cron.hourly/duid-save.sh
sudo chmod +x /usr/local/sbin/duid-save.sh
sudo ln -s /etc/systemd/system/duidsave.service /etc/systemd/system/multi-user.target.wants/duidsave.service

Post Reply