patches and low-level development discussion
 help / color / mirror / code / Atom feed
blob 2583655a13518ec90de7b0256b2153c9adbdb3bf 1344 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
 
/* 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 parsing functions that are used in the XDP programs.
 * They handle the following:
 *
 * - Validating VLAN tags.
 * - Extracting Ethernet and VLAN headers.
 * - Moving the head of an XDP context by the size of a VLAN header.
 * - Moving the Ethernet source and destination MAC addresses by the
 *   size of a VLAN header.
 */

#ifndef HELPERS_H
#define HELPERS_H

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

#define VLAN_HDR_SIZE 4
#define MAC_ADDRESS_COMBINED_SIZE 12
#define VLAN_VID_MASK           0x0fff /* VLAN Identifier */
#define VLAN_ETHTYPE (bpf_htons(0x8100))

struct tagged_ethhdr {
	__u8 mac_addresses[MAC_ADDRESS_COMBINED_SIZE];
	__be16 h_proto;
	__be16 h_vlan_TCI;
	__be16 h_vlan_encapsulated_proto;
};

// 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 2583655a13518ec90de7b0256b2153c9adbdb3bf ...
found 2583655a13518ec90de7b0256b2153c9adbdb3bf in https://inbox.spectrum-os.org/spectrum-devel/20251006-fix-forwarder-build-v2-1-6fdd7e05cb14@gmail.com/

applying [1/1] https://inbox.spectrum-os.org/spectrum-devel/20251006-fix-forwarder-build-v2-1-6fdd7e05cb14@gmail.com/
diff --git a/tools/xdp-forwarder/helpers.h b/tools/xdp-forwarder/helpers.h
new file mode 100644
index 0000000000000000000000000000000000000000..2583655a13518ec90de7b0256b2153c9adbdb3bf

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

index at:
100644 2583655a13518ec90de7b0256b2153c9adbdb3bf	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).