]>
Commit | Line | Data |
---|---|---|
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> | |
27 | ||
28 | #include "pimd.h" | |
29 | #include "pim_ssm.h" | |
30 | #include "pim_zebra.h" | |
31 | ||
d62a17ae | 32 | static void pim_ssm_range_reevaluate(void) |
15a5dafe | 33 | { |
d62a17ae | 34 | /* 1. Setup register state for (S,G) entries if G has changed from SSM |
35 | * to | |
36 | * ASM. | |
37 | * 2. check existing (*,G) IGMP registrations to see if they are | |
38 | * still ASM. if they are now SSM delete them. | |
39 | * 3. Allow channel setup for IGMP (*,G) members if G is now ASM | |
40 | * 4. I could tear down all (*,G), (S,G,rpt) states. But that is an | |
41 | * unnecessary sladge hammer and may not be particularly useful as it is | |
42 | * likely the SPT switchover has already happened for flows along such | |
43 | * RPTs. | |
44 | * As for the RPT states it seems that the best thing to do is let them | |
45 | * age | |
46 | * out gracefully. As long as the FHR and LHR do the right thing RPTs | |
47 | * will | |
48 | * disappear in time for SSM groups. | |
49 | */ | |
50 | pim_upstream_register_reevaluate(); | |
51 | igmp_source_forward_reevaluate_all(); | |
15a5dafe | 52 | } |
53 | ||
d62a17ae | 54 | void pim_ssm_prefix_list_update(struct prefix_list *plist) |
15a5dafe | 55 | { |
d62a17ae | 56 | struct pim_ssm *ssm = pimg->ssm_info; |
15a5dafe | 57 | |
d62a17ae | 58 | if (!ssm->plist_name |
59 | || strcmp(ssm->plist_name, prefix_list_name(plist))) { | |
60 | /* not ours */ | |
61 | return; | |
62 | } | |
15a5dafe | 63 | |
d62a17ae | 64 | pim_ssm_range_reevaluate(); |
15a5dafe | 65 | } |
66 | ||
d62a17ae | 67 | static int pim_is_grp_standard_ssm(struct prefix *group) |
15a5dafe | 68 | { |
d62a17ae | 69 | static int first = 1; |
70 | static struct prefix group_ssm; | |
15a5dafe | 71 | |
d62a17ae | 72 | if (first) { |
73 | str2prefix(PIM_SSM_STANDARD_RANGE, &group_ssm); | |
74 | first = 0; | |
75 | } | |
15a5dafe | 76 | |
d62a17ae | 77 | return prefix_match(&group_ssm, group); |
15a5dafe | 78 | } |
79 | ||
d62a17ae | 80 | int pim_is_grp_ssm(struct in_addr group_addr) |
15a5dafe | 81 | { |
d62a17ae | 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 | return pim_is_grp_standard_ssm(&group); | |
94 | } | |
95 | ||
96 | plist = prefix_list_lookup(AFI_IP, ssm->plist_name); | |
97 | if (!plist) | |
98 | return 0; | |
99 | ||
100 | return (prefix_list_apply(plist, &group) == PREFIX_PERMIT); | |
15a5dafe | 101 | } |
102 | ||
d62a17ae | 103 | int pim_ssm_range_set(vrf_id_t vrf_id, const char *plist_name) |
15a5dafe | 104 | { |
d62a17ae | 105 | struct pim_ssm *ssm; |
106 | int change = 0; | |
107 | ||
108 | if (vrf_id != VRF_DEFAULT) | |
109 | return PIM_SSM_ERR_NO_VRF; | |
110 | ||
111 | ssm = pimg->ssm_info; | |
112 | if (plist_name) { | |
113 | if (ssm->plist_name) { | |
114 | if (!strcmp(ssm->plist_name, plist_name)) | |
115 | return PIM_SSM_ERR_DUP; | |
116 | XFREE(MTYPE_PIM_FILTER_NAME, ssm->plist_name); | |
117 | } | |
118 | ssm->plist_name = XSTRDUP(MTYPE_PIM_FILTER_NAME, plist_name); | |
119 | change = 1; | |
120 | } else { | |
121 | if (ssm->plist_name) { | |
122 | change = 1; | |
123 | XFREE(MTYPE_PIM_FILTER_NAME, ssm->plist_name); | |
124 | } | |
125 | } | |
126 | ||
127 | if (change) | |
128 | pim_ssm_range_reevaluate(); | |
129 | ||
130 | return PIM_SSM_ERR_NONE; | |
15a5dafe | 131 | } |
132 | ||
d62a17ae | 133 | void *pim_ssm_init(vrf_id_t vrf_id) |
15a5dafe | 134 | { |
d62a17ae | 135 | struct pim_ssm *ssm; |
15a5dafe | 136 | |
d62a17ae | 137 | ssm = XCALLOC(MTYPE_PIM_SSM_INFO, sizeof(*ssm)); |
138 | ssm->vrf_id = vrf_id; | |
15a5dafe | 139 | |
d62a17ae | 140 | return ssm; |
15a5dafe | 141 | } |
142 | ||
d62a17ae | 143 | void pim_ssm_terminate(struct pim_ssm *ssm) |
15a5dafe | 144 | { |
d62a17ae | 145 | if (ssm && ssm->plist_name) |
146 | XFREE(MTYPE_PIM_FILTER_NAME, ssm->plist_name); | |
15a5dafe | 147 | } |