feat.c 35 KB

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