Merge lp:~christian-roeller/hipl/whitelisting into lp:hipl

Proposed by Christian Röller on 2011-09-14
Status: Needs review
Proposed branch: lp:~christian-roeller/hipl/whitelisting
Merge into: lp:hipl
Diff against target: 712 lines (+322/-89)
8 files modified
Makefile.am (+14/-7)
hipd/input.c (+1/-1)
hipd/netdev.c (+137/-80)
hipd/netdev.h (+3/-0)
test/check_hipd.c (+41/-0)
test/hipd/netdev.c (+92/-0)
test/hipd/test_suites.h (+33/-0)
test/lib/core/hostid.c (+1/-1)
To merge this branch: bzr merge lp:~christian-roeller/hipl/whitelisting
Reviewer Review Type Date Requested Status
Stefan Götz (community) 2011-09-14 Needs Fixing on 2011-09-14
Diego Biurrun 2011-09-14 Needs Fixing on 2011-09-14
Christof Mroz 2011-09-14 Needs Fixing on 2011-09-14
René Hummen 2011-09-14 Pending
Review via email: mp+75343@code.launchpad.net

This proposal supersedes a proposal from 2011-09-13.

Description of the change

Change in the whitelisting of hipl:

The problem with the current whitelisting fuction is, that it only considers the interface-indexes. So when you for instance want to whitelist your eth0 interface, but there are also alias-interfaces for this interface on your machine, then a change for this alias-interfaces would also trigger an update, because these interfaces have the same interface-index for the kernel.

To have a more concrete possibility to whitelist interfaces, I extend the whitelist-structure with the interface-label. So that when you now whitelist your interface eth0, only changes on this interface would trigger an update and not for the alias-interfaces.

I did this by just checking for every incoming NEWADDR netlinkevent, if the corresponding label for this address is whitelisted or not.

So please have a look and just tell if you are fine with this...

To post a comment you must log in.
Stefan Götz (stefan.goetz-deactivatedaccount) wrote : Posted in a previous version of this proposal
Download full text (7.4 KiB)

Hi Christian!

Thanks for this helpful contribution! My comments below:

> > === modified file 'hipd/netdev.c'
> > --- hipd/netdev.c 2011-05-31 18:21:28 +0000
> > +++ hipd/netdev.c 2011-07-14 15:34:41 +0000
> > -static void hip_netdev_white_list_add_index(int if_index)
> > +static void hip_netdev_white_list_add_index_and_name(int if_index, const char *const device_name)

[L] cleanup: please add a 'const' modifier to the 'if_index' argument
[L] cleanup: I guess that 'if_index' cannot be less than 0. If so, it would be
nice to change its type to unsigned to communicate this fact to the caller.

> > {
> > if (hip_netdev_white_list_count < HIP_NETDEV_MAX_WHITE_LIST) {
> > - hip_netdev_white_list[hip_netdev_white_list_count++] = if_index;
> > + hip_netdev_white_list[hip_netdev_white_list_count].if_index = if_index;
> > + strncpy(hip_netdev_white_list[hip_netdev_white_list_count].if_label, device_name, IF_NAMESIZE);
[L] maintainability: it is more maintainable to use
'sizeof(hip_netdev_white_list[0].if_label)' than 'IF_NAMESIZE' because then the
size of the 'if_label' field can be changed in the struct declaration without
having to touch other code.

> > @@ -120,16 +127,18 @@
> > }
> >
> > /**
> > - * Test if the given network interface index is white listed.
> > + * Test if the given network interface index plus label is white listed.
> > *
> > * @param if_index the index of the network interface to be tested
> > + * @param device_name the label of the network interface to be tested
> > * @return 1 if the index is whitelisted or zero otherwise
> > */
> > -static int hip_netdev_is_in_white_list(int if_index)
> > +static int hip_netdev_is_in_white_list(int if_index, char *device_name)

[M] policy: please apply full const correctness to the function arguments.
[L] cleanup: it would be nice to change the type of 'if_index' to unsigned as it
can never be < 0 (I guess)

> > {
> > - int i = 0;
> > + int i;
> > for (i = 0; i < hip_netdev_white_list_count; i++) {

[L] style: you could even place the declaration of 'i' in the for() header.

> > - if (hip_netdev_white_list[i] == if_index) {
> > + if (hip_netdev_white_list[i].if_index == if_index &&
> > + !strncmp(hip_netdev_white_list[i].if_label, device_name, IF_NAMESIZE)) {

[L] maintainability: 'sizeof()' instead of 'IF_NAMESIZE', see above

> > @@ -637,7 +645,7 @@
> > HIP_IFEL(!(if_index = if_nametoindex(g_iface->ifa_name)),
> > -1, "if_nametoindex failed\n");
> > /* Check if our interface is in the whitelist */
> > - if ((hip_netdev_white_list_count > 0) && (!hip_netdev_is_in_white_list(if_index))) {
> > + if ((hip_netdev_white_list_count > 0) && (!hip_netdev_is_in_white_list(if_index, g_iface->ifa_name))) {

[L] style: just a general comment: it would make more sense to move the '> 0'
check into the 'hip_netdev_is_in_white_list()' function so the caller does not
need to have internal knowledge about the list implementation. Furthermore it's
a really silly performance optimization.

> > @@ -1125,6 +1133,55 @@
> > }
> >
> > /**
> > + * find interface label for a given ip4 or ip6 addr
...

Read more...

review: Needs Fixing
Miika Komu (miika-iki) wrote : Posted in a previous version of this proposal

Quick test report: seems to work without any troubles.

Christian Röller (christian-roeller) wrote : Posted in a previous version of this proposal
Download full text (9.2 KiB)

Once my exam is over I have finally found the time to work on your improvement suggestions...

> Hi Christian!
>
> Thanks for this helpful contribution! My comments below:
>
> > > === modified file 'hipd/netdev.c'
> > > --- hipd/netdev.c 2011-05-31 18:21:28 +0000
> > > +++ hipd/netdev.c 2011-07-14 15:34:41 +0000
> > > -static void hip_netdev_white_list_add_index(int if_index)
> > > +static void hip_netdev_white_list_add_index_and_name(int if_index, const
> char *const device_name)
>
> [L] cleanup: please add a 'const' modifier to the 'if_index' argument
> [L] cleanup: I guess that 'if_index' cannot be less than 0. If so, it would be
> nice to change its type to unsigned to communicate this fact to the caller.

Both done, you are right no reason here for dont make it unsigned and const...

>
> > > {
> > > if (hip_netdev_white_list_count < HIP_NETDEV_MAX_WHITE_LIST) {
> > > - hip_netdev_white_list[hip_netdev_white_list_count++] = if_index;
> > > + hip_netdev_white_list[hip_netdev_white_list_count].if_index =
> if_index;
> > > +
> strncpy(hip_netdev_white_list[hip_netdev_white_list_count].if_label,
> device_name, IF_NAMESIZE);
> [L] maintainability: it is more maintainable to use
> 'sizeof(hip_netdev_white_list[0].if_label)' than 'IF_NAMESIZE' because then
> the
> size of the 'if_label' field can be changed in the struct declaration without
> having to touch other code.

Good point I didnt take this into account, its changed now

>
> > > @@ -120,16 +127,18 @@
> > > }
> > >
> > > /**
> > > - * Test if the given network interface index is white listed.
> > > + * Test if the given network interface index plus label is white listed.
> > > *
> > > * @param if_index the index of the network interface to be tested
> > > + * @param device_name the label of the network interface to be tested
> > > * @return 1 if the index is whitelisted or zero otherwise
> > > */
> > > -static int hip_netdev_is_in_white_list(int if_index)
> > > +static int hip_netdev_is_in_white_list(int if_index, char *device_name)
>
> [M] policy: please apply full const correctness to the function arguments.
> [L] cleanup: it would be nice to change the type of 'if_index' to unsigned as
> it
> can never be < 0 (I guess)

Same as above, so done...

>
> > > {
> > > - int i = 0;
> > > + int i;
> > > for (i = 0; i < hip_netdev_white_list_count; i++) {
>
> [L] style: you could even place the declaration of 'i' in the for() header.

Yes I can, so I did... ;-) The actual writer did it like this, so I just adopt it...

>
> > > - if (hip_netdev_white_list[i] == if_index) {
> > > + if (hip_netdev_white_list[i].if_index == if_index &&
> > > + !strncmp(hip_netdev_white_list[i].if_label, device_name,
> IF_NAMESIZE)) {
>
> [L] maintainability: 'sizeof()' instead of 'IF_NAMESIZE', see above

Done...but I use sizeof()-1 to do not override the null-termination

>
> > > @@ -637,7 +645,7 @@
> > > HIP_IFEL(!(if_index = if_nametoindex(g_iface->ifa_name)),
> > > -1, "if_nametoindex failed\n");
> > > /* Check if our interface is in the whitelist */
> > > - if ((hip_netdev_white_list_count ...

Read more...

Stefan Götz (stefan.goetz-deactivatedaccount) wrote : Posted in a previous version of this proposal
Download full text (4.4 KiB)

Hi Christian!

Thanks for your detailed reply! I was on holidays so that's why my answer is
quite late:

>>>> - if (hip_netdev_white_list[i] == if_index) {
>>>> + if (hip_netdev_white_list[i].if_index == if_index &&
>>>> + !strncmp(hip_netdev_white_list[i].if_label, device_name,
>> IF_NAMESIZE)) {
>>
>> [L] maintainability: 'sizeof()' instead of 'IF_NAMESIZE', see above
>
> Done...but I use sizeof()-1 to do not override the null-termination

Hm - in the case of the read-only 'strncmp()' function, I'm pretty sure that you
want to check both strings to their full extent, including the null-terminating
character. Otherwise, you can get false positives with unterminated strings (I
know, that's a pathological case, but still, passing 'sizeof() - 1' to
'strncmp()' seems logically incorrect to me).

>>>> +int hip_find_label_for_address(struct sockaddr *addr, char *label)
>>
>> [M] policy: please ensure full const correctness
>
> I write to label and cast addr, so I cannot declare const, can I?

You can use 'const struct sockaddr *const addr' and cast it to 'const struct
sockaddr_in const* s4_in'. Similarly, you can use 'char *const label' as you do
not intend to or do change the pointer value.

>>>> + res = getifaddrs(&myaddrs);
>>>> + for (ifa = myaddrs; ifa != NULL; ifa = ifa->ifa_next) {
>>>> + if (ifa->ifa_addr == NULL) continue;
>>>> + if (ifa->ifa_addr->sa_family != AF_INET &&
>> ifa->ifa_addr->sa_family != AF_INET6) continue;
>>
>> [M] policy: HIPL always uses "long" if statements including braces and
>> newlines.
>> Please adhere to that style. Do you use the pre-commit hook for checking your
>> code style? I'm asking because I'm surprised that the checker does not catch
>> this.
>
> For me the statement doesnt include braces or a new line. Maybe I have changed it and forgot to commit it...maybe you can check it again...

Exactly my point: it *should* include braces and newlines but currently it does
not :-) It should read

if (ifa->ifa_addr == NULL) {
 continue;
}

etc.

>> [L] maintainability: similar to the above cases, 'sizeof(s4_in)' would be more
>> easily maintainable and more obvious to read than 'sizeof(struct
>> sockaddr_in)'.
>> The same applies to the code below.
>>
>>>> + strncpy(label, ifa->ifa_name, IF_NAMESIZE);
>>
>> [L] 'sizeof()'
>
> Both done, like described above...

Just like 'strncmp()', 'strncpy()' should use the full character array - the
code should also check that the string to copy is not longer than the given
character array - 1 or otherwise return an error from the function. Only this
combination will ensure that the string is either copied correctly or an error
is detected under all circumstances.

>>>> + freeifaddrs(myaddrs);
>>>> + return 1;
>>>> + }
>>>> + }
>>>> + if (ifa->ifa_addr->sa_family == AF_INET6) {
>>>> + s6 = (struct sockaddr_in6 *)(ifa->ifa_addr);
>>>> + if (!memcmp(s6_in, s6, sizeof(struct sockaddr_in6))) {
>>>> + strncpy(label, ifa->ifa_name, IF_NAMESIZE);
>>>> + freeifaddrs(myaddrs);
>>>> + return 1;
>>
>> [L] styl...

Read more...

Christian Röller (christian-roeller) wrote : Posted in a previous version of this proposal
Download full text (5.1 KiB)

> Hi Christian!
>
> Thanks for your detailed reply! I was on holidays so that's why my answer is
> quite late:

No problem my first reply has also taken a while due to my exam preparations ;-)

>
> >>>> - if (hip_netdev_white_list[i] == if_index) {
> >>>> + if (hip_netdev_white_list[i].if_index == if_index &&
> >>>> + !strncmp(hip_netdev_white_list[i].if_label, device_name,
> >> IF_NAMESIZE)) {
> >>
> >> [L] maintainability: 'sizeof()' instead of 'IF_NAMESIZE', see above
> >
> > Done...but I use sizeof()-1 to do not override the null-termination
>
> Hm - in the case of the read-only 'strncmp()' function, I'm pretty sure that
> you
> want to check both strings to their full extent, including the null-
> terminating
> character. Otherwise, you can get false positives with unterminated strings (I
> know, that's a pathological case, but still, passing 'sizeof() - 1' to
> 'strncmp()' seems logically incorrect to me).

Yes of course...I never did it in the code. This was just a comment at the wrong position.

>
> >>>> +int hip_find_label_for_address(struct sockaddr *addr, char *label)
> >>
> >> [M] policy: please ensure full const correctness
> >
> > I write to label and cast addr, so I cannot declare const, can I?
>
> You can use 'const struct sockaddr *const addr' and cast it to 'const struct
> sockaddr_in const* s4_in'. Similarly, you can use 'char *const label' as you
> do
> not intend to or do change the pointer value.

Yes you are right, did it.

>
> >>>> + res = getifaddrs(&myaddrs);
> >>>> + for (ifa = myaddrs; ifa != NULL; ifa = ifa->ifa_next) {
> >>>> + if (ifa->ifa_addr == NULL) continue;
> >>>> + if (ifa->ifa_addr->sa_family != AF_INET &&
> >> ifa->ifa_addr->sa_family != AF_INET6) continue;
> >>
> >> [M] policy: HIPL always uses "long" if statements including braces and
> >> newlines.
> >> Please adhere to that style. Do you use the pre-commit hook for checking
> your
> >> code style? I'm asking because I'm surprised that the checker does not
> catch
> >> this.
> >
> > For me the statement doesnt include braces or a new line. Maybe I have
> changed it and forgot to commit it...maybe you can check it again...
>
> Exactly my point: it *should* include braces and newlines but currently it
> does
> not :-) It should read
>
> if (ifa->ifa_addr == NULL) {
> continue;
> }
>
> etc.

Ah OK now I got your point...sorry ;-) I changed it

>
> >> [L] maintainability: similar to the above cases, 'sizeof(s4_in)' would be
> more
> >> easily maintainable and more obvious to read than 'sizeof(struct
> >> sockaddr_in)'.
> >> The same applies to the code below.
> >>
> >>>> + strncpy(label, ifa->ifa_name, IF_NAMESIZE);
> >>
> >> [L] 'sizeof()'
> >
> > Both done, like described above...
>
> Just like 'strncmp()', 'strncpy()' should use the full character array - the
> code should also check that the string to copy is not longer than the given
> character array - 1 or otherwise return an error from the function. Only this
> combination will ensure that the string is either copied correctly or an error
> is detected under all circumstances.

OK, I changed it in the following way:
I chec...

Read more...

Stefan Götz (stefan.goetz-deactivatedaccount) : Posted in a previous version of this proposal
review: Approve
Diego Biurrun (diego-biurrun) wrote : Posted in a previous version of this proposal

 review needs-fixing

On Thu, Jul 14, 2011 at 03:34:45PM +0000, Christian Röller wrote:
> Christian Röller has proposed merging lp:~christian-roeller/hipl/whitelisting into lp:hipl.

Formatting is messed-up. Didn't you install the uncrustify pre-commit
hook as described in doc/HACKING? Why?

Diego

review: Needs Fixing
Christian Röller (christian-roeller) wrote : Posted in a previous version of this proposal

> review needs-fixing
>
> On Thu, Jul 14, 2011 at 03:34:45PM +0000, Christian Röller wrote:
> > Christian Röller has proposed merging lp:~christian-
> roeller/hipl/whitelisting into lp:hipl.
>
> Formatting is messed-up. Didn't you install the uncrustify pre-commit
> hook as described in doc/HACKING? Why?
>
> Diego

Sorry for that, I checked now my modifications with the stylechecker and correct everything it complained about.

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

On Mon, Aug 01, 2011 at 09:19:26AM +0000, Christian Röller wrote:
> > On Thu, Jul 14, 2011 at 03:34:45PM +0000, Christian Röller wrote:
> > > Christian Röller has proposed merging lp:~christian-
> > roeller/hipl/whitelisting into lp:hipl.
> >
> > Formatting is messed-up. Didn't you install the uncrustify pre-commit
> > hook as described in doc/HACKING? Why?
>
> Sorry for that, I checked now my modifications with the stylechecker
> and correct everything it complained about.

I'm not trying to pass blame around. I want to know why some of our
processes are not working as intended, so that we can fix them.

Why were you not running uncrustify? Did you just forget to install
the hook (no big deal, we all make mistakes and we have review for a
reason) or did you not know about it? Where would we have to advertise
it so that the next newcomer is informed of its existence?

Diego

Christian Röller (christian-roeller) wrote : Posted in a previous version of this proposal

> On Mon, Aug 01, 2011 at 09:19:26AM +0000, Christian Röller wrote:
> > > On Thu, Jul 14, 2011 at 03:34:45PM +0000, Christian Röller wrote:
> > > > Christian Röller has proposed merging lp:~christian-
> > > roeller/hipl/whitelisting into lp:hipl.
> > >
> > > Formatting is messed-up. Didn't you install the uncrustify pre-commit
> > > hook as described in doc/HACKING? Why?
> >
> > Sorry for that, I checked now my modifications with the stylechecker
> > and correct everything it complained about.
>
> I'm not trying to pass blame around. I want to know why some of our
> processes are not working as intended, so that we can fix them.
>
> Why were you not running uncrustify? Did you just forget to install
> the hook (no big deal, we all make mistakes and we have review for a
> reason) or did you not know about it? Where would we have to advertise
> it so that the next newcomer is informed of its existence?
>
> Diego

I have heard that there is a hook for this, but as this is my first share,
I just forgot to install it.
So in this case it was just my fault...
But for the next newcomers, it would be nice to advertise the HACKING doc a
little bit more, because it is very helpful and I don't know about it. I just
heard about the stylechecker through the grapevine.

So sorry again and thanks for the infos...
Christian

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

On Mon, Aug 01, 2011 at 09:59:28AM +0000, Christian Röller wrote:
> > On Mon, Aug 01, 2011 at 09:19:26AM +0000, Christian Röller wrote:
> > > > On Thu, Jul 14, 2011 at 03:34:45PM +0000, Christian Röller wrote:
> > > > > Christian Röller has proposed merging lp:~christian-
> > > > roeller/hipl/whitelisting into lp:hipl.
> > > >
> > > > Formatting is messed-up. Didn't you install the uncrustify pre-commit
> > > > hook as described in doc/HACKING? Why?
> > >
> > > Sorry for that, I checked now my modifications with the stylechecker
> > > and correct everything it complained about.
> >
> > I'm not trying to pass blame around. I want to know why some of our
> > processes are not working as intended, so that we can fix them.
> >
> > Why were you not running uncrustify? Did you just forget to install
> > the hook (no big deal, we all make mistakes and we have review for a
> > reason) or did you not know about it? Where would we have to advertise
> > it so that the next newcomer is informed of its existence?
>
> I have heard that there is a hook for this, but as this is my first share,
> I just forgot to install it.
> So in this case it was just my fault...

I repeat: I'm not trying to pass blame around. Stop apologizing please.

> But for the next newcomers, it would be nice to advertise the HACKING doc a
> little bit more, because it is very helpful and I don't know about it. I just
> heard about the stylechecker through the grapevine.

I've updated INSTALL and the PISA wiki slightly. There's still room for
improvement though.

Diego

Christian Röller (christian-roeller) wrote : Posted in a previous version of this proposal

Hi,

sorry for my long absence, it was again exam-time ;-)

So I correct everything, which were mentioned. Are there more improvement suggestions or any other reasons why it should not be merged in this version?
Otherwise I would do so.
I merged it locally and as there are only a few changes in two files, it works without any trouble.
The same applies for the compiling.

Regards,
Christian

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

Diego, have your comments been tackled? If so, please approve the merge request.

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

On Wed, Aug 10, 2011 at 02:07:38PM +0000, Christian Röller wrote:
>
> So I correct everything, which were mentioned. Are there more
> improvement suggestions or any other reasons why it should not be
> merged in this version?
> Otherwise I would do so.

The general idea is that you resubmit a fixed merge proposal.

Diego

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

On Wed, Aug 10, 2011 at 02:39:35PM +0000, René Hummen wrote:
> Diego, have your comments been tackled? If so, please approve the merge request.

There was no updated merge request, so the answer is no.

Diego

Christian Röller (christian-roeller) wrote : Posted in a previous version of this proposal

> On Wed, Aug 10, 2011 at 02:39:35PM +0000, René Hummen wrote:
> > Diego, have your comments been tackled? If so, please approve the merge
> request.
>
> There was no updated merge request, so the answer is no.
>
> Diego

I correct the code style violations with revision 5987.
What do you mean with updated merge request? I answered on your needs-fixing comment and correct it.
I did the same for Stefan's needs-fixing request and he approved it.
What should I rather have done?

Christian

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

On 10.08.2011, at 17:11, Christian Röller wrote:
>> On Wed, Aug 10, 2011 at 02:39:35PM +0000, René Hummen wrote:
>>> Diego, have your comments been tackled? If so, please approve the merge
>> request.
>>
>> There was no updated merge request, so the answer is no.
>>
>> Diego
>
> I correct the code style violations with revision 5987.
> What do you mean with updated merge request? I answered on your needs-fixing comment and correct it.
> I did the same for Stefan's needs-fixing request and he approved it.
> What should I rather have done?

In the top right corner of your merge proposal page on the Launchpad website, you can follow the link "Resubmit proposal". Don't check the option to "start afresh" in order to keep the discussion history intact and for others to follow the whole conversation.

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/

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

On Wed, Aug 10, 2011 at 03:11:23PM +0000, Christian Röller wrote:
> > On Wed, Aug 10, 2011 at 02:39:35PM +0000, René Hummen wrote:
> > > Diego, have your comments been tackled? If so, please approve the merge
> > request.
> >
> > There was no updated merge request, so the answer is no.
>
> I correct the code style violations with revision 5987.
> What do you mean with updated merge request? I answered on your
> needs-fixing comment and correct it.
> I did the same for Stefan's needs-fixing request and he approved it.
> What should I rather have done?

Maybe you did fix it in your branch, but how would we know? We never
had a chance to see and review it. What you should do now is send
another merge request from your updated branch.

Diego

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

On Wed, Aug 10, 2011 at 03:28:27PM +0000, Christian Röller wrote:
> Christian Röller has proposed merging lp:~christian-roeller/hipl/whitelisting into lp:hipl.

Did you run

  make alltests
  tools/hipl_autobuild.sh

with this branch?

> --- hipd/netdev.c 2011-05-25 09:22:19 +0000
> +++ hipd/netdev.c 2011-08-10 15:28:20 +0000
> @@ -99,19 +99,26 @@
> -static void hip_netdev_white_list_add_index(int if_index)
> +static void hip_netdev_white_list_add_index_and_name(const unsigned int if_index, const char *const device_name)

Please keep lines below 80 characters where easily possible, like here.

More examples below...

> @@ -1122,6 +1131,68 @@
>
> /**
> + * This functions gives you the interface label for a given ip4 or ip6 addr.

IPv4, IPv6 address

> + * @param addr address for which you want to know the label
> + * @param label pointer where the function stores the label
> + * @return one on success, zero on error and write the label in param label

Is the label written in both cases?

> +int hip_find_label_for_address(const struct sockaddr *const addr, char *const label)
> +{
> +
> + if (addr->sa_family == AF_INET) {
> + s4_in = (const struct sockaddr_in *const) (addr);
> + }
> + if (addr->sa_family == AF_INET6) {
> + s6_in = (const struct sockaddr_in6 *const) (addr);
> + }

An else will save you a comparison here.

> + getifaddrs(&myaddrs);
> + for (ifa = myaddrs; ifa != NULL; ifa = ifa->ifa_next) {
> + if (ifa->ifa_addr == NULL) {
> + continue;
> + }
> + if (ifa->ifa_addr->sa_family != AF_INET && ifa->ifa_addr->sa_family != AF_INET6) {
> + continue;
> + }

These two could be merged.

> + if (ifa->ifa_addr->sa_family == AF_INET) {
> + s4 = (struct sockaddr_in *) (ifa->ifa_addr);

pointless ()

> + if (ifa->ifa_addr->sa_family == AF_INET6) {
> + s6 = (struct sockaddr_in6 *) (ifa->ifa_addr);

pointless ()

As above, if you use else here, you could save a comparison.

> + if (!memcmp(s4_in, s4, sizeof(s4))) {
> + if (strlen(ifa->ifa_name) <= sizeof(label) - 1) {
> + strncpy(label, ifa->ifa_name, sizeof(label) - 1);
> + res = 1;
> + } else {
> + res = 0;
> + }
> + break;

> + if (!memcmp(s6_in, s6, sizeof(s6))) {
> + if (strlen(ifa->ifa_name) <= sizeof(label) - 1) {
> + strncpy(label, ifa->ifa_name, sizeof(label) - 1);
> + res = 1;
> + } else {
> + res = 0;
> + }
> + break;

Isn't there a way to avoid this code duplication?

Diego

Diego Biurrun (diego-biurrun) : Posted in a previous version of this proposal
review: Needs Fixing
Stefan Götz (stefan.goetz-deactivatedaccount) wrote : Posted in a previous version of this proposal

Fixing Diego's comments sure won't hurt, but otherwise I'm okay with this.

review: Approve
Christian Röller (christian-roeller) wrote : Posted in a previous version of this proposal
Download full text (3.3 KiB)

> On Wed, Aug 10, 2011 at 03:28:27PM +0000, Christian Röller wrote:
> > Christian Röller has proposed merging lp:~christian-
> roeller/hipl/whitelisting into lp:hipl.
>
> Did you run
>
> make alltests
> tools/hipl_autobuild.sh

Yes I run make alltests. It seems to be OK, I get no errors and it results with "archives ready for distribution".
I am not really sure how to use the autobuild script. How and from which machine can I run this script manually to build my branch?
Can it come to problems, although make and make alltests run without ones?

>
> with this branch?
>
> > --- hipd/netdev.c 2011-05-25 09:22:19 +0000
> > +++ hipd/netdev.c 2011-08-10 15:28:20 +0000
> > @@ -99,19 +99,26 @@
> > -static void hip_netdev_white_list_add_index(int if_index)
> > +static void hip_netdev_white_list_add_index_and_name(const unsigned int
> if_index, const char *const device_name)
>
> Please keep lines below 80 characters where easily possible, like here.

Done...

>
> More examples below...
>
> > @@ -1122,6 +1131,68 @@
> >
> > /**
> > + * This functions gives you the interface label for a given ip4 or ip6
> addr.
>
> IPv4, IPv6 address

Done...

>
> > + * @param addr address for which you want to know the label
> > + * @param label pointer where the function stores the label
> > + * @return one on success, zero on error and write the label in param label
>
> Is the label written in both cases?

Done...only if the address exists in the system

>
> > +int hip_find_label_for_address(const struct sockaddr *const addr, char
> *const label)
> > +{
> > +
> > + if (addr->sa_family == AF_INET) {
> > + s4_in = (const struct sockaddr_in *const) (addr);
> > + }
> > + if (addr->sa_family == AF_INET6) {
> > + s6_in = (const struct sockaddr_in6 *const) (addr);
> > + }
>
> An else will save you a comparison here.
>
> > + getifaddrs(&myaddrs);
> > + for (ifa = myaddrs; ifa != NULL; ifa = ifa->ifa_next) {
> > + if (ifa->ifa_addr == NULL) {
> > + continue;
> > + }
> > + if (ifa->ifa_addr->sa_family != AF_INET && ifa->ifa_addr->sa_family
> != AF_INET6) {
> > + continue;
> > + }
>
> These two could be merged.
>
> > + if (ifa->ifa_addr->sa_family == AF_INET) {
> > + s4 = (struct sockaddr_in *) (ifa->ifa_addr);
>
> pointless ()
>
> > + if (ifa->ifa_addr->sa_family == AF_INET6) {
> > + s6 = (struct sockaddr_in6 *) (ifa->ifa_addr);
>
> pointless ()
>
> As above, if you use else here, you could save a comparison.
>
> > + if (!memcmp(s4_in, s4, sizeof(s4))) {
> > + if (strlen(ifa->ifa_name) <= sizeof(label) - 1) {
> > + strncpy(label, ifa->ifa_name, sizeof(label) - 1);
> > + res = 1;
> > + } else {
> > + res = 0;
> > + }
> > + break;
>
> > + if (!memcmp(s6_in, s6, sizeof(s6))) {
> > + if (strlen(ifa->ifa_name) <= sizeof(label) - 1) {
> > + strncpy(label, ifa->ifa_name, sizeof(label) - 1);
> > + res = 1;
> > + } else {
> > + ...

Read more...

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

On Thu, Aug 11, 2011 at 11:47:26AM +0000, Christian Röller wrote:
> > On Wed, Aug 10, 2011 at 03:28:27PM +0000, Christian Röller wrote:
> > > Christian Röller has proposed merging lp:~christian-
> > roeller/hipl/whitelisting into lp:hipl.
> >
> > Did you run
> >
> > make alltests
> > tools/hipl_autobuild.sh
>
> Yes I run make alltests. It seems to be OK, I get no errors and it
> results with "archives ready for distribution". I am not really sure
> how to use the autobuild script. How and from which machine can I run
> this script manually to build my branch?

Did you try running or reading the script?

> Can it come to problems, although make and make alltests run without ones?

Yes.

Diego

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

 review needs-fixing

On Thu, Aug 11, 2011 at 11:48:47AM +0000, Christian Röller wrote:
> Christian Röller has proposed merging lp:~christian-roeller/hipl/whitelisting into lp:hipl.
>
> --- hipd/netdev.c 2011-05-25 09:22:19 +0000
> +++ hipd/netdev.c 2011-08-11 11:48:38 +0000
> @@ -99,19 +99,27 @@
> if (hip_netdev_white_list_count < HIP_NETDEV_MAX_WHITE_LIST) {
> - hip_netdev_white_list[hip_netdev_white_list_count++] = if_index;
> + hip_netdev_white_list[hip_netdev_white_list_count].if_index = if_index;
> + strncpy(hip_netdev_white_list[hip_netdev_white_list_count].if_label, device_name, sizeof(hip_netdev_white_list[0].if_label) - 1);

This is an opportunity for breaking a line, as is

> @@ -119,17 +127,20 @@
>
> -static int hip_netdev_is_in_white_list(int if_index)
> +static int hip_netdev_is_in_white_list(const unsigned int if_index, const char *const device_name)

this one

> + if (hip_netdev_white_list_count > 0) {
> + for (unsigned int i = 0; i < hip_netdev_white_list_count; i++) {
> + if (hip_netdev_white_list[i].if_index == if_index &&
> + !strncmp(hip_netdev_white_list[i].if_label, device_name, sizeof(hip_netdev_white_list[0].if_label))) {

and this one.

> @@ -1122,6 +1132,40 @@
>
> /**
> + * This functions gives you the interface label for a given IPv4 or IPv6 address.

This sentence explains why starting a sentence with "this sentence" is
redundant and weird.

> + * @param addr address for which you want to know the label
> + * @param label pointer where the function stores the label
> + * @return one on success, zero on error and write the label in param label
> + * if the given addr exists in the system

address

The usual convention is to return zero on success, not one.

> +int hip_find_label_for_address(const struct sockaddr *const addr, char *const label)

long line

> +{
> + int res = 0;
> + struct ifaddrs *myaddrs, *ifa = NULL;
> +
> + getifaddrs(&myaddrs);
> + for (ifa = myaddrs; ifa != NULL; ifa = ifa->ifa_next) {
> + if (ifa->ifa_addr == NULL ||
> + (ifa->ifa_addr->sa_family != AF_INET && ifa->ifa_addr->sa_family != AF_INET6)) {

long line

> @@ -1213,6 +1252,18 @@
>
> + /* find interface label for address and check if it is whitelisted or not */
> + if (is_add) {
> + char label[IF_NAMESIZE];
> + if (hip_find_label_for_address(addr, label)) {
> + if ((!hip_netdev_is_in_white_list(ifa->ifa_index, label))) {
> + HIP_DEBUG("Interface:<%s> is not whitelisted\n", label);
> + continue;

The conditions can be merged.

> --- hipd/netdev.h 2011-05-18 15:12:07 +0000
> +++ hipd/netdev.h 2011-08-11 11:48:38 +0000
> @@ -56,4 +56,6 @@
>
> +int hip_find_label_for_address(const struct sockaddr *const addr, char *const label);

long line

Diego

review: Needs Fixing
Christian Röller (christian-roeller) wrote : Posted in a previous version of this proposal
Download full text (3.2 KiB)

> review needs-fixing
>
> On Thu, Aug 11, 2011 at 11:48:47AM +0000, Christian Röller wrote:
> > Christian Röller has proposed merging lp:~christian-
> roeller/hipl/whitelisting into lp:hipl.
> >
> > --- hipd/netdev.c 2011-05-25 09:22:19 +0000
> > +++ hipd/netdev.c 2011-08-11 11:48:38 +0000
> > @@ -99,19 +99,27 @@
> > if (hip_netdev_white_list_count < HIP_NETDEV_MAX_WHITE_LIST) {
> > - hip_netdev_white_list[hip_netdev_white_list_count++] = if_index;
> > + hip_netdev_white_list[hip_netdev_white_list_count].if_index =
> if_index;
> > +
> strncpy(hip_netdev_white_list[hip_netdev_white_list_count].if_label,
> device_name, sizeof(hip_netdev_white_list[0].if_label) - 1);
>
> This is an opportunity for breaking a line, as is
>
> > @@ -119,17 +127,20 @@
> >
> > -static int hip_netdev_is_in_white_list(int if_index)
> > +static int hip_netdev_is_in_white_list(const unsigned int if_index, const
> char *const device_name)
>
> this one
>
> > + if (hip_netdev_white_list_count > 0) {
> > + for (unsigned int i = 0; i < hip_netdev_white_list_count; i++) {
> > + if (hip_netdev_white_list[i].if_index == if_index &&
> > + !strncmp(hip_netdev_white_list[i].if_label, device_name,
> sizeof(hip_netdev_white_list[0].if_label))) {
>
> and this one.
>
> > @@ -1122,6 +1132,40 @@
> >
> > /**
> > + * This functions gives you the interface label for a given IPv4 or IPv6
> address.
>
> This sentence explains why starting a sentence with "this sentence" is
> redundant and weird.
>
> > + * @param addr address for which you want to know the label
> > + * @param label pointer where the function stores the label
> > + * @return one on success, zero on error and write the label in param label
> > + * if the given addr exists in the system
>
> address
>
> The usual convention is to return zero on success, not one.
>
> > +int hip_find_label_for_address(const struct sockaddr *const addr, char
> *const label)
>
> long line
>
> > +{
> > + int res = 0;
> > + struct ifaddrs *myaddrs, *ifa = NULL;
> > +
> > + getifaddrs(&myaddrs);
> > + for (ifa = myaddrs; ifa != NULL; ifa = ifa->ifa_next) {
> > + if (ifa->ifa_addr == NULL ||
> > + (ifa->ifa_addr->sa_family != AF_INET &&
> ifa->ifa_addr->sa_family != AF_INET6)) {
>
> long line
>
> > @@ -1213,6 +1252,18 @@
> >
> > + /* find interface label for address and check if it is
> whitelisted or not */
> > + if (is_add) {
> > + char label[IF_NAMESIZE];
> > + if (hip_find_label_for_address(addr, label)) {
> > + if ((!hip_netdev_is_in_white_list(ifa->ifa_index,
> label))) {
> > + HIP_DEBUG("Interface:<%s> is not whitelisted\n",
> label);
> > + continue;
>
> The conditions can be merged.
>
> > --- hipd/netdev.h 2011-05-18 15:12:07 +0000
> > +++ hipd/netdev.h 2011-08-11 11:48:38 +0000
> > @@ -56,4 +56,6 @@
> >
> > +int hip_find_label_for_address(const struct sockaddr *const addr, char
> *const label);
>
> long line
>
> Diego

Everything done...
I also adapt the autobuild script to my local system conditi...

Read more...

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

Hi Christian!

Sorry for coming back late with required fixes :-(

> /**
> + * Gives you the interface label for a given IPv4 or IPv6 address.
> + *
> + * @param addr address for which you want to know the label
> + * @param label pointer where the function stores the label
> + * @return zero on success, one on error and write the label in param label
> + * if the given address exists in the system
> + */
> +int hip_find_label_for_address(const struct sockaddr *const addr,
> + char *const label)

[M] safety: this function is not very safe in how it handles the length of the memory buffer pointed to by 'label'. Please either document clearly how large the memory buffer needs to be and what happens if it is not or add code that helps to avoid buffer overflows here.

[M] policy: since this is a new function, it needs to be checked by a unit test. I know it's a PITA but unit tests, for example, immediately point to such issues as the memory buffer handling.

Regards,
 Stefan

review: Needs Fixing
Christian Röller (christian-roeller) wrote : Posted in a previous version of this proposal

> Hi Christian!

Hi

>
> Sorry for coming back late with required fixes :-(

no problem...

>
> > /**
> > + * Gives you the interface label for a given IPv4 or IPv6 address.
> > + *
> > + * @param addr address for which you want to know the label
> > + * @param label pointer where the function stores the label
> > + * @return zero on success, one on error and write the label in param label
> > + * if the given address exists in the system
> > + */
> > +int hip_find_label_for_address(const struct sockaddr *const addr,
> > + char *const label)
>
> [M] safety: this function is not very safe in how it handles the length of the
> memory buffer pointed to by 'label'. Please either document clearly how large
> the memory buffer needs to be and what happens if it is not or add code that
> helps to avoid buffer overflows here.

What is exactly the safety problem here? Do you mean I should additionally mention that label
sould be at least as big as IF_NAMESIZE, so that every possible interfacelabel length would fit?
Because right now I check whether the found interfacelabel is not bigger than the associated memory for label. And only if this is the case I will write to label. And I never write more than sizeof(label) bytes to label. Is this not enough to avoid a buffer overflow?
Right now the function will just return 1 if label would be to small. Maybe I should introduce here a special return value to make the debugging easier for the caller. What do you think?

>
> [M] policy: since this is a new function, it needs to be checked by a unit
> test. I know it's a PITA but unit tests, for example, immediately point to
> such issues as the memory buffer handling.
>
> Regards,
> Stefan

Christian

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

Hi Christian!

> > > +int hip_find_label_for_address(const struct sockaddr *const addr,
> > > + char *const label)
> >
> > [M] safety: this function is not very safe in how it handles the length of
[...]
>
> What is exactly the safety problem here?

Nothing - sorry, I simply misread the code.

Stefan

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

 review needs-fixing

On Mon, Aug 22, 2011 at 11:47:44AM +0000, Christian Röller wrote:
> Christian Röller has proposed merging lp:~christian-roeller/hipl/whitelisting into lp:hipl.

The word is "whitelist", not "white list". This is not exactly very
important, but since you are changing some parts of it, you might fix it
on the lines you are touching anyway.

> --- hipd/netdev.c 2011-08-15 14:11:56 +0000
> +++ hipd/netdev.c 2011-08-22 11:47:21 +0000
> @@ -97,19 +97,28 @@
> -static int hip_netdev_white_list[HIP_NETDEV_MAX_WHITE_LIST];
> -static int hip_netdev_white_list_count = 0;
> +struct hip_netdev_whiteliste_entry {
> + unsigned int if_index;
> + char if_label[IF_NAMESIZE];
> +};
> +static struct hip_netdev_whiteliste_entry hip_netdev_white_list[HIP_NETDEV_MAX_WHITE_LIST];
> +static unsigned int hip_netdev_white_list_count = 0;

whitelist, not whitelistE

> /**
> - * Add a network interface index number to the list of white listed
> + * Add a network interface index number plus label to the list of white listed

whitelisted

> * @param if_index the network interface index to be white listed
> + * @param device_name the network interface label to be white listed

whitelisted

> */
> -static void hip_netdev_white_list_add_index(int if_index)
> +static void hip_netdev_white_list_add_index_and_name(const unsigned int if_index,
> + const char *const device_name)

whitelist

> @@ -117,17 +126,22 @@
>
> /**
> - * Test if the given network interface index is white listed.
> + * Test if the given network interface index plus label is white listed.

whitelisted

> @@ -1120,6 +1133,40 @@
>
> /**
> + * Gives you the interface label for a given IPv4 or IPv6 address.
> + *
> + * @param addr address for which you want to know the label
> + * @param label pointer where the function stores the label

nit: please vertically align the descriptions.

Diego

review: Needs Fixing
Christian Röller (christian-roeller) wrote : Posted in a previous version of this proposal

> review needs-fixing
>
> On Mon, Aug 22, 2011 at 11:47:44AM +0000, Christian Röller wrote:
> > Christian Röller has proposed merging lp:~christian-
> roeller/hipl/whitelisting into lp:hipl.
>
> The word is "whitelist", not "white list". This is not exactly very
> important, but since you are changing some parts of it, you might fix it
> on the lines you are touching anyway.
>
> > --- hipd/netdev.c 2011-08-15 14:11:56 +0000
> > +++ hipd/netdev.c 2011-08-22 11:47:21 +0000
> > @@ -97,19 +97,28 @@
> > -static int hip_netdev_white_list[HIP_NETDEV_MAX_WHITE_LIST];
> > -static int hip_netdev_white_list_count = 0;
> > +struct hip_netdev_whiteliste_entry {
> > + unsigned int if_index;
> > + char if_label[IF_NAMESIZE];
> > +};
> > +static struct hip_netdev_whiteliste_entry
> hip_netdev_white_list[HIP_NETDEV_MAX_WHITE_LIST];
> > +static unsigned int hip_netdev_white_list_count = 0;
>
> whitelist, not whitelistE
>
> > /**
> > - * Add a network interface index number to the list of white listed
> > + * Add a network interface index number plus label to the list of white
> listed
>
> whitelisted
>
> > * @param if_index the network interface index to be white listed
> > + * @param device_name the network interface label to be white listed
>
> whitelisted
>
> > */
> > -static void hip_netdev_white_list_add_index(int if_index)
> > +static void hip_netdev_white_list_add_index_and_name(const unsigned int
> if_index,
> > + const char *const
> device_name)
>
> whitelist
>
> > @@ -117,17 +126,22 @@
> >
> > /**
> > - * Test if the given network interface index is white listed.
> > + * Test if the given network interface index plus label is white listed.
>
> whitelisted
>
> > @@ -1120,6 +1133,40 @@
> >
> > /**
> > + * Gives you the interface label for a given IPv4 or IPv6 address.
> > + *
> > + * @param addr address for which you want to know the label
> > + * @param label pointer where the function stores the label
>
> nit: please vertically align the descriptions.
>
> Diego

Correct the typos...

Christian

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

 review approve

On Mon, Aug 22, 2011 at 07:05:35PM +0000, Christian Röller wrote:
> Christian Röller has proposed merging lp:~christian-roeller/hipl/whitelisting into lp:hipl.
>
> --- hipd/netdev.c 2011-08-15 14:11:56 +0000
> +++ hipd/netdev.c 2011-08-22 19:05:27 +0000
> @@ -1120,6 +1133,40 @@
> }
>
> /**
> + * Gives you the interface label for a given IPv4 or IPv6 address.
> + *
> + * @param addr address for which you want to know the label
> + * @param label pointer where the function stores the label
> + * @return zero on success, one on error and write the label
> + * in param label if the given address exists in the system

What I tried to suggest here was that you could vertically align the
descriptions, i.e.

  * @param addr address for which you want to know the label
  * @param label pointer where the function stores the label

Witness how "address" and "pointer" start on the same column.
Feel free to implement or ignore this nitpick at your discretion.

Diego

review: Approve
René Hummen (rene-hummen) wrote : Posted in a previous version of this proposal
Download full text (3.5 KiB)

Hi,

I just got one issue that was raised by Stefan before, but has not been fixed so far (more inline).

On 22.08.2011, at 21:05, Christian Röller wrote:
> Christian Röller has proposed merging lp:~christian-roeller/hipl/whitelisting into lp:hipl.
>
> Requested reviews:
> Stefan Götz (stefan.goetz)
> Diego Biurrun (diego-biurrun)
>
> For more details, see:
> https://code.launchpad.net/~christian-roeller/hipl/whitelisting/+merge/72487

> /**
> - * Add a network interface index number to the list of white listed
> + * Add a network interface index number plus label to the list of whitelisted
> * network interfaces.
> *
> - * @param if_index the network interface index to be white listed
> + * @param if_index the network interface index to be whitelisted
> + * @param device_name the network interface label to be whitelisted
> */
> -static void hip_netdev_white_list_add_index(int if_index)
> +static void hip_netdev_white_list_add_index_and_name(const unsigned int if_index,
> + const char *const device_name)
> {
> if (hip_netdev_white_list_count < HIP_NETDEV_MAX_WHITE_LIST) {
> - hip_netdev_white_list[hip_netdev_white_list_count++] = if_index;
> + hip_netdev_white_list[hip_netdev_white_list_count].if_index = if_index;
> + strncpy(hip_netdev_white_list[hip_netdev_white_list_count].if_label,
> + device_name, sizeof(hip_netdev_white_list[0].if_label) - 1);

Why don't you strncpy the complete sizeof? Either the string is null-terminated, in which case you should copy the 0 as well, or it is not, in which case you will miss the last letter of the label. What happens with label is of length 1?

> /**
> - * Add a network interface index number to the list of white listed
> + * Add a network interface index number to the list of whitelisted
> * network interfaces by name.
> *
> - * @param device_name the name of the device to be white listed
> + * @param device_name the name of the device to be whitelisted
> * @return 1 on success, 0 on error
> */
> int hip_netdev_white_list_add(const char *const device_name)
> @@ -146,19 +160,18 @@
> int sock = 0;
> int ret = 0;
>
> - strncpy(ifr.ifr_name, device_name, IF_NAMESIZE);
> + strncpy(ifr.ifr_name, device_name, sizeof(ifr.ifr_name) - 1);

Same here.

> /**
> + * Gives you the interface label for a given IPv4 or IPv6 address.
> + *
> + * @param addr address for which you want to know the label
> + * @param label pointer where the function stores the label
> + * @return zero on success, one on error and write the label
> + * in param label if the given address exists in the system
> + */
> +int hip_find_label_for_address(const struct sockaddr *const addr,
> + char *const label)
> +{
> + int res = 1;
> + struct ifaddrs *myaddrs, *ifa = NULL;
> +
> + getifaddrs(&myaddrs);
> + for (ifa = myaddrs; ifa != NULL; ifa = ifa->ifa_next) {
> + if (ifa->ifa_addr == NULL ||
> + (ifa->ifa_addr->sa_family != AF_INET &&
> + ifa->ifa_addr->sa_family != AF_INET6)) {
> + continue;
> + }
>...

Read more...

René Hummen (rene-hummen) : Posted in a previous version of this proposal
review: Needs Information
Christian Röller (christian-roeller) wrote : Posted in a previous version of this proposal
Download full text (5.3 KiB)

> Hi,
>
> I just got one issue that was raised by Stefan before, but has not been fixed
> so far (more inline).
>
> On 22.08.2011, at 21:05, Christian Röller wrote:
> > Christian Röller has proposed merging lp:~christian-
> roeller/hipl/whitelisting into lp:hipl.
> >
> > Requested reviews:
> > Stefan Götz (stefan.goetz)
> > Diego Biurrun (diego-biurrun)
> >
> > For more details, see:
> > https://code.launchpad.net/~christian-roeller/hipl/whitelisting/+merge/72487
>
> > /**
> > - * Add a network interface index number to the list of white listed
> > + * Add a network interface index number plus label to the list of
> whitelisted
> > * network interfaces.
> > *
> > - * @param if_index the network interface index to be white listed
> > + * @param if_index the network interface index to be whitelisted
> > + * @param device_name the network interface label to be whitelisted
> > */
> > -static void hip_netdev_white_list_add_index(int if_index)
> > +static void hip_netdev_white_list_add_index_and_name(const unsigned int
> if_index,
> > + const char *const
> device_name)
> > {
> > if (hip_netdev_white_list_count < HIP_NETDEV_MAX_WHITE_LIST) {
> > - hip_netdev_white_list[hip_netdev_white_list_count++] = if_index;
> > + hip_netdev_white_list[hip_netdev_white_list_count].if_index =
> if_index;
> > +
> strncpy(hip_netdev_white_list[hip_netdev_white_list_count].if_label,
> > + device_name, sizeof(hip_netdev_white_list[0].if_label) -
> 1);
>
> Why don't you strncpy the complete sizeof? Either the string is null-
> terminated, in which case you should copy the 0 as well, or it is not, in
> which case you will miss the last letter of the label. What happens with label
> is of length 1?

Yes, you are right, I should definitly use the complete sizeof here. But it is always the same with
strncpy. Either it only copies the start of the string if the source is too long or it fills up
the destination with zeros, which is actually time wasting. But I think the more worse problem is to
have no null-termination, which would be the case if device_name will be exactly as big as IF_NAMESIZE.
So I should maybe increase:

struct hip_netdev_whitelist_entry {
    unsigned int if_index;
- char if_label[IF_NAMESIZE];
+ char if_label[IF_NAMESIZE+1];
};

to guarantee a null-termination. If we assume, that device_name is not bigger than IF_NAMESIZE, which we could/should check in function hip_netdev_white_list_add. See below...
>
> > /**
> > - * Add a network interface index number to the list of white listed
> > + * Add a network interface index number to the list of whitelisted
> > * network interfaces by name.
> > *
> > - * @param device_name the name of the device to be white listed
> > + * @param device_name the name of the device to be whitelisted
> > * @return 1 on success, 0 on error
> > */
> > int hip_netdev_white_list_add(const char *const device_name)
> > @@ -146,19 +160,18 @@
> > int sock = 0;
> > int ret = 0;
> >
> > - strncpy(ifr.ifr_name, device_name, IF_NAMESIZE);
> > + strncpy(ifr.ifr_name, device_name, sizeof...

Read more...

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

Hi Christian!

> +int hip_find_label_for_address(const struct sockaddr *const addr,
> + char *const label)

[M] policy: since this is a new function, it needs to be checked by a unit test.

Regards,
 Stefan

review: Needs Fixing
Christian Röller (christian-roeller) wrote : Posted in a previous version of this proposal
Download full text (6.0 KiB)

Hi,

sorry for the confusion.
I have just found out,that IF_NAMESIZE is big enough to fit the max. interface
name length plus null-termination. So with Rene's suggested change of using sizeof(*) instead of sizeof(* - 1) it is fine and guarantee a null-termination.

Christian

> > Hi,
> >
> > I just got one issue that was raised by Stefan before, but has not been
> fixed
> > so far (more inline).
> >
> > On 22.08.2011, at 21:05, Christian Röller wrote:
> > > Christian Röller has proposed merging lp:~christian-
> > roeller/hipl/whitelisting into lp:hipl.
> > >
> > > Requested reviews:
> > > Stefan Götz (stefan.goetz)
> > > Diego Biurrun (diego-biurrun)
> > >
> > > For more details, see:
> > > https://code.launchpad.net/~christian-
> roeller/hipl/whitelisting/+merge/72487
> >
> > > /**
> > > - * Add a network interface index number to the list of white listed
> > > + * Add a network interface index number plus label to the list of
> > whitelisted
> > > * network interfaces.
> > > *
> > > - * @param if_index the network interface index to be white listed
> > > + * @param if_index the network interface index to be whitelisted
> > > + * @param device_name the network interface label to be whitelisted
> > > */
> > > -static void hip_netdev_white_list_add_index(int if_index)
> > > +static void hip_netdev_white_list_add_index_and_name(const unsigned int
> > if_index,
> > > + const char *const
> > device_name)
> > > {
> > > if (hip_netdev_white_list_count < HIP_NETDEV_MAX_WHITE_LIST) {
> > > - hip_netdev_white_list[hip_netdev_white_list_count++] = if_index;
> > > + hip_netdev_white_list[hip_netdev_white_list_count].if_index =
> > if_index;
> > > +
> > strncpy(hip_netdev_white_list[hip_netdev_white_list_count].if_label,
> > > + device_name, sizeof(hip_netdev_white_list[0].if_label) -
> > 1);
> >
> > Why don't you strncpy the complete sizeof? Either the string is null-
> > terminated, in which case you should copy the 0 as well, or it is not, in
> > which case you will miss the last letter of the label. What happens with
> label
> > is of length 1?
>
> Yes, you are right, I should definitly use the complete sizeof here. But it is
> always the same with
> strncpy. Either it only copies the start of the string if the source is too
> long or it fills up
> the destination with zeros, which is actually time wasting. But I think the
> more worse problem is to
> have no null-termination, which would be the case if device_name will be
> exactly as big as IF_NAMESIZE.
> So I should maybe increase:
>
> struct hip_netdev_whitelist_entry {
> unsigned int if_index;
> - char if_label[IF_NAMESIZE];
> + char if_label[IF_NAMESIZE+1];
> };
>
> to guarantee a null-termination. If we assume, that device_name is not bigger
> than IF_NAMESIZE, which we could/should check in function
> hip_netdev_white_list_add. See below...
> >
> > > /**
> > > - * Add a network interface index number to the list of white listed
> > > + * Add a network interface index number to the list of whitelisted
> > > * network interfaces by name.
> > > *
> > > - * @param device_name...

Read more...

Christian Röller (christian-roeller) wrote : Posted in a previous version of this proposal

I have added the unit tests for the new function.

Regarding this I have updated the branch to have a latest code version and edit the Makefile.am to let the tests compile.

Additionally it occurs to me, that I have to change the hip_find_label_for_address function, because the "sizeof-check", I did before to determine the size of the passed label parameter, turns out to be pointless. For that reason I added a new parameter to the function, which indicates the size of the passed char pointer.

This will maybe not solve the problem of a buffer overflow, because the responsibility of the value of the new parameter is based on the programmer, but it could be helpful to not forget to choose the value big enough.

Just tell me what you think about it...

Christof Mroz (christof-mroz) wrote : Posted in a previous version of this proposal
Download full text (5.4 KiB)

Most of the following are just suggestions, though there's one stopper.

> -static void hip_netdev_white_list_add_index(int if_index)
> +static void hip_netdev_white_list_add_index_and_name(const unsigned int if_index,
> + const char *const device_name)
> {
> if (hip_netdev_white_list_count < HIP_NETDEV_MAX_WHITE_LIST) {
> - hip_netdev_white_list[hip_netdev_white_list_count++] = if_index;
> + hip_netdev_white_list[hip_netdev_white_list_count].if_index = if_index;
> + strncpy(hip_netdev_white_list[hip_netdev_white_list_count].if_label,
> + device_name, sizeof(hip_netdev_white_list[0].if_label));
> + hip_netdev_white_list_count++;

Sorry to bring up this issue again :)

I suspect you already know that the strncpy() may leave you with an
unterminated if_label here, and you're betting on a sensible length of
device_name. See e.g. [1] for an explanation.
It's always a good idea to add an assert() when gambling, for the sole
purpose of documentation if anything. But better still, I'd terminate
the string explicitly.

If I'm mistaken here, please comment the code (or the device_name
parameter) to clarify. Audit all the other instances of strncpy() you
touched, too.

Also, dropping the hip_netdev_ prefix, at least for static identifiers,
looks safe to me and it would vastly shorten line lengths everywhere in
this file.

[1] http://stackoverflow.com/questions/1453876/why-does-strncpy-not-null-terminate

> + if (hip_netdev_white_list_count > 0) {
> + for (unsigned int i = 0; i < hip_netdev_white_list_count; i++) {
> + if (hip_netdev_white_list[i].if_index == if_index &&
> + !strncmp(hip_netdev_white_list[i].if_label,
> + device_name, sizeof(hip_netdev_white_list[0].if_label))) {
> + return 1;
> + }
> }
> }

Drop the outer if(...): This check is performed on the first for(...) iteration
anyway.

     return 0;
 }

> /**
> - * Add a network interface index number to the list of white listed
> + * Add a network interface index number to the list of whitelisted
> * network interfaces by name.
> *

You replaced `white list' with `whitelist' in comments, so you should
change it in identifiers as well: `white_list' -> `whitelist'.

> /**
> + * Gives you the interface label for a given IPv4 or IPv6 address.

`Gives you' -> `Returns'

> + *
> + * @param addr Address for which you want to know the label
> + * @param label Pointer where the function stores the label.
> + * @param sizeoflabel Size of the passed label parameter, should be chosen big enough
> + * to be able to store every possible interface name plus null-termination.
> + * @return Zero on success, one on error and write the label
> + * in param label if the given address exists in the system.
> + * Label will be null terminated for sure, iff param label
> + * is chosen big enough(IF_NAMESIZE == 16).
> + */

I'...

Read more...

review: Needs Fixing
Christian Röller (christian-roeller) wrote : Posted in a previous version of this proposal
Download full text (7.6 KiB)

> Most of the following are just suggestions, though there's one stopper.
>
> > -static void hip_netdev_white_list_add_index(int if_index)
> > +static void hip_netdev_white_list_add_index_and_name(const unsigned int
> if_index,
> > + const char *const
> device_name)
> > {
> > if (hip_netdev_white_list_count < HIP_NETDEV_MAX_WHITE_LIST) {
> > - hip_netdev_white_list[hip_netdev_white_list_count++] = if_index;
> > + hip_netdev_white_list[hip_netdev_white_list_count].if_index =
> if_index;
> > +
> strncpy(hip_netdev_white_list[hip_netdev_white_list_count].if_label,
> > + device_name, sizeof(hip_netdev_white_list[0].if_label));
> > + hip_netdev_white_list_count++;
>
> Sorry to bring up this issue again :)
>
> I suspect you already know that the strncpy() may leave you with an
> unterminated if_label here, and you're betting on a sensible length of
> device_name. See e.g. [1] for an explanation.
> It's always a good idea to add an assert() when gambling, for the sole
> purpose of documentation if anything. But better still, I'd terminate
> the string explicitly.
>
> If I'm mistaken here, please comment the code (or the device_name
> parameter) to clarify. Audit all the other instances of strncpy() you
> touched, too.

Actually you are right, but in this case the null-termination is guaranteed.
Because the max interface name length in linux is 15 and I am allocating 16 byte(IF_NAMESIZE)
for my hip_netdev_whitelist_entry struct. And in strncpy I always write IF_NAMESIZE many bytes,
so even in the case our system has a maximum interface name of 15, I would write at least one byte
more and terminate the string in this manner, because strncpy would fill up the buffer with nulls.
So if_label has at least one null-termination, possibly more. I know this is not the definition of
a c-string with only one null-termination at the end, but actually this should not result in any problems. If I am wrong please correct me...

>
> Also, dropping the hip_netdev_ prefix, at least for static identifiers,
> looks safe to me and it would vastly shorten line lengths everywhere in
> this file.

Yes of course I can do it, thats because I didn't write this function I just adopt them.
So I tried to change as few as possible.

>
> [1] http://stackoverflow.com/questions/1453876/why-does-strncpy-not-null-
> terminate
>
> > + if (hip_netdev_white_list_count > 0) {
> > + for (unsigned int i = 0; i < hip_netdev_white_list_count; i++) {
> > + if (hip_netdev_white_list[i].if_index == if_index &&
> > + !strncmp(hip_netdev_white_list[i].if_label,
> > + device_name,
> sizeof(hip_netdev_white_list[0].if_label))) {
> > + return 1;
> > + }
> > }
> > }
>
> Drop the outer if(...): This check is performed on the first for(...)
> iteration
> anyway.

Same here I guess this was the actual auther of the function, but of course you are right this is duplicative. I just don't see it...

>
> return 0;
> }
>
> > /**
> > - * Add a network interface index number to the list of white listed...

Read more...

Christof Mroz (christof-mroz) wrote : Posted in a previous version of this proposal
Download full text (4.2 KiB)

On Tue, 13 Sep 2011 19:43:28 +0200, Christian Röller
<email address hidden> wrote:

> Because the max interface name length in linux is 15 and I am
> allocating 16 byte(IF_NAMESIZE) for my hip_netdev_whitelist_entry
> struct. And in strncpy I always write IF_NAMESIZE many bytes, so even
> in the case our system has a maximum interface name of 15, I would
> write at least one byte more and terminate the string in this manner,
> because strncpy would fill up the buffer with nulls.

Unless device_name points to a string that's bigger than the allowed
interface name. Consider the following minimal example:

char dst[2]; // expected to hold a one-character "string"
char src[] = "ab"; // too long
strncpy(dst, src, sizeof(dst)); // dst not NULL terminated

Now if you checked the length already (in the calling function, for
example), of course you can safely assume that the supplied string is
not too long. In order to communicate your assumption to fellow
programmers, add an assertion:

assert(strlen(device_name) < sizeof(whitelist[0].if_label))

If you didn't check the length beforehand however, you need to display
an error message and exit gracefully because the interface name is a
user-supplied value. Assertions are reserved for "programmer-supplied"
values, you could say.

> So if_label has at least one null-termination, possibly more. I know
> this is not the definition of a c-string with only one
> null-termination at the end, but actually this should not result in
> any problems. If I am wrong please correct me...

No you're right, multiple \0 bytes don't matter.

>> Also, dropping the hip_netdev_ prefix, at least for static identifiers,
>> looks safe to me and it would vastly shorten line lengths everywhere in
>> this file.
>
> Yes of course I can do it, thats because I didn't write this function I
> just adopt them.
> So I tried to change as few as possible.

Of course; if at all, this should be done in a designated branch since
the diff will be huge.

>> You replaced `white list' with `whitelist' in comments, so you should
>> change it in identifiers as well: `white_list' -> `whitelist'.
>
> Again a case of adoption, the actual author use this syntax, so I adopt
> it.
> This change was more the grammar owed, which should be adhered to in
> comments more than for variable names. ;-) But I can change it of
> course lets see what the others think about it...

Changing the comments was off-topic to begin with, so I'd be for
finishing it (unless someone objects)

>> I'd say it's reasonable to require `sizeof(label) >= IF_NAMESIZE' in the
>> documentation and drop the sizeoflabel parameter. Note that you can
>> specify
>>
>> int hip_find_label_for_address(const struct sockaddr *const addr,
>> char label[IF_NAMESIZE])
>>
>> to enable a minimal compile-time check (at least for statically
>> allocated buffers. Hey, better than nothing).
>
> Yes you are right, but to make use of it we need a statically allocated
> buffer, which we use for calling this function. This would only make
> sense if the function itself is static, right?

Maybe static wasn't the right term... I rather meant a "...

Read more...

Christian Röller (christian-roeller) wrote : Posted in a previous version of this proposal
Download full text (5.9 KiB)

> On Tue, 13 Sep 2011 19:43:28 +0200, Christian Röller
> <email address hidden> wrote:
>
> > Because the max interface name length in linux is 15 and I am
> > allocating 16 byte(IF_NAMESIZE) for my hip_netdev_whitelist_entry
> > struct. And in strncpy I always write IF_NAMESIZE many bytes, so even
> > in the case our system has a maximum interface name of 15, I would
> > write at least one byte more and terminate the string in this manner,
> > because strncpy would fill up the buffer with nulls.
>
> Unless device_name points to a string that's bigger than the allowed
> interface name. Consider the following minimal example:
>
> char dst[2]; // expected to hold a one-character "string"
> char src[] = "ab"; // too long
> strncpy(dst, src, sizeof(dst)); // dst not NULL terminated
>
> Now if you checked the length already (in the calling function, for
> example), of course you can safely assume that the supplied string is
> not too long. In order to communicate your assumption to fellow
> programmers, add an assertion:
>
> assert(strlen(device_name) < sizeof(whitelist[0].if_label))
>
> If you didn't check the length beforehand however, you need to display
> an error message and exit gracefully because the interface name is a
> user-supplied value. Assertions are reserved for "programmer-supplied"
> values, you could say.

Yes, you are right I should somehow communicate this. I just want to say that it is not possible
to have here no null-termination, because device_name(src) is at most 15 and
hip_netdev_white_list[hip_netdev_white_list_count].if_label(dst) is 16 and I will write 16 bytes.
You are right the interface name, which should be whitelisted is user-supplied, but the hip_netdev_white_list_add_index_and_name function is only called if the interface name is really existing in the system. So it's valid, which would be only the case if it will be smaller than 16.
But you are right, this is maybe not directly obvious. But I think to comment this in the function
is enough, because an assertion would mean additional computations, which are not necessary because the assertion would never fire.

>
> > So if_label has at least one null-termination, possibly more. I know
> > this is not the definition of a c-string with only one
> > null-termination at the end, but actually this should not result in
> > any problems. If I am wrong please correct me...
>
> No you're right, multiple \0 bytes don't matter.
>
> >> Also, dropping the hip_netdev_ prefix, at least for static identifiers,
> >> looks safe to me and it would vastly shorten line lengths everywhere in
> >> this file.
> >
> > Yes of course I can do it, thats because I didn't write this function I
> > just adopt them.
> > So I tried to change as few as possible.
>
> Of course; if at all, this should be done in a designated branch since
> the diff will be huge.
>
> >> You replaced `white list' with `whitelist' in comments, so you should
> >> change it in identifiers as well: `white_list' -> `whitelist'.
> >
> > Again a case of adoption, the actual author use this syntax, so I adopt
> > it.
> > This change was more the grammar owed, which should be adhered to in
...

Read more...

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

On Tue, 13 Sep 2011 21:09:23 +0200, Christian Röller
<email address hidden> wrote:

> But I think to comment this in the function is enough, because an
> assertion would mean additional computations, which are not necessary
> because the assertion would never fire.

That's the point of using an assertion versus a regular check: if
performance matters (in release builds etc.), you should be able to
undef the HIP_ASSERT macro (and thus don't compile the checks) without
breaking anything. In this sense, assertions don't cost anything.

> I tried this and the compiler doesn't complain. I could choose every
> size vor char label[].
> Are you sure, that this will be checked from the compiler? I think
> this would only be the case, if I will really declare label as
> static. Because only these variables are known to the compiler during
> the compilephase. For label[IF_NAMESIZE] will first memory allocated
> during the execution. Maybe this is the reason why the compiler
> doesn't complain. Although I would say this must be verifiable during
> the compilephase. But I am not sure if the compiler will do it.
> But maybe I am totaly wrong here. What would you say?

Just tried it myself, and you're right: no sanity checks when passing
buffers around. Not even bounds checking works for parameter arrays;
it's as if the size info is discarded altogether. Which can't be true
because the compiler needs to carry it around for multidimensional
arrays, where all but one dimension must be specified. Meh, never
trust compilers...

Why did I think it would work in the first place? Because gcc actually
does (static, i.e. no-cost) bounds-checking e.g. for stack-allocated
arrays if told so. But Parameters are a whole other affair, it seems.

That said: feel free to omit the size, though I'd say it improves
documentation.

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

On Tue, Sep 13, 2011 at 05:43:28PM +0000, Christian Röller wrote:
> > Most of the following are just suggestions, though there's one stopper.
> >
> > > -static void hip_netdev_white_list_add_index(int if_index)
> > > +static void hip_netdev_white_list_add_index_and_name(const unsigned int
> > if_index,
> > > + const char *const
> > device_name)
> > > {
> > > if (hip_netdev_white_list_count < HIP_NETDEV_MAX_WHITE_LIST) {
> > > - hip_netdev_white_list[hip_netdev_white_list_count++] = if_index;
> > > + hip_netdev_white_list[hip_netdev_white_list_count].if_index =
> > if_index;
> > > +
> > strncpy(hip_netdev_white_list[hip_netdev_white_list_count].if_label,
> > > + device_name, sizeof(hip_netdev_white_list[0].if_label));
> > > + hip_netdev_white_list_count++;
> >
> > Sorry to bring up this issue again :)
> >
> > I suspect you already know that the strncpy() may leave you with an
> > unterminated if_label here, and you're betting on a sensible length of
> > device_name. See e.g. [1] for an explanation.
> > It's always a good idea to add an assert() when gambling, for the sole
> > purpose of documentation if anything. But better still, I'd terminate
> > the string explicitly.
> >
> > If I'm mistaken here, please comment the code (or the device_name
> > parameter) to clarify. Audit all the other instances of strncpy() you
> > touched, too.
>
> Actually you are right, but in this case the null-termination is guaranteed.
> Because the max interface name length in linux is 15 and I am allocating 16 byte(IF_NAMESIZE)
> for my hip_netdev_whitelist_entry struct. And in strncpy I always write IF_NAMESIZE many bytes,
> so even in the case our system has a maximum interface name of 15, I would write at least one byte
> more and terminate the string in this manner, because strncpy would fill up the buffer with nulls.

So you are essentially saying that if HIPL gets ported to something else
than Linux, this will possibly introduce a subtle and hard to find bug? :)

Diego

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

On Tue, Sep 13, 2011 at 03:41:04PM +0000, Christof Mroz wrote:
>
> > +
> > + if (!memcmp(addr, ifa->ifa_addr, sizeof(addr))) {
> > + if (strlen(ifa->ifa_name) < sizeoflabel) {
> > + strncpy(label, ifa->ifa_name, sizeoflabel);
> > + res = 0;
> > + }
> > + break;
> > + }
> > + }
>
> Stopper: addr is a pointer, so sizeof(addr) is always sizeof(void*); you
> meant sizeof(*addr).
>
> This one may have slipped through your tests because accidentally,
> sizeof(void*) = sizeof(struct sockaddr). Be sure to check your code with
> IPv6, too.

good catch!

> > + if (!hip_find_label_for_address(addr, label, sizeof(label)) &&
> > + !hip_netdev_is_in_white_list(ifa->ifa_index, label)) {
> > + HIP_DEBUG("Interface:<%s> is not whitelisted\n", label);
> > + continue;
> > + }
>
> Maybe it's just me, but you return zero both for success and failure
> depending on the function, which confused me at first. Probably no big
> deal since these functions are not public, though.

You can find this all over HIPL, annoying as heck if you ask me :)

Somebody should open a bug about this and add it to the eternal todo
list... :)

Diego

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

On Tue, Sep 13, 2011 at 06:34:23PM +0000, Christof Mroz wrote:
> On Tue, 13 Sep 2011 19:43:28 +0200, Christian Röller
> <email address hidden> wrote:
>
> >> You replaced `white list' with `whitelist' in comments, so you should
> >> change it in identifiers as well: `white_list' -> `whitelist'.
> >
> > Again a case of adoption, the actual author use this syntax, so I adopt
> > it.
> > This change was more the grammar owed, which should be adhered to in
> > comments more than for variable names. ;-) But I can change it of
> > course lets see what the others think about it...
>
> Changing the comments was off-topic to begin with, so I'd be for
> finishing it (unless someone objects)

I'm for finishing it right away on trunk, outside the scope of this
branch :)

Diego

Diego Biurrun (diego-biurrun) wrote : Posted in a previous version of this proposal
Download full text (6.3 KiB)

 review needs-fixing

On Tue, Sep 13, 2011 at 12:20:34PM +0000, Christian Röller wrote:
>
> === modified file 'Makefile.am'
> --- Makefile.am 2011-08-10 15:03:07 +0000
> +++ Makefile.am 2011-09-13 12:20:25 +0000
> @@ -71,11 +71,15 @@
> TESTS = test/check_firewall \
> test/check_lib_core \
> test/check_lib_tool \
> - test/check_modules_midauth
> + test/check_modules_midauth \
> + test/check_lib_tool \
> + test/check_hipd
> check_PROGRAMS = test/check_firewall \
> test/check_lib_core \
> test/check_lib_tool \
> - test/check_modules_midauth
> + test/check_modules_midauth \
> + test/check_lib_tool \
> + test/check_hipd

duplicate entries

alphabetical order

> @@ -207,6 +211,10 @@
>
> +test_check_hipd_SOURCES = test/check_hipd.c \
> + test/hipd/netdev.c \
> + modules/midauth/hipd/midauth.c \
> + $(hipd_hipd_sources)

Please align the '\' vertically, same as in the rest of the file.

> test_check_firewall_SOURCES = test/check_firewall.c \
> test/mocks.c \

Like here for example :)

> --- hipd/netdev.c 2011-08-15 14:11:56 +0000
> +++ hipd/netdev.c 2011-09-13 12:20:25 +0000
> @@ -90,54 +90,68 @@
>
> -static int hip_netdev_white_list[HIP_NETDEV_MAX_WHITE_LIST];
> -static int hip_netdev_white_list_count = 0;
> +struct hip_netdev_whitelist_entry {
> + unsigned int if_index;
> + char if_label[IF_NAMESIZE];
> +};
> +static struct hip_netdev_whitelist_entry hip_netdev_white_list[HIP_NETDEV_MAX_WHITE_LIST];
> +static unsigned int hip_netdev_white_list_count = 0;
>
> -static void hip_netdev_white_list_add_index(int if_index)
> +static void hip_netdev_white_list_add_index_and_name(const unsigned int if_index,
> + const char *const device_name)

These unnecessary double prefixes (hip_ and netdev_) for symbols not
visible outside of this file are annoying.

In a perfect world, you would do a quick search and replace on trunk and
merge that back into your branch, but I don't want to pile too much
extra work on you. However, if you have a minute and the motivation..

Maybe you could drop them for the new code, but feel free to ignore me.

> -static int hip_netdev_is_in_white_list(int if_index)
> +static int hip_netdev_is_in_white_list(const unsigned int if_index,
> + const char *const device_name)

Oh look, this file only had a hip_ prefix - yay for consistency in HIPL,
even in the same file :)

> @@ -1120,6 +1133,44 @@
>
> /**
> + * Gives you the interface label for a given IPv4 or IPv6 address.
> + *
> + * @param addr Address for which you want to know the label
> + * @param label Pointer where the function stores the label.
> + * @param sizeoflabel Size of the passed label parameter, should be chosen big enough
> + * to be able to store...

Read more...

review: Needs Fixing
Christian Röller (christian-roeller) wrote : Posted in a previous version of this proposal

> On Tue, Sep 13, 2011 at 05:43:28PM +0000, Christian Röller wrote:
> > > Most of the following are just suggestions, though there's one stopper.
> > >
> > > > -static void hip_netdev_white_list_add_index(int if_index)
> > > > +static void hip_netdev_white_list_add_index_and_name(const unsigned int
> > > if_index,
> > > > + const char *const
> > > device_name)
> > > > {
> > > > if (hip_netdev_white_list_count < HIP_NETDEV_MAX_WHITE_LIST) {
> > > > - hip_netdev_white_list[hip_netdev_white_list_count++] =
> if_index;
> > > > + hip_netdev_white_list[hip_netdev_white_list_count].if_index =
> > > if_index;
> > > > +
> > > strncpy(hip_netdev_white_list[hip_netdev_white_list_count].if_label,
> > > > + device_name,
> sizeof(hip_netdev_white_list[0].if_label));
> > > > + hip_netdev_white_list_count++;
> > >
> > > Sorry to bring up this issue again :)
> > >
> > > I suspect you already know that the strncpy() may leave you with an
> > > unterminated if_label here, and you're betting on a sensible length of
> > > device_name. See e.g. [1] for an explanation.
> > > It's always a good idea to add an assert() when gambling, for the sole
> > > purpose of documentation if anything. But better still, I'd terminate
> > > the string explicitly.
> > >
> > > If I'm mistaken here, please comment the code (or the device_name
> > > parameter) to clarify. Audit all the other instances of strncpy() you
> > > touched, too.
> >
> > Actually you are right, but in this case the null-termination is guaranteed.
> > Because the max interface name length in linux is 15 and I am allocating 16
> byte(IF_NAMESIZE)
> > for my hip_netdev_whitelist_entry struct. And in strncpy I always write
> IF_NAMESIZE many bytes,
> > so even in the case our system has a maximum interface name of 15, I would
> write at least one byte
> > more and terminate the string in this manner, because strncpy would fill up
> the buffer with nulls.
>
> So you are essentially saying that if HIPL gets ported to something else
> than Linux, this will possibly introduce a subtle and hard to find bug? :)
>
> Diego

I had to limit the buffer length somehow, so I choose an OS-specific characteristic.
Is there a better way?

But isn't the whole whitelisting approach very os-specific(in this case linux)? I mean we base the whole whitelisting on OS-specific characteristics like interface-indeces and interface-label-names.
So maybe the whole whitelisting approach is a bug in this manner!? :)

But to be honest, I have no other idea than to treat the whitelisting separately for every OS. You?

Christian Röller (christian-roeller) wrote : Posted in a previous version of this proposal

I have submitted the code a cosmetic treatment and tried to implement all your improvement suggestions. Maybe you can have another look when you find the time...thanks

Christof Mroz (christof-mroz) wrote :

Almost there:

> + assert(strlen(device_name) < sizeof(whitelist[0].if_label));
> + if (whitelist_count < HIP_NETDEV_MAX_WHITE_LIST) {
> + whitelist[whitelist_count].if_index = if_index;
> + strncpy(whitelist[whitelist_count].if_label,
> + device_name, sizeof(whitelist[0].if_label));
> + whitelist_count++;

There's a HIP_ASSERT() macro that takes care of logging violations, and it's
correctly disabled in non-debug builds.

> - /* We should NEVER run out of white list slots!!! */
> - HIP_DIE("Error: ran out of space for white listed interfaces!\n");
> + /* We should NEVER run out of whitelist slots!!! */
> + HIP_DIE("Error: ran out of space for whitelisted interfaces!\n");

I know you didn't introduce the comment, but it's stupid nevertheless.

> - strncpy(ifr.ifr_name, device_name, IF_NAMESIZE);
> + strncpy(ifr.ifr_name, device_name, sizeof(ifr.ifr_name));

Would a HIP_ASSERT be appropriate here as well?

> * @return interface index if the network address is bound to one, zero if
> - * no interface index was found.
> + * no interface index was found.
> */

Unrelated: is zero a valid index, according to netlink? eth0 is, after all.
Changing the return value on failure to a negative number won't hurt
in any case.

> +START_TEST(test_hip_netdev_find_label_for_address_parameters)
> +{
> + struct ifaddrs *myaddrs, *ifa = NULL;
> + char label[IF_NAMESIZE];
> +
> + /* The passed label parameter for the function hip_find_label_for_address
> + * must be at least 1 greater than the found label in the function. So
> + * a size of 1 would be for sure too short to store at least the shortest
> + * label of only 1 character.
> + */
> + char label_too_short[1];
> +
> + getifaddrs(&myaddrs);

You should warn that this test was skipped if getifaddrs() doesn't return anything.
Using mock functions would be more correct, but in this case it's probably not
worth the effort.

review: Needs Fixing
Diego Biurrun (diego-biurrun) wrote :

 review needs-fixing

On Wed, Sep 14, 2011 at 12:50:08PM +0000, Christian Röller wrote:
> Christian Röller has proposed merging lp:~christian-roeller/hipl/whitelisting into lp:hipl.

The size of this merge proposal has grown from 19k to 30k overnight.
This is a problem. Note that review time grows more than linearly
with change size. Note further that most of the reviewers work on
HIPL in their free time.

You have added many completely unrelated changes to this merge
proposal. I know your intentions are good, but unfortunately
the result is not.

This merge proposal is about whitelisting. Changes not related to
whitelisting do *not* belong here. They should either go in a
separate merge proposal or be committed directly to trunk.

I bet you have only a single branch and do all your work in there, right?
This is a very common workstyle for people coming from centralized
revision control systems, but not a good way to work with Bazaar.
Start unleashing its power and branch merrily. I have had days where
I created and threw away a dozen or more branches.

Now please go ahead and create a separate branch for your whitespace
changes. You will be surprised how quickly that will get approved
and how much quicker your whitelisting branch will get approval :)

Happy branching, Diego

review: Needs Fixing

I second Christof's comments; please address them. As for Diego's comments, I agree wholeheartedly but I'd let you get away with a 'keep unrelated changes out of your next branch/merge proposal'. No further comments from my side.

review: Needs Fixing
Diego Biurrun (diego-biurrun) wrote :

On Wed, Sep 14, 2011 at 07:43:47PM +0000, Stefan Götz wrote:
> Review: Needs Fixing
>
> As for Diego's comments, I agree wholeheartedly but I'd let you get
> away with a 'keep unrelated changes out of your next branch/merge
> proposal'.

All of this really should not be that hard with the help of the rebase,
merge and replay bzr commands or even with diff and patch. The more
practice one gets using these tools, the better :)

In all the projects I worked, unrelated changes in a patch were an
automatic reject, no further questions asked...

Diego

> On Wed, Sep 14, 2011 at 07:43:47PM +0000, Stefan Götz wrote:
> > Review: Needs Fixing
> >
> > As for Diego's comments, I agree wholeheartedly but I'd let you get
> > away with a 'keep unrelated changes out of your next branch/merge
> > proposal'.
>
> All of this really should not be that hard with the help of the rebase,
> merge and replay bzr commands or even with diff and patch. The more
> practice one gets using these tools, the better :)
>
> In all the projects I worked, unrelated changes in a patch were an
> automatic reject, no further questions asked...
>
> Diego

I totally agree to that Diego, it was no good idea to mix up here different things.
I just did it because I have changed all comments for the whitelisting relevant functions
and just wanted to take care of consistency in the whole file.

You are right a little bit more practice with bazaar couldn't be bad :),
because this is the first time I really use it. But is it really worthwhile this time
to create an own branch for it? I mean I would just change a few comment alignment issues in one file. But as I said in the beginning I agree to that in principle.
So if it is wished, I will try to do it. Even though this could take a few days, because I have to
do first a lot of other things this week.

Regards,
Christian

Diego Biurrun (diego-biurrun) wrote :

On Thu, Sep 15, 2011 at 01:43:18PM +0000, Christian Röller wrote:
> > On Wed, Sep 14, 2011 at 07:43:47PM +0000, Stefan Götz wrote:
> > > Review: Needs Fixing
> > >
> > > As for Diego's comments, I agree wholeheartedly but I'd let you get
> > > away with a 'keep unrelated changes out of your next branch/merge
> > > proposal'.
> >
> > All of this really should not be that hard with the help of the rebase,
> > merge and replay bzr commands or even with diff and patch. The more
> > practice one gets using these tools, the better :)
> >
> > In all the projects I worked, unrelated changes in a patch were an
> > automatic reject, no further questions asked...
>
> I totally agree to that Diego, it was no good idea to mix up here different things.
> I just did it because I have changed all comments for the whitelisting relevant functions
> and just wanted to take care of consistency in the whole file.
>
> You are right a little bit more practice with bazaar couldn't be bad :),
> because this is the first time I really use it. But is it really worthwhile this time
> to create an own branch for it?

Yes.

> I mean I would just change a few comment alignment issues in one file.
> But as I said in the beginning I agree to that in principle.
> So if it is wished, I will try to do it. Even though this could take a
> few days, because I have to do first a lot of other things this week.

It really should not take you long. You can poke me on IRC if you have
trouble.

Diego

René Hummen (rene-hummen) wrote :

On 15.09.2011, at 15:43, Christian Röller wrote:
>> On Wed, Sep 14, 2011 at 07:43:47PM +0000, Stefan Götz wrote:
>>> Review: Needs Fixing
>>>
>>> As for Diego's comments, I agree wholeheartedly but I'd let you get
>>> away with a 'keep unrelated changes out of your next branch/merge
>>> proposal'.
>>
>> All of this really should not be that hard with the help of the rebase,
>> merge and replay bzr commands or even with diff and patch. The more
>> practice one gets using these tools, the better :)
>>
>> In all the projects I worked, unrelated changes in a patch were an
>> automatic reject, no further questions asked...
>>
>> Diego
>
> I totally agree to that Diego, it was no good idea to mix up here different things.
> I just did it because I have changed all comments for the whitelisting relevant functions
> and just wanted to take care of consistency in the whole file.
>
> You are right a little bit more practice with bazaar couldn't be bad :),
> because this is the first time I really use it. But is it really worthwhile this time
> to create an own branch for it? I mean I would just change a few comment alignment issues in one file. But as I said in the beginning I agree to that in principle.
> So if it is wished, I will try to do it. Even though this could take a few days, because I have to
> do first a lot of other things this week.

Please address Christof's comments. I agree with Stefan that for this time your branch is ok, but please take care to only propose related issues.

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/

Unmerged revisions

5999. By Christian Röller on 2011-09-14

Cosmetic issues in all files.

5998. By Christian Röller on 2011-09-14

Cosmetic issues in both files.

5997. By Christian Röller on 2011-09-13

A few cosmetic changes and correct one mistake regarding the use of sizeof.

5996. By Christian Röller on 2011-09-13

Rebase with trunk.

5995. By Christian Röller on 2011-08-30

Add Unit-Tests for the new function hip_find_label_for_address in /hipd/netdev.c

5994. By Christian Röller on 2011-08-24

Increase the n by 1 in strncpy regarding the writing of the interfacelabel to guarantee null-termination.

5993. By Christian Röller on 2011-08-23

cosmetic: alignments in function description hip_find_label_for_address

5992. By Christian Röller on 2011-08-22

cosmetic: correct some typos

5991. By Christian Röller on 2011-08-12

cosmetic: typo in function description

5990. By Christian Röller on 2011-08-12

cosmetic: shorten a few things

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'Makefile.am'
--- Makefile.am 2011-08-10 15:03:07 +0000
+++ Makefile.am 2011-09-14 12:49:45 +0000
@@ -68,13 +68,15 @@
6868
69### tests ###69### tests ###
70if HIP_UNITTESTS70if HIP_UNITTESTS
71TESTS = test/check_firewall \71TESTS = test/check_firewall \
72 test/check_lib_core \72 test/check_hipd \
73 test/check_lib_tool \73 test/check_lib_core \
74 test/check_modules_midauth74 test/check_lib_tool \
75check_PROGRAMS = test/check_firewall \75 test/check_modules_midauth
76 test/check_lib_core \76check_PROGRAMS = test/check_firewall \
77 test/check_lib_tool \77 test/check_hipd \
78 test/check_lib_core \
79 test/check_lib_tool \
78 test/check_modules_midauth80 test/check_modules_midauth
79endif81endif
8082
@@ -207,6 +209,10 @@
207lib_core_libhipcore_la_SOURCES += lib/core/performance.c209lib_core_libhipcore_la_SOURCES += lib/core/performance.c
208endif210endif
209211
212test_check_hipd_SOURCES = modules/midauth/hipd/midauth.c \
213 test/check_hipd.c \
214 test/hipd/netdev.c \
215 $(hipd_hipd_sources)
210216
211test_check_firewall_SOURCES = test/check_firewall.c \217test_check_firewall_SOURCES = test/check_firewall.c \
212 test/mocks.c \218 test/mocks.c \
@@ -240,6 +246,7 @@
240hipd_hipd_LDADD = lib/core/libhipcore.la246hipd_hipd_LDADD = lib/core/libhipcore.la
241test_auth_performance_LDADD = lib/core/libhipcore.la247test_auth_performance_LDADD = lib/core/libhipcore.la
242test_check_firewall_LDADD = lib/core/libhipcore.la248test_check_firewall_LDADD = lib/core/libhipcore.la
249test_check_hipd_LDADD = lib/core/libhipcore.la
243test_check_lib_core_LDADD = lib/core/libhipcore.la250test_check_lib_core_LDADD = lib/core/libhipcore.la
244test_check_lib_tool_LDADD = lib/core/libhipcore.la251test_check_lib_tool_LDADD = lib/core/libhipcore.la
245test_check_modules_midauth_LDADD = lib/core/libhipcore.la252test_check_modules_midauth_LDADD = lib/core/libhipcore.la
246253
=== modified file 'hipd/input.c'
--- hipd/input.c 2011-08-25 12:12:27 +0000
+++ hipd/input.c 2011-09-14 12:49:45 +0000
@@ -521,7 +521,7 @@
521 /* RVS/Relay is handled later in the code. */521 /* RVS/Relay is handled later in the code. */
522 if (hip_relay_get_status() == HIP_RELAY_OFF)522 if (hip_relay_get_status() == HIP_RELAY_OFF)
523#endif523#endif
524 return -1;524 return -1;
525 }525 }
526526
527 /* Debug printing of received packet information. All received HIP527 /* Debug printing of received packet information. All received HIP
528528
=== modified file 'hipd/netdev.c'
--- hipd/netdev.c 2011-08-15 14:11:56 +0000
+++ hipd/netdev.c 2011-09-14 12:49:45 +0000
@@ -53,6 +53,7 @@
53#include <openssl/rand.h>53#include <openssl/rand.h>
54#include <sys/ioctl.h>54#include <sys/ioctl.h>
55#include <linux/rtnetlink.h>55#include <linux/rtnetlink.h>
56#include <assert.h>
5657
57#include "lib/core/builder.h"58#include "lib/core/builder.h"
58#include "lib/core/common.h"59#include "lib/core/common.h"
@@ -79,7 +80,7 @@
7980
80/**81/**
81 * We really don't expect more than a handfull of interfaces to be on82 * We really don't expect more than a handfull of interfaces to be on
82 * our white list.83 * our whitelist.
83 */84 */
84#define HIP_NETDEV_MAX_WHITE_LIST 585#define HIP_NETDEV_MAX_WHITE_LIST 5
8586
@@ -90,43 +91,56 @@
90#define FAM_STR_MAX 3291#define FAM_STR_MAX 32
9192
92/**93/**
93 * This is the white list. For every interface, which is in our white list,94 * This is the whitelist. For every interface, which is in our whitelist,
94 * this array has a fixed size, because there seems to be no need at this95 * this array has a fixed size, because there seems to be no need at this
95 * moment to deal with dynamic memory - which would complicate the code96 * moment to deal with dynamic memory - which would complicate the code
96 * and cost size and performance at least equal if not more to this fixed97 * and cost size and performance at least equal if not more to this fixed
97 * size array.98 * size array.
98 * Free slots are signaled by the value -1.99 * Free slots are signaled by the value -1.
99 */100 */
100static int hip_netdev_white_list[HIP_NETDEV_MAX_WHITE_LIST];101struct whitelist_entry {
101static int hip_netdev_white_list_count = 0;102 unsigned int if_index;
103 char if_label[IF_NAMESIZE];
104};
105static struct whitelist_entry whitelist[HIP_NETDEV_MAX_WHITE_LIST];
106static unsigned int whitelist_count = 0;
102107
103/**108/**
104 * Add a network interface index number to the list of white listed109 * Add a network interface index number plus label to the list of whitelisted
105 * network interfaces.110 * network interfaces.
106 *111 *
107 * @param if_index the network interface index to be white listed112 * @param if_index the network interface index to be whitelisted
113 * @param device_name the network interface label to be whitelisted
108 */114 */
109static void hip_netdev_white_list_add_index(int if_index)115static void whitelist_add_index_and_name(const unsigned int if_index,
116 const char *const device_name)
110{117{
111 if (hip_netdev_white_list_count < HIP_NETDEV_MAX_WHITE_LIST) {118 assert(strlen(device_name) < sizeof(whitelist[0].if_label));
112 hip_netdev_white_list[hip_netdev_white_list_count++] = if_index;119 if (whitelist_count < HIP_NETDEV_MAX_WHITE_LIST) {
120 whitelist[whitelist_count].if_index = if_index;
121 strncpy(whitelist[whitelist_count].if_label,
122 device_name, sizeof(whitelist[0].if_label));
123 whitelist_count++;
113 } else {124 } else {
114 /* We should NEVER run out of white list slots!!! */125 /* We should NEVER run out of whitelist slots!!! */
115 HIP_DIE("Error: ran out of space for white listed interfaces!\n");126 HIP_DIE("Error: ran out of space for whitelisted interfaces!\n");
116 }127 }
117}128}
118129
119/**130/**
120 * Test if the given network interface index is white listed.131 * Test if the given network interface index plus label is whitelisted.
121 *132 *
122 * @param if_index the index of the network interface to be tested133 * @param if_index the index of the network interface to be tested
123 * @return 1 if the index is whitelisted or zero otherwise134 * @param device_name the label of the network interface to be tested
135 * @return 1 if the index is whitelisted or zero otherwise
124 */136 */
125static int hip_netdev_is_in_white_list(int if_index)137static int is_in_whitelist(const unsigned int if_index,
138 const char *const device_name)
126{139{
127 int i = 0;140 for (unsigned int i = 0; i < whitelist_count; i++) {
128 for (i = 0; i < hip_netdev_white_list_count; i++) {141 if (whitelist[i].if_index == if_index &&
129 if (hip_netdev_white_list[i] == if_index) {142 !strncmp(whitelist[i].if_label,
143 device_name, sizeof(whitelist[0].if_label))) {
130 return 1;144 return 1;
131 }145 }
132 }146 }
@@ -134,11 +148,11 @@
134}148}
135149
136/**150/**
137 * Add a network interface index number to the list of white listed151 * Add a network interface index number to the list of whitelisted
138 * network interfaces by name.152 * network interfaces by name.
139 *153 *
140 * @param device_name the name of the device to be white listed154 * @param device_name the name of the device to be whitelisted
141 * @return 1 on success, 0 on error155 * @return 1 on success, 0 on error
142 */156 */
143int hip_netdev_white_list_add(const char *const device_name)157int hip_netdev_white_list_add(const char *const device_name)
144{158{
@@ -146,19 +160,18 @@
146 int sock = 0;160 int sock = 0;
147 int ret = 0;161 int ret = 0;
148162
149 strncpy(ifr.ifr_name, device_name, IF_NAMESIZE);163 strncpy(ifr.ifr_name, device_name, sizeof(ifr.ifr_name));
150 sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);164 sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
151165
152 if (ioctl(sock, SIOCGIFINDEX, &ifr) == 0) {166 if (ioctl(sock, SIOCGIFINDEX, &ifr) == 0) {
153 ret = 1;167 ret = 1;
154 hip_netdev_white_list_add_index(ifr.ifr_ifindex);168 whitelist_add_index_and_name(ifr.ifr_ifindex, device_name);
155 HIP_DEBUG("Adding device <%s> to white list with index <%i>.\n",169 HIP_DEBUG("Adding device <%s> to whitelist with index <%i>.\n",
156 device_name,170 device_name,
157 ifr.ifr_ifindex);171 ifr.ifr_ifindex);
158 } else {172 } else {
159 ret = 0;173 ret = 0;
160 }174 }
161
162 if (sock) {175 if (sock) {
163 close(sock);176 close(sock);
164 }177 }
@@ -169,7 +182,7 @@
169 * hash function for the addresses hash table182 * hash function for the addresses hash table
170 *183 *
171 * @param ptr a pointer to a netdev_address structure184 * @param ptr a pointer to a netdev_address structure
172 * @return the calculated hash to index the parameter185 * @return the calculated hash to index the parameter
173 */186 */
174static unsigned long hip_netdev_hash(const void *ptr)187static unsigned long hip_netdev_hash(const void *ptr)
175{188{
@@ -195,7 +208,7 @@
195 *208 *
196 * @param ptr1 a pointer to a netdev_address structure209 * @param ptr1 a pointer to a netdev_address structure
197 * @param ptr2 a pointer to a netdev_address structure210 * @param ptr2 a pointer to a netdev_address structure
198 * @return 0 if the given pointers match or 1 otherwise211 * @return 0 if the given pointers match or 1 otherwise
199 */212 */
200static int hip_netdev_match(const void *ptr1, const void *ptr2)213static int hip_netdev_match(const void *ptr1, const void *ptr2)
201{214{
@@ -300,7 +313,7 @@
300 * parties should have a matching IP address family.313 * parties should have a matching IP address family.
301 *314 *
302 * @param addr addr the address to be tested (IPv4 address in IPv6 mapped format) for family315 * @param addr addr the address to be tested (IPv4 address in IPv6 mapped format) for family
303 * @return one if the address is recorded in the cache and zero otherwise316 * @return one if the address is recorded in the cache and zero otherwise
304 */317 */
305static int hip_exists_address_family_in_list(const struct in6_addr *addr)318static int hip_exists_address_family_in_list(const struct in6_addr *addr)
306{319{
@@ -323,10 +336,10 @@
323/**336/**
324 * Test if the given address with the given network interface index exists in the cache337 * Test if the given address with the given network interface index exists in the cache
325 *338 *
326 * @param addr A sockaddr structure containing the address to be checked. An IPv6 socket339 * @param addr A sockaddr structure containing the address to be checked. An IPv6 socket
327 * address structure can also contain an IPv4 address in IPv6-mapped format.340 * address structure can also contain an IPv4 address in IPv6-mapped format.
328 * @param ifindex the network interface index341 * @param ifindex the network interface index
329 * @return one if the index exists in the cache or zero otherwise342 * @return one if the index exists in the cache or zero otherwise
330 */343 */
331int hip_exists_address_in_list(struct sockaddr *addr, int ifindex)344int hip_exists_address_in_list(struct sockaddr *addr, int ifindex)
332{345{
@@ -393,9 +406,9 @@
393 * advertisements (UPDATE control message with a LOCATOR parameter) to406 * advertisements (UPDATE control message with a LOCATOR parameter) to
394 * peers.407 * peers.
395 *408 *
396 * @param addr a pointer to a socket address structure.409 * @param addr a pointer to a socket address structure.
397 * @param ifindex network device interface index.410 * @param ifindex network device interface index.
398 * @param flags flags411 * @param flags flags
399 */412 */
400void hip_add_address_to_list(struct sockaddr *addr, int ifindex, int flags)413void hip_add_address_to_list(struct sockaddr *addr, int ifindex, int flags)
401{414{
@@ -442,8 +455,8 @@
442/**455/**
443 * Delete an address from address cache of localhost addresses456 * Delete an address from address cache of localhost addresses
444 *457 *
445 * @param addr A sockaddr structure containing the address to be deleted.458 * @param addr A sockaddr structure containing the address to be deleted.
446 * IPv4 addresses can be in IPv6-mapped format.459 * IPv4 addresses can be in IPv6-mapped format.
447 * @param ifindex the network interface on which the address is attached to460 * @param ifindex the network interface on which the address is attached to
448 */461 */
449static void hip_delete_address_from_list(struct sockaddr *addr, int ifindex)462static void hip_delete_address_from_list(struct sockaddr *addr, int ifindex)
@@ -522,10 +535,10 @@
522/**535/**
523 * Get the interface index of a socket address.536 * Get the interface index of a socket address.
524 *537 *
525 * @param addr a pointer to a socket address whose interface index is to be538 * @param addr a pointer to a socket address whose interface index is to be
526 * searched.539 * searched.
527 * @return interface index if the network address is bound to one, zero if540 * @return interface index if the network address is bound to one, zero if
528 * no interface index was found.541 * no interface index was found.
529 */542 */
530static int hip_netdev_find_if(struct sockaddr *addr)543static int hip_netdev_find_if(struct sockaddr *addr)
531{544{
@@ -587,12 +600,12 @@
587 * a function that gets the ifindex of the network device which has the address600 * a function that gets the ifindex of the network device which has the address
588 * @c addr.601 * @c addr.
589 *602 *
590 * @param addr a pointer to an IPv6 address whose interface index is to be603 * @param addr a pointer to an IPv6 address whose interface index is to be
591 * searched.604 * searched.
592 * @return interface index if the network address is bound to one, zero if605 * @return interface index if the network address is bound to one, zero if
593 * no interface index was found and negative in error case.606 * no interface index was found and negative in error case.
594 * @todo The caller of this should be generalized to both IPv4 and IPv6607 * @todo The caller of this should be generalized to both IPv4 and IPv6
595 * so that this function can be removed (tkoponen).608 * so that this function can be removed (tkoponen).
596 */609 */
597int hip_devaddr2ifindex(struct in6_addr *addr)610int hip_devaddr2ifindex(struct in6_addr *addr)
598{611{
@@ -606,9 +619,9 @@
606 * Initialize the address cache of localhost addresses619 * Initialize the address cache of localhost addresses
607 *620 *
608 * @return zero on success and non-zero on error621 * @return zero on success and non-zero on error
609 * @todo This creates a new NETLINK socket (via getifaddrs), so this has to be622 * @todo This creates a new NETLINK socket (via getifaddrs), so this has to be
610 * run before the global NETLINK socket is opened. We did not have the time623 * run before the global NETLINK socket is opened. We did not have the time
611 * and energy to import all of the necessary functionality from iproute2.624 * and energy to import all of the necessary functionality from iproute2.
612 */625 */
613int hip_netdev_init_addresses(void)626int hip_netdev_init_addresses(void)
614{627{
@@ -632,7 +645,7 @@
632 HIP_IFEL(!(if_index = if_nametoindex(g_iface->ifa_name)),645 HIP_IFEL(!(if_index = if_nametoindex(g_iface->ifa_name)),
633 -1, "if_nametoindex failed\n");646 -1, "if_nametoindex failed\n");
634 /* Check if our interface is in the whitelist */647 /* Check if our interface is in the whitelist */
635 if ((hip_netdev_white_list_count > 0) && (!hip_netdev_is_in_white_list(if_index))) {648 if ((!is_in_whitelist(if_index, g_iface->ifa_name))) {
636 continue;649 continue;
637 }650 }
638651
@@ -650,12 +663,12 @@
650 * Try to map a given HIT or an LSI to a routable IP address using local host association663 * Try to map a given HIT or an LSI to a routable IP address using local host association
651 * data base, hosts files or DNS (in the presented order).664 * data base, hosts files or DNS (in the presented order).
652 *665 *
653 * @param hit a HIT to map to a LSI666 * @param hit a HIT to map to a LSI
654 * @param lsi an LSI to map to an IP address667 * @param lsi an LSI to map to an IP address
655 * @param addr output argument to which this function writes the address if found668 * @param addr output argument to which this function writes the address if found
656 * @return zero on success and non-zero on error669 * @return zero on success and non-zero on error
657 * @note Either HIT or LSI must be given. If both are given, the HIT is preferred.670 * @note Either HIT or LSI must be given. If both are given, the HIT is preferred.
658 * @todo move this to some other file (this file contains local IP address management, not remote)671 * @todo move this to some other file (this file contains local IP address management, not remote)
659 */672 */
660int hip_map_id_to_addr(const hip_hit_t *hit, const hip_lsi_t *lsi,673int hip_map_id_to_addr(const hip_hit_t *hit, const hip_lsi_t *lsi,
661 struct in6_addr *addr)674 struct in6_addr *addr)
@@ -726,21 +739,21 @@
726 * arguments. This function also supports HIP-based loopback739 * arguments. This function also supports HIP-based loopback
727 * connectivity and hiccups (data packet) extensions.740 * connectivity and hiccups (data packet) extensions.
728 *741 *
729 * @param src_hit_in The source HIT for the I1. Alternatively, NULL if default742 * @param src_hit_in The source HIT for the I1. Alternatively, NULL if default
730 * HIT is suitable743 * HIT is suitable
731 * @param dst_hit_in The destination HIT. This HIT cannot be a "pseudo HIT" as744 * @param dst_hit_in The destination HIT. This HIT cannot be a "pseudo HIT" as
732 * used by the opportunistic mode. Use hip_send_i1() function745 * used by the opportunistic mode. Use hip_send_i1() function
733 * instead with opportunistic mode.746 * instead with opportunistic mode.
734 * @param src_lsi_in Optional source LSI corresponding to the source HIT747 * @param src_lsi_in Optional source LSI corresponding to the source HIT
735 * @param dst_lsi_in Optional destination LSI corresponding to the destination HIT748 * @param dst_lsi_in Optional destination LSI corresponding to the destination HIT
736 * @param src_addr_in Source address for the I1 (IPv4 address in IPv6 mapped format)749 * @param src_addr_in Source address for the I1 (IPv4 address in IPv6 mapped format)
737 * @param dst_addr_in Destination address for the I1 (IPv4 address in IPv6 mapped format)750 * @param dst_addr_in Destination address for the I1 (IPv4 address in IPv6 mapped format)
738 * @return zero on success and non-zero on error751 * @return zero on success and non-zero on error
739 * @note HITs can be NULL if the LSIs are non-NULL (and vice versa).752 * @note HITs can be NULL if the LSIs are non-NULL (and vice versa).
740 * @note The locators (addresses) can be NULL. This function will753 * @note The locators (addresses) can be NULL. This function will
741 * try to map the HITs or LSIs to IP addresses. IPv4 broadcast754 * try to map the HITs or LSIs to IP addresses. IPv4 broadcast
742 * will be used as a last resort.755 * will be used as a last resort.
743 * @todo move this function to some other file756 * @todo move this function to some other file
744 */757 */
745static int hip_netdev_trigger_bex(const hip_hit_t *src_hit_in,758static int hip_netdev_trigger_bex(const hip_hit_t *src_hit_in,
746 const hip_hit_t *dst_hit_in,759 const hip_hit_t *dst_hit_in,
@@ -966,8 +979,8 @@
966 * Handle an "acquire" message from the kernel by triggering a base exchange.979 * Handle an "acquire" message from the kernel by triggering a base exchange.
967 *980 *
968 * @param msg a netlink "acquire" message981 * @param msg a netlink "acquire" message
969 * @return zero on success and non-zero on error982 * @return zero on success and non-zero on error
970 * @todo move this to some other file983 * @todo move this to some other file
971 */984 */
972static int hip_netdev_handle_acquire(struct nlmsghdr *msg)985static int hip_netdev_handle_acquire(struct nlmsghdr *msg)
973{986{
@@ -1012,8 +1025,8 @@
1012 *1025 *
1013 * @param msg the HIP user message containing HITs, LSIs and addresses as1026 * @param msg the HIP user message containing HITs, LSIs and addresses as
1014 * parameters1027 * parameters
1015 * @return zero on success and non-zero on error1028 * @return zero on success and non-zero on error
1016 * @todo move this to some other file1029 * @todo move this to some other file
1017 */1030 */
1018int hip_netdev_trigger_bex_msg(const struct hip_common *msg)1031int hip_netdev_trigger_bex_msg(const struct hip_common *msg)
1019{1032{
@@ -1120,6 +1133,44 @@
1120}1133}
11211134
1122/**1135/**
1136 * Returns the interface label for a given IPv4 or IPv6 address.
1137 *
1138 * @param addr Address for which you want to know the label
1139 * @param label Pointer where the function stores the label.
1140 * For the label should be at least 16 bytes allocated.
1141 * @param label_size Size of the passed label parameter, should be chosen big enough
1142 * to be able to store every possible interface name plus NULL-termination.
1143 * @return Zero on success, one on error and write the label
1144 * in param label if the given address exists in the system.
1145 * Label will be NULL-terminated for sure, iff param label
1146 * is chosen big enough(at least 16 bytes).
1147 */
1148int hip_netdev_find_label_for_address(const struct sockaddr *const addr,
1149 char *const label, const unsigned int label_size)
1150{
1151 int res = 1;
1152 struct ifaddrs *myaddrs, *ifa = NULL;
1153
1154 getifaddrs(&myaddrs);
1155 for (ifa = myaddrs; ifa != NULL; ifa = ifa->ifa_next) {
1156 if (ifa->ifa_addr->sa_family != AF_INET &&
1157 ifa->ifa_addr->sa_family != AF_INET6) {
1158 continue;
1159 }
1160
1161 if (!memcmp(addr, ifa->ifa_addr, sizeof(*addr))) {
1162 if (strlen(ifa->ifa_name) < label_size) {
1163 strncpy(label, ifa->ifa_name, label_size);
1164 res = 0;
1165 }
1166 break;
1167 }
1168 }
1169 freeifaddrs(myaddrs);
1170 return res;
1171}
1172
1173/**
1123 * Netlink event handler. Handles IPsec acquire messages (triggering1174 * Netlink event handler. Handles IPsec acquire messages (triggering
1124 * of base exchange) and updates the cache of local addresses when1175 * of base exchange) and updates the cache of local addresses when
1125 * address changes occur.1176 * address changes occur.
@@ -1127,7 +1178,7 @@
1127 * @param msg a netlink message1178 * @param msg a netlink message
1128 * @param len the length of the netlink message in bytes1179 * @param len the length of the netlink message in bytes
1129 * @param arg argument to pass (needed because of the callaback nature)1180 * @param arg argument to pass (needed because of the callaback nature)
1130 * @return zero on success and non-zero on error1181 * @return zero on success and non-zero on error
1131 */1182 */
1132int hip_netdev_event(struct nlmsghdr *msg, int len, UNUSED void *arg)1183int hip_netdev_event(struct nlmsghdr *msg, int len, UNUSED void *arg)
1133{1184{
@@ -1165,11 +1216,6 @@
1165 rta = IFA_RTA(ifa);1216 rta = IFA_RTA(ifa);
1166 l = msg->nlmsg_len - NLMSG_LENGTH(sizeof(*ifa));1217 l = msg->nlmsg_len - NLMSG_LENGTH(sizeof(*ifa));
11671218
1168 /* Check if our interface is in the whitelist */
1169 if ((hip_netdev_white_list_count > 0) &&
1170 (!hip_netdev_is_in_white_list(ifindex))) {
1171 continue;
1172 }
11731219
1174 if ((ifa->ifa_family != AF_INET) &&1220 if ((ifa->ifa_family != AF_INET) &&
1175 (ifa->ifa_family != AF_INET6)) {1221 (ifa->ifa_family != AF_INET6)) {
@@ -1211,6 +1257,17 @@
1211 HIP_DEBUG("Unknown addr family in addr\n");1257 HIP_DEBUG("Unknown addr family in addr\n");
1212 }1258 }
12131259
1260 /* find interface label for address and check if it is whitelisted or not */
1261 if (is_add) {
1262 char label[IF_NAMESIZE];
1263 if (!hip_netdev_find_label_for_address(addr, label, sizeof(label)) &&
1264 !is_in_whitelist(ifa->ifa_index, label)) {
1265 HIP_DEBUG("Interface:<%s> is not whitelisted\n", label);
1266 continue;
1267 }
1268 }
1269
1270
1214 /* Trying to add an existing address or deleting a non-existing1271 /* Trying to add an existing address or deleting a non-existing
1215 * address */1272 * address */
1216 exists = hip_exists_address_in_list(addr, ifa->ifa_index);1273 exists = hip_exists_address_in_list(addr, ifa->ifa_index);
@@ -1303,7 +1360,7 @@
1303 * @param local_hit The HIT to be removed.1360 * @param local_hit The HIT to be removed.
1304 * @return Zero on success, non-zero on failure.1361 * @return Zero on success, non-zero on failure.
1305 *1362 *
1306 * @see hip_manage_iface_local_hit()1363 * @see hip_manage_iface_local_hit()
1307 */1364 */
1308static int hip_remove_iface_local_hit(const hip_hit_t *const local_hit)1365static int hip_remove_iface_local_hit(const hip_hit_t *const local_hit)
1309{1366{
@@ -1340,7 +1397,7 @@
1340 * signature.1397 * signature.
1341 * @return Zero on success, non-zero on failure.1398 * @return Zero on success, non-zero on failure.
1342 *1399 *
1343 * @see hip_remove_iface_all_local_hits()1400 * @see hip_remove_iface_all_local_hits()
1344 */1401 */
1345static int hip_remove_iface_hit_by_host_id(struct local_host_id *entry,1402static int hip_remove_iface_hit_by_host_id(struct local_host_id *entry,
1346 UNUSED void *opaque)1403 UNUSED void *opaque)
@@ -1360,7 +1417,7 @@
1360 * Add a route to a local HIT1417 * Add a route to a local HIT
1361 *1418 *
1362 * @param local_hit the local HIT for which a route should be added1419 * @param local_hit the local HIT for which a route should be added
1363 * @return zero on success and non-zero on error1420 * @return zero on success and non-zero on error
1364 */1421 */
1365int hip_add_iface_local_route(const hip_hit_t *local_hit)1422int hip_add_iface_local_route(const hip_hit_t *local_hit)
1366{1423{
@@ -1387,7 +1444,7 @@
1387 * will be in IPv6-mapped format.1444 * will be in IPv6-mapped format.
1388 * @param dst The destination address. IPv4 addresses must be in1445 * @param dst The destination address. IPv4 addresses must be in
1389 * in IPv6-mapped format.1446 * in IPv6-mapped format.
1390 * @return zero on success and non-zero on failure1447 * @return zero on success and non-zero on failure
1391 */1448 */
1392int hip_select_source_address(struct in6_addr *src, const struct in6_addr *dst)1449int hip_select_source_address(struct in6_addr *src, const struct in6_addr *dst)
1393{1450{
13941451
=== modified file 'hipd/netdev.h'
--- hipd/netdev.h 2011-05-18 15:12:07 +0000
+++ hipd/netdev.h 2011-09-14 12:49:45 +0000
@@ -56,4 +56,7 @@
56int hip_map_id_to_addr(const hip_hit_t *hit, const hip_lsi_t *lsi,56int hip_map_id_to_addr(const hip_hit_t *hit, const hip_lsi_t *lsi,
57 struct in6_addr *addr);57 struct in6_addr *addr);
5858
59int hip_netdev_find_label_for_address(const struct sockaddr *const addr,
60 char *const label, const unsigned int label_size);
61
59#endif /* HIP_HIPD_NETDEV_H */62#endif /* HIP_HIPD_NETDEV_H */
6063
=== added file 'test/check_hipd.c'
--- test/check_hipd.c 1970-01-01 00:00:00 +0000
+++ test/check_hipd.c 2011-09-14 12:49:45 +0000
@@ -0,0 +1,41 @@
1/*
2 * Copyright (c) 2011 Aalto University and RWTH Aachen University.
3 *
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use,
8 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following
11 * conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26#include <check.h>
27#include <stdlib.h>
28
29#include "test/hipd/test_suites.h"
30
31int main(void)
32{
33 int number_failed;
34 SRunner *sr = srunner_create(NULL);
35 srunner_add_suite(sr, hipd_netdev());
36
37 srunner_run_all(sr, CK_NORMAL);
38 number_failed = srunner_ntests_failed(sr);
39 srunner_free(sr);
40 return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
41}
042
=== added directory 'test/hipd'
=== added file 'test/hipd/netdev.c'
--- test/hipd/netdev.c 1970-01-01 00:00:00 +0000
+++ test/hipd/netdev.c 2011-09-14 12:49:45 +0000
@@ -0,0 +1,92 @@
1/*
2 * Copyright (c) 2011 Aalto University and RWTH Aachen University.
3 *
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use,
8 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following
11 * conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26#include <check.h>
27#include <stdlib.h>
28#include <ifaddrs.h>
29#include <net/if.h>
30
31#include "hipd/netdev.h"
32#include "lib/core/debug.h"
33#include "lib/core/prefix.h"
34#include "test_suites.h"
35
36
37
38START_TEST(test_hip_netdev_find_label_for_address_parameters)
39{
40 struct ifaddrs *myaddrs, *ifa = NULL;
41 char label[IF_NAMESIZE];
42
43 /* The passed label parameter for the function hip_find_label_for_address
44 * must be at least 1 greater than the found label in the function. So
45 * a size of 1 would be for sure too short to store at least the shortest
46 * label of only 1 character.
47 */
48 char label_too_short[1];
49
50 getifaddrs(&myaddrs);
51 for (ifa = myaddrs; ifa != NULL; ifa = ifa->ifa_next) {
52 if (ifa->ifa_addr == NULL ||
53 (ifa->ifa_addr->sa_family != AF_INET &&
54 ifa->ifa_addr->sa_family != AF_INET6)) {
55 continue;
56 }
57 HIP_DEBUG("Size of chosen label: %d\n", sizeof(label));
58 if (ifa->ifa_addr->sa_family == AF_INET) {
59 HIP_DEBUG_INADDR("Try to find label for addr...",
60 hip_cast_sa_addr((struct sockaddr *) (ifa->ifa_addr)));
61 } else {
62 HIP_DEBUG_IN6ADDR("Try to find label for addr...",
63 hip_cast_sa_addr((struct sockaddr *) (ifa->ifa_addr)));
64 }
65
66 fail_unless(hip_netdev_find_label_for_address(ifa->ifa_addr, label, sizeof(label)) == 0,
67 "Could not find label although address must be known.");
68
69 HIP_DEBUG("Found: %s\n", label);
70
71 HIP_DEBUG("Size of chosen label: %d\n", sizeof(label_too_short));
72 HIP_DEBUG("Try to store in the too short chosen label parameter, return has to be 1\n");
73
74 fail_unless(hip_netdev_find_label_for_address(ifa->ifa_addr, label_too_short, sizeof(label_too_short)) == 1,
75 "Not enough memory allocated for the label parameter.");
76
77 HIP_DEBUG("Return of function: %d \n",
78 hip_netdev_find_label_for_address(ifa->ifa_addr, label_too_short, sizeof(label_too_short)));
79 }
80}
81END_TEST
82
83Suite *hipd_netdev(void)
84{
85 Suite *s = suite_create("hipd/netdev");
86
87 TCase *tc_netdev = tcase_create("netdev");
88 tcase_add_test(tc_netdev, test_hip_netdev_find_label_for_address_parameters);
89 suite_add_tcase(s, tc_netdev);
90
91 return s;
92}
093
=== added file 'test/hipd/test_suites.h'
--- test/hipd/test_suites.h 1970-01-01 00:00:00 +0000
+++ test/hipd/test_suites.h 2011-09-14 12:49:45 +0000
@@ -0,0 +1,33 @@
1/*
2 * Copyright (c) 2011 Aalto University and RWTH Aachen University.
3 *
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use,
8 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following
11 * conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26#ifndef HIP_TEST_HIPD_TEST_SUITES_H
27#define HIP_TEST_HIPD_TEST_SUITES_H
28
29#include <check.h>
30
31Suite *hipd_netdev(void);
32
33#endif /* HIP_TEST_HIPD_TEST_SUITES_H */
034
=== modified file 'test/lib/core/hostid.c'
--- test/lib/core/hostid.c 2011-09-05 08:46:53 +0000
+++ test/lib/core/hostid.c 2011-09-14 12:49:45 +0000
@@ -65,7 +65,7 @@
65START_TEST(test_serialize_deserialize_rsa_keys)65START_TEST(test_serialize_deserialize_rsa_keys)
66{66{
67 unsigned int i, keyrr_len = 0;67 unsigned int i, keyrr_len = 0;
68 int bits[3] = {1024, 2048, 3072};68 int bits[3] = { 1024, 2048, 3072 };
69 RSA *key = NULL, *key_deserialized = NULL;69 RSA *key = NULL, *key_deserialized = NULL;
70 EVP_PKEY *key_a = NULL, *key_b = NULL;70 EVP_PKEY *key_a = NULL, *key_b = NULL;
71 unsigned char *keyrr;71 unsigned char *keyrr;

Subscribers

People subscribed via source and target branches