From 7b358ec64f13ded293734b430c76b55b363cbdfc Mon Sep 17 00:00:00 2001 From: Abraham Fernandez Date: Tue, 31 Jul 2018 16:08:10 +0200 Subject: [PATCH 1/3] Added changes to permit pppoe interfaces --- src/config.c | 2 +- src/ifvc.c | 53 ++++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/src/config.c b/src/config.c index 77f3d423..2f0975fe 100644 --- a/src/config.c +++ b/src/config.c @@ -396,7 +396,7 @@ struct SubnetList *parseSubnetAddress(char *addrstr) { } tmpSubnet = (struct SubnetList*) malloc(sizeof(struct SubnetList)); - tmpSubnet->subnet_addr = addr; + tmpSubnet->subnet_addr = (addr & mask); tmpSubnet->subnet_mask = ntohl(mask); tmpSubnet->next = NULL; diff --git a/src/ifvc.c b/src/ifvc.c index 509012f0..9fee7b48 100644 --- a/src/ifvc.c +++ b/src/ifvc.c @@ -201,8 +201,10 @@ void rebuildIfVc () { ** */ void buildIfVc(void) { - struct ifreq IfVc[ sizeof( IfDescVc ) / sizeof( IfDescVc[ 0 ] ) ]; + struct ifreq IfVc[ MAX_IF * 2 ]; /* allocate in double in order to get as much information as possible */ struct ifreq *IfEp; + struct IfDesc *dp; + struct SubnetList *allowednet, *currsubnet; struct Config *config = getCommonConfig(); int Sock; @@ -246,6 +248,19 @@ void buildIfVc(void) { if (IfNext < IfPt + 1) IfNext = IfPt + 1; + /* don't retrieve any further info if MAX_IF is reached + */ + if ( IfDescEp >= &IfDescVc[ MAX_IF ] ) { + my_log(LOG_DEBUG, 0, "Too many interfaces, skipping all since %s", IfPt->ifr_name); + break; + } + + /* don't retrieve any info from non-IPv4 interfaces + */ + if ( IfPt->ifr_addr.sa_family != AF_INET ) { + my_log(LOG_DEBUG, 0, "Interface is not AF_INET, skipping %s (family %d)", IfPt->ifr_name, IfPt->ifr_addr.sa_family); + continue; + } strncpy( IfDescEp->Name, IfPt->ifr_name, sizeof( IfDescEp->Name ) ); // Currently don't set any allowed nets... @@ -254,14 +269,6 @@ void buildIfVc(void) { // Set the index to -1 by default. IfDescEp->index = (unsigned int)-1; - /* don't retrieve more info for non-IP interfaces - */ - if ( IfPt->ifr_addr.sa_family != AF_INET ) { - IfDescEp->InAdr.s_addr = 0; /* mark as non-IP interface */ - IfDescEp++; - continue; - } - // Get the interface adress... IfDescEp->InAdr.s_addr = s_addr_from_sockaddr(&IfPt->ifr_addr); addr = IfDescEp->InAdr.s_addr; @@ -274,6 +281,21 @@ void buildIfVc(void) { mask = s_addr_from_sockaddr(&IfReq.ifr_addr); // Do not use ifr_netmask as it is not available on freebsd subnet = addr & mask; + dp = getIfByName(IfPt->ifr_name, 1); + if (dp != NULL && dp->allowednets != NULL) { + allowednet = (struct SubnetList *)malloc(sizeof(struct SubnetList)); + if (allowednet == NULL) my_log(LOG_ERR, 0, "Out of memory !"); + allowednet->next = NULL; + allowednet->subnet_mask = mask; + allowednet->subnet_addr = subnet; + currsubnet = dp->allowednets; + while (currsubnet->next != NULL) + currsubnet = currsubnet->next; + currsubnet->next = allowednet; + continue; + } + + /* get if flags ** ** typical flags: @@ -333,13 +355,16 @@ void buildIfVc(void) { ** - NULL if no interface 'IfName' exists ** */ -struct IfDesc *getIfByName( const char *IfName ) { +struct IfDesc *getIfByName( const char *IfName, int iponly ) { struct IfDesc *Dp; - for ( Dp = IfDescVc; Dp < IfDescEp; Dp++ ) - if ( ! strcmp( IfName, Dp->Name ) ) - return Dp; - + for ( Dp = IfDescVc; Dp < IfDescEp; Dp++ ) { + if (iponly && Dp->InAdr.s_addr == 0) + continue; + if ( ! strcmp( IfName, Dp->Name ) ) + return Dp; + } + return NULL; } From 0ee16befe403b9aca025354db71473dc671d1ad5 Mon Sep 17 00:00:00 2001 From: Abraham Fernandez Date: Tue, 31 Jul 2018 16:15:25 +0200 Subject: [PATCH 2/3] Changed header missing --- src/igmpproxy.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/igmpproxy.h b/src/igmpproxy.h index ad1063be..95f00e6e 100644 --- a/src/igmpproxy.h +++ b/src/igmpproxy.h @@ -186,7 +186,7 @@ extern int upStreamIfIdx[MAX_UPS_VIFS]; */ void rebuildIfVc( void ); void buildIfVc( void ); -struct IfDesc *getIfByName( const char *IfName ); +struct IfDesc *getIfByName( const char *IfName, int iponly ); struct IfDesc *getIfByIx( unsigned Ix ); struct IfDesc *getIfByAddress( uint32_t Ix ); struct IfDesc *getIfByVifIndex( unsigned vifindex ); From 89b35284116873d30583fe0a650f45b74940909a Mon Sep 17 00:00:00 2001 From: Abraham Fernandez Alvarez Date: Thu, 2 Aug 2018 16:53:13 +0200 Subject: [PATCH 3/3] Reverted config.c --- src/config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.c b/src/config.c index 2f0975fe..77f3d423 100644 --- a/src/config.c +++ b/src/config.c @@ -396,7 +396,7 @@ struct SubnetList *parseSubnetAddress(char *addrstr) { } tmpSubnet = (struct SubnetList*) malloc(sizeof(struct SubnetList)); - tmpSubnet->subnet_addr = (addr & mask); + tmpSubnet->subnet_addr = addr; tmpSubnet->subnet_mask = ntohl(mask); tmpSubnet->next = NULL;