Skip to content

Commit db2bd81

Browse files
committed
Implement linter suggestions
1 parent 4e651a8 commit db2bd81

File tree

7 files changed

+19
-25
lines changed

7 files changed

+19
-25
lines changed

fwd.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func LocalForward(state *State, s *stack.Stack, conn KaConn, targetAddr net.Addr
155155
// connection had routable IP (unlike
156156
// 127.0.0.1)... well... spoof it! The client might find it
157157
// useful who launched the connection in the first place.
158-
if proxyProtocol == false {
158+
if !proxyProtocol {
159159
srcIP = conn.RemoteAddr()
160160
} else {
161161
ppPrefix = "PP "
@@ -251,5 +251,4 @@ pperror:
251251
err)
252252
}
253253
conn.Close()
254-
return
255254
}

kacon.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package main
22

33
import (
4-
"golang.org/x/sys/unix"
54
"net"
65
"sync"
76
"syscall"
87
"time"
8+
9+
"golang.org/x/sys/unix"
910
)
1011

1112
type KaConn interface {
@@ -92,7 +93,7 @@ func (c *KaUDPConn) Read(buf []byte) (int, error) {
9293
c.Conn.SetReadDeadline(t)
9394

9495
n, err := c.Conn.Read(buf)
95-
if ne, ok := err.(net.Error); ok == true && ne.Timeout() {
96+
if ne, ok := err.(net.Error); ok && ne.Timeout() {
9697
// On Keepalive raise special error
9798
return 0, &UDPKeepAliveError{err}
9899
} else {

main.go

+4-6
Original file line numberDiff line numberDiff line change
@@ -353,12 +353,10 @@ func Main(programName string, args []string) int {
353353
}
354354

355355
for {
356-
select {
357-
case sig := <-sigCh:
358-
signal.Reset(sig)
359-
fmt.Fprintf(os.Stderr, "[-] #%d Slirpnetstack closing\n", pid)
360-
goto stop
361-
}
356+
sig := <-sigCh
357+
signal.Reset(sig)
358+
fmt.Fprintf(os.Stderr, "[-] #%d Slirpnetstack closing\n", pid)
359+
goto stop
362360
}
363361
stop:
364362
// TODO: define semantics of graceful close on signal

net.go

+6-8
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func ParseDefAddress(ipS string, portS string) (_da *defAddress, _err error) {
100100
func (da *defAddress) Retrieve() *tcpip.FullAddress {
101101
da.Lock()
102102
defer da.Unlock()
103-
if da.label == "" || time.Now().Sub(da.fetched) <= dnsTTL {
103+
if da.label == "" || time.Since(da.fetched) <= dnsTTL {
104104
return &da.static
105105
}
106106
da.fetched = time.Now()
@@ -165,7 +165,7 @@ func simpleLookupHost(resolver *net.Resolver, label string) (net.IP, error) {
165165
return nil, err
166166
}
167167
if len(addrs) < 1 {
168-
return nil, fmt.Errorf("Empty dns reponse for %q", label)
168+
return nil, fmt.Errorf("empty dns reponse for %q", label)
169169
}
170170

171171
// prefer IPv4. No real reason.
@@ -178,7 +178,7 @@ func simpleLookupHost(resolver *net.Resolver, label string) (net.IP, error) {
178178

179179
ip := netParseIP(addrs[0])
180180
if ip == nil {
181-
return nil, fmt.Errorf("Empty dns reponse for %q", label)
181+
return nil, fmt.Errorf("empty dns reponse for %q", label)
182182
}
183183
return ip, nil
184184
}
@@ -189,7 +189,7 @@ func FullResolve(label string) (net.IP, uint16, error) {
189189
if len(p) == 2 {
190190
srvQuery, dnsSrv := p[0], p[1]
191191
if !strings.HasPrefix(dnsSrv, "srv-") {
192-
return nil, 0, fmt.Errorf("Unknown dns type %q", dnsSrv)
192+
return nil, 0, fmt.Errorf("unknown dns type %q", dnsSrv)
193193
}
194194

195195
dnsSrvAddr := dnsSrv[4:]
@@ -207,16 +207,14 @@ func FullResolve(label string) (net.IP, uint16, error) {
207207
}
208208
_, srvAddrs, err := r.LookupSRV(context.Background(), "", "", srvQuery)
209209
if err != nil || len(srvAddrs) == 0 {
210-
return nil, 0, fmt.Errorf("Failed to lookup SRV %q on %q", srvQuery, dnsSrvAddr)
210+
return nil, 0, fmt.Errorf("failed to lookup SRV %q on %q", srvQuery, dnsSrvAddr)
211211
}
212212

213213
// For effective resolution, allowing to utilize
214214
// /etc/hosts, trim the trailing dot if present.
215215
serviceLabel := srvAddrs[0].Target
216216
servicePort := srvAddrs[0].Port
217-
if strings.HasSuffix(serviceLabel, ".") {
218-
serviceLabel = serviceLabel[:len(serviceLabel)-1]
219-
}
217+
serviceLabel = strings.TrimSuffix(serviceLabel, ".")
220218

221219
ip, err := simpleLookupHost(r, serviceLabel)
222220
if err == nil && ip != nil {

proxy.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func connSplice(local KaConn, remote KaConn, sppHeader []byte) ProxyError {
154154
proxyOneFlow(remote, local, &pe.RemoteRead,
155155
&pe.LocalWrite, doneCh, 1, sppHeader)
156156
first := <-doneCh
157-
_ = <-doneCh
157+
<-doneCh
158158
switch {
159159
case first == 0 && pe.LocalRead != nil:
160160
pe.First = 0

routing.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func UdpRoutingHandler(s *stack.Stack, state *State) func(*udp.ForwarderRequest)
5454
}
5555

5656
rf, ok := state.remoteUdpFwd[loc.String()]
57-
if ok == false {
57+
if !ok {
5858
if block := FirewallRoutingBlock(state, loc); block {
5959
ep.Close()
6060
return
@@ -88,7 +88,7 @@ func TcpRoutingHandler(state *State) func(*tcp.ForwarderRequest) {
8888
}
8989

9090
rf, ok := state.remoteTcpFwd[loc.String()]
91-
if ok == false {
91+
if !ok {
9292
if block := FirewallRoutingBlock(state, loc); block {
9393
// In theory we could pass a bit of
9494
// data to the guest here. Like:

stack.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func NewStack(rcvBufferSize, sndBufferSize int) *stack.Stack {
126126
return s
127127
}
128128

129-
func createLinkEP(s *stack.Stack, tunFd int, tapMode bool, macAddress net.HardwareAddr, tapMtu uint32) (stack.LinkEndpoint, error) {
129+
func createLinkEP(_ *stack.Stack, tunFd int, tapMode bool, macAddress net.HardwareAddr, tapMtu uint32) (stack.LinkEndpoint, error) {
130130
parms := fdbased.Options{FDs: []int{tunFd},
131131
MTU: tapMtu,
132132
RXChecksumOffload: true,
@@ -227,9 +227,7 @@ func GonetDialTCP(s *stack.Stack, laddr, raddr *tcpip.FullAddress, network tcpip
227227

228228
err = ep.Connect(*raddr)
229229
if _, ok := err.(*tcpip.ErrConnectStarted); ok {
230-
select {
231-
case <-notifyCh:
232-
}
230+
<-notifyCh
233231

234232
err = ep.LastError()
235233
}

0 commit comments

Comments
 (0)