MCPcopy Create free account
hub / github.com/google/gvisor / newEmptySandboxNetworkStack

Method newEmptySandboxNetworkStack

runsc/boot/loader.go:1725–1779  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1723}
1724
1725func (c *sandboxNetstackCreator) newEmptySandboxNetworkStack() (*netstack.Stack, error) {
1726 netProtos := []stack.NetworkProtocolFactory{ipv4.NewProtocol, ipv6.NewProtocol, arp.NewProtocol}
1727 transProtos := []stack.TransportProtocolFactory{
1728 tcp.NewProtocol,
1729 udp.NewProtocol,
1730 icmp.NewProtocol4,
1731 icmp.NewProtocol6,
1732 }
1733 s := netstack.NewStack(stack.New(stack.Options{
1734 NetworkProtocols: netProtos,
1735 TransportProtocols: transProtos,
1736 Clock: c.clock,
1737 Stats: netstack.Metrics,
1738 HandleLocal: true,
1739 // Enable raw sockets for users with sufficient
1740 // privileges.
1741 RawFactory: raw.EndpointFactory{},
1742 AllowPacketEndpointWrite: c.allowPacketEndpointWrite,
1743 AllowLiveTCPMigration: c.allowLiveTCPMigration,
1744 DefaultIPTables: netfilter.DefaultLinuxTables,
1745 }), c.uid.UniqueID())
1746
1747 if nftables.IsNFTablesEnabled() {
1748 s.Stack.SetNFTables(nftables.NewNFTables(c.clock, s.Stack.SecureRNG()))
1749 }
1750
1751 // Enable SACK Recovery.
1752 {
1753 opt := tcpip.TCPSACKEnabled(true)
1754 if err := s.Stack.SetTransportProtocolOption(tcp.ProtocolNumber, &opt); err != nil {
1755 return nil, fmt.Errorf("SetTransportProtocolOption(%d, &%T(%t)): %s", tcp.ProtocolNumber, opt, opt, err)
1756 }
1757 }
1758
1759 // Set default TTLs as required by socket/netstack.
1760 {
1761 opt := tcpip.DefaultTTLOption(netstack.DefaultTTL)
1762 if err := s.Stack.SetNetworkProtocolOption(ipv4.ProtocolNumber, &opt); err != nil {
1763 return nil, fmt.Errorf("SetNetworkProtocolOption(%d, &%T(%d)): %s", ipv4.ProtocolNumber, opt, opt, err)
1764 }
1765 if err := s.Stack.SetNetworkProtocolOption(ipv6.ProtocolNumber, &opt); err != nil {
1766 return nil, fmt.Errorf("SetNetworkProtocolOption(%d, &%T(%d)): %s", ipv6.ProtocolNumber, opt, opt, err)
1767 }
1768 }
1769
1770 // Enable Receive Buffer Auto-Tuning.
1771 {
1772 opt := tcpip.TCPModerateReceiveBufferOption(true)
1773 if err := s.Stack.SetTransportProtocolOption(tcp.ProtocolNumber, &opt); err != nil {
1774 return nil, fmt.Errorf("SetTransportProtocolOption(%d, &%T(%t)): %s", tcp.ProtocolNumber, opt, opt, err)
1775 }
1776 }
1777
1778 return s, nil
1779}
1780
1781// sandboxNetstackCreator implements kernel.NetworkStackCreator.
1782//

Callers 2

newRootNetworkNamespaceFunction · 0.95
CreateStackMethod · 0.95

Calls 13

NewStackFunction · 0.92
NewFunction · 0.92
IsNFTablesEnabledFunction · 0.92
NewNFTablesFunction · 0.92
TCPSACKEnabledTypeAlias · 0.92
DefaultTTLOptionTypeAlias · 0.92
SetNFTablesMethod · 0.80
SecureRNGMethod · 0.80
UniqueIDMethod · 0.65

Tested by

no test coverage detected