2 * Server side of OSPF API.
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
24 #ifdef SUPPORT_OSPF_API
37 #include "sockunion.h" /* for inet_aton() */
40 #include <sys/types.h>
42 #include "ospfd/ospfd.h" /* for "struct thread_master" */
43 #include "ospfd/ospf_interface.h"
44 #include "ospfd/ospf_ism.h"
45 #include "ospfd/ospf_asbr.h"
46 #include "ospfd/ospf_lsa.h"
47 #include "ospfd/ospf_lsdb.h"
48 #include "ospfd/ospf_neighbor.h"
49 #include "ospfd/ospf_nsm.h"
50 #include "ospfd/ospf_flood.h"
51 #include "ospfd/ospf_packet.h"
52 #include "ospfd/ospf_spf.h"
53 #include "ospfd/ospf_dump.h"
54 #include "ospfd/ospf_route.h"
55 #include "ospfd/ospf_ase.h"
56 #include "ospfd/ospf_zebra.h"
57 #include "ospfd/ospf_errors.h"
59 #include "ospfd/ospf_api.h"
60 #include "ospfd/ospf_apiserver.h"
62 /* This is an implementation of an API to the OSPF daemon that allows
63 * external applications to access the OSPF daemon through socket
64 * connections. The application can use this API to inject its own
65 * opaque LSAs and flood them to other OSPF daemons. Other OSPF
66 * daemons then receive these LSAs and inform applications through the
67 * API by sending a corresponding message. The application can also
68 * register to receive all LSA types (in addition to opaque types) and
69 * use this information to reconstruct the OSPF's LSDB. The OSPF
70 * daemon supports multiple applications concurrently. */
72 /* List of all active connections. */
73 struct list
*apiserver_list
;
75 /* -----------------------------------------------------------
76 * Functions to lookup interfaces
77 * -----------------------------------------------------------
80 struct ospf_interface
*ospf_apiserver_if_lookup_by_addr(struct in_addr address
)
82 struct listnode
*node
, *nnode
;
83 struct ospf_interface
*oi
;
84 struct ospf
*ospf
= NULL
;
86 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
90 for (ALL_LIST_ELEMENTS(ospf
->oiflist
, node
, nnode
, oi
))
91 if (oi
->type
!= OSPF_IFTYPE_VIRTUALLINK
)
92 if (IPV4_ADDR_SAME(&address
, &oi
->address
->u
.prefix4
))
98 struct ospf_interface
*ospf_apiserver_if_lookup_by_ifp(struct interface
*ifp
)
100 struct listnode
*node
, *nnode
;
101 struct ospf_interface
*oi
;
102 struct ospf
*ospf
= NULL
;
104 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
108 for (ALL_LIST_ELEMENTS(ospf
->oiflist
, node
, nnode
, oi
))
115 /* -----------------------------------------------------------
117 * -----------------------------------------------------------
120 unsigned short ospf_apiserver_getport(void)
122 struct servent
*sp
= getservbyname("ospfapi", "tcp");
124 return sp
? ntohs(sp
->s_port
) : OSPF_API_SYNC_PORT
;
127 /* Initialize OSPF API module. Invoked from ospf_opaque_init() */
128 int ospf_apiserver_init(void)
133 /* Create new socket for synchronous messages. */
134 fd
= ospf_apiserver_serv_sock_family(ospf_apiserver_getport(), AF_INET
);
139 /* Schedule new thread that handles accepted connections. */
140 ospf_apiserver_event(OSPF_APISERVER_ACCEPT
, fd
, NULL
);
142 /* Initialize list that keeps track of all connections. */
143 apiserver_list
= list_new();
145 /* Register opaque-independent call back functions. These functions
146 are invoked on ISM, NSM changes and LSA update and LSA deletes */
147 rc
= ospf_register_opaque_functab(
148 0 /* all LSAs */, 0 /* all opaque types */,
149 ospf_apiserver_new_if
, ospf_apiserver_del_if
,
150 ospf_apiserver_ism_change
, ospf_apiserver_nsm_change
, NULL
,
151 NULL
, NULL
, NULL
, /* ospf_apiserver_show_info */
152 NULL
, /* originator_func */
153 NULL
, /* ospf_apiserver_lsa_refresher */
154 ospf_apiserver_lsa_update
, ospf_apiserver_lsa_delete
);
157 EC_OSPF_OPAQUE_REGISTRATION
,
158 "ospf_apiserver_init: Failed to register opaque type [0/0]");
167 /* Terminate OSPF API module. */
168 void ospf_apiserver_term(void)
170 struct ospf_apiserver
*apiserv
;
172 /* Unregister wildcard [0/0] type */
173 ospf_delete_opaque_functab(0 /* all LSAs */, 0 /* all opaque types */);
176 * Free all client instances. ospf_apiserver_free removes the node
177 * from the list, so we examine the head of the list anew each time.
179 while (apiserver_list
180 && (apiserv
= listgetdata(listhead(apiserver_list
))) != NULL
)
181 ospf_apiserver_free(apiserv
);
183 /* Free client list itself */
185 list_delete(&apiserver_list
);
187 /* Free wildcard list */
191 static struct ospf_apiserver
*lookup_apiserver(uint8_t lsa_type
,
194 struct listnode
*n1
, *n2
;
195 struct registered_opaque_type
*r
;
196 struct ospf_apiserver
*apiserv
, *found
= NULL
;
198 /* XXX: this approaches O(n**2) */
199 for (ALL_LIST_ELEMENTS_RO(apiserver_list
, n1
, apiserv
)) {
200 for (ALL_LIST_ELEMENTS_RO(apiserv
->opaque_types
, n2
, r
))
201 if (r
->lsa_type
== lsa_type
202 && r
->opaque_type
== opaque_type
) {
211 static struct ospf_apiserver
*lookup_apiserver_by_lsa(struct ospf_lsa
*lsa
)
213 struct lsa_header
*lsah
= lsa
->data
;
214 struct ospf_apiserver
*found
= NULL
;
216 if (IS_OPAQUE_LSA(lsah
->type
)) {
217 found
= lookup_apiserver(
218 lsah
->type
, GET_OPAQUE_TYPE(ntohl(lsah
->id
.s_addr
)));
223 /* -----------------------------------------------------------
224 * Followings are functions to manage client connections.
225 * -----------------------------------------------------------
227 static int ospf_apiserver_new_lsa_hook(struct ospf_lsa
*lsa
)
229 if (IS_DEBUG_OSPF_EVENT
)
230 zlog_debug("API: Put LSA(%p)[%s] into reserve, total=%ld",
231 (void *)lsa
, dump_lsa_key(lsa
), lsa
->lsdb
->total
);
235 static int ospf_apiserver_del_lsa_hook(struct ospf_lsa
*lsa
)
237 if (IS_DEBUG_OSPF_EVENT
)
238 zlog_debug("API: Get LSA(%p)[%s] from reserve, total=%ld",
239 (void *)lsa
, dump_lsa_key(lsa
), lsa
->lsdb
->total
);
243 /* Allocate new connection structure. */
244 struct ospf_apiserver
*ospf_apiserver_new(int fd_sync
, int fd_async
)
246 struct ospf_apiserver
*new =
247 XMALLOC(MTYPE_OSPF_APISERVER
, sizeof(struct ospf_apiserver
));
249 new->filter
= XMALLOC(MTYPE_OSPF_APISERVER_MSGFILTER
,
250 sizeof(struct lsa_filter_type
));
252 new->fd_sync
= fd_sync
;
253 new->fd_async
= fd_async
;
255 /* list of registered opaque types that application uses */
256 new->opaque_types
= list_new();
258 /* Initialize temporary strage for LSA instances to be refreshed. */
259 memset(&new->reserve
, 0, sizeof(struct ospf_lsdb
));
260 ospf_lsdb_init(&new->reserve
);
262 new->reserve
.new_lsa_hook
= ospf_apiserver_new_lsa_hook
; /* debug */
263 new->reserve
.del_lsa_hook
= ospf_apiserver_del_lsa_hook
; /* debug */
265 new->out_sync_fifo
= msg_fifo_new();
266 new->out_async_fifo
= msg_fifo_new();
267 new->t_sync_read
= NULL
;
268 #ifdef USE_ASYNC_READ
269 new->t_async_read
= NULL
;
270 #endif /* USE_ASYNC_READ */
271 new->t_sync_write
= NULL
;
272 new->t_async_write
= NULL
;
274 new->filter
->typemask
= 0; /* filter all LSAs */
275 new->filter
->origin
= ANY_ORIGIN
;
276 new->filter
->num_areas
= 0;
281 void ospf_apiserver_event(enum event event
, int fd
,
282 struct ospf_apiserver
*apiserv
)
285 case OSPF_APISERVER_ACCEPT
:
286 (void)thread_add_read(master
, ospf_apiserver_accept
, apiserv
,
289 case OSPF_APISERVER_SYNC_READ
:
290 apiserv
->t_sync_read
= NULL
;
291 thread_add_read(master
, ospf_apiserver_read
, apiserv
, fd
,
292 &apiserv
->t_sync_read
);
294 #ifdef USE_ASYNC_READ
295 case OSPF_APISERVER_ASYNC_READ
:
296 apiserv
->t_async_read
= NULL
;
297 thread_add_read(master
, ospf_apiserver_read
, apiserv
, fd
,
298 &apiserv
->t_async_read
);
300 #endif /* USE_ASYNC_READ */
301 case OSPF_APISERVER_SYNC_WRITE
:
302 thread_add_write(master
, ospf_apiserver_sync_write
, apiserv
, fd
,
303 &apiserv
->t_sync_write
);
305 case OSPF_APISERVER_ASYNC_WRITE
:
306 thread_add_write(master
, ospf_apiserver_async_write
, apiserv
,
307 fd
, &apiserv
->t_async_write
);
312 /* Free instance. First unregister all opaque types used by
313 application, flush opaque LSAs injected by application
314 from network and close connection. */
315 void ospf_apiserver_free(struct ospf_apiserver
*apiserv
)
317 struct listnode
*node
;
319 /* Cancel read and write threads. */
320 if (apiserv
->t_sync_read
) {
321 thread_cancel(apiserv
->t_sync_read
);
323 #ifdef USE_ASYNC_READ
324 if (apiserv
->t_async_read
) {
325 thread_cancel(apiserv
->t_async_read
);
327 #endif /* USE_ASYNC_READ */
328 if (apiserv
->t_sync_write
) {
329 thread_cancel(apiserv
->t_sync_write
);
332 if (apiserv
->t_async_write
) {
333 thread_cancel(apiserv
->t_async_write
);
336 /* Unregister all opaque types that application registered
337 and flush opaque LSAs if still in LSDB. */
339 while ((node
= listhead(apiserv
->opaque_types
)) != NULL
) {
340 struct registered_opaque_type
*regtype
= listgetdata(node
);
342 ospf_apiserver_unregister_opaque_type(
343 apiserv
, regtype
->lsa_type
, regtype
->opaque_type
);
346 /* Close connections to OSPFd. */
347 if (apiserv
->fd_sync
> 0) {
348 close(apiserv
->fd_sync
);
351 if (apiserv
->fd_async
> 0) {
352 close(apiserv
->fd_async
);
356 msg_fifo_free(apiserv
->out_sync_fifo
);
357 msg_fifo_free(apiserv
->out_async_fifo
);
359 /* Clear temporary strage for LSA instances to be refreshed. */
360 ospf_lsdb_delete_all(&apiserv
->reserve
);
361 ospf_lsdb_cleanup(&apiserv
->reserve
);
363 /* Remove from the list of active clients. */
364 listnode_delete(apiserver_list
, apiserv
);
366 if (IS_DEBUG_OSPF_EVENT
)
367 zlog_debug("API: Delete apiserv(%p), total#(%d)",
368 (void *)apiserv
, apiserver_list
->count
);
370 /* And free instance. */
371 XFREE(MTYPE_OSPF_APISERVER
, apiserv
);
374 int ospf_apiserver_read(struct thread
*thread
)
376 struct ospf_apiserver
*apiserv
;
382 apiserv
= THREAD_ARG(thread
);
383 fd
= THREAD_FD(thread
);
385 if (fd
== apiserv
->fd_sync
) {
386 event
= OSPF_APISERVER_SYNC_READ
;
387 apiserv
->t_sync_read
= NULL
;
389 if (IS_DEBUG_OSPF_EVENT
)
390 zlog_debug("API: ospf_apiserver_read: Peer: %pI4/%u",
391 &apiserv
->peer_sync
.sin_addr
,
392 ntohs(apiserv
->peer_sync
.sin_port
));
394 #ifdef USE_ASYNC_READ
395 else if (fd
== apiserv
->fd_async
) {
396 event
= OSPF_APISERVER_ASYNC_READ
;
397 apiserv
->t_async_read
= NULL
;
399 if (IS_DEBUG_OSPF_EVENT
)
400 zlog_debug("API: ospf_apiserver_read: Peer: %pI4/%u",
401 &apiserv
->peer_async
.sin_addr
,
402 ntohs(apiserv
->peer_async
.sin_port
));
404 #endif /* USE_ASYNC_READ */
406 zlog_warn("ospf_apiserver_read: Unknown fd(%d)", fd
);
407 ospf_apiserver_free(apiserv
);
411 /* Read message from fd. */
415 "ospf_apiserver_read: read failed on fd=%d, closing connection",
418 /* Perform cleanup. */
419 ospf_apiserver_free(apiserv
);
423 if (IS_DEBUG_OSPF_EVENT
)
426 /* Dispatch to corresponding message handler. */
427 rc
= ospf_apiserver_handle_msg(apiserv
, msg
);
429 /* Prepare for next message, add read thread. */
430 ospf_apiserver_event(event
, fd
, apiserv
);
438 int ospf_apiserver_sync_write(struct thread
*thread
)
440 struct ospf_apiserver
*apiserv
;
445 apiserv
= THREAD_ARG(thread
);
447 fd
= THREAD_FD(thread
);
449 apiserv
->t_sync_write
= NULL
;
452 if (fd
!= apiserv
->fd_sync
) {
453 zlog_warn("ospf_apiserver_sync_write: Unknown fd=%d", fd
);
457 if (IS_DEBUG_OSPF_EVENT
)
458 zlog_debug("API: ospf_apiserver_sync_write: Peer: %pI4/%u",
459 &apiserv
->peer_sync
.sin_addr
,
460 ntohs(apiserv
->peer_sync
.sin_port
));
462 /* Check whether there is really a message in the fifo. */
463 msg
= msg_fifo_pop(apiserv
->out_sync_fifo
);
466 "API: ospf_apiserver_sync_write: No message in Sync-FIFO?");
470 if (IS_DEBUG_OSPF_EVENT
)
473 rc
= msg_write(fd
, msg
);
475 /* Once a message is dequeued, it should be freed anyway. */
479 zlog_warn("ospf_apiserver_sync_write: write failed on fd=%d",
485 /* If more messages are in sync message fifo, schedule write thread. */
486 if (msg_fifo_head(apiserv
->out_sync_fifo
)) {
487 ospf_apiserver_event(OSPF_APISERVER_SYNC_WRITE
,
488 apiserv
->fd_sync
, apiserv
);
494 /* Perform cleanup and disconnect with peer */
495 ospf_apiserver_free(apiserv
);
502 int ospf_apiserver_async_write(struct thread
*thread
)
504 struct ospf_apiserver
*apiserv
;
509 apiserv
= THREAD_ARG(thread
);
511 fd
= THREAD_FD(thread
);
513 apiserv
->t_async_write
= NULL
;
516 if (fd
!= apiserv
->fd_async
) {
517 zlog_warn("ospf_apiserver_async_write: Unknown fd=%d", fd
);
521 if (IS_DEBUG_OSPF_EVENT
)
522 zlog_debug("API: ospf_apiserver_async_write: Peer: %pI4/%u",
523 &apiserv
->peer_async
.sin_addr
,
524 ntohs(apiserv
->peer_async
.sin_port
));
526 /* Check whether there is really a message in the fifo. */
527 msg
= msg_fifo_pop(apiserv
->out_async_fifo
);
530 "API: ospf_apiserver_async_write: No message in Async-FIFO?");
534 if (IS_DEBUG_OSPF_EVENT
)
537 rc
= msg_write(fd
, msg
);
539 /* Once a message is dequeued, it should be freed anyway. */
543 zlog_warn("ospf_apiserver_async_write: write failed on fd=%d",
549 /* If more messages are in async message fifo, schedule write thread. */
550 if (msg_fifo_head(apiserv
->out_async_fifo
)) {
551 ospf_apiserver_event(OSPF_APISERVER_ASYNC_WRITE
,
552 apiserv
->fd_async
, apiserv
);
558 /* Perform cleanup and disconnect with peer */
559 ospf_apiserver_free(apiserv
);
566 int ospf_apiserver_serv_sock_family(unsigned short port
, int family
)
572 memset(&su
, 0, sizeof(union sockunion
));
573 su
.sa
.sa_family
= family
;
575 /* Make new socket */
576 accept_sock
= sockunion_stream_socket(&su
);
580 /* This is a server, so reuse address and port */
581 sockopt_reuseaddr(accept_sock
);
582 sockopt_reuseport(accept_sock
);
584 /* Bind socket to address and given port. */
585 rc
= sockunion_bind(accept_sock
, &su
, port
, NULL
);
587 close(accept_sock
); /* Close socket */
591 /* Listen socket under queue length 3. */
592 rc
= listen(accept_sock
, 3);
594 zlog_warn("ospf_apiserver_serv_sock_family: listen: %s",
595 safe_strerror(errno
));
596 close(accept_sock
); /* Close socket */
603 /* Accept connection request from external applications. For each
604 accepted connection allocate own connection instance. */
605 int ospf_apiserver_accept(struct thread
*thread
)
611 struct ospf_apiserver
*apiserv
;
612 struct sockaddr_in peer_async
;
613 struct sockaddr_in peer_sync
;
614 unsigned int peerlen
;
617 /* THREAD_ARG (thread) is NULL */
618 accept_sock
= THREAD_FD(thread
);
620 /* Keep hearing on socket for further connections. */
621 ospf_apiserver_event(OSPF_APISERVER_ACCEPT
, accept_sock
, NULL
);
623 memset(&su
, 0, sizeof(union sockunion
));
624 /* Accept connection for synchronous messages */
625 new_sync_sock
= sockunion_accept(accept_sock
, &su
);
626 if (new_sync_sock
< 0) {
627 zlog_warn("ospf_apiserver_accept: accept: %s",
628 safe_strerror(errno
));
632 /* Get port address and port number of peer to make reverse connection.
633 The reverse channel uses the port number of the peer port+1. */
635 memset(&peer_sync
, 0, sizeof(struct sockaddr_in
));
636 peerlen
= sizeof(struct sockaddr_in
);
638 ret
= getpeername(new_sync_sock
, (struct sockaddr
*)&peer_sync
,
641 zlog_warn("ospf_apiserver_accept: getpeername: %s",
642 safe_strerror(errno
));
643 close(new_sync_sock
);
647 if (IS_DEBUG_OSPF_EVENT
)
648 zlog_debug("API: ospf_apiserver_accept: New peer: %pI4/%u",
650 ntohs(peer_sync
.sin_port
));
652 /* Create new socket for asynchronous messages. */
653 peer_async
= peer_sync
;
654 peer_async
.sin_port
= htons(ntohs(peer_sync
.sin_port
) + 1);
656 /* Check if remote port number to make reverse connection is valid one.
658 if (ntohs(peer_async
.sin_port
) == ospf_apiserver_getport()) {
660 "API: ospf_apiserver_accept: Peer(%pI4/%u): Invalid async port number?",
661 &peer_async
.sin_addr
,
662 ntohs(peer_async
.sin_port
));
663 close(new_sync_sock
);
667 new_async_sock
= socket(AF_INET
, SOCK_STREAM
, 0);
668 if (new_async_sock
< 0) {
669 zlog_warn("ospf_apiserver_accept: socket: %s",
670 safe_strerror(errno
));
671 close(new_sync_sock
);
675 ret
= connect(new_async_sock
, (struct sockaddr
*)&peer_async
,
676 sizeof(struct sockaddr_in
));
679 zlog_warn("ospf_apiserver_accept: connect: %s",
680 safe_strerror(errno
));
681 close(new_sync_sock
);
682 close(new_async_sock
);
686 #ifdef USE_ASYNC_READ
687 #else /* USE_ASYNC_READ */
688 /* Make the asynchronous channel write-only. */
689 ret
= shutdown(new_async_sock
, SHUT_RD
);
691 zlog_warn("ospf_apiserver_accept: shutdown: %s",
692 safe_strerror(errno
));
693 close(new_sync_sock
);
694 close(new_async_sock
);
697 #endif /* USE_ASYNC_READ */
699 /* Allocate new server-side connection structure */
700 apiserv
= ospf_apiserver_new(new_sync_sock
, new_async_sock
);
702 /* Add to active connection list */
703 listnode_add(apiserver_list
, apiserv
);
704 apiserv
->peer_sync
= peer_sync
;
705 apiserv
->peer_async
= peer_async
;
707 /* And add read threads for new connection */
708 ospf_apiserver_event(OSPF_APISERVER_SYNC_READ
, new_sync_sock
, apiserv
);
709 #ifdef USE_ASYNC_READ
710 ospf_apiserver_event(OSPF_APISERVER_ASYNC_READ
, new_async_sock
,
712 #endif /* USE_ASYNC_READ */
714 if (IS_DEBUG_OSPF_EVENT
)
715 zlog_debug("API: New apiserv(%p), total#(%d)", (void *)apiserv
,
716 apiserver_list
->count
);
722 /* -----------------------------------------------------------
723 * Send reply with return code to client application
724 * -----------------------------------------------------------
727 static int ospf_apiserver_send_msg(struct ospf_apiserver
*apiserv
,
730 struct msg_fifo
*fifo
;
735 switch (msg
->hdr
.msgtype
) {
737 fifo
= apiserv
->out_sync_fifo
;
738 fd
= apiserv
->fd_sync
;
739 event
= OSPF_APISERVER_SYNC_WRITE
;
741 case MSG_READY_NOTIFY
:
742 case MSG_LSA_UPDATE_NOTIFY
:
743 case MSG_LSA_DELETE_NOTIFY
:
748 fifo
= apiserv
->out_async_fifo
;
749 fd
= apiserv
->fd_async
;
750 event
= OSPF_APISERVER_ASYNC_WRITE
;
753 zlog_warn("ospf_apiserver_send_msg: Unknown message type %d",
758 /* Make a copy of the message and put in the fifo. Once the fifo
759 gets drained by the write thread, the message will be freed. */
760 /* NB: Given "msg" is untouched in this function. */
763 /* Enqueue message into corresponding fifo queue */
764 msg_fifo_push(fifo
, msg2
);
766 /* Schedule write thread */
767 ospf_apiserver_event(event
, fd
, apiserv
);
771 int ospf_apiserver_send_reply(struct ospf_apiserver
*apiserv
, uint32_t seqnr
,
774 struct msg
*msg
= new_msg_reply(seqnr
, rc
);
778 zlog_warn("ospf_apiserver_send_reply: msg_new failed");
780 /* Cannot allocate new message. What should we do? */
781 ospf_apiserver_free(apiserv
);
786 ret
= ospf_apiserver_send_msg(apiserv
, msg
);
792 /* -----------------------------------------------------------
793 * Generic message dispatching handler function
794 * -----------------------------------------------------------
797 int ospf_apiserver_handle_msg(struct ospf_apiserver
*apiserv
, struct msg
*msg
)
801 /* Call corresponding message handler function. */
802 switch (msg
->hdr
.msgtype
) {
803 case MSG_REGISTER_OPAQUETYPE
:
804 rc
= ospf_apiserver_handle_register_opaque_type(apiserv
, msg
);
806 case MSG_UNREGISTER_OPAQUETYPE
:
807 rc
= ospf_apiserver_handle_unregister_opaque_type(apiserv
, msg
);
809 case MSG_REGISTER_EVENT
:
810 rc
= ospf_apiserver_handle_register_event(apiserv
, msg
);
813 rc
= ospf_apiserver_handle_sync_lsdb(apiserv
, msg
);
815 case MSG_ORIGINATE_REQUEST
:
816 rc
= ospf_apiserver_handle_originate_request(apiserv
, msg
);
818 case MSG_DELETE_REQUEST
:
819 rc
= ospf_apiserver_handle_delete_request(apiserv
, msg
);
822 zlog_warn("ospf_apiserver_handle_msg: Unknown message type: %d",
830 /* -----------------------------------------------------------
831 * Following are functions for opaque type registration
832 * -----------------------------------------------------------
835 int ospf_apiserver_register_opaque_type(struct ospf_apiserver
*apiserv
,
836 uint8_t lsa_type
, uint8_t opaque_type
)
838 struct registered_opaque_type
*regtype
;
839 int (*originator_func
)(void *arg
);
843 case OSPF_OPAQUE_LINK_LSA
:
844 originator_func
= ospf_apiserver_lsa9_originator
;
846 case OSPF_OPAQUE_AREA_LSA
:
847 originator_func
= ospf_apiserver_lsa10_originator
;
849 case OSPF_OPAQUE_AS_LSA
:
850 originator_func
= ospf_apiserver_lsa11_originator
;
853 zlog_warn("ospf_apiserver_register_opaque_type: lsa_type(%d)",
855 return OSPF_API_ILLEGALLSATYPE
;
859 /* Register opaque function table */
860 /* NB: Duplicated registration will be detected inside the function. */
861 rc
= ospf_register_opaque_functab(
862 lsa_type
, opaque_type
, NULL
, /* ospf_apiserver_new_if */
863 NULL
, /* ospf_apiserver_del_if */
864 NULL
, /* ospf_apiserver_ism_change */
865 NULL
, /* ospf_apiserver_nsm_change */
866 NULL
, NULL
, NULL
, ospf_apiserver_show_info
, originator_func
,
867 ospf_apiserver_lsa_refresher
,
868 NULL
, /* ospf_apiserver_lsa_update */
869 NULL
/* ospf_apiserver_lsa_delete */);
872 flog_warn(EC_OSPF_OPAQUE_REGISTRATION
,
873 "Failed to register opaque type [%d/%d]", lsa_type
,
875 return OSPF_API_OPAQUETYPEINUSE
;
878 /* Remember the opaque type that application registers so when
879 connection shuts down, we can flush all LSAs of this opaque
882 regtype
= XCALLOC(MTYPE_OSPF_APISERVER
,
883 sizeof(struct registered_opaque_type
));
884 regtype
->lsa_type
= lsa_type
;
885 regtype
->opaque_type
= opaque_type
;
887 /* Add to list of registered opaque types */
888 listnode_add(apiserv
->opaque_types
, regtype
);
890 if (IS_DEBUG_OSPF_EVENT
)
892 "API: Add LSA-type(%d)/Opaque-type(%d) into apiserv(%p), total#(%d)",
893 lsa_type
, opaque_type
, (void *)apiserv
,
894 listcount(apiserv
->opaque_types
));
899 int ospf_apiserver_unregister_opaque_type(struct ospf_apiserver
*apiserv
,
900 uint8_t lsa_type
, uint8_t opaque_type
)
902 struct listnode
*node
, *nnode
;
903 struct registered_opaque_type
*regtype
;
905 for (ALL_LIST_ELEMENTS(apiserv
->opaque_types
, node
, nnode
, regtype
)) {
906 /* Check if we really registered this opaque type */
907 if (regtype
->lsa_type
== lsa_type
908 && regtype
->opaque_type
== opaque_type
) {
910 /* Yes, we registered this opaque type. Flush
911 all existing opaque LSAs of this type */
913 ospf_apiserver_flush_opaque_lsa(apiserv
, lsa_type
,
915 ospf_delete_opaque_functab(lsa_type
, opaque_type
);
917 /* Remove from list of registered opaque types */
918 listnode_delete(apiserv
->opaque_types
, regtype
);
920 if (IS_DEBUG_OSPF_EVENT
)
922 "API: Del LSA-type(%d)/Opaque-type(%d) from apiserv(%p), total#(%d)",
923 lsa_type
, opaque_type
, (void *)apiserv
,
924 listcount(apiserv
->opaque_types
));
930 /* Opaque type is not registered */
931 zlog_warn("Failed to unregister opaque type [%d/%d]", lsa_type
,
933 return OSPF_API_OPAQUETYPENOTREGISTERED
;
937 static int apiserver_is_opaque_type_registered(struct ospf_apiserver
*apiserv
,
941 struct listnode
*node
, *nnode
;
942 struct registered_opaque_type
*regtype
;
944 /* XXX: how many types are there? if few, why not just a bitmap? */
945 for (ALL_LIST_ELEMENTS(apiserv
->opaque_types
, node
, nnode
, regtype
)) {
946 /* Check if we really registered this opaque type */
947 if (regtype
->lsa_type
== lsa_type
948 && regtype
->opaque_type
== opaque_type
) {
957 int ospf_apiserver_handle_register_opaque_type(struct ospf_apiserver
*apiserv
,
960 struct msg_register_opaque_type
*rmsg
;
965 /* Extract parameters from register opaque type message */
966 rmsg
= (struct msg_register_opaque_type
*)STREAM_DATA(msg
->s
);
968 lsa_type
= rmsg
->lsatype
;
969 opaque_type
= rmsg
->opaquetype
;
971 rc
= ospf_apiserver_register_opaque_type(apiserv
, lsa_type
,
974 /* Send a reply back to client including return code */
975 rc
= ospf_apiserver_send_reply(apiserv
, ntohl(msg
->hdr
.msgseq
), rc
);
979 /* Now inform application about opaque types that are ready */
981 case OSPF_OPAQUE_LINK_LSA
:
982 ospf_apiserver_notify_ready_type9(apiserv
);
984 case OSPF_OPAQUE_AREA_LSA
:
985 ospf_apiserver_notify_ready_type10(apiserv
);
987 case OSPF_OPAQUE_AS_LSA
:
988 ospf_apiserver_notify_ready_type11(apiserv
);
996 /* Notify specific client about all opaque types 9 that are ready. */
997 void ospf_apiserver_notify_ready_type9(struct ospf_apiserver
*apiserv
)
999 struct listnode
*node
, *nnode
;
1000 struct listnode
*node2
, *nnode2
;
1002 struct ospf_interface
*oi
;
1003 struct registered_opaque_type
*r
;
1005 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1007 for (ALL_LIST_ELEMENTS(ospf
->oiflist
, node
, nnode
, oi
)) {
1008 /* Check if this interface is indeed ready for type 9 */
1009 if (!ospf_apiserver_is_ready_type9(oi
))
1012 /* Check for registered opaque type 9 types */
1013 /* XXX: loop-de-loop - optimise me */
1014 for (ALL_LIST_ELEMENTS(apiserv
->opaque_types
, node2
, nnode2
,
1018 if (r
->lsa_type
== OSPF_OPAQUE_LINK_LSA
) {
1020 /* Yes, this opaque type is ready */
1021 msg
= new_msg_ready_notify(
1022 0, OSPF_OPAQUE_LINK_LSA
, r
->opaque_type
,
1023 oi
->address
->u
.prefix4
);
1026 "apiserver_notify_ready_type9: msg_new failed");
1028 /* Cannot allocate new message. What
1030 ospf_apiserver_free(apiserv
);
1034 ospf_apiserver_send_msg(apiserv
, msg
);
1045 /* Notify specific client about all opaque types 10 that are ready. */
1046 void ospf_apiserver_notify_ready_type10(struct ospf_apiserver
*apiserv
)
1048 struct listnode
*node
, *nnode
;
1049 struct listnode
*node2
, *nnode2
;
1051 struct ospf_area
*area
;
1053 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1055 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
)) {
1056 struct registered_opaque_type
*r
;
1058 if (!ospf_apiserver_is_ready_type10(area
)) {
1062 /* Check for registered opaque type 10 types */
1063 /* XXX: loop in loop - optimise me */
1064 for (ALL_LIST_ELEMENTS(apiserv
->opaque_types
, node2
, nnode2
,
1068 if (r
->lsa_type
== OSPF_OPAQUE_AREA_LSA
) {
1069 /* Yes, this opaque type is ready */
1070 msg
= new_msg_ready_notify(
1071 0, OSPF_OPAQUE_AREA_LSA
, r
->opaque_type
,
1075 "apiserver_notify_ready_type10: msg_new failed");
1077 /* Cannot allocate new message. What
1079 ospf_apiserver_free(apiserv
);
1083 ospf_apiserver_send_msg(apiserv
, msg
);
1093 /* Notify specific client about all opaque types 11 that are ready */
1094 void ospf_apiserver_notify_ready_type11(struct ospf_apiserver
*apiserv
)
1096 struct listnode
*node
, *nnode
;
1098 struct registered_opaque_type
*r
;
1100 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1102 /* Can type 11 be originated? */
1103 if (!ospf_apiserver_is_ready_type11(ospf
))
1106 /* Check for registered opaque type 11 types */
1107 for (ALL_LIST_ELEMENTS(apiserv
->opaque_types
, node
, nnode
, r
)) {
1109 struct in_addr noarea_id
= {.s_addr
= 0L};
1111 if (r
->lsa_type
== OSPF_OPAQUE_AS_LSA
) {
1112 /* Yes, this opaque type is ready */
1113 msg
= new_msg_ready_notify(0, OSPF_OPAQUE_AS_LSA
,
1114 r
->opaque_type
, noarea_id
);
1118 "apiserver_notify_ready_type11: msg_new failed");
1120 /* Cannot allocate new message. What should we
1122 ospf_apiserver_free(apiserv
);
1126 ospf_apiserver_send_msg(apiserv
, msg
);
1135 int ospf_apiserver_handle_unregister_opaque_type(struct ospf_apiserver
*apiserv
,
1138 struct msg_unregister_opaque_type
*umsg
;
1143 /* Extract parameters from unregister opaque type message */
1144 umsg
= (struct msg_unregister_opaque_type
*)STREAM_DATA(msg
->s
);
1146 ltype
= umsg
->lsatype
;
1147 otype
= umsg
->opaquetype
;
1149 rc
= ospf_apiserver_unregister_opaque_type(apiserv
, ltype
, otype
);
1151 /* Send a reply back to client including return code */
1152 rc
= ospf_apiserver_send_reply(apiserv
, ntohl(msg
->hdr
.msgseq
), rc
);
1158 /* -----------------------------------------------------------
1159 * Following are functions for event (filter) registration.
1160 * -----------------------------------------------------------
1162 int ospf_apiserver_handle_register_event(struct ospf_apiserver
*apiserv
,
1165 struct msg_register_event
*rmsg
;
1169 rmsg
= (struct msg_register_event
*)STREAM_DATA(msg
->s
);
1171 /* Get request sequence number */
1172 seqnum
= msg_get_seq(msg
);
1174 /* Free existing filter in apiserv. */
1175 XFREE(MTYPE_OSPF_APISERVER_MSGFILTER
, apiserv
->filter
);
1176 /* Alloc new space for filter. */
1179 XMALLOC(MTYPE_OSPF_APISERVER_MSGFILTER
, ntohs(msg
->hdr
.msglen
));
1182 memcpy(apiserv
->filter
, &rmsg
->filter
, ntohs(msg
->hdr
.msglen
));
1185 /* Send a reply back to client with return code */
1186 rc
= ospf_apiserver_send_reply(apiserv
, seqnum
, rc
);
1191 /* -----------------------------------------------------------
1192 * Followings are functions for LSDB synchronization.
1193 * -----------------------------------------------------------
1196 static int apiserver_sync_callback(struct ospf_lsa
*lsa
, void *p_arg
,
1199 struct ospf_apiserver
*apiserv
;
1203 struct ospf_apiserver
*apiserv
;
1204 struct lsa_filter_type
*filter
;
1212 param
= (struct param_t
*)p_arg
;
1213 apiserv
= param
->apiserv
;
1214 seqnum
= (uint32_t)int_arg
;
1216 /* Check origin in filter. */
1217 if ((param
->filter
->origin
== ANY_ORIGIN
)
1218 || (param
->filter
->origin
== (lsa
->flags
& OSPF_LSA_SELF
))) {
1220 /* Default area for AS-External and Opaque11 LSAs */
1221 struct in_addr area_id
= {.s_addr
= 0L};
1223 /* Default interface for non Opaque9 LSAs */
1224 struct in_addr ifaddr
= {.s_addr
= 0L};
1227 area_id
= lsa
->area
->area_id
;
1229 if (lsa
->data
->type
== OSPF_OPAQUE_LINK_LSA
) {
1230 ifaddr
= lsa
->oi
->address
->u
.prefix4
;
1233 msg
= new_msg_lsa_change_notify(
1234 MSG_LSA_UPDATE_NOTIFY
, seqnum
, ifaddr
, area_id
,
1235 lsa
->flags
& OSPF_LSA_SELF
, lsa
->data
);
1238 "apiserver_sync_callback: new_msg_update failed");
1240 /* Cannot allocate new message. What should we do? */
1241 /* ospf_apiserver_free (apiserv);*/ /* Do nothing
1249 ospf_apiserver_send_msg(apiserv
, msg
);
1258 int ospf_apiserver_handle_sync_lsdb(struct ospf_apiserver
*apiserv
,
1261 struct listnode
*node
, *nnode
;
1264 struct msg_sync_lsdb
*smsg
;
1265 struct ospf_apiserver_param_t
{
1266 struct ospf_apiserver
*apiserv
;
1267 struct lsa_filter_type
*filter
;
1270 struct route_node
*rn
;
1271 struct ospf_lsa
*lsa
;
1273 struct ospf_area
*area
;
1275 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1277 /* Get request sequence number */
1278 seqnum
= msg_get_seq(msg
);
1280 smsg
= (struct msg_sync_lsdb
*)STREAM_DATA(msg
->s
);
1282 /* Set parameter struct. */
1283 param
.apiserv
= apiserv
;
1284 param
.filter
= &smsg
->filter
;
1286 /* Remember mask. */
1287 mask
= ntohs(smsg
->filter
.typemask
);
1289 /* Iterate over all areas. */
1290 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
)) {
1292 uint32_t *area_id
= NULL
;
1294 /* Compare area_id with area_ids in sync request. */
1295 if ((i
= smsg
->filter
.num_areas
) > 0) {
1296 /* Let area_id point to the list of area IDs,
1297 * which is at the end of smsg->filter. */
1298 area_id
= (uint32_t *)(&smsg
->filter
+ 1);
1300 if (*area_id
== area
->area_id
.s_addr
) {
1310 /* If area was found, then i>0 here. */
1312 /* Check msg type. */
1313 if (mask
& Power2
[OSPF_ROUTER_LSA
])
1314 LSDB_LOOP (ROUTER_LSDB(area
), rn
, lsa
)
1315 apiserver_sync_callback(
1316 lsa
, (void *)¶m
, seqnum
);
1317 if (mask
& Power2
[OSPF_NETWORK_LSA
])
1318 LSDB_LOOP (NETWORK_LSDB(area
), rn
, lsa
)
1319 apiserver_sync_callback(
1320 lsa
, (void *)¶m
, seqnum
);
1321 if (mask
& Power2
[OSPF_SUMMARY_LSA
])
1322 LSDB_LOOP (SUMMARY_LSDB(area
), rn
, lsa
)
1323 apiserver_sync_callback(
1324 lsa
, (void *)¶m
, seqnum
);
1325 if (mask
& Power2
[OSPF_ASBR_SUMMARY_LSA
])
1326 LSDB_LOOP (ASBR_SUMMARY_LSDB(area
), rn
, lsa
)
1327 apiserver_sync_callback(
1328 lsa
, (void *)¶m
, seqnum
);
1329 if (mask
& Power2
[OSPF_OPAQUE_LINK_LSA
])
1330 LSDB_LOOP (OPAQUE_LINK_LSDB(area
), rn
, lsa
)
1331 apiserver_sync_callback(
1332 lsa
, (void *)¶m
, seqnum
);
1333 if (mask
& Power2
[OSPF_OPAQUE_AREA_LSA
])
1334 LSDB_LOOP (OPAQUE_AREA_LSDB(area
), rn
, lsa
)
1335 apiserver_sync_callback(
1336 lsa
, (void *)¶m
, seqnum
);
1340 /* For AS-external LSAs */
1342 if (mask
& Power2
[OSPF_AS_EXTERNAL_LSA
])
1343 LSDB_LOOP (EXTERNAL_LSDB(ospf
), rn
, lsa
)
1344 apiserver_sync_callback(lsa
, (void *)¶m
,
1348 /* For AS-external opaque LSAs */
1350 if (mask
& Power2
[OSPF_OPAQUE_AS_LSA
])
1351 LSDB_LOOP (OPAQUE_AS_LSDB(ospf
), rn
, lsa
)
1352 apiserver_sync_callback(lsa
, (void *)¶m
,
1356 /* Send a reply back to client with return code */
1357 rc
= ospf_apiserver_send_reply(apiserv
, seqnum
, rc
);
1362 /* -----------------------------------------------------------
1363 * Followings are functions to originate or update LSA
1364 * from an application.
1365 * -----------------------------------------------------------
1368 /* Create a new internal opaque LSA by taking prototype and filling in
1369 missing fields such as age, sequence number, advertising router,
1370 checksum and so on. The interface parameter is used for type 9
1371 LSAs, area parameter for type 10. Type 11 LSAs do neither need area
1374 struct ospf_lsa
*ospf_apiserver_opaque_lsa_new(struct ospf_area
*area
,
1375 struct ospf_interface
*oi
,
1376 struct lsa_header
*protolsa
)
1379 struct lsa_header
*newlsa
;
1380 struct ospf_lsa
*new = NULL
;
1381 uint8_t options
= 0x0;
1389 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1393 /* Create a stream for internal opaque LSA */
1394 if ((s
= stream_new(OSPF_MAX_LSA_SIZE
)) == NULL
) {
1395 zlog_warn("ospf_apiserver_opaque_lsa_new: stream_new failed");
1399 newlsa
= (struct lsa_header
*)STREAM_DATA(s
);
1401 /* XXX If this is a link-local LSA or an AS-external LSA, how do we
1402 have to set options? */
1405 options
= LSA_OPTIONS_GET(area
);
1406 options
|= LSA_OPTIONS_NSSA_GET(area
);
1409 options
|= OSPF_OPTION_O
; /* Don't forget to set option bit */
1411 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
1412 zlog_debug("LSA[Type%d:%pI4]: Creating an Opaque-LSA instance",
1413 protolsa
->type
, &protolsa
->id
);
1416 /* Set opaque-LSA header fields. */
1417 lsa_header_set(s
, options
, protolsa
->type
, protolsa
->id
,
1420 /* Set opaque-LSA body fields. */
1421 stream_put(s
, ((uint8_t *)protolsa
) + sizeof(struct lsa_header
),
1422 ntohs(protolsa
->length
) - sizeof(struct lsa_header
));
1424 /* Determine length of LSA. */
1425 length
= stream_get_endp(s
);
1426 newlsa
->length
= htons(length
);
1428 /* Create OSPF LSA. */
1429 new = ospf_lsa_new_and_data(length
);
1433 new->vrf_id
= ospf
->vrf_id
;
1435 SET_FLAG(new->flags
, OSPF_LSA_SELF
);
1436 memcpy(new->data
, newlsa
, length
);
1443 int ospf_apiserver_is_ready_type9(struct ospf_interface
*oi
)
1445 /* Type 9 opaque LSA can be originated if there is at least one
1446 active opaque-capable neighbor attached to the outgoing
1449 return (ospf_nbr_count_opaque_capable(oi
) > 0);
1452 int ospf_apiserver_is_ready_type10(struct ospf_area
*area
)
1454 /* Type 10 opaque LSA can be originated if there is at least one
1455 interface belonging to the area that has an active opaque-capable
1457 struct listnode
*node
, *nnode
;
1458 struct ospf_interface
*oi
;
1460 for (ALL_LIST_ELEMENTS(area
->oiflist
, node
, nnode
, oi
))
1461 /* Is there an active neighbor attached to this interface? */
1462 if (ospf_apiserver_is_ready_type9(oi
))
1465 /* No active neighbor in area */
1469 int ospf_apiserver_is_ready_type11(struct ospf
*ospf
)
1471 /* Type 11 opaque LSA can be originated if there is at least one
1473 that has an active opaque-capable neighbor. */
1474 struct listnode
*node
, *nnode
;
1475 struct ospf_interface
*oi
;
1477 for (ALL_LIST_ELEMENTS(ospf
->oiflist
, node
, nnode
, oi
))
1478 /* Is there an active neighbor attached to this interface? */
1479 if (ospf_apiserver_is_ready_type9(oi
))
1482 /* No active neighbor at all */
1487 int ospf_apiserver_handle_originate_request(struct ospf_apiserver
*apiserv
,
1490 struct msg_originate_request
*omsg
;
1491 struct lsa_header
*data
;
1492 struct ospf_lsa
*new;
1493 struct ospf_lsa
*old
;
1494 struct ospf_area
*area
= NULL
;
1495 struct ospf_interface
*oi
= NULL
;
1496 struct ospf_lsdb
*lsdb
= NULL
;
1498 int lsa_type
, opaque_type
;
1502 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1504 /* Extract opaque LSA data from message */
1505 omsg
= (struct msg_originate_request
*)STREAM_DATA(msg
->s
);
1508 /* Determine interface for type9 or area for type10 LSAs. */
1509 switch (data
->type
) {
1510 case OSPF_OPAQUE_LINK_LSA
:
1511 oi
= ospf_apiserver_if_lookup_by_addr(omsg
->ifaddr
);
1513 zlog_warn("apiserver_originate: unknown interface %pI4",
1515 rc
= OSPF_API_NOSUCHINTERFACE
;
1521 case OSPF_OPAQUE_AREA_LSA
:
1522 area
= ospf_area_lookup_by_area_id(ospf
, omsg
->area_id
);
1524 zlog_warn("apiserver_originate: unknown area %pI4",
1526 rc
= OSPF_API_NOSUCHAREA
;
1531 case OSPF_OPAQUE_AS_LSA
:
1535 /* We can only handle opaque types here */
1537 "apiserver_originate: Cannot originate non-opaque LSA type %d",
1539 rc
= OSPF_API_ILLEGALLSATYPE
;
1543 /* Check if we registered this opaque type */
1544 lsa_type
= data
->type
;
1545 opaque_type
= GET_OPAQUE_TYPE(ntohl(data
->id
.s_addr
));
1547 if (!apiserver_is_opaque_type_registered(apiserv
, lsa_type
,
1550 "apiserver_originate: LSA-type(%d)/Opaque-type(%d): Not registered",
1551 lsa_type
, opaque_type
);
1552 rc
= OSPF_API_OPAQUETYPENOTREGISTERED
;
1556 /* Make sure that the neighbors are ready before we can originate */
1557 switch (data
->type
) {
1558 case OSPF_OPAQUE_LINK_LSA
:
1559 ready
= ospf_apiserver_is_ready_type9(oi
);
1561 case OSPF_OPAQUE_AREA_LSA
:
1562 ready
= ospf_apiserver_is_ready_type10(area
);
1564 case OSPF_OPAQUE_AS_LSA
:
1565 ready
= ospf_apiserver_is_ready_type11(ospf
);
1572 zlog_warn("Neighbors not ready to originate type %d",
1574 rc
= OSPF_API_NOTREADY
;
1578 /* Create OSPF's internal opaque LSA representation */
1579 new = ospf_apiserver_opaque_lsa_new(area
, oi
, data
);
1581 rc
= OSPF_API_NOMEMORY
; /* XXX */
1585 /* Determine if LSA is new or an update for an existing one. */
1586 old
= ospf_lsdb_lookup(lsdb
, new);
1589 /* New LSA install in LSDB. */
1590 rc
= ospf_apiserver_originate1(new);
1593 * Keep the new LSA instance in the "waiting place" until the
1595 * refresh timing. If several LSA update requests for the same
1597 * have issued by peer, the last one takes effect.
1599 new->lsdb
= &apiserv
->reserve
;
1600 ospf_lsdb_add(&apiserv
->reserve
, new);
1602 /* Kick the scheduler function. */
1603 ospf_opaque_lsa_refresh_schedule(old
);
1608 /* Send a reply back to client with return code */
1609 rc
= ospf_apiserver_send_reply(apiserv
, ntohl(msg
->hdr
.msgseq
), rc
);
1614 /* -----------------------------------------------------------
1615 * Flood an LSA within its flooding scope.
1616 * -----------------------------------------------------------
1619 /* XXX We can probably use ospf_flood_through instead of this function
1620 but then we need the neighbor parameter. If we set nbr to
1621 NULL then ospf_flood_through crashes due to dereferencing NULL. */
1623 void ospf_apiserver_flood_opaque_lsa(struct ospf_lsa
*lsa
)
1627 switch (lsa
->data
->type
) {
1628 case OSPF_OPAQUE_LINK_LSA
:
1629 /* Increment counters? XXX */
1631 /* Flood LSA through local network. */
1632 ospf_flood_through_area(lsa
->area
, NULL
/*nbr */, lsa
);
1634 case OSPF_OPAQUE_AREA_LSA
:
1635 /* Update LSA origination count. */
1637 lsa
->area
->ospf
->lsa_originate_count
++;
1639 /* Flood LSA through area. */
1640 ospf_flood_through_area(lsa
->area
, NULL
/*nbr */, lsa
);
1642 case OSPF_OPAQUE_AS_LSA
: {
1645 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1648 /* Increment counters? XXX */
1650 /* Flood LSA through AS. */
1651 ospf_flood_through_as(ospf
, NULL
/*nbr */, lsa
);
1657 int ospf_apiserver_originate1(struct ospf_lsa
*lsa
)
1661 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1664 /* Install this LSA into LSDB. */
1665 if (ospf_lsa_install(ospf
, lsa
->oi
, lsa
) == NULL
) {
1666 flog_warn(EC_OSPF_LSA_INSTALL_FAILURE
,
1667 "ospf_apiserver_originate1: ospf_lsa_install failed");
1671 /* Flood LSA within scope */
1675 * NB: Modified version of "ospf_flood_though ()" accepts NULL "inbr"
1676 * parameter, and thus it does not cause SIGSEGV error.
1678 ospf_flood_through(NULL
/*nbr */, lsa
);
1681 ospf_apiserver_flood_opaque_lsa(lsa
);
1688 /* Opaque LSAs of type 9 on a specific interface can now be
1689 originated. Tell clients that registered type 9. */
1690 int ospf_apiserver_lsa9_originator(void *arg
)
1692 struct ospf_interface
*oi
;
1694 oi
= (struct ospf_interface
*)arg
;
1695 if (listcount(apiserver_list
) > 0) {
1696 ospf_apiserver_clients_notify_ready_type9(oi
);
1701 int ospf_apiserver_lsa10_originator(void *arg
)
1703 struct ospf_area
*area
;
1705 area
= (struct ospf_area
*)arg
;
1706 if (listcount(apiserver_list
) > 0) {
1707 ospf_apiserver_clients_notify_ready_type10(area
);
1712 int ospf_apiserver_lsa11_originator(void *arg
)
1716 ospf
= (struct ospf
*)arg
;
1717 if (listcount(apiserver_list
) > 0) {
1718 ospf_apiserver_clients_notify_ready_type11(ospf
);
1724 /* Periodically refresh opaque LSAs so that they do not expire in
1726 struct ospf_lsa
*ospf_apiserver_lsa_refresher(struct ospf_lsa
*lsa
)
1728 struct ospf_apiserver
*apiserv
;
1729 struct ospf_lsa
*new = NULL
;
1734 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1737 apiserv
= lookup_apiserver_by_lsa(lsa
);
1740 "ospf_apiserver_lsa_refresher: LSA[%s]: No apiserver?",
1743 htons(OSPF_LSA_MAXAGE
); /* Flush it anyway. */
1747 if (IS_LSA_MAXAGE(lsa
)) {
1748 ospf_opaque_lsa_flush_schedule(lsa
);
1752 /* Check if updated version of LSA instance has already prepared. */
1753 new = ospf_lsdb_lookup(&apiserv
->reserve
, lsa
);
1755 /* This is a periodic refresh, driven by core OSPF mechanism. */
1756 new = ospf_apiserver_opaque_lsa_new(lsa
->area
, lsa
->oi
,
1760 "ospf_apiserver_lsa_refresher: Cannot create a new LSA?");
1764 /* This is a forcible refresh, requested by OSPF-API client. */
1765 ospf_lsdb_delete(&apiserv
->reserve
, new);
1769 /* Increment sequence number */
1770 new->data
->ls_seqnum
= lsa_seqnum_increment(lsa
);
1772 /* New LSA is in same area. */
1773 new->area
= lsa
->area
;
1774 SET_FLAG(new->flags
, OSPF_LSA_SELF
);
1776 /* Install LSA into LSDB. */
1777 if (ospf_lsa_install(ospf
, new->oi
, new) == NULL
) {
1779 EC_OSPF_LSA_INSTALL_FAILURE
,
1780 "ospf_apiserver_lsa_refresher: ospf_lsa_install failed");
1781 ospf_lsa_unlock(&new);
1785 /* Flood updated LSA through interface, area or AS */
1788 ospf_flood_through(NULL
/*nbr */, new);
1790 ospf_apiserver_flood_opaque_lsa(new);
1792 /* Debug logging. */
1793 if (IS_DEBUG_OSPF(lsa
, LSA_GENERATE
)) {
1794 zlog_debug("LSA[Type%d:%pI4]: Refresh Opaque LSA",
1795 new->data
->type
, &new->data
->id
);
1796 ospf_lsa_header_dump(new->data
);
1804 /* -----------------------------------------------------------
1805 * Followings are functions to delete LSAs
1806 * -----------------------------------------------------------
1809 int ospf_apiserver_handle_delete_request(struct ospf_apiserver
*apiserv
,
1812 struct msg_delete_request
*dmsg
;
1813 struct ospf_lsa
*old
;
1814 struct ospf_area
*area
= NULL
;
1816 int lsa_type
, opaque_type
;
1820 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1823 /* Extract opaque LSA from message */
1824 dmsg
= (struct msg_delete_request
*)STREAM_DATA(msg
->s
);
1826 /* Lookup area for link-local and area-local opaque LSAs */
1827 switch (dmsg
->lsa_type
) {
1828 case OSPF_OPAQUE_LINK_LSA
:
1829 case OSPF_OPAQUE_AREA_LSA
:
1830 area
= ospf_area_lookup_by_area_id(ospf
, dmsg
->area_id
);
1832 zlog_warn("ospf_apiserver_lsa_delete: unknown area %pI4",
1834 rc
= OSPF_API_NOSUCHAREA
;
1838 case OSPF_OPAQUE_AS_LSA
:
1839 /* AS-external opaque LSAs have no designated area */
1844 "ospf_apiserver_lsa_delete: Cannot delete non-opaque LSA type %d",
1846 rc
= OSPF_API_ILLEGALLSATYPE
;
1850 /* Check if we registered this opaque type */
1851 lsa_type
= dmsg
->lsa_type
;
1852 opaque_type
= dmsg
->opaque_type
;
1854 if (!apiserver_is_opaque_type_registered(apiserv
, lsa_type
,
1857 "ospf_apiserver_lsa_delete: LSA-type(%d)/Opaque-type(%d): Not registered",
1858 lsa_type
, opaque_type
);
1859 rc
= OSPF_API_OPAQUETYPENOTREGISTERED
;
1863 /* opaque_id is in network byte order */
1865 SET_OPAQUE_LSID(dmsg
->opaque_type
, ntohl(dmsg
->opaque_id
)));
1868 * Even if the target LSA has once scheduled to flush, it remains in
1869 * the LSDB until it is finally handled by the maxage remover thread.
1870 * Therefore, the lookup function below may return non-NULL result.
1872 old
= ospf_lsa_lookup(ospf
, area
, dmsg
->lsa_type
, id
, ospf
->router_id
);
1875 "ospf_apiserver_lsa_delete: LSA[Type%d:%pI4] not in LSDB",
1876 dmsg
->lsa_type
, &id
);
1877 rc
= OSPF_API_NOSUCHLSA
;
1881 /* Schedule flushing of LSA from LSDB */
1882 /* NB: Multiple scheduling will produce a warning message, but harmless.
1884 ospf_opaque_lsa_flush_schedule(old
);
1888 /* Send reply back to client including return code */
1889 rc
= ospf_apiserver_send_reply(apiserv
, ntohl(msg
->hdr
.msgseq
), rc
);
1893 /* Flush self-originated opaque LSA */
1894 static int apiserver_flush_opaque_type_callback(struct ospf_lsa
*lsa
,
1895 void *p_arg
, int int_arg
)
1898 struct ospf_apiserver
*apiserv
;
1900 uint8_t opaque_type
;
1906 param
= (struct param_t
*)p_arg
;
1908 /* If LSA matches type and opaque type then delete it */
1909 if (IS_LSA_SELF(lsa
) && lsa
->data
->type
== param
->lsa_type
1910 && GET_OPAQUE_TYPE(ntohl(lsa
->data
->id
.s_addr
))
1911 == param
->opaque_type
) {
1912 ospf_opaque_lsa_flush_schedule(lsa
);
1917 /* Delete self-originated opaque LSAs of a given opaque type. This
1918 function is called when an application unregisters a given opaque
1919 type or a connection to an application closes and all those opaque
1920 LSAs need to be flushed the LSDB. */
1921 void ospf_apiserver_flush_opaque_lsa(struct ospf_apiserver
*apiserv
,
1922 uint8_t lsa_type
, uint8_t opaque_type
)
1925 struct ospf_apiserver
*apiserv
;
1927 uint8_t opaque_type
;
1929 struct listnode
*node
, *nnode
;
1931 struct ospf_area
*area
;
1933 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1936 /* Set parameter struct. */
1937 param
.apiserv
= apiserv
;
1938 param
.lsa_type
= lsa_type
;
1939 param
.opaque_type
= opaque_type
;
1942 struct route_node
*rn
;
1943 struct ospf_lsa
*lsa
;
1945 case OSPF_OPAQUE_LINK_LSA
:
1946 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
))
1947 LSDB_LOOP (OPAQUE_LINK_LSDB(area
), rn
, lsa
)
1948 apiserver_flush_opaque_type_callback(
1949 lsa
, (void *)¶m
, 0);
1951 case OSPF_OPAQUE_AREA_LSA
:
1952 for (ALL_LIST_ELEMENTS(ospf
->areas
, node
, nnode
, area
))
1953 LSDB_LOOP (OPAQUE_AREA_LSDB(area
), rn
, lsa
)
1954 apiserver_flush_opaque_type_callback(
1955 lsa
, (void *)¶m
, 0);
1957 case OSPF_OPAQUE_AS_LSA
:
1958 LSDB_LOOP (OPAQUE_LINK_LSDB(ospf
), rn
, lsa
)
1959 apiserver_flush_opaque_type_callback(lsa
,
1969 /* -----------------------------------------------------------
1970 * Followings are callback functions to handle opaque types
1971 * -----------------------------------------------------------
1974 int ospf_apiserver_new_if(struct interface
*ifp
)
1976 struct ospf_interface
*oi
;
1978 /* For some strange reason it seems possible that we are invoked
1979 with an interface that has no name. This seems to happen during
1980 initialization. Return if this happens */
1982 if (ifp
->name
[0] == '\0') {
1983 /* interface has empty name */
1984 zlog_warn("ospf_apiserver_new_if: interface has no name?");
1988 /* zlog_warn for debugging */
1989 zlog_warn("ospf_apiserver_new_if");
1990 zlog_warn("ifp name=%s status=%d index=%d", ifp
->name
, ifp
->status
,
1993 if (ifp
->name
[0] == '\0') {
1994 /* interface has empty name */
1995 zlog_warn("ospf_apiserver_new_if: interface has no name?");
1999 oi
= ospf_apiserver_if_lookup_by_ifp(ifp
);
2002 /* This interface is known to Zebra but not to OSPF daemon yet.
2005 "ospf_apiserver_new_if: interface %s not known to OSPFd?",
2012 /* New interface added to OSPF, tell clients about it */
2013 if (listcount(apiserver_list
) > 0) {
2014 ospf_apiserver_clients_notify_new_if(oi
);
2019 int ospf_apiserver_del_if(struct interface
*ifp
)
2021 struct ospf_interface
*oi
;
2023 /* zlog_warn for debugging */
2024 zlog_warn("ospf_apiserver_del_if");
2025 zlog_warn("ifp name=%s status=%d index=%d", ifp
->name
, ifp
->status
,
2028 oi
= ospf_apiserver_if_lookup_by_ifp(ifp
);
2031 /* This interface is known to Zebra but not to OSPF daemon
2032 anymore. No need to tell clients about it */
2036 /* Interface deleted, tell clients about it */
2037 if (listcount(apiserver_list
) > 0) {
2038 ospf_apiserver_clients_notify_del_if(oi
);
2043 void ospf_apiserver_ism_change(struct ospf_interface
*oi
, int old_state
)
2045 /* Tell clients about interface change */
2047 /* zlog_warn for debugging */
2048 zlog_warn("ospf_apiserver_ism_change");
2049 if (listcount(apiserver_list
) > 0) {
2050 ospf_apiserver_clients_notify_ism_change(oi
);
2053 zlog_warn("oi->ifp->name=%s", oi
->ifp
->name
);
2054 zlog_warn("old_state=%d", old_state
);
2055 zlog_warn("oi->state=%d", oi
->state
);
2058 void ospf_apiserver_nsm_change(struct ospf_neighbor
*nbr
, int old_status
)
2060 /* Neighbor status changed, tell clients about it */
2061 zlog_warn("ospf_apiserver_nsm_change");
2062 if (listcount(apiserver_list
) > 0) {
2063 ospf_apiserver_clients_notify_nsm_change(nbr
);
2067 void ospf_apiserver_show_info(struct vty
*vty
, struct ospf_lsa
*lsa
)
2070 struct lsa_header header
;
2071 uint8_t data
[1]; /* opaque data have variable length. This is
2075 struct opaque_lsa
*olsa
;
2078 olsa
= (struct opaque_lsa
*)lsa
->data
;
2080 if (VALID_OPAQUE_INFO_LEN(lsa
->data
))
2081 opaquelen
= ntohs(lsa
->data
->length
) - OSPF_LSA_HEADER_SIZE
;
2085 /* Output information about opaque LSAs */
2089 " Added using OSPF API: %u octets of opaque data %s\n",
2091 VALID_OPAQUE_INFO_LEN(lsa
->data
) ? ""
2092 : "(Invalid length?)");
2093 vty_out(vty
, " Opaque data: ");
2095 for (i
= 0; i
< opaquelen
; i
++) {
2096 vty_out(vty
, "0x%x ", olsa
->data
[i
]);
2102 " Added using OSPF API: %u octets of opaque data %s",
2104 VALID_OPAQUE_INFO_LEN(lsa
->data
) ? ""
2105 : "(Invalid length?)");
2106 zlog_debug(" Opaque data: ");
2108 for (i
= 0; i
< opaquelen
; i
++) {
2109 zlog_debug("0x%x ", olsa
->data
[i
]);
2115 /* -----------------------------------------------------------
2116 * Followings are functions to notify clients about events
2117 * -----------------------------------------------------------
2120 /* Send a message to all clients. This is useful for messages
2121 that need to be notified to all clients (such as interface
2124 void ospf_apiserver_clients_notify_all(struct msg
*msg
)
2126 struct listnode
*node
, *nnode
;
2127 struct ospf_apiserver
*apiserv
;
2129 /* Send message to all clients */
2130 for (ALL_LIST_ELEMENTS(apiserver_list
, node
, nnode
, apiserv
))
2131 ospf_apiserver_send_msg(apiserv
, msg
);
2134 /* An interface is now ready to accept opaque LSAs. Notify all
2135 clients that registered to use this opaque type */
2136 void ospf_apiserver_clients_notify_ready_type9(struct ospf_interface
*oi
)
2138 struct listnode
*node
, *nnode
;
2140 struct ospf_apiserver
*apiserv
;
2144 zlog_warn("Interface has no address?");
2148 if (!ospf_apiserver_is_ready_type9(oi
)) {
2149 zlog_warn("Interface not ready for type 9?");
2153 for (ALL_LIST_ELEMENTS(apiserver_list
, node
, nnode
, apiserv
)) {
2154 struct listnode
*node2
, *nnode2
;
2155 struct registered_opaque_type
*r
;
2157 for (ALL_LIST_ELEMENTS(apiserv
->opaque_types
, node2
, nnode2
,
2159 if (r
->lsa_type
== OSPF_OPAQUE_LINK_LSA
) {
2160 msg
= new_msg_ready_notify(
2161 0, OSPF_OPAQUE_LINK_LSA
, r
->opaque_type
,
2162 oi
->address
->u
.prefix4
);
2165 "ospf_apiserver_clients_notify_ready_type9: new_msg_ready_notify failed");
2167 /* Cannot allocate new message. What
2169 ospf_apiserver_free(apiserv
);
2174 ospf_apiserver_send_msg(apiserv
, msg
);
2184 void ospf_apiserver_clients_notify_ready_type10(struct ospf_area
*area
)
2186 struct listnode
*node
, *nnode
;
2188 struct ospf_apiserver
*apiserv
;
2192 if (!ospf_apiserver_is_ready_type10(area
)) {
2193 zlog_warn("Area not ready for type 10?");
2197 for (ALL_LIST_ELEMENTS(apiserver_list
, node
, nnode
, apiserv
)) {
2198 struct listnode
*node2
, *nnode2
;
2199 struct registered_opaque_type
*r
;
2201 for (ALL_LIST_ELEMENTS(apiserv
->opaque_types
, node2
, nnode2
,
2203 if (r
->lsa_type
== OSPF_OPAQUE_AREA_LSA
) {
2204 msg
= new_msg_ready_notify(
2205 0, OSPF_OPAQUE_AREA_LSA
, r
->opaque_type
,
2209 "ospf_apiserver_clients_notify_ready_type10: new_msg_ready_nofity failed");
2211 /* Cannot allocate new message. What
2213 ospf_apiserver_free(apiserv
);
2218 ospf_apiserver_send_msg(apiserv
, msg
);
2229 void ospf_apiserver_clients_notify_ready_type11(struct ospf
*top
)
2231 struct listnode
*node
, *nnode
;
2233 struct in_addr id_null
= {.s_addr
= 0L};
2234 struct ospf_apiserver
*apiserv
;
2238 if (!ospf_apiserver_is_ready_type11(top
)) {
2239 zlog_warn("AS not ready for type 11?");
2243 for (ALL_LIST_ELEMENTS(apiserver_list
, node
, nnode
, apiserv
)) {
2244 struct listnode
*node2
, *nnode2
;
2245 struct registered_opaque_type
*r
;
2247 for (ALL_LIST_ELEMENTS(apiserv
->opaque_types
, node2
, nnode2
,
2249 if (r
->lsa_type
== OSPF_OPAQUE_AS_LSA
) {
2250 msg
= new_msg_ready_notify(
2251 0, OSPF_OPAQUE_AS_LSA
, r
->opaque_type
,
2255 "ospf_apiserver_clients_notify_ready_type11: new_msg_ready_notify failed");
2257 /* Cannot allocate new message. What
2259 ospf_apiserver_free(apiserv
);
2264 ospf_apiserver_send_msg(apiserv
, msg
);
2274 void ospf_apiserver_clients_notify_new_if(struct ospf_interface
*oi
)
2278 msg
= new_msg_new_if(0, oi
->address
->u
.prefix4
, oi
->area
->area_id
);
2280 ospf_apiserver_clients_notify_all(msg
);
2285 void ospf_apiserver_clients_notify_del_if(struct ospf_interface
*oi
)
2289 msg
= new_msg_del_if(0, oi
->address
->u
.prefix4
);
2291 ospf_apiserver_clients_notify_all(msg
);
2296 void ospf_apiserver_clients_notify_ism_change(struct ospf_interface
*oi
)
2299 struct in_addr ifaddr
= {.s_addr
= 0L};
2300 struct in_addr area_id
= {.s_addr
= 0L};
2306 ifaddr
= oi
->address
->u
.prefix4
;
2309 area_id
= oi
->area
->area_id
;
2312 msg
= new_msg_ism_change(0, ifaddr
, area_id
, oi
->state
);
2315 "apiserver_clients_notify_ism_change: msg_new failed");
2319 ospf_apiserver_clients_notify_all(msg
);
2323 void ospf_apiserver_clients_notify_nsm_change(struct ospf_neighbor
*nbr
)
2326 struct in_addr ifaddr
;
2327 struct in_addr nbraddr
;
2331 ifaddr
= nbr
->oi
->address
->u
.prefix4
;
2333 nbraddr
= nbr
->address
.u
.prefix4
;
2335 msg
= new_msg_nsm_change(0, ifaddr
, nbraddr
, nbr
->router_id
,
2339 "apiserver_clients_notify_nsm_change: msg_new failed");
2343 ospf_apiserver_clients_notify_all(msg
);
2347 static void apiserver_clients_lsa_change_notify(uint8_t msgtype
,
2348 struct ospf_lsa
*lsa
)
2351 struct listnode
*node
, *nnode
;
2352 struct ospf_apiserver
*apiserv
;
2354 /* Default area for AS-External and Opaque11 LSAs */
2355 struct in_addr area_id
= {.s_addr
= 0L};
2357 /* Default interface for non Opaque9 LSAs */
2358 struct in_addr ifaddr
= {.s_addr
= 0L};
2361 area_id
= lsa
->area
->area_id
;
2363 if (lsa
->data
->type
== OSPF_OPAQUE_LINK_LSA
) {
2365 ifaddr
= lsa
->oi
->address
->u
.prefix4
;
2368 /* Prepare message that can be sent to clients that have a matching
2370 msg
= new_msg_lsa_change_notify(msgtype
, 0L, /* no sequence number */
2372 lsa
->flags
& OSPF_LSA_SELF
, lsa
->data
);
2375 "apiserver_clients_lsa_change_notify: msg_new failed");
2379 /* Now send message to all clients with a matching filter */
2380 for (ALL_LIST_ELEMENTS(apiserver_list
, node
, nnode
, apiserv
)) {
2381 struct lsa_filter_type
*filter
;
2386 /* Check filter for this client. */
2387 filter
= apiserv
->filter
;
2389 /* Check area IDs in case of non AS-E LSAs.
2390 * If filter has areas (num_areas > 0),
2391 * then one of the areas must match the area ID of this LSA. */
2393 i
= filter
->num_areas
;
2394 if ((lsa
->data
->type
== OSPF_AS_EXTERNAL_LSA
)
2395 || (lsa
->data
->type
== OSPF_OPAQUE_AS_LSA
)) {
2400 area
= (uint32_t *)(filter
+ 1);
2402 if (*area
== area_id
.s_addr
) {
2413 /* Area match. Check LSA type. */
2414 mask
= ntohs(filter
->typemask
);
2416 if (mask
& Power2
[lsa
->data
->type
]) {
2417 /* Type also matches. Check origin. */
2418 if ((filter
->origin
== ANY_ORIGIN
)
2419 || (filter
->origin
== IS_LSA_SELF(lsa
))) {
2420 ospf_apiserver_send_msg(apiserv
, msg
);
2425 /* Free message since it is not used anymore */
2430 /* -------------------------------------------------------------
2431 * Followings are hooks invoked when LSAs are updated or deleted
2432 * -------------------------------------------------------------
2436 static int apiserver_notify_clients_lsa(uint8_t msgtype
, struct ospf_lsa
*lsa
)
2439 /* default area for AS-External and Opaque11 LSAs */
2440 struct in_addr area_id
= {.s_addr
= 0L};
2442 /* default interface for non Opaque9 LSAs */
2443 struct in_addr ifaddr
= {.s_addr
= 0L};
2445 /* Only notify this update if the LSA's age is smaller than
2446 MAXAGE. Otherwise clients would see LSA updates with max age just
2447 before they are deleted from the LSDB. LSA delete messages have
2448 MAXAGE too but should not be filtered. */
2449 if (IS_LSA_MAXAGE(lsa
) && (msgtype
== MSG_LSA_UPDATE_NOTIFY
)) {
2454 area_id
= lsa
->area
->area_id
;
2456 if (lsa
->data
->type
== OSPF_OPAQUE_LINK_LSA
) {
2457 ifaddr
= lsa
->oi
->address
->u
.prefix4
;
2459 msg
= new_msg_lsa_change_notify(msgtype
, 0L, /* no sequence number */
2461 lsa
->flags
& OSPF_LSA_SELF
, lsa
->data
);
2463 zlog_warn("notify_clients_lsa: msg_new failed");
2466 /* Notify all clients that new LSA is added/updated */
2467 apiserver_clients_lsa_change_notify(msgtype
, lsa
);
2469 /* Clients made their own copies of msg so we can free msg here */
2475 int ospf_apiserver_lsa_update(struct ospf_lsa
*lsa
)
2477 return apiserver_notify_clients_lsa(MSG_LSA_UPDATE_NOTIFY
, lsa
);
2480 int ospf_apiserver_lsa_delete(struct ospf_lsa
*lsa
)
2482 return apiserver_notify_clients_lsa(MSG_LSA_DELETE_NOTIFY
, lsa
);
2485 #endif /* SUPPORT_OSPF_API */