aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv6
diff options
context:
space:
mode:
authorPatrick McHardy <kaber@trash.net>2013-08-27 02:50:15 -0400
committerPablo Neira Ayuso <pablo@netfilter.org>2013-08-27 18:28:04 -0400
commit81eb6a1487718a89621a0e0be7fafd0cd7c429a4 (patch)
tree05c8e0e54aa0c9739b5b7cd46d29d5385cb1ede0 /net/ipv6
parent48b1de4c110a7afa4b85862f6c75af817db26fad (diff)
net: syncookies: export cookie_v6_init_sequence/cookie_v6_check
Extract the local TCP stack independant parts of tcp_v6_init_sequence() and cookie_v6_check() and export them for use by the upcoming IPv6 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>
Diffstat (limited to 'net/ipv6')
-rw-r--r--net/ipv6/syncookies.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/net/ipv6/syncookies.c b/net/ipv6/syncookies.c
index d5dda20bd717..bf63ac8a49b9 100644
--- a/net/ipv6/syncookies.c
+++ b/net/ipv6/syncookies.c
@@ -112,32 +112,38 @@ static __u32 check_tcp_syn_cookie(__u32 cookie, const struct in6_addr *saddr,
112 & COOKIEMASK; 112 & COOKIEMASK;
113} 113}
114 114
115__u32 cookie_v6_init_sequence(struct sock *sk, const struct sk_buff *skb, __u16 *mssp) 115u32 __cookie_v6_init_sequence(const struct ipv6hdr *iph,
116 const struct tcphdr *th, __u16 *mssp)
116{ 117{
117 const struct ipv6hdr *iph = ipv6_hdr(skb);
118 const struct tcphdr *th = tcp_hdr(skb);
119 int mssind; 118 int mssind;
120 const __u16 mss = *mssp; 119 const __u16 mss = *mssp;
121 120
122 tcp_synq_overflow(sk);
123
124 for (mssind = ARRAY_SIZE(msstab) - 1; mssind ; mssind--) 121 for (mssind = ARRAY_SIZE(msstab) - 1; mssind ; mssind--)
125 if (mss >= msstab[mssind]) 122 if (mss >= msstab[mssind])
126 break; 123 break;
127 124
128 *mssp = msstab[mssind]; 125 *mssp = msstab[mssind];
129 126
130 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_SYNCOOKIESSENT);
131
132 return secure_tcp_syn_cookie(&iph->saddr, &iph->daddr, th->source, 127 return secure_tcp_syn_cookie(&iph->saddr, &iph->daddr, th->source,
133 th->dest, ntohl(th->seq), 128 th->dest, ntohl(th->seq),
134 jiffies / (HZ * 60), mssind); 129 jiffies / (HZ * 60), mssind);
135} 130}
131EXPORT_SYMBOL_GPL(__cookie_v6_init_sequence);
136 132
137static inline int cookie_check(const struct sk_buff *skb, __u32 cookie) 133__u32 cookie_v6_init_sequence(struct sock *sk, const struct sk_buff *skb, __u16 *mssp)
138{ 134{
139 const struct ipv6hdr *iph = ipv6_hdr(skb); 135 const struct ipv6hdr *iph = ipv6_hdr(skb);
140 const struct tcphdr *th = tcp_hdr(skb); 136 const struct tcphdr *th = tcp_hdr(skb);
137
138 tcp_synq_overflow(sk);
139 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_SYNCOOKIESSENT);
140
141 return __cookie_v6_init_sequence(iph, th, mssp);
142}
143
144int __cookie_v6_check(const struct ipv6hdr *iph, const struct tcphdr *th,
145 __u32 cookie)
146{
141 __u32 seq = ntohl(th->seq) - 1; 147 __u32 seq = ntohl(th->seq) - 1;
142 __u32 mssind = check_tcp_syn_cookie(cookie, &iph->saddr, &iph->daddr, 148 __u32 mssind = check_tcp_syn_cookie(cookie, &iph->saddr, &iph->daddr,
143 th->source, th->dest, seq, 149 th->source, th->dest, seq,
@@ -145,6 +151,7 @@ static inline int cookie_check(const struct sk_buff *skb, __u32 cookie)
145 151
146 return mssind < ARRAY_SIZE(msstab) ? msstab[mssind] : 0; 152 return mssind < ARRAY_SIZE(msstab) ? msstab[mssind] : 0;
147} 153}
154EXPORT_SYMBOL_GPL(__cookie_v6_check);
148 155
149struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb) 156struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb)
150{ 157{
@@ -167,7 +174,7 @@ struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb)
167 goto out; 174 goto out;
168 175
169 if (tcp_synq_no_recent_overflow(sk) || 176 if (tcp_synq_no_recent_overflow(sk) ||
170 (mss = cookie_check(skb, cookie)) == 0) { 177 (mss = __cookie_v6_check(ipv6_hdr(skb), th, cookie)) == 0) {
171 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_SYNCOOKIESFAILED); 178 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_SYNCOOKIESFAILED);
172 goto out; 179 goto out;
173 } 180 }