]> git.proxmox.com Git - mirror_frr.git/blob - lib/ns.h
zebra: handle the zns init/destroy
[mirror_frr.git] / lib / ns.h
1 /*
2 * NS related header.
3 * Copyright (C) 2014 6WIND S.A.
4 *
5 * This file is part of GNU Zebra.
6 *
7 * GNU Zebra is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published
9 * by the Free Software Foundation; either version 2, or (at your
10 * option) any later version.
11 *
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; see the file COPYING; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #ifndef _ZEBRA_NS_H
23 #define _ZEBRA_NS_H
24
25 #include "openbsd-tree.h"
26 #include "linklist.h"
27 #include "vty.h"
28 #include "vrf.h"
29
30 typedef u_int32_t ns_id_t;
31
32 /* the default NS ID */
33 #define NS_DEFAULT 0
34 #define NS_UNKNOWN UINT32_MAX
35
36 /* Default netns directory (Linux) */
37 #define NS_RUN_DIR "/var/run/netns"
38
39 struct ns {
40 RB_ENTRY(ns) entry;
41
42 /* Identifier, same as the vector index */
43 ns_id_t ns_id;
44
45 /* Name */
46 char *name;
47
48 /* File descriptor */
49 int fd;
50
51 /* Master list of interfaces belonging to this NS */
52 struct list *iflist;
53
54 /* Back Pointer to VRF */
55 void *vrf_ctxt;
56
57 /* User data */
58 void *info;
59 };
60 RB_HEAD(ns_head, ns);
61 RB_PROTOTYPE(ns_head, ns, entry, ns_compare)
62
63 extern struct ns_head ns_tree;
64
65 /*
66 * NS hooks
67 */
68
69 #define NS_NEW_HOOK 0 /* a new logical-router is just created */
70 #define NS_DELETE_HOOK 1 /* a logical-router is to be deleted */
71 #define NS_ENABLE_HOOK 2 /* a logical-router is ready to use */
72 #define NS_DISABLE_HOOK 3 /* a logical-router is to be unusable */
73
74 /*
75 * Add a specific hook ns module.
76 * @param1: hook type
77 * @param2: the callback function
78 * - param 1: the NS ID
79 * - param 2: the address of the user data pointer (the user data
80 * can be stored in or freed from there)
81 */
82 extern void ns_add_hook(int type, int (*)(struct ns *));
83
84 /*
85 * NS initializer/destructor
86 */
87 extern void ns_init_zebra(void);
88 extern void ns_terminate(void);
89
90 /*
91 * NS utilities
92 */
93
94 /* Create a socket serving for the given NS */
95 extern int ns_socket(int, int, int, ns_id_t);
96 extern void ns_cmd_init(void);
97 extern int ns_handler_create(struct vty *vty, struct vrf *vrf,
98 char *pathname, ns_id_t ns_id);
99 extern char *ns_netns_pathname(struct vty *vty, const char *name);
100 extern void *ns_info_lookup(ns_id_t ns_id);
101 extern void ns_walk_func(int (*func)(struct ns *));
102
103 #endif /*_ZEBRA_NS_H*/