FILE
nf_conntrack_broadcast.c
File preview with syntax highlighting.
linux-6.19.14/net/netfilter/nf_conntrack_broadcast.c
1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * broadcast connection tracking helper 4 * 5 * (c) 2005 Patrick McHardy <kaber@trash.net> 6 */ 7 8#include <linux/module.h> 9#include <linux/ip.h> 10#include <net/route.h> 11#include <linux/inetdevice.h> 12#include <linux/skbuff.h> 13 14#include <net/netfilter/nf_conntrack.h> 15#include <net/netfilter/nf_conntrack_helper.h> 16#include <net/netfilter/nf_conntrack_expect.h> 17 18int nf_conntrack_broadcast_help(struct sk_buff *skb, 19 struct nf_conn *ct, 20 enum ip_conntrack_info ctinfo, 21 unsigned int timeout) 22{ 23 const struct nf_conntrack_helper *helper; 24 struct net *net = read_pnet(&ct->ct_net); 25 struct nf_conntrack_expect *exp; 26 struct iphdr *iph = ip_hdr(skb); 27 struct rtable *rt = skb_rtable(skb); 28 struct in_device *in_dev; 29 struct nf_conn_help *help = nfct_help(ct); 30 __be32 mask = 0; 31 32 /* we're only interested in locally generated packets */ 33 if (skb->sk == NULL || !net_eq(nf_ct_net(ct), sock_net(skb->sk))) 34 goto out; 35 if (rt == NULL || !(rt->rt_flags & RTCF_BROADCAST)) 36 goto out; 37 if (CTINFO2DIR(ctinfo) != IP_CT_DIR_ORIGINAL) 38 goto out; 39 40 in_dev = __in_dev_get_rcu(rt->dst.dev); 41 if (in_dev != NULL) { 42 const struct in_ifaddr *ifa; 43 44 in_dev_for_each_ifa_rcu(ifa, in_dev) { 45 if (ifa->ifa_flags & IFA_F_SECONDARY) 46 continue; 47 48 if (ifa->ifa_broadcast == iph->daddr) { 49 mask = ifa->ifa_mask; 50 break; 51 } 52 } 53 } 54 55 if (mask == 0) 56 goto out; 57 58 exp = nf_ct_expect_alloc(ct); 59 if (exp == NULL) 60 goto out; 61 62 exp->tuple = ct->tuplehash[IP_CT_DIR_REPLY].tuple; 63 64 helper = rcu_dereference(help->helper); 65 if (helper) 66 exp->tuple.src.u.udp.port = helper->tuple.src.u.udp.port; 67 68 exp->mask.src.u3.ip = mask; 69 exp->mask.src.u.udp.port = htons(0xFFFF); 70 71 exp->expectfn = NULL; 72 exp->flags = NF_CT_EXPECT_PERMANENT; 73 exp->class = NF_CT_EXPECT_CLASS_DEFAULT; 74 rcu_assign_pointer(exp->helper, helper); 75 write_pnet(&exp->net, net); 76#ifdef CONFIG_NF_CONNTRACK_ZONES 77 exp->zone = ct->zone; 78#endif 79 nf_ct_expect_related(exp, 0); 80 nf_ct_expect_put(exp); 81 82 nf_ct_refresh(ct, timeout * HZ); 83out: 84 return NF_ACCEPT; 85} 86EXPORT_SYMBOL_GPL(nf_conntrack_broadcast_help); 87 88MODULE_LICENSE("GPL"); 89MODULE_DESCRIPTION("Broadcast connection tracking helper");
~/
Read-only file preview.