Skip to content

Commit

Permalink
Remove duplicate code in mcgroup.c file
Browse files Browse the repository at this point in the history
Existing functionality is provided by k_join and k_leave functions.
  • Loading branch information
pali committed Sep 5, 2020
1 parent a7791d5 commit 78eda58
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 125 deletions.
1 change: 0 additions & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ igmpproxy_SOURCES = \
igmpproxy.h \
kern.c \
lib.c \
mcgroup.c \
mroute-api.c \
os-dragonfly.h \
os-freebsd.h \
Expand Down
6 changes: 3 additions & 3 deletions src/ifvc.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,15 @@ void rebuildIfVc () {
my_log(LOG_NOTICE, 0, "%s [Hidden -> Downstream]", Dp->Name);
Dp->state = IF_STATE_DOWNSTREAM;
addVIF(Dp);
joinMcGroup(MRouterFD, Dp, allrouters_group);
k_join(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(MRouterFD, Dp, allrouters_group);
k_join(Dp, allrouters_group);
IfDescEp++;
}

Expand All @@ -187,7 +187,7 @@ void rebuildIfVc () {
if (IF_STATE_LOST == Dp->state) {
my_log(LOG_NOTICE, 0, "%s [Downstream -> Hidden]", Dp->Name);
Dp->state = IF_STATE_HIDDEN;
leaveMcGroup( MRouterFD, Dp, allrouters_group );
k_leave(Dp, allrouters_group);
delVIF(Dp);
}
}
Expand Down
12 changes: 2 additions & 10 deletions src/igmpproxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,16 +242,8 @@ void k_hdr_include(int hdrincl);
void k_set_ttl(int t);
void k_set_loop(int l);
void k_set_if(uint32_t ifa);
/*
void k_join(uint32_t grp, uint32_t ifa);
void k_leave(uint32_t grp, uint32_t ifa);
*/

/* mcgroup.c
*/
int joinMcGroup( int UdpSock, struct IfDesc *IfDp, uint32_t mcastaddr );
int leaveMcGroup( int UdpSock, struct IfDesc *IfDp, uint32_t mcastaddr );

void k_join(struct IfDesc *ifd, uint32_t grp);
void k_leave(struct IfDesc *ifd, uint32_t grp);

/* rttable.c
*/
Expand Down
29 changes: 19 additions & 10 deletions src/kern.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,29 +111,38 @@ void k_set_if(uint32_t ifa) {
inetFmt(ifa, s1));
}

/*
void k_join(uint32_t grp, uint32_t ifa) {
void k_join(struct IfDesc *ifd, uint32_t grp) {
struct ip_mreq mreq;

mreq.imr_multiaddr.s_addr = grp;
mreq.imr_interface.s_addr = ifa;
mreq.imr_interface.s_addr = ifd->InAdr.s_addr;

my_log(LOG_NOTICE, 0, "Joining group %s on interface %s", inetFmt(grp, s1), ifd->Name);

if (setsockopt(MRouterFD, IPPROTO_IP, IP_ADD_MEMBERSHIP,
(char *)&mreq, sizeof(mreq)) < 0)
(char *)&mreq, sizeof(mreq)) < 0) {
int mcastGroupExceeded = (errno == ENOBUFS);
my_log(LOG_WARNING, errno, "can't join group %s on interface %s",
inetFmt(grp, s1), inetFmt(ifa, s2));
inetFmt(grp, s1), ifd->Name);
if (mcastGroupExceeded) {
my_log(LOG_WARNING, 0, "Maximum number of multicast groups were exceeded");
#ifdef __linux__
my_log(LOG_WARNING, 0, "Check settings of '/sbin/sysctl net.ipv4.igmp_max_memberships'");
#endif
}
}
}

void k_leave(uint32_t grp, uint32_t ifa) {
void k_leave(struct IfDesc *ifd, uint32_t grp) {
struct ip_mreq mreq;

mreq.imr_multiaddr.s_addr = grp;
mreq.imr_interface.s_addr = ifa;
mreq.imr_interface.s_addr = ifd->InAdr.s_addr;

my_log(LOG_NOTICE, 0, "Leaving group %s on interface %s", inetFmt(grp, s1), ifd->Name);

if (setsockopt(MRouterFD, IPPROTO_IP, IP_DROP_MEMBERSHIP,
(char *)&mreq, sizeof(mreq)) < 0)
my_log(LOG_WARNING, errno, "can't leave group %s on interface %s",
inetFmt(grp, s1), inetFmt(ifa, s2));
inetFmt(grp, s1), ifd->Name);
}
*/
94 changes: 0 additions & 94 deletions src/mcgroup.c

This file was deleted.

11 changes: 4 additions & 7 deletions src/rttable.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,11 @@ void initRouteTable(void) {
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( MRouterFD, Dp, allrouters_group );
k_join(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( MRouterFD, Dp, alligmp3_group );
k_join(Dp, alligmp3_group);
}
}
}
Expand Down Expand Up @@ -183,8 +182,7 @@ static void sendJoinLeaveUpstream(struct RouteTable* route, int join) {
inetFmt(route->group, s1),
inetFmt(upstrIf->InAdr.s_addr, s2));

//k_join(route->group, upstrIf->InAdr.s_addr);
joinMcGroup( MRouterFD, upstrIf, route->group );
k_join(upstrIf, route->group);

route->upstrState = ROUTESTATE_JOINED;
} else {
Expand All @@ -198,8 +196,7 @@ static void sendJoinLeaveUpstream(struct RouteTable* route, int join) {
inetFmt(route->group, s1),
inetFmt(upstrIf->InAdr.s_addr, s2));

//k_leave(route->group, upstrIf->InAdr.s_addr);
leaveMcGroup( MRouterFD, upstrIf, route->group );
k_leave(upstrIf, route->group);

route->upstrState = ROUTESTATE_NOTJOINED;
}
Expand Down

0 comments on commit 78eda58

Please sign in to comment.