func paddedLength(o NDPOption) int {
	l := o.Length()
	if l == 0 {
		return 0
	}
	l += 2
	mask := lengthByteUnits - 1
	l += mask
	l &^= mask
	if l/lengthByteUnits > 255 {
		return 0
	}
	return l
}
paddedLength returns the length of o, in bytes, with any padding bytes, if
required.
package header
import (
	"encoding/binary"
	"errors"
	"time"
	"github.com/google/netstack/tcpip"
)
const (
	NDPTargetLinkLayerAddressOptionType = 2
	ndpTargetEthernetLinkLayerAddressSize = 8
	NDPPrefixInformationType = 3
	ndpPrefixInformationLength = 30
	ndpPrefixInformationPrefixLengthOffset = 0
	ndpPrefixInformationFlagsOffset = 1
	ndpPrefixInformationOnLinkFlagMask = (1 << 7)
	ndpPrefixInformationAutoAddrConfFlagMask = (1 << 6)
	ndpPrefixInformationReserved1FlagsMask = 63
	ndpPrefixInformationValidLifetimeOffset = 2
	ndpPrefixInformationPreferredLifetimeOffset = 6
	ndpPrefixInformationReserved2Offset = 10
	ndpPrefixInformationReserved2Length = 4
	ndpPrefixInformationPrefixOffset = 14
	lengthByteUnits = 8
)
var (
	NDPPrefixInformationInfiniteLifetime = time.Second * 4294967295
)
type NDPOptionIterator struct {
	opts NDPOptions
}
var (
	ErrNDPOptBufExhausted  = errors.New("Buffer unexpectedly exhausted")
	ErrNDPOptZeroLength    = errors.New("NDP option has zero-valued Length field")
	ErrNDPOptMalformedBody = errors.New("NDP option has a malformed body")
)
func (i *NDPOptionIterator) Next() (NDPOption, bool, error) {
	for {
		if len(i.opts) == 0 {
			return nil, true, nil
		}
		if len(i.opts) < lengthByteUnits {
			return nil, true, ErrNDPOptBufExhausted
		}
		t := i.opts[0]
		l := i.opts[1]
		if l == 0 {
			return nil, true, ErrNDPOptZeroLength
		}
		numBytes := int(l) * lengthByteUnits
		numBodyBytes := numBytes - 2
		potentialBody := i.opts[2:]
		if left := len(potentialBody); left < numBodyBytes {
			return nil, true, ErrNDPOptBufExhausted
		}
		body := potentialBody[:numBodyBytes]
		i.opts = i.opts[numBytes:]
		switch t {
		case NDPTargetLinkLayerAddressOptionType:
			return NDPTargetLinkLayerAddressOption(body), false, nil
		case NDPPrefixInformationType:
			if numBodyBytes != ndpPrefixInformationLength {
				return nil, true, ErrNDPOptMalformedBody
			}
			return NDPPrefixInformation(body), false, nil
		default:
		}
	}
}
type NDPOptions []byte
func (b NDPOptions) Iter(check bool) (NDPOptionIterator, error) {
	it := NDPOptionIterator{opts: b}
	if check {
		for it2 := it; true; {
			if _, done, err := it2.Next(); err != nil || done {
				return it, err
			}
		}
	}
	return it, nil
}
func (b NDPOptions) Serialize(s NDPOptionsSerializer) int {
	done := 0
	for _, o := range s {
		l := paddedLength(o)
		if l == 0 {
			continue
		}
		b[0] = o.Type()
		b[1] = uint8(l / lengthByteUnits)
		used := o.serializeInto(b[2:])
		for i := used + 2; i < l; i++ {
			b[i] = 0
		}
		b = b[l:]
		done += l
	}
	return done
}
type NDPOption interface {
	Type() uint8
	Length() int
	serializeInto([]byte) int
}