4 * Copyright (C) 1997-1999 Kunihiro Ishiguro
5 * Copyright (C) 2015-2018 Cumulus Networks, Inc.
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)
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
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
23 #ifndef _ZEBRA_ZSERV_H
24 #define _ZEBRA_ZSERV_H
26 /* clang-format off */
27 #include <stdint.h> /* for uint32_t, uint8_t */
28 #include <time.h> /* for time_t */
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 */
40 #include "zebra/zebra_vrf.h" /* for zebra_vrf */
43 /* Default port information. */
44 #define ZEBRA_VTY_PORT 2601
46 /* Default configuration filename. */
47 #define DEFAULT_CONFIG_FILE "zebra.conf"
49 #define ZEBRA_RMAP_DEFAULT_UPDATE_TIMER 5 /* disabled by default */
51 /* Client structure. */
53 /* Client file descriptor. */
56 /* Input/output buffer to the client. */
57 struct stream_fifo
*ibuf_fifo
;
58 struct stream_fifo
*obuf_fifo
;
60 /* Private I/O buffers */
61 struct stream
*ibuf_work
;
62 struct stream
*obuf_work
;
64 /* Buffer of data waiting to be written to client. */
67 /* Threads for read/write. */
68 struct thread
*t_read
;
69 struct thread
*t_write
;
71 /* Thread for delayed close. */
72 struct thread
*t_suicide
;
74 /* default routing table this client munges */
77 /* This client's redistribute flag. */
78 struct redist_proto mi_redist
[AFI_MAX
][ZEBRA_ROUTE_MAX
];
79 vrf_bitmap_t redist
[AFI_MAX
][ZEBRA_ROUTE_MAX
];
81 /* Redistribute default route flag. */
82 vrf_bitmap_t redist_default
;
84 /* Interface information. */
87 /* Router-id information. */
92 /* client's protocol */
95 uint8_t is_synchronous
;
98 uint32_t redist_v4_add_cnt
;
99 uint32_t redist_v4_del_cnt
;
100 uint32_t redist_v6_add_cnt
;
101 uint32_t redist_v6_del_cnt
;
102 uint32_t v4_route_add_cnt
;
103 uint32_t v4_route_upd8_cnt
;
104 uint32_t v4_route_del_cnt
;
105 uint32_t v6_route_add_cnt
;
106 uint32_t v6_route_del_cnt
;
107 uint32_t v6_route_upd8_cnt
;
108 uint32_t connected_rt_add_cnt
;
109 uint32_t connected_rt_del_cnt
;
115 uint32_t bfd_peer_add_cnt
;
116 uint32_t bfd_peer_upd8_cnt
;
117 uint32_t bfd_peer_del_cnt
;
118 uint32_t bfd_peer_replay_cnt
;
121 uint32_t if_vrfchg_cnt
;
122 uint32_t bfd_client_reg_cnt
;
125 uint32_t l3vniadd_cnt
;
126 uint32_t l3vnidel_cnt
;
127 uint32_t macipadd_cnt
;
128 uint32_t macipdel_cnt
;
129 uint32_t prefixadd_cnt
;
130 uint32_t prefixdel_cnt
;
133 time_t last_read_time
;
134 time_t last_write_time
;
136 time_t nh_dereg_time
;
137 time_t nh_last_upd_time
;
143 #define ZAPI_HANDLER_ARGS \
144 struct zserv *client, struct zmsghdr *hdr, struct stream *msg, \
145 struct zebra_vrf *zvrf
147 /* Hooks for client connect / disconnect */
148 DECLARE_HOOK(zapi_client_connect
, (struct zserv
*client
), (client
));
149 DECLARE_KOOH(zapi_client_close
, (struct zserv
*client
), (client
));
154 struct thread_master
*master
;
155 struct list
*client_list
;
158 uint32_t rtm_table_default
;
161 #define ZEBRA_RIB_PROCESS_HOLD_TIME 10
162 struct work_queue
*ribq
;
163 struct meta_queue
*mq
;
166 struct work_queue
*lsp_process_q
;
168 #define ZEBRA_ZAPI_PACKETS_TO_PROCESS 10
169 uint32_t packets_to_process
;
171 extern struct zebra_t zebrad
;
172 extern unsigned int multipath_num
;
175 extern void zserv_init(void);
176 extern void zebra_zserv_socket_init(char *path
);
177 extern int zebra_server_send_message(struct zserv
*client
, struct stream
*msg
);
179 extern struct zserv
*zebra_find_client(uint8_t proto
, unsigned short instance
);
181 #if defined(HANDLE_ZAPI_FUZZING)
182 extern void zserv_read_file(char *input
);
185 #endif /* _ZEBRA_ZEBRA_H */