[ovs-dev] [PATCH 4/4] ovs: optimize 'ip_parse_port' function.

Guru Shetty guru at ovn.org
Mon Nov 21 17:22:39 UTC 2016


On 21 November 2016 at 08:03, nickcooper-zhangtonghao <nic at opencloud.tech>
wrote:

> Hi Guru Shetty
>
> I folded in the following minor incremental just because ovs_scan_len()
> is only really meant for
> situations where the 'n' offset is being incremented over several calls.
>

Thanks. I intend to add the following incremental before applying.

diff --git a/lib/packets.c b/lib/packets.c
index 1d2d452..ae81f46 100644
--- a/lib/packets.c
+++ b/lib/packets.c
@@ -431,7 +431,10 @@ ip_parse(const char *s, ovs_be32 *ip)

 /* Parses string 's', which must be an IP address with a port number
  * with ":" as a separator (e.g.: 192.168.1.2:80).
- * Stores the IP address into '*ip' and port number to '*port'. */
+ * Stores the IP address into '*ip' and port number to '*port'.
+ *
+ * Returns NULL if successful, otherwise an error message that the caller
must
+ * free(). */
 char * OVS_WARN_UNUSED_RESULT
 ip_parse_port(const char *s, ovs_be32 *ip, ovs_be16 *port)
 {



>
> Thanks.
> Nick
>
> On Nov 19, 2016, at 2:35 AM, Guru Shetty <guru at ovn.org> wrote:
>
> Can you tell why one is better than the other?
>
>
>> ---
>>  lib/packets.c | 11 ++++-------
>>  1 file changed, 4 insertions(+), 7 deletions(-)
>>
>> diff --git a/lib/packets.c b/lib/packets.c
>> index 990c407..1d2d452 100644
>> --- a/lib/packets.c
>> +++ b/lib/packets.c
>> @@ -436,15 +436,12 @@ char * OVS_WARN_UNUSED_RESULT
>>  ip_parse_port(const char *s, ovs_be32 *ip, ovs_be16 *port)
>>  {
>>      int n = 0;
>> -    if (!ovs_scan_len(s, &n, IP_PORT_SCAN_FMT,
>> -                IP_PORT_SCAN_ARGS(ip, port))) {
>> -        return xasprintf("%s: invalid IP address or port number", s);
>> +    if (ovs_scan(s, IP_PORT_SCAN_FMT"%n", IP_PORT_SCAN_ARGS(ip, port),
>> &n)
>> +        && !s[n]) {
>> +        return NULL;
>>      }
>>
>> -    if (s[n]) {
>> -        return xasprintf("%s: invalid IP address or port number", s);
>> -    }
>> -    return NULL;
>> +    return xasprintf("%s: invalid IP address or port number", s);
>>  }
>
>
>


More information about the dev mailing list