Skip to contentSkip to conversation

Cleanup ttl match option parsing

PATCH Applied Phil Oester 2 participants 4 messages Aug 22, 2004 – Aug 23, 2004 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Cleanup ttl match option parsing

The below patch allows the ttl match to be used with other matches without assuming it 'owns' all options. For example, this command currently causes the '...TTL option twice error':

iptables -A foo -d 1.2.3.4 -m ttl --ttl-eq 1 -m state --state NEW -j ACCEPT

But works with the below patch.

This fixes bugzilla #183

Phil

extensions/libipt_ttl.c 2004-08-22 13:07:01.161108504 -0400 renamed from extensions/libipt_ttl.c 2002-05-29 09:08:16.000000000 -0400 +5 -10
diff -ru ipt-orig/extensions/libipt_ttl.c ipt-new/extensions/libipt_ttl.c
@@ -40,10 +40,6 @@
        check_inverse(optarg, &invert, &optind, 0);
        value = atoi(argv[optind-1]);
 
-       if (*flags) 
-               exit_error(PARAMETER_PROBLEM, 
-                               "Can't specify TTL option twice");
-
        if (!optarg)
                exit_error(PARAMETER_PROBLEM,
                                "ttl: You must specify a value");
@@ -56,8 +52,6 @@
 
                        /* is 0 allowed? */
                        info->ttl = value;
-                       *flags = 1;
-
                        break;
                case '3':
                        if (invert) 
@@ -66,8 +60,6 @@
 
                        info->mode = IPT_TTL_LT;
                        info->ttl = value;
-                       *flags = 1;
-
                        break;
                case '4':
                        if (invert)
@@ -76,14 +68,17 @@
 
                        info->mode = IPT_TTL_GT;
                        info->ttl = value;
-                       *flags = 1;
-
                        break;
                default:
                        return 0;
 
        }
 
+       if (*flags) 
+               exit_error(PARAMETER_PROBLEM, 
+                               "Can't specify TTL option twice");
+       *flags = 1;
+
        return 1;
 }
 
#1 lore raw
Quoted 11 lines · Phil Oester

The below patch allows the ttl match to be used with other matches without assuming it 'owns' all options. For example, this command currently causes the '...TTL option twice error':

iptables -A foo -d 1.2.3.4 -m ttl --ttl-eq 1 -m state --state NEW -j ACCEPT

But works with the below patch.

This fixes bugzilla #183

I get rejects with this patch, please send it again as attachment.

Regards
Patrick

Quoted 59 lines

Phil

diff -ru ipt-orig/extensions/libipt_ttl.c ipt-new/extensions/libipt_ttl.c

extensions/libipt_ttl.c 2004-08-22 13:07:01.161108504 -0400 renamed from extensions/libipt_ttl.c 2002-05-29 09:08:16.000000000 -0400 +5 -10
@@ -40,10 +40,6 @@
       check_inverse(optarg, &invert, &optind, 0);
       value = atoi(argv[optind-1]);
 
-       if (*flags) 
-               exit_error(PARAMETER_PROBLEM, 
-                               "Can't specify TTL option twice");
-
       if (!optarg)
               exit_error(PARAMETER_PROBLEM,
                               "ttl: You must specify a value");
@@ -56,8 +52,6 @@
 
                       /* is 0 allowed? */
                       info->ttl = value;
-                       *flags = 1;
-
                       break;
               case '3':
                       if (invert) 
@@ -66,8 +60,6 @@
 
                       info->mode = IPT_TTL_LT;
                       info->ttl = value;
-                       *flags = 1;
-
                       break;
               case '4':
                       if (invert)
@@ -76,14 +68,17 @@
 
                       info->mode = IPT_TTL_GT;
                       info->ttl = value;
-                       *flags = 1;
-
                       break;
               default:
                       return 0;
 
       }
 
+       if (*flags) 
+               exit_error(PARAMETER_PROBLEM, 
+                               "Can't specify TTL option twice");
+       *flags = 1;
+
       return 1;
 }
 
#2 lore raw
Quoted 6 lines · Patrick McHardy
Quoted 4 lines · Phil Oester

The below patch allows the ttl match to be used with other matches without assuming it 'owns' all options. For example, this command currently causes the '...TTL option twice error':

Quoted 8 lines
Quoted 7 lines

iptables -A foo -d 1.2.3.4 -m ttl --ttl-eq 1 -m state --state NEW -j ACCEPT

But works with the below patch.

This fixes bugzilla #183

I get rejects with this patch, please send it again as attachment.

Indeed -- appologies.

Attached

Phil

extensions/libipt_ttl.c +5 -10
diff -ru ipt-orig/extensions/libipt_ttl.c ipt-new/extensions/libipt_ttl.c
@@ -40,10 +40,6 @@
 	check_inverse(optarg, &invert, &optind, 0);
 	value = atoi(argv[optind-1]);
 
-	if (*flags) 
-		exit_error(PARAMETER_PROBLEM, 
-				"Can't specify TTL option twice");
-
 	if (!optarg)
 		exit_error(PARAMETER_PROBLEM,
 				"ttl: You must specify a value");
@@ -56,8 +52,6 @@
 
 			/* is 0 allowed? */
 			info->ttl = value;
-			*flags = 1;
-
 			break;
 		case '3':
 			if (invert) 
@@ -66,8 +60,6 @@
 
 			info->mode = IPT_TTL_LT;
 			info->ttl = value;
-			*flags = 1;
-
 			break;
 		case '4':
 			if (invert)
@@ -76,14 +68,17 @@
 
 			info->mode = IPT_TTL_GT;
 			info->ttl = value;
-			*flags = 1;
-
 			break;
 		default:
 			return 0;
 
 	}
 
+	if (*flags) 
+		exit_error(PARAMETER_PROBLEM, 
+				"Can't specify TTL option twice");
+	*flags = 1;
+
 	return 1;
 }
 
#3 lore raw
Quoted 3 lines · Phil Oester

Attached

Applied, thanks.

Quoted 59 lines

Phil

------------------------------------------------------------------------

diff -ru ipt-orig/extensions/libipt_ttl.c ipt-new/extensions/libipt_ttl.c

extensions/libipt_ttl.c +5 -10
@@ -40,10 +40,6 @@
 	check_inverse(optarg, &invert, &optind, 0);
 	value = atoi(argv[optind-1]);
 
-	if (*flags) 
-		exit_error(PARAMETER_PROBLEM, 
-				"Can't specify TTL option twice");
-
 	if (!optarg)
 		exit_error(PARAMETER_PROBLEM,
 				"ttl: You must specify a value");
@@ -56,8 +52,6 @@
 
 			/* is 0 allowed? */
 			info->ttl = value;
-			*flags = 1;
-
 			break;
 		case '3':
 			if (invert) 
@@ -66,8 +60,6 @@
 
 			info->mode = IPT_TTL_LT;
 			info->ttl = value;
-			*flags = 1;
-
 			break;
 		case '4':
 			if (invert)
@@ -76,14 +68,17 @@
 
 			info->mode = IPT_TTL_GT;
 			info->ttl = value;
-			*flags = 1;
-
 			break;
 		default:
 			return 0;
 
 	}
 
+	if (*flags) 
+		exit_error(PARAMETER_PROBLEM, 
+				"Can't specify TTL option twice");
+	*flags = 1;
+
 	return 1;
 }