ds_put_char(string, ',');
}
-/* Pretty-print the ofp_match structure */
-static void ofp_print_match(struct ds *f, const struct ofp_match *om,
- int verbosity)
+static void
+ofp_print_match(struct ds *f, const struct ofp_match *om, int verbosity)
+{
+ char *s = ofp_match_to_string(om, verbosity);
+ ds_put_cstr(f, s);
+ free(s);
+}
+
+char *
+ofp_match_to_string(const struct ofp_match *om, int verbosity)
{
+ struct ds f = DS_EMPTY_INITIALIZER;
uint32_t w = ntohl(om->wildcards);
bool skip_type = false;
bool skip_proto = false;
if (!(w & OFPFW_NW_PROTO)) {
skip_proto = true;
if (om->nw_proto == IP_TYPE_ICMP) {
- ds_put_cstr(f, "icmp,");
+ ds_put_cstr(&f, "icmp,");
} else if (om->nw_proto == IP_TYPE_TCP) {
- ds_put_cstr(f, "tcp,");
+ ds_put_cstr(&f, "tcp,");
} else if (om->nw_proto == IP_TYPE_UDP) {
- ds_put_cstr(f, "udp,");
+ ds_put_cstr(&f, "udp,");
} else {
- ds_put_cstr(f, "ip,");
+ ds_put_cstr(&f, "ip,");
skip_proto = false;
}
} else {
- ds_put_cstr(f, "ip,");
+ ds_put_cstr(&f, "ip,");
}
} else if (om->dl_type == htons(ETH_TYPE_ARP)) {
- ds_put_cstr(f, "arp,");
+ ds_put_cstr(&f, "arp,");
} else {
skip_type = false;
}
}
- print_wild(f, "in_port=", w & OFPFW_IN_PORT, verbosity,
+ print_wild(&f, "in_port=", w & OFPFW_IN_PORT, verbosity,
"%d", ntohs(om->in_port));
- print_wild(f, "dl_vlan=", w & OFPFW_DL_VLAN, verbosity,
+ print_wild(&f, "dl_vlan=", w & OFPFW_DL_VLAN, verbosity,
"0x%04x", ntohs(om->dl_vlan));
- print_wild(f, "dl_src=", w & OFPFW_DL_SRC, verbosity,
+ print_wild(&f, "dl_src=", w & OFPFW_DL_SRC, verbosity,
ETH_ADDR_FMT, ETH_ADDR_ARGS(om->dl_src));
- print_wild(f, "dl_dst=", w & OFPFW_DL_DST, verbosity,
+ print_wild(&f, "dl_dst=", w & OFPFW_DL_DST, verbosity,
ETH_ADDR_FMT, ETH_ADDR_ARGS(om->dl_dst));
if (!skip_type) {
- print_wild(f, "dl_type=", w & OFPFW_DL_TYPE, verbosity,
+ print_wild(&f, "dl_type=", w & OFPFW_DL_TYPE, verbosity,
"0x%04x", ntohs(om->dl_type));
}
- print_ip_netmask(f, "nw_src=", om->nw_src,
+ print_ip_netmask(&f, "nw_src=", om->nw_src,
(w & OFPFW_NW_SRC_MASK) >> OFPFW_NW_SRC_SHIFT, verbosity);
- print_ip_netmask(f, "nw_dst=", om->nw_dst,
+ print_ip_netmask(&f, "nw_dst=", om->nw_dst,
(w & OFPFW_NW_DST_MASK) >> OFPFW_NW_DST_SHIFT, verbosity);
if (!skip_proto) {
- print_wild(f, "nw_proto=", w & OFPFW_NW_PROTO, verbosity,
+ print_wild(&f, "nw_proto=", w & OFPFW_NW_PROTO, verbosity,
"%u", om->nw_proto);
}
if (om->nw_proto == IP_TYPE_ICMP) {
- print_wild(f, "icmp_type=", w & OFPFW_ICMP_TYPE, verbosity,
+ print_wild(&f, "icmp_type=", w & OFPFW_ICMP_TYPE, verbosity,
"%d", ntohs(om->icmp_type));
- print_wild(f, "icmp_code=", w & OFPFW_ICMP_CODE, verbosity,
+ print_wild(&f, "icmp_code=", w & OFPFW_ICMP_CODE, verbosity,
"%d", ntohs(om->icmp_code));
} else {
- print_wild(f, "tp_src=", w & OFPFW_TP_SRC, verbosity,
+ print_wild(&f, "tp_src=", w & OFPFW_TP_SRC, verbosity,
"%d", ntohs(om->tp_src));
- print_wild(f, "tp_dst=", w & OFPFW_TP_DST, verbosity,
+ print_wild(&f, "tp_dst=", w & OFPFW_TP_DST, verbosity,
"%d", ntohs(om->tp_dst));
}
+ return ds_cstr(&f);
}
/* Pretty-print the OFPT_FLOW_MOD packet of 'len' bytes at 'oh' to 'string'