blob: d7b799875b1ac09e30c3caa51ae55cb46503f72b [file] [log] [blame]
Feng Lu41f44a22015-05-22 11:39:56 +02001/*
2 * VRF 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_VRF_H
24#define _ZEBRA_VRF_H
25
Feng Lu5a5702f2015-05-22 11:39:59 +020026#include "linklist.h"
27
Feng Lu41f44a22015-05-22 11:39:56 +020028/* The default VRF ID */
29#define VRF_DEFAULT 0
30
31/*
Feng Lu5a5702f2015-05-22 11:39:59 +020032 * The command strings
33 */
34
35#define VRF_CMD_STR "vrf <0-65535>"
36#define VRF_CMD_HELP_STR "Specify the VRF\nThe VRF ID\n"
37
38#define VRF_ALL_CMD_STR "vrf all"
39#define VRF_ALL_CMD_HELP_STR "Specify the VRF\nAll VRFs\n"
40
41/*
Feng Lu41f44a22015-05-22 11:39:56 +020042 * VRF hooks
43 */
44
45#define VRF_NEW_HOOK 0 /* a new VRF is just created */
46#define VRF_DELETE_HOOK 1 /* a VRF is to be deleted */
47
48/*
49 * Add a specific hook to VRF module.
50 * @param1: hook type
51 * @param2: the callback function
52 * - param 1: the VRF ID
53 * - param 2: the address of the user data pointer (the user data
54 * can be stored in or freed from there)
55 */
56extern void vrf_add_hook (int, int (*)(vrf_id_t, void **));
57
58/*
59 * VRF iteration
60 */
61
62typedef void * vrf_iter_t;
63#define VRF_ITER_INVALID NULL /* invalid value of the iterator */
64
65/*
66 * VRF iteration utilities. Example for the usage:
67 *
68 * vrf_iter_t iter = vrf_first();
69 * for (; iter != VRF_ITER_INVALID; iter = vrf_next (iter))
70 *
71 * or
72 *
73 * vrf_iter_t iter = vrf_iterator (<a given VRF ID>);
74 * for (; iter != VRF_ITER_INVALID; iter = vrf_next (iter))
75 */
76
77/* Return the iterator of the first VRF. */
78extern vrf_iter_t vrf_first (void);
79/* Return the next VRF iterator to the given iterator. */
80extern vrf_iter_t vrf_next (vrf_iter_t);
81/* Return the VRF iterator of the given VRF ID. If it does not exist,
82 * the iterator of the next existing VRF is returned. */
83extern vrf_iter_t vrf_iterator (vrf_id_t);
84
85/*
86 * VRF iterator to properties
87 */
88extern vrf_id_t vrf_iter2id (vrf_iter_t);
89extern void *vrf_iter2info (vrf_iter_t);
Feng Lu5a5702f2015-05-22 11:39:59 +020090extern struct list *vrf_iter2iflist (vrf_iter_t);
Feng Lu41f44a22015-05-22 11:39:56 +020091
92/*
93 * Utilities to obtain the user data
94 */
95
96/* Get the data pointer of the specified VRF. If not found, create one. */
97extern void *vrf_info_get (vrf_id_t);
98/* Look up the data pointer of the specified VRF. */
99extern void *vrf_info_lookup (vrf_id_t);
100
101/*
Feng Lu5a5702f2015-05-22 11:39:59 +0200102 * Utilities to obtain the interface list
103 */
104
105/* Look up the interface list of the specified VRF. */
106extern struct list *vrf_iflist (vrf_id_t);
107/* Get the interface list of the specified VRF. Create one if not find. */
108extern struct list *vrf_iflist_get (vrf_id_t);
109
110/*
Feng Lu41f44a22015-05-22 11:39:56 +0200111 * VRF initializer/destructor
112 */
113/* Please add hooks before calling vrf_init(). */
114extern void vrf_init (void);
115extern void vrf_terminate (void);
116
117#endif /*_ZEBRA_VRF_H*/
118