diff mbox series

[ovs-dev] Replace ds_put_* evaluating to constant expressions

Message ID 20200909090248.31114-1-anton.ivanov@cambridgegreys.com
State Changes Requested
Headers show
Series [ovs-dev] Replace ds_put_* evaluating to constant expressions | expand

Commit Message

Anton Ivanov Sept. 9, 2020, 9:02 a.m. UTC
From: Anton Ivanov <anton.ivanov@cambridgegreys.com>

Replaces ds_put_cstr and ds_put_format which evaluate to
constant expressions with string constants

Signed-off-by: Anton Ivanov <anton.ivanov@cambridgegreys.com>
---
 northd/ovn-northd.c | 56 ++++++++++++++++++++++-----------------------
 1 file changed, 28 insertions(+), 28 deletions(-)

Comments

Numan Siddique Sept. 9, 2020, 10:37 a.m. UTC | #1
On Wed, Sep 9, 2020 at 2:33 PM <anton.ivanov@cambridgegreys.com> wrote:
>
> From: Anton Ivanov <anton.ivanov@cambridgegreys.com>
>
> Replaces ds_put_cstr and ds_put_format which evaluate to
> constant expressions with string constants
>
> Signed-off-by: Anton Ivanov <anton.ivanov@cambridgegreys.com>

Acked-by: Numan Siddique <numans@ovn.org>

Thanks
Numan

> ---
>  northd/ovn-northd.c | 56 ++++++++++++++++++++++-----------------------
>  1 file changed, 28 insertions(+), 28 deletions(-)
>
> diff --git a/northd/ovn-northd.c b/northd/ovn-northd.c
> index 3de71612b..c681d5cbf 100644
> --- a/northd/ovn-northd.c
> +++ b/northd/ovn-northd.c
> @@ -1928,6 +1928,8 @@ update_dynamic_addresses(struct dynamic_address_update *update)
>
>      struct ds new_addr = DS_EMPTY_INITIALIZER;
>      ds_put_format(&new_addr, ETH_ADDR_FMT, ETH_ADDR_ARGS(mac));
> +
> +
>      ipam_insert_mac(&mac, true);
>
>      if (ip4) {
> @@ -6950,24 +6952,24 @@ build_lswitch_flows(struct hmap *datapaths, struct hmap *ports,
>          struct ds action = DS_EMPTY_INITIALIZER;
>
>          ds_clear(&match);
> -        ds_put_cstr(&match, "udp.dst == 53");
> +        const char *dns_match = "udp.dst == 53";
>          ds_put_format(&action,
>                        REGBIT_DNS_LOOKUP_RESULT" = dns_lookup(); next;");
>          ovn_lflow_add(lflows, od, S_SWITCH_IN_DNS_LOOKUP, 100,
> -                      ds_cstr(&match), ds_cstr(&action));
> +                      dns_match, ds_cstr(&action));
>          ds_clear(&action);
> -        ds_put_cstr(&match, " && "REGBIT_DNS_LOOKUP_RESULT);
> -        ds_put_format(&action, "eth.dst <-> eth.src; ip4.src <-> ip4.dst; "
> +
> +        const char *dns_match2 = "udp.dst == 53 && "REGBIT_DNS_LOOKUP_RESULT;
> +        const char *dns_action = "eth.dst <-> eth.src; ip4.src <-> ip4.dst; "
>                        "udp.dst = udp.src; udp.src = 53; outport = inport; "
> -                      "flags.loopback = 1; output;");
> +                      "flags.loopback = 1; output;";
>          ovn_lflow_add(lflows, od, S_SWITCH_IN_DNS_RESPONSE, 100,
> -                      ds_cstr(&match), ds_cstr(&action));
> -        ds_clear(&action);
> -        ds_put_format(&action, "eth.dst <-> eth.src; ip6.src <-> ip6.dst; "
> +                      dns_match2, dns_action);
> +        dns_action = "eth.dst <-> eth.src; ip6.src <-> ip6.dst; "
>                        "udp.dst = udp.src; udp.src = 53; outport = inport; "
> -                      "flags.loopback = 1; output;");
> +                      "flags.loopback = 1; output;";
>          ovn_lflow_add(lflows, od, S_SWITCH_IN_DNS_RESPONSE, 100,
> -                      ds_cstr(&match), ds_cstr(&action));
> +                      dns_match2, dns_action);
>          ds_destroy(&action);
>      }
>
> @@ -7839,10 +7841,10 @@ add_ecmp_symmetric_reply_flows(struct hmap *lflows,
>                              &st_route->header_);
>
>      ds_clear(&actions);
> -    ds_put_cstr(&actions, "eth.dst = ct_label.ecmp_reply_eth; next;");
> +    const char *action = "eth.dst = ct_label.ecmp_reply_eth; next;";
>      ovn_lflow_add_with_hint(lflows, od, S_ROUTER_IN_ARP_RESOLVE,
>                              200, ds_cstr(&ecmp_reply),
> -                            ds_cstr(&actions), &st_route->header_);
> +                            action, &st_route->header_);
>  }
>
>  static void
> @@ -8734,9 +8736,9 @@ build_lrouter_flows(struct hmap *datapaths, struct hmap *ports,
>
>          /* TTL discard */
>          ds_clear(&match);
> -        ds_put_cstr(&match, "ip4 && ip.ttl == {0, 1}");
> +        const char *ttl_match = "ip4 && ip.ttl == {0, 1}";
>          ovn_lflow_add(lflows, od, S_ROUTER_IN_IP_INPUT, 30,
> -                      ds_cstr(&match), "drop;");
> +                      ttl_match, "drop;");
>
>          /* Pass other traffic not already handled to the next table for
>           * routing. */
> @@ -8778,14 +8780,13 @@ build_lrouter_flows(struct hmap *datapaths, struct hmap *ports,
>              ds_put_cstr(&match, " && icmp4.type == 8 && icmp4.code == 0");
>
>              ds_clear(&actions);
> -            ds_put_format(&actions,
> -                "ip4.dst <-> ip4.src; "
> -                "ip.ttl = 255; "
> -                "icmp4.type = 0; "
> -                "flags.loopback = 1; "
> -                "next; ");
> +            const char * icmp_actions = "ip4.dst <-> ip4.src; "
> +                                    "ip.ttl = 255; "
> +                                    "icmp4.type = 0; "
> +                                    "flags.loopback = 1; "
> +                                    "next; ";
>              ovn_lflow_add_with_hint(lflows, op->od, S_ROUTER_IN_IP_INPUT, 90,
> -                                    ds_cstr(&match), ds_cstr(&actions),
> +                                    ds_cstr(&match), icmp_actions,
>                                      &op->nbrp->header_);
>          }
>
> @@ -9184,14 +9185,14 @@ build_lrouter_flows(struct hmap *datapaths, struct hmap *ports,
>              ds_put_cstr(&match, " && icmp6.type == 128 && icmp6.code == 0");
>
>              ds_clear(&actions);
> -            ds_put_cstr(&actions,
> +            const char *lrp_actions =
>                          "ip6.dst <-> ip6.src; "
>                          "ip.ttl = 255; "
>                          "icmp6.type = 129; "
>                          "flags.loopback = 1; "
> -                        "next; ");
> +                        "next; ";
>              ovn_lflow_add_with_hint(lflows, op->od, S_ROUTER_IN_IP_INPUT, 90,
> -                                    ds_cstr(&match), ds_cstr(&actions),
> +                                    ds_cstr(&match), lrp_actions,
>                                      &op->nbrp->header_);
>          }
>
> @@ -10449,13 +10450,12 @@ build_lrouter_flows(struct hmap *datapaths, struct hmap *ports,
>                                        REG_NEXT_HOP_IPV4 " == %s",
>                                        peer->json_key, vip);
>
> -                        ds_clear(&actions);
> -                        ds_put_format(&actions,
> -                                      "eth.dst = 00:00:00:00:00:00; next;");
> +                        const char *arp_actions =
> +                                      "eth.dst = 00:00:00:00:00:00; next;";
>                          ovn_lflow_add_with_hint(lflows, peer->od,
>                                                  S_ROUTER_IN_ARP_RESOLVE, 100,
>                                                  ds_cstr(&match),
> -                                                ds_cstr(&actions),
> +                                                arp_actions,
>                                                  &op->nbsp->header_);
>                          break;
>                      }
> --
> 2.20.1
>
> _______________________________________________
> dev mailing list
> dev@openvswitch.org
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev
>
Ilya Maximets Sept. 9, 2020, 11:20 a.m. UTC | #2
On 9/9/20 11:02 AM, anton.ivanov@cambridgegreys.com wrote:
> From: Anton Ivanov <anton.ivanov@cambridgegreys.com>
> 
> Replaces ds_put_cstr and ds_put_format which evaluate to
> constant expressions with string constants
> 
> Signed-off-by: Anton Ivanov <anton.ivanov@cambridgegreys.com>
> ---

Hi.  Thanks for the fix!

One general comment to almost all of your patches:
Please, use the following format for the patch subject:
  <area>: Summary.
i.e. add an <area>: part that should represent a piece of code this patch
is targeted to.  For example, it should be 'ovn-northd:' for this patch.
And it's also better to end the patch subject with a period.  You already
starting the summary with a capital letter, so this  part is fine.

https://docs.ovn.org/en/latest/internals/contributing/submitting-patches.html#email-subject

Some comments for the patch inline.

Best regards, Ilya Maximets.

>  northd/ovn-northd.c | 56 ++++++++++++++++++++++-----------------------
>  1 file changed, 28 insertions(+), 28 deletions(-)
> 
> diff --git a/northd/ovn-northd.c b/northd/ovn-northd.c
> index 3de71612b..c681d5cbf 100644
> --- a/northd/ovn-northd.c
> +++ b/northd/ovn-northd.c
> @@ -1928,6 +1928,8 @@ update_dynamic_addresses(struct dynamic_address_update *update)
>  
>      struct ds new_addr = DS_EMPTY_INITIALIZER;
>      ds_put_format(&new_addr, ETH_ADDR_FMT, ETH_ADDR_ARGS(mac));
> +
> +

This is totally unrelated and not needed.

>      ipam_insert_mac(&mac, true);
>  
>      if (ip4) {
> @@ -6950,24 +6952,24 @@ build_lswitch_flows(struct hmap *datapaths, struct hmap *ports,
>          struct ds action = DS_EMPTY_INITIALIZER;
>  
>          ds_clear(&match);

No need to clear.

> -        ds_put_cstr(&match, "udp.dst == 53");
> +        const char *dns_match = "udp.dst == 53";

It might be better to just pass this string directly  to the ovn_lflow_add.

>          ds_put_format(&action,
>                        REGBIT_DNS_LOOKUP_RESULT" = dns_lookup(); next;");
>          ovn_lflow_add(lflows, od, S_SWITCH_IN_DNS_LOOKUP, 100,
> -                      ds_cstr(&match), ds_cstr(&action));
> +                      dns_match, ds_cstr(&action));
>          ds_clear(&action);
> -        ds_put_cstr(&match, " && "REGBIT_DNS_LOOKUP_RESULT);
> -        ds_put_format(&action, "eth.dst <-> eth.src; ip4.src <-> ip4.dst; "
> +
> +        const char *dns_match2 = "udp.dst == 53 && "REGBIT_DNS_LOOKUP_RESULT;

Please, declare a single variable once for both cases at the top of the block.

> +        const char *dns_action = "eth.dst <-> eth.src; ip4.src <-> ip4.dst; "

And this block is not big, so , please, declare this variable at the top of the
block too.

>                        "udp.dst = udp.src; udp.src = 53; outport = inport; "
> -                      "flags.loopback = 1; output;");
> +                      "flags.loopback = 1; output;";
>          ovn_lflow_add(lflows, od, S_SWITCH_IN_DNS_RESPONSE, 100,
> -                      ds_cstr(&match), ds_cstr(&action));
> -        ds_clear(&action);
> -        ds_put_format(&action, "eth.dst <-> eth.src; ip6.src <-> ip6.dst; "
> +                      dns_match2, dns_action);
> +        dns_action = "eth.dst <-> eth.src; ip6.src <-> ip6.dst; "
>                        "udp.dst = udp.src; udp.src = 53; outport = inport; "
> -                      "flags.loopback = 1; output;");
> +                      "flags.loopback = 1; output;";
>          ovn_lflow_add(lflows, od, S_SWITCH_IN_DNS_RESPONSE, 100,
> -                      ds_cstr(&match), ds_cstr(&action));
> +                      dns_match2, dns_action);
>          ds_destroy(&action);
>      }
>  
> @@ -7839,10 +7841,10 @@ add_ecmp_symmetric_reply_flows(struct hmap *lflows,
>                              &st_route->header_);
>  
>      ds_clear(&actions);

No more need to clear.

> -    ds_put_cstr(&actions, "eth.dst = ct_label.ecmp_reply_eth; next;");
> +    const char *action = "eth.dst = ct_label.ecmp_reply_eth; next;";

It might be better to just pass this string directly  to the function below,
i.e. without any intermediate variables.

>      ovn_lflow_add_with_hint(lflows, od, S_ROUTER_IN_ARP_RESOLVE,
>                              200, ds_cstr(&ecmp_reply),
> -                            ds_cstr(&actions), &st_route->header_);
> +                            action, &st_route->header_);
>  }
>  
>  static void
> @@ -8734,9 +8736,9 @@ build_lrouter_flows(struct hmap *datapaths, struct hmap *ports,
>  
>          /* TTL discard */
>          ds_clear(&match);

No more need to clear.

> -        ds_put_cstr(&match, "ip4 && ip.ttl == {0, 1}");
> +        const char *ttl_match = "ip4 && ip.ttl == {0, 1}";

Ditto.

>          ovn_lflow_add(lflows, od, S_ROUTER_IN_IP_INPUT, 30,
> -                      ds_cstr(&match), "drop;");
> +                      ttl_match, "drop;");
>  
>          /* Pass other traffic not already handled to the next table for
>           * routing. */
> @@ -8778,14 +8780,13 @@ build_lrouter_flows(struct hmap *datapaths, struct hmap *ports,
>              ds_put_cstr(&match, " && icmp4.type == 8 && icmp4.code == 0");
>  
>              ds_clear(&actions);

No more need to clear.

> -            ds_put_format(&actions,
> -                "ip4.dst <-> ip4.src; "
> -                "ip.ttl = 255; "
> -                "icmp4.type = 0; "
> -                "flags.loopback = 1; "
> -                "next; ");
> +            const char * icmp_actions = "ip4.dst <-> ip4.src; "
> +                                    "ip.ttl = 255; "
> +                                    "icmp4.type = 0; "
> +                                    "flags.loopback = 1; "
> +                                    "next; ";

Since you're shifting these lines please align them with the first one,
i.e. 4 more spaces to the right.

BTW, it's kind of inconsistent that you're shifting these lines here and
not shifting in a change below.  It might make sense to not shift at all.

>              ovn_lflow_add_with_hint(lflows, op->od, S_ROUTER_IN_IP_INPUT, 90,
> -                                    ds_cstr(&match), ds_cstr(&actions),
> +                                    ds_cstr(&match), icmp_actions,
>                                      &op->nbrp->header_);
>          }
>  
> @@ -9184,14 +9185,14 @@ build_lrouter_flows(struct hmap *datapaths, struct hmap *ports,
>              ds_put_cstr(&match, " && icmp6.type == 128 && icmp6.code == 0");
>  
>              ds_clear(&actions);

No more need to clear.

> -            ds_put_cstr(&actions,
> +            const char *lrp_actions =
>                          "ip6.dst <-> ip6.src; "
>                          "ip.ttl = 255; "
>                          "icmp6.type = 129; "
>                          "flags.loopback = 1; "
> -                        "next; ");
> +                        "next; ";
>              ovn_lflow_add_with_hint(lflows, op->od, S_ROUTER_IN_IP_INPUT, 90,
> -                                    ds_cstr(&match), ds_cstr(&actions),
> +                                    ds_cstr(&match), lrp_actions,
>                                      &op->nbrp->header_);
>          }
>  
> @@ -10449,13 +10450,12 @@ build_lrouter_flows(struct hmap *datapaths, struct hmap *ports,
>                                        REG_NEXT_HOP_IPV4 " == %s",
>                                        peer->json_key, vip);
>  
> -                        ds_clear(&actions);
> -                        ds_put_format(&actions,
> -                                      "eth.dst = 00:00:00:00:00:00; next;");
> +                        const char *arp_actions =
> +                                      "eth.dst = 00:00:00:00:00:00; next;";
>                          ovn_lflow_add_with_hint(lflows, peer->od,
>                                                  S_ROUTER_IN_ARP_RESOLVE, 100,
>                                                  ds_cstr(&match),
> -                                                ds_cstr(&actions),
> +                                                arp_actions,
>                                                  &op->nbsp->header_);
>                          break;
>                      }
>
Anton Ivanov Sept. 9, 2020, 11:44 a.m. UTC | #3
On 09/09/2020 12:20, Ilya Maximets wrote:
> On 9/9/20 11:02 AM, anton.ivanov@cambridgegreys.com wrote:
>> From: Anton Ivanov <anton.ivanov@cambridgegreys.com>
>>
>> Replaces ds_put_cstr and ds_put_format which evaluate to
>> constant expressions with string constants
>>
>> Signed-off-by: Anton Ivanov <anton.ivanov@cambridgegreys.com>
>> ---
> 
> Hi.  Thanks for the fix!
> 
> One general comment to almost all of your patches:
> Please, use the following format for the patch subject:
>    <area>: Summary.
> i.e. add an <area>: part that should represent a piece of code this patch
> is targeted to.  For example, it should be 'ovn-northd:' for this patch.
> And it's also better to end the patch subject with a period.  You already
> starting the summary with a capital letter, so this  part is fine.
> 
> https://docs.ovn.org/en/latest/internals/contributing/submitting-patches.html#email-subject
> 
> Some comments for the patch inline.

Cool. I will address them in the next revision. I found one more case of 
constant format as well.

> 
> Best regards, Ilya Maximets.
> 
>>   northd/ovn-northd.c | 56 ++++++++++++++++++++++-----------------------
>>   1 file changed, 28 insertions(+), 28 deletions(-)
>>
>> diff --git a/northd/ovn-northd.c b/northd/ovn-northd.c
>> index 3de71612b..c681d5cbf 100644
>> --- a/northd/ovn-northd.c
>> +++ b/northd/ovn-northd.c
>> @@ -1928,6 +1928,8 @@ update_dynamic_addresses(struct dynamic_address_update *update)
>>   
>>       struct ds new_addr = DS_EMPTY_INITIALIZER;
>>       ds_put_format(&new_addr, ETH_ADDR_FMT, ETH_ADDR_ARGS(mac));
>> +
>> +
> 
> This is totally unrelated and not needed.
> 
>>       ipam_insert_mac(&mac, true);
>>   
>>       if (ip4) {
>> @@ -6950,24 +6952,24 @@ build_lswitch_flows(struct hmap *datapaths, struct hmap *ports,
>>           struct ds action = DS_EMPTY_INITIALIZER;
>>   
>>           ds_clear(&match);
> 
> No need to clear.
> 
>> -        ds_put_cstr(&match, "udp.dst == 53");
>> +        const char *dns_match = "udp.dst == 53";
> 
> It might be better to just pass this string directly  to the ovn_lflow_add.
> 
>>           ds_put_format(&action,
>>                         REGBIT_DNS_LOOKUP_RESULT" = dns_lookup(); next;");
>>           ovn_lflow_add(lflows, od, S_SWITCH_IN_DNS_LOOKUP, 100,
>> -                      ds_cstr(&match), ds_cstr(&action));
>> +                      dns_match, ds_cstr(&action));
>>           ds_clear(&action);
>> -        ds_put_cstr(&match, " && "REGBIT_DNS_LOOKUP_RESULT);
>> -        ds_put_format(&action, "eth.dst <-> eth.src; ip4.src <-> ip4.dst; "
>> +
>> +        const char *dns_match2 = "udp.dst == 53 && "REGBIT_DNS_LOOKUP_RESULT;
> 
> Please, declare a single variable once for both cases at the top of the block.
> 
>> +        const char *dns_action = "eth.dst <-> eth.src; ip4.src <-> ip4.dst; "
> 
> And this block is not big, so , please, declare this variable at the top of the
> block too.
> 
>>                         "udp.dst = udp.src; udp.src = 53; outport = inport; "
>> -                      "flags.loopback = 1; output;");
>> +                      "flags.loopback = 1; output;";
>>           ovn_lflow_add(lflows, od, S_SWITCH_IN_DNS_RESPONSE, 100,
>> -                      ds_cstr(&match), ds_cstr(&action));
>> -        ds_clear(&action);
>> -        ds_put_format(&action, "eth.dst <-> eth.src; ip6.src <-> ip6.dst; "
>> +                      dns_match2, dns_action);
>> +        dns_action = "eth.dst <-> eth.src; ip6.src <-> ip6.dst; "
>>                         "udp.dst = udp.src; udp.src = 53; outport = inport; "
>> -                      "flags.loopback = 1; output;");
>> +                      "flags.loopback = 1; output;";
>>           ovn_lflow_add(lflows, od, S_SWITCH_IN_DNS_RESPONSE, 100,
>> -                      ds_cstr(&match), ds_cstr(&action));
>> +                      dns_match2, dns_action);
>>           ds_destroy(&action);
>>       }
>>   
>> @@ -7839,10 +7841,10 @@ add_ecmp_symmetric_reply_flows(struct hmap *lflows,
>>                               &st_route->header_);
>>   
>>       ds_clear(&actions);
> 
> No more need to clear.
> 
>> -    ds_put_cstr(&actions, "eth.dst = ct_label.ecmp_reply_eth; next;");
>> +    const char *action = "eth.dst = ct_label.ecmp_reply_eth; next;";
> 
> It might be better to just pass this string directly  to the function below,
> i.e. without any intermediate variables.
> 
>>       ovn_lflow_add_with_hint(lflows, od, S_ROUTER_IN_ARP_RESOLVE,
>>                               200, ds_cstr(&ecmp_reply),
>> -                            ds_cstr(&actions), &st_route->header_);
>> +                            action, &st_route->header_);
>>   }
>>   
>>   static void
>> @@ -8734,9 +8736,9 @@ build_lrouter_flows(struct hmap *datapaths, struct hmap *ports,
>>   
>>           /* TTL discard */
>>           ds_clear(&match);
> 
> No more need to clear.
> 
>> -        ds_put_cstr(&match, "ip4 && ip.ttl == {0, 1}");
>> +        const char *ttl_match = "ip4 && ip.ttl == {0, 1}";
> 
> Ditto.
> 
>>           ovn_lflow_add(lflows, od, S_ROUTER_IN_IP_INPUT, 30,
>> -                      ds_cstr(&match), "drop;");
>> +                      ttl_match, "drop;");
>>   
>>           /* Pass other traffic not already handled to the next table for
>>            * routing. */
>> @@ -8778,14 +8780,13 @@ build_lrouter_flows(struct hmap *datapaths, struct hmap *ports,
>>               ds_put_cstr(&match, " && icmp4.type == 8 && icmp4.code == 0");
>>   
>>               ds_clear(&actions);
> 
> No more need to clear.
> 
>> -            ds_put_format(&actions,
>> -                "ip4.dst <-> ip4.src; "
>> -                "ip.ttl = 255; "
>> -                "icmp4.type = 0; "
>> -                "flags.loopback = 1; "
>> -                "next; ");
>> +            const char * icmp_actions = "ip4.dst <-> ip4.src; "
>> +                                    "ip.ttl = 255; "
>> +                                    "icmp4.type = 0; "
>> +                                    "flags.loopback = 1; "
>> +                                    "next; ";
> 
> Since you're shifting these lines please align them with the first one,
> i.e. 4 more spaces to the right.
> 
> BTW, it's kind of inconsistent that you're shifting these lines here and
> not shifting in a change below.  It might make sense to not shift at all.
> 
>>               ovn_lflow_add_with_hint(lflows, op->od, S_ROUTER_IN_IP_INPUT, 90,
>> -                                    ds_cstr(&match), ds_cstr(&actions),
>> +                                    ds_cstr(&match), icmp_actions,
>>                                       &op->nbrp->header_);
>>           }
>>   
>> @@ -9184,14 +9185,14 @@ build_lrouter_flows(struct hmap *datapaths, struct hmap *ports,
>>               ds_put_cstr(&match, " && icmp6.type == 128 && icmp6.code == 0");
>>   
>>               ds_clear(&actions);
> 
> No more need to clear.
> 
>> -            ds_put_cstr(&actions,
>> +            const char *lrp_actions =
>>                           "ip6.dst <-> ip6.src; "
>>                           "ip.ttl = 255; "
>>                           "icmp6.type = 129; "
>>                           "flags.loopback = 1; "
>> -                        "next; ");
>> +                        "next; ";
>>               ovn_lflow_add_with_hint(lflows, op->od, S_ROUTER_IN_IP_INPUT, 90,
>> -                                    ds_cstr(&match), ds_cstr(&actions),
>> +                                    ds_cstr(&match), lrp_actions,
>>                                       &op->nbrp->header_);
>>           }
>>   
>> @@ -10449,13 +10450,12 @@ build_lrouter_flows(struct hmap *datapaths, struct hmap *ports,
>>                                         REG_NEXT_HOP_IPV4 " == %s",
>>                                         peer->json_key, vip);
>>   
>> -                        ds_clear(&actions);
>> -                        ds_put_format(&actions,
>> -                                      "eth.dst = 00:00:00:00:00:00; next;");
>> +                        const char *arp_actions =
>> +                                      "eth.dst = 00:00:00:00:00:00; next;";
>>                           ovn_lflow_add_with_hint(lflows, peer->od,
>>                                                   S_ROUTER_IN_ARP_RESOLVE, 100,
>>                                                   ds_cstr(&match),
>> -                                                ds_cstr(&actions),
>> +                                                arp_actions,
>>                                                   &op->nbsp->header_);
>>                           break;
>>                       }
>>
> 
>
Mark Michelson Sept. 10, 2020, 6:21 p.m. UTC | #4
On 9/9/20 6:37 AM, Numan Siddique wrote:
> On Wed, Sep 9, 2020 at 2:33 PM <anton.ivanov@cambridgegreys.com> wrote:
>>
>> From: Anton Ivanov <anton.ivanov@cambridgegreys.com>
>>
>> Replaces ds_put_cstr and ds_put_format which evaluate to
>> constant expressions with string constants
>>
>> Signed-off-by: Anton Ivanov <anton.ivanov@cambridgegreys.com>
> 
> Acked-by: Numan Siddique <numans@ovn.org>
> 
> Thanks
> Numan

I merged this to master.

> 
>> ---
>>   northd/ovn-northd.c | 56 ++++++++++++++++++++++-----------------------
>>   1 file changed, 28 insertions(+), 28 deletions(-)
>>
>> diff --git a/northd/ovn-northd.c b/northd/ovn-northd.c
>> index 3de71612b..c681d5cbf 100644
>> --- a/northd/ovn-northd.c
>> +++ b/northd/ovn-northd.c
>> @@ -1928,6 +1928,8 @@ update_dynamic_addresses(struct dynamic_address_update *update)
>>
>>       struct ds new_addr = DS_EMPTY_INITIALIZER;
>>       ds_put_format(&new_addr, ETH_ADDR_FMT, ETH_ADDR_ARGS(mac));
>> +
>> +
>>       ipam_insert_mac(&mac, true);
>>
>>       if (ip4) {
>> @@ -6950,24 +6952,24 @@ build_lswitch_flows(struct hmap *datapaths, struct hmap *ports,
>>           struct ds action = DS_EMPTY_INITIALIZER;
>>
>>           ds_clear(&match);
>> -        ds_put_cstr(&match, "udp.dst == 53");
>> +        const char *dns_match = "udp.dst == 53";
>>           ds_put_format(&action,
>>                         REGBIT_DNS_LOOKUP_RESULT" = dns_lookup(); next;");
>>           ovn_lflow_add(lflows, od, S_SWITCH_IN_DNS_LOOKUP, 100,
>> -                      ds_cstr(&match), ds_cstr(&action));
>> +                      dns_match, ds_cstr(&action));
>>           ds_clear(&action);
>> -        ds_put_cstr(&match, " && "REGBIT_DNS_LOOKUP_RESULT);
>> -        ds_put_format(&action, "eth.dst <-> eth.src; ip4.src <-> ip4.dst; "
>> +
>> +        const char *dns_match2 = "udp.dst == 53 && "REGBIT_DNS_LOOKUP_RESULT;
>> +        const char *dns_action = "eth.dst <-> eth.src; ip4.src <-> ip4.dst; "
>>                         "udp.dst = udp.src; udp.src = 53; outport = inport; "
>> -                      "flags.loopback = 1; output;");
>> +                      "flags.loopback = 1; output;";
>>           ovn_lflow_add(lflows, od, S_SWITCH_IN_DNS_RESPONSE, 100,
>> -                      ds_cstr(&match), ds_cstr(&action));
>> -        ds_clear(&action);
>> -        ds_put_format(&action, "eth.dst <-> eth.src; ip6.src <-> ip6.dst; "
>> +                      dns_match2, dns_action);
>> +        dns_action = "eth.dst <-> eth.src; ip6.src <-> ip6.dst; "
>>                         "udp.dst = udp.src; udp.src = 53; outport = inport; "
>> -                      "flags.loopback = 1; output;");
>> +                      "flags.loopback = 1; output;";
>>           ovn_lflow_add(lflows, od, S_SWITCH_IN_DNS_RESPONSE, 100,
>> -                      ds_cstr(&match), ds_cstr(&action));
>> +                      dns_match2, dns_action);
>>           ds_destroy(&action);
>>       }
>>
>> @@ -7839,10 +7841,10 @@ add_ecmp_symmetric_reply_flows(struct hmap *lflows,
>>                               &st_route->header_);
>>
>>       ds_clear(&actions);
>> -    ds_put_cstr(&actions, "eth.dst = ct_label.ecmp_reply_eth; next;");
>> +    const char *action = "eth.dst = ct_label.ecmp_reply_eth; next;";
>>       ovn_lflow_add_with_hint(lflows, od, S_ROUTER_IN_ARP_RESOLVE,
>>                               200, ds_cstr(&ecmp_reply),
>> -                            ds_cstr(&actions), &st_route->header_);
>> +                            action, &st_route->header_);
>>   }
>>
>>   static void
>> @@ -8734,9 +8736,9 @@ build_lrouter_flows(struct hmap *datapaths, struct hmap *ports,
>>
>>           /* TTL discard */
>>           ds_clear(&match);
>> -        ds_put_cstr(&match, "ip4 && ip.ttl == {0, 1}");
>> +        const char *ttl_match = "ip4 && ip.ttl == {0, 1}";
>>           ovn_lflow_add(lflows, od, S_ROUTER_IN_IP_INPUT, 30,
>> -                      ds_cstr(&match), "drop;");
>> +                      ttl_match, "drop;");
>>
>>           /* Pass other traffic not already handled to the next table for
>>            * routing. */
>> @@ -8778,14 +8780,13 @@ build_lrouter_flows(struct hmap *datapaths, struct hmap *ports,
>>               ds_put_cstr(&match, " && icmp4.type == 8 && icmp4.code == 0");
>>
>>               ds_clear(&actions);
>> -            ds_put_format(&actions,
>> -                "ip4.dst <-> ip4.src; "
>> -                "ip.ttl = 255; "
>> -                "icmp4.type = 0; "
>> -                "flags.loopback = 1; "
>> -                "next; ");
>> +            const char * icmp_actions = "ip4.dst <-> ip4.src; "
>> +                                    "ip.ttl = 255; "
>> +                                    "icmp4.type = 0; "
>> +                                    "flags.loopback = 1; "
>> +                                    "next; ";
>>               ovn_lflow_add_with_hint(lflows, op->od, S_ROUTER_IN_IP_INPUT, 90,
>> -                                    ds_cstr(&match), ds_cstr(&actions),
>> +                                    ds_cstr(&match), icmp_actions,
>>                                       &op->nbrp->header_);
>>           }
>>
>> @@ -9184,14 +9185,14 @@ build_lrouter_flows(struct hmap *datapaths, struct hmap *ports,
>>               ds_put_cstr(&match, " && icmp6.type == 128 && icmp6.code == 0");
>>
>>               ds_clear(&actions);
>> -            ds_put_cstr(&actions,
>> +            const char *lrp_actions =
>>                           "ip6.dst <-> ip6.src; "
>>                           "ip.ttl = 255; "
>>                           "icmp6.type = 129; "
>>                           "flags.loopback = 1; "
>> -                        "next; ");
>> +                        "next; ";
>>               ovn_lflow_add_with_hint(lflows, op->od, S_ROUTER_IN_IP_INPUT, 90,
>> -                                    ds_cstr(&match), ds_cstr(&actions),
>> +                                    ds_cstr(&match), lrp_actions,
>>                                       &op->nbrp->header_);
>>           }
>>
>> @@ -10449,13 +10450,12 @@ build_lrouter_flows(struct hmap *datapaths, struct hmap *ports,
>>                                         REG_NEXT_HOP_IPV4 " == %s",
>>                                         peer->json_key, vip);
>>
>> -                        ds_clear(&actions);
>> -                        ds_put_format(&actions,
>> -                                      "eth.dst = 00:00:00:00:00:00; next;");
>> +                        const char *arp_actions =
>> +                                      "eth.dst = 00:00:00:00:00:00; next;";
>>                           ovn_lflow_add_with_hint(lflows, peer->od,
>>                                                   S_ROUTER_IN_ARP_RESOLVE, 100,
>>                                                   ds_cstr(&match),
>> -                                                ds_cstr(&actions),
>> +                                                arp_actions,
>>                                                   &op->nbsp->header_);
>>                           break;
>>                       }
>> --
>> 2.20.1
>>
>> _______________________________________________
>> dev mailing list
>> dev@openvswitch.org
>> https://mail.openvswitch.org/mailman/listinfo/ovs-dev
>>
> _______________________________________________
> dev mailing list
> dev@openvswitch.org
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev
>
Ilya Maximets Sept. 10, 2020, 6:23 p.m. UTC | #5
On 9/10/20 8:21 PM, Mark Michelson wrote:
> On 9/9/20 6:37 AM, Numan Siddique wrote:
>> On Wed, Sep 9, 2020 at 2:33 PM <anton.ivanov@cambridgegreys.com> wrote:
>>>
>>> From: Anton Ivanov <anton.ivanov@cambridgegreys.com>
>>>
>>> Replaces ds_put_cstr and ds_put_format which evaluate to
>>> constant expressions with string constants
>>>
>>> Signed-off-by: Anton Ivanov <anton.ivanov@cambridgegreys.com>
>>
>> Acked-by: Numan Siddique <numans@ovn.org>
>>
>> Thanks
>> Numan
> 
> I merged this to master.

This or v2?
Mark Michelson Sept. 10, 2020, 6:48 p.m. UTC | #6
On 9/10/20 2:23 PM, Ilya Maximets wrote:
> On 9/10/20 8:21 PM, Mark Michelson wrote:
>> On 9/9/20 6:37 AM, Numan Siddique wrote:
>>> On Wed, Sep 9, 2020 at 2:33 PM <anton.ivanov@cambridgegreys.com> wrote:
>>>>
>>>> From: Anton Ivanov <anton.ivanov@cambridgegreys.com>
>>>>
>>>> Replaces ds_put_cstr and ds_put_format which evaluate to
>>>> constant expressions with string constants
>>>>
>>>> Signed-off-by: Anton Ivanov <anton.ivanov@cambridgegreys.com>
>>>
>>> Acked-by: Numan Siddique <numans@ovn.org>
>>>
>>> Thanks
>>> Numan
>>
>> I merged this to master.
> 
> This or v2?
> 

Sorry, I merged v2 but responded on the wrong thread.
diff mbox series

Patch

diff --git a/northd/ovn-northd.c b/northd/ovn-northd.c
index 3de71612b..c681d5cbf 100644
--- a/northd/ovn-northd.c
+++ b/northd/ovn-northd.c
@@ -1928,6 +1928,8 @@  update_dynamic_addresses(struct dynamic_address_update *update)
 
     struct ds new_addr = DS_EMPTY_INITIALIZER;
     ds_put_format(&new_addr, ETH_ADDR_FMT, ETH_ADDR_ARGS(mac));
+
+
     ipam_insert_mac(&mac, true);
 
     if (ip4) {
@@ -6950,24 +6952,24 @@  build_lswitch_flows(struct hmap *datapaths, struct hmap *ports,
         struct ds action = DS_EMPTY_INITIALIZER;
 
         ds_clear(&match);
-        ds_put_cstr(&match, "udp.dst == 53");
+        const char *dns_match = "udp.dst == 53";
         ds_put_format(&action,
                       REGBIT_DNS_LOOKUP_RESULT" = dns_lookup(); next;");
         ovn_lflow_add(lflows, od, S_SWITCH_IN_DNS_LOOKUP, 100,
-                      ds_cstr(&match), ds_cstr(&action));
+                      dns_match, ds_cstr(&action));
         ds_clear(&action);
-        ds_put_cstr(&match, " && "REGBIT_DNS_LOOKUP_RESULT);
-        ds_put_format(&action, "eth.dst <-> eth.src; ip4.src <-> ip4.dst; "
+
+        const char *dns_match2 = "udp.dst == 53 && "REGBIT_DNS_LOOKUP_RESULT;
+        const char *dns_action = "eth.dst <-> eth.src; ip4.src <-> ip4.dst; "
                       "udp.dst = udp.src; udp.src = 53; outport = inport; "
-                      "flags.loopback = 1; output;");
+                      "flags.loopback = 1; output;";
         ovn_lflow_add(lflows, od, S_SWITCH_IN_DNS_RESPONSE, 100,
-                      ds_cstr(&match), ds_cstr(&action));
-        ds_clear(&action);
-        ds_put_format(&action, "eth.dst <-> eth.src; ip6.src <-> ip6.dst; "
+                      dns_match2, dns_action);
+        dns_action = "eth.dst <-> eth.src; ip6.src <-> ip6.dst; "
                       "udp.dst = udp.src; udp.src = 53; outport = inport; "
-                      "flags.loopback = 1; output;");
+                      "flags.loopback = 1; output;";
         ovn_lflow_add(lflows, od, S_SWITCH_IN_DNS_RESPONSE, 100,
-                      ds_cstr(&match), ds_cstr(&action));
+                      dns_match2, dns_action);
         ds_destroy(&action);
     }
 
@@ -7839,10 +7841,10 @@  add_ecmp_symmetric_reply_flows(struct hmap *lflows,
                             &st_route->header_);
 
     ds_clear(&actions);
-    ds_put_cstr(&actions, "eth.dst = ct_label.ecmp_reply_eth; next;");
+    const char *action = "eth.dst = ct_label.ecmp_reply_eth; next;";
     ovn_lflow_add_with_hint(lflows, od, S_ROUTER_IN_ARP_RESOLVE,
                             200, ds_cstr(&ecmp_reply),
-                            ds_cstr(&actions), &st_route->header_);
+                            action, &st_route->header_);
 }
 
 static void
@@ -8734,9 +8736,9 @@  build_lrouter_flows(struct hmap *datapaths, struct hmap *ports,
 
         /* TTL discard */
         ds_clear(&match);
-        ds_put_cstr(&match, "ip4 && ip.ttl == {0, 1}");
+        const char *ttl_match = "ip4 && ip.ttl == {0, 1}";
         ovn_lflow_add(lflows, od, S_ROUTER_IN_IP_INPUT, 30,
-                      ds_cstr(&match), "drop;");
+                      ttl_match, "drop;");
 
         /* Pass other traffic not already handled to the next table for
          * routing. */
@@ -8778,14 +8780,13 @@  build_lrouter_flows(struct hmap *datapaths, struct hmap *ports,
             ds_put_cstr(&match, " && icmp4.type == 8 && icmp4.code == 0");
 
             ds_clear(&actions);
-            ds_put_format(&actions,
-                "ip4.dst <-> ip4.src; "
-                "ip.ttl = 255; "
-                "icmp4.type = 0; "
-                "flags.loopback = 1; "
-                "next; ");
+            const char * icmp_actions = "ip4.dst <-> ip4.src; "
+                                    "ip.ttl = 255; "
+                                    "icmp4.type = 0; "
+                                    "flags.loopback = 1; "
+                                    "next; ";
             ovn_lflow_add_with_hint(lflows, op->od, S_ROUTER_IN_IP_INPUT, 90,
-                                    ds_cstr(&match), ds_cstr(&actions),
+                                    ds_cstr(&match), icmp_actions,
                                     &op->nbrp->header_);
         }
 
@@ -9184,14 +9185,14 @@  build_lrouter_flows(struct hmap *datapaths, struct hmap *ports,
             ds_put_cstr(&match, " && icmp6.type == 128 && icmp6.code == 0");
 
             ds_clear(&actions);
-            ds_put_cstr(&actions,
+            const char *lrp_actions =
                         "ip6.dst <-> ip6.src; "
                         "ip.ttl = 255; "
                         "icmp6.type = 129; "
                         "flags.loopback = 1; "
-                        "next; ");
+                        "next; ";
             ovn_lflow_add_with_hint(lflows, op->od, S_ROUTER_IN_IP_INPUT, 90,
-                                    ds_cstr(&match), ds_cstr(&actions),
+                                    ds_cstr(&match), lrp_actions,
                                     &op->nbrp->header_);
         }
 
@@ -10449,13 +10450,12 @@  build_lrouter_flows(struct hmap *datapaths, struct hmap *ports,
                                       REG_NEXT_HOP_IPV4 " == %s",
                                       peer->json_key, vip);
 
-                        ds_clear(&actions);
-                        ds_put_format(&actions,
-                                      "eth.dst = 00:00:00:00:00:00; next;");
+                        const char *arp_actions =
+                                      "eth.dst = 00:00:00:00:00:00; next;";
                         ovn_lflow_add_with_hint(lflows, peer->od,
                                                 S_ROUTER_IN_ARP_RESOLVE, 100,
                                                 ds_cstr(&match),
-                                                ds_cstr(&actions),
+                                                arp_actions,
                                                 &op->nbsp->header_);
                         break;
                     }