-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdebian-initramfs-ipv6-premount-script
84 lines (76 loc) · 1.94 KB
/
debian-initramfs-ipv6-premount-script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/sh
# Script to be placed in /etc/initramfs-tools/scripts/init-premount/ipv6
PREREQ=""
prereqs()
{
echo "$PREREQ"
}
parse_options()
{
v6opts="$1"
echo "v6opts='$v6opts'"
addr=""
gw=""
iface=""
ll=""
accept_ra=0
forwarding=0
IFS=","
for opt in $v6opts; do
case $opt in
addr=*)
addr=${opt#addr=}
;;
gw=*)
gw=${opt#gw=}
;;
iface=*)
iface=${opt#iface=}
;;
accept_ra=*)
iface=${opt#accept_ra=}
;;
ll=*)
ll=${opt#ll=}
;;
forwarding=*)
forwarding=${opt#forwarding=}
;;
esac
done
if [ ! -d "/proc/sys/net/ipv6/conf/${iface}" ]; then
log_failure_msg "IPv6: Interface ${iface} not found, sorry."
return 0
fi
log_begin_msg "IPv6: Setup IPv6 on ${iface}"
echo "${accept_ra}" > "/proc/sys/net/ipv6/conf/${iface}/accept_ra"
echo "${forwarding}" > "/proc/sys/net/ipv6/conf/${iface}/forwarding"
if [ -n "${ll}" ]; then
/sbin/ip -6 address flush dev "${iface}"
/sbin/ip -6 address add "${ll}" scope link dev "${iface}"
fi
/sbin/ip link set "${iface}" up
/sbin/ip -6 address add "${addr}" dev "${iface}"
if [ -n "${gw}" ]; then
/sbin/ip -6 route del default
/sbin/ip -6 route add default via "${gw}" dev "${iface}"
fi
log_end_msg
return 0
}
case $1 in
# get pre-requisites
prereqs)
prereqs
exit 0
;;
esac
for arg in $(cat /proc/cmdline); do
case ${arg} in
ipv6=*)
# syntax: ipv6=addr=<address>/<netmask>,gw=<gateway>,iface=<interface>,forwarding=<0/1>,accept_ra=<0/1/2>
# colons are not used as delimiters due to them being in use in ipv6 addrs
parse_options "${arg#ipv6=}"
;;
esac
done