]>
Commit | Line | Data |
---|---|---|
7f57883e DS |
1 | /* |
2 | * EIGRP Filter Functions. | |
3 | * Copyright (C) 2013-2015 | |
4 | * Authors: | |
5 | * Donnie Savage | |
6 | * Jan Janovic | |
7 | * Matej Perina | |
8 | * Peter Orsag | |
9 | * Peter Paluch | |
10 | * Frantisek Gazo | |
11 | * Tomas Hvorkovy | |
12 | * Martin Kontsek | |
13 | * Lukas Koribsky | |
14 | * | |
15 | * | |
16 | * This file is part of GNU Zebra. | |
17 | * | |
18 | * GNU Zebra is free software; you can redistribute it and/or modify it | |
19 | * under the terms of the GNU General Public License as published by the | |
20 | * Free Software Foundation; either version 2, or (at your option) any | |
21 | * later version. | |
22 | * | |
23 | * GNU Zebra is distributed in the hope that it will be useful, but | |
24 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
25 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
26 | * General Public License for more details. | |
27 | * | |
896014f4 DL |
28 | * You should have received a copy of the GNU General Public License along |
29 | * with this program; see the file COPYING; if not, write to the Free Software | |
30 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
7f57883e DS |
31 | */ |
32 | ||
33 | #include <zebra.h> | |
34 | ||
35 | #include "if.h" | |
36 | #include "command.h" | |
37 | #include "prefix.h" | |
38 | #include "table.h" | |
39 | #include "thread.h" | |
40 | #include "memory.h" | |
41 | #include "log.h" | |
42 | #include "stream.h" | |
43 | #include "filter.h" | |
44 | #include "sockunion.h" | |
45 | #include "sockopt.h" | |
46 | #include "routemap.h" | |
47 | #include "if_rmap.h" | |
48 | #include "plist.h" | |
49 | #include "distribute.h" | |
50 | #include "md5.h" | |
51 | #include "keychain.h" | |
52 | #include "privs.h" | |
53 | #include "vrf.h" | |
54 | ||
55 | #include "eigrpd/eigrp_structs.h" | |
56 | #include "eigrpd/eigrpd.h" | |
57 | #include "eigrpd/eigrp_const.h" | |
58 | #include "eigrpd/eigrp_filter.h" | |
59 | #include "eigrpd/eigrp_packet.h" | |
60 | #include "eigrpd/eigrp_memory.h" | |
61 | ||
62 | /* | |
63 | * Distribute-list update functions. | |
64 | */ | |
d62a17ae | 65 | void eigrp_distribute_update(struct distribute *dist) |
7f57883e | 66 | { |
d62a17ae | 67 | struct interface *ifp; |
68 | struct eigrp_interface *ei = NULL; | |
69 | struct access_list *alist; | |
70 | struct prefix_list *plist; | |
71 | // struct route_map *routemap; | |
72 | struct eigrp *e; | |
73 | ||
74 | /* if no interface address is present, set list to eigrp process struct | |
75 | */ | |
76 | e = eigrp_lookup(); | |
939a62a5 | 77 | assert(e != NULL); |
d62a17ae | 78 | |
79 | /* Check if distribute-list was set for process or interface */ | |
80 | if (!dist->ifname) { | |
81 | /* access list IN for whole process */ | |
82 | if (dist->list[DISTRIBUTE_V4_IN]) { | |
83 | alist = access_list_lookup( | |
84 | AFI_IP, dist->list[DISTRIBUTE_V4_IN]); | |
85 | if (alist) | |
86 | e->list[EIGRP_FILTER_IN] = alist; | |
87 | else | |
88 | e->list[EIGRP_FILTER_IN] = NULL; | |
89 | } else { | |
90 | e->list[EIGRP_FILTER_IN] = NULL; | |
91 | } | |
92 | ||
93 | /* access list OUT for whole process */ | |
94 | if (dist->list[DISTRIBUTE_V4_OUT]) { | |
95 | alist = access_list_lookup( | |
96 | AFI_IP, dist->list[DISTRIBUTE_V4_OUT]); | |
97 | if (alist) | |
98 | e->list[EIGRP_FILTER_OUT] = alist; | |
99 | else | |
100 | e->list[EIGRP_FILTER_OUT] = NULL; | |
101 | } else { | |
102 | e->list[EIGRP_FILTER_OUT] = NULL; | |
103 | } | |
104 | ||
105 | /* PREFIX_LIST IN for process */ | |
106 | if (dist->prefix[DISTRIBUTE_V4_IN]) { | |
107 | plist = prefix_list_lookup( | |
108 | AFI_IP, dist->prefix[DISTRIBUTE_V4_IN]); | |
109 | if (plist) { | |
110 | e->prefix[EIGRP_FILTER_IN] = plist; | |
111 | } else | |
112 | e->prefix[EIGRP_FILTER_IN] = NULL; | |
113 | } else | |
114 | e->prefix[EIGRP_FILTER_IN] = NULL; | |
115 | ||
116 | /* PREFIX_LIST OUT for process */ | |
117 | if (dist->prefix[DISTRIBUTE_V4_OUT]) { | |
118 | plist = prefix_list_lookup( | |
119 | AFI_IP, dist->prefix[DISTRIBUTE_V4_OUT]); | |
120 | if (plist) { | |
121 | e->prefix[EIGRP_FILTER_OUT] = plist; | |
122 | ||
123 | } else | |
124 | e->prefix[EIGRP_FILTER_OUT] = NULL; | |
125 | } else | |
126 | e->prefix[EIGRP_FILTER_OUT] = NULL; | |
127 | ||
128 | // This is commented out, because the distribute.[ch] code | |
129 | // changes looked poorly written from first glance | |
130 | // commit was 133bdf2d | |
131 | // TODO: DBS | |
7f57883e | 132 | #if 0 |
f9e5c9ca DS |
133 | /* route-map IN for whole process */ |
134 | if (dist->route[DISTRIBUTE_V4_IN]) | |
135 | { | |
136 | routemap = route_map_lookup_by_name (dist->route[DISTRIBUTE_V4_IN]); | |
137 | if (routemap) | |
138 | e->routemap[EIGRP_FILTER_IN] = routemap; | |
139 | else | |
140 | e->routemap[EIGRP_FILTER_IN] = NULL; | |
141 | } | |
142 | else | |
143 | { | |
144 | e->routemap[EIGRP_FILTER_IN] = NULL; | |
145 | } | |
146 | ||
147 | /* route-map OUT for whole process */ | |
148 | if (dist->route[DISTRIBUTE_V4_OUT]) | |
149 | { | |
150 | routemap = route_map_lookup_by_name (dist->route[DISTRIBUTE_V4_OUT]); | |
151 | if (routemap) | |
152 | e->routemap[EIGRP_FILTER_OUT] = routemap; | |
153 | else | |
154 | e->routemap[EIGRP_FILTER_OUT] = NULL; | |
155 | } | |
156 | else | |
157 | { | |
158 | e->routemap[EIGRP_FILTER_OUT] = NULL; | |
159 | } | |
7f57883e | 160 | #endif |
d62a17ae | 161 | // TODO: check Graceful restart after 10sec |
162 | ||
163 | /* check if there is already GR scheduled */ | |
164 | if (e->t_distribute != NULL) { | |
165 | /* if is, cancel schedule */ | |
166 | thread_cancel(e->t_distribute); | |
167 | } | |
168 | /* schedule Graceful restart for whole process in 10sec */ | |
169 | e->t_distribute = NULL; | |
170 | thread_add_timer(master, eigrp_distribute_timer_process, e, | |
171 | (10), &e->t_distribute); | |
172 | ||
173 | return; | |
174 | } | |
175 | ||
176 | ifp = if_lookup_by_name(dist->ifname, VRF_DEFAULT); | |
177 | if (ifp == NULL) | |
178 | return; | |
179 | ||
180 | /*struct eigrp_if_info * info = ifp->info; | |
181 | ei = info->eigrp_interface;*/ | |
182 | struct listnode *node, *nnode; | |
183 | struct eigrp_interface *ei2; | |
184 | /* Find proper interface */ | |
185 | for (ALL_LIST_ELEMENTS(e->eiflist, node, nnode, ei2)) { | |
186 | if (strcmp(ei2->ifp->name, ifp->name) == 0) { | |
187 | ei = ei2; | |
188 | break; | |
189 | } | |
190 | } | |
85bbc95d | 191 | assert(ei != NULL); |
d62a17ae | 192 | |
193 | /* Access-list for interface in */ | |
194 | if (dist->list[DISTRIBUTE_V4_IN]) { | |
195 | alist = access_list_lookup(AFI_IP, | |
196 | dist->list[DISTRIBUTE_V4_IN]); | |
197 | if (alist) { | |
198 | ei->list[EIGRP_FILTER_IN] = alist; | |
199 | } else | |
200 | ei->list[EIGRP_FILTER_IN] = NULL; | |
201 | } else { | |
202 | ei->list[EIGRP_FILTER_IN] = NULL; | |
203 | } | |
204 | ||
205 | /* Access-list for interface in */ | |
206 | if (dist->list[DISTRIBUTE_V4_OUT]) { | |
207 | alist = access_list_lookup(AFI_IP, | |
208 | dist->list[DISTRIBUTE_V4_OUT]); | |
209 | if (alist) | |
210 | ei->list[EIGRP_FILTER_OUT] = alist; | |
211 | else | |
212 | ei->list[EIGRP_FILTER_OUT] = NULL; | |
213 | ||
214 | } else | |
215 | ei->list[EIGRP_FILTER_OUT] = NULL; | |
216 | ||
217 | /* Prefix-list for interface in */ | |
218 | if (dist->prefix[DISTRIBUTE_V4_IN]) { | |
219 | plist = prefix_list_lookup(AFI_IP, | |
220 | dist->prefix[DISTRIBUTE_V4_IN]); | |
221 | if (plist) | |
222 | ei->prefix[EIGRP_FILTER_IN] = plist; | |
223 | else | |
224 | ei->prefix[EIGRP_FILTER_IN] = NULL; | |
225 | } else | |
226 | ei->prefix[EIGRP_FILTER_IN] = NULL; | |
227 | ||
228 | /* Prefix-list for interface out */ | |
229 | if (dist->prefix[DISTRIBUTE_V4_OUT]) { | |
230 | plist = prefix_list_lookup(AFI_IP, | |
231 | dist->prefix[DISTRIBUTE_V4_OUT]); | |
232 | if (plist) | |
233 | ei->prefix[EIGRP_FILTER_OUT] = plist; | |
234 | else | |
235 | ei->prefix[EIGRP_FILTER_OUT] = NULL; | |
236 | } else | |
237 | ei->prefix[EIGRP_FILTER_OUT] = NULL; | |
7f57883e DS |
238 | |
239 | #if 0 | |
240 | /* route-map IN for whole process */ | |
241 | if (dist->route[DISTRIBUTE_V4_IN]) | |
f9e5c9ca DS |
242 | { |
243 | zlog_info("<DEBUG ACL ALL in"); | |
244 | routemap = route_map_lookup_by_name (dist->route[DISTRIBUTE_V4_IN]); | |
245 | if (routemap) | |
246 | ei->routemap[EIGRP_FILTER_IN] = routemap; | |
247 | else | |
248 | ei->routemap[EIGRP_FILTER_IN] = NULL; | |
249 | } | |
7f57883e | 250 | else |
f9e5c9ca DS |
251 | { |
252 | ei->routemap[EIGRP_FILTER_IN] = NULL; | |
253 | } | |
7f57883e DS |
254 | |
255 | /* route-map OUT for whole process */ | |
256 | if (dist->route[DISTRIBUTE_V4_OUT]) | |
f9e5c9ca DS |
257 | { |
258 | routemap = route_map_lookup_by_name (dist->route[DISTRIBUTE_V4_OUT]); | |
259 | if (routemap) | |
260 | ei->routemap[EIGRP_FILTER_OUT] = routemap; | |
261 | else | |
262 | ei->routemap[EIGRP_FILTER_OUT] = NULL; | |
263 | } | |
7f57883e | 264 | else |
f9e5c9ca DS |
265 | { |
266 | ei->routemap[EIGRP_FILTER_OUT] = NULL; | |
267 | } | |
7f57883e | 268 | #endif |
d62a17ae | 269 | // TODO: check Graceful restart after 10sec |
270 | ||
271 | /* check if there is already GR scheduled */ | |
272 | if (ei->t_distribute != NULL) { | |
273 | /* if is, cancel schedule */ | |
274 | thread_cancel(ei->t_distribute); | |
275 | } | |
276 | /* schedule Graceful restart for interface in 10sec */ | |
277 | e->t_distribute = NULL; | |
278 | thread_add_timer(master, eigrp_distribute_timer_interface, ei, 10, | |
279 | &e->t_distribute); | |
7f57883e DS |
280 | } |
281 | ||
282 | /* | |
283 | * Function called by prefix-list and access-list update | |
284 | */ | |
d62a17ae | 285 | void eigrp_distribute_update_interface(struct interface *ifp) |
7f57883e | 286 | { |
d62a17ae | 287 | struct distribute *dist; |
7f57883e | 288 | |
d62a17ae | 289 | dist = distribute_lookup(ifp->name); |
290 | if (dist) | |
291 | eigrp_distribute_update(dist); | |
7f57883e DS |
292 | } |
293 | ||
294 | /* Update all interface's distribute list. | |
295 | * Function used in hook for prefix-list | |
296 | */ | |
d62a17ae | 297 | void eigrp_distribute_update_all(struct prefix_list *notused) |
7f57883e | 298 | { |
f4e14fdb | 299 | struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); |
d62a17ae | 300 | struct interface *ifp; |
7f57883e | 301 | |
451fda4f | 302 | FOR_ALL_INTERFACES (vrf, ifp) |
d62a17ae | 303 | eigrp_distribute_update_interface(ifp); |
7f57883e DS |
304 | } |
305 | ||
306 | /* | |
307 | * Function used in hook for acces-list | |
308 | */ | |
d62a17ae | 309 | void eigrp_distribute_update_all_wrapper(struct access_list *notused) |
7f57883e | 310 | { |
d62a17ae | 311 | eigrp_distribute_update_all(NULL); |
7f57883e DS |
312 | } |
313 | ||
314 | /* | |
315 | * @fn eigrp_distribute_timer_process | |
316 | * | |
f9e5c9ca | 317 | * @param[in] thread current execution thread timer is associated with |
7f57883e | 318 | * |
f9e5c9ca | 319 | * @return int always returns 0 |
7f57883e DS |
320 | * |
321 | * @par | |
322 | * Called when 10sec waiting time expire and | |
323 | * executes Graceful restart for whole process | |
324 | */ | |
d62a17ae | 325 | int eigrp_distribute_timer_process(struct thread *thread) |
7f57883e | 326 | { |
d62a17ae | 327 | struct eigrp *eigrp; |
7f57883e | 328 | |
d62a17ae | 329 | eigrp = THREAD_ARG(thread); |
330 | eigrp->t_distribute = NULL; | |
7f57883e | 331 | |
d62a17ae | 332 | /* execute GR for whole process */ |
333 | eigrp_update_send_process_GR(eigrp, EIGRP_GR_FILTER, NULL); | |
7f57883e | 334 | |
d62a17ae | 335 | return 0; |
7f57883e DS |
336 | } |
337 | ||
338 | /* | |
339 | * @fn eigrp_distribute_timer_interface | |
340 | * | |
f9e5c9ca | 341 | * @param[in] thread current execution thread timer is associated with |
7f57883e | 342 | * |
f9e5c9ca | 343 | * @return int always returns 0 |
7f57883e DS |
344 | * |
345 | * @par | |
346 | * Called when 10sec waiting time expire and | |
347 | * executes Graceful restart for interface | |
348 | */ | |
d62a17ae | 349 | int eigrp_distribute_timer_interface(struct thread *thread) |
7f57883e | 350 | { |
d62a17ae | 351 | struct eigrp_interface *ei; |
7f57883e | 352 | |
d62a17ae | 353 | ei = THREAD_ARG(thread); |
354 | ei->t_distribute = NULL; | |
7f57883e | 355 | |
d62a17ae | 356 | /* execute GR for interface */ |
357 | eigrp_update_send_interface_GR(ei, EIGRP_GR_FILTER, NULL); | |
7f57883e | 358 | |
d62a17ae | 359 | return 0; |
7f57883e | 360 | } |