[hipl-commit] [trunk] Rev 3638: Cleaning up hipd/netdev.c.

  • From: Miika Komu <miika@xxxxxx>
  • To: hipl-commit@xxxxxxxxxxxxx
  • Date: Mon, 15 Feb 2010 18:28:01 +0200

Committer: Miika Komu <miika@xxxxxx>
Date: Mon Feb 15 18:27:50 2010 +0200
Revision: 3638
Revision-id: miika@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Branch nick: trunk

Log:
  Cleaning up hipd/netdev.c.
  Removed dead code. Unified commenting style.

Modified:
  M  hipd/netdev.c

=== modified file 'hipd/netdev.c'
--- hipd/netdev.c       2010-02-15 13:05:01 +0000
+++ hipd/netdev.c       2010-02-15 16:27:50 +0000
@@ -262,7 +262,7 @@
                                    hip_cast_sa_addr(addr),
                                    hip_sa_addr_len(&n->addr));
             family_match = (n->addr.ss_family == addr->sa_family);
-        } else {         // addr->sa_family == AF_INET
+        } else { /* addr->sa_family == AF_INET */
             HIP_DEBUG("Addr given was not IPv6 nor IPv4.\n");
         }
 
@@ -517,72 +517,6 @@
     return hip_netdev_find_if((struct sockaddr *) &a);
 }
 
-#if 0
-/* This function seems unused. Can't we delete it? */
-int static add_address(const struct nlmsghdr *h, int len, void *arg)
-{
-    struct sockaddr_storage ss_addr;
-    struct sockaddr *addr = (struct sockaddr *) &ss_addr;
-
-    while (NLMSG_OK(h, len)) {
-        struct ifaddrmsg *ifa;
-        struct rtattr *rta, *tb[IFA_MAX + 1];
-
-        memset(tb, 0, sizeof(tb));
-        /* exit this loop on end or error */
-        if (h->nlmsg_type == NLMSG_DONE) {
-            int *done = (int *) arg;
-            *done = 1;
-            break;
-        }
-
-        if (h->nlmsg_type == NLMSG_ERROR) {
-            HIP_ERROR("Error in Netlink response.\n");
-            return -1;
-        }
-
-        ifa = NLMSG_DATA(h);
-        rta = IFA_RTA(ifa);
-        len = h->nlmsg_len - NLMSG_LENGTH(sizeof(*ifa));
-
-        if ((ifa->ifa_family != AF_INET) &&
-            (ifa->ifa_family != AF_INET6)) {
-            continue;
-        }
-
-        /* parse list of attributes into table
-         * (same as parse_rtattr()) */
-        while (RTA_OK(rta, len)) {
-            if (rta->rta_type <= IFA_MAX) {
-                tb[rta->rta_type] = rta;
-            }
-            rta = RTA_NEXT(rta, len);
-        }
-
-        /* fix tb entry for inet6 */
-        if (!tb[IFA_LOCAL]) {
-            tb[IFA_LOCAL] = tb[IFA_ADDRESS];
-        }
-        if (!tb[IFA_ADDRESS]) {
-            tb[IFA_ADDRESS] = tb[IFA_LOCAL];
-        }
-
-        /* save the addresses we care about */
-        if (tb[IFA_LOCAL]) {
-            addr->sa_family = ifa->ifa_family;
-            memcpy(hip_cast_sa_addr(addr), RTA_DATA(tb[IFA_LOCAL]),
-                   RTA_PAYLOAD(tb[IFA_LOCAL]));
-            add_address_to_list(addr, ifa->ifa_index, 0);
-            _HIP_DEBUG("ifindex=%d\n", ifa->ifa_index);
-        }
-        h = NLMSG_NEXT(h, len);
-    }
-
-    return 0;
-}
-
-#endif
-
 /*
  * Note: this creates a new NETLINK socket (via getifaddrs), so this has to be
  * run before the global NETLINK socket is opened. I did not have the time
@@ -596,7 +530,6 @@
 
     /* Initialize address list */
     HIP_DEBUG("Initializing addresses...\n");
-    //INIT_LIST_HEAD(addresses);
     addresses = hip_ht_init(hip_netdev_hash, hip_netdev_match);
 
     HIP_IFEL(getifaddrs(&g_ifaces), -1,
@@ -790,7 +723,7 @@
                  -1, "DHT get in opendht_get_endpoint failed!\n");
         inet_pton(AF_INET6, node_hit, &addr6.s6_addr);
 
-        //HDRR verification
+        /* HDRR verification */
         HIP_IFEL(hip_verify_hdrr((struct hip_common *) dht_response, &addr6),
                  -1, "HDRR Signature and/or host id verification failed!\n");
 
@@ -860,8 +793,6 @@
     if (hip_get_hit_to_ip_status() && !skip_namelookup) {
         HIP_DEBUG("looking for hit-to-ip record in dns\n");
         HIP_DEBUG("operation may take a while..\n");
-        //struct in6_addr tmp_in6_addr;
-        //struct in6_addr *tmp_in6_addr_ptr = &tmp_in6_addr;
         int res = hip_hit_to_ip(hit, addr);
 
         if (res == OK) {
@@ -880,19 +811,6 @@
         _HIP_DEBUG("### HIT STRING ### %s\n", (const char *) hit_str);
         err = opendht_get_endpointinfo((const char *) hit_str, addr);
         _HIP_DEBUG_IN6ADDR("### ADDR ###", addr);
-/*
- *              char *hit_str = NULL;
- *              //HIP_IFE((!(hit_str = HIP_MALLOC(INET6_ADDRSTRLEN, 0))), -1);
- *              //memset(hit_str, 0, INET6_ADDRSTRLEN);
- *
- *              memset(hit_str, 0, sizeof(hit_str));
- *              hip_in6_ntop(&hit2, hit_str);
- *
- *              //hit_str =  hip_convert_hit_to_str(hit, NULL);
- *              HIP_DEBUG("### HIT STRING ### %s\n", (const char *)hit_str);
- *
- *              err = opendht_get_endpointinfo((const char *) hit_str, addr);
- */
         if (err) {
             HIP_DEBUG("Got IP for HIT from DHT err = \n", err);
         }
@@ -912,13 +830,13 @@
                            struct in6_addr *src_addr,
                            struct in6_addr *dst_addr)
 {
-    int err                      = 0, if_index = 0, is_ipv4_locator,
-        reuse_hadb_local_address = 0, ha_nat_mode = hip_nat_status,
-        old_global_nat_mode      = hip_nat_status;
+    int err = 0, if_index = 0, is_ipv4_locator;
+    int reuse_hadb_local_address = 0, ha_nat_mode = hip_nat_status;
+    int old_global_nat_mode = hip_nat_status;
     in_port_t ha_local_port;
     in_port_t ha_peer_port;
-    hip_ha_t *entry              = NULL;
-    int is_loopback              = 0;
+    hip_ha_t *entry = NULL;
+    int is_loopback = 0;
     hip_lsi_t dlsi, slsi;
     struct in6_addr dhit, shit, saddr, dst6_lsi;
     struct in6_addr daddr;
@@ -1077,7 +995,7 @@
      * with the peer that gave use hints on the best NAT mode or source
      * address. */
 
-    /* @fixme: changing global state won't work with threads */
+    /** @todo changing global state won't work with threads */
     hip_nat_status = ha_nat_mode;
 
     /* To make it follow the same route as it was doing before HDRR/loactors */
@@ -1136,9 +1054,7 @@
 
     HIP_DEBUG("Using ifindex %d\n", if_index);
 
-    //add_address_to_list(addr, if_index /*acq->sel.ifindex*/);
-
-    /* If datapacket mode is set then dont send I1.
+    /* If datapacket mode is set then don't send I1.
      * Instead, reply with data packet mode message type. */
     if (hip_use_userspace_data_packet_mode) {
         goto out_err;
@@ -1240,7 +1156,7 @@
         }
     }
 
-    // @todo: check if peer lsi is all zeroes?
+    /** @todo: check if peer lsi is all zeroes? */
 
     /* Local LSI */
     param = hip_get_next_param(msg, param);
@@ -1252,7 +1168,7 @@
     }
     HIP_DEBUG_LSI("trigger_msg_our_lsi:", &our_lsi);
 
-    // @todo: check if local lsi is all zeroes?
+    /** @todo: check if local lsi is all zeroes? */
 
     /* Destination IP */
     param = hip_get_param(msg, HIP_PARAM_IPV6_ADDR);
@@ -1326,13 +1242,6 @@
             break;
         case RTM_DELLINK:
             HIP_DEBUG("RTM_DELLINK\n");
-            //ifinfo = (struct ifinfomsg*)NLMSG_DATA(msg);
-            //delete_address_from_list(NULL, ifinfo->ifi_index);
-            //delete_address_from_list(NULL, ifindex);
-            /* should do here
-             * hip_send_update_all(NULL, 0, ifindex, SEND_UPDATE_REA);
-             * but ifconfig ethX down never seems to come here
-             */
             break;
         /* Add or delete address from addresses */
         case RTM_NEWADDR:
@@ -1392,12 +1301,6 @@
                 HIP_DEBUG("Unknown addr family in addr\n");
             }
 
-            /*hip_start_timer_for_update();
-             * // Q: If timer is already set, do we reinitialize the time?
-             *
-             * // Q: do we update the addresss continuosly or do we just try 
to detect?
-             * hip_update_address_list() or use detect_addresses() in 
send_update()?*/
-
             /* Trying to add an existing address or deleting a non-existing
              * address */
             exists = exists_address_in_list(addr, ifa->ifa_index);
@@ -1418,7 +1321,7 @@
 
             break;
         case XFRMGRP_ACQUIRE:
-            /* XX TODO  does this ever happen? */
+            /* This seems never to occur */
             HIP_DEBUG("\n");
             return -1;
             break;
@@ -1428,11 +1331,11 @@
             break;
 #if 0
         case XFRMGRP_SA:
-            /* XX TODO  does this ever happen? */
+            /* This seems never to occur */
             return -1;
             break;
         case XFRMGRP_POLICY:
-            /* XX TODO  does this ever happen? */
+            /* This seems never to occur */
             return -1;
             break;
 #endif
@@ -1572,9 +1475,7 @@
     HIP_DEBUG_LSI("Default lsi is ", &lsi);
     hip_build_param_contents(msg, &hit, HIP_PARAM_HIT, sizeof(hit));
     hip_build_param_contents(msg, &lsi, HIP_PARAM_LSI, sizeof(lsi));
-/* Removed because unused
- * out_err:
- */
+
     return err;
 }
 
@@ -1601,7 +1502,7 @@
     return err;
 }
 
-//get the puzzle difficulty and return result to hipconf
+/* get the puzzle difficulty and return result to hipconf */
 int hip_get_puzzle_difficulty_msg(struct hip_common *msg)
 {
     int err            = 0, diff = 0;
@@ -1609,7 +1510,7 @@
     hip_hit_t all_zero_hit;
     bzero(&all_zero_hit, sizeof(all_zero_hit));
 
-    //obtain the hit
+    /* obtain the hit */
     dst_hit = hip_get_param_contents(msg, HIP_PARAM_HIT);
 
 #ifdef CONFIG_HIP_COOKIE
@@ -1624,15 +1525,13 @@
 
     _HIP_DEBUG("Puzzle difficulty is %d\n", diff);
     hip_build_param_contents(msg, &diff, HIP_PARAM_INT, sizeof(diff));
-    /* Disabled because it wasn't used
-     * out_err:
-     */
+
     return err;
 }
 
 
-/* TODO: This function has no error handling at all! Check if this is right-*/
-//set the puzzle difficulty acc to msg sent by hipconf
+/* @todo This function has no error handling at all! Check if this is right */
+/* set the puzzle difficulty acc to msg sent by hipconf */
 int hip_set_puzzle_difficulty_msg(struct hip_common *msg)
 {
     int err            = 0, *newVal = NULL;
@@ -1689,21 +1588,21 @@
                 item2            = (struct hip_locator_info_addr_item2 *) 
address_pointer;
                 hip_build_param_contents(msg, &item2->address,
                                          HIP_PARAM_SRC_ADDR, sizeof(struct 
in6_addr));
-                //HIP_DEBUG_HIT("LOCATOR", (struct in6_addr *)&item2->address);
+                _HIP_DEBUG_HIT("LOCATOR", (struct in6_addr *)&item2->address);
                 address_pointer += sizeof(struct hip_locator_info_addr_item2);
             } else if (((struct hip_locator_info_addr_item *) 
address_pointer)->locator_type
                        == HIP_LOCATOR_LOCATOR_TYPE_ESP_SPI) {
                 item             = (struct hip_locator_info_addr_item *) 
address_pointer;
                 hip_build_param_contents(msg, &item->address,
                                          HIP_PARAM_SRC_ADDR, sizeof(struct 
in6_addr));
-                //HIP_DEBUG_HIT("LOCATOR", (struct in6_addr *)&item->address);
+                _HIP_DEBUG_HIT("LOCATOR", (struct in6_addr *)&item->address);
                 address_pointer += sizeof(struct hip_locator_info_addr_item);
             } else if (((struct hip_locator_info_addr_item *) 
address_pointer)->locator_type
                        == HIP_LOCATOR_LOCATOR_TYPE_IPV6) {
                 item             = (struct hip_locator_info_addr_item *) 
address_pointer;
                 hip_build_param_contents(msg, &item->address,
                                          HIP_PARAM_SRC_ADDR, sizeof(struct 
in6_addr));
-                //HIP_DEBUG_HIT("LOCATOR", (struct in6_addr *)&item->address);
+                _HIP_DEBUG_HIT("LOCATOR", (struct in6_addr *)&item->address);
                 address_pointer += sizeof(struct hip_locator_info_addr_item);
             } else {
                 address_pointer += sizeof(struct hip_locator_info_addr_item);
@@ -1711,13 +1610,13 @@
         }
     } else {
         memcpy(&((&reply6)->s6_addr), in_msg, sizeof(reply6.s6_addr));
-        //HIP_DEBUG_HIT("LOCATOR", &reply6);
+        _HIP_DEBUG_HIT("LOCATOR", &reply6);
         if (ipv6_addr_cmp(&all_zero_ipv6, &reply6)) {
             hip_build_param_contents(msg, &reply6,
                                      HIP_PARAM_SRC_ADDR,
                                      sizeof(struct in6_addr));
         } else {
-            err_value = 3;    //Entry not found at DHT gateway
+            err_value = 3; /* Entry not found at DHT gateway */
             hip_build_param_contents(msg, &err_value,
                                      HIP_PARAM_INT, sizeof(int));
         }
@@ -1755,7 +1654,7 @@
     }
     if (param_type == HIP_PARAM_HOSTNAME) {
         ret_HOSTNAME = 1;
-        //get hostname
+        /* get hostname */
         HIP_IFEL(((hostname = hip_get_param(msg, HIP_PARAM_HOSTNAME)) == 
NULL), -1,
                  "hostname null\n");
         hostname     = hip_get_param_contents_direct(hostname);
@@ -1767,7 +1666,7 @@
         hip_convert_hit_to_str(dst_hit, NULL, hit_str);
     }
 
-    //convert hw addr to str
+    /* convert hw addr to str */
     inet_ntop(AF_INET,
               &(((struct sockaddr_in *) (void *) 
opendht_serving_gateway->ai_addr)->sin_addr),
               ip_str,
@@ -1775,7 +1674,7 @@
 
     /* init the dht gw socket */
     socket = init_dht_gateway_socket_gw(socket, opendht_serving_gateway);
-    //the connection to the gw here should be done using binding
+    /* the connection to the gw here should be done using binding */
     err    = connect_dht_gateway(socket, opendht_serving_gateway, 1);
 
     if (err != 0) {
@@ -1796,7 +1695,7 @@
         err = opendht_get(socket, (unsigned char *) hostname,
                           (unsigned char *) ip_str, 
opendht_serving_gateway_port);
     }
-    //get response from dht server
+    /* get response from dht server */
     err = opendht_read_response(socket, dht_response);
 
     if (err != 0) {
@@ -1807,7 +1706,7 @@
         goto out_err;
     }
 
-    //attach output to the msg back to hipconf
+    /* attach output to the msg back to hipconf */
     hip_attach_locator_addresses((struct hip_common *) dht_response, msg);
 
 out_err:

Other related posts:

  • » [hipl-commit] [trunk] Rev 3638: Cleaning up hipd/netdev.c. - Miika Komu