flow.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. struct flowi {
  24. struct flowi_common __fl_common;
  25. #define flowi_oif __fl_common.flowic_oif
  26. #define flowi_iif __fl_common.flowic_iif
  27. #define flowi_mark __fl_common.flowic_mark
  28. #define flowi_tos __fl_common.flowic_tos
  29. #define flowi_scope __fl_common.flowic_scope
  30. #define flowi_proto __fl_common.flowic_proto
  31. #define flowi_flags __fl_common.flowic_flags
  32. #define flowi_secid __fl_common.flowic_secid
  33. union {
  34. struct {
  35. __be32 daddr;
  36. __be32 saddr;
  37. } ip4_u;
  38. struct {
  39. struct in6_addr daddr;
  40. struct in6_addr saddr;
  41. __be32 flowlabel;
  42. } ip6_u;
  43. struct {
  44. __le16 daddr;
  45. __le16 saddr;
  46. __u8 scope;
  47. } dn_u;
  48. } nl_u;
  49. #define fld_dst nl_u.dn_u.daddr
  50. #define fld_src nl_u.dn_u.saddr
  51. #define fld_scope nl_u.dn_u.scope
  52. #define fl6_dst nl_u.ip6_u.daddr
  53. #define fl6_src nl_u.ip6_u.saddr
  54. #define fl6_flowlabel nl_u.ip6_u.flowlabel
  55. #define fl4_dst nl_u.ip4_u.daddr
  56. #define fl4_src nl_u.ip4_u.saddr
  57. #define fl4_tos flowi_tos
  58. #define fl4_scope flowi_scope
  59. union {
  60. struct {
  61. __be16 sport;
  62. __be16 dport;
  63. } ports;
  64. struct {
  65. __u8 type;
  66. __u8 code;
  67. } icmpt;
  68. struct {
  69. __le16 sport;
  70. __le16 dport;
  71. } dnports;
  72. __be32 spi;
  73. __be32 gre_key;
  74. struct {
  75. __u8 type;
  76. } mht;
  77. } uli_u;
  78. #define fl_ip_sport uli_u.ports.sport
  79. #define fl_ip_dport uli_u.ports.dport
  80. #define fl_icmp_type uli_u.icmpt.type
  81. #define fl_icmp_code uli_u.icmpt.code
  82. #define fl_ipsec_spi uli_u.spi
  83. #define fl_mh_type uli_u.mht.type
  84. #define fl_gre_key uli_u.gre_key
  85. } __attribute__((__aligned__(BITS_PER_LONG/8)));
  86. #define FLOW_DIR_IN 0
  87. #define FLOW_DIR_OUT 1
  88. #define FLOW_DIR_FWD 2
  89. struct net;
  90. struct sock;
  91. struct flow_cache_ops;
  92. struct flow_cache_object {
  93. const struct flow_cache_ops *ops;
  94. };
  95. struct flow_cache_ops {
  96. struct flow_cache_object *(*get)(struct flow_cache_object *);
  97. int (*check)(struct flow_cache_object *);
  98. void (*delete)(struct flow_cache_object *);
  99. };
  100. typedef struct flow_cache_object *(*flow_resolve_t)(
  101. struct net *net, const struct flowi *key, u16 family,
  102. u8 dir, struct flow_cache_object *oldobj, void *ctx);
  103. extern struct flow_cache_object *flow_cache_lookup(
  104. struct net *net, const struct flowi *key, u16 family,
  105. u8 dir, flow_resolve_t resolver, void *ctx);
  106. extern void flow_cache_flush(void);
  107. extern atomic_t flow_cache_genid;
  108. static inline int flow_cache_uli_match(const struct flowi *fl1,
  109. const struct flowi *fl2)
  110. {
  111. return (fl1->flowi_proto == fl2->flowi_proto &&
  112. !memcmp(&fl1->uli_u, &fl2->uli_u, sizeof(fl1->uli_u)));
  113. }
  114. #endif