Skip to content

Commit 366d1e9

Browse files
leitaoNipaLocal
authored andcommitted
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@debian.org> Reviewed-by: Simon Horman <horms@kernel.org> Signed-off-by: NipaLocal <nipa@local>
1 parent 6c9afed commit 366d1e9

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

net/core/netpoll.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,6 @@ EXPORT_SYMBOL(netpoll_send_skb);
417417
static void push_ipv6(struct netpoll *np, struct sk_buff *skb, int len)
418418
{
419419
struct ipv6hdr *ip6h;
420-
struct ethhdr *eth;
421420

422421
skb_push(skb, sizeof(struct ipv6hdr));
423422
skb_reset_network_header(skb);
@@ -435,16 +434,12 @@ static void push_ipv6(struct netpoll *np, struct sk_buff *skb, int len)
435434
ip6h->saddr = np->local_ip.in6;
436435
ip6h->daddr = np->remote_ip.in6;
437436

438-
eth = skb_push(skb, ETH_HLEN);
439-
skb_reset_mac_header(skb);
440437
skb->protocol = htons(ETH_P_IPV6);
441-
eth->h_proto = htons(ETH_P_IPV6);
442438
}
443439

444440
static void push_ipv4(struct netpoll *np, struct sk_buff *skb, int len)
445441
{
446442
static atomic_t ip_ident;
447-
struct ethhdr *eth;
448443
struct iphdr *iph;
449444
int ip_len;
450445

@@ -466,11 +461,7 @@ static void push_ipv4(struct netpoll *np, struct sk_buff *skb, int len)
466461
put_unaligned(np->local_ip.ip, &iph->saddr);
467462
put_unaligned(np->remote_ip.ip, &iph->daddr);
468463
iph->check = ip_fast_csum((unsigned char *)iph, iph->ihl);
469-
470-
eth = skb_push(skb, ETH_HLEN);
471-
skb_reset_mac_header(skb);
472464
skb->protocol = htons(ETH_P_IP);
473-
eth->h_proto = htons(ETH_P_IP);
474465
}
475466

476467
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)
491482
netpoll_udp_checksum(np, skb, len);
492483
}
493484

485+
static void push_eth(struct netpoll *np, struct sk_buff *skb)
486+
{
487+
struct ethhdr *eth;
488+
489+
eth = skb_push(skb, ETH_HLEN);
490+
skb_reset_mac_header(skb);
491+
ether_addr_copy(eth->h_source, np->dev->dev_addr);
492+
ether_addr_copy(eth->h_dest, np->remote_mac);
493+
if (np->ipv6)
494+
eth->h_proto = htons(ETH_P_IPV6);
495+
else
496+
eth->h_proto = htons(ETH_P_IP);
497+
}
498+
494499
int netpoll_send_udp(struct netpoll *np, const char *msg, int len)
495500
{
496501
int total_len, ip_len, udp_len;
497502
struct sk_buff *skb;
498-
struct ethhdr *eth;
499503

500504
if (!IS_ENABLED(CONFIG_PREEMPT_RT))
501505
WARN_ON_ONCE(!irqs_disabled());
@@ -521,11 +525,7 @@ int netpoll_send_udp(struct netpoll *np, const char *msg, int len)
521525
push_ipv6(np, skb, len);
522526
else
523527
push_ipv4(np, skb, len);
524-
525-
eth = eth_hdr(skb);
526-
ether_addr_copy(eth->h_source, np->dev->dev_addr);
527-
ether_addr_copy(eth->h_dest, np->remote_mac);
528-
528+
push_eth(np, skb);
529529
skb->dev = np->dev;
530530

531531
return (int)netpoll_send_skb(np, skb);

0 commit comments

Comments
 (0)