]> bbs.cooldavid.org Git - net-next-2.6.git/blob - include/net/fib_rules.h
68542b565cf75919b22e1c9ea3d873dba4cad951
[net-next-2.6.git] / include / net / fib_rules.h
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>
8 #include <net/netlink.h>
9
10 struct fib_rule
11 {
12         struct list_head        list;
13         atomic_t                refcnt;
14         int                     ifindex;
15         char                    ifname[IFNAMSIZ];
16         u32                     mark;
17         u32                     mark_mask;
18         u32                     pref;
19         u32                     flags;
20         u32                     table;
21         u8                      action;
22         struct rcu_head         rcu;
23 };
24
25 struct fib_lookup_arg
26 {
27         void                    *lookup_ptr;
28         void                    *result;
29         struct fib_rule         *rule;
30 };
31
32 struct fib_rules_ops
33 {
34         int                     family;
35         struct list_head        list;
36         int                     rule_size;
37
38         int                     (*action)(struct fib_rule *,
39                                           struct flowi *, int,
40                                           struct fib_lookup_arg *);
41         int                     (*match)(struct fib_rule *,
42                                          struct flowi *, int);
43         int                     (*configure)(struct fib_rule *,
44                                              struct sk_buff *,
45                                              struct nlmsghdr *,
46                                              struct fib_rule_hdr *,
47                                              struct nlattr **);
48         int                     (*compare)(struct fib_rule *,
49                                            struct fib_rule_hdr *,
50                                            struct nlattr **);
51         int                     (*fill)(struct fib_rule *, struct sk_buff *,
52                                         struct nlmsghdr *,
53                                         struct fib_rule_hdr *);
54         u32                     (*default_pref)(void);
55
56         int                     nlgroup;
57         struct nla_policy       *policy;
58         struct list_head        *rules_list;
59         struct module           *owner;
60 };
61
62 static inline void fib_rule_get(struct fib_rule *rule)
63 {
64         atomic_inc(&rule->refcnt);
65 }
66
67 static inline void fib_rule_put_rcu(struct rcu_head *head)
68 {
69         struct fib_rule *rule = container_of(head, struct fib_rule, rcu);
70         kfree(rule);
71 }
72
73 static inline void fib_rule_put(struct fib_rule *rule)
74 {
75         if (atomic_dec_and_test(&rule->refcnt))
76                 call_rcu(&rule->rcu, fib_rule_put_rcu);
77 }
78
79 static inline u32 frh_get_table(struct fib_rule_hdr *frh, struct nlattr **nla)
80 {
81         if (nla[FRA_TABLE])
82                 return nla_get_u32(nla[FRA_TABLE]);
83         return frh->table;
84 }
85
86 extern int                      fib_rules_register(struct fib_rules_ops *);
87 extern int                      fib_rules_unregister(struct fib_rules_ops *);
88
89 extern int                      fib_rules_lookup(struct fib_rules_ops *,
90                                                  struct flowi *, int flags,
91                                                  struct fib_lookup_arg *);
92
93 extern int                      fib_nl_newrule(struct sk_buff *,
94                                                struct nlmsghdr *, void *);
95 extern int                      fib_nl_delrule(struct sk_buff *,
96                                                struct nlmsghdr *, void *);
97 extern int                      fib_rules_dump(struct sk_buff *,
98                                                struct netlink_callback *, int);
99 #endif