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
22 #define _NF_LOG_H
33
44 #include <linux/netfilter.h>
5+#include <linux/netfilter/nf_log.h>
56
6−/* those NF_LOG_* defines and struct nf_loginfo are legacy definitios that will
7− * disappear once iptables is replaced with pkttables. Please DO NOT use them
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
7+/* Log tcp sequence, tcp options, ip options and uid owning local socket */
8+#define NF_LOG_DEFAULT_MASK 0x0f
149
1510 /* This flag indicates that copy_len field in nf_loginfo is set */
1611 #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
9191 if (loginfo->type == NF_LOG_TYPE_LOG)
9292 bitmask = loginfo->u.log.logflags;
9393 else
94− bitmask = NF_LOG_MASK;
94+ bitmask = NF_LOG_DEFAULT_MASK;
9595
9696 if ((bitmask & EBT_LOG_IP) && eth_hdr(skb)->h_proto ==
9797 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
156156 .u = {
157157 .log = {
158158 .level = 4,
159− .logflags = NF_LOG_MASK,
159+ .logflags = NF_LOG_DEFAULT_MASK,
160160 },
161161 },
162162 };
net/ipv4/netfilter/nf_log_arp.c+1−1
@@ -30,7 +30,7 @@ static struct nf_loginfo default_loginfo = { · 29 unmodified lines
3030 .u = {
3131 .log = {
3232 .level = LOGLEVEL_NOTICE,
33− .logflags = NF_LOG_MASK,
33+ .logflags = NF_LOG_DEFAULT_MASK,
3434 },
3535 },
3636 };
net/ipv4/netfilter/nf_log_ipv4.c+2−2
@@ -29,7 +29,7 @@ static struct nf_loginfo default_loginfo = { · 28 unmodified lines
2929 .u = {
3030 .log = {
3131 .level = LOGLEVEL_NOTICE,
32− .logflags = NF_LOG_MASK,
32+ .logflags = NF_LOG_DEFAULT_MASK,
3333 },
3434 },
3535 };
@@ -46,7 +46,7 @@ static void dump_ipv4_packet(struct nf_log_buf *m, · 10 unmodified lines
4646 if (info->type == NF_LOG_TYPE_LOG)
4747 logflags = info->u.log.logflags;
4848 else
49− logflags = NF_LOG_MASK;
49+ logflags = NF_LOG_DEFAULT_MASK;
5050
5151 ih = skb_header_pointer(skb, iphoff, sizeof(_iph), &_iph);
5252 if (ih == NULL) {
net/ipv6/netfilter/ip6_tables.c+1−1
@@ -190,7 +190,7 @@ static struct nf_loginfo trace_loginfo = { · 189 unmodified lines
190190 .u = {
191191 .log = {
192192 .level = LOGLEVEL_WARNING,
193− .logflags = NF_LOG_MASK,
193+ .logflags = NF_LOG_DEFAULT_MASK,
194194 },
195195 },
196196 };
net/ipv6/netfilter/nf_log_ipv6.c+2−2
@@ -30,7 +30,7 @@ static struct nf_loginfo default_loginfo = { · 29 unmodified lines
3030 .u = {
3131 .log = {
3232 .level = LOGLEVEL_NOTICE,
33− .logflags = NF_LOG_MASK,
33+ .logflags = NF_LOG_DEFAULT_MASK,
3434 },
3535 },
3636 };
@@ -52,7 +52,7 @@ static void dump_ipv6_packet(struct nf_log_buf *m, · 15 unmodified lines
5252 if (info->type == NF_LOG_TYPE_LOG)
5353 logflags = info->u.log.logflags;
5454 else
55− logflags = NF_LOG_MASK;
55+ logflags = NF_LOG_DEFAULT_MASK;
5656
5757 ih = skb_header_pointer(skb, ip6hoff, sizeof(_ip6h), &_ip6h);
5858 if (ih == NULL) {
net/netfilter/nf_tables_core.c+1−1
@@ -34,7 +34,7 @@ static struct nf_loginfo trace_loginfo = { · 33 unmodified lines
3434 .u = {
3535 .log = {
3636 .level = LOGLEVEL_WARNING,
37− .logflags = NF_LOG_MASK,
37+ .logflags = NF_LOG_DEFAULT_MASK,
3838 },
3939 },
4040 };
net/netfilter/nft_log.c+8−1
@@ -58,8 +58,11 @@ static int nft_log_init(const struct nft_ctx *ctx, · 57 unmodified lines
5858 if (tb[NFTA_LOG_LEVEL] != NULL &&
5959 tb[NFTA_LOG_GROUP] != NULL)
6060 return -EINVAL;
61− if (tb[NFTA_LOG_GROUP] != NULL)
61+ if (tb[NFTA_LOG_GROUP] != NULL) {
6262 li->type = NF_LOG_TYPE_ULOG;
63+ if (tb[NFTA_LOG_FLAGS] != NULL)
64+ return -EINVAL;
65+ }
6366
6467 nla = tb[NFTA_LOG_PREFIX];
6568 if (nla != NULL) {
@@ -87,6 +90,10 @@ static int nft_log_init(const struct nft_ctx *ctx, · 21 unmodified lines
8790 if (tb[NFTA_LOG_FLAGS] != NULL) {
8891 li->u.log.logflags =
8992 ntohl(nla_get_be32(tb[NFTA_LOG_FLAGS]));
93+ if (li->u.log.logflags & ~NF_LOG_MASK) {
94+ err = -EINVAL;
95+ goto err1;
96+ }
9097 }
9198 break;
9299 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