Skip to contentSkip to conversation

implementing icmp code filtering

RFC PATCH In review Eric Leblond 2 participants 3 messages Feb 10, 2014 netfilter

lore
Share & tools
lore
#0 lore raw

cover implementing icmp code filtering

Hello,

I've started to work on completing the reject implementation. I've got a decent patchset but one specific point in my current work is not valid for me.

There is multiple ICMP code lists depending on the value of the type. So the straightforward implementation updating proto_icmp has some issue:

const struct proto_desc proto_icmp = {
.name = "icmp",
.base = PROTO_BASE_TRANSPORT_HDR,
.templates = {
[ICMPHDR_TYPE] = ICMPHDR_TYPE("type", &icmp_type_type, type),
- [ICMPHDR_CODE] = ICMPHDR_FIELD("code", code),
+ [ICMPHDR_CODE] = ICMPHDR_TYPE("code", &icmp_code_type, code),

We have only one icmp_code_type symbo_table possible. For the userspace to kernel way this is not an issue. As matching on the key name will lead to a single value. Reverse order is not working as we need to know the context (here the type) for converting the code to a name.

A possible solution could be to declare a subtype in the symbol_table that could be used to set the context. For example, we could do something like:

+static const struct symbol_table icmp_code_tbl = {
+ .symbols = {
+ SYMBOL_WITH_SUBTYPE("network-unreachable", ICMP_NET_UNREACH, TYPE_ICMP_CODE_REJECT),

It we set the type to TYPE_ICMP_CODE_REJECT when sending the netlink message to kernel, then when reading back from kernel we will know what translation to use.

An alternative approach is to use multiple symbol_table and then create a structure aggregating the different symbol_table in one object that can be given as parameters to ICMPHDR_TYPE.

What do you think ? Any better idea ?

BR,
--
Eric

#1 lore raw

RFC PATCH 1/1 icmp: add code filtering with name

This patch define names for code field allowing to use string instead of integer when filtering on icmp code.

---
 include/datatype.h |  2 ++
 src/proto.c        | 43 ++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 44 insertions(+), 1 deletion(-)
include/datatype.h +2 -0
index 9e609cf..033ae08 100644
@@ -34,6 +34,7 @@
  * @TYPE_CT_DIR:	conntrack direction
  * @TYPE_CT_STATUS:	conntrack status (bitmask subtype)
  * @TYPE_ICMP6_TYPE:	ICMPv6 type codes (integer subtype)
+ * @TYPE_ICMP_CODE:	ICMP code codes (integer subtype)
  */
 enum datatypes {
 	TYPE_INVALID,
@@ -66,6 +67,7 @@ enum datatypes {
 	TYPE_CT_DIR,
 	TYPE_CT_STATUS,
 	TYPE_ICMP6_TYPE,
+	TYPE_ICMP_CODE,
 	__TYPE_MAX
 };
 #define TYPE_MAX		(__TYPE_MAX - 1)
src/proto.c +42 -1

60 lines not on this page · raw message

Signature · 1 line
1.9.0.rc3
#2 lore raw
In reply to Eric Leblond
Quoted 35 lines · Eric Leblond

Hello,

I've started to work on completing the reject implementation. I've got a decent patchset but one specific point in my current work is not valid for me.

There is multiple ICMP code lists depending on the value of the type. So the straightforward implementation updating proto_icmp has some issue:

const struct proto_desc proto_icmp = {

(quoted diff) +1 -1
 	.name		= "icmp",
 	.base		= PROTO_BASE_TRANSPORT_HDR,
 	.templates	= {
 		[ICMPHDR_TYPE]		= ICMPHDR_TYPE("type", &icmp_type_type, type),
-		[ICMPHDR_CODE]		= ICMPHDR_FIELD("code", code),
+		[ICMPHDR_CODE]		= ICMPHDR_TYPE("code", &icmp_code_type, code),

We have only one icmp_code_type symbo_table possible. For the userspace to kernel way this is not an issue. As matching on the key name will lead to a single value. Reverse order is not working as we need to know the context (here the type) for converting the code to a name.

A possible solution could be to declare a subtype in the symbol_table that could be used to set the context. For example, we could do something like:

(quoted diff) +3 -0
+static const struct symbol_table icmp_code_tbl = {
+       .symbols        = {
+               SYMBOL_WITH_SUBTYPE("network-unreachable",           ICMP_NET_UNREACH, TYPE_ICMP_CODE_REJECT),

It we set the type to TYPE_ICMP_CODE_REJECT when sending the netlink message to kernel, then when reading back from kernel we will know what translation to use.

Quoted 5 lines

An alternative approach is to use multiple symbol_table and then create a structure aggregating the different symbol_table in one object that can be given as parameters to ICMPHDR_TYPE.

What do you think ? Any better idea ?

I think we should use per-type code tables and complete the type during evaluation. Basically once we see a "icmp type unreachable" we complete the type of the "icmp code" expression (if any) to icmp_unreachable_code.

We do something similar in ct_expr_update_type() for ct expressions.