-
Notifications
You must be signed in to change notification settings - Fork 34
OCPBUGS-76699: ebpf: consolidate packet event logs into single line #706
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rameshsahoo11
wants to merge
2
commits into
openshift:master
Choose a base branch
from
rameshsahoo11:consolidate-event-logs
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ import ( | |
| "net" | ||
| "os" | ||
| "os/signal" | ||
| "strings" | ||
| "syscall" | ||
| "time" | ||
| "unsafe" | ||
|
|
@@ -104,66 +105,44 @@ func (infc *IngNodeFwController) ingressNodeFwEvents() error { | |
| log.Printf("lookup network iface %d: %s", eventHdr.IfId, err) | ||
| continue | ||
| } | ||
| if err := eventsLogger.Info(fmt.Sprintf("ruleId %d action %s len %d if %s\n", | ||
| eventHdr.RuleId, convertXdpActionToString(eventHdr.Action), eventHdr.PktLength, iface.Name)); err != nil { | ||
| log.Printf("syslog event logging failed %q", err) | ||
| } | ||
| // Build a complete log message with all packet details | ||
| var logMsg strings.Builder | ||
| fmt.Fprintf(&logMsg, "ruleId %d action %s len %d if %s", | ||
| eventHdr.RuleId, convertXdpActionToString(eventHdr.Action), eventHdr.PktLength, iface.Name) | ||
|
|
||
| decodePacket := gopacket.NewPacket(packet, layers.LayerTypeEthernet, gopacket.Default) | ||
| // check for IPv4 | ||
|
|
||
| // Append IP layer information | ||
| if ip4Layer := decodePacket.Layer(layers.LayerTypeIPv4); ip4Layer != nil { | ||
| ip, _ := ip4Layer.(*layers.IPv4) | ||
| if err := eventsLogger.Info(fmt.Sprintf("\tipv4 src addr %s dst addr %s\n", ip.SrcIP.String(), ip.DstIP.String())); err != nil { | ||
| log.Printf("syslog event logging for ruleId %d on intrerface %s failed err: %q", | ||
| eventHdr.RuleId, iface.Name, err) | ||
| } | ||
| } | ||
| // check for IPv6 | ||
| if ip6Layer := decodePacket.Layer(layers.LayerTypeIPv6); ip6Layer != nil { | ||
| fmt.Fprintf(&logMsg, " | ipv4 src %s dst %s", ip.SrcIP.String(), ip.DstIP.String()) | ||
| } else if ip6Layer := decodePacket.Layer(layers.LayerTypeIPv6); ip6Layer != nil { | ||
| ip, _ := ip6Layer.(*layers.IPv6) | ||
| if err := eventsLogger.Info(fmt.Sprintf("\tipv6 src addr %s dst addr %s\n", ip.SrcIP.String(), ip.DstIP.String())); err != nil { | ||
| log.Printf("syslog event logging for ruleId %d on intrerface %s failed err: %q", | ||
| eventHdr.RuleId, iface.Name, err) | ||
| } | ||
| fmt.Fprintf(&logMsg, " | ipv6 src %s dst %s", ip.SrcIP.String(), ip.DstIP.String()) | ||
| } | ||
| // check for TCP | ||
|
|
||
| // Append protocol-specific information | ||
| if tcpLayer := decodePacket.Layer(layers.LayerTypeTCP); tcpLayer != nil { | ||
| tcp, _ := tcpLayer.(*layers.TCP) | ||
| if err := eventsLogger.Info(fmt.Sprintf("\ttcp srcPort %d dstPort %d\n", tcp.SrcPort, tcp.DstPort)); err != nil { | ||
| log.Printf("syslog event logging for ruleId %d on intrerface %s failed err: %q", | ||
| eventHdr.RuleId, iface.Name, err) | ||
| } | ||
| } | ||
| // check for UDP | ||
| if udpLayer := decodePacket.Layer(layers.LayerTypeUDP); udpLayer != nil { | ||
| fmt.Fprintf(&logMsg, " | tcp srcPort %d dstPort %d", tcp.SrcPort, tcp.DstPort) | ||
| } else if udpLayer := decodePacket.Layer(layers.LayerTypeUDP); udpLayer != nil { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
| udp, _ := udpLayer.(*layers.UDP) | ||
| if err := eventsLogger.Info(fmt.Sprintf("\tudp srcPort %d dstPort %d\n", udp.SrcPort, udp.DstPort)); err != nil { | ||
| log.Printf("syslog event logging for ruleId %d on intrerface %s failed err: %q", | ||
| eventHdr.RuleId, iface.Name, err) | ||
| } | ||
| } | ||
| // check fo SCTP | ||
| if sctpLayer := decodePacket.Layer(layers.LayerTypeSCTP); sctpLayer != nil { | ||
| fmt.Fprintf(&logMsg, " | udp srcPort %d dstPort %d", udp.SrcPort, udp.DstPort) | ||
| } else if sctpLayer := decodePacket.Layer(layers.LayerTypeSCTP); sctpLayer != nil { | ||
| sctp, _ := sctpLayer.(*layers.SCTP) | ||
| if err := eventsLogger.Info(fmt.Sprintf("\tsctp srcPort %d dstPort %d\n", sctp.SrcPort, sctp.DstPort)); err != nil { | ||
| log.Printf("syslog event logging for ruleId %d on intrerface %s failed err: %q", | ||
| eventHdr.RuleId, iface.Name, err) | ||
| } | ||
| } | ||
| // check for ICMPv4 | ||
| if icmpv4Layer := decodePacket.Layer(layers.LayerTypeICMPv4); icmpv4Layer != nil { | ||
| fmt.Fprintf(&logMsg, " | sctp srcPort %d dstPort %d", sctp.SrcPort, sctp.DstPort) | ||
| } else if icmpv4Layer := decodePacket.Layer(layers.LayerTypeICMPv4); icmpv4Layer != nil { | ||
| icmp, _ := icmpv4Layer.(*layers.ICMPv4) | ||
| if err := eventsLogger.Info(fmt.Sprintf("\ticmpv4 type %d code %d\n", icmp.TypeCode.Type(), icmp.TypeCode.Code())); err != nil { | ||
| log.Printf("syslog event logging for ruleId %d on intrerface %s failed err: %q", | ||
| eventHdr.RuleId, iface.Name, err) | ||
| } | ||
| } | ||
| // check for ICMPV6 | ||
| if icmpv6Layer := decodePacket.Layer(layers.LayerTypeICMPv6); icmpv6Layer != nil { | ||
| fmt.Fprintf(&logMsg, " | icmpv4 type %d code %d", icmp.TypeCode.Type(), icmp.TypeCode.Code()) | ||
| } else if icmpv6Layer := decodePacket.Layer(layers.LayerTypeICMPv6); icmpv6Layer != nil { | ||
| icmp, _ := icmpv6Layer.(*layers.ICMPv6) | ||
| if err := eventsLogger.Info(fmt.Sprintf("\ticmpv6 type %d code %d\n", icmp.TypeCode.Type(), icmp.TypeCode.Code())); err != nil { | ||
| log.Printf("syslog event logging for ruleId %d on intrerface %s failed err: %q", | ||
| eventHdr.RuleId, iface.Name, err) | ||
| } | ||
| fmt.Fprintf(&logMsg, " | icmpv6 type %d code %d", icmp.TypeCode.Type(), icmp.TypeCode.Code()) | ||
| } | ||
|
|
||
| // Log the complete message as a single line | ||
| if err := eventsLogger.Info(logMsg.String()); err != nil { | ||
| log.Printf("syslog event logging for ruleId %d on interface %s failed err: %q", | ||
| eventHdr.RuleId, iface.Name, err) | ||
| } | ||
| } | ||
| }() | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here you shouldn't use
else if, it will cause ipv6 logs lost in dualtsack cluster