Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Generic internet FLOW. |
| 4 | * |
| 5 | */ |
| 6 | |
| 7 | #ifndef _NET_FLOW_H |
| 8 | #define _NET_FLOW_H |
| 9 | |
| 10 | #include <linux/in6.h> |
| 11 | #include <asm/atomic.h> |
| 12 | |
David S. Miller | 806566c | 2011-03-11 18:22:00 -0500 | [diff] [blame] | 13 | struct flowi_common { |
| 14 | int flowic_oif; |
| 15 | int flowic_iif; |
| 16 | __u32 flowic_mark; |
| 17 | __u8 flowic_tos; |
| 18 | __u8 flowic_scope; |
| 19 | __u8 flowic_proto; |
| 20 | __u8 flowic_flags; |
David S. Miller | fbef0a4 | 2011-03-11 15:55:37 -0500 | [diff] [blame] | 21 | #define FLOWI_FLAG_ANYSRC 0x01 |
| 22 | #define FLOWI_FLAG_PRECOW_METRICS 0x02 |
| 23 | #define FLOWI_FLAG_CAN_SLEEP 0x04 |
David S. Miller | 806566c | 2011-03-11 18:22:00 -0500 | [diff] [blame] | 24 | __u32 flowic_secid; |
| 25 | }; |
| 26 | |
David S. Miller | 08704bc | 2011-03-11 18:36:42 -0500 | [diff] [blame] | 27 | union flowi_uli { |
| 28 | struct { |
| 29 | __be16 sport; |
| 30 | __be16 dport; |
| 31 | } ports; |
| 32 | |
| 33 | struct { |
| 34 | __u8 type; |
| 35 | __u8 code; |
| 36 | } icmpt; |
| 37 | |
| 38 | struct { |
| 39 | __le16 sport; |
| 40 | __le16 dport; |
| 41 | } dnports; |
| 42 | |
| 43 | __be32 spi; |
| 44 | __be32 gre_key; |
| 45 | |
| 46 | struct { |
| 47 | __u8 type; |
| 48 | } mht; |
| 49 | }; |
| 50 | |
David S. Miller | 56bb805 | 2011-03-12 00:44:35 -0500 | [diff] [blame] | 51 | struct flowi4 { |
David S. Miller | 806566c | 2011-03-11 18:22:00 -0500 | [diff] [blame] | 52 | struct flowi_common __fl_common; |
David S. Miller | 22bd5b9 | 2011-03-11 19:54:08 -0500 | [diff] [blame] | 53 | #define flowi4_oif __fl_common.flowic_oif |
| 54 | #define flowi4_iif __fl_common.flowic_iif |
| 55 | #define flowi4_mark __fl_common.flowic_mark |
| 56 | #define flowi4_tos __fl_common.flowic_tos |
| 57 | #define flowi4_scope __fl_common.flowic_scope |
| 58 | #define flowi4_proto __fl_common.flowic_proto |
| 59 | #define flowi4_flags __fl_common.flowic_flags |
| 60 | #define flowi4_secid __fl_common.flowic_secid |
David S. Miller | 56bb805 | 2011-03-12 00:44:35 -0500 | [diff] [blame] | 61 | __be32 daddr; |
| 62 | __be32 saddr; |
| 63 | union flowi_uli uli; |
David S. Miller | 9cce96d | 2011-03-12 03:00:33 -0500 | [diff] [blame] | 64 | #define fl4_sport uli.ports.sport |
| 65 | #define fl4_dport uli.ports.dport |
| 66 | #define fl4_icmp_type uli.icmpt.type |
| 67 | #define fl4_icmp_code uli.icmpt.code |
| 68 | #define fl4_ipsec_spi uli.spi |
| 69 | #define fl4_mh_type uli.mht.type |
| 70 | #define fl4_gre_key uli.gre_key |
David S. Miller | 56bb805 | 2011-03-12 00:44:35 -0500 | [diff] [blame] | 71 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
David S. Miller | 56bb805 | 2011-03-12 00:44:35 -0500 | [diff] [blame] | 73 | struct flowi6 { |
| 74 | struct flowi_common __fl_common; |
David S. Miller | 2032656e | 2011-03-12 02:30:50 -0500 | [diff] [blame] | 75 | #define flowi6_oif __fl_common.flowic_oif |
| 76 | #define flowi6_iif __fl_common.flowic_iif |
| 77 | #define flowi6_mark __fl_common.flowic_mark |
| 78 | #define flowi6_tos __fl_common.flowic_tos |
| 79 | #define flowi6_scope __fl_common.flowic_scope |
| 80 | #define flowi6_proto __fl_common.flowic_proto |
| 81 | #define flowi6_flags __fl_common.flowic_flags |
| 82 | #define flowi6_secid __fl_common.flowic_secid |
David S. Miller | 56bb805 | 2011-03-12 00:44:35 -0500 | [diff] [blame] | 83 | struct in6_addr daddr; |
| 84 | struct in6_addr saddr; |
| 85 | __be32 flowlabel; |
| 86 | union flowi_uli uli; |
David S. Miller | 1958b85 | 2011-03-12 16:36:19 -0500 | [diff] [blame] | 87 | #define fl6_sport uli.ports.sport |
| 88 | #define fl6_dport uli.ports.dport |
| 89 | #define fl6_icmp_type uli.icmpt.type |
| 90 | #define fl6_icmp_code uli.icmpt.code |
| 91 | #define fl6_ipsec_spi uli.spi |
| 92 | #define fl6_mh_type uli.mht.type |
| 93 | #define fl6_gre_key uli.gre_key |
David S. Miller | 56bb805 | 2011-03-12 00:44:35 -0500 | [diff] [blame] | 94 | }; |
| 95 | |
| 96 | struct flowidn { |
| 97 | struct flowi_common __fl_common; |
David S. Miller | bef55ae | 2011-03-12 17:17:10 -0500 | [diff] [blame] | 98 | #define flowidn_oif __fl_common.flowic_oif |
| 99 | #define flowidn_iif __fl_common.flowic_iif |
| 100 | #define flowidn_mark __fl_common.flowic_mark |
| 101 | #define flowidn_scope __fl_common.flowic_scope |
| 102 | #define flowidn_proto __fl_common.flowic_proto |
| 103 | #define flowidn_flags __fl_common.flowic_flags |
David S. Miller | 56bb805 | 2011-03-12 00:44:35 -0500 | [diff] [blame] | 104 | __le16 daddr; |
| 105 | __le16 saddr; |
| 106 | union flowi_uli uli; |
David S. Miller | bef55ae | 2011-03-12 17:17:10 -0500 | [diff] [blame] | 107 | #define fld_sport uli.ports.sport |
| 108 | #define fld_dport uli.ports.dport |
David S. Miller | 56bb805 | 2011-03-12 00:44:35 -0500 | [diff] [blame] | 109 | }; |
| 110 | |
| 111 | struct flowi { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | union { |
David S. Miller | 56bb805 | 2011-03-12 00:44:35 -0500 | [diff] [blame] | 113 | struct flowi_common __fl_common; |
| 114 | struct flowi4 ip4; |
| 115 | struct flowi6 ip6; |
| 116 | struct flowidn dn; |
| 117 | } u; |
| 118 | #define flowi_oif u.__fl_common.flowic_oif |
| 119 | #define flowi_iif u.__fl_common.flowic_iif |
| 120 | #define flowi_mark u.__fl_common.flowic_mark |
| 121 | #define flowi_tos u.__fl_common.flowic_tos |
| 122 | #define flowi_scope u.__fl_common.flowic_scope |
| 123 | #define flowi_proto u.__fl_common.flowic_proto |
| 124 | #define flowi_flags u.__fl_common.flowic_flags |
| 125 | #define flowi_secid u.__fl_common.flowic_secid |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | } __attribute__((__aligned__(BITS_PER_LONG/8))); |
| 127 | |
David S. Miller | 59b1a94 | 2011-03-11 19:23:02 -0500 | [diff] [blame] | 128 | static inline struct flowi *flowi4_to_flowi(struct flowi4 *fl4) |
| 129 | { |
| 130 | return container_of(fl4, struct flowi, u.ip4); |
| 131 | } |
| 132 | |
| 133 | static inline struct flowi *flowi6_to_flowi(struct flowi6 *fl6) |
| 134 | { |
| 135 | return container_of(fl6, struct flowi, u.ip6); |
| 136 | } |
| 137 | |
| 138 | static inline struct flowi *flowidn_to_flowi(struct flowidn *fldn) |
| 139 | { |
| 140 | return container_of(fldn, struct flowi, u.dn); |
| 141 | } |
| 142 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | #define FLOW_DIR_IN 0 |
| 144 | #define FLOW_DIR_OUT 1 |
| 145 | #define FLOW_DIR_FWD 2 |
| 146 | |
Alexey Dobriyan | 52479b6 | 2008-11-25 17:35:18 -0800 | [diff] [blame] | 147 | struct net; |
Trent Jaeger | df71837 | 2005-12-13 23:12:27 -0800 | [diff] [blame] | 148 | struct sock; |
Timo Teräs | fe1a5f0 | 2010-04-07 00:30:04 +0000 | [diff] [blame] | 149 | struct flow_cache_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | |
Timo Teräs | fe1a5f0 | 2010-04-07 00:30:04 +0000 | [diff] [blame] | 151 | struct flow_cache_object { |
| 152 | const struct flow_cache_ops *ops; |
| 153 | }; |
| 154 | |
| 155 | struct flow_cache_ops { |
| 156 | struct flow_cache_object *(*get)(struct flow_cache_object *); |
| 157 | int (*check)(struct flow_cache_object *); |
| 158 | void (*delete)(struct flow_cache_object *); |
| 159 | }; |
| 160 | |
| 161 | typedef struct flow_cache_object *(*flow_resolve_t)( |
David S. Miller | dee9f4b | 2011-02-22 18:44:31 -0800 | [diff] [blame] | 162 | struct net *net, const struct flowi *key, u16 family, |
Timo Teräs | fe1a5f0 | 2010-04-07 00:30:04 +0000 | [diff] [blame] | 163 | u8 dir, struct flow_cache_object *oldobj, void *ctx); |
| 164 | |
| 165 | extern struct flow_cache_object *flow_cache_lookup( |
David S. Miller | dee9f4b | 2011-02-22 18:44:31 -0800 | [diff] [blame] | 166 | struct net *net, const struct flowi *key, u16 family, |
Timo Teräs | fe1a5f0 | 2010-04-07 00:30:04 +0000 | [diff] [blame] | 167 | u8 dir, flow_resolve_t resolver, void *ctx); |
| 168 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | extern void flow_cache_flush(void); |
| 170 | extern atomic_t flow_cache_genid; |
| 171 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | #endif |