feat.h 4.6 KB

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