diff options
author | Cong Wang <xiyou.wangcong@gmail.com> | 2013-11-01 23:58:49 (GMT) |
---|---|---|
committer | Thomas Graf <tgraf@suug.ch> | 2013-11-06 08:55:03 (GMT) |
commit | 760bfabad8cd1947224905a95d97df7d92a0fa60 (patch) | |
tree | 3e8c69b4146bc0cfb6c237b3c4392a21e8fa874d | |
parent | 4263106728eb229cfe7886af57efbea353ca2cfa (diff) | |
download | libnl-760bfabad8cd1947224905a95d97df7d92a0fa60.zip libnl-760bfabad8cd1947224905a95d97df7d92a0fa60.tar.gz libnl-760bfabad8cd1947224905a95d97df7d92a0fa60.tar.bz2 |
add link netns support
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: Thomas Graf <tgraf@suug.ch>
-rw-r--r-- | include/netlink-private/types.h | 2 | ||||
-rw-r--r-- | include/netlink/route/link.h | 6 | ||||
-rw-r--r-- | lib/route/link.c | 36 |
3 files changed, 44 insertions, 0 deletions
diff --git a/include/netlink-private/types.h b/include/netlink-private/types.h index aef230c..3635e0f 100644 --- a/include/netlink-private/types.h +++ b/include/netlink-private/types.h @@ -191,6 +191,8 @@ struct rtnl_link /* 3 byte hole */ struct rtnl_link_af_ops * l_af_ops; struct nl_data * l_phys_port_id; + int l_ns_fd; + pid_t l_ns_pid; }; struct rtnl_ncacheinfo diff --git a/include/netlink/route/link.h b/include/netlink/route/link.h index b0430f8..5ceddcf 100644 --- a/include/netlink/route/link.h +++ b/include/netlink/route/link.h @@ -16,6 +16,7 @@ #include <netlink/cache.h> #include <netlink/addr.h> #include <linux/if.h> +#include <sys/types.h> #ifdef __cplusplus extern "C" { @@ -219,6 +220,11 @@ extern uint32_t rtnl_link_get_num_rx_queues(struct rtnl_link *); extern struct nl_data * rtnl_link_get_phys_port_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); +extern pid_t rtnl_link_get_ns_pid(struct rtnl_link *); + extern int rtnl_link_enslave_ifindex(struct nl_sock *, int, int); extern int rtnl_link_enslave(struct nl_sock *, struct rtnl_link *, struct rtnl_link *); diff --git a/lib/route/link.c b/lib/route/link.c index b758013..b03ccfe 100644 --- a/lib/route/link.c +++ b/lib/route/link.c @@ -59,6 +59,8 @@ #define LINK_ATTR_PROTINFO (1 << 26) #define LINK_ATTR_AF_SPEC (1 << 27) #define LINK_ATTR_PHYS_PORT_ID (1 << 28) +#define LINK_ATTR_NS_FD (1 << 29) +#define LINK_ATTR_NS_PID (1 << 30) static struct nl_cache_ops rtnl_link_ops; static struct nl_object_ops link_obj_ops; @@ -285,6 +287,8 @@ struct nla_policy link_policy[IFLA_MAX+1] = { [IFLA_GROUP] = { .type = NLA_U32 }, [IFLA_CARRIER] = { .type = NLA_U8 }, [IFLA_PHYS_PORT_ID] = { .type = NLA_UNSPEC }, + [IFLA_NET_NS_PID] = { .type = NLA_U32 }, + [IFLA_NET_NS_FD] = { .type = NLA_U32 }, }; static struct nla_policy link_info_policy[IFLA_INFO_MAX+1] = { @@ -607,6 +611,16 @@ static int link_msg_parser(struct nl_cache_ops *ops, struct sockaddr_nl *who, link->ce_mask |= LINK_ATTR_GROUP; } + if (tb[IFLA_NET_NS_FD]) { + link->l_ns_fd = nla_get_u32(tb[IFLA_NET_NS_FD]); + link->ce_mask |= LINK_ATTR_NS_FD; + } + + if (tb[IFLA_NET_NS_FD]) { + link->l_ns_pid = nla_get_u32(tb[IFLA_NET_NS_PID]); + link->ce_mask |= LINK_ATTR_NS_PID; + } + if (tb[IFLA_PHYS_PORT_ID]) { link->l_phys_port_id = nl_data_alloc_attr(tb[IFLA_PHYS_PORT_ID]); if (link->l_phys_port_id == NULL) { @@ -2319,6 +2333,28 @@ struct nl_data *rtnl_link_get_phys_port_id(struct rtnl_link *link) return link->l_phys_port_id; } +void rtnl_link_set_ns_fd(struct rtnl_link *link, int fd) +{ + link->l_ns_fd = fd; + link->ce_mask |= LINK_ATTR_NS_FD; +} + +int rtnl_link_get_ns_fd(struct rtnl_link *link) +{ + return link->l_ns_fd; +} + +void rtnl_link_set_ns_pid(struct rtnl_link *link, pid_t pid) +{ + link->l_ns_pid = pid; + link->ce_mask |= LINK_ATTR_NS_PID; +} + +pid_t rtnl_link_get_ns_pid(struct rtnl_link *link) +{ + return link->l_ns_pid; +} + /** @} */ /** |