Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 1 | /* |
| 2 | * drivers/net/veth.c |
| 3 | * |
| 4 | * Copyright (C) 2007 OpenVZ http://openvz.org, SWsoft Inc |
| 5 | * |
| 6 | * Author: Pavel Emelianov <xemul@openvz.org> |
| 7 | * Ethtool interface from: Eric W. Biederman <ebiederm@xmission.com> |
| 8 | * |
| 9 | */ |
| 10 | |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 11 | #include <linux/netdevice.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 12 | #include <linux/slab.h> |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 13 | #include <linux/ethtool.h> |
| 14 | #include <linux/etherdevice.h> |
Eric Dumazet | cf05c70 | 2011-06-19 22:48:34 -0700 | [diff] [blame] | 15 | #include <linux/u64_stats_sync.h> |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 16 | |
Jiri Pirko | f7b1260 | 2014-02-18 20:53:18 +0100 | [diff] [blame] | 17 | #include <net/rtnetlink.h> |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 18 | #include <net/dst.h> |
| 19 | #include <net/xfrm.h> |
Toshiaki Makita | af87a3a | 2018-08-03 16:58:14 +0900 | [diff] [blame^] | 20 | #include <net/xdp.h> |
Stephen Hemminger | ecef969 | 2007-12-25 17:23:59 -0800 | [diff] [blame] | 21 | #include <linux/veth.h> |
Paul Gortmaker | 9d9779e | 2011-07-03 15:21:01 -0400 | [diff] [blame] | 22 | #include <linux/module.h> |
Toshiaki Makita | 948d4f2 | 2018-08-03 16:58:10 +0900 | [diff] [blame] | 23 | #include <linux/bpf.h> |
| 24 | #include <linux/filter.h> |
| 25 | #include <linux/ptr_ring.h> |
Toshiaki Makita | 948d4f2 | 2018-08-03 16:58:10 +0900 | [diff] [blame] | 26 | #include <linux/bpf_trace.h> |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 27 | |
| 28 | #define DRV_NAME "veth" |
| 29 | #define DRV_VERSION "1.0" |
| 30 | |
Toshiaki Makita | 9fc8d51 | 2018-08-03 16:58:13 +0900 | [diff] [blame] | 31 | #define VETH_XDP_FLAG BIT(0) |
Toshiaki Makita | 948d4f2 | 2018-08-03 16:58:10 +0900 | [diff] [blame] | 32 | #define VETH_RING_SIZE 256 |
| 33 | #define VETH_XDP_HEADROOM (XDP_PACKET_HEADROOM + NET_IP_ALIGN) |
| 34 | |
Eric Dumazet | 2681128 | 2012-12-29 16:02:43 +0000 | [diff] [blame] | 35 | struct pcpu_vstats { |
| 36 | u64 packets; |
| 37 | u64 bytes; |
Eric Dumazet | cf05c70 | 2011-06-19 22:48:34 -0700 | [diff] [blame] | 38 | struct u64_stats_sync syncp; |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | struct veth_priv { |
Toshiaki Makita | 948d4f2 | 2018-08-03 16:58:10 +0900 | [diff] [blame] | 42 | struct napi_struct xdp_napi; |
| 43 | struct net_device *dev; |
| 44 | struct bpf_prog __rcu *xdp_prog; |
| 45 | struct bpf_prog *_xdp_prog; |
Eric Dumazet | d0e2c55 | 2013-01-04 15:42:40 +0000 | [diff] [blame] | 46 | struct net_device __rcu *peer; |
Eric Dumazet | 2681128 | 2012-12-29 16:02:43 +0000 | [diff] [blame] | 47 | atomic64_t dropped; |
Paolo Abeni | 163e529 | 2016-02-26 10:45:41 +0100 | [diff] [blame] | 48 | unsigned requested_headroom; |
Toshiaki Makita | 948d4f2 | 2018-08-03 16:58:10 +0900 | [diff] [blame] | 49 | bool rx_notify_masked; |
| 50 | struct ptr_ring xdp_ring; |
| 51 | struct xdp_rxq_info xdp_rxq; |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 52 | }; |
| 53 | |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 54 | /* |
| 55 | * ethtool interface |
| 56 | */ |
| 57 | |
| 58 | static struct { |
| 59 | const char string[ETH_GSTRING_LEN]; |
| 60 | } ethtool_stats_keys[] = { |
| 61 | { "peer_ifindex" }, |
| 62 | }; |
| 63 | |
Philippe Reynes | 56607b9 | 2017-03-29 08:24:21 +0200 | [diff] [blame] | 64 | static int veth_get_link_ksettings(struct net_device *dev, |
| 65 | struct ethtool_link_ksettings *cmd) |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 66 | { |
Philippe Reynes | 56607b9 | 2017-03-29 08:24:21 +0200 | [diff] [blame] | 67 | cmd->base.speed = SPEED_10000; |
| 68 | cmd->base.duplex = DUPLEX_FULL; |
| 69 | cmd->base.port = PORT_TP; |
| 70 | cmd->base.autoneg = AUTONEG_DISABLE; |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 71 | return 0; |
| 72 | } |
| 73 | |
| 74 | static void veth_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) |
| 75 | { |
Rick Jones | 33a5ba1 | 2011-11-15 14:59:53 +0000 | [diff] [blame] | 76 | strlcpy(info->driver, DRV_NAME, sizeof(info->driver)); |
| 77 | strlcpy(info->version, DRV_VERSION, sizeof(info->version)); |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | static void veth_get_strings(struct net_device *dev, u32 stringset, u8 *buf) |
| 81 | { |
| 82 | switch(stringset) { |
| 83 | case ETH_SS_STATS: |
| 84 | memcpy(buf, ðtool_stats_keys, sizeof(ethtool_stats_keys)); |
| 85 | break; |
| 86 | } |
| 87 | } |
| 88 | |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 89 | static int veth_get_sset_count(struct net_device *dev, int sset) |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 90 | { |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 91 | switch (sset) { |
| 92 | case ETH_SS_STATS: |
| 93 | return ARRAY_SIZE(ethtool_stats_keys); |
| 94 | default: |
| 95 | return -EOPNOTSUPP; |
| 96 | } |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | static void veth_get_ethtool_stats(struct net_device *dev, |
| 100 | struct ethtool_stats *stats, u64 *data) |
| 101 | { |
Eric Dumazet | d0e2c55 | 2013-01-04 15:42:40 +0000 | [diff] [blame] | 102 | struct veth_priv *priv = netdev_priv(dev); |
| 103 | struct net_device *peer = rtnl_dereference(priv->peer); |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 104 | |
Eric Dumazet | d0e2c55 | 2013-01-04 15:42:40 +0000 | [diff] [blame] | 105 | data[0] = peer ? peer->ifindex : 0; |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 106 | } |
| 107 | |
Stephen Hemminger | 0fc0b73 | 2009-09-02 01:03:33 -0700 | [diff] [blame] | 108 | static const struct ethtool_ops veth_ethtool_ops = { |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 109 | .get_drvinfo = veth_get_drvinfo, |
| 110 | .get_link = ethtool_op_get_link, |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 111 | .get_strings = veth_get_strings, |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 112 | .get_sset_count = veth_get_sset_count, |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 113 | .get_ethtool_stats = veth_get_ethtool_stats, |
Philippe Reynes | 56607b9 | 2017-03-29 08:24:21 +0200 | [diff] [blame] | 114 | .get_link_ksettings = veth_get_link_ksettings, |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 115 | }; |
| 116 | |
Toshiaki Makita | 948d4f2 | 2018-08-03 16:58:10 +0900 | [diff] [blame] | 117 | /* general routines */ |
| 118 | |
Toshiaki Makita | 9fc8d51 | 2018-08-03 16:58:13 +0900 | [diff] [blame] | 119 | static bool veth_is_xdp_frame(void *ptr) |
| 120 | { |
| 121 | return (unsigned long)ptr & VETH_XDP_FLAG; |
| 122 | } |
| 123 | |
| 124 | static void *veth_ptr_to_xdp(void *ptr) |
| 125 | { |
| 126 | return (void *)((unsigned long)ptr & ~VETH_XDP_FLAG); |
| 127 | } |
| 128 | |
Toshiaki Makita | af87a3a | 2018-08-03 16:58:14 +0900 | [diff] [blame^] | 129 | static void *veth_xdp_to_ptr(void *ptr) |
| 130 | { |
| 131 | return (void *)((unsigned long)ptr | VETH_XDP_FLAG); |
| 132 | } |
| 133 | |
Toshiaki Makita | 9fc8d51 | 2018-08-03 16:58:13 +0900 | [diff] [blame] | 134 | static void veth_ptr_free(void *ptr) |
| 135 | { |
| 136 | if (veth_is_xdp_frame(ptr)) |
| 137 | xdp_return_frame(veth_ptr_to_xdp(ptr)); |
| 138 | else |
| 139 | kfree_skb(ptr); |
| 140 | } |
| 141 | |
Toshiaki Makita | 948d4f2 | 2018-08-03 16:58:10 +0900 | [diff] [blame] | 142 | static void __veth_xdp_flush(struct veth_priv *priv) |
| 143 | { |
| 144 | /* Write ptr_ring before reading rx_notify_masked */ |
| 145 | smp_mb(); |
| 146 | if (!priv->rx_notify_masked) { |
| 147 | priv->rx_notify_masked = true; |
| 148 | napi_schedule(&priv->xdp_napi); |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | static int veth_xdp_rx(struct veth_priv *priv, struct sk_buff *skb) |
| 153 | { |
| 154 | if (unlikely(ptr_ring_produce(&priv->xdp_ring, skb))) { |
| 155 | dev_kfree_skb_any(skb); |
| 156 | return NET_RX_DROP; |
| 157 | } |
| 158 | |
| 159 | return NET_RX_SUCCESS; |
| 160 | } |
| 161 | |
| 162 | static int veth_forward_skb(struct net_device *dev, struct sk_buff *skb, bool xdp) |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 163 | { |
Eric Dumazet | 2681128 | 2012-12-29 16:02:43 +0000 | [diff] [blame] | 164 | struct veth_priv *priv = netdev_priv(dev); |
Toshiaki Makita | 948d4f2 | 2018-08-03 16:58:10 +0900 | [diff] [blame] | 165 | |
| 166 | return __dev_forward_skb(dev, skb) ?: xdp ? |
| 167 | veth_xdp_rx(priv, skb) : |
| 168 | netif_rx(skb); |
| 169 | } |
| 170 | |
| 171 | static netdev_tx_t veth_xmit(struct sk_buff *skb, struct net_device *dev) |
| 172 | { |
| 173 | struct veth_priv *rcv_priv, *priv = netdev_priv(dev); |
Eric Dumazet | d0e2c55 | 2013-01-04 15:42:40 +0000 | [diff] [blame] | 174 | struct net_device *rcv; |
Eric Dumazet | 2681128 | 2012-12-29 16:02:43 +0000 | [diff] [blame] | 175 | int length = skb->len; |
Toshiaki Makita | 948d4f2 | 2018-08-03 16:58:10 +0900 | [diff] [blame] | 176 | bool rcv_xdp = false; |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 177 | |
Eric Dumazet | d0e2c55 | 2013-01-04 15:42:40 +0000 | [diff] [blame] | 178 | rcu_read_lock(); |
| 179 | rcv = rcu_dereference(priv->peer); |
| 180 | if (unlikely(!rcv)) { |
| 181 | kfree_skb(skb); |
| 182 | goto drop; |
| 183 | } |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 184 | |
Toshiaki Makita | 948d4f2 | 2018-08-03 16:58:10 +0900 | [diff] [blame] | 185 | rcv_priv = netdev_priv(rcv); |
| 186 | rcv_xdp = rcu_access_pointer(rcv_priv->xdp_prog); |
| 187 | |
| 188 | if (likely(veth_forward_skb(rcv, skb, rcv_xdp) == NET_RX_SUCCESS)) { |
Eric Dumazet | 2681128 | 2012-12-29 16:02:43 +0000 | [diff] [blame] | 189 | struct pcpu_vstats *stats = this_cpu_ptr(dev->vstats); |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 190 | |
Eric Dumazet | 2681128 | 2012-12-29 16:02:43 +0000 | [diff] [blame] | 191 | u64_stats_update_begin(&stats->syncp); |
| 192 | stats->bytes += length; |
| 193 | stats->packets++; |
| 194 | u64_stats_update_end(&stats->syncp); |
| 195 | } else { |
Eric Dumazet | d0e2c55 | 2013-01-04 15:42:40 +0000 | [diff] [blame] | 196 | drop: |
Eric Dumazet | 2681128 | 2012-12-29 16:02:43 +0000 | [diff] [blame] | 197 | atomic64_inc(&priv->dropped); |
| 198 | } |
Toshiaki Makita | 948d4f2 | 2018-08-03 16:58:10 +0900 | [diff] [blame] | 199 | |
| 200 | if (rcv_xdp) |
| 201 | __veth_xdp_flush(rcv_priv); |
| 202 | |
Eric Dumazet | d0e2c55 | 2013-01-04 15:42:40 +0000 | [diff] [blame] | 203 | rcu_read_unlock(); |
Toshiaki Makita | 948d4f2 | 2018-08-03 16:58:10 +0900 | [diff] [blame] | 204 | |
Patrick McHardy | 6ed1065 | 2009-06-23 06:03:08 +0000 | [diff] [blame] | 205 | return NETDEV_TX_OK; |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 206 | } |
| 207 | |
Eric Dumazet | 2681128 | 2012-12-29 16:02:43 +0000 | [diff] [blame] | 208 | static u64 veth_stats_one(struct pcpu_vstats *result, struct net_device *dev) |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 209 | { |
Eric Dumazet | cf05c70 | 2011-06-19 22:48:34 -0700 | [diff] [blame] | 210 | struct veth_priv *priv = netdev_priv(dev); |
David S. Miller | 11687a1 | 2009-06-25 02:45:42 -0700 | [diff] [blame] | 211 | int cpu; |
David S. Miller | 11687a1 | 2009-06-25 02:45:42 -0700 | [diff] [blame] | 212 | |
Eric Dumazet | 2681128 | 2012-12-29 16:02:43 +0000 | [diff] [blame] | 213 | result->packets = 0; |
| 214 | result->bytes = 0; |
Eric Dumazet | 2b1c8b0 | 2009-11-18 07:09:39 +0000 | [diff] [blame] | 215 | for_each_possible_cpu(cpu) { |
Eric Dumazet | 2681128 | 2012-12-29 16:02:43 +0000 | [diff] [blame] | 216 | struct pcpu_vstats *stats = per_cpu_ptr(dev->vstats, cpu); |
| 217 | u64 packets, bytes; |
Eric Dumazet | cf05c70 | 2011-06-19 22:48:34 -0700 | [diff] [blame] | 218 | unsigned int start; |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 219 | |
Eric Dumazet | cf05c70 | 2011-06-19 22:48:34 -0700 | [diff] [blame] | 220 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 221 | start = u64_stats_fetch_begin_irq(&stats->syncp); |
Eric Dumazet | 2681128 | 2012-12-29 16:02:43 +0000 | [diff] [blame] | 222 | packets = stats->packets; |
| 223 | bytes = stats->bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 224 | } while (u64_stats_fetch_retry_irq(&stats->syncp, start)); |
Eric Dumazet | 2681128 | 2012-12-29 16:02:43 +0000 | [diff] [blame] | 225 | result->packets += packets; |
| 226 | result->bytes += bytes; |
David S. Miller | 11687a1 | 2009-06-25 02:45:42 -0700 | [diff] [blame] | 227 | } |
Eric Dumazet | 2681128 | 2012-12-29 16:02:43 +0000 | [diff] [blame] | 228 | return atomic64_read(&priv->dropped); |
| 229 | } |
| 230 | |
stephen hemminger | bc1f447 | 2017-01-06 19:12:52 -0800 | [diff] [blame] | 231 | static void veth_get_stats64(struct net_device *dev, |
| 232 | struct rtnl_link_stats64 *tot) |
Eric Dumazet | 2681128 | 2012-12-29 16:02:43 +0000 | [diff] [blame] | 233 | { |
| 234 | struct veth_priv *priv = netdev_priv(dev); |
Eric Dumazet | d0e2c55 | 2013-01-04 15:42:40 +0000 | [diff] [blame] | 235 | struct net_device *peer; |
Eric Dumazet | 2681128 | 2012-12-29 16:02:43 +0000 | [diff] [blame] | 236 | struct pcpu_vstats one; |
| 237 | |
| 238 | tot->tx_dropped = veth_stats_one(&one, dev); |
| 239 | tot->tx_bytes = one.bytes; |
| 240 | tot->tx_packets = one.packets; |
| 241 | |
Eric Dumazet | d0e2c55 | 2013-01-04 15:42:40 +0000 | [diff] [blame] | 242 | rcu_read_lock(); |
| 243 | peer = rcu_dereference(priv->peer); |
| 244 | if (peer) { |
| 245 | tot->rx_dropped = veth_stats_one(&one, peer); |
| 246 | tot->rx_bytes = one.bytes; |
| 247 | tot->rx_packets = one.packets; |
| 248 | } |
| 249 | rcu_read_unlock(); |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 250 | } |
| 251 | |
Gao feng | 5c70ef8 | 2013-10-04 16:52:24 +0800 | [diff] [blame] | 252 | /* fake multicast ability */ |
| 253 | static void veth_set_multicast_list(struct net_device *dev) |
| 254 | { |
| 255 | } |
| 256 | |
Toshiaki Makita | 948d4f2 | 2018-08-03 16:58:10 +0900 | [diff] [blame] | 257 | static struct sk_buff *veth_build_skb(void *head, int headroom, int len, |
| 258 | int buflen) |
| 259 | { |
| 260 | struct sk_buff *skb; |
| 261 | |
| 262 | if (!buflen) { |
| 263 | buflen = SKB_DATA_ALIGN(headroom + len) + |
| 264 | SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); |
| 265 | } |
| 266 | skb = build_skb(head, buflen); |
| 267 | if (!skb) |
| 268 | return NULL; |
| 269 | |
| 270 | skb_reserve(skb, headroom); |
| 271 | skb_put(skb, len); |
| 272 | |
| 273 | return skb; |
| 274 | } |
| 275 | |
Toshiaki Makita | af87a3a | 2018-08-03 16:58:14 +0900 | [diff] [blame^] | 276 | static int veth_xdp_xmit(struct net_device *dev, int n, |
| 277 | struct xdp_frame **frames, u32 flags) |
| 278 | { |
| 279 | struct veth_priv *rcv_priv, *priv = netdev_priv(dev); |
| 280 | struct net_device *rcv; |
| 281 | unsigned int max_len; |
| 282 | int i, drops = 0; |
| 283 | |
| 284 | if (unlikely(flags & ~XDP_XMIT_FLAGS_MASK)) |
| 285 | return -EINVAL; |
| 286 | |
| 287 | rcv = rcu_dereference(priv->peer); |
| 288 | if (unlikely(!rcv)) |
| 289 | return -ENXIO; |
| 290 | |
| 291 | rcv_priv = netdev_priv(rcv); |
| 292 | /* Non-NULL xdp_prog ensures that xdp_ring is initialized on receive |
| 293 | * side. This means an XDP program is loaded on the peer and the peer |
| 294 | * device is up. |
| 295 | */ |
| 296 | if (!rcu_access_pointer(rcv_priv->xdp_prog)) |
| 297 | return -ENXIO; |
| 298 | |
| 299 | max_len = rcv->mtu + rcv->hard_header_len + VLAN_HLEN; |
| 300 | |
| 301 | spin_lock(&rcv_priv->xdp_ring.producer_lock); |
| 302 | for (i = 0; i < n; i++) { |
| 303 | struct xdp_frame *frame = frames[i]; |
| 304 | void *ptr = veth_xdp_to_ptr(frame); |
| 305 | |
| 306 | if (unlikely(frame->len > max_len || |
| 307 | __ptr_ring_produce(&rcv_priv->xdp_ring, ptr))) { |
| 308 | xdp_return_frame_rx_napi(frame); |
| 309 | drops++; |
| 310 | } |
| 311 | } |
| 312 | spin_unlock(&rcv_priv->xdp_ring.producer_lock); |
| 313 | |
| 314 | if (flags & XDP_XMIT_FLUSH) |
| 315 | __veth_xdp_flush(rcv_priv); |
| 316 | |
| 317 | return n - drops; |
| 318 | } |
| 319 | |
Toshiaki Makita | 9fc8d51 | 2018-08-03 16:58:13 +0900 | [diff] [blame] | 320 | static struct sk_buff *veth_xdp_rcv_one(struct veth_priv *priv, |
| 321 | struct xdp_frame *frame) |
| 322 | { |
| 323 | void *hard_start = frame->data - frame->headroom; |
| 324 | void *head = hard_start - sizeof(struct xdp_frame); |
| 325 | int len = frame->len, delta = 0; |
| 326 | struct bpf_prog *xdp_prog; |
| 327 | unsigned int headroom; |
| 328 | struct sk_buff *skb; |
| 329 | |
| 330 | rcu_read_lock(); |
| 331 | xdp_prog = rcu_dereference(priv->xdp_prog); |
| 332 | if (likely(xdp_prog)) { |
| 333 | struct xdp_buff xdp; |
| 334 | u32 act; |
| 335 | |
| 336 | xdp.data_hard_start = hard_start; |
| 337 | xdp.data = frame->data; |
| 338 | xdp.data_end = frame->data + frame->len; |
| 339 | xdp.data_meta = frame->data - frame->metasize; |
| 340 | xdp.rxq = &priv->xdp_rxq; |
| 341 | |
| 342 | act = bpf_prog_run_xdp(xdp_prog, &xdp); |
| 343 | |
| 344 | switch (act) { |
| 345 | case XDP_PASS: |
| 346 | delta = frame->data - xdp.data; |
| 347 | len = xdp.data_end - xdp.data; |
| 348 | break; |
| 349 | default: |
| 350 | bpf_warn_invalid_xdp_action(act); |
| 351 | case XDP_ABORTED: |
| 352 | trace_xdp_exception(priv->dev, xdp_prog, act); |
| 353 | case XDP_DROP: |
| 354 | goto err_xdp; |
| 355 | } |
| 356 | } |
| 357 | rcu_read_unlock(); |
| 358 | |
| 359 | headroom = sizeof(struct xdp_frame) + frame->headroom - delta; |
| 360 | skb = veth_build_skb(head, headroom, len, 0); |
| 361 | if (!skb) { |
| 362 | xdp_return_frame(frame); |
| 363 | goto err; |
| 364 | } |
| 365 | |
| 366 | xdp_scrub_frame(frame); |
| 367 | skb->protocol = eth_type_trans(skb, priv->dev); |
| 368 | err: |
| 369 | return skb; |
| 370 | err_xdp: |
| 371 | rcu_read_unlock(); |
| 372 | xdp_return_frame(frame); |
| 373 | |
| 374 | return NULL; |
| 375 | } |
| 376 | |
Toshiaki Makita | 948d4f2 | 2018-08-03 16:58:10 +0900 | [diff] [blame] | 377 | static struct sk_buff *veth_xdp_rcv_skb(struct veth_priv *priv, |
| 378 | struct sk_buff *skb) |
| 379 | { |
| 380 | u32 pktlen, headroom, act, metalen; |
| 381 | void *orig_data, *orig_data_end; |
| 382 | struct bpf_prog *xdp_prog; |
| 383 | int mac_len, delta, off; |
| 384 | struct xdp_buff xdp; |
| 385 | |
| 386 | rcu_read_lock(); |
| 387 | xdp_prog = rcu_dereference(priv->xdp_prog); |
| 388 | if (unlikely(!xdp_prog)) { |
| 389 | rcu_read_unlock(); |
| 390 | goto out; |
| 391 | } |
| 392 | |
| 393 | mac_len = skb->data - skb_mac_header(skb); |
| 394 | pktlen = skb->len + mac_len; |
| 395 | headroom = skb_headroom(skb) - mac_len; |
| 396 | |
| 397 | if (skb_shared(skb) || skb_head_is_locked(skb) || |
| 398 | skb_is_nonlinear(skb) || headroom < XDP_PACKET_HEADROOM) { |
| 399 | struct sk_buff *nskb; |
| 400 | int size, head_off; |
| 401 | void *head, *start; |
| 402 | struct page *page; |
| 403 | |
| 404 | size = SKB_DATA_ALIGN(VETH_XDP_HEADROOM + pktlen) + |
| 405 | SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); |
| 406 | if (size > PAGE_SIZE) |
| 407 | goto drop; |
| 408 | |
| 409 | page = alloc_page(GFP_ATOMIC | __GFP_NOWARN); |
| 410 | if (!page) |
| 411 | goto drop; |
| 412 | |
| 413 | head = page_address(page); |
| 414 | start = head + VETH_XDP_HEADROOM; |
| 415 | if (skb_copy_bits(skb, -mac_len, start, pktlen)) { |
| 416 | page_frag_free(head); |
| 417 | goto drop; |
| 418 | } |
| 419 | |
| 420 | nskb = veth_build_skb(head, |
| 421 | VETH_XDP_HEADROOM + mac_len, skb->len, |
| 422 | PAGE_SIZE); |
| 423 | if (!nskb) { |
| 424 | page_frag_free(head); |
| 425 | goto drop; |
| 426 | } |
| 427 | |
| 428 | skb_copy_header(nskb, skb); |
| 429 | head_off = skb_headroom(nskb) - skb_headroom(skb); |
| 430 | skb_headers_offset_update(nskb, head_off); |
| 431 | if (skb->sk) |
| 432 | skb_set_owner_w(nskb, skb->sk); |
| 433 | consume_skb(skb); |
| 434 | skb = nskb; |
| 435 | } |
| 436 | |
| 437 | xdp.data_hard_start = skb->head; |
| 438 | xdp.data = skb_mac_header(skb); |
| 439 | xdp.data_end = xdp.data + pktlen; |
| 440 | xdp.data_meta = xdp.data; |
| 441 | xdp.rxq = &priv->xdp_rxq; |
| 442 | orig_data = xdp.data; |
| 443 | orig_data_end = xdp.data_end; |
| 444 | |
| 445 | act = bpf_prog_run_xdp(xdp_prog, &xdp); |
| 446 | |
| 447 | switch (act) { |
| 448 | case XDP_PASS: |
| 449 | break; |
| 450 | default: |
| 451 | bpf_warn_invalid_xdp_action(act); |
| 452 | case XDP_ABORTED: |
| 453 | trace_xdp_exception(priv->dev, xdp_prog, act); |
| 454 | case XDP_DROP: |
| 455 | goto drop; |
| 456 | } |
| 457 | rcu_read_unlock(); |
| 458 | |
| 459 | delta = orig_data - xdp.data; |
| 460 | off = mac_len + delta; |
| 461 | if (off > 0) |
| 462 | __skb_push(skb, off); |
| 463 | else if (off < 0) |
| 464 | __skb_pull(skb, -off); |
| 465 | skb->mac_header -= delta; |
| 466 | off = xdp.data_end - orig_data_end; |
| 467 | if (off != 0) |
| 468 | __skb_put(skb, off); |
| 469 | skb->protocol = eth_type_trans(skb, priv->dev); |
| 470 | |
| 471 | metalen = xdp.data - xdp.data_meta; |
| 472 | if (metalen) |
| 473 | skb_metadata_set(skb, metalen); |
| 474 | out: |
| 475 | return skb; |
| 476 | drop: |
| 477 | rcu_read_unlock(); |
| 478 | kfree_skb(skb); |
| 479 | return NULL; |
| 480 | } |
| 481 | |
| 482 | static int veth_xdp_rcv(struct veth_priv *priv, int budget) |
| 483 | { |
| 484 | int i, done = 0; |
| 485 | |
| 486 | for (i = 0; i < budget; i++) { |
Toshiaki Makita | 9fc8d51 | 2018-08-03 16:58:13 +0900 | [diff] [blame] | 487 | void *ptr = __ptr_ring_consume(&priv->xdp_ring); |
| 488 | struct sk_buff *skb; |
Toshiaki Makita | 948d4f2 | 2018-08-03 16:58:10 +0900 | [diff] [blame] | 489 | |
Toshiaki Makita | 9fc8d51 | 2018-08-03 16:58:13 +0900 | [diff] [blame] | 490 | if (!ptr) |
Toshiaki Makita | 948d4f2 | 2018-08-03 16:58:10 +0900 | [diff] [blame] | 491 | break; |
| 492 | |
Toshiaki Makita | 9fc8d51 | 2018-08-03 16:58:13 +0900 | [diff] [blame] | 493 | if (veth_is_xdp_frame(ptr)) |
| 494 | skb = veth_xdp_rcv_one(priv, veth_ptr_to_xdp(ptr)); |
| 495 | else |
| 496 | skb = veth_xdp_rcv_skb(priv, ptr); |
Toshiaki Makita | 948d4f2 | 2018-08-03 16:58:10 +0900 | [diff] [blame] | 497 | |
| 498 | if (skb) |
| 499 | napi_gro_receive(&priv->xdp_napi, skb); |
| 500 | |
| 501 | done++; |
| 502 | } |
| 503 | |
| 504 | return done; |
| 505 | } |
| 506 | |
| 507 | static int veth_poll(struct napi_struct *napi, int budget) |
| 508 | { |
| 509 | struct veth_priv *priv = |
| 510 | container_of(napi, struct veth_priv, xdp_napi); |
| 511 | int done; |
| 512 | |
| 513 | done = veth_xdp_rcv(priv, budget); |
| 514 | |
| 515 | if (done < budget && napi_complete_done(napi, done)) { |
| 516 | /* Write rx_notify_masked before reading ptr_ring */ |
| 517 | smp_store_mb(priv->rx_notify_masked, false); |
| 518 | if (unlikely(!__ptr_ring_empty(&priv->xdp_ring))) { |
| 519 | priv->rx_notify_masked = true; |
| 520 | napi_schedule(&priv->xdp_napi); |
| 521 | } |
| 522 | } |
| 523 | |
| 524 | return done; |
| 525 | } |
| 526 | |
| 527 | static int veth_napi_add(struct net_device *dev) |
| 528 | { |
| 529 | struct veth_priv *priv = netdev_priv(dev); |
| 530 | int err; |
| 531 | |
| 532 | err = ptr_ring_init(&priv->xdp_ring, VETH_RING_SIZE, GFP_KERNEL); |
| 533 | if (err) |
| 534 | return err; |
| 535 | |
| 536 | netif_napi_add(dev, &priv->xdp_napi, veth_poll, NAPI_POLL_WEIGHT); |
| 537 | napi_enable(&priv->xdp_napi); |
| 538 | |
| 539 | return 0; |
| 540 | } |
| 541 | |
| 542 | static void veth_napi_del(struct net_device *dev) |
| 543 | { |
| 544 | struct veth_priv *priv = netdev_priv(dev); |
| 545 | |
| 546 | napi_disable(&priv->xdp_napi); |
| 547 | netif_napi_del(&priv->xdp_napi); |
| 548 | priv->rx_notify_masked = false; |
Toshiaki Makita | 9fc8d51 | 2018-08-03 16:58:13 +0900 | [diff] [blame] | 549 | ptr_ring_cleanup(&priv->xdp_ring, veth_ptr_free); |
Toshiaki Makita | 948d4f2 | 2018-08-03 16:58:10 +0900 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | static int veth_enable_xdp(struct net_device *dev) |
| 553 | { |
| 554 | struct veth_priv *priv = netdev_priv(dev); |
| 555 | int err; |
| 556 | |
| 557 | if (!xdp_rxq_info_is_reg(&priv->xdp_rxq)) { |
| 558 | err = xdp_rxq_info_reg(&priv->xdp_rxq, dev, 0); |
| 559 | if (err < 0) |
| 560 | return err; |
| 561 | |
| 562 | err = xdp_rxq_info_reg_mem_model(&priv->xdp_rxq, |
| 563 | MEM_TYPE_PAGE_SHARED, NULL); |
| 564 | if (err < 0) |
| 565 | goto err; |
| 566 | |
| 567 | err = veth_napi_add(dev); |
| 568 | if (err) |
| 569 | goto err; |
| 570 | } |
| 571 | |
| 572 | rcu_assign_pointer(priv->xdp_prog, priv->_xdp_prog); |
| 573 | |
| 574 | return 0; |
| 575 | err: |
| 576 | xdp_rxq_info_unreg(&priv->xdp_rxq); |
| 577 | |
| 578 | return err; |
| 579 | } |
| 580 | |
| 581 | static void veth_disable_xdp(struct net_device *dev) |
| 582 | { |
| 583 | struct veth_priv *priv = netdev_priv(dev); |
| 584 | |
| 585 | rcu_assign_pointer(priv->xdp_prog, NULL); |
| 586 | veth_napi_del(dev); |
| 587 | xdp_rxq_info_unreg(&priv->xdp_rxq); |
| 588 | } |
| 589 | |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 590 | static int veth_open(struct net_device *dev) |
| 591 | { |
Eric Dumazet | d0e2c55 | 2013-01-04 15:42:40 +0000 | [diff] [blame] | 592 | struct veth_priv *priv = netdev_priv(dev); |
| 593 | struct net_device *peer = rtnl_dereference(priv->peer); |
Toshiaki Makita | 948d4f2 | 2018-08-03 16:58:10 +0900 | [diff] [blame] | 594 | int err; |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 595 | |
Eric Dumazet | d0e2c55 | 2013-01-04 15:42:40 +0000 | [diff] [blame] | 596 | if (!peer) |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 597 | return -ENOTCONN; |
| 598 | |
Toshiaki Makita | 948d4f2 | 2018-08-03 16:58:10 +0900 | [diff] [blame] | 599 | if (priv->_xdp_prog) { |
| 600 | err = veth_enable_xdp(dev); |
| 601 | if (err) |
| 602 | return err; |
| 603 | } |
| 604 | |
Eric Dumazet | d0e2c55 | 2013-01-04 15:42:40 +0000 | [diff] [blame] | 605 | if (peer->flags & IFF_UP) { |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 606 | netif_carrier_on(dev); |
Eric Dumazet | d0e2c55 | 2013-01-04 15:42:40 +0000 | [diff] [blame] | 607 | netif_carrier_on(peer); |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 608 | } |
Toshiaki Makita | 948d4f2 | 2018-08-03 16:58:10 +0900 | [diff] [blame] | 609 | |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 610 | return 0; |
| 611 | } |
| 612 | |
Eric W. Biederman | 2cf48a1 | 2009-02-25 19:47:29 +0000 | [diff] [blame] | 613 | static int veth_close(struct net_device *dev) |
| 614 | { |
| 615 | struct veth_priv *priv = netdev_priv(dev); |
Eric Dumazet | 2efd32e | 2013-01-10 08:32:45 +0000 | [diff] [blame] | 616 | struct net_device *peer = rtnl_dereference(priv->peer); |
Eric W. Biederman | 2cf48a1 | 2009-02-25 19:47:29 +0000 | [diff] [blame] | 617 | |
| 618 | netif_carrier_off(dev); |
Eric Dumazet | 2efd32e | 2013-01-10 08:32:45 +0000 | [diff] [blame] | 619 | if (peer) |
| 620 | netif_carrier_off(peer); |
Eric W. Biederman | 2cf48a1 | 2009-02-25 19:47:29 +0000 | [diff] [blame] | 621 | |
Toshiaki Makita | 948d4f2 | 2018-08-03 16:58:10 +0900 | [diff] [blame] | 622 | if (priv->_xdp_prog) |
| 623 | veth_disable_xdp(dev); |
| 624 | |
Eric W. Biederman | 2cf48a1 | 2009-02-25 19:47:29 +0000 | [diff] [blame] | 625 | return 0; |
| 626 | } |
| 627 | |
Jarod Wilson | 9157208 | 2016-10-20 13:55:20 -0400 | [diff] [blame] | 628 | static int is_valid_veth_mtu(int mtu) |
Eric Biederman | 38d4081 | 2009-03-03 23:36:04 -0800 | [diff] [blame] | 629 | { |
Jarod Wilson | 9157208 | 2016-10-20 13:55:20 -0400 | [diff] [blame] | 630 | return mtu >= ETH_MIN_MTU && mtu <= ETH_MAX_MTU; |
Eric Biederman | 38d4081 | 2009-03-03 23:36:04 -0800 | [diff] [blame] | 631 | } |
| 632 | |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 633 | static int veth_dev_init(struct net_device *dev) |
| 634 | { |
WANG Cong | 1c213bd | 2014-02-13 11:46:28 -0800 | [diff] [blame] | 635 | dev->vstats = netdev_alloc_pcpu_stats(struct pcpu_vstats); |
Eric Dumazet | 2681128 | 2012-12-29 16:02:43 +0000 | [diff] [blame] | 636 | if (!dev->vstats) |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 637 | return -ENOMEM; |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 638 | return 0; |
| 639 | } |
| 640 | |
David S. Miller | 11687a1 | 2009-06-25 02:45:42 -0700 | [diff] [blame] | 641 | static void veth_dev_free(struct net_device *dev) |
| 642 | { |
Eric Dumazet | 2681128 | 2012-12-29 16:02:43 +0000 | [diff] [blame] | 643 | free_percpu(dev->vstats); |
David S. Miller | 11687a1 | 2009-06-25 02:45:42 -0700 | [diff] [blame] | 644 | } |
| 645 | |
WANG Cong | bb446c1 | 2014-06-23 15:36:02 -0700 | [diff] [blame] | 646 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 647 | static void veth_poll_controller(struct net_device *dev) |
| 648 | { |
| 649 | /* veth only receives frames when its peer sends one |
Toshiaki Makita | 948d4f2 | 2018-08-03 16:58:10 +0900 | [diff] [blame] | 650 | * Since it has nothing to do with disabling irqs, we are guaranteed |
WANG Cong | bb446c1 | 2014-06-23 15:36:02 -0700 | [diff] [blame] | 651 | * never to have pending data when we poll for it so |
| 652 | * there is nothing to do here. |
| 653 | * |
| 654 | * We need this though so netpoll recognizes us as an interface that |
| 655 | * supports polling, which enables bridge devices in virt setups to |
| 656 | * still use netconsole |
| 657 | */ |
| 658 | } |
| 659 | #endif /* CONFIG_NET_POLL_CONTROLLER */ |
| 660 | |
Nicolas Dichtel | a45253b | 2015-04-02 17:07:11 +0200 | [diff] [blame] | 661 | static int veth_get_iflink(const struct net_device *dev) |
| 662 | { |
| 663 | struct veth_priv *priv = netdev_priv(dev); |
| 664 | struct net_device *peer; |
| 665 | int iflink; |
| 666 | |
| 667 | rcu_read_lock(); |
| 668 | peer = rcu_dereference(priv->peer); |
| 669 | iflink = peer ? peer->ifindex : 0; |
| 670 | rcu_read_unlock(); |
| 671 | |
| 672 | return iflink; |
| 673 | } |
| 674 | |
Toshiaki Makita | dc22482 | 2018-08-03 16:58:11 +0900 | [diff] [blame] | 675 | static netdev_features_t veth_fix_features(struct net_device *dev, |
| 676 | netdev_features_t features) |
| 677 | { |
| 678 | struct veth_priv *priv = netdev_priv(dev); |
| 679 | struct net_device *peer; |
| 680 | |
| 681 | peer = rtnl_dereference(priv->peer); |
| 682 | if (peer) { |
| 683 | struct veth_priv *peer_priv = netdev_priv(peer); |
| 684 | |
| 685 | if (peer_priv->_xdp_prog) |
| 686 | features &= ~NETIF_F_GSO_SOFTWARE; |
| 687 | } |
| 688 | |
| 689 | return features; |
| 690 | } |
| 691 | |
Paolo Abeni | 163e529 | 2016-02-26 10:45:41 +0100 | [diff] [blame] | 692 | static void veth_set_rx_headroom(struct net_device *dev, int new_hr) |
| 693 | { |
| 694 | struct veth_priv *peer_priv, *priv = netdev_priv(dev); |
| 695 | struct net_device *peer; |
| 696 | |
| 697 | if (new_hr < 0) |
| 698 | new_hr = 0; |
| 699 | |
| 700 | rcu_read_lock(); |
| 701 | peer = rcu_dereference(priv->peer); |
| 702 | if (unlikely(!peer)) |
| 703 | goto out; |
| 704 | |
| 705 | peer_priv = netdev_priv(peer); |
| 706 | priv->requested_headroom = new_hr; |
| 707 | new_hr = max(priv->requested_headroom, peer_priv->requested_headroom); |
| 708 | dev->needed_headroom = new_hr; |
| 709 | peer->needed_headroom = new_hr; |
| 710 | |
| 711 | out: |
| 712 | rcu_read_unlock(); |
| 713 | } |
| 714 | |
Toshiaki Makita | 948d4f2 | 2018-08-03 16:58:10 +0900 | [diff] [blame] | 715 | static int veth_xdp_set(struct net_device *dev, struct bpf_prog *prog, |
| 716 | struct netlink_ext_ack *extack) |
| 717 | { |
| 718 | struct veth_priv *priv = netdev_priv(dev); |
| 719 | struct bpf_prog *old_prog; |
| 720 | struct net_device *peer; |
Toshiaki Makita | dc22482 | 2018-08-03 16:58:11 +0900 | [diff] [blame] | 721 | unsigned int max_mtu; |
Toshiaki Makita | 948d4f2 | 2018-08-03 16:58:10 +0900 | [diff] [blame] | 722 | int err; |
| 723 | |
| 724 | old_prog = priv->_xdp_prog; |
| 725 | priv->_xdp_prog = prog; |
| 726 | peer = rtnl_dereference(priv->peer); |
| 727 | |
| 728 | if (prog) { |
| 729 | if (!peer) { |
| 730 | NL_SET_ERR_MSG_MOD(extack, "Cannot set XDP when peer is detached"); |
| 731 | err = -ENOTCONN; |
| 732 | goto err; |
| 733 | } |
| 734 | |
Toshiaki Makita | dc22482 | 2018-08-03 16:58:11 +0900 | [diff] [blame] | 735 | max_mtu = PAGE_SIZE - VETH_XDP_HEADROOM - |
| 736 | peer->hard_header_len - |
| 737 | SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); |
| 738 | if (peer->mtu > max_mtu) { |
| 739 | NL_SET_ERR_MSG_MOD(extack, "Peer MTU is too large to set XDP"); |
| 740 | err = -ERANGE; |
| 741 | goto err; |
| 742 | } |
| 743 | |
Toshiaki Makita | 948d4f2 | 2018-08-03 16:58:10 +0900 | [diff] [blame] | 744 | if (dev->flags & IFF_UP) { |
| 745 | err = veth_enable_xdp(dev); |
| 746 | if (err) { |
| 747 | NL_SET_ERR_MSG_MOD(extack, "Setup for XDP failed"); |
| 748 | goto err; |
| 749 | } |
| 750 | } |
Toshiaki Makita | dc22482 | 2018-08-03 16:58:11 +0900 | [diff] [blame] | 751 | |
| 752 | if (!old_prog) { |
| 753 | peer->hw_features &= ~NETIF_F_GSO_SOFTWARE; |
| 754 | peer->max_mtu = max_mtu; |
| 755 | } |
Toshiaki Makita | 948d4f2 | 2018-08-03 16:58:10 +0900 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | if (old_prog) { |
Toshiaki Makita | dc22482 | 2018-08-03 16:58:11 +0900 | [diff] [blame] | 759 | if (!prog) { |
| 760 | if (dev->flags & IFF_UP) |
| 761 | veth_disable_xdp(dev); |
| 762 | |
| 763 | if (peer) { |
| 764 | peer->hw_features |= NETIF_F_GSO_SOFTWARE; |
| 765 | peer->max_mtu = ETH_MAX_MTU; |
| 766 | } |
| 767 | } |
Toshiaki Makita | 948d4f2 | 2018-08-03 16:58:10 +0900 | [diff] [blame] | 768 | bpf_prog_put(old_prog); |
| 769 | } |
| 770 | |
Toshiaki Makita | dc22482 | 2018-08-03 16:58:11 +0900 | [diff] [blame] | 771 | if ((!!old_prog ^ !!prog) && peer) |
| 772 | netdev_update_features(peer); |
| 773 | |
Toshiaki Makita | 948d4f2 | 2018-08-03 16:58:10 +0900 | [diff] [blame] | 774 | return 0; |
| 775 | err: |
| 776 | priv->_xdp_prog = old_prog; |
| 777 | |
| 778 | return err; |
| 779 | } |
| 780 | |
| 781 | static u32 veth_xdp_query(struct net_device *dev) |
| 782 | { |
| 783 | struct veth_priv *priv = netdev_priv(dev); |
| 784 | const struct bpf_prog *xdp_prog; |
| 785 | |
| 786 | xdp_prog = priv->_xdp_prog; |
| 787 | if (xdp_prog) |
| 788 | return xdp_prog->aux->id; |
| 789 | |
| 790 | return 0; |
| 791 | } |
| 792 | |
| 793 | static int veth_xdp(struct net_device *dev, struct netdev_bpf *xdp) |
| 794 | { |
| 795 | switch (xdp->command) { |
| 796 | case XDP_SETUP_PROG: |
| 797 | return veth_xdp_set(dev, xdp->prog, xdp->extack); |
| 798 | case XDP_QUERY_PROG: |
| 799 | xdp->prog_id = veth_xdp_query(dev); |
| 800 | return 0; |
| 801 | default: |
| 802 | return -EINVAL; |
| 803 | } |
| 804 | } |
| 805 | |
Stephen Hemminger | 4456e7b | 2008-11-19 21:50:10 -0800 | [diff] [blame] | 806 | static const struct net_device_ops veth_netdev_ops = { |
Daniel Lezcano | ee92362 | 2009-02-22 00:04:45 -0800 | [diff] [blame] | 807 | .ndo_init = veth_dev_init, |
| 808 | .ndo_open = veth_open, |
Eric W. Biederman | 2cf48a1 | 2009-02-25 19:47:29 +0000 | [diff] [blame] | 809 | .ndo_stop = veth_close, |
Daniel Lezcano | ee92362 | 2009-02-22 00:04:45 -0800 | [diff] [blame] | 810 | .ndo_start_xmit = veth_xmit, |
stephen hemminger | 6311cc4 | 2011-06-08 14:53:59 +0000 | [diff] [blame] | 811 | .ndo_get_stats64 = veth_get_stats64, |
Gao feng | 5c70ef8 | 2013-10-04 16:52:24 +0800 | [diff] [blame] | 812 | .ndo_set_rx_mode = veth_set_multicast_list, |
Daniel Lezcano | ee92362 | 2009-02-22 00:04:45 -0800 | [diff] [blame] | 813 | .ndo_set_mac_address = eth_mac_addr, |
WANG Cong | bb446c1 | 2014-06-23 15:36:02 -0700 | [diff] [blame] | 814 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 815 | .ndo_poll_controller = veth_poll_controller, |
| 816 | #endif |
Nicolas Dichtel | a45253b | 2015-04-02 17:07:11 +0200 | [diff] [blame] | 817 | .ndo_get_iflink = veth_get_iflink, |
Toshiaki Makita | dc22482 | 2018-08-03 16:58:11 +0900 | [diff] [blame] | 818 | .ndo_fix_features = veth_fix_features, |
Toshiaki Makita | 1a04a82 | 2015-07-31 15:03:25 +0900 | [diff] [blame] | 819 | .ndo_features_check = passthru_features_check, |
Paolo Abeni | 163e529 | 2016-02-26 10:45:41 +0100 | [diff] [blame] | 820 | .ndo_set_rx_headroom = veth_set_rx_headroom, |
Toshiaki Makita | 948d4f2 | 2018-08-03 16:58:10 +0900 | [diff] [blame] | 821 | .ndo_bpf = veth_xdp, |
Toshiaki Makita | af87a3a | 2018-08-03 16:58:14 +0900 | [diff] [blame^] | 822 | .ndo_xdp_xmit = veth_xdp_xmit, |
Stephen Hemminger | 4456e7b | 2008-11-19 21:50:10 -0800 | [diff] [blame] | 823 | }; |
| 824 | |
Alexander Duyck | 732912d7 | 2016-04-19 14:02:26 -0400 | [diff] [blame] | 825 | #define VETH_FEATURES (NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_HW_CSUM | \ |
Xin Long | c80fafb | 2016-08-25 13:21:49 +0800 | [diff] [blame] | 826 | NETIF_F_RXCSUM | NETIF_F_SCTP_CRC | NETIF_F_HIGHDMA | \ |
Alexander Duyck | 732912d7 | 2016-04-19 14:02:26 -0400 | [diff] [blame] | 827 | NETIF_F_GSO_SOFTWARE | NETIF_F_GSO_ENCAP_ALL | \ |
Patrick McHardy | 28d2b13 | 2013-04-19 02:04:32 +0000 | [diff] [blame] | 828 | NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX | \ |
| 829 | NETIF_F_HW_VLAN_STAG_TX | NETIF_F_HW_VLAN_STAG_RX ) |
Eric Dumazet | 8093315 | 2012-12-29 16:26:10 +0000 | [diff] [blame] | 830 | |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 831 | static void veth_setup(struct net_device *dev) |
| 832 | { |
| 833 | ether_setup(dev); |
| 834 | |
Neil Horman | 550fd08 | 2011-07-26 06:05:38 +0000 | [diff] [blame] | 835 | dev->priv_flags &= ~IFF_TX_SKB_SHARING; |
Hannes Frederic Sowa | 23ea5a9 | 2012-10-30 16:22:01 +0000 | [diff] [blame] | 836 | dev->priv_flags |= IFF_LIVE_ADDR_CHANGE; |
Phil Sutter | 02f01ec | 2015-08-18 10:30:29 +0200 | [diff] [blame] | 837 | dev->priv_flags |= IFF_NO_QUEUE; |
Paolo Abeni | 163e529 | 2016-02-26 10:45:41 +0100 | [diff] [blame] | 838 | dev->priv_flags |= IFF_PHONY_HEADROOM; |
Neil Horman | 550fd08 | 2011-07-26 06:05:38 +0000 | [diff] [blame] | 839 | |
Stephen Hemminger | 4456e7b | 2008-11-19 21:50:10 -0800 | [diff] [blame] | 840 | dev->netdev_ops = &veth_netdev_ops; |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 841 | dev->ethtool_ops = &veth_ethtool_ops; |
| 842 | dev->features |= NETIF_F_LLTX; |
Eric Dumazet | 8093315 | 2012-12-29 16:26:10 +0000 | [diff] [blame] | 843 | dev->features |= VETH_FEATURES; |
Toshiaki Makita | 8d0d21f | 2014-02-18 21:20:08 +0900 | [diff] [blame] | 844 | dev->vlan_features = dev->features & |
Vlad Yasevich | 3f8c707 | 2014-03-27 22:14:48 -0400 | [diff] [blame] | 845 | ~(NETIF_F_HW_VLAN_CTAG_TX | |
| 846 | NETIF_F_HW_VLAN_STAG_TX | |
| 847 | NETIF_F_HW_VLAN_CTAG_RX | |
| 848 | NETIF_F_HW_VLAN_STAG_RX); |
David S. Miller | cf124db | 2017-05-08 12:52:56 -0400 | [diff] [blame] | 849 | dev->needs_free_netdev = true; |
| 850 | dev->priv_destructor = veth_dev_free; |
Jarod Wilson | 9157208 | 2016-10-20 13:55:20 -0400 | [diff] [blame] | 851 | dev->max_mtu = ETH_MAX_MTU; |
Michał Mirosław | a2c725f | 2011-03-31 01:01:35 +0000 | [diff] [blame] | 852 | |
Eric Dumazet | 8093315 | 2012-12-29 16:26:10 +0000 | [diff] [blame] | 853 | dev->hw_features = VETH_FEATURES; |
Eric Dumazet | 82d8189 | 2013-10-25 18:25:03 -0700 | [diff] [blame] | 854 | dev->hw_enc_features = VETH_FEATURES; |
David Ahern | 607fca9 | 2016-08-24 20:10:45 -0700 | [diff] [blame] | 855 | dev->mpls_features = NETIF_F_HW_CSUM | NETIF_F_GSO_SOFTWARE; |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 856 | } |
| 857 | |
| 858 | /* |
| 859 | * netlink interface |
| 860 | */ |
| 861 | |
Matthias Schiffer | a8b8a889 | 2017-06-25 23:56:01 +0200 | [diff] [blame] | 862 | static int veth_validate(struct nlattr *tb[], struct nlattr *data[], |
| 863 | struct netlink_ext_ack *extack) |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 864 | { |
| 865 | if (tb[IFLA_ADDRESS]) { |
| 866 | if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN) |
| 867 | return -EINVAL; |
| 868 | if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS]))) |
| 869 | return -EADDRNOTAVAIL; |
| 870 | } |
Eric Biederman | 38d4081 | 2009-03-03 23:36:04 -0800 | [diff] [blame] | 871 | if (tb[IFLA_MTU]) { |
| 872 | if (!is_valid_veth_mtu(nla_get_u32(tb[IFLA_MTU]))) |
| 873 | return -EINVAL; |
| 874 | } |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 875 | return 0; |
| 876 | } |
| 877 | |
| 878 | static struct rtnl_link_ops veth_link_ops; |
| 879 | |
Eric W. Biederman | 81adee4 | 2009-11-08 00:53:51 -0800 | [diff] [blame] | 880 | static int veth_newlink(struct net *src_net, struct net_device *dev, |
Matthias Schiffer | 7a3f4a1 | 2017-06-25 23:55:59 +0200 | [diff] [blame] | 881 | struct nlattr *tb[], struct nlattr *data[], |
| 882 | struct netlink_ext_ack *extack) |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 883 | { |
| 884 | int err; |
| 885 | struct net_device *peer; |
| 886 | struct veth_priv *priv; |
| 887 | char ifname[IFNAMSIZ]; |
| 888 | struct nlattr *peer_tb[IFLA_MAX + 1], **tbp; |
Tom Gundersen | 5517750 | 2014-07-14 16:37:25 +0200 | [diff] [blame] | 889 | unsigned char name_assign_type; |
Patrick McHardy | 3729d50 | 2010-02-26 06:34:54 +0000 | [diff] [blame] | 890 | struct ifinfomsg *ifmp; |
Eric W. Biederman | 81adee4 | 2009-11-08 00:53:51 -0800 | [diff] [blame] | 891 | struct net *net; |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 892 | |
| 893 | /* |
| 894 | * create and register peer first |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 895 | */ |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 896 | if (data != NULL && data[VETH_INFO_PEER] != NULL) { |
| 897 | struct nlattr *nla_peer; |
| 898 | |
| 899 | nla_peer = data[VETH_INFO_PEER]; |
Patrick McHardy | 3729d50 | 2010-02-26 06:34:54 +0000 | [diff] [blame] | 900 | ifmp = nla_data(nla_peer); |
Jiri Pirko | f7b1260 | 2014-02-18 20:53:18 +0100 | [diff] [blame] | 901 | err = rtnl_nla_parse_ifla(peer_tb, |
| 902 | nla_data(nla_peer) + sizeof(struct ifinfomsg), |
Johannes Berg | fceb643 | 2017-04-12 14:34:07 +0200 | [diff] [blame] | 903 | nla_len(nla_peer) - sizeof(struct ifinfomsg), |
| 904 | NULL); |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 905 | if (err < 0) |
| 906 | return err; |
| 907 | |
Matthias Schiffer | a8b8a889 | 2017-06-25 23:56:01 +0200 | [diff] [blame] | 908 | err = veth_validate(peer_tb, NULL, extack); |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 909 | if (err < 0) |
| 910 | return err; |
| 911 | |
| 912 | tbp = peer_tb; |
Patrick McHardy | 3729d50 | 2010-02-26 06:34:54 +0000 | [diff] [blame] | 913 | } else { |
| 914 | ifmp = NULL; |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 915 | tbp = tb; |
Patrick McHardy | 3729d50 | 2010-02-26 06:34:54 +0000 | [diff] [blame] | 916 | } |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 917 | |
Serhey Popovych | 191cdb3 | 2017-06-21 12:12:24 +0300 | [diff] [blame] | 918 | if (ifmp && tbp[IFLA_IFNAME]) { |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 919 | nla_strlcpy(ifname, tbp[IFLA_IFNAME], IFNAMSIZ); |
Tom Gundersen | 5517750 | 2014-07-14 16:37:25 +0200 | [diff] [blame] | 920 | name_assign_type = NET_NAME_USER; |
| 921 | } else { |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 922 | snprintf(ifname, IFNAMSIZ, DRV_NAME "%%d"); |
Tom Gundersen | 5517750 | 2014-07-14 16:37:25 +0200 | [diff] [blame] | 923 | name_assign_type = NET_NAME_ENUM; |
| 924 | } |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 925 | |
Eric W. Biederman | 81adee4 | 2009-11-08 00:53:51 -0800 | [diff] [blame] | 926 | net = rtnl_link_get_net(src_net, tbp); |
| 927 | if (IS_ERR(net)) |
| 928 | return PTR_ERR(net); |
| 929 | |
Tom Gundersen | 5517750 | 2014-07-14 16:37:25 +0200 | [diff] [blame] | 930 | peer = rtnl_create_link(net, ifname, name_assign_type, |
| 931 | &veth_link_ops, tbp); |
Eric W. Biederman | 81adee4 | 2009-11-08 00:53:51 -0800 | [diff] [blame] | 932 | if (IS_ERR(peer)) { |
| 933 | put_net(net); |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 934 | return PTR_ERR(peer); |
Eric W. Biederman | 81adee4 | 2009-11-08 00:53:51 -0800 | [diff] [blame] | 935 | } |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 936 | |
Serhey Popovych | 191cdb3 | 2017-06-21 12:12:24 +0300 | [diff] [blame] | 937 | if (!ifmp || !tbp[IFLA_ADDRESS]) |
Danny Kukawka | f2cedb6 | 2012-02-15 06:45:39 +0000 | [diff] [blame] | 938 | eth_hw_addr_random(peer); |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 939 | |
Pavel Emelyanov | e6f8f1a | 2012-08-08 21:53:03 +0000 | [diff] [blame] | 940 | if (ifmp && (dev->ifindex != 0)) |
| 941 | peer->ifindex = ifmp->ifi_index; |
| 942 | |
Stephen Hemminger | 72d24955 | 2017-12-07 15:40:20 -0800 | [diff] [blame] | 943 | peer->gso_max_size = dev->gso_max_size; |
| 944 | peer->gso_max_segs = dev->gso_max_segs; |
| 945 | |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 946 | err = register_netdevice(peer); |
Eric W. Biederman | 81adee4 | 2009-11-08 00:53:51 -0800 | [diff] [blame] | 947 | put_net(net); |
| 948 | net = NULL; |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 949 | if (err < 0) |
| 950 | goto err_register_peer; |
| 951 | |
| 952 | netif_carrier_off(peer); |
| 953 | |
Patrick McHardy | 3729d50 | 2010-02-26 06:34:54 +0000 | [diff] [blame] | 954 | err = rtnl_configure_link(peer, ifmp); |
| 955 | if (err < 0) |
| 956 | goto err_configure_peer; |
| 957 | |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 958 | /* |
| 959 | * register dev last |
| 960 | * |
| 961 | * note, that since we've registered new device the dev's name |
| 962 | * should be re-allocated |
| 963 | */ |
| 964 | |
| 965 | if (tb[IFLA_ADDRESS] == NULL) |
Danny Kukawka | f2cedb6 | 2012-02-15 06:45:39 +0000 | [diff] [blame] | 966 | eth_hw_addr_random(dev); |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 967 | |
Jiri Pirko | 6c8c444 | 2011-04-30 01:28:17 +0000 | [diff] [blame] | 968 | if (tb[IFLA_IFNAME]) |
| 969 | nla_strlcpy(dev->name, tb[IFLA_IFNAME], IFNAMSIZ); |
| 970 | else |
| 971 | snprintf(dev->name, IFNAMSIZ, DRV_NAME "%%d"); |
| 972 | |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 973 | err = register_netdevice(dev); |
| 974 | if (err < 0) |
| 975 | goto err_register_dev; |
| 976 | |
| 977 | netif_carrier_off(dev); |
| 978 | |
| 979 | /* |
| 980 | * tie the deviced together |
| 981 | */ |
| 982 | |
| 983 | priv = netdev_priv(dev); |
Toshiaki Makita | 948d4f2 | 2018-08-03 16:58:10 +0900 | [diff] [blame] | 984 | priv->dev = dev; |
Eric Dumazet | d0e2c55 | 2013-01-04 15:42:40 +0000 | [diff] [blame] | 985 | rcu_assign_pointer(priv->peer, peer); |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 986 | |
| 987 | priv = netdev_priv(peer); |
Toshiaki Makita | 948d4f2 | 2018-08-03 16:58:10 +0900 | [diff] [blame] | 988 | priv->dev = peer; |
Eric Dumazet | d0e2c55 | 2013-01-04 15:42:40 +0000 | [diff] [blame] | 989 | rcu_assign_pointer(priv->peer, dev); |
Toshiaki Makita | 948d4f2 | 2018-08-03 16:58:10 +0900 | [diff] [blame] | 990 | |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 991 | return 0; |
| 992 | |
| 993 | err_register_dev: |
| 994 | /* nothing to do */ |
Patrick McHardy | 3729d50 | 2010-02-26 06:34:54 +0000 | [diff] [blame] | 995 | err_configure_peer: |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 996 | unregister_netdevice(peer); |
| 997 | return err; |
| 998 | |
| 999 | err_register_peer: |
| 1000 | free_netdev(peer); |
| 1001 | return err; |
| 1002 | } |
| 1003 | |
Eric Dumazet | 23289a3 | 2009-10-27 07:06:36 +0000 | [diff] [blame] | 1004 | static void veth_dellink(struct net_device *dev, struct list_head *head) |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 1005 | { |
| 1006 | struct veth_priv *priv; |
| 1007 | struct net_device *peer; |
| 1008 | |
| 1009 | priv = netdev_priv(dev); |
Eric Dumazet | d0e2c55 | 2013-01-04 15:42:40 +0000 | [diff] [blame] | 1010 | peer = rtnl_dereference(priv->peer); |
| 1011 | |
| 1012 | /* Note : dellink() is called from default_device_exit_batch(), |
| 1013 | * before a rcu_synchronize() point. The devices are guaranteed |
| 1014 | * not being freed before one RCU grace period. |
| 1015 | */ |
| 1016 | RCU_INIT_POINTER(priv->peer, NULL); |
Eric Dumazet | 2454053 | 2009-10-30 01:00:27 -0700 | [diff] [blame] | 1017 | unregister_netdevice_queue(dev, head); |
Eric Dumazet | f45a5c2 | 2013-02-08 20:10:49 +0000 | [diff] [blame] | 1018 | |
| 1019 | if (peer) { |
| 1020 | priv = netdev_priv(peer); |
| 1021 | RCU_INIT_POINTER(priv->peer, NULL); |
| 1022 | unregister_netdevice_queue(peer, head); |
| 1023 | } |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 1024 | } |
| 1025 | |
Thomas Graf | 2371143 | 2012-02-15 04:09:46 +0000 | [diff] [blame] | 1026 | static const struct nla_policy veth_policy[VETH_INFO_MAX + 1] = { |
| 1027 | [VETH_INFO_PEER] = { .len = sizeof(struct ifinfomsg) }, |
| 1028 | }; |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 1029 | |
Nicolas Dichtel | e5f4e7b | 2015-01-20 15:15:46 +0100 | [diff] [blame] | 1030 | static struct net *veth_get_link_net(const struct net_device *dev) |
| 1031 | { |
| 1032 | struct veth_priv *priv = netdev_priv(dev); |
| 1033 | struct net_device *peer = rtnl_dereference(priv->peer); |
| 1034 | |
| 1035 | return peer ? dev_net(peer) : dev_net(dev); |
| 1036 | } |
| 1037 | |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 1038 | static struct rtnl_link_ops veth_link_ops = { |
| 1039 | .kind = DRV_NAME, |
| 1040 | .priv_size = sizeof(struct veth_priv), |
| 1041 | .setup = veth_setup, |
| 1042 | .validate = veth_validate, |
| 1043 | .newlink = veth_newlink, |
| 1044 | .dellink = veth_dellink, |
| 1045 | .policy = veth_policy, |
| 1046 | .maxtype = VETH_INFO_MAX, |
Nicolas Dichtel | e5f4e7b | 2015-01-20 15:15:46 +0100 | [diff] [blame] | 1047 | .get_link_net = veth_get_link_net, |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 1048 | }; |
| 1049 | |
| 1050 | /* |
| 1051 | * init/fini |
| 1052 | */ |
| 1053 | |
| 1054 | static __init int veth_init(void) |
| 1055 | { |
| 1056 | return rtnl_link_register(&veth_link_ops); |
| 1057 | } |
| 1058 | |
| 1059 | static __exit void veth_exit(void) |
| 1060 | { |
Patrick McHardy | 6836545 | 2008-01-20 17:25:14 -0800 | [diff] [blame] | 1061 | rtnl_link_unregister(&veth_link_ops); |
Pavel Emelyanov | e314dbd | 2007-09-25 16:14:46 -0700 | [diff] [blame] | 1062 | } |
| 1063 | |
| 1064 | module_init(veth_init); |
| 1065 | module_exit(veth_exit); |
| 1066 | |
| 1067 | MODULE_DESCRIPTION("Virtual Ethernet Tunnel"); |
| 1068 | MODULE_LICENSE("GPL v2"); |
| 1069 | MODULE_ALIAS_RTNL_LINK(DRV_NAME); |