Skip to contentSkip to conversation

Bugfix: libnetfilter_conntrack getter and setter

PATCH Victor Stinner 2 participants 2 messages Jan 4, 2007 – Jan 5, 2007 netfilter

lore
Share & tools
lore
#0 lore raw

Hi,

Libnetfilter_conntrack getters and setters of new API are not complete:
* it's not possible to set counter attributes value
* it's not possible to set or read 'use' and 'id' attributes value

I can understand that setting counter values is not very useful, but trying to set them would lead to a crash (call NULL function). Same problem when trying to read use/id attribute value.

I attached two patches to fix that.

---

An alternative for nfct_set_attr() is to do nothing if the getter in NULL (and set an error?).

Victor Stinner
http://www.inl.fr/

conntrack/getter.c +13 -1
Index: src/conntrack/getter.c
===================================================================
@@ -157,6 +157,16 @@
 	return &ct->counters[__DIR_REPL].bytes;
 }
 
+static const void *get_attr_use(const struct nf_conntrack *ct)
+{
+	return &ct->use;
+}
+
+static const void *get_attr_id(const struct nf_conntrack *ct)
+{
+	return &ct->id;
+}
+
 static const void *get_attr_status(const struct nf_conntrack *ct)
 {
 	return &ct->status;
@@ -190,8 +200,10 @@
 	[ATTR_TIMEOUT]			= get_attr_timeout,
 	[ATTR_MARK]			= get_attr_mark,
 	[ATTR_ORIG_COUNTER_PACKETS] 	= get_attr_orig_counter_packets,
-	[ATTR_ORIG_COUNTER_BYTES]	= get_attr_orig_counter_bytes,
 	[ATTR_REPL_COUNTER_PACKETS]	= get_attr_repl_counter_packets,
+	[ATTR_ORIG_COUNTER_BYTES]	= get_attr_orig_counter_bytes,
 	[ATTR_REPL_COUNTER_BYTES]	= get_attr_repl_counter_bytes,
+	[ATTR_USE]			= get_attr_use,
+	[ATTR_ID]			= get_attr_id,
 	[ATTR_STATUS]			= get_attr_status,
 };
conntrack/setter.c +63 -27

100 lines not on this page · raw message

#1 lore raw

Hi,

Quoted 2 lines · Victor Stinner

Libnetfilter_conntrack getters and setters of new API are not complete:
* it's not possible to set counter attributes value

Because of ctnetlink, the kernel part of this whole thing, doesn't support this. Anyway, as you pointed out below, I can't see how this could be useful.

Quoted 1 line

* it's not possible to set or read 'use' and 'id' attributes value

The 'use' attribute must be possible to be get, but not set. I'll commit the patch for the getter mangled, I prefer dropping the 'id' support since it's planned to be removed.

Quoted 3 lines

I can understand that setting counter values is not very useful, but trying to set them would lead to a crash (call NULL function). Same problem when trying to read use/id attribute value.

OK, I think that the patch attached should be enough.

Quoted 2 lines

An alternative for nfct_set_attr() is to do nothing if the getter in NULL (and set an error?).

I prefer doing nothing and documenting this issue, perhaps doing some kind of warning or assertion, although that would be too much I think. Moreover, the error thing would pollute the code with tons of error checkings in the set operations.

Thanks again Victor.

Signature · 2 lines
The dawn of the fourth age of Linux firewalling is coming; a time of
great struggle and heroic deeds -- J.Kadlecsik got inspired by J.Morris
conntrack/api.c +10 -2
Index: src/conntrack/api.c
===================================================================
@@ -185,6 +185,12 @@
  * @ct: pointer to a valid conntrack
  * @type: attribute type
  * @value: pointer to the attribute value
+ *
+ * Note that certain attributes are unsettable:
+ * 	- ATTR_USE
+ * 	- ATTR_ID
+ * 	- ATTR_*_COUNTER_*
+ * The call of this function for such attributes do nothing.
  */
 void nfct_set_attr(struct nf_conntrack *ct,
 		   const enum nf_conntrack_attr type, 
@@ -196,8 +202,10 @@
 	if (type >= ATTR_MAX)
 		return;
 
-	set_attr_array[type](ct, value);
-	set_bit(type, ct->set);
+	if (set_attr_array[type]) {
+		set_attr_array[type](ct, value);
+		set_bit(type, ct->set);
+	}
 }
 
 /**
conntrack/getter.c +6 -0
Index: src/conntrack/getter.c
===================================================================
@@ -162,6 +162,11 @@
 	return &ct->status;
 }
 
+static const void *get_attr_use(const struct nf_conntrack *ct)
+{
+	return &ct->use;
+}
+
 get_attr get_attr_array[] = {
 	[ATTR_ORIG_IPV4_SRC]		= get_attr_orig_ipv4_src,
 	[ATTR_ORIG_IPV4_DST] 		= get_attr_orig_ipv4_dst,
@@ -193,5 +198,6 @@
 	[ATTR_ORIG_COUNTER_BYTES]	= get_attr_orig_counter_bytes,
 	[ATTR_REPL_COUNTER_PACKETS]	= get_attr_repl_counter_packets,
 	[ATTR_REPL_COUNTER_BYTES]	= get_attr_repl_counter_bytes,
+	[ATTR_USE]			= get_attr_use,
 	[ATTR_STATUS]			= get_attr_status,
 };