add zero max ports error

This commit is contained in:
soypat
2025-07-15 00:57:24 -03:00
parent ad22c61b28
commit 63dc5d1079
4 changed files with 8 additions and 0 deletions
+1
View File
@@ -42,6 +42,7 @@ type node struct {
}
var (
errZeroMaxNodes = errors.New("zero max ports")
errZeroPort = errors.New("port must be greater than zero")
errInvalidProto = errors.New("invalid protocol")
errProtoRegistered = errors.New("protocol already registered")
+2
View File
@@ -36,6 +36,8 @@ func (ls *StackEthernet) HardwareAddr6() [6]byte {
func (ls *StackEthernet) Reset6(mac, gateway [6]byte, mtu, maxNodes int) error {
if mtu > math.MaxUint16 || mtu < 256 {
return errors.New("invalid MTU")
} else if maxNodes <= 0 {
return errZeroMaxNodes
}
ls.handlers = slices.Grow(ls.handlers[:0], maxNodes)
*ls = StackEthernet{
+3
View File
@@ -27,6 +27,9 @@ type StackIP struct {
}
func (sb *StackIP) Reset(addr netip.Addr, maxNodes int) error {
if maxNodes <= 0 {
return errZeroMaxNodes
}
err := sb.SetAddr(addr)
if err != nil {
return err
+2
View File
@@ -27,6 +27,8 @@ func (ps *StackPorts) ResetTCP(maxNodes int) error {
func (ps *StackPorts) Reset(protocol uint64, dstPortOffset uint16, maxNodes int) error {
if protocol > math.MaxUint16 {
return errInvalidProto
} else if maxNodes <= 0 {
return errZeroMaxNodes
}
ps.handlers = slices.Grow(ps.handlers[:0], maxNodes)
*ps = StackPorts{