[hipl-dev] [Merge] lp:~hipl-core/hipl/mobility-fixes into lp:hipl

  • From: René Hummen <rene.hummen@xxxxxxxxxxxxxxxxx>
  • To: mp+41490@xxxxxxxxxxxxxxxxxx
  • Date: Mon, 22 Nov 2010 17:21:54 -0000

René Hummen has proposed merging lp:~hipl-core/hipl/mobility-fixes into lp:hipl.

Requested reviews:
  HIPL core team (hipl-core)


This branch aims at further encapsulating mobility functionality in the update 
module. To this end, dead code was removed or has been moved where possible.
-- 
https://code.launchpad.net/~hipl-core/hipl/mobility-fixes/+merge/41490
Your team HIPL core team is requested to review the proposed merge of 
lp:~hipl-core/hipl/mobility-fixes into lp:hipl.
=== modified file 'firewall/conntrack.c'
--- firewall/conntrack.c        2010-10-27 11:27:48 +0000
+++ firewall/conntrack.c        2010-11-22 17:21:23 +0000
@@ -59,6 +59,7 @@
 #include "lib/core/prefix.h"
 #include "lib/core/protodefs.h"
 #include "lib/tool/pk.h"
+#include "modules/update/hipd/update.h"
 #include "common_types.h"
 #include "dlist.h"
 #include "esp_prot_conntrack.h"

=== modified file 'hipd/esp_prot_hipd_msg.c'
--- hipd/esp_prot_hipd_msg.c    2010-10-15 15:29:14 +0000
+++ hipd/esp_prot_hipd_msg.c    2010-11-22 17:21:23 +0000
@@ -45,6 +45,7 @@
 #include "lib/core/ife.h"
 #include "lib/core/protodefs.h"
 #include "lib/tool/xfrmapi.h"
+#include "modules/update/hipd/update_builder.h"
 #include "cookie.h"
 #include "esp_prot_anchordb.h"
 #include "esp_prot_light_update.h"

=== modified file 'hipd/esp_prot_light_update.c'
--- hipd/esp_prot_light_update.c        2010-10-15 15:29:14 +0000
+++ hipd/esp_prot_light_update.c        2010-11-22 17:21:23 +0000
@@ -43,6 +43,7 @@
 #include "lib/core/ife.h"
 #include "lib/core/protodefs.h"
 #include "lib/tool/xfrmapi.h"
+#include "modules/update/hipd/update_builder.h"
 #include "esp_prot_anchordb.h"
 #include "esp_prot_hipd_msg.h"
 #include "hipd.h"

=== modified file 'hipd/hadb.h'
--- hipd/hadb.h 2010-10-15 15:29:14 +0000
+++ hipd/hadb.h 2010-11-22 17:21:23 +0000
@@ -42,8 +42,6 @@
 /* For switch userspace / kernel IPsec */
 extern int hip_use_userspace_ipsec;
 
-extern hip_xmit_func_set_t nat_xmit_func_set;
-
 extern HIP_HASHTABLE *hadb_hit;
 
 void hip_hadb_hold_entry(void *entry);

=== modified file 'hipd/hadb_legacy.h'
--- hipd/hadb_legacy.h  2010-10-15 15:29:14 +0000
+++ hipd/hadb_legacy.h  2010-11-22 17:21:23 +0000
@@ -37,18 +37,6 @@
                                     const struct in6_addr *addr,
                                     uint32_t *lifetime,
                                     struct timeval *modified_time);
-void hip_update_handle_ack_old(hip_ha_t *entry,
-                               struct hip_ack *ack,
-                               int have_esp_info);
-//add by santtu
-int hip_hadb_add_udp_addr_old(hip_ha_t *entry,
-                              struct in6_addr *addr,
-                              int is_bex_address,
-                              uint32_t lifetime,
-                              int is_preferred_addr,
-                              uint16_t port,
-                              uint32_t priority,
-                              uint8_t kind);
 
 void hip_hadb_delete_peer_addrlist_one_old(hip_ha_t *ha, struct in6_addr 
*addr);
 

=== modified file 'hipd/hipd.c'
--- hipd/hipd.c 2010-10-15 15:29:14 +0000
+++ hipd/hipd.c 2010-11-22 17:21:23 +0000
@@ -159,7 +159,6 @@
 
 int hip_shotgun_status                       = HIP_MSG_SHOTGUN_OFF;
 
-int hip_trigger_update_on_heart_beat_failure = 1;
 int hip_wait_addr_changes_to_stabilize       = 1;
 
 /**

=== modified file 'hipd/hipd.h'
--- hipd/hipd.h 2010-10-15 15:29:14 +0000
+++ hipd/hipd.h 2010-11-22 17:21:23 +0000
@@ -112,8 +112,6 @@
 extern int esp_prot_num_transforms;
 extern long esp_prot_num_parallel_hchains;
 
-extern int hip_trigger_update_on_heart_beat_failure;
-
 extern int hip_locator_status;
 extern int hip_transform_order;
 

=== modified file 'hipd/init.c'
--- hipd/init.c 2010-10-15 15:29:14 +0000
+++ hipd/init.c 2010-11-22 17:21:23 +0000
@@ -708,6 +708,7 @@
     lmod_register_packet_type(HIP_CLOSE_ACK, "HIP_CLOSE_ACK");
     lmod_register_packet_type(HIP_PSIG,      "HIP_PSIG");
     lmod_register_packet_type(HIP_TRIG,      "HIP_TRIG");
+    lmod_register_packet_type(HIP_UPDATE,    "HIP_UPDATE");
     lmod_register_packet_type(HIP_LUPDATE,   "HIP_LUPDATE");
     lmod_register_packet_type(HIP_DATA,      "HIP_DATA");
     lmod_register_packet_type(HIP_PAYLOAD,   "HIP_PAYLOAD");

=== modified file 'hipd/input.c'
--- hipd/input.c        2010-10-22 10:41:25 +0000
+++ hipd/input.c        2010-11-22 17:21:23 +0000
@@ -69,6 +69,7 @@
 #include "lib/core/state.h"
 #include "lib/core/transform.h"
 #include "lib/tool/xfrmapi.h"
+#include "modules/update/hipd/update.h"
 #include "config.h"
 #include "cookie.h"
 #include "dh.h"

=== modified file 'lib/core/builder.c'
--- lib/core/builder.c  2010-11-15 12:40:48 +0000
+++ lib/core/builder.c  2010-11-22 17:21:23 +0000
@@ -393,7 +393,7 @@
  * @param tlv_generic pointer to the parameter
  * @param type type of the parameter (in host byte order)
  */
-static void hip_set_param_type(struct hip_tlv_common *tlv_generic, 
hip_tlv_type_t type)
+void hip_set_param_type(struct hip_tlv_common *tlv_generic, hip_tlv_type_t 
type)
 {
     tlv_generic->type = htons(type);
 }
@@ -468,17 +468,6 @@
 }
 
 /**
- * Retrieve a pointer to the first locator in a LOCATOR parameter
- *
- * @param locator a pointer a LOCATOR parameter
- * @return a pointer to the first locator in the LOCATOR parameter
- */
-struct hip_locator_info_addr_item *hip_get_locator_first_addr_item(struct 
hip_locator *locator)
-{
-    return (struct hip_locator_info_addr_item *) (locator + 1);
-}
-
-/**
  * Translate a service life time from seconds to a 8-bit integer value. The
  * lifetime value in seconds is translated to a 8-bit integer value using
  * following formula: <code>lifetime = (8 * (log(seconds) / log(2)))
@@ -1069,9 +1058,9 @@
  * @param contents_size size of the contents after the TLV header
  *                 (in host byte order)
  */
-static void hip_calc_generic_param_len(struct hip_tlv_common *tlv_common,
-                                       hip_tlv_len_t tlv_size,
-                                       hip_tlv_len_t contents_size)
+void hip_calc_generic_param_len(struct hip_tlv_common *tlv_common,
+                                hip_tlv_len_t tlv_size,
+                                hip_tlv_len_t contents_size)
 {
     hip_set_param_contents_len(tlv_common,
                                tlv_size + contents_size -
@@ -1089,8 +1078,8 @@
  * @param contents_size size of the contents after type and length fields
  *                 (in host byte order)
  */
-static void hip_calc_param_len(struct hip_tlv_common *tlv_common,
-                               hip_tlv_len_t contents_size)
+void hip_calc_param_len(struct hip_tlv_common *tlv_common,
+                        hip_tlv_len_t contents_size)
 {
     hip_calc_generic_param_len(tlv_common,
                                sizeof(struct hip_tlv_common),
@@ -2829,84 +2818,6 @@
 }
 
 /**
- * build a HIP locator parameter
- *
- * @param msg           the message where the REA will be appended
- * @param addrs         list of addresses
- * @param addr_count number of addresses
- * @return 0 on success, otherwise < 0.
- */
-int hip_build_param_locator(struct hip_common *msg,
-                            struct hip_locator_info_addr_item *addrs,
-                            int addr_count)
-{
-    int err                          = 0;
-    struct hip_locator *locator_info = NULL;
-    int addrs_len = addr_count * (sizeof(struct hip_locator_info_addr_item));
-
-    HIP_IFE(!(locator_info = malloc(sizeof(struct hip_locator) + addrs_len)), 
-1);
-
-    hip_set_param_type((struct hip_tlv_common *) locator_info, 
HIP_PARAM_LOCATOR);
-
-    hip_calc_generic_param_len((struct hip_tlv_common *) locator_info,
-                               sizeof(struct hip_locator),
-                               addrs_len);
-
-    memcpy(locator_info + 1, addrs, addrs_len);
-    HIP_IFE(hip_build_param(msg, locator_info), -1);
-
-out_err:
-    if (locator_info) {
-        free(locator_info);
-    }
-    return err;
-}
-
-
-
-/**
- * build and append a HIP SEQ parameter to a message
- *
- * @param msg the message where the parameter will be appended
- * @param update_id Update ID
- * @return 0 on success, otherwise < 0.
- */
-int hip_build_param_seq(struct hip_common *msg, uint32_t update_id)
-{
-    int err = 0;
-    struct hip_seq seq;
-
-    hip_set_param_type((struct hip_tlv_common *) &seq, HIP_PARAM_SEQ);
-    hip_calc_generic_param_len((struct hip_tlv_common *) &seq,
-                               sizeof(struct hip_seq),
-                               0);
-    seq.update_id = htonl(update_id);
-    err = hip_build_param(msg, &seq);
-    return err;
-}
-
-/**
- * build and append a HIP ACK parameter to a message
- *
- * @param msg the message where the parameter will be appended
- * @param peer_update_id peer Update ID
- * @return 0 on success, otherwise < 0.
- */
-int hip_build_param_ack(struct hip_common *msg, uint32_t peer_update_id)
-{
-    int err = 0;
-    struct hip_ack ack;
-
-    hip_set_param_type((struct hip_tlv_common *) &ack, HIP_PARAM_ACK);
-    hip_calc_generic_param_len((struct hip_tlv_common *) &ack,
-                               sizeof(struct hip_ack),
-                               0);
-    ack.peer_update_id = htonl(peer_update_id);
-    err = hip_build_param(msg, &ack);
-    return err;
-}
-
-/**
  * build and append a ESP PROT transform parameter
  *
  * @param msg the message where the parameter will be appended
@@ -3954,88 +3865,6 @@
 }
 
 /**
- * Retrieve the amount the locators inside a LOCATOR parameter.
- * Type 1 and 2 parameters are supported.
- *
- * @param locator a LOCATOR parameter
- * @return the amount of locators
- */
-int hip_get_locator_addr_item_count(const struct hip_locator *locator)
-{
-    const char *address_pointer = (const char *) (locator + 1);
-    int amount                  = 0;
-    uint8_t type;
-
-    while (address_pointer <
-          ((const char *) locator) + hip_get_param_contents_len(locator)) {
-        type = ((const struct hip_locator_info_addr_item *)
-               address_pointer)->locator_type;
-
-        if (type == HIP_LOCATOR_LOCATOR_TYPE_UDP) {
-            address_pointer += sizeof(struct hip_locator_info_addr_item2);
-            amount += 1;
-        } else if (type == HIP_LOCATOR_LOCATOR_TYPE_ESP_SPI) {
-            address_pointer += sizeof(struct hip_locator_info_addr_item);
-            amount += 1;
-        } else if (type == HIP_LOCATOR_LOCATOR_TYPE_IPV6) {
-            address_pointer += sizeof(struct hip_locator_info_addr_item);
-            amount += 1;
-        } else {
-            address_pointer += sizeof(struct hip_locator_info_addr_item);
-        }
-    }
-    return amount;
-}
-
-/**
- * Retreive a @c LOCATOR ADDRESS ITEM@c from a list.
- *
- * @param item_list a pointer to the first item in the list
- * @param idx       the index of the item in the list
- * @return          the locator addres item
- */
-union hip_locator_info_addr *hip_get_locator_item(void *item_list, int idx)
-{
-    int i = 0;
-    struct hip_locator_info_addr_item *temp;
-    char *result;
-    result = (char *) item_list;
-
-
-    for (i = 0; i <= idx - 1; i++) {
-        temp = (struct hip_locator_info_addr_item *) result;
-        if (temp->locator_type == HIP_LOCATOR_LOCATOR_TYPE_ESP_SPI ||
-            temp->locator_type == HIP_LOCATOR_LOCATOR_TYPE_IPV6) {
-            result += sizeof(struct hip_locator_info_addr_item);
-        } else {
-            result += sizeof(struct hip_locator_info_addr_item2);
-        }
-    }
-    return (union hip_locator_info_addr *) result;
-}
-
-/**
- * retrieve a IP address from a locator item structure
- *
- * @param item      a pointer to the item
- * @return a pointer to the IP address
- */
-struct in6_addr *hip_get_locator_item_address(void *item)
-{
-    struct hip_locator_info_addr_item *temp;
-
-
-    temp = (struct hip_locator_info_addr_item *) item;
-    if (temp->locator_type == HIP_LOCATOR_LOCATOR_TYPE_ESP_SPI) {
-        return &temp->address;
-    } else if (temp->locator_type == HIP_LOCATOR_LOCATOR_TYPE_IPV6) {
-        return &temp->address;
-    } else {
-        return &((struct hip_locator_info_addr_item2 *) temp)->address;
-    }
-}
-
-/**
  * Build a @c RELAY_TO parameter to the HIP packet @c msg.
  *
  * @param msg  a pointer to a HIP packet common header

=== modified file 'lib/core/builder.h'
--- lib/core/builder.h  2010-10-15 15:29:14 +0000
+++ lib/core/builder.h  2010-11-22 17:21:23 +0000
@@ -68,7 +68,6 @@
                            const struct in6_addr *,
                            const struct in6_addr *);
 int hip_host_id_hits(hip_ha_t *entry, struct hip_common *msg);
-int hip_build_param_ack(struct hip_common *, uint32_t);
 int hip_build_param_contents(struct hip_common *,
                              const void *,
                              hip_tlv_type_t,
@@ -115,9 +114,6 @@
                              uint32_t,
                              uint16_t,
                              struct hip_crypto_key *);
-int hip_build_param_locator(struct hip_common *,
-                            struct hip_locator_info_addr_item *,
-                            int);
 int hip_build_param_cert(struct hip_common *,
                          uint8_t,
                          uint8_t,
@@ -139,7 +135,6 @@
 
 int hip_build_param_r1_counter(struct hip_common *, uint64_t);
 
-int hip_build_param_seq(struct hip_common *, uint32_t);
 int hip_build_param_signature2_contents(struct hip_common *,
                                         const void *,
                                         hip_tlv_len_t,
@@ -190,13 +185,9 @@
 struct hip_dh_public_value
         *hip_dh_select_key(struct hip_diffie_hellman *);
 uint8_t hip_get_host_id_algo(const struct hip_host_id *);
-int hip_get_locator_addr_item_count(const struct hip_locator *);
-union hip_locator_info_addr *hip_get_locator_item(void *item_list, int index);
 int hip_get_lifetime_value(time_t seconds, uint8_t *lifetime);
 int hip_get_lifetime_seconds(uint8_t lifetime, time_t *seconds);
 int hip_check_network_msg_len(const struct hip_common *msg);
-struct hip_locator_info_addr_item
-        *hip_get_locator_first_addr_item(struct hip_locator *);
 hip_hdr_err_t hip_get_msg_err(const struct hip_common *);
 uint16_t hip_get_msg_total_len(const struct hip_common *);
 hip_hdr_type_t hip_get_msg_type(const struct hip_common *);
@@ -216,6 +207,12 @@
 hip_tlv_len_t hip_get_param_total_len(const void *);
 hip_transform_suite_t hip_get_param_transform_suite_id(const void *);
 hip_tlv_type_t hip_get_param_type(const void *);
+void hip_set_param_type(struct hip_tlv_common *tlv_generic, hip_tlv_type_t 
type);
+void hip_calc_generic_param_len(struct hip_tlv_common *tlv_common,
+                                hip_tlv_len_t tlv_size,
+                                hip_tlv_len_t contents_size);
+void hip_calc_param_len(struct hip_tlv_common *tlv_common,
+                        hip_tlv_len_t contents_size);
 uint16_t hip_get_msg_checksum(struct hip_common *msg);
 const char *hip_message_type_name(const uint8_t);
 struct hip_common *hip_msg_alloc(void);
@@ -284,7 +281,6 @@
 int hip_build_param_nat_port(hip_common_t *msg,
                              const in_port_t port,
                              hip_tlv_type_t hipparam);
-struct in6_addr *hip_get_locator_item_address(void *item);
 int hip_build_digest(const int type, const void *in, int in_len, void *out);
 
 int hip_build_param_hmac(struct hip_common *msg,

=== modified file 'lib/core/debug.c'
--- lib/core/debug.c    2010-10-18 17:44:31 +0000
+++ lib/core/debug.c    2010-11-22 17:21:23 +0000
@@ -83,6 +83,7 @@
 #include "lib/core/list.h"
 #include "lib/core/prefix.h"
 #include "lib/tool/lutil.h"
+#include "modules/update/hipd/update.h"
 #include "builder.h"
 #include "ife.h"
 #include "state.h"
@@ -813,54 +814,3 @@
         HIP_DEBUG_HIT("Peer address", &addr->address);
     }
 }
-
-/**
- * Print a locator.
- * @param file
- * @param debug_level
- * @param line
- * @param function
- * @param str string to be printed before the HIT
- * @param locator the locator to be printed
- */
-void hip_print_locator(UNUSED int debug_level, UNUSED const char *file,
-                       UNUSED int line, UNUSED const char *function,
-                       DBG const char *str, struct hip_locator *locator)
-{
-/* XXTRASHXX Totally useless does anything but what it is supposed to do -SAMU 
*/
-
-    int n_addrs                                               = 0, i = 0;
-    struct hip_locator_info_addr_item *first_address_item     = NULL,
-    *locator_address_item                                     = NULL;
-    struct hip_locator_info_addr_item2 *locator_address_item2 = NULL;
-    /* locator = hip_get_param((struct hip_common *)in_msg,
-     * HIP_PARAM_LOCATOR);*/
-    if (locator) {
-        HIP_DEBUG("%s: \n", str);
-
-        n_addrs            = hip_get_locator_addr_item_count(locator);
-        HIP_DEBUG("there are  %d locator items \n", n_addrs);
-        first_address_item = hip_get_locator_first_addr_item(locator);
-
-        for (i = 0; i < n_addrs; i++) {
-            locator_address_item = (struct hip_locator_info_addr_item *)
-                                   hip_get_locator_item(first_address_item, i);
-            HIP_DEBUG("locator items index %d, type is %d \n", i,
-                      locator_address_item->locator_type );
-            if (locator_address_item->locator_type == 
HIP_LOCATOR_LOCATOR_TYPE_IPV6) {
-                HIP_INFO_HIT("locator",
-                             (struct in6_addr *) 
&locator_address_item->address);
-            }
-            if (locator_address_item->locator_type == 
HIP_LOCATOR_LOCATOR_TYPE_ESP_SPI) {
-                HIP_INFO_HIT("LOCATOR from ESP SPI(type 1)",
-                             (struct in6_addr *) 
&locator_address_item->address);
-            }
-            if (locator_address_item->locator_type == 
HIP_LOCATOR_LOCATOR_TYPE_UDP) {
-                locator_address_item2 = (struct hip_locator_info_addr_item2 *) 
locator_address_item;
-                HIP_INFO_HIT("LOCATOR from UDP",
-                             (struct in6_addr *) 
&locator_address_item2->address);
-                HIP_DEBUG("LOCATOR port for UDP: %d\n",  
ntohs(locator_address_item2->port));
-            }
-        }
-    }
-}

=== modified file 'lib/core/debug.h'
--- lib/core/debug.h    2010-11-12 15:50:17 +0000
+++ lib/core/debug.h    2010-11-22 17:21:23 +0000
@@ -406,12 +406,6 @@
 void hip_print_locator_addresses(const struct hip_common *);
 void hip_print_peer_addresses_to_be_added(hip_ha_t *);
 void hip_print_peer_addresses(hip_ha_t *);
-void hip_print_locator(int debug_level,
-                       const char *file,
-                       int line,
-                       const char *function,
-                       const char *str,
-                       struct hip_locator *locator);
 
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
 

=== modified file 'lib/core/protodefs.h'
--- lib/core/protodefs.h        2010-10-20 03:38:26 +0000
+++ lib/core/protodefs.h        2010-11-22 17:21:23 +0000
@@ -576,12 +576,6 @@
 typedef struct in6_addr hip_hit_t;
 typedef struct in_addr hip_lsi_t;
 typedef struct hip_hadb_state hip_ha_t;
-typedef struct hip_hadb_rcv_func_set hip_rcv_func_set_t;
-typedef struct hip_hadb_handle_func_set hip_handle_func_set_t;
-typedef struct hip_hadb_update_func_set hip_update_func_set_t;
-typedef struct hip_hadb_misc_func_set hip_misc_func_set_t;
-typedef struct hip_hadb_xmit_func_set hip_xmit_func_set_t;
-typedef struct hip_ipsec_func_set hip_ipsec_func_set_t;
 typedef struct hip_common hip_common_t;
 
 struct hip_crypto_key {
@@ -688,46 +682,6 @@
     uint16_t       caseid;
 } __attribute__ ((packed));
 
-/**
- * Fixed start of this struct must match to struct hip_peer_addr_list_item
- * for the part of address item. It is used in hip_update_locator_match().
- * @todo Maybe fix this in some better way?
- */
-struct hip_locator_info_addr_item {
-    uint8_t         traffic_type;
-    uint8_t         locator_type;
-    uint8_t         locator_length;
-    uint8_t         reserved; /**< last bit is P (prefered) */
-    uint32_t        lifetime;
-    struct in6_addr address;
-}  __attribute__ ((packed));
-//add by santtu
-/**
- * it is the type 2 locater for UDP or other transport protocol later.
- */
-struct hip_locator_info_addr_item2 {
-    uint8_t         traffic_type;
-    uint8_t         locator_type;
-    uint8_t         locator_length;
-    uint8_t         reserved; /* last bit is P (prefered) */
-    uint32_t        lifetime;
-    uint16_t        port;
-    uint8_t         transport_protocol;
-    uint8_t         kind;
-    uint32_t        priority;
-    uint32_t        spi;
-    struct in6_addr address;
-}  __attribute__ ((packed));
-
-
-/**
- * it is a union of both type1 and type2 locator.
- */
-union hip_locator_info_addr {
-    struct hip_locator_info_addr_item  type1;
-    struct hip_locator_info_addr_item2 type2;
-} __attribute__ ((packed));
-//end add
 /** Structure describing an endpoint. This structure is used by the resolver in
  * the userspace, so it is not length-padded like HIP parameters. All of the
  * members are in network byte order.
@@ -938,12 +892,6 @@
     uint8_t        data[0]; /**< A pointer to the notification data */
 } __attribute__ ((packed));
 
-struct hip_locator {
-    hip_tlv_type_t type;
-    hip_tlv_len_t  length;
-    /* fixed part ends */
-} __attribute__ ((packed));
-
 struct hip_hmac {
     hip_tlv_type_t type;
     hip_tlv_len_t  length;

=== modified file 'lib/core/state.h'
--- lib/core/state.h    2010-11-12 16:42:54 +0000
+++ lib/core/state.h    2010-11-22 17:21:23 +0000
@@ -80,26 +80,10 @@
 /* #define PEER_ADDR_STATE_UNVERIFIED       1 */
 #define PEER_ADDR_STATE_ACTIVE           2
 
-#define HIP_LOCATOR_TRAFFIC_TYPE_DUAL    0
-#define HIP_LOCATOR_TRAFFIC_TYPE_SIGNAL  1
-
-#define HIP_LOCATOR_LOCATOR_TYPE_IPV6    0
-#define HIP_LOCATOR_LOCATOR_TYPE_ESP_SPI 1
-//NAT branch
-#define HIP_LOCATOR_LOCATOR_TYPE_UDP 2
-
-/* #define HIP_LOCATOR_LOCATOR_TYPE_ESP_SPI_PRIORITY 126 */
-/* #define HIP_LOCATOR_LOCATOR_TYPE_REFLEXIVE_PRIORITY 120 */
 /** for the triple nat mode*/
 #define HIP_NAT_MODE_NONE               0
 #define HIP_NAT_MODE_PLAIN_UDP          1
 
-#define HIP_UPDATE_LOCATOR              0
-#define HIP_UPDATE_ECHO_REQUEST         1
-#define HIP_UPDATE_ECHO_RESPONSE        2
-#define HIP_UPDATE_ESP_ANCHOR          3
-#define HIP_UPDATE_ESP_ANCHOR_ACK      4
-
 #define HIP_SPI_DIRECTION_OUT           1
 #define HIP_SPI_DIRECTION_IN            2
 
@@ -142,8 +126,6 @@
     uint32_t        lifetime;
     struct timeval  modified_time;      /* time when this address was
                                          * added or updated */
-    uint32_t        seq_update_id;      /* the Update ID in SEQ parameter
-                                         * this address is related to */
     uint8_t         echo_data[4];       /* data put into the ECHO_REQUEST 
parameter */
 //NAT branch
     uint8_t         transport_protocol;             /*value 1 for UDP*/
@@ -162,34 +144,17 @@
     /* ifindex if the netdev to which this is related to */
     int           ifindex;
     unsigned long timestamp;        /* when SA was created */
-    int           updating;        /* UPDATE is in progress */
     uint32_t      esp_info_spi_out;        /* UPDATE, the stored outbound
                                             * SPI related to the inbound
                                             * SPI we sent in reply (useless?)*/
     uint16_t      keymat_index;        /* advertised keymat index */
-    int           update_state_flags;        /* 0x1=received ack for
-                                              * sent SEQ, 0x2=received
-                                              * peer's ESP_INFO,
-                                              * both=0x3=can move back
-                                              * to established */
     /* the Update ID in SEQ parameter these SPI are related to */
-    uint32_t                           seq_update_id;
-    /* the corresponding esp_info of peer */
     struct hip_esp_info                stored_received_esp_info;
-    /* our addresses this SPI is related to, reuse struct to ease coding */
-    struct hip_locator_info_addr_item *addresses;
-    int                                addresses_n; /* number of addresses */
 };
 
 struct hip_spi_out_item {
     uint32_t        spi;
     uint32_t        new_spi;        /* spi is changed to this when rekeying */
-
-    /* USELESS, IF SEQ ID WILL BE RELATED TO ADDRESS ITEMS,
-     * NOT OUTBOUND SPIS */
-    /* the Update ID in SEQ parameter these SPI are related to */
-    uint32_t        seq_update_id;
-
     HIP_HASHTABLE * peer_addr_list;    /* Peer's IPv6 addresses */
     struct in6_addr preferred_address;
 };

=== modified file 'modules/update/Makefile.am'
--- modules/update/Makefile.am  2010-03-30 08:44:33 +0000
+++ modules/update/Makefile.am  2010-11-22 17:21:23 +0000
@@ -1,6 +1,7 @@
 lib_LTLIBRARIES += modules/update/hipd/libhipupdate.la
 
 modules_update_hipd_libhipupdate_la_SOURCES = modules/update/hipd/update.c \
-                                              
modules/update/hipd/update_legacy.c
+                                              
modules/update/hipd/update_legacy.c \
+                                              
modules/update/hipd/update_builder.c
 
 hipd_hipd_LDADD += modules/update/hipd/libhipupdate.la

=== modified file 'modules/update/hipd/update.c'
--- modules/update/hipd/update.c        2010-11-12 16:42:54 +0000
+++ modules/update/hipd/update.c        2010-11-22 17:21:23 +0000
@@ -49,7 +49,6 @@
 #include "hipd/pisa.h"
 #include "hipd/pkt_handling.h"
 #include "hipd/user.h"
-#include "lib/core/builder.h"
 #include "lib/core/common.h"
 #include "lib/core/crypto.h"
 #include "lib/core/debug.h"
@@ -62,6 +61,7 @@
 #include "lib/core/protodefs.h"
 #include "lib/core/solve.h"
 #include "lib/core/modularization.h"
+#include "update_builder.h"
 #include "update_legacy.h"
 #include "update.h"
 
@@ -70,11 +70,6 @@
         @todo Remove this kludge. */
     int update_state;
 
-    /** Update function set.
-        @note Do not modify this value directly. Use
-        hip_hadb_set_handle_function_set() instead. */
-    hip_update_func_set_t *hadb_update_func;
-
     /** This "linked list" includes the locators we recieved in the initial
      * UPDATE packet. Locators are stored as "struct in6_addr *"s.
      *
@@ -96,6 +91,17 @@
 static const int update_id_window_size = 50;
 
 /**
+ * Retrieve a pointer to the first locator in a LOCATOR parameter
+ *
+ * @param locator a pointer a LOCATOR parameter
+ * @return a pointer to the first locator in the LOCATOR parameter
+ */
+static struct hip_locator_info_addr_item 
*hip_get_locator_first_addr_item(struct hip_locator *locator)
+{
+    return (struct hip_locator_info_addr_item *) (locator + 1);
+}
+
+/**
  * build locators in an UPDATE message
  *
  * @param locator_msg the message where the LOCATOR should be appended
@@ -616,6 +622,88 @@
 }
 
 /**
+ * Retreive a @c LOCATOR ADDRESS ITEM@c from a list.
+ *
+ * @param item_list a pointer to the first item in the list
+ * @param idx       the index of the item in the list
+ * @return          the locator addres item
+ */
+static union hip_locator_info_addr *hip_get_locator_item(void *item_list, int 
idx)
+{
+    int i = 0;
+    struct hip_locator_info_addr_item *temp;
+    char *result;
+    result = (char *) item_list;
+
+
+    for (i = 0; i <= idx - 1; i++) {
+        temp = (struct hip_locator_info_addr_item *) result;
+        if (temp->locator_type == HIP_LOCATOR_LOCATOR_TYPE_ESP_SPI ||
+            temp->locator_type == HIP_LOCATOR_LOCATOR_TYPE_IPV6) {
+            result += sizeof(struct hip_locator_info_addr_item);
+        } else {
+            result += sizeof(struct hip_locator_info_addr_item2);
+        }
+    }
+    return (union hip_locator_info_addr *) result;
+}
+
+/**
+ * retrieve a IP address from a locator item structure
+ *
+ * @param item      a pointer to the item
+ * @return a pointer to the IP address
+ */
+static struct in6_addr *hip_get_locator_item_address(void *item)
+{
+    struct hip_locator_info_addr_item *temp;
+
+
+    temp = item;
+    if (temp->locator_type == HIP_LOCATOR_LOCATOR_TYPE_ESP_SPI) {
+        return &temp->address;
+    } else if (temp->locator_type == HIP_LOCATOR_LOCATOR_TYPE_IPV6) {
+        return &temp->address;
+    } else {
+        return &((struct hip_locator_info_addr_item2 *) temp)->address;
+    }
+}
+
+/**
+ * Retrieve the amount the locators inside a LOCATOR parameter.
+ * Type 1 and 2 parameters are supported.
+ *
+ * @param locator a LOCATOR parameter
+ * @return the amount of locators
+ */
+int hip_get_locator_addr_item_count(const struct hip_locator *locator)
+{
+    const char *address_pointer = (const char *) (locator + 1);
+    int amount                  = 0;
+    uint8_t type;
+
+    while (address_pointer <
+          ((const char *) locator) + hip_get_param_contents_len(locator)) {
+        type = ((const struct hip_locator_info_addr_item *)
+               address_pointer)->locator_type;
+
+        if (type == HIP_LOCATOR_LOCATOR_TYPE_UDP) {
+            address_pointer += sizeof(struct hip_locator_info_addr_item2);
+            amount += 1;
+        } else if (type == HIP_LOCATOR_LOCATOR_TYPE_ESP_SPI) {
+            address_pointer += sizeof(struct hip_locator_info_addr_item);
+            amount += 1;
+        } else if (type == HIP_LOCATOR_LOCATOR_TYPE_IPV6) {
+            address_pointer += sizeof(struct hip_locator_info_addr_item);
+            amount += 1;
+        } else {
+            address_pointer += sizeof(struct hip_locator_info_addr_item);
+        }
+    }
+    return amount;
+}
+
+/**
  * process a LOCATOR paramter
  *
  * @param ha the related host association
@@ -638,7 +726,6 @@
     HIP_IFEL(!locator, -1, "locator is NULL");
 
     locator_addr_count = hip_get_locator_addr_item_count(locator);
-    HIP_IFEL((locator_addr_count < 0), -1, "Negative address count\n");
 
     HIP_DEBUG("LOCATOR has %d address(es), loc param len=%d\n",
               locator_addr_count, hip_get_param_total_len(locator));
@@ -850,7 +937,6 @@
              "Error on allocating memory for a update state instance.\n");
 
     update_state->update_state                   = 0;
-    update_state->hadb_update_func               = NULL;
     update_state->addresses_to_send_echo_request = hip_linked_list_init();
     update_state->update_id_out                  = 0;
     update_state->update_id_in                   = 0;
@@ -994,8 +1080,6 @@
         ack_peer_update_id = ntohl(ack->peer_update_id);
         HIP_DEBUG("ACK parameter found with peer Update ID %u.\n",
                   ack_peer_update_id);
-        /*ha->hadb_update_func->hip_update_handle_ack(
-         *      ha, ack, has_esp_info);*/
         if (ack_peer_update_id != hip_update_get_out_id(localstate)) {
             // Simplified logic of RFC 5201 6.12.2, 1st step:
             // We drop the packet if the Update ID in the ACK
@@ -1137,8 +1221,6 @@
 {
     int err = 0;
 
-    lmod_register_packet_type(HIP_UPDATE, "HIP_UPDATE");
-
     HIP_IFEL(lmod_register_state_init_function(&hip_update_init_state),
              -1,
              "Error on registering update state init function.\n");

=== modified file 'modules/update/hipd/update.h'
--- modules/update/hipd/update.h        2010-11-19 16:10:03 +0000
+++ modules/update/hipd/update.h        2010-11-22 17:21:23 +0000
@@ -38,6 +38,66 @@
 
 #include "lib/core/protodefs.h"
 
+/* the different mobility message types */
+#define HIP_UPDATE_LOCATOR              0
+#define HIP_UPDATE_ECHO_REQUEST         1
+#define HIP_UPDATE_ECHO_RESPONSE        2
+#define HIP_UPDATE_ESP_ANCHOR           3
+#define HIP_UPDATE_ESP_ANCHOR_ACK       4
+
+/* locator parameter types */
+#define HIP_LOCATOR_LOCATOR_TYPE_IPV6    0
+#define HIP_LOCATOR_LOCATOR_TYPE_ESP_SPI 1
+#define HIP_LOCATOR_LOCATOR_TYPE_UDP     2
+
+
+struct hip_locator {
+    hip_tlv_type_t type;
+    hip_tlv_len_t  length;
+    /* fixed part ends */
+} __attribute__ ((packed));
+
+/**
+ * Fixed start of this struct must match to struct hip_peer_addr_list_item
+ * for the part of address item. It is used in hip_update_locator_match().
+ * @todo Maybe fix this in some better way?
+ */
+struct hip_locator_info_addr_item {
+    uint8_t         traffic_type;
+    uint8_t         locator_type;
+    uint8_t         locator_length;
+    uint8_t         reserved; /**< last bit is P (prefered) */
+    uint32_t        lifetime;
+    struct in6_addr address;
+}  __attribute__ ((packed));
+
+/**
+ * it is the type 2 locater for UDP or other transport protocol later.
+ */
+struct hip_locator_info_addr_item2 {
+    uint8_t         traffic_type;
+    uint8_t         locator_type;
+    uint8_t         locator_length;
+    uint8_t         reserved; /* last bit is P (prefered) */
+    uint32_t        lifetime;
+    uint16_t        port;
+    uint8_t         transport_protocol;
+    uint8_t         kind;
+    uint32_t        priority;
+    uint32_t        spi;
+    struct in6_addr address;
+}  __attribute__ ((packed));
+
+/**
+ * it is a union of both type1 and type2 locator.
+ */
+union hip_locator_info_addr {
+    struct hip_locator_info_addr_item  type1;
+    struct hip_locator_info_addr_item2 type2;
+} __attribute__ ((packed));
+
+int hip_get_locator_addr_item_count(const struct hip_locator *locator);
+
 int hip_create_locators(hip_common_t *locator_msg,
                         struct hip_locator_info_addr_item **locators);
 

=== added file 'modules/update/hipd/update_builder.c'
--- modules/update/hipd/update_builder.c        1970-01-01 00:00:00 +0000
+++ modules/update/hipd/update_builder.c        2010-11-22 17:21:23 +0000
@@ -0,0 +1,111 @@
+/*
+ * Copyright (c) 2010 Aalto University and RWTH Aachen University.
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * @file
+ *
+ * This file facilitates buiding of mobility and multi-homing-specific
+ * parameters.
+ *
+ * @author Rene Hummen
+ */
+
+#include <string.h>
+
+#include "lib/core/builder.h"
+#include "lib/core/ife.h"
+#include "update_builder.h"
+
+
+/**
+ * build and append a HIP SEQ parameter to a message
+ *
+ * @param msg the message where the parameter will be appended
+ * @param update_id Update ID
+ * @return 0 on success, otherwise < 0.
+ */
+int hip_build_param_seq(struct hip_common *msg, uint32_t update_id)
+{
+    int err = 0;
+    struct hip_seq seq;
+
+    hip_set_param_type((struct hip_tlv_common *) &seq, HIP_PARAM_SEQ);
+    hip_calc_param_len((struct hip_tlv_common *) &seq,
+                       sizeof(struct hip_seq));
+    seq.update_id = htonl(update_id);
+    err = hip_build_param(msg, &seq);
+    return err;
+}
+
+/**
+ * build and append a HIP ACK parameter to a message
+ *
+ * @param msg the message where the parameter will be appended
+ * @param peer_update_id peer Update ID
+ * @return 0 on success, otherwise < 0.
+ */
+int hip_build_param_ack(struct hip_common *msg, uint32_t peer_update_id)
+{
+    int err = 0;
+    struct hip_ack ack;
+
+    hip_set_param_type((struct hip_tlv_common *) &ack, HIP_PARAM_ACK);
+    hip_calc_param_len((struct hip_tlv_common *) &ack, sizeof(struct hip_ack));
+    ack.peer_update_id = htonl(peer_update_id);
+    err = hip_build_param(msg, &ack);
+    return err;
+}
+
+/**
+ * build a HIP locator parameter
+ *
+ * @param msg           the message where the REA will be appended
+ * @param addrs         list of addresses
+ * @param addr_count number of addresses
+ * @return 0 on success, otherwise < 0.
+ */
+int hip_build_param_locator(struct hip_common *msg,
+                            struct hip_locator_info_addr_item *addrs,
+                            int addr_count)
+{
+    int err                          = 0;
+    struct hip_locator *locator_info = NULL;
+    int addrs_len = addr_count * (sizeof(struct hip_locator_info_addr_item));
+
+    HIP_IFE(!(locator_info = malloc(sizeof(struct hip_locator) + addrs_len)), 
-1);
+
+    hip_set_param_type((struct hip_tlv_common *) locator_info, 
HIP_PARAM_LOCATOR);
+
+    hip_calc_generic_param_len((struct hip_tlv_common *) locator_info,
+                               sizeof(struct hip_locator),
+                               addrs_len);
+
+    memcpy(locator_info + 1, addrs, addrs_len);
+    HIP_IFE(hip_build_param(msg, locator_info), -1);
+
+out_err:
+    free(locator_info);
+    return err;
+}

=== added file 'modules/update/hipd/update_builder.h'
--- modules/update/hipd/update_builder.h        1970-01-01 00:00:00 +0000
+++ modules/update/hipd/update_builder.h        2010-11-22 17:21:23 +0000
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2010 Aalto University and RWTH Aachen University.
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * @file
+ *
+ * This file facilitates buiding of mobility and multi-homing-specific
+ * parameters.
+ *
+ * @author Rene Hummen
+ */
+
+#include "lib/core/protodefs.h"
+#include "update.h"
+
+#ifndef MODULES_UPDATE_HIPD_UPDATE_BUILDER_H
+#define MODULES_UPDATE_HIPD_UPDATE_BUILDER_H
+
+int hip_build_param_seq(struct hip_common *msg, uint32_t update_id);
+int hip_build_param_ack(struct hip_common *msg, uint32_t peer_update_id);
+int hip_build_param_locator(struct hip_common *msg,
+                            struct hip_locator_info_addr_item *addrs,
+                            int addr_count);
+
+#endif /* MODULES_UPDATE_HIPD_UPDATE_BUILDER_H */

=== modified file 'modules/update/hipd/update_legacy.c'
--- modules/update/hipd/update_legacy.c 2010-09-25 18:30:26 +0000
+++ modules/update/hipd/update_legacy.c 2010-11-22 17:21:23 +0000
@@ -43,9 +43,14 @@
 #include "lib/core/list.h"
 #include "lib/core/prefix.h"
 #include "lib/core/protodefs.h"
+#include "update_builder.h"
 #include "update.h"
 #include "update_legacy.h"
 
+
+#define HIP_LOCATOR_TRAFFIC_TYPE_DUAL    0
+#define HIP_LOCATOR_TRAFFIC_TYPE_SIGNAL  1
+
 /**
  * build a LOCATOR parameter for an UPDATE packet
  *

Other related posts: