]> granicus.if.org Git - libnl/commitdiff
link: add support for IFLA_PHYS_SWITCH_ID
authorTobias Klauser <tklauser@distanz.ch>
Tue, 6 Dec 2016 11:03:10 +0000 (12:03 +0100)
committerTobias Klauser <tklauser@distanz.ch>
Tue, 6 Dec 2016 14:08:36 +0000 (15:08 +0100)
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
include/netlink-private/types.h
include/netlink/route/link.h
lib/route/link.c
libnl-route-3.sym

index 0bfdbd2de8337a2636477547aa19bf24143c5ff1..06eeb712c566839f41e15e03b8310332907230f5 100644 (file)
@@ -222,6 +222,7 @@ struct rtnl_link
        struct rtnl_link_af_ops *       l_af_ops;
        struct nl_data *                l_phys_port_id;
        char                            l_phys_port_name[IFNAMSIZ];
+       struct nl_data *                l_phys_switch_id;
        int                             l_ns_fd;
        pid_t                           l_ns_pid;
        struct rtnl_link_vf *           l_vf_list;
index 09f9603fc0a377b0ceb286d3605701ff095ed059..bf83b2164b5075c17a44ee99f8febab14ff97ab7 100644 (file)
@@ -236,6 +236,8 @@ extern struct nl_data *     rtnl_link_get_phys_port_id(struct rtnl_link *);
 
 extern char*   rtnl_link_get_phys_port_name(struct rtnl_link *);
 
+extern struct nl_data *        rtnl_link_get_phys_switch_id(struct rtnl_link *);
+
 extern void    rtnl_link_set_ns_fd(struct rtnl_link *, int);
 extern int     rtnl_link_get_ns_fd(struct rtnl_link *);
 extern void    rtnl_link_set_ns_pid(struct rtnl_link *, pid_t);
index 6fd2546d3eaf423772f9a0b2fa49c85d722835bf..599978a843ea295f116a69a7d68ea78bc8f59cc8 100644 (file)
@@ -68,6 +68,7 @@
 #define LINK_ATTR_VF_LIST              ((uint64_t) 1 << 33)
 #define LINK_ATTR_CARRIER_CHANGES      ((uint64_t) 1 << 34)
 #define LINK_ATTR_PHYS_PORT_NAME       ((uint64_t) 1 << 35)
+#define LINK_ATTR_PHYS_SWITCH_ID       ((uint64_t) 1 << 36)
 
 static struct nl_cache_ops rtnl_link_ops;
 static struct nl_object_ops link_obj_ops;
@@ -277,6 +278,7 @@ static void link_free_data(struct nl_object *c)
                do_foreach_af(link, af_free, NULL);
 
                nl_data_free(link->l_phys_port_id);
+               nl_data_free(link->l_phys_switch_id);
 
                if (link->ce_mask & LINK_ATTR_VF_LIST)
                        rtnl_link_sriov_free_data(link);
@@ -318,6 +320,10 @@ static int link_clone(struct nl_object *_dst, struct nl_object *_src)
                if (!(dst->l_phys_port_id = nl_data_clone(src->l_phys_port_id)))
                        return -NLE_NOMEM;
 
+       if (src->l_phys_switch_id)
+               if (!(dst->l_phys_switch_id = nl_data_clone(src->l_phys_switch_id)))
+                       return -NLE_NOMEM;
+
        if (src->ce_mask & LINK_ATTR_VF_LIST)
                if ((err = rtnl_link_sriov_clone(dst, src)) < 0)
                        return err;
@@ -353,6 +359,7 @@ struct nla_policy rtln_link_policy[IFLA_MAX+1] = {
        [IFLA_CARRIER_CHANGES]  = { .type = NLA_U32 },
        [IFLA_PHYS_PORT_ID]     = { .type = NLA_UNSPEC },
        [IFLA_PHYS_PORT_NAME]   = { .type = NLA_STRING, .maxlen = IFNAMSIZ },
+       [IFLA_PHYS_SWITCH_ID]   = { .type = NLA_UNSPEC },
        [IFLA_NET_NS_PID]       = { .type = NLA_U32 },
        [IFLA_NET_NS_FD]        = { .type = NLA_U32 },
 };
@@ -743,6 +750,15 @@ static int link_msg_parser(struct nl_cache_ops *ops, struct sockaddr_nl *who,
                link->ce_mask |= LINK_ATTR_PHYS_PORT_NAME;
        }
 
+       if (tb[IFLA_PHYS_SWITCH_ID]) {
+               link->l_phys_switch_id = nl_data_alloc_attr(tb[IFLA_PHYS_SWITCH_ID]);
+               if (link->l_phys_switch_id == NULL) {
+                       err = -NLE_NOMEM;
+                       goto errout;
+               }
+               link->ce_mask |= LINK_ATTR_PHYS_SWITCH_ID;
+       }
+
        err = pp->pp_cb((struct nl_object *) link, pp);
 errout:
        rtnl_link_af_ops_put(af_ops);
@@ -1137,6 +1153,7 @@ static const struct trans_tbl link_attrs[] = {
        __ADD(LINK_ATTR_CARRIER_CHANGES, carrier_changes),
        __ADD(LINK_ATTR_PHYS_PORT_ID, phys_port_id),
        __ADD(LINK_ATTR_PHYS_PORT_NAME, phys_port_name),
+       __ADD(LINK_ATTR_PHYS_SWITCH_ID, phys_switch_id),
        __ADD(LINK_ATTR_NS_FD, ns_fd),
        __ADD(LINK_ATTR_NS_PID, ns_pid),
        __ADD(LINK_ATTR_LINK_NETNSID, link_netnsid),
@@ -2656,6 +2673,17 @@ char *rtnl_link_get_phys_port_name(struct rtnl_link *link)
        return link->l_phys_port_name;
 }
 
+/*
+ * Return physical switch id of link object
+ * @arg link           Link object
+ *
+ * @return Physical switch id or NULL if not set.
+ */
+struct nl_data *rtnl_link_get_phys_switch_id(struct rtnl_link *link)
+{
+       return link->l_phys_switch_id;
+}
+
 void rtnl_link_set_ns_fd(struct rtnl_link *link, int fd)
 {
        link->l_ns_fd = fd;
index d235c959ad522fa0e3a45f20e6bc4d7853010e4e..17be064f68274567d7404cf080f716cfd2cff070 100644 (file)
@@ -960,6 +960,7 @@ global:
        rtnl_link_bridge_str2hwmode;
        rtnl_link_get_carrier_changes;
        rtnl_link_get_phys_port_name;
+       rtnl_link_get_phys_switch_id;
        rtnl_link_ipgre_get_pmtudisc;
        rtnl_link_is_ipgretap;
        rtnl_link_macvlan_add_macaddr;