mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-04 06:55:18 +00:00
zebra, lib: new API to get absolute netns val from relative netns val
when receiving a netlink API for an interface in a namespace, this interface may come with LINK_NSID value, which means that the interface has its link in an other namespace. Unfortunately, the link_nsid value is self to that namespace, and there is a need to know what is its associated nsid value from the default namespace point of view. The information collected previously on each namespace, can then be compared with that value to check if the link belongs to the default namespace or not. Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
This commit is contained in:
parent
20f4b2b071
commit
b1cc23b2cd
@ -584,6 +584,26 @@ int ns_socket(int domain, int type, int protocol, ns_id_t ns_id)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* if relative link_nsid matches default netns,
|
||||
* then return default absolute netns value
|
||||
* otherwise, return NS_UNKNOWN
|
||||
*/
|
||||
ns_id_t ns_id_get_absolute(ns_id_t ns_id_reference, ns_id_t link_nsid)
|
||||
{
|
||||
struct ns *ns;
|
||||
|
||||
ns = ns_lookup(ns_id_reference);
|
||||
if (!ns)
|
||||
return NS_UNKNOWN;
|
||||
|
||||
if (ns->relative_default_ns != link_nsid)
|
||||
return NS_UNKNOWN;
|
||||
|
||||
ns = ns_get_default();
|
||||
assert(ns);
|
||||
return ns->ns_id;
|
||||
}
|
||||
|
||||
ns_id_t ns_get_default_id(void)
|
||||
{
|
||||
if (default_ns)
|
||||
|
1
lib/ns.h
1
lib/ns.h
@ -181,6 +181,7 @@ extern struct ns *ns_lookup_name(const char *name);
|
||||
*/
|
||||
extern int ns_enable(struct ns *ns, void (*func)(ns_id_t, void *));
|
||||
extern struct ns *ns_get_created(struct ns *ns, char *name, ns_id_t ns_id);
|
||||
extern ns_id_t ns_id_get_absolute(ns_id_t ns_id_reference, ns_id_t link_nsid);
|
||||
extern void ns_disable(struct ns *ns);
|
||||
extern struct ns *ns_get_default(void);
|
||||
|
||||
|
@ -798,8 +798,10 @@ static int netlink_interface(struct nlmsghdr *h, ns_id_t ns_id, int startup)
|
||||
if (tb[IFLA_LINK])
|
||||
link_ifindex = *(ifindex_t *)RTA_DATA(tb[IFLA_LINK]);
|
||||
|
||||
if (tb[IFLA_LINK_NETNSID])
|
||||
if (tb[IFLA_LINK_NETNSID]) {
|
||||
link_nsid = *(ns_id_t *)RTA_DATA(tb[IFLA_LINK_NETNSID]);
|
||||
link_nsid = ns_id_get_absolute(ns_id, link_nsid);
|
||||
}
|
||||
|
||||
/* Add interface.
|
||||
* We add by index first because in some cases such as the master
|
||||
@ -1349,9 +1351,10 @@ int netlink_link_change(struct nlmsghdr *h, ns_id_t ns_id, int startup)
|
||||
if (tb[IFLA_LINK])
|
||||
link_ifindex = *(ifindex_t *)RTA_DATA(tb[IFLA_LINK]);
|
||||
|
||||
if (tb[IFLA_LINK_NETNSID])
|
||||
if (tb[IFLA_LINK_NETNSID]) {
|
||||
link_nsid = *(ns_id_t *)RTA_DATA(tb[IFLA_LINK_NETNSID]);
|
||||
|
||||
link_nsid = ns_id_get_absolute(ns_id, link_nsid);
|
||||
}
|
||||
if (tb[IFLA_IFALIAS]) {
|
||||
desc = (char *)RTA_DATA(tb[IFLA_IFALIAS]);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user