#include <errno.h>
#include <arpa/inet.h>
#include <inttypes.h>
+#include <net/if.h>
#include <openflow/openflow.h>
#include <openflow/openflow-netlink.h>
#include <signal.h>
\f
/* Public functions. */
+/* The caller must already have called cfg_read(). */
void
bridge_init(void)
{
sprintf(devname, "dp%d", i);
retval = dpif_open(devname, &dpif);
if (!retval) {
- dpif_delete(&dpif);
+ char dpif_name[IF_NAMESIZE];
+ if (dpif_get_name(&dpif, dpif_name, sizeof dpif_name)
+ || !cfg_has("bridge.%s.port", dpif_name)) {
+ dpif_delete(&dpif);
+ }
dpif_close(&dpif);
} else if (retval != ENODEV) {
VLOG_ERR("failed to delete datapath nl:%d: %s",
i, strerror(retval));
}
}
+
+ bridge_reconfigure();
}
static bool
br = xcalloc(1, sizeof *br);
error = dpif_create(name, &br->dpif);
- if (error) {
+ if (error == EEXIST) {
+ error = dpif_open(name, &br->dpif);
+ if (error) {
+ VLOG_ERR("datapath %s already exists but cannot be opened: %s",
+ name, strerror(error));
+ free(br);
+ return NULL;
+ }
+ dpif_flow_flush(&br->dpif);
+ } else if (error) {
VLOG_ERR("failed to create datapath %s: %s", name, strerror(error));
free(br);
return NULL;