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