]> git.proxmox.com Git - mirror_frr.git/blob - zebra/label_manager.h
e2f5d19019d3aaf2e48fea6441f7fe9d18a676fe
[mirror_frr.git] / zebra / label_manager.h
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Label Manager header
4 *
5 * Copyright (C) 2017 by Bingen Eguzkitza,
6 * Volta Networks Inc.
7 *
8 * This file is part of FRRouting (FRR)
9 */
10
11 #ifndef _LABEL_MANAGER_H
12 #define _LABEL_MANAGER_H
13
14 #include <stdint.h>
15
16 #include "lib/linklist.h"
17 #include "event.h"
18 #include "lib/hook.h"
19
20 #include "zebra/zserv.h"
21
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25
26 #define NO_PROTO 0
27
28 /*
29 * Label chunk struct
30 * Client daemon which the chunk belongs to can be identified by a tuple of:
31 * proto (daemon protocol) + instance + zapi session_id
32 * If the client then passes a non-empty value to keep field when it requests
33 * for chunks, the chunks won't be garbage collected and the client will be
34 * responsible for releasing them.
35 * Otherwise, if the keep field is not set (value 0) for the chunk, it will be
36 * automatically released when the client disconnects or when it reconnects
37 * (in case it died unexpectedly, we can know it's the same because it will have
38 * the same proto+instance+session values)
39 */
40 struct label_manager_chunk {
41 uint8_t proto;
42 unsigned short instance;
43 uint32_t session_id;
44 uint8_t keep;
45 uint32_t start; /* First label of the chunk */
46 uint32_t end; /* Last label of the chunk */
47 };
48
49 /* declare hooks for the basic API, so that it can be specialized or served
50 * externally. Also declare a hook when those functions have been registered,
51 * so that any external module wanting to replace those can react
52 */
53
54 DECLARE_HOOK(lm_client_connect, (struct zserv *client, vrf_id_t vrf_id),
55 (client, vrf_id));
56 DECLARE_HOOK(lm_client_disconnect, (struct zserv *client), (client));
57 DECLARE_HOOK(lm_get_chunk,
58 (struct label_manager_chunk * *lmc, struct zserv *client,
59 uint8_t keep, uint32_t size, uint32_t base, vrf_id_t vrf_id),
60 (lmc, client, keep, size, base, vrf_id));
61 DECLARE_HOOK(lm_release_chunk,
62 (struct zserv *client, uint32_t start, uint32_t end),
63 (client, start, end));
64 DECLARE_HOOK(lm_cbs_inited, (), ());
65
66
67 /* declare wrappers to be called in zapi_msg.c (as hooks must be called in
68 * source file where they were defined)
69 */
70 void lm_client_connect_call(struct zserv *client, vrf_id_t vrf_id);
71 void lm_get_chunk_call(struct label_manager_chunk **lmc, struct zserv *client,
72 uint8_t keep, uint32_t size, uint32_t base,
73 vrf_id_t vrf_id);
74 void lm_release_chunk_call(struct zserv *client, uint32_t start,
75 uint32_t end);
76
77 /* API for an external LM to return responses for requests */
78 int lm_client_connect_response(uint8_t proto, uint16_t instance,
79 uint32_t session_id, vrf_id_t vrf_id,
80 uint8_t result);
81 int lm_get_chunk_response(struct label_manager_chunk *lmc, struct zserv *client,
82 vrf_id_t vrf_id);
83
84 /* convenience function to allocate an lmc to be consumed by the above API */
85 struct label_manager_chunk *
86 create_label_chunk(uint8_t proto, unsigned short instance, uint32_t session_id,
87 uint8_t keep, uint32_t start, uint32_t end);
88 void delete_label_chunk(void *val);
89
90 /* register/unregister callbacks for hooks */
91 void lm_hooks_register(void);
92 void lm_hooks_unregister(void);
93
94 /*
95 * Main label manager struct
96 * Holds a linked list of label chunks.
97 */
98 struct label_manager {
99 struct list *lc_list;
100 };
101
102 void label_manager_init(void);
103 struct label_manager_chunk *
104 assign_label_chunk(uint8_t proto, unsigned short instance, uint32_t session_id,
105 uint8_t keep, uint32_t size, uint32_t base);
106 int release_label_chunk(uint8_t proto, unsigned short instance,
107 uint32_t session_id, uint32_t start, uint32_t end);
108 int lm_client_disconnect_cb(struct zserv *client);
109 int release_daemon_label_chunks(struct zserv *client);
110 void label_manager_close(void);
111
112 #ifdef __cplusplus
113 }
114 #endif
115
116 #endif /* _LABEL_MANAGER_H */