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

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

Version: ~ [ linux-5.16-rc1 ] ~ [ linux-5.15.2 ] ~ [ linux-5.14.18 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.79 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.159 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.217 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.255 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.290 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.292 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.18.140 ] ~ [ linux-3.16.85 ] ~ [ linux-3.14.79 ] ~ [ linux-3.12.74 ] ~ [ 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  * This is a module which is used for rejecting packets.
  3  */
  4 
  5 /* (C) 1999-2001 Paul `Rusty' Russell
  6  * (C) 2002-2004 Netfilter Core Team <coreteam@netfilter.org>
  7  *
  8  * This program is free software; you can redistribute it and/or modify
  9  * it under the terms of the GNU General Public License version 2 as
 10  * published by the Free Software Foundation.
 11  */
 12 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 13 #include <linux/module.h>
 14 #include <linux/skbuff.h>
 15 #include <linux/slab.h>
 16 #include <linux/ip.h>
 17 #include <linux/udp.h>
 18 #include <linux/icmp.h>
 19 #include <net/icmp.h>
 20 #include <linux/netfilter/x_tables.h>
 21 #include <linux/netfilter_ipv4/ip_tables.h>
 22 #include <linux/netfilter_ipv4/ipt_REJECT.h>
 23 #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
 24 #include <linux/netfilter_bridge.h>
 25 #endif
 26 
 27 #include <net/netfilter/ipv4/nf_reject.h>
 28 
 29 MODULE_LICENSE("GPL");
 30 MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>");
 31 MODULE_DESCRIPTION("Xtables: packet \"rejection\" target for IPv4");
 32 
 33 static unsigned int
 34 reject_tg(struct sk_buff *skb, const struct xt_action_param *par)
 35 {
 36         const struct ipt_reject_info *reject = par->targinfo;
 37         int hook = par->hooknum;
 38 
 39         switch (reject->with) {
 40         case IPT_ICMP_NET_UNREACHABLE:
 41                 nf_send_unreach(skb, ICMP_NET_UNREACH, hook);
 42                 break;
 43         case IPT_ICMP_HOST_UNREACHABLE:
 44                 nf_send_unreach(skb, ICMP_HOST_UNREACH, hook);
 45                 break;
 46         case IPT_ICMP_PROT_UNREACHABLE:
 47                 nf_send_unreach(skb, ICMP_PROT_UNREACH, hook);
 48                 break;
 49         case IPT_ICMP_PORT_UNREACHABLE:
 50                 nf_send_unreach(skb, ICMP_PORT_UNREACH, hook);
 51                 break;
 52         case IPT_ICMP_NET_PROHIBITED:
 53                 nf_send_unreach(skb, ICMP_NET_ANO, hook);
 54                 break;
 55         case IPT_ICMP_HOST_PROHIBITED:
 56                 nf_send_unreach(skb, ICMP_HOST_ANO, hook);
 57                 break;
 58         case IPT_ICMP_ADMIN_PROHIBITED:
 59                 nf_send_unreach(skb, ICMP_PKT_FILTERED, hook);
 60                 break;
 61         case IPT_TCP_RESET:
 62                 nf_send_reset(skb, hook);
 63         case IPT_ICMP_ECHOREPLY:
 64                 /* Doesn't happen. */
 65                 break;
 66         }
 67 
 68         return NF_DROP;
 69 }
 70 
 71 static int reject_tg_check(const struct xt_tgchk_param *par)
 72 {
 73         const struct ipt_reject_info *rejinfo = par->targinfo;
 74         const struct ipt_entry *e = par->entryinfo;
 75 
 76         if (rejinfo->with == IPT_ICMP_ECHOREPLY) {
 77                 pr_info("ECHOREPLY no longer supported.\n");
 78                 return -EINVAL;
 79         } else if (rejinfo->with == IPT_TCP_RESET) {
 80                 /* Must specify that it's a TCP packet */
 81                 if (e->ip.proto != IPPROTO_TCP ||
 82                     (e->ip.invflags & XT_INV_PROTO)) {
 83                         pr_info("TCP_RESET invalid for non-tcp\n");
 84                         return -EINVAL;
 85                 }
 86         }
 87         return 0;
 88 }
 89 
 90 static struct xt_target reject_tg_reg __read_mostly = {
 91         .name           = "REJECT",
 92         .family         = NFPROTO_IPV4,
 93         .target         = reject_tg,
 94         .targetsize     = sizeof(struct ipt_reject_info),
 95         .table          = "filter",
 96         .hooks          = (1 << NF_INET_LOCAL_IN) | (1 << NF_INET_FORWARD) |
 97                           (1 << NF_INET_LOCAL_OUT),
 98         .checkentry     = reject_tg_check,
 99         .me             = THIS_MODULE,
100 };
101 
102 static int __init reject_tg_init(void)
103 {
104         return xt_register_target(&reject_tg_reg);
105 }
106 
107 static void __exit reject_tg_exit(void)
108 {
109         xt_unregister_target(&reject_tg_reg);
110 }
111 
112 module_init(reject_tg_init);
113 module_exit(reject_tg_exit);
114 

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