]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - net/ipv6/netfilter/ip6t_REJECT.c
Merge branch 'smp-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[mirror_ubuntu-artful-kernel.git] / net / ipv6 / netfilter / ip6t_REJECT.c
CommitLineData
764d8a9f
PM
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 *
f229f6ce
PM
10 * Copyright (c) 2005-2007 Patrick McHardy <kaber@trash.net>
11 *
764d8a9f
PM
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 */
ff67e4e4 19#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
764d8a9f 20
5a0e3ad6 21#include <linux/gfp.h>
764d8a9f
PM
22#include <linux/module.h>
23#include <linux/skbuff.h>
24#include <linux/icmpv6.h>
25#include <linux/netdevice.h>
764d8a9f 26#include <net/icmp.h>
764d8a9f 27#include <net/flow.h>
6709dbbb 28#include <linux/netfilter/x_tables.h>
764d8a9f
PM
29#include <linux/netfilter_ipv6/ip6_tables.h>
30#include <linux/netfilter_ipv6/ip6t_REJECT.h>
31
cc70d069
EL
32#include <net/netfilter/ipv6/nf_reject.h>
33
764d8a9f 34MODULE_AUTHOR("Yasuyuki KOZAKAI <yasuyuki.kozakai@toshiba.co.jp>");
2ae15b64 35MODULE_DESCRIPTION("Xtables: packet \"rejection\" target for IPv6");
764d8a9f
PM
36MODULE_LICENSE("GPL");
37
d3c5ee6d 38static unsigned int
4b560b44 39reject_tg6(struct sk_buff *skb, const struct xt_action_param *par)
764d8a9f 40{
7eb35586 41 const struct ip6t_reject_info *reject = par->targinfo;
613dbd95 42 struct net *net = xt_net(par);
764d8a9f 43
1ab1457c
YH
44 switch (reject->with) {
45 case IP6T_ICMP6_NO_ROUTE:
613dbd95 46 nf_send_unreach6(net, skb, ICMPV6_NOROUTE, xt_hooknum(par));
1ab1457c
YH
47 break;
48 case IP6T_ICMP6_ADM_PROHIBITED:
613dbd95
PNA
49 nf_send_unreach6(net, skb, ICMPV6_ADM_PROHIBITED,
50 xt_hooknum(par));
1ab1457c
YH
51 break;
52 case IP6T_ICMP6_NOT_NEIGHBOUR:
613dbd95
PNA
53 nf_send_unreach6(net, skb, ICMPV6_NOT_NEIGHBOUR,
54 xt_hooknum(par));
1ab1457c
YH
55 break;
56 case IP6T_ICMP6_ADDR_UNREACH:
613dbd95
PNA
57 nf_send_unreach6(net, skb, ICMPV6_ADDR_UNREACH,
58 xt_hooknum(par));
1ab1457c
YH
59 break;
60 case IP6T_ICMP6_PORT_UNREACH:
613dbd95
PNA
61 nf_send_unreach6(net, skb, ICMPV6_PORT_UNREACH,
62 xt_hooknum(par));
1ab1457c
YH
63 break;
64 case IP6T_ICMP6_ECHOREPLY:
764d8a9f
PM
65 /* Do nothing */
66 break;
67 case IP6T_TCP_RESET:
613dbd95 68 nf_send_reset6(net, skb, xt_hooknum(par));
764d8a9f 69 break;
1afe839e 70 case IP6T_ICMP6_POLICY_FAIL:
613dbd95 71 nf_send_unreach6(net, skb, ICMPV6_POLICY_FAIL, xt_hooknum(par));
1afe839e
AH
72 break;
73 case IP6T_ICMP6_REJECT_ROUTE:
613dbd95
PNA
74 nf_send_unreach6(net, skb, ICMPV6_REJECT_ROUTE,
75 xt_hooknum(par));
1afe839e 76 break;
764d8a9f
PM
77 }
78
79 return NF_DROP;
80}
81
135367b8 82static int reject_tg6_check(const struct xt_tgchk_param *par)
764d8a9f 83{
af5d6dc2
JE
84 const struct ip6t_reject_info *rejinfo = par->targinfo;
85 const struct ip6t_entry *e = par->entryinfo;
764d8a9f 86
764d8a9f 87 if (rejinfo->with == IP6T_ICMP6_ECHOREPLY) {
ff67e4e4 88 pr_info("ECHOREPLY is not supported.\n");
d6b00a53 89 return -EINVAL;
764d8a9f
PM
90 } else if (rejinfo->with == IP6T_TCP_RESET) {
91 /* Must specify that it's a TCP packet */
e35158e4
PNA
92 if (!(e->ipv6.flags & IP6T_F_PROTO) ||
93 e->ipv6.proto != IPPROTO_TCP ||
3666ed1c 94 (e->ipv6.invflags & XT_INV_PROTO)) {
ff67e4e4 95 pr_info("TCP_RESET illegal for non-tcp\n");
d6b00a53 96 return -EINVAL;
764d8a9f
PM
97 }
98 }
d6b00a53 99 return 0;
764d8a9f
PM
100}
101
d3c5ee6d 102static struct xt_target reject_tg6_reg __read_mostly = {
764d8a9f 103 .name = "REJECT",
ee999d8b 104 .family = NFPROTO_IPV6,
d3c5ee6d 105 .target = reject_tg6,
7f939713
PM
106 .targetsize = sizeof(struct ip6t_reject_info),
107 .table = "filter",
6e23ae2a
PM
108 .hooks = (1 << NF_INET_LOCAL_IN) | (1 << NF_INET_FORWARD) |
109 (1 << NF_INET_LOCAL_OUT),
d3c5ee6d 110 .checkentry = reject_tg6_check,
764d8a9f
PM
111 .me = THIS_MODULE
112};
113
d3c5ee6d 114static int __init reject_tg6_init(void)
764d8a9f 115{
d3c5ee6d 116 return xt_register_target(&reject_tg6_reg);
764d8a9f
PM
117}
118
d3c5ee6d 119static void __exit reject_tg6_exit(void)
764d8a9f 120{
d3c5ee6d 121 xt_unregister_target(&reject_tg6_reg);
764d8a9f
PM
122}
123
d3c5ee6d
JE
124module_init(reject_tg6_init);
125module_exit(reject_tg6_exit);