Skip to content

Commit

Permalink
Add printing for network operations
Browse files Browse the repository at this point in the history
So now, for example, with
telnet localhost 2448
you see things like

telnet(18797) E connect(0x3, 0x55efe8c7a1f0 {Family: AF_INET, Addr: 0x7f000001, Port: 2448}, 0x10)
telnet(18797) X connect(0x3, 0x55efe8c7a1f0 {Family: AF_INET, Addr: 0x7f000001, Port: 2448}, 0x10) = {0xffffffffffffff91} (452.745µs)

It's not complete but it's better. And you can see how long it wasted on that connect :-)

Signed-off-by: Ronald G. Minnich <rminnich@gmail.com>
  • Loading branch information
rminnich committed Oct 29, 2018
1 parent f29011c commit 04255f7
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 62 deletions.
121 changes: 61 additions & 60 deletions pkg/strace/epsocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
package strace

import (
"bytes"
"encoding/binary"
"strings"

"golang.org/x/sys/unix"
)

Expand All @@ -38,72 +42,69 @@ type FullAddress struct {
// to the FullAddress format. It supports AF_UNIX, AF_INET and AF_INET6
// addresses.
func GetAddress(t *Tracer, sfamily int, addr []byte) (FullAddress, error) {
/*
// Make sure we have at least 2 bytes for the address family.
if len(addr) < 2 {
return FullAddress{}, syserr.ErrInvalidArgument
}
r := bytes.NewBuffer(addr[:2])
var fam uint16
if err := binary.Read(r, ByteOrder, &fam); err != nil {
return FullAddress{}, unix.EFAULT
}
if fam != uint16(sfamily) {
return FullAddress{}, unix.ENOTSUP
}

family := usermem.ByteOrder.Uint16(addr)
if family != uint16(sfamily) {
return FullAddress{}, syserr.ErrAddressFamilyNotSupported
// Get the rest of the fields based on the address family.
switch fam {
case unix.AF_UNIX:
path := addr[2:]
if len(path) > unix.PathMax {
return FullAddress{}, unix.EINVAL
}
// Get the rest of the fields based on the address family.
switch family {
case linux.AF_UNIX:
path := addr[2:]
if len(path) > linux.UnixPathMax {
return FullAddress{}, syserr.ErrInvalidArgument
// Drop the terminating NUL (if one exists) and everything after
// it for filesystem (non-abstract) addresses.
if len(path) > 0 && path[0] != 0 {
if n := bytes.IndexByte(path[1:], 0); n >= 0 {
path = path[:n+1]
}
// Drop the terminating NUL (if one exists) and everything after
// it for filesystem (non-abstract) addresses.
if len(path) > 0 && path[0] != 0 {
if n := bytes.IndexByte(path[1:], 0); n >= 0 {
path = path[:n+1]
}
}
return FullAddress{
Addr: Address(path),
}, nil
}
return FullAddress{
Addr: Address(path),
}, nil

case linux.AF_INET:
var a linux.SockAddrInet
if len(addr) < sockAddrInetSize {
return FullAddress{}, syserr.ErrBadAddress
}
binary.Unmarshal(addr[:sockAddrInetSize], usermem.ByteOrder, &a)
case unix.AF_INET:
var a unix.RawSockaddrInet4
r = bytes.NewBuffer(addr)
if err := binary.Read(r, binary.BigEndian, &a); err != nil {
return FullAddress{}, unix.EFAULT
}
out := FullAddress{
Addr: Address(a.Addr[:]),
Port: uint16(a.Port),
}
if out.Addr == "\x00\x00\x00\x00" {
out.Addr = ""
}
return out, nil
case unix.AF_INET6:
var a unix.RawSockaddrInet6
r = bytes.NewBuffer(addr)
if err := binary.Read(r, binary.BigEndian, &a); err != nil {
return FullAddress{}, unix.EFAULT
}

out := FullAddress{
Addr: Address(a.Addr[:]),
Port: ntohs(a.Port),
}
if out.Addr == "\x00\x00\x00\x00" {
out.Addr = ""
}
return out, nil
out := FullAddress{
Addr: Address(a.Addr[:]),
Port: uint16(a.Port),
}

case linux.AF_INET6:
var a linux.SockAddrInet6
if len(addr) < sockAddrInet6Size {
return FullAddress{}, syserr.ErrBadAddress
}
binary.Unmarshal(addr[:sockAddrInet6Size], usermem.ByteOrder, &a)
//if isLinkLocal(out.Addr) {
// out.NIC = NICID(a.Scope_id)
//}

out := FullAddress{
Addr: Address(a.Addr[:]),
Port: ntohs(a.Port),
}
if isLinkLocal(out.Addr) {
out.NIC = NICID(a.Scope_id)
}
if out.Addr == Address(strings.Repeat("\x00", 16)) {
out.Addr = ""
}
return out, nil
if out.Addr == Address(strings.Repeat("\x00", 16)) {
out.Addr = ""
}
return out, nil
default:

default:
*/
return FullAddress{}, unix.ENOTSUP
//}
return FullAddress{}, unix.ENOTSUP
}
}
4 changes: 2 additions & 2 deletions pkg/strace/socket.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,10 @@ func sockAddr(t *Tracer, addr Addr, length uint32) string {
}

if family == unix.AF_UNIX {
return fmt.Sprintf("%#x {Family: %s, Addr: %q}", addr, familyStr, string(fa.Addr))
return fmt.Sprintf("%#x {Family: %s, Addr: %q}", addr, familyStr, fa.Addr)
}

return fmt.Sprintf("%#x {Family: %s, Addr: %v, Port: %d}", addr, familyStr, fa.Addr, fa.Port)
return fmt.Sprintf("%#x {Family: %s, Addr: %#02x, Port: %d}", addr, familyStr, []byte(fa.Addr), fa.Port)
case unix.AF_NETLINK:
//sa, err := netlink.ExtractSockAddr(b)
//if err != nil {
Expand Down

0 comments on commit 04255f7

Please sign in to comment.