Skip to content

Commit

Permalink
multicast: add multicast_iface for IPv6 multicast
Browse files Browse the repository at this point in the history
  • Loading branch information
maximilianfridrich committed Jul 2, 2024
1 parent 243e870 commit 79bb08b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/examples/config
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
# multicast receivers (in priority order)- port number must be even
#multicast_call_prio 0
#multicast_ttl 1
#multicast_iface eth0 # needed for IPv6 multicast
#multicast_jbuf_type fixed # off, fixed, adaptive
#multicast_jbuf_delay 5-10 # frames
#multicast_fade_time 125 # fade in/out time in [ms]
#multicast_listener 224.0.2.21:50000
#multicast_listener 224.0.2.21:50002
#multicast_listener [FF2E::42]:50004
22 changes: 22 additions & 0 deletions modules/multicast/multicast.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

#include "multicast.h"

#include <net/if.h>

#define DEBUG_MODULE "multicast"
#define DEBUG_LEVEL 6
#include <re_dbg.h>
Expand All @@ -20,12 +22,14 @@ struct mccfg {
uint32_t callprio;
uint32_t ttl;
uint32_t tfade;
char iface[128];
};

static struct mccfg mccfg = {
0,
1,
125,
""
};


Expand Down Expand Up @@ -309,6 +313,21 @@ static int cmd_mcreg(struct re_printf *pf, void *arg)
goto out;
}

if (str_isset(mccfg.iface)) {
unsigned int if_index;
if_index = if_nametoindex(mccfg.iface);
if (!if_index) {
warning("Can not find interface %s.\n", &mccfg.iface);
if (sa_af(&addr) == AF_INET6) {
err = EINVAL;
goto out;
}
}
else {
sa_set_scopeid(&addr, if_index);
}
}

err = mcreceiver_alloc(&addr, prio);

out:
Expand Down Expand Up @@ -645,6 +664,9 @@ static int module_read_config(void)
if (mccfg.tfade > 2000)
mccfg.tfade = 2000;

(void)conf_get_str(conf_cur(), "multicast_iface", mccfg.iface,
sizeof(mccfg.iface));

sa_init(&laddr, AF_INET);
err = conf_apply(conf_cur(), "multicast_listener",
module_read_config_handler, &prio);
Expand Down

0 comments on commit 79bb08b

Please sign in to comment.