Skip to content

Commit

Permalink
ipv4: share tcp_v4_save_options() with cookie_v4_check()
Browse files Browse the repository at this point in the history
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 <[email protected]>
Cc: Eric Dumazet <[email protected]>
Signed-off-by: Cong Wang <[email protected]>
Signed-off-by: Cong Wang <[email protected]>
Acked-by: Eric Dumazet <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
congwang1986 authored and davem330 committed Oct 17, 2014
1 parent 2077eeb commit e25f866
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 29 deletions.
20 changes: 20 additions & 0 deletions include/net/tcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -1666,4 +1666,24 @@ int tcpv4_offload_init(void);
void tcp_v4_init(void);
void tcp_init(void);

/*
* Save and compile IPv4 options, return a pointer to it
*/
static inline struct ip_options_rcu *tcp_v4_save_options(struct sk_buff *skb)
{
const struct ip_options *opt = &TCP_SKB_CB(skb)->header.h4.opt;
struct ip_options_rcu *dopt = NULL;

if (opt && opt->optlen) {
int opt_size = sizeof(*dopt) + opt->optlen;

dopt = kmalloc(opt_size, GFP_ATOMIC);
if (dopt && __ip_options_echo(&dopt->opt, skb, opt)) {
kfree(dopt);
dopt = NULL;
}
}
return dopt;
}

#endif /* _TCP_H */
10 changes: 1 addition & 9 deletions net/ipv4/syncookies.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,15 +317,7 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb,
/* We throwed the options of the initial SYN away, so we hope
* the ACK carries the same options again (see RFC1122 4.2.3.8)
*/
if (opt && opt->optlen) {
int opt_size = sizeof(struct ip_options_rcu) + opt->optlen;

ireq->opt = kmalloc(opt_size, GFP_ATOMIC);
if (ireq->opt != NULL && __ip_options_echo(&ireq->opt->opt, skb, opt)) {
kfree(ireq->opt);
ireq->opt = NULL;
}
}
ireq->opt = tcp_v4_save_options(skb);

if (security_inet_conn_request(sk, skb, req)) {
reqsk_free(req);
Expand Down
20 changes: 0 additions & 20 deletions net/ipv4/tcp_ipv4.c
Original file line number Diff line number Diff line change
Expand Up @@ -880,26 +880,6 @@ bool tcp_syn_flood_action(struct sock *sk,
}
EXPORT_SYMBOL(tcp_syn_flood_action);

/*
* Save and compile IPv4 options into the request_sock if needed.
*/
static struct ip_options_rcu *tcp_v4_save_options(struct sk_buff *skb)
{
const struct ip_options *opt = &TCP_SKB_CB(skb)->header.h4.opt;
struct ip_options_rcu *dopt = NULL;

if (opt && opt->optlen) {
int opt_size = sizeof(*dopt) + opt->optlen;

dopt = kmalloc(opt_size, GFP_ATOMIC);
if (dopt && __ip_options_echo(&dopt->opt, skb, opt)) {
kfree(dopt);
dopt = NULL;
}
}
return dopt;
}

#ifdef CONFIG_TCP_MD5SIG
/*
* RFC2385 MD5 checksumming requires a mapping of
Expand Down

0 comments on commit e25f866

Please sign in to comment.