From nobody Wed Nov 27 07:30:32 2024 Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.47]) (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 BEF11149005; Sun, 13 Oct 2024 18:55:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728845736; cv=none; b=bsoNWZ9sTCpJE0U+oqsNR9gVz8JrtnzIBI097PEBlVdmID27wAd5tMaG+s/cL4WaKdFLSoHejs3e0z1wdd8G+5pwx8vAYsDPmw/jLBH+dSp4uuBK8wXQNck0UXMHevGbwzGca7rBTUbXFzcha6ewslY2Ag4U9zf/tbRPMAOFmPE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728845736; c=relaxed/simple; bh=FDhJVXPqgLK53TdlXXJJx7Wh39mTo+45pxTrQp6Wi4c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ci1SiVZeN8gVkZm+w/frnE09Pnbe9dDatQhCOwLRBbSrzMM90xHFsTNwCPkDz2ihD3SkB6D46xdT4ryjrOH0uyMQzeRM+OWSMPK/15DgliFAafOSLorm9aPcDF7cwUV6ReF4cRIeo6gZoP+u8Ea+exLex3t65ndGhbL+fzgIt4o= 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=Ye1PWli8; arc=none smtp.client-ip=209.85.218.47 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="Ye1PWli8" Received: by mail-ej1-f47.google.com with SMTP id a640c23a62f3a-a9963e47b69so570259866b.1; Sun, 13 Oct 2024 11:55:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728845733; x=1729450533; 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=GbZ+4AfljpB6Mob7lVDrAx0dHSaVOpAjB7zGVS+eC1Y=; b=Ye1PWli8NUc9V5WjpDmrpWRZY/SXn+VwM2TlxIrKhysHRAGGmMmTVOXu1b6IvMIYTS 1Wpb04YDNxXvBNX2iLn5rp65Gvf+rSc8EH9nXjS4ULU8GT4OqvUMNCdUyFnWqjCkO5t5 N/XIIcjzYfRb8GZk9rU8L2v+lsGKDi/JnIv3i+wYN1CTAKEL/a5NeJm/RCjgQGXuTNW2 0F+ep7CBdTax0eTcPtR8x7uVn7cqz4STNxKMI8jJH/wJvTIu3A0FNPcof3OMxkaPY101 MN46lu2zX3jCkKXMibckfhwS0RtWNMGbh3kDNTeHATId/zaDXkyg7U47X9tr96acUqSH USAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728845733; x=1729450533; 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=GbZ+4AfljpB6Mob7lVDrAx0dHSaVOpAjB7zGVS+eC1Y=; b=h3N1rpXyV7rV/0YG+0Y4a+mj+lFJVt+GDM9SmXMWlJG6Ao7wRyMZgu/6tEr98ZxlAL q1I8Xp168B1hE92ibrVSvpnqZNxhpwKdCs6LtSQaaEVBUdAJLrpQVs82QFS76k9Ouf9i sK4/XUziY5IkXKhu1dDK5QNosUF7SCfzF7JXb9/BHuhv4+DQc3DXrCarbG15DPzG8zIY LJSWslQMbIdEgxTvrOBcCPgZLiVxDwu6NVvZpa5kFa6Yamg5dF8RqtaBVtwFL7MrjA6h bpkEXGHaH9eyxhyBVBhbXWFGMNcUp0GDBSqYTW5HxkgoXTjZYgLs5xqa4ee/xH3UhCAb mc+A== X-Forwarded-Encrypted: i=1; AJvYcCUPGlM0dhEmXT+GpSbUMibZAjxVmX+oLo/cznslCeBY0k814ueFJeYJB5ourwQABuSlUbOLcwRukpdb0MfSvdxR@vger.kernel.org, AJvYcCVtUcMgEs0e5rUUcESYkl1s2nYzfyD0pErjeMioWZmoX2lfQUZ1OtU2ShVViBXnHfDOesP9N3ZI98nl59M=@vger.kernel.org X-Gm-Message-State: AOJu0Yx8JDYxt20nlK3JW6bpWG9wwCk8LwXfyHmtp4Bm7EC/Ww7xPTwF aHT3Y2FSvFa8VQkmzLPT5FLkug3Uy6b/rHg8Hext0EEoTLd6OiGP X-Google-Smtp-Source: AGHT+IHBwmUQlNXjLHzouwP3A/HnrJ9ShbIZ6PYI3ty3qPemvkmnTevcw0/QiFnh3+dIcw+vQiViIw== X-Received: by 2002:a17:907:d1a:b0:a9a:72c:f36f with SMTP id a640c23a62f3a-a9a072cf878mr239291766b.50.1728845732725; Sun, 13 Oct 2024 11:55:32 -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.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Oct 2024 11:55:32 -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 01/12] netfilter: nf_flow_table_offload: Add nf_flow_encap_push() for xmit direct Date: Sun, 13 Oct 2024 20:54:57 +0200 Message-ID: <20241013185509.4430-2-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" Loosely based on wenxu's patches: "nf_flow_table_offload: offload the vlan/PPPoE encap in the flowtable". Fixed double vlan and pppoe packets, almost entirely rewriting the patch. After this patch, it is possible to transmit packets in the fastpath with outgoing encaps, without using vlan- and/or pppoe-devices. This makes it possible to use more different kinds of network setups. For example, when bridge tagging is used to egress vlan tagged packets using the forward fastpath. Another example is passing 802.1q tagged packets through a bridge using the bridge fastpath. This also makes the software fastpath process more similar to the hardware offloaded fastpath process, where encaps are also pushed. After applying this patch, always info->outdev =3D info->hw_outdev, so the netfilter code can be further cleaned up by removing: * hw_outdev from struct nft_forward_info * out.hw_ifindex from struct nf_flow_route * out.hw_ifidx from struct flow_offload_tuple Signed-off-by: Eric Woudstra --- net/netfilter/nf_flow_table_ip.c | 96 +++++++++++++++++++++++++++++++- net/netfilter/nft_flow_offload.c | 6 +- 2 files changed, 96 insertions(+), 6 deletions(-) diff --git a/net/netfilter/nf_flow_table_ip.c b/net/netfilter/nf_flow_table= _ip.c index 98edcaa37b38..9221ddb6f07a 100644 --- a/net/netfilter/nf_flow_table_ip.c +++ b/net/netfilter/nf_flow_table_ip.c @@ -302,6 +302,92 @@ static bool nf_flow_skb_encap_protocol(struct sk_buff = *skb, __be16 proto, return false; } =20 +static inline int nf_flow_vlan_inner_push(struct sk_buff *skb, __be16 prot= o, u16 id) +{ + struct vlan_hdr *vhdr; + + if (skb_cow_head(skb, VLAN_HLEN)) + return -1; + + __skb_push(skb, VLAN_HLEN); + skb_reset_network_header(skb); + + vhdr =3D (struct vlan_hdr *)(skb->data); + vhdr->h_vlan_TCI =3D htons(id); + vhdr->h_vlan_encapsulated_proto =3D skb->protocol; + skb->protocol =3D proto; + + return 0; +} + +static inline int nf_flow_ppoe_push(struct sk_buff *skb, u16 id) +{ + struct ppp_hdr { + struct pppoe_hdr hdr; + __be16 proto; + } *ph; + int data_len =3D skb->len + 2; + __be16 proto; + + if (skb_cow_head(skb, PPPOE_SES_HLEN)) + return -1; + + if (skb->protocol =3D=3D htons(ETH_P_IP)) + proto =3D htons(PPP_IP); + else if (skb->protocol =3D=3D htons(ETH_P_IPV6)) + proto =3D htons(PPP_IPV6); + else + return -1; + + __skb_push(skb, PPPOE_SES_HLEN); + skb_reset_network_header(skb); + + ph =3D (struct ppp_hdr *)(skb->data); + ph->hdr.ver =3D 1; + ph->hdr.type =3D 1; + ph->hdr.code =3D 0; + ph->hdr.sid =3D htons(id); + ph->hdr.length =3D htons(data_len); + ph->proto =3D proto; + skb->protocol =3D htons(ETH_P_PPP_SES); + + return 0; +} + +static int nf_flow_encap_push(struct sk_buff *skb, + struct flow_offload_tuple_rhash *tuplehash, + unsigned short *type) +{ + int i =3D 0, ret =3D 0; + + if (!tuplehash->tuple.encap_num) + return 0; + + if (tuplehash->tuple.encap[i].proto =3D=3D htons(ETH_P_8021Q) || + tuplehash->tuple.encap[i].proto =3D=3D htons(ETH_P_8021AD)) { + __vlan_hwaccel_put_tag(skb, tuplehash->tuple.encap[i].proto, + tuplehash->tuple.encap[i].id); + i++; + if (i >=3D tuplehash->tuple.encap_num) + return 0; + } + + switch (tuplehash->tuple.encap[i].proto) { + case htons(ETH_P_8021Q): + *type =3D ETH_P_8021Q; + ret =3D nf_flow_vlan_inner_push(skb, + tuplehash->tuple.encap[i].proto, + tuplehash->tuple.encap[i].id); + break; + case htons(ETH_P_PPP_SES): + *type =3D ETH_P_PPP_SES; + ret =3D nf_flow_ppoe_push(skb, + tuplehash->tuple.encap[i].id); + break; + } + return ret; +} + static void nf_flow_encap_pop(struct sk_buff *skb, struct flow_offload_tuple_rhash *tuplehash) { @@ -331,6 +417,7 @@ static void nf_flow_encap_pop(struct sk_buff *skb, =20 static unsigned int nf_flow_queue_xmit(struct net *net, struct sk_buff *sk= b, const struct flow_offload_tuple_rhash *tuplehash, + struct flow_offload_tuple_rhash *other_tuplehash, unsigned short type) { struct net_device *outdev; @@ -339,6 +426,9 @@ static unsigned int nf_flow_queue_xmit(struct net *net,= struct sk_buff *skb, if (!outdev) return NF_DROP; =20 + if (nf_flow_encap_push(skb, other_tuplehash, &type) < 0) + return NF_DROP; + skb->dev =3D outdev; dev_hard_header(skb, skb->dev, type, tuplehash->tuple.out.h_dest, tuplehash->tuple.out.h_source, skb->len); @@ -458,7 +548,8 @@ nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb, ret =3D NF_STOLEN; break; case FLOW_OFFLOAD_XMIT_DIRECT: - ret =3D nf_flow_queue_xmit(state->net, skb, tuplehash, ETH_P_IP); + ret =3D nf_flow_queue_xmit(state->net, skb, tuplehash, + &flow->tuplehash[!dir], ETH_P_IP); if (ret =3D=3D NF_DROP) flow_offload_teardown(flow); break; @@ -753,7 +844,8 @@ nf_flow_offload_ipv6_hook(void *priv, struct sk_buff *s= kb, ret =3D NF_STOLEN; break; case FLOW_OFFLOAD_XMIT_DIRECT: - ret =3D nf_flow_queue_xmit(state->net, skb, tuplehash, ETH_P_IPV6); + ret =3D nf_flow_queue_xmit(state->net, skb, tuplehash, + &flow->tuplehash[!dir], ETH_P_IPV6); if (ret =3D=3D NF_DROP) flow_offload_teardown(flow); break; diff --git a/net/netfilter/nft_flow_offload.c b/net/netfilter/nft_flow_offl= oad.c index e8f800788c4a..bb15aa55e6fb 100644 --- a/net/netfilter/nft_flow_offload.c +++ b/net/netfilter/nft_flow_offload.c @@ -124,13 +124,12 @@ static void nft_dev_path_info(const struct net_device= _path_stack *stack, info->indev =3D NULL; break; } - if (!info->outdev) - info->outdev =3D path->dev; info->encap[info->num_encaps].id =3D path->encap.id; info->encap[info->num_encaps].proto =3D path->encap.proto; info->num_encaps++; if (path->type =3D=3D DEV_PATH_PPPOE) memcpy(info->h_dest, path->encap.h_dest, ETH_ALEN); + info->xmit_type =3D FLOW_OFFLOAD_XMIT_DIRECT; break; case DEV_PATH_BRIDGE: if (is_zero_ether_addr(info->h_source)) @@ -158,8 +157,7 @@ static void nft_dev_path_info(const struct net_device_p= ath_stack *stack, break; } } - if (!info->outdev) - info->outdev =3D info->indev; + info->outdev =3D info->indev; =20 info->hw_outdev =3D info->indev; =20 --=20 2.45.2