options.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. /*
  2. * net/dccp/options.c
  3. *
  4. * An implementation of the DCCP protocol
  5. * Copyright (c) 2005 Aristeu Sergio Rozanski Filho <aris@cathedrallabs.org>
  6. * Copyright (c) 2005 Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
  7. * Copyright (c) 2005 Ian McDonald <ian.mcdonald@jandi.co.nz>
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version
  12. * 2 of the License, or (at your option) any later version.
  13. */
  14. #include <linux/dccp.h>
  15. #include <linux/module.h>
  16. #include <linux/types.h>
  17. #include <asm/unaligned.h>
  18. #include <linux/kernel.h>
  19. #include <linux/skbuff.h>
  20. #include "ackvec.h"
  21. #include "ccid.h"
  22. #include "dccp.h"
  23. #include "feat.h"
  24. int sysctl_dccp_feat_sequence_window = DCCPF_INITIAL_SEQUENCE_WINDOW;
  25. int sysctl_dccp_feat_rx_ccid = DCCPF_INITIAL_CCID;
  26. int sysctl_dccp_feat_tx_ccid = DCCPF_INITIAL_CCID;
  27. int sysctl_dccp_feat_ack_ratio = DCCPF_INITIAL_ACK_RATIO;
  28. int sysctl_dccp_feat_send_ack_vector = DCCPF_INITIAL_SEND_ACK_VECTOR;
  29. int sysctl_dccp_feat_send_ndp_count = DCCPF_INITIAL_SEND_NDP_COUNT;
  30. static u32 dccp_decode_value_var(const unsigned char *bf, const u8 len)
  31. {
  32. u32 value = 0;
  33. if (len > 3)
  34. value += *bf++ << 24;
  35. if (len > 2)
  36. value += *bf++ << 16;
  37. if (len > 1)
  38. value += *bf++ << 8;
  39. if (len > 0)
  40. value += *bf;
  41. return value;
  42. }
  43. /**
  44. * dccp_parse_options - Parse DCCP options present in @skb
  45. * @sk: client|server|listening dccp socket (when @dreq != NULL)
  46. * @dreq: request socket to use during connection setup, or NULL
  47. */
  48. int dccp_parse_options(struct sock *sk, struct dccp_request_sock *dreq,
  49. struct sk_buff *skb)
  50. {
  51. struct dccp_sock *dp = dccp_sk(sk);
  52. const struct dccp_hdr *dh = dccp_hdr(skb);
  53. const u8 pkt_type = DCCP_SKB_CB(skb)->dccpd_type;
  54. u64 ackno = DCCP_SKB_CB(skb)->dccpd_ack_seq;
  55. unsigned char *options = (unsigned char *)dh + dccp_hdr_len(skb);
  56. unsigned char *opt_ptr = options;
  57. const unsigned char *opt_end = (unsigned char *)dh +
  58. (dh->dccph_doff * 4);
  59. struct dccp_options_received *opt_recv = &dp->dccps_options_received;
  60. unsigned char opt, len;
  61. unsigned char *value;
  62. u32 elapsed_time;
  63. __be32 opt_val;
  64. int rc;
  65. int mandatory = 0;
  66. memset(opt_recv, 0, sizeof(*opt_recv));
  67. opt = len = 0;
  68. while (opt_ptr != opt_end) {
  69. opt = *opt_ptr++;
  70. len = 0;
  71. value = NULL;
  72. /* Check if this isn't a single byte option */
  73. if (opt > DCCPO_MAX_RESERVED) {
  74. if (opt_ptr == opt_end)
  75. goto out_nonsensical_length;
  76. len = *opt_ptr++;
  77. if (len < 2)
  78. goto out_nonsensical_length;
  79. /*
  80. * Remove the type and len fields, leaving
  81. * just the value size
  82. */
  83. len -= 2;
  84. value = opt_ptr;
  85. opt_ptr += len;
  86. if (opt_ptr > opt_end)
  87. goto out_nonsensical_length;
  88. }
  89. /*
  90. * CCID-Specific Options (from RFC 4340, sec. 10.3):
  91. *
  92. * Option numbers 128 through 191 are for options sent from the
  93. * HC-Sender to the HC-Receiver; option numbers 192 through 255
  94. * are for options sent from the HC-Receiver to the HC-Sender.
  95. *
  96. * CCID-specific options are ignored during connection setup, as
  97. * negotiation may still be in progress (see RFC 4340, 10.3).
  98. * The same applies to Ack Vectors, as these depend on the CCID.
  99. *
  100. */
  101. if (dreq != NULL && (opt >= 128 ||
  102. opt == DCCPO_ACK_VECTOR_0 || opt == DCCPO_ACK_VECTOR_1))
  103. goto ignore_option;
  104. switch (opt) {
  105. case DCCPO_PADDING:
  106. break;
  107. case DCCPO_MANDATORY:
  108. if (mandatory)
  109. goto out_invalid_option;
  110. if (pkt_type != DCCP_PKT_DATA)
  111. mandatory = 1;
  112. break;
  113. case DCCPO_NDP_COUNT:
  114. if (len > 6)
  115. goto out_invalid_option;
  116. opt_recv->dccpor_ndp = dccp_decode_value_var(value, len);
  117. dccp_pr_debug("%s opt: NDP count=%llu\n", dccp_role(sk),
  118. (unsigned long long)opt_recv->dccpor_ndp);
  119. break;
  120. case DCCPO_CHANGE_L:
  121. /* fall through */
  122. case DCCPO_CHANGE_R:
  123. if (pkt_type == DCCP_PKT_DATA)
  124. break;
  125. if (len < 2)
  126. goto out_invalid_option;
  127. rc = dccp_feat_change_recv(sk, opt, *value, value + 1,
  128. len - 1);
  129. /*
  130. * When there is a change error, change_recv is
  131. * responsible for dealing with it. i.e. reply with an
  132. * empty confirm.
  133. * If the change was mandatory, then we need to die.
  134. */
  135. if (rc && mandatory)
  136. goto out_invalid_option;
  137. break;
  138. case DCCPO_CONFIRM_L:
  139. /* fall through */
  140. case DCCPO_CONFIRM_R:
  141. if (pkt_type == DCCP_PKT_DATA)
  142. break;
  143. if (len < 2) /* FIXME this disallows empty confirm */
  144. goto out_invalid_option;
  145. if (dccp_feat_confirm_recv(sk, opt, *value,
  146. value + 1, len - 1))
  147. goto out_invalid_option;
  148. break;
  149. case DCCPO_ACK_VECTOR_0:
  150. case DCCPO_ACK_VECTOR_1:
  151. if (dccp_packet_without_ack(skb)) /* RFC 4340, 11.4 */
  152. break;
  153. if (dccp_msk(sk)->dccpms_send_ack_vector &&
  154. dccp_ackvec_parse(sk, skb, &ackno, opt, value, len))
  155. goto out_invalid_option;
  156. break;
  157. case DCCPO_TIMESTAMP:
  158. if (len != 4)
  159. goto out_invalid_option;
  160. /*
  161. * RFC 4340 13.1: "The precise time corresponding to
  162. * Timestamp Value zero is not specified". We use
  163. * zero to indicate absence of a meaningful timestamp.
  164. */
  165. opt_val = get_unaligned((__be32 *)value);
  166. if (unlikely(opt_val == 0)) {
  167. DCCP_WARN("Timestamp with zero value\n");
  168. break;
  169. }
  170. if (dreq != NULL) {
  171. dreq->dreq_timestamp_echo = ntohl(opt_val);
  172. dreq->dreq_timestamp_time = dccp_timestamp();
  173. } else {
  174. opt_recv->dccpor_timestamp =
  175. dp->dccps_timestamp_echo = ntohl(opt_val);
  176. dp->dccps_timestamp_time = dccp_timestamp();
  177. }
  178. dccp_pr_debug("%s rx opt: TIMESTAMP=%u, ackno=%llu\n",
  179. dccp_role(sk), ntohl(opt_val),
  180. (unsigned long long)
  181. DCCP_SKB_CB(skb)->dccpd_ack_seq);
  182. break;
  183. case DCCPO_TIMESTAMP_ECHO:
  184. if (len != 4 && len != 6 && len != 8)
  185. goto out_invalid_option;
  186. opt_val = get_unaligned((__be32 *)value);
  187. opt_recv->dccpor_timestamp_echo = ntohl(opt_val);
  188. dccp_pr_debug("%s rx opt: TIMESTAMP_ECHO=%u, len=%d, "
  189. "ackno=%llu", dccp_role(sk),
  190. opt_recv->dccpor_timestamp_echo,
  191. len + 2,
  192. (unsigned long long)
  193. DCCP_SKB_CB(skb)->dccpd_ack_seq);
  194. value += 4;
  195. if (len == 4) { /* no elapsed time included */
  196. dccp_pr_debug_cat("\n");
  197. break;
  198. }
  199. if (len == 6) { /* 2-byte elapsed time */
  200. __be16 opt_val2 = get_unaligned((__be16 *)value);
  201. elapsed_time = ntohs(opt_val2);
  202. } else { /* 4-byte elapsed time */
  203. opt_val = get_unaligned((__be32 *)value);
  204. elapsed_time = ntohl(opt_val);
  205. }
  206. dccp_pr_debug_cat(", ELAPSED_TIME=%u\n", elapsed_time);
  207. /* Give precedence to the biggest ELAPSED_TIME */
  208. if (elapsed_time > opt_recv->dccpor_elapsed_time)
  209. opt_recv->dccpor_elapsed_time = elapsed_time;
  210. break;
  211. case DCCPO_ELAPSED_TIME:
  212. if (dccp_packet_without_ack(skb)) /* RFC 4340, 13.2 */
  213. break;
  214. if (len == 2) {
  215. __be16 opt_val2 = get_unaligned((__be16 *)value);
  216. elapsed_time = ntohs(opt_val2);
  217. } else if (len == 4) {
  218. opt_val = get_unaligned((__be32 *)value);
  219. elapsed_time = ntohl(opt_val);
  220. } else {
  221. goto out_invalid_option;
  222. }
  223. if (elapsed_time > opt_recv->dccpor_elapsed_time)
  224. opt_recv->dccpor_elapsed_time = elapsed_time;
  225. dccp_pr_debug("%s rx opt: ELAPSED_TIME=%d\n",
  226. dccp_role(sk), elapsed_time);
  227. break;
  228. case 128 ... 191: {
  229. const u16 idx = value - options;
  230. if (ccid_hc_rx_parse_options(dp->dccps_hc_rx_ccid, sk,
  231. opt, len, idx,
  232. value) != 0)
  233. goto out_invalid_option;
  234. }
  235. break;
  236. case 192 ... 255: {
  237. const u16 idx = value - options;
  238. if (ccid_hc_tx_parse_options(dp->dccps_hc_tx_ccid, sk,
  239. opt, len, idx,
  240. value) != 0)
  241. goto out_invalid_option;
  242. }
  243. break;
  244. default:
  245. DCCP_CRIT("DCCP(%p): option %d(len=%d) not "
  246. "implemented, ignoring", sk, opt, len);
  247. break;
  248. }
  249. ignore_option:
  250. if (opt != DCCPO_MANDATORY)
  251. mandatory = 0;
  252. }
  253. /* mandatory was the last byte in option list -> reset connection */
  254. if (mandatory)
  255. goto out_invalid_option;
  256. out_nonsensical_length:
  257. /* RFC 4340, 5.8: ignore option and all remaining option space */
  258. return 0;
  259. out_invalid_option:
  260. DCCP_INC_STATS_BH(DCCP_MIB_INVALIDOPT);
  261. DCCP_SKB_CB(skb)->dccpd_reset_code = DCCP_RESET_CODE_OPTION_ERROR;
  262. DCCP_WARN("DCCP(%p): invalid option %d, len=%d", sk, opt, len);
  263. DCCP_SKB_CB(skb)->dccpd_reset_data[0] = opt;
  264. DCCP_SKB_CB(skb)->dccpd_reset_data[1] = len > 0 ? value[0] : 0;
  265. DCCP_SKB_CB(skb)->dccpd_reset_data[2] = len > 1 ? value[1] : 0;
  266. return -1;
  267. }
  268. EXPORT_SYMBOL_GPL(dccp_parse_options);
  269. static void dccp_encode_value_var(const u32 value, unsigned char *to,
  270. const unsigned int len)
  271. {
  272. if (len > 3)
  273. *to++ = (value & 0xFF000000) >> 24;
  274. if (len > 2)
  275. *to++ = (value & 0xFF0000) >> 16;
  276. if (len > 1)
  277. *to++ = (value & 0xFF00) >> 8;
  278. if (len > 0)
  279. *to++ = (value & 0xFF);
  280. }
  281. static inline u8 dccp_ndp_len(const u64 ndp)
  282. {
  283. if (likely(ndp <= 0xFF))
  284. return 1;
  285. return likely(ndp <= USHORT_MAX) ? 2 : (ndp <= UINT_MAX ? 4 : 6);
  286. }
  287. int dccp_insert_option(struct sock *sk, struct sk_buff *skb,
  288. const unsigned char option,
  289. const void *value, const unsigned char len)
  290. {
  291. unsigned char *to;
  292. if (DCCP_SKB_CB(skb)->dccpd_opt_len + len + 2 > DCCP_MAX_OPT_LEN)
  293. return -1;
  294. DCCP_SKB_CB(skb)->dccpd_opt_len += len + 2;
  295. to = skb_push(skb, len + 2);
  296. *to++ = option;
  297. *to++ = len + 2;
  298. memcpy(to, value, len);
  299. return 0;
  300. }
  301. EXPORT_SYMBOL_GPL(dccp_insert_option);
  302. static int dccp_insert_option_ndp(struct sock *sk, struct sk_buff *skb)
  303. {
  304. struct dccp_sock *dp = dccp_sk(sk);
  305. u64 ndp = dp->dccps_ndp_count;
  306. if (dccp_non_data_packet(skb))
  307. ++dp->dccps_ndp_count;
  308. else
  309. dp->dccps_ndp_count = 0;
  310. if (ndp > 0) {
  311. unsigned char *ptr;
  312. const int ndp_len = dccp_ndp_len(ndp);
  313. const int len = ndp_len + 2;
  314. if (DCCP_SKB_CB(skb)->dccpd_opt_len + len > DCCP_MAX_OPT_LEN)
  315. return -1;
  316. DCCP_SKB_CB(skb)->dccpd_opt_len += len;
  317. ptr = skb_push(skb, len);
  318. *ptr++ = DCCPO_NDP_COUNT;
  319. *ptr++ = len;
  320. dccp_encode_value_var(ndp, ptr, ndp_len);
  321. }
  322. return 0;
  323. }
  324. static inline int dccp_elapsed_time_len(const u32 elapsed_time)
  325. {
  326. return elapsed_time == 0 ? 0 : elapsed_time <= 0xFFFF ? 2 : 4;
  327. }
  328. int dccp_insert_option_elapsed_time(struct sock *sk, struct sk_buff *skb,
  329. u32 elapsed_time)
  330. {
  331. const int elapsed_time_len = dccp_elapsed_time_len(elapsed_time);
  332. const int len = 2 + elapsed_time_len;
  333. unsigned char *to;
  334. if (elapsed_time_len == 0)
  335. return 0;
  336. if (DCCP_SKB_CB(skb)->dccpd_opt_len + len > DCCP_MAX_OPT_LEN)
  337. return -1;
  338. DCCP_SKB_CB(skb)->dccpd_opt_len += len;
  339. to = skb_push(skb, len);
  340. *to++ = DCCPO_ELAPSED_TIME;
  341. *to++ = len;
  342. if (elapsed_time_len == 2) {
  343. const __be16 var16 = htons((u16)elapsed_time);
  344. memcpy(to, &var16, 2);
  345. } else {
  346. const __be32 var32 = htonl(elapsed_time);
  347. memcpy(to, &var32, 4);
  348. }
  349. return 0;
  350. }
  351. EXPORT_SYMBOL_GPL(dccp_insert_option_elapsed_time);
  352. int dccp_insert_option_timestamp(struct sock *sk, struct sk_buff *skb)
  353. {
  354. __be32 now = htonl(dccp_timestamp());
  355. /* yes this will overflow but that is the point as we want a
  356. * 10 usec 32 bit timer which mean it wraps every 11.9 hours */
  357. return dccp_insert_option(sk, skb, DCCPO_TIMESTAMP, &now, sizeof(now));
  358. }
  359. EXPORT_SYMBOL_GPL(dccp_insert_option_timestamp);
  360. static int dccp_insert_option_timestamp_echo(struct dccp_sock *dp,
  361. struct dccp_request_sock *dreq,
  362. struct sk_buff *skb)
  363. {
  364. __be32 tstamp_echo;
  365. unsigned char *to;
  366. u32 elapsed_time, elapsed_time_len, len;
  367. if (dreq != NULL) {
  368. elapsed_time = dccp_timestamp() - dreq->dreq_timestamp_time;
  369. tstamp_echo = htonl(dreq->dreq_timestamp_echo);
  370. dreq->dreq_timestamp_echo = 0;
  371. } else {
  372. elapsed_time = dccp_timestamp() - dp->dccps_timestamp_time;
  373. tstamp_echo = htonl(dp->dccps_timestamp_echo);
  374. dp->dccps_timestamp_echo = 0;
  375. }
  376. elapsed_time_len = dccp_elapsed_time_len(elapsed_time);
  377. len = 6 + elapsed_time_len;
  378. if (DCCP_SKB_CB(skb)->dccpd_opt_len + len > DCCP_MAX_OPT_LEN)
  379. return -1;
  380. DCCP_SKB_CB(skb)->dccpd_opt_len += len;
  381. to = skb_push(skb, len);
  382. *to++ = DCCPO_TIMESTAMP_ECHO;
  383. *to++ = len;
  384. memcpy(to, &tstamp_echo, 4);
  385. to += 4;
  386. if (elapsed_time_len == 2) {
  387. const __be16 var16 = htons((u16)elapsed_time);
  388. memcpy(to, &var16, 2);
  389. } else if (elapsed_time_len == 4) {
  390. const __be32 var32 = htonl(elapsed_time);
  391. memcpy(to, &var32, 4);
  392. }
  393. return 0;
  394. }
  395. static int dccp_insert_feat_opt(struct sk_buff *skb, u8 type, u8 feat,
  396. u8 *val, u8 len)
  397. {
  398. u8 *to;
  399. if (DCCP_SKB_CB(skb)->dccpd_opt_len + len + 3 > DCCP_MAX_OPT_LEN) {
  400. DCCP_WARN("packet too small for feature %d option!\n", feat);
  401. return -1;
  402. }
  403. DCCP_SKB_CB(skb)->dccpd_opt_len += len + 3;
  404. to = skb_push(skb, len + 3);
  405. *to++ = type;
  406. *to++ = len + 3;
  407. *to++ = feat;
  408. if (len)
  409. memcpy(to, val, len);
  410. dccp_pr_debug("%s(%s (%d), ...), length %d\n",
  411. dccp_feat_typename(type),
  412. dccp_feat_name(feat), feat, len);
  413. return 0;
  414. }
  415. static int dccp_insert_options_feat(struct sock *sk, struct sk_buff *skb)
  416. {
  417. struct dccp_sock *dp = dccp_sk(sk);
  418. struct dccp_minisock *dmsk = dccp_msk(sk);
  419. struct dccp_opt_pend *opt, *next;
  420. int change = 0;
  421. /* confirm any options [NN opts] */
  422. list_for_each_entry_safe(opt, next, &dmsk->dccpms_conf, dccpop_node) {
  423. dccp_insert_feat_opt(skb, opt->dccpop_type,
  424. opt->dccpop_feat, opt->dccpop_val,
  425. opt->dccpop_len);
  426. /* fear empty confirms */
  427. if (opt->dccpop_val)
  428. kfree(opt->dccpop_val);
  429. kfree(opt);
  430. }
  431. INIT_LIST_HEAD(&dmsk->dccpms_conf);
  432. /* see which features we need to send */
  433. list_for_each_entry(opt, &dmsk->dccpms_pending, dccpop_node) {
  434. /* see if we need to send any confirm */
  435. if (opt->dccpop_sc) {
  436. dccp_insert_feat_opt(skb, opt->dccpop_type + 1,
  437. opt->dccpop_feat,
  438. opt->dccpop_sc->dccpoc_val,
  439. opt->dccpop_sc->dccpoc_len);
  440. BUG_ON(!opt->dccpop_sc->dccpoc_val);
  441. kfree(opt->dccpop_sc->dccpoc_val);
  442. kfree(opt->dccpop_sc);
  443. opt->dccpop_sc = NULL;
  444. }
  445. /* any option not confirmed, re-send it */
  446. if (!opt->dccpop_conf) {
  447. dccp_insert_feat_opt(skb, opt->dccpop_type,
  448. opt->dccpop_feat, opt->dccpop_val,
  449. opt->dccpop_len);
  450. change++;
  451. }
  452. }
  453. /* Retransmit timer.
  454. * If this is the master listening sock, we don't set a timer on it. It
  455. * should be fine because if the dude doesn't receive our RESPONSE
  456. * [which will contain the CHANGE] he will send another REQUEST which
  457. * will "retrnasmit" the change.
  458. */
  459. if (change && dp->dccps_role != DCCP_ROLE_LISTEN) {
  460. dccp_pr_debug("reset feat negotiation timer %p\n", sk);
  461. /* XXX don't reset the timer on re-transmissions. I.e. reset it
  462. * only when sending new stuff i guess. Currently the timer
  463. * never backs off because on re-transmission it just resets it!
  464. */
  465. inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS,
  466. inet_csk(sk)->icsk_rto, DCCP_RTO_MAX);
  467. }
  468. return 0;
  469. }
  470. /* The length of all options needs to be a multiple of 4 (5.8) */
  471. static void dccp_insert_option_padding(struct sk_buff *skb)
  472. {
  473. int padding = DCCP_SKB_CB(skb)->dccpd_opt_len % 4;
  474. if (padding != 0) {
  475. padding = 4 - padding;
  476. memset(skb_push(skb, padding), 0, padding);
  477. DCCP_SKB_CB(skb)->dccpd_opt_len += padding;
  478. }
  479. }
  480. int dccp_insert_options(struct sock *sk, struct sk_buff *skb)
  481. {
  482. struct dccp_sock *dp = dccp_sk(sk);
  483. struct dccp_minisock *dmsk = dccp_msk(sk);
  484. DCCP_SKB_CB(skb)->dccpd_opt_len = 0;
  485. if (dmsk->dccpms_send_ndp_count &&
  486. dccp_insert_option_ndp(sk, skb))
  487. return -1;
  488. if (!dccp_packet_without_ack(skb)) {
  489. if (dmsk->dccpms_send_ack_vector &&
  490. dccp_ackvec_pending(dp->dccps_hc_rx_ackvec) &&
  491. dccp_insert_option_ackvec(sk, skb))
  492. return -1;
  493. }
  494. if (dp->dccps_hc_rx_insert_options) {
  495. if (ccid_hc_rx_insert_options(dp->dccps_hc_rx_ccid, sk, skb))
  496. return -1;
  497. dp->dccps_hc_rx_insert_options = 0;
  498. }
  499. /* Feature negotiation */
  500. /* Data packets can't do feat negotiation */
  501. if (DCCP_SKB_CB(skb)->dccpd_type != DCCP_PKT_DATA &&
  502. DCCP_SKB_CB(skb)->dccpd_type != DCCP_PKT_DATAACK &&
  503. dccp_insert_options_feat(sk, skb))
  504. return -1;
  505. /*
  506. * Obtain RTT sample from Request/Response exchange.
  507. * This is currently used in CCID 3 initialisation.
  508. */
  509. if (DCCP_SKB_CB(skb)->dccpd_type == DCCP_PKT_REQUEST &&
  510. dccp_insert_option_timestamp(sk, skb))
  511. return -1;
  512. if (dp->dccps_timestamp_echo != 0 &&
  513. dccp_insert_option_timestamp_echo(dp, NULL, skb))
  514. return -1;
  515. dccp_insert_option_padding(skb);
  516. return 0;
  517. }
  518. int dccp_insert_options_rsk(struct dccp_request_sock *dreq, struct sk_buff *skb)
  519. {
  520. DCCP_SKB_CB(skb)->dccpd_opt_len = 0;
  521. if (dreq->dreq_timestamp_echo != 0 &&
  522. dccp_insert_option_timestamp_echo(NULL, dreq, skb))
  523. return -1;
  524. dccp_insert_option_padding(skb);
  525. return 0;
  526. }