From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sabrina Dubroca Subject: Re: [PATCH v6 1/4] udp_tunnel: add config option to bind to a device Date: Fri, 30 Nov 2018 15:31:00 +0100 Message-ID: <20181130143100.GA7623@bistromath.localdomain> References: <20181127130545.54356-1-abauvin@scaleway.com> <20181127130545.54356-2-abauvin@scaleway.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Cc: dsa@cumulusnetworks.com, roopa@cumulusnetworks.com, stephen@networkplumber.org, netdev@vger.kernel.org, akherbouche@scaleway.com To: Alexis Bauvin Return-path: Received: from mx1.redhat.com ([209.132.183.28]:60106 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726127AbeLABke (ORCPT ); Fri, 30 Nov 2018 20:40:34 -0500 Content-Disposition: inline In-Reply-To: <20181127130545.54356-2-abauvin@scaleway.com> Sender: netdev-owner@vger.kernel.org List-ID: 2018-11-27, 14:05:42 +0100, Alexis Bauvin wrote: > diff --git a/net/ipv4/udp_tunnel.c b/net/ipv4/udp_tunnel.c > index 6539ff15e9a3..dc68e15a4f72 100644 > --- a/net/ipv4/udp_tunnel.c > +++ b/net/ipv4/udp_tunnel.c > @@ -20,6 +20,16 @@ int udp_sock_create4(struct net *net, struct udp_port_cfg *cfg, > if (err < 0) > goto error; > > + if (cfg->bind_ifindex) { > + struct net_device *dev; > + > + dev = __dev_get_by_index(net, cfg->bind_ifindex); Quoting from net/core/dev.c: * [...] The device has not * had its reference counter increased so the caller must be careful * about locking. The caller must hold either the RTNL semaphore * or @dev_base_lock. */ which is the case for VXLAN (and GENEVE) during ndo_open, but I don't think other UDP tunnels (FOU, L2TP) are holding RTNL when they call udp_sock_create(). dev_get_by_index() + dev_put() should be safe. Also, I don't think it's a problem with vxlan, but this could handle the case where __dev_get_by_index returns NULL. > + err = kernel_setsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE, > + dev->name, strlen(dev->name) + 1); > + if (err < 0) > + goto error; > + } > + > udp_addr.sin_family = AF_INET; > udp_addr.sin_addr = cfg->local_ip; > udp_addr.sin_port = cfg->local_udp_port; -- Sabrina