Add mark target
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
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
@@ -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
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
@@ -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
@@ -105,6 +105,7 @@ struct arptables_target classifyARPTABLES_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
@@ -199,6 +199,7 @@ struct arptables_target changeARPTABLES_VERSION ,ARPT_ALIGN (sizeof (struct arpt_mangle )),ARPT_ALIGN (sizeof (struct arpt_mangle )), +0 , &help, &init, &parse,
extensions/arpt_standard.c +1 -0
@@ -54,6 +54,7 @@ struct arptables_target standardARPTABLES_VERSION ,ARPT_ALIGN (sizeof (int )),ARPT_ALIGN (sizeof (int )), +0 , &help, &init, &parse,
include/arptables.h +6 -0
@@ -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
PATCH v4 3/3 Add MARK target for arptables
In reply to Zhang ChunyuWe 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
@@ -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
@@ -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
Pablo Neira Ayuso
maintainerQuoted 8 lines · Zhang Chunyu
v1:
add mark target for arptablesv2:
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 formatV4:
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.
Quoted 24 lines
From: Pablo Neira Ayuso
Date: 2015-04-02
To: Zhang, Chunyu/章 春宇
Subject: Re: [PATCH V4 0/3] Add mark targetQuoted 8 lines · Zhang Chunyu
v1:
add mark target for arptablesv2:
add --and-mark
add --or-mark
add revision for common apiQuoted 7 lines
v3:
fold 2/4, 3/4 and 4/4 patch into one single patch use C99 initialization
change some formatV4:
resubmit the kernel patch
Quoted 7 lines
net/netfilter/xt_mark.cis missing a small change, you have to addMODULE_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.
Quoted 34 lines
From: netfilter-devel-owner
Date: 2015-04-02
To: [email protected]
Subject: Re: Re: [PATCH V4 0/3] Add mark targetQuoted 25 lines
From: Pablo Neira Ayuso
Date: 2015-04-02
To: Zhang, Chunyu/章 春宇
Subject: Re: [PATCH V4 0/3] Add mark targetQuoted 8 lines · Zhang Chunyu
v1:
add mark target for arptablesv2:
add --and-mark
add --or-mark
add revision for common apiQuoted 7 lines
v3:
fold 2/4, 3/4 and 4/4 patch into one single patch use C99 initialization
change some formatV4:
resubmit the kernel patch
net/netfilter/xt_mark.cis missing a small change, you have to addMODULE_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 socketi 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 1Chain 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�