1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * EIGRP Filter Functions.
4 * Copyright (C) 2013-2015
29 #include "sockunion.h"
34 #include "distribute.h"
40 #include "eigrpd/eigrp_structs.h"
41 #include "eigrpd/eigrpd.h"
42 #include "eigrpd/eigrp_const.h"
43 #include "eigrpd/eigrp_filter.h"
44 #include "eigrpd/eigrp_packet.h"
47 * Distribute-list update functions.
49 void eigrp_distribute_update(struct distribute_ctx
*ctx
,
50 struct distribute
*dist
)
52 struct eigrp
*e
= eigrp_lookup(ctx
->vrf
->vrf_id
);
53 struct interface
*ifp
;
54 struct eigrp_interface
*ei
= NULL
;
55 struct access_list
*alist
;
56 struct prefix_list
*plist
;
57 // struct route_map *routemap;
59 /* if no interface address is present, set list to eigrp process struct
62 /* Check if distribute-list was set for process or interface */
64 /* access list IN for whole process */
65 if (dist
->list
[DISTRIBUTE_V4_IN
]) {
66 alist
= access_list_lookup(
67 AFI_IP
, dist
->list
[DISTRIBUTE_V4_IN
]);
69 e
->list
[EIGRP_FILTER_IN
] = alist
;
71 e
->list
[EIGRP_FILTER_IN
] = NULL
;
73 e
->list
[EIGRP_FILTER_IN
] = NULL
;
76 /* access list OUT for whole process */
77 if (dist
->list
[DISTRIBUTE_V4_OUT
]) {
78 alist
= access_list_lookup(
79 AFI_IP
, dist
->list
[DISTRIBUTE_V4_OUT
]);
81 e
->list
[EIGRP_FILTER_OUT
] = alist
;
83 e
->list
[EIGRP_FILTER_OUT
] = NULL
;
85 e
->list
[EIGRP_FILTER_OUT
] = NULL
;
88 /* PREFIX_LIST IN for process */
89 if (dist
->prefix
[DISTRIBUTE_V4_IN
]) {
90 plist
= prefix_list_lookup(
91 AFI_IP
, dist
->prefix
[DISTRIBUTE_V4_IN
]);
93 e
->prefix
[EIGRP_FILTER_IN
] = plist
;
95 e
->prefix
[EIGRP_FILTER_IN
] = NULL
;
97 e
->prefix
[EIGRP_FILTER_IN
] = NULL
;
99 /* PREFIX_LIST OUT for process */
100 if (dist
->prefix
[DISTRIBUTE_V4_OUT
]) {
101 plist
= prefix_list_lookup(
102 AFI_IP
, dist
->prefix
[DISTRIBUTE_V4_OUT
]);
104 e
->prefix
[EIGRP_FILTER_OUT
] = plist
;
107 e
->prefix
[EIGRP_FILTER_OUT
] = NULL
;
109 e
->prefix
[EIGRP_FILTER_OUT
] = NULL
;
111 // TODO: check Graceful restart after 10sec
113 /* cancel GR scheduled */
114 thread_cancel(&(e
->t_distribute
));
116 /* schedule Graceful restart for whole process in 10sec */
117 thread_add_timer(master
, eigrp_distribute_timer_process
, e
,
118 (10), &e
->t_distribute
);
123 ifp
= if_lookup_by_name(dist
->ifname
, e
->vrf_id
);
127 /*struct eigrp_if_info * info = ifp->info;
128 ei = info->eigrp_interface;*/
129 struct listnode
*node
, *nnode
;
130 struct eigrp_interface
*ei2
;
131 /* Find proper interface */
132 for (ALL_LIST_ELEMENTS(e
->eiflist
, node
, nnode
, ei2
)) {
133 if (strcmp(ei2
->ifp
->name
, ifp
->name
) == 0) {
140 /* Access-list for interface in */
141 if (dist
->list
[DISTRIBUTE_V4_IN
]) {
142 alist
= access_list_lookup(AFI_IP
,
143 dist
->list
[DISTRIBUTE_V4_IN
]);
145 ei
->list
[EIGRP_FILTER_IN
] = alist
;
147 ei
->list
[EIGRP_FILTER_IN
] = NULL
;
149 ei
->list
[EIGRP_FILTER_IN
] = NULL
;
152 /* Access-list for interface in */
153 if (dist
->list
[DISTRIBUTE_V4_OUT
]) {
154 alist
= access_list_lookup(AFI_IP
,
155 dist
->list
[DISTRIBUTE_V4_OUT
]);
157 ei
->list
[EIGRP_FILTER_OUT
] = alist
;
159 ei
->list
[EIGRP_FILTER_OUT
] = NULL
;
162 ei
->list
[EIGRP_FILTER_OUT
] = NULL
;
164 /* Prefix-list for interface in */
165 if (dist
->prefix
[DISTRIBUTE_V4_IN
]) {
166 plist
= prefix_list_lookup(AFI_IP
,
167 dist
->prefix
[DISTRIBUTE_V4_IN
]);
169 ei
->prefix
[EIGRP_FILTER_IN
] = plist
;
171 ei
->prefix
[EIGRP_FILTER_IN
] = NULL
;
173 ei
->prefix
[EIGRP_FILTER_IN
] = NULL
;
175 /* Prefix-list for interface out */
176 if (dist
->prefix
[DISTRIBUTE_V4_OUT
]) {
177 plist
= prefix_list_lookup(AFI_IP
,
178 dist
->prefix
[DISTRIBUTE_V4_OUT
]);
180 ei
->prefix
[EIGRP_FILTER_OUT
] = plist
;
182 ei
->prefix
[EIGRP_FILTER_OUT
] = NULL
;
184 ei
->prefix
[EIGRP_FILTER_OUT
] = NULL
;
186 // TODO: check Graceful restart after 10sec
188 /* Cancel GR scheduled */
189 thread_cancel(&(ei
->t_distribute
));
190 /* schedule Graceful restart for interface in 10sec */
191 thread_add_timer(master
, eigrp_distribute_timer_interface
, ei
, 10,
196 * Function called by prefix-list and access-list update
198 void eigrp_distribute_update_interface(struct interface
*ifp
)
200 struct distribute
*dist
;
203 eigrp
= eigrp_lookup(ifp
->vrf
->vrf_id
);
206 dist
= distribute_lookup(eigrp
->distribute_ctx
, ifp
->name
);
208 eigrp_distribute_update(eigrp
->distribute_ctx
,
212 /* Update all interface's distribute list.
213 * Function used in hook for prefix-list
215 void eigrp_distribute_update_all(struct prefix_list
*notused
)
218 struct interface
*ifp
;
220 RB_FOREACH (vrf
, vrf_name_head
, &vrfs_by_name
) {
221 FOR_ALL_INTERFACES (vrf
, ifp
)
222 eigrp_distribute_update_interface(ifp
);
227 * Function used in hook for acces-list
229 void eigrp_distribute_update_all_wrapper(struct access_list
*notused
)
231 eigrp_distribute_update_all(NULL
);
235 * @fn eigrp_distribute_timer_process
237 * @param[in] thread current execution thread timer is associated with
242 * Called when 10sec waiting time expire and
243 * executes Graceful restart for whole process
245 void eigrp_distribute_timer_process(struct thread
*thread
)
249 eigrp
= THREAD_ARG(thread
);
251 /* execute GR for whole process */
252 eigrp_update_send_process_GR(eigrp
, EIGRP_GR_FILTER
, NULL
);
256 * @fn eigrp_distribute_timer_interface
258 * @param[in] thread current execution thread timer is associated with
263 * Called when 10sec waiting time expire and
264 * executes Graceful restart for interface
266 void eigrp_distribute_timer_interface(struct thread
*thread
)
268 struct eigrp_interface
*ei
;
270 ei
= THREAD_ARG(thread
);
271 ei
->t_distribute
= NULL
;
273 /* execute GR for interface */
274 eigrp_update_send_interface_GR(ei
, EIGRP_GR_FILTER
, NULL
);