[pisa-src] r1762 - in trunk/libpisa: nat.c nat.h

  • From: Thomas Jansen <mithi@xxxxxxxxx>
  • To: pisa-src@xxxxxxxxxxxxx
  • Date: Tue, 24 Nov 2009 11:08:50 +0100

Author: tjansen
Date: Tue Nov 24 11:08:50 2009
New Revision: 1762

Log:
Moved code to delete a single NAT mapping to a separate function.

Refactored pisa_nat_del_mappings_for_hit to make use of the new function.

Modified:
   trunk/libpisa/nat.c
   trunk/libpisa/nat.h

Modified: trunk/libpisa/nat.c
==============================================================================
--- trunk/libpisa/nat.c Tue Nov 24 10:55:39 2009        (r1761)
+++ trunk/libpisa/nat.c Tue Nov 24 11:08:50 2009        (r1762)
@@ -202,6 +202,22 @@
 }
 
 /**
+ * Remove a single NAT mapping from the hashes and free the memory.
+ *
+ * @param natlist list of all NAT mappings
+ * @param map mapping that will be removed from the list and freed
+ */
+void pisa_nat_del_mapping(pisa_nat_list *natlist, pisa_nat_mapping *map)
+{
+       if (map->state == PISA_NAT_STATE_FINAL) {
+               HASH_DELETE(hh_remote, natlist->hash_remote, map);
+               HASH_DELETE(hh_mac, natlist->hash_mac, map);
+       }
+       HASH_DELETE(hh_local_private, natlist->hash_local_private, map);
+       free(map);
+}
+
+/**
  * Remove all NAT mappings for a given HIT from the list.
  * @param remote_hit the remote public IPv6 address (HIT)
  */
@@ -211,14 +227,8 @@
 
        while (cur) {
                next = cur->hh_remote.next;
-               if (!memcmp(remote_hit, &cur->remote.hit, sizeof(struct 
in6_addr))) {
-                       if (cur->state == PISA_NAT_STATE_FINAL) {
-                               HASH_DELETE(hh_remote, natlist->hash_remote, 
cur);
-                               HASH_DELETE(hh_mac, natlist->hash_mac, cur);
-                       }
-                       HASH_DELETE(hh_local_private, 
natlist->hash_local_private, cur);
-                       free(cur);
-               }
+               if (!memcmp(remote_hit, &cur->remote.hit, sizeof(struct 
in6_addr)))
+                       pisa_nat_del_mapping(natlist, cur);
                cur = next;
        }
 }

Modified: trunk/libpisa/nat.h
==============================================================================
--- trunk/libpisa/nat.h Tue Nov 24 10:55:39 2009        (r1761)
+++ trunk/libpisa/nat.h Tue Nov 24 11:08:50 2009        (r1762)
@@ -51,6 +51,7 @@
 pisa_nat_mapping *pisa_nat_add_mapping(pisa_nat_list *natlist, struct in_addr 
*local_private, struct in_addr *remote_private, pisa_conmgr_entry *entry, 
pisa_mac *mac);
 pisa_nat_mapping *pisa_nat_add_preliminary(pisa_nat_list *natlist, struct 
in_addr *local_private);
 void pisa_nat_upgrade_preliminary(pisa_nat_list *natlist, pisa_nat_mapping 
*map, struct in_addr *remote_private, pisa_conmgr_entry *entry, pisa_mac *mac);
+void pisa_nat_del_mapping(pisa_nat_list *natlist, pisa_nat_mapping *map);
 void pisa_nat_del_mappings_for_hit(pisa_nat_list *natlist, struct in6_addr 
*remote_hit);
 pisa_nat_mapping *pisa_nat_mapping_find_by_remote(pisa_nat_list *natlist, 
struct in6_addr *remote_hit, struct in_addr *remote_ipv4);
 pisa_nat_mapping *pisa_nat_mapping_find_by_local_private(pisa_nat_list 
*natlist, struct in_addr *local_private);

Other related posts:

  • » [pisa-src] r1762 - in trunk/libpisa: nat.c nat.h - Thomas Jansen