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

TOMOYO Linux Cross Reference
Linux/net/ipv4/netfilter/nft_dup_ipv4.c

Version: ~ [ linux-5.4-rc3 ] ~ [ linux-5.3.6 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.79 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.149 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.196 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.196 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.75 ] ~ [ 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.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/ipv4/nf_dup_ipv4.h>
 17 
 18 struct nft_dup_ipv4 {
 19         enum nft_registers      sreg_addr:8;
 20         enum nft_registers      sreg_dev:8;
 21 };
 22 
 23 static void nft_dup_ipv4_eval(const struct nft_expr *expr,
 24                               struct nft_regs *regs,
 25                               const struct nft_pktinfo *pkt)
 26 {
 27         struct nft_dup_ipv4 *priv = nft_expr_priv(expr);
 28         struct in_addr gw = {
 29                 .s_addr = (__force __be32)regs->data[priv->sreg_addr],
 30         };
 31         int oif = priv->sreg_dev ? regs->data[priv->sreg_dev] : -1;
 32 
 33         nf_dup_ipv4(nft_net(pkt), pkt->skb, nft_hook(pkt), &gw, oif);
 34 }
 35 
 36 static int nft_dup_ipv4_init(const struct nft_ctx *ctx,
 37                              const struct nft_expr *expr,
 38                              const struct nlattr * const tb[])
 39 {
 40         struct nft_dup_ipv4 *priv = nft_expr_priv(expr);
 41         int err;
 42 
 43         if (tb[NFTA_DUP_SREG_ADDR] == NULL)
 44                 return -EINVAL;
 45 
 46         priv->sreg_addr = nft_parse_register(tb[NFTA_DUP_SREG_ADDR]);
 47         err = nft_validate_register_load(priv->sreg_addr, sizeof(struct in_addr));
 48         if (err < 0)
 49                 return err;
 50 
 51         if (tb[NFTA_DUP_SREG_DEV] != NULL) {
 52                 priv->sreg_dev = nft_parse_register(tb[NFTA_DUP_SREG_DEV]);
 53                 return nft_validate_register_load(priv->sreg_dev, sizeof(int));
 54         }
 55         return 0;
 56 }
 57 
 58 static int nft_dup_ipv4_dump(struct sk_buff *skb, const struct nft_expr *expr)
 59 {
 60         struct nft_dup_ipv4 *priv = nft_expr_priv(expr);
 61 
 62         if (nft_dump_register(skb, NFTA_DUP_SREG_ADDR, priv->sreg_addr))
 63                 goto nla_put_failure;
 64         if (priv->sreg_dev &&
 65             nft_dump_register(skb, NFTA_DUP_SREG_DEV, priv->sreg_dev))
 66                 goto nla_put_failure;
 67 
 68         return 0;
 69 
 70 nla_put_failure:
 71         return -1;
 72 }
 73 
 74 static struct nft_expr_type nft_dup_ipv4_type;
 75 static const struct nft_expr_ops nft_dup_ipv4_ops = {
 76         .type           = &nft_dup_ipv4_type,
 77         .size           = NFT_EXPR_SIZE(sizeof(struct nft_dup_ipv4)),
 78         .eval           = nft_dup_ipv4_eval,
 79         .init           = nft_dup_ipv4_init,
 80         .dump           = nft_dup_ipv4_dump,
 81 };
 82 
 83 static const struct nla_policy nft_dup_ipv4_policy[NFTA_DUP_MAX + 1] = {
 84         [NFTA_DUP_SREG_ADDR]    = { .type = NLA_U32 },
 85         [NFTA_DUP_SREG_DEV]     = { .type = NLA_U32 },
 86 };
 87 
 88 static struct nft_expr_type nft_dup_ipv4_type __read_mostly = {
 89         .family         = NFPROTO_IPV4,
 90         .name           = "dup",
 91         .ops            = &nft_dup_ipv4_ops,
 92         .policy         = nft_dup_ipv4_policy,
 93         .maxattr        = NFTA_DUP_MAX,
 94         .owner          = THIS_MODULE,
 95 };
 96 
 97 static int __init nft_dup_ipv4_module_init(void)
 98 {
 99         return nft_register_expr(&nft_dup_ipv4_type);
100 }
101 
102 static void __exit nft_dup_ipv4_module_exit(void)
103 {
104         nft_unregister_expr(&nft_dup_ipv4_type);
105 }
106 
107 module_init(nft_dup_ipv4_module_init);
108 module_exit(nft_dup_ipv4_module_exit);
109 
110 MODULE_LICENSE("GPL");
111 MODULE_AUTHOR("Pablo Neira Ayuso <pablo@netfilter.org>");
112 MODULE_ALIAS_NFT_AF_EXPR(AF_INET, "dup");
113 

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