]>
Commit | Line | Data |
---|---|---|
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 |
37 | struct redist_proto |
38 | { | |
39 | u_char enabled; | |
40 | struct list *instances; | |
41 | }; | |
42 | ||
718e3744 | 43 | /* Structure for the zebra client. */ |
44 | struct zclient | |
45 | { | |
46 | /* Socket to zebra daemon. */ | |
47 | int sock; | |
48 | ||
49 | /* Flag of communication to zebra is enabled or not. Default is on. | |
50 | This flag is disabled by `no router zebra' statement. */ | |
51 | int enable; | |
52 | ||
53 | /* Connection failure count. */ | |
54 | int fail; | |
55 | ||
56 | /* Input buffer for zebra message. */ | |
57 | struct stream *ibuf; | |
58 | ||
59 | /* Output buffer for zebra message. */ | |
60 | struct stream *obuf; | |
61 | ||
634f9ea2 | 62 | /* Buffer of data waiting to be written to zebra. */ |
63 | struct buffer *wb; | |
64 | ||
718e3744 | 65 | /* Read and connect thread. */ |
66 | struct thread *t_read; | |
67 | struct thread *t_connect; | |
68 | ||
634f9ea2 | 69 | /* Thread to write buffered data to zebra. */ |
70 | struct thread *t_write; | |
71 | ||
718e3744 | 72 | /* Redistribute information. */ |
7c8ff89e DS |
73 | u_char redist_default; /* clients protocol */ |
74 | u_short instance; | |
8bb0831e | 75 | struct redist_proto redist[AFI_MAX][ZEBRA_ROUTE_MAX]; |
718e3744 | 76 | |
77 | /* Redistribute defauilt. */ | |
78 | u_char default_information; | |
79 | ||
80 | /* Pointer to the callback functions. */ | |
c1b9800a | 81 | int (*router_id_update) (int, struct zclient *, uint16_t); |
82 | int (*interface_add) (int, struct zclient *, uint16_t); | |
83 | int (*interface_delete) (int, struct zclient *, uint16_t); | |
84 | int (*interface_up) (int, struct zclient *, uint16_t); | |
85 | int (*interface_down) (int, struct zclient *, uint16_t); | |
86 | int (*interface_address_add) (int, struct zclient *, uint16_t); | |
87 | int (*interface_address_delete) (int, struct zclient *, uint16_t); | |
68fe91d6 | 88 | int (*interface_bfd_dest_update) (int, struct zclient *, uint16_t); |
a80beece DS |
89 | int (*interface_nbr_address_add) (int, struct zclient *, uint16_t); |
90 | int (*interface_nbr_address_delete) (int, struct zclient *, uint16_t); | |
c1b9800a | 91 | int (*ipv4_route_add) (int, struct zclient *, uint16_t); |
92 | int (*ipv4_route_delete) (int, struct zclient *, uint16_t); | |
93 | int (*ipv6_route_add) (int, struct zclient *, uint16_t); | |
94 | int (*ipv6_route_delete) (int, struct zclient *, uint16_t); | |
fb018d25 | 95 | int (*nexthop_update) (int, struct zclient *, uint16_t); |
078430f6 | 96 | int (*import_check_update) (int, struct zclient *, uint16_t); |
c43ed2e4 | 97 | int (*bfd_dest_replay) (int, struct zclient *, uint16_t); |
718e3744 | 98 | }; |
99 | ||
100 | /* Zebra API message flag. */ | |
101 | #define ZAPI_MESSAGE_NEXTHOP 0x01 | |
102 | #define ZAPI_MESSAGE_IFINDEX 0x02 | |
103 | #define ZAPI_MESSAGE_DISTANCE 0x04 | |
104 | #define ZAPI_MESSAGE_METRIC 0x08 | |
c8a1cb5c DS |
105 | #define ZAPI_MESSAGE_TAG 0x10 |
106 | #define ZAPI_MESSAGE_ONLINK 0x20 | |
718e3744 | 107 | |
c1b9800a | 108 | /* Zserv protocol message header */ |
109 | struct zserv_header | |
110 | { | |
111 | uint16_t length; | |
112 | uint8_t marker; /* corresponds to command field in old zserv | |
113 | * always set to 255 in new zserv. | |
114 | */ | |
115 | uint8_t version; | |
8d79efdd | 116 | #define ZSERV_VERSION 2 |
c1b9800a | 117 | uint16_t command; |
118 | }; | |
119 | ||
718e3744 | 120 | /* Zebra IPv4 route message API. */ |
121 | struct zapi_ipv4 | |
122 | { | |
123 | u_char type; | |
7c8ff89e | 124 | u_short instance; |
718e3744 | 125 | |
126 | u_char flags; | |
127 | ||
128 | u_char message; | |
129 | ||
5a616c08 B |
130 | safi_t safi; |
131 | ||
718e3744 | 132 | u_char nexthop_num; |
133 | struct in_addr **nexthop; | |
134 | ||
135 | u_char ifindex_num; | |
136 | unsigned int *ifindex; | |
137 | ||
138 | u_char distance; | |
139 | ||
140 | u_int32_t metric; | |
0d9551dc DS |
141 | |
142 | u_short tag; | |
718e3744 | 143 | }; |
144 | ||
718e3744 | 145 | /* Prototypes of zebra client service functions. */ |
8cc4198f | 146 | extern struct zclient *zclient_new (void); |
7c8ff89e | 147 | extern void zclient_init (struct zclient *, int, u_short); |
8cc4198f | 148 | extern int zclient_start (struct zclient *); |
149 | extern void zclient_stop (struct zclient *); | |
150 | extern void zclient_reset (struct zclient *); | |
228da428 | 151 | extern void zclient_free (struct zclient *); |
634f9ea2 | 152 | |
b5114685 VT |
153 | extern int zclient_socket_connect (struct zclient *); |
154 | extern void zclient_serv_path_set (char *path); | |
718e3744 | 155 | |
7c8ff89e DS |
156 | extern int redist_check_instance (struct redist_proto *, u_short); |
157 | extern void redist_add_instance (struct redist_proto *, u_short); | |
158 | extern void redist_del_instance (struct redist_proto *, u_short); | |
159 | ||
634f9ea2 | 160 | /* Send redistribute command to zebra daemon. Do not update zclient state. */ |
8bb0831e | 161 | extern int zebra_redistribute_send (int command, struct zclient *, afi_t, int type, u_short instance); |
634f9ea2 | 162 | |
163 | /* If state has changed, update state and call zebra_redistribute_send. */ | |
8bb0831e | 164 | extern void zclient_redistribute (int command, struct zclient *, afi_t, int type, |
7c8ff89e | 165 | u_short instance); |
634f9ea2 | 166 | |
167 | /* If state has changed, update state and send the command to zebra. */ | |
8cc4198f | 168 | extern void zclient_redistribute_default (int command, struct zclient *); |
718e3744 | 169 | |
634f9ea2 | 170 | /* Send the message in zclient->obuf to the zebra daemon (or enqueue it). |
171 | Returns 0 for success or -1 on an I/O error. */ | |
172 | extern int zclient_send_message(struct zclient *); | |
718e3744 | 173 | |
d211086a | 174 | /* create header for command, length to be filled in by user later */ |
175 | extern void zclient_create_header (struct stream *, uint16_t); | |
176 | ||
8cc4198f | 177 | extern struct interface *zebra_interface_add_read (struct stream *); |
178 | extern struct interface *zebra_interface_state_read (struct stream *s); | |
179 | extern struct connected *zebra_interface_address_read (int, struct stream *); | |
a80beece | 180 | extern struct nbr_connected *zebra_interface_nbr_address_read (int, struct stream *); |
8cc4198f | 181 | extern void zebra_interface_if_set_value (struct stream *, struct interface *); |
182 | extern void zebra_router_id_update_read (struct stream *s, struct prefix *rid); | |
183 | extern int zapi_ipv4_route (u_char, struct zclient *, struct prefix_ipv4 *, | |
184 | struct zapi_ipv4 *); | |
718e3744 | 185 | |
186 | #ifdef HAVE_IPV6 | |
187 | /* IPv6 prefix add and delete function prototype. */ | |
188 | ||
189 | struct zapi_ipv6 | |
190 | { | |
191 | u_char type; | |
7c8ff89e | 192 | u_short instance; |
718e3744 | 193 | |
194 | u_char flags; | |
195 | ||
196 | u_char message; | |
197 | ||
c7ec179a B |
198 | safi_t safi; |
199 | ||
718e3744 | 200 | u_char nexthop_num; |
201 | struct in6_addr **nexthop; | |
202 | ||
203 | u_char ifindex_num; | |
204 | unsigned int *ifindex; | |
205 | ||
206 | u_char distance; | |
207 | ||
208 | u_int32_t metric; | |
0d9551dc DS |
209 | |
210 | u_short tag; | |
718e3744 | 211 | }; |
212 | ||
8cc4198f | 213 | extern int zapi_ipv6_route (u_char cmd, struct zclient *zclient, |
0a589359 | 214 | struct prefix_ipv6 *p, struct zapi_ipv6 *api); |
8a92a8a0 DS |
215 | extern int zapi_ipv4_route_ipv6_nexthop (u_char, struct zclient *, |
216 | struct prefix_ipv4 *, struct zapi_ipv6 *); | |
718e3744 | 217 | #endif /* HAVE_IPV6 */ |
218 | ||
219 | #endif /* _ZEBRA_ZCLIENT_H */ |