]> git.proxmox.com Git - mirror_frr.git/blame - lib/zclient.h
lib, zebra: move "struct vrf" to be a lib module
[mirror_frr.git] / lib / zclient.h
CommitLineData
718e3744 1/* Zebra's client header.
2 * Copyright (C) 1999 Kunihiro Ishiguro
3 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with GNU Zebra; see the file COPYING. If not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
20 */
21
22#ifndef _ZEBRA_ZCLIENT_H
23#define _ZEBRA_ZCLIENT_H
24
5734509c
PJ
25/* For struct zapi_ipv{4,6}. */
26#include "prefix.h"
27
718e3744 28/* For struct interface and struct connected. */
29#include "if.h"
30
31/* For input/output buffer to zebra. */
32#define ZEBRA_MAX_PACKET_SIZ 4096
33
34/* Zebra header size. */
c1b9800a 35#define ZEBRA_HEADER_SIZE 6
718e3744 36
7c8ff89e
DS
37struct redist_proto
38{
39 u_char enabled;
40 struct list *instances;
41};
42
718e3744 43/* Structure for the zebra client. */
44struct zclient
45{
4140ca4d
DS
46 /* The thread master we schedule ourselves on */
47 struct thread_master *master;
48
718e3744 49 /* Socket to zebra daemon. */
50 int sock;
51
52 /* Flag of communication to zebra is enabled or not. Default is on.
53 This flag is disabled by `no router zebra' statement. */
54 int enable;
55
56 /* Connection failure count. */
57 int fail;
58
59 /* Input buffer for zebra message. */
60 struct stream *ibuf;
61
62 /* Output buffer for zebra message. */
63 struct stream *obuf;
64
634f9ea2 65 /* Buffer of data waiting to be written to zebra. */
66 struct buffer *wb;
67
718e3744 68 /* Read and connect thread. */
69 struct thread *t_read;
70 struct thread *t_connect;
71
634f9ea2 72 /* Thread to write buffered data to zebra. */
73 struct thread *t_write;
74
718e3744 75 /* Redistribute information. */
7c8ff89e
DS
76 u_char redist_default; /* clients protocol */
77 u_short instance;
8bb0831e 78 struct redist_proto redist[AFI_MAX][ZEBRA_ROUTE_MAX];
718e3744 79
80 /* Redistribute defauilt. */
81 u_char default_information;
82
83 /* Pointer to the callback functions. */
c1b9800a 84 int (*router_id_update) (int, struct zclient *, uint16_t);
85 int (*interface_add) (int, struct zclient *, uint16_t);
86 int (*interface_delete) (int, struct zclient *, uint16_t);
87 int (*interface_up) (int, struct zclient *, uint16_t);
88 int (*interface_down) (int, struct zclient *, uint16_t);
89 int (*interface_address_add) (int, struct zclient *, uint16_t);
90 int (*interface_address_delete) (int, struct zclient *, uint16_t);
68fe91d6 91 int (*interface_bfd_dest_update) (int, struct zclient *, uint16_t);
a80beece
DS
92 int (*interface_nbr_address_add) (int, struct zclient *, uint16_t);
93 int (*interface_nbr_address_delete) (int, struct zclient *, uint16_t);
c1b9800a 94 int (*ipv4_route_add) (int, struct zclient *, uint16_t);
95 int (*ipv4_route_delete) (int, struct zclient *, uint16_t);
96 int (*ipv6_route_add) (int, struct zclient *, uint16_t);
97 int (*ipv6_route_delete) (int, struct zclient *, uint16_t);
fb018d25 98 int (*nexthop_update) (int, struct zclient *, uint16_t);
078430f6 99 int (*import_check_update) (int, struct zclient *, uint16_t);
c43ed2e4 100 int (*bfd_dest_replay) (int, struct zclient *, uint16_t);
5048fe14 101 int (*redistribute_route_ipv4_add) (int, struct zclient *, uint16_t);
102 int (*redistribute_route_ipv4_del) (int, struct zclient *, uint16_t);
103 int (*redistribute_route_ipv6_add) (int, struct zclient *, uint16_t);
104 int (*redistribute_route_ipv6_del) (int, struct zclient *, uint16_t);
718e3744 105};
106
107/* Zebra API message flag. */
108#define ZAPI_MESSAGE_NEXTHOP 0x01
109#define ZAPI_MESSAGE_IFINDEX 0x02
110#define ZAPI_MESSAGE_DISTANCE 0x04
111#define ZAPI_MESSAGE_METRIC 0x08
c8a1cb5c
DS
112#define ZAPI_MESSAGE_TAG 0x10
113#define ZAPI_MESSAGE_ONLINK 0x20
718e3744 114
c1b9800a 115/* Zserv protocol message header */
116struct zserv_header
117{
118 uint16_t length;
119 uint8_t marker; /* corresponds to command field in old zserv
120 * always set to 255 in new zserv.
121 */
122 uint8_t version;
8d79efdd 123#define ZSERV_VERSION 2
c1b9800a 124 uint16_t command;
125};
126
718e3744 127/* Zebra IPv4 route message API. */
128struct zapi_ipv4
129{
130 u_char type;
7c8ff89e 131 u_short instance;
718e3744 132
133 u_char flags;
134
135 u_char message;
136
5a616c08
B
137 safi_t safi;
138
718e3744 139 u_char nexthop_num;
140 struct in_addr **nexthop;
141
142 u_char ifindex_num;
143 unsigned int *ifindex;
144
145 u_char distance;
146
147 u_int32_t metric;
0d9551dc
DS
148
149 u_short tag;
718e3744 150};
151
718e3744 152/* Prototypes of zebra client service functions. */
4140ca4d 153extern struct zclient *zclient_new (struct thread_master *);
7c8ff89e 154extern void zclient_init (struct zclient *, int, u_short);
8cc4198f 155extern int zclient_start (struct zclient *);
156extern void zclient_stop (struct zclient *);
157extern void zclient_reset (struct zclient *);
228da428 158extern void zclient_free (struct zclient *);
634f9ea2 159
b5114685
VT
160extern int zclient_socket_connect (struct zclient *);
161extern void zclient_serv_path_set (char *path);
718e3744 162
7c8ff89e
DS
163extern int redist_check_instance (struct redist_proto *, u_short);
164extern void redist_add_instance (struct redist_proto *, u_short);
165extern void redist_del_instance (struct redist_proto *, u_short);
166
634f9ea2 167/* Send redistribute command to zebra daemon. Do not update zclient state. */
8bb0831e 168extern int zebra_redistribute_send (int command, struct zclient *, afi_t, int type, u_short instance);
634f9ea2 169
170/* If state has changed, update state and call zebra_redistribute_send. */
8bb0831e 171extern void zclient_redistribute (int command, struct zclient *, afi_t, int type,
7c8ff89e 172 u_short instance);
634f9ea2 173
174/* If state has changed, update state and send the command to zebra. */
8cc4198f 175extern void zclient_redistribute_default (int command, struct zclient *);
718e3744 176
634f9ea2 177/* Send the message in zclient->obuf to the zebra daemon (or enqueue it).
178 Returns 0 for success or -1 on an I/O error. */
179extern int zclient_send_message(struct zclient *);
718e3744 180
d211086a 181/* create header for command, length to be filled in by user later */
182extern void zclient_create_header (struct stream *, uint16_t);
183
8cc4198f 184extern struct interface *zebra_interface_add_read (struct stream *);
185extern struct interface *zebra_interface_state_read (struct stream *s);
186extern struct connected *zebra_interface_address_read (int, struct stream *);
a80beece 187extern struct nbr_connected *zebra_interface_nbr_address_read (int, struct stream *);
8cc4198f 188extern void zebra_interface_if_set_value (struct stream *, struct interface *);
189extern void zebra_router_id_update_read (struct stream *s, struct prefix *rid);
190extern int zapi_ipv4_route (u_char, struct zclient *, struct prefix_ipv4 *,
191 struct zapi_ipv4 *);
718e3744 192
193#ifdef HAVE_IPV6
194/* IPv6 prefix add and delete function prototype. */
195
196struct zapi_ipv6
197{
198 u_char type;
7c8ff89e 199 u_short instance;
718e3744 200
201 u_char flags;
202
203 u_char message;
204
c7ec179a
B
205 safi_t safi;
206
718e3744 207 u_char nexthop_num;
208 struct in6_addr **nexthop;
209
210 u_char ifindex_num;
211 unsigned int *ifindex;
212
213 u_char distance;
214
215 u_int32_t metric;
0d9551dc
DS
216
217 u_short tag;
718e3744 218};
219
8cc4198f 220extern int zapi_ipv6_route (u_char cmd, struct zclient *zclient,
0a589359 221 struct prefix_ipv6 *p, struct zapi_ipv6 *api);
8a92a8a0
DS
222extern int zapi_ipv4_route_ipv6_nexthop (u_char, struct zclient *,
223 struct prefix_ipv4 *, struct zapi_ipv6 *);
718e3744 224#endif /* HAVE_IPV6 */
225
226#endif /* _ZEBRA_ZCLIENT_H */