]>
git.proxmox.com Git - mirror_frr.git/blob - zebra/label_manager.h
4 * Copyright (C) 2017 by Bingen Eguzkitza,
7 * This file is part of FRRouting (FRR)
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
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.
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
24 #ifndef _LABEL_MANAGER_H
25 #define _LABEL_MANAGER_H
29 #include "lib/linklist.h"
30 #include "lib/thread.h"
33 #include "zebra/zserv.h"
43 * Client daemon which the chunk belongs to can be identified by a tuple of:
44 * proto (daemon protocol) + instance + zapi session_id
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
47 * responsible for releasing them.
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
51 * the same proto+instance+session values)
53 struct label_manager_chunk
{
55 unsigned short instance
;
58 uint32_t start
; /* First label of the chunk */
59 uint32_t end
; /* Last label of the chunk */
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
67 DECLARE_HOOK(lm_client_connect
, (struct zserv
*client
, vrf_id_t vrf_id
),
69 DECLARE_HOOK(lm_client_disconnect
, (struct zserv
*client
), (client
));
70 DECLARE_HOOK(lm_get_chunk
,
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
));
74 DECLARE_HOOK(lm_release_chunk
,
75 (struct zserv
*client
, uint32_t start
, uint32_t end
),
76 (client
, start
, end
));
77 DECLARE_HOOK(lm_cbs_inited
, (), ());
80 /* declare wrappers to be called in zapi_msg.c (as hooks must be called in
81 * source file where they were defined)
83 void lm_client_connect_call(struct zserv
*client
, vrf_id_t vrf_id
);
84 void lm_get_chunk_call(struct label_manager_chunk
**lmc
, struct zserv
*client
,
85 uint8_t keep
, uint32_t size
, uint32_t base
,
87 void lm_release_chunk_call(struct zserv
*client
, uint32_t start
,
90 /* API for an external LM to return responses for requests */
91 int lm_client_connect_response(uint8_t proto
, uint16_t instance
,
92 uint32_t session_id
, vrf_id_t vrf_id
,
94 int lm_get_chunk_response(struct label_manager_chunk
*lmc
, struct zserv
*client
,
97 /* convenience function to allocate an lmc to be consumed by the above API */
98 struct label_manager_chunk
*create_label_chunk(uint8_t proto
,
99 unsigned short instance
,
101 uint8_t keep
, uint32_t start
,
103 void delete_label_chunk(void *val
);
105 /* register/unregister callbacks for hooks */
106 void lm_hooks_register(void);
107 void lm_hooks_unregister(void);
110 * Main label manager struct
111 * Holds a linked list of label chunks.
113 struct label_manager
{
114 struct list
*lc_list
;
117 void label_manager_init(void);
118 struct label_manager_chunk
*assign_label_chunk(uint8_t proto
,
119 unsigned short instance
,
121 uint8_t keep
, uint32_t size
,
123 int release_label_chunk(uint8_t proto
, unsigned short instance
,
124 uint32_t session_id
, uint32_t start
, uint32_t end
);
125 int lm_client_disconnect_cb(struct zserv
*client
);
126 int release_daemon_label_chunks(struct zserv
*client
);
127 void label_manager_close(void);
133 #endif /* _LABEL_MANAGER_H */