From 93fb90b4f1eca5a9d1828714e06123bb22a7a219 Mon Sep 17 00:00:00 2001 From: sever-sever Date: Fri, 14 Aug 2020 17:02:20 +0000 Subject: dhclient: T2277: Hook for default route in vrf --- src/etc/dhcp/dhclient-enter-hooks.d/03-vyos-ipwrapper | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/etc/dhcp/dhclient-enter-hooks.d/03-vyos-ipwrapper') diff --git a/src/etc/dhcp/dhclient-enter-hooks.d/03-vyos-ipwrapper b/src/etc/dhcp/dhclient-enter-hooks.d/03-vyos-ipwrapper index f1167fcd2..60e001af7 100644 --- a/src/etc/dhcp/dhclient-enter-hooks.d/03-vyos-ipwrapper +++ b/src/etc/dhcp/dhclient-enter-hooks.d/03-vyos-ipwrapper @@ -20,6 +20,7 @@ function iptovtysh () { local VTYSH_NETADDR="" local VTYSH_GATEWAY="" local VTYSH_DEV="" + local VTYSH_VRF_NAME=$(ip -d link show dev $interface | grep $interface | awk '{print $9}') # convert default route to 0.0.0.0/0 if [ "$4" == "default" ] ; then VTYSH_NETADDR="0.0.0.0/0" @@ -40,7 +41,14 @@ function iptovtysh () { elif [ "$7" == "dev" ]; then VTYSH_DEV=$8 fi - VTYSH_CMD="ip route $VTYSH_NETADDR $VTYSH_GATEWAY $VTYSH_DEV tag $VTYSH_TAG $VTYSH_DISTANCE" + + # check if vrf is present + if [ $(ip -d link show dev $interface | grep vrf | wc -l) -eq 0 ]; then + VTYSH_CMD="ip route $VTYSH_NETADDR $VTYSH_GATEWAY $VTYSH_DEV tag $VTYSH_TAG $VTYSH_DISTANCE" + elif [ $(ip -d link show dev $interface | grep vrf | wc -l) -eq 1 ]; then + VTYSH_CMD="ip route $VTYSH_NETADDR $VTYSH_GATEWAY $VTYSH_DEV tag $VTYSH_TAG $VTYSH_DISTANCE vrf $VTYSH_VRF_NAME" + fi + # delete route if the command is "del" if [ "$3" == "del" ] ; then VTYSH_CMD="no $VTYSH_CMD" -- cgit v1.2.3 From 910fc06cfd4160705f12d890ca6a6b8436326a67 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Sat, 15 Aug 2020 22:54:23 +0200 Subject: dhclient: T2277: retrieve VRF inform from sysfs rather then iproute2 --- src/etc/dhcp/dhclient-enter-hooks.d/03-vyos-ipwrapper | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/etc/dhcp/dhclient-enter-hooks.d/03-vyos-ipwrapper') diff --git a/src/etc/dhcp/dhclient-enter-hooks.d/03-vyos-ipwrapper b/src/etc/dhcp/dhclient-enter-hooks.d/03-vyos-ipwrapper index 60e001af7..1e102c2d7 100644 --- a/src/etc/dhcp/dhclient-enter-hooks.d/03-vyos-ipwrapper +++ b/src/etc/dhcp/dhclient-enter-hooks.d/03-vyos-ipwrapper @@ -20,7 +20,7 @@ function iptovtysh () { local VTYSH_NETADDR="" local VTYSH_GATEWAY="" local VTYSH_DEV="" - local VTYSH_VRF_NAME=$(ip -d link show dev $interface | grep $interface | awk '{print $9}') + local VTYSH_VRF_NAME=$(basename /sys/class/net/eth1/upper_* | sed -e 's/upper_//') # convert default route to 0.0.0.0/0 if [ "$4" == "default" ] ; then VTYSH_NETADDR="0.0.0.0/0" @@ -42,12 +42,11 @@ function iptovtysh () { VTYSH_DEV=$8 fi - # check if vrf is present - if [ $(ip -d link show dev $interface | grep vrf | wc -l) -eq 0 ]; then - VTYSH_CMD="ip route $VTYSH_NETADDR $VTYSH_GATEWAY $VTYSH_DEV tag $VTYSH_TAG $VTYSH_DISTANCE" - elif [ $(ip -d link show dev $interface | grep vrf | wc -l) -eq 1 ]; then - VTYSH_CMD="ip route $VTYSH_NETADDR $VTYSH_GATEWAY $VTYSH_DEV tag $VTYSH_TAG $VTYSH_DISTANCE vrf $VTYSH_VRF_NAME" + # Add route to VRF routing table + if [ -n $VTYSH_VRF_NAME ]; then + VTYSH_VRF="vrf $VTYSH_VRF_NAME" fi + VTYSH_CMD="ip route $VTYSH_NETADDR $VTYSH_GATEWAY $VTYSH_DEV tag $VTYSH_TAG $VTYSH_DISTANCE $VTYSH_VRF" # delete route if the command is "del" if [ "$3" == "del" ] ; then -- cgit v1.2.3 From b17b8a0129f42c757c1e9a740664406e8da3dd42 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Sun, 16 Aug 2020 14:27:03 +0200 Subject: dhclient: T2277: remove VRF route when DHCP client exits --- src/etc/dhcp/dhclient-enter-hooks.d/03-vyos-ipwrapper | 2 +- src/etc/dhcp/dhclient-exit-hooks.d/01-vyos-cleanup | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) (limited to 'src/etc/dhcp/dhclient-enter-hooks.d/03-vyos-ipwrapper') diff --git a/src/etc/dhcp/dhclient-enter-hooks.d/03-vyos-ipwrapper b/src/etc/dhcp/dhclient-enter-hooks.d/03-vyos-ipwrapper index 1e102c2d7..d1161e704 100644 --- a/src/etc/dhcp/dhclient-enter-hooks.d/03-vyos-ipwrapper +++ b/src/etc/dhcp/dhclient-enter-hooks.d/03-vyos-ipwrapper @@ -20,7 +20,6 @@ function iptovtysh () { local VTYSH_NETADDR="" local VTYSH_GATEWAY="" local VTYSH_DEV="" - local VTYSH_VRF_NAME=$(basename /sys/class/net/eth1/upper_* | sed -e 's/upper_//') # convert default route to 0.0.0.0/0 if [ "$4" == "default" ] ; then VTYSH_NETADDR="0.0.0.0/0" @@ -43,6 +42,7 @@ function iptovtysh () { fi # Add route to VRF routing table + local VTYSH_VRF_NAME=$(basename /sys/class/net/$VTYSH_DEV/upper_* | sed -e 's/upper_//') if [ -n $VTYSH_VRF_NAME ]; then VTYSH_VRF="vrf $VTYSH_VRF_NAME" fi diff --git a/src/etc/dhcp/dhclient-exit-hooks.d/01-vyos-cleanup b/src/etc/dhcp/dhclient-exit-hooks.d/01-vyos-cleanup index 01981ad04..b768e1ae5 100644 --- a/src/etc/dhcp/dhclient-exit-hooks.d/01-vyos-cleanup +++ b/src/etc/dhcp/dhclient-exit-hooks.d/01-vyos-cleanup @@ -15,8 +15,14 @@ if [[ $reason =~ (EXPIRE|FAIL|RELEASE|STOP) ]]; then # try to delete default ip route for router in $old_routers; do - logmsg info "Deleting default route: via $router dev ${interface}" - ip -4 route del default via $router dev ${interface} + # check if we are bound to a VRF + local vrf_name=$(basename /sys/class/net/${interface}/upper_* | sed -e 's/upper_//') + if [ -n $vrf_name ]; then + vrf="vrf $vrf_name" + fi + + logmsg info "Deleting default route: via $router dev ${interface} ${vrf}" + ip -4 route del default via $router dev ${interface} ${vrf} done # delete rfc3442 routes -- cgit v1.2.3