Commit 49310624 authored by Jakub Kicinski's avatar Jakub Kicinski

Merge branch 'ipv6-random-cleanup-for-extension-header'

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.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents 9a94d764 6db5dd2b
......@@ -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);
......
......@@ -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;
......@@ -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);
......@@ -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;
......@@ -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);
......@@ -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
......@@ -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;
......@@ -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;
......
......@@ -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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment