blob: 8d5b402d600af3acfc2a0ff2d4519b1d74b89127 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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. Miller806566c2011-03-11 18:22:00 -050013struct 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. Millerfbef0a42011-03-11 15:55:37 -050021#define FLOWI_FLAG_ANYSRC 0x01
22#define FLOWI_FLAG_PRECOW_METRICS 0x02
23#define FLOWI_FLAG_CAN_SLEEP 0x04
David S. Miller806566c2011-03-11 18:22:00 -050024 __u32 flowic_secid;
25};
26
David S. Miller08704bc2011-03-11 18:36:42 -050027union 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. Miller56bb8052011-03-12 00:44:35 -050051struct flowi4 {
David S. Miller806566c2011-03-11 18:22:00 -050052 struct flowi_common __fl_common;
David S. Miller22bd5b92011-03-11 19:54:08 -050053#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. Miller56bb8052011-03-12 00:44:35 -050061 __be32 daddr;
62 __be32 saddr;
63 union flowi_uli uli;
64};
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
David S. Miller56bb8052011-03-12 00:44:35 -050066struct flowi6 {
67 struct flowi_common __fl_common;
David S. Miller20326562011-03-12 02:30:50 -050068#define flowi6_oif __fl_common.flowic_oif
69#define flowi6_iif __fl_common.flowic_iif
70#define flowi6_mark __fl_common.flowic_mark
71#define flowi6_tos __fl_common.flowic_tos
72#define flowi6_scope __fl_common.flowic_scope
73#define flowi6_proto __fl_common.flowic_proto
74#define flowi6_flags __fl_common.flowic_flags
75#define flowi6_secid __fl_common.flowic_secid
David S. Miller56bb8052011-03-12 00:44:35 -050076 struct in6_addr daddr;
77 struct in6_addr saddr;
78 __be32 flowlabel;
79 union flowi_uli uli;
80};
81
82struct flowidn {
83 struct flowi_common __fl_common;
84 __le16 daddr;
85 __le16 saddr;
86 union flowi_uli uli;
87};
88
89struct flowi {
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 union {
David S. Miller56bb8052011-03-12 00:44:35 -050091 struct flowi_common __fl_common;
92 struct flowi4 ip4;
93 struct flowi6 ip6;
94 struct flowidn dn;
95 } u;
96#define flowi_oif u.__fl_common.flowic_oif
97#define flowi_iif u.__fl_common.flowic_iif
98#define flowi_mark u.__fl_common.flowic_mark
99#define flowi_tos u.__fl_common.flowic_tos
100#define flowi_scope u.__fl_common.flowic_scope
101#define flowi_proto u.__fl_common.flowic_proto
102#define flowi_flags u.__fl_common.flowic_flags
103#define flowi_secid u.__fl_common.flowic_secid
David S. Miller1d28f422011-03-12 00:29:39 -0500104#define fl4_tos flowi_tos
105#define fl4_scope flowi_scope
David S. Miller56bb8052011-03-12 00:44:35 -0500106#define fld_scope flowi_scope
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
David S. Miller56bb8052011-03-12 00:44:35 -0500108#define fld_dst u.dn.daddr
109#define fld_src u.dn.saddr
110#define fl6_dst u.ip6.daddr
111#define fl6_src u.ip6.saddr
112#define fl6_flowlabel u.ip6.flowlabel
113#define fl4_dst u.ip4.daddr
114#define fl4_src u.ip4.saddr
115#define fl4_sport u.ip4.uli.ports.sport
116#define fl4_dport u.ip4.uli.ports.dport
117#define fl4_icmp_type u.ip4.uli.icmpt.type
118#define fl4_icmp_code u.ip4.uli.icmpt.code
119#define fl4_ipsec_spi u.ip4.uli.spi
120#define fl4_mh_type u.ip4.uli.mht.type
121#define fl4_gre_key u.ip4.uli.gre_key
122#define fl6_sport u.ip6.uli.ports.sport
123#define fl6_dport u.ip6.uli.ports.dport
124#define fl6_icmp_type u.ip6.uli.icmpt.type
125#define fl6_icmp_code u.ip6.uli.icmpt.code
126#define fl6_ipsec_spi u.ip6.uli.spi
127#define fl6_mh_type u.ip6.uli.mht.type
128#define fl6_gre_key u.ip6.uli.gre_key
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129} __attribute__((__aligned__(BITS_PER_LONG/8)));
130
David S. Miller59b1a942011-03-11 19:23:02 -0500131static inline struct flowi *flowi4_to_flowi(struct flowi4 *fl4)
132{
133 return container_of(fl4, struct flowi, u.ip4);
134}
135
136static inline struct flowi *flowi6_to_flowi(struct flowi6 *fl6)
137{
138 return container_of(fl6, struct flowi, u.ip6);
139}
140
141static inline struct flowi *flowidn_to_flowi(struct flowidn *fldn)
142{
143 return container_of(fldn, struct flowi, u.dn);
144}
145
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146#define FLOW_DIR_IN 0
147#define FLOW_DIR_OUT 1
148#define FLOW_DIR_FWD 2
149
Alexey Dobriyan52479b62008-11-25 17:35:18 -0800150struct net;
Trent Jaegerdf718372005-12-13 23:12:27 -0800151struct sock;
Timo Teräsfe1a5f02010-04-07 00:30:04 +0000152struct flow_cache_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
Timo Teräsfe1a5f02010-04-07 00:30:04 +0000154struct flow_cache_object {
155 const struct flow_cache_ops *ops;
156};
157
158struct flow_cache_ops {
159 struct flow_cache_object *(*get)(struct flow_cache_object *);
160 int (*check)(struct flow_cache_object *);
161 void (*delete)(struct flow_cache_object *);
162};
163
164typedef struct flow_cache_object *(*flow_resolve_t)(
David S. Millerdee9f4b2011-02-22 18:44:31 -0800165 struct net *net, const struct flowi *key, u16 family,
Timo Teräsfe1a5f02010-04-07 00:30:04 +0000166 u8 dir, struct flow_cache_object *oldobj, void *ctx);
167
168extern struct flow_cache_object *flow_cache_lookup(
David S. Millerdee9f4b2011-02-22 18:44:31 -0800169 struct net *net, const struct flowi *key, u16 family,
Timo Teräsfe1a5f02010-04-07 00:30:04 +0000170 u8 dir, flow_resolve_t resolver, void *ctx);
171
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172extern void flow_cache_flush(void);
173extern atomic_t flow_cache_genid;
174
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175#endif