feat.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. enum dccp_feat_type {
  16. FEAT_AT_RX = 1, /* located at RX side of half-connection */
  17. FEAT_AT_TX = 2, /* located at TX side of half-connection */
  18. FEAT_SP = 4, /* server-priority reconciliation (6.3.1) */
  19. FEAT_NN = 8, /* non-negotiable reconciliation (6.3.2) */
  20. FEAT_UNKNOWN = 0xFF /* not understood or invalid feature */
  21. };
  22. enum dccp_feat_state {
  23. FEAT_DEFAULT = 0, /* using default values from 6.4 */
  24. FEAT_INITIALISING, /* feature is being initialised */
  25. FEAT_CHANGING, /* Change sent but not confirmed yet */
  26. FEAT_UNSTABLE, /* local modification in state CHANGING */
  27. FEAT_STABLE /* both ends (think they) agree */
  28. };
  29. /**
  30. * dccp_feat_val - Container for SP or NN feature values
  31. * @nn: single NN value
  32. * @sp.vec: single SP value plus optional preference list
  33. * @sp.len: length of @sp.vec in bytes
  34. */
  35. typedef union {
  36. u64 nn;
  37. struct {
  38. u8 *vec;
  39. u8 len;
  40. } sp;
  41. } dccp_feat_val;
  42. /**
  43. * struct feat_entry - Data structure to perform feature negotiation
  44. * @val: feature's current value (SP features may have preference list)
  45. * @state: feature's current state
  46. * @feat_num: one of %dccp_feature_numbers
  47. * @needs_mandatory: whether Mandatory options should be sent
  48. * @needs_confirm: whether to send a Confirm instead of a Change
  49. * @empty_confirm: whether to send an empty Confirm (depends on @needs_confirm)
  50. * @is_local: feature location (1) or feature-remote (0)
  51. * @node: list pointers, entries arranged in FIFO order
  52. */
  53. struct dccp_feat_entry {
  54. dccp_feat_val val;
  55. enum dccp_feat_state state:8;
  56. u8 feat_num;
  57. bool needs_mandatory,
  58. needs_confirm,
  59. empty_confirm,
  60. is_local;
  61. struct list_head node;
  62. };
  63. static inline u8 dccp_feat_genopt(struct dccp_feat_entry *entry)
  64. {
  65. if (entry->needs_confirm)
  66. return entry->is_local ? DCCPO_CONFIRM_L : DCCPO_CONFIRM_R;
  67. return entry->is_local ? DCCPO_CHANGE_L : DCCPO_CHANGE_R;
  68. }
  69. #ifdef CONFIG_IP_DCCP_DEBUG
  70. extern const char *dccp_feat_typename(const u8 type);
  71. extern const char *dccp_feat_name(const u8 feat);
  72. static inline void dccp_feat_debug(const u8 type, const u8 feat, const u8 val)
  73. {
  74. dccp_pr_debug("%s(%s (%d), %d)\n", dccp_feat_typename(type),
  75. dccp_feat_name(feat), feat, val);
  76. }
  77. #else
  78. #define dccp_feat_debug(type, feat, val)
  79. #endif /* CONFIG_IP_DCCP_DEBUG */
  80. extern int dccp_feat_change(struct dccp_minisock *dmsk, u8 type, u8 feature,
  81. u8 *val, u8 len, gfp_t gfp);
  82. extern int dccp_feat_change_recv(struct sock *sk, u8 type, u8 feature,
  83. u8 *val, u8 len);
  84. extern int dccp_feat_confirm_recv(struct sock *sk, u8 type, u8 feature,
  85. u8 *val, u8 len);
  86. extern void dccp_feat_clean(struct dccp_minisock *dmsk);
  87. extern int dccp_feat_clone(struct sock *oldsk, struct sock *newsk);
  88. extern int dccp_feat_init(struct dccp_minisock *dmsk);
  89. #endif /* _DCCP_FEAT_H */