[hipl-commit] [trunk] Rev 3916: Splitting misc.c (bug id 1139) finished, I hope.

  • From: Miika Komu <miika@xxxxxx>
  • To: hipl-commit@xxxxxxxxxxxxx
  • Date: Wed, 10 Mar 2010 19:44:47 +0200

Committer: Miika Komu <miika@xxxxxx>
Date: Wed Mar 10 19:44:36 2010 +0200
Revision: 3916
Revision-id: miika@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Branch nick: trunk

Log:
  Splitting misc.c (bug id 1139) finished, I hope.
  Added lib/core/straddr.[c|h] and removed misc.[c|h]. I had to change the 
  order of the libraries in Makefile.am due to changed library 
  dependencies. I haven't tested all possible combinations of compilation 
  options. If you find still problems, they should be trivial to solve by 
  adding some missing include declarations in the source files.

Modified:
  D  lib/core/misc.c
  D  lib/core/misc.h
  A  lib/core/straddr.c
  A  lib/core/straddr.h
  M  Makefile.am
  M  agent/connhipd.c
  M  firewall/cache.c
  M  firewall/cache_port.c
  M  firewall/common_hipd_msg.c
  M  firewall/conntrack.c
  M  firewall/datapkt.c
  M  firewall/esp_prot_conntrack.c
  M  firewall/esp_prot_fw_msg.c
  M  firewall/firewalldb.c
  M  firewall/lsi.c
  M  firewall/lsi.h
  M  firewall/opptcp.c
  M  firewall/pisa.c
  M  firewall/sysopp.c
  M  firewall/user_ipsec_api.c
  M  firewall/user_ipsec_api.h
  M  firewall/user_ipsec_esp.c
  M  firewall/user_ipsec_fw_msg.c
  M  firewall/user_ipsec_sadb.c
  M  hipd/bos.h
  M  hipd/cert.h
  M  hipd/close.h
  M  hipd/configfilereader.c
  M  hipd/configfilereader.h
  M  hipd/dhtqueue.c
  M  hipd/esp_prot_anchordb.c
  M  hipd/esp_prot_light_update.c
  M  hipd/hadb.h
  M  hipd/hipd.c
  M  hipd/hipd.h
  M  hipd/hiprelay.c
  M  hipd/hiprelay.h
  M  hipd/init.c
  M  hipd/input.c
  M  hipd/keymat.h
  M  hipd/nat.h
  M  hipd/netdev.h
  M  hipd/oppdb.c
  M  hipd/oppdb.h
  M  hipd/output.h
  M  hipd/registration.c
  M  hipd/registration.h
  M  hipd/user_ipsec_hipd_msg.c
  M  lib/conf/hipconf.c
  M  lib/core/builder.h
  M  lib/core/certtools.c
  M  lib/core/certtools.h
  M  lib/core/debug.c
  M  lib/core/filemanip.h
  M  lib/core/hashtable.c
  M  lib/core/hashtable.h
  M  lib/core/hip_udp.h
  M  lib/core/hit.c
  M  lib/core/hit.h
  M  lib/core/hostid.c
  M  lib/core/hostid.h
  M  lib/core/hostsfiles.c
  M  lib/core/hostsfiles.h
  M  lib/core/message.c
  M  lib/core/prefix.c
  M  lib/core/prefix.h
  M  lib/core/protodefs.h
  M  lib/core/solve.h
  M  lib/dht/libhipdht.c
  M  lib/dht/libhipdht.h
  M  lib/dht/libhipdhtxml.c
  M  lib/opphip/wrap.c
  M  lib/tool/lutil.c
  M  lib/tool/lutil.h
  M  lib/tool/nlink.c
  M  lib/tool/nlink.h
  M  lib/tool/xfrmapi.h
  M  test/certteststub.c
  M  test/conntest.c
  M  test/conntest.h
  M  test/cookietest.c
  M  test/dhtteststub.c
  M  test/keygentest.c
  M  tools/pisacert.c

=== modified file 'Makefile.am'
--- Makefile.am 2010-03-10 16:30:43 +0000
+++ Makefile.am 2010-03-10 17:44:36 +0000
@@ -246,7 +246,6 @@
                                  lib/core/debug.c \
                                  lib/core/message.c \
                                  lib/core/esp_prot_common.c \
-                                 lib/core/misc.c \
                                  lib/core/hostsfiles.c \
                                  lib/core/filemanip.c \
                                  lib/core/hashchain.c \
@@ -256,6 +255,7 @@
                                  lib/core/transform.c \
                                  lib/core/keylen.c \
                                  lib/core/hit.c \
+                                 lib/core/straddr.c \
                                  lib/core/sqlitedbapi.c \
                                  lib/core/hashchain_store.c \
                                  lib/core/hip_statistics.c \
@@ -391,13 +391,15 @@
 
 ### *_LDADD ###
 
-test_conntest_client_opp_LDADD = lib/core/libhipcore.la \
-                                 lib/tool/libhiptool.la
+test_conntest_client_opp_LDADD =
 
 if HIP_OPPORTUNISTIC
 test_conntest_client_opp_LDADD += lib/opphip/libopphip.la
 endif
 
+test_conntest_client_opp_LDADD += lib/core/libhipcore.la \
+                                  lib/tool/libhiptool.la
+
 if HIP_PERFORMANCE
 test_conntest_client_opp_LDADD += lib/performance/libperformance.la
 endif
@@ -437,9 +439,9 @@
 
 
 if HIP_DHT
-test_dhtteststub_LDADD = lib/core/libhipcore.la \
-                             lib/tool/libhiptool.la \
-                             lib/dht/libhipdht.la
+test_dhtteststub_LDADD = lib/dht/libhipdht.la \
+                         lib/core/libhipcore.la \
+                         lib/tool/libhiptool.la
 
 if HIP_PERFORMANCE
 test_dhtteststub_LDADD += lib/performance/libperformance.la
@@ -479,9 +481,9 @@
                             lib/performance/libperformance.la
 endif
 
-tools_hipconf_LDADD = lib/core/libhipcore.la \
-                      lib/tool/libhiptool.la \
-                      lib/conf/libhipconf.la
+tools_hipconf_LDADD = lib/conf/libhipconf.la \
+                      lib/core/libhipcore.la \
+                      lib/tool/libhiptool.la
 
 # required by libhipconf
 if HIP_PERFORMANCE

=== modified file 'agent/connhipd.c'
--- agent/connhipd.c    2010-03-05 09:01:57 +0000
+++ agent/connhipd.c    2010-03-10 17:44:36 +0000
@@ -18,6 +18,7 @@
 #include <errno.h>
 #include <string.h>
 #include <fcntl.h>
+#include <unistd.h>
 
 #include "connhipd.h"
 #include "agent.h"
@@ -30,6 +31,7 @@
 #include "lib/core/icomm.h"
 #include "lib/core/message.h"
 #include "lib/core/builder.h"
+#include "lib/core/straddr.h"
 
 /* This socket is used for communication between agent and HIP daemon. */
 int hip_agent_sock           = 0;

=== modified file 'firewall/cache.c'
--- firewall/cache.c    2010-03-03 13:16:18 +0000
+++ firewall/cache.c    2010-03-10 17:44:36 +0000
@@ -16,7 +16,9 @@
 
 #include "cache.h"
 #include "lib/core/debug.h"
-#include "lib/core/misc.h"
+#include "lib/core/builder.h"
+#include "lib/core/message.h"
+
 #include "firewall.h"
 #include "user_ipsec_api.h"
 

=== modified file 'firewall/cache_port.c'
--- firewall/cache_port.c       2010-03-10 13:03:35 +0000
+++ firewall/cache_port.c       2010-03-10 17:44:36 +0000
@@ -23,9 +23,14 @@
 /* required for s6_addr32 */
 #define _BSD_SOURCE
 
+#include <stdio.h>
+
 #include "cache_port.h"
 #include "cache.h"
-#include "lib/core/misc.h"
+
+#include <lib/tool/lutil.h>
+
+
 
 static HIP_HASHTABLE *firewall_port_cache_db = NULL;
 

=== modified file 'firewall/common_hipd_msg.c'
--- firewall/common_hipd_msg.c  2010-02-17 17:38:08 +0000
+++ firewall/common_hipd_msg.c  2010-03-10 17:44:36 +0000
@@ -5,6 +5,7 @@
 #include "lib/core/ife.h"
 #include "lib/core/debug.h"
 #include "lib/core/builder.h"
+#include "lib/core/message.h"
 #include "firewall.h"
 
 /**

=== modified file 'firewall/conntrack.c'
--- firewall/conntrack.c        2010-03-09 18:26:22 +0000
+++ firewall/conntrack.c        2010-03-10 17:44:36 +0000
@@ -26,7 +26,7 @@
 #include "hslist.h"
 #include "esp_prot_conntrack.h"
 #include "datapkt.h"
-#include "lib/core/misc.h"
+
 #include "lib/core/hostid.h"
 #include "lib/core/hip_udp.h"
 #include "hipd/hadb.h"

=== modified file 'firewall/datapkt.c'
--- firewall/datapkt.c  2010-03-10 13:03:35 +0000
+++ firewall/datapkt.c  2010-03-10 17:44:36 +0000
@@ -27,6 +27,8 @@
 /* required for s6_addr32 */
 #define _BSD_SOURCE
 
+#include <netinet/ip.h>
+
 #include "config.h"
 #include "datapkt.h"
 #include "user_ipsec_api.h"
@@ -36,6 +38,7 @@
 #include "lib/core/ife.h"
 #include "lib/core/builder.h"
 #include "lib/core/hostid.h"
+#include "lib/core/message.h"
 
 static unsigned char *hip_data_packet = NULL;
 

=== modified file 'firewall/esp_prot_conntrack.c'
--- firewall/esp_prot_conntrack.c       2010-03-09 18:26:22 +0000
+++ firewall/esp_prot_conntrack.c       2010-03-10 17:44:36 +0000
@@ -15,6 +15,7 @@
 /* required for s6_addr32 */
 #define _BSD_SOURCE
 
+#include <netinet/udp.h>
 #include "lib/core/builder.h"
 #include "config.h"
 #include "esp_prot_conntrack.h"

=== modified file 'firewall/esp_prot_fw_msg.c'
--- firewall/esp_prot_fw_msg.c  2010-03-05 08:57:28 +0000
+++ firewall/esp_prot_fw_msg.c  2010-03-10 17:44:36 +0000
@@ -13,9 +13,12 @@
 /* required for s6_addr32 */
 #define _BSD_SOURCE
 
+#include <netinet/udp.h>
+
 #include "lib/core/debug.h"
 #include "lib/core/ife.h"
 #include "lib/core/builder.h"
+#include "lib/core/message.h"
 
 #include "esp_prot_fw_msg.h"
 #include "esp_prot_api.h"

=== modified file 'firewall/firewalldb.c'
--- firewall/firewalldb.c       2010-03-09 21:23:38 +0000
+++ firewall/firewalldb.c       2010-03-10 17:44:36 +0000
@@ -17,6 +17,8 @@
 
 #include <netinet/ip_icmp.h>
 #include <netinet/icmp6.h>
+#include <netinet/udp.h>
+#include <netinet/tcp.h>
 
 #include "firewalldb.h"
 #include "cache.h"
@@ -24,7 +26,8 @@
 #include "lib/core/icomm.h"
 #include "lib/core/debug.h"
 #include "lib/core/hashtable.h"
-#include "lib/core/misc.h"
+#include "lib/core/builder.h"
+
 #include "lib/tool/checksum.h"
 
 #define DISABLE_hip_firewall_hldb_dump

=== modified file 'firewall/lsi.c'
--- firewall/lsi.c      2010-03-10 13:03:35 +0000
+++ firewall/lsi.c      2010-03-10 17:44:36 +0000
@@ -25,16 +25,126 @@
 /* required for s6_addr32 */
 #define _BSD_SOURCE
 
+#include <netinet/ip6.h>
+#include <netinet/tcp.h>
+#include <netinet/udp.h>
 #include "cache.h"
 #include "cache_port.h"
 #include "firewall.h"
 #include "firewalldb.h"
 #include "lsi.h"
 #include "lib/core/builder.h"
+#include "lib/core/message.h"
 
 #define BUFSIZE HIP_MAX_PACKET
 
 /**
+ * build a message for hipd to trigger a base exchange
+ *
+ * @param src_hit an optional source HIT for the I1
+ * @param dst_hit a destination HIT for the I1
+ * @param src_lsi an optional source LSI (corresponding to a local HIT)
+ * @param dst_lsi a destination LSI for the I1
+ * @param src_ip  an optional source IP address for the I1
+ * @param dst_ip  a destination IP for the I1
+ * @return        zero on success or negative on error
+
+ * @note Many of the parameters are optional, but at least a
+ * destination LSI, HIT or IP (for opportunistic BEX) must to be
+ * provided
+ */
+int hip_trigger_bex(const struct in6_addr *src_hit,
+                    const struct in6_addr *dst_hit,
+                    struct in6_addr *src_lsi,
+                    struct in6_addr *dst_lsi,
+                    struct in6_addr *src_ip,
+                    struct in6_addr *dst_ip)
+{
+    struct hip_common *msg = NULL;
+    int err                = 0;
+    HIP_IFE(!(msg = hip_msg_alloc()), -1);
+    HIP_IFEL(!dst_hit && !dst_ip, -1,
+             "neither destination hit nor ip provided\n");
+
+    /* NOTE: we need this sequence in order to process the incoming
+     * message correctly */
+
+    /* build the message header */
+    HIP_IFEL(hip_build_user_hdr(msg, SO_HIP_TRIGGER_BEX, 0),
+             -1, "build hdr failed\n");
+
+    /* destination HIT, LSI or IP are obligatory */
+    if (dst_hit) {
+        HIP_DEBUG_HIT("dst_hit: ", dst_hit);
+        HIP_IFEL(hip_build_param_contents(msg, (void *) (dst_hit),
+                                          HIP_PARAM_HIT,
+                                          sizeof(struct in6_addr)),
+                 -1, "build param HIP_PARAM_HIT failed\n");
+    }
+
+    /* source HIT is optional */
+    if (src_hit) {
+        HIP_DEBUG_HIT("src_hit: ", src_hit);
+        HIP_IFEL(hip_build_param_contents(msg, (void *) (src_hit),
+                                          HIP_PARAM_HIT,
+                                          sizeof(struct in6_addr)),
+                 -1, "build param HIP_PARAM_HIT failed\n");
+    }
+
+    /* destination LSI is obligatory */
+    if (dst_lsi) {
+        HIP_DEBUG_IN6ADDR("dst lsi: ", dst_lsi);
+        HIP_IFEL(hip_build_param_contents(msg, (void *) (dst_lsi),
+                                          HIP_PARAM_LSI,
+                                          sizeof(struct in6_addr)),
+                 -1, "build param HIP_PARAM_LSI failed\n");
+    }
+
+    /* source LSI is optional */
+    if (src_lsi) {
+        HIP_DEBUG_IN6ADDR("src lsi: ", src_lsi);
+        HIP_IFEL(hip_build_param_contents(msg, (void *) (src_lsi),
+                                          HIP_PARAM_LSI,
+                                          sizeof(struct in6_addr)),
+                 -1, "build param HIP_PARAM_LSI failed\n");
+    }
+
+    /* if no destination HIT is provided, at least destination IP must
+       exist */
+    if (dst_ip) {
+        HIP_DEBUG_IN6ADDR("dst_ip: ", dst_ip);
+        HIP_IFEL(hip_build_param_contents(msg, (void *) (dst_ip),
+                                          HIP_PARAM_IPV6_ADDR,
+                                          sizeof(struct in6_addr)),
+                 -1, "build param HIP_PARAM_IPV6_ADDR failed\n");
+    }
+
+    /* this again is optional */
+    if (src_ip) {
+        HIP_DEBUG_IN6ADDR("src_ip: ", src_ip);
+        HIP_IFEL(hip_build_param_contents(msg, (void *) (src_ip),
+                                          HIP_PARAM_IPV6_ADDR,
+                                          sizeof(struct in6_addr)),
+                 -1, "build param HIP_PARAM_IPV6_ADDR failed\n");
+    }
+
+    HIP_DUMP_MSG(msg);
+
+    /* send msg to hipd and receive corresponding reply */
+    HIP_IFEL(hip_send_recv_daemon_info(msg, 0, 0), -1, "send_recv msg 
failed\n");
+
+    /* check error value */
+    HIP_IFEL(hip_get_msg_err(msg), -1, "hipd returned error message!\n");
+    HIP_DEBUG("Send_recv msg succeed \n");
+
+out_err:
+    if (msg) {
+        HIP_FREE(msg);
+    }
+    return err;
+}
+
+/**
  * Checks if the packet is a reinjection
  *
  * @param ip_src      pointer to the source address

=== modified file 'firewall/lsi.h'
--- firewall/lsi.h      2010-03-03 13:16:18 +0000
+++ firewall/lsi.h      2010-03-10 17:44:36 +0000
@@ -6,6 +6,12 @@
 #include <linux/netfilter_ipv4/ip_queue.h>
 #include "lib/core/protodefs.h"
 
+int hip_trigger_bex(const struct in6_addr *src_hit,
+                    const struct in6_addr *dst_hit,
+                    struct in6_addr *src_lsi,
+                    struct in6_addr *dst_lsi,
+                    struct in6_addr *src_ip,
+                    struct in6_addr *dst_ip);
 int hip_fw_handle_incoming_hit(const ipq_packet_msg_t *m,
                                const struct in6_addr *ip_src,
                                const struct in6_addr *ip_dst,

=== modified file 'firewall/opptcp.c'
--- firewall/opptcp.c   2010-02-17 17:38:08 +0000
+++ firewall/opptcp.c   2010-03-10 17:44:36 +0000
@@ -36,11 +36,13 @@
 /* required for s6_addr32 */
 #define _BSD_SOURCE
 
+#include <netinet/tcp.h>
 #include "opptcp.h"
 #include "firewalldb.h"
 #include "lib/core/debug.h"
 #include "lib/core/protodefs.h"
 #include "lib/core/builder.h"
+#include "lib/core/message.h"
 #include "common_hipd_msg.h"
 #include "firewall.h"
 

=== modified file 'firewall/pisa.c'
--- firewall/pisa.c     2010-03-09 18:26:22 +0000
+++ firewall/pisa.c     2010-03-10 17:44:36 +0000
@@ -23,7 +23,7 @@
 #include "config.h"
 #include "lib/core/ife.h"
 #include "midauth.h"
-#include "lib/core/misc.h"
+
 #include "pisa.h"
 #include "pisa_cert.h"
 #define PISA_RANDOM_LEN 16

=== modified file 'firewall/sysopp.c'
--- firewall/sysopp.c   2010-02-17 17:38:08 +0000
+++ firewall/sysopp.c   2010-03-10 17:44:36 +0000
@@ -1,14 +1,19 @@
 /* required for s6_addr32 */
 #define _BSD_SOURCE
 
+#include <netinet/ip6.h>
+#include <netinet/tcp.h>
+#include <netinet/udp.h>
+
 #include "lib/core/debug.h"
 #include "lib/core/builder.h"
-
+#include "lib/core/message.h"
 #include "sysopp.h"
 #include "firewall.h"
 #include "firewalldb.h"
 #include "lsi.h"
 #include "common_hipd_msg.h"
+#include "lib/core/hostid.h"
 
 void hip_fw_flush_system_based_opp_chains(void)
 {

=== modified file 'firewall/user_ipsec_api.c'
--- firewall/user_ipsec_api.c   2010-02-17 17:38:08 +0000
+++ firewall/user_ipsec_api.c   2010-03-10 17:44:36 +0000
@@ -21,6 +21,7 @@
 #include "esp_prot_api.h"
 #include "lib/core/ife.h"
 #include "lib/core/debug.h"
+#include "lsi.h"
 
 #define USER_IPSEC_INACTIVE 0
 #define USER_IPSEC_ACTIVE 1

=== modified file 'firewall/user_ipsec_api.h'
--- firewall/user_ipsec_api.h   2010-02-17 17:38:08 +0000
+++ firewall/user_ipsec_api.h   2010-03-10 17:44:36 +0000
@@ -16,7 +16,7 @@
 
 #include <netinet/udp.h>
 #include <openssl/evp.h>
-#include "lib/core/misc.h"
+
 #include "firewall_defines.h"
 
 /* this is the maximum buffer-size needed for an userspace ipsec esp packet

=== modified file 'firewall/user_ipsec_esp.c'
--- firewall/user_ipsec_esp.c   2010-03-10 11:34:35 +0000
+++ firewall/user_ipsec_esp.c   2010-03-10 17:44:36 +0000
@@ -32,7 +32,7 @@
 #include "user_ipsec_esp.h"
 #include "esp_prot_api.h"
 #include "lib/core/prefix.h"
-#include "lib/core/misc.h"
+
 #include "lib/tool/checksum.h"
 #include "lib/core/keylen.h"
 

=== modified file 'firewall/user_ipsec_fw_msg.c'
--- firewall/user_ipsec_fw_msg.c        2010-02-17 17:38:08 +0000
+++ firewall/user_ipsec_fw_msg.c        2010-03-10 17:44:36 +0000
@@ -16,6 +16,7 @@
 #include "esp_prot_fw_msg.h"
 #include "firewall.h"
 #include "lib/core/builder.h"
+#include "lib/core/message.h"
 
 #define DEFAULT_LIFETIME 0 /* place holder as timeout not implemented yet */
 

=== modified file 'firewall/user_ipsec_sadb.c'
--- firewall/user_ipsec_sadb.c  2010-03-10 11:34:35 +0000
+++ firewall/user_ipsec_sadb.c  2010-03-10 17:44:36 +0000
@@ -17,13 +17,16 @@
 
 #include <pthread.h>
 #include <openssl/sha.h>
+#include <string.h>
 
 #include "user_ipsec_sadb.h"
 #include "esp_prot_api.h"
 #include "firewall.h"
 #include "lib/core/ife.h"
-#include "lib/core/misc.h"
 #include "lib/core/keylen.h"
+#include "lib/core/debug.h"
+#include "lib/core/state.h"
+#include "lib/core/builder.h"
 
 /* hash functions used for calculating the entries' hashes
  *

=== modified file 'hipd/bos.h'
--- hipd/bos.h  2010-02-17 17:38:08 +0000
+++ hipd/bos.h  2010-03-10 17:44:36 +0000
@@ -13,9 +13,6 @@
 #include "lib/core/state.h"
 
 int hip_send_bos(const struct hip_common *msg);
-int hip_verify_packet_signature(struct hip_common *bos,
-                                struct hip_host_id *peer_host_id);
-
 int hip_handle_bos(struct hip_common *bos,
                    struct in6_addr *bos_saddr,
                    struct in6_addr *bos_daddr,

=== modified file 'hipd/cert.h'
--- hipd/cert.h 2010-03-09 18:26:22 +0000
+++ hipd/cert.h 2010-03-10 17:44:36 +0000
@@ -26,7 +26,7 @@
 #include "config.h"
 #include "lib/core/debug.h"
 #include "lib/core/ife.h"
-#include "lib/core/misc.h"
+
 #include "hidb.h"
 #include "lib/core/hashtable.h"
 

=== modified file 'hipd/close.h'
--- hipd/close.h        2010-02-17 17:38:08 +0000
+++ hipd/close.h        2010-03-10 17:44:36 +0000
@@ -2,7 +2,7 @@
 #define HIP_HIPD_CLOSE_H
 
 #include "hadb.h"
-#include "lib/core/misc.h"
+
 #include "hidb.h"
 #include "lib/core/builder.h"
 #include "cookie.h"
@@ -10,7 +10,7 @@
 #include "lib/core/debug.h"
 #include "keymat.h"
 #include "lib/core/crypto.h"
-#include "lib/core/misc.h"
+
 #include "lib/tool/pk.h"
 
 int hip_send_close(struct hip_common *msg, int delete_ha_info);

=== modified file 'hipd/configfilereader.c'
--- hipd/configfilereader.c     2010-02-17 17:38:08 +0000
+++ hipd/configfilereader.c     2010-03-10 17:44:36 +0000
@@ -10,6 +10,7 @@
 #define _BSD_SOURCE
 
 #include "configfilereader.h"
+#include "lib/core/debug.h"
 
 /** Error value for generic config file error. (Everything but -EIO and EOF are
  *  acceptable here.) */

=== modified file 'hipd/configfilereader.h'
--- hipd/configfilereader.h     2010-02-17 17:38:08 +0000
+++ hipd/configfilereader.h     2010-03-10 17:44:36 +0000
@@ -63,7 +63,7 @@
 #include <string.h>
 #include <ctype.h>
 #include <errno.h>
-#include "lib/core/misc.h" /* For debuging macros. */
+ /* For debuging macros. */
 
 /** Maximum number of characters per line in HIP relay config file. */
 #define HIP_RELAY_MAX_LINE_LEN 2048

=== modified file 'hipd/dhtqueue.c'
--- hipd/dhtqueue.c     2010-02-17 17:38:08 +0000
+++ hipd/dhtqueue.c     2010-03-10 17:44:36 +0000
@@ -9,11 +9,13 @@
 #define _BSD_SOURCE
 
 #include <stdlib.h>
+#include "dhtqueue.h"
+#include "hipd.h"
 #include "lib/core/hashtable.h"
 #include "lib/core/debug.h"
-
-#include "dhtqueue.h"
-#include "lib/core/misc.h"
+#include "lib/core/builder.h"
+
+
 
 struct hip_queue {
     void *data;

=== modified file 'hipd/esp_prot_anchordb.c'
--- hipd/esp_prot_anchordb.c    2010-02-17 17:38:08 +0000
+++ hipd/esp_prot_anchordb.c    2010-03-10 17:44:36 +0000
@@ -20,7 +20,8 @@
 #include "lib/core/esp_prot_common.h"
 #include "lib/core/builder.h"
 #include "esp_prot_anchordb.h"
-
+#include "hipd.h"
+#include "init.h"
 
 /* defines the structure storing the anchors */
 typedef struct anchor_db {

=== modified file 'hipd/esp_prot_light_update.c'
--- hipd/esp_prot_light_update.c        2010-03-08 22:21:34 +0000
+++ hipd/esp_prot_light_update.c        2010-03-10 17:44:36 +0000
@@ -17,6 +17,7 @@
 
 #include "esp_prot_light_update.h"
 #include "esp_prot_anchordb.h"
+#include "hipd.h"
 #include "lib/core/builder.h"
 #include "lib/core/hip_udp.h"
 

=== modified file 'hipd/hadb.h'
--- hipd/hadb.h 2010-03-09 18:26:22 +0000
+++ hipd/hadb.h 2010-03-10 17:44:36 +0000
@@ -5,11 +5,12 @@
 #include "keymat.h"
 #include "lib/tool/pk.h"
 #include "lib/core/debug.h"
-#include "lib/core/misc.h"
+
 #include "hidb.h"
 #include "lib/core/hashtable.h"
 #include "lib/core/state.h"
 #include "lib/core/builder.h"
+#include "lib/core/straddr.h"
 #include "input.h"      // required for declaration of receive functions
 #include "update.h"     // required for declaration of update function
 #include "user_ipsec_sadb_api.h"

=== modified file 'hipd/hipd.c'
--- hipd/hipd.c 2010-03-09 18:26:22 +0000
+++ hipd/hipd.c 2010-03-10 17:44:36 +0000
@@ -13,10 +13,11 @@
 #include "config.h"
 #include "hipd.h"
 #include "lib/dht/libhipdht.h"
+#include "lib/core/filemanip.h"
+#include "lib/core/straddr.h"
 #include "heartbeat.h"
 
 #ifdef CONFIG_HIP_PERFORMANCE
-#include "lib/core/filemanip.h"
 #include "lib/performance/performance.h"
 #endif
 

=== modified file 'hipd/hipd.h'
--- hipd/hipd.h 2010-03-09 18:26:22 +0000
+++ hipd/hipd.h 2010-03-10 17:44:36 +0000
@@ -73,8 +73,6 @@
 #define HIP_SIMULATE_PACKET_LOSS_PROBABILITY 0
 #define HIP_SIMULATE_PACKET_IS_LOST() (random() < ((uint64_t) 
HIP_SIMULATE_PACKET_LOSS_PROBABILITY * RAND_MAX) / 100)
 
-#define HIP_NETLINK_TALK_ACK 0 /* see netlink_talk */
-
 #define HIP_ADDRESS_CHANGE_WAIT_INTERVAL 6 /* seconds */
 #define HIP_ADDRESS_CHANGE_HB_COUNT_TRIGGER 2
 
@@ -190,6 +188,4 @@
 /* Functions for handling outgoing packets. */
 int hip_sendto_firewall(const struct hip_common *msg);
 
-#define IPV4_HDR_SIZE 20
-
 #endif /* HIP_HIPD_HIPD_H */

=== modified file 'hipd/hiprelay.c'
--- hipd/hiprelay.c     2010-03-09 18:26:22 +0000
+++ hipd/hiprelay.c     2010-03-10 17:44:36 +0000
@@ -19,6 +19,7 @@
 
 #include "config.h"
 #include "hiprelay.h"
+#include "output.h"
 #include "lib/core/hip_udp.h"
 
 /** HIP relay config file default content. If the file @c HIP_RELAY_CONFIG_FILE

=== modified file 'hipd/hiprelay.h'
--- hipd/hiprelay.h     2010-03-09 18:26:22 +0000
+++ hipd/hiprelay.h     2010-03-10 17:44:36 +0000
@@ -77,7 +77,7 @@
 #include <math.h> /* For pow() */
 
 #include "config.h"
-#include "lib/core/misc.h" /* For debuging macros. */
+ /* For debuging macros. */
 #include "registration.h" /* For lifetime conversions. */
 #include "configfilereader.h"
 #include "lib/core/state.h"

=== modified file 'hipd/init.c'
--- hipd/init.c 2010-03-09 18:26:22 +0000
+++ hipd/init.c 2010-03-10 17:44:36 +0000
@@ -13,17 +13,18 @@
 #include <netinet/icmp6.h>
 
 #include "config.h"
+#include "init.h"
+#include "oppdb.h"
 #include "lib/core/common_defines.h"
 #include "lib/core/debug.h"
-#include "init.h"
 #include "lib/performance/performance.h"
 #include "lib/core/hip_capability.h"
 #include "lib/core/filemanip.h"
 #include "lib/core/hostid.h"
 #include "lib/tool/nlink.h"
-#include "oppdb.h"
 #include "lib/dht/libhipdht.h"
 #include "lib/core/hip_udp.h"
+#include "lib/core/hostsfiles.h"
 
 #ifdef CONFIG_HIP_AGENT
 #include "hipd.h"

=== modified file 'hipd/input.c'
--- hipd/input.c        2010-03-10 13:03:35 +0000
+++ hipd/input.c        2010-03-10 17:44:36 +0000
@@ -30,7 +30,7 @@
 #include "lib/core/transform.h"
 #include "lib/core/keylen.h"
 #include "dh.h"
-#include "lib/core/misc.h"
+
 #include "hidb.h"
 #include "cookie.h"
 #include "output.h"

=== modified file 'hipd/keymat.h'
--- hipd/keymat.h       2010-03-05 08:47:53 +0000
+++ hipd/keymat.h       2010-03-10 17:44:36 +0000
@@ -2,7 +2,7 @@
 #define HIP_HIPD_KEYMAT_H
 
 #include "lib/core/list.h"
-#include "lib/core/misc.h"
+
 #include "lib/core/crypto.h"
 #include "lib/core/state.h"
 

=== modified file 'hipd/nat.h'
--- hipd/nat.h  2010-03-08 22:21:34 +0000
+++ hipd/nat.h  2010-03-10 17:44:36 +0000
@@ -28,13 +28,6 @@
 #define HIP_NAT_KEEP_ALIVE_INTERVAL 20
 /** Port number for NAT traversal of hip control packets. */
 
-/** For setting socket to listen for beet-udp packets. */
-#define HIP_UDP_ENCAP 100
-/** UDP encapsulation type. */
-#define HIP_UDP_ENCAP_ESPINUDP 2
-/** UDP encapsulation type. */
-#define HIP_UDP_ENCAP_ESPINUDP_NONIKE 1
-
 extern HIP_HASHTABLE *hadb_hit;
 hip_transform_suite_t hip_get_nat_mode(hip_ha_t *entry);
 int hip_nat_refresh_port(void);

=== modified file 'hipd/netdev.h'
--- hipd/netdev.h       2010-03-09 18:26:22 +0000
+++ hipd/netdev.h       2010-03-10 17:44:36 +0000
@@ -13,7 +13,7 @@
 #include "lib/core/list.h"
 #include "lib/core/debug.h"
 #include "lib/core/prefix.h"
-#include "lib/core/misc.h"
+
 #include "hit_to_ip.h"
 
 #ifdef CONFIG_HIP_MAEMO

=== modified file 'hipd/oppdb.c'
--- hipd/oppdb.c        2010-03-09 18:26:22 +0000
+++ hipd/oppdb.c        2010-03-10 17:44:36 +0000
@@ -16,6 +16,7 @@
 #include "oppdb.h"
 #include "hadb.h"
 #include "accessor.h"
+#include "lib/core/hit.h"
 
 #define HIP_LOCK_OPP_INIT(entry)
 #define HIP_UNLOCK_OPP_INIT(entry)

=== modified file 'hipd/oppdb.h'
--- hipd/oppdb.h        2010-03-03 13:16:18 +0000
+++ hipd/oppdb.h        2010-03-10 17:44:36 +0000
@@ -13,7 +13,7 @@
 #include <sys/socket.h>
 #include <sys/un.h>
 #include "lib/core/debug.h"
-#include "lib/core/misc.h"
+
 #include "hidb.h"
 #include "lib/core/hashtable.h"
 #include "lib/core/builder.h"

=== modified file 'hipd/output.h'
--- hipd/output.h       2010-03-09 18:26:22 +0000
+++ hipd/output.h       2010-03-10 17:44:36 +0000
@@ -21,7 +21,7 @@
 #include "dh.h"
 #include "hidb.h"
 #include "hadb.h"
-#include "lib/core/misc.h"
+
 #include "lib/core/builder.h"
 #include "cookie.h"
 #include "close.h"

=== modified file 'hipd/registration.c'
--- hipd/registration.c 2010-03-07 11:20:52 +0000
+++ hipd/registration.c 2010-03-10 17:44:36 +0000
@@ -14,6 +14,7 @@
 #define _BSD_SOURCE
 
 #include "registration.h"
+#include "hadb.h"
 
 /**
  * Pending request lifetime. Pending requests are created when the requester

=== modified file 'hipd/registration.h'
--- hipd/registration.h 2010-03-05 09:10:50 +0000
+++ hipd/registration.h 2010-03-10 17:44:36 +0000
@@ -14,7 +14,6 @@
 #ifndef HIP_HIPD_REGISTRATION_H
 #define HIP_HIPD_REGISTRATION_H
 
-#include "lib/core/misc.h"
 #include "lib/core/builder.h" // For lifetime conversions.
 #include "lib/core/protodefs.h" // For service type values and hip_ha_t
 #include "hiprelay.h" // For relrec lifetimes.

=== modified file 'hipd/user_ipsec_hipd_msg.c'
--- hipd/user_ipsec_hipd_msg.c  2010-02-17 14:11:29 +0000
+++ hipd/user_ipsec_hipd_msg.c  2010-03-10 17:44:36 +0000
@@ -14,6 +14,9 @@
 #define _BSD_SOURCE
 
 #include "user_ipsec_hipd_msg.h"
+#include "hipd.h"
+#include "init.h"
+#include "user_ipsec_sadb_api.h"
 #include "lib/core/builder.h"
 
 /**

=== modified file 'lib/conf/hipconf.c'
--- lib/conf/hipconf.c  2010-03-10 10:03:40 +0000
+++ lib/conf/hipconf.c  2010-03-10 17:44:36 +0000
@@ -40,10 +40,13 @@
 #include "config.h"
 #include "lib/core/builder.h"
 #include "lib/core/debug.h"
+#include "lib/core/straddr.h"
 #include "hipconf.h"
 #include "lib/core/prefix.h"
 #include "lib/dht/libhipdht.h"
 #include "lib/core/hostid.h"
+#include "lib/core/message.h"
+#include "lib/core/crypto.h"
 
 /**
  * TYPE_ constant list, as an index for each action_handler function.

=== modified file 'lib/core/builder.h'
--- lib/core/builder.h  2010-03-09 21:23:38 +0000
+++ lib/core/builder.h  2010-03-10 17:44:36 +0000
@@ -15,7 +15,7 @@
 
 #include "config.h"
 #include "debug.h"
-#include "misc.h"
+
 #include "icomm.h"
 #include "certtools.h"
 #include "hipd/registration.h"

=== modified file 'lib/core/certtools.c'
--- lib/core/certtools.c        2010-03-03 13:16:18 +0000
+++ lib/core/certtools.c        2010-03-10 17:44:36 +0000
@@ -8,6 +8,8 @@
 #define _BSD_SOURCE
 
 #include "certtools.h"
+#include "straddr.h"
+#include "lib/core/crypto.h"
 
 
/*******************************************************************************
 * FUNCTIONS FOR SPKI                                                          *

=== modified file 'lib/core/certtools.h'
--- lib/core/certtools.h        2010-03-09 18:26:22 +0000
+++ lib/core/certtools.h        2010-03-10 17:44:36 +0000
@@ -26,7 +26,7 @@
 #include "config.h"
 #include "debug.h"
 #include "ife.h"
-#include "misc.h"
+
 #include "hashtable.h"
 
 /** Defines */

=== modified file 'lib/core/debug.c'
--- lib/core/debug.c    2010-03-09 18:26:22 +0000
+++ lib/core/debug.c    2010-03-10 17:44:36 +0000
@@ -51,6 +51,7 @@
 
 #include "config.h"
 #include "debug.h"
+#include "straddr.h"
 #include "lib/tool/lutil.h"
 #include "lib/conf/hipconf.h"
 

=== modified file 'lib/core/filemanip.h'
--- lib/core/filemanip.h        2010-03-09 18:26:22 +0000
+++ lib/core/filemanip.h        2010-03-10 17:44:36 +0000
@@ -5,6 +5,15 @@
 
 #include "config.h"
 
+#ifdef CONFIG_HIP_OPENWRT
+# define HIP_CREATE_FILE(x)     check_and_create_file(x, 0644)
+#else
+# define HIP_CREATE_FILE(x)     open((x), O_RDWR | O_CREAT, 0644)
+#endif
+
+/* system/bin for Android */
+#define HIP_DEFAULT_EXEC_PATH 
"/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin:/system/bin"
+
 int hip_create_lock_file(char *filename, int killold);
 int hip_remove_lock_file(char *filename);
 int check_and_create_dir(char *dirname, mode_t mode);

=== modified file 'lib/core/hashtable.c'
--- lib/core/hashtable.c        2010-03-03 13:16:18 +0000
+++ lib/core/hashtable.c        2010-03-10 17:44:36 +0000
@@ -24,9 +24,43 @@
  */
 #include "hashtable.h"
 
+/**
+ * A generic object hashing function for lib/core/hashtable.c
+ *
+ * @param ptr an pointer to hash (must be at least 32 bits)
+ * @return a hash of the first 32-bits of the ptr's data
+ */
+unsigned long hip_hash_generic(const void *ptr)
+{
+    unsigned long hash = (unsigned long) (*((uint32_t *) ptr));
+    return hash % ULONG_MAX;
+}
+
+/**
+ * A generic matching function for lib/core/hashtable.c
+ *
+ * @param ptr1 a pointer to an item in the hash table
+ * @param ptr2 a pointer to an item in the hash table
+ * @return zero if the pointers match or one otherwise
+ */
+int hip_match_generic(const void *ptr1, const void *ptr2)
+{
+    return ptr1 != ptr2;
+}
+
 #ifdef HIPL_OPENSSL_100
 
 /**
+ * Returns a generic linked list based on the hash table implementation
+ *
+ * @return an allocated hash table which is caller is responsible to free
+ */
+LHASH_OF(HIP_HT) * hip_linked_list_init(void)
+{
+  return (LHASH_OF(HIP_HT) *) hip_ht_init(hip_hash_generic, hip_match_generic);
+}
+
+/**
  * Initialize hash table (or linked list)
  *
  * @param hashfunc hash function to calculated the hash
@@ -41,6 +75,11 @@
 
 #else /* not HIPL_OPENSSL_100 */
 
+HIP_HASHTABLE *hip_linked_list_init(void)
+{
+    return (HIP_HASHTABLE *) hip_ht_init(hip_hash_generic, hip_match_generic);
+}
+
 HIP_HASHTABLE *hip_ht_init(LHASH_HASH_FN_TYPE hashfunc,
                            LHASH_COMP_FN_TYPE cmpfunc)
 {

=== modified file 'lib/core/hashtable.h'
--- lib/core/hashtable.h        2010-02-17 17:38:08 +0000
+++ lib/core/hashtable.h        2010-03-10 17:44:36 +0000
@@ -4,6 +4,7 @@
 #include <openssl/bio.h>
 #include <openssl/crypto.h>
 #include <openssl/lhash.h>
+#include <limits.h>
 #include "debug.h"
 #include "list.h"
 
@@ -35,6 +36,7 @@
 typedef DECLARE_LHASH_OF (HIP_HT) hip_ht_common;
 typedef hip_ht_common HIP_HASHTABLE;
 
+LHASH_OF(HIP_HT) * hip_linked_list_init(void);
 LHASH_OF(HIP_HT) * hip_ht_init(LHASH_HASH_FN_TYPE hashfunc, LHASH_COMP_FN_TYPE 
cmpfunc);
 
 #else
@@ -70,6 +72,7 @@
 typedef DECLARE_LHASH_OF (HIP_HT) hip_ht_common;
 typedef LHASH HIP_HASHTABLE;
 
+HIP_HASHTABLE *hip_linked_list_init(void);
 HIP_HASHTABLE *hip_ht_init(LHASH_HASH_FN_TYPE hashfunc,
                            LHASH_COMP_FN_TYPE cmpfunc);
 #endif

=== modified file 'lib/core/hip_udp.h'
--- lib/core/hip_udp.h  2010-03-08 22:21:34 +0000
+++ lib/core/hip_udp.h  2010-03-10 17:44:36 +0000
@@ -4,7 +4,14 @@
 #include <netinet/in.h>
 
 #define HIP_NAT_UDP_PORT 10500
-#define HIP_NAT_TURN_PORT 10500
+//#define HIP_NAT_TURN_PORT 10500
+
+/** For setting socket to listen for beet-udp packets. */
+#define HIP_UDP_ENCAP 100
+/** UDP encapsulation type. */
+#define HIP_UDP_ENCAP_ESPINUDP 2
+/** UDP encapsulation type. */
+#define HIP_UDP_ENCAP_ESPINUDP_NONIKE 1
 
 /**
  * Get HIP local NAT UDP port.

=== modified file 'lib/core/hit.c'
--- lib/core/hit.c      2010-03-10 13:04:05 +0000
+++ lib/core/hit.c      2010-03-10 17:44:36 +0000
@@ -13,7 +13,8 @@
 #include "config.h"
 #include "hit.h"
 #include "debug.h"
-#include "misc.h"
+#include "straddr.h"
+#include "builder.h"
 
 /**
  * convert a binary HIT into a string
@@ -67,3 +68,33 @@
 {
     return ipv6_addr_cmp(hit1, hit2) == 0;
 }
+
+/**
+ * hip_hash_hit - calculate a hash from a HIT
+ *
+ * @param key pointer to a HIT
+ * @param range range of the hash
+ *
+ * Returns value in range: 0 <= x < range
+ */
+unsigned long hip_hash_hit(const void *ptr)
+{
+    uint8_t hash[HIP_AH_SHA_LEN];
+
+    hip_build_digest(HIP_DIGEST_SHA1, ptr + sizeof(uint16_t),
+                     7 * sizeof(uint16_t), hash);
+
+    return *((unsigned long *) hash);
+}
+
+/**
+ * Verify if if two HITs match based on hashing
+ *
+ * @param ptr1 a HIT
+ * @param ptr2 a HIT
+ * @return zero if the HITs match or one otherwise
+ */
+int hip_match_hit(const void *ptr1, const void *ptr2)
+{
+    return hip_hash_hit(ptr1) != hip_hash_hit(ptr2);
+}

=== modified file 'lib/core/hit.h'
--- lib/core/hit.h      2010-03-10 13:04:05 +0000
+++ lib/core/hit.h      2010-03-10 17:44:36 +0000
@@ -9,5 +9,7 @@
                       const struct in6_addr *hit2);
 int hip_hit_are_equal(const struct in6_addr *hit1,
                       const struct in6_addr *hit2);
+unsigned long hip_hash_hit(const void *hit);
+int hip_match_hit(const void *, const void *);
 
 #endif /* HIP_LIB_CORE_HIT_H */

=== modified file 'lib/core/hostid.c'
--- lib/core/hostid.c   2010-03-10 13:03:35 +0000
+++ lib/core/hostid.c   2010-03-10 17:44:36 +0000
@@ -9,11 +9,12 @@
  */
 
 #include <netinet/in.h>
-#include <lib/core/ife.h>
-#include <lib/core/debug.h>
-#include <lib/core/protodefs.h>
-#include <lib/core/crypto.h>
 #include <stdlib.h>
+#include "lib/core/ife.h"
+#include "lib/core/debug.h"
+#include "lib/core/protodefs.h"
+#include "lib/core/crypto.h"
+#include "lib/tool/pk.h"
 
 #include "config.h"
 #include "hostid.h"

=== modified file 'lib/core/hostid.h'
--- lib/core/hostid.h   2010-03-10 13:03:35 +0000
+++ lib/core/hostid.h   2010-03-10 17:44:36 +0000
@@ -1,6 +1,22 @@
 #ifndef HIP_LIB_CORE_HOSTID_H
 #define HIP_LIB_CORE_HOSTID_H
 
+#include "state.h"
+
+struct hip_rsa_keylen {
+    int e_len;
+    int e;
+    int n;
+};
+
+struct hip_hit_info {
+    struct hip_lhi lhi;
+    hip_lsi_t      lsi;
+};
+
+int hip_verify_packet_signature(struct hip_common *pkt,
+                                struct hip_host_id *peer_host_id);
+
 int hip_dsa_host_id_to_hit(const struct hip_host_id *host_id,
                            struct in6_addr *hit, int hit_type);
 

=== modified file 'lib/core/hostsfiles.c'
--- lib/core/hostsfiles.c       2010-03-09 18:26:22 +0000
+++ lib/core/hostsfiles.c       2010-03-10 17:44:36 +0000
@@ -23,9 +23,9 @@
 #include <netinet/in.h>
 
 #include "config.h"
-#include "misc.h"
+
 #include "hostsfiles.h"
-
+#include "lib/tool/lutil.h"
 
 /**
  * A "for-each" iterator function for hosts files that returns the first

=== modified file 'lib/core/hostsfiles.h'
--- lib/core/hostsfiles.h       2010-03-09 19:45:13 +0000
+++ lib/core/hostsfiles.h       2010-03-10 17:44:36 +0000
@@ -4,6 +4,10 @@
 #include "prefix.h"
 #include "lib/conf/hipconf.h"
 
+#ifndef HOST_NAME_MAX
+#  define HOST_NAME_MAX 64
+#endif /* HOST_NAME_MAX */
+
 int hip_map_first_id_to_hostname_from_hosts(const struct hosts_file_line 
*entry,
                                             const void *arg,
                                             void *result);
@@ -28,5 +32,8 @@
                                       hip_lsi_t *lsi,
                                       struct in6_addr *ip);
 int hip_map_lsi_to_hostname_from_hosts(hip_lsi_t *lsi, char *hostname);
+int hip_get_random_hostname_id_from_hosts(char *filename,
+                                          char *hostname,
+                                          char *id_str);
 
 #endif /* HIP_LIB_CORE_HOSTSFILES_H */

=== modified file 'lib/core/message.c'
--- lib/core/message.c  2010-03-08 22:21:34 +0000
+++ lib/core/message.c  2010-03-10 17:44:36 +0000
@@ -67,6 +67,7 @@
 /* required for s6_addr32 */
 #define _BSD_SOURCE
 
+#include <unistd.h>
 #include "message.h"
 #include "hip_udp.h"
 

=== modified file 'lib/core/prefix.c'
--- lib/core/prefix.c   2010-03-10 13:03:35 +0000
+++ lib/core/prefix.c   2010-03-10 17:44:36 +0000
@@ -118,6 +118,19 @@
 }
 
 /**
+ * compare two LSIs for equality
+ *
+ * @param lsi1 an LSI
+ * @param lsi2 an LSI
+ * @return one if the LSIs are equal or zero otherwise
+ */
+int hip_lsi_are_equal(const hip_lsi_t *lsi1,
+                      const hip_lsi_t *lsi2)
+{
+    return ipv4_addr_cmp(lsi1, lsi2) == 0;
+}
+
+/**
  * check the type of an IPv6 addresses
  *
  * @param id an IPv6 address, possibly in IPv6 mapped format
@@ -338,3 +351,54 @@
     IPV6_TO_IPV4_MAP(addr, &addr_in);
     return IS_IPV4_LOOPBACK(addr_in.s_addr);
 }
+
+int ipv4_addr_cmp(const struct in_addr *a1,
+                                const struct in_addr *a2) {
+    return memcmp((const char *) a1, (const char *) a2,
+                  sizeof(struct in_addr));
+}
+
+void ipv4_addr_copy(struct in_addr *a1,
+                                  const struct in_addr *a2) {
+    memcpy((char *) a1, (const char *) a2, sizeof(struct in_addr));
+}
+
+int ipv6_addr_cmp(const struct in6_addr *a1,
+                  const struct in6_addr *a2) {
+    return memcmp((const char *) a1, (const char *) a2,
+                  sizeof(struct in6_addr));
+}
+
+void ipv6_addr_copy(struct in6_addr *a1,
+               const struct in6_addr *a2) {
+    memcpy((char *) a1, (const char *) a2, sizeof(struct in6_addr));
+}
+
+int ipv6_addr_any(const struct in6_addr *a) {
+    return (a->s6_addr[0] | a->s6_addr[1] | a->s6_addr[2] | a->s6_addr[3] |
+            a->s6_addr[4] |a->s6_addr[5] |a->s6_addr[6] |a->s6_addr[7] |
+            a->s6_addr[8] |a->s6_addr[9] |a->s6_addr[10] |a->s6_addr[11] |
+            a->s6_addr[12] |a->s6_addr[13] |a->s6_addr[14] |a->s6_addr[15]) == 
0;
+}
+
+void hip_copy_in6addr_null_check(struct in6_addr *to,
+                                 struct in6_addr *from) {
+    HIP_ASSERT(to);
+    if (from) {
+        ipv6_addr_copy(to, from);
+    } else {
+        memset(to, 0, sizeof(*to));
+    }
+}
+
+void hip_copy_inaddr_null_check(struct in_addr *to,
+                                struct in_addr *from) {
+    HIP_ASSERT(to);
+    if (from) {
+        memcpy(to, from, sizeof(*to));
+    } else {
+        memset(to, 0, sizeof(*to));
+    }
+}
+
+

=== modified file 'lib/core/prefix.h'
--- lib/core/prefix.h   2010-03-10 13:03:35 +0000
+++ lib/core/prefix.h   2010-03-10 17:44:36 +0000
@@ -4,9 +4,9 @@
 #include <sys/un.h>
 #include <stdlib.h>
 
+#include "debug.h"
 #include "protodefs.h"
 #include "list.h"
-#include "debug.h"
 
 #define HIP_TMP_FNAME_TEMPLATE "/tmp/hip_XXXXXX"
 
@@ -35,6 +35,22 @@
 void hip_addr_to_sockaddr(struct in6_addr *addr, struct sockaddr_storage *sa);
 int hip_sockaddr_is_v6_mapped(struct sockaddr *sa);
 int hip_addr_is_loopback(struct in6_addr *addr);
+int hip_lsi_are_equal(const hip_lsi_t *lsi1,
+                      const hip_lsi_t *lsi2);
+
+int ipv4_addr_cmp(const struct in_addr *a1,
+                  const struct in_addr *a2);
+void ipv4_addr_copy(struct in_addr *a1,
+                    const struct in_addr *a2);
+int ipv6_addr_cmp(const struct in6_addr *a1,
+                  const struct in6_addr *a2);
+void ipv6_addr_copy(struct in6_addr *a1,
+                    const struct in6_addr *a2);
+int ipv6_addr_any(const struct in6_addr *a);
+void hip_copy_in6addr_null_check(struct in6_addr *to,
+                                 struct in6_addr *from);
+void hip_copy_inaddr_null_check(struct in_addr *to,
+                                struct in_addr *from);
 
 /* IN6_IS_ADDR_V4MAPPED(a) is defined in /usr/include/netinet/in.h */
 

=== modified file 'lib/core/protodefs.h'
--- lib/core/protodefs.h        2010-03-07 11:20:52 +0000
+++ lib/core/protodefs.h        2010-03-10 17:44:36 +0000
@@ -20,6 +20,8 @@
 #  define IPPROTO_HIP             139
 #endif
 
+#define IPV4_HDR_SIZE 20
+
 #define HIP_MAX_PACKET 4096
 #define HIP_MAX_NETWORK_PACKET 2048
 /** @addtogroup hip_msg

=== modified file 'lib/core/solve.h'
--- lib/core/solve.h    2010-03-09 18:26:22 +0000
+++ lib/core/solve.h    2010-03-10 17:44:36 +0000
@@ -7,7 +7,7 @@
 #include "lib/core/crypto.h"
 #include "protodefs.h"
 #include "state.h"
-#include "misc.h"
+
 
 #define HIP_PUZZLE_MAX_K        28
 

=== added file 'lib/core/straddr.c'
--- lib/core/straddr.c  1970-01-01 00:00:00 +0000
+++ lib/core/straddr.c  2010-03-10 17:44:36 +0000
@@ -0,0 +1,177 @@
+/**
+ * @file
+ *
+ * Distributed under <a href="http://www.gnu.org/licenses/gpl2.txt";>GNU/GPL</a>
+ *
+ * @brief Conversion functions from string to address and vice versa
+ *
+ * @author Miika Komu <miika@xxxxxx>
+ */
+
+/* required for s6_addr32 */
+#define _BSD_SOURCE
+
+#include <errno.h>
+#include <arpa/inet.h>
+#include <ctype.h>
+#include <openssl/evp.h>
+#include "config.h"
+#include "straddr.h"
+#include "debug.h"
+
+/**
+ * convert a binary IPv6 address to a string
+ *
+ * @param in6 the IPv6 address to convert
+ * @param buf a preallocated buffer where the string will be stored
+ * @return a pointer to the buf
+ */
+char *hip_in6_ntop(const struct in6_addr *in6, char *buf)
+{
+    if (!buf) {
+        return NULL;
+    }
+    sprintf(buf,
+            "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x",
+            ntohs(in6->s6_addr16[0]), ntohs(in6->s6_addr16[1]),
+            ntohs(in6->s6_addr16[2]), ntohs(in6->s6_addr16[3]),
+            ntohs(in6->s6_addr16[4]), ntohs(in6->s6_addr16[5]),
+            ntohs(in6->s6_addr16[6]), ntohs(in6->s6_addr16[7]));
+    return buf;
+}
+
+/**
+ * convert a string into a binary IPv4 address (a wrapper for inet_pton())
+ *
+ * @param str the string to convert
+ * @param ip an output argument that will contain a binary IPv4 calculated
+ *        from the @c str
+ * @return zero on success and negative on error
+ */
+int convert_string_to_address_v4(const char *str, struct in_addr *ip)
+{
+    int ret = 0, err = 0;
+
+    ret = inet_pton(AF_INET, str, ip);
+    HIP_IFEL((ret < 0 && errno == EAFNOSUPPORT), -1,
+             "inet_pton: not a valid address family\n");
+    HIP_IFEL((ret == 0), -1,
+             "inet_pton: %s: not a valid network address\n", str);
+out_err:
+    return err;
+}
+
+/**
+ * Convert a string to an IPv6 address. This function can handle
+ * also IPv6 mapped addresses.
+ *
+ * @param str the string to convert
+ * @param ip6 An output argument that will contain a binary IPv4 calculated
+ *        from the @c str. Possibly in IPv6 mapped format.
+ * @return zero on success or negative on error
+ */
+int convert_string_to_address(const char *str,
+                              struct in6_addr *ip6)
+{
+    int ret = 0, err = 0;
+    struct in_addr ip4;
+
+    ret = inet_pton(AF_INET6, str, ip6);
+    HIP_IFEL((ret < 0 && errno == EAFNOSUPPORT), -1,
+             "\"%s\" is not of valid address family.\n", str);
+    if (ret > 0) {
+        /* IPv6 address conversion was ok */
+        _HIP_DEBUG_IN6ADDR("Converted IPv6", ip6);
+        goto out_err;
+    }
+
+    /* Might be an ipv4 address (ret == 0). Lets catch it here. */
+    err = convert_string_to_address_v4(str, &ip4);
+    if (err) {
+        goto out_err;
+    }
+
+    IPV4_TO_IPV6_MAP(&ip4, ip6);
+    HIP_DEBUG("Mapped v4 to v6.\n");
+    HIP_DEBUG_IN6ADDR("mapped v6", ip6);
+
+out_err:
+    return err;
+}
+
+/**
+ * convert a string containing upper case characters to lower case
+ *
+ * @param to the result of the conversion (minimum length @c count)
+ * @param from a string possibly containing upper case characters
+ * @return zero on success or negative on failure
+ */
+int hip_string_to_lowercase(char *to, const char *from, const size_t count)
+{
+    if (to == NULL || from == NULL || count == 0) {
+        return -1;
+    }
+
+    int i = 0;
+
+    for (; i < count; i++) {
+        if (isalpha(from[i])) {
+            to[i] = tolower(from[i]);
+        } else {
+            to[i] = from[i];
+        }
+    }
+    return 0;
+}
+
+/**
+ * test if a given string contains a positive integer
+ *
+ * @param string the string to test
+ * @return zero if the string is digit or negative otherwise
+ */
+int hip_string_is_digit(const char *string)
+{
+    if (string == NULL) {
+        return -1;
+    }
+
+    int i = 0;
+
+    while (string[i] != '\0') {
+        if (!isdigit(string[i])) {
+            return -1;
+        }
+        i++;
+    }
+    return 0;
+}
+
+
+/**
+ * encode the given content to Base64
+ *
+ * @param buf Pointer to contents to be encoded
+ * @param len How long is the first parameter in bytes
+ *
+ * @return Returns a pointer to encoded content or NULL on error
+ */
+unsigned char *base64_encode(unsigned char *buf, unsigned int len)
+{
+    unsigned char *ret;
+    unsigned int b64_len;
+
+    b64_len = (((len + 2) / 3) * 4) + 1;
+    ret     = (unsigned char *) malloc(b64_len);
+    if (ret == NULL) {
+        goto out_err;
+    }
+    EVP_EncodeBlock(ret, buf, len);
+    return ret;
+out_err:
+    if (ret) {
+        free(ret);
+    }
+    return NULL;
+}
+

=== added file 'lib/core/straddr.h'
--- lib/core/straddr.h  1970-01-01 00:00:00 +0000
+++ lib/core/straddr.h  2010-03-10 17:44:36 +0000
@@ -0,0 +1,14 @@
+#ifndef HIP_LIB_CORE_STRADDR_H
+#define HIP_LIB_CORE_STRADDR_H
+
+#include <sys/types.h>
+#include <netinet/in.h>
+
+int convert_string_to_address_v4(const char *str, struct in_addr *ip);
+int convert_string_to_address(const char *str, struct in6_addr *ip6);
+char *hip_in6_ntop(const struct in6_addr *in6, char *buf);
+int hip_string_to_lowercase(char *to, const char *from, const size_t count);
+int hip_string_is_digit(const char *string);
+unsigned char *base64_encode(unsigned char *, unsigned int);
+
+#endif /* HIP_LIB_CORE_STRADDR_H */

=== modified file 'lib/dht/libhipdht.c'
--- lib/dht/libhipdht.c 2010-03-03 13:16:18 +0000
+++ lib/dht/libhipdht.c 2010-03-10 17:44:36 +0000
@@ -18,6 +18,8 @@
 #include <stdlib.h>
 #include <string.h>
 #include <netdb.h>
+#include <unistd.h>
+#include <ctype.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <arpa/inet.h>
@@ -31,7 +33,10 @@
 #include "lib/core/debug.h"
 #include "lib/core/ife.h"
 #include "lib/core/icomm.h"
-#include "lib/core/misc.h"
+#include "lib/core/builder.h"
+#include "lib/core/straddr.h"
+#include "lib/core/message.h"
+
 #include "libhipdht.h"
 #include "libhipdhtxml.h"
 

=== modified file 'lib/dht/libhipdht.h'
--- lib/dht/libhipdht.h 2010-03-09 18:26:22 +0000
+++ lib/dht/libhipdht.h 2010-03-10 17:44:36 +0000
@@ -1,6 +1,10 @@
 #ifndef HIP_LIB_DHT_LIBHIPDHT_H
 #define HIP_LIB_DHT_LIBHIPDHT_H
 
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netdb.h>
+
 #include "config.h"
 #include "lib/core/protodefs.h"
 

=== modified file 'lib/dht/libhipdhtxml.c'
--- lib/dht/libhipdhtxml.c      2010-02-17 17:38:08 +0000
+++ lib/dht/libhipdhtxml.c      2010-03-10 17:44:36 +0000
@@ -8,6 +8,7 @@
 #include <libxml2/libxml/tree.h>
 #include "libhipdhtxml.h"
 #include "lib/core/debug.h"
+#include "lib/core/straddr.h"
 #include "hipd/netdev.h"
 
 xmlNodePtr xml_new_param(xmlNodePtr node_parent, char *type, char *value);

=== modified file 'lib/opphip/wrap.c'
--- lib/opphip/wrap.c   2010-03-09 18:26:22 +0000
+++ lib/opphip/wrap.c   2010-03-10 17:44:36 +0000
@@ -25,6 +25,7 @@
 
 #include "config.h"
 #include "lib/core/debug.h"
+#include "lib/core/message.h"
 #include "hipd/hadb.h"
 #include "lib/core/hashtable.h"
 #include "lib/tool/lutil.h"

=== modified file 'lib/tool/lutil.c'
--- lib/tool/lutil.c    2010-03-08 21:21:01 +0000
+++ lib/tool/lutil.c    2010-03-10 17:44:36 +0000
@@ -264,3 +264,27 @@
 
     return _t1.tv_sec >= _t2.tv_sec;
 }
+
+/**
+ * find the maximum value from a variable list of integers
+ *
+ * @param num_args number of list items
+ * @param ... the integers from which to find maximum
+ * @return the integer with the largest value from the
+ *         list provided
+ */
+int maxof(int num_args, ...)
+{
+    int max, i, a;
+    va_list ap;
+
+    va_start(ap, num_args);
+    max = va_arg(ap, int);
+    for (i = 2; i <= num_args; i++) {
+        if ((a = va_arg(ap, int)) > max) {
+            max = a;
+        }
+    }
+    va_end(ap);
+    return max;
+}

=== modified file 'lib/tool/lutil.h'
--- lib/tool/lutil.h    2010-03-09 18:26:22 +0000
+++ lib/tool/lutil.h    2010-03-10 17:44:36 +0000
@@ -77,4 +77,6 @@
  */
 void extractsubstrings(char *string, List *list);
 
+int maxof(int num_args, ...);
+
 #endif /* HIP_LIB_TOOL_LUTIL_H */

=== modified file 'lib/tool/nlink.c'
--- lib/tool/nlink.c    2010-03-10 17:20:51 +0000
+++ lib/tool/nlink.c    2010-03-10 17:44:36 +0000
@@ -32,8 +32,10 @@
 
 #include <net/if.h>
 #include <sys/ioctl.h>
+#include <unistd.h>
 
 #include "config.h"
+#include "lib/core/hip_udp.h"
 #include "nlink.h"
 
 /* New one to prevent netlink overrun */

=== modified file 'lib/tool/nlink.h'
--- lib/tool/nlink.h    2010-03-05 08:47:53 +0000
+++ lib/tool/nlink.h    2010-03-10 17:44:36 +0000
@@ -18,6 +18,9 @@
 #include "lib/core/builder.h"
 #include "lib/core/debug.h"
 
+#define HIP_OPTION_KIND 30
+#define HIP_NETLINK_TALK_ACK 0 /* see netlink_talk */
+
 
 struct pseudo_hdr {
     uint32_t s_addr;
@@ -35,8 +38,6 @@
     uint16_t             length;
 };
 
-#define HIP_OPTION_KIND 30
-
 struct netdev_address {
     //hip_list_t next;
     struct sockaddr_storage addr;

=== modified file 'lib/tool/xfrmapi.h'
--- lib/tool/xfrmapi.h  2010-03-05 08:47:53 +0000
+++ lib/tool/xfrmapi.h  2010-03-10 17:44:36 +0000
@@ -15,7 +15,7 @@
 #include "lib/core/hashtable.h"
 #include "hipd/hadb.h"
 #include "hipd/user.h"
-#include "lib/core/misc.h"
+
 #include "lib/core/state.h"
 #include "nlink.h"
 

=== modified file 'test/certteststub.c'
--- test/certteststub.c 2010-02-17 17:38:08 +0000
+++ test/certteststub.c 2010-03-10 17:44:36 +0000
@@ -13,6 +13,7 @@
 /* required for s6_addr32 */
 #define _BSD_SOURCE
 
+#include <arpa/inet.h>
 #include <sys/time.h>
 #include <time.h>
 #include <zlib.h>

=== modified file 'test/conntest.c'
--- test/conntest.c     2010-03-04 13:42:51 +0000
+++ test/conntest.c     2010-03-10 17:44:36 +0000
@@ -2,6 +2,8 @@
 #define _BSD_SOURCE
 
 #include "conntest.h"
+#include "lib/tool/nlink.h"
+#include "lib/tool/lutil.h"
 
 /**
  * create_serversocket - given the port and the protocol

=== modified file 'test/conntest.h'
--- test/conntest.h     2010-02-17 17:38:08 +0000
+++ test/conntest.h     2010-03-10 17:44:36 +0000
@@ -16,7 +16,7 @@
 #include <sys/uio.h>
 #include "lib/core/debug.h"
 #include "lib/core/ife.h"
-#include "lib/core/misc.h"
+
 
 int create_socket(int proto);
 int create_serversocket(int type, in_port_t port);

=== modified file 'test/cookietest.c'
--- test/cookietest.c   2010-03-09 08:57:46 +0000
+++ test/cookietest.c   2010-03-10 17:44:36 +0000
@@ -2,7 +2,7 @@
 #define _BSD_SOURCE
 
 #include "lib/core/debug.h"
-#include "lib/core/misc.h"
+
 #include "lib/core/solve.h"
 #include <sys/time.h>
 #include <time.h>

=== modified file 'test/dhtteststub.c'
--- test/dhtteststub.c  2010-02-17 17:38:08 +0000
+++ test/dhtteststub.c  2010-03-10 17:44:36 +0000
@@ -23,9 +23,10 @@
 #include <netinet/ip.h>
 #include <errno.h>
 #include <time.h>
+#include <sys/time.h>
 #include "lib/dht/libhipdht.h"
 #include "lib/core/debug.h"
-#include "lib/core/misc.h"
+#include "lib/core/straddr.h"
 
 int main(int argc, char *argv[])
 {

=== modified file 'test/keygentest.c'
--- test/keygentest.c   2010-02-17 17:38:08 +0000
+++ test/keygentest.c   2010-03-10 17:44:36 +0000
@@ -13,7 +13,8 @@
 #include <time.h>
 
 #include "lib/core/debug.h"
-#include "lib/core/misc.h"
+#include "lib/core/crypto.h"
+#include "lib/tool/lutil.h"
 
 int main(int argc, char *argv[])
 {

=== modified file 'tools/pisacert.c'
--- tools/pisacert.c    2010-02-17 17:38:08 +0000
+++ tools/pisacert.c    2010-03-10 17:44:36 +0000
@@ -14,6 +14,8 @@
 #include "lib/core/icomm.h"
 #include "lib/core/debug.h"
 #include "lib/core/certtools.h"
+#include "lib/core/builder.h"
+#include "lib/core/message.h"
 
 /**
  * Get the default hit of the local HIPD.

Other related posts:

  • » [hipl-commit] [trunk] Rev 3916: Splitting misc.c (bug id 1139) finished, I hope. - Miika Komu