2 * EIGRP Filter Functions.
3 * Copyright (C) 2013-2015
16 * This file is part of GNU Zebra.
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
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.
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
44 #include "sockunion.h"
49 #include "distribute.h"
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"
63 * Distribute-list update functions.
65 void eigrp_distribute_update(struct distribute
*dist
)
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;
74 /* if no interface address is present, set list to eigrp process struct
78 /* Check if distribute-list was set for process or interface */
80 /* access list IN for whole process */
81 if (dist
->list
[DISTRIBUTE_V4_IN
]) {
82 alist
= access_list_lookup(
83 AFI_IP
, dist
->list
[DISTRIBUTE_V4_IN
]);
85 e
->list
[EIGRP_FILTER_IN
] = alist
;
87 e
->list
[EIGRP_FILTER_IN
] = NULL
;
89 e
->list
[EIGRP_FILTER_IN
] = NULL
;
92 /* access list OUT for whole process */
93 if (dist
->list
[DISTRIBUTE_V4_OUT
]) {
94 alist
= access_list_lookup(
95 AFI_IP
, dist
->list
[DISTRIBUTE_V4_OUT
]);
97 e
->list
[EIGRP_FILTER_OUT
] = alist
;
99 e
->list
[EIGRP_FILTER_OUT
] = NULL
;
101 e
->list
[EIGRP_FILTER_OUT
] = NULL
;
104 /* PREFIX_LIST IN for process */
105 if (dist
->prefix
[DISTRIBUTE_V4_IN
]) {
106 plist
= prefix_list_lookup(
107 AFI_IP
, dist
->prefix
[DISTRIBUTE_V4_IN
]);
109 e
->prefix
[EIGRP_FILTER_IN
] = plist
;
111 e
->prefix
[EIGRP_FILTER_IN
] = NULL
;
113 e
->prefix
[EIGRP_FILTER_IN
] = NULL
;
115 /* PREFIX_LIST OUT for process */
116 if (dist
->prefix
[DISTRIBUTE_V4_OUT
]) {
117 plist
= prefix_list_lookup(
118 AFI_IP
, dist
->prefix
[DISTRIBUTE_V4_OUT
]);
120 e
->prefix
[EIGRP_FILTER_OUT
] = plist
;
123 e
->prefix
[EIGRP_FILTER_OUT
] = NULL
;
125 e
->prefix
[EIGRP_FILTER_OUT
] = NULL
;
127 // This is commented out, because the distribute.[ch] code
128 // changes looked poorly written from first glance
129 // commit was 133bdf2d
132 /* route-map IN for whole process */
133 if (dist
->route
[DISTRIBUTE_V4_IN
])
135 routemap
= route_map_lookup_by_name (dist
->route
[DISTRIBUTE_V4_IN
]);
137 e
->routemap
[EIGRP_FILTER_IN
] = routemap
;
139 e
->routemap
[EIGRP_FILTER_IN
] = NULL
;
143 e
->routemap
[EIGRP_FILTER_IN
] = NULL
;
146 /* route-map OUT for whole process */
147 if (dist
->route
[DISTRIBUTE_V4_OUT
])
149 routemap
= route_map_lookup_by_name (dist
->route
[DISTRIBUTE_V4_OUT
]);
151 e
->routemap
[EIGRP_FILTER_OUT
] = routemap
;
153 e
->routemap
[EIGRP_FILTER_OUT
] = NULL
;
157 e
->routemap
[EIGRP_FILTER_OUT
] = NULL
;
160 // TODO: check Graceful restart after 10sec
162 /* check if there is already GR scheduled */
163 if (e
->t_distribute
!= NULL
) {
164 /* if is, cancel schedule */
165 thread_cancel(e
->t_distribute
);
167 /* schedule Graceful restart for whole process in 10sec */
168 e
->t_distribute
= NULL
;
169 thread_add_timer(master
, eigrp_distribute_timer_process
, e
,
170 (10), &e
->t_distribute
);
175 ifp
= if_lookup_by_name(dist
->ifname
, VRF_DEFAULT
);
179 /*struct eigrp_if_info * info = ifp->info;
180 ei = info->eigrp_interface;*/
181 struct listnode
*node
, *nnode
;
182 struct eigrp_interface
*ei2
;
183 /* Find proper interface */
184 for (ALL_LIST_ELEMENTS(e
->eiflist
, node
, nnode
, ei2
)) {
185 if (strcmp(ei2
->ifp
->name
, ifp
->name
) == 0) {
191 /* Access-list for interface in */
192 if (dist
->list
[DISTRIBUTE_V4_IN
]) {
193 alist
= access_list_lookup(AFI_IP
,
194 dist
->list
[DISTRIBUTE_V4_IN
]);
196 ei
->list
[EIGRP_FILTER_IN
] = alist
;
198 ei
->list
[EIGRP_FILTER_IN
] = NULL
;
200 ei
->list
[EIGRP_FILTER_IN
] = NULL
;
203 /* Access-list for interface in */
204 if (dist
->list
[DISTRIBUTE_V4_OUT
]) {
205 alist
= access_list_lookup(AFI_IP
,
206 dist
->list
[DISTRIBUTE_V4_OUT
]);
208 ei
->list
[EIGRP_FILTER_OUT
] = alist
;
210 ei
->list
[EIGRP_FILTER_OUT
] = NULL
;
213 ei
->list
[EIGRP_FILTER_OUT
] = NULL
;
215 /* Prefix-list for interface in */
216 if (dist
->prefix
[DISTRIBUTE_V4_IN
]) {
217 plist
= prefix_list_lookup(AFI_IP
,
218 dist
->prefix
[DISTRIBUTE_V4_IN
]);
220 ei
->prefix
[EIGRP_FILTER_IN
] = plist
;
222 ei
->prefix
[EIGRP_FILTER_IN
] = NULL
;
224 ei
->prefix
[EIGRP_FILTER_IN
] = NULL
;
226 /* Prefix-list for interface out */
227 if (dist
->prefix
[DISTRIBUTE_V4_OUT
]) {
228 plist
= prefix_list_lookup(AFI_IP
,
229 dist
->prefix
[DISTRIBUTE_V4_OUT
]);
231 ei
->prefix
[EIGRP_FILTER_OUT
] = plist
;
233 ei
->prefix
[EIGRP_FILTER_OUT
] = NULL
;
235 ei
->prefix
[EIGRP_FILTER_OUT
] = NULL
;
238 /* route-map IN for whole process */
239 if (dist
->route
[DISTRIBUTE_V4_IN
])
241 zlog_info("<DEBUG ACL ALL in");
242 routemap
= route_map_lookup_by_name (dist
->route
[DISTRIBUTE_V4_IN
]);
244 ei
->routemap
[EIGRP_FILTER_IN
] = routemap
;
246 ei
->routemap
[EIGRP_FILTER_IN
] = NULL
;
250 ei
->routemap
[EIGRP_FILTER_IN
] = NULL
;
253 /* route-map OUT for whole process */
254 if (dist
->route
[DISTRIBUTE_V4_OUT
])
256 routemap
= route_map_lookup_by_name (dist
->route
[DISTRIBUTE_V4_OUT
]);
258 ei
->routemap
[EIGRP_FILTER_OUT
] = routemap
;
260 ei
->routemap
[EIGRP_FILTER_OUT
] = NULL
;
264 ei
->routemap
[EIGRP_FILTER_OUT
] = NULL
;
267 // TODO: check Graceful restart after 10sec
269 /* check if there is already GR scheduled */
270 if (ei
->t_distribute
!= NULL
) {
271 /* if is, cancel schedule */
272 thread_cancel(ei
->t_distribute
);
274 /* schedule Graceful restart for interface in 10sec */
275 e
->t_distribute
= NULL
;
276 thread_add_timer(master
, eigrp_distribute_timer_interface
, ei
, 10,
281 * Function called by prefix-list and access-list update
283 void eigrp_distribute_update_interface(struct interface
*ifp
)
285 struct distribute
*dist
;
287 dist
= distribute_lookup(ifp
->name
);
289 eigrp_distribute_update(dist
);
292 /* Update all interface's distribute list.
293 * Function used in hook for prefix-list
295 void eigrp_distribute_update_all(struct prefix_list
*notused
)
297 struct interface
*ifp
;
298 struct listnode
*node
, *nnode
;
300 for (ALL_LIST_ELEMENTS(vrf_iflist(VRF_DEFAULT
), node
, nnode
, ifp
))
301 eigrp_distribute_update_interface(ifp
);
305 * Function used in hook for acces-list
307 void eigrp_distribute_update_all_wrapper(struct access_list
*notused
)
309 eigrp_distribute_update_all(NULL
);
313 * @fn eigrp_distribute_timer_process
315 * @param[in] thread current execution thread timer is associated with
317 * @return int always returns 0
320 * Called when 10sec waiting time expire and
321 * executes Graceful restart for whole process
323 int eigrp_distribute_timer_process(struct thread
*thread
)
327 eigrp
= THREAD_ARG(thread
);
328 eigrp
->t_distribute
= NULL
;
330 /* execute GR for whole process */
331 eigrp_update_send_process_GR(eigrp
, EIGRP_GR_FILTER
, NULL
);
337 * @fn eigrp_distribute_timer_interface
339 * @param[in] thread current execution thread timer is associated with
341 * @return int always returns 0
344 * Called when 10sec waiting time expire and
345 * executes Graceful restart for interface
347 int eigrp_distribute_timer_interface(struct thread
*thread
)
349 struct eigrp_interface
*ei
;
351 ei
= THREAD_ARG(thread
);
352 ei
->t_distribute
= NULL
;
354 /* execute GR for interface */
355 eigrp_update_send_interface_GR(ei
, EIGRP_GR_FILTER
, NULL
);