Merge tag 'pci-v6.16-fixes-3' of git://git.kernel.org/pub/scm/linux/kernel/git/pci/pci
[linux-block.git] / net / 8021q / vlan_dev.c
CommitLineData
2874c5fd 1// SPDX-License-Identifier: GPL-2.0-or-later
1da177e4
LT
2/* -*- linux-c -*-
3 * INET 802.1Q VLAN
4 * Ethernet-type device handling.
5 *
6 * Authors: Ben Greear <greearb@candelatech.com>
ad712087 7 * Please send support related email to: netdev@vger.kernel.org
1da177e4 8 * VLAN Home Page: http://www.candelatech.com/~greear/vlan.html
122952fc 9 *
1da177e4
LT
10 * Fixes: Mar 22 2001: Martin Bokaemper <mbokaemper@unispherenetworks.com>
11 * - reset skb->pkt_type on incoming packets when MAC was changed
12 * - see that changed MAC is saddr for outgoing packets
13 * Oct 20, 2001: Ard van Breeman:
14 * - Fix MC-list, finally.
15 * - Flush MC-list on VLAN destroy.
1da177e4
LT
16 */
17
afab2d29
JP
18#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
19
1da177e4 20#include <linux/module.h>
5a0e3ad6 21#include <linux/slab.h>
1da177e4
LT
22#include <linux/skbuff.h>
23#include <linux/netdevice.h>
37dd9255 24#include <linux/net_tstamp.h>
1da177e4 25#include <linux/etherdevice.h>
75b8846a 26#include <linux/ethtool.h>
ec1d8ccb 27#include <linux/phy.h>
1da177e4 28#include <net/arp.h>
abff3e5e 29#include <net/macsec.h>
8ef890df 30#include <net/netdev_lock.h>
1da177e4
LT
31
32#include "vlan.h"
33#include "vlanproc.h"
34#include <linux/if_vlan.h>
6d4cdf47 35#include <linux/netpoll.h>
1da177e4 36
1da177e4 37/*
122952fc 38 * Create the VLAN header for an arbitrary protocol layer
1da177e4
LT
39 *
40 * saddr=NULL means use device source address
41 * daddr=NULL means leave destination address (eg unresolved arp)
42 *
43 * This is called when the SKB is moving down the stack towards the
44 * physical devices.
45 */
ef3eb3e5
PM
46static int vlan_dev_hard_header(struct sk_buff *skb, struct net_device *dev,
47 unsigned short type,
48 const void *daddr, const void *saddr,
49 unsigned int len)
1da177e4 50{
1fd9b1fc 51 struct vlan_dev_priv *vlan = vlan_dev_priv(dev);
1da177e4 52 struct vlan_hdr *vhdr;
1349fe9a 53 unsigned int vhdrlen = 0;
9bb8582e 54 u16 vlan_tci = 0;
1349fe9a 55 int rc;
1da177e4 56
0c0667a8 57 if (!(vlan->flags & VLAN_FLAG_REORDER_HDR)) {
d58ff351 58 vhdr = skb_push(skb, VLAN_HLEN);
1da177e4 59
0c0667a8 60 vlan_tci = vlan->vlan_id;
e267cb96 61 vlan_tci |= vlan_dev_get_egress_qos_mask(dev, skb->priority);
9bb8582e 62 vhdr->h_vlan_TCI = htons(vlan_tci);
1da177e4
LT
63
64 /*
bf9ae538
OP
65 * Set the protocol type. For a packet of type ETH_P_802_3/2 we
66 * put the length in here instead.
1da177e4 67 */
bf9ae538 68 if (type != ETH_P_802_3 && type != ETH_P_802_2)
1da177e4 69 vhdr->h_vlan_encapsulated_proto = htons(type);
2029cc2c 70 else
1da177e4 71 vhdr->h_vlan_encapsulated_proto = htons(len);
279e172a 72
1fd9b1fc
PM
73 skb->protocol = vlan->vlan_proto;
74 type = ntohs(vlan->vlan_proto);
1349fe9a 75 vhdrlen = VLAN_HLEN;
1da177e4
LT
76 }
77
78 /* Before delegating work to the lower layer, enter our MAC-address */
79 if (saddr == NULL)
80 saddr = dev->dev_addr;
81
1349fe9a 82 /* Now make the underlying real hard header */
0c0667a8 83 dev = vlan->real_dev;
1349fe9a
PM
84 rc = dev_hard_header(skb, dev, type, daddr, saddr, len + vhdrlen);
85 if (rc > 0)
86 rc += vhdrlen;
1da177e4
LT
87 return rc;
88}
89
6eacf8ad
AW
90static inline netdev_tx_t vlan_netpoll_send_skb(struct vlan_dev_priv *vlan, struct sk_buff *skb)
91{
92#ifdef CONFIG_NET_POLL_CONTROLLER
f78ed220 93 return netpoll_send_skb(vlan->netpoll, skb);
6eacf8ad
AW
94#else
95 BUG();
6eacf8ad 96 return NETDEV_TX_OK;
f78ed220 97#endif
6eacf8ad
AW
98}
99
6fef4c0c
SH
100static netdev_tx_t vlan_dev_hard_start_xmit(struct sk_buff *skb,
101 struct net_device *dev)
1da177e4 102{
6eacf8ad 103 struct vlan_dev_priv *vlan = vlan_dev_priv(dev);
1da177e4 104 struct vlan_ethhdr *veth = (struct vlan_ethhdr *)(skb->data);
1a123a31
ED
105 unsigned int len;
106 int ret;
55b01e86 107
1da177e4
LT
108 /* Handle non-VLAN frames if they are sent to us, for example by DHCP.
109 *
110 * NOTE: THIS ASSUMES DIX ETHERNET, SPECIFICALLY NOT SUPPORTING
111 * OTHER THINGS LIKE FDDI/TokenRing/802.3 SNAPs...
112 */
dacab578
ED
113 if (vlan->flags & VLAN_FLAG_REORDER_HDR ||
114 veth->h_vlan_proto != vlan->vlan_proto) {
9bb8582e 115 u16 vlan_tci;
6eacf8ad 116 vlan_tci = vlan->vlan_id;
e267cb96 117 vlan_tci |= vlan_dev_get_egress_qos_mask(dev, skb->priority);
b960a0ac 118 __vlan_hwaccel_put_tag(skb, vlan->vlan_proto, vlan_tci);
1da177e4
LT
119 }
120
6eacf8ad 121 skb->dev = vlan->real_dev;
1a123a31 122 len = skb->len;
6eacf8ad
AW
123 if (unlikely(netpoll_tx_running(dev)))
124 return vlan_netpoll_send_skb(vlan, skb);
125
1a123a31
ED
126 ret = dev_queue_xmit(skb);
127
2d6c9ffc 128 if (likely(ret == NET_XMIT_SUCCESS || ret == NET_XMIT_CN)) {
4af429d2
ED
129 struct vlan_pcpu_stats *stats;
130
6eacf8ad 131 stats = this_cpu_ptr(vlan->vlan_pcpu_stats);
4af429d2 132 u64_stats_update_begin(&stats->syncp);
09cca53c
ED
133 u64_stats_inc(&stats->tx_packets);
134 u64_stats_add(&stats->tx_bytes, len);
307f73df 135 u64_stats_update_end(&stats->syncp);
4af429d2 136 } else {
6eacf8ad 137 this_cpu_inc(vlan->vlan_pcpu_stats->tx_dropped);
4af429d2 138 }
1a123a31 139
cbbef5e1 140 return ret;
1da177e4
LT
141}
142
ef3eb3e5 143static int vlan_dev_change_mtu(struct net_device *dev, int new_mtu)
1da177e4 144{
18d3df3e
PA
145 struct net_device *real_dev = vlan_dev_priv(dev)->real_dev;
146 unsigned int max_mtu = real_dev->mtu;
147
148 if (netif_reduces_vlan_mtu(real_dev))
149 max_mtu -= VLAN_HLEN;
150 if (max_mtu < new_mtu)
1da177e4
LT
151 return -ERANGE;
152
1eb2cded 153 WRITE_ONCE(dev->mtu, new_mtu);
1da177e4
LT
154
155 return 0;
156}
157
c17d8874 158void vlan_dev_set_ingress_priority(const struct net_device *dev,
9bb8582e 159 u32 skb_prio, u16 vlan_prio)
1da177e4 160{
7da82c06 161 struct vlan_dev_priv *vlan = vlan_dev_priv(dev);
b020cb48
PM
162
163 if (vlan->ingress_priority_map[vlan_prio & 0x7] && !skb_prio)
164 vlan->nr_ingress_mappings--;
165 else if (!vlan->ingress_priority_map[vlan_prio & 0x7] && skb_prio)
166 vlan->nr_ingress_mappings++;
167
168 vlan->ingress_priority_map[vlan_prio & 0x7] = skb_prio;
1da177e4
LT
169}
170
c17d8874 171int vlan_dev_set_egress_priority(const struct net_device *dev,
9bb8582e 172 u32 skb_prio, u16 vlan_prio)
1da177e4 173{
7da82c06 174 struct vlan_dev_priv *vlan = vlan_dev_priv(dev);
1da177e4
LT
175 struct vlan_priority_tci_mapping *mp = NULL;
176 struct vlan_priority_tci_mapping *np;
05423b24 177 u32 vlan_qos = (vlan_prio << VLAN_PRIO_SHIFT) & VLAN_PRIO_MASK;
122952fc 178
c17d8874 179 /* See if a priority mapping exists.. */
b020cb48 180 mp = vlan->egress_priority_map[skb_prio & 0xF];
c17d8874
PM
181 while (mp) {
182 if (mp->priority == skb_prio) {
b020cb48
PM
183 if (mp->vlan_qos && !vlan_qos)
184 vlan->nr_egress_mappings--;
185 else if (!mp->vlan_qos && vlan_qos)
186 vlan->nr_egress_mappings++;
187 mp->vlan_qos = vlan_qos;
c17d8874 188 return 0;
1da177e4 189 }
c17d8874 190 mp = mp->next;
1da177e4 191 }
c17d8874
PM
192
193 /* Create a new mapping then. */
b020cb48 194 mp = vlan->egress_priority_map[skb_prio & 0xF];
c17d8874
PM
195 np = kmalloc(sizeof(struct vlan_priority_tci_mapping), GFP_KERNEL);
196 if (!np)
197 return -ENOBUFS;
198
199 np->next = mp;
200 np->priority = skb_prio;
b020cb48 201 np->vlan_qos = vlan_qos;
3e3aac49
ED
202 /* Before inserting this element in hash table, make sure all its fields
203 * are committed to memory.
e267cb96 204 * coupled with smp_rmb() in vlan_dev_get_egress_qos_mask()
3e3aac49
ED
205 */
206 smp_wmb();
b020cb48
PM
207 vlan->egress_priority_map[skb_prio & 0xF] = np;
208 if (vlan_qos)
209 vlan->nr_egress_mappings++;
c17d8874 210 return 0;
1da177e4
LT
211}
212
84a2fba2
SL
213/* Flags are defined in the vlan_flags enum in
214 * include/uapi/linux/if_vlan.h file.
215 */
b3ce0325 216int vlan_dev_change_flags(const struct net_device *dev, u32 flags, u32 mask)
1da177e4 217{
7da82c06 218 struct vlan_dev_priv *vlan = vlan_dev_priv(dev);
b3ce0325
PM
219 u32 old_flags = vlan->flags;
220
5e756593 221 if (mask & ~(VLAN_FLAG_REORDER_HDR | VLAN_FLAG_GVRP |
8c8b3458
MM
222 VLAN_FLAG_LOOSE_BINDING | VLAN_FLAG_MVRP |
223 VLAN_FLAG_BRIDGE_BINDING))
b3ce0325
PM
224 return -EINVAL;
225
226 vlan->flags = (old_flags & ~mask) | (flags & mask);
70c03b49
PM
227
228 if (netif_running(dev) && (vlan->flags ^ old_flags) & VLAN_FLAG_GVRP) {
229 if (vlan->flags & VLAN_FLAG_GVRP)
230 vlan_gvrp_request_join(dev);
231 else
232 vlan_gvrp_request_leave(dev);
233 }
86fbe9bb
DW
234
235 if (netif_running(dev) && (vlan->flags ^ old_flags) & VLAN_FLAG_MVRP) {
236 if (vlan->flags & VLAN_FLAG_MVRP)
237 vlan_mvrp_request_join(dev);
238 else
239 vlan_mvrp_request_leave(dev);
240 }
b3ce0325 241 return 0;
1da177e4
LT
242}
243
9c153d38 244void vlan_dev_get_realdev_name(const struct net_device *dev, char *result, size_t size)
1da177e4 245{
9c153d38 246 strscpy_pad(result, vlan_dev_priv(dev)->real_dev->name, size);
1da177e4
LT
247}
248
308453aa
MM
249bool vlan_dev_inherit_address(struct net_device *dev,
250 struct net_device *real_dev)
251{
252 if (dev->addr_assign_type != NET_ADDR_STOLEN)
253 return false;
254
e35b8d7d 255 eth_hw_addr_set(dev, real_dev->dev_addr);
308453aa
MM
256 call_netdevice_notifiers(NETDEV_CHANGEADDR, dev);
257 return true;
258}
259
ef3eb3e5 260static int vlan_dev_open(struct net_device *dev)
1da177e4 261{
7da82c06 262 struct vlan_dev_priv *vlan = vlan_dev_priv(dev);
8c979c26
PM
263 struct net_device *real_dev = vlan->real_dev;
264 int err;
265
5e756593
PM
266 if (!(real_dev->flags & IFF_UP) &&
267 !(vlan->flags & VLAN_FLAG_LOOSE_BINDING))
1da177e4
LT
268 return -ENETDOWN;
269
308453aa
MM
270 if (!ether_addr_equal(dev->dev_addr, real_dev->dev_addr) &&
271 !vlan_dev_inherit_address(dev, real_dev)) {
a748ee24 272 err = dev_uc_add(real_dev, dev->dev_addr);
8c979c26 273 if (err < 0)
89146504 274 goto out;
8c979c26 275 }
8c979c26 276
07fc67be 277 ether_addr_copy(vlan->real_dev_addr, real_dev->dev_addr);
6c78dcbd 278
70c03b49
PM
279 if (vlan->flags & VLAN_FLAG_GVRP)
280 vlan_gvrp_request_join(dev);
281
86fbe9bb
DW
282 if (vlan->flags & VLAN_FLAG_MVRP)
283 vlan_mvrp_request_join(dev);
284
76052d8c
MM
285 if (netif_carrier_ok(real_dev) &&
286 !(vlan->flags & VLAN_FLAG_BRIDGE_BINDING))
0ac820ee 287 netif_carrier_on(dev);
1da177e4 288 return 0;
89146504 289
89146504 290out:
adc667e8 291 netif_carrier_off(dev);
89146504 292 return err;
1da177e4
LT
293}
294
ef3eb3e5 295static int vlan_dev_stop(struct net_device *dev)
1da177e4 296{
7da82c06 297 struct vlan_dev_priv *vlan = vlan_dev_priv(dev);
70c03b49
PM
298 struct net_device *real_dev = vlan->real_dev;
299
56addd6e 300 dev_mc_unsync(real_dev, dev);
a748ee24 301 dev_uc_unsync(real_dev, dev);
6c78dcbd 302
53a2b3a1 303 if (!ether_addr_equal(dev->dev_addr, real_dev->dev_addr))
a748ee24 304 dev_uc_del(real_dev, dev->dev_addr);
8c979c26 305
76052d8c
MM
306 if (!(vlan->flags & VLAN_FLAG_BRIDGE_BINDING))
307 netif_carrier_off(dev);
1da177e4
LT
308 return 0;
309}
310
ef3eb3e5 311static int vlan_dev_set_mac_address(struct net_device *dev, void *p)
39aaac11 312{
7da82c06 313 struct net_device *real_dev = vlan_dev_priv(dev)->real_dev;
39aaac11
PM
314 struct sockaddr *addr = p;
315 int err;
316
317 if (!is_valid_ether_addr(addr->sa_data))
318 return -EADDRNOTAVAIL;
319
320 if (!(dev->flags & IFF_UP))
321 goto out;
322
53a2b3a1 323 if (!ether_addr_equal(addr->sa_data, real_dev->dev_addr)) {
a748ee24 324 err = dev_uc_add(real_dev, addr->sa_data);
39aaac11
PM
325 if (err < 0)
326 return err;
327 }
328
53a2b3a1 329 if (!ether_addr_equal(dev->dev_addr, real_dev->dev_addr))
a748ee24 330 dev_uc_del(real_dev, dev->dev_addr);
39aaac11
PM
331
332out:
e35b8d7d 333 eth_hw_addr_set(dev, addr->sa_data);
39aaac11
PM
334 return 0;
335}
336
65c9fde1
MG
337static int vlan_hwtstamp_get(struct net_device *dev,
338 struct kernel_hwtstamp_config *cfg)
339{
340 struct net_device *real_dev = vlan_dev_priv(dev)->real_dev;
341
342 return generic_hwtstamp_get_lower(real_dev, cfg);
343}
344
345static int vlan_hwtstamp_set(struct net_device *dev,
346 struct kernel_hwtstamp_config *cfg,
347 struct netlink_ext_ack *extack)
348{
349 struct net_device *real_dev = vlan_dev_priv(dev)->real_dev;
350
351 if (!net_eq(dev_net(dev), dev_net(real_dev)))
352 return -EOPNOTSUPP;
353
354 return generic_hwtstamp_set_lower(real_dev, cfg, extack);
355}
356
ef3eb3e5 357static int vlan_dev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
1da177e4 358{
7da82c06 359 struct net_device *real_dev = vlan_dev_priv(dev)->real_dev;
1da177e4
LT
360 struct ifreq ifrr;
361 int err = -EOPNOTSUPP;
362
9c153d38 363 strscpy_pad(ifrr.ifr_name, real_dev->name, IFNAMSIZ);
1da177e4
LT
364 ifrr.ifr_ifru = ifr->ifr_ifru;
365
2029cc2c 366 switch (cmd) {
1da177e4
LT
367 case SIOCGMIIPHY:
368 case SIOCGMIIREG:
369 case SIOCSMIIREG:
ffb7ed19 370 err = dev_eth_ioctl(real_dev, &ifrr, cmd);
1da177e4 371 break;
1da177e4
LT
372 }
373
122952fc 374 if (!err)
1da177e4
LT
375 ifr->ifr_ifru = ifrr.ifr_ifru;
376
377 return err;
378}
379
cc883d16
FB
380static int vlan_dev_neigh_setup(struct net_device *dev, struct neigh_parms *pa)
381{
7da82c06 382 struct net_device *real_dev = vlan_dev_priv(dev)->real_dev;
cc883d16
FB
383 const struct net_device_ops *ops = real_dev->netdev_ops;
384 int err = 0;
385
386 if (netif_device_present(real_dev) && ops->ndo_neigh_setup)
9d40bbda 387 err = ops->ndo_neigh_setup(real_dev, pa);
cc883d16
FB
388
389 return err;
390}
391
f4d5392e 392#if IS_ENABLED(CONFIG_FCOE)
b85daa53
VD
393static int vlan_dev_fcoe_ddp_setup(struct net_device *dev, u16 xid,
394 struct scatterlist *sgl, unsigned int sgc)
395{
7da82c06 396 struct net_device *real_dev = vlan_dev_priv(dev)->real_dev;
b85daa53
VD
397 const struct net_device_ops *ops = real_dev->netdev_ops;
398 int rc = 0;
399
400 if (ops->ndo_fcoe_ddp_setup)
401 rc = ops->ndo_fcoe_ddp_setup(real_dev, xid, sgl, sgc);
402
403 return rc;
404}
405
406static int vlan_dev_fcoe_ddp_done(struct net_device *dev, u16 xid)
407{
7da82c06 408 struct net_device *real_dev = vlan_dev_priv(dev)->real_dev;
b85daa53
VD
409 const struct net_device_ops *ops = real_dev->netdev_ops;
410 int len = 0;
411
412 if (ops->ndo_fcoe_ddp_done)
413 len = ops->ndo_fcoe_ddp_done(real_dev, xid);
414
415 return len;
416}
0af46d99
YZ
417
418static int vlan_dev_fcoe_enable(struct net_device *dev)
419{
7da82c06 420 struct net_device *real_dev = vlan_dev_priv(dev)->real_dev;
0af46d99
YZ
421 const struct net_device_ops *ops = real_dev->netdev_ops;
422 int rc = -EINVAL;
423
424 if (ops->ndo_fcoe_enable)
425 rc = ops->ndo_fcoe_enable(real_dev);
426 return rc;
427}
428
429static int vlan_dev_fcoe_disable(struct net_device *dev)
430{
7da82c06 431 struct net_device *real_dev = vlan_dev_priv(dev)->real_dev;
0af46d99
YZ
432 const struct net_device_ops *ops = real_dev->netdev_ops;
433 int rc = -EINVAL;
434
435 if (ops->ndo_fcoe_disable)
436 rc = ops->ndo_fcoe_disable(real_dev);
437 return rc;
438}
d6534799 439
0a89eb92
CL
440static int vlan_dev_fcoe_ddp_target(struct net_device *dev, u16 xid,
441 struct scatterlist *sgl, unsigned int sgc)
d6534799 442{
7da82c06 443 struct net_device *real_dev = vlan_dev_priv(dev)->real_dev;
d6534799 444 const struct net_device_ops *ops = real_dev->netdev_ops;
0a89eb92
CL
445 int rc = 0;
446
447 if (ops->ndo_fcoe_ddp_target)
448 rc = ops->ndo_fcoe_ddp_target(real_dev, xid, sgl, sgc);
d6534799 449
d6534799
YZ
450 return rc;
451}
0a89eb92 452#endif
4ea09c9c 453
0a89eb92
CL
454#ifdef NETDEV_FCOE_WWNN
455static int vlan_dev_fcoe_get_wwn(struct net_device *dev, u64 *wwn, int type)
4ea09c9c 456{
7da82c06 457 struct net_device *real_dev = vlan_dev_priv(dev)->real_dev;
4ea09c9c 458 const struct net_device_ops *ops = real_dev->netdev_ops;
0a89eb92 459 int rc = -EINVAL;
4ea09c9c 460
0a89eb92
CL
461 if (ops->ndo_fcoe_get_wwn)
462 rc = ops->ndo_fcoe_get_wwn(real_dev, wwn, type);
4ea09c9c
YZ
463 return rc;
464}
b85daa53
VD
465#endif
466
ef3eb3e5 467static void vlan_dev_change_rx_flags(struct net_device *dev, int change)
6c78dcbd 468{
7da82c06 469 struct net_device *real_dev = vlan_dev_priv(dev)->real_dev;
6c78dcbd 470
27b91800
SF
471 if (change & IFF_ALLMULTI)
472 dev_set_allmulti(real_dev, dev->flags & IFF_ALLMULTI ? 1 : -1);
473 if (change & IFF_PROMISC)
474 dev_set_promiscuity(real_dev, dev->flags & IFF_PROMISC ? 1 : -1);
6c78dcbd
PM
475}
476
e83a2ea8 477static void vlan_dev_set_rx_mode(struct net_device *vlan_dev)
1da177e4 478{
d38569ab
VY
479 dev_mc_sync(vlan_dev_priv(vlan_dev)->real_dev, vlan_dev);
480 dev_uc_sync(vlan_dev_priv(vlan_dev)->real_dev, vlan_dev);
1da177e4 481}
ef3eb3e5 482
71854255
EBE
483static __be16 vlan_parse_protocol(const struct sk_buff *skb)
484{
485 struct vlan_ethhdr *veth = (struct vlan_ethhdr *)(skb->data);
486
487 return __vlan_get_protocol(skb, veth->h_vlan_proto, NULL);
488}
489
ef3eb3e5
PM
490static const struct header_ops vlan_header_ops = {
491 .create = vlan_dev_hard_header,
ef3eb3e5 492 .parse = eth_header_parse,
71854255 493 .parse_protocol = vlan_parse_protocol,
ef3eb3e5
PM
494};
495
2205369a
DM
496static int vlan_passthru_hard_header(struct sk_buff *skb, struct net_device *dev,
497 unsigned short type,
498 const void *daddr, const void *saddr,
499 unsigned int len)
500{
501 struct vlan_dev_priv *vlan = vlan_dev_priv(dev);
502 struct net_device *real_dev = vlan->real_dev;
503
dd38743b
PB
504 if (saddr == NULL)
505 saddr = dev->dev_addr;
506
2205369a
DM
507 return dev_hard_header(skb, real_dev, type, daddr, saddr, len);
508}
509
510static const struct header_ops vlan_passthru_header_ops = {
511 .create = vlan_passthru_hard_header,
2205369a 512 .parse = eth_header_parse,
71854255 513 .parse_protocol = vlan_parse_protocol,
2205369a
DM
514};
515
7ae9d342 516static const struct device_type vlan_type = {
e949b09b
DG
517 .name = "vlan",
518};
519
213b15ca 520static const struct net_device_ops vlan_netdev_ops;
f7d1b9f5 521
ef3eb3e5
PM
522static int vlan_dev_init(struct net_device *dev)
523{
76052d8c
MM
524 struct vlan_dev_priv *vlan = vlan_dev_priv(dev);
525 struct net_device *real_dev = vlan->real_dev;
ef3eb3e5 526
adc667e8
JV
527 netif_carrier_off(dev);
528
ef3eb3e5 529 /* IFF_BROADCAST|IFF_MULTICAST; ??? */
194dbcc8
JF
530 dev->flags = real_dev->flags & ~(IFF_UP | IFF_PROMISC | IFF_ALLMULTI |
531 IFF_MASTER | IFF_SLAVE);
ef3eb3e5
PM
532 dev->state = (real_dev->state & ((1<<__LINK_STATE_NOCARRIER) |
533 (1<<__LINK_STATE_DORMANT))) |
534 (1<<__LINK_STATE_PRESENT);
535
76052d8c
MM
536 if (vlan->flags & VLAN_FLAG_BRIDGE_BINDING)
537 dev->state |= (1 << __LINK_STATE_NOCARRIER);
538
a188222b 539 dev->hw_features = NETIF_F_HW_CSUM | NETIF_F_SG |
53f6b708 540 NETIF_F_FRAGLIST | NETIF_F_GSO_SOFTWARE |
7dad9937 541 NETIF_F_GSO_ENCAP_ALL |
53692b1d 542 NETIF_F_HIGHDMA | NETIF_F_SCTP_CRC |
a61fec1c 543 NETIF_F_FCOE_CRC | NETIF_F_FSO;
62f2a3a4 544
abff3e5e
EH
545 if (real_dev->vlan_features & NETIF_F_HW_MACSEC)
546 dev->hw_features |= NETIF_F_HW_MACSEC;
547
00d066a4
AL
548 dev->features |= dev->hw_features;
549 dev->lltx = true;
782dbbf5 550 dev->fcoe_mtu = true;
6df6398f 551 netif_inherit_tso_max(dev, real_dev);
2adb956b
VY
552 if (dev->features & NETIF_F_VLAN_FEATURES)
553 netdev_warn(real_dev, "VLAN features are set incorrectly. Q-in-Q configurations may not work correctly.\n");
554
a61fec1c
AL
555 dev->vlan_features = real_dev->vlan_features &
556 ~(NETIF_F_FCOE_CRC | NETIF_F_FSO);
7dad9937 557 dev->hw_enc_features = vlan_tnl_features(real_dev);
8b6912a5 558 dev->mpls_features = real_dev->mpls_features;
5fb13570 559
ef3eb3e5
PM
560 /* ipv6 shared card related stuff */
561 dev->dev_id = real_dev->dev_id;
562
308453aa 563 if (is_zero_ether_addr(dev->dev_addr)) {
e35b8d7d 564 eth_hw_addr_set(dev, real_dev->dev_addr);
308453aa
MM
565 dev->addr_assign_type = NET_ADDR_STOLEN;
566 }
ef3eb3e5
PM
567 if (is_zero_ether_addr(dev->broadcast))
568 memcpy(dev->broadcast, real_dev->broadcast, dev->addr_len);
569
f4d5392e 570#if IS_ENABLED(CONFIG_FCOE)
b85daa53
VD
571 dev->fcoe_ddp_xid = real_dev->fcoe_ddp_xid;
572#endif
573
d870bfb9 574 dev->needed_headroom = real_dev->needed_headroom;
76052d8c 575 if (vlan_hw_offload_capable(real_dev->features, vlan->vlan_proto)) {
2205369a 576 dev->header_ops = &vlan_passthru_header_ops;
ef3eb3e5 577 dev->hard_header_len = real_dev->hard_header_len;
ef3eb3e5
PM
578 } else {
579 dev->header_ops = &vlan_header_ops;
580 dev->hard_header_len = real_dev->hard_header_len + VLAN_HLEN;
ef3eb3e5
PM
581 }
582
213b15ca 583 dev->netdev_ops = &vlan_netdev_ops;
636e19a3 584
e949b09b
DG
585 SET_NETDEV_DEVTYPE(dev, &vlan_type);
586
9a3c93af 587 netdev_lockdep_set_classes(dev);
1a33e10e 588
76052d8c
MM
589 vlan->vlan_pcpu_stats = netdev_alloc_pcpu_stats(struct vlan_pcpu_stats);
590 if (!vlan->vlan_pcpu_stats)
9793241f
ED
591 return -ENOMEM;
592
01d9cc2d 593 /* Get vlan's reference to real_dev */
d62607c3 594 netdev_hold(real_dev, &vlan->dev_tracker, GFP_KERNEL);
01d9cc2d 595
ef3eb3e5
PM
596 return 0;
597}
598
9bbd917e 599/* Note: this function might be called multiple times for the same device. */
37aa50c5 600void vlan_dev_free_egress_priority(const struct net_device *dev)
23556323
PE
601{
602 struct vlan_priority_tci_mapping *pm;
7da82c06 603 struct vlan_dev_priv *vlan = vlan_dev_priv(dev);
23556323
PE
604 int i;
605
606 for (i = 0; i < ARRAY_SIZE(vlan->egress_priority_map); i++) {
607 while ((pm = vlan->egress_priority_map[i]) != NULL) {
608 vlan->egress_priority_map[i] = pm->next;
609 kfree(pm);
610 }
611 }
612}
613
37aa50c5
XL
614static void vlan_dev_uninit(struct net_device *dev)
615{
616 vlan_dev_free_egress_priority(dev);
617}
618
c8f44aff
MM
619static netdev_features_t vlan_dev_fix_features(struct net_device *dev,
620 netdev_features_t features)
8a0427bb 621{
7da82c06 622 struct net_device *real_dev = vlan_dev_priv(dev)->real_dev;
b29d3145 623 netdev_features_t old_features = features;
8403debe 624 netdev_features_t lower_features;
8a0427bb 625
8403debe
VY
626 lower_features = netdev_intersect_features((real_dev->vlan_features |
627 NETIF_F_RXCSUM),
628 real_dev->features);
712ae51a 629
8403debe
VY
630 /* Add HW_CSUM setting to preserve user ability to control
631 * checksum offload on the vlan device.
632 */
633 if (lower_features & (NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM))
634 lower_features |= NETIF_F_HW_CSUM;
635 features = netdev_intersect_features(features, lower_features);
53f6b708 636 features |= old_features & (NETIF_F_SOFT_FEATURES | NETIF_F_GSO_SOFTWARE);
8a0427bb
MM
637
638 return features;
639}
640
57709798
DD
641static int vlan_ethtool_get_link_ksettings(struct net_device *dev,
642 struct ethtool_link_ksettings *cmd)
b3020061 643{
7da82c06 644 const struct vlan_dev_priv *vlan = vlan_dev_priv(dev);
4bc71cb9 645
57709798 646 return __ethtool_get_link_ksettings(vlan->real_dev, cmd);
b3020061
SH
647}
648
649static void vlan_ethtool_get_drvinfo(struct net_device *dev,
650 struct ethtool_drvinfo *info)
651{
bb4d15df
WS
652 strscpy(info->driver, vlan_fullname, sizeof(info->driver));
653 strscpy(info->version, vlan_version, sizeof(info->version));
654 strscpy(info->fw_version, "N/A", sizeof(info->fw_version));
b3020061
SH
655}
656
37dd9255 657static int vlan_ethtool_get_ts_info(struct net_device *dev,
2111375b 658 struct kernel_ethtool_ts_info *info)
37dd9255
RC
659{
660 const struct vlan_dev_priv *vlan = vlan_dev_priv(dev);
b8768dc4 661 return ethtool_get_ts_info_by_layer(vlan->real_dev, info);
37dd9255
RC
662}
663
bc1f4470 664static void vlan_dev_get_stats64(struct net_device *dev,
665 struct rtnl_link_stats64 *stats)
9793241f 666{
5a4ae5f6
LR
667 struct vlan_pcpu_stats *p;
668 u32 rx_errors = 0, tx_dropped = 0;
669 int i;
9793241f 670
5a4ae5f6
LR
671 for_each_possible_cpu(i) {
672 u64 rxpackets, rxbytes, rxmulticast, txpackets, txbytes;
673 unsigned int start;
674
675 p = per_cpu_ptr(vlan_dev_priv(dev)->vlan_pcpu_stats, i);
676 do {
d120d1a6 677 start = u64_stats_fetch_begin(&p->syncp);
09cca53c
ED
678 rxpackets = u64_stats_read(&p->rx_packets);
679 rxbytes = u64_stats_read(&p->rx_bytes);
680 rxmulticast = u64_stats_read(&p->rx_multicast);
681 txpackets = u64_stats_read(&p->tx_packets);
682 txbytes = u64_stats_read(&p->tx_bytes);
d120d1a6 683 } while (u64_stats_fetch_retry(&p->syncp, start));
5a4ae5f6
LR
684
685 stats->rx_packets += rxpackets;
686 stats->rx_bytes += rxbytes;
687 stats->multicast += rxmulticast;
688 stats->tx_packets += txpackets;
689 stats->tx_bytes += txbytes;
690 /* rx_errors & tx_dropped are u32 */
09cca53c
ED
691 rx_errors += READ_ONCE(p->rx_errors);
692 tx_dropped += READ_ONCE(p->tx_dropped);
9793241f 693 }
5a4ae5f6
LR
694 stats->rx_errors = rx_errors;
695 stats->tx_dropped = tx_dropped;
9793241f
ED
696}
697
6d4cdf47 698#ifdef CONFIG_NET_POLL_CONTROLLER
de93cb2e 699static void vlan_dev_poll_controller(struct net_device *dev)
6d4cdf47
BL
700{
701 return;
702}
703
e44ef3f6 704static int vlan_dev_netpoll_setup(struct net_device *dev)
6d4cdf47 705{
f3da3893
AW
706 struct vlan_dev_priv *vlan = vlan_dev_priv(dev);
707 struct net_device *real_dev = vlan->real_dev;
6d4cdf47
BL
708 struct netpoll *netpoll;
709 int err = 0;
710
a8779ec1 711 netpoll = kzalloc(sizeof(*netpoll), GFP_KERNEL);
6d4cdf47
BL
712 err = -ENOMEM;
713 if (!netpoll)
714 goto out;
715
a8779ec1 716 err = __netpoll_setup(netpoll, real_dev);
6d4cdf47
BL
717 if (err) {
718 kfree(netpoll);
719 goto out;
720 }
721
f3da3893 722 vlan->netpoll = netpoll;
6d4cdf47
BL
723
724out:
725 return err;
726}
727
de93cb2e 728static void vlan_dev_netpoll_cleanup(struct net_device *dev)
6d4cdf47 729{
f3da3893
AW
730 struct vlan_dev_priv *vlan= vlan_dev_priv(dev);
731 struct netpoll *netpoll = vlan->netpoll;
6d4cdf47
BL
732
733 if (!netpoll)
734 return;
735
f3da3893 736 vlan->netpoll = NULL;
c9fbd71f 737 __netpoll_free(netpoll);
6d4cdf47
BL
738}
739#endif /* CONFIG_NET_POLL_CONTROLLER */
740
2dbf6b50
ND
741static int vlan_dev_get_iflink(const struct net_device *dev)
742{
e353ea9c 743 const struct net_device *real_dev = vlan_dev_priv(dev)->real_dev;
2dbf6b50 744
e353ea9c 745 return READ_ONCE(real_dev->ifindex);
2dbf6b50
ND
746}
747
e4417d69
PNA
748static int vlan_dev_fill_forward_path(struct net_device_path_ctx *ctx,
749 struct net_device_path *path)
750{
751 struct vlan_dev_priv *vlan = vlan_dev_priv(ctx->dev);
752
753 path->type = DEV_PATH_VLAN;
754 path->encap.id = vlan->vlan_id;
755 path->encap.proto = vlan->vlan_proto;
756 path->dev = ctx->dev;
757 ctx->dev = vlan->real_dev;
bcf2766b
FF
758 if (ctx->num_vlans >= ARRAY_SIZE(ctx->vlan))
759 return -ENOSPC;
760
761 ctx->vlan[ctx->num_vlans].id = vlan->vlan_id;
762 ctx->vlan[ctx->num_vlans].proto = vlan->vlan_proto;
763 ctx->num_vlans++;
e4417d69
PNA
764
765 return 0;
766}
767
abff3e5e
EH
768#if IS_ENABLED(CONFIG_MACSEC)
769
770static const struct macsec_ops *vlan_get_macsec_ops(const struct macsec_context *ctx)
771{
772 return vlan_dev_priv(ctx->netdev)->real_dev->macsec_ops;
773}
774
775static int vlan_macsec_offload(int (* const func)(struct macsec_context *),
776 struct macsec_context *ctx)
777{
778 if (unlikely(!func))
779 return 0;
780
781 return (*func)(ctx);
782}
783
784static int vlan_macsec_dev_open(struct macsec_context *ctx)
785{
786 const struct macsec_ops *ops = vlan_get_macsec_ops(ctx);
787
788 if (!ops)
789 return -EOPNOTSUPP;
790
791 return vlan_macsec_offload(ops->mdo_dev_open, ctx);
792}
793
794static int vlan_macsec_dev_stop(struct macsec_context *ctx)
795{
796 const struct macsec_ops *ops = vlan_get_macsec_ops(ctx);
797
798 if (!ops)
799 return -EOPNOTSUPP;
800
801 return vlan_macsec_offload(ops->mdo_dev_stop, ctx);
802}
803
804static int vlan_macsec_add_secy(struct macsec_context *ctx)
805{
806 const struct macsec_ops *ops = vlan_get_macsec_ops(ctx);
807
808 if (!ops)
809 return -EOPNOTSUPP;
810
811 return vlan_macsec_offload(ops->mdo_add_secy, ctx);
812}
813
814static int vlan_macsec_upd_secy(struct macsec_context *ctx)
815{
816 const struct macsec_ops *ops = vlan_get_macsec_ops(ctx);
817
818 if (!ops)
819 return -EOPNOTSUPP;
820
821 return vlan_macsec_offload(ops->mdo_upd_secy, ctx);
822}
823
824static int vlan_macsec_del_secy(struct macsec_context *ctx)
825{
826 const struct macsec_ops *ops = vlan_get_macsec_ops(ctx);
827
828 if (!ops)
829 return -EOPNOTSUPP;
830
831 return vlan_macsec_offload(ops->mdo_del_secy, ctx);
832}
833
834static int vlan_macsec_add_rxsc(struct macsec_context *ctx)
835{
836 const struct macsec_ops *ops = vlan_get_macsec_ops(ctx);
837
838 if (!ops)
839 return -EOPNOTSUPP;
840
841 return vlan_macsec_offload(ops->mdo_add_rxsc, ctx);
842}
843
844static int vlan_macsec_upd_rxsc(struct macsec_context *ctx)
845{
846 const struct macsec_ops *ops = vlan_get_macsec_ops(ctx);
847
848 if (!ops)
849 return -EOPNOTSUPP;
850
851 return vlan_macsec_offload(ops->mdo_upd_rxsc, ctx);
852}
853
854static int vlan_macsec_del_rxsc(struct macsec_context *ctx)
855{
856 const struct macsec_ops *ops = vlan_get_macsec_ops(ctx);
857
858 if (!ops)
859 return -EOPNOTSUPP;
860
861 return vlan_macsec_offload(ops->mdo_del_rxsc, ctx);
862}
863
864static int vlan_macsec_add_rxsa(struct macsec_context *ctx)
865{
866 const struct macsec_ops *ops = vlan_get_macsec_ops(ctx);
867
868 if (!ops)
869 return -EOPNOTSUPP;
870
871 return vlan_macsec_offload(ops->mdo_add_rxsa, ctx);
872}
873
874static int vlan_macsec_upd_rxsa(struct macsec_context *ctx)
875{
876 const struct macsec_ops *ops = vlan_get_macsec_ops(ctx);
877
878 if (!ops)
879 return -EOPNOTSUPP;
880
881 return vlan_macsec_offload(ops->mdo_upd_rxsa, ctx);
882}
883
884static int vlan_macsec_del_rxsa(struct macsec_context *ctx)
885{
886 const struct macsec_ops *ops = vlan_get_macsec_ops(ctx);
887
888 if (!ops)
889 return -EOPNOTSUPP;
890
891 return vlan_macsec_offload(ops->mdo_del_rxsa, ctx);
892}
893
894static int vlan_macsec_add_txsa(struct macsec_context *ctx)
895{
896 const struct macsec_ops *ops = vlan_get_macsec_ops(ctx);
897
898 if (!ops)
899 return -EOPNOTSUPP;
900
901 return vlan_macsec_offload(ops->mdo_add_txsa, ctx);
902}
903
904static int vlan_macsec_upd_txsa(struct macsec_context *ctx)
905{
906 const struct macsec_ops *ops = vlan_get_macsec_ops(ctx);
907
908 if (!ops)
909 return -EOPNOTSUPP;
910
911 return vlan_macsec_offload(ops->mdo_upd_txsa, ctx);
912}
913
914static int vlan_macsec_del_txsa(struct macsec_context *ctx)
915{
916 const struct macsec_ops *ops = vlan_get_macsec_ops(ctx);
917
918 if (!ops)
919 return -EOPNOTSUPP;
920
921 return vlan_macsec_offload(ops->mdo_del_txsa, ctx);
922}
923
924static int vlan_macsec_get_dev_stats(struct macsec_context *ctx)
925{
926 const struct macsec_ops *ops = vlan_get_macsec_ops(ctx);
927
928 if (!ops)
929 return -EOPNOTSUPP;
930
931 return vlan_macsec_offload(ops->mdo_get_dev_stats, ctx);
932}
933
934static int vlan_macsec_get_tx_sc_stats(struct macsec_context *ctx)
935{
936 const struct macsec_ops *ops = vlan_get_macsec_ops(ctx);
937
938 if (!ops)
939 return -EOPNOTSUPP;
940
941 return vlan_macsec_offload(ops->mdo_get_tx_sc_stats, ctx);
942}
943
944static int vlan_macsec_get_tx_sa_stats(struct macsec_context *ctx)
945{
946 const struct macsec_ops *ops = vlan_get_macsec_ops(ctx);
947
948 if (!ops)
949 return -EOPNOTSUPP;
950
951 return vlan_macsec_offload(ops->mdo_get_tx_sa_stats, ctx);
952}
953
954static int vlan_macsec_get_rx_sc_stats(struct macsec_context *ctx)
955{
956 const struct macsec_ops *ops = vlan_get_macsec_ops(ctx);
957
958 if (!ops)
959 return -EOPNOTSUPP;
960
961 return vlan_macsec_offload(ops->mdo_get_rx_sc_stats, ctx);
962}
963
964static int vlan_macsec_get_rx_sa_stats(struct macsec_context *ctx)
965{
966 const struct macsec_ops *ops = vlan_get_macsec_ops(ctx);
967
968 if (!ops)
969 return -EOPNOTSUPP;
970
971 return vlan_macsec_offload(ops->mdo_get_rx_sa_stats, ctx);
972}
973
974static const struct macsec_ops macsec_offload_ops = {
975 /* Device wide */
976 .mdo_dev_open = vlan_macsec_dev_open,
977 .mdo_dev_stop = vlan_macsec_dev_stop,
978 /* SecY */
979 .mdo_add_secy = vlan_macsec_add_secy,
980 .mdo_upd_secy = vlan_macsec_upd_secy,
981 .mdo_del_secy = vlan_macsec_del_secy,
982 /* Security channels */
983 .mdo_add_rxsc = vlan_macsec_add_rxsc,
984 .mdo_upd_rxsc = vlan_macsec_upd_rxsc,
985 .mdo_del_rxsc = vlan_macsec_del_rxsc,
986 /* Security associations */
987 .mdo_add_rxsa = vlan_macsec_add_rxsa,
988 .mdo_upd_rxsa = vlan_macsec_upd_rxsa,
989 .mdo_del_rxsa = vlan_macsec_del_rxsa,
990 .mdo_add_txsa = vlan_macsec_add_txsa,
991 .mdo_upd_txsa = vlan_macsec_upd_txsa,
992 .mdo_del_txsa = vlan_macsec_del_txsa,
993 /* Statistics */
994 .mdo_get_dev_stats = vlan_macsec_get_dev_stats,
995 .mdo_get_tx_sc_stats = vlan_macsec_get_tx_sc_stats,
996 .mdo_get_tx_sa_stats = vlan_macsec_get_tx_sa_stats,
997 .mdo_get_rx_sc_stats = vlan_macsec_get_rx_sc_stats,
998 .mdo_get_rx_sa_stats = vlan_macsec_get_rx_sa_stats,
999};
1000
1001#endif
1002
75b8846a 1003static const struct ethtool_ops vlan_ethtool_ops = {
57709798 1004 .get_link_ksettings = vlan_ethtool_get_link_ksettings,
b3020061 1005 .get_drvinfo = vlan_ethtool_get_drvinfo,
75b8846a 1006 .get_link = ethtool_op_get_link,
37dd9255 1007 .get_ts_info = vlan_ethtool_get_ts_info,
75b8846a
PM
1008};
1009
656299f7
SH
1010static const struct net_device_ops vlan_netdev_ops = {
1011 .ndo_change_mtu = vlan_dev_change_mtu,
1012 .ndo_init = vlan_dev_init,
1013 .ndo_uninit = vlan_dev_uninit,
1014 .ndo_open = vlan_dev_open,
1015 .ndo_stop = vlan_dev_stop,
669d3e0b
VD
1016 .ndo_start_xmit = vlan_dev_hard_start_xmit,
1017 .ndo_validate_addr = eth_validate_addr,
1018 .ndo_set_mac_address = vlan_dev_set_mac_address,
1019 .ndo_set_rx_mode = vlan_dev_set_rx_mode,
669d3e0b 1020 .ndo_change_rx_flags = vlan_dev_change_rx_flags,
a7605370 1021 .ndo_eth_ioctl = vlan_dev_ioctl,
669d3e0b 1022 .ndo_neigh_setup = vlan_dev_neigh_setup,
9618e2ff 1023 .ndo_get_stats64 = vlan_dev_get_stats64,
f4d5392e 1024#if IS_ENABLED(CONFIG_FCOE)
669d3e0b
VD
1025 .ndo_fcoe_ddp_setup = vlan_dev_fcoe_ddp_setup,
1026 .ndo_fcoe_ddp_done = vlan_dev_fcoe_ddp_done,
1027 .ndo_fcoe_enable = vlan_dev_fcoe_enable,
1028 .ndo_fcoe_disable = vlan_dev_fcoe_disable,
4ea09c9c 1029 .ndo_fcoe_ddp_target = vlan_dev_fcoe_ddp_target,
6d4cdf47 1030#endif
0a89eb92
CL
1031#ifdef NETDEV_FCOE_WWNN
1032 .ndo_fcoe_get_wwn = vlan_dev_fcoe_get_wwn,
1033#endif
6d4cdf47
BL
1034#ifdef CONFIG_NET_POLL_CONTROLLER
1035 .ndo_poll_controller = vlan_dev_poll_controller,
1036 .ndo_netpoll_setup = vlan_dev_netpoll_setup,
1037 .ndo_netpoll_cleanup = vlan_dev_netpoll_cleanup,
669d3e0b 1038#endif
8a0427bb 1039 .ndo_fix_features = vlan_dev_fix_features,
2dbf6b50 1040 .ndo_get_iflink = vlan_dev_get_iflink,
e4417d69 1041 .ndo_fill_forward_path = vlan_dev_fill_forward_path,
65c9fde1
MG
1042 .ndo_hwtstamp_get = vlan_hwtstamp_get,
1043 .ndo_hwtstamp_set = vlan_hwtstamp_set,
669d3e0b
VD
1044};
1045
a48e5faf
ED
1046static void vlan_dev_free(struct net_device *dev)
1047{
1048 struct vlan_dev_priv *vlan = vlan_dev_priv(dev);
1049
1050 free_percpu(vlan->vlan_pcpu_stats);
1051 vlan->vlan_pcpu_stats = NULL;
6a47cdc3
XL
1052
1053 /* Get rid of the vlan's reference to real_dev */
d62607c3 1054 netdev_put(vlan->real_dev, &vlan->dev_tracker);
a48e5faf
ED
1055}
1056
ef3eb3e5
PM
1057void vlan_setup(struct net_device *dev)
1058{
1059 ether_setup(dev);
1060
2e659c05 1061 dev->priv_flags |= IFF_802_1Q_VLAN | IFF_NO_QUEUE;
e817af27 1062 dev->priv_flags |= IFF_UNICAST_FLT;
02875878
ED
1063 dev->priv_flags &= ~IFF_TX_SKB_SHARING;
1064 netif_keep_dst(dev);
ef3eb3e5 1065
656299f7 1066 dev->netdev_ops = &vlan_netdev_ops;
cf124db5
DM
1067 dev->needs_free_netdev = true;
1068 dev->priv_destructor = vlan_dev_free;
75b8846a 1069 dev->ethtool_ops = &vlan_ethtool_ops;
ef3eb3e5 1070
abff3e5e
EH
1071#if IS_ENABLED(CONFIG_MACSEC)
1072 dev->macsec_ops = &macsec_offload_ops;
1073#endif
91572088
JW
1074 dev->min_mtu = 0;
1075 dev->max_mtu = ETH_MAX_MTU;
1076
423049ab 1077 eth_zero_addr(dev->broadcast);
ef3eb3e5 1078}