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 084688c..4edae2e 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 b36c515..2559bcc 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 d5e99bf..9121918 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 9f062d8..7f08b1d 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 9063680..340a8e4 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);
        }
 }