netifd: always send DHCPv4 hostname
[openwrt/staging/chunkeey.git] / package / network / config / netifd / files / lib / netifd / proto / dhcp.sh
index 6668b49c21523400006296262594b2349463901a..143e4451b6648ac2048b782989f7bb1c50f800d8 100755 (executable)
@@ -12,6 +12,7 @@ proto_dhcp_init_config() {
        proto_config_add_string clientid
        proto_config_add_string vendorid
        proto_config_add_boolean 'broadcast:bool'
+       proto_config_add_boolean 'release:bool'
        proto_config_add_string 'reqopts:list(string)'
        proto_config_add_string iface6rd
        proto_config_add_string sendopts
@@ -19,14 +20,16 @@ proto_dhcp_init_config() {
        proto_config_add_string zone6rd
        proto_config_add_string zone
        proto_config_add_string mtu6rd
+       proto_config_add_string customroutes
+       proto_config_add_boolean classlessroute
 }
 
 proto_dhcp_setup() {
        local config="$1"
        local iface="$2"
 
-       local ipaddr hostname clientid vendorid broadcast reqopts iface6rd sendopts delegate zone6rd zone mtu6rd
-       json_get_vars ipaddr hostname clientid vendorid broadcast reqopts iface6rd sendopts delegate zone6rd zone mtu6rd
+       local ipaddr hostname clientid vendorid broadcast release reqopts iface6rd sendopts delegate zone6rd zone mtu6rd customroutes classlessroute
+       json_get_vars ipaddr hostname clientid vendorid broadcast release reqopts iface6rd sendopts delegate zone6rd zone mtu6rd customroutes classlessroute
 
        local opt dhcpopts
        for opt in $reqopts; do
@@ -37,14 +40,19 @@ proto_dhcp_setup() {
                append dhcpopts "-x $opt"
        done
 
+       [ -z "$hostname" ] && hostname="$(cat /proc/sys/kernel/hostname)"
        [ "$broadcast" = 1 ] && broadcast="-B" || broadcast=
+       [ "$release" = 1 ] && release="-R" || release=
        [ -n "$clientid" ] && clientid="-x 0x3d:${clientid//:/}" || clientid="-C"
        [ -n "$iface6rd" ] && proto_export "IFACE6RD=$iface6rd"
-       [ -n "$iface6rd" ] && append dhcpopts "-O 212"
+       [ "$iface6rd" != 0 -a -f /lib/netifd/proto/6rd.sh ] && append dhcpopts "-O 212"
        [ -n "$zone6rd" ] && proto_export "ZONE6RD=$zone6rd"
        [ -n "$zone" ] && proto_export "ZONE=$zone"
        [ -n "$mtu6rd" ] && proto_export "MTU6RD=$mtu6rd"
+       [ -n "$customroutes" ] && proto_export "CUSTOMROUTES=$customroutes"
        [ "$delegate" = "0" ] && proto_export "IFACE6RD_DELEGATE=0"
+       # Request classless route option (see RFC 3442) by default
+       [ "$classlessroute" = "0" ] || append dhcpopts "-O 121"
 
        proto_export "INTERFACE=$config"
        proto_run_command "$config" udhcpc \
@@ -52,9 +60,9 @@ proto_dhcp_setup() {
                -s /lib/netifd/dhcp.script \
                -f -t 0 -i "$iface" \
                ${ipaddr:+-r $ipaddr} \
-               ${hostname:+-H $hostname} \
-               ${vendorid:+-V $vendorid} \
-               $clientid $broadcast $dhcpopts
+               ${hostname:+-x "hostname:$hostname"} \
+               ${vendorid:+-V "$vendorid"} \
+               $clientid $broadcast $release $dhcpopts
 }
 
 proto_dhcp_renew() {