diff options
Diffstat (limited to 'include/net/flow.h')
-rw-r--r-- | include/net/flow.h | 204 |
1 files changed, 128 insertions, 76 deletions
diff --git a/include/net/flow.h b/include/net/flow.h index 240b7f356c71..7fe5a0f9483a 100644 --- a/include/net/flow.h +++ b/include/net/flow.h | |||
@@ -10,78 +10,136 @@ | |||
10 | #include <linux/in6.h> | 10 | #include <linux/in6.h> |
11 | #include <asm/atomic.h> | 11 | #include <asm/atomic.h> |
12 | 12 | ||
13 | struct flowi { | 13 | struct flowi_common { |
14 | int oif; | 14 | int flowic_oif; |
15 | int iif; | 15 | int flowic_iif; |
16 | __u32 mark; | 16 | __u32 flowic_mark; |
17 | __u8 flowic_tos; | ||
18 | __u8 flowic_scope; | ||
19 | __u8 flowic_proto; | ||
20 | __u8 flowic_flags; | ||
21 | #define FLOWI_FLAG_ANYSRC 0x01 | ||
22 | #define FLOWI_FLAG_PRECOW_METRICS 0x02 | ||
23 | #define FLOWI_FLAG_CAN_SLEEP 0x04 | ||
24 | __u32 flowic_secid; | ||
25 | }; | ||
17 | 26 | ||
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 | |||
51 | struct flowi4 { | ||
52 | struct flowi_common __fl_common; | ||
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 | ||
61 | __be32 daddr; | ||
62 | __be32 saddr; | ||
63 | union flowi_uli uli; | ||
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 | ||
71 | }; | ||
72 | |||
73 | struct flowi6 { | ||
74 | struct flowi_common __fl_common; | ||
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 | ||
83 | struct in6_addr daddr; | ||
84 | struct in6_addr saddr; | ||
85 | __be32 flowlabel; | ||
86 | union flowi_uli uli; | ||
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 | ||
94 | }; | ||
95 | |||
96 | struct flowidn { | ||
97 | struct flowi_common __fl_common; | ||
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 | ||
104 | __le16 daddr; | ||
105 | __le16 saddr; | ||
106 | union flowi_uli uli; | ||
107 | #define fld_sport uli.ports.sport | ||
108 | #define fld_dport uli.ports.dport | ||
109 | }; | ||
110 | |||
111 | struct flowi { | ||
18 | union { | 112 | union { |
19 | struct { | 113 | struct flowi_common __fl_common; |
20 | __be32 daddr; | 114 | struct flowi4 ip4; |
21 | __be32 saddr; | 115 | struct flowi6 ip6; |
22 | __u8 tos; | 116 | struct flowidn dn; |
23 | __u8 scope; | 117 | } u; |
24 | } ip4_u; | 118 | #define flowi_oif u.__fl_common.flowic_oif |
25 | 119 | #define flowi_iif u.__fl_common.flowic_iif | |
26 | struct { | 120 | #define flowi_mark u.__fl_common.flowic_mark |
27 | struct in6_addr daddr; | 121 | #define flowi_tos u.__fl_common.flowic_tos |
28 | struct in6_addr saddr; | 122 | #define flowi_scope u.__fl_common.flowic_scope |
29 | __be32 flowlabel; | 123 | #define flowi_proto u.__fl_common.flowic_proto |
30 | } ip6_u; | 124 | #define flowi_flags u.__fl_common.flowic_flags |
31 | 125 | #define flowi_secid u.__fl_common.flowic_secid | |
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 nl_u.ip4_u.tos | ||
47 | #define fl4_scope nl_u.ip4_u.scope | ||
48 | |||
49 | __u8 proto; | ||
50 | __u8 flags; | ||
51 | #define FLOWI_FLAG_ANYSRC 0x01 | ||
52 | union { | ||
53 | struct { | ||
54 | __be16 sport; | ||
55 | __be16 dport; | ||
56 | } ports; | ||
57 | |||
58 | struct { | ||
59 | __u8 type; | ||
60 | __u8 code; | ||
61 | } icmpt; | ||
62 | |||
63 | struct { | ||
64 | __le16 sport; | ||
65 | __le16 dport; | ||
66 | } dnports; | ||
67 | |||
68 | __be32 spi; | ||
69 | __be32 gre_key; | ||
70 | |||
71 | struct { | ||
72 | __u8 type; | ||
73 | } mht; | ||
74 | } uli_u; | ||
75 | #define fl_ip_sport uli_u.ports.sport | ||
76 | #define fl_ip_dport uli_u.ports.dport | ||
77 | #define fl_icmp_type uli_u.icmpt.type | ||
78 | #define fl_icmp_code uli_u.icmpt.code | ||
79 | #define fl_ipsec_spi uli_u.spi | ||
80 | #define fl_mh_type uli_u.mht.type | ||
81 | #define fl_gre_key uli_u.gre_key | ||
82 | __u32 secid; /* used by xfrm; see secid.txt */ | ||
83 | } __attribute__((__aligned__(BITS_PER_LONG/8))); | 126 | } __attribute__((__aligned__(BITS_PER_LONG/8))); |
84 | 127 | ||
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 | |||
85 | #define FLOW_DIR_IN 0 | 143 | #define FLOW_DIR_IN 0 |
86 | #define FLOW_DIR_OUT 1 | 144 | #define FLOW_DIR_OUT 1 |
87 | #define FLOW_DIR_FWD 2 | 145 | #define FLOW_DIR_FWD 2 |
@@ -101,20 +159,14 @@ struct flow_cache_ops { | |||
101 | }; | 159 | }; |
102 | 160 | ||
103 | typedef struct flow_cache_object *(*flow_resolve_t)( | 161 | typedef struct flow_cache_object *(*flow_resolve_t)( |
104 | struct net *net, struct flowi *key, u16 family, | 162 | struct net *net, const struct flowi *key, u16 family, |
105 | u8 dir, struct flow_cache_object *oldobj, void *ctx); | 163 | u8 dir, struct flow_cache_object *oldobj, void *ctx); |
106 | 164 | ||
107 | extern struct flow_cache_object *flow_cache_lookup( | 165 | extern struct flow_cache_object *flow_cache_lookup( |
108 | struct net *net, struct flowi *key, u16 family, | 166 | struct net *net, const struct flowi *key, u16 family, |
109 | u8 dir, flow_resolve_t resolver, void *ctx); | 167 | u8 dir, flow_resolve_t resolver, void *ctx); |
110 | 168 | ||
111 | extern void flow_cache_flush(void); | 169 | extern void flow_cache_flush(void); |
112 | extern atomic_t flow_cache_genid; | 170 | extern atomic_t flow_cache_genid; |
113 | 171 | ||
114 | static inline int flow_cache_uli_match(struct flowi *fl1, struct flowi *fl2) | ||
115 | { | ||
116 | return (fl1->proto == fl2->proto && | ||
117 | !memcmp(&fl1->uli_u, &fl2->uli_u, sizeof(fl1->uli_u))); | ||
118 | } | ||
119 | |||
120 | #endif | 172 | #endif |