flow.h 2.5 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. union {
  15. struct {
  16. __be32 daddr;
  17. __be32 saddr;
  18. __u8 tos;
  19. __u8 scope;
  20. } ip4_u;
  21. struct {
  22. struct in6_addr daddr;
  23. struct in6_addr saddr;
  24. __be32 flowlabel;
  25. } ip6_u;
  26. struct {
  27. __le16 daddr;
  28. __le16 saddr;
  29. __u8 scope;
  30. } dn_u;
  31. } nl_u;
  32. #define fld_dst nl_u.dn_u.daddr
  33. #define fld_src nl_u.dn_u.saddr
  34. #define fld_scope nl_u.dn_u.scope
  35. #define fl6_dst nl_u.ip6_u.daddr
  36. #define fl6_src nl_u.ip6_u.saddr
  37. #define fl6_flowlabel nl_u.ip6_u.flowlabel
  38. #define fl4_dst nl_u.ip4_u.daddr
  39. #define fl4_src nl_u.ip4_u.saddr
  40. #define fl4_tos nl_u.ip4_u.tos
  41. #define fl4_scope nl_u.ip4_u.scope
  42. __u8 proto;
  43. __u8 flags;
  44. #define FLOWI_FLAG_ANYSRC 0x01
  45. #define FLOWI_FLAG_PRECOW_METRICS 0x02
  46. #define FLOWI_FLAG_CAN_SLEEP 0x04
  47. union {
  48. struct {
  49. __be16 sport;
  50. __be16 dport;
  51. } ports;
  52. struct {
  53. __u8 type;
  54. __u8 code;
  55. } icmpt;
  56. struct {
  57. __le16 sport;
  58. __le16 dport;
  59. } dnports;
  60. __be32 spi;
  61. __be32 gre_key;
  62. struct {
  63. __u8 type;
  64. } mht;
  65. } uli_u;
  66. #define fl_ip_sport uli_u.ports.sport
  67. #define fl_ip_dport uli_u.ports.dport
  68. #define fl_icmp_type uli_u.icmpt.type
  69. #define fl_icmp_code uli_u.icmpt.code
  70. #define fl_ipsec_spi uli_u.spi
  71. #define fl_mh_type uli_u.mht.type
  72. #define fl_gre_key uli_u.gre_key
  73. __u32 secid; /* used by xfrm; see secid.txt */
  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