2828#include <linux/percpu.h>
2929#include <linux/skbuff.h>
3030#include <linux/dmaengine.h>
31+ #include <linux/crypto.h>
3132
3233#include <net/inet_connection_sock.h>
3334#include <net/inet_timewait_sock.h>
@@ -161,6 +162,7 @@ extern void tcp_time_wait(struct sock *sk, int state, int timeo);
161162#define TCPOPT_SACK_PERM 4 /* SACK Permitted */
162163#define TCPOPT_SACK 5 /* SACK Block */
163164#define TCPOPT_TIMESTAMP 8 /* Better RTT estimations/PAWS */
165+ #define TCPOPT_MD5SIG 19 /* MD5 Signature (RFC2385) */
164166
165167/*
166168 * TCP option lengths
@@ -170,6 +172,7 @@ extern void tcp_time_wait(struct sock *sk, int state, int timeo);
170172#define TCPOLEN_WINDOW 3
171173#define TCPOLEN_SACK_PERM 2
172174#define TCPOLEN_TIMESTAMP 10
175+ #define TCPOLEN_MD5SIG 18
173176
174177/* But this is what stacks really send out. */
175178#define TCPOLEN_TSTAMP_ALIGNED 12
@@ -178,6 +181,7 @@ extern void tcp_time_wait(struct sock *sk, int state, int timeo);
178181#define TCPOLEN_SACK_BASE 2
179182#define TCPOLEN_SACK_BASE_ALIGNED 4
180183#define TCPOLEN_SACK_PERBLOCK 8
184+ #define TCPOLEN_MD5SIG_ALIGNED 20
181185
182186/* Flags in tp->nonagle */
183187#define TCP_NAGLE_OFF 1 /* Nagle's algo is disabled */
@@ -299,6 +303,8 @@ extern void tcp_cleanup_rbuf(struct sock *sk, int copied);
299303extern int tcp_twsk_unique (struct sock * sk ,
300304 struct sock * sktw , void * twp );
301305
306+ extern void tcp_twsk_destructor (struct sock * sk );
307+
302308static inline void tcp_dec_quickack_mode (struct sock * sk ,
303309 const unsigned int pkts )
304310{
@@ -1064,6 +1070,114 @@ static inline void clear_all_retrans_hints(struct tcp_sock *tp){
10641070 tp -> fastpath_skb_hint = NULL ;
10651071}
10661072
1073+ /* MD5 Signature */
1074+ struct crypto_hash ;
1075+
1076+ /* - key database */
1077+ struct tcp_md5sig_key {
1078+ u8 * key ;
1079+ u8 keylen ;
1080+ };
1081+
1082+ struct tcp4_md5sig_key {
1083+ u8 * key ;
1084+ u16 keylen ;
1085+ __be32 addr ;
1086+ };
1087+
1088+ struct tcp6_md5sig_key {
1089+ u8 * key ;
1090+ u16 keylen ;
1091+ #if 0
1092+ u32 scope_id ; /* XXX */
1093+ #endif
1094+ struct in6_addr addr ;
1095+ };
1096+
1097+ /* - sock block */
1098+ struct tcp_md5sig_info {
1099+ struct tcp4_md5sig_key * keys4 ;
1100+ #if defined(CONFIG_IPV6 ) || defined(CONFIG_IPV6_MODULE )
1101+ struct tcp6_md5sig_key * keys6 ;
1102+ u32 entries6 ;
1103+ u32 alloced6 ;
1104+ #endif
1105+ u32 entries4 ;
1106+ u32 alloced4 ;
1107+ };
1108+
1109+ /* - pseudo header */
1110+ struct tcp4_pseudohdr {
1111+ __be32 saddr ;
1112+ __be32 daddr ;
1113+ __u8 pad ;
1114+ __u8 protocol ;
1115+ __be16 len ;
1116+ };
1117+
1118+ struct tcp6_pseudohdr {
1119+ struct in6_addr saddr ;
1120+ struct in6_addr daddr ;
1121+ __be32 len ;
1122+ __be32 protocol ; /* including padding */
1123+ };
1124+
1125+ union tcp_md5sum_block {
1126+ struct tcp4_pseudohdr ip4 ;
1127+ #if defined(CONFIG_IPV6 ) || defined(CONFIG_IPV6_MODULE )
1128+ struct tcp6_pseudohdr ip6 ;
1129+ #endif
1130+ };
1131+
1132+ /* - pool: digest algorithm, hash description and scratch buffer */
1133+ struct tcp_md5sig_pool {
1134+ struct hash_desc md5_desc ;
1135+ union tcp_md5sum_block md5_blk ;
1136+ };
1137+
1138+ #define TCP_MD5SIG_MAXKEYS (~(u32)0) /* really?! */
1139+
1140+ /* - functions */
1141+ extern int tcp_v4_calc_md5_hash (char * md5_hash ,
1142+ struct tcp_md5sig_key * key ,
1143+ struct sock * sk ,
1144+ struct dst_entry * dst ,
1145+ struct request_sock * req ,
1146+ struct tcphdr * th ,
1147+ int protocol , int tcplen );
1148+ extern struct tcp_md5sig_key * tcp_v4_md5_lookup (struct sock * sk ,
1149+ struct sock * addr_sk );
1150+
1151+ extern int tcp_v4_md5_do_add (struct sock * sk ,
1152+ __be32 addr ,
1153+ u8 * newkey ,
1154+ u8 newkeylen );
1155+
1156+ extern int tcp_v4_md5_do_del (struct sock * sk ,
1157+ u32 addr );
1158+
1159+ extern struct tcp_md5sig_pool * * tcp_alloc_md5sig_pool (void );
1160+ extern void tcp_free_md5sig_pool (void );
1161+
1162+ extern struct tcp_md5sig_pool * __tcp_get_md5sig_pool (int cpu );
1163+ extern void __tcp_put_md5sig_pool (void );
1164+
1165+ static inline
1166+ struct tcp_md5sig_pool * tcp_get_md5sig_pool (void )
1167+ {
1168+ int cpu = get_cpu ();
1169+ struct tcp_md5sig_pool * ret = __tcp_get_md5sig_pool (cpu );
1170+ if (!ret )
1171+ put_cpu ();
1172+ return ret ;
1173+ }
1174+
1175+ static inline void tcp_put_md5sig_pool (void )
1176+ {
1177+ __tcp_put_md5sig_pool ();
1178+ put_cpu ();
1179+ }
1180+
10671181/* /proc */
10681182enum tcp_seq_states {
10691183 TCP_SEQ_STATE_LISTENING ,
@@ -1103,6 +1217,35 @@ extern int tcp4_proc_init(void);
11031217extern void tcp4_proc_exit (void );
11041218#endif
11051219
1220+ /* TCP af-specific functions */
1221+ struct tcp_sock_af_ops {
1222+ #ifdef CONFIG_TCP_MD5SIG
1223+ struct tcp_md5sig_key * (* md5_lookup ) (struct sock * sk ,
1224+ struct sock * addr_sk );
1225+ int (* calc_md5_hash ) (char * location ,
1226+ struct tcp_md5sig_key * md5 ,
1227+ struct sock * sk ,
1228+ struct dst_entry * dst ,
1229+ struct request_sock * req ,
1230+ struct tcphdr * th ,
1231+ int protocol , int len );
1232+ int (* md5_add ) (struct sock * sk ,
1233+ struct sock * addr_sk ,
1234+ u8 * newkey ,
1235+ u8 len );
1236+ int (* md5_parse ) (struct sock * sk ,
1237+ char __user * optval ,
1238+ int optlen );
1239+ #endif
1240+ };
1241+
1242+ struct tcp_request_sock_ops {
1243+ #ifdef CONFIG_TCP_MD5SIG
1244+ struct tcp_md5sig_key * (* md5_lookup ) (struct sock * sk ,
1245+ struct request_sock * req );
1246+ #endif
1247+ };
1248+
11061249extern void tcp_v4_init (struct net_proto_family * ops );
11071250extern void tcp_init (void );
11081251
0 commit comments