11 #include <linux/netdevice.h>
12 #include <linux/slab.h>
13 #include <linux/ethtool.h>
20 #include <linux/module.h>
22 #define DRV_NAME "veth"
23 #define DRV_VERSION "1.0"
48 } ethtool_stats_keys[] = {
77 memcpy(buf, ðtool_stats_keys,
sizeof(ethtool_stats_keys));
82 static int veth_get_sset_count(
struct net_device *dev,
int sset)
92 static void veth_get_ethtool_stats(
struct net_device *dev,
97 priv = netdev_priv(dev);
98 data[0] = priv->
peer->ifindex;
101 static const struct ethtool_ops veth_ethtool_ops = {
102 .get_settings = veth_get_settings,
103 .get_drvinfo = veth_get_drvinfo,
105 .get_strings = veth_get_strings,
106 .get_sset_count = veth_get_sset_count,
107 .get_ethtool_stats = veth_get_ethtool_stats,
121 priv = netdev_priv(dev);
123 rcv_priv = netdev_priv(rcv);
138 u64_stats_update_begin(&stats->
syncp);
141 u64_stats_update_end(&stats->
syncp);
143 u64_stats_update_begin(&rcv_stats->
syncp);
146 u64_stats_update_end(&rcv_stats->
syncp);
151 u64_stats_update_begin(&rcv_stats->
syncp);
153 u64_stats_update_end(&rcv_stats->
syncp);
164 struct veth_priv *priv = netdev_priv(dev);
174 start = u64_stats_fetch_begin_bh(&stats->
syncp);
180 }
while (u64_stats_fetch_retry_bh(&stats->
syncp, start));
195 priv = netdev_priv(dev);
208 struct veth_priv *priv = netdev_priv(dev);
216 static int is_valid_veth_mtu(
int new_mtu)
221 static int veth_change_mtu(
struct net_device *dev,
int new_mtu)
223 if (!is_valid_veth_mtu(new_mtu))
229 static int veth_dev_init(
struct net_device *dev)
238 priv = netdev_priv(dev);
243 static void veth_dev_free(
struct net_device *dev)
247 priv = netdev_priv(dev);
253 .ndo_init = veth_dev_init,
254 .ndo_open = veth_open,
255 .ndo_stop = veth_close,
256 .ndo_start_xmit = veth_xmit,
257 .ndo_change_mtu = veth_change_mtu,
258 .ndo_get_stats64 = veth_get_stats64,
262 static void veth_setup(
struct net_device *dev)
283 if (nla_len(tb[IFLA_ADDRESS]) !=
ETH_ALEN)
285 if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS])))
289 if (!is_valid_veth_mtu(nla_get_u32(tb[IFLA_MTU])))
297 static int veth_newlink(
struct net *src_net,
struct net_device *dev,
315 ifmp = nla_data(nla_peer);
317 nla_data(nla_peer) +
sizeof(
struct ifinfomsg),
323 err = veth_validate(peer_tb,
NULL);
345 return PTR_ERR(peer);
348 if (tbp[IFLA_ADDRESS] ==
NULL)
349 eth_hw_addr_random(peer);
351 if (ifmp && (dev->
ifindex != 0))
358 goto err_register_peer;
364 goto err_configure_peer;
373 if (tb[IFLA_ADDRESS] ==
NULL)
374 eth_hw_addr_random(dev);
389 goto err_register_dev;
397 priv = netdev_priv(dev);
400 priv = netdev_priv(peer);
408 unregister_netdevice(peer);
421 priv = netdev_priv(dev);
436 .validate = veth_validate,
437 .newlink = veth_newlink,
438 .dellink = veth_dellink,
439 .policy = veth_policy,
447 static __init int veth_init(
void)
452 static __exit void veth_exit(
void)