[hipl-commit] [tiny] Rev 3535: Removed update specific members from struct hip_hadb_state.

  • From: Tim Just <tim.just@xxxxxxxxxxxxxx>
  • To: hipl-commit@xxxxxxxxxxxxx
  • Date: Thu, 18 Feb 2010 16:23:29 +0200

Committer: Tim Just <tim.just@xxxxxxxxxxxxxx>
Date: Thu Feb 18 15:18:07 2010 +0100
Revision: 3535
Revision-id: tim.just@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Branch nick: tiny

Log:
  Removed update specific members from struct hip_hadb_state.
  
  Also the way they are accessed has been changed. Now the update state is 
modularized.

Modified:
  M  hipd/hadb.c
  M  hipd/hadb.h
  M  hipd/input.c
  M  lib/core/debug.c
  M  lib/core/debug.h
  M  lib/core/state.h
  M  modules/update/hipd/update.c

=== modified file 'hipd/hadb.c'
--- hipd/hadb.c 2010-02-17 16:39:54 +0000
+++ hipd/hadb.c 2010-02-18 14:18:07 +0000
@@ -11,6 +11,7 @@
 #include "hadb.h"
 #include "hipd.h"
 #include "lib/core/list.h"
+#include "lib/modularization/modularization.h"
 
 /* TODO Remove this include when modularization is finised */
 #include "modules/update/hipd/update.h"
@@ -658,7 +659,9 @@
  */
 static int hip_hadb_init_entry(hip_ha_t *entry)
 {
-    int err = 0;
+    int   err          = 0;
+    void *update_state = NULL;
+
     HIP_IFEL(!entry, -1, "HA is NULL\n");
 
 #if 0
@@ -705,9 +708,14 @@
     //initialize the peer hostname
     memset(entry->peer_hostname, '\0', HIP_HOST_ID_HOSTNAME_LEN_MAX);
 
-    entry->addresses_to_send_echo_request = hip_linked_list_init();
+    /* @todo Need hook for modularization
+     * FIXME This initialization should be done in the update module!
+     */
+    update_state = hip_update_init_state();
+    entry->hip_modular_state = hip_init_state();
+    hip_add_state_item(entry->hip_modular_state, update_state, "update");
 
-    entry->peer_addresses_old             = hip_linked_list_init();
+    entry->peer_addresses_old = hip_linked_list_init();
 
     // Randomize inbound SPI
     get_random_bytes(&entry->spi_inbound_current,
@@ -1254,10 +1262,6 @@
     return &default_handle_func_set;
 }
 
-/*hip_update_func_set_t *hip_get_update_default_func_set() {
- *      return &default_update_func_set;
- * }*/
-
 /**
  * Sets function pointer set for an hadb record. Pointer values will not be
  * copied!
@@ -1296,6 +1300,13 @@
     return -1;
 }
 
+/* @todo Are these functions needed? */
+#if 0
+hip_update_func_set_t *hip_get_update_default_func_set()
+{
+    return &default_update_func_set;
+}
+
 /**
  * Sets function pointer set for an hadb record. Pointer values will not be
  * copied!
@@ -1315,6 +1326,7 @@
     //HIP_ERROR("Func pointer set malformed. Func pointer set NOT appied.");
     return -1;
 }
+#endif /* 0 */
 
 /* NOTE! When modifying this function, remember that some control values may
  * not be allowed to co-exist. Therefore the logical OR might not be enough
@@ -1444,24 +1456,6 @@
 }
 
 /**
- * Removes all the addresses from the addresses_to_send_echo_request list
- * and deallocates them.
- * @param ha pointer to a host association
- */
-void hip_remove_addresses_to_send_echo_request(hip_ha_t *ha)
-{
-    int i = 0;
-    struct in6_addr *address;
-    hip_list_t *item, *tmp;
-
-    list_for_each_safe(item, tmp, ha->addresses_to_send_echo_request, i) {
-        address = (struct in6_addr *) list_entry(item);
-        list_del(address, ha->addresses_to_send_echo_request);
-        HIP_FREE(address);
-    }
-}
-
-/**
  * Deletes a HA state (and deallocate memory) Deletes all associates IPSEC SAs
  * and frees the memory occupied by the HA state.
  *
@@ -1505,10 +1499,7 @@
         HIP_FREE(ha->rendezvous_addr);
     }
 
-    if (ha->addresses_to_send_echo_request) {
-        hip_remove_addresses_to_send_echo_request(ha);
-        hip_ht_uninit(ha->addresses_to_send_echo_request);
-    }
+    hip_free_state(ha->hip_modular_state);
 
     if (ha->locator) {
         free(ha->locator);

=== modified file 'hipd/hadb.h'
--- hipd/hadb.h 2010-02-17 16:39:54 +0000
+++ hipd/hadb.h 2010-02-18 14:18:07 +0000
@@ -132,8 +132,6 @@
 void hip_hadb_set_peer_controls(hip_ha_t *entry, hip_controls_t mask);
 void hip_hadb_cancel_local_controls(hip_ha_t *entry, hip_controls_t mask);
 
-void hip_remove_addresses_to_send_echo_request(hip_ha_t *ha);
-
 int hip_count_open_connections(void);
 
 hip_ha_t *hip_hadb_find_rvs_candidate_entry(hip_hit_t *, hip_hit_t *);

=== modified file 'hipd/input.c'
--- hipd/input.c        2010-02-17 16:39:54 +0000
+++ hipd/input.c        2010-02-18 14:18:07 +0000
@@ -1678,11 +1678,12 @@
     hip_transform_suite_t esp_tfm, hip_tfm;
     struct hip_spi_in_item spi_in_data;
     struct hip_context i2_context;
-    struct hip_locator *locator = NULL;
-    int do_transform            = 0;
-    int if_index                = 0;
+    struct hip_locator *locator             = NULL;
+    int do_transform                        = 0;
+    int if_index                            = 0;
     struct sockaddr_storage ss_addr;
-    struct sockaddr *addr       = NULL;
+    struct sockaddr *addr                   = NULL;
+    struct update_state *localstate         = NULL;
     /** A function set for NAT travelsal. */
 
     HIP_INFO("\n\nReceived I2 from:");
@@ -2183,7 +2184,12 @@
      *   an Update ID of 0". All of these requirements can not be achieved
      *   at the same time so we initialize the id to -1.
      */
-    entry->update_id_out = -1;
+
+    /* @todo Need hook for modularization */
+    //entry->update_id_out = -1; TODO why -1?
+    localstate = hip_get_state_item(entry->hip_modular_state, "update");
+    localstate->update_id_out = 0;
+
     entry->state         = HIP_STATE_ESTABLISHED;
 
     /***** LOCATOR PARAMETER ******/
@@ -2354,12 +2360,13 @@
 int hip_handle_r2(hip_common_t *r2, in6_addr_t *r2_saddr, in6_addr_t *r2_daddr,
                   hip_ha_t *entry, hip_portpair_t *r2_info)
 {
-    struct hip_context *ctx       = NULL;
-    struct hip_esp_info *esp_info = NULL;
+    struct hip_context *ctx         = NULL;
+    struct hip_esp_info *esp_info   = NULL;
     struct hip_spi_out_item spi_out_data;
-    int err                       = 0, tfm = 0, retransmission = 0, idx = 0;
-    uint32_t spi_recvd            = 0, spi_in = 0;
-    struct hip_locator *locator   = NULL;
+    int err                         = 0, tfm = 0, retransmission = 0, idx = 0;
+    uint32_t spi_recvd              = 0, spi_in = 0;
+    struct hip_locator *locator     = NULL;
+    struct update_state *localstate = NULL;
 
     if (entry->state == HIP_STATE_ESTABLISHED) {
         retransmission = 1;
@@ -2519,7 +2526,11 @@
      *   an Update ID of 0". All of these requirements can not be achieved
      *   at the same time so we initialize the id to -1.
      */
-    entry->update_id_out = -1;
+    /* @todo Need hook for modularization */
+    //entry->update_id_out = -1; TODO why -1?
+    localstate = hip_get_state_item(entry->hip_modular_state, "update");
+    localstate->update_id_out  = 0;
+
     entry->state         = HIP_STATE_ESTABLISHED;
     hip_hadb_insert_state(entry);
 

=== modified file 'lib/core/debug.c'
--- lib/core/debug.c    2010-02-11 09:57:04 +0000
+++ lib/core/debug.c    2010-02-18 14:18:07 +0000
@@ -736,19 +736,6 @@
     }
 }
 
-void hip_print_addresses_to_send_update_request(hip_ha_t *ha)
-{
-    hip_list_t *item = NULL, *tmp = NULL;
-    struct in6_addr *address;
-    int i            = 0;
-
-    HIP_DEBUG("Addresses to send update:\n");
-    list_for_each_safe(item, tmp, ha->addresses_to_send_echo_request, i) {
-        address = (struct in6_addr *) list_entry(item);
-        HIP_DEBUG_IN6ADDR("", address);
-    }
-}
-
 //add  by santtu
 /**
  * hip_print_hit - print a HIT

=== modified file 'lib/core/debug.h'
--- lib/core/debug.h    2010-02-17 13:08:39 +0000
+++ lib/core/debug.h    2010-02-18 14:18:07 +0000
@@ -244,7 +244,6 @@
                        const char *function,
                        const char *str,
                        const struct hip_locator *locator);
-void hip_print_addresses_to_send_update_request(hip_ha_t *);
 
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
 

=== modified file 'lib/core/state.h'
--- lib/core/state.h    2010-02-18 11:08:26 +0000
+++ lib/core/state.h    2010-02-18 14:18:07 +0000
@@ -391,10 +391,6 @@
     uint16_t                                   esp_keymat_index;
     /* Last Kn, where n is @c keymat_calc_index. */
     unsigned char                              
current_keymat_K[HIP_AH_SHA_LEN];
-    /** Stored outgoing UPDATE ID counter. */
-    uint32_t                                   update_id_out;
-    /** Stored incoming UPDATE ID counter. */
-    uint32_t                                   update_id_in;
     /** Our public host identity. */
     struct hip_host_id *                       our_pub;
     /** Our private host identity. */
@@ -436,10 +432,6 @@
      *  @note Do not modify this value directly. Use
      *  hip_hadb_set_handle_function_set() instead. */
     hip_misc_func_set_t *                      hadb_misc_func;
-    /** 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;
     /** Transmission function set.
      *  @note Do not modify this value directly. Use
      *  hip_hadb_set_handle_function_set() instead. */
@@ -486,24 +478,15 @@
     int outbound_sa_count;
     int inbound_sa_count;
 
-    /** This "linked list" includes the locators we recieved in the initial
-     * UPDATE packet. Locators are stored as "struct in6_addr *"s.
-     *
-     * Hipd sends UPDATE packets including ECHO_REQUESTS to all these
-     * addresses.
-     *
-     * Notice that there's a hack that a hash table is used as a linked list
-     * here but this is common allover HIPL and it doesn't seem to cause
-     * performance problems.
-     */
-    HIP_HASHTABLE *addresses_to_send_echo_request;
-
     int            spi_inbound_current;
     int            spi_outbound_current;
     int            spi_outbound_new;
 
     // Has struct hip_peer_addr_list_item s
     HIP_HASHTABLE *peer_addresses_old;
+
+    /* modular state */
+    struct modular_state *hip_modular_state;
 };
 #endif /* __KERNEL__ */
 

=== modified file 'modules/update/hipd/update.c'
--- modules/update/hipd/update.c        2010-02-18 10:56:34 +0000
+++ modules/update/hipd/update.c        2010-02-18 14:18:07 +0000
@@ -69,6 +69,7 @@
     uint16_t mask                         = 0;
     struct hip_seq *seq                   = NULL;
     struct hip_echo_request *echo_request = NULL;
+    struct update_state *localstate       = NULL;
 
     HIP_DEBUG("Creating the UPDATE packet\n");
 
@@ -126,8 +127,10 @@
         /* hip_update_set_new_spi_in_old(ha, esp_info_old_spi,
          *  esp_info_new_spi, 0);*/
 
-        ha->update_id_out++;
-        update_id_out = ha->update_id_out;
+        localstate = hip_get_state_item(ha->hip_modular_state, "update");
+
+        localstate->update_id_out++;
+        update_id_out = localstate->update_id_out;
         _HIP_DEBUG("outgoing UPDATE ID=%u\n", update_id_out);
         /** @todo Handle this case. */
         HIP_IFEL(hip_build_param_seq(update_packet_to_send, update_id_out), -1,
@@ -236,6 +239,40 @@
     return err;
 }
 
+/**
+ * Removes all the addresses from the addresses_to_send_echo_request list
+ * and deallocates them.
+ * @param ha pointer to a host association
+*/
+static void hip_remove_addresses_to_send_echo_request(struct update_state 
*state)
+{
+    int i = 0;
+    hip_list_t *item = NULL, *tmp = NULL;
+    struct in6_addr *address;
+
+    list_for_each_safe(item, tmp, state->addresses_to_send_echo_request, i) {
+        address = (struct in6_addr *)list_entry(item);
+        list_del(address, state->addresses_to_send_echo_request);
+        HIP_FREE(address);
+    }
+}
+
+static void hip_print_addresses_to_send_update_request(hip_ha_t *ha)
+{
+    int i = 0;
+    hip_list_t *item = NULL, *tmp = NULL;
+    struct in6_addr *address;
+    struct update_state *localstate;
+
+    localstate = hip_get_state_item(ha->hip_modular_state, "update");
+
+    HIP_DEBUG("Addresses to send update:\n");
+    list_for_each_safe(item, tmp, localstate->addresses_to_send_echo_request, 
i) {
+        address = (struct in6_addr *)list_entry(item);
+        HIP_DEBUG_IN6ADDR("", address);
+    }
+}
+
 static int hip_select_local_addr_for_first_update(const struct hip_hadb_state 
*ha,
                                                   const struct in6_addr 
*src_addr,
                                                   const struct in6_addr 
*dst_addr,
@@ -307,6 +344,7 @@
     int err                             = 0, i = 0;
     hip_list_t *item                    = NULL, *tmp = NULL;
     hip_common_t *update_packet_to_send = NULL;
+    struct update_state *localstate     = NULL;
     struct in6_addr local_addr;
 
     HIP_IFEL(!(update_packet_to_send = hip_msg_alloc()), -ENOMEM,
@@ -338,7 +376,9 @@
 
             break;
         case HIP_UPDATE_ECHO_REQUEST:
-            list_for_each_safe(item, tmp, ha->addresses_to_send_echo_request, 
i) {
+            localstate = hip_get_state_item(ha->hip_modular_state, "update");
+
+            list_for_each_safe(item, tmp, 
localstate->addresses_to_send_echo_request, i) {
                 dst_addr = (struct in6_addr *) list_entry(item);
 
                 _HIP_DEBUG_IN6ADDR("Sending echo requests from", src_addr);
@@ -465,6 +505,7 @@
     union hip_locator_info_addr *locator_info_addr;
     struct in6_addr *peer_addr = 0;
     int src_addr_included      = 0;
+    struct update_state *localstate = NULL;
 
     HIP_IFEL(!locator, -1, "locator is NULL");
 
@@ -479,7 +520,9 @@
 
     // Empty the addresses_to_send_echo_request list before adding the
     // new addresses
-    hip_remove_addresses_to_send_echo_request(ha);
+    localstate = hip_get_state_item(ha->hip_modular_state, "update");
+    HIP_DEBUG("hip_get_state_item returned localstate: %p\n", localstate);
+    hip_remove_addresses_to_send_echo_request(localstate);
 
     locator_address_item =  hip_get_locator_first_addr_item(locator);
     for (i = 0; i < locator_addr_count; i++) {
@@ -493,7 +536,8 @@
         ;
 
         ipv6_addr_copy(peer_addr, 
hip_get_locator_item_address(locator_info_addr));
-        list_add(peer_addr, ha->addresses_to_send_echo_request);
+
+        list_add(peer_addr, localstate->addresses_to_send_echo_request);
 
         HIP_DEBUG_IN6ADDR("Comparing", src_addr);
         HIP_DEBUG_IN6ADDR("to ", peer_addr);
@@ -514,7 +558,7 @@
         ;
 
         ipv6_addr_copy(peer_addr, src_addr);
-        list_add(peer_addr, ha->addresses_to_send_echo_request);
+        list_add(peer_addr, localstate->addresses_to_send_echo_request);
     }
 
     hip_print_addresses_to_send_update_request(ha);
@@ -616,7 +660,7 @@
 int hip_receive_update(hip_common_t *received_update_packet, in6_addr_t 
*src_addr,
                        in6_addr_t *dst_addr, hip_ha_t *ha, hip_portpair_t 
*sinfo)
 {
-    int err                                 = 0;
+    int err = 0, same_seq = 0;
     unsigned int ack_peer_update_id         = 0;
     unsigned int seq_update_id              = 0;
     unsigned int has_esp_info               = 0;
@@ -626,7 +670,7 @@
     struct hip_locator *locator             = NULL;
     struct hip_echo_request *echo_request   = NULL;
     struct hip_echo_response *echo_response = NULL;
-    int same_seq                            = 0;
+    struct update_state *localstate         = NULL;
 
     /* RFC 5201 Section 5.4.4: If there is no corresponding HIP association,
      * the implementation MAY reply with an ICMP Parameter Problem. */
@@ -648,9 +692,11 @@
         goto out_err;
     }
 
+    localstate = hip_get_state_item(ha->hip_modular_state, "update");
+
     /* RFC 5201 Section 6.12: Receiving UPDATE Packets */
-    HIP_DEBUG("previous incoming update id=%u\n", ha->update_id_in);
-    HIP_DEBUG("previous outgoing update id=%u\n", ha->update_id_out);
+    HIP_DEBUG("previous incoming update id=%u\n", localstate->update_id_in);
+    HIP_DEBUG("previous outgoing update id=%u\n", localstate->update_id_out);
 
     /* RFC 5201 Section 6.12: 3th or 4th step:
      *
@@ -667,7 +713,7 @@
                   ack_peer_update_id);
         /*ha->hadb_update_func->hip_update_handle_ack(
          *      ha, ack, has_esp_info);*/
-        if (ack_peer_update_id != ha->update_id_out) {
+        if (ack_peer_update_id != localstate->update_id_out) {
             // Simplified logic of RFC 5201 6.12.2, 1st step:
             // We drop the packet if the Update ID in the ACK
             // parameter does not equal to the last outgoing Update ID
@@ -675,7 +721,7 @@
                       "equal to the last outgoing Update ID (%u). "
                       "Dropping the packet.\n",
                       ack_peer_update_id,
-                      ha->update_id_out);
+                      localstate->update_id_out);
             err = -1;
             goto out_err;
         }
@@ -694,15 +740,15 @@
 
         /// @todo 15.9.2009: Handle retransmission case
 
-        if (ha->update_id_in != 0 &&
-            (seq_update_id < ha->update_id_in ||
-             seq_update_id > ha->update_id_in + update_id_window_size)) {
+        if (localstate->update_id_in != 0 &&
+            (seq_update_id < localstate->update_id_in ||
+             seq_update_id > localstate->update_id_in + 
update_id_window_size)) {
             // RFC 5201 6.12.1 part 1:
             HIP_DEBUG("Update ID (%u) in the SEQ parameter is not "
                       "in the window of the previous Update ID (%u). "
                       "Dropping the packet.\n",
                       seq_update_id,
-                      ha->update_id_in);
+                      localstate->update_id_in);
 
             err = -1;
             goto out_err;
@@ -714,11 +760,12 @@
          * in the received SEQ parameter, for replay protection.
          */
 
-        if (ha->update_id_in != 0 && ha->update_id_in == seq_update_id) {
+        if (localstate->update_id_in != 0 &&
+            localstate->update_id_in == seq_update_id) {
             same_seq = 1;
         }
 
-        ha->update_id_in = seq_update_id;
+        localstate->update_id_in = seq_update_id;
         _HIP_DEBUG("Stored peer's incoming UPDATE ID %u\n", ha->update_id_in);
     }
 
@@ -817,7 +864,7 @@
     }
     state->update_state = 0;
     state->hadb_update_func = NULL;
-    state->addresses_to_send_echo_request = malloc(sizeof(hip_list_t));
+    state->addresses_to_send_echo_request = hip_linked_list_init();
     state->update_id_out = 0;
     state->update_id_in = 0;

Other related posts:

  • » [hipl-commit] [tiny] Rev 3535: Removed update specific members from struct hip_hadb_state. - Tim Just