Feng Lu | 41f44a2 | 2015-05-22 11:39:56 +0200 | [diff] [blame] | 1 | /* |
| 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 Lu | 5a5702f | 2015-05-22 11:39:59 +0200 | [diff] [blame] | 26 | #include "linklist.h" |
| 27 | |
Feng Lu | 41f44a2 | 2015-05-22 11:39:56 +0200 | [diff] [blame] | 28 | /* The default VRF ID */ |
| 29 | #define VRF_DEFAULT 0 |
| 30 | |
| 31 | /* |
Feng Lu | 5a5702f | 2015-05-22 11:39:59 +0200 | [diff] [blame] | 32 | * 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 Lu | 41f44a2 | 2015-05-22 11:39:56 +0200 | [diff] [blame] | 42 | * 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 */ |
Feng Lu | fb2bfc1 | 2015-05-22 11:40:08 +0200 | [diff] [blame^] | 47 | #define VRF_ENABLE_HOOK 2 /* a VRF is ready to use */ |
| 48 | #define VRF_DISABLE_HOOK 3 /* a VRF is to be unusable */ |
Feng Lu | 41f44a2 | 2015-05-22 11:39:56 +0200 | [diff] [blame] | 49 | |
| 50 | /* |
| 51 | * Add a specific hook to VRF module. |
| 52 | * @param1: hook type |
| 53 | * @param2: the callback function |
| 54 | * - param 1: the VRF ID |
| 55 | * - param 2: the address of the user data pointer (the user data |
| 56 | * can be stored in or freed from there) |
| 57 | */ |
| 58 | extern void vrf_add_hook (int, int (*)(vrf_id_t, void **)); |
| 59 | |
| 60 | /* |
| 61 | * VRF iteration |
| 62 | */ |
| 63 | |
| 64 | typedef void * vrf_iter_t; |
| 65 | #define VRF_ITER_INVALID NULL /* invalid value of the iterator */ |
| 66 | |
| 67 | /* |
| 68 | * VRF iteration utilities. Example for the usage: |
| 69 | * |
| 70 | * vrf_iter_t iter = vrf_first(); |
| 71 | * for (; iter != VRF_ITER_INVALID; iter = vrf_next (iter)) |
| 72 | * |
| 73 | * or |
| 74 | * |
| 75 | * vrf_iter_t iter = vrf_iterator (<a given VRF ID>); |
| 76 | * for (; iter != VRF_ITER_INVALID; iter = vrf_next (iter)) |
| 77 | */ |
| 78 | |
| 79 | /* Return the iterator of the first VRF. */ |
| 80 | extern vrf_iter_t vrf_first (void); |
| 81 | /* Return the next VRF iterator to the given iterator. */ |
| 82 | extern vrf_iter_t vrf_next (vrf_iter_t); |
| 83 | /* Return the VRF iterator of the given VRF ID. If it does not exist, |
| 84 | * the iterator of the next existing VRF is returned. */ |
| 85 | extern vrf_iter_t vrf_iterator (vrf_id_t); |
| 86 | |
| 87 | /* |
| 88 | * VRF iterator to properties |
| 89 | */ |
| 90 | extern vrf_id_t vrf_iter2id (vrf_iter_t); |
| 91 | extern void *vrf_iter2info (vrf_iter_t); |
Feng Lu | 5a5702f | 2015-05-22 11:39:59 +0200 | [diff] [blame] | 92 | extern struct list *vrf_iter2iflist (vrf_iter_t); |
Feng Lu | 41f44a2 | 2015-05-22 11:39:56 +0200 | [diff] [blame] | 93 | |
| 94 | /* |
| 95 | * Utilities to obtain the user data |
| 96 | */ |
| 97 | |
| 98 | /* Get the data pointer of the specified VRF. If not found, create one. */ |
| 99 | extern void *vrf_info_get (vrf_id_t); |
| 100 | /* Look up the data pointer of the specified VRF. */ |
| 101 | extern void *vrf_info_lookup (vrf_id_t); |
| 102 | |
| 103 | /* |
Feng Lu | 5a5702f | 2015-05-22 11:39:59 +0200 | [diff] [blame] | 104 | * Utilities to obtain the interface list |
| 105 | */ |
| 106 | |
| 107 | /* Look up the interface list of the specified VRF. */ |
| 108 | extern struct list *vrf_iflist (vrf_id_t); |
| 109 | /* Get the interface list of the specified VRF. Create one if not find. */ |
| 110 | extern struct list *vrf_iflist_get (vrf_id_t); |
| 111 | |
| 112 | /* |
Feng Lu | 41f44a2 | 2015-05-22 11:39:56 +0200 | [diff] [blame] | 113 | * VRF initializer/destructor |
| 114 | */ |
| 115 | /* Please add hooks before calling vrf_init(). */ |
| 116 | extern void vrf_init (void); |
| 117 | extern void vrf_terminate (void); |
| 118 | |
Feng Lu | fb2bfc1 | 2015-05-22 11:40:08 +0200 | [diff] [blame^] | 119 | /* |
| 120 | * VRF utilities |
| 121 | */ |
| 122 | |
| 123 | /* Create a socket serving for the given VRF */ |
| 124 | extern int vrf_socket (int, int, int, vrf_id_t); |
| 125 | |
Feng Lu | 41f44a2 | 2015-05-22 11:39:56 +0200 | [diff] [blame] | 126 | #endif /*_ZEBRA_VRF_H*/ |
| 127 | |