]>
Commit | Line | Data |
---|---|---|
2d33f157 | 1 | /* |
2 | * Server side of OSPF API. | |
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 | #ifndef _OSPF_APISERVER_H | |
24 | #define _OSPF_APISERVER_H | |
25 | ||
26 | /* MTYPE definition is not reflected to "memory.h". */ | |
27 | #define MTYPE_OSPF_APISERVER MTYPE_TMP | |
28 | #define MTYPE_OSPF_APISERVER_MSGFILTER MTYPE_TMP | |
29 | ||
30 | /* List of opaque types that application registered */ | |
ac4d0be5 | 31 | struct registered_opaque_type { |
32 | u_char lsa_type; | |
33 | u_char opaque_type; | |
2d33f157 | 34 | }; |
35 | ||
36 | ||
37 | /* Server instance for each accepted client connection. */ | |
ac4d0be5 | 38 | struct ospf_apiserver { |
39 | /* Socket connections for synchronous commands and asynchronous | |
40 | notifications */ | |
41 | int fd_sync; /* synchronous requests */ | |
42 | struct sockaddr_in peer_sync; | |
43 | ||
44 | int fd_async; /* asynchronous notifications */ | |
45 | struct sockaddr_in peer_async; | |
46 | ||
47 | /* List of all opaque types that application registers to use. Using | |
48 | a single connection with the OSPF daemon, multiple | |
49 | <lsa,opaque_type> pairs can be registered. However, each | |
50 | combination can only be registered once by all applications. */ | |
51 | struct list *opaque_types; /* of type registered_opaque_type */ | |
52 | ||
53 | /* Temporary storage for LSA instances to be refreshed. */ | |
54 | struct ospf_lsdb reserve; | |
55 | ||
56 | /* filter for LSA update/delete notifies */ | |
57 | struct lsa_filter_type *filter; | |
58 | ||
59 | /* Fifo buffers for outgoing messages */ | |
60 | struct msg_fifo *out_sync_fifo; | |
61 | struct msg_fifo *out_async_fifo; | |
62 | ||
63 | /* Read and write threads */ | |
64 | struct thread *t_sync_read; | |
2d33f157 | 65 | #ifdef USE_ASYNC_READ |
ac4d0be5 | 66 | struct thread *t_async_read; |
2d33f157 | 67 | #endif /* USE_ASYNC_READ */ |
ac4d0be5 | 68 | struct thread *t_sync_write; |
69 | struct thread *t_async_write; | |
2d33f157 | 70 | }; |
71 | ||
ac4d0be5 | 72 | enum event { |
73 | OSPF_APISERVER_ACCEPT, | |
74 | OSPF_APISERVER_SYNC_READ, | |
2d33f157 | 75 | #ifdef USE_ASYNC_READ |
ac4d0be5 | 76 | OSPF_APISERVER_ASYNC_READ, |
2d33f157 | 77 | #endif /* USE_ASYNC_READ */ |
ac4d0be5 | 78 | OSPF_APISERVER_SYNC_WRITE, |
79 | OSPF_APISERVER_ASYNC_WRITE | |
2d33f157 | 80 | }; |
81 | ||
82 | /* ----------------------------------------------------------- | |
83 | * Followings are functions to manage client connections. | |
84 | * ----------------------------------------------------------- | |
85 | */ | |
86 | ||
ac4d0be5 | 87 | extern unsigned short ospf_apiserver_getport(void); |
88 | extern int ospf_apiserver_init(void); | |
89 | extern void ospf_apiserver_term(void); | |
90 | extern struct ospf_apiserver *ospf_apiserver_new(int fd_sync, int fd_async); | |
91 | extern void ospf_apiserver_free(struct ospf_apiserver *apiserv); | |
92 | extern void ospf_apiserver_event(enum event event, int fd, | |
93 | struct ospf_apiserver *apiserv); | |
94 | extern int ospf_apiserver_serv_sock_family(unsigned short port, int family); | |
95 | extern int ospf_apiserver_accept(struct thread *thread); | |
96 | extern int ospf_apiserver_read(struct thread *thread); | |
97 | extern int ospf_apiserver_sync_write(struct thread *thread); | |
98 | extern int ospf_apiserver_async_write(struct thread *thread); | |
99 | extern int ospf_apiserver_send_reply(struct ospf_apiserver *apiserv, | |
100 | u_int32_t seqnr, u_char rc); | |
2d33f157 | 101 | |
102 | /* ----------------------------------------------------------- | |
103 | * Followings are message handler functions | |
104 | * ----------------------------------------------------------- | |
105 | */ | |
106 | ||
ac4d0be5 | 107 | extern int ospf_apiserver_lsa9_originator(void *arg); |
108 | extern int ospf_apiserver_lsa10_originator(void *arg); | |
109 | extern int ospf_apiserver_lsa11_originator(void *arg); | |
110 | ||
111 | extern void ospf_apiserver_clients_notify_all(struct msg *msg); | |
112 | ||
113 | extern void | |
114 | ospf_apiserver_clients_notify_ready_type9(struct ospf_interface *oi); | |
115 | extern void ospf_apiserver_clients_notify_ready_type10(struct ospf_area *area); | |
116 | extern void ospf_apiserver_clients_notify_ready_type11(struct ospf *top); | |
117 | ||
118 | extern void ospf_apiserver_clients_notify_new_if(struct ospf_interface *oi); | |
119 | extern void ospf_apiserver_clients_notify_del_if(struct ospf_interface *oi); | |
120 | extern void ospf_apiserver_clients_notify_ism_change(struct ospf_interface *oi); | |
121 | extern void ospf_apiserver_clients_notify_nsm_change(struct ospf_neighbor *nbr); | |
122 | ||
123 | extern int ospf_apiserver_is_ready_type9(struct ospf_interface *oi); | |
124 | extern int ospf_apiserver_is_ready_type10(struct ospf_area *area); | |
125 | extern int ospf_apiserver_is_ready_type11(struct ospf *ospf); | |
126 | ||
127 | extern void ospf_apiserver_notify_ready_type9(struct ospf_apiserver *apiserv); | |
128 | extern void ospf_apiserver_notify_ready_type10(struct ospf_apiserver *apiserv); | |
129 | extern void ospf_apiserver_notify_ready_type11(struct ospf_apiserver *apiserv); | |
130 | ||
131 | extern int ospf_apiserver_handle_msg(struct ospf_apiserver *apiserv, | |
2d33f157 | 132 | struct msg *msg); |
ac4d0be5 | 133 | extern int |
134 | ospf_apiserver_handle_register_opaque_type(struct ospf_apiserver *apiserv, | |
135 | struct msg *msg); | |
136 | extern int | |
137 | ospf_apiserver_handle_unregister_opaque_type(struct ospf_apiserver *apiserv, | |
138 | struct msg *msg); | |
139 | extern int ospf_apiserver_handle_register_event(struct ospf_apiserver *apiserv, | |
140 | struct msg *msg); | |
141 | extern int | |
142 | ospf_apiserver_handle_originate_request(struct ospf_apiserver *apiserv, | |
143 | struct msg *msg); | |
144 | extern int ospf_apiserver_handle_delete_request(struct ospf_apiserver *apiserv, | |
145 | struct msg *msg); | |
146 | extern int ospf_apiserver_handle_sync_lsdb(struct ospf_apiserver *apiserv, | |
147 | struct msg *msg); | |
2d33f157 | 148 | |
149 | ||
150 | /* ----------------------------------------------------------- | |
151 | * Followings are functions for LSA origination/deletion | |
152 | * ----------------------------------------------------------- | |
153 | */ | |
154 | ||
ac4d0be5 | 155 | extern int ospf_apiserver_register_opaque_type(struct ospf_apiserver *apiserver, |
156 | u_char lsa_type, | |
157 | u_char opaque_type); | |
158 | extern int | |
159 | ospf_apiserver_unregister_opaque_type(struct ospf_apiserver *apiserver, | |
160 | u_char lsa_type, u_char opaque_type); | |
161 | extern struct ospf_lsa * | |
162 | ospf_apiserver_opaque_lsa_new(struct ospf_area *area, struct ospf_interface *oi, | |
163 | struct lsa_header *protolsa); | |
164 | extern struct ospf_interface * | |
165 | ospf_apiserver_if_lookup_by_addr(struct in_addr address); | |
166 | extern struct ospf_interface * | |
167 | ospf_apiserver_if_lookup_by_ifp(struct interface *ifp); | |
168 | extern int ospf_apiserver_originate1(struct ospf_lsa *lsa); | |
169 | extern void ospf_apiserver_flood_opaque_lsa(struct ospf_lsa *lsa); | |
2d33f157 | 170 | |
171 | ||
172 | /* ----------------------------------------------------------- | |
ac4d0be5 | 173 | * Followings are callback functions to handle opaque types |
2d33f157 | 174 | * ----------------------------------------------------------- |
175 | */ | |
176 | ||
ac4d0be5 | 177 | extern int ospf_apiserver_new_if(struct interface *ifp); |
178 | extern int ospf_apiserver_del_if(struct interface *ifp); | |
179 | extern void ospf_apiserver_ism_change(struct ospf_interface *oi, | |
180 | int old_status); | |
181 | extern void ospf_apiserver_nsm_change(struct ospf_neighbor *nbr, | |
182 | int old_status); | |
183 | extern void ospf_apiserver_config_write_router(struct vty *vty); | |
184 | extern void ospf_apiserver_config_write_if(struct vty *vty, | |
185 | struct interface *ifp); | |
186 | extern void ospf_apiserver_show_info(struct vty *vty, struct ospf_lsa *lsa); | |
187 | extern int ospf_ospf_apiserver_lsa_originator(void *arg); | |
188 | extern struct ospf_lsa *ospf_apiserver_lsa_refresher(struct ospf_lsa *lsa); | |
189 | extern void ospf_apiserver_flush_opaque_lsa(struct ospf_apiserver *apiserv, | |
190 | u_char lsa_type, | |
191 | u_char opaque_type); | |
2d33f157 | 192 | |
193 | /* ----------------------------------------------------------- | |
194 | * Followings are hooks when LSAs are updated or deleted | |
195 | * ----------------------------------------------------------- | |
196 | */ | |
197 | ||
198 | ||
199 | /* Hooks that are invoked from ospf opaque module */ | |
200 | ||
ac4d0be5 | 201 | extern int ospf_apiserver_lsa_update(struct ospf_lsa *lsa); |
202 | extern int ospf_apiserver_lsa_delete(struct ospf_lsa *lsa); | |
2d33f157 | 203 | |
ac4d0be5 | 204 | extern void ospf_apiserver_clients_lsa_change_notify(u_char msgtype, |
205 | struct ospf_lsa *lsa); | |
2d33f157 | 206 | |
207 | #endif /* _OSPF_APISERVER_H */ |