Skip to content

Commit 7753c2f

Browse files
0x7f454c46davem330
authored andcommitted
net/tcp: Add option for TCP-AO to (not) hash header
Provide setsockopt() key flag that makes TCP-AO exclude hashing TCP header for peers that match the key. This is needed for interraction with middleboxes that may change TCP options, see RFC5925 (9.2). Co-developed-by: Francesco Ruggeri <[email protected]> Signed-off-by: Francesco Ruggeri <[email protected]> Co-developed-by: Salam Noureddine <[email protected]> Signed-off-by: Salam Noureddine <[email protected]> Signed-off-by: Dmitry Safonov <[email protected]> Acked-by: David Ahern <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 953af8e commit 7753c2f

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

include/uapi/linux/tcp.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,11 @@ struct tcp_diag_md5sig {
367367
#define TCP_AO_MAXKEYLEN 80
368368

369369
#define TCP_AO_KEYF_IFINDEX (1 << 0) /* L3 ifindex for VRF */
370+
#define TCP_AO_KEYF_EXCLUDE_OPT (1 << 1) /* "Indicates whether TCP
371+
* options other than TCP-AO
372+
* are included in the MAC
373+
* calculation"
374+
*/
370375

371376
struct tcp_ao_add { /* setsockopt(TCP_AO_ADD_KEY) */
372377
struct __kernel_sockaddr_storage addr; /* peer's address for the key */

net/ipv4/tcp_ao.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,8 @@ int tcp_ao_hash_hdr(unsigned short int family, char *ao_hash,
562562
WARN_ON_ONCE(1);
563563
goto clear_hash;
564564
}
565-
if (tcp_ao_hash_header(&hp, th, false,
565+
if (tcp_ao_hash_header(&hp, th,
566+
!!(key->keyflags & TCP_AO_KEYF_EXCLUDE_OPT),
566567
ao_hash, hash_offset, tcp_ao_maclen(key)))
567568
goto clear_hash;
568569
ahash_request_set_crypt(hp.req, NULL, hash_buf, 0);
@@ -610,7 +611,8 @@ int tcp_ao_hash_skb(unsigned short int family,
610611
goto clear_hash;
611612
if (tcp_ao_hash_pseudoheader(family, sk, skb, &hp, skb->len))
612613
goto clear_hash;
613-
if (tcp_ao_hash_header(&hp, th, false,
614+
if (tcp_ao_hash_header(&hp, th,
615+
!!(key->keyflags & TCP_AO_KEYF_EXCLUDE_OPT),
614616
ao_hash, hash_offset, tcp_ao_maclen(key)))
615617
goto clear_hash;
616618
if (tcp_sigpool_hash_skb_data(&hp, skb, th->doff << 2))
@@ -1454,7 +1456,7 @@ static struct tcp_ao_info *setsockopt_ao_info(struct sock *sk)
14541456
return ERR_PTR(-ESOCKTNOSUPPORT);
14551457
}
14561458

1457-
#define TCP_AO_KEYF_ALL (0)
1459+
#define TCP_AO_KEYF_ALL (TCP_AO_KEYF_EXCLUDE_OPT)
14581460

14591461
static struct tcp_ao_key *tcp_ao_key_alloc(struct sock *sk,
14601462
struct tcp_ao_add *cmd)

0 commit comments

Comments
 (0)