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

TOMOYO Linux Cross Reference
Linux/net/ipv4/netfilter/iptable_filter.c

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ 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.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-only
  2 /*
  3  * This is the 1999 rewrite of IP Firewalling, aiming for kernel 2.3.x.
  4  *
  5  * Copyright (C) 1999 Paul `Rusty' Russell & Michael J. Neuling
  6  * Copyright (C) 2000-2004 Netfilter Core Team <coreteam@netfilter.org>
  7  */
  8 
  9 #include <linux/module.h>
 10 #include <linux/moduleparam.h>
 11 #include <linux/netfilter_ipv4/ip_tables.h>
 12 #include <linux/slab.h>
 13 #include <net/ip.h>
 14 
 15 MODULE_LICENSE("GPL");
 16 MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>");
 17 MODULE_DESCRIPTION("iptables filter table");
 18 
 19 #define FILTER_VALID_HOOKS ((1 << NF_INET_LOCAL_IN) | \
 20                             (1 << NF_INET_FORWARD) | \
 21                             (1 << NF_INET_LOCAL_OUT))
 22 
 23 static const struct xt_table packet_filter = {
 24         .name           = "filter",
 25         .valid_hooks    = FILTER_VALID_HOOKS,
 26         .me             = THIS_MODULE,
 27         .af             = NFPROTO_IPV4,
 28         .priority       = NF_IP_PRI_FILTER,
 29 };
 30 
 31 static struct nf_hook_ops *filter_ops __read_mostly;
 32 
 33 /* Default to forward because I got too much mail already. */
 34 static bool forward __read_mostly = true;
 35 module_param(forward, bool, 0000);
 36 
 37 static int iptable_filter_table_init(struct net *net)
 38 {
 39         struct ipt_replace *repl;
 40         int err;
 41 
 42         repl = ipt_alloc_initial_table(&packet_filter);
 43         if (repl == NULL)
 44                 return -ENOMEM;
 45         /* Entry 1 is the FORWARD hook */
 46         ((struct ipt_standard *)repl->entries)[1].target.verdict =
 47                 forward ? -NF_ACCEPT - 1 : NF_DROP - 1;
 48 
 49         err = ipt_register_table(net, &packet_filter, repl, filter_ops);
 50         kfree(repl);
 51         return err;
 52 }
 53 
 54 static int __net_init iptable_filter_net_init(struct net *net)
 55 {
 56         if (!forward)
 57                 return iptable_filter_table_init(net);
 58 
 59         return 0;
 60 }
 61 
 62 static void __net_exit iptable_filter_net_pre_exit(struct net *net)
 63 {
 64         ipt_unregister_table_pre_exit(net, "filter");
 65 }
 66 
 67 static void __net_exit iptable_filter_net_exit(struct net *net)
 68 {
 69         ipt_unregister_table_exit(net, "filter");
 70 }
 71 
 72 static struct pernet_operations iptable_filter_net_ops = {
 73         .init = iptable_filter_net_init,
 74         .pre_exit = iptable_filter_net_pre_exit,
 75         .exit = iptable_filter_net_exit,
 76 };
 77 
 78 static int __init iptable_filter_init(void)
 79 {
 80         int ret = xt_register_template(&packet_filter,
 81                                        iptable_filter_table_init);
 82 
 83         if (ret < 0)
 84                 return ret;
 85 
 86         filter_ops = xt_hook_ops_alloc(&packet_filter, ipt_do_table);
 87         if (IS_ERR(filter_ops)) {
 88                 xt_unregister_template(&packet_filter);
 89                 return PTR_ERR(filter_ops);
 90         }
 91 
 92         ret = register_pernet_subsys(&iptable_filter_net_ops);
 93         if (ret < 0) {
 94                 xt_unregister_template(&packet_filter);
 95                 kfree(filter_ops);
 96                 return ret;
 97         }
 98 
 99         return 0;
100 }
101 
102 static void __exit iptable_filter_fini(void)
103 {
104         unregister_pernet_subsys(&iptable_filter_net_ops);
105         xt_unregister_template(&packet_filter);
106         kfree(filter_ops);
107 }
108 
109 module_init(iptable_filter_init);
110 module_exit(iptable_filter_fini);
111 

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

kernel.org | git.kernel.org | LWN.net | Project Home | 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.

sflogo.php