bpf: Fix unused nskb warning in bpf_icmp_send

Declare nskb inside the IPv4 and IPv6 case blocks so it is only present
when the corresponding code is built. The case braces are intentional to
scope the local declarations under the switch labels.

Fixes: f3603df9ae ("bpf: Add bpf_icmp_send kfunc")
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Mahe Tardy <mahe.tardy@gmail.com>
Link: https://lore.kernel.org/bpf/20260710180915.7105-1-mahe.tardy@gmail.com
Closes: https://lore.kernel.org/oe-kbuild-all/202607110140.JeJZ6GIa-lkp@intel.com/
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
This commit is contained in:
Mahe Tardy 2026-07-10 18:09:15 +00:00 committed by Kumar Kartikeya Dwivedi
parent b1d4514ff1
commit 30f77a0419
No known key found for this signature in database
GPG Key ID: 472D377B63542F83

View File

@ -12575,7 +12575,6 @@ __bpf_kfunc int bpf_xdp_pull_data(struct xdp_md *x, u32 len)
__bpf_kfunc int bpf_icmp_send(struct __sk_buff *skb_ctx, int type, int code)
{
struct sk_buff *skb = (struct sk_buff *)skb_ctx;
struct sk_buff *nskb;
struct sock *sk;
sk = skb_to_full_sk(skb);
@ -12589,6 +12588,8 @@ __bpf_kfunc int bpf_icmp_send(struct __sk_buff *skb_ctx, int type, int code)
switch (skb->protocol) {
#if IS_ENABLED(CONFIG_INET)
case htons(ETH_P_IP): {
struct sk_buff *nskb;
if (type != ICMP_DEST_UNREACH)
return -EOPNOTSUPP;
if (code < 0 || code > NR_ICMP_UNREACH ||
@ -12606,7 +12607,9 @@ __bpf_kfunc int bpf_icmp_send(struct __sk_buff *skb_ctx, int type, int code)
}
#endif
#if IS_ENABLED(CONFIG_IPV6)
case htons(ETH_P_IPV6):
case htons(ETH_P_IPV6): {
struct sk_buff *nskb;
if (type != ICMPV6_DEST_UNREACH)
return -EOPNOTSUPP;
if (code < 0 || code > ICMPV6_REJECT_ROUTE)
@ -12620,6 +12623,7 @@ __bpf_kfunc int bpf_icmp_send(struct __sk_buff *skb_ctx, int type, int code)
icmpv6_send(nskb, type, code, 0);
consume_skb(nskb);
break;
}
#endif
default:
return -EPROTONOSUPPORT;