]>
git.proxmox.com Git - mirror_frr.git/blob - zebra/label_manager.h
1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Copyright (C) 2017 by Bingen Eguzkitza,
8 * This file is part of FRRouting (FRR)
11 #ifndef _LABEL_MANAGER_H
12 #define _LABEL_MANAGER_H
16 #include "lib/linklist.h"
17 #include "lib/thread.h"
20 #include "zebra/zserv.h"
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)
40 struct label_manager_chunk
{
42 unsigned short instance
;
45 uint32_t start
; /* First label of the chunk */
46 uint32_t end
; /* Last label of the chunk */
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
54 DECLARE_HOOK(lm_client_connect
, (struct zserv
*client
, vrf_id_t 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
, (), ());
67 /* declare wrappers to be called in zapi_msg.c (as hooks must be called in
68 * source file where they were defined)
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
,
74 void lm_release_chunk_call(struct zserv
*client
, uint32_t start
,
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
,
81 int lm_get_chunk_response(struct label_manager_chunk
*lmc
, struct zserv
*client
,
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
);
90 /* register/unregister callbacks for hooks */
91 void lm_hooks_register(void);
92 void lm_hooks_unregister(void);
95 * Main label manager struct
96 * Holds a linked list of label chunks.
98 struct label_manager
{
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);
116 #endif /* _LABEL_MANAGER_H */