@@ -38,6 +38,7 @@ struct nln {
bool has_run; /* Guard for run and wait functions. */
/* Passed in by nln_create(). */
+ char *netns; /* The network namespace. */
int protocol; /* Protocol passed to nl_sock_create(). */
nln_parse_func *parse; /* Message parsing function. */
void *change; /* Change passed to parse. */
@@ -58,12 +59,16 @@ struct nln_notifier {
* Incoming messages will be parsed with 'parse' which will be passed 'change'
* as an argument. */
struct nln *
-nln_create(int protocol, nln_parse_func *parse, void *change)
+nln_create(const char *netns, int protocol, nln_parse_func *parse,
+ void *change)
{
struct nln *nln;
nln = xzalloc(sizeof *nln);
nln->notify_sock = NULL;
+ if (netns) {
+ nln->netns = xstrdup(netns);
+ }
nln->protocol = protocol;
nln->parse = parse;
nln->change = change;
@@ -84,6 +89,7 @@ nln_destroy(struct nln *nln)
if (nln) {
ovs_assert(ovs_list_is_empty(&nln->all_notifiers));
nl_sock_destroy(nln->notify_sock);
+ free(nln->netns);
free(nln);
}
}
@@ -106,7 +112,7 @@ nln_notifier_create(struct nln *nln, int multicast_group, nln_notify_func *cb,
if (!nln->notify_sock) {
struct nl_sock *sock;
- error = nl_sock_create(nln->protocol, &sock);
+ error = nl_sock_ns_create(nln->netns, nln->protocol, &sock);
if (error) {
VLOG_WARN("could not create netlink socket: %s",
ovs_strerror(error));
@@ -41,7 +41,8 @@ typedef void nln_notify_func(const void *change, void *aux);
*/
typedef int nln_parse_func(struct ofpbuf *buf, void *change);
-struct nln *nln_create(int protocol, nln_parse_func *, void *change);
+struct nln *nln_create(const char *netns, int protocol,
+ nln_parse_func *, void *change);
void nln_destroy(struct nln *);
struct nln_notifier *nln_notifier_create(struct nln *, int multicast_group,
nln_notify_func *, void *aux);
@@ -1742,7 +1742,7 @@ static struct ovs_mutex pool_mutex = OVS_MUTEX_INITIALIZER;
static struct shash pools OVS_GUARDED_BY(pool_mutex) =
SHASH_INITIALIZER(&pools);
-static int
+int
nl_sock_ns_create(const char *netns, int protocol, struct nl_sock **sockp) {
int ret, ns_fd, ns_default_fd, err;
if (netns) {
@@ -255,6 +255,7 @@ int nl_transact(const char *netns, int protocol, const struct ofpbuf *request,
struct ofpbuf **replyp);
void nl_transact_multiple(const char *netns, int protocol,
struct nl_transaction **, size_t n);
+int nl_sock_ns_create(const char *netns, int protocol, struct nl_sock **sockp);
/* Table dumping. */
#define NL_DUMP_BUFSIZE 4096
@@ -110,7 +110,8 @@ route_table_init(void)
ovs_assert(!route6_notifier);
ovs_router_init();
- nln = nln_create(NETLINK_ROUTE, route_table_parse, &rtmsg);
+ nln = nln_create(NULL, NETLINK_ROUTE,
+ route_table_parse, &rtmsg);
route_notifier =
nln_notifier_create(nln, RTNLGRP_IPV4_ROUTE,
@@ -210,7 +210,7 @@ struct nln_notifier *
rtnetlink_notifier_create(rtnetlink_notify_func *cb, void *aux)
{
if (!nln) {
- nln = nln_create(NETLINK_ROUTE, rtnetlink_parse_cb, &rtn_change);
+ nln = nln_create(NULL, NETLINK_ROUTE, rtnetlink_parse_cb, &rtn_change);
}
return nln_notifier_create(nln, RTNLGRP_LINK, (nln_notify_func *) cb, aux);
@@ -80,7 +80,7 @@ test_nl_ct_monitor(struct ovs_cmdl_context *ctx OVS_UNUSED)
unsigned i;
- nln = nln_create(NETLINK_NETFILTER, event_parse, &change);
+ nln = nln_create(NULL, NETLINK_NETFILTER, event_parse, &change);
for (i = 0; i < ARRAY_SIZE(groups); i++) {
notifiers[i] = nln_notifier_create(nln, groups[i], event_print, NULL);
extend network namespace support also to the netlink-notifier. This is needed on the OVN side for watching routes. Signed-off-by: Felix Huettner <felix.huettner@stackit.cloud> --- lib/netlink-notifier.c | 10 ++++++++-- lib/netlink-notifier.h | 3 ++- lib/netlink-socket.c | 2 +- lib/netlink-socket.h | 1 + lib/route-table.c | 3 ++- lib/rtnetlink.c | 2 +- tests/test-netlink-conntrack.c | 2 +- 7 files changed, 16 insertions(+), 7 deletions(-)