From 8e2112261c68189c2c78455c3e1f32d7f5447ab9 Mon Sep 17 00:00:00 2001
From: sarthurdev <965089+sarthurdev@users.noreply.github.com>
Date: Sat, 20 Jan 2024 22:25:06 +0100
Subject: dhcpv6: T3771: Allow installation of routes for delegated prefixes
---
src/system/on-dhcpv6-event.sh | 78 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 78 insertions(+)
create mode 100755 src/system/on-dhcpv6-event.sh
(limited to 'src/system/on-dhcpv6-event.sh')
diff --git a/src/system/on-dhcpv6-event.sh b/src/system/on-dhcpv6-event.sh
new file mode 100755
index 000000000..fcc88ae6f
--- /dev/null
+++ b/src/system/on-dhcpv6-event.sh
@@ -0,0 +1,78 @@
+#!/bin/bash
+#
+# Copyright (C) 2024 VyOS maintainers and contributors
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 or later as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+#
+#
+
+if [ $# -lt 1 ]; then
+ echo Invalid args
+ logger -s -t on-dhcpv6-event "Invalid args \"$@\""
+ exit 1
+fi
+
+action=$1
+
+case "$action" in
+ lease6_renew|lease6_recover)
+ exit 0
+ ;;
+
+ lease6_release|lease6_expire|lease6_decline)
+ ifname=$QUERY6_IFACE_NAME
+ client_ip=$LEASE6_ADDRESS
+ client_prefix_len=$LEASE6_PREFIX_LEN
+
+ if [[ "$LEASE6_TYPE" != "IA_PD" ]]; then
+ exit 0
+ fi
+
+ sudo -n /sbin/ip -6 route del ${client_ip}/${client_prefix_len} \
+ dev ${ifname} \
+ proto static
+
+ exit 0
+ ;;
+
+ leases6_committed)
+ for ((i = 0; i < $LEASES6_SIZE; i++)); do
+ ifname=$QUERY6_IFACE_NAME
+ requester_link_local=$QUERY6_REMOTE_ADDR
+ client_type_var="LEASES6_AT${i}_TYPE"
+ client_ip_var="LEASES6_AT${i}_ADDRESS"
+ client_prefix_len_var="LEASES6_AT${i}_PREFIX_LEN"
+
+ client_type=${!client_type_var}
+
+ if [[ "$client_type" != "IA_PD" ]]; then
+ continue
+ fi
+
+ client_ip=${!client_ip_var}
+ client_prefix_len=${!client_prefix_len_var}
+
+ sudo -n /sbin/ip -6 route replace ${client_ip}/${client_prefix_len} \
+ via ${requester_link_local} \
+ dev ${ifname} \
+ proto static
+ done
+
+ exit 0
+ ;;
+
+ *)
+ logger -s -t on-dhcpv6-event "Invalid command \"$1\""
+ exit 1
+ ;;
+esac
--
cgit v1.2.3
From dca220d515e6c1009b316400174382b88837df6c Mon Sep 17 00:00:00 2001
From: Chris Buechler
Date: Thu, 25 Jan 2024 16:36:33 -0600
Subject: Updates to Kea DHCPv6 PD route hook (#6)
* Fix route deletion errors when interface is missing. Clarify variable names.
---
src/system/on-dhcpv6-event.sh | 35 ++++++++++++++++++++++-------------
1 file changed, 22 insertions(+), 13 deletions(-)
(limited to 'src/system/on-dhcpv6-event.sh')
diff --git a/src/system/on-dhcpv6-event.sh b/src/system/on-dhcpv6-event.sh
index fcc88ae6f..cbb370999 100755
--- a/src/system/on-dhcpv6-event.sh
+++ b/src/system/on-dhcpv6-event.sh
@@ -31,16 +31,23 @@ case "$action" in
lease6_release|lease6_expire|lease6_decline)
ifname=$QUERY6_IFACE_NAME
- client_ip=$LEASE6_ADDRESS
- client_prefix_len=$LEASE6_PREFIX_LEN
+ lease_addr=$LEASE6_ADDRESS
+ lease_prefix_len=$LEASE6_PREFIX_LEN
if [[ "$LEASE6_TYPE" != "IA_PD" ]]; then
exit 0
fi
- sudo -n /sbin/ip -6 route del ${client_ip}/${client_prefix_len} \
- dev ${ifname} \
- proto static
+ logger -s -t on-dhcpv6-event "Processing route deletion for ${lease_addr}/${lease_prefix_len}"
+ route_cmd="sudo -n /sbin/ip -6 route del ${lease_addr}/${lease_prefix_len}"
+
+ # the ifname is not always present, like in LEASE6_VALID_LIFETIME=0 updates,
+ # but 'route del' works either way. Use interface only if there is one.
+ if [[ "$ifname" != "" ]]; then
+ route_cmd+=" dev ${ifname}"
+ fi
+ route_cmd+=" proto static"
+ eval "$route_cmd"
exit 0
;;
@@ -49,20 +56,22 @@ case "$action" in
for ((i = 0; i < $LEASES6_SIZE; i++)); do
ifname=$QUERY6_IFACE_NAME
requester_link_local=$QUERY6_REMOTE_ADDR
- client_type_var="LEASES6_AT${i}_TYPE"
- client_ip_var="LEASES6_AT${i}_ADDRESS"
- client_prefix_len_var="LEASES6_AT${i}_PREFIX_LEN"
+ lease_type_var="LEASES6_AT${i}_TYPE"
+ lease_ip_var="LEASES6_AT${i}_ADDRESS"
+ lease_prefix_len_var="LEASES6_AT${i}_PREFIX_LEN"
- client_type=${!client_type_var}
+ lease_type=${!lease_type_var}
- if [[ "$client_type" != "IA_PD" ]]; then
+ if [[ "$lease_type" != "IA_PD" ]]; then
continue
fi
- client_ip=${!client_ip_var}
- client_prefix_len=${!client_prefix_len_var}
+ lease_ip=${!lease_ip_var}
+ lease_prefix_len=${!lease_prefix_len_var}
+
+ logger -s -t on-dhcpv6-event "Processing PD route for ${lease_addr}/${lease_prefix_len}. Link local: ${requester_link_local} ifname: ${ifname}"
- sudo -n /sbin/ip -6 route replace ${client_ip}/${client_prefix_len} \
+ sudo -n /sbin/ip -6 route replace ${lease_ip}/${lease_prefix_len} \
via ${requester_link_local} \
dev ${ifname} \
proto static
--
cgit v1.2.3