OpenWrt – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | #!/bin/sh |
2 | |||
3 | [ -L /sbin/udhcpc ] || exit 0 |
||
4 | |||
5 | . /lib/functions.sh |
||
6 | . ../netifd-proto.sh |
||
7 | init_proto "$@" |
||
8 | |||
9 | proto_dhcp_init_config() { |
||
10 | renew_handler=1 |
||
11 | |||
12 | proto_config_add_string 'ipaddr:ipaddr' |
||
13 | proto_config_add_string 'hostname:hostname' |
||
14 | proto_config_add_string clientid |
||
15 | proto_config_add_string vendorid |
||
16 | proto_config_add_boolean 'broadcast:bool' |
||
17 | proto_config_add_boolean 'release:bool' |
||
18 | proto_config_add_string 'reqopts:list(string)' |
||
19 | proto_config_add_boolean 'defaultreqopts:bool' |
||
20 | proto_config_add_string iface6rd |
||
21 | proto_config_add_array 'sendopts:list(string)' |
||
22 | proto_config_add_boolean delegate |
||
23 | proto_config_add_string zone6rd |
||
24 | proto_config_add_string zone |
||
25 | proto_config_add_string mtu6rd |
||
26 | proto_config_add_string customroutes |
||
27 | proto_config_add_boolean classlessroute |
||
28 | } |
||
29 | |||
30 | proto_dhcp_add_sendopts() { |
||
31 | [ -n "$1" ] && append "$3" "-x $1" |
||
32 | } |
||
33 | |||
34 | proto_dhcp_setup() { |
||
35 | local config="$1" |
||
36 | local iface="$2" |
||
37 | |||
38 | local ipaddr hostname clientid vendorid broadcast release reqopts defaultreqopts iface6rd sendopts delegate zone6rd zone mtu6rd customroutes classlessroute |
||
39 | json_get_vars ipaddr hostname clientid vendorid broadcast release reqopts defaultreqopts iface6rd delegate zone6rd zone mtu6rd customroutes classlessroute |
||
40 | |||
41 | local opt dhcpopts |
||
42 | for opt in $reqopts; do |
||
43 | append dhcpopts "-O $opt" |
||
44 | done |
||
45 | |||
46 | json_for_each_item proto_dhcp_add_sendopts sendopts dhcpopts |
||
47 | |||
48 | [ -z "$hostname" ] && hostname="$(cat /proc/sys/kernel/hostname)" |
||
49 | [ "$defaultreqopts" = 0 ] && defaultreqopts="-o" || defaultreqopts= |
||
50 | [ "$broadcast" = 1 ] && broadcast="-B" || broadcast= |
||
51 | [ "$release" = 1 ] && release="-R" || release= |
||
52 | [ -n "$clientid" ] && clientid="-x 0x3d:${clientid//:/}" || clientid="-C" |
||
53 | [ -n "$iface6rd" ] && proto_export "IFACE6RD=$iface6rd" |
||
54 | [ "$iface6rd" != 0 -a -f /lib/netifd/proto/6rd.sh ] && append dhcpopts "-O 212" |
||
55 | [ -n "$zone6rd" ] && proto_export "ZONE6RD=$zone6rd" |
||
56 | [ -n "$zone" ] && proto_export "ZONE=$zone" |
||
57 | [ -n "$mtu6rd" ] && proto_export "MTU6RD=$mtu6rd" |
||
58 | [ -n "$customroutes" ] && proto_export "CUSTOMROUTES=$customroutes" |
||
59 | [ "$delegate" = "0" ] && proto_export "IFACE6RD_DELEGATE=0" |
||
60 | # Request classless route option (see RFC 3442) by default |
||
61 | [ "$classlessroute" = "0" ] || append dhcpopts "-O 121" |
||
62 | |||
63 | proto_export "INTERFACE=$config" |
||
64 | proto_run_command "$config" udhcpc \ |
||
65 | -p /var/run/udhcpc-$iface.pid \ |
||
66 | -s /lib/netifd/dhcp.script \ |
||
67 | -f -t 0 -i "$iface" \ |
||
68 | ${ipaddr:+-r $ipaddr} \ |
||
69 | ${hostname:+-x "hostname:$hostname"} \ |
||
70 | ${vendorid:+-V "$vendorid"} \ |
||
71 | $clientid $defaultreqopts $broadcast $release $dhcpopts |
||
72 | } |
||
73 | |||
74 | proto_dhcp_renew() { |
||
75 | local interface="$1" |
||
76 | # SIGUSR1 forces udhcpc to renew its lease |
||
77 | local sigusr1="$(kill -l SIGUSR1)" |
||
78 | [ -n "$sigusr1" ] && proto_kill_command "$interface" $sigusr1 |
||
79 | } |
||
80 | |||
81 | proto_dhcp_teardown() { |
||
82 | local interface="$1" |
||
83 | proto_kill_command "$interface" |
||
84 | } |
||
85 | |||
86 | add_protocol dhcp |