From 54b97c74fe0ec25614ceb943013eb7500abefc6d Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Fri, 2 Oct 2015 09:30:02 -0700 Subject: [PATCH] pimd: Add RP check code Add the ability for the node to determine if it is the RP or not. Currently this only allows static RP's. Signed-off-by: Donald Sharp --- pimd/pim_rp.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ pimd/pim_rp.h | 2 ++ 2 files changed, 50 insertions(+) diff --git a/pimd/pim_rp.c b/pimd/pim_rp.c index 757c770c1d..506b60eabb 100644 --- a/pimd/pim_rp.c +++ b/pimd/pim_rp.c @@ -20,11 +20,59 @@ */ #include +#include "log.h" #include "network.h" #include "pimd.h" +#include "pim_str.h" #include "pim_rp.h" +static int i_am_rp = 0; + +/* + * Checks to see if we should elect ourself the actual RP + */ +void +pim_rp_check_rp (struct in_addr old, struct in_addr new) +{ + if (PIM_DEBUG_ZEBRA) { + char sold[100]; + char snew[100]; + char rp[100]; + pim_inet4_dump("", qpim_rp, rp, sizeof(rp)); + pim_inet4_dump("", old, sold, sizeof(sold)); + pim_inet4_dump("", new, snew, sizeof(snew)); + zlog_debug("%s: %s for old %s new %s", __func__, rp, sold, snew ); + } + + if (qpim_rp.s_addr == 0) + return; + + if (new.s_addr == qpim_rp.s_addr) + { + i_am_rp = 1; + return; + } + + if (old.s_addr == qpim_rp.s_addr) + { + i_am_rp = 0; + return; + } +} + +/* + * I_am_RP(G) is true if the group-to-RP mapping indicates that + * this router is the RP for the group. + * + * Since we only have static RP, all groups are part of this RP + */ +int +pim_rp_i_am_rp (struct in_addr group) +{ + return i_am_rp; +} + /* * Set the upstream IP address we want to talk to based upon * the rp configured and the source address diff --git a/pimd/pim_rp.h b/pimd/pim_rp.h index 114cc2cfd8..4639e7cebf 100644 --- a/pimd/pim_rp.h +++ b/pimd/pim_rp.h @@ -21,6 +21,8 @@ #ifndef PIM_RP_H #define PIM_RP_H +void pim_rp_check_rp (struct in_addr old, struct in_addr new); +int pim_rp_i_am_rp (struct in_addr group); int pim_rp_set_upstream_addr (struct in_addr *up, struct in_addr source); #endif -- 2.39.5