aboutsummaryrefslogtreecommitdiffstats
path: root/hicn-light/src
diff options
context:
space:
mode:
authorJordan Augé <jordan.auge@cisco.com>2019-10-28 15:44:42 +0100
committerMauro Sardara <msardara@cisco.com>2019-10-30 14:46:57 +0000
commit5fca7ef4838c6a8aede8a5e338940804e8e363f7 (patch)
tree341257400aaa3dd428340418a2c1a808bdbbb01c /hicn-light/src
parent3d674d504306489c4d845260f058ce44aa083f33 (diff)
[HICN-363] Fix memory leaks
Change-Id: I7617becdb520f20caca341be11fbb8c1054de021 Signed-off-by: Jordan Augé <jordan.auge@cisco.com>
Diffstat (limited to 'hicn-light/src')
-rw-r--r--hicn-light/src/hicn/config/configuration.c8
-rw-r--r--hicn-light/src/hicn/config/symbolicNameTable.c2
-rw-r--r--hicn-light/src/hicn/core/CMakeLists.txt6
-rw-r--r--hicn-light/src/hicn/core/forwarder.c62
-rw-r--r--hicn-light/src/hicn/core/mapme.c (renamed from hicn-light/src/hicn/core/mapMe.c)109
-rw-r--r--hicn-light/src/hicn/core/mapme.h (renamed from hicn-light/src/hicn/core/mapMe.h)40
-rw-r--r--hicn-light/src/hicn/core/messageHandler.h6
-rw-r--r--hicn-light/src/hicn/io/hicnListener.c2
-rw-r--r--hicn-light/src/hicn/io/listenerSet.c2
-rw-r--r--hicn-light/src/hicn/io/streamConnection.c1
-rw-r--r--hicn-light/src/hicn/io/udpListener.c9
-rw-r--r--hicn-light/src/hicn/processor/fibEntry.c7
-rw-r--r--hicn-light/src/hicn/processor/messageProcessor.c1
-rw-r--r--hicn-light/src/hicn/socket/api.c45
-rw-r--r--hicn-light/src/hicn/strategies/loadBalancer.c13
15 files changed, 193 insertions, 120 deletions
diff --git a/hicn-light/src/hicn/config/configuration.c b/hicn-light/src/hicn/config/configuration.c
index 4771c4073..c10b01c30 100644
--- a/hicn-light/src/hicn/config/configuration.c
+++ b/hicn-light/src/hicn/config/configuration.c
@@ -44,7 +44,7 @@
#include <hicn/core/forwarder.h>
#include <hicn/core/system.h>
#ifdef WITH_MAPME
-#include <hicn/core/mapMe.h>
+#include <hicn/core/mapme.h>
#endif /* WITH_MAPME */
#include <hicn/io/streamConnection.h>
@@ -498,8 +498,8 @@ struct iovec *configuration_ProcessRemoveListener(Configuration *config,
ConnectionTable *connTable = forwarder_GetConnectionTable(config->forwarder);
ListenerOps *listenerOps = listenerSet_FindById(listenerSet, listenerId);
if (listenerOps) {
- ConnectionList *connectionList =connectionTable_GetEntries(connTable);
- for (size_t i =0; i < connectionList_Length(connectionList); i++) {
+ ConnectionList *connectionList = connectionTable_GetEntries(connTable);
+ for (size_t i = 0; i < connectionList_Length(connectionList); i++) {
Connection *connection = connectionList_Get(connectionList, i);
const AddressPair *addressPair = connection_GetAddressPair(connection);
const Address *address = addressPair_GetLocal(addressPair);
@@ -514,6 +514,7 @@ struct iovec *configuration_ProcessRemoveListener(Configuration *config,
symbolicNameTable_Remove(config->symbolicNameTable, symbolicConnection);
}
}
+ connectionList_Destroy(&connectionList);
// remove listener
listenerSet_RemoveById(listenerSet, listenerId);
success = true;
@@ -1391,6 +1392,7 @@ void configuration_ReceiveCommand(Configuration *config, command_id command,
switch (command) {
case LIST_CONNECTIONS:
case LIST_ROUTES: // case LIST_INTERFACES: case ETC...:
+ case LIST_LISTENERS:
parcMemory_Deallocate(
&response[1]
.iov_base); // deallocate payload only if generated at fwd side
diff --git a/hicn-light/src/hicn/config/symbolicNameTable.c b/hicn-light/src/hicn/config/symbolicNameTable.c
index 723039fae..e5ae81d3e 100644
--- a/hicn-light/src/hicn/config/symbolicNameTable.c
+++ b/hicn-light/src/hicn/config/symbolicNameTable.c
@@ -74,7 +74,7 @@ SymbolicNameTable *symbolicNameTable_Create(void) {
void symbolicNameTable_Destroy(SymbolicNameTable **tablePtr) {
SymbolicNameTable *table = *tablePtr;
parcHashCodeTable_Destroy(&table->symbolicNameTable);
- // parcHashCodeTable_Destroy(&table->indexToNameTable);
+ parcHashCodeTable_Destroy(&table->indexToNameTable);
parcMemory_Deallocate((void **)&table);
*tablePtr = NULL;
}
diff --git a/hicn-light/src/hicn/core/CMakeLists.txt b/hicn-light/src/hicn/core/CMakeLists.txt
index c6e000524..5e2b696d7 100644
--- a/hicn-light/src/hicn/core/CMakeLists.txt
+++ b/hicn-light/src/hicn/core/CMakeLists.txt
@@ -28,7 +28,7 @@ list(APPEND HEADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/numberSet.h
${CMAKE_CURRENT_SOURCE_DIR}/streamBuffer.h
${CMAKE_CURRENT_SOURCE_DIR}/system.h
- ${CMAKE_CURRENT_SOURCE_DIR}/mapMe.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/mapme.h
${CMAKE_CURRENT_SOURCE_DIR}/wldr.h
${CMAKE_CURRENT_SOURCE_DIR}/messageHandler.h
${CMAKE_CURRENT_SOURCE_DIR}/nameBitvector.h
@@ -46,7 +46,7 @@ list(APPEND SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/message.c
${CMAKE_CURRENT_SOURCE_DIR}/numberSet.c
${CMAKE_CURRENT_SOURCE_DIR}/streamBuffer.c
- ${CMAKE_CURRENT_SOURCE_DIR}/mapMe.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/mapme.c
${CMAKE_CURRENT_SOURCE_DIR}/wldr.c
${CMAKE_CURRENT_SOURCE_DIR}/nameBitvector.c
${CMAKE_CURRENT_SOURCE_DIR}/name.c
@@ -59,4 +59,4 @@ set(TO_INSTALL_HEADER_FILES
${TO_INSTALL_HEADER_FILES}
${HEADER_FILES}
PARENT_SCOPE
-) \ No newline at end of file
+)
diff --git a/hicn-light/src/hicn/core/forwarder.c b/hicn-light/src/hicn/core/forwarder.c
index c9527bb49..66551b0ec 100644
--- a/hicn-light/src/hicn/core/forwarder.c
+++ b/hicn-light/src/hicn/core/forwarder.c
@@ -52,7 +52,7 @@
#include <hicn/core/forwarder.h>
#include <hicn/core/messagePacketType.h>
#ifdef WITH_MAPME
-#include <hicn/core/mapMe.h>
+#include <hicn/core/mapme.h>
#endif /* WITH_MAPME */
#include <hicn/config/configuration.h>
#include <hicn/config/configurationFile.h>
@@ -197,10 +197,19 @@ Forwarder *forwarder_Create(Logger *logger) {
dispatcher_StartSignalEvent(forwarder->dispatcher, forwarder->signal_usr1);
#endif
-#if !defined(__APPLE__) && !defined(_WIN32) && defined(PUNTING)
+#if !defined(__APPLE__) && !defined(__ANDROID__) && !defined(_WIN32) && \
+ defined(PUNTING)
forwarder->hicnSocketHelper = hicn_create();
- if (forwarder->hicnSocketHelper == NULL) return NULL;
+ if (!forwarder->hicnSocketHelper)
+ goto ERR_SOCKET;
#endif /* __APPLE__ */
+
+#ifdef WITH_MAPME
+ if (!(mapme_create(&forwarder->mapme, forwarder)))
+ goto ERR_MAPME;
+#endif /* WITH_MAPME */
+
+
/* ignore child */
#ifndef _WIN32
signal(SIGCHLD, SIG_IGN);
@@ -220,10 +229,6 @@ Forwarder *forwarder_Create(Logger *logger) {
wtnow_timeout.tv_sec = 0;
wtnow_timeout.tv_usec = 50000; // 20 Hz keepalive
-#ifdef WITH_MAPME
- if (!(mapMe_Init(&forwarder->mapme, forwarder))) return NULL;
-#endif /* WITH_MAPME */
-
PARCEventScheduler *base =
dispatcher_GetEventScheduler(forwarder->dispatcher);
forwarder->keepalive_event = parcEventTimer_Create(
@@ -231,6 +236,39 @@ Forwarder *forwarder_Create(Logger *logger) {
parcEventTimer_Start(forwarder->keepalive_event, &wtnow_timeout);
return forwarder;
+
+#ifdef WITH_MAPME
+ERR_MAPME:
+#endif /* WITH_MAPME */
+#if !defined(__APPLE__) && !defined(__ANDROID__) && !defined(_WIN32) && \
+ defined(PUNTING)
+ hicn_free(forwarder->hicnSocketHelper);
+ERR_SOCKET:
+#endif
+ listenerSet_Destroy(&(forwarder->listenerSet));
+ connectionManager_Destroy(&(forwarder->connectionManager));
+ connectionTable_Destroy(&(forwarder->connectionTable));
+ messageProcessor_Destroy(&(forwarder->processor));
+ configuration_Destroy(&(forwarder->config));
+ messenger_Destroy(&(forwarder->messenger));
+
+ dispatcher_DestroySignalEvent(forwarder->dispatcher,
+ &(forwarder->signal_int));
+ dispatcher_DestroySignalEvent(forwarder->dispatcher,
+ &(forwarder->signal_term));
+#ifndef _WIN32
+ dispatcher_DestroySignalEvent(forwarder->dispatcher,
+ &(forwarder->signal_usr1));
+#endif
+
+ parcClock_Release(&forwarder->clock);
+ logger_Release(&forwarder->logger);
+
+ // do the dispatcher last
+ dispatcher_Destroy(&(forwarder->dispatcher));
+
+ parcMemory_Deallocate((void **)&forwarder);
+ return NULL;
}
void forwarder_Destroy(Forwarder **ptr) {
@@ -239,7 +277,7 @@ void forwarder_Destroy(Forwarder **ptr) {
Forwarder *forwarder = *ptr;
#if !defined(__APPLE__) && !defined(__ANDROID__) && !defined(_WIN32) && \
defined(PUNTING)
- hicn_destroy();
+ hicn_free(forwarder->hicnSocketHelper);
#endif
parcEventTimer_Destroy(&(forwarder->keepalive_event));
@@ -252,6 +290,10 @@ void forwarder_Destroy(Forwarder **ptr) {
// the messenger is used by many of the other pieces, so destroy it last
messenger_Destroy(&(forwarder->messenger));
+#ifdef WITH_MAPME
+ mapme_free(forwarder->mapme);
+#endif /* WITH_MAPME */
+
dispatcher_DestroySignalEvent(forwarder->dispatcher,
&(forwarder->signal_int));
dispatcher_DestroySignalEvent(forwarder->dispatcher,
@@ -532,13 +574,13 @@ void forwarder_onConnectionEvent(Forwarder *forwarder, const Connection *conn, c
#ifdef WITH_POLICY
messageProcessor_onConnectionEvent(forwarder->processor, conn, event);
#else
- mapMe_onConnectionEvent(forwarder->mapme, conn, event);
+ mapme_onConnectionEvent(forwarder->mapme, conn, event);
#endif /* WITH_POLICY */
}
void forwarder_ProcessMapMe(Forwarder *forwarder, const uint8_t *msgBuffer,
unsigned conn_id) {
- mapMe_Process(forwarder->mapme, msgBuffer, conn_id);
+ mapme_Process(forwarder->mapme, msgBuffer, conn_id);
}
MapMe *
diff --git a/hicn-light/src/hicn/core/mapMe.c b/hicn-light/src/hicn/core/mapme.c
index 2b621387b..94ada3afa 100644
--- a/hicn-light/src/hicn/core/mapMe.c
+++ b/hicn-light/src/hicn/core/mapme.c
@@ -14,14 +14,14 @@
*/
/**
- * @file mapMe.c
+ * @file mapme.c
* @brief MAP-Me : AnchorLess Producer Mobility Management.
*/
#ifdef WITH_MAPME
#include <hicn/hicn.h>
-#include <hicn/core/mapMe.h>
+#include <hicn/core/mapme.h>
#include <stdio.h> // printf
#include <hicn/core/connection.h>
@@ -88,7 +88,7 @@ static MapMe MapMeDefault = {.retx = MAPME_DEFAULT_RETX,
/******************************************************************************/
-bool mapMe_Init(MapMe **mapme, Forwarder *forwarder) {
+bool mapme_create(MapMe **mapme, Forwarder *forwarder) {
*mapme = malloc(sizeof(MapMe));
if (!mapme) goto ERR_MALLOC;
@@ -108,6 +108,11 @@ ERR_MALLOC:
return false;
}
+void mapme_free(MapMe *mapme)
+{
+ free(mapme);
+}
+
/******************************************************************************
* TFIB
******************************************************************************/
@@ -122,7 +127,7 @@ typedef struct {
Ticks lastAckedUpdate;
} MapMeTFIB;
-static MapMeTFIB *mapMeTFIB_Create() {
+static MapMeTFIB *mapmeTFIB_Create() {
MapMeTFIB *tfib;
tfib = malloc(sizeof(MapMeTFIB));
if (!tfib) goto ERR_MALLOC;
@@ -139,7 +144,7 @@ ERR_MALLOC:
return NULL;
}
-void mapMeTFIB_Release(MapMeTFIB **tfibPtr) {
+void mapmeTFIB_Release(MapMeTFIB **tfibPtr) {
MapMeTFIB *tfib = *tfibPtr;
parcHashMap_Release(&tfib->nexthops);
free(tfib);
@@ -147,25 +152,25 @@ void mapMeTFIB_Release(MapMeTFIB **tfibPtr) {
}
/**
- * @function mapMe_CreateTFIB
+ * @function mapme_CreateTFIB
* @abstract Associate a new TFIB entry to a FIB entry.
* @param [in] - Pointer to the FIB entry.
* @return Boolean indicating the success of the operation.
*/
-static void mapMe_CreateTFIB(FibEntry *fibEntry) {
+static void mapme_CreateTFIB(FibEntry *fibEntry) {
MapMeTFIB *tfib;
/* Make sure we don't already have an associated TFIB entry */
tfib = fibEntry_getUserData(fibEntry);
// assertNull(tfib);
- tfib = mapMeTFIB_Create();
- fibEntry_setUserData(fibEntry, tfib, (void (*)(void **))mapMeTFIB_Release);
+ tfib = mapmeTFIB_Create();
+ fibEntry_setUserData(fibEntry, tfib, (void (*)(void **))mapmeTFIB_Release);
}
#define TFIB(fibEntry) ((MapMeTFIB *)fibEntry_getUserData(fibEntry))
-static const PARCEventTimer *mapMeTFIB_Get(const MapMeTFIB *tfib,
+static const PARCEventTimer *mapmeTFIB_Get(const MapMeTFIB *tfib,
unsigned conn_id) {
const PARCEventTimer *timer;
const PARCBuffer *buffer;
@@ -178,7 +183,7 @@ static const PARCEventTimer *mapMeTFIB_Get(const MapMeTFIB *tfib,
return timer;
}
-static void mapMeTFIB_Put(MapMeTFIB *tfib, unsigned conn_id,
+static void mapmeTFIB_Put(MapMeTFIB *tfib, unsigned conn_id,
const PARCEventTimer *timer) {
/* NOTE: Timers are not objects (the only class not being an object in
* fact), and as such, we cannot use them as values for the HashMap.
@@ -194,14 +199,14 @@ static void mapMeTFIB_Put(MapMeTFIB *tfib, unsigned conn_id,
parcBuffer_Release(&buffer);
}
-static void mapMeTFIB_Remove(MapMeTFIB *tfib, unsigned conn_id) {
+static void mapmeTFIB_Remove(MapMeTFIB *tfib, unsigned conn_id) {
// Who releases the timer ?
PARCUnsigned *cid = parcUnsigned_Create(conn_id);
parcHashMap_Remove(tfib->nexthops, cid);
parcUnsigned_Release(&cid);
}
-static PARCIterator *mapMeTFIB_CreateKeyIterator(const MapMeTFIB *tfib) {
+static PARCIterator *mapmeTFIB_CreateKeyIterator(const MapMeTFIB *tfib) {
return parcHashMap_CreateKeyIterator(tfib->nexthops);
}
@@ -214,7 +219,7 @@ int hicn_prefix_from_name(const Name *name, hicn_prefix_t *prefix) {
return hicn_prefix_create_from_ip_prefix(&ip_prefix, prefix);
}
-static Message *mapMe_createMessage(const MapMe *mapme, const Name *name,
+static Message *mapme_createMessage(const MapMe *mapme, const Name *name,
mapme_params_t *params) {
Ticks now = forwarder_GetTicks(mapme->forwarder);
Logger *logger = logger_Acquire(forwarder_GetLogger(mapme->forwarder));
@@ -250,7 +255,7 @@ ERR_NAME:
return NULL;
}
-static Message *mapMe_createAckMessage(const MapMe *mapme,
+static Message *mapme_createAckMessage(const MapMe *mapme,
const uint8_t *msgBuffer,
const mapme_params_t *params) {
Ticks now = forwarder_GetTicks(mapme->forwarder);
@@ -281,11 +286,11 @@ struct setFacePendingArgs {
uint32_t num_retx;
};
-static bool mapMe_setFacePending(const MapMe *mapme, const Name *name,
+static bool mapme_setFacePending(const MapMe *mapme, const Name *name,
FibEntry *fibEntry, unsigned conn_id,
bool send, bool is_first, uint32_t num_retx);
-static void mapMe_setFacePendingCallback(int fd, PARCEventType which_event,
+static void mapme_setFacePendingCallback(int fd, PARCEventType which_event,
void *data) {
struct setFacePendingArgs *args = (struct setFacePendingArgs *)data;
@@ -294,7 +299,7 @@ static void mapMe_setFacePendingCallback(int fd, PARCEventType which_event,
PARCEventType_Timeout, which_event);
INFO(args->mapme, "Timeout during retransmission. Re-sending");
- mapMe_setFacePending(args->mapme, args->name, args->fibEntry, args->conn_id,
+ mapme_setFacePending(args->mapme, args->name, args->fibEntry, args->conn_id,
args->send, args->is_first, args->num_retx);
}
@@ -304,7 +309,7 @@ static void mapMe_setFacePendingCallback(int fd, PARCEventType which_event,
* NOTE: IN are currently disabled until the proper placeholder is agreed in the
* interest header.
*/
-static hicn_mapme_type_t mapMe_getTypeFromHeuristic(const MapMe *mapme,
+static hicn_mapme_type_t mapme_getTypeFromHeuristic(const MapMe *mapme,
FibEntry *fibEntry) {
#if 0 /* interplay of IU/IN */
if (TFIB(fibEntry)->lastAckedUpdate == 0) {
@@ -318,7 +323,7 @@ static hicn_mapme_type_t mapMe_getTypeFromHeuristic(const MapMe *mapme,
#endif
}
-static bool mapMe_setFacePending(const MapMe *mapme, const Name *name,
+static bool mapme_setFacePending(const MapMe *mapme, const Name *name,
FibEntry *fibEntry, unsigned conn_id,
bool send, bool is_first, uint32_t num_retx) {
int rc;
@@ -339,9 +344,9 @@ static bool mapMe_setFacePending(const MapMe *mapme, const Name *name,
if (is_first || send) {
mapme_params_t params = {
.protocol = IPPROTO_IPV6,
- .type = is_first ? mapMe_getTypeFromHeuristic(mapme, fibEntry) : UPDATE,
+ .type = is_first ? mapme_getTypeFromHeuristic(mapme, fibEntry) : UPDATE,
.seq = TFIB(fibEntry)->seq};
- Message *special_interest = mapMe_createMessage(mapme, name, &params);
+ Message *special_interest = mapme_createMessage(mapme, name, &params);
if (!special_interest) {
INFO(mapme, "[MAP-Me] Could not create special interest");
return false;
@@ -377,7 +382,7 @@ static bool mapMe_setFacePending(const MapMe *mapme, const Name *name,
args->num_retx = num_retx + 1;
timer = dispatcher_CreateTimer(dispatcher, TIMER_NO_REPEAT,
- mapMe_setFacePendingCallback, args);
+ mapme_setFacePendingCallback, args);
struct timeval timeout = {mapme->retx / 1000,
(mapme->retx % 1000) * 1000};
rc = parcEventTimer_Start(timer, &timeout);
@@ -392,13 +397,13 @@ static bool mapMe_setFacePending(const MapMe *mapme, const Name *name,
}
PARCEventTimer *oldTimer =
- (PARCEventTimer *)mapMeTFIB_Get(TFIB(fibEntry), conn_id);
+ (PARCEventTimer *)mapmeTFIB_Get(TFIB(fibEntry), conn_id);
if (oldTimer) {
INFO(mapme, "[MAP-Me] - Found old timer, would need to cancel !");
// parcEventTimer_Stop(oldTimer);
}
INFO(mapme, "[MAP-Me] - Putting new timer in TFIB");
- if (timer) mapMeTFIB_Put(TFIB(fibEntry), conn_id, timer);
+ if (timer) mapmeTFIB_Put(TFIB(fibEntry), conn_id, timer);
return true;
@@ -414,7 +419,7 @@ ERR_TIMER:
/*
* Return true if we have at least one local connection as next hop
*/
-static bool mapMe_hasLocalNextHops(const MapMe *mapme,
+static bool mapme_hasLocalNextHops(const MapMe *mapme,
const FibEntry *fibEntry) {
const NumberSet *nexthops = fibEntry_GetNexthops(fibEntry);
const ConnectionTable *table = forwarder_GetConnectionTable(mapme->forwarder);
@@ -438,7 +443,7 @@ static bool mapMe_hasLocalNextHops(const MapMe *mapme,
/*
* Callback called everytime a new connection is created by the control protocol
*/
-void mapMe_onConnectionEvent(const MapMe *mapme, const Connection *conn_added, connection_event_t event) {
+void mapme_onConnectionEvent(const MapMe *mapme, const Connection *conn_added, connection_event_t event) {
switch(event) {
case CONNECTION_EVENT_CREATE:
case CONNECTION_EVENT_SET_UP:
@@ -462,13 +467,13 @@ void mapMe_onConnectionEvent(const MapMe *mapme, const Connection *conn_added, c
const Name *name = fibEntry_GetPrefix(fibEntry);
/* Skip entries that have no local connection as next hop */
- if (!mapMe_hasLocalNextHops(mapme, fibEntry))
+ if (!mapme_hasLocalNextHops(mapme, fibEntry))
continue;
/* This entry corresponds to a locally served prefix, set
* Special Interest */
if (!TFIB(fibEntry)) /* Create TFIB associated to FIB entry */
- mapMe_CreateTFIB(fibEntry);
+ mapme_CreateTFIB(fibEntry);
TFIB(fibEntry)->seq++;
char *name_str = name_ToString(name);
@@ -476,7 +481,7 @@ void mapMe_onConnectionEvent(const MapMe *mapme, const Connection *conn_added, c
conn_added_id);
free(name_str);
- mapMe_setFacePending(mapme, name, fibEntry, conn_added_id, true, true, 0);
+ mapme_setFacePending(mapme, name, fibEntry, conn_added_id, true, true, 0);
}
break;
}
@@ -488,7 +493,7 @@ void mapMe_onConnectionEvent(const MapMe *mapme, const Connection *conn_added, c
}
#ifdef WITH_POLICY
-void mapMe_onPolicyUpdate(const MapMe *mapme, const Connection *conn_selected, FibEntry * fibEntry)
+void mapme_onPolicyUpdate(const MapMe *mapme, const Connection *conn_selected, FibEntry * fibEntry)
{
/* Ignore local connections corresponding to applications for now */
if (connection_IsLocal(conn_selected))
@@ -500,13 +505,13 @@ void mapMe_onPolicyUpdate(const MapMe *mapme, const Connection *conn_selected, F
const Name *name = fibEntry_GetPrefix(fibEntry);
/* Skip entries that have no local connection as next hop */
- if (!mapMe_hasLocalNextHops(mapme, fibEntry))
+ if (!mapme_hasLocalNextHops(mapme, fibEntry))
return;
/* This entry corresponds to a locally served prefix, set
* Special Interest */
if (!TFIB(fibEntry)) /* Create TFIB associated to FIB entry */
- mapMe_CreateTFIB(fibEntry);
+ mapme_CreateTFIB(fibEntry);
TFIB(fibEntry)->seq++;
char *name_str = name_ToString(name);
@@ -514,7 +519,7 @@ void mapMe_onPolicyUpdate(const MapMe *mapme, const Connection *conn_selected, F
conn_selected_id);
free(name_str);
- mapMe_setFacePending(mapme, name, fibEntry, conn_selected_id, true, true, 0);
+ mapme_setFacePending(mapme, name, fibEntry, conn_selected_id, true, true, 0);
}
#endif /* WITH_POLICY */
@@ -525,7 +530,7 @@ void mapMe_onPolicyUpdate(const MapMe *mapme, const Connection *conn_selected, F
/**
* @discussion This function is way too long and should be cut out
*/
-static bool mapMe_onSpecialInterest(const MapMe *mapme,
+static bool mapme_onSpecialInterest(const MapMe *mapme,
const uint8_t *msgBuffer,
unsigned conn_in_id, hicn_prefix_t *prefix,
mapme_params_t *params) {
@@ -551,7 +556,7 @@ static bool mapMe_onSpecialInterest(const MapMe *mapme,
* Immediately send an acknowledgement back on the ingress connection
* We always ack, even duplicates.
*/
- Message *ack = mapMe_createAckMessage(mapme, msgBuffer, params);
+ Message *ack = mapme_createAckMessage(mapme, msgBuffer, params);
if (!ack) goto ERR_ACK_CREATE;
rv = connection_ReSend(conn_in, ack, NOT_A_NOTIFICATION);
if (!rv) goto ERR_ACK_SEND;
@@ -584,7 +589,7 @@ static bool mapMe_onSpecialInterest(const MapMe *mapme,
fibEntry = fibEntry_Create(name, fwdStrategy);
#endif /* WITH_POLICY */
FibEntry *lpm = fib_MatchName(fib, name);
- mapMe_CreateTFIB(fibEntry);
+ mapme_CreateTFIB(fibEntry);
fib_Add(fib, fibEntry);
if (!lpm) {
TFIB(fibEntry)->seq = seq;
@@ -606,7 +611,7 @@ static bool mapMe_onSpecialInterest(const MapMe *mapme,
/* Create TFIB associated to FIB entry */
INFO(mapme,
"[MAP-Me] - Creating TFIB entry with default sequence number");
- mapMe_CreateTFIB(fibEntry);
+ mapme_CreateTFIB(fibEntry);
}
fibSeq = TFIB(fibEntry)->seq;
@@ -621,13 +626,13 @@ static bool mapMe_onSpecialInterest(const MapMe *mapme,
/* Reliably forward the IU on all prevHops */
INFO(mapme, "[MAP-Me] - (1/3) processing prev hops");
if (params->type == UPDATE) {
- PARCIterator *iterator = mapMeTFIB_CreateKeyIterator(TFIB(fibEntry));
+ PARCIterator *iterator = mapmeTFIB_CreateKeyIterator(TFIB(fibEntry));
while (parcIterator_HasNext(iterator)) {
PARCUnsigned *cid = parcIterator_Next(iterator);
unsigned conn_id = parcUnsigned_GetUnsigned(cid);
INFO(mapme, "[MAP-Me] - Re-sending IU to pending connection %d",
conn_id);
- mapMe_setFacePending(mapme, fibEntry_GetPrefix(fibEntry), fibEntry,
+ mapme_setFacePending(mapme, fibEntry_GetPrefix(fibEntry), fibEntry,
conn_id, false, false, 0);
}
parcIterator_Release(&iterator);
@@ -662,14 +667,14 @@ static bool mapMe_onSpecialInterest(const MapMe *mapme,
INFO(mapme, "[MAP-Me] - (3/3) next hops ~~> prev hops");
PARCEventTimer *oldTimer =
- (PARCEventTimer *)mapMeTFIB_Get(TFIB(fibEntry), conn_in_id);
+ (PARCEventTimer *)mapmeTFIB_Get(TFIB(fibEntry), conn_in_id);
if (oldTimer) {
/* This happens if we receive an IU while we are still sending
* one in the other direction
*/
INFO(mapme, "[MAP-Me] - Canceled pending timer");
parcEventTimer_Stop(oldTimer);
- mapMeTFIB_Remove(TFIB(fibEntry), conn_in_id);
+ mapmeTFIB_Remove(TFIB(fibEntry), conn_in_id);
}
/* Remove all next hops */
@@ -692,7 +697,7 @@ static bool mapMe_onSpecialInterest(const MapMe *mapme,
INFO(mapme, "[MAP-Me] - Sending IU on current next hop connection %d",
conn_id);
- mapMe_setFacePending(mapme, fibEntry_GetPrefix(fibEntry), fibEntry,
+ mapme_setFacePending(mapme, fibEntry_GetPrefix(fibEntry), fibEntry,
conn_id, send, false, 0);
complete = false;
}
@@ -716,7 +721,7 @@ static bool mapMe_onSpecialInterest(const MapMe *mapme,
* producer and that we received back our own IU. In that case, we just
* need to Ack and ignore it.
*/
- if (mapMe_hasLocalNextHops(mapme, fibEntry)) {
+ if (mapme_hasLocalNextHops(mapme, fibEntry)) {
INFO(mapme, "[MAP-Me] - Received original interest... Update complete");
return true;
}
@@ -736,7 +741,7 @@ static bool mapMe_onSpecialInterest(const MapMe *mapme,
mapme,
"[MAP-Me] - Update interest %d -> %d sent backwards on connection %d",
seq, fibSeq, conn_in_id);
- mapMe_setFacePending(mapme, fibEntry_GetPrefix(fibEntry), fibEntry,
+ mapme_setFacePending(mapme, fibEntry_GetPrefix(fibEntry), fibEntry,
conn_in_id, send, false, 0);
}
@@ -748,7 +753,7 @@ ERR_ACK_CREATE:
return false;
}
-void mapMe_onSpecialInterestAck(const MapMe *mapme, const uint8_t *msgBuffer,
+void mapme_onSpecialInterestAck(const MapMe *mapme, const uint8_t *msgBuffer,
unsigned conn_in_id, hicn_prefix_t *prefix,
mapme_params_t *params) {
INFO(mapme, "[MAP-Me] Receive IU/IN Ack on connection %d", conn_in_id);
@@ -793,7 +798,7 @@ void mapMe_onSpecialInterestAck(const MapMe *mapme, const uint8_t *msgBuffer,
}
PARCEventTimer *timer =
- (PARCEventTimer *)mapMeTFIB_Get(TFIB(fibEntry), conn_in_id);
+ (PARCEventTimer *)mapmeTFIB_Get(TFIB(fibEntry), conn_in_id);
if (!timer) {
INFO(mapme,
"[MAP-Me] - Ignored ACK for prefix not having the Connection in "
@@ -803,7 +808,7 @@ void mapMe_onSpecialInterestAck(const MapMe *mapme, const uint8_t *msgBuffer,
/* Stop timer and remove entry from TFIB */
parcEventTimer_Stop(timer);
- mapMeTFIB_Remove(TFIB(fibEntry), conn_in_id);
+ mapmeTFIB_Remove(TFIB(fibEntry), conn_in_id);
INFO(mapme, "[MAP-Me] - Removing TFIB entry for ack on connection %d",
conn_in_id);
@@ -831,7 +836,7 @@ void mapMe_onSpecialInterestAck(const MapMe *mapme, const uint8_t *msgBuffer,
/*
* Returns true iif the message corresponds to a MAP-Me packet
*/
-bool mapMe_isMapMe(const uint8_t *packet) {
+bool mapme_isMapMe(const uint8_t *packet) {
hicn_mapme_header_t * mapme = (hicn_mapme_header_t*)packet;
switch(HICN_IP_VERSION(packet)) {
@@ -859,7 +864,7 @@ bool mapMe_isMapMe(const uint8_t *packet) {
* MAP-Me (eg. ICMP packets) and return higher level messages that can be
* processed by MAP-Me core.
*/
-void mapMe_Process(const MapMe *mapme, const uint8_t *msgBuffer,
+void mapme_Process(const MapMe *mapme, const uint8_t *msgBuffer,
unsigned conn_id) {
hicn_prefix_t prefix;
mapme_params_t params;
@@ -868,11 +873,11 @@ void mapMe_Process(const MapMe *mapme, const uint8_t *msgBuffer,
switch (params.type) {
case UPDATE:
case NOTIFICATION:
- mapMe_onSpecialInterest(mapme, msgBuffer, conn_id, &prefix, &params);
+ mapme_onSpecialInterest(mapme, msgBuffer, conn_id, &prefix, &params);
break;
case UPDATE_ACK:
case NOTIFICATION_ACK:
- mapMe_onSpecialInterestAck(mapme, msgBuffer, conn_id, &prefix, &params);
+ mapme_onSpecialInterestAck(mapme, msgBuffer, conn_id, &prefix, &params);
break;
default:
ERR(mapme, "[MAP-Me] Unknown message");
diff --git a/hicn-light/src/hicn/core/mapMe.h b/hicn-light/src/hicn/core/mapme.h
index 7ea90d299..5888ccd21 100644
--- a/hicn-light/src/hicn/core/mapMe.h
+++ b/hicn-light/src/hicn/core/mapme.h
@@ -14,12 +14,12 @@
*/
/**
- * @file mapMe.h
+ * @file mapme.h
* @brief MAP-Me : AnchorLess Producer Mobility Management
*/
-#ifndef mapMe_h
-#define mapMe_h
+#ifndef mapme_h
+#define mapme_h
#ifdef WITH_MAPME
@@ -35,11 +35,17 @@ struct mapme;
typedef struct mapme MapMe;
/**
- * @function MapMe_Init
+ * @function mapme_create
* @abstract Initializes MAP-Me state in the forwarder.
* @return bool - Boolean informing about the success of MAP-Me initialization.
*/
-bool mapMe_Init(MapMe **mapme, Forwarder *Forwarder);
+bool mapme_create(MapMe **mapme, Forwarder *Forwarder);
+
+/**
+ * @function mapme_free
+ * @abstract Free MAP-Me state in the forwarder.
+ */
+void mapme_free(MapMe *mapme);
/**
* @function messageHandler_isMapMe
@@ -50,20 +56,20 @@ bool mapMe_Init(MapMe **mapme, Forwarder *Forwarder);
* @param [in] msgBuffer - The buffer to match
* @return A boolean indicating whether message is a MAP-Me control message.
*/
-bool mapMe_isMapMe(const uint8_t *msgBuffer);
+bool mapme_isMapMe(const uint8_t *msgBuffer);
/**
- * @function mapMe_handleMapMeMessage
+ * @function mapme_handleMapMeMessage
* @abstract Process a MAP-Me message.
* @param [in] mapme - Pointer to the MAP-Me data structure.
* @param [in] message - MAP-Me buffer
* @param [in] conn_id - Ingress connection id
*/
-void mapMe_Process(const MapMe *mapme, const uint8_t *msgBuffer,
+void mapme_Process(const MapMe *mapme, const uint8_t *msgBuffer,
unsigned conn_id);
/**
- * @function mapMe_onConnectionEvent
+ * @function mapme_onConnectionEvent
* @abstract Callback following the addition of the face though the control
* protocol.
* @discussion This callback triggers the sending of control packets by MAP-Me.
@@ -71,28 +77,28 @@ void mapMe_Process(const MapMe *mapme, const uint8_t *msgBuffer,
* @param [in] conn - The newly added connection.
* @param [in] event - Connection event
*/
-void mapMe_onConnectionEvent(const MapMe *mapme, const Connection *conn, connection_event_t event);
+void mapme_onConnectionEvent(const MapMe *mapme, const Connection *conn, connection_event_t event);
#ifdef WITH_POLICY
/**
- * @function mapMe_onPolicyUpdate
+ * @function mapme_onPolicyUpdate
*/
-void mapMe_onPolicyUpdate(const MapMe *mapme, const Connection *conn_added, FibEntry * fibEntry);
+void mapme_onPolicyUpdate(const MapMe *mapme, const Connection *conn_added, FibEntry * fibEntry);
#endif /* WITH_POLICY */
/**
- * @function mapMe_getNextHops
+ * @function mapme_getNextHops
* @abstract return the nexthops to forward interests defined by mapme, it
* covers also the case where local discovery mechanisms are trriggered.
*/
-NumberSet *mapMe_getNextHops(const MapMe *mapme, FibEntry *fibEntry,
+NumberSet *mapme_getNextHops(const MapMe *mapme, FibEntry *fibEntry,
const Message *interest);
-hicn_mapme_type_t mapMe_PktType_To_LibHicnPktType(MessagePacketType type);
+hicn_mapme_type_t mapme_PktType_To_LibHicnPktType(MessagePacketType type);
-MessagePacketType mapMe_LibHicnPktType_To_PktType(hicn_mapme_type_t type);
+MessagePacketType mapme_LibHicnPktType_To_PktType(hicn_mapme_type_t type);
#endif /* WITH_MAPME */
-#endif // mapMe_h
+#endif // mapme_h
diff --git a/hicn-light/src/hicn/core/messageHandler.h b/hicn-light/src/hicn/core/messageHandler.h
index f1f91bc40..e2f0140e5 100644
--- a/hicn-light/src/hicn/core/messageHandler.h
+++ b/hicn-light/src/hicn/core/messageHandler.h
@@ -57,7 +57,7 @@
#include <hicn/core/forwarder.h>
#ifdef WITH_MAPME
-#include <hicn/core/mapMe.h>
+#include <hicn/core/mapme.h>
#include <hicn/socket/api.h>
#endif /* WITH_MAPME */
@@ -274,7 +274,7 @@ static inline bool messageHandler_handleHooks(Forwarder * forwarder,
/* BEGIN Match */
#ifdef WITH_MAPME
- bool is_mapme = mapMe_isMapMe(packet);
+ bool is_mapme = mapme_isMapMe(packet);
is_matched |= is_mapme;
#endif /* WITH_MAPME */
@@ -310,7 +310,7 @@ static inline bool messageHandler_handleHooks(Forwarder * forwarder,
/* BEGIN Process */
#ifdef WITH_MAPME
- if (mapMe_isMapMe(packet))
+ if (mapme_isMapMe(packet))
forwarder_ProcessMapMe(forwarder, packet, conn_id);
#endif /* WITH_MAPME */
diff --git a/hicn-light/src/hicn/io/hicnListener.c b/hicn-light/src/hicn/io/hicnListener.c
index a60c4dd12..5a47982ff 100644
--- a/hicn-light/src/hicn/io/hicnListener.c
+++ b/hicn-light/src/hicn/io/hicnListener.c
@@ -31,7 +31,7 @@
#include <parc/algol/parc_Memory.h>
#include <parc/algol/parc_Network.h>
#include <parc/assert/parc_Assert.h>
-#include <hicn/core/mapMe.h>
+#include <hicn/core/mapme.h>
#include <hicn/core/messagePacketType.h>
#include <hicn/io/listener.h>
#include <hicn/socket/api.h>
diff --git a/hicn-light/src/hicn/io/listenerSet.c b/hicn-light/src/hicn/io/listenerSet.c
index 45dbe887a..d69632287 100644
--- a/hicn-light/src/hicn/io/listenerSet.c
+++ b/hicn-light/src/hicn/io/listenerSet.c
@@ -175,7 +175,7 @@ void listenerSet_RemoveById(const ListenerSet *set, unsigned id) {
ListenerOps *ops = parcArrayList_Get(set->listOfListeners, i);
parcAssertNotNull(ops, "Got null listener ops at index %zu", i);
if (ops->getInterfaceIndex(ops) == id) {
- parcArrayList_RemoveAtIndex(set->listOfListeners, i);
+ parcArrayList_RemoveAndDestroyAtIndex(set->listOfListeners, i);
break;
}
}
diff --git a/hicn-light/src/hicn/io/streamConnection.c b/hicn-light/src/hicn/io/streamConnection.c
index 08ff728d6..4e2f9c37e 100644
--- a/hicn-light/src/hicn/io/streamConnection.c
+++ b/hicn-light/src/hicn/io/streamConnection.c
@@ -598,6 +598,7 @@ static void _conn_readcb(PARCEventQueue *event, PARCEventType type,
// If received correctly the whole message, send to dispatcher
if (message) {
forwarder_ReceiveCommand(stream->forwarder, command, rx, stream->id);
+ parcMemory_Deallocate((void **)&rx);
parcEventBuffer_Destroy(&message);
}
diff --git a/hicn-light/src/hicn/io/udpListener.c b/hicn-light/src/hicn/io/udpListener.c
index f43756a11..e484dc2db 100644
--- a/hicn-light/src/hicn/io/udpListener.c
+++ b/hicn-light/src/hicn/io/udpListener.c
@@ -282,8 +282,13 @@ ListenerOps *udpListener_CreateInet(Forwarder *forwarder, char *listenerName,
myerrno, strerror(myerrno));
parcMemory_Deallocate((void **)&str);
}
-
+ parcMemory_Deallocate((void **)&udp->listenerName);
+ parcMemory_Deallocate((void **)&udp->interfaceName);
+#ifndef _WIN32
close(udp->udp_socket);
+#else
+ closesocket(udp->udp_socket);
+#endif
addressDestroy(&udp->localAddress);
logger_Release(&udp->logger);
parcMemory_Deallocate((void **)&udp);
@@ -304,6 +309,8 @@ static void udpListener_Destroy(UdpListener **listenerPtr) {
"UdpListener %p destroyed", (void *)udp);
}
+ parcMemory_Deallocate((void **)&udp->listenerName);
+ parcMemory_Deallocate((void **)&udp->interfaceName);
#ifndef _WIN32
close(udp->udp_socket);
#else
diff --git a/hicn-light/src/hicn/processor/fibEntry.c b/hicn-light/src/hicn/processor/fibEntry.c
index f12dd506b..28cf6b13c 100644
--- a/hicn-light/src/hicn/processor/fibEntry.c
+++ b/hicn-light/src/hicn/processor/fibEntry.c
@@ -42,7 +42,7 @@
#include <hicn/policy.h>
#ifdef WITH_MAPME
-#include <hicn/core/mapMe.h>
+#include <hicn/core/mapme.h>
#endif /* WITH_MAPME */
#define ALPHA 0.5
@@ -149,6 +149,9 @@ void fibEntry_Release(FibEntry **fibEntryPtr) {
fibEntry->userDataRelease(&fibEntry->userData);
}
#endif /* WITH_MAPME */
+#ifdef WITH_POLICY
+ numberSet_Release(&fibEntry->nexthops);
+#endif /* WITH_POLICY */
parcMemory_Deallocate((void **)&fibEntry);
}
*fibEntryPtr = NULL;
@@ -467,7 +470,7 @@ void fibEntry_ReconsiderPolicy(FibEntry *fibEntry) {
fibEntry->previous_nexthop = nexthop;
ConnectionTable * table = forwarder_GetConnectionTable(fibEntry->forwarder);
const Connection * conn = connectionTable_FindById(table, nexthop);
- mapMe_onPolicyUpdate(forwarder_getMapmeInstance(fibEntry->forwarder), conn, fibEntry);
+ mapme_onPolicyUpdate(forwarder_getMapmeInstance(fibEntry->forwarder), conn, fibEntry);
}
END:
diff --git a/hicn-light/src/hicn/processor/messageProcessor.c b/hicn-light/src/hicn/processor/messageProcessor.c
index 6598b9035..58220ac9c 100644
--- a/hicn-light/src/hicn/processor/messageProcessor.c
+++ b/hicn-light/src/hicn/processor/messageProcessor.c
@@ -403,6 +403,7 @@ void messageProcessor_onConnectionEvent(const MessageProcessor *processor,
FibEntry *fibEntry = (FibEntry *)fibEntryList_Get(fiblist, i);
fibEntry_ReconsiderPolicy(fibEntry);
}
+ fibEntryList_Destroy(&fiblist);
}
#endif /* WITH_MAPME */
diff --git a/hicn-light/src/hicn/socket/api.c b/hicn-light/src/hicn/socket/api.c
index a3d5a3cfe..34c0aae54 100644
--- a/hicn-light/src/hicn/socket/api.c
+++ b/hicn-light/src/hicn/socket/api.c
@@ -72,7 +72,8 @@ hicn_socket_helper_t *hicn_create() {
}
hicn->conf = malloc(sizeof(hicn_conf_t));
- if (hicn->conf < 0) goto ERR_CONF;
+ if (hicn->conf < 0)
+ goto ERR_CONF;
memcpy(hicn->conf, &hicn_default_conf, sizeof(hicn_conf_t));
/* Initialize socket tree to empty */
@@ -126,64 +127,56 @@ ERR_MALLOC:
void hicn_destroy() {
int rc;
+ int ret = 0;
uint16_t i;
/* Restore default rules */
printf("Restoring default configuration.\n");
rc = ops.del_lo_prio_rule(NULL, AF_INET6, LOCAL_PRIORITY);
- if (rc < 0) {
- goto ERR;
- }
+ if (rc < 0)
+ ret = -1;
rc = ops.del_lo_prio_rule(NULL, AF_INET, LOCAL_PRIORITY);
- if (rc < 0) {
- goto ERR;
- }
+ if (rc < 0)
+ ret = -1;
rc = ops.add_lo_prio_rule(NULL, AF_INET6, 0);
- if (rc < 0) {
- goto ERR;
- }
+ if (rc < 0)
+ ret = -1;
rc = ops.add_lo_prio_rule(NULL, AF_INET, 0);
- if (rc < 0) {
- goto ERR;
- }
+ if (rc < 0)
+ ret = -1;
for (i = 0; i < rules_counter; i++) {
if (strcmp(rules_to_remove[i].tun_name, "NONE") != 0) {
rc = ops.del_rule(rules_to_remove[i].tun_name,
rules_to_remove[i].address_family,
rules_to_remove[i].table_id);
- if (rc < 0) {
- goto ERR;
- }
} else {
rc = ops.del_prio_rule(
&rules_to_remove[i].prefix, rules_to_remove[i].address_family,
rules_to_remove[i].priority, rules_to_remove[i].table_id);
- if (rc < 0) {
- goto ERR;
- }
}
+ if (rc < 0)
+ ret = -1;
}
for (i = 0; i < routes_counter; i++) {
rc = ops.del_out_route(routes_to_remove[i].remote_ip_address,
routes_to_remove[i].address_family,
routes_to_remove[i].table_id);
- if (rc < 0) {
- goto ERR;
- }
+ if (rc < 0)
+ ret = -1;
}
-ERR:
- if (rc < 0) printf("Unexpected exit. Some state may not be deleted.\n");
- return;
+ if (ret < 0)
+ printf("Unexpected exit. Some state may not be deleted.\n");
}
void hicn_free(hicn_socket_helper_t *hicn) {
- // close tun ?
+ hicn_destroy();
+ free(hicn->conf);
free(hicn);
}
diff --git a/hicn-light/src/hicn/strategies/loadBalancer.c b/hicn-light/src/hicn/strategies/loadBalancer.c
index ca9d34289..e3f377791 100644
--- a/hicn-light/src/hicn/strategies/loadBalancer.c
+++ b/hicn-light/src/hicn/strategies/loadBalancer.c
@@ -323,6 +323,10 @@ static void _strategyLoadBalancer_RemoveNexthop(StrategyImpl *strategy,
PARCUnsigned *cid = parcUnsigned_Create(connectionId);
if (parcHashMap_Contains(lb->strategy_state, cid)) {
+ StrategyNexthopState *state =
+ (StrategyNexthopState *)parcHashMap_Get(lb->strategy_state, cid);
+ parcObject_Release((void**)&state);
+
parcHashMap_Remove(lb->strategy_state, cid);
#ifndef WITH_POLICY
numberSet_Remove(lb->nexthops, connectionId);
@@ -341,6 +345,15 @@ static void _strategyLoadBalancer_ImplDestroy(StrategyImpl **strategyPtr) {
StrategyImpl *impl = *strategyPtr;
StrategyLoadBalancer *strategy = (StrategyLoadBalancer *)impl->context;
+ PARCIterator *it = parcHashMap_CreateKeyIterator(strategy->strategy_state);
+ while (parcIterator_HasNext(it)) {
+ PARCUnsigned *cid = parcIterator_Next(it);
+ StrategyNexthopState *state =
+ (StrategyNexthopState *)parcHashMap_Get(strategy->strategy_state, cid);
+ parcObject_Release((void**)&state);
+ }
+ parcIterator_Release(&it);
+
parcHashMap_Release(&(strategy->strategy_state));
#ifndef WITH_POLICY
numberSet_Release(&(strategy->nexthops));