summaryrefslogtreecommitdiff
path: root/lib/ofp-print.c
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2014-05-07 21:39:00 -0700
committerBen Pfaff <blp@nicira.com>2014-05-14 10:31:41 -0700
commit9b77a3364471bfb72279db08dec700e54c579f86 (patch)
treed0fdd0bb03e4c95bee0cbdbe2560991d2e0c9d21 /lib/ofp-print.c
parente28ac5cf361eabee7a224954b99229b379496a8b (diff)
downloadopenvswitch-9b77a3364471bfb72279db08dec700e54c579f86.tar.gz
ofp-util: Remove ofputil_count_phy_ports().
It's harder to calculate the number of ports in a given amount of space in OpenFlow 1.4 and later, because the ofp_port structure becomes variable length in those versions. This commit removes the one caller, replacing it by a version that doesn't need to know the number of ports in advance. Signed-off-by: Ben Pfaff <blp@nicira.com>
Diffstat (limited to 'lib/ofp-print.c')
-rw-r--r--lib/ofp-print.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/lib/ofp-print.c b/lib/ofp-print.c
index a2e515d2d..909a84688 100644
--- a/lib/ofp-print.c
+++ b/lib/ofp-print.c
@@ -418,28 +418,33 @@ static void
ofp_print_phy_ports(struct ds *string, uint8_t ofp_version,
struct ofpbuf *b)
{
- size_t n_ports;
struct ofputil_phy_port *ports;
- enum ofperr error;
+ size_t allocated_ports, n_ports;
+ int retval;
size_t i;
- n_ports = ofputil_count_phy_ports(ofp_version, b);
+ ports = NULL;
+ allocated_ports = 0;
+ for (n_ports = 0; ; n_ports++) {
+ if (n_ports >= allocated_ports) {
+ ports = x2nrealloc(ports, &allocated_ports, sizeof *ports);
+ }
- ports = xmalloc(n_ports * sizeof *ports);
- for (i = 0; i < n_ports; i++) {
- error = ofputil_pull_phy_port(ofp_version, b, &ports[i]);
- if (error) {
- ofp_print_error(string, error);
- goto exit;
+ retval = ofputil_pull_phy_port(ofp_version, b, &ports[n_ports]);
+ if (retval) {
+ break;
}
}
+
qsort(ports, n_ports, sizeof *ports, compare_ports);
for (i = 0; i < n_ports; i++) {
ofp_print_phy_port(string, &ports[i]);
}
-
-exit:
free(ports);
+
+ if (retval != EOF) {
+ ofp_print_error(string, retval);
+ }
}
static const char *