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

TOMOYO Linux Cross Reference
Linux/net/ipv6/netfilter/ip6t_REJECT.c

Version: ~ [ linux-5.13-rc5 ] ~ [ linux-5.12.9 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.42 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.124 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.193 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.235 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.271 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.271 ] ~ [ 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  * IP6 tables REJECT target module
  3  * Linux INET6 implementation
  4  *
  5  * Copyright (C)2003 USAGI/WIDE Project
  6  *
  7  * Authors:
  8  *      Yasuyuki Kozakai        <yasuyuki.kozakai@toshiba.co.jp>
  9  *
 10  * Copyright (c) 2005-2007 Patrick McHardy <kaber@trash.net>
 11  *
 12  * Based on net/ipv4/netfilter/ipt_REJECT.c
 13  *
 14  * This program is free software; you can redistribute it and/or
 15  * modify it under the terms of the GNU General Public License
 16  * as published by the Free Software Foundation; either version
 17  * 2 of the License, or (at your option) any later version.
 18  */
 19 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 20 
 21 #include <linux/gfp.h>
 22 #include <linux/module.h>
 23 #include <linux/skbuff.h>
 24 #include <linux/icmpv6.h>
 25 #include <linux/netdevice.h>
 26 #include <net/icmp.h>
 27 #include <net/flow.h>
 28 #include <linux/netfilter/x_tables.h>
 29 #include <linux/netfilter_ipv6/ip6_tables.h>
 30 #include <linux/netfilter_ipv6/ip6t_REJECT.h>
 31 
 32 #include <net/netfilter/ipv6/nf_reject.h>
 33 
 34 MODULE_AUTHOR("Yasuyuki KOZAKAI <yasuyuki.kozakai@toshiba.co.jp>");
 35 MODULE_DESCRIPTION("Xtables: packet \"rejection\" target for IPv6");
 36 MODULE_LICENSE("GPL");
 37 
 38 
 39 static unsigned int
 40 reject_tg6(struct sk_buff *skb, const struct xt_action_param *par)
 41 {
 42         const struct ip6t_reject_info *reject = par->targinfo;
 43         struct net *net = dev_net((par->in != NULL) ? par->in : par->out);
 44 
 45         pr_debug("%s: medium point\n", __func__);
 46         switch (reject->with) {
 47         case IP6T_ICMP6_NO_ROUTE:
 48                 nf_send_unreach6(net, skb, ICMPV6_NOROUTE, par->hooknum);
 49                 break;
 50         case IP6T_ICMP6_ADM_PROHIBITED:
 51                 nf_send_unreach6(net, skb, ICMPV6_ADM_PROHIBITED, par->hooknum);
 52                 break;
 53         case IP6T_ICMP6_NOT_NEIGHBOUR:
 54                 nf_send_unreach6(net, skb, ICMPV6_NOT_NEIGHBOUR, par->hooknum);
 55                 break;
 56         case IP6T_ICMP6_ADDR_UNREACH:
 57                 nf_send_unreach6(net, skb, ICMPV6_ADDR_UNREACH, par->hooknum);
 58                 break;
 59         case IP6T_ICMP6_PORT_UNREACH:
 60                 nf_send_unreach6(net, skb, ICMPV6_PORT_UNREACH, par->hooknum);
 61                 break;
 62         case IP6T_ICMP6_ECHOREPLY:
 63                 /* Do nothing */
 64                 break;
 65         case IP6T_TCP_RESET:
 66                 nf_send_reset6(net, skb, par->hooknum);
 67                 break;
 68         default:
 69                 net_info_ratelimited("case %u not handled yet\n", reject->with);
 70                 break;
 71         }
 72 
 73         return NF_DROP;
 74 }
 75 
 76 static int reject_tg6_check(const struct xt_tgchk_param *par)
 77 {
 78         const struct ip6t_reject_info *rejinfo = par->targinfo;
 79         const struct ip6t_entry *e = par->entryinfo;
 80 
 81         if (rejinfo->with == IP6T_ICMP6_ECHOREPLY) {
 82                 pr_info("ECHOREPLY is not supported.\n");
 83                 return -EINVAL;
 84         } else if (rejinfo->with == IP6T_TCP_RESET) {
 85                 /* Must specify that it's a TCP packet */
 86                 if (!(e->ipv6.flags & IP6T_F_PROTO) ||
 87                     e->ipv6.proto != IPPROTO_TCP ||
 88                     (e->ipv6.invflags & XT_INV_PROTO)) {
 89                         pr_info("TCP_RESET illegal for non-tcp\n");
 90                         return -EINVAL;
 91                 }
 92         }
 93         return 0;
 94 }
 95 
 96 static struct xt_target reject_tg6_reg __read_mostly = {
 97         .name           = "REJECT",
 98         .family         = NFPROTO_IPV6,
 99         .target         = reject_tg6,
100         .targetsize     = sizeof(struct ip6t_reject_info),
101         .table          = "filter",
102         .hooks          = (1 << NF_INET_LOCAL_IN) | (1 << NF_INET_FORWARD) |
103                           (1 << NF_INET_LOCAL_OUT),
104         .checkentry     = reject_tg6_check,
105         .me             = THIS_MODULE
106 };
107 
108 static int __init reject_tg6_init(void)
109 {
110         return xt_register_target(&reject_tg6_reg);
111 }
112 
113 static void __exit reject_tg6_exit(void)
114 {
115         xt_unregister_target(&reject_tg6_reg);
116 }
117 
118 module_init(reject_tg6_init);
119 module_exit(reject_tg6_exit);
120 

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