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

TOMOYO Linux Cross Reference
Linux/net/ipv4/netfilter/ipt_REJECT.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 // SPDX-License-Identifier: GPL-2.0-only
  2 /*
  3  * This is a module which is used for rejecting packets.
  4  */
  5 
  6 /* (C) 1999-2001 Paul `Rusty' Russell
  7  * (C) 2002-2004 Netfilter Core Team <coreteam@netfilter.org>
  8  */
  9 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 10 #include <linux/module.h>
 11 #include <linux/skbuff.h>
 12 #include <linux/slab.h>
 13 #include <linux/ip.h>
 14 #include <linux/udp.h>
 15 #include <linux/icmp.h>
 16 #include <net/icmp.h>
 17 #include <linux/netfilter/x_tables.h>
 18 #include <linux/netfilter_ipv4/ip_tables.h>
 19 #include <linux/netfilter_ipv4/ipt_REJECT.h>
 20 #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
 21 #include <linux/netfilter_bridge.h>
 22 #endif
 23 
 24 #include <net/netfilter/ipv4/nf_reject.h>
 25 
 26 MODULE_LICENSE("GPL");
 27 MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>");
 28 MODULE_DESCRIPTION("Xtables: packet \"rejection\" target for IPv4");
 29 
 30 static unsigned int
 31 reject_tg(struct sk_buff *skb, const struct xt_action_param *par)
 32 {
 33         const struct ipt_reject_info *reject = par->targinfo;
 34         int hook = xt_hooknum(par);
 35 
 36         switch (reject->with) {
 37         case IPT_ICMP_NET_UNREACHABLE:
 38                 nf_send_unreach(skb, ICMP_NET_UNREACH, hook);
 39                 break;
 40         case IPT_ICMP_HOST_UNREACHABLE:
 41                 nf_send_unreach(skb, ICMP_HOST_UNREACH, hook);
 42                 break;
 43         case IPT_ICMP_PROT_UNREACHABLE:
 44                 nf_send_unreach(skb, ICMP_PROT_UNREACH, hook);
 45                 break;
 46         case IPT_ICMP_PORT_UNREACHABLE:
 47                 nf_send_unreach(skb, ICMP_PORT_UNREACH, hook);
 48                 break;
 49         case IPT_ICMP_NET_PROHIBITED:
 50                 nf_send_unreach(skb, ICMP_NET_ANO, hook);
 51                 break;
 52         case IPT_ICMP_HOST_PROHIBITED:
 53                 nf_send_unreach(skb, ICMP_HOST_ANO, hook);
 54                 break;
 55         case IPT_ICMP_ADMIN_PROHIBITED:
 56                 nf_send_unreach(skb, ICMP_PKT_FILTERED, hook);
 57                 break;
 58         case IPT_TCP_RESET:
 59                 nf_send_reset(xt_net(par), skb, hook);
 60         case IPT_ICMP_ECHOREPLY:
 61                 /* Doesn't happen. */
 62                 break;
 63         }
 64 
 65         return NF_DROP;
 66 }
 67 
 68 static int reject_tg_check(const struct xt_tgchk_param *par)
 69 {
 70         const struct ipt_reject_info *rejinfo = par->targinfo;
 71         const struct ipt_entry *e = par->entryinfo;
 72 
 73         if (rejinfo->with == IPT_ICMP_ECHOREPLY) {
 74                 pr_info_ratelimited("ECHOREPLY no longer supported.\n");
 75                 return -EINVAL;
 76         } else if (rejinfo->with == IPT_TCP_RESET) {
 77                 /* Must specify that it's a TCP packet */
 78                 if (e->ip.proto != IPPROTO_TCP ||
 79                     (e->ip.invflags & XT_INV_PROTO)) {
 80                         pr_info_ratelimited("TCP_RESET invalid for non-tcp\n");
 81                         return -EINVAL;
 82                 }
 83         }
 84         return 0;
 85 }
 86 
 87 static struct xt_target reject_tg_reg __read_mostly = {
 88         .name           = "REJECT",
 89         .family         = NFPROTO_IPV4,
 90         .target         = reject_tg,
 91         .targetsize     = sizeof(struct ipt_reject_info),
 92         .table          = "filter",
 93         .hooks          = (1 << NF_INET_LOCAL_IN) | (1 << NF_INET_FORWARD) |
 94                           (1 << NF_INET_LOCAL_OUT),
 95         .checkentry     = reject_tg_check,
 96         .me             = THIS_MODULE,
 97 };
 98 
 99 static int __init reject_tg_init(void)
100 {
101         return xt_register_target(&reject_tg_reg);
102 }
103 
104 static void __exit reject_tg_exit(void)
105 {
106         xt_unregister_target(&reject_tg_reg);
107 }
108 
109 module_init(reject_tg_init);
110 module_exit(reject_tg_exit);
111 

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