* Retrieves table list from kernel, * optionally sorts it and calls requested function for each table. * Returns 0 on success. */
| 1674 | * Returns 0 on success. |
| 1675 | */ |
| 1676 | static int |
| 1677 | tables_foreach(table_cb_t *f, void *arg, int sort) |
| 1678 | { |
| 1679 | ipfw_obj_lheader *olh; |
| 1680 | ipfw_xtable_info *info; |
| 1681 | size_t sz; |
| 1682 | uint32_t i; |
| 1683 | int error; |
| 1684 | |
| 1685 | /* Start with reasonable default */ |
| 1686 | sz = sizeof(*olh) + 16 * sizeof(ipfw_xtable_info); |
| 1687 | |
| 1688 | for (;;) { |
| 1689 | if ((olh = calloc(1, sz)) == NULL) |
| 1690 | return (ENOMEM); |
| 1691 | |
| 1692 | olh->size = sz; |
| 1693 | if (do_get3(IP_FW_TABLES_XLIST, &olh->opheader, &sz) != 0) { |
| 1694 | sz = olh->size; |
| 1695 | free(olh); |
| 1696 | if (errno != ENOMEM) |
| 1697 | return (errno); |
| 1698 | continue; |
| 1699 | } |
| 1700 | |
| 1701 | if (sort != 0) |
| 1702 | qsort(olh + 1, olh->count, olh->objsize, |
| 1703 | tablename_cmp); |
| 1704 | |
| 1705 | info = (ipfw_xtable_info *)(olh + 1); |
| 1706 | for (i = 0; i < olh->count; i++) { |
| 1707 | if (g_co.use_set == 0 || info->set == g_co.use_set - 1) |
| 1708 | error = f(info, arg); |
| 1709 | info = (ipfw_xtable_info *)((caddr_t)info + |
| 1710 | olh->objsize); |
| 1711 | } |
| 1712 | free(olh); |
| 1713 | break; |
| 1714 | } |
| 1715 | return (0); |
| 1716 | } |
| 1717 | |
| 1718 | |
| 1719 | /* |
no test coverage detected