Skip to content

Commit 5d21d0a

Browse files
t-8chkuba-moo
authored andcommitted
net: generalize calculation of skb extensions length
Remove the necessity to modify skb_ext_total_length() when new extension types are added. Also reduces the line count a bit. With optimizations enabled the function is folded down to the same constant value as before during compilation. This has been validated on x86 with GCC 6.5.0 and 13.2.1. Also a similar construct has been validated on godbolt.org with GCC 5.1. In any case the compiler has to be able to evaluate the construct at compile-time for the BUILD_BUG_ON() in skb_extensions_init(). Even if not evaluated at compile-time this function would only ever be executed once at run-time, so the overhead would be very minuscule. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Reviewed-by: Simon Horman <horms@kernel.org> Link: https://lore.kernel.org/r/20230823-skb_ext-simplify-v2-1-66e26cd66860@weissschuh.net Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 57ce642 commit 5d21d0a

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

net/core/skbuff.c

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4785,23 +4785,13 @@ static const u8 skb_ext_type_len[] = {
47854785

47864786
static __always_inline unsigned int skb_ext_total_length(void)
47874787
{
4788-
return SKB_EXT_CHUNKSIZEOF(struct skb_ext) +
4789-
#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
4790-
skb_ext_type_len[SKB_EXT_BRIDGE_NF] +
4791-
#endif
4792-
#ifdef CONFIG_XFRM
4793-
skb_ext_type_len[SKB_EXT_SEC_PATH] +
4794-
#endif
4795-
#if IS_ENABLED(CONFIG_NET_TC_SKB_EXT)
4796-
skb_ext_type_len[TC_SKB_EXT] +
4797-
#endif
4798-
#if IS_ENABLED(CONFIG_MPTCP)
4799-
skb_ext_type_len[SKB_EXT_MPTCP] +
4800-
#endif
4801-
#if IS_ENABLED(CONFIG_MCTP_FLOWS)
4802-
skb_ext_type_len[SKB_EXT_MCTP] +
4803-
#endif
4804-
0;
4788+
unsigned int l = SKB_EXT_CHUNKSIZEOF(struct skb_ext);
4789+
int i;
4790+
4791+
for (i = 0; i < ARRAY_SIZE(skb_ext_type_len); i++)
4792+
l += skb_ext_type_len[i];
4793+
4794+
return l;
48054795
}
48064796

48074797
static void skb_extensions_init(void)

0 commit comments

Comments
 (0)