diff options
-rw-r--r-- | pkg/tcpip/header/ipv4.go | 8 | ||||
-rw-r--r-- | pkg/tcpip/network/ipv4/ipv4.go | 4 | ||||
-rw-r--r-- | pkg/tcpip/stack/registration.go | 4 |
3 files changed, 8 insertions, 8 deletions
diff --git a/pkg/tcpip/header/ipv4.go b/pkg/tcpip/header/ipv4.go index 3d465e28a..713d476d6 100644 --- a/pkg/tcpip/header/ipv4.go +++ b/pkg/tcpip/header/ipv4.go @@ -275,12 +275,12 @@ func (b IPv4) DestinationAddress() tcpip.Address { // IPv4Options is a buffer that holds all the raw IP options. type IPv4Options []byte -// AllocationSize implements stack.NetOptions. +// SizeWithPadding implements stack.NetOptions. // It reports the size to allocate for the Options. RFC 791 page 23 (end of // section 3.1) says of the padding at the end of the options: // The internet header padding is used to ensure that the internet // header ends on a 32 bit boundary. -func (o IPv4Options) AllocationSize() int { +func (o IPv4Options) SizeWithPadding() int { return (len(o) + IPv4IHLStride - 1) & ^(IPv4IHLStride - 1) } @@ -368,8 +368,8 @@ func (b IPv4) Encode(i *IPv4Fields) { // worth a bit of optimisation here to keep the copy out of the fast path. hdrLen := IPv4MinimumSize if len(i.Options) != 0 { - // AllocationSize is always >= len(i.Options). - aLen := i.Options.AllocationSize() + // SizeWithPadding is always >= len(i.Options). + aLen := i.Options.SizeWithPadding() hdrLen += aLen if hdrLen > len(b) { panic(fmt.Sprintf("encode received %d bytes, wanted >= %d", len(b), hdrLen)) diff --git a/pkg/tcpip/network/ipv4/ipv4.go b/pkg/tcpip/network/ipv4/ipv4.go index 0af646df9..0c828004a 100644 --- a/pkg/tcpip/network/ipv4/ipv4.go +++ b/pkg/tcpip/network/ipv4/ipv4.go @@ -206,12 +206,12 @@ func (e *endpoint) addIPHeader(r *stack.Route, pkt *stack.PacketBuffer, params s if opts, ok = params.Options.(header.IPv4Options); !ok { panic(fmt.Sprintf("want IPv4Options, got %T", params.Options)) } - hdrLen += opts.AllocationSize() + hdrLen += opts.SizeWithPadding() if hdrLen > header.IPv4MaximumHeaderSize { // Since we have no way to report an error we must either panic or create // a packet which is different to what was requested. Choose panic as this // would be a programming error that should be caught in testing. - panic(fmt.Sprintf("IPv4 Options %d bytes, Max %d", params.Options.AllocationSize(), header.IPv4MaximumOptionsSize)) + panic(fmt.Sprintf("IPv4 Options %d bytes, Max %d", params.Options.SizeWithPadding(), header.IPv4MaximumOptionsSize)) } } ip := header.IPv4(pkt.NetworkHeader().Push(hdrLen)) diff --git a/pkg/tcpip/stack/registration.go b/pkg/tcpip/stack/registration.go index 1b1603bee..79d024662 100644 --- a/pkg/tcpip/stack/registration.go +++ b/pkg/tcpip/stack/registration.go @@ -262,10 +262,10 @@ const ( // NetOptions is an interface that allows us to pass network protocol specific // options through the Stack layer code. type NetOptions interface { - // AllocationSize returns the amount of memory that must be allocated to + // SizeWithPadding returns the amount of memory that must be allocated to // hold the options given that the value must be rounded up to the next // multiple of 4 bytes. - AllocationSize() int + SizeWithPadding() int } // NetworkHeaderParams are the header parameters given as input by the |