4 * Bart De Schuymer <bdschuym@pandora.be>
13 #include "../include/ebtables_u.h"
14 #include <linux/netfilter_bridge/ebt_mark_m.h>
18 static struct option opts
[] =
20 { "mark", required_argument
, 0, MARK
},
24 static void print_help()
28 "--mark [!] [value][/mask]: Match nfmask value (see man page)\n");
31 static void init(struct ebt_entry_match
*match
)
33 struct ebt_mark_m_info
*markinfo
= (struct ebt_mark_m_info
*)match
->data
;
38 markinfo
->bitmask
= 0;
42 static int parse(int c
, char **argv
, int argc
, const struct ebt_u_entry
*entry
,
43 unsigned int *flags
, struct ebt_entry_match
**match
)
45 struct ebt_mark_m_info
*markinfo
= (struct ebt_mark_m_info
*)
51 ebt_check_option2(flags
, MARK
);
52 if (ebt_check_inverse2(optarg
))
54 markinfo
->mark
= strtoul(optarg
, &end
, 0);
55 markinfo
->bitmask
= EBT_MARK_AND
;
58 markinfo
->bitmask
= EBT_MARK_OR
;
59 markinfo
->mask
= strtoul(end
+1, &end
, 0);
61 markinfo
->mask
= 0xffffffff;
62 if ( *end
!= '\0' || end
== optarg
)
63 ebt_print_error2("Bad mark value '%s'", optarg
);
71 static void final_check(const struct ebt_u_entry
*entry
,
72 const struct ebt_entry_match
*match
, const char *name
,
73 unsigned int hookmask
, unsigned int time
)
77 static void print(const struct ebt_u_entry
*entry
,
78 const struct ebt_entry_match
*match
)
80 struct ebt_mark_m_info
*markinfo
=
81 (struct ebt_mark_m_info
*)match
->data
;
86 if (markinfo
->bitmask
== EBT_MARK_OR
)
87 printf("/0x%lx ", markinfo
->mask
);
88 else if(markinfo
->mask
!= 0xffffffff)
89 printf("0x%lx/0x%lx ", markinfo
->mark
, markinfo
->mask
);
91 printf("0x%lx ", markinfo
->mark
);
94 static int compare(const struct ebt_entry_match
*m1
,
95 const struct ebt_entry_match
*m2
)
97 struct ebt_mark_m_info
*markinfo1
= (struct ebt_mark_m_info
*)m1
->data
;
98 struct ebt_mark_m_info
*markinfo2
= (struct ebt_mark_m_info
*)m2
->data
;
100 if (markinfo1
->invert
!= markinfo2
->invert
)
102 if (markinfo1
->mark
!= markinfo2
->mark
)
104 if (markinfo1
->mask
!= markinfo2
->mask
)
106 if (markinfo1
->bitmask
!= markinfo2
->bitmask
)
111 static struct ebt_u_match mark_match
=
114 .size
= sizeof(struct ebt_mark_m_info
),
118 .final_check
= final_check
,
126 ebt_register_match(&mark_match
);