]>
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" | |
7f57883e DS |
60 | |
61 | /* | |
62 | * Distribute-list update functions. | |
63 | */ | |
03a38493 PG |
64 | void eigrp_distribute_update(struct distribute_ctx *ctx, |
65 | struct distribute *dist) | |
7f57883e | 66 | { |
4cfff48a | 67 | struct eigrp *e = eigrp_lookup(ctx->vrf->vrf_id); |
d62a17ae | 68 | struct interface *ifp; |
69 | struct eigrp_interface *ei = NULL; | |
70 | struct access_list *alist; | |
71 | struct prefix_list *plist; | |
72 | // struct route_map *routemap; | |
d62a17ae | 73 | |
74 | /* if no interface address is present, set list to eigrp process struct | |
75 | */ | |
d62a17ae | 76 | |
77 | /* Check if distribute-list was set for process or interface */ | |
78 | if (!dist->ifname) { | |
79 | /* access list IN for whole process */ | |
80 | if (dist->list[DISTRIBUTE_V4_IN]) { | |
81 | alist = access_list_lookup( | |
82 | AFI_IP, dist->list[DISTRIBUTE_V4_IN]); | |
83 | if (alist) | |
84 | e->list[EIGRP_FILTER_IN] = alist; | |
85 | else | |
86 | e->list[EIGRP_FILTER_IN] = NULL; | |
87 | } else { | |
88 | e->list[EIGRP_FILTER_IN] = NULL; | |
89 | } | |
90 | ||
91 | /* access list OUT for whole process */ | |
92 | if (dist->list[DISTRIBUTE_V4_OUT]) { | |
93 | alist = access_list_lookup( | |
94 | AFI_IP, dist->list[DISTRIBUTE_V4_OUT]); | |
95 | if (alist) | |
96 | e->list[EIGRP_FILTER_OUT] = alist; | |
97 | else | |
98 | e->list[EIGRP_FILTER_OUT] = NULL; | |
99 | } else { | |
100 | e->list[EIGRP_FILTER_OUT] = NULL; | |
101 | } | |
102 | ||
103 | /* PREFIX_LIST IN for process */ | |
104 | if (dist->prefix[DISTRIBUTE_V4_IN]) { | |
105 | plist = prefix_list_lookup( | |
106 | AFI_IP, dist->prefix[DISTRIBUTE_V4_IN]); | |
107 | if (plist) { | |
108 | e->prefix[EIGRP_FILTER_IN] = plist; | |
109 | } else | |
110 | e->prefix[EIGRP_FILTER_IN] = NULL; | |
111 | } else | |
112 | e->prefix[EIGRP_FILTER_IN] = NULL; | |
113 | ||
114 | /* PREFIX_LIST OUT for process */ | |
115 | if (dist->prefix[DISTRIBUTE_V4_OUT]) { | |
116 | plist = prefix_list_lookup( | |
117 | AFI_IP, dist->prefix[DISTRIBUTE_V4_OUT]); | |
118 | if (plist) { | |
119 | e->prefix[EIGRP_FILTER_OUT] = plist; | |
120 | ||
121 | } else | |
122 | e->prefix[EIGRP_FILTER_OUT] = NULL; | |
123 | } else | |
124 | e->prefix[EIGRP_FILTER_OUT] = NULL; | |
125 | ||
d62a17ae | 126 | // TODO: check Graceful restart after 10sec |
127 | ||
50478845 MS |
128 | /* cancel GR scheduled */ |
129 | thread_cancel(&(e->t_distribute)); | |
b3d6bc6e | 130 | |
d62a17ae | 131 | /* schedule Graceful restart for whole process in 10sec */ |
d62a17ae | 132 | thread_add_timer(master, eigrp_distribute_timer_process, e, |
133 | (10), &e->t_distribute); | |
134 | ||
135 | return; | |
136 | } | |
137 | ||
daa64bdf | 138 | ifp = if_lookup_by_name(dist->ifname, e->vrf_id); |
d62a17ae | 139 | if (ifp == NULL) |
140 | return; | |
141 | ||
142 | /*struct eigrp_if_info * info = ifp->info; | |
143 | ei = info->eigrp_interface;*/ | |
144 | struct listnode *node, *nnode; | |
145 | struct eigrp_interface *ei2; | |
146 | /* Find proper interface */ | |
147 | for (ALL_LIST_ELEMENTS(e->eiflist, node, nnode, ei2)) { | |
148 | if (strcmp(ei2->ifp->name, ifp->name) == 0) { | |
149 | ei = ei2; | |
150 | break; | |
151 | } | |
152 | } | |
85bbc95d | 153 | assert(ei != NULL); |
d62a17ae | 154 | |
155 | /* Access-list for interface in */ | |
156 | if (dist->list[DISTRIBUTE_V4_IN]) { | |
157 | alist = access_list_lookup(AFI_IP, | |
158 | dist->list[DISTRIBUTE_V4_IN]); | |
159 | if (alist) { | |
160 | ei->list[EIGRP_FILTER_IN] = alist; | |
161 | } else | |
162 | ei->list[EIGRP_FILTER_IN] = NULL; | |
163 | } else { | |
164 | ei->list[EIGRP_FILTER_IN] = NULL; | |
165 | } | |
166 | ||
167 | /* Access-list for interface in */ | |
168 | if (dist->list[DISTRIBUTE_V4_OUT]) { | |
169 | alist = access_list_lookup(AFI_IP, | |
170 | dist->list[DISTRIBUTE_V4_OUT]); | |
171 | if (alist) | |
172 | ei->list[EIGRP_FILTER_OUT] = alist; | |
173 | else | |
174 | ei->list[EIGRP_FILTER_OUT] = NULL; | |
175 | ||
176 | } else | |
177 | ei->list[EIGRP_FILTER_OUT] = NULL; | |
178 | ||
179 | /* Prefix-list for interface in */ | |
180 | if (dist->prefix[DISTRIBUTE_V4_IN]) { | |
181 | plist = prefix_list_lookup(AFI_IP, | |
182 | dist->prefix[DISTRIBUTE_V4_IN]); | |
183 | if (plist) | |
184 | ei->prefix[EIGRP_FILTER_IN] = plist; | |
185 | else | |
186 | ei->prefix[EIGRP_FILTER_IN] = NULL; | |
187 | } else | |
188 | ei->prefix[EIGRP_FILTER_IN] = NULL; | |
189 | ||
190 | /* Prefix-list for interface out */ | |
191 | if (dist->prefix[DISTRIBUTE_V4_OUT]) { | |
192 | plist = prefix_list_lookup(AFI_IP, | |
193 | dist->prefix[DISTRIBUTE_V4_OUT]); | |
194 | if (plist) | |
195 | ei->prefix[EIGRP_FILTER_OUT] = plist; | |
196 | else | |
197 | ei->prefix[EIGRP_FILTER_OUT] = NULL; | |
198 | } else | |
199 | ei->prefix[EIGRP_FILTER_OUT] = NULL; | |
7f57883e | 200 | |
d62a17ae | 201 | // TODO: check Graceful restart after 10sec |
202 | ||
50478845 | 203 | /* Cancel GR scheduled */ |
b3d6bc6e | 204 | thread_cancel(&(ei->t_distribute)); |
d62a17ae | 205 | /* schedule Graceful restart for interface in 10sec */ |
d62a17ae | 206 | thread_add_timer(master, eigrp_distribute_timer_interface, ei, 10, |
eb946ef5 | 207 | &ei->t_distribute); |
7f57883e DS |
208 | } |
209 | ||
210 | /* | |
211 | * Function called by prefix-list and access-list update | |
212 | */ | |
d62a17ae | 213 | void eigrp_distribute_update_interface(struct interface *ifp) |
7f57883e | 214 | { |
d62a17ae | 215 | struct distribute *dist; |
03a38493 | 216 | struct eigrp *eigrp; |
7f57883e | 217 | |
096f7609 | 218 | eigrp = eigrp_lookup(ifp->vrf->vrf_id); |
03a38493 PG |
219 | if (!eigrp) |
220 | return; | |
221 | dist = distribute_lookup(eigrp->distribute_ctx, ifp->name); | |
d62a17ae | 222 | if (dist) |
03a38493 PG |
223 | eigrp_distribute_update(eigrp->distribute_ctx, |
224 | dist); | |
7f57883e DS |
225 | } |
226 | ||
227 | /* Update all interface's distribute list. | |
228 | * Function used in hook for prefix-list | |
229 | */ | |
d62a17ae | 230 | void eigrp_distribute_update_all(struct prefix_list *notused) |
7f57883e | 231 | { |
4cfff48a | 232 | struct vrf *vrf; |
d62a17ae | 233 | struct interface *ifp; |
7f57883e | 234 | |
4cfff48a DS |
235 | RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { |
236 | FOR_ALL_INTERFACES (vrf, ifp) | |
237 | eigrp_distribute_update_interface(ifp); | |
238 | } | |
7f57883e DS |
239 | } |
240 | ||
241 | /* | |
242 | * Function used in hook for acces-list | |
243 | */ | |
d62a17ae | 244 | void eigrp_distribute_update_all_wrapper(struct access_list *notused) |
7f57883e | 245 | { |
d62a17ae | 246 | eigrp_distribute_update_all(NULL); |
7f57883e DS |
247 | } |
248 | ||
249 | /* | |
250 | * @fn eigrp_distribute_timer_process | |
251 | * | |
f9e5c9ca | 252 | * @param[in] thread current execution thread timer is associated with |
7f57883e | 253 | * |
cc9f21da | 254 | * @return void |
7f57883e DS |
255 | * |
256 | * @par | |
257 | * Called when 10sec waiting time expire and | |
258 | * executes Graceful restart for whole process | |
259 | */ | |
cc9f21da | 260 | void eigrp_distribute_timer_process(struct thread *thread) |
7f57883e | 261 | { |
d62a17ae | 262 | struct eigrp *eigrp; |
7f57883e | 263 | |
d62a17ae | 264 | eigrp = THREAD_ARG(thread); |
7f57883e | 265 | |
d62a17ae | 266 | /* execute GR for whole process */ |
267 | eigrp_update_send_process_GR(eigrp, EIGRP_GR_FILTER, NULL); | |
7f57883e DS |
268 | } |
269 | ||
270 | /* | |
271 | * @fn eigrp_distribute_timer_interface | |
272 | * | |
f9e5c9ca | 273 | * @param[in] thread current execution thread timer is associated with |
7f57883e | 274 | * |
cc9f21da | 275 | * @return void |
7f57883e DS |
276 | * |
277 | * @par | |
278 | * Called when 10sec waiting time expire and | |
279 | * executes Graceful restart for interface | |
280 | */ | |
cc9f21da | 281 | void eigrp_distribute_timer_interface(struct thread *thread) |
7f57883e | 282 | { |
d62a17ae | 283 | struct eigrp_interface *ei; |
7f57883e | 284 | |
d62a17ae | 285 | ei = THREAD_ARG(thread); |
286 | ei->t_distribute = NULL; | |
7f57883e | 287 | |
d62a17ae | 288 | /* execute GR for interface */ |
289 | eigrp_update_send_interface_GR(ei, EIGRP_GR_FILTER, NULL); | |
7f57883e | 290 | } |