Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: syncookies: export cookie_v4_init_sequence/cookie_v4_check

Extract the local TCP stack independant parts of tcp_v4_init_sequence()
and cookie_v4_check() and export them for use by the upcoming SYNPROXY
target.

Signed-off-by: Patrick McHardy <kaber@trash.net>
Acked-by: David S. Miller <davem@davemloft.net>
Tested-by: Martin Topholm <mph@one.com>
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>

authored by

Patrick McHardy and committed by
Pablo Neira Ayuso
0198230b 41d73ec0

+22 -11
+4
include/net/tcp.h
··· 476 476 477 477 /* From syncookies.c */ 478 478 extern __u32 syncookie_secret[2][16-4+SHA_DIGEST_WORDS]; 479 + extern int __cookie_v4_check(const struct iphdr *iph, const struct tcphdr *th, 480 + u32 cookie); 479 481 extern struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb, 480 482 struct ip_options *opt); 481 483 #ifdef CONFIG_SYN_COOKIES 484 + extern u32 __cookie_v4_init_sequence(const struct iphdr *iph, 485 + const struct tcphdr *th, u16 *mssp); 482 486 extern __u32 cookie_v4_init_sequence(struct sock *sk, struct sk_buff *skb, 483 487 __u16 *mss); 484 488 #else
+18 -11
net/ipv4/syncookies.c
··· 160 160 * Generate a syncookie. mssp points to the mss, which is returned 161 161 * rounded down to the value encoded in the cookie. 162 162 */ 163 - __u32 cookie_v4_init_sequence(struct sock *sk, struct sk_buff *skb, __u16 *mssp) 163 + u32 __cookie_v4_init_sequence(const struct iphdr *iph, const struct tcphdr *th, 164 + u16 *mssp) 164 165 { 165 - const struct iphdr *iph = ip_hdr(skb); 166 - const struct tcphdr *th = tcp_hdr(skb); 167 166 int mssind; 168 167 const __u16 mss = *mssp; 169 - 170 - tcp_synq_overflow(sk); 171 168 172 169 for (mssind = ARRAY_SIZE(msstab) - 1; mssind ; mssind--) 173 170 if (mss >= msstab[mssind]) 174 171 break; 175 172 *mssp = msstab[mssind]; 176 173 177 - NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_SYNCOOKIESSENT); 178 - 179 174 return secure_tcp_syn_cookie(iph->saddr, iph->daddr, 180 175 th->source, th->dest, ntohl(th->seq), 181 176 jiffies / (HZ * 60), mssind); 177 + } 178 + EXPORT_SYMBOL_GPL(__cookie_v4_init_sequence); 179 + 180 + __u32 cookie_v4_init_sequence(struct sock *sk, struct sk_buff *skb, __u16 *mssp) 181 + { 182 + const struct iphdr *iph = ip_hdr(skb); 183 + const struct tcphdr *th = tcp_hdr(skb); 184 + 185 + tcp_synq_overflow(sk); 186 + NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_SYNCOOKIESSENT); 187 + 188 + return __cookie_v4_init_sequence(iph, th, mssp); 182 189 } 183 190 184 191 /* ··· 199 192 * Check if a ack sequence number is a valid syncookie. 200 193 * Return the decoded mss if it is, or 0 if not. 201 194 */ 202 - static inline int cookie_check(struct sk_buff *skb, __u32 cookie) 195 + int __cookie_v4_check(const struct iphdr *iph, const struct tcphdr *th, 196 + u32 cookie) 203 197 { 204 - const struct iphdr *iph = ip_hdr(skb); 205 - const struct tcphdr *th = tcp_hdr(skb); 206 198 __u32 seq = ntohl(th->seq) - 1; 207 199 __u32 mssind = check_tcp_syn_cookie(cookie, iph->saddr, iph->daddr, 208 200 th->source, th->dest, seq, ··· 210 204 211 205 return mssind < ARRAY_SIZE(msstab) ? msstab[mssind] : 0; 212 206 } 207 + EXPORT_SYMBOL_GPL(__cookie_v4_check); 213 208 214 209 static inline struct sock *get_cookie_sock(struct sock *sk, struct sk_buff *skb, 215 210 struct request_sock *req, ··· 291 284 goto out; 292 285 293 286 if (tcp_synq_no_recent_overflow(sk) || 294 - (mss = cookie_check(skb, cookie)) == 0) { 287 + (mss = __cookie_v4_check(ip_hdr(skb), th, cookie)) == 0) { 295 288 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_SYNCOOKIESFAILED); 296 289 goto out; 297 290 }