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

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

Version: ~ [ linux-5.4-rc7 ] ~ [ linux-5.3.10 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.83 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.153 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.200 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.200 ] ~ [ 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.76 ] ~ [ 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-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ 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  * Copyright (c) 2008 Patrick McHardy <kaber@trash.net>
  3  * Copyright (c) 2012-2013 Pablo Neira Ayuso <pablo@netfilter.org>
  4  *
  5  * This program is free software; you can redistribute it and/or modify
  6  * it under the terms of the GNU General Public License version 2 as
  7  * published by the Free Software Foundation.
  8  *
  9  * Development of this code funded by Astaro AG (http://www.astaro.com/)
 10  */
 11 
 12 #include <linux/init.h>
 13 #include <linux/module.h>
 14 #include <linux/ip.h>
 15 #include <linux/netfilter_ipv4.h>
 16 #include <net/netfilter/nf_tables.h>
 17 #include <net/net_namespace.h>
 18 #include <net/ip.h>
 19 #include <net/netfilter/nf_tables_ipv4.h>
 20 
 21 static unsigned int nft_do_chain_ipv4(void *priv,
 22                                       struct sk_buff *skb,
 23                                       const struct nf_hook_state *state)
 24 {
 25         struct nft_pktinfo pkt;
 26 
 27         nft_set_pktinfo_ipv4(&pkt, skb, state);
 28 
 29         return nft_do_chain(&pkt, priv);
 30 }
 31 
 32 static unsigned int nft_ipv4_output(void *priv,
 33                                     struct sk_buff *skb,
 34                                     const struct nf_hook_state *state)
 35 {
 36         if (unlikely(skb->len < sizeof(struct iphdr) ||
 37                      ip_hdr(skb)->ihl < sizeof(struct iphdr) / 4)) {
 38                 if (net_ratelimit())
 39                         pr_info("nf_tables_ipv4: ignoring short SOCK_RAW "
 40                                 "packet\n");
 41                 return NF_ACCEPT;
 42         }
 43 
 44         return nft_do_chain_ipv4(priv, skb, state);
 45 }
 46 
 47 struct nft_af_info nft_af_ipv4 __read_mostly = {
 48         .family         = NFPROTO_IPV4,
 49         .nhooks         = NF_INET_NUMHOOKS,
 50         .owner          = THIS_MODULE,
 51         .nops           = 1,
 52         .hooks          = {
 53                 [NF_INET_LOCAL_IN]      = nft_do_chain_ipv4,
 54                 [NF_INET_LOCAL_OUT]     = nft_ipv4_output,
 55                 [NF_INET_FORWARD]       = nft_do_chain_ipv4,
 56                 [NF_INET_PRE_ROUTING]   = nft_do_chain_ipv4,
 57                 [NF_INET_POST_ROUTING]  = nft_do_chain_ipv4,
 58         },
 59 };
 60 EXPORT_SYMBOL_GPL(nft_af_ipv4);
 61 
 62 static int nf_tables_ipv4_init_net(struct net *net)
 63 {
 64         net->nft.ipv4 = kmalloc(sizeof(struct nft_af_info), GFP_KERNEL);
 65         if (net->nft.ipv4 == NULL)
 66                 return -ENOMEM;
 67 
 68         memcpy(net->nft.ipv4, &nft_af_ipv4, sizeof(nft_af_ipv4));
 69 
 70         if (nft_register_afinfo(net, net->nft.ipv4) < 0)
 71                 goto err;
 72 
 73         return 0;
 74 err:
 75         kfree(net->nft.ipv4);
 76         return -ENOMEM;
 77 }
 78 
 79 static void nf_tables_ipv4_exit_net(struct net *net)
 80 {
 81         nft_unregister_afinfo(net, net->nft.ipv4);
 82         kfree(net->nft.ipv4);
 83 }
 84 
 85 static struct pernet_operations nf_tables_ipv4_net_ops = {
 86         .init   = nf_tables_ipv4_init_net,
 87         .exit   = nf_tables_ipv4_exit_net,
 88 };
 89 
 90 static const struct nf_chain_type filter_ipv4 = {
 91         .name           = "filter",
 92         .type           = NFT_CHAIN_T_DEFAULT,
 93         .family         = NFPROTO_IPV4,
 94         .owner          = THIS_MODULE,
 95         .hook_mask      = (1 << NF_INET_LOCAL_IN) |
 96                           (1 << NF_INET_LOCAL_OUT) |
 97                           (1 << NF_INET_FORWARD) |
 98                           (1 << NF_INET_PRE_ROUTING) |
 99                           (1 << NF_INET_POST_ROUTING),
100 };
101 
102 static int __init nf_tables_ipv4_init(void)
103 {
104         int ret;
105 
106         ret = nft_register_chain_type(&filter_ipv4);
107         if (ret < 0)
108                 return ret;
109 
110         ret = register_pernet_subsys(&nf_tables_ipv4_net_ops);
111         if (ret < 0)
112                 nft_unregister_chain_type(&filter_ipv4);
113 
114         return ret;
115 }
116 
117 static void __exit nf_tables_ipv4_exit(void)
118 {
119         unregister_pernet_subsys(&nf_tables_ipv4_net_ops);
120         nft_unregister_chain_type(&filter_ipv4);
121 }
122 
123 module_init(nf_tables_ipv4_init);
124 module_exit(nf_tables_ipv4_exit);
125 
126 MODULE_LICENSE("GPL");
127 MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
128 MODULE_ALIAS_NFT_FAMILY(AF_INET);
129 

~ [ 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