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>
8 #include <net/netlink.h>
12 struct list_head list;
15 char ifname[IFNAMSIZ];
29 struct fib_rule *rule;
35 struct list_head list;
38 int (*action)(struct fib_rule *,
40 struct fib_lookup_arg *);
41 int (*match)(struct fib_rule *,
43 int (*configure)(struct fib_rule *,
46 struct fib_rule_hdr *,
48 int (*compare)(struct fib_rule *,
49 struct fib_rule_hdr *,
51 int (*fill)(struct fib_rule *, struct sk_buff *,
53 struct fib_rule_hdr *);
54 u32 (*default_pref)(void);
55 size_t (*nlmsg_payload)(struct fib_rule *);
58 struct nla_policy *policy;
59 struct list_head *rules_list;
63 #define FRA_GENERIC_POLICY \
64 [FRA_IFNAME] = { .type = NLA_STRING, .len = IFNAMSIZ - 1 }, \
65 [FRA_PRIORITY] = { .type = NLA_U32 }, \
66 [FRA_FWMARK] = { .type = NLA_U32 }, \
67 [FRA_FWMASK] = { .type = NLA_U32 }, \
68 [FRA_TABLE] = { .type = NLA_U32 }
70 static inline void fib_rule_get(struct fib_rule *rule)
72 atomic_inc(&rule->refcnt);
75 static inline void fib_rule_put_rcu(struct rcu_head *head)
77 struct fib_rule *rule = container_of(head, struct fib_rule, rcu);
81 static inline void fib_rule_put(struct fib_rule *rule)
83 if (atomic_dec_and_test(&rule->refcnt))
84 call_rcu(&rule->rcu, fib_rule_put_rcu);
87 static inline u32 frh_get_table(struct fib_rule_hdr *frh, struct nlattr **nla)
90 return nla_get_u32(nla[FRA_TABLE]);
94 extern int fib_rules_register(struct fib_rules_ops *);
95 extern int fib_rules_unregister(struct fib_rules_ops *);
97 extern int fib_rules_lookup(struct fib_rules_ops *,
98 struct flowi *, int flags,
99 struct fib_lookup_arg *);
101 extern int fib_nl_newrule(struct sk_buff *,
102 struct nlmsghdr *, void *);
103 extern int fib_nl_delrule(struct sk_buff *,
104 struct nlmsghdr *, void *);
105 extern int fib_rules_dump(struct sk_buff *,
106 struct netlink_callback *, int);