Skip to content

Commit 811efc0

Browse files
0x7f454c46davem330
authored andcommitted
net/tcp: Move tcp_inbound_hash() from headers
Two reasons: 1. It's grown up enough 2. In order to not do header spaghetti by including <trace/events/tcp.h>, which is necessary for TCP tracepoints. While at it, unexport and make static tcp_inbound_ao_hash(). Reviewed-by: Eric Dumazet <[email protected]> Signed-off-by: Dmitry Safonov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 7286308 commit 811efc0

File tree

2 files changed

+76
-76
lines changed

2 files changed

+76
-76
lines changed

include/net/tcp.h

Lines changed: 4 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1863,12 +1863,6 @@ tcp_md5_do_lookup_any_l3index(const struct sock *sk,
18631863
return __tcp_md5_do_lookup(sk, 0, addr, family, true);
18641864
}
18651865

1866-
enum skb_drop_reason
1867-
tcp_inbound_md5_hash(const struct sock *sk, const struct sk_buff *skb,
1868-
const void *saddr, const void *daddr,
1869-
int family, int l3index, const __u8 *hash_location);
1870-
1871-
18721866
#define tcp_twsk_md5_key(twsk) ((twsk)->tw_md5_key)
18731867
#else
18741868
static inline struct tcp_md5sig_key *
@@ -1885,13 +1879,6 @@ tcp_md5_do_lookup_any_l3index(const struct sock *sk,
18851879
return NULL;
18861880
}
18871881

1888-
static inline enum skb_drop_reason
1889-
tcp_inbound_md5_hash(const struct sock *sk, const struct sk_buff *skb,
1890-
const void *saddr, const void *daddr,
1891-
int family, int l3index, const __u8 *hash_location)
1892-
{
1893-
return SKB_NOT_DROPPED_YET;
1894-
}
18951882
#define tcp_twsk_md5_key(twsk) NULL
18961883
#endif
18971884

@@ -2806,66 +2793,9 @@ static inline bool tcp_ao_required(struct sock *sk, const void *saddr,
28062793
return false;
28072794
}
28082795

2809-
/* Called with rcu_read_lock() */
2810-
static inline enum skb_drop_reason
2811-
tcp_inbound_hash(struct sock *sk, const struct request_sock *req,
2812-
const struct sk_buff *skb,
2813-
const void *saddr, const void *daddr,
2814-
int family, int dif, int sdif)
2815-
{
2816-
const struct tcphdr *th = tcp_hdr(skb);
2817-
const struct tcp_ao_hdr *aoh;
2818-
const __u8 *md5_location;
2819-
int l3index;
2820-
2821-
/* Invalid option or two times meet any of auth options */
2822-
if (tcp_parse_auth_options(th, &md5_location, &aoh)) {
2823-
tcp_hash_fail("TCP segment has incorrect auth options set",
2824-
family, skb, "");
2825-
return SKB_DROP_REASON_TCP_AUTH_HDR;
2826-
}
2827-
2828-
if (req) {
2829-
if (tcp_rsk_used_ao(req) != !!aoh) {
2830-
NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPAOBAD);
2831-
tcp_hash_fail("TCP connection can't start/end using TCP-AO",
2832-
family, skb, "%s",
2833-
!aoh ? "missing AO" : "AO signed");
2834-
return SKB_DROP_REASON_TCP_AOFAILURE;
2835-
}
2836-
}
2837-
2838-
/* sdif set, means packet ingressed via a device
2839-
* in an L3 domain and dif is set to the l3mdev
2840-
*/
2841-
l3index = sdif ? dif : 0;
2842-
2843-
/* Fast path: unsigned segments */
2844-
if (likely(!md5_location && !aoh)) {
2845-
/* Drop if there's TCP-MD5 or TCP-AO key with any rcvid/sndid
2846-
* for the remote peer. On TCP-AO established connection
2847-
* the last key is impossible to remove, so there's
2848-
* always at least one current_key.
2849-
*/
2850-
if (tcp_ao_required(sk, saddr, family, l3index, true)) {
2851-
tcp_hash_fail("AO hash is required, but not found",
2852-
family, skb, "L3 index %d", l3index);
2853-
return SKB_DROP_REASON_TCP_AONOTFOUND;
2854-
}
2855-
if (unlikely(tcp_md5_do_lookup(sk, l3index, saddr, family))) {
2856-
NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPMD5NOTFOUND);
2857-
tcp_hash_fail("MD5 Hash not found",
2858-
family, skb, "L3 index %d", l3index);
2859-
return SKB_DROP_REASON_TCP_MD5NOTFOUND;
2860-
}
2861-
return SKB_NOT_DROPPED_YET;
2862-
}
2863-
2864-
if (aoh)
2865-
return tcp_inbound_ao_hash(sk, skb, family, req, l3index, aoh);
2866-
2867-
return tcp_inbound_md5_hash(sk, skb, saddr, daddr, family,
2868-
l3index, md5_location);
2869-
}
2796+
enum skb_drop_reason tcp_inbound_hash(struct sock *sk,
2797+
const struct request_sock *req, const struct sk_buff *skb,
2798+
const void *saddr, const void *daddr,
2799+
int family, int dif, int sdif);
28702800

28712801
#endif /* _TCP_H */

net/ipv4/tcp.c

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4463,7 +4463,7 @@ int tcp_md5_hash_key(struct tcp_sigpool *hp,
44634463
EXPORT_SYMBOL(tcp_md5_hash_key);
44644464

44654465
/* Called with rcu_read_lock() */
4466-
enum skb_drop_reason
4466+
static enum skb_drop_reason
44674467
tcp_inbound_md5_hash(const struct sock *sk, const struct sk_buff *skb,
44684468
const void *saddr, const void *daddr,
44694469
int family, int l3index, const __u8 *hash_location)
@@ -4517,10 +4517,80 @@ tcp_inbound_md5_hash(const struct sock *sk, const struct sk_buff *skb,
45174517
}
45184518
return SKB_NOT_DROPPED_YET;
45194519
}
4520-
EXPORT_SYMBOL(tcp_inbound_md5_hash);
4520+
#else
4521+
static inline enum skb_drop_reason
4522+
tcp_inbound_md5_hash(const struct sock *sk, const struct sk_buff *skb,
4523+
const void *saddr, const void *daddr,
4524+
int family, int l3index, const __u8 *hash_location)
4525+
{
4526+
return SKB_NOT_DROPPED_YET;
4527+
}
45214528

45224529
#endif
45234530

4531+
/* Called with rcu_read_lock() */
4532+
enum skb_drop_reason
4533+
tcp_inbound_hash(struct sock *sk, const struct request_sock *req,
4534+
const struct sk_buff *skb,
4535+
const void *saddr, const void *daddr,
4536+
int family, int dif, int sdif)
4537+
{
4538+
const struct tcphdr *th = tcp_hdr(skb);
4539+
const struct tcp_ao_hdr *aoh;
4540+
const __u8 *md5_location;
4541+
int l3index;
4542+
4543+
/* Invalid option or two times meet any of auth options */
4544+
if (tcp_parse_auth_options(th, &md5_location, &aoh)) {
4545+
tcp_hash_fail("TCP segment has incorrect auth options set",
4546+
family, skb, "");
4547+
return SKB_DROP_REASON_TCP_AUTH_HDR;
4548+
}
4549+
4550+
if (req) {
4551+
if (tcp_rsk_used_ao(req) != !!aoh) {
4552+
NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPAOBAD);
4553+
tcp_hash_fail("TCP connection can't start/end using TCP-AO",
4554+
family, skb, "%s",
4555+
!aoh ? "missing AO" : "AO signed");
4556+
return SKB_DROP_REASON_TCP_AOFAILURE;
4557+
}
4558+
}
4559+
4560+
/* sdif set, means packet ingressed via a device
4561+
* in an L3 domain and dif is set to the l3mdev
4562+
*/
4563+
l3index = sdif ? dif : 0;
4564+
4565+
/* Fast path: unsigned segments */
4566+
if (likely(!md5_location && !aoh)) {
4567+
/* Drop if there's TCP-MD5 or TCP-AO key with any rcvid/sndid
4568+
* for the remote peer. On TCP-AO established connection
4569+
* the last key is impossible to remove, so there's
4570+
* always at least one current_key.
4571+
*/
4572+
if (tcp_ao_required(sk, saddr, family, l3index, true)) {
4573+
tcp_hash_fail("AO hash is required, but not found",
4574+
family, skb, "L3 index %d", l3index);
4575+
return SKB_DROP_REASON_TCP_AONOTFOUND;
4576+
}
4577+
if (unlikely(tcp_md5_do_lookup(sk, l3index, saddr, family))) {
4578+
NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPMD5NOTFOUND);
4579+
tcp_hash_fail("MD5 Hash not found",
4580+
family, skb, "L3 index %d", l3index);
4581+
return SKB_DROP_REASON_TCP_MD5NOTFOUND;
4582+
}
4583+
return SKB_NOT_DROPPED_YET;
4584+
}
4585+
4586+
if (aoh)
4587+
return tcp_inbound_ao_hash(sk, skb, family, req, l3index, aoh);
4588+
4589+
return tcp_inbound_md5_hash(sk, skb, saddr, daddr, family,
4590+
l3index, md5_location);
4591+
}
4592+
EXPORT_SYMBOL_GPL(tcp_inbound_hash);
4593+
45244594
void tcp_done(struct sock *sk)
45254595
{
45264596
struct request_sock *req;

0 commit comments

Comments
 (0)