From b3f2bf7cbe92b1ee6942f68038f17a3329c61f06 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Thu, 4 Aug 2016 10:07:30 -0300 Subject: [PATCH] pimd: add a workaround for *BSD VIFF_USE_IFINDEX is not available on BSDs and other UNIX systems. In order to build pimd on these platforms, use 'vifc_lcl_addr' instead of 'vifc_lcl_ifindex' to specify the interfaces we want to enable forwarding of multicast traffic. In the case of unnumbered interfaces, print an error and return. Signed-off-by: Renato Westphal --- configure.ac | 45 ++++++++++++++++++++++++++++++++++++++++----- pimd/pim_iface.c | 24 ++++++++---------------- pimd/pim_mroute.c | 9 +++++++++ 3 files changed, 57 insertions(+), 21 deletions(-) diff --git a/configure.ac b/configure.ac index 6f07f10cd0..50918227e9 100755 --- a/configure.ac +++ b/configure.ac @@ -996,11 +996,46 @@ dnl figure out how to specify an interface in multicast sockets API dnl --------------------------------------------------------------- AC_CHECK_MEMBERS([struct ip_mreqn.imr_ifindex], [], [], QUAGGA_INCLUDES) -AC_CHECK_HEADERS([linux/mroute.h], [], [], -[ -#if HAVE_NETINET_IN_H -#include -#endif]) +AC_CHECK_HEADERS([linux/mroute.h], [], [],[ + #ifdef HAVE_SYS_SOCKET_H + # include + #endif + #ifdef HAVE_NETINET_IN_H + # include + #endif + #define _LINUX_IN_H /* For Linux <= 2.6.25 */ + #include +]) + +m4_define([QUAGGA_INCLUDES], +QUAGGA_INCLUDES +[#if HAVE_LINUX_MROUTE_H +# include +#endif +])dnl + +AC_CHECK_HEADERS([netinet/ip_mroute.h], [], [],[ + #ifdef HAVE_SYS_SOCKET_H + # include + #endif + #ifdef HAVE_SYS_TYPES_H + # include + #endif + #ifdef HAVE_NETINET_IN_H + # include + #endif + #ifdef HAVE_NET_ROUTE_H + # include + #endif +]) + +m4_define([QUAGGA_INCLUDES], +QUAGGA_INCLUDES +[#if HAVE_NETINET_IP_MROUTE_H +# include +#endif +])dnl + AC_MSG_CHECKING([for BSD struct ip_mreq hack]) AC_TRY_COMPILE([#ifdef HAVE_SYS_PARAM_H #include diff --git a/pimd/pim_iface.c b/pimd/pim_iface.c index 14c8c7262e..3c60275027 100644 --- a/pimd/pim_iface.c +++ b/pimd/pim_iface.c @@ -41,19 +41,6 @@ #include "pim_time.h" #include "pim_ssmpingd.h" -#ifndef VIFF_USE_IFINDEX -# ifdef linux -/* make it work compile-time - whether it works runtime depends on the user - * having 2.6.32 or newer */ -# define VIFF_USE_IFINDEX 0x8 -# else -# error no VIFF_USE_IFINDEX on this system, code needs porting -/* NB: without VIFF_USE_IFINDEX, the local IP address is used to identify - * interfaces, which means it's impossible to support multiple interfaces that - * have the same or no IP address (e.g. unnumbered) */ -# endif -#endif - struct interface *pim_regiface = NULL; static void pim_if_igmp_join_del_all(struct interface *ifp); @@ -645,7 +632,7 @@ int pim_if_add_vif(struct interface *ifp) { struct pim_interface *pim_ifp = ifp->info; struct in_addr ifaddr; - unsigned char flags; + unsigned char flags = 0; zassert(pim_ifp); @@ -681,8 +668,13 @@ int pim_if_add_vif(struct interface *ifp) return -3; } - flags = (ifp->ifindex == PIM_OIF_PIM_REGISTER_VIF) ? - VIFF_REGISTER : VIFF_USE_IFINDEX; + if (ifp->ifindex == PIM_OIF_PIM_REGISTER_VIF) + flags = VIFF_REGISTER; +#ifdef VIFF_USE_IFINDEX + else + flags = VIFF_USE_IFINDEX; +#endif + if (pim_mroute_add_vif(ifp, ifaddr, flags)) { /* pim_mroute_add_vif reported error */ return -5; diff --git a/pimd/pim_mroute.c b/pimd/pim_mroute.c index ab3742438d..56f49d62f5 100644 --- a/pimd/pim_mroute.c +++ b/pimd/pim_mroute.c @@ -501,7 +501,16 @@ int pim_mroute_add_vif(struct interface *ifp, struct in_addr ifaddr, unsigned ch memset(&vc, 0, sizeof(vc)); vc.vifc_vifi = pim_ifp->mroute_vif_index; +#ifdef VIFF_USE_IFINDEX vc.vifc_lcl_ifindex = ifp->ifindex; +#else + if (ifaddr.s_addr == INADDR_ANY) { + zlog_warn("%s: unnumbered interfaces are not supported on this platform", + __PRETTY_FUNCTION__); + return -1; + } + memcpy(&vc.vifc_lcl_addr, &ifaddr, sizeof(vc.vifc_lcl_addr)); +#endif vc.vifc_flags = flags; vc.vifc_threshold = PIM_MROUTE_MIN_TTL; vc.vifc_rate_limit = 0; -- 2.39.5