flow.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. *
  3. * Generic internet FLOW.
  4. *
  5. */
  6. #ifndef _NET_FLOW_H
  7. #define _NET_FLOW_H
  8. #include <linux/in6.h>
  9. #include <asm/atomic.h>
  10. struct flowi_common {
  11. int flowic_oif;
  12. int flowic_iif;
  13. __u32 flowic_mark;
  14. __u8 flowic_tos;
  15. __u8 flowic_scope;
  16. __u8 flowic_proto;
  17. __u8 flowic_flags;
  18. #define FLOWI_FLAG_ANYSRC 0x01
  19. #define FLOWI_FLAG_PRECOW_METRICS 0x02
  20. #define FLOWI_FLAG_CAN_SLEEP 0x04
  21. __u32 flowic_secid;
  22. };
  23. union flowi_uli {
  24. struct {
  25. __be16 sport;
  26. __be16 dport;
  27. } ports;
  28. struct {
  29. __u8 type;
  30. __u8 code;
  31. } icmpt;
  32. struct {
  33. __le16 sport;
  34. __le16 dport;
  35. } dnports;
  36. __be32 spi;
  37. __be32 gre_key;
  38. struct {
  39. __u8 type;
  40. } mht;
  41. };
  42. struct flowi4 {
  43. struct flowi_common __fl_common;
  44. #define flowi4_oif __fl_common.flowic_oif
  45. #define flowi4_iif __fl_common.flowic_iif
  46. #define flowi4_mark __fl_common.flowic_mark
  47. #define flowi4_tos __fl_common.flowic_tos
  48. #define flowi4_scope __fl_common.flowic_scope
  49. #define flowi4_proto __fl_common.flowic_proto
  50. #define flowi4_flags __fl_common.flowic_flags
  51. #define flowi4_secid __fl_common.flowic_secid
  52. __be32 daddr;
  53. __be32 saddr;
  54. union flowi_uli uli;
  55. };
  56. struct flowi6 {
  57. struct flowi_common __fl_common;
  58. struct in6_addr daddr;
  59. struct in6_addr saddr;
  60. __be32 flowlabel;
  61. union flowi_uli uli;
  62. };
  63. struct flowidn {
  64. struct flowi_common __fl_common;
  65. __le16 daddr;
  66. __le16 saddr;
  67. union flowi_uli uli;
  68. };
  69. struct flowi {
  70. union {
  71. struct flowi_common __fl_common;
  72. struct flowi4 ip4;
  73. struct flowi6 ip6;
  74. struct flowidn dn;
  75. } u;
  76. #define flowi_oif u.__fl_common.flowic_oif
  77. #define flowi_iif u.__fl_common.flowic_iif
  78. #define flowi_mark u.__fl_common.flowic_mark
  79. #define flowi_tos u.__fl_common.flowic_tos
  80. #define flowi_scope u.__fl_common.flowic_scope
  81. #define flowi_proto u.__fl_common.flowic_proto
  82. #define flowi_flags u.__fl_common.flowic_flags
  83. #define flowi_secid u.__fl_common.flowic_secid
  84. #define fl4_tos flowi_tos
  85. #define fl4_scope flowi_scope
  86. #define fld_scope flowi_scope
  87. #define fld_dst u.dn.daddr
  88. #define fld_src u.dn.saddr
  89. #define fl6_dst u.ip6.daddr
  90. #define fl6_src u.ip6.saddr
  91. #define fl6_flowlabel u.ip6.flowlabel
  92. #define fl4_dst u.ip4.daddr
  93. #define fl4_src u.ip4.saddr
  94. #define fl4_sport u.ip4.uli.ports.sport
  95. #define fl4_dport u.ip4.uli.ports.dport
  96. #define fl4_icmp_type u.ip4.uli.icmpt.type
  97. #define fl4_icmp_code u.ip4.uli.icmpt.code
  98. #define fl4_ipsec_spi u.ip4.uli.spi
  99. #define fl4_mh_type u.ip4.uli.mht.type
  100. #define fl4_gre_key u.ip4.uli.gre_key
  101. #define fl6_sport u.ip6.uli.ports.sport
  102. #define fl6_dport u.ip6.uli.ports.dport
  103. #define fl6_icmp_type u.ip6.uli.icmpt.type
  104. #define fl6_icmp_code u.ip6.uli.icmpt.code
  105. #define fl6_ipsec_spi u.ip6.uli.spi
  106. #define fl6_mh_type u.ip6.uli.mht.type
  107. #define fl6_gre_key u.ip6.uli.gre_key
  108. } __attribute__((__aligned__(BITS_PER_LONG/8)));
  109. static inline struct flowi *flowi4_to_flowi(struct flowi4 *fl4)
  110. {
  111. return container_of(fl4, struct flowi, u.ip4);
  112. }
  113. static inline struct flowi *flowi6_to_flowi(struct flowi6 *fl6)
  114. {
  115. return container_of(fl6, struct flowi, u.ip6);
  116. }
  117. static inline struct flowi *flowidn_to_flowi(struct flowidn *fldn)
  118. {
  119. return container_of(fldn, struct flowi, u.dn);
  120. }
  121. #define FLOW_DIR_IN 0
  122. #define FLOW_DIR_OUT 1
  123. #define FLOW_DIR_FWD 2
  124. struct net;
  125. struct sock;
  126. struct flow_cache_ops;
  127. struct flow_cache_object {
  128. const struct flow_cache_ops *ops;
  129. };
  130. struct flow_cache_ops {
  131. struct flow_cache_object *(*get)(struct flow_cache_object *);
  132. int (*check)(struct flow_cache_object *);
  133. void (*delete)(struct flow_cache_object *);
  134. };
  135. typedef struct flow_cache_object *(*flow_resolve_t)(
  136. struct net *net, const struct flowi *key, u16 family,
  137. u8 dir, struct flow_cache_object *oldobj, void *ctx);
  138. extern struct flow_cache_object *flow_cache_lookup(
  139. struct net *net, const struct flowi *key, u16 family,
  140. u8 dir, flow_resolve_t resolver, void *ctx);
  141. extern void flow_cache_flush(void);
  142. extern atomic_t flow_cache_genid;
  143. #endif