feat.h 4.8 KB

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