Reply
Highlighted
Emerging Member
Posts: 59
Registered: ‎03-15-2015
Kudos: 18
Solutions: 1

script to renew DHCPv6-PD lease after PPP disconnect/reconnect

I created a little script I use to reconnect to the IPv6 world after my PPP session gets interrupted. For IPv4 it all comes back up normally, but for IPv6 the DHCPv6-PD process isn't run again, so I only have IPv4 connectivity then. This script is very simple and does two things:

 

1-check if DNS resolution over IPv4 is possible. If not, error out, there are bigger problems than this script can help with.

2-if IPv4 DNS works, check if google.com can be reached over IPv6 with ping6. If it fails, renew DHCPv6-PD lease.

 

And that's it..

 

I've named the script check-pd.sh and put it in /config/scripts (making sure it is executable 'chmod +x check-pd.sh')

 

#!/bin/bash

# check-pd.sh is a simple shell script to check if IPv4 connectivity is working, but IPv6 is not. 
# If so, it will renew the DHCPv6-PD lease. This script is meant to run on an Edgerouter Lite
# with firmware version 1.6.0. It may not run on other versions. It may not run on your machine.
# It may be mean to your kitten. No warranties, caveat emptor and all that.

# First, make sure we can resolve google, otherwise 'ping6' would hang

if ! $(host -4 -W3 www.google.com > /dev/null 2>&1); then
# 	If you want to do stuff if IPv4 resolving is down, this would be where you can do that.
# 	The next three lines are an idea, they need work and probably thought before implementing

#        Make a note in syslog
#        logger "DNS appears to be down, restarting router..."
#        reboot

	echo "DNS resolving does not work, the problem is bigger than this script can help with."
        exit
fi

# Second, try to ping6 google 3 times, if we don't have 100% success, renew DHCPv6-PD lease

x=`/bin/ping6 -c3 google.com 2>&1 | grep 100%`
if [ ! "$x" = "" ]; then
        echo "IPv6 is down!! Renewing DHCPv6-PD lease!"
# 	Make a note in syslog
 	logger "IPv4 connectivity is up, IPv6 is down. Renewing DHCPv6-PD lease!"
	renew dhcpv6-pd interface pppoe0
fi

As you can see, there is room for improvement, especially with regards to the messages/log entries. (it's a first draft really) However, it works quite well. I've moved to run it every 5 minutes. Here is how you do that:

 

set system task-scheduler task check-pd executable path /config/scripts/check-pd.sh
set system task-scheduler task check-pd interval 5m

 I hope this helps others. For now, with 1.6 it is needed and it is unknown if the issue is resolved for 1.7. If you read this when 1.7 or later is released, do some research to check if this is still needed. (or downgrade to 1.6 if you feel you must run this script) Man Wink

Regular Member
Posts: 318
Registered: ‎06-08-2013
Kudos: 158
Solutions: 16

Re: script to renew DHCPv6-PD lease after PPP disconnect/reconnect

That looks cool, I'll give it a try later.

One question, would it not be better to have it triggered when the PPPOE session comes up?

Scripts in /config/scripts/ppp/ip-up.d/ are triggered in alphabetical order.

 

Emerging Member
Posts: 59
Registered: ‎03-15-2015
Kudos: 18
Solutions: 1

Re: script to renew DHCPv6-PD lease after PPP disconnect/reconnect

[ Edited ]

that would be much better, I think, however, in a normal boot, it will be executed as well. Maybe I should put a sleep 30 in it or so, so that in the normal situation it won't do anything, only when there is a disconnect/reconnect.

 

Scripts in that directory are also executed on reconnect? Also, that directory is checked for? It currently does not exist on my ERL.

 

I guess for a little while I'll have two versions, that don't output anything other than syslog messages. One in the ppp/ip-up.d directory, one where I have it now (triggered by config). I'll then scan through the syslog messages (need a unique code in the message to grep for) and see which one, if any, gets used.

Regular Member
Posts: 318
Registered: ‎06-08-2013
Kudos: 158
Solutions: 16

Re: script to renew DHCPv6-PD lease after PPP disconnect/reconnect

The scripts are executed whener the ppp session comes up and passes some variables in if they're needed. I've got a script that sends a message to my android phone with my new IPv4 address every time it retrains (since dynamic DNS makes these issues transparent). 

 

I believe the directory is checked for, as far as I can recall I've not made any changes to get it recorgnised as I've had a number of config updates since I wrote the script.

 

The script as-is checks for connectivity before releasing/renewing, so if you were to put in enough of a delay between the script starting and then it pinging google (so the initial DHCPv6 setup can happen on boot) then it should all be good.

Previous Employee
Posts: 13,551
Registered: ‎06-10-2011
Kudos: 5411
Solutions: 1657
Contributions: 2

Re: script to renew DHCPv6-PD lease after PPP disconnect/reconnect

Thanks for sharing the script. Just to confirm, for the particular issue of PPPoE reconnect, it would be sufficient to execute the "renew" when PPPoE connection is re-established (after a disconnect), right?

Emerging Member
Posts: 59
Registered: ‎03-15-2015
Kudos: 18
Solutions: 1

Re: script to renew DHCPv6-PD lease after PPP disconnect/reconnect

indeed, I'll just put a "sleep 30" in the script that I put in the folder that gets executed after the ppp interface comes up. That should be enough time for IPv6 to get configured if it does and isn't too long for IPv6 to be gone. (5 minutes is acceptable to me anyway)

 

And indeed, a 'renew' after the interface comes up should be enough. It should be the default, imho, as in, built-in to the way the ERL behaves.

 

For now, it seems I haven't gotten disconnected for a while (in the beginning if IPv6 working for me it happened a few times), or.. the script is working. I'll change the syslog messages to have a unique code I can grep for in /var/log/message*

Previous Employee
Posts: 13,551
Registered: ‎06-10-2011
Kudos: 5411
Solutions: 1657
Contributions: 2

Re: script to renew DHCPv6-PD lease after PPP disconnect/reconnect

OK, so sounds like we can just put a ppp "if-up" script to do "renew", which should address this issue? If so we can look into that. Thanks for providing the information.

Emerging Member
Posts: 59
Registered: ‎03-15-2015
Kudos: 18
Solutions: 1

Re: script to renew DHCPv6-PD lease after PPP disconnect/reconnect

you are probably correct, although I've done a few greps through /var/log/messages and I haven't been able to see any entries.. it could be my IPv6 has gotten more stable than it did in the first day I got it working.

 

Regardless, when it wasn't working, a simple renew was sufficient. It would be nice to be included by default. (seems only logical to also renew IPv6 when the ppp session restarts)

Reply