Skip to contentSkip to conversation

: Netfilter update + minor fixes

PATCH Applied Patrick McHardy 3 participants 26 messages Jan 18, 2008 – Feb 19, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover : Netfilter update + minor fixes

These patches restructure the libnl nfnetlink_log code as discussed earlier by splitting it into two seperate object types, one to represent the log instance and one for the actual messages. They also add support for nfnetlink_queue, which follows the same pattern, and for basic conntrack requests (add/delete/query).

Additionally they contains a few minor fixes that don't relate to netfilter, but I had them queued in the same tree, so I've included them for simplicity.

Comments and/or applying welcome :)

 include/Makefile                          |    2 +
 include/linux/if_vlan.h                   |   61 ++++
 include/linux/netfilter.h                 |   39 +++
 include/linux/netfilter/nfnetlink_log.h   |    1 +
 include/linux/netfilter/nfnetlink_queue.h |   94 ++++++
 include/netlink-types.h                   |   78 ++++-
 include/netlink/netfilter/ct.h            |    9 +
 include/netlink/netfilter/log.h           |  110 ++++----
 include/netlink/netfilter/log_msg.h       |   98 ++++++
 include/netlink/netfilter/netfilter.h     |   31 ++
 include/netlink/netfilter/queue.h         |   86 +++++
 include/netlink/netfilter/queue_msg.h     |  101 ++++++
 lib/netfilter/ct.c                        |  153 +++++++++
 lib/netfilter/log.c                       |  325 +++++++-------------
 lib/netfilter/log_msg.c                   |  218 +++++++++++++
 lib/netfilter/log_msg_obj.c               |  456 +++++++++++++++++++++++++++
 lib/netfilter/log_obj.c                   |  420 +++++++++-----------------
 lib/netfilter/netfilter.c                 |   53 ++++
 lib/netfilter/queue.c                     |  233 ++++++++++++++
 lib/netfilter/queue_msg.c                 |  240 ++++++++++++++
 lib/netfilter/queue_msg_obj.c             |  480 +++++++++++++++++++++++++++++
 lib/netfilter/queue_obj.c                 |  213 +++++++++++++
 lib/route/route_utils.c                   |   10 +
 src/nf-log.c                              |   55 +++-
 src/{nf-log.c => nf-queue.c}              |   64 +++-
 25 files changed, 3038 insertions(+), 592 deletions(-)
 create mode 100644 include/linux/if_vlan.h
 create mode 100644 include/linux/netfilter.h
 create mode 100644 include/linux/netfilter/nfnetlink_queue.h
 create mode 100644 include/netlink/netfilter/log_msg.h
 create mode 100644 include/netlink/netfilter/netfilter.h
 create mode 100644 include/netlink/netfilter/queue.h
 create mode 100644 include/netlink/netfilter/queue_msg.h
 create mode 100644 lib/netfilter/log_msg.c
 create mode 100644 lib/netfilter/log_msg_obj.c
 create mode 100644 lib/netfilter/netfilter.c
 create mode 100644 lib/netfilter/queue.c
 create mode 100644 lib/netfilter/queue_msg.c
 create mode 100644 lib/netfilter/queue_msg_obj.c
 create mode 100644 lib/netfilter/queue_obj.c
 copy src/{nf-log.c => nf-queue.c} (63%)

Patrick McHardy (9):
[LIBNL]: Add if_vlan.h
[LIBNL]: Fix minor memleaks on exit
[LIBNL]: Generic netfilter stuff
[LIBNL]: Add nfnetlink_queue support
[LIBNL]: nfnetlink_log: only set hwproto if not zero [LIBNL]: nfnetlink_log: support NUFLA_GID attribute [LIBNL]: Split up nfnetlink_log into log and msg objects [LIBNL]: Support conntrack add/delete/query requests [LIBNL]: Install netfilter headers

#1 lore raw

PATCH 1/9 : Add if_vlan.h

commit 057316c354252ef6273f6deb4fe4232c02e4d141

Author: Patrick McHardy <[email protected]>
Date:   Fri Jan 18 16:15:53 2008 +0100

[LIBNL]: Add if_vlan.h

vlan support needs VLAN_FLAG_REORDER_HDR, which is not available in older if_vlan.h versions. Add the current version from the kernel.

include/linux/if_vlan.h new file +61 -0
new file mode 100644
index 0000000..a1dbeec
@@ -0,0 +1,61 @@
+/*
+ * VLAN		An implementation of 802.1Q VLAN tagging.
+ *
+ * Authors:	Ben Greear <[email protected]>
+ *
+ *		This program is free software; you can redistribute it and/or
+ *		modify it under the terms of the GNU General Public License
+ *		as published by the Free Software Foundation; either version
+ *		2 of the License, or (at your option) any later version.
+ *
+ */
+
+#ifndef _LINUX_IF_VLAN_H_
+#define _LINUX_IF_VLAN_H_
+
+
+/* VLAN IOCTLs are found in sockios.h */
+
+/* Passed in vlan_ioctl_args structure to determine behaviour. */
+enum vlan_ioctl_cmds {
+	ADD_VLAN_CMD,
+	DEL_VLAN_CMD,
+	SET_VLAN_INGRESS_PRIORITY_CMD,
+	SET_VLAN_EGRESS_PRIORITY_CMD,
+	GET_VLAN_INGRESS_PRIORITY_CMD,
+	GET_VLAN_EGRESS_PRIORITY_CMD,
+	SET_VLAN_NAME_TYPE_CMD,
+	SET_VLAN_FLAG_CMD,
+	GET_VLAN_REALDEV_NAME_CMD, /* If this works, you know it's a VLAN device, btw */
+	GET_VLAN_VID_CMD /* Get the VID of this VLAN (specified by name) */
+};
+
+enum vlan_flags {
+	VLAN_FLAG_REORDER_HDR	= 0x1,
+};
+
+enum vlan_name_types {
+	VLAN_NAME_TYPE_PLUS_VID, /* Name will look like:  vlan0005 */
+	VLAN_NAME_TYPE_RAW_PLUS_VID, /* name will look like:  eth1.0005 */
+	VLAN_NAME_TYPE_PLUS_VID_NO_PAD, /* Name will look like:  vlan5 */
+	VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD, /* Name will look like:  eth0.5 */
+	VLAN_NAME_TYPE_HIGHEST
+};
+
+struct vlan_ioctl_args {
+	int cmd; /* Should be one of the vlan_ioctl_cmds enum above. */
+	char device1[24];
+
+        union {
+		char device2[24];
+		int VID;
+		unsigned int skb_priority;
+		unsigned int name_type;
+		unsigned int bind_type;
+		unsigned int flag; /* Matches vlan_dev_info flags */
+        } u;
+
+	short vlan_qos;
+};
+
+#endif /* !(_LINUX_IF_VLAN_H_) */
Applied
#2 lore raw

Re: [LIBNL 01/09]: Add if_vlan.h

* Patrick McHardy <[email protected]> 2008-01-18 17:55

Quoted 8 lines

commit 057316c354252ef6273f6deb4fe4232c02e4d141

Author: Patrick McHardy <[email protected]>
Date:   Fri Jan 18 16:15:53 2008 +0100

[LIBNL]: Add if_vlan.h

vlan support needs VLAN_FLAG_REORDER_HDR, which is not available in older if_vlan.h versions. Add the current version from the kernel.

Applied, thanks.

#3 lore raw

PATCH 2/9 : Fix minor memleaks on exit

In reply to Patrick McHardy

commit f3982f36f684c2ef1174bf3d951c15d3e5a91f9a

Author: Patrick McHardy <[email protected]>
Date:   Fri Jan 18 16:16:07 2008 +0100

[LIBNL]: Fix minor memleaks on exit

Make valgrind happy ...

lib/route/route_utils.c +10 -0
index a12d169..1386cda 100644
@@ -63,6 +63,11 @@ static void __init init_routing_table_names(void)
 	add_routing_table_name(RT_TABLE_LOCAL, "local");
 };
 
+static void __exit release_routing_table_names(void)
+{
+	__trans_list_clear(&table_names);
+}
+
 int rtnl_route_read_table_names(const char *path)
 {
 	__trans_list_clear(&table_names);
@@ -104,6 +109,11 @@ static void __init init_proto_names(void)
 	add_proto_name(RTPROT_STATIC, "static");
 };
 
+static void __exit release_proto_names(void)
+{
+	__trans_list_clear(&proto_names);
+}
+
 int rtnl_route_read_protocol_names(const char *path)
 {
 	__trans_list_clear(&proto_names);
Applied
#4 lore raw

Re: [LIBNL 02/09]: Fix minor memleaks on exit

* Patrick McHardy <[email protected]> 2008-01-18 17:55

Quoted 7 lines

commit f3982f36f684c2ef1174bf3d951c15d3e5a91f9a

Author: Patrick McHardy <[email protected]>
Date:   Fri Jan 18 16:16:07 2008 +0100

[LIBNL]: Fix minor memleaks on exit

Make valgrind happy ...

Applied, thanks Patrick.

#5 lore raw

PATCH 3/9 : Generic netfilter stuff

In reply to Patrick McHardy

commit d0d52158ccf2b1d60f864e888f9bdb08c0bdae8b

Author: Patrick McHardy <[email protected]>
Date:   Fri Jan 18 16:17:18 2008 +0100

[LIBNL]: Generic netfilter stuff

Add some generic helper functions for netfilter.

include/linux/netfilter.h new file +39 -0
new file mode 100644
index 0000000..0750ca6
@@ -0,0 +1,39 @@
+#ifndef __LINUX_NETFILTER_H
+#define __LINUX_NETFILTER_H
+
+
+/* Responses from hook functions. */
+#define NF_DROP 0
+#define NF_ACCEPT 1
+#define NF_STOLEN 2
+#define NF_QUEUE 3
+#define NF_REPEAT 4
+#define NF_STOP 5
+#define NF_MAX_VERDICT NF_STOP
+
+/* we overload the higher bits for encoding auxiliary data such as the queue
+ * number. Not nice, but better than additional function arguments. */
+#define NF_VERDICT_MASK 0x0000ffff
+#define NF_VERDICT_BITS 16
+
+#define NF_VERDICT_QMASK 0xffff0000
+#define NF_VERDICT_QBITS 16
+
+#define NF_QUEUE_NR(x) (((x << NF_VERDICT_QBITS) & NF_VERDICT_QMASK) | NF_QUEUE)
+
+/* only for userspace compatibility */
+/* Generic cache responses from hook functions.
+   <= 0x2000 is used for protocol-flags. */
+#define NFC_UNKNOWN 0x4000
+#define NFC_ALTERED 0x8000
+
+enum nf_inet_hooks {
+	NF_INET_PRE_ROUTING,
+	NF_INET_LOCAL_IN,
+	NF_INET_FORWARD,
+	NF_INET_LOCAL_OUT,
+	NF_INET_POST_ROUTING,
+	NF_INET_NUMHOOKS,
+};
+
+#endif /*__LINUX_NETFILTER_H*/
include/netlink/netfilter/netfilter.h new file +31 -0
new file mode 100644
index 0000000..dd3589c
@@ -0,0 +1,31 @@
+/*
+ * netlink/netfilter/netfilter.h	Netfilter generic functions
+ *
+ *	This library is free software; you can redistribute it and/or
+ *	modify it under the terms of the GNU Lesser General Public
+ *	License as published by the Free Software Foundation version 2.1
+ *	of the License.
+ *
+ * Copyright (c) 2008 Patrick McHardy <[email protected]>
+ */
+
+#ifndef NETLINK_NETFILTER_H_
+#define NETLINK_NETFILTER_H_
+
+#include <netlink/netlink.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern char *			nfnl_verdict2str(unsigned int, char *, size_t);
+extern unsigned int		nfnl_str2verdict(const char *);
+
+extern char *			nfnl_inet_hook2str(unsigned int, char *, size_t);
+extern unsigned int		nfnl_str2inet_hook(const char *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
lib/netfilter/netfilter.c new file +53 -0

53 lines not on this page · raw message

#6 lore raw

Re: [LIBNL 03/09]: Generic netfilter stuff

* Patrick McHardy <[email protected]> 2008-01-18 17:55

Quoted 7 lines

commit d0d52158ccf2b1d60f864e888f9bdb08c0bdae8b

Author: Patrick McHardy <[email protected]>
Date:   Fri Jan 18 16:17:18 2008 +0100

[LIBNL]: Generic netfilter stuff

Add some generic helper functions for netfilter.

Also applied.

#7 lore raw

PATCH 4/9 : Add nfnetlink_queue support

In reply to Patrick McHardy

commit 1782a5fba82778d0d10838f511f57b2b2b70966a

Author: Patrick McHardy <[email protected]>
Date:   Fri Jan 18 17:44:08 2008 +0100

[LIBNL]: Add nfnetlink_queue support

include/linux/netfilter/nfnetlink_queue.h new file +94 -0
new file mode 100644
index 0000000..bf7cfb6
@@ -0,0 +1,94 @@
+#ifndef _NFNETLINK_QUEUE_H
+#define _NFNETLINK_QUEUE_H
+
+#include <linux/types.h>
+#include <linux/netfilter/nfnetlink.h>
+
+#ifndef aligned_be64
+#define aligned_be64 u_int64_t __attribute__((aligned(8)))
+#endif
+
+enum nfqnl_msg_types {
+	NFQNL_MSG_PACKET,		/* packet from kernel to userspace */
+	NFQNL_MSG_VERDICT,		/* verdict from userspace to kernel */
+	NFQNL_MSG_CONFIG,		/* connect to a particular queue */
+
+	NFQNL_MSG_MAX
+};
+
+struct nfqnl_msg_packet_hdr {
+	__be32		packet_id;	/* unique ID of packet in queue */
+	__be16		hw_protocol;	/* hw protocol (network order) */
+	u_int8_t	hook;		/* netfilter hook */
+} __attribute__ ((packed));
+
+struct nfqnl_msg_packet_hw {
+	__be16		hw_addrlen;
+	u_int16_t	_pad;
+	u_int8_t	hw_addr[8];
+};
+
+struct nfqnl_msg_packet_timestamp {
+	aligned_be64	sec;
+	aligned_be64	usec;
+};
+
+enum nfqnl_attr_type {
+	NFQA_UNSPEC,
+	NFQA_PACKET_HDR,
+	NFQA_VERDICT_HDR,		/* nfqnl_msg_verdict_hrd */
+	NFQA_MARK,			/* u_int32_t nfmark */
+	NFQA_TIMESTAMP,			/* nfqnl_msg_packet_timestamp */
+	NFQA_IFINDEX_INDEV,		/* u_int32_t ifindex */
+	NFQA_IFINDEX_OUTDEV,		/* u_int32_t ifindex */
+	NFQA_IFINDEX_PHYSINDEV,		/* u_int32_t ifindex */
+	NFQA_IFINDEX_PHYSOUTDEV,	/* u_int32_t ifindex */
+	NFQA_HWADDR,			/* nfqnl_msg_packet_hw */
+	NFQA_PAYLOAD,			/* opaque data payload */
+
+	__NFQA_MAX
+};
+#define NFQA_MAX (__NFQA_MAX - 1)
+
+struct nfqnl_msg_verdict_hdr {
+	__be32 verdict;
+	__be32 id;
+};
+
+
+enum nfqnl_msg_config_cmds {
+	NFQNL_CFG_CMD_NONE,
+	NFQNL_CFG_CMD_BIND,
+	NFQNL_CFG_CMD_UNBIND,
+	NFQNL_CFG_CMD_PF_BIND,
+	NFQNL_CFG_CMD_PF_UNBIND,
+};
+
+struct nfqnl_msg_config_cmd {
+	u_int8_t	command;	/* nfqnl_msg_config_cmds */
+	u_int8_t	_pad;
+	__be16		pf;		/* AF_xxx for PF_[UN]BIND */
+};
+
+enum nfqnl_config_mode {
+	NFQNL_COPY_NONE,
+	NFQNL_COPY_META,
+	NFQNL_COPY_PACKET,
+};
+
+struct nfqnl_msg_config_params {
+	__be32		copy_range;
+	u_int8_t	copy_mode;	/* enum nfqnl_config_mode */
+} __attribute__ ((packed));
+
+
+enum nfqnl_attr_config {
+	NFQA_CFG_UNSPEC,
+	NFQA_CFG_CMD,			/* nfqnl_msg_config_cmd */
+	NFQA_CFG_PARAMS,		/* nfqnl_msg_config_params */
+	NFQA_CFG_QUEUE_MAXLEN,		/* u_int32_t */
+	__NFQA_CFG_MAX
+};
+#define NFQA_CFG_MAX (__NFQA_CFG_MAX-1)
+
+#endif /* _NFNETLINK_QUEUE_H */
include/netlink-types.h +30 -0
index f7c6437..f7bddca 100644
@@ -755,4 +755,34 @@ struct nfnl_log {
 	uint32_t		log_seq_global;
 };
 
+struct nfnl_queue {
+	NLHDR_COMMON
+
+	uint16_t		queue_group;
+	uint32_t		queue_maxlen;
+	uint32_t		queue_copy_range;
+	uint8_t			queue_copy_mode;
+};
+
+struct nfnl_queue_msg {
+	NLHDR_COMMON
+
+	uint16_t		queue_msg_group;
+	uint8_t			queue_msg_family;
+	uint8_t			queue_msg_hook;
+	uint16_t		queue_msg_hwproto;
+	uint32_t		queue_msg_packetid;
+	uint32_t		queue_msg_mark;
+	struct timeval		queue_msg_timestamp;
+	uint32_t		queue_msg_indev;
+	uint32_t		queue_msg_outdev;
+	uint32_t		queue_msg_physindev;
+	uint32_t		queue_msg_physoutdev;
+	uint8_t			queue_msg_hwaddr[8];
+	int			queue_msg_hwaddr_len;
+	void *			queue_msg_payload;
+	int			queue_msg_payload_len;
+	uint32_t		queue_msg_verdict;
+};
+
 #endif
include/netlink/netfilter/queue.h new file +86 -0

86 lines not on this page · raw message

include/netlink/netfilter/queue_msg.h new file +101 -0

101 lines not on this page · raw message

lib/netfilter/queue.c new file +233 -0

233 lines not on this page · raw message

lib/netfilter/queue_msg.c new file +240 -0

240 lines not on this page · raw message

lib/netfilter/queue_msg_obj.c new file +480 -0

480 lines not on this page · raw message

lib/netfilter/queue_obj.c new file +213 -0

213 lines not on this page · raw message

src/nf-queue.c new file +172 -0

172 lines not on this page · raw message

#9 lore raw

PATCH 5/9 : nfnetlink_log: only set hwproto if not zero

In reply to Patrick McHardy

commit 26b35449524246778d4a14c3805430797c29c039

Author: Patrick McHardy <[email protected]>
Date:   Fri Jan 18 17:44:52 2008 +0100

[LIBNL]: nfnetlink_log: only set hwproto if not zero

The hwproto doesn't have its own attribute and is also present when not set. Don't set the attribute if its value is zero.

lib/netfilter/log.c +2 -1
index a6bf3d5..a900927 100644
@@ -86,7 +86,8 @@ struct nfnl_log *nfnlmsg_log_parse(struct nlmsghdr *nlh)
 	if (attr) {
 		struct nfulnl_msg_packet_hdr *hdr = nla_data(attr);
 
-		nfnl_log_set_hwproto(log, hdr->hw_protocol);
+		if (hdr->hw_protocol)
+			nfnl_log_set_hwproto(log, hdr->hw_protocol);
 		nfnl_log_set_hook(log, hdr->hook);
 	}
 
Applied
#10 lore raw

Re: [LIBNL 05/09]: nfnetlink_log: only set hwproto if not zero

* Patrick McHardy <[email protected]> 2008-01-18 17:55

Quoted 10 lines

commit 26b35449524246778d4a14c3805430797c29c039

Author: Patrick McHardy <[email protected]>
Date:   Fri Jan 18 17:44:52 2008 +0100

[LIBNL]: nfnetlink_log: only set hwproto if not zero

The hwproto doesn't have its own attribute and is also present when not set. Don't set the attribute if its value is zero.

Applied.

#11 lore raw

PATCH 6/9 : nfnetlink_log: support NUFLA_GID attribute

In reply to Patrick McHardy

commit 2c2e8051726fb34980d1e7b72c15d0a6eba4cfc0

Author: Patrick McHardy <[email protected]>
Date:   Fri Jan 18 17:44:52 2008 +0100

[LIBNL]: nfnetlink_log: support NUFLA_GID attribute

The NUFLA_GID attribute (currently only in net-2.6.25) contains the gid of the sending process for locally generated packets.

include/linux/netfilter/nfnetlink_log.h +1 -0
index 2de5df9..38fafc1 100644
@@ -51,6 +51,7 @@ enum nfulnl_attr_type {
 	NFULA_UID,			/* user id of socket */
 	NFULA_SEQ,			/* instance-local sequence number */
 	NFULA_SEQ_GLOBAL,		/* global sequence number */
+	NFULA_GID,			/* group id of socket */
 
 	__NFULA_MAX
 };
include/netlink-types.h +1 -0
index f7bddca..cbf903e 100644
@@ -751,6 +751,7 @@ struct nfnl_log {
 	int			log_payload_len;
 	char *			log_prefix;
 	uint32_t		log_uid;
+	uint32_t		log_gid;
 	uint32_t		log_seq;
 	uint32_t		log_seq_global;
 };
include/netlink/netfilter/log.h +4 -0
index e65cc58..817de2d 100644
@@ -89,6 +89,10 @@ extern void		nfnl_log_set_uid(struct nfnl_log *, uint32_t);
 extern int		nfnl_log_test_uid(const struct nfnl_log *);
 extern uint32_t		nfnl_log_get_uid(const struct nfnl_log *);
 
+extern void		nfnl_log_set_gid(struct nfnl_log *, uint32_t);
+extern int		nfnl_log_test_gid(const struct nfnl_log *);
+extern uint32_t		nfnl_log_get_gid(const struct nfnl_log *);
+
 extern void		nfnl_log_set_seq(struct nfnl_log *, uint32_t);
 extern int		nfnl_log_test_seq(const struct nfnl_log *);
 extern uint32_t		nfnl_log_get_seq(const struct nfnl_log *);
lib/netfilter/log.c +5 -0
index a900927..8d70e7f 100644
@@ -58,6 +58,7 @@ static struct nla_policy log_policy[NFULA_MAX+1] = {
 	//[NFULA_PAYLOAD]
 	[NFULA_PREFIX]			= { .type = NLA_STRING, },
 	[NFULA_UID]			= { .type = NLA_U32 },
+	[NFULA_GID]			= { .type = NLA_U32 },
 	[NFULA_SEQ]			= { .type = NLA_U32 },
 	[NFULA_SEQ_GLOBAL]		= { .type = NLA_U32 },
 };
@@ -146,6 +147,10 @@ struct nfnl_log *nfnlmsg_log_parse(struct nlmsghdr *nlh)
 	if (attr)
 		nfnl_log_set_uid(log, ntohl(nla_get_u32(attr)));
 
+	attr = tb[NFULA_GID];
+	if (attr)
+		nfnl_log_set_gid(log, ntohl(nla_get_u32(attr)));
+
 	attr = tb[NFULA_SEQ];
 	if (attr)
 		nfnl_log_set_seq(log, ntohl(nla_get_u32(attr)));
lib/netfilter/log_obj.c +26 -2
index c3adc51..0e4411e 100644
@@ -29,8 +29,9 @@
 #define LOG_ATTR_PAYLOAD		(1UL << 10)
 #define LOG_ATTR_PREFIX			(1UL << 11)
 #define LOG_ATTR_UID			(1UL << 12)
-#define LOG_ATTR_SEQ			(1UL << 13)
-#define LOG_ATTR_SEQ_GLOBAL		(1UL << 14)
+#define LOG_ATTR_GID			(1UL << 13)
+#define LOG_ATTR_SEQ			(1UL << 14)
+#define LOG_ATTR_SEQ_GLOBAL		(1UL << 15)
 /** @endcond */
 
 static void log_free_data(struct nl_object *c)
@@ -144,6 +145,12 @@ static int log_dump(struct nl_object *a, struct nl_dump_params *p)
 	if (log->ce_mask & LOG_ATTR_PAYLOAD)
 		dp_dump(p, "PAYLOADLEN=%d ", log->log_payload_len);
 
+	if (log->ce_mask & LOG_ATTR_UID)
+		dp_dump(p, "UID=%u ", log->log_uid);
+
+	if (log->ce_mask & LOG_ATTR_GID)
+		dp_dump(p, "GID=%u ", log->log_gid);
+
 	if (log->ce_mask & LOG_ATTR_SEQ)
 		dp_dump(p, "SEQ=%d ", log->log_seq);
 
@@ -378,6 +385,23 @@ uint32_t nfnl_log_get_uid(const struct nfnl_log *log)
 	return log->log_uid;
 }
 
+void nfnl_log_set_gid(struct nfnl_log *log, uint32_t gid)
+{
+	log->log_gid = gid;
+	log->ce_mask |= LOG_ATTR_GID;
+}
+
+int nfnl_log_test_gid(const struct nfnl_log *log)
+{
+	return !!(log->ce_mask & LOG_ATTR_GID);
+}
+
+uint32_t nfnl_log_get_gid(const struct nfnl_log *log)
+{
+	return log->log_gid;
+}
+
+
 void nfnl_log_set_seq(struct nfnl_log *log, uint32_t seq)
 {
 	log->log_seq = seq;
Applied
#12 lore raw

Re: [LIBNL 06/09]: nfnetlink_log: support NUFLA_GID attribute

* Patrick McHardy <[email protected]> 2008-01-18 17:55

Quoted 10 lines

commit 2c2e8051726fb34980d1e7b72c15d0a6eba4cfc0

Author: Patrick McHardy <[email protected]>
Date:   Fri Jan 18 17:44:52 2008 +0100

[LIBNL]: nfnetlink_log: support NUFLA_GID attribute

The NUFLA_GID attribute (currently only in net-2.6.25) contains the gid of the sending process for locally generated packets.

Applied, thanks Patrick.

#13 lore raw

PATCH 7/9 : Split up nfnetlink_log into log and msg objects

In reply to Patrick McHardy

commit c566db4405200994482d36fac45089aba4e2360a

Author: Patrick McHardy <[email protected]>
Date:   Fri Jan 18 17:52:41 2008 +0100

[LIBNL]: Split up nfnetlink_log into log and msg objects

Split the nfnetlink_log code into two seperate objects, "netfilter/log" to represent logging instances and "netfilter/log_msg" to represent log messages. Also perform some function name unification for consistency with other libnl object types, mainly renaming nfnl_log_build_*_msg to nfnl_log_build_*_request.

This changes the API in an incompatible way, but since this feature is new and the libnl netfilter headers haven't been installed so far, there shouldn't be any users affected by this.

include/netlink-types.h +31 -18
index cbf903e..a690cb2 100644
@@ -736,24 +736,37 @@ struct nfnl_ct {
 struct nfnl_log {
 	NLHDR_COMMON
 
-	uint8_t			log_family;
-	uint8_t			log_hook;
-	uint16_t		log_hwproto;
-	uint32_t		log_mark;
-	struct timeval		log_timestamp;
-	uint32_t		log_indev;
-	uint32_t		log_outdev;
-	uint32_t		log_physindev;
-	uint32_t		log_physoutdev;
-	uint8_t			log_hwaddr[8];
-	int			log_hwaddr_len;
-	void *			log_payload;
-	int			log_payload_len;
-	char *			log_prefix;
-	uint32_t		log_uid;
-	uint32_t		log_gid;
-	uint32_t		log_seq;
-	uint32_t		log_seq_global;
+	uint16_t		log_group;
+	uint8_t			log_copy_mode;
+	uint32_t		log_copy_range;
+	uint32_t		log_flush_timeout;
+	uint32_t		log_alloc_size;
+	uint32_t		log_queue_threshold;
+	uint32_t		log_flags;
+	uint32_t		log_flag_mask;
+};
+
+struct nfnl_log_msg {
+	NLHDR_COMMON
+
+	uint8_t			log_msg_family;
+	uint8_t			log_msg_hook;
+	uint16_t		log_msg_hwproto;
+	uint32_t		log_msg_mark;
+	struct timeval		log_msg_timestamp;
+	uint32_t		log_msg_indev;
+	uint32_t		log_msg_outdev;
+	uint32_t		log_msg_physindev;
+	uint32_t		log_msg_physoutdev;
+	uint8_t			log_msg_hwaddr[8];
+	int			log_msg_hwaddr_len;
+	void *			log_msg_payload;
+	int			log_msg_payload_len;
+	char *			log_msg_prefix;
+	uint32_t		log_msg_uid;
+	uint32_t		log_msg_gid;
+	uint32_t		log_msg_seq;
+	uint32_t		log_msg_seq_global;
 };
 
 struct nfnl_queue {
include/netlink/netfilter/log.h +57 -57

143 lines not on this page · raw message

include/netlink/netfilter/log_msg.h new file +98 -0

98 lines not on this page · raw message

lib/netfilter/log.c +109 -222

407 lines not on this page · raw message

lib/netfilter/log_msg.c new file +218 -0

218 lines not on this page · raw message

lib/netfilter/log_msg_obj.c new file +456 -0

456 lines not on this page · raw message

lib/netfilter/log_obj.c +140 -304

558 lines not on this page · raw message

src/nf-log.c +46 -9

96 lines not on this page · raw message

#14 lore raw

Re: [LIBNL 07/09]: Split up nfnetlink_log into log and msg objects

Quoted 12 lines · Patrick McHardy

commit c566db4405200994482d36fac45089aba4e2360a

Author: Patrick McHardy <[email protected]>
Date:   Fri Jan 18 17:52:41 2008 +0100

[LIBNL]: Split up nfnetlink_log into log and msg objects

Split the nfnetlink_log code into two seperate objects, "netfilter/log" to represent logging instances and "netfilter/log_msg" to represent log messages. Also perform some function name unification for consistency with other libnl object types, mainly renaming nfnl_log_build_*_msg to nfnl_log_build_*_request.

Quoted 5 lines

This changes the API in an incompatible way, but since this feature is new and the libnl netfilter headers haven't been installed so far, there shouldn't be any users affected by this.

Definitely an improvement, thanks. The pf bind/unbind are still handled differently, but I guess they are too simple to warrant it and will never get more attributes.

I hadn't noticed the missing headers because my cross compile environment has its own custom install target.

#15 lore raw

Re: [LIBNL 07/09]: Split up nfnetlink_log into log and msg objects

Quoted 17 lines · Philip Craig
Quoted 16 lines · Patrick McHardy

commit c566db4405200994482d36fac45089aba4e2360a

Author: Patrick McHardy <[email protected]>
Date:   Fri Jan 18 17:52:41 2008 +0100

[LIBNL]: Split up nfnetlink_log into log and msg objects

Split the nfnetlink_log code into two seperate objects, "netfilter/log" to represent logging instances and "netfilter/log_msg" to represent log messages. Also perform some function name unification for consistency with other libnl object types, mainly renaming nfnl_log_build_*_msg to nfnl_log_build_*_request.

This changes the API in an incompatible way, but since this feature is new and the libnl netfilter headers haven't been installed so far, there shouldn't be any users affected by this.

Quoted 5 lines
Quoted 1 line

Definitely an improvement, thanks. The pf bind/unbind are still handled differently, but I guess they are too simple to warrant it and will never get more attributes.

Yes, I kept those seperated from the log object because we can subscribe to multiple families and this really didn't fit the object model very well. I still hope to get rid of these within the kernel some day.

Quoted 2 lines

I hadn't noticed the missing headers because my cross compile environment has its own custom install target.

I was happy to discover it since this means we can change the API without annoying users :)

#16 lore raw

Re: [LIBNL 07/09]: Split up nfnetlink_log into log and msg objects

In reply to Patrick McHardy

* Patrick McHardy <[email protected]> 2008-01-18 17:55

Quoted 11 lines

commit c566db4405200994482d36fac45089aba4e2360a

Author: Patrick McHardy <[email protected]>
Date:   Fri Jan 18 17:52:41 2008 +0100

[LIBNL]: Split up nfnetlink_log into log and msg objects

Split the nfnetlink_log code into two seperate objects, "netfilter/log" to represent logging instances and "netfilter/log_msg" to represent log messages. Also perform some function name unification for consistency with other libnl object types, mainly renaming nfnl_log_build_*_msg to nfnl_log_build_*_request.

Applied with a few whitespaces fixed. Thanks Patrick!

Quoted 3 lines

This changes the API in an incompatible way, but since this feature is new and the libnl netfilter headers haven't been installed so far, there shouldn't be any users affected by this.

Yes, I agree.

#17 lore raw

PATCH 8/9 : Support conntrack add/delete/query requests

In reply to Patrick McHardy

commit 5d2b826674d411f99e571fd35ad5722fed077e5e

Author: Patrick McHardy <[email protected]>
Date:   Fri Jan 18 17:53:14 2008 +0100

[LIBNL]: Support conntrack add/delete/query requests

include/netlink/netfilter/ct.h +9 -0
index 965b869..f554017 100644
@@ -39,6 +39,15 @@ extern void		nfnl_ct_put(struct nfnl_ct *);
 
 extern int		nfnl_ct_dump_request(struct nl_handle *);
 
+extern struct nl_msg *	nfnl_ct_build_add_request(const struct nfnl_ct *, int);
+extern int		nfnl_ct_add(struct nl_handle *, const struct nfnl_ct *, int);
+
+extern struct nl_msg *	nfnl_ct_build_delete_request(const struct nfnl_ct *, int);
+extern int		nfnl_ct_delete(struct nl_handle *, const struct nfnl_ct *, int);
+
+extern struct nl_msg *	nfnl_ct_build_query_request(const struct nfnl_ct *, int);
+extern int		nfnl_ct_query(struct nl_handle *, const struct nfnl_ct *, int);
+
 extern void		nfnl_ct_set_family(struct nfnl_ct *, uint8_t);
 extern uint8_t		nfnl_ct_get_family(const struct nfnl_ct *);
 
lib/netfilter/ct.c +153 -0

165 lines not on this page · raw message

#18 lore raw

Re: [LIBNL 08/09]: Support conntrack add/delete/query requests

Quoted 13 lines · Patrick McHardy

commit 5d2b826674d411f99e571fd35ad5722fed077e5e

Author: Patrick McHardy <[email protected]>
Date:   Fri Jan 18 17:53:14 2008 +0100

[LIBNL]: Support conntrack add/delete/query requests

include/netlink/netfilter/ct.h +0 -0
index 965b869..f554017 100644

include/netlink/netfilter/ct.h extern void nfnl_ct_put(struct nfnl_ct *); · line 40

Quoted 2 lines
include/netlink/netfilter/ct.h +0 -0
@@ -39,6 +39,15 @@ extern void		nfnl_ct_put(struct nfnl_ct *);
 
 extern int		nfnl_ct_dump_request(struct nl_handle *);

This was just a quick and dirty dump request. nfnl_ct_query covers this now, so we can delete it.

Quoted 11 lines
include/netlink/netfilter/ct.h +9 -0
+extern struct nl_msg *	nfnl_ct_build_add_request(const struct nfnl_ct *, int);
+extern int		nfnl_ct_add(struct nl_handle *, const struct nfnl_ct *, int);
+
+extern struct nl_msg *	nfnl_ct_build_delete_request(const struct nfnl_ct *, int);
+extern int		nfnl_ct_delete(struct nl_handle *, const struct nfnl_ct *, int);
+
+extern struct nl_msg *	nfnl_ct_build_query_request(const struct nfnl_ct *, int);
+extern int		nfnl_ct_query(struct nl_handle *, const struct nfnl_ct *, int);
+
 extern void		nfnl_ct_set_family(struct nfnl_ct *, uint8_t);
 extern uint8_t		nfnl_ct_get_family(const struct nfnl_ct *);
#19 lore raw

Re: [LIBNL 08/09]: Support conntrack add/delete/query requests

Quoted 15 lines · Philip Craig
Quoted 14 lines · Patrick McHardy

commit 5d2b826674d411f99e571fd35ad5722fed077e5e

Author: Patrick McHardy <[email protected]>
Date:   Fri Jan 18 17:53:14 2008 +0100

[LIBNL]: Support conntrack add/delete/query requests

include/netlink/netfilter/ct.h +0 -0
index 965b869..f554017 100644
@@ -39,6 +39,15 @@ extern void		nfnl_ct_put(struct nfnl_ct *);
 
Quoted 4 lines

include/netlink/netfilter/ct.h extern void nfnl_ct_put(struct nfnl_ct *); · line 40

Quoted 1 line
include/netlink/netfilter/ct.h +0 -0
 extern int		nfnl_ct_dump_request(struct nl_handle *);

This was just a quick and dirty dump request. nfnl_ct_query covers this now, so we can delete it.

nfnl_ct_query doesn't perform a full dump, so this still looks useful.

#20 lore raw

Re: [LIBNL 08/09]: Support conntrack add/delete/query requests

Quoted 1 line · Patrick McHardy

nfnl_ct_query doesn't perform a full dump, so this still looks useful.

Will this do a full dump? nfnl_ct_query(handle, nfnl_ct_alloc(), NLM_F_DUMP);

I'm okay with leaving it in there, I just didn't want to keep functions that none of the other objects in libnl have if they aren't really needed.

#21 lore raw

Re: [LIBNL 08/09]: Support conntrack add/delete/query requests

Quoted 5 lines · Philip Craig
Quoted 1 line · Patrick McHardy

nfnl_ct_query doesn't perform a full dump, so this still looks useful.

Will this do a full dump? nfnl_ct_query(handle, nfnl_ct_alloc(), NLM_F_DUMP);

Yes, but the query function expects a conntrack object with tuples etc. to build the message, so its unnecessary complicated to use it for a full dump.

Quoted 2 lines

I'm okay with leaving it in there, I just didn't want to keep functions that none of the other objects in libnl have if they aren't really needed.

In this case I think its preferrable to keep it around.

Applied
#22 lore raw

Re: [LIBNL 08/09]: Support conntrack add/delete/query requests

In reply to Patrick McHardy

* Patrick McHardy <[email protected]> 2008-01-18 17:55

Quoted 7 lines

commit 5d2b826674d411f99e571fd35ad5722fed077e5e

Author: Patrick McHardy <[email protected]>
Date:   Fri Jan 18 17:53:14 2008 +0100

[LIBNL]: Support conntrack add/delete/query requests

Applied, thanks everyone.

Will there be a src/nf-ct-(add|del|query).c? ;-)

#23 lore raw

Re: [LIBNL 08/09]: Support conntrack add/delete/query requests

Quoted 5 lines · Thomas Graf

* Patrick McHardy <[email protected]> 2008-01-18 17:55

Quoted 4 lines

commit 5d2b826674d411f99e571fd35ad5722fed077e5e

Author: Patrick McHardy <[email protected]>
Date:   Fri Jan 18 17:53:14 2008 +0100
Quoted 7 lines
Quoted 3 lines

[LIBNL]: Support conntrack add/delete/query requests

Applied, thanks everyone.

Will there be a src/nf-ct-(add|del|query).c? ;-)

I'll put one in when I find some time.

#24 lore raw

PATCH 9/9 : Install netfilter headers

In reply to Patrick McHardy

commit 8c4229982c96650d5369fa33c40749de0ac29bb2

Author: Patrick McHardy <[email protected]>
Date:   Fri Jan 18 17:53:14 2008 +0100

[LIBNL]: Install netfilter headers

libnl currently forgets to install the netfilter headers. Fix that.

include/Makefile +2 -0
index a2b23e0..968ebe5 100644
@@ -29,10 +29,12 @@ install:
 	mkdir -p $(DESTDIR)$(includedir)/netlink/route/cls/
 	mkdir -p $(DESTDIR)$(includedir)/netlink/genl/
 	mkdir -p $(DESTDIR)$(includedir)/netlink/fib_lookup/
+	mkdir -p $(DESTDIR)$(includedir)/netlink/netfilter
 	install -m 0644 netlink/*.h $(DESTDIR)$(includedir)/netlink/
 	install -m 0644 netlink/route/*.h $(DESTDIR)$(includedir)/netlink/route/
 	install -m 0644 netlink/route/sch/*.h $(DESTDIR)$(includedir)/netlink/route/sch/
 	install -m 0644 netlink/route/cls/*.h $(DESTDIR)$(includedir)/netlink/route/cls/
 	install -m 0644 netlink/genl/*.h $(DESTDIR)$(includedir)/netlink/genl/
 	install -m 0644 netlink/fib_lookup/*.h $(DESTDIR)$(includedir)/netlink/fib_lookup/
+	install -m 0644 netlink/netfilter/*.h $(DESTDIR)$(includedir)/netlink/netfilter/
 
#25 lore raw

Re: [LIBNL 09/09]: Install netfilter headers

* Patrick McHardy <[email protected]> 2008-01-18 17:56

Quoted 10 lines

commit 8c4229982c96650d5369fa33c40749de0ac29bb2

Author: Patrick McHardy <[email protected]>
Date:   Fri Jan 18 17:53:14 2008 +0100

[LIBNL]: Install netfilter headers

libnl currently forgets to install the netfilter headers. Fix that.

Also applied, thanks for all this nice work Patrick.

All changes pushed to kernel.org.