* Iterates over a routing table specified by @fibnum and @family and * deletes elements marked by @filter_f. * @fibnum: rtable id * @family: AF_ address family * @filter_f: function returning non-zero value for items to delete * @arg: data to pass to the @filter_f function * @report: true if rtsock notification is needed. */
| 1299 | * @report: true if rtsock notification is needed. |
| 1300 | */ |
| 1301 | void |
| 1302 | rib_walk_del(u_int fibnum, int family, rib_filter_f_t *filter_f, void *arg, bool report) |
| 1303 | { |
| 1304 | struct rib_head *rnh; |
| 1305 | struct rt_delinfo di; |
| 1306 | struct rtentry *rt; |
| 1307 | struct nhop_object *nh; |
| 1308 | struct epoch_tracker et; |
| 1309 | |
| 1310 | rnh = rt_tables_get_rnh(fibnum, family); |
| 1311 | if (rnh == NULL) |
| 1312 | return; |
| 1313 | |
| 1314 | bzero(&di, sizeof(di)); |
| 1315 | di.info.rti_filter = filter_f; |
| 1316 | di.info.rti_filterdata = arg; |
| 1317 | di.rnh = rnh; |
| 1318 | di.rc.rc_cmd = RTM_DELETE; |
| 1319 | |
| 1320 | NET_EPOCH_ENTER(et); |
| 1321 | |
| 1322 | RIB_WLOCK(rnh); |
| 1323 | rnh->rnh_walktree(&rnh->head, rt_checkdelroute, &di); |
| 1324 | RIB_WUNLOCK(rnh); |
| 1325 | |
| 1326 | /* We might have something to reclaim. */ |
| 1327 | bzero(&di.rc, sizeof(di.rc)); |
| 1328 | di.rc.rc_cmd = RTM_DELETE; |
| 1329 | while (di.head != NULL) { |
| 1330 | rt = di.head; |
| 1331 | di.head = rt->rt_chain; |
| 1332 | rt->rt_chain = NULL; |
| 1333 | nh = rt->rt_nhop; |
| 1334 | |
| 1335 | di.rc.rc_rt = rt; |
| 1336 | di.rc.rc_nh_old = nh; |
| 1337 | rib_notify(rnh, RIB_NOTIFY_DELAYED, &di.rc); |
| 1338 | |
| 1339 | /* TODO std rt -> rt_addrinfo export */ |
| 1340 | di.info.rti_info[RTAX_DST] = rt_key(rt); |
| 1341 | di.info.rti_info[RTAX_NETMASK] = rt_mask(rt); |
| 1342 | |
| 1343 | if (report) { |
| 1344 | #ifdef ROUTE_MPATH |
| 1345 | struct nhgrp_object *nhg; |
| 1346 | struct weightened_nhop *wn; |
| 1347 | uint32_t num_nhops; |
| 1348 | if (NH_IS_NHGRP(nh)) { |
| 1349 | nhg = (struct nhgrp_object *)nh; |
| 1350 | wn = nhgrp_get_nhops(nhg, &num_nhops); |
| 1351 | for (int i = 0; i < num_nhops; i++) |
| 1352 | rt_routemsg(RTM_DELETE, rt, wn[i].nh, fibnum); |
| 1353 | } else |
| 1354 | #endif |
| 1355 | rt_routemsg(RTM_DELETE, rt, nh, fibnum); |
| 1356 | } |
| 1357 | rtfree(rt); |
| 1358 | } |
no test coverage detected