summaryrefslogtreecommitdiffstats
path: root/zebra/label_manager.h
diff options
context:
space:
mode:
authorEmanuele Di Pascale <emanuele@voltanet.io>2019-06-27 10:11:35 +0200
committerEmanuele Di Pascale <emanuele@voltanet.io>2019-07-10 15:20:27 +0200
commite11d7c96d7de7f7117dc544f2e6a59a83335d185 (patch)
tree2bcc2e595bb91211692cf6ed136c5cad27103fdf /zebra/label_manager.h
parenttests: remove test_lblmgr.c (diff)
downloadfrr-e11d7c96d7de7f7117dc544f2e6a59a83335d185.tar.xz
frr-e11d7c96d7de7f7117dc544f2e6a59a83335d185.zip
zebra: label manager refactor
in order to both streamline the code and allow users to define their own specialized versions of the LM api handlers, define hooks for the 4 main primitives offered by the label manager (i.e. connect, disconnect, get_chunk and release_chunk), and have the existing code be run in response to a hook_call. Additionally, have the responses to the requesting daemon be callable from an external API. Note that the proxy version of the label manager was a source of issues and hardly used in practice. With the new hooks, users with more complex requirements can simply plug in their own code to handle label distribution remotely, so there is no longer a reason to maintain this code. Signed-off-by: Emanuele Di Pascale <emanuele@voltanet.io>
Diffstat (limited to 'zebra/label_manager.h')
-rw-r--r--zebra/label_manager.h58
1 files changed, 52 insertions, 6 deletions
diff --git a/zebra/label_manager.h b/zebra/label_manager.h
index f1b7d050c..74e283e85 100644
--- a/zebra/label_manager.h
+++ b/zebra/label_manager.h
@@ -28,6 +28,7 @@
#include "lib/linklist.h"
#include "lib/thread.h"
+#include "lib/hook.h"
#include "zebra/zserv.h"
@@ -57,6 +58,54 @@ struct label_manager_chunk {
uint32_t end; /* Last label of the chunk */
};
+/* declare hooks for the basic API, so that it can be specialized or served
+ * externally. Also declare a hook when those functions have been registered,
+ * so that any external module wanting to replace those can react
+ */
+
+DECLARE_HOOK(lm_client_connect,
+ (uint8_t proto, uint16_t instance, vrf_id_t vrf_id),
+ (proto, instance, vrf_id));
+DECLARE_HOOK(lm_client_disconnect, (uint8_t proto, uint16_t instance),
+ (proto, instance));
+DECLARE_HOOK(lm_get_chunk,
+ (struct label_manager_chunk * *lmc, uint8_t proto,
+ uint16_t instance, uint8_t keep, uint32_t size, uint32_t base,
+ vrf_id_t vrf_id),
+ (lmc, proto, instance, keep, size, base, vrf_id));
+DECLARE_HOOK(lm_release_chunk,
+ (uint8_t proto, uint16_t instance, uint32_t start, uint32_t end),
+ (proto, instance, start, end));
+DECLARE_HOOK(lm_cbs_inited, (), ());
+
+
+/* declare wrappers to be called in zapi_msg.c (as hooks must be called in
+ * source file where they were defined)
+ */
+void lm_client_connect_call(uint8_t proto, uint16_t instance, vrf_id_t vrf_id);
+void lm_get_chunk_call(struct label_manager_chunk **lmc, uint8_t proto,
+ uint16_t instance, uint8_t keep, uint32_t size,
+ uint32_t base, vrf_id_t vrf_id);
+void lm_release_chunk_call(uint8_t proto, uint16_t instance, uint32_t start,
+ uint32_t end);
+
+/* API for an external LM to return responses for requests */
+int lm_client_connect_response(uint8_t proto, uint16_t instance,
+ vrf_id_t vrf_id, uint8_t result);
+int lm_get_chunk_response(struct label_manager_chunk *lmc, uint8_t proto,
+ uint16_t instance, vrf_id_t vrf_id);
+
+/* convenience function to allocate an lmc to be consumed by the above API */
+struct label_manager_chunk *create_label_chunk(uint8_t proto,
+ unsigned short instance,
+ uint8_t keep, uint32_t start,
+ uint32_t end);
+void delete_label_chunk(void *val);
+
+/* register/unregister callbacks for hooks */
+void lm_hooks_register(void);
+void lm_hooks_unregister(void);
+
/*
* Main label manager struct
* Holds a linked list of label chunks.
@@ -65,18 +114,15 @@ struct label_manager {
struct list *lc_list;
};
-bool lm_is_external;
-
-int zread_relay_label_manager_request(int cmd, struct zserv *zserv,
- struct stream *msg, vrf_id_t vrf_id);
-void label_manager_init(char *lm_zserv_path);
+void label_manager_init(void);
struct label_manager_chunk *assign_label_chunk(uint8_t proto,
unsigned short instance,
uint8_t keep, uint32_t size,
uint32_t base);
int release_label_chunk(uint8_t proto, unsigned short instance, uint32_t start,
uint32_t end);
-int release_daemon_label_chunks(struct zserv *client);
+int lm_client_disconnect_cb(struct zserv *client);
+int release_daemon_label_chunks(uint8_t proto, unsigned short instance);
void label_manager_close(void);
#ifdef __cplusplus