feat.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. #ifndef _DCCP_FEAT_H
  3. #define _DCCP_FEAT_H
  4. /*
  5. * net/dccp/feat.h
  6. *
  7. * Feature negotiation for the DCCP protocol (RFC 4340, section 6)
  8. * Copyright (c) 2008 Gerrit Renker <gerrit@erg.abdn.ac.uk>
  9. * Copyright (c) 2005 Andrea Bittau <a.bittau@cs.ucl.ac.uk>
  10. */
  11. #include <linux/types.h>
  12. #include "dccp.h"
  13. /*
  14. * Known limit values
  15. */
  16. /* Ack Ratio takes 2-byte integer values (11.3) */
  17. #define DCCPF_ACK_RATIO_MAX 0xFFFF
  18. /* Wmin=32 and Wmax=2^46-1 from 7.5.2 */
  19. #define DCCPF_SEQ_WMIN 32
  20. #define DCCPF_SEQ_WMAX 0x3FFFFFFFFFFFull
  21. /* Maximum number of SP values that fit in a single (Confirm) option */
  22. #define DCCP_FEAT_MAX_SP_VALS (DCCP_SINGLE_OPT_MAXLEN - 2)
  23. enum dccp_feat_type {
  24. FEAT_AT_RX = 1, /* located at RX side of half-connection */
  25. FEAT_AT_TX = 2, /* located at TX side of half-connection */
  26. FEAT_SP = 4, /* server-priority reconciliation (6.3.1) */
  27. FEAT_NN = 8, /* non-negotiable reconciliation (6.3.2) */
  28. FEAT_UNKNOWN = 0xFF /* not understood or invalid feature */
  29. };
  30. enum dccp_feat_state {
  31. FEAT_DEFAULT = 0, /* using default values from 6.4 */
  32. FEAT_INITIALISING, /* feature is being initialised */
  33. FEAT_CHANGING, /* Change sent but not confirmed yet */
  34. FEAT_UNSTABLE, /* local modification in state CHANGING */
  35. FEAT_STABLE /* both ends (think they) agree */
  36. };
  37. /**
  38. * dccp_feat_val - Container for SP or NN feature values
  39. * @nn: single NN value
  40. * @sp.vec: single SP value plus optional preference list
  41. * @sp.len: length of @sp.vec in bytes
  42. */
  43. typedef union {
  44. u64 nn;
  45. struct {
  46. u8 *vec;
  47. u8 len;
  48. } sp;
  49. } dccp_feat_val;
  50. /**
  51. * struct feat_entry - Data structure to perform feature negotiation
  52. * @val: feature's current value (SP features may have preference list)
  53. * @state: feature's current state
  54. * @feat_num: one of %dccp_feature_numbers
  55. * @needs_mandatory: whether Mandatory options should be sent
  56. * @needs_confirm: whether to send a Confirm instead of a Change
  57. * @empty_confirm: whether to send an empty Confirm (depends on @needs_confirm)
  58. * @is_local: feature location (1) or feature-remote (0)
  59. * @node: list pointers, entries arranged in FIFO order
  60. */
  61. struct dccp_feat_entry {
  62. dccp_feat_val val;
  63. enum dccp_feat_state state:8;
  64. u8 feat_num;
  65. bool needs_mandatory,
  66. needs_confirm,
  67. empty_confirm,
  68. is_local;
  69. struct list_head node;
  70. };
  71. static inline u8 dccp_feat_genopt(struct dccp_feat_entry *entry)
  72. {
  73. if (entry->needs_confirm)
  74. return entry->is_local ? DCCPO_CONFIRM_L : DCCPO_CONFIRM_R;
  75. return entry->is_local ? DCCPO_CHANGE_L : DCCPO_CHANGE_R;
  76. }
  77. /**
  78. * struct ccid_dependency - Track changes resulting from choosing a CCID
  79. * @dependent_feat: one of %dccp_feature_numbers
  80. * @is_local: local (1) or remote (0) @dependent_feat
  81. * @is_mandatory: whether presence of @dependent_feat is mission-critical or not
  82. * @val: corresponding default value for @dependent_feat (u8 is sufficient here)
  83. */
  84. struct ccid_dependency {
  85. u8 dependent_feat;
  86. bool is_local:1,
  87. is_mandatory:1;
  88. u8 val;
  89. };
  90. /*
  91. * Sysctls to seed defaults for feature negotiation
  92. */
  93. extern unsigned long sysctl_dccp_sequence_window;
  94. extern int sysctl_dccp_rx_ccid;
  95. extern int sysctl_dccp_tx_ccid;
  96. int dccp_feat_init(struct sock *sk);
  97. void dccp_feat_initialise_sysctls(void);
  98. int dccp_feat_register_sp(struct sock *sk, u8 feat, u8 is_local,
  99. u8 const *list, u8 len);
  100. int dccp_feat_parse_options(struct sock *, struct dccp_request_sock *,
  101. u8 mand, u8 opt, u8 feat, u8 *val, u8 len);
  102. int dccp_feat_clone_list(struct list_head const *, struct list_head *);
  103. /*
  104. * Encoding variable-length options and their maximum length.
  105. *
  106. * This affects NN options (SP options are all u8) and other variable-length
  107. * options (see table 3 in RFC 4340). The limit is currently given the Sequence
  108. * Window NN value (sec. 7.5.2) and the NDP count (sec. 7.7) option, all other
  109. * options consume less than 6 bytes (timestamps are 4 bytes).
  110. * When updating this constant (e.g. due to new internet drafts / RFCs), make
  111. * sure that you also update all code which refers to it.
  112. */
  113. #define DCCP_OPTVAL_MAXLEN 6
  114. void dccp_encode_value_var(const u64 value, u8 *to, const u8 len);
  115. u64 dccp_decode_value_var(const u8 *bf, const u8 len);
  116. u64 dccp_feat_nn_get(struct sock *sk, u8 feat);
  117. int dccp_insert_option_mandatory(struct sk_buff *skb);
  118. int dccp_insert_fn_opt(struct sk_buff *skb, u8 type, u8 feat, u8 *val, u8 len,
  119. bool repeat_first);
  120. #endif /* _DCCP_FEAT_H */