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

TOMOYO Linux Cross Reference
Linux/net/netfilter/nft_reject.c

Version: ~ [ linux-5.1-rc6 ] ~ [ linux-5.0.9 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.36 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.113 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.170 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.178 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.138 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.65 ] ~ [ 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.39.4 ] ~ [ linux-2.6.38.8 ] ~ [ linux-2.6.37.6 ] ~ [ linux-2.6.36.4 ] ~ [ linux-2.6.35.14 ] ~ [ linux-2.6.34.15 ] ~ [ linux-2.6.33.20 ] ~ [ 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-2009 Patrick McHardy <kaber@trash.net>
  3  * Copyright (c) 2013 Eric Leblond <eric@regit.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/kernel.h>
 13 #include <linux/init.h>
 14 #include <linux/module.h>
 15 #include <linux/netlink.h>
 16 #include <linux/netfilter.h>
 17 #include <linux/netfilter/nf_tables.h>
 18 #include <net/netfilter/nf_tables.h>
 19 #include <net/netfilter/nft_reject.h>
 20 #include <linux/icmp.h>
 21 #include <linux/icmpv6.h>
 22 
 23 const struct nla_policy nft_reject_policy[NFTA_REJECT_MAX + 1] = {
 24         [NFTA_REJECT_TYPE]              = { .type = NLA_U32 },
 25         [NFTA_REJECT_ICMP_CODE]         = { .type = NLA_U8 },
 26 };
 27 EXPORT_SYMBOL_GPL(nft_reject_policy);
 28 
 29 int nft_reject_init(const struct nft_ctx *ctx,
 30                     const struct nft_expr *expr,
 31                     const struct nlattr * const tb[])
 32 {
 33         struct nft_reject *priv = nft_expr_priv(expr);
 34 
 35         if (tb[NFTA_REJECT_TYPE] == NULL)
 36                 return -EINVAL;
 37 
 38         priv->type = ntohl(nla_get_be32(tb[NFTA_REJECT_TYPE]));
 39         switch (priv->type) {
 40         case NFT_REJECT_ICMP_UNREACH:
 41                 if (tb[NFTA_REJECT_ICMP_CODE] == NULL)
 42                         return -EINVAL;
 43                 priv->icmp_code = nla_get_u8(tb[NFTA_REJECT_ICMP_CODE]);
 44         case NFT_REJECT_TCP_RST:
 45                 break;
 46         default:
 47                 return -EINVAL;
 48         }
 49 
 50         return 0;
 51 }
 52 EXPORT_SYMBOL_GPL(nft_reject_init);
 53 
 54 int nft_reject_dump(struct sk_buff *skb, const struct nft_expr *expr)
 55 {
 56         const struct nft_reject *priv = nft_expr_priv(expr);
 57 
 58         if (nla_put_be32(skb, NFTA_REJECT_TYPE, htonl(priv->type)))
 59                 goto nla_put_failure;
 60 
 61         switch (priv->type) {
 62         case NFT_REJECT_ICMP_UNREACH:
 63                 if (nla_put_u8(skb, NFTA_REJECT_ICMP_CODE, priv->icmp_code))
 64                         goto nla_put_failure;
 65                 break;
 66         default:
 67                 break;
 68         }
 69 
 70         return 0;
 71 
 72 nla_put_failure:
 73         return -1;
 74 }
 75 EXPORT_SYMBOL_GPL(nft_reject_dump);
 76 
 77 static u8 icmp_code_v4[NFT_REJECT_ICMPX_MAX + 1] = {
 78         [NFT_REJECT_ICMPX_NO_ROUTE]             = ICMP_NET_UNREACH,
 79         [NFT_REJECT_ICMPX_PORT_UNREACH]         = ICMP_PORT_UNREACH,
 80         [NFT_REJECT_ICMPX_HOST_UNREACH]         = ICMP_HOST_UNREACH,
 81         [NFT_REJECT_ICMPX_ADMIN_PROHIBITED]     = ICMP_PKT_FILTERED,
 82 };
 83 
 84 int nft_reject_icmp_code(u8 code)
 85 {
 86         BUG_ON(code > NFT_REJECT_ICMPX_MAX);
 87 
 88         return icmp_code_v4[code];
 89 }
 90 
 91 EXPORT_SYMBOL_GPL(nft_reject_icmp_code);
 92 
 93 
 94 static u8 icmp_code_v6[NFT_REJECT_ICMPX_MAX + 1] = {
 95         [NFT_REJECT_ICMPX_NO_ROUTE]             = ICMPV6_NOROUTE,
 96         [NFT_REJECT_ICMPX_PORT_UNREACH]         = ICMPV6_PORT_UNREACH,
 97         [NFT_REJECT_ICMPX_HOST_UNREACH]         = ICMPV6_ADDR_UNREACH,
 98         [NFT_REJECT_ICMPX_ADMIN_PROHIBITED]     = ICMPV6_ADM_PROHIBITED,
 99 };
100 
101 int nft_reject_icmpv6_code(u8 code)
102 {
103         BUG_ON(code > NFT_REJECT_ICMPX_MAX);
104 
105         return icmp_code_v6[code];
106 }
107 
108 EXPORT_SYMBOL_GPL(nft_reject_icmpv6_code);
109 
110 MODULE_LICENSE("GPL");
111 MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
112 

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