]>
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 | * | |
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 | ||
9e6fca3a | 21 | #include <zebra.h> |
22 | ||
15a5dafe | 23 | #include <lib/linklist.h> |
24 | #include <lib/prefix.h> | |
25 | #include <lib/vty.h> | |
26 | #include <lib/vrf.h> | |
27 | #include <lib/plist.h> | |
28 | ||
29 | #include "pimd.h" | |
30 | #include "pim_ssm.h" | |
31 | #include "pim_zebra.h" | |
32 | ||
ac4d0be5 | 33 | static void pim_ssm_range_reevaluate(void) |
15a5dafe | 34 | { |
ac4d0be5 | 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 | */ | |
51 | pim_upstream_register_reevaluate(); | |
52 | igmp_source_forward_reevaluate_all(); | |
15a5dafe | 53 | } |
54 | ||
ac4d0be5 | 55 | void pim_ssm_prefix_list_update(struct prefix_list *plist) |
15a5dafe | 56 | { |
ac4d0be5 | 57 | struct pim_ssm *ssm = pimg->ssm_info; |
15a5dafe | 58 | |
ac4d0be5 | 59 | if (!ssm->plist_name |
60 | || strcmp(ssm->plist_name, prefix_list_name(plist))) { | |
61 | /* not ours */ | |
62 | return; | |
63 | } | |
15a5dafe | 64 | |
ac4d0be5 | 65 | pim_ssm_range_reevaluate(); |
15a5dafe | 66 | } |
67 | ||
ac4d0be5 | 68 | static int pim_is_grp_standard_ssm(struct prefix *group) |
15a5dafe | 69 | { |
ac4d0be5 | 70 | static int first = 1; |
71 | static struct prefix group_ssm; | |
15a5dafe | 72 | |
ac4d0be5 | 73 | if (first) { |
74 | str2prefix(PIM_SSM_STANDARD_RANGE, &group_ssm); | |
75 | first = 0; | |
76 | } | |
15a5dafe | 77 | |
ac4d0be5 | 78 | return prefix_match(&group_ssm, group); |
15a5dafe | 79 | } |
80 | ||
ac4d0be5 | 81 | int pim_is_grp_ssm(struct in_addr group_addr) |
15a5dafe | 82 | { |
ac4d0be5 | 83 | struct pim_ssm *ssm; |
84 | struct prefix group; | |
85 | struct prefix_list *plist; | |
86 | ||
87 | memset(&group, 0, sizeof(group)); | |
88 | group.family = AF_INET; | |
89 | group.u.prefix4 = group_addr; | |
90 | group.prefixlen = 32; | |
91 | ||
92 | ssm = pimg->ssm_info; | |
93 | if (!ssm->plist_name) { | |
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); | |
15a5dafe | 102 | } |
103 | ||
ac4d0be5 | 104 | int pim_ssm_range_set(vrf_id_t vrf_id, const char *plist_name) |
15a5dafe | 105 | { |
ac4d0be5 | 106 | struct pim_ssm *ssm; |
107 | int change = 0; | |
108 | ||
109 | if (vrf_id != VRF_DEFAULT) | |
110 | return PIM_SSM_ERR_NO_VRF; | |
111 | ||
112 | ssm = pimg->ssm_info; | |
113 | if (plist_name) { | |
114 | if (ssm->plist_name) { | |
115 | if (!strcmp(ssm->plist_name, plist_name)) | |
116 | return PIM_SSM_ERR_DUP; | |
117 | XFREE(MTYPE_PIM_FILTER_NAME, ssm->plist_name); | |
118 | } | |
119 | ssm->plist_name = XSTRDUP(MTYPE_PIM_FILTER_NAME, plist_name); | |
120 | change = 1; | |
121 | } else { | |
122 | if (ssm->plist_name) { | |
123 | change = 1; | |
124 | XFREE(MTYPE_PIM_FILTER_NAME, ssm->plist_name); | |
125 | } | |
126 | } | |
127 | ||
128 | if (change) | |
129 | pim_ssm_range_reevaluate(); | |
130 | ||
131 | return PIM_SSM_ERR_NONE; | |
15a5dafe | 132 | } |
133 | ||
ac4d0be5 | 134 | void *pim_ssm_init(vrf_id_t vrf_id) |
15a5dafe | 135 | { |
ac4d0be5 | 136 | struct pim_ssm *ssm; |
15a5dafe | 137 | |
ac4d0be5 | 138 | ssm = XCALLOC(MTYPE_PIM_SSM_INFO, sizeof(*ssm)); |
139 | ssm->vrf_id = vrf_id; | |
15a5dafe | 140 | |
ac4d0be5 | 141 | return ssm; |
15a5dafe | 142 | } |
143 | ||
ac4d0be5 | 144 | void pim_ssm_terminate(struct pim_ssm *ssm) |
15a5dafe | 145 | { |
ac4d0be5 | 146 | if (ssm && ssm->plist_name) |
147 | XFREE(MTYPE_PIM_FILTER_NAME, ssm->plist_name); | |
15a5dafe | 148 | } |