Skip to content

Commit fc56878

Browse files
hormsummakynes
authored andcommitted
netfilter: nf_reject: Fix build warning when CONFIG_BRIDGE_NETFILTER=n
If CONFIG_BRIDGE_NETFILTER is not enabled, which is the case for x86_64 defconfig, then building nf_reject_ipv4.c and nf_reject_ipv6.c with W=1 using gcc-14 results in the following warnings, which are treated as errors: net/ipv4/netfilter/nf_reject_ipv4.c: In function 'nf_send_reset': net/ipv4/netfilter/nf_reject_ipv4.c:243:23: error: variable 'niph' set but not used [-Werror=unused-but-set-variable] 243 | struct iphdr *niph; | ^~~~ cc1: all warnings being treated as errors net/ipv6/netfilter/nf_reject_ipv6.c: In function 'nf_send_reset6': net/ipv6/netfilter/nf_reject_ipv6.c:286:25: error: variable 'ip6h' set but not used [-Werror=unused-but-set-variable] 286 | struct ipv6hdr *ip6h; | ^~~~ cc1: all warnings being treated as errors Address this by reducing the scope of these local variables to where they are used, which is code only compiled when CONFIG_BRIDGE_NETFILTER enabled. Compile tested and run through netfilter selftests. Reported-by: Andy Shevchenko <[email protected]> Closes: https://lore.kernel.org/netfilter-devel/[email protected]/ Signed-off-by: Simon Horman <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 642c89c commit fc56878

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

net/ipv4/netfilter/nf_reject_ipv4.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,8 @@ static int nf_reject_fill_skb_dst(struct sk_buff *skb_in)
239239
void nf_send_reset(struct net *net, struct sock *sk, struct sk_buff *oldskb,
240240
int hook)
241241
{
242-
struct sk_buff *nskb;
243-
struct iphdr *niph;
244242
const struct tcphdr *oth;
243+
struct sk_buff *nskb;
245244
struct tcphdr _oth;
246245

247246
oth = nf_reject_ip_tcphdr_get(oldskb, &_oth, hook);
@@ -266,14 +265,12 @@ void nf_send_reset(struct net *net, struct sock *sk, struct sk_buff *oldskb,
266265
nskb->mark = IP4_REPLY_MARK(net, oldskb->mark);
267266

268267
skb_reserve(nskb, LL_MAX_HEADER);
269-
niph = nf_reject_iphdr_put(nskb, oldskb, IPPROTO_TCP,
270-
ip4_dst_hoplimit(skb_dst(nskb)));
268+
nf_reject_iphdr_put(nskb, oldskb, IPPROTO_TCP,
269+
ip4_dst_hoplimit(skb_dst(nskb)));
271270
nf_reject_ip_tcphdr_put(nskb, oldskb, oth);
272271
if (ip_route_me_harder(net, sk, nskb, RTN_UNSPEC))
273272
goto free_nskb;
274273

275-
niph = ip_hdr(nskb);
276-
277274
/* "Never happens" */
278275
if (nskb->len > dst_mtu(skb_dst(nskb)))
279276
goto free_nskb;
@@ -290,6 +287,7 @@ void nf_send_reset(struct net *net, struct sock *sk, struct sk_buff *oldskb,
290287
*/
291288
if (nf_bridge_info_exists(oldskb)) {
292289
struct ethhdr *oeth = eth_hdr(oldskb);
290+
struct iphdr *niph = ip_hdr(nskb);
293291
struct net_device *br_indev;
294292

295293
br_indev = nf_bridge_get_physindev(oldskb, net);

net/ipv6/netfilter/nf_reject_ipv6.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,6 @@ void nf_send_reset6(struct net *net, struct sock *sk, struct sk_buff *oldskb,
283283
const struct tcphdr *otcph;
284284
unsigned int otcplen, hh_len;
285285
const struct ipv6hdr *oip6h = ipv6_hdr(oldskb);
286-
struct ipv6hdr *ip6h;
287286
struct dst_entry *dst = NULL;
288287
struct flowi6 fl6;
289288

@@ -339,8 +338,7 @@ void nf_send_reset6(struct net *net, struct sock *sk, struct sk_buff *oldskb,
339338
nskb->mark = fl6.flowi6_mark;
340339

341340
skb_reserve(nskb, hh_len + dst->header_len);
342-
ip6h = nf_reject_ip6hdr_put(nskb, oldskb, IPPROTO_TCP,
343-
ip6_dst_hoplimit(dst));
341+
nf_reject_ip6hdr_put(nskb, oldskb, IPPROTO_TCP, ip6_dst_hoplimit(dst));
344342
nf_reject_ip6_tcphdr_put(nskb, oldskb, otcph, otcplen);
345343

346344
nf_ct_attach(nskb, oldskb);
@@ -355,6 +353,7 @@ void nf_send_reset6(struct net *net, struct sock *sk, struct sk_buff *oldskb,
355353
*/
356354
if (nf_bridge_info_exists(oldskb)) {
357355
struct ethhdr *oeth = eth_hdr(oldskb);
356+
struct ipv6hdr *ip6h = ipv6_hdr(nskb);
358357
struct net_device *br_indev;
359358

360359
br_indev = nf_bridge_get_physindev(oldskb, net);

0 commit comments

Comments
 (0)