mirror of
https://github.com/soypat/lneto.git
synced 2026-08-15 12:23:44 +00:00
add zero max ports error
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -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{
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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{
|
||||
|
||||
Reference in New Issue
Block a user