diff options
Diffstat (limited to 'net/ipv6/tcp_ipv6.c')
| -rw-r--r-- | net/ipv6/tcp_ipv6.c | 639 |
1 files changed, 62 insertions, 577 deletions
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c index 8827389abaf7..2947bc56d8a0 100644 --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c | |||
| @@ -48,6 +48,7 @@ | |||
| 48 | #include <net/tcp.h> | 48 | #include <net/tcp.h> |
| 49 | #include <net/ndisc.h> | 49 | #include <net/ndisc.h> |
| 50 | #include <net/inet6_hashtables.h> | 50 | #include <net/inet6_hashtables.h> |
| 51 | #include <net/inet6_connection_sock.h> | ||
| 51 | #include <net/ipv6.h> | 52 | #include <net/ipv6.h> |
| 52 | #include <net/transp_v6.h> | 53 | #include <net/transp_v6.h> |
| 53 | #include <net/addrconf.h> | 54 | #include <net/addrconf.h> |
| @@ -59,6 +60,7 @@ | |||
| 59 | #include <net/addrconf.h> | 60 | #include <net/addrconf.h> |
| 60 | #include <net/snmp.h> | 61 | #include <net/snmp.h> |
| 61 | #include <net/dsfield.h> | 62 | #include <net/dsfield.h> |
| 63 | #include <net/timewait_sock.h> | ||
| 62 | 64 | ||
| 63 | #include <asm/uaccess.h> | 65 | #include <asm/uaccess.h> |
| 64 | 66 | ||
| @@ -67,224 +69,33 @@ | |||
| 67 | 69 | ||
| 68 | static void tcp_v6_send_reset(struct sk_buff *skb); | 70 | static void tcp_v6_send_reset(struct sk_buff *skb); |
| 69 | static void tcp_v6_reqsk_send_ack(struct sk_buff *skb, struct request_sock *req); | 71 | static void tcp_v6_reqsk_send_ack(struct sk_buff *skb, struct request_sock *req); |
| 70 | static void tcp_v6_send_check(struct sock *sk, struct tcphdr *th, int len, | 72 | static void tcp_v6_send_check(struct sock *sk, int len, |
| 71 | struct sk_buff *skb); | 73 | struct sk_buff *skb); |
| 72 | 74 | ||
| 73 | static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb); | 75 | static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb); |
| 74 | static int tcp_v6_xmit(struct sk_buff *skb, int ipfragok); | ||
| 75 | 76 | ||
| 76 | static struct tcp_func ipv6_mapped; | 77 | static struct inet_connection_sock_af_ops ipv6_mapped; |
| 77 | static struct tcp_func ipv6_specific; | 78 | static struct inet_connection_sock_af_ops ipv6_specific; |
| 78 | 79 | ||
| 79 | static inline int tcp_v6_bind_conflict(const struct sock *sk, | ||
| 80 | const struct inet_bind_bucket *tb) | ||
| 81 | { | ||
| 82 | const struct sock *sk2; | ||
| 83 | const struct hlist_node *node; | ||
| 84 | |||
| 85 | /* We must walk the whole port owner list in this case. -DaveM */ | ||
| 86 | sk_for_each_bound(sk2, node, &tb->owners) { | ||
| 87 | if (sk != sk2 && | ||
| 88 | (!sk->sk_bound_dev_if || | ||
| 89 | !sk2->sk_bound_dev_if || | ||
| 90 | sk->sk_bound_dev_if == sk2->sk_bound_dev_if) && | ||
| 91 | (!sk->sk_reuse || !sk2->sk_reuse || | ||
| 92 | sk2->sk_state == TCP_LISTEN) && | ||
| 93 | ipv6_rcv_saddr_equal(sk, sk2)) | ||
| 94 | break; | ||
| 95 | } | ||
| 96 | |||
| 97 | return node != NULL; | ||
| 98 | } | ||
| 99 | |||
| 100 | /* Grrr, addr_type already calculated by caller, but I don't want | ||
| 101 | * to add some silly "cookie" argument to this method just for that. | ||
| 102 | * But it doesn't matter, the recalculation is in the rarest path | ||
| 103 | * this function ever takes. | ||
| 104 | */ | ||
| 105 | static int tcp_v6_get_port(struct sock *sk, unsigned short snum) | 80 | static int tcp_v6_get_port(struct sock *sk, unsigned short snum) |
| 106 | { | 81 | { |
| 107 | struct inet_bind_hashbucket *head; | 82 | return inet_csk_get_port(&tcp_hashinfo, sk, snum, |
| 108 | struct inet_bind_bucket *tb; | 83 | inet6_csk_bind_conflict); |
| 109 | struct hlist_node *node; | ||
| 110 | int ret; | ||
| 111 | |||
| 112 | local_bh_disable(); | ||
| 113 | if (snum == 0) { | ||
| 114 | int low = sysctl_local_port_range[0]; | ||
| 115 | int high = sysctl_local_port_range[1]; | ||
| 116 | int remaining = (high - low) + 1; | ||
| 117 | int rover = net_random() % (high - low) + low; | ||
| 118 | |||
| 119 | do { | ||
| 120 | head = &tcp_hashinfo.bhash[inet_bhashfn(rover, tcp_hashinfo.bhash_size)]; | ||
| 121 | spin_lock(&head->lock); | ||
| 122 | inet_bind_bucket_for_each(tb, node, &head->chain) | ||
| 123 | if (tb->port == rover) | ||
| 124 | goto next; | ||
| 125 | break; | ||
| 126 | next: | ||
| 127 | spin_unlock(&head->lock); | ||
| 128 | if (++rover > high) | ||
| 129 | rover = low; | ||
| 130 | } while (--remaining > 0); | ||
| 131 | |||
| 132 | /* Exhausted local port range during search? It is not | ||
| 133 | * possible for us to be holding one of the bind hash | ||
| 134 | * locks if this test triggers, because if 'remaining' | ||
| 135 | * drops to zero, we broke out of the do/while loop at | ||
| 136 | * the top level, not from the 'break;' statement. | ||
| 137 | */ | ||
| 138 | ret = 1; | ||
| 139 | if (unlikely(remaining <= 0)) | ||
| 140 | goto fail; | ||
| 141 | |||
| 142 | /* OK, here is the one we will use. */ | ||
| 143 | snum = rover; | ||
| 144 | } else { | ||
| 145 | head = &tcp_hashinfo.bhash[inet_bhashfn(snum, tcp_hashinfo.bhash_size)]; | ||
| 146 | spin_lock(&head->lock); | ||
| 147 | inet_bind_bucket_for_each(tb, node, &head->chain) | ||
| 148 | if (tb->port == snum) | ||
| 149 | goto tb_found; | ||
| 150 | } | ||
| 151 | tb = NULL; | ||
| 152 | goto tb_not_found; | ||
| 153 | tb_found: | ||
| 154 | if (tb && !hlist_empty(&tb->owners)) { | ||
| 155 | if (tb->fastreuse > 0 && sk->sk_reuse && | ||
| 156 | sk->sk_state != TCP_LISTEN) { | ||
| 157 | goto success; | ||
| 158 | } else { | ||
| 159 | ret = 1; | ||
| 160 | if (tcp_v6_bind_conflict(sk, tb)) | ||
| 161 | goto fail_unlock; | ||
| 162 | } | ||
| 163 | } | ||
| 164 | tb_not_found: | ||
| 165 | ret = 1; | ||
| 166 | if (tb == NULL) { | ||
| 167 | tb = inet_bind_bucket_create(tcp_hashinfo.bind_bucket_cachep, head, snum); | ||
| 168 | if (tb == NULL) | ||
| 169 | goto fail_unlock; | ||
| 170 | } | ||
| 171 | if (hlist_empty(&tb->owners)) { | ||
| 172 | if (sk->sk_reuse && sk->sk_state != TCP_LISTEN) | ||
| 173 | tb->fastreuse = 1; | ||
| 174 | else | ||
| 175 | tb->fastreuse = 0; | ||
| 176 | } else if (tb->fastreuse && | ||
| 177 | (!sk->sk_reuse || sk->sk_state == TCP_LISTEN)) | ||
| 178 | tb->fastreuse = 0; | ||
| 179 | |||
| 180 | success: | ||
| 181 | if (!inet_csk(sk)->icsk_bind_hash) | ||
| 182 | inet_bind_hash(sk, tb, snum); | ||
| 183 | BUG_TRAP(inet_csk(sk)->icsk_bind_hash == tb); | ||
| 184 | ret = 0; | ||
| 185 | |||
| 186 | fail_unlock: | ||
| 187 | spin_unlock(&head->lock); | ||
| 188 | fail: | ||
| 189 | local_bh_enable(); | ||
| 190 | return ret; | ||
| 191 | } | ||
| 192 | |||
| 193 | static __inline__ void __tcp_v6_hash(struct sock *sk) | ||
| 194 | { | ||
| 195 | struct hlist_head *list; | ||
| 196 | rwlock_t *lock; | ||
| 197 | |||
| 198 | BUG_TRAP(sk_unhashed(sk)); | ||
| 199 | |||
| 200 | if (sk->sk_state == TCP_LISTEN) { | ||
| 201 | list = &tcp_hashinfo.listening_hash[inet_sk_listen_hashfn(sk)]; | ||
| 202 | lock = &tcp_hashinfo.lhash_lock; | ||
| 203 | inet_listen_wlock(&tcp_hashinfo); | ||
| 204 | } else { | ||
| 205 | unsigned int hash; | ||
| 206 | sk->sk_hash = hash = inet6_sk_ehashfn(sk); | ||
| 207 | hash &= (tcp_hashinfo.ehash_size - 1); | ||
| 208 | list = &tcp_hashinfo.ehash[hash].chain; | ||
| 209 | lock = &tcp_hashinfo.ehash[hash].lock; | ||
| 210 | write_lock(lock); | ||
| 211 | } | ||
| 212 | |||
| 213 | __sk_add_node(sk, list); | ||
| 214 | sock_prot_inc_use(sk->sk_prot); | ||
| 215 | write_unlock(lock); | ||
| 216 | } | 84 | } |
| 217 | 85 | ||
| 218 | |||
| 219 | static void tcp_v6_hash(struct sock *sk) | 86 | static void tcp_v6_hash(struct sock *sk) |
| 220 | { | 87 | { |
| 221 | if (sk->sk_state != TCP_CLOSE) { | 88 | if (sk->sk_state != TCP_CLOSE) { |
| 222 | struct tcp_sock *tp = tcp_sk(sk); | 89 | if (inet_csk(sk)->icsk_af_ops == &ipv6_mapped) { |
| 223 | |||
| 224 | if (tp->af_specific == &ipv6_mapped) { | ||
| 225 | tcp_prot.hash(sk); | 90 | tcp_prot.hash(sk); |
| 226 | return; | 91 | return; |
| 227 | } | 92 | } |
| 228 | local_bh_disable(); | 93 | local_bh_disable(); |
| 229 | __tcp_v6_hash(sk); | 94 | __inet6_hash(&tcp_hashinfo, sk); |
| 230 | local_bh_enable(); | 95 | local_bh_enable(); |
| 231 | } | 96 | } |
| 232 | } | 97 | } |
| 233 | 98 | ||
| 234 | /* | ||
| 235 | * Open request hash tables. | ||
| 236 | */ | ||
| 237 | |||
| 238 | static u32 tcp_v6_synq_hash(const struct in6_addr *raddr, const u16 rport, const u32 rnd) | ||
| 239 | { | ||
| 240 | u32 a, b, c; | ||
| 241 | |||
| 242 | a = raddr->s6_addr32[0]; | ||
| 243 | b = raddr->s6_addr32[1]; | ||
| 244 | c = raddr->s6_addr32[2]; | ||
| 245 | |||
| 246 | a += JHASH_GOLDEN_RATIO; | ||
| 247 | b += JHASH_GOLDEN_RATIO; | ||
| 248 | c += rnd; | ||
| 249 | __jhash_mix(a, b, c); | ||
| 250 | |||
| 251 | a += raddr->s6_addr32[3]; | ||
| 252 | b += (u32) rport; | ||
| 253 | __jhash_mix(a, b, c); | ||
| 254 | |||
| 255 | return c & (TCP_SYNQ_HSIZE - 1); | ||
| 256 | } | ||
| 257 | |||
| 258 | static struct request_sock *tcp_v6_search_req(const struct sock *sk, | ||
| 259 | struct request_sock ***prevp, | ||
| 260 | __u16 rport, | ||
| 261 | struct in6_addr *raddr, | ||
| 262 | struct in6_addr *laddr, | ||
| 263 | int iif) | ||
| 264 | { | ||
| 265 | const struct inet_connection_sock *icsk = inet_csk(sk); | ||
| 266 | struct listen_sock *lopt = icsk->icsk_accept_queue.listen_opt; | ||
| 267 | struct request_sock *req, **prev; | ||
| 268 | |||
| 269 | for (prev = &lopt->syn_table[tcp_v6_synq_hash(raddr, rport, lopt->hash_rnd)]; | ||
| 270 | (req = *prev) != NULL; | ||
| 271 | prev = &req->dl_next) { | ||
| 272 | const struct tcp6_request_sock *treq = tcp6_rsk(req); | ||
| 273 | |||
| 274 | if (inet_rsk(req)->rmt_port == rport && | ||
| 275 | req->rsk_ops->family == AF_INET6 && | ||
| 276 | ipv6_addr_equal(&treq->rmt_addr, raddr) && | ||
| 277 | ipv6_addr_equal(&treq->loc_addr, laddr) && | ||
| 278 | (!treq->iif || treq->iif == iif)) { | ||
| 279 | BUG_TRAP(req->sk == NULL); | ||
| 280 | *prevp = prev; | ||
| 281 | return req; | ||
| 282 | } | ||
| 283 | } | ||
| 284 | |||
| 285 | return NULL; | ||
| 286 | } | ||
| 287 | |||
| 288 | static __inline__ u16 tcp_v6_check(struct tcphdr *th, int len, | 99 | static __inline__ u16 tcp_v6_check(struct tcphdr *th, int len, |
| 289 | struct in6_addr *saddr, | 100 | struct in6_addr *saddr, |
| 290 | struct in6_addr *daddr, | 101 | struct in6_addr *daddr, |
| @@ -308,195 +119,12 @@ static __u32 tcp_v6_init_sequence(struct sock *sk, struct sk_buff *skb) | |||
| 308 | } | 119 | } |
| 309 | } | 120 | } |
| 310 | 121 | ||
| 311 | static int __tcp_v6_check_established(struct sock *sk, const __u16 lport, | ||
| 312 | struct inet_timewait_sock **twp) | ||
| 313 | { | ||
| 314 | struct inet_sock *inet = inet_sk(sk); | ||
| 315 | const struct ipv6_pinfo *np = inet6_sk(sk); | ||
| 316 | const struct in6_addr *daddr = &np->rcv_saddr; | ||
| 317 | const struct in6_addr *saddr = &np->daddr; | ||
| 318 | const int dif = sk->sk_bound_dev_if; | ||
| 319 | const u32 ports = INET_COMBINED_PORTS(inet->dport, lport); | ||
| 320 | unsigned int hash = inet6_ehashfn(daddr, inet->num, saddr, inet->dport); | ||
| 321 | struct inet_ehash_bucket *head = inet_ehash_bucket(&tcp_hashinfo, hash); | ||
| 322 | struct sock *sk2; | ||
| 323 | const struct hlist_node *node; | ||
| 324 | struct inet_timewait_sock *tw; | ||
| 325 | |||
| 326 | prefetch(head->chain.first); | ||
| 327 | write_lock(&head->lock); | ||
| 328 | |||
| 329 | /* Check TIME-WAIT sockets first. */ | ||
| 330 | sk_for_each(sk2, node, &(head + tcp_hashinfo.ehash_size)->chain) { | ||
| 331 | const struct tcp6_timewait_sock *tcp6tw = tcp6_twsk(sk2); | ||
| 332 | |||
| 333 | tw = inet_twsk(sk2); | ||
| 334 | |||
| 335 | if(*((__u32 *)&(tw->tw_dport)) == ports && | ||
| 336 | sk2->sk_family == PF_INET6 && | ||
| 337 | ipv6_addr_equal(&tcp6tw->tw_v6_daddr, saddr) && | ||
| 338 | ipv6_addr_equal(&tcp6tw->tw_v6_rcv_saddr, daddr) && | ||
| 339 | sk2->sk_bound_dev_if == sk->sk_bound_dev_if) { | ||
| 340 | const struct tcp_timewait_sock *tcptw = tcp_twsk(sk2); | ||
| 341 | struct tcp_sock *tp = tcp_sk(sk); | ||
| 342 | |||
| 343 | if (tcptw->tw_ts_recent_stamp && | ||
| 344 | (!twp || | ||
| 345 | (sysctl_tcp_tw_reuse && | ||
| 346 | xtime.tv_sec - tcptw->tw_ts_recent_stamp > 1))) { | ||
| 347 | /* See comment in tcp_ipv4.c */ | ||
| 348 | tp->write_seq = tcptw->tw_snd_nxt + 65535 + 2; | ||
| 349 | if (!tp->write_seq) | ||
| 350 | tp->write_seq = 1; | ||
| 351 | tp->rx_opt.ts_recent = tcptw->tw_ts_recent; | ||
| 352 | tp->rx_opt.ts_recent_stamp = tcptw->tw_ts_recent_stamp; | ||
| 353 | sock_hold(sk2); | ||
| 354 | goto unique; | ||
| 355 | } else | ||
| 356 | goto not_unique; | ||
| 357 | } | ||
| 358 | } | ||
| 359 | tw = NULL; | ||
| 360 | |||
| 361 | /* And established part... */ | ||
| 362 | sk_for_each(sk2, node, &head->chain) { | ||
| 363 | if (INET6_MATCH(sk2, hash, saddr, daddr, ports, dif)) | ||
| 364 | goto not_unique; | ||
| 365 | } | ||
| 366 | |||
| 367 | unique: | ||
| 368 | BUG_TRAP(sk_unhashed(sk)); | ||
| 369 | __sk_add_node(sk, &head->chain); | ||
| 370 | sk->sk_hash = hash; | ||
| 371 | sock_prot_inc_use(sk->sk_prot); | ||
| 372 | write_unlock(&head->lock); | ||
| 373 | |||
| 374 | if (twp) { | ||
| 375 | *twp = tw; | ||
| 376 | NET_INC_STATS_BH(LINUX_MIB_TIMEWAITRECYCLED); | ||
| 377 | } else if (tw) { | ||
| 378 | /* Silly. Should hash-dance instead... */ | ||
| 379 | inet_twsk_deschedule(tw, &tcp_death_row); | ||
| 380 | NET_INC_STATS_BH(LINUX_MIB_TIMEWAITRECYCLED); | ||
| 381 | |||
| 382 | inet_twsk_put(tw); | ||
| 383 | } | ||
| 384 | return 0; | ||
| 385 | |||
| 386 | not_unique: | ||
| 387 | write_unlock(&head->lock); | ||
| 388 | return -EADDRNOTAVAIL; | ||
| 389 | } | ||
| 390 | |||
| 391 | static inline u32 tcpv6_port_offset(const struct sock *sk) | ||
| 392 | { | ||
| 393 | const struct inet_sock *inet = inet_sk(sk); | ||
| 394 | const struct ipv6_pinfo *np = inet6_sk(sk); | ||
| 395 | |||
| 396 | return secure_tcpv6_port_ephemeral(np->rcv_saddr.s6_addr32, | ||
| 397 | np->daddr.s6_addr32, | ||
| 398 | inet->dport); | ||
| 399 | } | ||
| 400 | |||
| 401 | static int tcp_v6_hash_connect(struct sock *sk) | ||
| 402 | { | ||
| 403 | unsigned short snum = inet_sk(sk)->num; | ||
| 404 | struct inet_bind_hashbucket *head; | ||
| 405 | struct inet_bind_bucket *tb; | ||
| 406 | int ret; | ||
| 407 | |||
| 408 | if (!snum) { | ||
| 409 | int low = sysctl_local_port_range[0]; | ||
| 410 | int high = sysctl_local_port_range[1]; | ||
| 411 | int range = high - low; | ||
| 412 | int i; | ||
| 413 | int port; | ||
| 414 | static u32 hint; | ||
| 415 | u32 offset = hint + tcpv6_port_offset(sk); | ||
| 416 | struct hlist_node *node; | ||
| 417 | struct inet_timewait_sock *tw = NULL; | ||
| 418 | |||
| 419 | local_bh_disable(); | ||
| 420 | for (i = 1; i <= range; i++) { | ||
| 421 | port = low + (i + offset) % range; | ||
| 422 | head = &tcp_hashinfo.bhash[inet_bhashfn(port, tcp_hashinfo.bhash_size)]; | ||
| 423 | spin_lock(&head->lock); | ||
| 424 | |||
| 425 | /* Does not bother with rcv_saddr checks, | ||
| 426 | * because the established check is already | ||
| 427 | * unique enough. | ||
| 428 | */ | ||
| 429 | inet_bind_bucket_for_each(tb, node, &head->chain) { | ||
| 430 | if (tb->port == port) { | ||
| 431 | BUG_TRAP(!hlist_empty(&tb->owners)); | ||
| 432 | if (tb->fastreuse >= 0) | ||
| 433 | goto next_port; | ||
| 434 | if (!__tcp_v6_check_established(sk, | ||
| 435 | port, | ||
| 436 | &tw)) | ||
| 437 | goto ok; | ||
| 438 | goto next_port; | ||
| 439 | } | ||
| 440 | } | ||
| 441 | |||
| 442 | tb = inet_bind_bucket_create(tcp_hashinfo.bind_bucket_cachep, head, port); | ||
| 443 | if (!tb) { | ||
| 444 | spin_unlock(&head->lock); | ||
| 445 | break; | ||
| 446 | } | ||
| 447 | tb->fastreuse = -1; | ||
| 448 | goto ok; | ||
| 449 | |||
| 450 | next_port: | ||
| 451 | spin_unlock(&head->lock); | ||
| 452 | } | ||
| 453 | local_bh_enable(); | ||
| 454 | |||
| 455 | return -EADDRNOTAVAIL; | ||
| 456 | |||
| 457 | ok: | ||
| 458 | hint += i; | ||
| 459 | |||
| 460 | /* Head lock still held and bh's disabled */ | ||
| 461 | inet_bind_hash(sk, tb, port); | ||
| 462 | if (sk_unhashed(sk)) { | ||
| 463 | inet_sk(sk)->sport = htons(port); | ||
| 464 | __tcp_v6_hash(sk); | ||
| 465 | } | ||
| 466 | spin_unlock(&head->lock); | ||
| 467 | |||
| 468 | if (tw) { | ||
| 469 | inet_twsk_deschedule(tw, &tcp_death_row); | ||
| 470 | inet_twsk_put(tw); | ||
| 471 | } | ||
| 472 | |||
| 473 | ret = 0; | ||
| 474 | goto out; | ||
| 475 | } | ||
| 476 | |||
| 477 | head = &tcp_hashinfo.bhash[inet_bhashfn(snum, tcp_hashinfo.bhash_size)]; | ||
| 478 | tb = inet_csk(sk)->icsk_bind_hash; | ||
| 479 | spin_lock_bh(&head->lock); | ||
| 480 | |||
| 481 | if (sk_head(&tb->owners) == sk && !sk->sk_bind_node.next) { | ||
| 482 | __tcp_v6_hash(sk); | ||
| 483 | spin_unlock_bh(&head->lock); | ||
| 484 | return 0; | ||
| 485 | } else { | ||
| 486 | spin_unlock(&head->lock); | ||
| 487 | /* No definite answer... Walk to established hash table */ | ||
| 488 | ret = __tcp_v6_check_established(sk, snum, NULL); | ||
| 489 | out: | ||
| 490 | local_bh_enable(); | ||
| 491 | return ret; | ||
| 492 | } | ||
| 493 | } | ||
| 494 | |||
| 495 | static int tcp_v6_connect(struct sock *sk, struct sockaddr *uaddr, | 122 | static int tcp_v6_connect(struct sock *sk, struct sockaddr *uaddr, |
| 496 | int addr_len) | 123 | int addr_len) |
| 497 | { | 124 | { |
| 498 | struct sockaddr_in6 *usin = (struct sockaddr_in6 *) uaddr; | 125 | struct sockaddr_in6 *usin = (struct sockaddr_in6 *) uaddr; |
| 499 | struct inet_sock *inet = inet_sk(sk); | 126 | struct inet_sock *inet = inet_sk(sk); |
| 127 | struct inet_connection_sock *icsk = inet_csk(sk); | ||
| 500 | struct ipv6_pinfo *np = inet6_sk(sk); | 128 | struct ipv6_pinfo *np = inet6_sk(sk); |
| 501 | struct tcp_sock *tp = tcp_sk(sk); | 129 | struct tcp_sock *tp = tcp_sk(sk); |
| 502 | struct in6_addr *saddr = NULL, *final_p = NULL, final; | 130 | struct in6_addr *saddr = NULL, *final_p = NULL, final; |
| @@ -571,7 +199,7 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr *uaddr, | |||
| 571 | */ | 199 | */ |
| 572 | 200 | ||
| 573 | if (addr_type == IPV6_ADDR_MAPPED) { | 201 | if (addr_type == IPV6_ADDR_MAPPED) { |
| 574 | u32 exthdrlen = tp->ext_header_len; | 202 | u32 exthdrlen = icsk->icsk_ext_hdr_len; |
| 575 | struct sockaddr_in sin; | 203 | struct sockaddr_in sin; |
| 576 | 204 | ||
| 577 | SOCK_DEBUG(sk, "connect: ipv4 mapped\n"); | 205 | SOCK_DEBUG(sk, "connect: ipv4 mapped\n"); |
| @@ -583,14 +211,14 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr *uaddr, | |||
| 583 | sin.sin_port = usin->sin6_port; | 211 | sin.sin_port = usin->sin6_port; |
| 584 | sin.sin_addr.s_addr = usin->sin6_addr.s6_addr32[3]; | 212 | sin.sin_addr.s_addr = usin->sin6_addr.s6_addr32[3]; |
| 585 | 213 | ||
| 586 | tp->af_specific = &ipv6_mapped; | 214 | icsk->icsk_af_ops = &ipv6_mapped; |
| 587 | sk->sk_backlog_rcv = tcp_v4_do_rcv; | 215 | sk->sk_backlog_rcv = tcp_v4_do_rcv; |
| 588 | 216 | ||
| 589 | err = tcp_v4_connect(sk, (struct sockaddr *)&sin, sizeof(sin)); | 217 | err = tcp_v4_connect(sk, (struct sockaddr *)&sin, sizeof(sin)); |
| 590 | 218 | ||
| 591 | if (err) { | 219 | if (err) { |
| 592 | tp->ext_header_len = exthdrlen; | 220 | icsk->icsk_ext_hdr_len = exthdrlen; |
| 593 | tp->af_specific = &ipv6_specific; | 221 | icsk->icsk_af_ops = &ipv6_specific; |
| 594 | sk->sk_backlog_rcv = tcp_v6_do_rcv; | 222 | sk->sk_backlog_rcv = tcp_v6_do_rcv; |
| 595 | goto failure; | 223 | goto failure; |
| 596 | } else { | 224 | } else { |
| @@ -643,16 +271,17 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr *uaddr, | |||
| 643 | sk->sk_route_caps = dst->dev->features & | 271 | sk->sk_route_caps = dst->dev->features & |
| 644 | ~(NETIF_F_IP_CSUM | NETIF_F_TSO); | 272 | ~(NETIF_F_IP_CSUM | NETIF_F_TSO); |
| 645 | 273 | ||
| 646 | tp->ext_header_len = 0; | 274 | icsk->icsk_ext_hdr_len = 0; |
| 647 | if (np->opt) | 275 | if (np->opt) |
| 648 | tp->ext_header_len = np->opt->opt_flen + np->opt->opt_nflen; | 276 | icsk->icsk_ext_hdr_len = (np->opt->opt_flen + |
| 277 | np->opt->opt_nflen); | ||
| 649 | 278 | ||
| 650 | tp->rx_opt.mss_clamp = IPV6_MIN_MTU - sizeof(struct tcphdr) - sizeof(struct ipv6hdr); | 279 | tp->rx_opt.mss_clamp = IPV6_MIN_MTU - sizeof(struct tcphdr) - sizeof(struct ipv6hdr); |
| 651 | 280 | ||
| 652 | inet->dport = usin->sin6_port; | 281 | inet->dport = usin->sin6_port; |
| 653 | 282 | ||
| 654 | tcp_set_state(sk, TCP_SYN_SENT); | 283 | tcp_set_state(sk, TCP_SYN_SENT); |
| 655 | err = tcp_v6_hash_connect(sk); | 284 | err = inet6_hash_connect(&tcp_death_row, sk); |
| 656 | if (err) | 285 | if (err) |
| 657 | goto late_failure; | 286 | goto late_failure; |
| 658 | 287 | ||
| @@ -758,7 +387,7 @@ static void tcp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt, | |||
| 758 | } else | 387 | } else |
| 759 | dst_hold(dst); | 388 | dst_hold(dst); |
| 760 | 389 | ||
| 761 | if (tp->pmtu_cookie > dst_mtu(dst)) { | 390 | if (inet_csk(sk)->icsk_pmtu_cookie > dst_mtu(dst)) { |
| 762 | tcp_sync_mss(sk, dst_mtu(dst)); | 391 | tcp_sync_mss(sk, dst_mtu(dst)); |
| 763 | tcp_simple_retransmit(sk); | 392 | tcp_simple_retransmit(sk); |
| 764 | } /* else let the usual retransmit timer handle it */ | 393 | } /* else let the usual retransmit timer handle it */ |
| @@ -775,8 +404,8 @@ static void tcp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt, | |||
| 775 | if (sock_owned_by_user(sk)) | 404 | if (sock_owned_by_user(sk)) |
| 776 | goto out; | 405 | goto out; |
| 777 | 406 | ||
| 778 | req = tcp_v6_search_req(sk, &prev, th->dest, &hdr->daddr, | 407 | req = inet6_csk_search_req(sk, &prev, th->dest, &hdr->daddr, |
| 779 | &hdr->saddr, inet6_iif(skb)); | 408 | &hdr->saddr, inet6_iif(skb)); |
| 780 | if (!req) | 409 | if (!req) |
| 781 | goto out; | 410 | goto out; |
| 782 | 411 | ||
| @@ -822,7 +451,7 @@ out: | |||
| 822 | static int tcp_v6_send_synack(struct sock *sk, struct request_sock *req, | 451 | static int tcp_v6_send_synack(struct sock *sk, struct request_sock *req, |
| 823 | struct dst_entry *dst) | 452 | struct dst_entry *dst) |
| 824 | { | 453 | { |
| 825 | struct tcp6_request_sock *treq = tcp6_rsk(req); | 454 | struct inet6_request_sock *treq = inet6_rsk(req); |
| 826 | struct ipv6_pinfo *np = inet6_sk(sk); | 455 | struct ipv6_pinfo *np = inet6_sk(sk); |
| 827 | struct sk_buff * skb; | 456 | struct sk_buff * skb; |
| 828 | struct ipv6_txoptions *opt = NULL; | 457 | struct ipv6_txoptions *opt = NULL; |
| @@ -888,8 +517,8 @@ done: | |||
| 888 | 517 | ||
| 889 | static void tcp_v6_reqsk_destructor(struct request_sock *req) | 518 | static void tcp_v6_reqsk_destructor(struct request_sock *req) |
| 890 | { | 519 | { |
| 891 | if (tcp6_rsk(req)->pktopts) | 520 | if (inet6_rsk(req)->pktopts) |
| 892 | kfree_skb(tcp6_rsk(req)->pktopts); | 521 | kfree_skb(inet6_rsk(req)->pktopts); |
| 893 | } | 522 | } |
| 894 | 523 | ||
| 895 | static struct request_sock_ops tcp6_request_sock_ops = { | 524 | static struct request_sock_ops tcp6_request_sock_ops = { |
| @@ -901,26 +530,15 @@ static struct request_sock_ops tcp6_request_sock_ops = { | |||
| 901 | .send_reset = tcp_v6_send_reset | 530 | .send_reset = tcp_v6_send_reset |
| 902 | }; | 531 | }; |
| 903 | 532 | ||
| 904 | static int ipv6_opt_accepted(struct sock *sk, struct sk_buff *skb) | 533 | static struct timewait_sock_ops tcp6_timewait_sock_ops = { |
| 905 | { | 534 | .twsk_obj_size = sizeof(struct tcp6_timewait_sock), |
| 906 | struct ipv6_pinfo *np = inet6_sk(sk); | 535 | .twsk_unique = tcp_twsk_unique, |
| 907 | struct inet6_skb_parm *opt = IP6CB(skb); | 536 | }; |
| 908 | |||
| 909 | if (np->rxopt.all) { | ||
| 910 | if ((opt->hop && (np->rxopt.bits.hopopts || np->rxopt.bits.ohopopts)) || | ||
| 911 | ((IPV6_FLOWINFO_MASK & *(u32*)skb->nh.raw) && np->rxopt.bits.rxflow) || | ||
| 912 | (opt->srcrt && (np->rxopt.bits.srcrt || np->rxopt.bits.osrcrt)) || | ||
| 913 | ((opt->dst1 || opt->dst0) && (np->rxopt.bits.dstopts || np->rxopt.bits.odstopts))) | ||
| 914 | return 1; | ||
| 915 | } | ||
| 916 | return 0; | ||
| 917 | } | ||
| 918 | |||
| 919 | 537 | ||
| 920 | static void tcp_v6_send_check(struct sock *sk, struct tcphdr *th, int len, | 538 | static void tcp_v6_send_check(struct sock *sk, int len, struct sk_buff *skb) |
| 921 | struct sk_buff *skb) | ||
| 922 | { | 539 | { |
| 923 | struct ipv6_pinfo *np = inet6_sk(sk); | 540 | struct ipv6_pinfo *np = inet6_sk(sk); |
| 541 | struct tcphdr *th = skb->h.th; | ||
| 924 | 542 | ||
| 925 | if (skb->ip_summed == CHECKSUM_HW) { | 543 | if (skb->ip_summed == CHECKSUM_HW) { |
| 926 | th->check = ~csum_ipv6_magic(&np->saddr, &np->daddr, len, IPPROTO_TCP, 0); | 544 | th->check = ~csum_ipv6_magic(&np->saddr, &np->daddr, len, IPPROTO_TCP, 0); |
| @@ -1091,8 +709,9 @@ static struct sock *tcp_v6_hnd_req(struct sock *sk,struct sk_buff *skb) | |||
| 1091 | struct sock *nsk; | 709 | struct sock *nsk; |
| 1092 | 710 | ||
| 1093 | /* Find possible connection requests. */ | 711 | /* Find possible connection requests. */ |
| 1094 | req = tcp_v6_search_req(sk, &prev, th->source, &skb->nh.ipv6h->saddr, | 712 | req = inet6_csk_search_req(sk, &prev, th->source, |
| 1095 | &skb->nh.ipv6h->daddr, inet6_iif(skb)); | 713 | &skb->nh.ipv6h->saddr, |
| 714 | &skb->nh.ipv6h->daddr, inet6_iif(skb)); | ||
| 1096 | if (req) | 715 | if (req) |
| 1097 | return tcp_check_req(sk, skb, req, prev); | 716 | return tcp_check_req(sk, skb, req, prev); |
| 1098 | 717 | ||
| @@ -1116,23 +735,12 @@ static struct sock *tcp_v6_hnd_req(struct sock *sk,struct sk_buff *skb) | |||
| 1116 | return sk; | 735 | return sk; |
| 1117 | } | 736 | } |
| 1118 | 737 | ||
| 1119 | static void tcp_v6_synq_add(struct sock *sk, struct request_sock *req) | ||
| 1120 | { | ||
| 1121 | struct inet_connection_sock *icsk = inet_csk(sk); | ||
| 1122 | struct listen_sock *lopt = icsk->icsk_accept_queue.listen_opt; | ||
| 1123 | const u32 h = tcp_v6_synq_hash(&tcp6_rsk(req)->rmt_addr, inet_rsk(req)->rmt_port, lopt->hash_rnd); | ||
| 1124 | |||
| 1125 | reqsk_queue_hash_req(&icsk->icsk_accept_queue, h, req, TCP_TIMEOUT_INIT); | ||
| 1126 | inet_csk_reqsk_queue_added(sk, TCP_TIMEOUT_INIT); | ||
| 1127 | } | ||
| 1128 | |||
| 1129 | |||
| 1130 | /* FIXME: this is substantially similar to the ipv4 code. | 738 | /* FIXME: this is substantially similar to the ipv4 code. |
| 1131 | * Can some kind of merge be done? -- erics | 739 | * Can some kind of merge be done? -- erics |
| 1132 | */ | 740 | */ |
| 1133 | static int tcp_v6_conn_request(struct sock *sk, struct sk_buff *skb) | 741 | static int tcp_v6_conn_request(struct sock *sk, struct sk_buff *skb) |
| 1134 | { | 742 | { |
| 1135 | struct tcp6_request_sock *treq; | 743 | struct inet6_request_sock *treq; |
| 1136 | struct ipv6_pinfo *np = inet6_sk(sk); | 744 | struct ipv6_pinfo *np = inet6_sk(sk); |
| 1137 | struct tcp_options_received tmp_opt; | 745 | struct tcp_options_received tmp_opt; |
| 1138 | struct tcp_sock *tp = tcp_sk(sk); | 746 | struct tcp_sock *tp = tcp_sk(sk); |
| @@ -1157,7 +765,7 @@ static int tcp_v6_conn_request(struct sock *sk, struct sk_buff *skb) | |||
| 1157 | if (sk_acceptq_is_full(sk) && inet_csk_reqsk_queue_young(sk) > 1) | 765 | if (sk_acceptq_is_full(sk) && inet_csk_reqsk_queue_young(sk) > 1) |
| 1158 | goto drop; | 766 | goto drop; |
| 1159 | 767 | ||
| 1160 | req = reqsk_alloc(&tcp6_request_sock_ops); | 768 | req = inet6_reqsk_alloc(&tcp6_request_sock_ops); |
| 1161 | if (req == NULL) | 769 | if (req == NULL) |
| 1162 | goto drop; | 770 | goto drop; |
| 1163 | 771 | ||
| @@ -1170,7 +778,7 @@ static int tcp_v6_conn_request(struct sock *sk, struct sk_buff *skb) | |||
| 1170 | tmp_opt.tstamp_ok = tmp_opt.saw_tstamp; | 778 | tmp_opt.tstamp_ok = tmp_opt.saw_tstamp; |
| 1171 | tcp_openreq_init(req, &tmp_opt, skb); | 779 | tcp_openreq_init(req, &tmp_opt, skb); |
| 1172 | 780 | ||
| 1173 | treq = tcp6_rsk(req); | 781 | treq = inet6_rsk(req); |
| 1174 | ipv6_addr_copy(&treq->rmt_addr, &skb->nh.ipv6h->saddr); | 782 | ipv6_addr_copy(&treq->rmt_addr, &skb->nh.ipv6h->saddr); |
| 1175 | ipv6_addr_copy(&treq->loc_addr, &skb->nh.ipv6h->daddr); | 783 | ipv6_addr_copy(&treq->loc_addr, &skb->nh.ipv6h->daddr); |
| 1176 | TCP_ECN_create_request(req, skb->h.th); | 784 | TCP_ECN_create_request(req, skb->h.th); |
| @@ -1196,8 +804,7 @@ static int tcp_v6_conn_request(struct sock *sk, struct sk_buff *skb) | |||
| 1196 | if (tcp_v6_send_synack(sk, req, NULL)) | 804 | if (tcp_v6_send_synack(sk, req, NULL)) |
| 1197 | goto drop; | 805 | goto drop; |
| 1198 | 806 | ||
| 1199 | tcp_v6_synq_add(sk, req); | 807 | inet6_csk_reqsk_queue_hash_add(sk, req, TCP_TIMEOUT_INIT); |
| 1200 | |||
| 1201 | return 0; | 808 | return 0; |
| 1202 | 809 | ||
| 1203 | drop: | 810 | drop: |
| @@ -1212,7 +819,7 @@ static struct sock * tcp_v6_syn_recv_sock(struct sock *sk, struct sk_buff *skb, | |||
| 1212 | struct request_sock *req, | 819 | struct request_sock *req, |
| 1213 | struct dst_entry *dst) | 820 | struct dst_entry *dst) |
| 1214 | { | 821 | { |
| 1215 | struct tcp6_request_sock *treq = tcp6_rsk(req); | 822 | struct inet6_request_sock *treq = inet6_rsk(req); |
| 1216 | struct ipv6_pinfo *newnp, *np = inet6_sk(sk); | 823 | struct ipv6_pinfo *newnp, *np = inet6_sk(sk); |
| 1217 | struct tcp6_sock *newtcp6sk; | 824 | struct tcp6_sock *newtcp6sk; |
| 1218 | struct inet_sock *newinet; | 825 | struct inet_sock *newinet; |
| @@ -1247,7 +854,7 @@ static struct sock * tcp_v6_syn_recv_sock(struct sock *sk, struct sk_buff *skb, | |||
| 1247 | 854 | ||
| 1248 | ipv6_addr_copy(&newnp->rcv_saddr, &newnp->saddr); | 855 | ipv6_addr_copy(&newnp->rcv_saddr, &newnp->saddr); |
| 1249 | 856 | ||
| 1250 | newtp->af_specific = &ipv6_mapped; | 857 | inet_csk(newsk)->icsk_af_ops = &ipv6_mapped; |
| 1251 | newsk->sk_backlog_rcv = tcp_v4_do_rcv; | 858 | newsk->sk_backlog_rcv = tcp_v4_do_rcv; |
| 1252 | newnp->pktoptions = NULL; | 859 | newnp->pktoptions = NULL; |
| 1253 | newnp->opt = NULL; | 860 | newnp->opt = NULL; |
| @@ -1261,10 +868,10 @@ static struct sock * tcp_v6_syn_recv_sock(struct sock *sk, struct sk_buff *skb, | |||
| 1261 | */ | 868 | */ |
| 1262 | 869 | ||
| 1263 | /* It is tricky place. Until this moment IPv4 tcp | 870 | /* It is tricky place. Until this moment IPv4 tcp |
| 1264 | worked with IPv6 af_tcp.af_specific. | 871 | worked with IPv6 icsk.icsk_af_ops. |
| 1265 | Sync it now. | 872 | Sync it now. |
| 1266 | */ | 873 | */ |
| 1267 | tcp_sync_mss(newsk, newtp->pmtu_cookie); | 874 | tcp_sync_mss(newsk, inet_csk(newsk)->icsk_pmtu_cookie); |
| 1268 | 875 | ||
| 1269 | return newsk; | 876 | return newsk; |
| 1270 | } | 877 | } |
| @@ -1371,10 +978,10 @@ static struct sock * tcp_v6_syn_recv_sock(struct sock *sk, struct sk_buff *skb, | |||
| 1371 | sock_kfree_s(sk, opt, opt->tot_len); | 978 | sock_kfree_s(sk, opt, opt->tot_len); |
| 1372 | } | 979 | } |
| 1373 | 980 | ||
| 1374 | newtp->ext_header_len = 0; | 981 | inet_csk(newsk)->icsk_ext_hdr_len = 0; |
| 1375 | if (newnp->opt) | 982 | if (newnp->opt) |
| 1376 | newtp->ext_header_len = newnp->opt->opt_nflen + | 983 | inet_csk(newsk)->icsk_ext_hdr_len = (newnp->opt->opt_nflen + |
| 1377 | newnp->opt->opt_flen; | 984 | newnp->opt->opt_flen); |
| 1378 | 985 | ||
| 1379 | tcp_sync_mss(newsk, dst_mtu(dst)); | 986 | tcp_sync_mss(newsk, dst_mtu(dst)); |
| 1380 | newtp->advmss = dst_metric(dst, RTAX_ADVMSS); | 987 | newtp->advmss = dst_metric(dst, RTAX_ADVMSS); |
| @@ -1382,7 +989,7 @@ static struct sock * tcp_v6_syn_recv_sock(struct sock *sk, struct sk_buff *skb, | |||
| 1382 | 989 | ||
| 1383 | newinet->daddr = newinet->saddr = newinet->rcv_saddr = LOOPBACK4_IPV6; | 990 | newinet->daddr = newinet->saddr = newinet->rcv_saddr = LOOPBACK4_IPV6; |
| 1384 | 991 | ||
| 1385 | __tcp_v6_hash(newsk); | 992 | __inet6_hash(&tcp_hashinfo, newsk); |
| 1386 | inet_inherit_port(&tcp_hashinfo, sk, newsk); | 993 | inet_inherit_port(&tcp_hashinfo, sk, newsk); |
| 1387 | 994 | ||
| 1388 | return newsk; | 995 | return newsk; |
| @@ -1679,139 +1286,16 @@ do_time_wait: | |||
| 1679 | goto discard_it; | 1286 | goto discard_it; |
| 1680 | } | 1287 | } |
| 1681 | 1288 | ||
| 1682 | static int tcp_v6_rebuild_header(struct sock *sk) | ||
| 1683 | { | ||
| 1684 | int err; | ||
| 1685 | struct dst_entry *dst; | ||
| 1686 | struct ipv6_pinfo *np = inet6_sk(sk); | ||
| 1687 | |||
| 1688 | dst = __sk_dst_check(sk, np->dst_cookie); | ||
| 1689 | |||
| 1690 | if (dst == NULL) { | ||
| 1691 | struct inet_sock *inet = inet_sk(sk); | ||
| 1692 | struct in6_addr *final_p = NULL, final; | ||
| 1693 | struct flowi fl; | ||
| 1694 | |||
| 1695 | memset(&fl, 0, sizeof(fl)); | ||
| 1696 | fl.proto = IPPROTO_TCP; | ||
| 1697 | ipv6_addr_copy(&fl.fl6_dst, &np->daddr); | ||
| 1698 | ipv6_addr_copy(&fl.fl6_src, &np->saddr); | ||
| 1699 | fl.fl6_flowlabel = np->flow_label; | ||
| 1700 | fl.oif = sk->sk_bound_dev_if; | ||
| 1701 | fl.fl_ip_dport = inet->dport; | ||
| 1702 | fl.fl_ip_sport = inet->sport; | ||
| 1703 | |||
| 1704 | if (np->opt && np->opt->srcrt) { | ||
| 1705 | struct rt0_hdr *rt0 = (struct rt0_hdr *) np->opt->srcrt; | ||
| 1706 | ipv6_addr_copy(&final, &fl.fl6_dst); | ||
| 1707 | ipv6_addr_copy(&fl.fl6_dst, rt0->addr); | ||
| 1708 | final_p = &final; | ||
| 1709 | } | ||
| 1710 | |||
| 1711 | err = ip6_dst_lookup(sk, &dst, &fl); | ||
| 1712 | if (err) { | ||
| 1713 | sk->sk_route_caps = 0; | ||
| 1714 | return err; | ||
| 1715 | } | ||
| 1716 | if (final_p) | ||
| 1717 | ipv6_addr_copy(&fl.fl6_dst, final_p); | ||
| 1718 | |||
| 1719 | if ((err = xfrm_lookup(&dst, &fl, sk, 0)) < 0) { | ||
| 1720 | sk->sk_err_soft = -err; | ||
| 1721 | return err; | ||
| 1722 | } | ||
| 1723 | |||
| 1724 | ip6_dst_store(sk, dst, NULL); | ||
| 1725 | sk->sk_route_caps = dst->dev->features & | ||
| 1726 | ~(NETIF_F_IP_CSUM | NETIF_F_TSO); | ||
| 1727 | } | ||
| 1728 | |||
| 1729 | return 0; | ||
| 1730 | } | ||
| 1731 | |||
| 1732 | static int tcp_v6_xmit(struct sk_buff *skb, int ipfragok) | ||
| 1733 | { | ||
| 1734 | struct sock *sk = skb->sk; | ||
| 1735 | struct inet_sock *inet = inet_sk(sk); | ||
| 1736 | struct ipv6_pinfo *np = inet6_sk(sk); | ||
| 1737 | struct flowi fl; | ||
| 1738 | struct dst_entry *dst; | ||
| 1739 | struct in6_addr *final_p = NULL, final; | ||
| 1740 | |||
| 1741 | memset(&fl, 0, sizeof(fl)); | ||
| 1742 | fl.proto = IPPROTO_TCP; | ||
| 1743 | ipv6_addr_copy(&fl.fl6_dst, &np->daddr); | ||
| 1744 | ipv6_addr_copy(&fl.fl6_src, &np->saddr); | ||
| 1745 | fl.fl6_flowlabel = np->flow_label; | ||
| 1746 | IP6_ECN_flow_xmit(sk, fl.fl6_flowlabel); | ||
| 1747 | fl.oif = sk->sk_bound_dev_if; | ||
| 1748 | fl.fl_ip_sport = inet->sport; | ||
| 1749 | fl.fl_ip_dport = inet->dport; | ||
| 1750 | |||
| 1751 | if (np->opt && np->opt->srcrt) { | ||
| 1752 | struct rt0_hdr *rt0 = (struct rt0_hdr *) np->opt->srcrt; | ||
| 1753 | ipv6_addr_copy(&final, &fl.fl6_dst); | ||
| 1754 | ipv6_addr_copy(&fl.fl6_dst, rt0->addr); | ||
| 1755 | final_p = &final; | ||
| 1756 | } | ||
| 1757 | |||
| 1758 | dst = __sk_dst_check(sk, np->dst_cookie); | ||
| 1759 | |||
| 1760 | if (dst == NULL) { | ||
| 1761 | int err = ip6_dst_lookup(sk, &dst, &fl); | ||
| 1762 | |||
| 1763 | if (err) { | ||
| 1764 | sk->sk_err_soft = -err; | ||
| 1765 | return err; | ||
| 1766 | } | ||
| 1767 | |||
| 1768 | if (final_p) | ||
| 1769 | ipv6_addr_copy(&fl.fl6_dst, final_p); | ||
| 1770 | |||
| 1771 | if ((err = xfrm_lookup(&dst, &fl, sk, 0)) < 0) { | ||
| 1772 | sk->sk_route_caps = 0; | ||
| 1773 | return err; | ||
| 1774 | } | ||
| 1775 | |||
| 1776 | ip6_dst_store(sk, dst, NULL); | ||
| 1777 | sk->sk_route_caps = dst->dev->features & | ||
| 1778 | ~(NETIF_F_IP_CSUM | NETIF_F_TSO); | ||
| 1779 | } | ||
| 1780 | |||
| 1781 | skb->dst = dst_clone(dst); | ||
| 1782 | |||
| 1783 | /* Restore final destination back after routing done */ | ||
| 1784 | ipv6_addr_copy(&fl.fl6_dst, &np->daddr); | ||
| 1785 | |||
| 1786 | return ip6_xmit(sk, skb, &fl, np->opt, 0); | ||
| 1787 | } | ||
| 1788 | |||
| 1789 | static void v6_addr2sockaddr(struct sock *sk, struct sockaddr * uaddr) | ||
| 1790 | { | ||
| 1791 | struct ipv6_pinfo *np = inet6_sk(sk); | ||
| 1792 | struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) uaddr; | ||
| 1793 | |||
| 1794 | sin6->sin6_family = AF_INET6; | ||
| 1795 | ipv6_addr_copy(&sin6->sin6_addr, &np->daddr); | ||
| 1796 | sin6->sin6_port = inet_sk(sk)->dport; | ||
| 1797 | /* We do not store received flowlabel for TCP */ | ||
| 1798 | sin6->sin6_flowinfo = 0; | ||
| 1799 | sin6->sin6_scope_id = 0; | ||
| 1800 | if (sk->sk_bound_dev_if && | ||
| 1801 | ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL) | ||
| 1802 | sin6->sin6_scope_id = sk->sk_bound_dev_if; | ||
| 1803 | } | ||
| 1804 | |||
| 1805 | static int tcp_v6_remember_stamp(struct sock *sk) | 1289 | static int tcp_v6_remember_stamp(struct sock *sk) |
| 1806 | { | 1290 | { |
| 1807 | /* Alas, not yet... */ | 1291 | /* Alas, not yet... */ |
| 1808 | return 0; | 1292 | return 0; |
| 1809 | } | 1293 | } |
| 1810 | 1294 | ||
| 1811 | static struct tcp_func ipv6_specific = { | 1295 | static struct inet_connection_sock_af_ops ipv6_specific = { |
| 1812 | .queue_xmit = tcp_v6_xmit, | 1296 | .queue_xmit = inet6_csk_xmit, |
| 1813 | .send_check = tcp_v6_send_check, | 1297 | .send_check = tcp_v6_send_check, |
| 1814 | .rebuild_header = tcp_v6_rebuild_header, | 1298 | .rebuild_header = inet6_sk_rebuild_header, |
| 1815 | .conn_request = tcp_v6_conn_request, | 1299 | .conn_request = tcp_v6_conn_request, |
| 1816 | .syn_recv_sock = tcp_v6_syn_recv_sock, | 1300 | .syn_recv_sock = tcp_v6_syn_recv_sock, |
| 1817 | .remember_stamp = tcp_v6_remember_stamp, | 1301 | .remember_stamp = tcp_v6_remember_stamp, |
| @@ -1819,7 +1303,7 @@ static struct tcp_func ipv6_specific = { | |||
| 1819 | 1303 | ||
| 1820 | .setsockopt = ipv6_setsockopt, | 1304 | .setsockopt = ipv6_setsockopt, |
| 1821 | .getsockopt = ipv6_getsockopt, | 1305 | .getsockopt = ipv6_getsockopt, |
| 1822 | .addr2sockaddr = v6_addr2sockaddr, | 1306 | .addr2sockaddr = inet6_csk_addr2sockaddr, |
| 1823 | .sockaddr_len = sizeof(struct sockaddr_in6) | 1307 | .sockaddr_len = sizeof(struct sockaddr_in6) |
| 1824 | }; | 1308 | }; |
| 1825 | 1309 | ||
| @@ -1827,7 +1311,7 @@ static struct tcp_func ipv6_specific = { | |||
| 1827 | * TCP over IPv4 via INET6 API | 1311 | * TCP over IPv4 via INET6 API |
| 1828 | */ | 1312 | */ |
| 1829 | 1313 | ||
| 1830 | static struct tcp_func ipv6_mapped = { | 1314 | static struct inet_connection_sock_af_ops ipv6_mapped = { |
| 1831 | .queue_xmit = ip_queue_xmit, | 1315 | .queue_xmit = ip_queue_xmit, |
| 1832 | .send_check = tcp_v4_send_check, | 1316 | .send_check = tcp_v4_send_check, |
| 1833 | .rebuild_header = inet_sk_rebuild_header, | 1317 | .rebuild_header = inet_sk_rebuild_header, |
| @@ -1838,7 +1322,7 @@ static struct tcp_func ipv6_mapped = { | |||
| 1838 | 1322 | ||
| 1839 | .setsockopt = ipv6_setsockopt, | 1323 | .setsockopt = ipv6_setsockopt, |
| 1840 | .getsockopt = ipv6_getsockopt, | 1324 | .getsockopt = ipv6_getsockopt, |
| 1841 | .addr2sockaddr = v6_addr2sockaddr, | 1325 | .addr2sockaddr = inet6_csk_addr2sockaddr, |
| 1842 | .sockaddr_len = sizeof(struct sockaddr_in6) | 1326 | .sockaddr_len = sizeof(struct sockaddr_in6) |
| 1843 | }; | 1327 | }; |
| 1844 | 1328 | ||
| @@ -1877,8 +1361,9 @@ static int tcp_v6_init_sock(struct sock *sk) | |||
| 1877 | 1361 | ||
| 1878 | sk->sk_state = TCP_CLOSE; | 1362 | sk->sk_state = TCP_CLOSE; |
| 1879 | 1363 | ||
| 1880 | tp->af_specific = &ipv6_specific; | 1364 | icsk->icsk_af_ops = &ipv6_specific; |
| 1881 | icsk->icsk_ca_ops = &tcp_init_congestion_ops; | 1365 | icsk->icsk_ca_ops = &tcp_init_congestion_ops; |
| 1366 | icsk->icsk_sync_mss = tcp_sync_mss; | ||
| 1882 | sk->sk_write_space = sk_stream_write_space; | 1367 | sk->sk_write_space = sk_stream_write_space; |
| 1883 | sock_set_flag(sk, SOCK_USE_WRITE_QUEUE); | 1368 | sock_set_flag(sk, SOCK_USE_WRITE_QUEUE); |
| 1884 | 1369 | ||
| @@ -1900,14 +1385,13 @@ static int tcp_v6_destroy_sock(struct sock *sk) | |||
| 1900 | static void get_openreq6(struct seq_file *seq, | 1385 | static void get_openreq6(struct seq_file *seq, |
| 1901 | struct sock *sk, struct request_sock *req, int i, int uid) | 1386 | struct sock *sk, struct request_sock *req, int i, int uid) |
| 1902 | { | 1387 | { |
| 1903 | struct in6_addr *dest, *src; | ||
| 1904 | int ttd = req->expires - jiffies; | 1388 | int ttd = req->expires - jiffies; |
| 1389 | struct in6_addr *src = &inet6_rsk(req)->loc_addr; | ||
| 1390 | struct in6_addr *dest = &inet6_rsk(req)->rmt_addr; | ||
| 1905 | 1391 | ||
| 1906 | if (ttd < 0) | 1392 | if (ttd < 0) |
| 1907 | ttd = 0; | 1393 | ttd = 0; |
| 1908 | 1394 | ||
| 1909 | src = &tcp6_rsk(req)->loc_addr; | ||
| 1910 | dest = &tcp6_rsk(req)->rmt_addr; | ||
| 1911 | seq_printf(seq, | 1395 | seq_printf(seq, |
| 1912 | "%4d: %08X%08X%08X%08X:%04X %08X%08X%08X%08X:%04X " | 1396 | "%4d: %08X%08X%08X%08X:%04X %08X%08X%08X%08X:%04X " |
| 1913 | "%02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p\n", | 1397 | "%02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p\n", |
| @@ -1988,14 +1472,14 @@ static void get_timewait6_sock(struct seq_file *seq, | |||
| 1988 | { | 1472 | { |
| 1989 | struct in6_addr *dest, *src; | 1473 | struct in6_addr *dest, *src; |
| 1990 | __u16 destp, srcp; | 1474 | __u16 destp, srcp; |
| 1991 | struct tcp6_timewait_sock *tcp6tw = tcp6_twsk((struct sock *)tw); | 1475 | struct inet6_timewait_sock *tw6 = inet6_twsk((struct sock *)tw); |
| 1992 | int ttd = tw->tw_ttd - jiffies; | 1476 | int ttd = tw->tw_ttd - jiffies; |
| 1993 | 1477 | ||
| 1994 | if (ttd < 0) | 1478 | if (ttd < 0) |
| 1995 | ttd = 0; | 1479 | ttd = 0; |
| 1996 | 1480 | ||
| 1997 | dest = &tcp6tw->tw_v6_daddr; | 1481 | dest = &tw6->tw_v6_daddr; |
| 1998 | src = &tcp6tw->tw_v6_rcv_saddr; | 1482 | src = &tw6->tw_v6_rcv_saddr; |
| 1999 | destp = ntohs(tw->tw_dport); | 1483 | destp = ntohs(tw->tw_dport); |
| 2000 | srcp = ntohs(tw->tw_sport); | 1484 | srcp = ntohs(tw->tw_sport); |
| 2001 | 1485 | ||
| @@ -2093,7 +1577,7 @@ struct proto tcpv6_prot = { | |||
| 2093 | .sysctl_rmem = sysctl_tcp_rmem, | 1577 | .sysctl_rmem = sysctl_tcp_rmem, |
| 2094 | .max_header = MAX_TCP_HEADER, | 1578 | .max_header = MAX_TCP_HEADER, |
| 2095 | .obj_size = sizeof(struct tcp6_sock), | 1579 | .obj_size = sizeof(struct tcp6_sock), |
| 2096 | .twsk_obj_size = sizeof(struct tcp6_timewait_sock), | 1580 | .twsk_prot = &tcp6_timewait_sock_ops, |
| 2097 | .rsk_prot = &tcp6_request_sock_ops, | 1581 | .rsk_prot = &tcp6_request_sock_ops, |
| 2098 | }; | 1582 | }; |
| 2099 | 1583 | ||
| @@ -2110,7 +1594,8 @@ static struct inet_protosw tcpv6_protosw = { | |||
| 2110 | .ops = &inet6_stream_ops, | 1594 | .ops = &inet6_stream_ops, |
| 2111 | .capability = -1, | 1595 | .capability = -1, |
| 2112 | .no_check = 0, | 1596 | .no_check = 0, |
| 2113 | .flags = INET_PROTOSW_PERMANENT, | 1597 | .flags = INET_PROTOSW_PERMANENT | |
| 1598 | INET_PROTOSW_ICSK, | ||
| 2114 | }; | 1599 | }; |
| 2115 | 1600 | ||
| 2116 | void __init tcpv6_init(void) | 1601 | void __init tcpv6_init(void) |
