Skip to content

Commit

Permalink
Add option to add routes for unknown multicast groups
Browse files Browse the repository at this point in the history
  • Loading branch information
Uglymotha committed Dec 6, 2024
1 parent 87a4a75 commit c8bc020
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ int openCliFd(void) {

// Open the socket, set permissions and mode.
if (cli_fd == -1) {
if ( ! strcpy(cli_sa.sun_path, CONF->runPath)
if ( ! strncpy(cli_sa.sun_path, CONF->runPath, sizeof(cli_sa.sun_path))
|| ! snprintf(cli_sa.sun_path + strlen(cli_sa.sun_path), sizeof(cli_sa.sun_path) - strlen(cli_sa.sun_path),
mrt_tbl ? "cli-%d.sock" : "cli.sock", mrt_tbl)
|| (stat(cli_sa.sun_path, &st) == 0 && unlink(cli_sa.sun_path) < 0)
Expand Down
19 changes: 17 additions & 2 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ static inline void parseFilters(char *in, char *token, struct filters ***filP,
static inline bool parsePhyintToken(char *token);

// All valid configuration options. Prepend whitespace to allow for strstr() exact token matching.
static const char *options = " include phyint user group chroot defaultquickleave quickleave maxorigins hashtablesize routetables defaultdown defaultup defaultupdown defaultthreshold defaultratelimit defaultquerierver defaultquerierip defaultrobustness defaultqueryinterval defaultqueryrepsonseinterval defaultlastmemberinterval defaultlastmembercount bwcontrol rescanvif rescanconf loglevel logfile defaultproxylocalmc defaultnoquerierelection proxylocalmc noproxylocalmc upstream downstream disabled ratelimit threshold querierver querierip robustness queryinterval queryrepsonseinterval lastmemberinterval lastmembercount defaultnocksumverify nocksumverify cksumverify noquerierelection querierelection nocksumverify cksumverify noquerierelection querierelection defaultfilterany nodefaultfilter filter altnet whitelist reqqueuesize kbufsize pbufsize maxtbl defaulttable defaultdisableipmrules";
static const char *phyintopt = " table updownstream upstream downstream disabled proxylocalmc noproxylocalmc quickleave noquickleave ratelimit threshold nocksumverify cksumverify noquerierelection querierelection querierip querierver robustnessvalue queryinterval queryrepsonseinterval lastmemberinterval lastmembercount defaultfilter filter altnet whitelist disableipmrules";
static const char *options = " include phyint user group chroot defaultquickleave quickleave maxorigins hashtablesize routetables defaultdown defaultup defaultupdown defaultthreshold defaultratelimit defaultquerierver defaultquerierip defaultrobustness defaultqueryinterval defaultqueryrepsonseinterval defaultlastmemberinterval defaultlastmembercount bwcontrol rescanvif rescanconf loglevel logfile defaultproxylocalmc defaultnoquerierelection proxylocalmc noproxylocalmc upstream downstream disabled ratelimit threshold querierver querierip robustness queryinterval queryrepsonseinterval lastmemberinterval lastmembercount defaultnocksumverify nocksumverify cksumverify noquerierelection querierelection nocksumverify cksumverify noquerierelection querierelection defaultfilterany nodefaultfilter filter altnet whitelist reqqueuesize kbufsize pbufsize maxtbl defaulttable defaultdisableipmrules defaultrouteunknownmc";
static const char *phyintopt = " table updownstream upstream downstream disabled proxylocalmc noproxylocalmc quickleave noquickleave ratelimit threshold nocksumverify cksumverify noquerierelection querierelection querierip querierver robustnessvalue queryinterval queryrepsonseinterval lastmemberinterval lastmembercount defaultfilter filter altnet whitelist disableipmrules routeunknownmc norouteunknownmc";

// Daemon Configuration.
static struct Config conf, oldconf;
Expand Down Expand Up @@ -236,6 +236,9 @@ static inline void initCommonConfig(void) {
// Log to file disabled by default.
conf.logLevel = !conf.log2Stderr ? LOG_WARNING : conf.logLevel;

// Do not add routes for unknown groups by default.
conf.routeUnknownMc = false;

// Default no timed rebuild interfaces / reload config.
conf.rescanVif = 0;
conf.rescanConf = 0;
Expand Down Expand Up @@ -488,6 +491,14 @@ static inline bool parsePhyintToken(char *token) {
tmpPtr->cksumVerify = true;
LOG(LOG_NOTICE, 0, "Config (%s): Will verify IGMP checksums.", tmpPtr->name);

} else if (strcmp(" routeunknownmc", token) == 0) {
tmpPtr->routeUnknownMc = true;
LOG(LOG_NOTICE, 0, "Config (%s): Will add routes for unknown groups.", tmpPtr->name);

} else if (strcmp(" norouteunknownmc", token) == 0) {
tmpPtr->routeUnknownMc = false;
LOG(LOG_NOTICE, 0, "Config (%s): Will not add routes for unknown groups.", tmpPtr->name);

} else if (strcmp(" robustness", token) == 0 && INTTOKEN) {
if (intToken < 1 || intToken > 7)
LOG(LOG_WARNING, 0, "Config (%s): Robustness value must be between 1 and 7.", tmpPtr->name);
Expand Down Expand Up @@ -830,6 +841,10 @@ bool loadConfig(char *cfgFile) {
LOG(LOG_NOTICE, 0, "Config: Setting default last member query count to %d.", intToken);
}

} else if (strcmp(" defaultrouteunknownmc", token) == 0 && INTTOKEN) {
conf.routeUnknownMc = true;
LOG(LOG_NOTICE, 0, "Config: Will add routes for unknown MC groups.", intToken);

} else if (strcmp(" bwcontrol", token) == 0 && INTTOKEN) {
conf.bwControlInterval = intToken < 3 ? 3 : intToken;
LOG(LOG_NOTICE, 0, "Config: Setting bandwidth control interval to %ds.", intToken);
Expand Down
5 changes: 4 additions & 1 deletion src/igmpv3proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ struct Config {
uint8_t logLevel;
char *logFilePath;
bool log2Stderr; // Log to stderr instead of to syslog / file
// Set if mc route needs to be added for unknown groups.
bool routeUnknownMc;
// Set if nneed to detect new interface.
uint32_t rescanVif;
// Set if nneed to detect config change.
Expand Down Expand Up @@ -205,12 +207,13 @@ struct vifConfig {
bool cksumVerify; // Do not validate igmp checksums on interface
bool quickLeave; // Fast upstream leave
bool proxyLocalMc; // Forward local multicast
bool routeUnknownMc; // Add routes for unknown (not requested downstream) groups
struct filters *filters; // ACL for interface
struct filters *rates; // Ratelimiters for interface
struct vifConfig *next;
};
#define VIFSZ (sizeof(struct vifConfig))
#define DEFAULT_VIFCONF (struct vifConfig){ "", conf.defaultTable, conf.defaultInterfaceState, conf.defaultThreshold, conf.defaultRatelimit, {conf.querierIp, conf.querierVer, conf.querierElection, conf.robustnessValue, conf.queryInterval, conf.queryResponseInterval, conf.lastMemberQueryInterval, conf.lastMemberQueryCount, 0, 0}, conf.disableIpMrules, false, conf.cksumVerify, conf.quickLeave, conf.proxyLocalMc, NULL, NULL, vifConf }
#define DEFAULT_VIFCONF (struct vifConfig){ "", conf.defaultTable, conf.defaultInterfaceState, conf.defaultThreshold, conf.defaultRatelimit, {conf.querierIp, conf.querierVer, conf.querierElection, conf.robustnessValue, conf.queryInterval, conf.queryResponseInterval, conf.lastMemberQueryInterval, conf.lastMemberQueryCount, 0, 0}, conf.disableIpMrules, false, conf.cksumVerify, conf.quickLeave, conf.proxyLocalMc, conf.routeUnknownMc, NULL, NULL, vifConf }

// Running querier status for interface.
struct querier { // igmp querier status for interface
Expand Down
2 changes: 1 addition & 1 deletion src/mctable.c
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ inline bool toInclude(struct mcTable *mct, struct IfDesc *IfDp) {
*/
inline void activateRoute(struct IfDesc *IfDp, void *_src, register uint32_t ip, register uint32_t group, bool activate) {
struct src *src = _src;
struct mcTable *mct = src ? src->mct : findGroup(group, false);
struct mcTable *mct = src ? src->mct : findGroup(group, IfDp->conf->routeUnknownMc);
if (! mct) {
LOG(LOG_DEBUG, 0, "activateRoute: Group %s not found, ignoring activation.", inetFmt(group, 1), inetFmt(group, 2));
return;
Expand Down

0 comments on commit c8bc020

Please sign in to comment.