Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

xfrm: ipv6: move mip6_destopt_offset into xfrm core

This helper is relatively small, just move this to the xfrm core
and call it directly.

Next patch does the same for the ROUTING type.

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>

authored by

Florian Westphal and committed by
Steffen Klassert
37b9e7eb 9acf4d3b

+57 -49
-49
net/ipv6/mip6.c
··· 247 247 return err; 248 248 } 249 249 250 - static int mip6_destopt_offset(struct xfrm_state *x, struct sk_buff *skb, 251 - u8 **nexthdr) 252 - { 253 - u16 offset = sizeof(struct ipv6hdr); 254 - struct ipv6_opt_hdr *exthdr = 255 - (struct ipv6_opt_hdr *)(ipv6_hdr(skb) + 1); 256 - const unsigned char *nh = skb_network_header(skb); 257 - unsigned int packet_len = skb_tail_pointer(skb) - 258 - skb_network_header(skb); 259 - int found_rhdr = 0; 260 - 261 - *nexthdr = &ipv6_hdr(skb)->nexthdr; 262 - 263 - while (offset + 1 <= packet_len) { 264 - 265 - switch (**nexthdr) { 266 - case NEXTHDR_HOP: 267 - break; 268 - case NEXTHDR_ROUTING: 269 - found_rhdr = 1; 270 - break; 271 - case NEXTHDR_DEST: 272 - /* 273 - * HAO MUST NOT appear more than once. 274 - * XXX: It is better to try to find by the end of 275 - * XXX: packet if HAO exists. 276 - */ 277 - if (ipv6_find_tlv(skb, offset, IPV6_TLV_HAO) >= 0) { 278 - net_dbg_ratelimited("mip6: hao exists already, override\n"); 279 - return offset; 280 - } 281 - 282 - if (found_rhdr) 283 - return offset; 284 - 285 - break; 286 - default: 287 - return offset; 288 - } 289 - 290 - offset += ipv6_optlen(exthdr); 291 - *nexthdr = &exthdr->nexthdr; 292 - exthdr = (struct ipv6_opt_hdr *)(nh + offset); 293 - } 294 - 295 - return offset; 296 - } 297 - 298 250 static int mip6_destopt_init_state(struct xfrm_state *x) 299 251 { 300 252 if (x->id.spi) { ··· 284 332 .input = mip6_destopt_input, 285 333 .output = mip6_destopt_output, 286 334 .reject = mip6_destopt_reject, 287 - .hdr_offset = mip6_destopt_offset, 288 335 }; 289 336 290 337 static int mip6_rthdr_input(struct xfrm_state *x, struct sk_buff *skb)
+57
net/xfrm/xfrm_output.c
··· 77 77 return 0; 78 78 } 79 79 80 + #if IS_ENABLED(CONFIG_IPV6_MIP6) 81 + static int mip6_destopt_offset(struct xfrm_state *x, struct sk_buff *skb, 82 + u8 **nexthdr) 83 + { 84 + u16 offset = sizeof(struct ipv6hdr); 85 + struct ipv6_opt_hdr *exthdr = 86 + (struct ipv6_opt_hdr *)(ipv6_hdr(skb) + 1); 87 + const unsigned char *nh = skb_network_header(skb); 88 + unsigned int packet_len = skb_tail_pointer(skb) - 89 + skb_network_header(skb); 90 + int found_rhdr = 0; 91 + 92 + *nexthdr = &ipv6_hdr(skb)->nexthdr; 93 + 94 + while (offset + 1 <= packet_len) { 95 + switch (**nexthdr) { 96 + case NEXTHDR_HOP: 97 + break; 98 + case NEXTHDR_ROUTING: 99 + found_rhdr = 1; 100 + break; 101 + case NEXTHDR_DEST: 102 + /* HAO MUST NOT appear more than once. 103 + * XXX: It is better to try to find by the end of 104 + * XXX: packet if HAO exists. 105 + */ 106 + if (ipv6_find_tlv(skb, offset, IPV6_TLV_HAO) >= 0) { 107 + net_dbg_ratelimited("mip6: hao exists already, override\n"); 108 + return offset; 109 + } 110 + 111 + if (found_rhdr) 112 + return offset; 113 + 114 + break; 115 + default: 116 + return offset; 117 + } 118 + 119 + offset += ipv6_optlen(exthdr); 120 + *nexthdr = &exthdr->nexthdr; 121 + exthdr = (struct ipv6_opt_hdr *)(nh + offset); 122 + } 123 + 124 + return offset; 125 + } 126 + #endif 127 + 80 128 static int xfrm6_hdr_offset(struct xfrm_state *x, struct sk_buff *skb, u8 **prevhdr) 81 129 { 130 + switch (x->type->proto) { 131 + #if IS_ENABLED(CONFIG_IPV6_MIP6) 132 + case IPPROTO_DSTOPTS: 133 + return mip6_destopt_offset(x, skb, prevhdr); 134 + #endif 135 + default: 136 + break; 137 + } 138 + 82 139 return x->type->hdr_offset(x, skb, prevhdr); 83 140 } 84 141