50 Commits
Author SHA1 Message Date
Andrei VaginandgVisor bot e2e84bf5ba tcpip/link: use lockdep mutexes
PiperOrigin-RevId: 692004573
2024-10-31 18:56:13 -07:00
Andrei VaginandgVisor bot b488752cba netstack: implement RTM_SETLINK/IFLA_NET_NS_FD
IFLA_NET_NS_FD specifies a file descriptor that refers to a network namespace.

PiperOrigin-RevId: 648882826
2024-07-02 16:49:27 -07:00
Jing ChenandgVisor bot 8ef3239b0b Add SetMTU to change the mtu of device.
The method will be primarily used with RTM_[NEW|SET]LINK when IFLA_MTU
is present.

PiperOrigin-RevId: 646264847
2024-06-24 16:58:13 -07:00
Andrei VaginandgVisor bot 646a033213 tcpip: destroy both ends of one veth pair together
PiperOrigin-RevId: 645562424
2024-06-21 18:50:54 -07:00
Jing ChenandgVisor bot 2c5c7869d9 Add SetLinkAddress method to NetworkLinkEndpoint interface.
The method will be primarily used by IFLA_ADDRESS.

PiperOrigin-RevId: 642492748
2024-06-11 21:40:39 -07:00
Nayana BidariandgVisor bot 90266aa28a Netstack S/R: Mark all the structs in netstack as savable.
Marks the structs in netstack as savable. This does not change or break any
existing behavior as the netstack itself is not savable yet.

PiperOrigin-RevId: 635943481
2024-05-21 15:19:07 -07:00
Kevin KrakauerandgVisor bot 5b4fbd06d8 netstack: remove PacketBufferPtr
PacketBufferPtr is leftover from a dead experiment. Just use *PacketBuffer.

PiperOrigin-RevId: 611531815
2024-02-29 11:10:38 -08:00
Ghanan GowripalanandgVisor bot a7d4a785b5 Set LinkHeader for pkts sent by raw packet socket
Previously, when a packet was sent from a raw packet socket, the packet
buffer's link header was left unpopulated and the link header was only
found in the packet buffer's payload. This breaks the expectations of
LinkEndpoints which expect the link layer header to always be populated
when the link requires a header.

PiperOrigin-RevId: 542349445
2023-06-21 13:41:22 -07:00
James Tucker a13a283303 tcpip/link: avoid attempts to deliver packets to nil dispatchers
Fixes #8765
2023-03-30 13:25:02 -07:00
Nicolas LacasseandgVisor bot 13d7bf69d8 Protect Endpoint.dispatcher with an RWMutex.
Many Endpoint implementations had unsafe accesses of dispatcher field.

PiperOrigin-RevId: 502675235
2023-01-17 13:40:04 -08:00
Bruno Dal BoandgVisor bot 2b208ac832 Set PktType for all Ethernet Packets
In preparation for improving ARP handling of gratuitous ARPs, set PktType in
regular inbound flow instead of only when handling packet sockets.

PiperOrigin-RevId: 501562322
2023-01-12 07:43:18 -08:00
Kevin KrakauerandgVisor bot 4eca206fa4 netstack: introduce PacketBufferPtr
PiperOrigin-RevId: 479437464
2022-10-06 16:16:54 -07:00
Ghanan GowripalanandgVisor bot 4fcd3c77ea (Re)introduce packetsocket link endpoint
The packetsocket link endpoint is used to enable a packet endpoint to
receive packets right before they are sent to the driver for outgoing
packets or right after they are recieved from the driver for incoming
packets.

Before this change, only packets that are sent/received by the
`stack.nic` were delivered to packet endpoints. However, the packet
endpoint should also receive packets that don't reach `stack.nic`.
Such an example can be when the interface is bridged and an incoming
packet is sent out through a sibling bridge port instead of being
delivered to a `stack.nic`.

The packetsocket link endpoint must wrap a link endpoint that
populates the link headers for ingress packets. It should ideally
be placed as low in the link endpoint heirarchy as possible so that
packets are probed as close to device drivers as possible.

https://github.com/google/gvisor/commit/2d9b33c0fd7d812a7296cd71f14c03925f815f28
removed the original packetsocket link endpoint which only allowed
low-level capturing of outbound packets but not inbound packets.

The CL mentioned above is cl/395761629.

PiperOrigin-RevId: 424947620
2022-01-28 13:43:55 -08:00
Ghanan GowripalanandgVisor bot f54fcc6e11 Drop LinkEndpoint.WriteRawPacket
PiperOrigin-RevId: 424490855
2022-01-26 18:33:55 -08:00
Ghanan GowripalanandgVisor bot ed2f45ace3 Populate link header from packet buffer fields
The arguments passed to LinkEndpoint.AddHeader are all available in
the packet buffer so just get the values from the packet buffer.

PiperOrigin-RevId: 424463821
2022-01-26 16:10:03 -08:00
Ghanan GowripalanandgVisor bot abd993f608 Don't pass link addresses in rx path
...as they are not used in all cases expect in the packet endpoint
which can get the link address directly from the link header.

PiperOrigin-RevId: 424427195
2022-01-26 13:24:35 -08:00
Ghanan GowripalanandgVisor bot 196baa62ca Don't pass route info and net proto to write fns
...as the packet buffer already holds that information.

Updates #3810.
Fixes #6537.

PiperOrigin-RevId: 421898143
2022-01-14 13:23:22 -08:00
Lucas ManningandgVisor bot e511fc9092 Remove WritePacket from LinkEndpoint.
PiperOrigin-RevId: 418672809
2021-12-28 13:45:13 -08:00
Ghanan GowripalanandgVisor bot 2d9b33c0fd Remove link/packetsocket
This change removes NetworkDispatcher.DeliverOutboundPacket.

Since all packet writes go through the NIC (the only NetworkDispatcher),
we can deliver outgoing packets to interested packet endpoints before
writing the packet to the link endpoint as the stack expects that all
packets that get delivered to a link endpoint are transmitted on the
wire. That is, link endpoints no longer need to let the stack know when
it writes a packet as the stack already knows about the packet it writes
through a link endpoint.

PiperOrigin-RevId: 395761629
2021-09-09 12:34:54 -07:00
Ghanan GowripalanandgVisor bot fbf020d6a0 Add LinkEndpoint.WriteRawPacket with stubs
...returning unsupported errors.

PiperOrigin-RevId: 393388991
2021-08-27 11:15:23 -07:00
Ghanan GowripalanandgVisor bot 47bc115158 Only carry GSO options in the packet buffer
With this change, GSO options no longer needs to be passed around as
a function argument in the write path.

This change is done in preparation for a later change that defers
segmentation, and may change GSO options for a packet as it flows
down the stack.

Updates #170.

PiperOrigin-RevId: 369774872
2021-04-21 18:09:27 -07:00
Jamie LiuandgVisor bot ba4dfa7172 Move //pkg/gate.Gate to //pkg/sync.
- Use atomic add rather than CAS in every Gate method, which is slightly
  faster in most cases.

- Implement Close wakeup using gopark/goready to avoid channel allocation.

New benchmarks:
name                         old time/op  new time/op  delta
GateEnterLeave-12            16.7ns ± 1%  10.3ns ± 1%  -38.44%  (p=0.000 n=9+8)
GateClose-12                 50.2ns ± 8%  42.4ns ± 6%  -15.44%  (p=0.000 n=10+10)
GateEnterLeaveAsyncClose-12   972ns ± 2%   640ns ± 7%  -34.15%  (p=0.000 n=9+10)

PiperOrigin-RevId: 359336344
2021-02-24 11:56:56 -08:00
Tamir DubersteinandgVisor bot 8d1afb4185 Change tcpip.Error to an interface
This makes it possible to add data to types that implement tcpip.Error.
ErrBadLinkEndpoint is removed as it is unused.

PiperOrigin-RevId: 354437314
2021-01-28 17:59:58 -08:00
Ghanan GowripalanandgVisor bot fd5b52c87f Only pass stack.Route's fields to LinkEndpoints
stack.Route is used to send network packets and resolve link addresses.
A LinkEndpoint does not need to do either of these and only needs the
route's fields at the time of the packet write request.

Since LinkEndpoints only need the route's fields when writing packets,
pass a stack.RouteInfo instead.

PiperOrigin-RevId: 352108405
2021-01-15 16:49:15 -08:00
Bruno Dal BoandgVisor bot 9d148627f8 Introduce stack.WritePacketToRemote, remove LinkEndpoint.WriteRawPacket
Redefine stack.WritePacket into stack.WritePacketToRemote which lets the NIC
decide whether to append link headers.

PiperOrigin-RevId: 343071742
2020-11-18 07:05:59 -08:00