Commit ff107d27 authored by Liping Zhang's avatar Liping Zhang Committed by Pablo Neira Ayuso

netfilter: nft_log: complete NFTA_LOG_FLAGS attr support

NFTA_LOG_FLAGS attribute is already supported, but the related
NF_LOG_XXX flags are not exposed to the userspace. So we cannot
explicitly enable log flags to log uid, tcp sequence, ip options
and so on, i.e. such rule "nft add rule filter output log uid"
is not supported yet.

So move NF_LOG_XXX macro definitions to the uapi/../nf_log.h. In
order to keep consistent with other modules, change NF_LOG_MASK to
refer to all supported log flags. On the other hand, add a new
NF_LOG_DEFAULT_MASK to refer to the original default log flags.

Finally, if user specify the unsupported log flags or NFTA_LOG_GROUP
and NFTA_LOG_FLAGS are set at the same time, report EINVAL to the
userspace.
Signed-off-by: default avatarLiping Zhang <liping.zhang@spreadtrum.com>
Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
parent 0f3cd9b3
...@@ -2,15 +2,10 @@ ...@@ -2,15 +2,10 @@
#define _NF_LOG_H #define _NF_LOG_H
#include <linux/netfilter.h> #include <linux/netfilter.h>
#include <linux/netfilter/nf_log.h>
/* those NF_LOG_* defines and struct nf_loginfo are legacy definitios that will /* Log tcp sequence, tcp options, ip options and uid owning local socket */
* disappear once iptables is replaced with pkttables. Please DO NOT use them #define NF_LOG_DEFAULT_MASK 0x0f
* for any new code! */
#define NF_LOG_TCPSEQ 0x01 /* Log TCP sequence numbers */
#define NF_LOG_TCPOPT 0x02 /* Log TCP options */
#define NF_LOG_IPOPT 0x04 /* Log IP options */
#define NF_LOG_UID 0x08 /* Log UID owning local socket */
#define NF_LOG_MASK 0x0f
/* This flag indicates that copy_len field in nf_loginfo is set */ /* This flag indicates that copy_len field in nf_loginfo is set */
#define NF_LOG_F_COPY_LEN 0x1 #define NF_LOG_F_COPY_LEN 0x1
......
#ifndef _NETFILTER_NF_LOG_H
#define _NETFILTER_NF_LOG_H
#define NF_LOG_TCPSEQ 0x01 /* Log TCP sequence numbers */
#define NF_LOG_TCPOPT 0x02 /* Log TCP options */
#define NF_LOG_IPOPT 0x04 /* Log IP options */
#define NF_LOG_UID 0x08 /* Log UID owning local socket */
#define NF_LOG_NFLOG 0x10 /* Unsupported, don't reuse */
#define NF_LOG_MACDECODE 0x20 /* Decode MAC header */
#define NF_LOG_MASK 0x2f
#endif /* _NETFILTER_NF_LOG_H */
...@@ -91,7 +91,7 @@ ebt_log_packet(struct net *net, u_int8_t pf, unsigned int hooknum, ...@@ -91,7 +91,7 @@ ebt_log_packet(struct net *net, u_int8_t pf, unsigned int hooknum,
if (loginfo->type == NF_LOG_TYPE_LOG) if (loginfo->type == NF_LOG_TYPE_LOG)
bitmask = loginfo->u.log.logflags; bitmask = loginfo->u.log.logflags;
else else
bitmask = NF_LOG_MASK; bitmask = NF_LOG_DEFAULT_MASK;
if ((bitmask & EBT_LOG_IP) && eth_hdr(skb)->h_proto == if ((bitmask & EBT_LOG_IP) && eth_hdr(skb)->h_proto ==
htons(ETH_P_IP)) { htons(ETH_P_IP)) {
......
...@@ -156,7 +156,7 @@ static struct nf_loginfo trace_loginfo = { ...@@ -156,7 +156,7 @@ static struct nf_loginfo trace_loginfo = {
.u = { .u = {
.log = { .log = {
.level = 4, .level = 4,
.logflags = NF_LOG_MASK, .logflags = NF_LOG_DEFAULT_MASK,
}, },
}, },
}; };
......
...@@ -30,7 +30,7 @@ static struct nf_loginfo default_loginfo = { ...@@ -30,7 +30,7 @@ static struct nf_loginfo default_loginfo = {
.u = { .u = {
.log = { .log = {
.level = LOGLEVEL_NOTICE, .level = LOGLEVEL_NOTICE,
.logflags = NF_LOG_MASK, .logflags = NF_LOG_DEFAULT_MASK,
}, },
}, },
}; };
......
...@@ -29,7 +29,7 @@ static struct nf_loginfo default_loginfo = { ...@@ -29,7 +29,7 @@ static struct nf_loginfo default_loginfo = {
.u = { .u = {
.log = { .log = {
.level = LOGLEVEL_NOTICE, .level = LOGLEVEL_NOTICE,
.logflags = NF_LOG_MASK, .logflags = NF_LOG_DEFAULT_MASK,
}, },
}, },
}; };
...@@ -46,7 +46,7 @@ static void dump_ipv4_packet(struct nf_log_buf *m, ...@@ -46,7 +46,7 @@ static void dump_ipv4_packet(struct nf_log_buf *m,
if (info->type == NF_LOG_TYPE_LOG) if (info->type == NF_LOG_TYPE_LOG)
logflags = info->u.log.logflags; logflags = info->u.log.logflags;
else else
logflags = NF_LOG_MASK; logflags = NF_LOG_DEFAULT_MASK;
ih = skb_header_pointer(skb, iphoff, sizeof(_iph), &_iph); ih = skb_header_pointer(skb, iphoff, sizeof(_iph), &_iph);
if (ih == NULL) { if (ih == NULL) {
......
...@@ -190,7 +190,7 @@ static struct nf_loginfo trace_loginfo = { ...@@ -190,7 +190,7 @@ static struct nf_loginfo trace_loginfo = {
.u = { .u = {
.log = { .log = {
.level = LOGLEVEL_WARNING, .level = LOGLEVEL_WARNING,
.logflags = NF_LOG_MASK, .logflags = NF_LOG_DEFAULT_MASK,
}, },
}, },
}; };
......
...@@ -30,7 +30,7 @@ static struct nf_loginfo default_loginfo = { ...@@ -30,7 +30,7 @@ static struct nf_loginfo default_loginfo = {
.u = { .u = {
.log = { .log = {
.level = LOGLEVEL_NOTICE, .level = LOGLEVEL_NOTICE,
.logflags = NF_LOG_MASK, .logflags = NF_LOG_DEFAULT_MASK,
}, },
}, },
}; };
...@@ -52,7 +52,7 @@ static void dump_ipv6_packet(struct nf_log_buf *m, ...@@ -52,7 +52,7 @@ static void dump_ipv6_packet(struct nf_log_buf *m,
if (info->type == NF_LOG_TYPE_LOG) if (info->type == NF_LOG_TYPE_LOG)
logflags = info->u.log.logflags; logflags = info->u.log.logflags;
else else
logflags = NF_LOG_MASK; logflags = NF_LOG_DEFAULT_MASK;
ih = skb_header_pointer(skb, ip6hoff, sizeof(_ip6h), &_ip6h); ih = skb_header_pointer(skb, ip6hoff, sizeof(_ip6h), &_ip6h);
if (ih == NULL) { if (ih == NULL) {
......
...@@ -34,7 +34,7 @@ static struct nf_loginfo trace_loginfo = { ...@@ -34,7 +34,7 @@ static struct nf_loginfo trace_loginfo = {
.u = { .u = {
.log = { .log = {
.level = LOGLEVEL_WARNING, .level = LOGLEVEL_WARNING,
.logflags = NF_LOG_MASK, .logflags = NF_LOG_DEFAULT_MASK,
}, },
}, },
}; };
......
...@@ -58,8 +58,11 @@ static int nft_log_init(const struct nft_ctx *ctx, ...@@ -58,8 +58,11 @@ static int nft_log_init(const struct nft_ctx *ctx,
if (tb[NFTA_LOG_LEVEL] != NULL && if (tb[NFTA_LOG_LEVEL] != NULL &&
tb[NFTA_LOG_GROUP] != NULL) tb[NFTA_LOG_GROUP] != NULL)
return -EINVAL; return -EINVAL;
if (tb[NFTA_LOG_GROUP] != NULL) if (tb[NFTA_LOG_GROUP] != NULL) {
li->type = NF_LOG_TYPE_ULOG; li->type = NF_LOG_TYPE_ULOG;
if (tb[NFTA_LOG_FLAGS] != NULL)
return -EINVAL;
}
nla = tb[NFTA_LOG_PREFIX]; nla = tb[NFTA_LOG_PREFIX];
if (nla != NULL) { if (nla != NULL) {
...@@ -87,6 +90,10 @@ static int nft_log_init(const struct nft_ctx *ctx, ...@@ -87,6 +90,10 @@ static int nft_log_init(const struct nft_ctx *ctx,
if (tb[NFTA_LOG_FLAGS] != NULL) { if (tb[NFTA_LOG_FLAGS] != NULL) {
li->u.log.logflags = li->u.log.logflags =
ntohl(nla_get_be32(tb[NFTA_LOG_FLAGS])); ntohl(nla_get_be32(tb[NFTA_LOG_FLAGS]));
if (li->u.log.logflags & ~NF_LOG_MASK) {
err = -EINVAL;
goto err1;
}
} }
break; break;
case NF_LOG_TYPE_ULOG: case NF_LOG_TYPE_ULOG:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment