| skipped 1593 lines |
1594 | 1594 | | return ret; |
1595 | 1595 | | } |
1596 | 1596 | | |
1597 | | - | char *get_legacy_iptables_bin(bool ipv6) |
| 1597 | + | char *get_legacy_iptables_bin(bool ipv6, bool restore) |
1598 | 1598 | | { |
1599 | | - | static char iptables_bin[2][32]; |
| 1599 | + | static char iptables_bin[2][2][32]; |
1600 | 1600 | | /* 0 - means we don't know yet, |
1601 | 1601 | | * -1 - not present, |
1602 | 1602 | | * 1 - present. |
1603 | 1603 | | */ |
1604 | | - | static int iptables_present[2] = { 0, 0 }; |
1605 | | - | char bins[2][2][32] = { { "iptables-save", "iptables-legacy-save" }, |
1606 | | - | { "ip6tables-save", "ip6tables-legacy-save" } }; |
| 1604 | + | static int iptables_present[2][2] = { { 0, 0 }, { 0, 0 } }; |
| 1605 | + | char bins[2][2][2][32] = { { { "iptables-save", "iptables-legacy-save" }, |
| 1606 | + | { "iptables-restore", "iptables-legacy-restore" } }, |
| 1607 | + | { { "ip6tables-save", "ip6tables-legacy-save" }, |
| 1608 | + | { "ip6tables-restore", "ip6tables-legacy-restore" } } }; |
1607 | 1609 | | int ret; |
1608 | 1610 | | |
1609 | | - | if (iptables_present[ipv6] == -1) |
| 1611 | + | if (iptables_present[ipv6][restore] == -1) |
1610 | 1612 | | return NULL; |
1611 | 1613 | | |
1612 | | - | if (iptables_present[ipv6] == 1) |
1613 | | - | return iptables_bin[ipv6]; |
| 1614 | + | if (iptables_present[ipv6][restore] == 1) |
| 1615 | + | return iptables_bin[ipv6][restore]; |
1614 | 1616 | | |
1615 | | - | memcpy(iptables_bin[ipv6], bins[ipv6][0], strlen(bins[ipv6][0]) + 1); |
1616 | | - | ret = is_iptables_nft(iptables_bin[ipv6]); |
| 1617 | + | memcpy(iptables_bin[ipv6][restore], bins[ipv6][restore][0], strlen(bins[ipv6][restore][0]) + 1); |
| 1618 | + | ret = is_iptables_nft(iptables_bin[ipv6][restore]); |
1617 | 1619 | | |
1618 | 1620 | | /* |
1619 | 1621 | | * iptables on host uses nft backend (or not installed), |
1620 | 1622 | | * let's try iptables-legacy |
1621 | 1623 | | */ |
1622 | 1624 | | if (ret < 0 || ret == 1) { |
1623 | | - | memcpy(iptables_bin[ipv6], bins[ipv6][1], strlen(bins[ipv6][1]) + 1); |
1624 | | - | ret = is_iptables_nft(iptables_bin[ipv6]); |
| 1625 | + | memcpy(iptables_bin[ipv6][restore], bins[ipv6][restore][1], strlen(bins[ipv6][restore][1]) + 1); |
| 1626 | + | ret = is_iptables_nft(iptables_bin[ipv6][restore]); |
1625 | 1627 | | if (ret < 0 || ret == 1) { |
1626 | | - | iptables_present[ipv6] = -1; |
| 1628 | + | iptables_present[ipv6][restore] = -1; |
1627 | 1629 | | return NULL; |
1628 | 1630 | | } |
1629 | 1631 | | } |
1630 | 1632 | | |
1631 | 1633 | | /* we can come here with iptables-save or iptables-legacy-save */ |
1632 | | - | iptables_present[ipv6] = 1; |
| 1634 | + | iptables_present[ipv6][restore] = 1; |
1633 | 1635 | | |
1634 | | - | return iptables_bin[ipv6]; |
| 1636 | + | return iptables_bin[ipv6][restore]; |
1635 | 1637 | | } |
1636 | 1638 | | |
1637 | 1639 | | /* |
| skipped 452 lines |