Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1 | /* |
| 2 | * net/dccp/ipv4.c |
| 3 | * |
| 4 | * An implementation of the DCCP protocol |
| 5 | * Arnaldo Carvalho de Melo <acme@conectiva.com.br> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * as published by the Free Software Foundation; either version |
| 10 | * 2 of the License, or (at your option) any later version. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/config.h> |
| 14 | #include <linux/dccp.h> |
| 15 | #include <linux/icmp.h> |
| 16 | #include <linux/module.h> |
| 17 | #include <linux/skbuff.h> |
| 18 | #include <linux/random.h> |
| 19 | |
| 20 | #include <net/icmp.h> |
| 21 | #include <net/inet_hashtables.h> |
Arnaldo Carvalho de Melo | 14c8502 | 2005-12-27 02:43:12 -0200 | [diff] [blame] | 22 | #include <net/inet_sock.h> |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 23 | #include <net/sock.h> |
Arnaldo Carvalho de Melo | 6d6ee43 | 2005-12-13 23:25:19 -0800 | [diff] [blame] | 24 | #include <net/timewait_sock.h> |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 25 | #include <net/tcp_states.h> |
| 26 | #include <net/xfrm.h> |
| 27 | |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 28 | #include "ackvec.h" |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 29 | #include "ccid.h" |
| 30 | #include "dccp.h" |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 31 | #include "feat.h" |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 32 | |
| 33 | struct inet_hashinfo __cacheline_aligned dccp_hashinfo = { |
| 34 | .lhash_lock = RW_LOCK_UNLOCKED, |
| 35 | .lhash_users = ATOMIC_INIT(0), |
Arnaldo Carvalho de Melo | 7690af3 | 2005-08-13 20:34:54 -0300 | [diff] [blame] | 36 | .lhash_wait = __WAIT_QUEUE_HEAD_INITIALIZER(dccp_hashinfo.lhash_wait), |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 37 | }; |
| 38 | |
Arnaldo Carvalho de Melo | 540722f | 2005-08-10 05:54:28 -0300 | [diff] [blame] | 39 | EXPORT_SYMBOL_GPL(dccp_hashinfo); |
| 40 | |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 41 | static int dccp_v4_get_port(struct sock *sk, const unsigned short snum) |
| 42 | { |
Arnaldo Carvalho de Melo | 971af18 | 2005-12-13 23:14:47 -0800 | [diff] [blame] | 43 | return inet_csk_get_port(&dccp_hashinfo, sk, snum, |
| 44 | inet_csk_bind_conflict); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | static void dccp_v4_hash(struct sock *sk) |
| 48 | { |
| 49 | inet_hash(&dccp_hashinfo, sk); |
| 50 | } |
| 51 | |
Arnaldo Carvalho de Melo | f21e68c | 2005-12-13 23:24:16 -0800 | [diff] [blame] | 52 | void dccp_unhash(struct sock *sk) |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 53 | { |
| 54 | inet_unhash(&dccp_hashinfo, sk); |
| 55 | } |
| 56 | |
Arnaldo Carvalho de Melo | f21e68c | 2005-12-13 23:24:16 -0800 | [diff] [blame] | 57 | EXPORT_SYMBOL_GPL(dccp_unhash); |
| 58 | |
Arnaldo Carvalho de Melo | f21e68c | 2005-12-13 23:24:16 -0800 | [diff] [blame] | 59 | int dccp_v4_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len) |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 60 | { |
| 61 | struct inet_sock *inet = inet_sk(sk); |
| 62 | struct dccp_sock *dp = dccp_sk(sk); |
| 63 | const struct sockaddr_in *usin = (struct sockaddr_in *)uaddr; |
| 64 | struct rtable *rt; |
| 65 | u32 daddr, nexthop; |
| 66 | int tmp; |
| 67 | int err; |
| 68 | |
| 69 | dp->dccps_role = DCCP_ROLE_CLIENT; |
| 70 | |
Arnaldo Carvalho de Melo | 67e6b62 | 2005-09-16 16:58:40 -0700 | [diff] [blame] | 71 | if (dccp_service_not_initialized(sk)) |
| 72 | return -EPROTO; |
| 73 | |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 74 | if (addr_len < sizeof(struct sockaddr_in)) |
| 75 | return -EINVAL; |
| 76 | |
| 77 | if (usin->sin_family != AF_INET) |
| 78 | return -EAFNOSUPPORT; |
| 79 | |
| 80 | nexthop = daddr = usin->sin_addr.s_addr; |
| 81 | if (inet->opt != NULL && inet->opt->srr) { |
| 82 | if (daddr == 0) |
| 83 | return -EINVAL; |
| 84 | nexthop = inet->opt->faddr; |
| 85 | } |
| 86 | |
| 87 | tmp = ip_route_connect(&rt, nexthop, inet->saddr, |
| 88 | RT_CONN_FLAGS(sk), sk->sk_bound_dev_if, |
| 89 | IPPROTO_DCCP, |
| 90 | inet->sport, usin->sin_port, sk); |
| 91 | if (tmp < 0) |
| 92 | return tmp; |
| 93 | |
| 94 | if (rt->rt_flags & (RTCF_MULTICAST | RTCF_BROADCAST)) { |
| 95 | ip_rt_put(rt); |
| 96 | return -ENETUNREACH; |
| 97 | } |
| 98 | |
| 99 | if (inet->opt == NULL || !inet->opt->srr) |
| 100 | daddr = rt->rt_dst; |
| 101 | |
| 102 | if (inet->saddr == 0) |
| 103 | inet->saddr = rt->rt_src; |
| 104 | inet->rcv_saddr = inet->saddr; |
| 105 | |
| 106 | inet->dport = usin->sin_port; |
| 107 | inet->daddr = daddr; |
| 108 | |
Arnaldo Carvalho de Melo | d83d846 | 2005-12-13 23:26:10 -0800 | [diff] [blame] | 109 | inet_csk(sk)->icsk_ext_hdr_len = 0; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 110 | if (inet->opt != NULL) |
Arnaldo Carvalho de Melo | d83d846 | 2005-12-13 23:26:10 -0800 | [diff] [blame] | 111 | inet_csk(sk)->icsk_ext_hdr_len = inet->opt->optlen; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 112 | /* |
| 113 | * Socket identity is still unknown (sport may be zero). |
| 114 | * However we set state to DCCP_REQUESTING and not releasing socket |
| 115 | * lock select source port, enter ourselves into the hash tables and |
| 116 | * complete initialization after this. |
| 117 | */ |
| 118 | dccp_set_state(sk, DCCP_REQUESTING); |
Arnaldo Carvalho de Melo | a7f5e7f | 2005-12-13 23:25:31 -0800 | [diff] [blame] | 119 | err = inet_hash_connect(&dccp_death_row, sk); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 120 | if (err != 0) |
| 121 | goto failure; |
| 122 | |
Patrick McHardy | 5d39a79 | 2006-01-31 17:35:35 -0800 | [diff] [blame] | 123 | err = ip_route_newports(&rt, IPPROTO_DCCP, inet->sport, inet->dport, |
| 124 | sk); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 125 | if (err != 0) |
| 126 | goto failure; |
| 127 | |
| 128 | /* OK, now commit destination to socket. */ |
| 129 | sk_setup_caps(sk, &rt->u.dst); |
| 130 | |
| 131 | dp->dccps_gar = |
| 132 | dp->dccps_iss = secure_dccp_sequence_number(inet->saddr, |
| 133 | inet->daddr, |
| 134 | inet->sport, |
| 135 | usin->sin_port); |
| 136 | dccp_update_gss(sk, dp->dccps_iss); |
| 137 | |
| 138 | inet->id = dp->dccps_iss ^ jiffies; |
| 139 | |
| 140 | err = dccp_connect(sk); |
| 141 | rt = NULL; |
| 142 | if (err != 0) |
| 143 | goto failure; |
| 144 | out: |
| 145 | return err; |
| 146 | failure: |
Arnaldo Carvalho de Melo | 7690af3 | 2005-08-13 20:34:54 -0300 | [diff] [blame] | 147 | /* |
| 148 | * This unhashes the socket and releases the local port, if necessary. |
| 149 | */ |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 150 | dccp_set_state(sk, DCCP_CLOSED); |
| 151 | ip_rt_put(rt); |
| 152 | sk->sk_route_caps = 0; |
| 153 | inet->dport = 0; |
| 154 | goto out; |
| 155 | } |
| 156 | |
Arnaldo Carvalho de Melo | f21e68c | 2005-12-13 23:24:16 -0800 | [diff] [blame] | 157 | EXPORT_SYMBOL_GPL(dccp_v4_connect); |
| 158 | |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 159 | /* |
| 160 | * This routine does path mtu discovery as defined in RFC1191. |
| 161 | */ |
| 162 | static inline void dccp_do_pmtu_discovery(struct sock *sk, |
| 163 | const struct iphdr *iph, |
| 164 | u32 mtu) |
| 165 | { |
| 166 | struct dst_entry *dst; |
| 167 | const struct inet_sock *inet = inet_sk(sk); |
| 168 | const struct dccp_sock *dp = dccp_sk(sk); |
| 169 | |
| 170 | /* We are not interested in DCCP_LISTEN and request_socks (RESPONSEs |
| 171 | * send out by Linux are always < 576bytes so they should go through |
| 172 | * unfragmented). |
| 173 | */ |
| 174 | if (sk->sk_state == DCCP_LISTEN) |
| 175 | return; |
| 176 | |
| 177 | /* We don't check in the destentry if pmtu discovery is forbidden |
| 178 | * on this route. We just assume that no packet_to_big packets |
| 179 | * are send back when pmtu discovery is not active. |
| 180 | * There is a small race when the user changes this flag in the |
| 181 | * route, but I think that's acceptable. |
| 182 | */ |
| 183 | if ((dst = __sk_dst_check(sk, 0)) == NULL) |
| 184 | return; |
| 185 | |
| 186 | dst->ops->update_pmtu(dst, mtu); |
| 187 | |
| 188 | /* Something is about to be wrong... Remember soft error |
| 189 | * for the case, if this connection will not able to recover. |
| 190 | */ |
| 191 | if (mtu < dst_mtu(dst) && ip_dont_fragment(sk, dst)) |
| 192 | sk->sk_err_soft = EMSGSIZE; |
| 193 | |
| 194 | mtu = dst_mtu(dst); |
| 195 | |
| 196 | if (inet->pmtudisc != IP_PMTUDISC_DONT && |
Arnaldo Carvalho de Melo | d83d846 | 2005-12-13 23:26:10 -0800 | [diff] [blame] | 197 | inet_csk(sk)->icsk_pmtu_cookie > mtu) { |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 198 | dccp_sync_mss(sk, mtu); |
| 199 | |
| 200 | /* |
| 201 | * From: draft-ietf-dccp-spec-11.txt |
| 202 | * |
Arnaldo Carvalho de Melo | 7690af3 | 2005-08-13 20:34:54 -0300 | [diff] [blame] | 203 | * DCCP-Sync packets are the best choice for upward |
| 204 | * probing, since DCCP-Sync probes do not risk application |
| 205 | * data loss. |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 206 | */ |
Arnaldo Carvalho de Melo | e92ae93 | 2005-08-17 03:10:59 -0300 | [diff] [blame] | 207 | dccp_send_sync(sk, dp->dccps_gsr, DCCP_PKT_SYNC); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 208 | } /* else let the usual retransmit timer handle it */ |
| 209 | } |
| 210 | |
| 211 | static void dccp_v4_ctl_send_ack(struct sk_buff *rxskb) |
| 212 | { |
| 213 | int err; |
| 214 | struct dccp_hdr *rxdh = dccp_hdr(rxskb), *dh; |
| 215 | const int dccp_hdr_ack_len = sizeof(struct dccp_hdr) + |
| 216 | sizeof(struct dccp_hdr_ext) + |
| 217 | sizeof(struct dccp_hdr_ack_bits); |
| 218 | struct sk_buff *skb; |
| 219 | |
| 220 | if (((struct rtable *)rxskb->dst)->rt_type != RTN_LOCAL) |
| 221 | return; |
| 222 | |
| 223 | skb = alloc_skb(MAX_DCCP_HEADER + 15, GFP_ATOMIC); |
| 224 | if (skb == NULL) |
| 225 | return; |
| 226 | |
| 227 | /* Reserve space for headers. */ |
| 228 | skb_reserve(skb, MAX_DCCP_HEADER); |
| 229 | |
| 230 | skb->dst = dst_clone(rxskb->dst); |
| 231 | |
| 232 | skb->h.raw = skb_push(skb, dccp_hdr_ack_len); |
| 233 | dh = dccp_hdr(skb); |
| 234 | memset(dh, 0, dccp_hdr_ack_len); |
| 235 | |
| 236 | /* Build DCCP header and checksum it. */ |
| 237 | dh->dccph_type = DCCP_PKT_ACK; |
| 238 | dh->dccph_sport = rxdh->dccph_dport; |
| 239 | dh->dccph_dport = rxdh->dccph_sport; |
| 240 | dh->dccph_doff = dccp_hdr_ack_len / 4; |
| 241 | dh->dccph_x = 1; |
| 242 | |
| 243 | dccp_hdr_set_seq(dh, DCCP_SKB_CB(rxskb)->dccpd_ack_seq); |
Arnaldo Carvalho de Melo | 7690af3 | 2005-08-13 20:34:54 -0300 | [diff] [blame] | 244 | dccp_hdr_set_ack(dccp_hdr_ack_bits(skb), |
| 245 | DCCP_SKB_CB(rxskb)->dccpd_seq); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 246 | |
| 247 | bh_lock_sock(dccp_ctl_socket->sk); |
| 248 | err = ip_build_and_send_pkt(skb, dccp_ctl_socket->sk, |
Arnaldo Carvalho de Melo | 7690af3 | 2005-08-13 20:34:54 -0300 | [diff] [blame] | 249 | rxskb->nh.iph->daddr, |
| 250 | rxskb->nh.iph->saddr, NULL); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 251 | bh_unlock_sock(dccp_ctl_socket->sk); |
| 252 | |
| 253 | if (err == NET_XMIT_CN || err == 0) { |
| 254 | DCCP_INC_STATS_BH(DCCP_MIB_OUTSEGS); |
| 255 | DCCP_INC_STATS_BH(DCCP_MIB_OUTRSTS); |
| 256 | } |
| 257 | } |
| 258 | |
Arnaldo Carvalho de Melo | 7690af3 | 2005-08-13 20:34:54 -0300 | [diff] [blame] | 259 | static void dccp_v4_reqsk_send_ack(struct sk_buff *skb, |
| 260 | struct request_sock *req) |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 261 | { |
| 262 | dccp_v4_ctl_send_ack(skb); |
| 263 | } |
| 264 | |
| 265 | static int dccp_v4_send_response(struct sock *sk, struct request_sock *req, |
| 266 | struct dst_entry *dst) |
| 267 | { |
| 268 | int err = -1; |
| 269 | struct sk_buff *skb; |
| 270 | |
| 271 | /* First, grab a route. */ |
| 272 | |
| 273 | if (dst == NULL && (dst = inet_csk_route_req(sk, req)) == NULL) |
| 274 | goto out; |
| 275 | |
| 276 | skb = dccp_make_response(sk, dst, req); |
| 277 | if (skb != NULL) { |
| 278 | const struct inet_request_sock *ireq = inet_rsk(req); |
| 279 | |
Herbert Xu | 49c5bfa | 2005-10-18 12:03:28 +1000 | [diff] [blame] | 280 | memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt)); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 281 | err = ip_build_and_send_pkt(skb, sk, ireq->loc_addr, |
| 282 | ireq->rmt_addr, |
| 283 | ireq->opt); |
| 284 | if (err == NET_XMIT_CN) |
| 285 | err = 0; |
| 286 | } |
| 287 | |
| 288 | out: |
| 289 | dst_release(dst); |
| 290 | return err; |
| 291 | } |
| 292 | |
| 293 | /* |
| 294 | * This routine is called by the ICMP module when it gets some sort of error |
| 295 | * condition. If err < 0 then the socket should be closed and the error |
| 296 | * returned to the user. If err > 0 it's just the icmp type << 8 | icmp code. |
| 297 | * After adjustment header points to the first 8 bytes of the tcp header. We |
| 298 | * need to find the appropriate port. |
| 299 | * |
| 300 | * The locking strategy used here is very "optimistic". When someone else |
| 301 | * accesses the socket the ICMP is just dropped and for some paths there is no |
| 302 | * check at all. A more general error queue to queue errors for later handling |
| 303 | * is probably better. |
| 304 | */ |
| 305 | void dccp_v4_err(struct sk_buff *skb, u32 info) |
| 306 | { |
| 307 | const struct iphdr *iph = (struct iphdr *)skb->data; |
Arnaldo Carvalho de Melo | 7690af3 | 2005-08-13 20:34:54 -0300 | [diff] [blame] | 308 | const struct dccp_hdr *dh = (struct dccp_hdr *)(skb->data + |
| 309 | (iph->ihl << 2)); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 310 | struct dccp_sock *dp; |
| 311 | struct inet_sock *inet; |
| 312 | const int type = skb->h.icmph->type; |
| 313 | const int code = skb->h.icmph->code; |
| 314 | struct sock *sk; |
| 315 | __u64 seq; |
| 316 | int err; |
| 317 | |
| 318 | if (skb->len < (iph->ihl << 2) + 8) { |
| 319 | ICMP_INC_STATS_BH(ICMP_MIB_INERRORS); |
| 320 | return; |
| 321 | } |
| 322 | |
| 323 | sk = inet_lookup(&dccp_hashinfo, iph->daddr, dh->dccph_dport, |
| 324 | iph->saddr, dh->dccph_sport, inet_iif(skb)); |
| 325 | if (sk == NULL) { |
| 326 | ICMP_INC_STATS_BH(ICMP_MIB_INERRORS); |
| 327 | return; |
| 328 | } |
| 329 | |
| 330 | if (sk->sk_state == DCCP_TIME_WAIT) { |
| 331 | inet_twsk_put((struct inet_timewait_sock *)sk); |
| 332 | return; |
| 333 | } |
| 334 | |
| 335 | bh_lock_sock(sk); |
| 336 | /* If too many ICMPs get dropped on busy |
| 337 | * servers this needs to be solved differently. |
| 338 | */ |
| 339 | if (sock_owned_by_user(sk)) |
| 340 | NET_INC_STATS_BH(LINUX_MIB_LOCKDROPPEDICMPS); |
| 341 | |
| 342 | if (sk->sk_state == DCCP_CLOSED) |
| 343 | goto out; |
| 344 | |
| 345 | dp = dccp_sk(sk); |
| 346 | seq = dccp_hdr_seq(skb); |
| 347 | if (sk->sk_state != DCCP_LISTEN && |
| 348 | !between48(seq, dp->dccps_swl, dp->dccps_swh)) { |
| 349 | NET_INC_STATS(LINUX_MIB_OUTOFWINDOWICMPS); |
| 350 | goto out; |
| 351 | } |
| 352 | |
| 353 | switch (type) { |
| 354 | case ICMP_SOURCE_QUENCH: |
| 355 | /* Just silently ignore these. */ |
| 356 | goto out; |
| 357 | case ICMP_PARAMETERPROB: |
| 358 | err = EPROTO; |
| 359 | break; |
| 360 | case ICMP_DEST_UNREACH: |
| 361 | if (code > NR_ICMP_UNREACH) |
| 362 | goto out; |
| 363 | |
| 364 | if (code == ICMP_FRAG_NEEDED) { /* PMTU discovery (RFC1191) */ |
| 365 | if (!sock_owned_by_user(sk)) |
| 366 | dccp_do_pmtu_discovery(sk, iph, info); |
| 367 | goto out; |
| 368 | } |
| 369 | |
| 370 | err = icmp_err_convert[code].errno; |
| 371 | break; |
| 372 | case ICMP_TIME_EXCEEDED: |
| 373 | err = EHOSTUNREACH; |
| 374 | break; |
| 375 | default: |
| 376 | goto out; |
| 377 | } |
| 378 | |
| 379 | switch (sk->sk_state) { |
| 380 | struct request_sock *req , **prev; |
| 381 | case DCCP_LISTEN: |
| 382 | if (sock_owned_by_user(sk)) |
| 383 | goto out; |
| 384 | req = inet_csk_search_req(sk, &prev, dh->dccph_dport, |
| 385 | iph->daddr, iph->saddr); |
| 386 | if (!req) |
| 387 | goto out; |
| 388 | |
| 389 | /* |
| 390 | * ICMPs are not backlogged, hence we cannot get an established |
| 391 | * socket here. |
| 392 | */ |
| 393 | BUG_TRAP(!req->sk); |
| 394 | |
| 395 | if (seq != dccp_rsk(req)->dreq_iss) { |
| 396 | NET_INC_STATS_BH(LINUX_MIB_OUTOFWINDOWICMPS); |
| 397 | goto out; |
| 398 | } |
| 399 | /* |
| 400 | * Still in RESPOND, just remove it silently. |
| 401 | * There is no good way to pass the error to the newly |
| 402 | * created socket, and POSIX does not want network |
| 403 | * errors returned from accept(). |
| 404 | */ |
| 405 | inet_csk_reqsk_queue_drop(sk, req, prev); |
| 406 | goto out; |
| 407 | |
| 408 | case DCCP_REQUESTING: |
| 409 | case DCCP_RESPOND: |
| 410 | if (!sock_owned_by_user(sk)) { |
| 411 | DCCP_INC_STATS_BH(DCCP_MIB_ATTEMPTFAILS); |
| 412 | sk->sk_err = err; |
| 413 | |
| 414 | sk->sk_error_report(sk); |
| 415 | |
| 416 | dccp_done(sk); |
| 417 | } else |
| 418 | sk->sk_err_soft = err; |
| 419 | goto out; |
| 420 | } |
| 421 | |
| 422 | /* If we've already connected we will keep trying |
| 423 | * until we time out, or the user gives up. |
| 424 | * |
| 425 | * rfc1122 4.2.3.9 allows to consider as hard errors |
| 426 | * only PROTO_UNREACH and PORT_UNREACH (well, FRAG_FAILED too, |
| 427 | * but it is obsoleted by pmtu discovery). |
| 428 | * |
| 429 | * Note, that in modern internet, where routing is unreliable |
| 430 | * and in each dark corner broken firewalls sit, sending random |
| 431 | * errors ordered by their masters even this two messages finally lose |
| 432 | * their original sense (even Linux sends invalid PORT_UNREACHs) |
| 433 | * |
| 434 | * Now we are in compliance with RFCs. |
| 435 | * --ANK (980905) |
| 436 | */ |
| 437 | |
| 438 | inet = inet_sk(sk); |
| 439 | if (!sock_owned_by_user(sk) && inet->recverr) { |
| 440 | sk->sk_err = err; |
| 441 | sk->sk_error_report(sk); |
| 442 | } else /* Only an error on timeout */ |
| 443 | sk->sk_err_soft = err; |
| 444 | out: |
| 445 | bh_unlock_sock(sk); |
| 446 | sock_put(sk); |
| 447 | } |
| 448 | |
Arnaldo Carvalho de Melo | 57cca05 | 2005-12-13 23:16:16 -0800 | [diff] [blame] | 449 | /* This routine computes an IPv4 DCCP checksum. */ |
Arnaldo Carvalho de Melo | f21e68c | 2005-12-13 23:24:16 -0800 | [diff] [blame] | 450 | void dccp_v4_send_check(struct sock *sk, int len, struct sk_buff *skb) |
Arnaldo Carvalho de Melo | 57cca05 | 2005-12-13 23:16:16 -0800 | [diff] [blame] | 451 | { |
| 452 | const struct inet_sock *inet = inet_sk(sk); |
| 453 | struct dccp_hdr *dh = dccp_hdr(skb); |
| 454 | |
| 455 | dh->dccph_checksum = dccp_v4_checksum(skb, inet->saddr, inet->daddr); |
| 456 | } |
| 457 | |
Arnaldo Carvalho de Melo | f21e68c | 2005-12-13 23:24:16 -0800 | [diff] [blame] | 458 | EXPORT_SYMBOL_GPL(dccp_v4_send_check); |
| 459 | |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 460 | int dccp_v4_send_reset(struct sock *sk, enum dccp_reset_codes code) |
| 461 | { |
| 462 | struct sk_buff *skb; |
| 463 | /* |
| 464 | * FIXME: what if rebuild_header fails? |
| 465 | * Should we be doing a rebuild_header here? |
| 466 | */ |
| 467 | int err = inet_sk_rebuild_header(sk); |
| 468 | |
| 469 | if (err != 0) |
| 470 | return err; |
| 471 | |
| 472 | skb = dccp_make_reset(sk, sk->sk_dst_cache, code); |
| 473 | if (skb != NULL) { |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 474 | const struct inet_sock *inet = inet_sk(sk); |
| 475 | |
Herbert Xu | 49c5bfa | 2005-10-18 12:03:28 +1000 | [diff] [blame] | 476 | memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt)); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 477 | err = ip_build_and_send_pkt(skb, sk, |
| 478 | inet->saddr, inet->daddr, NULL); |
| 479 | if (err == NET_XMIT_CN) |
| 480 | err = 0; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | return err; |
| 484 | } |
| 485 | |
| 486 | static inline u64 dccp_v4_init_sequence(const struct sock *sk, |
| 487 | const struct sk_buff *skb) |
| 488 | { |
| 489 | return secure_dccp_sequence_number(skb->nh.iph->daddr, |
| 490 | skb->nh.iph->saddr, |
| 491 | dccp_hdr(skb)->dccph_dport, |
| 492 | dccp_hdr(skb)->dccph_sport); |
| 493 | } |
| 494 | |
| 495 | int dccp_v4_conn_request(struct sock *sk, struct sk_buff *skb) |
| 496 | { |
| 497 | struct inet_request_sock *ireq; |
| 498 | struct dccp_sock dp; |
| 499 | struct request_sock *req; |
| 500 | struct dccp_request_sock *dreq; |
Andrea Bittau | 60fe62e | 2006-03-20 19:23:32 -0800 | [diff] [blame^] | 501 | const __be32 saddr = skb->nh.iph->saddr; |
| 502 | const __be32 daddr = skb->nh.iph->daddr; |
| 503 | const __be32 service = dccp_hdr_request(skb)->dccph_req_service; |
Arnaldo Carvalho de Melo | 0c10c5d | 2005-09-16 16:58:33 -0700 | [diff] [blame] | 504 | struct dccp_skb_cb *dcb = DCCP_SKB_CB(skb); |
| 505 | __u8 reset_code = DCCP_RESET_CODE_TOO_BUSY; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 506 | |
| 507 | /* Never answer to DCCP_PKT_REQUESTs send to broadcast or multicast */ |
| 508 | if (((struct rtable *)skb->dst)->rt_flags & |
Arnaldo Carvalho de Melo | 0c10c5d | 2005-09-16 16:58:33 -0700 | [diff] [blame] | 509 | (RTCF_BROADCAST | RTCF_MULTICAST)) { |
| 510 | reset_code = DCCP_RESET_CODE_NO_CONNECTION; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 511 | goto drop; |
Arnaldo Carvalho de Melo | 0c10c5d | 2005-09-16 16:58:33 -0700 | [diff] [blame] | 512 | } |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 513 | |
Arnaldo Carvalho de Melo | 67e6b62 | 2005-09-16 16:58:40 -0700 | [diff] [blame] | 514 | if (dccp_bad_service_code(sk, service)) { |
| 515 | reset_code = DCCP_RESET_CODE_BAD_SERVICE_CODE; |
| 516 | goto drop; |
| 517 | } |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 518 | /* |
| 519 | * TW buckets are converted to open requests without |
| 520 | * limitations, they conserve resources and peer is |
| 521 | * evidently real one. |
| 522 | */ |
| 523 | if (inet_csk_reqsk_queue_is_full(sk)) |
| 524 | goto drop; |
| 525 | |
| 526 | /* |
| 527 | * Accept backlog is full. If we have already queued enough |
| 528 | * of warm entries in syn queue, drop request. It is better than |
| 529 | * clogging syn queue with openreqs with exponentially increasing |
| 530 | * timeout. |
| 531 | */ |
| 532 | if (sk_acceptq_is_full(sk) && inet_csk_reqsk_queue_young(sk) > 1) |
| 533 | goto drop; |
| 534 | |
| 535 | req = reqsk_alloc(sk->sk_prot->rsk_prot); |
| 536 | if (req == NULL) |
| 537 | goto drop; |
| 538 | |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 539 | if (dccp_parse_options(sk, skb)) |
| 540 | goto drop; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 541 | |
| 542 | dccp_openreq_init(req, &dp, skb); |
| 543 | |
| 544 | ireq = inet_rsk(req); |
| 545 | ireq->loc_addr = daddr; |
| 546 | ireq->rmt_addr = saddr; |
Arnaldo Carvalho de Melo | 7690af3 | 2005-08-13 20:34:54 -0300 | [diff] [blame] | 547 | req->rcv_wnd = 100; /* Fake, option parsing will get the |
| 548 | right value */ |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 549 | ireq->opt = NULL; |
| 550 | |
| 551 | /* |
| 552 | * Step 3: Process LISTEN state |
| 553 | * |
| 554 | * Set S.ISR, S.GSR, S.SWL, S.SWH from packet or Init Cookie |
| 555 | * |
| 556 | * In fact we defer setting S.GSR, S.SWL, S.SWH to |
| 557 | * dccp_create_openreq_child. |
| 558 | */ |
| 559 | dreq = dccp_rsk(req); |
Arnaldo Carvalho de Melo | 67e6b62 | 2005-09-16 16:58:40 -0700 | [diff] [blame] | 560 | dreq->dreq_isr = dcb->dccpd_seq; |
| 561 | dreq->dreq_iss = dccp_v4_init_sequence(sk, skb); |
| 562 | dreq->dreq_service = service; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 563 | |
Arnaldo Carvalho de Melo | f21e68c | 2005-12-13 23:24:16 -0800 | [diff] [blame] | 564 | if (dccp_v4_send_response(sk, req, NULL)) |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 565 | goto drop_and_free; |
| 566 | |
| 567 | inet_csk_reqsk_queue_hash_add(sk, req, DCCP_TIMEOUT_INIT); |
| 568 | return 0; |
| 569 | |
| 570 | drop_and_free: |
Arnaldo Carvalho de Melo | fc44b98 | 2005-12-13 23:25:06 -0800 | [diff] [blame] | 571 | reqsk_free(req); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 572 | drop: |
| 573 | DCCP_INC_STATS_BH(DCCP_MIB_ATTEMPTFAILS); |
Arnaldo Carvalho de Melo | 0c10c5d | 2005-09-16 16:58:33 -0700 | [diff] [blame] | 574 | dcb->dccpd_reset_code = reset_code; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 575 | return -1; |
| 576 | } |
| 577 | |
Arnaldo Carvalho de Melo | f21e68c | 2005-12-13 23:24:16 -0800 | [diff] [blame] | 578 | EXPORT_SYMBOL_GPL(dccp_v4_conn_request); |
| 579 | |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 580 | /* |
| 581 | * The three way handshake has completed - we got a valid ACK or DATAACK - |
| 582 | * now create the new socket. |
| 583 | * |
| 584 | * This is the equivalent of TCP's tcp_v4_syn_recv_sock |
| 585 | */ |
| 586 | struct sock *dccp_v4_request_recv_sock(struct sock *sk, struct sk_buff *skb, |
| 587 | struct request_sock *req, |
| 588 | struct dst_entry *dst) |
| 589 | { |
| 590 | struct inet_request_sock *ireq; |
| 591 | struct inet_sock *newinet; |
| 592 | struct dccp_sock *newdp; |
| 593 | struct sock *newsk; |
| 594 | |
| 595 | if (sk_acceptq_is_full(sk)) |
| 596 | goto exit_overflow; |
| 597 | |
| 598 | if (dst == NULL && (dst = inet_csk_route_req(sk, req)) == NULL) |
| 599 | goto exit; |
| 600 | |
| 601 | newsk = dccp_create_openreq_child(sk, req, skb); |
| 602 | if (newsk == NULL) |
| 603 | goto exit; |
| 604 | |
| 605 | sk_setup_caps(newsk, dst); |
| 606 | |
| 607 | newdp = dccp_sk(newsk); |
| 608 | newinet = inet_sk(newsk); |
| 609 | ireq = inet_rsk(req); |
| 610 | newinet->daddr = ireq->rmt_addr; |
| 611 | newinet->rcv_saddr = ireq->loc_addr; |
| 612 | newinet->saddr = ireq->loc_addr; |
| 613 | newinet->opt = ireq->opt; |
| 614 | ireq->opt = NULL; |
| 615 | newinet->mc_index = inet_iif(skb); |
| 616 | newinet->mc_ttl = skb->nh.iph->ttl; |
| 617 | newinet->id = jiffies; |
| 618 | |
| 619 | dccp_sync_mss(newsk, dst_mtu(dst)); |
| 620 | |
| 621 | __inet_hash(&dccp_hashinfo, newsk, 0); |
| 622 | __inet_inherit_port(&dccp_hashinfo, sk, newsk); |
| 623 | |
| 624 | return newsk; |
| 625 | |
| 626 | exit_overflow: |
| 627 | NET_INC_STATS_BH(LINUX_MIB_LISTENOVERFLOWS); |
| 628 | exit: |
| 629 | NET_INC_STATS_BH(LINUX_MIB_LISTENDROPS); |
| 630 | dst_release(dst); |
| 631 | return NULL; |
| 632 | } |
| 633 | |
Arnaldo Carvalho de Melo | f21e68c | 2005-12-13 23:24:16 -0800 | [diff] [blame] | 634 | EXPORT_SYMBOL_GPL(dccp_v4_request_recv_sock); |
| 635 | |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 636 | static struct sock *dccp_v4_hnd_req(struct sock *sk, struct sk_buff *skb) |
| 637 | { |
| 638 | const struct dccp_hdr *dh = dccp_hdr(skb); |
| 639 | const struct iphdr *iph = skb->nh.iph; |
| 640 | struct sock *nsk; |
| 641 | struct request_sock **prev; |
| 642 | /* Find possible connection requests. */ |
| 643 | struct request_sock *req = inet_csk_search_req(sk, &prev, |
| 644 | dh->dccph_sport, |
| 645 | iph->saddr, iph->daddr); |
| 646 | if (req != NULL) |
| 647 | return dccp_check_req(sk, skb, req, prev); |
| 648 | |
| 649 | nsk = __inet_lookup_established(&dccp_hashinfo, |
| 650 | iph->saddr, dh->dccph_sport, |
| 651 | iph->daddr, ntohs(dh->dccph_dport), |
| 652 | inet_iif(skb)); |
| 653 | if (nsk != NULL) { |
| 654 | if (nsk->sk_state != DCCP_TIME_WAIT) { |
| 655 | bh_lock_sock(nsk); |
| 656 | return nsk; |
| 657 | } |
| 658 | inet_twsk_put((struct inet_timewait_sock *)nsk); |
| 659 | return NULL; |
| 660 | } |
| 661 | |
| 662 | return sk; |
| 663 | } |
| 664 | |
Andrea Bittau | 60fe62e | 2006-03-20 19:23:32 -0800 | [diff] [blame^] | 665 | int dccp_v4_checksum(const struct sk_buff *skb, const __be32 saddr, |
| 666 | const __be32 daddr) |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 667 | { |
Yoshifumi Nishida | 95b81ef | 2005-08-09 20:15:35 -0700 | [diff] [blame] | 668 | const struct dccp_hdr* dh = dccp_hdr(skb); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 669 | int checksum_len; |
| 670 | u32 tmp; |
| 671 | |
| 672 | if (dh->dccph_cscov == 0) |
| 673 | checksum_len = skb->len; |
| 674 | else { |
| 675 | checksum_len = (dh->dccph_cscov + dh->dccph_x) * sizeof(u32); |
Arnaldo Carvalho de Melo | 7690af3 | 2005-08-13 20:34:54 -0300 | [diff] [blame] | 676 | checksum_len = checksum_len < skb->len ? checksum_len : |
| 677 | skb->len; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 678 | } |
| 679 | |
| 680 | tmp = csum_partial((unsigned char *)dh, checksum_len, 0); |
Arnaldo Carvalho de Melo | 7690af3 | 2005-08-13 20:34:54 -0300 | [diff] [blame] | 681 | return csum_tcpudp_magic(saddr, daddr, checksum_len, |
| 682 | IPPROTO_DCCP, tmp); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 683 | } |
| 684 | |
Yoshifumi Nishida | 95b81ef | 2005-08-09 20:15:35 -0700 | [diff] [blame] | 685 | static int dccp_v4_verify_checksum(struct sk_buff *skb, |
Andrea Bittau | 60fe62e | 2006-03-20 19:23:32 -0800 | [diff] [blame^] | 686 | const __be32 saddr, const __be32 daddr) |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 687 | { |
Yoshifumi Nishida | 95b81ef | 2005-08-09 20:15:35 -0700 | [diff] [blame] | 688 | struct dccp_hdr *dh = dccp_hdr(skb); |
| 689 | int checksum_len; |
| 690 | u32 tmp; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 691 | |
Yoshifumi Nishida | 95b81ef | 2005-08-09 20:15:35 -0700 | [diff] [blame] | 692 | if (dh->dccph_cscov == 0) |
| 693 | checksum_len = skb->len; |
| 694 | else { |
| 695 | checksum_len = (dh->dccph_cscov + dh->dccph_x) * sizeof(u32); |
Arnaldo Carvalho de Melo | 7690af3 | 2005-08-13 20:34:54 -0300 | [diff] [blame] | 696 | checksum_len = checksum_len < skb->len ? checksum_len : |
| 697 | skb->len; |
Yoshifumi Nishida | 95b81ef | 2005-08-09 20:15:35 -0700 | [diff] [blame] | 698 | } |
| 699 | tmp = csum_partial((unsigned char *)dh, checksum_len, 0); |
Arnaldo Carvalho de Melo | 7690af3 | 2005-08-13 20:34:54 -0300 | [diff] [blame] | 700 | return csum_tcpudp_magic(saddr, daddr, checksum_len, |
| 701 | IPPROTO_DCCP, tmp) == 0 ? 0 : -1; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | static struct dst_entry* dccp_v4_route_skb(struct sock *sk, |
| 705 | struct sk_buff *skb) |
| 706 | { |
| 707 | struct rtable *rt; |
| 708 | struct flowi fl = { .oif = ((struct rtable *)skb->dst)->rt_iif, |
| 709 | .nl_u = { .ip4_u = |
| 710 | { .daddr = skb->nh.iph->saddr, |
| 711 | .saddr = skb->nh.iph->daddr, |
| 712 | .tos = RT_CONN_FLAGS(sk) } }, |
| 713 | .proto = sk->sk_protocol, |
| 714 | .uli_u = { .ports = |
| 715 | { .sport = dccp_hdr(skb)->dccph_dport, |
Arnaldo Carvalho de Melo | 7690af3 | 2005-08-13 20:34:54 -0300 | [diff] [blame] | 716 | .dport = dccp_hdr(skb)->dccph_sport } |
| 717 | } |
| 718 | }; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 719 | |
| 720 | if (ip_route_output_flow(&rt, &fl, sk, 0)) { |
| 721 | IP_INC_STATS_BH(IPSTATS_MIB_OUTNOROUTES); |
| 722 | return NULL; |
| 723 | } |
| 724 | |
| 725 | return &rt->u.dst; |
| 726 | } |
| 727 | |
Arnaldo Carvalho de Melo | a1d3a35 | 2005-08-13 22:42:25 -0300 | [diff] [blame] | 728 | static void dccp_v4_ctl_send_reset(struct sk_buff *rxskb) |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 729 | { |
| 730 | int err; |
| 731 | struct dccp_hdr *rxdh = dccp_hdr(rxskb), *dh; |
| 732 | const int dccp_hdr_reset_len = sizeof(struct dccp_hdr) + |
| 733 | sizeof(struct dccp_hdr_ext) + |
| 734 | sizeof(struct dccp_hdr_reset); |
| 735 | struct sk_buff *skb; |
| 736 | struct dst_entry *dst; |
Arnaldo Carvalho de Melo | 2807d4f | 2005-08-21 05:33:48 -0300 | [diff] [blame] | 737 | u64 seqno; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 738 | |
| 739 | /* Never send a reset in response to a reset. */ |
| 740 | if (rxdh->dccph_type == DCCP_PKT_RESET) |
| 741 | return; |
| 742 | |
| 743 | if (((struct rtable *)rxskb->dst)->rt_type != RTN_LOCAL) |
| 744 | return; |
| 745 | |
| 746 | dst = dccp_v4_route_skb(dccp_ctl_socket->sk, rxskb); |
| 747 | if (dst == NULL) |
| 748 | return; |
| 749 | |
| 750 | skb = alloc_skb(MAX_DCCP_HEADER + 15, GFP_ATOMIC); |
| 751 | if (skb == NULL) |
| 752 | goto out; |
| 753 | |
| 754 | /* Reserve space for headers. */ |
| 755 | skb_reserve(skb, MAX_DCCP_HEADER); |
| 756 | skb->dst = dst_clone(dst); |
| 757 | |
| 758 | skb->h.raw = skb_push(skb, dccp_hdr_reset_len); |
| 759 | dh = dccp_hdr(skb); |
| 760 | memset(dh, 0, dccp_hdr_reset_len); |
| 761 | |
| 762 | /* Build DCCP header and checksum it. */ |
| 763 | dh->dccph_type = DCCP_PKT_RESET; |
| 764 | dh->dccph_sport = rxdh->dccph_dport; |
| 765 | dh->dccph_dport = rxdh->dccph_sport; |
| 766 | dh->dccph_doff = dccp_hdr_reset_len / 4; |
| 767 | dh->dccph_x = 1; |
Arnaldo Carvalho de Melo | 7690af3 | 2005-08-13 20:34:54 -0300 | [diff] [blame] | 768 | dccp_hdr_reset(skb)->dccph_reset_code = |
| 769 | DCCP_SKB_CB(rxskb)->dccpd_reset_code; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 770 | |
Arnaldo Carvalho de Melo | 2807d4f | 2005-08-21 05:33:48 -0300 | [diff] [blame] | 771 | /* See "8.3.1. Abnormal Termination" in draft-ietf-dccp-spec-11 */ |
| 772 | seqno = 0; |
| 773 | if (DCCP_SKB_CB(rxskb)->dccpd_ack_seq != DCCP_PKT_WITHOUT_ACK_SEQ) |
| 774 | dccp_set_seqno(&seqno, DCCP_SKB_CB(rxskb)->dccpd_ack_seq + 1); |
| 775 | |
| 776 | dccp_hdr_set_seq(dh, seqno); |
Arnaldo Carvalho de Melo | 7690af3 | 2005-08-13 20:34:54 -0300 | [diff] [blame] | 777 | dccp_hdr_set_ack(dccp_hdr_ack_bits(skb), |
| 778 | DCCP_SKB_CB(rxskb)->dccpd_seq); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 779 | |
Yoshifumi Nishida | 95b81ef | 2005-08-09 20:15:35 -0700 | [diff] [blame] | 780 | dh->dccph_checksum = dccp_v4_checksum(skb, rxskb->nh.iph->saddr, |
| 781 | rxskb->nh.iph->daddr); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 782 | |
| 783 | bh_lock_sock(dccp_ctl_socket->sk); |
| 784 | err = ip_build_and_send_pkt(skb, dccp_ctl_socket->sk, |
Arnaldo Carvalho de Melo | 7690af3 | 2005-08-13 20:34:54 -0300 | [diff] [blame] | 785 | rxskb->nh.iph->daddr, |
| 786 | rxskb->nh.iph->saddr, NULL); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 787 | bh_unlock_sock(dccp_ctl_socket->sk); |
| 788 | |
| 789 | if (err == NET_XMIT_CN || err == 0) { |
| 790 | DCCP_INC_STATS_BH(DCCP_MIB_OUTSEGS); |
| 791 | DCCP_INC_STATS_BH(DCCP_MIB_OUTRSTS); |
| 792 | } |
| 793 | out: |
| 794 | dst_release(dst); |
| 795 | } |
| 796 | |
| 797 | int dccp_v4_do_rcv(struct sock *sk, struct sk_buff *skb) |
| 798 | { |
| 799 | struct dccp_hdr *dh = dccp_hdr(skb); |
| 800 | |
| 801 | if (sk->sk_state == DCCP_OPEN) { /* Fast path */ |
| 802 | if (dccp_rcv_established(sk, skb, dh, skb->len)) |
| 803 | goto reset; |
| 804 | return 0; |
| 805 | } |
| 806 | |
| 807 | /* |
| 808 | * Step 3: Process LISTEN state |
| 809 | * If S.state == LISTEN, |
Arnaldo Carvalho de Melo | 7690af3 | 2005-08-13 20:34:54 -0300 | [diff] [blame] | 810 | * If P.type == Request or P contains a valid Init Cookie |
| 811 | * option, |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 812 | * * Must scan the packet's options to check for an Init |
| 813 | * Cookie. Only the Init Cookie is processed here, |
| 814 | * however; other options are processed in Step 8. This |
| 815 | * scan need only be performed if the endpoint uses Init |
| 816 | * Cookies * |
| 817 | * * Generate a new socket and switch to that socket * |
| 818 | * Set S := new socket for this port pair |
| 819 | * S.state = RESPOND |
| 820 | * Choose S.ISS (initial seqno) or set from Init Cookie |
| 821 | * Set S.ISR, S.GSR, S.SWL, S.SWH from packet or Init Cookie |
| 822 | * Continue with S.state == RESPOND |
| 823 | * * A Response packet will be generated in Step 11 * |
| 824 | * Otherwise, |
| 825 | * Generate Reset(No Connection) unless P.type == Reset |
| 826 | * Drop packet and return |
| 827 | * |
Arnaldo Carvalho de Melo | 7690af3 | 2005-08-13 20:34:54 -0300 | [diff] [blame] | 828 | * NOTE: the check for the packet types is done in |
| 829 | * dccp_rcv_state_process |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 830 | */ |
| 831 | if (sk->sk_state == DCCP_LISTEN) { |
| 832 | struct sock *nsk = dccp_v4_hnd_req(sk, skb); |
| 833 | |
| 834 | if (nsk == NULL) |
| 835 | goto discard; |
| 836 | |
| 837 | if (nsk != sk) { |
| 838 | if (dccp_child_process(sk, nsk, skb)) |
| 839 | goto reset; |
| 840 | return 0; |
| 841 | } |
| 842 | } |
| 843 | |
| 844 | if (dccp_rcv_state_process(sk, skb, dh, skb->len)) |
| 845 | goto reset; |
| 846 | return 0; |
| 847 | |
| 848 | reset: |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 849 | dccp_v4_ctl_send_reset(skb); |
| 850 | discard: |
| 851 | kfree_skb(skb); |
| 852 | return 0; |
| 853 | } |
| 854 | |
Arnaldo Carvalho de Melo | f21e68c | 2005-12-13 23:24:16 -0800 | [diff] [blame] | 855 | EXPORT_SYMBOL_GPL(dccp_v4_do_rcv); |
| 856 | |
| 857 | int dccp_invalid_packet(struct sk_buff *skb) |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 858 | { |
| 859 | const struct dccp_hdr *dh; |
| 860 | |
| 861 | if (skb->pkt_type != PACKET_HOST) |
| 862 | return 1; |
| 863 | |
| 864 | if (!pskb_may_pull(skb, sizeof(struct dccp_hdr))) { |
Arnaldo Carvalho de Melo | c59eab4 | 2005-08-18 21:12:02 -0300 | [diff] [blame] | 865 | LIMIT_NETDEBUG(KERN_WARNING "DCCP: pskb_may_pull failed\n"); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 866 | return 1; |
| 867 | } |
| 868 | |
| 869 | dh = dccp_hdr(skb); |
| 870 | |
| 871 | /* If the packet type is not understood, drop packet and return */ |
| 872 | if (dh->dccph_type >= DCCP_PKT_INVALID) { |
Arnaldo Carvalho de Melo | c59eab4 | 2005-08-18 21:12:02 -0300 | [diff] [blame] | 873 | LIMIT_NETDEBUG(KERN_WARNING "DCCP: invalid packet type\n"); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 874 | return 1; |
| 875 | } |
| 876 | |
| 877 | /* |
| 878 | * If P.Data Offset is too small for packet type, or too large for |
| 879 | * packet, drop packet and return |
| 880 | */ |
| 881 | if (dh->dccph_doff < dccp_hdr_len(skb) / sizeof(u32)) { |
Arnaldo Carvalho de Melo | c59eab4 | 2005-08-18 21:12:02 -0300 | [diff] [blame] | 882 | LIMIT_NETDEBUG(KERN_WARNING "DCCP: P.Data Offset(%u) " |
| 883 | "too small 1\n", |
| 884 | dh->dccph_doff); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 885 | return 1; |
| 886 | } |
| 887 | |
| 888 | if (!pskb_may_pull(skb, dh->dccph_doff * sizeof(u32))) { |
Arnaldo Carvalho de Melo | c59eab4 | 2005-08-18 21:12:02 -0300 | [diff] [blame] | 889 | LIMIT_NETDEBUG(KERN_WARNING "DCCP: P.Data Offset(%u) " |
| 890 | "too small 2\n", |
| 891 | dh->dccph_doff); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 892 | return 1; |
| 893 | } |
| 894 | |
| 895 | dh = dccp_hdr(skb); |
| 896 | |
| 897 | /* |
| 898 | * If P.type is not Data, Ack, or DataAck and P.X == 0 (the packet |
| 899 | * has short sequence numbers), drop packet and return |
| 900 | */ |
| 901 | if (dh->dccph_x == 0 && |
| 902 | dh->dccph_type != DCCP_PKT_DATA && |
| 903 | dh->dccph_type != DCCP_PKT_ACK && |
| 904 | dh->dccph_type != DCCP_PKT_DATAACK) { |
Arnaldo Carvalho de Melo | c59eab4 | 2005-08-18 21:12:02 -0300 | [diff] [blame] | 905 | LIMIT_NETDEBUG(KERN_WARNING "DCCP: P.type (%s) not Data, Ack " |
| 906 | "nor DataAck and P.X == 0\n", |
| 907 | dccp_packet_name(dh->dccph_type)); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 908 | return 1; |
| 909 | } |
| 910 | |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 911 | return 0; |
| 912 | } |
| 913 | |
Arnaldo Carvalho de Melo | f21e68c | 2005-12-13 23:24:16 -0800 | [diff] [blame] | 914 | EXPORT_SYMBOL_GPL(dccp_invalid_packet); |
| 915 | |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 916 | /* this is called when real data arrives */ |
| 917 | int dccp_v4_rcv(struct sk_buff *skb) |
| 918 | { |
| 919 | const struct dccp_hdr *dh; |
| 920 | struct sock *sk; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 921 | |
| 922 | /* Step 1: Check header basics: */ |
| 923 | |
| 924 | if (dccp_invalid_packet(skb)) |
| 925 | goto discard_it; |
| 926 | |
Arnaldo Carvalho de Melo | f21e68c | 2005-12-13 23:24:16 -0800 | [diff] [blame] | 927 | /* If the header checksum is incorrect, drop packet and return */ |
| 928 | if (dccp_v4_verify_checksum(skb, skb->nh.iph->saddr, |
| 929 | skb->nh.iph->daddr) < 0) { |
| 930 | LIMIT_NETDEBUG(KERN_WARNING "%s: incorrect header checksum\n", |
| 931 | __FUNCTION__); |
| 932 | goto discard_it; |
| 933 | } |
| 934 | |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 935 | dh = dccp_hdr(skb); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 936 | |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 937 | DCCP_SKB_CB(skb)->dccpd_seq = dccp_hdr_seq(skb); |
| 938 | DCCP_SKB_CB(skb)->dccpd_type = dh->dccph_type; |
| 939 | |
| 940 | dccp_pr_debug("%8.8s " |
| 941 | "src=%u.%u.%u.%u@%-5d " |
| 942 | "dst=%u.%u.%u.%u@%-5d seq=%llu", |
| 943 | dccp_packet_name(dh->dccph_type), |
| 944 | NIPQUAD(skb->nh.iph->saddr), ntohs(dh->dccph_sport), |
| 945 | NIPQUAD(skb->nh.iph->daddr), ntohs(dh->dccph_dport), |
David S. Miller | f6ccf55 | 2005-08-09 20:27:14 -0700 | [diff] [blame] | 946 | (unsigned long long) DCCP_SKB_CB(skb)->dccpd_seq); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 947 | |
| 948 | if (dccp_packet_without_ack(skb)) { |
| 949 | DCCP_SKB_CB(skb)->dccpd_ack_seq = DCCP_PKT_WITHOUT_ACK_SEQ; |
| 950 | dccp_pr_debug_cat("\n"); |
| 951 | } else { |
| 952 | DCCP_SKB_CB(skb)->dccpd_ack_seq = dccp_hdr_ack_seq(skb); |
David S. Miller | f6ccf55 | 2005-08-09 20:27:14 -0700 | [diff] [blame] | 953 | dccp_pr_debug_cat(", ack=%llu\n", |
| 954 | (unsigned long long) |
| 955 | DCCP_SKB_CB(skb)->dccpd_ack_seq); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 956 | } |
| 957 | |
| 958 | /* Step 2: |
| 959 | * Look up flow ID in table and get corresponding socket */ |
| 960 | sk = __inet_lookup(&dccp_hashinfo, |
| 961 | skb->nh.iph->saddr, dh->dccph_sport, |
| 962 | skb->nh.iph->daddr, ntohs(dh->dccph_dport), |
| 963 | inet_iif(skb)); |
| 964 | |
| 965 | /* |
| 966 | * Step 2: |
| 967 | * If no socket ... |
| 968 | * Generate Reset(No Connection) unless P.type == Reset |
| 969 | * Drop packet and return |
| 970 | */ |
| 971 | if (sk == NULL) { |
| 972 | dccp_pr_debug("failed to look up flow ID in table and " |
| 973 | "get corresponding socket\n"); |
| 974 | goto no_dccp_socket; |
| 975 | } |
| 976 | |
| 977 | /* |
| 978 | * Step 2: |
| 979 | * ... or S.state == TIMEWAIT, |
| 980 | * Generate Reset(No Connection) unless P.type == Reset |
| 981 | * Drop packet and return |
| 982 | */ |
| 983 | |
| 984 | if (sk->sk_state == DCCP_TIME_WAIT) { |
Arnaldo Carvalho de Melo | 64cf1e5 | 2005-08-09 20:45:21 -0700 | [diff] [blame] | 985 | dccp_pr_debug("sk->sk_state == DCCP_TIME_WAIT: " |
| 986 | "do_time_wait\n"); |
| 987 | goto do_time_wait; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 988 | } |
| 989 | |
Arnaldo Carvalho de Melo | 25995ff | 2005-12-27 02:42:22 -0200 | [diff] [blame] | 990 | if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 991 | goto discard_and_relse; |
Patrick McHardy | eb9c7eb | 2006-01-06 23:06:30 -0800 | [diff] [blame] | 992 | nf_reset(skb); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 993 | |
Arnaldo Carvalho de Melo | 25995ff | 2005-12-27 02:42:22 -0200 | [diff] [blame] | 994 | return sk_receive_skb(sk, skb); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 995 | |
| 996 | no_dccp_socket: |
| 997 | if (!xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) |
| 998 | goto discard_it; |
| 999 | /* |
| 1000 | * Step 2: |
| 1001 | * Generate Reset(No Connection) unless P.type == Reset |
| 1002 | * Drop packet and return |
| 1003 | */ |
| 1004 | if (dh->dccph_type != DCCP_PKT_RESET) { |
Arnaldo Carvalho de Melo | 7690af3 | 2005-08-13 20:34:54 -0300 | [diff] [blame] | 1005 | DCCP_SKB_CB(skb)->dccpd_reset_code = |
| 1006 | DCCP_RESET_CODE_NO_CONNECTION; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1007 | dccp_v4_ctl_send_reset(skb); |
| 1008 | } |
| 1009 | |
| 1010 | discard_it: |
| 1011 | /* Discard frame. */ |
| 1012 | kfree_skb(skb); |
| 1013 | return 0; |
| 1014 | |
| 1015 | discard_and_relse: |
| 1016 | sock_put(sk); |
| 1017 | goto discard_it; |
Arnaldo Carvalho de Melo | 64cf1e5 | 2005-08-09 20:45:21 -0700 | [diff] [blame] | 1018 | |
| 1019 | do_time_wait: |
| 1020 | inet_twsk_put((struct inet_timewait_sock *)sk); |
| 1021 | goto no_dccp_socket; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1022 | } |
| 1023 | |
Arnaldo Carvalho de Melo | 57cca05 | 2005-12-13 23:16:16 -0800 | [diff] [blame] | 1024 | struct inet_connection_sock_af_ops dccp_ipv4_af_ops = { |
| 1025 | .queue_xmit = ip_queue_xmit, |
| 1026 | .send_check = dccp_v4_send_check, |
| 1027 | .rebuild_header = inet_sk_rebuild_header, |
| 1028 | .conn_request = dccp_v4_conn_request, |
| 1029 | .syn_recv_sock = dccp_v4_request_recv_sock, |
| 1030 | .net_header_len = sizeof(struct iphdr), |
| 1031 | .setsockopt = ip_setsockopt, |
| 1032 | .getsockopt = ip_getsockopt, |
| 1033 | .addr2sockaddr = inet_csk_addr2sockaddr, |
| 1034 | .sockaddr_len = sizeof(struct sockaddr_in), |
| 1035 | }; |
| 1036 | |
Arnaldo Carvalho de Melo | f21e68c | 2005-12-13 23:24:16 -0800 | [diff] [blame] | 1037 | int dccp_v4_init_sock(struct sock *sk) |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1038 | { |
| 1039 | struct dccp_sock *dp = dccp_sk(sk); |
Arnaldo Carvalho de Melo | d83d846 | 2005-12-13 23:26:10 -0800 | [diff] [blame] | 1040 | struct inet_connection_sock *icsk = inet_csk(sk); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1041 | static int dccp_ctl_socket_init = 1; |
| 1042 | |
| 1043 | dccp_options_init(&dp->dccps_options); |
Arnaldo Carvalho de Melo | b0e5678 | 2005-09-09 02:38:35 -0300 | [diff] [blame] | 1044 | do_gettimeofday(&dp->dccps_epoch); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1045 | |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1046 | /* |
| 1047 | * FIXME: We're hardcoding the CCID, and doing this at this point makes |
| 1048 | * the listening (master) sock get CCID control blocks, which is not |
| 1049 | * necessary, but for now, to not mess with the test userspace apps, |
| 1050 | * lets leave it here, later the real solution is to do this in a |
| 1051 | * setsockopt(CCIDs-I-want/accept). -acme |
| 1052 | */ |
| 1053 | if (likely(!dccp_ctl_socket_init)) { |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 1054 | int rc; |
| 1055 | |
Arnaldo Carvalho de Melo | 9833d6d | 2006-03-20 17:34:53 -0800 | [diff] [blame] | 1056 | if (dp->dccps_options.dccpo_send_ack_vector) { |
| 1057 | dp->dccps_hc_rx_ackvec = dccp_ackvec_alloc(GFP_KERNEL); |
| 1058 | if (dp->dccps_hc_rx_ackvec == NULL) |
| 1059 | return -ENOMEM; |
| 1060 | } |
Arnaldo Carvalho de Melo | 91f0ebf | 2006-03-20 19:21:44 -0800 | [diff] [blame] | 1061 | dp->dccps_hc_rx_ccid = |
| 1062 | ccid_hc_rx_new(dp->dccps_options.dccpo_rx_ccid, |
| 1063 | sk, GFP_KERNEL); |
| 1064 | dp->dccps_hc_tx_ccid = |
| 1065 | ccid_hc_tx_new(dp->dccps_options.dccpo_tx_ccid, |
| 1066 | sk, GFP_KERNEL); |
| 1067 | if (unlikely(dp->dccps_hc_rx_ccid == NULL || |
| 1068 | dp->dccps_hc_tx_ccid == NULL)) { |
| 1069 | ccid_hc_rx_delete(dp->dccps_hc_rx_ccid, sk); |
| 1070 | ccid_hc_tx_delete(dp->dccps_hc_tx_ccid, sk); |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 1071 | if (dp->dccps_options.dccpo_send_ack_vector) { |
| 1072 | dccp_ackvec_free(dp->dccps_hc_rx_ackvec); |
| 1073 | dp->dccps_hc_rx_ackvec = NULL; |
| 1074 | } |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1075 | dp->dccps_hc_rx_ccid = dp->dccps_hc_tx_ccid = NULL; |
| 1076 | return -ENOMEM; |
| 1077 | } |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 1078 | |
| 1079 | rc = dccp_feat_init(sk); |
| 1080 | if (rc) |
| 1081 | return rc; |
| 1082 | } else { |
| 1083 | /* control socket doesn't need feat nego */ |
| 1084 | INIT_LIST_HEAD(&dp->dccps_options.dccpo_pending); |
| 1085 | INIT_LIST_HEAD(&dp->dccps_options.dccpo_conf); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1086 | dccp_ctl_socket_init = 0; |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 1087 | } |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1088 | |
| 1089 | dccp_init_xmit_timers(sk); |
Arnaldo Carvalho de Melo | d83d846 | 2005-12-13 23:26:10 -0800 | [diff] [blame] | 1090 | icsk->icsk_rto = DCCP_TIMEOUT_INIT; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1091 | sk->sk_state = DCCP_CLOSED; |
Arnaldo Carvalho de Melo | c530cfb | 2005-08-29 02:15:54 -0300 | [diff] [blame] | 1092 | sk->sk_write_space = dccp_write_space; |
Arnaldo Carvalho de Melo | d83d846 | 2005-12-13 23:26:10 -0800 | [diff] [blame] | 1093 | icsk->icsk_af_ops = &dccp_ipv4_af_ops; |
| 1094 | icsk->icsk_sync_mss = dccp_sync_mss; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1095 | dp->dccps_mss_cache = 536; |
| 1096 | dp->dccps_role = DCCP_ROLE_UNDEFINED; |
Arnaldo Carvalho de Melo | 67e6b62 | 2005-09-16 16:58:40 -0700 | [diff] [blame] | 1097 | dp->dccps_service = DCCP_SERVICE_INVALID_VALUE; |
Andrea Bittau | 2a91aa3 | 2006-03-20 17:41:47 -0800 | [diff] [blame] | 1098 | dp->dccps_l_ack_ratio = dp->dccps_r_ack_ratio = 1; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1099 | |
| 1100 | return 0; |
| 1101 | } |
| 1102 | |
Arnaldo Carvalho de Melo | f21e68c | 2005-12-13 23:24:16 -0800 | [diff] [blame] | 1103 | EXPORT_SYMBOL_GPL(dccp_v4_init_sock); |
| 1104 | |
| 1105 | int dccp_v4_destroy_sock(struct sock *sk) |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1106 | { |
| 1107 | struct dccp_sock *dp = dccp_sk(sk); |
| 1108 | |
| 1109 | /* |
Ian McDonald | 4c7e689 | 2005-12-21 19:02:39 -0800 | [diff] [blame] | 1110 | * DCCP doesn't use sk_write_queue, just sk_send_head |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1111 | * for retransmissions |
| 1112 | */ |
| 1113 | if (sk->sk_send_head != NULL) { |
| 1114 | kfree_skb(sk->sk_send_head); |
| 1115 | sk->sk_send_head = NULL; |
| 1116 | } |
| 1117 | |
| 1118 | /* Clean up a referenced DCCP bind bucket. */ |
| 1119 | if (inet_csk(sk)->icsk_bind_hash != NULL) |
| 1120 | inet_put_port(&dccp_hashinfo, sk); |
| 1121 | |
Jesper Juhl | a51482b | 2005-11-08 09:41:34 -0800 | [diff] [blame] | 1122 | kfree(dp->dccps_service_list); |
| 1123 | dp->dccps_service_list = NULL; |
Arnaldo Carvalho de Melo | 67e6b62 | 2005-09-16 16:58:40 -0700 | [diff] [blame] | 1124 | |
Arnaldo Carvalho de Melo | ae31c33 | 2005-09-18 00:17:51 -0700 | [diff] [blame] | 1125 | if (dp->dccps_options.dccpo_send_ack_vector) { |
| 1126 | dccp_ackvec_free(dp->dccps_hc_rx_ackvec); |
| 1127 | dp->dccps_hc_rx_ackvec = NULL; |
| 1128 | } |
Arnaldo Carvalho de Melo | 91f0ebf | 2006-03-20 19:21:44 -0800 | [diff] [blame] | 1129 | ccid_hc_rx_delete(dp->dccps_hc_rx_ccid, sk); |
| 1130 | ccid_hc_tx_delete(dp->dccps_hc_tx_ccid, sk); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1131 | dp->dccps_hc_rx_ccid = dp->dccps_hc_tx_ccid = NULL; |
| 1132 | |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 1133 | /* clean up feature negotiation state */ |
| 1134 | dccp_feat_clean(sk); |
| 1135 | |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1136 | return 0; |
| 1137 | } |
| 1138 | |
Arnaldo Carvalho de Melo | f21e68c | 2005-12-13 23:24:16 -0800 | [diff] [blame] | 1139 | EXPORT_SYMBOL_GPL(dccp_v4_destroy_sock); |
| 1140 | |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1141 | static void dccp_v4_reqsk_destructor(struct request_sock *req) |
| 1142 | { |
| 1143 | kfree(inet_rsk(req)->opt); |
| 1144 | } |
| 1145 | |
| 1146 | static struct request_sock_ops dccp_request_sock_ops = { |
| 1147 | .family = PF_INET, |
| 1148 | .obj_size = sizeof(struct dccp_request_sock), |
| 1149 | .rtx_syn_ack = dccp_v4_send_response, |
| 1150 | .send_ack = dccp_v4_reqsk_send_ack, |
| 1151 | .destructor = dccp_v4_reqsk_destructor, |
| 1152 | .send_reset = dccp_v4_ctl_send_reset, |
| 1153 | }; |
| 1154 | |
Arnaldo Carvalho de Melo | 6d6ee43 | 2005-12-13 23:25:19 -0800 | [diff] [blame] | 1155 | static struct timewait_sock_ops dccp_timewait_sock_ops = { |
| 1156 | .twsk_obj_size = sizeof(struct inet_timewait_sock), |
| 1157 | }; |
| 1158 | |
Arnaldo Carvalho de Melo | 34ca686 | 2005-12-13 23:23:32 -0800 | [diff] [blame] | 1159 | struct proto dccp_prot = { |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1160 | .name = "DCCP", |
| 1161 | .owner = THIS_MODULE, |
| 1162 | .close = dccp_close, |
| 1163 | .connect = dccp_v4_connect, |
| 1164 | .disconnect = dccp_disconnect, |
| 1165 | .ioctl = dccp_ioctl, |
| 1166 | .init = dccp_v4_init_sock, |
| 1167 | .setsockopt = dccp_setsockopt, |
| 1168 | .getsockopt = dccp_getsockopt, |
| 1169 | .sendmsg = dccp_sendmsg, |
| 1170 | .recvmsg = dccp_recvmsg, |
| 1171 | .backlog_rcv = dccp_v4_do_rcv, |
| 1172 | .hash = dccp_v4_hash, |
Arnaldo Carvalho de Melo | f21e68c | 2005-12-13 23:24:16 -0800 | [diff] [blame] | 1173 | .unhash = dccp_unhash, |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1174 | .accept = inet_csk_accept, |
| 1175 | .get_port = dccp_v4_get_port, |
| 1176 | .shutdown = dccp_shutdown, |
| 1177 | .destroy = dccp_v4_destroy_sock, |
| 1178 | .orphan_count = &dccp_orphan_count, |
| 1179 | .max_header = MAX_DCCP_HEADER, |
| 1180 | .obj_size = sizeof(struct dccp_sock), |
| 1181 | .rsk_prot = &dccp_request_sock_ops, |
Arnaldo Carvalho de Melo | 6d6ee43 | 2005-12-13 23:25:19 -0800 | [diff] [blame] | 1182 | .twsk_prot = &dccp_timewait_sock_ops, |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1183 | }; |
Arnaldo Carvalho de Melo | 6d6ee43 | 2005-12-13 23:25:19 -0800 | [diff] [blame] | 1184 | |
| 1185 | EXPORT_SYMBOL_GPL(dccp_prot); |