]> git.proxmox.com Git - mirror_frr.git/blob - eigrpd/eigrp_filter.c
Merge pull request #10590 from donaldsharp/bgp_error_codes
[mirror_frr.git] / eigrpd / eigrp_filter.c
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 *
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
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
61 /*
62 * Distribute-list update functions.
63 */
64 void eigrp_distribute_update(struct distribute_ctx *ctx,
65 struct distribute *dist)
66 {
67 struct eigrp *e = eigrp_lookup(ctx->vrf->vrf_id);
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;
73
74 /* if no interface address is present, set list to eigrp process struct
75 */
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
126 // TODO: check Graceful restart after 10sec
127
128 /* cancel GR scheduled */
129 thread_cancel(&(e->t_distribute));
130
131 /* schedule Graceful restart for whole process in 10sec */
132 thread_add_timer(master, eigrp_distribute_timer_process, e,
133 (10), &e->t_distribute);
134
135 return;
136 }
137
138 ifp = if_lookup_by_name(dist->ifname, e->vrf_id);
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 }
153 assert(ei != NULL);
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;
200
201 // TODO: check Graceful restart after 10sec
202
203 /* Cancel GR scheduled */
204 thread_cancel(&(ei->t_distribute));
205 /* schedule Graceful restart for interface in 10sec */
206 thread_add_timer(master, eigrp_distribute_timer_interface, ei, 10,
207 &ei->t_distribute);
208 }
209
210 /*
211 * Function called by prefix-list and access-list update
212 */
213 void eigrp_distribute_update_interface(struct interface *ifp)
214 {
215 struct distribute *dist;
216 struct eigrp *eigrp;
217
218 eigrp = eigrp_lookup(ifp->vrf->vrf_id);
219 if (!eigrp)
220 return;
221 dist = distribute_lookup(eigrp->distribute_ctx, ifp->name);
222 if (dist)
223 eigrp_distribute_update(eigrp->distribute_ctx,
224 dist);
225 }
226
227 /* Update all interface's distribute list.
228 * Function used in hook for prefix-list
229 */
230 void eigrp_distribute_update_all(struct prefix_list *notused)
231 {
232 struct vrf *vrf;
233 struct interface *ifp;
234
235 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
236 FOR_ALL_INTERFACES (vrf, ifp)
237 eigrp_distribute_update_interface(ifp);
238 }
239 }
240
241 /*
242 * Function used in hook for acces-list
243 */
244 void eigrp_distribute_update_all_wrapper(struct access_list *notused)
245 {
246 eigrp_distribute_update_all(NULL);
247 }
248
249 /*
250 * @fn eigrp_distribute_timer_process
251 *
252 * @param[in] thread current execution thread timer is associated with
253 *
254 * @return int always returns 0
255 *
256 * @par
257 * Called when 10sec waiting time expire and
258 * executes Graceful restart for whole process
259 */
260 int eigrp_distribute_timer_process(struct thread *thread)
261 {
262 struct eigrp *eigrp;
263
264 eigrp = THREAD_ARG(thread);
265
266 /* execute GR for whole process */
267 eigrp_update_send_process_GR(eigrp, EIGRP_GR_FILTER, NULL);
268
269 return 0;
270 }
271
272 /*
273 * @fn eigrp_distribute_timer_interface
274 *
275 * @param[in] thread current execution thread timer is associated with
276 *
277 * @return int always returns 0
278 *
279 * @par
280 * Called when 10sec waiting time expire and
281 * executes Graceful restart for interface
282 */
283 int eigrp_distribute_timer_interface(struct thread *thread)
284 {
285 struct eigrp_interface *ei;
286
287 ei = THREAD_ARG(thread);
288 ei->t_distribute = NULL;
289
290 /* execute GR for interface */
291 eigrp_update_send_interface_GR(ei, EIGRP_GR_FILTER, NULL);
292
293 return 0;
294 }