flow.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. union {
  47. struct {
  48. __be16 sport;
  49. __be16 dport;
  50. } ports;
  51. struct {
  52. __u8 type;
  53. __u8 code;
  54. } icmpt;
  55. struct {
  56. __le16 sport;
  57. __le16 dport;
  58. } dnports;
  59. __be32 spi;
  60. __be32 gre_key;
  61. struct {
  62. __u8 type;
  63. } mht;
  64. } uli_u;
  65. #define fl_ip_sport uli_u.ports.sport
  66. #define fl_ip_dport uli_u.ports.dport
  67. #define fl_icmp_type uli_u.icmpt.type
  68. #define fl_icmp_code uli_u.icmpt.code
  69. #define fl_ipsec_spi uli_u.spi
  70. #define fl_mh_type uli_u.mht.type
  71. #define fl_gre_key uli_u.gre_key
  72. __u32 secid; /* used by xfrm; see secid.txt */
  73. } __attribute__((__aligned__(BITS_PER_LONG/8)));
  74. #define FLOW_DIR_IN 0
  75. #define FLOW_DIR_OUT 1
  76. #define FLOW_DIR_FWD 2
  77. struct net;
  78. struct sock;
  79. struct flow_cache_ops;
  80. struct flow_cache_object {
  81. const struct flow_cache_ops *ops;
  82. };
  83. struct flow_cache_ops {
  84. struct flow_cache_object *(*get)(struct flow_cache_object *);
  85. int (*check)(struct flow_cache_object *);
  86. void (*delete)(struct flow_cache_object *);
  87. };
  88. typedef struct flow_cache_object *(*flow_resolve_t)(
  89. struct net *net, const struct flowi *key, u16 family,
  90. u8 dir, struct flow_cache_object *oldobj, void *ctx);
  91. extern struct flow_cache_object *flow_cache_lookup(
  92. struct net *net, const struct flowi *key, u16 family,
  93. u8 dir, flow_resolve_t resolver, void *ctx);
  94. extern void flow_cache_flush(void);
  95. extern atomic_t flow_cache_genid;
  96. static inline int flow_cache_uli_match(const struct flowi *fl1,
  97. const struct flowi *fl2)
  98. {
  99. return (fl1->proto == fl2->proto &&
  100. !memcmp(&fl1->uli_u, &fl2->uli_u, sizeof(fl1->uli_u)));
  101. }
  102. #endif