]> git.proxmox.com Git - mirror_frr.git/blame - zebra/label_manager.h
Merge pull request #8643 from icosahedral/master
[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 *
8678d638 7 * This file is part of FRRouting (FRR)
fea12efb 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
4cebdb9b
MS
43 * Client daemon which the chunk belongs to can be identified by a tuple of:
44 * proto (daemon protocol) + instance + zapi session_id
fea12efb 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
4cebdb9b 47 * responsible for releasing them.
fea12efb 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
4cebdb9b 51 * the same proto+instance+session values)
fea12efb 52 */
53struct label_manager_chunk {
d7c0a89a
QY
54 uint8_t proto;
55 unsigned short instance;
4cebdb9b 56 uint32_t session_id;
d7c0a89a 57 uint8_t keep;
d62a17ae 58 uint32_t start; /* First label of the chunk */
59 uint32_t end; /* Last label of the chunk */
fea12efb 60};
61
e11d7c96
EDP
62/* declare hooks for the basic API, so that it can be specialized or served
63 * externally. Also declare a hook when those functions have been registered,
64 * so that any external module wanting to replace those can react
65 */
66
4cebdb9b
MS
67DECLARE_HOOK(lm_client_connect, (struct zserv *client, vrf_id_t vrf_id),
68 (client, vrf_id));
69DECLARE_HOOK(lm_client_disconnect, (struct zserv *client), (client));
e11d7c96 70DECLARE_HOOK(lm_get_chunk,
4cebdb9b
MS
71 (struct label_manager_chunk * *lmc, struct zserv *client,
72 uint8_t keep, uint32_t size, uint32_t base, vrf_id_t vrf_id),
73 (lmc, client, keep, size, base, vrf_id));
e11d7c96 74DECLARE_HOOK(lm_release_chunk,
4cebdb9b
MS
75 (struct zserv *client, uint32_t start, uint32_t end),
76 (client, start, end));
e11d7c96
EDP
77DECLARE_HOOK(lm_cbs_inited, (), ());
78
79
80/* declare wrappers to be called in zapi_msg.c (as hooks must be called in
81 * source file where they were defined)
82 */
4cebdb9b
MS
83void lm_client_connect_call(struct zserv *client, vrf_id_t vrf_id);
84void lm_get_chunk_call(struct label_manager_chunk **lmc, struct zserv *client,
85 uint8_t keep, uint32_t size, uint32_t base,
86 vrf_id_t vrf_id);
87void lm_release_chunk_call(struct zserv *client, uint32_t start,
e11d7c96
EDP
88 uint32_t end);
89
90/* API for an external LM to return responses for requests */
91int lm_client_connect_response(uint8_t proto, uint16_t instance,
4cebdb9b
MS
92 uint32_t session_id, vrf_id_t vrf_id,
93 uint8_t result);
94int lm_get_chunk_response(struct label_manager_chunk *lmc, struct zserv *client,
95 vrf_id_t vrf_id);
e11d7c96 96
507d2737
PR
97/* convenience function to allocate an lmc to be consumed by the above API */
98struct label_manager_chunk *
99create_label_chunk(uint8_t proto, unsigned short instance, uint32_t session_id,
100 uint8_t keep, uint32_t start, uint32_t end);
101void delete_label_chunk(void *val);
102
e11d7c96
EDP
103/* register/unregister callbacks for hooks */
104void lm_hooks_register(void);
105void lm_hooks_unregister(void);
106
fea12efb 107/*
108 * Main label manager struct
109 * Holds a linked list of label chunks.
110 */
111struct label_manager {
112 struct list *lc_list;
113};
114
e11d7c96 115void label_manager_init(void);
507d2737
PR
116struct label_manager_chunk *
117assign_label_chunk(uint8_t proto, unsigned short instance, uint32_t session_id,
118 uint8_t keep, uint32_t size, uint32_t base);
119int release_label_chunk(uint8_t proto, unsigned short instance,
120 uint32_t session_id, uint32_t start, uint32_t end);
e11d7c96 121int lm_client_disconnect_cb(struct zserv *client);
4cebdb9b 122int release_daemon_label_chunks(struct zserv *client);
fea12efb 123void label_manager_close(void);
124
51e94aa7
EDP
125#ifdef __cplusplus
126}
127#endif
128
d62a17ae 129#endif /* _LABEL_MANAGER_H */