diff --git a/pimd/pim_assert.c b/pimd/pim_assert.c index 5dae675716..9f9c9e66f0 100644 --- a/pimd/pim_assert.c +++ b/pimd/pim_assert.c @@ -24,6 +24,7 @@ #include "log.h" #include "prefix.h" +#include "if.h" #include "pimd.h" #include "pim_str.h" diff --git a/pimd/pim_br.c b/pimd/pim_br.c index 6958ad545d..121a45fd16 100644 --- a/pimd/pim_br.c +++ b/pimd/pim_br.c @@ -22,6 +22,7 @@ #include "memory.h" #include "log.h" +#include "if.h" #include "pimd.h" #include "pim_str.h" diff --git a/pimd/pim_hello.c b/pimd/pim_hello.c index bfc128b97a..21d0e5b85c 100644 --- a/pimd/pim_hello.c +++ b/pimd/pim_hello.c @@ -23,6 +23,7 @@ #include #include "log.h" +#include "if.h" #include "pimd.h" #include "pim_pim.h" diff --git a/pimd/pim_iface.c b/pimd/pim_iface.c index 1f818ccf51..8357a26a3e 100644 --- a/pimd/pim_iface.c +++ b/pimd/pim_iface.c @@ -607,6 +607,22 @@ struct in_addr pim_find_primary_addr(struct interface *ifp) return find_first_nonsec_addr(ifp); } +static pim_iface_vif_index = 0; + +int +pim_iface_next_vif_index (struct interface *ifp) +{ + /* + * The pimreg vif is always going to be in index 0 + * of the table. + */ + if (ifp->ifindex == PIM_OIF_PIM_REGISTER_VIF) + return 0; + + pim_iface_vif_index++; + return pim_iface_vif_index; +} + /* pim_if_add_vif() uses ifindex as vif_index @@ -634,13 +650,6 @@ int pim_if_add_vif(struct interface *ifp) return -2; } - if (ifp->ifindex >= MAXVIFS) { - zlog_warn("%s: ifindex=%d >= MAXVIFS=%d on interface %s", - __PRETTY_FUNCTION__, - ifp->ifindex, MAXVIFS, ifp->name); - return -3; - } - ifaddr = pim_ifp->primary_address; if (ifp->ifindex != PIM_OIF_PIM_REGISTER_VIF && PIM_INADDR_IS_ANY(ifaddr)) { zlog_warn("%s: could not get address for interface %s ifindex=%d", @@ -649,14 +658,23 @@ int pim_if_add_vif(struct interface *ifp) return -4; } - flags = (ifp->ifindex == PIM_OIF_PIM_REGISTER_VIF) ? VIFF_REGISTER : VIFF_USE_IFINDEX; - if (pim_mroute_add_vif(ifp->ifindex, ifaddr, flags)) { + pim_ifp->mroute_vif_index = pim_iface_next_vif_index (ifp); + + if (pim_ifp->mroute_vif_index >= MAXVIFS) + { + zlog_warn("%s: Attempting to configure more than MAXVIFS=%d on pim enabled interface %s", + __PRETTY_FUNCTION__, + MAXVIFS, ifp->name); + return -3; + } + + flags = (ifp->ifindex == PIM_OIF_PIM_REGISTER_VIF) ? + VIFF_REGISTER : VIFF_USE_IFINDEX; + if (pim_mroute_add_vif(ifp, ifaddr, flags)) { /* pim_mroute_add_vif reported error */ return -5; } - pim_ifp->mroute_vif_index = ifp->ifindex; - /* Update highest vif_index */ diff --git a/pimd/pim_ifchannel.c b/pimd/pim_ifchannel.c index 5271d412d1..abfa5cc2b7 100644 --- a/pimd/pim_ifchannel.c +++ b/pimd/pim_ifchannel.c @@ -25,6 +25,7 @@ #include "linklist.h" #include "thread.h" #include "memory.h" +#include "if.h" #include "pimd.h" #include "pim_str.h" diff --git a/pimd/pim_igmpv3.c b/pimd/pim_igmpv3.c index 180de9d71e..7c00204c51 100644 --- a/pimd/pim_igmpv3.c +++ b/pimd/pim_igmpv3.c @@ -23,6 +23,7 @@ #include #include "log.h" #include "memory.h" +#include "if.h" #include "pimd.h" #include "pim_iface.h" diff --git a/pimd/pim_join.c b/pimd/pim_join.c index 9d8e0012e4..f3b5e78ada 100644 --- a/pimd/pim_join.c +++ b/pimd/pim_join.c @@ -24,6 +24,7 @@ #include "log.h" #include "prefix.h" +#include "if.h" #include "pimd.h" #include "pim_str.h" diff --git a/pimd/pim_mroute.c b/pimd/pim_mroute.c index 6f5fe480f2..f85f422298 100644 --- a/pimd/pim_mroute.c +++ b/pimd/pim_mroute.c @@ -23,6 +23,7 @@ #include #include "log.h" #include "privs.h" +#include "if.h" #include "pimd.h" #include "pim_mroute.h" @@ -449,8 +450,9 @@ int pim_mroute_socket_disable() would be used for multicast forwarding, a corresponding multicast interface must be added to the kernel. */ -int pim_mroute_add_vif(int vif_index, struct in_addr ifaddr, unsigned char flags) +int pim_mroute_add_vif(struct interface *ifp, struct in_addr ifaddr, unsigned char flags) { + struct pim_interface *pim_ifp = ifp->info; struct vifctl vc; int err; @@ -461,8 +463,8 @@ int pim_mroute_add_vif(int vif_index, struct in_addr ifaddr, unsigned char flags } memset(&vc, 0, sizeof(vc)); - vc.vifc_vifi = vif_index; - vc.vifc_lcl_ifindex = vif_index; + vc.vifc_vifi = pim_ifp->mroute_vif_index; + vc.vifc_lcl_ifindex = ifp->ifindex; vc.vifc_flags = flags; vc.vifc_threshold = PIM_MROUTE_MIN_TTL; vc.vifc_rate_limit = 0; @@ -482,7 +484,7 @@ int pim_mroute_add_vif(int vif_index, struct in_addr ifaddr, unsigned char flags zlog_warn("%s %s: failure: setsockopt(fd=%d,IPPROTO_IP,MRT_ADD_VIF,vif_index=%d,ifaddr=%s,flag=%d): errno=%d: %s", __FILE__, __PRETTY_FUNCTION__, - qpim_mroute_socket_fd, vif_index, ifaddr_str, flags, + qpim_mroute_socket_fd, ifp->ifindex, ifaddr_str, flags, e, safe_strerror(e)); errno = e; return -2; diff --git a/pimd/pim_mroute.h b/pimd/pim_mroute.h index a32c792d78..c1ce012e2d 100644 --- a/pimd/pim_mroute.h +++ b/pimd/pim_mroute.h @@ -166,7 +166,7 @@ struct igmpmsg int pim_mroute_socket_enable(void); int pim_mroute_socket_disable(void); -int pim_mroute_add_vif(int vif_index, struct in_addr ifaddr, unsigned char flags); +int pim_mroute_add_vif(struct interface *ifp, struct in_addr ifaddr, unsigned char flags); int pim_mroute_del_vif(int vif_index); int pim_mroute_add(struct mfcctl *mc); diff --git a/pimd/pim_msg.c b/pimd/pim_msg.c index 8ead7ce643..aa0433a2e2 100644 --- a/pimd/pim_msg.c +++ b/pimd/pim_msg.c @@ -22,6 +22,8 @@ #include +#include "if.h" + #include "pimd.h" #include "pim_pim.h" #include "pim_msg.h" diff --git a/pimd/pim_neighbor.c b/pimd/pim_neighbor.c index 8932dc324c..cb41209238 100644 --- a/pimd/pim_neighbor.c +++ b/pimd/pim_neighbor.c @@ -25,6 +25,7 @@ #include "log.h" #include "prefix.h" #include "memory.h" +#include "if.h" #include "pimd.h" #include "pim_neighbor.h" diff --git a/pimd/pim_oil.c b/pimd/pim_oil.c index 7c03370fc4..5e7f1786d7 100644 --- a/pimd/pim_oil.c +++ b/pimd/pim_oil.c @@ -25,6 +25,7 @@ #include "log.h" #include "memory.h" #include "linklist.h" +#include "if.h" #include "pimd.h" #include "pim_oil.h" diff --git a/pimd/pim_pim.c b/pimd/pim_pim.c index 2ff062bd67..959663433d 100644 --- a/pimd/pim_pim.c +++ b/pimd/pim_pim.c @@ -25,6 +25,7 @@ #include "log.h" #include "thread.h" #include "memory.h" +#include "if.h" #include "pimd.h" #include "pim_pim.h" diff --git a/pimd/pim_routemap.c b/pimd/pim_routemap.c index 56868ae093..ced7c87484 100644 --- a/pimd/pim_routemap.c +++ b/pimd/pim_routemap.c @@ -21,6 +21,7 @@ */ #include +#include "if.h" #include "routemap.h" #include "pimd.h" diff --git a/pimd/pim_rp.c b/pimd/pim_rp.c index 747f3d48e4..26d108bcaa 100644 --- a/pimd/pim_rp.c +++ b/pimd/pim_rp.c @@ -22,6 +22,7 @@ #include "log.h" #include "network.h" +#include "if.h" #include "pimd.h" #include "pim_str.h" diff --git a/pimd/pim_rpf.c b/pimd/pim_rpf.c index 354fd664c0..11d8464486 100644 --- a/pimd/pim_rpf.c +++ b/pimd/pim_rpf.c @@ -22,6 +22,8 @@ #include +#include "if.h" + #include "log.h" #include "prefix.h" #include "memory.h" diff --git a/pimd/pim_static.c b/pimd/pim_static.c index 5114901dad..47a34daf48 100644 --- a/pimd/pim_static.c +++ b/pimd/pim_static.c @@ -23,6 +23,7 @@ #include #include "vty.h" +#include "if.h" #include "pim_static.h" #include "pim_time.h" diff --git a/pimd/pim_tlv.c b/pimd/pim_tlv.c index ed4dbba2e5..6e88990058 100644 --- a/pimd/pim_tlv.c +++ b/pimd/pim_tlv.c @@ -24,6 +24,7 @@ #include "log.h" #include "prefix.h" +#include "if.h" #include "pimd.h" #include "pim_int.h"