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>
This commit is contained in:
parent
57ce6427e0
commit
5d21d0a65b
|
@ -4785,23 +4785,13 @@ static const u8 skb_ext_type_len[] = {
|
||||||
|
|
||||||
static __always_inline unsigned int skb_ext_total_length(void)
|
static __always_inline unsigned int skb_ext_total_length(void)
|
||||||
{
|
{
|
||||||
return SKB_EXT_CHUNKSIZEOF(struct skb_ext) +
|
unsigned int l = SKB_EXT_CHUNKSIZEOF(struct skb_ext);
|
||||||
#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
|
int i;
|
||||||
skb_ext_type_len[SKB_EXT_BRIDGE_NF] +
|
|
||||||
#endif
|
for (i = 0; i < ARRAY_SIZE(skb_ext_type_len); i++)
|
||||||
#ifdef CONFIG_XFRM
|
l += skb_ext_type_len[i];
|
||||||
skb_ext_type_len[SKB_EXT_SEC_PATH] +
|
|
||||||
#endif
|
return l;
|
||||||
#if IS_ENABLED(CONFIG_NET_TC_SKB_EXT)
|
|
||||||
skb_ext_type_len[TC_SKB_EXT] +
|
|
||||||
#endif
|
|
||||||
#if IS_ENABLED(CONFIG_MPTCP)
|
|
||||||
skb_ext_type_len[SKB_EXT_MPTCP] +
|
|
||||||
#endif
|
|
||||||
#if IS_ENABLED(CONFIG_MCTP_FLOWS)
|
|
||||||
skb_ext_type_len[SKB_EXT_MCTP] +
|
|
||||||
#endif
|
|
||||||
0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void skb_extensions_init(void)
|
static void skb_extensions_init(void)
|
||||||
|
|
Loading…
Reference in New Issue