patches and low-level development discussion
 help / color / mirror / code / Atom feed
blob 0fdf0a8c3b09cc34d325b7a71f915b4f39e3bd86 1624 bytes (raw)
name: tools/xdp-forwarder/prog_physical.c 	 # 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
55
 
// SPDX-License-Identifier: EUPL-1.2+ AND (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>

#include "helpers.h"

struct {
	__uint(type, BPF_MAP_TYPE_DEVMAP);
	__type(key, int);
	__type(value, int);
	__uint(max_entries, 1);
	__uint(pinning, LIBBPF_PIN_BY_NAME);
} router_iface SEC(".maps");

static __always_inline bool vlan_tag_push(struct xdp_md *ctx, __u16 tag)
{
	struct maybe_tagged_ethhdr *hdr;

	// Add extra space at the front of the packet.
	// Doing this first avoids reloading pointers and
	// extra bounds checks later.
	if (bpf_xdp_adjust_head(ctx, -(int)sizeof(hdr->untagged.pad)))
		return false;

	hdr = (void *)(long)ctx->data;
	if (hdr + 1 > (void *)(long)ctx->data_end)
		return false;

	// Move the MAC addresses.
	// Ethertype is already in the correct position.
	__builtin_memmove(&hdr->tagged.eth.mac_addresses,
	                  &hdr->untagged.eth.mac_addresses,
	                  sizeof(hdr->tagged.eth.mac_addresses));

	// Set the VLAN ID and the Ethertype of the frame.
	hdr->tagged.vlan.h_vlan_TCI = bpf_htons((__u16)tag);
	hdr->tagged.eth.h_proto = bpf_htons(VLAN_ETHTYPE);
	return true;
}

SEC("xdp")
int physical(struct xdp_md *ctx)
{
	__u32 ingress_ifindex = ctx->ingress_ifindex;

	if (!vlan_tag_is_valid(ingress_ifindex))
		return XDP_DROP;

	if (!vlan_tag_push(ctx, (__u16)ingress_ifindex))
		return XDP_DROP;

	// Redirect to the router interface.
	return bpf_redirect_map(&router_iface, 0, 0);
}

debug log:

solving 0fdf0a8c3b09cc34d325b7a71f915b4f39e3bd86 ...
found 0fdf0a8c3b09cc34d325b7a71f915b4f39e3bd86 in https://inbox.spectrum-os.org/spectrum-devel/20251021-fix-forwarder-build-v4-2-b978718c004d@gmail.com/
retrying 2b70654ebe21cb2504e6d26ca3b93cb4b62efb0f as 2b70654ebe21cb2504e6d26ca3b93cb4b62efb0
retrying 2b70654ebe21cb2504e6d26ca3b93cb4b62efb0 as 2b70654ebe21cb2504e6d26ca3b93cb4b62efb
retrying 2b70654ebe21cb2504e6d26ca3b93cb4b62efb as 2b70654ebe21cb2504e6d26ca3b93cb4b62ef
retrying 2b70654ebe21cb2504e6d26ca3b93cb4b62ef as 2b70654ebe21cb2504e6d26ca3b93cb4b62e
retrying 2b70654ebe21cb2504e6d26ca3b93cb4b62e as 2b70654ebe21cb2504e6d26ca3b93cb4b62
retrying 2b70654ebe21cb2504e6d26ca3b93cb4b62 as 2b70654ebe21cb2504e6d26ca3b93cb4b6
retrying 2b70654ebe21cb2504e6d26ca3b93cb4b6 as 2b70654ebe21cb2504e6d26ca3b93cb4b
retrying 2b70654ebe21cb2504e6d26ca3b93cb4b as 2b70654ebe21cb2504e6d26ca3b93cb4
retrying 2b70654ebe21cb2504e6d26ca3b93cb4 as 2b70654ebe21cb2504e6d26ca3b93cb
retrying 2b70654ebe21cb2504e6d26ca3b93cb as 2b70654ebe21cb2504e6d26ca3b93c
retrying 2b70654ebe21cb2504e6d26ca3b93c as 2b70654ebe21cb2504e6d26ca3b93
retrying 2b70654ebe21cb2504e6d26ca3b93 as 2b70654ebe21cb2504e6d26ca3b9
retrying 2b70654ebe21cb2504e6d26ca3b9 as 2b70654ebe21cb2504e6d26ca3b
retrying 2b70654ebe21cb2504e6d26ca3b as 2b70654ebe21cb2504e6d26ca3
retrying 2b70654ebe21cb2504e6d26ca3 as 2b70654ebe21cb2504e6d26ca
retrying 2b70654ebe21cb2504e6d26ca as 2b70654ebe21cb2504e6d26c
retrying 2b70654ebe21cb2504e6d26c as 2b70654ebe21cb2504e6d26
retrying 2b70654ebe21cb2504e6d26 as 2b70654ebe21cb2504e6d2
retrying 2b70654ebe21cb2504e6d2 as 2b70654ebe21cb2504e6d
retrying 2b70654ebe21cb2504e6d as 2b70654ebe21cb2504e6
retrying 2b70654ebe21cb2504e6 as 2b70654ebe21cb2504e
retrying 2b70654ebe21cb2504e as 2b70654ebe21cb2504
retrying 2b70654ebe21cb2504 as 2b70654ebe21cb250
retrying 2b70654ebe21cb250 as 2b70654ebe21cb25
retrying 2b70654ebe21cb25 as 2b70654ebe21cb2
retrying 2b70654ebe21cb2 as 2b70654ebe21cb
retrying 2b70654ebe21cb as 2b70654ebe21c
retrying 2b70654ebe21c as 2b70654ebe21
retrying 2b70654ebe21 as 2b70654ebe2
retrying 2b70654ebe2 as 2b70654ebe
retrying 2b70654ebe as 2b70654eb
retrying 2b70654eb as 2b70654e
retrying 2b70654e as 2b70654
found 2b70654 in https://inbox.spectrum-os.org/spectrum-devel/20250923163519.48306-2-yureka@cyberchaos.dev/ ||
	https://inbox.spectrum-os.org/spectrum-devel/20250923132012.28013-3-yureka@cyberchaos.dev/ ||
	https://inbox.spectrum-os.org/spectrum-devel/20250924114300.100541-2-yureka@cyberchaos.dev/

applying [1/2] https://inbox.spectrum-os.org/spectrum-devel/20250923163519.48306-2-yureka@cyberchaos.dev/
diff --git a/tools/xdp-forwarder/prog_physical.c b/tools/xdp-forwarder/prog_physical.c
new file mode 100644
index 0000000..2b70654

Checking patch tools/xdp-forwarder/prog_physical.c...
Applied patch tools/xdp-forwarder/prog_physical.c cleanly.

skipping https://inbox.spectrum-os.org/spectrum-devel/20250923132012.28013-3-yureka@cyberchaos.dev/ for 2b70654
skipping https://inbox.spectrum-os.org/spectrum-devel/20250924114300.100541-2-yureka@cyberchaos.dev/ for 2b70654
index at:
100644 2b70654ebe21cb2504e6d26ca3b93cb4b62efb0f	tools/xdp-forwarder/prog_physical.c

applying [2/2] https://inbox.spectrum-os.org/spectrum-devel/20251021-fix-forwarder-build-v4-2-b978718c004d@gmail.com/
diff --git a/tools/xdp-forwarder/prog_physical.c b/tools/xdp-forwarder/prog_physical.c
index 2b70654ebe21cb2504e6d26ca3b93cb4b62efb0f..0fdf0a8c3b09cc34d325b7a71f915b4f39e3bd86 100644

Checking patch tools/xdp-forwarder/prog_physical.c...
Applied patch tools/xdp-forwarder/prog_physical.c cleanly.

index at:
100644 0fdf0a8c3b09cc34d325b7a71f915b4f39e3bd86	tools/xdp-forwarder/prog_physical.c

(*) 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).