1 #ifndef __NET_FIB_RULES_H
2 #define __NET_FIB_RULES_H
4 #include <linux/types.h>
5 #include <linux/slab.h>
6 #include <linux/netdevice.h>
7 #include <linux/fib_rules.h>
8 #include <linux/refcount.h>
10 #include <net/rtnetlink.h>
11 #include <net/fib_notifier.h>
13 struct fib_kuid_range {
19 struct list_head list;
28 /* 2 bytes hole, try to use */
31 struct fib_rule __rcu *ctarget;
37 int suppress_prefixlen;
38 char iifname[IFNAMSIZ];
39 char oifname[IFNAMSIZ];
40 struct fib_kuid_range uid_range;
44 struct fib_lookup_arg {
47 struct fib_rule *rule;
50 #define FIB_LOOKUP_NOREF 1
51 #define FIB_LOOKUP_IGNORE_LINKSTATE 2
54 struct fib_rules_ops {
56 struct list_head list;
61 unsigned int fib_rules_seq;
63 int (*action)(struct fib_rule *,
65 struct fib_lookup_arg *);
66 bool (*suppress)(struct fib_rule *,
67 struct fib_lookup_arg *);
68 int (*match)(struct fib_rule *,
70 int (*configure)(struct fib_rule *,
72 struct fib_rule_hdr *,
74 int (*delete)(struct fib_rule *);
75 int (*compare)(struct fib_rule *,
76 struct fib_rule_hdr *,
78 int (*fill)(struct fib_rule *, struct sk_buff *,
79 struct fib_rule_hdr *);
80 size_t (*nlmsg_payload)(struct fib_rule *);
82 /* Called after modifications to the rules set, must flush
83 * the route cache if one exists. */
84 void (*flush_cache)(struct fib_rules_ops *ops);
87 const struct nla_policy *policy;
88 struct list_head rules_list;
94 struct fib_rule_notifier_info {
95 struct fib_notifier_info info; /* must be first */
96 struct fib_rule *rule;
99 #define FRA_GENERIC_POLICY \
100 [FRA_IIFNAME] = { .type = NLA_STRING, .len = IFNAMSIZ - 1 }, \
101 [FRA_OIFNAME] = { .type = NLA_STRING, .len = IFNAMSIZ - 1 }, \
102 [FRA_PRIORITY] = { .type = NLA_U32 }, \
103 [FRA_FWMARK] = { .type = NLA_U32 }, \
104 [FRA_FWMASK] = { .type = NLA_U32 }, \
105 [FRA_TABLE] = { .type = NLA_U32 }, \
106 [FRA_SUPPRESS_PREFIXLEN] = { .type = NLA_U32 }, \
107 [FRA_SUPPRESS_IFGROUP] = { .type = NLA_U32 }, \
108 [FRA_GOTO] = { .type = NLA_U32 }, \
109 [FRA_L3MDEV] = { .type = NLA_U8 }, \
110 [FRA_UID_RANGE] = { .len = sizeof(struct fib_rule_uid_range) }
112 static inline void fib_rule_get(struct fib_rule *rule)
114 refcount_inc(&rule->refcnt);
117 static inline void fib_rule_put(struct fib_rule *rule)
119 if (refcount_dec_and_test(&rule->refcnt))
120 kfree_rcu(rule, rcu);
123 #ifdef CONFIG_NET_L3_MASTER_DEV
124 static inline u32 fib_rule_get_table(struct fib_rule *rule,
125 struct fib_lookup_arg *arg)
127 return rule->l3mdev ? arg->table : rule->table;
130 static inline u32 fib_rule_get_table(struct fib_rule *rule,
131 struct fib_lookup_arg *arg)
137 static inline u32 frh_get_table(struct fib_rule_hdr *frh, struct nlattr **nla)
140 return nla_get_u32(nla[FRA_TABLE]);
144 struct fib_rules_ops *fib_rules_register(const struct fib_rules_ops *,
146 void fib_rules_unregister(struct fib_rules_ops *);
148 int fib_rules_lookup(struct fib_rules_ops *, struct flowi *, int flags,
149 struct fib_lookup_arg *);
150 int fib_default_rule_add(struct fib_rules_ops *, u32 pref, u32 table,
152 bool fib_rule_matchall(const struct fib_rule *rule);
153 int fib_rules_dump(struct net *net, struct notifier_block *nb, int family);
154 unsigned int fib_rules_seq_read(struct net *net, int family);
156 int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr *nlh,
157 struct netlink_ext_ack *extack);
158 int fib_nl_delrule(struct sk_buff *skb, struct nlmsghdr *nlh,
159 struct netlink_ext_ack *extack);