]> git.proxmox.com Git - mirror_frr.git/blame - pimd/pim_ssm.c
Merge pull request #10770 from chiragshah6/evpn_dev3
[mirror_frr.git] / pimd / pim_ssm.c
CommitLineData
15a5dafe 1/*
2 * IP SSM ranges for FRR
3 * Copyright (C) 2017 Cumulus Networks, Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
896014f4
DL
15 * You should have received a copy of the GNU General Public License along
16 * with this program; see the file COPYING; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15a5dafe 18 */
19
9e6fca3a 20#include <zebra.h>
21
15a5dafe 22#include <lib/linklist.h>
23#include <lib/prefix.h>
24#include <lib/vty.h>
25#include <lib/vrf.h>
26#include <lib/plist.h>
d9ff4302 27#include <lib/lib_errors.h>
15a5dafe 28
29#include "pimd.h"
30#include "pim_ssm.h"
cd6d2858 31#include "pim_igmp.h"
15a5dafe 32
6f439a70 33static void pim_ssm_range_reevaluate(struct pim_instance *pim)
15a5dafe 34{
94120cb2 35#if PIM_IPV == 4
d62a17ae 36 /* 1. Setup register state for (S,G) entries if G has changed from SSM
37 * to
38 * ASM.
39 * 2. check existing (*,G) IGMP registrations to see if they are
40 * still ASM. if they are now SSM delete them.
41 * 3. Allow channel setup for IGMP (*,G) members if G is now ASM
42 * 4. I could tear down all (*,G), (S,G,rpt) states. But that is an
43 * unnecessary sladge hammer and may not be particularly useful as it is
44 * likely the SPT switchover has already happened for flows along such
45 * RPTs.
46 * As for the RPT states it seems that the best thing to do is let them
47 * age
48 * out gracefully. As long as the FHR and LHR do the right thing RPTs
49 * will
50 * disappear in time for SSM groups.
51 */
6f439a70 52 pim_upstream_register_reevaluate(pim);
5d59e408 53 igmp_source_forward_reevaluate_all(pim);
94120cb2 54#endif
15a5dafe 55}
56
6f439a70
DS
57void pim_ssm_prefix_list_update(struct pim_instance *pim,
58 struct prefix_list *plist)
15a5dafe 59{
6f439a70 60 struct pim_ssm *ssm = pim->ssm_info;
15a5dafe 61
d62a17ae 62 if (!ssm->plist_name
63 || strcmp(ssm->plist_name, prefix_list_name(plist))) {
64 /* not ours */
65 return;
66 }
15a5dafe 67
6f439a70 68 pim_ssm_range_reevaluate(pim);
15a5dafe 69}
70
d62a17ae 71static int pim_is_grp_standard_ssm(struct prefix *group)
15a5dafe 72{
d62a17ae 73 static int first = 1;
74 static struct prefix group_ssm;
15a5dafe 75
d62a17ae 76 if (first) {
e691f179 77 if (!str2prefix(PIM_SSM_STANDARD_RANGE, &group_ssm))
450971aa 78 flog_err(EC_LIB_DEVELOPMENT,
1c50c1c0 79 "%s: Failure to Read Group Address: %s",
15569c58 80 __func__, PIM_SSM_STANDARD_RANGE);
e691f179 81
d62a17ae 82 first = 0;
83 }
15a5dafe 84
d62a17ae 85 return prefix_match(&group_ssm, group);
15a5dafe 86}
87
80d9fa1e 88int pim_is_grp_ssm(struct pim_instance *pim, pim_addr group_addr)
15a5dafe 89{
d62a17ae 90 struct pim_ssm *ssm;
91 struct prefix group;
92 struct prefix_list *plist;
93
80d9fa1e 94 pim_addr_to_prefix(&group, group_addr);
d62a17ae 95
6f439a70 96 ssm = pim->ssm_info;
d62a17ae 97 if (!ssm->plist_name) {
98 return pim_is_grp_standard_ssm(&group);
99 }
100
80d9fa1e 101 plist = prefix_list_lookup(PIM_AFI, ssm->plist_name);
d62a17ae 102 if (!plist)
103 return 0;
104
105 return (prefix_list_apply(plist, &group) == PREFIX_PERMIT);
15a5dafe 106}
107
6f439a70
DS
108int pim_ssm_range_set(struct pim_instance *pim, vrf_id_t vrf_id,
109 const char *plist_name)
15a5dafe 110{
d62a17ae 111 struct pim_ssm *ssm;
112 int change = 0;
113
d3cc1e45 114 if (vrf_id != pim->vrf->vrf_id)
d62a17ae 115 return PIM_SSM_ERR_NO_VRF;
116
6f439a70 117 ssm = pim->ssm_info;
d62a17ae 118 if (plist_name) {
119 if (ssm->plist_name) {
120 if (!strcmp(ssm->plist_name, plist_name))
121 return PIM_SSM_ERR_DUP;
122 XFREE(MTYPE_PIM_FILTER_NAME, ssm->plist_name);
123 }
124 ssm->plist_name = XSTRDUP(MTYPE_PIM_FILTER_NAME, plist_name);
125 change = 1;
126 } else {
127 if (ssm->plist_name) {
128 change = 1;
129 XFREE(MTYPE_PIM_FILTER_NAME, ssm->plist_name);
130 }
131 }
132
133 if (change)
6f439a70 134 pim_ssm_range_reevaluate(pim);
d62a17ae 135
136 return PIM_SSM_ERR_NONE;
15a5dafe 137}
138
e07fe9e6 139void *pim_ssm_init(void)
15a5dafe 140{
d62a17ae 141 struct pim_ssm *ssm;
15a5dafe 142
d62a17ae 143 ssm = XCALLOC(MTYPE_PIM_SSM_INFO, sizeof(*ssm));
15a5dafe 144
d62a17ae 145 return ssm;
15a5dafe 146}
147
d62a17ae 148void pim_ssm_terminate(struct pim_ssm *ssm)
15a5dafe 149{
27cfe222
DS
150 if (!ssm)
151 return;
152
0a22ddfb 153 XFREE(MTYPE_PIM_FILTER_NAME, ssm->plist_name);
27cfe222
DS
154
155 XFREE(MTYPE_PIM_SSM_INFO, ssm);
15a5dafe 156}