X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=ofproto%2Fofproto.c;h=8e2ea6b526bf20d1dfc26362beaec27fcd659c32;hb=6033d9d9d7058b1fb83f8235a6eed0572285b97c;hp=98515c298ff99cd58f0802a456fdbb2be16289f9;hpb=8e70e196a26404ab9e2f881cb8c383ef5fc4af29;p=sliver-openvswitch.git diff --git a/ofproto/ofproto.c b/ofproto/ofproto.c index 98515c298..8e2ea6b52 100644 --- a/ofproto/ofproto.c +++ b/ofproto/ofproto.c @@ -1613,38 +1613,30 @@ static uint16_t alloc_ofp_port(struct ofproto *ofproto, const char *netdev_name) { uint16_t ofp_port; + uint16_t end_port_no = ofproto->alloc_port_no; ofp_port = simap_get(&ofproto->ofp_requests, netdev_name); ofp_port = ofp_port ? ofp_port : OFPP_NONE; if (ofp_port >= ofproto->max_ports || bitmap_is_set(ofproto->ofp_port_ids, ofp_port)) { - bool retry = ofproto->alloc_port_no ? true : false; - /* Search for a free OpenFlow port number. We try not to * immediately reuse them to prevent problems due to old * flows. */ - while (ofp_port >= ofproto->max_ports) { - for (ofproto->alloc_port_no++; - ofproto->alloc_port_no < ofproto->max_ports; - ofproto->alloc_port_no++) { - if (!bitmap_is_set(ofproto->ofp_port_ids, - ofproto->alloc_port_no)) { - ofp_port = ofproto->alloc_port_no; - break; - } + for (;;) { + if (++ofproto->alloc_port_no >= ofproto->max_ports) { + ofproto->alloc_port_no = 0; } - if (ofproto->alloc_port_no >= ofproto->max_ports) { - if (retry) { - ofproto->alloc_port_no = 0; - retry = false; - } else { - return OFPP_NONE; - } + if (!bitmap_is_set(ofproto->ofp_port_ids, + ofproto->alloc_port_no)) { + ofp_port = ofproto->alloc_port_no; + break; + } + if (ofproto->alloc_port_no == end_port_no) { + return OFPP_NONE; } } } - bitmap_set1(ofproto->ofp_port_ids, ofp_port); return ofp_port; }