]> git.proxmox.com Git - mirror_frr.git/blame - lib/ns.h
zebra/lib: plug several memleaks
[mirror_frr.git] / lib / ns.h
CommitLineData
32bcb8b0
DS
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
18 * along with GNU Zebra; see the file COPYING. If not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
21 */
22
23#ifndef _ZEBRA_NS_H
24#define _ZEBRA_NS_H
25
26#include "linklist.h"
27
28typedef u_int16_t ns_id_t;
29
30/* The default NS ID */
31#define NS_DEFAULT 0
32
33/*
34 * The command strings
35 */
13460c44 36#define NS_RUN_DIR "/var/run/netns"
32bcb8b0
DS
37#define NS_CMD_STR "logical-router <0-65535>"
38#define NS_CMD_HELP_STR "Specify the Logical-Router\nThe Logical-Router ID\n"
39
40#define NS_ALL_CMD_STR "logical-router all"
41#define NS_ALL_CMD_HELP_STR "Specify the logical-router\nAll logical-router's\n"
42
43/*
44 * NS hooks
45 */
46
47#define NS_NEW_HOOK 0 /* a new logical-router is just created */
48#define NS_DELETE_HOOK 1 /* a logical-router is to be deleted */
49#define NS_ENABLE_HOOK 2 /* a logical-router is ready to use */
50#define NS_DISABLE_HOOK 3 /* a logical-router is to be unusable */
51
52/*
53 * Add a specific hook ns module.
54 * @param1: hook type
55 * @param2: the callback function
56 * - param 1: the NS ID
57 * - param 2: the address of the user data pointer (the user data
58 * can be stored in or freed from there)
59 */
60extern void ns_add_hook (int, int (*)(ns_id_t, void **));
61
62/*
63 * NS iteration
64 */
65
66typedef void * ns_iter_t;
67#define NS_ITER_INVALID NULL /* invalid value of the iterator */
68
69/*
70 * NS iteration utilities. Example for the usage:
71 *
72 * ns_iter_t iter = ns_first();
73 * for (; iter != NS_ITER_INVALID; iter = ns_next (iter))
74 *
75 * or
76 *
77 * ns_iter_t iter = ns_iterator (<a given NS ID>);
78 * for (; iter != NS_ITER_INVALID; iter = ns_next (iter))
79 */
80
81/* Return the iterator of the first NS. */
82extern ns_iter_t ns_first (void);
83/* Return the next NS iterator to the given iterator. */
84extern ns_iter_t ns_next (ns_iter_t);
85/* Return the NS iterator of the given NS ID. If it does not exist,
86 * the iterator of the next existing NS is returned. */
87extern ns_iter_t ns_iterator (ns_id_t);
88
89/*
90 * NS iterator to properties
91 */
92extern ns_id_t ns_iter2id (ns_iter_t);
93extern void *ns_iter2info (ns_iter_t);
94extern struct list *ns_iter2iflist (ns_iter_t);
95
96/*
97 * Utilities to obtain the user data
98 */
99
100/* Get the data pointer of the specified NS. If not found, create one. */
101extern void *ns_info_get (ns_id_t);
102/* Look up the data pointer of the specified NS. */
103extern void *ns_info_lookup (ns_id_t);
104
105/*
106 * Utilities to obtain the interface list
107 */
108
109/* Look up the interface list of the specified NS. */
110extern struct list *ns_iflist (ns_id_t);
111/* Get the interface list of the specified NS. Create one if not find. */
112extern struct list *ns_iflist_get (ns_id_t);
113
114/*
115 * NS bit-map: maintaining flags, one bit per NS ID
116 */
117
118typedef void * ns_bitmap_t;
119#define NS_BITMAP_NULL NULL
120
121extern ns_bitmap_t ns_bitmap_init (void);
122extern void ns_bitmap_free (ns_bitmap_t);
123extern void ns_bitmap_set (ns_bitmap_t, ns_id_t);
124extern void ns_bitmap_unset (ns_bitmap_t, ns_id_t);
125extern int ns_bitmap_check (ns_bitmap_t, ns_id_t);
126
127/*
128 * NS initializer/destructor
129 */
130/* Please add hooks before calling ns_init(). */
131extern void ns_init (void);
132extern void ns_terminate (void);
133
134/*
135 * NS utilities
136 */
137
138/* Create a socket serving for the given NS */
139extern int ns_socket (int, int, int, ns_id_t);
140
141#endif /*_ZEBRA_NS_H*/
142