]> git.proxmox.com Git - mirror_frr.git/blob - zebra/label_manager.h
Merge pull request #5789 from donaldsharp/bgp_ebgp_reason
[mirror_frr.git] / zebra / label_manager.h
1 /*
2 * Label Manager header
3 *
4 * Copyright (C) 2017 by Bingen Eguzkitza,
5 * Volta Networks Inc.
6 *
7 * This file is part of FreeRangeRouting (FRR)
8 *
9 * FRR is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2, or (at your option) any
12 * later version.
13 *
14 * FRR is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; see the file COPYING; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24 #ifndef _LABEL_MANAGER_H
25 #define _LABEL_MANAGER_H
26
27 #include <stdint.h>
28
29 #include "lib/linklist.h"
30 #include "lib/thread.h"
31 #include "lib/hook.h"
32
33 #include "zebra/zserv.h"
34
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38
39 #define NO_PROTO 0
40
41 /*
42 * Label chunk struct
43 * Client daemon which the chunk belongs to can be identified by either
44 * proto (daemon protocol) + instance.
45 * If the client then passes a non-empty value to keep field when it requests
46 * for chunks, the chunks won't be garbage collected and the client will be
47 * responsible of its release.
48 * Otherwise, if the keep field is not set (value 0) for the chunk, it will be
49 * automatically released when the client disconnects or when it reconnects
50 * (in case it died unexpectedly, we can know it's the same because it will have
51 * the same proto and instance values)
52 */
53 struct label_manager_chunk {
54 uint8_t proto;
55 unsigned short instance;
56 uint8_t keep;
57 uint32_t start; /* First label of the chunk */
58 uint32_t end; /* Last label of the chunk */
59 };
60
61 /* declare hooks for the basic API, so that it can be specialized or served
62 * externally. Also declare a hook when those functions have been registered,
63 * so that any external module wanting to replace those can react
64 */
65
66 DECLARE_HOOK(lm_client_connect,
67 (uint8_t proto, uint16_t instance, vrf_id_t vrf_id),
68 (proto, instance, vrf_id));
69 DECLARE_HOOK(lm_client_disconnect, (uint8_t proto, uint16_t instance),
70 (proto, instance));
71 DECLARE_HOOK(lm_get_chunk,
72 (struct label_manager_chunk * *lmc, uint8_t proto,
73 uint16_t instance, uint8_t keep, uint32_t size, uint32_t base,
74 vrf_id_t vrf_id),
75 (lmc, proto, instance, keep, size, base, vrf_id));
76 DECLARE_HOOK(lm_release_chunk,
77 (uint8_t proto, uint16_t instance, uint32_t start, uint32_t end),
78 (proto, instance, start, end));
79 DECLARE_HOOK(lm_cbs_inited, (), ());
80
81
82 /* declare wrappers to be called in zapi_msg.c (as hooks must be called in
83 * source file where they were defined)
84 */
85 void lm_client_connect_call(uint8_t proto, uint16_t instance, vrf_id_t vrf_id);
86 void lm_get_chunk_call(struct label_manager_chunk **lmc, uint8_t proto,
87 uint16_t instance, uint8_t keep, uint32_t size,
88 uint32_t base, vrf_id_t vrf_id);
89 void lm_release_chunk_call(uint8_t proto, uint16_t instance, uint32_t start,
90 uint32_t end);
91
92 /* API for an external LM to return responses for requests */
93 int lm_client_connect_response(uint8_t proto, uint16_t instance,
94 vrf_id_t vrf_id, uint8_t result);
95 int lm_get_chunk_response(struct label_manager_chunk *lmc, uint8_t proto,
96 uint16_t instance, vrf_id_t vrf_id);
97
98 /* convenience function to allocate an lmc to be consumed by the above API */
99 struct label_manager_chunk *create_label_chunk(uint8_t proto,
100 unsigned short instance,
101 uint8_t keep, uint32_t start,
102 uint32_t end);
103 void delete_label_chunk(void *val);
104
105 /* register/unregister callbacks for hooks */
106 void lm_hooks_register(void);
107 void lm_hooks_unregister(void);
108
109 /*
110 * Main label manager struct
111 * Holds a linked list of label chunks.
112 */
113 struct label_manager {
114 struct list *lc_list;
115 };
116
117 void label_manager_init(void);
118 struct label_manager_chunk *assign_label_chunk(uint8_t proto,
119 unsigned short instance,
120 uint8_t keep, uint32_t size,
121 uint32_t base);
122 int release_label_chunk(uint8_t proto, unsigned short instance, uint32_t start,
123 uint32_t end);
124 int lm_client_disconnect_cb(struct zserv *client);
125 int release_daemon_label_chunks(uint8_t proto, unsigned short instance);
126 void label_manager_close(void);
127
128 #ifdef __cplusplus
129 }
130 #endif
131
132 #endif /* _LABEL_MANAGER_H */