Merge master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6

* master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6: (32 commits)
[NETPOLL]: Fix local_bh_enable() warning.
[IPVS]: Make ip_vs_sync.c <= 80col wide.
[IPVS]: Use msleep_interruptable() instead of ssleep() aka msleep()
[HAMRADIO]: Fix baycom_epp.c compile failure.
[DCCP]: Whitespace cleanups
[DCCP] ccid3: Fixup some type conversions related to rtts
[DCCP] ccid3: BUG-FIX - conversion errors
[DCCP] ccid3: Reorder packet history source file
[DCCP] ccid3: Reorder packet history header file
[DCCP] ccid3: Make debug output consistent
[DCCP] ccid3: Perform history operations only after packet has been sent
[DCCP] ccid3: TX history - remove unused field
[DCCP] ccid3: Shift window counter computation
[DCCP] ccid3: Sanity-check RTT samples
[DCCP] ccid3: Initialise RTT values
[DCCP] ccid: Deprecate ccid_hc_tx_insert_options
[DCCP]: Warn when discarding packet due to internal errors
[DCCP]: Only deliver to the CCID rx side in charge
[DCCP]: Simplify TFRC calculation
[DCCP]: Debug timeval operations
...

+664 -611
+2 -4
Documentation/networking/dccp.txt
··· 19 19 20 20 It has a base protocol and pluggable congestion control IDs (CCIDs). 21 21 22 - It is at experimental RFC status and the homepage for DCCP as a protocol is at: 22 + It is at proposed standard RFC status and the homepage for DCCP as a protocol 23 + is at: 23 24 http://www.read.cs.ucla.edu/dccp/ 24 25 25 26 Missing features ··· 34 33 35 34 Socket options 36 35 ============== 37 - 38 - DCCP_SOCKOPT_PACKET_SIZE is used for CCID3 to set default packet size for 39 - calculations. 40 36 41 37 DCCP_SOCKOPT_SERVICE sets the service. The specification mandates use of 42 38 service codes (RFC 4340, sec. 8.1.2); if this socket option is not set,
+1 -1
crypto/sha512.c
··· 24 24 25 25 #define SHA384_DIGEST_SIZE 48 26 26 #define SHA512_DIGEST_SIZE 64 27 - #define SHA384_HMAC_BLOCK_SIZE 96 27 + #define SHA384_HMAC_BLOCK_SIZE 128 28 28 #define SHA512_HMAC_BLOCK_SIZE 128 29 29 30 30 struct sha512_ctx {
+1 -1
drivers/atm/.gitignore
··· 2 2 fore200e_mkfirm 3 3 fore200e_pca_fw.c 4 4 pca200e.bin 5 - 5 + pca200e_ecd.bin2
+1 -1
drivers/net/hamradio/baycom_epp.c
··· 1177 1177 dev->mtu = AX25_DEF_PACLEN; /* eth_mtu is the default */ 1178 1178 dev->addr_len = AX25_ADDR_LEN; /* sizeof an ax.25 address */ 1179 1179 memcpy(dev->broadcast, &ax25_bcast, AX25_ADDR_LEN); 1180 - memcpy(dev->dev_addr, &ax25_nocall, AX25_ADDR_LEN); 1180 + memcpy(dev->dev_addr, &null_ax25_address, AX25_ADDR_LEN); 1181 1181 dev->tx_queue_len = 16; 1182 1182 1183 1183 /* New style flags */
+3 -2
drivers/net/wan/Kconfig
··· 382 382 383 383 # Wan router core. 384 384 config WAN_ROUTER_DRIVERS 385 - bool "WAN router drivers" 385 + tristate "WAN router drivers" 386 386 depends on WAN && WAN_ROUTER 387 387 ---help--- 388 388 Connect LAN to WAN via Linux box. ··· 393 393 <file:Documentation/networking/wan-router.txt>. 394 394 395 395 Note that the answer to this question won't directly affect the 396 - kernel: saying N will just cause the configurator to skip all 396 + kernel except for how subordinate drivers may be built: 397 + saying N will just cause the configurator to skip all 397 398 the questions about WAN router drivers. 398 399 399 400 If unsure, say N.
+13 -13
include/linux/dccp.h
··· 176 176 }; 177 177 178 178 /* DCCP features (RFC 4340 section 6.4) */ 179 - enum { 180 - DCCPF_RESERVED = 0, 181 - DCCPF_CCID = 1, 179 + enum { 180 + DCCPF_RESERVED = 0, 181 + DCCPF_CCID = 1, 182 182 DCCPF_SHORT_SEQNOS = 2, /* XXX: not yet implemented */ 183 - DCCPF_SEQUENCE_WINDOW = 3, 183 + DCCPF_SEQUENCE_WINDOW = 3, 184 184 DCCPF_ECN_INCAPABLE = 4, /* XXX: not yet implemented */ 185 - DCCPF_ACK_RATIO = 5, 186 - DCCPF_SEND_ACK_VECTOR = 6, 187 - DCCPF_SEND_NDP_COUNT = 7, 185 + DCCPF_ACK_RATIO = 5, 186 + DCCPF_SEND_ACK_VECTOR = 6, 187 + DCCPF_SEND_NDP_COUNT = 7, 188 188 DCCPF_MIN_CSUM_COVER = 8, 189 189 DCCPF_DATA_CHECKSUM = 9, /* XXX: not yet implemented */ 190 - /* 10-127 reserved */ 191 - DCCPF_MIN_CCID_SPECIFIC = 128, 192 - DCCPF_MAX_CCID_SPECIFIC = 255, 190 + /* 10-127 reserved */ 191 + DCCPF_MIN_CCID_SPECIFIC = 128, 192 + DCCPF_MAX_CCID_SPECIFIC = 255, 193 193 }; 194 194 195 195 /* this structure is argument to DCCP_SOCKOPT_CHANGE_X */ ··· 427 427 }; 428 428 429 429 #define DCCP_SERVICE_INVALID_VALUE htonl((__u32)-1) 430 - #define DCCP_SERVICE_CODE_IS_ABSENT 0 430 + #define DCCP_SERVICE_CODE_IS_ABSENT 0 431 431 432 432 static inline int dccp_list_has_service(const struct dccp_service_list *sl, 433 433 const __be32 service) ··· 436 436 u32 i = sl->dccpsl_nr; 437 437 while (i--) 438 438 if (sl->dccpsl_list[i] == service) 439 - return 1; 439 + return 1; 440 440 } 441 441 return 0; 442 442 } ··· 511 511 __u8 dccps_hc_tx_insert_options:1; 512 512 struct timer_list dccps_xmit_timer; 513 513 }; 514 - 514 + 515 515 static inline struct dccp_sock *dccp_sk(const struct sock *sk) 516 516 { 517 517 return (struct dccp_sock *)sk;
+6 -2
include/linux/tfrc.h
··· 37 37 * @tfrctx_p: current loss event rate (5.4) 38 38 * @tfrctx_rto: estimate of RTO, equals 4*RTT (4.3) 39 39 * @tfrctx_ipi: inter-packet interval (4.6) 40 + * 41 + * Note: X and X_recv are both maintained in units of 64 * bytes/second. This 42 + * enables a finer resolution of sending rates and avoids problems with 43 + * integer arithmetic; u32 is not sufficient as scaling consumes 6 bits. 40 44 */ 41 45 struct tfrc_tx_info { 42 - __u32 tfrctx_x; 43 - __u32 tfrctx_x_recv; 46 + __u64 tfrctx_x; 47 + __u64 tfrctx_x_recv; 44 48 __u32 tfrctx_x_calc; 45 49 __u32 tfrctx_rtt; 46 50 __u32 tfrctx_p;
+2
include/net/ax25.h
··· 285 285 extern const ax25_address ax25_bcast; 286 286 extern const ax25_address ax25_defaddr; 287 287 extern const ax25_address null_ax25_address; 288 + extern char *ax2asc(char *buf, const ax25_address *); 289 + extern void asc2ax(ax25_address *addr, const char *callsign); 288 290 extern int ax25cmp(const ax25_address *, const ax25_address *); 289 291 extern int ax25digicmp(const ax25_digi *, const ax25_digi *); 290 292 extern const unsigned char *ax25_addr_parse(const unsigned char *, int,
+1 -1
net/ax25/ax25_addr.c
··· 83 83 */ 84 84 void asc2ax(ax25_address *addr, const char *callsign) 85 85 { 86 - char *s; 86 + const char *s; 87 87 int n; 88 88 89 89 for (s = callsign, n = 0; n < 6; n++) {
+18 -12
net/core/netpoll.c
··· 242 242 243 243 /* don't get messages out of order, and no recursion */ 244 244 if (skb_queue_len(&npinfo->txq) == 0 && 245 - npinfo->poll_owner != smp_processor_id() && 246 - netif_tx_trylock(dev)) { 247 - /* try until next clock tick */ 248 - for (tries = jiffies_to_usecs(1)/USEC_PER_POLL; tries > 0; --tries) { 249 - if (!netif_queue_stopped(dev)) 250 - status = dev->hard_start_xmit(skb, dev); 245 + npinfo->poll_owner != smp_processor_id()) { 246 + unsigned long flags; 251 247 252 - if (status == NETDEV_TX_OK) 253 - break; 248 + local_irq_save(flags); 249 + if (netif_tx_trylock(dev)) { 250 + /* try until next clock tick */ 251 + for (tries = jiffies_to_usecs(1)/USEC_PER_POLL; 252 + tries > 0; --tries) { 253 + if (!netif_queue_stopped(dev)) 254 + status = dev->hard_start_xmit(skb, dev); 254 255 255 - /* tickle device maybe there is some cleanup */ 256 - netpoll_poll(np); 256 + if (status == NETDEV_TX_OK) 257 + break; 257 258 258 - udelay(USEC_PER_POLL); 259 + /* tickle device maybe there is some cleanup */ 260 + netpoll_poll(np); 261 + 262 + udelay(USEC_PER_POLL); 263 + } 264 + netif_tx_unlock(dev); 259 265 } 260 - netif_tx_unlock(dev); 266 + local_irq_restore(flags); 261 267 } 262 268 263 269 if (status != NETDEV_TX_OK) {
+2 -2
net/dccp/ackvec.c
··· 223 223 gap = -new_head; 224 224 } 225 225 new_head += DCCP_MAX_ACKVEC_LEN; 226 - } 226 + } 227 227 228 228 av->dccpav_buf_head = new_head; 229 229 ··· 336 336 void dccp_ackvector_print(const u64 ackno, const unsigned char *vector, int len) 337 337 { 338 338 dccp_pr_debug_cat("ACK vector len=%d, ackno=%llu |", len, 339 - (unsigned long long)ackno); 339 + (unsigned long long)ackno); 340 340 341 341 while (len--) { 342 342 const u8 state = (*vector & DCCP_ACKVEC_STATE_MASK) >> 6;
-10
net/dccp/ccid.h
··· 43 43 unsigned char* value); 44 44 int (*ccid_hc_rx_insert_options)(struct sock *sk, 45 45 struct sk_buff *skb); 46 - int (*ccid_hc_tx_insert_options)(struct sock *sk, 47 - struct sk_buff *skb); 48 46 void (*ccid_hc_tx_packet_recv)(struct sock *sk, 49 47 struct sk_buff *skb); 50 48 int (*ccid_hc_tx_parse_options)(struct sock *sk, ··· 142 144 if (ccid->ccid_ops->ccid_hc_rx_parse_options != NULL) 143 145 rc = ccid->ccid_ops->ccid_hc_rx_parse_options(sk, option, len, idx, value); 144 146 return rc; 145 - } 146 - 147 - static inline int ccid_hc_tx_insert_options(struct ccid *ccid, struct sock *sk, 148 - struct sk_buff *skb) 149 - { 150 - if (ccid->ccid_ops->ccid_hc_tx_insert_options != NULL) 151 - return ccid->ccid_ops->ccid_hc_tx_insert_options(sk, skb); 152 - return 0; 153 147 } 154 148 155 149 static inline int ccid_hc_rx_insert_options(struct ccid *ccid, struct sock *sk,
+6 -6
net/dccp/ccids/ccid2.c
··· 351 351 352 352 while (seqp != hctx->ccid2hctx_seqh) { 353 353 ccid2_pr_debug("out seq=%llu acked=%d time=%lu\n", 354 - (unsigned long long)seqp->ccid2s_seq, 354 + (unsigned long long)seqp->ccid2s_seq, 355 355 seqp->ccid2s_acked, seqp->ccid2s_sent); 356 356 seqp = seqp->ccid2s_next; 357 357 } ··· 473 473 /* first measurement */ 474 474 if (hctx->ccid2hctx_srtt == -1) { 475 475 ccid2_pr_debug("R: %lu Time=%lu seq=%llu\n", 476 - r, jiffies, 476 + r, jiffies, 477 477 (unsigned long long)seqp->ccid2s_seq); 478 478 ccid2_change_srtt(hctx, r); 479 479 hctx->ccid2hctx_rttvar = r >> 1; ··· 518 518 hctx->ccid2hctx_lastrtt = jiffies; 519 519 520 520 ccid2_pr_debug("srtt: %ld rttvar: %ld rto: %ld (HZ=%d) R=%lu\n", 521 - hctx->ccid2hctx_srtt, hctx->ccid2hctx_rttvar, 522 - hctx->ccid2hctx_rto, HZ, r); 521 + hctx->ccid2hctx_srtt, hctx->ccid2hctx_rttvar, 522 + hctx->ccid2hctx_rto, HZ, r); 523 523 hctx->ccid2hctx_sent = 0; 524 524 } 525 525 ··· 667 667 /* new packet received or marked */ 668 668 if (state != DCCP_ACKVEC_STATE_NOT_RECEIVED && 669 669 !seqp->ccid2s_acked) { 670 - if (state == 670 + if (state == 671 671 DCCP_ACKVEC_STATE_ECN_MARKED) { 672 - ccid2_congestion_event(hctx, 672 + ccid2_congestion_event(hctx, 673 673 seqp); 674 674 } else 675 675 ccid2_new_ack(sk, seqp,
+263 -248
net/dccp/ccids/ccid3.c
··· 41 41 #include "lib/tfrc.h" 42 42 #include "ccid3.h" 43 43 44 - /* 45 - * Reason for maths here is to avoid 32 bit overflow when a is big. 46 - * With this we get close to the limit. 47 - */ 48 - static u32 usecs_div(const u32 a, const u32 b) 49 - { 50 - const u32 div = a < (UINT_MAX / (USEC_PER_SEC / 10)) ? 10 : 51 - a < (UINT_MAX / (USEC_PER_SEC / 50)) ? 50 : 52 - a < (UINT_MAX / (USEC_PER_SEC / 100)) ? 100 : 53 - a < (UINT_MAX / (USEC_PER_SEC / 500)) ? 500 : 54 - a < (UINT_MAX / (USEC_PER_SEC / 1000)) ? 1000 : 55 - a < (UINT_MAX / (USEC_PER_SEC / 5000)) ? 5000 : 56 - a < (UINT_MAX / (USEC_PER_SEC / 10000)) ? 10000 : 57 - a < (UINT_MAX / (USEC_PER_SEC / 50000)) ? 50000 : 58 - 100000; 59 - const u32 tmp = a * (USEC_PER_SEC / div); 60 - return (b >= 2 * div) ? tmp / (b / div) : tmp; 61 - } 62 - 63 - 64 - 65 44 #ifdef CONFIG_IP_DCCP_CCID3_DEBUG 66 45 static int ccid3_debug; 67 46 #define ccid3_pr_debug(format, a...) DCCP_PR_DEBUG(ccid3_debug, format, ##a) ··· 87 108 { 88 109 timeval_sub_usecs(&hctx->ccid3hctx_t_nom, hctx->ccid3hctx_t_ipi); 89 110 90 - /* Calculate new t_ipi (inter packet interval) by t_ipi = s / X_inst */ 91 - hctx->ccid3hctx_t_ipi = usecs_div(hctx->ccid3hctx_s, hctx->ccid3hctx_x); 111 + /* Calculate new t_ipi = s / X_inst (X_inst is in 64 * bytes/second) */ 112 + hctx->ccid3hctx_t_ipi = scaled_div(hctx->ccid3hctx_s, 113 + hctx->ccid3hctx_x >> 6); 92 114 93 115 /* Update nominal send time with regard to the new t_ipi */ 94 116 timeval_add_usecs(&hctx->ccid3hctx_t_nom, hctx->ccid3hctx_t_ipi); ··· 108 128 * X = max(min(2 * X, 2 * X_recv), s / R); 109 129 * tld = now; 110 130 * 131 + * Note: X and X_recv are both stored in units of 64 * bytes/second, to support 132 + * fine-grained resolution of sending rates. This requires scaling by 2^6 133 + * throughout the code. Only X_calc is unscaled (in bytes/second). 134 + * 111 135 * If X has changed, we also update the scheduled send time t_now, 112 136 * the inter-packet interval t_ipi, and the delta value. 113 - */ 137 + */ 114 138 static void ccid3_hc_tx_update_x(struct sock *sk, struct timeval *now) 115 139 116 140 { 117 141 struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); 118 - const __u32 old_x = hctx->ccid3hctx_x; 142 + const __u64 old_x = hctx->ccid3hctx_x; 119 143 120 144 if (hctx->ccid3hctx_p > 0) { 121 - hctx->ccid3hctx_x_calc = tfrc_calc_x(hctx->ccid3hctx_s, 122 - hctx->ccid3hctx_rtt, 123 - hctx->ccid3hctx_p); 124 - hctx->ccid3hctx_x = max_t(u32, min(hctx->ccid3hctx_x_calc, 125 - hctx->ccid3hctx_x_recv * 2), 126 - hctx->ccid3hctx_s / TFRC_T_MBI); 127 145 128 - } else if (timeval_delta(now, &hctx->ccid3hctx_t_ld) >= 129 - hctx->ccid3hctx_rtt) { 130 - hctx->ccid3hctx_x = max(min(hctx->ccid3hctx_x_recv, 131 - hctx->ccid3hctx_x ) * 2, 132 - usecs_div(hctx->ccid3hctx_s, 133 - hctx->ccid3hctx_rtt) ); 146 + hctx->ccid3hctx_x = min(((__u64)hctx->ccid3hctx_x_calc) << 6, 147 + hctx->ccid3hctx_x_recv * 2); 148 + hctx->ccid3hctx_x = max(hctx->ccid3hctx_x, 149 + (((__u64)hctx->ccid3hctx_s) << 6) / 150 + TFRC_T_MBI); 151 + 152 + } else if (timeval_delta(now, &hctx->ccid3hctx_t_ld) - 153 + (suseconds_t)hctx->ccid3hctx_rtt >= 0) { 154 + 155 + hctx->ccid3hctx_x = 156 + max(2 * min(hctx->ccid3hctx_x, hctx->ccid3hctx_x_recv), 157 + scaled_div(((__u64)hctx->ccid3hctx_s) << 6, 158 + hctx->ccid3hctx_rtt)); 134 159 hctx->ccid3hctx_t_ld = *now; 135 - } else 136 - ccid3_pr_debug("Not changing X\n"); 160 + } 137 161 138 162 if (hctx->ccid3hctx_x != old_x) 139 163 ccid3_update_send_time(hctx); 140 164 } 141 165 142 166 /* 143 - * Track the mean packet size `s' (cf. RFC 4342, 5.3 and RFC 3448, 4.1) 144 - * @len: DCCP packet payload size in bytes 167 + * Track the mean packet size `s' (cf. RFC 4342, 5.3 and RFC 3448, 4.1) 168 + * @len: DCCP packet payload size in bytes 145 169 */ 146 170 static inline void ccid3_hc_tx_update_s(struct ccid3_hc_tx_sock *hctx, int len) 147 171 { ··· 162 178 */ 163 179 } 164 180 181 + /* 182 + * Update Window Counter using the algorithm from [RFC 4342, 8.1]. 183 + * The algorithm is not applicable if RTT < 4 microseconds. 184 + */ 185 + static inline void ccid3_hc_tx_update_win_count(struct ccid3_hc_tx_sock *hctx, 186 + struct timeval *now) 187 + { 188 + suseconds_t delta; 189 + u32 quarter_rtts; 190 + 191 + if (unlikely(hctx->ccid3hctx_rtt < 4)) /* avoid divide-by-zero */ 192 + return; 193 + 194 + delta = timeval_delta(now, &hctx->ccid3hctx_t_last_win_count); 195 + DCCP_BUG_ON(delta < 0); 196 + 197 + quarter_rtts = (u32)delta / (hctx->ccid3hctx_rtt / 4); 198 + 199 + if (quarter_rtts > 0) { 200 + hctx->ccid3hctx_t_last_win_count = *now; 201 + hctx->ccid3hctx_last_win_count += min_t(u32, quarter_rtts, 5); 202 + hctx->ccid3hctx_last_win_count &= 0xF; /* mod 16 */ 203 + 204 + ccid3_pr_debug("now at %#X\n", hctx->ccid3hctx_last_win_count); 205 + } 206 + } 207 + 165 208 static void ccid3_hc_tx_no_feedback_timer(unsigned long data) 166 209 { 167 210 struct sock *sk = (struct sock *)data; ··· 202 191 goto restart_timer; 203 192 } 204 193 205 - ccid3_pr_debug("%s, sk=%p, state=%s\n", dccp_role(sk), sk, 194 + ccid3_pr_debug("%s(%p, state=%s) - entry \n", dccp_role(sk), sk, 206 195 ccid3_tx_state_name(hctx->ccid3hctx_state)); 207 - 196 + 208 197 switch (hctx->ccid3hctx_state) { 209 198 case TFRC_SSTATE_NO_FBACK: 210 199 /* RFC 3448, 4.4: Halve send rate directly */ 211 - hctx->ccid3hctx_x = min_t(u32, hctx->ccid3hctx_x / 2, 212 - hctx->ccid3hctx_s / TFRC_T_MBI); 200 + hctx->ccid3hctx_x = max(hctx->ccid3hctx_x / 2, 201 + (((__u64)hctx->ccid3hctx_s) << 6) / 202 + TFRC_T_MBI); 213 203 214 - ccid3_pr_debug("%s, sk=%p, state=%s, updated tx rate to %d " 215 - "bytes/s\n", 216 - dccp_role(sk), sk, 204 + ccid3_pr_debug("%s(%p, state=%s), updated tx rate to %u " 205 + "bytes/s\n", dccp_role(sk), sk, 217 206 ccid3_tx_state_name(hctx->ccid3hctx_state), 218 - hctx->ccid3hctx_x); 207 + (unsigned)(hctx->ccid3hctx_x >> 6)); 219 208 /* The value of R is still undefined and so we can not recompute 220 209 * the timout value. Keep initial value as per [RFC 4342, 5]. */ 221 210 t_nfb = TFRC_INITIAL_TIMEOUT; ··· 224 213 case TFRC_SSTATE_FBACK: 225 214 /* 226 215 * Check if IDLE since last timeout and recv rate is less than 227 - * 4 packets per RTT 216 + * 4 packets (in units of 64*bytes/sec) per RTT 228 217 */ 229 218 if (!hctx->ccid3hctx_idle || 230 - (hctx->ccid3hctx_x_recv >= 231 - 4 * usecs_div(hctx->ccid3hctx_s, hctx->ccid3hctx_rtt))) { 219 + (hctx->ccid3hctx_x_recv >= 4 * 220 + scaled_div(((__u64)hctx->ccid3hctx_s) << 6, 221 + hctx->ccid3hctx_rtt))) { 232 222 struct timeval now; 233 223 234 - ccid3_pr_debug("%s, sk=%p, state=%s, not idle\n", 224 + ccid3_pr_debug("%s(%p, state=%s), not idle\n", 235 225 dccp_role(sk), sk, 236 - ccid3_tx_state_name(hctx->ccid3hctx_state)); 237 - /* Halve sending rate */ 226 + ccid3_tx_state_name(hctx->ccid3hctx_state)); 238 227 239 - /* If (p == 0 || X_calc > 2 * X_recv) 228 + /* 229 + * Modify the cached value of X_recv [RFC 3448, 4.4] 230 + * 231 + * If (p == 0 || X_calc > 2 * X_recv) 240 232 * X_recv = max(X_recv / 2, s / (2 * t_mbi)); 241 233 * Else 242 234 * X_recv = X_calc / 4; 235 + * 236 + * Note that X_recv is scaled by 2^6 while X_calc is not 243 237 */ 244 238 BUG_ON(hctx->ccid3hctx_p && !hctx->ccid3hctx_x_calc); 245 239 246 240 if (hctx->ccid3hctx_p == 0 || 247 - hctx->ccid3hctx_x_calc > 2 * hctx->ccid3hctx_x_recv) 248 - hctx->ccid3hctx_x_recv = max_t(u32, hctx->ccid3hctx_x_recv / 2, 249 - hctx->ccid3hctx_s / (2 * TFRC_T_MBI)); 250 - else 251 - hctx->ccid3hctx_x_recv = hctx->ccid3hctx_x_calc / 4; 241 + (hctx->ccid3hctx_x_calc > 242 + (hctx->ccid3hctx_x_recv >> 5))) { 252 243 253 - /* Update sending rate */ 254 - dccp_timestamp(sk, &now); 244 + hctx->ccid3hctx_x_recv = 245 + max(hctx->ccid3hctx_x_recv / 2, 246 + (((__u64)hctx->ccid3hctx_s) << 6) / 247 + (2 * TFRC_T_MBI)); 248 + 249 + if (hctx->ccid3hctx_p == 0) 250 + dccp_timestamp(sk, &now); 251 + } else { 252 + hctx->ccid3hctx_x_recv = hctx->ccid3hctx_x_calc; 253 + hctx->ccid3hctx_x_recv <<= 4; 254 + } 255 + /* Now recalculate X [RFC 3448, 4.3, step (4)] */ 255 256 ccid3_hc_tx_update_x(sk, &now); 256 257 } 257 258 /* ··· 274 251 t_nfb = max(hctx->ccid3hctx_t_rto, 2 * hctx->ccid3hctx_t_ipi); 275 252 break; 276 253 case TFRC_SSTATE_NO_SENT: 277 - DCCP_BUG("Illegal %s state NO_SENT, sk=%p", dccp_role(sk), sk); 254 + DCCP_BUG("%s(%p) - Illegal state NO_SENT", dccp_role(sk), sk); 278 255 /* fall through */ 279 256 case TFRC_SSTATE_TERM: 280 257 goto out; ··· 300 277 { 301 278 struct dccp_sock *dp = dccp_sk(sk); 302 279 struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); 303 - struct dccp_tx_hist_entry *new_packet; 304 280 struct timeval now; 305 - long delay; 281 + suseconds_t delay; 306 282 307 283 BUG_ON(hctx == NULL); 308 284 ··· 313 291 if (unlikely(skb->len == 0)) 314 292 return -EBADMSG; 315 293 316 - /* See if last packet allocated was not sent */ 317 - new_packet = dccp_tx_hist_head(&hctx->ccid3hctx_hist); 318 - if (new_packet == NULL || new_packet->dccphtx_sent) { 319 - new_packet = dccp_tx_hist_entry_new(ccid3_tx_hist, 320 - GFP_ATOMIC); 321 - 322 - if (unlikely(new_packet == NULL)) { 323 - DCCP_WARN("%s, sk=%p, not enough mem to add to history," 324 - "send refused\n", dccp_role(sk), sk); 325 - return -ENOBUFS; 326 - } 327 - 328 - dccp_tx_hist_add_entry(&hctx->ccid3hctx_hist, new_packet); 329 - } 330 - 331 294 dccp_timestamp(sk, &now); 332 295 333 296 switch (hctx->ccid3hctx_state) { 334 297 case TFRC_SSTATE_NO_SENT: 335 298 sk_reset_timer(sk, &hctx->ccid3hctx_no_feedback_timer, 336 - jiffies + usecs_to_jiffies(TFRC_INITIAL_TIMEOUT)); 299 + (jiffies + 300 + usecs_to_jiffies(TFRC_INITIAL_TIMEOUT))); 337 301 hctx->ccid3hctx_last_win_count = 0; 338 302 hctx->ccid3hctx_t_last_win_count = now; 339 303 ccid3_hc_tx_set_state(sk, TFRC_SSTATE_NO_FBACK); 340 304 341 - /* Set initial sending rate to 1 packet per second */ 305 + /* Set initial sending rate X/s to 1pps (X is scaled by 2^6) */ 342 306 ccid3_hc_tx_update_s(hctx, skb->len); 343 - hctx->ccid3hctx_x = hctx->ccid3hctx_s; 307 + hctx->ccid3hctx_x = hctx->ccid3hctx_s; 308 + hctx->ccid3hctx_x <<= 6; 344 309 345 310 /* First timeout, according to [RFC 3448, 4.2], is 1 second */ 346 311 hctx->ccid3hctx_t_ipi = USEC_PER_SEC; ··· 341 332 case TFRC_SSTATE_FBACK: 342 333 delay = timeval_delta(&hctx->ccid3hctx_t_nom, &now); 343 334 /* 344 - * Scheduling of packet transmissions [RFC 3448, 4.6] 335 + * Scheduling of packet transmissions [RFC 3448, 4.6] 345 336 * 346 337 * if (t_now > t_nom - delta) 347 338 * // send the packet now 348 339 * else 349 340 * // send the packet in (t_nom - t_now) milliseconds. 350 341 */ 351 - if (delay - (long)hctx->ccid3hctx_delta >= 0) 342 + if (delay - (suseconds_t)hctx->ccid3hctx_delta >= 0) 352 343 return delay / 1000L; 344 + 345 + ccid3_hc_tx_update_win_count(hctx, &now); 353 346 break; 354 347 case TFRC_SSTATE_TERM: 355 - DCCP_BUG("Illegal %s state TERM, sk=%p", dccp_role(sk), sk); 348 + DCCP_BUG("%s(%p) - Illegal state TERM", dccp_role(sk), sk); 356 349 return -EINVAL; 357 350 } 358 351 359 352 /* prepare to send now (add options etc.) */ 360 353 dp->dccps_hc_tx_insert_options = 1; 361 - new_packet->dccphtx_ccval = DCCP_SKB_CB(skb)->dccpd_ccval = 362 - hctx->ccid3hctx_last_win_count; 354 + DCCP_SKB_CB(skb)->dccpd_ccval = hctx->ccid3hctx_last_win_count; 355 + 356 + /* set the nominal send time for the next following packet */ 363 357 timeval_add_usecs(&hctx->ccid3hctx_t_nom, hctx->ccid3hctx_t_ipi); 364 358 365 359 return 0; 366 360 } 367 361 368 - static void ccid3_hc_tx_packet_sent(struct sock *sk, int more, unsigned int len) 362 + static void ccid3_hc_tx_packet_sent(struct sock *sk, int more, 363 + unsigned int len) 369 364 { 370 - const struct dccp_sock *dp = dccp_sk(sk); 371 365 struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); 372 366 struct timeval now; 373 - unsigned long quarter_rtt; 374 367 struct dccp_tx_hist_entry *packet; 375 368 376 369 BUG_ON(hctx == NULL); 377 370 378 - dccp_timestamp(sk, &now); 379 - 380 371 ccid3_hc_tx_update_s(hctx, len); 381 372 382 - packet = dccp_tx_hist_head(&hctx->ccid3hctx_hist); 373 + packet = dccp_tx_hist_entry_new(ccid3_tx_hist, GFP_ATOMIC); 383 374 if (unlikely(packet == NULL)) { 384 - DCCP_WARN("packet doesn't exist in history!\n"); 375 + DCCP_CRIT("packet history - out of memory!"); 385 376 return; 386 377 } 387 - if (unlikely(packet->dccphtx_sent)) { 388 - DCCP_WARN("no unsent packet in history!\n"); 389 - return; 390 - } 378 + dccp_tx_hist_add_entry(&hctx->ccid3hctx_hist, packet); 379 + 380 + dccp_timestamp(sk, &now); 391 381 packet->dccphtx_tstamp = now; 392 - packet->dccphtx_seqno = dp->dccps_gss; 393 - /* 394 - * Check if win_count have changed 395 - * Algorithm in "8.1. Window Counter Value" in RFC 4342. 396 - */ 397 - quarter_rtt = timeval_delta(&now, &hctx->ccid3hctx_t_last_win_count); 398 - if (likely(hctx->ccid3hctx_rtt > 8)) 399 - quarter_rtt /= hctx->ccid3hctx_rtt / 4; 400 - 401 - if (quarter_rtt > 0) { 402 - hctx->ccid3hctx_t_last_win_count = now; 403 - hctx->ccid3hctx_last_win_count = (hctx->ccid3hctx_last_win_count + 404 - min_t(unsigned long, quarter_rtt, 5)) % 16; 405 - ccid3_pr_debug("%s, sk=%p, window changed from " 406 - "%u to %u!\n", 407 - dccp_role(sk), sk, 408 - packet->dccphtx_ccval, 409 - hctx->ccid3hctx_last_win_count); 410 - } 411 - 412 - hctx->ccid3hctx_idle = 0; 413 - packet->dccphtx_rtt = hctx->ccid3hctx_rtt; 414 - packet->dccphtx_sent = 1; 382 + packet->dccphtx_seqno = dccp_sk(sk)->dccps_gss; 383 + packet->dccphtx_rtt = hctx->ccid3hctx_rtt; 384 + packet->dccphtx_sent = 1; 385 + hctx->ccid3hctx_idle = 0; 415 386 } 416 387 417 388 static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb) ··· 403 414 struct timeval now; 404 415 unsigned long t_nfb; 405 416 u32 pinv; 406 - long r_sample, t_elapsed; 417 + suseconds_t r_sample, t_elapsed; 407 418 408 419 BUG_ON(hctx == NULL); 409 420 ··· 419 430 case TFRC_SSTATE_FBACK: 420 431 /* get packet from history to look up t_recvdata */ 421 432 packet = dccp_tx_hist_find_entry(&hctx->ccid3hctx_hist, 422 - DCCP_SKB_CB(skb)->dccpd_ack_seq); 433 + DCCP_SKB_CB(skb)->dccpd_ack_seq); 423 434 if (unlikely(packet == NULL)) { 424 435 DCCP_WARN("%s(%p), seqno %llu(%s) doesn't exist " 425 436 "in history!\n", dccp_role(sk), sk, 426 437 (unsigned long long)DCCP_SKB_CB(skb)->dccpd_ack_seq, 427 - dccp_packet_name(DCCP_SKB_CB(skb)->dccpd_type)); 438 + dccp_packet_name(DCCP_SKB_CB(skb)->dccpd_type)); 428 439 return; 429 440 } 430 441 431 - /* Update receive rate */ 442 + /* Update receive rate in units of 64 * bytes/second */ 432 443 hctx->ccid3hctx_x_recv = opt_recv->ccid3or_receive_rate; 444 + hctx->ccid3hctx_x_recv <<= 6; 433 445 434 446 /* Update loss event rate */ 435 447 pinv = opt_recv->ccid3or_loss_event_rate; 436 - if (pinv == ~0U || pinv == 0) 448 + if (pinv == ~0U || pinv == 0) /* see RFC 4342, 8.5 */ 437 449 hctx->ccid3hctx_p = 0; 438 - else 439 - hctx->ccid3hctx_p = 1000000 / pinv; 450 + else /* can not exceed 100% */ 451 + hctx->ccid3hctx_p = 1000000 / pinv; 440 452 441 453 dccp_timestamp(sk, &now); 442 454 443 455 /* 444 456 * Calculate new round trip sample as per [RFC 3448, 4.3] by 445 - * R_sample = (now - t_recvdata) - t_elapsed 457 + * R_sample = (now - t_recvdata) - t_elapsed 446 458 */ 447 459 r_sample = timeval_delta(&now, &packet->dccphtx_tstamp); 448 460 t_elapsed = dp->dccps_options_received.dccpor_elapsed_time * 10; 449 461 450 - if (unlikely(r_sample <= 0)) { 451 - DCCP_WARN("WARNING: R_sample (%ld) <= 0!\n", r_sample); 452 - r_sample = 0; 453 - } else if (unlikely(r_sample <= t_elapsed)) 454 - DCCP_WARN("WARNING: r_sample=%ldus <= t_elapsed=%ldus\n", 455 - r_sample, t_elapsed); 462 + DCCP_BUG_ON(r_sample < 0); 463 + if (unlikely(r_sample <= t_elapsed)) 464 + DCCP_WARN("WARNING: r_sample=%dus <= t_elapsed=%dus\n", 465 + (int)r_sample, (int)t_elapsed); 456 466 else 457 467 r_sample -= t_elapsed; 468 + CCID3_RTT_SANITY_CHECK(r_sample); 458 469 459 - /* Update RTT estimate by 470 + /* Update RTT estimate by 460 471 * If (No feedback recv) 461 472 * R = R_sample; 462 473 * Else ··· 465 476 * q is a constant, RFC 3448 recomments 0.9 466 477 */ 467 478 if (hctx->ccid3hctx_state == TFRC_SSTATE_NO_FBACK) { 468 - /* Use Larger Initial Windows [RFC 4342, sec. 5] 469 - * We deviate in that we use `s' instead of `MSS'. */ 470 - u16 w_init = max( 4 * hctx->ccid3hctx_s, 471 - max(2 * hctx->ccid3hctx_s, 4380)); 479 + /* 480 + * Larger Initial Windows [RFC 4342, sec. 5] 481 + * We deviate in that we use `s' instead of `MSS'. 482 + */ 483 + __u64 w_init = min(4 * hctx->ccid3hctx_s, 484 + max(2 * hctx->ccid3hctx_s, 4380)); 472 485 hctx->ccid3hctx_rtt = r_sample; 473 - hctx->ccid3hctx_x = usecs_div(w_init, r_sample); 486 + hctx->ccid3hctx_x = scaled_div(w_init << 6, r_sample); 474 487 hctx->ccid3hctx_t_ld = now; 475 488 476 489 ccid3_update_send_time(hctx); 477 490 478 - ccid3_pr_debug("%s(%p), s=%u, w_init=%u, " 479 - "R_sample=%ldus, X=%u\n", dccp_role(sk), 480 - sk, hctx->ccid3hctx_s, w_init, r_sample, 481 - hctx->ccid3hctx_x); 491 + ccid3_pr_debug("%s(%p), s=%u, w_init=%llu, " 492 + "R_sample=%dus, X=%u\n", dccp_role(sk), 493 + sk, hctx->ccid3hctx_s, w_init, 494 + (int)r_sample, 495 + (unsigned)(hctx->ccid3hctx_x >> 6)); 482 496 483 497 ccid3_hc_tx_set_state(sk, TFRC_SSTATE_FBACK); 484 498 } else { 485 499 hctx->ccid3hctx_rtt = (9 * hctx->ccid3hctx_rtt + 486 - (u32)r_sample ) / 10; 500 + (u32)r_sample) / 10; 487 501 502 + /* Update sending rate (step 4 of [RFC 3448, 4.3]) */ 503 + if (hctx->ccid3hctx_p > 0) 504 + hctx->ccid3hctx_x_calc = 505 + tfrc_calc_x(hctx->ccid3hctx_s, 506 + hctx->ccid3hctx_rtt, 507 + hctx->ccid3hctx_p); 488 508 ccid3_hc_tx_update_x(sk, &now); 489 509 490 - ccid3_pr_debug("%s(%p), RTT=%uus (sample=%ldus), s=%u, " 491 - "p=%u, X_calc=%u, X=%u\n", dccp_role(sk), 492 - sk, hctx->ccid3hctx_rtt, r_sample, 510 + ccid3_pr_debug("%s(%p), RTT=%uus (sample=%dus), s=%u, " 511 + "p=%u, X_calc=%u, X_recv=%u, X=%u\n", 512 + dccp_role(sk), 513 + sk, hctx->ccid3hctx_rtt, (int)r_sample, 493 514 hctx->ccid3hctx_s, hctx->ccid3hctx_p, 494 515 hctx->ccid3hctx_x_calc, 495 - hctx->ccid3hctx_x); 516 + (unsigned)(hctx->ccid3hctx_x_recv >> 6), 517 + (unsigned)(hctx->ccid3hctx_x >> 6)); 496 518 } 497 519 498 520 /* unschedule no feedback timer */ ··· 513 513 dccp_tx_hist_purge_older(ccid3_tx_hist, 514 514 &hctx->ccid3hctx_hist, packet); 515 515 /* 516 - * As we have calculated new ipi, delta, t_nom it is possible that 517 - * we now can send a packet, so wake up dccp_wait_for_ccid 516 + * As we have calculated new ipi, delta, t_nom it is possible 517 + * that we now can send a packet, so wake up dccp_wait_for_ccid 518 518 */ 519 519 sk->sk_write_space(sk); 520 520 521 521 /* 522 522 * Update timeout interval for the nofeedback timer. 523 523 * We use a configuration option to increase the lower bound. 524 - * This can help avoid triggering the nofeedback timer too often 525 - * ('spinning') on LANs with small RTTs. 524 + * This can help avoid triggering the nofeedback timer too 525 + * often ('spinning') on LANs with small RTTs. 526 526 */ 527 527 hctx->ccid3hctx_t_rto = max_t(u32, 4 * hctx->ccid3hctx_rtt, 528 528 CONFIG_IP_DCCP_CCID3_RTO * 529 - (USEC_PER_SEC/1000) ); 529 + (USEC_PER_SEC/1000)); 530 530 /* 531 531 * Schedule no feedback timer to expire in 532 532 * max(t_RTO, 2 * s/X) = max(t_RTO, 2 * t_ipi) 533 533 */ 534 534 t_nfb = max(hctx->ccid3hctx_t_rto, 2 * hctx->ccid3hctx_t_ipi); 535 - 536 - ccid3_pr_debug("%s, sk=%p, Scheduled no feedback timer to " 537 - "expire in %lu jiffies (%luus)\n", 538 - dccp_role(sk), sk, 539 - usecs_to_jiffies(t_nfb), t_nfb); 540 535 541 - sk_reset_timer(sk, &hctx->ccid3hctx_no_feedback_timer, 536 + ccid3_pr_debug("%s(%p), Scheduled no feedback timer to " 537 + "expire in %lu jiffies (%luus)\n", 538 + dccp_role(sk), 539 + sk, usecs_to_jiffies(t_nfb), t_nfb); 540 + 541 + sk_reset_timer(sk, &hctx->ccid3hctx_no_feedback_timer, 542 542 jiffies + usecs_to_jiffies(t_nfb)); 543 543 544 544 /* set idle flag */ 545 - hctx->ccid3hctx_idle = 1; 545 + hctx->ccid3hctx_idle = 1; 546 546 break; 547 547 case TFRC_SSTATE_NO_SENT: 548 - if (dccp_sk(sk)->dccps_role == DCCP_ROLE_CLIENT) 549 - DCCP_WARN("Illegal ACK received - no packet sent\n"); 548 + /* 549 + * XXX when implementing bidirectional rx/tx check this again 550 + */ 551 + DCCP_WARN("Illegal ACK received - no packet sent\n"); 550 552 /* fall through */ 551 553 case TFRC_SSTATE_TERM: /* ignore feedback when closing */ 552 554 break; 553 555 } 554 - } 555 - 556 - static int ccid3_hc_tx_insert_options(struct sock *sk, struct sk_buff *skb) 557 - { 558 - const struct ccid3_hc_tx_sock *hctx = ccid3_hc_tx_sk(sk); 559 - 560 - BUG_ON(hctx == NULL); 561 - 562 - if (sk->sk_state == DCCP_OPEN || sk->sk_state == DCCP_PARTOPEN) 563 - DCCP_SKB_CB(skb)->dccpd_ccval = hctx->ccid3hctx_last_win_count; 564 - return 0; 565 556 } 566 557 567 558 static int ccid3_hc_tx_parse_options(struct sock *sk, unsigned char option, ··· 579 588 switch (option) { 580 589 case TFRC_OPT_LOSS_EVENT_RATE: 581 590 if (unlikely(len != 4)) { 582 - DCCP_WARN("%s, sk=%p, invalid len %d " 591 + DCCP_WARN("%s(%p), invalid len %d " 583 592 "for TFRC_OPT_LOSS_EVENT_RATE\n", 584 593 dccp_role(sk), sk, len); 585 594 rc = -EINVAL; 586 595 } else { 587 - opt_recv->ccid3or_loss_event_rate = ntohl(*(__be32 *)value); 588 - ccid3_pr_debug("%s, sk=%p, LOSS_EVENT_RATE=%u\n", 596 + opt_recv->ccid3or_loss_event_rate = 597 + ntohl(*(__be32 *)value); 598 + ccid3_pr_debug("%s(%p), LOSS_EVENT_RATE=%u\n", 589 599 dccp_role(sk), sk, 590 600 opt_recv->ccid3or_loss_event_rate); 591 601 } ··· 594 602 case TFRC_OPT_LOSS_INTERVALS: 595 603 opt_recv->ccid3or_loss_intervals_idx = idx; 596 604 opt_recv->ccid3or_loss_intervals_len = len; 597 - ccid3_pr_debug("%s, sk=%p, LOSS_INTERVALS=(%u, %u)\n", 605 + ccid3_pr_debug("%s(%p), LOSS_INTERVALS=(%u, %u)\n", 598 606 dccp_role(sk), sk, 599 607 opt_recv->ccid3or_loss_intervals_idx, 600 608 opt_recv->ccid3or_loss_intervals_len); 601 609 break; 602 610 case TFRC_OPT_RECEIVE_RATE: 603 611 if (unlikely(len != 4)) { 604 - DCCP_WARN("%s, sk=%p, invalid len %d " 612 + DCCP_WARN("%s(%p), invalid len %d " 605 613 "for TFRC_OPT_RECEIVE_RATE\n", 606 614 dccp_role(sk), sk, len); 607 615 rc = -EINVAL; 608 616 } else { 609 - opt_recv->ccid3or_receive_rate = ntohl(*(__be32 *)value); 610 - ccid3_pr_debug("%s, sk=%p, RECEIVE_RATE=%u\n", 617 + opt_recv->ccid3or_receive_rate = 618 + ntohl(*(__be32 *)value); 619 + ccid3_pr_debug("%s(%p), RECEIVE_RATE=%u\n", 611 620 dccp_role(sk), sk, 612 621 opt_recv->ccid3or_receive_rate); 613 622 } ··· 623 630 struct ccid3_hc_tx_sock *hctx = ccid_priv(ccid); 624 631 625 632 hctx->ccid3hctx_s = 0; 633 + hctx->ccid3hctx_rtt = 0; 626 634 hctx->ccid3hctx_state = TFRC_SSTATE_NO_SENT; 627 635 INIT_LIST_HEAD(&hctx->ccid3hctx_hist); 628 636 629 - hctx->ccid3hctx_no_feedback_timer.function = ccid3_hc_tx_no_feedback_timer; 637 + hctx->ccid3hctx_no_feedback_timer.function = 638 + ccid3_hc_tx_no_feedback_timer; 630 639 hctx->ccid3hctx_no_feedback_timer.data = (unsigned long)sk; 631 640 init_timer(&hctx->ccid3hctx_no_feedback_timer); 632 641 ··· 693 698 struct dccp_sock *dp = dccp_sk(sk); 694 699 struct dccp_rx_hist_entry *packet; 695 700 struct timeval now; 701 + suseconds_t delta; 696 702 697 - ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk); 703 + ccid3_pr_debug("%s(%p) - entry \n", dccp_role(sk), sk); 698 704 699 705 dccp_timestamp(sk, &now); 700 706 ··· 703 707 case TFRC_RSTATE_NO_DATA: 704 708 hcrx->ccid3hcrx_x_recv = 0; 705 709 break; 706 - case TFRC_RSTATE_DATA: { 707 - const u32 delta = timeval_delta(&now, 708 - &hcrx->ccid3hcrx_tstamp_last_feedback); 709 - hcrx->ccid3hcrx_x_recv = usecs_div(hcrx->ccid3hcrx_bytes_recv, 710 - delta); 711 - } 710 + case TFRC_RSTATE_DATA: 711 + delta = timeval_delta(&now, 712 + &hcrx->ccid3hcrx_tstamp_last_feedback); 713 + DCCP_BUG_ON(delta < 0); 714 + hcrx->ccid3hcrx_x_recv = 715 + scaled_div32(hcrx->ccid3hcrx_bytes_recv, delta); 712 716 break; 713 717 case TFRC_RSTATE_TERM: 714 - DCCP_BUG("Illegal %s state TERM, sk=%p", dccp_role(sk), sk); 718 + DCCP_BUG("%s(%p) - Illegal state TERM", dccp_role(sk), sk); 715 719 return; 716 720 } 717 721 718 722 packet = dccp_rx_hist_find_data_packet(&hcrx->ccid3hcrx_hist); 719 723 if (unlikely(packet == NULL)) { 720 - DCCP_WARN("%s, sk=%p, no data packet in history!\n", 724 + DCCP_WARN("%s(%p), no data packet in history!\n", 721 725 dccp_role(sk), sk); 722 726 return; 723 727 } ··· 726 730 hcrx->ccid3hcrx_ccval_last_counter = packet->dccphrx_ccval; 727 731 hcrx->ccid3hcrx_bytes_recv = 0; 728 732 729 - /* Convert to multiples of 10us */ 730 - hcrx->ccid3hcrx_elapsed_time = 731 - timeval_delta(&now, &packet->dccphrx_tstamp) / 10; 733 + /* Elapsed time information [RFC 4340, 13.2] in units of 10 * usecs */ 734 + delta = timeval_delta(&now, &packet->dccphrx_tstamp); 735 + DCCP_BUG_ON(delta < 0); 736 + hcrx->ccid3hcrx_elapsed_time = delta / 10; 737 + 732 738 if (hcrx->ccid3hcrx_p == 0) 733 - hcrx->ccid3hcrx_pinv = ~0; 734 - else 739 + hcrx->ccid3hcrx_pinv = ~0U; /* see RFC 4342, 8.5 */ 740 + else if (hcrx->ccid3hcrx_p > 1000000) { 741 + DCCP_WARN("p (%u) > 100%%\n", hcrx->ccid3hcrx_p); 742 + hcrx->ccid3hcrx_pinv = 1; /* use 100% in this case */ 743 + } else 735 744 hcrx->ccid3hcrx_pinv = 1000000 / hcrx->ccid3hcrx_p; 745 + 736 746 dp->dccps_hc_rx_insert_options = 1; 737 747 dccp_send_ack(sk); 738 748 } ··· 766 764 hcrx->ccid3hcrx_elapsed_time)) || 767 765 dccp_insert_option_timestamp(sk, skb) || 768 766 dccp_insert_option(sk, skb, TFRC_OPT_LOSS_EVENT_RATE, 769 - &pinv, sizeof(pinv)) || 767 + &pinv, sizeof(pinv)) || 770 768 dccp_insert_option(sk, skb, TFRC_OPT_RECEIVE_RATE, 771 - &x_recv, sizeof(x_recv))) 769 + &x_recv, sizeof(x_recv))) 772 770 return -1; 773 771 774 772 return 0; ··· 782 780 { 783 781 struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk); 784 782 struct dccp_rx_hist_entry *entry, *next, *tail = NULL; 785 - u32 rtt, delta, x_recv, fval, p, tmp2; 783 + u32 x_recv, p; 784 + suseconds_t rtt, delta; 786 785 struct timeval tstamp = { 0, }; 787 786 int interval = 0; 788 787 int win_count = 0; 789 788 int step = 0; 790 - u64 tmp1; 789 + u64 fval; 791 790 792 791 list_for_each_entry_safe(entry, next, &hcrx->ccid3hcrx_hist, 793 792 dccphrx_node) { ··· 813 810 } 814 811 815 812 if (unlikely(step == 0)) { 816 - DCCP_WARN("%s, sk=%p, packet history has no data packets!\n", 813 + DCCP_WARN("%s(%p), packet history has no data packets!\n", 817 814 dccp_role(sk), sk); 818 815 return ~0; 819 816 } 820 817 821 818 if (unlikely(interval == 0)) { 822 - DCCP_WARN("%s, sk=%p, Could not find a win_count interval > 0." 819 + DCCP_WARN("%s(%p), Could not find a win_count interval > 0." 823 820 "Defaulting to 1\n", dccp_role(sk), sk); 824 821 interval = 1; 825 822 } ··· 828 825 DCCP_CRIT("tail is null\n"); 829 826 return ~0; 830 827 } 831 - rtt = timeval_delta(&tstamp, &tail->dccphrx_tstamp) * 4 / interval; 832 - ccid3_pr_debug("%s, sk=%p, approximated RTT to %uus\n", 833 - dccp_role(sk), sk, rtt); 834 828 835 - if (rtt == 0) { 836 - DCCP_WARN("RTT==0, setting to 1\n"); 837 - rtt = 1; 829 + delta = timeval_delta(&tstamp, &tail->dccphrx_tstamp); 830 + DCCP_BUG_ON(delta < 0); 831 + 832 + rtt = delta * 4 / interval; 833 + ccid3_pr_debug("%s(%p), approximated RTT to %dus\n", 834 + dccp_role(sk), sk, (int)rtt); 835 + 836 + /* 837 + * Determine the length of the first loss interval via inverse lookup. 838 + * Assume that X_recv can be computed by the throughput equation 839 + * s 840 + * X_recv = -------- 841 + * R * fval 842 + * Find some p such that f(p) = fval; return 1/p [RFC 3448, 6.3.1]. 843 + */ 844 + if (rtt == 0) { /* would result in divide-by-zero */ 845 + DCCP_WARN("RTT==0, returning 1/p = 1\n"); 846 + return 1000000; 838 847 } 839 848 840 849 dccp_timestamp(sk, &tstamp); 841 850 delta = timeval_delta(&tstamp, &hcrx->ccid3hcrx_tstamp_last_feedback); 842 - x_recv = usecs_div(hcrx->ccid3hcrx_bytes_recv, delta); 851 + DCCP_BUG_ON(delta <= 0); 843 852 844 - if (x_recv == 0) 845 - x_recv = hcrx->ccid3hcrx_x_recv; 846 - 847 - tmp1 = (u64)x_recv * (u64)rtt; 848 - do_div(tmp1,10000000); 849 - tmp2 = (u32)tmp1; 850 - 851 - if (!tmp2) { 852 - DCCP_CRIT("tmp2 = 0, x_recv = %u, rtt =%u\n", x_recv, rtt); 853 - return ~0; 853 + x_recv = scaled_div32(hcrx->ccid3hcrx_bytes_recv, delta); 854 + if (x_recv == 0) { /* would also trigger divide-by-zero */ 855 + DCCP_WARN("X_recv==0\n"); 856 + if ((x_recv = hcrx->ccid3hcrx_x_recv) == 0) { 857 + DCCP_BUG("stored value of X_recv is zero"); 858 + return 1000000; 859 + } 854 860 } 855 861 856 - fval = (hcrx->ccid3hcrx_s * 100000) / tmp2; 857 - /* do not alter order above or you will get overflow on 32 bit */ 862 + fval = scaled_div(hcrx->ccid3hcrx_s, rtt); 863 + fval = scaled_div32(fval, x_recv); 858 864 p = tfrc_calc_x_reverse_lookup(fval); 859 - ccid3_pr_debug("%s, sk=%p, receive rate=%u bytes/s, implied " 865 + 866 + ccid3_pr_debug("%s(%p), receive rate=%u bytes/s, implied " 860 867 "loss rate=%u\n", dccp_role(sk), sk, x_recv, p); 861 868 862 869 if (p == 0) 863 870 return ~0; 864 871 else 865 - return 1000000 / p; 872 + return 1000000 / p; 866 873 } 867 874 868 875 static void ccid3_hc_rx_update_li(struct sock *sk, u64 seq_loss, u8 win_loss) ··· 926 913 struct dccp_rx_hist_entry *packet) 927 914 { 928 915 struct ccid3_hc_rx_sock *hcrx = ccid3_hc_rx_sk(sk); 929 - struct dccp_rx_hist_entry *rx_hist = dccp_rx_hist_head(&hcrx->ccid3hcrx_hist); 916 + struct dccp_rx_hist_entry *rx_hist = 917 + dccp_rx_hist_head(&hcrx->ccid3hcrx_hist); 930 918 u64 seqno = packet->dccphrx_seqno; 931 919 u64 tmp_seqno; 932 920 int loss = 0; ··· 955 941 dccp_inc_seqno(&tmp_seqno); 956 942 while (dccp_rx_hist_find_entry(&hcrx->ccid3hcrx_hist, 957 943 tmp_seqno, &ccval)) { 958 - hcrx->ccid3hcrx_seqno_nonloss = tmp_seqno; 944 + hcrx->ccid3hcrx_seqno_nonloss = tmp_seqno; 959 945 hcrx->ccid3hcrx_ccval_nonloss = ccval; 960 946 dccp_inc_seqno(&tmp_seqno); 961 947 } ··· 981 967 const struct dccp_options_received *opt_recv; 982 968 struct dccp_rx_hist_entry *packet; 983 969 struct timeval now; 984 - u32 p_prev, rtt_prev, r_sample, t_elapsed; 970 + u32 p_prev, rtt_prev; 971 + suseconds_t r_sample, t_elapsed; 985 972 int loss, payload_size; 986 973 987 974 BUG_ON(hcrx == NULL); ··· 1002 987 r_sample = timeval_usecs(&now); 1003 988 t_elapsed = opt_recv->dccpor_elapsed_time * 10; 1004 989 990 + DCCP_BUG_ON(r_sample < 0); 1005 991 if (unlikely(r_sample <= t_elapsed)) 1006 - DCCP_WARN("r_sample=%uus, t_elapsed=%uus\n", 992 + DCCP_WARN("r_sample=%ldus, t_elapsed=%ldus\n", 1007 993 r_sample, t_elapsed); 1008 994 else 1009 995 r_sample -= t_elapsed; 996 + CCID3_RTT_SANITY_CHECK(r_sample); 1010 997 1011 998 if (hcrx->ccid3hcrx_state == TFRC_RSTATE_NO_DATA) 1012 999 hcrx->ccid3hcrx_rtt = r_sample; ··· 1017 1000 r_sample / 10; 1018 1001 1019 1002 if (rtt_prev != hcrx->ccid3hcrx_rtt) 1020 - ccid3_pr_debug("%s, New RTT=%uus, elapsed time=%u\n", 1021 - dccp_role(sk), hcrx->ccid3hcrx_rtt, 1003 + ccid3_pr_debug("%s(%p), New RTT=%uus, elapsed time=%u\n", 1004 + dccp_role(sk), sk, hcrx->ccid3hcrx_rtt, 1022 1005 opt_recv->dccpor_elapsed_time); 1023 1006 break; 1024 1007 case DCCP_PKT_DATA: ··· 1030 1013 packet = dccp_rx_hist_entry_new(ccid3_rx_hist, sk, opt_recv->dccpor_ndp, 1031 1014 skb, GFP_ATOMIC); 1032 1015 if (unlikely(packet == NULL)) { 1033 - DCCP_WARN("%s, sk=%p, Not enough mem to add rx packet " 1016 + DCCP_WARN("%s(%p), Not enough mem to add rx packet " 1034 1017 "to history, consider it lost!\n", dccp_role(sk), sk); 1035 1018 return; 1036 1019 } ··· 1045 1028 1046 1029 switch (hcrx->ccid3hcrx_state) { 1047 1030 case TFRC_RSTATE_NO_DATA: 1048 - ccid3_pr_debug("%s, sk=%p(%s), skb=%p, sending initial " 1049 - "feedback\n", 1050 - dccp_role(sk), sk, 1031 + ccid3_pr_debug("%s(%p, state=%s), skb=%p, sending initial " 1032 + "feedback\n", dccp_role(sk), sk, 1051 1033 dccp_state_name(sk->sk_state), skb); 1052 1034 ccid3_hc_rx_send_feedback(sk); 1053 1035 ccid3_hc_rx_set_state(sk, TFRC_RSTATE_DATA); ··· 1057 1041 break; 1058 1042 1059 1043 dccp_timestamp(sk, &now); 1060 - if (timeval_delta(&now, &hcrx->ccid3hcrx_tstamp_last_ack) >= 1061 - hcrx->ccid3hcrx_rtt) { 1044 + if ((timeval_delta(&now, &hcrx->ccid3hcrx_tstamp_last_ack) - 1045 + (suseconds_t)hcrx->ccid3hcrx_rtt) >= 0) { 1062 1046 hcrx->ccid3hcrx_tstamp_last_ack = now; 1063 1047 ccid3_hc_rx_send_feedback(sk); 1064 1048 } 1065 1049 return; 1066 1050 case TFRC_RSTATE_TERM: 1067 - DCCP_BUG("Illegal %s state TERM, sk=%p", dccp_role(sk), sk); 1051 + DCCP_BUG("%s(%p) - Illegal state TERM", dccp_role(sk), sk); 1068 1052 return; 1069 1053 } 1070 1054 1071 1055 /* Dealing with packet loss */ 1072 - ccid3_pr_debug("%s, sk=%p(%s), data loss! Reacting...\n", 1056 + ccid3_pr_debug("%s(%p, state=%s), data loss! Reacting...\n", 1073 1057 dccp_role(sk), sk, dccp_state_name(sk->sk_state)); 1074 1058 1075 1059 p_prev = hcrx->ccid3hcrx_p; ··· 1094 1078 { 1095 1079 struct ccid3_hc_rx_sock *hcrx = ccid_priv(ccid); 1096 1080 1097 - ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk); 1081 + ccid3_pr_debug("entry\n"); 1098 1082 1099 1083 hcrx->ccid3hcrx_state = TFRC_RSTATE_NO_DATA; 1100 1084 INIT_LIST_HEAD(&hcrx->ccid3hcrx_hist); ··· 1102 1086 dccp_timestamp(sk, &hcrx->ccid3hcrx_tstamp_last_ack); 1103 1087 hcrx->ccid3hcrx_tstamp_last_feedback = hcrx->ccid3hcrx_tstamp_last_ack; 1104 1088 hcrx->ccid3hcrx_s = 0; 1105 - hcrx->ccid3hcrx_rtt = 5000; /* XXX 5ms for now... */ 1089 + hcrx->ccid3hcrx_rtt = 0; 1106 1090 return 0; 1107 1091 } 1108 1092 ··· 1131 1115 1132 1116 BUG_ON(hcrx == NULL); 1133 1117 1134 - info->tcpi_ca_state = hcrx->ccid3hcrx_state; 1135 - info->tcpi_options |= TCPI_OPT_TIMESTAMPS; 1136 - info->tcpi_rcv_rtt = hcrx->ccid3hcrx_rtt; 1118 + info->tcpi_ca_state = hcrx->ccid3hcrx_state; 1119 + info->tcpi_options |= TCPI_OPT_TIMESTAMPS; 1120 + info->tcpi_rcv_rtt = hcrx->ccid3hcrx_rtt; 1137 1121 } 1138 1122 1139 1123 static void ccid3_hc_tx_get_info(struct sock *sk, struct tcp_info *info) ··· 1214 1198 .ccid_hc_tx_send_packet = ccid3_hc_tx_send_packet, 1215 1199 .ccid_hc_tx_packet_sent = ccid3_hc_tx_packet_sent, 1216 1200 .ccid_hc_tx_packet_recv = ccid3_hc_tx_packet_recv, 1217 - .ccid_hc_tx_insert_options = ccid3_hc_tx_insert_options, 1218 1201 .ccid_hc_tx_parse_options = ccid3_hc_tx_parse_options, 1219 1202 .ccid_hc_rx_obj_size = sizeof(struct ccid3_hc_rx_sock), 1220 1203 .ccid_hc_rx_init = ccid3_hc_rx_init, ··· 1225 1210 .ccid_hc_rx_getsockopt = ccid3_hc_rx_getsockopt, 1226 1211 .ccid_hc_tx_getsockopt = ccid3_hc_tx_getsockopt, 1227 1212 }; 1228 - 1213 + 1229 1214 #ifdef CONFIG_IP_DCCP_CCID3_DEBUG 1230 1215 module_param(ccid3_debug, int, 0444); 1231 1216 MODULE_PARM_DESC(ccid3_debug, "Enable debug messages"); ··· 1248 1233 goto out_free_tx; 1249 1234 1250 1235 rc = ccid_register(&ccid3); 1251 - if (rc != 0) 1236 + if (rc != 0) 1252 1237 goto out_free_loss_interval_history; 1253 1238 out: 1254 1239 return rc;
+28 -18
net/dccp/ccids/ccid3.h
··· 51 51 /* Parameter t_mbi from [RFC 3448, 4.3]: backoff interval in seconds */ 52 52 #define TFRC_T_MBI 64 53 53 54 + /* What we think is a reasonable upper limit on RTT values */ 55 + #define CCID3_SANE_RTT_MAX ((suseconds_t)(4 * USEC_PER_SEC)) 56 + 57 + #define CCID3_RTT_SANITY_CHECK(rtt) do { \ 58 + if (rtt > CCID3_SANE_RTT_MAX) { \ 59 + DCCP_CRIT("RTT (%d) too large, substituting %d", \ 60 + (int)rtt, (int)CCID3_SANE_RTT_MAX); \ 61 + rtt = CCID3_SANE_RTT_MAX; \ 62 + } } while (0) 63 + 54 64 enum ccid3_options { 55 65 TFRC_OPT_LOSS_EVENT_RATE = 192, 56 66 TFRC_OPT_LOSS_INTERVALS = 193, ··· 77 67 78 68 /* TFRC sender states */ 79 69 enum ccid3_hc_tx_states { 80 - TFRC_SSTATE_NO_SENT = 1, 70 + TFRC_SSTATE_NO_SENT = 1, 81 71 TFRC_SSTATE_NO_FBACK, 82 72 TFRC_SSTATE_FBACK, 83 73 TFRC_SSTATE_TERM, ··· 85 75 86 76 /** struct ccid3_hc_tx_sock - CCID3 sender half-connection socket 87 77 * 88 - * @ccid3hctx_x - Current sending rate 89 - * @ccid3hctx_x_recv - Receive rate 90 - * @ccid3hctx_x_calc - Calculated send rate (RFC 3448, 3.1) 78 + * @ccid3hctx_x - Current sending rate in 64 * bytes per second 79 + * @ccid3hctx_x_recv - Receive rate in 64 * bytes per second 80 + * @ccid3hctx_x_calc - Calculated rate in bytes per second 91 81 * @ccid3hctx_rtt - Estimate of current round trip time in usecs 92 82 * @ccid3hctx_p - Current loss event rate (0-1) scaled by 1000000 93 - * @ccid3hctx_s - Packet size 94 - * @ccid3hctx_t_rto - Retransmission Timeout (RFC 3448, 3.1) 95 - * @ccid3hctx_t_ipi - Interpacket (send) interval (RFC 3448, 4.6) 83 + * @ccid3hctx_s - Packet size in bytes 84 + * @ccid3hctx_t_rto - Nofeedback Timer setting in usecs 85 + * @ccid3hctx_t_ipi - Interpacket (send) interval (RFC 3448, 4.6) in usecs 96 86 * @ccid3hctx_state - Sender state, one of %ccid3_hc_tx_states 97 87 * @ccid3hctx_last_win_count - Last window counter sent 98 88 * @ccid3hctx_t_last_win_count - Timestamp of earliest packet 99 - * with last_win_count value sent 89 + * with last_win_count value sent 100 90 * @ccid3hctx_no_feedback_timer - Handle to no feedback timer 101 91 * @ccid3hctx_idle - Flag indicating that sender is idling 102 92 * @ccid3hctx_t_ld - Time last doubled during slow start 103 93 * @ccid3hctx_t_nom - Nominal send time of next packet 104 - * @ccid3hctx_delta - Send timer delta 94 + * @ccid3hctx_delta - Send timer delta (RFC 3448, 4.6) in usecs 105 95 * @ccid3hctx_hist - Packet history 106 96 * @ccid3hctx_options_received - Parsed set of retrieved options 107 97 */ ··· 115 105 #define ccid3hctx_t_rto ccid3hctx_tfrc.tfrctx_rto 116 106 #define ccid3hctx_t_ipi ccid3hctx_tfrc.tfrctx_ipi 117 107 u16 ccid3hctx_s; 118 - enum ccid3_hc_tx_states ccid3hctx_state:8; 108 + enum ccid3_hc_tx_states ccid3hctx_state:8; 119 109 u8 ccid3hctx_last_win_count; 120 110 u8 ccid3hctx_idle; 121 111 struct timeval ccid3hctx_t_last_win_count; ··· 129 119 130 120 /* TFRC receiver states */ 131 121 enum ccid3_hc_rx_states { 132 - TFRC_RSTATE_NO_DATA = 1, 122 + TFRC_RSTATE_NO_DATA = 1, 133 123 TFRC_RSTATE_DATA, 134 124 TFRC_RSTATE_TERM = 127, 135 125 }; ··· 157 147 #define ccid3hcrx_x_recv ccid3hcrx_tfrc.tfrcrx_x_recv 158 148 #define ccid3hcrx_rtt ccid3hcrx_tfrc.tfrcrx_rtt 159 149 #define ccid3hcrx_p ccid3hcrx_tfrc.tfrcrx_p 160 - u64 ccid3hcrx_seqno_nonloss:48, 150 + u64 ccid3hcrx_seqno_nonloss:48, 161 151 ccid3hcrx_ccval_nonloss:4, 162 152 ccid3hcrx_ccval_last_counter:4; 163 153 enum ccid3_hc_rx_states ccid3hcrx_state:8; 164 - u32 ccid3hcrx_bytes_recv; 165 - struct timeval ccid3hcrx_tstamp_last_feedback; 166 - struct timeval ccid3hcrx_tstamp_last_ack; 154 + u32 ccid3hcrx_bytes_recv; 155 + struct timeval ccid3hcrx_tstamp_last_feedback; 156 + struct timeval ccid3hcrx_tstamp_last_ack; 167 157 struct list_head ccid3hcrx_hist; 168 158 struct list_head ccid3hcrx_li_hist; 169 - u16 ccid3hcrx_s; 170 - u32 ccid3hcrx_pinv; 171 - u32 ccid3hcrx_elapsed_time; 159 + u16 ccid3hcrx_s; 160 + u32 ccid3hcrx_pinv; 161 + u32 ccid3hcrx_elapsed_time; 172 162 }; 173 163 174 164 static inline struct ccid3_hc_tx_sock *ccid3_hc_tx_sk(const struct sock *sk)
+112 -107
net/dccp/ccids/lib/packet_history.c
··· 36 36 37 37 #include <linux/module.h> 38 38 #include <linux/string.h> 39 - 40 39 #include "packet_history.h" 41 40 41 + /* 42 + * Transmitter History Routines 43 + */ 44 + struct dccp_tx_hist *dccp_tx_hist_new(const char *name) 45 + { 46 + struct dccp_tx_hist *hist = kmalloc(sizeof(*hist), GFP_ATOMIC); 47 + static const char dccp_tx_hist_mask[] = "tx_hist_%s"; 48 + char *slab_name; 49 + 50 + if (hist == NULL) 51 + goto out; 52 + 53 + slab_name = kmalloc(strlen(name) + sizeof(dccp_tx_hist_mask) - 1, 54 + GFP_ATOMIC); 55 + if (slab_name == NULL) 56 + goto out_free_hist; 57 + 58 + sprintf(slab_name, dccp_tx_hist_mask, name); 59 + hist->dccptxh_slab = kmem_cache_create(slab_name, 60 + sizeof(struct dccp_tx_hist_entry), 61 + 0, SLAB_HWCACHE_ALIGN, 62 + NULL, NULL); 63 + if (hist->dccptxh_slab == NULL) 64 + goto out_free_slab_name; 65 + out: 66 + return hist; 67 + out_free_slab_name: 68 + kfree(slab_name); 69 + out_free_hist: 70 + kfree(hist); 71 + hist = NULL; 72 + goto out; 73 + } 74 + 75 + EXPORT_SYMBOL_GPL(dccp_tx_hist_new); 76 + 77 + void dccp_tx_hist_delete(struct dccp_tx_hist *hist) 78 + { 79 + const char* name = kmem_cache_name(hist->dccptxh_slab); 80 + 81 + kmem_cache_destroy(hist->dccptxh_slab); 82 + kfree(name); 83 + kfree(hist); 84 + } 85 + 86 + EXPORT_SYMBOL_GPL(dccp_tx_hist_delete); 87 + 88 + struct dccp_tx_hist_entry * 89 + dccp_tx_hist_find_entry(const struct list_head *list, const u64 seq) 90 + { 91 + struct dccp_tx_hist_entry *packet = NULL, *entry; 92 + 93 + list_for_each_entry(entry, list, dccphtx_node) 94 + if (entry->dccphtx_seqno == seq) { 95 + packet = entry; 96 + break; 97 + } 98 + 99 + return packet; 100 + } 101 + 102 + EXPORT_SYMBOL_GPL(dccp_tx_hist_find_entry); 103 + 104 + void dccp_tx_hist_purge(struct dccp_tx_hist *hist, struct list_head *list) 105 + { 106 + struct dccp_tx_hist_entry *entry, *next; 107 + 108 + list_for_each_entry_safe(entry, next, list, dccphtx_node) { 109 + list_del_init(&entry->dccphtx_node); 110 + dccp_tx_hist_entry_delete(hist, entry); 111 + } 112 + } 113 + 114 + EXPORT_SYMBOL_GPL(dccp_tx_hist_purge); 115 + 116 + void dccp_tx_hist_purge_older(struct dccp_tx_hist *hist, 117 + struct list_head *list, 118 + struct dccp_tx_hist_entry *packet) 119 + { 120 + struct dccp_tx_hist_entry *next; 121 + 122 + list_for_each_entry_safe_continue(packet, next, list, dccphtx_node) { 123 + list_del_init(&packet->dccphtx_node); 124 + dccp_tx_hist_entry_delete(hist, packet); 125 + } 126 + } 127 + 128 + EXPORT_SYMBOL_GPL(dccp_tx_hist_purge_older); 129 + 130 + /* 131 + * Receiver History Routines 132 + */ 42 133 struct dccp_rx_hist *dccp_rx_hist_new(const char *name) 43 134 { 44 135 struct dccp_rx_hist *hist = kmalloc(sizeof(*hist), GFP_ATOMIC); ··· 174 83 175 84 EXPORT_SYMBOL_GPL(dccp_rx_hist_delete); 176 85 177 - void dccp_rx_hist_purge(struct dccp_rx_hist *hist, struct list_head *list) 86 + int dccp_rx_hist_find_entry(const struct list_head *list, const u64 seq, 87 + u8 *ccval) 178 88 { 179 - struct dccp_rx_hist_entry *entry, *next; 89 + struct dccp_rx_hist_entry *packet = NULL, *entry; 180 90 181 - list_for_each_entry_safe(entry, next, list, dccphrx_node) { 182 - list_del_init(&entry->dccphrx_node); 183 - kmem_cache_free(hist->dccprxh_slab, entry); 184 - } 91 + list_for_each_entry(entry, list, dccphrx_node) 92 + if (entry->dccphrx_seqno == seq) { 93 + packet = entry; 94 + break; 95 + } 96 + 97 + if (packet) 98 + *ccval = packet->dccphrx_ccval; 99 + 100 + return packet != NULL; 185 101 } 186 102 187 - EXPORT_SYMBOL_GPL(dccp_rx_hist_purge); 188 - 103 + EXPORT_SYMBOL_GPL(dccp_rx_hist_find_entry); 189 104 struct dccp_rx_hist_entry * 190 105 dccp_rx_hist_find_data_packet(const struct list_head *list) 191 106 { ··· 281 184 282 185 EXPORT_SYMBOL_GPL(dccp_rx_hist_add_packet); 283 186 284 - struct dccp_tx_hist *dccp_tx_hist_new(const char *name) 187 + void dccp_rx_hist_purge(struct dccp_rx_hist *hist, struct list_head *list) 285 188 { 286 - struct dccp_tx_hist *hist = kmalloc(sizeof(*hist), GFP_ATOMIC); 287 - static const char dccp_tx_hist_mask[] = "tx_hist_%s"; 288 - char *slab_name; 189 + struct dccp_rx_hist_entry *entry, *next; 289 190 290 - if (hist == NULL) 291 - goto out; 292 - 293 - slab_name = kmalloc(strlen(name) + sizeof(dccp_tx_hist_mask) - 1, 294 - GFP_ATOMIC); 295 - if (slab_name == NULL) 296 - goto out_free_hist; 297 - 298 - sprintf(slab_name, dccp_tx_hist_mask, name); 299 - hist->dccptxh_slab = kmem_cache_create(slab_name, 300 - sizeof(struct dccp_tx_hist_entry), 301 - 0, SLAB_HWCACHE_ALIGN, 302 - NULL, NULL); 303 - if (hist->dccptxh_slab == NULL) 304 - goto out_free_slab_name; 305 - out: 306 - return hist; 307 - out_free_slab_name: 308 - kfree(slab_name); 309 - out_free_hist: 310 - kfree(hist); 311 - hist = NULL; 312 - goto out; 313 - } 314 - 315 - EXPORT_SYMBOL_GPL(dccp_tx_hist_new); 316 - 317 - void dccp_tx_hist_delete(struct dccp_tx_hist *hist) 318 - { 319 - const char* name = kmem_cache_name(hist->dccptxh_slab); 320 - 321 - kmem_cache_destroy(hist->dccptxh_slab); 322 - kfree(name); 323 - kfree(hist); 324 - } 325 - 326 - EXPORT_SYMBOL_GPL(dccp_tx_hist_delete); 327 - 328 - struct dccp_tx_hist_entry * 329 - dccp_tx_hist_find_entry(const struct list_head *list, const u64 seq) 330 - { 331 - struct dccp_tx_hist_entry *packet = NULL, *entry; 332 - 333 - list_for_each_entry(entry, list, dccphtx_node) 334 - if (entry->dccphtx_seqno == seq) { 335 - packet = entry; 336 - break; 337 - } 338 - 339 - return packet; 340 - } 341 - 342 - EXPORT_SYMBOL_GPL(dccp_tx_hist_find_entry); 343 - 344 - int dccp_rx_hist_find_entry(const struct list_head *list, const u64 seq, 345 - u8 *ccval) 346 - { 347 - struct dccp_rx_hist_entry *packet = NULL, *entry; 348 - 349 - list_for_each_entry(entry, list, dccphrx_node) 350 - if (entry->dccphrx_seqno == seq) { 351 - packet = entry; 352 - break; 353 - } 354 - 355 - if (packet) 356 - *ccval = packet->dccphrx_ccval; 357 - 358 - return packet != NULL; 359 - } 360 - 361 - EXPORT_SYMBOL_GPL(dccp_rx_hist_find_entry); 362 - 363 - void dccp_tx_hist_purge_older(struct dccp_tx_hist *hist, 364 - struct list_head *list, 365 - struct dccp_tx_hist_entry *packet) 366 - { 367 - struct dccp_tx_hist_entry *next; 368 - 369 - list_for_each_entry_safe_continue(packet, next, list, dccphtx_node) { 370 - list_del_init(&packet->dccphtx_node); 371 - dccp_tx_hist_entry_delete(hist, packet); 191 + list_for_each_entry_safe(entry, next, list, dccphrx_node) { 192 + list_del_init(&entry->dccphrx_node); 193 + kmem_cache_free(hist->dccprxh_slab, entry); 372 194 } 373 195 } 374 196 375 - EXPORT_SYMBOL_GPL(dccp_tx_hist_purge_older); 197 + EXPORT_SYMBOL_GPL(dccp_rx_hist_purge); 376 198 377 - void dccp_tx_hist_purge(struct dccp_tx_hist *hist, struct list_head *list) 378 - { 379 - struct dccp_tx_hist_entry *entry, *next; 380 - 381 - list_for_each_entry_safe(entry, next, list, dccphtx_node) { 382 - list_del_init(&entry->dccphtx_node); 383 - dccp_tx_hist_entry_delete(hist, entry); 384 - } 385 - } 386 - 387 - EXPORT_SYMBOL_GPL(dccp_tx_hist_purge); 388 199 389 200 MODULE_AUTHOR("Ian McDonald <ian.mcdonald@jandi.co.nz>, " 390 201 "Arnaldo Carvalho de Melo <acme@ghostprotocols.net>");
+77 -71
net/dccp/ccids/lib/packet_history.h
··· 49 49 #define TFRC_WIN_COUNT_PER_RTT 4 50 50 #define TFRC_WIN_COUNT_LIMIT 16 51 51 52 + /* 53 + * Transmitter History data structures and declarations 54 + */ 52 55 struct dccp_tx_hist_entry { 53 56 struct list_head dccphtx_node; 54 57 u64 dccphtx_seqno:48, 55 - dccphtx_ccval:4, 56 58 dccphtx_sent:1; 57 59 u32 dccphtx_rtt; 58 60 struct timeval dccphtx_tstamp; 59 - }; 60 - 61 - struct dccp_rx_hist_entry { 62 - struct list_head dccphrx_node; 63 - u64 dccphrx_seqno:48, 64 - dccphrx_ccval:4, 65 - dccphrx_type:4; 66 - u32 dccphrx_ndp; /* In fact it is from 8 to 24 bits */ 67 - struct timeval dccphrx_tstamp; 68 61 }; 69 62 70 63 struct dccp_tx_hist { ··· 65 72 }; 66 73 67 74 extern struct dccp_tx_hist *dccp_tx_hist_new(const char *name); 68 - extern void dccp_tx_hist_delete(struct dccp_tx_hist *hist); 69 - 70 - struct dccp_rx_hist { 71 - struct kmem_cache *dccprxh_slab; 72 - }; 73 - 74 - extern struct dccp_rx_hist *dccp_rx_hist_new(const char *name); 75 - extern void dccp_rx_hist_delete(struct dccp_rx_hist *hist); 76 - extern struct dccp_rx_hist_entry * 77 - dccp_rx_hist_find_data_packet(const struct list_head *list); 75 + extern void dccp_tx_hist_delete(struct dccp_tx_hist *hist); 78 76 79 77 static inline struct dccp_tx_hist_entry * 80 - dccp_tx_hist_entry_new(struct dccp_tx_hist *hist, 81 - const gfp_t prio) 78 + dccp_tx_hist_entry_new(struct dccp_tx_hist *hist, 79 + const gfp_t prio) 82 80 { 83 81 struct dccp_tx_hist_entry *entry = kmem_cache_alloc(hist->dccptxh_slab, 84 82 prio); ··· 80 96 return entry; 81 97 } 82 98 83 - static inline void dccp_tx_hist_entry_delete(struct dccp_tx_hist *hist, 84 - struct dccp_tx_hist_entry *entry) 85 - { 86 - if (entry != NULL) 87 - kmem_cache_free(hist->dccptxh_slab, entry); 88 - } 89 - 90 - extern struct dccp_tx_hist_entry * 91 - dccp_tx_hist_find_entry(const struct list_head *list, 92 - const u64 seq); 93 - extern int dccp_rx_hist_find_entry(const struct list_head *list, const u64 seq, 94 - u8 *ccval); 95 - 96 - static inline void dccp_tx_hist_add_entry(struct list_head *list, 97 - struct dccp_tx_hist_entry *entry) 98 - { 99 - list_add(&entry->dccphtx_node, list); 100 - } 101 - 102 - extern void dccp_tx_hist_purge_older(struct dccp_tx_hist *hist, 103 - struct list_head *list, 104 - struct dccp_tx_hist_entry *next); 105 - 106 - extern void dccp_tx_hist_purge(struct dccp_tx_hist *hist, 107 - struct list_head *list); 108 - 109 99 static inline struct dccp_tx_hist_entry * 110 - dccp_tx_hist_head(struct list_head *list) 100 + dccp_tx_hist_head(struct list_head *list) 111 101 { 112 102 struct dccp_tx_hist_entry *head = NULL; 113 103 ··· 91 133 return head; 92 134 } 93 135 136 + extern struct dccp_tx_hist_entry * 137 + dccp_tx_hist_find_entry(const struct list_head *list, 138 + const u64 seq); 139 + 140 + static inline void dccp_tx_hist_add_entry(struct list_head *list, 141 + struct dccp_tx_hist_entry *entry) 142 + { 143 + list_add(&entry->dccphtx_node, list); 144 + } 145 + 146 + static inline void dccp_tx_hist_entry_delete(struct dccp_tx_hist *hist, 147 + struct dccp_tx_hist_entry *entry) 148 + { 149 + if (entry != NULL) 150 + kmem_cache_free(hist->dccptxh_slab, entry); 151 + } 152 + 153 + extern void dccp_tx_hist_purge(struct dccp_tx_hist *hist, 154 + struct list_head *list); 155 + 156 + extern void dccp_tx_hist_purge_older(struct dccp_tx_hist *hist, 157 + struct list_head *list, 158 + struct dccp_tx_hist_entry *next); 159 + 160 + /* 161 + * Receiver History data structures and declarations 162 + */ 163 + struct dccp_rx_hist_entry { 164 + struct list_head dccphrx_node; 165 + u64 dccphrx_seqno:48, 166 + dccphrx_ccval:4, 167 + dccphrx_type:4; 168 + u32 dccphrx_ndp; /* In fact it is from 8 to 24 bits */ 169 + struct timeval dccphrx_tstamp; 170 + }; 171 + 172 + struct dccp_rx_hist { 173 + struct kmem_cache *dccprxh_slab; 174 + }; 175 + 176 + extern struct dccp_rx_hist *dccp_rx_hist_new(const char *name); 177 + extern void dccp_rx_hist_delete(struct dccp_rx_hist *hist); 178 + 94 179 static inline struct dccp_rx_hist_entry * 95 - dccp_rx_hist_entry_new(struct dccp_rx_hist *hist, 96 - const struct sock *sk, 97 - const u32 ndp, 98 - const struct sk_buff *skb, 99 - const gfp_t prio) 180 + dccp_rx_hist_entry_new(struct dccp_rx_hist *hist, 181 + const struct sock *sk, 182 + const u32 ndp, 183 + const struct sk_buff *skb, 184 + const gfp_t prio) 100 185 { 101 186 struct dccp_rx_hist_entry *entry = kmem_cache_alloc(hist->dccprxh_slab, 102 187 prio); ··· 157 156 return entry; 158 157 } 159 158 159 + static inline struct dccp_rx_hist_entry * 160 + dccp_rx_hist_head(struct list_head *list) 161 + { 162 + struct dccp_rx_hist_entry *head = NULL; 163 + 164 + if (!list_empty(list)) 165 + head = list_entry(list->next, struct dccp_rx_hist_entry, 166 + dccphrx_node); 167 + return head; 168 + } 169 + 170 + extern int dccp_rx_hist_find_entry(const struct list_head *list, const u64 seq, 171 + u8 *ccval); 172 + extern struct dccp_rx_hist_entry * 173 + dccp_rx_hist_find_data_packet(const struct list_head *list); 174 + 175 + extern void dccp_rx_hist_add_packet(struct dccp_rx_hist *hist, 176 + struct list_head *rx_list, 177 + struct list_head *li_list, 178 + struct dccp_rx_hist_entry *packet, 179 + u64 nonloss_seqno); 180 + 160 181 static inline void dccp_rx_hist_entry_delete(struct dccp_rx_hist *hist, 161 182 struct dccp_rx_hist_entry *entry) 162 183 { ··· 189 166 extern void dccp_rx_hist_purge(struct dccp_rx_hist *hist, 190 167 struct list_head *list); 191 168 192 - static inline struct dccp_rx_hist_entry * 193 - dccp_rx_hist_head(struct list_head *list) 194 - { 195 - struct dccp_rx_hist_entry *head = NULL; 196 - 197 - if (!list_empty(list)) 198 - head = list_entry(list->next, struct dccp_rx_hist_entry, 199 - dccphrx_node); 200 - return head; 201 - } 202 - 203 169 static inline int 204 170 dccp_rx_hist_entry_data_packet(const struct dccp_rx_hist_entry *entry) 205 171 { 206 172 return entry->dccphrx_type == DCCP_PKT_DATA || 207 173 entry->dccphrx_type == DCCP_PKT_DATAACK; 208 174 } 209 - 210 - extern void dccp_rx_hist_add_packet(struct dccp_rx_hist *hist, 211 - struct list_head *rx_list, 212 - struct list_head *li_list, 213 - struct dccp_rx_hist_entry *packet, 214 - u64 nonloss_seqno); 215 175 216 176 extern u64 dccp_rx_hist_detect_loss(struct list_head *rx_list, 217 177 struct list_head *li_list, u8 *win_loss);
+22 -1
net/dccp/ccids/lib/tfrc.h
··· 13 13 * the Free Software Foundation; either version 2 of the License, or 14 14 * (at your option) any later version. 15 15 */ 16 - 17 16 #include <linux/types.h> 17 + #include <asm/div64.h> 18 + 19 + /* integer-arithmetic divisions of type (a * 1000000)/b */ 20 + static inline u64 scaled_div(u64 a, u32 b) 21 + { 22 + BUG_ON(b==0); 23 + a *= 1000000; 24 + do_div(a, b); 25 + return a; 26 + } 27 + 28 + static inline u32 scaled_div32(u64 a, u32 b) 29 + { 30 + u64 result = scaled_div(a, b); 31 + 32 + if (result > UINT_MAX) { 33 + DCCP_CRIT("Overflow: a(%llu)/b(%u) > ~0U", 34 + (unsigned long long)a, b); 35 + return UINT_MAX; 36 + } 37 + return result; 38 + } 18 39 19 40 extern u32 tfrc_calc_x(u16 s, u32 R, u32 p); 20 41 extern u32 tfrc_calc_x_reverse_lookup(u32 fvalue);
+13 -15
net/dccp/ccids/lib/tfrc_equation.c
··· 13 13 */ 14 14 15 15 #include <linux/module.h> 16 - #include <asm/div64.h> 17 16 #include "../../dccp.h" 18 17 #include "tfrc.h" 19 18 ··· 615 616 * @R: RTT scaled by 1000000 (i.e., microseconds) 616 617 * @p: loss ratio estimate scaled by 1000000 617 618 * Returns X_calc in bytes per second (not scaled). 618 - * 619 - * Note: DO NOT alter this code unless you run test cases against it, 620 - * as the code has been optimized to stop underflow/overflow. 621 619 */ 622 620 u32 tfrc_calc_x(u16 s, u32 R, u32 p) 623 621 { 624 - int index; 622 + u16 index; 625 623 u32 f; 626 - u64 tmp1, tmp2; 624 + u64 result; 627 625 628 626 /* check against invalid parameters and divide-by-zero */ 629 627 BUG_ON(p > 1000000); /* p must not exceed 100% */ ··· 646 650 f = tfrc_calc_x_lookup[index][0]; 647 651 } 648 652 649 - /* The following computes X = s/(R*f(p)) in bytes per second. Since f(p) 650 - * and R are both scaled by 1000000, we need to multiply by 1000000^2. 651 - * ==> DO NOT alter this unless you test against overflow on 32 bit */ 652 - tmp1 = ((u64)s * 100000000); 653 - tmp2 = ((u64)R * (u64)f); 654 - do_div(tmp2, 10000); 655 - do_div(tmp1, tmp2); 656 - 657 - return (u32)tmp1; 653 + /* 654 + * Compute X = s/(R*f(p)) in bytes per second. 655 + * Since f(p) and R are both scaled by 1000000, we need to multiply by 656 + * 1000000^2. To avoid overflow, the result is computed in two stages. 657 + * This works under almost all reasonable operational conditions, for a 658 + * wide range of parameters. Yet, should some strange combination of 659 + * parameters result in overflow, the use of scaled_div32 will catch 660 + * this and return UINT_MAX - which is a logically adequate consequence. 661 + */ 662 + result = scaled_div(s, R); 663 + return scaled_div32(result, f); 658 664 } 659 665 660 666 EXPORT_SYMBOL_GPL(tfrc_calc_x);
+1 -2
net/dccp/dccp.h
··· 80 80 81 81 #define DCCP_RTO_MAX ((unsigned)(120 * HZ)) /* FIXME: using TCP value */ 82 82 83 - #define DCCP_XMIT_TIMEO 30000 /* Time/msecs for blocking transmit per packet */ 84 - 85 83 /* sysctl variables for DCCP */ 86 84 extern int sysctl_dccp_request_retries; 87 85 extern int sysctl_dccp_retries1; ··· 432 434 tv->tv_sec--; 433 435 tv->tv_usec += USEC_PER_SEC; 434 436 } 437 + DCCP_BUG_ON(tv->tv_sec < 0); 435 438 } 436 439 437 440 #ifdef CONFIG_SYSCTL
+3 -3
net/dccp/feat.c
··· 329 329 switch (type) { 330 330 case DCCPO_CHANGE_L: opt->dccpop_type = DCCPO_CONFIRM_R; break; 331 331 case DCCPO_CHANGE_R: opt->dccpop_type = DCCPO_CONFIRM_L; break; 332 - default: DCCP_WARN("invalid type %d\n", type); return; 332 + default: DCCP_WARN("invalid type %d\n", type); return; 333 333 334 334 } 335 335 opt->dccpop_feat = feature; ··· 427 427 switch (type) { 428 428 case DCCPO_CONFIRM_L: t = DCCPO_CHANGE_R; break; 429 429 case DCCPO_CONFIRM_R: t = DCCPO_CHANGE_L; break; 430 - default: DCCP_WARN("invalid type %d\n", type); 430 + default: DCCP_WARN("invalid type %d\n", type); 431 431 return 1; 432 432 433 433 } ··· 610 610 case DCCPO_CHANGE_R: return("ChangeR"); 611 611 case DCCPO_CONFIRM_R: return("ConfirmR"); 612 612 /* the following case must not appear in feature negotation */ 613 - default: dccp_pr_debug("unknown type %d [BUG!]\n", type); 613 + default: dccp_pr_debug("unknown type %d [BUG!]\n", type); 614 614 } 615 615 return NULL; 616 616 }
+30 -17
net/dccp/input.c
··· 1 1 /* 2 2 * net/dccp/input.c 3 - * 3 + * 4 4 * An implementation of the DCCP protocol 5 5 * Arnaldo Carvalho de Melo <acme@conectiva.com.br> 6 6 * ··· 82 82 * Otherwise, 83 83 * Drop packet and return 84 84 */ 85 - if (dh->dccph_type == DCCP_PKT_SYNC || 85 + if (dh->dccph_type == DCCP_PKT_SYNC || 86 86 dh->dccph_type == DCCP_PKT_SYNCACK) { 87 87 if (between48(DCCP_SKB_CB(skb)->dccpd_ack_seq, 88 88 dp->dccps_awl, dp->dccps_awh) && ··· 185 185 dccp_rcv_close(sk, skb); 186 186 return 0; 187 187 case DCCP_PKT_REQUEST: 188 - /* Step 7 189 - * or (S.is_server and P.type == Response) 188 + /* Step 7 189 + * or (S.is_server and P.type == Response) 190 190 * or (S.is_client and P.type == Request) 191 191 * or (S.state >= OPEN and P.type == Request 192 192 * and P.seqno >= S.OSR) ··· 248 248 DCCP_ACKVEC_STATE_RECEIVED)) 249 249 goto discard; 250 250 251 - ccid_hc_rx_packet_recv(dp->dccps_hc_rx_ccid, sk, skb); 252 - ccid_hc_tx_packet_recv(dp->dccps_hc_tx_ccid, sk, skb); 251 + /* 252 + * Deliver to the CCID module in charge. 253 + * FIXME: Currently DCCP operates one-directional only, i.e. a listening 254 + * server is not at the same time a connecting client. There is 255 + * not much sense in delivering to both rx/tx sides at the moment 256 + * (only one is active at a time); when moving to bidirectional 257 + * service, this needs to be revised. 258 + */ 259 + if (dccp_sk(sk)->dccps_role == DCCP_ROLE_SERVER) 260 + ccid_hc_rx_packet_recv(dp->dccps_hc_rx_ccid, sk, skb); 261 + else 262 + ccid_hc_tx_packet_recv(dp->dccps_hc_tx_ccid, sk, skb); 253 263 254 264 return __dccp_rcv_established(sk, skb, dh, len); 255 265 discard: ··· 274 264 const struct dccp_hdr *dh, 275 265 const unsigned len) 276 266 { 277 - /* 267 + /* 278 268 * Step 4: Prepare sequence numbers in REQUEST 279 269 * If S.state == REQUEST, 280 270 * If (P.type == Response or P.type == Reset) ··· 342 332 * from the Response * / 343 333 * S.state := PARTOPEN 344 334 * Set PARTOPEN timer 345 - * Continue with S.state == PARTOPEN 335 + * Continue with S.state == PARTOPEN 346 336 * / * Step 12 will send the Ack completing the 347 337 * three-way handshake * / 348 338 */ ··· 373 363 */ 374 364 __kfree_skb(skb); 375 365 return 0; 376 - } 366 + } 377 367 dccp_send_ack(sk); 378 368 return -1; 379 369 } ··· 381 371 out_invalid_packet: 382 372 /* dccp_v4_do_rcv will send a reset */ 383 373 DCCP_SKB_CB(skb)->dccpd_reset_code = DCCP_RESET_CODE_PACKET_ERROR; 384 - return 1; 374 + return 1; 385 375 } 386 376 387 377 static int dccp_rcv_respond_partopen_state_process(struct sock *sk, ··· 488 478 if (dcb->dccpd_ack_seq != DCCP_PKT_WITHOUT_ACK_SEQ) 489 479 dccp_event_ack_recv(sk, skb); 490 480 491 - if (dccp_msk(sk)->dccpms_send_ack_vector && 481 + if (dccp_msk(sk)->dccpms_send_ack_vector && 492 482 dccp_ackvec_add(dp->dccps_hc_rx_ackvec, sk, 493 - DCCP_SKB_CB(skb)->dccpd_seq, 494 - DCCP_ACKVEC_STATE_RECEIVED)) 495 - goto discard; 483 + DCCP_SKB_CB(skb)->dccpd_seq, 484 + DCCP_ACKVEC_STATE_RECEIVED)) 485 + goto discard; 496 486 497 - ccid_hc_rx_packet_recv(dp->dccps_hc_rx_ccid, sk, skb); 498 - ccid_hc_tx_packet_recv(dp->dccps_hc_tx_ccid, sk, skb); 487 + /* XXX see the comments in dccp_rcv_established about this */ 488 + if (dccp_sk(sk)->dccps_role == DCCP_ROLE_SERVER) 489 + ccid_hc_rx_packet_recv(dp->dccps_hc_rx_ccid, sk, skb); 490 + else 491 + ccid_hc_tx_packet_recv(dp->dccps_hc_tx_ccid, sk, skb); 499 492 } 500 493 501 494 /* ··· 580 567 } 581 568 } 582 569 583 - if (!queued) { 570 + if (!queued) { 584 571 discard: 585 572 __kfree_skb(skb); 586 573 }
+13 -13
net/dccp/ipv4.c
··· 157 157 /* We don't check in the destentry if pmtu discovery is forbidden 158 158 * on this route. We just assume that no packet_to_big packets 159 159 * are send back when pmtu discovery is not active. 160 - * There is a small race when the user changes this flag in the 160 + * There is a small race when the user changes this flag in the 161 161 * route, but I think that's acceptable. 162 162 */ 163 163 if ((dst = __sk_dst_check(sk, 0)) == NULL) ··· 467 467 .uli_u = { .ports = 468 468 { .sport = dccp_hdr(skb)->dccph_dport, 469 469 .dport = dccp_hdr(skb)->dccph_sport } 470 - } 470 + } 471 471 }; 472 472 473 473 security_skb_classify_flow(skb, &fl); ··· 595 595 struct inet_request_sock *ireq; 596 596 struct request_sock *req; 597 597 struct dccp_request_sock *dreq; 598 - const __be32 service = dccp_hdr_request(skb)->dccph_req_service; 598 + const __be32 service = dccp_hdr_request(skb)->dccph_req_service; 599 599 struct dccp_skb_cb *dcb = DCCP_SKB_CB(skb); 600 600 __u8 reset_code = DCCP_RESET_CODE_TOO_BUSY; 601 601 ··· 609 609 if (dccp_bad_service_code(sk, service)) { 610 610 reset_code = DCCP_RESET_CODE_BAD_SERVICE_CODE; 611 611 goto drop; 612 - } 612 + } 613 613 /* 614 614 * TW buckets are converted to open requests without 615 615 * limitations, they conserve resources and peer is ··· 644 644 ireq->rmt_addr = skb->nh.iph->saddr; 645 645 ireq->opt = NULL; 646 646 647 - /* 647 + /* 648 648 * Step 3: Process LISTEN state 649 649 * 650 650 * Set S.ISR, S.GSR, S.SWL, S.SWH from packet or Init Cookie ··· 846 846 } 847 847 848 848 /* Step 2: 849 - * Look up flow ID in table and get corresponding socket */ 849 + * Look up flow ID in table and get corresponding socket */ 850 850 sk = __inet_lookup(&dccp_hashinfo, 851 851 skb->nh.iph->saddr, dh->dccph_sport, 852 852 skb->nh.iph->daddr, dh->dccph_dport, 853 853 inet_iif(skb)); 854 854 855 - /* 855 + /* 856 856 * Step 2: 857 - * If no socket ... 857 + * If no socket ... 858 858 */ 859 859 if (sk == NULL) { 860 860 dccp_pr_debug("failed to look up flow ID in table and " ··· 862 862 goto no_dccp_socket; 863 863 } 864 864 865 - /* 865 + /* 866 866 * Step 2: 867 - * ... or S.state == TIMEWAIT, 867 + * ... or S.state == TIMEWAIT, 868 868 * Generate Reset(No Connection) unless P.type == Reset 869 869 * Drop packet and return 870 870 */ ··· 876 876 877 877 /* 878 878 * RFC 4340, sec. 9.2.1: Minimum Checksum Coverage 879 - * o if MinCsCov = 0, only packets with CsCov = 0 are accepted 880 - * o if MinCsCov > 0, also accept packets with CsCov >= MinCsCov 879 + * o if MinCsCov = 0, only packets with CsCov = 0 are accepted 880 + * o if MinCsCov > 0, also accept packets with CsCov >= MinCsCov 881 881 */ 882 882 min_cov = dccp_sk(sk)->dccps_pcrlen; 883 883 if (dh->dccph_cscov && (min_cov == 0 || dh->dccph_cscov < min_cov)) { ··· 900 900 goto discard_it; 901 901 /* 902 902 * Step 2: 903 - * If no socket ... 903 + * If no socket ... 904 904 * Generate Reset(No Connection) unless P.type == Reset 905 905 * Drop packet and return 906 906 */
+12 -12
net/dccp/ipv6.c
··· 77 77 } 78 78 79 79 static inline __u32 secure_dccpv6_sequence_number(__be32 *saddr, __be32 *daddr, 80 - __be16 sport, __be16 dport ) 80 + __be16 sport, __be16 dport ) 81 81 { 82 82 return secure_tcpv6_sequence_number(saddr, daddr, sport, dport); 83 83 } ··· 329 329 skb = alloc_skb(dccp_v6_ctl_socket->sk->sk_prot->max_header, 330 330 GFP_ATOMIC); 331 331 if (skb == NULL) 332 - return; 332 + return; 333 333 334 334 skb_reserve(skb, dccp_v6_ctl_socket->sk->sk_prot->max_header); 335 335 ··· 353 353 354 354 dccp_csum_outgoing(skb); 355 355 dh->dccph_checksum = dccp_v6_csum_finish(skb, &rxskb->nh.ipv6h->saddr, 356 - &rxskb->nh.ipv6h->daddr); 356 + &rxskb->nh.ipv6h->daddr); 357 357 358 358 memset(&fl, 0, sizeof(fl)); 359 359 ipv6_addr_copy(&fl.fl6_dst, &rxskb->nh.ipv6h->saddr); ··· 424 424 struct dccp_request_sock *dreq; 425 425 struct inet6_request_sock *ireq6; 426 426 struct ipv6_pinfo *np = inet6_sk(sk); 427 - const __be32 service = dccp_hdr_request(skb)->dccph_req_service; 427 + const __be32 service = dccp_hdr_request(skb)->dccph_req_service; 428 428 struct dccp_skb_cb *dcb = DCCP_SKB_CB(skb); 429 429 __u8 reset_code = DCCP_RESET_CODE_TOO_BUSY; 430 430 ··· 437 437 if (dccp_bad_service_code(sk, service)) { 438 438 reset_code = DCCP_RESET_CODE_BAD_SERVICE_CODE; 439 439 goto drop; 440 - } 440 + } 441 441 /* 442 442 * There are no SYN attacks on IPv6, yet... 443 443 */ ··· 787 787 * otherwise we just shortcircuit this and continue with 788 788 * the new socket.. 789 789 */ 790 - if (nsk != sk) { 790 + if (nsk != sk) { 791 791 if (dccp_child_process(sk, nsk, skb)) 792 792 goto reset; 793 793 if (opt_skb != NULL) ··· 843 843 DCCP_SKB_CB(skb)->dccpd_ack_seq = dccp_hdr_ack_seq(skb); 844 844 845 845 /* Step 2: 846 - * Look up flow ID in table and get corresponding socket */ 846 + * Look up flow ID in table and get corresponding socket */ 847 847 sk = __inet6_lookup(&dccp_hashinfo, &skb->nh.ipv6h->saddr, 848 848 dh->dccph_sport, 849 849 &skb->nh.ipv6h->daddr, ntohs(dh->dccph_dport), 850 850 inet6_iif(skb)); 851 851 /* 852 852 * Step 2: 853 - * If no socket ... 853 + * If no socket ... 854 854 */ 855 855 if (sk == NULL) { 856 856 dccp_pr_debug("failed to look up flow ID in table and " ··· 860 860 861 861 /* 862 862 * Step 2: 863 - * ... or S.state == TIMEWAIT, 863 + * ... or S.state == TIMEWAIT, 864 864 * Generate Reset(No Connection) unless P.type == Reset 865 865 * Drop packet and return 866 866 */ ··· 872 872 873 873 /* 874 874 * RFC 4340, sec. 9.2.1: Minimum Checksum Coverage 875 - * o if MinCsCov = 0, only packets with CsCov = 0 are accepted 876 - * o if MinCsCov > 0, also accept packets with CsCov >= MinCsCov 875 + * o if MinCsCov = 0, only packets with CsCov = 0 are accepted 876 + * o if MinCsCov > 0, also accept packets with CsCov >= MinCsCov 877 877 */ 878 878 min_cov = dccp_sk(sk)->dccps_pcrlen; 879 879 if (dh->dccph_cscov && (min_cov == 0 || dh->dccph_cscov < min_cov)) { ··· 893 893 goto discard_it; 894 894 /* 895 895 * Step 2: 896 - * If no socket ... 896 + * If no socket ... 897 897 * Generate Reset(No Connection) unless P.type == Reset 898 898 * Drop packet and return 899 899 */
+1 -1
net/dccp/minisocks.c
··· 182 182 183 183 EXPORT_SYMBOL_GPL(dccp_create_openreq_child); 184 184 185 - /* 185 + /* 186 186 * Process an incoming packet for RESPOND sockets represented 187 187 * as an request_sock. 188 188 */
-5
net/dccp/options.c
··· 557 557 return -1; 558 558 dp->dccps_hc_rx_insert_options = 0; 559 559 } 560 - if (dp->dccps_hc_tx_insert_options) { 561 - if (ccid_hc_tx_insert_options(dp->dccps_hc_tx_ccid, sk, skb)) 562 - return -1; 563 - dp->dccps_hc_tx_insert_options = 0; 564 - } 565 560 566 561 /* Feature negotiation */ 567 562 /* Data packets can't do feat negotiation */
+13 -26
net/dccp/output.c
··· 1 1 /* 2 2 * net/dccp/output.c 3 - * 3 + * 4 4 * An implementation of the DCCP protocol 5 5 * Arnaldo Carvalho de Melo <acme@conectiva.com.br> 6 6 * ··· 175 175 /** 176 176 * dccp_wait_for_ccid - Wait for ccid to tell us we can send a packet 177 177 * @sk: socket to wait for 178 - * @timeo: for how long 179 178 */ 180 - static int dccp_wait_for_ccid(struct sock *sk, struct sk_buff *skb, 181 - long *timeo) 179 + static int dccp_wait_for_ccid(struct sock *sk, struct sk_buff *skb) 182 180 { 183 181 struct dccp_sock *dp = dccp_sk(sk); 184 182 DEFINE_WAIT(wait); 185 - long delay; 183 + unsigned long delay; 186 184 int rc; 187 185 188 186 while (1) { ··· 188 190 189 191 if (sk->sk_err) 190 192 goto do_error; 191 - if (!*timeo) 192 - goto do_nonblock; 193 193 if (signal_pending(current)) 194 194 goto do_interrupted; 195 195 ··· 195 199 if (rc <= 0) 196 200 break; 197 201 delay = msecs_to_jiffies(rc); 198 - if (delay > *timeo || delay < 0) 199 - goto do_nonblock; 200 - 201 202 sk->sk_write_pending++; 202 203 release_sock(sk); 203 - *timeo -= schedule_timeout(delay); 204 + schedule_timeout(delay); 204 205 lock_sock(sk); 205 206 sk->sk_write_pending--; 206 207 } ··· 208 215 do_error: 209 216 rc = -EPIPE; 210 217 goto out; 211 - do_nonblock: 212 - rc = -EAGAIN; 213 - goto out; 214 218 do_interrupted: 215 - rc = sock_intr_errno(*timeo); 219 + rc = -EINTR; 216 220 goto out; 217 221 } 218 222 ··· 230 240 { 231 241 struct dccp_sock *dp = dccp_sk(sk); 232 242 struct sk_buff *skb; 233 - long timeo = DCCP_XMIT_TIMEO; /* If a packet is taking longer than 234 - this we have other issues */ 235 243 236 244 while ((skb = skb_peek(&sk->sk_write_queue))) { 237 245 int err = ccid_hc_tx_send_packet(dp->dccps_hc_tx_ccid, sk, skb); ··· 239 251 sk_reset_timer(sk, &dp->dccps_xmit_timer, 240 252 msecs_to_jiffies(err)+jiffies); 241 253 break; 242 - } else { 243 - err = dccp_wait_for_ccid(sk, skb, &timeo); 244 - timeo = DCCP_XMIT_TIMEO; 245 - } 246 - if (err) 254 + } else 255 + err = dccp_wait_for_ccid(sk, skb); 256 + if (err && err != -EINTR) 247 257 DCCP_BUG("err=%d after dccp_wait_for_ccid", err); 248 258 } 249 259 ··· 267 281 if (err) 268 282 DCCP_BUG("err=%d after ccid_hc_tx_packet_sent", 269 283 err); 270 - } else 284 + } else { 285 + dccp_pr_debug("packet discarded\n"); 271 286 kfree(skb); 287 + } 272 288 } 273 289 } 274 290 ··· 338 350 339 351 static struct sk_buff *dccp_make_reset(struct sock *sk, struct dst_entry *dst, 340 352 const enum dccp_reset_codes code) 341 - 342 353 { 343 354 struct dccp_hdr *dh; 344 355 struct dccp_sock *dp = dccp_sk(sk); ··· 418 431 419 432 dccp_sync_mss(sk, dst_mtu(dst)); 420 433 421 - /* 434 + /* 422 435 * SWL and AWL are initially adjusted so that they are not less than 423 436 * the initial Sequence Numbers received and sent, respectively: 424 437 * SWL := max(GSR + 1 - floor(W/4), ISR), 425 438 * AWL := max(GSS - W' + 1, ISS). 426 439 * These adjustments MUST be applied only at the beginning of the 427 440 * connection. 428 - */ 441 + */ 429 442 dccp_update_gss(sk, dp->dccps_iss); 430 443 dccp_set_seqno(&dp->dccps_awl, max48(dp->dccps_awl, dp->dccps_iss)); 431 444
+3 -3
net/dccp/proto.c
··· 196 196 sk, GFP_KERNEL); 197 197 dp->dccps_hc_tx_ccid = ccid_hc_tx_new(dmsk->dccpms_tx_ccid, 198 198 sk, GFP_KERNEL); 199 - if (unlikely(dp->dccps_hc_rx_ccid == NULL || 199 + if (unlikely(dp->dccps_hc_rx_ccid == NULL || 200 200 dp->dccps_hc_tx_ccid == NULL)) { 201 201 ccid_hc_rx_delete(dp->dccps_hc_rx_ccid, sk); 202 202 ccid_hc_tx_delete(dp->dccps_hc_tx_ccid, sk); ··· 390 390 struct dccp_sock *dp = dccp_sk(sk); 391 391 struct dccp_service_list *sl = NULL; 392 392 393 - if (service == DCCP_SERVICE_INVALID_VALUE || 393 + if (service == DCCP_SERVICE_INVALID_VALUE || 394 394 optlen > DCCP_SERVICE_LIST_MAX_LEN * sizeof(u32)) 395 395 return -EINVAL; 396 396 ··· 830 830 static const unsigned char dccp_new_state[] = { 831 831 /* current state: new state: action: */ 832 832 [0] = DCCP_CLOSED, 833 - [DCCP_OPEN] = DCCP_CLOSING | DCCP_ACTION_FIN, 833 + [DCCP_OPEN] = DCCP_CLOSING | DCCP_ACTION_FIN, 834 834 [DCCP_REQUESTING] = DCCP_CLOSED, 835 835 [DCCP_PARTOPEN] = DCCP_CLOSING | DCCP_ACTION_FIN, 836 836 [DCCP_LISTEN] = DCCP_CLOSED,
+7 -7
net/dccp/timer.c
··· 1 1 /* 2 2 * net/dccp/timer.c 3 - * 3 + * 4 4 * An implementation of the DCCP protocol 5 5 * Arnaldo Carvalho de Melo <acme@conectiva.com.br> 6 6 * ··· 102 102 * sk->sk_send_head has to have one skb with 103 103 * DCCP_SKB_CB(skb)->dccpd_type set to one of the retransmittable DCCP 104 104 * packet types. The only packets eligible for retransmission are: 105 - * -- Requests in client-REQUEST state (sec. 8.1.1) 106 - * -- Acks in client-PARTOPEN state (sec. 8.1.5) 107 - * -- CloseReq in server-CLOSEREQ state (sec. 8.3) 108 - * -- Close in node-CLOSING state (sec. 8.3) */ 105 + * -- Requests in client-REQUEST state (sec. 8.1.1) 106 + * -- Acks in client-PARTOPEN state (sec. 8.1.5) 107 + * -- CloseReq in server-CLOSEREQ state (sec. 8.3) 108 + * -- Close in node-CLOSING state (sec. 8.3) */ 109 109 BUG_TRAP(sk->sk_send_head != NULL); 110 110 111 - /* 111 + /* 112 112 * More than than 4MSL (8 minutes) has passed, a RESET(aborted) was 113 113 * sent, no need to retransmit, this sock is dead. 114 114 */ ··· 200 200 /* Only process if socket is not in use. */ 201 201 bh_lock_sock(sk); 202 202 if (sock_owned_by_user(sk)) { 203 - /* Try again later. */ 203 + /* Try again later. */ 204 204 inet_csk_reset_keepalive_timer(sk, HZ / 20); 205 205 goto out; 206 206 }
+10 -7
net/ipv4/ipvs/ip_vs_sync.c
··· 657 657 if (stop_master_sync) 658 658 break; 659 659 660 - ssleep(1); 660 + msleep_interruptible(1000); 661 661 } 662 662 663 663 /* clean up the sync_buff queue */ ··· 714 714 if (stop_backup_sync) 715 715 break; 716 716 717 - ssleep(1); 717 + msleep_interruptible(1000); 718 718 } 719 719 720 720 /* release the sending multicast socket */ ··· 826 826 if ((pid = kernel_thread(sync_thread, startup, 0)) < 0) { 827 827 IP_VS_ERR("could not create sync_thread due to %d... " 828 828 "retrying.\n", pid); 829 - ssleep(1); 829 + msleep_interruptible(1000); 830 830 goto repeat; 831 831 } 832 832 ··· 849 849 850 850 ip_vs_sync_state |= state; 851 851 if (state == IP_VS_STATE_MASTER) { 852 - strlcpy(ip_vs_master_mcast_ifn, mcast_ifn, sizeof(ip_vs_master_mcast_ifn)); 852 + strlcpy(ip_vs_master_mcast_ifn, mcast_ifn, 853 + sizeof(ip_vs_master_mcast_ifn)); 853 854 ip_vs_master_syncid = syncid; 854 855 } else { 855 - strlcpy(ip_vs_backup_mcast_ifn, mcast_ifn, sizeof(ip_vs_backup_mcast_ifn)); 856 + strlcpy(ip_vs_backup_mcast_ifn, mcast_ifn, 857 + sizeof(ip_vs_backup_mcast_ifn)); 856 858 ip_vs_backup_syncid = syncid; 857 859 } 858 860 ··· 862 860 if ((pid = kernel_thread(fork_sync_thread, &startup, 0)) < 0) { 863 861 IP_VS_ERR("could not create fork_sync_thread due to %d... " 864 862 "retrying.\n", pid); 865 - ssleep(1); 863 + msleep_interruptible(1000); 866 864 goto repeat; 867 865 } 868 866 ··· 882 880 883 881 IP_VS_DBG(7, "%s: pid %d\n", __FUNCTION__, current->pid); 884 882 IP_VS_INFO("stopping sync thread %d ...\n", 885 - (state == IP_VS_STATE_MASTER) ? sync_master_pid : sync_backup_pid); 883 + (state == IP_VS_STATE_MASTER) ? 884 + sync_master_pid : sync_backup_pid); 886 885 887 886 __set_current_state(TASK_UNINTERRUPTIBLE); 888 887 add_wait_queue(&stop_sync_wait, &wait);