diff --git a/hw-lib/nf2/hw_flow.c b/hw-lib/nf2/hw_flow.c index ced0e0f..657e3cd 100644 --- a/hw-lib/nf2/hw_flow.c +++ b/hw-lib/nf2/hw_flow.c @@ -202,6 +202,10 @@ nf2_uninstall_flow(struct datapath *dpinst, struct sw_table *flowtab, struct list deleted; list_init(&deleted); + dev = nf2_get_net_device(); + if (dev == NULL) + return 0; + LIST_FOR_EACH_SAFE (flow, n, struct sw_flow, node, &nf2flowtab->flows) { if (flow_matches_desc(&flow->key, key, strict) && (!strict || flow->priority == priority) @@ -209,16 +213,11 @@ nf2_uninstall_flow(struct datapath *dpinst, struct sw_table *flowtab, nf2flow = flow->private; if (nf2flow != NULL) { - dev = nf2_get_net_device(); - if (dev == NULL) - return 0; flow->packet_count += nf2_get_packet_count(dev, nf2flow); flow->byte_count += nf2_get_byte_count(dev, - nf2flow); - - nf2_free_net_device(dev); + nf2flow); } count += do_uninstall(flow, &deleted); if (keep_flow == KEEP_FLOW) { @@ -229,6 +228,8 @@ nf2_uninstall_flow(struct datapath *dpinst, struct sw_table *flowtab, } nf2flowtab->num_flows -= count; + nf2_free_net_device(dev); + if (keep_flow == DELETE_FLOW) { /* Notify DP of deleted flows and delete the flow */ LIST_FOR_EACH_SAFE (flow, n, struct sw_flow, node, &deleted) { @@ -397,6 +398,8 @@ nf2_get_portstats(of_hw_driver_t *hw_drv, int of_port, } if (nf2_get_port_info(dev, nf2_port, nf2portinfo)) { + nf2_free_net_device(dev); + free(nf2portinfo); return 1; } @@ -416,6 +419,8 @@ nf2_get_portstats(of_hw_driver_t *hw_drv, int of_port, stats->rx_crc_err = -1; stats->collisions = -1; + nf2_free_net_device(dev); + free(nf2portinfo); return 0; } diff --git a/hw-lib/nf2/nf2_lib.c b/hw-lib/nf2/nf2_lib.c index 9d26aa3..4b5c35e 100644 --- a/hw-lib/nf2/nf2_lib.c +++ b/hw-lib/nf2/nf2_lib.c @@ -75,6 +75,9 @@ static void populate_action_set_vlan_vid(nf2_of_action_wrap *, uint8_t *); static void populate_action_set_vlan_pcp(nf2_of_action_wrap *, uint8_t *); static void populate_action_strip_vlan(nf2_of_action_wrap *); +int iface_chk_done = 0; +int net_iface = 0; + struct nf2device * nf2_get_net_device(void) { @@ -82,9 +85,18 @@ nf2_get_net_device(void) dev = calloc(1, sizeof(struct nf2device)); dev->device_name = DEFAULT_IFACE; - if (check_iface(dev)) { - return NULL; - } + if (iface_chk_done) { + dev->net_iface = net_iface; + } else { + if (check_iface(dev)) { + iface_chk_done = 0; + return NULL; + } else { + iface_chk_done = 1; + net_iface = dev->net_iface; + } + } + if (openDescriptor(dev)) { return NULL; }