]> git.proxmox.com Git - mirror_frr.git/blob - pimd/pim_ssm.c
pimd: Allow SSM groups to co-exist with ASM groups.
[mirror_frr.git] / pimd / pim_ssm.c
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 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; see the file COPYING; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
18 * MA 02110-1301 USA
19 */
20
21 #include <lib/linklist.h>
22 #include <lib/prefix.h>
23 #include <lib/vty.h>
24 #include <lib/vrf.h>
25 #include <lib/plist.h>
26
27 #include "pimd.h"
28 #include "pim_ssm.h"
29 #include "pim_zebra.h"
30
31 static void
32 pim_ssm_range_reevaluate (void)
33 {
34 /* 1. Setup register state for (S,G) entries if G has changed from SSM to
35 * ASM.
36 * 2. check existing (*,G) IGMP registrations to see if they are
37 * still ASM. if they are now SSM delete them.
38 * 3. Allow channel setup for IGMP (*,G) members if G is now ASM
39 * 4. I could tear down all (*,G), (S,G,rpt) states. But that is an
40 * unnecessary sladge hammer and may not be particularly useful as it is
41 * likely the SPT switchover has already happened for flows along such RPTs.
42 * As for the RPT states it seems that the best thing to do is let them age
43 * out gracefully. As long as the FHR and LHR do the right thing RPTs will
44 * disappear in time for SSM groups.
45 */
46 pim_upstream_register_reevaluate ();
47 igmp_source_forward_reevaluate_all ();
48 }
49
50 void
51 pim_ssm_prefix_list_update (struct prefix_list *plist)
52 {
53 struct pim_ssm *ssm = pimg->ssm_info;
54
55 if (!ssm->plist_name || strcmp (ssm->plist_name, prefix_list_name (plist)))
56 {
57 /* not ours */
58 return;
59 }
60
61 pim_ssm_range_reevaluate ();
62 }
63
64 static int
65 pim_is_grp_standard_ssm (struct prefix *group)
66 {
67 static int first = 1;
68 static struct prefix group_ssm;
69
70 if (first)
71 {
72 str2prefix (PIM_SSM_STANDARD_RANGE, &group_ssm);
73 first = 0;
74 }
75
76 return prefix_match (&group_ssm, group);
77 }
78
79 int
80 pim_is_grp_ssm (struct in_addr group_addr)
81 {
82 struct pim_ssm *ssm;
83 struct prefix group;
84 struct prefix_list *plist;
85
86 memset (&group, 0, sizeof (group));
87 group.family = AF_INET;
88 group.u.prefix4 = group_addr;
89 group.prefixlen = 32;
90
91 ssm = pimg->ssm_info;
92 if (!ssm->plist_name)
93 {
94 return pim_is_grp_standard_ssm (&group);
95 }
96
97 plist = prefix_list_lookup (AFI_IP, ssm->plist_name);
98 if (!plist)
99 return 0;
100
101 return (prefix_list_apply (plist, &group) == PREFIX_PERMIT);
102 }
103
104 int
105 pim_ssm_range_set (vrf_id_t vrf_id, const char *plist_name)
106 {
107 struct pim_ssm *ssm;
108 int change = 0;
109
110 if (vrf_id != VRF_DEFAULT)
111 return PIM_SSM_ERR_NO_VRF;
112
113 ssm = pimg->ssm_info;
114 if (plist_name)
115 {
116 if (ssm->plist_name)
117 {
118 if (!strcmp (ssm->plist_name, plist_name))
119 return PIM_SSM_ERR_DUP;
120 XFREE (MTYPE_PIM_FILTER_NAME, ssm->plist_name);
121 }
122 ssm->plist_name = XSTRDUP (MTYPE_PIM_FILTER_NAME, plist_name);
123 change = 1;
124 }
125 else
126 {
127 if (ssm->plist_name)
128 {
129 change = 1;
130 XFREE (MTYPE_PIM_FILTER_NAME, ssm->plist_name);
131 }
132 }
133
134 if (change)
135 pim_ssm_range_reevaluate ();
136
137 return PIM_SSM_ERR_NONE;
138 }
139
140 void *
141 pim_ssm_init (vrf_id_t vrf_id)
142 {
143 struct pim_ssm *ssm;
144
145 ssm = XCALLOC (MTYPE_PIM_SSM_INFO, sizeof (*ssm));
146 ssm->vrf_id = vrf_id;
147
148 return ssm;
149 }
150
151 void
152 pim_ssm_terminate (struct pim_ssm *ssm)
153 {
154 if (ssm && ssm->plist_name)
155 XFREE (MTYPE_PIM_FILTER_NAME, ssm->plist_name);
156 }