Skip to content

Commit

Permalink
Merge branch 'ipv6-random-cleanup-for-extension-header'
Browse files Browse the repository at this point in the history
Kuniyuki Iwashima says:

====================
ipv6: Random cleanup for Extension Header.

This series (1) cleans up pskb_may_pull() in some functions, where needed
data are already pulled by their caller, (2) removes redundant multicast
test, and (3) optimises reload timing of the header.
====================

Link: https://lore.kernel.org/r/20230614230107.22301-1-kuniyu@amazon.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Jakub Kicinski committed Jun 19, 2023
2 parents 9a94d76 + 6db5dd2 commit 4931062
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 38 deletions.
3 changes: 0 additions & 3 deletions include/net/rpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ static inline int rpl_init(void)
static inline void rpl_exit(void) {}
#endif

size_t ipv6_rpl_srh_size(unsigned char n, unsigned char cmpri,
unsigned char cmpre);

void ipv6_rpl_srh_decompress(struct ipv6_rpl_sr_hdr *outhdr,
const struct ipv6_rpl_sr_hdr *inhdr,
const struct in6_addr *daddr, unsigned char n);
Expand Down
33 changes: 5 additions & 28 deletions net/ipv6/exthdrs.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,6 @@ static bool ip6_parse_tlv(bool hopbyhop,
max_count = -max_count;
}

if (skb_transport_offset(skb) + len > skb_headlen(skb))
goto bad;

off += 2;
len -= 2;

Expand Down Expand Up @@ -402,11 +399,7 @@ static int ipv6_srh_rcv(struct sk_buff *skb)

skb_postpull_rcsum(skb, skb_network_header(skb),
skb_network_header_len(skb));

if (!pskb_pull(skb, offset)) {
kfree_skb(skb);
return -1;
}
skb_pull(skb, offset);
skb_postpull_rcsum(skb, skb_transport_header(skb),
offset);

Expand Down Expand Up @@ -444,9 +437,9 @@ static int ipv6_srh_rcv(struct sk_buff *skb)
kfree_skb(skb);
return -1;
}
}

hdr = (struct ipv6_sr_hdr *)skb_transport_header(skb);
hdr = (struct ipv6_sr_hdr *)skb_transport_header(skb);
}

hdr->segments_left--;
addr = hdr->segments + hdr->segments_left;
Expand Down Expand Up @@ -517,11 +510,7 @@ static int ipv6_rpl_srh_rcv(struct sk_buff *skb)

skb_postpull_rcsum(skb, skb_network_header(skb),
skb_network_header_len(skb));

if (!pskb_pull(skb, offset)) {
kfree_skb(skb);
return -1;
}
skb_pull(skb, offset);
skb_postpull_rcsum(skb, skb_transport_header(skb),
offset);

Expand All @@ -543,11 +532,6 @@ static int ipv6_rpl_srh_rcv(struct sk_buff *skb)
return 1;
}

if (!pskb_may_pull(skb, sizeof(*hdr))) {
kfree_skb(skb);
return -1;
}

n = (hdr->hdrlen << 3) - hdr->pad - (16 - hdr->cmpre);
r = do_div(n, (16 - hdr->cmpri));
/* checks if calculation was without remainder and n fits into
Expand All @@ -567,12 +551,6 @@ static int ipv6_rpl_srh_rcv(struct sk_buff *skb)
return -1;
}

if (!pskb_may_pull(skb, ipv6_rpl_srh_size(n, hdr->cmpri,
hdr->cmpre))) {
kfree_skb(skb);
return -1;
}

hdr->segments_left--;
i = n - hdr->segments_left;

Expand All @@ -586,8 +564,7 @@ static int ipv6_rpl_srh_rcv(struct sk_buff *skb)
ipv6_rpl_srh_decompress(ohdr, hdr, &ipv6_hdr(skb)->daddr, n);
chdr = (struct ipv6_rpl_sr_hdr *)(buf + ((ohdr->hdrlen + 1) << 3));

if ((ipv6_addr_type(&ipv6_hdr(skb)->daddr) & IPV6_ADDR_MULTICAST) ||
(ipv6_addr_type(&ohdr->rpl_segaddr[i]) & IPV6_ADDR_MULTICAST)) {
if (ipv6_addr_is_multicast(&ohdr->rpl_segaddr[i])) {
kfree_skb(skb);
kfree(buf);
return -1;
Expand Down
7 changes: 0 additions & 7 deletions net/ipv6/rpl.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@ static void *ipv6_rpl_segdata_pos(const struct ipv6_rpl_sr_hdr *hdr, int i)
return (void *)&hdr->rpl_segdata[i * IPV6_PFXTAIL_LEN(hdr->cmpri)];
}

size_t ipv6_rpl_srh_size(unsigned char n, unsigned char cmpri,
unsigned char cmpre)
{
return sizeof(struct ipv6_rpl_sr_hdr) + (n * IPV6_PFXTAIL_LEN(cmpri)) +
IPV6_PFXTAIL_LEN(cmpre);
}

void ipv6_rpl_srh_decompress(struct ipv6_rpl_sr_hdr *outhdr,
const struct ipv6_rpl_sr_hdr *inhdr,
const struct in6_addr *daddr, unsigned char n)
Expand Down

0 comments on commit 4931062

Please sign in to comment.