]> git.proxmox.com Git - mirror_frr.git/blob - ospfd/ospf_api.h
doc: Add `show ipv6 rpf X:X::X:X` command to docs
[mirror_frr.git] / ospfd / ospf_api.h
1 /*
2 * API message handling module for OSPF daemon and client.
3 * Copyright (C) 2001, 2002 Ralph Keller
4 * Copyright (c) 2022, LabN Consulting, L.L.C.
5 *
6 * This file is part of GNU Zebra.
7 *
8 * GNU Zebra is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published
10 * by the Free Software Foundation; either version 2, or (at your
11 * option) any later version.
12 *
13 * GNU Zebra is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for 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
24 /* This file is used both by the OSPFd and client applications to
25 define message formats used for communication. */
26
27 #ifndef _OSPF_API_H
28 #define _OSPF_API_H
29
30 #include <zebra.h>
31 #include "ospf_lsa.h"
32
33 #define OSPF_API_VERSION 1
34
35 /* MTYPE definition is not reflected to "memory.h". */
36 #define MTYPE_OSPF_API_MSG MTYPE_TMP
37 #define MTYPE_OSPF_API_FIFO MTYPE_TMP
38
39 /* Default API server port to accept connection request from client-side. */
40 /* This value could be overridden by "ospfapi" entry in "/etc/services". */
41 #define OSPF_API_SYNC_PORT 2607
42
43 /* -----------------------------------------------------------
44 * Generic messages
45 * -----------------------------------------------------------
46 */
47
48 /* Message header structure, fields are in network byte order and
49 aligned to four octets. */
50 struct apimsghdr {
51 uint8_t version; /* OSPF API protocol version */
52 uint8_t msgtype; /* Type of message */
53 uint16_t msglen; /* Length of message w/o header */
54 uint32_t msgseq; /* Sequence number */
55 };
56
57 /* Message representation with header and body */
58 struct msg {
59 struct msg *next; /* to link into fifo */
60
61 /* Message header */
62 struct apimsghdr hdr;
63
64 /* Message body */
65 struct stream *s;
66 };
67
68 /* Prototypes for generic messages. */
69 extern struct msg *msg_new(uint8_t msgtype, void *msgbody, uint32_t seqnum,
70 uint16_t msglen);
71 extern struct msg *msg_dup(struct msg *msg);
72 extern void msg_print(struct msg *msg); /* XXX debug only */
73 extern void msg_free(struct msg *msg);
74 struct msg *msg_read(int fd);
75 extern int msg_write(int fd, struct msg *msg);
76
77 /* For requests, the message sequence number is between MIN_SEQ and
78 MAX_SEQ. For notifications, the sequence number is 0. */
79
80 #define MIN_SEQ 1
81 #define MAX_SEQ 2147483647
82
83 extern void msg_set_seq(struct msg *msg, uint32_t seqnr);
84 extern uint32_t msg_get_seq(struct msg *msg);
85
86 /* -----------------------------------------------------------
87 * Message fifo queues
88 * -----------------------------------------------------------
89 */
90
91 /* Message queue structure. */
92 struct msg_fifo {
93 unsigned long count;
94
95 struct msg *head;
96 struct msg *tail;
97 };
98
99 /* Prototype for message fifo queues. */
100 extern struct msg_fifo *msg_fifo_new(void);
101 extern void msg_fifo_push(struct msg_fifo *, struct msg *msg);
102 extern struct msg *msg_fifo_pop(struct msg_fifo *fifo);
103 extern struct msg *msg_fifo_head(struct msg_fifo *fifo);
104 extern void msg_fifo_flush(struct msg_fifo *fifo);
105 extern void msg_fifo_free(struct msg_fifo *fifo);
106
107 /* -----------------------------------------------------------
108 * Specific message type and format definitions
109 * -----------------------------------------------------------
110 */
111
112 /* Messages to OSPF daemon. */
113 #define MSG_REGISTER_OPAQUETYPE 1
114 #define MSG_UNREGISTER_OPAQUETYPE 2
115 #define MSG_REGISTER_EVENT 3
116 #define MSG_SYNC_LSDB 4
117 #define MSG_ORIGINATE_REQUEST 5
118 #define MSG_DELETE_REQUEST 6
119 #define MSG_SYNC_REACHABLE 7
120 #define MSG_SYNC_ISM 8
121 #define MSG_SYNC_NSM 9
122 #define MSG_SYNC_ROUTER_ID 19
123
124 /* Messages from OSPF daemon. */
125 #define MSG_REPLY 10
126 #define MSG_READY_NOTIFY 11
127 #define MSG_LSA_UPDATE_NOTIFY 12
128 #define MSG_LSA_DELETE_NOTIFY 13
129 #define MSG_NEW_IF 14
130 #define MSG_DEL_IF 15
131 #define MSG_ISM_CHANGE 16
132 #define MSG_NSM_CHANGE 17
133 #define MSG_REACHABLE_CHANGE 18
134 #define MSG_ROUTER_ID_CHANGE 20
135
136 struct msg_register_opaque_type {
137 uint8_t lsatype;
138 uint8_t opaquetype;
139 uint8_t pad[2]; /* padding */
140 };
141
142 struct msg_unregister_opaque_type {
143 uint8_t lsatype;
144 uint8_t opaquetype;
145 uint8_t pad[2]; /* padding */
146 };
147
148 /* Power2 is needed to convert LSA types into bit positions,
149 * see typemask below. Type definition starts at 1, so
150 * Power2[0] is not used. */
151
152
153 static const uint16_t Power2[] = {
154 0, (1 << 0), (1 << 1), (1 << 2), (1 << 3), (1 << 4),
155 (1 << 5), (1 << 6), (1 << 7), (1 << 8), (1 << 9), (1 << 10),
156 (1 << 11), (1 << 12), (1 << 13), (1 << 14), (1 << 15)};
157
158 struct lsa_filter_type {
159 uint16_t typemask; /* bitmask for selecting LSA types (1..16) */
160 uint8_t origin; /* selects according to origin. */
161 #define NON_SELF_ORIGINATED 0
162 #define SELF_ORIGINATED (OSPF_LSA_SELF)
163 #define ANY_ORIGIN 2
164
165 uint8_t num_areas; /* number of areas in the filter. */
166 /* areas, if any, go here. */
167 };
168
169 struct msg_register_event {
170 struct lsa_filter_type filter;
171 };
172
173 struct msg_sync_lsdb {
174 struct lsa_filter_type filter;
175 };
176
177 struct msg_originate_request {
178 /* Used for LSA type 9 otherwise ignored */
179 struct in_addr ifaddr;
180
181 /* Used for LSA type 10 otherwise ignored */
182 struct in_addr area_id;
183
184 /* LSA header and LSA-specific part */
185 struct lsa_header data;
186 };
187
188
189 /* OSPF API MSG Delete Flag. */
190 #define OSPF_API_DEL_ZERO_LEN_LSA 0x01 /* send withdrawal with no LSA data */
191
192 #define IS_DEL_ZERO_LEN_LSA(x) ((x)->flags & OSPF_API_DEL_ZERO_LEN_LSA)
193
194 struct msg_delete_request {
195 struct in_addr addr; /* intf IP for link local, area for type 10,
196 "0.0.0.0" for AS-external */
197 uint8_t lsa_type;
198 uint8_t opaque_type;
199 uint8_t pad; /* padding */
200 uint8_t flags; /* delete flags */
201 uint32_t opaque_id;
202 };
203
204 struct msg_reply {
205 signed char errcode;
206 #define OSPF_API_OK 0
207 #define OSPF_API_NOSUCHINTERFACE (-1)
208 #define OSPF_API_NOSUCHAREA (-2)
209 #define OSPF_API_NOSUCHLSA (-3)
210 #define OSPF_API_ILLEGALLSATYPE (-4)
211 #define OSPF_API_OPAQUETYPEINUSE (-5)
212 #define OSPF_API_OPAQUETYPENOTREGISTERED (-6)
213 #define OSPF_API_NOTREADY (-7)
214 #define OSPF_API_NOMEMORY (-8)
215 #define OSPF_API_ERROR (-9)
216 #define OSPF_API_UNDEF (-10)
217 uint8_t pad[3]; /* padding to four byte alignment */
218 };
219
220 /* Message to tell client application that it ospf daemon is
221 * ready to accept opaque LSAs for a given interface or area. */
222
223 struct msg_ready_notify {
224 uint8_t lsa_type;
225 uint8_t opaque_type;
226 uint8_t pad[2]; /* padding */
227 struct in_addr addr; /* interface address or area address */
228 };
229
230 /* These messages have a dynamic length depending on the embodied LSA.
231 They are aligned to four octets. msg_lsa_change_notify is used for
232 both LSA update and LSAs delete. */
233
234 struct msg_lsa_change_notify {
235 /* Used for LSA type 9 otherwise ignored */
236 struct in_addr ifaddr;
237 /* Area ID. Not valid for AS-External and Opaque11 LSAs. */
238 struct in_addr area_id;
239 uint8_t is_self_originated; /* 1 if self originated. */
240 uint8_t pad[3];
241 struct lsa_header data;
242 };
243
244 struct msg_new_if {
245 struct in_addr ifaddr; /* interface IP address */
246 struct in_addr area_id; /* area this interface belongs to */
247 };
248
249 struct msg_del_if {
250 struct in_addr ifaddr; /* interface IP address */
251 };
252
253 struct msg_ism_change {
254 struct in_addr ifaddr; /* interface IP address */
255 struct in_addr area_id; /* area this interface belongs to */
256 uint8_t status; /* interface status (up/down) */
257 uint8_t pad[3]; /* not used */
258 };
259
260 struct msg_nsm_change {
261 struct in_addr ifaddr; /* attached interface */
262 struct in_addr nbraddr; /* Neighbor interface address */
263 struct in_addr router_id; /* Router ID of neighbor */
264 uint8_t status; /* NSM status */
265 uint8_t pad[3];
266 };
267
268 struct msg_reachable_change {
269 uint16_t nadd;
270 uint16_t nremove;
271 struct in_addr router_ids[]; /* add followed by remove */
272 };
273
274 struct msg_router_id_change {
275 struct in_addr router_id; /* this systems router id */
276 };
277
278 /* We make use of a union to define a structure that covers all
279 possible API messages. This allows us to find out how much memory
280 needs to be reserved for the largest API message. */
281 struct apimsg {
282 struct apimsghdr hdr;
283 union {
284 struct msg_register_opaque_type register_opaque_type;
285 struct msg_register_event register_event;
286 struct msg_sync_lsdb sync_lsdb;
287 struct msg_originate_request originate_request;
288 struct msg_delete_request delete_request;
289 struct msg_reply reply;
290 struct msg_ready_notify ready_notify;
291 struct msg_new_if new_if;
292 struct msg_del_if del_if;
293 struct msg_ism_change ism_change;
294 struct msg_nsm_change nsm_change;
295 struct msg_lsa_change_notify lsa_change_notify;
296 struct msg_reachable_change reachable_change;
297 struct msg_router_id_change router_id_change;
298 } u;
299 };
300
301 #define OSPF_API_MAX_MSG_SIZE (sizeof(struct apimsg) + OSPF_MAX_PACKET_SIZE)
302
303 /* -----------------------------------------------------------
304 * Prototypes for specific messages
305 * -----------------------------------------------------------
306 */
307
308 /* For debugging only. */
309 extern void api_opaque_lsa_print(struct ospf_lsa *lsa);
310
311 /* Messages sent by client */
312 extern struct msg *new_msg_register_opaque_type(uint32_t seqnum, uint8_t ltype,
313 uint8_t otype);
314 extern struct msg *new_msg_register_event(uint32_t seqnum,
315 struct lsa_filter_type *filter);
316 extern struct msg *new_msg_sync_lsdb(uint32_t seqnum,
317 struct lsa_filter_type *filter);
318 extern struct msg *new_msg_originate_request(uint32_t seqnum,
319 struct in_addr ifaddr,
320 struct in_addr area_id,
321 struct lsa_header *data);
322 extern struct msg *new_msg_delete_request(uint32_t seqnum, struct in_addr addr,
323 uint8_t lsa_type, uint8_t opaque_type,
324 uint32_t opaque_id, uint8_t flags);
325
326 /* Messages sent by OSPF daemon */
327 extern struct msg *new_msg_reply(uint32_t seqnum, uint8_t rc);
328
329 extern struct msg *new_msg_ready_notify(uint32_t seqnr, uint8_t lsa_type,
330 uint8_t opaque_type,
331 struct in_addr addr);
332
333 extern struct msg *new_msg_new_if(uint32_t seqnr, struct in_addr ifaddr,
334 struct in_addr area);
335
336 extern struct msg *new_msg_del_if(uint32_t seqnr, struct in_addr ifaddr);
337
338 extern struct msg *new_msg_ism_change(uint32_t seqnr, struct in_addr ifaddr,
339 struct in_addr area, uint8_t status);
340
341 extern struct msg *new_msg_nsm_change(uint32_t seqnr, struct in_addr ifaddr,
342 struct in_addr nbraddr,
343 struct in_addr router_id, uint8_t status);
344
345 /* msgtype is MSG_LSA_UPDATE_NOTIFY or MSG_LSA_DELETE_NOTIFY */
346 extern struct msg *new_msg_lsa_change_notify(uint8_t msgtype, uint32_t seqnum,
347 struct in_addr ifaddr,
348 struct in_addr area_id,
349 uint8_t is_self_originated,
350 struct lsa_header *data);
351
352 extern struct msg *new_msg_reachable_change(uint32_t seqnum, uint16_t nadd,
353 struct in_addr *add,
354 uint16_t nremove,
355 struct in_addr *remove);
356
357 extern struct msg *new_msg_router_id_change(uint32_t seqnr,
358 struct in_addr router_id);
359 /* string printing functions */
360 extern const char *ospf_api_errname(int errcode);
361 extern const char *ospf_api_typename(int msgtype);
362
363 #endif /* _OSPF_API_H */