hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/include/linux/if_vlan.h
....@@ -1,13 +1,8 @@
1
+/* SPDX-License-Identifier: GPL-2.0-or-later */
12 /*
23 * VLAN An implementation of 802.1Q VLAN tagging.
34 *
45 * Authors: Ben Greear <greearb@candelatech.com>
5
- *
6
- * This program is free software; you can redistribute it and/or
7
- * modify it under the terms of the GNU General Public License
8
- * as published by the Free Software Foundation; either version
9
- * 2 of the License, or (at your option) any later version.
10
- *
116 */
127 #ifndef _LINUX_IF_VLAN_H_
138 #define _LINUX_IF_VLAN_H_
....@@ -67,8 +62,7 @@
6762
6863 #define VLAN_PRIO_MASK 0xe000 /* Priority Code Point */
6964 #define VLAN_PRIO_SHIFT 13
70
-#define VLAN_CFI_MASK 0x1000 /* Canonical Format Indicator */
71
-#define VLAN_TAG_PRESENT VLAN_CFI_MASK
65
+#define VLAN_CFI_MASK 0x1000 /* Canonical Format Indicator / Drop Eligible Indicator */
7266 #define VLAN_VID_MASK 0x0fff /* VLAN Identifier */
7367 #define VLAN_N_VID 4096
7468
....@@ -80,10 +74,11 @@
8074 return dev->priv_flags & IFF_802_1Q_VLAN;
8175 }
8276
83
-#define skb_vlan_tag_present(__skb) ((__skb)->vlan_tci & VLAN_TAG_PRESENT)
84
-#define skb_vlan_tag_get(__skb) ((__skb)->vlan_tci & ~VLAN_TAG_PRESENT)
77
+#define skb_vlan_tag_present(__skb) ((__skb)->vlan_present)
78
+#define skb_vlan_tag_get(__skb) ((__skb)->vlan_tci)
8579 #define skb_vlan_tag_get_id(__skb) ((__skb)->vlan_tci & VLAN_VID_MASK)
86
-#define skb_vlan_tag_get_prio(__skb) ((__skb)->vlan_tci & VLAN_PRIO_MASK)
80
+#define skb_vlan_tag_get_cfi(__skb) (!!((__skb)->vlan_tci & VLAN_CFI_MASK))
81
+#define skb_vlan_tag_get_prio(__skb) (((__skb)->vlan_tci & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT)
8782
8883 static inline int vlan_get_rx_ctag_filter_info(struct net_device *dev)
8984 {
....@@ -135,6 +130,9 @@
135130
136131 extern struct net_device *__vlan_find_dev_deep_rcu(struct net_device *real_dev,
137132 __be16 vlan_proto, u16 vlan_id);
133
+extern int vlan_for_each(struct net_device *dev,
134
+ int (*action)(struct net_device *dev, int vid,
135
+ void *arg), void *arg);
138136 extern struct net_device *vlan_dev_real_dev(const struct net_device *dev);
139137 extern u16 vlan_dev_vlan_id(const struct net_device *dev);
140138 extern __be16 vlan_dev_vlan_proto(const struct net_device *dev);
....@@ -186,7 +184,6 @@
186184 #ifdef CONFIG_NET_POLL_CONTROLLER
187185 struct netpoll *netpoll;
188186 #endif
189
- unsigned int nest_level;
190187 };
191188
192189 static inline struct vlan_dev_priv *vlan_dev_priv(const struct net_device *dev)
....@@ -225,17 +222,20 @@
225222
226223 extern bool vlan_uses_dev(const struct net_device *dev);
227224
228
-static inline int vlan_get_encap_level(struct net_device *dev)
229
-{
230
- BUG_ON(!is_vlan_dev(dev));
231
- return vlan_dev_priv(dev)->nest_level;
232
-}
233225 #else
234226 static inline struct net_device *
235227 __vlan_find_dev_deep_rcu(struct net_device *real_dev,
236228 __be16 vlan_proto, u16 vlan_id)
237229 {
238230 return NULL;
231
+}
232
+
233
+static inline int
234
+vlan_for_each(struct net_device *dev,
235
+ int (*action)(struct net_device *dev, int vid, void *arg),
236
+ void *arg)
237
+{
238
+ return 0;
239239 }
240240
241241 static inline struct net_device *vlan_dev_real_dev(const struct net_device *dev)
....@@ -290,11 +290,6 @@
290290 static inline bool vlan_uses_dev(const struct net_device *dev)
291291 {
292292 return false;
293
-}
294
-static inline int vlan_get_encap_level(struct net_device *dev)
295
-{
296
- BUG();
297
- return 0;
298293 }
299294 #endif
300295
....@@ -463,6 +458,31 @@
463458 return skb;
464459 }
465460
461
+/**
462
+ * __vlan_hwaccel_clear_tag - clear hardware accelerated VLAN info
463
+ * @skb: skbuff to clear
464
+ *
465
+ * Clears the VLAN information from @skb
466
+ */
467
+static inline void __vlan_hwaccel_clear_tag(struct sk_buff *skb)
468
+{
469
+ skb->vlan_present = 0;
470
+}
471
+
472
+/**
473
+ * __vlan_hwaccel_copy_tag - copy hardware accelerated VLAN info from another skb
474
+ * @dst: skbuff to copy to
475
+ * @src: skbuff to copy from
476
+ *
477
+ * Copies VLAN information from @src to @dst (for branchless code)
478
+ */
479
+static inline void __vlan_hwaccel_copy_tag(struct sk_buff *dst, const struct sk_buff *src)
480
+{
481
+ dst->vlan_present = src->vlan_present;
482
+ dst->vlan_proto = src->vlan_proto;
483
+ dst->vlan_tci = src->vlan_tci;
484
+}
485
+
466486 /*
467487 * __vlan_hwaccel_push_inside - pushes vlan tag to the payload
468488 * @skb: skbuff to tag
....@@ -477,7 +497,7 @@
477497 skb = vlan_insert_tag_set_proto(skb, skb->vlan_proto,
478498 skb_vlan_tag_get(skb));
479499 if (likely(skb))
480
- skb->vlan_tci = 0;
500
+ __vlan_hwaccel_clear_tag(skb);
481501 return skb;
482502 }
483503
....@@ -493,7 +513,8 @@
493513 __be16 vlan_proto, u16 vlan_tci)
494514 {
495515 skb->vlan_proto = vlan_proto;
496
- skb->vlan_tci = VLAN_TAG_PRESENT | vlan_tci;
516
+ skb->vlan_tci = vlan_tci;
517
+ skb->vlan_present = 1;
497518 }
498519
499520 /**
....@@ -532,8 +553,6 @@
532553 return -EINVAL;
533554 }
534555 }
535
-
536
-#define HAVE_VLAN_GET_TAG
537556
538557 /**
539558 * vlan_get_tag - get the VLAN ID from the skb
....@@ -607,6 +626,23 @@
607626 return __vlan_get_protocol(skb, skb->protocol, NULL);
608627 }
609628
629
+/* This version of __vlan_get_protocol() also pulls mac header in skb->head */
630
+static inline __be16 vlan_get_protocol_and_depth(struct sk_buff *skb,
631
+ __be16 type, int *depth)
632
+{
633
+ int maclen;
634
+
635
+ type = __vlan_get_protocol(skb, type, &maclen);
636
+
637
+ if (type) {
638
+ if (!pskb_may_pull(skb, maclen))
639
+ type = 0;
640
+ else if (depth)
641
+ *depth = maclen;
642
+ }
643
+ return type;
644
+}
645
+
610646 /* A getter for the SKB protocol field which will handle VLAN tags consistently
611647 * whether VLAN acceleration is enabled or not.
612648 */