aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorYOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>2006-11-14 22:07:45 -0500
committerDavid S. Miller <davem@sunset.davemloft.net>2006-12-03 00:22:39 -0500
commitcfb6eeb4c860592edd123fdea908d23c6ad1c7dc (patch)
tree361c073622faa540ef6602ef1b0a6e8c0a17fc60 /include
parentbf6bce71eae386dbc37f93af7e5ad173450d9945 (diff)
[TCP]: MD5 Signature Option (RFC2385) support.
Based on implementation by Rick Payne. Signed-off-by: YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include')
-rw-r--r--include/linux/tcp.h35
-rw-r--r--include/net/request_sock.h3
-rw-r--r--include/net/tcp.h143
-rw-r--r--include/net/timewait_sock.h3
4 files changed, 180 insertions, 4 deletions
diff --git a/include/linux/tcp.h b/include/linux/tcp.h
index 2d36f6db3706..0aecfc955591 100644
--- a/include/linux/tcp.h
+++ b/include/linux/tcp.h
@@ -19,6 +19,7 @@
19 19
20#include <linux/types.h> 20#include <linux/types.h>
21#include <asm/byteorder.h> 21#include <asm/byteorder.h>
22#include <linux/socket.h>
22 23
23struct tcphdr { 24struct tcphdr {
24 __be16 source; 25 __be16 source;
@@ -94,6 +95,7 @@ enum {
94#define TCP_INFO 11 /* Information about this connection. */ 95#define TCP_INFO 11 /* Information about this connection. */
95#define TCP_QUICKACK 12 /* Block/reenable quick acks */ 96#define TCP_QUICKACK 12 /* Block/reenable quick acks */
96#define TCP_CONGESTION 13 /* Congestion control algorithm */ 97#define TCP_CONGESTION 13 /* Congestion control algorithm */
98#define TCP_MD5SIG 14 /* TCP MD5 Signature (RFC2385) */
97 99
98#define TCPI_OPT_TIMESTAMPS 1 100#define TCPI_OPT_TIMESTAMPS 1
99#define TCPI_OPT_SACK 2 101#define TCPI_OPT_SACK 2
@@ -157,6 +159,17 @@ struct tcp_info
157 __u32 tcpi_total_retrans; 159 __u32 tcpi_total_retrans;
158}; 160};
159 161
162/* for TCP_MD5SIG socket option */
163#define TCP_MD5SIG_MAXKEYLEN 80
164
165struct tcp_md5sig {
166 struct __kernel_sockaddr_storage tcpm_addr; /* address associated */
167 __u16 __tcpm_pad1; /* zero */
168 __u16 tcpm_keylen; /* key length */
169 __u32 __tcpm_pad2; /* zero */
170 __u8 tcpm_key[TCP_MD5SIG_MAXKEYLEN]; /* key (binary) */
171};
172
160#ifdef __KERNEL__ 173#ifdef __KERNEL__
161 174
162#include <linux/skbuff.h> 175#include <linux/skbuff.h>
@@ -197,9 +210,13 @@ struct tcp_options_received {
197}; 210};
198 211
199struct tcp_request_sock { 212struct tcp_request_sock {
200 struct inet_request_sock req; 213 struct inet_request_sock req;
201 __u32 rcv_isn; 214#ifdef CONFIG_TCP_MD5SIG
202 __u32 snt_isn; 215 /* Only used by TCP MD5 Signature so far. */
216 struct tcp_request_sock_ops *af_specific;
217#endif
218 __u32 rcv_isn;
219 __u32 snt_isn;
203}; 220};
204 221
205static inline struct tcp_request_sock *tcp_rsk(const struct request_sock *req) 222static inline struct tcp_request_sock *tcp_rsk(const struct request_sock *req)
@@ -363,6 +380,14 @@ struct tcp_sock {
363 __u32 probe_seq_start; 380 __u32 probe_seq_start;
364 __u32 probe_seq_end; 381 __u32 probe_seq_end;
365 } mtu_probe; 382 } mtu_probe;
383
384#ifdef CONFIG_TCP_MD5SIG
385/* TCP AF-Specific parts; only used by MD5 Signature support so far */
386 struct tcp_sock_af_ops *af_specific;
387
388/* TCP MD5 Signagure Option information */
389 struct tcp_md5sig_info *md5sig_info;
390#endif
366}; 391};
367 392
368static inline struct tcp_sock *tcp_sk(const struct sock *sk) 393static inline struct tcp_sock *tcp_sk(const struct sock *sk)
@@ -377,6 +402,10 @@ struct tcp_timewait_sock {
377 __u32 tw_rcv_wnd; 402 __u32 tw_rcv_wnd;
378 __u32 tw_ts_recent; 403 __u32 tw_ts_recent;
379 long tw_ts_recent_stamp; 404 long tw_ts_recent_stamp;
405#ifdef CONFIG_TCP_MD5SIG
406 __u16 tw_md5_keylen;
407 __u8 tw_md5_key[TCP_MD5SIG_MAXKEYLEN];
408#endif
380}; 409};
381 410
382static inline struct tcp_timewait_sock *tcp_twsk(const struct sock *sk) 411static inline struct tcp_timewait_sock *tcp_twsk(const struct sock *sk)
diff --git a/include/net/request_sock.h b/include/net/request_sock.h
index b5b023e79e5f..e37baaf2080b 100644
--- a/include/net/request_sock.h
+++ b/include/net/request_sock.h
@@ -35,7 +35,8 @@ struct request_sock_ops {
35 struct dst_entry *dst); 35 struct dst_entry *dst);
36 void (*send_ack)(struct sk_buff *skb, 36 void (*send_ack)(struct sk_buff *skb,
37 struct request_sock *req); 37 struct request_sock *req);
38 void (*send_reset)(struct sk_buff *skb); 38 void (*send_reset)(struct sock *sk,
39 struct sk_buff *skb);
39 void (*destructor)(struct request_sock *req); 40 void (*destructor)(struct request_sock *req);
40}; 41};
41 42
diff --git a/include/net/tcp.h b/include/net/tcp.h
index e1a5d29d0a1f..363960872de0 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -28,6 +28,7 @@
28#include <linux/percpu.h> 28#include <linux/percpu.h>
29#include <linux/skbuff.h> 29#include <linux/skbuff.h>
30#include <linux/dmaengine.h> 30#include <linux/dmaengine.h>
31#include <linux/crypto.h>
31 32
32#include <net/inet_connection_sock.h> 33#include <net/inet_connection_sock.h>
33#include <net/inet_timewait_sock.h> 34#include <net/inet_timewait_sock.h>
@@ -161,6 +162,7 @@ extern void tcp_time_wait(struct sock *sk, int state, int timeo);
161#define TCPOPT_SACK_PERM 4 /* SACK Permitted */ 162#define TCPOPT_SACK_PERM 4 /* SACK Permitted */
162#define TCPOPT_SACK 5 /* SACK Block */ 163#define TCPOPT_SACK 5 /* SACK Block */
163#define TCPOPT_TIMESTAMP 8 /* Better RTT estimations/PAWS */ 164#define TCPOPT_TIMESTAMP 8 /* Better RTT estimations/PAWS */
165#define TCPOPT_MD5SIG 19 /* MD5 Signature (RFC2385) */
164 166
165/* 167/*
166 * TCP option lengths 168 * TCP option lengths
@@ -170,6 +172,7 @@ extern void tcp_time_wait(struct sock *sk, int state, int timeo);
170#define TCPOLEN_WINDOW 3 172#define TCPOLEN_WINDOW 3
171#define TCPOLEN_SACK_PERM 2 173#define TCPOLEN_SACK_PERM 2
172#define TCPOLEN_TIMESTAMP 10 174#define TCPOLEN_TIMESTAMP 10
175#define TCPOLEN_MD5SIG 18
173 176
174/* But this is what stacks really send out. */ 177/* But this is what stacks really send out. */
175#define TCPOLEN_TSTAMP_ALIGNED 12 178#define TCPOLEN_TSTAMP_ALIGNED 12
@@ -178,6 +181,7 @@ extern void tcp_time_wait(struct sock *sk, int state, int timeo);
178#define TCPOLEN_SACK_BASE 2 181#define TCPOLEN_SACK_BASE 2
179#define TCPOLEN_SACK_BASE_ALIGNED 4 182#define TCPOLEN_SACK_BASE_ALIGNED 4
180#define TCPOLEN_SACK_PERBLOCK 8 183#define TCPOLEN_SACK_PERBLOCK 8
184#define TCPOLEN_MD5SIG_ALIGNED 20
181 185
182/* Flags in tp->nonagle */ 186/* Flags in tp->nonagle */
183#define TCP_NAGLE_OFF 1 /* Nagle's algo is disabled */ 187#define TCP_NAGLE_OFF 1 /* Nagle's algo is disabled */
@@ -299,6 +303,8 @@ extern void tcp_cleanup_rbuf(struct sock *sk, int copied);
299extern int tcp_twsk_unique(struct sock *sk, 303extern int tcp_twsk_unique(struct sock *sk,
300 struct sock *sktw, void *twp); 304 struct sock *sktw, void *twp);
301 305
306extern void tcp_twsk_destructor(struct sock *sk);
307
302static inline void tcp_dec_quickack_mode(struct sock *sk, 308static inline void tcp_dec_quickack_mode(struct sock *sk,
303 const unsigned int pkts) 309 const unsigned int pkts)
304{ 310{
@@ -1064,6 +1070,114 @@ static inline void clear_all_retrans_hints(struct tcp_sock *tp){
1064 tp->fastpath_skb_hint = NULL; 1070 tp->fastpath_skb_hint = NULL;
1065} 1071}
1066 1072
1073/* MD5 Signature */
1074struct crypto_hash;
1075
1076/* - key database */
1077struct tcp_md5sig_key {
1078 u8 *key;
1079 u8 keylen;
1080};
1081
1082struct tcp4_md5sig_key {
1083 u8 *key;
1084 u16 keylen;
1085 __be32 addr;
1086};
1087
1088struct 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 */
1098struct 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 */
1110struct tcp4_pseudohdr {
1111 __be32 saddr;
1112 __be32 daddr;
1113 __u8 pad;
1114 __u8 protocol;
1115 __be16 len;
1116};
1117
1118struct tcp6_pseudohdr {
1119 struct in6_addr saddr;
1120 struct in6_addr daddr;
1121 __be32 len;
1122 __be32 protocol; /* including padding */
1123};
1124
1125union 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 */
1133struct 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 */
1141extern 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);
1148extern struct tcp_md5sig_key *tcp_v4_md5_lookup(struct sock *sk,
1149 struct sock *addr_sk);
1150
1151extern int tcp_v4_md5_do_add(struct sock *sk,
1152 __be32 addr,
1153 u8 *newkey,
1154 u8 newkeylen);
1155
1156extern int tcp_v4_md5_do_del(struct sock *sk,
1157 u32 addr);
1158
1159extern struct tcp_md5sig_pool **tcp_alloc_md5sig_pool(void);
1160extern void tcp_free_md5sig_pool(void);
1161
1162extern struct tcp_md5sig_pool *__tcp_get_md5sig_pool(int cpu);
1163extern void __tcp_put_md5sig_pool(void);
1164
1165static inline
1166struct 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
1175static inline void tcp_put_md5sig_pool(void)
1176{
1177 __tcp_put_md5sig_pool();
1178 put_cpu();
1179}
1180
1067/* /proc */ 1181/* /proc */
1068enum tcp_seq_states { 1182enum tcp_seq_states {
1069 TCP_SEQ_STATE_LISTENING, 1183 TCP_SEQ_STATE_LISTENING,
@@ -1103,6 +1217,35 @@ extern int tcp4_proc_init(void);
1103extern void tcp4_proc_exit(void); 1217extern void tcp4_proc_exit(void);
1104#endif 1218#endif
1105 1219
1220/* TCP af-specific functions */
1221struct 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
1242struct 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
1106extern void tcp_v4_init(struct net_proto_family *ops); 1249extern void tcp_v4_init(struct net_proto_family *ops);
1107extern void tcp_init(void); 1250extern void tcp_init(void);
1108 1251
diff --git a/include/net/timewait_sock.h b/include/net/timewait_sock.h
index be293d795e38..d7a306ea560d 100644
--- a/include/net/timewait_sock.h
+++ b/include/net/timewait_sock.h
@@ -31,6 +31,9 @@ static inline int twsk_unique(struct sock *sk, struct sock *sktw, void *twp)
31 31
32static inline void twsk_destructor(struct sock *sk) 32static inline void twsk_destructor(struct sock *sk)
33{ 33{
34 BUG_ON(sk == NULL);
35 BUG_ON(sk->sk_prot == NULL);
36 BUG_ON(sk->sk_prot->twsk_prot == NULL);
34 if (sk->sk_prot->twsk_prot->twsk_destructor != NULL) 37 if (sk->sk_prot->twsk_prot->twsk_destructor != NULL)
35 sk->sk_prot->twsk_prot->twsk_destructor(sk); 38 sk->sk_prot->twsk_prot->twsk_destructor(sk);
36} 39}