netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Borkmann <dborkman@redhat.com>
To: Stephen Hemminger <stephen@networkplumber.org>
Cc: davem@davemloft.net, shahed.shaikh@qlogic.com, netdev@vger.kernel.org
Subject: Re: [PATCH net-next] net: vxlan: use custom ndo_change_mtu handler
Date: Tue, 17 Dec 2013 19:18:09 +0100	[thread overview]
Message-ID: <52B09561.8040404@redhat.com> (raw)
In-Reply-To: <20131217093640.63220542@nehalam.linuxnetplumber.net>

On 12/17/2013 06:36 PM, Stephen Hemminger wrote:
> On Tue, 17 Dec 2013 14:20:09 +0100
> Daniel Borkmann <dborkman@redhat.com> wrote:
>
>> +static int vxlan_change_mtu(struct net_device *dev, int new_mtu)
>> +{
>> +	struct net *net = current->nsproxy->net_ns;
>> +	struct vxlan_dev *vxlan = netdev_priv(dev);
>> +	struct vxlan_rdst *dst = &vxlan->default_dst;
>> +	bool is_ipv6 = dst->remote_ip.sa.sa_family == AF_INET6;
>> +	int hroom = is_ipv6 ? VXLAN6_HEADROOM : VXLAN_HEADROOM;
>> +	struct net_device *lowerdev;
>> +
>> +	lowerdev = dev_get_by_index(net, dst->remote_ifindex);
>> +	if (lowerdev == NULL)
>> +		return eth_change_mtu(dev, new_mtu);
>> +
>> +	if (new_mtu == lowerdev->mtu)
>> +		new_mtu = lowerdev->mtu - hroom;
>> +	if (new_mtu < 68 || new_mtu > lowerdev->mtu - hroom) {
>> +		dev_put(lowerdev);
>> +		return -EINVAL;
>> +	}
>> +
>> +	dev->mtu = new_mtu;
>> +
>> +	dev_put(lowerdev);
>> +	return 0;
>> +}
>> +
>
> The *net should just be devnet(dev).
>
> Don't need ref here, called under RTNL.
>
> You can't arbitrarly shrink user's requested mtu
>
> Minor nit picking: I don't like adding more local flag variables.
> To me it is clearer.

Ok, will send a v2 with your feedback incorporated.

Thanks a lot Stephen!

> The resulting function is:
>
>
> static int vxlan_change_mtu(struct net_device *dev, int new_mtu)
> {
> 	struct vxlan_dev *vxlan = netdev_priv(dev);
> 	int maxmtu;
> 	struct net_device *lowerdev;
>
> 	lowerdev = __dev_get_by_index(devnet(dev),
> 				      vxlan->default_dst.remote_ifindex);
> 	if (lowerdev == NULL)
> 		return eth_change_mtu(dev, new_mtu);
>
> 	if (dst->remote_ip.sa.sa_family == AF_INET6)
> 		maxmtu = lowerdev->mtu - VXLAN6_HEADROOM;
> 	else
> 		maxmtu = lowerdev->mtu - VXLAN_HEADROOM;
>
> 	if (new_mtu < 68 || new_mtu > maxmtu)
> 		return -EINVAL;
>
> 	dev->mtu = new_mtu;
> 	return 0;
> }
>
>

      reply	other threads:[~2013-12-17 18:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-17 13:20 [PATCH net-next] net: vxlan: use custom ndo_change_mtu handler Daniel Borkmann
2013-12-17 17:36 ` Stephen Hemminger
2013-12-17 18:18   ` Daniel Borkmann [this message]

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=52B09561.8040404@redhat.com \
    --to=dborkman@redhat.com \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=shahed.shaikh@qlogic.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).