int ns_socket(int domain, int type, int protocol, ns_id_t ns_id)
{
struct ns *ns = ns_lookup(ns_id);
- int ret = -1;
+ int ret;
- if (!ns_is_enabled(ns)) {
+ if (!ns || !ns_is_enabled(ns)) {
errno = ENOSYS;
return -1;
}
int new = 0;
if (debug_vrf)
- zlog_debug("VRF_GET: %s(%u)", name, vrf_id);
+ zlog_debug("VRF_GET: %s(%u)",
+ name == NULL ? "(NULL)" : name, vrf_id);
/* Nothing to see, move along here */
if (!name && vrf_id == VRF_UNKNOWN)
char buf[NL_PKT_BUF_SIZE];
} req;
- struct zebra_ns *zns = zebra_ns_lookup(NS_DEFAULT);
+ struct zebra_ns *zns;
+ if (vrf_is_backend_netns())
+ zns = zebra_ns_lookup((ns_id_t)ifp->vrf_id);
+ else
+ zns = zebra_ns_lookup(NS_DEFAULT);
p = ifc->address;
memset(&req, 0, sizeof req - NL_PKT_BUF_SIZE);
zns = zebra_ns_lookup(ns_id);
ifi = NLMSG_DATA(h);
+ /* assume if not default zns, then new VRF */
if (!(h->nlmsg_type == RTM_NEWLINK || h->nlmsg_type == RTM_DELLINK)) {
/* If this is not link add/delete message so print warning. */
zlog_warn("netlink_link_change: wrong kernel message %d",
} else
zif_slave_type = ZEBRA_IF_SLAVE_OTHER;
}
-
+ if (vrf_is_backend_netns())
+ vrf_id = (vrf_id_t)ns_id;
if (ifp == NULL
|| !CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE)) {
/* Add interface notification from kernel */
void if_add_update(struct interface *ifp)
{
struct zebra_if *if_data;
+ struct zebra_ns *zns;
- if_link_per_ns(zebra_ns_lookup(NS_DEFAULT), ifp);
+ if (vrf_is_backend_netns())
+ zns = zebra_ns_lookup((ns_id_t)ifp->vrf_id);
+ else
+ zns = zebra_ns_lookup(NS_DEFAULT);
+ if_link_per_ns(zns, ifp);
if_data = ifp->info;
assert(if_data);
return -1;
}
- sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
+ sock = ns_socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE, ns_id);
if (sock < 0) {
zlog_err("Can't open %s socket: %s", nl->name,
safe_strerror(errno));
if (zserv_privs.change(ZPRIVS_RAISE))
zlog_err("routing_socket: Can't raise privileges");
- routing_sock = socket(AF_ROUTE, SOCK_RAW, 0);
+ routing_sock = ns_socket(AF_ROUTE, SOCK_RAW,
+ 0, (ns_id_t)zns->ns->ns_id);
if (routing_sock < 0) {
if (zserv_privs.change(ZPRIVS_LOWER))
#include "command.h"
#include "privs.h"
#include "vrf.h"
+#include "ns.h"
#include "zebra/interface.h"
#include "zebra/rtadv.h"
return 0;
}
-static int rtadv_make_socket(void)
+static int rtadv_make_socket(ns_id_t ns_id)
{
int sock;
int ret = 0;
zlog_err("rtadv_make_socket: could not raise privs, %s",
safe_strerror(errno));
- sock = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
+ sock = ns_socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6, ns_id);
if (zserv_privs.change(ZPRIVS_LOWER))
zlog_err("rtadv_make_socket: could not lower privs, %s",
void rtadv_init(struct zebra_ns *zns)
{
- zns->rtadv.sock = rtadv_make_socket();
+ zns->rtadv.sock = rtadv_make_socket(zns->ns_id);
}
void rtadv_terminate(struct zebra_ns *zns)