netjack2: implement ifname in the driver

See #4666
This commit is contained in:
Wim Taymans 2025-04-28 11:13:14 +02:00
parent 93ee66dcab
commit b6cb76bf8d
2 changed files with 12 additions and 5 deletions

View file

@ -705,7 +705,7 @@ static bool is_multicast(struct sockaddr *sa, socklen_t salen)
static int make_socket(struct sockaddr_storage *src, socklen_t src_len,
struct sockaddr_storage *dst, socklen_t dst_len,
bool loop, int ttl, int dscp)
bool loop, int ttl, int dscp, const char *ifname)
{
int af, fd, val, res;
struct timeval timeout;
@ -721,7 +721,13 @@ static int make_socket(struct sockaddr_storage *src, socklen_t src_len,
pw_log_error("setsockopt failed: %m");
goto error;
}
#ifdef SO_BINDTODEVICE
if (ifname && setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, ifname, strlen(ifname)) < 0) {
res = -errno;
pw_log_error("setsockopt(SO_BINDTODEVICE) failed: %m");
goto error;
}
#endif
#ifdef SO_PRIORITY
val = 6;
if (setsockopt(fd, SOL_SOCKET, SO_PRIORITY, &val, sizeof(val)) < 0)
@ -981,9 +987,11 @@ static int create_netjack2_socket(struct impl *impl)
impl->ttl = pw_properties_get_uint32(impl->props, "net.ttl", DEFAULT_NET_TTL);
impl->loop = pw_properties_get_bool(impl->props, "net.loop", DEFAULT_NET_LOOP);
impl->dscp = pw_properties_get_uint32(impl->props, "net.dscp", DEFAULT_NET_DSCP);
str = pw_properties_get(impl->props, "local.ifname");
fd = make_socket(&impl->src_addr, impl->src_len,
&impl->dst_addr, impl->dst_len, impl->loop, impl->ttl, impl->dscp);
&impl->dst_addr, impl->dst_len, impl->loop, impl->ttl, impl->dscp,
str);
if (fd < 0) {
res = -errno;
pw_log_error("can't create socket: %s", spa_strerror(res));

View file

@ -1082,8 +1082,7 @@ static int create_netjack2_socket(struct impl *impl)
impl->dscp = pw_properties_get_uint32(impl->props, "net.dscp", DEFAULT_NET_DSCP);
str = pw_properties_get(impl->props, "local.ifname");
fd = make_announce_socket(&impl->src_addr, impl->src_len,
pw_properties_get(impl->props, "local.ifname"));
fd = make_announce_socket(&impl->src_addr, impl->src_len, str);
if (fd < 0) {
res = fd;
pw_log_error("can't create socket: %s", spa_strerror(res));