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

TOMOYO Linux Cross Reference
Linux/net/netfilter/nft_log.c

Version: ~ [ linux-5.12-rc7 ] ~ [ linux-5.11.13 ] ~ [ linux-5.10.29 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.111 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.186 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.230 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.266 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.266 ] ~ [ 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) 2008-2009 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/kernel.h>
 12 #include <linux/init.h>
 13 #include <linux/module.h>
 14 #include <linux/netlink.h>
 15 #include <linux/netfilter.h>
 16 #include <linux/netfilter/nf_tables.h>
 17 #include <net/netfilter/nf_tables.h>
 18 #include <net/netfilter/nf_log.h>
 19 #include <linux/netdevice.h>
 20 
 21 static const char *nft_log_null_prefix = "";
 22 
 23 struct nft_log {
 24         struct nf_loginfo       loginfo;
 25         char                    *prefix;
 26 };
 27 
 28 static void nft_log_eval(const struct nft_expr *expr,
 29                          struct nft_data data[NFT_REG_MAX + 1],
 30                          const struct nft_pktinfo *pkt)
 31 {
 32         const struct nft_log *priv = nft_expr_priv(expr);
 33         struct net *net = dev_net(pkt->in ? pkt->in : pkt->out);
 34 
 35         nf_log_packet(net, pkt->ops->pf, pkt->ops->hooknum, pkt->skb, pkt->in,
 36                       pkt->out, &priv->loginfo, "%s", priv->prefix);
 37 }
 38 
 39 static const struct nla_policy nft_log_policy[NFTA_LOG_MAX + 1] = {
 40         [NFTA_LOG_GROUP]        = { .type = NLA_U16 },
 41         [NFTA_LOG_PREFIX]       = { .type = NLA_STRING,
 42                                     .len = NF_LOG_PREFIXLEN - 1 },
 43         [NFTA_LOG_SNAPLEN]      = { .type = NLA_U32 },
 44         [NFTA_LOG_QTHRESHOLD]   = { .type = NLA_U16 },
 45 };
 46 
 47 static int nft_log_init(const struct nft_ctx *ctx,
 48                         const struct nft_expr *expr,
 49                         const struct nlattr * const tb[])
 50 {
 51         struct nft_log *priv = nft_expr_priv(expr);
 52         struct nf_loginfo *li = &priv->loginfo;
 53         const struct nlattr *nla;
 54 
 55         nla = tb[NFTA_LOG_PREFIX];
 56         if (nla != NULL) {
 57                 priv->prefix = kmalloc(nla_len(nla) + 1, GFP_KERNEL);
 58                 if (priv->prefix == NULL)
 59                         return -ENOMEM;
 60                 nla_strlcpy(priv->prefix, nla, nla_len(nla) + 1);
 61         } else
 62                 priv->prefix = (char *)nft_log_null_prefix;
 63 
 64         li->type = NF_LOG_TYPE_ULOG;
 65         if (tb[NFTA_LOG_GROUP] != NULL)
 66                 li->u.ulog.group = ntohs(nla_get_be16(tb[NFTA_LOG_GROUP]));
 67 
 68         if (tb[NFTA_LOG_SNAPLEN] != NULL)
 69                 li->u.ulog.copy_len = ntohl(nla_get_be32(tb[NFTA_LOG_SNAPLEN]));
 70         if (tb[NFTA_LOG_QTHRESHOLD] != NULL) {
 71                 li->u.ulog.qthreshold =
 72                         ntohs(nla_get_be16(tb[NFTA_LOG_QTHRESHOLD]));
 73         }
 74 
 75         return 0;
 76 }
 77 
 78 static void nft_log_destroy(const struct nft_ctx *ctx,
 79                             const struct nft_expr *expr)
 80 {
 81         struct nft_log *priv = nft_expr_priv(expr);
 82 
 83         if (priv->prefix != nft_log_null_prefix)
 84                 kfree(priv->prefix);
 85 }
 86 
 87 static int nft_log_dump(struct sk_buff *skb, const struct nft_expr *expr)
 88 {
 89         const struct nft_log *priv = nft_expr_priv(expr);
 90         const struct nf_loginfo *li = &priv->loginfo;
 91 
 92         if (priv->prefix != nft_log_null_prefix)
 93                 if (nla_put_string(skb, NFTA_LOG_PREFIX, priv->prefix))
 94                         goto nla_put_failure;
 95         if (li->u.ulog.group)
 96                 if (nla_put_be16(skb, NFTA_LOG_GROUP, htons(li->u.ulog.group)))
 97                         goto nla_put_failure;
 98         if (li->u.ulog.copy_len)
 99                 if (nla_put_be32(skb, NFTA_LOG_SNAPLEN,
100                                  htonl(li->u.ulog.copy_len)))
101                         goto nla_put_failure;
102         if (li->u.ulog.qthreshold)
103                 if (nla_put_be16(skb, NFTA_LOG_QTHRESHOLD,
104                                  htons(li->u.ulog.qthreshold)))
105                         goto nla_put_failure;
106         return 0;
107 
108 nla_put_failure:
109         return -1;
110 }
111 
112 static struct nft_expr_type nft_log_type;
113 static const struct nft_expr_ops nft_log_ops = {
114         .type           = &nft_log_type,
115         .size           = NFT_EXPR_SIZE(sizeof(struct nft_log)),
116         .eval           = nft_log_eval,
117         .init           = nft_log_init,
118         .destroy        = nft_log_destroy,
119         .dump           = nft_log_dump,
120 };
121 
122 static struct nft_expr_type nft_log_type __read_mostly = {
123         .name           = "log",
124         .ops            = &nft_log_ops,
125         .policy         = nft_log_policy,
126         .maxattr        = NFTA_LOG_MAX,
127         .owner          = THIS_MODULE,
128 };
129 
130 static int __init nft_log_module_init(void)
131 {
132         return nft_register_expr(&nft_log_type);
133 }
134 
135 static void __exit nft_log_module_exit(void)
136 {
137         nft_unregister_expr(&nft_log_type);
138 }
139 
140 module_init(nft_log_module_init);
141 module_exit(nft_log_module_exit);
142 
143 MODULE_LICENSE("GPL");
144 MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
145 MODULE_ALIAS_NFT_EXPR("log");
146 

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