Skip to contentSkip to conversation

Add mark target

PATCH In review Zhang Chunyu 2 participants 7 messages Mar 30, 2015 – Apr 3, 2015 netfilter

lore
Share & tools
lore
#0 lore raw

v4 cover Add mark target

v1:
add mark target for arptables

v2:
add --and-mark
add --or-mark
add revision for common api

v3:
fold 2/4, 3/4 and 4/4 patch into one single patch use C99 initialization
change some format

V4:
resubmit the kernel patch

Zhang Chunyu (3):
Add revision field for xt_entry_target
Add revision field for arptables userspace
Add MARK target for arptables

 arptables.8                              |  17 ++++
 arptables.c                              |   2 +
 extensions/Makefile                      |   2 +-
 extensions/arpt_CLASSIFY.c               |   1 +
 extensions/arpt_MARK.c                   | 151 +++++++++++++++++++++++++++++++
 extensions/arpt_mangle.c                 |   1 +
 extensions/arpt_standard.c               |   1 +
 include/arptables.h                      |   6 ++
 include/linux/netfilter_arp/arp_tables.h |   3 +-
 9 files changed, 182 insertions(+), 2 deletions(-)
 create mode 100644 extensions/arpt_MARK.c
Signature · 1 line
1.7.12.4
#1 lore raw

PATCH v4 1/3 Add revision field for xt_entry_target

This filed is useful if we want to add TARGET which has revision for arptables rules.

Also make sure xt_entry_target is consistent with the definition in kernel.

---
 include/linux/netfilter_arp/arp_tables.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/linux/netfilter_arp/arp_tables.h +2 -1
index 0acda66..0bf2457 100644
@@ -19,7 +19,7 @@
 
 #include <linux/netfilter_arp.h>
 
-#define ARPT_FUNCTION_MAXNAMELEN 30
+#define ARPT_FUNCTION_MAXNAMELEN 29
 #define ARPT_TABLE_MAXNAMELEN 32
 
 #define ARPT_DEV_ADDR_LEN_MAX 16
@@ -69,6 +69,7 @@ struct arpt_entry_target
 
 			/* Used by userspace */
 			char name[ARPT_FUNCTION_MAXNAMELEN];
+			u_int8_t revision;
 		} user;
 		struct {
 			u_int16_t target_size;
Signature · 1 line
1.7.12.4
#2 lore raw

PATCH v4 2/3 Add revision field for arptables userspace

In reply to Zhang Chunyu
---
 arptables.c                | 2 ++
 extensions/arpt_CLASSIFY.c | 1 +
 extensions/arpt_mangle.c   | 1 +
 extensions/arpt_standard.c | 1 +
 include/arptables.h        | 6 ++++++
 5 files changed, 11 insertions(+)
arptables.c +2 -0
index 845e226..3f24ef1 100644
@@ -2067,6 +2067,7 @@ int do_command(int argc, char *argv[], char **table, arptc_handle_t *handle)
 				target->t->u.target_size = size;
 				strncpy(target->t->u.user.name, jumpto, sizeof(target->t->u.user.name));
 				target->t->u.user.name[sizeof(target->t->u.user.name)-1] = '\0';
+				target->t->u.user.revision = target->revision;
 /*
 				target->init(target->t, &fw.nfcache);
 */
@@ -2391,6 +2392,7 @@ int do_command(int argc, char *argv[], char **table, arptc_handle_t *handle)
 			target->t = fw_calloc(1, size);
 			target->t->u.target_size = size;
 			strcpy(target->t->u.user.name, jumpto);
+			target->t->u.user.revision = target->revision;
 			target->init(target->t);
 		}
 
extensions/arpt_CLASSIFY.c +1 -0
index cb5770b..7893aed 100644
@@ -105,6 +105,7 @@ struct arptables_target classify
 	ARPTABLES_VERSION,
 	ARPT_ALIGN(sizeof(struct xt_classify_target_info)),
 	ARPT_ALIGN(sizeof(struct xt_classify_target_info)),
+	0,
 	&help,
 	&init,
 	&parse,
extensions/arpt_mangle.c +1 -0
index c38fc16..502fc2b 100644
@@ -199,6 +199,7 @@ struct arptables_target change
     ARPTABLES_VERSION,
     ARPT_ALIGN(sizeof(struct arpt_mangle)),
     ARPT_ALIGN(sizeof(struct arpt_mangle)),
+	0,
     &help,
     &init,
     &parse,
extensions/arpt_standard.c +1 -0
index cb3891d..c647316 100644
@@ -54,6 +54,7 @@ struct arptables_target standard
     ARPTABLES_VERSION,
     ARPT_ALIGN(sizeof(int)),
     ARPT_ALIGN(sizeof(int)),
+	0,
     &help,
     &init,
     &parse,
include/arptables.h +6 -0
index 820b664..82e6e9a 100644
@@ -32,6 +32,9 @@ struct arptables_match
 	/* Size of match data relevent for userspace comparison purposes */
 	size_t userspacesize;
 
+	/* Revision of target (0 by default). */
+	u_int8_t revision;
+
 	/* Function which prints out usage message. */
 	void (*help)(void);
 
@@ -81,6 +84,9 @@ struct arptables_target
 	/* Size of target data relevent for userspace comparison purposes */
 	size_t userspacesize;
 
+	/* Revision of target (0 by default). */
+	u_int8_t revision;
+
 	/* Function which prints out usage message. */
 	void (*help)(void);
 
Signature · 1 line
1.7.12.4
#3 lore raw

PATCH v4 3/3 Add MARK target for arptables

In reply to Zhang Chunyu

We can use MARK target to set make value for arp packet.

---
 arptables.8            |  17 ++++++
 extensions/Makefile    |   2 +-
 extensions/arpt_MARK.c | 151 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 169 insertions(+), 1 deletion(-)
 create mode 100644 extensions/arpt_MARK.c
arptables.8 +17 -0
index 78b2c60..676b884 100644
@@ -315,6 +315,23 @@ sify the packet into a specific CBQ class).
 Set the major and minor  class  value.  The  values  are  always
 interpreted as hexadecimal even if no 0x prefix is given.
 
+.SS MARK
+This  module  allows you to set the skb->mark value (and thus classify
+the packet by the mark in u32)
+
+.TP
+.BR "--set-mark mark"
+Set the mark value. The  values  are  always
+interpreted as hexadecimal even if no 0x prefix is given
+
+.TP
+.BR "--and-mark mark"
+Binary AND the mark with bits.
+
+.TP
+.BR "--or-mark mark"
+Binary OR the mark with bits.
+
 .SH MAILINGLISTS
 .BR "" "See " http://netfilter.org/mailinglists.html
 .SH SEE ALSO
extensions/Makefile +1 -1
index 09b244e..0189cc9 100644
@@ -1,6 +1,6 @@
 #! /usr/bin/make
 
-EXT_FUNC+=standard mangle CLASSIFY
+EXT_FUNC+=standard mangle CLASSIFY MARK
 EXT_OBJS+=$(foreach T,$(EXT_FUNC), extensions/arpt_$(T).o)
 
 extensions/ebt_%.o: extensions/arpt_%.c include/arptables.h include/arptables_common.h
extensions/arpt_MARK.c new file +151 -0

151 lines not on this page · raw message

Signature · 1 line
1.7.12.4
#4 lore raw
In reply to Zhang Chunyu
Quoted 8 lines · Zhang Chunyu

v1:
add mark target for arptables

v2:
add --and-mark
add --or-mark
add revision for common api

Quoted 7 lines

v3:
fold 2/4, 3/4 and 4/4 patch into one single patch use C99 initialization
change some format

V4:
resubmit the kernel patch

net/netfilter/xt_mark.c is missing a small change, you have to add MODULE_ALIAS("arpt_MARK").

And after that, I hitting here:

# arptables -I OUTPUT -j MARK --set-mark 1
arptables: Protocol wrong type for socket

With my arptables patches applied in first place, so I suspect the right revision is not being set in what we send to the kernel from userspace.

#5 lore raw
Quoted 24 lines

From: Pablo Neira Ayuso
Date: 2015-04-02
To: Zhang, Chunyu/章 春宇
Subject: Re: [PATCH V4 0/3] Add mark target

Quoted 8 lines · Zhang Chunyu

v1:
add mark target for arptables

v2:
add --and-mark
add --or-mark
add revision for common api

Quoted 7 lines

v3:
fold 2/4, 3/4 and 4/4 patch into one single patch use C99 initialization
change some format

V4:
resubmit the kernel patch

Quoted 7 lines

net/netfilter/xt_mark.c is missing a small change, you have to add MODULE_ALIAS("arpt_MARK").

And after that, I hitting here:

# arptables -I OUTPUT -j MARK --set-mark 1
arptables: Protocol wrong type for socket

i will add MODULE_ALIAS("arpt_MARK").
will test and answer again

now i use :

# modprobe xt_mark
# ./arptables  -I OUTPUT -j MARK --set-mark 1
# ./arptables --list
Chain INPUT (policy ACCEPT)

Chain OUTPUT (policy ACCEPT)
-j MARK --set-mark 1

Chain FORWARD (policy ACCEPT)

Quoted 4 lines

With my arptables patches applied in first place, so I suspect the right revision is not being set in what we send to the kernel from userspace.

#6 lore raw
Quoted 34 lines

From: netfilter-devel-owner
Date: 2015-04-02
To: [email protected]
Subject: Re: Re: [PATCH V4 0/3] Add mark target

Quoted 25 lines

From: Pablo Neira Ayuso
Date: 2015-04-02
To: Zhang, Chunyu/章 春宇
Subject: Re: [PATCH V4 0/3] Add mark target

Quoted 8 lines · Zhang Chunyu

v1:
add mark target for arptables

v2:
add --and-mark
add --or-mark
add revision for common api

Quoted 7 lines

v3:
fold 2/4, 3/4 and 4/4 patch into one single patch use C99 initialization
change some format

V4:
resubmit the kernel patch

net/netfilter/xt_mark.c is missing a small change, you have to add MODULE_ALIAS("arpt_MARK").

Quoted 7 lines
Quoted 4 lines

And after that, I hitting here:

# arptables -I OUTPUT -j MARK --set-mark 1
arptables: Protocol wrong type for socket

i will add MODULE_ALIAS("arpt_MARK").
will test and answer again

net/netfilter/xt_mark.c will add :
1. MODULE_ALIAS("arpt_MARK").
2.
static struct xt_target mark_tg_reg[] __read_mostly = {
{
.name = "MARK",
.revision = 2,
.family = NFPROTO_UNSPEC,
.target = mark_tg,
.targetsize = sizeof(struct xt_mark_tginfo2),
.me = THIS_MODULE,
},
{
.name = "MARK",
.revision = 2,
.family = NFPROTO_ARP, < === here !
.target = mark_tg,
.targetsize = sizeof(struct xt_mark_tginfo2),
.me = THIS_MODULE,
}
};

i will fix it in v5

Quoted 17 lines

now i use :

# modprobe xt_mark
# ./arptables  -I OUTPUT -j MARK --set-mark 1
# ./arptables --list
Chain INPUT (policy ACCEPT)

Chain OUTPUT (policy ACCEPT)
-j MARK --set-mark 1

Chain FORWARD (policy ACCEPT)

Quoted 4 lines

With my arptables patches applied in first place, so I suspect the
right revision is not being set in what we send to the kernel from userspace.�{.n�+�������+%��lzwm��b�맲��r��zw�~)mz�^��b��^n�r���z���h����&���G���h�(�階�ݢj"���m�����z�ޖ���f���h���~�m�