IPv6: add class support to regular IPv6 addresses
authorSteven Barth <steven@midlink.org>
Wed, 27 Nov 2013 13:52:31 +0000 (14:52 +0100)
committerSteven Barth <steven@midlink.org>
Wed, 27 Nov 2013 13:52:31 +0000 (14:52 +0100)
interface-ip.c
interface-ip.h
proto.c
scripts/netifd-proto.sh
ubus.c

index 084688c61c8e1921401784d44f3a948d5893b124..4edae2e91771ce41ac618392225d6b1132f9a7bb 100644 (file)
@@ -578,6 +578,7 @@ interface_update_proto_addr(struct vlist_tree *tree,
 
                        system_del_address(dev, a_old);
                }
+               free(a_old->pclass);
                free(a_old);
        }
 
index b36c515f3d5b1ebf12dc69dd3978882360cead65..2559bccc4adc1b946a2acce77555dd04a72b744c 100644 (file)
@@ -85,6 +85,7 @@ struct device_addr {
        /* ipv6 only */
        time_t valid_until;
        time_t preferred_until;
+       char *pclass;
 
        /* must be last */
        enum device_addr_flags flags;
diff --git a/proto.c b/proto.c
index d5e99bf3b5298878a23eb77efa5604f42b79ab7b..91219189437dd4b9feb0671e23085bdf964f58cf 100644 (file)
--- a/proto.c
+++ b/proto.c
@@ -69,6 +69,7 @@ enum {
        ADDR_PREFERRED,
        ADDR_VALID,
        ADDR_OFFLINK,
+       ADDR_CLASS,
        __ADDR_MAX
 };
 
@@ -80,6 +81,7 @@ static const struct blobmsg_policy proto_ip_addr[__ADDR_MAX] = {
        [ADDR_PREFERRED] = { .name = "preferred", .type = BLOBMSG_TYPE_INT32 },
        [ADDR_VALID] = { .name = "valid", .type = BLOBMSG_TYPE_INT32 },
        [ADDR_OFFLINK] = { .name = "offlink", .type = BLOBMSG_TYPE_BOOL },
+       [ADDR_CLASS] = { .name = "class", .type = BLOBMSG_TYPE_STRING },
 };
 
 static struct device_addr *
@@ -208,6 +210,9 @@ parse_address_item(struct blob_attr *attr, bool v6, bool ext)
                        else if (addr->preferred_until > addr->valid_until)
                                goto error;
                }
+
+               if ((cur = tb[ADDR_CLASS]))
+                       addr->pclass = strdup(blobmsg_get_string(cur));
        }
 
        return addr;
index 9f062d8a0c4495667e2c996b0e597bd52ba1bd5d..7f08b1d15c725dd45b85b919712b6bb0d6026fa6 100644 (file)
@@ -106,8 +106,9 @@ proto_add_ipv6_address() {
        local preferred="$3"
        local valid="$4"
        local offlink="$5"
+       local class="$6"
 
-       append PROTO_IP6ADDR "$address/$mask/$preferred/$valid/$offlink"
+       append PROTO_IP6ADDR "$address/$mask/$preferred/$valid/$offlink/$class"
 }
 
 proto_add_ipv4_route() {
@@ -175,6 +176,8 @@ _proto_push_ipv6_addr() {
        valid="${str%%/*}"
        str="${str#*/}"
        offlink="${str%%/*}"
+       str="${str#*/}"
+       class="${str%%/*}"
 
        json_add_object ""
        json_add_string ipaddr "$address"
@@ -182,6 +185,7 @@ _proto_push_ipv6_addr() {
        [ -n "$preferred" ] && json_add_int preferred "$preferred"
        [ -n "$valid" ] && json_add_int valid "$valid"
        [ -n "$offlink" ] && json_add_boolean offlink "$offlink"
+       [ -n "$class" ] && json_add_string class "$class"
        json_close_object
 }
 
diff --git a/ubus.c b/ubus.c
index 90636804bb6d61fb45649ddce18bf1114569d03c..340a8e417110b2cabc4b388d7da1dad1d54009e9 100644 (file)
--- a/ubus.c
+++ b/ubus.c
@@ -441,6 +441,9 @@ interface_ip_dump_address_list(struct interface_ip_settings *ip, bool v6,
                if (addr->valid_until)
                        blobmsg_add_u32(&b, "valid", addr->valid_until - now);
 
+               if (addr->pclass)
+                       blobmsg_add_string(&b, "class", addr->pclass);
+
                blobmsg_close_table(&b, a);
        }
 }