ipv4.c (46557bef3f3834ac33031c7be27d39d90d507442) ipv4.c (e6b4d11367519bc71729c09d05a126b133c755be)
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

--- 48 unchanged lines hidden (view full) ---

57
58 nexthop = daddr = usin->sin_addr.s_addr;
59 if (inet->opt != NULL && inet->opt->srr) {
60 if (daddr == 0)
61 return -EINVAL;
62 nexthop = inet->opt->faddr;
63 }
64
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

--- 48 unchanged lines hidden (view full) ---

57
58 nexthop = daddr = usin->sin_addr.s_addr;
59 if (inet->opt != NULL && inet->opt->srr) {
60 if (daddr == 0)
61 return -EINVAL;
62 nexthop = inet->opt->faddr;
63 }
64
65 tmp = ip_route_connect(&rt, nexthop, inet->saddr,
65 tmp = ip_route_connect(&rt, nexthop, inet->inet_saddr,
66 RT_CONN_FLAGS(sk), sk->sk_bound_dev_if,
67 IPPROTO_DCCP,
66 RT_CONN_FLAGS(sk), sk->sk_bound_dev_if,
67 IPPROTO_DCCP,
68 inet->sport, usin->sin_port, sk, 1);
68 inet->inet_sport, usin->sin_port, sk, 1);
69 if (tmp < 0)
70 return tmp;
71
72 if (rt->rt_flags & (RTCF_MULTICAST | RTCF_BROADCAST)) {
73 ip_rt_put(rt);
74 return -ENETUNREACH;
75 }
76
77 if (inet->opt == NULL || !inet->opt->srr)
78 daddr = rt->rt_dst;
79
69 if (tmp < 0)
70 return tmp;
71
72 if (rt->rt_flags & (RTCF_MULTICAST | RTCF_BROADCAST)) {
73 ip_rt_put(rt);
74 return -ENETUNREACH;
75 }
76
77 if (inet->opt == NULL || !inet->opt->srr)
78 daddr = rt->rt_dst;
79
80 if (inet->saddr == 0)
81 inet->saddr = rt->rt_src;
82 inet->rcv_saddr = inet->saddr;
80 if (inet->inet_saddr == 0)
81 inet->inet_saddr = rt->rt_src;
82 inet->inet_rcv_saddr = inet->inet_saddr;
83
83
84 inet->dport = usin->sin_port;
85 inet->daddr = daddr;
84 inet->inet_dport = usin->sin_port;
85 inet->inet_daddr = daddr;
86
87 inet_csk(sk)->icsk_ext_hdr_len = 0;
88 if (inet->opt != NULL)
89 inet_csk(sk)->icsk_ext_hdr_len = inet->opt->optlen;
90 /*
91 * Socket identity is still unknown (sport may be zero).
92 * However we set state to DCCP_REQUESTING and not releasing socket
93 * lock select source port, enter ourselves into the hash tables and
94 * complete initialization after this.
95 */
96 dccp_set_state(sk, DCCP_REQUESTING);
97 err = inet_hash_connect(&dccp_death_row, sk);
98 if (err != 0)
99 goto failure;
100
86
87 inet_csk(sk)->icsk_ext_hdr_len = 0;
88 if (inet->opt != NULL)
89 inet_csk(sk)->icsk_ext_hdr_len = inet->opt->optlen;
90 /*
91 * Socket identity is still unknown (sport may be zero).
92 * However we set state to DCCP_REQUESTING and not releasing socket
93 * lock select source port, enter ourselves into the hash tables and
94 * complete initialization after this.
95 */
96 dccp_set_state(sk, DCCP_REQUESTING);
97 err = inet_hash_connect(&dccp_death_row, sk);
98 if (err != 0)
99 goto failure;
100
101 err = ip_route_newports(&rt, IPPROTO_DCCP, inet->sport, inet->dport,
102 sk);
101 err = ip_route_newports(&rt, IPPROTO_DCCP, inet->inet_sport,
102 inet->inet_dport, sk);
103 if (err != 0)
104 goto failure;
105
106 /* OK, now commit destination to socket. */
107 sk_setup_caps(sk, &rt->u.dst);
108
103 if (err != 0)
104 goto failure;
105
106 /* OK, now commit destination to socket. */
107 sk_setup_caps(sk, &rt->u.dst);
108
109 dp->dccps_iss = secure_dccp_sequence_number(inet->saddr, inet->daddr,
110 inet->sport, inet->dport);
111 inet->id = dp->dccps_iss ^ jiffies;
109 dp->dccps_iss = secure_dccp_sequence_number(inet->inet_saddr,
110 inet->inet_daddr,
111 inet->inet_sport,
112 inet->inet_dport);
113 inet->inet_id = dp->dccps_iss ^ jiffies;
112
113 err = dccp_connect(sk);
114 rt = NULL;
115 if (err != 0)
116 goto failure;
117out:
118 return err;
119failure:
120 /*
121 * This unhashes the socket and releases the local port, if necessary.
122 */
123 dccp_set_state(sk, DCCP_CLOSED);
124 ip_rt_put(rt);
125 sk->sk_route_caps = 0;
114
115 err = dccp_connect(sk);
116 rt = NULL;
117 if (err != 0)
118 goto failure;
119out:
120 return err;
121failure:
122 /*
123 * This unhashes the socket and releases the local port, if necessary.
124 */
125 dccp_set_state(sk, DCCP_CLOSED);
126 ip_rt_put(rt);
127 sk->sk_route_caps = 0;
126 inet->dport = 0;
128 inet->inet_dport = 0;
127 goto out;
128}
129
130EXPORT_SYMBOL_GPL(dccp_v4_connect);
131
132/*
133 * This routine does path mtu discovery as defined in RFC1191.
134 */

--- 212 unchanged lines hidden (view full) ---

347}
348
349void dccp_v4_send_check(struct sock *sk, int unused, struct sk_buff *skb)
350{
351 const struct inet_sock *inet = inet_sk(sk);
352 struct dccp_hdr *dh = dccp_hdr(skb);
353
354 dccp_csum_outgoing(skb);
129 goto out;
130}
131
132EXPORT_SYMBOL_GPL(dccp_v4_connect);
133
134/*
135 * This routine does path mtu discovery as defined in RFC1191.
136 */

--- 212 unchanged lines hidden (view full) ---

349}
350
351void dccp_v4_send_check(struct sock *sk, int unused, struct sk_buff *skb)
352{
353 const struct inet_sock *inet = inet_sk(sk);
354 struct dccp_hdr *dh = dccp_hdr(skb);
355
356 dccp_csum_outgoing(skb);
355 dh->dccph_checksum = dccp_v4_csum_finish(skb, inet->saddr, inet->daddr);
357 dh->dccph_checksum = dccp_v4_csum_finish(skb,
358 inet->inet_saddr,
359 inet->inet_daddr);
356}
357
358EXPORT_SYMBOL_GPL(dccp_v4_send_check);
359
360static inline u64 dccp_v4_init_sequence(const struct sk_buff *skb)
361{
362 return secure_dccp_sequence_number(ip_hdr(skb)->daddr,
363 ip_hdr(skb)->saddr,

--- 24 unchanged lines hidden (view full) ---

388 newsk = dccp_create_openreq_child(sk, req, skb);
389 if (newsk == NULL)
390 goto exit;
391
392 sk_setup_caps(newsk, dst);
393
394 newinet = inet_sk(newsk);
395 ireq = inet_rsk(req);
360}
361
362EXPORT_SYMBOL_GPL(dccp_v4_send_check);
363
364static inline u64 dccp_v4_init_sequence(const struct sk_buff *skb)
365{
366 return secure_dccp_sequence_number(ip_hdr(skb)->daddr,
367 ip_hdr(skb)->saddr,

--- 24 unchanged lines hidden (view full) ---

392 newsk = dccp_create_openreq_child(sk, req, skb);
393 if (newsk == NULL)
394 goto exit;
395
396 sk_setup_caps(newsk, dst);
397
398 newinet = inet_sk(newsk);
399 ireq = inet_rsk(req);
396 newinet->daddr = ireq->rmt_addr;
397 newinet->rcv_saddr = ireq->loc_addr;
398 newinet->saddr = ireq->loc_addr;
400 newinet->inet_daddr = ireq->rmt_addr;
401 newinet->inet_rcv_saddr = ireq->loc_addr;
402 newinet->inet_saddr = ireq->loc_addr;
399 newinet->opt = ireq->opt;
400 ireq->opt = NULL;
401 newinet->mc_index = inet_iif(skb);
402 newinet->mc_ttl = ip_hdr(skb)->ttl;
403 newinet->opt = ireq->opt;
404 ireq->opt = NULL;
405 newinet->mc_index = inet_iif(skb);
406 newinet->mc_ttl = ip_hdr(skb)->ttl;
403 newinet->id = jiffies;
407 newinet->inet_id = jiffies;
404
405 dccp_sync_mss(newsk, dst_mtu(dst));
406
407 __inet_hash_nolisten(newsk);
408 __inet_inherit_port(sk, newsk);
409
410 return newsk;
411

--- 56 unchanged lines hidden (view full) ---

468 if (ip_route_output_flow(net, &rt, &fl, sk, 0)) {
469 IP_INC_STATS_BH(net, IPSTATS_MIB_OUTNOROUTES);
470 return NULL;
471 }
472
473 return &rt->u.dst;
474}
475
408
409 dccp_sync_mss(newsk, dst_mtu(dst));
410
411 __inet_hash_nolisten(newsk);
412 __inet_inherit_port(sk, newsk);
413
414 return newsk;
415

--- 56 unchanged lines hidden (view full) ---

472 if (ip_route_output_flow(net, &rt, &fl, sk, 0)) {
473 IP_INC_STATS_BH(net, IPSTATS_MIB_OUTNOROUTES);
474 return NULL;
475 }
476
477 return &rt->u.dst;
478}
479
476static int dccp_v4_send_response(struct sock *sk, struct request_sock *req)
480static int dccp_v4_send_response(struct sock *sk, struct request_sock *req,
481 struct request_values *rv_unused)
477{
478 int err = -1;
479 struct sk_buff *skb;
480 struct dst_entry *dst;
481
482 dst = inet_csk_route_req(sk, req);
483 if (dst == NULL)
484 goto out;

--- 132 unchanged lines hidden (view full) ---

617 *
618 * In fact we defer setting S.GSR, S.SWL, S.SWH to
619 * dccp_create_openreq_child.
620 */
621 dreq->dreq_isr = dcb->dccpd_seq;
622 dreq->dreq_iss = dccp_v4_init_sequence(skb);
623 dreq->dreq_service = service;
624
482{
483 int err = -1;
484 struct sk_buff *skb;
485 struct dst_entry *dst;
486
487 dst = inet_csk_route_req(sk, req);
488 if (dst == NULL)
489 goto out;

--- 132 unchanged lines hidden (view full) ---

622 *
623 * In fact we defer setting S.GSR, S.SWL, S.SWH to
624 * dccp_create_openreq_child.
625 */
626 dreq->dreq_isr = dcb->dccpd_seq;
627 dreq->dreq_iss = dccp_v4_init_sequence(skb);
628 dreq->dreq_service = service;
629
625 if (dccp_v4_send_response(sk, req))
630 if (dccp_v4_send_response(sk, req, NULL))
626 goto drop_and_free;
627
628 inet_csk_reqsk_queue_hash_add(sk, req, DCCP_TIMEOUT_INIT);
629 return 0;
630
631drop_and_free:
632 reqsk_free(req);
633drop:

--- 348 unchanged lines hidden (view full) ---

982#endif
983};
984
985static struct inet_protosw dccp_v4_protosw = {
986 .type = SOCK_DCCP,
987 .protocol = IPPROTO_DCCP,
988 .prot = &dccp_v4_prot,
989 .ops = &inet_dccp_ops,
631 goto drop_and_free;
632
633 inet_csk_reqsk_queue_hash_add(sk, req, DCCP_TIMEOUT_INIT);
634 return 0;
635
636drop_and_free:
637 reqsk_free(req);
638drop:

--- 348 unchanged lines hidden (view full) ---

987#endif
988};
989
990static struct inet_protosw dccp_v4_protosw = {
991 .type = SOCK_DCCP,
992 .protocol = IPPROTO_DCCP,
993 .prot = &dccp_v4_prot,
994 .ops = &inet_dccp_ops,
990 .capability = -1,
991 .no_check = 0,
992 .flags = INET_PROTOSW_ICSK,
993};
994
995static int dccp_v4_init_net(struct net *net)
996{
997 int err;
998

--- 62 unchanged lines hidden ---
995 .no_check = 0,
996 .flags = INET_PROTOSW_ICSK,
997};
998
999static int dccp_v4_init_net(struct net *net)
1000{
1001 int err;
1002

--- 62 unchanged lines hidden ---