From 4ab25212ee38de5dfd4571d23714a777ec051b5f Mon Sep 17 00:00:00 2001 From: Uglymotha Date: Fri, 8 May 2020 17:52:45 +0200 Subject: [PATCH 01/45] timing --- src/callout.c | 206 +++++++++++------------------------------------- src/config.c | 123 +++++++++++++++++++++++++++++ src/ifvc.c | 152 +++-------------------------------- src/igmpproxy.c | 78 ++++++------------ src/igmpproxy.h | 28 +++++-- src/rttable.c | 14 +++- 6 files changed, 241 insertions(+), 360 deletions(-) diff --git a/src/callout.c b/src/callout.c index c49da6cf..c4ab4292 100644 --- a/src/callout.c +++ b/src/callout.c @@ -37,26 +37,19 @@ /* the code below implements a callout queue */ static int id = 0; -static struct timeOutQueue *queue = 0; /* pointer to the beginning of timeout queue */ +static struct timeOutQueue *queue = NULL; /* pointer to the beginning of timeout queue */ struct timeOutQueue { struct timeOutQueue *next; // Next event in queue int id; timer_f func; // function to call void *data; // Data for function - int time; // Time offset for next event + long time; // Time for event }; // Method for dumping the Queue to the log. static void debugQueue(void); -/** -* Initializes the callout queue -*/ -void callout_init(void) { - queue = NULL; -} - /** * Clears all scheduled timeouts... */ @@ -70,58 +63,22 @@ void free_all_callouts(void) { } } - /** - * elapsed_time seconds have passed; perform all the events that should - * happen. + * Execute all expired timers, using .5s grace. */ -void age_callout_queue(int elapsed_time) { - struct timeOutQueue *ptr; - struct timeOutQueue *_queue = NULL; - struct timeOutQueue *last = NULL; - int i = 0; - - for (ptr = queue; ptr; ptr = ptr->next) { - if (ptr->time > elapsed_time) { - ptr->time -= elapsed_time; - break; - } else { - elapsed_time -= ptr->time; - if (_queue == NULL) - _queue = ptr; - last = ptr; - } - } - - queue = ptr; - if (last) { - last->next = NULL; - } - - /* process existing events */ - for (ptr = _queue; ptr; ptr = _queue, i++) { - _queue = _queue->next; +void age_callout_queue(struct timespec curtime) { + struct timeOutQueue *ptr = queue; + int i = 1; + + if (curtime.tv_sec == 0) clock_gettime (CLOCK_MONOTONIC, &curtime); + while (ptr && ((ptr->time <= curtime.tv_sec) || ( curtime.tv_nsec >= 500000000 && ptr->time <= curtime.tv_sec-1))) { my_log(LOG_DEBUG, 0, "About to call timeout %d (#%d)", ptr->id, i); - if (ptr->func) - ptr->func(ptr->data); - free(ptr); - } -} - -/** - * Return in how many seconds age_callout_queue() would like to be called. - * Return -1 if there are no events pending. - */ -int timer_nextTimer(void) { - if (queue) { - if (queue->time < 0) { - my_log(LOG_WARNING, 0, "timer_nextTimer top of queue says %d", - queue->time); - return 0; - } - return queue->time; + struct timeOutQueue *tmp = ptr; + if (ptr->func) ptr->func(ptr->data); + queue = ptr = ptr->next; + free(tmp); + i++; } - return -1; } /** @@ -131,61 +88,41 @@ int timer_nextTimer(void) { * @param data - Pointer to the function data to supply... */ int timer_setTimer(int delay, timer_f action, void *data) { - struct timeOutQueue *ptr, *node, *prev; - int i = 0; + struct timeOutQueue *ptr = queue, *node; + struct timespec curtime; + int i = 1; - /* create a node */ + // create a node. node = (struct timeOutQueue *)malloc(sizeof(struct timeOutQueue)); if (node == 0) { my_log(LOG_WARNING, 0, "Malloc Failed in timer_settimer\n"); return -1; } + clock_gettime(CLOCK_MONOTONIC, &curtime); node->func = action; node->data = data; - node->time = delay; - node->next = 0; + node->time = curtime.tv_sec + delay; + node->next = NULL; node->id = ++id; - prev = ptr = queue; - - /* insert node in the queue */ - - /* if the queue is empty, insert the node and return */ - if (!queue) { - queue = node; - } + // if the queue is empty, insert the node and return. + if (!queue) queue = node; else { - /* chase the pointer looking for the right place */ - while (ptr) { - if (delay < ptr->time) { - // We found the correct node - node->next = ptr; - if (ptr == queue) { - queue = node; - } - else { - prev->next = node; - } - ptr->time -= node->time; - my_log(LOG_DEBUG, 0, - "Created timeout %d (#%d) - delay %d secs", - node->id, i, node->time); - debugQueue(); - return node->id; - } else { - // Continur to check nodes. - delay -= ptr->time; node->time = delay; - prev = ptr; - ptr = ptr->next; - } - i++; + // chase the queue looking for the right place. + for ( i++; ptr->next && node->time >= ptr->next->time; ptr = ptr->next ) i++; + if ( ptr == queue && node->time < ptr->time ) { + // Start of queue, insert. + queue = node; node->next = ptr; + } else if ( ptr->next ) { + // Middle of queue, insert + node->next = ptr->next; ptr->next = node; + } else { + // End of queue, append. + ptr->next = node; } - prev->next = node; } - my_log(LOG_DEBUG, 0, "Created timeout %d (#%d) - delay %d secs", - node->id, i, node->time); debugQueue(); - + my_log(LOG_DEBUG, 0, "Created timeout %d (#%d) - delay %d secs", node->id, i, delay); return node->id; } @@ -193,77 +130,26 @@ int timer_setTimer(int delay, timer_f action, void *data) { * returns the time until the timer is scheduled */ int timer_leftTimer(int timer_id) { - struct timeOutQueue *ptr; - int left = 0; - - if (!timer_id) - return -1; - - for (ptr = queue; ptr; ptr = ptr->next) { - left += ptr->time; - if (ptr->id == timer_id) { - return left; - } + struct timeOutQueue *ptr = queue; + struct timespec curtime; + + if (!timer_id || !queue) return -1; + while (ptr && ptr->id != timer_id) ptr = ptr->next; + if ( ptr ){ + clock_gettime (CLOCK_MONOTONIC, &curtime); + return (ptr->time - curtime.tv_sec); } return -1; } -/** -* clears the associated timer. Returns 1 if succeeded. -*/ -int timer_clearTimer(int timer_id) { - struct timeOutQueue *ptr, *prev; - int i = 0; - - if (!timer_id) - return 0; - - prev = ptr = queue; - - /* - * find the right node, delete it. the subsequent node's time - * gets bumped up - */ - - debugQueue(); - while (ptr) { - if (ptr->id == timer_id) { - /* got the right node */ - - /* unlink it from the queue */ - if (ptr == queue) - queue = queue->next; - else - prev->next = ptr->next; - - /* increment next node if any */ - if (ptr->next != 0) - (ptr->next)->time += ptr->time; - - if (ptr->data) - free(ptr->data); - my_log(LOG_DEBUG, 0, "deleted timer %d (#%d)", ptr->id, i); - free(ptr); - debugQueue(); - return 1; - } - prev = ptr; - ptr = ptr->next; - i++; - } - // If we get here, the timer was not deleted. - my_log(LOG_DEBUG, 0, "failed to delete timer %d (#%d)", timer_id, i); - debugQueue(); - return 0; -} - /** * debugging utility */ static void debugQueue(void) { - struct timeOutQueue *ptr; + struct timeOutQueue *ptr; int i = 1; for (ptr = queue; ptr; ptr = ptr->next) { - my_log(LOG_DEBUG, 0, "(Id:%d, Time:%d) ", ptr->id, ptr->time); + my_log(LOG_DEBUG, 0, "(%d - Id:%d, Time:%d) ", i, ptr->id, ptr->time); + i++; } } diff --git a/src/config.c b/src/config.c index 030da1ac..c34cf414 100644 --- a/src/config.c +++ b/src/config.c @@ -100,6 +100,38 @@ struct Config *getCommonConfig(void) { return &commonConfig; } +// Reloads the configuration file and removes interfaces which were removed from config. +void reloadConfig() { + struct IfDesc *Dp; + struct vifconfig *OldConfPtr, *NewConfPtr, *TmpConfPtr; + + // Load the new configuration keep reference to the old. + OldConfPtr = vifconf; + if ( ! loadConfig(configFilePath) ) my_log(LOG_ERR, 0, "reloadConfig: Unable to load config file."); + + // Rebuild the interfaces config. + rebuildIfVc(); + + my_log(LOG_DEBUG, 0, "reloadConfig: Config Reloaded. OldConfPtr %x, NewConfPtr, %x", OldConfPtr, vifconf); + // Free all the old mallocd subnetlists and vifconf list. + while ( OldConfPtr ) { + TmpConfPtr=OldConfPtr->next; // Increment before free or pointers may be invalid. + struct SubnetList *TmpNetPtr; + for ( ; OldConfPtr->allowednets; ) { + TmpNetPtr = OldConfPtr->allowednets->next; + free (OldConfPtr->allowednets); + OldConfPtr->allowednets = TmpNetPtr; + } + for ( ; OldConfPtr->allowedgroups; ) { + TmpNetPtr = OldConfPtr->allowedgroups->next; + free (OldConfPtr->allowedgroups); + OldConfPtr->allowedgroups = TmpNetPtr; + } + free (OldConfPtr); + OldConfPtr = TmpConfPtr; + } +} + /** * Loads the configuration from file, and stores the config in * respective holders... @@ -260,6 +292,97 @@ void configureVifs(void) { } } +/* create VIFs for all IP, non-loop interfaces. + When argument is not NULL rebuild the interface table. +*/ +void createVifs(struct IfDescP *RebuildP) { + struct IfDesc *Dp, *oDp = NULL; + int vifcount = 0, upsvifcount = 0, Ix = 0; + bool join = 0; + + // init array to "not set" + for ( Ix = 0; Ix < MAX_UPS_VIFS; Ix++) upStreamIfIdx[Ix] = -1; + + if ( RebuildP != NULL ) { + // When rebuild, check if interfaces have dissapeared and call delVIF if necessary. + for ( oDp=RebuildP->S; oDpE; oDp++ ) { + for ( Ix = 0; (Dp = getIfByIx(Ix)); Ix++ ) if ( ! strcmp (oDp->Name, Dp->Name) ) break; + if ( Dp == NULL ) { + my_log(LOG_DEBUG, 0, "Interface %s disappeared from system", oDp->Name ); + if ( oDp->index != -1 ) delVIF(oDp); + } + } + } + + for ( Ix = 0; (Dp = getIfByIx(Ix)); Ix++ ) { + if ( RebuildP == NULL ) { + // Only add vif for valid interfaces on start-up. + if ( (Dp->Flags & IFF_LOOPBACK) || (Dp->state != IF_STATE_DOWNSTREAM && Dp->state != IF_STATE_UPSTREAM) ) continue; + } else { + /* Need rebuild, check if interface is new or already exists (check table below). + old: disabled new: disabled -> do nothing + old: disabled new: downstream -> addVIF(new), joinmcroutergroups + old: disabled new: upstream -> addVIF(new) + old: downstream new: disabled -> delVIF(old) + state table old: downstream new: downstream -> addvif(new,old) + old: downstream new: upstream -> delvif(old), addvif(new) + old: upstream new: disabled -> clear routes oldvif, delVIF(old) + old: upstream new: downstream -> clear routes oldvif, delvif(old)),addvif(new), joinmcroutergroup + old: upstream new: upstream -> addvif(new,old) + */ + for ( oDp=RebuildP->S; oDpE; oDp++ ) if ( ! strcmp (oDp->Name, Dp->Name) ) break; + if ( oDp < RebuildP->E ) { + switch (oDp->state) { + case IF_STATE_DISABLED: + switch (Dp->state) { + case IF_STATE_DISABLED: { continue; } + case IF_STATE_DOWNSTREAM: { oDp=NULL; join=1; break; } + case IF_STATE_UPSTREAM: { oDp=NULL; break; } + } + break; + case IF_STATE_DOWNSTREAM: + switch (Dp->state) { + case IF_STATE_DISABLED: { delVIF(oDp); continue; } + case IF_STATE_DOWNSTREAM: { break; } + case IF_STATE_UPSTREAM: { delVIF(oDp); oDp=NULL; break; } + } + break; + case IF_STATE_UPSTREAM: + switch (Dp->state) { + case IF_STATE_DISABLED: { clearRoutes(oDp); delVIF(oDp); continue; } + case IF_STATE_DOWNSTREAM: { clearRoutes(oDp); delVIF(oDp); oDp=NULL; join=1; break; } + case IF_STATE_UPSTREAM: { break; } + } + break; + } + if (Dp->Flags & IFF_LOOPBACK) continue; + } else { + // New Interface. Only add valid up/downstream vif. + if ( (Dp->Flags & IFF_LOOPBACK) || (Dp->state != IF_STATE_DOWNSTREAM && Dp->state != IF_STATE_UPSTREAM) ) continue; + oDp=NULL; + } + } + if(Dp->state == IF_STATE_UPSTREAM) { + if (upsvifcount < MAX_UPS_VIFS -1) + { + my_log(LOG_DEBUG, 0, "Found upstream IF #%d, will assign as upstream Vif %d", + upsvifcount, Ix); + upStreamIfIdx[upsvifcount++] = Ix; + } else { + my_log(LOG_ERR, 0, "Cannot set VIF #%d as upstream as well. Max upstream Vif count is %d", + Ix, MAX_UPS_VIFS); + } + } + addVIF( Dp ); + if ( join ) joinMcRoutersGroup(Dp); + vifcount++; + } + + // All vifs created, check if there is an upstream and at least one downstream. + if ( upsvifcount == 0 || vifcount == upsvifcount ) { + my_log(LOG_ERR, 0, "There must be at least 1 Vif as upstream and 1 as dowstream."); + } +} /** * Internal function to parse phyint config diff --git a/src/ifvc.c b/src/ifvc.c index 509012f0..b39a0fc3 100644 --- a/src/ifvc.c +++ b/src/ifvc.c @@ -42,6 +42,7 @@ static inline uint32_t s_addr_from_sockaddr(const struct sockaddr *addr) { } struct IfDesc IfDescVc[ MAX_IF ], *IfDescEp = IfDescVc; +struct IfDescP IfDescP = { NULL, NULL, 0 }; /* aimwang: add for detect interface and rebuild IfVc record */ /*************************************************** @@ -50,149 +51,22 @@ struct IfDesc IfDescVc[ MAX_IF ], *IfDescEp = IfDescVc; * So I can check if the file exist then run me and delete the file. ***************************************************/ void rebuildIfVc () { - struct ifreq IfVc[ sizeof( IfDescVc ) / sizeof( IfDescVc[ 0 ] ) ]; - struct ifreq *IfEp; - struct ifconf IoCtlReq; - struct IfDesc *Dp; - struct ifreq *IfPt, *IfNext; - uint32_t addr, subnet, mask; - int Sock; + // Build new IfDesc Table. Keep Copy of Old. + struct IfDescP OldIfDescP=IfDescP, TmpIfDescP=IfDescP; + buildIfVc(); - // Get the config. - struct Config *config = getCommonConfig(); + // Call configureVifs to link the new IfDesc table. + configureVifs(); - if ( (Sock = socket( AF_INET, SOCK_DGRAM, 0 )) < 0 ) - my_log( LOG_ERR, errno, "RAW socket open" ); + // Call createvifs with pointer to old IfDesc table for relinking vifs and removing or adding interfaces if required. + my_log (LOG_DEBUG,0,"RebuildIfVc: creating vifs, Old IfDescP: %x, New: %x", OldIfDescP.S, IfDescP.S); + createVifs(&OldIfDescP); - // aimwang: set all downstream IF as lost, for check IF exist or gone. - for (Dp = IfDescVc; Dp < IfDescEp; Dp++) { - if (Dp->state == IF_STATE_DOWNSTREAM) { - Dp->state = IF_STATE_LOST; - } + // Free the old IfDesc Table. + if ( OldIfDescP.S != NULL ) { + for (struct IfDesc *Dp = TmpIfDescP.S; Dp < TmpIfDescP.E; Dp++) free(Dp->allowednets); + free(OldIfDescP.S); } - - IoCtlReq.ifc_buf = (void *)IfVc; - IoCtlReq.ifc_len = sizeof( IfVc ); - - if ( ioctl( Sock, SIOCGIFCONF, &IoCtlReq ) < 0 ) - my_log( LOG_ERR, errno, "ioctl SIOCGIFCONF" ); - - IfEp = (void *)((char *)IfVc + IoCtlReq.ifc_len); - - for ( IfPt = IfVc; IfPt < IfEp; IfPt = IfNext ) { - struct ifreq IfReq; - char FmtBu[ 32 ]; - - IfNext = (struct ifreq *)((char *)&IfPt->ifr_addr + -#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN - IfPt->ifr_addr.sa_len -#else - sizeof(struct sockaddr_in) -#endif - ); - if (IfNext < IfPt + 1) - IfNext = IfPt + 1; - - for (Dp = IfDescVc; Dp < IfDescEp; Dp++) { - if (0 == strcmp(Dp->Name, IfPt->ifr_name)) { - break; - } - } - - if (Dp == IfDescEp) { - strncpy( Dp->Name, IfPt->ifr_name, sizeof( IfDescEp->Name ) ); - } - - if ( IfPt->ifr_addr.sa_family != AF_INET ) { - if (Dp == IfDescEp) { - IfDescEp++; - } - Dp->InAdr.s_addr = 0; /* mark as non-IP interface */ - continue; - } - - // Get the interface adress... - Dp->InAdr.s_addr = s_addr_from_sockaddr(&IfPt->ifr_addr); - addr = Dp->InAdr.s_addr; - - memcpy( IfReq.ifr_name, Dp->Name, sizeof( IfReq.ifr_name ) ); - - // Get the subnet mask... - if (ioctl(Sock, SIOCGIFNETMASK, &IfReq ) < 0) - my_log(LOG_ERR, errno, "ioctl SIOCGIFNETMASK for %s", IfReq.ifr_name); - mask = s_addr_from_sockaddr(&IfReq.ifr_addr); // Do not use ifr_netmask as it is not available on freebsd - subnet = addr & mask; - - if ( ioctl( Sock, SIOCGIFFLAGS, &IfReq ) < 0 ) - my_log( LOG_ERR, errno, "ioctl SIOCGIFFLAGS" ); - Dp->Flags = IfReq.ifr_flags; - - if (0x10d1 == Dp->Flags) - { - if ( ioctl( Sock, SIOCGIFDSTADDR, &IfReq ) < 0 ) - my_log(LOG_ERR, errno, "ioctl SIOCGIFDSTADDR for %s", IfReq.ifr_name); - addr = s_addr_from_sockaddr(&IfReq.ifr_dstaddr); - subnet = addr & mask; - } - - if (Dp == IfDescEp) { - // Insert the verified subnet as an allowed net... - Dp->allowednets = (struct SubnetList *)malloc(sizeof(struct SubnetList)); - if(IfDescEp->allowednets == NULL) { - my_log(LOG_ERR, 0, "Out of memory !"); - } - Dp->allowednets->next = NULL; - Dp->state = IF_STATE_DOWNSTREAM; - Dp->robustness = DEFAULT_ROBUSTNESS; - Dp->threshold = DEFAULT_THRESHOLD; /* ttl limit */ - Dp->ratelimit = DEFAULT_RATELIMIT; - } - - // Set the network address for the IF.. - Dp->allowednets->subnet_mask = mask; - Dp->allowednets->subnet_addr = subnet; - - // Set the state for the IF... - if (Dp->state == IF_STATE_LOST) { - Dp->state = IF_STATE_DOWNSTREAM; - } - - // when IF become enabeld from downstream, addVIF to enable its VIF - if (Dp->state == IF_STATE_HIDDEN) { - my_log(LOG_NOTICE, 0, "%s [Hidden -> Downstream]", Dp->Name); - Dp->state = IF_STATE_DOWNSTREAM; - addVIF(Dp); - joinMcGroup(getMcGroupSock(), Dp, allrouters_group); - } - - // addVIF when found new IF - if (Dp == IfDescEp) { - my_log(LOG_NOTICE, 0, "%s [New]", Dp->Name); - Dp->state = config->defaultInterfaceState; - addVIF(Dp); - joinMcGroup(getMcGroupSock(), Dp, allrouters_group); - IfDescEp++; - } - - // Debug log the result... - my_log( LOG_DEBUG, 0, "rebuildIfVc: Interface %s Addr: %s, Flags: 0x%04x, Network: %s", - Dp->Name, - fmtInAdr( FmtBu, Dp->InAdr ), - Dp->Flags, - inetFmts(subnet, mask, s1)); - } - - // aimwang: search not longer exist IF, set as hidden and call delVIF - for (Dp = IfDescVc; Dp < IfDescEp; Dp++) { - if (IF_STATE_LOST == Dp->state) { - my_log(LOG_NOTICE, 0, "%s [Downstream -> Hidden]", Dp->Name); - Dp->state = IF_STATE_HIDDEN; - leaveMcGroup( getMcGroupSock(), Dp, allrouters_group ); - delVIF(Dp); - } - } - - close( Sock ); } /* diff --git a/src/igmpproxy.c b/src/igmpproxy.c index c72a567f..be95370f 100644 --- a/src/igmpproxy.c +++ b/src/igmpproxy.c @@ -38,8 +38,10 @@ */ /* getopt() and clock_getime() */ -#ifndef _POSIX_C_SOURCE -#define _POSIX_C_SOURCE 200112L +#ifndef __FreeBSD__ + #ifndef _POSIX_C_SOURCE + #define _POSIX_C_SOURCE 200112L + #endif #endif #include "igmpproxy.h" @@ -113,7 +115,7 @@ int main( int ArgCn, char *ArgVc[] ) { fputs("You must specify the configuration file.\n", stderr); exit(1); } - char *configFilePath = ArgVc[optind]; + configFilePath = ArgVc[optind]; // Chech that we are root if (geteuid() != 0) { @@ -238,7 +240,7 @@ int igmpProxyInit(void) { // Initialize Routing table initRouteTable(); // Initialize timer - callout_init(); + free_all_callouts(); return 1; } @@ -250,7 +252,7 @@ void igmpProxyCleanUp(void) { my_log( LOG_DEBUG, 0, "clean handler called" ); free_all_callouts(); // No more timeouts. - clearAllRoutes(); // Remove all routes. + clearRoutes(NULL); // Remove all routes. disableMRouter(); // Disable the multirout API } @@ -265,18 +267,16 @@ void igmpProxyRun(void) { int MaxFD, Rt, secs; fd_set ReadFDS; socklen_t dummy = 0; - struct timespec curtime, lasttime, difftime, tv; - // The timeout is a pointer in order to set it to NULL if nessecary. - struct timespec *timeout = &tv; + struct timespec curtime, lasttime, difftime, *timeout = &difftime; + + // First thing we send a membership query in downstream VIF's... + sendGeneralMembershipQuery(); // Initialize timer vars difftime.tv_nsec = 0; clock_gettime(CLOCK_MONOTONIC, &curtime); lasttime = curtime; - // First thing we send a membership query in downstream VIF's... - sendGeneralMembershipQuery(); - // Loop until the end... for (;;) { @@ -289,17 +289,21 @@ void igmpProxyRun(void) { } } - /* aimwang: call rebuildIfVc */ - if (config->rescanVif) - rebuildIfVc(); - - // Prepare timeout... - secs = timer_nextTimer(); - if(secs == -1) { - timeout = NULL; + // Timeout = 1s - difference between current and last time age_callout queue with .01s grace. + // This will make sure age_callout_queue is run once every s (timer resolution) +- 0.01s. + // If aging queues takes > .01s on very slow systems or when queue is very large, + // this will become less accurate by about the time it takes to age the queue + time to process a request. + clock_gettime(CLOCK_MONOTONIC, &curtime); + difftime.tv_sec = curtime.tv_sec - lasttime.tv_sec; + if (curtime.tv_nsec >= lasttime.tv_nsec ) { + timeout->tv_nsec = 999999999 - (curtime.tv_nsec - lasttime.tv_nsec); } else { - timeout->tv_nsec = 0; - timeout->tv_sec = (secs > 3) ? 3 : secs; // aimwang: set max timeout + timeout->tv_nsec = 999999999 - (1000000000 - lasttime.tv_nsec + curtime.tv_nsec); difftime.tv_sec--; + } + if ( difftime.tv_sec > 0 || timeout->tv_nsec < 10000000 ) { + timeout->tv_nsec = 999999999; timeout->tv_sec = 0; + lasttime = curtime; + age_callout_queue(curtime); } // Prepare for select. @@ -331,39 +335,7 @@ void igmpProxyRun(void) { acceptIgmp(recvlen); } } - - // At this point, we can handle timeouts... - do { - /* - * If the select timed out, then there's no other - * activity to account for and we don't need to - * call gettimeofday. - */ - if (Rt == 0) { - curtime.tv_sec = lasttime.tv_sec + secs; - curtime.tv_nsec = lasttime.tv_nsec; - Rt = -1; /* don't do this next time through the loop */ - } else { - clock_gettime(CLOCK_MONOTONIC, &curtime); - } - difftime.tv_sec = curtime.tv_sec - lasttime.tv_sec; - difftime.tv_nsec += curtime.tv_nsec - lasttime.tv_nsec; - while (difftime.tv_nsec > 1000000000) { - difftime.tv_sec++; - difftime.tv_nsec -= 1000000000; - } - if (difftime.tv_nsec < 0) { - difftime.tv_sec--; - difftime.tv_nsec += 1000000000; - } - lasttime = curtime; - if (secs == 0 || difftime.tv_sec > 0) - age_callout_queue(difftime.tv_sec); - secs = -1; - } while (difftime.tv_sec > 0); - } - } /* diff --git a/src/igmpproxy.h b/src/igmpproxy.h index 5e25b23a..b6811a9d 100644 --- a/src/igmpproxy.h +++ b/src/igmpproxy.h @@ -35,8 +35,10 @@ * igmpproxy.h - Header file for common includes. */ -#include "config.h" -#include "os.h" +#ifndef __FreeBSD__ + #include "config.h" + #include "os.h" +#endif #include #include @@ -60,6 +62,11 @@ #include #include +#ifdef __FreeBSD__ + #include "config.h" + #include "os.h" +#endif + /* * Limit on length of route data */ @@ -158,6 +165,12 @@ struct IfDesc { unsigned int index; }; +struct IfDescP { + struct IfDesc *S; + struct IfDesc *E; + unsigned int nrint; +}; + // Keeps common configuration settings struct Config { unsigned int robustnessValue; @@ -216,8 +229,11 @@ int getVifIx( struct IfDesc *IfDp ); /* config.c */ +char *configFilePath; +void reloadConfig(); int loadConfig(char *configFile); void configureVifs(void); +void createVifs(struct IfDescP *RebuildP); struct Config *getCommonConfig(void); /* igmp.c @@ -261,7 +277,8 @@ int leaveMcGroup( int UdpSock, struct IfDesc *IfDp, uint32_t mcastaddr ); /* rttable.c */ void initRouteTable(void); -void clearAllRoutes(void); +void joinMcRoutersGroup(struct IfDesc *Dp); +void clearRoutes(struct IfDesc *IfDp); int insertRoute(uint32_t group, int ifx, uint32_t src); int activateRoute(uint32_t group, uint32_t originAddr, int upstrVif); void ageActiveRoutes(void); @@ -280,12 +297,9 @@ void sendGeneralMembershipQuery(void); */ typedef void (*timer_f)(void *); -void callout_init(void); void free_all_callouts(void); -void age_callout_queue(int); -int timer_nextTimer(void); +void age_callout_queue(struct timespec curtime); int timer_setTimer(int, timer_f, void *); -int timer_clearTimer(int); int timer_leftTimer(int); /* confread.c diff --git a/src/rttable.c b/src/rttable.c index 3d33c77e..024a0c98 100644 --- a/src/rttable.c +++ b/src/rttable.c @@ -153,6 +153,18 @@ void initRouteTable(void) { } } +void joinMcRoutersGroup(struct IfDesc *Dp) { + my_log(LOG_DEBUG, 0, "Joining all-routers group %s on vif %s", + inetFmt(allrouters_group,s1),inetFmt(Dp->InAdr.s_addr,s2)); + + //k_join(allrouters_group, Dp->InAdr.s_addr); + joinMcGroup( getMcGroupSock(), Dp, allrouters_group ); + + my_log(LOG_DEBUG, 0, "Joining all igmpv3 multicast routers group %s on vif %s", + inetFmt(alligmp3_group,s1),inetFmt(Dp->InAdr.s_addr,s2)); + joinMcGroup( getMcGroupSock(), Dp, alligmp3_group ); +} + /** * Internal function to send join or leave requests for * a specified route upstream... @@ -228,7 +240,7 @@ static void sendJoinLeaveUpstream(struct RouteTable* route, int join) { /** * Clear all routes from routing table, and alerts Leaves upstream. */ -void clearAllRoutes(void) { +void clearRoutes(struct IfDesc *IfDp) { struct RouteTable *croute, *remainroute; // Loop through all routes... From 9fbfe5f1dc70c53acf02c8787665a92968045e86 Mon Sep 17 00:00:00 2001 From: Uglymotha Date: Sat, 9 May 2020 09:10:37 +0200 Subject: [PATCH 02/45] config.h to top --- src/igmpproxy.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/igmpproxy.h b/src/igmpproxy.h index b6811a9d..69ca23a3 100644 --- a/src/igmpproxy.h +++ b/src/igmpproxy.h @@ -35,8 +35,8 @@ * igmpproxy.h - Header file for common includes. */ +#include "config.h" #ifndef __FreeBSD__ - #include "config.h" #include "os.h" #endif @@ -63,7 +63,6 @@ #include #ifdef __FreeBSD__ - #include "config.h" #include "os.h" #endif From 5dd7a68a612edea29618d7e1c294564a53a2b8fb Mon Sep 17 00:00:00 2001 From: Uglymotha Date: Sat, 9 May 2020 09:20:25 +0200 Subject: [PATCH 03/45] Remove unused variables from reloadconfig() --- src/config.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/config.c b/src/config.c index c34cf414..f5b019ea 100644 --- a/src/config.c +++ b/src/config.c @@ -102,8 +102,7 @@ struct Config *getCommonConfig(void) { // Reloads the configuration file and removes interfaces which were removed from config. void reloadConfig() { - struct IfDesc *Dp; - struct vifconfig *OldConfPtr, *NewConfPtr, *TmpConfPtr; + struct vifconfig *OldConfPtr, *TmpConfPtr; // Load the new configuration keep reference to the old. OldConfPtr = vifconf; From 26489a00328e4748fc6b22ba306d2a56bd764846 Mon Sep 17 00:00:00 2001 From: Uglymotha Date: Sat, 9 May 2020 09:22:43 +0200 Subject: [PATCH 04/45] IfDesc.index -> signed --- src/igmpproxy.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/igmpproxy.h b/src/igmpproxy.h index 69ca23a3..ade4ad11 100644 --- a/src/igmpproxy.h +++ b/src/igmpproxy.h @@ -161,7 +161,7 @@ struct IfDesc { unsigned int robustness; unsigned char threshold; /* ttl limit */ unsigned int ratelimit; - unsigned int index; + signed int index; }; struct IfDescP { From 4a1d3304d27739db3a7070551a9d58280adff3bd Mon Sep 17 00:00:00 2001 From: Uglymotha Date: Sat, 9 May 2020 09:23:34 +0200 Subject: [PATCH 05/45] vifindex -> signed --- src/ifvc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ifvc.c b/src/ifvc.c index b39a0fc3..be48c62a 100644 --- a/src/ifvc.c +++ b/src/ifvc.c @@ -260,7 +260,7 @@ struct IfDesc *getIfByAddress( uint32_t ipaddr ) { * the supplied IP adress. The IP must match a interfaces * subnet, or any configured allowed subnet on a interface. */ -struct IfDesc *getIfByVifIndex( unsigned vifindex ) { +struct IfDesc *getIfByVifIndex( signed vifindex ) { struct IfDesc *Dp; if(vifindex>0) { for ( Dp = IfDescVc; Dp < IfDescEp; Dp++ ) { From 822b619055f9e0cfb05d05a53b57596b1fd3cab1 Mon Sep 17 00:00:00 2001 From: Uglymotha Date: Sat, 9 May 2020 09:24:49 +0200 Subject: [PATCH 06/45] vifindex / upstrvif -> signed --- src/igmpproxy.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/igmpproxy.h b/src/igmpproxy.h index ade4ad11..4c0912c8 100644 --- a/src/igmpproxy.h +++ b/src/igmpproxy.h @@ -203,7 +203,7 @@ void buildIfVc( void ); struct IfDesc *getIfByName( const char *IfName ); struct IfDesc *getIfByIx( unsigned Ix ); struct IfDesc *getIfByAddress( uint32_t Ix ); -struct IfDesc *getIfByVifIndex( unsigned vifindex ); +struct IfDesc *getIfByVifIndex( signed vifindex ); int isAdressValidForIf(struct IfDesc* intrface, uint32_t ipaddr); /* mroute-api.c @@ -279,7 +279,7 @@ void initRouteTable(void); void joinMcRoutersGroup(struct IfDesc *Dp); void clearRoutes(struct IfDesc *IfDp); int insertRoute(uint32_t group, int ifx, uint32_t src); -int activateRoute(uint32_t group, uint32_t originAddr, int upstrVif); +int activateRoute(uint32_t group, uint32_t originAddr, signed upstrVif); void ageActiveRoutes(void); void setRouteLastMemberMode(uint32_t group, uint32_t src); int lastMemberGroupAge(uint32_t group); From 1c6340bd7603eb576706a9cddd57b949c49324ec Mon Sep 17 00:00:00 2001 From: Uglymotha Date: Sat, 9 May 2020 09:25:56 +0200 Subject: [PATCH 07/45] upstrvif -> signed --- src/rttable.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rttable.c b/src/rttable.c index 024a0c98..b7358712 100644 --- a/src/rttable.c +++ b/src/rttable.c @@ -442,7 +442,7 @@ int insertRoute(uint32_t group, int ifx, uint32_t src) { * activated, it's reinstalled in the kernel. If * the route is activated, no originAddr is needed. */ -int activateRoute(uint32_t group, uint32_t originAddr, int upstrVif) { +int activateRoute(uint32_t group, uint32_t originAddr, signed upstrVif) { struct RouteTable* croute; int result = 0; From d0fa83adcc2c668709f9fbe91b83c22ebd4b236d Mon Sep 17 00:00:00 2001 From: Uglymotha Date: Sat, 9 May 2020 09:26:56 +0200 Subject: [PATCH 08/45] vifindex -> signed --- src/igmp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/igmp.c b/src/igmp.c index 38914377..e9265619 100644 --- a/src/igmp.c +++ b/src/igmp.c @@ -166,7 +166,7 @@ void acceptIgmp(int recvlen) { } } else { // Activate the route. - int vifindex = checkVIF->index; + signed vifindex = checkVIF->index; my_log(LOG_DEBUG, 0, "Route activate request from %s to %s on VIF[%d]", inetFmt(src,s1), inetFmt(dst,s2), vifindex); activateRoute(dst, src, vifindex); From d44ad8a5cdb6c838d3d5fac98536b26771bff9f3 Mon Sep 17 00:00:00 2001 From: Uglymotha Date: Sat, 9 May 2020 09:35:20 +0200 Subject: [PATCH 09/45] if (upsvifcount >= MAX_UPS_VIFS) --- src/config.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/config.c b/src/config.c index f5b019ea..132567d0 100644 --- a/src/config.c +++ b/src/config.c @@ -362,14 +362,12 @@ void createVifs(struct IfDescP *RebuildP) { } } if(Dp->state == IF_STATE_UPSTREAM) { - if (upsvifcount < MAX_UPS_VIFS -1) - { - my_log(LOG_DEBUG, 0, "Found upstream IF #%d, will assign as upstream Vif %d", - upsvifcount, Ix); - upStreamIfIdx[upsvifcount++] = Ix; - } else { + if (upsvifcount >= MAX_UPS_VIFS) { my_log(LOG_ERR, 0, "Cannot set VIF #%d as upstream as well. Max upstream Vif count is %d", Ix, MAX_UPS_VIFS); + } else { + my_log(LOG_DEBUG, 0, "Found upstream IF #%d, will assign as upstream Vif %d", upsvifcount, Ix); + upStreamIfIdx[upsvifcount++] = Ix; } } addVIF( Dp ); From e5ed28fdf3f7c3bed24928a0ee6e11cbd6502e20 Mon Sep 17 00:00:00 2001 From: Uglymotha Date: Sat, 9 May 2020 10:10:19 +0200 Subject: [PATCH 10/45] reintroduce use of confg variable prevents a compiler warning without removing the declarion of config from igmpproxy run, as it will be used later. --- src/igmpproxy.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/igmpproxy.c b/src/igmpproxy.c index be95370f..7d3f003a 100644 --- a/src/igmpproxy.c +++ b/src/igmpproxy.c @@ -264,7 +264,7 @@ void igmpProxyRun(void) { struct Config *config = getCommonConfig(); // Set some needed values. register int recvlen; - int MaxFD, Rt, secs; + int MaxFD, Rt; fd_set ReadFDS; socklen_t dummy = 0; struct timespec curtime, lasttime, difftime, *timeout = &difftime; @@ -289,6 +289,8 @@ void igmpProxyRun(void) { } } + if (config->rescanVif) (void)0; + // Timeout = 1s - difference between current and last time age_callout queue with .01s grace. // This will make sure age_callout_queue is run once every s (timer resolution) +- 0.01s. // If aging queues takes > .01s on very slow systems or when queue is very large, From 1b7f5537d600c7d0e33cb5fb7ca9222db694f64b Mon Sep 17 00:00:00 2001 From: Uglymotha Date: Sun, 10 May 2020 08:50:35 +0200 Subject: [PATCH 11/45] ifdp->index -> signed --- src/mroute-api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mroute-api.c b/src/mroute-api.c index fae4ab02..94cafeeb 100644 --- a/src/mroute-api.c +++ b/src/mroute-api.c @@ -100,7 +100,7 @@ void delVIF( struct IfDesc *IfDp ) { struct vifctl VifCtl; - if ((unsigned int)-1 == IfDp->index) + if ((signed int)-1 == IfDp->index) return; VifCtl.vifc_vifi = IfDp->index; From 5c2602169f86b3f5a8cdc7e6de59ab230c007d61 Mon Sep 17 00:00:00 2001 From: Uglymotha Date: Sun, 10 May 2020 09:10:58 +0200 Subject: [PATCH 12/45] function definition - includes --- src/igmpproxy.h | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/igmpproxy.h b/src/igmpproxy.h index 4c0912c8..271ac393 100644 --- a/src/igmpproxy.h +++ b/src/igmpproxy.h @@ -36,9 +36,7 @@ */ #include "config.h" -#ifndef __FreeBSD__ - #include "os.h" -#endif +#include "os.h" #include #include @@ -62,10 +60,6 @@ #include #include -#ifdef __FreeBSD__ - #include "os.h" -#endif - /* * Limit on length of route data */ @@ -229,7 +223,7 @@ int getVifIx( struct IfDesc *IfDp ); /* config.c */ char *configFilePath; -void reloadConfig(); +void reloadConfig(void); int loadConfig(char *configFile); void configureVifs(void); void createVifs(struct IfDescP *RebuildP); From 4ba9b437dddba225a4223841472e196a4c54cdbc Mon Sep 17 00:00:00 2001 From: Uglymotha Date: Sun, 10 May 2020 09:21:10 +0200 Subject: [PATCH 13/45] style fixes --- src/config.c | 54 +++++++++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/src/config.c b/src/config.c index 132567d0..f3625c94 100644 --- a/src/config.c +++ b/src/config.c @@ -101,7 +101,7 @@ struct Config *getCommonConfig(void) { } // Reloads the configuration file and removes interfaces which were removed from config. -void reloadConfig() { +void reloadConfig(void) { struct vifconfig *OldConfPtr, *TmpConfPtr; // Load the new configuration keep reference to the old. @@ -297,26 +297,30 @@ void configureVifs(void) { void createVifs(struct IfDescP *RebuildP) { struct IfDesc *Dp, *oDp = NULL; int vifcount = 0, upsvifcount = 0, Ix = 0; - bool join = 0; + bool join = false; // init array to "not set" - for ( Ix = 0; Ix < MAX_UPS_VIFS; Ix++) upStreamIfIdx[Ix] = -1; + for (Ix = 0; Ix < MAX_UPS_VIFS; Ix++) { + upStreamIfIdx[Ix] = -1; + } - if ( RebuildP != NULL ) { + if (RebuildP != NULL) { // When rebuild, check if interfaces have dissapeared and call delVIF if necessary. - for ( oDp=RebuildP->S; oDpE; oDp++ ) { - for ( Ix = 0; (Dp = getIfByIx(Ix)); Ix++ ) if ( ! strcmp (oDp->Name, Dp->Name) ) break; - if ( Dp == NULL ) { - my_log(LOG_DEBUG, 0, "Interface %s disappeared from system", oDp->Name ); - if ( oDp->index != -1 ) delVIF(oDp); + for (oDp=RebuildP->S; oDpE; oDp++) { + for (Ix = 0; (Dp = getIfByIx(Ix)); Ix++) { + if (! strcmp (oDp->Name, Dp->Name)) break; + } + if (Dp == NULL) { + my_log(LOG_DEBUG, 0, "Interface %s disappeared from system", oDp->Name); + if (oDp->index != -1) delVIF(oDp); } } } - for ( Ix = 0; (Dp = getIfByIx(Ix)); Ix++ ) { - if ( RebuildP == NULL ) { + for(Ix = 0; Dp = getIfByIx(Ix); Ix++) { + if (RebuildP == NULL) { // Only add vif for valid interfaces on start-up. - if ( (Dp->Flags & IFF_LOOPBACK) || (Dp->state != IF_STATE_DOWNSTREAM && Dp->state != IF_STATE_UPSTREAM) ) continue; + if ((Dp->Flags & IFF_LOOPBACK) || (Dp->state != IF_STATE_DOWNSTREAM && Dp->state != IF_STATE_UPSTREAM)) continue; } else { /* Need rebuild, check if interface is new or already exists (check table below). old: disabled new: disabled -> do nothing @@ -329,35 +333,37 @@ void createVifs(struct IfDescP *RebuildP) { old: upstream new: downstream -> clear routes oldvif, delvif(old)),addvif(new), joinmcroutergroup old: upstream new: upstream -> addvif(new,old) */ - for ( oDp=RebuildP->S; oDpE; oDp++ ) if ( ! strcmp (oDp->Name, Dp->Name) ) break; + for ( oDp=RebuildP->S; oDpE; oDp++ ) { + if ( ! strcmp (oDp->Name, Dp->Name) ) break; + } if ( oDp < RebuildP->E ) { switch (oDp->state) { case IF_STATE_DISABLED: switch (Dp->state) { - case IF_STATE_DISABLED: { continue; } - case IF_STATE_DOWNSTREAM: { oDp=NULL; join=1; break; } - case IF_STATE_UPSTREAM: { oDp=NULL; break; } + case IF_STATE_DISABLED: { continue; } + case IF_STATE_DOWNSTREAM: { oDp=NULL; join=true; break; } + case IF_STATE_UPSTREAM: { oDp=NULL; break; } } break; case IF_STATE_DOWNSTREAM: switch (Dp->state) { - case IF_STATE_DISABLED: { delVIF(oDp); continue; } - case IF_STATE_DOWNSTREAM: { break; } - case IF_STATE_UPSTREAM: { delVIF(oDp); oDp=NULL; break; } + case IF_STATE_DISABLED: { delVIF(oDp); continue; } + case IF_STATE_DOWNSTREAM: { break; } + case IF_STATE_UPSTREAM: { delVIF(oDp); oDp=NULL; break; } } break; case IF_STATE_UPSTREAM: switch (Dp->state) { - case IF_STATE_DISABLED: { clearRoutes(oDp); delVIF(oDp); continue; } - case IF_STATE_DOWNSTREAM: { clearRoutes(oDp); delVIF(oDp); oDp=NULL; join=1; break; } - case IF_STATE_UPSTREAM: { break; } + case IF_STATE_DISABLED: { clearRoutes(oDp); delVIF(oDp); continue; } + case IF_STATE_DOWNSTREAM: { clearRoutes(oDp); delVIF(oDp); oDp=NULL; join=true; break; } + case IF_STATE_UPSTREAM: { break; } } break; } if (Dp->Flags & IFF_LOOPBACK) continue; } else { // New Interface. Only add valid up/downstream vif. - if ( (Dp->Flags & IFF_LOOPBACK) || (Dp->state != IF_STATE_DOWNSTREAM && Dp->state != IF_STATE_UPSTREAM) ) continue; + if ((Dp->Flags & IFF_LOOPBACK) || (Dp->state != IF_STATE_DOWNSTREAM && Dp->state != IF_STATE_UPSTREAM)) continue; oDp=NULL; } } @@ -376,7 +382,7 @@ void createVifs(struct IfDescP *RebuildP) { } // All vifs created, check if there is an upstream and at least one downstream. - if ( upsvifcount == 0 || vifcount == upsvifcount ) { + if (upsvifcount == 0 || vifcount == upsvifcount) { my_log(LOG_ERR, 0, "There must be at least 1 Vif as upstream and 1 as dowstream."); } } From 4b98f3c92d240a32bcc7406338d5478205a941a8 Mon Sep 17 00:00:00 2001 From: Uglymotha Date: Sun, 10 May 2020 09:33:15 +0200 Subject: [PATCH 14/45] style fixes --- src/callout.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/callout.c b/src/callout.c index c4ab4292..6cba7864 100644 --- a/src/callout.c +++ b/src/callout.c @@ -71,10 +71,12 @@ void age_callout_queue(struct timespec curtime) { int i = 1; if (curtime.tv_sec == 0) clock_gettime (CLOCK_MONOTONIC, &curtime); - while (ptr && ((ptr->time <= curtime.tv_sec) || ( curtime.tv_nsec >= 500000000 && ptr->time <= curtime.tv_sec-1))) { + while (ptr && ((ptr->time <= curtime.tv_sec) || (curtime.tv_nsec >= 500000000 && ptr->time <= curtime.tv_sec-1))) { my_log(LOG_DEBUG, 0, "About to call timeout %d (#%d)", ptr->id, i); struct timeOutQueue *tmp = ptr; - if (ptr->func) ptr->func(ptr->data); + if (ptr->func) { + ptr->func(ptr->data); + } queue = ptr = ptr->next; free(tmp); i++; @@ -109,13 +111,15 @@ int timer_setTimer(int delay, timer_f action, void *data) { if (!queue) queue = node; else { // chase the queue looking for the right place. - for ( i++; ptr->next && node->time >= ptr->next->time; ptr = ptr->next ) i++; - if ( ptr == queue && node->time < ptr->time ) { + for (i++; ptr->next && node->time >= ptr->next->time; ptr = ptr->next, i++); + if (ptr == queue && node->time < ptr->time) { // Start of queue, insert. - queue = node; node->next = ptr; + queue = node; + node->next = ptr; } else if ( ptr->next ) { // Middle of queue, insert - node->next = ptr->next; ptr->next = node; + node->next = ptr->next; + ptr->next = node; } else { // End of queue, append. ptr->next = node; @@ -134,8 +138,10 @@ int timer_leftTimer(int timer_id) { struct timespec curtime; if (!timer_id || !queue) return -1; - while (ptr && ptr->id != timer_id) ptr = ptr->next; - if ( ptr ){ + while (ptr && ptr->id != timer_id) { + ptr = ptr->next; + } + if (ptr){ clock_gettime (CLOCK_MONOTONIC, &curtime); return (ptr->time - curtime.tv_sec); } @@ -146,10 +152,10 @@ int timer_leftTimer(int timer_id) { * debugging utility */ static void debugQueue(void) { - struct timeOutQueue *ptr; int i = 1; + struct timeOutQueue *ptr; + int i = 1; - for (ptr = queue; ptr; ptr = ptr->next) { + for (ptr = queue; ptr; ptr = ptr->next, i++) { my_log(LOG_DEBUG, 0, "(%d - Id:%d, Time:%d) ", i, ptr->id, ptr->time); - i++; } } From bed0b9d66cc88d5502dffeb5f848aeee48352340 Mon Sep 17 00:00:00 2001 From: Uglymotha Date: Sun, 10 May 2020 09:38:46 +0200 Subject: [PATCH 15/45] style fixes --- src/config.c | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/src/config.c b/src/config.c index f3625c94..1daf77cd 100644 --- a/src/config.c +++ b/src/config.c @@ -106,22 +106,24 @@ void reloadConfig(void) { // Load the new configuration keep reference to the old. OldConfPtr = vifconf; - if ( ! loadConfig(configFilePath) ) my_log(LOG_ERR, 0, "reloadConfig: Unable to load config file."); + if (! loadConfig(configFilePath)) { + my_log(LOG_ERR, 0, "reloadConfig: Unable to load config file."); + } // Rebuild the interfaces config. rebuildIfVc(); my_log(LOG_DEBUG, 0, "reloadConfig: Config Reloaded. OldConfPtr %x, NewConfPtr, %x", OldConfPtr, vifconf); // Free all the old mallocd subnetlists and vifconf list. - while ( OldConfPtr ) { + while (OldConfPtr) { TmpConfPtr=OldConfPtr->next; // Increment before free or pointers may be invalid. struct SubnetList *TmpNetPtr; - for ( ; OldConfPtr->allowednets; ) { + while (OldConfPtr->allowednets) { TmpNetPtr = OldConfPtr->allowednets->next; free (OldConfPtr->allowednets); OldConfPtr->allowednets = TmpNetPtr; } - for ( ; OldConfPtr->allowedgroups; ) { + while (OldConfPtr->allowedgroups) { TmpNetPtr = OldConfPtr->allowedgroups->next; free (OldConfPtr->allowedgroups); OldConfPtr->allowedgroups = TmpNetPtr; @@ -308,11 +310,15 @@ void createVifs(struct IfDescP *RebuildP) { // When rebuild, check if interfaces have dissapeared and call delVIF if necessary. for (oDp=RebuildP->S; oDpE; oDp++) { for (Ix = 0; (Dp = getIfByIx(Ix)); Ix++) { - if (! strcmp (oDp->Name, Dp->Name)) break; + if (! strcmp (oDp->Name, Dp->Name)) { + break; + } } if (Dp == NULL) { my_log(LOG_DEBUG, 0, "Interface %s disappeared from system", oDp->Name); - if (oDp->index != -1) delVIF(oDp); + if (oDp->index != -1) { + delVIF(oDp); + } } } } @@ -320,7 +326,9 @@ void createVifs(struct IfDescP *RebuildP) { for(Ix = 0; Dp = getIfByIx(Ix); Ix++) { if (RebuildP == NULL) { // Only add vif for valid interfaces on start-up. - if ((Dp->Flags & IFF_LOOPBACK) || (Dp->state != IF_STATE_DOWNSTREAM && Dp->state != IF_STATE_UPSTREAM)) continue; + if ((Dp->Flags & IFF_LOOPBACK) || (Dp->state != IF_STATE_DOWNSTREAM && Dp->state != IF_STATE_UPSTREAM)) { + continue; + } } else { /* Need rebuild, check if interface is new or already exists (check table below). old: disabled new: disabled -> do nothing @@ -333,8 +341,10 @@ void createVifs(struct IfDescP *RebuildP) { old: upstream new: downstream -> clear routes oldvif, delvif(old)),addvif(new), joinmcroutergroup old: upstream new: upstream -> addvif(new,old) */ - for ( oDp=RebuildP->S; oDpE; oDp++ ) { - if ( ! strcmp (oDp->Name, Dp->Name) ) break; + for (oDp=RebuildP->S; oDpE; oDp++) { + if (! strcmp (oDp->Name, Dp->Name)) { + break; + } } if ( oDp < RebuildP->E ) { switch (oDp->state) { @@ -360,10 +370,14 @@ void createVifs(struct IfDescP *RebuildP) { } break; } - if (Dp->Flags & IFF_LOOPBACK) continue; + if (Dp->Flags & IFF_LOOPBACK) { + continue; + } } else { // New Interface. Only add valid up/downstream vif. - if ((Dp->Flags & IFF_LOOPBACK) || (Dp->state != IF_STATE_DOWNSTREAM && Dp->state != IF_STATE_UPSTREAM)) continue; + if ((Dp->Flags & IFF_LOOPBACK) || (Dp->state != IF_STATE_DOWNSTREAM && Dp->state != IF_STATE_UPSTREAM)) { + continue; + } oDp=NULL; } } @@ -376,8 +390,10 @@ void createVifs(struct IfDescP *RebuildP) { upStreamIfIdx[upsvifcount++] = Ix; } } - addVIF( Dp ); - if ( join ) joinMcRoutersGroup(Dp); + addVIF(Dp); + if (join) { + joinMcRoutersGroup(Dp); + } vifcount++; } From 8a495aeb93dbc3c385a4c9c6f1b79d084c5beaa9 Mon Sep 17 00:00:00 2001 From: Uglymotha Date: Sun, 10 May 2020 09:43:28 +0200 Subject: [PATCH 16/45] style fixes --- src/igmpproxy.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/igmpproxy.c b/src/igmpproxy.c index 7d3f003a..fcdec153 100644 --- a/src/igmpproxy.c +++ b/src/igmpproxy.c @@ -300,9 +300,10 @@ void igmpProxyRun(void) { if (curtime.tv_nsec >= lasttime.tv_nsec ) { timeout->tv_nsec = 999999999 - (curtime.tv_nsec - lasttime.tv_nsec); } else { - timeout->tv_nsec = 999999999 - (1000000000 - lasttime.tv_nsec + curtime.tv_nsec); difftime.tv_sec--; + timeout->tv_nsec = 999999999 - (1000000000 - lasttime.tv_nsec + curtime.tv_nsec); + difftime.tv_sec--; } - if ( difftime.tv_sec > 0 || timeout->tv_nsec < 10000000 ) { + if (difftime.tv_sec > 0 || timeout->tv_nsec < 10000000) { timeout->tv_nsec = 999999999; timeout->tv_sec = 0; lasttime = curtime; age_callout_queue(curtime); From 1db3ae31bb34413b5546f53e0e17d08db72b737f Mon Sep 17 00:00:00 2001 From: Uglymotha Date: Sun, 10 May 2020 09:46:11 +0200 Subject: [PATCH 17/45] style fixes --- src/ifvc.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/ifvc.c b/src/ifvc.c index be48c62a..91754bc6 100644 --- a/src/ifvc.c +++ b/src/ifvc.c @@ -63,8 +63,10 @@ void rebuildIfVc () { createVifs(&OldIfDescP); // Free the old IfDesc Table. - if ( OldIfDescP.S != NULL ) { - for (struct IfDesc *Dp = TmpIfDescP.S; Dp < TmpIfDescP.E; Dp++) free(Dp->allowednets); + if (OldIfDescP.S != NULL) { + for (struct IfDesc *Dp = TmpIfDescP.S; Dp < TmpIfDescP.E; Dp++) { + free(Dp->allowednets); + } free(OldIfDescP.S); } } @@ -260,7 +262,7 @@ struct IfDesc *getIfByAddress( uint32_t ipaddr ) { * the supplied IP adress. The IP must match a interfaces * subnet, or any configured allowed subnet on a interface. */ -struct IfDesc *getIfByVifIndex( signed vifindex ) { +struct IfDesc *getIfByVifIndex( int vifindex ) { struct IfDesc *Dp; if(vifindex>0) { for ( Dp = IfDescVc; Dp < IfDescEp; Dp++ ) { From 53cdf60ef0d6c2a77c4ad400d3c8d072bc40a94c Mon Sep 17 00:00:00 2001 From: Uglymotha Date: Sun, 10 May 2020 09:48:01 +0200 Subject: [PATCH 18/45] style fixes --- src/config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.c b/src/config.c index 1daf77cd..b8279cb9 100644 --- a/src/config.c +++ b/src/config.c @@ -249,7 +249,7 @@ int loadConfig(char *configFile) { * Appends extra VIF configuration from config file. */ void configureVifs(void) { - unsigned Ix; + int Ix; struct IfDesc *Dp; struct vifconfig *confPtr; From 0b08284becf8fdbd517ebe3837f2cbe02b6180f1 Mon Sep 17 00:00:00 2001 From: Uglymotha Date: Sun, 10 May 2020 09:49:22 +0200 Subject: [PATCH 19/45] style fixes --- src/igmp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/igmp.c b/src/igmp.c index e9265619..38914377 100644 --- a/src/igmp.c +++ b/src/igmp.c @@ -166,7 +166,7 @@ void acceptIgmp(int recvlen) { } } else { // Activate the route. - signed vifindex = checkVIF->index; + int vifindex = checkVIF->index; my_log(LOG_DEBUG, 0, "Route activate request from %s to %s on VIF[%d]", inetFmt(src,s1), inetFmt(dst,s2), vifindex); activateRoute(dst, src, vifindex); From fab1b190a9e2106c46c4f3e09992decb1a713a27 Mon Sep 17 00:00:00 2001 From: Uglymotha Date: Sun, 10 May 2020 09:50:30 +0200 Subject: [PATCH 20/45] style fixes --- src/mroute-api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mroute-api.c b/src/mroute-api.c index 94cafeeb..138002b8 100644 --- a/src/mroute-api.c +++ b/src/mroute-api.c @@ -100,7 +100,7 @@ void delVIF( struct IfDesc *IfDp ) { struct vifctl VifCtl; - if ((signed int)-1 == IfDp->index) + if ((int)-1 == IfDp->index) return; VifCtl.vifc_vifi = IfDp->index; From f55af1045c06ab38a70bf5c8cc254bdd2ddef128 Mon Sep 17 00:00:00 2001 From: Uglymotha Date: Sun, 10 May 2020 09:53:18 +0200 Subject: [PATCH 21/45] style fixes --- src/rttable.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/rttable.c b/src/rttable.c index b7358712..b49721d1 100644 --- a/src/rttable.c +++ b/src/rttable.c @@ -158,11 +158,11 @@ void joinMcRoutersGroup(struct IfDesc *Dp) { inetFmt(allrouters_group,s1),inetFmt(Dp->InAdr.s_addr,s2)); //k_join(allrouters_group, Dp->InAdr.s_addr); - joinMcGroup( getMcGroupSock(), Dp, allrouters_group ); + joinMcGroup(getMcGroupSock(), Dp, allrouters_group); my_log(LOG_DEBUG, 0, "Joining all igmpv3 multicast routers group %s on vif %s", inetFmt(alligmp3_group,s1),inetFmt(Dp->InAdr.s_addr,s2)); - joinMcGroup( getMcGroupSock(), Dp, alligmp3_group ); + joinMcGroup(getMcGroupSock(), Dp, alligmp3_group); } /** @@ -442,7 +442,7 @@ int insertRoute(uint32_t group, int ifx, uint32_t src) { * activated, it's reinstalled in the kernel. If * the route is activated, no originAddr is needed. */ -int activateRoute(uint32_t group, uint32_t originAddr, signed upstrVif) { +int activateRoute(uint32_t group, uint32_t originAddr, int upstrVif) { struct RouteTable* croute; int result = 0; From cc4774423238fd6961cc5b657eab990abaea4950 Mon Sep 17 00:00:00 2001 From: Uglymotha Date: Sun, 10 May 2020 09:54:33 +0200 Subject: [PATCH 22/45] style fixes --- src/igmpproxy.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/igmpproxy.h b/src/igmpproxy.h index 271ac393..55fa75fb 100644 --- a/src/igmpproxy.h +++ b/src/igmpproxy.h @@ -155,7 +155,7 @@ struct IfDesc { unsigned int robustness; unsigned char threshold; /* ttl limit */ unsigned int ratelimit; - signed int index; + int index; }; struct IfDescP { @@ -197,7 +197,7 @@ void buildIfVc( void ); struct IfDesc *getIfByName( const char *IfName ); struct IfDesc *getIfByIx( unsigned Ix ); struct IfDesc *getIfByAddress( uint32_t Ix ); -struct IfDesc *getIfByVifIndex( signed vifindex ); +struct IfDesc *getIfByVifIndex( int vifindex ); int isAdressValidForIf(struct IfDesc* intrface, uint32_t ipaddr); /* mroute-api.c @@ -273,7 +273,7 @@ void initRouteTable(void); void joinMcRoutersGroup(struct IfDesc *Dp); void clearRoutes(struct IfDesc *IfDp); int insertRoute(uint32_t group, int ifx, uint32_t src); -int activateRoute(uint32_t group, uint32_t originAddr, signed upstrVif); +int activateRoute(uint32_t group, uint32_t originAddr, int upstrVif); void ageActiveRoutes(void); void setRouteLastMemberMode(uint32_t group, uint32_t src); int lastMemberGroupAge(uint32_t group); From 7e084960b6e47d9cc74fdbf9bd05a476b4dcd0e5 Mon Sep 17 00:00:00 2001 From: Uglymotha Date: Sun, 10 May 2020 09:55:18 +0200 Subject: [PATCH 23/45] style fixes --- src/igmpproxy.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/igmpproxy.c b/src/igmpproxy.c index fcdec153..1754dc7c 100644 --- a/src/igmpproxy.c +++ b/src/igmpproxy.c @@ -38,10 +38,8 @@ */ /* getopt() and clock_getime() */ -#ifndef __FreeBSD__ - #ifndef _POSIX_C_SOURCE - #define _POSIX_C_SOURCE 200112L - #endif +#ifndef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200112L #endif #include "igmpproxy.h" From 0c17249cccea74cb7c2e2dfeff2e38a5d458dc83 Mon Sep 17 00:00:00 2001 From: Uglymotha Date: Sun, 10 May 2020 09:56:11 +0200 Subject: [PATCH 24/45] clearroutes --- src/igmpproxy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/igmpproxy.c b/src/igmpproxy.c index 1754dc7c..51abcf41 100644 --- a/src/igmpproxy.c +++ b/src/igmpproxy.c @@ -250,7 +250,7 @@ void igmpProxyCleanUp(void) { my_log( LOG_DEBUG, 0, "clean handler called" ); free_all_callouts(); // No more timeouts. - clearRoutes(NULL); // Remove all routes. + clearRoutes(); // Remove all routes. disableMRouter(); // Disable the multirout API } From f365de4152c4bd7e396e00a1583e8daa27032528 Mon Sep 17 00:00:00 2001 From: Uglymotha Date: Sun, 10 May 2020 09:56:59 +0200 Subject: [PATCH 25/45] clearroutes --- src/igmpproxy.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/igmpproxy.h b/src/igmpproxy.h index 55fa75fb..423d775e 100644 --- a/src/igmpproxy.h +++ b/src/igmpproxy.h @@ -271,7 +271,7 @@ int leaveMcGroup( int UdpSock, struct IfDesc *IfDp, uint32_t mcastaddr ); */ void initRouteTable(void); void joinMcRoutersGroup(struct IfDesc *Dp); -void clearRoutes(struct IfDesc *IfDp); +void clearRoutes(void); int insertRoute(uint32_t group, int ifx, uint32_t src); int activateRoute(uint32_t group, uint32_t originAddr, int upstrVif); void ageActiveRoutes(void); From b19a4b17a05d8673e3cd24576baafd9857fe23de Mon Sep 17 00:00:00 2001 From: Uglymotha Date: Sun, 10 May 2020 09:57:23 +0200 Subject: [PATCH 26/45] clearroutes --- src/rttable.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rttable.c b/src/rttable.c index b49721d1..ed795fe1 100644 --- a/src/rttable.c +++ b/src/rttable.c @@ -240,7 +240,7 @@ static void sendJoinLeaveUpstream(struct RouteTable* route, int join) { /** * Clear all routes from routing table, and alerts Leaves upstream. */ -void clearRoutes(struct IfDesc *IfDp) { +void clearRoutes(void) { struct RouteTable *croute, *remainroute; // Loop through all routes... From e7fd15350d30bd72f83106f0cdc4b05aed6fcc71 Mon Sep 17 00:00:00 2001 From: Uglymotha Date: Sun, 10 May 2020 10:04:06 +0200 Subject: [PATCH 27/45] style fixes --- src/callout.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/callout.c b/src/callout.c index 6cba7864..4bc8faaf 100644 --- a/src/callout.c +++ b/src/callout.c @@ -153,9 +153,9 @@ int timer_leftTimer(int timer_id) { */ static void debugQueue(void) { struct timeOutQueue *ptr; - int i = 1; + int i; - for (ptr = queue; ptr; ptr = ptr->next, i++) { + for (i = 1, ptr = queue; ptr; ptr = ptr->next, i++) { my_log(LOG_DEBUG, 0, "(%d - Id:%d, Time:%d) ", i, ptr->id, ptr->time); } } From 9df9e7d856e7ffef7cb4b0d2faa927a5e0650bc4 Mon Sep 17 00:00:00 2001 From: Uglymotha Date: Sun, 10 May 2020 10:16:34 +0200 Subject: [PATCH 28/45] clearroutes --- src/config.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/config.c b/src/config.c index b8279cb9..daf02245 100644 --- a/src/config.c +++ b/src/config.c @@ -364,8 +364,8 @@ void createVifs(struct IfDescP *RebuildP) { break; case IF_STATE_UPSTREAM: switch (Dp->state) { - case IF_STATE_DISABLED: { clearRoutes(oDp); delVIF(oDp); continue; } - case IF_STATE_DOWNSTREAM: { clearRoutes(oDp); delVIF(oDp); oDp=NULL; join=true; break; } + case IF_STATE_DISABLED: { clearRoutes(); delVIF(oDp); continue; } + case IF_STATE_DOWNSTREAM: { clearRoutes(); delVIF(oDp); oDp=NULL; join=true; break; } case IF_STATE_UPSTREAM: { break; } } break; From 3939a26c09f54531304b1eb76395fb01a5d90686 Mon Sep 17 00:00:00 2001 From: Uglymotha Date: Sun, 10 May 2020 11:00:01 +0200 Subject: [PATCH 29/45] style fixes --- src/config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.c b/src/config.c index daf02245..198f7522 100644 --- a/src/config.c +++ b/src/config.c @@ -323,7 +323,7 @@ void createVifs(struct IfDescP *RebuildP) { } } - for(Ix = 0; Dp = getIfByIx(Ix); Ix++) { + for(Ix = 0; (Dp = getIfByIx(Ix)); Ix++) { if (RebuildP == NULL) { // Only add vif for valid interfaces on start-up. if ((Dp->Flags & IFF_LOOPBACK) || (Dp->state != IF_STATE_DOWNSTREAM && Dp->state != IF_STATE_UPSTREAM)) { From aed93145aee0ab60bc56c6e2680f4bc70b504cc9 Mon Sep 17 00:00:00 2001 From: Uglymotha Date: Mon, 11 May 2020 08:46:12 +0200 Subject: [PATCH 30/45] index unsinged --- src/igmpproxy.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/igmpproxy.h b/src/igmpproxy.h index 423d775e..429b024a 100644 --- a/src/igmpproxy.h +++ b/src/igmpproxy.h @@ -155,7 +155,7 @@ struct IfDesc { unsigned int robustness; unsigned char threshold; /* ttl limit */ unsigned int ratelimit; - int index; + unsigned int index; }; struct IfDescP { From 7114b67d20934cd6f9cbbcc4f1ec88e811002c39 Mon Sep 17 00:00:00 2001 From: Uglymotha Date: Mon, 11 May 2020 08:50:54 +0200 Subject: [PATCH 31/45] compare index unsinged -1 --- src/config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.c b/src/config.c index 198f7522..5a1233fe 100644 --- a/src/config.c +++ b/src/config.c @@ -316,7 +316,7 @@ void createVifs(struct IfDescP *RebuildP) { } if (Dp == NULL) { my_log(LOG_DEBUG, 0, "Interface %s disappeared from system", oDp->Name); - if (oDp->index != -1) { + if (oDp->index != (unsigned int)-1) { delVIF(oDp); } } From 798b4cfc2f4dd8633789b6e8c017609547a6ae13 Mon Sep 17 00:00:00 2001 From: Uglymotha Date: Mon, 11 May 2020 08:55:54 +0200 Subject: [PATCH 32/45] vifindex unsigned --- src/ifvc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ifvc.c b/src/ifvc.c index 91754bc6..b121ced5 100644 --- a/src/ifvc.c +++ b/src/ifvc.c @@ -262,7 +262,7 @@ struct IfDesc *getIfByAddress( uint32_t ipaddr ) { * the supplied IP adress. The IP must match a interfaces * subnet, or any configured allowed subnet on a interface. */ -struct IfDesc *getIfByVifIndex( int vifindex ) { +struct IfDesc *getIfByVifIndex( unsigned vifindex ) { struct IfDesc *Dp; if(vifindex>0) { for ( Dp = IfDescVc; Dp < IfDescEp; Dp++ ) { From af06070afbabb39c355b8874a3b7d2adfcac954d Mon Sep 17 00:00:00 2001 From: Uglymotha Date: Mon, 11 May 2020 08:56:31 +0200 Subject: [PATCH 33/45] vifindex unsigned --- src/igmpproxy.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/igmpproxy.h b/src/igmpproxy.h index 429b024a..ef9abc8a 100644 --- a/src/igmpproxy.h +++ b/src/igmpproxy.h @@ -197,7 +197,7 @@ void buildIfVc( void ); struct IfDesc *getIfByName( const char *IfName ); struct IfDesc *getIfByIx( unsigned Ix ); struct IfDesc *getIfByAddress( uint32_t Ix ); -struct IfDesc *getIfByVifIndex( int vifindex ); +struct IfDesc *getIfByVifIndex( unsigned vifindex ); int isAdressValidForIf(struct IfDesc* intrface, uint32_t ipaddr); /* mroute-api.c From 2c19ff751255f9fd75ca68841248472a4fb73e2f Mon Sep 17 00:00:00 2001 From: Uglymotha Date: Mon, 11 May 2020 08:59:40 +0200 Subject: [PATCH 34/45] index unsigned-1 --- src/mroute-api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mroute-api.c b/src/mroute-api.c index 138002b8..fae4ab02 100644 --- a/src/mroute-api.c +++ b/src/mroute-api.c @@ -100,7 +100,7 @@ void delVIF( struct IfDesc *IfDp ) { struct vifctl VifCtl; - if ((int)-1 == IfDp->index) + if ((unsigned int)-1 == IfDp->index) return; VifCtl.vifc_vifi = IfDp->index; From 2d58db6794d46499c9434c17fcf03140d75dfd3b Mon Sep 17 00:00:00 2001 From: Uglymotha Date: Tue, 12 May 2020 10:35:34 +0200 Subject: [PATCH 35/45] remove joinmcrouters removes joining of mc routers groups on startup. Removes initroutetable function in favor of clearroutes --- src/rttable.c | 41 +---------------------------------------- 1 file changed, 1 insertion(+), 40 deletions(-) diff --git a/src/rttable.c b/src/rttable.c index ed795fe1..9c512635 100644 --- a/src/rttable.c +++ b/src/rttable.c @@ -68,7 +68,7 @@ struct RouteTable { // Keeper for the routing table... -static struct RouteTable *routing_table; +static struct RouteTable *routing_table = NULL; // Prototypes void logRouteTable(const char *header); @@ -126,45 +126,6 @@ int getMcGroupSock(void) { return mcGroupSock; } -/** -* Initializes the routing table. -*/ -void initRouteTable(void) { - unsigned Ix; - struct IfDesc *Dp; - - // Clear routing table... - routing_table = NULL; - - // Join the all routers group on downstream vifs... - for ( Ix = 0; (Dp = getIfByIx(Ix)); Ix++ ) { - // If this is a downstream vif, we should join the All routers group... - if( Dp->InAdr.s_addr && ! (Dp->Flags & IFF_LOOPBACK) && Dp->state == IF_STATE_DOWNSTREAM) { - my_log(LOG_DEBUG, 0, "Joining all-routers group %s on vif %s", - inetFmt(allrouters_group,s1),inetFmt(Dp->InAdr.s_addr,s2)); - - //k_join(allrouters_group, Dp->InAdr.s_addr); - joinMcGroup( getMcGroupSock(), Dp, allrouters_group ); - - my_log(LOG_DEBUG, 0, "Joining all igmpv3 multicast routers group %s on vif %s", - inetFmt(alligmp3_group,s1),inetFmt(Dp->InAdr.s_addr,s2)); - joinMcGroup( getMcGroupSock(), Dp, alligmp3_group ); - } - } -} - -void joinMcRoutersGroup(struct IfDesc *Dp) { - my_log(LOG_DEBUG, 0, "Joining all-routers group %s on vif %s", - inetFmt(allrouters_group,s1),inetFmt(Dp->InAdr.s_addr,s2)); - - //k_join(allrouters_group, Dp->InAdr.s_addr); - joinMcGroup(getMcGroupSock(), Dp, allrouters_group); - - my_log(LOG_DEBUG, 0, "Joining all igmpv3 multicast routers group %s on vif %s", - inetFmt(alligmp3_group,s1),inetFmt(Dp->InAdr.s_addr,s2)); - joinMcGroup(getMcGroupSock(), Dp, alligmp3_group); -} - /** * Internal function to send join or leave requests for * a specified route upstream... From b082eeceee01d76ab3ea5b1e7aa9b425d049e9d3 Mon Sep 17 00:00:00 2001 From: Uglymotha Date: Tue, 12 May 2020 10:36:48 +0200 Subject: [PATCH 36/45] clearroutes instead of initroutetable Use clearroutes() instead of initroutetable() in igmpproxyinit() --- src/igmpproxy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/igmpproxy.c b/src/igmpproxy.c index 51abcf41..801b8f6d 100644 --- a/src/igmpproxy.c +++ b/src/igmpproxy.c @@ -236,7 +236,7 @@ int igmpProxyInit(void) { // Initialize IGMP initIgmp(); // Initialize Routing table - initRouteTable(); + clearRoutes(); // Initialize timer free_all_callouts(); From a64fd02e6196e6655d6b8addc066aab753cea556 Mon Sep 17 00:00:00 2001 From: Uglymotha Date: Tue, 12 May 2020 10:37:31 +0200 Subject: [PATCH 37/45] remove initroutetable() --- src/igmpproxy.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/igmpproxy.h b/src/igmpproxy.h index ef9abc8a..58e1cd5b 100644 --- a/src/igmpproxy.h +++ b/src/igmpproxy.h @@ -269,7 +269,6 @@ int leaveMcGroup( int UdpSock, struct IfDesc *IfDp, uint32_t mcastaddr ); /* rttable.c */ -void initRouteTable(void); void joinMcRoutersGroup(struct IfDesc *Dp); void clearRoutes(void); int insertRoute(uint32_t group, int ifx, uint32_t src); From 68d5bf0773b57468e7a7708af6880cd5db909f7e Mon Sep 17 00:00:00 2001 From: Uglymotha Date: Tue, 12 May 2020 10:43:15 +0200 Subject: [PATCH 38/45] remove joinmcrroutergroup fro createvifs() --- src/config.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/config.c b/src/config.c index 5a1233fe..08f3bc6b 100644 --- a/src/config.c +++ b/src/config.c @@ -299,7 +299,6 @@ void configureVifs(void) { void createVifs(struct IfDescP *RebuildP) { struct IfDesc *Dp, *oDp = NULL; int vifcount = 0, upsvifcount = 0, Ix = 0; - bool join = false; // init array to "not set" for (Ix = 0; Ix < MAX_UPS_VIFS; Ix++) { @@ -332,13 +331,13 @@ void createVifs(struct IfDescP *RebuildP) { } else { /* Need rebuild, check if interface is new or already exists (check table below). old: disabled new: disabled -> do nothing - old: disabled new: downstream -> addVIF(new), joinmcroutergroups + old: disabled new: downstream -> addVIF(new) old: disabled new: upstream -> addVIF(new) old: downstream new: disabled -> delVIF(old) state table old: downstream new: downstream -> addvif(new,old) old: downstream new: upstream -> delvif(old), addvif(new) old: upstream new: disabled -> clear routes oldvif, delVIF(old) - old: upstream new: downstream -> clear routes oldvif, delvif(old)),addvif(new), joinmcroutergroup + old: upstream new: downstream -> clear routes oldvif, delvif(old)),addvif(new) old: upstream new: upstream -> addvif(new,old) */ for (oDp=RebuildP->S; oDpE; oDp++) { @@ -350,23 +349,23 @@ void createVifs(struct IfDescP *RebuildP) { switch (oDp->state) { case IF_STATE_DISABLED: switch (Dp->state) { - case IF_STATE_DISABLED: { continue; } - case IF_STATE_DOWNSTREAM: { oDp=NULL; join=true; break; } - case IF_STATE_UPSTREAM: { oDp=NULL; break; } + case IF_STATE_DISABLED: { continue; } + case IF_STATE_DOWNSTREAM: { oDp=NULL; break; } + case IF_STATE_UPSTREAM: { oDp=NULL; break; } } break; case IF_STATE_DOWNSTREAM: switch (Dp->state) { - case IF_STATE_DISABLED: { delVIF(oDp); continue; } - case IF_STATE_DOWNSTREAM: { break; } - case IF_STATE_UPSTREAM: { delVIF(oDp); oDp=NULL; break; } + case IF_STATE_DISABLED: { delVIF(oDp); continue; } + case IF_STATE_DOWNSTREAM: { break; } + case IF_STATE_UPSTREAM: { delVIF(oDp); oDp=NULL; break; } } break; case IF_STATE_UPSTREAM: switch (Dp->state) { - case IF_STATE_DISABLED: { clearRoutes(); delVIF(oDp); continue; } - case IF_STATE_DOWNSTREAM: { clearRoutes(); delVIF(oDp); oDp=NULL; join=true; break; } - case IF_STATE_UPSTREAM: { break; } + case IF_STATE_DISABLED: { clearRoutes(); delVIF(oDp); continue; } + case IF_STATE_DOWNSTREAM: { clearRoutes(); delVIF(oDp); oDp=NULL; break; } + case IF_STATE_UPSTREAM: { break; } } break; } @@ -391,9 +390,6 @@ void createVifs(struct IfDescP *RebuildP) { } } addVIF(Dp); - if (join) { - joinMcRoutersGroup(Dp); - } vifcount++; } From f13f13996f4822ba3704c874e4b2a321771dd8fe Mon Sep 17 00:00:00 2001 From: Uglymotha Date: Tue, 12 May 2020 11:46:07 +0200 Subject: [PATCH 39/45] configurevifs ix unsigned --- src/config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.c b/src/config.c index 08f3bc6b..eb4866b1 100644 --- a/src/config.c +++ b/src/config.c @@ -249,7 +249,7 @@ int loadConfig(char *configFile) { * Appends extra VIF configuration from config file. */ void configureVifs(void) { - int Ix; + unsinged Ix; struct IfDesc *Dp; struct vifconfig *confPtr; From 5f26f145a39466c9f5bb76ce583769c513b4c274 Mon Sep 17 00:00:00 2001 From: Uglymotha Date: Tue, 12 May 2020 12:44:04 +0200 Subject: [PATCH 40/45] typo --- src/config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.c b/src/config.c index eb4866b1..488ea5f7 100644 --- a/src/config.c +++ b/src/config.c @@ -249,7 +249,7 @@ int loadConfig(char *configFile) { * Appends extra VIF configuration from config file. */ void configureVifs(void) { - unsinged Ix; + unsigned Ix; struct IfDesc *Dp; struct vifconfig *confPtr; From bed8ecd127395e589293f507ed4862a662f2b2fd Mon Sep 17 00:00:00 2001 From: Uglymotha Date: Tue, 12 May 2020 13:22:15 +0200 Subject: [PATCH 41/45] remove joinmcrouters --- src/igmpproxy.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/igmpproxy.h b/src/igmpproxy.h index 58e1cd5b..b7568a46 100644 --- a/src/igmpproxy.h +++ b/src/igmpproxy.h @@ -269,7 +269,6 @@ int leaveMcGroup( int UdpSock, struct IfDesc *IfDp, uint32_t mcastaddr ); /* rttable.c */ -void joinMcRoutersGroup(struct IfDesc *Dp); void clearRoutes(void); int insertRoute(uint32_t group, int ifx, uint32_t src); int activateRoute(uint32_t group, uint32_t originAddr, int upstrVif); From c947ab775c2f6176c2d72c2b7e9d96b01dae4bf3 Mon Sep 17 00:00:00 2001 From: Sietse van Zanen Date: Tue, 19 May 2020 17:13:43 +0200 Subject: [PATCH 42/45] Syncd changes with master branch --- src/callout.c | 41 +++++------- src/config.c | 164 ++++++++++++++++++++++++++++-------------------- src/ifvc.c | 25 +++++--- src/igmpproxy.c | 2 +- src/igmpproxy.h | 16 ++++- src/request.c | 7 --- 6 files changed, 145 insertions(+), 110 deletions(-) diff --git a/src/callout.c b/src/callout.c index 4bc8faaf..aff1adee 100644 --- a/src/callout.c +++ b/src/callout.c @@ -40,11 +40,11 @@ static int id = 0; static struct timeOutQueue *queue = NULL; /* pointer to the beginning of timeout queue */ struct timeOutQueue { - struct timeOutQueue *next; // Next event in queue int id; timer_f func; // function to call void *data; // Data for function long time; // Time for event + struct timeOutQueue *next; // Next event in queue }; // Method for dumping the Queue to the log. @@ -56,10 +56,8 @@ static void debugQueue(void); void free_all_callouts(void) { struct timeOutQueue *p; - while (queue) { - p = queue; - queue = queue->next; - free(p); + for (p = queue ? queue->next : NULL; queue; queue = p, p = queue->next) { + free(queue); // Alloced by timer_setTimer() } } @@ -78,7 +76,7 @@ void age_callout_queue(struct timespec curtime) { ptr->func(ptr->data); } queue = ptr = ptr->next; - free(tmp); + free(tmp); // Alloced by timer_setTimer() i++; } } @@ -94,9 +92,9 @@ int timer_setTimer(int delay, timer_f action, void *data) { struct timespec curtime; int i = 1; - // create a node. + // create a node. Freed by free_all_callouts() and age_callout_queue(). node = (struct timeOutQueue *)malloc(sizeof(struct timeOutQueue)); - if (node == 0) { + if (! node) { my_log(LOG_WARNING, 0, "Malloc Failed in timer_settimer\n"); return -1; } @@ -104,24 +102,20 @@ int timer_setTimer(int delay, timer_f action, void *data) { node->func = action; node->data = data; node->time = curtime.tv_sec + delay; - node->next = NULL; node->id = ++id; - // if the queue is empty, insert the node and return. - if (!queue) queue = node; - else { + if (! queue) { + // if the queue is empty, insert the node and return. + queue = node; + } else { // chase the queue looking for the right place. for (i++; ptr->next && node->time >= ptr->next->time; ptr = ptr->next, i++); if (ptr == queue && node->time < ptr->time) { // Start of queue, insert. queue = node; node->next = ptr; - } else if ( ptr->next ) { - // Middle of queue, insert - node->next = ptr->next; - ptr->next = node; } else { - // End of queue, append. + node->next = ptr->next; ptr->next = node; } } @@ -134,16 +128,15 @@ int timer_setTimer(int delay, timer_f action, void *data) { * returns the time until the timer is scheduled */ int timer_leftTimer(int timer_id) { - struct timeOutQueue *ptr = queue; + struct timeOutQueue *ptr; struct timespec curtime; if (!timer_id || !queue) return -1; - while (ptr && ptr->id != timer_id) { - ptr = ptr->next; - } - if (ptr){ - clock_gettime (CLOCK_MONOTONIC, &curtime); - return (ptr->time - curtime.tv_sec); + for (ptr = queue; ptr; ptr = ptr->next) { + if (ptr->id == timer_id) { + clock_gettime(CLOCK_MONOTONIC, &curtime); + return (ptr->time - curtime.tv_sec); + } } return -1; } diff --git a/src/config.c b/src/config.c index 488ea5f7..f40f4e89 100644 --- a/src/config.c +++ b/src/config.c @@ -47,9 +47,11 @@ struct vifconfig { // Keep allowed nets for VIF. struct SubnetList* allowednets; + struct SubnetList* deniednets; // Allowed Groups struct SubnetList* allowedgroups; + struct SubnetList* deniedgroups; // Next config in list... struct vifconfig* next; @@ -114,22 +116,10 @@ void reloadConfig(void) { rebuildIfVc(); my_log(LOG_DEBUG, 0, "reloadConfig: Config Reloaded. OldConfPtr %x, NewConfPtr, %x", OldConfPtr, vifconf); - // Free all the old mallocd subnetlists and vifconf list. - while (OldConfPtr) { - TmpConfPtr=OldConfPtr->next; // Increment before free or pointers may be invalid. - struct SubnetList *TmpNetPtr; - while (OldConfPtr->allowednets) { - TmpNetPtr = OldConfPtr->allowednets->next; - free (OldConfPtr->allowednets); - OldConfPtr->allowednets = TmpNetPtr; - } - while (OldConfPtr->allowedgroups) { - TmpNetPtr = OldConfPtr->allowedgroups->next; - free (OldConfPtr->allowedgroups); - OldConfPtr->allowedgroups = TmpNetPtr; - } - free (OldConfPtr); - OldConfPtr = TmpConfPtr; + + // Free all the old mallocd vifconf list. + for (TmpConfPtr = OldConfPtr->next; OldConfPtr; OldConfPtr = TmpConfPtr, TmpConfPtr = OldConfPtr->next) { + free (OldConfPtr); // Alloced by parsePhyintToken() } } @@ -299,86 +289,103 @@ void configureVifs(void) { void createVifs(struct IfDescP *RebuildP) { struct IfDesc *Dp, *oDp = NULL; int vifcount = 0, upsvifcount = 0, Ix = 0; + struct gvDescL *gvDescL = NULL, *TmpgvDescL = NULL, *AddgvDescL = NULL; - // init array to "not set" - for (Ix = 0; Ix < MAX_UPS_VIFS; Ix++) { - upStreamIfIdx[Ix] = -1; - } - - if (RebuildP != NULL) { + if (RebuildP) { // When rebuild, check if interfaces have dissapeared and call delVIF if necessary. for (oDp=RebuildP->S; oDpE; oDp++) { - for (Ix = 0; (Dp = getIfByIx(Ix)); Ix++) { - if (! strcmp (oDp->Name, Dp->Name)) { - break; - } - } - if (Dp == NULL) { + if (! (Dp = getIfByName(oDp->Name, NULL))) { my_log(LOG_DEBUG, 0, "Interface %s disappeared from system", oDp->Name); if (oDp->index != (unsigned int)-1) { + AddgvDescL = clearRoutes(oDp, RebuildP); + // For any dissappaerd downstream vif we may have a list of groups to be queried after we are done. + if (AddgvDescL) { + if (! gvDescL) { + gvDescL = AddgvDescL; + } else { + for (TmpgvDescL = gvDescL; TmpgvDescL && TmpgvDescL->next; TmpgvDescL = TmpgvDescL->next); + TmpgvDescL->next = AddgvDescL; + } + } delVIF(oDp); } } } } - for(Ix = 0; (Dp = getIfByIx(Ix)); Ix++) { - if (RebuildP == NULL) { + // Loop through all new interfaces and check what has changed. + for(Ix = 0; (Dp = getIfByIx(Ix, NULL)); Ix++) { + AddgvDescL = NULL; + if (! RebuildP) { // Only add vif for valid interfaces on start-up. if ((Dp->Flags & IFF_LOOPBACK) || (Dp->state != IF_STATE_DOWNSTREAM && Dp->state != IF_STATE_UPSTREAM)) { continue; } - } else { + } else if ((oDp = getIfByName(Dp->Name, RebuildP))) { /* Need rebuild, check if interface is new or already exists (check table below). old: disabled new: disabled -> do nothing old: disabled new: downstream -> addVIF(new) old: disabled new: upstream -> addVIF(new) - old: downstream new: disabled -> delVIF(old) + old: downstream new: disabled -> clear routes oldvif, delVIF(old) state table old: downstream new: downstream -> addvif(new,old) - old: downstream new: upstream -> delvif(old), addvif(new) + old: downstream new: upstream -> clear routes oldvif, delvif(old), addvif(new) old: upstream new: disabled -> clear routes oldvif, delVIF(old) old: upstream new: downstream -> clear routes oldvif, delvif(old)),addvif(new) old: upstream new: upstream -> addvif(new,old) */ - for (oDp=RebuildP->S; oDpE; oDp++) { - if (! strcmp (oDp->Name, Dp->Name)) { - break; - } + if (oDp->state != IF_STATE_UPSTREAM && Dp->state == IF_STATE_UPSTREAM) { + // If vif transitions to upstream set relevant routes to not joined. + clearRoutes(Dp, NULL); } - if ( oDp < RebuildP->E ) { - switch (oDp->state) { - case IF_STATE_DISABLED: - switch (Dp->state) { - case IF_STATE_DISABLED: { continue; } - case IF_STATE_DOWNSTREAM: { oDp=NULL; break; } - case IF_STATE_UPSTREAM: { oDp=NULL; break; } - } - break; - case IF_STATE_DOWNSTREAM: - switch (Dp->state) { - case IF_STATE_DISABLED: { delVIF(oDp); continue; } - case IF_STATE_DOWNSTREAM: { break; } - case IF_STATE_UPSTREAM: { delVIF(oDp); oDp=NULL; break; } - } - break; - case IF_STATE_UPSTREAM: - switch (Dp->state) { - case IF_STATE_DISABLED: { clearRoutes(); delVIF(oDp); continue; } - case IF_STATE_DOWNSTREAM: { clearRoutes(); delVIF(oDp); oDp=NULL; break; } - case IF_STATE_UPSTREAM: { break; } - } - break; + + switch (oDp->state) { + case IF_STATE_DISABLED: + switch (Dp->state) { + case IF_STATE_DISABLED: { continue; } + case IF_STATE_DOWNSTREAM: { oDp=NULL; break; } + case IF_STATE_UPSTREAM: { oDp=NULL; break; } + } + break; + case IF_STATE_DOWNSTREAM: + switch (Dp->state) { + case IF_STATE_DISABLED: { AddgvDescL = clearRoutes(oDp, RebuildP); delVIF(oDp); break; } + case IF_STATE_DOWNSTREAM: { break; } + case IF_STATE_UPSTREAM: { AddgvDescL = clearRoutes(oDp, RebuildP); delVIF(oDp); oDp=NULL; break; } } - if (Dp->Flags & IFF_LOOPBACK) { - continue; + break; + case IF_STATE_UPSTREAM: + switch (Dp->state) { + case IF_STATE_DISABLED: { clearRoutes(oDp, RebuildP); delVIF(oDp); continue; } + case IF_STATE_DOWNSTREAM: { clearRoutes(oDp, RebuildP); delVIF(oDp); oDp=NULL; break; } + case IF_STATE_UPSTREAM: { break; } } - } else { - // New Interface. Only add valid up/downstream vif. - if ((Dp->Flags & IFF_LOOPBACK) || (Dp->state != IF_STATE_DOWNSTREAM && Dp->state != IF_STATE_UPSTREAM)) { - continue; + break; + } + + // For any removed downstream vif we may have a list of groups to be queried after we are done. + if (AddgvDescL) { + if (! gvDescL) { + gvDescL = AddgvDescL; + } else { + for (TmpgvDescL = gvDescL; TmpgvDescL && TmpgvDescL->next; TmpgvDescL = TmpgvDescL->next); + TmpgvDescL->next = AddgvDescL; } - oDp=NULL; } + + // Do not call addvif for loopback or if switched from downstream to disabled. + if ((Dp->Flags & IFF_LOOPBACK) || (oDp && oDp->state == IF_STATE_DOWNSTREAM && Dp->state == IF_STATE_DISABLED)) { + continue; + } + } else { + // New Interface. Only add valid up/downstream vif. + if ((Dp->Flags & IFF_LOOPBACK) || (Dp->state != IF_STATE_DOWNSTREAM && Dp->state != IF_STATE_UPSTREAM)) { + continue; + } + if (Dp->state == IF_STATE_UPSTREAM) { + // Set relevant routes to not joined. + clearRoutes(Dp, NULL); + } + oDp=NULL; } if(Dp->state == IF_STATE_UPSTREAM) { if (upsvifcount >= MAX_UPS_VIFS) { @@ -386,10 +393,10 @@ void createVifs(struct IfDescP *RebuildP) { Ix, MAX_UPS_VIFS); } else { my_log(LOG_DEBUG, 0, "Found upstream IF #%d, will assign as upstream Vif %d", upsvifcount, Ix); - upStreamIfIdx[upsvifcount++] = Ix; + upsvifcount++; } } - addVIF(Dp); + addVIF(Dp, oDp); vifcount++; } @@ -397,6 +404,25 @@ void createVifs(struct IfDescP *RebuildP) { if (upsvifcount == 0 || vifcount == upsvifcount) { my_log(LOG_ERR, 0, "There must be at least 1 Vif as upstream and 1 as dowstream."); } + + // If we have a lists of groups that have been set to check last member start the group specific querier. + while (gvDescL) { + struct gvDescL *FgvDescL = gvDescL; + + my_log(LOG_DEBUG, 0, "createVifs: Starting group specific query for %s", inetFmt(gvDescL->gvDesc->group,s1)); + sendGroupSpecificMemberQuery(gvDescL->gvDesc); + + // The list may have duplicates, remove them + for (TmpgvDescL = gvDescL; TmpgvDescL && TmpgvDescL->next; TmpgvDescL = TmpgvDescL->next) { + if (TmpgvDescL->next->gvDesc->group == gvDescL->gvDesc->group) { + TmpgvDescL->next = TmpgvDescL->next->next; + free(TmpgvDescL->next->gvDesc); // Alloced by clearRoutes() + free(TmpgvDescL->next); // Alloced by clearRoutes() + } + } + gvDescL = gvDescL->next; + free(FgvDescL); // Alloced by clearRoutes() + } } /** diff --git a/src/ifvc.c b/src/ifvc.c index b121ced5..ca30de1b 100644 --- a/src/ifvc.c +++ b/src/ifvc.c @@ -50,25 +50,34 @@ struct IfDescP IfDescP = { NULL, NULL, 0 }; * For example: /etc/ppp/ip-up & ip-down can touch a file /tmp/ppp_changed * So I can check if the file exist then run me and delete the file. ***************************************************/ -void rebuildIfVc () { +void rebuildIfVc() { // Build new IfDesc Table. Keep Copy of Old. - struct IfDescP OldIfDescP=IfDescP, TmpIfDescP=IfDescP; + struct IfDescP OldIfDescP = IfDescP; buildIfVc(); // Call configureVifs to link the new IfDesc table. configureVifs(); - // Call createvifs with pointer to old IfDesc table for relinking vifs and removing or adding interfaces if required. + // Call createvifs with pointers IfDesc tables for relinking vifs and removing or adding interfaces if required. my_log (LOG_DEBUG,0,"RebuildIfVc: creating vifs, Old IfDescP: %x, New: %x", OldIfDescP.S, IfDescP.S); createVifs(&OldIfDescP); - // Free the old IfDesc Table. - if (OldIfDescP.S != NULL) { - for (struct IfDesc *Dp = TmpIfDescP.S; Dp < TmpIfDescP.E; Dp++) { - free(Dp->allowednets); + // Free the old IfDesc Table and linked subnet lists. + struct IfDesc *Dp; + for (Dp = OldIfDescP.S; Dp < OldIfDescP.E; Dp++) { + int i; + for (i = 1; i <= 4; i++) { + struct SubnetList *TmpNetPtr, *currsubnet; + currsubnet = i == 1 ? Dp->allowednets : + i == 2 ? Dp->deniednets : + i == 3 ? Dp->allowedgroups : + Dp->deniedgroups; + for (TmpNetPtr = currsubnet ? currsubnet->next : NULL; currsubnet; currsubnet = TmpNetPtr, TmpNetPtr = currsubnet->next) { + free(currsubnet); // Alloced by builfIfVc and allocSubnet(). + } } - free(OldIfDescP.S); } + free(OldIfDescP.S); // Alloced by buildIfVc() } /* diff --git a/src/igmpproxy.c b/src/igmpproxy.c index 801b8f6d..fc5ce22b 100644 --- a/src/igmpproxy.c +++ b/src/igmpproxy.c @@ -276,7 +276,7 @@ void igmpProxyRun(void) { lasttime = curtime; // Loop until the end... - for (;;) { + while (true) { // Process signaling... if (sighandled) { diff --git a/src/igmpproxy.h b/src/igmpproxy.h index b7568a46..827387e8 100644 --- a/src/igmpproxy.h +++ b/src/igmpproxy.h @@ -150,8 +150,10 @@ struct IfDesc { struct in_addr InAdr; /* == 0 for non IP interfaces */ short Flags; short state; - struct SubnetList* allowednets; + struct SubnetList* allowednets; + struct SubnetList* deniednets; struct SubnetList* allowedgroups; + struct SubnetList* deniedgroups; unsigned int robustness; unsigned char threshold; /* ttl limit */ unsigned int ratelimit; @@ -190,6 +192,18 @@ struct Config { // Holds the indeces of the upstream IF... extern int upStreamIfIdx[MAX_UPS_VIFS]; +// Group specific query structs. +typedef struct { + uint32_t group; + struct IfDesc *sourceVif; + short started; +} GroupVifDesc; + +struct gvDescL { + GroupVifDesc *gvDesc; + struct gvDescL *next; +}; + /* ifvc.c */ void rebuildIfVc( void ); diff --git a/src/request.c b/src/request.c index 06d14c44..f1f84ff1 100644 --- a/src/request.c +++ b/src/request.c @@ -43,13 +43,6 @@ // Prototypes... void sendGroupSpecificMemberQuery(void *argument); -typedef struct { - uint32_t group; - // uint32_t vifAddr; - short started; -} GroupVifDesc; - - /** * Handles incoming membership reports, and * appends them to the routing table. From 10f044ddc0ef0f7023960d4392a18ecffb3e3f39 Mon Sep 17 00:00:00 2001 From: Sietse van Zanen Date: Tue, 19 May 2020 17:20:42 +0200 Subject: [PATCH 43/45] Syncd changes with master branch --- src/callout.c | 1 + src/config.c | 24 +++++++++++++----------- src/rttable.c | 4 +++- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/callout.c b/src/callout.c index aff1adee..4a913858 100644 --- a/src/callout.c +++ b/src/callout.c @@ -103,6 +103,7 @@ int timer_setTimer(int delay, timer_f action, void *data) { node->data = data; node->time = curtime.tv_sec + delay; node->id = ++id; + node->next = NULL; if (! queue) { // if the queue is empty, insert the node and return. diff --git a/src/config.c b/src/config.c index f40f4e89..4ced5b27 100644 --- a/src/config.c +++ b/src/config.c @@ -294,10 +294,10 @@ void createVifs(struct IfDescP *RebuildP) { if (RebuildP) { // When rebuild, check if interfaces have dissapeared and call delVIF if necessary. for (oDp=RebuildP->S; oDpE; oDp++) { - if (! (Dp = getIfByName(oDp->Name, NULL))) { + if (! (Dp = getIfByName(oDp->Name))) { my_log(LOG_DEBUG, 0, "Interface %s disappeared from system", oDp->Name); if (oDp->index != (unsigned int)-1) { - AddgvDescL = clearRoutes(oDp, RebuildP); + AddgvDescL = clearRoutes(); // For any dissappaerd downstream vif we may have a list of groups to be queried after we are done. if (AddgvDescL) { if (! gvDescL) { @@ -314,14 +314,14 @@ void createVifs(struct IfDescP *RebuildP) { } // Loop through all new interfaces and check what has changed. - for(Ix = 0; (Dp = getIfByIx(Ix, NULL)); Ix++) { + for(Ix = 0; (Dp = getIfByIx(Ix)); Ix++) { AddgvDescL = NULL; if (! RebuildP) { // Only add vif for valid interfaces on start-up. if ((Dp->Flags & IFF_LOOPBACK) || (Dp->state != IF_STATE_DOWNSTREAM && Dp->state != IF_STATE_UPSTREAM)) { continue; } - } else if ((oDp = getIfByName(Dp->Name, RebuildP))) { + } else if ((oDp = getIfByName(Dp->Name))) { /* Need rebuild, check if interface is new or already exists (check table below). old: disabled new: disabled -> do nothing old: disabled new: downstream -> addVIF(new) @@ -335,7 +335,7 @@ void createVifs(struct IfDescP *RebuildP) { */ if (oDp->state != IF_STATE_UPSTREAM && Dp->state == IF_STATE_UPSTREAM) { // If vif transitions to upstream set relevant routes to not joined. - clearRoutes(Dp, NULL); + clearRoutes(); } switch (oDp->state) { @@ -348,15 +348,15 @@ void createVifs(struct IfDescP *RebuildP) { break; case IF_STATE_DOWNSTREAM: switch (Dp->state) { - case IF_STATE_DISABLED: { AddgvDescL = clearRoutes(oDp, RebuildP); delVIF(oDp); break; } + case IF_STATE_DISABLED: { AddgvDescL = clearRoutes(); delVIF(oDp); break; } case IF_STATE_DOWNSTREAM: { break; } - case IF_STATE_UPSTREAM: { AddgvDescL = clearRoutes(oDp, RebuildP); delVIF(oDp); oDp=NULL; break; } + case IF_STATE_UPSTREAM: { AddgvDescL = clearRoutes(); delVIF(oDp); oDp=NULL; break; } } break; case IF_STATE_UPSTREAM: switch (Dp->state) { - case IF_STATE_DISABLED: { clearRoutes(oDp, RebuildP); delVIF(oDp); continue; } - case IF_STATE_DOWNSTREAM: { clearRoutes(oDp, RebuildP); delVIF(oDp); oDp=NULL; break; } + case IF_STATE_DISABLED: { clearRoutes(); delVIF(oDp); continue; } + case IF_STATE_DOWNSTREAM: { clearRoutes(); delVIF(oDp); oDp=NULL; break; } case IF_STATE_UPSTREAM: { break; } } break; @@ -383,7 +383,7 @@ void createVifs(struct IfDescP *RebuildP) { } if (Dp->state == IF_STATE_UPSTREAM) { // Set relevant routes to not joined. - clearRoutes(Dp, NULL); + clearRoutes(); } oDp=NULL; } @@ -396,7 +396,7 @@ void createVifs(struct IfDescP *RebuildP) { upsvifcount++; } } - addVIF(Dp, oDp); + addVIF(Dp); vifcount++; } @@ -454,7 +454,9 @@ struct vifconfig *parsePhyintToken(void) { tmpPtr->threshold = 1; tmpPtr->state = commonConfig.defaultInterfaceState; tmpPtr->allowednets = NULL; + tmpPtr->deniednets = NULL; tmpPtr->allowedgroups = NULL; + tmpPtr->deniedgroups = NULL; // Make a copy of the token to store the IF name tmpPtr->name = strdup( token ); diff --git a/src/rttable.c b/src/rttable.c index 9c512635..b8a0a620 100644 --- a/src/rttable.c +++ b/src/rttable.c @@ -201,7 +201,7 @@ static void sendJoinLeaveUpstream(struct RouteTable* route, int join) { /** * Clear all routes from routing table, and alerts Leaves upstream. */ -void clearRoutes(void) { +struct gvDescL *clearRoutes(void) { struct RouteTable *croute, *remainroute; // Loop through all routes... @@ -228,6 +228,8 @@ void clearRoutes(void) { // Send a notice that the routing table is empty... my_log(LOG_NOTICE, 0, "All routes removed. Routing table is empty."); + + return 0; } /** From 68e69d5b973a9a7fb58fd1f584080f50e99d4e69 Mon Sep 17 00:00:00 2001 From: Sietse van Zanen Date: Tue, 19 May 2020 17:29:50 +0200 Subject: [PATCH 44/45] Syncd changes with master branch --- src/config.c | 3 +++ src/igmpproxy.h | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/config.c b/src/config.c index 4ced5b27..3245a4c2 100644 --- a/src/config.c +++ b/src/config.c @@ -275,6 +275,9 @@ void configureVifs(void) { vifLast->next = confPtr->allowednets; Dp->allowedgroups = confPtr->allowedgroups; + Dp->deniednets = confPtr->deniednets; + Dp->allowedgroups = confPtr->allowedgroups; + Dp->deniedgroups = confPtr->deniedgroups; break; } diff --git a/src/igmpproxy.h b/src/igmpproxy.h index 827387e8..206321a4 100644 --- a/src/igmpproxy.h +++ b/src/igmpproxy.h @@ -150,7 +150,7 @@ struct IfDesc { struct in_addr InAdr; /* == 0 for non IP interfaces */ short Flags; short state; - struct SubnetList* allowednets; + struct SubnetList* allowednets; struct SubnetList* deniednets; struct SubnetList* allowedgroups; struct SubnetList* deniedgroups; From 6c3bed17b1b06e0f5c1332a89bb9319c8fe389b0 Mon Sep 17 00:00:00 2001 From: Sietse van Zanen Date: Tue, 19 May 2020 17:38:47 +0200 Subject: [PATCH 45/45] Syncd changes with master branch --- src/callout.c | 2 +- src/config.c | 2 +- src/igmpproxy.h | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/callout.c b/src/callout.c index 4a913858..dd23fb91 100644 --- a/src/callout.c +++ b/src/callout.c @@ -146,7 +146,7 @@ int timer_leftTimer(int timer_id) { * debugging utility */ static void debugQueue(void) { - struct timeOutQueue *ptr; + struct timeOutQueue *ptr; int i; for (i = 1, ptr = queue; ptr; ptr = ptr->next, i++) { diff --git a/src/config.c b/src/config.c index 3245a4c2..c7bc86f3 100644 --- a/src/config.c +++ b/src/config.c @@ -275,7 +275,7 @@ void configureVifs(void) { vifLast->next = confPtr->allowednets; Dp->allowedgroups = confPtr->allowedgroups; - Dp->deniednets = confPtr->deniednets; + Dp->deniednets = confPtr->deniednets; Dp->allowedgroups = confPtr->allowedgroups; Dp->deniedgroups = confPtr->deniedgroups; diff --git a/src/igmpproxy.h b/src/igmpproxy.h index 206321a4..632b2353 100644 --- a/src/igmpproxy.h +++ b/src/igmpproxy.h @@ -283,7 +283,7 @@ int leaveMcGroup( int UdpSock, struct IfDesc *IfDp, uint32_t mcastaddr ); /* rttable.c */ -void clearRoutes(void); +struct gvDescL *clearRoutes(void); int insertRoute(uint32_t group, int ifx, uint32_t src); int activateRoute(uint32_t group, uint32_t originAddr, int upstrVif); void ageActiveRoutes(void); @@ -294,6 +294,7 @@ int getMcGroupSock(void); /* request.c */ +void sendGroupSpecificMemberQuery(void *argument); void acceptGroupReport(uint32_t src, uint32_t group); void acceptLeaveMessage(uint32_t src, uint32_t group); void sendGeneralMembershipQuery(void);