2007-09-25 23:14:46 +00:00
|
|
|
/*
|
|
|
|
* drivers/net/veth.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 OpenVZ http://openvz.org, SWsoft Inc
|
|
|
|
*
|
|
|
|
* Author: Pavel Emelianov <xemul@openvz.org>
|
|
|
|
* Ethtool interface from: Eric W. Biederman <ebiederm@xmission.com>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/netdevice.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2007-09-25 23:14:46 +00:00
|
|
|
#include <linux/ethtool.h>
|
|
|
|
#include <linux/etherdevice.h>
|
2011-06-20 05:48:34 +00:00
|
|
|
#include <linux/u64_stats_sync.h>
|
2007-09-25 23:14:46 +00:00
|
|
|
|
2014-02-18 19:53:18 +00:00
|
|
|
#include <net/rtnetlink.h>
|
2007-09-25 23:14:46 +00:00
|
|
|
#include <net/dst.h>
|
|
|
|
#include <net/xfrm.h>
|
2007-12-26 01:23:59 +00:00
|
|
|
#include <linux/veth.h>
|
2011-07-03 19:21:01 +00:00
|
|
|
#include <linux/module.h>
|
2007-09-25 23:14:46 +00:00
|
|
|
|
|
|
|
#define DRV_NAME "veth"
|
|
|
|
#define DRV_VERSION "1.0"
|
|
|
|
|
2012-12-29 16:02:43 +00:00
|
|
|
struct pcpu_vstats {
|
|
|
|
u64 packets;
|
|
|
|
u64 bytes;
|
2011-06-20 05:48:34 +00:00
|
|
|
struct u64_stats_sync syncp;
|
2007-09-25 23:14:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct veth_priv {
|
2013-01-04 15:42:40 +00:00
|
|
|
struct net_device __rcu *peer;
|
2012-12-29 16:02:43 +00:00
|
|
|
atomic64_t dropped;
|
2016-02-26 09:45:41 +00:00
|
|
|
unsigned requested_headroom;
|
2007-09-25 23:14:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ethtool interface
|
|
|
|
*/
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
const char string[ETH_GSTRING_LEN];
|
|
|
|
} ethtool_stats_keys[] = {
|
|
|
|
{ "peer_ifindex" },
|
|
|
|
};
|
|
|
|
|
2017-03-29 06:24:21 +00:00
|
|
|
static int veth_get_link_ksettings(struct net_device *dev,
|
|
|
|
struct ethtool_link_ksettings *cmd)
|
2007-09-25 23:14:46 +00:00
|
|
|
{
|
2017-03-29 06:24:21 +00:00
|
|
|
cmd->base.speed = SPEED_10000;
|
|
|
|
cmd->base.duplex = DUPLEX_FULL;
|
|
|
|
cmd->base.port = PORT_TP;
|
|
|
|
cmd->base.autoneg = AUTONEG_DISABLE;
|
2007-09-25 23:14:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void veth_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
|
|
|
|
{
|
2011-11-15 14:59:53 +00:00
|
|
|
strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
|
|
|
|
strlcpy(info->version, DRV_VERSION, sizeof(info->version));
|
2007-09-25 23:14:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void veth_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
|
|
|
|
{
|
|
|
|
switch(stringset) {
|
|
|
|
case ETH_SS_STATS:
|
|
|
|
memcpy(buf, ðtool_stats_keys, sizeof(ethtool_stats_keys));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-04 01:07:32 +00:00
|
|
|
static int veth_get_sset_count(struct net_device *dev, int sset)
|
2007-09-25 23:14:46 +00:00
|
|
|
{
|
2007-10-04 01:07:32 +00:00
|
|
|
switch (sset) {
|
|
|
|
case ETH_SS_STATS:
|
|
|
|
return ARRAY_SIZE(ethtool_stats_keys);
|
|
|
|
default:
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
2007-09-25 23:14:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void veth_get_ethtool_stats(struct net_device *dev,
|
|
|
|
struct ethtool_stats *stats, u64 *data)
|
|
|
|
{
|
2013-01-04 15:42:40 +00:00
|
|
|
struct veth_priv *priv = netdev_priv(dev);
|
|
|
|
struct net_device *peer = rtnl_dereference(priv->peer);
|
2007-09-25 23:14:46 +00:00
|
|
|
|
2013-01-04 15:42:40 +00:00
|
|
|
data[0] = peer ? peer->ifindex : 0;
|
2007-09-25 23:14:46 +00:00
|
|
|
}
|
|
|
|
|
2009-09-02 08:03:33 +00:00
|
|
|
static const struct ethtool_ops veth_ethtool_ops = {
|
2007-09-25 23:14:46 +00:00
|
|
|
.get_drvinfo = veth_get_drvinfo,
|
|
|
|
.get_link = ethtool_op_get_link,
|
|
|
|
.get_strings = veth_get_strings,
|
2007-10-04 01:07:32 +00:00
|
|
|
.get_sset_count = veth_get_sset_count,
|
2007-09-25 23:14:46 +00:00
|
|
|
.get_ethtool_stats = veth_get_ethtool_stats,
|
2017-03-29 06:24:21 +00:00
|
|
|
.get_link_ksettings = veth_get_link_ksettings,
|
2007-09-25 23:14:46 +00:00
|
|
|
};
|
|
|
|
|
2009-08-31 19:50:51 +00:00
|
|
|
static netdev_tx_t veth_xmit(struct sk_buff *skb, struct net_device *dev)
|
2007-09-25 23:14:46 +00:00
|
|
|
{
|
2012-12-29 16:02:43 +00:00
|
|
|
struct veth_priv *priv = netdev_priv(dev);
|
2013-01-04 15:42:40 +00:00
|
|
|
struct net_device *rcv;
|
2012-12-29 16:02:43 +00:00
|
|
|
int length = skb->len;
|
2007-09-25 23:14:46 +00:00
|
|
|
|
2013-01-04 15:42:40 +00:00
|
|
|
rcu_read_lock();
|
|
|
|
rcv = rcu_dereference(priv->peer);
|
|
|
|
if (unlikely(!rcv)) {
|
|
|
|
kfree_skb(skb);
|
|
|
|
goto drop;
|
|
|
|
}
|
2007-09-25 23:14:46 +00:00
|
|
|
|
2012-12-29 16:02:43 +00:00
|
|
|
if (likely(dev_forward_skb(rcv, skb) == NET_RX_SUCCESS)) {
|
|
|
|
struct pcpu_vstats *stats = this_cpu_ptr(dev->vstats);
|
2007-09-25 23:14:46 +00:00
|
|
|
|
2012-12-29 16:02:43 +00:00
|
|
|
u64_stats_update_begin(&stats->syncp);
|
|
|
|
stats->bytes += length;
|
|
|
|
stats->packets++;
|
|
|
|
u64_stats_update_end(&stats->syncp);
|
|
|
|
} else {
|
2013-01-04 15:42:40 +00:00
|
|
|
drop:
|
2012-12-29 16:02:43 +00:00
|
|
|
atomic64_inc(&priv->dropped);
|
|
|
|
}
|
2013-01-04 15:42:40 +00:00
|
|
|
rcu_read_unlock();
|
2009-06-23 06:03:08 +00:00
|
|
|
return NETDEV_TX_OK;
|
2007-09-25 23:14:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* general routines
|
|
|
|
*/
|
|
|
|
|
2012-12-29 16:02:43 +00:00
|
|
|
static u64 veth_stats_one(struct pcpu_vstats *result, struct net_device *dev)
|
2007-09-25 23:14:46 +00:00
|
|
|
{
|
2011-06-20 05:48:34 +00:00
|
|
|
struct veth_priv *priv = netdev_priv(dev);
|
2009-06-25 09:45:42 +00:00
|
|
|
int cpu;
|
2007-09-25 23:14:46 +00:00
|
|
|
|
2012-12-29 16:02:43 +00:00
|
|
|
result->packets = 0;
|
|
|
|
result->bytes = 0;
|
2009-11-18 07:09:39 +00:00
|
|
|
for_each_possible_cpu(cpu) {
|
2012-12-29 16:02:43 +00:00
|
|
|
struct pcpu_vstats *stats = per_cpu_ptr(dev->vstats, cpu);
|
|
|
|
u64 packets, bytes;
|
2011-06-20 05:48:34 +00:00
|
|
|
unsigned int start;
|
|
|
|
|
|
|
|
do {
|
2014-03-14 04:26:42 +00:00
|
|
|
start = u64_stats_fetch_begin_irq(&stats->syncp);
|
2012-12-29 16:02:43 +00:00
|
|
|
packets = stats->packets;
|
|
|
|
bytes = stats->bytes;
|
2014-03-14 04:26:42 +00:00
|
|
|
} while (u64_stats_fetch_retry_irq(&stats->syncp, start));
|
2012-12-29 16:02:43 +00:00
|
|
|
result->packets += packets;
|
|
|
|
result->bytes += bytes;
|
2009-06-25 09:45:42 +00:00
|
|
|
}
|
2012-12-29 16:02:43 +00:00
|
|
|
return atomic64_read(&priv->dropped);
|
|
|
|
}
|
|
|
|
|
2017-01-07 03:12:52 +00:00
|
|
|
static void veth_get_stats64(struct net_device *dev,
|
|
|
|
struct rtnl_link_stats64 *tot)
|
2012-12-29 16:02:43 +00:00
|
|
|
{
|
|
|
|
struct veth_priv *priv = netdev_priv(dev);
|
2013-01-04 15:42:40 +00:00
|
|
|
struct net_device *peer;
|
2012-12-29 16:02:43 +00:00
|
|
|
struct pcpu_vstats one;
|
|
|
|
|
|
|
|
tot->tx_dropped = veth_stats_one(&one, dev);
|
|
|
|
tot->tx_bytes = one.bytes;
|
|
|
|
tot->tx_packets = one.packets;
|
|
|
|
|
2013-01-04 15:42:40 +00:00
|
|
|
rcu_read_lock();
|
|
|
|
peer = rcu_dereference(priv->peer);
|
|
|
|
if (peer) {
|
|
|
|
tot->rx_dropped = veth_stats_one(&one, peer);
|
|
|
|
tot->rx_bytes = one.bytes;
|
|
|
|
tot->rx_packets = one.packets;
|
|
|
|
}
|
|
|
|
rcu_read_unlock();
|
2007-09-25 23:14:46 +00:00
|
|
|
}
|
|
|
|
|
2013-10-04 08:52:24 +00:00
|
|
|
/* fake multicast ability */
|
|
|
|
static void veth_set_multicast_list(struct net_device *dev)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-09-25 23:14:46 +00:00
|
|
|
static int veth_open(struct net_device *dev)
|
|
|
|
{
|
2013-01-04 15:42:40 +00:00
|
|
|
struct veth_priv *priv = netdev_priv(dev);
|
|
|
|
struct net_device *peer = rtnl_dereference(priv->peer);
|
2007-09-25 23:14:46 +00:00
|
|
|
|
2013-01-04 15:42:40 +00:00
|
|
|
if (!peer)
|
2007-09-25 23:14:46 +00:00
|
|
|
return -ENOTCONN;
|
|
|
|
|
2013-01-04 15:42:40 +00:00
|
|
|
if (peer->flags & IFF_UP) {
|
2007-09-25 23:14:46 +00:00
|
|
|
netif_carrier_on(dev);
|
2013-01-04 15:42:40 +00:00
|
|
|
netif_carrier_on(peer);
|
2007-09-25 23:14:46 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-02-25 19:47:29 +00:00
|
|
|
static int veth_close(struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct veth_priv *priv = netdev_priv(dev);
|
2013-01-10 08:32:45 +00:00
|
|
|
struct net_device *peer = rtnl_dereference(priv->peer);
|
2009-02-25 19:47:29 +00:00
|
|
|
|
|
|
|
netif_carrier_off(dev);
|
2013-01-10 08:32:45 +00:00
|
|
|
if (peer)
|
|
|
|
netif_carrier_off(peer);
|
2009-02-25 19:47:29 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
net: use core MTU range checking in core net infra
geneve:
- Merge __geneve_change_mtu back into geneve_change_mtu, set max_mtu
- This one isn't quite as straight-forward as others, could use some
closer inspection and testing
macvlan:
- set min/max_mtu
tun:
- set min/max_mtu, remove tun_net_change_mtu
vxlan:
- Merge __vxlan_change_mtu back into vxlan_change_mtu
- Set max_mtu to IP_MAX_MTU and retain dynamic MTU range checks in
change_mtu function
- This one is also not as straight-forward and could use closer inspection
and testing from vxlan folks
bridge:
- set max_mtu of IP_MAX_MTU and retain dynamic MTU range checks in
change_mtu function
openvswitch:
- set min/max_mtu, remove internal_dev_change_mtu
- note: max_mtu wasn't checked previously, it's been set to 65535, which
is the largest possible size supported
sch_teql:
- set min/max_mtu (note: max_mtu previously unchecked, used max of 65535)
macsec:
- min_mtu = 0, max_mtu = 65535
macvlan:
- min_mtu = 0, max_mtu = 65535
ntb_netdev:
- min_mtu = 0, max_mtu = 65535
veth:
- min_mtu = 68, max_mtu = 65535
8021q:
- min_mtu = 0, max_mtu = 65535
CC: netdev@vger.kernel.org
CC: Nicolas Dichtel <nicolas.dichtel@6wind.com>
CC: Hannes Frederic Sowa <hannes@stressinduktion.org>
CC: Tom Herbert <tom@herbertland.com>
CC: Daniel Borkmann <daniel@iogearbox.net>
CC: Alexander Duyck <alexander.h.duyck@intel.com>
CC: Paolo Abeni <pabeni@redhat.com>
CC: Jiri Benc <jbenc@redhat.com>
CC: WANG Cong <xiyou.wangcong@gmail.com>
CC: Roopa Prabhu <roopa@cumulusnetworks.com>
CC: Pravin B Shelar <pshelar@ovn.org>
CC: Sabrina Dubroca <sd@queasysnail.net>
CC: Patrick McHardy <kaber@trash.net>
CC: Stephen Hemminger <stephen@networkplumber.org>
CC: Pravin Shelar <pshelar@nicira.com>
CC: Maxim Krasnyansky <maxk@qti.qualcomm.com>
Signed-off-by: Jarod Wilson <jarod@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2016-10-20 17:55:20 +00:00
|
|
|
static int is_valid_veth_mtu(int mtu)
|
2009-03-04 07:36:04 +00:00
|
|
|
{
|
net: use core MTU range checking in core net infra
geneve:
- Merge __geneve_change_mtu back into geneve_change_mtu, set max_mtu
- This one isn't quite as straight-forward as others, could use some
closer inspection and testing
macvlan:
- set min/max_mtu
tun:
- set min/max_mtu, remove tun_net_change_mtu
vxlan:
- Merge __vxlan_change_mtu back into vxlan_change_mtu
- Set max_mtu to IP_MAX_MTU and retain dynamic MTU range checks in
change_mtu function
- This one is also not as straight-forward and could use closer inspection
and testing from vxlan folks
bridge:
- set max_mtu of IP_MAX_MTU and retain dynamic MTU range checks in
change_mtu function
openvswitch:
- set min/max_mtu, remove internal_dev_change_mtu
- note: max_mtu wasn't checked previously, it's been set to 65535, which
is the largest possible size supported
sch_teql:
- set min/max_mtu (note: max_mtu previously unchecked, used max of 65535)
macsec:
- min_mtu = 0, max_mtu = 65535
macvlan:
- min_mtu = 0, max_mtu = 65535
ntb_netdev:
- min_mtu = 0, max_mtu = 65535
veth:
- min_mtu = 68, max_mtu = 65535
8021q:
- min_mtu = 0, max_mtu = 65535
CC: netdev@vger.kernel.org
CC: Nicolas Dichtel <nicolas.dichtel@6wind.com>
CC: Hannes Frederic Sowa <hannes@stressinduktion.org>
CC: Tom Herbert <tom@herbertland.com>
CC: Daniel Borkmann <daniel@iogearbox.net>
CC: Alexander Duyck <alexander.h.duyck@intel.com>
CC: Paolo Abeni <pabeni@redhat.com>
CC: Jiri Benc <jbenc@redhat.com>
CC: WANG Cong <xiyou.wangcong@gmail.com>
CC: Roopa Prabhu <roopa@cumulusnetworks.com>
CC: Pravin B Shelar <pshelar@ovn.org>
CC: Sabrina Dubroca <sd@queasysnail.net>
CC: Patrick McHardy <kaber@trash.net>
CC: Stephen Hemminger <stephen@networkplumber.org>
CC: Pravin Shelar <pshelar@nicira.com>
CC: Maxim Krasnyansky <maxk@qti.qualcomm.com>
Signed-off-by: Jarod Wilson <jarod@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2016-10-20 17:55:20 +00:00
|
|
|
return mtu >= ETH_MIN_MTU && mtu <= ETH_MAX_MTU;
|
2009-03-04 07:36:04 +00:00
|
|
|
}
|
|
|
|
|
2007-09-25 23:14:46 +00:00
|
|
|
static int veth_dev_init(struct net_device *dev)
|
|
|
|
{
|
2014-02-13 19:46:28 +00:00
|
|
|
dev->vstats = netdev_alloc_pcpu_stats(struct pcpu_vstats);
|
2012-12-29 16:02:43 +00:00
|
|
|
if (!dev->vstats)
|
2007-09-25 23:14:46 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-06-25 09:45:42 +00:00
|
|
|
static void veth_dev_free(struct net_device *dev)
|
|
|
|
{
|
2012-12-29 16:02:43 +00:00
|
|
|
free_percpu(dev->vstats);
|
2009-06-25 09:45:42 +00:00
|
|
|
}
|
|
|
|
|
2014-06-23 22:36:02 +00:00
|
|
|
#ifdef CONFIG_NET_POLL_CONTROLLER
|
|
|
|
static void veth_poll_controller(struct net_device *dev)
|
|
|
|
{
|
|
|
|
/* veth only receives frames when its peer sends one
|
|
|
|
* Since it's a synchronous operation, we are guaranteed
|
|
|
|
* never to have pending data when we poll for it so
|
|
|
|
* there is nothing to do here.
|
|
|
|
*
|
|
|
|
* We need this though so netpoll recognizes us as an interface that
|
|
|
|
* supports polling, which enables bridge devices in virt setups to
|
|
|
|
* still use netconsole
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_NET_POLL_CONTROLLER */
|
|
|
|
|
2015-04-02 15:07:11 +00:00
|
|
|
static int veth_get_iflink(const struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct veth_priv *priv = netdev_priv(dev);
|
|
|
|
struct net_device *peer;
|
|
|
|
int iflink;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
peer = rcu_dereference(priv->peer);
|
|
|
|
iflink = peer ? peer->ifindex : 0;
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
|
|
|
return iflink;
|
|
|
|
}
|
|
|
|
|
2016-02-26 09:45:41 +00:00
|
|
|
static void veth_set_rx_headroom(struct net_device *dev, int new_hr)
|
|
|
|
{
|
|
|
|
struct veth_priv *peer_priv, *priv = netdev_priv(dev);
|
|
|
|
struct net_device *peer;
|
|
|
|
|
|
|
|
if (new_hr < 0)
|
|
|
|
new_hr = 0;
|
|
|
|
|
|
|
|
rcu_read_lock();
|
|
|
|
peer = rcu_dereference(priv->peer);
|
|
|
|
if (unlikely(!peer))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
peer_priv = netdev_priv(peer);
|
|
|
|
priv->requested_headroom = new_hr;
|
|
|
|
new_hr = max(priv->requested_headroom, peer_priv->requested_headroom);
|
|
|
|
dev->needed_headroom = new_hr;
|
|
|
|
peer->needed_headroom = new_hr;
|
|
|
|
|
|
|
|
out:
|
|
|
|
rcu_read_unlock();
|
|
|
|
}
|
|
|
|
|
2008-11-20 05:50:10 +00:00
|
|
|
static const struct net_device_ops veth_netdev_ops = {
|
2009-02-22 08:04:45 +00:00
|
|
|
.ndo_init = veth_dev_init,
|
|
|
|
.ndo_open = veth_open,
|
2009-02-25 19:47:29 +00:00
|
|
|
.ndo_stop = veth_close,
|
2009-02-22 08:04:45 +00:00
|
|
|
.ndo_start_xmit = veth_xmit,
|
2011-06-08 14:53:59 +00:00
|
|
|
.ndo_get_stats64 = veth_get_stats64,
|
2013-10-04 08:52:24 +00:00
|
|
|
.ndo_set_rx_mode = veth_set_multicast_list,
|
2009-02-22 08:04:45 +00:00
|
|
|
.ndo_set_mac_address = eth_mac_addr,
|
2014-06-23 22:36:02 +00:00
|
|
|
#ifdef CONFIG_NET_POLL_CONTROLLER
|
|
|
|
.ndo_poll_controller = veth_poll_controller,
|
|
|
|
#endif
|
2015-04-02 15:07:11 +00:00
|
|
|
.ndo_get_iflink = veth_get_iflink,
|
2015-07-31 06:03:25 +00:00
|
|
|
.ndo_features_check = passthru_features_check,
|
2016-02-26 09:45:41 +00:00
|
|
|
.ndo_set_rx_headroom = veth_set_rx_headroom,
|
2008-11-20 05:50:10 +00:00
|
|
|
};
|
|
|
|
|
2016-04-19 18:02:26 +00:00
|
|
|
#define VETH_FEATURES (NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_HW_CSUM | \
|
2016-08-25 05:21:49 +00:00
|
|
|
NETIF_F_RXCSUM | NETIF_F_SCTP_CRC | NETIF_F_HIGHDMA | \
|
2016-04-19 18:02:26 +00:00
|
|
|
NETIF_F_GSO_SOFTWARE | NETIF_F_GSO_ENCAP_ALL | \
|
2013-04-19 02:04:32 +00:00
|
|
|
NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX | \
|
|
|
|
NETIF_F_HW_VLAN_STAG_TX | NETIF_F_HW_VLAN_STAG_RX )
|
2012-12-29 16:26:10 +00:00
|
|
|
|
2007-09-25 23:14:46 +00:00
|
|
|
static void veth_setup(struct net_device *dev)
|
|
|
|
{
|
|
|
|
ether_setup(dev);
|
|
|
|
|
2011-07-26 06:05:38 +00:00
|
|
|
dev->priv_flags &= ~IFF_TX_SKB_SHARING;
|
2012-10-30 16:22:01 +00:00
|
|
|
dev->priv_flags |= IFF_LIVE_ADDR_CHANGE;
|
2015-08-18 08:30:29 +00:00
|
|
|
dev->priv_flags |= IFF_NO_QUEUE;
|
2016-02-26 09:45:41 +00:00
|
|
|
dev->priv_flags |= IFF_PHONY_HEADROOM;
|
2011-07-26 06:05:38 +00:00
|
|
|
|
2008-11-20 05:50:10 +00:00
|
|
|
dev->netdev_ops = &veth_netdev_ops;
|
2007-09-25 23:14:46 +00:00
|
|
|
dev->ethtool_ops = &veth_ethtool_ops;
|
|
|
|
dev->features |= NETIF_F_LLTX;
|
2012-12-29 16:26:10 +00:00
|
|
|
dev->features |= VETH_FEATURES;
|
2014-02-18 12:20:08 +00:00
|
|
|
dev->vlan_features = dev->features &
|
2014-03-28 02:14:48 +00:00
|
|
|
~(NETIF_F_HW_VLAN_CTAG_TX |
|
|
|
|
NETIF_F_HW_VLAN_STAG_TX |
|
|
|
|
NETIF_F_HW_VLAN_CTAG_RX |
|
|
|
|
NETIF_F_HW_VLAN_STAG_RX);
|
net: Fix inconsistent teardown and release of private netdev state.
Network devices can allocate reasources and private memory using
netdev_ops->ndo_init(). However, the release of these resources
can occur in one of two different places.
Either netdev_ops->ndo_uninit() or netdev->destructor().
The decision of which operation frees the resources depends upon
whether it is necessary for all netdev refs to be released before it
is safe to perform the freeing.
netdev_ops->ndo_uninit() presumably can occur right after the
NETDEV_UNREGISTER notifier completes and the unicast and multicast
address lists are flushed.
netdev->destructor(), on the other hand, does not run until the
netdev references all go away.
Further complicating the situation is that netdev->destructor()
almost universally does also a free_netdev().
This creates a problem for the logic in register_netdevice().
Because all callers of register_netdevice() manage the freeing
of the netdev, and invoke free_netdev(dev) if register_netdevice()
fails.
If netdev_ops->ndo_init() succeeds, but something else fails inside
of register_netdevice(), it does call ndo_ops->ndo_uninit(). But
it is not able to invoke netdev->destructor().
This is because netdev->destructor() will do a free_netdev() and
then the caller of register_netdevice() will do the same.
However, this means that the resources that would normally be released
by netdev->destructor() will not be.
Over the years drivers have added local hacks to deal with this, by
invoking their destructor parts by hand when register_netdevice()
fails.
Many drivers do not try to deal with this, and instead we have leaks.
Let's close this hole by formalizing the distinction between what
private things need to be freed up by netdev->destructor() and whether
the driver needs unregister_netdevice() to perform the free_netdev().
netdev->priv_destructor() performs all actions to free up the private
resources that used to be freed by netdev->destructor(), except for
free_netdev().
netdev->needs_free_netdev is a boolean that indicates whether
free_netdev() should be done at the end of unregister_netdevice().
Now, register_netdevice() can sanely release all resources after
ndo_ops->ndo_init() succeeds, by invoking both ndo_ops->ndo_uninit()
and netdev->priv_destructor().
And at the end of unregister_netdevice(), we invoke
netdev->priv_destructor() and optionally call free_netdev().
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-05-08 16:52:56 +00:00
|
|
|
dev->needs_free_netdev = true;
|
|
|
|
dev->priv_destructor = veth_dev_free;
|
net: use core MTU range checking in core net infra
geneve:
- Merge __geneve_change_mtu back into geneve_change_mtu, set max_mtu
- This one isn't quite as straight-forward as others, could use some
closer inspection and testing
macvlan:
- set min/max_mtu
tun:
- set min/max_mtu, remove tun_net_change_mtu
vxlan:
- Merge __vxlan_change_mtu back into vxlan_change_mtu
- Set max_mtu to IP_MAX_MTU and retain dynamic MTU range checks in
change_mtu function
- This one is also not as straight-forward and could use closer inspection
and testing from vxlan folks
bridge:
- set max_mtu of IP_MAX_MTU and retain dynamic MTU range checks in
change_mtu function
openvswitch:
- set min/max_mtu, remove internal_dev_change_mtu
- note: max_mtu wasn't checked previously, it's been set to 65535, which
is the largest possible size supported
sch_teql:
- set min/max_mtu (note: max_mtu previously unchecked, used max of 65535)
macsec:
- min_mtu = 0, max_mtu = 65535
macvlan:
- min_mtu = 0, max_mtu = 65535
ntb_netdev:
- min_mtu = 0, max_mtu = 65535
veth:
- min_mtu = 68, max_mtu = 65535
8021q:
- min_mtu = 0, max_mtu = 65535
CC: netdev@vger.kernel.org
CC: Nicolas Dichtel <nicolas.dichtel@6wind.com>
CC: Hannes Frederic Sowa <hannes@stressinduktion.org>
CC: Tom Herbert <tom@herbertland.com>
CC: Daniel Borkmann <daniel@iogearbox.net>
CC: Alexander Duyck <alexander.h.duyck@intel.com>
CC: Paolo Abeni <pabeni@redhat.com>
CC: Jiri Benc <jbenc@redhat.com>
CC: WANG Cong <xiyou.wangcong@gmail.com>
CC: Roopa Prabhu <roopa@cumulusnetworks.com>
CC: Pravin B Shelar <pshelar@ovn.org>
CC: Sabrina Dubroca <sd@queasysnail.net>
CC: Patrick McHardy <kaber@trash.net>
CC: Stephen Hemminger <stephen@networkplumber.org>
CC: Pravin Shelar <pshelar@nicira.com>
CC: Maxim Krasnyansky <maxk@qti.qualcomm.com>
Signed-off-by: Jarod Wilson <jarod@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2016-10-20 17:55:20 +00:00
|
|
|
dev->max_mtu = ETH_MAX_MTU;
|
2011-03-31 01:01:35 +00:00
|
|
|
|
2012-12-29 16:26:10 +00:00
|
|
|
dev->hw_features = VETH_FEATURES;
|
2013-10-26 01:25:03 +00:00
|
|
|
dev->hw_enc_features = VETH_FEATURES;
|
2016-08-25 03:10:45 +00:00
|
|
|
dev->mpls_features = NETIF_F_HW_CSUM | NETIF_F_GSO_SOFTWARE;
|
2007-09-25 23:14:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* netlink interface
|
|
|
|
*/
|
|
|
|
|
2017-06-25 21:56:01 +00:00
|
|
|
static int veth_validate(struct nlattr *tb[], struct nlattr *data[],
|
|
|
|
struct netlink_ext_ack *extack)
|
2007-09-25 23:14:46 +00:00
|
|
|
{
|
|
|
|
if (tb[IFLA_ADDRESS]) {
|
|
|
|
if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN)
|
|
|
|
return -EINVAL;
|
|
|
|
if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS])))
|
|
|
|
return -EADDRNOTAVAIL;
|
|
|
|
}
|
2009-03-04 07:36:04 +00:00
|
|
|
if (tb[IFLA_MTU]) {
|
|
|
|
if (!is_valid_veth_mtu(nla_get_u32(tb[IFLA_MTU])))
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2007-09-25 23:14:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct rtnl_link_ops veth_link_ops;
|
|
|
|
|
2009-11-08 08:53:51 +00:00
|
|
|
static int veth_newlink(struct net *src_net, struct net_device *dev,
|
2017-06-25 21:55:59 +00:00
|
|
|
struct nlattr *tb[], struct nlattr *data[],
|
|
|
|
struct netlink_ext_ack *extack)
|
2007-09-25 23:14:46 +00:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
struct net_device *peer;
|
|
|
|
struct veth_priv *priv;
|
|
|
|
char ifname[IFNAMSIZ];
|
|
|
|
struct nlattr *peer_tb[IFLA_MAX + 1], **tbp;
|
2014-07-14 14:37:25 +00:00
|
|
|
unsigned char name_assign_type;
|
rtnetlink: support specifying device flags on device creation
commit e8469ed959c373c2ff9e6f488aa5a14971aebe1f
Author: Patrick McHardy <kaber@trash.net>
Date: Tue Feb 23 20:41:30 2010 +0100
Support specifying the initial device flags when creating a device though
rtnl_link. Devices allocated by rtnl_create_link() are marked as INITIALIZING
in order to surpress netlink registration notifications. To complete setup,
rtnl_configure_link() must be called, which performs the device flag changes
and invokes the deferred notifiers if everything went well.
Two examples:
# add macvlan to eth0
#
$ ip link add link eth0 up allmulticast on type macvlan
[LINK]11: macvlan0@eth0: <BROADCAST,MULTICAST,ALLMULTI,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN
link/ether 26:f8:84:02:f9:2a brd ff:ff:ff:ff:ff:ff
[ROUTE]ff00::/8 dev macvlan0 table local metric 256 mtu 1500 advmss 1440 hoplimit 0
[ROUTE]fe80::/64 dev macvlan0 proto kernel metric 256 mtu 1500 advmss 1440 hoplimit 0
[LINK]11: macvlan0@eth0: <BROADCAST,MULTICAST,ALLMULTI,UP,LOWER_UP> mtu 1500
link/ether 26:f8:84:02:f9:2a
[ADDR]11: macvlan0 inet6 fe80::24f8:84ff:fe02:f92a/64 scope link
valid_lft forever preferred_lft forever
[ROUTE]local fe80::24f8:84ff:fe02:f92a via :: dev lo table local proto none metric 0 mtu 16436 advmss 16376 hoplimit 0
[ROUTE]default via fe80::215:e9ff:fef0:10f8 dev macvlan0 proto kernel metric 1024 mtu 1500 advmss 1440 hoplimit 0
[NEIGH]fe80::215:e9ff:fef0:10f8 dev macvlan0 lladdr 00:15:e9:f0:10:f8 router STALE
[ROUTE]2001:6f8:974::/64 dev macvlan0 proto kernel metric 256 expires 0sec mtu 1500 advmss 1440 hoplimit 0
[PREFIX]prefix 2001:6f8:974::/64 dev macvlan0 onlink autoconf valid 14400 preferred 131084
[ADDR]11: macvlan0 inet6 2001:6f8:974:0:24f8:84ff:fe02:f92a/64 scope global dynamic
valid_lft 86399sec preferred_lft 14399sec
# add VLAN to eth1, eth1 is down
#
$ ip link add link eth1 up type vlan id 1000
RTNETLINK answers: Network is down
<no events>
Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2010-02-26 06:34:54 +00:00
|
|
|
struct ifinfomsg *ifmp;
|
2009-11-08 08:53:51 +00:00
|
|
|
struct net *net;
|
2007-09-25 23:14:46 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* create and register peer first
|
|
|
|
*/
|
|
|
|
if (data != NULL && data[VETH_INFO_PEER] != NULL) {
|
|
|
|
struct nlattr *nla_peer;
|
|
|
|
|
|
|
|
nla_peer = data[VETH_INFO_PEER];
|
rtnetlink: support specifying device flags on device creation
commit e8469ed959c373c2ff9e6f488aa5a14971aebe1f
Author: Patrick McHardy <kaber@trash.net>
Date: Tue Feb 23 20:41:30 2010 +0100
Support specifying the initial device flags when creating a device though
rtnl_link. Devices allocated by rtnl_create_link() are marked as INITIALIZING
in order to surpress netlink registration notifications. To complete setup,
rtnl_configure_link() must be called, which performs the device flag changes
and invokes the deferred notifiers if everything went well.
Two examples:
# add macvlan to eth0
#
$ ip link add link eth0 up allmulticast on type macvlan
[LINK]11: macvlan0@eth0: <BROADCAST,MULTICAST,ALLMULTI,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN
link/ether 26:f8:84:02:f9:2a brd ff:ff:ff:ff:ff:ff
[ROUTE]ff00::/8 dev macvlan0 table local metric 256 mtu 1500 advmss 1440 hoplimit 0
[ROUTE]fe80::/64 dev macvlan0 proto kernel metric 256 mtu 1500 advmss 1440 hoplimit 0
[LINK]11: macvlan0@eth0: <BROADCAST,MULTICAST,ALLMULTI,UP,LOWER_UP> mtu 1500
link/ether 26:f8:84:02:f9:2a
[ADDR]11: macvlan0 inet6 fe80::24f8:84ff:fe02:f92a/64 scope link
valid_lft forever preferred_lft forever
[ROUTE]local fe80::24f8:84ff:fe02:f92a via :: dev lo table local proto none metric 0 mtu 16436 advmss 16376 hoplimit 0
[ROUTE]default via fe80::215:e9ff:fef0:10f8 dev macvlan0 proto kernel metric 1024 mtu 1500 advmss 1440 hoplimit 0
[NEIGH]fe80::215:e9ff:fef0:10f8 dev macvlan0 lladdr 00:15:e9:f0:10:f8 router STALE
[ROUTE]2001:6f8:974::/64 dev macvlan0 proto kernel metric 256 expires 0sec mtu 1500 advmss 1440 hoplimit 0
[PREFIX]prefix 2001:6f8:974::/64 dev macvlan0 onlink autoconf valid 14400 preferred 131084
[ADDR]11: macvlan0 inet6 2001:6f8:974:0:24f8:84ff:fe02:f92a/64 scope global dynamic
valid_lft 86399sec preferred_lft 14399sec
# add VLAN to eth1, eth1 is down
#
$ ip link add link eth1 up type vlan id 1000
RTNETLINK answers: Network is down
<no events>
Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2010-02-26 06:34:54 +00:00
|
|
|
ifmp = nla_data(nla_peer);
|
2014-02-18 19:53:18 +00:00
|
|
|
err = rtnl_nla_parse_ifla(peer_tb,
|
|
|
|
nla_data(nla_peer) + sizeof(struct ifinfomsg),
|
2017-04-12 12:34:07 +00:00
|
|
|
nla_len(nla_peer) - sizeof(struct ifinfomsg),
|
|
|
|
NULL);
|
2007-09-25 23:14:46 +00:00
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
2017-06-25 21:56:01 +00:00
|
|
|
err = veth_validate(peer_tb, NULL, extack);
|
2007-09-25 23:14:46 +00:00
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
tbp = peer_tb;
|
rtnetlink: support specifying device flags on device creation
commit e8469ed959c373c2ff9e6f488aa5a14971aebe1f
Author: Patrick McHardy <kaber@trash.net>
Date: Tue Feb 23 20:41:30 2010 +0100
Support specifying the initial device flags when creating a device though
rtnl_link. Devices allocated by rtnl_create_link() are marked as INITIALIZING
in order to surpress netlink registration notifications. To complete setup,
rtnl_configure_link() must be called, which performs the device flag changes
and invokes the deferred notifiers if everything went well.
Two examples:
# add macvlan to eth0
#
$ ip link add link eth0 up allmulticast on type macvlan
[LINK]11: macvlan0@eth0: <BROADCAST,MULTICAST,ALLMULTI,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN
link/ether 26:f8:84:02:f9:2a brd ff:ff:ff:ff:ff:ff
[ROUTE]ff00::/8 dev macvlan0 table local metric 256 mtu 1500 advmss 1440 hoplimit 0
[ROUTE]fe80::/64 dev macvlan0 proto kernel metric 256 mtu 1500 advmss 1440 hoplimit 0
[LINK]11: macvlan0@eth0: <BROADCAST,MULTICAST,ALLMULTI,UP,LOWER_UP> mtu 1500
link/ether 26:f8:84:02:f9:2a
[ADDR]11: macvlan0 inet6 fe80::24f8:84ff:fe02:f92a/64 scope link
valid_lft forever preferred_lft forever
[ROUTE]local fe80::24f8:84ff:fe02:f92a via :: dev lo table local proto none metric 0 mtu 16436 advmss 16376 hoplimit 0
[ROUTE]default via fe80::215:e9ff:fef0:10f8 dev macvlan0 proto kernel metric 1024 mtu 1500 advmss 1440 hoplimit 0
[NEIGH]fe80::215:e9ff:fef0:10f8 dev macvlan0 lladdr 00:15:e9:f0:10:f8 router STALE
[ROUTE]2001:6f8:974::/64 dev macvlan0 proto kernel metric 256 expires 0sec mtu 1500 advmss 1440 hoplimit 0
[PREFIX]prefix 2001:6f8:974::/64 dev macvlan0 onlink autoconf valid 14400 preferred 131084
[ADDR]11: macvlan0 inet6 2001:6f8:974:0:24f8:84ff:fe02:f92a/64 scope global dynamic
valid_lft 86399sec preferred_lft 14399sec
# add VLAN to eth1, eth1 is down
#
$ ip link add link eth1 up type vlan id 1000
RTNETLINK answers: Network is down
<no events>
Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2010-02-26 06:34:54 +00:00
|
|
|
} else {
|
|
|
|
ifmp = NULL;
|
2007-09-25 23:14:46 +00:00
|
|
|
tbp = tb;
|
rtnetlink: support specifying device flags on device creation
commit e8469ed959c373c2ff9e6f488aa5a14971aebe1f
Author: Patrick McHardy <kaber@trash.net>
Date: Tue Feb 23 20:41:30 2010 +0100
Support specifying the initial device flags when creating a device though
rtnl_link. Devices allocated by rtnl_create_link() are marked as INITIALIZING
in order to surpress netlink registration notifications. To complete setup,
rtnl_configure_link() must be called, which performs the device flag changes
and invokes the deferred notifiers if everything went well.
Two examples:
# add macvlan to eth0
#
$ ip link add link eth0 up allmulticast on type macvlan
[LINK]11: macvlan0@eth0: <BROADCAST,MULTICAST,ALLMULTI,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN
link/ether 26:f8:84:02:f9:2a brd ff:ff:ff:ff:ff:ff
[ROUTE]ff00::/8 dev macvlan0 table local metric 256 mtu 1500 advmss 1440 hoplimit 0
[ROUTE]fe80::/64 dev macvlan0 proto kernel metric 256 mtu 1500 advmss 1440 hoplimit 0
[LINK]11: macvlan0@eth0: <BROADCAST,MULTICAST,ALLMULTI,UP,LOWER_UP> mtu 1500
link/ether 26:f8:84:02:f9:2a
[ADDR]11: macvlan0 inet6 fe80::24f8:84ff:fe02:f92a/64 scope link
valid_lft forever preferred_lft forever
[ROUTE]local fe80::24f8:84ff:fe02:f92a via :: dev lo table local proto none metric 0 mtu 16436 advmss 16376 hoplimit 0
[ROUTE]default via fe80::215:e9ff:fef0:10f8 dev macvlan0 proto kernel metric 1024 mtu 1500 advmss 1440 hoplimit 0
[NEIGH]fe80::215:e9ff:fef0:10f8 dev macvlan0 lladdr 00:15:e9:f0:10:f8 router STALE
[ROUTE]2001:6f8:974::/64 dev macvlan0 proto kernel metric 256 expires 0sec mtu 1500 advmss 1440 hoplimit 0
[PREFIX]prefix 2001:6f8:974::/64 dev macvlan0 onlink autoconf valid 14400 preferred 131084
[ADDR]11: macvlan0 inet6 2001:6f8:974:0:24f8:84ff:fe02:f92a/64 scope global dynamic
valid_lft 86399sec preferred_lft 14399sec
# add VLAN to eth1, eth1 is down
#
$ ip link add link eth1 up type vlan id 1000
RTNETLINK answers: Network is down
<no events>
Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2010-02-26 06:34:54 +00:00
|
|
|
}
|
2007-09-25 23:14:46 +00:00
|
|
|
|
2017-06-21 09:12:24 +00:00
|
|
|
if (ifmp && tbp[IFLA_IFNAME]) {
|
2007-09-25 23:14:46 +00:00
|
|
|
nla_strlcpy(ifname, tbp[IFLA_IFNAME], IFNAMSIZ);
|
2014-07-14 14:37:25 +00:00
|
|
|
name_assign_type = NET_NAME_USER;
|
|
|
|
} else {
|
2007-09-25 23:14:46 +00:00
|
|
|
snprintf(ifname, IFNAMSIZ, DRV_NAME "%%d");
|
2014-07-14 14:37:25 +00:00
|
|
|
name_assign_type = NET_NAME_ENUM;
|
|
|
|
}
|
2007-09-25 23:14:46 +00:00
|
|
|
|
2009-11-08 08:53:51 +00:00
|
|
|
net = rtnl_link_get_net(src_net, tbp);
|
|
|
|
if (IS_ERR(net))
|
|
|
|
return PTR_ERR(net);
|
|
|
|
|
2014-07-14 14:37:25 +00:00
|
|
|
peer = rtnl_create_link(net, ifname, name_assign_type,
|
|
|
|
&veth_link_ops, tbp);
|
2009-11-08 08:53:51 +00:00
|
|
|
if (IS_ERR(peer)) {
|
|
|
|
put_net(net);
|
2007-09-25 23:14:46 +00:00
|
|
|
return PTR_ERR(peer);
|
2009-11-08 08:53:51 +00:00
|
|
|
}
|
2007-09-25 23:14:46 +00:00
|
|
|
|
2017-06-21 09:12:24 +00:00
|
|
|
if (!ifmp || !tbp[IFLA_ADDRESS])
|
2012-02-15 06:45:39 +00:00
|
|
|
eth_hw_addr_random(peer);
|
2012-08-08 21:53:03 +00:00
|
|
|
|
|
|
|
if (ifmp && (dev->ifindex != 0))
|
|
|
|
peer->ifindex = ifmp->ifi_index;
|
2007-09-25 23:14:46 +00:00
|
|
|
|
|
|
|
err = register_netdevice(peer);
|
2009-11-08 08:53:51 +00:00
|
|
|
put_net(net);
|
|
|
|
net = NULL;
|
2007-09-25 23:14:46 +00:00
|
|
|
if (err < 0)
|
|
|
|
goto err_register_peer;
|
|
|
|
|
|
|
|
netif_carrier_off(peer);
|
|
|
|
|
rtnetlink: support specifying device flags on device creation
commit e8469ed959c373c2ff9e6f488aa5a14971aebe1f
Author: Patrick McHardy <kaber@trash.net>
Date: Tue Feb 23 20:41:30 2010 +0100
Support specifying the initial device flags when creating a device though
rtnl_link. Devices allocated by rtnl_create_link() are marked as INITIALIZING
in order to surpress netlink registration notifications. To complete setup,
rtnl_configure_link() must be called, which performs the device flag changes
and invokes the deferred notifiers if everything went well.
Two examples:
# add macvlan to eth0
#
$ ip link add link eth0 up allmulticast on type macvlan
[LINK]11: macvlan0@eth0: <BROADCAST,MULTICAST,ALLMULTI,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN
link/ether 26:f8:84:02:f9:2a brd ff:ff:ff:ff:ff:ff
[ROUTE]ff00::/8 dev macvlan0 table local metric 256 mtu 1500 advmss 1440 hoplimit 0
[ROUTE]fe80::/64 dev macvlan0 proto kernel metric 256 mtu 1500 advmss 1440 hoplimit 0
[LINK]11: macvlan0@eth0: <BROADCAST,MULTICAST,ALLMULTI,UP,LOWER_UP> mtu 1500
link/ether 26:f8:84:02:f9:2a
[ADDR]11: macvlan0 inet6 fe80::24f8:84ff:fe02:f92a/64 scope link
valid_lft forever preferred_lft forever
[ROUTE]local fe80::24f8:84ff:fe02:f92a via :: dev lo table local proto none metric 0 mtu 16436 advmss 16376 hoplimit 0
[ROUTE]default via fe80::215:e9ff:fef0:10f8 dev macvlan0 proto kernel metric 1024 mtu 1500 advmss 1440 hoplimit 0
[NEIGH]fe80::215:e9ff:fef0:10f8 dev macvlan0 lladdr 00:15:e9:f0:10:f8 router STALE
[ROUTE]2001:6f8:974::/64 dev macvlan0 proto kernel metric 256 expires 0sec mtu 1500 advmss 1440 hoplimit 0
[PREFIX]prefix 2001:6f8:974::/64 dev macvlan0 onlink autoconf valid 14400 preferred 131084
[ADDR]11: macvlan0 inet6 2001:6f8:974:0:24f8:84ff:fe02:f92a/64 scope global dynamic
valid_lft 86399sec preferred_lft 14399sec
# add VLAN to eth1, eth1 is down
#
$ ip link add link eth1 up type vlan id 1000
RTNETLINK answers: Network is down
<no events>
Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2010-02-26 06:34:54 +00:00
|
|
|
err = rtnl_configure_link(peer, ifmp);
|
|
|
|
if (err < 0)
|
|
|
|
goto err_configure_peer;
|
|
|
|
|
2007-09-25 23:14:46 +00:00
|
|
|
/*
|
|
|
|
* register dev last
|
|
|
|
*
|
|
|
|
* note, that since we've registered new device the dev's name
|
|
|
|
* should be re-allocated
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (tb[IFLA_ADDRESS] == NULL)
|
2012-02-15 06:45:39 +00:00
|
|
|
eth_hw_addr_random(dev);
|
2007-09-25 23:14:46 +00:00
|
|
|
|
2011-04-30 01:28:17 +00:00
|
|
|
if (tb[IFLA_IFNAME])
|
|
|
|
nla_strlcpy(dev->name, tb[IFLA_IFNAME], IFNAMSIZ);
|
|
|
|
else
|
|
|
|
snprintf(dev->name, IFNAMSIZ, DRV_NAME "%%d");
|
|
|
|
|
2007-09-25 23:14:46 +00:00
|
|
|
err = register_netdevice(dev);
|
|
|
|
if (err < 0)
|
|
|
|
goto err_register_dev;
|
|
|
|
|
|
|
|
netif_carrier_off(dev);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* tie the deviced together
|
|
|
|
*/
|
|
|
|
|
|
|
|
priv = netdev_priv(dev);
|
2013-01-04 15:42:40 +00:00
|
|
|
rcu_assign_pointer(priv->peer, peer);
|
2007-09-25 23:14:46 +00:00
|
|
|
|
|
|
|
priv = netdev_priv(peer);
|
2013-01-04 15:42:40 +00:00
|
|
|
rcu_assign_pointer(priv->peer, dev);
|
2007-09-25 23:14:46 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_register_dev:
|
|
|
|
/* nothing to do */
|
rtnetlink: support specifying device flags on device creation
commit e8469ed959c373c2ff9e6f488aa5a14971aebe1f
Author: Patrick McHardy <kaber@trash.net>
Date: Tue Feb 23 20:41:30 2010 +0100
Support specifying the initial device flags when creating a device though
rtnl_link. Devices allocated by rtnl_create_link() are marked as INITIALIZING
in order to surpress netlink registration notifications. To complete setup,
rtnl_configure_link() must be called, which performs the device flag changes
and invokes the deferred notifiers if everything went well.
Two examples:
# add macvlan to eth0
#
$ ip link add link eth0 up allmulticast on type macvlan
[LINK]11: macvlan0@eth0: <BROADCAST,MULTICAST,ALLMULTI,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN
link/ether 26:f8:84:02:f9:2a brd ff:ff:ff:ff:ff:ff
[ROUTE]ff00::/8 dev macvlan0 table local metric 256 mtu 1500 advmss 1440 hoplimit 0
[ROUTE]fe80::/64 dev macvlan0 proto kernel metric 256 mtu 1500 advmss 1440 hoplimit 0
[LINK]11: macvlan0@eth0: <BROADCAST,MULTICAST,ALLMULTI,UP,LOWER_UP> mtu 1500
link/ether 26:f8:84:02:f9:2a
[ADDR]11: macvlan0 inet6 fe80::24f8:84ff:fe02:f92a/64 scope link
valid_lft forever preferred_lft forever
[ROUTE]local fe80::24f8:84ff:fe02:f92a via :: dev lo table local proto none metric 0 mtu 16436 advmss 16376 hoplimit 0
[ROUTE]default via fe80::215:e9ff:fef0:10f8 dev macvlan0 proto kernel metric 1024 mtu 1500 advmss 1440 hoplimit 0
[NEIGH]fe80::215:e9ff:fef0:10f8 dev macvlan0 lladdr 00:15:e9:f0:10:f8 router STALE
[ROUTE]2001:6f8:974::/64 dev macvlan0 proto kernel metric 256 expires 0sec mtu 1500 advmss 1440 hoplimit 0
[PREFIX]prefix 2001:6f8:974::/64 dev macvlan0 onlink autoconf valid 14400 preferred 131084
[ADDR]11: macvlan0 inet6 2001:6f8:974:0:24f8:84ff:fe02:f92a/64 scope global dynamic
valid_lft 86399sec preferred_lft 14399sec
# add VLAN to eth1, eth1 is down
#
$ ip link add link eth1 up type vlan id 1000
RTNETLINK answers: Network is down
<no events>
Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2010-02-26 06:34:54 +00:00
|
|
|
err_configure_peer:
|
2007-09-25 23:14:46 +00:00
|
|
|
unregister_netdevice(peer);
|
|
|
|
return err;
|
|
|
|
|
|
|
|
err_register_peer:
|
|
|
|
free_netdev(peer);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2009-10-27 07:06:36 +00:00
|
|
|
static void veth_dellink(struct net_device *dev, struct list_head *head)
|
2007-09-25 23:14:46 +00:00
|
|
|
{
|
|
|
|
struct veth_priv *priv;
|
|
|
|
struct net_device *peer;
|
|
|
|
|
|
|
|
priv = netdev_priv(dev);
|
2013-01-04 15:42:40 +00:00
|
|
|
peer = rtnl_dereference(priv->peer);
|
|
|
|
|
|
|
|
/* Note : dellink() is called from default_device_exit_batch(),
|
|
|
|
* before a rcu_synchronize() point. The devices are guaranteed
|
|
|
|
* not being freed before one RCU grace period.
|
|
|
|
*/
|
|
|
|
RCU_INIT_POINTER(priv->peer, NULL);
|
2009-10-30 08:00:27 +00:00
|
|
|
unregister_netdevice_queue(dev, head);
|
2013-02-08 20:10:49 +00:00
|
|
|
|
|
|
|
if (peer) {
|
|
|
|
priv = netdev_priv(peer);
|
|
|
|
RCU_INIT_POINTER(priv->peer, NULL);
|
|
|
|
unregister_netdevice_queue(peer, head);
|
|
|
|
}
|
2007-09-25 23:14:46 +00:00
|
|
|
}
|
|
|
|
|
2012-02-15 04:09:46 +00:00
|
|
|
static const struct nla_policy veth_policy[VETH_INFO_MAX + 1] = {
|
|
|
|
[VETH_INFO_PEER] = { .len = sizeof(struct ifinfomsg) },
|
|
|
|
};
|
2007-09-25 23:14:46 +00:00
|
|
|
|
2015-01-20 14:15:46 +00:00
|
|
|
static struct net *veth_get_link_net(const struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct veth_priv *priv = netdev_priv(dev);
|
|
|
|
struct net_device *peer = rtnl_dereference(priv->peer);
|
|
|
|
|
|
|
|
return peer ? dev_net(peer) : dev_net(dev);
|
|
|
|
}
|
|
|
|
|
2007-09-25 23:14:46 +00:00
|
|
|
static struct rtnl_link_ops veth_link_ops = {
|
|
|
|
.kind = DRV_NAME,
|
|
|
|
.priv_size = sizeof(struct veth_priv),
|
|
|
|
.setup = veth_setup,
|
|
|
|
.validate = veth_validate,
|
|
|
|
.newlink = veth_newlink,
|
|
|
|
.dellink = veth_dellink,
|
|
|
|
.policy = veth_policy,
|
|
|
|
.maxtype = VETH_INFO_MAX,
|
2015-01-20 14:15:46 +00:00
|
|
|
.get_link_net = veth_get_link_net,
|
2007-09-25 23:14:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* init/fini
|
|
|
|
*/
|
|
|
|
|
|
|
|
static __init int veth_init(void)
|
|
|
|
{
|
|
|
|
return rtnl_link_register(&veth_link_ops);
|
|
|
|
}
|
|
|
|
|
|
|
|
static __exit void veth_exit(void)
|
|
|
|
{
|
2008-01-21 01:25:14 +00:00
|
|
|
rtnl_link_unregister(&veth_link_ops);
|
2007-09-25 23:14:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(veth_init);
|
|
|
|
module_exit(veth_exit);
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("Virtual Ethernet Tunnel");
|
|
|
|
MODULE_LICENSE("GPL v2");
|
|
|
|
MODULE_ALIAS_RTNL_LINK(DRV_NAME);
|