MCPcopy
hub / github.com/microsoft/retina / generateDropTracepoint

Method generateDropTracepoint

shell/tracescript.go:100–160  ·  view source on GitHub ↗

generateDropTracepoint creates the kfree_skb tracepoint for packet drops.

()

Source from the content-addressed store, hash-verified

98
99// generateDropTracepoint creates the kfree_skb tracepoint for packet drops.
100func (g *ScriptGenerator) generateDropTracepoint() string {
101 var sb strings.Builder
102
103 // Tracepoint for packet drops
104 // Note: No pre-filter here because we need to parse skb to get IPs.
105 // IP filtering is done in the body after extracting addresses.
106 sb.WriteString("tracepoint:skb:kfree_skb\n")
107 sb.WriteString("{\n")
108
109 // Extract packet info
110 sb.WriteString(` $skb = (struct sk_buff *)args->skbaddr;
111 $reason = args->reason;
112
113 // Skip non-drop events (reason 0-2 are not real drops)
114 if ($reason <= 2) { return; }
115
116 $protocol = $skb->protocol;
117
118 // Only process IPv4 for now
119 if (bswap($protocol) != 0x0800) { return; }
120
121 $iph = (struct iphdr *)($skb->head + $skb->network_header);
122 $saddr_raw = $iph->saddr;
123 $daddr_raw = $iph->daddr;
124 $saddr = ntop(2, $saddr_raw);
125 $daddr = ntop(2, $daddr_raw);
126 $ipproto = $iph->protocol;
127
128`)
129
130 // Add IP/CIDR filter inside the body if specified
131 ipFilter := g.buildSkbIPFilterCondition()
132 if ipFilter != "" {
133 sb.WriteString(ipFilter)
134 }
135
136 sb.WriteString(` $sport = (uint16)0;
137 $dport = (uint16)0;
138
139 // Extract ports for TCP/UDP
140 if ($ipproto == 6 || $ipproto == 17) {
141 $transport_off = $skb->transport_header;
142 if ($transport_off > 0 && $transport_off < 65535) {
143 $th = $skb->head + $transport_off;
144 $sport = bswap(*(uint16*)($th));
145 $dport = bswap(*(uint16*)($th + 2));
146 }
147 }
148
149`)
150
151 // Generate output based on format
152 if g.config.OutputJSON {
153 sb.WriteString(g.generateJSONOutput())
154 } else {
155 sb.WriteString(g.generateTableOutput())
156 }
157

Callers 1

GenerateMethod · 0.95

Calls 4

generateJSONOutputMethod · 0.95
generateTableOutputMethod · 0.95
StringMethod · 0.45

Tested by

no test coverage detected