feat.c 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744
  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. /*
  25. * Feature activation handlers.
  26. *
  27. * These all use an u64 argument, to provide enough room for NN/SP features. At
  28. * this stage the negotiated values have been checked to be within their range.
  29. */
  30. static int dccp_hdlr_ccid(struct sock *sk, u64 ccid, bool rx)
  31. {
  32. struct dccp_sock *dp = dccp_sk(sk);
  33. struct ccid *new_ccid = ccid_new(ccid, sk, rx, gfp_any());
  34. if (new_ccid == NULL)
  35. return -ENOMEM;
  36. if (rx) {
  37. ccid_hc_rx_delete(dp->dccps_hc_rx_ccid, sk);
  38. dp->dccps_hc_rx_ccid = new_ccid;
  39. } else {
  40. ccid_hc_tx_delete(dp->dccps_hc_tx_ccid, sk);
  41. dp->dccps_hc_tx_ccid = new_ccid;
  42. }
  43. return 0;
  44. }
  45. static int dccp_hdlr_seq_win(struct sock *sk, u64 seq_win, bool rx)
  46. {
  47. if (!rx)
  48. dccp_msk(sk)->dccpms_sequence_window = seq_win;
  49. return 0;
  50. }
  51. static int dccp_hdlr_ack_ratio(struct sock *sk, u64 ratio, bool rx)
  52. {
  53. if (rx)
  54. dccp_sk(sk)->dccps_r_ack_ratio = ratio;
  55. else
  56. dccp_sk(sk)->dccps_l_ack_ratio = ratio;
  57. return 0;
  58. }
  59. static int dccp_hdlr_ackvec(struct sock *sk, u64 enable, bool rx)
  60. {
  61. struct dccp_sock *dp = dccp_sk(sk);
  62. if (rx) {
  63. if (enable && dp->dccps_hc_rx_ackvec == NULL) {
  64. dp->dccps_hc_rx_ackvec = dccp_ackvec_alloc(gfp_any());
  65. if (dp->dccps_hc_rx_ackvec == NULL)
  66. return -ENOMEM;
  67. } else if (!enable) {
  68. dccp_ackvec_free(dp->dccps_hc_rx_ackvec);
  69. dp->dccps_hc_rx_ackvec = NULL;
  70. }
  71. }
  72. return 0;
  73. }
  74. static int dccp_hdlr_ndp(struct sock *sk, u64 enable, bool rx)
  75. {
  76. if (!rx)
  77. dccp_msk(sk)->dccpms_send_ndp_count = (enable > 0);
  78. return 0;
  79. }
  80. /*
  81. * Minimum Checksum Coverage is located at the RX side (9.2.1). This means that
  82. * `rx' holds when the sending peer informs about his partial coverage via a
  83. * ChangeR() option. In the other case, we are the sender and the receiver
  84. * announces its coverage via ChangeL() options. The policy here is to honour
  85. * such communication by enabling the corresponding partial coverage - but only
  86. * if it has not been set manually before; the warning here means that all
  87. * packets will be dropped.
  88. */
  89. static int dccp_hdlr_min_cscov(struct sock *sk, u64 cscov, bool rx)
  90. {
  91. struct dccp_sock *dp = dccp_sk(sk);
  92. if (rx)
  93. dp->dccps_pcrlen = cscov;
  94. else {
  95. if (dp->dccps_pcslen == 0)
  96. dp->dccps_pcslen = cscov;
  97. else if (cscov > dp->dccps_pcslen)
  98. DCCP_WARN("CsCov %u too small, peer requires >= %u\n",
  99. dp->dccps_pcslen, (u8)cscov);
  100. }
  101. return 0;
  102. }
  103. static const struct {
  104. u8 feat_num; /* DCCPF_xxx */
  105. enum dccp_feat_type rxtx; /* RX or TX */
  106. enum dccp_feat_type reconciliation; /* SP or NN */
  107. u8 default_value; /* as in 6.4 */
  108. int (*activation_hdlr)(struct sock *sk, u64 val, bool rx);
  109. /*
  110. * Lookup table for location and type of features (from RFC 4340/4342)
  111. * +--------------------------+----+-----+----+----+---------+-----------+
  112. * | Feature | Location | Reconc. | Initial | Section |
  113. * | | RX | TX | SP | NN | Value | Reference |
  114. * +--------------------------+----+-----+----+----+---------+-----------+
  115. * | DCCPF_CCID | | X | X | | 2 | 10 |
  116. * | DCCPF_SHORT_SEQNOS | | X | X | | 0 | 7.6.1 |
  117. * | DCCPF_SEQUENCE_WINDOW | | X | | X | 100 | 7.5.2 |
  118. * | DCCPF_ECN_INCAPABLE | X | | X | | 0 | 12.1 |
  119. * | DCCPF_ACK_RATIO | | X | | X | 2 | 11.3 |
  120. * | DCCPF_SEND_ACK_VECTOR | X | | X | | 0 | 11.5 |
  121. * | DCCPF_SEND_NDP_COUNT | | X | X | | 0 | 7.7.2 |
  122. * | DCCPF_MIN_CSUM_COVER | X | | X | | 0 | 9.2.1 |
  123. * | DCCPF_DATA_CHECKSUM | X | | X | | 0 | 9.3.1 |
  124. * | DCCPF_SEND_LEV_RATE | X | | X | | 0 | 4342/8.4 |
  125. * +--------------------------+----+-----+----+----+---------+-----------+
  126. */
  127. } dccp_feat_table[] = {
  128. { DCCPF_CCID, FEAT_AT_TX, FEAT_SP, 2, dccp_hdlr_ccid },
  129. { DCCPF_SHORT_SEQNOS, FEAT_AT_TX, FEAT_SP, 0, NULL },
  130. { DCCPF_SEQUENCE_WINDOW, FEAT_AT_TX, FEAT_NN, 100, dccp_hdlr_seq_win },
  131. { DCCPF_ECN_INCAPABLE, FEAT_AT_RX, FEAT_SP, 0, NULL },
  132. { DCCPF_ACK_RATIO, FEAT_AT_TX, FEAT_NN, 2, dccp_hdlr_ack_ratio},
  133. { DCCPF_SEND_ACK_VECTOR, FEAT_AT_RX, FEAT_SP, 0, dccp_hdlr_ackvec },
  134. { DCCPF_SEND_NDP_COUNT, FEAT_AT_TX, FEAT_SP, 0, dccp_hdlr_ndp },
  135. { DCCPF_MIN_CSUM_COVER, FEAT_AT_RX, FEAT_SP, 0, dccp_hdlr_min_cscov},
  136. { DCCPF_DATA_CHECKSUM, FEAT_AT_RX, FEAT_SP, 0, NULL },
  137. { DCCPF_SEND_LEV_RATE, FEAT_AT_RX, FEAT_SP, 0, NULL },
  138. };
  139. #define DCCP_FEAT_SUPPORTED_MAX ARRAY_SIZE(dccp_feat_table)
  140. /**
  141. * dccp_feat_index - Hash function to map feature number into array position
  142. * Returns consecutive array index or -1 if the feature is not understood.
  143. */
  144. static int dccp_feat_index(u8 feat_num)
  145. {
  146. /* The first 9 entries are occupied by the types from RFC 4340, 6.4 */
  147. if (feat_num > DCCPF_RESERVED && feat_num <= DCCPF_DATA_CHECKSUM)
  148. return feat_num - 1;
  149. /*
  150. * Other features: add cases for new feature types here after adding
  151. * them to the above table.
  152. */
  153. switch (feat_num) {
  154. case DCCPF_SEND_LEV_RATE:
  155. return DCCP_FEAT_SUPPORTED_MAX - 1;
  156. }
  157. return -1;
  158. }
  159. static u8 dccp_feat_type(u8 feat_num)
  160. {
  161. int idx = dccp_feat_index(feat_num);
  162. if (idx < 0)
  163. return FEAT_UNKNOWN;
  164. return dccp_feat_table[idx].reconciliation;
  165. }
  166. static int dccp_feat_default_value(u8 feat_num)
  167. {
  168. int idx = dccp_feat_index(feat_num);
  169. return idx < 0 ? : dccp_feat_table[idx].default_value;
  170. }
  171. static int __dccp_feat_activate(struct sock *sk, const int idx,
  172. const bool is_local, dccp_feat_val const *fval)
  173. {
  174. bool rx;
  175. u64 val;
  176. if (idx < 0 || idx >= DCCP_FEAT_SUPPORTED_MAX)
  177. return -1;
  178. if (dccp_feat_table[idx].activation_hdlr == NULL)
  179. return 0;
  180. if (fval == NULL) {
  181. val = dccp_feat_table[idx].default_value;
  182. } else if (dccp_feat_table[idx].reconciliation == FEAT_SP) {
  183. if (fval->sp.vec == NULL) {
  184. /*
  185. * This can happen when an empty Confirm is sent
  186. * for an SP (i.e. known) feature. In this case
  187. * we would be using the default anyway.
  188. */
  189. DCCP_CRIT("Feature #%d undefined: using default", idx);
  190. val = dccp_feat_table[idx].default_value;
  191. } else {
  192. val = fval->sp.vec[0];
  193. }
  194. } else {
  195. val = fval->nn;
  196. }
  197. /* Location is RX if this is a local-RX or remote-TX feature */
  198. rx = (is_local == (dccp_feat_table[idx].rxtx == FEAT_AT_RX));
  199. return dccp_feat_table[idx].activation_hdlr(sk, val, rx);
  200. }
  201. /* Test for "Req'd" feature (RFC 4340, 6.4) */
  202. static inline int dccp_feat_must_be_understood(u8 feat_num)
  203. {
  204. return feat_num == DCCPF_CCID || feat_num == DCCPF_SHORT_SEQNOS ||
  205. feat_num == DCCPF_SEQUENCE_WINDOW;
  206. }
  207. /* copy constructor, fval must not already contain allocated memory */
  208. static int dccp_feat_clone_sp_val(dccp_feat_val *fval, u8 const *val, u8 len)
  209. {
  210. fval->sp.len = len;
  211. if (fval->sp.len > 0) {
  212. fval->sp.vec = kmemdup(val, len, gfp_any());
  213. if (fval->sp.vec == NULL) {
  214. fval->sp.len = 0;
  215. return -ENOBUFS;
  216. }
  217. }
  218. return 0;
  219. }
  220. static void dccp_feat_val_destructor(u8 feat_num, dccp_feat_val *val)
  221. {
  222. if (unlikely(val == NULL))
  223. return;
  224. if (dccp_feat_type(feat_num) == FEAT_SP)
  225. kfree(val->sp.vec);
  226. memset(val, 0, sizeof(*val));
  227. }
  228. static struct dccp_feat_entry *
  229. dccp_feat_clone_entry(struct dccp_feat_entry const *original)
  230. {
  231. struct dccp_feat_entry *new;
  232. u8 type = dccp_feat_type(original->feat_num);
  233. if (type == FEAT_UNKNOWN)
  234. return NULL;
  235. new = kmemdup(original, sizeof(struct dccp_feat_entry), gfp_any());
  236. if (new == NULL)
  237. return NULL;
  238. if (type == FEAT_SP && dccp_feat_clone_sp_val(&new->val,
  239. original->val.sp.vec,
  240. original->val.sp.len)) {
  241. kfree(new);
  242. return NULL;
  243. }
  244. return new;
  245. }
  246. static void dccp_feat_entry_destructor(struct dccp_feat_entry *entry)
  247. {
  248. if (entry != NULL) {
  249. dccp_feat_val_destructor(entry->feat_num, &entry->val);
  250. kfree(entry);
  251. }
  252. }
  253. /*
  254. * List management functions
  255. *
  256. * Feature negotiation lists rely on and maintain the following invariants:
  257. * - each feat_num in the list is known, i.e. we know its type and default value
  258. * - each feat_num/is_local combination is unique (old entries are overwritten)
  259. * - SP values are always freshly allocated
  260. * - list is sorted in increasing order of feature number (faster lookup)
  261. */
  262. static struct dccp_feat_entry *dccp_feat_list_lookup(struct list_head *fn_list,
  263. u8 feat_num, bool is_local)
  264. {
  265. struct dccp_feat_entry *entry;
  266. list_for_each_entry(entry, fn_list, node)
  267. if (entry->feat_num == feat_num && entry->is_local == is_local)
  268. return entry;
  269. else if (entry->feat_num > feat_num)
  270. break;
  271. return NULL;
  272. }
  273. /**
  274. * dccp_feat_entry_new - Central list update routine (called by all others)
  275. * @head: list to add to
  276. * @feat: feature number
  277. * @local: whether the local (1) or remote feature with number @feat is meant
  278. * This is the only constructor and serves to ensure the above invariants.
  279. */
  280. static struct dccp_feat_entry *
  281. dccp_feat_entry_new(struct list_head *head, u8 feat, bool local)
  282. {
  283. struct dccp_feat_entry *entry;
  284. list_for_each_entry(entry, head, node)
  285. if (entry->feat_num == feat && entry->is_local == local) {
  286. dccp_feat_val_destructor(entry->feat_num, &entry->val);
  287. return entry;
  288. } else if (entry->feat_num > feat) {
  289. head = &entry->node;
  290. break;
  291. }
  292. entry = kmalloc(sizeof(*entry), gfp_any());
  293. if (entry != NULL) {
  294. entry->feat_num = feat;
  295. entry->is_local = local;
  296. list_add_tail(&entry->node, head);
  297. }
  298. return entry;
  299. }
  300. /**
  301. * dccp_feat_push_change - Add/overwrite a Change option in the list
  302. * @fn_list: feature-negotiation list to update
  303. * @feat: one of %dccp_feature_numbers
  304. * @local: whether local (1) or remote (0) @feat_num is meant
  305. * @needs_mandatory: whether to use Mandatory feature negotiation options
  306. * @fval: pointer to NN/SP value to be inserted (will be copied)
  307. */
  308. static int dccp_feat_push_change(struct list_head *fn_list, u8 feat, u8 local,
  309. u8 mandatory, dccp_feat_val *fval)
  310. {
  311. struct dccp_feat_entry *new = dccp_feat_entry_new(fn_list, feat, local);
  312. if (new == NULL)
  313. return -ENOMEM;
  314. new->feat_num = feat;
  315. new->is_local = local;
  316. new->state = FEAT_INITIALISING;
  317. new->needs_confirm = 0;
  318. new->empty_confirm = 0;
  319. new->val = *fval;
  320. new->needs_mandatory = mandatory;
  321. return 0;
  322. }
  323. /**
  324. * dccp_feat_push_confirm - Add a Confirm entry to the FN list
  325. * @fn_list: feature-negotiation list to add to
  326. * @feat: one of %dccp_feature_numbers
  327. * @local: whether local (1) or remote (0) @feat_num is being confirmed
  328. * @fval: pointer to NN/SP value to be inserted or NULL
  329. * Returns 0 on success, a Reset code for further processing otherwise.
  330. */
  331. static int dccp_feat_push_confirm(struct list_head *fn_list, u8 feat, u8 local,
  332. dccp_feat_val *fval)
  333. {
  334. struct dccp_feat_entry *new = dccp_feat_entry_new(fn_list, feat, local);
  335. if (new == NULL)
  336. return DCCP_RESET_CODE_TOO_BUSY;
  337. new->feat_num = feat;
  338. new->is_local = local;
  339. new->state = FEAT_STABLE; /* transition in 6.6.2 */
  340. new->needs_confirm = 1;
  341. new->empty_confirm = (fval == NULL);
  342. new->val.nn = 0; /* zeroes the whole structure */
  343. if (!new->empty_confirm)
  344. new->val = *fval;
  345. new->needs_mandatory = 0;
  346. return 0;
  347. }
  348. static int dccp_push_empty_confirm(struct list_head *fn_list, u8 feat, u8 local)
  349. {
  350. return dccp_feat_push_confirm(fn_list, feat, local, NULL);
  351. }
  352. static inline void dccp_feat_list_pop(struct dccp_feat_entry *entry)
  353. {
  354. list_del(&entry->node);
  355. dccp_feat_entry_destructor(entry);
  356. }
  357. void dccp_feat_list_purge(struct list_head *fn_list)
  358. {
  359. struct dccp_feat_entry *entry, *next;
  360. list_for_each_entry_safe(entry, next, fn_list, node)
  361. dccp_feat_entry_destructor(entry);
  362. INIT_LIST_HEAD(fn_list);
  363. }
  364. EXPORT_SYMBOL_GPL(dccp_feat_list_purge);
  365. /* generate @to as full clone of @from - @to must not contain any nodes */
  366. int dccp_feat_clone_list(struct list_head const *from, struct list_head *to)
  367. {
  368. struct dccp_feat_entry *entry, *new;
  369. INIT_LIST_HEAD(to);
  370. list_for_each_entry(entry, from, node) {
  371. new = dccp_feat_clone_entry(entry);
  372. if (new == NULL)
  373. goto cloning_failed;
  374. list_add_tail(&new->node, to);
  375. }
  376. return 0;
  377. cloning_failed:
  378. dccp_feat_list_purge(to);
  379. return -ENOMEM;
  380. }
  381. /**
  382. * dccp_feat_valid_nn_length - Enforce length constraints on NN options
  383. * Length is between 0 and %DCCP_OPTVAL_MAXLEN. Used for outgoing packets only,
  384. * incoming options are accepted as long as their values are valid.
  385. */
  386. static u8 dccp_feat_valid_nn_length(u8 feat_num)
  387. {
  388. if (feat_num == DCCPF_ACK_RATIO) /* RFC 4340, 11.3 and 6.6.8 */
  389. return 2;
  390. if (feat_num == DCCPF_SEQUENCE_WINDOW) /* RFC 4340, 7.5.2 and 6.5 */
  391. return 6;
  392. return 0;
  393. }
  394. static u8 dccp_feat_is_valid_nn_val(u8 feat_num, u64 val)
  395. {
  396. switch (feat_num) {
  397. case DCCPF_ACK_RATIO:
  398. return val <= DCCPF_ACK_RATIO_MAX;
  399. case DCCPF_SEQUENCE_WINDOW:
  400. return val >= DCCPF_SEQ_WMIN && val <= DCCPF_SEQ_WMAX;
  401. }
  402. return 0; /* feature unknown - so we can't tell */
  403. }
  404. /* check that SP values are within the ranges defined in RFC 4340 */
  405. static u8 dccp_feat_is_valid_sp_val(u8 feat_num, u8 val)
  406. {
  407. switch (feat_num) {
  408. case DCCPF_CCID:
  409. return val == DCCPC_CCID2 || val == DCCPC_CCID3;
  410. /* Type-check Boolean feature values: */
  411. case DCCPF_SHORT_SEQNOS:
  412. case DCCPF_ECN_INCAPABLE:
  413. case DCCPF_SEND_ACK_VECTOR:
  414. case DCCPF_SEND_NDP_COUNT:
  415. case DCCPF_DATA_CHECKSUM:
  416. case DCCPF_SEND_LEV_RATE:
  417. return val < 2;
  418. case DCCPF_MIN_CSUM_COVER:
  419. return val < 16;
  420. }
  421. return 0; /* feature unknown */
  422. }
  423. static u8 dccp_feat_sp_list_ok(u8 feat_num, u8 const *sp_list, u8 sp_len)
  424. {
  425. if (sp_list == NULL || sp_len < 1)
  426. return 0;
  427. while (sp_len--)
  428. if (!dccp_feat_is_valid_sp_val(feat_num, *sp_list++))
  429. return 0;
  430. return 1;
  431. }
  432. /**
  433. * dccp_feat_insert_opts - Generate FN options from current list state
  434. * @skb: next sk_buff to be sent to the peer
  435. * @dp: for client during handshake and general negotiation
  436. * @dreq: used by the server only (all Changes/Confirms in LISTEN/RESPOND)
  437. */
  438. int dccp_feat_insert_opts(struct dccp_sock *dp, struct dccp_request_sock *dreq,
  439. struct sk_buff *skb)
  440. {
  441. struct list_head *fn = dreq ? &dreq->dreq_featneg : &dp->dccps_featneg;
  442. struct dccp_feat_entry *pos, *next;
  443. u8 opt, type, len, *ptr, nn_in_nbo[DCCP_OPTVAL_MAXLEN];
  444. bool rpt;
  445. /* put entries into @skb in the order they appear in the list */
  446. list_for_each_entry_safe_reverse(pos, next, fn, node) {
  447. opt = dccp_feat_genopt(pos);
  448. type = dccp_feat_type(pos->feat_num);
  449. rpt = false;
  450. if (pos->empty_confirm) {
  451. len = 0;
  452. ptr = NULL;
  453. } else {
  454. if (type == FEAT_SP) {
  455. len = pos->val.sp.len;
  456. ptr = pos->val.sp.vec;
  457. rpt = pos->needs_confirm;
  458. } else if (type == FEAT_NN) {
  459. len = dccp_feat_valid_nn_length(pos->feat_num);
  460. ptr = nn_in_nbo;
  461. dccp_encode_value_var(pos->val.nn, ptr, len);
  462. } else {
  463. DCCP_BUG("unknown feature %u", pos->feat_num);
  464. return -1;
  465. }
  466. }
  467. if (dccp_insert_fn_opt(skb, opt, pos->feat_num, ptr, len, rpt))
  468. return -1;
  469. if (pos->needs_mandatory && dccp_insert_option_mandatory(skb))
  470. return -1;
  471. /*
  472. * Enter CHANGING after transmitting the Change option (6.6.2).
  473. */
  474. if (pos->state == FEAT_INITIALISING)
  475. pos->state = FEAT_CHANGING;
  476. }
  477. return 0;
  478. }
  479. /**
  480. * __feat_register_nn - Register new NN value on socket
  481. * @fn: feature-negotiation list to register with
  482. * @feat: an NN feature from %dccp_feature_numbers
  483. * @mandatory: use Mandatory option if 1
  484. * @nn_val: value to register (restricted to 4 bytes)
  485. * Note that NN features are local by definition (RFC 4340, 6.3.2).
  486. */
  487. static int __feat_register_nn(struct list_head *fn, u8 feat,
  488. u8 mandatory, u64 nn_val)
  489. {
  490. dccp_feat_val fval = { .nn = nn_val };
  491. if (dccp_feat_type(feat) != FEAT_NN ||
  492. !dccp_feat_is_valid_nn_val(feat, nn_val))
  493. return -EINVAL;
  494. /* Don't bother with default values, they will be activated anyway. */
  495. if (nn_val - (u64)dccp_feat_default_value(feat) == 0)
  496. return 0;
  497. return dccp_feat_push_change(fn, feat, 1, mandatory, &fval);
  498. }
  499. /**
  500. * __feat_register_sp - Register new SP value/list on socket
  501. * @fn: feature-negotiation list to register with
  502. * @feat: an SP feature from %dccp_feature_numbers
  503. * @is_local: whether the local (1) or the remote (0) @feat is meant
  504. * @mandatory: use Mandatory option if 1
  505. * @sp_val: SP value followed by optional preference list
  506. * @sp_len: length of @sp_val in bytes
  507. */
  508. static int __feat_register_sp(struct list_head *fn, u8 feat, u8 is_local,
  509. u8 mandatory, u8 const *sp_val, u8 sp_len)
  510. {
  511. dccp_feat_val fval;
  512. if (dccp_feat_type(feat) != FEAT_SP ||
  513. !dccp_feat_sp_list_ok(feat, sp_val, sp_len))
  514. return -EINVAL;
  515. /* Avoid negotiating alien CCIDs by only advertising supported ones */
  516. if (feat == DCCPF_CCID && !ccid_support_check(sp_val, sp_len))
  517. return -EOPNOTSUPP;
  518. if (dccp_feat_clone_sp_val(&fval, sp_val, sp_len))
  519. return -ENOMEM;
  520. return dccp_feat_push_change(fn, feat, is_local, mandatory, &fval);
  521. }
  522. /**
  523. * dccp_feat_register_sp - Register requests to change SP feature values
  524. * @sk: client or listening socket
  525. * @feat: one of %dccp_feature_numbers
  526. * @is_local: whether the local (1) or remote (0) @feat is meant
  527. * @list: array of preferred values, in descending order of preference
  528. * @len: length of @list in bytes
  529. */
  530. int dccp_feat_register_sp(struct sock *sk, u8 feat, u8 is_local,
  531. u8 const *list, u8 len)
  532. { /* any changes must be registered before establishing the connection */
  533. if (sk->sk_state != DCCP_CLOSED)
  534. return -EISCONN;
  535. if (dccp_feat_type(feat) != FEAT_SP)
  536. return -EINVAL;
  537. return __feat_register_sp(&dccp_sk(sk)->dccps_featneg, feat, is_local,
  538. 0, list, len);
  539. }
  540. /* Analogous to dccp_feat_register_sp(), but for non-negotiable values */
  541. int dccp_feat_register_nn(struct sock *sk, u8 feat, u64 val)
  542. {
  543. /* any changes must be registered before establishing the connection */
  544. if (sk->sk_state != DCCP_CLOSED)
  545. return -EISCONN;
  546. if (dccp_feat_type(feat) != FEAT_NN)
  547. return -EINVAL;
  548. return __feat_register_nn(&dccp_sk(sk)->dccps_featneg, feat, 0, val);
  549. }
  550. /*
  551. * Tracking features whose value depend on the choice of CCID
  552. *
  553. * This is designed with an extension in mind so that a list walk could be done
  554. * before activating any features. However, the existing framework was found to
  555. * work satisfactorily up until now, the automatic verification is left open.
  556. * When adding new CCIDs, add a corresponding dependency table here.
  557. */
  558. static const struct ccid_dependency *dccp_feat_ccid_deps(u8 ccid, bool is_local)
  559. {
  560. static const struct ccid_dependency ccid2_dependencies[2][2] = {
  561. /*
  562. * CCID2 mandates Ack Vectors (RFC 4341, 4.): as CCID is a TX
  563. * feature and Send Ack Vector is an RX feature, `is_local'
  564. * needs to be reversed.
  565. */
  566. { /* Dependencies of the receiver-side (remote) CCID2 */
  567. {
  568. .dependent_feat = DCCPF_SEND_ACK_VECTOR,
  569. .is_local = true,
  570. .is_mandatory = true,
  571. .val = 1
  572. },
  573. { 0, 0, 0, 0 }
  574. },
  575. { /* Dependencies of the sender-side (local) CCID2 */
  576. {
  577. .dependent_feat = DCCPF_SEND_ACK_VECTOR,
  578. .is_local = false,
  579. .is_mandatory = true,
  580. .val = 1
  581. },
  582. { 0, 0, 0, 0 }
  583. }
  584. };
  585. static const struct ccid_dependency ccid3_dependencies[2][5] = {
  586. { /*
  587. * Dependencies of the receiver-side CCID3
  588. */
  589. { /* locally disable Ack Vectors */
  590. .dependent_feat = DCCPF_SEND_ACK_VECTOR,
  591. .is_local = true,
  592. .is_mandatory = false,
  593. .val = 0
  594. },
  595. { /* see below why Send Loss Event Rate is on */
  596. .dependent_feat = DCCPF_SEND_LEV_RATE,
  597. .is_local = true,
  598. .is_mandatory = true,
  599. .val = 1
  600. },
  601. { /* NDP Count is needed as per RFC 4342, 6.1.1 */
  602. .dependent_feat = DCCPF_SEND_NDP_COUNT,
  603. .is_local = false,
  604. .is_mandatory = true,
  605. .val = 1
  606. },
  607. { 0, 0, 0, 0 },
  608. },
  609. { /*
  610. * CCID3 at the TX side: we request that the HC-receiver
  611. * will not send Ack Vectors (they will be ignored, so
  612. * Mandatory is not set); we enable Send Loss Event Rate
  613. * (Mandatory since the implementation does not support
  614. * the Loss Intervals option of RFC 4342, 8.6).
  615. * The last two options are for peer's information only.
  616. */
  617. {
  618. .dependent_feat = DCCPF_SEND_ACK_VECTOR,
  619. .is_local = false,
  620. .is_mandatory = false,
  621. .val = 0
  622. },
  623. {
  624. .dependent_feat = DCCPF_SEND_LEV_RATE,
  625. .is_local = false,
  626. .is_mandatory = true,
  627. .val = 1
  628. },
  629. { /* this CCID does not support Ack Ratio */
  630. .dependent_feat = DCCPF_ACK_RATIO,
  631. .is_local = true,
  632. .is_mandatory = false,
  633. .val = 0
  634. },
  635. { /* tell receiver we are sending NDP counts */
  636. .dependent_feat = DCCPF_SEND_NDP_COUNT,
  637. .is_local = true,
  638. .is_mandatory = false,
  639. .val = 1
  640. },
  641. { 0, 0, 0, 0 }
  642. }
  643. };
  644. switch (ccid) {
  645. case DCCPC_CCID2:
  646. return ccid2_dependencies[is_local];
  647. case DCCPC_CCID3:
  648. return ccid3_dependencies[is_local];
  649. default:
  650. return NULL;
  651. }
  652. }
  653. /**
  654. * dccp_feat_propagate_ccid - Resolve dependencies of features on choice of CCID
  655. * @fn: feature-negotiation list to update
  656. * @id: CCID number to track
  657. * @is_local: whether TX CCID (1) or RX CCID (0) is meant
  658. * This function needs to be called after registering all other features.
  659. */
  660. static int dccp_feat_propagate_ccid(struct list_head *fn, u8 id, bool is_local)
  661. {
  662. const struct ccid_dependency *table = dccp_feat_ccid_deps(id, is_local);
  663. int i, rc = (table == NULL);
  664. for (i = 0; rc == 0 && table[i].dependent_feat != DCCPF_RESERVED; i++)
  665. if (dccp_feat_type(table[i].dependent_feat) == FEAT_SP)
  666. rc = __feat_register_sp(fn, table[i].dependent_feat,
  667. table[i].is_local,
  668. table[i].is_mandatory,
  669. &table[i].val, 1);
  670. else
  671. rc = __feat_register_nn(fn, table[i].dependent_feat,
  672. table[i].is_mandatory,
  673. table[i].val);
  674. return rc;
  675. }
  676. /**
  677. * dccp_feat_finalise_settings - Finalise settings before starting negotiation
  678. * @dp: client or listening socket (settings will be inherited)
  679. * This is called after all registrations (socket initialisation, sysctls, and
  680. * sockopt calls), and before sending the first packet containing Change options
  681. * (ie. client-Request or server-Response), to ensure internal consistency.
  682. */
  683. int dccp_feat_finalise_settings(struct dccp_sock *dp)
  684. {
  685. struct list_head *fn = &dp->dccps_featneg;
  686. struct dccp_feat_entry *entry;
  687. int i = 2, ccids[2] = { -1, -1 };
  688. /*
  689. * Propagating CCIDs:
  690. * 1) not useful to propagate CCID settings if this host advertises more
  691. * than one CCID: the choice of CCID may still change - if this is
  692. * the client, or if this is the server and the client sends
  693. * singleton CCID values.
  694. * 2) since is that propagate_ccid changes the list, we defer changing
  695. * the sorted list until after the traversal.
  696. */
  697. list_for_each_entry(entry, fn, node)
  698. if (entry->feat_num == DCCPF_CCID && entry->val.sp.len == 1)
  699. ccids[entry->is_local] = entry->val.sp.vec[0];
  700. while (i--)
  701. if (ccids[i] > 0 && dccp_feat_propagate_ccid(fn, ccids[i], i))
  702. return -1;
  703. return 0;
  704. }
  705. /**
  706. * dccp_feat_server_ccid_dependencies - Resolve CCID-dependent features
  707. * It is the server which resolves the dependencies once the CCID has been
  708. * fully negotiated. If no CCID has been negotiated, it uses the default CCID.
  709. */
  710. int dccp_feat_server_ccid_dependencies(struct dccp_request_sock *dreq)
  711. {
  712. struct list_head *fn = &dreq->dreq_featneg;
  713. struct dccp_feat_entry *entry;
  714. u8 is_local, ccid;
  715. for (is_local = 0; is_local <= 1; is_local++) {
  716. entry = dccp_feat_list_lookup(fn, DCCPF_CCID, is_local);
  717. if (entry != NULL && !entry->empty_confirm)
  718. ccid = entry->val.sp.vec[0];
  719. else
  720. ccid = dccp_feat_default_value(DCCPF_CCID);
  721. if (dccp_feat_propagate_ccid(fn, ccid, is_local))
  722. return -1;
  723. }
  724. return 0;
  725. }
  726. static int dccp_feat_update_ccid(struct sock *sk, u8 type, u8 new_ccid_nr)
  727. {
  728. struct dccp_sock *dp = dccp_sk(sk);
  729. struct dccp_minisock *dmsk = dccp_msk(sk);
  730. /* figure out if we are changing our CCID or the peer's */
  731. const int rx = type == DCCPO_CHANGE_R;
  732. const u8 ccid_nr = rx ? dmsk->dccpms_rx_ccid : dmsk->dccpms_tx_ccid;
  733. struct ccid *new_ccid;
  734. /* Check if nothing is being changed. */
  735. if (ccid_nr == new_ccid_nr)
  736. return 0;
  737. new_ccid = ccid_new(new_ccid_nr, sk, rx, GFP_ATOMIC);
  738. if (new_ccid == NULL)
  739. return -ENOMEM;
  740. if (rx) {
  741. ccid_hc_rx_delete(dp->dccps_hc_rx_ccid, sk);
  742. dp->dccps_hc_rx_ccid = new_ccid;
  743. dmsk->dccpms_rx_ccid = new_ccid_nr;
  744. } else {
  745. ccid_hc_tx_delete(dp->dccps_hc_tx_ccid, sk);
  746. dp->dccps_hc_tx_ccid = new_ccid;
  747. dmsk->dccpms_tx_ccid = new_ccid_nr;
  748. }
  749. return 0;
  750. }
  751. static int dccp_feat_update(struct sock *sk, u8 type, u8 feat, u8 val)
  752. {
  753. dccp_feat_debug(type, feat, val);
  754. switch (feat) {
  755. case DCCPF_CCID:
  756. return dccp_feat_update_ccid(sk, type, val);
  757. default:
  758. dccp_pr_debug("UNIMPLEMENTED: %s(%d, ...)\n",
  759. dccp_feat_typename(type), feat);
  760. break;
  761. }
  762. return 0;
  763. }
  764. /* Select the first entry in @servlist that also occurs in @clilist (6.3.1) */
  765. static int dccp_feat_preflist_match(u8 *servlist, u8 slen, u8 *clilist, u8 clen)
  766. {
  767. u8 c, s;
  768. for (s = 0; s < slen; s++)
  769. for (c = 0; c < clen; c++)
  770. if (servlist[s] == clilist[c])
  771. return servlist[s];
  772. return -1;
  773. }
  774. /**
  775. * dccp_feat_prefer - Move preferred entry to the start of array
  776. * Reorder the @array_len elements in @array so that @preferred_value comes
  777. * first. Returns >0 to indicate that @preferred_value does occur in @array.
  778. */
  779. static u8 dccp_feat_prefer(u8 preferred_value, u8 *array, u8 array_len)
  780. {
  781. u8 i, does_occur = 0;
  782. if (array != NULL) {
  783. for (i = 0; i < array_len; i++)
  784. if (array[i] == preferred_value) {
  785. array[i] = array[0];
  786. does_occur++;
  787. }
  788. if (does_occur)
  789. array[0] = preferred_value;
  790. }
  791. return does_occur;
  792. }
  793. /**
  794. * dccp_feat_reconcile - Reconcile SP preference lists
  795. * @fval: SP list to reconcile into
  796. * @arr: received SP preference list
  797. * @len: length of @arr in bytes
  798. * @is_server: whether this side is the server (and @fv is the server's list)
  799. * @reorder: whether to reorder the list in @fv after reconciling with @arr
  800. * When successful, > 0 is returned and the reconciled list is in @fval.
  801. * A value of 0 means that negotiation failed (no shared entry).
  802. */
  803. static int dccp_feat_reconcile(dccp_feat_val *fv, u8 *arr, u8 len,
  804. bool is_server, bool reorder)
  805. {
  806. int rc;
  807. if (!fv->sp.vec || !arr) {
  808. DCCP_CRIT("NULL feature value or array");
  809. return 0;
  810. }
  811. if (is_server)
  812. rc = dccp_feat_preflist_match(fv->sp.vec, fv->sp.len, arr, len);
  813. else
  814. rc = dccp_feat_preflist_match(arr, len, fv->sp.vec, fv->sp.len);
  815. if (!reorder)
  816. return rc;
  817. if (rc < 0)
  818. return 0;
  819. /*
  820. * Reorder list: used for activating features and in dccp_insert_fn_opt.
  821. */
  822. return dccp_feat_prefer(rc, fv->sp.vec, fv->sp.len);
  823. }
  824. #ifdef __this_is_the_old_framework_and_will_be_removed_later_in_a_subsequent_patch
  825. static int dccp_feat_reconcile(struct sock *sk, struct dccp_opt_pend *opt,
  826. u8 *rpref, u8 rlen)
  827. {
  828. struct dccp_sock *dp = dccp_sk(sk);
  829. u8 *spref, slen, *res = NULL;
  830. int i, j, rc, agree = 1;
  831. BUG_ON(rpref == NULL);
  832. /* check if we are the black sheep */
  833. if (dp->dccps_role == DCCP_ROLE_CLIENT) {
  834. spref = rpref;
  835. slen = rlen;
  836. rpref = opt->dccpop_val;
  837. rlen = opt->dccpop_len;
  838. } else {
  839. spref = opt->dccpop_val;
  840. slen = opt->dccpop_len;
  841. }
  842. /*
  843. * Now we have server preference list in spref and client preference in
  844. * rpref
  845. */
  846. BUG_ON(spref == NULL);
  847. BUG_ON(rpref == NULL);
  848. /* FIXME sanity check vals */
  849. /* Are values in any order? XXX Lame "algorithm" here */
  850. for (i = 0; i < slen; i++) {
  851. for (j = 0; j < rlen; j++) {
  852. if (spref[i] == rpref[j]) {
  853. res = &spref[i];
  854. break;
  855. }
  856. }
  857. if (res)
  858. break;
  859. }
  860. /* we didn't agree on anything */
  861. if (res == NULL) {
  862. /* confirm previous value */
  863. switch (opt->dccpop_feat) {
  864. case DCCPF_CCID:
  865. /* XXX did i get this right? =P */
  866. if (opt->dccpop_type == DCCPO_CHANGE_L)
  867. res = &dccp_msk(sk)->dccpms_tx_ccid;
  868. else
  869. res = &dccp_msk(sk)->dccpms_rx_ccid;
  870. break;
  871. default:
  872. DCCP_BUG("Fell through, feat=%d", opt->dccpop_feat);
  873. /* XXX implement res */
  874. return -EFAULT;
  875. }
  876. dccp_pr_debug("Don't agree... reconfirming %d\n", *res);
  877. agree = 0; /* this is used for mandatory options... */
  878. }
  879. /* need to put result and our preference list */
  880. rlen = 1 + opt->dccpop_len;
  881. rpref = kmalloc(rlen, GFP_ATOMIC);
  882. if (rpref == NULL)
  883. return -ENOMEM;
  884. *rpref = *res;
  885. memcpy(&rpref[1], opt->dccpop_val, opt->dccpop_len);
  886. /* put it in the "confirm queue" */
  887. if (opt->dccpop_sc == NULL) {
  888. opt->dccpop_sc = kmalloc(sizeof(*opt->dccpop_sc), GFP_ATOMIC);
  889. if (opt->dccpop_sc == NULL) {
  890. kfree(rpref);
  891. return -ENOMEM;
  892. }
  893. } else {
  894. /* recycle the confirm slot */
  895. BUG_ON(opt->dccpop_sc->dccpoc_val == NULL);
  896. kfree(opt->dccpop_sc->dccpoc_val);
  897. dccp_pr_debug("recycling confirm slot\n");
  898. }
  899. memset(opt->dccpop_sc, 0, sizeof(*opt->dccpop_sc));
  900. opt->dccpop_sc->dccpoc_val = rpref;
  901. opt->dccpop_sc->dccpoc_len = rlen;
  902. /* update the option on our side [we are about to send the confirm] */
  903. rc = dccp_feat_update(sk, opt->dccpop_type, opt->dccpop_feat, *res);
  904. if (rc) {
  905. kfree(opt->dccpop_sc->dccpoc_val);
  906. kfree(opt->dccpop_sc);
  907. opt->dccpop_sc = NULL;
  908. return rc;
  909. }
  910. dccp_pr_debug("Will confirm %d\n", *rpref);
  911. /* say we want to change to X but we just got a confirm X, suppress our
  912. * change
  913. */
  914. if (!opt->dccpop_conf) {
  915. if (*opt->dccpop_val == *res)
  916. opt->dccpop_conf = 1;
  917. dccp_pr_debug("won't ask for change of same feature\n");
  918. }
  919. return agree ? 0 : DCCP_FEAT_SP_NOAGREE; /* used for mandatory opts */
  920. }
  921. static int dccp_feat_sp(struct sock *sk, u8 type, u8 feature, u8 *val, u8 len)
  922. {
  923. struct dccp_minisock *dmsk = dccp_msk(sk);
  924. struct dccp_opt_pend *opt;
  925. int rc = 1;
  926. u8 t;
  927. /*
  928. * We received a CHANGE. We gotta match it against our own preference
  929. * list. If we got a CHANGE_R it means it's a change for us, so we need
  930. * to compare our CHANGE_L list.
  931. */
  932. if (type == DCCPO_CHANGE_L)
  933. t = DCCPO_CHANGE_R;
  934. else
  935. t = DCCPO_CHANGE_L;
  936. /* find our preference list for this feature */
  937. list_for_each_entry(opt, &dmsk->dccpms_pending, dccpop_node) {
  938. if (opt->dccpop_type != t || opt->dccpop_feat != feature)
  939. continue;
  940. /* find the winner from the two preference lists */
  941. rc = dccp_feat_reconcile(sk, opt, val, len);
  942. break;
  943. }
  944. /* We didn't deal with the change. This can happen if we have no
  945. * preference list for the feature. In fact, it just shouldn't
  946. * happen---if we understand a feature, we should have a preference list
  947. * with at least the default value.
  948. */
  949. BUG_ON(rc == 1);
  950. return rc;
  951. }
  952. static int dccp_feat_nn(struct sock *sk, u8 type, u8 feature, u8 *val, u8 len)
  953. {
  954. struct dccp_opt_pend *opt;
  955. struct dccp_minisock *dmsk = dccp_msk(sk);
  956. u8 *copy;
  957. int rc;
  958. /* NN features must be Change L (sec. 6.3.2) */
  959. if (type != DCCPO_CHANGE_L) {
  960. dccp_pr_debug("received %s for NN feature %d\n",
  961. dccp_feat_typename(type), feature);
  962. return -EFAULT;
  963. }
  964. /* XXX sanity check opt val */
  965. /* copy option so we can confirm it */
  966. opt = kzalloc(sizeof(*opt), GFP_ATOMIC);
  967. if (opt == NULL)
  968. return -ENOMEM;
  969. copy = kmemdup(val, len, GFP_ATOMIC);
  970. if (copy == NULL) {
  971. kfree(opt);
  972. return -ENOMEM;
  973. }
  974. opt->dccpop_type = DCCPO_CONFIRM_R; /* NN can only confirm R */
  975. opt->dccpop_feat = feature;
  976. opt->dccpop_val = copy;
  977. opt->dccpop_len = len;
  978. /* change feature */
  979. rc = dccp_feat_update(sk, type, feature, *val);
  980. if (rc) {
  981. kfree(opt->dccpop_val);
  982. kfree(opt);
  983. return rc;
  984. }
  985. dccp_feat_debug(type, feature, *copy);
  986. list_add_tail(&opt->dccpop_node, &dmsk->dccpms_conf);
  987. return 0;
  988. }
  989. static void dccp_feat_empty_confirm(struct dccp_minisock *dmsk,
  990. u8 type, u8 feature)
  991. {
  992. /* XXX check if other confirms for that are queued and recycle slot */
  993. struct dccp_opt_pend *opt = kzalloc(sizeof(*opt), GFP_ATOMIC);
  994. if (opt == NULL) {
  995. /* XXX what do we do? Ignoring should be fine. It's a change
  996. * after all =P
  997. */
  998. return;
  999. }
  1000. switch (type) {
  1001. case DCCPO_CHANGE_L:
  1002. opt->dccpop_type = DCCPO_CONFIRM_R;
  1003. break;
  1004. case DCCPO_CHANGE_R:
  1005. opt->dccpop_type = DCCPO_CONFIRM_L;
  1006. break;
  1007. default:
  1008. DCCP_WARN("invalid type %d\n", type);
  1009. kfree(opt);
  1010. return;
  1011. }
  1012. opt->dccpop_feat = feature;
  1013. opt->dccpop_val = NULL;
  1014. opt->dccpop_len = 0;
  1015. /* change feature */
  1016. dccp_pr_debug("Empty %s(%d)\n", dccp_feat_typename(type), feature);
  1017. list_add_tail(&opt->dccpop_node, &dmsk->dccpms_conf);
  1018. }
  1019. static void dccp_feat_flush_confirm(struct sock *sk)
  1020. {
  1021. struct dccp_minisock *dmsk = dccp_msk(sk);
  1022. /* Check if there is anything to confirm in the first place */
  1023. int yes = !list_empty(&dmsk->dccpms_conf);
  1024. if (!yes) {
  1025. struct dccp_opt_pend *opt;
  1026. list_for_each_entry(opt, &dmsk->dccpms_pending, dccpop_node) {
  1027. if (opt->dccpop_conf) {
  1028. yes = 1;
  1029. break;
  1030. }
  1031. }
  1032. }
  1033. if (!yes)
  1034. return;
  1035. /* OK there is something to confirm... */
  1036. /* XXX check if packet is in flight? Send delayed ack?? */
  1037. if (sk->sk_state == DCCP_OPEN)
  1038. dccp_send_ack(sk);
  1039. }
  1040. int dccp_feat_change_recv(struct sock *sk, u8 type, u8 feature, u8 *val, u8 len)
  1041. {
  1042. int rc;
  1043. /* Ignore Change requests other than during connection setup */
  1044. if (sk->sk_state != DCCP_LISTEN && sk->sk_state != DCCP_REQUESTING)
  1045. return 0;
  1046. dccp_feat_debug(type, feature, *val);
  1047. /* figure out if it's SP or NN feature */
  1048. switch (feature) {
  1049. /* deal with SP features */
  1050. case DCCPF_CCID:
  1051. /* XXX Obsoleted by next patch
  1052. rc = dccp_feat_sp(sk, type, feature, val, len); */
  1053. break;
  1054. /* deal with NN features */
  1055. case DCCPF_ACK_RATIO:
  1056. /* XXX Obsoleted by next patch
  1057. rc = dccp_feat_nn(sk, type, feature, val, len); */
  1058. break;
  1059. /* XXX implement other features */
  1060. default:
  1061. dccp_pr_debug("UNIMPLEMENTED: not handling %s(%d, ...)\n",
  1062. dccp_feat_typename(type), feature);
  1063. rc = -EFAULT;
  1064. break;
  1065. }
  1066. /* check if there were problems changing features */
  1067. if (rc) {
  1068. /* If we don't agree on SP, we sent a confirm for old value.
  1069. * However we propagate rc to caller in case option was
  1070. * mandatory
  1071. */
  1072. if (rc != DCCP_FEAT_SP_NOAGREE)
  1073. dccp_feat_empty_confirm(dccp_msk(sk), type, feature);
  1074. }
  1075. /* generate the confirm [if required] */
  1076. dccp_feat_flush_confirm(sk);
  1077. return rc;
  1078. }
  1079. EXPORT_SYMBOL_GPL(dccp_feat_change_recv);
  1080. int dccp_feat_confirm_recv(struct sock *sk, u8 type, u8 feature,
  1081. u8 *val, u8 len)
  1082. {
  1083. u8 t;
  1084. struct dccp_opt_pend *opt;
  1085. struct dccp_minisock *dmsk = dccp_msk(sk);
  1086. int found = 0;
  1087. int all_confirmed = 1;
  1088. /* Ignore Confirm options other than during connection setup */
  1089. if (sk->sk_state != DCCP_LISTEN && sk->sk_state != DCCP_REQUESTING)
  1090. return 0;
  1091. dccp_feat_debug(type, feature, *val);
  1092. /* locate our change request */
  1093. switch (type) {
  1094. case DCCPO_CONFIRM_L: t = DCCPO_CHANGE_R; break;
  1095. case DCCPO_CONFIRM_R: t = DCCPO_CHANGE_L; break;
  1096. default: DCCP_WARN("invalid type %d\n", type);
  1097. return 1;
  1098. }
  1099. /* XXX sanity check feature value */
  1100. list_for_each_entry(opt, &dmsk->dccpms_pending, dccpop_node) {
  1101. if (!opt->dccpop_conf && opt->dccpop_type == t &&
  1102. opt->dccpop_feat == feature) {
  1103. found = 1;
  1104. dccp_pr_debug("feature %d found\n", opt->dccpop_feat);
  1105. /* XXX do sanity check */
  1106. opt->dccpop_conf = 1;
  1107. /* We got a confirmation---change the option */
  1108. dccp_feat_update(sk, opt->dccpop_type,
  1109. opt->dccpop_feat, *val);
  1110. /* XXX check the return value of dccp_feat_update */
  1111. break;
  1112. }
  1113. if (!opt->dccpop_conf)
  1114. all_confirmed = 0;
  1115. }
  1116. if (!found)
  1117. dccp_pr_debug("%s(%d, ...) never requested\n",
  1118. dccp_feat_typename(type), feature);
  1119. return 0;
  1120. }
  1121. EXPORT_SYMBOL_GPL(dccp_feat_confirm_recv);
  1122. #endif /* (later) */
  1123. void dccp_feat_clean(struct dccp_minisock *dmsk)
  1124. {
  1125. struct dccp_opt_pend *opt, *next;
  1126. list_for_each_entry_safe(opt, next, &dmsk->dccpms_pending,
  1127. dccpop_node) {
  1128. BUG_ON(opt->dccpop_val == NULL);
  1129. kfree(opt->dccpop_val);
  1130. if (opt->dccpop_sc != NULL) {
  1131. BUG_ON(opt->dccpop_sc->dccpoc_val == NULL);
  1132. kfree(opt->dccpop_sc->dccpoc_val);
  1133. kfree(opt->dccpop_sc);
  1134. }
  1135. kfree(opt);
  1136. }
  1137. INIT_LIST_HEAD(&dmsk->dccpms_pending);
  1138. list_for_each_entry_safe(opt, next, &dmsk->dccpms_conf, dccpop_node) {
  1139. BUG_ON(opt == NULL);
  1140. if (opt->dccpop_val != NULL)
  1141. kfree(opt->dccpop_val);
  1142. kfree(opt);
  1143. }
  1144. INIT_LIST_HEAD(&dmsk->dccpms_conf);
  1145. }
  1146. EXPORT_SYMBOL_GPL(dccp_feat_clean);
  1147. /* this is to be called only when a listening sock creates its child. It is
  1148. * assumed by the function---the confirm is not duplicated, but rather it is
  1149. * "passed on".
  1150. */
  1151. int dccp_feat_clone(struct sock *oldsk, struct sock *newsk)
  1152. {
  1153. struct dccp_minisock *olddmsk = dccp_msk(oldsk);
  1154. struct dccp_minisock *newdmsk = dccp_msk(newsk);
  1155. struct dccp_opt_pend *opt;
  1156. int rc = 0;
  1157. INIT_LIST_HEAD(&newdmsk->dccpms_pending);
  1158. INIT_LIST_HEAD(&newdmsk->dccpms_conf);
  1159. list_for_each_entry(opt, &olddmsk->dccpms_pending, dccpop_node) {
  1160. struct dccp_opt_pend *newopt;
  1161. /* copy the value of the option */
  1162. u8 *val = kmemdup(opt->dccpop_val, opt->dccpop_len, GFP_ATOMIC);
  1163. if (val == NULL)
  1164. goto out_clean;
  1165. newopt = kmemdup(opt, sizeof(*newopt), GFP_ATOMIC);
  1166. if (newopt == NULL) {
  1167. kfree(val);
  1168. goto out_clean;
  1169. }
  1170. /* insert the option */
  1171. newopt->dccpop_val = val;
  1172. list_add_tail(&newopt->dccpop_node, &newdmsk->dccpms_pending);
  1173. /* XXX what happens with backlogs and multiple connections at
  1174. * once...
  1175. */
  1176. /* the master socket no longer needs to worry about confirms */
  1177. opt->dccpop_sc = NULL; /* it's not a memleak---new socket has it */
  1178. /* reset state for a new socket */
  1179. opt->dccpop_conf = 0;
  1180. }
  1181. /* XXX not doing anything about the conf queue */
  1182. out:
  1183. return rc;
  1184. out_clean:
  1185. dccp_feat_clean(newdmsk);
  1186. rc = -ENOMEM;
  1187. goto out;
  1188. }
  1189. EXPORT_SYMBOL_GPL(dccp_feat_clone);
  1190. /**
  1191. * dccp_feat_change_recv - Process incoming ChangeL/R options
  1192. * @fn: feature-negotiation list to update
  1193. * @is_mandatory: whether the Change was preceded by a Mandatory option
  1194. * @opt: %DCCPO_CHANGE_L or %DCCPO_CHANGE_R
  1195. * @feat: one of %dccp_feature_numbers
  1196. * @val: NN value or SP value/preference list
  1197. * @len: length of @val in bytes
  1198. * @server: whether this node is the server (1) or the client (0)
  1199. */
  1200. static u8 dccp_feat_change_recv(struct list_head *fn, u8 is_mandatory, u8 opt,
  1201. u8 feat, u8 *val, u8 len, const bool server)
  1202. {
  1203. u8 defval, type = dccp_feat_type(feat);
  1204. const bool local = (opt == DCCPO_CHANGE_R);
  1205. struct dccp_feat_entry *entry;
  1206. dccp_feat_val fval;
  1207. if (len == 0 || type == FEAT_UNKNOWN) /* 6.1 and 6.6.8 */
  1208. goto unknown_feature_or_value;
  1209. /*
  1210. * Negotiation of NN features: Change R is invalid, so there is no
  1211. * simultaneous negotiation; hence we do not look up in the list.
  1212. */
  1213. if (type == FEAT_NN) {
  1214. if (local || len > sizeof(fval.nn))
  1215. goto unknown_feature_or_value;
  1216. /* 6.3.2: "The feature remote MUST accept any valid value..." */
  1217. fval.nn = dccp_decode_value_var(val, len);
  1218. if (!dccp_feat_is_valid_nn_val(feat, fval.nn))
  1219. goto unknown_feature_or_value;
  1220. return dccp_feat_push_confirm(fn, feat, local, &fval);
  1221. }
  1222. /*
  1223. * Unidirectional/simultaneous negotiation of SP features (6.3.1)
  1224. */
  1225. entry = dccp_feat_list_lookup(fn, feat, local);
  1226. if (entry == NULL) {
  1227. /*
  1228. * No particular preferences have been registered. We deal with
  1229. * this situation by assuming that all valid values are equally
  1230. * acceptable, and apply the following checks:
  1231. * - if the peer's list is a singleton, we accept a valid value;
  1232. * - if we are the server, we first try to see if the peer (the
  1233. * client) advertises the default value. If yes, we use it,
  1234. * otherwise we accept the preferred value;
  1235. * - else if we are the client, we use the first list element.
  1236. */
  1237. if (dccp_feat_clone_sp_val(&fval, val, 1))
  1238. return DCCP_RESET_CODE_TOO_BUSY;
  1239. if (len > 1 && server) {
  1240. defval = dccp_feat_default_value(feat);
  1241. if (dccp_feat_preflist_match(&defval, 1, val, len) > -1)
  1242. fval.sp.vec[0] = defval;
  1243. } else if (!dccp_feat_is_valid_sp_val(feat, fval.sp.vec[0])) {
  1244. kfree(fval.sp.vec);
  1245. goto unknown_feature_or_value;
  1246. }
  1247. /* Treat unsupported CCIDs like invalid values */
  1248. if (feat == DCCPF_CCID && !ccid_support_check(fval.sp.vec, 1)) {
  1249. kfree(fval.sp.vec);
  1250. goto not_valid_or_not_known;
  1251. }
  1252. return dccp_feat_push_confirm(fn, feat, local, &fval);
  1253. } else if (entry->state == FEAT_UNSTABLE) { /* 6.6.2 */
  1254. return 0;
  1255. }
  1256. if (dccp_feat_reconcile(&entry->val, val, len, server, true)) {
  1257. entry->empty_confirm = 0;
  1258. } else if (is_mandatory) {
  1259. return DCCP_RESET_CODE_MANDATORY_ERROR;
  1260. } else if (entry->state == FEAT_INITIALISING) {
  1261. /*
  1262. * Failed simultaneous negotiation (server only): try to `save'
  1263. * the connection by checking whether entry contains the default
  1264. * value for @feat. If yes, send an empty Confirm to signal that
  1265. * the received Change was not understood - which implies using
  1266. * the default value.
  1267. * If this also fails, we use Reset as the last resort.
  1268. */
  1269. WARN_ON(!server);
  1270. defval = dccp_feat_default_value(feat);
  1271. if (!dccp_feat_reconcile(&entry->val, &defval, 1, server, true))
  1272. return DCCP_RESET_CODE_OPTION_ERROR;
  1273. entry->empty_confirm = 1;
  1274. }
  1275. entry->needs_confirm = 1;
  1276. entry->needs_mandatory = 0;
  1277. entry->state = FEAT_STABLE;
  1278. return 0;
  1279. unknown_feature_or_value:
  1280. if (!is_mandatory)
  1281. return dccp_push_empty_confirm(fn, feat, local);
  1282. not_valid_or_not_known:
  1283. return is_mandatory ? DCCP_RESET_CODE_MANDATORY_ERROR
  1284. : DCCP_RESET_CODE_OPTION_ERROR;
  1285. }
  1286. /**
  1287. * dccp_feat_confirm_recv - Process received Confirm options
  1288. * @fn: feature-negotiation list to update
  1289. * @is_mandatory: whether @opt was preceded by a Mandatory option
  1290. * @opt: %DCCPO_CONFIRM_L or %DCCPO_CONFIRM_R
  1291. * @feat: one of %dccp_feature_numbers
  1292. * @val: NN value or SP value/preference list
  1293. * @len: length of @val in bytes
  1294. * @server: whether this node is server (1) or client (0)
  1295. */
  1296. static u8 dccp_feat_confirm_recv(struct list_head *fn, u8 is_mandatory, u8 opt,
  1297. u8 feat, u8 *val, u8 len, const bool server)
  1298. {
  1299. u8 *plist, plen, type = dccp_feat_type(feat);
  1300. const bool local = (opt == DCCPO_CONFIRM_R);
  1301. struct dccp_feat_entry *entry = dccp_feat_list_lookup(fn, feat, local);
  1302. if (entry == NULL) { /* nothing queued: ignore or handle error */
  1303. if (is_mandatory && type == FEAT_UNKNOWN)
  1304. return DCCP_RESET_CODE_MANDATORY_ERROR;
  1305. if (!local && type == FEAT_NN) /* 6.3.2 */
  1306. goto confirmation_failed;
  1307. return 0;
  1308. }
  1309. if (entry->state != FEAT_CHANGING) /* 6.6.2 */
  1310. return 0;
  1311. if (len == 0) {
  1312. if (dccp_feat_must_be_understood(feat)) /* 6.6.7 */
  1313. goto confirmation_failed;
  1314. /*
  1315. * Empty Confirm during connection setup: this means reverting
  1316. * to the `old' value, which in this case is the default. Since
  1317. * we handle default values automatically when no other values
  1318. * have been set, we revert to the old value by removing this
  1319. * entry from the list.
  1320. */
  1321. dccp_feat_list_pop(entry);
  1322. return 0;
  1323. }
  1324. if (type == FEAT_NN) {
  1325. if (len > sizeof(entry->val.nn))
  1326. goto confirmation_failed;
  1327. if (entry->val.nn == dccp_decode_value_var(val, len))
  1328. goto confirmation_succeeded;
  1329. DCCP_WARN("Bogus Confirm for non-existing value\n");
  1330. goto confirmation_failed;
  1331. }
  1332. /*
  1333. * Parsing SP Confirms: the first element of @val is the preferred
  1334. * SP value which the peer confirms, the remainder depends on @len.
  1335. * Note that only the confirmed value need to be a valid SP value.
  1336. */
  1337. if (!dccp_feat_is_valid_sp_val(feat, *val))
  1338. goto confirmation_failed;
  1339. if (len == 1) { /* peer didn't supply a preference list */
  1340. plist = val;
  1341. plen = len;
  1342. } else { /* preferred value + preference list */
  1343. plist = val + 1;
  1344. plen = len - 1;
  1345. }
  1346. /* Check whether the peer got the reconciliation right (6.6.8) */
  1347. if (dccp_feat_reconcile(&entry->val, plist, plen, server, 0) != *val) {
  1348. DCCP_WARN("Confirm selected the wrong value %u\n", *val);
  1349. return DCCP_RESET_CODE_OPTION_ERROR;
  1350. }
  1351. entry->val.sp.vec[0] = *val;
  1352. confirmation_succeeded:
  1353. entry->state = FEAT_STABLE;
  1354. return 0;
  1355. confirmation_failed:
  1356. DCCP_WARN("Confirmation failed\n");
  1357. return is_mandatory ? DCCP_RESET_CODE_MANDATORY_ERROR
  1358. : DCCP_RESET_CODE_OPTION_ERROR;
  1359. }
  1360. /**
  1361. * dccp_feat_parse_options - Process Feature-Negotiation Options
  1362. * @sk: for general use and used by the client during connection setup
  1363. * @dreq: used by the server during connection setup
  1364. * @mandatory: whether @opt was preceded by a Mandatory option
  1365. * @opt: %DCCPO_CHANGE_L | %DCCPO_CHANGE_R | %DCCPO_CONFIRM_L | %DCCPO_CONFIRM_R
  1366. * @feat: one of %dccp_feature_numbers
  1367. * @val: value contents of @opt
  1368. * @len: length of @val in bytes
  1369. * Returns 0 on success, a Reset code for ending the connection otherwise.
  1370. */
  1371. int dccp_feat_parse_options(struct sock *sk, struct dccp_request_sock *dreq,
  1372. u8 mandatory, u8 opt, u8 feat, u8 *val, u8 len)
  1373. {
  1374. struct dccp_sock *dp = dccp_sk(sk);
  1375. struct list_head *fn = dreq ? &dreq->dreq_featneg : &dp->dccps_featneg;
  1376. bool server = false;
  1377. switch (sk->sk_state) {
  1378. /*
  1379. * Negotiation during connection setup
  1380. */
  1381. case DCCP_LISTEN:
  1382. server = true; /* fall through */
  1383. case DCCP_REQUESTING:
  1384. switch (opt) {
  1385. case DCCPO_CHANGE_L:
  1386. case DCCPO_CHANGE_R:
  1387. return dccp_feat_change_recv(fn, mandatory, opt, feat,
  1388. val, len, server);
  1389. case DCCPO_CONFIRM_R:
  1390. case DCCPO_CONFIRM_L:
  1391. return dccp_feat_confirm_recv(fn, mandatory, opt, feat,
  1392. val, len, server);
  1393. }
  1394. }
  1395. return 0; /* ignore FN options in all other states */
  1396. }
  1397. int dccp_feat_init(struct sock *sk)
  1398. {
  1399. struct dccp_sock *dp = dccp_sk(sk);
  1400. struct dccp_minisock *dmsk = dccp_msk(sk);
  1401. int rc;
  1402. INIT_LIST_HEAD(&dmsk->dccpms_pending); /* XXX no longer used */
  1403. INIT_LIST_HEAD(&dmsk->dccpms_conf); /* XXX no longer used */
  1404. /* CCID L */
  1405. rc = __feat_register_sp(&dp->dccps_featneg, DCCPF_CCID, 1, 0,
  1406. &dmsk->dccpms_tx_ccid, 1);
  1407. if (rc)
  1408. goto out;
  1409. /* CCID R */
  1410. rc = __feat_register_sp(&dp->dccps_featneg, DCCPF_CCID, 0, 0,
  1411. &dmsk->dccpms_rx_ccid, 1);
  1412. if (rc)
  1413. goto out;
  1414. /* Ack ratio */
  1415. rc = __feat_register_nn(&dp->dccps_featneg, DCCPF_ACK_RATIO, 0,
  1416. dp->dccps_l_ack_ratio);
  1417. out:
  1418. return rc;
  1419. }
  1420. EXPORT_SYMBOL_GPL(dccp_feat_init);
  1421. int dccp_feat_activate_values(struct sock *sk, struct list_head *fn_list)
  1422. {
  1423. struct dccp_sock *dp = dccp_sk(sk);
  1424. struct dccp_feat_entry *cur, *next;
  1425. int idx;
  1426. dccp_feat_val *fvals[DCCP_FEAT_SUPPORTED_MAX][2] = {
  1427. [0 ... DCCP_FEAT_SUPPORTED_MAX-1] = { NULL, NULL }
  1428. };
  1429. list_for_each_entry(cur, fn_list, node) {
  1430. /*
  1431. * An empty Confirm means that either an unknown feature type
  1432. * or an invalid value was present. In the first case there is
  1433. * nothing to activate, in the other the default value is used.
  1434. */
  1435. if (cur->empty_confirm)
  1436. continue;
  1437. idx = dccp_feat_index(cur->feat_num);
  1438. if (idx < 0) {
  1439. DCCP_BUG("Unknown feature %u", cur->feat_num);
  1440. goto activation_failed;
  1441. }
  1442. if (cur->state != FEAT_STABLE) {
  1443. DCCP_CRIT("Negotiation of %s %u failed in state %u",
  1444. cur->is_local ? "local" : "remote",
  1445. cur->feat_num, cur->state);
  1446. goto activation_failed;
  1447. }
  1448. fvals[idx][cur->is_local] = &cur->val;
  1449. }
  1450. /*
  1451. * Activate in decreasing order of index, so that the CCIDs are always
  1452. * activated as the last feature. This avoids the case where a CCID
  1453. * relies on the initialisation of one or more features that it depends
  1454. * on (e.g. Send NDP Count, Send Ack Vector, and Ack Ratio features).
  1455. */
  1456. for (idx = DCCP_FEAT_SUPPORTED_MAX; --idx >= 0;)
  1457. if (__dccp_feat_activate(sk, idx, 0, fvals[idx][0]) ||
  1458. __dccp_feat_activate(sk, idx, 1, fvals[idx][1])) {
  1459. DCCP_CRIT("Could not activate %d", idx);
  1460. goto activation_failed;
  1461. }
  1462. /* Clean up Change options which have been confirmed already */
  1463. list_for_each_entry_safe(cur, next, fn_list, node)
  1464. if (!cur->needs_confirm)
  1465. dccp_feat_list_pop(cur);
  1466. dccp_pr_debug("Activation OK\n");
  1467. return 0;
  1468. activation_failed:
  1469. /*
  1470. * We clean up everything that may have been allocated, since
  1471. * it is difficult to track at which stage negotiation failed.
  1472. * This is ok, since all allocation functions below are robust
  1473. * against NULL arguments.
  1474. */
  1475. ccid_hc_rx_delete(dp->dccps_hc_rx_ccid, sk);
  1476. ccid_hc_tx_delete(dp->dccps_hc_tx_ccid, sk);
  1477. dp->dccps_hc_rx_ccid = dp->dccps_hc_tx_ccid = NULL;
  1478. dccp_ackvec_free(dp->dccps_hc_rx_ackvec);
  1479. dp->dccps_hc_rx_ackvec = NULL;
  1480. return -1;
  1481. }
  1482. #ifdef CONFIG_IP_DCCP_DEBUG
  1483. const char *dccp_feat_typename(const u8 type)
  1484. {
  1485. switch(type) {
  1486. case DCCPO_CHANGE_L: return("ChangeL");
  1487. case DCCPO_CONFIRM_L: return("ConfirmL");
  1488. case DCCPO_CHANGE_R: return("ChangeR");
  1489. case DCCPO_CONFIRM_R: return("ConfirmR");
  1490. /* the following case must not appear in feature negotation */
  1491. default: dccp_pr_debug("unknown type %d [BUG!]\n", type);
  1492. }
  1493. return NULL;
  1494. }
  1495. EXPORT_SYMBOL_GPL(dccp_feat_typename);
  1496. const char *dccp_feat_name(const u8 feat)
  1497. {
  1498. static const char *feature_names[] = {
  1499. [DCCPF_RESERVED] = "Reserved",
  1500. [DCCPF_CCID] = "CCID",
  1501. [DCCPF_SHORT_SEQNOS] = "Allow Short Seqnos",
  1502. [DCCPF_SEQUENCE_WINDOW] = "Sequence Window",
  1503. [DCCPF_ECN_INCAPABLE] = "ECN Incapable",
  1504. [DCCPF_ACK_RATIO] = "Ack Ratio",
  1505. [DCCPF_SEND_ACK_VECTOR] = "Send ACK Vector",
  1506. [DCCPF_SEND_NDP_COUNT] = "Send NDP Count",
  1507. [DCCPF_MIN_CSUM_COVER] = "Min. Csum Coverage",
  1508. [DCCPF_DATA_CHECKSUM] = "Send Data Checksum",
  1509. };
  1510. if (feat > DCCPF_DATA_CHECKSUM && feat < DCCPF_MIN_CCID_SPECIFIC)
  1511. return feature_names[DCCPF_RESERVED];
  1512. if (feat == DCCPF_SEND_LEV_RATE)
  1513. return "Send Loss Event Rate";
  1514. if (feat >= DCCPF_MIN_CCID_SPECIFIC)
  1515. return "CCID-specific";
  1516. return feature_names[feat];
  1517. }
  1518. EXPORT_SYMBOL_GPL(dccp_feat_name);
  1519. #endif /* CONFIG_IP_DCCP_DEBUG */