Skip to content

Commit 1b37f09

Browse files
yabetatsuyagrg
authored andcommitted
Bugfix: NetFPGA: Change to efficiently handle NetFPGA-device
1 parent aa9401c commit 1b37f09

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

hw-lib/nf2/hw_flow.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,23 +202,22 @@ nf2_uninstall_flow(struct datapath *dpinst, struct sw_table *flowtab,
202202
struct list deleted;
203203
list_init(&deleted);
204204

205+
dev = nf2_get_net_device();
206+
if (dev == NULL)
207+
return 0;
208+
205209
LIST_FOR_EACH_SAFE (flow, n, struct sw_flow, node, &nf2flowtab->flows) {
206210
if (flow_matches_desc(&flow->key, key, strict)
207211
&& (!strict || flow->priority == priority)
208212
&& flow_has_out_port(flow, out_port)) {
209213
nf2flow = flow->private;
210214

211215
if (nf2flow != NULL) {
212-
dev = nf2_get_net_device();
213-
if (dev == NULL)
214-
return 0;
215216
flow->packet_count
216217
+= nf2_get_packet_count(dev,
217218
nf2flow);
218219
flow->byte_count += nf2_get_byte_count(dev,
219-
nf2flow);
220-
221-
nf2_free_net_device(dev);
220+
nf2flow);
222221
}
223222
count += do_uninstall(flow, &deleted);
224223
if (keep_flow == KEEP_FLOW) {
@@ -229,6 +228,8 @@ nf2_uninstall_flow(struct datapath *dpinst, struct sw_table *flowtab,
229228
}
230229
nf2flowtab->num_flows -= count;
231230

231+
nf2_free_net_device(dev);
232+
232233
if (keep_flow == DELETE_FLOW) {
233234
/* Notify DP of deleted flows and delete the flow */
234235
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,
397398
}
398399

399400
if (nf2_get_port_info(dev, nf2_port, nf2portinfo)) {
401+
nf2_free_net_device(dev);
402+
free(nf2portinfo);
400403
return 1;
401404
}
402405

@@ -416,6 +419,8 @@ nf2_get_portstats(of_hw_driver_t *hw_drv, int of_port,
416419
stats->rx_crc_err = -1;
417420
stats->collisions = -1;
418421

422+
nf2_free_net_device(dev);
423+
free(nf2portinfo);
419424
return 0;
420425
}
421426

hw-lib/nf2/nf2_lib.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,28 @@ static void populate_action_set_vlan_vid(nf2_of_action_wrap *, uint8_t *);
7575
static void populate_action_set_vlan_pcp(nf2_of_action_wrap *, uint8_t *);
7676
static void populate_action_strip_vlan(nf2_of_action_wrap *);
7777

78+
int iface_chk_done = 0;
79+
int net_iface = 0;
80+
7881
struct nf2device *
7982
nf2_get_net_device(void)
8083
{
8184
struct nf2device *dev;
8285
dev = calloc(1, sizeof(struct nf2device));
8386
dev->device_name = DEFAULT_IFACE;
8487

85-
if (check_iface(dev)) {
86-
return NULL;
87-
}
88+
if (iface_chk_done) {
89+
dev->net_iface = net_iface;
90+
} else {
91+
if (check_iface(dev)) {
92+
iface_chk_done = 0;
93+
return NULL;
94+
} else {
95+
iface_chk_done = 1;
96+
net_iface = dev->net_iface;
97+
}
98+
}
99+
88100
if (openDescriptor(dev)) {
89101
return NULL;
90102
}

0 commit comments

Comments
 (0)