Merge lp:~martin-lp/hipl/hipfwconf into lp:hipl

Proposed by David Martin
Status: Superseded
Proposed branch: lp:~martin-lp/hipl/hipfwconf
Merge into: lp:hipl
Diff against target: 1468 lines (+420/-198)
19 files modified
doc/HOWTO.xml.in (+50/-50)
firewall/cache.c (+1/-1)
firewall/conntrack.c (+54/-1)
firewall/conntrack.h (+2/-0)
firewall/firewall.c (+32/-17)
firewall/firewall.h (+3/-1)
firewall/firewall_control.c (+30/-3)
firewall/firewall_control.h (+2/-2)
hipd/init.c (+2/-2)
hipd/nat.c (+1/-1)
hipd/registration.c (+1/-1)
lib/core/conf.c (+161/-81)
lib/core/conf.h (+5/-0)
lib/core/hostid.c (+1/-1)
lib/core/message.c (+69/-32)
lib/core/message.h (+1/-0)
lib/tool/nlink.c (+1/-1)
tools/hipconf.c (+1/-1)
tools/hipdnsproxy/hipdnsproxy.in (+3/-3)
To merge this branch: bzr merge lp:~martin-lp/hipl/hipfwconf
Reviewer Review Type Date Requested Status
Miika Komu Approve
Diego Biurrun Pending
Review via email: mp+81467@code.launchpad.net

This proposal supersedes a proposal from 2011-11-07.

This proposal has been superseded by a proposal from 2011-11-07.

Description of the change

This branch introduces changes to get the currently active connection from the firewall.

This is a resubmitted merge proposal:
instead of using a separate binary option 1 of the previous discussion is implemented:
> 1) add an extra keyword to the hipconf command line: hipconf (daemon | firewall) COMMAND

Changes since last proposal:
Applied new command syntax to hopefully all documentation and usage.

Summed up changes since the last proposal (revision 6116ff.):
Keywords to address hipd / hipfw are daemon and firewall and defined in lib/core/conf.h.
The hipconf help print has been updated.
Config file syntax does not have to be changed as only hipd parses configs via hipconf and the daemon
keyword is hardcoded.

From what I've tested everything works as before.

To post a comment you must log in.
Revision history for this message
Miika Komu (miika-iki) wrote : Posted in a previous version of this proposal

Why separate binary just for configuring hipfw? Why this can't be embedded into hipconf?

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

On Mon, Oct 24, 2011 at 03:49:25PM +0000, Miika Komu wrote:
> Review: Needs Information
>
> Why separate binary just for configuring hipfw? Why this can't be embedded into hipconf?

Seconded. I'm terribly suspicious of this whole hipconf thing and
whether or not it is a good idea. IIUC authentication is nonexistent
and it's not clear to me what the advantage to rereading a config
file is.

Diego

Revision history for this message
Miika Komu (miika-iki) wrote : Posted in a previous version of this proposal

Another benefit of merged functionality is to allow reading of static information from /etc/hip/hipd_config

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

On 24.10.2011, at 17:49, Miika Komu wrote:
> Why separate binary just for configuring hipfw? Why this can't be embedded into hipconf?

There are three ways to implement this functionality:
1) add an extra keyword to the hipconf command line: hipconf (daemon | firewall) COMMAND
2) add firewall queries as command parameter: hipconf get firewall-ha
3) implement as separate binary using libcore.

(1) would require some changes to hipconf command line parsing and would render the old user API broken. Furthermore, it would require an even longer parameter list for getting specific information. For these reasons, I would not want to implement this option.
(2) is somewhat inconsistent with the current syntax, but I would be fine with that. Only minor changes to the current proposal would be required.
(3) doesn't break the user API and clearly separates hipd configuration from hipfw status querying. This is my preferred option.

Opinions and other proposals are welcome.

Ciao,
René

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

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

Forgot to include launchpad.

Begin forwarded message:
> From: René Hummen <email address hidden>
> Date: 27. Oktober 2011 15:41:06 MESZ
> To: <email address hidden>
> Subject: Re: [hipl-dev] Re: [Merge] lp:~martin-lp/hipl/hipfwconf into lp:hipl
>
> On 24.10.2011, at 19:27, Diego Biurrun wrote:
>> On Mon, Oct 24, 2011 at 03:49:25PM +0000, Miika Komu wrote:
>>> Review: Needs Information
>>>
>>> Why separate binary just for configuring hipfw? Why this can't be embedded into hipconf?
>>
>> Seconded. I'm terribly suspicious of this whole hipconf thing and
>> whether or not it is a good idea. IIUC authentication is nonexistent
>> and it's not clear to me what the advantage to rereading a config
>> file is.
>
> The issue of having one or multiple binaries aside, I think hipconf should rather be a hipstatus tool. I.e., hipd and hipfw should be configured via config files (with reload functionality) and the the current run-time status should be requestable via hipstatus. However, this is not as it's done in HIPL at the moment. Instead, reading the config file mimics calls to hipconf in order to set up the hipd. hipfwconf, on the other hand, only provides status information.
>
> Do I see volunteers who are willing to fix this hipconf-based configuration issue? :)
>
> Ciao,
> René

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

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

On 25.10.2011, at 09:42, Miika Komu wrote:
> Another benefit of merged functionality is to allow reading of static information from /etc/hip/hipd_config

I don't see your point here. Can you please explain. By the way, hipfwconf wraps around libcore the same way hipconf does.

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

Revision history for this message
Miika Komu (miika-iki) wrote : Posted in a previous version of this proposal

> IIUC authentication is nonexistent

This a fallacy, it does have authentication. Critical functions are allowed only for root.

> and it's not clear to me what the advantage to rereading a config
> file is.

Obviously, changing of parameters during run time.

Revision history for this message
Miika Komu (miika-iki) wrote : Posted in a previous version of this proposal

> On 25.10.2011, at 09:42, Miika Komu wrote:
> > Another benefit of merged functionality is to allow reading of static
> information from /etc/hip/hipd_config
>
> I don't see your point here. Can you please explain. By the way, hipfwconf
> wraps around libcore the same way hipconf does.

You mean that you can set hipfwconf parameters from /etc/hip/hipd_config ? Did you test this?

Revision history for this message
Miika Komu (miika-iki) wrote : Posted in a previous version of this proposal

> On 24.10.2011, at 17:49, Miika Komu wrote:
> > Why separate binary just for configuring hipfw? Why this can't be embedded
> into hipconf?
>
> There are three ways to implement this functionality:
> 1) add an extra keyword to the hipconf command line: hipconf (daemon |
> firewall) COMMAND
> 2) add firewall queries as command parameter: hipconf get firewall-ha

Either of these would work for me. Probably 1 is a bit cleaner.

> 3) implement as separate binary using libcore.

I'll counterargument against this below.

> (1) would require some changes to hipconf command line parsing and would
> render the old user API broken. Furthermore, it would require an even longer
> parameter list for getting specific information. For these reasons, I would
> not want to implement this option.

Who cares if the API is changes, really? By breaking, you mean /etc/hip/hipd_config? The file could be prefixed with a "daemon" with a simple regexp when you start hipd (if we would choose #1).

> (2) is somewhat inconsistent with the current syntax, but I would be fine with
> that. Only minor changes to the current proposal would be required.

I would be fine with this.

> (3) doesn't break the user API and clearly separates hipd configuration from
> hipfw status querying. This is my preferred option.

Proposal 3 also fragments the HIP administrative interface into two. You suggest that we'll have one read-only interface and another writeable. I believe in a more unified interface and I fail see why we should disperse. It doesn't sound very responsible to say something is bad, but leave it as it is and switch to new tool?

What do you mean by "hipconf-based configuration issue"?

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

On Thu, Oct 27, 2011 at 01:31:29PM +0000, René Hummen wrote:
> On 24.10.2011, at 17:49, Miika Komu wrote:
> > Why separate binary just for configuring hipfw? Why this can't be embedded into hipconf?
>
> There are three ways to implement this functionality:
> 1) add an extra keyword to the hipconf command line: hipconf (daemon | firewall) COMMAND
> 2) add firewall queries as command parameter: hipconf get firewall-ha
> 3) implement as separate binary using libcore.
>
> (1) would require some changes to hipconf command line parsing and
> would render the old user API broken. Furthermore, it would require an
> even longer parameter list for getting specific information. For these
> reasons, I would not want to implement this option.

alias hipdconf="hipconf daemon"
alias hipfwconf="hipconf firewall"

Diego

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

 review needs-fixing

On Mon, Oct 31, 2011 at 06:22:27PM +0000, David Martin wrote:
>
> --- Makefile.am 2011-10-17 18:14:10 +0000
> +++ Makefile.am 2011-10-31 18:21:26 +0000
> @@ -90,8 +90,8 @@
>
> -tools_hipconf_SOURCES = tools/hipconf.c
> -tools_pisacert_SOURCES = tools/pisacert.c
> +tools_hipconf_SOURCES = tools/hipconf.c
> +tools_pisacert_SOURCES = tools/pisacert.c

unrelated

Diego

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

hip_send_recv_firewall_info() has been copy-pasted from hip_send_recv_daemon_info(). The same goes for
hip_send_recv_firewall_info() and hip_handle_user_msg(). Code reuse?

lib/core/conf.c:hipconf_usage is not updated accordingly. Same goes for hipd/init.c:HIPL_CONFIG_FILE_EX. Otherwise, nobody will know about your extensions.

Also, I would like to hear a test report with some existing hipconf options to understand that legacy support still works. For example, try the following:

* hipconf add map HIT IP
* hipconf get ha all
* hipconf rst all

<wait few secs>

* hipconf nat none
* hipconf add map HIT IP
* hipconf get ha all
* hipconf rst all

<wait few secs>

* hipconf nat plain-udp
* hipconf add map HIT IP
* hipconf get ha all
* hipconf rst all

<wait few secs>

* hipconf nat port 1111
* hipconf add map HIT IP
* hipconf get ha all
* hipconf rst all

Does it do what expected?

Other than this, I am satisfied with this commit.

review: Needs Fixing
Revision history for this message
David Martin (martin-lp) wrote : Posted in a previous version of this proposal

Hi,

On Mon, Oct 31, 2011 at 9:58 PM, Diego Biurrun <email address hidden> wrote:
> On Mon, Oct 31, 2011 at 06:22:27PM +0000, David Martin wrote:
>> --- Makefile.am 2011-10-17 18:14:10 +0000
>> +++ Makefile.am 2011-10-31 18:21:26 +0000
>> @@ -90,8 +90,8 @@
>>
>> -tools_hipconf_SOURCES = tools/hipconf.c
>> -tools_pisacert_SOURCES = tools/pisacert.c
>> +tools_hipconf_SOURCES = tools/hipconf.c
>> +tools_pisacert_SOURCES = tools/pisacert.c
>
> unrelated

That's not really unrelated but unintended. Forgot to reindent after removing the hipfwconf line. Fixed now.

Revision history for this message
David Martin (martin-lp) wrote : Posted in a previous version of this proposal

Hi,

On Wed, Nov 2, 2011 at 8:32 AM, Miika Komu <email address hidden> wrote:
> Review: Needs Fixing
>
> hip_send_recv_firewall_info() has been copy-pasted from hip_send_recv_daemon_info().

You are right, that has been some pretty evil piece of copy-paste. Fixed this in revision 6121.

> The same goes for hip_send_recv_firewall_info() and hip_handle_user_msg(). Code reuse?

What exactly do you mean?

> lib/core/conf.c:hipconf_usage is not updated accordingly. Same goes for hipd/init.c:HIPL_CONFIG_FILE_EX. Otherwise, nobody will know about your extensions.

I changed it where hipconf_usage was used but this may have not been clear enough.
I've fixed it in revision 6122. Should be better now.

> Also, I would like to hear a test report with some existing hipconf options to understand that legacy support still works. For example, try the following:
>
> * hipconf add map HIT IP
> * hipconf get ha all
> * hipconf rst all
>
> <wait few secs>
>
> * hipconf nat none
> * hipconf add map HIT IP
> * hipconf get ha all
> * hipconf rst all
>
> <wait few secs>
>
> * hipconf nat plain-udp
> * hipconf add map HIT IP
> * hipconf get ha all
> * hipconf rst all
>
> <wait few secs>
>
> * hipconf nat port 1111
> * hipconf add map HIT IP
> * hipconf get ha all
> * hipconf rst all
>
> Does it do what expected?

Did not test that yet but I'll have a look into it and report back.

Revision history for this message
Miika Komu (miika-iki) wrote : Posted in a previous version of this proposal

Hi,

On 11/02/2011 01:04 PM, David Martin wrote:
>> The same goes for hip_send_recv_firewall_info() and hip_handle_user_msg(). Code reuse?
> What exactly do you mean?

the functions offer very similar functionality (copy paste).

Revision history for this message
David Martin (martin-lp) wrote : Posted in a previous version of this proposal

Hi again,

On Wed, Nov 2, 2011 at 12:25 PM, Miika Komu <email address hidden> wrote:
> On 11/02/2011 01:04 PM, David Martin wrote:
>>>
>>> The same goes for hip_send_recv_firewall_info() and
>>> hip_handle_user_msg(). Code reuse?
>>
>> What exactly do you mean?
>
> the functions offer very similar functionality (copy paste).

Sorry for being a bit dense but I'm still not sure what you mean.
hip_handle_user_msg() is an enormous beast of a function dealing with all incoming
hipconf messages. hip_send_recv_firewall_info() sends messages to hipfw and
since the last commit is nothing more than a wrapper for send_recv_info_internal().

Maybe you mean hip_handle_msg() in firewall_control.c which basically does the same
as hip_handle_user_msg() only for the firewall. It has not really been touched in this
branch and I see no reason to merge them together. It would result in an even bigger
and even more unwieldy function. The firewall does receive user messages of the same
message type, but it acts differently on them than hipd. I think it's reasonable to keep them
apart. We should think about renaming them to make their purpose more obvious but this
is out of scope of this branch.

Revision history for this message
Miika Komu (miika-iki) wrote : Posted in a previous version of this proposal

Sorry, I mean fw_handle_hipd_message() and hip_handle_user_msg(). It seems that the beginning of the functions is copy paste. You could extract the beginning into another function and call it in the other two.

Revision history for this message
David Martin (martin-lp) wrote : Posted in a previous version of this proposal
Download full text (3.7 KiB)

Hi,

On Wed, Nov 2, 2011 at 3:26 PM, Miika Komu <email address hidden> wrote:
> Sorry, I mean fw_handle_hipd_message() and hip_handle_user_msg(). It seems that the beginning of the functions is copy paste. You could extract the beginning into another function and call it in the other two.

You are right. But if I see it correctly those two weren't really touched by this branch so I would
say it's not related. Feel free to change it in trunk. :)))

PS: Fixed non-compiling make doxygen and added error-handling for wrong process keywords in the last two revisions.

PPS: Had a look at your proposed commands as well. They seem to work alright as far as I can judge. Here's a log:

martin@pisa1:~/src/hipl/hipl_hipfwconf$ sudo tools/hipconf daemon add map 2001:17:e5ab:56b2:3b45:419f:f784:af6a 10.0.3.1
Mapped v4 to v6.
mapped v6: 10.0.3.1
Sending user message 2 to HIPD on socket 3
Sent 88 bytes
Waiting to receive daemon info.
88 bytes received from HIP daemon.
User message was sent successfully to the HIP daemon.

martin@pisa1:~/src/hipl/hipl_hipfwconf$ sudo tools/hipconf daemon get ha all
Sending user message 22 to HIPD on socket 3
Sent 40 bytes
Waiting to receive daemon info.
248 bytes received from HIP daemon.
HA is UNASSOCIATED
 Shotgun mode is off.
 Broadcast mode is off.
 Local HIT: 2001:0017:e5ab:56b2:3b45:419f:f784:af6a
 Peer HIT: 2001:0017:e5ab:56b2:3b45:419f:f784:af6a
 Local LSI: 1.0.0.1
 Peer LSI: 1.0.0.1
 Local IP: 10.0.3.1
 Local NAT traversal UDP port: 10500
 Peer IP: 10.0.3.1
 Peer NAT traversal UDP port: 10500
 Peer hostname:

martin@pisa1:~/src/hipl/hipl_hipfwconf$ sudo tools/hipconf daemon rst all
Sending user message 68 to HIPD on socket 3
Sent 64 bytes
Waiting to receive daemon info.
64 bytes received from HIP daemon.
User message was sent successfully to the HIP daemon.

martin@pisa1:~/src/hipl/hipl_hipfwconf$ sudo tools/hipconf daemon get ha all
Sending user message 22 to HIPD on socket 3
Sent 40 bytes
Waiting to receive daemon info.
40 bytes received from HIP daemon.

martin@pisa1:~/src/hipl/hipl_hipfwconf$ sudo tools/hipconf daemon nat none
<snip>

martin@pisa1:~/src/hipl/hipl_hipfwconf$ sudo tools/hipconf daemon add map 2001:17:e5ab:56b2:3b45:419f:f784:af6a 10.0.3.1
<snip>

martin@pisa1:~/src/hipl/hipl_hipfwconf$ sudo tools/hipconf daemon get ha all
<snip>
HA is UNASSOCIATED
 Shotgun mode is off.
 Broadcast mode is off.
 Local HIT: 2001:0017:e5ab:56b2:3b45:419f:f784:af6a
 Peer HIT: 2001:0017:e5ab:56b2:3b45:419f:f784:af6a
 Local LSI: 1.0.0.1
 Peer LSI: 1.0.0.1
 Local IP: 10.0.3.1
 Local NAT traversal UDP port: 0
 Peer IP: 10.0.3.1
 Peer NAT traversal UDP port: 0
 Peer hostname:

martin@pisa1:~/src/hipl/hipl_hipfwconf$ sudo tools/hipconf daemon nat plain-udp
<snip>

martin@pisa1:~/src/hipl/hipl_hipfwconf$ sudo tools/hipconf daemon get ha all
<snip>
HA is UNASSOCIATED
 Shotgun mode is off.
 Broadcast mode is off.
 Local HIT: 2001:0017:e5ab:56b2:3b45:419f:f784:af6a
 Peer HIT: 2001:0017:e5ab:56b2:3b45:419f:f784:af6a
 Local LSI: 1.0.0.1
 Peer LSI: 1.0.0.1
 Local IP: 10.0.3.1
 Local NAT traversal UDP port: 10500
 Peer IP: 10.0.3.1
 Peer NAT traversal UDP port: 10500
 Peer hostname:

martin@pisa1:~/src/hipl/hipl_hi...

Read more...

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

On 27.10.2011, at 16:37, Miika Komu wrote:
>> On 25.10.2011, at 09:42, Miika Komu wrote:
>>> Another benefit of merged functionality is to allow reading of static
>> information from /etc/hip/hipd_config
>>
>> I don't see your point here. Can you please explain. By the way, hipfwconf
>> wraps around libcore the same way hipconf does.
>
> You mean that you can set hipfwconf parameters from /etc/hip/hipd_config ? Did you test this?

Hmmm, I'm not sure what this discussion was about exactly. Maybe some clarification as to what kind of functionality this branch is supposed to introduce: it allows to request status information from hipfw at run-time. However, it does not allow for run-time configuration right now. Of course, it would be easy to extend hipfw with this functionality, but I don't see that this desirable.

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

Revision history for this message
Miika Komu (miika-iki) wrote : Posted in a previous version of this proposal

> Hmmm, I'm not sure what this discussion was about exactly. Maybe some clarification as to what kind of functionality
> this branch is supposed to introduce: it allows to request status information from hipfw at run-time. However, it
> does not allow for run-time configuration right now. Of course, it would be easy to extend hipfw with this
> functionality, but I don't see that this desirable.

Never mind (now hipd_config can be used to trigger hipfw actions as well).

review: Approve
Revision history for this message
David Martin (martin-lp) wrote : Posted in a previous version of this proposal

Diego, your opinion? :)

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

 review needs-fixing

On Mon, Oct 31, 2011 at 06:22:27PM +0000, David Martin wrote:
>
> --- lib/core/conf.h 2011-08-15 14:11:56 +0000
> +++ lib/core/conf.h 2011-10-31 18:21:26 +0000
> @@ -54,6 +54,11 @@
>
> +enum daemon_name { HIP_DAEMON, HIP_FIREWALL };
> +/* keywords used to identify hipd / hipfw as target of hipconf command */
> +#define HIPCONF_HIPD_KEYWORD "daemon"
> +#define HIPCONF_HIPFW_KEYWORD "firewall"

These appear unused outside of conf.c.

Diego

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

On Fri, Nov 04, 2011 at 12:07:34PM +0000, David Martin wrote:
> Diego, your opinion? :)

I said enough to reject it already, just added some more ;)

Diego

Revision history for this message
David Martin (martin-lp) wrote : Posted in a previous version of this proposal

Hi,

On Fri, Nov 4, 2011 at 1:25 PM, Diego Biurrun <email address hidden> wrote:
> On Mon, Oct 31, 2011 at 06:22:27PM +0000, David Martin wrote:
>>
>> --- lib/core/conf.h 2011-08-15 14:11:56 +0000
>> +++ lib/core/conf.h 2011-10-31 18:21:26 +0000
>> @@ -54,6 +54,11 @@
>>
>> +enum daemon_name { HIP_DAEMON, HIP_FIREWALL };
>> +/* keywords used to identify hipd / hipfw as target of hipconf command */
>> +#define HIPCONF_HIPD_KEYWORD "daemon"
>> +#define HIPCONF_HIPFW_KEYWORD "firewall"
>
> These appear unused outside of conf.c.

Nope, using them in lib/core/message.c as well. Did you pull the latest revisions?

On Fri, Nov 4, 2011 at 1:29 PM, Diego Biurrun <email address hidden> wrote:
> I said enough to reject it already, just added some more ;)

Well, other than you being terribly suspicious of hipconf in general you did not say
aynthing. And that's not very constructive. :p

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

On Fri, Nov 04, 2011 at 12:53:25PM +0000, David Martin wrote:
> On Fri, Nov 4, 2011 at 1:25 PM, Diego Biurrun <email address hidden> wrote:
> > On Mon, Oct 31, 2011 at 06:22:27PM +0000, David Martin wrote:
> >>
> >> --- lib/core/conf.h 2011-08-15 14:11:56 +0000
> >> +++ lib/core/conf.h 2011-10-31 18:21:26 +0000
> >> @@ -54,6 +54,11 @@
> >>
> >> +enum daemon_name { HIP_DAEMON, HIP_FIREWALL };
> >> +/* keywords used to identify hipd / hipfw as target of hipconf command */
> >> +#define HIPCONF_HIPD_KEYWORD "daemon"
> >> +#define HIPCONF_HIPFW_KEYWORD "firewall"
> >
> > These appear unused outside of conf.c.
>
> Nope, using them in lib/core/message.c as well. Did you pull the latest revisions?

Of course not! I don't pull anything to review your work, why would I?
I just sit here and read emails. I should not have to care about you
committing new revisions somewhere I'm not looking.

> On Fri, Nov 4, 2011 at 1:29 PM, Diego Biurrun <email address hidden> wrote:
> > I said enough to reject it already, just added some more ;)
>
> Well, other than you being terribly suspicious of hipconf in general you did not say
> aynthing. And that's not very constructive. :p

I said there were unrelated stray changes - that's ground enough not to
commit it so I did not bother to look in detail at a version that will
not be pushed anyway ;)

Diego

Revision history for this message
Miika Komu (miika-iki) wrote : Posted in a previous version of this proposal

Good work!

review: Approve
Revision history for this message
Miika Komu (miika-iki) wrote : Posted in a previous version of this proposal

Sorry, I stumbled on a problem after hitting the Approve button. "hipconf daemon" is needed now for all existing commands, right? If yes, then this need to be properly adjusted in:

* doc/HOWTO.xml.in
* lib/core/conf.c
* lib/core/hostid.c
* lib/core/message.c
* lib/tool/nlink.c
* hipd/nat.c
* tools/hipdnsproxy/hipdnsproxy.in
* firewall/conntrack.c
* firewall/cache.c

Scan for "hipconf" in the files and adjust where appropiate.

review: Needs Fixing
Revision history for this message
David Martin (martin-lp) wrote : Posted in a previous version of this proposal

Hi,

On Mon, Nov 7, 2011 at 3:33 PM, Miika Komu <email address hidden> wrote:
> Review: Needs Fixing
>
> Sorry, I stumbled on a problem after hitting the Approve button. "hipconf daemon" is needed now for all existing commands, right? If yes, then this need to be properly adjusted in:
>
> * doc/HOWTO.xml.in
> * lib/core/conf.c
> * lib/core/hostid.c
> * lib/core/message.c
> * lib/tool/nlink.c
> * hipd/nat.c
> * tools/hipdnsproxy/hipdnsproxy.in
> * firewall/conntrack.c
> * firewall/cache.c
>
> Scan for "hipconf" in the files and adjust where appropiate.

Good catch! Should've thought about grepping through the other files to find hipconf occurances. I would have missed the *.in for sure though.

Fixed this and will resubmit the proposal.

Revision history for this message
David Martin (martin-lp) wrote :

Sorry, seems like I oversaw a merge conflict. Will fix this and retransmit.

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

Let's make it final this time :)

review: Approve
lp:~martin-lp/hipl/hipfwconf updated
6113. By David Martin

Make hipconf_usage string static as it is local to lib/core/conf.c.

6134. By David Martin

Fix some stray error messages referring incorrectly only to the HIP daemon.

Make them more generic by adding the firewall as well.

6135. By David Martin

Correct header #include ordering in firewall_control.c.

6136. By David Martin

Make hipfwconf_usage static as it's local to conf.c.

6137. By David Martin

Cosmetics: Fix typo in conf_get_process() documentation.

6138. By David Martin

Make daemon_name enum static, it is local to lib/core/conf.c.

6139. By David Martin

Refer to daemon in error messages instead of mentioning both hipd and hipfw.

6140. By David Martin

Use 'the' when referring to the daemon in conf.c/message.c error messages.

Sounds a lot better this way.

6141. By David Martin

Move daemon_name enum to lib/core/conf.c as it is only used there.

6142. By David Martin

Return enum daemon_name instead of int in conf_get_process().

If we have got a named enum for that purpose we may as well use it.

6143. By David Martin

Make conf_get_process() const-correct.

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'doc/HOWTO.xml.in'
2--- doc/HOWTO.xml.in 2011-11-03 09:21:12 +0000
3+++ doc/HOWTO.xml.in 2011-11-07 17:07:26 +0000
4@@ -594,7 +594,7 @@
5
6 <itemizedlist>
7 <listitem><programlisting>Version of HIPL software. Ubuntu: dpkg -l 'hipl*'. Red Hat-based distros: rpm -qa | grep hipl</programlisting></listitem>
8- <listitem><programlisting>hipconf get ha all</programlisting></listitem>
9+ <listitem><programlisting>hipconf daemon get ha all</programlisting></listitem>
10 <listitem><programlisting>ip xfrm state</programlisting></listitem>
11 <listitem><programlisting>uname -a</programlisting></listitem>
12 <listitem><programlisting>lsb_release -a</programlisting></listitem>
13@@ -658,7 +658,7 @@
14
15 <para>To use access the servers using HIP behind a NAT box, you
16 have two alternatives. Firstly, you enable the UDP
17- encapsulation using "hipconf nat plain-udp". See <xref
18+ encapsulation using "hipconf daemon nat plain-udp". See <xref
19 linkend="ch_hip_nat" /> for more information. Secondly,
20 you can install miredo on your machine and make sure that HIP
21 uses the IPv6 address of the server.</para>
22@@ -674,7 +674,7 @@
23 <title>Closing HIP Security Associations Manually</title>
24 <para>
25 You can use the hipconf tool to reset HIP SAs manually. Type
26- "hipconf rst all" to close all SAs.
27+ "hipconf daemon rst all" to close all SAs.
28 </para>
29 </section>
30
31@@ -761,10 +761,10 @@
32 HIT_OF_XXX with the HIT of the host XXX. The hip daemon loads (and
33 creates if necessary) the host identities from @sysconfdir@ automatically.
34 If you want to know the default HIT of the localhost, run
35- "hipconf get hi default".
36- You can list all HITs of the machine with "hipconf get hi all". By
37+ "hipconf daemon get hi default".
38+ You can list all HITs of the machine with "hipconf daemon get hi all". By
39 default, you'll see only one. If you want to use all four HITs of the
40- host, you have to invoke "hipconf add hi default". The use of multiple
41+ host, you have to invoke "hipconf daemon add hi default". The use of multiple
42 local HITs is not currently recommended!
43 </para>
44 <para>
45@@ -773,7 +773,7 @@
46 possible but not necessary:
47 </para>
48 <para>
49- hipconf add map PEER_HIT PEER_IP
50+ hipconf daemon add map PEER_HIT PEER_IP
51 </para>
52 <para>
53 You can also add the mapping to "@sysconfdir@/hipd_config" and restart hipd.
54@@ -830,18 +830,18 @@
55 more information messages with the daemons or capturing the network packets.</para>
56 <para>The log messages displayed by the hip daemon can be changed dynamically:</para>
57 <para>
58- hipconf debug none # &lt;only HIP_DIE and HIP_ASSERT messages are shown&gt;
59+ hipconf daemon debug none # &lt;only HIP_DIE and HIP_ASSERT messages are shown&gt;
60 </para>
61 <para>
62- hipconf debug low # &lt;shows HIP_DIE, HIP_ASSERT and HIP_ERROR
63+ hipconf daemon debug low # &lt;shows HIP_DIE, HIP_ASSERT and HIP_ERROR
64 messages&gt;
65 </para>
66 <para>
67- hipconf debug medium # &lt;shows HIP_DIE, HIP_ASSERT, HIP_ERROR and
68+ hipconf daemon debug medium # &lt;shows HIP_DIE, HIP_ASSERT, HIP_ERROR and
69 HIP_INFO messages&gt;
70 </para>
71 <para>
72- hipconf debug all # &lt;shows all messages, including
73+ hipconf daemon debug all # &lt;shows all messages, including
74 HIP_DEBUG&gt;
75 </para>
76 <para>
77@@ -882,14 +882,14 @@
78 </para>
79 </listitem>
80 <listitem>
81- <para>Add the information with hipconf add map
82+ <para>Add the information with hipconf daemon add map
83 <itemizedlist>
84- <listitem><para>hipconf add map OOPS_HIT OOPS_IP [OOPS_LSI] </para></listitem>
85+ <listitem><para>hipconf daemon add map OOPS_HIT OOPS_IP [OOPS_LSI] </para></listitem>
86 </itemizedlist>
87 </para>
88 </listitem>
89 </itemizedlist>
90- <para>If the command hipconf add map is not executed, we must add the peer IP in
91+ <para>If the command hipconf daemon add map is not executed, we must add the peer IP in
92 the file /etc/hosts</para>
93 <itemizedlist>
94 <listitem><para>OOPS_IP oops</para></listitem>
95@@ -929,7 +929,7 @@
96 <formalpara><title>Running the application</title><para></para></formalpara>
97 <para>Once we have finished the step before and started running hipd and hipfw, we can
98 run the application. If the LSI has been generated automatically, we can check its
99- value with hipconf get ha OOPS_HIT or hipconf get ha all.
100+ value with hipconf daemon get ha OOPS_HIT or hipconf daemon get ha all.
101 Afterwards, we start running the application, e.g.:
102 </para>
103 <itemizedlist>
104@@ -989,7 +989,7 @@
105 </itemizedlist>
106 <para>
107 You can also trigger the handover message exchange without
108- changing IP addresses by running "hipconf manual-update". Note that this
109+ changing IP addresses by running "hipconf daemon manual-update". Note that this
110 only simulates the message exchange that would normally occur on IP
111 address changes and does not test handover detection.
112 </para>
113@@ -1056,9 +1056,9 @@
114 /etc/hosts.
115 </para>
116 <para>
117- 3b. Execute "hipconf add map PEER_HIT PEER_IP" and use the HIT directly
118+ 3b. Execute "hipconf daemon add map PEER_HIT PEER_IP" and use the HIT directly
119 in the application. You can insert the
120- hipconf command also to @sysconfdir@/hipd_config and restart hipd.
121+ hipconf command without daemon keyword also to @sysconfdir@/hipd_config and restart hipd.
122 </para>
123 </section>
124
125@@ -1107,7 +1107,7 @@
126 run at that time):
127 </para>
128 <para>
129- hipconf run normal|opp firefox
130+ hipconf daemon run normal|opp firefox
131 </para>
132 </section>
133 <section id="sec_sendmail">
134@@ -1167,7 +1167,7 @@
135 </programlisting>
136 <para>
137 The "HIT_OF_THE_CLIENT" should not be taken as literal. Replace it with the
138- actual HIT of the client (run "hipconf get ha default" at the client host).
139+ actual HIT of the client (run "hipconf daemon get ha default" at the client host).
140 </para>
141 <para>
142 It should be noticed that you can also specify the HIT_OF_CLIENT at the
143@@ -1412,7 +1412,7 @@
144 </programlisting>
145 <para>
146 Notice that &lt;hit-of-the-server&gt; should not be taken literally. Replace
147- it with the HIT of the server (run "hipconf get hi default" at the server).
148+ it with the HIT of the server (run "hipconf daemon get hi default" at the server).
149 If you want to use LSIs instead of HITs, you shouldn't use the -V option
150 and use LSIs as instructed in <xref linkend="interop_ip_v4_v6" />.
151 </para>
152@@ -1624,15 +1624,15 @@
153 </para>
154
155 <para>
156- With "hipconf hit-to-ip on", the HIP daemon uses IP addresses of
157+ With "hipconf daemon hit-to-ip on", the HIP daemon uses IP addresses of
158 5.7.d.1.c.c.8.d.0.6.3.b.a.4.6.2.5.0.5.2.e.4.7.5.e.1.0.0.1.0.0.2.hit-to-ip.infrahip.net.
159 to contact peer host with HIT 2001:1e:574e:2505:264a:b360:d8cc:1d75
160 </para>
161 <para>Default hit-to-ip.infrahip.net. suffix can be changed with
162- "hipconf hit-to-ip-set &lt;new.hit-to-ip.zone.&gt;. Please note it is independent from HIT_TO_IP_ZONE in @sysconfdir@/nsupdate.conf"
163+ "hipconf daemon hit-to-ip-set &lt;new.hit-to-ip.zone.&gt;. Please note it is independent from HIT_TO_IP_ZONE in @sysconfdir@/nsupdate.conf"
164 </para>
165 <para>
166- With "hipconf nsupdate on", the HIP daemon also maintains
167+ With "hipconf daemon nsupdate on", the HIP daemon also maintains
168 records in hit-to-ip.infrahip.net. Once you start hipd, it will
169 call nsupdate.pl with HIT and IP address for every HIT of your
170 host. It is executed upon mobility events (i.e. address changes)
171@@ -1799,7 +1799,7 @@
172 the HIP daemon at the responder and use the "<emphasis>hipconf</emphasis>" tool from another
173 shell at the responder to get the default hi:
174 <programlisting>
175- hipconf get hi default
176+ hipconf daemon get hi default
177 </programlisting>
178 Now, add this HIT in between the white list quotation marks in the
179 configuration file of the RVS / HIP relay server:
180@@ -1849,10 +1849,10 @@
181 otherwise modify the configuration file, you can reinitialize the server
182 without restarting the daemon itself using the "<emphasis>hipconf</emphasis>" tool:
183 <programlisting>
184- hipconf reinit service rvs</programlisting>
185+ hipconf daemon reinit service rvs</programlisting>
186 or
187 <programlisting>
188- hipconf reinit service relay</programlisting>
189+ hipconf daemon reinit service relay</programlisting>
190 The reinitialization does not have any effect on the existing
191 RVS / HIP relay server clients, but only affects clients registering
192 after the reinitialization.
193@@ -1963,7 +1963,7 @@
194 that you would have in a normal base exchange execution not
195 involving an RVS. Please make sure that you use the same HIT
196 here as &lt;RESPONDER HIT&gt; as what the
197- "<emphasis>hipconf get hi default</emphasis>"
198+ "<emphasis>hipconf daemon get hi default</emphasis>"
199 outputs at the responder.
200 </para>
201 </listitem>
202@@ -2012,14 +2012,14 @@
203 </para></listitem>
204 <listitem><para>
205 At the rendezvous server, we have to indicate that we are willing to offer
206- rendezvous service:<programlisting>hipconf add service rvs</programlisting>
207+ rendezvous service:<programlisting>hipconf daemon add service rvs</programlisting>
208 </para></listitem>
209 <listitem id="listitem_rvs"><para>
210 At the responder, we have to register to the rendezvous server:
211- <programlisting>hipconf add server rvs [RVS-HIT] &lt;RVS-IP or hostname&gt; &lt;LIFETIME-IN-SECONDS&gt;</programlisting>
212+ <programlisting>hipconf daemon add server rvs [RVS-HIT] &lt;RVS-IP or hostname&gt; &lt;LIFETIME-IN-SECONDS&gt;</programlisting>
213 This will launch a base exchange i.e. establish a HIP SA between the
214 rendezvous server and the responder. Please use the default HIT of
215- the rendezvous server ("<emphasis>hipconf get hi default</emphasis>" at the RVS).
216+ the rendezvous server ("<emphasis>hipconf daemon get hi default</emphasis>" at the RVS).
217 The &lt;LIFETIME-IN-SECONDS&gt; value represents the number of seconds
218 we would like our service registration to last, but it is not
219 necessarily the number of seconds we are granted the service.
220@@ -2053,7 +2053,7 @@
221 To cancel the rendezvous service (without killing the HIP
222 daemon) type:
223 <programlisting>
224- hipconf del service rvs
225+ hipconf daemon del service rvs
226 </programlisting>
227 This will delete all existing rendezvous server registrations
228 and remove the rendezvous service from the offered services.
229@@ -2064,7 +2064,7 @@
230 To reinitialize the rendezvous service after modifications to
231 the configuration file (without killing the HIP daemon) type:
232 <programlisting>
233- hipconf reinit service rvs
234+ hipconf daemon reinit service rvs
235 </programlisting>
236 The changes that you have made to the configuration file affect the
237 clients registering after the reinitialization.
238@@ -2082,7 +2082,7 @@
239 <para>
240 To cancel the registration to the rendezvous service type:
241 <programlisting>
242- hipconf del server rvs &lt;RVS-HIT&gt; &lt;RVS-IP&gt;
243+ hipconf daemon del server rvs &lt;RVS-HIT&gt; &lt;RVS-IP&gt;
244 </programlisting>
245 This will send a HIP message asking for rendezvous service
246 cancellation to the rendezvous server.
247@@ -2237,17 +2237,17 @@
248 At the relay server, we have to indicate that we are willing to offer
249 relay service:
250 <programlisting>
251- hipconf add service relay
252+ hipconf daemon add service relay
253 </programlisting>
254 </para></listitem>
255 <listitem><para>
256 At the responder, we have to register to the relay server:
257 <programlisting>
258- hipconf add server relay &lt;RELAY-HIT&gt; &lt;RELAY-IP&gt; &lt;LIFETIME-IN-SECONDS&gt;
259+ hipconf daemon add server relay &lt;RELAY-HIT&gt; &lt;RELAY-IP&gt; &lt;LIFETIME-IN-SECONDS&gt;
260 </programlisting>
261 This will launch a base exchange i.e. establish a HIP SA between the
262 relay server and the responder. Please use the default HIT of the
263- relay server ("<emphasis>hipconf get hi default</emphasis>" at
264+ relay server ("<emphasis>hipconf daemon get hi default</emphasis>" at
265 the relay server). The &lt;LIFETIME-IN-SECONDS&gt; value represents
266 the number of seconds we would like our service registration to
267 last, but it is not necessarily the number of seconds we are granted
268@@ -2285,7 +2285,7 @@
269 To cancel the relay service (without killing the HIP daemon)
270 type:
271 <programlisting>
272- hipconf del service relay
273+ hipconf daemon del service relay
274 </programlisting>
275 This will delete all existing relay server registrations
276 and remove the relay service from the offered services.
277@@ -2296,7 +2296,7 @@
278 To reinitialize the relay service after modifications to
279 the configuration file (without killing the HIP daemon) type:
280 <programlisting>
281- hipconf reinit service relay
282+ hipconf daemon reinit service relay
283 </programlisting>
284 The changes that you have made to the configuration file affect the
285 clients registering after the reinitialization.
286@@ -2314,7 +2314,7 @@
287 <para>
288 To cancel the registration to the relay service type:
289 <programlisting>
290- hipconf del server relay &lt;RELAY-HIT&gt; &lt;RELAY-IP&gt;
291+ hipconf daemon del server relay &lt;RELAY-HIT&gt; &lt;RELAY-IP&gt;
292 </programlisting>
293 This will send a HIP message asking for relay service
294 cancellation to the relay server.
295@@ -2494,7 +2494,7 @@
296 example, to request a service identified by number 1 (the
297 rendezvous service), you can type
298 <programlisting>
299- hipconf add server 1 &lt;SERVER-HIT&gt; &lt;SERVER-IP&gt; &lt;LIFETIME-IN-SECONDS&gt;
300+ hipconf daemon add server 1 &lt;SERVER-HIT&gt; &lt;SERVER-IP&gt; &lt;LIFETIME-IN-SECONDS&gt;
301 </programlisting>
302 Notice, however, that if the server does not support the
303 service you have requested, a request is never sent.
304@@ -2506,7 +2506,7 @@
305 can chain the service types. For example, to request services
306 identified by registration types 3, 10 and 245 you can type:
307 <programlisting>
308- hipconf add server 3 10 245 &lt;SERVER-HIT&gt; &lt;SERVER-IP&gt; &lt;LIFETIME-IN-SECONDS&gt;
309+ hipconf daemon add server 3 10 245 &lt;SERVER-HIT&gt; &lt;SERVER-IP&gt; &lt;LIFETIME-IN-SECONDS&gt;
310 </programlisting>
311 Using this chaining method one can request up to ten
312 services with one REG_REQUEST parameter.
313@@ -2518,7 +2518,7 @@
314 request you can chain the service types as with
315 registration.
316 <programlisting>
317- hipconf del server 3 10 245 &lt;SERVER-HIT&gt; &lt;SERVER-IP&gt;
318+ hipconf daemon del server 3 10 245 &lt;SERVER-HIT&gt; &lt;SERVER-IP&gt;
319 </programlisting>
320 Using this chaining method one can request up to ten
321 service cancellations with one REG_REQUEST parameter.
322@@ -2696,7 +2696,7 @@
323 </para>
324 <para>The NAT traversal can be experimented in a similar way as depicted
325 in earlier sections. The only difference is that you have to tell the
326- initiator manually that it is behind a NAT using "hipconf nat on".
327+ initiator manually that it is behind a NAT using "hipconf daemon nat on".
328 After this, you can initiate the base exchange
329 according to the previous instructions. The manual configuration is
330 currently required because support for automatic NAT detection (STUN)
331@@ -2709,10 +2709,10 @@
332 </para>
333 <itemizedlist>
334 <listitem><para>
335- hipconf nat plain-udp
336+ hipconf daemon nat plain-udp
337 </para> </listitem>
338 <listitem><para>
339- hipconf add map peer_hit peer_ipv4_addr
340+ hipconf daemon add map peer_hit peer_ipv4_addr
341 </para> </listitem>
342 <listitem><para>
343 ping6 -I source_hit dst_hit
344@@ -2735,7 +2735,7 @@
345 by installing the Miredo client software. Then, establish HIP connections
346 to Teredo addresses (check ifconfig teredo) at the client side as
347 instructed in <xref linkend="ch_basictest" />. As Teredo is a NAT traversal
348- solution by itself, you don't have use UDP encapsulation for HIP (hipconf nat none).
349+ solution by itself, you don't have use UDP encapsulation for HIP (hipconf daemon nat none).
350 </para>
351 <para>
352 See
353@@ -2770,7 +2770,7 @@
354 relays HIP control and ESP data traffic. You can use one the InfraHIP servers
355 or set up your own as instructed in <xref linkend="ch_rvs_relay"
356 />. Both Initiator and Responder must be configured with
357- "hipconf nat ice-udp". Then Initiator must run the base exchange through the
358+ "hipconf daemon nat ice-udp". Then Initiator must run the base exchange through the
359 relay server.
360 </para>
361
362@@ -2816,12 +2816,12 @@
363
364 <para>
365 <programlisting>
366-hipconf shotgun on
367+hipconf daemon shotgun on
368 </programlisting>
369 </para>
370
371 <para>The same line can be also included in @sysconfdir@/hipd_config
372- without the "hipconf" prefix.
373+ without the "hipconf daemon" prefix.
374 </para>
375
376 <para>At the time of writing this, the shotgun extension did not yet
377
378=== modified file 'firewall/cache.c'
379--- firewall/cache.c 2011-10-25 21:14:16 +0000
380+++ firewall/cache.c 2011-11-07 17:07:26 +0000
381@@ -281,7 +281,7 @@
382 }
383 }
384
385- /* Note: this function is also reached by "hipconf rst all"
386+ /* Note: this function is also reached by "hipconf daemon rst all"
387 * so we don't want to uninitialize hash table here. Instead,
388 * we handle it in firewall_exit(). */
389
390
391=== modified file 'firewall/conntrack.c'
392--- firewall/conntrack.c 2011-10-25 21:14:16 +0000
393+++ firewall/conntrack.c 2011-11-07 17:07:26 +0000
394@@ -910,7 +910,7 @@
395 * Relay to pass e.g. p2p-unfriendly NAT boxes. The ESP relay mode
396 * assumes that the HIP relay (in hipd) and ESP relay (in hipfw) are
397 * running on the same middlehost in a public network. The responder
398- * has to register to the relay with "hipconf add server full-relay"
399+ * has to register to the relay with "hipconf daemon add server full-relay"
400 * which operates as defined in <a
401 * href="http://tools.ietf.org/html/draft-ietf-hip-nat-traversal"> NAT
402 * traversal for HIP</a>. Then the initiator can contact the responder
403@@ -2244,3 +2244,56 @@
404 remove_connection(conn_list->data);
405 }
406 }
407+
408+/**
409+ * Prepare given message with host association info from the tracked connections.
410+ *
411+ * @param msg The message where the info is written.
412+ * @return 0 on success
413+ * -1 on error
414+ */
415+int hip_fw_handle_get_ha_info(struct hip_common *msg)
416+{
417+ struct hip_hadb_user_info_state hid = { { { { 0 } } } };
418+ struct slist *iter_conn;
419+ struct connection *conn;
420+ struct hip_data *data;
421+
422+ if (!msg) {
423+ HIP_ERROR("Missing message parameter.\n");
424+ return -1;
425+ }
426+
427+ if (conn_list == NULL) {
428+ HIP_DEBUG("No tracked connections to return.\n");
429+ return 0;
430+ }
431+
432+ hip_msg_init(msg);
433+ if (hip_build_user_hdr(msg, HIP_MSG_GET_HA_INFO, 0) < 0) {
434+ HIP_ERROR("Failed to build GET_HA_INFO message header.\n");
435+ return -1;
436+ }
437+
438+ iter_conn = conn_list;
439+ while (iter_conn) {
440+ conn = iter_conn->data;
441+ data = conn->original.hip_tuple->data;
442+
443+ // build HA_INFO with info from connection initiator
444+ hid.state = conn->state;
445+ ipv6_addr_copy(&hid.hit_our, &data->src_hit);
446+ ipv6_addr_copy(&hid.hit_peer, &data->dst_hit);
447+ hid.nat_udp_port_local = conn->original.src_port;
448+ hid.nat_udp_port_peer = conn->original.dst_port;
449+
450+ if (hip_build_param_contents(msg, &hid, HIP_PARAM_HA_INFO, sizeof(hid)) < 0) {
451+ HIP_ERROR("Failed to build initiator HA_INFO parameter.\n");
452+ return -1;
453+ }
454+
455+ iter_conn = iter_conn->next;
456+ }
457+
458+ return 0;
459+}
460
461=== modified file 'firewall/conntrack.h'
462--- firewall/conntrack.h 2011-07-18 16:31:37 +0000
463+++ firewall/conntrack.h 2011-11-07 17:07:26 +0000
464@@ -63,4 +63,6 @@
465 void hip_fw_conntrack_periodic_cleanup(void);
466 void hip_fw_uninit_conntrack(void);
467
468+int hip_fw_handle_get_ha_info(struct hip_common *msg);
469+
470 #endif /* HIP_FIREWALL_CONNTRACK_H */
471
472=== modified file 'firewall/firewall.c'
473--- firewall/firewall.c 2011-10-30 11:41:51 +0000
474+++ firewall/firewall.c 2011-11-07 17:07:26 +0000
475@@ -1672,7 +1672,7 @@
476 n = recvfrom(hip_fw_async_sock, msg, sizeof(struct hip_common),
477 MSG_PEEK, (struct sockaddr *) &sock_addr, &alen);
478 if (n < 0) {
479- HIP_ERROR("Error receiving message header from daemon.\n");
480+ HIP_ERROR("Error receiving message header.\n");
481 return -1;
482 }
483
484@@ -1701,24 +1701,13 @@
485 (struct sockaddr *) &sock_addr, &alen);
486
487 if (n < 0) {
488- HIP_ERROR("Error receiving message parameters from daemon.\n");
489+ HIP_ERROR("Error receiving message parameters.\n");
490 return -1;
491 }
492
493 HIP_ASSERT(n == len);
494
495- if (ntohs(sock_addr.sin6_port) != HIP_DAEMON_LOCAL_PORT) {
496- int type = hip_get_msg_type(msg);
497- if (type == HIP_MSG_FW_BEX_DONE) {
498- HIP_DEBUG("HIP_MSG_FW_BEX_DONE\n");
499- HIP_DEBUG("%d == %d\n", ntohs(sock_addr.sin6_port),
500- HIP_DAEMON_LOCAL_PORT);
501- }
502- HIP_DEBUG("Drop, message not from hipd\n");
503- return -1;
504- }
505-
506- if (hip_handle_msg(msg) < 0) {
507+ if (hip_handle_msg(msg, (struct sockaddr *) &sock_addr) < 0) {
508 HIP_ERROR("Error handling message\n");
509 return -1;
510 }
511@@ -1847,8 +1836,6 @@
512 sock_addr.sin6_addr = in6addr_loopback;
513 HIP_IFEL(bind(hip_fw_async_sock, (struct sockaddr *) &sock_addr, sizeof(sock_addr)), -1,
514 "Bind on firewall socket addr failed. Give -k option to kill old hipfw\n");
515- HIP_IFEL(hip_daemon_connect(hip_fw_async_sock), -1,
516- "connecting socket failed\n");
517
518 /* Starting hipfw does not always work when hipfw starts first -miika */
519 if (hip_userspace_ipsec || hip_lsi_support) {
520@@ -1944,7 +1931,7 @@
521 }
522
523 if (FD_ISSET(hip_fw_async_sock, &read_fdset)) {
524- HIP_DEBUG("****** Received HIPD message ******\n");
525+ HIP_DEBUG("****** Received user message ******\n");
526 err = fw_handle_hipd_message(msg);
527 }
528
529@@ -2009,3 +1996,31 @@
530
531 return &default_lsi;
532 }
533+
534+/**
535+ * Send a message via the firewall socket for asynchronous messages.
536+ * Caller is responsible for setting up the message.
537+ *
538+ * @param msg The message to be sent.
539+ * @param addr The destination address.
540+ *
541+ * @return 0 on success
542+ * -1 on error
543+ */
544+int hip_fw_send_message(const struct hip_common *const msg,
545+ const struct sockaddr *const addr)
546+{
547+ uint16_t len;
548+
549+ if (msg == NULL || addr == NULL) {
550+ HIP_ERROR("Empty message or address.\n");
551+ return -1;
552+ }
553+
554+ len = hip_get_msg_total_len(msg);
555+ if (sendto(hip_fw_async_sock, msg, len, 0, addr, hip_sockaddr_len(addr)) != len) {
556+ return -1;
557+ }
558+
559+ return 0;
560+}
561
562=== modified file 'firewall/firewall.h'
563--- firewall/firewall.h 2011-04-05 16:44:22 +0000
564+++ firewall/firewall.h 2011-11-07 17:07:26 +0000
565@@ -1,5 +1,5 @@
566 /*
567- * Copyright (c) 2010 Aalto University and RWTH Aachen University.
568+ * Copyright (c) 2010-2011 Aalto University and RWTH Aachen University.
569 *
570 * Permission is hereby granted, free of charge, to any person
571 * obtaining a copy of this software and associated documentation
572@@ -55,5 +55,7 @@
573 void hip_fw_uninit_esp_relay(void);
574 hip_hit_t *hip_fw_get_default_hit(void);
575 hip_lsi_t *hip_fw_get_default_lsi(void);
576+int hip_fw_send_message(const struct hip_common *const msg,
577+ const struct sockaddr *const addr);
578
579 #endif /* HIP_FIREWALL_FIREWALL_H */
580
581=== modified file 'firewall/firewall_control.c'
582--- firewall/firewall_control.c 2011-10-25 21:14:16 +0000
583+++ firewall/firewall_control.c 2011-11-07 17:07:26 +0000
584@@ -38,10 +38,12 @@
585 #include <string.h>
586 #include <netinet/in.h>
587
588+#include "conntrack.h"
589 #include "lib/core/builder.h"
590 #include "lib/core/debug.h"
591 #include "lib/core/ife.h"
592 #include "lib/core/message.h"
593+#include "lib/core/prefix.h"
594 #include "lib/core/protodefs.h"
595 #include "cache.h"
596 #include "firewall.h"
597@@ -91,12 +93,13 @@
598 }
599
600 /**
601- * distribute a message from hipd to the respective extension handler
602+ * distribute a user message to the respective extension handler
603 *
604- * @param msg pointer to the received user message
605+ * @param msg pointer to the received user message
606+ * @param addr destination address for a reply
607 * @return 0 on success, else -1
608 */
609-int hip_handle_msg(struct hip_common *msg)
610+int hip_handle_msg(struct hip_common *msg, struct sockaddr *addr)
611 {
612 int type, err = 0;
613 struct hip_common *msg_out = NULL;
614@@ -150,12 +153,36 @@
615 HIP_IFEL(hip_send_recv_daemon_info(msg_out, 1, hip_fw_sock), -1,
616 "Couldn't notify daemon of firewall presence\n");
617 break;
618+ case HIP_MSG_GET_HA_INFO:
619+ HIP_IFEL(hip_fw_handle_get_ha_info(msg), -1,
620+ "Could not handle GET_HA message.\n");
621+ HIP_IFEL(hip_fw_send_message(msg, addr), -1,
622+ "Could not send HA reply.\n");
623+ break;
624 default:
625 HIP_ERROR("Unhandled message type %d\n", type);
626 err = -1;
627 break;
628 }
629+
630 out_err:
631+ if (hip_get_msg_response(msg)) {
632+ HIP_DEBUG("Send response\n");
633+ if (err) {
634+ hip_hdr msg_type = hip_get_msg_type(msg);
635+ hip_msg_init(msg);
636+ hip_build_user_hdr(msg, msg_type, 0);
637+ hip_set_msg_err(msg, 1);
638+ }
639+ HIP_DEBUG("Sending message (type=%d) response\n",
640+ hip_get_msg_type(msg));
641+ if (hip_fw_send_message(msg, addr) == -1) {
642+ err = -1;
643+ } else {
644+ HIP_DEBUG("Response sent ok\n");
645+ }
646+ }
647+
648 free(msg_out);
649 return err;
650 }
651
652=== modified file 'firewall/firewall_control.h'
653--- firewall/firewall_control.h 2010-10-15 15:29:14 +0000
654+++ firewall/firewall_control.h 2011-11-07 17:07:26 +0000
655@@ -1,5 +1,5 @@
656 /*
657- * Copyright (c) 2010 Aalto University and RWTH Aachen University.
658+ * Copyright (c) 2010-2011 Aalto University and RWTH Aachen University.
659 *
660 * Permission is hereby granted, free of charge, to any person
661 * obtaining a copy of this software and associated documentation
662@@ -28,6 +28,6 @@
663
664 #include "lib/core/protodefs.h"
665
666-int hip_handle_msg(struct hip_common *msg);
667+int hip_handle_msg(struct hip_common *msg, struct sockaddr *addr);
668
669 #endif /* HIP_FIREWALL_FIREWALL_CONTROL_H */
670
671=== modified file 'hipd/init.c'
672--- hipd/init.c 2011-11-03 09:21:12 +0000
673+++ hipd/init.c 2011-11-07 17:07:26 +0000
674@@ -164,7 +164,7 @@
675 }
676
677 #define HIPL_CONFIG_FILE_EX \
678- "# Format of this file is as with hipconf, but without hipconf prefix\n\
679+ "# Format of this file is as with hipconf, but without \"hipconf daemon\" prefix\n\
680 # add hi default # add all four HITs (see bug id 592127)\n\
681 # add map HIT IP # preload some HIT-to-IP mappings to hipd\n\
682 # add service rvs # the host acts as HIP rendezvous (see also HIPL_SYSCONFDIR/relay_config)\n\
683@@ -549,7 +549,7 @@
684 /* Three steps because multiple large keys will not fit in the same message */
685
686 /* DSA keys and RSA anonymous are not loaded by default until bug id
687- * 592127 is properly solved. Run hipconf add hi default if you want to
688+ * 592127 is properly solved. Run hipconf daemon add hi default if you want to
689 * enable non-default HITs. */
690
691 /* rsa pub */
692
693=== modified file 'hipd/nat.c'
694--- hipd/nat.c 2011-10-25 21:14:16 +0000
695+++ hipd/nat.c 2011-11-07 17:07:26 +0000
696@@ -209,7 +209,7 @@
697 *
698 * @return zero on success, or negative error value on error.
699 * @todo Extend this to handle peer_hit case for
700- * <code>"hipconf hip nat peer_hit"</code> This would be helpful in
701+ * <code>"hipconf daemon hip nat peer_hit"</code> This would be helpful in
702 * multihoming case.
703 */
704 int hip_user_nat_mode(int nat_mode)
705
706=== modified file 'hipd/registration.c'
707--- hipd/registration.c 2011-10-25 21:44:47 +0000
708+++ hipd/registration.c 2011-11-07 17:07:26 +0000
709@@ -1574,7 +1574,7 @@
710 }
711
712 /* Workaround for registration when a mapping already pre-exists
713- * (inserted e.g. with "hipconf add map"). This can be removed
714+ * (inserted e.g. with "hipconf daemon add map"). This can be removed
715 * after bug id 592135 is resolved. */
716 if (entry->state != HIP_STATE_NONE || HIP_STATE_UNASSOCIATED) {
717 struct hip_common *msg2 = calloc(HIP_MAX_PACKET, 1);
718
719=== modified file 'lib/core/conf.c'
720--- lib/core/conf.c 2011-11-03 09:21:12 +0000
721+++ lib/core/conf.c 2011-11-07 17:07:26 +0000
722@@ -77,9 +77,9 @@
723
724 /**
725 * hipconf tool actions. These are numerical values for the first commandline
726- * argument. For example in "tools/hipconf get hi default" -command "get"
727- * is the action. If you want a new action named as 'NEWACT', define a
728- * constant variable which has value between 0 and ACTION_MAX.
729+ * argument. For example in "tools/hipconf daemon get hi default"
730+ * -command "get" is the action. If you want a new action named as 'NEWACT',
731+ * define a constant variable which has value between 0 and ACTION_MAX.
732 * Probably you also need to increase the value of ACTION_MAX.
733 * @see conf_get_action()
734 */
735@@ -181,6 +181,11 @@
736 /* #define TYPE_RELAY 22 */
737
738 /**
739+ * The daemon process to be configured by the conf command.
740+ */
741+enum daemon_name daemon_name;
742+
743+/**
744 * A help string containing the usage of @c hipconf and also
745 * @c HIPL_SYSCONFDIR/hipd_config.
746 *
747@@ -188,6 +193,9 @@
748 * for the action.
749 */
750 const char *hipconf_usage =
751+ HIPCONF_HIPD_KEYWORD
752+ " <command>\n\n"
753+ "HIP daemon commands:\n"
754 "add map <hit> <ip> [lsi]\n"
755 "get map <hit | lsi>\n"
756 "del hi <hit> | all\n"
757@@ -226,6 +234,51 @@
758 ;
759
760 /**
761+ * A help string containing the usage of @c hipfwconf.
762+ *
763+ * @note If you added a new action, do not forget to add a brief usage below
764+ * for the action.
765+ */
766+const char *hipfwconf_usage =
767+ HIPCONF_HIPFW_KEYWORD
768+ " <command>\n\n"
769+ "HIP firewall commands:\n"
770+ "get ha <hit> | all\n";
771+
772+/**
773+ * Send a message to hipd or hipfw and optionally receive an answer.
774+ *
775+ * @param msg The message to be sent. The respective answer will be stored
776+ * here as well.
777+ * @param send_only 1 if no response from hipd should be requested.
778+ * 0 if it should block until a response from hipd is received.
779+ * This option has no effect when sending messages to hipfw.
780+ *
781+ * @return 0 on success
782+ * -1 on error
783+ */
784+static int send_receive_message(struct hip_common *msg,
785+ const int send_only)
786+{
787+ if (daemon_name == HIP_DAEMON) {
788+ if (hip_send_recv_daemon_info(msg, send_only, 0)) {
789+ HIP_ERROR("Failed to send user message to the HIP daemon.\n");
790+ return -1;
791+ }
792+ } else if (daemon_name == HIP_FIREWALL) {
793+ if (hip_send_recv_firewall_info(msg)) {
794+ HIP_ERROR("Failed to send user message to the HIP firewall.\n");
795+ return -1;
796+ }
797+ } else {
798+ HIP_ERROR("Destination daemon process unknown.\n");
799+ return -1;
800+ }
801+
802+ return 0;
803+}
804+
805+/**
806 * Query hipd for the HITs of the local host
807 *
808 * @param msg input/output message for the query/response for hipd
809@@ -510,6 +563,25 @@
810 /* Non-static functions -> global scope */
811
812 /**
813+ * Map daemon / firewall keyboard to its respective enum.
814+ *
815+ * @param argv an array of strings (command line args to hipconf)
816+ * @return HIP_DAEMON in case of hipd keyword
817+ * HIP_FIREWALL in case of hipfw keyword
818+ * UNKNOWN_KEYWORD else
819+ */
820+static int conf_get_process(const char *argv[])
821+{
822+ if (!strcmp(HIPCONF_HIPD_KEYWORD, argv[1])) {
823+ return HIP_DAEMON;
824+ } else if (!strcmp(HIPCONF_HIPFW_KEYWORD, argv[1])) {
825+ return HIP_FIREWALL;
826+ }
827+
828+ return UNKNOWN_KEYWORD;
829+}
830+
831+/**
832 * Map a symbolic hipconf action (=add/del) into a number
833 *
834 * @param argv an array of strings (command line args to hipconf)
835@@ -526,61 +598,61 @@
836 {
837 int ret = -1;
838
839- if (!strcmp("add", argv[1])) {
840+ if (!strcmp("add", argv[2])) {
841 ret = ACTION_ADD;
842- } else if (!strcmp("del", argv[1])) {
843+ } else if (!strcmp("del", argv[2])) {
844 ret = ACTION_DEL;
845- } else if (!strcmp("new", argv[1])) {
846+ } else if (!strcmp("new", argv[2])) {
847 ret = ACTION_NEW;
848- } else if (!strcmp("get", argv[1])) {
849+ } else if (!strcmp("get", argv[2])) {
850 ret = ACTION_GET;
851- } else if (!strcmp("set", argv[1])) {
852+ } else if (!strcmp("set", argv[2])) {
853 ret = ACTION_SET;
854- } else if (!strcmp("inc", argv[1])) {
855+ } else if (!strcmp("inc", argv[2])) {
856 ret = ACTION_INC;
857- } else if (!strcmp("dec", argv[1])) {
858+ } else if (!strcmp("dec", argv[2])) {
859 ret = ACTION_DEC;
860- } else if (!strcmp("rst", argv[1])) {
861+ } else if (!strcmp("rst", argv[2])) {
862 ret = ACTION_RST;
863- } else if (!strcmp("run", argv[1])) {
864+ } else if (!strcmp("run", argv[2])) {
865 ret = ACTION_RUN;
866- } else if (!strcmp("load", argv[1])) {
867+ } else if (!strcmp("load", argv[2])) {
868 ret = ACTION_LOAD;
869- } else if (!strcmp("heartbeat", argv[1])) {
870+ } else if (!strcmp("heartbeat", argv[2])) {
871 ret = ACTION_HEARTBEAT;
872- } else if (!strcmp("locator", argv[1])) {
873+ } else if (!strcmp("locator", argv[2])) {
874 ret = ACTION_LOCATOR;
875- } else if (!strcmp("debug", argv[1])) {
876+ } else if (!strcmp("debug", argv[2])) {
877 ret = ACTION_DEBUG;
878- } else if (!strcmp("transform", argv[1])) {
879+ } else if (!strcmp("transform", argv[2])) {
880 ret = ACTION_TRANSORDER;
881- } else if (!strcmp("reinit", argv[1])) {
882+ } else if (!strcmp("reinit", argv[2])) {
883 ret = ACTION_REINIT;
884- } else if (!strcmp("manual-update", argv[1])) {
885+ } else if (!strcmp("manual-update", argv[2])) {
886 ret = ACTION_MANUAL_UPDATE;
887- } else if (!strcmp("hit-to-lsi", argv[1])) {
888+ } else if (!strcmp("hit-to-lsi", argv[2])) {
889 ret = ACTION_HIT_TO_LSI;
890- } else if (!strcmp("nsupdate", argv[1])) {
891+ } else if (!strcmp("nsupdate", argv[2])) {
892 ret = ACTION_NSUPDATE;
893- } else if (!strcmp("hit-to-ip-set", argv[1])) {
894+ } else if (!strcmp("hit-to-ip-set", argv[2])) {
895 ret = ACTION_HIT_TO_IP_SET;
896- } else if (!strcmp("hit-to-ip", argv[1])) {
897+ } else if (!strcmp("hit-to-ip", argv[2])) {
898 ret = ACTION_HIT_TO_IP;
899- } else if (!strcmp("shotgun", argv[1])) {
900+ } else if (!strcmp("shotgun", argv[2])) {
901 ret = ACTION_SHOTGUN;
902- } else if (!strcmp("lsi-to-hit", argv[1])) {
903+ } else if (!strcmp("lsi-to-hit", argv[2])) {
904 ret = ACTION_LSI_TO_HIT;
905- } else if (!strcmp("nat", argv[1])) {
906- if (!strcmp("port", argv[2])) {
907- if (!strcmp("local", argv[3])) {
908+ } else if (!strcmp("nat", argv[2])) {
909+ if (!strcmp("port", argv[3])) {
910+ if (!strcmp("local", argv[4])) {
911 ret = ACTION_NAT_LOCAL_PORT;
912- } else if (!strcmp("peer", argv[3])) {
913+ } else if (!strcmp("peer", argv[4])) {
914 ret = ACTION_NAT_PEER_PORT;
915 }
916 } else {
917 ret = ACTION_NAT;
918 }
919- } else if (!strcmp("broadcast", argv[1])) {
920+ } else if (!strcmp("broadcast", argv[2])) {
921 ret = ACTION_BROADCAST;
922 }
923
924@@ -670,45 +742,45 @@
925 ret = TYPE_HA;
926 } else if (!strcmp("shotgun", text)) {
927 ret = TYPE_SHOTGUN;
928- } else if ((!strcmp("all", text)) && (strcmp("rst", argv[1]) == 0)) {
929- ret = TYPE_RST;
930- } else if ((!strcmp("peer_hit", text)) && (strcmp("rst", argv[1]) == 0)) {
931- ret = TYPE_RST;
932- } else if (strcmp("nat", argv[1]) == 0) {
933- if (argv[2] && strcmp("port", argv[2]) == 0) {
934- if (argv[3] && strcmp("local", argv[3]) == 0) {
935+ } else if ((!strcmp("all", text)) && (strcmp("rst", argv[2]) == 0)) {
936+ ret = TYPE_RST;
937+ } else if ((!strcmp("peer_hit", text)) && (strcmp("rst", argv[2]) == 0)) {
938+ ret = TYPE_RST;
939+ } else if (strcmp("nat", argv[2]) == 0) {
940+ if (argv[3] && strcmp("port", argv[3]) == 0) {
941+ if (argv[4] && strcmp("local", argv[4]) == 0) {
942 ret = TYPE_NAT_LOCAL_PORT;
943- } else if (argv[3] && strcmp("peer", argv[3]) == 0) {
944+ } else if (argv[4] && strcmp("peer", argv[4]) == 0) {
945 ret = TYPE_NAT_PEER_PORT;
946 }
947 } else {
948 ret = TYPE_NAT;
949 }
950- } else if (strcmp("locator", argv[1]) == 0) {
951+ } else if (strcmp("locator", argv[2]) == 0) {
952 ret = TYPE_LOCATOR;
953 } else if (!strcmp("debug", text)) {
954 ret = TYPE_DEBUG;
955 } else if (!strcmp("order", text)) {
956 ret = TYPE_ORDER;
957- } else if (strcmp("heartbeat", argv[1]) == 0) {
958+ } else if (strcmp("heartbeat", argv[2]) == 0) {
959 ret = TYPE_HEARTBEAT;
960 } else if (!strcmp("ttl", text)) {
961 ret = TYPE_TTL;
962 } else if (!strcmp("config", text)) {
963 ret = TYPE_CONFIG;
964- } else if (strcmp("manual-update", argv[1]) == 0) {
965+ } else if (strcmp("manual-update", argv[2]) == 0) {
966 ret = TYPE_MANUAL_UPDATE;
967- } else if (strcmp("hit-to-lsi", argv[1]) == 0) {
968+ } else if (strcmp("hit-to-lsi", argv[2]) == 0) {
969 ret = TYPE_HIT_TO_LSI;
970- } else if (strcmp("nsupdate", argv[1]) == 0) {
971+ } else if (strcmp("nsupdate", argv[2]) == 0) {
972 ret = TYPE_NSUPDATE;
973- } else if (strcmp("hit-to-ip-set", argv[1]) == 0) {
974+ } else if (strcmp("hit-to-ip-set", argv[2]) == 0) {
975 ret = TYPE_HIT_TO_IP_SET;
976- } else if (strcmp("hit-to-ip", argv[1]) == 0) {
977+ } else if (strcmp("hit-to-ip", argv[2]) == 0) {
978 ret = TYPE_HIT_TO_IP;
979- } else if (strcmp("lsi-to-hit", argv[1]) == 0) {
980+ } else if (strcmp("lsi-to-hit", argv[2]) == 0) {
981 ret = TYPE_LSI_TO_HIT;
982- } else if (strcmp("broadcast", argv[1]) == 0) {
983+ } else if (strcmp("broadcast", argv[2]) == 0) {
984 ret = TYPE_BROADCAST;
985 } else {
986 HIP_DEBUG("ERROR: NO MATCHES FOUND \n");
987@@ -725,7 +797,7 @@
988 * here in the switch(action) block.
989 * @param action integer value for an action
990 * @return an index for argv[], which indicates the type argument.
991- * Usually either 1 or 2.
992+ * Usually either 2 or 3.
993 */
994 static int conf_get_type_arg(int action)
995 {
996@@ -753,15 +825,15 @@
997 case ACTION_HIT_TO_IP:
998 case ACTION_HIT_TO_IP_SET:
999 case ACTION_BROADCAST:
1000+ type_arg = 3;
1001+ break;
1002+ case ACTION_MANUAL_UPDATE:
1003+ case ACTION_HIT_TO_LSI:
1004+ case ACTION_LSI_TO_HIT:
1005+ case ACTION_DEBUG:
1006+ case ACTION_SHOTGUN:
1007 type_arg = 2;
1008 break;
1009- case ACTION_MANUAL_UPDATE:
1010- case ACTION_HIT_TO_LSI:
1011- case ACTION_LSI_TO_HIT:
1012- case ACTION_DEBUG:
1013- case ACTION_SHOTGUN:
1014- type_arg = 1;
1015- break;
1016 default:
1017 break;
1018 }
1019@@ -816,9 +888,9 @@
1020 * Handles the hipconf commands where the type is @c server. Creates a user
1021 * message from the function parameters @c msg, @c action and @c opt[]. The
1022 * command line that this function parses is of type:
1023- * <code>tools/hipconf <b>add</b> server &lt;SERVICES&gt; &lt;SERVER HIT&gt;
1024+ * <code>tools/hipconf daemon <b>add</b> server &lt;SERVICES&gt; &lt;SERVER HIT&gt;
1025 * &lt;SERVER IP ADDRESS&gt; &lt;LIFETIME&gt;</code> or
1026- * <code>tools/hipconf <b>del</b> server &lt;SERVICES&gt; &lt;SERVER HIT&gt;
1027+ * <code>tools/hipconf daemon <b>del</b> server &lt;SERVICES&gt; &lt;SERVER HIT&gt;
1028 * &lt;SERVER IP ADDRESS&gt;</code>, where <code>&lt;SERVICES&gt;</code> is a list of
1029 * the services to which we want to register or cancel or registration. The
1030 * list can consist of any number of the strings @c rvs, @c relay,
1031@@ -1999,9 +2071,9 @@
1032 }
1033
1034 /**
1035- * Handle e.g. "hipconf run normal firefox". Enables HIP support
1036- * for the given application using LD_PRELOAD. This means that
1037- * all getaddrinfo() calls go through the modified libinet6 library.
1038+ * Handle e.g. "hipconf daemon run normal firefox".
1039+ * Enables HIP support for the given application using LD_PRELOAD. This means
1040+ * that all getaddrinfo() calls go through the modified libinet6 library.
1041 * This function is depracated.
1042 *
1043 * @param msg input/output message for the query/response for hipd
1044@@ -2045,10 +2117,10 @@
1045 HIP_IFEL(optc > 1, -1, "Too many arguments\n");
1046
1047 HIP_IFEL(hip_build_user_hdr(msg, HIP_MSG_GET_HA_INFO, 0), -1,
1048- "Building of daemon header failed\n");
1049+ "Building of user msg header failed\n");
1050
1051- HIP_IFEL(hip_send_recv_daemon_info(msg, send_only, 0), -1,
1052- "send recv daemon info\n");
1053+ HIP_IFEL(send_receive_message(msg, send_only), -1,
1054+ "send recv info\n");
1055
1056 while ((current_param = hip_get_next_param(msg, current_param))) {
1057 ha = hip_get_param_contents_direct(current_param);
1058@@ -2316,8 +2388,9 @@
1059 *comment = '\0';
1060 }
1061
1062- /* prefix the contents of the line with" hipconf" */
1063- res_len = sprintf(str, "hipconf %s", c);
1064+ /* prefix the contents of the line with" hipconf HIPCONF_HIPD_KEYWORD"
1065+ * Only hipd parses config files as hipconf commands, hardcode it as target */
1066+ res_len = sprintf(str, "hipconf %s %s", HIPCONF_HIPD_KEYWORD, c);
1067 if (str[res_len] == '\n') {
1068 str[res_len] = '\0';
1069 }
1070@@ -2330,7 +2403,6 @@
1071 args[i++] = token;
1072 token = strtok(NULL, " \t");
1073 }
1074-
1075 err = hip_do_hipconf(i, args, 1);
1076 if (err) {
1077 HIP_ERROR("Error on the following line: %s\n", line);
1078@@ -2454,9 +2526,18 @@
1079 struct hip_common *msg = NULL;
1080
1081 /* Check that we have at least one command line argument. */
1082- if (argc < 2) {
1083- HIP_ERROR("Invalid arguments.\n\n%s usage:\n%s\n",
1084- argv[0], hipconf_usage);
1085+ if (argc < 3) {
1086+ HIP_ERROR("Invalid arguments.\nUsage to communicate with HIP daemon:\n %s %s\n"
1087+ "\nUsage to communicate with HIP firewall:\n %s %s\n",
1088+ argv[0], hipconf_usage, argv[0], hipfwconf_usage);
1089+ return -1;
1090+ }
1091+
1092+ /* set context for this conf command */
1093+ daemon_name = conf_get_process(argv);
1094+ if (daemon_name == UNKNOWN_KEYWORD) {
1095+ HIP_ERROR("Invalid target process argument '%s'. Expected '%s' or '%s'.\n",
1096+ argv[1], HIPCONF_HIPD_KEYWORD, HIPCONF_HIPFW_KEYWORD);
1097 return -1;
1098 }
1099
1100@@ -2464,14 +2545,14 @@
1101 action = conf_get_action(argv);
1102
1103 if (action == -1) {
1104- HIP_ERROR("Invalid action argument '%s'\n", argv[1]);
1105+ HIP_ERROR("Invalid action argument '%s'\n", argv[2]);
1106 return -1;
1107 }
1108
1109 /* Check that we have at least the minimum number of arguments
1110 * for the given action. */
1111- if (argc < conf_check_action_argc(action) + 2) {
1112- HIP_ERROR("Not enough arguments given for the action '%s'\n", argv[1]);
1113+ if (argc < conf_check_action_argc(action) + 3) {
1114+ HIP_ERROR("Not enough arguments given for the action '%s'\n", argv[2]);
1115 return -1;
1116 }
1117
1118@@ -2499,25 +2580,23 @@
1119 /* Call handler function from the handler function pointer
1120 * array at index "type" with given commandline arguments.
1121 * The functions build a hip_common message. */
1122- if (argc == 3) {
1123- err = (*action_handler[type])(msg, action, &argv[2], argc - 3, send_only);
1124+ if (argc == 4) {
1125+ err = (*action_handler[type])(msg, action, &argv[3], argc - 4, send_only);
1126 } else {
1127- err = (*action_handler[type])(msg, action, &argv[3], argc - 3, send_only);
1128+ err = (*action_handler[type])(msg, action, &argv[4], argc - 4, send_only);
1129 }
1130
1131 if (err != 0) {
1132- HIP_ERROR("Failed to send a message to the HIP daemon.\n");
1133+ HIP_ERROR("Failed to send user message.\n");
1134 goto out_err;
1135 }
1136
1137- /* hipconf new hi does not involve any messages to hipd */
1138+ /* hipconf daemon new hi does not involve any messages to hipd */
1139 if (hip_get_msg_type(msg) == 0) {
1140 goto out_err;
1141 }
1142
1143- /* Send message to hipd */
1144- HIP_IFEL(hip_send_recv_daemon_info(msg, send_only, 0), -1,
1145- "Failed to send user message to the HIP daemon.\n");
1146+ send_receive_message(msg, send_only);
1147
1148 HIP_INFO("User message was sent successfully to the HIP daemon.\n");
1149
1150@@ -2525,7 +2604,8 @@
1151 free(msg);
1152
1153 if (err) {
1154- HIP_ERROR("(Check syntax for hipconf. Is hipd running or root privilege needed?)\n");
1155+ HIP_ERROR("(Check syntax for hipconf. Is hipd or hipfw running or root"
1156+ " privilege needed?)\n");
1157 }
1158
1159 return err;
1160
1161=== modified file 'lib/core/conf.h'
1162--- lib/core/conf.h 2011-08-15 14:11:56 +0000
1163+++ lib/core/conf.h 2011-11-07 17:07:26 +0000
1164@@ -54,6 +54,11 @@
1165 #define ACTION_ADD 1
1166 #define ACTION_NEW 3
1167
1168+enum daemon_name { HIP_DAEMON, HIP_FIREWALL, UNKNOWN_KEYWORD };
1169+/* keywords used to identify hipd / hipfw as target of hipconf command */
1170+#define HIPCONF_HIPD_KEYWORD "daemon"
1171+#define HIPCONF_HIPFW_KEYWORD "firewall"
1172+
1173 int hip_handle_exec_app(int fork, int type, int argc,
1174 const char *const argv[]);
1175 int hip_do_hipconf(int argc, const char *argv[], int send_only);
1176
1177=== modified file 'lib/core/hostid.c'
1178--- lib/core/hostid.c 2011-10-25 21:14:16 +0000
1179+++ lib/core/hostid.c 2011-11-07 17:07:26 +0000
1180@@ -710,7 +710,7 @@
1181
1182 switch (action) {
1183 case ACTION_NEW:
1184- /* Default directory is created only in "hipconf new default hi" */
1185+ /* Default directory is created only in "hipconf daemon new default hi" */
1186 if (use_default) {
1187 if ((err = check_and_create_dir(HIPL_SYSCONFDIR,
1188 HIP_DIR_MODE))) {
1189
1190=== modified file 'lib/core/message.c'
1191--- lib/core/message.c 2011-10-25 21:44:47 +0000
1192+++ lib/core/message.c 2011-11-07 17:07:26 +0000
1193@@ -40,7 +40,7 @@
1194 * hence the message does not block.
1195 *
1196 * Use the synchronous message interface only when you expect the
1197- * request message to be completed immediately. For example, "hipconf
1198+ * request message to be completed immediately. For example, "hipconf daemon
1199 * get ha all" was safe to be implemented with synchronous messaging
1200 * because hipd can process the request immediately.
1201 *
1202@@ -86,6 +86,7 @@
1203 #include <sys/time.h>
1204 #include <sys/types.h>
1205
1206+#include "lib/core/conf.h"
1207 #include "lib/tool/nlink.h"
1208 #include "builder.h"
1209 #include "common.h"
1210@@ -144,7 +145,7 @@
1211 } while (timeout_left > 0 && errno == EAGAIN && bytes < 0);
1212
1213 if (bytes < 0) {
1214- HIP_ERROR("recv() peek error (is hipd running?)\n");
1215+ HIP_ERROR("recv() peek error (is hipd or hipfw running?)\n");
1216 err = -EAGAIN;
1217 goto out_err;
1218 } else if (bytes < hdr_size) {
1219@@ -178,6 +179,30 @@
1220 }
1221
1222 /**
1223+ * Connect a socket to the loopback address of hipd or hipfw.
1224+ *
1225+ * @param hip_user_sock The socket to connect.
1226+ * @param port The port to connect.
1227+ * @return zero on success and negative on failure
1228+ * @note currently only SOCK_DGRAM and AF_INET6 are supported
1229+ */
1230+static int hip_connect(int hip_user_sock, int port)
1231+{
1232+ struct sockaddr_in6 addr = { 0 };
1233+
1234+ addr.sin6_family = AF_INET6;
1235+ addr.sin6_port = htons(port);
1236+ addr.sin6_addr = in6addr_loopback;
1237+
1238+ if (connect(hip_user_sock, (struct sockaddr *) &addr, sizeof(addr))) {
1239+ HIP_ERROR("connection failed: %s\n", strerror(errno));
1240+ return -1;
1241+ }
1242+
1243+ return 0;
1244+}
1245+
1246+/**
1247 * Connect a socket to the loop back address of hipd
1248 *
1249 * @param hip_user_sock The socket to connect. Currently only SOCK_DGRAM
1250@@ -187,21 +212,7 @@
1251 */
1252 int hip_daemon_connect(int hip_user_sock)
1253 {
1254- int err = 0;
1255- struct sockaddr_in6 daemon_addr = { 0 };
1256- // We're using system call here add thus resetting errno.
1257- errno = 0;
1258-
1259- daemon_addr.sin6_family = AF_INET6;
1260- daemon_addr.sin6_port = htons(HIP_DAEMON_LOCAL_PORT);
1261- daemon_addr.sin6_addr = in6addr_loopback;
1262-
1263- HIP_IFEL(connect(hip_user_sock, (struct sockaddr *) &daemon_addr,
1264- sizeof(daemon_addr)), -1, "connection to daemon failed\n");
1265-
1266-out_err:
1267-
1268- return err;
1269+ return hip_connect(hip_user_sock, HIP_DAEMON_LOCAL_PORT);
1270 }
1271
1272 /**
1273@@ -211,7 +222,7 @@
1274 * obtain a port number below 1024. In UNIX/Linux this means that the
1275 * process has superuser privileges. Hipd uses the port number to
1276 * verify if the caller has sufficient privileges to execute
1277- * e.g. "hipconf rst all". The function falls back to non-privileged
1278+ * e.g. "hipconf daemon rst all". The function falls back to non-privileged
1279 * ports if it fails to obtain a privileged port and then hipd allows
1280 * only certain operations for the calling process.
1281 *
1282@@ -319,23 +330,30 @@
1283 #define EHIP 500
1284
1285 /**
1286- * Send and receive data with hipd. Do not call this function directly, use
1287- * hip_send_recv_daemon_info instead!
1288+ * Send and receive data with hipd or hipfw. Do not call this function directly,
1289+ * use hip_send_recv_daemon_info or hip_send_recv_firewall_info instead!
1290 *
1291- * @param msg the message to send to hipd
1292+ * @param msg The message to send to hipd or hipfw
1293 * @param opt_socket Optional socket to use for the message exchange. When
1294 * set to zero, the function creates a temporary socket
1295 * and closes it after the transaction is completed.
1296+ * @param port The port to send the message to.
1297 * @return zero on success and negative on failure
1298 * @note currently only SOCK_DGRAM and AF_INET6 are supported
1299 */
1300-static int send_recv_daemon_info_internal(struct hip_common *msg,
1301- int opt_socket)
1302+static int send_recv_info_internal(struct hip_common *msg, int opt_socket, int port)
1303 {
1304 int hip_user_sock = 0, err = 0, n = 0, len = 0;
1305 struct sockaddr_in6 addr = { 0 };
1306 uint8_t msg_type_old, msg_type_new;
1307+ const char *receiver;
1308
1309+ /* determine receiver to print correct debug / error messages */
1310+ if (port == HIP_FIREWALL_PORT) {
1311+ receiver = HIPCONF_HIPFW_KEYWORD;
1312+ } else {
1313+ receiver = HIPCONF_HIPD_KEYWORD;
1314+ }
1315 msg_type_old = hip_get_msg_type(msg);
1316
1317 // We're using system call here and thus resetting errno.
1318@@ -354,9 +372,9 @@
1319 HIP_IFEL(daemon_bind_socket(hip_user_sock,
1320 (struct sockaddr *) &addr), -1,
1321 "bind failed\n");
1322- /* Connect to hipd. Otherwise e.g. "hipconf get ha all"
1323+ /* Connect to hipd or hipfw. Otherwise e.g. "hipconf daemon get ha all"
1324 * blocks when hipd is not running. */
1325- HIP_IFEL(hip_daemon_connect(hip_user_sock), -1,
1326+ HIP_IFEL(hip_connect(hip_user_sock, port), -1,
1327 "connect failed\n");
1328 }
1329
1330@@ -368,14 +386,18 @@
1331 /* Require a response from hipd */
1332 hip_set_msg_response(msg, 1);
1333
1334- n = sendto_hipd(hip_user_sock, msg, len);
1335+ if (port == HIP_FIREWALL_PORT) {
1336+ n = send(hip_user_sock, msg, len, 0);
1337+ } else {
1338+ n = sendto_hipd(hip_user_sock, msg, len);
1339+ }
1340 if (n < len) {
1341- HIP_ERROR("Could not send message to daemon.\n");
1342+ HIP_ERROR("Could not send message to %s.\n", receiver);
1343 err = -ECOMM;
1344 goto out_err;
1345 }
1346
1347- HIP_DEBUG("Waiting to receive daemon info.\n");
1348+ HIP_DEBUG("Waiting to receive %s info.\n", receiver);
1349
1350 if ((len = peek_recv_total_len(hip_user_sock, 0, HIP_DEFAULT_MSG_TIMEOUT)) < 0) {
1351 err = len;
1352@@ -390,14 +412,14 @@
1353 "Message sync problem. Expected %d, got %d\n",
1354 msg_type_old, msg_type_new);
1355
1356- HIP_DEBUG("%d bytes received from HIP daemon\n", n);
1357+ HIP_DEBUG("%d bytes received from HIP %s.\n", n, receiver);
1358
1359 if (n == 0) {
1360- HIP_INFO("The HIP daemon has performed an orderly shutdown.\n");
1361+ HIP_INFO("The HIP %s has performed an orderly shutdown.\n", receiver);
1362 // Note. This is not an error condition, thus we return zero.
1363 goto out_err;
1364 } else if (n < (int) sizeof(struct hip_common)) {
1365- HIP_ERROR("Could not receive message from daemon.\n");
1366+ HIP_ERROR("Could not receive message from %s.\n", receiver);
1367 goto out_err;
1368 }
1369
1370@@ -442,7 +464,7 @@
1371 struct sockaddr_in6 addr = { 0 };
1372
1373 if (!send_only) {
1374- return send_recv_daemon_info_internal(msg, opt_socket);
1375+ return send_recv_info_internal(msg, opt_socket, HIP_DAEMON_LOCAL_PORT);
1376 }
1377
1378 if (opt_socket) {
1379@@ -479,6 +501,21 @@
1380 }
1381
1382 /**
1383+ * A generic function to send messages to hipfw with subsequent reply. This will
1384+ * block the process until the hipfw sends the response or a predefined timeout
1385+ * is exceeded.
1386+ *
1387+ * @param msg An input/output parameter. As input, contains the
1388+ * message to be sent to hipfw. As output, hipfw response
1389+ * will be written here.
1390+ * @return zero on success and negative on failure.
1391+ */
1392+int hip_send_recv_firewall_info(struct hip_common *const msg)
1393+{
1394+ return send_recv_info_internal(msg, 0, HIP_FIREWALL_PORT);
1395+}
1396+
1397+/**
1398 * Read an interprocess (user) message
1399 *
1400 * @param sockfd a socket from where to read
1401
1402=== modified file 'lib/core/message.h'
1403--- lib/core/message.h 2011-08-15 14:11:56 +0000
1404+++ lib/core/message.h 2011-11-07 17:07:26 +0000
1405@@ -46,5 +46,6 @@
1406 int hip_send_recv_daemon_info(struct hip_common *msg,
1407 int send_only,
1408 int opt_socket);
1409+int hip_send_recv_firewall_info(struct hip_common *const msg);
1410
1411 #endif /* HIP_LIB_CORE_MESSAGE_H */
1412
1413=== modified file 'lib/tool/nlink.c'
1414--- lib/tool/nlink.c 2011-10-25 21:14:16 +0000
1415+++ lib/tool/nlink.c 2011-11-07 17:07:26 +0000
1416@@ -146,7 +146,7 @@
1417
1418 /* Transitioned from recvmsg() to recvfrom() due to
1419 * "Netlink overrun" errors when executing
1420- * "hipconf rst all" */
1421+ * "hipconf daemon rst all" */
1422
1423 status = recvfrom(nl->fd, buf, sizeof(buf),
1424 0, NULL, NULL);
1425
1426=== modified file 'tools/hipconf.c'
1427--- tools/hipconf.c 2011-08-15 14:11:56 +0000
1428+++ tools/hipconf.c 2011-11-07 17:07:26 +0000
1429@@ -53,7 +53,7 @@
1430 hip_set_logdebug(LOGDEBUG_ALL);
1431
1432 HIP_IFEL(hip_do_hipconf(argc, argv, 0), -2,
1433- "Error: Cannot configure the HIP daemon.\n");
1434+ "Error: Cannot configure the HIP daemon or firewall.\n");
1435
1436 out_err:
1437 return err;
1438
1439=== modified file 'tools/hipdnsproxy/hipdnsproxy.in'
1440--- tools/hipdnsproxy/hipdnsproxy.in 2011-06-09 19:11:46 +0000
1441+++ tools/hipdnsproxy/hipdnsproxy.in 2011-11-07 17:07:26 +0000
1442@@ -545,7 +545,7 @@
1443 f.close()
1444
1445 def map_hit_to_lsi(gp, hit):
1446- cmd = "hipconf hit-to-lsi " + hit + " 2>&1"
1447+ cmd = "hipconf daemon hit-to-lsi " + hit + " 2>&1"
1448 #gp.fout.write("cmd - %s\n" % (cmd,))
1449 p = Popen(cmd, shell=True, stdout=subprocess.PIPE).stdout
1450 result = p.readline()
1451@@ -558,7 +558,7 @@
1452 return None
1453
1454 def lsi_to_hit(gp, lsi):
1455- cmd = "hipconf lsi-to-hit " + lsi + " 2>&1"
1456+ cmd = "hipconf daemon lsi-to-hit " + lsi + " 2>&1"
1457 p = Popen(cmd, shell=True, stdout=subprocess.PIPE).stdout
1458 result = p.readline()
1459 while result:
1460@@ -570,7 +570,7 @@
1461 return None
1462
1463 def add_hit_ip_map(gp, hit, ip):
1464- cmd = "hipconf add map " + hit + " " + ip + \
1465+ cmd = "hipconf daemon add map " + hit + " " + ip + \
1466 " > /dev/null 2>&1"
1467 gp.fout.write('Associating HIT %s with IP %s\n' % (hit, ip))
1468 os.system(cmd)

Subscribers

People subscribed via source and target branches

to all changes: