comgt: add metric, defaultroute and peerdns options for ncm protocol
[openwrt/staging/dedeckeh.git] / package / network / utils / comgt / files / ncm.sh
index 4c3f161f98a5c33d34b69b7713740a638e286fc3..1f4d8a4e7760894164c48444886987583494b258 100644 (file)
@@ -17,6 +17,9 @@ proto_ncm_init_config() {
        proto_config_add_string pincode
        proto_config_add_string delay
        proto_config_add_string mode
+       proto_config_add_string pdptype
+       proto_config_add_boolean ipv6
+       proto_config_add_defaults
 }
 
 proto_ncm_setup() {
@@ -24,8 +27,24 @@ proto_ncm_setup() {
 
        local manufacturer initialize setmode connect ifname devname devpath
 
-       local device apn auth username password pincode delay mode
-       json_get_vars device apn auth username password pincode delay mode
+       local device apn auth username password pincode delay mode pdptype ipv6 $PROTO_DEFAULT_OPTIONS
+       json_get_vars device apn auth username password pincode delay mode pdptype ipv6 $PROTO_DEFAULT_OPTIONS
+       
+       if [ "$ipv6" = 0 ]; then
+               ipv6=""
+       else
+               ipv6=1
+       fi
+       
+       [ -z "$pdptype" ] && {
+               if [ -n "$ipv6" ]; then
+                       pdptype="IPV4V6"
+               else
+                       pdptype="IP"
+               fi
+       }
+
+       [ -n "$ctl_device" ] && device=$ctl_device
 
        [ -n "$device" ] || {
                echo "No control device specified"
@@ -114,22 +133,27 @@ proto_ncm_setup() {
                return 1
        }
 
-       echo "Connected, starting DHCP"
+       echo "Connected, starting DHCP on $ifname"
        
        proto_init_update "$ifname" 1
        proto_send_update "$interface"
 
        json_init
-       json_add_string name "${interface}_dhcp"
+       json_add_string name "${interface}_4"
        json_add_string ifname "@$interface"
        json_add_string proto "dhcp"
+       proto_add_dynamic_defaults
        ubus call network add_dynamic "$(json_dump)"
 
-       json_init
-       json_add_string name "${interface}_dhcpv6"
-       json_add_string ifname "@$interface"
-       json_add_string proto "dhcpv6"
-       ubus call network add_dynamic "$(json_dump)"
+       [ -n "$ipv6" ] && {
+               json_init
+               json_add_string name "${interface}_6"
+               json_add_string ifname "@$interface"
+               json_add_string proto "dhcpv6"
+               json_add_string extendprefix 1
+               proto_add_dynamic_defaults
+               ubus call network add_dynamic "$(json_dump)"
+       }
 }
 
 proto_ncm_teardown() {