lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20131217093640.63220542@nehalam.linuxnetplumber.net>
Date:	Tue, 17 Dec 2013 09:36:40 -0800
From:	Stephen Hemminger <stephen@...workplumber.org>
To:	Daniel Borkmann <dborkman@...hat.com>
Cc:	davem@...emloft.net, shahed.shaikh@...gic.com,
	netdev@...r.kernel.org
Subject: Re: [PATCH net-next] net: vxlan: use custom ndo_change_mtu handler

On Tue, 17 Dec 2013 14:20:09 +0100
Daniel Borkmann <dborkman@...hat.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.

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;
}


--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ