flow.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 {
  11. int oif;
  12. int iif;
  13. __u32 mark;
  14. __u8 tos;
  15. __u8 scope;
  16. __u8 proto;
  17. __u8 flags;
  18. #define FLOWI_FLAG_ANYSRC 0x01
  19. #define FLOWI_FLAG_PRECOW_METRICS 0x02
  20. #define FLOWI_FLAG_CAN_SLEEP 0x04
  21. __u32 secid;
  22. union {
  23. struct {
  24. __be32 daddr;
  25. __be32 saddr;
  26. } ip4_u;
  27. struct {
  28. struct in6_addr daddr;
  29. struct in6_addr saddr;
  30. __be32 flowlabel;
  31. } ip6_u;
  32. struct {
  33. __le16 daddr;
  34. __le16 saddr;
  35. __u8 scope;
  36. } dn_u;
  37. } nl_u;
  38. #define fld_dst nl_u.dn_u.daddr
  39. #define fld_src nl_u.dn_u.saddr
  40. #define fld_scope nl_u.dn_u.scope
  41. #define fl6_dst nl_u.ip6_u.daddr
  42. #define fl6_src nl_u.ip6_u.saddr
  43. #define fl6_flowlabel nl_u.ip6_u.flowlabel
  44. #define fl4_dst nl_u.ip4_u.daddr
  45. #define fl4_src nl_u.ip4_u.saddr
  46. #define fl4_tos tos
  47. #define fl4_scope scope
  48. union {
  49. struct {
  50. __be16 sport;
  51. __be16 dport;
  52. } ports;
  53. struct {
  54. __u8 type;
  55. __u8 code;
  56. } icmpt;
  57. struct {
  58. __le16 sport;
  59. __le16 dport;
  60. } dnports;
  61. __be32 spi;
  62. __be32 gre_key;
  63. struct {
  64. __u8 type;
  65. } mht;
  66. } uli_u;
  67. #define fl_ip_sport uli_u.ports.sport
  68. #define fl_ip_dport uli_u.ports.dport
  69. #define fl_icmp_type uli_u.icmpt.type
  70. #define fl_icmp_code uli_u.icmpt.code
  71. #define fl_ipsec_spi uli_u.spi
  72. #define fl_mh_type uli_u.mht.type
  73. #define fl_gre_key uli_u.gre_key
  74. } __attribute__((__aligned__(BITS_PER_LONG/8)));
  75. #define FLOW_DIR_IN 0
  76. #define FLOW_DIR_OUT 1
  77. #define FLOW_DIR_FWD 2
  78. struct net;
  79. struct sock;
  80. struct flow_cache_ops;
  81. struct flow_cache_object {
  82. const struct flow_cache_ops *ops;
  83. };
  84. struct flow_cache_ops {
  85. struct flow_cache_object *(*get)(struct flow_cache_object *);
  86. int (*check)(struct flow_cache_object *);
  87. void (*delete)(struct flow_cache_object *);
  88. };
  89. typedef struct flow_cache_object *(*flow_resolve_t)(
  90. struct net *net, const struct flowi *key, u16 family,
  91. u8 dir, struct flow_cache_object *oldobj, void *ctx);
  92. extern struct flow_cache_object *flow_cache_lookup(
  93. struct net *net, const struct flowi *key, u16 family,
  94. u8 dir, flow_resolve_t resolver, void *ctx);
  95. extern void flow_cache_flush(void);
  96. extern atomic_t flow_cache_genid;
  97. static inline int flow_cache_uli_match(const struct flowi *fl1,
  98. const struct flowi *fl2)
  99. {
  100. return (fl1->proto == fl2->proto &&
  101. !memcmp(&fl1->uli_u, &fl2->uli_u, sizeof(fl1->uli_u)));
  102. }
  103. #endif