]> bbs.cooldavid.org Git - net-next-2.6.git/blame - include/net/fib_rules.h
[NET] rules: Use rtnl registration interface
[net-next-2.6.git] / include / net / fib_rules.h
CommitLineData
14c0b97d
TG
1#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>
9d9e6a58 8#include <net/rtnetlink.h>
14c0b97d
TG
9
10struct fib_rule
11{
12 struct list_head list;
13 atomic_t refcnt;
14 int ifindex;
15 char ifname[IFNAMSIZ];
b8964ed9
TG
16 u32 mark;
17 u32 mark_mask;
14c0b97d
TG
18 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;
e1701c68 37 int addr_size;
14c0b97d
TG
38
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);
339bf98f 56 size_t (*nlmsg_payload)(struct fib_rule *);
14c0b97d
TG
57
58 int nlgroup;
59 struct nla_policy *policy;
60 struct list_head *rules_list;
61 struct module *owner;
62};
63
1f6c9557
TG
64#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
14c0b97d
TG
71static 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
9e762a4a
PM
88static 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
14c0b97d
TG
95extern 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
14c0b97d
TG
102extern int fib_rules_dump(struct sk_buff *,
103 struct netlink_callback *, int);
104#endif