[hipl-commit] [trunk] Rev 4711: Restored registration code

  • From: Artturi Karila <artturi.karila@xxxxxxxxxx>
  • To: hipl-commit@xxxxxxxxxxxxx
  • Date: Fri, 4 Jun 2010 15:18:01 +0300

Committer: Artturi Karila <artturi.karila@xxxxxxxxxx>
Date: 04/06/2010 at 15:18:01
Revision: 4711
Revision-id: artturi.karila@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Branch nick: trunk

Log:
  Restored registration code
  
  The REG_REQUEST parameter was not being included in I2. Restored code from 
r4608 to make registration work again.

Modified:
  M  hipd/registration.c

=== modified file 'hipd/registration.c'
--- hipd/registration.c 2010-06-01 15:11:59 +0000
+++ hipd/registration.c 2010-06-04 12:18:01 +0000
@@ -304,6 +304,68 @@
 }
 
 /**
+ * Gets all pending requests for given host association. Gets all pending
+ * requests for host association @c entry.
+ *
+ * Make sure that the target buffer @c requests has room for at least as many
+ * pending requests that the host association @c entry has currently. You can
+ * have this number by calling hip_get_pending_request_count().
+ *
+ * @param  entry    a pointer to a host association whose pending requests are
+ *                  to be get.
+ * @param  requests a target buffer for the pending requests.
+ * @return          -1 if @c requests is NULL or if no pending requests were
+ *                  found, zero otherwise.
+ * @see             hip_get_pending_request_count().
+ */
+static int hip_get_pending_requests(hip_ha_t *entry, hip_pending_request_t 
*requests[])
+{
+    if (requests == NULL) {
+        return -1;
+    }
+
+    hip_ll_node_t *iter = 0;
+    int request_count   = 0;
+
+    while ((iter = hip_ll_iterate(&pending_requests, iter)) != NULL) {
+        if (((hip_pending_request_t *) (iter->ptr))->entry
+            == entry) {
+            requests[request_count] =
+                (hip_pending_request_t *) (iter->ptr);
+            request_count++;
+        }
+    }
+
+    if (request_count == 0) {
+        return -1;
+    }
+
+    return 0;
+}
+
+/**
+ * Gets the number of pending requests for a given host association.
+ *
+ * @param  entry a pointer to a host association whose count of pending 
requests
+ *               is to be get.
+ * @return       the number of pending requests for the host association.
+ */
+static int hip_get_pending_request_count(hip_ha_t *entry)
+{
+    hip_ll_node_t *iter = 0;
+    int request_count   = 0;
+
+    while ((iter = hip_ll_iterate(&pending_requests, iter)) != NULL) {
+        if (((hip_pending_request_t *) (iter->ptr))->entry
+            == entry) {
+            request_count++;
+        }
+    }
+
+    return request_count;
+}
+
+/**
  * Handles param REG_INFO. Digs out the REG_INFO parameter from the HIP message
  * @c source_msg, sets the peer control bits accordingly and builds REG_REQUEST
  * in response to the HIP message @c target_msg. The peer controls are set to
@@ -384,6 +446,67 @@
         }
     }
 
+    /* This far we have stored the information of what services the server
+     * offers. Next we check if we have requested any of those services from
+     * command line using hipconf. If we have requested, we have pending
+     * requests stored. We build a REG_REQUEST parameter containing each
+     * service that we have requested and the server offers. */
+
+    if (entry->local_controls & HIP_HA_CTRL_LOCAL_REQ_ANY) {
+        int request_count = hip_get_pending_request_count(entry);
+        if (request_count > 0) {
+            int j = 0, types_to_request = 0;
+            uint8_t type_array[request_count], valid_lifetime = 0;
+            hip_pending_request_t *requests[request_count];
+
+            i = 0;
+            hip_get_pending_requests(entry, requests);
+
+            /* If we have requested for a cancellation of a service
+             * we use lifetime of zero. Otherwise we must check
+             * that the requested lifetime falls between the offered
+             * lifetime boundaries. */
+            if (requests[0]->lifetime == 0) {
+                HIP_DEBUG("SERVICE CANCELATION \n");
+                valid_lifetime = 0;
+            } else {
+                valid_lifetime = MIN(requests[0]->lifetime,
+                                     reg_info->max_lifetime);
+                valid_lifetime = MAX(valid_lifetime,
+                                     reg_info->min_lifetime);
+            }
+
+            /* Copy the Reg Types to an array. Outer loop for the
+             * services we have requested, inner loop for the
+             * services the server offers. */
+            for (i = 0; i < request_count; i++) {
+                for (j = 0; j < type_count; j++) {
+                    if (requests[i]->reg_type ==
+                        reg_types[j]) {
+                        type_array[types_to_request] =
+                            requests[i]->reg_type;
+
+                        types_to_request++;
+                        break;
+                    }
+                }
+            }
+            HIP_DEBUG("VALID SERVICE LIFETIME %d\n", valid_lifetime);
+            if (types_to_request > 0) {
+                HIP_IFEL(hip_build_param_reg_request(
+                             target_msg, valid_lifetime,
+                             type_array, types_to_request),
+                         -1,
+                         "Failed to build a REG_REQUEST " \
+                         "parameter.\n");
+            }
+        }
+        /* We do not delete the pending requests for this entry yet, but
+         * only after R2 has arrived. We do not need pending requests
+         * when R2 arrives, but in case the I2 is to be retransmitted,
+         * we must be able to produce the REG_REQUEST parameter. */
+    }
+
 out_err:
     return err;
 }

Other related posts:

  • » [hipl-commit] [trunk] Rev 4711: Restored registration code - Artturi Karila