[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250702-netpoll_untagle_ip-v2-6-13cf3db24e2b@debian.org>
Date: Wed, 02 Jul 2025 03:06:38 -0700
From: Breno Leitao <leitao@...ian.org>
To: "David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>, Jakub Kicinski <kuba@...nel.org>,
Paolo Abeni <pabeni@...hat.com>, Simon Horman <horms@...nel.org>,
Andrew Lunn <andrew+netdev@...n.ch>, Shuah Khan <shuah@...nel.org>
Cc: netdev@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-kselftest@...r.kernel.org, Breno Leitao <leitao@...ian.org>,
kernel-team@...a.com
Subject: [PATCH net-next v2 6/7] netpoll: move Ethernet setup to push_eth()
helper
Refactor Ethernet header population into dedicated function, completing
the layered abstraction with:
- push_eth() for link layer
- push_udp() for transport
- push_ipv4()/push_ipv6() for network
Signed-off-by: Breno Leitao <leitao@...ian.org>
---
net/core/netpoll.c | 30 +++++++++++++++---------------
1 file changed, 15 insertions(+), 15 deletions(-)
diff --git a/net/core/netpoll.c b/net/core/netpoll.c
index 70035e27d91cc..a1da97b5b30b6 100644
--- a/net/core/netpoll.c
+++ b/net/core/netpoll.c
@@ -417,7 +417,6 @@ EXPORT_SYMBOL(netpoll_send_skb);
static void push_ipv6(struct netpoll *np, struct sk_buff *skb, int len)
{
struct ipv6hdr *ip6h;
- struct ethhdr *eth;
skb_push(skb, sizeof(struct ipv6hdr));
skb_reset_network_header(skb);
@@ -435,16 +434,12 @@ static void push_ipv6(struct netpoll *np, struct sk_buff *skb, int len)
ip6h->saddr = np->local_ip.in6;
ip6h->daddr = np->remote_ip.in6;
- eth = skb_push(skb, ETH_HLEN);
- skb_reset_mac_header(skb);
skb->protocol = htons(ETH_P_IPV6);
- eth->h_proto = htons(ETH_P_IPV6);
}
static void push_ipv4(struct netpoll *np, struct sk_buff *skb, int len)
{
static atomic_t ip_ident;
- struct ethhdr *eth;
struct iphdr *iph;
int ip_len;
@@ -466,11 +461,7 @@ static void push_ipv4(struct netpoll *np, struct sk_buff *skb, int len)
put_unaligned(np->local_ip.ip, &iph->saddr);
put_unaligned(np->remote_ip.ip, &iph->daddr);
iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
-
- eth = skb_push(skb, ETH_HLEN);
- skb_reset_mac_header(skb);
skb->protocol = htons(ETH_P_IP);
- eth->h_proto = htons(ETH_P_IP);
}
static void push_udp(struct netpoll *np, struct sk_buff *skb, int len)
@@ -491,11 +482,24 @@ static void push_udp(struct netpoll *np, struct sk_buff *skb, int len)
netpoll_udp_checksum(np, skb, len);
}
+static void push_eth(struct netpoll *np, struct sk_buff *skb)
+{
+ struct ethhdr *eth;
+
+ eth = skb_push(skb, ETH_HLEN);
+ skb_reset_mac_header(skb);
+ ether_addr_copy(eth->h_source, np->dev->dev_addr);
+ ether_addr_copy(eth->h_dest, np->remote_mac);
+ if (np->ipv6)
+ eth->h_proto = htons(ETH_P_IPV6);
+ else
+ eth->h_proto = htons(ETH_P_IP);
+}
+
int netpoll_send_udp(struct netpoll *np, const char *msg, int len)
{
int total_len, ip_len, udp_len;
struct sk_buff *skb;
- struct ethhdr *eth;
if (!IS_ENABLED(CONFIG_PREEMPT_RT))
WARN_ON_ONCE(!irqs_disabled());
@@ -521,11 +525,7 @@ int netpoll_send_udp(struct netpoll *np, const char *msg, int len)
push_ipv6(np, skb, len);
else
push_ipv4(np, skb, len);
-
- eth = eth_hdr(skb);
- ether_addr_copy(eth->h_source, np->dev->dev_addr);
- ether_addr_copy(eth->h_dest, np->remote_mac);
-
+ push_eth(np, skb);
skb->dev = np->dev;
return (int)netpoll_send_skb(np, skb);
--
2.47.1
Powered by blists - more mailing lists