diff options
| author | Donald Sharp <sharpd@cumulusnetworks.com> | 2016-06-28 21:50:49 -0400 |
|---|---|---|
| committer | Donald Sharp <sharpd@cumulusnetworks.com> | 2016-06-28 21:50:49 -0400 |
| commit | 61ea3951a2ecd0d439cb772d566f43e544c8ba48 (patch) | |
| tree | 1662320fd1967d4f57ca5eb1daeaa44724e204ac /pimd/pim_sock.c | |
| parent | bab3cf0a8e7572ace6f5ebc3cde320fd00f5e8e7 (diff) | |
pimd: Bind pim sockets to interface they are associated with
When pim is receiving packets, each interface's fd is receiving
packets for all interfaces. Modify the code to bind the
pim interface sockets to the interface they were created for.
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
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) |
