1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * broadcast connection tracking helper
5 * (c) 2005 Patrick McHardy <kaber@trash.net>
8 #include <linux/module.h>
10 #include <net/route.h>
11 #include <linux/inetdevice.h>
12 #include <linux/skbuff.h>
14 #include <net/netfilter/nf_conntrack.h>
15 #include <net/netfilter/nf_conntrack_helper.h>
16 #include <net/netfilter/nf_conntrack_expect.h>
18 int nf_conntrack_broadcast_help(struct sk_buff
*skb
,
20 enum ip_conntrack_info ctinfo
,
23 struct nf_conntrack_expect
*exp
;
24 struct iphdr
*iph
= ip_hdr(skb
);
25 struct rtable
*rt
= skb_rtable(skb
);
26 struct in_device
*in_dev
;
27 struct nf_conn_help
*help
= nfct_help(ct
);
30 /* we're only interested in locally generated packets */
31 if (skb
->sk
== NULL
|| !net_eq(nf_ct_net(ct
), sock_net(skb
->sk
)))
33 if (rt
== NULL
|| !(rt
->rt_flags
& RTCF_BROADCAST
))
35 if (CTINFO2DIR(ctinfo
) != IP_CT_DIR_ORIGINAL
)
38 in_dev
= __in_dev_get_rcu(rt
->dst
.dev
);
40 const struct in_ifaddr
*ifa
;
42 in_dev_for_each_ifa_rcu(ifa
, in_dev
) {
43 if (ifa
->ifa_flags
& IFA_F_SECONDARY
)
46 if (ifa
->ifa_broadcast
== iph
->daddr
) {
56 exp
= nf_ct_expect_alloc(ct
);
60 exp
->tuple
= ct
->tuplehash
[IP_CT_DIR_REPLY
].tuple
;
61 exp
->tuple
.src
.u
.udp
.port
= help
->helper
->tuple
.src
.u
.udp
.port
;
63 exp
->mask
.src
.u3
.ip
= mask
;
64 exp
->mask
.src
.u
.udp
.port
= htons(0xFFFF);
67 exp
->flags
= NF_CT_EXPECT_PERMANENT
;
68 exp
->class = NF_CT_EXPECT_CLASS_DEFAULT
;
71 nf_ct_expect_related(exp
, 0);
72 nf_ct_expect_put(exp
);
74 nf_ct_refresh(ct
, skb
, timeout
* HZ
);
78 EXPORT_SYMBOL_GPL(nf_conntrack_broadcast_help
);
80 MODULE_LICENSE("GPL");