Linux 2.6.21-rc6
[firewire-audio.git] / include / net / fib_rules.h
blobd585ea9fa97d3887435e064922f5e65a62748851
1 #ifndef __NET_FIB_RULES_H
2 #define __NET_FIB_RULES_H
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>
10 struct fib_rule
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;
25 struct fib_lookup_arg
27 void *lookup_ptr;
28 void *result;
29 struct fib_rule *rule;
32 struct fib_rules_ops
34 int family;
35 struct list_head list;
36 int rule_size;
37 int addr_size;
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);
56 size_t (*nlmsg_payload)(struct fib_rule *);
58 int nlgroup;
59 struct nla_policy *policy;
60 struct list_head *rules_list;
61 struct module *owner;
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 }
71 static inline void fib_rule_get(struct fib_rule *rule)
73 atomic_inc(&rule->refcnt);
76 static inline void fib_rule_put_rcu(struct rcu_head *head)
78 struct fib_rule *rule = container_of(head, struct fib_rule, rcu);
79 kfree(rule);
82 static inline void fib_rule_put(struct fib_rule *rule)
84 if (atomic_dec_and_test(&rule->refcnt))
85 call_rcu(&rule->rcu, fib_rule_put_rcu);
88 static inline u32 frh_get_table(struct fib_rule_hdr *frh, struct nlattr **nla)
90 if (nla[FRA_TABLE])
91 return nla_get_u32(nla[FRA_TABLE]);
92 return frh->table;
95 extern int fib_rules_register(struct fib_rules_ops *);
96 extern int fib_rules_unregister(struct fib_rules_ops *);
98 extern int fib_rules_lookup(struct fib_rules_ops *,
99 struct flowi *, int flags,
100 struct fib_lookup_arg *);
102 extern int fib_nl_newrule(struct sk_buff *,
103 struct nlmsghdr *, void *);
104 extern int fib_nl_delrule(struct sk_buff *,
105 struct nlmsghdr *, void *);
106 extern int fib_rules_dump(struct sk_buff *,
107 struct netlink_callback *, int);
108 #endif