From 4e03e87547853523d4ff941935a6ef1712518c61 Mon Sep 17 00:00:00 2001 From: Adin Scannell Date: Tue, 12 Jan 2021 12:36:17 -0800 Subject: Fix simple mistakes identified by goreportcard. These are primarily simplification and lint mistakes. However, minor fixes are also included and tests added where appropriate. PiperOrigin-RevId: 351425971 --- test/iptables/filter_input.go | 1 + test/iptables/nat.go | 30 +++++++++++++++--------------- 2 files changed, 16 insertions(+), 15 deletions(-) (limited to 'test/iptables') diff --git a/test/iptables/filter_input.go b/test/iptables/filter_input.go index b45d448b8..37a1a6694 100644 --- a/test/iptables/filter_input.go +++ b/test/iptables/filter_input.go @@ -328,6 +328,7 @@ func (FilterInputRequireProtocolUDP) ContainerAction(ctx context.Context, ip net return nil } +// LocalAction implements TestCase.LocalAction. func (FilterInputRequireProtocolUDP) LocalAction(ctx context.Context, ip net.IP, ipv6 bool) error { // No-op. return nil diff --git a/test/iptables/nat.go b/test/iptables/nat.go index b98d99fb8..495241482 100644 --- a/test/iptables/nat.go +++ b/test/iptables/nat.go @@ -621,24 +621,24 @@ func listenForRedirectedConn(ctx context.Context, ipv6 bool, originalDsts []net. } } return fmt.Errorf("SO_ORIGINAL_DST returned %+v, but wanted one of %+v (note: port numbers are in network byte order)", got, originalDsts) - } else { - got, err := originalDestination4(connFD) - if err != nil { - return err + } + + got, err := originalDestination4(connFD) + if err != nil { + return err + } + // The original destination could be any of our IPs. + for _, dst := range originalDsts { + want := syscall.RawSockaddrInet4{ + Family: syscall.AF_INET, + Port: htons(dropPort), } - // The original destination could be any of our IPs. - for _, dst := range originalDsts { - want := syscall.RawSockaddrInet4{ - Family: syscall.AF_INET, - Port: htons(dropPort), - } - copy(want.Addr[:], dst.To4()) - if got == want { - return nil - } + copy(want.Addr[:], dst.To4()) + if got == want { + return nil } - return fmt.Errorf("SO_ORIGINAL_DST returned %+v, but wanted one of %+v (note: port numbers are in network byte order)", got, originalDsts) } + return fmt.Errorf("SO_ORIGINAL_DST returned %+v, but wanted one of %+v (note: port numbers are in network byte order)", got, originalDsts) } // loopbackTests runs an iptables rule and ensures that packets sent to -- cgit v1.2.3