parse point to point ip addresses
authorFelix Fietkau <nbd@openwrt.org>
Sun, 13 May 2012 20:16:48 +0000 (22:16 +0200)
committerFelix Fietkau <nbd@openwrt.org>
Mon, 14 May 2012 19:38:20 +0000 (21:38 +0200)
dummy/netifd-proto.sh
interface-ip.h
proto.c

index 99ad11edee0a496fd790c9727f62a2b9035e3ba2..a38f9d996075af7ff3afa95c17048de3b47b30b0 100755 (executable)
@@ -105,8 +105,9 @@ proto_add_ipv4_address() {
        local address="$1"
        local mask="$2"
        local broadcast="$3"
+       local ptp="$4"
 
-       jshn_append PROTO_IPADDR "$address/$mask/$broadcast"
+       jshn_append PROTO_IPADDR "$address/$mask/$broadcast/$ptp"
 }
 
 proto_add_ipv6_address() {
@@ -134,18 +135,21 @@ proto_add_ipv6_route() {
 
 _proto_push_ipv4_addr() {
        local str="$1"
-       local address mask broadcast
+       local address mask broadcast ptp
 
        address="${str%%/*}"
        str="${str#*/}"
        mask="${str%%/*}"
        str="${str#*/}"
-       broadcast="$str"
+       broadcast="${str%%/*}"
+       str="${str#*/}"
+       ptp="$str"
 
        json_add_object ""
        json_add_string ipaddr "$address"
        [ -n "$mask" ] && json_add_string mask "$mask"
        [ -n "$broadcast" ] && json_add_string broadcast "$broadcast"
+       [ -n "$ptp" ] && json_add_string ptp "$ptp"
        json_close_object
 }
 
index cbfcb49de4e91b209565a4f71c1f4d6990fc7257..ae5a63e2465ff0d7da64170d6c8b4b58c54eae05 100644 (file)
@@ -40,6 +40,7 @@ struct device_addr {
 
        /* ipv4 only */
        uint32_t broadcast;
+       uint32_t point_to_point;
 
        /* must be last */
        enum device_addr_flags flags;
diff --git a/proto.c b/proto.c
index ed0a0085cc7a8a2c62c2092a6284705ce1778c32..8266e81ed71d995cc201cd8f1cada82af0a4aa57 100644 (file)
--- a/proto.c
+++ b/proto.c
@@ -64,6 +64,7 @@ enum {
        ADDR_IPADDR,
        ADDR_MASK,
        ADDR_BROADCAST,
+       ADDR_PTP,
        __ADDR_MAX
 };
 
@@ -71,6 +72,7 @@ static const struct blobmsg_policy proto_ip_addr[__ADDR_MAX] = {
        [ADDR_IPADDR] = { .name = "ipaddr", .type = BLOBMSG_TYPE_STRING },
        [ADDR_MASK] = { .name = "mask", .type = BLOBMSG_TYPE_STRING },
        [ADDR_BROADCAST] = { .name = "broadcast", .type = BLOBMSG_TYPE_STRING },
+       [ADDR_PTP] = { .name = "ptp", .type = BLOBMSG_TYPE_STRING },
 };
 
 unsigned int
@@ -226,8 +228,12 @@ parse_address_item(struct blob_attr *attr, bool v6, bool ext)
        if (!inet_pton(v6 ? AF_INET6 : AF_INET, blobmsg_data(cur), &addr->addr))
                goto error;
 
-       if (!v6 && (cur = tb[ADDR_BROADCAST])) {
-               if (!inet_pton(AF_INET, blobmsg_data(cur), &addr->broadcast))
+       if (!v6) {
+               if ((cur = tb[ADDR_BROADCAST]) &&
+                   !inet_pton(AF_INET, blobmsg_data(cur), &addr->broadcast))
+                       goto error;
+               if ((cur = tb[ADDR_PTP]) &&
+                   !inet_pton(AF_INET, blobmsg_data(cur), &addr->point_to_point))
                        goto error;
        }