frr/zebra/zebra_ns.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

115 lines
2.9 KiB
C
Raw Normal View History

// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Zebra NS header
* Copyright (C) 2016 Cumulus Networks, Inc.
* Donald Sharp
*/
#if !defined(__ZEBRA_NS_H__)
#define __ZEBRA_NS_H__
#include <lib/ns.h>
#include <lib/vrf.h>
#include "zebra/rib.h"
#include "zebra/zebra_vrf.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifdef HAVE_NETLINK
#include <linux/netlink.h>
/* Socket interface to kernel */
struct nlsock {
int sock;
int seq;
struct sockaddr_nl snl;
char name[64];
uint8_t *buf;
size_t buflen;
};
#endif
/* Tree of interfaces: external linkage struct, and rbtree */
PREDECL_RBTREE_UNIQ(ifp_tree);
struct ifp_tree_link {
struct ifp_tree_item link;
ifindex_t ifindex;
struct interface *ifp;
/* Backpointer */
struct zebra_ns *zns;
};
struct zebra_ns {
/* net-ns name. */
char name[VRF_NAMSIZ];
/* Identifier. */
ns_id_t ns_id;
#ifdef HAVE_NETLINK
struct nlsock netlink; /* kernel messages */
struct nlsock netlink_cmd; /* command channel */
/* dplane system's channels: one for outgoing programming,
* for the FIB e.g., and one for incoming events from the OS.
*/
struct nlsock netlink_dplane_out;
struct nlsock netlink_dplane_in;
struct event *t_netlink;
struct nlsock ge_netlink_cmd; /* command channel for generic netlink */
#endif
/* Tree of interfaces in this ns */
struct ifp_tree_head ifp_tree;
/* Back pointer */
struct ns *ns;
};
struct zebra_ns *zebra_ns_lookup(ns_id_t ns_id);
/* Manage collection of ifps per-NS */
void zebra_ns_link_ifp(struct zebra_ns *zns, struct interface *ifp);
void zebra_ns_unlink_ifp(struct interface *ifp);
struct interface *zebra_ns_lookup_ifp(struct zebra_ns *zns, uint32_t ifindex);
struct interface *zebra_ns_lookup_ifp_name(struct zebra_ns *zns, const char *ifname);
/* Iterate collection of ifps, calling application's callback. Callback uses
* return semantics from lib/ns.h: return NS_WALK_STOP to stop the iteration.
* Caller's 'arg' is included in each callback.
* The iterator returns STOP or CONTINUE also.
*/
int zebra_ns_ifp_walk(struct zebra_ns *zns,
int (*func)(struct interface *ifp, void *arg), void *arg);
/* Walk all NSes, and all ifps for each NS. */
void zebra_ns_ifp_walk_all(int (*func)(struct interface *ifp, void *arg), void *arg);
*: rework renaming the default VRF Currently, it is possible to rename the default VRF either by passing `-o` option to zebra or by creating a file in `/var/run/netns` and binding it to `/proc/self/ns/net`. In both cases, only zebra knows about the rename and other daemons learn about it only after they connect to zebra. This is a problem, because daemons may read their config before they connect to zebra. To handle this rename after the config is read, we have some special code in every single daemon, which is not very bad but not desirable in my opinion. But things are getting worse when we need to handle this in northbound layer as we have to manually rewrite the config nodes. This approach is already hacky, but still works as every daemon handles its own NB structures. But it is completely incompatible with the central management daemon architecture we are aiming for, as mgmtd doesn't even have a connection with zebra to learn from it. And it shouldn't have it, because operational state changes should never affect configuration. To solve the problem and simplify the code, I propose to expand the `-o` option to all daemons. By using the startup option, we let daemons know about the rename before they read their configs so we don't need any special code to deal with it. There's an easy way to pass the option to all daemons by using `frr_global_options` variable. Unfortunately, the second way of renaming by creating a file in `/var/run/netns` is incompatible with the new mgmtd architecture. Theoretically, we could force daemons to read their configs only after they connect to zebra, but it means adding even more code to handle a very specific use-case. And anyway this won't work for mgmtd as it doesn't have a connection with zebra. So I had to remove this option. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
2021-12-03 23:22:55 +01:00
int zebra_ns_init(void);
int zebra_ns_enable(ns_id_t ns_id, void **info);
int zebra_ns_disabled(struct ns *ns);
int zebra_ns_early_shutdown(struct ns *ns,
void *param_in __attribute__((unused)),
void **param_out __attribute__((unused)));
int zebra_ns_final_shutdown(struct ns *ns,
void *param_in __attribute__((unused)),
void **param_out __attribute__((unused)));
zebra: fix heap-use-after free on ns shutdown The following ASAN issue has been observed: > ERROR: AddressSanitizer: heap-use-after-free on address 0x6160000acba4 at pc 0x55910c5694d0 bp 0x7ffe3a8ac850 sp 0x7ffe3a8ac840 > READ of size 4 at 0x6160000acba4 thread T0 > #0 0x55910c5694cf in ctx_info_from_zns zebra/zebra_dplane.c:3315 > #1 0x55910c569696 in dplane_ctx_ns_init zebra/zebra_dplane.c:3331 > #2 0x55910c56bf61 in dplane_ctx_nexthop_init zebra/zebra_dplane.c:3680 > #3 0x55910c5711ca in dplane_nexthop_update_internal zebra/zebra_dplane.c:4490 > #4 0x55910c571c5c in dplane_nexthop_delete zebra/zebra_dplane.c:4717 > #5 0x55910c61e90e in zebra_nhg_uninstall_kernel zebra/zebra_nhg.c:3413 > #6 0x55910c615d8a in zebra_nhg_decrement_ref zebra/zebra_nhg.c:1919 > #7 0x55910c6404db in route_entry_update_nhe zebra/zebra_rib.c:454 > #8 0x55910c64c904 in rib_re_nhg_free zebra/zebra_rib.c:2822 > #9 0x55910c655be2 in rib_unlink zebra/zebra_rib.c:4212 > #10 0x55910c6430f9 in zebra_rtable_node_cleanup zebra/zebra_rib.c:968 > #11 0x7f26f275b8a9 in route_node_free lib/table.c:75 > #12 0x7f26f275bae4 in route_table_free lib/table.c:111 > #13 0x7f26f275b749 in route_table_finish lib/table.c:46 > #14 0x55910c65db17 in zebra_router_free_table zebra/zebra_router.c:191 > #15 0x55910c65dfb5 in zebra_router_terminate zebra/zebra_router.c:244 > #16 0x55910c4f40db in zebra_finalize zebra/main.c:249 > #17 0x7f26f2777108 in event_call lib/event.c:2011 > #18 0x7f26f264180e in frr_run lib/libfrr.c:1212 > #19 0x55910c4f49cb in main zebra/main.c:531 > #20 0x7f26f2029d8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58 > #21 0x7f26f2029e3f in __libc_start_main_impl ../csu/libc-start.c:392 > #22 0x55910c4b0114 in _start (/usr/lib/frr/zebra+0x1ae114) It happens with FRR using the kernel. During shutdown, the namespace identifier is attempted to be obtained by zebra, in an attempt to prepare zebra dataplane nexthop messages. Fix this by accessing the ns structure. Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2024-10-07 15:11:43 +02:00
int zebra_ns_kernel_shutdown(struct ns *ns, void *param_in __attribute__((unused)),
void **param_out __attribute__((unused)));
void zebra_ns_startup_continue(struct zebra_dplane_ctx *ctx);
#ifdef __cplusplus
}
#endif
#endif