Patrick McHardy | 9651851 | 2013-10-14 11:00:02 +0200 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2008 Patrick McHardy <kaber@trash.net> |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 as |
| 6 | * published by the Free Software Foundation. |
| 7 | * |
| 8 | * Development of this code funded by Astaro AG (http://www.astaro.com/) |
| 9 | */ |
| 10 | |
| 11 | #include <linux/init.h> |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/ip.h> |
| 14 | #include <linux/netfilter_ipv4.h> |
| 15 | #include <net/netfilter/nf_tables.h> |
| 16 | #include <net/ip.h> |
| 17 | |
| 18 | static unsigned int nft_ipv4_output(const struct nf_hook_ops *ops, |
| 19 | struct sk_buff *skb, |
| 20 | const struct net_device *in, |
| 21 | const struct net_device *out, |
| 22 | int (*okfn)(struct sk_buff *)) |
| 23 | { |
| 24 | if (unlikely(skb->len < sizeof(struct iphdr) || |
| 25 | ip_hdr(skb)->ihl < sizeof(struct iphdr) / 4)) { |
| 26 | if (net_ratelimit()) |
| 27 | pr_info("nf_tables_ipv4: ignoring short SOCK_RAW " |
| 28 | "packet\n"); |
| 29 | return NF_ACCEPT; |
| 30 | } |
| 31 | |
| 32 | return nft_do_chain(ops, skb, in, out, okfn); |
| 33 | } |
| 34 | |
| 35 | static struct nft_af_info nft_af_ipv4 __read_mostly = { |
| 36 | .family = NFPROTO_IPV4, |
| 37 | .nhooks = NF_INET_NUMHOOKS, |
| 38 | .owner = THIS_MODULE, |
| 39 | .hooks = { |
| 40 | [NF_INET_LOCAL_OUT] = nft_ipv4_output, |
| 41 | }, |
| 42 | }; |
| 43 | |
| 44 | static int __init nf_tables_ipv4_init(void) |
| 45 | { |
| 46 | return nft_register_afinfo(&nft_af_ipv4); |
| 47 | } |
| 48 | |
| 49 | static void __exit nf_tables_ipv4_exit(void) |
| 50 | { |
| 51 | nft_unregister_afinfo(&nft_af_ipv4); |
| 52 | } |
| 53 | |
| 54 | module_init(nf_tables_ipv4_init); |
| 55 | module_exit(nf_tables_ipv4_exit); |
| 56 | |
| 57 | MODULE_LICENSE("GPL"); |
| 58 | MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>"); |
| 59 | MODULE_ALIAS_NFT_FAMILY(AF_INET); |