History

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.

Liping Zhang committed 10 years ago

Commit ff107d21 parent 0f3cd9b10 files · +32 −18Browse files

Unified · Split

10 files
  1. include/net/netfilter/nf_log.h +3 −8
  2. include/uapi/linux/netfilter/nf_log.h +12 −0
  3. net/bridge/netfilter/ebt_log.c +1 −1
  4. net/ipv4/netfilter/ip_tables.c +1 −1
  5. net/ipv4/netfilter/nf_log_arp.c +1 −1
  6. net/ipv4/netfilter/nf_log_ipv4.c +2 −2
  7. net/ipv6/netfilter/ip6_tables.c +1 −1
  8. net/ipv6/netfilter/nf_log_ipv6.c +2 −2
  9. net/netfilter/nf_tables_core.c +1 −1
  10. net/netfilter/nft_log.c +8 −1
include/net/netfilter/nf_log.h+3−8
@@ -2,15 +2,10 @@ · 1 unmodified line
2#define _NF_LOG_H2#define _NF_LOG_H
3 3
4#include <linux/netfilter.h>4#include <linux/netfilter.h>
5#include <linux/netfilter/nf_log.h>
5 6
6/* those NF_LOG_* defines and struct nf_loginfo are legacy definitios that will7/* Log tcp sequence, tcp options, ip options and uid owning local socket */
7 * disappear once iptables is replaced with pkttables. Please DO NOT use them8#define NF_LOG_DEFAULT_MASK 0x0f
8 * for any new code! */
9#define NF_LOG_TCPSEQ 0x01 /* Log TCP sequence numbers */
10#define NF_LOG_TCPOPT 0x02 /* Log TCP options */
11#define NF_LOG_IPOPT 0x04 /* Log IP options */
12#define NF_LOG_UID 0x08 /* Log UID owning local socket */
13#define NF_LOG_MASK 0x0f
14 9
15/* This flag indicates that copy_len field in nf_loginfo is set */10/* This flag indicates that copy_len field in nf_loginfo is set */
16#define NF_LOG_F_COPY_LEN 0x111#define NF_LOG_F_COPY_LEN 0x1
include/uapi/linux/netfilter/nf_log.h+12−0
@@ -0,0 +1,12 @@
1#ifndef _NETFILTER_NF_LOG_H
2#define _NETFILTER_NF_LOG_H
3
4#define NF_LOG_TCPSEQ 0x01 /* Log TCP sequence numbers */
5#define NF_LOG_TCPOPT 0x02 /* Log TCP options */
6#define NF_LOG_IPOPT 0x04 /* Log IP options */
7#define NF_LOG_UID 0x08 /* Log UID owning local socket */
8#define NF_LOG_NFLOG 0x10 /* Unsupported, don't reuse */
9#define NF_LOG_MACDECODE 0x20 /* Decode MAC header */
10#define NF_LOG_MASK 0x2f
11
12#endif /* _NETFILTER_NF_LOG_H */
net/bridge/netfilter/ebt_log.c+1−1
@@ -91,7 +91,7 @@ ebt_log_packet(struct net *net, u_int8_t pf, unsigned int hooknum, · 90 unmodified lines
91 if (loginfo->type == NF_LOG_TYPE_LOG)91 if (loginfo->type == NF_LOG_TYPE_LOG)
92 bitmask = loginfo->u.log.logflags;92 bitmask = loginfo->u.log.logflags;
93 else93 else
94 bitmask = NF_LOG_MASK;94 bitmask = NF_LOG_DEFAULT_MASK;
95 95
96 if ((bitmask & EBT_LOG_IP) && eth_hdr(skb)->h_proto ==96 if ((bitmask & EBT_LOG_IP) && eth_hdr(skb)->h_proto ==
97 htons(ETH_P_IP)) {97 htons(ETH_P_IP)) {
net/ipv4/netfilter/ip_tables.c+1−1
@@ -156,7 +156,7 @@ static struct nf_loginfo trace_loginfo = { · 155 unmodified lines
156 .u = {156 .u = {
157 .log = {157 .log = {
158 .level = 4,158 .level = 4,
159 .logflags = NF_LOG_MASK,159 .logflags = NF_LOG_DEFAULT_MASK,
160 },160 },
161 },161 },
162};162};
net/ipv4/netfilter/nf_log_arp.c+1−1
@@ -30,7 +30,7 @@ static struct nf_loginfo default_loginfo = { · 29 unmodified lines
30 .u = {30 .u = {
31 .log = {31 .log = {
32 .level = LOGLEVEL_NOTICE,32 .level = LOGLEVEL_NOTICE,
33 .logflags = NF_LOG_MASK,33 .logflags = NF_LOG_DEFAULT_MASK,
34 },34 },
35 },35 },
36};36};
net/ipv4/netfilter/nf_log_ipv4.c+2−2
@@ -29,7 +29,7 @@ static struct nf_loginfo default_loginfo = { · 28 unmodified lines
29 .u = {29 .u = {
30 .log = {30 .log = {
31 .level = LOGLEVEL_NOTICE,31 .level = LOGLEVEL_NOTICE,
32 .logflags = NF_LOG_MASK,32 .logflags = NF_LOG_DEFAULT_MASK,
33 },33 },
34 },34 },
35};35};
@@ -46,7 +46,7 @@ static void dump_ipv4_packet(struct nf_log_buf *m, · 10 unmodified lines
46 if (info->type == NF_LOG_TYPE_LOG)46 if (info->type == NF_LOG_TYPE_LOG)
47 logflags = info->u.log.logflags;47 logflags = info->u.log.logflags;
48 else48 else
49 logflags = NF_LOG_MASK;49 logflags = NF_LOG_DEFAULT_MASK;
50 50
51 ih = skb_header_pointer(skb, iphoff, sizeof(_iph), &_iph);51 ih = skb_header_pointer(skb, iphoff, sizeof(_iph), &_iph);
52 if (ih == NULL) {52 if (ih == NULL) {
net/ipv6/netfilter/ip6_tables.c+1−1
@@ -190,7 +190,7 @@ static struct nf_loginfo trace_loginfo = { · 189 unmodified lines
190 .u = {190 .u = {
191 .log = {191 .log = {
192 .level = LOGLEVEL_WARNING,192 .level = LOGLEVEL_WARNING,
193 .logflags = NF_LOG_MASK,193 .logflags = NF_LOG_DEFAULT_MASK,
194 },194 },
195 },195 },
196};196};
net/ipv6/netfilter/nf_log_ipv6.c+2−2
@@ -30,7 +30,7 @@ static struct nf_loginfo default_loginfo = { · 29 unmodified lines
30 .u = {30 .u = {
31 .log = {31 .log = {
32 .level = LOGLEVEL_NOTICE,32 .level = LOGLEVEL_NOTICE,
33 .logflags = NF_LOG_MASK,33 .logflags = NF_LOG_DEFAULT_MASK,
34 },34 },
35 },35 },
36};36};
@@ -52,7 +52,7 @@ static void dump_ipv6_packet(struct nf_log_buf *m, · 15 unmodified lines
52 if (info->type == NF_LOG_TYPE_LOG)52 if (info->type == NF_LOG_TYPE_LOG)
53 logflags = info->u.log.logflags;53 logflags = info->u.log.logflags;
54 else54 else
55 logflags = NF_LOG_MASK;55 logflags = NF_LOG_DEFAULT_MASK;
56 56
57 ih = skb_header_pointer(skb, ip6hoff, sizeof(_ip6h), &_ip6h);57 ih = skb_header_pointer(skb, ip6hoff, sizeof(_ip6h), &_ip6h);
58 if (ih == NULL) {58 if (ih == NULL) {
net/netfilter/nf_tables_core.c+1−1
@@ -34,7 +34,7 @@ static struct nf_loginfo trace_loginfo = { · 33 unmodified lines
34 .u = {34 .u = {
35 .log = {35 .log = {
36 .level = LOGLEVEL_WARNING,36 .level = LOGLEVEL_WARNING,
37 .logflags = NF_LOG_MASK,37 .logflags = NF_LOG_DEFAULT_MASK,
38 },38 },
39 },39 },
40};40};
net/netfilter/nft_log.c+8−1
@@ -58,8 +58,11 @@ static int nft_log_init(const struct nft_ctx *ctx, · 57 unmodified lines
58 if (tb[NFTA_LOG_LEVEL] != NULL &&58 if (tb[NFTA_LOG_LEVEL] != NULL &&
59 tb[NFTA_LOG_GROUP] != NULL)59 tb[NFTA_LOG_GROUP] != NULL)
60 return -EINVAL;60 return -EINVAL;
61 if (tb[NFTA_LOG_GROUP] != NULL)61 if (tb[NFTA_LOG_GROUP] != NULL) {
62 li->type = NF_LOG_TYPE_ULOG;62 li->type = NF_LOG_TYPE_ULOG;
63 if (tb[NFTA_LOG_FLAGS] != NULL)
64 return -EINVAL;
65 }
63 66
64 nla = tb[NFTA_LOG_PREFIX];67 nla = tb[NFTA_LOG_PREFIX];
65 if (nla != NULL) {68 if (nla != NULL) {
@@ -87,6 +90,10 @@ static int nft_log_init(const struct nft_ctx *ctx, · 21 unmodified lines
87 if (tb[NFTA_LOG_FLAGS] != NULL) {90 if (tb[NFTA_LOG_FLAGS] != NULL) {
88 li->u.log.logflags =91 li->u.log.logflags =
89 ntohl(nla_get_be32(tb[NFTA_LOG_FLAGS]));92 ntohl(nla_get_be32(tb[NFTA_LOG_FLAGS]));
93 if (li->u.log.logflags & ~NF_LOG_MASK) {
94 err = -EINVAL;
95 goto err1;
96 }
90 }97 }
91 break;98 break;
92 case NF_LOG_TYPE_ULOG:99 case NF_LOG_TYPE_ULOG:

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t