1010#define VLAN_MAX_DEPTH 10
1111#include "../common/parsing_helpers.h"
1212
13+ #if 0
1314#define VLAN_VID_MASK 0x0fff /* VLAN Identifier */
14- struct vlans {
15+ struct collect_vlans {
1516 __u16 id [VLAN_MAX_DEPTH ];
1617};
18+ #endif
1719
20+ #if 0 /* moved to parsing_helpers.h */
1821/* Based on parse_ethhdr() */
1922static __always_inline int __parse_ethhdr_vlan (struct hdr_cursor * nh ,
2023 void * data_end ,
2124 struct ethhdr * * ethhdr ,
22- struct vlans * vlans )
25+ struct collect_vlans * vlans )
2326{
2427 struct ethhdr * eth = nh -> pos ;
2528 int hdrsize = sizeof (* eth );
@@ -51,14 +54,16 @@ static __always_inline int __parse_ethhdr_vlan(struct hdr_cursor *nh,
5154
5255 h_proto = vlh -> h_vlan_encapsulated_proto ;
5356 if (vlans ) {
54- vlans -> id [i ] = vlh -> h_vlan_TCI & VLAN_VID_MASK ;
57+ vlans -> id [i ] =
58+ bpf_ntohs (vlh -> h_vlan_TCI ) & VLAN_VID_MASK ;
5559 }
5660 vlh ++ ;
5761 }
5862
5963 nh -> pos = vlh ;
6064 return h_proto ; /* network-byte-order */
6165}
66+ #endif
6267
6368SEC ("xdp_vlan02" )
6469int xdp_vlan_02 (struct xdp_md * ctx )
@@ -71,13 +76,17 @@ int xdp_vlan_02(struct xdp_md *ctx)
7176 int eth_type ;
7277 nh .pos = data ;
7378
74- struct vlans vlans ;
79+ struct collect_vlans vlans ;
7580
7681 struct ethhdr * eth ;
77- eth_type = __parse_ethhdr_vlan (& nh , data_end , & eth , & vlans );
7882
83+ eth_type = parse_ethhdr_vlan (& nh , data_end , & eth , & vlans );
7984 if (eth_type < 0 )
8085 return XDP_ABORTED ;
86+ /* The eth_type have skipped VLAN-types, but collected VLAN ids. The
87+ * eth ptr still points to Ethernet header, thus to check if this is a
88+ * VLAN packet do proto_is_vlan(eth->h_proto).
89+ */
8190
8291 /* The LLVM compiler is very clever, it sees that program only access
8392 * 2nd "inner" vlan (array index 1), and only does loop unroll of 2, and
@@ -112,7 +121,7 @@ int xdp_vlan_02(struct xdp_md *ctx)
112121 }
113122#endif
114123 /* Hint: to inspect BPF byte-code run:
115- * llvm-objdump -S xdp_vlan02_kern.o
124+ * llvm-objdump --no-show-raw-insn - S xdp_vlan02_kern.o
116125 */
117126 return XDP_PASS ;
118127}
0 commit comments