summaryrefslogtreecommitdiffhomepage
path: root/pkg/tcpip/network/ipv4
diff options
context:
space:
mode:
authorgVisor bot <gvisor-bot@google.com>2020-11-11 19:02:45 +0000
committergVisor bot <gvisor-bot@google.com>2020-11-11 19:02:45 +0000
commit60cccae0c7a71b9307061ec66bf074447e9e74a8 (patch)
tree582b44e602e0cc5e630520fdea11301975ea814b /pkg/tcpip/network/ipv4
parentbe78b95d48d788bcb4c5132889350434342b4ae7 (diff)
parent9c4102896d8ffbe6a90b57e7aca85f912dcadd9c (diff)
Merge release-20201030.0-68-g9c4102896 (automated)
Diffstat (limited to 'pkg/tcpip/network/ipv4')
-rw-r--r--pkg/tcpip/network/ipv4/ipv4.go19
1 files changed, 17 insertions, 2 deletions
diff --git a/pkg/tcpip/network/ipv4/ipv4.go b/pkg/tcpip/network/ipv4/ipv4.go
index cfd0c505a..a376cb8ec 100644
--- a/pkg/tcpip/network/ipv4/ipv4.go
+++ b/pkg/tcpip/network/ipv4/ipv4.go
@@ -199,14 +199,28 @@ func (e *endpoint) NetworkProtocolNumber() tcpip.NetworkProtocolNumber {
}
func (e *endpoint) addIPHeader(r *stack.Route, pkt *stack.PacketBuffer, params stack.NetworkHeaderParams) {
- ip := header.IPv4(pkt.NetworkHeader().Push(header.IPv4MinimumSize))
+ hdrLen := header.IPv4MinimumSize
+ var opts header.IPv4Options
+ if params.Options != nil {
+ var ok bool
+ if opts, ok = params.Options.(header.IPv4Options); !ok {
+ panic(fmt.Sprintf("want IPv4Options, got %T", params.Options))
+ }
+ hdrLen += opts.AllocationSize()
+ 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))
+ }
+ }
+ ip := header.IPv4(pkt.NetworkHeader().Push(hdrLen))
length := uint16(pkt.Size())
// RFC 6864 section 4.3 mandates uniqueness of ID values for non-atomic
// datagrams. Since the DF bit is never being set here, all datagrams
// are non-atomic and need an ID.
id := atomic.AddUint32(&e.protocol.ids[hashRoute(r, params.Protocol, e.protocol.hashIV)%buckets], 1)
ip.Encode(&header.IPv4Fields{
- IHL: header.IPv4MinimumSize,
TotalLength: length,
ID: uint16(id),
TTL: params.TTL,
@@ -214,6 +228,7 @@ func (e *endpoint) addIPHeader(r *stack.Route, pkt *stack.PacketBuffer, params s
Protocol: uint8(params.Protocol),
SrcAddr: r.LocalAddress,
DstAddr: r.RemoteAddress,
+ Options: opts,
})
ip.SetChecksum(^ip.CalculateChecksum())
pkt.NetworkProtocolNumber = ProtocolNumber