ipv4: Define inet_sk_init_flowi4() and use it in inet_sk_rebuild_header().
authorGuillaume Nault <gnault@redhat.com>
Mon, 16 Dec 2024 17:21:44 +0000 (18:21 +0100)
committerJakub Kicinski <kuba@kernel.org>
Fri, 20 Dec 2024 21:50:09 +0000 (13:50 -0800)
commit1dbdce30f040a87f5aa6a9dbe43be398737f090f
treec171045b99d5d3940b8635e974a32f25867511a2
parent6ed3472173c575cd8aaed6c62eb74f7728404ee6
ipv4: Define inet_sk_init_flowi4() and use it in inet_sk_rebuild_header().

IPv4 code commonly has to initialise a flowi4 structure from an IPv4
socket. This requires looking at potential IPv4 options to set the
proper destination address, call flowi4_init_output() with the correct
set of parameters and run the sk_classify_flow security hook.

Instead of reimplementing these operations in different parts of the
stack, let's define inet_sk_init_flowi4() which does all these
operations.

The first user is inet_sk_rebuild_header(), where inet_sk_init_flowi4()
replaces ip_route_output_ports(). Unlike ip_route_output_ports(), which
sets the flowi4 structure and performs the route lookup in one go,
inet_sk_init_flowi4() only initialises the flow. The route lookup is
then done by ip_route_output_flow(). Decoupling flow initialisation
from route lookup makes this new interface applicable more broadly as
it will allow some users to overwrite specific struct flowi4 members
before the route lookup.

Signed-off-by: Guillaume Nault <gnault@redhat.com>
Link: https://patch.msgid.link/fd416275262b1f518d5abfcef740ce4f4a1a6522.1734357769.git.gnault@redhat.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
include/net/route.h
net/ipv4/af_inet.c