[hipl-commit] [tiny] Rev 3637: First step on HEARTBEAT modularization.

  • From: Tim Just <tim.just@xxxxxxxxxxxxxx>
  • To: hipl-commit@xxxxxxxxxxxxx
  • Date: Mon, 8 Mar 2010 17:50:27 +0200

Committer: Tim Just <tim.just@xxxxxxxxxxxxxx>
Date: Mon Mar 08 16:47:13 2010 +0100
Revision: 3637
Revision-id: tim.just@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Branch nick: tiny

Log:
  First step on HEARTBEAT modularization.
  
  Created a new module HEARTBEAT. The optional functionality of sending 
  heartbeats per ICMP socket will be encapsulated in this module. Right
  now the sending of heartbeats should work, but the receiving not.
  
  This will be fixed as soon as the socket handling is modularized.
  
  The function set_cloexec_flag was renamed to hip_set_cloexec_flag and is
  not static anymore. This function is neede by the heartbeat module.

Modified:
  A  modules/heartbeat/
  A  modules/heartbeat/Makefile.am
  A  modules/heartbeat/hipd/
  A  modules/heartbeat/module_info.xml
  R  hipd/heartbeat.c => modules/heartbeat/hipd/heartbeat.c
  R  hipd/heartbeat.h => modules/heartbeat/hipd/heartbeat.h
  M  Makefile.am
  M  hipd/hadb.c
  M  hipd/hipd.c
  M  hipd/hipd.h
  M  hipd/init.c
  M  hipd/init.h
  M  hipd/input.c
  M  hipd/maintenance.c
  M  hipd/maintenance.h
  M  hipd/output.c
  M  hipd/user.c
  M  modules/update/hipd/update.c
  M  modules/heartbeat/hipd/heartbeat.c
  M  modules/heartbeat/hipd/heartbeat.h

=== modified file 'Makefile.am'
--- Makefile.am 2010-03-05 18:11:38 +0000
+++ Makefile.am 2010-03-08 15:47:13 +0000
@@ -101,8 +101,7 @@
                     hipd/esp_prot_light_update.c \
                     hipd/nsupdate.c \
                     hipd/hit_to_ip.c \
-                    hipd/hadb_legacy.c \
-                    hipd/heartbeat.c
+                    hipd/hadb_legacy.c
 
 if HIP_PFKEY
 hipd_hipd_SOURCES += hipd/pfkeyapi.c

=== modified file 'hipd/hadb.c'
--- hipd/hadb.c 2010-03-05 18:40:53 +0000
+++ hipd/hadb.c 2010-03-08 15:47:13 +0000
@@ -1221,15 +1221,16 @@
     ipv4_addr_copy(&hid.lsi_peer, &entry->lsi_peer);
     memcpy(&hid.peer_hostname, &entry->peer_hostname, 
HIP_HOST_ID_HOSTNAME_LEN_MAX);
 
+    /** @todo Modularize heartbeat */
+#if 0
     hid.heartbeats_on       = hip_icmp_interval;
     calc_statistics(&entry->heartbeats_statistics, (uint32_t *) 
&hid.heartbeats_received, NULL, NULL,
                     &hid.heartbeats_mean, &hid.heartbeats_variance, 
STATS_IN_MSECS);
-#if 0
     hid.heartbeats_mean     = entry->heartbeats_mean;
     hid.heartbeats_variance = entry->heartbeats_variance;
     hid.heartbeats_received = entry->heartbeats_statistics.num_items;
-#endif
     hid.heartbeats_sent     = entry->heartbeats_sent;
+#endif
 
     /*For some reason this gives negative result*/
     /*hip_timeval_diff(&entry->bex_start,

=== modified file 'hipd/hipd.c'
--- hipd/hipd.c 2010-03-05 17:28:01 +0000
+++ hipd/hipd.c 2010-03-08 15:47:13 +0000
@@ -15,7 +15,6 @@
 #endif /* HAVE_CONFIG_H */
 
 #include "hipd.h"
-#include "heartbeat.h"
 
 #ifdef CONFIG_HIP_PERFORMANCE
 #include "lib/performance/performance.h"
@@ -59,10 +58,6 @@
  *  machine is behind a NAT. */
 hip_transform_suite_t hip_nat_status = 0;
 
-/** ICMPv6 socket and the interval 0 for interval means off */
-int hip_icmp_sock                    = 0;
-int hip_icmp_interval                = HIP_NAT_KEEP_ALIVE_INTERVAL;
-
 /* Encrypt host id in I2 */
 int hip_encrypt_i2_hi                = 0;
 
@@ -336,14 +331,14 @@
     HIP_IFEL(create_configs_and_exit, 0,
              "Configs created, exiting\n");
 
-    highest_descriptor = maxof(7,
+    highest_descriptor = maxof(6,
                                hip_nl_route.fd,
                                hip_raw_sock_input_v6,
                                hip_user_sock,
                                hip_nl_ipsec.fd,
                                hip_raw_sock_input_v4,
-                               hip_nat_sock_input_udp,
-                               hip_icmp_sock);
+                               hip_nat_sock_input_udp);
+//                               hip_icmp_sock);
 
     /* Allocate user message. */
     HIP_IFE(!(hipd_msg = hip_msg_alloc()), 1);
@@ -365,7 +360,7 @@
         FD_SET(hip_nat_sock_input_udp, &read_fdset);
         FD_SET(hip_user_sock, &read_fdset);
         FD_SET(hip_nl_ipsec.fd, &read_fdset);
-        FD_SET(hip_icmp_sock, &read_fdset);
+        //FD_SET(hip_icmp_sock, &read_fdset);
         /* FD_SET(hip_firewall_sock, &read_fdset); */
         hip_firewall_sock = hip_user_sock;
 
@@ -499,10 +494,10 @@
             }
         }
 
-        if (FD_ISSET(hip_icmp_sock, &read_fdset)) {
-            HIP_IFEL(hip_icmp_recvmsg(hip_icmp_sock), -1,
-                     "Failed to recvmsg from ICMPv6\n");
-        }
+//        if (FD_ISSET(hip_icmp_sock, &read_fdset)) {
+//            HIP_IFEL(hip_icmp_recvmsg(hip_icmp_sock), -1,
+//                     "Failed to recvmsg from ICMPv6\n");
+//        }
 
         if (FD_ISSET(hip_nat_sock_input_udp, &read_fdset)) {
             /* Data structures for storing the source and

=== modified file 'hipd/hipd.h'
--- hipd/hipd.h 2010-03-05 17:28:01 +0000
+++ hipd/hipd.h 2010-03-08 15:47:13 +0000
@@ -104,9 +104,6 @@
 
 extern int hip_shotgun_status;
 
-extern int hip_icmp_sock;
-extern int hip_icmp_interval;
-
 extern int hip_encrypt_i2_hi;
 
 extern struct addrinfo *opendht_serving_gateway;

=== modified file 'hipd/init.c'
--- hipd/init.c 2010-03-05 19:14:35 +0000
+++ hipd/init.c 2010-03-08 15:47:13 +0000
@@ -99,24 +99,6 @@
     }
 }
 
-static int set_cloexec_flag(int desc, int value)
-{
-    int oldflags = fcntl(desc, F_GETFD, 0);
-    /* If reading the flags failed, return error indication now.*/
-    if (oldflags < 0) {
-        return oldflags;
-    }
-    /* Set just the flag we want to set. */
-
-    if (value != 0) {
-        oldflags |= FD_CLOEXEC;
-    } else {
-        oldflags &= ~FD_CLOEXEC;
-    }
-    /* Store modified flag word in the descriptor. */
-    return fcntl(desc, F_SETFD, oldflags);
-}
-
 #ifndef CONFIG_HIP_OPENWRT
 #ifdef CONFIG_HIP_DEBUG
 static void hip_print_sysinfo(void)
@@ -309,7 +291,7 @@
     int off = 0;
 
     *hip_raw_sock_v4 = socket(AF_INET, SOCK_RAW, proto);
-    set_cloexec_flag(*hip_raw_sock_v4, 1);
+    hip_set_cloexec_flag(*hip_raw_sock_v4, 1);
     HIP_IFEL(*hip_raw_sock_v4 <= 0, 1, "Raw socket v4 creation failed. Not 
root?\n");
 
     /* see bug id 212 why RECV_ERR is off */
@@ -327,35 +309,6 @@
 }
 
 /**
- * Initialize icmpv6 socket.
- */
-static int hip_init_icmp_v6(int *icmpsockfd)
-{
-    int err = 0, on = 1;
-    struct icmp6_filter filter;
-
-    /* Make sure that hipd does not send icmpv6 immediately after base 
exchange */
-    heartbeat_counter = hip_icmp_interval;
-
-    *icmpsockfd       = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
-    set_cloexec_flag(*icmpsockfd, 1);
-    HIP_IFEL(*icmpsockfd <= 0, 1, "ICMPv6 socket creation failed\n");
-
-    ICMP6_FILTER_SETBLOCKALL(&filter);
-    ICMP6_FILTER_SETPASS(ICMP6_ECHO_REPLY, &filter);
-    err = setsockopt(*icmpsockfd, IPPROTO_ICMPV6, ICMP6_FILTER, &filter,
-                     sizeof(struct icmp6_filter));
-    HIP_IFEL(err, -1, "setsockopt icmp ICMP6_FILTER failed\n");
-
-
-    err = setsockopt(*icmpsockfd, IPPROTO_IPV6, IPV6_2292PKTINFO, &on, 
sizeof(on));
-    HIP_IFEL(err, -1, "setsockopt icmp IPV6_RECVPKTINFO failed\n");
-
-out_err:
-    return err;
-}
-
-/**
  * Probe kernel modules.
  */
 
@@ -633,7 +586,6 @@
     HIP_IFEL(hip_init_raw_sock_v6(&hip_raw_sock_input_v6, IPPROTO_HIP), -1, 
"raw sock input v6\n");
     HIP_IFEL(hip_init_raw_sock_v4(&hip_raw_sock_input_v4, IPPROTO_HIP), -1, 
"raw sock input v4\n");
     HIP_IFEL(hip_create_nat_sock_udp(&hip_nat_sock_input_udp, 0, 0), -1, "raw 
sock input udp\n");
-    HIP_IFEL(hip_init_icmp_v6(&hip_icmp_sock), -1, "icmpv6 sock\n");
 
     HIP_DEBUG("hip_raw_sock_v6 input = %d\n", hip_raw_sock_input_v6);
     HIP_DEBUG("hip_raw_sock_v6 output = %d\n", hip_raw_sock_output_v6);
@@ -641,7 +593,6 @@
     HIP_DEBUG("hip_raw_sock_v4 output = %d\n", hip_raw_sock_output_v4);
     HIP_DEBUG("hip_nat_sock_udp input = %d\n", hip_nat_sock_input_udp);
     HIP_DEBUG("hip_nat_sock_udp output = %d\n", hip_nat_sock_output_udp);
-    HIP_DEBUG("hip_icmp_sock = %d\n", hip_icmp_sock);
 
     if (flush_ipsec) {
         hip_flush_all_sa();
@@ -675,7 +626,7 @@
     daemon_addr.sin6_family = AF_INET6;
     daemon_addr.sin6_port   = htons(HIP_DAEMON_LOCAL_PORT);
     daemon_addr.sin6_addr   = in6addr_loopback;
-    set_cloexec_flag(hip_user_sock, 1);
+    hip_set_cloexec_flag(hip_user_sock, 1);
 
     HIP_IFEL(bind(hip_user_sock, (struct sockaddr *) &daemon_addr,
                   sizeof(daemon_addr)), -1,
@@ -829,7 +780,7 @@
     int on = 1, off = 0, err = 0;
 
     *hip_raw_sock_v6 = socket(AF_INET6, SOCK_RAW, proto);
-    set_cloexec_flag(*hip_raw_sock_v6, 1);
+    hip_set_cloexec_flag(*hip_raw_sock_v6, 1);
     HIP_IFEL(*hip_raw_sock_v6 <= 0, 1, "Raw socket creation failed. Not 
root?\n");
 
     /* see bug id 212 why RECV_ERR is off */
@@ -844,6 +795,34 @@
     return err;
 }
 
+int hip_set_cloexec_flag(int desc, int value)
+{
+    int oldflags = fcntl(desc, F_GETFD, 0);
+    /* If reading the flags failed, return error indication now.*/
+    if (oldflags < 0) {
+        return oldflags;
+    }
+    /* Set just the flag we want to set. */
+
+    if (value != 0) {
+        oldflags |= FD_CLOEXEC;
+    } else {
+        oldflags &= ~FD_CLOEXEC;
+    }
+    /* Store modified flag word in the descriptor. */
+    return fcntl(desc, F_SETFD, oldflags);
+}
+
+/**
+ * Creates a UDP socket for NAT traversal.
+ *
+ * @param  hip_nat_sock_udp a pointer to the UDP socket.
+ * @param sockaddr_in the address that will be used to create the
+ *                 socket. If NULL is passed, INADDR_ANY is used.
+ * @param is_output 1 if the socket is for output, otherwise 0
+ *
+ * @return zero on success, negative error value on error.
+ */
 int hip_create_nat_sock_udp(int *hip_nat_sock_udp,
                             struct sockaddr_in *addr,
                             int is_output)
@@ -867,7 +846,7 @@
         HIP_ERROR("Can not open socket for UDP\n");
         return -1;
     }
-    set_cloexec_flag(*hip_nat_sock_udp, 1);
+    hip_set_cloexec_flag(*hip_nat_sock_udp, 1);
     err = setsockopt(*hip_nat_sock_udp, IPPROTO_IP, IP_PKTINFO, &on, 
sizeof(on));
     HIP_IFEL(err, -1, "setsockopt udp pktinfo failed\n");
     /* see bug id 212 why RECV_ERR is off */
@@ -908,7 +887,6 @@
     }
 
     HIP_DEBUG_INADDR("UDP socket created and bound to addr", (struct in_addr 
*) &myaddr.sin_addr.s_addr);
-    //return 0;
 
 out_err:
     return err;

=== modified file 'hipd/init.h'
--- hipd/init.h 2010-03-05 17:28:01 +0000
+++ hipd/init.h 2010-03-08 15:47:13 +0000
@@ -31,16 +31,9 @@
 int hip_associate_default_hit_lsi(void);
 
 int hipd_init(int flush_ipsec, int killold);
-/**
- * Creates a UDP socket for NAT traversal.
- *
- * @param  hip_nat_sock_udp a pointer to the UDP socket.
- * @param sockaddr_in the address that will be used to create the
- *                 socket. If NULL is passed, INADDR_ANY is used.
- * @param is_output 1 if the socket is for output, otherwise 0
- *
- * @return zero on success, negative error value on error.
- */
+
+int hip_set_cloexec_flag(int desc, int value);
+
 int hip_create_nat_sock_udp(int *hip_nat_sock_udp,
                             struct sockaddr_in *addr,
                             int is_output);

=== modified file 'hipd/input.c'
--- hipd/input.c        2010-03-08 09:44:30 +0000
+++ hipd/input.c        2010-03-08 15:47:13 +0000
@@ -1779,12 +1779,6 @@
                HIP_MAX_NETWORK_PACKET);
     }
 
-    /* Send the first heartbeat. Notice that the error is ignored to complete
-     * the base exchange successfully. */
-    if (hip_icmp_interval > 0) {
-        hip_send_icmp(hip_icmp_sock, packet_ctx->hadb_entry);
-    }
-
 out_err:
     if (packet_ctx->hadb_entry->state == HIP_STATE_ESTABLISHED) {
         HIP_DEBUG("Send response to firewall.\n");

=== modified file 'hipd/maintenance.c'
--- hipd/maintenance.c  2010-03-05 17:28:01 +0000
+++ hipd/maintenance.c  2010-03-08 15:47:13 +0000
@@ -19,7 +19,6 @@
 
 #include "maintenance.h"
 #include "modularization.h"
-#include "heartbeat.h"
 
 #define FORCE_EXIT_COUNTER_START                5
 
@@ -33,7 +32,6 @@
 float queue_counter          = QUEUE_CHECK_INIT;
 int force_exit_counter       = FORCE_EXIT_COUNTER_START;
 int cert_publish_counter     = CERTIFICATE_PUBLISH_INTERVAL;
-int heartbeat_counter        = 0;
 int hip_firewall_status      = -1;
 int fall, retr;
 
@@ -193,16 +191,9 @@
         precreate_counter--;
     }
 
-    /* is heartbeat support on */
-    if (hip_icmp_interval > 0) {
-        /* Check if the heartbeats should be sent */
-        if (heartbeat_counter < 1) {
-            hip_for_each_ha(hip_send_heartbeat, &hip_icmp_sock);
-            heartbeat_counter = hip_icmp_interval;
-        } else {
-            heartbeat_counter--;
-        }
-    } else if (hip_nat_status) {
+
+    /** @todo Disable NOTIFY keepalives, when heartbeat is enabled */
+    if (hip_nat_status) {
         /* Send NOTIFY keepalives for NATs only when ICMPv6
          * keepalives are disabled */
         if (nat_keep_alive_counter < 0) {

=== modified file 'hipd/maintenance.h'
--- hipd/maintenance.h  2010-03-05 17:28:01 +0000
+++ hipd/maintenance.h  2010-03-08 15:47:13 +0000
@@ -9,8 +9,6 @@
 #include "lib/core/hip_statistics.h"
 #include "nat.h"
 
-extern int heartbeat_counter;
-
 int hip_periodic_maintenance(void);
 void hip_set_firewall_status(void);
 int hip_get_firewall_status(void);

=== modified file 'hipd/output.c'
--- hipd/output.c       2010-03-08 09:44:30 +0000
+++ hipd/output.c       2010-03-08 15:47:13 +0000
@@ -1373,14 +1373,6 @@
 
     HIP_IFEL(err, -ECOMM, "Sending R2 packet failed.\n");
 
-    /* Send the first heartbeat. Notice that error value is ignored
-     * because we want to to complete the base exchange successfully
-     */
-    if (hip_icmp_interval > 0) {
-        _HIP_DEBUG("icmp sock %d\n", hip_icmp_sock);
-        hip_send_icmp(hip_icmp_sock, packet_ctx->hadb_entry);
-    }
-
 out_err:
     if (packet_ctx->output_msg) {
         free(packet_ctx->output_msg);

=== modified file 'hipd/user.c'
--- hipd/user.c 2010-03-05 17:28:01 +0000
+++ hipd/user.c 2010-03-08 15:47:13 +0000
@@ -54,7 +54,6 @@
     int err                      = 0, msg_type = 0, n = 0, len = 0, reti = 0;
     int access_ok                = 0, is_root = 0;
     struct hip_tlv_common *param = NULL;
-    struct hip_heartbeat *heartbeat;
     int send_response            = 0;
 
     HIP_ASSERT(src->sin6_family == AF_INET6);
@@ -157,12 +156,15 @@
                   hip_locator_status, SO_HIP_SET_LOCATOR_OFF);
         hip_recreate_all_precreated_r1_packets();
         break;
+    /** @todo Create module heartbeat-upate */
+#if 0
     case SO_HIP_HEARTBEAT:
         heartbeat         = hip_get_param(msg, HIP_PARAM_HEARTBEAT);
         hip_icmp_interval = heartbeat->heartbeat;
         heartbeat_counter = hip_icmp_interval;
         HIP_DEBUG("Received heartbeat interval (%d seconds)\n", 
hip_icmp_interval);
         break;
+#endif
     case SO_HIP_SET_DEBUG_ALL:
         /* Displays all debugging messages. */
         _HIP_DEBUG("Handling DEBUG ALL user message.\n");

=== added directory 'modules/heartbeat'
=== added file 'modules/heartbeat/Makefile.am'
--- modules/heartbeat/Makefile.am       1970-01-01 00:00:00 +0000
+++ modules/heartbeat/Makefile.am       2010-03-08 15:47:13 +0000
@@ -0,0 +1,2 @@
+lib_LTLIBRARIES += modules/heartbeat/hipd/libhipheartbeat.la
+modules_heartbeat_hipd_libhipheartbeat_la_SOURCES = 
modules/heartbeat/hipd/heartbeat.c

=== added directory 'modules/heartbeat/hipd'
=== added file 'modules/heartbeat/module_info.xml'
--- modules/heartbeat/module_info.xml   1970-01-01 00:00:00 +0000
+++ modules/heartbeat/module_info.xml   2010-03-08 15:47:13 +0000
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!-- Mandatory: name, version -->
+<module
+    name="heartbeat"
+    version="0.0.1"
+    description="Heartbeat extension for the hip daemon."
+    developer=""
+    bugaddress="hipl-users@xxxxxxxxxxxxx"
+    webpage="http://infrahip.hiit.fi/";>
+
+    <!-- Mandatory: name, header_file, init_function, linkcommand -->
+    <application
+        name="hipd"
+        header_file="modules/heartbeat/hipd/heartbeat.h"
+        init_function="hip_heartbeat_init"
+        linkcommand="hipd_hipd_LDADD += 
modules/heartbeat/hipd/libhipheartbeat.la" />
+</module>

=== modified file 'modules/update/hipd/update.c'
--- modules/update/hipd/update.c        2010-03-08 09:44:30 +0000
+++ modules/update/hipd/update.c        2010-03-08 15:47:13 +0000
@@ -922,6 +922,8 @@
     return err;
 }
 
+/** @todo Create module heartbeat-upate */
+#if 0
 static int hip_handle_update_heartbeat_trigger(hip_ha_t *ha, void *unused)
 {
     struct hip_locator_info_addr_item *locators;
@@ -968,6 +970,7 @@
 
     return err;
 }
+#endif
 
 int hip_update_maintenance(void)
 {
@@ -991,10 +994,11 @@
         }
     }
 
-    if (hip_trigger_update_on_heart_beat_failure &&
-        hip_icmp_interval > 0) {
-        hip_for_each_ha(hip_handle_update_heartbeat_trigger, NULL);
-    }
+    /** @todo Create module heartbeat-upate */
+//    if (hip_trigger_update_on_heart_beat_failure &&
+//        hip_icmp_interval > 0) {
+//        hip_for_each_ha(hip_handle_update_heartbeat_trigger, NULL);
+//    }
 
     return err;
 }

Other related posts:

  • » [hipl-commit] [tiny] Rev 3637: First step on HEARTBEAT modularization. - Tim Just