mirror of
https://github.com/soypat/lneto.git
synced 2026-08-25 00:49:04 +00:00
add FieldClassOperation to pcap and associated formatting changes
This commit is contained in:
@@ -115,7 +115,7 @@ func run() (err error) {
|
|||||||
var cap pcap.PacketBreakdown
|
var cap pcap.PacketBreakdown
|
||||||
var frames []pcap.Frame
|
var frames []pcap.Frame
|
||||||
pf := pcap.Formatter{
|
pf := pcap.Formatter{
|
||||||
FilterClasses: []pcap.FieldClass{pcap.FieldClassFlags, pcap.FieldClassDst, pcap.FieldClassSrc, pcap.FieldClassAddress},
|
FilterClasses: []pcap.FieldClass{pcap.FieldClassFlags, pcap.FieldClassOperation, pcap.FieldClassDst, pcap.FieldClassSrc, pcap.FieldClassAddress},
|
||||||
}
|
}
|
||||||
var pfbuf []byte
|
var pfbuf []byte
|
||||||
logFrames := func(context string, pkt []byte) error {
|
logFrames := func(context string, pkt []byte) error {
|
||||||
@@ -163,12 +163,11 @@ func run() (err error) {
|
|||||||
log.Fatal("groutine read:", err)
|
log.Fatal("groutine read:", err)
|
||||||
} else if nread > 0 {
|
} else if nread > 0 {
|
||||||
err = stack.Demux(buf[:nread], 0)
|
err = stack.Demux(buf[:nread], 0)
|
||||||
if err != nil {
|
if !errors.Is(err, lneto.ErrPacketDrop) {
|
||||||
if !errors.Is(err, lneto.ErrPacketDrop) {
|
// Only skip logging packet in case of dropped packet.
|
||||||
err = logFrames("IN", buf[:nread])
|
err = logFrames("IN", buf[:nread])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("ERR:INLOG", err)
|
log.Println("ERR:INLOG", err)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -670,6 +670,7 @@ const (
|
|||||||
FieldClassAddress // address
|
FieldClassAddress // address
|
||||||
// FieldClassBinaryText represents long stretches of binary data such as BOOTP DHCPv4 field.
|
// FieldClassBinaryText represents long stretches of binary data such as BOOTP DHCPv4 field.
|
||||||
FieldClassBinaryText // binary-text
|
FieldClassBinaryText // binary-text
|
||||||
|
FieldClassOperation // op
|
||||||
)
|
)
|
||||||
|
|
||||||
const octet = 8
|
const octet = 8
|
||||||
@@ -718,8 +719,7 @@ var baseARPFields = [...]FrameField{
|
|||||||
BitLength: 1 * octet,
|
BitLength: 1 * octet,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "Opcode",
|
Class: FieldClassOperation,
|
||||||
Class: FieldClassType,
|
|
||||||
FrameBitOffset: 6 * octet,
|
FrameBitOffset: 6 * octet,
|
||||||
BitLength: 2 * octet,
|
BitLength: 2 * octet,
|
||||||
},
|
},
|
||||||
@@ -924,8 +924,7 @@ var baseUDPFields = [...]FrameField{
|
|||||||
|
|
||||||
var baseDHCPv4Fields = [...]FrameField{
|
var baseDHCPv4Fields = [...]FrameField{
|
||||||
{
|
{
|
||||||
Name: "Opcode",
|
Class: FieldClassOperation,
|
||||||
Class: FieldClassType,
|
|
||||||
FrameBitOffset: 0,
|
FrameBitOffset: 0,
|
||||||
BitLength: 1 * octet,
|
BitLength: 1 * octet,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ func (f *Formatter) formatField(dst []byte, pktStartOff int, field FrameField, p
|
|||||||
dst = hex.AppendEncode(dst, f.buf)
|
dst = hex.AppendEncode(dst, f.buf)
|
||||||
case FieldClassText:
|
case FieldClassText:
|
||||||
dst = strconv.AppendQuote(dst, string(f.buf))
|
dst = strconv.AppendQuote(dst, string(f.buf))
|
||||||
case FieldClassDst, FieldClassSrc, FieldClassSize, FieldClassAddress:
|
case FieldClassDst, FieldClassSrc, FieldClassSize, FieldClassAddress, FieldClassOperation:
|
||||||
// IP, MAC addresses and ports.
|
// IP, MAC addresses and ports.
|
||||||
if field.BitLength <= 16 {
|
if field.BitLength <= 16 {
|
||||||
v, err := fieldAsUint(pkt, fieldBitStart, field.BitLength, field.RightAligned)
|
v, err := fieldAsUint(pkt, fieldBitStart, field.BitLength, field.RightAligned)
|
||||||
|
|||||||
@@ -23,11 +23,12 @@ func _() {
|
|||||||
_ = x[FieldClassText-12]
|
_ = x[FieldClassText-12]
|
||||||
_ = x[FieldClassAddress-13]
|
_ = x[FieldClassAddress-13]
|
||||||
_ = x[FieldClassBinaryText-14]
|
_ = x[FieldClassBinaryText-14]
|
||||||
|
_ = x[FieldClassOperation-15]
|
||||||
}
|
}
|
||||||
|
|
||||||
const _FieldClass_name = "undefinedsourcedestinationprotocolversiontypesizeflagsidentificationchecksumoptionspayloadtextaddressbinary-text"
|
const _FieldClass_name = "undefinedsourcedestinationprotocolversiontypesizeflagsidentificationchecksumoptionspayloadtextaddressbinary-textop"
|
||||||
|
|
||||||
var _FieldClass_index = [...]uint8{0, 9, 15, 26, 34, 41, 45, 49, 54, 68, 76, 83, 90, 94, 101, 112}
|
var _FieldClass_index = [...]uint8{0, 9, 15, 26, 34, 41, 45, 49, 54, 68, 76, 83, 90, 94, 101, 112, 114}
|
||||||
|
|
||||||
func (i FieldClass) String() string {
|
func (i FieldClass) String() string {
|
||||||
if i >= FieldClass(len(_FieldClass_index)-1) {
|
if i >= FieldClass(len(_FieldClass_index)-1) {
|
||||||
|
|||||||
+3
-2
@@ -195,11 +195,12 @@ func _() {
|
|||||||
// Re-run the stringer command to generate them again.
|
// Re-run the stringer command to generate them again.
|
||||||
var x [1]struct{}
|
var x [1]struct{}
|
||||||
_ = x[ErrPacketDrop-1]
|
_ = x[ErrPacketDrop-1]
|
||||||
|
_ = x[ErrBadCRC-2]
|
||||||
}
|
}
|
||||||
|
|
||||||
const _errGeneric_name = "packet dropped"
|
const _errGeneric_name = "packet droppedincorrect checksum"
|
||||||
|
|
||||||
var _errGeneric_index = [...]uint8{0, 14}
|
var _errGeneric_index = [...]uint8{0, 14, 32}
|
||||||
|
|
||||||
func (i errGeneric) String() string {
|
func (i errGeneric) String() string {
|
||||||
i -= 1
|
i -= 1
|
||||||
|
|||||||
+1
-5
@@ -2,7 +2,6 @@ package xnet
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/binary"
|
|
||||||
"errors"
|
"errors"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
@@ -602,8 +601,5 @@ func (tst *tester) getFieldByClassLen(proto any, class pcap.FieldClass, octetLen
|
|||||||
|
|
||||||
func (tst *tester) getARPOperation() arp.Operation {
|
func (tst *tester) getARPOperation() arp.Operation {
|
||||||
tst.t.Helper()
|
tst.t.Helper()
|
||||||
// ARP has 3 FieldClassType fields: Hardware type (0), Protocol type (1), Opcode (2)
|
return arp.Operation(tst.getInt(ethernet.TypeARP, pcap.FieldClassOperation))
|
||||||
// All are 2 bytes, so we need occurrence=2 to get Opcode.
|
|
||||||
data := tst.getFieldByClassLen(ethernet.TypeARP, pcap.FieldClassType, 2, 2)
|
|
||||||
return arp.Operation(binary.BigEndian.Uint16(data))
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user