blob: 541ac13f245a54e7ab4c2f4e53c9968a8934ed03 [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. Miller806566c2011-03-11 18:22:00 -050051struct flowi {
52 struct flowi_common __fl_common;
53#define flowi_oif __fl_common.flowic_oif
54#define flowi_iif __fl_common.flowic_iif
55#define flowi_mark __fl_common.flowic_mark
56#define flowi_tos __fl_common.flowic_tos
57#define flowi_scope __fl_common.flowic_scope
58#define flowi_proto __fl_common.flowic_proto
59#define flowi_flags __fl_common.flowic_flags
60#define flowi_secid __fl_common.flowic_secid
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
62 union {
63 struct {
Al Virof2c3fe22006-09-26 21:26:42 -070064 __be32 daddr;
65 __be32 saddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 } ip4_u;
67
68 struct {
69 struct in6_addr daddr;
70 struct in6_addr saddr;
Al Viro90bcaf72006-11-08 00:25:17 -080071 __be32 flowlabel;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 } ip6_u;
73
74 struct {
Steven Whitehousec4ea94a2006-03-20 22:42:39 -080075 __le16 daddr;
76 __le16 saddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 __u8 scope;
78 } dn_u;
79 } nl_u;
80#define fld_dst nl_u.dn_u.daddr
81#define fld_src nl_u.dn_u.saddr
Linus Torvalds1da177e2005-04-16 15:20:36 -070082#define fld_scope nl_u.dn_u.scope
83#define fl6_dst nl_u.ip6_u.daddr
84#define fl6_src nl_u.ip6_u.saddr
85#define fl6_flowlabel nl_u.ip6_u.flowlabel
86#define fl4_dst nl_u.ip4_u.daddr
87#define fl4_src nl_u.ip4_u.saddr
David S. Miller1d28f422011-03-12 00:29:39 -050088#define fl4_tos flowi_tos
89#define fl4_scope flowi_scope
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
David S. Miller08704bc2011-03-11 18:36:42 -050091 union flowi_uli uli_u;
Linus Torvalds1da177e2005-04-16 15:20:36 -070092#define fl_ip_sport uli_u.ports.sport
93#define fl_ip_dport uli_u.ports.dport
94#define fl_icmp_type uli_u.icmpt.type
95#define fl_icmp_code uli_u.icmpt.code
96#define fl_ipsec_spi uli_u.spi
Masahide NAKAMURA2b741652006-08-23 20:34:26 -070097#define fl_mh_type uli_u.mht.type
Timo Teräscc9ff192010-11-03 04:41:38 +000098#define fl_gre_key uli_u.gre_key
Linus Torvalds1da177e2005-04-16 15:20:36 -070099} __attribute__((__aligned__(BITS_PER_LONG/8)));
100
101#define FLOW_DIR_IN 0
102#define FLOW_DIR_OUT 1
103#define FLOW_DIR_FWD 2
104
Alexey Dobriyan52479b62008-11-25 17:35:18 -0800105struct net;
Trent Jaegerdf718372005-12-13 23:12:27 -0800106struct sock;
Timo Teräsfe1a5f02010-04-07 00:30:04 +0000107struct flow_cache_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
Timo Teräsfe1a5f02010-04-07 00:30:04 +0000109struct flow_cache_object {
110 const struct flow_cache_ops *ops;
111};
112
113struct flow_cache_ops {
114 struct flow_cache_object *(*get)(struct flow_cache_object *);
115 int (*check)(struct flow_cache_object *);
116 void (*delete)(struct flow_cache_object *);
117};
118
119typedef struct flow_cache_object *(*flow_resolve_t)(
David S. Millerdee9f4b2011-02-22 18:44:31 -0800120 struct net *net, const struct flowi *key, u16 family,
Timo Teräsfe1a5f02010-04-07 00:30:04 +0000121 u8 dir, struct flow_cache_object *oldobj, void *ctx);
122
123extern struct flow_cache_object *flow_cache_lookup(
David S. Millerdee9f4b2011-02-22 18:44:31 -0800124 struct net *net, const struct flowi *key, u16 family,
Timo Teräsfe1a5f02010-04-07 00:30:04 +0000125 u8 dir, flow_resolve_t resolver, void *ctx);
126
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127extern void flow_cache_flush(void);
128extern atomic_t flow_cache_genid;
129
David S. Miller0730b9a2011-02-22 18:27:22 -0800130static inline int flow_cache_uli_match(const struct flowi *fl1,
131 const struct flowi *fl2)
Masahide NAKAMURA157bfc22007-04-30 00:33:35 -0700132{
David S. Miller1d28f422011-03-12 00:29:39 -0500133 return (fl1->flowi_proto == fl2->flowi_proto &&
Masahide NAKAMURA157bfc22007-04-30 00:33:35 -0700134 !memcmp(&fl1->uli_u, &fl2->uli_u, sizeof(fl1->uli_u)));
135}
136
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137#endif