9219d1
From 714a097ba82ad53b90cfff921ea3749cd1130f3e Mon Sep 17 00:00:00 2001
9219d1
From: Dumitru Ceara <dceara@redhat.com>
9219d1
Date: Tue, 23 Jun 2020 10:17:50 +0200
9219d1
Subject: [PATCH] lex: Allow unmasked bits in value/mask tokens.
9219d1
9219d1
It's quite restrictive to not accept ACLs/policies that match on a CIDR
9219d1
that has non-zero host bits. Right now this generates a lexer error that
9219d1
can only be detected in the logs.
9219d1
9219d1
There's no real harm in automatically zero-ing the unmasked bits.
9219d1
9219d1
Reported-at: https://bugzilla.redhat.com/1812820
9219d1
Reported-by: Ying Xu <yinxu@redhat.com>
9219d1
Signed-off-by: Dumitru Ceara <dceara@redhat.com>
9219d1
Acked-by: Mark Michelson <mmichels@redhat.com>
9219d1
Signed-off-by: Numan Siddique <numans@ovn.org>
9219d1
(cherry picked from upstream commit 2104f67aacd62f62a31f4e23a6720aeeaa751154)
9219d1
9219d1
Change-Id: I90c57fe51170d63fcd08d1a57d6d9555755a43be
9219d1
---
9219d1
 lib/lex.c    | 10 ++--------
9219d1
 tests/ovn.at | 11 +++++++----
9219d1
 2 files changed, 9 insertions(+), 12 deletions(-)
9219d1
9219d1
diff --git a/lib/lex.c b/lib/lex.c
9219d1
index 94f6c77..4d92199 100644
9219d1
--- a/lib/lex.c
9219d1
+++ b/lib/lex.c
9219d1
@@ -485,16 +485,10 @@ lex_parse_mask(const char *p, struct lex_token *token)
9219d1
         return p;
9219d1
     }
9219d1
 
9219d1
-    /* Check invariant that a 1-bit in the value corresponds to a 1-bit in the
9219d1
+    /* Apply invariant that a 1-bit in the value corresponds to a 1-bit in the
9219d1
      * mask. */
9219d1
     for (int i = 0; i < ARRAY_SIZE(token->mask.be32); i++) {
9219d1
-        ovs_be32 v = token->value.be32[i];
9219d1
-        ovs_be32 m = token->mask.be32[i];
9219d1
-
9219d1
-        if (v & ~m) {
9219d1
-            lex_error(token, "Value contains unmasked 1-bits.");
9219d1
-            break;
9219d1
-        }
9219d1
+        token->value.be32[i] &= token->mask.be32[i];
9219d1
     }
9219d1
 
9219d1
     /* Done! */
9219d1
diff --git a/tests/ovn.at b/tests/ovn.at
9219d1
index cf521af..e7e0439 100644
9219d1
--- a/tests/ovn.at
9219d1
+++ b/tests/ovn.at
9219d1
@@ -79,7 +79,7 @@ a/b => a error("`/' is only valid as part of `//' or `/*'.") b
9219d1
 
9219d1
 0/0
9219d1
 0/1
9219d1
-1/0 => error("Value contains unmasked 1-bits.")
9219d1
+1/0 => 0/0
9219d1
 1/1
9219d1
 128/384
9219d1
 1/3
9219d1
@@ -99,7 +99,7 @@ a/b => a error("`/' is only valid as part of `//' or `/*'.") b
9219d1
 0X => error("Hex digits expected following 0X.")
9219d1
 0x0/0x0 => 0/0
9219d1
 0x0/0x1 => 0/0x1
9219d1
-0x1/0x0 => error("Value contains unmasked 1-bits.")
9219d1
+0x1/0x0 => 0/0
9219d1
 0xffff/0x1ffff
9219d1
 0x. => error("Invalid syntax in hexadecimal constant.")
9219d1
 
9219d1
@@ -109,9 +109,12 @@ a/b => a error("`/' is only valid as part of `//' or `/*'.") b
9219d1
 192.168.0.0/255.255.0.0 => 192.168.0.0/16
9219d1
 192.168.0.0/255.255.255.0 => 192.168.0.0/24
9219d1
 192.168.0.0/255.255.0.255
9219d1
-192.168.0.0/255.0.0.0 => error("Value contains unmasked 1-bits.")
9219d1
+192.168.0.0/255.0.0.0 => 192.0.0.0/8
9219d1
 192.168.0.0/32
9219d1
 192.168.0.0/255.255.255.255 => 192.168.0.0/32
9219d1
+192.168.0.2/32
9219d1
+192.168.0.2/30 => 192.168.0.0/30
9219d1
+192.168.0.2/24 => 192.168.0.0/24
9219d1
 1.2.3.4:5 => 1.2.3.4 : 5
9219d1
 
9219d1
 ::
9219d1
@@ -135,7 +138,7 @@ FE:DC:ba:98:76:54 => fe:dc:ba:98:76:54
9219d1
 01:00:00:00:00:00/01:00:00:00:00:00
9219d1
 ff:ff:ff:ff:ff:ff/ff:ff:ff:ff:ff:ff
9219d1
 fe:ff:ff:ff:ff:ff/ff:ff:ff:ff:ff:ff
9219d1
-ff:ff:ff:ff:ff:ff/fe:ff:ff:ff:ff:ff => error("Value contains unmasked 1-bits.")
9219d1
+ff:ff:ff:ff:ff:ff/fe:ff:ff:ff:ff:ff => fe:ff:ff:ff:ff:ff/fe:ff:ff:ff:ff:ff
9219d1
 fe:x => error("Invalid numeric constant.")
9219d1
 00:01:02:03:04:x => error("Invalid numeric constant.")
9219d1
 
9219d1
-- 
9219d1
1.8.3.1
9219d1