+ LIST_FOR_EACH (r, struct relay, node, &relays) {
+ relay_wait(r);
+ }
+ if (listen_vconn) {
+ vconn_accept_wait(listen_vconn);
+ }
+ poll_block();
+ }
+
+ return 0;
+}
+
+static void
+new_management_connection(const char *nl_name, struct vconn *new_remote)
+{
+ char *nl_name_without_subscription;
+ struct vconn *new_local;
+ struct rconn *r1, *r2;
+ int retval;
+
+ /* nl:123 or nl:123:1 opens a netlink connection to local datapath 123. We
+ * only accept the former syntax in main().
+ *
+ * nl:123:0 opens a netlink connection to local datapath 123 without
+ * obtaining a subscription for ofp_packet_in or ofp_flow_expired
+ * messages.*/
+ nl_name_without_subscription = xasprintf("%s:0", nl_name);
+ retval = vconn_open(nl_name_without_subscription, &new_local);
+ if (retval) {
+ VLOG_ERR("could not connect to %s (%s)",
+ nl_name_without_subscription, strerror(retval));
+ vconn_close(new_remote);
+ return;
+ }
+ free(nl_name_without_subscription);
+
+ /* Add it to the relay list. */
+ r1 = rconn_new_from_vconn(nl_name_without_subscription, 1, new_local);
+ r2 = rconn_new_from_vconn("passive", 1, new_remote);
+ relay_create(r1, r2);
+}
+
+static void
+relay_create(struct rconn *a, struct rconn *b)
+{
+ struct relay *r;
+ int i;
+
+ r = xmalloc(sizeof *r);
+ for (i = 0; i < 2; i++) {
+ r->halves[i].rconn = i ? b : a;
+ r->halves[i].rxbuf = NULL;
+ }
+ list_push_back(&relays, &r->node);
+}
+
+static void
+relay_run(struct relay *r)
+{
+ int iteration;
+ int i;
+
+ for (i = 0; i < 2; i++) {
+ rconn_run(r->halves[i].rconn);
+ }
+
+ /* Limit the number of iterations to prevent other tasks from starving. */
+ for (iteration = 0; iteration < 50; iteration++) {
+ bool progress = false;