remove legacy remnants and move ip,udp,ethernet logic into subpackages

This commit is contained in:
soypat
2025-02-20 16:00:55 -03:00
parent 0606a04f45
commit f86bb6f01a
22 changed files with 590 additions and 1885 deletions
+7 -6
View File
@@ -7,6 +7,7 @@ import (
"net"
"net/netip"
"github.com/soypat/lneto/ethernet"
"github.com/soypat/lneto/lneto2"
)
@@ -49,16 +50,16 @@ func (afrm Frame) SetHardware(Type uint16, length uint8) {
afrm.buf[4] = length
}
// Protocol returns the internet protocol type and length. See [lneto2.EtherType].
func (afrm Frame) Protocol() (Type lneto2.EtherType, length uint8) {
Type = lneto2.EtherType(binary.BigEndian.Uint16(afrm.buf[2:4]))
// Protocol returns the internet protocol type and length. See [ethernet.Type].
func (afrm Frame) Protocol() (Type ethernet.Type, length uint8) {
Type = ethernet.Type(binary.BigEndian.Uint16(afrm.buf[2:4]))
return Type, afrm.protolen()
}
func (afrm Frame) protolen() uint8 { return afrm.buf[5] }
// SetProtocol sets the protocol type and length fields of the ARP frame. See [Frame.Protocol] and [lneto2.EtherType].
func (afrm Frame) SetProtocol(Type lneto2.EtherType, length uint8) {
// SetProtocol sets the protocol type and length fields of the ARP frame. See [Frame.Protocol] and [ethernet.Type].
func (afrm Frame) SetProtocol(Type ethernet.Type, length uint8) {
binary.BigEndian.PutUint16(afrm.buf[2:4], uint16(Type))
afrm.buf[5] = length
}
@@ -150,7 +151,7 @@ func (afrm Frame) String() string {
sndhw, sndpt := afrm.Sender()
tgthw, tgtpt := afrm.Target()
var sndstr, tgtstr string
if ptt == lneto2.EtherTypeIPv4 || ptt == lneto2.EtherTypeIPv6 {
if ptt == ethernet.TypeIPv4 || ptt == ethernet.TypeIPv6 {
sender, _ := netip.AddrFromSlice(sndpt)
target, _ := netip.AddrFromSlice(tgtpt)
sndstr = sender.String()
+3 -2
View File
@@ -4,6 +4,7 @@ import (
"bytes"
"errors"
"github.com/soypat/lneto/ethernet"
"github.com/soypat/lneto/lneto2"
)
@@ -11,7 +12,7 @@ type Handler struct {
ourHWAddr []byte
ourProtoAddr []byte
htype uint16
protoType lneto2.EtherType
protoType ethernet.Type
pending [][sizeHeaderv6]byte
queries []queryResult
}
@@ -22,7 +23,7 @@ type HandlerConfig struct {
MaxQueries int
MaxPending int
HardwareType uint16
ProtocolType lneto2.EtherType
ProtocolType ethernet.Type
}
func NewHandler(cfg HandlerConfig) (*Handler, error) {
+3 -3
View File
@@ -5,7 +5,7 @@ import (
"log"
"testing"
"github.com/soypat/lneto/lneto2"
"github.com/soypat/lneto/ethernet"
)
func TestHandler(t *testing.T) {
@@ -15,7 +15,7 @@ func TestHandler(t *testing.T) {
MaxQueries: 1,
MaxPending: 1,
HardwareType: 1,
ProtocolType: lneto2.EtherTypeIPv4,
ProtocolType: ethernet.TypeIPv4,
})
if err != nil {
t.Fatal(err)
@@ -26,7 +26,7 @@ func TestHandler(t *testing.T) {
MaxQueries: 1,
MaxPending: 1,
HardwareType: 1,
ProtocolType: lneto2.EtherTypeIPv4,
ProtocolType: ethernet.TypeIPv4,
})
if err != nil {
t.Fatal(err)