: Support for partial checksums (RFC 4340, sec. 9.2)
Subsystems (2)
PATCH 3/3 : Support for partial checksums (RFC 4340, sec. 9.2)
This patch does the following:
a) introduces variable-length checksums as specified in [RFC 4340, sec. 9.2]
b) provides necessary socket options and documentation as to how to use them
c) basic support and infrastructure for the Minimum Checksum Coverage feature [RFC 4340, sec. 9.2.1]: acceptability tests, user notification and user interface
In addition, it
(1) fixes two bugs in the DCCPv4 checksum computation:
* pseudo-header used checksum_len instead of skb->len
* incorrect checksum coverage calculation based on dccph_x
(2) removes dccp_v4_verify_checksum() since it reduplicates code of the checksum computation; code calling this function is updated accordingly.
(3) now uses skb_checksum(), which is safer than checksum_partial() if the sk_buff has is a non-linear buffer (has pages attached to it).
(4) fixes an outstanding TODO item:
* If P.CsCov is too large for the packet size, drop packet and return.
The code has been tested with applications, the latest version of tcpdump now comes with support for partial DCCP checksums.
------------------------------------------------------------------------------
Documentation/networking/dccp.txt | 16 +++++ include/linux/dccp.h | 7 ++ net/dccp/dccp.h | 29 ++++++++-- net/dccp/ipv4.c | 105 ++++++++++++++++++-------------------- net/dccp/ipv6.c | 74 +++++++++++++++++--------- net/dccp/output.c | 13 +--- net/dccp/proto.c | 26 +++++++-- 7 files changed, 173 insertions(+), 97 deletions(-)
------------------------------------------------------------------------------
Documentation/networking/dccp.txt +16 -0
@@ -47,6 +47,22 @@ the socket will fall back to 0 (which me is present). Connecting sockets set at most one service option; for listening sockets, multiple service codes can be specified. +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 +accepted by the receiver. Hence, when using this feature on the sender, it must +be enabled at the receiver, too with suitable choice of CsCov. + +DCCP_SOCKOPT_SEND_CSCOV sets the sender checksum coverage. Values in the + range 0..15 are acceptable. The default setting is 0 (full coverage), + values between 1..15 indicate partial coverage. +DCCP_SOCKOPT_SEND_CSCOV is for the receiver and has a different meaning: it + sets a threshold, where again values 0..15 are acceptable. The default + of 0 means that all packets with a partial coverage will be discarded. + Values in the range 1..15 indicate that packets with minimally such a + coverage value are also acceptable. The higher the number, the more + restrictive this setting (see [RFC 4340, sec. 9.2.1]). + Notes ==
include/linux/dccp.h +7 -0
@@ -183,6 +183,7 @@ enum {DCCPF_ACK_RATIO =5 ,DCCPF_SEND_ACK_VECTOR =6 ,DCCPF_SEND_NDP_COUNT =7 , +DCCPF_MIN_CSUM_COVER =8 ,/* 10-127 reserved */ DCCPF_MIN_CCID_SPECIFIC =128 , DCCPF_MAX_CCID_SPECIFIC = 255,
@@ -200,6 +201,8 @@ #define DCCP_SOCKOPT_PACKET_SIZE 1#define DCCP_SOCKOPT_SERVICE 2#define DCCP_SOCKOPT_CHANGE_L 3#define DCCP_SOCKOPT_CHANGE_R 4 +#define DCCP_SOCKOPT_SEND_CSCOV 10 +#define DCCP_SOCKOPT_RECV_CSCOV 11#define DCCP_SOCKOPT_CCID_RX_INFO 128#define DCCP_SOCKOPT_CCID_TX_INFO 192
@@ -450,6 +453,8 @@ struct dccp_ackvec;* @dccps_timestamp_echo - latest timestamp received on a TIMESTAMP option * @dccps_packet_size - Set thru setsockopt * @dccps_role - Role of this sock, one of %dccp_role +* @dccps_pcslen - sender partial checksum coverage (via sockopt) +* @dccps_pcrlen - receiver partial checksum coverage (via sockopt) * @dccps_ndp_count - number of Non Data Packets since last data packet * @dccps_hc_rx_ackvec - rx half connection ack vector * @dccps_xmit_timer - timer for when CCID is not ready to send
@@ -474,6 +479,8 @@ struct dccp_sock {__u32 dccps_packet_size;__u16 dccps_l_ack_ratio;__u16 dccps_r_ack_ratio; +__u16 dccps_pcslen; +__u16 dccps_pcrlen;unsigned long dccps_ndp_count;__u32 dccps_mss_cache;struct dccp_minisock dccps_minisock;
net/dccp/dccp.h +24 -5
@@ -129,6 +129,30 @@ #define DCCP_ADD_STATS_BH(field, val) \#define DCCP_ADD_STATS_USER (field, val) \ SNMP_ADD_STATS_USER(dccp_statistics, field, val) +/* +* Checksumming routines +*/ +static inline int dccp_csum_coverage (const struct sk_buff *skb) +{ +const struct dccp_hdr * dh =dccp_hdr (skb); + +if (dh->dccph_cscov =0 ) +return skb->len; +return (dh->dccph_doff + dh->dccph_cscov -1 ) *sizeof (u32); +} + +static inline void dccp_csum_outgoing (struct sk_buff *skb) +{ +int cov =dccp_csum_coverage (skb); + +if (cov >= skb->len) +dccp_hdr (skb)->dccph_cscov =0 ; + + skb->csum =skb_checksum (skb,0 , (cov > skb->len)? skb->len : cov,0 ); +} + +extern void dccp_v4_send_check (struct sock *sk,int len,struct sk_buff *skb); +extern int dccp_retransmit_skb (struct sock *sk,struct sk_buff *skb);extern void dccp_send_ack (struct sock *sk);
@@ -214,14 +238,9 @@ extern void dccp_shutdown(struct sockextern int inet_dccp_listen (struct socket *sock,int backlog);extern unsigned int dccp_poll (struct file *file,struct socket *sock,poll_table *wait); -extern void dccp_v4_send_check (struct sock *sk,int len, -struct sk_buff *skb);extern int dccp_v4_connect (struct sock *sk,struct sockaddr *uaddr,int addr_len); -extern int dccp_v4_checksum (const struct sk_buff *skb, -const __be32 saddr,const __be32 daddr); -extern int dccp_send_reset (struct sock *sk,enum dccp_reset_codes code);extern void dccp_send_close (struct sock *sk,const int active);extern int dccp_invalid_packet (struct sk_buff *skb);
net/dccp/ipv4.c +52 -53
162 lines not on this page · raw message
net/dccp/ipv6.c +47 -27
119 lines not on this page · raw message
net/dccp/output.c +5 -8
@@ -96,6 +96,7 @@ static int dccp_transmit_skb(struct sock dh->dccph_dport = inet->dport; dh->dccph_doff = (dccp_header_size + dcb->dccpd_opt_len) /4 ; dh->dccph_ccval = dcb->dccpd_ccval; + dh->dccph_cscov = dp->dccps_pcslen;/* XXX For now we're using only 48 bits sequence numbers */ dh->dccph_x =1 ;
@@ -115,7 +116,7 @@ static int dccp_transmit_skb(struct sockbreak ; } - icsk->icsk_af_ops->send_check (sk, skb->len, skb); + icsk->icsk_af_ops->send_check (sk,0 , skb);if (set_ack)dccp_event_ack_sent (sk);
@@ -329,7 +330,6 @@ struct sk_buff *dccp_make_response(strucskb_reserve (skb, sk->sk_prot->max_header); skb->dst =dst_clone (dst); - skb->csum =0 ; dreq =dccp_rsk (req);DCCP_SKB_CB (skb)->dccpd_type =DCCP_PKT_RESPONSE ;
@@ -352,6 +352,8 @@ struct sk_buff *dccp_make_response(strucdccp_hdr_set_ack (dccp_hdr_ack_bits (skb), dreq->dreq_isr);dccp_hdr_response (skb)->dccph_resp_service = dreq->dreq_service; +dccp_csum_outgoing (skb); +DCCP_INC_STATS (DCCP_MIB_OUTSEGS );return skb; }
@@ -376,7 +378,6 @@ static struct sk_buff *dccp_make_reset(sskb_reserve (skb, sk->sk_prot->max_header); skb->dst =dst_clone (dst); - skb->csum =0 ;dccp_inc_seqno (&dp->dccps_gss);
@@ -401,7 +402,7 @@ static struct sk_buff *dccp_make_reset(sdccp_hdr_set_ack (dccp_hdr_ack_bits (skb), dp->dccps_gsr);dccp_hdr_reset (skb)->dccph_reset_code = code; -inet_csk (sk)->icsk_af_ops->send_check (sk, skb->len, skb); +inet_csk (sk)->icsk_af_ops->send_check (sk,0 , skb);DCCP_INC_STATS (DCCP_MIB_OUTSEGS );return skb;
@@ -475,7 +476,6 @@ int dccp_connect(struct sock *sk)skb_reserve (skb, sk->sk_prot->max_header);DCCP_SKB_CB (skb)->dccpd_type =DCCP_PKT_REQUEST ; - skb->csum =0 ;dccp_skb_entail (sk, skb);dccp_transmit_skb (sk,skb_clone (skb,GFP_KERNEL ));
@@ -507,7 +507,6 @@ void dccp_send_ack(struct sock *sk)/* Reserve space for headers */ skb_reserve (skb, sk->sk_prot->max_header); - skb->csum =0 ;DCCP_SKB_CB (skb)->dccpd_type =DCCP_PKT_ACK ;dccp_transmit_skb (sk, skb); }
@@ -561,7 +560,6 @@ void dccp_send_sync(struct sock *sk, con/* Reserve space for headers and prepare control bits. */ skb_reserve (skb, sk->sk_prot->max_header); - skb->csum =0 ;DCCP_SKB_CB (skb)->dccpd_type = pkt_type;DCCP_SKB_CB (skb)->dccpd_seq = seq;
@@ -587,7 +585,6 @@ void dccp_send_close(struct sock *sk, co/* Reserve space for headers and prepare control bits. */ skb_reserve (skb, sk->sk_prot->max_header); - skb->csum =0 ;DCCP_SKB_CB (skb)->dccpd_type = dp->dccps_role =DCCP_ROLE_CLIENT ?DCCP_PKT_CLOSE :DCCP_PKT_CLOSEREQ ;
net/dccp/proto.c +22 -4
@@ -472,7 +472,6 @@ static int do_dccp_setsockopt(struct soccase DCCP_SOCKOPT_PACKET_SIZE : dp->dccps_packet_size = val;break ; -case DCCP_SOCKOPT_CHANGE_L :if (optlen !=sizeof (struct dccp_so_feat )) err = -EINVAL ;
@@ -481,7 +480,6 @@ static int do_dccp_setsockopt(struct soc (struct dccp_so_feat __user *) optval);break ; -case DCCP_SOCKOPT_CHANGE_R :if (optlen !=sizeof (struct dccp_so_feat )) err = -EINVAL ;
@@ -490,12 +488,26 @@ static int do_dccp_setsockopt(struct soc (struct dccp_so_feat __user *) optval);break ; - +case DCCP_SOCKOPT_SEND_CSCOV :/* sender side, RFC 4340, sec. 9.2 */ +if (val <0 || val >15 ) + err = -EINVAL ; +else + dp->dccps_pcslen = val; +break ; +case DCCP_SOCKOPT_RECV_CSCOV :/* receiver side, RFC 4340 sec. 9.2.1 */ +if (val <0 || val >15 ) + err = -EINVAL ; +else { + dp->dccps_pcrlen = val; +/* FIXME: add feature negotiation, +* ChangeL(MinimumChecksumCoverage, val) */ + } +break ;default : err = -ENOPROTOOPT ;break ; } - +release_sock (sk);return err; }
@@ -575,6 +587,12 @@ static int do_dccp_getsockopt(struct soccase DCCP_SOCKOPT_SERVICE :return dccp_getsockopt_service (sk, len, (__be32 __user *)optval, optlen); +case DCCP_SOCKOPT_SEND_CSCOV : + val = dp->dccps_pcslen; +break ; +case DCCP_SOCKOPT_RECV_CSCOV : + val = dp->dccps_pcrlen; +break ; case 128 ... 191:return ccid_hc_rx_getsockopt (dp->dccps_hc_rx_ccid, sk, optname, len, (u32 __user *)optval, optlen);