diff options
author | David Gibson <david@gibson.dropbear.id.au> | 2024-07-17 14:52:18 +1000 |
---|---|---|
committer | Stefano Brivio <sbrivio@redhat.com> | 2024-07-17 15:27:27 +0200 |
commit | 9b125e7776333326b91adfc4cfd54298737004cd (patch) | |
tree | 39ce4a14dacb89248652fdb7f0e7f1bfc7446a25 /icmp.c | |
parent | 2fa91ee391b7bbed960bf404a405573c64d836aa (diff) | |
download | passt-9b125e7776333326b91adfc4cfd54298737004cd.tar passt-9b125e7776333326b91adfc4cfd54298737004cd.tar.gz passt-9b125e7776333326b91adfc4cfd54298737004cd.tar.bz2 passt-9b125e7776333326b91adfc4cfd54298737004cd.tar.lz passt-9b125e7776333326b91adfc4cfd54298737004cd.tar.xz passt-9b125e7776333326b91adfc4cfd54298737004cd.tar.zst passt-9b125e7776333326b91adfc4cfd54298737004cd.zip |
flow, icmp, tcp: Clean up helpers for getting flow from index
TCP (both regular and spliced) and ICMP both have macros to retrieve the
relevant protcol specific flow structure from a flow index. In most cases
what we actually want is to get the specific flow from a sidx. Replace
those simple macros with a more precise inline, which also asserts that
the flow is of the type we expect.
While we're they're also add a pif_at_sidx() helper to get the interface of
a specific flow & side, which is useful in some places.
Finally, fix some minor style issues in the comments on some of the
existing sidx related helpers.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'icmp.c')
-rw-r--r-- | icmp.c | 22 |
1 files changed, 19 insertions, 3 deletions
@@ -45,19 +45,35 @@ #define ICMP_ECHO_TIMEOUT 60 /* s, timeout for ICMP socket activity */ #define ICMP_NUM_IDS (1U << 16) -#define PINGF(idx) (&(FLOW(idx)->ping)) - /* Indexed by ICMP echo identifier */ static struct icmp_ping_flow *icmp_id_map[IP_VERSIONS][ICMP_NUM_IDS]; /** + * ping_at_sidx() - Get ping specific flow at given sidx + * @sidx: Flow and side to retrieve + * + * Return: ping specific flow at @sidx, or NULL of @sidx is invalid. Asserts if + * the flow at @sidx is not FLOW_PING4 or FLOW_PING6 + */ +static struct icmp_ping_flow *ping_at_sidx(flow_sidx_t sidx) +{ + union flow *flow = flow_at_sidx(sidx); + + if (!flow) + return NULL; + + ASSERT(flow->f.type == FLOW_PING4 || flow->f.type == FLOW_PING6); + return &flow->ping; +} + +/** * icmp_sock_handler() - Handle new data from ICMP or ICMPv6 socket * @c: Execution context * @ref: epoll reference */ void icmp_sock_handler(const struct ctx *c, union epoll_ref ref) { - struct icmp_ping_flow *pingf = PINGF(ref.flowside.flow); + struct icmp_ping_flow *pingf = ping_at_sidx(ref.flowside); union sockaddr_inany sr; socklen_t sl = sizeof(sr); char buf[USHRT_MAX]; |