PUD: remove rx sockets from OLSR when closing interfaces
authorFerry Huberts <f.huberts@mindef.nl>
Wed, 28 Sep 2011 09:16:21 +0000 (11:16 +0200)
committerFerry Huberts <f.huberts@mindef.nl>
Wed, 28 Sep 2011 09:16:31 +0000 (11:16 +0200)
Signed-off-by: Ferry Huberts <f.huberts@mindef.nl>
lib/pud/src/networkInterfaces.c
lib/pud/src/networkInterfaces.h

index 83fbc5a..e55bd21 100644 (file)
@@ -210,6 +210,7 @@ static bool createRxInterface(const char * ifName, union olsr_sockaddr ipAddr,
        memcpy(networkInterface->name, ifName, sizeof(networkInterface->name));
        networkInterface->name[IFNAMSIZ] = '\0';
        networkInterface->ipAddress = ipAddr;
+       networkInterface->handler = NULL;
        memcpy(&networkInterface->hwAddress[0], hwAddr,
                        sizeof(networkInterface->hwAddress));
        networkInterface->next = NULL;
@@ -220,6 +221,7 @@ static bool createRxInterface(const char * ifName, union olsr_sockaddr ipAddr,
                goto bail;
        }
        networkInterface->socketFd = socketFd;
+       networkInterface->handler = rxSocketHandlerFunction;
 
        /* Add new object to the end of the global list. */
        if (rxNetworkInterfacesListHead == NULL) {
@@ -397,6 +399,7 @@ static bool createTxInterface(const char * ifName, union olsr_sockaddr ipAddr) {
        memcpy(networkInterface->name, ifName, sizeof(networkInterface->name));
        networkInterface->name[IFNAMSIZ] = '\0';
        networkInterface->ipAddress = ipAddr;
+       networkInterface->handler = NULL;
        memcpy(&networkInterface->hwAddress[0], hwAddr,
                        sizeof(networkInterface->hwAddress));
        networkInterface->next = NULL;
@@ -622,6 +625,10 @@ static void closeInterfaces(TRxTxNetworkInterface * networkInterface) {
        while (nextNetworkInterface != NULL) {
                TRxTxNetworkInterface * iteratedNetworkInterface = nextNetworkInterface;
                if (iteratedNetworkInterface->socketFd >= 0) {
+                       if (iteratedNetworkInterface->handler) {
+                               remove_olsr_socket(iteratedNetworkInterface->socketFd,
+                                               iteratedNetworkInterface->handler, NULL);
+                       }
                        close(iteratedNetworkInterface->socketFd);
                        iteratedNetworkInterface->socketFd = -1;
                }
index 4bdaca0..d7a024d 100644 (file)
@@ -23,6 +23,9 @@ typedef struct _TRxTxNetworkInterface {
                /** The IP address of the interface */
                union olsr_sockaddr ipAddress;
 
+               /** the socket handler function */
+               socket_handler_func handler;
+
                /** The hardware address of the interface */
                unsigned char hwAddress[IFHWADDRLEN];