@@ -911,17 +911,13 @@ static void tcp_v4_send_reset(const struct sock *sk, struct sk_buff *skb)
911911static void tcp_v4_send_ack (const struct sock * sk ,
912912 struct sk_buff * skb , u32 seq , u32 ack ,
913913 u32 win , u32 tsval , u32 tsecr , int oif ,
914- struct tcp_md5sig_key * key ,
914+ struct tcp_key * key ,
915915 int reply_flags , u8 tos , u32 txhash )
916916{
917917 const struct tcphdr * th = tcp_hdr (skb );
918918 struct {
919919 struct tcphdr th ;
920- __be32 opt [(TCPOLEN_TSTAMP_ALIGNED >> 2 )
921- #ifdef CONFIG_TCP_MD5SIG
922- + (TCPOLEN_MD5SIG_ALIGNED >> 2 )
923- #endif
924- ];
920+ __be32 opt [(MAX_TCP_OPTION_SPACE >> 2 )];
925921 } rep ;
926922 struct net * net = sock_net (sk );
927923 struct ip_reply_arg arg ;
@@ -952,7 +948,7 @@ static void tcp_v4_send_ack(const struct sock *sk,
952948 rep .th .window = htons (win );
953949
954950#ifdef CONFIG_TCP_MD5SIG
955- if (key ) {
951+ if (tcp_key_is_md5 ( key ) ) {
956952 int offset = (tsecr ) ? 3 : 0 ;
957953
958954 rep .opt [offset ++ ] = htonl ((TCPOPT_NOP << 24 ) |
@@ -963,9 +959,27 @@ static void tcp_v4_send_ack(const struct sock *sk,
963959 rep .th .doff = arg .iov [0 ].iov_len /4 ;
964960
965961 tcp_v4_md5_hash_hdr ((__u8 * ) & rep .opt [offset ],
966- key , ip_hdr (skb )-> saddr ,
962+ key -> md5_key , ip_hdr (skb )-> saddr ,
967963 ip_hdr (skb )-> daddr , & rep .th );
968964 }
965+ #endif
966+ #ifdef CONFIG_TCP_AO
967+ if (tcp_key_is_ao (key )) {
968+ int offset = (tsecr ) ? 3 : 0 ;
969+
970+ rep .opt [offset ++ ] = htonl ((TCPOPT_AO << 24 ) |
971+ (tcp_ao_len (key -> ao_key ) << 16 ) |
972+ (key -> ao_key -> sndid << 8 ) |
973+ key -> rcv_next );
974+ arg .iov [0 ].iov_len += round_up (tcp_ao_len (key -> ao_key ), 4 );
975+ rep .th .doff = arg .iov [0 ].iov_len / 4 ;
976+
977+ tcp_ao_hash_hdr (AF_INET , (char * )& rep .opt [offset ],
978+ key -> ao_key , key -> traffic_key ,
979+ (union tcp_ao_addr * )& ip_hdr (skb )-> saddr ,
980+ (union tcp_ao_addr * )& ip_hdr (skb )-> daddr ,
981+ & rep .th , key -> sne );
982+ }
969983#endif
970984 arg .flags = reply_flags ;
971985 arg .csum = csum_tcpudp_nofold (ip_hdr (skb )-> daddr ,
@@ -999,27 +1013,58 @@ static void tcp_v4_timewait_ack(struct sock *sk, struct sk_buff *skb)
9991013{
10001014 struct inet_timewait_sock * tw = inet_twsk (sk );
10011015 struct tcp_timewait_sock * tcptw = tcp_twsk (sk );
1016+ struct tcp_key key = {};
1017+ #ifdef CONFIG_TCP_AO
1018+ struct tcp_ao_info * ao_info ;
1019+
1020+ /* FIXME: the segment to-be-acked is not verified yet */
1021+ ao_info = rcu_dereference (tcptw -> ao_info );
1022+ if (ao_info ) {
1023+ const struct tcp_ao_hdr * aoh ;
1024+
1025+ if (tcp_parse_auth_options (tcp_hdr (skb ), NULL , & aoh )) {
1026+ inet_twsk_put (tw );
1027+ return ;
1028+ }
1029+
1030+ if (aoh )
1031+ key .ao_key = tcp_ao_established_key (ao_info , aoh -> rnext_keyid , -1 );
1032+ }
1033+ if (key .ao_key ) {
1034+ struct tcp_ao_key * rnext_key ;
1035+
1036+ key .traffic_key = snd_other_key (key .ao_key );
1037+ rnext_key = READ_ONCE (ao_info -> rnext_key );
1038+ key .rcv_next = rnext_key -> rcvid ;
1039+ key .type = TCP_KEY_AO ;
1040+ #else
1041+ if (0 ) {
1042+ #endif
1043+ #ifdef CONFIG_TCP_MD5SIG
1044+ } else if (static_branch_unlikely (& tcp_md5_needed .key )) {
1045+ key .md5_key = tcp_twsk_md5_key (tcptw );
1046+ if (key .md5_key )
1047+ key .type = TCP_KEY_MD5 ;
1048+ #endif
1049+ }
10021050
10031051 tcp_v4_send_ack (sk , skb ,
10041052 tcptw -> tw_snd_nxt , tcptw -> tw_rcv_nxt ,
10051053 tcptw -> tw_rcv_wnd >> tw -> tw_rcv_wscale ,
10061054 tcp_tw_tsval (tcptw ),
10071055 tcptw -> tw_ts_recent ,
1008- tw -> tw_bound_dev_if ,
1009- tcp_twsk_md5_key (tcptw ),
1056+ tw -> tw_bound_dev_if , & key ,
10101057 tw -> tw_transparent ? IP_REPLY_ARG_NOSRCCHECK : 0 ,
10111058 tw -> tw_tos ,
1012- tw -> tw_txhash
1013- );
1059+ tw -> tw_txhash );
10141060
10151061 inet_twsk_put (tw );
10161062}
10171063
10181064static void tcp_v4_reqsk_send_ack (const struct sock * sk , struct sk_buff * skb ,
10191065 struct request_sock * req )
10201066{
1021- const union tcp_md5_addr * addr ;
1022- int l3index ;
1067+ struct tcp_key key = {};
10231068
10241069 /* sk->sk_state == TCP_LISTEN -> for regular TCP_SYN_RECV
10251070 * sk->sk_state == TCP_SYN_RECV -> for Fast Open.
@@ -1032,15 +1077,24 @@ static void tcp_v4_reqsk_send_ack(const struct sock *sk, struct sk_buff *skb,
10321077 * exception of <SYN> segments, MUST be right-shifted by
10331078 * Rcv.Wind.Shift bits:
10341079 */
1035- addr = (union tcp_md5_addr * )& ip_hdr (skb )-> saddr ;
1036- l3index = tcp_v4_sdif (skb ) ? inet_iif (skb ) : 0 ;
1080+ #ifdef CONFIG_TCP_MD5SIG
1081+ if (static_branch_unlikely (& tcp_md5_needed .key )) {
1082+ const union tcp_md5_addr * addr ;
1083+ int l3index ;
1084+
1085+ addr = (union tcp_md5_addr * )& ip_hdr (skb )-> saddr ;
1086+ l3index = tcp_v4_sdif (skb ) ? inet_iif (skb ) : 0 ;
1087+ key .md5_key = tcp_md5_do_lookup (sk , l3index , addr , AF_INET );
1088+ if (key .md5_key )
1089+ key .type = TCP_KEY_MD5 ;
1090+ }
1091+ #endif
10371092 tcp_v4_send_ack (sk , skb , seq ,
10381093 tcp_rsk (req )-> rcv_nxt ,
10391094 req -> rsk_rcv_wnd >> inet_rsk (req )-> rcv_wscale ,
10401095 tcp_rsk_tsval (tcp_rsk (req )),
10411096 READ_ONCE (req -> ts_recent ),
1042- 0 ,
1043- tcp_md5_do_lookup (sk , l3index , addr , AF_INET ),
1097+ 0 , & key ,
10441098 inet_rsk (req )-> no_srccheck ? IP_REPLY_ARG_NOSRCCHECK : 0 ,
10451099 ip_hdr (skb )-> tos ,
10461100 READ_ONCE (tcp_rsk (req )-> txhash ));
@@ -2404,7 +2458,7 @@ void tcp_v4_destroy_sock(struct sock *sk)
24042458 rcu_assign_pointer (tp -> md5sig_info , NULL );
24052459 }
24062460#endif
2407- tcp_ao_destroy_sock (sk );
2461+ tcp_ao_destroy_sock (sk , false );
24082462
24092463 /* Clean up a referenced TCP bind bucket. */
24102464 if (inet_csk (sk )-> icsk_bind_hash )
0 commit comments