fib_rules.h 3.2 KB
Newer Older
1 2 3 4
#ifndef __NET_FIB_RULES_H
#define __NET_FIB_RULES_H

#include <linux/types.h>
5
#include <linux/slab.h>
6 7 8
#include <linux/netdevice.h>
#include <linux/fib_rules.h>
#include <net/flow.h>
9
#include <net/rtnetlink.h>
10

E
Eric Dumazet 已提交
11
struct fib_rule {
12 13
	struct list_head	list;
	atomic_t		refcnt;
14
	int			iifindex;
15
	int			oifindex;
16 17
	u32			mark;
	u32			mark_mask;
18 19 20
	u32			pref;
	u32			flags;
	u32			table;
21
	u8			table_prefixlen_min;
22
	u8			action;
T
Thomas Graf 已提交
23
	u32			target;
E
Eric Dumazet 已提交
24
	struct fib_rule __rcu	*ctarget;
25
	char			iifname[IFNAMSIZ];
26
	char			oifname[IFNAMSIZ];
27
	struct rcu_head		rcu;
28
	struct net *		fr_net;
29 30
};

E
Eric Dumazet 已提交
31
struct fib_lookup_arg {
32 33 34
	void			*lookup_ptr;
	void			*result;
	struct fib_rule		*rule;
E
Eric Dumazet 已提交
35 36
	int			flags;
#define FIB_LOOKUP_NOREF	1
37 38
};

E
Eric Dumazet 已提交
39
struct fib_rules_ops {
40 41 42
	int			family;
	struct list_head	list;
	int			rule_size;
43
	int			addr_size;
T
Thomas Graf 已提交
44 45
	int			unresolved_rules;
	int			nr_goto_rules;
46 47 48 49

	int			(*action)(struct fib_rule *,
					  struct flowi *, int,
					  struct fib_lookup_arg *);
50 51
	bool			(*suppress)(struct fib_rule *,
					    struct fib_lookup_arg *);
52 53 54 55 56 57
	int			(*match)(struct fib_rule *,
					 struct flowi *, int);
	int			(*configure)(struct fib_rule *,
					     struct sk_buff *,
					     struct fib_rule_hdr *,
					     struct nlattr **);
58
	void			(*delete)(struct fib_rule *);
59 60 61 62 63
	int			(*compare)(struct fib_rule *,
					   struct fib_rule_hdr *,
					   struct nlattr **);
	int			(*fill)(struct fib_rule *, struct sk_buff *,
					struct fib_rule_hdr *);
64
	u32			(*default_pref)(struct fib_rules_ops *ops);
65
	size_t			(*nlmsg_payload)(struct fib_rule *);
66

67 68
	/* Called after modifications to the rules set, must flush
	 * the route cache if one exists. */
69
	void			(*flush_cache)(struct fib_rules_ops *ops);
70

71
	int			nlgroup;
72
	const struct nla_policy	*policy;
73
	struct list_head	rules_list;
74
	struct module		*owner;
75
	struct net		*fro_net;
76
	struct rcu_head		rcu;
77 78
};

79
#define FRA_GENERIC_POLICY \
80
	[FRA_IIFNAME]	= { .type = NLA_STRING, .len = IFNAMSIZ - 1 }, \
81
	[FRA_OIFNAME]	= { .type = NLA_STRING, .len = IFNAMSIZ - 1 }, \
82 83 84
	[FRA_PRIORITY]	= { .type = NLA_U32 }, \
	[FRA_FWMARK]	= { .type = NLA_U32 }, \
	[FRA_FWMASK]	= { .type = NLA_U32 }, \
T
Thomas Graf 已提交
85
	[FRA_TABLE]     = { .type = NLA_U32 }, \
86
	[FRA_TABLE_PREFIXLEN_MIN] = { .type = NLA_U8 }, \
T
Thomas Graf 已提交
87
	[FRA_GOTO]	= { .type = NLA_U32 }
88

89 90 91 92 93 94 95 96
static inline void fib_rule_get(struct fib_rule *rule)
{
	atomic_inc(&rule->refcnt);
}

static inline void fib_rule_put_rcu(struct rcu_head *head)
{
	struct fib_rule *rule = container_of(head, struct fib_rule, rcu);
97
	release_net(rule->fr_net);
98 99 100 101 102 103 104 105 106
	kfree(rule);
}

static inline void fib_rule_put(struct fib_rule *rule)
{
	if (atomic_dec_and_test(&rule->refcnt))
		call_rcu(&rule->rcu, fib_rule_put_rcu);
}

107 108 109 110 111 112 113
static inline u32 frh_get_table(struct fib_rule_hdr *frh, struct nlattr **nla)
{
	if (nla[FRA_TABLE])
		return nla_get_u32(nla[FRA_TABLE]);
	return frh->table;
}

114
extern struct fib_rules_ops *fib_rules_register(const struct fib_rules_ops *, struct net *);
D
Denis V. Lunev 已提交
115
extern void fib_rules_unregister(struct fib_rules_ops *);
116 117 118 119

extern int			fib_rules_lookup(struct fib_rules_ops *,
						 struct flowi *, int flags,
						 struct fib_lookup_arg *);
120 121 122
extern int			fib_default_rule_add(struct fib_rules_ops *,
						     u32 pref, u32 table,
						     u32 flags);
123
extern u32			fib_default_rule_pref(struct fib_rules_ops *ops);
124
#endif