Commit | Line | Data |
---|---|---|
14c0b97d TG |
1 | #ifndef __NET_FIB_RULES_H |
2 | #define __NET_FIB_RULES_H | |
3 | ||
4 | #include <linux/types.h> | |
5a0e3ad6 | 5 | #include <linux/slab.h> |
14c0b97d TG |
6 | #include <linux/netdevice.h> |
7 | #include <linux/fib_rules.h> | |
717d1e99 | 8 | #include <linux/refcount.h> |
14c0b97d | 9 | #include <net/flow.h> |
9d9e6a58 | 10 | #include <net/rtnetlink.h> |
1b2a4440 | 11 | #include <net/fib_notifier.h> |
14c0b97d | 12 | |
622ec2c9 LC |
13 | struct fib_kuid_range { |
14 | kuid_t start; | |
15 | kuid_t end; | |
16 | }; | |
17 | ||
fd2c3ef7 | 18 | struct fib_rule { |
14c0b97d | 19 | struct list_head list; |
491deb24 | 20 | int iifindex; |
1b038a5e | 21 | int oifindex; |
b8964ed9 TG |
22 | u32 mark; |
23 | u32 mark_mask; | |
14c0b97d TG |
24 | u32 flags; |
25 | u32 table; | |
26 | u8 action; | |
96c63fa7 DA |
27 | u8 l3mdev; |
28 | /* 2 bytes hole, try to use */ | |
0947c9fe | 29 | u32 target; |
e7030878 | 30 | __be64 tun_id; |
7a2b03c5 | 31 | struct fib_rule __rcu *ctarget; |
fba3679d ED |
32 | struct net *fr_net; |
33 | ||
717d1e99 | 34 | refcount_t refcnt; |
fba3679d ED |
35 | u32 pref; |
36 | int suppress_ifgroup; | |
37 | int suppress_prefixlen; | |
491deb24 | 38 | char iifname[IFNAMSIZ]; |
1b038a5e | 39 | char oifname[IFNAMSIZ]; |
622ec2c9 | 40 | struct fib_kuid_range uid_range; |
14c0b97d TG |
41 | struct rcu_head rcu; |
42 | }; | |
43 | ||
fd2c3ef7 | 44 | struct fib_lookup_arg { |
14c0b97d TG |
45 | void *lookup_ptr; |
46 | void *result; | |
47 | struct fib_rule *rule; | |
96c63fa7 | 48 | u32 table; |
ebc0ffae | 49 | int flags; |
0eeb075f AG |
50 | #define FIB_LOOKUP_NOREF 1 |
51 | #define FIB_LOOKUP_IGNORE_LINKSTATE 2 | |
14c0b97d TG |
52 | }; |
53 | ||
fd2c3ef7 | 54 | struct fib_rules_ops { |
14c0b97d TG |
55 | int family; |
56 | struct list_head list; | |
57 | int rule_size; | |
e1701c68 | 58 | int addr_size; |
0947c9fe TG |
59 | int unresolved_rules; |
60 | int nr_goto_rules; | |
1b2a4440 | 61 | unsigned int fib_rules_seq; |
14c0b97d TG |
62 | |
63 | int (*action)(struct fib_rule *, | |
64 | struct flowi *, int, | |
65 | struct fib_lookup_arg *); | |
7764a45a ST |
66 | bool (*suppress)(struct fib_rule *, |
67 | struct fib_lookup_arg *); | |
14c0b97d TG |
68 | int (*match)(struct fib_rule *, |
69 | struct flowi *, int); | |
70 | int (*configure)(struct fib_rule *, | |
71 | struct sk_buff *, | |
14c0b97d TG |
72 | struct fib_rule_hdr *, |
73 | struct nlattr **); | |
0ddcf43d | 74 | int (*delete)(struct fib_rule *); |
14c0b97d TG |
75 | int (*compare)(struct fib_rule *, |
76 | struct fib_rule_hdr *, | |
77 | struct nlattr **); | |
78 | int (*fill)(struct fib_rule *, struct sk_buff *, | |
14c0b97d | 79 | struct fib_rule_hdr *); |
339bf98f | 80 | size_t (*nlmsg_payload)(struct fib_rule *); |
14c0b97d | 81 | |
73417f61 TG |
82 | /* Called after modifications to the rules set, must flush |
83 | * the route cache if one exists. */ | |
ae299fc0 | 84 | void (*flush_cache)(struct fib_rules_ops *ops); |
73417f61 | 85 | |
14c0b97d | 86 | int nlgroup; |
ef7c79ed | 87 | const struct nla_policy *policy; |
76c72d4f | 88 | struct list_head rules_list; |
14c0b97d | 89 | struct module *owner; |
03592383 | 90 | struct net *fro_net; |
e9c5158a | 91 | struct rcu_head rcu; |
14c0b97d TG |
92 | }; |
93 | ||
1b2a4440 IS |
94 | struct fib_rule_notifier_info { |
95 | struct fib_notifier_info info; /* must be first */ | |
96 | struct fib_rule *rule; | |
97 | }; | |
98 | ||
1f6c9557 | 99 | #define FRA_GENERIC_POLICY \ |
491deb24 | 100 | [FRA_IIFNAME] = { .type = NLA_STRING, .len = IFNAMSIZ - 1 }, \ |
1b038a5e | 101 | [FRA_OIFNAME] = { .type = NLA_STRING, .len = IFNAMSIZ - 1 }, \ |
1f6c9557 TG |
102 | [FRA_PRIORITY] = { .type = NLA_U32 }, \ |
103 | [FRA_FWMARK] = { .type = NLA_U32 }, \ | |
104 | [FRA_FWMASK] = { .type = NLA_U32 }, \ | |
0947c9fe | 105 | [FRA_TABLE] = { .type = NLA_U32 }, \ |
73f5698e | 106 | [FRA_SUPPRESS_PREFIXLEN] = { .type = NLA_U32 }, \ |
6ef94cfa | 107 | [FRA_SUPPRESS_IFGROUP] = { .type = NLA_U32 }, \ |
96c63fa7 | 108 | [FRA_GOTO] = { .type = NLA_U32 }, \ |
622ec2c9 LC |
109 | [FRA_L3MDEV] = { .type = NLA_U8 }, \ |
110 | [FRA_UID_RANGE] = { .len = sizeof(struct fib_rule_uid_range) } | |
1f6c9557 | 111 | |
14c0b97d TG |
112 | static inline void fib_rule_get(struct fib_rule *rule) |
113 | { | |
717d1e99 | 114 | refcount_inc(&rule->refcnt); |
14c0b97d TG |
115 | } |
116 | ||
14c0b97d TG |
117 | static inline void fib_rule_put(struct fib_rule *rule) |
118 | { | |
717d1e99 | 119 | if (refcount_dec_and_test(&rule->refcnt)) |
efd7ef1c | 120 | kfree_rcu(rule, rcu); |
14c0b97d TG |
121 | } |
122 | ||
96c63fa7 DA |
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) | |
126 | { | |
127 | return rule->l3mdev ? arg->table : rule->table; | |
128 | } | |
129 | #else | |
130 | static inline u32 fib_rule_get_table(struct fib_rule *rule, | |
131 | struct fib_lookup_arg *arg) | |
132 | { | |
133 | return rule->table; | |
134 | } | |
135 | #endif | |
136 | ||
9e762a4a PM |
137 | static inline u32 frh_get_table(struct fib_rule_hdr *frh, struct nlattr **nla) |
138 | { | |
139 | if (nla[FRA_TABLE]) | |
140 | return nla_get_u32(nla[FRA_TABLE]); | |
141 | return frh->table; | |
142 | } | |
143 | ||
8de6879f JP |
144 | struct fib_rules_ops *fib_rules_register(const struct fib_rules_ops *, |
145 | struct net *); | |
146 | void fib_rules_unregister(struct fib_rules_ops *); | |
14c0b97d | 147 | |
8de6879f JP |
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, | |
151 | u32 flags); | |
3c71006d | 152 | bool fib_rule_matchall(const struct fib_rule *rule); |
1b2a4440 IS |
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); | |
96c63fa7 | 155 | |
c21ef3e3 DA |
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); | |
14c0b97d | 160 | #endif |