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