()
| 1723 | } |
| 1724 | |
| 1725 | func (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 | // |
no test coverage detected