Skip to content

Commit 6c9afed

Browse files
leitaoNipaLocal
authored andcommitted
netpoll: factor out UDP header setup into push_udp() helper
Move UDP header construction from netpoll_send_udp() into a new static helper function push_udp(). This completes the protocol layer refactoring by: 1. Creating a dedicated helper for UDP header assembly 2. Removing UDP-specific logic from the main send function 3. Establishing a consistent pattern with existing IPv4/IPv6 helpers: - push_udp() - push_ipv4() - push_ipv6() The change improves code organization and maintains the encapsulation pattern established in previous refactorings. Signed-off-by: Breno Leitao <leitao@debian.org> Reviewed-by: Simon Horman <horms@kernel.org> Signed-off-by: NipaLocal <nipa@local>
1 parent 7aed973 commit 6c9afed

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

net/core/netpoll.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -473,11 +473,28 @@ static void push_ipv4(struct netpoll *np, struct sk_buff *skb, int len)
473473
eth->h_proto = htons(ETH_P_IP);
474474
}
475475

476+
static void push_udp(struct netpoll *np, struct sk_buff *skb, int len)
477+
{
478+
struct udphdr *udph;
479+
int udp_len;
480+
481+
udp_len = len + sizeof(struct udphdr);
482+
483+
skb_push(skb, sizeof(struct udphdr));
484+
skb_reset_transport_header(skb);
485+
486+
udph = udp_hdr(skb);
487+
udph->source = htons(np->local_port);
488+
udph->dest = htons(np->remote_port);
489+
udph->len = htons(udp_len);
490+
491+
netpoll_udp_checksum(np, skb, len);
492+
}
493+
476494
int netpoll_send_udp(struct netpoll *np, const char *msg, int len)
477495
{
478496
int total_len, ip_len, udp_len;
479497
struct sk_buff *skb;
480-
struct udphdr *udph;
481498
struct ethhdr *eth;
482499

483500
if (!IS_ENABLED(CONFIG_PREEMPT_RT))
@@ -499,14 +516,7 @@ int netpoll_send_udp(struct netpoll *np, const char *msg, int len)
499516
skb_copy_to_linear_data(skb, msg, len);
500517
skb_put(skb, len);
501518

502-
skb_push(skb, sizeof(struct udphdr));
503-
skb_reset_transport_header(skb);
504-
udph = udp_hdr(skb);
505-
udph->source = htons(np->local_port);
506-
udph->dest = htons(np->remote_port);
507-
udph->len = htons(udp_len);
508-
509-
netpoll_udp_checksum(np, skb, len);
519+
push_udp(np, skb, len);
510520
if (np->ipv6)
511521
push_ipv6(np, skb, len);
512522
else

0 commit comments

Comments
 (0)