summaryrefslogtreecommitdiffstats
path: root/package/network/config/netifd/files/lib/netifd/dhcp.script
blob: b365a53528fdf4ad900ebad1f9f8b62a08825a8f (plain)
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
85
86
#!/bin/sh
[ -z "$1" ] && echo "Error: should be run by udhcpc" && exit 1

. /lib/functions.sh
. /lib/netifd/netifd-proto.sh

set_classless_routes() {
	local max=128
	local type
	while [ -n "$1" -a -n "$2" -a $max -gt 0 ]; do
		proto_add_ipv4_route "${1%%/*}" "${1##*/}" "$2"
		max=$(($max-1))
		shift 2
	done
}

setup_interface () {
	proto_init_update "*" 1
	proto_add_ipv4_address "$ip" "${subnet:-255.255.255.0}"
	# TODO: apply $broadcast

	for i in $router; do
		proto_add_ipv4_route 0.0.0.0 0 "$i"
	done

	# CIDR STATIC ROUTES (rfc3442)
	[ -n "$staticroutes" ] && set_classless_routes $staticroutes
	[ -n "$msstaticroutes" ] && set_classless_routes $msstaticroutes

	for dns in $dns; do
		proto_add_dns_server "$dns"
	done
	for domain in $domain; do
		proto_add_dns_search "$domain"
	done
	proto_send_update "$INTERFACE"

	if [ -n "$IFACE6RD" -a -n "$ip6rd" ]; then
		local v4mask="${ip6rd%% *}"
		ip6rd="${ip6rd#* }"
		local ip6rdprefixlen="${ip6rd%% *}"
		ip6rd="${ip6rd#* }"
		local ip6rdprefix="${ip6rd%% *}"
		ip6rd="${ip6rd#* }"
		local ip6rdbr="${ip6rd%% *}"

uci -q batch <<-EOF >/dev/null
set network.$IFACE6RD.proto=6rd
set network.$IFACE6RD.auto=0
set network.$IFACE6RD.peeraddr=$ip6rdbr
set network.$IFACE6RD.ip4prefixlen=$v4mask
set network.$IFACE6RD.ip6prefix=$ip6rdprefix
set network.$IFCAE6RD.ip6prefixlen=$ip6rdprefixlen
commit network
EOF

		ifdown "$IFACE6RD"
		/etc/init.d/network reload
		ifup "$IFACE6RD"
	fi

	# TODO
	# [ -n "$ntpsrv" ] && 	change_state network "$ifc" lease_ntpsrv "$ntpsrv"
	# [ -n "$timesvr" ] && 	change_state network "$ifc" lease_timesrv "$timesvr"
	# [ -n "$hostname" ] &&	change_state network "$ifc" lease_hostname "$hostname"
	# [ -n "$timezone" ] && 	change_state network "$ifc" lease_timezone "$timezone"
}

deconfig_interface() {
	proto_init_update "*" 0
	proto_send_update "$INTERFACE"
}

case "$1" in
	deconfig)
		deconfig_interface
	;;
	renew|bound)
		setup_interface
	;;
esac

# user rules
[ -f /etc/udhcpc.user ] && . /etc/udhcpc.user

exit 0