patches and low-level development discussion
 help / color / mirror / code / Atom feed
blob f9bcbf48a230bd374d1035a0f9da8d04dc301505 1240 bytes (raw)
name: tools/xdp-forwarder/helpers.h 	 # note: path name is non-authoritative(*)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
 
/* SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) */
/* SPDX-FileCopyrightText: 2021 The xdp-tutorial Authors */
// SPDX-FileCopyrightText: 2025 Yureka Lilian <yureka@cyberchaos.dev>
// SPDX-FileCopyrightText: 2025 Demi Marie Obenour <demiobenour@gmail.com>
/*
 * This file contains a helper for validating a VLAN tag,
 * as well as structs used by both BPF programs.
 */

#ifndef HELPERS_H
#define HELPERS_H

#include <linux/bpf.h>
#include <bpf/bpf_endian.h>
#include <bpf/bpf_helpers.h>

#define VLAN_ETHTYPE    0x8100 /* Ethertype for tagged frames */

struct ethhdr {
	struct {
		__u8 destination_mac[6];
		__u8 source_mac[6];
	} mac_addresses;
	__be16 h_proto;
};

struct vlan_hdr {
	__be16 h_vlan_TCI;
	__be16 h_vlan_encapsulated_proto;
};

struct maybe_tagged_ethhdr {
	union {
		struct {
			struct ethhdr eth;
			struct vlan_hdr vlan;
		} tagged;
		struct {
			struct vlan_hdr pad;
			struct ethhdr eth;
		} untagged;
	};
};

// The router doesn't support the PCP and DEI bits
// and they are not part of the VLAN tag.
// Therefore, ensure they are unset.
// Also reject VLAN 0, which is reserved.
static __always_inline bool vlan_tag_is_valid(__u32 tag)
{
	return tag >= 1 && tag <= 0x0FFF;
}

#endif /* HELPERS_H */

debug log:

solving f9bcbf48a230bd374d1035a0f9da8d04dc301505 ...
found f9bcbf48a230bd374d1035a0f9da8d04dc301505 in https://inbox.spectrum-os.org/spectrum-devel/20251021-fix-forwarder-build-v4-2-b978718c004d@gmail.com/ ||
	https://inbox.spectrum-os.org/spectrum-devel/20251008-fix-forwarder-build-v3-1-a93e5156fb6a@gmail.com/

applying [1/1] https://inbox.spectrum-os.org/spectrum-devel/20251021-fix-forwarder-build-v4-2-b978718c004d@gmail.com/
diff --git a/tools/xdp-forwarder/helpers.h b/tools/xdp-forwarder/helpers.h
new file mode 100644
index 0000000000000000000000000000000000000000..f9bcbf48a230bd374d1035a0f9da8d04dc301505

Checking patch tools/xdp-forwarder/helpers.h...
Applied patch tools/xdp-forwarder/helpers.h cleanly.

skipping https://inbox.spectrum-os.org/spectrum-devel/20251008-fix-forwarder-build-v3-1-a93e5156fb6a@gmail.com/ for f9bcbf48a230bd374d1035a0f9da8d04dc301505
index at:
100644 f9bcbf48a230bd374d1035a0f9da8d04dc301505	tools/xdp-forwarder/helpers.h

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://spectrum-os.org/git/crosvm
	https://spectrum-os.org/git/doc
	https://spectrum-os.org/git/mktuntap
	https://spectrum-os.org/git/nixpkgs
	https://spectrum-os.org/git/spectrum
	https://spectrum-os.org/git/ucspi-vsock
	https://spectrum-os.org/git/www

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).