Skip to content

Commit

Permalink
refix: #2
Browse files Browse the repository at this point in the history
  • Loading branch information
mzz2017 committed Dec 7, 2021
1 parent 3d37126 commit 29f126a
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions tracer/stop_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,9 @@ func (t *Tracer) network(socketInfo *SocketMetadata) string {

func (t *Tracer) handleINet4(socketInfo *SocketMetadata, bSockAddr []byte) (sockAddrToPock []byte, err error) {
network := t.network(socketInfo)
port := t.port(socketInfo)
portSentTo := t.port(socketInfo)
addr := *(*RawSockaddrInet4)(unsafe.Pointer(&bSockAddr[0]))
if ip := netaddr.IPFrom4(addr.Addr); ip.IsLoopback() && port != 53 {
if ip := netaddr.IPFrom4(addr.Addr); ip.IsLoopback() && binary.BigEndian.Uint16(addr.Port[:]) != 53 {
// skip loopback
t.log.Tracef("skip loopback: %v", netaddr.IPPortFrom(ip, binary.BigEndian.Uint16(addr.Port[:])).String())
return nil, nil
Expand All @@ -280,7 +280,7 @@ func (t *Tracer) handleINet4(socketInfo *SocketMetadata, bSockAddr []byte) (sock
}
loopback := t.proxy.AllocProjection(originAddr)
addr.Addr = loopback.As4()
binary.BigEndian.PutUint16(addr.Port[:], uint16(port))
binary.BigEndian.PutUint16(addr.Port[:], uint16(portSentTo))
//logrus.Traceln("port", addr.Port)
_bSockAddrToPock := *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{
Data: uintptr(unsafe.Pointer(&addr)),
Expand All @@ -289,20 +289,20 @@ func (t *Tracer) handleINet4(socketInfo *SocketMetadata, bSockAddr []byte) (sock
}))
bSockAddrToPock := make([]byte, len(_bSockAddrToPock))
copy(bSockAddrToPock, _bSockAddrToPock)
t.log.Tracef("handleINet4 (%v): origin: %v, after: %v", network, originAddr, net.JoinHostPort(loopback.String(), strconv.Itoa(port)))
t.log.Tracef("handleINet4 (%v): origin: %v, after: %v", network, originAddr, net.JoinHostPort(loopback.String(), strconv.Itoa(portSentTo)))
return bSockAddrToPock, nil
}

func (t *Tracer) handleINet6(socketInfo *SocketMetadata, bSockAddr []byte) (sockAddrToPock []byte, err error) {
network := t.network(socketInfo)
port := t.port(socketInfo)
portSentTo := t.port(socketInfo)

addr := *(*RawSockaddrInet6)(unsafe.Pointer(&bSockAddr[0]))
ip := netaddr.IPFrom16(addr.Addr)
if ip.Is4in6() {
ip = netaddr.IPFrom4(ip.As4())
}
if ip.IsLoopback() && port != 53 {
if ip.IsLoopback() && binary.BigEndian.Uint16(addr.Port[:]) != 53 {
// skip loopback
t.log.Tracef("skip loopback: %v", netaddr.IPPortFrom(ip, binary.BigEndian.Uint16(addr.Port[:])).String())
return nil, nil
Expand All @@ -325,13 +325,13 @@ func (t *Tracer) handleINet6(socketInfo *SocketMetadata, bSockAddr []byte) (sock
return nil, err
}
addr.Addr = ipv4MappedIPv6.As16()
binary.BigEndian.PutUint16(addr.Port[:], uint16(port))
binary.BigEndian.PutUint16(addr.Port[:], uint16(portSentTo))
_bSockAddrToPock := *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{
Data: uintptr(unsafe.Pointer(&addr)),
Cap: binary.Size(addr),
Len: binary.Size(addr),
}))
t.log.Tracef("handleINet6 (%v): origin: %v, after: %v", network, originAddr, net.JoinHostPort(ipv4MappedIPv6.String(), strconv.Itoa(port)))
t.log.Tracef("handleINet6 (%v): origin: %v, after: %v", network, originAddr, net.JoinHostPort(ipv4MappedIPv6.String(), strconv.Itoa(portSentTo)))
bSockAddrToPock := make([]byte, len(_bSockAddrToPock))
copy(bSockAddrToPock, _bSockAddrToPock)
return bSockAddrToPock, nil
Expand Down

0 comments on commit 29f126a

Please sign in to comment.