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

TOMOYO Linux Cross Reference
Linux/net/ipv6/netfilter/nft_dup_ipv6.c

Version: ~ [ linux-5.16 ] ~ [ linux-5.15.13 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.90 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.170 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.224 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.261 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.296 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.298 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.18.140 ] ~ [ linux-3.16.85 ] ~ [ linux-3.14.79 ] ~ [ linux-3.12.74 ] ~ [ linux-3.10.108 ] ~ [ 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) 2015 Pablo Neira Ayuso <pablo@netfilter.org>
  3  *
  4  * This program is free software; you can redistribute it and/or modify it
  5  * under the terms of the GNU General Public License version 2 as published by
  6  * the Free Software Foundation.
  7  */
  8 
  9 #include <linux/kernel.h>
 10 #include <linux/init.h>
 11 #include <linux/module.h>
 12 #include <linux/netlink.h>
 13 #include <linux/netfilter.h>
 14 #include <linux/netfilter/nf_tables.h>
 15 #include <net/netfilter/nf_tables.h>
 16 #include <net/netfilter/ipv6/nf_dup_ipv6.h>
 17 
 18 struct nft_dup_ipv6 {
 19         enum nft_registers      sreg_addr:8;
 20         enum nft_registers      sreg_dev:8;
 21 };
 22 
 23 static void nft_dup_ipv6_eval(const struct nft_expr *expr,
 24                               struct nft_regs *regs,
 25                               const struct nft_pktinfo *pkt)
 26 {
 27         struct nft_dup_ipv6 *priv = nft_expr_priv(expr);
 28         struct in6_addr *gw = (struct in6_addr *)&regs->data[priv->sreg_addr];
 29         int oif = priv->sreg_dev ? regs->data[priv->sreg_dev] : -1;
 30 
 31         nf_dup_ipv6(nft_net(pkt), pkt->skb, nft_hook(pkt), gw, oif);
 32 }
 33 
 34 static int nft_dup_ipv6_init(const struct nft_ctx *ctx,
 35                              const struct nft_expr *expr,
 36                              const struct nlattr * const tb[])
 37 {
 38         struct nft_dup_ipv6 *priv = nft_expr_priv(expr);
 39         int err;
 40 
 41         if (tb[NFTA_DUP_SREG_ADDR] == NULL)
 42                 return -EINVAL;
 43 
 44         priv->sreg_addr = nft_parse_register(tb[NFTA_DUP_SREG_ADDR]);
 45         err = nft_validate_register_load(priv->sreg_addr, sizeof(struct in6_addr));
 46         if (err < 0)
 47                 return err;
 48 
 49         if (tb[NFTA_DUP_SREG_DEV] != NULL) {
 50                 priv->sreg_dev = nft_parse_register(tb[NFTA_DUP_SREG_DEV]);
 51                 return nft_validate_register_load(priv->sreg_dev, sizeof(int));
 52         }
 53         return 0;
 54 }
 55 
 56 static int nft_dup_ipv6_dump(struct sk_buff *skb, const struct nft_expr *expr)
 57 {
 58         struct nft_dup_ipv6 *priv = nft_expr_priv(expr);
 59 
 60         if (nft_dump_register(skb, NFTA_DUP_SREG_ADDR, priv->sreg_addr))
 61                 goto nla_put_failure;
 62         if (priv->sreg_dev &&
 63             nft_dump_register(skb, NFTA_DUP_SREG_DEV, priv->sreg_dev))
 64                 goto nla_put_failure;
 65 
 66         return 0;
 67 
 68 nla_put_failure:
 69         return -1;
 70 }
 71 
 72 static struct nft_expr_type nft_dup_ipv6_type;
 73 static const struct nft_expr_ops nft_dup_ipv6_ops = {
 74         .type           = &nft_dup_ipv6_type,
 75         .size           = NFT_EXPR_SIZE(sizeof(struct nft_dup_ipv6)),
 76         .eval           = nft_dup_ipv6_eval,
 77         .init           = nft_dup_ipv6_init,
 78         .dump           = nft_dup_ipv6_dump,
 79 };
 80 
 81 static const struct nla_policy nft_dup_ipv6_policy[NFTA_DUP_MAX + 1] = {
 82         [NFTA_DUP_SREG_ADDR]    = { .type = NLA_U32 },
 83         [NFTA_DUP_SREG_DEV]     = { .type = NLA_U32 },
 84 };
 85 
 86 static struct nft_expr_type nft_dup_ipv6_type __read_mostly = {
 87         .family         = NFPROTO_IPV6,
 88         .name           = "dup",
 89         .ops            = &nft_dup_ipv6_ops,
 90         .policy         = nft_dup_ipv6_policy,
 91         .maxattr        = NFTA_DUP_MAX,
 92         .owner          = THIS_MODULE,
 93 };
 94 
 95 static int __init nft_dup_ipv6_module_init(void)
 96 {
 97         return nft_register_expr(&nft_dup_ipv6_type);
 98 }
 99 
100 static void __exit nft_dup_ipv6_module_exit(void)
101 {
102         nft_unregister_expr(&nft_dup_ipv6_type);
103 }
104 
105 module_init(nft_dup_ipv6_module_init);
106 module_exit(nft_dup_ipv6_module_exit);
107 
108 MODULE_LICENSE("GPL");
109 MODULE_AUTHOR("Pablo Neira Ayuso <pablo@netfilter.org>");
110 MODULE_ALIAS_NFT_AF_EXPR(AF_INET6, "dup");
111 

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