Skip to content

Commit 02fa460

Browse files
Gerrit Renkerdavem330
authored andcommitted
dccp: Increase the scope of variable-length htonl/ntohl functions
This extends the scope of two available functions, encode|decode_value_var, to work up to 6 (8) bytes, to match maximum requirements in the RFC. These functions are going to be used both by general option processing and feature negotiation code, hence declarations have been put into feat.h. Signed-off-by: Gerrit Renker <gerrit@erg.abdn.ac.uk> Acked-by: Ian McDonald <ian.mcdonald@jandi.co.nz> Acked-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 71c262a commit 02fa460

2 files changed

Lines changed: 28 additions & 7 deletions

File tree

‎net/dccp/feat.h‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,18 @@ extern int dccp_feat_clone(struct sock *oldsk, struct sock *newsk);
125125
extern int dccp_feat_clone_list(struct list_head const *, struct list_head *);
126126
extern int dccp_feat_init(struct sock *sk);
127127

128+
/*
129+
* Encoding variable-length options and their maximum length.
130+
*
131+
* This affects NN options (SP options are all u8) and other variable-length
132+
* options (see table 3 in RFC 4340). The limit is currently given the Sequence
133+
* Window NN value (sec. 7.5.2) and the NDP count (sec. 7.7) option, all other
134+
* options consume less than 6 bytes (timestamps are 4 bytes).
135+
* When updating this constant (e.g. due to new internet drafts / RFCs), make
136+
* sure that you also update all code which refers to it.
137+
*/
138+
#define DCCP_OPTVAL_MAXLEN 6
139+
140+
extern void dccp_encode_value_var(const u64 value, u8 *to, const u8 len);
141+
extern u64 dccp_decode_value_var(const u8 *bf, const u8 len);
128142
#endif /* _DCCP_FEAT_H */

‎net/dccp/options.c‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,20 @@ int sysctl_dccp_feat_tx_ccid = DCCPF_INITIAL_CCID;
2929
int sysctl_dccp_feat_send_ack_vector = DCCPF_INITIAL_SEND_ACK_VECTOR;
3030
int sysctl_dccp_feat_send_ndp_count = DCCPF_INITIAL_SEND_NDP_COUNT;
3131

32-
static u32 dccp_decode_value_var(const unsigned char *bf, const u8 len)
32+
u64 dccp_decode_value_var(const u8 *bf, const u8 len)
3333
{
34-
u32 value = 0;
34+
u64 value = 0;
3535

36+
if (len >= DCCP_OPTVAL_MAXLEN)
37+
value += ((u64)*bf++) << 40;
38+
if (len > 4)
39+
value += ((u64)*bf++) << 32;
3640
if (len > 3)
37-
value += *bf++ << 24;
41+
value += ((u64)*bf++) << 24;
3842
if (len > 2)
39-
value += *bf++ << 16;
43+
value += ((u64)*bf++) << 16;
4044
if (len > 1)
41-
value += *bf++ << 8;
45+
value += ((u64)*bf++) << 8;
4246
if (len > 0)
4347
value += *bf;
4448

@@ -298,9 +302,12 @@ int dccp_parse_options(struct sock *sk, struct dccp_request_sock *dreq,
298302

299303
EXPORT_SYMBOL_GPL(dccp_parse_options);
300304

301-
static void dccp_encode_value_var(const u32 value, unsigned char *to,
302-
const unsigned int len)
305+
void dccp_encode_value_var(const u64 value, u8 *to, const u8 len)
303306
{
307+
if (len >= DCCP_OPTVAL_MAXLEN)
308+
*to++ = (value & 0xFF0000000000ull) >> 40;
309+
if (len > 4)
310+
*to++ = (value & 0xFF00000000ull) >> 32;
304311
if (len > 3)
305312
*to++ = (value & 0xFF000000) >> 24;
306313
if (len > 2)

0 commit comments

Comments
 (0)