Skip to content

Commit

Permalink
ofproto-dpif: Refactor the get capability code.
Browse files Browse the repository at this point in the history
Make the code simpler by removing the use of
xasprintf and free, and use smap_add_format.

Cc: Ben Pfaff <[email protected]>
Signed-off-by: William Tu <[email protected]>
Acked-by: Ben Pfaff <[email protected]>
  • Loading branch information
williamtu committed Dec 3, 2019
1 parent 3343f8d commit 551c728
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions ofproto/ofproto-dpif.c
Original file line number Diff line number Diff line change
Expand Up @@ -5523,7 +5523,6 @@ ct_del_zone_timeout_policy(const char *datapath_type, uint16_t zone_id)
static void
get_datapath_cap(const char *datapath_type, struct smap *cap)
{
char *str_value;
struct odp_support odp;
struct dpif_backer_support s;
struct dpif_backer *backer = shash_find_data(&all_dpif_backers,
Expand All @@ -5535,14 +5534,9 @@ get_datapath_cap(const char *datapath_type, struct smap *cap)
odp = s.odp;

/* ODP_SUPPORT_FIELDS */
str_value = xasprintf("%"PRIuSIZE, odp.max_vlan_headers);
smap_add(cap, "max_vlan_headers", str_value);
free(str_value);

str_value = xasprintf("%"PRIuSIZE, odp.max_mpls_depth);
smap_add(cap, "max_mpls_depth", str_value);
free(str_value);

smap_add_format(cap, "max_vlan_headers", "%"PRIuSIZE,
odp.max_vlan_headers);
smap_add_format(cap, "max_mpls_depth", "%"PRIuSIZE, odp.max_mpls_depth);
smap_add(cap, "recirc", odp.recirc ? "true" : "false");
smap_add(cap, "ct_state", odp.ct_state ? "true" : "false");
smap_add(cap, "ct_zone", odp.ct_zone ? "true" : "false");
Expand All @@ -5562,11 +5556,7 @@ get_datapath_cap(const char *datapath_type, struct smap *cap)
smap_add(cap, "sample_nesting", s.sample_nesting ? "true" : "false");
smap_add(cap, "ct_eventmask", s.ct_eventmask ? "true" : "false");
smap_add(cap, "ct_clear", s.ct_clear ? "true" : "false");

str_value = xasprintf("%"PRIuSIZE, s.max_hash_alg);
smap_add(cap, "max_hash_alg", str_value);
free(str_value);

smap_add_format(cap, "max_hash_alg", "%"PRIuSIZE, s.max_hash_alg);
smap_add(cap, "check_pkt_len", s.check_pkt_len ? "true" : "false");
smap_add(cap, "ct_timeout", s.ct_timeout ? "true" : "false");
}
Expand Down

0 comments on commit 551c728

Please sign in to comment.