[hipl-commit] [tiny] Rev 3642: Further unification of packet handling in daemon main loop.

  • From: Tim Just <tim.just@xxxxxxxxxxxxxx>
  • To: hipl-commit@xxxxxxxxxxxxx
  • Date: Tue, 9 Mar 2010 16:58:26 +0200

Committer: Tim Just <tim.just@xxxxxxxxxxxxxx>
Date: Tue Mar 09 15:57:05 2010 +0100
Revision: 3642
Revision-id: tim.just@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Branch nick: tiny

Log:
  Further unification of packet handling in daemon main loop.

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

=== modified file 'hipd/hipd.c'
--- hipd/hipd.c 2010-03-09 14:14:54 +0000
+++ hipd/hipd.c 2010-03-09 14:57:05 +0000
@@ -403,10 +403,7 @@
                                         0)) {
                 HIP_ERROR("Reading network msg failed\n");
             } else {
-                err = hip_receive_control_packet(packet_ctx.input_msg,
-                                                 packet_ctx.src_addr,
-                                                 packet_ctx.dst_addr,
-                                                 packet_ctx.msg_ports);
+                err = hip_receive_control_packet(&packet_ctx);
                 if (err) {
                     HIP_ERROR("hip_receive_control_packet()!\n");
                 }
@@ -428,10 +425,7 @@
                                         IPV4_HDR_SIZE)) {
                 HIP_ERROR("Reading network msg failed\n");
             } else {
-                err = hip_receive_control_packet(packet_ctx.input_msg,
-                                                 packet_ctx.src_addr,
-                                                 packet_ctx.dst_addr,
-                                                 packet_ctx.msg_ports);
+                err = hip_receive_control_packet(&packet_ctx);
                 if (err) {
                     HIP_ERROR("hip_receive_control_packet()!\n");
                 }
@@ -460,10 +454,7 @@
                 /* If the values were read in successfully, we
                  * do the UDP specific stuff next. */
             } else {
-                err =  hip_receive_udp_control_packet(packet_ctx.input_msg,
-                                                      packet_ctx.src_addr,
-                                                      packet_ctx.dst_addr,
-                                                      packet_ctx.msg_ports);
+                err =  hip_receive_udp_control_packet(&packet_ctx);
             }
         }
 

=== modified file 'hipd/hiprelay.c'
--- hipd/hiprelay.c     2010-03-05 17:28:01 +0000
+++ hipd/hiprelay.c     2010-03-09 14:57:05 +0000
@@ -244,15 +244,6 @@
     return hash;
 }
 
-static int hip_relay_forward_response(const hip_common_t *r,
-                                      const uint8_t type_hdr,
-                                      const in6_addr_t *r_saddr,
-                                      const in6_addr_t *r_daddr,
-                                      const hip_portpair_t *r_info,
-                                      const in6_addr_t *relay_to_addr,
-                                      const in_port_t relay_to_port);
-
-
 static void hip_relht_rec_free_type_doall_arg(hip_relrec_t *rec, const 
hip_relrec_type_t *type)
 {
     hip_relrec_t *fetch_record = hip_relht_get(rec);
@@ -880,73 +871,6 @@
  *           No lines over 80 characters. No capital letters in funcion names
  *           (C-style). Function commmends should be in header file.
  */
-int hip_relay_handle_relay_to(struct hip_common *msg,
-                              int msg_type,
-                              struct in6_addr *src_addr,
-                              struct in6_addr *dst_addr,
-                              hip_portpair_t *msg_info)
-{
-    int err           = 0;
-    hip_relrec_t *rec = NULL, dummy;
-    struct hip_relay_to *relay_to;
-    //check if full relay service is active
-
-    if (hip_relay_get_status() == HIP_RELAY_OFF) {
-        /* Should we set err to -1? */
-        goto out_err;
-    }
-
-    HIP_DEBUG("handle_relay_to: full relay is on\n");
-    // check if the relay has been registered
-
-    /* Check if we have a relay record in our database matching the
-     * I's HIT. We should find one, if the I is
-     * registered to relay.*/
-    HIP_DEBUG_HIT("Searching relay record on HIT:", &msg->hits);
-    memcpy(&(dummy.hit_r), &msg->hits, sizeof(msg->hits));
-    rec = hip_relht_get(&dummy);
-
-    if (rec == NULL) {
-        HIP_DEBUG("handle_relay_to: No matching relay record found.\n");
-        goto out_err;
-    } else if (rec->type == HIP_RVSRELAY) {
-        goto out_err;
-    }
-
-    HIP_DEBUG("handle_relay_to: Matching relay record found:Full-Relay.\n");
-
-    //check if there is a relay_to parameter
-    relay_to = (struct hip_relay_to *) hip_get_param(msg, HIP_PARAM_RELAY_TO);
-    HIP_IFEL(!relay_to, 0, "No relay_to  found\n");
-
-    // check msg type
-    switch (msg_type) {
-    case HIP_R1:
-    case HIP_R2:
-    case HIP_UPDATE:
-    case HIP_NOTIFY:
-        HIP_DEBUG_IN6ADDR("the relay to address: ",
-                          (struct in6_addr *) &relay_to->address);
-        HIP_DEBUG("the relay to ntohs(port): %d",
-                  ntohs(relay_to->port));
-        hip_relay_forward_response(
-            msg, msg_type, src_addr, dst_addr, msg_info,
-            (in6_addr_t *) &relay_to->address, ntohs(relay_to->port));
-        //  state = HIP_STATE_NONE;
-        err = 1;
-        goto out_err;
-    }
-
-out_err:
-    return err;
-}
-
-/**
- * @todo     Xiang! Please, add decent Doxygen comments, check the doxy syntax
- *           from doc/HACKING. Stick to C-coding style using LINUX indendation.
- *           No lines over 80 characters. No capital letters in funcion names
- *           (C-style). Function commmends should be in header file.
- */
 static int hip_relay_forward_response(const hip_common_t *r,
                                       const uint8_t type_hdr,
                                       const in6_addr_t *r_saddr,
@@ -998,6 +922,77 @@
     return err;
 }
 
+/**
+ * @todo     Xiang! Please, add decent Doxygen comments, check the doxy syntax
+ *           from doc/HACKING. Stick to C-coding style using LINUX indendation.
+ *           No lines over 80 characters. No capital letters in funcion names
+ *           (C-style). Function commmends should be in header file.
+ */
+int hip_relay_handle_relay_to(const uint8_t packet_type,
+                              const uint32_t ha_state,
+                              struct hip_packet_context *packet_ctx)
+{
+    int err           = 0;
+    hip_relrec_t *rec = NULL, dummy;
+    struct hip_relay_to *relay_to;
+    //check if full relay service is active
+
+    if (hip_relay_get_status() == HIP_RELAY_OFF) {
+        /* Should we set err to -1? */
+        goto out_err;
+    }
+
+    HIP_DEBUG("handle_relay_to: full relay is on\n");
+    // check if the relay has been registered
+
+    /* Check if we have a relay record in our database matching the
+     * I's HIT. We should find one, if the I is
+     * registered to relay.*/
+    HIP_DEBUG_HIT("Searching relay record on HIT:",
+                  &packet_ctx->input_msg->hits);
+
+    memcpy(&(dummy.hit_r), &packet_ctx->input_msg->hits, 
sizeof(packet_ctx->input_msg->hits));
+    rec = hip_relht_get(&dummy);
+
+    if (rec == NULL) {
+        HIP_DEBUG("handle_relay_to: No matching relay record found.\n");
+        goto out_err;
+    } else if (rec->type == HIP_RVSRELAY) {
+        goto out_err;
+    }
+
+    HIP_DEBUG("handle_relay_to: Matching relay record found:Full-Relay.\n");
+
+    //check if there is a relay_to parameter
+    relay_to = (struct hip_relay_to *) hip_get_param(packet_ctx->input_msg, 
HIP_PARAM_RELAY_TO);
+    HIP_IFEL(!relay_to, 0, "No relay_to  found\n");
+
+    // check msg type
+    switch (packet_type) {
+    case HIP_R1:
+    case HIP_R2:
+    case HIP_UPDATE:
+    case HIP_NOTIFY:
+        HIP_DEBUG_IN6ADDR("the relay to address: ",
+                          (struct in6_addr *) &relay_to->address);
+        HIP_DEBUG("the relay to ntohs(port): %d",
+                  ntohs(relay_to->port));
+        hip_relay_forward_response(packet_ctx->input_msg,
+                                   packet_type,
+                                   packet_ctx->src_addr,
+                                   packet_ctx->dst_addr,
+                                   packet_ctx->msg_ports,
+                                   (in6_addr_t *) &relay_to->address,
+                                   ntohs(relay_to->port));
+        //  state = HIP_STATE_NONE;
+        err = 1;
+        goto out_err;
+    }
+
+out_err:
+    return err;
+}
+
 int hip_relay_add_rvs_to_ha(hip_common_t *source_msg, hip_ha_t *entry)
 {
     struct hip_via_rvs *via_rvs = NULL;

=== modified file 'hipd/hiprelay.h'
--- hipd/hiprelay.h     2010-03-05 17:28:01 +0000
+++ hipd/hiprelay.h     2010-03-09 14:57:05 +0000
@@ -479,11 +479,9 @@
                                         hip_ha_t *entry);
 
 
-int hip_relay_handle_relay_to(struct hip_common *msg,
-                              int msg_type,
-                              struct in6_addr *src_addr,
-                              struct in6_addr *dst_addr,
-                              hip_portpair_t *msg_info);
+int hip_relay_handle_relay_to(const uint8_t packet_type,
+                              const uint32_t ha_state,
+                              struct hip_packet_context *packet_ctx);
 
 /**
  * function for full relay service. from I to R

=== modified file 'hipd/input.c'
--- hipd/input.c        2010-03-08 15:47:13 +0000
+++ hipd/input.c        2010-03-09 14:57:05 +0000
@@ -505,14 +505,10 @@
  * @param info  a pointer to the source and destination ports.
  * @return      zero on success, or negative error value on error.
  */
-int hip_receive_control_packet(struct hip_common *msg,
-                               struct in6_addr *src_addr,
-                               struct in6_addr *dst_addr,
-                               hip_portpair_t *msg_info)
+int hip_receive_control_packet(struct hip_packet_context *packet_ctx)
 {
     int err = 0;
     struct in6_addr ipv6_any_addr = IN6ADDR_ANY_INIT;
-    struct hip_packet_context ctx = {0};
     uint32_t type, state;
 
     /* Debug printing of received packet information. All received HIP
@@ -520,64 +516,67 @@
      * printing packet data here works for all packets. To avoid excessive
      * debug printing do not print this information inside the individual
      * receive or handle functions. */
-    HIP_DEBUG_HIT("HIT Sender  ", &msg->hits);
-    HIP_DEBUG_HIT("HIT Receiver", &msg->hitr);
+    HIP_DEBUG_HIT("HIT Sender  ", &packet_ctx->input_msg->hits);
+    HIP_DEBUG_HIT("HIT Receiver", &packet_ctx->input_msg->hitr);
     HIP_DEBUG("source port: %u, destination port: %u\n",
-              msg_info->src_port, msg_info->dst_port);
-    HIP_DUMP_MSG(msg);
-
-    if (hip_hidb_hit_is_our(&msg->hits) &&
-        (IN6_ARE_ADDR_EQUAL(&msg->hitr, &msg->hits) ||
-         IN6_ARE_ADDR_EQUAL(&msg->hitr, &ipv6_any_addr)) &&
-        !hip_addr_is_loopback(dst_addr) &&
-        !hip_addr_is_loopback(src_addr) &&
-        !IN6_ARE_ADDR_EQUAL(src_addr, dst_addr)) {
+              packet_ctx->msg_ports->src_port,
+              packet_ctx->msg_ports->dst_port);
+
+    HIP_DUMP_MSG(packet_ctx->input_msg);
+
+    if (hip_hidb_hit_is_our(&packet_ctx->input_msg->hits) &&
+        (IN6_ARE_ADDR_EQUAL(&packet_ctx->input_msg->hitr,
+                            &packet_ctx->input_msg->hits) ||
+         IN6_ARE_ADDR_EQUAL(&packet_ctx->input_msg->hitr,
+                            &ipv6_any_addr)) &&
+        !hip_addr_is_loopback(packet_ctx->dst_addr) &&
+        !hip_addr_is_loopback(packet_ctx->src_addr) &&
+        !IN6_ARE_ADDR_EQUAL(packet_ctx->src_addr, packet_ctx->dst_addr)) {
         HIP_DEBUG("Invalid loopback packet. Dropping.\n");
         goto out_err;
     }
 
-    HIP_IFEL(hip_check_network_msg(msg),
+    HIP_IFEL(hip_check_network_msg(packet_ctx->input_msg),
              -1,
              "Checking control message failed.\n");
 
-    type  = hip_get_msg_type(msg);
+    type  = hip_get_msg_type(packet_ctx->input_msg);
 
     /** @todo Check packet csum.*/
 
-    ctx.hadb_entry = hip_hadb_find_byhits(&msg->hits, &msg->hitr);
+    packet_ctx->hadb_entry = hip_hadb_find_byhits(&packet_ctx->input_msg->hits,
+                                                  
&packet_ctx->input_msg->hitr);
 
     // Check if we need to drop the packet
-    if (ctx.hadb_entry &&
-        hip_packet_to_drop(ctx.hadb_entry, type, &msg->hitr) == 1) {
+    if (packet_ctx->hadb_entry &&
+        hip_packet_to_drop(packet_ctx->hadb_entry,
+                           type,
+                           &packet_ctx->input_msg->hitr) == 1) {
         HIP_DEBUG("Ignoring the packet sent.\n");
         err = -1;
         goto out_err;
     }
 
-    ctx.input_msg = msg;
-    ctx.src_addr  = src_addr;
-    ctx.dst_addr  = dst_addr;
-    ctx.msg_ports = msg_info;
-
-    if (ctx.hadb_entry) {
-        state = ctx.hadb_entry->state;
+    if (packet_ctx->hadb_entry) {
+        state = packet_ctx->hadb_entry->state;
     } else {
         state = HIP_STATE_NONE;
     }
 
 #ifdef CONFIG_HIP_OPPORTUNISTIC
-    if (!ctx.hadb_entry && opportunistic_mode &&
+    if (!packet_ctx->hadb_entry && opportunistic_mode &&
         (type == HIP_I1 || type == HIP_R1)) {
-        ctx.hadb_entry = hip_oppdb_get_hadb_entry_i1_r1(msg,
-                                               src_addr,
-                                               dst_addr,
-                                               msg_info);
+        packet_ctx->hadb_entry =
+                hip_oppdb_get_hadb_entry_i1_r1(packet_ctx->input_msg,
+                                               packet_ctx->src_addr,
+                                               packet_ctx->dst_addr,
+                                               packet_ctx->msg_ports);
     }
 #endif
 
 #ifdef CONFIG_HIP_RVS
     /* check if it a relaying msg */
-    if (hip_relay_handle_relay_to(msg, type, src_addr, dst_addr, msg_info)) {
+    if (hip_relay_handle_relay_to(type, state, packet_ctx)) {
         err = -ECANCELED;
         goto out_err;
     } else {
@@ -585,7 +584,7 @@
     }
 #endif
 
-    hip_run_handle_functions(type, state, &ctx);
+    hip_run_handle_functions(type, state, packet_ctx);
 
 #ifdef CONFIG_HIP_PERFORMANCE
     HIP_DEBUG("Write PERF_SIGN, PERF_DSA_SIGN_IMPL, PERF_RSA_SIGN_IMPL," \
@@ -630,19 +629,16 @@
  * @param info  a pointer to the source and destination ports.
  * @return      zero on success, or negative error value on error.
  */
-int hip_receive_udp_control_packet(struct hip_common *msg,
-                                   struct in6_addr *saddr,
-                                   struct in6_addr *daddr,
-                                   hip_portpair_t *info)
+int hip_receive_udp_control_packet(struct hip_packet_context *packet_ctx)
 {
-    hip_ha_t *entry;
-    int err                       = 0, type;
-    struct in6_addr *saddr_public = saddr;
+    int err         = 0, type;
+    hip_ha_t *entry = NULL;
 
     _HIP_DEBUG("hip_nat_receive_udp_control_packet() invoked.\n");
 
-    type  = hip_get_msg_type(msg);
-    entry = hip_hadb_find_byhits(&msg->hits, &msg->hitr);
+    type  = hip_get_msg_type(packet_ctx->input_msg);
+    entry = hip_hadb_find_byhits(&packet_ctx->input_msg->hits,
+                                 &packet_ctx->input_msg->hitr);
 
 #ifndef CONFIG_HIP_RVS
     /* The ip of RVS is taken to be ip of the peer while using RVS server
@@ -657,10 +653,10 @@
          * used for setting up the SAs: handle_r1 creates one-way SA and
          * handle_i2 the other way; let's make sure that they are the
          * same. */
-        saddr_public = &entry->peer_addr;
+        packet_ctx->src_addr = &entry->peer_addr;
     }
 #endif
-    HIP_IFEL(hip_receive_control_packet(msg, saddr_public, daddr, info), -1,
+    HIP_IFEL(hip_receive_control_packet(packet_ctx), -1,
              "receiving of control packet failed\n");
 out_err:
     return err;

=== modified file 'hipd/input.h'
--- hipd/input.h        2010-03-08 09:44:30 +0000
+++ hipd/input.h        2010-03-09 14:57:05 +0000
@@ -76,15 +76,9 @@
 int hip_verify_packet_rvs_hmac(struct hip_common *msg,
                                struct hip_crypto_key *crypto_key);
 
-int hip_receive_control_packet(struct hip_common *msg,
-                               struct in6_addr *src_addr,
-                               struct in6_addr *dst_addr,
-                               hip_portpair_t *msg_info);
+int hip_receive_control_packet(struct hip_packet_context *packet_ctx);
 
-int hip_receive_udp_control_packet(struct hip_common *msg,
-                                   struct in6_addr *saddr,
-                                   struct in6_addr *daddr,
-                                   hip_portpair_t *info);
+int hip_receive_udp_control_packet(struct hip_packet_context *packet_ctx);
 
 int hip_handle_i1(const uint8_t packet_type,
                   const uint32_t ha_state,

Other related posts:

  • » [hipl-commit] [tiny] Rev 3642: Further unification of packet handling in daemon main loop. - Tim Just