Commit 27258ee54f8cd4a43d09319aa5448145afc2cb8d
Committed by
David S. Miller
1 parent
0d48d93947
Exists in
master
and in
7 other branches
[DCCP]: Introduce dccp_write_xmit from code in dccp_sendmsg
This way it gets closer to the TCP flow, where congestion window checks are done, it seems we can map ccid_hc_tx_send_packet in dccp_write_xmit to tcp_snd_wnd_test in tcp_write_xmit, a CCID2 decision should just fit in here as well... Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Showing 5 changed files with 57 additions and 72 deletions Inline Diff
net/dccp/ccid.h
1 | #ifndef _CCID_H | 1 | #ifndef _CCID_H |
2 | #define _CCID_H | 2 | #define _CCID_H |
3 | /* | 3 | /* |
4 | * net/dccp/ccid.h | 4 | * net/dccp/ccid.h |
5 | * | 5 | * |
6 | * An implementation of the DCCP protocol | 6 | * An implementation of the DCCP protocol |
7 | * Arnaldo Carvalho de Melo <acme@conectiva.com.br> | 7 | * Arnaldo Carvalho de Melo <acme@conectiva.com.br> |
8 | * | 8 | * |
9 | * CCID infrastructure | 9 | * CCID infrastructure |
10 | * | 10 | * |
11 | * This program is free software; you can redistribute it and/or modify it | 11 | * This program is free software; you can redistribute it and/or modify it |
12 | * under the terms of the GNU General Public License version 2 as | 12 | * under the terms of the GNU General Public License version 2 as |
13 | * published by the Free Software Foundation. | 13 | * published by the Free Software Foundation. |
14 | */ | 14 | */ |
15 | 15 | ||
16 | #include <net/sock.h> | 16 | #include <net/sock.h> |
17 | #include <linux/dccp.h> | 17 | #include <linux/dccp.h> |
18 | #include <linux/list.h> | 18 | #include <linux/list.h> |
19 | #include <linux/module.h> | 19 | #include <linux/module.h> |
20 | 20 | ||
21 | #define CCID_MAX 255 | 21 | #define CCID_MAX 255 |
22 | 22 | ||
23 | struct ccid { | 23 | struct ccid { |
24 | unsigned char ccid_id; | 24 | unsigned char ccid_id; |
25 | const char *ccid_name; | 25 | const char *ccid_name; |
26 | struct module *ccid_owner; | 26 | struct module *ccid_owner; |
27 | int (*ccid_init)(struct sock *sk); | 27 | int (*ccid_init)(struct sock *sk); |
28 | void (*ccid_exit)(struct sock *sk); | 28 | void (*ccid_exit)(struct sock *sk); |
29 | int (*ccid_hc_rx_init)(struct sock *sk); | 29 | int (*ccid_hc_rx_init)(struct sock *sk); |
30 | int (*ccid_hc_tx_init)(struct sock *sk); | 30 | int (*ccid_hc_tx_init)(struct sock *sk); |
31 | void (*ccid_hc_rx_exit)(struct sock *sk); | 31 | void (*ccid_hc_rx_exit)(struct sock *sk); |
32 | void (*ccid_hc_tx_exit)(struct sock *sk); | 32 | void (*ccid_hc_tx_exit)(struct sock *sk); |
33 | void (*ccid_hc_rx_packet_recv)(struct sock *sk, struct sk_buff *skb); | 33 | void (*ccid_hc_rx_packet_recv)(struct sock *sk, struct sk_buff *skb); |
34 | int (*ccid_hc_rx_parse_options)(struct sock *sk, | 34 | int (*ccid_hc_rx_parse_options)(struct sock *sk, |
35 | unsigned char option, | 35 | unsigned char option, |
36 | unsigned char len, u16 idx, | 36 | unsigned char len, u16 idx, |
37 | unsigned char* value); | 37 | unsigned char* value); |
38 | void (*ccid_hc_rx_insert_options)(struct sock *sk, struct sk_buff *skb); | 38 | void (*ccid_hc_rx_insert_options)(struct sock *sk, struct sk_buff *skb); |
39 | void (*ccid_hc_tx_insert_options)(struct sock *sk, struct sk_buff *skb); | 39 | void (*ccid_hc_tx_insert_options)(struct sock *sk, struct sk_buff *skb); |
40 | void (*ccid_hc_tx_packet_recv)(struct sock *sk, struct sk_buff *skb); | 40 | void (*ccid_hc_tx_packet_recv)(struct sock *sk, struct sk_buff *skb); |
41 | int (*ccid_hc_tx_parse_options)(struct sock *sk, | 41 | int (*ccid_hc_tx_parse_options)(struct sock *sk, |
42 | unsigned char option, | 42 | unsigned char option, |
43 | unsigned char len, u16 idx, | 43 | unsigned char len, u16 idx, |
44 | unsigned char* value); | 44 | unsigned char* value); |
45 | int (*ccid_hc_tx_send_packet)(struct sock *sk, | 45 | int (*ccid_hc_tx_send_packet)(struct sock *sk, |
46 | struct sk_buff *skb, int len, | 46 | struct sk_buff *skb, int len); |
47 | long *delay); | ||
48 | void (*ccid_hc_tx_packet_sent)(struct sock *sk, int more, int len); | 47 | void (*ccid_hc_tx_packet_sent)(struct sock *sk, int more, int len); |
49 | }; | 48 | }; |
50 | 49 | ||
51 | extern int ccid_register(struct ccid *ccid); | 50 | extern int ccid_register(struct ccid *ccid); |
52 | extern int ccid_unregister(struct ccid *ccid); | 51 | extern int ccid_unregister(struct ccid *ccid); |
53 | 52 | ||
54 | extern struct ccid *ccid_init(unsigned char id, struct sock *sk); | 53 | extern struct ccid *ccid_init(unsigned char id, struct sock *sk); |
55 | extern void ccid_exit(struct ccid *ccid, struct sock *sk); | 54 | extern void ccid_exit(struct ccid *ccid, struct sock *sk); |
56 | 55 | ||
57 | static inline void __ccid_get(struct ccid *ccid) | 56 | static inline void __ccid_get(struct ccid *ccid) |
58 | { | 57 | { |
59 | __module_get(ccid->ccid_owner); | 58 | __module_get(ccid->ccid_owner); |
60 | } | 59 | } |
61 | 60 | ||
62 | static inline int ccid_hc_tx_send_packet(struct ccid *ccid, struct sock *sk, | 61 | static inline int ccid_hc_tx_send_packet(struct ccid *ccid, struct sock *sk, |
63 | struct sk_buff *skb, int len, | 62 | struct sk_buff *skb, int len) |
64 | long *delay) | ||
65 | { | 63 | { |
66 | int rc = 0; | 64 | int rc = 0; |
67 | if (ccid->ccid_hc_tx_send_packet != NULL) | 65 | if (ccid->ccid_hc_tx_send_packet != NULL) |
68 | rc = ccid->ccid_hc_tx_send_packet(sk, skb, len, delay); | 66 | rc = ccid->ccid_hc_tx_send_packet(sk, skb, len); |
69 | return rc; | 67 | return rc; |
70 | } | 68 | } |
71 | 69 | ||
72 | static inline void ccid_hc_tx_packet_sent(struct ccid *ccid, struct sock *sk, | 70 | static inline void ccid_hc_tx_packet_sent(struct ccid *ccid, struct sock *sk, |
73 | int more, int len) | 71 | int more, int len) |
74 | { | 72 | { |
75 | if (ccid->ccid_hc_tx_packet_sent != NULL) | 73 | if (ccid->ccid_hc_tx_packet_sent != NULL) |
76 | ccid->ccid_hc_tx_packet_sent(sk, more, len); | 74 | ccid->ccid_hc_tx_packet_sent(sk, more, len); |
77 | } | 75 | } |
78 | 76 | ||
79 | static inline int ccid_hc_rx_init(struct ccid *ccid, struct sock *sk) | 77 | static inline int ccid_hc_rx_init(struct ccid *ccid, struct sock *sk) |
80 | { | 78 | { |
81 | int rc = 0; | 79 | int rc = 0; |
82 | if (ccid->ccid_hc_rx_init != NULL) | 80 | if (ccid->ccid_hc_rx_init != NULL) |
83 | rc = ccid->ccid_hc_rx_init(sk); | 81 | rc = ccid->ccid_hc_rx_init(sk); |
84 | return rc; | 82 | return rc; |
85 | } | 83 | } |
86 | 84 | ||
87 | static inline int ccid_hc_tx_init(struct ccid *ccid, struct sock *sk) | 85 | static inline int ccid_hc_tx_init(struct ccid *ccid, struct sock *sk) |
88 | { | 86 | { |
89 | int rc = 0; | 87 | int rc = 0; |
90 | if (ccid->ccid_hc_tx_init != NULL) | 88 | if (ccid->ccid_hc_tx_init != NULL) |
91 | rc = ccid->ccid_hc_tx_init(sk); | 89 | rc = ccid->ccid_hc_tx_init(sk); |
92 | return rc; | 90 | return rc; |
93 | } | 91 | } |
94 | 92 | ||
95 | static inline void ccid_hc_rx_exit(struct ccid *ccid, struct sock *sk) | 93 | static inline void ccid_hc_rx_exit(struct ccid *ccid, struct sock *sk) |
96 | { | 94 | { |
97 | if (ccid->ccid_hc_rx_exit != NULL) | 95 | if (ccid->ccid_hc_rx_exit != NULL) |
98 | ccid->ccid_hc_rx_exit(sk); | 96 | ccid->ccid_hc_rx_exit(sk); |
99 | } | 97 | } |
100 | 98 | ||
101 | static inline void ccid_hc_tx_exit(struct ccid *ccid, struct sock *sk) | 99 | static inline void ccid_hc_tx_exit(struct ccid *ccid, struct sock *sk) |
102 | { | 100 | { |
103 | if (ccid->ccid_hc_tx_exit != NULL) | 101 | if (ccid->ccid_hc_tx_exit != NULL) |
104 | ccid->ccid_hc_tx_exit(sk); | 102 | ccid->ccid_hc_tx_exit(sk); |
105 | } | 103 | } |
106 | 104 | ||
107 | static inline void ccid_hc_rx_packet_recv(struct ccid *ccid, struct sock *sk, | 105 | static inline void ccid_hc_rx_packet_recv(struct ccid *ccid, struct sock *sk, |
108 | struct sk_buff *skb) | 106 | struct sk_buff *skb) |
109 | { | 107 | { |
110 | if (ccid->ccid_hc_rx_packet_recv != NULL) | 108 | if (ccid->ccid_hc_rx_packet_recv != NULL) |
111 | ccid->ccid_hc_rx_packet_recv(sk, skb); | 109 | ccid->ccid_hc_rx_packet_recv(sk, skb); |
112 | } | 110 | } |
113 | 111 | ||
114 | static inline void ccid_hc_tx_packet_recv(struct ccid *ccid, struct sock *sk, | 112 | static inline void ccid_hc_tx_packet_recv(struct ccid *ccid, struct sock *sk, |
115 | struct sk_buff *skb) | 113 | struct sk_buff *skb) |
116 | { | 114 | { |
117 | if (ccid->ccid_hc_tx_packet_recv != NULL) | 115 | if (ccid->ccid_hc_tx_packet_recv != NULL) |
118 | ccid->ccid_hc_tx_packet_recv(sk, skb); | 116 | ccid->ccid_hc_tx_packet_recv(sk, skb); |
119 | } | 117 | } |
120 | 118 | ||
121 | static inline int ccid_hc_tx_parse_options(struct ccid *ccid, struct sock *sk, | 119 | static inline int ccid_hc_tx_parse_options(struct ccid *ccid, struct sock *sk, |
122 | unsigned char option, | 120 | unsigned char option, |
123 | unsigned char len, u16 idx, | 121 | unsigned char len, u16 idx, |
124 | unsigned char* value) | 122 | unsigned char* value) |
125 | { | 123 | { |
126 | int rc = 0; | 124 | int rc = 0; |
127 | if (ccid->ccid_hc_tx_parse_options != NULL) | 125 | if (ccid->ccid_hc_tx_parse_options != NULL) |
128 | rc = ccid->ccid_hc_tx_parse_options(sk, option, len, idx, value); | 126 | rc = ccid->ccid_hc_tx_parse_options(sk, option, len, idx, value); |
129 | return rc; | 127 | return rc; |
130 | } | 128 | } |
131 | 129 | ||
132 | static inline int ccid_hc_rx_parse_options(struct ccid *ccid, struct sock *sk, | 130 | static inline int ccid_hc_rx_parse_options(struct ccid *ccid, struct sock *sk, |
133 | unsigned char option, | 131 | unsigned char option, |
134 | unsigned char len, u16 idx, | 132 | unsigned char len, u16 idx, |
135 | unsigned char* value) | 133 | unsigned char* value) |
136 | { | 134 | { |
137 | int rc = 0; | 135 | int rc = 0; |
138 | if (ccid->ccid_hc_rx_parse_options != NULL) | 136 | if (ccid->ccid_hc_rx_parse_options != NULL) |
139 | rc = ccid->ccid_hc_rx_parse_options(sk, option, len, idx, value); | 137 | rc = ccid->ccid_hc_rx_parse_options(sk, option, len, idx, value); |
140 | return rc; | 138 | return rc; |
141 | } | 139 | } |
142 | 140 | ||
143 | static inline void ccid_hc_tx_insert_options(struct ccid *ccid, struct sock *sk, | 141 | static inline void ccid_hc_tx_insert_options(struct ccid *ccid, struct sock *sk, |
144 | struct sk_buff *skb) | 142 | struct sk_buff *skb) |
145 | { | 143 | { |
146 | if (ccid->ccid_hc_tx_insert_options != NULL) | 144 | if (ccid->ccid_hc_tx_insert_options != NULL) |
147 | ccid->ccid_hc_tx_insert_options(sk, skb); | 145 | ccid->ccid_hc_tx_insert_options(sk, skb); |
148 | } | 146 | } |
149 | 147 | ||
150 | static inline void ccid_hc_rx_insert_options(struct ccid *ccid, struct sock *sk, | 148 | static inline void ccid_hc_rx_insert_options(struct ccid *ccid, struct sock *sk, |
151 | struct sk_buff *skb) | 149 | struct sk_buff *skb) |
152 | { | 150 | { |
153 | if (ccid->ccid_hc_rx_insert_options != NULL) | 151 | if (ccid->ccid_hc_rx_insert_options != NULL) |
154 | ccid->ccid_hc_rx_insert_options(sk, skb); | 152 | ccid->ccid_hc_rx_insert_options(sk, skb); |
155 | } | 153 | } |
156 | #endif /* _CCID_H */ | 154 | #endif /* _CCID_H */ |
157 | 155 |
net/dccp/ccids/ccid3.c
1 | /* | 1 | /* |
2 | * net/dccp/ccids/ccid3.c | 2 | * net/dccp/ccids/ccid3.c |
3 | * | 3 | * |
4 | * Copyright (c) 2005 The University of Waikato, Hamilton, New Zealand. | 4 | * Copyright (c) 2005 The University of Waikato, Hamilton, New Zealand. |
5 | * | 5 | * |
6 | * An implementation of the DCCP protocol | 6 | * An implementation of the DCCP protocol |
7 | * | 7 | * |
8 | * This code has been developed by the University of Waikato WAND | 8 | * This code has been developed by the University of Waikato WAND |
9 | * research group. For further information please see http://www.wand.net.nz/ | 9 | * research group. For further information please see http://www.wand.net.nz/ |
10 | * or e-mail Ian McDonald - iam4@cs.waikato.ac.nz | 10 | * or e-mail Ian McDonald - iam4@cs.waikato.ac.nz |
11 | * | 11 | * |
12 | * This code also uses code from Lulea University, rereleased as GPL by its | 12 | * This code also uses code from Lulea University, rereleased as GPL by its |
13 | * authors: | 13 | * authors: |
14 | * Copyright (c) 2003 Nils-Erik Mattsson, Joacim Haggmark, Magnus Erixzon | 14 | * Copyright (c) 2003 Nils-Erik Mattsson, Joacim Haggmark, Magnus Erixzon |
15 | * | 15 | * |
16 | * Changes to meet Linux coding standards, to make it meet latest ccid3 draft | 16 | * Changes to meet Linux coding standards, to make it meet latest ccid3 draft |
17 | * and to make it work as a loadable module in the DCCP stack written by | 17 | * and to make it work as a loadable module in the DCCP stack written by |
18 | * Arnaldo Carvalho de Melo <acme@conectiva.com.br>. | 18 | * Arnaldo Carvalho de Melo <acme@conectiva.com.br>. |
19 | * | 19 | * |
20 | * Copyright (c) 2005 Arnaldo Carvalho de Melo <acme@conectiva.com.br> | 20 | * Copyright (c) 2005 Arnaldo Carvalho de Melo <acme@conectiva.com.br> |
21 | * | 21 | * |
22 | * This program is free software; you can redistribute it and/or modify | 22 | * This program is free software; you can redistribute it and/or modify |
23 | * it under the terms of the GNU General Public License as published by | 23 | * it under the terms of the GNU General Public License as published by |
24 | * the Free Software Foundation; either version 2 of the License, or | 24 | * the Free Software Foundation; either version 2 of the License, or |
25 | * (at your option) any later version. | 25 | * (at your option) any later version. |
26 | * | 26 | * |
27 | * This program is distributed in the hope that it will be useful, | 27 | * This program is distributed in the hope that it will be useful, |
28 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 28 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
29 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 29 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
30 | * GNU General Public License for more details. | 30 | * GNU General Public License for more details. |
31 | * | 31 | * |
32 | * You should have received a copy of the GNU General Public License | 32 | * You should have received a copy of the GNU General Public License |
33 | * along with this program; if not, write to the Free Software | 33 | * along with this program; if not, write to the Free Software |
34 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 34 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
35 | */ | 35 | */ |
36 | 36 | ||
37 | #include "../ccid.h" | 37 | #include "../ccid.h" |
38 | #include "../dccp.h" | 38 | #include "../dccp.h" |
39 | #include "ccid3.h" | 39 | #include "ccid3.h" |
40 | 40 | ||
41 | #ifdef CCID3_DEBUG | 41 | #ifdef CCID3_DEBUG |
42 | extern int ccid3_debug; | 42 | extern int ccid3_debug; |
43 | 43 | ||
44 | #define ccid3_pr_debug(format, a...) \ | 44 | #define ccid3_pr_debug(format, a...) \ |
45 | do { if (ccid3_debug) \ | 45 | do { if (ccid3_debug) \ |
46 | printk(KERN_DEBUG "%s: " format, __FUNCTION__, ##a); \ | 46 | printk(KERN_DEBUG "%s: " format, __FUNCTION__, ##a); \ |
47 | } while (0) | 47 | } while (0) |
48 | #else | 48 | #else |
49 | #define ccid3_pr_debug(format, a...) | 49 | #define ccid3_pr_debug(format, a...) |
50 | #endif | 50 | #endif |
51 | 51 | ||
52 | #define TFRC_MIN_PACKET_SIZE 16 | 52 | #define TFRC_MIN_PACKET_SIZE 16 |
53 | #define TFRC_STD_PACKET_SIZE 256 | 53 | #define TFRC_STD_PACKET_SIZE 256 |
54 | #define TFRC_MAX_PACKET_SIZE 65535 | 54 | #define TFRC_MAX_PACKET_SIZE 65535 |
55 | 55 | ||
56 | #define USEC_IN_SEC 1000000 | 56 | #define USEC_IN_SEC 1000000 |
57 | 57 | ||
58 | #define TFRC_INITIAL_TIMEOUT (2 * USEC_IN_SEC) | 58 | #define TFRC_INITIAL_TIMEOUT (2 * USEC_IN_SEC) |
59 | /* two seconds as per CCID3 spec 11 */ | 59 | /* two seconds as per CCID3 spec 11 */ |
60 | 60 | ||
61 | #define TFRC_OPSYS_HALF_TIME_GRAN (USEC_IN_SEC / (2 * HZ)) | 61 | #define TFRC_OPSYS_HALF_TIME_GRAN (USEC_IN_SEC / (2 * HZ)) |
62 | /* above is in usecs - half the scheduling granularity as per RFC3448 4.6 */ | 62 | /* above is in usecs - half the scheduling granularity as per RFC3448 4.6 */ |
63 | 63 | ||
64 | #define TFRC_WIN_COUNT_PER_RTT 4 | 64 | #define TFRC_WIN_COUNT_PER_RTT 4 |
65 | #define TFRC_WIN_COUNT_LIMIT 16 | 65 | #define TFRC_WIN_COUNT_LIMIT 16 |
66 | 66 | ||
67 | #define TFRC_MAX_BACK_OFF_TIME 64 | 67 | #define TFRC_MAX_BACK_OFF_TIME 64 |
68 | /* above is in seconds */ | 68 | /* above is in seconds */ |
69 | 69 | ||
70 | #define TFRC_SMALLEST_P 40 | 70 | #define TFRC_SMALLEST_P 40 |
71 | 71 | ||
72 | #define TFRC_RECV_IVAL_F_LENGTH 8 /* length(w[]) */ | 72 | #define TFRC_RECV_IVAL_F_LENGTH 8 /* length(w[]) */ |
73 | 73 | ||
74 | /* Number of later packets received before one is considered lost */ | 74 | /* Number of later packets received before one is considered lost */ |
75 | #define TFRC_RECV_NUM_LATE_LOSS 3 | 75 | #define TFRC_RECV_NUM_LATE_LOSS 3 |
76 | 76 | ||
77 | enum ccid3_options { | 77 | enum ccid3_options { |
78 | TFRC_OPT_LOSS_EVENT_RATE = 192, | 78 | TFRC_OPT_LOSS_EVENT_RATE = 192, |
79 | TFRC_OPT_LOSS_INTERVALS = 193, | 79 | TFRC_OPT_LOSS_INTERVALS = 193, |
80 | TFRC_OPT_RECEIVE_RATE = 194, | 80 | TFRC_OPT_RECEIVE_RATE = 194, |
81 | }; | 81 | }; |
82 | 82 | ||
83 | static int ccid3_debug; | 83 | static int ccid3_debug; |
84 | 84 | ||
85 | static kmem_cache_t *ccid3_tx_hist_slab; | 85 | static kmem_cache_t *ccid3_tx_hist_slab; |
86 | static kmem_cache_t *ccid3_rx_hist_slab; | 86 | static kmem_cache_t *ccid3_rx_hist_slab; |
87 | static kmem_cache_t *ccid3_loss_interval_hist_slab; | 87 | static kmem_cache_t *ccid3_loss_interval_hist_slab; |
88 | 88 | ||
89 | static inline struct ccid3_tx_hist_entry *ccid3_tx_hist_entry_new(int prio) | 89 | static inline struct ccid3_tx_hist_entry *ccid3_tx_hist_entry_new(int prio) |
90 | { | 90 | { |
91 | struct ccid3_tx_hist_entry *entry = kmem_cache_alloc(ccid3_tx_hist_slab, prio); | 91 | struct ccid3_tx_hist_entry *entry = kmem_cache_alloc(ccid3_tx_hist_slab, prio); |
92 | 92 | ||
93 | if (entry != NULL) | 93 | if (entry != NULL) |
94 | entry->ccid3htx_sent = 0; | 94 | entry->ccid3htx_sent = 0; |
95 | 95 | ||
96 | return entry; | 96 | return entry; |
97 | } | 97 | } |
98 | 98 | ||
99 | static inline void ccid3_tx_hist_entry_delete(struct ccid3_tx_hist_entry *entry) | 99 | static inline void ccid3_tx_hist_entry_delete(struct ccid3_tx_hist_entry *entry) |
100 | { | 100 | { |
101 | if (entry != NULL) | 101 | if (entry != NULL) |
102 | kmem_cache_free(ccid3_tx_hist_slab, entry); | 102 | kmem_cache_free(ccid3_tx_hist_slab, entry); |
103 | } | 103 | } |
104 | 104 | ||
105 | static inline struct ccid3_rx_hist_entry *ccid3_rx_hist_entry_new(struct sock *sk, | 105 | static inline struct ccid3_rx_hist_entry *ccid3_rx_hist_entry_new(struct sock *sk, |
106 | struct sk_buff *skb, | 106 | struct sk_buff *skb, |
107 | int prio) | 107 | int prio) |
108 | { | 108 | { |
109 | struct ccid3_rx_hist_entry *entry = kmem_cache_alloc(ccid3_rx_hist_slab, prio); | 109 | struct ccid3_rx_hist_entry *entry = kmem_cache_alloc(ccid3_rx_hist_slab, prio); |
110 | 110 | ||
111 | if (entry != NULL) { | 111 | if (entry != NULL) { |
112 | const struct dccp_hdr *dh = dccp_hdr(skb); | 112 | const struct dccp_hdr *dh = dccp_hdr(skb); |
113 | 113 | ||
114 | entry->ccid3hrx_seqno = DCCP_SKB_CB(skb)->dccpd_seq; | 114 | entry->ccid3hrx_seqno = DCCP_SKB_CB(skb)->dccpd_seq; |
115 | entry->ccid3hrx_win_count = dh->dccph_ccval; | 115 | entry->ccid3hrx_win_count = dh->dccph_ccval; |
116 | entry->ccid3hrx_type = dh->dccph_type; | 116 | entry->ccid3hrx_type = dh->dccph_type; |
117 | entry->ccid3hrx_ndp = dccp_sk(sk)->dccps_options_received.dccpor_ndp; | 117 | entry->ccid3hrx_ndp = dccp_sk(sk)->dccps_options_received.dccpor_ndp; |
118 | do_gettimeofday(&(entry->ccid3hrx_tstamp)); | 118 | do_gettimeofday(&(entry->ccid3hrx_tstamp)); |
119 | } | 119 | } |
120 | 120 | ||
121 | return entry; | 121 | return entry; |
122 | } | 122 | } |
123 | 123 | ||
124 | static inline void ccid3_rx_hist_entry_delete(struct ccid3_rx_hist_entry *entry) | 124 | static inline void ccid3_rx_hist_entry_delete(struct ccid3_rx_hist_entry *entry) |
125 | { | 125 | { |
126 | if (entry != NULL) | 126 | if (entry != NULL) |
127 | kmem_cache_free(ccid3_rx_hist_slab, entry); | 127 | kmem_cache_free(ccid3_rx_hist_slab, entry); |
128 | } | 128 | } |
129 | 129 | ||
130 | static void ccid3_rx_history_delete(struct list_head *hist) | 130 | static void ccid3_rx_history_delete(struct list_head *hist) |
131 | { | 131 | { |
132 | struct ccid3_rx_hist_entry *entry, *next; | 132 | struct ccid3_rx_hist_entry *entry, *next; |
133 | 133 | ||
134 | list_for_each_entry_safe(entry, next, hist, ccid3hrx_node) { | 134 | list_for_each_entry_safe(entry, next, hist, ccid3hrx_node) { |
135 | list_del_init(&entry->ccid3hrx_node); | 135 | list_del_init(&entry->ccid3hrx_node); |
136 | kmem_cache_free(ccid3_rx_hist_slab, entry); | 136 | kmem_cache_free(ccid3_rx_hist_slab, entry); |
137 | } | 137 | } |
138 | } | 138 | } |
139 | 139 | ||
140 | static inline struct ccid3_loss_interval_hist_entry *ccid3_loss_interval_hist_entry_new(int prio) | 140 | static inline struct ccid3_loss_interval_hist_entry *ccid3_loss_interval_hist_entry_new(int prio) |
141 | { | 141 | { |
142 | return kmem_cache_alloc(ccid3_loss_interval_hist_slab, prio); | 142 | return kmem_cache_alloc(ccid3_loss_interval_hist_slab, prio); |
143 | } | 143 | } |
144 | 144 | ||
145 | static inline void ccid3_loss_interval_hist_entry_delete(struct ccid3_loss_interval_hist_entry *entry) | 145 | static inline void ccid3_loss_interval_hist_entry_delete(struct ccid3_loss_interval_hist_entry *entry) |
146 | { | 146 | { |
147 | if (entry != NULL) | 147 | if (entry != NULL) |
148 | kmem_cache_free(ccid3_loss_interval_hist_slab, entry); | 148 | kmem_cache_free(ccid3_loss_interval_hist_slab, entry); |
149 | } | 149 | } |
150 | 150 | ||
151 | static void ccid3_loss_interval_history_delete(struct list_head *hist) | 151 | static void ccid3_loss_interval_history_delete(struct list_head *hist) |
152 | { | 152 | { |
153 | struct ccid3_loss_interval_hist_entry *entry, *next; | 153 | struct ccid3_loss_interval_hist_entry *entry, *next; |
154 | 154 | ||
155 | list_for_each_entry_safe(entry, next, hist, ccid3lih_node) { | 155 | list_for_each_entry_safe(entry, next, hist, ccid3lih_node) { |
156 | list_del_init(&entry->ccid3lih_node); | 156 | list_del_init(&entry->ccid3lih_node); |
157 | kmem_cache_free(ccid3_loss_interval_hist_slab, entry); | 157 | kmem_cache_free(ccid3_loss_interval_hist_slab, entry); |
158 | } | 158 | } |
159 | } | 159 | } |
160 | 160 | ||
161 | static int ccid3_init(struct sock *sk) | 161 | static int ccid3_init(struct sock *sk) |
162 | { | 162 | { |
163 | ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk); | 163 | ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk); |
164 | return 0; | 164 | return 0; |
165 | } | 165 | } |
166 | 166 | ||
167 | static void ccid3_exit(struct sock *sk) | 167 | static void ccid3_exit(struct sock *sk) |
168 | { | 168 | { |
169 | ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk); | 169 | ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk); |
170 | } | 170 | } |
171 | 171 | ||
172 | /* TFRC sender states */ | 172 | /* TFRC sender states */ |
173 | enum ccid3_hc_tx_states { | 173 | enum ccid3_hc_tx_states { |
174 | TFRC_SSTATE_NO_SENT = 1, | 174 | TFRC_SSTATE_NO_SENT = 1, |
175 | TFRC_SSTATE_NO_FBACK, | 175 | TFRC_SSTATE_NO_FBACK, |
176 | TFRC_SSTATE_FBACK, | 176 | TFRC_SSTATE_FBACK, |
177 | TFRC_SSTATE_TERM, | 177 | TFRC_SSTATE_TERM, |
178 | }; | 178 | }; |
179 | 179 | ||
180 | #ifdef CCID3_DEBUG | 180 | #ifdef CCID3_DEBUG |
181 | static const char *ccid3_tx_state_name(enum ccid3_hc_tx_states state) | 181 | static const char *ccid3_tx_state_name(enum ccid3_hc_tx_states state) |
182 | { | 182 | { |
183 | static char *ccid3_state_names[] = { | 183 | static char *ccid3_state_names[] = { |
184 | [TFRC_SSTATE_NO_SENT] = "NO_SENT", | 184 | [TFRC_SSTATE_NO_SENT] = "NO_SENT", |
185 | [TFRC_SSTATE_NO_FBACK] = "NO_FBACK", | 185 | [TFRC_SSTATE_NO_FBACK] = "NO_FBACK", |
186 | [TFRC_SSTATE_FBACK] = "FBACK", | 186 | [TFRC_SSTATE_FBACK] = "FBACK", |
187 | [TFRC_SSTATE_TERM] = "TERM", | 187 | [TFRC_SSTATE_TERM] = "TERM", |
188 | }; | 188 | }; |
189 | 189 | ||
190 | return ccid3_state_names[state]; | 190 | return ccid3_state_names[state]; |
191 | } | 191 | } |
192 | #endif | 192 | #endif |
193 | 193 | ||
194 | static inline void ccid3_hc_tx_set_state(struct sock *sk, enum ccid3_hc_tx_states state) | 194 | static inline void ccid3_hc_tx_set_state(struct sock *sk, enum ccid3_hc_tx_states state) |
195 | { | 195 | { |
196 | struct dccp_sock *dp = dccp_sk(sk); | 196 | struct dccp_sock *dp = dccp_sk(sk); |
197 | struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private; | 197 | struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private; |
198 | enum ccid3_hc_tx_states oldstate = hctx->ccid3hctx_state; | 198 | enum ccid3_hc_tx_states oldstate = hctx->ccid3hctx_state; |
199 | 199 | ||
200 | ccid3_pr_debug("%s(%p) %-8.8s -> %s\n", | 200 | ccid3_pr_debug("%s(%p) %-8.8s -> %s\n", |
201 | dccp_role(sk), sk, ccid3_tx_state_name(oldstate), ccid3_tx_state_name(state)); | 201 | dccp_role(sk), sk, ccid3_tx_state_name(oldstate), ccid3_tx_state_name(state)); |
202 | WARN_ON(state == oldstate); | 202 | WARN_ON(state == oldstate); |
203 | hctx->ccid3hctx_state = state; | 203 | hctx->ccid3hctx_state = state; |
204 | } | 204 | } |
205 | 205 | ||
206 | static void timeval_sub(struct timeval large, struct timeval small, struct timeval *result) { | 206 | static void timeval_sub(struct timeval large, struct timeval small, struct timeval *result) { |
207 | 207 | ||
208 | result->tv_sec = large.tv_sec-small.tv_sec; | 208 | result->tv_sec = large.tv_sec-small.tv_sec; |
209 | if (large.tv_usec < small.tv_usec) { | 209 | if (large.tv_usec < small.tv_usec) { |
210 | (result->tv_sec)--; | 210 | (result->tv_sec)--; |
211 | result->tv_usec = USEC_IN_SEC+large.tv_usec-small.tv_usec; | 211 | result->tv_usec = USEC_IN_SEC+large.tv_usec-small.tv_usec; |
212 | } else | 212 | } else |
213 | result->tv_usec = large.tv_usec-small.tv_usec; | 213 | result->tv_usec = large.tv_usec-small.tv_usec; |
214 | } | 214 | } |
215 | 215 | ||
216 | static inline void timeval_fix(struct timeval *tv) { | 216 | static inline void timeval_fix(struct timeval *tv) { |
217 | if (tv->tv_usec >= USEC_IN_SEC) { | 217 | if (tv->tv_usec >= USEC_IN_SEC) { |
218 | tv->tv_sec++; | 218 | tv->tv_sec++; |
219 | tv->tv_usec -= USEC_IN_SEC; | 219 | tv->tv_usec -= USEC_IN_SEC; |
220 | } | 220 | } |
221 | } | 221 | } |
222 | 222 | ||
223 | /* returns the difference in usecs between timeval passed in and current time */ | 223 | /* returns the difference in usecs between timeval passed in and current time */ |
224 | static inline u32 now_delta(struct timeval tv) { | 224 | static inline u32 now_delta(struct timeval tv) { |
225 | struct timeval now; | 225 | struct timeval now; |
226 | 226 | ||
227 | do_gettimeofday(&now); | 227 | do_gettimeofday(&now); |
228 | return ((now.tv_sec-tv.tv_sec)*1000000+now.tv_usec-tv.tv_usec); | 228 | return ((now.tv_sec-tv.tv_sec)*1000000+now.tv_usec-tv.tv_usec); |
229 | } | 229 | } |
230 | 230 | ||
231 | #define CALCX_ARRSIZE 500 | 231 | #define CALCX_ARRSIZE 500 |
232 | 232 | ||
233 | #define CALCX_SPLIT 50000 | 233 | #define CALCX_SPLIT 50000 |
234 | /* equivalent to 0.05 */ | 234 | /* equivalent to 0.05 */ |
235 | 235 | ||
236 | static const u32 calcx_lookup[CALCX_ARRSIZE][2] = { | 236 | static const u32 calcx_lookup[CALCX_ARRSIZE][2] = { |
237 | { 37172 , 8172 }, | 237 | { 37172 , 8172 }, |
238 | { 53499 , 11567 }, | 238 | { 53499 , 11567 }, |
239 | { 66664 , 14180 }, | 239 | { 66664 , 14180 }, |
240 | { 78298 , 16388 }, | 240 | { 78298 , 16388 }, |
241 | { 89021 , 18339 }, | 241 | { 89021 , 18339 }, |
242 | { 99147 , 20108 }, | 242 | { 99147 , 20108 }, |
243 | { 108858 , 21738 }, | 243 | { 108858 , 21738 }, |
244 | { 118273 , 23260 }, | 244 | { 118273 , 23260 }, |
245 | { 127474 , 24693 }, | 245 | { 127474 , 24693 }, |
246 | { 136520 , 26052 }, | 246 | { 136520 , 26052 }, |
247 | { 145456 , 27348 }, | 247 | { 145456 , 27348 }, |
248 | { 154316 , 28589 }, | 248 | { 154316 , 28589 }, |
249 | { 163130 , 29783 }, | 249 | { 163130 , 29783 }, |
250 | { 171919 , 30935 }, | 250 | { 171919 , 30935 }, |
251 | { 180704 , 32049 }, | 251 | { 180704 , 32049 }, |
252 | { 189502 , 33130 }, | 252 | { 189502 , 33130 }, |
253 | { 198328 , 34180 }, | 253 | { 198328 , 34180 }, |
254 | { 207194 , 35202 }, | 254 | { 207194 , 35202 }, |
255 | { 216114 , 36198 }, | 255 | { 216114 , 36198 }, |
256 | { 225097 , 37172 }, | 256 | { 225097 , 37172 }, |
257 | { 234153 , 38123 }, | 257 | { 234153 , 38123 }, |
258 | { 243294 , 39055 }, | 258 | { 243294 , 39055 }, |
259 | { 252527 , 39968 }, | 259 | { 252527 , 39968 }, |
260 | { 261861 , 40864 }, | 260 | { 261861 , 40864 }, |
261 | { 271305 , 41743 }, | 261 | { 271305 , 41743 }, |
262 | { 280866 , 42607 }, | 262 | { 280866 , 42607 }, |
263 | { 290553 , 43457 }, | 263 | { 290553 , 43457 }, |
264 | { 300372 , 44293 }, | 264 | { 300372 , 44293 }, |
265 | { 310333 , 45117 }, | 265 | { 310333 , 45117 }, |
266 | { 320441 , 45929 }, | 266 | { 320441 , 45929 }, |
267 | { 330705 , 46729 }, | 267 | { 330705 , 46729 }, |
268 | { 341131 , 47518 }, | 268 | { 341131 , 47518 }, |
269 | { 351728 , 48297 }, | 269 | { 351728 , 48297 }, |
270 | { 362501 , 49066 }, | 270 | { 362501 , 49066 }, |
271 | { 373460 , 49826 }, | 271 | { 373460 , 49826 }, |
272 | { 384609 , 50577 }, | 272 | { 384609 , 50577 }, |
273 | { 395958 , 51320 }, | 273 | { 395958 , 51320 }, |
274 | { 407513 , 52054 }, | 274 | { 407513 , 52054 }, |
275 | { 419281 , 52780 }, | 275 | { 419281 , 52780 }, |
276 | { 431270 , 53499 }, | 276 | { 431270 , 53499 }, |
277 | { 443487 , 54211 }, | 277 | { 443487 , 54211 }, |
278 | { 455940 , 54916 }, | 278 | { 455940 , 54916 }, |
279 | { 468635 , 55614 }, | 279 | { 468635 , 55614 }, |
280 | { 481581 , 56306 }, | 280 | { 481581 , 56306 }, |
281 | { 494785 , 56991 }, | 281 | { 494785 , 56991 }, |
282 | { 508254 , 57671 }, | 282 | { 508254 , 57671 }, |
283 | { 521996 , 58345 }, | 283 | { 521996 , 58345 }, |
284 | { 536019 , 59014 }, | 284 | { 536019 , 59014 }, |
285 | { 550331 , 59677 }, | 285 | { 550331 , 59677 }, |
286 | { 564939 , 60335 }, | 286 | { 564939 , 60335 }, |
287 | { 579851 , 60988 }, | 287 | { 579851 , 60988 }, |
288 | { 595075 , 61636 }, | 288 | { 595075 , 61636 }, |
289 | { 610619 , 62279 }, | 289 | { 610619 , 62279 }, |
290 | { 626491 , 62918 }, | 290 | { 626491 , 62918 }, |
291 | { 642700 , 63553 }, | 291 | { 642700 , 63553 }, |
292 | { 659253 , 64183 }, | 292 | { 659253 , 64183 }, |
293 | { 676158 , 64809 }, | 293 | { 676158 , 64809 }, |
294 | { 693424 , 65431 }, | 294 | { 693424 , 65431 }, |
295 | { 711060 , 66050 }, | 295 | { 711060 , 66050 }, |
296 | { 729073 , 66664 }, | 296 | { 729073 , 66664 }, |
297 | { 747472 , 67275 }, | 297 | { 747472 , 67275 }, |
298 | { 766266 , 67882 }, | 298 | { 766266 , 67882 }, |
299 | { 785464 , 68486 }, | 299 | { 785464 , 68486 }, |
300 | { 805073 , 69087 }, | 300 | { 805073 , 69087 }, |
301 | { 825103 , 69684 }, | 301 | { 825103 , 69684 }, |
302 | { 845562 , 70278 }, | 302 | { 845562 , 70278 }, |
303 | { 866460 , 70868 }, | 303 | { 866460 , 70868 }, |
304 | { 887805 , 71456 }, | 304 | { 887805 , 71456 }, |
305 | { 909606 , 72041 }, | 305 | { 909606 , 72041 }, |
306 | { 931873 , 72623 }, | 306 | { 931873 , 72623 }, |
307 | { 954614 , 73202 }, | 307 | { 954614 , 73202 }, |
308 | { 977839 , 73778 }, | 308 | { 977839 , 73778 }, |
309 | { 1001557 , 74352 }, | 309 | { 1001557 , 74352 }, |
310 | { 1025777 , 74923 }, | 310 | { 1025777 , 74923 }, |
311 | { 1050508 , 75492 }, | 311 | { 1050508 , 75492 }, |
312 | { 1075761 , 76058 }, | 312 | { 1075761 , 76058 }, |
313 | { 1101544 , 76621 }, | 313 | { 1101544 , 76621 }, |
314 | { 1127867 , 77183 }, | 314 | { 1127867 , 77183 }, |
315 | { 1154739 , 77741 }, | 315 | { 1154739 , 77741 }, |
316 | { 1182172 , 78298 }, | 316 | { 1182172 , 78298 }, |
317 | { 1210173 , 78852 }, | 317 | { 1210173 , 78852 }, |
318 | { 1238753 , 79405 }, | 318 | { 1238753 , 79405 }, |
319 | { 1267922 , 79955 }, | 319 | { 1267922 , 79955 }, |
320 | { 1297689 , 80503 }, | 320 | { 1297689 , 80503 }, |
321 | { 1328066 , 81049 }, | 321 | { 1328066 , 81049 }, |
322 | { 1359060 , 81593 }, | 322 | { 1359060 , 81593 }, |
323 | { 1390684 , 82135 }, | 323 | { 1390684 , 82135 }, |
324 | { 1422947 , 82675 }, | 324 | { 1422947 , 82675 }, |
325 | { 1455859 , 83213 }, | 325 | { 1455859 , 83213 }, |
326 | { 1489430 , 83750 }, | 326 | { 1489430 , 83750 }, |
327 | { 1523671 , 84284 }, | 327 | { 1523671 , 84284 }, |
328 | { 1558593 , 84817 }, | 328 | { 1558593 , 84817 }, |
329 | { 1594205 , 85348 }, | 329 | { 1594205 , 85348 }, |
330 | { 1630518 , 85878 }, | 330 | { 1630518 , 85878 }, |
331 | { 1667543 , 86406 }, | 331 | { 1667543 , 86406 }, |
332 | { 1705290 , 86932 }, | 332 | { 1705290 , 86932 }, |
333 | { 1743770 , 87457 }, | 333 | { 1743770 , 87457 }, |
334 | { 1782994 , 87980 }, | 334 | { 1782994 , 87980 }, |
335 | { 1822973 , 88501 }, | 335 | { 1822973 , 88501 }, |
336 | { 1863717 , 89021 }, | 336 | { 1863717 , 89021 }, |
337 | { 1905237 , 89540 }, | 337 | { 1905237 , 89540 }, |
338 | { 1947545 , 90057 }, | 338 | { 1947545 , 90057 }, |
339 | { 1990650 , 90573 }, | 339 | { 1990650 , 90573 }, |
340 | { 2034566 , 91087 }, | 340 | { 2034566 , 91087 }, |
341 | { 2079301 , 91600 }, | 341 | { 2079301 , 91600 }, |
342 | { 2124869 , 92111 }, | 342 | { 2124869 , 92111 }, |
343 | { 2171279 , 92622 }, | 343 | { 2171279 , 92622 }, |
344 | { 2218543 , 93131 }, | 344 | { 2218543 , 93131 }, |
345 | { 2266673 , 93639 }, | 345 | { 2266673 , 93639 }, |
346 | { 2315680 , 94145 }, | 346 | { 2315680 , 94145 }, |
347 | { 2365575 , 94650 }, | 347 | { 2365575 , 94650 }, |
348 | { 2416371 , 95154 }, | 348 | { 2416371 , 95154 }, |
349 | { 2468077 , 95657 }, | 349 | { 2468077 , 95657 }, |
350 | { 2520707 , 96159 }, | 350 | { 2520707 , 96159 }, |
351 | { 2574271 , 96660 }, | 351 | { 2574271 , 96660 }, |
352 | { 2628782 , 97159 }, | 352 | { 2628782 , 97159 }, |
353 | { 2684250 , 97658 }, | 353 | { 2684250 , 97658 }, |
354 | { 2740689 , 98155 }, | 354 | { 2740689 , 98155 }, |
355 | { 2798110 , 98651 }, | 355 | { 2798110 , 98651 }, |
356 | { 2856524 , 99147 }, | 356 | { 2856524 , 99147 }, |
357 | { 2915944 , 99641 }, | 357 | { 2915944 , 99641 }, |
358 | { 2976382 , 100134 }, | 358 | { 2976382 , 100134 }, |
359 | { 3037850 , 100626 }, | 359 | { 3037850 , 100626 }, |
360 | { 3100360 , 101117 }, | 360 | { 3100360 , 101117 }, |
361 | { 3163924 , 101608 }, | 361 | { 3163924 , 101608 }, |
362 | { 3228554 , 102097 }, | 362 | { 3228554 , 102097 }, |
363 | { 3294263 , 102586 }, | 363 | { 3294263 , 102586 }, |
364 | { 3361063 , 103073 }, | 364 | { 3361063 , 103073 }, |
365 | { 3428966 , 103560 }, | 365 | { 3428966 , 103560 }, |
366 | { 3497984 , 104045 }, | 366 | { 3497984 , 104045 }, |
367 | { 3568131 , 104530 }, | 367 | { 3568131 , 104530 }, |
368 | { 3639419 , 105014 }, | 368 | { 3639419 , 105014 }, |
369 | { 3711860 , 105498 }, | 369 | { 3711860 , 105498 }, |
370 | { 3785467 , 105980 }, | 370 | { 3785467 , 105980 }, |
371 | { 3860253 , 106462 }, | 371 | { 3860253 , 106462 }, |
372 | { 3936229 , 106942 }, | 372 | { 3936229 , 106942 }, |
373 | { 4013410 , 107422 }, | 373 | { 4013410 , 107422 }, |
374 | { 4091808 , 107902 }, | 374 | { 4091808 , 107902 }, |
375 | { 4171435 , 108380 }, | 375 | { 4171435 , 108380 }, |
376 | { 4252306 , 108858 }, | 376 | { 4252306 , 108858 }, |
377 | { 4334431 , 109335 }, | 377 | { 4334431 , 109335 }, |
378 | { 4417825 , 109811 }, | 378 | { 4417825 , 109811 }, |
379 | { 4502501 , 110287 }, | 379 | { 4502501 , 110287 }, |
380 | { 4588472 , 110762 }, | 380 | { 4588472 , 110762 }, |
381 | { 4675750 , 111236 }, | 381 | { 4675750 , 111236 }, |
382 | { 4764349 , 111709 }, | 382 | { 4764349 , 111709 }, |
383 | { 4854283 , 112182 }, | 383 | { 4854283 , 112182 }, |
384 | { 4945564 , 112654 }, | 384 | { 4945564 , 112654 }, |
385 | { 5038206 , 113126 }, | 385 | { 5038206 , 113126 }, |
386 | { 5132223 , 113597 }, | 386 | { 5132223 , 113597 }, |
387 | { 5227627 , 114067 }, | 387 | { 5227627 , 114067 }, |
388 | { 5324432 , 114537 }, | 388 | { 5324432 , 114537 }, |
389 | { 5422652 , 115006 }, | 389 | { 5422652 , 115006 }, |
390 | { 5522299 , 115474 }, | 390 | { 5522299 , 115474 }, |
391 | { 5623389 , 115942 }, | 391 | { 5623389 , 115942 }, |
392 | { 5725934 , 116409 }, | 392 | { 5725934 , 116409 }, |
393 | { 5829948 , 116876 }, | 393 | { 5829948 , 116876 }, |
394 | { 5935446 , 117342 }, | 394 | { 5935446 , 117342 }, |
395 | { 6042439 , 117808 }, | 395 | { 6042439 , 117808 }, |
396 | { 6150943 , 118273 }, | 396 | { 6150943 , 118273 }, |
397 | { 6260972 , 118738 }, | 397 | { 6260972 , 118738 }, |
398 | { 6372538 , 119202 }, | 398 | { 6372538 , 119202 }, |
399 | { 6485657 , 119665 }, | 399 | { 6485657 , 119665 }, |
400 | { 6600342 , 120128 }, | 400 | { 6600342 , 120128 }, |
401 | { 6716607 , 120591 }, | 401 | { 6716607 , 120591 }, |
402 | { 6834467 , 121053 }, | 402 | { 6834467 , 121053 }, |
403 | { 6953935 , 121514 }, | 403 | { 6953935 , 121514 }, |
404 | { 7075025 , 121976 }, | 404 | { 7075025 , 121976 }, |
405 | { 7197752 , 122436 }, | 405 | { 7197752 , 122436 }, |
406 | { 7322131 , 122896 }, | 406 | { 7322131 , 122896 }, |
407 | { 7448175 , 123356 }, | 407 | { 7448175 , 123356 }, |
408 | { 7575898 , 123815 }, | 408 | { 7575898 , 123815 }, |
409 | { 7705316 , 124274 }, | 409 | { 7705316 , 124274 }, |
410 | { 7836442 , 124733 }, | 410 | { 7836442 , 124733 }, |
411 | { 7969291 , 125191 }, | 411 | { 7969291 , 125191 }, |
412 | { 8103877 , 125648 }, | 412 | { 8103877 , 125648 }, |
413 | { 8240216 , 126105 }, | 413 | { 8240216 , 126105 }, |
414 | { 8378321 , 126562 }, | 414 | { 8378321 , 126562 }, |
415 | { 8518208 , 127018 }, | 415 | { 8518208 , 127018 }, |
416 | { 8659890 , 127474 }, | 416 | { 8659890 , 127474 }, |
417 | { 8803384 , 127930 }, | 417 | { 8803384 , 127930 }, |
418 | { 8948702 , 128385 }, | 418 | { 8948702 , 128385 }, |
419 | { 9095861 , 128840 }, | 419 | { 9095861 , 128840 }, |
420 | { 9244875 , 129294 }, | 420 | { 9244875 , 129294 }, |
421 | { 9395760 , 129748 }, | 421 | { 9395760 , 129748 }, |
422 | { 9548529 , 130202 }, | 422 | { 9548529 , 130202 }, |
423 | { 9703198 , 130655 }, | 423 | { 9703198 , 130655 }, |
424 | { 9859782 , 131108 }, | 424 | { 9859782 , 131108 }, |
425 | { 10018296 , 131561 }, | 425 | { 10018296 , 131561 }, |
426 | { 10178755 , 132014 }, | 426 | { 10178755 , 132014 }, |
427 | { 10341174 , 132466 }, | 427 | { 10341174 , 132466 }, |
428 | { 10505569 , 132917 }, | 428 | { 10505569 , 132917 }, |
429 | { 10671954 , 133369 }, | 429 | { 10671954 , 133369 }, |
430 | { 10840345 , 133820 }, | 430 | { 10840345 , 133820 }, |
431 | { 11010757 , 134271 }, | 431 | { 11010757 , 134271 }, |
432 | { 11183206 , 134721 }, | 432 | { 11183206 , 134721 }, |
433 | { 11357706 , 135171 }, | 433 | { 11357706 , 135171 }, |
434 | { 11534274 , 135621 }, | 434 | { 11534274 , 135621 }, |
435 | { 11712924 , 136071 }, | 435 | { 11712924 , 136071 }, |
436 | { 11893673 , 136520 }, | 436 | { 11893673 , 136520 }, |
437 | { 12076536 , 136969 }, | 437 | { 12076536 , 136969 }, |
438 | { 12261527 , 137418 }, | 438 | { 12261527 , 137418 }, |
439 | { 12448664 , 137867 }, | 439 | { 12448664 , 137867 }, |
440 | { 12637961 , 138315 }, | 440 | { 12637961 , 138315 }, |
441 | { 12829435 , 138763 }, | 441 | { 12829435 , 138763 }, |
442 | { 13023101 , 139211 }, | 442 | { 13023101 , 139211 }, |
443 | { 13218974 , 139658 }, | 443 | { 13218974 , 139658 }, |
444 | { 13417071 , 140106 }, | 444 | { 13417071 , 140106 }, |
445 | { 13617407 , 140553 }, | 445 | { 13617407 , 140553 }, |
446 | { 13819999 , 140999 }, | 446 | { 13819999 , 140999 }, |
447 | { 14024862 , 141446 }, | 447 | { 14024862 , 141446 }, |
448 | { 14232012 , 141892 }, | 448 | { 14232012 , 141892 }, |
449 | { 14441465 , 142339 }, | 449 | { 14441465 , 142339 }, |
450 | { 14653238 , 142785 }, | 450 | { 14653238 , 142785 }, |
451 | { 14867346 , 143230 }, | 451 | { 14867346 , 143230 }, |
452 | { 15083805 , 143676 }, | 452 | { 15083805 , 143676 }, |
453 | { 15302632 , 144121 }, | 453 | { 15302632 , 144121 }, |
454 | { 15523842 , 144566 }, | 454 | { 15523842 , 144566 }, |
455 | { 15747453 , 145011 }, | 455 | { 15747453 , 145011 }, |
456 | { 15973479 , 145456 }, | 456 | { 15973479 , 145456 }, |
457 | { 16201939 , 145900 }, | 457 | { 16201939 , 145900 }, |
458 | { 16432847 , 146345 }, | 458 | { 16432847 , 146345 }, |
459 | { 16666221 , 146789 }, | 459 | { 16666221 , 146789 }, |
460 | { 16902076 , 147233 }, | 460 | { 16902076 , 147233 }, |
461 | { 17140429 , 147677 }, | 461 | { 17140429 , 147677 }, |
462 | { 17381297 , 148121 }, | 462 | { 17381297 , 148121 }, |
463 | { 17624696 , 148564 }, | 463 | { 17624696 , 148564 }, |
464 | { 17870643 , 149007 }, | 464 | { 17870643 , 149007 }, |
465 | { 18119154 , 149451 }, | 465 | { 18119154 , 149451 }, |
466 | { 18370247 , 149894 }, | 466 | { 18370247 , 149894 }, |
467 | { 18623936 , 150336 }, | 467 | { 18623936 , 150336 }, |
468 | { 18880241 , 150779 }, | 468 | { 18880241 , 150779 }, |
469 | { 19139176 , 151222 }, | 469 | { 19139176 , 151222 }, |
470 | { 19400759 , 151664 }, | 470 | { 19400759 , 151664 }, |
471 | { 19665007 , 152107 }, | 471 | { 19665007 , 152107 }, |
472 | { 19931936 , 152549 }, | 472 | { 19931936 , 152549 }, |
473 | { 20201564 , 152991 }, | 473 | { 20201564 , 152991 }, |
474 | { 20473907 , 153433 }, | 474 | { 20473907 , 153433 }, |
475 | { 20748982 , 153875 }, | 475 | { 20748982 , 153875 }, |
476 | { 21026807 , 154316 }, | 476 | { 21026807 , 154316 }, |
477 | { 21307399 , 154758 }, | 477 | { 21307399 , 154758 }, |
478 | { 21590773 , 155199 }, | 478 | { 21590773 , 155199 }, |
479 | { 21876949 , 155641 }, | 479 | { 21876949 , 155641 }, |
480 | { 22165941 , 156082 }, | 480 | { 22165941 , 156082 }, |
481 | { 22457769 , 156523 }, | 481 | { 22457769 , 156523 }, |
482 | { 22752449 , 156964 }, | 482 | { 22752449 , 156964 }, |
483 | { 23049999 , 157405 }, | 483 | { 23049999 , 157405 }, |
484 | { 23350435 , 157846 }, | 484 | { 23350435 , 157846 }, |
485 | { 23653774 , 158287 }, | 485 | { 23653774 , 158287 }, |
486 | { 23960036 , 158727 }, | 486 | { 23960036 , 158727 }, |
487 | { 24269236 , 159168 }, | 487 | { 24269236 , 159168 }, |
488 | { 24581392 , 159608 }, | 488 | { 24581392 , 159608 }, |
489 | { 24896521 , 160049 }, | 489 | { 24896521 , 160049 }, |
490 | { 25214642 , 160489 }, | 490 | { 25214642 , 160489 }, |
491 | { 25535772 , 160929 }, | 491 | { 25535772 , 160929 }, |
492 | { 25859927 , 161370 }, | 492 | { 25859927 , 161370 }, |
493 | { 26187127 , 161810 }, | 493 | { 26187127 , 161810 }, |
494 | { 26517388 , 162250 }, | 494 | { 26517388 , 162250 }, |
495 | { 26850728 , 162690 }, | 495 | { 26850728 , 162690 }, |
496 | { 27187165 , 163130 }, | 496 | { 27187165 , 163130 }, |
497 | { 27526716 , 163569 }, | 497 | { 27526716 , 163569 }, |
498 | { 27869400 , 164009 }, | 498 | { 27869400 , 164009 }, |
499 | { 28215234 , 164449 }, | 499 | { 28215234 , 164449 }, |
500 | { 28564236 , 164889 }, | 500 | { 28564236 , 164889 }, |
501 | { 28916423 , 165328 }, | 501 | { 28916423 , 165328 }, |
502 | { 29271815 , 165768 }, | 502 | { 29271815 , 165768 }, |
503 | { 29630428 , 166208 }, | 503 | { 29630428 , 166208 }, |
504 | { 29992281 , 166647 }, | 504 | { 29992281 , 166647 }, |
505 | { 30357392 , 167087 }, | 505 | { 30357392 , 167087 }, |
506 | { 30725779 , 167526 }, | 506 | { 30725779 , 167526 }, |
507 | { 31097459 , 167965 }, | 507 | { 31097459 , 167965 }, |
508 | { 31472452 , 168405 }, | 508 | { 31472452 , 168405 }, |
509 | { 31850774 , 168844 }, | 509 | { 31850774 , 168844 }, |
510 | { 32232445 , 169283 }, | 510 | { 32232445 , 169283 }, |
511 | { 32617482 , 169723 }, | 511 | { 32617482 , 169723 }, |
512 | { 33005904 , 170162 }, | 512 | { 33005904 , 170162 }, |
513 | { 33397730 , 170601 }, | 513 | { 33397730 , 170601 }, |
514 | { 33792976 , 171041 }, | 514 | { 33792976 , 171041 }, |
515 | { 34191663 , 171480 }, | 515 | { 34191663 , 171480 }, |
516 | { 34593807 , 171919 }, | 516 | { 34593807 , 171919 }, |
517 | { 34999428 , 172358 }, | 517 | { 34999428 , 172358 }, |
518 | { 35408544 , 172797 }, | 518 | { 35408544 , 172797 }, |
519 | { 35821174 , 173237 }, | 519 | { 35821174 , 173237 }, |
520 | { 36237335 , 173676 }, | 520 | { 36237335 , 173676 }, |
521 | { 36657047 , 174115 }, | 521 | { 36657047 , 174115 }, |
522 | { 37080329 , 174554 }, | 522 | { 37080329 , 174554 }, |
523 | { 37507197 , 174993 }, | 523 | { 37507197 , 174993 }, |
524 | { 37937673 , 175433 }, | 524 | { 37937673 , 175433 }, |
525 | { 38371773 , 175872 }, | 525 | { 38371773 , 175872 }, |
526 | { 38809517 , 176311 }, | 526 | { 38809517 , 176311 }, |
527 | { 39250924 , 176750 }, | 527 | { 39250924 , 176750 }, |
528 | { 39696012 , 177190 }, | 528 | { 39696012 , 177190 }, |
529 | { 40144800 , 177629 }, | 529 | { 40144800 , 177629 }, |
530 | { 40597308 , 178068 }, | 530 | { 40597308 , 178068 }, |
531 | { 41053553 , 178507 }, | 531 | { 41053553 , 178507 }, |
532 | { 41513554 , 178947 }, | 532 | { 41513554 , 178947 }, |
533 | { 41977332 , 179386 }, | 533 | { 41977332 , 179386 }, |
534 | { 42444904 , 179825 }, | 534 | { 42444904 , 179825 }, |
535 | { 42916290 , 180265 }, | 535 | { 42916290 , 180265 }, |
536 | { 43391509 , 180704 }, | 536 | { 43391509 , 180704 }, |
537 | { 43870579 , 181144 }, | 537 | { 43870579 , 181144 }, |
538 | { 44353520 , 181583 }, | 538 | { 44353520 , 181583 }, |
539 | { 44840352 , 182023 }, | 539 | { 44840352 , 182023 }, |
540 | { 45331092 , 182462 }, | 540 | { 45331092 , 182462 }, |
541 | { 45825761 , 182902 }, | 541 | { 45825761 , 182902 }, |
542 | { 46324378 , 183342 }, | 542 | { 46324378 , 183342 }, |
543 | { 46826961 , 183781 }, | 543 | { 46826961 , 183781 }, |
544 | { 47333531 , 184221 }, | 544 | { 47333531 , 184221 }, |
545 | { 47844106 , 184661 }, | 545 | { 47844106 , 184661 }, |
546 | { 48358706 , 185101 }, | 546 | { 48358706 , 185101 }, |
547 | { 48877350 , 185541 }, | 547 | { 48877350 , 185541 }, |
548 | { 49400058 , 185981 }, | 548 | { 49400058 , 185981 }, |
549 | { 49926849 , 186421 }, | 549 | { 49926849 , 186421 }, |
550 | { 50457743 , 186861 }, | 550 | { 50457743 , 186861 }, |
551 | { 50992759 , 187301 }, | 551 | { 50992759 , 187301 }, |
552 | { 51531916 , 187741 }, | 552 | { 51531916 , 187741 }, |
553 | { 52075235 , 188181 }, | 553 | { 52075235 , 188181 }, |
554 | { 52622735 , 188622 }, | 554 | { 52622735 , 188622 }, |
555 | { 53174435 , 189062 }, | 555 | { 53174435 , 189062 }, |
556 | { 53730355 , 189502 }, | 556 | { 53730355 , 189502 }, |
557 | { 54290515 , 189943 }, | 557 | { 54290515 , 189943 }, |
558 | { 54854935 , 190383 }, | 558 | { 54854935 , 190383 }, |
559 | { 55423634 , 190824 }, | 559 | { 55423634 , 190824 }, |
560 | { 55996633 , 191265 }, | 560 | { 55996633 , 191265 }, |
561 | { 56573950 , 191706 }, | 561 | { 56573950 , 191706 }, |
562 | { 57155606 , 192146 }, | 562 | { 57155606 , 192146 }, |
563 | { 57741621 , 192587 }, | 563 | { 57741621 , 192587 }, |
564 | { 58332014 , 193028 }, | 564 | { 58332014 , 193028 }, |
565 | { 58926806 , 193470 }, | 565 | { 58926806 , 193470 }, |
566 | { 59526017 , 193911 }, | 566 | { 59526017 , 193911 }, |
567 | { 60129666 , 194352 }, | 567 | { 60129666 , 194352 }, |
568 | { 60737774 , 194793 }, | 568 | { 60737774 , 194793 }, |
569 | { 61350361 , 195235 }, | 569 | { 61350361 , 195235 }, |
570 | { 61967446 , 195677 }, | 570 | { 61967446 , 195677 }, |
571 | { 62589050 , 196118 }, | 571 | { 62589050 , 196118 }, |
572 | { 63215194 , 196560 }, | 572 | { 63215194 , 196560 }, |
573 | { 63845897 , 197002 }, | 573 | { 63845897 , 197002 }, |
574 | { 64481179 , 197444 }, | 574 | { 64481179 , 197444 }, |
575 | { 65121061 , 197886 }, | 575 | { 65121061 , 197886 }, |
576 | { 65765563 , 198328 }, | 576 | { 65765563 , 198328 }, |
577 | { 66414705 , 198770 }, | 577 | { 66414705 , 198770 }, |
578 | { 67068508 , 199213 }, | 578 | { 67068508 , 199213 }, |
579 | { 67726992 , 199655 }, | 579 | { 67726992 , 199655 }, |
580 | { 68390177 , 200098 }, | 580 | { 68390177 , 200098 }, |
581 | { 69058085 , 200540 }, | 581 | { 69058085 , 200540 }, |
582 | { 69730735 , 200983 }, | 582 | { 69730735 , 200983 }, |
583 | { 70408147 , 201426 }, | 583 | { 70408147 , 201426 }, |
584 | { 71090343 , 201869 }, | 584 | { 71090343 , 201869 }, |
585 | { 71777343 , 202312 }, | 585 | { 71777343 , 202312 }, |
586 | { 72469168 , 202755 }, | 586 | { 72469168 , 202755 }, |
587 | { 73165837 , 203199 }, | 587 | { 73165837 , 203199 }, |
588 | { 73867373 , 203642 }, | 588 | { 73867373 , 203642 }, |
589 | { 74573795 , 204086 }, | 589 | { 74573795 , 204086 }, |
590 | { 75285124 , 204529 }, | 590 | { 75285124 , 204529 }, |
591 | { 76001380 , 204973 }, | 591 | { 76001380 , 204973 }, |
592 | { 76722586 , 205417 }, | 592 | { 76722586 , 205417 }, |
593 | { 77448761 , 205861 }, | 593 | { 77448761 , 205861 }, |
594 | { 78179926 , 206306 }, | 594 | { 78179926 , 206306 }, |
595 | { 78916102 , 206750 }, | 595 | { 78916102 , 206750 }, |
596 | { 79657310 , 207194 }, | 596 | { 79657310 , 207194 }, |
597 | { 80403571 , 207639 }, | 597 | { 80403571 , 207639 }, |
598 | { 81154906 , 208084 }, | 598 | { 81154906 , 208084 }, |
599 | { 81911335 , 208529 }, | 599 | { 81911335 , 208529 }, |
600 | { 82672880 , 208974 }, | 600 | { 82672880 , 208974 }, |
601 | { 83439562 , 209419 }, | 601 | { 83439562 , 209419 }, |
602 | { 84211402 , 209864 }, | 602 | { 84211402 , 209864 }, |
603 | { 84988421 , 210309 }, | 603 | { 84988421 , 210309 }, |
604 | { 85770640 , 210755 }, | 604 | { 85770640 , 210755 }, |
605 | { 86558080 , 211201 }, | 605 | { 86558080 , 211201 }, |
606 | { 87350762 , 211647 }, | 606 | { 87350762 , 211647 }, |
607 | { 88148708 , 212093 }, | 607 | { 88148708 , 212093 }, |
608 | { 88951938 , 212539 }, | 608 | { 88951938 , 212539 }, |
609 | { 89760475 , 212985 }, | 609 | { 89760475 , 212985 }, |
610 | { 90574339 , 213432 }, | 610 | { 90574339 , 213432 }, |
611 | { 91393551 , 213878 }, | 611 | { 91393551 , 213878 }, |
612 | { 92218133 , 214325 }, | 612 | { 92218133 , 214325 }, |
613 | { 93048107 , 214772 }, | 613 | { 93048107 , 214772 }, |
614 | { 93883493 , 215219 }, | 614 | { 93883493 , 215219 }, |
615 | { 94724314 , 215666 }, | 615 | { 94724314 , 215666 }, |
616 | { 95570590 , 216114 }, | 616 | { 95570590 , 216114 }, |
617 | { 96422343 , 216561 }, | 617 | { 96422343 , 216561 }, |
618 | { 97279594 , 217009 }, | 618 | { 97279594 , 217009 }, |
619 | { 98142366 , 217457 }, | 619 | { 98142366 , 217457 }, |
620 | { 99010679 , 217905 }, | 620 | { 99010679 , 217905 }, |
621 | { 99884556 , 218353 }, | 621 | { 99884556 , 218353 }, |
622 | { 100764018 , 218801 }, | 622 | { 100764018 , 218801 }, |
623 | { 101649086 , 219250 }, | 623 | { 101649086 , 219250 }, |
624 | { 102539782 , 219698 }, | 624 | { 102539782 , 219698 }, |
625 | { 103436128 , 220147 }, | 625 | { 103436128 , 220147 }, |
626 | { 104338146 , 220596 }, | 626 | { 104338146 , 220596 }, |
627 | { 105245857 , 221046 }, | 627 | { 105245857 , 221046 }, |
628 | { 106159284 , 221495 }, | 628 | { 106159284 , 221495 }, |
629 | { 107078448 , 221945 }, | 629 | { 107078448 , 221945 }, |
630 | { 108003370 , 222394 }, | 630 | { 108003370 , 222394 }, |
631 | { 108934074 , 222844 }, | 631 | { 108934074 , 222844 }, |
632 | { 109870580 , 223294 }, | 632 | { 109870580 , 223294 }, |
633 | { 110812910 , 223745 }, | 633 | { 110812910 , 223745 }, |
634 | { 111761087 , 224195 }, | 634 | { 111761087 , 224195 }, |
635 | { 112715133 , 224646 }, | 635 | { 112715133 , 224646 }, |
636 | { 113675069 , 225097 }, | 636 | { 113675069 , 225097 }, |
637 | { 114640918 , 225548 }, | 637 | { 114640918 , 225548 }, |
638 | { 115612702 , 225999 }, | 638 | { 115612702 , 225999 }, |
639 | { 116590442 , 226450 }, | 639 | { 116590442 , 226450 }, |
640 | { 117574162 , 226902 }, | 640 | { 117574162 , 226902 }, |
641 | { 118563882 , 227353 }, | 641 | { 118563882 , 227353 }, |
642 | { 119559626 , 227805 }, | 642 | { 119559626 , 227805 }, |
643 | { 120561415 , 228258 }, | 643 | { 120561415 , 228258 }, |
644 | { 121569272 , 228710 }, | 644 | { 121569272 , 228710 }, |
645 | { 122583219 , 229162 }, | 645 | { 122583219 , 229162 }, |
646 | { 123603278 , 229615 }, | 646 | { 123603278 , 229615 }, |
647 | { 124629471 , 230068 }, | 647 | { 124629471 , 230068 }, |
648 | { 125661822 , 230521 }, | 648 | { 125661822 , 230521 }, |
649 | { 126700352 , 230974 }, | 649 | { 126700352 , 230974 }, |
650 | { 127745083 , 231428 }, | 650 | { 127745083 , 231428 }, |
651 | { 128796039 , 231882 }, | 651 | { 128796039 , 231882 }, |
652 | { 129853241 , 232336 }, | 652 | { 129853241 , 232336 }, |
653 | { 130916713 , 232790 }, | 653 | { 130916713 , 232790 }, |
654 | { 131986475 , 233244 }, | 654 | { 131986475 , 233244 }, |
655 | { 133062553 , 233699 }, | 655 | { 133062553 , 233699 }, |
656 | { 134144966 , 234153 }, | 656 | { 134144966 , 234153 }, |
657 | { 135233739 , 234608 }, | 657 | { 135233739 , 234608 }, |
658 | { 136328894 , 235064 }, | 658 | { 136328894 , 235064 }, |
659 | { 137430453 , 235519 }, | 659 | { 137430453 , 235519 }, |
660 | { 138538440 , 235975 }, | 660 | { 138538440 , 235975 }, |
661 | { 139652876 , 236430 }, | 661 | { 139652876 , 236430 }, |
662 | { 140773786 , 236886 }, | 662 | { 140773786 , 236886 }, |
663 | { 141901190 , 237343 }, | 663 | { 141901190 , 237343 }, |
664 | { 143035113 , 237799 }, | 664 | { 143035113 , 237799 }, |
665 | { 144175576 , 238256 }, | 665 | { 144175576 , 238256 }, |
666 | { 145322604 , 238713 }, | 666 | { 145322604 , 238713 }, |
667 | { 146476218 , 239170 }, | 667 | { 146476218 , 239170 }, |
668 | { 147636442 , 239627 }, | 668 | { 147636442 , 239627 }, |
669 | { 148803298 , 240085 }, | 669 | { 148803298 , 240085 }, |
670 | { 149976809 , 240542 }, | 670 | { 149976809 , 240542 }, |
671 | { 151156999 , 241000 }, | 671 | { 151156999 , 241000 }, |
672 | { 152343890 , 241459 }, | 672 | { 152343890 , 241459 }, |
673 | { 153537506 , 241917 }, | 673 | { 153537506 , 241917 }, |
674 | { 154737869 , 242376 }, | 674 | { 154737869 , 242376 }, |
675 | { 155945002 , 242835 }, | 675 | { 155945002 , 242835 }, |
676 | { 157158929 , 243294 }, | 676 | { 157158929 , 243294 }, |
677 | { 158379673 , 243753 }, | 677 | { 158379673 , 243753 }, |
678 | { 159607257 , 244213 }, | 678 | { 159607257 , 244213 }, |
679 | { 160841704 , 244673 }, | 679 | { 160841704 , 244673 }, |
680 | { 162083037 , 245133 }, | 680 | { 162083037 , 245133 }, |
681 | { 163331279 , 245593 }, | 681 | { 163331279 , 245593 }, |
682 | { 164586455 , 246054 }, | 682 | { 164586455 , 246054 }, |
683 | { 165848586 , 246514 }, | 683 | { 165848586 , 246514 }, |
684 | { 167117696 , 246975 }, | 684 | { 167117696 , 246975 }, |
685 | { 168393810 , 247437 }, | 685 | { 168393810 , 247437 }, |
686 | { 169676949 , 247898 }, | 686 | { 169676949 , 247898 }, |
687 | { 170967138 , 248360 }, | 687 | { 170967138 , 248360 }, |
688 | { 172264399 , 248822 }, | 688 | { 172264399 , 248822 }, |
689 | { 173568757 , 249284 }, | 689 | { 173568757 , 249284 }, |
690 | { 174880235 , 249747 }, | 690 | { 174880235 , 249747 }, |
691 | { 176198856 , 250209 }, | 691 | { 176198856 , 250209 }, |
692 | { 177524643 , 250672 }, | 692 | { 177524643 , 250672 }, |
693 | { 178857621 , 251136 }, | 693 | { 178857621 , 251136 }, |
694 | { 180197813 , 251599 }, | 694 | { 180197813 , 251599 }, |
695 | { 181545242 , 252063 }, | 695 | { 181545242 , 252063 }, |
696 | { 182899933 , 252527 }, | 696 | { 182899933 , 252527 }, |
697 | { 184261908 , 252991 }, | 697 | { 184261908 , 252991 }, |
698 | { 185631191 , 253456 }, | 698 | { 185631191 , 253456 }, |
699 | { 187007807 , 253920 }, | 699 | { 187007807 , 253920 }, |
700 | { 188391778 , 254385 }, | 700 | { 188391778 , 254385 }, |
701 | { 189783129 , 254851 }, | 701 | { 189783129 , 254851 }, |
702 | { 191181884 , 255316 }, | 702 | { 191181884 , 255316 }, |
703 | { 192588065 , 255782 }, | 703 | { 192588065 , 255782 }, |
704 | { 194001698 , 256248 }, | 704 | { 194001698 , 256248 }, |
705 | { 195422805 , 256714 }, | 705 | { 195422805 , 256714 }, |
706 | { 196851411 , 257181 }, | 706 | { 196851411 , 257181 }, |
707 | { 198287540 , 257648 }, | 707 | { 198287540 , 257648 }, |
708 | { 199731215 , 258115 }, | 708 | { 199731215 , 258115 }, |
709 | { 201182461 , 258582 }, | 709 | { 201182461 , 258582 }, |
710 | { 202641302 , 259050 }, | 710 | { 202641302 , 259050 }, |
711 | { 204107760 , 259518 }, | 711 | { 204107760 , 259518 }, |
712 | { 205581862 , 259986 }, | 712 | { 205581862 , 259986 }, |
713 | { 207063630 , 260454 }, | 713 | { 207063630 , 260454 }, |
714 | { 208553088 , 260923 }, | 714 | { 208553088 , 260923 }, |
715 | { 210050262 , 261392 }, | 715 | { 210050262 , 261392 }, |
716 | { 211555174 , 261861 }, | 716 | { 211555174 , 261861 }, |
717 | { 213067849 , 262331 }, | 717 | { 213067849 , 262331 }, |
718 | { 214588312 , 262800 }, | 718 | { 214588312 , 262800 }, |
719 | { 216116586 , 263270 }, | 719 | { 216116586 , 263270 }, |
720 | { 217652696 , 263741 }, | 720 | { 217652696 , 263741 }, |
721 | { 219196666 , 264211 }, | 721 | { 219196666 , 264211 }, |
722 | { 220748520 , 264682 }, | 722 | { 220748520 , 264682 }, |
723 | { 222308282 , 265153 }, | 723 | { 222308282 , 265153 }, |
724 | { 223875978 , 265625 }, | 724 | { 223875978 , 265625 }, |
725 | { 225451630 , 266097 }, | 725 | { 225451630 , 266097 }, |
726 | { 227035265 , 266569 }, | 726 | { 227035265 , 266569 }, |
727 | { 228626905 , 267041 }, | 727 | { 228626905 , 267041 }, |
728 | { 230226576 , 267514 }, | 728 | { 230226576 , 267514 }, |
729 | { 231834302 , 267986 }, | 729 | { 231834302 , 267986 }, |
730 | { 233450107 , 268460 }, | 730 | { 233450107 , 268460 }, |
731 | { 235074016 , 268933 }, | 731 | { 235074016 , 268933 }, |
732 | { 236706054 , 269407 }, | 732 | { 236706054 , 269407 }, |
733 | { 238346244 , 269881 }, | 733 | { 238346244 , 269881 }, |
734 | { 239994613 , 270355 }, | 734 | { 239994613 , 270355 }, |
735 | { 241651183 , 270830 }, | 735 | { 241651183 , 270830 }, |
736 | { 243315981 , 271305 } | 736 | { 243315981 , 271305 } |
737 | }; | 737 | }; |
738 | 738 | ||
739 | /* Calculate the send rate as per section 3.1 of RFC3448 | 739 | /* Calculate the send rate as per section 3.1 of RFC3448 |
740 | 740 | ||
741 | Returns send rate in bytes per second | 741 | Returns send rate in bytes per second |
742 | 742 | ||
743 | Integer maths and lookups are used as not allowed floating point in kernel | 743 | Integer maths and lookups are used as not allowed floating point in kernel |
744 | 744 | ||
745 | The function for Xcalc as per section 3.1 of RFC3448 is: | 745 | The function for Xcalc as per section 3.1 of RFC3448 is: |
746 | 746 | ||
747 | X = s | 747 | X = s |
748 | ------------------------------------------------------------- | 748 | ------------------------------------------------------------- |
749 | R*sqrt(2*b*p/3) + (t_RTO * (3*sqrt(3*b*p/8) * p * (1+32*p^2))) | 749 | R*sqrt(2*b*p/3) + (t_RTO * (3*sqrt(3*b*p/8) * p * (1+32*p^2))) |
750 | 750 | ||
751 | where | 751 | where |
752 | X is the trasmit rate in bytes/second | 752 | X is the trasmit rate in bytes/second |
753 | s is the packet size in bytes | 753 | s is the packet size in bytes |
754 | R is the round trip time in seconds | 754 | R is the round trip time in seconds |
755 | p is the loss event rate, between 0 and 1.0, of the number of loss events | 755 | p is the loss event rate, between 0 and 1.0, of the number of loss events |
756 | as a fraction of the number of packets transmitted | 756 | as a fraction of the number of packets transmitted |
757 | t_RTO is the TCP retransmission timeout value in seconds | 757 | t_RTO is the TCP retransmission timeout value in seconds |
758 | b is the number of packets acknowledged by a single TCP acknowledgement | 758 | b is the number of packets acknowledged by a single TCP acknowledgement |
759 | 759 | ||
760 | we can assume that b = 1 and t_RTO is 4 * R. With this the equation becomes: | 760 | we can assume that b = 1 and t_RTO is 4 * R. With this the equation becomes: |
761 | 761 | ||
762 | X = s | 762 | X = s |
763 | ----------------------------------------------------------------------- | 763 | ----------------------------------------------------------------------- |
764 | R * sqrt(2 * p / 3) + (12 * R * (sqrt(3 * p / 8) * p * (1 + 32 * p^2))) | 764 | R * sqrt(2 * p / 3) + (12 * R * (sqrt(3 * p / 8) * p * (1 + 32 * p^2))) |
765 | 765 | ||
766 | 766 | ||
767 | which we can break down into: | 767 | which we can break down into: |
768 | 768 | ||
769 | X = s | 769 | X = s |
770 | -------- | 770 | -------- |
771 | R * f(p) | 771 | R * f(p) |
772 | 772 | ||
773 | where f(p) = sqrt(2 * p / 3) + (12 * sqrt(3 * p / 8) * p * (1 + 32 * p * p)) | 773 | where f(p) = sqrt(2 * p / 3) + (12 * sqrt(3 * p / 8) * p * (1 + 32 * p * p)) |
774 | 774 | ||
775 | Function parameters: | 775 | Function parameters: |
776 | s - bytes | 776 | s - bytes |
777 | R - RTT in usecs | 777 | R - RTT in usecs |
778 | p - loss rate (decimal fraction multiplied by 1,000,000) | 778 | p - loss rate (decimal fraction multiplied by 1,000,000) |
779 | 779 | ||
780 | Returns Xcalc in bytes per second | 780 | Returns Xcalc in bytes per second |
781 | 781 | ||
782 | DON'T alter this code unless you run test cases against it as the code | 782 | DON'T alter this code unless you run test cases against it as the code |
783 | has been manipulated to stop underflow/overlow. | 783 | has been manipulated to stop underflow/overlow. |
784 | 784 | ||
785 | */ | 785 | */ |
786 | static u32 ccid3_calc_x(u16 s, u32 R, u32 p) | 786 | static u32 ccid3_calc_x(u16 s, u32 R, u32 p) |
787 | { | 787 | { |
788 | int index; | 788 | int index; |
789 | u32 f; | 789 | u32 f; |
790 | u64 tmp1, tmp2; | 790 | u64 tmp1, tmp2; |
791 | 791 | ||
792 | if (p < CALCX_SPLIT) | 792 | if (p < CALCX_SPLIT) |
793 | index = (p / (CALCX_SPLIT / CALCX_ARRSIZE)) - 1; | 793 | index = (p / (CALCX_SPLIT / CALCX_ARRSIZE)) - 1; |
794 | else | 794 | else |
795 | index = (p / (1000000 / CALCX_ARRSIZE)) - 1; | 795 | index = (p / (1000000 / CALCX_ARRSIZE)) - 1; |
796 | 796 | ||
797 | if (index < 0) | 797 | if (index < 0) |
798 | /* p should be 0 unless there is a bug in my code */ | 798 | /* p should be 0 unless there is a bug in my code */ |
799 | index = 0; | 799 | index = 0; |
800 | 800 | ||
801 | if (R == 0) | 801 | if (R == 0) |
802 | R = 1; /* RTT can't be zero or else divide by zero */ | 802 | R = 1; /* RTT can't be zero or else divide by zero */ |
803 | 803 | ||
804 | BUG_ON(index >= CALCX_ARRSIZE); | 804 | BUG_ON(index >= CALCX_ARRSIZE); |
805 | 805 | ||
806 | if (p >= CALCX_SPLIT) | 806 | if (p >= CALCX_SPLIT) |
807 | f = calcx_lookup[index][0]; | 807 | f = calcx_lookup[index][0]; |
808 | else | 808 | else |
809 | f = calcx_lookup[index][1]; | 809 | f = calcx_lookup[index][1]; |
810 | 810 | ||
811 | tmp1 = ((u64)s * 100000000); | 811 | tmp1 = ((u64)s * 100000000); |
812 | tmp2 = ((u64)R * (u64)f); | 812 | tmp2 = ((u64)R * (u64)f); |
813 | do_div(tmp2,10000); | 813 | do_div(tmp2,10000); |
814 | do_div(tmp1,tmp2); | 814 | do_div(tmp1,tmp2); |
815 | /* don't alter above math unless you test due to overflow on 32 bit */ | 815 | /* don't alter above math unless you test due to overflow on 32 bit */ |
816 | 816 | ||
817 | return (u32)tmp1; | 817 | return (u32)tmp1; |
818 | } | 818 | } |
819 | 819 | ||
820 | /* Calculate new t_ipi (inter packet interval) by t_ipi = s / X_inst */ | 820 | /* Calculate new t_ipi (inter packet interval) by t_ipi = s / X_inst */ |
821 | static inline void ccid3_calc_new_t_ipi(struct ccid3_hc_tx_sock *hctx) | 821 | static inline void ccid3_calc_new_t_ipi(struct ccid3_hc_tx_sock *hctx) |
822 | { | 822 | { |
823 | if (hctx->ccid3hctx_state == TFRC_SSTATE_NO_FBACK) | 823 | if (hctx->ccid3hctx_state == TFRC_SSTATE_NO_FBACK) |
824 | return; | 824 | return; |
825 | /* if no feedback spec says t_ipi is 1 second (set elsewhere and then | 825 | /* if no feedback spec says t_ipi is 1 second (set elsewhere and then |
826 | * doubles after every no feedback timer (separate function) */ | 826 | * doubles after every no feedback timer (separate function) */ |
827 | 827 | ||
828 | if (hctx->ccid3hctx_x < 10) { | 828 | if (hctx->ccid3hctx_x < 10) { |
829 | ccid3_pr_debug("ccid3_calc_new_t_ipi - ccid3hctx_x < 10\n"); | 829 | ccid3_pr_debug("ccid3_calc_new_t_ipi - ccid3hctx_x < 10\n"); |
830 | hctx->ccid3hctx_x = 10; | 830 | hctx->ccid3hctx_x = 10; |
831 | } | 831 | } |
832 | hctx->ccid3hctx_t_ipi = (hctx->ccid3hctx_s * 100000) | 832 | hctx->ccid3hctx_t_ipi = (hctx->ccid3hctx_s * 100000) |
833 | / (hctx->ccid3hctx_x / 10); | 833 | / (hctx->ccid3hctx_x / 10); |
834 | /* reason for above maths with 10 in there is to avoid 32 bit | 834 | /* reason for above maths with 10 in there is to avoid 32 bit |
835 | * overflow for jumbo packets */ | 835 | * overflow for jumbo packets */ |
836 | 836 | ||
837 | } | 837 | } |
838 | 838 | ||
839 | /* Calculate new delta by delta = min(t_ipi / 2, t_gran / 2) */ | 839 | /* Calculate new delta by delta = min(t_ipi / 2, t_gran / 2) */ |
840 | static inline void ccid3_calc_new_delta(struct ccid3_hc_tx_sock *hctx) | 840 | static inline void ccid3_calc_new_delta(struct ccid3_hc_tx_sock *hctx) |
841 | { | 841 | { |
842 | hctx->ccid3hctx_delta = min_t(u32, hctx->ccid3hctx_t_ipi / 2, TFRC_OPSYS_HALF_TIME_GRAN); | 842 | hctx->ccid3hctx_delta = min_t(u32, hctx->ccid3hctx_t_ipi / 2, TFRC_OPSYS_HALF_TIME_GRAN); |
843 | 843 | ||
844 | } | 844 | } |
845 | 845 | ||
846 | /* | 846 | /* |
847 | * Update X by | 847 | * Update X by |
848 | * If (p > 0) | 848 | * If (p > 0) |
849 | * x_calc = calcX(s, R, p); | 849 | * x_calc = calcX(s, R, p); |
850 | * X = max(min(X_calc, 2 * X_recv), s / t_mbi); | 850 | * X = max(min(X_calc, 2 * X_recv), s / t_mbi); |
851 | * Else | 851 | * Else |
852 | * If (now - tld >= R) | 852 | * If (now - tld >= R) |
853 | * X = max(min(2 * X, 2 * X_recv), s / R); | 853 | * X = max(min(2 * X, 2 * X_recv), s / R); |
854 | * tld = now; | 854 | * tld = now; |
855 | */ | 855 | */ |
856 | static void ccid3_hc_tx_update_x(struct sock *sk) | 856 | static void ccid3_hc_tx_update_x(struct sock *sk) |
857 | { | 857 | { |
858 | struct dccp_sock *dp = dccp_sk(sk); | 858 | struct dccp_sock *dp = dccp_sk(sk); |
859 | struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private; | 859 | struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private; |
860 | 860 | ||
861 | if (hctx->ccid3hctx_p >= TFRC_SMALLEST_P) { /* to avoid large error in calcX */ | 861 | if (hctx->ccid3hctx_p >= TFRC_SMALLEST_P) { /* to avoid large error in calcX */ |
862 | hctx->ccid3hctx_x_calc = ccid3_calc_x(hctx->ccid3hctx_s, | 862 | hctx->ccid3hctx_x_calc = ccid3_calc_x(hctx->ccid3hctx_s, |
863 | hctx->ccid3hctx_rtt, | 863 | hctx->ccid3hctx_rtt, |
864 | hctx->ccid3hctx_p); | 864 | hctx->ccid3hctx_p); |
865 | hctx->ccid3hctx_x = max_t(u32, min_t(u32, hctx->ccid3hctx_x_calc, 2 * hctx->ccid3hctx_x_recv), | 865 | hctx->ccid3hctx_x = max_t(u32, min_t(u32, hctx->ccid3hctx_x_calc, 2 * hctx->ccid3hctx_x_recv), |
866 | hctx->ccid3hctx_s / TFRC_MAX_BACK_OFF_TIME); | 866 | hctx->ccid3hctx_s / TFRC_MAX_BACK_OFF_TIME); |
867 | } else if (now_delta(hctx->ccid3hctx_t_ld) >= hctx->ccid3hctx_rtt) { | 867 | } else if (now_delta(hctx->ccid3hctx_t_ld) >= hctx->ccid3hctx_rtt) { |
868 | u32 rtt = hctx->ccid3hctx_rtt; | 868 | u32 rtt = hctx->ccid3hctx_rtt; |
869 | if (rtt < 10) { | 869 | if (rtt < 10) { |
870 | rtt = 10; | 870 | rtt = 10; |
871 | } /* avoid divide by zero below */ | 871 | } /* avoid divide by zero below */ |
872 | 872 | ||
873 | hctx->ccid3hctx_x = max_t(u32, min_t(u32, 2 * hctx->ccid3hctx_x_recv, 2 * hctx->ccid3hctx_x), | 873 | hctx->ccid3hctx_x = max_t(u32, min_t(u32, 2 * hctx->ccid3hctx_x_recv, 2 * hctx->ccid3hctx_x), |
874 | (hctx->ccid3hctx_s * 100000) / (rtt / 10)); | 874 | (hctx->ccid3hctx_s * 100000) / (rtt / 10)); |
875 | /* Using 100000 and 10 to avoid 32 bit overflow for jumbo frames */ | 875 | /* Using 100000 and 10 to avoid 32 bit overflow for jumbo frames */ |
876 | do_gettimeofday(&hctx->ccid3hctx_t_ld); | 876 | do_gettimeofday(&hctx->ccid3hctx_t_ld); |
877 | } | 877 | } |
878 | 878 | ||
879 | if (hctx->ccid3hctx_x == 0) { | 879 | if (hctx->ccid3hctx_x == 0) { |
880 | ccid3_pr_debug("ccid3hctx_x = 0!\n"); | 880 | ccid3_pr_debug("ccid3hctx_x = 0!\n"); |
881 | hctx->ccid3hctx_x = 1; | 881 | hctx->ccid3hctx_x = 1; |
882 | } | 882 | } |
883 | } | 883 | } |
884 | 884 | ||
885 | static void ccid3_hc_tx_no_feedback_timer(unsigned long data) | 885 | static void ccid3_hc_tx_no_feedback_timer(unsigned long data) |
886 | { | 886 | { |
887 | struct sock *sk = (struct sock *)data; | 887 | struct sock *sk = (struct sock *)data; |
888 | struct dccp_sock *dp = dccp_sk(sk); | 888 | struct dccp_sock *dp = dccp_sk(sk); |
889 | unsigned long next_tmout = 0; | 889 | unsigned long next_tmout = 0; |
890 | struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private; | 890 | struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private; |
891 | u32 rtt; | 891 | u32 rtt; |
892 | 892 | ||
893 | bh_lock_sock(sk); | 893 | bh_lock_sock(sk); |
894 | if (sock_owned_by_user(sk)) { | 894 | if (sock_owned_by_user(sk)) { |
895 | /* Try again later. */ | 895 | /* Try again later. */ |
896 | /* XXX: set some sensible MIB */ | 896 | /* XXX: set some sensible MIB */ |
897 | sk_reset_timer(sk, &hctx->ccid3hctx_no_feedback_timer, jiffies + HZ / 5); | 897 | sk_reset_timer(sk, &hctx->ccid3hctx_no_feedback_timer, jiffies + HZ / 5); |
898 | goto out; | 898 | goto out; |
899 | } | 899 | } |
900 | 900 | ||
901 | ccid3_pr_debug("%s, sk=%p, state=%s\n", dccp_role(sk), sk, | 901 | ccid3_pr_debug("%s, sk=%p, state=%s\n", dccp_role(sk), sk, |
902 | ccid3_tx_state_name(hctx->ccid3hctx_state)); | 902 | ccid3_tx_state_name(hctx->ccid3hctx_state)); |
903 | 903 | ||
904 | if (hctx->ccid3hctx_x < 10) { | 904 | if (hctx->ccid3hctx_x < 10) { |
905 | ccid3_pr_debug("TFRC_SSTATE_NO_FBACK ccid3hctx_x < 10\n"); | 905 | ccid3_pr_debug("TFRC_SSTATE_NO_FBACK ccid3hctx_x < 10\n"); |
906 | hctx->ccid3hctx_x = 10; | 906 | hctx->ccid3hctx_x = 10; |
907 | } | 907 | } |
908 | 908 | ||
909 | switch (hctx->ccid3hctx_state) { | 909 | switch (hctx->ccid3hctx_state) { |
910 | case TFRC_SSTATE_TERM: | 910 | case TFRC_SSTATE_TERM: |
911 | goto out; | 911 | goto out; |
912 | case TFRC_SSTATE_NO_FBACK: | 912 | case TFRC_SSTATE_NO_FBACK: |
913 | /* Halve send rate */ | 913 | /* Halve send rate */ |
914 | hctx->ccid3hctx_x /= 2; | 914 | hctx->ccid3hctx_x /= 2; |
915 | if (hctx->ccid3hctx_x < (hctx->ccid3hctx_s / TFRC_MAX_BACK_OFF_TIME)) | 915 | if (hctx->ccid3hctx_x < (hctx->ccid3hctx_s / TFRC_MAX_BACK_OFF_TIME)) |
916 | hctx->ccid3hctx_x = hctx->ccid3hctx_s / TFRC_MAX_BACK_OFF_TIME; | 916 | hctx->ccid3hctx_x = hctx->ccid3hctx_s / TFRC_MAX_BACK_OFF_TIME; |
917 | 917 | ||
918 | ccid3_pr_debug("%s, sk=%p, state=%s, updated tx rate to %d bytes/s\n", | 918 | ccid3_pr_debug("%s, sk=%p, state=%s, updated tx rate to %d bytes/s\n", |
919 | dccp_role(sk), sk, ccid3_tx_state_name(hctx->ccid3hctx_state), | 919 | dccp_role(sk), sk, ccid3_tx_state_name(hctx->ccid3hctx_state), |
920 | hctx->ccid3hctx_x); | 920 | hctx->ccid3hctx_x); |
921 | next_tmout = max_t(u32, 2 * (hctx->ccid3hctx_s * 100000) | 921 | next_tmout = max_t(u32, 2 * (hctx->ccid3hctx_s * 100000) |
922 | / (hctx->ccid3hctx_x / 10), TFRC_INITIAL_TIMEOUT); | 922 | / (hctx->ccid3hctx_x / 10), TFRC_INITIAL_TIMEOUT); |
923 | /* do above maths with 100000 and 10 to prevent overflow on 32 bit */ | 923 | /* do above maths with 100000 and 10 to prevent overflow on 32 bit */ |
924 | /* FIXME - not sure above calculation is correct. See section 5 of CCID3 11 | 924 | /* FIXME - not sure above calculation is correct. See section 5 of CCID3 11 |
925 | * should adjust tx_t_ipi and double that to achieve it really */ | 925 | * should adjust tx_t_ipi and double that to achieve it really */ |
926 | break; | 926 | break; |
927 | case TFRC_SSTATE_FBACK: | 927 | case TFRC_SSTATE_FBACK: |
928 | /* Check if IDLE since last timeout and recv rate is less than 4 packets per RTT */ | 928 | /* Check if IDLE since last timeout and recv rate is less than 4 packets per RTT */ |
929 | rtt = hctx->ccid3hctx_rtt; | 929 | rtt = hctx->ccid3hctx_rtt; |
930 | if (rtt < 10) | 930 | if (rtt < 10) |
931 | rtt = 10; | 931 | rtt = 10; |
932 | /* stop divide by zero below */ | 932 | /* stop divide by zero below */ |
933 | if (!hctx->ccid3hctx_idle || (hctx->ccid3hctx_x_recv >= | 933 | if (!hctx->ccid3hctx_idle || (hctx->ccid3hctx_x_recv >= |
934 | 4 * (hctx->ccid3hctx_s * 100000) / (rtt / 10))) { | 934 | 4 * (hctx->ccid3hctx_s * 100000) / (rtt / 10))) { |
935 | ccid3_pr_debug("%s, sk=%p, state=%s, not idle\n", dccp_role(sk), sk, | 935 | ccid3_pr_debug("%s, sk=%p, state=%s, not idle\n", dccp_role(sk), sk, |
936 | ccid3_tx_state_name(hctx->ccid3hctx_state)); | 936 | ccid3_tx_state_name(hctx->ccid3hctx_state)); |
937 | /* Halve sending rate */ | 937 | /* Halve sending rate */ |
938 | 938 | ||
939 | /* If (X_calc > 2 * X_recv) | 939 | /* If (X_calc > 2 * X_recv) |
940 | * X_recv = max(X_recv / 2, s / (2 * t_mbi)); | 940 | * X_recv = max(X_recv / 2, s / (2 * t_mbi)); |
941 | * Else | 941 | * Else |
942 | * X_recv = X_calc / 4; | 942 | * X_recv = X_calc / 4; |
943 | */ | 943 | */ |
944 | BUG_ON(hctx->ccid3hctx_p >= TFRC_SMALLEST_P && hctx->ccid3hctx_x_calc == 0); | 944 | BUG_ON(hctx->ccid3hctx_p >= TFRC_SMALLEST_P && hctx->ccid3hctx_x_calc == 0); |
945 | 945 | ||
946 | /* check also if p is zero -> x_calc is infinity? */ | 946 | /* check also if p is zero -> x_calc is infinity? */ |
947 | if (hctx->ccid3hctx_p < TFRC_SMALLEST_P || | 947 | if (hctx->ccid3hctx_p < TFRC_SMALLEST_P || |
948 | hctx->ccid3hctx_x_calc > 2 * hctx->ccid3hctx_x_recv) | 948 | hctx->ccid3hctx_x_calc > 2 * hctx->ccid3hctx_x_recv) |
949 | hctx->ccid3hctx_x_recv = max_t(u32, hctx->ccid3hctx_x_recv / 2, | 949 | hctx->ccid3hctx_x_recv = max_t(u32, hctx->ccid3hctx_x_recv / 2, |
950 | hctx->ccid3hctx_s / (2 * TFRC_MAX_BACK_OFF_TIME)); | 950 | hctx->ccid3hctx_s / (2 * TFRC_MAX_BACK_OFF_TIME)); |
951 | else | 951 | else |
952 | hctx->ccid3hctx_x_recv = hctx->ccid3hctx_x_calc / 4; | 952 | hctx->ccid3hctx_x_recv = hctx->ccid3hctx_x_calc / 4; |
953 | 953 | ||
954 | /* Update sending rate */ | 954 | /* Update sending rate */ |
955 | ccid3_hc_tx_update_x(sk); | 955 | ccid3_hc_tx_update_x(sk); |
956 | } | 956 | } |
957 | if (hctx->ccid3hctx_x == 0) { | 957 | if (hctx->ccid3hctx_x == 0) { |
958 | ccid3_pr_debug("TFRC_SSTATE_FBACK ccid3hctx_x = 0!\n"); | 958 | ccid3_pr_debug("TFRC_SSTATE_FBACK ccid3hctx_x = 0!\n"); |
959 | hctx->ccid3hctx_x = 10; | 959 | hctx->ccid3hctx_x = 10; |
960 | } | 960 | } |
961 | /* Schedule no feedback timer to expire in max(4 * R, 2 * s / X) */ | 961 | /* Schedule no feedback timer to expire in max(4 * R, 2 * s / X) */ |
962 | next_tmout = max_t(u32, inet_csk(sk)->icsk_rto, | 962 | next_tmout = max_t(u32, inet_csk(sk)->icsk_rto, |
963 | 2 * (hctx->ccid3hctx_s * 100000) / (hctx->ccid3hctx_x / 10)); | 963 | 2 * (hctx->ccid3hctx_s * 100000) / (hctx->ccid3hctx_x / 10)); |
964 | break; | 964 | break; |
965 | default: | 965 | default: |
966 | printk(KERN_CRIT "%s: %s, sk=%p, Illegal state (%d)!\n", | 966 | printk(KERN_CRIT "%s: %s, sk=%p, Illegal state (%d)!\n", |
967 | __FUNCTION__, dccp_role(sk), sk, hctx->ccid3hctx_state); | 967 | __FUNCTION__, dccp_role(sk), sk, hctx->ccid3hctx_state); |
968 | dump_stack(); | 968 | dump_stack(); |
969 | goto out; | 969 | goto out; |
970 | } | 970 | } |
971 | 971 | ||
972 | sk_reset_timer(sk, &hctx->ccid3hctx_no_feedback_timer, | 972 | sk_reset_timer(sk, &hctx->ccid3hctx_no_feedback_timer, |
973 | jiffies + max_t(u32, 1, usecs_to_jiffies(next_tmout))); | 973 | jiffies + max_t(u32, 1, usecs_to_jiffies(next_tmout))); |
974 | hctx->ccid3hctx_idle = 1; | 974 | hctx->ccid3hctx_idle = 1; |
975 | out: | 975 | out: |
976 | bh_unlock_sock(sk); | 976 | bh_unlock_sock(sk); |
977 | sock_put(sk); | 977 | sock_put(sk); |
978 | } | 978 | } |
979 | 979 | ||
980 | static int ccid3_hc_tx_send_packet(struct sock *sk, struct sk_buff *skb, | 980 | static int ccid3_hc_tx_send_packet(struct sock *sk, |
981 | int len, long *delay) | 981 | struct sk_buff *skb, int len) |
982 | { | 982 | { |
983 | struct dccp_sock *dp = dccp_sk(sk); | 983 | struct dccp_sock *dp = dccp_sk(sk); |
984 | struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private; | 984 | struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private; |
985 | struct ccid3_tx_hist_entry *new_packet = NULL; | 985 | struct ccid3_tx_hist_entry *new_packet = NULL; |
986 | struct timeval now; | 986 | struct timeval now; |
987 | long delay; | ||
987 | int rc = -ENOTCONN; | 988 | int rc = -ENOTCONN; |
988 | 989 | ||
989 | // ccid3_pr_debug("%s, sk=%p, skb=%p, len=%d\n", dccp_role(sk), sk, skb, len); | 990 | // ccid3_pr_debug("%s, sk=%p, skb=%p, len=%d\n", dccp_role(sk), sk, skb, len); |
990 | /* | 991 | /* |
991 | * check if pure ACK or Terminating */ | 992 | * check if pure ACK or Terminating */ |
992 | /* XXX: We only call this function for DATA and DATAACK, on, these packets can have | 993 | /* XXX: We only call this function for DATA and DATAACK, on, these packets can have |
993 | * zero length, but why the comment about "pure ACK"? | 994 | * zero length, but why the comment about "pure ACK"? |
994 | */ | 995 | */ |
995 | if (hctx == NULL || len == 0 || hctx->ccid3hctx_state == TFRC_SSTATE_TERM) | 996 | if (hctx == NULL || len == 0 || hctx->ccid3hctx_state == TFRC_SSTATE_TERM) |
996 | goto out; | 997 | goto out; |
997 | 998 | ||
998 | /* See if last packet allocated was not sent */ | 999 | /* See if last packet allocated was not sent */ |
999 | if (!list_empty(&hctx->ccid3hctx_hist)) | 1000 | if (!list_empty(&hctx->ccid3hctx_hist)) |
1000 | new_packet = list_entry(hctx->ccid3hctx_hist.next, | 1001 | new_packet = list_entry(hctx->ccid3hctx_hist.next, |
1001 | struct ccid3_tx_hist_entry, ccid3htx_node); | 1002 | struct ccid3_tx_hist_entry, ccid3htx_node); |
1002 | 1003 | ||
1003 | if (new_packet == NULL || new_packet->ccid3htx_sent) { | 1004 | if (new_packet == NULL || new_packet->ccid3htx_sent) { |
1004 | new_packet = ccid3_tx_hist_entry_new(SLAB_ATOMIC); | 1005 | new_packet = ccid3_tx_hist_entry_new(SLAB_ATOMIC); |
1005 | 1006 | ||
1006 | rc = -ENOBUFS; | 1007 | rc = -ENOBUFS; |
1007 | if (new_packet == NULL) { | 1008 | if (new_packet == NULL) { |
1008 | ccid3_pr_debug("%s, sk=%p, not enough mem to add " | 1009 | ccid3_pr_debug("%s, sk=%p, not enough mem to add " |
1009 | "to history, send refused\n", dccp_role(sk), sk); | 1010 | "to history, send refused\n", dccp_role(sk), sk); |
1010 | goto out; | 1011 | goto out; |
1011 | } | 1012 | } |
1012 | 1013 | ||
1013 | list_add(&new_packet->ccid3htx_node, &hctx->ccid3hctx_hist); | 1014 | list_add(&new_packet->ccid3htx_node, &hctx->ccid3hctx_hist); |
1014 | } | 1015 | } |
1015 | 1016 | ||
1016 | do_gettimeofday(&now); | 1017 | do_gettimeofday(&now); |
1017 | 1018 | ||
1018 | switch (hctx->ccid3hctx_state) { | 1019 | switch (hctx->ccid3hctx_state) { |
1019 | case TFRC_SSTATE_NO_SENT: | 1020 | case TFRC_SSTATE_NO_SENT: |
1020 | ccid3_pr_debug("%s, sk=%p, first packet(%llu)\n", dccp_role(sk), sk, | 1021 | ccid3_pr_debug("%s, sk=%p, first packet(%llu)\n", dccp_role(sk), sk, |
1021 | dp->dccps_gss); | 1022 | dp->dccps_gss); |
1022 | 1023 | ||
1023 | hctx->ccid3hctx_no_feedback_timer.function = ccid3_hc_tx_no_feedback_timer; | 1024 | hctx->ccid3hctx_no_feedback_timer.function = ccid3_hc_tx_no_feedback_timer; |
1024 | hctx->ccid3hctx_no_feedback_timer.data = (unsigned long)sk; | 1025 | hctx->ccid3hctx_no_feedback_timer.data = (unsigned long)sk; |
1025 | sk_reset_timer(sk, &hctx->ccid3hctx_no_feedback_timer, jiffies + usecs_to_jiffies(TFRC_INITIAL_TIMEOUT)); | 1026 | sk_reset_timer(sk, &hctx->ccid3hctx_no_feedback_timer, jiffies + usecs_to_jiffies(TFRC_INITIAL_TIMEOUT)); |
1026 | hctx->ccid3hctx_last_win_count = 0; | 1027 | hctx->ccid3hctx_last_win_count = 0; |
1027 | hctx->ccid3hctx_t_last_win_count = now; | 1028 | hctx->ccid3hctx_t_last_win_count = now; |
1028 | ccid3_hc_tx_set_state(sk, TFRC_SSTATE_NO_FBACK); | 1029 | ccid3_hc_tx_set_state(sk, TFRC_SSTATE_NO_FBACK); |
1029 | hctx->ccid3hctx_t_ipi = TFRC_INITIAL_TIMEOUT; | 1030 | hctx->ccid3hctx_t_ipi = TFRC_INITIAL_TIMEOUT; |
1030 | 1031 | ||
1031 | /* Set nominal send time for initial packet */ | 1032 | /* Set nominal send time for initial packet */ |
1032 | hctx->ccid3hctx_t_nom = now; | 1033 | hctx->ccid3hctx_t_nom = now; |
1033 | (hctx->ccid3hctx_t_nom).tv_usec += hctx->ccid3hctx_t_ipi; | 1034 | (hctx->ccid3hctx_t_nom).tv_usec += hctx->ccid3hctx_t_ipi; |
1034 | timeval_fix(&(hctx->ccid3hctx_t_nom)); | 1035 | timeval_fix(&(hctx->ccid3hctx_t_nom)); |
1035 | ccid3_calc_new_delta(hctx); | 1036 | ccid3_calc_new_delta(hctx); |
1036 | rc = 0; | 1037 | rc = 0; |
1037 | break; | 1038 | break; |
1038 | case TFRC_SSTATE_NO_FBACK: | 1039 | case TFRC_SSTATE_NO_FBACK: |
1039 | case TFRC_SSTATE_FBACK: | 1040 | case TFRC_SSTATE_FBACK: |
1040 | *delay = (now_delta(hctx->ccid3hctx_t_nom) - hctx->ccid3hctx_delta); | 1041 | delay = (now_delta(hctx->ccid3hctx_t_nom) - hctx->ccid3hctx_delta); |
1041 | ccid3_pr_debug("send_packet delay=%ld\n",*delay); | 1042 | ccid3_pr_debug("send_packet delay=%ld\n", delay); |
1042 | *delay /= -1000; | 1043 | delay /= -1000; |
1043 | /* divide by -1000 is to convert to ms and get sign right */ | 1044 | /* divide by -1000 is to convert to ms and get sign right */ |
1044 | rc = *delay > 0 ? -EAGAIN : 0; | 1045 | rc = delay > 0 ? -EAGAIN : 0; |
1045 | break; | 1046 | break; |
1046 | default: | 1047 | default: |
1047 | printk(KERN_CRIT "%s: %s, sk=%p, Illegal state (%d)!\n", | 1048 | printk(KERN_CRIT "%s: %s, sk=%p, Illegal state (%d)!\n", |
1048 | __FUNCTION__, dccp_role(sk), sk, hctx->ccid3hctx_state); | 1049 | __FUNCTION__, dccp_role(sk), sk, hctx->ccid3hctx_state); |
1049 | dump_stack(); | 1050 | dump_stack(); |
1050 | rc = -EINVAL; | 1051 | rc = -EINVAL; |
1051 | break; | 1052 | break; |
1052 | } | 1053 | } |
1053 | 1054 | ||
1054 | /* Can we send? if so add options and add to packet history */ | 1055 | /* Can we send? if so add options and add to packet history */ |
1055 | if (rc == 0) | 1056 | if (rc == 0) |
1056 | new_packet->ccid3htx_win_count = DCCP_SKB_CB(skb)->dccpd_ccval = hctx->ccid3hctx_last_win_count; | 1057 | new_packet->ccid3htx_win_count = DCCP_SKB_CB(skb)->dccpd_ccval = hctx->ccid3hctx_last_win_count; |
1057 | out: | 1058 | out: |
1058 | return rc; | 1059 | return rc; |
1059 | } | 1060 | } |
1060 | 1061 | ||
1061 | static void ccid3_hc_tx_packet_sent(struct sock *sk, int more, int len) | 1062 | static void ccid3_hc_tx_packet_sent(struct sock *sk, int more, int len) |
1062 | { | 1063 | { |
1063 | struct dccp_sock *dp = dccp_sk(sk); | 1064 | struct dccp_sock *dp = dccp_sk(sk); |
1064 | struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private; | 1065 | struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private; |
1065 | struct ccid3_tx_hist_entry *packet = NULL; | 1066 | struct ccid3_tx_hist_entry *packet = NULL; |
1066 | struct timeval now; | 1067 | struct timeval now; |
1067 | 1068 | ||
1068 | // ccid3_pr_debug("%s, sk=%p, more=%d, len=%d\n", dccp_role(sk), sk, more, len); | 1069 | // ccid3_pr_debug("%s, sk=%p, more=%d, len=%d\n", dccp_role(sk), sk, more, len); |
1069 | BUG_ON(hctx == NULL); | 1070 | BUG_ON(hctx == NULL); |
1070 | 1071 | ||
1071 | if (hctx->ccid3hctx_state == TFRC_SSTATE_TERM) { | 1072 | if (hctx->ccid3hctx_state == TFRC_SSTATE_TERM) { |
1072 | ccid3_pr_debug("%s, sk=%p, while state is TFRC_SSTATE_TERM!\n", | 1073 | ccid3_pr_debug("%s, sk=%p, while state is TFRC_SSTATE_TERM!\n", |
1073 | dccp_role(sk), sk); | 1074 | dccp_role(sk), sk); |
1074 | return; | 1075 | return; |
1075 | } | 1076 | } |
1076 | 1077 | ||
1077 | do_gettimeofday(&now); | 1078 | do_gettimeofday(&now); |
1078 | 1079 | ||
1079 | /* check if we have sent a data packet */ | 1080 | /* check if we have sent a data packet */ |
1080 | if (len > 0) { | 1081 | if (len > 0) { |
1081 | unsigned long quarter_rtt; | 1082 | unsigned long quarter_rtt; |
1082 | 1083 | ||
1083 | if (list_empty(&hctx->ccid3hctx_hist)) { | 1084 | if (list_empty(&hctx->ccid3hctx_hist)) { |
1084 | printk(KERN_CRIT "%s: packet doesn't exists in history!\n", __FUNCTION__); | 1085 | printk(KERN_CRIT "%s: packet doesn't exists in history!\n", __FUNCTION__); |
1085 | return; | 1086 | return; |
1086 | } | 1087 | } |
1087 | packet = list_entry(hctx->ccid3hctx_hist.next, struct ccid3_tx_hist_entry, ccid3htx_node); | 1088 | packet = list_entry(hctx->ccid3hctx_hist.next, struct ccid3_tx_hist_entry, ccid3htx_node); |
1088 | if (packet->ccid3htx_sent) { | 1089 | if (packet->ccid3htx_sent) { |
1089 | printk(KERN_CRIT "%s: no unsent packet in history!\n", __FUNCTION__); | 1090 | printk(KERN_CRIT "%s: no unsent packet in history!\n", __FUNCTION__); |
1090 | return; | 1091 | return; |
1091 | } | 1092 | } |
1092 | packet->ccid3htx_tstamp = now; | 1093 | packet->ccid3htx_tstamp = now; |
1093 | packet->ccid3htx_seqno = dp->dccps_gss; | 1094 | packet->ccid3htx_seqno = dp->dccps_gss; |
1094 | // ccid3_pr_debug("%s, sk=%p, seqno=%llu inserted!\n", dccp_role(sk), sk, packet->ccid3htx_seqno); | 1095 | // ccid3_pr_debug("%s, sk=%p, seqno=%llu inserted!\n", dccp_role(sk), sk, packet->ccid3htx_seqno); |
1095 | 1096 | ||
1096 | /* | 1097 | /* |
1097 | * Check if win_count have changed */ | 1098 | * Check if win_count have changed */ |
1098 | /* COMPLIANCE_BEGIN | 1099 | /* COMPLIANCE_BEGIN |
1099 | * Algorithm in "8.1. Window Counter Valuer" in draft-ietf-dccp-ccid3-11.txt | 1100 | * Algorithm in "8.1. Window Counter Valuer" in draft-ietf-dccp-ccid3-11.txt |
1100 | */ | 1101 | */ |
1101 | quarter_rtt = now_delta(hctx->ccid3hctx_t_last_win_count) / (hctx->ccid3hctx_rtt / 4); | 1102 | quarter_rtt = now_delta(hctx->ccid3hctx_t_last_win_count) / (hctx->ccid3hctx_rtt / 4); |
1102 | if (quarter_rtt > 0) { | 1103 | if (quarter_rtt > 0) { |
1103 | hctx->ccid3hctx_t_last_win_count = now; | 1104 | hctx->ccid3hctx_t_last_win_count = now; |
1104 | hctx->ccid3hctx_last_win_count = (hctx->ccid3hctx_last_win_count + | 1105 | hctx->ccid3hctx_last_win_count = (hctx->ccid3hctx_last_win_count + |
1105 | min_t(unsigned long, quarter_rtt, 5)) % 16; | 1106 | min_t(unsigned long, quarter_rtt, 5)) % 16; |
1106 | ccid3_pr_debug("%s, sk=%p, window changed from %u to %u!\n", | 1107 | ccid3_pr_debug("%s, sk=%p, window changed from %u to %u!\n", |
1107 | dccp_role(sk), sk, | 1108 | dccp_role(sk), sk, |
1108 | packet->ccid3htx_win_count, | 1109 | packet->ccid3htx_win_count, |
1109 | hctx->ccid3hctx_last_win_count); | 1110 | hctx->ccid3hctx_last_win_count); |
1110 | } | 1111 | } |
1111 | /* COMPLIANCE_END */ | 1112 | /* COMPLIANCE_END */ |
1112 | #if 0 | 1113 | #if 0 |
1113 | ccid3_pr_debug("%s, sk=%p, packet sent (%llu,%u)\n", | 1114 | ccid3_pr_debug("%s, sk=%p, packet sent (%llu,%u)\n", |
1114 | dccp_role(sk), sk, | 1115 | dccp_role(sk), sk, |
1115 | packet->ccid3htx_seqno, | 1116 | packet->ccid3htx_seqno, |
1116 | packet->ccid3htx_win_count); | 1117 | packet->ccid3htx_win_count); |
1117 | #endif | 1118 | #endif |
1118 | hctx->ccid3hctx_idle = 0; | 1119 | hctx->ccid3hctx_idle = 0; |
1119 | packet->ccid3htx_sent = 1; | 1120 | packet->ccid3htx_sent = 1; |
1120 | } else | 1121 | } else |
1121 | ccid3_pr_debug("%s, sk=%p, seqno=%llu NOT inserted!\n", | 1122 | ccid3_pr_debug("%s, sk=%p, seqno=%llu NOT inserted!\n", |
1122 | dccp_role(sk), sk, dp->dccps_gss); | 1123 | dccp_role(sk), sk, dp->dccps_gss); |
1123 | 1124 | ||
1124 | switch (hctx->ccid3hctx_state) { | 1125 | switch (hctx->ccid3hctx_state) { |
1125 | case TFRC_SSTATE_NO_SENT: | 1126 | case TFRC_SSTATE_NO_SENT: |
1126 | /* if first wasn't pure ack */ | 1127 | /* if first wasn't pure ack */ |
1127 | if (len != 0) | 1128 | if (len != 0) |
1128 | printk(KERN_CRIT "%s: %s, First packet sent is noted as a data packet\n", | 1129 | printk(KERN_CRIT "%s: %s, First packet sent is noted as a data packet\n", |
1129 | __FUNCTION__, dccp_role(sk)); | 1130 | __FUNCTION__, dccp_role(sk)); |
1130 | return; | 1131 | return; |
1131 | case TFRC_SSTATE_NO_FBACK: | 1132 | case TFRC_SSTATE_NO_FBACK: |
1132 | case TFRC_SSTATE_FBACK: | 1133 | case TFRC_SSTATE_FBACK: |
1133 | if (len > 0) { | 1134 | if (len > 0) { |
1134 | hctx->ccid3hctx_t_nom = now; | 1135 | hctx->ccid3hctx_t_nom = now; |
1135 | ccid3_calc_new_t_ipi(hctx); | 1136 | ccid3_calc_new_t_ipi(hctx); |
1136 | ccid3_calc_new_delta(hctx); | 1137 | ccid3_calc_new_delta(hctx); |
1137 | (hctx->ccid3hctx_t_nom).tv_usec += hctx->ccid3hctx_t_ipi; | 1138 | (hctx->ccid3hctx_t_nom).tv_usec += hctx->ccid3hctx_t_ipi; |
1138 | timeval_fix(&(hctx->ccid3hctx_t_nom)); | 1139 | timeval_fix(&(hctx->ccid3hctx_t_nom)); |
1139 | } | 1140 | } |
1140 | break; | 1141 | break; |
1141 | default: | 1142 | default: |
1142 | printk(KERN_CRIT "%s: %s, sk=%p, Illegal state (%d)!\n", | 1143 | printk(KERN_CRIT "%s: %s, sk=%p, Illegal state (%d)!\n", |
1143 | __FUNCTION__, dccp_role(sk), sk, hctx->ccid3hctx_state); | 1144 | __FUNCTION__, dccp_role(sk), sk, hctx->ccid3hctx_state); |
1144 | dump_stack(); | 1145 | dump_stack(); |
1145 | break; | 1146 | break; |
1146 | } | 1147 | } |
1147 | } | 1148 | } |
1148 | 1149 | ||
1149 | static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb) | 1150 | static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb) |
1150 | { | 1151 | { |
1151 | struct dccp_sock *dp = dccp_sk(sk); | 1152 | struct dccp_sock *dp = dccp_sk(sk); |
1152 | struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private; | 1153 | struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private; |
1153 | struct ccid3_options_received *opt_recv; | 1154 | struct ccid3_options_received *opt_recv; |
1154 | struct ccid3_tx_hist_entry *entry, *next, *packet; | 1155 | struct ccid3_tx_hist_entry *entry, *next, *packet; |
1155 | unsigned long next_tmout; | 1156 | unsigned long next_tmout; |
1156 | u16 t_elapsed; | 1157 | u16 t_elapsed; |
1157 | u32 pinv; | 1158 | u32 pinv; |
1158 | u32 x_recv; | 1159 | u32 x_recv; |
1159 | u32 r_sample; | 1160 | u32 r_sample; |
1160 | #if 0 | 1161 | #if 0 |
1161 | ccid3_pr_debug("%s, sk=%p(%s), skb=%p(%s)\n", | 1162 | ccid3_pr_debug("%s, sk=%p(%s), skb=%p(%s)\n", |
1162 | dccp_role(sk), sk, dccp_state_name(sk->sk_state), | 1163 | dccp_role(sk), sk, dccp_state_name(sk->sk_state), |
1163 | skb, dccp_packet_name(DCCP_SKB_CB(skb)->dccpd_type)); | 1164 | skb, dccp_packet_name(DCCP_SKB_CB(skb)->dccpd_type)); |
1164 | #endif | 1165 | #endif |
1165 | if (hctx == NULL) | 1166 | if (hctx == NULL) |
1166 | return; | 1167 | return; |
1167 | 1168 | ||
1168 | if (hctx->ccid3hctx_state == TFRC_SSTATE_TERM) { | 1169 | if (hctx->ccid3hctx_state == TFRC_SSTATE_TERM) { |
1169 | ccid3_pr_debug("%s, sk=%p, received a packet when terminating!\n", dccp_role(sk), sk); | 1170 | ccid3_pr_debug("%s, sk=%p, received a packet when terminating!\n", dccp_role(sk), sk); |
1170 | return; | 1171 | return; |
1171 | } | 1172 | } |
1172 | 1173 | ||
1173 | /* we are only interested in ACKs */ | 1174 | /* we are only interested in ACKs */ |
1174 | if (!(DCCP_SKB_CB(skb)->dccpd_type == DCCP_PKT_ACK || | 1175 | if (!(DCCP_SKB_CB(skb)->dccpd_type == DCCP_PKT_ACK || |
1175 | DCCP_SKB_CB(skb)->dccpd_type == DCCP_PKT_DATAACK)) | 1176 | DCCP_SKB_CB(skb)->dccpd_type == DCCP_PKT_DATAACK)) |
1176 | return; | 1177 | return; |
1177 | 1178 | ||
1178 | opt_recv = &hctx->ccid3hctx_options_received; | 1179 | opt_recv = &hctx->ccid3hctx_options_received; |
1179 | 1180 | ||
1180 | t_elapsed = dp->dccps_options_received.dccpor_elapsed_time; | 1181 | t_elapsed = dp->dccps_options_received.dccpor_elapsed_time; |
1181 | x_recv = opt_recv->ccid3or_receive_rate; | 1182 | x_recv = opt_recv->ccid3or_receive_rate; |
1182 | pinv = opt_recv->ccid3or_loss_event_rate; | 1183 | pinv = opt_recv->ccid3or_loss_event_rate; |
1183 | 1184 | ||
1184 | switch (hctx->ccid3hctx_state) { | 1185 | switch (hctx->ccid3hctx_state) { |
1185 | case TFRC_SSTATE_NO_SENT: | 1186 | case TFRC_SSTATE_NO_SENT: |
1186 | /* FIXME: what to do here? */ | 1187 | /* FIXME: what to do here? */ |
1187 | return; | 1188 | return; |
1188 | case TFRC_SSTATE_NO_FBACK: | 1189 | case TFRC_SSTATE_NO_FBACK: |
1189 | case TFRC_SSTATE_FBACK: | 1190 | case TFRC_SSTATE_FBACK: |
1190 | /* Calculate new round trip sample by | 1191 | /* Calculate new round trip sample by |
1191 | * R_sample = (now - t_recvdata) - t_delay */ | 1192 | * R_sample = (now - t_recvdata) - t_delay */ |
1192 | /* get t_recvdata from history */ | 1193 | /* get t_recvdata from history */ |
1193 | packet = NULL; | 1194 | packet = NULL; |
1194 | list_for_each_entry_safe(entry, next, &hctx->ccid3hctx_hist, ccid3htx_node) | 1195 | list_for_each_entry_safe(entry, next, &hctx->ccid3hctx_hist, ccid3htx_node) |
1195 | if (entry->ccid3htx_seqno == DCCP_SKB_CB(skb)->dccpd_ack_seq) { | 1196 | if (entry->ccid3htx_seqno == DCCP_SKB_CB(skb)->dccpd_ack_seq) { |
1196 | packet = entry; | 1197 | packet = entry; |
1197 | break; | 1198 | break; |
1198 | } | 1199 | } |
1199 | 1200 | ||
1200 | if (packet == NULL) { | 1201 | if (packet == NULL) { |
1201 | ccid3_pr_debug("%s, sk=%p, seqno %llu(%s) does't exist in history!\n", | 1202 | ccid3_pr_debug("%s, sk=%p, seqno %llu(%s) does't exist in history!\n", |
1202 | dccp_role(sk), sk, DCCP_SKB_CB(skb)->dccpd_ack_seq, | 1203 | dccp_role(sk), sk, DCCP_SKB_CB(skb)->dccpd_ack_seq, |
1203 | dccp_packet_name(DCCP_SKB_CB(skb)->dccpd_type)); | 1204 | dccp_packet_name(DCCP_SKB_CB(skb)->dccpd_type)); |
1204 | return; | 1205 | return; |
1205 | } | 1206 | } |
1206 | 1207 | ||
1207 | /* Update RTT */ | 1208 | /* Update RTT */ |
1208 | r_sample = now_delta(packet->ccid3htx_tstamp); | 1209 | r_sample = now_delta(packet->ccid3htx_tstamp); |
1209 | /* FIXME: */ | 1210 | /* FIXME: */ |
1210 | // r_sample -= usecs_to_jiffies(t_elapsed * 10); | 1211 | // r_sample -= usecs_to_jiffies(t_elapsed * 10); |
1211 | 1212 | ||
1212 | /* Update RTT estimate by | 1213 | /* Update RTT estimate by |
1213 | * If (No feedback recv) | 1214 | * If (No feedback recv) |
1214 | * R = R_sample; | 1215 | * R = R_sample; |
1215 | * Else | 1216 | * Else |
1216 | * R = q * R + (1 - q) * R_sample; | 1217 | * R = q * R + (1 - q) * R_sample; |
1217 | * | 1218 | * |
1218 | * q is a constant, RFC 3448 recomments 0.9 | 1219 | * q is a constant, RFC 3448 recomments 0.9 |
1219 | */ | 1220 | */ |
1220 | if (hctx->ccid3hctx_state == TFRC_SSTATE_NO_FBACK) { | 1221 | if (hctx->ccid3hctx_state == TFRC_SSTATE_NO_FBACK) { |
1221 | ccid3_hc_tx_set_state(sk, TFRC_SSTATE_FBACK); | 1222 | ccid3_hc_tx_set_state(sk, TFRC_SSTATE_FBACK); |
1222 | hctx->ccid3hctx_rtt = r_sample; | 1223 | hctx->ccid3hctx_rtt = r_sample; |
1223 | } else | 1224 | } else |
1224 | hctx->ccid3hctx_rtt = (hctx->ccid3hctx_rtt * 9) / 10 + r_sample / 10; | 1225 | hctx->ccid3hctx_rtt = (hctx->ccid3hctx_rtt * 9) / 10 + r_sample / 10; |
1225 | 1226 | ||
1226 | /* | 1227 | /* |
1227 | * XXX: this is to avoid a division by zero in ccid3_hc_tx_packet_sent | 1228 | * XXX: this is to avoid a division by zero in ccid3_hc_tx_packet_sent |
1228 | * implemention of the new window count. | 1229 | * implemention of the new window count. |
1229 | */ | 1230 | */ |
1230 | if (hctx->ccid3hctx_rtt < 4) | 1231 | if (hctx->ccid3hctx_rtt < 4) |
1231 | hctx->ccid3hctx_rtt = 4; | 1232 | hctx->ccid3hctx_rtt = 4; |
1232 | 1233 | ||
1233 | ccid3_pr_debug("%s, sk=%p, New RTT estimate=%uus, r_sample=%us\n", | 1234 | ccid3_pr_debug("%s, sk=%p, New RTT estimate=%uus, r_sample=%us\n", |
1234 | dccp_role(sk), sk, | 1235 | dccp_role(sk), sk, |
1235 | hctx->ccid3hctx_rtt, | 1236 | hctx->ccid3hctx_rtt, |
1236 | r_sample); | 1237 | r_sample); |
1237 | 1238 | ||
1238 | /* Update timeout interval */ | 1239 | /* Update timeout interval */ |
1239 | inet_csk(sk)->icsk_rto = max_t(u32, 4 * hctx->ccid3hctx_rtt, USEC_IN_SEC); | 1240 | inet_csk(sk)->icsk_rto = max_t(u32, 4 * hctx->ccid3hctx_rtt, USEC_IN_SEC); |
1240 | 1241 | ||
1241 | /* Update receive rate */ | 1242 | /* Update receive rate */ |
1242 | hctx->ccid3hctx_x_recv = x_recv; /* x_recv in bytes per second */ | 1243 | hctx->ccid3hctx_x_recv = x_recv; /* x_recv in bytes per second */ |
1243 | 1244 | ||
1244 | /* Update loss event rate */ | 1245 | /* Update loss event rate */ |
1245 | if (pinv == ~0 || pinv == 0) | 1246 | if (pinv == ~0 || pinv == 0) |
1246 | hctx->ccid3hctx_p = 0; | 1247 | hctx->ccid3hctx_p = 0; |
1247 | else { | 1248 | else { |
1248 | hctx->ccid3hctx_p = 1000000 / pinv; | 1249 | hctx->ccid3hctx_p = 1000000 / pinv; |
1249 | 1250 | ||
1250 | if (hctx->ccid3hctx_p < TFRC_SMALLEST_P) { | 1251 | if (hctx->ccid3hctx_p < TFRC_SMALLEST_P) { |
1251 | hctx->ccid3hctx_p = TFRC_SMALLEST_P; | 1252 | hctx->ccid3hctx_p = TFRC_SMALLEST_P; |
1252 | ccid3_pr_debug("%s, sk=%p, Smallest p used!\n", dccp_role(sk), sk); | 1253 | ccid3_pr_debug("%s, sk=%p, Smallest p used!\n", dccp_role(sk), sk); |
1253 | } | 1254 | } |
1254 | } | 1255 | } |
1255 | 1256 | ||
1256 | /* unschedule no feedback timer */ | 1257 | /* unschedule no feedback timer */ |
1257 | sk_stop_timer(sk, &hctx->ccid3hctx_no_feedback_timer); | 1258 | sk_stop_timer(sk, &hctx->ccid3hctx_no_feedback_timer); |
1258 | 1259 | ||
1259 | /* Update sending rate */ | 1260 | /* Update sending rate */ |
1260 | ccid3_hc_tx_update_x(sk); | 1261 | ccid3_hc_tx_update_x(sk); |
1261 | 1262 | ||
1262 | /* Update next send time */ | 1263 | /* Update next send time */ |
1263 | if (hctx->ccid3hctx_t_ipi > (hctx->ccid3hctx_t_nom).tv_usec) { | 1264 | if (hctx->ccid3hctx_t_ipi > (hctx->ccid3hctx_t_nom).tv_usec) { |
1264 | (hctx->ccid3hctx_t_nom).tv_usec += USEC_IN_SEC; | 1265 | (hctx->ccid3hctx_t_nom).tv_usec += USEC_IN_SEC; |
1265 | (hctx->ccid3hctx_t_nom).tv_sec--; | 1266 | (hctx->ccid3hctx_t_nom).tv_sec--; |
1266 | } | 1267 | } |
1267 | /* FIXME - if no feedback then t_ipi can go > 1 second */ | 1268 | /* FIXME - if no feedback then t_ipi can go > 1 second */ |
1268 | (hctx->ccid3hctx_t_nom).tv_usec -= hctx->ccid3hctx_t_ipi; | 1269 | (hctx->ccid3hctx_t_nom).tv_usec -= hctx->ccid3hctx_t_ipi; |
1269 | ccid3_calc_new_t_ipi(hctx); | 1270 | ccid3_calc_new_t_ipi(hctx); |
1270 | (hctx->ccid3hctx_t_nom).tv_usec += hctx->ccid3hctx_t_ipi; | 1271 | (hctx->ccid3hctx_t_nom).tv_usec += hctx->ccid3hctx_t_ipi; |
1271 | timeval_fix(&(hctx->ccid3hctx_t_nom)); | 1272 | timeval_fix(&(hctx->ccid3hctx_t_nom)); |
1272 | ccid3_calc_new_delta(hctx); | 1273 | ccid3_calc_new_delta(hctx); |
1273 | 1274 | ||
1274 | /* remove all packets older than the one acked from history */ | 1275 | /* remove all packets older than the one acked from history */ |
1275 | list_for_each_entry_safe_continue(entry, next, &hctx->ccid3hctx_hist, ccid3htx_node) { | 1276 | list_for_each_entry_safe_continue(entry, next, &hctx->ccid3hctx_hist, ccid3htx_node) { |
1276 | list_del_init(&entry->ccid3htx_node); | 1277 | list_del_init(&entry->ccid3htx_node); |
1277 | ccid3_tx_hist_entry_delete(entry); | 1278 | ccid3_tx_hist_entry_delete(entry); |
1278 | } | 1279 | } |
1279 | if (hctx->ccid3hctx_x < 10) { | 1280 | if (hctx->ccid3hctx_x < 10) { |
1280 | ccid3_pr_debug("ccid3_hc_tx_packet_recv hctx->ccid3hctx_x < 10\n"); | 1281 | ccid3_pr_debug("ccid3_hc_tx_packet_recv hctx->ccid3hctx_x < 10\n"); |
1281 | hctx->ccid3hctx_x = 10; | 1282 | hctx->ccid3hctx_x = 10; |
1282 | } | 1283 | } |
1283 | /* to prevent divide by zero below */ | 1284 | /* to prevent divide by zero below */ |
1284 | 1285 | ||
1285 | /* Schedule no feedback timer to expire in max(4 * R, 2 * s / X) */ | 1286 | /* Schedule no feedback timer to expire in max(4 * R, 2 * s / X) */ |
1286 | next_tmout = max(inet_csk(sk)->icsk_rto, | 1287 | next_tmout = max(inet_csk(sk)->icsk_rto, |
1287 | 2 * (hctx->ccid3hctx_s * 100000) / (hctx->ccid3hctx_x/10)); | 1288 | 2 * (hctx->ccid3hctx_s * 100000) / (hctx->ccid3hctx_x/10)); |
1288 | /* maths with 100000 and 10 is to prevent overflow with 32 bit */ | 1289 | /* maths with 100000 and 10 is to prevent overflow with 32 bit */ |
1289 | 1290 | ||
1290 | ccid3_pr_debug("%s, sk=%p, Scheduled no feedback timer to expire in %lu jiffies (%luus)\n", | 1291 | ccid3_pr_debug("%s, sk=%p, Scheduled no feedback timer to expire in %lu jiffies (%luus)\n", |
1291 | dccp_role(sk), sk, usecs_to_jiffies(next_tmout), next_tmout); | 1292 | dccp_role(sk), sk, usecs_to_jiffies(next_tmout), next_tmout); |
1292 | 1293 | ||
1293 | sk_reset_timer(sk, &hctx->ccid3hctx_no_feedback_timer, | 1294 | sk_reset_timer(sk, &hctx->ccid3hctx_no_feedback_timer, |
1294 | jiffies + max_t(u32,1,usecs_to_jiffies(next_tmout))); | 1295 | jiffies + max_t(u32,1,usecs_to_jiffies(next_tmout))); |
1295 | 1296 | ||
1296 | /* set idle flag */ | 1297 | /* set idle flag */ |
1297 | hctx->ccid3hctx_idle = 1; | 1298 | hctx->ccid3hctx_idle = 1; |
1298 | break; | 1299 | break; |
1299 | default: | 1300 | default: |
1300 | printk(KERN_CRIT "%s: %s, sk=%p, Illegal state (%d)!\n", | 1301 | printk(KERN_CRIT "%s: %s, sk=%p, Illegal state (%d)!\n", |
1301 | __FUNCTION__, dccp_role(sk), sk, hctx->ccid3hctx_state); | 1302 | __FUNCTION__, dccp_role(sk), sk, hctx->ccid3hctx_state); |
1302 | dump_stack(); | 1303 | dump_stack(); |
1303 | break; | 1304 | break; |
1304 | } | 1305 | } |
1305 | } | 1306 | } |
1306 | 1307 | ||
1307 | static void ccid3_hc_tx_insert_options(struct sock *sk, struct sk_buff *skb) | 1308 | static void ccid3_hc_tx_insert_options(struct sock *sk, struct sk_buff *skb) |
1308 | { | 1309 | { |
1309 | const struct dccp_sock *dp = dccp_sk(sk); | 1310 | const struct dccp_sock *dp = dccp_sk(sk); |
1310 | struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private; | 1311 | struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private; |
1311 | 1312 | ||
1312 | if (hctx == NULL || !(sk->sk_state == DCCP_OPEN || sk->sk_state == DCCP_PARTOPEN)) | 1313 | if (hctx == NULL || !(sk->sk_state == DCCP_OPEN || sk->sk_state == DCCP_PARTOPEN)) |
1313 | return; | 1314 | return; |
1314 | 1315 | ||
1315 | DCCP_SKB_CB(skb)->dccpd_ccval = hctx->ccid3hctx_last_win_count; | 1316 | DCCP_SKB_CB(skb)->dccpd_ccval = hctx->ccid3hctx_last_win_count; |
1316 | } | 1317 | } |
1317 | 1318 | ||
1318 | static int ccid3_hc_tx_parse_options(struct sock *sk, unsigned char option, | 1319 | static int ccid3_hc_tx_parse_options(struct sock *sk, unsigned char option, |
1319 | unsigned char len, u16 idx, unsigned char *value) | 1320 | unsigned char len, u16 idx, unsigned char *value) |
1320 | { | 1321 | { |
1321 | int rc = 0; | 1322 | int rc = 0; |
1322 | struct dccp_sock *dp = dccp_sk(sk); | 1323 | struct dccp_sock *dp = dccp_sk(sk); |
1323 | struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private; | 1324 | struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private; |
1324 | struct ccid3_options_received *opt_recv; | 1325 | struct ccid3_options_received *opt_recv; |
1325 | 1326 | ||
1326 | if (hctx == NULL) | 1327 | if (hctx == NULL) |
1327 | return 0; | 1328 | return 0; |
1328 | 1329 | ||
1329 | opt_recv = &hctx->ccid3hctx_options_received; | 1330 | opt_recv = &hctx->ccid3hctx_options_received; |
1330 | 1331 | ||
1331 | if (opt_recv->ccid3or_seqno != dp->dccps_gsr) { | 1332 | if (opt_recv->ccid3or_seqno != dp->dccps_gsr) { |
1332 | opt_recv->ccid3or_seqno = dp->dccps_gsr; | 1333 | opt_recv->ccid3or_seqno = dp->dccps_gsr; |
1333 | opt_recv->ccid3or_loss_event_rate = ~0; | 1334 | opt_recv->ccid3or_loss_event_rate = ~0; |
1334 | opt_recv->ccid3or_loss_intervals_idx = 0; | 1335 | opt_recv->ccid3or_loss_intervals_idx = 0; |
1335 | opt_recv->ccid3or_loss_intervals_len = 0; | 1336 | opt_recv->ccid3or_loss_intervals_len = 0; |
1336 | opt_recv->ccid3or_receive_rate = 0; | 1337 | opt_recv->ccid3or_receive_rate = 0; |
1337 | } | 1338 | } |
1338 | 1339 | ||
1339 | switch (option) { | 1340 | switch (option) { |
1340 | case TFRC_OPT_LOSS_EVENT_RATE: | 1341 | case TFRC_OPT_LOSS_EVENT_RATE: |
1341 | if (len != 4) { | 1342 | if (len != 4) { |
1342 | ccid3_pr_debug("%s, sk=%p, invalid len for TFRC_OPT_LOSS_EVENT_RATE\n", | 1343 | ccid3_pr_debug("%s, sk=%p, invalid len for TFRC_OPT_LOSS_EVENT_RATE\n", |
1343 | dccp_role(sk), sk); | 1344 | dccp_role(sk), sk); |
1344 | rc = -EINVAL; | 1345 | rc = -EINVAL; |
1345 | } else { | 1346 | } else { |
1346 | opt_recv->ccid3or_loss_event_rate = ntohl(*(u32 *)value); | 1347 | opt_recv->ccid3or_loss_event_rate = ntohl(*(u32 *)value); |
1347 | ccid3_pr_debug("%s, sk=%p, LOSS_EVENT_RATE=%u\n", | 1348 | ccid3_pr_debug("%s, sk=%p, LOSS_EVENT_RATE=%u\n", |
1348 | dccp_role(sk), sk, | 1349 | dccp_role(sk), sk, |
1349 | opt_recv->ccid3or_loss_event_rate); | 1350 | opt_recv->ccid3or_loss_event_rate); |
1350 | } | 1351 | } |
1351 | break; | 1352 | break; |
1352 | case TFRC_OPT_LOSS_INTERVALS: | 1353 | case TFRC_OPT_LOSS_INTERVALS: |
1353 | opt_recv->ccid3or_loss_intervals_idx = idx; | 1354 | opt_recv->ccid3or_loss_intervals_idx = idx; |
1354 | opt_recv->ccid3or_loss_intervals_len = len; | 1355 | opt_recv->ccid3or_loss_intervals_len = len; |
1355 | ccid3_pr_debug("%s, sk=%p, LOSS_INTERVALS=(%u, %u)\n", | 1356 | ccid3_pr_debug("%s, sk=%p, LOSS_INTERVALS=(%u, %u)\n", |
1356 | dccp_role(sk), sk, | 1357 | dccp_role(sk), sk, |
1357 | opt_recv->ccid3or_loss_intervals_idx, | 1358 | opt_recv->ccid3or_loss_intervals_idx, |
1358 | opt_recv->ccid3or_loss_intervals_len); | 1359 | opt_recv->ccid3or_loss_intervals_len); |
1359 | break; | 1360 | break; |
1360 | case TFRC_OPT_RECEIVE_RATE: | 1361 | case TFRC_OPT_RECEIVE_RATE: |
1361 | if (len != 4) { | 1362 | if (len != 4) { |
1362 | ccid3_pr_debug("%s, sk=%p, invalid len for TFRC_OPT_RECEIVE_RATE\n", | 1363 | ccid3_pr_debug("%s, sk=%p, invalid len for TFRC_OPT_RECEIVE_RATE\n", |
1363 | dccp_role(sk), sk); | 1364 | dccp_role(sk), sk); |
1364 | rc = -EINVAL; | 1365 | rc = -EINVAL; |
1365 | } else { | 1366 | } else { |
1366 | opt_recv->ccid3or_receive_rate = ntohl(*(u32 *)value); | 1367 | opt_recv->ccid3or_receive_rate = ntohl(*(u32 *)value); |
1367 | ccid3_pr_debug("%s, sk=%p, RECEIVE_RATE=%u\n", | 1368 | ccid3_pr_debug("%s, sk=%p, RECEIVE_RATE=%u\n", |
1368 | dccp_role(sk), sk, | 1369 | dccp_role(sk), sk, |
1369 | opt_recv->ccid3or_receive_rate); | 1370 | opt_recv->ccid3or_receive_rate); |
1370 | } | 1371 | } |
1371 | break; | 1372 | break; |
1372 | } | 1373 | } |
1373 | 1374 | ||
1374 | return rc; | 1375 | return rc; |
1375 | } | 1376 | } |
1376 | 1377 | ||
1377 | static int ccid3_hc_tx_init(struct sock *sk) | 1378 | static int ccid3_hc_tx_init(struct sock *sk) |
1378 | { | 1379 | { |
1379 | struct dccp_sock *dp = dccp_sk(sk); | 1380 | struct dccp_sock *dp = dccp_sk(sk); |
1380 | struct ccid3_hc_tx_sock *hctx; | 1381 | struct ccid3_hc_tx_sock *hctx; |
1381 | 1382 | ||
1382 | ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk); | 1383 | ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk); |
1383 | 1384 | ||
1384 | hctx = dp->dccps_hc_tx_ccid_private = kmalloc(sizeof(*hctx), gfp_any()); | 1385 | hctx = dp->dccps_hc_tx_ccid_private = kmalloc(sizeof(*hctx), gfp_any()); |
1385 | if (hctx == NULL) | 1386 | if (hctx == NULL) |
1386 | return -ENOMEM; | 1387 | return -ENOMEM; |
1387 | 1388 | ||
1388 | memset(hctx, 0, sizeof(*hctx)); | 1389 | memset(hctx, 0, sizeof(*hctx)); |
1389 | 1390 | ||
1390 | if (dp->dccps_avg_packet_size >= TFRC_MIN_PACKET_SIZE && | 1391 | if (dp->dccps_avg_packet_size >= TFRC_MIN_PACKET_SIZE && |
1391 | dp->dccps_avg_packet_size <= TFRC_MAX_PACKET_SIZE) | 1392 | dp->dccps_avg_packet_size <= TFRC_MAX_PACKET_SIZE) |
1392 | hctx->ccid3hctx_s = (u16)dp->dccps_avg_packet_size; | 1393 | hctx->ccid3hctx_s = (u16)dp->dccps_avg_packet_size; |
1393 | else | 1394 | else |
1394 | hctx->ccid3hctx_s = TFRC_STD_PACKET_SIZE; | 1395 | hctx->ccid3hctx_s = TFRC_STD_PACKET_SIZE; |
1395 | 1396 | ||
1396 | hctx->ccid3hctx_x = hctx->ccid3hctx_s; /* set transmission rate to 1 packet per second */ | 1397 | hctx->ccid3hctx_x = hctx->ccid3hctx_s; /* set transmission rate to 1 packet per second */ |
1397 | hctx->ccid3hctx_rtt = 4; /* See ccid3_hc_tx_packet_sent win_count calculatation */ | 1398 | hctx->ccid3hctx_rtt = 4; /* See ccid3_hc_tx_packet_sent win_count calculatation */ |
1398 | inet_csk(sk)->icsk_rto = USEC_IN_SEC; | 1399 | inet_csk(sk)->icsk_rto = USEC_IN_SEC; |
1399 | hctx->ccid3hctx_state = TFRC_SSTATE_NO_SENT; | 1400 | hctx->ccid3hctx_state = TFRC_SSTATE_NO_SENT; |
1400 | INIT_LIST_HEAD(&hctx->ccid3hctx_hist); | 1401 | INIT_LIST_HEAD(&hctx->ccid3hctx_hist); |
1401 | init_timer(&hctx->ccid3hctx_no_feedback_timer); | 1402 | init_timer(&hctx->ccid3hctx_no_feedback_timer); |
1402 | 1403 | ||
1403 | return 0; | 1404 | return 0; |
1404 | } | 1405 | } |
1405 | 1406 | ||
1406 | static void ccid3_hc_tx_exit(struct sock *sk) | 1407 | static void ccid3_hc_tx_exit(struct sock *sk) |
1407 | { | 1408 | { |
1408 | struct dccp_sock *dp = dccp_sk(sk); | 1409 | struct dccp_sock *dp = dccp_sk(sk); |
1409 | struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private; | 1410 | struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private; |
1410 | struct ccid3_tx_hist_entry *entry, *next; | 1411 | struct ccid3_tx_hist_entry *entry, *next; |
1411 | 1412 | ||
1412 | ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk); | 1413 | ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk); |
1413 | BUG_ON(hctx == NULL); | 1414 | BUG_ON(hctx == NULL); |
1414 | 1415 | ||
1415 | ccid3_hc_tx_set_state(sk, TFRC_SSTATE_TERM); | 1416 | ccid3_hc_tx_set_state(sk, TFRC_SSTATE_TERM); |
1416 | sk_stop_timer(sk, &hctx->ccid3hctx_no_feedback_timer); | 1417 | sk_stop_timer(sk, &hctx->ccid3hctx_no_feedback_timer); |
1417 | 1418 | ||
1418 | /* Empty packet history */ | 1419 | /* Empty packet history */ |
1419 | list_for_each_entry_safe(entry, next, &hctx->ccid3hctx_hist, ccid3htx_node) { | 1420 | list_for_each_entry_safe(entry, next, &hctx->ccid3hctx_hist, ccid3htx_node) { |
1420 | list_del_init(&entry->ccid3htx_node); | 1421 | list_del_init(&entry->ccid3htx_node); |
1421 | ccid3_tx_hist_entry_delete(entry); | 1422 | ccid3_tx_hist_entry_delete(entry); |
1422 | } | 1423 | } |
1423 | 1424 | ||
1424 | kfree(dp->dccps_hc_tx_ccid_private); | 1425 | kfree(dp->dccps_hc_tx_ccid_private); |
1425 | dp->dccps_hc_tx_ccid_private = NULL; | 1426 | dp->dccps_hc_tx_ccid_private = NULL; |
1426 | } | 1427 | } |
1427 | 1428 | ||
1428 | /* | 1429 | /* |
1429 | * RX Half Connection methods | 1430 | * RX Half Connection methods |
1430 | */ | 1431 | */ |
1431 | 1432 | ||
1432 | /* TFRC receiver states */ | 1433 | /* TFRC receiver states */ |
1433 | enum ccid3_hc_rx_states { | 1434 | enum ccid3_hc_rx_states { |
1434 | TFRC_RSTATE_NO_DATA = 1, | 1435 | TFRC_RSTATE_NO_DATA = 1, |
1435 | TFRC_RSTATE_DATA, | 1436 | TFRC_RSTATE_DATA, |
1436 | TFRC_RSTATE_TERM = 127, | 1437 | TFRC_RSTATE_TERM = 127, |
1437 | }; | 1438 | }; |
1438 | 1439 | ||
1439 | #ifdef CCID3_DEBUG | 1440 | #ifdef CCID3_DEBUG |
1440 | static const char *ccid3_rx_state_name(enum ccid3_hc_rx_states state) | 1441 | static const char *ccid3_rx_state_name(enum ccid3_hc_rx_states state) |
1441 | { | 1442 | { |
1442 | static char *ccid3_rx_state_names[] = { | 1443 | static char *ccid3_rx_state_names[] = { |
1443 | [TFRC_RSTATE_NO_DATA] = "NO_DATA", | 1444 | [TFRC_RSTATE_NO_DATA] = "NO_DATA", |
1444 | [TFRC_RSTATE_DATA] = "DATA", | 1445 | [TFRC_RSTATE_DATA] = "DATA", |
1445 | [TFRC_RSTATE_TERM] = "TERM", | 1446 | [TFRC_RSTATE_TERM] = "TERM", |
1446 | }; | 1447 | }; |
1447 | 1448 | ||
1448 | return ccid3_rx_state_names[state]; | 1449 | return ccid3_rx_state_names[state]; |
1449 | } | 1450 | } |
1450 | #endif | 1451 | #endif |
1451 | 1452 | ||
1452 | static inline void ccid3_hc_rx_set_state(struct sock *sk, enum ccid3_hc_rx_states state) | 1453 | static inline void ccid3_hc_rx_set_state(struct sock *sk, enum ccid3_hc_rx_states state) |
1453 | { | 1454 | { |
1454 | struct dccp_sock *dp = dccp_sk(sk); | 1455 | struct dccp_sock *dp = dccp_sk(sk); |
1455 | struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private; | 1456 | struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private; |
1456 | enum ccid3_hc_rx_states oldstate = hcrx->ccid3hcrx_state; | 1457 | enum ccid3_hc_rx_states oldstate = hcrx->ccid3hcrx_state; |
1457 | 1458 | ||
1458 | ccid3_pr_debug("%s(%p) %-8.8s -> %s\n", | 1459 | ccid3_pr_debug("%s(%p) %-8.8s -> %s\n", |
1459 | dccp_role(sk), sk, ccid3_rx_state_name(oldstate), ccid3_rx_state_name(state)); | 1460 | dccp_role(sk), sk, ccid3_rx_state_name(oldstate), ccid3_rx_state_name(state)); |
1460 | WARN_ON(state == oldstate); | 1461 | WARN_ON(state == oldstate); |
1461 | hcrx->ccid3hcrx_state = state; | 1462 | hcrx->ccid3hcrx_state = state; |
1462 | } | 1463 | } |
1463 | 1464 | ||
1464 | static int ccid3_hc_rx_add_hist(struct sock *sk, struct ccid3_rx_hist_entry *packet) | 1465 | static int ccid3_hc_rx_add_hist(struct sock *sk, struct ccid3_rx_hist_entry *packet) |
1465 | { | 1466 | { |
1466 | struct dccp_sock *dp = dccp_sk(sk); | 1467 | struct dccp_sock *dp = dccp_sk(sk); |
1467 | struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private; | 1468 | struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private; |
1468 | struct ccid3_rx_hist_entry *entry, *next; | 1469 | struct ccid3_rx_hist_entry *entry, *next; |
1469 | u8 num_later = 0; | 1470 | u8 num_later = 0; |
1470 | 1471 | ||
1471 | if (list_empty(&hcrx->ccid3hcrx_hist)) | 1472 | if (list_empty(&hcrx->ccid3hcrx_hist)) |
1472 | list_add(&packet->ccid3hrx_node, &hcrx->ccid3hcrx_hist); | 1473 | list_add(&packet->ccid3hrx_node, &hcrx->ccid3hcrx_hist); |
1473 | else { | 1474 | else { |
1474 | u64 seqno = packet->ccid3hrx_seqno; | 1475 | u64 seqno = packet->ccid3hrx_seqno; |
1475 | struct ccid3_rx_hist_entry *iter = list_entry(hcrx->ccid3hcrx_hist.next, | 1476 | struct ccid3_rx_hist_entry *iter = list_entry(hcrx->ccid3hcrx_hist.next, |
1476 | struct ccid3_rx_hist_entry, | 1477 | struct ccid3_rx_hist_entry, |
1477 | ccid3hrx_node); | 1478 | ccid3hrx_node); |
1478 | if (after48(seqno, iter->ccid3hrx_seqno)) | 1479 | if (after48(seqno, iter->ccid3hrx_seqno)) |
1479 | list_add(&packet->ccid3hrx_node, &hcrx->ccid3hcrx_hist); | 1480 | list_add(&packet->ccid3hrx_node, &hcrx->ccid3hcrx_hist); |
1480 | else { | 1481 | else { |
1481 | if (iter->ccid3hrx_type == DCCP_PKT_DATA || | 1482 | if (iter->ccid3hrx_type == DCCP_PKT_DATA || |
1482 | iter->ccid3hrx_type == DCCP_PKT_DATAACK) | 1483 | iter->ccid3hrx_type == DCCP_PKT_DATAACK) |
1483 | num_later = 1; | 1484 | num_later = 1; |
1484 | 1485 | ||
1485 | list_for_each_entry_continue(iter, &hcrx->ccid3hcrx_hist, ccid3hrx_node) { | 1486 | list_for_each_entry_continue(iter, &hcrx->ccid3hcrx_hist, ccid3hrx_node) { |
1486 | if (after48(seqno, iter->ccid3hrx_seqno)) { | 1487 | if (after48(seqno, iter->ccid3hrx_seqno)) { |
1487 | list_add(&packet->ccid3hrx_node, &iter->ccid3hrx_node); | 1488 | list_add(&packet->ccid3hrx_node, &iter->ccid3hrx_node); |
1488 | goto trim_history; | 1489 | goto trim_history; |
1489 | } | 1490 | } |
1490 | 1491 | ||
1491 | if (iter->ccid3hrx_type == DCCP_PKT_DATA || | 1492 | if (iter->ccid3hrx_type == DCCP_PKT_DATA || |
1492 | iter->ccid3hrx_type == DCCP_PKT_DATAACK) | 1493 | iter->ccid3hrx_type == DCCP_PKT_DATAACK) |
1493 | num_later++; | 1494 | num_later++; |
1494 | 1495 | ||
1495 | if (num_later == TFRC_RECV_NUM_LATE_LOSS) { | 1496 | if (num_later == TFRC_RECV_NUM_LATE_LOSS) { |
1496 | ccid3_rx_hist_entry_delete(packet); | 1497 | ccid3_rx_hist_entry_delete(packet); |
1497 | ccid3_pr_debug("%s, sk=%p, packet(%llu) already lost!\n", | 1498 | ccid3_pr_debug("%s, sk=%p, packet(%llu) already lost!\n", |
1498 | dccp_role(sk), sk, seqno); | 1499 | dccp_role(sk), sk, seqno); |
1499 | return 1; | 1500 | return 1; |
1500 | } | 1501 | } |
1501 | } | 1502 | } |
1502 | 1503 | ||
1503 | if (num_later < TFRC_RECV_NUM_LATE_LOSS) | 1504 | if (num_later < TFRC_RECV_NUM_LATE_LOSS) |
1504 | list_add_tail(&packet->ccid3hrx_node, &hcrx->ccid3hcrx_hist); | 1505 | list_add_tail(&packet->ccid3hrx_node, &hcrx->ccid3hcrx_hist); |
1505 | /* FIXME: else what? should we destroy the packet like above? */ | 1506 | /* FIXME: else what? should we destroy the packet like above? */ |
1506 | } | 1507 | } |
1507 | } | 1508 | } |
1508 | 1509 | ||
1509 | trim_history: | 1510 | trim_history: |
1510 | /* Trim history (remove all packets after the NUM_LATE_LOSS + 1 data packets) */ | 1511 | /* Trim history (remove all packets after the NUM_LATE_LOSS + 1 data packets) */ |
1511 | num_later = TFRC_RECV_NUM_LATE_LOSS + 1; | 1512 | num_later = TFRC_RECV_NUM_LATE_LOSS + 1; |
1512 | 1513 | ||
1513 | if (!list_empty(&hcrx->ccid3hcrx_loss_interval_hist)) { | 1514 | if (!list_empty(&hcrx->ccid3hcrx_loss_interval_hist)) { |
1514 | list_for_each_entry_safe(entry, next, &hcrx->ccid3hcrx_hist, ccid3hrx_node) { | 1515 | list_for_each_entry_safe(entry, next, &hcrx->ccid3hcrx_hist, ccid3hrx_node) { |
1515 | if (num_later == 0) { | 1516 | if (num_later == 0) { |
1516 | list_del_init(&entry->ccid3hrx_node); | 1517 | list_del_init(&entry->ccid3hrx_node); |
1517 | ccid3_rx_hist_entry_delete(entry); | 1518 | ccid3_rx_hist_entry_delete(entry); |
1518 | } else if (entry->ccid3hrx_type == DCCP_PKT_DATA || | 1519 | } else if (entry->ccid3hrx_type == DCCP_PKT_DATA || |
1519 | entry->ccid3hrx_type == DCCP_PKT_DATAACK) | 1520 | entry->ccid3hrx_type == DCCP_PKT_DATAACK) |
1520 | --num_later; | 1521 | --num_later; |
1521 | } | 1522 | } |
1522 | } else { | 1523 | } else { |
1523 | int step = 0; | 1524 | int step = 0; |
1524 | u8 win_count = 0; /* Not needed, but lets shut up gcc */ | 1525 | u8 win_count = 0; /* Not needed, but lets shut up gcc */ |
1525 | int tmp; | 1526 | int tmp; |
1526 | /* | 1527 | /* |
1527 | * We have no loss interval history so we need at least one | 1528 | * We have no loss interval history so we need at least one |
1528 | * rtt:s of data packets to approximate rtt. | 1529 | * rtt:s of data packets to approximate rtt. |
1529 | */ | 1530 | */ |
1530 | list_for_each_entry_safe(entry, next, &hcrx->ccid3hcrx_hist, ccid3hrx_node) { | 1531 | list_for_each_entry_safe(entry, next, &hcrx->ccid3hcrx_hist, ccid3hrx_node) { |
1531 | if (num_later == 0) { | 1532 | if (num_later == 0) { |
1532 | switch (step) { | 1533 | switch (step) { |
1533 | case 0: | 1534 | case 0: |
1534 | step = 1; | 1535 | step = 1; |
1535 | /* OK, find next data packet */ | 1536 | /* OK, find next data packet */ |
1536 | num_later = 1; | 1537 | num_later = 1; |
1537 | break; | 1538 | break; |
1538 | case 1: | 1539 | case 1: |
1539 | step = 2; | 1540 | step = 2; |
1540 | /* OK, find next data packet */ | 1541 | /* OK, find next data packet */ |
1541 | num_later = 1; | 1542 | num_later = 1; |
1542 | win_count = entry->ccid3hrx_win_count; | 1543 | win_count = entry->ccid3hrx_win_count; |
1543 | break; | 1544 | break; |
1544 | case 2: | 1545 | case 2: |
1545 | tmp = win_count - entry->ccid3hrx_win_count; | 1546 | tmp = win_count - entry->ccid3hrx_win_count; |
1546 | if (tmp < 0) | 1547 | if (tmp < 0) |
1547 | tmp += TFRC_WIN_COUNT_LIMIT; | 1548 | tmp += TFRC_WIN_COUNT_LIMIT; |
1548 | if (tmp > TFRC_WIN_COUNT_PER_RTT + 1) { | 1549 | if (tmp > TFRC_WIN_COUNT_PER_RTT + 1) { |
1549 | /* we have found a packet older than one rtt | 1550 | /* we have found a packet older than one rtt |
1550 | * remove the rest */ | 1551 | * remove the rest */ |
1551 | step = 3; | 1552 | step = 3; |
1552 | } else /* OK, find next data packet */ | 1553 | } else /* OK, find next data packet */ |
1553 | num_later = 1; | 1554 | num_later = 1; |
1554 | break; | 1555 | break; |
1555 | case 3: | 1556 | case 3: |
1556 | list_del_init(&entry->ccid3hrx_node); | 1557 | list_del_init(&entry->ccid3hrx_node); |
1557 | ccid3_rx_hist_entry_delete(entry); | 1558 | ccid3_rx_hist_entry_delete(entry); |
1558 | break; | 1559 | break; |
1559 | } | 1560 | } |
1560 | } else if (entry->ccid3hrx_type == DCCP_PKT_DATA || | 1561 | } else if (entry->ccid3hrx_type == DCCP_PKT_DATA || |
1561 | entry->ccid3hrx_type == DCCP_PKT_DATAACK) | 1562 | entry->ccid3hrx_type == DCCP_PKT_DATAACK) |
1562 | --num_later; | 1563 | --num_later; |
1563 | } | 1564 | } |
1564 | } | 1565 | } |
1565 | 1566 | ||
1566 | return 0; | 1567 | return 0; |
1567 | } | 1568 | } |
1568 | 1569 | ||
1569 | static void ccid3_hc_rx_send_feedback(struct sock *sk) | 1570 | static void ccid3_hc_rx_send_feedback(struct sock *sk) |
1570 | { | 1571 | { |
1571 | struct dccp_sock *dp = dccp_sk(sk); | 1572 | struct dccp_sock *dp = dccp_sk(sk); |
1572 | struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private; | 1573 | struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private; |
1573 | struct ccid3_rx_hist_entry *entry, *packet; | 1574 | struct ccid3_rx_hist_entry *entry, *packet; |
1574 | 1575 | ||
1575 | ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk); | 1576 | ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk); |
1576 | 1577 | ||
1577 | switch (hcrx->ccid3hcrx_state) { | 1578 | switch (hcrx->ccid3hcrx_state) { |
1578 | case TFRC_RSTATE_NO_DATA: | 1579 | case TFRC_RSTATE_NO_DATA: |
1579 | hcrx->ccid3hcrx_x_recv = 0; | 1580 | hcrx->ccid3hcrx_x_recv = 0; |
1580 | break; | 1581 | break; |
1581 | case TFRC_RSTATE_DATA: { | 1582 | case TFRC_RSTATE_DATA: { |
1582 | u32 delta = now_delta(hcrx->ccid3hcrx_tstamp_last_feedback); | 1583 | u32 delta = now_delta(hcrx->ccid3hcrx_tstamp_last_feedback); |
1583 | 1584 | ||
1584 | if (delta == 0) | 1585 | if (delta == 0) |
1585 | delta = 1; /* to prevent divide by zero */ | 1586 | delta = 1; /* to prevent divide by zero */ |
1586 | hcrx->ccid3hcrx_x_recv = (hcrx->ccid3hcrx_bytes_recv * USEC_IN_SEC) / delta; | 1587 | hcrx->ccid3hcrx_x_recv = (hcrx->ccid3hcrx_bytes_recv * USEC_IN_SEC) / delta; |
1587 | } | 1588 | } |
1588 | break; | 1589 | break; |
1589 | default: | 1590 | default: |
1590 | printk(KERN_CRIT "%s: %s, sk=%p, Illegal state (%d)!\n", | 1591 | printk(KERN_CRIT "%s: %s, sk=%p, Illegal state (%d)!\n", |
1591 | __FUNCTION__, dccp_role(sk), sk, hcrx->ccid3hcrx_state); | 1592 | __FUNCTION__, dccp_role(sk), sk, hcrx->ccid3hcrx_state); |
1592 | dump_stack(); | 1593 | dump_stack(); |
1593 | return; | 1594 | return; |
1594 | } | 1595 | } |
1595 | 1596 | ||
1596 | packet = NULL; | 1597 | packet = NULL; |
1597 | list_for_each_entry(entry, &hcrx->ccid3hcrx_hist, ccid3hrx_node) | 1598 | list_for_each_entry(entry, &hcrx->ccid3hcrx_hist, ccid3hrx_node) |
1598 | if (entry->ccid3hrx_type == DCCP_PKT_DATA || | 1599 | if (entry->ccid3hrx_type == DCCP_PKT_DATA || |
1599 | entry->ccid3hrx_type == DCCP_PKT_DATAACK) { | 1600 | entry->ccid3hrx_type == DCCP_PKT_DATAACK) { |
1600 | packet = entry; | 1601 | packet = entry; |
1601 | break; | 1602 | break; |
1602 | } | 1603 | } |
1603 | 1604 | ||
1604 | if (packet == NULL) { | 1605 | if (packet == NULL) { |
1605 | printk(KERN_CRIT "%s: %s, sk=%p, no data packet in history!\n", | 1606 | printk(KERN_CRIT "%s: %s, sk=%p, no data packet in history!\n", |
1606 | __FUNCTION__, dccp_role(sk), sk); | 1607 | __FUNCTION__, dccp_role(sk), sk); |
1607 | dump_stack(); | 1608 | dump_stack(); |
1608 | return; | 1609 | return; |
1609 | } | 1610 | } |
1610 | 1611 | ||
1611 | do_gettimeofday(&(hcrx->ccid3hcrx_tstamp_last_feedback)); | 1612 | do_gettimeofday(&(hcrx->ccid3hcrx_tstamp_last_feedback)); |
1612 | hcrx->ccid3hcrx_last_counter = packet->ccid3hrx_win_count; | 1613 | hcrx->ccid3hcrx_last_counter = packet->ccid3hrx_win_count; |
1613 | hcrx->ccid3hcrx_seqno_last_counter = packet->ccid3hrx_seqno; | 1614 | hcrx->ccid3hcrx_seqno_last_counter = packet->ccid3hrx_seqno; |
1614 | hcrx->ccid3hcrx_bytes_recv = 0; | 1615 | hcrx->ccid3hcrx_bytes_recv = 0; |
1615 | 1616 | ||
1616 | /* Convert to multiples of 10us */ | 1617 | /* Convert to multiples of 10us */ |
1617 | hcrx->ccid3hcrx_elapsed_time = now_delta(packet->ccid3hrx_tstamp) / 10; | 1618 | hcrx->ccid3hcrx_elapsed_time = now_delta(packet->ccid3hrx_tstamp) / 10; |
1618 | if (hcrx->ccid3hcrx_p == 0) | 1619 | if (hcrx->ccid3hcrx_p == 0) |
1619 | hcrx->ccid3hcrx_pinv = ~0; | 1620 | hcrx->ccid3hcrx_pinv = ~0; |
1620 | else | 1621 | else |
1621 | hcrx->ccid3hcrx_pinv = 1000000 / hcrx->ccid3hcrx_p; | 1622 | hcrx->ccid3hcrx_pinv = 1000000 / hcrx->ccid3hcrx_p; |
1622 | dccp_send_ack(sk); | 1623 | dccp_send_ack(sk); |
1623 | } | 1624 | } |
1624 | 1625 | ||
1625 | static void ccid3_hc_rx_insert_options(struct sock *sk, struct sk_buff *skb) | 1626 | static void ccid3_hc_rx_insert_options(struct sock *sk, struct sk_buff *skb) |
1626 | { | 1627 | { |
1627 | const struct dccp_sock *dp = dccp_sk(sk); | 1628 | const struct dccp_sock *dp = dccp_sk(sk); |
1628 | struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private; | 1629 | struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private; |
1629 | 1630 | ||
1630 | if (hcrx == NULL || !(sk->sk_state == DCCP_OPEN || sk->sk_state == DCCP_PARTOPEN)) | 1631 | if (hcrx == NULL || !(sk->sk_state == DCCP_OPEN || sk->sk_state == DCCP_PARTOPEN)) |
1631 | return; | 1632 | return; |
1632 | 1633 | ||
1633 | if (hcrx->ccid3hcrx_elapsed_time != 0 && !dccp_packet_without_ack(skb)) | 1634 | if (hcrx->ccid3hcrx_elapsed_time != 0 && !dccp_packet_without_ack(skb)) |
1634 | dccp_insert_option_elapsed_time(sk, skb, hcrx->ccid3hcrx_elapsed_time); | 1635 | dccp_insert_option_elapsed_time(sk, skb, hcrx->ccid3hcrx_elapsed_time); |
1635 | 1636 | ||
1636 | if (DCCP_SKB_CB(skb)->dccpd_type != DCCP_PKT_DATA) { | 1637 | if (DCCP_SKB_CB(skb)->dccpd_type != DCCP_PKT_DATA) { |
1637 | const u32 x_recv = htonl(hcrx->ccid3hcrx_x_recv); | 1638 | const u32 x_recv = htonl(hcrx->ccid3hcrx_x_recv); |
1638 | const u32 pinv = htonl(hcrx->ccid3hcrx_pinv); | 1639 | const u32 pinv = htonl(hcrx->ccid3hcrx_pinv); |
1639 | 1640 | ||
1640 | dccp_insert_option(sk, skb, TFRC_OPT_LOSS_EVENT_RATE, &pinv, sizeof(pinv)); | 1641 | dccp_insert_option(sk, skb, TFRC_OPT_LOSS_EVENT_RATE, &pinv, sizeof(pinv)); |
1641 | dccp_insert_option(sk, skb, TFRC_OPT_RECEIVE_RATE, &x_recv, sizeof(x_recv)); | 1642 | dccp_insert_option(sk, skb, TFRC_OPT_RECEIVE_RATE, &x_recv, sizeof(x_recv)); |
1642 | } | 1643 | } |
1643 | 1644 | ||
1644 | DCCP_SKB_CB(skb)->dccpd_ccval = hcrx->ccid3hcrx_last_counter; | 1645 | DCCP_SKB_CB(skb)->dccpd_ccval = hcrx->ccid3hcrx_last_counter; |
1645 | } | 1646 | } |
1646 | 1647 | ||
1647 | /* Weights used to calculate loss event rate */ | 1648 | /* Weights used to calculate loss event rate */ |
1648 | /* | 1649 | /* |
1649 | * These are integers as per section 8 of RFC3448. We can then divide by 4 * | 1650 | * These are integers as per section 8 of RFC3448. We can then divide by 4 * |
1650 | * when we use it. | 1651 | * when we use it. |
1651 | */ | 1652 | */ |
1652 | const int ccid3_hc_rx_w[TFRC_RECV_IVAL_F_LENGTH] = { 4, 4, 4, 4, 3, 2, 1, 1, }; | 1653 | const int ccid3_hc_rx_w[TFRC_RECV_IVAL_F_LENGTH] = { 4, 4, 4, 4, 3, 2, 1, 1, }; |
1653 | 1654 | ||
1654 | /* | 1655 | /* |
1655 | * args: fvalue - function value to match | 1656 | * args: fvalue - function value to match |
1656 | * returns: p closest to that value | 1657 | * returns: p closest to that value |
1657 | * | 1658 | * |
1658 | * both fvalue and p are multiplied by 1,000,000 to use ints | 1659 | * both fvalue and p are multiplied by 1,000,000 to use ints |
1659 | */ | 1660 | */ |
1660 | u32 calcx_reverse_lookup(u32 fvalue) { | 1661 | u32 calcx_reverse_lookup(u32 fvalue) { |
1661 | int ctr = 0; | 1662 | int ctr = 0; |
1662 | int small; | 1663 | int small; |
1663 | 1664 | ||
1664 | if (fvalue < calcx_lookup[0][1]) | 1665 | if (fvalue < calcx_lookup[0][1]) |
1665 | return 0; | 1666 | return 0; |
1666 | if (fvalue <= calcx_lookup[CALCX_ARRSIZE-1][1]) | 1667 | if (fvalue <= calcx_lookup[CALCX_ARRSIZE-1][1]) |
1667 | small = 1; | 1668 | small = 1; |
1668 | else if (fvalue > calcx_lookup[CALCX_ARRSIZE-1][0]) | 1669 | else if (fvalue > calcx_lookup[CALCX_ARRSIZE-1][0]) |
1669 | return 1000000; | 1670 | return 1000000; |
1670 | else | 1671 | else |
1671 | small = 0; | 1672 | small = 0; |
1672 | while (fvalue > calcx_lookup[ctr][small]) | 1673 | while (fvalue > calcx_lookup[ctr][small]) |
1673 | ctr++; | 1674 | ctr++; |
1674 | if (small) | 1675 | if (small) |
1675 | return (CALCX_SPLIT * ctr / CALCX_ARRSIZE); | 1676 | return (CALCX_SPLIT * ctr / CALCX_ARRSIZE); |
1676 | else | 1677 | else |
1677 | return (1000000 * ctr / CALCX_ARRSIZE) ; | 1678 | return (1000000 * ctr / CALCX_ARRSIZE) ; |
1678 | } | 1679 | } |
1679 | 1680 | ||
1680 | /* calculate first loss interval | 1681 | /* calculate first loss interval |
1681 | * | 1682 | * |
1682 | * returns estimated loss interval in usecs */ | 1683 | * returns estimated loss interval in usecs */ |
1683 | 1684 | ||
1684 | static u32 ccid3_hc_rx_calc_first_li(struct sock *sk) | 1685 | static u32 ccid3_hc_rx_calc_first_li(struct sock *sk) |
1685 | { | 1686 | { |
1686 | struct dccp_sock *dp = dccp_sk(sk); | 1687 | struct dccp_sock *dp = dccp_sk(sk); |
1687 | struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private; | 1688 | struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private; |
1688 | struct ccid3_rx_hist_entry *entry, *next, *tail = NULL; | 1689 | struct ccid3_rx_hist_entry *entry, *next, *tail = NULL; |
1689 | u32 rtt, delta, x_recv, fval, p, tmp2; | 1690 | u32 rtt, delta, x_recv, fval, p, tmp2; |
1690 | struct timeval tstamp, tmp_tv; | 1691 | struct timeval tstamp, tmp_tv; |
1691 | int interval = 0; | 1692 | int interval = 0; |
1692 | int win_count = 0; | 1693 | int win_count = 0; |
1693 | int step = 0; | 1694 | int step = 0; |
1694 | u64 tmp1; | 1695 | u64 tmp1; |
1695 | 1696 | ||
1696 | list_for_each_entry_safe(entry, next, &hcrx->ccid3hcrx_hist, ccid3hrx_node) { | 1697 | list_for_each_entry_safe(entry, next, &hcrx->ccid3hcrx_hist, ccid3hrx_node) { |
1697 | if (entry->ccid3hrx_type == DCCP_PKT_DATA || | 1698 | if (entry->ccid3hrx_type == DCCP_PKT_DATA || |
1698 | entry->ccid3hrx_type == DCCP_PKT_DATAACK) { | 1699 | entry->ccid3hrx_type == DCCP_PKT_DATAACK) { |
1699 | tail = entry; | 1700 | tail = entry; |
1700 | 1701 | ||
1701 | switch (step) { | 1702 | switch (step) { |
1702 | case 0: | 1703 | case 0: |
1703 | tstamp = entry->ccid3hrx_tstamp; | 1704 | tstamp = entry->ccid3hrx_tstamp; |
1704 | win_count = entry->ccid3hrx_win_count; | 1705 | win_count = entry->ccid3hrx_win_count; |
1705 | step = 1; | 1706 | step = 1; |
1706 | break; | 1707 | break; |
1707 | case 1: | 1708 | case 1: |
1708 | interval = win_count - entry->ccid3hrx_win_count; | 1709 | interval = win_count - entry->ccid3hrx_win_count; |
1709 | if (interval < 0) | 1710 | if (interval < 0) |
1710 | interval += TFRC_WIN_COUNT_LIMIT; | 1711 | interval += TFRC_WIN_COUNT_LIMIT; |
1711 | if (interval > 4) | 1712 | if (interval > 4) |
1712 | goto found; | 1713 | goto found; |
1713 | break; | 1714 | break; |
1714 | } | 1715 | } |
1715 | } | 1716 | } |
1716 | } | 1717 | } |
1717 | 1718 | ||
1718 | if (step == 0) { | 1719 | if (step == 0) { |
1719 | printk(KERN_CRIT "%s: %s, sk=%p, packet history contains no data packets!\n", | 1720 | printk(KERN_CRIT "%s: %s, sk=%p, packet history contains no data packets!\n", |
1720 | __FUNCTION__, dccp_role(sk), sk); | 1721 | __FUNCTION__, dccp_role(sk), sk); |
1721 | return ~0; | 1722 | return ~0; |
1722 | } | 1723 | } |
1723 | 1724 | ||
1724 | if (interval == 0) { | 1725 | if (interval == 0) { |
1725 | ccid3_pr_debug("%s, sk=%p, Could not find a win_count interval > 0. Defaulting to 1\n", | 1726 | ccid3_pr_debug("%s, sk=%p, Could not find a win_count interval > 0. Defaulting to 1\n", |
1726 | dccp_role(sk), sk); | 1727 | dccp_role(sk), sk); |
1727 | interval = 1; | 1728 | interval = 1; |
1728 | } | 1729 | } |
1729 | found: | 1730 | found: |
1730 | timeval_sub(tstamp,tail->ccid3hrx_tstamp,&tmp_tv); | 1731 | timeval_sub(tstamp,tail->ccid3hrx_tstamp,&tmp_tv); |
1731 | rtt = (tmp_tv.tv_sec * USEC_IN_SEC + tmp_tv.tv_usec) * 4 / interval; | 1732 | rtt = (tmp_tv.tv_sec * USEC_IN_SEC + tmp_tv.tv_usec) * 4 / interval; |
1732 | ccid3_pr_debug("%s, sk=%p, approximated RTT to %uus\n", | 1733 | ccid3_pr_debug("%s, sk=%p, approximated RTT to %uus\n", |
1733 | dccp_role(sk), sk, rtt); | 1734 | dccp_role(sk), sk, rtt); |
1734 | if (rtt == 0) | 1735 | if (rtt == 0) |
1735 | rtt = 1; | 1736 | rtt = 1; |
1736 | 1737 | ||
1737 | delta = now_delta(hcrx->ccid3hcrx_tstamp_last_feedback); | 1738 | delta = now_delta(hcrx->ccid3hcrx_tstamp_last_feedback); |
1738 | if (delta == 0) | 1739 | if (delta == 0) |
1739 | delta = 1; | 1740 | delta = 1; |
1740 | 1741 | ||
1741 | x_recv = (hcrx->ccid3hcrx_bytes_recv * USEC_IN_SEC) / delta; | 1742 | x_recv = (hcrx->ccid3hcrx_bytes_recv * USEC_IN_SEC) / delta; |
1742 | 1743 | ||
1743 | tmp1 = (u64)x_recv * (u64)rtt; | 1744 | tmp1 = (u64)x_recv * (u64)rtt; |
1744 | do_div(tmp1,10000000); | 1745 | do_div(tmp1,10000000); |
1745 | tmp2 = (u32)tmp1; | 1746 | tmp2 = (u32)tmp1; |
1746 | fval = (hcrx->ccid3hcrx_s * 100000) / tmp2; | 1747 | fval = (hcrx->ccid3hcrx_s * 100000) / tmp2; |
1747 | /* do not alter order above or you will get overflow on 32 bit */ | 1748 | /* do not alter order above or you will get overflow on 32 bit */ |
1748 | p = calcx_reverse_lookup(fval); | 1749 | p = calcx_reverse_lookup(fval); |
1749 | ccid3_pr_debug("%s, sk=%p, receive rate=%u bytes/s, implied loss rate=%u\n",\ | 1750 | ccid3_pr_debug("%s, sk=%p, receive rate=%u bytes/s, implied loss rate=%u\n",\ |
1750 | dccp_role(sk), sk, x_recv, p); | 1751 | dccp_role(sk), sk, x_recv, p); |
1751 | 1752 | ||
1752 | if (p == 0) | 1753 | if (p == 0) |
1753 | return ~0; | 1754 | return ~0; |
1754 | else | 1755 | else |
1755 | return 1000000 / p; | 1756 | return 1000000 / p; |
1756 | } | 1757 | } |
1757 | 1758 | ||
1758 | static void ccid3_hc_rx_update_li(struct sock *sk, u64 seq_loss, u8 win_loss) | 1759 | static void ccid3_hc_rx_update_li(struct sock *sk, u64 seq_loss, u8 win_loss) |
1759 | { | 1760 | { |
1760 | struct dccp_sock *dp = dccp_sk(sk); | 1761 | struct dccp_sock *dp = dccp_sk(sk); |
1761 | struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private; | 1762 | struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private; |
1762 | struct ccid3_loss_interval_hist_entry *li_entry; | 1763 | struct ccid3_loss_interval_hist_entry *li_entry; |
1763 | 1764 | ||
1764 | if (seq_loss != DCCP_MAX_SEQNO + 1) { | 1765 | if (seq_loss != DCCP_MAX_SEQNO + 1) { |
1765 | ccid3_pr_debug("%s, sk=%p, seq_loss=%llu, win_loss=%u, packet loss detected\n", | 1766 | ccid3_pr_debug("%s, sk=%p, seq_loss=%llu, win_loss=%u, packet loss detected\n", |
1766 | dccp_role(sk), sk, seq_loss, win_loss); | 1767 | dccp_role(sk), sk, seq_loss, win_loss); |
1767 | 1768 | ||
1768 | if (list_empty(&hcrx->ccid3hcrx_loss_interval_hist)) { | 1769 | if (list_empty(&hcrx->ccid3hcrx_loss_interval_hist)) { |
1769 | struct ccid3_loss_interval_hist_entry *li_tail = NULL; | 1770 | struct ccid3_loss_interval_hist_entry *li_tail = NULL; |
1770 | int i; | 1771 | int i; |
1771 | 1772 | ||
1772 | ccid3_pr_debug("%s, sk=%p, first loss event detected, creating history\n", dccp_role(sk), sk); | 1773 | ccid3_pr_debug("%s, sk=%p, first loss event detected, creating history\n", dccp_role(sk), sk); |
1773 | for (i = 0; i <= TFRC_RECV_IVAL_F_LENGTH; ++i) { | 1774 | for (i = 0; i <= TFRC_RECV_IVAL_F_LENGTH; ++i) { |
1774 | li_entry = ccid3_loss_interval_hist_entry_new(SLAB_ATOMIC); | 1775 | li_entry = ccid3_loss_interval_hist_entry_new(SLAB_ATOMIC); |
1775 | if (li_entry == NULL) { | 1776 | if (li_entry == NULL) { |
1776 | ccid3_loss_interval_history_delete(&hcrx->ccid3hcrx_loss_interval_hist); | 1777 | ccid3_loss_interval_history_delete(&hcrx->ccid3hcrx_loss_interval_hist); |
1777 | ccid3_pr_debug("%s, sk=%p, not enough mem for creating history\n", | 1778 | ccid3_pr_debug("%s, sk=%p, not enough mem for creating history\n", |
1778 | dccp_role(sk), sk); | 1779 | dccp_role(sk), sk); |
1779 | return; | 1780 | return; |
1780 | } | 1781 | } |
1781 | if (li_tail == NULL) | 1782 | if (li_tail == NULL) |
1782 | li_tail = li_entry; | 1783 | li_tail = li_entry; |
1783 | list_add(&li_entry->ccid3lih_node, &hcrx->ccid3hcrx_loss_interval_hist); | 1784 | list_add(&li_entry->ccid3lih_node, &hcrx->ccid3hcrx_loss_interval_hist); |
1784 | } | 1785 | } |
1785 | 1786 | ||
1786 | li_entry->ccid3lih_seqno = seq_loss; | 1787 | li_entry->ccid3lih_seqno = seq_loss; |
1787 | li_entry->ccid3lih_win_count = win_loss; | 1788 | li_entry->ccid3lih_win_count = win_loss; |
1788 | 1789 | ||
1789 | li_tail->ccid3lih_interval = ccid3_hc_rx_calc_first_li(sk); | 1790 | li_tail->ccid3lih_interval = ccid3_hc_rx_calc_first_li(sk); |
1790 | } | 1791 | } |
1791 | } | 1792 | } |
1792 | /* FIXME: find end of interval */ | 1793 | /* FIXME: find end of interval */ |
1793 | } | 1794 | } |
1794 | 1795 | ||
1795 | static void ccid3_hc_rx_detect_loss(struct sock *sk) | 1796 | static void ccid3_hc_rx_detect_loss(struct sock *sk) |
1796 | { | 1797 | { |
1797 | struct dccp_sock *dp = dccp_sk(sk); | 1798 | struct dccp_sock *dp = dccp_sk(sk); |
1798 | struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private; | 1799 | struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private; |
1799 | struct ccid3_rx_hist_entry *entry, *a_next, *b_next, *packet; | 1800 | struct ccid3_rx_hist_entry *entry, *a_next, *b_next, *packet; |
1800 | struct ccid3_rx_hist_entry *a_loss = NULL; | 1801 | struct ccid3_rx_hist_entry *a_loss = NULL; |
1801 | struct ccid3_rx_hist_entry *b_loss = NULL; | 1802 | struct ccid3_rx_hist_entry *b_loss = NULL; |
1802 | u64 seq_loss = DCCP_MAX_SEQNO + 1; | 1803 | u64 seq_loss = DCCP_MAX_SEQNO + 1; |
1803 | u8 win_loss = 0; | 1804 | u8 win_loss = 0; |
1804 | u8 num_later = TFRC_RECV_NUM_LATE_LOSS; | 1805 | u8 num_later = TFRC_RECV_NUM_LATE_LOSS; |
1805 | 1806 | ||
1806 | list_for_each_entry_safe(entry, b_next, &hcrx->ccid3hcrx_hist, ccid3hrx_node) { | 1807 | list_for_each_entry_safe(entry, b_next, &hcrx->ccid3hcrx_hist, ccid3hrx_node) { |
1807 | if (num_later == 0) { | 1808 | if (num_later == 0) { |
1808 | b_loss = entry; | 1809 | b_loss = entry; |
1809 | break; | 1810 | break; |
1810 | } else if (entry->ccid3hrx_type == DCCP_PKT_DATA || | 1811 | } else if (entry->ccid3hrx_type == DCCP_PKT_DATA || |
1811 | entry->ccid3hrx_type == DCCP_PKT_DATAACK) | 1812 | entry->ccid3hrx_type == DCCP_PKT_DATAACK) |
1812 | --num_later; | 1813 | --num_later; |
1813 | } | 1814 | } |
1814 | 1815 | ||
1815 | if (b_loss == NULL) | 1816 | if (b_loss == NULL) |
1816 | goto out_update_li; | 1817 | goto out_update_li; |
1817 | 1818 | ||
1818 | a_next = b_next; | 1819 | a_next = b_next; |
1819 | num_later = 1; | 1820 | num_later = 1; |
1820 | 1821 | ||
1821 | list_for_each_entry_safe_continue(entry, a_next, &hcrx->ccid3hcrx_hist, ccid3hrx_node) { | 1822 | list_for_each_entry_safe_continue(entry, a_next, &hcrx->ccid3hcrx_hist, ccid3hrx_node) { |
1822 | if (num_later == 0) { | 1823 | if (num_later == 0) { |
1823 | a_loss = entry; | 1824 | a_loss = entry; |
1824 | break; | 1825 | break; |
1825 | } else if (entry->ccid3hrx_type == DCCP_PKT_DATA || | 1826 | } else if (entry->ccid3hrx_type == DCCP_PKT_DATA || |
1826 | entry->ccid3hrx_type == DCCP_PKT_DATAACK) | 1827 | entry->ccid3hrx_type == DCCP_PKT_DATAACK) |
1827 | --num_later; | 1828 | --num_later; |
1828 | } | 1829 | } |
1829 | 1830 | ||
1830 | if (a_loss == NULL) { | 1831 | if (a_loss == NULL) { |
1831 | if (list_empty(&hcrx->ccid3hcrx_loss_interval_hist)) { | 1832 | if (list_empty(&hcrx->ccid3hcrx_loss_interval_hist)) { |
1832 | /* no loss event have occured yet */ | 1833 | /* no loss event have occured yet */ |
1833 | ccid3_pr_debug("%s, sk=%p, TODO: find a lost data " | 1834 | ccid3_pr_debug("%s, sk=%p, TODO: find a lost data " |
1834 | "packet by comparing to initial seqno\n", | 1835 | "packet by comparing to initial seqno\n", |
1835 | dccp_role(sk), sk); | 1836 | dccp_role(sk), sk); |
1836 | goto out_update_li; | 1837 | goto out_update_li; |
1837 | } else { | 1838 | } else { |
1838 | pr_info("%s: %s, sk=%p, ERROR! Less than 4 data packets in history", | 1839 | pr_info("%s: %s, sk=%p, ERROR! Less than 4 data packets in history", |
1839 | __FUNCTION__, dccp_role(sk), sk); | 1840 | __FUNCTION__, dccp_role(sk), sk); |
1840 | return; | 1841 | return; |
1841 | } | 1842 | } |
1842 | } | 1843 | } |
1843 | 1844 | ||
1844 | /* Locate a lost data packet */ | 1845 | /* Locate a lost data packet */ |
1845 | entry = packet = b_loss; | 1846 | entry = packet = b_loss; |
1846 | list_for_each_entry_safe_continue(entry, b_next, &hcrx->ccid3hcrx_hist, ccid3hrx_node) { | 1847 | list_for_each_entry_safe_continue(entry, b_next, &hcrx->ccid3hcrx_hist, ccid3hrx_node) { |
1847 | u64 delta = dccp_delta_seqno(entry->ccid3hrx_seqno, packet->ccid3hrx_seqno); | 1848 | u64 delta = dccp_delta_seqno(entry->ccid3hrx_seqno, packet->ccid3hrx_seqno); |
1848 | 1849 | ||
1849 | if (delta != 0) { | 1850 | if (delta != 0) { |
1850 | if (packet->ccid3hrx_type == DCCP_PKT_DATA || | 1851 | if (packet->ccid3hrx_type == DCCP_PKT_DATA || |
1851 | packet->ccid3hrx_type == DCCP_PKT_DATAACK) | 1852 | packet->ccid3hrx_type == DCCP_PKT_DATAACK) |
1852 | --delta; | 1853 | --delta; |
1853 | /* | 1854 | /* |
1854 | * FIXME: check this, probably this % usage is because | 1855 | * FIXME: check this, probably this % usage is because |
1855 | * in earlier drafts the ndp count was just 8 bits | 1856 | * in earlier drafts the ndp count was just 8 bits |
1856 | * long, but now it cam be up to 24 bits long. | 1857 | * long, but now it cam be up to 24 bits long. |
1857 | */ | 1858 | */ |
1858 | #if 0 | 1859 | #if 0 |
1859 | if (delta % DCCP_NDP_LIMIT != | 1860 | if (delta % DCCP_NDP_LIMIT != |
1860 | (packet->ccid3hrx_ndp - entry->ccid3hrx_ndp) % DCCP_NDP_LIMIT) | 1861 | (packet->ccid3hrx_ndp - entry->ccid3hrx_ndp) % DCCP_NDP_LIMIT) |
1861 | #endif | 1862 | #endif |
1862 | if (delta != packet->ccid3hrx_ndp - entry->ccid3hrx_ndp) { | 1863 | if (delta != packet->ccid3hrx_ndp - entry->ccid3hrx_ndp) { |
1863 | seq_loss = entry->ccid3hrx_seqno; | 1864 | seq_loss = entry->ccid3hrx_seqno; |
1864 | dccp_inc_seqno(&seq_loss); | 1865 | dccp_inc_seqno(&seq_loss); |
1865 | } | 1866 | } |
1866 | } | 1867 | } |
1867 | packet = entry; | 1868 | packet = entry; |
1868 | if (packet == a_loss) | 1869 | if (packet == a_loss) |
1869 | break; | 1870 | break; |
1870 | } | 1871 | } |
1871 | 1872 | ||
1872 | if (seq_loss != DCCP_MAX_SEQNO + 1) | 1873 | if (seq_loss != DCCP_MAX_SEQNO + 1) |
1873 | win_loss = a_loss->ccid3hrx_win_count; | 1874 | win_loss = a_loss->ccid3hrx_win_count; |
1874 | 1875 | ||
1875 | out_update_li: | 1876 | out_update_li: |
1876 | ccid3_hc_rx_update_li(sk, seq_loss, win_loss); | 1877 | ccid3_hc_rx_update_li(sk, seq_loss, win_loss); |
1877 | } | 1878 | } |
1878 | 1879 | ||
1879 | static u32 ccid3_hc_rx_calc_i_mean(struct sock *sk) | 1880 | static u32 ccid3_hc_rx_calc_i_mean(struct sock *sk) |
1880 | { | 1881 | { |
1881 | struct dccp_sock *dp = dccp_sk(sk); | 1882 | struct dccp_sock *dp = dccp_sk(sk); |
1882 | struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private; | 1883 | struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private; |
1883 | struct ccid3_loss_interval_hist_entry *li_entry, *li_next; | 1884 | struct ccid3_loss_interval_hist_entry *li_entry, *li_next; |
1884 | int i = 0; | 1885 | int i = 0; |
1885 | u32 i_tot; | 1886 | u32 i_tot; |
1886 | u32 i_tot0 = 0; | 1887 | u32 i_tot0 = 0; |
1887 | u32 i_tot1 = 0; | 1888 | u32 i_tot1 = 0; |
1888 | u32 w_tot = 0; | 1889 | u32 w_tot = 0; |
1889 | 1890 | ||
1890 | list_for_each_entry_safe(li_entry, li_next, &hcrx->ccid3hcrx_loss_interval_hist, ccid3lih_node) { | 1891 | list_for_each_entry_safe(li_entry, li_next, &hcrx->ccid3hcrx_loss_interval_hist, ccid3lih_node) { |
1891 | if (i < TFRC_RECV_IVAL_F_LENGTH) { | 1892 | if (i < TFRC_RECV_IVAL_F_LENGTH) { |
1892 | i_tot0 += li_entry->ccid3lih_interval * ccid3_hc_rx_w[i]; | 1893 | i_tot0 += li_entry->ccid3lih_interval * ccid3_hc_rx_w[i]; |
1893 | w_tot += ccid3_hc_rx_w[i]; | 1894 | w_tot += ccid3_hc_rx_w[i]; |
1894 | } | 1895 | } |
1895 | 1896 | ||
1896 | if (i != 0) | 1897 | if (i != 0) |
1897 | i_tot1 += li_entry->ccid3lih_interval * ccid3_hc_rx_w[i - 1]; | 1898 | i_tot1 += li_entry->ccid3lih_interval * ccid3_hc_rx_w[i - 1]; |
1898 | 1899 | ||
1899 | if (++i > TFRC_RECV_IVAL_F_LENGTH) | 1900 | if (++i > TFRC_RECV_IVAL_F_LENGTH) |
1900 | break; | 1901 | break; |
1901 | } | 1902 | } |
1902 | 1903 | ||
1903 | if (i != TFRC_RECV_IVAL_F_LENGTH) { | 1904 | if (i != TFRC_RECV_IVAL_F_LENGTH) { |
1904 | pr_info("%s: %s, sk=%p, ERROR! Missing entry in interval history!\n", | 1905 | pr_info("%s: %s, sk=%p, ERROR! Missing entry in interval history!\n", |
1905 | __FUNCTION__, dccp_role(sk), sk); | 1906 | __FUNCTION__, dccp_role(sk), sk); |
1906 | return 0; | 1907 | return 0; |
1907 | } | 1908 | } |
1908 | 1909 | ||
1909 | i_tot = max(i_tot0, i_tot1); | 1910 | i_tot = max(i_tot0, i_tot1); |
1910 | 1911 | ||
1911 | /* FIXME: Why do we do this? -Ian McDonald */ | 1912 | /* FIXME: Why do we do this? -Ian McDonald */ |
1912 | if (i_tot * 4 < w_tot) | 1913 | if (i_tot * 4 < w_tot) |
1913 | i_tot = w_tot * 4; | 1914 | i_tot = w_tot * 4; |
1914 | 1915 | ||
1915 | return i_tot * 4 / w_tot; | 1916 | return i_tot * 4 / w_tot; |
1916 | } | 1917 | } |
1917 | 1918 | ||
1918 | static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb) | 1919 | static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb) |
1919 | { | 1920 | { |
1920 | struct dccp_sock *dp = dccp_sk(sk); | 1921 | struct dccp_sock *dp = dccp_sk(sk); |
1921 | struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private; | 1922 | struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private; |
1922 | struct ccid3_rx_hist_entry *packet; | 1923 | struct ccid3_rx_hist_entry *packet; |
1923 | struct timeval now; | 1924 | struct timeval now; |
1924 | u8 win_count; | 1925 | u8 win_count; |
1925 | u32 p_prev; | 1926 | u32 p_prev; |
1926 | int ins; | 1927 | int ins; |
1927 | #if 0 | 1928 | #if 0 |
1928 | ccid3_pr_debug("%s, sk=%p(%s), skb=%p(%s)\n", | 1929 | ccid3_pr_debug("%s, sk=%p(%s), skb=%p(%s)\n", |
1929 | dccp_role(sk), sk, dccp_state_name(sk->sk_state), | 1930 | dccp_role(sk), sk, dccp_state_name(sk->sk_state), |
1930 | skb, dccp_packet_name(DCCP_SKB_CB(skb)->dccpd_type)); | 1931 | skb, dccp_packet_name(DCCP_SKB_CB(skb)->dccpd_type)); |
1931 | #endif | 1932 | #endif |
1932 | if (hcrx == NULL) | 1933 | if (hcrx == NULL) |
1933 | return; | 1934 | return; |
1934 | 1935 | ||
1935 | BUG_ON(!(hcrx->ccid3hcrx_state == TFRC_RSTATE_NO_DATA || | 1936 | BUG_ON(!(hcrx->ccid3hcrx_state == TFRC_RSTATE_NO_DATA || |
1936 | hcrx->ccid3hcrx_state == TFRC_RSTATE_DATA)); | 1937 | hcrx->ccid3hcrx_state == TFRC_RSTATE_DATA)); |
1937 | 1938 | ||
1938 | switch (DCCP_SKB_CB(skb)->dccpd_type) { | 1939 | switch (DCCP_SKB_CB(skb)->dccpd_type) { |
1939 | case DCCP_PKT_ACK: | 1940 | case DCCP_PKT_ACK: |
1940 | if (hcrx->ccid3hcrx_state == TFRC_RSTATE_NO_DATA) | 1941 | if (hcrx->ccid3hcrx_state == TFRC_RSTATE_NO_DATA) |
1941 | return; | 1942 | return; |
1942 | case DCCP_PKT_DATAACK: | 1943 | case DCCP_PKT_DATAACK: |
1943 | if (dp->dccps_options_received.dccpor_timestamp_echo == 0) | 1944 | if (dp->dccps_options_received.dccpor_timestamp_echo == 0) |
1944 | break; | 1945 | break; |
1945 | p_prev = hcrx->ccid3hcrx_rtt; | 1946 | p_prev = hcrx->ccid3hcrx_rtt; |
1946 | do_gettimeofday(&now); | 1947 | do_gettimeofday(&now); |
1947 | /* hcrx->ccid3hcrx_rtt = now - dp->dccps_options_received.dccpor_timestamp_echo - | 1948 | /* hcrx->ccid3hcrx_rtt = now - dp->dccps_options_received.dccpor_timestamp_echo - |
1948 | usecs_to_jiffies(dp->dccps_options_received.dccpor_elapsed_time * 10); | 1949 | usecs_to_jiffies(dp->dccps_options_received.dccpor_elapsed_time * 10); |
1949 | FIXME - I think above code is broken - have to look at options more, will also need | 1950 | FIXME - I think above code is broken - have to look at options more, will also need |
1950 | to fix pr_debug below */ | 1951 | to fix pr_debug below */ |
1951 | if (p_prev != hcrx->ccid3hcrx_rtt) | 1952 | if (p_prev != hcrx->ccid3hcrx_rtt) |
1952 | ccid3_pr_debug("%s, sk=%p, New RTT estimate=%lu jiffies, tstamp_echo=%u, elapsed time=%u\n", | 1953 | ccid3_pr_debug("%s, sk=%p, New RTT estimate=%lu jiffies, tstamp_echo=%u, elapsed time=%u\n", |
1953 | dccp_role(sk), sk, hcrx->ccid3hcrx_rtt, | 1954 | dccp_role(sk), sk, hcrx->ccid3hcrx_rtt, |
1954 | dp->dccps_options_received.dccpor_timestamp_echo, | 1955 | dp->dccps_options_received.dccpor_timestamp_echo, |
1955 | dp->dccps_options_received.dccpor_elapsed_time); | 1956 | dp->dccps_options_received.dccpor_elapsed_time); |
1956 | break; | 1957 | break; |
1957 | case DCCP_PKT_DATA: | 1958 | case DCCP_PKT_DATA: |
1958 | break; | 1959 | break; |
1959 | default: | 1960 | default: |
1960 | ccid3_pr_debug("%s, sk=%p, not DATA/DATAACK/ACK packet(%s)\n", | 1961 | ccid3_pr_debug("%s, sk=%p, not DATA/DATAACK/ACK packet(%s)\n", |
1961 | dccp_role(sk), sk, | 1962 | dccp_role(sk), sk, |
1962 | dccp_packet_name(DCCP_SKB_CB(skb)->dccpd_type)); | 1963 | dccp_packet_name(DCCP_SKB_CB(skb)->dccpd_type)); |
1963 | return; | 1964 | return; |
1964 | } | 1965 | } |
1965 | 1966 | ||
1966 | packet = ccid3_rx_hist_entry_new(sk, skb, SLAB_ATOMIC); | 1967 | packet = ccid3_rx_hist_entry_new(sk, skb, SLAB_ATOMIC); |
1967 | if (packet == NULL) { | 1968 | if (packet == NULL) { |
1968 | ccid3_pr_debug("%s, sk=%p, Not enough mem to add rx packet to history (consider it lost)!", | 1969 | ccid3_pr_debug("%s, sk=%p, Not enough mem to add rx packet to history (consider it lost)!", |
1969 | dccp_role(sk), sk); | 1970 | dccp_role(sk), sk); |
1970 | return; | 1971 | return; |
1971 | } | 1972 | } |
1972 | 1973 | ||
1973 | win_count = packet->ccid3hrx_win_count; | 1974 | win_count = packet->ccid3hrx_win_count; |
1974 | 1975 | ||
1975 | ins = ccid3_hc_rx_add_hist(sk, packet); | 1976 | ins = ccid3_hc_rx_add_hist(sk, packet); |
1976 | 1977 | ||
1977 | if (DCCP_SKB_CB(skb)->dccpd_type == DCCP_PKT_ACK) | 1978 | if (DCCP_SKB_CB(skb)->dccpd_type == DCCP_PKT_ACK) |
1978 | return; | 1979 | return; |
1979 | 1980 | ||
1980 | switch (hcrx->ccid3hcrx_state) { | 1981 | switch (hcrx->ccid3hcrx_state) { |
1981 | case TFRC_RSTATE_NO_DATA: | 1982 | case TFRC_RSTATE_NO_DATA: |
1982 | ccid3_pr_debug("%s, sk=%p(%s), skb=%p, sending initial feedback\n", | 1983 | ccid3_pr_debug("%s, sk=%p(%s), skb=%p, sending initial feedback\n", |
1983 | dccp_role(sk), sk, dccp_state_name(sk->sk_state), skb); | 1984 | dccp_role(sk), sk, dccp_state_name(sk->sk_state), skb); |
1984 | ccid3_hc_rx_send_feedback(sk); | 1985 | ccid3_hc_rx_send_feedback(sk); |
1985 | ccid3_hc_rx_set_state(sk, TFRC_RSTATE_DATA); | 1986 | ccid3_hc_rx_set_state(sk, TFRC_RSTATE_DATA); |
1986 | return; | 1987 | return; |
1987 | case TFRC_RSTATE_DATA: | 1988 | case TFRC_RSTATE_DATA: |
1988 | hcrx->ccid3hcrx_bytes_recv += skb->len - dccp_hdr(skb)->dccph_doff * 4; | 1989 | hcrx->ccid3hcrx_bytes_recv += skb->len - dccp_hdr(skb)->dccph_doff * 4; |
1989 | if (ins == 0) { | 1990 | if (ins == 0) { |
1990 | do_gettimeofday(&now); | 1991 | do_gettimeofday(&now); |
1991 | if ((now_delta(hcrx->ccid3hcrx_tstamp_last_ack)) >= hcrx->ccid3hcrx_rtt) { | 1992 | if ((now_delta(hcrx->ccid3hcrx_tstamp_last_ack)) >= hcrx->ccid3hcrx_rtt) { |
1992 | hcrx->ccid3hcrx_tstamp_last_ack = now; | 1993 | hcrx->ccid3hcrx_tstamp_last_ack = now; |
1993 | ccid3_hc_rx_send_feedback(sk); | 1994 | ccid3_hc_rx_send_feedback(sk); |
1994 | } | 1995 | } |
1995 | return; | 1996 | return; |
1996 | } | 1997 | } |
1997 | break; | 1998 | break; |
1998 | default: | 1999 | default: |
1999 | printk(KERN_CRIT "%s: %s, sk=%p, Illegal state (%d)!\n", | 2000 | printk(KERN_CRIT "%s: %s, sk=%p, Illegal state (%d)!\n", |
2000 | __FUNCTION__, dccp_role(sk), sk, hcrx->ccid3hcrx_state); | 2001 | __FUNCTION__, dccp_role(sk), sk, hcrx->ccid3hcrx_state); |
2001 | dump_stack(); | 2002 | dump_stack(); |
2002 | return; | 2003 | return; |
2003 | } | 2004 | } |
2004 | 2005 | ||
2005 | /* Dealing with packet loss */ | 2006 | /* Dealing with packet loss */ |
2006 | ccid3_pr_debug("%s, sk=%p(%s), skb=%p, data loss! Reacting...\n", | 2007 | ccid3_pr_debug("%s, sk=%p(%s), skb=%p, data loss! Reacting...\n", |
2007 | dccp_role(sk), sk, dccp_state_name(sk->sk_state), skb); | 2008 | dccp_role(sk), sk, dccp_state_name(sk->sk_state), skb); |
2008 | 2009 | ||
2009 | ccid3_hc_rx_detect_loss(sk); | 2010 | ccid3_hc_rx_detect_loss(sk); |
2010 | p_prev = hcrx->ccid3hcrx_p; | 2011 | p_prev = hcrx->ccid3hcrx_p; |
2011 | 2012 | ||
2012 | /* Calculate loss event rate */ | 2013 | /* Calculate loss event rate */ |
2013 | if (!list_empty(&hcrx->ccid3hcrx_loss_interval_hist)) | 2014 | if (!list_empty(&hcrx->ccid3hcrx_loss_interval_hist)) |
2014 | /* Scaling up by 1000000 as fixed decimal */ | 2015 | /* Scaling up by 1000000 as fixed decimal */ |
2015 | hcrx->ccid3hcrx_p = 1000000 / ccid3_hc_rx_calc_i_mean(sk); | 2016 | hcrx->ccid3hcrx_p = 1000000 / ccid3_hc_rx_calc_i_mean(sk); |
2016 | 2017 | ||
2017 | if (hcrx->ccid3hcrx_p > p_prev) { | 2018 | if (hcrx->ccid3hcrx_p > p_prev) { |
2018 | ccid3_hc_rx_send_feedback(sk); | 2019 | ccid3_hc_rx_send_feedback(sk); |
2019 | return; | 2020 | return; |
2020 | } | 2021 | } |
2021 | } | 2022 | } |
2022 | 2023 | ||
2023 | static int ccid3_hc_rx_init(struct sock *sk) | 2024 | static int ccid3_hc_rx_init(struct sock *sk) |
2024 | { | 2025 | { |
2025 | struct dccp_sock *dp = dccp_sk(sk); | 2026 | struct dccp_sock *dp = dccp_sk(sk); |
2026 | struct ccid3_hc_rx_sock *hcrx; | 2027 | struct ccid3_hc_rx_sock *hcrx; |
2027 | 2028 | ||
2028 | ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk); | 2029 | ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk); |
2029 | 2030 | ||
2030 | hcrx = dp->dccps_hc_rx_ccid_private = kmalloc(sizeof(*hcrx), gfp_any()); | 2031 | hcrx = dp->dccps_hc_rx_ccid_private = kmalloc(sizeof(*hcrx), gfp_any()); |
2031 | if (hcrx == NULL) | 2032 | if (hcrx == NULL) |
2032 | return -ENOMEM; | 2033 | return -ENOMEM; |
2033 | 2034 | ||
2034 | memset(hcrx, 0, sizeof(*hcrx)); | 2035 | memset(hcrx, 0, sizeof(*hcrx)); |
2035 | 2036 | ||
2036 | if (dp->dccps_avg_packet_size >= TFRC_MIN_PACKET_SIZE && | 2037 | if (dp->dccps_avg_packet_size >= TFRC_MIN_PACKET_SIZE && |
2037 | dp->dccps_avg_packet_size <= TFRC_MAX_PACKET_SIZE) | 2038 | dp->dccps_avg_packet_size <= TFRC_MAX_PACKET_SIZE) |
2038 | hcrx->ccid3hcrx_s = (u16)dp->dccps_avg_packet_size; | 2039 | hcrx->ccid3hcrx_s = (u16)dp->dccps_avg_packet_size; |
2039 | else | 2040 | else |
2040 | hcrx->ccid3hcrx_s = TFRC_STD_PACKET_SIZE; | 2041 | hcrx->ccid3hcrx_s = TFRC_STD_PACKET_SIZE; |
2041 | 2042 | ||
2042 | hcrx->ccid3hcrx_state = TFRC_RSTATE_NO_DATA; | 2043 | hcrx->ccid3hcrx_state = TFRC_RSTATE_NO_DATA; |
2043 | INIT_LIST_HEAD(&hcrx->ccid3hcrx_hist); | 2044 | INIT_LIST_HEAD(&hcrx->ccid3hcrx_hist); |
2044 | INIT_LIST_HEAD(&hcrx->ccid3hcrx_loss_interval_hist); | 2045 | INIT_LIST_HEAD(&hcrx->ccid3hcrx_loss_interval_hist); |
2045 | 2046 | ||
2046 | return 0; | 2047 | return 0; |
2047 | } | 2048 | } |
2048 | 2049 | ||
2049 | static void ccid3_hc_rx_exit(struct sock *sk) | 2050 | static void ccid3_hc_rx_exit(struct sock *sk) |
2050 | { | 2051 | { |
2051 | struct dccp_sock *dp = dccp_sk(sk); | 2052 | struct dccp_sock *dp = dccp_sk(sk); |
2052 | struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private; | 2053 | struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private; |
2053 | 2054 | ||
2054 | ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk); | 2055 | ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk); |
2055 | 2056 | ||
2056 | if (hcrx == NULL) | 2057 | if (hcrx == NULL) |
2057 | return; | 2058 | return; |
2058 | 2059 | ||
2059 | ccid3_hc_rx_set_state(sk, TFRC_RSTATE_TERM); | 2060 | ccid3_hc_rx_set_state(sk, TFRC_RSTATE_TERM); |
2060 | 2061 | ||
2061 | /* Empty packet history */ | 2062 | /* Empty packet history */ |
2062 | ccid3_rx_history_delete(&hcrx->ccid3hcrx_hist); | 2063 | ccid3_rx_history_delete(&hcrx->ccid3hcrx_hist); |
2063 | 2064 | ||
2064 | /* Empty loss interval history */ | 2065 | /* Empty loss interval history */ |
2065 | ccid3_loss_interval_history_delete(&hcrx->ccid3hcrx_loss_interval_hist); | 2066 | ccid3_loss_interval_history_delete(&hcrx->ccid3hcrx_loss_interval_hist); |
2066 | 2067 | ||
2067 | kfree(dp->dccps_hc_rx_ccid_private); | 2068 | kfree(dp->dccps_hc_rx_ccid_private); |
2068 | dp->dccps_hc_rx_ccid_private = NULL; | 2069 | dp->dccps_hc_rx_ccid_private = NULL; |
2069 | } | 2070 | } |
2070 | 2071 | ||
2071 | static struct ccid ccid3 = { | 2072 | static struct ccid ccid3 = { |
2072 | .ccid_id = 3, | 2073 | .ccid_id = 3, |
2073 | .ccid_name = "ccid3", | 2074 | .ccid_name = "ccid3", |
2074 | .ccid_owner = THIS_MODULE, | 2075 | .ccid_owner = THIS_MODULE, |
2075 | .ccid_init = ccid3_init, | 2076 | .ccid_init = ccid3_init, |
2076 | .ccid_exit = ccid3_exit, | 2077 | .ccid_exit = ccid3_exit, |
2077 | .ccid_hc_tx_init = ccid3_hc_tx_init, | 2078 | .ccid_hc_tx_init = ccid3_hc_tx_init, |
2078 | .ccid_hc_tx_exit = ccid3_hc_tx_exit, | 2079 | .ccid_hc_tx_exit = ccid3_hc_tx_exit, |
2079 | .ccid_hc_tx_send_packet = ccid3_hc_tx_send_packet, | 2080 | .ccid_hc_tx_send_packet = ccid3_hc_tx_send_packet, |
2080 | .ccid_hc_tx_packet_sent = ccid3_hc_tx_packet_sent, | 2081 | .ccid_hc_tx_packet_sent = ccid3_hc_tx_packet_sent, |
2081 | .ccid_hc_tx_packet_recv = ccid3_hc_tx_packet_recv, | 2082 | .ccid_hc_tx_packet_recv = ccid3_hc_tx_packet_recv, |
2082 | .ccid_hc_tx_insert_options = ccid3_hc_tx_insert_options, | 2083 | .ccid_hc_tx_insert_options = ccid3_hc_tx_insert_options, |
2083 | .ccid_hc_tx_parse_options = ccid3_hc_tx_parse_options, | 2084 | .ccid_hc_tx_parse_options = ccid3_hc_tx_parse_options, |
2084 | .ccid_hc_rx_init = ccid3_hc_rx_init, | 2085 | .ccid_hc_rx_init = ccid3_hc_rx_init, |
2085 | .ccid_hc_rx_exit = ccid3_hc_rx_exit, | 2086 | .ccid_hc_rx_exit = ccid3_hc_rx_exit, |
2086 | .ccid_hc_rx_insert_options = ccid3_hc_rx_insert_options, | 2087 | .ccid_hc_rx_insert_options = ccid3_hc_rx_insert_options, |
2087 | .ccid_hc_rx_packet_recv = ccid3_hc_rx_packet_recv, | 2088 | .ccid_hc_rx_packet_recv = ccid3_hc_rx_packet_recv, |
2088 | }; | 2089 | }; |
2089 | 2090 | ||
2090 | module_param(ccid3_debug, int, 0444); | 2091 | module_param(ccid3_debug, int, 0444); |
2091 | MODULE_PARM_DESC(ccid3_debug, "Enable debug messages"); | 2092 | MODULE_PARM_DESC(ccid3_debug, "Enable debug messages"); |
2092 | 2093 | ||
2093 | static __init int ccid3_module_init(void) | 2094 | static __init int ccid3_module_init(void) |
2094 | { | 2095 | { |
2095 | int rc = -ENOMEM; | 2096 | int rc = -ENOMEM; |
2096 | 2097 | ||
2097 | ccid3_tx_hist_slab = kmem_cache_create("dccp_ccid3_tx_history", | 2098 | ccid3_tx_hist_slab = kmem_cache_create("dccp_ccid3_tx_history", |
2098 | sizeof(struct ccid3_tx_hist_entry), 0, | 2099 | sizeof(struct ccid3_tx_hist_entry), 0, |
2099 | SLAB_HWCACHE_ALIGN, NULL, NULL); | 2100 | SLAB_HWCACHE_ALIGN, NULL, NULL); |
2100 | if (ccid3_tx_hist_slab == NULL) | 2101 | if (ccid3_tx_hist_slab == NULL) |
2101 | goto out; | 2102 | goto out; |
2102 | 2103 | ||
2103 | ccid3_rx_hist_slab = kmem_cache_create("dccp_ccid3_rx_history", | 2104 | ccid3_rx_hist_slab = kmem_cache_create("dccp_ccid3_rx_history", |
2104 | sizeof(struct ccid3_rx_hist_entry), 0, | 2105 | sizeof(struct ccid3_rx_hist_entry), 0, |
2105 | SLAB_HWCACHE_ALIGN, NULL, NULL); | 2106 | SLAB_HWCACHE_ALIGN, NULL, NULL); |
2106 | if (ccid3_rx_hist_slab == NULL) | 2107 | if (ccid3_rx_hist_slab == NULL) |
2107 | goto out_free_tx_history; | 2108 | goto out_free_tx_history; |
2108 | 2109 | ||
2109 | ccid3_loss_interval_hist_slab = kmem_cache_create("dccp_ccid3_loss_interval_history", | 2110 | ccid3_loss_interval_hist_slab = kmem_cache_create("dccp_ccid3_loss_interval_history", |
2110 | sizeof(struct ccid3_loss_interval_hist_entry), 0, | 2111 | sizeof(struct ccid3_loss_interval_hist_entry), 0, |
2111 | SLAB_HWCACHE_ALIGN, NULL, NULL); | 2112 | SLAB_HWCACHE_ALIGN, NULL, NULL); |
2112 | if (ccid3_loss_interval_hist_slab == NULL) | 2113 | if (ccid3_loss_interval_hist_slab == NULL) |
2113 | goto out_free_rx_history; | 2114 | goto out_free_rx_history; |
2114 | 2115 | ||
2115 | rc = ccid_register(&ccid3); | 2116 | rc = ccid_register(&ccid3); |
2116 | if (rc != 0) | 2117 | if (rc != 0) |
2117 | goto out_free_loss_interval_history; | 2118 | goto out_free_loss_interval_history; |
2118 | 2119 | ||
2119 | out: | 2120 | out: |
2120 | return rc; | 2121 | return rc; |
2121 | out_free_loss_interval_history: | 2122 | out_free_loss_interval_history: |
2122 | kmem_cache_destroy(ccid3_loss_interval_hist_slab); | 2123 | kmem_cache_destroy(ccid3_loss_interval_hist_slab); |
2123 | ccid3_loss_interval_hist_slab = NULL; | 2124 | ccid3_loss_interval_hist_slab = NULL; |
2124 | out_free_rx_history: | 2125 | out_free_rx_history: |
2125 | kmem_cache_destroy(ccid3_rx_hist_slab); | 2126 | kmem_cache_destroy(ccid3_rx_hist_slab); |
2126 | ccid3_rx_hist_slab = NULL; | 2127 | ccid3_rx_hist_slab = NULL; |
2127 | out_free_tx_history: | 2128 | out_free_tx_history: |
2128 | kmem_cache_destroy(ccid3_tx_hist_slab); | 2129 | kmem_cache_destroy(ccid3_tx_hist_slab); |
2129 | ccid3_tx_hist_slab = NULL; | 2130 | ccid3_tx_hist_slab = NULL; |
2130 | goto out; | 2131 | goto out; |
2131 | } | 2132 | } |
2132 | module_init(ccid3_module_init); | 2133 | module_init(ccid3_module_init); |
2133 | 2134 | ||
2134 | static __exit void ccid3_module_exit(void) | 2135 | static __exit void ccid3_module_exit(void) |
2135 | { | 2136 | { |
2136 | ccid_unregister(&ccid3); | 2137 | ccid_unregister(&ccid3); |
2137 | 2138 | ||
2138 | if (ccid3_tx_hist_slab != NULL) { | 2139 | if (ccid3_tx_hist_slab != NULL) { |
2139 | kmem_cache_destroy(ccid3_tx_hist_slab); | 2140 | kmem_cache_destroy(ccid3_tx_hist_slab); |
2140 | ccid3_tx_hist_slab = NULL; | 2141 | ccid3_tx_hist_slab = NULL; |
2141 | } | 2142 | } |
2142 | if (ccid3_rx_hist_slab != NULL) { | 2143 | if (ccid3_rx_hist_slab != NULL) { |
2143 | kmem_cache_destroy(ccid3_rx_hist_slab); | 2144 | kmem_cache_destroy(ccid3_rx_hist_slab); |
2144 | ccid3_rx_hist_slab = NULL; | 2145 | ccid3_rx_hist_slab = NULL; |
2145 | } | 2146 | } |
2146 | if (ccid3_loss_interval_hist_slab != NULL) { | 2147 | if (ccid3_loss_interval_hist_slab != NULL) { |
2147 | kmem_cache_destroy(ccid3_loss_interval_hist_slab); | 2148 | kmem_cache_destroy(ccid3_loss_interval_hist_slab); |
2148 | ccid3_loss_interval_hist_slab = NULL; | 2149 | ccid3_loss_interval_hist_slab = NULL; |
2149 | } | 2150 | } |
2150 | } | 2151 | } |
2151 | module_exit(ccid3_module_exit); | 2152 | module_exit(ccid3_module_exit); |
2152 | 2153 | ||
2153 | MODULE_AUTHOR("Ian McDonald <iam4@cs.waikato.ac.nz> & Arnaldo Carvalho de Melo <acme@ghostprotocols.net>"); | 2154 | MODULE_AUTHOR("Ian McDonald <iam4@cs.waikato.ac.nz> & Arnaldo Carvalho de Melo <acme@ghostprotocols.net>"); |
2154 | MODULE_DESCRIPTION("DCCP TFRC CCID3 CCID"); | 2155 | MODULE_DESCRIPTION("DCCP TFRC CCID3 CCID"); |
2155 | MODULE_LICENSE("GPL"); | 2156 | MODULE_LICENSE("GPL"); |
2156 | MODULE_ALIAS("net-dccp-ccid-3"); | 2157 | MODULE_ALIAS("net-dccp-ccid-3"); |
2157 | 2158 |
net/dccp/dccp.h
1 | #ifndef _DCCP_H | 1 | #ifndef _DCCP_H |
2 | #define _DCCP_H | 2 | #define _DCCP_H |
3 | /* | 3 | /* |
4 | * net/dccp/dccp.h | 4 | * net/dccp/dccp.h |
5 | * | 5 | * |
6 | * An implementation of the DCCP protocol | 6 | * An implementation of the DCCP protocol |
7 | * Arnaldo Carvalho de Melo <acme@conectiva.com.br> | 7 | * Arnaldo Carvalho de Melo <acme@conectiva.com.br> |
8 | * | 8 | * |
9 | * This program is free software; you can redistribute it and/or modify it | 9 | * This program is free software; you can redistribute it and/or modify it |
10 | * under the terms of the GNU General Public License version 2 as | 10 | * under the terms of the GNU General Public License version 2 as |
11 | * published by the Free Software Foundation. | 11 | * published by the Free Software Foundation. |
12 | */ | 12 | */ |
13 | 13 | ||
14 | #include <linux/dccp.h> | 14 | #include <linux/dccp.h> |
15 | #include <net/snmp.h> | 15 | #include <net/snmp.h> |
16 | #include <net/sock.h> | 16 | #include <net/sock.h> |
17 | #include <net/tcp.h> | 17 | #include <net/tcp.h> |
18 | 18 | ||
19 | #define DCCP_DEBUG | 19 | #define DCCP_DEBUG |
20 | 20 | ||
21 | #ifdef DCCP_DEBUG | 21 | #ifdef DCCP_DEBUG |
22 | extern int dccp_debug; | 22 | extern int dccp_debug; |
23 | 23 | ||
24 | #define dccp_pr_debug(format, a...) \ | 24 | #define dccp_pr_debug(format, a...) \ |
25 | do { if (dccp_debug) \ | 25 | do { if (dccp_debug) \ |
26 | printk(KERN_DEBUG "%s: " format, __FUNCTION__ , ##a); \ | 26 | printk(KERN_DEBUG "%s: " format, __FUNCTION__ , ##a); \ |
27 | } while (0) | 27 | } while (0) |
28 | #define dccp_pr_debug_cat(format, a...) do { if (dccp_debug) printk(format, ##a); } while (0) | 28 | #define dccp_pr_debug_cat(format, a...) do { if (dccp_debug) printk(format, ##a); } while (0) |
29 | #else | 29 | #else |
30 | #define dccp_pr_debug(format, a...) | 30 | #define dccp_pr_debug(format, a...) |
31 | #define dccp_pr_debug_cat(format, a...) | 31 | #define dccp_pr_debug_cat(format, a...) |
32 | #endif | 32 | #endif |
33 | 33 | ||
34 | extern struct inet_hashinfo dccp_hashinfo; | 34 | extern struct inet_hashinfo dccp_hashinfo; |
35 | 35 | ||
36 | extern atomic_t dccp_orphan_count; | 36 | extern atomic_t dccp_orphan_count; |
37 | extern int dccp_tw_count; | 37 | extern int dccp_tw_count; |
38 | extern void dccp_tw_deschedule(struct inet_timewait_sock *tw); | 38 | extern void dccp_tw_deschedule(struct inet_timewait_sock *tw); |
39 | 39 | ||
40 | extern void dccp_time_wait(struct sock *sk, int state, int timeo); | 40 | extern void dccp_time_wait(struct sock *sk, int state, int timeo); |
41 | 41 | ||
42 | /* FIXME: Right size this */ | 42 | /* FIXME: Right size this */ |
43 | #define DCCP_MAX_OPT_LEN 128 | 43 | #define DCCP_MAX_OPT_LEN 128 |
44 | 44 | ||
45 | #define DCCP_MAX_PACKET_HDR 32 | 45 | #define DCCP_MAX_PACKET_HDR 32 |
46 | 46 | ||
47 | #define MAX_DCCP_HEADER (DCCP_MAX_PACKET_HDR + DCCP_MAX_OPT_LEN + MAX_HEADER) | 47 | #define MAX_DCCP_HEADER (DCCP_MAX_PACKET_HDR + DCCP_MAX_OPT_LEN + MAX_HEADER) |
48 | 48 | ||
49 | #define DCCP_TIMEWAIT_LEN (60 * HZ) /* how long to wait to destroy TIME-WAIT | 49 | #define DCCP_TIMEWAIT_LEN (60 * HZ) /* how long to wait to destroy TIME-WAIT |
50 | * state, about 60 seconds */ | 50 | * state, about 60 seconds */ |
51 | 51 | ||
52 | /* draft-ietf-dccp-spec-11.txt initial RTO value */ | 52 | /* draft-ietf-dccp-spec-11.txt initial RTO value */ |
53 | #define DCCP_TIMEOUT_INIT ((unsigned)(3 * HZ)) | 53 | #define DCCP_TIMEOUT_INIT ((unsigned)(3 * HZ)) |
54 | 54 | ||
55 | /* Maximal interval between probes for local resources. */ | 55 | /* Maximal interval between probes for local resources. */ |
56 | #define DCCP_RESOURCE_PROBE_INTERVAL ((unsigned)(HZ / 2U)) | 56 | #define DCCP_RESOURCE_PROBE_INTERVAL ((unsigned)(HZ / 2U)) |
57 | 57 | ||
58 | #define DCCP_RTO_MAX ((unsigned)(120 * HZ)) /* FIXME: using TCP value */ | 58 | #define DCCP_RTO_MAX ((unsigned)(120 * HZ)) /* FIXME: using TCP value */ |
59 | 59 | ||
60 | extern struct proto dccp_v4_prot; | 60 | extern struct proto dccp_v4_prot; |
61 | 61 | ||
62 | /* is seq1 < seq2 ? */ | 62 | /* is seq1 < seq2 ? */ |
63 | static inline const int before48(const u64 seq1, const u64 seq2) | 63 | static inline const int before48(const u64 seq1, const u64 seq2) |
64 | { | 64 | { |
65 | return (const s64)((seq1 << 16) - (seq2 << 16)) < 0; | 65 | return (const s64)((seq1 << 16) - (seq2 << 16)) < 0; |
66 | } | 66 | } |
67 | 67 | ||
68 | /* is seq1 > seq2 ? */ | 68 | /* is seq1 > seq2 ? */ |
69 | static inline const int after48(const u64 seq1, const u64 seq2) | 69 | static inline const int after48(const u64 seq1, const u64 seq2) |
70 | { | 70 | { |
71 | return (const s64)((seq2 << 16) - (seq1 << 16)) < 0; | 71 | return (const s64)((seq2 << 16) - (seq1 << 16)) < 0; |
72 | } | 72 | } |
73 | 73 | ||
74 | /* is seq2 <= seq1 <= seq3 ? */ | 74 | /* is seq2 <= seq1 <= seq3 ? */ |
75 | static inline const int between48(const u64 seq1, const u64 seq2, const u64 seq3) | 75 | static inline const int between48(const u64 seq1, const u64 seq2, const u64 seq3) |
76 | { | 76 | { |
77 | return (seq3 << 16) - (seq2 << 16) >= (seq1 << 16) - (seq2 << 16); | 77 | return (seq3 << 16) - (seq2 << 16) >= (seq1 << 16) - (seq2 << 16); |
78 | } | 78 | } |
79 | 79 | ||
80 | static inline u64 max48(const u64 seq1, const u64 seq2) | 80 | static inline u64 max48(const u64 seq1, const u64 seq2) |
81 | { | 81 | { |
82 | return after48(seq1, seq2) ? seq1 : seq2; | 82 | return after48(seq1, seq2) ? seq1 : seq2; |
83 | } | 83 | } |
84 | 84 | ||
85 | enum { | 85 | enum { |
86 | DCCP_MIB_NUM = 0, | 86 | DCCP_MIB_NUM = 0, |
87 | DCCP_MIB_ACTIVEOPENS, /* ActiveOpens */ | 87 | DCCP_MIB_ACTIVEOPENS, /* ActiveOpens */ |
88 | DCCP_MIB_ESTABRESETS, /* EstabResets */ | 88 | DCCP_MIB_ESTABRESETS, /* EstabResets */ |
89 | DCCP_MIB_CURRESTAB, /* CurrEstab */ | 89 | DCCP_MIB_CURRESTAB, /* CurrEstab */ |
90 | DCCP_MIB_OUTSEGS, /* OutSegs */ | 90 | DCCP_MIB_OUTSEGS, /* OutSegs */ |
91 | DCCP_MIB_OUTRSTS, | 91 | DCCP_MIB_OUTRSTS, |
92 | DCCP_MIB_ABORTONTIMEOUT, | 92 | DCCP_MIB_ABORTONTIMEOUT, |
93 | DCCP_MIB_TIMEOUTS, | 93 | DCCP_MIB_TIMEOUTS, |
94 | DCCP_MIB_ABORTFAILED, | 94 | DCCP_MIB_ABORTFAILED, |
95 | DCCP_MIB_PASSIVEOPENS, | 95 | DCCP_MIB_PASSIVEOPENS, |
96 | DCCP_MIB_ATTEMPTFAILS, | 96 | DCCP_MIB_ATTEMPTFAILS, |
97 | DCCP_MIB_OUTDATAGRAMS, | 97 | DCCP_MIB_OUTDATAGRAMS, |
98 | DCCP_MIB_INERRS, | 98 | DCCP_MIB_INERRS, |
99 | DCCP_MIB_OPTMANDATORYERROR, | 99 | DCCP_MIB_OPTMANDATORYERROR, |
100 | DCCP_MIB_INVALIDOPT, | 100 | DCCP_MIB_INVALIDOPT, |
101 | __DCCP_MIB_MAX | 101 | __DCCP_MIB_MAX |
102 | }; | 102 | }; |
103 | 103 | ||
104 | #define DCCP_MIB_MAX __DCCP_MIB_MAX | 104 | #define DCCP_MIB_MAX __DCCP_MIB_MAX |
105 | struct dccp_mib { | 105 | struct dccp_mib { |
106 | unsigned long mibs[DCCP_MIB_MAX]; | 106 | unsigned long mibs[DCCP_MIB_MAX]; |
107 | } __SNMP_MIB_ALIGN__; | 107 | } __SNMP_MIB_ALIGN__; |
108 | 108 | ||
109 | DECLARE_SNMP_STAT(struct dccp_mib, dccp_statistics); | 109 | DECLARE_SNMP_STAT(struct dccp_mib, dccp_statistics); |
110 | #define DCCP_INC_STATS(field) SNMP_INC_STATS(dccp_statistics, field) | 110 | #define DCCP_INC_STATS(field) SNMP_INC_STATS(dccp_statistics, field) |
111 | #define DCCP_INC_STATS_BH(field) SNMP_INC_STATS_BH(dccp_statistics, field) | 111 | #define DCCP_INC_STATS_BH(field) SNMP_INC_STATS_BH(dccp_statistics, field) |
112 | #define DCCP_INC_STATS_USER(field) SNMP_INC_STATS_USER(dccp_statistics, field) | 112 | #define DCCP_INC_STATS_USER(field) SNMP_INC_STATS_USER(dccp_statistics, field) |
113 | #define DCCP_DEC_STATS(field) SNMP_DEC_STATS(dccp_statistics, field) | 113 | #define DCCP_DEC_STATS(field) SNMP_DEC_STATS(dccp_statistics, field) |
114 | #define DCCP_ADD_STATS_BH(field, val) SNMP_ADD_STATS_BH(dccp_statistics, field, val) | 114 | #define DCCP_ADD_STATS_BH(field, val) SNMP_ADD_STATS_BH(dccp_statistics, field, val) |
115 | #define DCCP_ADD_STATS_USER(field, val) SNMP_ADD_STATS_USER(dccp_statistics, field, val) | 115 | #define DCCP_ADD_STATS_USER(field, val) SNMP_ADD_STATS_USER(dccp_statistics, field, val) |
116 | 116 | ||
117 | extern int dccp_transmit_skb(struct sock *sk, struct sk_buff *skb); | 117 | extern int dccp_transmit_skb(struct sock *sk, struct sk_buff *skb); |
118 | extern int dccp_retransmit_skb(struct sock *sk, struct sk_buff *skb); | 118 | extern int dccp_retransmit_skb(struct sock *sk, struct sk_buff *skb); |
119 | 119 | ||
120 | extern int dccp_send_response(struct sock *sk); | 120 | extern int dccp_send_response(struct sock *sk); |
121 | extern void dccp_send_ack(struct sock *sk); | 121 | extern void dccp_send_ack(struct sock *sk); |
122 | extern void dccp_send_delayed_ack(struct sock *sk); | 122 | extern void dccp_send_delayed_ack(struct sock *sk); |
123 | extern void dccp_send_sync(struct sock *sk, u64 seq); | 123 | extern void dccp_send_sync(struct sock *sk, u64 seq); |
124 | 124 | ||
125 | extern int dccp_write_xmit(struct sock *sk, struct sk_buff *skb, | ||
126 | const int len); | ||
127 | |||
125 | extern void dccp_init_xmit_timers(struct sock *sk); | 128 | extern void dccp_init_xmit_timers(struct sock *sk); |
126 | static inline void dccp_clear_xmit_timers(struct sock *sk) | 129 | static inline void dccp_clear_xmit_timers(struct sock *sk) |
127 | { | 130 | { |
128 | inet_csk_clear_xmit_timers(sk); | 131 | inet_csk_clear_xmit_timers(sk); |
129 | } | 132 | } |
130 | 133 | ||
131 | extern unsigned int dccp_sync_mss(struct sock *sk, u32 pmtu); | 134 | extern unsigned int dccp_sync_mss(struct sock *sk, u32 pmtu); |
132 | 135 | ||
133 | extern const char *dccp_packet_name(const int type); | 136 | extern const char *dccp_packet_name(const int type); |
134 | extern const char *dccp_state_name(const int state); | 137 | extern const char *dccp_state_name(const int state); |
135 | 138 | ||
136 | static inline void dccp_set_state(struct sock *sk, const int state) | 139 | static inline void dccp_set_state(struct sock *sk, const int state) |
137 | { | 140 | { |
138 | const int oldstate = sk->sk_state; | 141 | const int oldstate = sk->sk_state; |
139 | 142 | ||
140 | dccp_pr_debug("%s(%p) %-10.10s -> %s\n", | 143 | dccp_pr_debug("%s(%p) %-10.10s -> %s\n", |
141 | dccp_role(sk), sk, | 144 | dccp_role(sk), sk, |
142 | dccp_state_name(oldstate), dccp_state_name(state)); | 145 | dccp_state_name(oldstate), dccp_state_name(state)); |
143 | WARN_ON(state == oldstate); | 146 | WARN_ON(state == oldstate); |
144 | 147 | ||
145 | switch (state) { | 148 | switch (state) { |
146 | case DCCP_OPEN: | 149 | case DCCP_OPEN: |
147 | if (oldstate != DCCP_OPEN) | 150 | if (oldstate != DCCP_OPEN) |
148 | DCCP_INC_STATS(DCCP_MIB_CURRESTAB); | 151 | DCCP_INC_STATS(DCCP_MIB_CURRESTAB); |
149 | break; | 152 | break; |
150 | 153 | ||
151 | case DCCP_CLOSED: | 154 | case DCCP_CLOSED: |
152 | if (oldstate == DCCP_CLOSING || oldstate == DCCP_OPEN) | 155 | if (oldstate == DCCP_CLOSING || oldstate == DCCP_OPEN) |
153 | DCCP_INC_STATS(DCCP_MIB_ESTABRESETS); | 156 | DCCP_INC_STATS(DCCP_MIB_ESTABRESETS); |
154 | 157 | ||
155 | sk->sk_prot->unhash(sk); | 158 | sk->sk_prot->unhash(sk); |
156 | if (inet_csk(sk)->icsk_bind_hash != NULL && | 159 | if (inet_csk(sk)->icsk_bind_hash != NULL && |
157 | !(sk->sk_userlocks & SOCK_BINDPORT_LOCK)) | 160 | !(sk->sk_userlocks & SOCK_BINDPORT_LOCK)) |
158 | inet_put_port(&dccp_hashinfo, sk); | 161 | inet_put_port(&dccp_hashinfo, sk); |
159 | /* fall through */ | 162 | /* fall through */ |
160 | default: | 163 | default: |
161 | if (oldstate == DCCP_OPEN) | 164 | if (oldstate == DCCP_OPEN) |
162 | DCCP_DEC_STATS(DCCP_MIB_CURRESTAB); | 165 | DCCP_DEC_STATS(DCCP_MIB_CURRESTAB); |
163 | } | 166 | } |
164 | 167 | ||
165 | /* Change state AFTER socket is unhashed to avoid closed | 168 | /* Change state AFTER socket is unhashed to avoid closed |
166 | * socket sitting in hash tables. | 169 | * socket sitting in hash tables. |
167 | */ | 170 | */ |
168 | sk->sk_state = state; | 171 | sk->sk_state = state; |
169 | } | 172 | } |
170 | 173 | ||
171 | static inline void dccp_done(struct sock *sk) | 174 | static inline void dccp_done(struct sock *sk) |
172 | { | 175 | { |
173 | dccp_set_state(sk, DCCP_CLOSED); | 176 | dccp_set_state(sk, DCCP_CLOSED); |
174 | dccp_clear_xmit_timers(sk); | 177 | dccp_clear_xmit_timers(sk); |
175 | 178 | ||
176 | sk->sk_shutdown = SHUTDOWN_MASK; | 179 | sk->sk_shutdown = SHUTDOWN_MASK; |
177 | 180 | ||
178 | if (!sock_flag(sk, SOCK_DEAD)) | 181 | if (!sock_flag(sk, SOCK_DEAD)) |
179 | sk->sk_state_change(sk); | 182 | sk->sk_state_change(sk); |
180 | else | 183 | else |
181 | inet_csk_destroy_sock(sk); | 184 | inet_csk_destroy_sock(sk); |
182 | } | 185 | } |
183 | 186 | ||
184 | static inline void dccp_openreq_init(struct request_sock *req, | 187 | static inline void dccp_openreq_init(struct request_sock *req, |
185 | struct dccp_sock *dp, | 188 | struct dccp_sock *dp, |
186 | struct sk_buff *skb) | 189 | struct sk_buff *skb) |
187 | { | 190 | { |
188 | /* | 191 | /* |
189 | * FIXME: fill in the other req fields from the DCCP options | 192 | * FIXME: fill in the other req fields from the DCCP options |
190 | * received | 193 | * received |
191 | */ | 194 | */ |
192 | inet_rsk(req)->rmt_port = dccp_hdr(skb)->dccph_sport; | 195 | inet_rsk(req)->rmt_port = dccp_hdr(skb)->dccph_sport; |
193 | inet_rsk(req)->acked = 0; | 196 | inet_rsk(req)->acked = 0; |
194 | req->rcv_wnd = 0; | 197 | req->rcv_wnd = 0; |
195 | } | 198 | } |
196 | 199 | ||
197 | extern void dccp_v4_send_check(struct sock *sk, struct dccp_hdr *dh, int len, | ||
198 | struct sk_buff *skb); | ||
199 | extern int dccp_v4_conn_request(struct sock *sk, struct sk_buff *skb); | 200 | extern int dccp_v4_conn_request(struct sock *sk, struct sk_buff *skb); |
200 | 201 | ||
201 | extern struct sock *dccp_create_openreq_child(struct sock *sk, | 202 | extern struct sock *dccp_create_openreq_child(struct sock *sk, |
202 | const struct request_sock *req, | 203 | const struct request_sock *req, |
203 | const struct sk_buff *skb); | 204 | const struct sk_buff *skb); |
204 | 205 | ||
205 | extern int dccp_v4_do_rcv(struct sock *sk, struct sk_buff *skb); | 206 | extern int dccp_v4_do_rcv(struct sock *sk, struct sk_buff *skb); |
206 | 207 | ||
207 | extern void dccp_v4_err(struct sk_buff *skb, u32); | 208 | extern void dccp_v4_err(struct sk_buff *skb, u32); |
208 | 209 | ||
209 | extern int dccp_v4_rcv(struct sk_buff *skb); | 210 | extern int dccp_v4_rcv(struct sk_buff *skb); |
210 | 211 | ||
211 | extern struct sock *dccp_v4_request_recv_sock(struct sock *sk, | 212 | extern struct sock *dccp_v4_request_recv_sock(struct sock *sk, |
212 | struct sk_buff *skb, | 213 | struct sk_buff *skb, |
213 | struct request_sock *req, | 214 | struct request_sock *req, |
214 | struct dst_entry *dst); | 215 | struct dst_entry *dst); |
215 | extern struct sock *dccp_check_req(struct sock *sk, struct sk_buff *skb, | 216 | extern struct sock *dccp_check_req(struct sock *sk, struct sk_buff *skb, |
216 | struct request_sock *req, | 217 | struct request_sock *req, |
217 | struct request_sock **prev); | 218 | struct request_sock **prev); |
218 | 219 | ||
219 | extern int dccp_child_process(struct sock *parent, struct sock *child, | 220 | extern int dccp_child_process(struct sock *parent, struct sock *child, |
220 | struct sk_buff *skb); | 221 | struct sk_buff *skb); |
221 | extern int dccp_rcv_state_process(struct sock *sk, struct sk_buff *skb, | 222 | extern int dccp_rcv_state_process(struct sock *sk, struct sk_buff *skb, |
222 | struct dccp_hdr *dh, unsigned len); | 223 | struct dccp_hdr *dh, unsigned len); |
223 | extern int dccp_rcv_established(struct sock *sk, struct sk_buff *skb, | 224 | extern int dccp_rcv_established(struct sock *sk, struct sk_buff *skb, |
224 | const struct dccp_hdr *dh, const unsigned len); | 225 | const struct dccp_hdr *dh, const unsigned len); |
225 | 226 | ||
226 | extern void dccp_close(struct sock *sk, long timeout); | 227 | extern void dccp_close(struct sock *sk, long timeout); |
227 | extern struct sk_buff *dccp_make_response(struct sock *sk, | 228 | extern struct sk_buff *dccp_make_response(struct sock *sk, |
228 | struct dst_entry *dst, | 229 | struct dst_entry *dst, |
229 | struct request_sock *req); | 230 | struct request_sock *req); |
230 | 231 | ||
231 | extern int dccp_connect(struct sock *sk); | 232 | extern int dccp_connect(struct sock *sk); |
232 | extern int dccp_disconnect(struct sock *sk, int flags); | 233 | extern int dccp_disconnect(struct sock *sk, int flags); |
233 | extern int dccp_getsockopt(struct sock *sk, int level, int optname, | 234 | extern int dccp_getsockopt(struct sock *sk, int level, int optname, |
234 | char *optval, int *optlen); | 235 | char *optval, int *optlen); |
235 | extern int dccp_ioctl(struct sock *sk, int cmd, unsigned long arg); | 236 | extern int dccp_ioctl(struct sock *sk, int cmd, unsigned long arg); |
236 | extern int dccp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg, | 237 | extern int dccp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg, |
237 | size_t size); | 238 | size_t size); |
238 | extern int dccp_recvmsg(struct kiocb *iocb, struct sock *sk, | 239 | extern int dccp_recvmsg(struct kiocb *iocb, struct sock *sk, |
239 | struct msghdr *msg, size_t len, int nonblock, | 240 | struct msghdr *msg, size_t len, int nonblock, |
240 | int flags, int *addr_len); | 241 | int flags, int *addr_len); |
241 | extern int dccp_setsockopt(struct sock *sk, int level, int optname, | 242 | extern int dccp_setsockopt(struct sock *sk, int level, int optname, |
242 | char *optval, int optlen); | 243 | char *optval, int optlen); |
243 | extern void dccp_shutdown(struct sock *sk, int how); | 244 | extern void dccp_shutdown(struct sock *sk, int how); |
244 | 245 | ||
245 | extern int dccp_v4_checksum(const struct sk_buff *skb, | 246 | extern int dccp_v4_checksum(const struct sk_buff *skb, |
246 | const u32 saddr, const u32 daddr); | 247 | const u32 saddr, const u32 daddr); |
247 | 248 | ||
248 | extern int dccp_v4_send_reset(struct sock *sk, enum dccp_reset_codes code); | 249 | extern int dccp_v4_send_reset(struct sock *sk, enum dccp_reset_codes code); |
249 | extern void dccp_send_close(struct sock *sk); | 250 | extern void dccp_send_close(struct sock *sk); |
250 | 251 | ||
251 | struct dccp_skb_cb { | 252 | struct dccp_skb_cb { |
252 | __u8 dccpd_type; | 253 | __u8 dccpd_type; |
253 | __u8 dccpd_reset_code; | 254 | __u8 dccpd_reset_code; |
254 | __u8 dccpd_service; | 255 | __u8 dccpd_service; |
255 | __u8 dccpd_ccval; | 256 | __u8 dccpd_ccval; |
256 | __u64 dccpd_seq; | 257 | __u64 dccpd_seq; |
257 | __u64 dccpd_ack_seq; | 258 | __u64 dccpd_ack_seq; |
258 | int dccpd_opt_len; | 259 | int dccpd_opt_len; |
259 | }; | 260 | }; |
260 | 261 | ||
261 | #define DCCP_SKB_CB(__skb) ((struct dccp_skb_cb *)&((__skb)->cb[0])) | 262 | #define DCCP_SKB_CB(__skb) ((struct dccp_skb_cb *)&((__skb)->cb[0])) |
262 | 263 | ||
263 | static inline int dccp_non_data_packet(const struct sk_buff *skb) | 264 | static inline int dccp_non_data_packet(const struct sk_buff *skb) |
264 | { | 265 | { |
265 | const __u8 type = DCCP_SKB_CB(skb)->dccpd_type; | 266 | const __u8 type = DCCP_SKB_CB(skb)->dccpd_type; |
266 | 267 | ||
267 | return type == DCCP_PKT_ACK || | 268 | return type == DCCP_PKT_ACK || |
268 | type == DCCP_PKT_CLOSE || | 269 | type == DCCP_PKT_CLOSE || |
269 | type == DCCP_PKT_CLOSEREQ || | 270 | type == DCCP_PKT_CLOSEREQ || |
270 | type == DCCP_PKT_RESET || | 271 | type == DCCP_PKT_RESET || |
271 | type == DCCP_PKT_SYNC || | 272 | type == DCCP_PKT_SYNC || |
272 | type == DCCP_PKT_SYNCACK; | 273 | type == DCCP_PKT_SYNCACK; |
273 | } | 274 | } |
274 | 275 | ||
275 | static inline int dccp_packet_without_ack(const struct sk_buff *skb) | 276 | static inline int dccp_packet_without_ack(const struct sk_buff *skb) |
276 | { | 277 | { |
277 | const __u8 type = DCCP_SKB_CB(skb)->dccpd_type; | 278 | const __u8 type = DCCP_SKB_CB(skb)->dccpd_type; |
278 | 279 | ||
279 | return type == DCCP_PKT_DATA || type == DCCP_PKT_REQUEST; | 280 | return type == DCCP_PKT_DATA || type == DCCP_PKT_REQUEST; |
280 | } | 281 | } |
281 | 282 | ||
282 | #define DCCP_MAX_SEQNO ((((u64)1) << 48) - 1) | 283 | #define DCCP_MAX_SEQNO ((((u64)1) << 48) - 1) |
283 | #define DCCP_PKT_WITHOUT_ACK_SEQ (DCCP_MAX_SEQNO << 2) | 284 | #define DCCP_PKT_WITHOUT_ACK_SEQ (DCCP_MAX_SEQNO << 2) |
284 | 285 | ||
285 | static inline void dccp_set_seqno(u64 *seqno, u64 value) | 286 | static inline void dccp_set_seqno(u64 *seqno, u64 value) |
286 | { | 287 | { |
287 | if (value > DCCP_MAX_SEQNO) | 288 | if (value > DCCP_MAX_SEQNO) |
288 | value -= DCCP_MAX_SEQNO + 1; | 289 | value -= DCCP_MAX_SEQNO + 1; |
289 | *seqno = value; | 290 | *seqno = value; |
290 | } | 291 | } |
291 | 292 | ||
292 | static inline u64 dccp_delta_seqno(u64 seqno1, u64 seqno2) | 293 | static inline u64 dccp_delta_seqno(u64 seqno1, u64 seqno2) |
293 | { | 294 | { |
294 | return ((seqno2 << 16) - (seqno1 << 16)) >> 16; | 295 | return ((seqno2 << 16) - (seqno1 << 16)) >> 16; |
295 | } | 296 | } |
296 | 297 | ||
297 | static inline void dccp_inc_seqno(u64 *seqno) | 298 | static inline void dccp_inc_seqno(u64 *seqno) |
298 | { | 299 | { |
299 | if (++*seqno > DCCP_MAX_SEQNO) | 300 | if (++*seqno > DCCP_MAX_SEQNO) |
300 | *seqno = 0; | 301 | *seqno = 0; |
301 | } | 302 | } |
302 | 303 | ||
303 | static inline void dccp_hdr_set_seq(struct dccp_hdr *dh, const u64 gss) | 304 | static inline void dccp_hdr_set_seq(struct dccp_hdr *dh, const u64 gss) |
304 | { | 305 | { |
305 | struct dccp_hdr_ext *dhx = (struct dccp_hdr_ext *)((void *)dh + sizeof(*dh)); | 306 | struct dccp_hdr_ext *dhx = (struct dccp_hdr_ext *)((void *)dh + sizeof(*dh)); |
306 | 307 | ||
307 | #if defined(__LITTLE_ENDIAN_BITFIELD) | 308 | #if defined(__LITTLE_ENDIAN_BITFIELD) |
308 | dh->dccph_seq = htonl((gss >> 32)) >> 8; | 309 | dh->dccph_seq = htonl((gss >> 32)) >> 8; |
309 | #elif defined(__BIG_ENDIAN_BITFIELD) | 310 | #elif defined(__BIG_ENDIAN_BITFIELD) |
310 | dh->dccph_seq = htonl((gss >> 32)); | 311 | dh->dccph_seq = htonl((gss >> 32)); |
311 | #else | 312 | #else |
312 | #error "Adjust your <asm/byteorder.h> defines" | 313 | #error "Adjust your <asm/byteorder.h> defines" |
313 | #endif | 314 | #endif |
314 | dhx->dccph_seq_low = htonl(gss & 0xffffffff); | 315 | dhx->dccph_seq_low = htonl(gss & 0xffffffff); |
315 | } | 316 | } |
316 | 317 | ||
317 | static inline void dccp_hdr_set_ack(struct dccp_hdr_ack_bits *dhack, const u64 gsr) | 318 | static inline void dccp_hdr_set_ack(struct dccp_hdr_ack_bits *dhack, const u64 gsr) |
318 | { | 319 | { |
319 | #if defined(__LITTLE_ENDIAN_BITFIELD) | 320 | #if defined(__LITTLE_ENDIAN_BITFIELD) |
320 | dhack->dccph_ack_nr_high = htonl((gsr >> 32)) >> 8; | 321 | dhack->dccph_ack_nr_high = htonl((gsr >> 32)) >> 8; |
321 | #elif defined(__BIG_ENDIAN_BITFIELD) | 322 | #elif defined(__BIG_ENDIAN_BITFIELD) |
322 | dhack->dccph_ack_nr_high = htonl((gsr >> 32)); | 323 | dhack->dccph_ack_nr_high = htonl((gsr >> 32)); |
323 | #else | 324 | #else |
324 | #error "Adjust your <asm/byteorder.h> defines" | 325 | #error "Adjust your <asm/byteorder.h> defines" |
325 | #endif | 326 | #endif |
326 | dhack->dccph_ack_nr_low = htonl(gsr & 0xffffffff); | 327 | dhack->dccph_ack_nr_low = htonl(gsr & 0xffffffff); |
327 | } | 328 | } |
328 | 329 | ||
329 | static inline void dccp_update_gsr(struct sock *sk, u64 seq) | 330 | static inline void dccp_update_gsr(struct sock *sk, u64 seq) |
330 | { | 331 | { |
331 | struct dccp_sock *dp = dccp_sk(sk); | 332 | struct dccp_sock *dp = dccp_sk(sk); |
332 | u64 tmp_gsr; | 333 | u64 tmp_gsr; |
333 | 334 | ||
334 | dccp_set_seqno(&tmp_gsr, dp->dccps_gsr + 1 - (dp->dccps_options.dccpo_sequence_window / 4)); | 335 | dccp_set_seqno(&tmp_gsr, dp->dccps_gsr + 1 - (dp->dccps_options.dccpo_sequence_window / 4)); |
335 | dp->dccps_gsr = seq; | 336 | dp->dccps_gsr = seq; |
336 | dccp_set_seqno(&dp->dccps_swl, max48(tmp_gsr, dp->dccps_isr)); | 337 | dccp_set_seqno(&dp->dccps_swl, max48(tmp_gsr, dp->dccps_isr)); |
337 | dccp_set_seqno(&dp->dccps_swh, | 338 | dccp_set_seqno(&dp->dccps_swh, |
338 | dp->dccps_gsr + (3 * dp->dccps_options.dccpo_sequence_window) / 4); | 339 | dp->dccps_gsr + (3 * dp->dccps_options.dccpo_sequence_window) / 4); |
339 | } | 340 | } |
340 | 341 | ||
341 | static inline void dccp_update_gss(struct sock *sk, u64 seq) | 342 | static inline void dccp_update_gss(struct sock *sk, u64 seq) |
342 | { | 343 | { |
343 | struct dccp_sock *dp = dccp_sk(sk); | 344 | struct dccp_sock *dp = dccp_sk(sk); |
344 | u64 tmp_gss; | 345 | u64 tmp_gss; |
345 | 346 | ||
346 | dccp_set_seqno(&tmp_gss, dp->dccps_gss - dp->dccps_options.dccpo_sequence_window + 1); | 347 | dccp_set_seqno(&tmp_gss, dp->dccps_gss - dp->dccps_options.dccpo_sequence_window + 1); |
347 | dp->dccps_awl = max48(tmp_gss, dp->dccps_iss); | 348 | dp->dccps_awl = max48(tmp_gss, dp->dccps_iss); |
348 | dp->dccps_awh = dp->dccps_gss = seq; | 349 | dp->dccps_awh = dp->dccps_gss = seq; |
349 | } | 350 | } |
350 | 351 | ||
351 | extern void dccp_insert_options(struct sock *sk, struct sk_buff *skb); | 352 | extern void dccp_insert_options(struct sock *sk, struct sk_buff *skb); |
352 | extern void dccp_insert_option_elapsed_time(struct sock *sk, | 353 | extern void dccp_insert_option_elapsed_time(struct sock *sk, |
353 | struct sk_buff *skb, | 354 | struct sk_buff *skb, |
354 | u32 elapsed_time); | 355 | u32 elapsed_time); |
355 | extern void dccp_insert_option(struct sock *sk, struct sk_buff *skb, | 356 | extern void dccp_insert_option(struct sock *sk, struct sk_buff *skb, |
356 | unsigned char option, | 357 | unsigned char option, |
357 | const void *value, unsigned char len); | 358 | const void *value, unsigned char len); |
358 | 359 | ||
359 | extern struct socket *dccp_ctl_socket; | 360 | extern struct socket *dccp_ctl_socket; |
360 | 361 | ||
361 | #define DCCP_ACKPKTS_STATE_RECEIVED 0 | 362 | #define DCCP_ACKPKTS_STATE_RECEIVED 0 |
362 | #define DCCP_ACKPKTS_STATE_ECN_MARKED (1 << 6) | 363 | #define DCCP_ACKPKTS_STATE_ECN_MARKED (1 << 6) |
363 | #define DCCP_ACKPKTS_STATE_NOT_RECEIVED (3 << 6) | 364 | #define DCCP_ACKPKTS_STATE_NOT_RECEIVED (3 << 6) |
364 | 365 | ||
365 | #define DCCP_ACKPKTS_STATE_MASK 0xC0 /* 11000000 */ | 366 | #define DCCP_ACKPKTS_STATE_MASK 0xC0 /* 11000000 */ |
366 | #define DCCP_ACKPKTS_LEN_MASK 0x3F /* 00111111 */ | 367 | #define DCCP_ACKPKTS_LEN_MASK 0x3F /* 00111111 */ |
367 | 368 | ||
368 | /** struct dccp_ackpkts - acknowledgeable packets | 369 | /** struct dccp_ackpkts - acknowledgeable packets |
369 | * | 370 | * |
370 | * This data structure is the one defined in the DCCP draft | 371 | * This data structure is the one defined in the DCCP draft |
371 | * Appendix A. | 372 | * Appendix A. |
372 | * | 373 | * |
373 | * @dccpap_buf_head - circular buffer head | 374 | * @dccpap_buf_head - circular buffer head |
374 | * @dccpap_buf_tail - circular buffer tail | 375 | * @dccpap_buf_tail - circular buffer tail |
375 | * @dccpap_buf_ackno - ack # of the most recent packet acknoldgeable in the buffer (i.e. %dccpap_buf_head) | 376 | * @dccpap_buf_ackno - ack # of the most recent packet acknoldgeable in the buffer (i.e. %dccpap_buf_head) |
376 | * @dccpap_buf_nonce - the one-bit sum of the ECN Nonces on all packets acked by the buffer with State 0 | 377 | * @dccpap_buf_nonce - the one-bit sum of the ECN Nonces on all packets acked by the buffer with State 0 |
377 | * | 378 | * |
378 | * Additionally, the HC-Receiver must keep some information about the | 379 | * Additionally, the HC-Receiver must keep some information about the |
379 | * Ack Vectors it has recently sent. For each packet sent carrying an | 380 | * Ack Vectors it has recently sent. For each packet sent carrying an |
380 | * Ack Vector, it remembers four variables: | 381 | * Ack Vector, it remembers four variables: |
381 | * | 382 | * |
382 | * @dccpap_ack_seqno - the Sequence Number used for the packet (HC-Receiver seqno) | 383 | * @dccpap_ack_seqno - the Sequence Number used for the packet (HC-Receiver seqno) |
383 | * @dccpap_ack_ptr - the value of buf_head at the time of acknowledgement. | 384 | * @dccpap_ack_ptr - the value of buf_head at the time of acknowledgement. |
384 | * @dccpap_ack_ackno - the Acknowledgement Number used for the packet (HC-Sender seqno) | 385 | * @dccpap_ack_ackno - the Acknowledgement Number used for the packet (HC-Sender seqno) |
385 | * @dccpap_ack_nonce - the one-bit sum of the ECN Nonces for all State 0. | 386 | * @dccpap_ack_nonce - the one-bit sum of the ECN Nonces for all State 0. |
386 | * | 387 | * |
387 | * @dccpap_buf_len - circular buffer length | 388 | * @dccpap_buf_len - circular buffer length |
388 | * @dccpap_buf - circular buffer of acknowledgeable packets | 389 | * @dccpap_buf - circular buffer of acknowledgeable packets |
389 | */ | 390 | */ |
390 | struct dccp_ackpkts { | 391 | struct dccp_ackpkts { |
391 | unsigned int dccpap_buf_head; | 392 | unsigned int dccpap_buf_head; |
392 | unsigned int dccpap_buf_tail; | 393 | unsigned int dccpap_buf_tail; |
393 | u64 dccpap_buf_ackno; | 394 | u64 dccpap_buf_ackno; |
394 | u64 dccpap_ack_seqno; | 395 | u64 dccpap_ack_seqno; |
395 | u64 dccpap_ack_ackno; | 396 | u64 dccpap_ack_ackno; |
396 | unsigned int dccpap_ack_ptr; | 397 | unsigned int dccpap_ack_ptr; |
397 | unsigned int dccpap_buf_vector_len; | 398 | unsigned int dccpap_buf_vector_len; |
398 | unsigned int dccpap_ack_vector_len; | 399 | unsigned int dccpap_ack_vector_len; |
399 | unsigned int dccpap_buf_len; | 400 | unsigned int dccpap_buf_len; |
400 | unsigned long dccpap_time; | 401 | unsigned long dccpap_time; |
401 | u8 dccpap_buf_nonce; | 402 | u8 dccpap_buf_nonce; |
402 | u8 dccpap_ack_nonce; | 403 | u8 dccpap_ack_nonce; |
403 | u8 dccpap_buf[0]; | 404 | u8 dccpap_buf[0]; |
404 | }; | 405 | }; |
405 | 406 | ||
406 | extern struct dccp_ackpkts *dccp_ackpkts_alloc(unsigned int len, int priority); | 407 | extern struct dccp_ackpkts *dccp_ackpkts_alloc(unsigned int len, int priority); |
407 | extern void dccp_ackpkts_free(struct dccp_ackpkts *ap); | 408 | extern void dccp_ackpkts_free(struct dccp_ackpkts *ap); |
408 | extern int dccp_ackpkts_add(struct dccp_ackpkts *ap, u64 ackno, u8 state); | 409 | extern int dccp_ackpkts_add(struct dccp_ackpkts *ap, u64 ackno, u8 state); |
409 | extern void dccp_ackpkts_check_rcv_ackno(struct dccp_ackpkts *ap, | 410 | extern void dccp_ackpkts_check_rcv_ackno(struct dccp_ackpkts *ap, |
410 | struct sock *sk, u64 ackno); | 411 | struct sock *sk, u64 ackno); |
411 | 412 | ||
412 | #ifdef DCCP_DEBUG | 413 | #ifdef DCCP_DEBUG |
413 | extern void dccp_ackvector_print(const u64 ackno, | 414 | extern void dccp_ackvector_print(const u64 ackno, |
414 | const unsigned char *vector, int len); | 415 | const unsigned char *vector, int len); |
415 | extern void dccp_ackpkts_print(const struct dccp_ackpkts *ap); | 416 | extern void dccp_ackpkts_print(const struct dccp_ackpkts *ap); |
416 | #else | 417 | #else |
417 | static inline void dccp_ackvector_print(const u64 ackno, | 418 | static inline void dccp_ackvector_print(const u64 ackno, |
418 | const unsigned char *vector, | 419 | const unsigned char *vector, |
419 | int len) { } | 420 | int len) { } |
420 | static inline void dccp_ackpkts_print(const struct dccp_ackpkts *ap) { } | 421 | static inline void dccp_ackpkts_print(const struct dccp_ackpkts *ap) { } |
421 | #endif | 422 | #endif |
422 | 423 |
net/dccp/output.c
1 | /* | 1 | /* |
2 | * net/dccp/output.c | 2 | * net/dccp/output.c |
3 | * | 3 | * |
4 | * An implementation of the DCCP protocol | 4 | * An implementation of the DCCP protocol |
5 | * Arnaldo Carvalho de Melo <acme@conectiva.com.br> | 5 | * Arnaldo Carvalho de Melo <acme@conectiva.com.br> |
6 | * | 6 | * |
7 | * This program is free software; you can redistribute it and/or | 7 | * This program is free software; you can redistribute it and/or |
8 | * modify it under the terms of the GNU General Public License | 8 | * modify it under the terms of the GNU General Public License |
9 | * as published by the Free Software Foundation; either version | 9 | * as published by the Free Software Foundation; either version |
10 | * 2 of the License, or (at your option) any later version. | 10 | * 2 of the License, or (at your option) any later version. |
11 | */ | 11 | */ |
12 | 12 | ||
13 | #include <linux/config.h> | 13 | #include <linux/config.h> |
14 | #include <linux/dccp.h> | 14 | #include <linux/dccp.h> |
15 | #include <linux/skbuff.h> | 15 | #include <linux/skbuff.h> |
16 | 16 | ||
17 | #include <net/sock.h> | 17 | #include <net/sock.h> |
18 | 18 | ||
19 | #include "ccid.h" | 19 | #include "ccid.h" |
20 | #include "dccp.h" | 20 | #include "dccp.h" |
21 | 21 | ||
22 | static inline void dccp_event_ack_sent(struct sock *sk) | 22 | static inline void dccp_event_ack_sent(struct sock *sk) |
23 | { | 23 | { |
24 | inet_csk_clear_xmit_timer(sk, ICSK_TIME_DACK); | 24 | inet_csk_clear_xmit_timer(sk, ICSK_TIME_DACK); |
25 | } | 25 | } |
26 | 26 | ||
27 | /* | 27 | /* |
28 | * All SKB's seen here are completely headerless. It is our | 28 | * All SKB's seen here are completely headerless. It is our |
29 | * job to build the DCCP header, and pass the packet down to | 29 | * job to build the DCCP header, and pass the packet down to |
30 | * IP so it can do the same plus pass the packet off to the | 30 | * IP so it can do the same plus pass the packet off to the |
31 | * device. | 31 | * device. |
32 | */ | 32 | */ |
33 | int dccp_transmit_skb(struct sock *sk, struct sk_buff *skb) | 33 | int dccp_transmit_skb(struct sock *sk, struct sk_buff *skb) |
34 | { | 34 | { |
35 | if (likely(skb != NULL)) { | 35 | if (likely(skb != NULL)) { |
36 | const struct inet_sock *inet = inet_sk(sk); | 36 | const struct inet_sock *inet = inet_sk(sk); |
37 | struct dccp_sock *dp = dccp_sk(sk); | 37 | struct dccp_sock *dp = dccp_sk(sk); |
38 | struct dccp_skb_cb *dcb = DCCP_SKB_CB(skb); | 38 | struct dccp_skb_cb *dcb = DCCP_SKB_CB(skb); |
39 | struct dccp_hdr *dh; | 39 | struct dccp_hdr *dh; |
40 | /* XXX For now we're using only 48 bits sequence numbers */ | 40 | /* XXX For now we're using only 48 bits sequence numbers */ |
41 | const int dccp_header_size = sizeof(*dh) + | 41 | const int dccp_header_size = sizeof(*dh) + |
42 | sizeof(struct dccp_hdr_ext) + | 42 | sizeof(struct dccp_hdr_ext) + |
43 | dccp_packet_hdr_len(dcb->dccpd_type); | 43 | dccp_packet_hdr_len(dcb->dccpd_type); |
44 | int err, set_ack = 1; | 44 | int err, set_ack = 1; |
45 | u64 ackno = dp->dccps_gsr; | 45 | u64 ackno = dp->dccps_gsr; |
46 | 46 | ||
47 | /* | 47 | /* |
48 | * FIXME: study DCCP_PKT_SYNC[ACK] to see what is the right thing | 48 | * FIXME: study DCCP_PKT_SYNC[ACK] to see what is the right thing |
49 | * to do here... | 49 | * to do here... |
50 | */ | 50 | */ |
51 | dccp_inc_seqno(&dp->dccps_gss); | 51 | dccp_inc_seqno(&dp->dccps_gss); |
52 | 52 | ||
53 | dcb->dccpd_seq = dp->dccps_gss; | 53 | dcb->dccpd_seq = dp->dccps_gss; |
54 | dccp_insert_options(sk, skb); | 54 | dccp_insert_options(sk, skb); |
55 | 55 | ||
56 | switch (dcb->dccpd_type) { | 56 | switch (dcb->dccpd_type) { |
57 | case DCCP_PKT_DATA: | 57 | case DCCP_PKT_DATA: |
58 | set_ack = 0; | 58 | set_ack = 0; |
59 | break; | 59 | break; |
60 | case DCCP_PKT_SYNC: | 60 | case DCCP_PKT_SYNC: |
61 | case DCCP_PKT_SYNCACK: | 61 | case DCCP_PKT_SYNCACK: |
62 | ackno = dcb->dccpd_seq; | 62 | ackno = dcb->dccpd_seq; |
63 | break; | 63 | break; |
64 | } | 64 | } |
65 | 65 | ||
66 | skb->h.raw = skb_push(skb, dccp_header_size); | 66 | skb->h.raw = skb_push(skb, dccp_header_size); |
67 | dh = dccp_hdr(skb); | 67 | dh = dccp_hdr(skb); |
68 | /* Data packets are not cloned as they are never retransmitted */ | 68 | /* Data packets are not cloned as they are never retransmitted */ |
69 | if (skb_cloned(skb)) | 69 | if (skb_cloned(skb)) |
70 | skb_set_owner_w(skb, sk); | 70 | skb_set_owner_w(skb, sk); |
71 | 71 | ||
72 | /* Build DCCP header and checksum it. */ | 72 | /* Build DCCP header and checksum it. */ |
73 | memset(dh, 0, dccp_header_size); | 73 | memset(dh, 0, dccp_header_size); |
74 | dh->dccph_type = dcb->dccpd_type; | 74 | dh->dccph_type = dcb->dccpd_type; |
75 | dh->dccph_sport = inet->sport; | 75 | dh->dccph_sport = inet->sport; |
76 | dh->dccph_dport = inet->dport; | 76 | dh->dccph_dport = inet->dport; |
77 | dh->dccph_doff = (dccp_header_size + dcb->dccpd_opt_len) / 4; | 77 | dh->dccph_doff = (dccp_header_size + dcb->dccpd_opt_len) / 4; |
78 | dh->dccph_ccval = dcb->dccpd_ccval; | 78 | dh->dccph_ccval = dcb->dccpd_ccval; |
79 | /* XXX For now we're using only 48 bits sequence numbers */ | 79 | /* XXX For now we're using only 48 bits sequence numbers */ |
80 | dh->dccph_x = 1; | 80 | dh->dccph_x = 1; |
81 | 81 | ||
82 | dp->dccps_awh = dp->dccps_gss; | 82 | dp->dccps_awh = dp->dccps_gss; |
83 | dccp_hdr_set_seq(dh, dp->dccps_gss); | 83 | dccp_hdr_set_seq(dh, dp->dccps_gss); |
84 | if (set_ack) | 84 | if (set_ack) |
85 | dccp_hdr_set_ack(dccp_hdr_ack_bits(skb), ackno); | 85 | dccp_hdr_set_ack(dccp_hdr_ack_bits(skb), ackno); |
86 | 86 | ||
87 | switch (dcb->dccpd_type) { | 87 | switch (dcb->dccpd_type) { |
88 | case DCCP_PKT_REQUEST: | 88 | case DCCP_PKT_REQUEST: |
89 | dccp_hdr_request(skb)->dccph_req_service = dcb->dccpd_service; | 89 | dccp_hdr_request(skb)->dccph_req_service = dcb->dccpd_service; |
90 | break; | 90 | break; |
91 | case DCCP_PKT_RESET: | 91 | case DCCP_PKT_RESET: |
92 | dccp_hdr_reset(skb)->dccph_reset_code = dcb->dccpd_reset_code; | 92 | dccp_hdr_reset(skb)->dccph_reset_code = dcb->dccpd_reset_code; |
93 | break; | 93 | break; |
94 | } | 94 | } |
95 | 95 | ||
96 | dh->dccph_checksum = dccp_v4_checksum(skb, inet->saddr, | 96 | dh->dccph_checksum = dccp_v4_checksum(skb, inet->saddr, |
97 | inet->daddr); | 97 | inet->daddr); |
98 | 98 | ||
99 | if (dcb->dccpd_type == DCCP_PKT_ACK || | 99 | if (dcb->dccpd_type == DCCP_PKT_ACK || |
100 | dcb->dccpd_type == DCCP_PKT_DATAACK) | 100 | dcb->dccpd_type == DCCP_PKT_DATAACK) |
101 | dccp_event_ack_sent(sk); | 101 | dccp_event_ack_sent(sk); |
102 | 102 | ||
103 | DCCP_INC_STATS(DCCP_MIB_OUTSEGS); | 103 | DCCP_INC_STATS(DCCP_MIB_OUTSEGS); |
104 | 104 | ||
105 | err = ip_queue_xmit(skb, 0); | 105 | err = ip_queue_xmit(skb, 0); |
106 | if (err <= 0) | 106 | if (err <= 0) |
107 | return err; | 107 | return err; |
108 | 108 | ||
109 | /* NET_XMIT_CN is special. It does not guarantee, | 109 | /* NET_XMIT_CN is special. It does not guarantee, |
110 | * that this packet is lost. It tells that device | 110 | * that this packet is lost. It tells that device |
111 | * is about to start to drop packets or already | 111 | * is about to start to drop packets or already |
112 | * drops some packets of the same priority and | 112 | * drops some packets of the same priority and |
113 | * invokes us to send less aggressively. | 113 | * invokes us to send less aggressively. |
114 | */ | 114 | */ |
115 | return err == NET_XMIT_CN ? 0 : err; | 115 | return err == NET_XMIT_CN ? 0 : err; |
116 | } | 116 | } |
117 | return -ENOBUFS; | 117 | return -ENOBUFS; |
118 | } | 118 | } |
119 | 119 | ||
120 | unsigned int dccp_sync_mss(struct sock *sk, u32 pmtu) | 120 | unsigned int dccp_sync_mss(struct sock *sk, u32 pmtu) |
121 | { | 121 | { |
122 | struct dccp_sock *dp = dccp_sk(sk); | 122 | struct dccp_sock *dp = dccp_sk(sk); |
123 | int mss_now; | 123 | int mss_now; |
124 | 124 | ||
125 | /* | 125 | /* |
126 | * FIXME: we really should be using the af_specific thing to support IPv6. | 126 | * FIXME: we really should be using the af_specific thing to support IPv6. |
127 | * mss_now = pmtu - tp->af_specific->net_header_len - sizeof(struct dccp_hdr) - sizeof(struct dccp_hdr_ext); | 127 | * mss_now = pmtu - tp->af_specific->net_header_len - sizeof(struct dccp_hdr) - sizeof(struct dccp_hdr_ext); |
128 | */ | 128 | */ |
129 | mss_now = pmtu - sizeof(struct iphdr) - sizeof(struct dccp_hdr) - sizeof(struct dccp_hdr_ext); | 129 | mss_now = pmtu - sizeof(struct iphdr) - sizeof(struct dccp_hdr) - sizeof(struct dccp_hdr_ext); |
130 | 130 | ||
131 | /* Now subtract optional transport overhead */ | 131 | /* Now subtract optional transport overhead */ |
132 | mss_now -= dp->dccps_ext_header_len; | 132 | mss_now -= dp->dccps_ext_header_len; |
133 | 133 | ||
134 | /* | 134 | /* |
135 | * FIXME: this should come from the CCID infrastructure, where, say, | 135 | * FIXME: this should come from the CCID infrastructure, where, say, |
136 | * TFRC will say it wants TIMESTAMPS, ELAPSED time, etc, for now lets | 136 | * TFRC will say it wants TIMESTAMPS, ELAPSED time, etc, for now lets |
137 | * put a rough estimate for NDP + TIMESTAMP + TIMESTAMP_ECHO + ELAPSED | 137 | * put a rough estimate for NDP + TIMESTAMP + TIMESTAMP_ECHO + ELAPSED |
138 | * TIME + TFRC_OPT_LOSS_EVENT_RATE + TFRC_OPT_RECEIVE_RATE + padding to | 138 | * TIME + TFRC_OPT_LOSS_EVENT_RATE + TFRC_OPT_RECEIVE_RATE + padding to |
139 | * make it a multiple of 4 | 139 | * make it a multiple of 4 |
140 | */ | 140 | */ |
141 | 141 | ||
142 | mss_now -= ((5 + 6 + 10 + 6 + 6 + 6 + 3) / 4) * 4; | 142 | mss_now -= ((5 + 6 + 10 + 6 + 6 + 6 + 3) / 4) * 4; |
143 | 143 | ||
144 | /* And store cached results */ | 144 | /* And store cached results */ |
145 | dp->dccps_pmtu_cookie = pmtu; | 145 | dp->dccps_pmtu_cookie = pmtu; |
146 | dp->dccps_mss_cache = mss_now; | 146 | dp->dccps_mss_cache = mss_now; |
147 | 147 | ||
148 | return mss_now; | 148 | return mss_now; |
149 | } | 149 | } |
150 | 150 | ||
151 | int dccp_write_xmit(struct sock *sk, struct sk_buff *skb, const int len) | ||
152 | { | ||
153 | const struct dccp_sock *dp = dccp_sk(sk); | ||
154 | int err = ccid_hc_tx_send_packet(dp->dccps_hc_tx_ccid, sk, skb, len); | ||
155 | |||
156 | if (err == 0) { | ||
157 | const struct dccp_ackpkts *ap = dp->dccps_hc_rx_ackpkts; | ||
158 | struct dccp_skb_cb *dcb = DCCP_SKB_CB(skb); | ||
159 | |||
160 | if (sk->sk_state == DCCP_PARTOPEN) { | ||
161 | /* See 8.1.5. Handshake Completion */ | ||
162 | inet_csk_schedule_ack(sk); | ||
163 | inet_csk_reset_xmit_timer(sk, ICSK_TIME_DACK, | ||
164 | inet_csk(sk)->icsk_rto, | ||
165 | DCCP_RTO_MAX); | ||
166 | dcb->dccpd_type = DCCP_PKT_DATAACK; | ||
167 | /* | ||
168 | * FIXME: we really should have a | ||
169 | * dccps_ack_pending or use icsk. | ||
170 | */ | ||
171 | } else if (inet_csk_ack_scheduled(sk) || | ||
172 | (dp->dccps_options.dccpo_send_ack_vector && | ||
173 | ap->dccpap_buf_ackno != DCCP_MAX_SEQNO + 1 && | ||
174 | ap->dccpap_ack_seqno == DCCP_MAX_SEQNO + 1)) | ||
175 | dcb->dccpd_type = DCCP_PKT_DATAACK; | ||
176 | else | ||
177 | dcb->dccpd_type = DCCP_PKT_DATA; | ||
178 | |||
179 | err = dccp_transmit_skb(sk, skb); | ||
180 | ccid_hc_tx_packet_sent(dp->dccps_hc_tx_ccid, sk, 0, len); | ||
181 | } | ||
182 | |||
183 | return err; | ||
184 | } | ||
185 | |||
151 | int dccp_retransmit_skb(struct sock *sk, struct sk_buff *skb) | 186 | int dccp_retransmit_skb(struct sock *sk, struct sk_buff *skb) |
152 | { | 187 | { |
153 | if (inet_sk_rebuild_header(sk) != 0) | 188 | if (inet_sk_rebuild_header(sk) != 0) |
154 | return -EHOSTUNREACH; /* Routing failure or similar. */ | 189 | return -EHOSTUNREACH; /* Routing failure or similar. */ |
155 | 190 | ||
156 | return dccp_transmit_skb(sk, (skb_cloned(skb) ? | 191 | return dccp_transmit_skb(sk, (skb_cloned(skb) ? |
157 | pskb_copy(skb, GFP_ATOMIC): | 192 | pskb_copy(skb, GFP_ATOMIC): |
158 | skb_clone(skb, GFP_ATOMIC))); | 193 | skb_clone(skb, GFP_ATOMIC))); |
159 | } | 194 | } |
160 | 195 | ||
161 | struct sk_buff *dccp_make_response(struct sock *sk, struct dst_entry *dst, | 196 | struct sk_buff *dccp_make_response(struct sock *sk, struct dst_entry *dst, |
162 | struct request_sock *req) | 197 | struct request_sock *req) |
163 | { | 198 | { |
164 | struct dccp_hdr *dh; | 199 | struct dccp_hdr *dh; |
165 | const int dccp_header_size = sizeof(struct dccp_hdr) + | 200 | const int dccp_header_size = sizeof(struct dccp_hdr) + |
166 | sizeof(struct dccp_hdr_ext) + | 201 | sizeof(struct dccp_hdr_ext) + |
167 | sizeof(struct dccp_hdr_response); | 202 | sizeof(struct dccp_hdr_response); |
168 | struct sk_buff *skb = sock_wmalloc(sk, MAX_HEADER + DCCP_MAX_OPT_LEN + | 203 | struct sk_buff *skb = sock_wmalloc(sk, MAX_HEADER + DCCP_MAX_OPT_LEN + |
169 | dccp_header_size, 1, | 204 | dccp_header_size, 1, |
170 | GFP_ATOMIC); | 205 | GFP_ATOMIC); |
171 | if (skb == NULL) | 206 | if (skb == NULL) |
172 | return NULL; | 207 | return NULL; |
173 | 208 | ||
174 | /* Reserve space for headers. */ | 209 | /* Reserve space for headers. */ |
175 | skb_reserve(skb, MAX_HEADER + DCCP_MAX_OPT_LEN + dccp_header_size); | 210 | skb_reserve(skb, MAX_HEADER + DCCP_MAX_OPT_LEN + dccp_header_size); |
176 | 211 | ||
177 | skb->dst = dst_clone(dst); | 212 | skb->dst = dst_clone(dst); |
178 | skb->csum = 0; | 213 | skb->csum = 0; |
179 | 214 | ||
180 | DCCP_SKB_CB(skb)->dccpd_type = DCCP_PKT_RESPONSE; | 215 | DCCP_SKB_CB(skb)->dccpd_type = DCCP_PKT_RESPONSE; |
181 | DCCP_SKB_CB(skb)->dccpd_seq = dccp_rsk(req)->dreq_iss; | 216 | DCCP_SKB_CB(skb)->dccpd_seq = dccp_rsk(req)->dreq_iss; |
182 | dccp_insert_options(sk, skb); | 217 | dccp_insert_options(sk, skb); |
183 | 218 | ||
184 | skb->h.raw = skb_push(skb, dccp_header_size); | 219 | skb->h.raw = skb_push(skb, dccp_header_size); |
185 | 220 | ||
186 | dh = dccp_hdr(skb); | 221 | dh = dccp_hdr(skb); |
187 | memset(dh, 0, dccp_header_size); | 222 | memset(dh, 0, dccp_header_size); |
188 | 223 | ||
189 | dh->dccph_sport = inet_sk(sk)->sport; | 224 | dh->dccph_sport = inet_sk(sk)->sport; |
190 | dh->dccph_dport = inet_rsk(req)->rmt_port; | 225 | dh->dccph_dport = inet_rsk(req)->rmt_port; |
191 | dh->dccph_doff = (dccp_header_size + DCCP_SKB_CB(skb)->dccpd_opt_len) / 4; | 226 | dh->dccph_doff = (dccp_header_size + DCCP_SKB_CB(skb)->dccpd_opt_len) / 4; |
192 | dh->dccph_type = DCCP_PKT_RESPONSE; | 227 | dh->dccph_type = DCCP_PKT_RESPONSE; |
193 | dh->dccph_x = 1; | 228 | dh->dccph_x = 1; |
194 | dccp_hdr_set_seq(dh, dccp_rsk(req)->dreq_iss); | 229 | dccp_hdr_set_seq(dh, dccp_rsk(req)->dreq_iss); |
195 | dccp_hdr_set_ack(dccp_hdr_ack_bits(skb), dccp_rsk(req)->dreq_isr); | 230 | dccp_hdr_set_ack(dccp_hdr_ack_bits(skb), dccp_rsk(req)->dreq_isr); |
196 | 231 | ||
197 | dh->dccph_checksum = dccp_v4_checksum(skb, inet_rsk(req)->loc_addr, | 232 | dh->dccph_checksum = dccp_v4_checksum(skb, inet_rsk(req)->loc_addr, |
198 | inet_rsk(req)->rmt_addr); | 233 | inet_rsk(req)->rmt_addr); |
199 | 234 | ||
200 | DCCP_INC_STATS(DCCP_MIB_OUTSEGS); | 235 | DCCP_INC_STATS(DCCP_MIB_OUTSEGS); |
201 | return skb; | 236 | return skb; |
202 | } | 237 | } |
203 | 238 | ||
204 | struct sk_buff *dccp_make_reset(struct sock *sk, struct dst_entry *dst, | 239 | struct sk_buff *dccp_make_reset(struct sock *sk, struct dst_entry *dst, |
205 | const enum dccp_reset_codes code) | 240 | const enum dccp_reset_codes code) |
206 | 241 | ||
207 | { | 242 | { |
208 | struct dccp_hdr *dh; | 243 | struct dccp_hdr *dh; |
209 | struct dccp_sock *dp = dccp_sk(sk); | 244 | struct dccp_sock *dp = dccp_sk(sk); |
210 | const int dccp_header_size = sizeof(struct dccp_hdr) + | 245 | const int dccp_header_size = sizeof(struct dccp_hdr) + |
211 | sizeof(struct dccp_hdr_ext) + | 246 | sizeof(struct dccp_hdr_ext) + |
212 | sizeof(struct dccp_hdr_reset); | 247 | sizeof(struct dccp_hdr_reset); |
213 | struct sk_buff *skb = sock_wmalloc(sk, MAX_HEADER + DCCP_MAX_OPT_LEN + | 248 | struct sk_buff *skb = sock_wmalloc(sk, MAX_HEADER + DCCP_MAX_OPT_LEN + |
214 | dccp_header_size, 1, | 249 | dccp_header_size, 1, |
215 | GFP_ATOMIC); | 250 | GFP_ATOMIC); |
216 | if (skb == NULL) | 251 | if (skb == NULL) |
217 | return NULL; | 252 | return NULL; |
218 | 253 | ||
219 | /* Reserve space for headers. */ | 254 | /* Reserve space for headers. */ |
220 | skb_reserve(skb, MAX_HEADER + DCCP_MAX_OPT_LEN + dccp_header_size); | 255 | skb_reserve(skb, MAX_HEADER + DCCP_MAX_OPT_LEN + dccp_header_size); |
221 | 256 | ||
222 | skb->dst = dst_clone(dst); | 257 | skb->dst = dst_clone(dst); |
223 | skb->csum = 0; | 258 | skb->csum = 0; |
224 | 259 | ||
225 | dccp_inc_seqno(&dp->dccps_gss); | 260 | dccp_inc_seqno(&dp->dccps_gss); |
226 | 261 | ||
227 | DCCP_SKB_CB(skb)->dccpd_reset_code = code; | 262 | DCCP_SKB_CB(skb)->dccpd_reset_code = code; |
228 | DCCP_SKB_CB(skb)->dccpd_type = DCCP_PKT_RESET; | 263 | DCCP_SKB_CB(skb)->dccpd_type = DCCP_PKT_RESET; |
229 | DCCP_SKB_CB(skb)->dccpd_seq = dp->dccps_gss; | 264 | DCCP_SKB_CB(skb)->dccpd_seq = dp->dccps_gss; |
230 | dccp_insert_options(sk, skb); | 265 | dccp_insert_options(sk, skb); |
231 | 266 | ||
232 | skb->h.raw = skb_push(skb, dccp_header_size); | 267 | skb->h.raw = skb_push(skb, dccp_header_size); |
233 | 268 | ||
234 | dh = dccp_hdr(skb); | 269 | dh = dccp_hdr(skb); |
235 | memset(dh, 0, dccp_header_size); | 270 | memset(dh, 0, dccp_header_size); |
236 | 271 | ||
237 | dh->dccph_sport = inet_sk(sk)->sport; | 272 | dh->dccph_sport = inet_sk(sk)->sport; |
238 | dh->dccph_dport = inet_sk(sk)->dport; | 273 | dh->dccph_dport = inet_sk(sk)->dport; |
239 | dh->dccph_doff = (dccp_header_size + DCCP_SKB_CB(skb)->dccpd_opt_len) / 4; | 274 | dh->dccph_doff = (dccp_header_size + DCCP_SKB_CB(skb)->dccpd_opt_len) / 4; |
240 | dh->dccph_type = DCCP_PKT_RESET; | 275 | dh->dccph_type = DCCP_PKT_RESET; |
241 | dh->dccph_x = 1; | 276 | dh->dccph_x = 1; |
242 | dccp_hdr_set_seq(dh, dp->dccps_gss); | 277 | dccp_hdr_set_seq(dh, dp->dccps_gss); |
243 | dccp_hdr_set_ack(dccp_hdr_ack_bits(skb), dp->dccps_gsr); | 278 | dccp_hdr_set_ack(dccp_hdr_ack_bits(skb), dp->dccps_gsr); |
244 | 279 | ||
245 | dccp_hdr_reset(skb)->dccph_reset_code = code; | 280 | dccp_hdr_reset(skb)->dccph_reset_code = code; |
246 | 281 | ||
247 | dh->dccph_checksum = dccp_v4_checksum(skb, inet_sk(sk)->saddr, | 282 | dh->dccph_checksum = dccp_v4_checksum(skb, inet_sk(sk)->saddr, |
248 | inet_sk(sk)->daddr); | 283 | inet_sk(sk)->daddr); |
249 | 284 | ||
250 | DCCP_INC_STATS(DCCP_MIB_OUTSEGS); | 285 | DCCP_INC_STATS(DCCP_MIB_OUTSEGS); |
251 | return skb; | 286 | return skb; |
252 | } | 287 | } |
253 | 288 | ||
254 | /* | 289 | /* |
255 | * Do all connect socket setups that can be done AF independent. | 290 | * Do all connect socket setups that can be done AF independent. |
256 | */ | 291 | */ |
257 | static inline void dccp_connect_init(struct sock *sk) | 292 | static inline void dccp_connect_init(struct sock *sk) |
258 | { | 293 | { |
259 | struct dst_entry *dst = __sk_dst_get(sk); | 294 | struct dst_entry *dst = __sk_dst_get(sk); |
260 | struct inet_connection_sock *icsk = inet_csk(sk); | 295 | struct inet_connection_sock *icsk = inet_csk(sk); |
261 | 296 | ||
262 | sk->sk_err = 0; | 297 | sk->sk_err = 0; |
263 | sock_reset_flag(sk, SOCK_DONE); | 298 | sock_reset_flag(sk, SOCK_DONE); |
264 | 299 | ||
265 | dccp_sync_mss(sk, dst_mtu(dst)); | 300 | dccp_sync_mss(sk, dst_mtu(dst)); |
266 | 301 | ||
267 | /* | 302 | /* |
268 | * FIXME: set dp->{dccps_swh,dccps_swl}, with | 303 | * FIXME: set dp->{dccps_swh,dccps_swl}, with |
269 | * something like dccp_inc_seq | 304 | * something like dccp_inc_seq |
270 | */ | 305 | */ |
271 | 306 | ||
272 | icsk->icsk_retransmits = 0; | 307 | icsk->icsk_retransmits = 0; |
273 | } | 308 | } |
274 | 309 | ||
275 | int dccp_connect(struct sock *sk) | 310 | int dccp_connect(struct sock *sk) |
276 | { | 311 | { |
277 | struct sk_buff *skb; | 312 | struct sk_buff *skb; |
278 | struct inet_connection_sock *icsk = inet_csk(sk); | 313 | struct inet_connection_sock *icsk = inet_csk(sk); |
279 | 314 | ||
280 | dccp_connect_init(sk); | 315 | dccp_connect_init(sk); |
281 | 316 | ||
282 | skb = alloc_skb(MAX_DCCP_HEADER + 15, sk->sk_allocation); | 317 | skb = alloc_skb(MAX_DCCP_HEADER + 15, sk->sk_allocation); |
283 | if (unlikely(skb == NULL)) | 318 | if (unlikely(skb == NULL)) |
284 | return -ENOBUFS; | 319 | return -ENOBUFS; |
285 | 320 | ||
286 | /* Reserve space for headers. */ | 321 | /* Reserve space for headers. */ |
287 | skb_reserve(skb, MAX_DCCP_HEADER); | 322 | skb_reserve(skb, MAX_DCCP_HEADER); |
288 | 323 | ||
289 | DCCP_SKB_CB(skb)->dccpd_type = DCCP_PKT_REQUEST; | 324 | DCCP_SKB_CB(skb)->dccpd_type = DCCP_PKT_REQUEST; |
290 | /* FIXME: set service to something meaningful, coming | 325 | /* FIXME: set service to something meaningful, coming |
291 | * from userspace*/ | 326 | * from userspace*/ |
292 | DCCP_SKB_CB(skb)->dccpd_service = 0; | 327 | DCCP_SKB_CB(skb)->dccpd_service = 0; |
293 | skb->csum = 0; | 328 | skb->csum = 0; |
294 | skb_set_owner_w(skb, sk); | 329 | skb_set_owner_w(skb, sk); |
295 | 330 | ||
296 | BUG_TRAP(sk->sk_send_head == NULL); | 331 | BUG_TRAP(sk->sk_send_head == NULL); |
297 | sk->sk_send_head = skb; | 332 | sk->sk_send_head = skb; |
298 | dccp_transmit_skb(sk, skb_clone(skb, GFP_KERNEL)); | 333 | dccp_transmit_skb(sk, skb_clone(skb, GFP_KERNEL)); |
299 | DCCP_INC_STATS(DCCP_MIB_ACTIVEOPENS); | 334 | DCCP_INC_STATS(DCCP_MIB_ACTIVEOPENS); |
300 | 335 | ||
301 | /* Timer for repeating the REQUEST until an answer. */ | 336 | /* Timer for repeating the REQUEST until an answer. */ |
302 | inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS, icsk->icsk_rto, TCP_RTO_MAX); | 337 | inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS, |
338 | icsk->icsk_rto, DCCP_RTO_MAX); | ||
303 | return 0; | 339 | return 0; |
304 | } | 340 | } |
305 | 341 | ||
306 | void dccp_send_ack(struct sock *sk) | 342 | void dccp_send_ack(struct sock *sk) |
307 | { | 343 | { |
308 | /* If we have been reset, we may not send again. */ | 344 | /* If we have been reset, we may not send again. */ |
309 | if (sk->sk_state != DCCP_CLOSED) { | 345 | if (sk->sk_state != DCCP_CLOSED) { |
310 | struct sk_buff *skb = alloc_skb(MAX_DCCP_HEADER, GFP_ATOMIC); | 346 | struct sk_buff *skb = alloc_skb(MAX_DCCP_HEADER, GFP_ATOMIC); |
311 | 347 | ||
312 | if (skb == NULL) { | 348 | if (skb == NULL) { |
313 | inet_csk_schedule_ack(sk); | 349 | inet_csk_schedule_ack(sk); |
314 | inet_csk(sk)->icsk_ack.ato = TCP_ATO_MIN; | 350 | inet_csk(sk)->icsk_ack.ato = TCP_ATO_MIN; |
315 | inet_csk_reset_xmit_timer(sk, ICSK_TIME_DACK, TCP_DELACK_MAX, TCP_RTO_MAX); | 351 | inet_csk_reset_xmit_timer(sk, ICSK_TIME_DACK, TCP_DELACK_MAX, TCP_RTO_MAX); |
316 | return; | 352 | return; |
317 | } | 353 | } |
318 | 354 | ||
319 | /* Reserve space for headers */ | 355 | /* Reserve space for headers */ |
320 | skb_reserve(skb, MAX_DCCP_HEADER); | 356 | skb_reserve(skb, MAX_DCCP_HEADER); |
321 | skb->csum = 0; | 357 | skb->csum = 0; |
322 | DCCP_SKB_CB(skb)->dccpd_type = DCCP_PKT_ACK; | 358 | DCCP_SKB_CB(skb)->dccpd_type = DCCP_PKT_ACK; |
323 | skb_set_owner_w(skb, sk); | 359 | skb_set_owner_w(skb, sk); |
324 | dccp_transmit_skb(sk, skb); | 360 | dccp_transmit_skb(sk, skb); |
325 | } | 361 | } |
326 | } | 362 | } |
327 | 363 | ||
328 | EXPORT_SYMBOL_GPL(dccp_send_ack); | 364 | EXPORT_SYMBOL_GPL(dccp_send_ack); |
329 | 365 | ||
330 | void dccp_send_delayed_ack(struct sock *sk) | 366 | void dccp_send_delayed_ack(struct sock *sk) |
331 | { | 367 | { |
332 | struct inet_connection_sock *icsk = inet_csk(sk); | 368 | struct inet_connection_sock *icsk = inet_csk(sk); |
333 | /* | 369 | /* |
334 | * FIXME: tune this timer. elapsed time fixes the skew, so no problem | 370 | * FIXME: tune this timer. elapsed time fixes the skew, so no problem |
335 | * with using 2s, and active senders also piggyback the ACK into a | 371 | * with using 2s, and active senders also piggyback the ACK into a |
336 | * DATAACK packet, so this is really for quiescent senders. | 372 | * DATAACK packet, so this is really for quiescent senders. |
337 | */ | 373 | */ |
338 | unsigned long timeout = jiffies + 2 * HZ; | 374 | unsigned long timeout = jiffies + 2 * HZ; |
339 | 375 | ||
340 | /* Use new timeout only if there wasn't a older one earlier. */ | 376 | /* Use new timeout only if there wasn't a older one earlier. */ |
341 | if (icsk->icsk_ack.pending & ICSK_ACK_TIMER) { | 377 | if (icsk->icsk_ack.pending & ICSK_ACK_TIMER) { |
342 | /* If delack timer was blocked or is about to expire, | 378 | /* If delack timer was blocked or is about to expire, |
343 | * send ACK now. | 379 | * send ACK now. |
344 | * | 380 | * |
345 | * FIXME: check the "about to expire" part | 381 | * FIXME: check the "about to expire" part |
346 | */ | 382 | */ |
347 | if (icsk->icsk_ack.blocked) { | 383 | if (icsk->icsk_ack.blocked) { |
348 | dccp_send_ack(sk); | 384 | dccp_send_ack(sk); |
349 | return; | 385 | return; |
350 | } | 386 | } |
351 | 387 | ||
352 | if (!time_before(timeout, icsk->icsk_ack.timeout)) | 388 | if (!time_before(timeout, icsk->icsk_ack.timeout)) |
353 | timeout = icsk->icsk_ack.timeout; | 389 | timeout = icsk->icsk_ack.timeout; |
354 | } | 390 | } |
355 | icsk->icsk_ack.pending |= ICSK_ACK_SCHED | ICSK_ACK_TIMER; | 391 | icsk->icsk_ack.pending |= ICSK_ACK_SCHED | ICSK_ACK_TIMER; |
356 | icsk->icsk_ack.timeout = timeout; | 392 | icsk->icsk_ack.timeout = timeout; |
357 | sk_reset_timer(sk, &icsk->icsk_delack_timer, timeout); | 393 | sk_reset_timer(sk, &icsk->icsk_delack_timer, timeout); |
358 | } | 394 | } |
359 | 395 | ||
360 | void dccp_send_sync(struct sock *sk, u64 seq) | 396 | void dccp_send_sync(struct sock *sk, u64 seq) |
361 | { | 397 | { |
362 | /* | 398 | /* |
363 | * We are not putting this on the write queue, so | 399 | * We are not putting this on the write queue, so |
364 | * dccp_transmit_skb() will set the ownership to this | 400 | * dccp_transmit_skb() will set the ownership to this |
365 | * sock. | 401 | * sock. |
366 | */ | 402 | */ |
367 | struct sk_buff *skb = alloc_skb(MAX_DCCP_HEADER, GFP_ATOMIC); | 403 | struct sk_buff *skb = alloc_skb(MAX_DCCP_HEADER, GFP_ATOMIC); |
368 | 404 | ||
369 | if (skb == NULL) | 405 | if (skb == NULL) |
370 | /* FIXME: how to make sure the sync is sent? */ | 406 | /* FIXME: how to make sure the sync is sent? */ |
371 | return; | 407 | return; |
372 | 408 | ||
373 | /* Reserve space for headers and prepare control bits. */ | 409 | /* Reserve space for headers and prepare control bits. */ |
374 | skb_reserve(skb, MAX_DCCP_HEADER); | 410 | skb_reserve(skb, MAX_DCCP_HEADER); |
375 | skb->csum = 0; | 411 | skb->csum = 0; |
376 | DCCP_SKB_CB(skb)->dccpd_type = DCCP_PKT_SYNC; | 412 | DCCP_SKB_CB(skb)->dccpd_type = DCCP_PKT_SYNC; |
377 | DCCP_SKB_CB(skb)->dccpd_seq = seq; | 413 | DCCP_SKB_CB(skb)->dccpd_seq = seq; |
378 | 414 | ||
379 | skb_set_owner_w(skb, sk); | 415 | skb_set_owner_w(skb, sk); |
380 | dccp_transmit_skb(sk, skb); | 416 | dccp_transmit_skb(sk, skb); |
381 | } | 417 | } |
382 | 418 | ||
383 | /* Send a DCCP_PKT_CLOSE/CLOSEREQ. The caller locks the socket for us. This cannot be | 419 | /* Send a DCCP_PKT_CLOSE/CLOSEREQ. The caller locks the socket for us. This cannot be |
384 | * allowed to fail queueing a DCCP_PKT_CLOSE/CLOSEREQ frame under any circumstances. | 420 | * allowed to fail queueing a DCCP_PKT_CLOSE/CLOSEREQ frame under any circumstances. |
385 | */ | 421 | */ |
386 | void dccp_send_close(struct sock *sk) | 422 | void dccp_send_close(struct sock *sk) |
387 | { | 423 | { |
388 | struct dccp_sock *dp = dccp_sk(sk); | 424 | struct dccp_sock *dp = dccp_sk(sk); |
389 | struct sk_buff *skb; | 425 | struct sk_buff *skb; |
390 | 426 | ||
391 | /* Socket is locked, keep trying until memory is available. */ | 427 | /* Socket is locked, keep trying until memory is available. */ |
392 | for (;;) { | 428 | for (;;) { |
393 | skb = alloc_skb(sk->sk_prot->max_header, GFP_KERNEL); | 429 | skb = alloc_skb(sk->sk_prot->max_header, GFP_KERNEL); |
394 | if (skb != NULL) | 430 | if (skb != NULL) |
395 | break; | 431 | break; |
396 | yield(); | 432 | yield(); |
397 | } | 433 | } |
398 | 434 | ||
399 | /* Reserve space for headers and prepare control bits. */ | 435 | /* Reserve space for headers and prepare control bits. */ |
400 | skb_reserve(skb, sk->sk_prot->max_header); | 436 | skb_reserve(skb, sk->sk_prot->max_header); |
401 | skb->csum = 0; | 437 | skb->csum = 0; |
402 | DCCP_SKB_CB(skb)->dccpd_type = dp->dccps_role == DCCP_ROLE_CLIENT ? DCCP_PKT_CLOSE : DCCP_PKT_CLOSEREQ; | 438 | DCCP_SKB_CB(skb)->dccpd_type = dp->dccps_role == DCCP_ROLE_CLIENT ? DCCP_PKT_CLOSE : DCCP_PKT_CLOSEREQ; |
403 | 439 | ||
404 | skb_set_owner_w(skb, sk); | 440 | skb_set_owner_w(skb, sk); |
405 | dccp_transmit_skb(sk, skb); | 441 | dccp_transmit_skb(sk, skb); |
406 | 442 | ||
407 | ccid_hc_rx_exit(dp->dccps_hc_rx_ccid, sk); | 443 | ccid_hc_rx_exit(dp->dccps_hc_rx_ccid, sk); |
408 | ccid_hc_tx_exit(dp->dccps_hc_tx_ccid, sk); | 444 | ccid_hc_tx_exit(dp->dccps_hc_tx_ccid, sk); |
409 | } | 445 | } |
410 | 446 |
net/dccp/proto.c
1 | /* | 1 | /* |
2 | * net/dccp/proto.c | 2 | * net/dccp/proto.c |
3 | * | 3 | * |
4 | * An implementation of the DCCP protocol | 4 | * An implementation of the DCCP protocol |
5 | * Arnaldo Carvalho de Melo <acme@conectiva.com.br> | 5 | * Arnaldo Carvalho de Melo <acme@conectiva.com.br> |
6 | * | 6 | * |
7 | * This program is free software; you can redistribute it and/or modify it | 7 | * This program is free software; you can redistribute it and/or modify it |
8 | * under the terms of the GNU General Public License version 2 as | 8 | * under the terms of the GNU General Public License version 2 as |
9 | * published by the Free Software Foundation. | 9 | * published by the Free Software Foundation. |
10 | */ | 10 | */ |
11 | 11 | ||
12 | #include <linux/config.h> | 12 | #include <linux/config.h> |
13 | #include <linux/dccp.h> | 13 | #include <linux/dccp.h> |
14 | #include <linux/module.h> | 14 | #include <linux/module.h> |
15 | #include <linux/types.h> | 15 | #include <linux/types.h> |
16 | #include <linux/sched.h> | 16 | #include <linux/sched.h> |
17 | #include <linux/kernel.h> | 17 | #include <linux/kernel.h> |
18 | #include <linux/skbuff.h> | 18 | #include <linux/skbuff.h> |
19 | #include <linux/netdevice.h> | 19 | #include <linux/netdevice.h> |
20 | #include <linux/in.h> | 20 | #include <linux/in.h> |
21 | #include <linux/if_arp.h> | 21 | #include <linux/if_arp.h> |
22 | #include <linux/init.h> | 22 | #include <linux/init.h> |
23 | #include <linux/random.h> | 23 | #include <linux/random.h> |
24 | #include <net/checksum.h> | 24 | #include <net/checksum.h> |
25 | 25 | ||
26 | #include <net/inet_common.h> | 26 | #include <net/inet_common.h> |
27 | #include <net/ip.h> | 27 | #include <net/ip.h> |
28 | #include <net/protocol.h> | 28 | #include <net/protocol.h> |
29 | #include <net/sock.h> | 29 | #include <net/sock.h> |
30 | #include <net/xfrm.h> | 30 | #include <net/xfrm.h> |
31 | 31 | ||
32 | #include <asm/semaphore.h> | 32 | #include <asm/semaphore.h> |
33 | #include <linux/spinlock.h> | 33 | #include <linux/spinlock.h> |
34 | #include <linux/timer.h> | 34 | #include <linux/timer.h> |
35 | #include <linux/delay.h> | 35 | #include <linux/delay.h> |
36 | #include <linux/poll.h> | 36 | #include <linux/poll.h> |
37 | #include <linux/dccp.h> | 37 | #include <linux/dccp.h> |
38 | 38 | ||
39 | #include "ccid.h" | 39 | #include "ccid.h" |
40 | #include "dccp.h" | 40 | #include "dccp.h" |
41 | 41 | ||
42 | DEFINE_SNMP_STAT(struct dccp_mib, dccp_statistics); | 42 | DEFINE_SNMP_STAT(struct dccp_mib, dccp_statistics); |
43 | 43 | ||
44 | atomic_t dccp_orphan_count = ATOMIC_INIT(0); | 44 | atomic_t dccp_orphan_count = ATOMIC_INIT(0); |
45 | 45 | ||
46 | static struct net_protocol dccp_protocol = { | 46 | static struct net_protocol dccp_protocol = { |
47 | .handler = dccp_v4_rcv, | 47 | .handler = dccp_v4_rcv, |
48 | .err_handler = dccp_v4_err, | 48 | .err_handler = dccp_v4_err, |
49 | }; | 49 | }; |
50 | 50 | ||
51 | const char *dccp_packet_name(const int type) | 51 | const char *dccp_packet_name(const int type) |
52 | { | 52 | { |
53 | static const char *dccp_packet_names[] = { | 53 | static const char *dccp_packet_names[] = { |
54 | [DCCP_PKT_REQUEST] = "REQUEST", | 54 | [DCCP_PKT_REQUEST] = "REQUEST", |
55 | [DCCP_PKT_RESPONSE] = "RESPONSE", | 55 | [DCCP_PKT_RESPONSE] = "RESPONSE", |
56 | [DCCP_PKT_DATA] = "DATA", | 56 | [DCCP_PKT_DATA] = "DATA", |
57 | [DCCP_PKT_ACK] = "ACK", | 57 | [DCCP_PKT_ACK] = "ACK", |
58 | [DCCP_PKT_DATAACK] = "DATAACK", | 58 | [DCCP_PKT_DATAACK] = "DATAACK", |
59 | [DCCP_PKT_CLOSEREQ] = "CLOSEREQ", | 59 | [DCCP_PKT_CLOSEREQ] = "CLOSEREQ", |
60 | [DCCP_PKT_CLOSE] = "CLOSE", | 60 | [DCCP_PKT_CLOSE] = "CLOSE", |
61 | [DCCP_PKT_RESET] = "RESET", | 61 | [DCCP_PKT_RESET] = "RESET", |
62 | [DCCP_PKT_SYNC] = "SYNC", | 62 | [DCCP_PKT_SYNC] = "SYNC", |
63 | [DCCP_PKT_SYNCACK] = "SYNCACK", | 63 | [DCCP_PKT_SYNCACK] = "SYNCACK", |
64 | }; | 64 | }; |
65 | 65 | ||
66 | if (type >= DCCP_NR_PKT_TYPES) | 66 | if (type >= DCCP_NR_PKT_TYPES) |
67 | return "INVALID"; | 67 | return "INVALID"; |
68 | else | 68 | else |
69 | return dccp_packet_names[type]; | 69 | return dccp_packet_names[type]; |
70 | } | 70 | } |
71 | 71 | ||
72 | EXPORT_SYMBOL_GPL(dccp_packet_name); | 72 | EXPORT_SYMBOL_GPL(dccp_packet_name); |
73 | 73 | ||
74 | const char *dccp_state_name(const int state) | 74 | const char *dccp_state_name(const int state) |
75 | { | 75 | { |
76 | static char *dccp_state_names[] = { | 76 | static char *dccp_state_names[] = { |
77 | [DCCP_OPEN] = "OPEN", | 77 | [DCCP_OPEN] = "OPEN", |
78 | [DCCP_REQUESTING] = "REQUESTING", | 78 | [DCCP_REQUESTING] = "REQUESTING", |
79 | [DCCP_PARTOPEN] = "PARTOPEN", | 79 | [DCCP_PARTOPEN] = "PARTOPEN", |
80 | [DCCP_LISTEN] = "LISTEN", | 80 | [DCCP_LISTEN] = "LISTEN", |
81 | [DCCP_RESPOND] = "RESPOND", | 81 | [DCCP_RESPOND] = "RESPOND", |
82 | [DCCP_CLOSING] = "CLOSING", | 82 | [DCCP_CLOSING] = "CLOSING", |
83 | [DCCP_TIME_WAIT] = "TIME_WAIT", | 83 | [DCCP_TIME_WAIT] = "TIME_WAIT", |
84 | [DCCP_CLOSED] = "CLOSED", | 84 | [DCCP_CLOSED] = "CLOSED", |
85 | }; | 85 | }; |
86 | 86 | ||
87 | if (state >= DCCP_MAX_STATES) | 87 | if (state >= DCCP_MAX_STATES) |
88 | return "INVALID STATE!"; | 88 | return "INVALID STATE!"; |
89 | else | 89 | else |
90 | return dccp_state_names[state]; | 90 | return dccp_state_names[state]; |
91 | } | 91 | } |
92 | 92 | ||
93 | EXPORT_SYMBOL_GPL(dccp_state_name); | 93 | EXPORT_SYMBOL_GPL(dccp_state_name); |
94 | 94 | ||
95 | static inline int dccp_listen_start(struct sock *sk) | 95 | static inline int dccp_listen_start(struct sock *sk) |
96 | { | 96 | { |
97 | dccp_sk(sk)->dccps_role = DCCP_ROLE_LISTEN; | 97 | dccp_sk(sk)->dccps_role = DCCP_ROLE_LISTEN; |
98 | return inet_csk_listen_start(sk, TCP_SYNQ_HSIZE); | 98 | return inet_csk_listen_start(sk, TCP_SYNQ_HSIZE); |
99 | } | 99 | } |
100 | 100 | ||
101 | int dccp_disconnect(struct sock *sk, int flags) | 101 | int dccp_disconnect(struct sock *sk, int flags) |
102 | { | 102 | { |
103 | struct inet_connection_sock *icsk = inet_csk(sk); | 103 | struct inet_connection_sock *icsk = inet_csk(sk); |
104 | struct inet_sock *inet = inet_sk(sk); | 104 | struct inet_sock *inet = inet_sk(sk); |
105 | int err = 0; | 105 | int err = 0; |
106 | const int old_state = sk->sk_state; | 106 | const int old_state = sk->sk_state; |
107 | 107 | ||
108 | if (old_state != DCCP_CLOSED) | 108 | if (old_state != DCCP_CLOSED) |
109 | dccp_set_state(sk, DCCP_CLOSED); | 109 | dccp_set_state(sk, DCCP_CLOSED); |
110 | 110 | ||
111 | /* ABORT function of RFC793 */ | 111 | /* ABORT function of RFC793 */ |
112 | if (old_state == DCCP_LISTEN) { | 112 | if (old_state == DCCP_LISTEN) { |
113 | inet_csk_listen_stop(sk); | 113 | inet_csk_listen_stop(sk); |
114 | /* FIXME: do the active reset thing */ | 114 | /* FIXME: do the active reset thing */ |
115 | } else if (old_state == DCCP_REQUESTING) | 115 | } else if (old_state == DCCP_REQUESTING) |
116 | sk->sk_err = ECONNRESET; | 116 | sk->sk_err = ECONNRESET; |
117 | 117 | ||
118 | dccp_clear_xmit_timers(sk); | 118 | dccp_clear_xmit_timers(sk); |
119 | __skb_queue_purge(&sk->sk_receive_queue); | 119 | __skb_queue_purge(&sk->sk_receive_queue); |
120 | if (sk->sk_send_head != NULL) { | 120 | if (sk->sk_send_head != NULL) { |
121 | __kfree_skb(sk->sk_send_head); | 121 | __kfree_skb(sk->sk_send_head); |
122 | sk->sk_send_head = NULL; | 122 | sk->sk_send_head = NULL; |
123 | } | 123 | } |
124 | 124 | ||
125 | inet->dport = 0; | 125 | inet->dport = 0; |
126 | 126 | ||
127 | if (!(sk->sk_userlocks & SOCK_BINDADDR_LOCK)) | 127 | if (!(sk->sk_userlocks & SOCK_BINDADDR_LOCK)) |
128 | inet_reset_saddr(sk); | 128 | inet_reset_saddr(sk); |
129 | 129 | ||
130 | sk->sk_shutdown = 0; | 130 | sk->sk_shutdown = 0; |
131 | sock_reset_flag(sk, SOCK_DONE); | 131 | sock_reset_flag(sk, SOCK_DONE); |
132 | 132 | ||
133 | icsk->icsk_backoff = 0; | 133 | icsk->icsk_backoff = 0; |
134 | inet_csk_delack_init(sk); | 134 | inet_csk_delack_init(sk); |
135 | __sk_dst_reset(sk); | 135 | __sk_dst_reset(sk); |
136 | 136 | ||
137 | BUG_TRAP(!inet->num || icsk->icsk_bind_hash); | 137 | BUG_TRAP(!inet->num || icsk->icsk_bind_hash); |
138 | 138 | ||
139 | sk->sk_error_report(sk); | 139 | sk->sk_error_report(sk); |
140 | return err; | 140 | return err; |
141 | } | 141 | } |
142 | 142 | ||
143 | int dccp_ioctl(struct sock *sk, int cmd, unsigned long arg) | 143 | int dccp_ioctl(struct sock *sk, int cmd, unsigned long arg) |
144 | { | 144 | { |
145 | dccp_pr_debug("entry\n"); | 145 | dccp_pr_debug("entry\n"); |
146 | return -ENOIOCTLCMD; | 146 | return -ENOIOCTLCMD; |
147 | } | 147 | } |
148 | 148 | ||
149 | int dccp_setsockopt(struct sock *sk, int level, int optname, | 149 | int dccp_setsockopt(struct sock *sk, int level, int optname, |
150 | char *optval, int optlen) | 150 | char *optval, int optlen) |
151 | { | 151 | { |
152 | dccp_pr_debug("entry\n"); | 152 | dccp_pr_debug("entry\n"); |
153 | 153 | ||
154 | if (level != SOL_DCCP) | 154 | if (level != SOL_DCCP) |
155 | return ip_setsockopt(sk, level, optname, optval, optlen); | 155 | return ip_setsockopt(sk, level, optname, optval, optlen); |
156 | 156 | ||
157 | return -EOPNOTSUPP; | 157 | return -EOPNOTSUPP; |
158 | } | 158 | } |
159 | 159 | ||
160 | int dccp_getsockopt(struct sock *sk, int level, int optname, | 160 | int dccp_getsockopt(struct sock *sk, int level, int optname, |
161 | char *optval, int *optlen) | 161 | char *optval, int *optlen) |
162 | { | 162 | { |
163 | dccp_pr_debug("entry\n"); | 163 | dccp_pr_debug("entry\n"); |
164 | 164 | ||
165 | if (level != SOL_DCCP) | 165 | if (level != SOL_DCCP) |
166 | return ip_getsockopt(sk, level, optname, optval, optlen); | 166 | return ip_getsockopt(sk, level, optname, optval, optlen); |
167 | 167 | ||
168 | return -EOPNOTSUPP; | 168 | return -EOPNOTSUPP; |
169 | } | 169 | } |
170 | 170 | ||
171 | int dccp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg, | 171 | int dccp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg, |
172 | size_t len) | 172 | size_t len) |
173 | { | 173 | { |
174 | const struct dccp_sock *dp = dccp_sk(sk); | 174 | const struct dccp_sock *dp = dccp_sk(sk); |
175 | const int flags = msg->msg_flags; | 175 | const int flags = msg->msg_flags; |
176 | const int noblock = flags & MSG_DONTWAIT; | 176 | const int noblock = flags & MSG_DONTWAIT; |
177 | struct sk_buff *skb; | 177 | struct sk_buff *skb; |
178 | int rc, size; | 178 | int rc, size; |
179 | long timeo; | 179 | long timeo; |
180 | 180 | ||
181 | if (len > dp->dccps_mss_cache) | 181 | if (len > dp->dccps_mss_cache) |
182 | return -EMSGSIZE; | 182 | return -EMSGSIZE; |
183 | 183 | ||
184 | lock_sock(sk); | 184 | lock_sock(sk); |
185 | timeo = sock_sndtimeo(sk, noblock); | ||
185 | 186 | ||
186 | timeo = sock_sndtimeo(sk, flags & MSG_DONTWAIT); | ||
187 | |||
188 | /* | 187 | /* |
189 | * We have to use sk_stream_wait_connect here to set sk_write_pending, | 188 | * We have to use sk_stream_wait_connect here to set sk_write_pending, |
190 | * so that the trick in dccp_rcv_request_sent_state_process. | 189 | * so that the trick in dccp_rcv_request_sent_state_process. |
191 | */ | 190 | */ |
192 | /* Wait for a connection to finish. */ | 191 | /* Wait for a connection to finish. */ |
193 | if ((1 << sk->sk_state) & ~(DCCPF_OPEN | DCCPF_PARTOPEN | DCCPF_CLOSING)) | 192 | if ((1 << sk->sk_state) & ~(DCCPF_OPEN | DCCPF_PARTOPEN | DCCPF_CLOSING)) |
194 | if ((rc = sk_stream_wait_connect(sk, &timeo)) != 0) | 193 | if ((rc = sk_stream_wait_connect(sk, &timeo)) != 0) |
195 | goto out_err; | 194 | goto out_release; |
196 | 195 | ||
197 | size = sk->sk_prot->max_header + len; | 196 | size = sk->sk_prot->max_header + len; |
198 | release_sock(sk); | 197 | release_sock(sk); |
199 | skb = sock_alloc_send_skb(sk, size, noblock, &rc); | 198 | skb = sock_alloc_send_skb(sk, size, noblock, &rc); |
200 | lock_sock(sk); | 199 | lock_sock(sk); |
201 | |||
202 | if (skb == NULL) | 200 | if (skb == NULL) |
203 | goto out_release; | 201 | goto out_release; |
204 | 202 | ||
205 | skb_reserve(skb, sk->sk_prot->max_header); | 203 | skb_reserve(skb, sk->sk_prot->max_header); |
206 | rc = memcpy_fromiovec(skb_put(skb, len), msg->msg_iov, len); | 204 | rc = memcpy_fromiovec(skb_put(skb, len), msg->msg_iov, len); |
207 | if (rc == 0) { | 205 | if (rc != 0) |
208 | struct dccp_skb_cb *dcb = DCCP_SKB_CB(skb); | 206 | goto out_discard; |
209 | const struct dccp_ackpkts *ap = dp->dccps_hc_rx_ackpkts; | ||
210 | long delay; | ||
211 | 207 | ||
212 | /* | 208 | rc = dccp_write_xmit(sk, skb, len); |
213 | * XXX: This is just to match the Waikato tree CA interaction | ||
214 | * points, after the CCID3 code is stable and I have a better | ||
215 | * understanding of behaviour I'll change this to look more like | ||
216 | * TCP. | ||
217 | */ | ||
218 | while (1) { | ||
219 | rc = ccid_hc_tx_send_packet(dp->dccps_hc_tx_ccid, sk, | ||
220 | skb, len, &delay); | ||
221 | if (rc == 0) | ||
222 | break; | ||
223 | if (rc != -EAGAIN) | ||
224 | goto out_discard; | ||
225 | if (delay > timeo) | ||
226 | goto out_discard; | ||
227 | release_sock(sk); | ||
228 | delay = schedule_timeout(delay); | ||
229 | lock_sock(sk); | ||
230 | timeo -= delay; | ||
231 | if (signal_pending(current)) | ||
232 | goto out_interrupted; | ||
233 | rc = -EPIPE; | ||
234 | if (!(sk->sk_state == DCCP_PARTOPEN || sk->sk_state == DCCP_OPEN)) | ||
235 | goto out_discard; | ||
236 | } | ||
237 | |||
238 | if (sk->sk_state == DCCP_PARTOPEN) { | ||
239 | /* See 8.1.5. Handshake Completion */ | ||
240 | inet_csk_schedule_ack(sk); | ||
241 | inet_csk_reset_xmit_timer(sk, ICSK_TIME_DACK, inet_csk(sk)->icsk_rto, TCP_RTO_MAX); | ||
242 | dcb->dccpd_type = DCCP_PKT_DATAACK; | ||
243 | /* FIXME: we really should have a dccps_ack_pending or use icsk */ | ||
244 | } else if (inet_csk_ack_scheduled(sk) || | ||
245 | (dp->dccps_options.dccpo_send_ack_vector && | ||
246 | ap->dccpap_buf_ackno != DCCP_MAX_SEQNO + 1 && | ||
247 | ap->dccpap_ack_seqno == DCCP_MAX_SEQNO + 1)) | ||
248 | dcb->dccpd_type = DCCP_PKT_DATAACK; | ||
249 | else | ||
250 | dcb->dccpd_type = DCCP_PKT_DATA; | ||
251 | dccp_transmit_skb(sk, skb); | ||
252 | ccid_hc_tx_packet_sent(dp->dccps_hc_tx_ccid, sk, 0, len); | ||
253 | } else { | ||
254 | out_discard: | ||
255 | kfree_skb(skb); | ||
256 | } | ||
257 | out_release: | 209 | out_release: |
258 | release_sock(sk); | 210 | release_sock(sk); |
259 | return rc ? : len; | 211 | return rc ? : len; |
260 | out_err: | 212 | out_discard: |
261 | rc = sk_stream_error(sk, flags, rc); | 213 | kfree_skb(skb); |
262 | goto out_release; | 214 | goto out_release; |
263 | out_interrupted: | ||
264 | rc = sock_intr_errno(timeo); | ||
265 | goto out_discard; | ||
266 | } | 215 | } |
267 | 216 | ||
268 | EXPORT_SYMBOL(dccp_sendmsg); | 217 | EXPORT_SYMBOL(dccp_sendmsg); |
269 | 218 | ||
270 | int dccp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg, | 219 | int dccp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg, |
271 | size_t len, int nonblock, int flags, int *addr_len) | 220 | size_t len, int nonblock, int flags, int *addr_len) |
272 | { | 221 | { |
273 | const struct dccp_hdr *dh; | 222 | const struct dccp_hdr *dh; |
274 | int copied = 0; | 223 | int copied = 0; |
275 | unsigned long used; | 224 | unsigned long used; |
276 | int err; | 225 | int err; |
277 | int target; /* Read at least this many bytes */ | 226 | int target; /* Read at least this many bytes */ |
278 | long timeo; | 227 | long timeo; |
279 | 228 | ||
280 | lock_sock(sk); | 229 | lock_sock(sk); |
281 | 230 | ||
282 | err = -ENOTCONN; | 231 | err = -ENOTCONN; |
283 | if (sk->sk_state == DCCP_LISTEN) | 232 | if (sk->sk_state == DCCP_LISTEN) |
284 | goto out; | 233 | goto out; |
285 | 234 | ||
286 | timeo = sock_rcvtimeo(sk, nonblock); | 235 | timeo = sock_rcvtimeo(sk, nonblock); |
287 | 236 | ||
288 | /* Urgent data needs to be handled specially. */ | 237 | /* Urgent data needs to be handled specially. */ |
289 | if (flags & MSG_OOB) | 238 | if (flags & MSG_OOB) |
290 | goto recv_urg; | 239 | goto recv_urg; |
291 | 240 | ||
292 | /* FIXME */ | 241 | /* FIXME */ |
293 | #if 0 | 242 | #if 0 |
294 | seq = &tp->copied_seq; | 243 | seq = &tp->copied_seq; |
295 | if (flags & MSG_PEEK) { | 244 | if (flags & MSG_PEEK) { |
296 | peek_seq = tp->copied_seq; | 245 | peek_seq = tp->copied_seq; |
297 | seq = &peek_seq; | 246 | seq = &peek_seq; |
298 | } | 247 | } |
299 | #endif | 248 | #endif |
300 | 249 | ||
301 | target = sock_rcvlowat(sk, flags & MSG_WAITALL, len); | 250 | target = sock_rcvlowat(sk, flags & MSG_WAITALL, len); |
302 | 251 | ||
303 | do { | 252 | do { |
304 | struct sk_buff *skb; | 253 | struct sk_buff *skb; |
305 | u32 offset; | 254 | u32 offset; |
306 | 255 | ||
307 | /* FIXME */ | 256 | /* FIXME */ |
308 | #if 0 | 257 | #if 0 |
309 | /* Are we at urgent data? Stop if we have read anything or have SIGURG pending. */ | 258 | /* Are we at urgent data? Stop if we have read anything or have SIGURG pending. */ |
310 | if (tp->urg_data && tp->urg_seq == *seq) { | 259 | if (tp->urg_data && tp->urg_seq == *seq) { |
311 | if (copied) | 260 | if (copied) |
312 | break; | 261 | break; |
313 | if (signal_pending(current)) { | 262 | if (signal_pending(current)) { |
314 | copied = timeo ? sock_intr_errno(timeo) : -EAGAIN; | 263 | copied = timeo ? sock_intr_errno(timeo) : -EAGAIN; |
315 | break; | 264 | break; |
316 | } | 265 | } |
317 | } | 266 | } |
318 | #endif | 267 | #endif |
319 | 268 | ||
320 | /* Next get a buffer. */ | 269 | /* Next get a buffer. */ |
321 | 270 | ||
322 | skb = skb_peek(&sk->sk_receive_queue); | 271 | skb = skb_peek(&sk->sk_receive_queue); |
323 | do { | 272 | do { |
324 | if (!skb) | 273 | if (!skb) |
325 | break; | 274 | break; |
326 | 275 | ||
327 | offset = 0; | 276 | offset = 0; |
328 | dh = dccp_hdr(skb); | 277 | dh = dccp_hdr(skb); |
329 | 278 | ||
330 | if (dh->dccph_type == DCCP_PKT_DATA || | 279 | if (dh->dccph_type == DCCP_PKT_DATA || |
331 | dh->dccph_type == DCCP_PKT_DATAACK) | 280 | dh->dccph_type == DCCP_PKT_DATAACK) |
332 | goto found_ok_skb; | 281 | goto found_ok_skb; |
333 | 282 | ||
334 | if (dh->dccph_type == DCCP_PKT_RESET || | 283 | if (dh->dccph_type == DCCP_PKT_RESET || |
335 | dh->dccph_type == DCCP_PKT_CLOSE) { | 284 | dh->dccph_type == DCCP_PKT_CLOSE) { |
336 | dccp_pr_debug("found fin ok!\n"); | 285 | dccp_pr_debug("found fin ok!\n"); |
337 | goto found_fin_ok; | 286 | goto found_fin_ok; |
338 | } | 287 | } |
339 | dccp_pr_debug("packet_type=%s\n", dccp_packet_name(dh->dccph_type)); | 288 | dccp_pr_debug("packet_type=%s\n", dccp_packet_name(dh->dccph_type)); |
340 | BUG_TRAP(flags & MSG_PEEK); | 289 | BUG_TRAP(flags & MSG_PEEK); |
341 | skb = skb->next; | 290 | skb = skb->next; |
342 | } while (skb != (struct sk_buff *)&sk->sk_receive_queue); | 291 | } while (skb != (struct sk_buff *)&sk->sk_receive_queue); |
343 | 292 | ||
344 | /* Well, if we have backlog, try to process it now yet. */ | 293 | /* Well, if we have backlog, try to process it now yet. */ |
345 | if (copied >= target && !sk->sk_backlog.tail) | 294 | if (copied >= target && !sk->sk_backlog.tail) |
346 | break; | 295 | break; |
347 | 296 | ||
348 | if (copied) { | 297 | if (copied) { |
349 | if (sk->sk_err || | 298 | if (sk->sk_err || |
350 | sk->sk_state == DCCP_CLOSED || | 299 | sk->sk_state == DCCP_CLOSED || |
351 | (sk->sk_shutdown & RCV_SHUTDOWN) || | 300 | (sk->sk_shutdown & RCV_SHUTDOWN) || |
352 | !timeo || | 301 | !timeo || |
353 | signal_pending(current) || | 302 | signal_pending(current) || |
354 | (flags & MSG_PEEK)) | 303 | (flags & MSG_PEEK)) |
355 | break; | 304 | break; |
356 | } else { | 305 | } else { |
357 | if (sock_flag(sk, SOCK_DONE)) | 306 | if (sock_flag(sk, SOCK_DONE)) |
358 | break; | 307 | break; |
359 | 308 | ||
360 | if (sk->sk_err) { | 309 | if (sk->sk_err) { |
361 | copied = sock_error(sk); | 310 | copied = sock_error(sk); |
362 | break; | 311 | break; |
363 | } | 312 | } |
364 | 313 | ||
365 | if (sk->sk_shutdown & RCV_SHUTDOWN) | 314 | if (sk->sk_shutdown & RCV_SHUTDOWN) |
366 | break; | 315 | break; |
367 | 316 | ||
368 | if (sk->sk_state == DCCP_CLOSED) { | 317 | if (sk->sk_state == DCCP_CLOSED) { |
369 | if (!sock_flag(sk, SOCK_DONE)) { | 318 | if (!sock_flag(sk, SOCK_DONE)) { |
370 | /* This occurs when user tries to read | 319 | /* This occurs when user tries to read |
371 | * from never connected socket. | 320 | * from never connected socket. |
372 | */ | 321 | */ |
373 | copied = -ENOTCONN; | 322 | copied = -ENOTCONN; |
374 | break; | 323 | break; |
375 | } | 324 | } |
376 | break; | 325 | break; |
377 | } | 326 | } |
378 | 327 | ||
379 | if (!timeo) { | 328 | if (!timeo) { |
380 | copied = -EAGAIN; | 329 | copied = -EAGAIN; |
381 | break; | 330 | break; |
382 | } | 331 | } |
383 | 332 | ||
384 | if (signal_pending(current)) { | 333 | if (signal_pending(current)) { |
385 | copied = sock_intr_errno(timeo); | 334 | copied = sock_intr_errno(timeo); |
386 | break; | 335 | break; |
387 | } | 336 | } |
388 | } | 337 | } |
389 | 338 | ||
390 | /* FIXME: cleanup_rbuf(sk, copied); */ | 339 | /* FIXME: cleanup_rbuf(sk, copied); */ |
391 | 340 | ||
392 | if (copied >= target) { | 341 | if (copied >= target) { |
393 | /* Do not sleep, just process backlog. */ | 342 | /* Do not sleep, just process backlog. */ |
394 | release_sock(sk); | 343 | release_sock(sk); |
395 | lock_sock(sk); | 344 | lock_sock(sk); |
396 | } else | 345 | } else |
397 | sk_wait_data(sk, &timeo); | 346 | sk_wait_data(sk, &timeo); |
398 | 347 | ||
399 | continue; | 348 | continue; |
400 | 349 | ||
401 | found_ok_skb: | 350 | found_ok_skb: |
402 | /* Ok so how much can we use? */ | 351 | /* Ok so how much can we use? */ |
403 | used = skb->len - offset; | 352 | used = skb->len - offset; |
404 | if (len < used) | 353 | if (len < used) |
405 | used = len; | 354 | used = len; |
406 | 355 | ||
407 | if (!(flags & MSG_TRUNC)) { | 356 | if (!(flags & MSG_TRUNC)) { |
408 | err = skb_copy_datagram_iovec(skb, offset, | 357 | err = skb_copy_datagram_iovec(skb, offset, |
409 | msg->msg_iov, used); | 358 | msg->msg_iov, used); |
410 | if (err) { | 359 | if (err) { |
411 | /* Exception. Bailout! */ | 360 | /* Exception. Bailout! */ |
412 | if (!copied) | 361 | if (!copied) |
413 | copied = -EFAULT; | 362 | copied = -EFAULT; |
414 | break; | 363 | break; |
415 | } | 364 | } |
416 | } | 365 | } |
417 | 366 | ||
418 | copied += used; | 367 | copied += used; |
419 | len -= used; | 368 | len -= used; |
420 | 369 | ||
421 | /* FIXME: tcp_rcv_space_adjust(sk); */ | 370 | /* FIXME: tcp_rcv_space_adjust(sk); */ |
422 | 371 | ||
423 | //skip_copy: | 372 | //skip_copy: |
424 | if (used + offset < skb->len) | 373 | if (used + offset < skb->len) |
425 | continue; | 374 | continue; |
426 | 375 | ||
427 | if (!(flags & MSG_PEEK)) | 376 | if (!(flags & MSG_PEEK)) |
428 | sk_eat_skb(sk, skb); | 377 | sk_eat_skb(sk, skb); |
429 | continue; | 378 | continue; |
430 | found_fin_ok: | 379 | found_fin_ok: |
431 | if (!(flags & MSG_PEEK)) | 380 | if (!(flags & MSG_PEEK)) |
432 | sk_eat_skb(sk, skb); | 381 | sk_eat_skb(sk, skb); |
433 | break; | 382 | break; |
434 | 383 | ||
435 | } while (len > 0); | 384 | } while (len > 0); |
436 | 385 | ||
437 | /* According to UNIX98, msg_name/msg_namelen are ignored | 386 | /* According to UNIX98, msg_name/msg_namelen are ignored |
438 | * on connected socket. I was just happy when found this 8) --ANK | 387 | * on connected socket. I was just happy when found this 8) --ANK |
439 | */ | 388 | */ |
440 | 389 | ||
441 | /* Clean up data we have read: This will do ACK frames. */ | 390 | /* Clean up data we have read: This will do ACK frames. */ |
442 | /* FIXME: cleanup_rbuf(sk, copied); */ | 391 | /* FIXME: cleanup_rbuf(sk, copied); */ |
443 | 392 | ||
444 | release_sock(sk); | 393 | release_sock(sk); |
445 | return copied; | 394 | return copied; |
446 | 395 | ||
447 | out: | 396 | out: |
448 | release_sock(sk); | 397 | release_sock(sk); |
449 | return err; | 398 | return err; |
450 | 399 | ||
451 | recv_urg: | 400 | recv_urg: |
452 | /* FIXME: err = tcp_recv_urg(sk, timeo, msg, len, flags, addr_len); */ | 401 | /* FIXME: err = tcp_recv_urg(sk, timeo, msg, len, flags, addr_len); */ |
453 | goto out; | 402 | goto out; |
454 | } | 403 | } |
455 | 404 | ||
456 | static int inet_dccp_listen(struct socket *sock, int backlog) | 405 | static int inet_dccp_listen(struct socket *sock, int backlog) |
457 | { | 406 | { |
458 | struct sock *sk = sock->sk; | 407 | struct sock *sk = sock->sk; |
459 | unsigned char old_state; | 408 | unsigned char old_state; |
460 | int err; | 409 | int err; |
461 | 410 | ||
462 | lock_sock(sk); | 411 | lock_sock(sk); |
463 | 412 | ||
464 | err = -EINVAL; | 413 | err = -EINVAL; |
465 | if (sock->state != SS_UNCONNECTED || sock->type != SOCK_DCCP) | 414 | if (sock->state != SS_UNCONNECTED || sock->type != SOCK_DCCP) |
466 | goto out; | 415 | goto out; |
467 | 416 | ||
468 | old_state = sk->sk_state; | 417 | old_state = sk->sk_state; |
469 | if (!((1 << old_state) & (DCCPF_CLOSED | DCCPF_LISTEN))) | 418 | if (!((1 << old_state) & (DCCPF_CLOSED | DCCPF_LISTEN))) |
470 | goto out; | 419 | goto out; |
471 | 420 | ||
472 | /* Really, if the socket is already in listen state | 421 | /* Really, if the socket is already in listen state |
473 | * we can only allow the backlog to be adjusted. | 422 | * we can only allow the backlog to be adjusted. |
474 | */ | 423 | */ |
475 | if (old_state != DCCP_LISTEN) { | 424 | if (old_state != DCCP_LISTEN) { |
476 | /* | 425 | /* |
477 | * FIXME: here it probably should be sk->sk_prot->listen_start | 426 | * FIXME: here it probably should be sk->sk_prot->listen_start |
478 | * see tcp_listen_start | 427 | * see tcp_listen_start |
479 | */ | 428 | */ |
480 | err = dccp_listen_start(sk); | 429 | err = dccp_listen_start(sk); |
481 | if (err) | 430 | if (err) |
482 | goto out; | 431 | goto out; |
483 | } | 432 | } |
484 | sk->sk_max_ack_backlog = backlog; | 433 | sk->sk_max_ack_backlog = backlog; |
485 | err = 0; | 434 | err = 0; |
486 | 435 | ||
487 | out: | 436 | out: |
488 | release_sock(sk); | 437 | release_sock(sk); |
489 | return err; | 438 | return err; |
490 | } | 439 | } |
491 | 440 | ||
492 | static const unsigned char dccp_new_state[] = { | 441 | static const unsigned char dccp_new_state[] = { |
493 | /* current state: new state: action: */ | 442 | /* current state: new state: action: */ |
494 | [0] = DCCP_CLOSED, | 443 | [0] = DCCP_CLOSED, |
495 | [DCCP_OPEN] = DCCP_CLOSING | DCCP_ACTION_FIN, | 444 | [DCCP_OPEN] = DCCP_CLOSING | DCCP_ACTION_FIN, |
496 | [DCCP_REQUESTING] = DCCP_CLOSED, | 445 | [DCCP_REQUESTING] = DCCP_CLOSED, |
497 | [DCCP_PARTOPEN] = DCCP_CLOSING | DCCP_ACTION_FIN, | 446 | [DCCP_PARTOPEN] = DCCP_CLOSING | DCCP_ACTION_FIN, |
498 | [DCCP_LISTEN] = DCCP_CLOSED, | 447 | [DCCP_LISTEN] = DCCP_CLOSED, |
499 | [DCCP_RESPOND] = DCCP_CLOSED, | 448 | [DCCP_RESPOND] = DCCP_CLOSED, |
500 | [DCCP_CLOSING] = DCCP_CLOSED, | 449 | [DCCP_CLOSING] = DCCP_CLOSED, |
501 | [DCCP_TIME_WAIT] = DCCP_CLOSED, | 450 | [DCCP_TIME_WAIT] = DCCP_CLOSED, |
502 | [DCCP_CLOSED] = DCCP_CLOSED, | 451 | [DCCP_CLOSED] = DCCP_CLOSED, |
503 | }; | 452 | }; |
504 | 453 | ||
505 | static int dccp_close_state(struct sock *sk) | 454 | static int dccp_close_state(struct sock *sk) |
506 | { | 455 | { |
507 | const int next = dccp_new_state[sk->sk_state]; | 456 | const int next = dccp_new_state[sk->sk_state]; |
508 | const int ns = next & DCCP_STATE_MASK; | 457 | const int ns = next & DCCP_STATE_MASK; |
509 | 458 | ||
510 | if (ns != sk->sk_state) | 459 | if (ns != sk->sk_state) |
511 | dccp_set_state(sk, ns); | 460 | dccp_set_state(sk, ns); |
512 | 461 | ||
513 | return next & DCCP_ACTION_FIN; | 462 | return next & DCCP_ACTION_FIN; |
514 | } | 463 | } |
515 | 464 | ||
516 | void dccp_close(struct sock *sk, long timeout) | 465 | void dccp_close(struct sock *sk, long timeout) |
517 | { | 466 | { |
518 | struct sk_buff *skb; | 467 | struct sk_buff *skb; |
519 | 468 | ||
520 | lock_sock(sk); | 469 | lock_sock(sk); |
521 | 470 | ||
522 | sk->sk_shutdown = SHUTDOWN_MASK; | 471 | sk->sk_shutdown = SHUTDOWN_MASK; |
523 | 472 | ||
524 | if (sk->sk_state == DCCP_LISTEN) { | 473 | if (sk->sk_state == DCCP_LISTEN) { |
525 | dccp_set_state(sk, DCCP_CLOSED); | 474 | dccp_set_state(sk, DCCP_CLOSED); |
526 | 475 | ||
527 | /* Special case. */ | 476 | /* Special case. */ |
528 | inet_csk_listen_stop(sk); | 477 | inet_csk_listen_stop(sk); |
529 | 478 | ||
530 | goto adjudge_to_death; | 479 | goto adjudge_to_death; |
531 | } | 480 | } |
532 | 481 | ||
533 | /* | 482 | /* |
534 | * We need to flush the recv. buffs. We do this only on the | 483 | * We need to flush the recv. buffs. We do this only on the |
535 | * descriptor close, not protocol-sourced closes, because the | 484 | * descriptor close, not protocol-sourced closes, because the |
536 | *reader process may not have drained the data yet! | 485 | *reader process may not have drained the data yet! |
537 | */ | 486 | */ |
538 | /* FIXME: check for unread data */ | 487 | /* FIXME: check for unread data */ |
539 | while ((skb = __skb_dequeue(&sk->sk_receive_queue)) != NULL) { | 488 | while ((skb = __skb_dequeue(&sk->sk_receive_queue)) != NULL) { |
540 | __kfree_skb(skb); | 489 | __kfree_skb(skb); |
541 | } | 490 | } |
542 | 491 | ||
543 | if (sock_flag(sk, SOCK_LINGER) && !sk->sk_lingertime) { | 492 | if (sock_flag(sk, SOCK_LINGER) && !sk->sk_lingertime) { |
544 | /* Check zero linger _after_ checking for unread data. */ | 493 | /* Check zero linger _after_ checking for unread data. */ |
545 | sk->sk_prot->disconnect(sk, 0); | 494 | sk->sk_prot->disconnect(sk, 0); |
546 | } else if (dccp_close_state(sk)) { | 495 | } else if (dccp_close_state(sk)) { |
547 | dccp_send_close(sk); | 496 | dccp_send_close(sk); |
548 | } | 497 | } |
549 | 498 | ||
550 | sk_stream_wait_close(sk, timeout); | 499 | sk_stream_wait_close(sk, timeout); |
551 | 500 | ||
552 | adjudge_to_death: | 501 | adjudge_to_death: |
553 | release_sock(sk); | 502 | release_sock(sk); |
554 | /* | 503 | /* |
555 | * Now socket is owned by kernel and we acquire BH lock | 504 | * Now socket is owned by kernel and we acquire BH lock |
556 | * to finish close. No need to check for user refs. | 505 | * to finish close. No need to check for user refs. |
557 | */ | 506 | */ |
558 | local_bh_disable(); | 507 | local_bh_disable(); |
559 | bh_lock_sock(sk); | 508 | bh_lock_sock(sk); |
560 | BUG_TRAP(!sock_owned_by_user(sk)); | 509 | BUG_TRAP(!sock_owned_by_user(sk)); |
561 | 510 | ||
562 | sock_hold(sk); | 511 | sock_hold(sk); |
563 | sock_orphan(sk); | 512 | sock_orphan(sk); |
564 | 513 | ||
565 | if (sk->sk_state != DCCP_CLOSED) | 514 | if (sk->sk_state != DCCP_CLOSED) |
566 | dccp_set_state(sk, DCCP_CLOSED); | 515 | dccp_set_state(sk, DCCP_CLOSED); |
567 | 516 | ||
568 | atomic_inc(&dccp_orphan_count); | 517 | atomic_inc(&dccp_orphan_count); |
569 | if (sk->sk_state == DCCP_CLOSED) | 518 | if (sk->sk_state == DCCP_CLOSED) |
570 | inet_csk_destroy_sock(sk); | 519 | inet_csk_destroy_sock(sk); |
571 | 520 | ||
572 | /* Otherwise, socket is reprieved until protocol close. */ | 521 | /* Otherwise, socket is reprieved until protocol close. */ |
573 | 522 | ||
574 | bh_unlock_sock(sk); | 523 | bh_unlock_sock(sk); |
575 | local_bh_enable(); | 524 | local_bh_enable(); |
576 | sock_put(sk); | 525 | sock_put(sk); |
577 | } | 526 | } |
578 | 527 | ||
579 | void dccp_shutdown(struct sock *sk, int how) | 528 | void dccp_shutdown(struct sock *sk, int how) |
580 | { | 529 | { |
581 | dccp_pr_debug("entry\n"); | 530 | dccp_pr_debug("entry\n"); |
582 | } | 531 | } |
583 | 532 | ||
584 | struct proto_ops inet_dccp_ops = { | 533 | struct proto_ops inet_dccp_ops = { |
585 | .family = PF_INET, | 534 | .family = PF_INET, |
586 | .owner = THIS_MODULE, | 535 | .owner = THIS_MODULE, |
587 | .release = inet_release, | 536 | .release = inet_release, |
588 | .bind = inet_bind, | 537 | .bind = inet_bind, |
589 | .connect = inet_stream_connect, | 538 | .connect = inet_stream_connect, |
590 | .socketpair = sock_no_socketpair, | 539 | .socketpair = sock_no_socketpair, |
591 | .accept = inet_accept, | 540 | .accept = inet_accept, |
592 | .getname = inet_getname, | 541 | .getname = inet_getname, |
593 | .poll = sock_no_poll, | 542 | .poll = sock_no_poll, |
594 | .ioctl = inet_ioctl, | 543 | .ioctl = inet_ioctl, |
595 | .listen = inet_dccp_listen, /* FIXME: work on inet_listen to rename it to sock_common_listen */ | 544 | .listen = inet_dccp_listen, /* FIXME: work on inet_listen to rename it to sock_common_listen */ |
596 | .shutdown = inet_shutdown, | 545 | .shutdown = inet_shutdown, |
597 | .setsockopt = sock_common_setsockopt, | 546 | .setsockopt = sock_common_setsockopt, |
598 | .getsockopt = sock_common_getsockopt, | 547 | .getsockopt = sock_common_getsockopt, |
599 | .sendmsg = inet_sendmsg, | 548 | .sendmsg = inet_sendmsg, |
600 | .recvmsg = sock_common_recvmsg, | 549 | .recvmsg = sock_common_recvmsg, |
601 | .mmap = sock_no_mmap, | 550 | .mmap = sock_no_mmap, |
602 | .sendpage = sock_no_sendpage, | 551 | .sendpage = sock_no_sendpage, |
603 | }; | 552 | }; |
604 | 553 | ||
605 | extern struct net_proto_family inet_family_ops; | 554 | extern struct net_proto_family inet_family_ops; |
606 | 555 | ||
607 | static struct inet_protosw dccp_v4_protosw = { | 556 | static struct inet_protosw dccp_v4_protosw = { |
608 | .type = SOCK_DCCP, | 557 | .type = SOCK_DCCP, |
609 | .protocol = IPPROTO_DCCP, | 558 | .protocol = IPPROTO_DCCP, |
610 | .prot = &dccp_v4_prot, | 559 | .prot = &dccp_v4_prot, |
611 | .ops = &inet_dccp_ops, | 560 | .ops = &inet_dccp_ops, |
612 | .capability = -1, | 561 | .capability = -1, |
613 | .no_check = 0, | 562 | .no_check = 0, |
614 | .flags = 0, | 563 | .flags = 0, |
615 | }; | 564 | }; |
616 | 565 | ||
617 | /* | 566 | /* |
618 | * This is the global socket data structure used for responding to | 567 | * This is the global socket data structure used for responding to |
619 | * the Out-of-the-blue (OOTB) packets. A control sock will be created | 568 | * the Out-of-the-blue (OOTB) packets. A control sock will be created |
620 | * for this socket at the initialization time. | 569 | * for this socket at the initialization time. |
621 | */ | 570 | */ |
622 | struct socket *dccp_ctl_socket; | 571 | struct socket *dccp_ctl_socket; |
623 | 572 | ||
624 | static char dccp_ctl_socket_err_msg[] __initdata = | 573 | static char dccp_ctl_socket_err_msg[] __initdata = |
625 | KERN_ERR "DCCP: Failed to create the control socket.\n"; | 574 | KERN_ERR "DCCP: Failed to create the control socket.\n"; |
626 | 575 | ||
627 | static int __init dccp_ctl_sock_init(void) | 576 | static int __init dccp_ctl_sock_init(void) |
628 | { | 577 | { |
629 | int rc = sock_create_kern(PF_INET, SOCK_DCCP, IPPROTO_DCCP, | 578 | int rc = sock_create_kern(PF_INET, SOCK_DCCP, IPPROTO_DCCP, |
630 | &dccp_ctl_socket); | 579 | &dccp_ctl_socket); |
631 | if (rc < 0) | 580 | if (rc < 0) |
632 | printk(dccp_ctl_socket_err_msg); | 581 | printk(dccp_ctl_socket_err_msg); |
633 | else { | 582 | else { |
634 | dccp_ctl_socket->sk->sk_allocation = GFP_ATOMIC; | 583 | dccp_ctl_socket->sk->sk_allocation = GFP_ATOMIC; |
635 | inet_sk(dccp_ctl_socket->sk)->uc_ttl = -1; | 584 | inet_sk(dccp_ctl_socket->sk)->uc_ttl = -1; |
636 | 585 | ||
637 | /* Unhash it so that IP input processing does not even | 586 | /* Unhash it so that IP input processing does not even |
638 | * see it, we do not wish this socket to see incoming | 587 | * see it, we do not wish this socket to see incoming |
639 | * packets. | 588 | * packets. |
640 | */ | 589 | */ |
641 | dccp_ctl_socket->sk->sk_prot->unhash(dccp_ctl_socket->sk); | 590 | dccp_ctl_socket->sk->sk_prot->unhash(dccp_ctl_socket->sk); |
642 | } | 591 | } |
643 | 592 | ||
644 | return rc; | 593 | return rc; |
645 | } | 594 | } |
646 | 595 | ||
647 | static void __exit dccp_ctl_sock_exit(void) | 596 | static void __exit dccp_ctl_sock_exit(void) |
648 | { | 597 | { |
649 | if (dccp_ctl_socket != NULL) | 598 | if (dccp_ctl_socket != NULL) |
650 | sock_release(dccp_ctl_socket); | 599 | sock_release(dccp_ctl_socket); |
651 | } | 600 | } |
652 | 601 | ||
653 | static int __init init_dccp_v4_mibs(void) | 602 | static int __init init_dccp_v4_mibs(void) |
654 | { | 603 | { |
655 | int rc = -ENOMEM; | 604 | int rc = -ENOMEM; |
656 | 605 | ||
657 | dccp_statistics[0] = alloc_percpu(struct dccp_mib); | 606 | dccp_statistics[0] = alloc_percpu(struct dccp_mib); |
658 | if (dccp_statistics[0] == NULL) | 607 | if (dccp_statistics[0] == NULL) |
659 | goto out; | 608 | goto out; |
660 | 609 | ||
661 | dccp_statistics[1] = alloc_percpu(struct dccp_mib); | 610 | dccp_statistics[1] = alloc_percpu(struct dccp_mib); |
662 | if (dccp_statistics[1] == NULL) | 611 | if (dccp_statistics[1] == NULL) |
663 | goto out_free_one; | 612 | goto out_free_one; |
664 | 613 | ||
665 | rc = 0; | 614 | rc = 0; |
666 | out: | 615 | out: |
667 | return rc; | 616 | return rc; |
668 | out_free_one: | 617 | out_free_one: |
669 | free_percpu(dccp_statistics[0]); | 618 | free_percpu(dccp_statistics[0]); |
670 | dccp_statistics[0] = NULL; | 619 | dccp_statistics[0] = NULL; |
671 | goto out; | 620 | goto out; |
672 | 621 | ||
673 | } | 622 | } |
674 | 623 | ||
675 | static int thash_entries; | 624 | static int thash_entries; |
676 | module_param(thash_entries, int, 0444); | 625 | module_param(thash_entries, int, 0444); |
677 | MODULE_PARM_DESC(thash_entries, "Number of ehash buckets"); | 626 | MODULE_PARM_DESC(thash_entries, "Number of ehash buckets"); |
678 | 627 | ||
679 | int dccp_debug; | 628 | int dccp_debug; |
680 | module_param(dccp_debug, int, 0444); | 629 | module_param(dccp_debug, int, 0444); |
681 | MODULE_PARM_DESC(dccp_debug, "Enable debug messages"); | 630 | MODULE_PARM_DESC(dccp_debug, "Enable debug messages"); |
682 | 631 | ||
683 | static int __init dccp_init(void) | 632 | static int __init dccp_init(void) |
684 | { | 633 | { |
685 | unsigned long goal; | 634 | unsigned long goal; |
686 | int ehash_order, bhash_order, i; | 635 | int ehash_order, bhash_order, i; |
687 | int rc = proto_register(&dccp_v4_prot, 1); | 636 | int rc = proto_register(&dccp_v4_prot, 1); |
688 | 637 | ||
689 | if (rc) | 638 | if (rc) |
690 | goto out; | 639 | goto out; |
691 | 640 | ||
692 | dccp_hashinfo.bind_bucket_cachep = kmem_cache_create("dccp_bind_bucket", | 641 | dccp_hashinfo.bind_bucket_cachep = kmem_cache_create("dccp_bind_bucket", |
693 | sizeof(struct inet_bind_bucket), | 642 | sizeof(struct inet_bind_bucket), |
694 | 0, SLAB_HWCACHE_ALIGN, | 643 | 0, SLAB_HWCACHE_ALIGN, |
695 | NULL, NULL); | 644 | NULL, NULL); |
696 | if (!dccp_hashinfo.bind_bucket_cachep) | 645 | if (!dccp_hashinfo.bind_bucket_cachep) |
697 | goto out_proto_unregister; | 646 | goto out_proto_unregister; |
698 | 647 | ||
699 | /* | 648 | /* |
700 | * Size and allocate the main established and bind bucket | 649 | * Size and allocate the main established and bind bucket |
701 | * hash tables. | 650 | * hash tables. |
702 | * | 651 | * |
703 | * The methodology is similar to that of the buffer cache. | 652 | * The methodology is similar to that of the buffer cache. |
704 | */ | 653 | */ |
705 | if (num_physpages >= (128 * 1024)) | 654 | if (num_physpages >= (128 * 1024)) |
706 | goal = num_physpages >> (21 - PAGE_SHIFT); | 655 | goal = num_physpages >> (21 - PAGE_SHIFT); |
707 | else | 656 | else |
708 | goal = num_physpages >> (23 - PAGE_SHIFT); | 657 | goal = num_physpages >> (23 - PAGE_SHIFT); |
709 | 658 | ||
710 | if (thash_entries) | 659 | if (thash_entries) |
711 | goal = (thash_entries * sizeof(struct inet_ehash_bucket)) >> PAGE_SHIFT; | 660 | goal = (thash_entries * sizeof(struct inet_ehash_bucket)) >> PAGE_SHIFT; |
712 | for (ehash_order = 0; (1UL << ehash_order) < goal; ehash_order++) | 661 | for (ehash_order = 0; (1UL << ehash_order) < goal; ehash_order++) |
713 | ; | 662 | ; |
714 | do { | 663 | do { |
715 | dccp_hashinfo.ehash_size = (1UL << ehash_order) * PAGE_SIZE / | 664 | dccp_hashinfo.ehash_size = (1UL << ehash_order) * PAGE_SIZE / |
716 | sizeof(struct inet_ehash_bucket); | 665 | sizeof(struct inet_ehash_bucket); |
717 | dccp_hashinfo.ehash_size >>= 1; | 666 | dccp_hashinfo.ehash_size >>= 1; |
718 | while (dccp_hashinfo.ehash_size & (dccp_hashinfo.ehash_size - 1)) | 667 | while (dccp_hashinfo.ehash_size & (dccp_hashinfo.ehash_size - 1)) |
719 | dccp_hashinfo.ehash_size--; | 668 | dccp_hashinfo.ehash_size--; |
720 | dccp_hashinfo.ehash = (struct inet_ehash_bucket *) | 669 | dccp_hashinfo.ehash = (struct inet_ehash_bucket *) |
721 | __get_free_pages(GFP_ATOMIC, ehash_order); | 670 | __get_free_pages(GFP_ATOMIC, ehash_order); |
722 | } while (!dccp_hashinfo.ehash && --ehash_order > 0); | 671 | } while (!dccp_hashinfo.ehash && --ehash_order > 0); |
723 | 672 | ||
724 | if (!dccp_hashinfo.ehash) { | 673 | if (!dccp_hashinfo.ehash) { |
725 | printk(KERN_CRIT "Failed to allocate DCCP " | 674 | printk(KERN_CRIT "Failed to allocate DCCP " |
726 | "established hash table\n"); | 675 | "established hash table\n"); |
727 | goto out_free_bind_bucket_cachep; | 676 | goto out_free_bind_bucket_cachep; |
728 | } | 677 | } |
729 | 678 | ||
730 | for (i = 0; i < (dccp_hashinfo.ehash_size << 1); i++) { | 679 | for (i = 0; i < (dccp_hashinfo.ehash_size << 1); i++) { |
731 | rwlock_init(&dccp_hashinfo.ehash[i].lock); | 680 | rwlock_init(&dccp_hashinfo.ehash[i].lock); |
732 | INIT_HLIST_HEAD(&dccp_hashinfo.ehash[i].chain); | 681 | INIT_HLIST_HEAD(&dccp_hashinfo.ehash[i].chain); |
733 | } | 682 | } |
734 | 683 | ||
735 | bhash_order = ehash_order; | 684 | bhash_order = ehash_order; |
736 | 685 | ||
737 | do { | 686 | do { |
738 | dccp_hashinfo.bhash_size = (1UL << bhash_order) * PAGE_SIZE / | 687 | dccp_hashinfo.bhash_size = (1UL << bhash_order) * PAGE_SIZE / |
739 | sizeof(struct inet_bind_hashbucket); | 688 | sizeof(struct inet_bind_hashbucket); |
740 | if ((dccp_hashinfo.bhash_size > (64 * 1024)) && bhash_order > 0) | 689 | if ((dccp_hashinfo.bhash_size > (64 * 1024)) && bhash_order > 0) |
741 | continue; | 690 | continue; |
742 | dccp_hashinfo.bhash = (struct inet_bind_hashbucket *) | 691 | dccp_hashinfo.bhash = (struct inet_bind_hashbucket *) |
743 | __get_free_pages(GFP_ATOMIC, bhash_order); | 692 | __get_free_pages(GFP_ATOMIC, bhash_order); |
744 | } while (!dccp_hashinfo.bhash && --bhash_order >= 0); | 693 | } while (!dccp_hashinfo.bhash && --bhash_order >= 0); |
745 | 694 | ||
746 | if (!dccp_hashinfo.bhash) { | 695 | if (!dccp_hashinfo.bhash) { |
747 | printk(KERN_CRIT "Failed to allocate DCCP bind hash table\n"); | 696 | printk(KERN_CRIT "Failed to allocate DCCP bind hash table\n"); |
748 | goto out_free_dccp_ehash; | 697 | goto out_free_dccp_ehash; |
749 | } | 698 | } |
750 | 699 | ||
751 | for (i = 0; i < dccp_hashinfo.bhash_size; i++) { | 700 | for (i = 0; i < dccp_hashinfo.bhash_size; i++) { |
752 | spin_lock_init(&dccp_hashinfo.bhash[i].lock); | 701 | spin_lock_init(&dccp_hashinfo.bhash[i].lock); |
753 | INIT_HLIST_HEAD(&dccp_hashinfo.bhash[i].chain); | 702 | INIT_HLIST_HEAD(&dccp_hashinfo.bhash[i].chain); |
754 | } | 703 | } |
755 | 704 | ||
756 | if (init_dccp_v4_mibs()) | 705 | if (init_dccp_v4_mibs()) |
757 | goto out_free_dccp_bhash; | 706 | goto out_free_dccp_bhash; |
758 | 707 | ||
759 | rc = -EAGAIN; | 708 | rc = -EAGAIN; |
760 | if (inet_add_protocol(&dccp_protocol, IPPROTO_DCCP)) | 709 | if (inet_add_protocol(&dccp_protocol, IPPROTO_DCCP)) |
761 | goto out_free_dccp_v4_mibs; | 710 | goto out_free_dccp_v4_mibs; |
762 | 711 | ||
763 | inet_register_protosw(&dccp_v4_protosw); | 712 | inet_register_protosw(&dccp_v4_protosw); |
764 | 713 | ||
765 | rc = dccp_ctl_sock_init(); | 714 | rc = dccp_ctl_sock_init(); |
766 | if (rc) | 715 | if (rc) |
767 | goto out_unregister_protosw; | 716 | goto out_unregister_protosw; |
768 | out: | 717 | out: |
769 | return rc; | 718 | return rc; |
770 | out_unregister_protosw: | 719 | out_unregister_protosw: |
771 | inet_unregister_protosw(&dccp_v4_protosw); | 720 | inet_unregister_protosw(&dccp_v4_protosw); |
772 | inet_del_protocol(&dccp_protocol, IPPROTO_DCCP); | 721 | inet_del_protocol(&dccp_protocol, IPPROTO_DCCP); |
773 | out_free_dccp_v4_mibs: | 722 | out_free_dccp_v4_mibs: |
774 | free_percpu(dccp_statistics[0]); | 723 | free_percpu(dccp_statistics[0]); |
775 | free_percpu(dccp_statistics[1]); | 724 | free_percpu(dccp_statistics[1]); |
776 | dccp_statistics[0] = dccp_statistics[1] = NULL; | 725 | dccp_statistics[0] = dccp_statistics[1] = NULL; |
777 | out_free_dccp_bhash: | 726 | out_free_dccp_bhash: |
778 | free_pages((unsigned long)dccp_hashinfo.bhash, bhash_order); | 727 | free_pages((unsigned long)dccp_hashinfo.bhash, bhash_order); |
779 | dccp_hashinfo.bhash = NULL; | 728 | dccp_hashinfo.bhash = NULL; |
780 | out_free_dccp_ehash: | 729 | out_free_dccp_ehash: |
781 | free_pages((unsigned long)dccp_hashinfo.ehash, ehash_order); | 730 | free_pages((unsigned long)dccp_hashinfo.ehash, ehash_order); |
782 | dccp_hashinfo.ehash = NULL; | 731 | dccp_hashinfo.ehash = NULL; |
783 | out_free_bind_bucket_cachep: | 732 | out_free_bind_bucket_cachep: |
784 | kmem_cache_destroy(dccp_hashinfo.bind_bucket_cachep); | 733 | kmem_cache_destroy(dccp_hashinfo.bind_bucket_cachep); |
785 | dccp_hashinfo.bind_bucket_cachep = NULL; | 734 | dccp_hashinfo.bind_bucket_cachep = NULL; |
786 | out_proto_unregister: | 735 | out_proto_unregister: |
787 | proto_unregister(&dccp_v4_prot); | 736 | proto_unregister(&dccp_v4_prot); |
788 | goto out; | 737 | goto out; |
789 | } | 738 | } |
790 | 739 | ||
791 | static const char dccp_del_proto_err_msg[] __exitdata = | 740 | static const char dccp_del_proto_err_msg[] __exitdata = |
792 | KERN_ERR "can't remove dccp net_protocol\n"; | 741 | KERN_ERR "can't remove dccp net_protocol\n"; |
793 | 742 | ||
794 | static void __exit dccp_fini(void) | 743 | static void __exit dccp_fini(void) |
795 | { | 744 | { |
796 | dccp_ctl_sock_exit(); | 745 | dccp_ctl_sock_exit(); |
797 | 746 | ||
798 | inet_unregister_protosw(&dccp_v4_protosw); | 747 | inet_unregister_protosw(&dccp_v4_protosw); |
799 | 748 | ||
800 | if (inet_del_protocol(&dccp_protocol, IPPROTO_DCCP) < 0) | 749 | if (inet_del_protocol(&dccp_protocol, IPPROTO_DCCP) < 0) |
801 | printk(dccp_del_proto_err_msg); | 750 | printk(dccp_del_proto_err_msg); |
802 | 751 | ||
803 | /* Free the control endpoint. */ | 752 | /* Free the control endpoint. */ |
804 | sock_release(dccp_ctl_socket); | 753 | sock_release(dccp_ctl_socket); |
805 | 754 | ||
806 | proto_unregister(&dccp_v4_prot); | 755 | proto_unregister(&dccp_v4_prot); |
807 | 756 | ||
808 | kmem_cache_destroy(dccp_hashinfo.bind_bucket_cachep); | 757 | kmem_cache_destroy(dccp_hashinfo.bind_bucket_cachep); |
809 | } | 758 | } |
810 | 759 | ||
811 | module_init(dccp_init); | 760 | module_init(dccp_init); |
812 | module_exit(dccp_fini); | 761 | module_exit(dccp_fini); |
813 | 762 | ||
814 | /* | 763 | /* |
815 | * __stringify doesn't likes enums, so use SOCK_DCCP (6) and IPPROTO_DCCP (33) | 764 | * __stringify doesn't likes enums, so use SOCK_DCCP (6) and IPPROTO_DCCP (33) |
816 | * values directly, Also cover the case where the protocol is not specified, | 765 | * values directly, Also cover the case where the protocol is not specified, |
817 | * i.e. net-pf-PF_INET-proto-0-type-SOCK_DCCP | 766 | * i.e. net-pf-PF_INET-proto-0-type-SOCK_DCCP |
818 | */ | 767 | */ |
819 | MODULE_ALIAS("net-pf-" __stringify(PF_INET) "-proto-33-type-6"); | 768 | MODULE_ALIAS("net-pf-" __stringify(PF_INET) "-proto-33-type-6"); |
820 | MODULE_ALIAS("net-pf-" __stringify(PF_INET) "-proto-0-type-6"); | 769 | MODULE_ALIAS("net-pf-" __stringify(PF_INET) "-proto-0-type-6"); |
821 | MODULE_LICENSE("GPL"); | 770 | MODULE_LICENSE("GPL"); |
822 | MODULE_AUTHOR("Arnaldo Carvalho de Melo <acme@conectiva.com.br>"); | 771 | MODULE_AUTHOR("Arnaldo Carvalho de Melo <acme@conectiva.com.br>"); |
823 | MODULE_DESCRIPTION("DCCP - Datagram Congestion Controlled Protocol"); | 772 | MODULE_DESCRIPTION("DCCP - Datagram Congestion Controlled Protocol"); |