Skip to content

Commit f62c751

Browse files
0x7f454c46kuba-moo
authored andcommitted
net/tcp: Separate tcp_md5sig_info allocation into tcp_md5sig_info_add()
Add a helper to allocate tcp_md5sig_info, that will help later to do/allocate things when info allocated, once per socket. Signed-off-by: Dmitry Safonov <[email protected]> Reviewed-by: Eric Dumazet <[email protected]> Acked-by: Jakub Kicinski <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent eb8c507 commit f62c751

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

net/ipv4/tcp_ipv4.c

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,24 @@ struct tcp_md5sig_key *tcp_v4_md5_lookup(const struct sock *sk,
11611161
}
11621162
EXPORT_SYMBOL(tcp_v4_md5_lookup);
11631163

1164+
static int tcp_md5sig_info_add(struct sock *sk, gfp_t gfp)
1165+
{
1166+
struct tcp_sock *tp = tcp_sk(sk);
1167+
struct tcp_md5sig_info *md5sig;
1168+
1169+
if (rcu_dereference_protected(tp->md5sig_info, lockdep_sock_is_held(sk)))
1170+
return 0;
1171+
1172+
md5sig = kmalloc(sizeof(*md5sig), gfp);
1173+
if (!md5sig)
1174+
return -ENOMEM;
1175+
1176+
sk_gso_disable(sk);
1177+
INIT_HLIST_HEAD(&md5sig->head);
1178+
rcu_assign_pointer(tp->md5sig_info, md5sig);
1179+
return 0;
1180+
}
1181+
11641182
/* This can be called on a newly created socket, from other files */
11651183
int tcp_md5_do_add(struct sock *sk, const union tcp_md5_addr *addr,
11661184
int family, u8 prefixlen, int l3index, u8 flags,
@@ -1191,17 +1209,11 @@ int tcp_md5_do_add(struct sock *sk, const union tcp_md5_addr *addr,
11911209
return 0;
11921210
}
11931211

1212+
if (tcp_md5sig_info_add(sk, gfp))
1213+
return -ENOMEM;
1214+
11941215
md5sig = rcu_dereference_protected(tp->md5sig_info,
11951216
lockdep_sock_is_held(sk));
1196-
if (!md5sig) {
1197-
md5sig = kmalloc(sizeof(*md5sig), gfp);
1198-
if (!md5sig)
1199-
return -ENOMEM;
1200-
1201-
sk_gso_disable(sk);
1202-
INIT_HLIST_HEAD(&md5sig->head);
1203-
rcu_assign_pointer(tp->md5sig_info, md5sig);
1204-
}
12051217

12061218
key = sock_kmalloc(sk, sizeof(*key), gfp | __GFP_ZERO);
12071219
if (!key)

0 commit comments

Comments
 (0)