Skip to content

Commit 28b9498

Browse files
Jan Engelhardtkaber
authored andcommitted
netfilter: xtables: merge xt_MARK into xt_mark
Two arguments for combining the two: - xt_mark is pretty useless without xt_MARK - the actual code is so small anyway that the kmod metadata and the module in its loaded state totally outweighs the combined actual code size. i586-before: -rw-r--r-- 1 jengelh users 3821 Feb 10 01:01 xt_MARK.ko -rw-r--r-- 1 jengelh users 2592 Feb 10 00:04 xt_MARK.o -rw-r--r-- 1 jengelh users 3274 Feb 10 01:01 xt_mark.ko -rw-r--r-- 1 jengelh users 2108 Feb 10 00:05 xt_mark.o text data bss dec hex filename 354 264 0 618 26a xt_MARK.o 223 176 0 399 18f xt_mark.o And the runtime size is like 14 KB. i586-after: -rw-r--r-- 1 jengelh users 3264 Feb 18 17:28 xt_mark.o Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
1 parent 44c5873 commit 28b9498

6 files changed

Lines changed: 70 additions & 82 deletions

File tree

‎include/linux/netfilter/xt_MARK.h‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
#ifndef _XT_MARK_H_target
22
#define _XT_MARK_H_target
33

4-
#include <linux/types.h>
5-
6-
struct xt_mark_tginfo2 {
7-
__u32 mark, mask;
8-
};
4+
#include <linux/netfilter/xt_mark.h>
95

106
#endif /*_XT_MARK_H_target */

‎include/linux/netfilter/xt_mark.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44
#include <linux/types.h>
55

6+
struct xt_mark_tginfo2 {
7+
__u32 mark, mask;
8+
};
9+
610
struct xt_mark_mtinfo1 {
711
__u32 mark, mask;
812
__u8 invert;

‎net/netfilter/Kconfig‎

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,23 @@ config NETFILTER_XTABLES
314314

315315
if NETFILTER_XTABLES
316316

317+
comment "Xtables combined modules"
318+
319+
config NETFILTER_XT_MARK
320+
tristate 'nfmark target and match support'
321+
default m if NETFILTER_ADVANCED=n
322+
---help---
323+
This option adds the "MARK" target and "mark" match.
324+
325+
Netfilter mark matching allows you to match packets based on the
326+
"nfmark" value in the packet.
327+
The target allows you to create rules in the "mangle" table which alter
328+
the netfilter mark (nfmark) field associated with the packet.
329+
330+
Prior to routing, the nfmark can influence the routing method (see
331+
"Use netfilter MARK value as routing key") and can also be used by
332+
other subsystems to change their behavior.
333+
317334
# alphabetically ordered list of targets
318335

319336
comment "Xtables targets"
@@ -425,16 +442,12 @@ config NETFILTER_XT_TARGET_LED
425442

426443
config NETFILTER_XT_TARGET_MARK
427444
tristate '"MARK" target support'
428-
default m if NETFILTER_ADVANCED=n
429-
help
430-
This option adds a `MARK' target, which allows you to create rules
431-
in the `mangle' table which alter the netfilter mark (nfmark) field
432-
associated with the packet prior to routing. This can change
433-
the routing method (see `Use netfilter MARK value as routing
434-
key') and can also be used by other subsystems to change their
435-
behavior.
436-
437-
To compile it as a module, choose M here. If unsure, say N.
445+
depends on NETFILTER_ADVANCED
446+
select NETFILTER_XT_MARK
447+
---help---
448+
This is a backwards-compat option for the user's convenience
449+
(e.g. when running oldconfig). It selects
450+
CONFIG_NETFILTER_XT_MARK (combined mark/MARK module).
438451

439452
config NETFILTER_XT_TARGET_NFLOG
440453
tristate '"NFLOG" target support'
@@ -739,13 +752,12 @@ config NETFILTER_XT_MATCH_MAC
739752

740753
config NETFILTER_XT_MATCH_MARK
741754
tristate '"mark" match support'
742-
default m if NETFILTER_ADVANCED=n
743-
help
744-
Netfilter mark matching allows you to match packets based on the
745-
`nfmark' value in the packet. This can be set by the MARK target
746-
(see below).
747-
748-
To compile it as a module, choose M here. If unsure, say N.
755+
depends on NETFILTER_ADVANCED
756+
select NETFILTER_XT_MARK
757+
---help---
758+
This is a backwards-compat option for the user's convenience
759+
(e.g. when running oldconfig). It selects
760+
CONFIG_NETFILTER_XT_MARK (combined mark/MARK module).
749761

750762
config NETFILTER_XT_MATCH_MULTIPORT
751763
tristate '"multiport" Multiple port match support'

‎net/netfilter/Makefile‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ obj-$(CONFIG_NETFILTER_TPROXY) += nf_tproxy_core.o
4040
# generic X tables
4141
obj-$(CONFIG_NETFILTER_XTABLES) += x_tables.o xt_tcpudp.o
4242

43+
# combos
44+
obj-$(CONFIG_NETFILTER_XT_MARK) += xt_mark.o
45+
4346
# targets
4447
obj-$(CONFIG_NETFILTER_XT_TARGET_CLASSIFY) += xt_CLASSIFY.o
4548
obj-$(CONFIG_NETFILTER_XT_TARGET_CONNMARK) += xt_CONNMARK.o
@@ -48,7 +51,6 @@ obj-$(CONFIG_NETFILTER_XT_TARGET_CT) += xt_CT.o
4851
obj-$(CONFIG_NETFILTER_XT_TARGET_DSCP) += xt_DSCP.o
4952
obj-$(CONFIG_NETFILTER_XT_TARGET_HL) += xt_HL.o
5053
obj-$(CONFIG_NETFILTER_XT_TARGET_LED) += xt_LED.o
51-
obj-$(CONFIG_NETFILTER_XT_TARGET_MARK) += xt_MARK.o
5254
obj-$(CONFIG_NETFILTER_XT_TARGET_NFLOG) += xt_NFLOG.o
5355
obj-$(CONFIG_NETFILTER_XT_TARGET_NFQUEUE) += xt_NFQUEUE.o
5456
obj-$(CONFIG_NETFILTER_XT_TARGET_NOTRACK) += xt_NOTRACK.o
@@ -76,7 +78,6 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_IPRANGE) += xt_iprange.o
7678
obj-$(CONFIG_NETFILTER_XT_MATCH_LENGTH) += xt_length.o
7779
obj-$(CONFIG_NETFILTER_XT_MATCH_LIMIT) += xt_limit.o
7880
obj-$(CONFIG_NETFILTER_XT_MATCH_MAC) += xt_mac.o
79-
obj-$(CONFIG_NETFILTER_XT_MATCH_MARK) += xt_mark.o
8081
obj-$(CONFIG_NETFILTER_XT_MATCH_MULTIPORT) += xt_multiport.o
8182
obj-$(CONFIG_NETFILTER_XT_MATCH_OSF) += xt_osf.o
8283
obj-$(CONFIG_NETFILTER_XT_MATCH_OWNER) += xt_owner.o

‎net/netfilter/xt_MARK.c‎

Lines changed: 0 additions & 56 deletions
This file was deleted.

‎net/netfilter/xt_mark.c‎

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,20 @@
1818

1919
MODULE_LICENSE("GPL");
2020
MODULE_AUTHOR("Marc Boucher <marc@mbsi.ca>");
21-
MODULE_DESCRIPTION("Xtables: packet mark match");
21+
MODULE_DESCRIPTION("Xtables: packet mark operations");
2222
MODULE_ALIAS("ipt_mark");
2323
MODULE_ALIAS("ip6t_mark");
24+
MODULE_ALIAS("ipt_MARK");
25+
MODULE_ALIAS("ip6t_MARK");
26+
27+
static unsigned int
28+
mark_tg(struct sk_buff *skb, const struct xt_target_param *par)
29+
{
30+
const struct xt_mark_tginfo2 *info = par->targinfo;
31+
32+
skb->mark = (skb->mark & ~info->mask) ^ info->mark;
33+
return XT_CONTINUE;
34+
}
2435

2536
static bool
2637
mark_mt(const struct sk_buff *skb, const struct xt_match_param *par)
@@ -30,6 +41,15 @@ mark_mt(const struct sk_buff *skb, const struct xt_match_param *par)
3041
return ((skb->mark & info->mask) == info->mark) ^ info->invert;
3142
}
3243

44+
static struct xt_target mark_tg_reg __read_mostly = {
45+
.name = "MARK",
46+
.revision = 2,
47+
.family = NFPROTO_UNSPEC,
48+
.target = mark_tg,
49+
.targetsize = sizeof(struct xt_mark_tginfo2),
50+
.me = THIS_MODULE,
51+
};
52+
3353
static struct xt_match mark_mt_reg __read_mostly = {
3454
.name = "mark",
3555
.revision = 1,
@@ -41,12 +61,23 @@ static struct xt_match mark_mt_reg __read_mostly = {
4161

4262
static int __init mark_mt_init(void)
4363
{
44-
return xt_register_match(&mark_mt_reg);
64+
int ret;
65+
66+
ret = xt_register_target(&mark_tg_reg);
67+
if (ret < 0)
68+
return ret;
69+
ret = xt_register_match(&mark_mt_reg);
70+
if (ret < 0) {
71+
xt_unregister_target(&mark_tg_reg);
72+
return ret;
73+
}
74+
return 0;
4575
}
4676

4777
static void __exit mark_mt_exit(void)
4878
{
4979
xt_unregister_match(&mark_mt_reg);
80+
xt_unregister_target(&mark_tg_reg);
5081
}
5182

5283
module_init(mark_mt_init);

0 commit comments

Comments
 (0)