2021-11-24 23:20:46 +03:00
|
|
|
package inet
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/wader/fq/format"
|
|
|
|
"github.com/wader/fq/pkg/decode"
|
2022-07-16 19:39:57 +03:00
|
|
|
"github.com/wader/fq/pkg/interp"
|
2021-12-02 00:48:25 +03:00
|
|
|
"github.com/wader/fq/pkg/scalar"
|
2021-11-24 23:20:46 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2022-07-16 19:39:57 +03:00
|
|
|
interp.RegisterFormat(decode.Format{
|
2021-11-24 23:20:46 +03:00
|
|
|
Name: format.ICMP,
|
|
|
|
Description: "Internet Control Message Protocol",
|
2022-04-01 17:31:55 +03:00
|
|
|
Groups: []string{format.IP_PACKET},
|
2021-11-24 23:20:46 +03:00
|
|
|
DecodeFn: decodeICMP,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// based on https://en.wikipedia.org/wiki/Internet_Control_Message_Protocol
|
2022-09-30 14:58:23 +03:00
|
|
|
var icmpTypeMap = scalar.UintMap{
|
2021-11-24 23:20:46 +03:00
|
|
|
0: {Sym: "echo_reply", Description: "Echo reply"},
|
|
|
|
3: {Sym: "unreachable", Description: "Destination network unreachable"},
|
|
|
|
4: {Sym: "source_quench", Description: "Source quench (congestion control)"},
|
|
|
|
5: {Sym: "redirect", Description: "Redirect Datagram for the Network"},
|
|
|
|
6: {Description: "Alternate Host Address"},
|
|
|
|
8: {Sym: "echo_request", Description: "Echo request"},
|
|
|
|
9: {Sym: "router_advertisement", Description: "Router Advertisement"},
|
|
|
|
10: {Sym: "router_solicitation", Description: "Router discovery/selection/solicitation"},
|
|
|
|
11: {Sym: "time_exceeded", Description: "TTL expired in transit"},
|
|
|
|
12: {Sym: "parameter_problem", Description: "Pointer indicates the error"},
|
|
|
|
13: {Sym: "timestamp", Description: "Timestamp"},
|
|
|
|
14: {Sym: "timestamp_reply", Description: "Timestamp reply"},
|
|
|
|
15: {Sym: "information_request", Description: "Information Request"},
|
|
|
|
16: {Sym: "information_reply", Description: "Information Reply"},
|
|
|
|
17: {Sym: "address_mask_request", Description: "Address Mask Request"},
|
|
|
|
18: {Sym: "address_mask_reply", Description: "Address Mask Reply"},
|
|
|
|
30: {Sym: "traceroute", Description: "Information Request"},
|
|
|
|
31: {Description: "Datagram Conversion Error"},
|
|
|
|
32: {Description: "Mobile Host Redirect"},
|
|
|
|
33: {Description: "Where-Are-You (originally meant for IPv6)"},
|
|
|
|
34: {Description: "Here-I-Am (originally meant for IPv6)"},
|
|
|
|
35: {Description: "Mobile Registration Request"},
|
|
|
|
36: {Description: "Mobile Registration Reply"},
|
|
|
|
37: {Description: "Domain Name Request"},
|
|
|
|
38: {Description: "Domain Name Reply"},
|
|
|
|
39: {Description: "Simple Key-Management for Internet Protocol"},
|
|
|
|
40: {Sym: "photuris"},
|
|
|
|
41: {Description: "Experimental icmp for experimental mobility protocols"},
|
|
|
|
42: {Sym: "extended_echo_request", Description: "Request Extended Echo"},
|
|
|
|
43: {Sym: "extended_echo_reply", Description: "No Error"},
|
|
|
|
}
|
|
|
|
|
2022-09-30 14:58:23 +03:00
|
|
|
var icmpCodeMapMap = map[uint64]scalar.UintMapDescription{
|
2021-11-24 23:20:46 +03:00
|
|
|
3: {
|
2022-04-07 19:25:23 +03:00
|
|
|
1: "Destination host unreachable",
|
|
|
|
2: "Destination protocol unreachable",
|
|
|
|
3: "Destination port unreachable",
|
|
|
|
4: "Fragmentation required, and DF flag set",
|
|
|
|
5: "Source route failed",
|
|
|
|
6: "Destination network unknown",
|
|
|
|
7: "Destination host unknown",
|
|
|
|
8: "Source host isolated",
|
|
|
|
9: "Network administratively prohibited",
|
|
|
|
10: "Host administratively prohibited",
|
|
|
|
11: "Network unreachable for ToS",
|
|
|
|
12: "Host unreachable for ToS",
|
|
|
|
13: "Communication administratively prohibited",
|
|
|
|
14: "Host Precedence Violation",
|
|
|
|
15: "Precedence cutoff in effect",
|
2021-11-24 23:20:46 +03:00
|
|
|
},
|
|
|
|
5: {
|
2022-04-07 19:25:23 +03:00
|
|
|
0: "Redirect Datagram for the Network",
|
|
|
|
1: "Redirect Datagram for the Host",
|
|
|
|
2: "Redirect Datagram for the ToS & network",
|
|
|
|
3: "Redirect Datagram for the ToS & host",
|
2021-11-24 23:20:46 +03:00
|
|
|
},
|
|
|
|
11: {
|
2022-04-07 19:25:23 +03:00
|
|
|
0: "TTL expired in transit",
|
|
|
|
1: "Fragment reassembly time exceeded",
|
2021-11-24 23:20:46 +03:00
|
|
|
},
|
|
|
|
12: {
|
2022-04-07 19:25:23 +03:00
|
|
|
0: "Pointer indicates the error",
|
|
|
|
1: "Missing a required option",
|
|
|
|
2: "Bad length",
|
2021-11-24 23:20:46 +03:00
|
|
|
},
|
|
|
|
43: {
|
2022-04-07 19:25:23 +03:00
|
|
|
0: "No Error",
|
|
|
|
1: "Malformed Query",
|
|
|
|
2: "No Such Interface",
|
|
|
|
3: "No Such Table Entry",
|
|
|
|
4: "Multiple Interfaces Satisfy Query",
|
2021-11-24 23:20:46 +03:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-05-20 16:10:41 +03:00
|
|
|
func decodeICMP(d *decode.D, in any) any {
|
2022-04-01 17:31:55 +03:00
|
|
|
if ipi, ok := in.(format.IPPacketIn); ok && ipi.Protocol != format.IPv4ProtocolICMP {
|
|
|
|
d.Fatalf("incorrect protocol %d", ipi.Protocol)
|
|
|
|
}
|
|
|
|
|
2021-12-02 00:48:25 +03:00
|
|
|
typ := d.FieldU8("type", icmpTypeMap)
|
|
|
|
d.FieldU8("code", icmpCodeMapMap[typ])
|
2021-11-24 23:20:46 +03:00
|
|
|
d.FieldU16("checksum")
|
|
|
|
d.FieldRawLen("content", d.BitsLeft())
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|