]> git.proxmox.com Git - mirror_frr.git/blame - ospfd/ospf_api.h
*: make consistent & update GPLv2 file headers
[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/* -----------------------------------------------------------
40 * Generic messages
41 * -----------------------------------------------------------
42 */
43
44/* Message header structure, fields are in network byte order and
45 aligned to four octets. */
46struct apimsghdr
47{
48 u_char version; /* OSPF API protocol version */
49 u_char msgtype; /* Type of message */
50 u_int16_t msglen; /* Length of message w/o header */
51 u_int32_t msgseq; /* Sequence number */
52};
53
54/* Message representation with header and body */
55struct msg
56{
57 struct msg *next; /* to link into fifo */
58
59 /* Message header */
60 struct apimsghdr hdr;
61
62 /* Message body */
63 struct stream *s;
64};
65
66/* Prototypes for generic messages. */
4dadc291 67extern struct msg *msg_new (u_char msgtype, void *msgbody,
2d33f157 68 u_int32_t seqnum, u_int16_t msglen);
4dadc291 69extern struct msg *msg_dup (struct msg *msg);
70extern void msg_print (struct msg *msg); /* XXX debug only */
71extern void msg_free (struct msg *msg);
2d33f157 72struct msg *msg_read (int fd);
4dadc291 73extern int msg_write (int fd, struct msg *msg);
2d33f157 74
75/* For requests, the message sequence number is between MIN_SEQ and
76 MAX_SEQ. For notifications, the sequence number is 0. */
77
78#define MIN_SEQ 1
79#define MAX_SEQ 2147483647
80
4dadc291 81extern void msg_set_seq (struct msg *msg, u_int32_t seqnr);
82extern u_int32_t msg_get_seq (struct msg *msg);
2d33f157 83
84/* -----------------------------------------------------------
85 * Message fifo queues
86 * -----------------------------------------------------------
87 */
88
89/* Message queue structure. */
90struct msg_fifo
91{
92 unsigned long count;
93
94 struct msg *head;
95 struct msg *tail;
96};
97
98/* Prototype for message fifo queues. */
4dadc291 99extern struct msg_fifo *msg_fifo_new (void);
100extern void msg_fifo_push (struct msg_fifo *, struct msg *msg);
101extern struct msg *msg_fifo_pop (struct msg_fifo *fifo);
102extern struct msg *msg_fifo_head (struct msg_fifo *fifo);
103extern void msg_fifo_flush (struct msg_fifo *fifo);
104extern void msg_fifo_free (struct msg_fifo *fifo);
2d33f157 105
106/* -----------------------------------------------------------
107 * Specific message type and format definitions
108 * -----------------------------------------------------------
109 */
110
111/* Messages to OSPF daemon. */
112#define MSG_REGISTER_OPAQUETYPE 1
113#define MSG_UNREGISTER_OPAQUETYPE 2
114#define MSG_REGISTER_EVENT 3
115#define MSG_SYNC_LSDB 4
116#define MSG_ORIGINATE_REQUEST 5
117#define MSG_DELETE_REQUEST 6
118
119/* Messages from OSPF daemon. */
120#define MSG_REPLY 10
121#define MSG_READY_NOTIFY 11
122#define MSG_LSA_UPDATE_NOTIFY 12
123#define MSG_LSA_DELETE_NOTIFY 13
124#define MSG_NEW_IF 14
125#define MSG_DEL_IF 15
126#define MSG_ISM_CHANGE 16
127#define MSG_NSM_CHANGE 17
128
129struct msg_register_opaque_type
130{
131 u_char lsatype;
132 u_char opaquetype;
133 u_char pad[2]; /* padding */
134};
135
136struct msg_unregister_opaque_type
137{
138 u_char lsatype;
139 u_char opaquetype;
140 u_char pad[2]; /* padding */
141};
142
143/* Power2 is needed to convert LSA types into bit positions,
144 * see typemask below. Type definition starts at 1, so
145 * Power2[0] is not used. */
146
147
148#ifdef ORIGINAL_CODING
149static const u_int16_t
150 Power2[] = { 0x0, 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80,
151 0x100, 0x200, 0x400, 0x800, 0x1000, 0x2000, 0x4000, 0x8000
152};
153#else
154static const u_int16_t
155 Power2[] = { 0, (1 << 0), (1 << 1), (1 << 2), (1 << 3), (1 << 4),
156 (1 << 5), (1 << 6), (1 << 7), (1 << 8), (1 << 9),
157 (1 << 10), (1 << 11), (1 << 12), (1 << 13), (1 << 14),
158 (1 << 15)
159};
160#endif /* ORIGINAL_CODING */
161
162struct lsa_filter_type
163{
164 u_int16_t typemask; /* bitmask for selecting LSA types (1..16) */
165 u_char origin; /* selects according to origin. */
166#define NON_SELF_ORIGINATED 0
167#define SELF_ORIGINATED (OSPF_LSA_SELF)
168#define ANY_ORIGIN 2
169
170 u_char num_areas; /* number of areas in the filter. */
171 /* areas, if any, go here. */
172};
173
174struct msg_register_event
175{
176 struct lsa_filter_type filter;
177};
178
179struct msg_sync_lsdb
180{
181 struct lsa_filter_type filter;
182};
183
184struct msg_originate_request
185{
186 /* Used for LSA type 9 otherwise ignored */
187 struct in_addr ifaddr;
188
189 /* Used for LSA type 10 otherwise ignored */
190 struct in_addr area_id;
191
192 /* LSA header and LSA-specific part */
193 struct lsa_header data;
194};
195
196struct msg_delete_request
197{
198 struct in_addr area_id; /* "0.0.0.0" for AS-external opaque LSAs */
199 u_char lsa_type;
200 u_char opaque_type;
201 u_char pad[2]; /* padding */
202 u_int32_t opaque_id;
203};
204
205struct msg_reply
206{
306541b3 207 signed char errcode;
2d33f157 208#define OSPF_API_OK 0
209#define OSPF_API_NOSUCHINTERFACE (-1)
210#define OSPF_API_NOSUCHAREA (-2)
211#define OSPF_API_NOSUCHLSA (-3)
212#define OSPF_API_ILLEGALLSATYPE (-4)
213#define OSPF_API_OPAQUETYPEINUSE (-5)
214#define OSPF_API_OPAQUETYPENOTREGISTERED (-6)
215#define OSPF_API_NOTREADY (-7)
216#define OSPF_API_NOMEMORY (-8)
217#define OSPF_API_ERROR (-9)
218#define OSPF_API_UNDEF (-10)
219 u_char pad[3]; /* padding to four byte alignment */
220};
221
222/* Message to tell client application that it ospf daemon is
223 * ready to accept opaque LSAs for a given interface or area. */
224
225struct msg_ready_notify
226{
227 u_char lsa_type;
228 u_char opaque_type;
229 u_char pad[2]; /* padding */
230 struct in_addr addr; /* interface address or area address */
231};
232
233/* These messages have a dynamic length depending on the embodied LSA.
234 They are aligned to four octets. msg_lsa_change_notify is used for
235 both LSA update and LSAs delete. */
236
237struct msg_lsa_change_notify
238{
239 /* Used for LSA type 9 otherwise ignored */
240 struct in_addr ifaddr;
241 /* Area ID. Not valid for AS-External and Opaque11 LSAs. */
242 struct in_addr area_id;
243 u_char is_self_originated; /* 1 if self originated. */
244 u_char pad[3];
245 struct lsa_header data;
246};
247
248struct msg_new_if
249{
250 struct in_addr ifaddr; /* interface IP address */
251 struct in_addr area_id; /* area this interface belongs to */
252};
253
254struct msg_del_if
255{
256 struct in_addr ifaddr; /* interface IP address */
257};
258
259struct msg_ism_change
260{
261 struct in_addr ifaddr; /* interface IP address */
262 struct in_addr area_id; /* area this interface belongs to */
263 u_char status; /* interface status (up/down) */
264 u_char pad[3]; /* not used */
265};
266
267struct msg_nsm_change
268{
269 struct in_addr ifaddr; /* attached interface */
270 struct in_addr nbraddr; /* Neighbor interface address */
271 struct in_addr router_id; /* Router ID of neighbor */
272 u_char status; /* NSM status */
273 u_char pad[3];
274};
275
276/* We make use of a union to define a structure that covers all
277 possible API messages. This allows us to find out how much memory
278 needs to be reserved for the largest API message. */
279struct apimsg
280{
281 struct apimsghdr hdr;
282 union
283 {
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 }
297 u;
298};
299
300#define OSPF_API_MAX_MSG_SIZE (sizeof(struct apimsg) + OSPF_MAX_LSA_SIZE)
301
302/* -----------------------------------------------------------
303 * Prototypes for specific messages
304 * -----------------------------------------------------------
305 */
306
307/* For debugging only. */
4dadc291 308extern void api_opaque_lsa_print (struct lsa_header *data);
2d33f157 309
310/* Messages sent by client */
4dadc291 311extern struct msg *new_msg_register_opaque_type (u_int32_t seqnum,
312 u_char ltype, u_char otype);
313extern struct msg *new_msg_register_event (u_int32_t seqnum,
314 struct lsa_filter_type *filter);
315extern struct msg *new_msg_sync_lsdb (u_int32_t seqnum,
316 struct lsa_filter_type *filter);
317extern struct msg *new_msg_originate_request (u_int32_t seqnum,
318 struct in_addr ifaddr,
319 struct in_addr area_id,
320 struct lsa_header *data);
321extern struct msg *new_msg_delete_request (u_int32_t seqnum,
322 struct in_addr area_id,
323 u_char lsa_type,
324 u_char opaque_type,
325 u_int32_t opaque_id);
2d33f157 326
327/* Messages sent by OSPF daemon */
4dadc291 328extern struct msg *new_msg_reply (u_int32_t seqnum, u_char rc);
2d33f157 329
4dadc291 330extern struct msg *new_msg_ready_notify (u_int32_t seqnr, u_char lsa_type,
331 u_char opaque_type,
332 struct in_addr addr);
2d33f157 333
4dadc291 334extern struct msg *new_msg_new_if (u_int32_t seqnr,
335 struct in_addr ifaddr,
336 struct in_addr area);
2d33f157 337
4dadc291 338extern struct msg *new_msg_del_if (u_int32_t seqnr, struct in_addr ifaddr);
2d33f157 339
4dadc291 340extern struct msg *new_msg_ism_change (u_int32_t seqnr, struct in_addr ifaddr,
341 struct in_addr area, u_char status);
2d33f157 342
4dadc291 343extern struct msg *new_msg_nsm_change (u_int32_t seqnr, struct in_addr ifaddr,
344 struct in_addr nbraddr,
345 struct in_addr router_id,
346 u_char status);
2d33f157 347
348/* msgtype is MSG_LSA_UPDATE_NOTIFY or MSG_LSA_DELETE_NOTIFY */
4dadc291 349extern struct msg *new_msg_lsa_change_notify (u_char msgtype,
350 u_int32_t seqnum,
351 struct in_addr ifaddr,
352 struct in_addr area_id,
353 u_char is_self_originated,
354 struct lsa_header *data);
2d33f157 355
356/* string printing functions */
4dadc291 357extern const char *ospf_api_errname (int errcode);
358extern const char *ospf_api_typename (int msgtype);
2d33f157 359
360#endif /* _OSPF_API_H */