netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sabrina Dubroca <sd@queasysnail.net>
To: Alexis Bauvin <abauvin@scaleway.com>
Cc: dsa@cumulusnetworks.com, roopa@cumulusnetworks.com,
	stephen@networkplumber.org, netdev@vger.kernel.org,
	akherbouche@scaleway.com
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	[thread overview]
Message-ID: <20181130143100.GA7623@bistromath.localdomain> (raw)
In-Reply-To: <20181127130545.54356-2-abauvin@scaleway.com>

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

  reply	other threads:[~2018-12-01  1:40 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-27 13:05 [PATCH v6 0/4] Add VRF support for VXLAN underlay Alexis Bauvin
2018-11-27 13:05 ` [PATCH v6 1/4] udp_tunnel: add config option to bind to a device Alexis Bauvin
2018-11-30 14:31   ` Sabrina Dubroca [this message]
2018-12-03  9:14     ` Alexis Bauvin
2018-11-30 21:15   ` David Miller
2018-11-27 13:05 ` [PATCH v6 2/4] l3mdev: add function to retreive upper master Alexis Bauvin
2018-11-27 13:05 ` [PATCH v6 3/4] vxlan: add support for underlay in non-default VRF Alexis Bauvin
2018-11-27 13:05 ` [PATCH v6 4/4] test/net: Add script for VXLAN underlay in a VRF Alexis Bauvin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181130143100.GA7623@bistromath.localdomain \
    --to=sd@queasysnail.net \
    --cc=abauvin@scaleway.com \
    --cc=akherbouche@scaleway.com \
    --cc=dsa@cumulusnetworks.com \
    --cc=netdev@vger.kernel.org \
    --cc=roopa@cumulusnetworks.com \
    --cc=stephen@networkplumber.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).