mirror of
https://git.proxmox.com/git/mirror_frr
synced 2026-02-01 18:37:27 +00:00
*: create a helper function to set the IP_MULTICAST_LOOP sockoption
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
This commit is contained in:
parent
5736139d4a
commit
c5bdb09fd9
@ -421,15 +421,7 @@ sock_set_ipv4_mcast(struct iface *iface)
|
||||
int
|
||||
sock_set_ipv4_mcast_loop(int fd)
|
||||
{
|
||||
uint8_t loop = 0;
|
||||
|
||||
if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP,
|
||||
(char *)&loop, sizeof(loop)) < 0) {
|
||||
log_warn("%s: error setting IP_MULTICAST_LOOP", __func__);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
return (0);
|
||||
return (setsockopt_ipv4_multicast_loop(fd, 0));
|
||||
}
|
||||
|
||||
int
|
||||
|
||||
@ -384,7 +384,20 @@ setsockopt_ipv4_multicast_if(int sock, struct in_addr if_addr,
|
||||
#error "Unsupported multicast API"
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
setsockopt_ipv4_multicast_loop (int sock, u_char val)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = setsockopt (sock, IPPROTO_IP, IP_MULTICAST_LOOP, (void *) &val,
|
||||
sizeof (val));
|
||||
if (ret < 0)
|
||||
zlog_warn ("can't setsockopt IP_MULTICAST_LOOP");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
setsockopt_ipv4_ifindex (int sock, ifindex_t val)
|
||||
{
|
||||
|
||||
@ -89,6 +89,8 @@ extern int setsockopt_ipv4_multicast(int sock, int optname,
|
||||
struct in_addr if_addr,
|
||||
unsigned int mcast_addr,
|
||||
ifindex_t ifindex);
|
||||
extern int setsockopt_ipv4_multicast_loop (int sock, u_char val);
|
||||
|
||||
extern int setsockopt_ipv4_tos(int sock, int tos);
|
||||
|
||||
/* Ask for, and get, ifindex, by whatever method is supported. */
|
||||
|
||||
@ -132,18 +132,16 @@ ospf_if_ipmulticast (struct ospf *top, struct prefix *p, ifindex_t ifindex)
|
||||
{
|
||||
u_char val;
|
||||
int ret, len;
|
||||
|
||||
val = 0;
|
||||
len = sizeof (val);
|
||||
|
||||
|
||||
/* Prevent receiving self-origined multicast packets. */
|
||||
ret = setsockopt (top->fd, IPPROTO_IP, IP_MULTICAST_LOOP, (void *)&val, len);
|
||||
ret = setsockopt_ipv4_multicast_loop (top->fd, 0);
|
||||
if (ret < 0)
|
||||
zlog_warn ("can't setsockopt IP_MULTICAST_LOOP(0) for fd %d: %s",
|
||||
top->fd, safe_strerror(errno));
|
||||
|
||||
/* Explicitly set multicast ttl to 1 -- endo. */
|
||||
val = 1;
|
||||
len = sizeof (val);
|
||||
ret = setsockopt (top->fd, IPPROTO_IP, IP_MULTICAST_TTL, (void *)&val, len);
|
||||
if (ret < 0)
|
||||
zlog_warn ("can't setsockopt IP_MULTICAST_TTL(1) for fd %d: %s",
|
||||
|
||||
@ -35,6 +35,7 @@
|
||||
#include "privs.h"
|
||||
#include "if.h"
|
||||
#include "vrf.h"
|
||||
#include "sockopt.h"
|
||||
|
||||
#include "pimd.h"
|
||||
#include "pim_mroute.h"
|
||||
@ -173,8 +174,7 @@ int pim_socket_mcast(int protocol, struct in_addr ifaddr, int ifindex, u_char lo
|
||||
}
|
||||
}
|
||||
|
||||
if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP,
|
||||
(void *) &loop, sizeof(loop))) {
|
||||
if (setsockopt_ipv4_multicast_loop (fd, loop)) {
|
||||
zlog_warn("Could not %s Multicast Loopback Option on socket fd=%d: errno=%d: %s",
|
||||
loop ? "enable" : "disable",
|
||||
fd, errno, safe_strerror(errno));
|
||||
|
||||
@ -25,6 +25,7 @@
|
||||
#include "if.h"
|
||||
#include "log.h"
|
||||
#include "memory.h"
|
||||
#include "sockopt.h"
|
||||
|
||||
#include "pim_ssmpingd.h"
|
||||
#include "pim_time.h"
|
||||
@ -150,17 +151,12 @@ static int ssmpingd_socket(struct in_addr addr, int port, int mttl)
|
||||
return -1;
|
||||
}
|
||||
|
||||
{
|
||||
u_char loop = 0;
|
||||
if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP,
|
||||
(void *) &loop, sizeof(loop))) {
|
||||
zlog_warn("%s: could not %s Multicast Loopback Option on socket fd=%d: errno=%d: %s",
|
||||
__PRETTY_FUNCTION__,
|
||||
loop ? "enable" : "disable",
|
||||
fd, errno, safe_strerror(errno));
|
||||
close(fd);
|
||||
return PIM_SOCK_ERR_LOOP;
|
||||
}
|
||||
if (setsockopt_ipv4_multicast_loop (fd, 0)) {
|
||||
zlog_warn("%s: could not disable Multicast Loopback Option on socket fd=%d: errno=%d: %s",
|
||||
__PRETTY_FUNCTION__,
|
||||
fd, errno, safe_strerror(errno));
|
||||
close(fd);
|
||||
return PIM_SOCK_ERR_LOOP;
|
||||
}
|
||||
|
||||
if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_IF,
|
||||
|
||||
@ -323,12 +323,8 @@ send_packet(struct interface *ifp,
|
||||
zlog_warn("sendto %s", safe_strerror (errno));
|
||||
}
|
||||
|
||||
if(dst != INADDR_BROADCAST) {
|
||||
on = 0;
|
||||
if( setsockopt(irdp_sock,IPPROTO_IP, IP_MULTICAST_LOOP,
|
||||
(char *)&on,sizeof(on)) < 0)
|
||||
zlog_warn("sendto %s", safe_strerror (errno));
|
||||
}
|
||||
if(dst != INADDR_BROADCAST)
|
||||
setsockopt_ipv4_multicast_loop (irdp_sock, 0);
|
||||
|
||||
memset(&sockdst,0,sizeof(sockdst));
|
||||
sockdst.sin_family=AF_INET;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user