]> git.proxmox.com Git - mirror_frr.git/blame - zebra/label_manager.h
zebra: print unknown rule family as number
[mirror_frr.git] / zebra / label_manager.h
CommitLineData
fea12efb 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 *
896014f4
DL
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
fea12efb 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"
e11d7c96 31#include "lib/hook.h"
fea12efb 32
bf094f69
QY
33#include "zebra/zserv.h"
34
51e94aa7
EDP
35#ifdef __cplusplus
36extern "C" {
37#endif
38
fea12efb 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 */
53struct label_manager_chunk {
d7c0a89a
QY
54 uint8_t proto;
55 unsigned short instance;
56 uint8_t keep;
d62a17ae 57 uint32_t start; /* First label of the chunk */
58 uint32_t end; /* Last label of the chunk */
fea12efb 59};
60
e11d7c96
EDP
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
66DECLARE_HOOK(lm_client_connect,
67 (uint8_t proto, uint16_t instance, vrf_id_t vrf_id),
68 (proto, instance, vrf_id));
69DECLARE_HOOK(lm_client_disconnect, (uint8_t proto, uint16_t instance),
70 (proto, instance));
71DECLARE_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));
76DECLARE_HOOK(lm_release_chunk,
77 (uint8_t proto, uint16_t instance, uint32_t start, uint32_t end),
78 (proto, instance, start, end));
79DECLARE_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 */
85void lm_client_connect_call(uint8_t proto, uint16_t instance, vrf_id_t vrf_id);
86void 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);
89void 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 */
93int lm_client_connect_response(uint8_t proto, uint16_t instance,
94 vrf_id_t vrf_id, uint8_t result);
95int 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 */
99struct label_manager_chunk *create_label_chunk(uint8_t proto,
100 unsigned short instance,
101 uint8_t keep, uint32_t start,
102 uint32_t end);
103void delete_label_chunk(void *val);
104
105/* register/unregister callbacks for hooks */
106void lm_hooks_register(void);
107void lm_hooks_unregister(void);
108
fea12efb 109/*
110 * Main label manager struct
111 * Holds a linked list of label chunks.
112 */
113struct label_manager {
114 struct list *lc_list;
115};
116
e11d7c96 117void label_manager_init(void);
d7c0a89a
QY
118struct label_manager_chunk *assign_label_chunk(uint8_t proto,
119 unsigned short instance,
0e3b6a92
EDP
120 uint8_t keep, uint32_t size,
121 uint32_t base);
d7c0a89a 122int release_label_chunk(uint8_t proto, unsigned short instance, uint32_t start,
fea12efb 123 uint32_t end);
e11d7c96
EDP
124int lm_client_disconnect_cb(struct zserv *client);
125int release_daemon_label_chunks(uint8_t proto, unsigned short instance);
fea12efb 126void label_manager_close(void);
127
51e94aa7
EDP
128#ifdef __cplusplus
129}
130#endif
131
d62a17ae 132#endif /* _LABEL_MANAGER_H */