mirror of
https://github.com/soypat/lneto.git
synced 2026-08-19 22:24:03 +00:00
remove legacy remnants and move ip,udp,ethernet logic into subpackages
This commit is contained in:
+14
-8
@@ -9,14 +9,6 @@ import (
|
||||
"github.com/soypat/lneto/lneto2"
|
||||
)
|
||||
|
||||
var (
|
||||
errShortTCP = errors.New("TCP offset exceeds frame")
|
||||
errBadTCPOff = errors.New("TCP offset invalid")
|
||||
errEvilPacket = errors.New("evil packet")
|
||||
errZeroDstPort = errors.New("TCP zero destination port")
|
||||
errZeroSrcPort = errors.New("TCP zero source port")
|
||||
)
|
||||
|
||||
const (
|
||||
sizeHeaderTCP = 20
|
||||
)
|
||||
@@ -148,6 +140,12 @@ func (tfrm Frame) Segment(payloadSize int) Segment {
|
||||
}
|
||||
}
|
||||
|
||||
func (tfrm Frame) CRCWrite(crc *lneto2.CRC791) {
|
||||
// Write excluding CRC
|
||||
crc.Write(tfrm.buf[:16])
|
||||
crc.Write(tfrm.buf[18:])
|
||||
}
|
||||
|
||||
// SetSegment sets the sequence, acknowledgment, offset, window and flag fields of the TCP header from the the [Segment].
|
||||
// Offset, like in [Frame.SetOffset], is expressed in words with minimum being 5.
|
||||
func (tfrm Frame) SetSegment(seg Segment, offset uint8) {
|
||||
@@ -184,6 +182,14 @@ func (tfrm Frame) String() string {
|
||||
// Validation API
|
||||
//
|
||||
|
||||
var (
|
||||
errShortTCP = errors.New("TCP offset exceeds frame")
|
||||
errBadTCPOff = errors.New("TCP offset invalid")
|
||||
errEvilPacket = errors.New("evil packet")
|
||||
errZeroDstPort = errors.New("TCP zero destination port")
|
||||
errZeroSrcPort = errors.New("TCP zero source port")
|
||||
)
|
||||
|
||||
// func (tfrm Frame) Validate(v *lneto2.Validator) {
|
||||
// tfrm.ValidateSize(v)
|
||||
// tfrm.ValidateExceptCRC(v)
|
||||
|
||||
+8
-6
@@ -5,7 +5,9 @@ import (
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"github.com/soypat/lneto"
|
||||
"github.com/soypat/lneto/ethernet"
|
||||
"github.com/soypat/lneto/ipv4"
|
||||
"github.com/soypat/lneto/lneto2"
|
||||
"github.com/soypat/lneto/tcp"
|
||||
)
|
||||
|
||||
@@ -584,20 +586,20 @@ func TestExchange_helloworld_client(t *testing.T) {
|
||||
}
|
||||
|
||||
func parseSegment(t *testing.T, b []byte) (tcp.Segment, []byte) {
|
||||
var vld lneto.Validator
|
||||
var vld lneto2.Validator
|
||||
t.Helper()
|
||||
efrm, err := lneto.NewEthFrame(b)
|
||||
efrm, err := ethernet.NewFrame(b)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if efrm.EtherTypeOrSize() != lneto.EtherTypeIPv4 {
|
||||
if efrm.EtherTypeOrSize() != ethernet.TypeIPv4 {
|
||||
t.Fatalf("not IPv4")
|
||||
}
|
||||
efrm.ValidateSize(&vld)
|
||||
if err := vld.Err(); err != nil {
|
||||
t.Fatal(vld.Err())
|
||||
}
|
||||
ifrm, err := lneto.NewIPv4Frame(efrm.Payload())
|
||||
ifrm, err := ipv4.NewFrame(efrm.Payload())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -614,7 +616,7 @@ func parseSegment(t *testing.T, b []byte) (tcp.Segment, []byte) {
|
||||
}
|
||||
|
||||
ipl := ifrm.Payload()
|
||||
tfrm, err := lneto.NewTCPFrame(ipl)
|
||||
tfrm, err := tcp.NewFrame(ipl)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user