diff mbox series

[ovs-dev,v2,2/3] ovn-util: Optimize is_dynamic_lsp_address.

Message ID 20230302131110.1665580-3-i.maximets@ovn.org
State Accepted
Headers show
Series northd: Optimize parsing of LSP addresses. | expand

Checks

Context Check Description
ovsrobot/apply-robot warning apply and check: warning
ovsrobot/github-robot-_Build_and_Test success github build: passed
ovsrobot/github-robot-_ovn-kubernetes success github build: passed

Commit Message

Ilya Maximets March 2, 2023, 1:11 p.m. UTC
For non-dynamic address, current version performs 1 strcmp + 4 attempts
for ovs_scan.  Updated code performs 1 strncmp + 1 ovs_scan.

Also, for ports with both IPv4 and IPv6 specified, new version doesn't
re-parse IPv4 twice.

Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
---
 lib/ovn-util.c | 40 ++++++++++++++++++++++++++++------------
 1 file changed, 28 insertions(+), 12 deletions(-)

Comments

0-day Robot March 2, 2023, 2:20 p.m. UTC | #1
Bleep bloop.  Greetings Ilya Maximets, I am a robot and I have tried out your patch.
Thanks for your contribution.

I encountered some error that I wasn't expecting.  See the details below.


checkpatch:
WARNING: Comment with 'xxx' marker
#52 FILE: lib/ovn-util.c:123:
            /* Either "dynamic xxxx::xxxx" or "dynamic x.x.x.x xxxx::xxxx". */

Lines checked: 71, Warnings: 1, Errors: 0


Please check this out.  If you feel there has been an error, please email aconole@redhat.com

Thanks,
0-day Robot
Simon Horman March 2, 2023, 2:44 p.m. UTC | #2
On Thu, Mar 02, 2023 at 02:11:09PM +0100, Ilya Maximets wrote:
> For non-dynamic address, current version performs 1 strcmp + 4 attempts
> for ovs_scan.  Updated code performs 1 strncmp + 1 ovs_scan.
> 
> Also, for ports with both IPv4 and IPv6 specified, new version doesn't
> re-parse IPv4 twice.
> 
> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>

Reviewed-by: Simon Horman <simon.horman@corigine.com>
diff mbox series

Patch

diff --git a/lib/ovn-util.c b/lib/ovn-util.c
index 47484ef01..8242dcf89 100644
--- a/lib/ovn-util.c
+++ b/lib/ovn-util.c
@@ -105,18 +105,34 @@  is_dynamic_lsp_address(const char *address)
     char ipv6_s[IPV6_SCAN_LEN + 1];
     struct eth_addr ea;
     ovs_be32 ip;
-    int n;
-    return (!strcmp(address, "dynamic")
-            || (ovs_scan(address, "dynamic "IP_SCAN_FMT"%n",
-                         IP_SCAN_ARGS(&ip), &n)
-                         && address[n] == '\0')
-            || (ovs_scan(address, "dynamic "IP_SCAN_FMT" "IPV6_SCAN_FMT"%n",
-                         IP_SCAN_ARGS(&ip), ipv6_s, &n)
-                         && address[n] == '\0')
-            || (ovs_scan(address, "dynamic "IPV6_SCAN_FMT"%n",
-                         ipv6_s, &n) && address[n] == '\0')
-            || (ovs_scan(address, ETH_ADDR_SCAN_FMT" dynamic%n",
-                         ETH_ADDR_SCAN_ARGS(ea), &n) && address[n] == '\0'));
+    int n = 0;
+
+    if (!strncmp(address, "dynamic", 7)) {
+        n = 7;
+        if (!address[n]) {
+            /* "dynamic" */
+            return true;
+        }
+        if (ovs_scan_len(address, &n, " "IP_SCAN_FMT, IP_SCAN_ARGS(&ip))
+            && !address[n]) {
+            /* "dynamic x.x.x.x" */
+            return true;
+        }
+        if (ovs_scan_len(address, &n, " "IPV6_SCAN_FMT, ipv6_s)
+            && !address[n]) {
+            /* Either "dynamic xxxx::xxxx" or "dynamic x.x.x.x xxxx::xxxx". */
+            return true;
+        }
+        return false;
+    }
+
+    if (ovs_scan_len(address, &n, ETH_ADDR_SCAN_FMT" dynamic",
+                     ETH_ADDR_SCAN_ARGS(ea)) && !address[n]) {
+        /* "xx:xx:xx:xx:xx:xx dynamic" */
+        return true;
+    }
+
+    return false;
 }
 
 static bool