: DCCP patches for 2.6.25
Subsystems (3)
cover : DCCP patches for 2.6.25
Hi David,
Please consider pulling from:
master.kernel.org:/pub/scm/linux/kernel/git/acme/net-2.6.25
Best Regards,
- Arnaldo
Documentation/networking/dccp.txt | 6 + include/linux/dccp.h | 24 ++++++- net/dccp/dccp.h | 10 ++- net/dccp/feat.c | 29 ++++---- net/dccp/feat.h | 26 ------- net/dccp/input.c | 28 +++++--- net/dccp/ipv4.c | 8 +- net/dccp/ipv6.c | 8 +- net/dccp/minisocks.c | 33 +++++---- net/dccp/options.c | 126 +++++++++++++++++++++++++------------- net/dccp/output.c | 21 +++++- net/dccp/proto.c | 34 +++------- 12 files changed, 208 insertions(+), 145 deletions(-)
PATCH 1/12 : Perform SHUT_RD and SHUT_WR on receiving close
From: Gerrit Renker <[email protected]>
This patch performs two changes:
1) Close the write-end in addition to the read-end when a fin-like segment (Close or CloseReq) is received by DCCP. This accounts for the fact that DCCP, in contrast to TCP, does not have a half-close. RFC 4340 says in this respect that when a fin-like segment has been sent there is no guarantee at all that
any further data will be processed.
Thus this patch performs SHUT_WR in addition to the SHUT_RD when a fin-like segment is encountered.
2) Minor change: I noted that code appears twice in different places and think it makes sense to put this into a self-contained function (dccp_enqueue()).
--- net/dccp/input.c | 22 +++++++++++++++------- 1 files changed, 15 insertions(+), 7 deletions(-)
net/dccp/input.c +15 -7
@@ -22,16 +22,27 @@/* rate-limit for syncs in reply to sequence-invalid packets; RFC 4340, 7.5.4 */ int sysctl_dccp_sync_ratelimit__read_mostly =HZ /8 ; -static void dccp_fin (struct sock *sk,struct sk_buff *skb) +static void dccp_enqueue_skb (struct sock *sk,struct sk_buff *skb) { - sk->sk_shutdown |=RCV_SHUTDOWN ; -sock_set_flag (sk,SOCK_DONE );__skb_pull (skb,dccp_hdr (skb)->dccph_doff *4 );__skb_queue_tail (&sk->sk_receive_queue, skb);skb_set_owner_r (skb, sk); sk->sk_data_ready (sk,0 ); } +static void dccp_fin (struct sock *sk,struct sk_buff *skb) +{ +/* +* On receiving Close/CloseReq, both RD/WR shutdown are performed. +* RFC 4340, 8.3 says that we MAY send further Data/DataAcks after +* receiving the closing segment, but there is no guarantee that such +* data will be processed at all. +*/ + sk->sk_shutdown =SHUTDOWN_MASK ; +sock_set_flag (sk,SOCK_DONE ); +dccp_enqueue_skb (sk, skb); +} +static int dccp_rcv_close (struct sock *sk,struct sk_buff *skb) {int queued =0 ;
@@ -282,10 +293,7 @@ static int __dccp_rcv_established(struct sock *sk, struct sk_buff *skb,* - sk_shutdown = RCV_SHUTDOWN, use Code 1, "Not Listening" * - sk_receive_queue is full, use Code 2, "Receive Buffer" */ -__skb_pull (skb, dh->dccph_doff *4 ); -__skb_queue_tail (&sk->sk_receive_queue, skb); -skb_set_owner_r (skb, sk); - sk->sk_data_ready (sk,0 ); +dccp_enqueue_skb (sk, skb);return 0 ;case DCCP_PKT_ACK : goto discard;
Signature · 1 line
1.5.3.4
PATCH 2/12 : Shift the retransmit timer for active-close into output.c
From: Gerrit Renker <[email protected]>
When performing active close, RFC 4340, 8.3. requires to retransmit the Close/CloseReq with a backoff-retransmit timer starting at intially 2 RTTs.
This patch shifts the existing code for active-close retransmit timer into output.c, so that the retransmit timer is started when the first Close/CloseReq is sent. Previously, the timer was started when, after releasing the socket in dccp_close(), the actively-closing side had not yet reached the CLOSED/TIMEWAIT state.
The patch further reduces the initial timeout from 3 seconds to the required 2 RTTs, where - in absence of a known RTT - the fallback value specified in RFC 4340, 3.4 is used.
--- net/dccp/output.c | 13 ++++++++++++- net/dccp/proto.c | 18 ------------------ 2 files changed, 12 insertions(+), 19 deletions(-)
net/dccp/output.c +12 -1
@@ -574,7 +574,18 @@ void dccp_send_close(struct sock *sk, const int active)dccp_write_xmit (sk,1 );dccp_skb_entail (sk, skb);dccp_transmit_skb (sk,skb_clone (skb, prio)); -/* FIXME do we need a retransmit timer here? */ +/* +* Retransmission timer for active-close: RFC 4340, 8.3 requires +* to retransmit the Close/CloseReq until the CLOSING/CLOSEREQ +* state can be left. The initial timeout is 2 RTTs. +* Since RTT measurement is done by the CCIDs, there is no easy +* way to get an RTT sample. The fallback RTT from RFC 4340, 3.4 +* is too low (200ms); we use a high value to avoid unnecessary +* retransmissions when the link RTT is > 0.2 seconds. +* FIXME: Let main module sample RTTs and use that instead. +*/ +inet_csk_reset_xmit_timer (sk,ICSK_TIME_RETRANS , +DCCP_TIMEOUT_INIT ,DCCP_RTO_MAX ); }else dccp_transmit_skb (sk, skb); }
net/dccp/proto.c +0 -18
@@ -996,24 +996,6 @@ adjudge_to_death:if (state !=DCCP_CLOSED && sk->sk_state =DCCP_CLOSED ) goto out; -/* -* The last release_sock may have processed the CLOSE or RESET -* packet moving sock to CLOSED state, if not we have to fire -* the CLOSE/CLOSEREQ retransmission timer, see "8.3. Termination" -* in draft-ietf-dccp-spec-11. -acme -*/ -if (sk->sk_state =DCCP_CLOSING ) { -/* FIXME: should start at 2 * RTT */ -/* Timer for repeating the CLOSE/CLOSEREQ until an answer. */ -inet_csk_reset_xmit_timer (sk,ICSK_TIME_RETRANS , -inet_csk (sk)->icsk_rto, -DCCP_RTO_MAX ); -#if 0 -/* Yeah, we should use sk->sk_prot->orphan_count, etc */ -dccp_set_state (sk,DCCP_CLOSED ); -#endif - } -if (sk->sk_state =DCCP_CLOSED )inet_csk_destroy_sock (sk);
Signature · 1 line
1.5.3.4
PATCH 3/12 : Use maximum-RTO backoff from DCCP spec
From: Gerrit Renker <[email protected]>
This removes another Fixme, using the TCP maximum RTO rather than the value specified by the DCCP specification. Across the sections in RFC 4340, 64 seconds is consistently suggested as maximum RTO backoff value; and this is the value which is now used.
I have checked both termination cases for retransmissions of Close/CloseReq:
with the default value 15 of `retries2', and an initial icsk_retransmit = 0, it takes about 614 seconds to declare a non-responding peer as dead, after which the final terminating Reset is sent. With the TCP maximum RTO value of 120 seconds it takes (as might be expected) almost twice as long, about 23 minutes.
--- net/dccp/dccp.h | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-)
net/dccp/dccp.h +8 -1
@@ -72,7 +72,14 @@ extern void dccp_time_wait(struct sock *sk, int state, int timeo);/* RFC 1122, 4.2.3.1 initial RTO value */ #define DCCP_TIMEOUT_INIT ((unsigned)(3 * HZ)) -#define DCCP_RTO_MAX ((unsigned)(120 * HZ))/* FIXME: using TCP value */ +/* +* The maximum back-off value for retransmissions. This is needed for +* - retransmitting client-Requests (sec. 8.1.1), +* - retransmitting Close/CloseReq when closing (sec. 8.3), +* - feature-negotiation retransmission (sec. 6.6.3), +* - Acks in client-PARTOPEN state (sec. 8.1.5). +*/ +#define DCCP_RTO_MAX ((unsigned)(64 * HZ))/* * RTT sampling: sanity bounds and fallback RTT value from RFC 4340, section 3.4
Signature · 1 line
1.5.3.4
PATCH 4/12 : Support for server holding timewait state
From: Gerrit Renker <[email protected]>
This adds a socket option and signalling support for the case where the server holds timewait state on closing the connection, as described in RFC 4340, 8.3.
Since holding timewait state at the server is the non-usual case, it is enabled via a socket option. Documentation for this socket option has been added.
The setsockopt statement has been made resilient against different possible cases of expressing boolean `true' values using a suggestion by Ian McDonald.
--- Documentation/networking/dccp.txt | 6 ++++++ include/linux/dccp.h | 3 +++ net/dccp/output.c | 6 ++++-- net/dccp/proto.c | 13 ++++++++++++- 4 files changed, 25 insertions(+), 3 deletions(-)
Documentation/networking/dccp.txt +6 -0
@@ -57,6 +57,12 @@ can be set before calling bind(). DCCP_SOCKOPT_GET_CUR_MPS is read-only and retrieves the current maximum packet size (application payload size) in bytes, see RFC 4340, section 14. +DCCP_SOCKOPT_SERVER_TIMEWAIT enables the server (listening socket) to hold +timewait state when closing the connection (RFC 4340, 8.3). The usual case is +that the closing server sends a CloseReq, whereupon the client holds timewait +state. When this boolean socket option is on, the server sends a Close instead +and will enter TIMEWAIT. This option must be set after accept() returns. + DCCP_SOCKOPT_SEND_CSCOV and DCCP_SOCKOPT_RECV_CSCOV are used for setting the partial checksum coverage (RFC 4340, sec. 9.2). The default is that checksums always cover the entire packet and that only fully covered application data is
include/linux/dccp.h +3 -0
@@ -205,6 +205,7 @@ struct dccp_so_feat {#define DCCP_SOCKOPT_CHANGE_L 3#define DCCP_SOCKOPT_CHANGE_R 4#define DCCP_SOCKOPT_GET_CUR_MPS 5 +#define DCCP_SOCKOPT_SERVER_TIMEWAIT 6#define DCCP_SOCKOPT_SEND_CSCOV 10#define DCCP_SOCKOPT_RECV_CSCOV 11#define DCCP_SOCKOPT_CCID_RX_INFO 128
@@ -492,6 +493,7 @@ struct dccp_ackvec;* @dccps_role - role of this sock, one of %dccp_role * @dccps_hc_rx_insert_options - receiver wants to add options when acking * @dccps_hc_tx_insert_options - sender wants to add options when sending +* @dccps_server_timewait - server holds timewait state on close (RFC 4340, 8.3) * @dccps_xmit_timer - timer for when CCID is not ready to send * @dccps_syn_rtt - RTT sample from Request/Response exchange (in usecs) */
@@ -528,6 +530,7 @@ struct dccp_sock { enum dccp_role dccps_role:2; __u8 dccps_hc_rx_insert_options:1; __u8 dccps_hc_tx_insert_options:1; + __u8 dccps_server_timewait:1;struct timer_list dccps_xmit_timer; };
net/dccp/output.c +4 -2
@@ -567,8 +567,10 @@ void dccp_send_close(struct sock *sk, const int active)/* Reserve space for headers and prepare control bits. */ skb_reserve (skb, sk->sk_prot->max_header); -DCCP_SKB_CB (skb)->dccpd_type = dp->dccps_role =DCCP_ROLE_CLIENT ? -DCCP_PKT_CLOSE :DCCP_PKT_CLOSEREQ ; +if (dp->dccps_role =DCCP_ROLE_SERVER && !dp->dccps_server_timewait) +DCCP_SKB_CB (skb)->dccpd_type =DCCP_PKT_CLOSEREQ ; +else +DCCP_SKB_CB (skb)->dccpd_type =DCCP_PKT_CLOSE ;if (active) {dccp_write_xmit (sk,1 );
net/dccp/proto.c +12 -1
@@ -551,6 +551,12 @@ static int do_dccp_setsockopt(struct sock *sk, int level, int optname, (struct dccp_so_feat __user *) optval);break ; +case DCCP_SOCKOPT_SERVER_TIMEWAIT : +if (dp->dccps_role !=DCCP_ROLE_SERVER ) + err = -EOPNOTSUPP ; +else + dp->dccps_server_timewait = (val !=0 ); +break ;case DCCP_SOCKOPT_SEND_CSCOV :/* sender side, RFC 4340, sec. 9.2 */ if (val <0 || val >15 ) err = -EINVAL ;
@@ -653,6 +659,10 @@ static int do_dccp_getsockopt(struct sock *sk, int level, int optname, val = dp->dccps_mss_cache; len =sizeof (val);break ; +case DCCP_SOCKOPT_SERVER_TIMEWAIT : + val = dp->dccps_server_timewait; + len =sizeof (val); +break ;case DCCP_SOCKOPT_SEND_CSCOV : val = dp->dccps_pcslen; len =sizeof (val);
@@ -918,7 +928,8 @@ static void dccp_terminate_connection(struct sock *sk)case DCCP_OPEN :dccp_send_close (sk,1 ); -if (dccp_sk (sk)->dccps_role =DCCP_ROLE_SERVER ) +if (dccp_sk (sk)->dccps_role =DCCP_ROLE_SERVER && + !dccp_sk (sk)->dccps_server_timewait) next_state =DCCP_ACTIVE_CLOSEREQ ;else next_state =DCCP_CLOSING ;
Signature · 1 line
1.5.3.4
PATCH 5/12 : Collapse repeated `len' statements into one
From: Gerrit Renker <[email protected]>
This replaces 4 individual assignments for `len' with a single one, placed where the control flow of those 4 leads to.
--- net/dccp/proto.c | 5 +---- 1 files changed, 1 insertions(+), 4 deletions(-)
net/dccp/proto.c +1 -4
@@ -657,19 +657,15 @@ static int do_dccp_getsockopt(struct sock *sk, int level, int optname, (__be32 __user *)optval, optlen);case DCCP_SOCKOPT_GET_CUR_MPS : val = dp->dccps_mss_cache; - len =sizeof (val);break ;case DCCP_SOCKOPT_SERVER_TIMEWAIT : val = dp->dccps_server_timewait; - len =sizeof (val);break ;case DCCP_SOCKOPT_SEND_CSCOV : val = dp->dccps_pcslen; - len =sizeof (val);break ;case DCCP_SOCKOPT_RECV_CSCOV : val = dp->dccps_pcrlen; - len =sizeof (val);break ; case 128 ... 191: return ccid_hc_rx_getsockopt(dp->dccps_hc_rx_ccid, sk, optname,
@@ -681,6 +677,7 @@ static int do_dccp_getsockopt(struct sock *sk, int level, int optname,return -ENOPROTOOPT ; } + len =sizeof (val);if (put_user (len, optlen) ||copy_to_user (optval, &val, len))return -EFAULT ;
Signature · 1 line
1.5.3.4
PATCH 6/12 : Allow to parse options on Request Sockets
From: Gerrit Renker <[email protected]>
The option parsing code currently only parses on full sk's. This causes a problem for options sent during the initial handshake (in particular timestamps and feature-negotiation options). Therefore, this patch extends the option parsing code with an additional argument for request_socks: if it is non-NULL, options are parsed on the request socket, otherwise the normal path (parsing on the sk) is used.
Subsequent patches, which implement feature negotiation during connection setup, make use of this facility.
--- include/linux/dccp.h | 5 +++-- net/dccp/input.c | 6 +++--- net/dccp/ipv4.c | 8 ++++---- net/dccp/ipv6.c | 8 ++++---- net/dccp/options.c | 34 +++++++++++++++++++++++----------- 5 files changed, 37 insertions(+), 24 deletions(-)
include/linux/dccp.h +3 -2
@@ -407,8 +407,6 @@ struct dccp_opt_pend {extern void dccp_minisock_init (struct dccp_minisock *dmsk); -extern int dccp_parse_options (struct sock *sk,struct sk_buff *skb); -struct dccp_request_sock {struct inet_request_sock dreq_inet_rsk;__u64 dreq_iss;
@@ -423,6 +421,9 @@ static inline struct dccp_request_sock *dccp_rsk(const struct request_sock *req)extern struct inet_timewait_death_row dccp_death_row; +extern int dccp_parse_options (struct sock *sk,struct dccp_request_sock *dreq, +struct sk_buff *skb); +struct dccp_options_received {u32 dccpor_ndp;/* only 24 bits */ u32 dccpor_timestamp;
net/dccp/input.c +3 -3
@@ -369,7 +369,7 @@ int dccp_rcv_established(struct sock *sk, struct sk_buff *skb,if (dccp_check_seqno (sk, skb)) goto discard; -if (dccp_parse_options (sk, skb)) +if (dccp_parse_options (sk,NULL , skb)) goto discard;if (DCCP_SKB_CB (skb)->dccpd_ack_seq !=DCCP_PKT_WITHOUT_ACK_SEQ )
@@ -427,7 +427,7 @@ static int dccp_rcv_request_sent_state_process(struct sock *sk, goto out_invalid_packet; } -if (dccp_parse_options (sk, skb)) +if (dccp_parse_options (sk,NULL , skb)) goto out_invalid_packet;/* Obtain usec RTT sample from SYN exchange (used by CCID 3) */
@@ -609,7 +609,7 @@ int dccp_rcv_state_process(struct sock *sk, struct sk_buff *skb,/* * Step 8: Process options and mark acknowledgeable */ -if (dccp_parse_options (sk, skb)) +if (dccp_parse_options (sk,NULL , skb)) goto discard;if (dcb->dccpd_ack_seq !=DCCP_PKT_WITHOUT_ACK_SEQ )
net/dccp/ipv4.c +4 -4
@@ -600,11 +600,12 @@ int dccp_v4_conn_request(struct sock *sk, struct sk_buff *skb)if (req =NULL ) goto drop; -if (dccp_parse_options (sk, skb)) - goto drop_and_free; -dccp_reqsk_init (req, skb); + dreq =dccp_rsk (req); +if (dccp_parse_options (sk, dreq, skb)) + goto drop_and_free; +if (security_inet_conn_request (sk, skb, req)) goto drop_and_free;
@@ -621,7 +622,6 @@ int dccp_v4_conn_request(struct sock *sk, struct sk_buff *skb)* In fact we defer setting S.GSR, S.SWL, S.SWH to * dccp_create_openreq_child. */ - dreq =dccp_rsk (req); dreq->dreq_isr = dcb->dccpd_seq; dreq->dreq_iss =dccp_v4_init_sequence (skb); dreq->dreq_service = service;
net/dccp/ipv6.c +4 -4
@@ -415,11 +415,12 @@ static int dccp_v6_conn_request(struct sock *sk, struct sk_buff *skb)if (req =NULL ) goto drop; -if (dccp_parse_options (sk, skb)) - goto drop_and_free; -dccp_reqsk_init (req, skb); + dreq =dccp_rsk (req); +if (dccp_parse_options (sk, dreq, skb)) + goto drop_and_free; +if (security_inet_conn_request (sk, skb, req)) goto drop_and_free;
@@ -449,7 +450,6 @@ static int dccp_v6_conn_request(struct sock *sk, struct sk_buff *skb)* In fact we defer setting S.GSR, S.SWL, S.SWH to * dccp_create_openreq_child. */ - dreq =dccp_rsk (req); dreq->dreq_isr = dcb->dccpd_seq; dreq->dreq_iss =dccp_v6_init_sequence (skb); dreq->dreq_service = service;
net/dccp/options.c +23 -11
@@ -46,7 +46,13 @@ static u32 dccp_decode_value_var(const unsigned char *bf, const u8 len)return value; } -int dccp_parse_options (struct sock *sk,struct sk_buff *skb) +/** +* dccp_parse_options - Parse DCCP options present in @skb +* @sk: client|server|listening dccp socket (when @dreq != NULL) +* @dreq: request socket to use during connection setup, or NULL +*/ +int dccp_parse_options (struct sock *sk,struct dccp_request_sock *dreq, +struct sk_buff *skb) {struct dccp_sock *dp =dccp_sk (sk);const struct dccp_hdr *dh =dccp_hdr (skb);
@@ -92,6 +98,20 @@ int dccp_parse_options(struct sock *sk, struct sk_buff *skb) goto out_invalid_option; } +/* +* CCID-Specific Options (from RFC 4340, sec. 10.3): +* +* Option numbers 128 through 191 are for options sent from the +* HC-Sender to the HC-Receiver; option numbers 192 through 255 +* are for options sent from the HC-Receiver to the HC-Sender. +* +* CCID-specific options are ignored during connection setup, as +* negotiation may still be in progress (see RFC 4340, 10.3). +* +*/ +if (dreq !=NULL && opt >=128 ) + goto ignore_option; +switch (opt) {case DCCPO_PADDING :break ;
@@ -150,6 +170,7 @@ int dccp_parse_options(struct sock *sk, struct sk_buff *skb) opt_val =get_unaligned ((__be32 *)value); opt_recv->dccpor_timestamp =ntohl (opt_val); +/* FIXME: if dreq != NULL, don't store this on listening socket */ dp->dccps_timestamp_echo = opt_recv->dccpor_timestamp; dp->dccps_timestamp_time =ktime_get_real ();
@@ -213,15 +234,6 @@ int dccp_parse_options(struct sock *sk, struct sk_buff *skb)dccp_pr_debug ("%s rx opt: ELAPSED_TIME=%d\n" ,dccp_role (sk), elapsed_time);break ; -/* -* From RFC 4340, sec. 10.3: -* -* Option numbers 128 through 191 are for -* options sent from the HC-Sender to the -* HC-Receiver; option numbers 192 through 255 -* are for options sent from the HC-Receiver to -* the HC-Sender. -*/ case 128 ... 191: {const u16 idx = value - options;
@@ -245,7 +257,7 @@ int dccp_parse_options(struct sock *sk, struct sk_buff *skb) "implemented, ignoring", sk, opt, len);break ; } - +ignore_option:if (opt !=DCCPO_MANDATORY ) mandatory =0 ; }
Signature · 1 line
1.5.3.4
PATCH 7/12 : Add (missing) option parsing to request_sock processing
From: Gerrit Renker <[email protected]>
This adds option-parsing code to processing of Acks in the listening state on request_socks on the server, serving two purposes
(i) resolves a FIXME (removed);
(ii) paves the way for feature-negotiation during connection-setup.
There is an intended subtlety here with regard to dccp_check_req:
Parsing options happens only after testing whether the received packet is a retransmitted Request. Otherwise, if the Request contained (a possibly large number of) feature-negotiation options, recomputing state would have to happen each time a retransmitted Request arrives, which opens the door to an easy DoS attack. Since in a genuine retransmission the options should not be different from the original, reusing the already computed state seems better.
The other point is - if there are timestamp options on the Request, they will not be answered; which means that in the presence of retransmission (likely due to loss and/or other problems), the use of Request/Response RTT sampling is suspended, so that startup problems here do not propagate.
--- net/dccp/minisocks.c | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-)
net/dccp/minisocks.c +6 -6
@@ -200,10 +200,10 @@ struct sock *dccp_check_req(struct sock *sk, struct sk_buff *skb, struct request_sock **prev) {struct sock *child =NULL ; +struct dccp_request_sock *dreq =dccp_rsk (req);/* Check for retransmitted REQUEST */ if (dccp_hdr (skb)->dccph_type =DCCP_PKT_REQUEST ) { -struct dccp_request_sock *dreq =dccp_rsk (req);if (after48 (DCCP_SKB_CB (skb)->dccpd_seq, dreq->dreq_isr)) {dccp_pr_debug ("Retransmitted REQUEST\n" );
@@ -227,22 +227,22 @@ struct sock *dccp_check_req(struct sock *sk, struct sk_buff *skb, goto drop;/* Invalid ACK */ -if (DCCP_SKB_CB (skb)->dccpd_ack_seq !=dccp_rsk (req)->dreq_iss) { +if (DCCP_SKB_CB (skb)->dccpd_ack_seq != dreq->dreq_iss) {dccp_pr_debug ("Invalid ACK number: ack_seq=%llu, " "dreq_iss=%llu\n" , (unsigned long long )DCCP_SKB_CB (skb)->dccpd_ack_seq, - (unsigned long long ) -dccp_rsk (req)->dreq_iss); + (unsigned long long ) dreq->dreq_iss); goto drop; } +if (dccp_parse_options (sk, dreq, skb)) + goto drop; + child =inet_csk (sk)->icsk_af_ops->syn_recv_sock (sk, skb, req,NULL );if (child =NULL ) goto listen_overflow; -/* FIXME: deal with options */ -inet_csk_reqsk_queue_unlink (sk, req, prev);inet_csk_reqsk_queue_removed (sk, req);inet_csk_reqsk_queue_add (sk, req, child);
Signature · 1 line
1.5.3.4
PATCH 8/12 : Handle timestamps on Request/Response exchange separately
From: Gerrit Renker <[email protected]>
In DCCP, timestamps can occur on packets anytime, CCID3 uses a timestamp(/echo) on the Request/Response exchange. This patch addresses the following situation:
* timestamps are recorded on the listening socket;
* Responses are sent from dccp_request_sockets;
* suppose two connections reach the listening socket with very small time in between:
* the first timestamp value gets overwritten by the second connection request.
This is not really good, so this patch separates timestamps into
* those which are received by the server during the initial handshake (on dccp_request_sock);
* those which are received by the client or the client after connection establishment.
As before, a timestamp of 0 is regarded as indicating that no (meaningful) timestamp has been received (in addition, a warning message is printed if hosts send 0-valued timestamps).
The timestamp-echoing now works as follows:
* when a timestamp is present on the initial Request, it is placed into dreq, due to the call to dccp_parse_options in dccp_v{4,6}_conn_request;
* when a timestamp is present on the Ack leading from RESPOND => OPEN, it is copied over from the request_sock into the child cocket in dccp_create_openreq_child;
* timestamps received on an (established) dccp_sock are treated as before.
Since Elapsed Time is measured in hundredths of milliseconds (13.2), the new dccp_timestamp() function is used, as it is expected that the time between receiving the timestamp and sending the timestamp echo will be very small against the wrap-around time. As a byproduct, this allows smaller timestamping-time fields.
Furthermore, inserting the Timestamp Echo option has been taken out of the block starting with '!dccp_packet_without_ack()', since Timestamp Echo can be carried on any packet (5.8 and 13.3).
--- include/linux/dccp.h | 16 ++++++++++++- net/dccp/minisocks.c | 21 +++++++++++------- net/dccp/options.c | 56 ++++++++++++++++++++++++++++++++----------------- 3 files changed, 63 insertions(+), 30 deletions(-)
include/linux/dccp.h +14 -2
@@ -407,11 +407,23 @@ struct dccp_opt_pend {extern void dccp_minisock_init (struct dccp_minisock *dmsk); +/** +* struct dccp_request_sock - represent DCCP-specific connection request +* @dreq_inet_rsk: structure inherited from +* @dreq_iss: initial sequence number sent on the Response (RFC 4340, 7.1) +* @dreq_isr: initial sequence number received on the Request +* @dreq_service: service code present on the Request (there is just one) +* The following two fields are analogous to the ones in dccp_sock: +* @dreq_timestamp_echo: last received timestamp to echo (13.1) +* @dreq_timestamp_echo: the time of receiving the last @dreq_timestamp_echo +*/ struct dccp_request_sock {struct inet_request_sock dreq_inet_rsk;__u64 dreq_iss;__u64 dreq_isr;__be32 dreq_service; +__u32 dreq_timestamp_echo; +__u32 dreq_timestamp_time; };static inline struct dccp_request_sock *dccp_rsk (const struct request_sock *req)
@@ -477,8 +489,8 @@ struct dccp_ackvec;* @dccps_gar - greatest valid ack number received on a non-Sync; initialized to %dccps_iss * @dccps_service - first (passive sock) or unique (active sock) service code * @dccps_service_list - second .. last service code on passive socket -* @dccps_timestamp_time - time of latest TIMESTAMP option * @dccps_timestamp_echo - latest timestamp received on a TIMESTAMP option +* @dccps_timestamp_time - time of receiving latest @dccps_timestamp_echo * @dccps_l_ack_ratio - feature-local Ack Ratio * @dccps_r_ack_ratio - feature-remote Ack Ratio * @dccps_pcslen - sender partial checksum coverage (via sockopt)
@@ -514,8 +526,8 @@ struct dccp_sock {__u64 dccps_gar;__be32 dccps_service;struct dccp_service_list *dccps_service_list; -ktime_t dccps_timestamp_time;__u32 dccps_timestamp_echo; +__u32 dccps_timestamp_time;__u16 dccps_l_ack_ratio;__u16 dccps_r_ack_ratio;__u16 dccps_pcslen;
net/dccp/minisocks.c +13 -8
@@ -117,11 +117,13 @@ struct sock *dccp_create_openreq_child(struct sock *sk,struct dccp_sock *newdp =dccp_sk (newsk);struct dccp_minisock *newdmsk =dccp_msk (newsk); - newdp->dccps_role =DCCP_ROLE_SERVER ; - newdp->dccps_hc_rx_ackvec =NULL ; - newdp->dccps_service_list =NULL ; - newdp->dccps_service = dreq->dreq_service; - newicsk->icsk_rto =DCCP_TIMEOUT_INIT ; + newdp->dccps_role =DCCP_ROLE_SERVER ; + newdp->dccps_hc_rx_ackvec =NULL ; + newdp->dccps_service_list =NULL ; + newdp->dccps_service = dreq->dreq_service; + newdp->dccps_timestamp_echo = dreq->dreq_timestamp_echo; + newdp->dccps_timestamp_time = dreq->dreq_timestamp_time; + newicsk->icsk_rto =DCCP_TIMEOUT_INIT ;if (dccp_feat_clone (sk, newsk)) goto out_free;
@@ -303,9 +305,12 @@ EXPORT_SYMBOL_GPL(dccp_reqsk_send_ack);void dccp_reqsk_init (struct request_sock *req,struct sk_buff *skb) { -inet_rsk (req)->rmt_port =dccp_hdr (skb)->dccph_sport; -inet_rsk (req)->acked =0 ; - req->rcv_wnd = sysctl_dccp_feat_sequence_window; +struct dccp_request_sock *dreq =dccp_rsk (req); + +inet_rsk (req)->rmt_port =dccp_hdr (skb)->dccph_sport; +inet_rsk (req)->acked =0 ; + req->rcv_wnd = sysctl_dccp_feat_sequence_window; + dreq->dreq_timestamp_echo =0 ; }EXPORT_SYMBOL_GPL (dccp_reqsk_init);
net/dccp/options.c +35 -20
98 lines not on this page · raw message
Signature · 1 line
1.5.3.4
PATCH 9/12 : Support inserting options during the 3-way handshake
From: Gerrit Renker <[email protected]>
This provides a separate routine to insert options during the initial handshake. The main purpose is to conduct feature negotiation, for the moment the only user is the timestamp echo needed for the (CCID3) handshake RTT sample.
Padding of options has been put into a small separate routine, to be shared among the two functions. This could also be used as a generic routine to finish inserting options.
Also removed an `XXX' comment since its content was obvious.
--- net/dccp/dccp.h | 1 + net/dccp/options.c | 32 ++++++++++++++++++++++---------- net/dccp/output.c | 2 +- 3 files changed, 24 insertions(+), 11 deletions(-)
net/dccp/dccp.h +1 -0
@@ -428,6 +428,7 @@ static inline int dccp_ack_pending(const struct sock *sk) }extern int dccp_insert_options (struct sock *sk,struct sk_buff *skb); +extern int dccp_insert_options_rsk (struct dccp_request_sock *,struct sk_buff *);extern int dccp_insert_option_elapsed_time (struct sock *sk,struct sk_buff *skb,u32 elapsed_time);
net/dccp/options.c +22 -10
@@ -537,6 +537,18 @@ static int dccp_insert_options_feat(struct sock *sk, struct sk_buff *skb)return 0 ; } +/* The length of all options needs to be a multiple of 4 (5.8) */ +static void dccp_insert_option_padding (struct sk_buff *skb) +{ +int padding =DCCP_SKB_CB (skb)->dccpd_opt_len %4 ; + +if (padding !=0 ) { + padding =4 - padding; +memset (skb_push (skb, padding),0 , padding); +DCCP_SKB_CB (skb)->dccpd_opt_len += padding; + } +} +int dccp_insert_options (struct sock *sk,struct sk_buff *skb) {struct dccp_sock *dp =dccp_sk (sk);
@@ -580,18 +592,18 @@ int dccp_insert_options(struct sock *sk, struct sk_buff *skb) dccp_insert_option_timestamp_echo(dp, NULL, skb))return -1 ; -/* XXX: insert other options when appropriate */ +dccp_insert_option_padding (skb); +return 0 ; +} -if (DCCP_SKB_CB (skb)->dccpd_opt_len !=0 ) { -/* The length of all options has to be a multiple of 4 */ -int padding =DCCP_SKB_CB (skb)->dccpd_opt_len %4 ; +int dccp_insert_options_rsk (struct dccp_request_sock *dreq,struct sk_buff *skb) +{ +DCCP_SKB_CB (skb)->dccpd_opt_len =0 ; -if (padding !=0 ) { - padding =4 - padding; -memset (skb_push (skb, padding),0 , padding); -DCCP_SKB_CB (skb)->dccpd_opt_len += padding; - } - } +if (dreq->dreq_timestamp_echo !=0 && +dccp_insert_option_timestamp_echo (NULL , dreq, skb)) +return -1 ; +dccp_insert_option_padding (skb);return 0 ; }
net/dccp/output.c +1 -1
@@ -303,7 +303,7 @@ struct sk_buff *dccp_make_response(struct sock *sk, struct dst_entry *dst,DCCP_SKB_CB (skb)->dccpd_type =DCCP_PKT_RESPONSE ;DCCP_SKB_CB (skb)->dccpd_seq = dreq->dreq_iss; -if (dccp_insert_options (sk, skb)) { +if (dccp_insert_options_rsk (dreq, skb)) {kfree_skb (skb);return NULL ; }
Signature · 1 line
1.5.3.4
PATCH 10/12 : Remove unused and redundant validation functions
From: Gerrit Renker <[email protected]>
This removes two inlines which were both called in a single function only:
1) dccp_feat_change() is always called with either DCCPO_CHANGE_L or DCCPO_CHANGE_R as argument
* from dccp_set_socktopt_change() via do_dccp_setsockopt() with DCCP_SOCKOPT_CHANGE_R/L
* from __dccp_feat_init() via dccp_feat_init() also with DCCP_SOCKOPT_CHANGE_R/L.
Hence the dccp_feat_is_valid_type() is completely unnecessary and always returns true.
2) Due to (1), the length test reduces to 'len >= 4', which in turn makes dccp_feat_is_valid_length() unnecessary.
Furthermore, the inline function dccp_feat_is_reserved() was unfolded, since only called in a single place.
--- net/dccp/feat.c | 12 ++++-------- net/dccp/feat.h | 26 -------------------------- 2 files changed, 4 insertions(+), 34 deletions(-)
net/dccp/feat.c +4 -8
@@ -24,11 +24,7 @@ int dccp_feat_change(struct dccp_minisock *dmsk, u8 type, u8 feature,dccp_feat_debug (type, feature, *val); -if (!dccp_feat_is_valid_type (type)) { -DCCP_WARN ("option type %d invalid in negotiation\n" , type); -return 1 ; - } -if (!dccp_feat_is_valid_length (type, feature, len)) { +if (len >3 ) {DCCP_WARN ("invalid length %d\n" , len);return 1 ; }
@@ -637,12 +633,12 @@ const char *dccp_feat_name(const u8 feat) [DCCPF_MIN_CSUM_COVER] = "Min. Csum Coverage", [DCCPF_DATA_CHECKSUM] = "Send Data Checksum", }; +if (feat >DCCPF_DATA_CHECKSUM && feat <DCCPF_MIN_CCID_SPECIFIC ) +return feature_names[DCCPF_RESERVED ]; +if (feat >=DCCPF_MIN_CCID_SPECIFIC )return "CCID-specific" ; -if (dccp_feat_is_reserved (feat)) -return feature_names[DCCPF_RESERVED ]; -return feature_names[feat]; }
net/dccp/feat.h +0 -26
@@ -14,32 +14,6 @@#include <linux/types.h> #include "dccp.h" -static inline int dccp_feat_is_valid_length (u8 type,u8 feature,u8 len) -{ -/* sec. 6.1: Confirm has at least length 3, -* sec. 6.2: Change has at least length 4 */ -if (len <3 ) -return 1 ; -if (len <4 && (type =DCCPO_CHANGE_L || type =DCCPO_CHANGE_R )) -return 1 ; -/* XXX: add per-feature length validation (sec. 6.6.8) */ -return 0 ; -} - -static inline int dccp_feat_is_reserved (const u8 feat) -{ -return (feat >DCCPF_DATA_CHECKSUM && - feat <DCCPF_MIN_CCID_SPECIFIC ) || - feat =DCCPF_RESERVED ; -} - -/* feature negotiation knows only these four option types (RFC 4340, sec. 6) */ -static inline int dccp_feat_is_valid_type (const u8 optnum) -{ -return optnum >=DCCPO_CHANGE_L && optnum <=DCCPO_CONFIRM_R ; - -} -#ifdef CONFIG_IP_DCCP_DEBUG extern const char *dccp_feat_typename (const u8 type);extern const char *dccp_feat_name (const u8 feat);
Signature · 1 line
1.5.3.4
PATCH 11/12 : Make code assumptions explicit
From: Gerrit Renker <[email protected]>
This removes several `XXX' references which indicate a missing support for non-1-byte feature values: this is unnecessary, as all currently known (standardised) SP feature values are 1-byte quantities.
--- net/dccp/feat.c | 17 ++++++++++------- 1 files changed, 10 insertions(+), 7 deletions(-)
net/dccp/feat.c +10 -7
@@ -4,10 +4,16 @@* An implementation of the DCCP protocol * Andrea Bittau <[email protected]> * -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version -* 2 of the License, or (at your option) any later version. +* ASSUMPTIONS +* ----------- +* o All currently known SP features have 1-byte quantities. If in the future +* extensions of RFCs 4340..42 define features with item lengths larger than +* one byte, a feature-specific extension of the code will be required. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version +* 2 of the License, or (at your option) any later version. */ #include <linux/module.h>
@@ -95,7 +101,6 @@ static int dccp_feat_update_ccid(struct sock *sk, u8 type, u8 new_ccid_nr)return 0 ; } -/* XXX taking only u8 vals */ static int dccp_feat_update (struct sock *sk,u8 type,u8 feat,u8 val) {dccp_feat_debug (type, feat, val);
@@ -140,7 +145,6 @@ static int dccp_feat_reconcile(struct sock *sk, struct dccp_opt_pend *opt,/* FIXME sanity check vals */ /* Are values in any order? XXX Lame "algorithm" here */ -/* XXX assume values are 1 byte */ for (i =0 ; i < slen; i++) {for (j =0 ; j < rlen; j++) {if (spref[i] = rpref[j]) {
@@ -175,7 +179,6 @@ static int dccp_feat_reconcile(struct sock *sk, struct dccp_opt_pend *opt, }/* need to put result and our preference list */ -/* XXX assume 1 byte vals */ rlen =1 + opt->dccpop_len; rpref =kmalloc (rlen,GFP_ATOMIC );if (rpref =NULL )
Signature · 1 line
1.5.3.4
PATCH 12/12 : Ignore feature negotiation on Data packets
From: Gerrit Renker <[email protected]>
This implements [RFC 4340, p. 32]: "any feature negotiation options received on DCCP-Data packets MUST be ignored".
Also added a FIXME for further processing, since the code currently (wrongly) classifies empty Confirm options as invalid - this needs to be resolved in a separate patch.
--- net/dccp/options.c | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-)
net/dccp/options.c +5 -1
@@ -132,6 +132,8 @@ int dccp_parse_options(struct sock *sk, struct dccp_request_sock *dreq,case DCCPO_CHANGE_L :/* fall through */ case DCCPO_CHANGE_R : +if (pkt_type =DCCP_PKT_DATA ) +break ;if (len <2 ) goto out_invalid_option; rc = dccp_feat_change_recv(sk, opt, *value, value + 1,
@@ -148,7 +150,9 @@ int dccp_parse_options(struct sock *sk, struct dccp_request_sock *dreq,case DCCPO_CONFIRM_L :/* fall through */ case DCCPO_CONFIRM_R : -if (len <2 ) +if (pkt_type =DCCP_PKT_DATA ) +break ; +if (len <2 )/* FIXME this disallows empty confirm */ goto out_invalid_option;if (dccp_feat_confirm_recv (sk, opt, *value, value +1 , len -1 ))
Signature · 1 line
1.5.3.4
David Miller
maintainerFrom: Arnaldo Carvalho de Melo <[email protected]>
Date: Thu, 13 Dec 2007 13:05:53 -0200
Quoted 3 lines
Please consider pulling from:
master.kernel.org:/pub/scm/linux/kernel/git/acme/net-2.6.25
Looks good, pulled and pushed back out to net-2.6.25
Thanks!