* [PATCH V2 0/4] add mark target for arptables
@ 2015-03-25 1:57 Zhang Chunyu
2015-03-25 1:57 ` [PATCH V2 1/4] Add revision field for xt_entry_target Zhang Chunyu
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: Zhang Chunyu @ 2015-03-25 1:57 UTC (permalink / raw)
To: netfilter-devel; +Cc: Zhang Chunyu
v1:
add mark target for arptables
v2:
add --and-mark
add --or-mark
add revision for common api
Zhang Chunyu (4):
Add MARK target for arptables
Update the manpage for MARK target
Add --and-mark and --or-mark
Add revision field for xt_entry_target
arptables.8 | 17 ++++
arptables.c | 2 +
extensions/Makefile | 2 +-
extensions/arpt_CLASSIFY.c | 1 +
extensions/arpt_MARK.c | 156 +++++++++++++++++++++++++++++++
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, 187 insertions(+), 2 deletions(-)
create mode 100644 extensions/arpt_MARK.c
--
1.7.12.4
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH V2 1/4] Add revision field for xt_entry_target
2015-03-25 1:57 [PATCH V2 0/4] add mark target for arptables Zhang Chunyu
@ 2015-03-25 1:57 ` Zhang Chunyu
2015-03-25 1:57 ` [PATCH V2 2/4] Add MARK target for arptables Zhang Chunyu
` (2 subsequent siblings)
3 siblings, 0 replies; 9+ messages in thread
From: Zhang Chunyu @ 2015-03-25 1:57 UTC (permalink / raw)
To: netfilter-devel; +Cc: zhangcy, Gao feng
From: zhangcy <zhangcy@cn.fujitsu.com>
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.
Signed-off-by: Gao feng <gaofeng@cn.fujitsu.com>
Signed-off-by: Zhang Chunyu <zhangcy@cn.fujitsu.com>
---
arptables.c | 2 ++
extensions/arpt_CLASSIFY.c | 1 +
extensions/arpt_mangle.c | 1 +
extensions/arpt_standard.c | 1 +
include/arptables.h | 6 ++++++
include/linux/netfilter_arp/arp_tables.h | 3 ++-
6 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/arptables.c b/arptables.c
index 845e226..3f24ef1 100644
--- a/arptables.c
+++ b/arptables.c
@@ -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);
}
diff --git a/extensions/arpt_CLASSIFY.c b/extensions/arpt_CLASSIFY.c
index cb5770b..7893aed 100644
--- a/extensions/arpt_CLASSIFY.c
+++ b/extensions/arpt_CLASSIFY.c
@@ -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,
diff --git a/extensions/arpt_mangle.c b/extensions/arpt_mangle.c
index c38fc16..502fc2b 100644
--- a/extensions/arpt_mangle.c
+++ b/extensions/arpt_mangle.c
@@ -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,
diff --git a/extensions/arpt_standard.c b/extensions/arpt_standard.c
index cb3891d..c647316 100644
--- a/extensions/arpt_standard.c
+++ b/extensions/arpt_standard.c
@@ -54,6 +54,7 @@ struct arptables_target standard
ARPTABLES_VERSION,
ARPT_ALIGN(sizeof(int)),
ARPT_ALIGN(sizeof(int)),
+ 0,
&help,
&init,
&parse,
diff --git a/include/arptables.h b/include/arptables.h
index 820b664..82e6e9a 100644
--- a/include/arptables.h
+++ b/include/arptables.h
@@ -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);
diff --git a/include/linux/netfilter_arp/arp_tables.h b/include/linux/netfilter_arp/arp_tables.h
index 0acda66..0bf2457 100644
--- a/include/linux/netfilter_arp/arp_tables.h
+++ b/include/linux/netfilter_arp/arp_tables.h
@@ -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;
--
1.7.12.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH V2 2/4] Add MARK target for arptables
2015-03-25 1:57 [PATCH V2 0/4] add mark target for arptables Zhang Chunyu
2015-03-25 1:57 ` [PATCH V2 1/4] Add revision field for xt_entry_target Zhang Chunyu
@ 2015-03-25 1:57 ` Zhang Chunyu
2015-03-25 16:16 ` Pablo Neira Ayuso
2015-03-25 1:57 ` [PATCH V2 3/4] Update the manpage for MARK target Zhang Chunyu
2015-03-25 1:57 ` [PATCH V2 4/4] Add --and-mark and --or-mark Zhang Chunyu
3 siblings, 1 reply; 9+ messages in thread
From: Zhang Chunyu @ 2015-03-25 1:57 UTC (permalink / raw)
To: netfilter-devel; +Cc: Zhang Chunyu, Gao feng
We can use MARK target to set make value for arp packet.
Signed-off-by: Gao feng <gaofeng@cn.fujitsu.com>
Signed-off-by: Zhang Chunyu <zhangcy@cn.fujitsu.com>
---
extensions/Makefile | 2 +-
extensions/arpt_MARK.c | 119 +++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 120 insertions(+), 1 deletion(-)
create mode 100644 extensions/arpt_MARK.c
diff --git a/extensions/Makefile b/extensions/Makefile
index 09b244e..0189cc9 100644
--- a/extensions/Makefile
+++ b/extensions/Makefile
@@ -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
diff --git a/extensions/arpt_MARK.c b/extensions/arpt_MARK.c
new file mode 100644
index 0000000..d9aec8b
--- /dev/null
+++ b/extensions/arpt_MARK.c
@@ -0,0 +1,119 @@
+/*
+ * (C) 2014 by Gao Feng <gaofeng@cn.fujitsu.com>
+ *
+ * arpt_MARK.c -- arptables extension to set mark for arp packet
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <stdio.h>
+#include <getopt.h>
+#include <arptables.h>
+#include <linux/netfilter/xt_mark.h>
+#include <linux/netfilter/xt_MARK.h>
+#include <linux/netfilter/x_tables.h>
+
+static void
+help(void)
+{
+ printf(
+"MARK target v%s options:\n"
+"--set-mark mark : set the mark value\n",
+ ARPTABLES_VERSION);
+}
+
+#define MARK_OPT 1
+
+static struct option opts[] = {
+ { "set-mark" , required_argument, 0, MARK_OPT },
+ {0}
+};
+
+static void
+init(struct arpt_entry_target *t)
+{
+ struct xt_mark_tginfo2 *info = (struct xt_mark_tginfo2 *) t->data;
+
+ info->mark = 0;
+}
+
+static int
+parse(int c, char **argv, int invert, unsigned int *flags,
+ const struct arpt_entry *e,
+ struct arpt_entry_target **t)
+{
+ struct xt_mark_tginfo2 *info = (struct xt_mark_tginfo2 *)(*t)->data;
+ int i;
+
+ switch (c) {
+ case MARK_OPT:
+ if (sscanf(argv[optind-1], "%x", &i) != 1) {
+ exit_error(PARAMETER_PROBLEM,
+ "Bad mark value `%s'", optarg);
+ return 0;
+ }
+ info->mark = i;
+ if (*flags)
+ exit_error(PARAMETER_PROBLEM,
+ "CLASSIFY: Can't specify --set-mark twice");
+ *flags = 1;
+ break;
+ default:
+ return 0;
+ }
+ return 1;
+}
+
+static void final_check(unsigned int flags)
+{
+ if (!flags)
+ exit_error(PARAMETER_PROBLEM, "MARK: Parameter --set-mark is required");
+}
+
+static void print(const struct arpt_arp *ip,
+ const struct arpt_entry_target *target, int numeric)
+{
+ struct xt_mark_tginfo2 *info = (struct xt_mark_tginfo2 *)(target->data);
+
+ printf("--set-mark %x ", info->mark);
+}
+
+static void
+save(const struct arpt_arp *ip, const struct arpt_entry_target *target)
+{
+}
+
+static
+struct arptables_target mark
+= { NULL,
+ "MARK",
+ ARPTABLES_VERSION,
+ ARPT_ALIGN(sizeof(struct xt_mark_tginfo2)),
+ ARPT_ALIGN(sizeof(struct xt_mark_tginfo2)),
+ 2,
+ &help,
+ &init,
+ &parse,
+ &final_check,
+ &print,
+ &save,
+ opts
+};
+
+static void _init(void) __attribute__ ((constructor));
+static void _init(void)
+{
+ register_target(&mark);
+}
--
1.7.12.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH V2 3/4] Update the manpage for MARK target
2015-03-25 1:57 [PATCH V2 0/4] add mark target for arptables Zhang Chunyu
2015-03-25 1:57 ` [PATCH V2 1/4] Add revision field for xt_entry_target Zhang Chunyu
2015-03-25 1:57 ` [PATCH V2 2/4] Add MARK target for arptables Zhang Chunyu
@ 2015-03-25 1:57 ` Zhang Chunyu
2015-03-25 1:57 ` [PATCH V2 4/4] Add --and-mark and --or-mark Zhang Chunyu
3 siblings, 0 replies; 9+ messages in thread
From: Zhang Chunyu @ 2015-03-25 1:57 UTC (permalink / raw)
To: netfilter-devel; +Cc: Zhang Chunyu, Gao feng
Signed-off-by: Gao feng <gaofeng@cn.fujitsu.com>
Signed-off-by: Zhang Chunyu <zhangcy@cn.fujitsu.com>
---
arptables.8 | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/arptables.8 b/arptables.8
index 78b2c60..a0ada83 100644
--- a/arptables.8
+++ b/arptables.8
@@ -315,6 +315,16 @@ 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.
+
.SH MAILINGLISTS
.BR "" "See " http://netfilter.org/mailinglists.html
.SH SEE ALSO
--
1.7.12.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH V2 4/4] Add --and-mark and --or-mark
2015-03-25 1:57 [PATCH V2 0/4] add mark target for arptables Zhang Chunyu
` (2 preceding siblings ...)
2015-03-25 1:57 ` [PATCH V2 3/4] Update the manpage for MARK target Zhang Chunyu
@ 2015-03-25 1:57 ` Zhang Chunyu
2015-03-25 16:16 ` Pablo Neira Ayuso
3 siblings, 1 reply; 9+ messages in thread
From: Zhang Chunyu @ 2015-03-25 1:57 UTC (permalink / raw)
To: netfilter-devel; +Cc: Zhang Chunyu, Gao feng
Signed-off-by: Gao feng <gaofeng@cn.fujitsu.com>
Signed-off-by: Zhang Chunyu <zhangcy@cn.fujitsu.com>
---
arptables.8 | 11 +++++++++--
extensions/arpt_MARK.c | 47 ++++++++++++++++++++++++++++++++++++++++++-----
2 files changed, 51 insertions(+), 7 deletions(-)
diff --git a/arptables.8 b/arptables.8
index a0ada83..676b884 100644
--- a/arptables.8
+++ b/arptables.8
@@ -321,9 +321,16 @@ 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
-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
diff --git a/extensions/arpt_MARK.c b/extensions/arpt_MARK.c
index d9aec8b..b03a8fc 100644
--- a/extensions/arpt_MARK.c
+++ b/extensions/arpt_MARK.c
@@ -30,14 +30,21 @@ help(void)
{
printf(
"MARK target v%s options:\n"
-"--set-mark mark : set the mark value\n",
+"--set-mark mark : set the mark value\n"
+"--and-mark value : binary AND the mark with value\n"
+"--or-mark value : binary OR the mark with value\n",
ARPTABLES_VERSION);
}
#define MARK_OPT 1
+#define AND_MARK_OPT 2
+#define OR_MARK_OPT 3
+
static struct option opts[] = {
{ "set-mark" , required_argument, 0, MARK_OPT },
+ { "and-mark" , required_argument, 0, AND_MARK_OPT },
+ { "or-mark" , required_argument, 0, OR_MARK_OPT },
{0}
};
@@ -67,9 +74,34 @@ parse(int c, char **argv, int invert, unsigned int *flags,
info->mark = i;
if (*flags)
exit_error(PARAMETER_PROBLEM,
- "CLASSIFY: Can't specify --set-mark twice");
+ "MARK: Can't specify --set-mark twice");
+ *flags = 1;
+ break;
+ case AND_MARK_OPT:
+ if (sscanf(argv[optind-1], "%x", &i) != 1) {
+ exit_error(PARAMETER_PROBLEM,
+ "Bad mark value `%s'", optarg);
+ return 0;
+ }
+ info->mark = 0;
+ info->mask = ~i;
+ if (*flags)
+ exit_error(PARAMETER_PROBLEM,
+ "MARK: Can't specify --and-mark twice");
*flags = 1;
break;
+ case OR_MARK_OPT:
+ if (sscanf(argv[optind-1], "%x", &i) != 1) {
+ exit_error(PARAMETER_PROBLEM,
+ "Bad mark value `%s'", optarg);
+ return 0;
+ }
+ info->mark = info->mask = i;
+ if (*flags)
+ exit_error(PARAMETER_PROBLEM,
+ "MARK: Can't specify --or-mark twice");
+ *flags = 1;
+ break;
default:
return 0;
}
@@ -79,15 +111,20 @@ parse(int c, char **argv, int invert, unsigned int *flags,
static void final_check(unsigned int flags)
{
if (!flags)
- exit_error(PARAMETER_PROBLEM, "MARK: Parameter --set-mark is required");
+ exit_error(PARAMETER_PROBLEM, "MARK: Parameter --set-mark/--and-mark/--or-mark is required");
}
static void print(const struct arpt_arp *ip,
const struct arpt_entry_target *target, int numeric)
{
struct xt_mark_tginfo2 *info = (struct xt_mark_tginfo2 *)(target->data);
-
- printf("--set-mark %x ", info->mark);
+
+ if (info->mark == 0)
+ printf("--and-mark %x", (unsigned int)(uint32_t)~info->mask);
+ else if (info->mark == info->mask)
+ printf("--or-mark %x", info->mark);
+ else
+ printf("--set-mark %x", info->mark);
}
static void
--
1.7.12.4
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH V2 2/4] Add MARK target for arptables
2015-03-25 1:57 ` [PATCH V2 2/4] Add MARK target for arptables Zhang Chunyu
@ 2015-03-25 16:16 ` Pablo Neira Ayuso
2015-03-26 1:43 ` Zhang, Chunyu
0 siblings, 1 reply; 9+ messages in thread
From: Pablo Neira Ayuso @ 2015-03-25 16:16 UTC (permalink / raw)
To: Zhang Chunyu; +Cc: netfilter-devel, Gao feng
On Tue, Mar 24, 2015 at 09:57:34PM -0400, Zhang Chunyu wrote:
> We can use MARK target to set make value for arp packet.
>
> Signed-off-by: Gao feng <gaofeng@cn.fujitsu.com>
> Signed-off-by: Zhang Chunyu <zhangcy@cn.fujitsu.com>
> ---
> extensions/Makefile | 2 +-
> extensions/arpt_MARK.c | 119 +++++++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 120 insertions(+), 1 deletion(-)
> create mode 100644 extensions/arpt_MARK.c
>
> diff --git a/extensions/Makefile b/extensions/Makefile
> index 09b244e..0189cc9 100644
> --- a/extensions/Makefile
> +++ b/extensions/Makefile
> @@ -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
> diff --git a/extensions/arpt_MARK.c b/extensions/arpt_MARK.c
> new file mode 100644
> index 0000000..d9aec8b
> --- /dev/null
> +++ b/extensions/arpt_MARK.c
> @@ -0,0 +1,119 @@
> +/*
> + * (C) 2014 by Gao Feng <gaofeng@cn.fujitsu.com>
> + *
> + * arpt_MARK.c -- arptables extension to set mark for arp packet
> + *
> + * 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.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
> + */
> +
> +#include <stdio.h>
> +#include <getopt.h>
> +#include <arptables.h>
> +#include <linux/netfilter/xt_mark.h>
> +#include <linux/netfilter/xt_MARK.h>
> +#include <linux/netfilter/x_tables.h>
> +
> +static void
> +help(void)
Place this in the same line, ie.
static void help(void)
> +{
> + printf(
> +"MARK target v%s options:\n"
> +"--set-mark mark : set the mark value\n",
> + ARPTABLES_VERSION);
> +}
> +
> +#define MARK_OPT 1
> +
> +static struct option opts[] = {
> + { "set-mark" , required_argument, 0, MARK_OPT },
Could you use C99 initialization for this?
I know other extensions don't because this code is rather old, but it
would be good to good at least new code in better shape.
> + {0}
> +};
> +
> +static void
> +init(struct arpt_entry_target *t)
> +{
> + struct xt_mark_tginfo2 *info = (struct xt_mark_tginfo2 *) t->data;
> +
> + info->mark = 0;
> +}
> +
> +static int
> +parse(int c, char **argv, int invert, unsigned int *flags,
> + const struct arpt_entry *e,
> + struct arpt_entry_target **t)
> +{
> + struct xt_mark_tginfo2 *info = (struct xt_mark_tginfo2 *)(*t)->data;
> + int i;
> +
> + switch (c) {
> + case MARK_OPT:
We prefer:
switch (c) {
case MARK_OPT:
...
> + if (sscanf(argv[optind-1], "%x", &i) != 1) {
> + exit_error(PARAMETER_PROBLEM,
> + "Bad mark value `%s'", optarg);
exit_error(...
"Bad mark..."
> + return 0;
> + }
> + info->mark = i;
> + if (*flags)
> + exit_error(PARAMETER_PROBLEM,
> + "CLASSIFY: Can't specify --set-mark twice");
> + *flags = 1;
> + break;
> + default:
> + return 0;
> + }
> + return 1;
> +}
> +
> +static void final_check(unsigned int flags)
> +{
> + if (!flags)
> + exit_error(PARAMETER_PROBLEM, "MARK: Parameter --set-mark is required");
> +}
> +
> +static void print(const struct arpt_arp *ip,
> + const struct arpt_entry_target *target, int numeric)
> +{
> + struct xt_mark_tginfo2 *info = (struct xt_mark_tginfo2 *)(target->data);
> +
> + printf("--set-mark %x ", info->mark);
> +}
> +
> +static void
> +save(const struct arpt_arp *ip, const struct arpt_entry_target *target)
> +{
> +}
> +
> +static
> +struct arptables_target mark
> += { NULL,
> + "MARK",
> + ARPTABLES_VERSION,
> + ARPT_ALIGN(sizeof(struct xt_mark_tginfo2)),
> + ARPT_ALIGN(sizeof(struct xt_mark_tginfo2)),
> + 2,
> + &help,
> + &init,
> + &parse,
> + &final_check,
> + &print,
> + &save,
> + opts
Please, use C99 structure initialization here too.
> +};
> +
> +static void _init(void) __attribute__ ((constructor));
> +static void _init(void)
> +{
> + register_target(&mark);
> +}
> --
> 1.7.12.4
>
> --
> To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH V2 4/4] Add --and-mark and --or-mark
2015-03-25 1:57 ` [PATCH V2 4/4] Add --and-mark and --or-mark Zhang Chunyu
@ 2015-03-25 16:16 ` Pablo Neira Ayuso
2015-03-26 1:39 ` Zhang, Chunyu
0 siblings, 1 reply; 9+ messages in thread
From: Pablo Neira Ayuso @ 2015-03-25 16:16 UTC (permalink / raw)
To: Zhang Chunyu; +Cc: netfilter-devel, Gao feng
Please fold 2/4, 3/4 and 4/4 into one single patch and resubmit.
Thanks.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Re: [PATCH V2 4/4] Add --and-mark and --or-mark
2015-03-25 16:16 ` Pablo Neira Ayuso
@ 2015-03-26 1:39 ` Zhang, Chunyu
0 siblings, 0 replies; 9+ messages in thread
From: Zhang, Chunyu @ 2015-03-26 1:39 UTC (permalink / raw)
To: pablo; +Cc: netfilter-devel
>From: Pablo Neira Ayuso
>Date: 2015-03-26
>To: Zhang, Chunyu/章 春宇
>Subject: Re: [PATCH V2 4/4] Add --and-mark and --or-mark
>
>Please fold 2/4, 3/4 and 4/4 into one single patch and resubmit.
ok. will do it in v3
>
>Thanks.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Re: [PATCH V2 2/4] Add MARK target for arptables
2015-03-25 16:16 ` Pablo Neira Ayuso
@ 2015-03-26 1:43 ` Zhang, Chunyu
0 siblings, 0 replies; 9+ messages in thread
From: Zhang, Chunyu @ 2015-03-26 1:43 UTC (permalink / raw)
To: pablo; +Cc: netfilter-devel, Gao, Feng/高 峰
>From: netfilter-devel-owner
>Date: 2015-03-26
>To: Zhang, Chunyu/章 春宇
>Subject: Re: [PATCH V2 2/4] Add MARK target for arptables
>
>On Tue, Mar 24, 2015 at 09:57:34PM -0400, Zhang Chunyu wrote:
>> We can use MARK target to set make value for arp packet.
>>
>> Signed-off-by: Gao feng <gaofeng@cn.fujitsu.com>
>> Signed-off-by: Zhang Chunyu <zhangcy@cn.fujitsu.com>
>> ---
>> extensions/Makefile | 2 +-
>> extensions/arpt_MARK.c | 119 +++++++++++++++++++++++++++++++++++++++++++++++++
>> 2 files changed, 120 insertions(+), 1 deletion(-)
>> create mode 100644 extensions/arpt_MARK.c
>>
>> diff --git a/extensions/Makefile b/extensions/Makefile
>> index 09b244e..0189cc9 100644
>> --- a/extensions/Makefile
>> +++ b/extensions/Makefile
>> @@ -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
>> diff --git a/extensions/arpt_MARK.c b/extensions/arpt_MARK.c
>> new file mode 100644
>> index 0000000..d9aec8b
>> --- /dev/null
>> +++ b/extensions/arpt_MARK.c
>> @@ -0,0 +1,119 @@
>> +/*
>> + * (C) 2014 by Gao Feng <gaofeng@cn.fujitsu.com>
>> + *
>> + * arpt_MARK.c -- arptables extension to set mark for arp packet
>> + *
>> + * 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.
>> + *
>> + * This program is distributed in the hope that it will be useful,
>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
>> + * GNU General Public License for more details.
>> + *
>> + * You should have received a copy of the GNU General Public License
>> + * along with this program; if not, write to the Free Software
>> + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
>> + */
>> +
>> +#include <stdio.h>
>> +#include <getopt.h>
>> +#include <arptables.h>
>> +#include <linux/netfilter/xt_mark.h>
>> +#include <linux/netfilter/xt_MARK.h>
>> +#include <linux/netfilter/x_tables.h>
>> +
>> +static void
>> +help(void)
>
>Place this in the same line, ie.
>
>static void help(void)
ok. will fix it in v3.
>
>> +{
>> + printf(
>> +"MARK target v%s options:\n"
>> +"--set-mark mark : set the mark value\n",
>> + ARPTABLES_VERSION);
>> +}
>> +
>> +#define MARK_OPT 1
>> +
>> +static struct option opts[] = {
>> + { "set-mark" , required_argument, 0, MARK_OPT },
>
>Could you use C99 initialization for this?
>
>I know other extensions don't because this code is rather old, but it
>would be good to good at least new code in better shape.
ok. will fix it in v3.
>
>> + {0}
>> +};
>> +
>> +static void
>> +init(struct arpt_entry_target *t)
>> +{
>> + struct xt_mark_tginfo2 *info = (struct xt_mark_tginfo2 *) t->data;
>> +
>> + info->mark = 0;
>> +}
>> +
>> +static int
>> +parse(int c, char **argv, int invert, unsigned int *flags,
>> + const struct arpt_entry *e,
>> + struct arpt_entry_target **t)
>> +{
>> + struct xt_mark_tginfo2 *info = (struct xt_mark_tginfo2 *)(*t)->data;
>> + int i;
>> +
>> + switch (c) {
>> + case MARK_OPT:
>
>We prefer:
>
> switch (c) {
> case MARK_OPT:
> ...
ok. will fix it in v3.
>
>> + if (sscanf(argv[optind-1], "%x", &i) != 1) {
>> + exit_error(PARAMETER_PROBLEM,
>> + "Bad mark value `%s'", optarg);
>
> exit_error(...
> "Bad mark..."
>
>> + return 0;
>> + }
>> + info->mark = i;
>> + if (*flags)
>> + exit_error(PARAMETER_PROBLEM,
>> + "CLASSIFY: Can't specify --set-mark twice");
>> + *flags = 1;
>> + break;
>> + default:
>> + return 0;
>> + }
>> + return 1;
>> +}
>> +
>> +static void final_check(unsigned int flags)
>> +{
>> + if (!flags)
>> + exit_error(PARAMETER_PROBLEM, "MARK: Parameter --set-mark is required");
>> +}
>> +
>> +static void print(const struct arpt_arp *ip,
>> + const struct arpt_entry_target *target, int numeric)
>> +{
>> + struct xt_mark_tginfo2 *info = (struct xt_mark_tginfo2 *)(target->data);
>> +
>> + printf("--set-mark %x ", info->mark);
>> +}
>> +
>> +static void
>> +save(const struct arpt_arp *ip, const struct arpt_entry_target *target)
>> +{
>> +}
>> +
>> +static
>> +struct arptables_target mark
>> += { NULL,
>> + "MARK",
>> + ARPTABLES_VERSION,
>> + ARPT_ALIGN(sizeof(struct xt_mark_tginfo2)),
>> + ARPT_ALIGN(sizeof(struct xt_mark_tginfo2)),
>> + 2,
>> + &help,
>> + &init,
>> + &parse,
>> + &final_check,
>> + &print,
>> + &save,
>> + opts
>
>Please, use C99 structure initialization here too.
ok. will fix it in v3.
thanks!
>
>> +};
>> +
>> +static void _init(void) __attribute__ ((constructor));
>> +static void _init(void)
>> +{
>> + register_target(&mark);
>> +}
>> --
>> 1.7.12.4
>>
>> --
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2015-03-26 1:43 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-25 1:57 [PATCH V2 0/4] add mark target for arptables Zhang Chunyu
2015-03-25 1:57 ` [PATCH V2 1/4] Add revision field for xt_entry_target Zhang Chunyu
2015-03-25 1:57 ` [PATCH V2 2/4] Add MARK target for arptables Zhang Chunyu
2015-03-25 16:16 ` Pablo Neira Ayuso
2015-03-26 1:43 ` Zhang, Chunyu
2015-03-25 1:57 ` [PATCH V2 3/4] Update the manpage for MARK target Zhang Chunyu
2015-03-25 1:57 ` [PATCH V2 4/4] Add --and-mark and --or-mark Zhang Chunyu
2015-03-25 16:16 ` Pablo Neira Ayuso
2015-03-26 1:39 ` Zhang, Chunyu
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.