feat: new log formatter

This commit is contained in:
mzz2017
2023-02-04 15:02:44 +08:00
parent 68c8ff7754
commit a70d09f59a
8 changed files with 113 additions and 13 deletions

View File

@ -8,6 +8,7 @@ package control
import (
"fmt"
"github.com/mzz2017/softwind/pkg/zeroalloc/io"
"github.com/sirupsen/logrus"
"github.com/v2rayA/dae/common"
"github.com/v2rayA/dae/common/consts"
internal "github.com/v2rayA/dae/pkg/ebpf_internal"
@ -48,7 +49,10 @@ func (c *ControlPlane) handleConn(lConn net.Conn) (err error) {
outbound := c.outbounds[value.Outbound]
// TODO: Set-up ip to domain mapping and show domain if possible.
src := lConn.RemoteAddr().(*net.TCPAddr).AddrPort()
c.log.Infof("TCP: %v <-[%v]-> %v", RefineSourceToShow(src, dst.Addr()), outbound.Name, RefineAddrPortToShow(dst))
c.log.WithFields(logrus.Fields{
"l4proto": "TCP",
"outbound": outbound.Name,
}).Infof("%v <-> %v", RefineSourceToShow(src, dst.Addr()), RefineAddrPortToShow(dst))
if value.Outbound < 0 || int(value.Outbound) >= len(c.outbounds) {
return fmt.Errorf("outbound id from bpf is out of range: %v not in [0, %v]", value.Outbound, len(c.outbounds)-1)
}

View File

@ -141,8 +141,11 @@ func (c *ControlPlane) handlePkt(data []byte, lConn *net.UDPConn, lAddrPort neti
}
} else {
// TODO: Set-up ip to domain mapping and show domain if possible.
c.log.Infof("UDP %v <-[%v]-> %v",
RefineSourceToShow(lAddrPort, dest.Addr()), outbound.Name, RefineAddrPortToShow(dest),
c.log.WithFields(logrus.Fields{
"l4proto": "UDP",
"outbound": outbound.Name,
}).Infof("%v <-> %v",
RefineSourceToShow(lAddrPort, dest.Addr()), RefineAddrPortToShow(dest),
)
}
ue, err := DefaultUdpEndpointPool.GetOrCreate(lAddrPort, &UdpEndpointOptions{