Error rewrites (#43)

* pcap: reuse Frame memory

* slog: reduce heap allocations of addresses; also prevent heap alloc of dhcp options in pcap

* dns: heapless improvement; add StackAsync buffer for more heapless operation; start thinking of errors

* errors: begin standardise errors in lneto

* errors: finish standardization of errors

* fix merge issues

* add more lneto errors to rest of package

* format errors.go
This commit is contained in:
Pat Whittingslow
2026-02-28 20:18:27 +01:00
committed by GitHub
parent 3d0bc93cbe
commit fa5ba918bb
38 changed files with 272 additions and 322 deletions
+3 -9
View File
@@ -2,7 +2,6 @@ package ethernet
import (
"encoding/binary"
"errors"
"github.com/soypat/lneto"
)
@@ -13,7 +12,7 @@ import (
// with payload/options of frames to avoid panics.
func NewFrame(buf []byte) (Frame, error) {
if len(buf) < sizeHeaderNoVLAN {
return Frame{buf: nil}, errShort
return Frame{buf: nil}, lneto.ErrShortBuffer
}
return Frame{buf: buf}, nil
}
@@ -115,19 +114,14 @@ func (frm Frame) ClearHeader() {
// Validation API.
//
var (
errShort = errors.New("ethernet: too short")
errShortVLAN = errors.New("ethernet: short VLAN")
)
// ValidateSize checks the frame's size fields and compares with the actual buffer
// the frame. It returns a non-nil error on finding an inconsistency.
func (efrm Frame) ValidateSize(v *lneto.Validator) {
sz := efrm.EtherTypeOrSize()
if sz.IsSize() && len(efrm.buf) < int(sz) {
v.AddError(errShort)
v.AddError(lneto.ErrInvalidLengthField)
}
if sz == TypeVLAN && len(efrm.buf) < 18 {
v.AddError(errShortVLAN)
v.AddError(lneto.ErrShortBuffer)
}
}