Root/package/netifd/files/lib/netifd/proto/dhcp.sh

1#!/bin/sh
2
3. /etc/functions.sh
4. ../netifd-proto.sh
5init_proto "$@"
6
7proto_dhcp_init_config() {
8    proto_config_add_string "ipaddr"
9    proto_config_add_string "netmask"
10    proto_config_add_string "hostname"
11    proto_config_add_string "clientid"
12    proto_config_add_string "vendorid"
13    proto_config_add_boolean "broadcast"
14    proto_config_add_string "reqopts"
15}
16
17proto_dhcp_setup() {
18    local config="$1"
19    local iface="$2"
20
21    json_get_var ipaddr ipaddr
22    json_get_var hostname hostname
23    json_get_var clientid clientid
24    json_get_var vendorid vendorid
25    json_get_var broadcast broadcast
26    json_get_var reqopts reqopts
27
28    local opt dhcpopts
29    for opt in $reqopts; do
30        append dhcpopts "-O opt"
31    done
32
33    [ "$broadcast" = 1 ] && broadcast="-O broadcast" || broadcast=
34
35    proto_export "INTERFACE=$config"
36    proto_run_command "$config" udhcpc \
37        -p /var/run/udhcpc-$iface.pid \
38        -s /lib/netifd/dhcp.script \
39        -f -t 0 -i "$iface" \
40        ${ipaddr:+-r $ipaddr} \
41        ${hostname:+-H $hostname} \
42        ${clientid:+-c $clientid} \
43        ${vendorid:+-V $vendorid} \
44        $broadcast $dhcpopts
45}
46
47proto_dhcp_teardown() {
48    proto_kill_command
49}
50
51add_protocol dhcp
52
53

Archive Download this file



interactive