mirror of
https://github.com/soypat/lneto.git
synced 2026-09-10 16:49:37 +00:00
add zero max ports error
This commit is contained in:
@@ -42,6 +42,7 @@ type node struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
errZeroMaxNodes = errors.New("zero max ports")
|
||||||
errZeroPort = errors.New("port must be greater than zero")
|
errZeroPort = errors.New("port must be greater than zero")
|
||||||
errInvalidProto = errors.New("invalid protocol")
|
errInvalidProto = errors.New("invalid protocol")
|
||||||
errProtoRegistered = errors.New("protocol already registered")
|
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 {
|
func (ls *StackEthernet) Reset6(mac, gateway [6]byte, mtu, maxNodes int) error {
|
||||||
if mtu > math.MaxUint16 || mtu < 256 {
|
if mtu > math.MaxUint16 || mtu < 256 {
|
||||||
return errors.New("invalid MTU")
|
return errors.New("invalid MTU")
|
||||||
|
} else if maxNodes <= 0 {
|
||||||
|
return errZeroMaxNodes
|
||||||
}
|
}
|
||||||
ls.handlers = slices.Grow(ls.handlers[:0], maxNodes)
|
ls.handlers = slices.Grow(ls.handlers[:0], maxNodes)
|
||||||
*ls = StackEthernet{
|
*ls = StackEthernet{
|
||||||
|
|||||||
@@ -27,6 +27,9 @@ type StackIP struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (sb *StackIP) Reset(addr netip.Addr, maxNodes int) error {
|
func (sb *StackIP) Reset(addr netip.Addr, maxNodes int) error {
|
||||||
|
if maxNodes <= 0 {
|
||||||
|
return errZeroMaxNodes
|
||||||
|
}
|
||||||
err := sb.SetAddr(addr)
|
err := sb.SetAddr(addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ func (ps *StackPorts) ResetTCP(maxNodes int) error {
|
|||||||
func (ps *StackPorts) Reset(protocol uint64, dstPortOffset uint16, maxNodes int) error {
|
func (ps *StackPorts) Reset(protocol uint64, dstPortOffset uint16, maxNodes int) error {
|
||||||
if protocol > math.MaxUint16 {
|
if protocol > math.MaxUint16 {
|
||||||
return errInvalidProto
|
return errInvalidProto
|
||||||
|
} else if maxNodes <= 0 {
|
||||||
|
return errZeroMaxNodes
|
||||||
}
|
}
|
||||||
ps.handlers = slices.Grow(ps.handlers[:0], maxNodes)
|
ps.handlers = slices.Grow(ps.handlers[:0], maxNodes)
|
||||||
*ps = StackPorts{
|
*ps = StackPorts{
|
||||||
|
|||||||
Reference in New Issue
Block a user