Add color output for flow match conditions for ovs-ofctl dump-flows
command utility, by calling ds_put_color() instead of ds_put_format()
in the functions responsible for printing the actions.

This also causes the option to be propagated upward to the other callers
of those functions (partially implemented, to be completed if colors are
to be provided for other commands / tools).

Signed-off-by: Quentin Monnet <quentin.mon...@6wind.com>
---
 lib/dpif-netdev.c       |   2 +-
 lib/flow.c              |   7 +-
 lib/flow.h              |   3 +-
 lib/match.c             | 288 +++++++++++++++++++++++++++++-------------------
 lib/match.h             |   3 +-
 lib/meta-flow.c         |   7 +-
 lib/odp-util.c          |   6 +-
 lib/ofp-print.c         |  16 +--
 ofproto/ofproto-dpif.c  |   2 +-
 ovn/controller/ofctrl.c |   2 +-
 10 files changed, 204 insertions(+), 132 deletions(-)

diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
index 1b9793bbf91f..8d236477b61e 100644
--- a/lib/dpif-netdev.c
+++ b/lib/dpif-netdev.c
@@ -2045,7 +2045,7 @@ dp_netdev_flow_add(struct dp_netdev_pmd_thread *pmd,
         ds_put_cstr(&ds, "flow_add: ");
         odp_format_ufid(ufid, &ds);
         ds_put_cstr(&ds, " ");
-        match_format(&match, &ds, OFP_DEFAULT_PRIORITY);
+        match_format(&match, &ds, OFP_DEFAULT_PRIORITY, 0);
         ds_put_cstr(&ds, ", actions:");
         format_odp_actions(&ds, actions, actions_len);
 
diff --git a/lib/flow.c b/lib/flow.c
index 5668d0c5899e..268832b859da 100644
--- a/lib/flow.c
+++ b/lib/flow.c
@@ -26,6 +26,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include "byte-order.h"
+#include "colors.h"
 #include "coverage.h"
 #include "csum.h"
 #include "dynamic-string.h"
@@ -945,10 +946,12 @@ format_flags(struct ds *ds, const char 
*(*bit_to_string)(uint32_t),
 void
 format_flags_masked(struct ds *ds, const char *name,
                     const char *(*bit_to_string)(uint32_t), uint32_t flags,
-                    uint32_t mask, uint32_t max_mask)
+                    uint32_t mask, uint32_t max_mask, int const color_option)
 {
     if (name) {
+        ds_put_color_start(ds, param_color, color_option);
         ds_put_format(ds, "%s=", name);
+        ds_put_color_end(ds, color_option);
     }
 
     if (mask == max_mask) {
@@ -1181,7 +1184,7 @@ flow_format(struct ds *ds, const struct flow *flow)
         WC_UNMASK_FIELD(wc, metadata);
     }
 
-    match_format(&match, ds, OFP_DEFAULT_PRIORITY);
+    match_format(&match, ds, OFP_DEFAULT_PRIORITY, 0);
 }
 
 void
diff --git a/lib/flow.h b/lib/flow.h
index dc7130d7bbd3..b3ed50f69394 100644
--- a/lib/flow.h
+++ b/lib/flow.h
@@ -204,7 +204,8 @@ void format_flags(struct ds *ds, const char 
*(*bit_to_string)(uint32_t),
                   uint32_t flags, char del);
 void format_flags_masked(struct ds *ds, const char *name,
                          const char *(*bit_to_string)(uint32_t),
-                         uint32_t flags, uint32_t mask, uint32_t max_mask);
+                         uint32_t flags, uint32_t mask, uint32_t max_mask,
+                         int const color_option);
 int parse_flags(const char *s, const char *(*bit_to_string)(uint32_t),
                 char end, const char *field_name, char **res_string,
                 uint32_t *res_flags, uint32_t allowed, uint32_t *res_mask);
diff --git a/lib/match.c b/lib/match.c
index 95d34bc7011f..512258ee0c36 100644
--- a/lib/match.c
+++ b/lib/match.c
@@ -18,6 +18,7 @@
 #include "match.h"
 #include <stdlib.h>
 #include "byte-order.h"
+#include "colors.h"
 #include "dynamic-string.h"
 #include "ofp-util.h"
 #include "packets.h"
@@ -864,11 +865,13 @@ match_init_hidden_fields(struct match *m)
 }
 
 static void
-format_eth_masked(struct ds *s, const char *name,
-                  const struct eth_addr eth, const struct eth_addr mask)
+format_eth_masked(struct ds *s, const char *name, const struct eth_addr eth,
+                  const struct eth_addr mask, int const color_option)
 {
     if (!eth_addr_is_zero(mask)) {
+        ds_put_color_start(s, param_color, color_option);
         ds_put_format(s, "%s=", name);
+        ds_put_color_end(s, color_option);
         eth_format_masked(eth, &mask, s);
         ds_put_char(s, ',');
     }
@@ -876,10 +879,12 @@ format_eth_masked(struct ds *s, const char *name,
 
 static void
 format_ip_netmask(struct ds *s, const char *name, ovs_be32 ip,
-                  ovs_be32 netmask)
+                  ovs_be32 netmask, int const color_option)
 {
     if (netmask) {
+        ds_put_color_start(s, param_color, color_option);
         ds_put_format(s, "%s=", name);
+        ds_put_color_end(s, color_option);
         ip_format_masked(ip, netmask, s);
         ds_put_char(s, ',');
     }
@@ -888,21 +893,25 @@ format_ip_netmask(struct ds *s, const char *name, 
ovs_be32 ip,
 static void
 format_ipv6_netmask(struct ds *s, const char *name,
                     const struct in6_addr *addr,
-                    const struct in6_addr *netmask)
+                    const struct in6_addr *netmask, int const color_option)
 {
     if (!ipv6_mask_is_any(netmask)) {
+        ds_put_color_start(s, param_color, color_option);
         ds_put_format(s, "%s=", name);
+        ds_put_color_end(s, color_option);
         ipv6_format_masked(addr, netmask, s);
         ds_put_char(s, ',');
     }
 }
 
 static void
-format_uint16_masked(struct ds *s, const char *name,
-                   uint16_t value, uint16_t mask)
+format_uint16_masked(struct ds *s, const char *name, uint16_t value,
+                     uint16_t mask, int const color_option)
 {
     if (mask != 0) {
+        ds_put_color_start(s, param_color, color_option);
         ds_put_format(s, "%s=", name);
+        ds_put_color_end(s, color_option);
         if (mask == UINT16_MAX) {
             ds_put_format(s, "%"PRIu16, value);
         } else {
@@ -913,11 +922,13 @@ format_uint16_masked(struct ds *s, const char *name,
 }
 
 static void
-format_be16_masked(struct ds *s, const char *name,
-                   ovs_be16 value, ovs_be16 mask)
+format_be16_masked(struct ds *s, const char *name, ovs_be16 value,
+                   ovs_be16 mask, int const color_option)
 {
     if (mask != htons(0)) {
+        ds_put_color_start(s, param_color, color_option);
         ds_put_format(s, "%s=", name);
+        ds_put_color_end(s, color_option);
         if (mask == OVS_BE16_MAX) {
             ds_put_format(s, "%"PRIu16, ntohs(value));
         } else {
@@ -929,11 +940,13 @@ format_be16_masked(struct ds *s, const char *name,
 }
 
 static void
-format_be32_masked(struct ds *s, const char *name,
-                   ovs_be32 value, ovs_be32 mask)
+format_be32_masked(struct ds *s, const char *name, ovs_be32 value,
+                   ovs_be32 mask, int const color_option)
 {
     if (mask != htonl(0)) {
+        ds_put_color_start(s, param_color, color_option);
         ds_put_format(s, "%s=", name);
+        ds_put_color_end(s, color_option);
         if (mask == OVS_BE32_MAX) {
             ds_put_format(s, "%"PRIu32, ntohl(value));
         } else {
@@ -945,11 +958,14 @@ format_be32_masked(struct ds *s, const char *name,
 }
 
 static void
-format_uint32_masked(struct ds *s, const char *name,
-                   uint32_t value, uint32_t mask)
+format_uint32_masked(struct ds *s, const char *name, uint32_t value,
+                     uint32_t mask, int const color_option)
 {
     if (mask) {
-        ds_put_format(s, "%s=%#"PRIx32, name, value);
+        ds_put_color_start(s, param_color, color_option);
+        ds_put_format(s, "%s=", name);
+        ds_put_color_end(s, color_option);
+        ds_put_format(s, "%#"PRIx32, value);
         if (mask != UINT32_MAX) {
             ds_put_format(s, "/%#"PRIx32, mask);
         }
@@ -958,11 +974,14 @@ format_uint32_masked(struct ds *s, const char *name,
 }
 
 static void
-format_be64_masked(struct ds *s, const char *name,
-                   ovs_be64 value, ovs_be64 mask)
+format_be64_masked(struct ds *s, const char *name, ovs_be64 value,
+                   ovs_be64 mask, int const color_option)
 {
     if (mask != htonll(0)) {
-        ds_put_format(s, "%s=%#"PRIx64, name, ntohll(value));
+        ds_put_color_start(s, param_color, color_option);
+        ds_put_format(s, "%s=", name);
+        ds_put_color_end(s, color_option);
+        ds_put_format(s, "%#"PRIx64, ntohll(value));
         if (mask != OVS_BE64_MAX) {
             ds_put_format(s, "/%#"PRIx64, ntohll(mask));
         }
@@ -971,22 +990,26 @@ format_be64_masked(struct ds *s, const char *name,
 }
 
 static void
-format_flow_tunnel(struct ds *s, const struct match *match)
+format_flow_tunnel(struct ds *s, const struct match *match,
+                   int const color_option)
 {
     const struct flow_wildcards *wc = &match->wc;
     const struct flow_tnl *tnl = &match->flow.tunnel;
 
-    format_be64_masked(s, "tun_id", tnl->tun_id, wc->masks.tunnel.tun_id);
-    format_ip_netmask(s, "tun_src", tnl->ip_src, wc->masks.tunnel.ip_src);
-    format_ip_netmask(s, "tun_dst", tnl->ip_dst, wc->masks.tunnel.ip_dst);
+    format_be64_masked(s, "tun_id", tnl->tun_id, wc->masks.tunnel.tun_id,
+                       color_option);
+    format_ip_netmask(s, "tun_src", tnl->ip_src, wc->masks.tunnel.ip_src,
+                      color_option);
+    format_ip_netmask(s, "tun_dst", tnl->ip_dst, wc->masks.tunnel.ip_dst,
+                      color_option);
     format_ipv6_netmask(s, "tun_ipv6_src", &tnl->ipv6_src,
-                        &wc->masks.tunnel.ipv6_src);
+                        &wc->masks.tunnel.ipv6_src, color_option);
     format_ipv6_netmask(s, "tun_ipv6_dst", &tnl->ipv6_dst,
-                        &wc->masks.tunnel.ipv6_dst);
+                        &wc->masks.tunnel.ipv6_dst, color_option);
 
     if (wc->masks.tunnel.gbp_id) {
         format_be16_masked(s, "tun_gbp_id", tnl->gbp_id,
-                           wc->masks.tunnel.gbp_id);
+                           wc->masks.tunnel.gbp_id, color_option);
     }
 
     if (wc->masks.tunnel.gbp_flags) {
@@ -1003,18 +1026,19 @@ format_flow_tunnel(struct ds *s, const struct match 
*match)
         format_flags_masked(s, "tun_flags", flow_tun_flag_to_string,
                             tnl->flags,
                             wc->masks.tunnel.flags & FLOW_TNL_F_MASK,
-                            FLOW_TNL_F_MASK);
+                            FLOW_TNL_F_MASK, color_option);
         ds_put_char(s, ',');
     }
     tun_metadata_match_format(s, match);
 }
 
 static void
-format_ct_label_masked(struct ds *s, const ovs_u128 *key, const ovs_u128 *mask)
+format_ct_label_masked(struct ds *s, const ovs_u128 *key, const ovs_u128 *mask,
+                       int const color_option)
 {
     if (!ovs_u128_is_zero(mask)) {
         ovs_be128 value = hton128(*key);
-        ds_put_format(s, "ct_label=");
+        ds_put_color(s, "ct_label=", param_color, color_option);
         ds_put_hex(s, &value, sizeof value);
         if (!is_all_ones(mask, sizeof(*mask))) {
             value = hton128(*mask);
@@ -1028,7 +1052,8 @@ format_ct_label_masked(struct ds *s, const ovs_u128 *key, 
const ovs_u128 *mask)
 /* Appends a string representation of 'match' to 's'.  If 'priority' is
  * different from OFP_DEFAULT_PRIORITY, includes it in 's'. */
 void
-match_format(const struct match *match, struct ds *s, int priority)
+match_format(const struct match *match, struct ds *s, int priority,
+             int const color_option)
 {
     const struct flow_wildcards *wc = &match->wc;
     size_t start_len = s->length;
@@ -1041,38 +1066,42 @@ match_format(const struct match *match, struct ds *s, 
int priority)
     BUILD_ASSERT_DECL(FLOW_WC_SEQ == 35);
 
     if (priority != OFP_DEFAULT_PRIORITY) {
-        ds_put_format(s, "priority=%d,", priority);
+        ds_put_color(s, "priority=", special_color, color_option);
+        ds_put_format(s, "%d,", priority);
     }
 
-    format_uint32_masked(s, "pkt_mark", f->pkt_mark, wc->masks.pkt_mark);
+    format_uint32_masked(s, "pkt_mark", f->pkt_mark, wc->masks.pkt_mark,
+                         color_option);
 
     if (wc->masks.recirc_id) {
         format_uint32_masked(s, "recirc_id", f->recirc_id,
-                             wc->masks.recirc_id);
+                             wc->masks.recirc_id, color_option);
     }
 
     if (wc->masks.dp_hash) {
         format_uint32_masked(s, "dp_hash", f->dp_hash,
-                             wc->masks.dp_hash);
+                             wc->masks.dp_hash, color_option);
     }
 
     if (wc->masks.conj_id) {
-        ds_put_format(s, "conj_id=%"PRIu32",", f->conj_id);
+        ds_put_color(s, "conj_id=", param_color, color_option);
+        ds_put_format(s, "%"PRIu32",", f->conj_id);
     }
 
     if (wc->masks.skb_priority) {
-        ds_put_format(s, "skb_priority=%#"PRIx32",", f->skb_priority);
+        ds_put_color(s, "skb_priority=", param_color, color_option);
+        ds_put_format(s, "%#"PRIx32",", f->skb_priority);
     }
 
     if (wc->masks.actset_output) {
-        ds_put_cstr(s, "actset_output=");
+        ds_put_color(s, "actset_output=", param_color, color_option);
         ofputil_format_port(f->actset_output, s);
         ds_put_char(s, ',');
     }
 
     if (wc->masks.ct_state) {
         if (wc->masks.ct_state == UINT16_MAX) {
-            ds_put_cstr(s, "ct_state=");
+            ds_put_color(s, "ct_state=", param_color, color_option);
             if (f->ct_state) {
                 format_flags(s, ct_state_to_string, f->ct_state, '|');
             } else {
@@ -1080,21 +1109,25 @@ match_format(const struct match *match, struct ds *s, 
int priority)
             }
         } else {
             format_flags_masked(s, "ct_state", ct_state_to_string,
-                                f->ct_state, wc->masks.ct_state, UINT16_MAX);
+                                f->ct_state, wc->masks.ct_state, UINT16_MAX,
+                                color_option);
         }
         ds_put_char(s, ',');
     }
 
     if (wc->masks.ct_zone) {
-        format_uint16_masked(s, "ct_zone", f->ct_zone, wc->masks.ct_zone);
+        format_uint16_masked(s, "ct_zone", f->ct_zone, wc->masks.ct_zone,
+                             color_option);
     }
 
     if (wc->masks.ct_mark) {
-        format_uint32_masked(s, "ct_mark", f->ct_mark, wc->masks.ct_mark);
+        format_uint32_masked(s, "ct_mark", f->ct_mark, wc->masks.ct_mark,
+                             color_option);
     }
 
     if (!ovs_u128_is_zero(&wc->masks.ct_label)) {
-        format_ct_label_masked(s, &f->ct_label, &wc->masks.ct_label);
+        format_ct_label_masked(s, &f->ct_label, &wc->masks.ct_label,
+                               color_option);
     }
 
     if (wc->masks.dl_type) {
@@ -1103,48 +1136,48 @@ match_format(const struct match *match, struct ds *s, 
int priority)
             if (wc->masks.nw_proto) {
                 skip_proto = true;
                 if (f->nw_proto == IPPROTO_ICMP) {
-                    ds_put_cstr(s, "icmp,");
+                    ds_put_color(s, "icmp,", value_color, color_option);
                 } else if (f->nw_proto == IPPROTO_IGMP) {
-                    ds_put_cstr(s, "igmp,");
+                    ds_put_color(s, "igmp,", value_color, color_option);
                 } else if (f->nw_proto == IPPROTO_TCP) {
-                    ds_put_cstr(s, "tcp,");
+                    ds_put_color(s, "tcp,", value_color, color_option);
                 } else if (f->nw_proto == IPPROTO_UDP) {
-                    ds_put_cstr(s, "udp,");
+                    ds_put_color(s, "udp,", value_color, color_option);
                 } else if (f->nw_proto == IPPROTO_SCTP) {
-                    ds_put_cstr(s, "sctp,");
+                    ds_put_color(s, "sctp,", value_color, color_option);
                 } else {
-                    ds_put_cstr(s, "ip,");
+                    ds_put_color(s, "ip,", value_color, color_option);
                     skip_proto = false;
                 }
             } else {
-                ds_put_cstr(s, "ip,");
+                ds_put_color(s, "ip,", value_color, color_option);
             }
         } else if (f->dl_type == htons(ETH_TYPE_IPV6)) {
             if (wc->masks.nw_proto) {
                 skip_proto = true;
                 if (f->nw_proto == IPPROTO_ICMPV6) {
-                    ds_put_cstr(s, "icmp6,");
+                    ds_put_color(s, "icmp6,", value_color, color_option);
                 } else if (f->nw_proto == IPPROTO_TCP) {
-                    ds_put_cstr(s, "tcp6,");
+                    ds_put_color(s, "tcp6,", value_color, color_option);
                 } else if (f->nw_proto == IPPROTO_UDP) {
-                    ds_put_cstr(s, "udp6,");
+                    ds_put_color(s, "udp6,", value_color, color_option);
                 } else if (f->nw_proto == IPPROTO_SCTP) {
-                    ds_put_cstr(s, "sctp6,");
+                    ds_put_color(s, "sctp6,", value_color, color_option);
                 } else {
-                    ds_put_cstr(s, "ipv6,");
+                    ds_put_color(s, "ipv6,", value_color, color_option);
                     skip_proto = false;
                 }
             } else {
-                ds_put_cstr(s, "ipv6,");
+                ds_put_color(s, "ipv6,", value_color, color_option);
             }
         } else if (f->dl_type == htons(ETH_TYPE_ARP)) {
-            ds_put_cstr(s, "arp,");
+            ds_put_color(s, "arp,", value_color, color_option);
         } else if (f->dl_type == htons(ETH_TYPE_RARP)) {
-            ds_put_cstr(s, "rarp,");
+            ds_put_color(s, "rarp,", value_color, color_option);
         } else if (f->dl_type == htons(ETH_TYPE_MPLS)) {
-            ds_put_cstr(s, "mpls,");
+            ds_put_color(s, "mpls,", value_color, color_option);
         } else if (f->dl_type == htons(ETH_TYPE_MPLS_MCAST)) {
-            ds_put_cstr(s, "mplsm,");
+            ds_put_color(s, "mplsm,", value_color, color_option);
         } else {
             skip_type = false;
         }
@@ -1155,15 +1188,17 @@ match_format(const struct match *match, struct ds *s, 
int priority)
         if (snprintf(regname, REGNAME_LEN, "reg%d", i) >= REGNAME_LEN) {
             strcpy(regname, "reg?");
         }
-        format_uint32_masked(s, regname, f->regs[i], wc->masks.regs[i]);
+        format_uint32_masked(s, regname, f->regs[i], wc->masks.regs[i],
+                             color_option);
     }
 
-    format_flow_tunnel(s, match);
+    format_flow_tunnel(s, match, color_option);
 
-    format_be64_masked(s, "metadata", f->metadata, wc->masks.metadata);
+    format_be64_masked(s, "metadata", f->metadata, wc->masks.metadata,
+                       color_option);
 
     if (wc->masks.in_port.ofp_port) {
-        ds_put_cstr(s, "in_port=");
+        ds_put_color(s, "in_port=", value_color, color_option);
         ofputil_format_port(f->in_port.ofp_port, s);
         ds_put_char(s, ',');
     }
@@ -1177,32 +1212,37 @@ match_format(const struct match *match, struct ds *s, 
int priority)
             && (!pcp_mask || pcp_mask == htons(VLAN_PCP_MASK))
             && (vid_mask || pcp_mask)) {
             if (vid_mask) {
-                ds_put_format(s, "dl_vlan=%"PRIu16",",
-                              vlan_tci_to_vid(f->vlan_tci));
+                ds_put_color(s, "dl_vlan=", param_color, color_option);
+                ds_put_format(s, "%"PRIu16",", vlan_tci_to_vid(f->vlan_tci));
             }
             if (pcp_mask) {
-                ds_put_format(s, "dl_vlan_pcp=%d,",
-                              vlan_tci_to_pcp(f->vlan_tci));
+                ds_put_color(s, "dl_vlan_pcp=", param_color, color_option);
+                ds_put_format(s, "%d,", vlan_tci_to_pcp(f->vlan_tci));
             }
         } else if (wc->masks.vlan_tci == htons(0xffff)) {
-            ds_put_format(s, "vlan_tci=0x%04"PRIx16",", ntohs(f->vlan_tci));
+            ds_put_color(s, "vlan_tci=", param_color, color_option);
+            ds_put_format(s, "0x%04"PRIx16",", ntohs(f->vlan_tci));
         } else {
-            ds_put_format(s, "vlan_tci=0x%04"PRIx16"/0x%04"PRIx16",",
+            ds_put_color(s, "vlan_tci=", param_color, color_option);
+            ds_put_format(s, "0x%04"PRIx16"/0x%04"PRIx16",",
                           ntohs(f->vlan_tci), ntohs(wc->masks.vlan_tci));
         }
     }
-    format_eth_masked(s, "dl_src", f->dl_src, wc->masks.dl_src);
-    format_eth_masked(s, "dl_dst", f->dl_dst, wc->masks.dl_dst);
+    format_eth_masked(s, "dl_src", f->dl_src, wc->masks.dl_src, color_option);
+    format_eth_masked(s, "dl_dst", f->dl_dst, wc->masks.dl_dst, color_option);
     if (!skip_type && wc->masks.dl_type) {
-        ds_put_format(s, "dl_type=0x%04"PRIx16",", ntohs(f->dl_type));
+        ds_put_color(s, "dl_type=", param_color, color_option);
+        ds_put_format(s, "0x%04"PRIx16",", ntohs(f->dl_type));
     }
     if (f->dl_type == htons(ETH_TYPE_IPV6)) {
-        format_ipv6_netmask(s, "ipv6_src", &f->ipv6_src, &wc->masks.ipv6_src);
-        format_ipv6_netmask(s, "ipv6_dst", &f->ipv6_dst, &wc->masks.ipv6_dst);
+        format_ipv6_netmask(s, "ipv6_src", &f->ipv6_src, &wc->masks.ipv6_src,
+                            color_option);
+        format_ipv6_netmask(s, "ipv6_dst", &f->ipv6_dst, &wc->masks.ipv6_dst,
+                            color_option);
         if (wc->masks.ipv6_label) {
             if (wc->masks.ipv6_label == OVS_BE32_MAX) {
-                ds_put_format(s, "ipv6_label=0x%05"PRIx32",",
-                              ntohl(f->ipv6_label));
+                ds_put_color(s, "ipv6_label=", param_color, color_option);
+                ds_put_format(s, "0x%05"PRIx32",", ntohl(f->ipv6_label));
             } else {
                 ds_put_format(s, "ipv6_label=0x%05"PRIx32"/0x%05"PRIx32",",
                               ntohl(f->ipv6_label),
@@ -1211,95 +1251,121 @@ match_format(const struct match *match, struct ds *s, 
int priority)
         }
     } else if (f->dl_type == htons(ETH_TYPE_ARP) ||
                f->dl_type == htons(ETH_TYPE_RARP)) {
-        format_ip_netmask(s, "arp_spa", f->nw_src, wc->masks.nw_src);
-        format_ip_netmask(s, "arp_tpa", f->nw_dst, wc->masks.nw_dst);
+        format_ip_netmask(s, "arp_spa", f->nw_src, wc->masks.nw_src,
+                          color_option);
+        format_ip_netmask(s, "arp_tpa", f->nw_dst, wc->masks.nw_dst,
+                          color_option);
     } else {
-        format_ip_netmask(s, "nw_src", f->nw_src, wc->masks.nw_src);
-        format_ip_netmask(s, "nw_dst", f->nw_dst, wc->masks.nw_dst);
+        format_ip_netmask(s, "nw_src", f->nw_src, wc->masks.nw_src,
+                          color_option);
+        format_ip_netmask(s, "nw_dst", f->nw_dst, wc->masks.nw_dst,
+                          color_option);
     }
     if (!skip_proto && wc->masks.nw_proto) {
         if (f->dl_type == htons(ETH_TYPE_ARP) ||
             f->dl_type == htons(ETH_TYPE_RARP)) {
-            ds_put_format(s, "arp_op=%"PRIu8",", f->nw_proto);
+            ds_put_color(s, "arp_op=", param_color, color_option);
+            ds_put_format(s, "%"PRIu8",", f->nw_proto);
         } else {
-            ds_put_format(s, "nw_proto=%"PRIu8",", f->nw_proto);
+            ds_put_color(s, "nw_proto=", param_color, color_option);
+            ds_put_format(s, "%"PRIu8",", f->nw_proto);
         }
     }
     if (f->dl_type == htons(ETH_TYPE_ARP) ||
         f->dl_type == htons(ETH_TYPE_RARP)) {
-        format_eth_masked(s, "arp_sha", f->arp_sha, wc->masks.arp_sha);
-        format_eth_masked(s, "arp_tha", f->arp_tha, wc->masks.arp_tha);
+        format_eth_masked(s, "arp_sha", f->arp_sha, wc->masks.arp_sha,
+                          color_option);
+        format_eth_masked(s, "arp_tha", f->arp_tha, wc->masks.arp_tha,
+                          color_option);
     }
     if (wc->masks.nw_tos & IP_DSCP_MASK) {
-        ds_put_format(s, "nw_tos=%"PRIu8",", f->nw_tos & IP_DSCP_MASK);
+        ds_put_color(s, "nw_tos=", param_color, color_option);
+        ds_put_format(s, "%"PRIu8",", f->nw_tos & IP_DSCP_MASK);
     }
     if (wc->masks.nw_tos & IP_ECN_MASK) {
-        ds_put_format(s, "nw_ecn=%"PRIu8",", f->nw_tos & IP_ECN_MASK);
+        ds_put_color(s, "nw_ecn=", param_color, color_option);
+        ds_put_format(s, "%"PRIu8",", f->nw_tos & IP_ECN_MASK);
     }
     if (wc->masks.nw_ttl) {
-        ds_put_format(s, "nw_ttl=%"PRIu8",", f->nw_ttl);
+        ds_put_color(s, "nw_ttl=", param_color, color_option);
+        ds_put_format(s, "%"PRIu8",", f->nw_ttl);
     }
     if (wc->masks.mpls_lse[0] & htonl(MPLS_LABEL_MASK)) {
-        ds_put_format(s, "mpls_label=%"PRIu32",",
-                      mpls_lse_to_label(f->mpls_lse[0]));
+        ds_put_color(s, "mpls_label=", param_color, color_option);
+        ds_put_format(s, "%"PRIu32",", mpls_lse_to_label(f->mpls_lse[0]));
     }
     if (wc->masks.mpls_lse[0] & htonl(MPLS_TC_MASK)) {
-        ds_put_format(s, "mpls_tc=%"PRIu8",",
-                      mpls_lse_to_tc(f->mpls_lse[0]));
+        ds_put_color(s, "mpls_tc=", param_color, color_option);
+        ds_put_format(s, "%"PRIu8",", mpls_lse_to_tc(f->mpls_lse[0]));
     }
     if (wc->masks.mpls_lse[0] & htonl(MPLS_TTL_MASK)) {
-        ds_put_format(s, "mpls_ttl=%"PRIu8",",
-                      mpls_lse_to_ttl(f->mpls_lse[0]));
+        ds_put_color(s, "mpls_ttl=", param_color, color_option);
+        ds_put_format(s, "%"PRIu8",", mpls_lse_to_ttl(f->mpls_lse[0]));
     }
     if (wc->masks.mpls_lse[0] & htonl(MPLS_BOS_MASK)) {
-        ds_put_format(s, "mpls_bos=%"PRIu8",",
-                      mpls_lse_to_bos(f->mpls_lse[0]));
+        ds_put_color(s, "mpls_bos=", param_color, color_option);
+        ds_put_format(s, "%"PRIu8",", mpls_lse_to_bos(f->mpls_lse[0]));
     }
-    format_be32_masked(s, "mpls_lse1", f->mpls_lse[1], wc->masks.mpls_lse[1]);
-    format_be32_masked(s, "mpls_lse2", f->mpls_lse[2], wc->masks.mpls_lse[2]);
+    format_be32_masked(s, "mpls_lse1", f->mpls_lse[1], wc->masks.mpls_lse[1],
+                       color_option);
+    format_be32_masked(s, "mpls_lse2", f->mpls_lse[2], wc->masks.mpls_lse[2],
+                       color_option);
 
     switch (wc->masks.nw_frag) {
     case FLOW_NW_FRAG_ANY | FLOW_NW_FRAG_LATER:
-        ds_put_format(s, "nw_frag=%s,",
+        ds_put_color(s, "nw_frag=", param_color, color_option);
+        ds_put_format(s, "%s,",
                       f->nw_frag & FLOW_NW_FRAG_ANY
                       ? (f->nw_frag & FLOW_NW_FRAG_LATER ? "later" : "first")
                       : (f->nw_frag & FLOW_NW_FRAG_LATER ? "<error>" : "no"));
         break;
 
     case FLOW_NW_FRAG_ANY:
-        ds_put_format(s, "nw_frag=%s,",
+        ds_put_color(s, "nw_frag=", param_color, color_option);
+        ds_put_format(s, "%s,",
                       f->nw_frag & FLOW_NW_FRAG_ANY ? "yes" : "no");
         break;
 
     case FLOW_NW_FRAG_LATER:
-        ds_put_format(s, "nw_frag=%s,",
+        ds_put_color(s, "nw_frag=", param_color, color_option);
+        ds_put_format(s, "%s,",
                       f->nw_frag & FLOW_NW_FRAG_LATER ? "later" : "not_later");
         break;
     }
     if (f->dl_type == htons(ETH_TYPE_IP) &&
         f->nw_proto == IPPROTO_ICMP) {
-        format_be16_masked(s, "icmp_type", f->tp_src, wc->masks.tp_src);
-        format_be16_masked(s, "icmp_code", f->tp_dst, wc->masks.tp_dst);
+        format_be16_masked(s, "icmp_type", f->tp_src, wc->masks.tp_src,
+                           color_option);
+        format_be16_masked(s, "icmp_code", f->tp_dst, wc->masks.tp_dst,
+                           color_option);
     } else if (f->dl_type == htons(ETH_TYPE_IP) &&
                f->nw_proto == IPPROTO_IGMP) {
-        format_be16_masked(s, "igmp_type", f->tp_src, wc->masks.tp_src);
-        format_be16_masked(s, "igmp_code", f->tp_dst, wc->masks.tp_dst);
+        format_be16_masked(s, "igmp_type", f->tp_src, wc->masks.tp_src,
+                           color_option);
+        format_be16_masked(s, "igmp_code", f->tp_dst, wc->masks.tp_dst,
+                           color_option);
     } else if (f->dl_type == htons(ETH_TYPE_IPV6) &&
                f->nw_proto == IPPROTO_ICMPV6) {
-        format_be16_masked(s, "icmp_type", f->tp_src, wc->masks.tp_src);
-        format_be16_masked(s, "icmp_code", f->tp_dst, wc->masks.tp_dst);
+        format_be16_masked(s, "icmp_type", f->tp_src, wc->masks.tp_src,
+                           color_option);
+        format_be16_masked(s, "icmp_code", f->tp_dst, wc->masks.tp_dst,
+                           color_option);
         format_ipv6_netmask(s, "nd_target", &f->nd_target,
-                            &wc->masks.nd_target);
-        format_eth_masked(s, "nd_sll", f->arp_sha, wc->masks.arp_sha);
-        format_eth_masked(s, "nd_tll", f->arp_tha, wc->masks.arp_tha);
+                            &wc->masks.nd_target, color_option);
+        format_eth_masked(s, "nd_sll", f->arp_sha, wc->masks.arp_sha,
+                          color_option);
+        format_eth_masked(s, "nd_tll", f->arp_tha, wc->masks.arp_tha,
+                          color_option);
     } else {
-        format_be16_masked(s, "tp_src", f->tp_src, wc->masks.tp_src);
-        format_be16_masked(s, "tp_dst", f->tp_dst, wc->masks.tp_dst);
+        format_be16_masked(s, "tp_src", f->tp_src, wc->masks.tp_src,
+                           color_option);
+        format_be16_masked(s, "tp_dst", f->tp_dst, wc->masks.tp_dst,
+                           color_option);
     }
     if (is_ip_any(f) && f->nw_proto == IPPROTO_TCP && wc->masks.tcp_flags) {
         format_flags_masked(s, "tcp_flags", packet_tcp_flag_to_string,
                             ntohs(f->tcp_flags), 
TCP_FLAGS(wc->masks.tcp_flags),
-                            TCP_FLAGS(OVS_BE16_MAX));
+                            TCP_FLAGS(OVS_BE16_MAX), color_option);
     }
 
     if (s->length > start_len) {
@@ -1314,7 +1380,7 @@ char *
 match_to_string(const struct match *match, int priority)
 {
     struct ds s = DS_EMPTY_INITIALIZER;
-    match_format(match, &s, priority);
+    match_format(match, &s, priority, 0);
     return ds_steal_cstr(&s);
 }
 
@@ -1419,7 +1485,7 @@ minimatch_format(const struct minimatch *match, struct ds 
*s, int priority)
     struct match megamatch;
 
     minimatch_expand(match, &megamatch);
-    match_format(&megamatch, s, priority);
+    match_format(&megamatch, s, priority, 0);
 }
 
 /* Converts 'match' to a string and returns the string.  If 'priority' is
diff --git a/lib/match.h b/lib/match.h
index 650a203d3c64..d5b78402a09b 100644
--- a/lib/match.h
+++ b/lib/match.h
@@ -165,7 +165,8 @@ uint32_t match_hash(const struct match *, uint32_t basis);
 void match_init_hidden_fields(struct match *);
 bool match_has_default_hidden_fields(const struct match *);
 
-void match_format(const struct match *, struct ds *, int priority);
+void match_format(const struct match *, struct ds *, int priority,
+                  int const color_option);
 char *match_to_string(const struct match *, int priority);
 void match_print(const struct match *);
 
diff --git a/lib/meta-flow.c b/lib/meta-flow.c
index 6bd0b999ad4e..22f83fd457de 100644
--- a/lib/meta-flow.c
+++ b/lib/meta-flow.c
@@ -2352,21 +2352,22 @@ static void
 mf_format_tnl_flags_string(ovs_be16 value, ovs_be16 mask, struct ds *s)
 {
     format_flags_masked(s, NULL, flow_tun_flag_to_string, ntohs(value),
-                        ntohs(mask) & FLOW_TNL_PUB_F_MASK, 
FLOW_TNL_PUB_F_MASK);
+                        ntohs(mask) & FLOW_TNL_PUB_F_MASK, FLOW_TNL_PUB_F_MASK,
+                        0);
 }
 
 static void
 mf_format_tcp_flags_string(ovs_be16 value, ovs_be16 mask, struct ds *s)
 {
     format_flags_masked(s, NULL, packet_tcp_flag_to_string, ntohs(value),
-                        TCP_FLAGS(mask), TCP_FLAGS(OVS_BE16_MAX));
+                        TCP_FLAGS(mask), TCP_FLAGS(OVS_BE16_MAX), 0);
 }
 
 static void
 mf_format_ct_state_string(ovs_be32 value, ovs_be32 mask, struct ds *s)
 {
     format_flags_masked(s, NULL, ct_state_to_string, ntohl(value),
-                        ntohl(mask), UINT16_MAX);
+                        ntohl(mask), UINT16_MAX, 0);
 }
 
 /* Appends to 's' a string representation of field 'mf' whose value is in
diff --git a/lib/odp-util.c b/lib/odp-util.c
index 95e86f20cc90..f54245c4147a 100644
--- a/lib/odp-util.c
+++ b/lib/odp-util.c
@@ -2284,7 +2284,7 @@ format_tun_flags(struct ds *ds, const char *name, 
uint16_t key,
         ds_put_char(ds, '(');
         if (mask) {
             format_flags_masked(ds, NULL, flow_tun_flag_to_string, key,
-                                *mask & FLOW_TNL_F_MASK, FLOW_TNL_F_MASK);
+                                *mask & FLOW_TNL_F_MASK, FLOW_TNL_F_MASK, 0);
         } else { /* Fully masked. */
             format_flags(ds, flow_tun_flag_to_string, key, '|');
         }
@@ -2727,7 +2727,7 @@ format_odp_key_attr(const struct nlattr *a, const struct 
nlattr *ma,
             format_flags_masked(ds, NULL, odp_ct_state_to_string,
                                 nl_attr_get_u32(a),
                                 mask_empty(ma) ? 0 : nl_attr_get_u32(ma),
-                                UINT32_MAX);
+                                UINT32_MAX, 0);
         } else {
             format_flags(ds, odp_ct_state_to_string, nl_attr_get_u32(a), '|');
         }
@@ -2864,7 +2864,7 @@ format_odp_key_attr(const struct nlattr *a, const struct 
nlattr *ma,
             format_flags_masked(ds, NULL, packet_tcp_flag_to_string,
                                 ntohs(nl_attr_get_be16(a)),
                                 TCP_FLAGS(nl_attr_get_be16(ma)),
-                                TCP_FLAGS(OVS_BE16_MAX));
+                                TCP_FLAGS(OVS_BE16_MAX), 0);
         } else {
             format_flags(ds, packet_tcp_flag_to_string,
                          ntohs(nl_attr_get_be16(a)), '|');
diff --git a/lib/ofp-print.c b/lib/ofp-print.c
index a4374e66ca30..5f638193dda0 100644
--- a/lib/ofp-print.c
+++ b/lib/ofp-print.c
@@ -121,7 +121,7 @@ ofp_print_packet_in(struct ds *string, const struct 
ofp_header *oh,
 
     ds_put_format(string, " total_len=%"PRIuSIZE" ", total_len);
 
-    match_format(&pin.flow_metadata, string, OFP_DEFAULT_PRIORITY);
+    match_format(&pin.flow_metadata, string, OFP_DEFAULT_PRIORITY, 0);
 
     ds_put_format(string, " (via %s)",
                   ofputil_packet_in_reason_to_string(pin.reason,
@@ -781,7 +781,7 @@ ofp_print_flow_mod(struct ds *s, const struct ofp_header 
*oh, int verbosity)
         /* nx_match_to_string() doesn't print priority. */
         need_priority = true;
     } else {
-        match_format(&fm.match, s, fm.priority);
+        match_format(&fm.match, s, fm.priority, 0);
 
         /* match_format() does print priority. */
         need_priority = false;
@@ -902,7 +902,7 @@ ofp_print_flow_removed(struct ds *string, const struct 
ofp_header *oh)
     }
 
     ds_put_char(string, ' ');
-    match_format(&fr.match, string, fr.priority);
+    match_format(&fr.match, string, fr.priority, 0);
 
     ds_put_format(string, " reason=%s",
                   ofp_flow_removed_reason_to_string(fr.reason, reasonbuf,
@@ -1503,7 +1503,7 @@ ofp_print_flow_stats_request(struct ds *string, const 
struct ofp_header *oh)
     }
 
     ds_put_char(string, ' ');
-    match_format(&fsr.match, string, OFP_DEFAULT_PRIORITY);
+    match_format(&fsr.match, string, OFP_DEFAULT_PRIORITY, 0);
 }
 
 void
@@ -1517,7 +1517,7 @@ ofp_print_flow_stats(struct ds *string, struct 
ofputil_flow_stats *fs,
     ofp_print_duration(string, fs->duration_sec, fs->duration_nsec);
     ds_put_cstr(string, ", ");
 
-    ds_put_color(string, "table=", param_color, color_option);
+    ds_put_color(string, "table=", special_color, color_option);
     ds_put_format(string, "%"PRIu8", ", fs->table_id);
 
     ds_put_color(string, "n_packets=", param_color, color_option);
@@ -1550,7 +1550,7 @@ ofp_print_flow_stats(struct ds *string, struct 
ofputil_flow_stats *fs,
         ds_put_format(string, "%d, ", fs->hard_age);
     }
 
-    match_format(&fs->match, string, fs->priority);
+    match_format(&fs->match, string, fs->priority, color_option);
     if (string->string[string->length - 1] != ' ') {
         ds_put_char(string, ' ');
     }
@@ -2191,7 +2191,7 @@ ofp_print_nxst_flow_monitor_request(struct ds *string,
         }
 
         ds_put_char(string, ' ');
-        match_format(&request.match, string, OFP_DEFAULT_PRIORITY);
+        match_format(&request.match, string, OFP_DEFAULT_PRIORITY, 0);
         ds_chomp(string, ' ');
     }
 }
@@ -2256,7 +2256,7 @@ ofp_print_nxst_flow_monitor_reply(struct ds *string,
         ds_put_format(string, " cookie=%#"PRIx64, ntohll(update.cookie));
 
         ds_put_char(string, ' ');
-        match_format(update.match, string, OFP_DEFAULT_PRIORITY);
+        match_format(update.match, string, OFP_DEFAULT_PRIORITY, 0);
 
         if (update.ofpacts_len) {
             if (string->string[string->length - 1] != ' ') {
diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c
index adfaeb681356..eb540c38faca 100644
--- a/ofproto/ofproto-dpif.c
+++ b/ofproto/ofproto-dpif.c
@@ -4712,7 +4712,7 @@ trace_format_megaflow(struct ds *result, int level, const 
char *title,
     ds_put_char_multiple(result, '\t', level);
     ds_put_format(result, "%s: ", title);
     match_init(&match, trace->key, &trace->wc);
-    match_format(&match, result, OFP_DEFAULT_PRIORITY);
+    match_format(&match, result, OFP_DEFAULT_PRIORITY, 0);
     ds_put_char(result, '\n');
 }
 
diff --git a/ovn/controller/ofctrl.c b/ovn/controller/ofctrl.c
index e16d84a53d8e..02018be47c03 100644
--- a/ovn/controller/ofctrl.c
+++ b/ovn/controller/ofctrl.c
@@ -534,7 +534,7 @@ ovn_flow_to_string(const struct ovn_flow *f)
     struct ds s = DS_EMPTY_INITIALIZER;
     ds_put_format(&s, "table_id=%"PRIu8", ", f->table_id);
     ds_put_format(&s, "priority=%"PRIu16", ", f->priority);
-    match_format(&f->match, &s, OFP_DEFAULT_PRIORITY);
+    match_format(&f->match, &s, OFP_DEFAULT_PRIORITY, 0);
     ds_put_cstr(&s, ", actions=");
     ofpacts_format(f->ofpacts, f->ofpacts_len, &s);
     return ds_steal_cstr(&s);
-- 
1.9.1

_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to