1/* 2 * IPv6 raw table, a port of the IPv4 raw table to IPv6 3 * 4 * Copyright (C) 2003 Jozsef Kadlecsik <kadlec@blackhole.kfki.hu> 5 */ 6#include <linux/module.h> 7#include <linux/netfilter_ipv6/ip6_tables.h> 8#include <linux/slab.h> 9 10#define RAW_VALID_HOOKS ((1 << NF_INET_PRE_ROUTING) | (1 << NF_INET_LOCAL_OUT)) 11 12static const struct xt_table packet_raw = { 13 .name = "raw", 14 .valid_hooks = RAW_VALID_HOOKS, 15 .me = THIS_MODULE, 16 .af = NFPROTO_IPV6, 17 .priority = NF_IP6_PRI_RAW, 18}; 19 20/* The work comes in here from netfilter.c. */ 21static unsigned int 22ip6table_raw_hook(const struct nf_hook_ops *ops, struct sk_buff *skb, 23 const struct nf_hook_state *state) 24{ 25 const struct net *net = dev_net(state->in ? state->in : state->out); 26 27 return ip6t_do_table(skb, ops->hooknum, state, net->ipv6.ip6table_raw); 28} 29 30static struct nf_hook_ops *rawtable_ops __read_mostly; 31 32static int __net_init ip6table_raw_net_init(struct net *net) 33{ 34 struct ip6t_replace *repl; 35 36 repl = ip6t_alloc_initial_table(&packet_raw); 37 if (repl == NULL) 38 return -ENOMEM; 39 net->ipv6.ip6table_raw = 40 ip6t_register_table(net, &packet_raw, repl); 41 kfree(repl); 42 return PTR_ERR_OR_ZERO(net->ipv6.ip6table_raw); 43} 44 45static void __net_exit ip6table_raw_net_exit(struct net *net) 46{ 47 ip6t_unregister_table(net, net->ipv6.ip6table_raw); 48} 49 50static struct pernet_operations ip6table_raw_net_ops = { 51 .init = ip6table_raw_net_init, 52 .exit = ip6table_raw_net_exit, 53}; 54 55static int __init ip6table_raw_init(void) 56{ 57 int ret; 58 59 ret = register_pernet_subsys(&ip6table_raw_net_ops); 60 if (ret < 0) 61 return ret; 62 63 /* Register hooks */ 64 rawtable_ops = xt_hook_link(&packet_raw, ip6table_raw_hook); 65 if (IS_ERR(rawtable_ops)) { 66 ret = PTR_ERR(rawtable_ops); 67 goto cleanup_table; 68 } 69 70 return ret; 71 72 cleanup_table: 73 unregister_pernet_subsys(&ip6table_raw_net_ops); 74 return ret; 75} 76 77static void __exit ip6table_raw_fini(void) 78{ 79 xt_hook_unlink(&packet_raw, rawtable_ops); 80 unregister_pernet_subsys(&ip6table_raw_net_ops); 81} 82 83module_init(ip6table_raw_init); 84module_exit(ip6table_raw_fini); 85MODULE_LICENSE("GPL"); 86