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