Skip to content

Feature/clean igmp #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions src/igmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
**
*/
/**
* igmp.h - Recieves IGMP requests, and handle them
* igmp.c - Receives IGMP requests, and handle them
* appropriately...
*/

Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down
12 changes: 2 additions & 10 deletions src/igmpproxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ int igmpProxyInit(void) {
}

// Initialize IGMP
initIgmp();
igmp_init();
// Initialize Routing table
initRouteTable();
// Initialize timer
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/igmpproxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
4 changes: 2 additions & 2 deletions src/request.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down