--- iptables-1.2.7a-old/extensions/libipt_MARK.c 2002-08-05 16:26:47.000000000 +0200 +++ iptables-1.2.7a-new/extensions/libipt_MARK.c 2003-01-15 02:22:05.000000000 +0100 @@ -8,11 +8,6 @@ #include #include -struct markinfo { - struct ipt_entry_target t; - struct ipt_mark_target_info mark; -}; - /* Function which prints out usage message. */ static void help(void) @@ -20,12 +15,20 @@ printf( "MARK target v%s options:\n" " --set-mark value Set nfmark value\n" +#ifdef MARK_BITOPS +" --and-mark value Binary AND the nfmark with value\n" +" --or-mark value Binary OR the nfmark with value\n" +#endif "\n", IPTABLES_VERSION); } static struct option opts[] = { { "set-mark", 1, 0, '1' }, +#ifdef MARK_BITOPS + { "and-mark", 1, 0, '2' }, + { "or-mark", 1, 0, '3' }, +#endif { 0 } }; @@ -42,24 +45,40 @@ const struct ipt_entry *entry, struct ipt_entry_target **target) { - struct ipt_mark_target_info *markinfo - = (struct ipt_mark_target_info *)(*target)->data; +#ifdef MARK_BITOPS + struct ipt_mark_bitops_target_info *markinfo + = (struct ipt_mark_bitops_target_info *)(*target)->data; switch (c) { case '1': - if (string_to_number(optarg, 0, 0xffffffff, - (unsigned int *)&markinfo->mark)) - exit_error(PARAMETER_PROBLEM, "Bad MARK value `%s'", optarg); - if (*flags) - exit_error(PARAMETER_PROBLEM, - "MARK target: Can't specify --set-mark twice"); - *flags = 1; + markinfo->mode = IPT_MARK_SET; + break; + case '2': + markinfo->mode = IPT_MARK_AND; + break; + case '3': + markinfo->mode = IPT_MARK_OR; break; - default: return 0; } - +#else + struct ipt_mark_target_info *markinfo + = (struct ipt_mark_target_info *)(*target)->data; + if (c != '1') + return 0; +#endif + if (string_to_number(optarg, 0, 0xffffffff, + (unsigned int *)&markinfo->mark)) + exit_error(PARAMETER_PROBLEM, + "Bad MARK value `%s'", optarg); + + if (*flags) + exit_error(PARAMETER_PROBLEM, + "MARK target: " + "Can't specify operation twice"); + *flags = 1; + return 1; } @@ -68,7 +87,7 @@ { if (!flags) exit_error(PARAMETER_PROBLEM, - "MARK target: Parameter --set-mark is required"); + "MARK target: Additional parameter required"); } static void @@ -83,20 +102,53 @@ const struct ipt_entry_target *target, int numeric) { +#ifdef MARK_BITOPS + const struct ipt_mark_bitops_target_info *markinfo = + (const struct ipt_mark_bitops_target_info *)target->data; + switch (markinfo->mode) { + case IPT_MARK_SET: + printf("MARK set "); + break; + case IPT_MARK_AND: + printf("MARK and "); + break; + case IPT_MARK_OR: + printf("MARK or "); + break; + } +#else const struct ipt_mark_target_info *markinfo = (const struct ipt_mark_target_info *)target->data; printf("MARK set "); +#endif print_mark(markinfo->mark, numeric); + } /* Saves the union ipt_targinfo in parsable form to stdout. */ static void save(const struct ipt_ip *ip, const struct ipt_entry_target *target) { +#ifdef MARK_BITOPS + const struct ipt_mark_bitops_target_info *markinfo = + (const struct ipt_mark_bitops_target_info *)target->data; + switch (markinfo->mode) { + case IPT_MARK_SET: + printf("--set-mark "); + break; + case IPT_MARK_AND: + printf("--and-mark "); + break; + case IPT_MARK_OR: + printf("--or-mark "); + break; + } +#else const struct ipt_mark_target_info *markinfo = (const struct ipt_mark_target_info *)target->data; - - printf("--set-mark 0x%lx ", markinfo->mark); + printf("--set-mark "); +#endif + print_mark(markinfo->mark,0); } static @@ -104,8 +156,13 @@ = { NULL, "MARK", IPTABLES_VERSION, +#ifdef MARK_BITOPS + IPT_ALIGN(sizeof(struct ipt_mark_bitops_target_info)), + IPT_ALIGN(sizeof(struct ipt_mark_bitops_target_info)), +#else IPT_ALIGN(sizeof(struct ipt_mark_target_info)), IPT_ALIGN(sizeof(struct ipt_mark_target_info)), +#endif &help, &init, &parse, --- iptables-1.2.7a-old/iptables.8 2002-08-07 11:37:40.000000000 +0200 +++ iptables-1.2.7a-new/iptables.8 2003-01-15 02:16:57.000000000 +0100 @@ -690,6 +690,23 @@ table. It can for example be used in conjunction with iproute2. .TP .BI "--set-mark " "mark" +Sets the marking of the packet to +.I mark +regardless of the current mark value of the packet. +.P +Since kernel 2.4.21 two additional options to the MARK target have been +made available. The new options are: +.TP +.BI "--and-mark " "mark" +Binary AND between the current mark value of the packet and the supplied +.I mark +value. +.TP +.BI "--or-mark " "mark" +Binary OR between the current mark value of the packet and the supplied +.I mark +value. + .SS REJECT This is used to send back an error packet in response to the matched packet: otherwise it is equivalent to