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

ipv4: share tcp_v4_save_options() with cookie_v4_check()

cookie_v4_check() allocates ip_options_rcu in the same way
with tcp_v4_save_options(), we can just make it a helper function.

Cc: Krzysztof Kolasa <kkolasa@winsoft.pl>
Cc: Eric Dumazet <edumazet@google.com>
Signed-off-by: Cong Wang <cwang@twopensource.com>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Acked-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Cong Wang and committed by
David S. Miller
e25f866f 2077eebf

+21 -29
+20
include/net/tcp.h
··· 1666 1666 void tcp_v4_init(void); 1667 1667 void tcp_init(void); 1668 1668 1669 + /* 1670 + * Save and compile IPv4 options, return a pointer to it 1671 + */ 1672 + static inline struct ip_options_rcu *tcp_v4_save_options(struct sk_buff *skb) 1673 + { 1674 + const struct ip_options *opt = &TCP_SKB_CB(skb)->header.h4.opt; 1675 + struct ip_options_rcu *dopt = NULL; 1676 + 1677 + if (opt && opt->optlen) { 1678 + int opt_size = sizeof(*dopt) + opt->optlen; 1679 + 1680 + dopt = kmalloc(opt_size, GFP_ATOMIC); 1681 + if (dopt && __ip_options_echo(&dopt->opt, skb, opt)) { 1682 + kfree(dopt); 1683 + dopt = NULL; 1684 + } 1685 + } 1686 + return dopt; 1687 + } 1688 + 1669 1689 #endif /* _TCP_H */
+1 -9
net/ipv4/syncookies.c
··· 317 317 /* We throwed the options of the initial SYN away, so we hope 318 318 * the ACK carries the same options again (see RFC1122 4.2.3.8) 319 319 */ 320 - if (opt && opt->optlen) { 321 - int opt_size = sizeof(struct ip_options_rcu) + opt->optlen; 322 - 323 - ireq->opt = kmalloc(opt_size, GFP_ATOMIC); 324 - if (ireq->opt != NULL && __ip_options_echo(&ireq->opt->opt, skb, opt)) { 325 - kfree(ireq->opt); 326 - ireq->opt = NULL; 327 - } 328 - } 320 + ireq->opt = tcp_v4_save_options(skb); 329 321 330 322 if (security_inet_conn_request(sk, skb, req)) { 331 323 reqsk_free(req);
-20
net/ipv4/tcp_ipv4.c
··· 880 880 } 881 881 EXPORT_SYMBOL(tcp_syn_flood_action); 882 882 883 - /* 884 - * Save and compile IPv4 options into the request_sock if needed. 885 - */ 886 - static struct ip_options_rcu *tcp_v4_save_options(struct sk_buff *skb) 887 - { 888 - const struct ip_options *opt = &TCP_SKB_CB(skb)->header.h4.opt; 889 - struct ip_options_rcu *dopt = NULL; 890 - 891 - if (opt && opt->optlen) { 892 - int opt_size = sizeof(*dopt) + opt->optlen; 893 - 894 - dopt = kmalloc(opt_size, GFP_ATOMIC); 895 - if (dopt && __ip_options_echo(&dopt->opt, skb, opt)) { 896 - kfree(dopt); 897 - dopt = NULL; 898 - } 899 - } 900 - return dopt; 901 - } 902 - 903 883 #ifdef CONFIG_TCP_MD5SIG 904 884 /* 905 885 * RFC2385 MD5 checksumming requires a mapping of