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