]> git.proxmox.com Git - mirror_frr.git/blob - zebra/zserv.h
Merge pull request #2384 from qlyoung/docs-bgp-update
[mirror_frr.git] / zebra / zserv.h
1 /*
2 * Zebra API server.
3 * Portions:
4 * Copyright (C) 1997-1999 Kunihiro Ishiguro
5 * Copyright (C) 2015-2018 Cumulus Networks, Inc.
6 * et al.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation; either version 2 of the License, or (at your option)
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; see the file COPYING; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #ifndef _ZEBRA_ZSERV_H
24 #define _ZEBRA_ZSERV_H
25
26 /* clang-format off */
27 #include <stdint.h> /* for uint32_t, uint8_t */
28 #include <time.h> /* for time_t */
29
30 #include "lib/route_types.h" /* for ZEBRA_ROUTE_MAX */
31 #include "lib/zebra.h" /* for AFI_MAX */
32 #include "lib/vrf.h" /* for vrf_bitmap_t */
33 #include "lib/zclient.h" /* for redist_proto */
34 #include "lib/stream.h" /* for stream, stream_fifo */
35 #include "lib/thread.h" /* for thread, thread_master */
36 #include "lib/linklist.h" /* for list */
37 #include "lib/workqueue.h" /* for work_queue */
38 #include "lib/hook.h" /* for DECLARE_HOOK, DECLARE_KOOH */
39
40 #include "zebra/zebra_vrf.h" /* for zebra_vrf */
41 /* clang-format on */
42
43 /* Default port information. */
44 #define ZEBRA_VTY_PORT 2601
45
46 /* Default configuration filename. */
47 #define DEFAULT_CONFIG_FILE "zebra.conf"
48
49 #define ZEBRA_RMAP_DEFAULT_UPDATE_TIMER 5 /* disabled by default */
50
51 /* Client structure. */
52 struct zserv {
53 /* Client pthread */
54 struct frr_pthread *pthread;
55
56 /* Client file descriptor. */
57 int sock;
58
59 /* Input/output buffer to the client. */
60 pthread_mutex_t ibuf_mtx;
61 struct stream_fifo *ibuf_fifo;
62 pthread_mutex_t obuf_mtx;
63 struct stream_fifo *obuf_fifo;
64
65 /* Private I/O buffers */
66 struct stream *ibuf_work;
67 struct stream *obuf_work;
68
69 /* Buffer of data waiting to be written to client. */
70 struct buffer *wb;
71
72 /* Threads for read/write. */
73 struct thread *t_read;
74 struct thread *t_write;
75
76 /* default routing table this client munges */
77 int rtm_table;
78
79 /* This client's redistribute flag. */
80 struct redist_proto mi_redist[AFI_MAX][ZEBRA_ROUTE_MAX];
81 vrf_bitmap_t redist[AFI_MAX][ZEBRA_ROUTE_MAX];
82
83 /* Redistribute default route flag. */
84 vrf_bitmap_t redist_default;
85
86 /* Interface information. */
87 vrf_bitmap_t ifinfo;
88
89 /* Router-id information. */
90 vrf_bitmap_t ridinfo;
91
92 bool notify_owner;
93
94 /* client's protocol */
95 uint8_t proto;
96 uint16_t instance;
97 uint8_t is_synchronous;
98
99 /* Statistics */
100 uint32_t redist_v4_add_cnt;
101 uint32_t redist_v4_del_cnt;
102 uint32_t redist_v6_add_cnt;
103 uint32_t redist_v6_del_cnt;
104 uint32_t v4_route_add_cnt;
105 uint32_t v4_route_upd8_cnt;
106 uint32_t v4_route_del_cnt;
107 uint32_t v6_route_add_cnt;
108 uint32_t v6_route_del_cnt;
109 uint32_t v6_route_upd8_cnt;
110 uint32_t connected_rt_add_cnt;
111 uint32_t connected_rt_del_cnt;
112 uint32_t ifup_cnt;
113 uint32_t ifdown_cnt;
114 uint32_t ifadd_cnt;
115 uint32_t ifdel_cnt;
116 uint32_t if_bfd_cnt;
117 uint32_t bfd_peer_add_cnt;
118 uint32_t bfd_peer_upd8_cnt;
119 uint32_t bfd_peer_del_cnt;
120 uint32_t bfd_peer_replay_cnt;
121 uint32_t vrfadd_cnt;
122 uint32_t vrfdel_cnt;
123 uint32_t if_vrfchg_cnt;
124 uint32_t bfd_client_reg_cnt;
125 uint32_t vniadd_cnt;
126 uint32_t vnidel_cnt;
127 uint32_t l3vniadd_cnt;
128 uint32_t l3vnidel_cnt;
129 uint32_t macipadd_cnt;
130 uint32_t macipdel_cnt;
131 uint32_t prefixadd_cnt;
132 uint32_t prefixdel_cnt;
133
134 time_t nh_reg_time;
135 time_t nh_dereg_time;
136 time_t nh_last_upd_time;
137
138 /*
139 * Session information.
140 *
141 * These are not synchronous with respect to each other. For instance,
142 * last_read_cmd may contain a value that has been read in the future
143 * relative to last_read_time.
144 */
145
146 /* monotime of client creation */
147 _Atomic uint32_t connect_time;
148 /* monotime of last message received */
149 _Atomic uint32_t last_read_time;
150 /* monotime of last message sent */
151 _Atomic uint32_t last_write_time;
152 /* command code of last message read */
153 _Atomic uint16_t last_read_cmd;
154 /* command code of last message written */
155 _Atomic uint16_t last_write_cmd;
156 };
157
158 #define ZAPI_HANDLER_ARGS \
159 struct zserv *client, struct zmsghdr *hdr, struct stream *msg, \
160 struct zebra_vrf *zvrf
161
162 /* Hooks for client connect / disconnect */
163 DECLARE_HOOK(zserv_client_connect, (struct zserv *client), (client));
164 DECLARE_KOOH(zserv_client_close, (struct zserv *client), (client));
165
166 /* Zebra instance */
167 struct zebra_t {
168 /* Thread master */
169 struct thread_master *master;
170 struct list *client_list;
171
172 /* Socket */
173 int sock;
174
175 /* default table */
176 uint32_t rtm_table_default;
177
178 /* rib work queue */
179 #define ZEBRA_RIB_PROCESS_HOLD_TIME 10
180 struct work_queue *ribq;
181 struct meta_queue *mq;
182
183 /* LSP work queue */
184 struct work_queue *lsp_process_q;
185
186 #define ZEBRA_ZAPI_PACKETS_TO_PROCESS 1000
187 _Atomic uint32_t packets_to_process;
188 };
189 extern struct zebra_t zebrad;
190 extern unsigned int multipath_num;
191
192 /*
193 * Initialize Zebra API server.
194 *
195 * Installs CLI commands and creates the client list.
196 */
197 extern void zserv_init(void);
198
199 /*
200 * Start Zebra API server.
201 *
202 * Allocates resources, creates the server socket and begins listening on the
203 * socket.
204 *
205 * path
206 * where to place the Unix domain socket
207 */
208 extern void zserv_start(char *path);
209
210 /*
211 * Send a message to a connected Zebra API client.
212 *
213 * client
214 * the client to send to
215 *
216 * msg
217 * the message to send
218 */
219 extern int zserv_send_message(struct zserv *client, struct stream *msg);
220
221 /*
222 * Retrieve a client by its protocol and instance number.
223 *
224 * proto
225 * protocol number
226 *
227 * instance
228 * instance number
229 *
230 * Returns:
231 * The Zebra API client.
232 */
233 extern struct zserv *zserv_find_client(uint8_t proto, unsigned short instance);
234
235 #if defined(HANDLE_ZAPI_FUZZING)
236 extern void zserv_read_file(char *input);
237 #endif
238
239 #endif /* _ZEBRA_ZEBRA_H */