diff options
Diffstat (limited to 'pimd/pim_sock.c')
| -rw-r--r-- | pimd/pim_sock.c | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/pimd/pim_sock.c b/pimd/pim_sock.c index 278a0972f8..a2e166f796 100644 --- a/pimd/pim_sock.c +++ b/pimd/pim_sock.c @@ -34,6 +34,7 @@ #include "log.h" #include "privs.h" #include "if.h" +#include "vrf.h" #include "pimd.h" #include "pim_mroute.h" @@ -67,7 +68,7 @@ int pim_socket_raw(int protocol) return fd; } -int pim_socket_mcast(int protocol, struct in_addr ifaddr, int loop) +int pim_socket_mcast(int protocol, struct in_addr ifaddr, int ifindex, int loop) { int fd; @@ -78,6 +79,33 @@ int pim_socket_mcast(int protocol, struct in_addr ifaddr, int loop) return PIM_SOCK_ERR_SOCKET; } + if (protocol == IPPROTO_PIM) + { + int ret; + struct interface *ifp = NULL; + + ifp = if_lookup_by_index_vrf (ifindex, VRF_DEFAULT); + + if (pimd_privs.change (ZPRIVS_RAISE)) + zlog_err ("%s: could not raise privs, %s", + __PRETTY_FUNCTION__, safe_strerror (errno)); + + ret = setsockopt (fd, SOL_SOCKET, + SO_BINDTODEVICE, ifp->name, strlen (ifp->name)); + + if (pimd_privs.change (ZPRIVS_LOWER)) + zlog_err ("%s: could not lower privs, %s", + __PRETTY_FUNCTION__, safe_strerror (errno)); + + if (ret) + { + zlog_warn("Could not set fd: %d for interface: %s to device", + fd, ifp->name); + return PIM_SOCK_ERR_BIND; + } + } + + /* Needed to obtain destination address from recvmsg() */ { #if defined(HAVE_IP_PKTINFO) |
