mirror of
https://github.com/soypat/lneto.git
synced 2026-08-11 10:23:47 +00:00
push last night work
This commit is contained in:
+3
-3
@@ -8,8 +8,8 @@ type IPProto uint8
|
||||
// IP protocol numbers.
|
||||
const (
|
||||
IPProtoHopByHop IPProto = 0 // IPv6 Hop-by-Hop Option [RFC8200]
|
||||
IPProtoICMP IPProto = 1 // Internet Control Message [RFC792]
|
||||
IPProtoIGMP IPProto = 2 // Internet Group Management [RFC1112]
|
||||
IPProtoICMP IPProto = 1 // ICMP [RFC792]
|
||||
IPProtoIGMP IPProto = 2 // IGMP [RFC1112]
|
||||
IPProtoGGP IPProto = 3 // Gateway-to-Gateway [RFC823]
|
||||
IPProtoIPv4 IPProto = 4 // IPv4 encapsulation [RFC2003]
|
||||
IPProtoST IPProto = 5 // Stream [RFC1190, RFC1819]
|
||||
@@ -138,7 +138,7 @@ const (
|
||||
IPProtoFC IPProto = 133 // Fibre Channel
|
||||
IPProtoRSVP_E2E_IGNORE IPProto = 134 // RSVP-E2E-IGNORE
|
||||
IPProtoMobilityHeader IPProto = 135 // Mobility Header
|
||||
IPProtoUDPLite IPProto = 136 // UDPLite
|
||||
IPProtoUDPLite IPProto = 136 // UDP-Lite [RFC3828]
|
||||
IPProtoMPLSInIP IPProto = 137 // MPLS-in-IP
|
||||
IPProtoMANET IPProto = 138 // MANET Protocols
|
||||
IPProtoHIP IPProto = 139 // Host Identity Protocol
|
||||
|
||||
+96
-11
@@ -141,7 +141,32 @@ func (pc *PacketBreakdown) CaptureIPv6(dst []Frame, pkt []byte, bitOffset int) (
|
||||
dst = append(dst, finfo)
|
||||
proto := ifrm6.NextHeader()
|
||||
end := bitOffset + 40*octet
|
||||
return pc.captureIPProto(proto, dst, pkt, end)
|
||||
var protoErrs []error
|
||||
var crc lneto.CRC791
|
||||
if proto == lneto.IPProtoTCP {
|
||||
ifrm6.CRCWritePseudo(&crc)
|
||||
tfrm, err := tcp.NewFrame(ifrm6.Payload())
|
||||
if err == nil {
|
||||
tfrm.CRCWrite(&crc)
|
||||
wantSum := crc.Sum16()
|
||||
gotSum := tfrm.CRC()
|
||||
if wantSum != gotSum {
|
||||
protoErrs = append(protoErrs, &crcError16{protocol: "ipv6+tcp", want: wantSum, got: gotSum})
|
||||
}
|
||||
}
|
||||
} else if proto == lneto.IPProtoUDP || proto == lneto.IPProtoUDPLite {
|
||||
ifrm6.CRCWritePseudo(&crc)
|
||||
ufrm, err := udp.NewFrame(ifrm6.Payload())
|
||||
if err == nil {
|
||||
ufrm.CRCWriteIPv6(&crc)
|
||||
wantSum := crc.Sum16()
|
||||
gotSum := ufrm.CRC()
|
||||
if wantSum != gotSum {
|
||||
protoErrs = append(protoErrs, &crcError16{protocol: "ipv6+udp", want: wantSum, got: gotSum})
|
||||
}
|
||||
}
|
||||
}
|
||||
return pc.captureIPProto(proto, dst, pkt, end, protoErrs...)
|
||||
}
|
||||
|
||||
func (pc *PacketBreakdown) CaptureIPv4(dst []Frame, pkt []byte, bitOffset int) ([]Frame, error) {
|
||||
@@ -169,21 +194,61 @@ func (pc *PacketBreakdown) CaptureIPv4(dst []Frame, pkt []byte, bitOffset int) (
|
||||
BitLength: octet * len(options),
|
||||
})
|
||||
}
|
||||
proto := ifrm4.Protocol()
|
||||
gotSum := ifrm4.CRC()
|
||||
wantSum := ifrm4.CalculateHeaderCRC()
|
||||
if gotSum != wantSum {
|
||||
finfo.Errors = append(finfo.Errors, &crcError16{protocol: "ipv4", want: wantSum, got: gotSum})
|
||||
}
|
||||
dst = append(dst, finfo)
|
||||
proto := ifrm4.Protocol()
|
||||
end := bitOffset + octet*ifrm4.HeaderLength()
|
||||
return pc.captureIPProto(proto, dst, pkt, end)
|
||||
var protoErrs []error
|
||||
var crc lneto.CRC791
|
||||
if proto == lneto.IPProtoTCP {
|
||||
ifrm4.CRCWriteTCPPseudo(&crc)
|
||||
tfrm, err := tcp.NewFrame(ifrm4.Payload())
|
||||
if err == nil {
|
||||
tfrm.CRCWrite(&crc)
|
||||
wantSum := crc.Sum16()
|
||||
gotSum := tfrm.CRC()
|
||||
if wantSum != gotSum {
|
||||
protoErrs = append(protoErrs, &crcError16{protocol: "ipv4+tcp", want: wantSum, got: gotSum})
|
||||
}
|
||||
}
|
||||
} else if proto == lneto.IPProtoUDP || proto == lneto.IPProtoUDPLite {
|
||||
ifrm4.CRCWriteUDPPseudo(&crc)
|
||||
ufrm, err := udp.NewFrame(ifrm4.Payload())
|
||||
if err == nil {
|
||||
ufrm.CRCWriteIPv4(&crc)
|
||||
wantSum := crc.Sum16()
|
||||
gotSum := ufrm.CRC()
|
||||
if wantSum != gotSum {
|
||||
protoErrs = append(protoErrs, &crcError16{protocol: "ipv4+udp", want: wantSum, got: gotSum})
|
||||
}
|
||||
}
|
||||
}
|
||||
return pc.captureIPProto(proto, dst, pkt, end, protoErrs...)
|
||||
|
||||
}
|
||||
|
||||
func (pc *PacketBreakdown) captureIPProto(proto lneto.IPProto, dst []Frame, pkt []byte, bitOffset int) (_ []Frame, err error) {
|
||||
func (pc *PacketBreakdown) captureIPProto(proto lneto.IPProto, dst []Frame, pkt []byte, bitOffset int, ipProtoErrs ...error) (_ []Frame, err error) {
|
||||
nextFrame := len(dst)
|
||||
switch proto {
|
||||
case lneto.IPProtoTCP:
|
||||
dst, err = pc.CaptureTCP(dst, pkt, bitOffset)
|
||||
case lneto.IPProtoUDP:
|
||||
dst, err = pc.CaptureUDP(dst, pkt, bitOffset)
|
||||
case lneto.IPProtoUDPLite:
|
||||
dst, err = pc.CaptureUDP(dst, pkt, bitOffset)
|
||||
if len(dst) > nextFrame {
|
||||
dst[nextFrame].Protocol = lneto.IPProtoUDPLite
|
||||
}
|
||||
default:
|
||||
dst = append(dst, remainingFrameInfo(proto, 0, bitOffset, octet*len(pkt)))
|
||||
}
|
||||
if len(ipProtoErrs) > 0 && len(dst) > nextFrame {
|
||||
dst[nextFrame].Errors = append(dst[nextFrame].Errors, ipProtoErrs...)
|
||||
}
|
||||
return dst, err
|
||||
}
|
||||
|
||||
@@ -303,6 +368,7 @@ type Frame struct {
|
||||
Protocol any
|
||||
Fields []FrameField
|
||||
PacketBitOffset int
|
||||
Errors []error
|
||||
}
|
||||
|
||||
// FieldByClass gets the frame field index with the argument FieldClass Class field set.
|
||||
@@ -414,16 +480,25 @@ func (frm Frame) AppendField(dst []byte, fieldIdx int, pkt []byte) ([]byte, erro
|
||||
}
|
||||
|
||||
func (frm Frame) String() string {
|
||||
iopt, err := frm.FieldByClass(FieldClassOptions)
|
||||
hasOpts := ""
|
||||
if err == nil {
|
||||
hasOpts = fmt.Sprintf(" optlen=%d", (frm.Fields[iopt].BitLength+7)/8)
|
||||
}
|
||||
return string(frm.AppendString(nil))
|
||||
}
|
||||
|
||||
func (frm Frame) AppendString(b []byte) []byte {
|
||||
bitlen := frm.LenBits()
|
||||
b = fmt.Appendf(b, "%s", frm.Protocol)
|
||||
if bitlen%8 == 0 {
|
||||
return fmt.Sprintf("%s len=%d%s", frm.Protocol, bitlen/8, hasOpts)
|
||||
b = fmt.Appendf(b, " len=%d", bitlen/8)
|
||||
} else {
|
||||
b = fmt.Appendf(b, " bits=%d", bitlen)
|
||||
}
|
||||
return fmt.Sprintf("%s bits=%d%s", frm.Protocol, bitlen, hasOpts)
|
||||
iopt, err := frm.FieldByClass(FieldClassOptions)
|
||||
if err == nil {
|
||||
b = fmt.Appendf(b, " optlen=%d", (frm.Fields[iopt].BitLength+7)/8)
|
||||
}
|
||||
for _, err := range frm.Errors {
|
||||
b = fmt.Appendf(b, " %s", err.Error())
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
func (frm Frame) LenBits() (totalBitlen int) {
|
||||
@@ -722,3 +797,13 @@ func remainingFrameInfo(proto any, class FieldClass, pktBitOffset, pktBitLen int
|
||||
}},
|
||||
}
|
||||
}
|
||||
|
||||
type crcError16 struct {
|
||||
protocol string
|
||||
want uint16
|
||||
got uint16
|
||||
}
|
||||
|
||||
func (cerr *crcError16) Error() string {
|
||||
return fmt.Sprintf("%s:incorrect checksum. want 0x%x, got 0x%x", cerr.protocol, cerr.want, cerr.got)
|
||||
}
|
||||
|
||||
+4
-4
@@ -152,20 +152,20 @@ func _() {
|
||||
}
|
||||
|
||||
const (
|
||||
_IPProto_name_0 = "IPv6 Hop-by-Hop Option [RFC8200]Internet Control Message [RFC792]Internet Group Management [RFC1112]Gateway-to-Gateway [RFC823]IPv4 encapsulation [RFC2003]Stream [RFC1190, RFC1819]TCP [RFC9293]CBT [Ballardie]Exterior Gateway Protocol [RFC888]any private interior gateway (used by Cisco for their IGRP)BBN RCC MonitoringNetwork Voice Protocol [RFC741]PUPARGUSEMCONCross Net DebuggerChaosUDP [RFC768]MultiplexingDCN Measurement SubsystemsHost Monitoring [RFC869]Packet Radio MeasurementXEROX NS IDPTrunk-1Trunk-2Leaf-1Leaf-2Reliable Data Protocol [RFC908]Internet Reliable Transaction [RFC938]ISO Transport Protocol Class 4 [RFC905]Bulk Data Transfer Protocol [RFC998]MFE Network Services ProtocolMERIT Internodal ProtocolDatagram Congestion Control Protocol [RFC4340]Third Party Connect ProtocolInter-Domain Policy Routing ProtocolXTPDatagram Delivery ProtocolIDPR Control Message Transport ProtoTP++ Transport ProtocolIL Transport ProtocolIPv6 encapsulation [RFC2473]Source Demand Routing ProtocolRouting Header for IPv6 [RFC8200]Fragment Header for IPv6 [RFC8200]Inter-Domain Routing ProtocolReservation Protocol [RFC2205]Generic Routing Encapsulation [RFC2784]Dynamic Source Routing ProtocolBNAEncap Security Payload [RFC4303]Authentication Header [RFC4302]Integrated Net Layer Security TUBAIP with EncryptionNBMA Address Resolution ProtocolIP MobilityTransport Layer Security Protocol using Kryptonet key managementSKIPICMP for IPv6 [RFC8200]No Next Header for IPv6 [RFC8200]Destination Options for IPv6 [RFC8200]"
|
||||
_IPProto_name_0 = "IPv6 Hop-by-Hop Option [RFC8200]ICMP [RFC792]IGMP [RFC1112]Gateway-to-Gateway [RFC823]IPv4 encapsulation [RFC2003]Stream [RFC1190, RFC1819]TCP [RFC9293]CBT [Ballardie]Exterior Gateway Protocol [RFC888]any private interior gateway (used by Cisco for their IGRP)BBN RCC MonitoringNetwork Voice Protocol [RFC741]PUPARGUSEMCONCross Net DebuggerChaosUDP [RFC768]MultiplexingDCN Measurement SubsystemsHost Monitoring [RFC869]Packet Radio MeasurementXEROX NS IDPTrunk-1Trunk-2Leaf-1Leaf-2Reliable Data Protocol [RFC908]Internet Reliable Transaction [RFC938]ISO Transport Protocol Class 4 [RFC905]Bulk Data Transfer Protocol [RFC998]MFE Network Services ProtocolMERIT Internodal ProtocolDatagram Congestion Control Protocol [RFC4340]Third Party Connect ProtocolInter-Domain Policy Routing ProtocolXTPDatagram Delivery ProtocolIDPR Control Message Transport ProtoTP++ Transport ProtocolIL Transport ProtocolIPv6 encapsulation [RFC2473]Source Demand Routing ProtocolRouting Header for IPv6 [RFC8200]Fragment Header for IPv6 [RFC8200]Inter-Domain Routing ProtocolReservation Protocol [RFC2205]Generic Routing Encapsulation [RFC2784]Dynamic Source Routing ProtocolBNAEncap Security Payload [RFC4303]Authentication Header [RFC4302]Integrated Net Layer Security TUBAIP with EncryptionNBMA Address Resolution ProtocolIP MobilityTransport Layer Security Protocol using Kryptonet key managementSKIPICMP for IPv6 [RFC8200]No Next Header for IPv6 [RFC8200]Destination Options for IPv6 [RFC8200]"
|
||||
_IPProto_name_1 = "CFTP"
|
||||
_IPProto_name_2 = "SATNET and Backroom EXPAKKryptolanMIT Remote Virtual Disk ProtocolInternet Pluribus Packet Core"
|
||||
_IPProto_name_3 = "SATNET MonitoringVISA ProtocolInternet Packet Core UtilityComputer Protocol Network ExecutiveComputer Protocol Heart BeatWang Span NetworkPacket Video ProtocolBackroom SATNET MonitoringSUN ND PROTOCOL-TemporaryWIDEBAND MonitoringWIDEBAND EXPAKISO Internet ProtocolVMTPSECURE-VMTPVINESTTPNSFNET-IGPDissimilar Gateway ProtocolTCFEIGRPOSPFIGPSprite RPC ProtocolLocus Address Resolution ProtocolMulticast Transport ProtocolAX.25 FramesIP-within-IP Encapsulation ProtocolMobile Internetworking Control Pro.Semaphore Communications Sec. Pro.Ethernet-within-IP EncapsulationEncapsulation Header"
|
||||
_IPProto_name_4 = "GMTPIpsilon Flow Management ProtocolPNNI over IPProtocol Independent MulticastARISSCPSQNXActive NetworksIP Payload Compression ProtocolSitara Networks ProtocolCompaq Peer ProtocolIPX in IPVirtual Router Redundancy ProtocolPGM Reliable Transport Protocol"
|
||||
_IPProto_name_5 = "Layer Two Tunneling Protocol v3D-II Data Exchange (DDX)Interactive Agent Transfer ProtocolSchedule Transfer ProtocolSpectraLink Radio ProtocolUTISimple Message ProtocolSMPerformance Transparency ProtocolISIS over IPv4FIRECombat Radio Transport ProtocolCombat Radio User DatagramSSCOPMCEIPLTSecure Packet ShieldPrivate IP Encapsulation within IPStream Control Transmission ProtocolFibre ChannelRSVP-E2E-IGNOREMobility HeaderUDPLiteMPLS-in-IPMANET ProtocolsHost Identity ProtocolShim6 ProtocolWrapped Encapsulating Security PayloadRobust Header CompressionEthernetAGGFRAG Encapsulation payload for ESPNetwork Service Header"
|
||||
_IPProto_name_5 = "Layer Two Tunneling Protocol v3D-II Data Exchange (DDX)Interactive Agent Transfer ProtocolSchedule Transfer ProtocolSpectraLink Radio ProtocolUTISimple Message ProtocolSMPerformance Transparency ProtocolISIS over IPv4FIRECombat Radio Transport ProtocolCombat Radio User DatagramSSCOPMCEIPLTSecure Packet ShieldPrivate IP Encapsulation within IPStream Control Transmission ProtocolFibre ChannelRSVP-E2E-IGNOREMobility HeaderUDP-Lite [RFC3828]MPLS-in-IPMANET ProtocolsHost Identity ProtocolShim6 ProtocolWrapped Encapsulating Security PayloadRobust Header CompressionEthernetAGGFRAG Encapsulation payload for ESPNetwork Service Header"
|
||||
)
|
||||
|
||||
var (
|
||||
_IPProto_index_0 = [...]uint16{0, 32, 65, 100, 127, 155, 180, 193, 208, 242, 301, 319, 350, 353, 358, 363, 381, 386, 398, 410, 436, 460, 484, 496, 503, 510, 516, 522, 553, 591, 630, 666, 695, 720, 766, 794, 830, 833, 859, 895, 918, 939, 967, 997, 1030, 1064, 1093, 1123, 1162, 1193, 1196, 1228, 1259, 1293, 1311, 1343, 1354, 1418, 1422, 1445, 1478, 1516}
|
||||
_IPProto_index_0 = [...]uint16{0, 32, 45, 59, 86, 114, 139, 152, 167, 201, 260, 278, 309, 312, 317, 322, 340, 345, 357, 369, 395, 419, 443, 455, 462, 469, 475, 481, 512, 550, 589, 625, 654, 679, 725, 753, 789, 792, 818, 854, 877, 898, 926, 956, 989, 1023, 1052, 1082, 1121, 1152, 1155, 1187, 1218, 1252, 1270, 1302, 1313, 1377, 1381, 1404, 1437, 1475}
|
||||
_IPProto_index_2 = [...]uint8{0, 25, 34, 66, 95}
|
||||
_IPProto_index_3 = [...]uint16{0, 17, 30, 58, 93, 121, 138, 159, 185, 210, 229, 243, 264, 268, 279, 284, 287, 297, 324, 327, 332, 339, 358, 391, 419, 431, 466, 501, 535, 567, 587}
|
||||
_IPProto_index_4 = [...]uint8{0, 4, 36, 48, 78, 82, 86, 89, 104, 135, 159, 179, 188, 222, 253}
|
||||
_IPProto_index_5 = [...]uint16{0, 31, 55, 90, 116, 142, 145, 168, 170, 203, 217, 221, 252, 278, 286, 290, 310, 344, 380, 393, 408, 423, 430, 440, 455, 477, 491, 529, 554, 562, 599, 621}
|
||||
_IPProto_index_5 = [...]uint16{0, 31, 55, 90, 116, 142, 145, 168, 170, 203, 217, 221, 252, 278, 286, 290, 310, 344, 380, 393, 408, 423, 441, 451, 466, 488, 502, 540, 565, 573, 610, 632}
|
||||
)
|
||||
|
||||
func (i IPProto) String() string {
|
||||
|
||||
@@ -79,6 +79,21 @@ func (ufrm Frame) Payload() []byte {
|
||||
return ufrm.buf[sizeHeader:l]
|
||||
}
|
||||
|
||||
func (ufrm Frame) CRCWriteIPv4(crc *lneto.CRC791) {
|
||||
crc.AddUint16(ufrm.Length())
|
||||
crc.AddUint16(ufrm.SourcePort())
|
||||
crc.AddUint16(ufrm.DestinationPort())
|
||||
crc.AddUint16(ufrm.Length()) // Length double tap for IPv4.
|
||||
crc.Write(ufrm.Payload())
|
||||
}
|
||||
|
||||
func (ufrm Frame) CRCWriteIPv6(crc *lneto.CRC791) {
|
||||
crc.AddUint16(ufrm.SourcePort())
|
||||
crc.AddUint16(ufrm.DestinationPort())
|
||||
crc.AddUint16(ufrm.Length())
|
||||
crc.Write(ufrm.Payload())
|
||||
}
|
||||
|
||||
// func (ufrm Frame) CalculateIPv4Checksum(ifrm IPv4Frame) uint16 {
|
||||
// var crc lneto.CRC791
|
||||
// ifrm.crcWriteUDPPseudo(&crc)
|
||||
|
||||
Reference in New Issue
Block a user