Merge lp:~stefan.goetz-deactivatedaccount/hipl/hidb-lsidb into lp:hipl

Proposed by Stefan Götz
Status: Merged
Approved by: Stefan Götz
Approved revision: 6250
Merged at revision: 6248
Proposed branch: lp:~stefan.goetz-deactivatedaccount/hipl/hidb-lsidb
Merge into: lp:hipl
Diff against target: 472 lines (+329/-42)
7 files modified
Makefile.am (+10/-3)
hipd/hidb.c (+4/-39)
hipd/lsidb.c (+106/-0)
hipd/lsidb.h (+43/-0)
test/check_hipd.c (+41/-0)
test/hipd/lsidb.c (+92/-0)
test/hipd/test_suites.h (+33/-0)
To merge this branch: bzr merge lp:~stefan.goetz-deactivatedaccount/hipl/hidb-lsidb
Reviewer Review Type Date Requested Status
Miika Komu Approve
Diego Biurrun Approve
René Hummen Pending
Review via email: mp+89144@code.launchpad.net

This proposal supersedes a proposal from 2012-01-17.

Description of the change

Clean up internal implementation of HIDB: introduce a dedicated container for local-scope identifiers (LSIs) and use it in the HIDB.

Reviewing the individual commits provides additional context.

Changes since the last merge proposal:

2012-01-16: rebased on trunk; no functional changes; confirmed that LSI functionality is still working as expected when accessing the local interfaces and the HIPL test servers; please comment.

2012-01-18: addressed Diego's review comments (fixed style issues and bogus UNUSED macro)

To post a comment you must log in.
Revision history for this message
René Hummen (rene-hummen) wrote : Posted in a previous version of this proposal

review needs-fixing

On 20.05.2011, at 23:27, Stefan Götz wrote:
> Stefan Götz has proposed merging lp:~stefan.goetz/hipl/hidb-lsidb into lp:hipl.
>
> Requested reviews:
> HIPL core team (hipl-core)
>
> For more details, see:
> https://code.launchpad.net/~stefan.goetz/hipl/hidb-lsidb/+merge/61833
>
> Clean up internal implementation of HIDB: introduce a dedicated container for local-scope identifiers (LSIs) and use it in the HIDB.
>
> Reviewing the individual commits provides additional context.
> --
> https://code.launchpad.net/~stefan.goetz/hipl/hidb-lsidb/+merge/61833
> Your team HIPL core team is requested to review the proposed merge of lp:~stefan.goetz/hipl/hidb-lsidb into lp:hipl.

> /* assign a free lsi address */
> - HIP_IFEL(hip_hidb_add_lsi(db, id_entry) < 0, -EEXIST, "No LSI free\n");
> + HIP_IFEL(lsidb_allocate_lsi(&id_entry->lsi) == false, -EEXIST,
> + "Unable to allocate an LSI from the LSIDB for a local host ID\n");

What happened to the hip_ prefix for functions?

Otherwise, this proposal is fine.

Ciao,
René

--
Dipl.-Inform. Rene Hummen, Ph.D. Student
Chair of Communication and Distributed Systems
RWTH Aachen University, Germany
tel: +49 241 80 20772
web: http://www.comsys.rwth-aachen.de/team/rene-hummen/

Revision history for this message
Stefan Götz (stefan.goetz-deactivatedaccount) wrote : Posted in a previous version of this proposal

Hi Rene!

Thanks for reviewing!

> What happened to the hip_ prefix for functions?

I did not use them because 1) they seem useless to me (or is there a
reason why they are necessary?) 2) there is no official policy about
using them (at least not in doc/HACKING) and 3) they are not used
consistently throughout the code anyway.

> Otherwise, this proposal is fine.

Thanks! :)

I'll work on the bugs first though

Stefan

Revision history for this message
René Hummen (rene-hummen) wrote : Posted in a previous version of this proposal

> Hi Rene!
>
> Thanks for reviewing!
>
> > What happened to the hip_ prefix for functions?
>
> I did not use them because 1) they seem useless to me (or is there a
> reason why they are necessary?)

You are right. They are not necessary in the daemons, but they must be included in the library functions.

> 2) there is no official policy about
> using them (at least not in doc/HACKING)

I will add this to the policies, once we agree that my answer to (1) is the way to go.

> and 3) they are not used
> consistently throughout the code anyway.

True, but that doesn't mean we cannot improve the code as we go on ;-)

This proposal is good to be merged.

review: Approve
Revision history for this message
René Hummen (rene-hummen) wrote : Posted in a previous version of this proposal

Oh one more thing, can you please always state in the merge proposal if and how the code has been tested. Here, a comment in the lines of "Tested BEX in VM testbed with 2 HIP hosts using HIP LSIs as end-point identifiers." would be great.

Thanks,
René

Revision history for this message
Stefan Götz (stefan.goetz-deactivatedaccount) wrote : Posted in a previous version of this proposal

Hi Rene!

[The hip_ prefix]

>> I did not use them because 1) they seem useless to me (or is there a
>> reason why they are necessary?)
>
> You are right. They are not necessary in the daemons, but they must be included in the library functions.
>
>> 2) there is no official policy about
>> using them (at least not in doc/HACKING)
>
> I will add this to the policies, once we agree that my answer to (1) is the way to go.

Hm. I'd prefer a consistent rule for the complete code base because
code tends to move between daemons and the library. Personally, I
don't think that name clashes between HIPL code and other code will
ever be a big problem which is why I'm not a big fan of hip_ (which
should be hipl_, anyway) but then that's just my gut feeling. But this
is nothing too important - I'm fine with any rule, including the one
you suggest above.

As soon as HACKING is updated, I'll update the code in my branches, too.

Stefan

Revision history for this message
Christof Mroz (christof-mroz) wrote : Posted in a previous version of this proposal

On Mon, 06 Jun 2011 09:16:25 +0200, Stefan Götz
<email address hidden> wrote:

> Hm. I'd prefer a consistent rule for the complete code base because
> code tends to move between daemons and the library. Personally, I
> don't think that name clashes between HIPL code and other code will
> ever be a big problem which is why I'm not a big fan of hip_ (which
> should be hipl_, anyway) but then that's just my gut feeling. But this
> is nothing too important - I'm fine with any rule, including the one
> you suggest above.

I ran into this issue when working on midauth in the firewall:
There's code speicific to hipd, specific to hipfw and also shared between
those (in modules/). Applying the least amount of creativity possible,
this resulted in names like (don't remember exactly)
hipfw_check_challenge_response(...) and hip_check_challenge_response(...),
for example, the former calling the latter.
Without prefixes, I could have come up with
"process_challenge_response(...)" or similar purely to avoid a name clash
of course, but I'd have to remember which verb belongs to hipfw or hipd
then every time.
Another example: main(argc,argv) parsing parameters and delegating control
to hipd_main() (or hipfw_main()), rather than "run_daemon()" or something.

That's just an annoyance of course (and you could argue that adding a
prefix every time is even more annoying). And this applies to cross-module
functions only... prefixes pose no benefit to static functions IMHO.

Revision history for this message
Diego Biurrun (diego-biurrun) wrote : Posted in a previous version of this proposal

On Fri, May 20, 2011 at 09:27:34PM +0000, Stefan Götz wrote:
> Stefan Götz has proposed merging lp:~stefan.goetz/hipl/hidb-lsidb into lp:hipl.
>
> For more details, see:
> https://code.launchpad.net/~stefan.goetz/hipl/hidb-lsidb/+merge/61833
>
> Clean up internal implementation of HIDB: introduce a dedicated
> container for local-scope identifiers (LSIs) and use it in the HIDB.

What's the status of this merge proposal?

Diego

Revision history for this message
Stefan Götz (stefan.goetz-deactivatedaccount) wrote : Posted in a previous version of this proposal

Before merging this proposal, I would like to
- add an LSI-related test to the regression test framework
- run this branch against that test and verify that it does not break things

I occasionally work on these steps and I hope to have this proposal ready by the end of the month.

Revision history for this message
Diego Biurrun (diego-biurrun) wrote : Posted in a previous version of this proposal
Download full text (3.5 KiB)

 review needs-fixing

On Tue, Jan 17, 2012 at 12:56:51PM +0000, Stefan Götz wrote:
> Stefan Götz has proposed merging lp:~stefan.goetz/hipl/hidb-lsidb into lp:hipl.

Looks mostly good, some minor issues I noticed below ...

> --- Makefile.am 2012-01-05 15:20:15 +0000
> +++ Makefile.am 2012-01-17 12:55:31 +0000
> @@ -69,10 +69,12 @@
> ### tests ###
> if HIP_UNITTESTS
> TESTS = test/check_hipfw \
> + test/check_hipd \
> test/check_lib_core \
> check_PROGRAMS = test/check_hipfw \
> + test/check_hipd \
> test/check_lib_core \
> @@ -219,6 +222,9 @@
> test/hipfw/rewrite.c \
> $(hipfw_hipfw_sources)
>
> +test_check_hipd_SOURCES = test/check_hipd.c \
> + test/hipd/lsidb.c
> +
> test_check_lib_core_SOURCES = test/check_lib_core.c \
> test/lib/core/crypto.c \
> @@ -242,6 +248,7 @@
> test_auth_performance_LDADD = lib/core/libhipcore.la
> test_check_hipfw_LDADD = lib/core/libhipcore.la
> +test_check_hipd_LDADD = lib/core/libhipcore.la
> test_check_lib_core_LDADD = lib/core/libhipcore.la

All of this in proper alphabetical order please.

> --- hipd/hidb.c 2011-12-30 23:20:44 +0000
> +++ hipd/hidb.c 2012-01-17 12:55:31 +0000
> --- hipd/lsidb.c 1970-01-01 00:00:00 +0000
> +++ hipd/lsidb.c 2012-01-17 12:55:31 +0000
> @@ -0,0 +1,106 @@
> +/*
> + * Copyright (c) 2011-2012 Aalto University and RWTH Aachen University.

Just 2012 should be enough.

> +bool lsidb_free_lsi(UNUSED const hip_lsi_t lsi)
> +{
> + /* is this a valid LSI? */
> + if ((ntohl(lsi.s_addr) & ~HIP_LSI_TYPE_MASK_CLEAR) == HIP_LSI_PREFIX) {
> + /* we currently do not support freeing the LSI */
> + return true;
> + }
> +
> + return false;
> +}

The UNUSED seems wrong ...

> --- hipd/lsidb.h 1970-01-01 00:00:00 +0000
> +++ hipd/lsidb.h 2012-01-17 12:55:31 +0000
> @@ -0,0 +1,43 @@
> +/*
> + * Copyright (c) 2011-2012 Aalto University and RWTH Aachen University.

see above

> +#ifndef HIP_HIPD_LSIDB_H
> +#define HIP_HIPD_LSIDB_H
> +
> +#endif /* HIP_HIPD_LSIDB_H */

HIPL_

> --- test/check_hipd.c 1970-01-01 00:00:00 +0000
> +++ test/check_hipd.c 2012-01-17 12:55:31 +0000
> @@ -0,0 +1,40 @@
> +/*
> + * Copyright (c) 2011-2012 Aalto University and RWTH Aachen University.

see above

> + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
> + * OTHER DEALINGS IN THE SOFTWARE.
> + */
> +#include <check.h>
> +#include <stdlib.h>

nit: leave an empty line

> --- test/hipd/lsidb.c 1970-01-01 00:00:00 +0000
> +++ test/hipd/lsidb.c 2012-01-17 12:55:31 +0000
> @@ -0,0 +1,91 @@
> +/*
> + * Copyright (c) 2011-2012 Aalto University and RWTH Aachen University.

again

> + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
> + * OTHER DEALINGS IN THE SOFTWARE.
> + */
> +#include <check.h>
> +#include <stdlib.h>

empty line

> --- test/hipd/test_suites.h 1970-01-01 00:00:00 +0000
> +++ test/hipd/test_suites.h 2012-01-17 12:55:31 +0000
> @@ -0,...

Read more...

review: Needs Fixing
Revision history for this message
Diego Biurrun (diego-biurrun) wrote :

 review approve

On Wed, Jan 18, 2012 at 09:18:28PM +0000, Stefan Götz wrote:
> Stefan Götz has proposed merging lp:~stefan.goetz/hipl/hidb-lsidb into lp:hipl.
>
> --- Makefile.am 2012-01-05 15:20:15 +0000
> +++ Makefile.am 2012-01-18 21:17:27 +0000
> @@ -1,4 +1,4 @@
> -# Copyright (c) 2010-2011 Aalto University and RWTH Aachen University.
> +# Copyright (c) 2012 Aalto University and RWTH Aachen University.

2010-2012 :)

Diego

review: Approve
6250. By Stefan Götz

Restore copyright year range

Revision history for this message
Miika Komu (miika-iki) wrote :

Works for me. Good work!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Makefile.am'
2--- Makefile.am 2012-01-05 15:20:15 +0000
3+++ Makefile.am 2012-01-19 09:28:24 +0000
4@@ -1,4 +1,4 @@
5-# Copyright (c) 2010-2011 Aalto University and RWTH Aachen University.
6+# Copyright (c) 2010-2012 Aalto University and RWTH Aachen University.
7 #
8 # Permission is hereby granted, free of charge, to any person
9 # obtaining a copy of this software and associated documentation
10@@ -68,11 +68,13 @@
11
12 ### tests ###
13 if HIP_UNITTESTS
14-TESTS = test/check_hipfw \
15+TESTS = test/check_hipd \
16+ test/check_hipfw \
17 test/check_lib_core \
18 test/check_lib_tool \
19 test/check_modules_midauth
20-check_PROGRAMS = test/check_hipfw \
21+check_PROGRAMS = test/check_hipd \
22+ test/check_hipfw \
23 test/check_lib_core \
24 test/check_lib_tool \
25 test/check_modules_midauth
26@@ -111,6 +113,7 @@
27 hipd/init.c \
28 hipd/input.c \
29 hipd/keymat.c \
30+ hipd/lsidb.c \
31 hipd/maintenance.c \
32 hipd/nat.c \
33 hipd/netdev.c \
34@@ -208,6 +211,9 @@
35 endif
36
37
38+test_check_hipd_SOURCES = test/check_hipd.c \
39+ test/hipd/lsidb.c
40+
41 test_check_hipfw_SOURCES = test/check_hipfw.c \
42 test/mocks.c \
43 test/hipfw/conntrack.c \
44@@ -241,6 +247,7 @@
45 hipd_hipd_LDADD = lib/core/libhipcore.la
46 hipfw_hipfw_LDADD = lib/core/libhipcore.la
47 test_auth_performance_LDADD = lib/core/libhipcore.la
48+test_check_hipd_LDADD = lib/core/libhipcore.la
49 test_check_hipfw_LDADD = lib/core/libhipcore.la
50 test_check_lib_core_LDADD = lib/core/libhipcore.la
51 test_check_lib_tool_LDADD = lib/core/libhipcore.la
52
53=== modified file 'hipd/hidb.c'
54--- hipd/hidb.c 2011-12-30 23:20:44 +0000
55+++ hipd/hidb.c 2012-01-19 09:28:24 +0000
56@@ -1,5 +1,5 @@
57 /*
58- * Copyright (c) 2010-2011 Aalto University and RWTH Aachen University.
59+ * Copyright (c) 2010-2012 Aalto University and RWTH Aachen University.
60 *
61 * Permission is hereby granted, free of charge, to any person
62 * obtaining a copy of this software and associated documentation
63@@ -54,6 +54,7 @@
64 #include "config.h"
65 #include "cookie.h"
66 #include "hipd.h"
67+#include "lsidb.h"
68 #include "netdev.h"
69 #include "hidb.h"
70
71@@ -61,8 +62,6 @@
72 HIP_HASHTABLE *hip_local_hostid_db = NULL;
73 #define HIP_MAX_HOST_ID_LEN 1600
74
75-static const char *lsi_addresses[] = { "1.0.0.1", "1.0.0.2", "1.0.0.3", "1.0.0.4" };
76-
77 #ifdef HAVE_EC_CRYPTO
78 /**
79 * Strips the private key component from an ECDSA-based host id.
80@@ -406,41 +405,6 @@
81 return 1;
82 }
83
84-/**
85- * Assign a free LSI to a host id entry
86- *
87- * @param db database structure
88- * @param id_entry contains an entry to the db, will contain an unsigned lsi
89- * @return zero on success, or negative error value on failure.
90- */
91-static int hidb_add_lsi(HIP_HASHTABLE *db, struct local_host_id *id_entry)
92-{
93- struct local_host_id *id_entry_aux;
94- LHASH_NODE *item;
95- hip_lsi_t lsi_aux;
96- int used_lsi, c, i;
97- int len = sizeof(lsi_addresses) / sizeof(*lsi_addresses);
98-
99- for (i = 0; i < len; i++) {
100- inet_aton(lsi_addresses[i], &lsi_aux);
101- used_lsi = 0;
102-
103- list_for_each(item, db, c) {
104- id_entry_aux = list_entry(item);
105- if (hip_lsi_are_equal(&lsi_aux, &id_entry_aux->lsi)) {
106- used_lsi = 1;
107- c = -1;
108- }
109- }
110-
111- if (!used_lsi) {
112- memcpy(&id_entry->lsi, &lsi_aux, sizeof(hip_lsi_t));
113- break;
114- }
115- }
116- return 0;
117-}
118-
119 /*
120 * Interface functions to access databases.
121 *
122@@ -507,7 +471,8 @@
123 }
124
125 /* assign a free lsi address */
126- HIP_IFEL(hidb_add_lsi(db, id_entry) < 0, -EEXIST, "No LSI free\n");
127+ HIP_IFEL(lsidb_allocate_lsi(&id_entry->lsi) == false, -EEXIST,
128+ "Unable to allocate an LSI from the LSIDB for a local host ID\n");
129
130 memcpy(lsi, &id_entry->lsi, sizeof(hip_lsi_t));
131 id_entry->insert = add;
132
133=== added file 'hipd/lsidb.c'
134--- hipd/lsidb.c 1970-01-01 00:00:00 +0000
135+++ hipd/lsidb.c 2012-01-19 09:28:24 +0000
136@@ -0,0 +1,106 @@
137+/*
138+ * Copyright (c) 2012 Aalto University and RWTH Aachen University.
139+ *
140+ * Permission is hereby granted, free of charge, to any person
141+ * obtaining a copy of this software and associated documentation
142+ * files (the "Software"), to deal in the Software without
143+ * restriction, including without limitation the rights to use,
144+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
145+ * copies of the Software, and to permit persons to whom the
146+ * Software is furnished to do so, subject to the following
147+ * conditions:
148+ *
149+ * The above copyright notice and this permission notice shall be
150+ * included in all copies or substantial portions of the Software.
151+ *
152+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
153+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
154+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
155+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
156+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
157+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
158+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
159+ * OTHER DEALINGS IN THE SOFTWARE.
160+ */
161+
162+/**
163+ * @file
164+ * Implementation of the local scope identifier (LSI) database.
165+ * The LSIDB manages which LSIs are assigned to network interfaces on the local
166+ * host and which LSIs are still available.
167+ */
168+
169+#include <netinet/in.h>
170+#include <stdbool.h>
171+
172+#include "lib/core/common.h"
173+#include "lib/core/debug.h"
174+#include "lib/core/protodefs.h"
175+#include "lsidb.h"
176+
177+static unsigned lsi_index = 1;
178+
179+/**
180+ * Allocate an unused LSI that is still available to be used on the local host.
181+ * This function merely keeps track of LSIs allocated through this interface.
182+ * It does no check the actual network interfaces or other data structures in
183+ * the HIP daemon to determine whether LSIs are in use or not.
184+ *
185+ * @param lsi Points to an LSI object that receives the LSI if this function
186+ * returns successfully.
187+ * The result of calling this function with @a lsi == @c NULL or
188+ * @a lsi not pointing to a valid LSI object is undefined.
189+ * @return This function returns true if an available LSI was successfully
190+ * allocated and stored in @a lsi.
191+ * This function returns false if no more LSIs are available on
192+ * the local host.
193+ *
194+ * @internal
195+ * The current implementation is extremely primitive and returns successively
196+ * incremented LSIs.
197+ * Freeing an LSI has no effect.
198+ * This is currently acceptable because LSIs are allocated together with host
199+ * identities when HIPD starts up and LSIs are only freed when HIPD exits.
200+ * This interface is intended to hide potentially more complex allocation
201+ * schemes, too.
202+ */
203+bool lsidb_allocate_lsi(hip_lsi_t *const lsi)
204+{
205+ HIP_ASSERT(lsi);
206+ /* the index may not be 0 because that does not lead to a valid network
207+ * address */
208+ HIP_ASSERT(lsi_index != 0);
209+
210+ /* does the index still fit into the allowed address prefix length of
211+ * LSIs (-1 because the highest address is the broadcast address) */
212+ if (lsi_index < HIP_LSI_TYPE_MASK_CLEAR) {
213+ *lsi = (hip_lsi_t) { htonl(HIP_LSI_PREFIX | lsi_index) };
214+ lsi_index++;
215+ return true;
216+ }
217+
218+ return false;
219+}
220+
221+/**
222+ * Free a previously allocated LSI so it is available to allocation again.
223+ * This function should be called only after the LSI has been de-registered
224+ * from the system is no longer in active use.
225+ *
226+ * @param lsi The LSI object to free.
227+ * @return This function returns true if @a lsi is an LSI that was
228+ * previously allocated via lsidb_allocate_lsi() and if it was
229+ * freed successfully.
230+ * This function returns false if @a lsi could not be freed and
231+ * made available through allocation again.
232+ */
233+bool lsidb_free_lsi(const hip_lsi_t lsi)
234+{
235+ /* is this a valid LSI? */
236+ if ((ntohl(lsi.s_addr) & ~HIP_LSI_TYPE_MASK_CLEAR) == HIP_LSI_PREFIX) {
237+ /* we currently do not support freeing the LSI */
238+ return true;
239+ }
240+
241+ return false;
242+}
243
244=== added file 'hipd/lsidb.h'
245--- hipd/lsidb.h 1970-01-01 00:00:00 +0000
246+++ hipd/lsidb.h 2012-01-19 09:28:24 +0000
247@@ -0,0 +1,43 @@
248+/*
249+ * Copyright (c) 2012 Aalto University and RWTH Aachen University.
250+ *
251+ * Permission is hereby granted, free of charge, to any person
252+ * obtaining a copy of this software and associated documentation
253+ * files (the "Software"), to deal in the Software without
254+ * restriction, including without limitation the rights to use,
255+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
256+ * copies of the Software, and to permit persons to whom the
257+ * Software is furnished to do so, subject to the following
258+ * conditions:
259+ *
260+ * The above copyright notice and this permission notice shall be
261+ * included in all copies or substantial portions of the Software.
262+ *
263+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
264+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
265+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
266+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
267+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
268+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
269+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
270+ * OTHER DEALINGS IN THE SOFTWARE.
271+ */
272+
273+/**
274+ * @file
275+ * Public interface of the local scope identifier (LSI) database.
276+ * The LSIDB manages which LSIs are assigned to network interfaces on the local
277+ * host and which LSIs are still available.
278+ */
279+
280+#ifndef HIPL_HIPD_LSIDB_H
281+#define HIPL_HIPD_LSIDB_H
282+
283+#include <stdbool.h>
284+
285+#include "lib/core/protodefs.h"
286+
287+bool lsidb_allocate_lsi(hip_lsi_t *const lsi);
288+bool lsidb_free_lsi(const hip_lsi_t const lsi);
289+
290+#endif /* HIPL_HIPD_LSIDB_H */
291
292=== added file 'test/check_hipd.c'
293--- test/check_hipd.c 1970-01-01 00:00:00 +0000
294+++ test/check_hipd.c 2012-01-19 09:28:24 +0000
295@@ -0,0 +1,41 @@
296+/*
297+ * Copyright (c) 2012 Aalto University and RWTH Aachen University.
298+ *
299+ * Permission is hereby granted, free of charge, to any person
300+ * obtaining a copy of this software and associated documentation
301+ * files (the "Software"), to deal in the Software without
302+ * restriction, including without limitation the rights to use,
303+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
304+ * copies of the Software, and to permit persons to whom the
305+ * Software is furnished to do so, subject to the following
306+ * conditions:
307+ *
308+ * The above copyright notice and this permission notice shall be
309+ * included in all copies or substantial portions of the Software.
310+ *
311+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
312+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
313+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
314+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
315+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
316+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
317+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
318+ * OTHER DEALINGS IN THE SOFTWARE.
319+ */
320+
321+#include <check.h>
322+#include <stdlib.h>
323+
324+#include "test/hipd/test_suites.h"
325+
326+int main(void)
327+{
328+ int number_failed;
329+ SRunner *sr = srunner_create(NULL);
330+ srunner_add_suite(sr, hipd_lsidb());
331+
332+ srunner_run_all(sr, CK_NORMAL);
333+ number_failed = srunner_ntests_failed(sr);
334+ srunner_free(sr);
335+ return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
336+}
337
338=== added directory 'test/hipd'
339=== added file 'test/hipd/lsidb.c'
340--- test/hipd/lsidb.c 1970-01-01 00:00:00 +0000
341+++ test/hipd/lsidb.c 2012-01-19 09:28:24 +0000
342@@ -0,0 +1,92 @@
343+/*
344+ * Copyright (c) 2012 Aalto University and RWTH Aachen University.
345+ *
346+ * Permission is hereby granted, free of charge, to any person
347+ * obtaining a copy of this software and associated documentation
348+ * files (the "Software"), to deal in the Software without
349+ * restriction, including without limitation the rights to use,
350+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
351+ * copies of the Software, and to permit persons to whom the
352+ * Software is furnished to do so, subject to the following
353+ * conditions:
354+ *
355+ * The above copyright notice and this permission notice shall be
356+ * included in all copies or substantial portions of the Software.
357+ *
358+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
359+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
360+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
361+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
362+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
363+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
364+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
365+ * OTHER DEALINGS IN THE SOFTWARE.
366+ */
367+
368+#include <check.h>
369+#include <stdlib.h>
370+
371+#include "hipd/lsidb.c"
372+#include "test_suites.h"
373+
374+START_TEST(test_lsidb_allocate_lsi_valid)
375+{
376+ hip_lsi_t lsi;
377+
378+ /* exhaust all available LSIs */
379+ for (unsigned i = 1; i < HIP_LSI_TYPE_MASK_CLEAR; i++) {
380+ fail_unless(lsidb_allocate_lsi(&lsi) == true, NULL);
381+ /* does the returned LSI have the correct LSI head? */
382+ fail_unless((lsi.s_addr & ntohl(HIP_LSI_TYPE_MASK_1)) != 0, NULL);
383+ /* does the returned LSI have the correct prefix? */
384+ fail_unless((lsi.s_addr & ntohl(~HIP_LSI_TYPE_MASK_CLEAR)) == ntohl(HIP_LSI_TYPE_MASK_1), NULL);
385+ }
386+
387+ /* now the allocator should return an error because there should be no
388+ * LSIs left. */
389+ fail_unless(lsidb_allocate_lsi(&lsi) == false, NULL);
390+}
391+END_TEST
392+
393+START_TEST(test_lsidb_free_lsi_valid)
394+{
395+ hip_lsi_t lsi;
396+
397+ fail_unless(lsidb_allocate_lsi(&lsi) == true, NULL);
398+ fail_unless(lsidb_free_lsi(lsi) == true, NULL);
399+}
400+END_TEST
401+
402+START_TEST(test_lsidb_free_lsi_invalid)
403+{
404+ hip_lsi_t lsi = { 0xFFFFFFFF };
405+
406+ fail_unless(lsidb_free_lsi(lsi) == false, NULL);
407+}
408+END_TEST
409+
410+#ifdef HAVE_TCASE_ADD_EXIT_TEST
411+START_TEST(test_lsidb_allocate_lsi_null)
412+{
413+ lsidb_allocate_lsi(NULL);
414+}
415+END_TEST
416+#endif /* HAVE_TCASE_ADD_EXIT_TEST */
417+
418+Suite *hipd_lsidb(void)
419+{
420+ Suite *s = suite_create("hipd/lsidb");
421+
422+ TCase *tc_core = tcase_create("Core");
423+ tcase_add_test(tc_core, test_lsidb_allocate_lsi_valid);
424+ tcase_add_test(tc_core, test_lsidb_free_lsi_valid);
425+ tcase_add_test(tc_core, test_lsidb_free_lsi_invalid);
426+ // the tcase_add_exit_test macro is only available in check 0.9.8 or later but
427+ // scratchbox uses an older version of checkc so we try to avoid this macro
428+#ifdef HAVE_TCASE_ADD_EXIT_TEST
429+ tcase_add_exit_test(tc_core, test_lsidb_allocate_lsi_null, 1);
430+#endif
431+ suite_add_tcase(s, tc_core);
432+
433+ return s;
434+}
435
436=== added file 'test/hipd/test_suites.h'
437--- test/hipd/test_suites.h 1970-01-01 00:00:00 +0000
438+++ test/hipd/test_suites.h 2012-01-19 09:28:24 +0000
439@@ -0,0 +1,33 @@
440+/*
441+ * Copyright (c) 2012 Aalto University and RWTH Aachen University.
442+ *
443+ * Permission is hereby granted, free of charge, to any person
444+ * obtaining a copy of this software and associated documentation
445+ * files (the "Software"), to deal in the Software without
446+ * restriction, including without limitation the rights to use,
447+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
448+ * copies of the Software, and to permit persons to whom the
449+ * Software is furnished to do so, subject to the following
450+ * conditions:
451+ *
452+ * The above copyright notice and this permission notice shall be
453+ * included in all copies or substantial portions of the Software.
454+ *
455+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
456+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
457+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
458+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
459+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
460+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
461+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
462+ * OTHER DEALINGS IN THE SOFTWARE.
463+ */
464+
465+#ifndef HIPL_TEST_HIPD_TEST_SUITES_H
466+#define HIPL_TEST_HIPD_TEST_SUITES_H
467+
468+#include <check.h>
469+
470+Suite *hipd_lsidb(void);
471+
472+#endif /* HIPL_TEST_HIPD_TEST_SUITES_H */

Subscribers

People subscribed via source and target branches

to all changes: