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