(tap_device: &str, host_ip: &str, gateway_port: u16)
| 475 | } |
| 476 | |
| 477 | fn teardown_tap_networking(tap_device: &str, host_ip: &str, gateway_port: u16) { |
| 478 | // Delete the entire nftables table — single atomic operation. |
| 479 | let table_name = nft_ruleset::teardown_table_name(tap_device); |
| 480 | let _ = run_cmd("nft", &["delete", "table", "ip", &table_name]); |
| 481 | |
| 482 | // Clean up legacy iptables rules from older driver versions. |
| 483 | let subnet = tap_subnet_from_host_ip(host_ip); |
| 484 | let _ = run_cmd( |
| 485 | "iptables", |
| 486 | &[ |
| 487 | "-D", |
| 488 | "FORWARD", |
| 489 | "-o", |
| 490 | tap_device, |
| 491 | "-m", |
| 492 | "state", |
| 493 | "--state", |
| 494 | "RELATED,ESTABLISHED", |
| 495 | "-j", |
| 496 | "ACCEPT", |
| 497 | ], |
| 498 | ); |
| 499 | let _ = run_cmd( |
| 500 | "iptables", |
| 501 | &["-D", "FORWARD", "-i", tap_device, "-j", "ACCEPT"], |
| 502 | ); |
| 503 | if gateway_port > 0 { |
| 504 | let port_str = gateway_port.to_string(); |
| 505 | let _ = run_cmd( |
| 506 | "iptables", |
| 507 | &[ |
| 508 | "-D", "INPUT", "-i", tap_device, "-p", "tcp", "--dport", &port_str, "-j", "ACCEPT", |
| 509 | ], |
| 510 | ); |
| 511 | } |
| 512 | let _ = run_cmd( |
| 513 | "iptables", |
| 514 | &["-D", "INPUT", "-i", tap_device, "-j", "ACCEPT"], |
| 515 | ); |
| 516 | let _ = run_cmd( |
| 517 | "iptables", |
| 518 | &[ |
| 519 | "-t", |
| 520 | "nat", |
| 521 | "-D", |
| 522 | "POSTROUTING", |
| 523 | "-s", |
| 524 | &subnet, |
| 525 | "-j", |
| 526 | "MASQUERADE", |
| 527 | ], |
| 528 | ); |
| 529 | |
| 530 | let _ = run_cmd("ip", &["link", "set", tap_device, "down"]); |
| 531 | let _ = run_cmd("ip", &["tuntap", "del", "dev", tap_device, "mode", "tap"]); |
| 532 | } |
| 533 | |
| 534 | fn tap_subnet_from_host_ip(host_ip: &str) -> String { |
no test coverage detected