Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at v5.0-rc4 124 lines 3.2 kB view raw
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 23const 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}; 27EXPORT_SYMBOL_GPL(nft_reject_policy); 28 29int nft_reject_validate(const struct nft_ctx *ctx, 30 const struct nft_expr *expr, 31 const struct nft_data **data) 32{ 33 return nft_chain_validate_hooks(ctx->chain, 34 (1 << NF_INET_LOCAL_IN) | 35 (1 << NF_INET_FORWARD) | 36 (1 << NF_INET_LOCAL_OUT)); 37} 38EXPORT_SYMBOL_GPL(nft_reject_validate); 39 40int nft_reject_init(const struct nft_ctx *ctx, 41 const struct nft_expr *expr, 42 const struct nlattr * const tb[]) 43{ 44 struct nft_reject *priv = nft_expr_priv(expr); 45 46 if (tb[NFTA_REJECT_TYPE] == NULL) 47 return -EINVAL; 48 49 priv->type = ntohl(nla_get_be32(tb[NFTA_REJECT_TYPE])); 50 switch (priv->type) { 51 case NFT_REJECT_ICMP_UNREACH: 52 if (tb[NFTA_REJECT_ICMP_CODE] == NULL) 53 return -EINVAL; 54 priv->icmp_code = nla_get_u8(tb[NFTA_REJECT_ICMP_CODE]); 55 case NFT_REJECT_TCP_RST: 56 break; 57 default: 58 return -EINVAL; 59 } 60 61 return 0; 62} 63EXPORT_SYMBOL_GPL(nft_reject_init); 64 65int nft_reject_dump(struct sk_buff *skb, const struct nft_expr *expr) 66{ 67 const struct nft_reject *priv = nft_expr_priv(expr); 68 69 if (nla_put_be32(skb, NFTA_REJECT_TYPE, htonl(priv->type))) 70 goto nla_put_failure; 71 72 switch (priv->type) { 73 case NFT_REJECT_ICMP_UNREACH: 74 if (nla_put_u8(skb, NFTA_REJECT_ICMP_CODE, priv->icmp_code)) 75 goto nla_put_failure; 76 break; 77 default: 78 break; 79 } 80 81 return 0; 82 83nla_put_failure: 84 return -1; 85} 86EXPORT_SYMBOL_GPL(nft_reject_dump); 87 88static u8 icmp_code_v4[NFT_REJECT_ICMPX_MAX + 1] = { 89 [NFT_REJECT_ICMPX_NO_ROUTE] = ICMP_NET_UNREACH, 90 [NFT_REJECT_ICMPX_PORT_UNREACH] = ICMP_PORT_UNREACH, 91 [NFT_REJECT_ICMPX_HOST_UNREACH] = ICMP_HOST_UNREACH, 92 [NFT_REJECT_ICMPX_ADMIN_PROHIBITED] = ICMP_PKT_FILTERED, 93}; 94 95int nft_reject_icmp_code(u8 code) 96{ 97 if (WARN_ON_ONCE(code > NFT_REJECT_ICMPX_MAX)) 98 return ICMP_NET_UNREACH; 99 100 return icmp_code_v4[code]; 101} 102 103EXPORT_SYMBOL_GPL(nft_reject_icmp_code); 104 105 106static u8 icmp_code_v6[NFT_REJECT_ICMPX_MAX + 1] = { 107 [NFT_REJECT_ICMPX_NO_ROUTE] = ICMPV6_NOROUTE, 108 [NFT_REJECT_ICMPX_PORT_UNREACH] = ICMPV6_PORT_UNREACH, 109 [NFT_REJECT_ICMPX_HOST_UNREACH] = ICMPV6_ADDR_UNREACH, 110 [NFT_REJECT_ICMPX_ADMIN_PROHIBITED] = ICMPV6_ADM_PROHIBITED, 111}; 112 113int nft_reject_icmpv6_code(u8 code) 114{ 115 if (WARN_ON_ONCE(code > NFT_REJECT_ICMPX_MAX)) 116 return ICMPV6_NOROUTE; 117 118 return icmp_code_v6[code]; 119} 120 121EXPORT_SYMBOL_GPL(nft_reject_icmpv6_code); 122 123MODULE_LICENSE("GPL"); 124MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");