Created
September 29, 2020 20:30
-
-
Save relvinhas/8b8e20ec3897b2230226b546285d677c to your computer and use it in GitHub Desktop.
DANOS - Update PBR routing table
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/vbash | |
DHCP_INTERFACE=$1 | |
ROUTING_TABLE=$2 | |
DHCP_LEASES=/var/lib/dhcp/dhclient_${DHCP_INTERFACE}.leases | |
if ! [ -f $DHCP_LEASES ]; then | |
echo "Unable to find DHCP Lease for ${DHCP_INTERFACE}" | |
exit | |
fi | |
CURRENT_DHCP_ROUTER=$(grep "option routers" ${DHCP_LEASES} | tail -n 1 | awk {'print $3'} | sed 's/;//g') | |
source /opt/vyatta/share/vyatta-cfg/functions/script-wrapper | |
configure | |
CURRENT_ROUTER=$(cmd_helper show protocols static table ${ROUTING_TABLE} route 0.0.0.0/0 next-hop | grep next-hop | awk {'print $2'}) | |
if ! [ "$CURRENT_ROUTER" ] || [ "$CURRENT_DHCP_ROUTER" != "$CURRENT_ROUTER" ]; then | |
echo "Updating route" | |
if [ "$CURRENT_ROUTER" ]; then | |
cmd_helper delete protocols static table ${ROUTING_TABLE} route 0.0.0.0/0 next-hop | |
fi | |
cmd_helper set protocols static table ${ROUTING_TABLE} route 0.0.0.0/0 next-hop ${CURRENT_DHCP_ROUTER} | |
commit | |
exit | |
fi | |
echo "No configuration changes" | |
cmd_helper exit discard |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Raw config: https://gist.github.com/relvinhas/e9d53adaabc50987b636a87b725fef7a
VM setup: https://gist.github.com/relvinhas/a60845913f8bcfdd8592c57e34374459