Add an interactive mode in lookip tool, demonstrate lasting connections
[strongswan.git] / src / libcharon / plugins / lookip / lookip_listener.h
1 /*
2 * Copyright (C) 2012 Martin Willi
3 * Copyright (C) 2012 revosec AG
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 /**
17 * @defgroup lookip_listener lookip_listener
18 * @{ @ingroup lookip
19 */
20
21 #ifndef LOOKIP_LISTENER_H_
22 #define LOOKIP_LISTENER_H_
23
24 #include <bus/listeners/listener.h>
25
26 typedef struct lookip_listener_t lookip_listener_t;
27
28 /**
29 * Callback function to query virtual IP entries
30 *
31 * @param user user supplied pointer
32 * @param up TRUE if tunnels established, FALSE if closed
33 * @param vip virtual IP of remote peer
34 * @param other peer external IP
35 * @param id peer identity
36 * @param name associated connection name
37 * @return TRUE to receive more results, FALSE to cancel
38 */
39 typedef bool (*lookip_callback_t)(void *user, bool up, host_t *vip,
40 host_t *other, identification_t *id, char *name);
41
42 /**
43 * Listener collecting virtual IPs.
44 */
45 struct lookip_listener_t {
46
47 /**
48 * Implements listener_t interface.
49 */
50 listener_t listener;
51
52 /**
53 * Perform a lookup for a given virtual IP, invoke callback for matches.
54 *
55 * The "up" parameter is always TRUE when the callback is invoked using
56 * lookup().
57 *
58 * @param vip virtual IP to look up, NULL to get all entries
59 * @param cb callback function to invoke
60 * @param user user data to pass to callback function
61 * @return number of matches
62 */
63 int (*lookup)(lookip_listener_t *this, host_t *vip,
64 lookip_callback_t cb, void *user);
65
66 /**
67 * Register a listener function that gets notified about virtual IP changes.
68 *
69 * @param cb callback function to invoke
70 * @param user user data to pass to callback function
71 */
72 void (*add_listener)(lookip_listener_t *this,
73 lookip_callback_t cb, void *user);
74
75 /**
76 * Destroy a lookip_listener_t.
77 */
78 void (*destroy)(lookip_listener_t *this);
79 };
80
81 /**
82 * Create a lookip_listener instance.
83 */
84 lookip_listener_t *lookip_listener_create();
85
86 #endif /** LOOKIP_LISTENER_H_ @}*/