]> git.proxmox.com Git - mirror_frr.git/blame - ospfd/ospf_apiserver.h
ospfd: cli: add "show ip ospf reachable-routers" CLI
[mirror_frr.git] / ospfd / ospf_apiserver.h
CommitLineData
2d33f157 1/*
2 * Server side of OSPF API.
3 * Copyright (C) 2001, 2002 Ralph Keller
4 *
5 * This file is part of GNU Zebra.
896014f4 6 *
2d33f157 7 * GNU Zebra is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published
9 * by the Free Software Foundation; either version 2, or (at your
10 * option) any later version.
11 *
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
896014f4
DL
17 * You should have received a copy of the GNU General Public License along
18 * with this program; see the file COPYING; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2d33f157 20 */
21
22#ifndef _OSPF_APISERVER_H
23#define _OSPF_APISERVER_H
24
149491af
CH
25#include <zebra.h>
26#include "ospf_api.h"
27#include "ospf_lsdb.h"
28
2d33f157 29/* MTYPE definition is not reflected to "memory.h". */
30#define MTYPE_OSPF_APISERVER MTYPE_TMP
31#define MTYPE_OSPF_APISERVER_MSGFILTER MTYPE_TMP
32
33/* List of opaque types that application registered */
d62a17ae 34struct registered_opaque_type {
d7c0a89a
QY
35 uint8_t lsa_type;
36 uint8_t opaque_type;
2d33f157 37};
38
39
40/* Server instance for each accepted client connection. */
d62a17ae 41struct ospf_apiserver {
42 /* Socket connections for synchronous commands and asynchronous
43 notifications */
44 int fd_sync; /* synchronous requests */
45 struct sockaddr_in peer_sync;
46
47 int fd_async; /* asynchronous notifications */
48 struct sockaddr_in peer_async;
49
50 /* List of all opaque types that application registers to use. Using
51 a single connection with the OSPF daemon, multiple
52 <lsa,opaque_type> pairs can be registered. However, each
53 combination can only be registered once by all applications. */
54 struct list *opaque_types; /* of type registered_opaque_type */
55
56 /* Temporary storage for LSA instances to be refreshed. */
57 struct ospf_lsdb reserve;
58
149491af
CH
59 /* Sync reachable routers */
60 bool reachable_sync;
61
d62a17ae 62 /* filter for LSA update/delete notifies */
63 struct lsa_filter_type *filter;
64
65 /* Fifo buffers for outgoing messages */
66 struct msg_fifo *out_sync_fifo;
67 struct msg_fifo *out_async_fifo;
68
69 /* Read and write threads */
70 struct thread *t_sync_read;
2d33f157 71#ifdef USE_ASYNC_READ
d62a17ae 72 struct thread *t_async_read;
2d33f157 73#endif /* USE_ASYNC_READ */
d62a17ae 74 struct thread *t_sync_write;
75 struct thread *t_async_write;
2d33f157 76};
77
14416b1f 78enum ospf_apiserver_event {
d62a17ae 79 OSPF_APISERVER_ACCEPT,
80 OSPF_APISERVER_SYNC_READ,
2d33f157 81#ifdef USE_ASYNC_READ
d62a17ae 82 OSPF_APISERVER_ASYNC_READ,
2d33f157 83#endif /* USE_ASYNC_READ */
d62a17ae 84 OSPF_APISERVER_SYNC_WRITE,
85 OSPF_APISERVER_ASYNC_WRITE
2d33f157 86};
87
88/* -----------------------------------------------------------
78dfa0c7 89 * Following are functions to manage client connections.
2d33f157 90 * -----------------------------------------------------------
91 */
92
d62a17ae 93extern unsigned short ospf_apiserver_getport(void);
94extern int ospf_apiserver_init(void);
95extern void ospf_apiserver_term(void);
96extern struct ospf_apiserver *ospf_apiserver_new(int fd_sync, int fd_async);
97extern void ospf_apiserver_free(struct ospf_apiserver *apiserv);
14416b1f 98extern void ospf_apiserver_event(enum ospf_apiserver_event event, int fd,
d62a17ae 99 struct ospf_apiserver *apiserv);
100extern int ospf_apiserver_serv_sock_family(unsigned short port, int family);
cc9f21da
DS
101extern void ospf_apiserver_accept(struct thread *thread);
102extern void ospf_apiserver_read(struct thread *thread);
103extern void ospf_apiserver_sync_write(struct thread *thread);
104extern void ospf_apiserver_async_write(struct thread *thread);
d62a17ae 105extern int ospf_apiserver_send_reply(struct ospf_apiserver *apiserv,
d7c0a89a 106 uint32_t seqnr, uint8_t rc);
2d33f157 107
108/* -----------------------------------------------------------
78dfa0c7 109 * Following are message handler functions
2d33f157 110 * -----------------------------------------------------------
111 */
112
d62a17ae 113extern int ospf_apiserver_lsa9_originator(void *arg);
114extern int ospf_apiserver_lsa10_originator(void *arg);
115extern int ospf_apiserver_lsa11_originator(void *arg);
116
117extern void ospf_apiserver_clients_notify_all(struct msg *msg);
118
119extern void
120ospf_apiserver_clients_notify_ready_type9(struct ospf_interface *oi);
121extern void ospf_apiserver_clients_notify_ready_type10(struct ospf_area *area);
122extern void ospf_apiserver_clients_notify_ready_type11(struct ospf *top);
123
124extern void ospf_apiserver_clients_notify_new_if(struct ospf_interface *oi);
125extern void ospf_apiserver_clients_notify_del_if(struct ospf_interface *oi);
126extern void ospf_apiserver_clients_notify_ism_change(struct ospf_interface *oi);
127extern void ospf_apiserver_clients_notify_nsm_change(struct ospf_neighbor *nbr);
128
129extern int ospf_apiserver_is_ready_type9(struct ospf_interface *oi);
130extern int ospf_apiserver_is_ready_type10(struct ospf_area *area);
131extern int ospf_apiserver_is_ready_type11(struct ospf *ospf);
132
133extern void ospf_apiserver_notify_ready_type9(struct ospf_apiserver *apiserv);
134extern void ospf_apiserver_notify_ready_type10(struct ospf_apiserver *apiserv);
135extern void ospf_apiserver_notify_ready_type11(struct ospf_apiserver *apiserv);
136
137extern int ospf_apiserver_handle_msg(struct ospf_apiserver *apiserv,
2d33f157 138 struct msg *msg);
d62a17ae 139extern int
140ospf_apiserver_handle_register_opaque_type(struct ospf_apiserver *apiserv,
141 struct msg *msg);
142extern int
143ospf_apiserver_handle_unregister_opaque_type(struct ospf_apiserver *apiserv,
144 struct msg *msg);
145extern int ospf_apiserver_handle_register_event(struct ospf_apiserver *apiserv,
146 struct msg *msg);
147extern int
148ospf_apiserver_handle_originate_request(struct ospf_apiserver *apiserv,
149 struct msg *msg);
150extern int ospf_apiserver_handle_delete_request(struct ospf_apiserver *apiserv,
151 struct msg *msg);
152extern int ospf_apiserver_handle_sync_lsdb(struct ospf_apiserver *apiserv,
153 struct msg *msg);
149491af
CH
154extern int ospf_apiserver_handle_sync_reachable(struct ospf_apiserver *apiserv,
155 struct msg *msg);
2d33f157 156
149491af
CH
157extern void ospf_apiserver_notify_reachable(struct route_table *ort,
158 struct route_table *nrt);
2d33f157 159/* -----------------------------------------------------------
78dfa0c7 160 * Following are functions for LSA origination/deletion
2d33f157 161 * -----------------------------------------------------------
162 */
163
d62a17ae 164extern int ospf_apiserver_register_opaque_type(struct ospf_apiserver *apiserver,
d7c0a89a
QY
165 uint8_t lsa_type,
166 uint8_t opaque_type);
d62a17ae 167extern int
168ospf_apiserver_unregister_opaque_type(struct ospf_apiserver *apiserver,
d7c0a89a 169 uint8_t lsa_type, uint8_t opaque_type);
d62a17ae 170extern struct ospf_lsa *
171ospf_apiserver_opaque_lsa_new(struct ospf_area *area, struct ospf_interface *oi,
172 struct lsa_header *protolsa);
173extern struct ospf_interface *
174ospf_apiserver_if_lookup_by_addr(struct in_addr address);
175extern struct ospf_interface *
176ospf_apiserver_if_lookup_by_ifp(struct interface *ifp);
177extern int ospf_apiserver_originate1(struct ospf_lsa *lsa);
178extern void ospf_apiserver_flood_opaque_lsa(struct ospf_lsa *lsa);
2d33f157 179
180
181/* -----------------------------------------------------------
78dfa0c7 182 * Following are callback functions to handle opaque types
2d33f157 183 * -----------------------------------------------------------
184 */
185
d62a17ae 186extern int ospf_apiserver_new_if(struct interface *ifp);
187extern int ospf_apiserver_del_if(struct interface *ifp);
188extern void ospf_apiserver_ism_change(struct ospf_interface *oi,
189 int old_status);
190extern void ospf_apiserver_nsm_change(struct ospf_neighbor *nbr,
191 int old_status);
192extern void ospf_apiserver_config_write_router(struct vty *vty);
193extern void ospf_apiserver_config_write_if(struct vty *vty,
194 struct interface *ifp);
3e63092b
RW
195extern void ospf_apiserver_show_info(struct vty *vty, struct json_object *json,
196 struct ospf_lsa *lsa);
d62a17ae 197extern int ospf_ospf_apiserver_lsa_originator(void *arg);
198extern struct ospf_lsa *ospf_apiserver_lsa_refresher(struct ospf_lsa *lsa);
199extern void ospf_apiserver_flush_opaque_lsa(struct ospf_apiserver *apiserv,
d7c0a89a
QY
200 uint8_t lsa_type,
201 uint8_t opaque_type);
2d33f157 202
203/* -----------------------------------------------------------
78dfa0c7 204 * Following are hooks when LSAs are updated or deleted
2d33f157 205 * -----------------------------------------------------------
206 */
207
208
209/* Hooks that are invoked from ospf opaque module */
210
d62a17ae 211extern int ospf_apiserver_lsa_update(struct ospf_lsa *lsa);
212extern int ospf_apiserver_lsa_delete(struct ospf_lsa *lsa);
2d33f157 213
d7c0a89a 214extern void ospf_apiserver_clients_lsa_change_notify(uint8_t msgtype,
d62a17ae 215 struct ospf_lsa *lsa);
2d33f157 216
217#endif /* _OSPF_APISERVER_H */