]>
Commit | Line | Data |
---|---|---|
acddc0ed | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
fea12efb | 2 | /* |
3 | * Label Manager header | |
4 | * | |
5 | * Copyright (C) 2017 by Bingen Eguzkitza, | |
6 | * Volta Networks Inc. | |
7 | * | |
8678d638 | 8 | * This file is part of FRRouting (FRR) |
fea12efb | 9 | */ |
10 | ||
11 | #ifndef _LABEL_MANAGER_H | |
12 | #define _LABEL_MANAGER_H | |
13 | ||
14 | #include <stdint.h> | |
15 | ||
16 | #include "lib/linklist.h" | |
24a58196 | 17 | #include "frrevent.h" |
e11d7c96 | 18 | #include "lib/hook.h" |
fea12efb | 19 | |
bf094f69 QY |
20 | #include "zebra/zserv.h" |
21 | ||
51e94aa7 EDP |
22 | #ifdef __cplusplus |
23 | extern "C" { | |
24 | #endif | |
25 | ||
fea12efb | 26 | #define NO_PROTO 0 |
27 | ||
28 | /* | |
29 | * Label chunk struct | |
4cebdb9b MS |
30 | * Client daemon which the chunk belongs to can be identified by a tuple of: |
31 | * proto (daemon protocol) + instance + zapi session_id | |
fea12efb | 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 | |
4cebdb9b | 34 | * responsible for releasing them. |
fea12efb | 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 | |
4cebdb9b | 38 | * the same proto+instance+session values) |
fea12efb | 39 | */ |
40 | struct label_manager_chunk { | |
d7c0a89a QY |
41 | uint8_t proto; |
42 | unsigned short instance; | |
4cebdb9b | 43 | uint32_t session_id; |
d7c0a89a | 44 | uint8_t keep; |
d62a17ae | 45 | uint32_t start; /* First label of the chunk */ |
46 | uint32_t end; /* Last label of the chunk */ | |
fea12efb | 47 | }; |
48 | ||
e11d7c96 EDP |
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 | ||
4cebdb9b MS |
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)); | |
e11d7c96 | 57 | DECLARE_HOOK(lm_get_chunk, |
4cebdb9b MS |
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)); | |
e11d7c96 | 61 | DECLARE_HOOK(lm_release_chunk, |
4cebdb9b MS |
62 | (struct zserv *client, uint32_t start, uint32_t end), |
63 | (client, start, end)); | |
e11d7c96 EDP |
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 | */ | |
4cebdb9b MS |
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, | |
e11d7c96 EDP |
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, | |
4cebdb9b MS |
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); | |
e11d7c96 | 83 | |
507d2737 PR |
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 | ||
e11d7c96 EDP |
90 | /* register/unregister callbacks for hooks */ |
91 | void lm_hooks_register(void); | |
92 | void lm_hooks_unregister(void); | |
93 | ||
fea12efb | 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 | ||
e11d7c96 | 102 | void label_manager_init(void); |
507d2737 PR |
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); | |
e11d7c96 | 108 | int lm_client_disconnect_cb(struct zserv *client); |
4cebdb9b | 109 | int release_daemon_label_chunks(struct zserv *client); |
fea12efb | 110 | void label_manager_close(void); |
111 | ||
51e94aa7 EDP |
112 | #ifdef __cplusplus |
113 | } | |
114 | #endif | |
115 | ||
d62a17ae | 116 | #endif /* _LABEL_MANAGER_H */ |