Skip to content

datapath: Split snat_v{4,6}_process() into two functions (SNAT and rev-SNAT) #19660

@brb

Description

@brb

Split the snat_v{4,6}_process() functions into nat_snat_v{4,6}() and nat_rev_snat_v{4,6}().

The proposed change would not only improve the readability of the datapath code, but also should reduce the verifier complexity of the code path which is responsible for doing the rev-SNAT translations, as no new SNAT mapping needs to be find for this code path (only the lookup in the BPF SNAT map).

After inspecting the bpf/lib/nodeport.h, we have the following code paths which involve the SNAT:

  • to-netdev@bpf_host: the snat_v*_process() is called with NAT_DIR_EGRESS. It is used to SNAT outgoing packets.
  • from-netdev@bpf_host (via nodeport_lb{4,6}()):
    • When a service is not found, the function is called with NAT_DIR_INGRESS. It is used to rev-SNAT incoming packets (e.g., outside => pod, replies from remote service backends).
    • When a service is found, with NAT_DIR_EGRESS. It is used to SNAT a service request to a remote node.

From the above, nat_snat_v*() would be called for NAT_DIR_EGRESS, while nat_rev_snat_v*() for NAT_DIR_INGRESS.

Metadata

Metadata

Assignees

Labels

area/datapathImpacts bpf/ or low-level forwarding details, including map management and monitor messages.kind/cleanupThis includes no functional changes.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions