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

ESP: Export esp_output_fill_trailer function

The esp fill trailer method is identical for both
IPv6 and IPv4.

Share the implementation for esp6 and esp to avoid
code duplication in addition it could be also used
at various drivers code.

Signed-off-by: Raed Salem <raeds@mellanox.com>
Reviewed-by: Boris Pismenny <borisp@mellanox.com>
Reviewed-by: Saeed Mahameed <saeedm@mellanox.com>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>

authored by

Raed Salem and committed by
Steffen Klassert
dda520c4 a4c278d1

+16 -32
+16
include/net/esp.h
··· 11 11 return (struct ip_esp_hdr *)skb_transport_header(skb); 12 12 } 13 13 14 + static inline void esp_output_fill_trailer(u8 *tail, int tfclen, int plen, __u8 proto) 15 + { 16 + /* Fill padding... */ 17 + if (tfclen) { 18 + memset(tail, 0, tfclen); 19 + tail += tfclen; 20 + } 21 + do { 22 + int i; 23 + for (i = 0; i < plen - 2; i++) 24 + tail[i] = i + 1; 25 + } while (0); 26 + tail[plen - 2] = plen - 2; 27 + tail[plen - 1] = proto; 28 + } 29 + 14 30 struct esp_info { 15 31 struct ip_esp_hdr *esph; 16 32 __be64 seqno;
-16
net/ipv4/esp4.c
··· 341 341 esp_output_done(base, err); 342 342 } 343 343 344 - static void esp_output_fill_trailer(u8 *tail, int tfclen, int plen, __u8 proto) 345 - { 346 - /* Fill padding... */ 347 - if (tfclen) { 348 - memset(tail, 0, tfclen); 349 - tail += tfclen; 350 - } 351 - do { 352 - int i; 353 - for (i = 0; i < plen - 2; i++) 354 - tail[i] = i + 1; 355 - } while (0); 356 - tail[plen - 2] = plen - 2; 357 - tail[plen - 1] = proto; 358 - } 359 - 360 344 static struct ip_esp_hdr *esp_output_udp_encap(struct sk_buff *skb, 361 345 int encap_type, 362 346 struct esp_info *esp,
-16
net/ipv6/esp6.c
··· 207 207 esp_output_done(base, err); 208 208 } 209 209 210 - static void esp_output_fill_trailer(u8 *tail, int tfclen, int plen, __u8 proto) 211 - { 212 - /* Fill padding... */ 213 - if (tfclen) { 214 - memset(tail, 0, tfclen); 215 - tail += tfclen; 216 - } 217 - do { 218 - int i; 219 - for (i = 0; i < plen - 2; i++) 220 - tail[i] = i + 1; 221 - } while (0); 222 - tail[plen - 2] = plen - 2; 223 - tail[plen - 1] = proto; 224 - } 225 - 226 210 int esp6_output_head(struct xfrm_state *x, struct sk_buff *skb, struct esp_info *esp) 227 211 { 228 212 u8 *tail;