.. | .. |
---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-or-later */ |
---|
1 | 2 | /* |
---|
2 | 3 | * INET An implementation of the TCP/IP protocol suite for the LINUX |
---|
3 | 4 | * operating system. INET is implemented using the BSD Socket |
---|
.. | .. |
---|
6 | 7 | * Definitions for the Forwarding Information Base. |
---|
7 | 8 | * |
---|
8 | 9 | * Authors: A.N.Kuznetsov, <kuznet@ms2.inr.ac.ru> |
---|
9 | | - * |
---|
10 | | - * This program is free software; you can redistribute it and/or |
---|
11 | | - * modify it under the terms of the GNU General Public License |
---|
12 | | - * as published by the Free Software Foundation; either version |
---|
13 | | - * 2 of the License, or (at your option) any later version. |
---|
14 | 10 | */ |
---|
15 | 11 | |
---|
16 | 12 | #ifndef _NET_IP_FIB_H |
---|
.. | .. |
---|
32 | 28 | u8 fc_protocol; |
---|
33 | 29 | u8 fc_scope; |
---|
34 | 30 | u8 fc_type; |
---|
35 | | - /* 3 bytes unused */ |
---|
| 31 | + u8 fc_gw_family; |
---|
| 32 | + /* 2 bytes unused */ |
---|
36 | 33 | u32 fc_table; |
---|
37 | 34 | __be32 fc_dst; |
---|
38 | | - __be32 fc_gw; |
---|
| 35 | + union { |
---|
| 36 | + __be32 fc_gw4; |
---|
| 37 | + struct in6_addr fc_gw6; |
---|
| 38 | + }; |
---|
39 | 39 | int fc_oif; |
---|
40 | 40 | u32 fc_flags; |
---|
41 | 41 | u32 fc_priority; |
---|
42 | 42 | __be32 fc_prefsrc; |
---|
| 43 | + u32 fc_nh_id; |
---|
43 | 44 | struct nlattr *fc_mx; |
---|
44 | 45 | struct rtnexthop *fc_mp; |
---|
45 | 46 | int fc_mx_len; |
---|
.. | .. |
---|
76 | 77 | #define FNHE_HASH_SIZE (1 << FNHE_HASH_SHIFT) |
---|
77 | 78 | #define FNHE_RECLAIM_DEPTH 5 |
---|
78 | 79 | |
---|
| 80 | +struct fib_nh_common { |
---|
| 81 | + struct net_device *nhc_dev; |
---|
| 82 | + int nhc_oif; |
---|
| 83 | + unsigned char nhc_scope; |
---|
| 84 | + u8 nhc_family; |
---|
| 85 | + u8 nhc_gw_family; |
---|
| 86 | + unsigned char nhc_flags; |
---|
| 87 | + struct lwtunnel_state *nhc_lwtstate; |
---|
| 88 | + |
---|
| 89 | + union { |
---|
| 90 | + __be32 ipv4; |
---|
| 91 | + struct in6_addr ipv6; |
---|
| 92 | + } nhc_gw; |
---|
| 93 | + |
---|
| 94 | + int nhc_weight; |
---|
| 95 | + atomic_t nhc_upper_bound; |
---|
| 96 | + |
---|
| 97 | + /* v4 specific, but allows fib6_nh with v4 routes */ |
---|
| 98 | + struct rtable __rcu * __percpu *nhc_pcpu_rth_output; |
---|
| 99 | + struct rtable __rcu *nhc_rth_input; |
---|
| 100 | + struct fnhe_hash_bucket __rcu *nhc_exceptions; |
---|
| 101 | +}; |
---|
| 102 | + |
---|
79 | 103 | struct fib_nh { |
---|
80 | | - struct net_device *nh_dev; |
---|
| 104 | + struct fib_nh_common nh_common; |
---|
81 | 105 | struct hlist_node nh_hash; |
---|
82 | 106 | struct fib_info *nh_parent; |
---|
83 | | - unsigned int nh_flags; |
---|
84 | | - unsigned char nh_scope; |
---|
85 | | -#ifdef CONFIG_IP_ROUTE_MULTIPATH |
---|
86 | | - int nh_weight; |
---|
87 | | - atomic_t nh_upper_bound; |
---|
88 | | -#endif |
---|
89 | 107 | #ifdef CONFIG_IP_ROUTE_CLASSID |
---|
90 | 108 | __u32 nh_tclassid; |
---|
91 | 109 | #endif |
---|
92 | | - int nh_oif; |
---|
93 | | - __be32 nh_gw; |
---|
94 | 110 | __be32 nh_saddr; |
---|
95 | 111 | int nh_saddr_genid; |
---|
96 | | - struct rtable __rcu * __percpu *nh_pcpu_rth_output; |
---|
97 | | - struct rtable __rcu *nh_rth_input; |
---|
98 | | - struct fnhe_hash_bucket __rcu *nh_exceptions; |
---|
99 | | - struct lwtunnel_state *nh_lwtstate; |
---|
| 112 | +#define fib_nh_family nh_common.nhc_family |
---|
| 113 | +#define fib_nh_dev nh_common.nhc_dev |
---|
| 114 | +#define fib_nh_oif nh_common.nhc_oif |
---|
| 115 | +#define fib_nh_flags nh_common.nhc_flags |
---|
| 116 | +#define fib_nh_lws nh_common.nhc_lwtstate |
---|
| 117 | +#define fib_nh_scope nh_common.nhc_scope |
---|
| 118 | +#define fib_nh_gw_family nh_common.nhc_gw_family |
---|
| 119 | +#define fib_nh_gw4 nh_common.nhc_gw.ipv4 |
---|
| 120 | +#define fib_nh_gw6 nh_common.nhc_gw.ipv6 |
---|
| 121 | +#define fib_nh_weight nh_common.nhc_weight |
---|
| 122 | +#define fib_nh_upper_bound nh_common.nhc_upper_bound |
---|
100 | 123 | }; |
---|
101 | 124 | |
---|
102 | 125 | /* |
---|
103 | 126 | * This structure contains data shared by many of routes. |
---|
104 | 127 | */ |
---|
105 | 128 | |
---|
| 129 | +struct nexthop; |
---|
| 130 | + |
---|
106 | 131 | struct fib_info { |
---|
107 | 132 | struct hlist_node fib_hash; |
---|
108 | 133 | struct hlist_node fib_lhash; |
---|
| 134 | + struct list_head nh_list; |
---|
109 | 135 | struct net *fib_net; |
---|
110 | 136 | int fib_treeref; |
---|
111 | 137 | refcount_t fib_clntref; |
---|
.. | .. |
---|
123 | 149 | #define fib_rtt fib_metrics->metrics[RTAX_RTT-1] |
---|
124 | 150 | #define fib_advmss fib_metrics->metrics[RTAX_ADVMSS-1] |
---|
125 | 151 | int fib_nhs; |
---|
| 152 | + bool fib_nh_is_v6; |
---|
| 153 | + bool nh_updated; |
---|
| 154 | + struct nexthop *nh; |
---|
126 | 155 | struct rcu_head rcu; |
---|
127 | | - struct fib_nh fib_nh[0]; |
---|
128 | | -#define fib_dev fib_nh[0].nh_dev |
---|
| 156 | + struct fib_nh fib_nh[]; |
---|
129 | 157 | }; |
---|
130 | 158 | |
---|
131 | 159 | |
---|
.. | .. |
---|
135 | 163 | |
---|
136 | 164 | struct fib_table; |
---|
137 | 165 | struct fib_result { |
---|
138 | | - __be32 prefix; |
---|
139 | | - unsigned char prefixlen; |
---|
140 | | - unsigned char nh_sel; |
---|
141 | | - unsigned char type; |
---|
142 | | - unsigned char scope; |
---|
143 | | - u32 tclassid; |
---|
144 | | - struct fib_info *fi; |
---|
145 | | - struct fib_table *table; |
---|
146 | | - struct hlist_head *fa_head; |
---|
| 166 | + __be32 prefix; |
---|
| 167 | + unsigned char prefixlen; |
---|
| 168 | + unsigned char nh_sel; |
---|
| 169 | + unsigned char type; |
---|
| 170 | + unsigned char scope; |
---|
| 171 | + u32 tclassid; |
---|
| 172 | + struct fib_nh_common *nhc; |
---|
| 173 | + struct fib_info *fi; |
---|
| 174 | + struct fib_table *table; |
---|
| 175 | + struct hlist_head *fa_head; |
---|
147 | 176 | }; |
---|
148 | 177 | |
---|
149 | 178 | struct fib_result_nl { |
---|
.. | .. |
---|
161 | 190 | int err; |
---|
162 | 191 | }; |
---|
163 | 192 | |
---|
164 | | -#ifdef CONFIG_IP_ROUTE_MULTIPATH |
---|
165 | | -#define FIB_RES_NH(res) ((res).fi->fib_nh[(res).nh_sel]) |
---|
166 | | -#else /* CONFIG_IP_ROUTE_MULTIPATH */ |
---|
167 | | -#define FIB_RES_NH(res) ((res).fi->fib_nh[0]) |
---|
168 | | -#endif /* CONFIG_IP_ROUTE_MULTIPATH */ |
---|
169 | | - |
---|
170 | 193 | #ifdef CONFIG_IP_MULTIPLE_TABLES |
---|
171 | 194 | #define FIB_TABLE_HASHSZ 256 |
---|
172 | 195 | #else |
---|
173 | 196 | #define FIB_TABLE_HASHSZ 2 |
---|
174 | 197 | #endif |
---|
175 | 198 | |
---|
176 | | -__be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh); |
---|
| 199 | +__be32 fib_info_update_nhc_saddr(struct net *net, struct fib_nh_common *nhc, |
---|
| 200 | + unsigned char scope); |
---|
| 201 | +__be32 fib_result_prefsrc(struct net *net, struct fib_result *res); |
---|
177 | 202 | |
---|
178 | | -#define FIB_RES_SADDR(net, res) \ |
---|
179 | | - ((FIB_RES_NH(res).nh_saddr_genid == \ |
---|
180 | | - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \ |
---|
181 | | - FIB_RES_NH(res).nh_saddr : \ |
---|
182 | | - fib_info_update_nh_saddr((net), &FIB_RES_NH(res))) |
---|
183 | | -#define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw) |
---|
184 | | -#define FIB_RES_DEV(res) (FIB_RES_NH(res).nh_dev) |
---|
185 | | -#define FIB_RES_OIF(res) (FIB_RES_NH(res).nh_oif) |
---|
| 203 | +#define FIB_RES_NHC(res) ((res).nhc) |
---|
| 204 | +#define FIB_RES_DEV(res) (FIB_RES_NHC(res)->nhc_dev) |
---|
| 205 | +#define FIB_RES_OIF(res) (FIB_RES_NHC(res)->nhc_oif) |
---|
186 | 206 | |
---|
187 | | -#define FIB_RES_PREFSRC(net, res) ((res).fi->fib_prefsrc ? : \ |
---|
188 | | - FIB_RES_SADDR(net, res)) |
---|
| 207 | +struct fib_rt_info { |
---|
| 208 | + struct fib_info *fi; |
---|
| 209 | + u32 tb_id; |
---|
| 210 | + __be32 dst; |
---|
| 211 | + int dst_len; |
---|
| 212 | + u8 tos; |
---|
| 213 | + u8 type; |
---|
| 214 | + u8 offload:1, |
---|
| 215 | + trap:1, |
---|
| 216 | + unused:6; |
---|
| 217 | +}; |
---|
189 | 218 | |
---|
190 | 219 | struct fib_entry_notifier_info { |
---|
191 | 220 | struct fib_notifier_info info; /* must be first */ |
---|
.. | .. |
---|
202 | 231 | struct fib_nh *fib_nh; |
---|
203 | 232 | }; |
---|
204 | 233 | |
---|
205 | | -int call_fib4_notifier(struct notifier_block *nb, struct net *net, |
---|
| 234 | +int call_fib4_notifier(struct notifier_block *nb, |
---|
206 | 235 | enum fib_event_type event_type, |
---|
207 | 236 | struct fib_notifier_info *info); |
---|
208 | 237 | int call_fib4_notifiers(struct net *net, enum fib_event_type event_type, |
---|
.. | .. |
---|
211 | 240 | int __net_init fib4_notifier_init(struct net *net); |
---|
212 | 241 | void __net_exit fib4_notifier_exit(struct net *net); |
---|
213 | 242 | |
---|
214 | | -void fib_notify(struct net *net, struct notifier_block *nb); |
---|
| 243 | +void fib_info_notify_update(struct net *net, struct nl_info *info); |
---|
| 244 | +int fib_notify(struct net *net, struct notifier_block *nb, |
---|
| 245 | + struct netlink_ext_ack *extack); |
---|
215 | 246 | |
---|
216 | 247 | struct fib_table { |
---|
217 | 248 | struct hlist_node tb_hlist; |
---|
.. | .. |
---|
219 | 250 | int tb_num_default; |
---|
220 | 251 | struct rcu_head rcu; |
---|
221 | 252 | unsigned long *tb_data; |
---|
222 | | - unsigned long __data[0]; |
---|
| 253 | + unsigned long __data[]; |
---|
| 254 | +}; |
---|
| 255 | + |
---|
| 256 | +struct fib_dump_filter { |
---|
| 257 | + u32 table_id; |
---|
| 258 | + /* filter_set is an optimization that an entry is set */ |
---|
| 259 | + bool filter_set; |
---|
| 260 | + bool dump_routes; |
---|
| 261 | + bool dump_exceptions; |
---|
| 262 | + unsigned char protocol; |
---|
| 263 | + unsigned char rt_type; |
---|
| 264 | + unsigned int flags; |
---|
| 265 | + struct net_device *dev; |
---|
223 | 266 | }; |
---|
224 | 267 | |
---|
225 | 268 | int fib_table_lookup(struct fib_table *tb, const struct flowi4 *flp, |
---|
.. | .. |
---|
229 | 272 | int fib_table_delete(struct net *, struct fib_table *, struct fib_config *, |
---|
230 | 273 | struct netlink_ext_ack *extack); |
---|
231 | 274 | int fib_table_dump(struct fib_table *table, struct sk_buff *skb, |
---|
232 | | - struct netlink_callback *cb); |
---|
| 275 | + struct netlink_callback *cb, struct fib_dump_filter *filter); |
---|
233 | 276 | int fib_table_flush(struct net *net, struct fib_table *table, bool flush_all); |
---|
234 | 277 | struct fib_table *fib_trie_unmerge(struct fib_table *main_tb); |
---|
235 | 278 | void fib_table_flush_external(struct fib_table *table); |
---|
.. | .. |
---|
279 | 322 | return err; |
---|
280 | 323 | } |
---|
281 | 324 | |
---|
| 325 | +static inline bool fib4_has_custom_rules(const struct net *net) |
---|
| 326 | +{ |
---|
| 327 | + return false; |
---|
| 328 | +} |
---|
| 329 | + |
---|
282 | 330 | static inline bool fib4_rule_default(const struct fib_rule *rule) |
---|
283 | 331 | { |
---|
284 | 332 | return true; |
---|
285 | 333 | } |
---|
286 | 334 | |
---|
287 | | -static inline int fib4_rules_dump(struct net *net, struct notifier_block *nb) |
---|
| 335 | +static inline int fib4_rules_dump(struct net *net, struct notifier_block *nb, |
---|
| 336 | + struct netlink_ext_ack *extack) |
---|
288 | 337 | { |
---|
289 | 338 | return 0; |
---|
290 | 339 | } |
---|
.. | .. |
---|
345 | 394 | return err; |
---|
346 | 395 | } |
---|
347 | 396 | |
---|
| 397 | +static inline bool fib4_has_custom_rules(const struct net *net) |
---|
| 398 | +{ |
---|
| 399 | + return net->ipv4.fib_has_custom_rules; |
---|
| 400 | +} |
---|
| 401 | + |
---|
348 | 402 | bool fib4_rule_default(const struct fib_rule *rule); |
---|
349 | | -int fib4_rules_dump(struct net *net, struct notifier_block *nb); |
---|
| 403 | +int fib4_rules_dump(struct net *net, struct notifier_block *nb, |
---|
| 404 | + struct netlink_ext_ack *extack); |
---|
350 | 405 | unsigned int fib4_rules_seq_read(struct net *net); |
---|
351 | 406 | |
---|
352 | 407 | static inline bool fib4_rules_early_flow_dissect(struct net *net, |
---|
.. | .. |
---|
372 | 427 | /* Exported by fib_frontend.c */ |
---|
373 | 428 | extern const struct nla_policy rtm_ipv4_policy[]; |
---|
374 | 429 | void ip_fib_init(void); |
---|
| 430 | +int fib_gw_from_via(struct fib_config *cfg, struct nlattr *nla, |
---|
| 431 | + struct netlink_ext_ack *extack); |
---|
375 | 432 | __be32 fib_compute_spec_dst(struct sk_buff *skb); |
---|
| 433 | +bool fib_info_nh_uses_dev(struct fib_info *fi, const struct net_device *dev); |
---|
376 | 434 | int fib_validate_source(struct sk_buff *skb, __be32 src, __be32 dst, |
---|
377 | 435 | u8 tos, int oif, struct net_device *dev, |
---|
378 | 436 | struct in_device *idev, u32 *itag); |
---|
379 | 437 | #ifdef CONFIG_IP_ROUTE_CLASSID |
---|
380 | 438 | static inline int fib_num_tclassid_users(struct net *net) |
---|
381 | 439 | { |
---|
382 | | - return net->ipv4.fib_num_tclassid_users; |
---|
| 440 | + return atomic_read(&net->ipv4.fib_num_tclassid_users); |
---|
383 | 441 | } |
---|
384 | 442 | #else |
---|
385 | 443 | static inline int fib_num_tclassid_users(struct net *net) |
---|
.. | .. |
---|
389 | 447 | #endif |
---|
390 | 448 | int fib_unmerge(struct net *net); |
---|
391 | 449 | |
---|
| 450 | +static inline bool nhc_l3mdev_matches_dev(const struct fib_nh_common *nhc, |
---|
| 451 | +const struct net_device *dev) |
---|
| 452 | +{ |
---|
| 453 | + if (nhc->nhc_dev == dev || |
---|
| 454 | + l3mdev_master_ifindex_rcu(nhc->nhc_dev) == dev->ifindex) |
---|
| 455 | + return true; |
---|
| 456 | + |
---|
| 457 | + return false; |
---|
| 458 | +} |
---|
| 459 | + |
---|
392 | 460 | /* Exported by fib_semantics.c */ |
---|
393 | 461 | int ip_fib_check_default(__be32 gw, struct net_device *dev); |
---|
394 | 462 | int fib_sync_down_dev(struct net_device *dev, unsigned long event, bool force); |
---|
395 | 463 | int fib_sync_down_addr(struct net_device *dev, __be32 local); |
---|
396 | | -int fib_sync_up(struct net_device *dev, unsigned int nh_flags); |
---|
| 464 | +int fib_sync_up(struct net_device *dev, unsigned char nh_flags); |
---|
397 | 465 | void fib_sync_mtu(struct net_device *dev, u32 orig_mtu); |
---|
| 466 | +void fib_nhc_update_mtu(struct fib_nh_common *nhc, u32 new, u32 orig); |
---|
398 | 467 | |
---|
399 | 468 | #ifdef CONFIG_IP_ROUTE_MULTIPATH |
---|
400 | 469 | int fib_multipath_hash(const struct net *net, const struct flowi4 *fl4, |
---|
401 | 470 | const struct sk_buff *skb, struct flow_keys *flkeys); |
---|
402 | 471 | #endif |
---|
| 472 | +int fib_check_nh(struct net *net, struct fib_nh *nh, u32 table, u8 scope, |
---|
| 473 | + struct netlink_ext_ack *extack); |
---|
403 | 474 | void fib_select_multipath(struct fib_result *res, int hash); |
---|
404 | 475 | void fib_select_path(struct net *net, struct fib_result *res, |
---|
405 | 476 | struct flowi4 *fl4, const struct sk_buff *skb); |
---|
406 | 477 | |
---|
| 478 | +int fib_nh_init(struct net *net, struct fib_nh *fib_nh, |
---|
| 479 | + struct fib_config *cfg, int nh_weight, |
---|
| 480 | + struct netlink_ext_ack *extack); |
---|
| 481 | +void fib_nh_release(struct net *net, struct fib_nh *fib_nh); |
---|
| 482 | +int fib_nh_common_init(struct net *net, struct fib_nh_common *nhc, |
---|
| 483 | + struct nlattr *fc_encap, u16 fc_encap_type, |
---|
| 484 | + void *cfg, gfp_t gfp_flags, |
---|
| 485 | + struct netlink_ext_ack *extack); |
---|
| 486 | +void fib_nh_common_release(struct fib_nh_common *nhc); |
---|
| 487 | + |
---|
407 | 488 | /* Exported by fib_trie.c */ |
---|
| 489 | +void fib_alias_hw_flags_set(struct net *net, const struct fib_rt_info *fri); |
---|
408 | 490 | void fib_trie_init(void); |
---|
409 | 491 | struct fib_table *fib_trie_table(u32 id, struct fib_table *alias); |
---|
| 492 | +bool fib_lookup_good_nhc(const struct fib_nh_common *nhc, int fib_flags, |
---|
| 493 | + const struct flowi4 *flp); |
---|
410 | 494 | |
---|
411 | 495 | static inline void fib_combine_itag(u32 *itag, const struct fib_result *res) |
---|
412 | 496 | { |
---|
413 | 497 | #ifdef CONFIG_IP_ROUTE_CLASSID |
---|
| 498 | + struct fib_nh_common *nhc = res->nhc; |
---|
414 | 499 | #ifdef CONFIG_IP_MULTIPLE_TABLES |
---|
415 | 500 | u32 rtag; |
---|
416 | 501 | #endif |
---|
417 | | - *itag = FIB_RES_NH(*res).nh_tclassid<<16; |
---|
| 502 | + if (nhc->nhc_family == AF_INET) { |
---|
| 503 | + struct fib_nh *nh; |
---|
| 504 | + |
---|
| 505 | + nh = container_of(nhc, struct fib_nh, nh_common); |
---|
| 506 | + *itag = nh->nh_tclassid << 16; |
---|
| 507 | + } else { |
---|
| 508 | + *itag = 0; |
---|
| 509 | + } |
---|
| 510 | + |
---|
418 | 511 | #ifdef CONFIG_IP_MULTIPLE_TABLES |
---|
419 | 512 | rtag = res->tclassid; |
---|
420 | 513 | if (*itag == 0) |
---|
.. | .. |
---|
424 | 517 | #endif |
---|
425 | 518 | } |
---|
426 | 519 | |
---|
| 520 | +void fib_flush(struct net *net); |
---|
427 | 521 | void free_fib_info(struct fib_info *fi); |
---|
428 | 522 | |
---|
429 | 523 | static inline void fib_info_hold(struct fib_info *fi) |
---|
.. | .. |
---|
452 | 546 | |
---|
453 | 547 | u32 ip_mtu_from_fib_result(struct fib_result *res, __be32 daddr); |
---|
454 | 548 | |
---|
| 549 | +int ip_valid_fib_dump_req(struct net *net, const struct nlmsghdr *nlh, |
---|
| 550 | + struct fib_dump_filter *filter, |
---|
| 551 | + struct netlink_callback *cb); |
---|
| 552 | + |
---|
| 553 | +int fib_nexthop_info(struct sk_buff *skb, const struct fib_nh_common *nh, |
---|
| 554 | + u8 rt_family, unsigned char *flags, bool skip_oif); |
---|
| 555 | +int fib_add_nexthop(struct sk_buff *skb, const struct fib_nh_common *nh, |
---|
| 556 | + int nh_weight, u8 rt_family, u32 nh_tclassid); |
---|
455 | 557 | #endif /* _NET_FIB_H */ |
---|