Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync gold 1.978 staging #1135

Merged
merged 4 commits into from
Nov 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions scripts/firerouter_dhcpcd_record_pd
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
#!/bin/bash

prefix_and_mac_to_ipv6() {
prefix=$1
mac=$2
if [ "$(echo $prefix | grep -o ":" | wc -l)" -gt 4 ]; then
prefix=$(echo $prefix | sed 's/.$//')
fi
IFS=':'; set $mac; unset IFS
echo "$prefix$(printf %02x $((0x$1 ^ 2)))$2:${3}ff:fe$4:$5$6"
}

metric=${ifmetric:-'1024'}
reject_route_metric=$((metric - 1))

Expand All @@ -12,13 +22,15 @@ if [ -z "$default_rt_tables" ]; then
fi

pd_changed=""
self_mac=$(cat /sys/class/net/eth0/address)

case $reason in

BOUND6|REBOOT6)
pd_changed="1"
pd_id=1
pds=""
pd_self_addr=""
while [ $pd_id -lt 10 ]; do
new_prefix_name="new_dhcp6_ia_pd1_prefix${pd_id}"
eval "new_prefix=\$$new_prefix_name"
Expand All @@ -27,17 +39,28 @@ case $reason in
new_prefix_val="$new_prefix/$new_prefix_length"
if [ $new_prefix_val != "/" ]; then
pds="$pds$new_prefix_val\n"
prefix=$(echo $new_prefix_val | cut -d "/" -f 1)
pd_self_addr=$(prefix_and_mac_to_ipv6 $prefix $self_mac)
for default_rt_table in $default_rt_tables; do
sudo ip -6 r add unreachable $new_prefix_val dev lo metric $reject_route_metric table $default_rt_table
done
fi
pd_id=$((pd_id + 1))
done
echo $pds > /home/pi/.router/run/dhcpcd/$interface/delegated_prefix
prev_pd_self_addr=$(cat /dev/shm/pd_self_addr.$interface || echo "")
if [ -n "$prev_pd_self_addr" ] && [ "$prev_pd_self_addr" != "$pd_self_addr" ]; then
sudo ip -6 a del $prev_pd_self_addr dev $interface &> /dev/null
fi
if [ -n "$pd_self_addr" ] && [ -z "$nd1_addr1" ] && [ -z "$new_dhcp6_ia_na1_ia_addr1" ]; then
echo $pd_self_addr > /dev/shm/pd_self_addr.$interface
sudo ip -6 a add $pd_self_addr dev $interface &> /dev/null
fi
;;
RENEW6|REBIND6)
pd_id=1
pds=""
pd_self_addr=""
while [ $pd_id -lt 10 ]; do
old_prefix_name="old_dhcp6_ia_pd1_prefix${pd_id}"
eval "old_prefix=\$$old_prefix_name"
Expand All @@ -54,13 +77,23 @@ case $reason in
fi
if [ "$new_prefix_val" != "/" ]; then
pds="$pds$new_prefix_val\n"
prefix=$(echo $new_prefix_val | cut -d "/" -f 1)
pd_self_addr=$(prefix_and_mac_to_ipv6 $prefix $self_mac)
for default_rt_table in $default_rt_tables; do
sudo ip -6 r add unreachable $new_prefix_val dev lo metric $reject_route_metric table $default_rt_table
done
fi
pd_id=$((pd_id + 1))
done
echo $pds > /home/pi/.router/run/dhcpcd/$interface/delegated_prefix
prev_pd_self_addr=$(cat /dev/shm/pd_self_addr.$interface || echo "")
if [ -n "$prev_pd_self_addr" ] && [ "$prev_pd_self_addr" != "$pd_self_addr" ]; then
sudo ip -6 a del $prev_pd_self_addr dev $interface &> /dev/null
fi
if [ -n "$pd_self_addr" ] && [ -z "$nd1_addr1" ] && [ -z "$new_dhcp6_ia_na1_ia_addr1" ]; then
echo $pd_self_addr > /dev/shm/pd_self_addr.$interface
sudo ip -6 a add $pd_self_addr dev $interface &> /dev/null
fi
;;
esac

Expand Down
Loading