X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=lib%2Fns.h;h=b3810f069b46b8914b24c565b5c8daa524247990;hb=897989f8710208ce8aa6cf5efe5de1927569fb4f;hp=98fd3fa18c65077f1fd22a7c45c8d86cb7bdbe95;hpb=31d08cde94b5a5e2ee6d48564c73e4edeb4a3220;p=mirror_frr.git diff --git a/lib/ns.h b/lib/ns.h index 98fd3fa18..b3810f069 100644 --- a/lib/ns.h +++ b/lib/ns.h @@ -24,39 +24,56 @@ #include "openbsd-tree.h" #include "linklist.h" +#include "vty.h" -typedef u_int16_t ns_id_t; +typedef uint32_t ns_id_t; -/* The default NS ID */ -#define NS_DEFAULT 0 +/* the default NS ID */ +#define NS_UNKNOWN UINT32_MAX /* Default netns directory (Linux) */ #define NS_RUN_DIR "/var/run/netns" -struct ns -{ - RB_ENTRY(ns) entry; +#ifdef HAVE_NETNS +#define NS_DEFAULT_NAME "/proc/self/ns/net" +#else /* !HAVE_NETNS */ +#define NS_DEFAULT_NAME "Default-logical-router" +#endif /* HAVE_NETNS */ - /* Identifier, same as the vector index */ - ns_id_t ns_id; +struct ns { + RB_ENTRY(ns) entry; - /* Name */ - char *name; + /* Identifier, same as the vector index */ + ns_id_t ns_id; - /* File descriptor */ - int fd; + /* Identifier, mapped on the NSID value */ + ns_id_t internal_ns_id; - /* Master list of interfaces belonging to this NS */ - struct list *iflist; + /* Name */ + char *name; - /* User data */ - void *info; + /* File descriptor */ + int fd; + + /* Master list of interfaces belonging to this NS */ + struct list *iflist; + + /* Back Pointer to VRF */ + void *vrf_ctxt; + + /* User data */ + void *info; }; -RB_HEAD (ns_head, ns); -RB_PROTOTYPE (ns_head, ns, entry, ns_compare) +RB_HEAD(ns_head, ns); +RB_PROTOTYPE(ns_head, ns, entry, ns_compare) extern struct ns_head ns_tree; +/* + * API for managing NETNS. eg from zebra daemon + * one want to manage the list of NETNS, etc... + */ + /* * NS hooks */ @@ -74,21 +91,87 @@ extern struct ns_head ns_tree; * - param 2: the address of the user data pointer (the user data * can be stored in or freed from there) */ -extern void ns_add_hook (int, int (*)(ns_id_t, void **)); +extern void ns_add_hook(int type, int (*)(struct ns *)); + /* * NS initializer/destructor */ -/* Please add hooks before calling ns_init(). */ -extern void ns_init (void); -extern void ns_terminate (void); + +extern void ns_terminate(void); + +/* API to initialize NETNS managerment + * parameter is the default ns_id + */ +extern void ns_init_management(ns_id_t ns_id, ns_id_t internal_ns_idx); + /* * NS utilities */ -/* Create a socket serving for the given NS */ -extern int ns_socket (int, int, int, ns_id_t); +/* Create a socket serving for the given NS + */ +int ns_socket(int domain, int type, int protocol, ns_id_t ns_id); -#endif /*_ZEBRA_NS_H*/ +/* return the path of the NETNS */ +extern char *ns_netns_pathname(struct vty *vty, const char *name); + +/* Parse and execute a function on all the NETNS */ +extern void ns_walk_func(int (*func)(struct ns *)); +/* API to get the NETNS name, from the ns pointer */ +extern const char *ns_get_name(struct ns *ns); + +/* only called from vrf ( when removing netns from vrf) + * or at VRF or logical router termination + */ +extern void ns_delete(struct ns *ns); + +/* return > 0 if netns is available + * called by VRF to check netns backend is available for VRF + */ +extern int ns_have_netns(void); + +/* API to get context information of a NS */ +extern void *ns_info_lookup(ns_id_t ns_id); + +/* API to map internal ns id value with + * user friendly ns id external value + */ +extern ns_id_t ns_map_nsid_with_external(ns_id_t ns_id, bool map); + +/* + * NS init routine + * should be called from backendx + */ +extern void ns_init(void); + +/* API to retrieve default NS */ +extern ns_id_t ns_get_default_id(void); + +#define NS_DEFAULT ns_get_default_id() + +/* API that can be used to change from NS */ +extern int ns_switchback_to_initial(void); +extern int ns_switch_to_netns(const char *netns_name); + +/* + * NS handling routines. + * called by modules that use NS backend + */ + +/* API to search for already present NETNS */ +extern struct ns *ns_lookup(ns_id_t ns_id); +extern struct ns *ns_lookup_name(const char *name); + +/* API to handle NS : creation, enable, disable + * for enable, a callback function is passed as parameter + * the callback belongs to the module that uses NS as backend + * upon enabling the NETNS, the upper layer is informed + */ +extern int ns_enable(struct ns *ns, void (*func)(ns_id_t, void *)); +extern struct ns *ns_get_created(struct ns *ns, char *name, ns_id_t ns_id); +extern void ns_disable(struct ns *ns); + +#endif /*_ZEBRA_NS_H*/