[hipl-commit] [tiny] Rev 3566: Handling of I1 and UPDATE packets now uses libmodularization.

  • From: Tim Just <tim.just@xxxxxxxxxxxxxx>
  • To: hipl-commit@xxxxxxxxxxxxx
  • Date: Wed, 24 Feb 2010 15:10:08 +0200

Committer: Tim Just <tim.just@xxxxxxxxxxxxxx>
Date: Wed Feb 24 14:06:21 2010 +0100
Revision: 3566
Revision-id: tim.just@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Branch nick: tiny

Log:
  Handling of I1 and UPDATE packets now uses libmodularization.
  
  The function 'run_handle_functions' is called from hip_receive_control_packet
  and calls all registered handle functions for the current combination of 
  packet type and host association state.
  
  The handle function registration is done in init.c or in the corresponding
  module (update).

Modified:
  M  hipd/init.c
  M  hipd/input.c
  M  hipd/netdev.c
  M  modules/update/hipd/update.c
  M  modules/update/hipd/update.h

=== modified file 'hipd/init.c'
--- hipd/init.c 2010-02-22 18:30:02 +0000
+++ hipd/init.c 2010-02-24 13:06:21 +0000
@@ -408,6 +408,42 @@
 #endif /* ANDROID_CHANGES */
 #endif /* CONFIG_HIP_OPENWRT */
 
+static int hip_init_handle_functions(void)
+{
+    int err = 0;
+
+    hip_register_handle_function(HIP_I1, HIP_STATE_UNASSOCIATED, 
&hip_handle_i1, 0);
+    hip_register_handle_function(HIP_I1, HIP_STATE_I1_SENT,      
&hip_handle_i1, 0);
+    hip_register_handle_function(HIP_I1, HIP_STATE_I2_SENT,      
&hip_handle_i1, 0);
+    hip_register_handle_function(HIP_I1, HIP_STATE_R2_SENT,      
&hip_handle_i1, 0);
+    hip_register_handle_function(HIP_I1, HIP_STATE_ESTABLISHED,  
&hip_handle_i1, 0);
+    hip_register_handle_function(HIP_I1, HIP_STATE_CLOSING,      
&hip_handle_i1, 0);
+    hip_register_handle_function(HIP_I1, HIP_STATE_CLOSED,       
&hip_handle_i1, 0);
+    hip_register_handle_function(HIP_I1, HIP_STATE_NONE,         
&hip_handle_i1, 0);
+
+    hip_register_handle_function(HIP_STATE_NONE, HIP_STATE_UNASSOCIATED, 
&hip_handle_i1, 0);
+    hip_register_handle_function(HIP_STATE_NONE, HIP_STATE_I1_SENT,      
&hip_handle_i1, 0);
+    hip_register_handle_function(HIP_STATE_NONE, HIP_STATE_I2_SENT,      
&hip_handle_i1, 0);
+    hip_register_handle_function(HIP_STATE_NONE, HIP_STATE_R2_SENT,      
&hip_handle_i1, 0);
+    hip_register_handle_function(HIP_STATE_NONE, HIP_STATE_ESTABLISHED,  
&hip_handle_i1, 0);
+    hip_register_handle_function(HIP_STATE_NONE, HIP_STATE_CLOSING,      
&hip_handle_i1, 0);
+    hip_register_handle_function(HIP_STATE_NONE, HIP_STATE_CLOSED,       
&hip_handle_i1, 0);
+    hip_register_handle_function(HIP_STATE_NONE, HIP_STATE_NONE,         
&hip_handle_i1, 0);
+
+    /* @todo enable performance measurement */
+#if 0
+#ifdef CONFIG_HIP_PERFORMANCE
+    HIP_DEBUG("Start PERF_I1\n");
+    hip_perf_start_benchmark(perf_set, PERF_I1);
+    HIP_DEBUG("Stop and write PERF_I1\n");
+    hip_perf_stop_benchmark(perf_set, PERF_I1);
+    hip_perf_write_benchmark(perf_set, PERF_I1);
+#endif
+#endif
+
+    return err;
+}
+
 /**
  * Main initialization function for HIP daemon.
  */
@@ -442,6 +478,8 @@
 
     hip_set_os_dep_variables();
 
+    hip_init_handle_functions();
+
 #ifndef CONFIG_HIP_OPENWRT
 #ifdef CONFIG_HIP_DEBUG
     hip_print_sysinfo();
@@ -883,6 +921,8 @@
     /* Next line is needed only if RVS or hiprelay is in use. */
     hip_uninit_services();
 
+    hip_uninit_handle_functions();
+
 #ifdef CONFIG_HIP_OPPORTUNISTIC
     hip_oppdb_uninit();
 #endif

=== modified file 'hipd/input.c'
--- hipd/input.c        2010-02-24 10:15:34 +0000
+++ hipd/input.c        2010-02-24 13:06:21 +0000
@@ -510,7 +510,7 @@
                                struct in6_addr *dst_addr,
                                hip_portpair_t *msg_info)
 {
-    hip_ha_t tmp, *entry = NULL;
+    hip_ha_t tmp;
     int err = 0, skip_sync = 0;
     struct in6_addr ipv6_any_addr = IN6ADDR_ANY_INIT;
     struct hip_packet_context ctx = {0};
@@ -546,10 +546,12 @@
 
     /** @todo Check packet csum.*/
 
-    entry = hip_hadb_find_byhits(&msg->hits, &msg->hitr);
+    ctx.hadb_entry = hip_hadb_find_byhits(&msg->hits, &msg->hitr);
 
     // Check if we need to drop the packet
-    if (entry && hip_packet_to_drop(entry, type, &msg->hitr) == 1) {
+    if (ctx.hadb_entry &&
+        hip_packet_to_drop(ctx.hadb_entry, type, &msg->hitr) == 1)
+    {
         HIP_DEBUG("Ignoring the packet sent \n");
         err = -1;
         goto out_err;
@@ -558,19 +560,19 @@
     ctx.msg        = msg;
     ctx.src_addr   = src_addr;
     ctx.dst_addr   = dst_addr;
-    ctx.hadb_entry = entry;
     ctx.msg_info   = msg_info;
 
-    if (entry) {
-        state = entry->state;
+    if (ctx.hadb_entry) {
+        state = ctx.hadb_entry->state;
     } else {
         state = HIP_STATE_NONE;
     }
 
 #ifdef CONFIG_HIP_OPPORTUNISTIC
-    if (!entry && opportunistic_mode &&
+    if (!ctx.hadb_entry && opportunistic_mode &&
         (type == HIP_I1 || type == HIP_R1)) {
-        entry = hip_oppdb_get_hadb_entry_i1_r1(msg, src_addr,
+        ctx.hadb_entry = hip_oppdb_get_hadb_entry_i1_r1(msg,
+                                               src_addr,
                                                dst_addr,
                                                msg_info);
     }
@@ -586,21 +588,9 @@
     }
 #endif
 
+    hip_run_handle_functions(type, state, &ctx);
+
     switch (type) {
-    case HIP_DATA:
-    case HIP_I1:
-#ifdef CONFIG_HIP_PERFORMANCE
-        HIP_DEBUG("Start PERF_I1\n");
-        hip_perf_start_benchmark(perf_set, PERF_I1);
-#endif
-        err = hip_handle_i1(type, state, &ctx);
-#ifdef CONFIG_HIP_PERFORMANCE
-        HIP_DEBUG("Stop and write PERF_I1\n");
-        hip_perf_stop_benchmark(perf_set, PERF_I1);
-        hip_perf_write_benchmark(perf_set, PERF_I1);
-#endif
-        break;
-
     case HIP_I2:
         /* Possibly state. */
 #ifdef CONFIG_HIP_PERFORMANCE
@@ -615,7 +605,7 @@
 #endif
         break;
     case HIP_LUPDATE:
-        HIP_IFCS(entry, err = esp_prot_handle_light_update(type, state, &ctx));
+        HIP_IFCS(ctx.hadb_entry, err = esp_prot_handle_light_update(type, 
state, &ctx));
         break;
 
     case HIP_R1:
@@ -624,8 +614,8 @@
         hip_perf_start_benchmark(perf_set, PERF_R1);
 #endif
         /* State. */
-        HIP_IFEL(!entry, -1, "No entry when receiving R1\n");
-        HIP_IFCS(entry, err = hip_handle_r1(type, state, &ctx));
+        HIP_IFEL(!ctx.hadb_entry, -1, "No entry when receiving R1\n");
+        HIP_IFCS(ctx.hadb_entry, err = hip_handle_r1(type, state, &ctx));
 #ifdef CONFIG_HIP_PERFORMANCE
         HIP_DEBUG("Stop and write PERF_R1\n");
         hip_perf_stop_benchmark(perf_set, PERF_R1);
@@ -638,7 +628,7 @@
         HIP_DEBUG("Start PERF_R2\n");
         hip_perf_start_benchmark(perf_set, PERF_R2);
 #endif
-        HIP_IFCS(entry, err = hip_handle_r2(type, state, &ctx));
+        HIP_IFCS(ctx.hadb_entry, err = hip_handle_r2(type, state, &ctx));
 #ifdef CONFIG_HIP_PERFORMANCE
         HIP_DEBUG("Stop and write PERF_R2\n");
         hip_perf_stop_benchmark(perf_set, PERF_R2);
@@ -646,13 +636,8 @@
 #endif
         break;
 
-    case HIP_UPDATE:
-        HIP_DEBUG_HIT("received an UPDATE:  ", src_addr );
-        HIP_IFCS(entry, err = hip_handle_update(&ctx));
-        break;
-
     case HIP_NOTIFY:
-        HIP_IFCS(entry, err = hip_handle_notify(type, state, &ctx));
+        HIP_IFCS(ctx.hadb_entry, err = hip_handle_notify(type, state, &ctx));
         break;
 
     case HIP_BOS:
@@ -672,7 +657,7 @@
         HIP_DEBUG("Start PERF_HANDLE_CLOSE\n");
         hip_perf_start_benchmark(perf_set, PERF_HANDLE_CLOSE);
 #endif
-        HIP_IFCS(entry, err = hip_handle_close(type, state, &ctx));
+        HIP_IFCS(ctx.hadb_entry, err = hip_handle_close(type, state, &ctx));
 #ifdef CONFIG_HIP_PERFORMANCE
         HIP_DEBUG("Stop and write PERF_HANDLE_CLOSE");
         hip_perf_stop_benchmark(perf_set, PERF_HANDLE_CLOSE);
@@ -685,7 +670,7 @@
         HIP_DEBUG("Start PERF_HANDLE_CLOSE_ACK\n");
         hip_perf_start_benchmark(perf_set, PERF_HANDLE_CLOSE_ACK);
 #endif
-        HIP_IFCS(entry, err = hip_handle_close_ack(type, state, &ctx));
+        HIP_IFCS(ctx.hadb_entry, err = hip_handle_close_ack(type, state, 
&ctx));
 #ifdef CONFIG_HIP_PERFORMANCE
         HIP_DEBUG("Stop and write PERF_HANDLE_CLOSE_ACK\n");
         hip_perf_stop_benchmark(perf_set, PERF_HANDLE_CLOSE_ACK);

=== modified file 'hipd/netdev.c'
--- hipd/netdev.c       2010-02-17 16:39:54 +0000
+++ hipd/netdev.c       2010-02-24 13:06:21 +0000
@@ -1253,7 +1253,7 @@
              * address */
             exists = hip_exists_address_in_list(addr, ifa->ifa_index);
             HIP_IFEL(((exists && is_add) || (!exists && !is_add)), -1,
-                     "Address change discarded (exists=%d, is_add=%d)",
+                     "Address change discarded (exists=%d, is_add=%d)\n",
                      exists, is_add);
 
             hip_update_address_list(addr, is_add, ifa->ifa_index);

=== modified file 'modules/update/hipd/update.c'
--- modules/update/hipd/update.c        2010-02-24 08:28:04 +0000
+++ modules/update/hipd/update.c        2010-02-24 13:06:21 +0000
@@ -659,7 +659,9 @@
     }
 }
 
-int hip_handle_update(struct hip_packet_context *ctx)
+int hip_handle_update(const uint32_t packet_type,
+                      const uint32_t ha_state,
+                      struct hip_packet_context *ctx)
 {
     int err = 0, same_seq = 0;
     unsigned int ack_peer_update_id         = 0;
@@ -677,15 +679,15 @@
      * the implementation MAY reply with an ICMP Parameter Problem. */
     HIP_IFEL(!ctx->hadb_entry, -1, "No host association database entry 
found.\n");
 
-    /// @todo: Relay support
+    /** @todo: Relay support */
 
     /* RFC 5201 Section 4.4.2, Table 5: According to the state processes
      * listed, the state is moved from R2_SENT to ESTABLISHED if an
      * UPDATE packet is received */
     if (ctx->hadb_entry->state == HIP_STATE_R2_SENT) {
         ctx->hadb_entry->state = HIP_STATE_ESTABLISHED;
-        HIP_DEBUG("Received UPDATE in state %s, moving to " \
-                  "ESTABLISHED.\n", hip_state_str(ctx->hadb_entry->state));
+        HIP_DEBUG("Received UPDATE in state %s, moving to ESTABLISHED.\n",
+                  hip_state_str(ctx->hadb_entry->state));
     } else if (ctx->hadb_entry->state != HIP_STATE_ESTABLISHED) {
         HIP_ERROR("Received UPDATE in illegal state %s.\n",
                   hip_state_str(ctx->hadb_entry->state));
@@ -843,12 +845,18 @@
 /**
  * Initialization function for update module.
  *
- * @note currently without any functionality.
- *
  * @return 0
  */
 int hip_update_init(void)
 {
+    hip_register_handle_function(HIP_UPDATE,
+                                 HIP_STATE_ESTABLISHED,
+                                 &hip_handle_update,
+                                 0);
+    hip_register_handle_function(HIP_UPDATE,
+                                 HIP_STATE_R2_SENT,
+                                 &hip_handle_update,
+                                 0);
     return 0;
 }
 

=== modified file 'modules/update/hipd/update.h'
--- modules/update/hipd/update.h        2010-02-24 08:28:04 +0000
+++ modules/update/hipd/update.h        2010-02-24 13:06:21 +0000
@@ -9,7 +9,10 @@
 #ifndef HIP_HIPD_UPDATE_H
 #define HIP_HIPD_UPDATE_H
 
+#include <stdint.h>
+
 #include "lib/core/builder.h"
+#include "lib/modularization/modularization.h"
 #include "hipd/hadb.h"
 
 struct update_state {
@@ -63,7 +66,9 @@
  *
  * @return 0 if succeeded, error number otherwise
  */
-int hip_handle_update(struct hip_packet_context *ctx);
+int hip_handle_update(const uint32_t packet_type,
+                      const uint32_t ha_state,
+                      struct hip_packet_context *ctx);
 
 int hip_create_locators(hip_common_t *locator_msg,
                         struct hip_locator_info_addr_item **locators);

Other related posts:

  • » [hipl-commit] [tiny] Rev 3566: Handling of I1 and UPDATE packets now uses libmodularization. - Tim Just