Skip to content

Instantly share code, notes, and snippets.

@relvinhas
Created September 29, 2020 20:30
Show Gist options
  • Save relvinhas/8b8e20ec3897b2230226b546285d677c to your computer and use it in GitHub Desktop.
Save relvinhas/8b8e20ec3897b2230226b546285d677c to your computer and use it in GitHub Desktop.
DANOS - Update PBR routing table
#!/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
@relvinhas
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment