| 892 | |
| 893 | |
| 894 | def cleanup_bridge(bridge): |
| 895 | bridge_name = get_br_fw(bridge) |
| 896 | logging.debug("Cleaning old bridge chains: " + bridge_name) |
| 897 | if not bridge_name: |
| 898 | return True |
| 899 | |
| 900 | # Delete iptables/bridge rules |
| 901 | rules = execute("""iptables-save | grep %s | grep '^-A' | sed 's/-A/-D/' """ % bridge_name).split("\n") |
| 902 | for rule in [_f for _f in rules if _f]: |
| 903 | try: |
| 904 | command = "iptables " + rule |
| 905 | execute(command) |
| 906 | except: pass |
| 907 | |
| 908 | chains = [bridge_name, bridge_name+'-IN', bridge_name+'-OUT'] |
| 909 | # Flush old bridge chain |
| 910 | for chain in chains: |
| 911 | try: |
| 912 | execute("iptables -F " + chain) |
| 913 | except: pass |
| 914 | # Remove bridge chains |
| 915 | for chain in chains: |
| 916 | try: |
| 917 | execute("iptables -X " + chain) |
| 918 | except: pass |
| 919 | return True |
| 920 | |
| 921 | |
| 922 | def cleanup_rules(): |