From patchwork Thu Nov 2 19:05:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Flavio Leitner X-Patchwork-Id: 833511 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3ySZpf5nBNz9sMN for ; Fri, 3 Nov 2017 06:27:06 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id E2036E2F; Thu, 2 Nov 2017 19:05:49 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 3E9CBE35 for ; Thu, 2 Nov 2017 19:05:47 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-qt0-f196.google.com (mail-qt0-f196.google.com [209.85.216.196]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 626A4463 for ; Thu, 2 Nov 2017 19:05:46 +0000 (UTC) Received: by mail-qt0-f196.google.com with SMTP id z28so630473qtz.13 for ; Thu, 02 Nov 2017 12:05:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=cddyCx6H9Z3jSA5ZgPq2czNmeDFE39uPQtQTJ2un2wU=; b=o+4xlLp8fCfE5mZqE3YTP/Cm1oL2ieNbhj9PtYcrs+abKblYCTpF5bQrwNWMIirLXW aRc0Q5zvbypVUKMD2OP2UPw7Y2lapQo+6+kp60WWY+96jOqarey8HeUD5CuI5Z4Rv6sd GahdeZ9PBMwrGnsAJDSYOiMcVjVMu1pjIsVgsKMIkhhqoZwgau8TanPCq6GAtvpu0PN/ bUPJm4B9nVrPIf8dne5T3BiV5V873CEK0j2dqBRJZgsftht4Vb3AdOJ8N/krdPOT8j8L 05Qqy0mo47LOh6gbV5LY25Clg3yaGb6QhPsA99QkXEczXdLdxMlNk6LAAM1BH8GeEGVP MU9Q== X-Gm-Message-State: AMCzsaU8xZJj2020FvXBaP1poHTlV2pRNglUj7ZE4Qrc6HqP4Yl7MpXP WcQxmwylahGI8VgCGeihbYeArfiEqvI= X-Google-Smtp-Source: ABhQp+TR+eqFZuOHK43llG2WqAG/LXClzdErNxqA8bgeiH8thB5fK0qWPNgxPHl+EIlal+7BFVRw9g== X-Received: by 10.200.46.114 with SMTP id s47mr6482391qta.165.1509649545232; Thu, 02 Nov 2017 12:05:45 -0700 (PDT) Received: from localhost ([177.40.123.73]) by smtp.gmail.com with ESMTPSA id q28sm2768079qkq.33.2017.11.02.12.05.44 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Nov 2017 12:05:44 -0700 (PDT) From: Flavio Leitner To: dev@openvswitch.org Date: Thu, 2 Nov 2017 17:05:02 -0200 Message-Id: <20171102190509.2688-2-fbl@redhat.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171102190509.2688-1-fbl@redhat.com> References: <20171102190509.2688-1-fbl@redhat.com> X-Spam-Status: No, score=0.5 required=5.0 tests=RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM autolearn=disabled version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Flavio Leitner , Jiri Benc Subject: [ovs-dev] [PATCH 1/8] netlink: provide network namespace id from a msg. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org The netlink notification's ancillary data contains the network namespace id (netnsid) needed to identify the device correctly. (ifindex and netnsid). Signed-off-by: Flavio Leitner --- configure.ac | 3 +- lib/automake.mk | 1 + lib/dpif-netlink.c | 6 +-- lib/netdev-linux.c | 2 +- lib/netlink-notifier.c | 2 +- lib/netlink-socket.c | 37 ++++++++++++--- lib/netlink-socket.h | 4 +- lib/netns.h | 119 +++++++++++++++++++++++++++++++++++++++++++++++++ utilities/nlmon.c | 2 +- 9 files changed, 162 insertions(+), 14 deletions(-) create mode 100644 lib/netns.h diff --git a/configure.ac b/configure.ac index 27425991a..522704f9d 100644 --- a/configure.ac +++ b/configure.ac @@ -113,7 +113,8 @@ AC_CHECK_MEMBERS([struct sockaddr_in6.sin6_scope_id], [], [], [[#include #include ]]) AC_CHECK_FUNCS([mlockall strnlen getloadavg statvfs getmntent_r sendmmsg]) -AC_CHECK_HEADERS([mntent.h sys/statvfs.h linux/types.h linux/if_ether.h stdatomic.h]) +AC_CHECK_HEADERS([mntent.h sys/statvfs.h linux/types.h linux/if_ether.h ]) +AC_CHECK_HEADERS([linux/net_namespace.h stdatomic.h]) AC_CHECK_HEADERS([net/if_mib.h], [], [], [[#include #include ]]) diff --git a/lib/automake.mk b/lib/automake.mk index ca1cf5dd2..e354cd96f 100644 --- a/lib/automake.mk +++ b/lib/automake.mk @@ -140,6 +140,7 @@ lib_libopenvswitch_la_SOURCES = \ lib/netflow.h \ lib/netlink.c \ lib/netlink.h \ + lib/netns.h \ lib/nx-match.c \ lib/nx-match.h \ lib/object-collection.c \ diff --git a/lib/dpif-netlink.c b/lib/dpif-netlink.c index 29001fbe4..563eb5638 100644 --- a/lib/dpif-netlink.c +++ b/lib/dpif-netlink.c @@ -1287,7 +1287,7 @@ dpif_netlink_port_poll(const struct dpif *dpif_, char **devnamep) int error; ofpbuf_use_stub(&buf, buf_stub, sizeof buf_stub); - error = nl_sock_recv(dpif->port_notifier, &buf, false); + error = nl_sock_recv(dpif->port_notifier, &buf, NULL, false); if (!error) { struct dpif_netlink_vport vport; @@ -2621,7 +2621,7 @@ dpif_netlink_recv_windows(struct dpif_netlink *dpif, uint32_t handler_id, return EAGAIN; } - error = nl_sock_recv(sock_pool[i].nl_sock, buf, false); + error = nl_sock_recv(sock_pool[i].nl_sock, buf, NULL, false); if (error == ENOBUFS) { /* ENOBUFS typically means that we've received so many * packets that the buffer overflowed. Try again @@ -2696,7 +2696,7 @@ dpif_netlink_recv__(struct dpif_netlink *dpif, uint32_t handler_id, return EAGAIN; } - error = nl_sock_recv(ch->sock, buf, false); + error = nl_sock_recv(ch->sock, buf, NULL, false); if (error == ENOBUFS) { /* ENOBUFS typically means that we've received so many * packets that the buffer overflowed. Try again diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index 2ff3e2bcc..0d03ca876 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -638,7 +638,7 @@ netdev_linux_run(const struct netdev_class *netdev_class OVS_UNUSED) struct ofpbuf buf; ofpbuf_use_stub(&buf, buf_stub, sizeof buf_stub); - error = nl_sock_recv(sock, &buf, false); + error = nl_sock_recv(sock, &buf, NULL, false); if (!error) { struct rtnetlink_change change; diff --git a/lib/netlink-notifier.c b/lib/netlink-notifier.c index 3acded418..d33904658 100644 --- a/lib/netlink-notifier.c +++ b/lib/netlink-notifier.c @@ -187,7 +187,7 @@ nln_run(struct nln *nln) int error; ofpbuf_use_stub(&buf, buf_stub, sizeof buf_stub); - error = nl_sock_recv(nln->notify_sock, &buf, false); + error = nl_sock_recv(nln->notify_sock, &buf, NULL, false); if (!error) { int group = nln->parse(&buf, nln->change); diff --git a/lib/netlink-socket.c b/lib/netlink-socket.c index ccfd55e92..08eb0c8ee 100644 --- a/lib/netlink-socket.c +++ b/lib/netlink-socket.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -607,7 +608,8 @@ nl_sock_send_seq(struct nl_sock *sock, const struct ofpbuf *msg, } static int -nl_sock_recv__(struct nl_sock *sock, struct ofpbuf *buf, bool wait) +nl_sock_recv__(struct nl_sock *sock, struct ofpbuf *buf, struct netns *ns, + bool wait) { /* We can't accurately predict the size of the data to be received. The * caller is supposed to have allocated enough space in 'buf' to handle the @@ -618,6 +620,8 @@ nl_sock_recv__(struct nl_sock *sock, struct ofpbuf *buf, bool wait) uint8_t tail[65536]; struct iovec iov[2]; struct msghdr msg; + uint8_t msgctrl[64]; + struct cmsghdr *cmsg; ssize_t retval; int error; @@ -632,6 +636,8 @@ nl_sock_recv__(struct nl_sock *sock, struct ofpbuf *buf, bool wait) memset(&msg, 0, sizeof msg); msg.msg_iov = iov; msg.msg_iovlen = 2; + msg.msg_control = msgctrl; + msg.msg_controllen = sizeof msgctrl; /* Receive a Netlink message from the kernel. * @@ -706,6 +712,23 @@ nl_sock_recv__(struct nl_sock *sock, struct ofpbuf *buf, bool wait) } #endif + if (ns) { + /* The network namespace id comes as ancillary data. For older + * kernels, this data is either not available or it might be -1, + * so it falls back to local network namespace (no id). Latest + * kernels return a valid ID only if available or nothing. */ + netns_set_local(ns); + cmsg = CMSG_FIRSTHDR(&msg); + while (cmsg != NULL) { + if (cmsg->cmsg_level == SOL_NETLINK + && cmsg->cmsg_type == NETLINK_LISTEN_ALL_NSID) { + int *id = ALIGNED_CAST(int *, CMSG_DATA(cmsg)); + netns_set_id(ns, *id); + } + cmsg = CMSG_NXTHDR(&msg, cmsg); + } + } + log_nlmsg(__func__, 0, buf->data, buf->size, sock->protocol); COVERAGE_INC(netlink_received); @@ -714,7 +737,8 @@ nl_sock_recv__(struct nl_sock *sock, struct ofpbuf *buf, bool wait) /* Tries to receive a Netlink message from the kernel on 'sock' into 'buf'. If * 'wait' is true, waits for a message to be ready. Otherwise, fails with - * EAGAIN if the 'sock' receive buffer is empty. + * EAGAIN if the 'sock' receive buffer is empty. If 'ns' is provided, the + * network namespace information will be provided. * * The caller must have initialized 'buf' with an allocation of at least * NLMSG_HDRLEN bytes. For best performance, the caller should allocate enough @@ -730,9 +754,10 @@ nl_sock_recv__(struct nl_sock *sock, struct ofpbuf *buf, bool wait) * Regardless of success or failure, this function resets 'buf''s headroom to * 0. */ int -nl_sock_recv(struct nl_sock *sock, struct ofpbuf *buf, bool wait) +nl_sock_recv(struct nl_sock *sock, struct ofpbuf *buf, struct netns *ns, + bool wait) { - return nl_sock_recv__(sock, buf, wait); + return nl_sock_recv__(sock, buf, ns, wait); } static void @@ -821,7 +846,7 @@ nl_sock_transact_multiple__(struct nl_sock *sock, } /* Receive a reply. */ - error = nl_sock_recv__(sock, buf_txn->reply, false); + error = nl_sock_recv__(sock, buf_txn->reply, NULL, false); if (error) { if (error == EAGAIN) { nl_sock_record_errors__(transactions, n, 0); @@ -1101,7 +1126,7 @@ nl_dump_refill(struct nl_dump *dump, struct ofpbuf *buffer) int error; while (!buffer->size) { - error = nl_sock_recv__(dump->sock, buffer, false); + error = nl_sock_recv__(dump->sock, buffer, NULL, false); if (error) { /* The kernel never blocks providing the results of a dump, so * error == EAGAIN means that we've read the whole thing, and diff --git a/lib/netlink-socket.h b/lib/netlink-socket.h index d3cc64288..348483fad 100644 --- a/lib/netlink-socket.h +++ b/lib/netlink-socket.h @@ -193,6 +193,7 @@ #include #include #include +#include "netns.h" #include "openvswitch/ofpbuf.h" #include "ovs-atomic.h" #include "ovs-thread.h" @@ -221,7 +222,8 @@ int nl_sock_unsubscribe_packets(struct nl_sock *sock); int nl_sock_send(struct nl_sock *, const struct ofpbuf *, bool wait); int nl_sock_send_seq(struct nl_sock *, const struct ofpbuf *, uint32_t nlmsg_seq, bool wait); -int nl_sock_recv(struct nl_sock *, struct ofpbuf *, bool wait); +int nl_sock_recv(struct nl_sock *, struct ofpbuf *, struct netns *, + bool wait); int nl_sock_drain(struct nl_sock *); diff --git a/lib/netns.h b/lib/netns.h new file mode 100644 index 000000000..2e8bd8b0c --- /dev/null +++ b/lib/netns.h @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2017 Red Hat Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef NETNS_H +#define NETNS_H 1 + +#include + +#ifdef HAVE_LINUX_NET_NAMESPACE_H +#include +#define NETNS_NOT_ASSIGNED NETNSA_NSID_NOT_ASSIGNED +#else +#define NETNS_NOT_ASSIGNED -1 +#endif + +enum netns_state { + NETNS_INVALID, /* not initialized yet */ + NETNS_LOCAL, /* local or not supported on older kernels */ + NETNS_REMOTE /* on another network namespace with valid ID */ +}; + +struct netns { + enum netns_state state; + int id; +}; + +/* Prototypes */ +static inline void netns_set_id(struct netns *ns, int id); +static inline void netns_set_invalid(struct netns *ns); +static inline bool netns_is_invalid(struct netns *ns); +static inline void netns_set_local(struct netns *ns); +static inline bool netns_is_local(struct netns *ns); +static inline bool netns_is_remote(struct netns *ns); +static inline bool netns_eq(const struct netns *a, const struct netns *b); +static inline void netns_copy(struct netns *dst, const struct netns *src); + +/* Functions */ +static inline void +netns_set_id(struct netns *ns, int id) +{ + if (!ns) { + return; + } + + if (id == NETNS_NOT_ASSIGNED) { + ns->state = NETNS_LOCAL; + } else { + ns->state = NETNS_REMOTE; + ns->id = id; + } +} + +static inline void +netns_set_invalid(struct netns *ns) +{ + ns->state = NETNS_INVALID; +} + +static inline bool +netns_is_invalid(struct netns *ns) +{ + return ns->state == NETNS_INVALID; +} + +static inline void +netns_set_local(struct netns *ns) +{ + ns->state = NETNS_LOCAL; +} + +static inline bool +netns_is_local(struct netns *ns) +{ + return (ns->state == NETNS_LOCAL); +} + +static inline bool +netns_is_remote(struct netns *ns) +{ + return (ns->state == NETNS_REMOTE); +} + +static inline void +netns_copy(struct netns *dst, const struct netns *src) +{ + if (src->state == NETNS_LOCAL || src->state == NETNS_REMOTE) { + *dst = *src; + } +} + +static inline bool +netns_eq(const struct netns *a, const struct netns *b) +{ + if (a->state == NETNS_LOCAL && b->state == NETNS_LOCAL) { + return true; + } + + if (a->state == NETNS_REMOTE && b->state == NETNS_REMOTE && + a->id == b->id) { + return true; + } + + return false; +} + +#endif diff --git a/utilities/nlmon.c b/utilities/nlmon.c index 2e16222cb..08a117b58 100644 --- a/utilities/nlmon.c +++ b/utilities/nlmon.c @@ -59,7 +59,7 @@ main(int argc OVS_UNUSED, char *argv[]) ofpbuf_use_stub(&buf, buf_stub, sizeof buf_stub); for (;;) { - error = nl_sock_recv(sock, &buf, false); + error = nl_sock_recv(sock, &buf, NULL, false); if (error == EAGAIN) { /* Nothing to do. */ } else if (error == ENOBUFS) { From patchwork Thu Nov 2 19:05:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Flavio Leitner X-Patchwork-Id: 833512 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3ySZs174m8z9sMN for ; Fri, 3 Nov 2017 06:29:09 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id C7E13E5F; Thu, 2 Nov 2017 19:05:53 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id B536AE58 for ; Thu, 2 Nov 2017 19:05:51 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-qk0-f196.google.com (mail-qk0-f196.google.com [209.85.220.196]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 61AE04CC for ; Thu, 2 Nov 2017 19:05:50 +0000 (UTC) Received: by mail-qk0-f196.google.com with SMTP id k123so641088qke.3 for ; Thu, 02 Nov 2017 12:05:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=iWDl1PAqCido74rRlHVeYOSz1hH/fNMuVbxaFkd69Jo=; b=AQMamv1F0d7l0SRMT1tXvxi5vfZFcQdkSXr4nHd91gyfnbFH6rVXVbRdpUza0hGP0X Lm00ldLVqxf5N4XEm9ltZLQ/O70MT01cMXj/F6HqFbnVMQ2maZSYhJrmmvr7/Hb1Dq9E 1f+02SuRdPauJk691CfUbGWUwH0QSlRCngUfTrmgA+oni6DG1LbBDAbqzvK9CJkXdhXj kkdc5cSQc53D2aFJwkByAXKRO+px++R+NDayFLfUPCiwRBF3RjxCdS6futEJJ8Juutl/ FbiQin6i+FCbXchtZc5cQBTor2tp4vjmxSjCXrc5bPdMEipNxT5csTnONi0ieak+Rv4z gI0w== X-Gm-Message-State: AJaThX4XImGMezurW2+SMviLMKTS+jQ082o5p3GAGfsIeR+2TvO3nGUX SjZ9nq0lH5SGehQkj1gQcoQQ0O0RExI= X-Google-Smtp-Source: ABhQp+SrzPuSsDiyFSKuQEp3v6SjjwcAflH+sdNj2uz0E3kcRp6VSPxlnMO67j/t5NsjqYMFEngMfg== X-Received: by 10.55.207.20 with SMTP id e20mr6491065qkj.1.1509649548237; Thu, 02 Nov 2017 12:05:48 -0700 (PDT) Received: from localhost ([177.40.123.73]) by smtp.gmail.com with ESMTPSA id o71sm2478106qka.74.2017.11.02.12.05.47 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Nov 2017 12:05:47 -0700 (PDT) From: Flavio Leitner To: dev@openvswitch.org Date: Thu, 2 Nov 2017 17:05:03 -0200 Message-Id: <20171102190509.2688-3-fbl@redhat.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171102190509.2688-1-fbl@redhat.com> References: <20171102190509.2688-1-fbl@redhat.com> X-Spam-Status: No, score=0.5 required=5.0 tests=RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM autolearn=disabled version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Flavio Leitner , Jiri Benc Subject: [ovs-dev] [PATCH 2/8] netdev-linux: initialize netns as invalid. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org A port might be already in another netns, so initialize it as invalid to force a state update. Signed-off-by: Flavio Leitner --- lib/netdev-linux.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index 0d03ca876..3c80690f4 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -788,6 +788,10 @@ netdev_linux_common_construct(struct netdev *netdev_) return EINVAL; } + /* The device could be in the same network namespace or in another one. + * Initialize as invalid to force a state update. */ + netns_set_invalid(&netdev->netns); + ovs_mutex_init(&netdev->mutex); return 0; } From patchwork Thu Nov 2 19:05:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Flavio Leitner X-Patchwork-Id: 833514 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3ySZv86Pwcz9sMN for ; Fri, 3 Nov 2017 06:31:00 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 7A2D3E71; Thu, 2 Nov 2017 19:05:57 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 58630E64 for ; Thu, 2 Nov 2017 19:05:53 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-qk0-f195.google.com (mail-qk0-f195.google.com [209.85.220.195]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id ECCEF463 for ; Thu, 2 Nov 2017 19:05:52 +0000 (UTC) Received: by mail-qk0-f195.google.com with SMTP id r64so653163qkc.1 for ; Thu, 02 Nov 2017 12:05:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=my0lq0LvlmyBZA7SuT2TFRLiauN5BagkWEuJtgaax0I=; b=dY8yY8bvte19T8OyUFzgSAKAOLr6eLuk8KYodMM1Sp7h87bnZ/D/UDnijHiyX5xWr2 ODG81rgH9MYTPPVZQw6C1JFNUuwt7EbvHVIT3S9Ll/e0CLI5J3Pnw16eJUXqJpZvDLT8 SPisJAZE/rfZPdCBIqkxnDtMOVCj3Udd/lHOqBvSz6s9K1iPhe+HQ6WtB8sIsLrSIWrP vWJ6AffOirmp07544D/3mba79diMZFE3rvQrSOdOU7CKLHPDTGVaxaMoBxC8kAv1wTm+ YPT6wMFnU1V9Le/Teig8eV1PdTtbo+y9S9N+Y7mBJ+VElKsrrRzDkacXyIiFk7Hja1HF UZCg== X-Gm-Message-State: AJaThX4h4d1YyMUqMNE4NCK4JzmQLyhMDG6pbDCojlTdKEuSRuFjWZxW 0BSPLoOYA7GvaTICcBMYM0o9cIU7XU8= X-Google-Smtp-Source: ABhQp+QJM+hnBDha9ODTBfdF7vkZ/DERDs9bMDRGmzhDMr4tDQCu5vuu4dVXlv09D0BNjYJR1/MNSg== X-Received: by 10.55.18.165 with SMTP id 37mr6222520qks.352.1509649551189; Thu, 02 Nov 2017 12:05:51 -0700 (PDT) Received: from localhost ([177.40.123.73]) by smtp.gmail.com with ESMTPSA id n4sm2615823qkh.8.2017.11.02.12.05.50 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Nov 2017 12:05:50 -0700 (PDT) From: Flavio Leitner To: dev@openvswitch.org Date: Thu, 2 Nov 2017 17:05:04 -0200 Message-Id: <20171102190509.2688-4-fbl@redhat.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171102190509.2688-1-fbl@redhat.com> References: <20171102190509.2688-1-fbl@redhat.com> X-Spam-Status: No, score=0.5 required=5.0 tests=RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM autolearn=disabled version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Flavio Leitner , Jiri Benc Subject: [ovs-dev] [PATCH 3/8] vport: retrieve the netnsid if available. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org Recent kernels provide the network namespace ID of a port, so use that to discover where the port currently is. Signed-off-by: Flavio Leitner --- datapath/linux/compat/include/linux/openvswitch.h | 2 ++ lib/dpif-netlink.c | 6 ++++++ lib/dpif-netlink.h | 2 ++ lib/netdev-linux.c | 20 ++++++++++++++++++++ 4 files changed, 30 insertions(+) diff --git a/datapath/linux/compat/include/linux/openvswitch.h b/datapath/linux/compat/include/linux/openvswitch.h index bc6c94b8d..d2712d05f 100644 --- a/datapath/linux/compat/include/linux/openvswitch.h +++ b/datapath/linux/compat/include/linux/openvswitch.h @@ -283,6 +283,8 @@ enum ovs_vport_attr { /* receiving upcalls */ OVS_VPORT_ATTR_STATS, /* struct ovs_vport_stats */ OVS_VPORT_ATTR_PAD, + OVS_VPORT_ATTR_IFINDEX, + OVS_VPORT_ATTR_NETNSID, __OVS_VPORT_ATTR_MAX }; diff --git a/lib/dpif-netlink.c b/lib/dpif-netlink.c index 563eb5638..81c4631f0 100644 --- a/lib/dpif-netlink.c +++ b/lib/dpif-netlink.c @@ -3065,6 +3065,7 @@ dpif_netlink_vport_from_ofpbuf(struct dpif_netlink_vport *vport, [OVS_VPORT_ATTR_STATS] = { NL_POLICY_FOR(struct ovs_vport_stats), .optional = true }, [OVS_VPORT_ATTR_OPTIONS] = { .type = NL_A_NESTED, .optional = true }, + [OVS_VPORT_ATTR_NETNSID] = { .type = NL_A_U32, .optional = true }, }; dpif_netlink_vport_init(vport); @@ -3100,6 +3101,11 @@ dpif_netlink_vport_from_ofpbuf(struct dpif_netlink_vport *vport, vport->options = nl_attr_get(a[OVS_VPORT_ATTR_OPTIONS]); vport->options_len = nl_attr_get_size(a[OVS_VPORT_ATTR_OPTIONS]); } + if (a[OVS_VPORT_ATTR_NETNSID]) { + netns_set_id(&vport->netns, nl_attr_get_u32(a[OVS_VPORT_ATTR_NETNSID])); + } else { + netns_set_local(&vport->netns); + } return 0; } diff --git a/lib/dpif-netlink.h b/lib/dpif-netlink.h index 568b81441..680a74c2f 100644 --- a/lib/dpif-netlink.h +++ b/lib/dpif-netlink.h @@ -21,6 +21,7 @@ #include #include #include "odp-netlink.h" +#include "netns.h" #include "flow.h" @@ -32,6 +33,7 @@ struct dpif_netlink_vport { /* ovs_vport header. */ int dp_ifindex; + struct netns netns; odp_port_t port_no; /* ODPP_NONE if unknown. */ enum ovs_vport_type type; diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index 3c80690f4..8ddaa8b39 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -476,6 +476,7 @@ struct netdev_linux { long long int miimon_interval; /* Miimon Poll rate. Disabled if <= 0. */ struct timer miimon_timer; + struct netns netns; /* network namespace. */ /* The following are figured out "on demand" only. They are only valid * when the corresponding VALID_* bit in 'cache_valid' is set. */ int ifindex; @@ -571,6 +572,25 @@ netdev_rxq_linux_cast(const struct netdev_rxq *rx) return CONTAINER_OF(rx, struct netdev_rxq_linux, up); } +static int +netdev_linux_netns_update(struct netdev_linux *netdev) +{ + struct netns *dev_netns = &netdev->netns; + struct dpif_netlink_vport reply; + struct ofpbuf *buf; + int error; + + error = dpif_netlink_vport_get(netdev_get_name(&netdev->up), &reply, &buf); + if (error) { + netns_set_invalid(dev_netns); + return error; + } + + netns_copy(dev_netns, &reply.netns); + ofpbuf_delete(buf); + return 0; +} + static void netdev_linux_update(struct netdev_linux *netdev, const struct rtnetlink_change *) OVS_REQUIRES(netdev->mutex); From patchwork Thu Nov 2 19:05:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Flavio Leitner X-Patchwork-Id: 833515 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3ySZwH2ThMz9sMN for ; Fri, 3 Nov 2017 06:31:59 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id D5F35E7C; Thu, 2 Nov 2017 19:05:58 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 68D32E6C for ; Thu, 2 Nov 2017 19:05:55 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-qt0-f194.google.com (mail-qt0-f194.google.com [209.85.216.194]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 0FB1F4FA for ; Thu, 2 Nov 2017 19:05:54 +0000 (UTC) Received: by mail-qt0-f194.google.com with SMTP id 1so671547qtn.3 for ; Thu, 02 Nov 2017 12:05:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=SWQbWfBZvWJ95KA7f4H2WlUWoPiJwzpdEH5ewTIL6EE=; b=Ss5KA7K+nUp+OZzDbLWumGqyaOYBwqTEVKc7gvx0Pr1MXp76XYHRwgA3FNLITrCaUd +TzqMkIO6g688jNp+KBsOVZqG5lvyjVNgsOqvohsSkyc6gY+Sgib0q0sjVtCgy0Il+uj AmtwUFvBQeOjWFAt3ZG1Hq/B8WT3v0GlQvteo3gr+/b2lDSzcjoSTw9yOSaOquzo/Kdd EGEJj2VzY8M+WXPjut9RnqGsxUerz7IkejihxSdn3ra10RpTr0C9H1EqNCRapdNQCY3+ FVVpmQiimCeuowgd5G8yYHAEBTVNT8zcXlMMY5wKe+bhIFWt7cY0Zv0lrfaavJftGMQ9 SvOg== X-Gm-Message-State: AMCzsaURgOtLBvFqjPcoT9X1XsuPkfS8Lhc5W+7vWM2+D5Lv0caqY0Cn nVsXfoPRl2CdCwuqPScAJP1jdFwLbXA= X-Google-Smtp-Source: ABhQp+RTldw776kgKtgKpyKah8eB+86gZNq9tDuVbGX19jodUVz/Jw1veBvGXe4xmXiUe9xId+bifA== X-Received: by 10.200.48.199 with SMTP id w7mr7010907qta.54.1509649554028; Thu, 02 Nov 2017 12:05:54 -0700 (PDT) Received: from localhost ([177.40.123.73]) by smtp.gmail.com with ESMTPSA id y192sm2641167qky.62.2017.11.02.12.05.53 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Nov 2017 12:05:53 -0700 (PDT) From: Flavio Leitner To: dev@openvswitch.org Date: Thu, 2 Nov 2017 17:05:05 -0200 Message-Id: <20171102190509.2688-5-fbl@redhat.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171102190509.2688-1-fbl@redhat.com> References: <20171102190509.2688-1-fbl@redhat.com> X-Spam-Status: No, score=0.5 required=5.0 tests=RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM autolearn=disabled version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Flavio Leitner , Jiri Benc Subject: [ovs-dev] [PATCH 4/8] netdev: update device info only if netns matches. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org A network device in another network namespace could have the same name, so once the socket starts listening to other network namespaces, it is necessary to confirm the netns id. Signed-off-by: Flavio Leitner --- lib/netdev-linux.c | 50 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index 8ddaa8b39..7f9387c0e 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -573,7 +573,7 @@ netdev_rxq_linux_cast(const struct netdev_rxq *rx) } static int -netdev_linux_netns_update(struct netdev_linux *netdev) +netdev_linux_netns_update__(struct netdev_linux *netdev) { struct netns *dev_netns = &netdev->netns; struct dpif_netlink_vport reply; @@ -591,7 +591,31 @@ netdev_linux_netns_update(struct netdev_linux *netdev) return 0; } -static void netdev_linux_update(struct netdev_linux *netdev, +static int +netdev_linux_netns_update(struct netdev_linux *netdev) +{ + if (netns_is_invalid(&netdev->netns)) { + return netdev_linux_netns_update__(netdev); + } + + return 0; +} + +static bool +netdev_linux_netns_is_remote(struct netdev_linux *netdev) +{ + netdev_linux_netns_update(netdev); + return netns_is_remote(&netdev->netns); +} + +static bool +netdev_linux_netns_is_eq(struct netdev_linux *netdev, struct netns *ns) +{ + netdev_linux_netns_update(netdev); + return netns_eq(&netdev->netns, ns); +} + +static void netdev_linux_update(struct netdev_linux *netdev, struct netns *, const struct rtnetlink_change *) OVS_REQUIRES(netdev->mutex); static void netdev_linux_changed(struct netdev_linux *netdev, @@ -655,10 +679,11 @@ netdev_linux_run(const struct netdev_class *netdev_class OVS_UNUSED) do { static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5); uint64_t buf_stub[4096 / 8]; + struct netns ns; struct ofpbuf buf; ofpbuf_use_stub(&buf, buf_stub, sizeof buf_stub); - error = nl_sock_recv(sock, &buf, NULL, false); + error = nl_sock_recv(sock, &buf, &ns, false); if (!error) { struct rtnetlink_change change; @@ -677,7 +702,7 @@ netdev_linux_run(const struct netdev_class *netdev_class OVS_UNUSED) struct netdev_linux *netdev = netdev_linux_cast(netdev_); ovs_mutex_lock(&netdev->mutex); - netdev_linux_update(netdev, &change); + netdev_linux_update(netdev, &ns, &change); ovs_mutex_unlock(&netdev->mutex); } netdev_close(netdev_); @@ -744,11 +769,11 @@ netdev_linux_changed(struct netdev_linux *dev, } static void -netdev_linux_update(struct netdev_linux *dev, - const struct rtnetlink_change *change) +netdev_linux_update__(struct netdev_linux *dev, + const struct rtnetlink_change *change) OVS_REQUIRES(dev->mutex) { - if (rtnetlink_type_is_rtnlgrp_link(change->nlmsg_type)){ + if (rtnetlink_type_is_rtnlgrp_link(change->nlmsg_type)) { if (change->nlmsg_type == RTM_NEWLINK) { /* Keep drv-info, and ip addresses. */ netdev_linux_changed(dev, change->ifi_flags, @@ -772,6 +797,7 @@ netdev_linux_update(struct netdev_linux *dev, dev->get_ifindex_error = 0; } else { netdev_linux_changed(dev, change->ifi_flags, 0); + netns_set_invalid(&dev->netns); } } else if (rtnetlink_type_is_rtnlgrp_addr(change->nlmsg_type)) { /* Invalidates in4, in6. */ @@ -781,6 +807,16 @@ netdev_linux_update(struct netdev_linux *dev, } } +static void +netdev_linux_update(struct netdev_linux *dev, struct netns *ns, + const struct rtnetlink_change *change) + OVS_REQUIRES(dev->mutex) +{ + if (netdev_linux_netns_is_eq(dev, ns)) { + netdev_linux_update__(dev, change); + } +} + static struct netdev * netdev_linux_alloc(void) { From patchwork Thu Nov 2 19:05:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Flavio Leitner X-Patchwork-Id: 833516 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3ySZwr6BPHz9sMN for ; Fri, 3 Nov 2017 06:32:28 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id AEFB3E82; Thu, 2 Nov 2017 19:06:01 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 18E49E74 for ; Thu, 2 Nov 2017 19:06:00 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-qk0-f193.google.com (mail-qk0-f193.google.com [209.85.220.193]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 9F691463 for ; Thu, 2 Nov 2017 19:05:59 +0000 (UTC) Received: by mail-qk0-f193.google.com with SMTP id 17so624065qkq.8 for ; Thu, 02 Nov 2017 12:05:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=nvYtpdm5+uAA31xCu6TSShlWCbkJU3o0Js4mgi1V2N0=; b=TiAErcHusj+XebyiP5nmDxdVFqaSZZU+fJMsvT9e/QfF5NzwCav2Wt2Fxza8R8IYfD R2LYfmOlOk2TgOil5nKwlVv+GkJIYTy7AaLGnDqPnQTyEZUcZt4utqQFIdYTeNdjj9Aw 4igfISWAMyRfuEKvAr2GRU7AFBLD29ecwZFz/u79/JQ/ymwKbs4q/C7WvHG9e9RVNszg tWpwd1TTqAHYG026w7LUqJTFY/AfZDgnojo6j9TxBPWA+P3PkVRajpL+uxcqr2FMX4rn 2MYwfaGZZrjrjYy0jApySwRuZmGc7kSb/h59AT3Z5E8AxsrytRJyNpLDKqPiVIM6m/c/ htbg== X-Gm-Message-State: AMCzsaVGTwuFUCI/JsPIj+aSFYH9OvWc9q+5eh2Wv+N2Q1Y4Ha6KyTRb 2ZBaQCsdkwm8EZXpZbvZnq3EULvO0rs= X-Google-Smtp-Source: ABhQp+Tq+WJnfth0t1OtRrhIU9XrdwN+Zuitd/lLR4komRXmQsEwp4VSPoPVUfdQ5Zj0joXsRbhCpw== X-Received: by 10.55.158.78 with SMTP id h75mr5964469qke.355.1509649557151; Thu, 02 Nov 2017 12:05:57 -0700 (PDT) Received: from localhost ([177.40.123.73]) by smtp.gmail.com with ESMTPSA id i27sm2575048qtc.91.2017.11.02.12.05.56 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Nov 2017 12:05:56 -0700 (PDT) From: Flavio Leitner To: dev@openvswitch.org Date: Thu, 2 Nov 2017 17:05:06 -0200 Message-Id: <20171102190509.2688-6-fbl@redhat.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171102190509.2688-1-fbl@redhat.com> References: <20171102190509.2688-1-fbl@redhat.com> X-Spam-Status: No, score=0.5 required=5.0 tests=RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM autolearn=disabled version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Flavio Leitner , Jiri Benc Subject: [ovs-dev] [PATCH 5/8] netdev-linux: use netlink to update netdev. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org The ioctl interface doesn't support network namespaces, so try updating the netdev using netlink message instead. To provide backwards compatibility, fall back to the previous method if netlink isn't supported or fails. Signed-off-by: Flavio Leitner --- lib/netdev-linux.c | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 104 insertions(+), 3 deletions(-) diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index 7f9387c0e..0250b0987 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -86,6 +86,9 @@ COVERAGE_DEFINE(netdev_get_ethtool); COVERAGE_DEFINE(netdev_set_ethtool); +#ifndef IFLA_IF_NETNSID +#define IFLA_IF_NETNSID 0x45 +#endif /* These were introduced in Linux 2.6.14, so they might be missing if we have * old headers. */ #ifndef ADVERTISED_Pause @@ -615,6 +618,7 @@ netdev_linux_netns_is_eq(struct netdev_linux *netdev, struct netns *ns) return netns_eq(&netdev->netns, ns); } +static int netdev_linux_update_via_netlink(struct netdev_linux *); static void netdev_linux_update(struct netdev_linux *netdev, struct netns *, const struct rtnetlink_change *) OVS_REQUIRES(netdev->mutex); @@ -1435,6 +1439,11 @@ netdev_linux_get_etheraddr(const struct netdev *netdev_, struct eth_addr *mac) ovs_mutex_lock(&netdev->mutex); if (!(netdev->cache_valid & VALID_ETHERADDR)) { + netdev_linux_update_via_netlink(netdev); + } + + if (!(netdev->cache_valid & VALID_ETHERADDR)) { + /* Fall back to ioctl if netlink fails */ netdev->ether_addr_error = get_etheraddr(netdev_get_name(netdev_), &netdev->etheraddr); netdev->cache_valid |= VALID_ETHERADDR; @@ -1455,6 +1464,11 @@ netdev_linux_get_mtu__(struct netdev_linux *netdev, int *mtup) int error; if (!(netdev->cache_valid & VALID_MTU)) { + netdev_linux_update_via_netlink(netdev); + } + + if (!(netdev->cache_valid & VALID_MTU)) { + /* Fall back to ioctl if netlink fails */ struct ifreq ifr; netdev->netdev_mtu_error = af_inet_ifreq_ioctl( @@ -2867,12 +2881,21 @@ netdev_linux_update_flags(struct netdev *netdev_, enum netdev_flags off, enum netdev_flags on, enum netdev_flags *old_flagsp) { struct netdev_linux *netdev = netdev_linux_cast(netdev_); - int error; + int error = 0; ovs_mutex_lock(&netdev->mutex); - error = update_flags(netdev, off, on, old_flagsp); + if (on || off) { + /* Changing flags over netlink isn't support yet. */ + error = update_flags(netdev, off, on, old_flagsp); + } else { + /* Try reading flags over netlink, or fall back to ioctl. */ + if (!netdev_linux_update_via_netlink(netdev)) { + *old_flagsp = iff_to_nd_flags(netdev->ifi_flags); + } else { + error = update_flags(netdev, off, on, old_flagsp); + } + } ovs_mutex_unlock(&netdev->mutex); - return error; } @@ -5515,6 +5538,11 @@ get_ifindex(const struct netdev *netdev_, int *ifindexp) struct netdev_linux *netdev = netdev_linux_cast(netdev_); if (!(netdev->cache_valid & VALID_IFINDEX)) { + netdev_linux_update_via_netlink(netdev); + } + + if (!(netdev->cache_valid & VALID_IFINDEX)) { + /* Fall back to ioctl if netlink fails */ int ifindex = linux_get_ifindex(netdev_get_name(netdev_)); if (ifindex < 0) { @@ -5532,6 +5560,79 @@ get_ifindex(const struct netdev *netdev_, int *ifindexp) } static int +netdev_linux_update_via_netlink(struct netdev_linux *netdev) +{ + struct ofpbuf request; + struct ofpbuf *reply; + struct rtnetlink_change chg; + struct rtnetlink_change *change = &chg; + int error; + + ofpbuf_init(&request, 0); + nl_msg_put_nlmsghdr(&request, + sizeof(struct ifinfomsg) + NL_ATTR_SIZE(IFNAMSIZ), + RTM_GETLINK, NLM_F_REQUEST); + ofpbuf_put_zeros(&request, sizeof(struct ifinfomsg)); + + /* The correct identifiers for a Linux device are netnsid and ifindex, + * but ifindex changes as the port is moved to another network namespace + * and the interface name statically stored in ovsdb. */ + nl_msg_put_string(&request, IFLA_IFNAME, netdev_get_name(&netdev->up)); + if (netdev_linux_netns_is_remote(netdev)) { + nl_msg_push_u32(&request, IFLA_IF_NETNSID, netdev->netns.id); + } + error = nl_transact(NETLINK_ROUTE, &request, &reply); + ofpbuf_uninit(&request); + if (error) { + ofpbuf_delete(reply); + return error; + } + + if (rtnetlink_parse(reply, change) + && change->nlmsg_type == RTM_NEWLINK) { + bool changed = false; + error = 0; + + /* Update netdev from rtnl msg and increment its seq if needed. */ + if ((change->ifi_flags ^ netdev->ifi_flags) & IFF_RUNNING) { + netdev->carrier_resets++; + changed = true; + } + if (change->ifi_flags != netdev->ifi_flags) { + netdev->ifi_flags = change->ifi_flags; + changed = true; + } + if (change->mtu && change->mtu != netdev->mtu) { + netdev->mtu = change->mtu; + netdev->cache_valid |= VALID_MTU; + netdev->netdev_mtu_error = 0; + changed = true; + } + if (!eth_addr_is_zero(change->mac) + && !eth_addr_equals(change->mac, netdev->etheraddr)) { + netdev->etheraddr = change->mac; + netdev->cache_valid |= VALID_ETHERADDR; + netdev->ether_addr_error = 0; + changed = true; + } + if (change->if_index != netdev->ifindex) { + netdev->ifindex = change->if_index; + netdev->cache_valid |= VALID_IFINDEX; + netdev->get_ifindex_error = 0; + changed = true; + } + if (changed) { + netdev_change_seq_changed(&netdev->up); + } + } else { + error = EINVAL; + } + + ofpbuf_delete(reply); + return error; +} + +static int get_etheraddr(const char *netdev_name, struct eth_addr *ea) { struct ifreq ifr; From patchwork Thu Nov 2 19:05:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Flavio Leitner X-Patchwork-Id: 833517 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3ySZxP5NMmz9sMN for ; Fri, 3 Nov 2017 06:32:57 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 889B7E74; Thu, 2 Nov 2017 19:06:04 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id AEB3AE0D for ; Thu, 2 Nov 2017 19:06:01 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-qt0-f194.google.com (mail-qt0-f194.google.com [209.85.216.194]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 2BD5F463 for ; Thu, 2 Nov 2017 19:06:01 +0000 (UTC) Received: by mail-qt0-f194.google.com with SMTP id p1so674069qtg.2 for ; Thu, 02 Nov 2017 12:06:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=kn1TiynPKG63hCU13LIMxhwJUfVa0hluFdVCTlx7vpk=; b=ZhHfnvnZWtLm/xyLvgd+aSweuoBF752wzJ8P6jzmVCWxJfCEpWC/CkvPbED6GBtVei bTwc2IXZ5QDeRxsZWxoOcB+C0RPSr6oA2xxyPFio0gPi8Ei0Li0WN/DsIZeEIOc3uvzr ta1nbvRFVjPyHZ2poiDenvflexpQYI9sWYELT2CSwwbM6WF6yuuHEvKW4akO8O5pTMvX UfJUiOZ32kOCK+0ePXjjfKqpje3wGceLl1ZKX/ysYzv8rn99gTFxD2QDryvGwc+6FGkX smR14B3u7Kiyi/9ztl3+I/YudBNDMT59LUxWXfAt2rXN9XlEUFFrBYLf/SavGPixOerX vp4w== X-Gm-Message-State: AMCzsaU20e4lD63oUw6yoaIkokqfkS0dyk6puwq+jPy1s45CFhy+7t5l k44zhsBjQ5C8pVLn05oCztCqM7/agTk= X-Google-Smtp-Source: ABhQp+RQdJYGw5zaJKDPdjJIHm+izBhUy6KSoxINQaS5gWqsLHR3QfCzNCjg5aAHOZn7BqqIVKJM4g== X-Received: by 10.200.40.202 with SMTP id j10mr6350858qtj.301.1509649560069; Thu, 02 Nov 2017 12:06:00 -0700 (PDT) Received: from localhost ([177.40.123.73]) by smtp.gmail.com with ESMTPSA id b26sm2536448qtc.39.2017.11.02.12.05.59 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Nov 2017 12:05:59 -0700 (PDT) From: Flavio Leitner To: dev@openvswitch.org Date: Thu, 2 Nov 2017 17:05:07 -0200 Message-Id: <20171102190509.2688-7-fbl@redhat.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171102190509.2688-1-fbl@redhat.com> References: <20171102190509.2688-1-fbl@redhat.com> X-Spam-Status: No, score=0.5 required=5.0 tests=RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM autolearn=disabled version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Flavio Leitner , Jiri Benc Subject: [ovs-dev] [PATCH 6/8] netlink linux: enable listening to all nsids X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org 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 --- 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(-) diff --git a/lib/daemon-unix.c b/lib/daemon-unix.c index 967a28432..be6d29cbe 100644 --- a/lib/daemon-unix.c +++ b/lib/daemon-unix.c @@ -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; diff --git a/lib/daemon.man b/lib/daemon.man index 820a09903..68c0a312d 100644 --- a/lib/daemon.man +++ b/lib/daemon.man @@ -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. diff --git a/lib/daemon.xml b/lib/daemon.xml index 5cb447c49..1b5e8acae 100644 --- a/lib/daemon.xml +++ b/lib/daemon.xml @@ -107,10 +107,10 @@ 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 - ovs-vswitchd, will be granted two additional - capabilities, namely CAP_NET_ADMIN and - CAP_NET_RAW. The capability change will apply even - if the new user is root. + ovs-vswitchd, 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.

diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index 0250b0987..b40b7b920 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -653,6 +653,7 @@ netdev_linux_notify_sock(void) } } } + nl_sock_listen_all_nsid(sock, true); ovsthread_once_done(&once); } diff --git a/lib/netlink-protocol.h b/lib/netlink-protocol.h index a7b9a65fa..c0617dfad 100644 --- a/lib/netlink-protocol.h +++ b/lib/netlink-protocol.h @@ -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 diff --git a/lib/netlink-socket.c b/lib/netlink-socket.c index 08eb0c8ee..7c037ca57 100644 --- a/lib/netlink-socket.c +++ b/lib/netlink-socket.c @@ -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) diff --git a/lib/netlink-socket.h b/lib/netlink-socket.h index 348483fad..deac8d244 100644 --- a/lib/netlink-socket.h +++ b/lib/netlink-socket.h @@ -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); diff --git a/tests/ofproto-macros.at b/tests/ofproto-macros.at index 38449db32..5657f0f87 100644 --- a/tests/ofproto-macros.at +++ b/tests/ofproto-macros.at @@ -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']]) ]) diff --git a/tests/ovn-controller-vtep.at b/tests/ovn-controller-vtep.at index 9b9e42115..f56a98396 100644 --- a/tests/ovn-controller-vtep.at +++ b/tests/ovn-controller-vtep.at @@ -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 \ From patchwork Thu Nov 2 19:05:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Flavio Leitner X-Patchwork-Id: 833518 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3ySZy83RDSz9sNd for ; Fri, 3 Nov 2017 06:33:36 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 8824AE90; Thu, 2 Nov 2017 19:06:07 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 9E0BDE0D for ; Thu, 2 Nov 2017 19:06:05 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-qk0-f193.google.com (mail-qk0-f193.google.com [209.85.220.193]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 4F5AE484 for ; Thu, 2 Nov 2017 19:06:05 +0000 (UTC) Received: by mail-qk0-f193.google.com with SMTP id f199so643839qke.2 for ; Thu, 02 Nov 2017 12:06:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=TQXit8qDhtRYsujwWE9pdFZW5PHF3bRLOOo60Illl0M=; b=XSN+gprDSY3H4m+ofHXHyTWE736vClC2n7iYZVTtRJ3054cgwIgBQwygvfkS/cklo2 lyFQNV/h3dEDha2GT0HwdI5wtbI4aNNZ2WJpvlu/4CvQyW8BfnOAlapihr9KGSc17HnQ GqryjnqQAqIT32s4G+ek3+i4ccvq/X59zlD0b8lYbPNj/TqUkJa5neFbpR4LV+H8odrB 3LajS/dxJnmMclufnDdrJyQZPBQqkiiHrjLZtzz5qLQIHVFVZbbvAi0gMgmEAlBy1RbH e39t25ieeHQ9XwpGAvoLrmHpdQt2wxWVGSSIv5XdXE1I7PM5y2TN1TGXa07M9wG6EmoD /IJg== X-Gm-Message-State: AMCzsaUTRNZM1+bDGBQ8cUdV+oasKzve7tHGhiUa8ad3dzZnhB2rxH0i b3JNXQmhcmJJ95FFUqrYLJXpaKaK6lA= X-Google-Smtp-Source: ABhQp+TBg83l96igMYQQJF6yBSTNXr0i93Ggl6dtRXc/eMNhmwCqrXrZr8GheKxxAyGAsq++WuD/WA== X-Received: by 10.55.0.136 with SMTP id t8mr6374692qkg.286.1509649562989; Thu, 02 Nov 2017 12:06:02 -0700 (PDT) Received: from localhost ([177.40.123.73]) by smtp.gmail.com with ESMTPSA id t93sm2481371qtd.45.2017.11.02.12.06.02 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Nov 2017 12:06:02 -0700 (PDT) From: Flavio Leitner To: dev@openvswitch.org Date: Thu, 2 Nov 2017 17:05:08 -0200 Message-Id: <20171102190509.2688-8-fbl@redhat.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171102190509.2688-1-fbl@redhat.com> References: <20171102190509.2688-1-fbl@redhat.com> X-Spam-Status: No, score=0.5 required=5.0 tests=RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM autolearn=disabled version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Flavio Leitner , Jiri Benc Subject: [ovs-dev] [PATCH 7/8] nlmon: added netns support. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org Signed-off-by: Flavio Leitner --- utilities/nlmon.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/utilities/nlmon.c b/utilities/nlmon.c index 08a117b58..609b152f9 100644 --- a/utilities/nlmon.c +++ b/utilities/nlmon.c @@ -41,6 +41,7 @@ main(int argc OVS_UNUSED, char *argv[]) { uint64_t buf_stub[4096 / 64]; struct nl_sock *sock; + struct netns ns; struct ofpbuf buf; int error; @@ -57,9 +58,10 @@ main(int argc OVS_UNUSED, char *argv[]) ovs_fatal(error, "could not join RTNLGRP_LINK multicast group"); } + nl_sock_listen_all_nsid(sock, true); ofpbuf_use_stub(&buf, buf_stub, sizeof buf_stub); for (;;) { - error = nl_sock_recv(sock, &buf, NULL, false); + error = nl_sock_recv(sock, &buf, &ns, false); if (error == EAGAIN) { /* Nothing to do. */ } else if (error == ENOBUFS) { @@ -123,6 +125,11 @@ main(int argc OVS_UNUSED, char *argv[]) } } printf("\n"); + if (netns_is_remote(&ns)) { + printf("\tnetns id: %d\n", ns.id); + } else { + printf("\tnetns id: local\n"); + } if (attrs[IFLA_MASTER]) { uint32_t idx = nl_attr_get_u32(attrs[IFLA_MASTER]); char ifname[IFNAMSIZ]; From patchwork Thu Nov 2 19:05:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Flavio Leitner X-Patchwork-Id: 833519 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3ySZyj5xdNz9sMN for ; Fri, 3 Nov 2017 06:34:05 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 54950E8F; Thu, 2 Nov 2017 19:06:09 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id D2AE9E84 for ; Thu, 2 Nov 2017 19:06:07 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-qt0-f194.google.com (mail-qt0-f194.google.com [209.85.216.194]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 2AF2F463 for ; Thu, 2 Nov 2017 19:06:07 +0000 (UTC) Received: by mail-qt0-f194.google.com with SMTP id z28so631608qtz.13 for ; Thu, 02 Nov 2017 12:06:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=psU8SjEtr+57Rdt3NuB0/eKiuvLxHa9JvLOg9n9kXjk=; b=ZIH2UjM3HinTefTMckCHKXCwlccKGg1OWWjZ4cNSEv0ND8hfM6LMVQbFNUYUPJ5cZk QGjqOFuFSLmfUPyiP6pXk7FPX3CZjKKO238IZhhLcZ1dr/YFi98pt6LNeR+rk5a8/ZNj 9fO/FuSuc85+CupU3I4gx/5/+dU+sGrQJtSydqBRKHx495YC2KkRuJftsirhAQ7fMA7r 1IvQ0Ns3j1ou7qyXxr31Ew7ttvL+xNntQrBBzrIOvWtzZqDuOOCuPMNB1P2jw4OzfF/w fGDfmvMr6JDYsaNIKXkzapmxCmpMJ7y1pzfJGny5Qb4nE7XVjmPujxPKK0tk86C59ooZ J9GA== X-Gm-Message-State: AMCzsaVyxH0tKysDX2JaFF3yhrPSnOwD6CaavRdzTU6zseXmeDd9/12Q lfIP5Ej6isNm40kX2Hag47nIOBareXw= X-Google-Smtp-Source: ABhQp+S2ZiHlgL+Y+VsUDIxYR78XacAc3BmIp5VPPcCrOwCDNoUXqsMuppiVzGib19Ubh06sPXzlpg== X-Received: by 10.200.28.42 with SMTP id a39mr6734930qtk.126.1509649566129; Thu, 02 Nov 2017 12:06:06 -0700 (PDT) Received: from localhost ([177.40.123.73]) by smtp.gmail.com with ESMTPSA id u123sm2479274qkh.25.2017.11.02.12.06.05 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 02 Nov 2017 12:06:05 -0700 (PDT) From: Flavio Leitner To: dev@openvswitch.org Date: Thu, 2 Nov 2017 17:05:09 -0200 Message-Id: <20171102190509.2688-9-fbl@redhat.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171102190509.2688-1-fbl@redhat.com> References: <20171102190509.2688-1-fbl@redhat.com> X-Spam-Status: No, score=0.5 required=5.0 tests=RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, T_FILL_THIS_FORM_SHORT autolearn=disabled version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Flavio Leitner , Jiri Benc Subject: [ovs-dev] [PATCH 8/8] netdev-linux: fail ops not supporting remote netns. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org When the netdev is in another namespace and the operation doesn't support network namespaces, return the correct error. Signed-off-by: Flavio Leitner --- lib/netdev-linux.c | 134 +++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 120 insertions(+), 14 deletions(-) diff --git a/lib/netdev-linux.c b/lib/netdev-linux.c index b40b7b920..1d948c956 100644 --- a/lib/netdev-linux.c +++ b/lib/netdev-linux.c @@ -1341,6 +1341,11 @@ netdev_linux_send(struct netdev *netdev_, int qid OVS_UNUSED, int sock = 0; if (!is_tap_netdev(netdev_)) { + if (netdev_linux_netns_is_remote(netdev_linux_cast(netdev_))) { + error = EOPNOTSUPP; + goto free_batch; + } + sock = af_packet_sock(); if (sock < 0) { error = -sock; @@ -1400,6 +1405,10 @@ netdev_linux_set_etheraddr(struct netdev *netdev_, const struct eth_addr mac) int error; ovs_mutex_lock(&netdev->mutex); + if (netdev_linux_netns_is_remote(netdev)) { + error = EOPNOTSUPP; + goto exit; + } if (netdev->cache_valid & VALID_ETHERADDR) { error = netdev->ether_addr_error; @@ -1513,6 +1522,11 @@ netdev_linux_set_mtu(struct netdev *netdev_, int mtu) int error; ovs_mutex_lock(&netdev->mutex); + if (netdev_linux_netns_is_remote(netdev)) { + error = EOPNOTSUPP; + goto exit; + } + if (netdev->cache_valid & VALID_MTU) { error = netdev->netdev_mtu_error; if (error || netdev->mtu == mtu) { @@ -1542,9 +1556,14 @@ netdev_linux_get_ifindex(const struct netdev *netdev_) int ifindex, error; ovs_mutex_lock(&netdev->mutex); + if (netdev_linux_netns_is_remote(netdev)) { + error = EOPNOTSUPP; + goto exit; + } error = get_ifindex(netdev_, &ifindex); - ovs_mutex_unlock(&netdev->mutex); +exit: + ovs_mutex_unlock(&netdev->mutex); return error ? -error : ifindex; } @@ -2085,6 +2104,11 @@ netdev_linux_get_features(const struct netdev *netdev_, int error; ovs_mutex_lock(&netdev->mutex); + if (netdev_linux_netns_is_remote(netdev)) { + error = EOPNOTSUPP; + goto exit; + } + netdev_linux_read_features(netdev); if (!netdev->get_features_error) { *current = netdev->current; @@ -2093,8 +2117,9 @@ netdev_linux_get_features(const struct netdev *netdev_, *peer = 0; /* XXX */ } error = netdev->get_features_error; - ovs_mutex_unlock(&netdev->mutex); +exit: + ovs_mutex_unlock(&netdev->mutex); return error; } @@ -2110,6 +2135,12 @@ netdev_linux_set_advertisements(struct netdev *netdev_, ovs_mutex_lock(&netdev->mutex); COVERAGE_INC(netdev_get_ethtool); + + if (netdev_linux_netns_is_remote(netdev)) { + error = EOPNOTSUPP; + goto exit; + } + memset(&ecmd, 0, sizeof ecmd); error = netdev_linux_do_ethtool(netdev_get_name(netdev_), &ecmd, ETHTOOL_GSET, "ETHTOOL_GSET"); @@ -2187,6 +2218,11 @@ netdev_linux_set_policing(struct netdev *netdev_, : kbits_burst); /* Stick with user-specified value. */ ovs_mutex_lock(&netdev->mutex); + if (netdev_linux_netns_is_remote(netdev)) { + error = EOPNOTSUPP; + goto out; + } + if (netdev->cache_valid & VALID_POLICING) { error = netdev->netdev_policing_error; if (error || (netdev->kbits_rate == kbits_rate && @@ -2323,6 +2359,11 @@ netdev_linux_get_qos(const struct netdev *netdev_, int error; ovs_mutex_lock(&netdev->mutex); + if (netdev_linux_netns_is_remote(netdev)) { + error = EOPNOTSUPP; + goto exit; + } + error = tc_query_qdisc(netdev_); if (!error) { *typep = netdev->tc->ops->ovs_name; @@ -2330,8 +2371,9 @@ netdev_linux_get_qos(const struct netdev *netdev_, ? netdev->tc->ops->qdisc_get(netdev_, details) : 0); } - ovs_mutex_unlock(&netdev->mutex); +exit: + ovs_mutex_unlock(&netdev->mutex); return error; } @@ -2353,6 +2395,11 @@ netdev_linux_set_qos(struct netdev *netdev_, } ovs_mutex_lock(&netdev->mutex); + if (netdev_linux_netns_is_remote(netdev)) { + error = EOPNOTSUPP; + goto exit; + } + error = tc_query_qdisc(netdev_); if (error) { goto exit; @@ -2386,6 +2433,11 @@ netdev_linux_get_queue(const struct netdev *netdev_, int error; ovs_mutex_lock(&netdev->mutex); + if (netdev_linux_netns_is_remote(netdev)) { + error = EOPNOTSUPP; + goto exit; + } + error = tc_query_qdisc(netdev_); if (!error) { struct tc_queue *queue = tc_find_queue(netdev_, queue_id); @@ -2393,8 +2445,9 @@ netdev_linux_get_queue(const struct netdev *netdev_, ? netdev->tc->ops->class_get(netdev_, queue, details) : ENOENT); } - ovs_mutex_unlock(&netdev->mutex); +exit: + ovs_mutex_unlock(&netdev->mutex); return error; } @@ -2406,6 +2459,11 @@ netdev_linux_set_queue(struct netdev *netdev_, int error; ovs_mutex_lock(&netdev->mutex); + if (netdev_linux_netns_is_remote(netdev)) { + error = EOPNOTSUPP; + goto exit; + } + error = tc_query_qdisc(netdev_); if (!error) { error = (queue_id < netdev->tc->ops->n_queues @@ -2413,8 +2471,9 @@ netdev_linux_set_queue(struct netdev *netdev_, ? netdev->tc->ops->class_set(netdev_, queue_id, details) : EINVAL); } - ovs_mutex_unlock(&netdev->mutex); +exit: + ovs_mutex_unlock(&netdev->mutex); return error; } @@ -2425,6 +2484,11 @@ netdev_linux_delete_queue(struct netdev *netdev_, unsigned int queue_id) int error; ovs_mutex_lock(&netdev->mutex); + if (netdev_linux_netns_is_remote(netdev)) { + error = EOPNOTSUPP; + goto exit; + } + error = tc_query_qdisc(netdev_); if (!error) { if (netdev->tc->ops->class_delete) { @@ -2436,8 +2500,9 @@ netdev_linux_delete_queue(struct netdev *netdev_, unsigned int queue_id) error = EINVAL; } } - ovs_mutex_unlock(&netdev->mutex); +exit: + ovs_mutex_unlock(&netdev->mutex); return error; } @@ -2450,6 +2515,11 @@ netdev_linux_get_queue_stats(const struct netdev *netdev_, int error; ovs_mutex_lock(&netdev->mutex); + if (netdev_linux_netns_is_remote(netdev)) { + error = EOPNOTSUPP; + goto exit; + } + error = tc_query_qdisc(netdev_); if (!error) { if (netdev->tc->ops->class_get_stats) { @@ -2465,8 +2535,9 @@ netdev_linux_get_queue_stats(const struct netdev *netdev_, error = EOPNOTSUPP; } } - ovs_mutex_unlock(&netdev->mutex); +exit: + ovs_mutex_unlock(&netdev->mutex); return error; } @@ -2509,10 +2580,15 @@ struct netdev_linux_queue_state { static int netdev_linux_queue_dump_start(const struct netdev *netdev_, void **statep) { - const struct netdev_linux *netdev = netdev_linux_cast(netdev_); + struct netdev_linux *netdev = netdev_linux_cast(netdev_); int error; ovs_mutex_lock(&netdev->mutex); + if (netdev_linux_netns_is_remote(netdev)) { + error = EOPNOTSUPP; + goto exit; + } + error = tc_query_qdisc(netdev_); if (!error) { if (netdev->tc->ops->class_get) { @@ -2533,8 +2609,9 @@ netdev_linux_queue_dump_start(const struct netdev *netdev_, void **statep) error = EOPNOTSUPP; } } - ovs_mutex_unlock(&netdev->mutex); +exit: + ovs_mutex_unlock(&netdev->mutex); return error; } @@ -2542,11 +2619,16 @@ static int netdev_linux_queue_dump_next(const struct netdev *netdev_, void *state_, unsigned int *queue_idp, struct smap *details) { - const struct netdev_linux *netdev = netdev_linux_cast(netdev_); + struct netdev_linux *netdev = netdev_linux_cast(netdev_); struct netdev_linux_queue_state *state = state_; int error = EOF; ovs_mutex_lock(&netdev->mutex); + if (netdev_linux_netns_is_remote(netdev)) { + error = EOPNOTSUPP; + goto exit; + } + while (state->cur_queue < state->n_queues) { unsigned int queue_id = state->queues[state->cur_queue++]; struct tc_queue *queue = tc_find_queue(netdev_, queue_id); @@ -2557,8 +2639,9 @@ netdev_linux_queue_dump_next(const struct netdev *netdev_, void *state_, break; } } - ovs_mutex_unlock(&netdev->mutex); +exit: + ovs_mutex_unlock(&netdev->mutex); return error; } @@ -2581,6 +2664,11 @@ netdev_linux_dump_queue_stats(const struct netdev *netdev_, int error; ovs_mutex_lock(&netdev->mutex); + if (netdev_linux_netns_is_remote(netdev)) { + error = EOPNOTSUPP; + goto exit; + } + error = tc_query_qdisc(netdev_); if (!error) { struct queue_dump_state state; @@ -2607,8 +2695,9 @@ netdev_linux_dump_queue_stats(const struct netdev *netdev_, } } } - ovs_mutex_unlock(&netdev->mutex); +exit: + ovs_mutex_unlock(&netdev->mutex); return error; } @@ -2620,6 +2709,11 @@ netdev_linux_set_in4(struct netdev *netdev_, struct in_addr address, int error; ovs_mutex_lock(&netdev->mutex); + if (netdev_linux_netns_is_remote(netdev)) { + error = EOPNOTSUPP; + goto exit; + } + error = do_set_addr(netdev_, SIOCSIFADDR, "SIOCSIFADDR", address); if (!error) { if (address.s_addr != INADDR_ANY) { @@ -2628,8 +2722,8 @@ netdev_linux_set_in4(struct netdev *netdev_, struct in_addr address, } } +exit: ovs_mutex_unlock(&netdev->mutex); - return error; } @@ -2644,9 +2738,15 @@ netdev_linux_get_addr_list(const struct netdev *netdev_, int error; ovs_mutex_lock(&netdev->mutex); + if (netdev_linux_netns_is_remote(netdev)) { + error = EOPNOTSUPP; + goto exit; + } + error = netdev_get_addrs(netdev_get_name(netdev_), addr, mask, n_cnt); - ovs_mutex_unlock(&netdev->mutex); +exit: + ovs_mutex_unlock(&netdev->mutex); return error; } @@ -2887,6 +2987,10 @@ netdev_linux_update_flags(struct netdev *netdev_, enum netdev_flags off, ovs_mutex_lock(&netdev->mutex); if (on || off) { /* Changing flags over netlink isn't support yet. */ + if (netdev_linux_netns_is_remote(netdev)) { + error = EOPNOTSUPP; + goto exit; + } error = update_flags(netdev, off, on, old_flagsp); } else { /* Try reading flags over netlink, or fall back to ioctl. */ @@ -2896,6 +3000,8 @@ netdev_linux_update_flags(struct netdev *netdev_, enum netdev_flags off, error = update_flags(netdev, off, on, old_flagsp); } } + +exit: ovs_mutex_unlock(&netdev->mutex); return error; }