2022-04-01 17:31:55 +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"
|
2022-04-01 17:31:55 +03:00
|
|
|
"github.com/wader/fq/pkg/scalar"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2023-03-29 01:36:55 +03:00
|
|
|
interp.RegisterFormat(
|
2023-05-01 14:19:04 +03:00
|
|
|
format.ICMPv6,
|
2023-03-29 01:36:55 +03:00
|
|
|
&decode.Format{
|
|
|
|
Description: "Internet Control Message Protocol v6",
|
2023-05-01 14:19:04 +03:00
|
|
|
Groups: []*decode.Group{format.IP_Packet},
|
2023-03-29 01:36:55 +03:00
|
|
|
DecodeFn: decodeICMPv6,
|
|
|
|
})
|
2022-04-01 17:31:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// based on https://en.wikipedia.org/wiki/Internet_Control_Message_Protocol_for_IPv6
|
2022-09-30 14:58:23 +03:00
|
|
|
var icmpv6TypeMap = scalar.UintMap{
|
2022-04-01 17:31:55 +03:00
|
|
|
1: {Sym: "unreachable", Description: "Destination unreachable"},
|
|
|
|
2: {Sym: "too_big", Description: "Packet too big"},
|
|
|
|
3: {Sym: "time_exceeded", Description: "Time exceeded"},
|
|
|
|
4: {Sym: "parameter_problem", Description: "Parameter problem"},
|
|
|
|
100: {Description: "Private experimentation"},
|
|
|
|
101: {Description: "Private experimentation"},
|
|
|
|
127: {Description: "Reserved for expansion of ICMPv6 error messages"},
|
|
|
|
128: {Sym: "echo_reply", Description: "Echo Request"},
|
|
|
|
129: {Sym: "echo_request", Description: "Echo Reply"},
|
|
|
|
130: {Description: "Multicast Listener Query (MLD)"},
|
|
|
|
131: {Description: "Multicast Listener Report (MLD)"},
|
|
|
|
132: {Description: "Multicast Listener Done (MLD)"},
|
|
|
|
133: {Description: "Router Solicitation (NDP)"},
|
|
|
|
134: {Description: "Router Advertisement (NDP)"},
|
|
|
|
135: {Description: "Neighbor Solicitation (NDP)"},
|
|
|
|
136: {Description: "Neighbor Advertisement (NDP)"},
|
|
|
|
137: {Description: "Redirect Message (NDP)"},
|
|
|
|
138: {Description: "Router Renumbering Router Renumbering Command"},
|
|
|
|
139: {Description: "ICMP Node Information Query"},
|
|
|
|
140: {Description: "ICMP Node Information Response"},
|
|
|
|
141: {Description: "Inverse Neighbor Discovery Solicitation Message"},
|
|
|
|
142: {Description: "Inverse Neighbor Discovery Advertisement Message"},
|
|
|
|
143: {Description: "Multicast Listener Discovery (MLDv2) reports (RFC 3810)"},
|
|
|
|
144: {Description: "Home Agent Address Discovery Request Message"},
|
|
|
|
145: {Description: "Home Agent Address Discovery Reply Message"},
|
|
|
|
146: {Description: "Mobile Prefix Solicitation"},
|
|
|
|
147: {Description: "Mobile Prefix Advertisement"},
|
|
|
|
148: {Description: "Certification Path Solicitation (SEND)"},
|
|
|
|
149: {Description: "Certification Path Advertisement (SEND)"},
|
|
|
|
151: {Description: "Multicast Router Advertisement (MRD)"},
|
|
|
|
152: {Description: "Multicast Router Solicitation (MRD)"},
|
|
|
|
153: {Description: "Multicast Router Termination (MRD)"},
|
|
|
|
155: {Description: "RPL Control Message"},
|
|
|
|
200: {Description: "Private experimentation"},
|
|
|
|
201: {Description: "Private experimentation"},
|
|
|
|
255: {Description: "Reserved for expansion of ICMPv6 informational messages"},
|
|
|
|
}
|
|
|
|
|
2022-09-30 14:58:23 +03:00
|
|
|
var icmpv6CodeMapMap = map[uint64]scalar.UintMapDescription{
|
2022-04-01 17:31:55 +03:00
|
|
|
1: {
|
2022-04-07 19:25:23 +03:00
|
|
|
1: "Communication with destination administratively prohibited",
|
|
|
|
2: "Beyond scope of source address",
|
|
|
|
3: "Address unreachable",
|
|
|
|
4: "Port unreachable",
|
|
|
|
5: "Source address failed ingress/egress policy",
|
|
|
|
6: "Reject route to destination",
|
|
|
|
7: "Error in Source Routing Header",
|
2022-04-01 17:31:55 +03:00
|
|
|
},
|
|
|
|
3: {
|
2022-04-07 19:25:23 +03:00
|
|
|
0: "Hop limit exceeded in transit",
|
|
|
|
1: "Fragment reassembly time exceeded",
|
2022-04-01 17:31:55 +03:00
|
|
|
},
|
|
|
|
4: {
|
2022-04-07 19:25:23 +03:00
|
|
|
0: "Erroneous header field encountered",
|
|
|
|
1: "Unrecognized Next Header type encountered",
|
|
|
|
2: "Unrecognized IPv6 option encountered",
|
2022-04-01 17:31:55 +03:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2023-02-18 23:10:48 +03:00
|
|
|
func decodeICMPv6(d *decode.D) any {
|
2023-05-01 14:19:04 +03:00
|
|
|
var ipi format.IP_Packet_In
|
2023-02-18 23:10:48 +03:00
|
|
|
if d.ArgAs(&ipi) && ipi.Protocol != format.IPv4ProtocolICMPv6 {
|
2022-04-01 17:31:55 +03:00
|
|
|
d.Fatalf("incorrect protocol %d", ipi.Protocol)
|
|
|
|
}
|
|
|
|
|
|
|
|
typ := d.FieldU8("type", icmpv6TypeMap)
|
|
|
|
d.FieldU8("code", icmpv6CodeMapMap[typ])
|
|
|
|
d.FieldU16("checksum")
|
|
|
|
d.FieldRawLen("content", d.BitsLeft())
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|