1 /*
2 *
3 * Copyright (c) 2003 The Regents of the University of California. All
4 * rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * - Neither the name of the University nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS''
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
19 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
21 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
25 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 */
30
31
32 /*
33 * liblink/conntest_client.c: A helper library for talking to the
34 * conntest daemon.
35 *
36 * $Id: conntest_client.c,v 1.8 2007-12-08 04:05:04 girod Exp $
37 */
38
39 char conntest_client_c_cvsid[] = "$Id: conntest_client.c,v 1.8 2007-12-08 04:05:04 girod Exp $";
40
41 #include <stdio.h>
42 #include <stdlib.h>
43
44 #include "libdev/status_client.h"
45 #include "link/link.h"
46 #include "link/conntest.h"
47
48
49 static void conntestlist_destroy(void *data, g_event_t *event)
50 {
51 /* free the copy of the opts that we made when the event was created */
52 free(data);
53 }
54
55
56 /* When the status client code tells us that we have new data */
57 static int conntestlist_dispatch(void *new_buffer, size_t size, void *data)
58 {
59 int retval = EVENT_RENEW;
60 conntest_opts_t *opts = (conntest_opts_t *) data;
61
62 if (size % sizeof(neigh_t)) {
63 elog(LOG_CRIT, "got corrupt neighborlist size %d!!", (int) size);
64 goto done;
65 }
66
67 if (opts->new_info)
68 retval = (opts->new_info)((neigh_t *) new_buffer, size/sizeof(neigh_t),
69 opts->data);
70
71 done:
72 return retval;
73 }
74
75
76 /*
77 * create an event that fires a user callback every time we get a new
78 * neighborlist from the conntest service
79 */
80 int g_conntest(conntest_opts_t *conntest_opts, status_client_context_t **ref)
81 {
82 int retval;
83 conntest_opts_t *opts_copy = malloc(sizeof(conntest_opts_t));
84 status_client_opts_t sc_opts = {
85 handler: conntestlist_dispatch,
86 private_data: opts_copy,
87 destroy: conntestlist_destroy
88 };
89
90 /* make sure malloc didn't fail */
91 if (opts_copy == NULL) {
92 errno = ENOMEM;
93 retval = -1;
94 goto done;
95 }
96
97 /* make sure user provided options */
98 if (conntest_opts == NULL) {
99 errno = EINVAL;
100 retval = -1;
101 goto done;
102 }
103
104 /* compute the conntest link name */
105 sc_opts.devname = link_name_s(conntest_opts->link_name, LINK_CONNTEST_SUBDEV);
106
107 /* make a copy of the conntest options */
108 *opts_copy = *conntest_opts;
109
110 /* try to open the file */
111 retval = g_status_client_full(&sc_opts, ref);
112
113 done:
114 if (retval < 0) {
115 if (opts_copy)
116 free(opts_copy);
117 }
118 return retval;
119 }
120
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.