mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
iptables: use "-t nat" for NAT tests
PiperOrigin-RevId: 295835807
This commit is contained in:
@@ -27,7 +27,16 @@ const iptablesBinary = "iptables"
|
||||
|
||||
// filterTable calls `iptables -t filter` with the given args.
|
||||
func filterTable(args ...string) error {
|
||||
args = append([]string{"-t", "filter"}, args...)
|
||||
return tableCmd("filter", args)
|
||||
}
|
||||
|
||||
// natTable calls `iptables -t nat` with the given args.
|
||||
func natTable(args ...string) error {
|
||||
return tableCmd("nat", args)
|
||||
}
|
||||
|
||||
func tableCmd(table string, args []string) error {
|
||||
args = append([]string{"-t", table}, args...)
|
||||
cmd := exec.Command(iptablesBinary, args...)
|
||||
if out, err := cmd.CombinedOutput(); err != nil {
|
||||
return fmt.Errorf("error running iptables with args %v\nerror: %v\noutput: %s", args, err, string(out))
|
||||
|
||||
@@ -38,7 +38,7 @@ func (NATRedirectUDPPort) Name() string {
|
||||
|
||||
// ContainerAction implements TestCase.ContainerAction.
|
||||
func (NATRedirectUDPPort) ContainerAction(ip net.IP) error {
|
||||
if err := filterTable("-t", "nat", "-A", "PREROUTING", "-p", "udp", "-j", "REDIRECT", "--to-ports", fmt.Sprintf("%d", redirectPort)); err != nil {
|
||||
if err := natTable("-A", "PREROUTING", "-p", "udp", "-j", "REDIRECT", "--to-ports", fmt.Sprintf("%d", redirectPort)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ func (NATDropUDP) Name() string {
|
||||
|
||||
// ContainerAction implements TestCase.ContainerAction.
|
||||
func (NATDropUDP) ContainerAction(ip net.IP) error {
|
||||
if err := filterTable("-t", "nat", "-A", "PREROUTING", "-p", "udp", "-j", "REDIRECT", "--to-ports", fmt.Sprintf("%d", redirectPort)); err != nil {
|
||||
if err := natTable("-A", "PREROUTING", "-p", "udp", "-j", "REDIRECT", "--to-ports", fmt.Sprintf("%d", redirectPort)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user