Infof and Debugf in places we use formatting (#102)

* no message
* no message
This commit is contained in:
gadotroee 2021-07-12 14:53:26 +03:00 committed by GitHub
parent f03df50def
commit ec18d96b45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 22 deletions

View File

@ -51,7 +51,7 @@ func main() {
tapTargets := getTapTargets() tapTargets := getTapTargets()
if tapTargets != nil { if tapTargets != nil {
tap.SetFilterAuthorities(tapTargets) tap.SetFilterAuthorities(tapTargets)
rlog.Info("Filtering for the following authorities:", tap.GetFilterIPs()) rlog.Infof("Filtering for the following authorities: %v", tap.GetFilterIPs())
} }
harOutputChannel, outboundLinkOutputChannel := tap.StartPassiveTapper(tapOpts) harOutputChannel, outboundLinkOutputChannel := tap.StartPassiveTapper(tapOpts)

View File

@ -131,7 +131,7 @@ func saveHarToDb(entry *har.Entry, connectionInfo *tap.ConnectionInfo) {
unresolvedSource := connectionInfo.ClientIP unresolvedSource := connectionInfo.ClientIP
resolvedSource = k8sResolver.Resolve(unresolvedSource) resolvedSource = k8sResolver.Resolve(unresolvedSource)
if resolvedSource == "" { if resolvedSource == "" {
rlog.Debug("Cannot find resolved name to source: %s\n", unresolvedSource) rlog.Debugf("Cannot find resolved name to source: %s\n", unresolvedSource)
if os.Getenv("SKIP_NOT_RESOLVED_SOURCE") == "1" { if os.Getenv("SKIP_NOT_RESOLVED_SOURCE") == "1" {
return return
} }
@ -139,7 +139,7 @@ func saveHarToDb(entry *har.Entry, connectionInfo *tap.ConnectionInfo) {
unresolvedDestination := fmt.Sprintf("%s:%s", connectionInfo.ServerIP, connectionInfo.ServerPort) unresolvedDestination := fmt.Sprintf("%s:%s", connectionInfo.ServerIP, connectionInfo.ServerPort)
resolvedDestination = k8sResolver.Resolve(unresolvedDestination) resolvedDestination = k8sResolver.Resolve(unresolvedDestination)
if resolvedDestination == "" { if resolvedDestination == "" {
rlog.Debug("Cannot find resolved name to dest: %s\n", unresolvedDestination) rlog.Debugf("Cannot find resolved name to dest: %s\n", unresolvedDestination)
if os.Getenv("SKIP_NOT_RESOLVED_DEST") == "1" { if os.Getenv("SKIP_NOT_RESOLVED_DEST") == "1" {
return return
} }

View File

@ -213,7 +213,7 @@ func startPassiveTapper(harWriter *HarWriter, outboundLinkWriter *OutboundLinkWr
if localhostIPs, err := getLocalhostIPs(); err != nil { if localhostIPs, err := getLocalhostIPs(); err != nil {
// TODO: think this over // TODO: think this over
rlog.Info("Failed to get self IP addresses") rlog.Info("Failed to get self IP addresses")
rlog.Error("Getting-Self-Address", "Error getting self ip address: %s (%v,%+v)", err, err, err) rlog.Errorf("Getting-Self-Address", "Error getting self ip address: %s (%v,%+v)", err, err, err)
ownIps = make([]string, 0) ownIps = make([]string, 0)
} else { } else {
ownIps = localhostIPs ownIps = localhostIPs
@ -230,14 +230,14 @@ func startPassiveTapper(harWriter *HarWriter, outboundLinkWriter *OutboundLinkWr
SetFilterPorts(appPorts) SetFilterPorts(appPorts)
envVal := os.Getenv(maxHTTP2DataLenEnvVar) envVal := os.Getenv(maxHTTP2DataLenEnvVar)
if envVal == "" { if envVal == "" {
rlog.Info("Received empty/no HTTP2_DATA_SIZE_LIMIT env var! falling back to", maxHTTP2DataLenDefault) rlog.Infof("Received empty/no HTTP2_DATA_SIZE_LIMIT env var! falling back to %v", maxHTTP2DataLenDefault)
maxHTTP2DataLen = maxHTTP2DataLenDefault maxHTTP2DataLen = maxHTTP2DataLenDefault
} else { } else {
if convertedInt, err := strconv.Atoi(envVal); err != nil { if convertedInt, err := strconv.Atoi(envVal); err != nil {
rlog.Info("Received invalid HTTP2_DATA_SIZE_LIMIT env var! falling back to", maxHTTP2DataLenDefault) rlog.Infof("Received invalid HTTP2_DATA_SIZE_LIMIT env var! falling back to %v", maxHTTP2DataLenDefault)
maxHTTP2DataLen = maxHTTP2DataLenDefault maxHTTP2DataLen = maxHTTP2DataLenDefault
} else { } else {
rlog.Info("Received HTTP2_DATA_SIZE_LIMIT env var:", maxHTTP2DataLenDefault) rlog.Infof("Received HTTP2_DATA_SIZE_LIMIT env var: %v", maxHTTP2DataLenDefault)
maxHTTP2DataLen = convertedInt maxHTTP2DataLen = convertedInt
} }
} }
@ -379,11 +379,11 @@ func startPassiveTapper(harWriter *HarWriter, outboundLinkWriter *OutboundLinkWr
for packet := range source.Packets() { for packet := range source.Packets() {
count++ count++
rlog.Debug("PACKET #%d", count) rlog.Debugf("PACKET #%d", count)
data := packet.Data() data := packet.Data()
bytes += int64(len(data)) bytes += int64(len(data))
if *hexdumppkt { if *hexdumppkt {
rlog.Debug("Packet content (%d/0x%x) - %s", len(data), len(data), hex.Dump(data)) rlog.Debugf("Packet content (%d/0x%x) - %s", len(data), len(data), hex.Dump(data))
} }
// defrag the IPv4 packet if required // defrag the IPv4 packet if required
@ -398,12 +398,12 @@ func startPassiveTapper(harWriter *HarWriter, outboundLinkWriter *OutboundLinkWr
if err != nil { if err != nil {
log.Fatalln("Error while de-fragmenting", err) log.Fatalln("Error while de-fragmenting", err)
} else if newip4 == nil { } else if newip4 == nil {
rlog.Debug("Fragment...") rlog.Debugf("Fragment...")
continue // packet fragment, we don't have whole packet yet. continue // packet fragment, we don't have whole packet yet.
} }
if newip4.Length != l { if newip4.Length != l {
stats.ipdefrag++ stats.ipdefrag++
rlog.Debug("Decoding re-assembled packet: %s", newip4.NextLayerType()) rlog.Debugf("Decoding re-assembled packet: %s", newip4.NextLayerType())
pb, ok := packet.(gopacket.PacketBuilder) pb, ok := packet.(gopacket.PacketBuilder)
if !ok { if !ok {
log.Panic("Not a PacketBuilder") log.Panic("Not a PacketBuilder")
@ -426,7 +426,7 @@ func startPassiveTapper(harWriter *HarWriter, outboundLinkWriter *OutboundLinkWr
CaptureInfo: packet.Metadata().CaptureInfo, CaptureInfo: packet.Metadata().CaptureInfo,
} }
stats.totalsz += len(tcp.Payload) stats.totalsz += len(tcp.Payload)
rlog.Debug(packet.NetworkLayer().NetworkFlow().Src(), ":", tcp.SrcPort, " -> ", packet.NetworkLayer().NetworkFlow().Dst(), ":", tcp.DstPort) rlog.Debugf(packet.NetworkLayer().NetworkFlow().Src(), ":", tcp.SrcPort, " -> ", packet.NetworkLayer().NetworkFlow().Dst(), ":", tcp.DstPort)
assemblerMutex.Lock() assemblerMutex.Lock()
assembler.AssembleWithContext(packet.NetworkLayer().NetworkFlow(), tcp, &c) assembler.AssembleWithContext(packet.NetworkLayer().NetworkFlow(), tcp, &c)
assemblerMutex.Unlock() assemblerMutex.Unlock()
@ -454,7 +454,7 @@ func startPassiveTapper(harWriter *HarWriter, outboundLinkWriter *OutboundLinkWr
assemblerMutex.Lock() assemblerMutex.Lock()
closed := assembler.FlushAll() closed := assembler.FlushAll()
assemblerMutex.Unlock() assemblerMutex.Unlock()
rlog.Debug("Final flush: %d closed", closed) rlog.Debugf("Final flush: %d closed", closed)
if outputLevel >= 2 { if outputLevel >= 2 {
streamPool.Dump() streamPool.Dump()
} }
@ -470,7 +470,7 @@ func startPassiveTapper(harWriter *HarWriter, outboundLinkWriter *OutboundLinkWr
streamFactory.WaitGoRoutines() streamFactory.WaitGoRoutines()
assemblerMutex.Lock() assemblerMutex.Lock()
rlog.Debug("%s", assembler.Dump()) rlog.Debugf("%s", assembler.Dump())
assemblerMutex.Unlock() assemblerMutex.Unlock()
if !*nodefrag { if !*nodefrag {
log.Printf("IPdefrag:\t\t%d", stats.ipdefrag) log.Printf("IPdefrag:\t\t%d", stats.ipdefrag)

View File

@ -23,11 +23,11 @@ type tcpStreamFactory struct {
} }
func (factory *tcpStreamFactory) New(net, transport gopacket.Flow, tcp *layers.TCP, ac reassembly.AssemblerContext) reassembly.Stream { func (factory *tcpStreamFactory) New(net, transport gopacket.Flow, tcp *layers.TCP, ac reassembly.AssemblerContext) reassembly.Stream {
rlog.Debug("* NEW: %s %s", net, transport) rlog.Debugf("* NEW: %s %s", net, transport)
fsmOptions := reassembly.TCPSimpleFSMOptions{ fsmOptions := reassembly.TCPSimpleFSMOptions{
SupportMissingEstablishment: *allowmissinginit, SupportMissingEstablishment: *allowmissinginit,
} }
rlog.Debug("Current App Ports: %v", gSettings.filterPorts) rlog.Debugf("Current App Ports: %v", gSettings.filterPorts)
srcIp := net.Src().String() srcIp := net.Src().String()
dstIp := net.Dst().String() dstIp := net.Dst().String()
dstPort := int(tcp.DstPort) dstPort := int(tcp.DstPort)
@ -92,31 +92,31 @@ func (factory *tcpStreamFactory) WaitGoRoutines() {
func (factory *tcpStreamFactory) getStreamProps(srcIP string, dstIP string, dstPort int) *streamProps { func (factory *tcpStreamFactory) getStreamProps(srcIP string, dstIP string, dstPort int) *streamProps {
if hostMode { if hostMode {
if inArrayString(gSettings.filterAuthorities, fmt.Sprintf("%s:%d", dstIP, dstPort)) == true { if inArrayString(gSettings.filterAuthorities, fmt.Sprintf("%s:%d", dstIP, dstPort)) == true {
rlog.Debug("getStreamProps %s", fmt.Sprintf("+ host1 %s:%d", dstIP, dstPort)) rlog.Debugf("getStreamProps %s", fmt.Sprintf("+ host1 %s:%d", dstIP, dstPort))
return &streamProps{isTapTarget: true, isOutgoing: false} return &streamProps{isTapTarget: true, isOutgoing: false}
} else if inArrayString(gSettings.filterAuthorities, dstIP) == true { } else if inArrayString(gSettings.filterAuthorities, dstIP) == true {
rlog.Debug("getStreamProps %s", fmt.Sprintf("+ host2 %s", dstIP)) rlog.Debugf("getStreamProps %s", fmt.Sprintf("+ host2 %s", dstIP))
return &streamProps{isTapTarget: true, isOutgoing: false} return &streamProps{isTapTarget: true, isOutgoing: false}
} else if *anydirection && inArrayString(gSettings.filterAuthorities, srcIP) == true { } else if *anydirection && inArrayString(gSettings.filterAuthorities, srcIP) == true {
rlog.Debug("getStreamProps %s", fmt.Sprintf("+ host3 %s", srcIP)) rlog.Debugf("getStreamProps %s", fmt.Sprintf("+ host3 %s", srcIP))
return &streamProps{isTapTarget: true, isOutgoing: true} return &streamProps{isTapTarget: true, isOutgoing: true}
} }
return &streamProps{isTapTarget: false} return &streamProps{isTapTarget: false}
} else { } else {
isTappedPort := dstPort == 80 || (gSettings.filterPorts != nil && (inArrayInt(gSettings.filterPorts, dstPort))) isTappedPort := dstPort == 80 || (gSettings.filterPorts != nil && (inArrayInt(gSettings.filterPorts, dstPort)))
if !isTappedPort { if !isTappedPort {
rlog.Debug("getStreamProps %s", fmt.Sprintf("- notHost1 %d", dstPort)) rlog.Debugf("getStreamProps %s", fmt.Sprintf("- notHost1 %d", dstPort))
return &streamProps{isTapTarget: false, isOutgoing: false} return &streamProps{isTapTarget: false, isOutgoing: false}
} }
isOutgoing := !inArrayString(ownIps, dstIP) isOutgoing := !inArrayString(ownIps, dstIP)
if !*anydirection && isOutgoing { if !*anydirection && isOutgoing {
rlog.Debug("getStreamProps %s", fmt.Sprintf("- notHost2")) rlog.Debugf("getStreamProps %s", fmt.Sprintf("- notHost2"))
return &streamProps{isTapTarget: false, isOutgoing: isOutgoing} return &streamProps{isTapTarget: false, isOutgoing: isOutgoing}
} }
rlog.Debug("getStreamProps %s", fmt.Sprintf("+ notHost3 %s -> %s:%d", srcIP, dstIP, dstPort)) rlog.Debugf("getStreamProps %s", fmt.Sprintf("+ notHost3 %s -> %s:%d", srcIP, dstIP, dstPort))
return &streamProps{isTapTarget: true} return &streamProps{isTapTarget: true}
} }
} }