xdp-tutorial icon indicating copy to clipboard operation
xdp-tutorial copied to clipboard

xdp vlan

Open onlyzaxd opened this issue 2 years ago • 1 comments

Hello

Is there any example or something that show me how to parse a specific vlan id on a interface and filter it ?

I have a interface with is having more then 1 vlan and if i load the program on it it goes crazy

I mean i found something like this but not sure how to specify the exactly vlan id

for (i = 0; i < 2; i++) {
	if (h_proto == htons(ETH_P_8021Q) || h_proto == htons(ETH_P_8021AD)) {
		struct vlan_hdr *vhdr;

		vhdr = data + nh_off;
		nh_off += sizeof(struct vlan_hdr);
		if (data + nh_off > data_end) {
			return XDP_PASS;
		}
		h_proto = vhdr->h_vlan_encapsulated_proto;
	}
}

onlyzaxd avatar Jun 22 '22 09:06 onlyzaxd

There's some example code here parsing VLAN IDs:

https://github.com/xdp-project/bpf-examples/blob/master/include/xdp/parsing_helpers.h#L120

Note that for XDP you'll have to turn off VLAN offload to be able to actually see the VLAN tags in the packet...

tohojo avatar Jun 22 '22 10:06 tohojo