blob: d585ea9fa97d3887435e064922f5e65a62748851 [file] [log] [blame]
Thomas Graf14c0b972006-08-04 03:38:38 -07001#ifndef __NET_FIB_RULES_H
2#define __NET_FIB_RULES_H
3
4#include <linux/types.h>
5#include <linux/netdevice.h>
6#include <linux/fib_rules.h>
7#include <net/flow.h>
8#include <net/netlink.h>
9
10struct fib_rule
11{
12 struct list_head list;
13 atomic_t refcnt;
14 int ifindex;
15 char ifname[IFNAMSIZ];
Thomas Grafb8964ed2006-11-09 15:22:18 -080016 u32 mark;
17 u32 mark_mask;
Thomas Graf14c0b972006-08-04 03:38:38 -070018 u32 pref;
19 u32 flags;
20 u32 table;
21 u8 action;
22 struct rcu_head rcu;
23};
24
25struct fib_lookup_arg
26{
27 void *lookup_ptr;
28 void *result;
29 struct fib_rule *rule;
30};
31
32struct fib_rules_ops
33{
34 int family;
35 struct list_head list;
36 int rule_size;
Thomas Grafe1701c62007-03-24 12:46:02 -070037 int addr_size;
Thomas Graf14c0b972006-08-04 03:38:38 -070038
39 int (*action)(struct fib_rule *,
40 struct flowi *, int,
41 struct fib_lookup_arg *);
42 int (*match)(struct fib_rule *,
43 struct flowi *, int);
44 int (*configure)(struct fib_rule *,
45 struct sk_buff *,
46 struct nlmsghdr *,
47 struct fib_rule_hdr *,
48 struct nlattr **);
49 int (*compare)(struct fib_rule *,
50 struct fib_rule_hdr *,
51 struct nlattr **);
52 int (*fill)(struct fib_rule *, struct sk_buff *,
53 struct nlmsghdr *,
54 struct fib_rule_hdr *);
55 u32 (*default_pref)(void);
Thomas Graf339bf982006-11-10 14:10:15 -080056 size_t (*nlmsg_payload)(struct fib_rule *);
Thomas Graf14c0b972006-08-04 03:38:38 -070057
58 int nlgroup;
59 struct nla_policy *policy;
60 struct list_head *rules_list;
61 struct module *owner;
62};
63
Thomas Graf1f6c9552006-11-09 15:22:48 -080064#define FRA_GENERIC_POLICY \
65 [FRA_IFNAME] = { .type = NLA_STRING, .len = IFNAMSIZ - 1 }, \
66 [FRA_PRIORITY] = { .type = NLA_U32 }, \
67 [FRA_FWMARK] = { .type = NLA_U32 }, \
68 [FRA_FWMASK] = { .type = NLA_U32 }, \
69 [FRA_TABLE] = { .type = NLA_U32 }
70
Thomas Graf14c0b972006-08-04 03:38:38 -070071static inline void fib_rule_get(struct fib_rule *rule)
72{
73 atomic_inc(&rule->refcnt);
74}
75
76static inline void fib_rule_put_rcu(struct rcu_head *head)
77{
78 struct fib_rule *rule = container_of(head, struct fib_rule, rcu);
79 kfree(rule);
80}
81
82static inline void fib_rule_put(struct fib_rule *rule)
83{
84 if (atomic_dec_and_test(&rule->refcnt))
85 call_rcu(&rule->rcu, fib_rule_put_rcu);
86}
87
Patrick McHardy9e762a42006-08-10 23:09:48 -070088static inline u32 frh_get_table(struct fib_rule_hdr *frh, struct nlattr **nla)
89{
90 if (nla[FRA_TABLE])
91 return nla_get_u32(nla[FRA_TABLE]);
92 return frh->table;
93}
94
Thomas Graf14c0b972006-08-04 03:38:38 -070095extern int fib_rules_register(struct fib_rules_ops *);
96extern int fib_rules_unregister(struct fib_rules_ops *);
97
98extern int fib_rules_lookup(struct fib_rules_ops *,
99 struct flowi *, int flags,
100 struct fib_lookup_arg *);
101
102extern int fib_nl_newrule(struct sk_buff *,
103 struct nlmsghdr *, void *);
104extern int fib_nl_delrule(struct sk_buff *,
105 struct nlmsghdr *, void *);
106extern int fib_rules_dump(struct sk_buff *,
107 struct netlink_callback *, int);
108#endif