mirror of
				https://git.proxmox.com/git/mirror_frr
				synced 2025-11-04 03:29:06 +00:00 
			
		
		
		
	Signed-off-by: Daniel Walton <dwalton@cumulusnetworks.com> This allows "show ip mroute" and "show ip pim upstream" to display the groups in order.
		
			
				
	
	
		
			207 lines
		
	
	
		
			6.4 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			207 lines
		
	
	
		
			6.4 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
/*
 | 
						|
  PIM for Quagga
 | 
						|
  Copyright (C) 2008  Everton da Silva Marques
 | 
						|
 | 
						|
  This program is free software; you can redistribute it and/or modify
 | 
						|
  it under the terms of the GNU General Public License as published by
 | 
						|
  the Free Software Foundation; either version 2 of the License, or
 | 
						|
  (at your option) any later version.
 | 
						|
 | 
						|
  This program is distributed in the hope that it will be useful, but
 | 
						|
  WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
						|
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 | 
						|
  General Public License for more details.
 | 
						|
  
 | 
						|
  You should have received a copy of the GNU General Public License
 | 
						|
  along with this program; see the file COPYING; if not, write to the
 | 
						|
  Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
 | 
						|
  MA 02110-1301 USA
 | 
						|
  
 | 
						|
*/
 | 
						|
 | 
						|
#include <zebra.h>
 | 
						|
 | 
						|
#include "log.h"
 | 
						|
#include "memory.h"
 | 
						|
#include "if.h"
 | 
						|
#include "prefix.h"
 | 
						|
#include "vty.h"
 | 
						|
#include "plist.h"
 | 
						|
 | 
						|
#include "pimd.h"
 | 
						|
#include "pim_cmd.h"
 | 
						|
#include "pim_iface.h"
 | 
						|
#include "pim_zebra.h"
 | 
						|
#include "pim_str.h"
 | 
						|
#include "pim_oil.h"
 | 
						|
#include "pim_pim.h"
 | 
						|
#include "pim_upstream.h"
 | 
						|
#include "pim_rpf.h"
 | 
						|
#include "pim_ssmpingd.h"
 | 
						|
#include "pim_static.h"
 | 
						|
#include "pim_rp.h"
 | 
						|
 | 
						|
const char *const PIM_ALL_SYSTEMS      = MCAST_ALL_SYSTEMS;
 | 
						|
const char *const PIM_ALL_ROUTERS      = MCAST_ALL_ROUTERS;
 | 
						|
const char *const PIM_ALL_PIM_ROUTERS  = MCAST_ALL_PIM_ROUTERS;
 | 
						|
const char *const PIM_ALL_IGMP_ROUTERS = MCAST_ALL_IGMP_ROUTERS;
 | 
						|
 | 
						|
struct thread_master     *master = NULL;
 | 
						|
uint32_t                  qpim_debugs = 0;
 | 
						|
int                       qpim_mroute_socket_fd = -1;
 | 
						|
int64_t                   qpim_mroute_socket_creation = 0; /* timestamp of creation */
 | 
						|
struct thread            *qpim_mroute_socket_reader = NULL;
 | 
						|
int                       qpim_mroute_oif_highest_vif_index = -1;
 | 
						|
struct list              *qpim_channel_oil_list = NULL;
 | 
						|
int                       qpim_t_periodic = PIM_DEFAULT_T_PERIODIC; /* Period between Join/Prune Messages */
 | 
						|
struct list              *qpim_upstream_list = NULL;
 | 
						|
struct zclient           *qpim_zclient_update = NULL;
 | 
						|
struct pim_assert_metric  qpim_infinite_assert_metric;
 | 
						|
long                      qpim_rpf_cache_refresh_delay_msec = 2000;
 | 
						|
struct thread            *qpim_rpf_cache_refresher = NULL;
 | 
						|
int64_t                   qpim_rpf_cache_refresh_requests = 0;
 | 
						|
int64_t                   qpim_rpf_cache_refresh_events = 0;
 | 
						|
int64_t                   qpim_rpf_cache_refresh_last =  0;
 | 
						|
struct in_addr            qpim_inaddr_any;
 | 
						|
struct list              *qpim_ssmpingd_list = NULL;
 | 
						|
struct in_addr            qpim_ssmpingd_group_addr;
 | 
						|
int64_t                   qpim_scan_oil_events = 0;
 | 
						|
int64_t                   qpim_scan_oil_last = 0;
 | 
						|
int64_t                   qpim_mroute_add_events = 0;
 | 
						|
int64_t                   qpim_mroute_add_last = 0;
 | 
						|
int64_t                   qpim_mroute_del_events = 0;
 | 
						|
int64_t                   qpim_mroute_del_last = 0;
 | 
						|
struct list              *qpim_static_route_list = NULL;
 | 
						|
unsigned int              qpim_keep_alive_time = PIM_KEEPALIVE_PERIOD;
 | 
						|
signed int                qpim_rp_keep_alive_time = 0;
 | 
						|
int64_t                   qpim_nexthop_lookups = 0;
 | 
						|
 | 
						|
int32_t qpim_register_suppress_time = PIM_REGISTER_SUPPRESSION_TIME_DEFAULT;
 | 
						|
int32_t qpim_register_probe_time = PIM_REGISTER_PROBE_TIME_DEFAULT;
 | 
						|
 | 
						|
static void pim_free()
 | 
						|
{
 | 
						|
  pim_ssmpingd_destroy();
 | 
						|
 | 
						|
  if (qpim_channel_oil_list)
 | 
						|
    list_free(qpim_channel_oil_list);
 | 
						|
 | 
						|
  if (qpim_upstream_list)
 | 
						|
    list_free(qpim_upstream_list);
 | 
						|
 | 
						|
  if (qpim_static_route_list)
 | 
						|
     list_free(qpim_static_route_list);
 | 
						|
 | 
						|
  pim_route_map_terminate();
 | 
						|
 | 
						|
  pim_rp_free ();
 | 
						|
  pim_route_map_terminate();
 | 
						|
}
 | 
						|
 | 
						|
static int
 | 
						|
pim_channel_oil_compare (struct channel_oil *c1, struct channel_oil *c2)
 | 
						|
{
 | 
						|
   if (ntohl(c1->oil.mfcc_mcastgrp.s_addr) < ntohl(c2->oil.mfcc_mcastgrp.s_addr))
 | 
						|
     return -1;
 | 
						|
 | 
						|
   if (ntohl(c1->oil.mfcc_mcastgrp.s_addr) > ntohl(c2->oil.mfcc_mcastgrp.s_addr))
 | 
						|
     return 1;
 | 
						|
 | 
						|
   if (ntohl(c1->oil.mfcc_origin.s_addr) < ntohl(c2->oil.mfcc_origin.s_addr))
 | 
						|
     return -1;
 | 
						|
 | 
						|
   if (ntohl(c1->oil.mfcc_origin.s_addr) > ntohl(c2->oil.mfcc_origin.s_addr))
 | 
						|
     return 1;
 | 
						|
 | 
						|
   return 0;
 | 
						|
}
 | 
						|
 | 
						|
static int
 | 
						|
pim_upstream_compare (struct pim_upstream *up1, struct pim_upstream *up2)
 | 
						|
{
 | 
						|
   if (ntohl(up1->sg.grp.s_addr) < ntohl(up2->sg.grp.s_addr))
 | 
						|
     return -1;
 | 
						|
 | 
						|
   if (ntohl(up1->sg.grp.s_addr) > ntohl(up2->sg.grp.s_addr))
 | 
						|
     return 1;
 | 
						|
 | 
						|
   if (ntohl(up1->sg.src.s_addr) < ntohl(up2->sg.src.s_addr))
 | 
						|
     return -1;
 | 
						|
 | 
						|
   if (ntohl(up1->sg.src.s_addr) > ntohl(up2->sg.src.s_addr))
 | 
						|
     return 1;
 | 
						|
 | 
						|
   return 0;
 | 
						|
}
 | 
						|
 | 
						|
void pim_init()
 | 
						|
{
 | 
						|
  srandom(time(NULL));
 | 
						|
 | 
						|
  qpim_rp_keep_alive_time = PIM_RP_KEEPALIVE_PERIOD;
 | 
						|
 | 
						|
  pim_rp_init ();
 | 
						|
 | 
						|
  if (!inet_aton(PIM_ALL_PIM_ROUTERS, &qpim_all_pim_routers_addr)) {
 | 
						|
    zlog_err("%s %s: could not solve %s to group address: errno=%d: %s",
 | 
						|
	     __FILE__, __PRETTY_FUNCTION__,
 | 
						|
	     PIM_ALL_PIM_ROUTERS, errno, safe_strerror(errno));
 | 
						|
    zassert(0);
 | 
						|
    return;
 | 
						|
  }
 | 
						|
 | 
						|
  qpim_channel_oil_list = list_new();
 | 
						|
  if (!qpim_channel_oil_list) {
 | 
						|
    zlog_err("%s %s: failure: channel_oil_list=list_new()",
 | 
						|
	     __FILE__, __PRETTY_FUNCTION__);
 | 
						|
    return;
 | 
						|
  }
 | 
						|
  qpim_channel_oil_list->del = (void (*)(void *)) pim_channel_oil_free;
 | 
						|
  qpim_channel_oil_list->cmp = (int (*)(void *, void *)) pim_channel_oil_compare;
 | 
						|
 | 
						|
  qpim_upstream_list = list_new();
 | 
						|
  if (!qpim_upstream_list) {
 | 
						|
    zlog_err("%s %s: failure: upstream_list=list_new()",
 | 
						|
	     __FILE__, __PRETTY_FUNCTION__);
 | 
						|
    pim_free();
 | 
						|
    return;
 | 
						|
  }
 | 
						|
  qpim_upstream_list->del = (void (*)(void *)) pim_upstream_free;
 | 
						|
  qpim_upstream_list->cmp = (int (*)(void *, void *)) pim_upstream_compare;
 | 
						|
 | 
						|
  qpim_static_route_list = list_new();
 | 
						|
  if (!qpim_static_route_list) {
 | 
						|
    zlog_err("%s %s: failure: static_route_list=list_new()",
 | 
						|
        __FILE__, __PRETTY_FUNCTION__);
 | 
						|
    return;
 | 
						|
  }
 | 
						|
  qpim_static_route_list->del = (void (*)(void *)) pim_static_route_free;
 | 
						|
 | 
						|
  qpim_mroute_socket_fd = -1; /* mark mroute as disabled */
 | 
						|
  qpim_mroute_oif_highest_vif_index = -1;
 | 
						|
 | 
						|
  qpim_inaddr_any.s_addr = PIM_NET_INADDR_ANY;
 | 
						|
 | 
						|
  /*
 | 
						|
    RFC 4601: 4.6.3.  Assert Metrics
 | 
						|
 | 
						|
    assert_metric
 | 
						|
    infinite_assert_metric() {
 | 
						|
    return {1,infinity,infinity,0}
 | 
						|
    }
 | 
						|
  */
 | 
						|
  qpim_infinite_assert_metric.rpt_bit_flag      = 1;
 | 
						|
  qpim_infinite_assert_metric.metric_preference = PIM_ASSERT_METRIC_PREFERENCE_MAX;
 | 
						|
  qpim_infinite_assert_metric.route_metric      = PIM_ASSERT_ROUTE_METRIC_MAX;
 | 
						|
  qpim_infinite_assert_metric.ip_address        = qpim_inaddr_any;
 | 
						|
 | 
						|
  pim_if_init();
 | 
						|
  pim_cmd_init();
 | 
						|
  pim_ssmpingd_init();
 | 
						|
}
 | 
						|
 | 
						|
void pim_terminate()
 | 
						|
{
 | 
						|
  pim_free();
 | 
						|
}
 |