Add source-restricted routes
[project/netifd.git] / dummy / netifd-proto.sh
index 17efd59..6f20de9 100755 (executable)
@@ -122,8 +122,11 @@ proto_add_ipv4_address() {
 proto_add_ipv6_address() {
        local address="$1"
        local mask="$2"
+       local preferred="$3"
+       local valid="$4"
+       local offlink="$5"
 
-       append PROTO_IP6ADDR "$address/$mask"
+       append PROTO_IP6ADDR "$address/$mask/$preferred/$valid/$offlink"
 }
 
 proto_add_ipv4_route() {
@@ -131,15 +134,18 @@ proto_add_ipv4_route() {
        local mask="$2"
        local gw="$3"
 
-       append PROTO_ROUTE "$target/$mask/$gw"
+       append PROTO_ROUTE "$target/$mask/$gw//"
 }
 
 proto_add_ipv6_route() {
        local target="$1"
        local mask="$2"
        local gw="$3"
+       local metric="$4"
+       local valid="$5"
+       local source="$6"
 
-       append PROTO_ROUTE6 "$target/$mask/$gw"
+       append PROTO_ROUTE6 "$target/$mask/$gw/$metric/$valid/$source"
 }
 
 proto_add_ipv6_prefix() {
@@ -177,15 +183,24 @@ _proto_push_ipv4_addr() {
 
 _proto_push_ipv6_addr() {
        local str="$1"
-       local address mask
+       local address mask preferred valid offlink
 
        address="${str%%/*}"
        str="${str#*/}"
-       mask="$str"
+       mask="${str%%/*}"
+       str="${str#*/}"
+       preferred="${str%%/*}"
+       str="${str#*/}"
+       valid="${str%%/*}"
+       str="${str#*/}"
+       offlink="${str%%/*}"
 
        json_add_object ""
        json_add_string ipaddr "$address"
        [ -n "$mask" ] && json_add_string mask "$mask"
+       [ -n "$preferred" ] && json_add_int preferred "$preferred"
+       [ -n "$valid" ] && json_add_int valid "$valid"
+       [ -n "$offlink" ] && json_add_boolean offlink "$offlink"
        json_close_object
 }
 
@@ -198,12 +213,22 @@ _proto_push_route() {
        local target="${str%%/*}"
        str="${str#*/}"
        local mask="${str%%/*}"
-       local gw="${str#*/}"
+       str="${str#*/}"
+       local gw="${str%%/*}"
+       str="${str#*/}"
+       local metric="${str%%/*}"
+       str="${str#*/}"
+       local valid="${str%%/*}"
+       str="${str#*/}"
+       local source="${str}"
 
        json_add_object ""
        json_add_string target "$target"
        json_add_string netmask "$mask"
        [ -n "$gw" ] && json_add_string gateway "$gw"
+       [ -n "$metric" ] && json_add_int metric "$metric"
+       [ -n "$valid" ] && json_add_int valid "$valid"
+       [ -n "$source" ] && json_add_string source "$source"
        json_close_object
 }
 
@@ -313,6 +338,7 @@ proto_set_available() {
 proto_add_host_dependency() {
        local interface="$1"
        local host="$2"
+       local ifname="$3"
 
        # execute in subshell to not taint callers env
        # see tickets #11046, #11545, #11570
@@ -320,6 +346,7 @@ proto_add_host_dependency() {
                json_init
                json_add_int action 6
                json_add_string host "$host"
+               [ -n "$ifname" ] && json_add_string ifname "$ifname"
                _proto_notify "$interface" -S
        )
 }