~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/net/netfilter/nf_conntrack_broadcast.c

Version: ~ [ linux-5.7-rc7 ] ~ [ linux-5.6.14 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.42 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.124 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.181 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.224 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.224 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.84 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  *      broadcast connection tracking helper
  3  *
  4  *      (c) 2005 Patrick McHardy <kaber@trash.net>
  5  *
  6  *      This program is free software; you can redistribute it and/or
  7  *      modify it under the terms of the GNU General Public License
  8  *      as published by the Free Software Foundation; either version
  9  *      2 of the License, or (at your option) any later version.
 10  */
 11 
 12 #include <linux/module.h>
 13 #include <linux/ip.h>
 14 #include <net/route.h>
 15 #include <linux/inetdevice.h>
 16 #include <linux/skbuff.h>
 17 
 18 #include <net/netfilter/nf_conntrack.h>
 19 #include <net/netfilter/nf_conntrack_helper.h>
 20 #include <net/netfilter/nf_conntrack_expect.h>
 21 
 22 int nf_conntrack_broadcast_help(struct sk_buff *skb,
 23                                 unsigned int protoff,
 24                                 struct nf_conn *ct,
 25                                 enum ip_conntrack_info ctinfo,
 26                                 unsigned int timeout)
 27 {
 28         struct nf_conntrack_expect *exp;
 29         struct iphdr *iph = ip_hdr(skb);
 30         struct rtable *rt = skb_rtable(skb);
 31         struct in_device *in_dev;
 32         struct nf_conn_help *help = nfct_help(ct);
 33         __be32 mask = 0;
 34 
 35         /* we're only interested in locally generated packets */
 36         if (skb->sk == NULL)
 37                 goto out;
 38         if (rt == NULL || !(rt->rt_flags & RTCF_BROADCAST))
 39                 goto out;
 40         if (CTINFO2DIR(ctinfo) != IP_CT_DIR_ORIGINAL)
 41                 goto out;
 42 
 43         rcu_read_lock();
 44         in_dev = __in_dev_get_rcu(rt->dst.dev);
 45         if (in_dev != NULL) {
 46                 for_primary_ifa(in_dev) {
 47                         if (ifa->ifa_broadcast == iph->daddr) {
 48                                 mask = ifa->ifa_mask;
 49                                 break;
 50                         }
 51                 } endfor_ifa(in_dev);
 52         }
 53         rcu_read_unlock();
 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         exp->tuple.src.u.udp.port = help->helper->tuple.src.u.udp.port;
 64 
 65         exp->mask.src.u3.ip       = mask;
 66         exp->mask.src.u.udp.port  = htons(0xFFFF);
 67 
 68         exp->expectfn             = NULL;
 69         exp->flags                = NF_CT_EXPECT_PERMANENT;
 70         exp->class                = NF_CT_EXPECT_CLASS_DEFAULT;
 71         exp->helper               = NULL;
 72 
 73         nf_ct_expect_related(exp);
 74         nf_ct_expect_put(exp);
 75 
 76         nf_ct_refresh(ct, skb, timeout * HZ);
 77 out:
 78         return NF_ACCEPT;
 79 }
 80 EXPORT_SYMBOL_GPL(nf_conntrack_broadcast_help);
 81 
 82 MODULE_LICENSE("GPL");
 83 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp