google / google/gvisor

Improve type safety for packet buffer

Open
#4,549 3 comments 0 reactions 0 assignees View on GitHub
area: networking type: cleanup type: enhancement
Dominant language
Go
Stars
19.3k
Forks
2k
Avg merge
3d 5h
Merged PRs (30d)
264

Description

The Packet buffer currently holds only fields that are only set by some layer and then read by layers above it. Lower layers "promise" to never touch upper layers' fields.

E.g. Network layer adds network layer information and transport layer uses that when processing a packet. The link layer never touches those fields.

We should consider improving the type safety of the packet buffer by wrapping lower layer types with a new type that has its layer's information.

E.g.
Instead of
```
struct Packet {
NetworkLayerInfo
LinkLayerInfo

pkt
}
```

We can use
```
struct LinkPacket {
LinkLayerInfo

pkt
}

struct NetworkPacket {
NetworkLayerInfo
LinkLayerInfo

pkt
}
```

An alternative is to wrap lower layer types with another layer's type (LinkPacket in a NetworkPacket) or some other idea.

cc @tamird @hbhasker

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.