Skip to content

Commit 91579c9

Browse files
committed
Merge branch 'tcp-ao-md5-racepoits'
Dmitry Safonov says: ==================== net/tcp: TCP-AO and TCP-MD5 tracepoints Changes in v2: - Fix the build with CONFIG_IPV6=m (Eric Dumazet) - Move unused keyid/rnext/maclen later in the series to the patch that uses them (Simon Horman) - Reworked tcp_ao selftest lib to allow async tracing non-tcp events (was working on a stress-test that needs trace_kfree_skb() event, not in this series). - Separated selftest changes from kernel, as they now have a couple of unrelated to tracepoints changes - Wrote a few lines of Documentation/ - Link to v1: https://lore.kernel.org/r/[email protected] ==================== Signed-off-by: Dmitry Safonov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
2 parents d4cea2c + efe46fb commit 91579c9

File tree

9 files changed

+443
-157
lines changed

9 files changed

+443
-157
lines changed

Documentation/networking/tcp_ao.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,15 @@ TCP-AO per-socket counters are also duplicated with per-netns counters,
337337
exposed with SNMP. Those are ``TCPAOGood``, ``TCPAOBad``, ``TCPAOKeyNotFound``,
338338
``TCPAORequired`` and ``TCPAODroppedIcmps``.
339339

340+
For monitoring purposes, there are following TCP-AO trace events:
341+
``tcp_hash_bad_header``, ``tcp_hash_ao_required``, ``tcp_ao_handshake_failure``,
342+
``tcp_ao_wrong_maclen``, ``tcp_ao_wrong_maclen``, ``tcp_ao_key_not_found``,
343+
``tcp_ao_rnext_request``, ``tcp_ao_synack_no_key``, ``tcp_ao_snd_sne_update``,
344+
``tcp_ao_rcv_sne_update``. It's possible to separately enable any of them and
345+
one can filter them by net-namespace, 4-tuple, family, L3 index, and TCP header
346+
flags. If a segment has a TCP-AO header, the filters may also include
347+
keyid, rnext, and maclen. SNE updates include the rolled-over numbers.
348+
340349
RFC 5925 very permissively specifies how TCP port matching can be done for
341350
MKTs::
342351

include/net/tcp.h

Lines changed: 8 additions & 84 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

@@ -2386,21 +2373,15 @@ static inline void tcp_get_current_key(const struct sock *sk,
23862373

23872374
static inline bool tcp_key_is_md5(const struct tcp_key *key)
23882375
{
2389-
#ifdef CONFIG_TCP_MD5SIG
2390-
if (static_branch_unlikely(&tcp_md5_needed.key) &&
2391-
key->type == TCP_KEY_MD5)
2392-
return true;
2393-
#endif
2376+
if (static_branch_tcp_md5())
2377+
return key->type == TCP_KEY_MD5;
23942378
return false;
23952379
}
23962380

23972381
static inline bool tcp_key_is_ao(const struct tcp_key *key)
23982382
{
2399-
#ifdef CONFIG_TCP_AO
2400-
if (static_branch_unlikely(&tcp_ao_needed.key) &&
2401-
key->type == TCP_KEY_AO)
2402-
return true;
2403-
#endif
2383+
if (static_branch_tcp_ao())
2384+
return key->type == TCP_KEY_AO;
24042385
return false;
24052386
}
24062387

@@ -2812,66 +2793,9 @@ static inline bool tcp_ao_required(struct sock *sk, const void *saddr,
28122793
return false;
28132794
}
28142795

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

28772801
#endif /* _TCP_H */

include/net/tcp_ao.h

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ struct tcp_ao_hdr {
1919
u8 rnext_keyid;
2020
};
2121

22+
static inline u8 tcp_ao_hdr_maclen(const struct tcp_ao_hdr *aoh)
23+
{
24+
return aoh->length - sizeof(struct tcp_ao_hdr);
25+
}
26+
2227
struct tcp_ao_counters {
2328
atomic64_t pkt_good;
2429
atomic64_t pkt_bad;
@@ -144,43 +149,6 @@ extern struct static_key_false_deferred tcp_ao_needed;
144149
#define static_branch_tcp_ao() false
145150
#endif
146151

147-
static inline bool tcp_hash_should_produce_warnings(void)
148-
{
149-
return static_branch_tcp_md5() || static_branch_tcp_ao();
150-
}
151-
152-
#define tcp_hash_fail(msg, family, skb, fmt, ...) \
153-
do { \
154-
const struct tcphdr *th = tcp_hdr(skb); \
155-
char hdr_flags[6]; \
156-
char *f = hdr_flags; \
157-
\
158-
if (!tcp_hash_should_produce_warnings()) \
159-
break; \
160-
if (th->fin) \
161-
*f++ = 'F'; \
162-
if (th->syn) \
163-
*f++ = 'S'; \
164-
if (th->rst) \
165-
*f++ = 'R'; \
166-
if (th->psh) \
167-
*f++ = 'P'; \
168-
if (th->ack) \
169-
*f++ = '.'; \
170-
*f = 0; \
171-
if ((family) == AF_INET) { \
172-
net_info_ratelimited("%s for %pI4.%d->%pI4.%d [%s] " fmt "\n", \
173-
msg, &ip_hdr(skb)->saddr, ntohs(th->source), \
174-
&ip_hdr(skb)->daddr, ntohs(th->dest), \
175-
hdr_flags, ##__VA_ARGS__); \
176-
} else { \
177-
net_info_ratelimited("%s for [%pI6c].%d->[%pI6c].%d [%s]" fmt "\n", \
178-
msg, &ipv6_hdr(skb)->saddr, ntohs(th->source), \
179-
&ipv6_hdr(skb)->daddr, ntohs(th->dest), \
180-
hdr_flags, ##__VA_ARGS__); \
181-
} \
182-
} while (0)
183-
184152
#ifdef CONFIG_TCP_AO
185153
/* TCP-AO structures and functions */
186154
struct tcp4_ao_context {

0 commit comments

Comments
 (0)