major ARP Handler refactor; DNS improvements; bridge example rework

This commit is contained in:
soypat
2025-07-09 22:49:13 -03:00
parent 70731c2ffa
commit a257becf15
10 changed files with 223 additions and 127 deletions
+10 -15
View File
@@ -24,28 +24,23 @@ func (narp *NodeARP) Protocol() uint64 { return uint64(ethernet.TypeARP) }
func (narp *NodeARP) ConnectionID() *uint64 { return narp.handler.ConnectionID() }
func (narp *NodeARP) Demux(EtherFrame []byte, arpOff int) error {
afrm, err := arp.NewFrame(EtherFrame[arpOff:])
if err != nil {
slog.Error("bad-ARP", slog.String("err", err.Error()))
return nil
}
afrm.ValidateSize(&narp.vld)
if narp.vld.HasError() {
slog.Error("invalid-ARP", slog.String("err", narp.vld.ErrPop().Error()))
return nil
}
return narp.handler.Recv(EtherFrame[arpOff:])
return narp.handler.Demux(EtherFrame, arpOff)
}
func (narp *NodeARP) Encapsulate(EtherFrame []byte, arpOff int) (int, error) {
n, err := narp.handler.Send(EtherFrame[arpOff:])
n, err := narp.handler.Encapsulate(EtherFrame, arpOff)
if err != nil || n == 0 {
return 0, err // end with error.
}
afrm, _ := arp.NewFrame(EtherFrame[arpOff:])
hwaddr, _ := afrm.Target()
efrm, _ := ethernet.NewFrame(EtherFrame)
copy(efrm.DestinationHardwareAddr()[:], hwaddr)
slog.Info("handle", slog.String("out", afrm.String()))
return n, err
}
func (narp *NodeARP) StartQuery(proto []byte) error {
return narp.handler.StartQuery(proto)
}
func (narp *NodeARP) QueryResult(proto []byte) ([]byte, error) {
return narp.handler.QueryResult(proto)
}