1 /*
2  * Client side of OSPF API.
3  * Copyright (C) 2001, 2002, 2003 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 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
20  */
21 
22 #ifndef _OSPF_APICLIENT_H
23 #define _OSPF_APICLIENT_H
24 
25 /* Structure for the OSPF API client */
26 struct ospf_apiclient {
27 
28 	/* Sockets for sync requests and async notifications */
29 	int fd_sync;
30 	int fd_async;
31 
32 	/* Pointer to callback functions */
33 	void (*ready_notify)(uint8_t lsa_type, uint8_t opaque_type,
34 			     struct in_addr addr);
35 	void (*new_if)(struct in_addr ifaddr, struct in_addr area_id);
36 	void (*del_if)(struct in_addr ifaddr);
37 	void (*ism_change)(struct in_addr ifaddr, struct in_addr area_id,
38 			   uint8_t status);
39 	void (*nsm_change)(struct in_addr ifaddr, struct in_addr nbraddr,
40 			   struct in_addr router_id, uint8_t status);
41 	void (*update_notify)(struct in_addr ifaddr, struct in_addr area_id,
42 			      uint8_t self_origin, struct lsa_header *lsa);
43 	void (*delete_notify)(struct in_addr ifaddr, struct in_addr area_id,
44 			      uint8_t self_origin, struct lsa_header *lsa);
45 };
46 
47 
48 /* ---------------------------------------------------------
49  * API function prototypes.
50  * --------------------------------------------------------- */
51 
52 /* Open connection to OSPF daemon. Two ports will be allocated on
53    client, sync channel at syncport and reverse channel at syncport+1 */
54 struct ospf_apiclient *ospf_apiclient_connect(char *host, int syncport);
55 
56 /* Shutdown connection to OSPF daemon. */
57 int ospf_apiclient_close(struct ospf_apiclient *oclient);
58 
59 /* Synchronous request to register opaque type. */
60 int ospf_apiclient_register_opaque_type(struct ospf_apiclient *oclient,
61 					uint8_t ltype, uint8_t otype);
62 
63 /* Synchronous request to register event mask. */
64 int ospf_apiclient_register_events(struct ospf_apiclient *oclient,
65 				   uint32_t mask);
66 
67 /* Register callback functions.*/
68 void ospf_apiclient_register_callback(
69 	struct ospf_apiclient *oclient,
70 	void (*ready_notify)(uint8_t lsa_type, uint8_t opaque_type,
71 			     struct in_addr addr),
72 	void (*new_if)(struct in_addr ifaddr, struct in_addr area_id),
73 	void (*del_if)(struct in_addr ifaddr),
74 	void (*ism_change)(struct in_addr ifaddr, struct in_addr area_id,
75 			   uint8_t status),
76 	void (*nsm_change)(struct in_addr ifaddr, struct in_addr nbraddr,
77 			   struct in_addr router_id, uint8_t status),
78 	void (*update_notify)(struct in_addr ifaddr, struct in_addr area_id,
79 			      uint8_t selforig, struct lsa_header *lsa),
80 	void (*delete_notify)(struct in_addr ifaddr, struct in_addr area_id,
81 			      uint8_t selforig, struct lsa_header *lsa));
82 
83 /* Synchronous request to synchronize LSDB. */
84 int ospf_apiclient_sync_lsdb(struct ospf_apiclient *oclient);
85 
86 /* Synchronous request to originate or update opaque LSA. */
87 int ospf_apiclient_lsa_originate(struct ospf_apiclient *oclient,
88 				 struct in_addr ifaddr, struct in_addr area_id,
89 				 uint8_t lsa_type, uint8_t opaque_type,
90 				 uint32_t opaque_id, void *opaquedata,
91 				 int opaquelen);
92 
93 
94 /* Synchronous request to delete opaque LSA. Parameter opaque_id is in
95    host byte order */
96 int ospf_apiclient_lsa_delete(struct ospf_apiclient *oclient,
97 			      struct in_addr area_id, uint8_t lsa_type,
98 			      uint8_t opaque_type, uint32_t opaque_id);
99 
100 /* Fetch async message and handle it  */
101 int ospf_apiclient_handle_async(struct ospf_apiclient *oclient);
102 
103 #endif /* _OSPF_APICLIENT_H */
104