feat.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236
  1. /*
  2. * net/dccp/feat.c
  3. *
  4. * An implementation of the DCCP protocol
  5. * Andrea Bittau <a.bittau@cs.ucl.ac.uk>
  6. *
  7. * ASSUMPTIONS
  8. * -----------
  9. * o Feature negotiation is coordinated with connection setup (as in TCP), wild
  10. * changes of parameters of an established connection are not supported.
  11. * o All currently known SP features have 1-byte quantities. If in the future
  12. * extensions of RFCs 4340..42 define features with item lengths larger than
  13. * one byte, a feature-specific extension of the code will be required.
  14. *
  15. * This program is free software; you can redistribute it and/or
  16. * modify it under the terms of the GNU General Public License
  17. * as published by the Free Software Foundation; either version
  18. * 2 of the License, or (at your option) any later version.
  19. */
  20. #include <linux/module.h>
  21. #include "ccid.h"
  22. #include "feat.h"
  23. #define DCCP_FEAT_SP_NOAGREE (-123)
  24. static const struct {
  25. u8 feat_num; /* DCCPF_xxx */
  26. enum dccp_feat_type rxtx; /* RX or TX */
  27. enum dccp_feat_type reconciliation; /* SP or NN */
  28. u8 default_value; /* as in 6.4 */
  29. /*
  30. * Lookup table for location and type of features (from RFC 4340/4342)
  31. * +--------------------------+----+-----+----+----+---------+-----------+
  32. * | Feature | Location | Reconc. | Initial | Section |
  33. * | | RX | TX | SP | NN | Value | Reference |
  34. * +--------------------------+----+-----+----+----+---------+-----------+
  35. * | DCCPF_CCID | | X | X | | 2 | 10 |
  36. * | DCCPF_SHORT_SEQNOS | | X | X | | 0 | 7.6.1 |
  37. * | DCCPF_SEQUENCE_WINDOW | | X | | X | 100 | 7.5.2 |
  38. * | DCCPF_ECN_INCAPABLE | X | | X | | 0 | 12.1 |
  39. * | DCCPF_ACK_RATIO | | X | | X | 2 | 11.3 |
  40. * | DCCPF_SEND_ACK_VECTOR | X | | X | | 0 | 11.5 |
  41. * | DCCPF_SEND_NDP_COUNT | | X | X | | 0 | 7.7.2 |
  42. * | DCCPF_MIN_CSUM_COVER | X | | X | | 0 | 9.2.1 |
  43. * | DCCPF_DATA_CHECKSUM | X | | X | | 0 | 9.3.1 |
  44. * | DCCPF_SEND_LEV_RATE | X | | X | | 0 | 4342/8.4 |
  45. * +--------------------------+----+-----+----+----+---------+-----------+
  46. */
  47. } dccp_feat_table[] = {
  48. { DCCPF_CCID, FEAT_AT_TX, FEAT_SP, 2 },
  49. { DCCPF_SHORT_SEQNOS, FEAT_AT_TX, FEAT_SP, 0 },
  50. { DCCPF_SEQUENCE_WINDOW, FEAT_AT_TX, FEAT_NN, 100 },
  51. { DCCPF_ECN_INCAPABLE, FEAT_AT_RX, FEAT_SP, 0 },
  52. { DCCPF_ACK_RATIO, FEAT_AT_TX, FEAT_NN, 2 },
  53. { DCCPF_SEND_ACK_VECTOR, FEAT_AT_RX, FEAT_SP, 0 },
  54. { DCCPF_SEND_NDP_COUNT, FEAT_AT_TX, FEAT_SP, 0 },
  55. { DCCPF_MIN_CSUM_COVER, FEAT_AT_RX, FEAT_SP, 0 },
  56. { DCCPF_DATA_CHECKSUM, FEAT_AT_RX, FEAT_SP, 0 },
  57. { DCCPF_SEND_LEV_RATE, FEAT_AT_RX, FEAT_SP, 0 },
  58. };
  59. #define DCCP_FEAT_SUPPORTED_MAX ARRAY_SIZE(dccp_feat_table)
  60. /**
  61. * dccp_feat_index - Hash function to map feature number into array position
  62. * Returns consecutive array index or -1 if the feature is not understood.
  63. */
  64. static int dccp_feat_index(u8 feat_num)
  65. {
  66. /* The first 9 entries are occupied by the types from RFC 4340, 6.4 */
  67. if (feat_num > DCCPF_RESERVED && feat_num <= DCCPF_DATA_CHECKSUM)
  68. return feat_num - 1;
  69. /*
  70. * Other features: add cases for new feature types here after adding
  71. * them to the above table.
  72. */
  73. switch (feat_num) {
  74. case DCCPF_SEND_LEV_RATE:
  75. return DCCP_FEAT_SUPPORTED_MAX - 1;
  76. }
  77. return -1;
  78. }
  79. static u8 dccp_feat_type(u8 feat_num)
  80. {
  81. int idx = dccp_feat_index(feat_num);
  82. if (idx < 0)
  83. return FEAT_UNKNOWN;
  84. return dccp_feat_table[idx].reconciliation;
  85. }
  86. static int dccp_feat_default_value(u8 feat_num)
  87. {
  88. int idx = dccp_feat_index(feat_num);
  89. return idx < 0 ? : dccp_feat_table[idx].default_value;
  90. }
  91. /* copy constructor, fval must not already contain allocated memory */
  92. static int dccp_feat_clone_sp_val(dccp_feat_val *fval, u8 const *val, u8 len)
  93. {
  94. fval->sp.len = len;
  95. if (fval->sp.len > 0) {
  96. fval->sp.vec = kmemdup(val, len, gfp_any());
  97. if (fval->sp.vec == NULL) {
  98. fval->sp.len = 0;
  99. return -ENOBUFS;
  100. }
  101. }
  102. return 0;
  103. }
  104. static void dccp_feat_val_destructor(u8 feat_num, dccp_feat_val *val)
  105. {
  106. if (unlikely(val == NULL))
  107. return;
  108. if (dccp_feat_type(feat_num) == FEAT_SP)
  109. kfree(val->sp.vec);
  110. memset(val, 0, sizeof(*val));
  111. }
  112. static struct dccp_feat_entry *
  113. dccp_feat_clone_entry(struct dccp_feat_entry const *original)
  114. {
  115. struct dccp_feat_entry *new;
  116. u8 type = dccp_feat_type(original->feat_num);
  117. if (type == FEAT_UNKNOWN)
  118. return NULL;
  119. new = kmemdup(original, sizeof(struct dccp_feat_entry), gfp_any());
  120. if (new == NULL)
  121. return NULL;
  122. if (type == FEAT_SP && dccp_feat_clone_sp_val(&new->val,
  123. original->val.sp.vec,
  124. original->val.sp.len)) {
  125. kfree(new);
  126. return NULL;
  127. }
  128. return new;
  129. }
  130. static void dccp_feat_entry_destructor(struct dccp_feat_entry *entry)
  131. {
  132. if (entry != NULL) {
  133. dccp_feat_val_destructor(entry->feat_num, &entry->val);
  134. kfree(entry);
  135. }
  136. }
  137. /*
  138. * List management functions
  139. *
  140. * Feature negotiation lists rely on and maintain the following invariants:
  141. * - each feat_num in the list is known, i.e. we know its type and default value
  142. * - each feat_num/is_local combination is unique (old entries are overwritten)
  143. * - SP values are always freshly allocated
  144. * - list is sorted in increasing order of feature number (faster lookup)
  145. */
  146. static struct dccp_feat_entry *dccp_feat_list_lookup(struct list_head *fn_list,
  147. u8 feat_num, bool is_local)
  148. {
  149. struct dccp_feat_entry *entry;
  150. list_for_each_entry(entry, fn_list, node)
  151. if (entry->feat_num == feat_num && entry->is_local == is_local)
  152. return entry;
  153. else if (entry->feat_num > feat_num)
  154. break;
  155. return NULL;
  156. }
  157. /**
  158. * dccp_feat_entry_new - Central list update routine (called by all others)
  159. * @head: list to add to
  160. * @feat: feature number
  161. * @local: whether the local (1) or remote feature with number @feat is meant
  162. * This is the only constructor and serves to ensure the above invariants.
  163. */
  164. static struct dccp_feat_entry *
  165. dccp_feat_entry_new(struct list_head *head, u8 feat, bool local)
  166. {
  167. struct dccp_feat_entry *entry;
  168. list_for_each_entry(entry, head, node)
  169. if (entry->feat_num == feat && entry->is_local == local) {
  170. dccp_feat_val_destructor(entry->feat_num, &entry->val);
  171. return entry;
  172. } else if (entry->feat_num > feat) {
  173. head = &entry->node;
  174. break;
  175. }
  176. entry = kmalloc(sizeof(*entry), gfp_any());
  177. if (entry != NULL) {
  178. entry->feat_num = feat;
  179. entry->is_local = local;
  180. list_add_tail(&entry->node, head);
  181. }
  182. return entry;
  183. }
  184. /**
  185. * dccp_feat_push_change - Add/overwrite a Change option in the list
  186. * @fn_list: feature-negotiation list to update
  187. * @feat: one of %dccp_feature_numbers
  188. * @local: whether local (1) or remote (0) @feat_num is meant
  189. * @needs_mandatory: whether to use Mandatory feature negotiation options
  190. * @fval: pointer to NN/SP value to be inserted (will be copied)
  191. */
  192. static int dccp_feat_push_change(struct list_head *fn_list, u8 feat, u8 local,
  193. u8 mandatory, dccp_feat_val *fval)
  194. {
  195. struct dccp_feat_entry *new = dccp_feat_entry_new(fn_list, feat, local);
  196. if (new == NULL)
  197. return -ENOMEM;
  198. new->feat_num = feat;
  199. new->is_local = local;
  200. new->state = FEAT_INITIALISING;
  201. new->needs_confirm = 0;
  202. new->empty_confirm = 0;
  203. new->val = *fval;
  204. new->needs_mandatory = mandatory;
  205. return 0;
  206. }
  207. /**
  208. * dccp_feat_push_confirm - Add a Confirm entry to the FN list
  209. * @fn_list: feature-negotiation list to add to
  210. * @feat: one of %dccp_feature_numbers
  211. * @local: whether local (1) or remote (0) @feat_num is being confirmed
  212. * @fval: pointer to NN/SP value to be inserted or NULL
  213. * Returns 0 on success, a Reset code for further processing otherwise.
  214. */
  215. static int dccp_feat_push_confirm(struct list_head *fn_list, u8 feat, u8 local,
  216. dccp_feat_val *fval)
  217. {
  218. struct dccp_feat_entry *new = dccp_feat_entry_new(fn_list, feat, local);
  219. if (new == NULL)
  220. return DCCP_RESET_CODE_TOO_BUSY;
  221. new->feat_num = feat;
  222. new->is_local = local;
  223. new->state = FEAT_STABLE; /* transition in 6.6.2 */
  224. new->needs_confirm = 1;
  225. new->empty_confirm = (fval == NULL);
  226. new->val.nn = 0; /* zeroes the whole structure */
  227. if (!new->empty_confirm)
  228. new->val = *fval;
  229. new->needs_mandatory = 0;
  230. return 0;
  231. }
  232. static int dccp_push_empty_confirm(struct list_head *fn_list, u8 feat, u8 local)
  233. {
  234. return dccp_feat_push_confirm(fn_list, feat, local, NULL);
  235. }
  236. static inline void dccp_feat_list_pop(struct dccp_feat_entry *entry)
  237. {
  238. list_del(&entry->node);
  239. dccp_feat_entry_destructor(entry);
  240. }
  241. void dccp_feat_list_purge(struct list_head *fn_list)
  242. {
  243. struct dccp_feat_entry *entry, *next;
  244. list_for_each_entry_safe(entry, next, fn_list, node)
  245. dccp_feat_entry_destructor(entry);
  246. INIT_LIST_HEAD(fn_list);
  247. }
  248. EXPORT_SYMBOL_GPL(dccp_feat_list_purge);
  249. /* generate @to as full clone of @from - @to must not contain any nodes */
  250. int dccp_feat_clone_list(struct list_head const *from, struct list_head *to)
  251. {
  252. struct dccp_feat_entry *entry, *new;
  253. INIT_LIST_HEAD(to);
  254. list_for_each_entry(entry, from, node) {
  255. new = dccp_feat_clone_entry(entry);
  256. if (new == NULL)
  257. goto cloning_failed;
  258. list_add_tail(&new->node, to);
  259. }
  260. return 0;
  261. cloning_failed:
  262. dccp_feat_list_purge(to);
  263. return -ENOMEM;
  264. }
  265. /**
  266. * dccp_feat_valid_nn_length - Enforce length constraints on NN options
  267. * Length is between 0 and %DCCP_OPTVAL_MAXLEN. Used for outgoing packets only,
  268. * incoming options are accepted as long as their values are valid.
  269. */
  270. static u8 dccp_feat_valid_nn_length(u8 feat_num)
  271. {
  272. if (feat_num == DCCPF_ACK_RATIO) /* RFC 4340, 11.3 and 6.6.8 */
  273. return 2;
  274. if (feat_num == DCCPF_SEQUENCE_WINDOW) /* RFC 4340, 7.5.2 and 6.5 */
  275. return 6;
  276. return 0;
  277. }
  278. static u8 dccp_feat_is_valid_nn_val(u8 feat_num, u64 val)
  279. {
  280. switch (feat_num) {
  281. case DCCPF_ACK_RATIO:
  282. return val <= DCCPF_ACK_RATIO_MAX;
  283. case DCCPF_SEQUENCE_WINDOW:
  284. return val >= DCCPF_SEQ_WMIN && val <= DCCPF_SEQ_WMAX;
  285. }
  286. return 0; /* feature unknown - so we can't tell */
  287. }
  288. /* check that SP values are within the ranges defined in RFC 4340 */
  289. static u8 dccp_feat_is_valid_sp_val(u8 feat_num, u8 val)
  290. {
  291. switch (feat_num) {
  292. case DCCPF_CCID:
  293. return val == DCCPC_CCID2 || val == DCCPC_CCID3;
  294. /* Type-check Boolean feature values: */
  295. case DCCPF_SHORT_SEQNOS:
  296. case DCCPF_ECN_INCAPABLE:
  297. case DCCPF_SEND_ACK_VECTOR:
  298. case DCCPF_SEND_NDP_COUNT:
  299. case DCCPF_DATA_CHECKSUM:
  300. case DCCPF_SEND_LEV_RATE:
  301. return val < 2;
  302. case DCCPF_MIN_CSUM_COVER:
  303. return val < 16;
  304. }
  305. return 0; /* feature unknown */
  306. }
  307. static u8 dccp_feat_sp_list_ok(u8 feat_num, u8 const *sp_list, u8 sp_len)
  308. {
  309. if (sp_list == NULL || sp_len < 1)
  310. return 0;
  311. while (sp_len--)
  312. if (!dccp_feat_is_valid_sp_val(feat_num, *sp_list++))
  313. return 0;
  314. return 1;
  315. }
  316. /**
  317. * dccp_feat_insert_opts - Generate FN options from current list state
  318. * @skb: next sk_buff to be sent to the peer
  319. * @dp: for client during handshake and general negotiation
  320. * @dreq: used by the server only (all Changes/Confirms in LISTEN/RESPOND)
  321. */
  322. int dccp_feat_insert_opts(struct dccp_sock *dp, struct dccp_request_sock *dreq,
  323. struct sk_buff *skb)
  324. {
  325. struct list_head *fn = dreq ? &dreq->dreq_featneg : &dp->dccps_featneg;
  326. struct dccp_feat_entry *pos, *next;
  327. u8 opt, type, len, *ptr, nn_in_nbo[DCCP_OPTVAL_MAXLEN];
  328. bool rpt;
  329. /* put entries into @skb in the order they appear in the list */
  330. list_for_each_entry_safe_reverse(pos, next, fn, node) {
  331. opt = dccp_feat_genopt(pos);
  332. type = dccp_feat_type(pos->feat_num);
  333. rpt = false;
  334. if (pos->empty_confirm) {
  335. len = 0;
  336. ptr = NULL;
  337. } else {
  338. if (type == FEAT_SP) {
  339. len = pos->val.sp.len;
  340. ptr = pos->val.sp.vec;
  341. rpt = pos->needs_confirm;
  342. } else if (type == FEAT_NN) {
  343. len = dccp_feat_valid_nn_length(pos->feat_num);
  344. ptr = nn_in_nbo;
  345. dccp_encode_value_var(pos->val.nn, ptr, len);
  346. } else {
  347. DCCP_BUG("unknown feature %u", pos->feat_num);
  348. return -1;
  349. }
  350. }
  351. if (dccp_insert_fn_opt(skb, opt, pos->feat_num, ptr, len, rpt))
  352. return -1;
  353. if (pos->needs_mandatory && dccp_insert_option_mandatory(skb))
  354. return -1;
  355. /*
  356. * Enter CHANGING after transmitting the Change option (6.6.2).
  357. */
  358. if (pos->state == FEAT_INITIALISING)
  359. pos->state = FEAT_CHANGING;
  360. }
  361. return 0;
  362. }
  363. /**
  364. * __feat_register_nn - Register new NN value on socket
  365. * @fn: feature-negotiation list to register with
  366. * @feat: an NN feature from %dccp_feature_numbers
  367. * @mandatory: use Mandatory option if 1
  368. * @nn_val: value to register (restricted to 4 bytes)
  369. * Note that NN features are local by definition (RFC 4340, 6.3.2).
  370. */
  371. static int __feat_register_nn(struct list_head *fn, u8 feat,
  372. u8 mandatory, u64 nn_val)
  373. {
  374. dccp_feat_val fval = { .nn = nn_val };
  375. if (dccp_feat_type(feat) != FEAT_NN ||
  376. !dccp_feat_is_valid_nn_val(feat, nn_val))
  377. return -EINVAL;
  378. /* Don't bother with default values, they will be activated anyway. */
  379. if (nn_val - (u64)dccp_feat_default_value(feat) == 0)
  380. return 0;
  381. return dccp_feat_push_change(fn, feat, 1, mandatory, &fval);
  382. }
  383. /**
  384. * __feat_register_sp - Register new SP value/list on socket
  385. * @fn: feature-negotiation list to register with
  386. * @feat: an SP feature from %dccp_feature_numbers
  387. * @is_local: whether the local (1) or the remote (0) @feat is meant
  388. * @mandatory: use Mandatory option if 1
  389. * @sp_val: SP value followed by optional preference list
  390. * @sp_len: length of @sp_val in bytes
  391. */
  392. static int __feat_register_sp(struct list_head *fn, u8 feat, u8 is_local,
  393. u8 mandatory, u8 const *sp_val, u8 sp_len)
  394. {
  395. dccp_feat_val fval;
  396. if (dccp_feat_type(feat) != FEAT_SP ||
  397. !dccp_feat_sp_list_ok(feat, sp_val, sp_len))
  398. return -EINVAL;
  399. /* Avoid negotiating alien CCIDs by only advertising supported ones */
  400. if (feat == DCCPF_CCID && !ccid_support_check(sp_val, sp_len))
  401. return -EOPNOTSUPP;
  402. if (dccp_feat_clone_sp_val(&fval, sp_val, sp_len))
  403. return -ENOMEM;
  404. return dccp_feat_push_change(fn, feat, is_local, mandatory, &fval);
  405. }
  406. /**
  407. * dccp_feat_register_sp - Register requests to change SP feature values
  408. * @sk: client or listening socket
  409. * @feat: one of %dccp_feature_numbers
  410. * @is_local: whether the local (1) or remote (0) @feat is meant
  411. * @list: array of preferred values, in descending order of preference
  412. * @len: length of @list in bytes
  413. */
  414. int dccp_feat_register_sp(struct sock *sk, u8 feat, u8 is_local,
  415. u8 const *list, u8 len)
  416. { /* any changes must be registered before establishing the connection */
  417. if (sk->sk_state != DCCP_CLOSED)
  418. return -EISCONN;
  419. if (dccp_feat_type(feat) != FEAT_SP)
  420. return -EINVAL;
  421. return __feat_register_sp(&dccp_sk(sk)->dccps_featneg, feat, is_local,
  422. 0, list, len);
  423. }
  424. /* Analogous to dccp_feat_register_sp(), but for non-negotiable values */
  425. int dccp_feat_register_nn(struct sock *sk, u8 feat, u64 val)
  426. {
  427. /* any changes must be registered before establishing the connection */
  428. if (sk->sk_state != DCCP_CLOSED)
  429. return -EISCONN;
  430. if (dccp_feat_type(feat) != FEAT_NN)
  431. return -EINVAL;
  432. return __feat_register_nn(&dccp_sk(sk)->dccps_featneg, feat, 0, val);
  433. }
  434. /*
  435. * Tracking features whose value depend on the choice of CCID
  436. *
  437. * This is designed with an extension in mind so that a list walk could be done
  438. * before activating any features. However, the existing framework was found to
  439. * work satisfactorily up until now, the automatic verification is left open.
  440. * When adding new CCIDs, add a corresponding dependency table here.
  441. */
  442. static const struct ccid_dependency *dccp_feat_ccid_deps(u8 ccid, bool is_local)
  443. {
  444. static const struct ccid_dependency ccid2_dependencies[2][2] = {
  445. /*
  446. * CCID2 mandates Ack Vectors (RFC 4341, 4.): as CCID is a TX
  447. * feature and Send Ack Vector is an RX feature, `is_local'
  448. * needs to be reversed.
  449. */
  450. { /* Dependencies of the receiver-side (remote) CCID2 */
  451. {
  452. .dependent_feat = DCCPF_SEND_ACK_VECTOR,
  453. .is_local = true,
  454. .is_mandatory = true,
  455. .val = 1
  456. },
  457. { 0, 0, 0, 0 }
  458. },
  459. { /* Dependencies of the sender-side (local) CCID2 */
  460. {
  461. .dependent_feat = DCCPF_SEND_ACK_VECTOR,
  462. .is_local = false,
  463. .is_mandatory = true,
  464. .val = 1
  465. },
  466. { 0, 0, 0, 0 }
  467. }
  468. };
  469. static const struct ccid_dependency ccid3_dependencies[2][5] = {
  470. { /*
  471. * Dependencies of the receiver-side CCID3
  472. */
  473. { /* locally disable Ack Vectors */
  474. .dependent_feat = DCCPF_SEND_ACK_VECTOR,
  475. .is_local = true,
  476. .is_mandatory = false,
  477. .val = 0
  478. },
  479. { /* see below why Send Loss Event Rate is on */
  480. .dependent_feat = DCCPF_SEND_LEV_RATE,
  481. .is_local = true,
  482. .is_mandatory = true,
  483. .val = 1
  484. },
  485. { /* NDP Count is needed as per RFC 4342, 6.1.1 */
  486. .dependent_feat = DCCPF_SEND_NDP_COUNT,
  487. .is_local = false,
  488. .is_mandatory = true,
  489. .val = 1
  490. },
  491. { 0, 0, 0, 0 },
  492. },
  493. { /*
  494. * CCID3 at the TX side: we request that the HC-receiver
  495. * will not send Ack Vectors (they will be ignored, so
  496. * Mandatory is not set); we enable Send Loss Event Rate
  497. * (Mandatory since the implementation does not support
  498. * the Loss Intervals option of RFC 4342, 8.6).
  499. * The last two options are for peer's information only.
  500. */
  501. {
  502. .dependent_feat = DCCPF_SEND_ACK_VECTOR,
  503. .is_local = false,
  504. .is_mandatory = false,
  505. .val = 0
  506. },
  507. {
  508. .dependent_feat = DCCPF_SEND_LEV_RATE,
  509. .is_local = false,
  510. .is_mandatory = true,
  511. .val = 1
  512. },
  513. { /* this CCID does not support Ack Ratio */
  514. .dependent_feat = DCCPF_ACK_RATIO,
  515. .is_local = true,
  516. .is_mandatory = false,
  517. .val = 0
  518. },
  519. { /* tell receiver we are sending NDP counts */
  520. .dependent_feat = DCCPF_SEND_NDP_COUNT,
  521. .is_local = true,
  522. .is_mandatory = false,
  523. .val = 1
  524. },
  525. { 0, 0, 0, 0 }
  526. }
  527. };
  528. switch (ccid) {
  529. case DCCPC_CCID2:
  530. return ccid2_dependencies[is_local];
  531. case DCCPC_CCID3:
  532. return ccid3_dependencies[is_local];
  533. default:
  534. return NULL;
  535. }
  536. }
  537. /**
  538. * dccp_feat_propagate_ccid - Resolve dependencies of features on choice of CCID
  539. * @fn: feature-negotiation list to update
  540. * @id: CCID number to track
  541. * @is_local: whether TX CCID (1) or RX CCID (0) is meant
  542. * This function needs to be called after registering all other features.
  543. */
  544. static int dccp_feat_propagate_ccid(struct list_head *fn, u8 id, bool is_local)
  545. {
  546. const struct ccid_dependency *table = dccp_feat_ccid_deps(id, is_local);
  547. int i, rc = (table == NULL);
  548. for (i = 0; rc == 0 && table[i].dependent_feat != DCCPF_RESERVED; i++)
  549. if (dccp_feat_type(table[i].dependent_feat) == FEAT_SP)
  550. rc = __feat_register_sp(fn, table[i].dependent_feat,
  551. table[i].is_local,
  552. table[i].is_mandatory,
  553. &table[i].val, 1);
  554. else
  555. rc = __feat_register_nn(fn, table[i].dependent_feat,
  556. table[i].is_mandatory,
  557. table[i].val);
  558. return rc;
  559. }
  560. /**
  561. * dccp_feat_finalise_settings - Finalise settings before starting negotiation
  562. * @dp: client or listening socket (settings will be inherited)
  563. * This is called after all registrations (socket initialisation, sysctls, and
  564. * sockopt calls), and before sending the first packet containing Change options
  565. * (ie. client-Request or server-Response), to ensure internal consistency.
  566. */
  567. int dccp_feat_finalise_settings(struct dccp_sock *dp)
  568. {
  569. struct list_head *fn = &dp->dccps_featneg;
  570. struct dccp_feat_entry *entry;
  571. int i = 2, ccids[2] = { -1, -1 };
  572. /*
  573. * Propagating CCIDs:
  574. * 1) not useful to propagate CCID settings if this host advertises more
  575. * than one CCID: the choice of CCID may still change - if this is
  576. * the client, or if this is the server and the client sends
  577. * singleton CCID values.
  578. * 2) since is that propagate_ccid changes the list, we defer changing
  579. * the sorted list until after the traversal.
  580. */
  581. list_for_each_entry(entry, fn, node)
  582. if (entry->feat_num == DCCPF_CCID && entry->val.sp.len == 1)
  583. ccids[entry->is_local] = entry->val.sp.vec[0];
  584. while (i--)
  585. if (ccids[i] > 0 && dccp_feat_propagate_ccid(fn, ccids[i], i))
  586. return -1;
  587. return 0;
  588. }
  589. /**
  590. * dccp_feat_server_ccid_dependencies - Resolve CCID-dependent features
  591. * It is the server which resolves the dependencies once the CCID has been
  592. * fully negotiated. If no CCID has been negotiated, it uses the default CCID.
  593. */
  594. int dccp_feat_server_ccid_dependencies(struct dccp_request_sock *dreq)
  595. {
  596. struct list_head *fn = &dreq->dreq_featneg;
  597. struct dccp_feat_entry *entry;
  598. u8 is_local, ccid;
  599. for (is_local = 0; is_local <= 1; is_local++) {
  600. entry = dccp_feat_list_lookup(fn, DCCPF_CCID, is_local);
  601. if (entry != NULL && !entry->empty_confirm)
  602. ccid = entry->val.sp.vec[0];
  603. else
  604. ccid = dccp_feat_default_value(DCCPF_CCID);
  605. if (dccp_feat_propagate_ccid(fn, ccid, is_local))
  606. return -1;
  607. }
  608. return 0;
  609. }
  610. static int dccp_feat_update_ccid(struct sock *sk, u8 type, u8 new_ccid_nr)
  611. {
  612. struct dccp_sock *dp = dccp_sk(sk);
  613. struct dccp_minisock *dmsk = dccp_msk(sk);
  614. /* figure out if we are changing our CCID or the peer's */
  615. const int rx = type == DCCPO_CHANGE_R;
  616. const u8 ccid_nr = rx ? dmsk->dccpms_rx_ccid : dmsk->dccpms_tx_ccid;
  617. struct ccid *new_ccid;
  618. /* Check if nothing is being changed. */
  619. if (ccid_nr == new_ccid_nr)
  620. return 0;
  621. new_ccid = ccid_new(new_ccid_nr, sk, rx, GFP_ATOMIC);
  622. if (new_ccid == NULL)
  623. return -ENOMEM;
  624. if (rx) {
  625. ccid_hc_rx_delete(dp->dccps_hc_rx_ccid, sk);
  626. dp->dccps_hc_rx_ccid = new_ccid;
  627. dmsk->dccpms_rx_ccid = new_ccid_nr;
  628. } else {
  629. ccid_hc_tx_delete(dp->dccps_hc_tx_ccid, sk);
  630. dp->dccps_hc_tx_ccid = new_ccid;
  631. dmsk->dccpms_tx_ccid = new_ccid_nr;
  632. }
  633. return 0;
  634. }
  635. static int dccp_feat_update(struct sock *sk, u8 type, u8 feat, u8 val)
  636. {
  637. dccp_feat_debug(type, feat, val);
  638. switch (feat) {
  639. case DCCPF_CCID:
  640. return dccp_feat_update_ccid(sk, type, val);
  641. default:
  642. dccp_pr_debug("UNIMPLEMENTED: %s(%d, ...)\n",
  643. dccp_feat_typename(type), feat);
  644. break;
  645. }
  646. return 0;
  647. }
  648. static int dccp_feat_reconcile(struct sock *sk, struct dccp_opt_pend *opt,
  649. u8 *rpref, u8 rlen)
  650. {
  651. struct dccp_sock *dp = dccp_sk(sk);
  652. u8 *spref, slen, *res = NULL;
  653. int i, j, rc, agree = 1;
  654. BUG_ON(rpref == NULL);
  655. /* check if we are the black sheep */
  656. if (dp->dccps_role == DCCP_ROLE_CLIENT) {
  657. spref = rpref;
  658. slen = rlen;
  659. rpref = opt->dccpop_val;
  660. rlen = opt->dccpop_len;
  661. } else {
  662. spref = opt->dccpop_val;
  663. slen = opt->dccpop_len;
  664. }
  665. /*
  666. * Now we have server preference list in spref and client preference in
  667. * rpref
  668. */
  669. BUG_ON(spref == NULL);
  670. BUG_ON(rpref == NULL);
  671. /* FIXME sanity check vals */
  672. /* Are values in any order? XXX Lame "algorithm" here */
  673. for (i = 0; i < slen; i++) {
  674. for (j = 0; j < rlen; j++) {
  675. if (spref[i] == rpref[j]) {
  676. res = &spref[i];
  677. break;
  678. }
  679. }
  680. if (res)
  681. break;
  682. }
  683. /* we didn't agree on anything */
  684. if (res == NULL) {
  685. /* confirm previous value */
  686. switch (opt->dccpop_feat) {
  687. case DCCPF_CCID:
  688. /* XXX did i get this right? =P */
  689. if (opt->dccpop_type == DCCPO_CHANGE_L)
  690. res = &dccp_msk(sk)->dccpms_tx_ccid;
  691. else
  692. res = &dccp_msk(sk)->dccpms_rx_ccid;
  693. break;
  694. default:
  695. DCCP_BUG("Fell through, feat=%d", opt->dccpop_feat);
  696. /* XXX implement res */
  697. return -EFAULT;
  698. }
  699. dccp_pr_debug("Don't agree... reconfirming %d\n", *res);
  700. agree = 0; /* this is used for mandatory options... */
  701. }
  702. /* need to put result and our preference list */
  703. rlen = 1 + opt->dccpop_len;
  704. rpref = kmalloc(rlen, GFP_ATOMIC);
  705. if (rpref == NULL)
  706. return -ENOMEM;
  707. *rpref = *res;
  708. memcpy(&rpref[1], opt->dccpop_val, opt->dccpop_len);
  709. /* put it in the "confirm queue" */
  710. if (opt->dccpop_sc == NULL) {
  711. opt->dccpop_sc = kmalloc(sizeof(*opt->dccpop_sc), GFP_ATOMIC);
  712. if (opt->dccpop_sc == NULL) {
  713. kfree(rpref);
  714. return -ENOMEM;
  715. }
  716. } else {
  717. /* recycle the confirm slot */
  718. BUG_ON(opt->dccpop_sc->dccpoc_val == NULL);
  719. kfree(opt->dccpop_sc->dccpoc_val);
  720. dccp_pr_debug("recycling confirm slot\n");
  721. }
  722. memset(opt->dccpop_sc, 0, sizeof(*opt->dccpop_sc));
  723. opt->dccpop_sc->dccpoc_val = rpref;
  724. opt->dccpop_sc->dccpoc_len = rlen;
  725. /* update the option on our side [we are about to send the confirm] */
  726. rc = dccp_feat_update(sk, opt->dccpop_type, opt->dccpop_feat, *res);
  727. if (rc) {
  728. kfree(opt->dccpop_sc->dccpoc_val);
  729. kfree(opt->dccpop_sc);
  730. opt->dccpop_sc = NULL;
  731. return rc;
  732. }
  733. dccp_pr_debug("Will confirm %d\n", *rpref);
  734. /* say we want to change to X but we just got a confirm X, suppress our
  735. * change
  736. */
  737. if (!opt->dccpop_conf) {
  738. if (*opt->dccpop_val == *res)
  739. opt->dccpop_conf = 1;
  740. dccp_pr_debug("won't ask for change of same feature\n");
  741. }
  742. return agree ? 0 : DCCP_FEAT_SP_NOAGREE; /* used for mandatory opts */
  743. }
  744. static int dccp_feat_sp(struct sock *sk, u8 type, u8 feature, u8 *val, u8 len)
  745. {
  746. struct dccp_minisock *dmsk = dccp_msk(sk);
  747. struct dccp_opt_pend *opt;
  748. int rc = 1;
  749. u8 t;
  750. /*
  751. * We received a CHANGE. We gotta match it against our own preference
  752. * list. If we got a CHANGE_R it means it's a change for us, so we need
  753. * to compare our CHANGE_L list.
  754. */
  755. if (type == DCCPO_CHANGE_L)
  756. t = DCCPO_CHANGE_R;
  757. else
  758. t = DCCPO_CHANGE_L;
  759. /* find our preference list for this feature */
  760. list_for_each_entry(opt, &dmsk->dccpms_pending, dccpop_node) {
  761. if (opt->dccpop_type != t || opt->dccpop_feat != feature)
  762. continue;
  763. /* find the winner from the two preference lists */
  764. rc = dccp_feat_reconcile(sk, opt, val, len);
  765. break;
  766. }
  767. /* We didn't deal with the change. This can happen if we have no
  768. * preference list for the feature. In fact, it just shouldn't
  769. * happen---if we understand a feature, we should have a preference list
  770. * with at least the default value.
  771. */
  772. BUG_ON(rc == 1);
  773. return rc;
  774. }
  775. static int dccp_feat_nn(struct sock *sk, u8 type, u8 feature, u8 *val, u8 len)
  776. {
  777. struct dccp_opt_pend *opt;
  778. struct dccp_minisock *dmsk = dccp_msk(sk);
  779. u8 *copy;
  780. int rc;
  781. /* NN features must be Change L (sec. 6.3.2) */
  782. if (type != DCCPO_CHANGE_L) {
  783. dccp_pr_debug("received %s for NN feature %d\n",
  784. dccp_feat_typename(type), feature);
  785. return -EFAULT;
  786. }
  787. /* XXX sanity check opt val */
  788. /* copy option so we can confirm it */
  789. opt = kzalloc(sizeof(*opt), GFP_ATOMIC);
  790. if (opt == NULL)
  791. return -ENOMEM;
  792. copy = kmemdup(val, len, GFP_ATOMIC);
  793. if (copy == NULL) {
  794. kfree(opt);
  795. return -ENOMEM;
  796. }
  797. opt->dccpop_type = DCCPO_CONFIRM_R; /* NN can only confirm R */
  798. opt->dccpop_feat = feature;
  799. opt->dccpop_val = copy;
  800. opt->dccpop_len = len;
  801. /* change feature */
  802. rc = dccp_feat_update(sk, type, feature, *val);
  803. if (rc) {
  804. kfree(opt->dccpop_val);
  805. kfree(opt);
  806. return rc;
  807. }
  808. dccp_feat_debug(type, feature, *copy);
  809. list_add_tail(&opt->dccpop_node, &dmsk->dccpms_conf);
  810. return 0;
  811. }
  812. static void dccp_feat_empty_confirm(struct dccp_minisock *dmsk,
  813. u8 type, u8 feature)
  814. {
  815. /* XXX check if other confirms for that are queued and recycle slot */
  816. struct dccp_opt_pend *opt = kzalloc(sizeof(*opt), GFP_ATOMIC);
  817. if (opt == NULL) {
  818. /* XXX what do we do? Ignoring should be fine. It's a change
  819. * after all =P
  820. */
  821. return;
  822. }
  823. switch (type) {
  824. case DCCPO_CHANGE_L:
  825. opt->dccpop_type = DCCPO_CONFIRM_R;
  826. break;
  827. case DCCPO_CHANGE_R:
  828. opt->dccpop_type = DCCPO_CONFIRM_L;
  829. break;
  830. default:
  831. DCCP_WARN("invalid type %d\n", type);
  832. kfree(opt);
  833. return;
  834. }
  835. opt->dccpop_feat = feature;
  836. opt->dccpop_val = NULL;
  837. opt->dccpop_len = 0;
  838. /* change feature */
  839. dccp_pr_debug("Empty %s(%d)\n", dccp_feat_typename(type), feature);
  840. list_add_tail(&opt->dccpop_node, &dmsk->dccpms_conf);
  841. }
  842. static void dccp_feat_flush_confirm(struct sock *sk)
  843. {
  844. struct dccp_minisock *dmsk = dccp_msk(sk);
  845. /* Check if there is anything to confirm in the first place */
  846. int yes = !list_empty(&dmsk->dccpms_conf);
  847. if (!yes) {
  848. struct dccp_opt_pend *opt;
  849. list_for_each_entry(opt, &dmsk->dccpms_pending, dccpop_node) {
  850. if (opt->dccpop_conf) {
  851. yes = 1;
  852. break;
  853. }
  854. }
  855. }
  856. if (!yes)
  857. return;
  858. /* OK there is something to confirm... */
  859. /* XXX check if packet is in flight? Send delayed ack?? */
  860. if (sk->sk_state == DCCP_OPEN)
  861. dccp_send_ack(sk);
  862. }
  863. int dccp_feat_change_recv(struct sock *sk, u8 type, u8 feature, u8 *val, u8 len)
  864. {
  865. int rc;
  866. /* Ignore Change requests other than during connection setup */
  867. if (sk->sk_state != DCCP_LISTEN && sk->sk_state != DCCP_REQUESTING)
  868. return 0;
  869. dccp_feat_debug(type, feature, *val);
  870. /* figure out if it's SP or NN feature */
  871. switch (feature) {
  872. /* deal with SP features */
  873. case DCCPF_CCID:
  874. rc = dccp_feat_sp(sk, type, feature, val, len);
  875. break;
  876. /* deal with NN features */
  877. case DCCPF_ACK_RATIO:
  878. rc = dccp_feat_nn(sk, type, feature, val, len);
  879. break;
  880. /* XXX implement other features */
  881. default:
  882. dccp_pr_debug("UNIMPLEMENTED: not handling %s(%d, ...)\n",
  883. dccp_feat_typename(type), feature);
  884. rc = -EFAULT;
  885. break;
  886. }
  887. /* check if there were problems changing features */
  888. if (rc) {
  889. /* If we don't agree on SP, we sent a confirm for old value.
  890. * However we propagate rc to caller in case option was
  891. * mandatory
  892. */
  893. if (rc != DCCP_FEAT_SP_NOAGREE)
  894. dccp_feat_empty_confirm(dccp_msk(sk), type, feature);
  895. }
  896. /* generate the confirm [if required] */
  897. dccp_feat_flush_confirm(sk);
  898. return rc;
  899. }
  900. EXPORT_SYMBOL_GPL(dccp_feat_change_recv);
  901. int dccp_feat_confirm_recv(struct sock *sk, u8 type, u8 feature,
  902. u8 *val, u8 len)
  903. {
  904. u8 t;
  905. struct dccp_opt_pend *opt;
  906. struct dccp_minisock *dmsk = dccp_msk(sk);
  907. int found = 0;
  908. int all_confirmed = 1;
  909. /* Ignore Confirm options other than during connection setup */
  910. if (sk->sk_state != DCCP_LISTEN && sk->sk_state != DCCP_REQUESTING)
  911. return 0;
  912. dccp_feat_debug(type, feature, *val);
  913. /* locate our change request */
  914. switch (type) {
  915. case DCCPO_CONFIRM_L: t = DCCPO_CHANGE_R; break;
  916. case DCCPO_CONFIRM_R: t = DCCPO_CHANGE_L; break;
  917. default: DCCP_WARN("invalid type %d\n", type);
  918. return 1;
  919. }
  920. /* XXX sanity check feature value */
  921. list_for_each_entry(opt, &dmsk->dccpms_pending, dccpop_node) {
  922. if (!opt->dccpop_conf && opt->dccpop_type == t &&
  923. opt->dccpop_feat == feature) {
  924. found = 1;
  925. dccp_pr_debug("feature %d found\n", opt->dccpop_feat);
  926. /* XXX do sanity check */
  927. opt->dccpop_conf = 1;
  928. /* We got a confirmation---change the option */
  929. dccp_feat_update(sk, opt->dccpop_type,
  930. opt->dccpop_feat, *val);
  931. /* XXX check the return value of dccp_feat_update */
  932. break;
  933. }
  934. if (!opt->dccpop_conf)
  935. all_confirmed = 0;
  936. }
  937. if (!found)
  938. dccp_pr_debug("%s(%d, ...) never requested\n",
  939. dccp_feat_typename(type), feature);
  940. return 0;
  941. }
  942. EXPORT_SYMBOL_GPL(dccp_feat_confirm_recv);
  943. void dccp_feat_clean(struct dccp_minisock *dmsk)
  944. {
  945. struct dccp_opt_pend *opt, *next;
  946. list_for_each_entry_safe(opt, next, &dmsk->dccpms_pending,
  947. dccpop_node) {
  948. BUG_ON(opt->dccpop_val == NULL);
  949. kfree(opt->dccpop_val);
  950. if (opt->dccpop_sc != NULL) {
  951. BUG_ON(opt->dccpop_sc->dccpoc_val == NULL);
  952. kfree(opt->dccpop_sc->dccpoc_val);
  953. kfree(opt->dccpop_sc);
  954. }
  955. kfree(opt);
  956. }
  957. INIT_LIST_HEAD(&dmsk->dccpms_pending);
  958. list_for_each_entry_safe(opt, next, &dmsk->dccpms_conf, dccpop_node) {
  959. BUG_ON(opt == NULL);
  960. if (opt->dccpop_val != NULL)
  961. kfree(opt->dccpop_val);
  962. kfree(opt);
  963. }
  964. INIT_LIST_HEAD(&dmsk->dccpms_conf);
  965. }
  966. EXPORT_SYMBOL_GPL(dccp_feat_clean);
  967. /* this is to be called only when a listening sock creates its child. It is
  968. * assumed by the function---the confirm is not duplicated, but rather it is
  969. * "passed on".
  970. */
  971. int dccp_feat_clone(struct sock *oldsk, struct sock *newsk)
  972. {
  973. struct dccp_minisock *olddmsk = dccp_msk(oldsk);
  974. struct dccp_minisock *newdmsk = dccp_msk(newsk);
  975. struct dccp_opt_pend *opt;
  976. int rc = 0;
  977. INIT_LIST_HEAD(&newdmsk->dccpms_pending);
  978. INIT_LIST_HEAD(&newdmsk->dccpms_conf);
  979. list_for_each_entry(opt, &olddmsk->dccpms_pending, dccpop_node) {
  980. struct dccp_opt_pend *newopt;
  981. /* copy the value of the option */
  982. u8 *val = kmemdup(opt->dccpop_val, opt->dccpop_len, GFP_ATOMIC);
  983. if (val == NULL)
  984. goto out_clean;
  985. newopt = kmemdup(opt, sizeof(*newopt), GFP_ATOMIC);
  986. if (newopt == NULL) {
  987. kfree(val);
  988. goto out_clean;
  989. }
  990. /* insert the option */
  991. newopt->dccpop_val = val;
  992. list_add_tail(&newopt->dccpop_node, &newdmsk->dccpms_pending);
  993. /* XXX what happens with backlogs and multiple connections at
  994. * once...
  995. */
  996. /* the master socket no longer needs to worry about confirms */
  997. opt->dccpop_sc = NULL; /* it's not a memleak---new socket has it */
  998. /* reset state for a new socket */
  999. opt->dccpop_conf = 0;
  1000. }
  1001. /* XXX not doing anything about the conf queue */
  1002. out:
  1003. return rc;
  1004. out_clean:
  1005. dccp_feat_clean(newdmsk);
  1006. rc = -ENOMEM;
  1007. goto out;
  1008. }
  1009. EXPORT_SYMBOL_GPL(dccp_feat_clone);
  1010. int dccp_feat_init(struct sock *sk)
  1011. {
  1012. struct dccp_sock *dp = dccp_sk(sk);
  1013. struct dccp_minisock *dmsk = dccp_msk(sk);
  1014. int rc;
  1015. INIT_LIST_HEAD(&dmsk->dccpms_pending); /* XXX no longer used */
  1016. INIT_LIST_HEAD(&dmsk->dccpms_conf); /* XXX no longer used */
  1017. /* CCID L */
  1018. rc = __feat_register_sp(&dp->dccps_featneg, DCCPF_CCID, 1, 0,
  1019. &dmsk->dccpms_tx_ccid, 1);
  1020. if (rc)
  1021. goto out;
  1022. /* CCID R */
  1023. rc = __feat_register_sp(&dp->dccps_featneg, DCCPF_CCID, 0, 0,
  1024. &dmsk->dccpms_rx_ccid, 1);
  1025. if (rc)
  1026. goto out;
  1027. /* Ack ratio */
  1028. rc = __feat_register_nn(&dp->dccps_featneg, DCCPF_ACK_RATIO, 0,
  1029. dp->dccps_l_ack_ratio);
  1030. out:
  1031. return rc;
  1032. }
  1033. EXPORT_SYMBOL_GPL(dccp_feat_init);
  1034. #ifdef CONFIG_IP_DCCP_DEBUG
  1035. const char *dccp_feat_typename(const u8 type)
  1036. {
  1037. switch(type) {
  1038. case DCCPO_CHANGE_L: return("ChangeL");
  1039. case DCCPO_CONFIRM_L: return("ConfirmL");
  1040. case DCCPO_CHANGE_R: return("ChangeR");
  1041. case DCCPO_CONFIRM_R: return("ConfirmR");
  1042. /* the following case must not appear in feature negotation */
  1043. default: dccp_pr_debug("unknown type %d [BUG!]\n", type);
  1044. }
  1045. return NULL;
  1046. }
  1047. EXPORT_SYMBOL_GPL(dccp_feat_typename);
  1048. const char *dccp_feat_name(const u8 feat)
  1049. {
  1050. static const char *feature_names[] = {
  1051. [DCCPF_RESERVED] = "Reserved",
  1052. [DCCPF_CCID] = "CCID",
  1053. [DCCPF_SHORT_SEQNOS] = "Allow Short Seqnos",
  1054. [DCCPF_SEQUENCE_WINDOW] = "Sequence Window",
  1055. [DCCPF_ECN_INCAPABLE] = "ECN Incapable",
  1056. [DCCPF_ACK_RATIO] = "Ack Ratio",
  1057. [DCCPF_SEND_ACK_VECTOR] = "Send ACK Vector",
  1058. [DCCPF_SEND_NDP_COUNT] = "Send NDP Count",
  1059. [DCCPF_MIN_CSUM_COVER] = "Min. Csum Coverage",
  1060. [DCCPF_DATA_CHECKSUM] = "Send Data Checksum",
  1061. };
  1062. if (feat > DCCPF_DATA_CHECKSUM && feat < DCCPF_MIN_CCID_SPECIFIC)
  1063. return feature_names[DCCPF_RESERVED];
  1064. if (feat == DCCPF_SEND_LEV_RATE)
  1065. return "Send Loss Event Rate";
  1066. if (feat >= DCCPF_MIN_CCID_SPECIFIC)
  1067. return "CCID-specific";
  1068. return feature_names[feat];
  1069. }
  1070. EXPORT_SYMBOL_GPL(dccp_feat_name);
  1071. #endif /* CONFIG_IP_DCCP_DEBUG */