2 * API message handling module for OSPF daemon and client.
3 * Copyright (C) 2001, 2002 Ralph Keller
5 * This file is part of GNU Zebra.
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.
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.
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
23 /* This file is used both by the OSPFd and client applications to
24 define message formats used for communication. */
29 #define OSPF_API_VERSION 1
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
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
39 /* -----------------------------------------------------------
41 * -----------------------------------------------------------
44 /* Message header structure, fields are in network byte order and
45 aligned to four octets. */
47 uint8_t version
; /* OSPF API protocol version */
48 uint8_t msgtype
; /* Type of message */
49 uint16_t msglen
; /* Length of message w/o header */
50 uint32_t msgseq
; /* Sequence number */
53 /* Message representation with header and body */
55 struct msg
*next
; /* to link into fifo */
64 /* Prototypes for generic messages. */
65 extern struct msg
*msg_new(uint8_t msgtype
, void *msgbody
, uint32_t seqnum
,
67 extern struct msg
*msg_dup(struct msg
*msg
);
68 extern void msg_print(struct msg
*msg
); /* XXX debug only */
69 extern void msg_free(struct msg
*msg
);
70 struct msg
*msg_read(int fd
);
71 extern int msg_write(int fd
, struct msg
*msg
);
73 /* For requests, the message sequence number is between MIN_SEQ and
74 MAX_SEQ. For notifications, the sequence number is 0. */
77 #define MAX_SEQ 2147483647
79 extern void msg_set_seq(struct msg
*msg
, uint32_t seqnr
);
80 extern uint32_t msg_get_seq(struct msg
*msg
);
82 /* -----------------------------------------------------------
84 * -----------------------------------------------------------
87 /* Message queue structure. */
95 /* Prototype for message fifo queues. */
96 extern struct msg_fifo
*msg_fifo_new(void);
97 extern void msg_fifo_push(struct msg_fifo
*, struct msg
*msg
);
98 extern struct msg
*msg_fifo_pop(struct msg_fifo
*fifo
);
99 extern struct msg
*msg_fifo_head(struct msg_fifo
*fifo
);
100 extern void msg_fifo_flush(struct msg_fifo
*fifo
);
101 extern void msg_fifo_free(struct msg_fifo
*fifo
);
103 /* -----------------------------------------------------------
104 * Specific message type and format definitions
105 * -----------------------------------------------------------
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
116 /* Messages from OSPF daemon. */
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
126 struct msg_register_opaque_type
{
129 uint8_t pad
[2]; /* padding */
132 struct msg_unregister_opaque_type
{
135 uint8_t pad
[2]; /* padding */
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. */
143 static const uint16_t Power2
[] = {
144 0, (1 << 0), (1 << 1), (1 << 2), (1 << 3), (1 << 4),
145 (1 << 5), (1 << 6), (1 << 7), (1 << 8), (1 << 9), (1 << 10),
146 (1 << 11), (1 << 12), (1 << 13), (1 << 14), (1 << 15)};
148 struct lsa_filter_type
{
149 uint16_t typemask
; /* bitmask for selecting LSA types (1..16) */
150 uint8_t origin
; /* selects according to origin. */
151 #define NON_SELF_ORIGINATED 0
152 #define SELF_ORIGINATED (OSPF_LSA_SELF)
155 uint8_t num_areas
; /* number of areas in the filter. */
156 /* areas, if any, go here. */
159 struct msg_register_event
{
160 struct lsa_filter_type filter
;
163 struct msg_sync_lsdb
{
164 struct lsa_filter_type filter
;
167 struct msg_originate_request
{
168 /* Used for LSA type 9 otherwise ignored */
169 struct in_addr ifaddr
;
171 /* Used for LSA type 10 otherwise ignored */
172 struct in_addr area_id
;
174 /* LSA header and LSA-specific part */
175 struct lsa_header data
;
178 struct msg_delete_request
{
179 struct in_addr area_id
; /* "0.0.0.0" for AS-external opaque LSAs */
182 uint8_t pad
[2]; /* padding */
188 #define OSPF_API_OK 0
189 #define OSPF_API_NOSUCHINTERFACE (-1)
190 #define OSPF_API_NOSUCHAREA (-2)
191 #define OSPF_API_NOSUCHLSA (-3)
192 #define OSPF_API_ILLEGALLSATYPE (-4)
193 #define OSPF_API_OPAQUETYPEINUSE (-5)
194 #define OSPF_API_OPAQUETYPENOTREGISTERED (-6)
195 #define OSPF_API_NOTREADY (-7)
196 #define OSPF_API_NOMEMORY (-8)
197 #define OSPF_API_ERROR (-9)
198 #define OSPF_API_UNDEF (-10)
199 uint8_t pad
[3]; /* padding to four byte alignment */
202 /* Message to tell client application that it ospf daemon is
203 * ready to accept opaque LSAs for a given interface or area. */
205 struct msg_ready_notify
{
208 uint8_t pad
[2]; /* padding */
209 struct in_addr addr
; /* interface address or area address */
212 /* These messages have a dynamic length depending on the embodied LSA.
213 They are aligned to four octets. msg_lsa_change_notify is used for
214 both LSA update and LSAs delete. */
216 struct msg_lsa_change_notify
{
217 /* Used for LSA type 9 otherwise ignored */
218 struct in_addr ifaddr
;
219 /* Area ID. Not valid for AS-External and Opaque11 LSAs. */
220 struct in_addr area_id
;
221 uint8_t is_self_originated
; /* 1 if self originated. */
223 struct lsa_header data
;
227 struct in_addr ifaddr
; /* interface IP address */
228 struct in_addr area_id
; /* area this interface belongs to */
232 struct in_addr ifaddr
; /* interface IP address */
235 struct msg_ism_change
{
236 struct in_addr ifaddr
; /* interface IP address */
237 struct in_addr area_id
; /* area this interface belongs to */
238 uint8_t status
; /* interface status (up/down) */
239 uint8_t pad
[3]; /* not used */
242 struct msg_nsm_change
{
243 struct in_addr ifaddr
; /* attached interface */
244 struct in_addr nbraddr
; /* Neighbor interface address */
245 struct in_addr router_id
; /* Router ID of neighbor */
246 uint8_t status
; /* NSM status */
250 /* We make use of a union to define a structure that covers all
251 possible API messages. This allows us to find out how much memory
252 needs to be reserved for the largest API message. */
254 struct apimsghdr hdr
;
256 struct msg_register_opaque_type register_opaque_type
;
257 struct msg_register_event register_event
;
258 struct msg_sync_lsdb sync_lsdb
;
259 struct msg_originate_request originate_request
;
260 struct msg_delete_request delete_request
;
261 struct msg_reply reply
;
262 struct msg_ready_notify ready_notify
;
263 struct msg_new_if new_if
;
264 struct msg_del_if del_if
;
265 struct msg_ism_change ism_change
;
266 struct msg_nsm_change nsm_change
;
267 struct msg_lsa_change_notify lsa_change_notify
;
271 #define OSPF_API_MAX_MSG_SIZE (sizeof(struct apimsg) + OSPF_MAX_LSA_SIZE)
273 /* -----------------------------------------------------------
274 * Prototypes for specific messages
275 * -----------------------------------------------------------
278 /* For debugging only. */
279 extern void api_opaque_lsa_print(struct lsa_header
*data
);
281 /* Messages sent by client */
282 extern struct msg
*new_msg_register_opaque_type(uint32_t seqnum
, uint8_t ltype
,
284 extern struct msg
*new_msg_register_event(uint32_t seqnum
,
285 struct lsa_filter_type
*filter
);
286 extern struct msg
*new_msg_sync_lsdb(uint32_t seqnum
,
287 struct lsa_filter_type
*filter
);
288 extern struct msg
*new_msg_originate_request(uint32_t seqnum
,
289 struct in_addr ifaddr
,
290 struct in_addr area_id
,
291 struct lsa_header
*data
);
292 extern struct msg
*new_msg_delete_request(uint32_t seqnum
,
293 struct in_addr area_id
,
294 uint8_t lsa_type
, uint8_t opaque_type
,
297 /* Messages sent by OSPF daemon */
298 extern struct msg
*new_msg_reply(uint32_t seqnum
, uint8_t rc
);
300 extern struct msg
*new_msg_ready_notify(uint32_t seqnr
, uint8_t lsa_type
,
302 struct in_addr addr
);
304 extern struct msg
*new_msg_new_if(uint32_t seqnr
, struct in_addr ifaddr
,
305 struct in_addr area
);
307 extern struct msg
*new_msg_del_if(uint32_t seqnr
, struct in_addr ifaddr
);
309 extern struct msg
*new_msg_ism_change(uint32_t seqnr
, struct in_addr ifaddr
,
310 struct in_addr area
, uint8_t status
);
312 extern struct msg
*new_msg_nsm_change(uint32_t seqnr
, struct in_addr ifaddr
,
313 struct in_addr nbraddr
,
314 struct in_addr router_id
, uint8_t status
);
316 /* msgtype is MSG_LSA_UPDATE_NOTIFY or MSG_LSA_DELETE_NOTIFY */
317 extern struct msg
*new_msg_lsa_change_notify(uint8_t msgtype
, uint32_t seqnum
,
318 struct in_addr ifaddr
,
319 struct in_addr area_id
,
320 uint8_t is_self_originated
,
321 struct lsa_header
*data
);
323 /* string printing functions */
324 extern const char *ospf_api_errname(int errcode
);
325 extern const char *ospf_api_typename(int msgtype
);
327 #endif /* _OSPF_API_H */