Skip to content

Commit

Permalink
style: refine code style
Browse files Browse the repository at this point in the history
  • Loading branch information
AkinoKaede committed May 28, 2023
1 parent 6c1bf1e commit b380d1e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions app/tun/handler_tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ func HandleTCP(handle func(tun_net.TCPConn)) StackOption {

// TODO: set sockopt

tcpConn := &tcpConn{
conn := &tcpConn{
TCPConn: gonet.NewTCPConn(wg, linkedEndpoint),
id: r.ID(),
}

tcpQueue <- tcpConn
handle(conn)
})
s.SetTransportProtocolHandler(tcp.ProtocolNumber, tcpForwarder.HandlePacket)

Expand Down
4 changes: 2 additions & 2 deletions app/tun/handler_udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ func HandleUDP(handle func(tun_net.UDPConn)) StackOption {
return
}

udpConn := &udpConn{
conn := &udpConn{
UDPConn: gonet.NewUDPConn(s, wg, linkedEndpoint),
id: r.ID(),
}

handle(udpConn)
handle(conn)
})
s.SetTransportProtocolHandler(gvisor_udp.ProtocolNumber, udpForwarder.HandlePacket)
return nil
Expand Down
8 changes: 4 additions & 4 deletions app/tun/nic.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,21 @@ func SetSpoofing(id tcpip.NICID, enable bool) StackOption {
func AddProtocolAddress(id tcpip.NICID, ips []*routercommon.CIDR) StackOption {
return func(s *stack.Stack) error {
for _, ip := range ips {
tcpIpAddr := tcpip.AddrFrom4Slice(ip.Ip)
tcpIPAddr := tcpip.AddrFrom4Slice(ip.Ip)
protocolAddress := tcpip.ProtocolAddress{
AddressWithPrefix: tcpip.AddressWithPrefix{
Address: tcpIpAddr,
Address: tcpIPAddr,
PrefixLen: int(ip.Prefix),
},
}

switch tcpIpAddr.Len() {
switch tcpIPAddr.Len() {
case 4:
protocolAddress.Protocol = ipv4.ProtocolNumber
case 16:
protocolAddress.Protocol = ipv6.ProtocolNumber
default:
return newError("invalid IP address length:", tcpIpAddr.Len())
return newError("invalid IP address length:", tcpIPAddr.Len())
}

if err := s.AddProtocolAddress(id, protocolAddress, stack.AddressProperties{}); err != nil {
Expand Down

0 comments on commit b380d1e

Please sign in to comment.