diff --git a/src/igmp.c b/src/igmp.c index 38914377..2e69068b 100644 --- a/src/igmp.c +++ b/src/igmp.c @@ -32,7 +32,7 @@ ** */ /** -* igmp.h - Recieves IGMP requests, and handle them +* igmp.c - Receives IGMP requests, and handle them * appropriately... */ @@ -50,7 +50,7 @@ extern int MRouterFD; * Open and initialize the igmp socket, and fill in the non-changing * IP header fields in the output packet buffer. */ -void initIgmp(void) { +void igmp_init(void) { struct ip *ip; recv_buf = malloc(RECV_BUF_SIZE); @@ -103,7 +103,7 @@ static const char *igmpPacketKind(unsigned int type, unsigned int code) { * Process a newly received IGMP packet that is sitting in the input * packet buffer. */ -void acceptIgmp(int recvlen) { +static void acceptIgmp(int recvlen) { register uint32_t src, dst, group; struct ip *ip; struct igmp *igmp; @@ -262,6 +262,23 @@ void acceptIgmp(int recvlen) { } } +/* Receive IGMP packet + * + * @return 0 if the function succeeds, 1 if recvfrom fails + */ +int igmp_receive(void) { + socklen_t dummy = 0; + int recvlen = recvfrom(MRouterFD, recv_buf, RECV_BUF_SIZE, 0, NULL, &dummy); + if (recvlen < 0) { + if (errno != EINTR) my_log(LOG_ERR, errno, "recvfrom"); + return 1; + } + + acceptIgmp(recvlen); + + return 0; +} + /* * Construct an IGMP message in the output packet buffer. The caller may @@ -304,7 +321,7 @@ static void buildIgmp(uint32_t src, uint32_t dst, int type, int code, uint32_t g * Then send the message from the interface with IP address 'src' to * destination 'dst'. */ -void sendIgmp(uint32_t src, uint32_t dst, int type, int code, uint32_t group, int datalen) { +void igmp_send(uint32_t src, uint32_t dst, int type, int code, uint32_t group, int datalen) { struct sockaddr_in sdst; int setloop = 0, setigmpsource = 0; diff --git a/src/igmpproxy.c b/src/igmpproxy.c index 9d1172b3..9a638e75 100644 --- a/src/igmpproxy.c +++ b/src/igmpproxy.c @@ -232,7 +232,7 @@ int igmpProxyInit(void) { } // Initialize IGMP - initIgmp(); + igmp_init(); // Initialize Routing table initRouteTable(); // Initialize timer @@ -259,10 +259,8 @@ void igmpProxyRun(void) { // Get the config. struct Config *config = getCommonConfig(); // Set some needed values. - register int recvlen; 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; @@ -318,15 +316,9 @@ void igmpProxyRun(void) { // Read IGMP request, and handle it... if( FD_ISSET( MRouterFD, &ReadFDS ) ) { - - recvlen = recvfrom(MRouterFD, recv_buf, RECV_BUF_SIZE, - 0, NULL, &dummy); - if (recvlen < 0) { - if (errno != EINTR) my_log(LOG_ERR, errno, "recvfrom"); + if (igmp_receive()) { continue; } - - acceptIgmp(recvlen); } } diff --git a/src/igmpproxy.h b/src/igmpproxy.h index ad1063be..3e211e63 100644 --- a/src/igmpproxy.h +++ b/src/igmpproxy.h @@ -223,9 +223,9 @@ struct Config *getCommonConfig(void); extern uint32_t allhosts_group; extern uint32_t allrouters_group; extern uint32_t alligmp3_group; -void initIgmp(void); -void acceptIgmp(int); -void sendIgmp (uint32_t, uint32_t, int, int, uint32_t,int); +void igmp_init(void); +int igmp_receive(void); +void igmp_send(uint32_t, uint32_t, int, int, uint32_t, int); /* lib.c */ diff --git a/src/request.c b/src/request.c index 13d92ff7..ae34f5f8 100644 --- a/src/request.c +++ b/src/request.c @@ -188,7 +188,7 @@ void sendGroupSpecificMemberQuery(void *argument) { if (interfaceInRoute(gvDesc->group ,Dp->index)) { // Send a group specific membership query... - sendIgmp(Dp->InAdr.s_addr, gvDesc->group, + igmp_send(Dp->InAdr.s_addr, gvDesc->group, IGMP_MEMBERSHIP_QUERY, conf->lastMemberQueryInterval * IGMP_TIMER_SCALE, gvDesc->group, 0); @@ -219,7 +219,7 @@ void sendGeneralMembershipQuery(void) { if ( Dp->InAdr.s_addr && ! (Dp->Flags & IFF_LOOPBACK) ) { if(Dp->state == IF_STATE_DOWNSTREAM) { // Send the membership query... - sendIgmp(Dp->InAdr.s_addr, allhosts_group, + igmp_send(Dp->InAdr.s_addr, allhosts_group, IGMP_MEMBERSHIP_QUERY, conf->queryResponseInterval * IGMP_TIMER_SCALE, 0, 0);