From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from atuin.qyliss.net (localhost [IPv6:::1]) by atuin.qyliss.net (Postfix) with ESMTP id 1F1F6160B9; Sun, 07 Sep 2025 19:26:05 +0000 (UTC) Received: by atuin.qyliss.net (Postfix, from userid 993) id 0021A16099; Sun, 07 Sep 2025 19:26:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on atuin.qyliss.net X-Spam-Level: X-Spam-Status: No, score=-0.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DMARC_PASS,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=4.0.1 Received: from mail-yw1-x1133.google.com (mail-yw1-x1133.google.com [IPv6:2607:f8b0:4864:20::1133]) by atuin.qyliss.net (Postfix) with ESMTPS id C0D7D16096 for ; Sun, 07 Sep 2025 19:25:59 +0000 (UTC) Received: by mail-yw1-x1133.google.com with SMTP id 00721157ae682-71d603f13abso37977757b3.0 for ; Sun, 07 Sep 2025 12:25:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1757273153; x=1757877953; darn=spectrum-os.org; h=autocrypt:in-reply-to:content-language:references:to:subject:from :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=DnbypF2Rxpxkuw4eDGjSlzILgbcUUS09OIKSXFwwwL4=; b=Wjk1eYnuWvk37aKyJrBmXdG9xm9ToXS7tzNU9MVsVJbu8d/KimY1dRRR7D7gJM7taz kxchCcB89SJXCmsxTxajSLTfkFsB/W/tX267Xfp71/JUWr9LDxxU5mtbDIDQ4ouX0Nre 0Gn/NDeHyLHNOsvuqrmP0Ua9h1nwLGgpeJ4nTN6Uj3RvO/+buEOcC1GGQV19l57eP6lA VSvHQCObeX7oWAXC/d+fzT1FKzC5GkqvH0DWydHwlTpezQiPdYn08ileyYI10WtYS7r2 QkEaOOG8P4ESLib2KgVB8FE4J3lCf/RLQTMw1u7IVS0BOGjAKZ2oNBdTUuKezVISVRMH vrKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1757273153; x=1757877953; h=autocrypt:in-reply-to:content-language:references:to:subject:from :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=DnbypF2Rxpxkuw4eDGjSlzILgbcUUS09OIKSXFwwwL4=; b=DBFkxyQT24pDeTT7U9IQQi+ZXrjcFCuXnqVLvUswMWdB5aMcLTUc01YJ1kyByJoazE GQL/IBFSYQntXwD5j9vhvWXtfIxyNdeqf10HR09z5I+i44jXcYrpKsUoWHPp/Q4Bd/jr a1EMePHk13+qaI1Evqj9I1vQcKzCoGBcGB1y3Zt2ocgIlsVYgmAAbNrQbwv1FP/UQJvQ z0OWyh+J2hZwnWlLgA6KPxuMsWfcbm70y+KJIE2MYRFsP2ezrO/bg3/3j2oVEnQfFXIR 52T6zDEwJVazWeeVKb5yeTCswZV7gyUzTmARe8wPCOb8c8YRg1Me8RExuImG/QlQGgHV ZfFw== X-Forwarded-Encrypted: i=1; AJvYcCVdCcR+75i/gHQ1Ej4we+7MCvpfCLaImgl8iMm13daHfZ1kCfbePC2U2MR6oAIO3USU61Raxw==@spectrum-os.org X-Gm-Message-State: AOJu0YwtJy9OJ1CuSf+dGSiba6DutAd2o1JBIIatAu+yrpmXZFaECIaI J7AsnoAtsZDes3viKHc0pdnZdOHjN8Ypb2EckcPPV7p5D1Gt/tAaNhLh X-Gm-Gg: ASbGncsOh5YLINgO1rFqCriEo1Lk8pNlh1TvOQA6jpsp1gioeASaQJxennsBVMCva1K QZnkkZ9jBVap9c1l/UnSXFYIWRONabfyBFYsd0Ru7tlUMlT4RXwnrbIJsuvpn9KIPfKseUciHaM j9DJtktuzkcVGA2ZKtsEl6nhu+fowaPlFOZDRGqXvlHE3nfrc6juMZu1tqouveF/UhykfhjXaS4 0u0nDraiUDPzDCTjcK/PI8UIQyrZKmUaiDbj7+spDvXbYn/DjqT5EQ6WlFBRfXi+LeJ6X6MgtmE PxVENo0yvuxdKaV6wc6xv+2NmgzGxt0a5nP/uJ/ihcU+qZadOMokDezvPZHZjvrWVj4+4eQfous dhYzFRwG3C51tShhhnzxAKNtgR4JJ5qidUbbPhgYFYnfOgS9g4M/xjnaJx8lIGG/OtrGwMcU89i Cj7LS2etl8Pu3J5/Yz/TTlYsfc/Th5fIhguLoFR/YHsFrKXQ== X-Google-Smtp-Source: AGHT+IGWMluJW63fIoooumUV2C9bduDBJSiQ+jFotKnG1sQqswZlhvgSJ+/KCRNkkLcnTJxwsn2Yeg== X-Received: by 2002:a05:690c:6813:b0:721:5aa1:8fe5 with SMTP id 00721157ae682-727f2bcef7bmr50747037b3.4.1757273152965; Sun, 07 Sep 2025 12:25:52 -0700 (PDT) Received: from [10.138.34.110] (h96-60-249-169.cncrtn.broadband.dynamic.tds.net. [96.60.249.169]) by smtp.gmail.com with ESMTPSA id 00721157ae682-726895f4ba8sm20083037b3.13.2025.09.07.12.25.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 07 Sep 2025 12:25:52 -0700 (PDT) Message-ID: Date: Sun, 7 Sep 2025 15:25:43 -0400 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Demi Marie Obenour Subject: Re: [PATCH] tools: add xdp-forwarder To: Yureka Lilian , devel@spectrum-os.org References: <20250906141228.2357630-1-yureka@cyberchaos.dev> Content-Language: en-US In-Reply-To: <20250906141228.2357630-1-yureka@cyberchaos.dev> Autocrypt: addr=demiobenour@gmail.com; keydata= xsFNBFp+A0oBEADffj6anl9/BHhUSxGTICeVl2tob7hPDdhHNgPR4C8xlYt5q49yB+l2nipd aq+4Gk6FZfqC825TKl7eRpUjMriwle4r3R0ydSIGcy4M6eb0IcxmuPYfbWpr/si88QKgyGSV Z7GeNW1UnzTdhYHuFlk8dBSmB1fzhEYEk0RcJqg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CZNj65B/nkDOvodSiwfwjjVVE2V3iEzxMHbgyTCGA67+Bo/d5aQGj gn0TPtsGzelyQHipaUzEyrsceUGWYoKXYyVWKEfyh0cDfnd9diAm3VeNqchtcMpoehETH8fr RHnJdBcjf112PzQSdKC6kqU0Q196c4Vp5HDOQfNiDnTf7gZSj0BraHOByy9LEDCLhQiCmr+2 E0rW4tBtDAn2HkT9uf32ZGqJCn1O+2uVfFhGu6vPE5qkqrbSE8TG+03H8ecU2q50zgHWPdHM OBvy3EhzfAh2VmOSTcRK+tSUe/u3wdLRDPwv/DTzGI36Kgky9MsDC5gpIwNbOJP2G/q1wT1o Gkw4IXfWv2ufWiXqJ+k7HEi2N1sree7Dy9KBCqb+ca1vFhYPDJfhP75I/VnzHVssZ/rYZ9+5 1yDoUABoNdJNSGUYl+Yh9Pw9pE3Kt4EFzUlFZWbE4xKL/NPno+z4J9aWemLLszcYz/u3XnbO vUSQHSrmfOzX3cV4yfmjM5lewgSstoxGyTx2M8enslgdXhPthZlDnTnOT+C+OTsh8+m5tos8 HQjaPM01MKBiAqdPgksm1wu2DrrwUi6ChRVTUBcj6+/9IJ81H2P2gJk3Ls3AVIxIffLoY34E +MYSfkEjBz0E8CLOcAw7JIwAaeBT Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="------------Vbm80JtUv08s3L0hyWBMw06m" Message-ID-Hash: OG3NKBJBVYRRTA7NTRIUN7OCF2BR6BLG X-Message-ID-Hash: OG3NKBJBVYRRTA7NTRIUN7OCF2BR6BLG X-MailFrom: demiobenour@gmail.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-devel.spectrum-os.org-0; header-match-devel.spectrum-os.org-1; header-match-devel.spectrum-os.org-2; header-match-devel.spectrum-os.org-3; header-match-devel.spectrum-os.org-4; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.9 Precedence: list List-Id: Patches and low-level development discussion Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --------------Vbm80JtUv08s3L0hyWBMw06m Content-Type: multipart/mixed; boundary="------------C1h8EYlLDCgA0Hs0YVYo8ZQd"; protected-headers="v1" From: Demi Marie Obenour To: Yureka Lilian , devel@spectrum-os.org Message-ID: Subject: Re: [PATCH] tools: add xdp-forwarder References: <20250906141228.2357630-1-yureka@cyberchaos.dev> In-Reply-To: <20250906141228.2357630-1-yureka@cyberchaos.dev> --------------C1h8EYlLDCgA0Hs0YVYo8ZQd Content-Type: multipart/mixed; boundary="------------cuDSPXQTCy2C1SIB0IrQEQVx" --------------cuDSPXQTCy2C1SIB0IrQEQVx Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 9/6/25 10:12, Yureka Lilian wrote: > The xdp-forwarder's purpose is implementing the functionality needed > within the net-vm (a VM running the Linux drivers for any physical > interfaces on the spectrum system). >=20 > In the future, the net-vm will load the included XDP programs on the > passed-through physical interfaces as well as the downstream virtio > interface going into the router (recognized by its special MAC address)= =2E >=20 > The net-vm needs to multiplex between the physical interfaces, as there= > might be several interfaces in the same IOMMU-group. >=20 > For this, the XDP program loaded on the physical interfaces > (`prog_physical.o`) applies a VLAN tag corresponding to the interface i= d > and redirects the packets to the router interface (identified by the > `router_iface` bpf map). In the other direction the XDP program loaded = on > the router interface (`prog_router.o`) removes one layer of VLAN taggin= g > and redirects the packets to the interface read from the VLAN tag. >=20 > The helper program `set_router_iface` is used to update the `router_ifa= ce` > bpf map to point to the interface passed as argument to the program. >=20 > Signed-off-by: Yureka Lilian > --- > pkgs/default.nix | 5 + > tools/default.nix | 15 +- > tools/meson.build | 5 + > tools/meson_options.txt | 4 + > tools/xdp-forwarder/include/parsing_helpers.h | 273 ++++++++++++++++++= > tools/xdp-forwarder/include/rewrite_helpers.h | 145 ++++++++++ > tools/xdp-forwarder/meson.build | 38 +++ > tools/xdp-forwarder/prog_physical.c | 37 +++ > tools/xdp-forwarder/prog_router.c | 43 +++ > tools/xdp-forwarder/set_router_iface.c | 29 ++ > 10 files changed, 591 insertions(+), 3 deletions(-) > create mode 100644 tools/xdp-forwarder/include/parsing_helpers.h > create mode 100644 tools/xdp-forwarder/include/rewrite_helpers.h > create mode 100644 tools/xdp-forwarder/meson.build > create mode 100644 tools/xdp-forwarder/prog_physical.c > create mode 100644 tools/xdp-forwarder/prog_router.c > create mode 100644 tools/xdp-forwarder/set_router_iface.c >=20 > diff --git a/pkgs/default.nix b/pkgs/default.nix > index 3b81339..76b2a5c 100644 > --- a/pkgs/default.nix > +++ b/pkgs/default.nix > @@ -1,4 +1,5 @@ > # SPDX-FileCopyrightText: 2023-2024 Alyssa Ross > +# SPDX-FileCopyrightText: 2025 Yureka Lilian > # SPDX-License-Identifier: MIT > =20 > { ... } @ args: > @@ -42,6 +43,10 @@ let > guestSupport =3D false; > hostSupport =3D true; > }; > + spectrum-driver-tools =3D self.callSpectrumPackage ../tools { > + guestSupport =3D false; > + driverSupport =3D true; > + }; > xdg-desktop-portal-spectrum-host =3D > self.callSpectrumPackage ../tools/xdg-desktop-portal-spectrum-ho= st {}; > =20 > diff --git a/tools/default.nix b/tools/default.nix > index 95d76a1..e664f47 100644 > --- a/tools/default.nix > +++ b/tools/default.nix > @@ -1,13 +1,16 @@ > # SPDX-License-Identifier: MIT > # SPDX-FileCopyrightText: 2022-2025 Alyssa Ross > +# SPDX-FileCopyrightText: 2025 Yureka Lilian > =20 > import ../lib/call-package.nix ( > { src, lib, stdenv, fetchCrate, fetchurl, runCommand, buildPackages > , meson, ninja, pkg-config, rustc > , clang-tools, clippy > , dbus > +, clang, libbpf > , guestSupport ? true > , hostSupport ? false > +, driverSupport ? false > }: > =20 > let > @@ -70,15 +73,18 @@ stdenv.mkDerivation (finalAttrs: { > ./lsvm > ./start-vmm > ./subprojects > + ] ++ lib.optionals driverSupport [ > + ./xdp-forwarder > ])); > }; > sourceRoot =3D "source/tools"; > =20 > depsBuildBuild =3D lib.optionals hostSupport [ buildPackages.stdenv.= cc ]; > nativeBuildInputs =3D [ meson ninja ] > - ++ lib.optionals guestSupport [ pkg-config ] > - ++ lib.optionals hostSupport [ rustc ]; > - buildInputs =3D lib.optionals guestSupport [ dbus ]; > + ++ lib.optionals (guestSupport || driverSupport) [ pkg-config ] > + ++ lib.optionals hostSupport [ rustc ] > + ++ lib.optionals driverSupport [ clang ]; > + buildInputs =3D lib.optionals guestSupport [ dbus ] ++ lib.optionals= driverSupport [ libbpf ]; > =20 > postPatch =3D lib.optionals hostSupport (lib.concatMapStringsSep "\n= " (crate: '' > mkdir -p subprojects/packagecache > @@ -88,12 +94,15 @@ stdenv.mkDerivation (finalAttrs: { > mesonFlags =3D [ > (lib.mesonBool "guest" guestSupport) > (lib.mesonBool "host" hostSupport) > + (lib.mesonBool "driver" driverSupport) > "-Dhostfsrootdir=3D/run/virtiofs/virtiofs0" > "-Dtests=3Dfalse" > "-Dunwind=3Dfalse" > "-Dwerror=3Dtrue" > ]; > =20 > + hardeningDisable =3D lib.optionals driverSupport [ "zerocallusedregs= " ]; > + > passthru.tests =3D { > clang-tidy =3D finalAttrs.finalPackage.overrideAttrs ( > { name, src, nativeBuildInputs ? [], ... }: > diff --git a/tools/meson.build b/tools/meson.build > index 9cebd03..e49f27c 100644 > --- a/tools/meson.build > +++ b/tools/meson.build > @@ -1,5 +1,6 @@ > # SPDX-License-Identifier: EUPL-1.2+ > # SPDX-FileCopyrightText: 2024 Alyssa Ross > +# SPDX-FileCopyrightText: 2025 Yureka Lilian > =20 > project('spectrum-tools', 'c', > default_options : { > @@ -26,3 +27,7 @@ endif > if get_option('guest') > subdir('xdg-desktop-portal-spectrum') > endif > + > +if get_option('driver') > + subdir('xdp-forwarder') > +endif > diff --git a/tools/meson_options.txt b/tools/meson_options.txt > index 4af0031..887e388 100644 > --- a/tools/meson_options.txt > +++ b/tools/meson_options.txt > @@ -1,5 +1,6 @@ > # SPDX-License-Identifier: EUPL-1.2+ > # SPDX-FileCopyrightText: 2022-2024 Alyssa Ross > +# SPDX-FileCopyrightText: 2025 Yureka Lilian > =20 > option('host', type : 'boolean', value : false, > description : 'Build tools for the Spectrum host') > @@ -7,6 +8,9 @@ option('host', type : 'boolean', value : false, > option('guest', type : 'boolean', > description : 'Build tools for Spectrum guests') > =20 > +option('driver', type : 'boolean', > + description : 'Build tools for Spectrum driver VMs') > + > option('hostfsrootdir', type : 'string', value : '/run/host', > description : 'Path where the virtio-fs provided by the host will be= mounted') > =20 > diff --git a/tools/xdp-forwarder/include/parsing_helpers.h b/tools/xdp-= forwarder/include/parsing_helpers.h > new file mode 100644 > index 0000000..3d240cd > --- /dev/null > +++ b/tools/xdp-forwarder/include/parsing_helpers.h > @@ -0,0 +1,273 @@ > +/* SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-clause) */ > +/* Vendored from https://github.com/xdp-project/xdp-tutorial/blob/d3d3= eed6ea9a63d1302bfa8b5a8e93862bfe11f0/common/parsing_helpers.h */ > +/* > + * This file contains parsing functions that are used in the packetXX = XDP > + * programs. The functions are marked as __always_inline, and fully de= fined in > + * this header file to be included in the BPF program. > + * > + * Each helper parses a packet header, including doing bounds checking= , and > + * returns the type of its contents if successful, and -1 otherwise. > + * > + * For Ethernet and IP headers, the content type is the type of the pa= yload > + * (h_proto for Ethernet, nexthdr for IPv6), for ICMP it is the ICMP t= ype field. > + * All return values are in host byte order. > + * > + * The versions of the functions included here are slightly expanded v= ersions of > + * the functions in the packet01 lesson. For instance, the Ethernet he= ader > + * parsing has support for parsing VLAN tags. > + */ > + > +#ifndef __PARSING_HELPERS_H > +#define __PARSING_HELPERS_H > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +/* Header cursor to keep track of current parsing position */ > +struct hdr_cursor { > + void *pos; > +}; > + > +/* > + * struct vlan_hdr - vlan header > + * @h_vlan_TCI: priority and VLAN ID > + * @h_vlan_encapsulated_proto: packet type ID or len > + */ > +struct vlan_hdr { > + __be16 h_vlan_TCI; > + __be16 h_vlan_encapsulated_proto; > +}; > + > +/* > + * Struct icmphdr_common represents the common part of the icmphdr and= icmp6hdr > + * structures. > + */ > +struct icmphdr_common { > + __u8 type; > + __u8 code; > + __sum16 cksum; > +}; > + > +/* Allow users of header file to redefine VLAN max depth */ > +#ifndef VLAN_MAX_DEPTH > +#define VLAN_MAX_DEPTH 2 > +#endif > + > +#define VLAN_VID_MASK 0x0fff /* VLAN Identifier */ > +/* Struct for collecting VLANs after parsing via parse_ethhdr_vlan */ > +struct collect_vlans { > + __u16 id[VLAN_MAX_DEPTH]; > +}; > + > +static __always_inline int proto_is_vlan(__u16 h_proto) > +{ > + return !!(h_proto =3D=3D bpf_htons(ETH_P_8021Q) || > + h_proto =3D=3D bpf_htons(ETH_P_8021AD)); > +} > + > +/* Notice, parse_ethhdr() will skip VLAN tags, by advancing nh->pos an= d returns > + * next header EtherType, BUT the ethhdr pointer supplied still points= to the > + * Ethernet header. Thus, caller can look at eth->h_proto to see if th= is was a > + * VLAN tagged packet. > + */ > +static __always_inline int parse_ethhdr_vlan(struct hdr_cursor *nh, > + void *data_end, > + struct ethhdr **ethhdr, > + struct collect_vlans *vla= ns) > +{ > + struct ethhdr *eth =3D nh->pos; > + int hdrsize =3D sizeof(*eth); > + struct vlan_hdr *vlh; > + __u16 h_proto; > + int i; > + > + /* Byte-count bounds check; check if current pointer + size of header= > + * is after data_end. > + */ > + if (nh->pos + hdrsize > data_end) > + return -1; > + > + nh->pos +=3D hdrsize; > + *ethhdr =3D eth; > + vlh =3D nh->pos; > + h_proto =3D eth->h_proto; > + > + /* Use loop unrolling to avoid the verifier restriction on loops; > + * support up to VLAN_MAX_DEPTH layers of VLAN encapsulation. > + */ > + #pragma unroll > + for (i =3D 0; i < VLAN_MAX_DEPTH; i++) { > + if (!proto_is_vlan(h_proto)) > + break; > + > + if (vlh + 1 > data_end) > + break; > + > + h_proto =3D vlh->h_vlan_encapsulated_proto; > + if (vlans) /* collect VLAN ids */ > + vlans->id[i] =3D > + (bpf_ntohs(vlh->h_vlan_TCI) & VLAN_VID_MASK); > + > + vlh++; > + } > + > + nh->pos =3D vlh; > + return h_proto; /* network-byte-order */ > +} > + > +static __always_inline int parse_ethhdr(struct hdr_cursor *nh, > + void *data_end, > + struct ethhdr **ethhdr) > +{ > + /* Expect compiler removes the code that collects VLAN ids */ > + return parse_ethhdr_vlan(nh, data_end, ethhdr, NULL); > +} > + > +static __always_inline int parse_ip6hdr(struct hdr_cursor *nh, > + void *data_end, > + struct ipv6hdr **ip6hdr) > +{ > + struct ipv6hdr *ip6h =3D nh->pos; > + > + /* Pointer-arithmetic bounds check; pointer +1 points to after end of= > + * thing being pointed to. We will be using this style in the remaind= er > + * of the tutorial. > + */ > + if (ip6h + 1 > data_end) > + return -1; > + > + nh->pos =3D ip6h + 1; > + *ip6hdr =3D ip6h; > + > + return ip6h->nexthdr; > +} > + > +static __always_inline int parse_iphdr(struct hdr_cursor *nh, > + void *data_end, > + struct iphdr **iphdr) > +{ > + struct iphdr *iph =3D nh->pos; > + int hdrsize; > + > + if (iph + 1 > data_end) > + return -1; > + > + hdrsize =3D iph->ihl * 4; > + /* Sanity check packet field is valid */ > + if(hdrsize < sizeof(*iph)) > + return -1; > + > + /* Variable-length IPv4 header, need to use byte-based arithmetic */ > + if (nh->pos + hdrsize > data_end) > + return -1; > + > + nh->pos +=3D hdrsize; > + *iphdr =3D iph; > + > + return iph->protocol; > +} > + > +static __always_inline int parse_icmp6hdr(struct hdr_cursor *nh, > + void *data_end, > + struct icmp6hdr **icmp6hdr) > +{ > + struct icmp6hdr *icmp6h =3D nh->pos; > + > + if (icmp6h + 1 > data_end) > + return -1; > + > + nh->pos =3D icmp6h + 1; > + *icmp6hdr =3D icmp6h; > + > + return icmp6h->icmp6_type; > +} > + > +static __always_inline int parse_icmphdr(struct hdr_cursor *nh, > + void *data_end, > + struct icmphdr **icmphdr) > +{ > + struct icmphdr *icmph =3D nh->pos; > + > + if (icmph + 1 > data_end) > + return -1; > + > + nh->pos =3D icmph + 1; > + *icmphdr =3D icmph; > + > + return icmph->type; > +} > + > +static __always_inline int parse_icmphdr_common(struct hdr_cursor *nh,= > + void *data_end, > + struct icmphdr_common = **icmphdr) > +{ > + struct icmphdr_common *h =3D nh->pos; > + > + if (h + 1 > data_end) > + return -1; > + > + nh->pos =3D h + 1; > + *icmphdr =3D h; > + > + return h->type; > +} > + > +/* > + * parse_udphdr: parse the udp header and return the length of the udp= payload > + */ > +static __always_inline int parse_udphdr(struct hdr_cursor *nh, > + void *data_end, > + struct udphdr **udphdr) > +{ > + int len; > + struct udphdr *h =3D nh->pos; > + > + if (h + 1 > data_end) > + return -1; > + > + nh->pos =3D h + 1; > + *udphdr =3D h; > + > + len =3D bpf_ntohs(h->len) - sizeof(struct udphdr); > + if (len < 0) > + return -1; > + > + return len; > +} > + > +/* > + * parse_tcphdr: parse and return the length of the tcp header > + */ > +static __always_inline int parse_tcphdr(struct hdr_cursor *nh, > + void *data_end, > + struct tcphdr **tcphdr) > +{ > + int len; > + struct tcphdr *h =3D nh->pos; > + > + if (h + 1 > data_end) > + return -1; > + > + len =3D h->doff * 4; > + /* Sanity check packet field is valid */ > + if(len < sizeof(*h)) > + return -1; > + > + /* Variable-length TCP header, need to use byte-based arithmetic */ > + if (nh->pos + len > data_end) > + return -1; > + > + nh->pos +=3D len; > + *tcphdr =3D h; > + > + return len; > +} > + > +#endif /* __PARSING_HELPERS_H */ > diff --git a/tools/xdp-forwarder/include/rewrite_helpers.h b/tools/xdp-= forwarder/include/rewrite_helpers.h > new file mode 100644 > index 0000000..2deae9a > --- /dev/null > +++ b/tools/xdp-forwarder/include/rewrite_helpers.h > @@ -0,0 +1,145 @@ > +/* SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-clause) */ > +/* Vendored from https://github.com/xdp-project/xdp-tutorial/blob/d3d3= eed6ea9a63d1302bfa8b5a8e93862bfe11f0/common/rewrite_helpers.h */ > +/* > + * This file contains functions that are used in the packetXX XDP prog= rams to > + * manipulate on packets data. The functions are marked as __always_in= line, and > + * fully defined in this header file to be included in the BPF program= =2E > + */ > + > +#ifndef __REWRITE_HELPERS_H > +#define __REWRITE_HELPERS_H > + > +#include > +#include > +#include > +#include > + > +#include > +#include > + > +/* Pops the outermost VLAN tag off the packet. Returns the popped VLAN= ID on > + * success or negative errno on failure. > + */ > +static __always_inline int vlan_tag_pop(struct xdp_md *ctx, struct eth= hdr *eth) > +{ > + void *data_end =3D (void *)(long)ctx->data_end; > + struct ethhdr eth_cpy; > + struct vlan_hdr *vlh; > + __be16 h_proto; > + int vlid; > + > + if (!proto_is_vlan(eth->h_proto)) > + return -1; > + > + /* Careful with the parenthesis here */ > + vlh =3D (void *)(eth + 1); > + > + /* Still need to do bounds checking */ > + if (vlh + 1 > data_end) > + return -1; > + > + /* Save vlan ID for returning, h_proto for updating Ethernet header *= / > + vlid =3D bpf_ntohs(vlh->h_vlan_TCI); > + h_proto =3D vlh->h_vlan_encapsulated_proto; > + > + /* Make a copy of the outer Ethernet header before we cut it off */ > + __builtin_memcpy(ð_cpy, eth, sizeof(eth_cpy)); > + > + /* Actually adjust the head pointer */ > + if (bpf_xdp_adjust_head(ctx, (int)sizeof(*vlh))) > + return -1; > + > + /* Need to re-evaluate data *and* data_end and do new bounds checking= > + * after adjusting head > + */ > + eth =3D (void *)(long)ctx->data; > + data_end =3D (void *)(long)ctx->data_end; > + if (eth + 1 > data_end) > + return -1; > + > + /* Copy back the old Ethernet header and update the proto type */ > + __builtin_memcpy(eth, ð_cpy, sizeof(*eth)); > + eth->h_proto =3D h_proto; > + > + return vlid; > +} In Spectrum, eth is always the packet data, so this should be able to be simplified to: /* Pops the outermost VLAN tag off the packet. Returns the popped VLAN ID= on * success or negative errno on failure. */ static __always_inline int vlan_tag_pop(struct xdp_md *ctx) { char *data_end =3D (void *)(long)ctx->data_end; struct ethhdr *eth =3D (void *)(long)ctx->data; struct vlan_hdr *vlh; int vlid; /* Careful with the parenthesis here */ vlh =3D (void *)(eth + 1); /* Still need to do bounds checking */ if (vlh + 1 > data_end) return -1; if (!proto_is_vlan(eth->h_proto)) return -1; /* Save vlan ID for returning */ vlid =3D bpf_ntohs(vlh->h_vlan_TCI); /* Move the source and destination MAC addresses */ __builtin_memmove(data + sizeof(*vlh), data, offsetof(struct ethhdr, h_proto)); /* Actually adjust the head pointer */ if (bpf_xdp_adjust_head(ctx, (int)sizeof(*vlh))) return -1; return vlid; } > +/* Pushes a new VLAN tag after the Ethernet header. Returns 0 on succe= ss, > + * -1 on failure. > + */ > +static __always_inline int vlan_tag_push(struct xdp_md *ctx, > + struct ethhdr *eth, int vlid)= > +{ > + void *data_end =3D (void *)(long)ctx->data_end; > + struct ethhdr eth_cpy; > + struct vlan_hdr *vlh; > + > + /* First copy the original Ethernet header */ > + __builtin_memcpy(ð_cpy, eth, sizeof(eth_cpy)); > + > + /* Then add space in front of the packet */ > + if (bpf_xdp_adjust_head(ctx, 0 - (int)sizeof(*vlh))) > + return -1; > + > + /* Need to re-evaluate data_end and data after head adjustment, and > + * bounds check, even though we know there is enough space (as we > + * increased it). > + */ > + data_end =3D (void *)(long)ctx->data_end; > + eth =3D (void *)(long)ctx->data; > + > + if (eth + 1 > data_end) > + return -1; > + > + /* Copy back Ethernet header in the right place, populate VLAN tag wi= th > + * ID and proto, and set outer Ethernet header to VLAN type. > + */ > + __builtin_memcpy(eth, ð_cpy, sizeof(*eth)); > + > + vlh =3D (void *)(eth + 1); > + > + if (vlh + 1 > data_end) > + return -1; > + > + vlh->h_vlan_TCI =3D bpf_htons(vlid); > + vlh->h_vlan_encapsulated_proto =3D eth->h_proto; > + > + eth->h_proto =3D bpf_htons(ETH_P_8021Q); > + return 0; > +} In the Spectrum use-case (where the Ethernet header is always the one in the packet) this should be able to be simplified to (not tested): /* Pushes a new VLAN tag after the Ethernet header. Returns 0 on success,= * -1 on failure. */ static __always_inline int vlan_tag_push(struct xdp_md *ctx, int vlid) { struct ethhdr *eth; __u16 *h_vlan_TCI; void *data_end; /* Add space in front of the packet */ if (bpf_xdp_adjust_head(ctx, -(int)sizeof(struct vlan_hdr))) return -1; /* Need to refetch eth. Also need to bounds check even * though we know there is enough space (as we increased it). */ data_end =3D (void *)(long)ctx->data_end; eth =3D (void *)(long)ctx->data; h_vlan_TCI =3D (__u16 *)(eth + 1); if (h_vlan_TCI + 1 > data_end) return -1; /* Move source and destination MAC addresses, populate VLAN tag * with ID and proto, and set outer Ethernet header to VLAN type. */ __builtin_memmove(eth, eth + sizeof(struct vlan_hdr), offsetof(struct ethhdr, h_proto)); eth->h_proto =3D bpf_htons(ETH_P_8021Q); *h_vlan_TCI =3D bpf_htons(vlid); return 0; } This also avoids needing the 'eth' parameter, as it is now assigned in th= e function body before being read from. I'm not sure this would be > +/* > + * Swaps destination and source MAC addresses inside an Ethernet heade= r > + */ > +static __always_inline void swap_src_dst_mac(struct ethhdr *eth) > +{ > + __u8 h_tmp[ETH_ALEN]; > + > + __builtin_memcpy(h_tmp, eth->h_source, ETH_ALEN); > + __builtin_memcpy(eth->h_source, eth->h_dest, ETH_ALEN); > + __builtin_memcpy(eth->h_dest, h_tmp, ETH_ALEN); > +} > + > +/* > + * Swaps destination and source IPv6 addresses inside an IPv6 header > + */ > +static __always_inline void swap_src_dst_ipv6(struct ipv6hdr *ipv6) > +{ > + struct in6_addr tmp =3D ipv6->saddr; > + > + ipv6->saddr =3D ipv6->daddr; > + ipv6->daddr =3D tmp; > +} > + > +/* > + * Swaps destination and source IPv4 addresses inside an IPv4 header > + */ > +static __always_inline void swap_src_dst_ipv4(struct iphdr *iphdr) > +{ > + __be32 tmp =3D iphdr->saddr; > + > + iphdr->saddr =3D iphdr->daddr; > + iphdr->daddr =3D tmp; > +} > + > +#endif /* __REWRITE_HELPERS_H */ > diff --git a/tools/xdp-forwarder/meson.build b/tools/xdp-forwarder/meso= n.build > new file mode 100644 > index 0000000..7e60c11 > --- /dev/null > +++ b/tools/xdp-forwarder/meson.build > @@ -0,0 +1,38 @@ > +# SPDX-License-Identifier: EUPL-1.2+ > +# SPDX-FileCopyrightText: 2025 Yureka Lilian > + > +libbpf =3D dependency('libbpf', version : '1.6.2') > + > +executable('set_router_iface', 'set_router_iface.c', > + dependencies : libbpf, > + install : true) > + > +clang =3D find_program('clang') > + > +bpf_o_cmd =3D [ > + clang.full_path(), > + '-fno-stack-protector', > + '-O2', > + '-target', 'bpf', > + '-I', meson.current_source_dir() + '/include', > + '-g', > + '-c', > + '@INPUT@', > + '-o', > + '@OUTPUT@', > +] I recommend adding -fno-strict-overflow and -fno-strict-aliasing here. I don't know if those are implied by -target bpf, but better safe than sorry. > +prog_router_o =3D custom_target( > + input : 'prog_router.c', > + output : 'prog_router.o', > + command : bpf_o_cmd, > + install: true, > + install_dir: 'lib/xdp') > + > +prog_physical_o =3D custom_target( > + input : 'prog_physical.c', > + output : 'prog_physical.o', > + command : bpf_o_cmd, > + install: true, > + install_dir: 'lib/xdp') Meson allows providing a dependency file so that the target is remade if any of the headers are changed. Clang is able to produce such a file (-MD -MP -MF file). I also recommend compiling with lots of warnings enabled (perhaps -Wall -Wextra). > diff --git a/tools/xdp-forwarder/prog_physical.c b/tools/xdp-forwarder/= prog_physical.c > new file mode 100644 > index 0000000..04b5131 > --- /dev/null > +++ b/tools/xdp-forwarder/prog_physical.c > @@ -0,0 +1,37 @@ > +// SPDX-License-Identifier: EUPL-1.2+ > +// SPDX-FileCopyrightText: 2025 Yureka Lilian > + > +#define VLAN_MAX_DEPTH 1 > + > +#include > +#include > +#include "parsing_helpers.h" > +#include "rewrite_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"); > + > +SEC("xdp") > +int physical(struct xdp_md *ctx) > +{ > + void *data_end =3D (void *)(long)ctx->data_end; > + void *data =3D (void *)(long)ctx->data; Would it make sense to use char * here? I know that Linux uses arithmetic on void *, but it makes the > + > + struct hdr_cursor nh; > + nh.pos =3D data; > + > + struct ethhdr *eth; > + if (parse_ethhdr(&nh, data_end, ð) < 0) > + return XDP_DROP;> + > + > + if (ctx->ingress_ifindex < 1 || ctx->ingress_ifindex > 4096) > + return XDP_DROP; > + > + vlan_tag_push(ctx, eth, ctx->ingress_ifindex); Looks like a missing check for the return value. > + return bpf_redirect_map(&router_iface, 0, 0); > +} > diff --git a/tools/xdp-forwarder/prog_router.c b/tools/xdp-forwarder/pr= og_router.c > new file mode 100644 > index 0000000..fe6a6b5 > --- /dev/null > +++ b/tools/xdp-forwarder/prog_router.c > @@ -0,0 +1,43 @@ > +// SPDX-License-Identifier: EUPL-1.2+ > +// SPDX-FileCopyrightText: 2025 Yureka Lilian > + > +#define VLAN_MAX_DEPTH 1 > + > +#include > +#include > +#include "parsing_helpers.h" > +#include "rewrite_helpers.h" > + > +// The map is actually not used by this program, but just included > +// to keep the reference-counted pin alive before any physical interfa= ces > +// are added. > +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"); > + > + > +SEC("xdp") > +int router(struct xdp_md *ctx) > +{ > + void *data_end =3D (void *)(long)ctx->data_end; > + void *data =3D (void *)(long)ctx->data; > + > + struct hdr_cursor nh; > + nh.pos =3D data; > + > + struct ethhdr *eth; > + int r; > + if (r =3D parse_ethhdr(&nh, data_end, ð) < 0) > + return XDP_DROP; Did you mean if ((r =3D parse_ethhdr(&nh, data_end, ð)) < 0) return XDP_DROP; ? > + int vlid =3D vlan_tag_pop(ctx, eth); > + if (vlid < 0) { > + return XDP_DROP; > + } I don=E2=80=99t think Spectrum uses bits other than the VLAN ID, and VLAN 0 is reserved, so perhaps: if (vlid < 1 || vlid > 4096) { return XDP_DROP; } > + return bpf_redirect(vlid, 0); > +} > diff --git a/tools/xdp-forwarder/set_router_iface.c b/tools/xdp-forward= er/set_router_iface.c > new file mode 100644 > index 0000000..32835f9 > --- /dev/null > +++ b/tools/xdp-forwarder/set_router_iface.c > @@ -0,0 +1,29 @@ > +// SPDX-License-Identifier: EUPL-1.2+ > +// SPDX-FileCopyrightText: 2025 Yureka Lilian > + > +#include > +#include > +#include > +#include > + > +int main(int argc, char **argv) > +{ > + if (argc < 2) { > + err(EXIT_FAILURE, "missing interface name"); > + } > + > + int router_idx =3D if_nametoindex(argv[1]); > + if (router_idx <=3D 0) { > + err(EXIT_FAILURE, "error getting router interface"); > + } > + > + int map_fd =3D bpf_obj_get("/sys/fs/bpf/router_iface"); > + if (map_fd < 0) { > + err(EXIT_FAILURE, "failed to open bpf map"); > + } > + > + int id =3D 0; > + if (bpf_map_update_elem(map_fd, &id, &router_idx, 0) < 0) { > + err(EXIT_FAILURE, "failed to update bpf map"); > + } > +} I simplified the code into the following (only compile-tested): /* SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-clause) */ /* * This file contains parsing functions that can be used in eXDP programs= =2E The * functions are marked as __always_inline, and fully defined in this hea= der * file to be included in the BPF program. * * Each helper parses a packet header, including doing bounds checking, a= nd * returns the type of its contents if successful, and -1 otherwise. * * For Ethernet and IP headers, the content type is the type of the paylo= ad * (h_proto for Ethernet, nexthdr for IPv6), for ICMP it is the ICMP type= field. * All return values are in host byte order. */ #include #include #include #include #include #include /* * struct vlan_hdr - vlan header * @h_vlan_TCI: priority and VLAN ID * @h_vlan_encapsulated_proto: packet type ID or len */ struct vlan_hdr { __be16 h_vlan_TCI; __be16 h_vlan_encapsulated_proto; } __attribute__((__packed__)); struct eth_vlan_hdr { struct ethhdr eth; struct vlan_hdr vlan; } __attribute__((__packed__)); static __always_inline int proto_is_vlan(__u16 h_proto) { return !!(h_proto =3D=3D bpf_htons(ETH_P_8021Q) || h_proto =3D=3D bpf_htons(ETH_P_8021AD)); } /* Pushes a new VLAN tag after the Ethernet header. Returns 0 on success,= * -1 on failure. */ static __always_inline int vlan_tag_push(struct xdp_md *ctx, int vlid) { struct eth_vlan_hdr *hdr; char *data_end; char *data; /* Check for valid Ethernet frame */ if ((unsigned long)ctx->data + ETH_ZLEN > (unsigned long)ctx->data_end) return -1; /* Add space in front of the packet */ if (bpf_xdp_adjust_head(ctx, -(int)sizeof(struct vlan_hdr))) return -1; /* Must re-fetch header pointers */ data_end =3D (char *)(long)ctx->data_end; data =3D (char *)(long)ctx->data; /* Verifier requires this (redundant) bounds check */ if (data + ETH_ZLEN + sizeof(struct vlan_hdr) > data_end) return -1; /* Move source and destination MAC addresses, populate VLAN tag * with ID and proto, and set outer Ethernet header to VLAN type. */ __builtin_memmove(data, data + sizeof(struct vlan_hdr), offsetof(struct ethhdr, h_proto)); hdr =3D (struct eth_vlan_hdr *)data; /* TODO: should this be ETH_P_8021AD? */ hdr->eth.h_proto =3D bpf_htons(ETH_P_8021Q); hdr->vlan.h_vlan_TCI =3D bpf_htons(vlid); return 0; } /* Pops the outermost VLAN tag off the packet. Returns the popped VLAN ID= on * success or negative errno on failure. */ static __always_inline int vlan_tag_pop(struct xdp_md *ctx) { char *data_end =3D (void *)(long)ctx->data_end; struct ethhdr *eth =3D (void *)(long)ctx->data; struct vlan_hdr *vlh; int vlid; /* Check that the produced Ethernet frame will be long enough */ if ((unsigned long)eth + ETH_ZLEN + sizeof(*vlh) > (unsigned long)data_end) return -1; /* Careful with the parenthesis here */ vlh =3D (void *)(eth + 1); if (!proto_is_vlan(eth->h_proto)) return -1; /* Save vlan ID for returning */ vlid =3D bpf_ntohs(vlh->h_vlan_TCI); /* Move the source and destination MAC addresses. * This moves the Ethernet header by 4 bytes, so * be sure to cast to char * before doing pointer * arithmetic. */ __builtin_memmove((char *)eth + sizeof(*vlh), eth, offsetof(struct ethhdr, h_proto)); /* Actually adjust the head pointer */ if (bpf_xdp_adjust_head(ctx, (int)sizeof(*vlh))) return -1; return vlid; } // The maps are actually not used by this program, but just included // to keep the reference-counted pin alive before any physical interfaces= // are added. struct { __uint(type, BPF_MAP_TYPE_DEVMAP); __type(key, int); __type(value, int); __uint(max_entries, 1); __uint(pinning, LIBBPF_PIN_BY_NAME); } physical_iface SEC(".maps"); 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"); SEC("xdp") int physical(struct xdp_md *ctx) { if (ctx->ingress_ifindex < 1 || ctx->ingress_ifindex > 4096) return XDP_DROP; if (vlan_tag_push(ctx, ctx->ingress_ifindex)) return XDP_DROP; return bpf_redirect_map(&physical_iface, 0, 0); } SEC("xdp") int router(struct xdp_md *ctx) { int vlid =3D vlan_tag_pop(ctx); /* Negative VLAN IDs indicate errors, and 0 is reserved and invalid. * Values above 4096 indicate that the priority field is used, which * isn't suppported out of simplicity. */ if (vlid < 1 || vlid > 4096) return XDP_DROP; return bpf_redirect(vlid, 0); } --=20 Sincerely, Demi Marie Obenour (she/her/hers) --------------cuDSPXQTCy2C1SIB0IrQEQVx Content-Type: application/pgp-keys; name="OpenPGP_0xB288B55FFF9C22C1.asc" Content-Disposition: attachment; filename="OpenPGP_0xB288B55FFF9C22C1.asc" Content-Description: OpenPGP public key Content-Transfer-Encoding: quoted-printable -----BEGIN PGP PUBLIC KEY BLOCK----- xsFNBFp+A0oBEADffj6anl9/BHhUSxGTICeVl2tob7hPDdhHNgPR4C8xlYt5q49y B+l2nipdaq+4Gk6FZfqC825TKl7eRpUjMriwle4r3R0ydSIGcy4M6eb0IcxmuPYf bWpr/si88QKgyGSVZ7GeNW1UnzTdhYHuFlk8dBSmB1fzhEYEk0RcJqg4AKoq6/3/ UorR+FaSuVwT7rqzGrTlscnTDlPWgRzrQ3jssesI7sZLm82E3pJSgaUoCdCOlL7M MPCJwI8JpPlBedRpe9tfVyfu3euTPLPxwcV3L/cfWPGSL4PofBtB8NUU6QwYiQ9H zx4xOyn67zW73/G0Q2vPPRst8LBDqlxLjbtx/WLR6h3nBc3eyuZ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ZwT3CPTSSKc7ySndEXWkOYArDIdtyxdE1p5/c3aoz4utzUU7NDHQ+vVIwlnZSMiZ jek2IJP3SZ+COOIHCVxpUaZ4lnzWT4eDqABhMLpIzw6NmGfg+kLBJhouqz81WITr EtJuZYM5blWncBOJCoWMnBEcTEo/viU3GgcVRw=3D=3D =3Dx94R -----END PGP PUBLIC KEY BLOCK----- --------------cuDSPXQTCy2C1SIB0IrQEQVx-- --------------C1h8EYlLDCgA0Hs0YVYo8ZQd-- --------------Vbm80JtUv08s3L0hyWBMw06m Content-Type: application/pgp-signature; name="OpenPGP_signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="OpenPGP_signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEopQtqVJW1aeuo9/sszaHOrMp8lMFAmi93DgACgkQszaHOrMp 8lNgUg/7BcygE34Lxy1aUKrURwNfs2/sXp5w5IcKtG5dzKpVr+LRQTK4QJg1jHF9 qHgivtP9NWNFP9xkJDmfvtFgCzRppyDv3pxS9JIPD6InMW7WX96DwDetBDutYgB6 42Z1pxDgZIA7jGJwSvZBC+GxyH0ACddUxjYsR5f7sqBCiOWvh5RdtDORnQjOLvde RME9fLQsbSdylwck9MyyjiY2q53b+TIqgZ/nITunjEqojau7j8xxEF0/O3r2iAfC MuJIEY08/DuAf4fvdhVOZ/WQKynEmC92wDgpz+jbPyIw3QUuP3ciL3rTuuYqk/zt ko2N8qYsNcqf4l8pe6YZHXGkY89eb7FntDv6Mgo/F1xOPqK2gxPon75qiSqjNxoO TEPyUpGJaKjGtDH/EPEjzR8rSkRFYmdfVfSXF0gt2GuOftNfNHknL7ZyCHIcjPJR Y0n1MtL4rT4jxlDB9J+rc9uGRnH5ep4sqqBaXmr1TqZyHN17OCN0zXhOJhSHRvth kup161FSBDwqylzTiLEy7Kc2oTergy0YGmAhl79heLMHTA4RzXix1HQbJP/jikT/ gfF7sy6LVAq2WSGJDfhuy2/9ShH+5DPnZceqjEle5kkrl6f/H0KqaLpE+NRNclKI ue4KpiRK6tbviOYMoATy5NHuNiCPnAyY4jaRXt4tWeIj6FNukC8= =CXkZ -----END PGP SIGNATURE----- --------------Vbm80JtUv08s3L0hyWBMw06m--