[hipl-commit] [tiny] Rev 3564: Prepared CLOSE handling for modularization.

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

Committer: Tim Just <tim.just@xxxxxxxxxxxxxx>
Date: Wed Feb 24 10:52:53 2010 +0100
Revision: 3564
Revision-id: tim.just@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Branch nick: tiny

Log:
  Prepared CLOSE handling for modularization.
    
  Unified hip_receive_close and hip_handle_close into hip_handle_close. This 
function
  will be used as handle function in terms of libmodularization.

Modified:
  M  hipd/close.c
  M  hipd/close.h
  M  hipd/input.c

=== modified file 'hipd/close.c'
--- hipd/close.c        2010-02-22 18:30:02 +0000
+++ hipd/close.c        2010-02-24 09:52:53 +0000
@@ -173,42 +173,66 @@
     return err;
 }
 
-int hip_handle_close(struct hip_common *close, hip_ha_t *entry)
+int hip_handle_close(const uint32_t packet_type,
+                     const uint32_t ha_state,
+                     struct hip_packet_context *ctx)
 {
 #ifdef CONFIG_HIP_PERFORMANCE
     HIP_DEBUG("Start PERF_HANDLE_CLOSE\n");
     hip_perf_start_benchmark( perf_set, PERF_HANDLE_CLOSE );
 #endif
-    int err                      = 0, mask = 0;
+    uint16_t mask = HIP_PACKET_CTRL_ANON;
+    int err = 0, echo_len;
     struct hip_common *close_ack = NULL;
     struct hip_echo_request *request;
-    int echo_len;
+
+    HIP_IFEL(ipv6_addr_any(&(ctx->msg)->hitr), -1,
+             "Received NULL receiver HIT in CLOSE. Dropping\n");
+
+    HIP_IFEL(!hip_controls_sane(ntohs(ctx->msg->control), 0), -1,
+             "Received illegal controls in CLOSE: 0x%x. Dropping\n",
+             ntohs(ctx->msg->control));
+
+    if (!ctx->hadb_entry) {
+        HIP_DEBUG("No HA for the received close\n");
+        goto out_err;
+    }
+
+    switch (ha_state) {
+    case HIP_STATE_ESTABLISHED:
+    case HIP_STATE_CLOSING:
+        /* Proceed with packet handling */
+        break;
+    default:
+        HIP_ERROR("Internal state (%d) is incorrect\n", ha_state);
+        goto out_err;
+    }
 
     /* verify HMAC */
-    if (entry->is_loopback) {
-        HIP_IFEL(hip_verify_packet_hmac(close, &entry->hip_hmac_out),
+    if (ctx->hadb_entry->is_loopback) {
+        HIP_IFEL(hip_verify_packet_hmac(ctx->msg, 
&(ctx->hadb_entry)->hip_hmac_out),
                  -ENOENT, "HMAC validation on close failed.\n");
     } else {
-        HIP_IFEL(hip_verify_packet_hmac(close, &entry->hip_hmac_in),
+        HIP_IFEL(hip_verify_packet_hmac(ctx->msg, 
&(ctx->hadb_entry)->hip_hmac_in),
                  -ENOENT, "HMAC validation on close failed.\n");
     }
 
     /* verify signature */
-    HIP_IFEL(entry->verify(entry->peer_pub_key, close), -EINVAL,
+    HIP_IFEL(ctx->hadb_entry->verify(ctx->hadb_entry->peer_pub_key, ctx->msg), 
-EINVAL,
              "Verification of close signature failed.\n");
 
     HIP_IFE(!(close_ack = hip_msg_alloc()), -ENOMEM);
 
     HIP_IFEL(!(request =
-                   hip_get_param(close, HIP_PARAM_ECHO_REQUEST_SIGN)),
+                   hip_get_param(ctx->msg, HIP_PARAM_ECHO_REQUEST_SIGN)),
              -1, "No echo request under signature.\n");
     echo_len = hip_get_param_contents_len(request);
 
     hip_build_network_hdr(close_ack,
                           HIP_CLOSE_ACK,
                           mask,
-                          &entry->hit_our,
-                          &entry->hit_peer);
+                          &(ctx->hadb_entry)->hit_our,
+                          &(ctx->hadb_entry)->hit_peer);
 
     HIP_IFEL(hip_build_param_echo(close_ack, request + 1,
                                   echo_len, 1, 0), -1,
@@ -216,19 +240,19 @@
 
     /************* HMAC ************/
     HIP_IFEL(hip_build_param_hmac_contents(close_ack,
-                                           &entry->hip_hmac_out),
+                                           &(ctx->hadb_entry)->hip_hmac_out),
              -1, "Building of HMAC failed.\n");
 
     /********** Signature **********/
-    HIP_IFEL(entry->sign(entry->our_priv_key, close_ack), -EINVAL,
+    HIP_IFEL(ctx->hadb_entry->sign(ctx->hadb_entry->our_priv_key, close_ack), 
-EINVAL,
              "Could not create signature.\n");
 
-    HIP_IFEL(hip_send_pkt(NULL, &entry->peer_addr, 
hip_get_local_nat_udp_port(),
-                          entry->peer_udp_port,
-                          close_ack, entry, 0),
+    HIP_IFEL(hip_send_pkt(NULL, &(ctx->hadb_entry)->peer_addr, 
hip_get_local_nat_udp_port(),
+                          ctx->hadb_entry->peer_udp_port,
+                          close_ack, ctx->hadb_entry, 0),
              -ECOMM, "Sending CLOSE ACK message failed.\n");
 
-    entry->state = HIP_STATE_CLOSED;
+    ctx->hadb_entry->state = HIP_STATE_CLOSED;
 
     HIP_DEBUG("CLOSED.\n");
 
@@ -237,18 +261,18 @@
 #ifdef CONFIG_HIP_RVS
     if (hip_relay_get_status()) {
         hip_relrec_t dummy;
-        memcpy(&(dummy.hit_r), &(close->hits),
-               sizeof(close->hits));
+        memcpy(&(dummy.hit_r), &(ctx->msg->hits),
+               sizeof(ctx->msg->hits));
         hip_relht_rec_free_doall(&dummy);
         /* Check that the element really got deleted. */
         if (hip_relht_get(&dummy) == NULL) {
             HIP_DEBUG_HIT("Deleted relay record for HIT",
-                          &(close->hits));
+                          &(ctx->msg->hits));
         }
     }
 #endif
 
-    HIP_IFEL(hip_del_peer_info(&entry->hit_our, &entry->hit_peer), -1,
+    HIP_IFEL(hip_del_peer_info(&(ctx->hadb_entry)->hit_our, 
&(ctx->hadb_entry)->hit_peer), -1,
              "Deleting peer info failed.\n");
 #ifdef CONFIG_HIP_PERFORMANCE
     HIP_DEBUG("Stop and write PERF_HANDLE_CLOSE\n");
@@ -264,52 +288,6 @@
     return err;
 }
 
-int hip_receive_close(struct hip_common *close,
-                      hip_ha_t          *entry)
-{
-    int state     = 0;
-    int err       = 0;
-    uint16_t mask = HIP_PACKET_CTRL_ANON;
-
-    /* XX FIX: CHECK THE SIGNATURE */
-
-    HIP_DEBUG("\n");
-    HIP_IFEL(ipv6_addr_any(&close->hitr), -1,
-             "Received NULL receiver HIT in CLOSE. Dropping\n");
-
-    if (!hip_controls_sane(ntohs(close->control), mask)) {
-        HIP_ERROR("Received illegal controls in CLOSE: 0x%x. Dropping\n",
-                  ntohs(close->control));
-        goto out_err;
-    }
-
-    if (!entry) {
-        HIP_DEBUG("No HA for the received close\n");
-        goto out_err;
-    } else {
-        HIP_LOCK_HA(entry);
-        state = entry->state;
-    }
-
-    switch (state) {
-    case HIP_STATE_ESTABLISHED:
-    case HIP_STATE_CLOSING:
-        err = hip_handle_close(close, entry);
-        break;
-    default:
-        HIP_ERROR("Internal state (%d) is incorrect\n", state);
-        break;
-    }
-
-    if (entry) {
-        /* XX CHECK: is the put done twice? once already in handle? */
-        HIP_UNLOCK_HA(entry);
-        /* hip_put_ha(entry); */
-    }
-out_err:
-    return err;
-}
-
 int hip_handle_close_ack(struct hip_common *close_ack, hip_ha_t *entry)
 {
 #ifdef CONFIG_HIP_PERFORMANCE

=== modified file 'hipd/close.h'
--- hipd/close.h        2010-02-17 13:08:39 +0000
+++ hipd/close.h        2010-02-24 09:52:53 +0000
@@ -14,10 +14,11 @@
 #include "lib/tool/pk.h"
 
 int hip_send_close(struct hip_common *msg, int delete_ha_info);
-int hip_handle_close(struct hip_common *close, hip_ha_t *entry);
+int hip_handle_close(const uint32_t packet_type,
+                     const uint32_t ha_state,
+                     struct hip_packet_context *ctx);
 int hip_handle_close_ack(struct hip_common *close_ack, hip_ha_t *entry);
 int hip_purge_closing_ha(hip_ha_t *ha, void *notused);
-int hip_receive_close(struct hip_common *close, hip_ha_t *entry);
 int hip_receive_close_ack(struct hip_common *close_ack, hip_ha_t *entry);
 
 #endif /* HIP_HIPD_CLOSE_H */

=== modified file 'hipd/input.c'
--- hipd/input.c        2010-02-24 09:22:28 +0000
+++ hipd/input.c        2010-02-24 09:52:53 +0000
@@ -672,7 +672,7 @@
         HIP_DEBUG("Start PERF_HANDLE_CLOSE\n");
         hip_perf_start_benchmark(perf_set, PERF_HANDLE_CLOSE);
 #endif
-        HIP_IFCS(entry, err = hip_receive_close(msg, entry));
+        HIP_IFCS(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);

Other related posts:

  • » [hipl-commit] [tiny] Rev 3564: Prepared CLOSE handling for modularization. - Tim Just