From nobody Wed Nov 27 07:51:19 2024 Received: from mail-ej1-f49.google.com (mail-ej1-f49.google.com [209.85.218.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 03CED197A68; Sun, 13 Oct 2024 18:55:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728845751; cv=none; b=RZIhdPn20u46pKvwLytL6P11Mmlt8IiHvJfWx7C+jYYQCPG3SAr9+zqmimh8UimQigNWg7TvNAn6Zezs9w37blmamTomifMvzgT1DK92Beydtj/ZuXTqmsOwOVrPZmiGTzUOn7zpXLproTsvsKOARZ/rLhYWvO3LshkqqDqgsUA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728845751; c=relaxed/simple; bh=n5GlTdCtKOmtjAaFIunijEhjxn6K4vforcxuYnG9cJ0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GqqO7uSrgFHIHUtD0MKTgQHwKyLt7UQWJ4nqbjUvE4U3HUGpSRHSeqE2+4Dxgb6GgBNh49ztatXo49zV+/VLfQwfkqiyDUTGbDZVC9Ea22rEiETAgk1tnXaxlskPVyoJIxkFTaQV5yMS+rRH808hw1GWgxcyZJeRYplKd1RrHv4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=k6beZ14d; arc=none smtp.client-ip=209.85.218.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="k6beZ14d" Received: by mail-ej1-f49.google.com with SMTP id a640c23a62f3a-a99f1fd20c4so189157866b.0; Sun, 13 Oct 2024 11:55:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728845748; x=1729450548; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nXqA2N6PSdeku8lbnGk/r0H6SHXM5r8C6mfKewggPXk=; b=k6beZ14dj1lQG6jpSqamSyfeOqeyPm1p6byFsZuGX9D3L10O2p/l6jhWg8s8qNoqRH +cP7uWvViwFtHoiSMzSfVZfQVrlqFJajIB1+A6xoHwUozvoJRvC5gnmsNM42dbE5wtew eWzUzUAY5EGk87ob8Ip2gA9TfB3DOBRFrbZM/GRnl49W9xneQklcPlne1KjQnBpzTsGd Wi9t6MVrclDmulR/E56JCNR9SwpHwbPWPSlvHK+mLwt3me5WoN0PMW7gJqMtfC5IrFeb U3UMHw0C8SuZHNvgK+d4wv1is531ZTSLO+Gh3QikmKWj/bOplxWbB7fyzdN1NVSt4djG WdkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728845748; x=1729450548; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nXqA2N6PSdeku8lbnGk/r0H6SHXM5r8C6mfKewggPXk=; b=JwFoHRSptyF6Mb6usIPGeOOLF/Vo8fh54B2UFylaTU6blzhe23vNq9PY3ctOTzIFkq H/5Bc1V9H+I8ONdMk5IVGNDC0YnACTylSL4XRaxM6uFcs5ce2WuAs7xD8rW0Puch1gUZ j7PeqcjKoncH2PPUotAjoWfc7XWsk+XEG/52LS4xQfw7KVdHpW7qWLNdJBPIze5csJ7n uJeFoNOhLWsTIwbS0Ezi6KAC+BSKAGVDSmGDH+ONT+sk/BzOp45b2gGY3T/rCSTK8cgZ 1wwKbmTDQAjEl7+bDp0QcY+wcMrW5ZY/79xmL/axYCuMEwiSblNZr5q1JGsvqimxK97D b5Wg== X-Forwarded-Encrypted: i=1; AJvYcCWSqn9zPVGWm6P6v9H3eHxCE8Or+tlch8OxZ3NeqrcYcHUW+05H7S/fmhl7qEt6IDKUVVZI8Hz7NMX3osg=@vger.kernel.org, AJvYcCXAzItjBDrWwIDl5zvI4LV16kAPAebh27FlhiDd85LcNFpa3sjj++zfAPpt44FOfRQPwbc8GHCULE0S6pJh0Hoj@vger.kernel.org X-Gm-Message-State: AOJu0Yz487lkdcB+goUEkni7SdAsz48w2fh1p2JxOwVZy5WVkfkjApL3 sFsNKGlXQnj2du+AIVi1D0L3lrq0xgVdbL8o2DqZkijqczy7ewWZ X-Google-Smtp-Source: AGHT+IGDRNNl2WNHKk/RQYIt3X3ZUbDBl2cG/u3cyrPOyqik2hRlsXTDnJIYfMk+W8sAqccVFejf5w== X-Received: by 2002:a17:906:6a0f:b0:a9a:196:fc29 with SMTP id a640c23a62f3a-a9a0196fee5mr289924666b.61.1728845748194; Sun, 13 Oct 2024 11:55:48 -0700 (PDT) Received: from corebook.localdomain (2001-1c00-020d-1300-1b1c-4449-176a-89ea.cable.dynamic.v6.ziggo.nl. [2001:1c00:20d:1300:1b1c:4449:176a:89ea]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a12d384b9sm13500866b.172.2024.10.13.11.55.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Oct 2024 11:55:47 -0700 (PDT) From: Eric Woudstra To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Pablo Neira Ayuso , Jozsef Kadlecsik , Roopa Prabhu , Nikolay Aleksandrov , Matthias Brugger , AngeloGioacchino Del Regno , Jiri Pirko , Sebastian Andrzej Siewior , Lorenzo Bianconi , "Frank Wunderlich" , Daniel Golle , Eric Woudstra Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org, bridge@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Subject: [PATCH RFC v1 net-next 12/12] netfilter: nft_flow_offload: Add bridgeflow to nft_flow_offload_eval() Date: Sun, 13 Oct 2024 20:55:08 +0200 Message-ID: <20241013185509.4430-13-ericwouds@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241013185509.4430-1-ericwouds@gmail.com> References: <20241013185509.4430-1-ericwouds@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Edit nft_flow_offload_eval() to make it possible to handle a flowtable of the nft bridge family. Use nft_flow_offload_bridge_init() to fill the flow tuples. It uses nft_dev_fill_bridge_path() in each direction. Signed-off-by: Eric Woudstra --- net/netfilter/nft_flow_offload.c | 142 +++++++++++++++++++++++++++++-- 1 file changed, 137 insertions(+), 5 deletions(-) diff --git a/net/netfilter/nft_flow_offload.c b/net/netfilter/nft_flow_offl= oad.c index 2923286d475e..bd4850691baa 100644 --- a/net/netfilter/nft_flow_offload.c +++ b/net/netfilter/nft_flow_offload.c @@ -184,6 +184,129 @@ static bool nft_flowtable_find_dev(const struct net_d= evice *dev, return found; } =20 +static int nft_dev_fill_bridge_path(struct flow_offload *flow, + struct nft_flowtable *ft, + const struct nft_pktinfo *pkt, + enum ip_conntrack_dir dir, + const struct net_device *src_dev, + const struct net_device *dst_dev, + unsigned char *src_ha, + unsigned char *dst_ha) +{ + struct flow_offload_tuple_rhash *th =3D flow->tuplehash; + struct net_device_path_stack stack; + struct net_device_path_ctx ctx =3D {}; + struct nft_forward_info info =3D {}; + int i, j =3D 0; + + for (i =3D th[dir].tuple.encap_num - 1; i >=3D 0 ; i--) { + if (info.num_encaps >=3D NF_FLOW_TABLE_ENCAP_MAX) + return -1; + info.encap[info.num_encaps].id =3D th[dir].tuple.encap[i].id; + info.encap[info.num_encaps].proto =3D th[dir].tuple.encap[i].proto; + info.num_encaps++; + + if (th[dir].tuple.encap[i].proto =3D=3D htons(ETH_P_PPP_SES)) + continue; + + if (ctx.num_vlans >=3D NET_DEVICE_PATH_VLAN_MAX) + return -1; + ctx.vlan[ctx.num_vlans].id =3D th[dir].tuple.encap[i].id; + ctx.vlan[ctx.num_vlans].proto =3D th[dir].tuple.encap[i].proto; + ctx.num_vlans++; + } + ctx.dev =3D src_dev; + ether_addr_copy(ctx.daddr, dst_ha); + + if (dev_fill_bridge_path(&ctx, &stack) < 0) + return -1; + + nft_dev_path_info(&stack, &info, dst_ha, &ft->data); + + if (!info.indev || info.indev !=3D dst_dev) + return -1; + + th[!dir].tuple.iifidx =3D info.indev->ifindex; + for (i =3D info.num_encaps - 1; i >=3D 0; i--) { + th[!dir].tuple.encap[j].id =3D info.encap[i].id; + th[!dir].tuple.encap[j].proto =3D info.encap[i].proto; + if (info.ingress_vlans & BIT(i)) + th[!dir].tuple.in_vlan_ingress |=3D BIT(j); + j++; + } + th[!dir].tuple.encap_num =3D info.num_encaps; + + th[dir].tuple.mtu =3D dst_dev->mtu; + ether_addr_copy(th[dir].tuple.out.h_source, src_ha); + ether_addr_copy(th[dir].tuple.out.h_dest, dst_ha); + th[dir].tuple.out.ifidx =3D info.outdev->ifindex; + th[dir].tuple.out.hw_ifidx =3D info.hw_outdev->ifindex; + th[dir].tuple.xmit_type =3D FLOW_OFFLOAD_XMIT_DIRECT; + + return 0; +} + +static int nft_flow_offload_bridge_init(struct flow_offload *flow, + const struct nft_pktinfo *pkt, + enum ip_conntrack_dir dir, + struct nft_flowtable *ft) +{ + struct ethhdr *eth =3D eth_hdr(pkt->skb); + struct flow_offload_tuple *tuple; + const struct net_device *out_dev; + const struct net_device *in_dev; + int err, i =3D 0; + + in_dev =3D nft_in(pkt); + if (!in_dev || !nft_flowtable_find_dev(in_dev, ft)) + return -1; + + out_dev =3D nft_out(pkt); + if (!out_dev || !nft_flowtable_find_dev(out_dev, ft)) + return -1; + + tuple =3D &flow->tuplehash[!dir].tuple; + + if (skb_vlan_tag_present(pkt->skb)) { + tuple->encap[i].id =3D skb_vlan_tag_get(pkt->skb); + tuple->encap[i].proto =3D pkt->skb->vlan_proto; + i++; + } + switch (pkt->skb->protocol) { + case htons(ETH_P_8021Q): + struct vlan_hdr *vhdr; + + vhdr =3D (struct vlan_hdr *)skb_network_header(pkt->skb); + tuple->encap[i].id =3D ntohs(vhdr->h_vlan_TCI); + tuple->encap[i].proto =3D pkt->skb->protocol; + i++; + break; + case htons(ETH_P_PPP_SES): + struct pppoe_hdr *phdr; + + phdr =3D (struct pppoe_hdr *)skb_network_header(pkt->skb); + tuple->encap[i].id =3D ntohs(phdr->sid); + tuple->encap[i].proto =3D pkt->skb->protocol; + i++; + break; + } + tuple->encap_num =3D i; + + err =3D nft_dev_fill_bridge_path(flow, ft, pkt, !dir, out_dev, in_dev, + eth->h_dest, eth->h_source); + if (err < 0) + return err; + + memset(tuple->encap, 0, sizeof(tuple->encap)); + + err =3D nft_dev_fill_bridge_path(flow, ft, pkt, dir, in_dev, out_dev, + eth->h_source, eth->h_dest); + if (err < 0) + return err; + + return 0; +} + static void nft_dev_forward_path(struct nf_flow_route *route, const struct nf_conn *ct, enum ip_conntrack_dir dir, @@ -294,6 +417,7 @@ static void nft_flow_offload_eval(const struct nft_expr= *expr, { struct nft_flow_offload *priv =3D nft_expr_priv(expr); struct nf_flowtable *flowtable =3D &priv->flowtable->data; + bool routing =3D (flowtable->type->family !=3D NFPROTO_BRIDGE); struct tcphdr _tcph, *tcph =3D NULL; struct nf_flow_route route =3D {}; enum ip_conntrack_info ctinfo; @@ -347,14 +471,20 @@ static void nft_flow_offload_eval(const struct nft_ex= pr *expr, goto out; =20 dir =3D CTINFO2DIR(ctinfo); - if (nft_flow_route(pkt, ct, &route, dir, priv->flowtable) < 0) - goto err_flow_route; + if (routing) { + if (nft_flow_route(pkt, ct, &route, dir, priv->flowtable) < 0) + goto err_flow_route; + } =20 flow =3D flow_offload_alloc(ct); if (!flow) goto err_flow_alloc; =20 - flow_offload_route_init(flow, &route); + if (routing) + flow_offload_route_init(flow, &route); + else + if (nft_flow_offload_bridge_init(flow, pkt, dir, priv->flowtable) < 0) + goto err_flow_route; =20 if (tcph) { ct->proto.tcp.seen[0].flags |=3D IP_CT_TCP_FLAG_BE_LIBERAL; @@ -407,8 +537,10 @@ static void nft_flow_offload_eval(const struct nft_exp= r *expr, err_flow_add: flow_offload_free(flow); err_flow_alloc: - dst_release(route.tuple[dir].dst); - dst_release(route.tuple[!dir].dst); + if (routing) { + dst_release(route.tuple[dir].dst); + dst_release(route.tuple[!dir].dst); + } err_flow_route: clear_bit(IPS_OFFLOAD_BIT, &ct->status); out: --=20 2.45.2