feat.c 49 KB

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