@@ -818,7 +818,8 @@ daemon_become_new_user_linux(bool access_datapath OVS_UNUSED)
if (access_datapath && !ret) {
ret = capng_update(CAPNG_ADD, cap_sets, CAP_NET_ADMIN)
- || capng_update(CAPNG_ADD, cap_sets, CAP_NET_RAW);
+ || capng_update(CAPNG_ADD, cap_sets, CAP_NET_RAW)
+ || capng_update(CAPNG_ADD, cap_sets, CAP_NET_BROADCAST);
}
} else {
ret = -1;
@@ -76,9 +76,9 @@ started by the root user accepts this argument.
.IP
On Linux, daemons will be granted CAP_IPC_LOCK and CAP_NET_BIND_SERVICES
before dropping root privileges. Daemons that interact with a datapath,
-such as \fBovs\-vswitchd\fR, will be granted two additional capabilities, namely
-CAP_NET_ADMIN and CAP_NET_RAW. The capability change will apply even if
-new user is "root".
+such as \fBovs\-vswitchd\fR, will be granted three additional capabilities,
+namely CAP_NET_ADMIN, CAP_NET_BROADCAST and CAP_NET_RAW. The capability
+change will apply even if the new user is root.
.IP
On Windows, this option is not currently supported. For security reasons,
specifying this option will cause the daemon process not to start.
@@ -107,10 +107,10 @@
On Linux, daemons will be granted <code>CAP_IPC_LOCK</code> and
<code>CAP_NET_BIND_SERVICES</code> before dropping root privileges.
Daemons that interact with a datapath, such as
- <code>ovs-vswitchd</code>, will be granted two additional
- capabilities, namely <code>CAP_NET_ADMIN</code> and
- <code>CAP_NET_RAW</code>. The capability change will apply even
- if the new user is root.
+ <code>ovs-vswitchd</code>, will be granted three additional
+ capabilities, namely <code>CAP_NET_ADMIN</code>,
+ <code>CAP_NET_BROADCAST</code> and <code>CAP_NET_RAW</code>. The
+ capability change will apply even if the new user is root.
</p>
<p>
@@ -653,6 +653,7 @@ netdev_linux_notify_sock(void)
}
}
}
+ nl_sock_listen_all_nsid(sock, true);
ovsthread_once_done(&once);
}
@@ -158,6 +158,12 @@ enum {
#define NETLINK_DROP_MEMBERSHIP 2
#endif
+/* This was introduced in v4.2. (We want our programs to support the newer
+ * kernel features even if compiled with older headers.) */
+#ifndef NETLINK_LISTEN_ALL_NSID
+#define NETLINK_LISTEN_ALL_NSID 8
+#endif
+
/* These were introduced all together in 2.6.23. (We want our programs to
* support the newer kernel features even if compiled with older headers.) */
#ifndef CTRL_ATTR_MCAST_GRP_MAX
@@ -441,6 +441,33 @@ nl_sock_join_mcgroup(struct nl_sock *sock, unsigned int multicast_group)
return 0;
}
+/* When 'enable' is true, it tries to enable 'sock' to receive netlink
+ * notifications form all network namespaces that have an nsid assigned
+ * into the network namespace where the socket has been opened. The
+ * running kernel needs to provide support for that. When 'enable' is
+ * false, it will receive netlink notifications only from the network
+ * namespace where the socket has been opened.
+ *
+ * Returns 0 if successful, otherwise a positive errno. */
+int
+nl_sock_listen_all_nsid(struct nl_sock *sock, bool enable)
+{
+ int error;
+ int val = enable ? 1 : 0;
+
+#ifndef _WIN32
+ if (setsockopt(sock->fd, SOL_NETLINK, NETLINK_LISTEN_ALL_NSID, &val,
+ sizeof val) < 0) {
+ error = errno;
+ VLOG_INFO("netlink: could not %s listening to all nsid (%s)",
+ enable ? "enable" : "disable", ovs_strerror(error));
+ return errno;
+ }
+#endif
+
+ return 0;
+}
+
#ifdef _WIN32
int
nl_sock_subscribe_packet__(struct nl_sock *sock, bool subscribe)
@@ -214,6 +214,8 @@ void nl_sock_destroy(struct nl_sock *);
int nl_sock_join_mcgroup(struct nl_sock *, unsigned int multicast_group);
int nl_sock_leave_mcgroup(struct nl_sock *, unsigned int multicast_group);
+int nl_sock_listen_all_nsid(struct nl_sock *, bool enable);
+
#ifdef _WIN32
int nl_sock_subscribe_packets(struct nl_sock *sock);
int nl_sock_unsubscribe_packets(struct nl_sock *sock);
@@ -341,6 +341,7 @@ m4_define([_OVS_VSWITCHD_START],
/netdev_linux|INFO|.*device has unknown hardware address family/d
/ofproto|INFO|datapath ID changed to fedcba9876543210/d
/dpdk|INFO|DPDK Disabled - Use other_config:dpdk-init to enable/d
+/netlink_socket|INFO|netlink: could not enable listening to all nsid/d
/netdev: Flow API/d
/tc: Using policy/d']])
])
@@ -43,6 +43,7 @@ m4_define([OVN_CONTROLLER_VTEP_START],
/vswitchd|INFO|ovs-vswitchd (Open vSwitch)/d
/reconnect|INFO|/d
/ofproto|INFO|using datapath ID/d
+/netlink_socket|INFO|netlink: could not enable listening to all nsid/d
/ofproto|INFO|datapath ID changed to fedcba9876543210/d']])
AT_CHECK([ovs-vsctl -- add-br br-vtep \
-- set bridge br-vtep datapath-type=dummy other-config:datapath-id=fedcba9876543210 other-config:hwaddr=aa:55:aa:55:00:00 protocols=[[OpenFlow10,OpenFlow11,OpenFlow12,OpenFlow13,OpenFlow14,OpenFlow15]] fail-mode=secure \
Internal ports may be moved to another network namespace and when that happens, the vswitch stops receiving netlink notifications. This patch enables the vswitch to listen to all network namespaces that have a nsid assigned into the network namespace where the socket has been opened. It requires kernel 4.2 or newer. Signed-off-by: Flavio Leitner <fbl@redhat.com> --- lib/daemon-unix.c | 3 ++- lib/daemon.man | 6 +++--- lib/daemon.xml | 8 ++++---- lib/netdev-linux.c | 1 + lib/netlink-protocol.h | 6 ++++++ lib/netlink-socket.c | 27 +++++++++++++++++++++++++++ lib/netlink-socket.h | 2 ++ tests/ofproto-macros.at | 1 + tests/ovn-controller-vtep.at | 1 + 9 files changed, 47 insertions(+), 8 deletions(-)