mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Use 1 fragmentation component per IP stack
This will help manage memory consumption by IP reassembly when receiving IP fragments on multiple network endpoints. Previously, each endpoint would cap memory consumption at 4MB, but with this change, each IP stack will cap memory consumption at 4MB. No behaviour changes. PiperOrigin-RevId: 324913904
This commit is contained in:
committed by
gVisor bot
parent
0500f84b6f
commit
00993130e5
@@ -52,27 +52,25 @@ const (
|
||||
)
|
||||
|
||||
type endpoint struct {
|
||||
nicID tcpip.NICID
|
||||
id stack.NetworkEndpointID
|
||||
prefixLen int
|
||||
linkEP stack.LinkEndpoint
|
||||
dispatcher stack.TransportDispatcher
|
||||
fragmentation *fragmentation.Fragmentation
|
||||
protocol *protocol
|
||||
stack *stack.Stack
|
||||
nicID tcpip.NICID
|
||||
id stack.NetworkEndpointID
|
||||
prefixLen int
|
||||
linkEP stack.LinkEndpoint
|
||||
dispatcher stack.TransportDispatcher
|
||||
protocol *protocol
|
||||
stack *stack.Stack
|
||||
}
|
||||
|
||||
// NewEndpoint creates a new ipv4 endpoint.
|
||||
func (p *protocol) NewEndpoint(nicID tcpip.NICID, addrWithPrefix tcpip.AddressWithPrefix, linkAddrCache stack.LinkAddressCache, dispatcher stack.TransportDispatcher, linkEP stack.LinkEndpoint, st *stack.Stack) (stack.NetworkEndpoint, *tcpip.Error) {
|
||||
e := &endpoint{
|
||||
nicID: nicID,
|
||||
id: stack.NetworkEndpointID{LocalAddress: addrWithPrefix.Address},
|
||||
prefixLen: addrWithPrefix.PrefixLen,
|
||||
linkEP: linkEP,
|
||||
dispatcher: dispatcher,
|
||||
fragmentation: fragmentation.NewFragmentation(fragmentblockSize, fragmentation.HighFragThreshold, fragmentation.LowFragThreshold, fragmentation.DefaultReassembleTimeout),
|
||||
protocol: p,
|
||||
stack: st,
|
||||
nicID: nicID,
|
||||
id: stack.NetworkEndpointID{LocalAddress: addrWithPrefix.Address},
|
||||
prefixLen: addrWithPrefix.PrefixLen,
|
||||
linkEP: linkEP,
|
||||
dispatcher: dispatcher,
|
||||
protocol: p,
|
||||
stack: st,
|
||||
}
|
||||
|
||||
return e, nil
|
||||
@@ -442,7 +440,9 @@ func (e *endpoint) HandlePacket(r *stack.Route, pkt *stack.PacketBuffer) {
|
||||
}
|
||||
var ready bool
|
||||
var err error
|
||||
pkt.Data, ready, err = e.fragmentation.Process(
|
||||
pkt.Data, ready, err = e.protocol.fragmentation.Process(
|
||||
// As per RFC 791 section 2.3, the identification value is unique
|
||||
// for a source-destination pair and protocol.
|
||||
fragmentation.FragmentID{
|
||||
Source: h.SourceAddress(),
|
||||
Destination: h.DestinationAddress(),
|
||||
@@ -484,6 +484,8 @@ type protocol struct {
|
||||
// uint8 portion of it is meaningful and it must be accessed
|
||||
// atomically.
|
||||
defaultTTL uint32
|
||||
|
||||
fragmentation *fragmentation.Fragmentation
|
||||
}
|
||||
|
||||
// Number returns the ipv4 protocol number.
|
||||
@@ -605,5 +607,10 @@ func NewProtocol() stack.NetworkProtocol {
|
||||
}
|
||||
hashIV := r[buckets]
|
||||
|
||||
return &protocol{ids: ids, hashIV: hashIV, defaultTTL: DefaultTTL}
|
||||
return &protocol{
|
||||
ids: ids,
|
||||
hashIV: hashIV,
|
||||
defaultTTL: DefaultTTL,
|
||||
fragmentation: fragmentation.NewFragmentation(fragmentblockSize, fragmentation.HighFragThreshold, fragmentation.LowFragThreshold, fragmentation.DefaultReassembleTimeout),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,6 @@ type endpoint struct {
|
||||
linkEP stack.LinkEndpoint
|
||||
linkAddrCache stack.LinkAddressCache
|
||||
dispatcher stack.TransportDispatcher
|
||||
fragmentation *fragmentation.Fragmentation
|
||||
protocol *protocol
|
||||
}
|
||||
|
||||
@@ -342,7 +341,7 @@ func (e *endpoint) HandlePacket(r *stack.Route, pkt *stack.PacketBuffer) {
|
||||
var ready bool
|
||||
// Note that pkt doesn't have its transport header set after reassembly,
|
||||
// and won't until DeliverNetworkPacket sets it.
|
||||
pkt.Data, ready, err = e.fragmentation.Process(
|
||||
pkt.Data, ready, err = e.protocol.fragmentation.Process(
|
||||
// IPv6 ignores the Protocol field since the ID only needs to be unique
|
||||
// across source-destination pairs, as per RFC 8200 section 4.5.
|
||||
fragmentation.FragmentID{
|
||||
@@ -445,7 +444,8 @@ type protocol struct {
|
||||
// defaultTTL is the current default TTL for the protocol. Only the
|
||||
// uint8 portion of it is meaningful and it must be accessed
|
||||
// atomically.
|
||||
defaultTTL uint32
|
||||
defaultTTL uint32
|
||||
fragmentation *fragmentation.Fragmentation
|
||||
}
|
||||
|
||||
// Number returns the ipv6 protocol number.
|
||||
@@ -478,7 +478,6 @@ func (p *protocol) NewEndpoint(nicID tcpip.NICID, addrWithPrefix tcpip.AddressWi
|
||||
linkEP: linkEP,
|
||||
linkAddrCache: linkAddrCache,
|
||||
dispatcher: dispatcher,
|
||||
fragmentation: fragmentation.NewFragmentation(header.IPv6FragmentExtHdrFragmentOffsetBytesPerUnit, fragmentation.HighFragThreshold, fragmentation.LowFragThreshold, fragmentation.DefaultReassembleTimeout),
|
||||
protocol: p,
|
||||
}, nil
|
||||
}
|
||||
@@ -606,5 +605,8 @@ func calculateMTU(mtu uint32) uint32 {
|
||||
|
||||
// NewProtocol returns an IPv6 network protocol.
|
||||
func NewProtocol() stack.NetworkProtocol {
|
||||
return &protocol{defaultTTL: DefaultTTL}
|
||||
return &protocol{
|
||||
defaultTTL: DefaultTTL,
|
||||
fragmentation: fragmentation.NewFragmentation(header.IPv6FragmentExtHdrFragmentOffsetBytesPerUnit, fragmentation.HighFragThreshold, fragmentation.LowFragThreshold, fragmentation.DefaultReassembleTimeout),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user