+ retval = do_recv(vconn, &b);
+ if (!retval) {
+ struct ofp_header *oh = b->data;
+
+ if (oh->type == OFPT_HELLO) {
+ if (b->size > sizeof *oh) {
+ struct ds msg = DS_EMPTY_INITIALIZER;
+ ds_put_format(&msg, "%s: extra-long hello:\n", vconn->name);
+ ds_put_hex_dump(&msg, b->data, b->size, 0, true);
+ VLOG_WARN_RL(&rl, ds_cstr(&msg));
+ ds_destroy(&msg);
+ }
+
+ vconn->version = MIN(OFP_VERSION, oh->version);
+ if (vconn->version < vconn->min_version) {
+ VLOG_WARN_RL(&rl, "%s: version negotiation failed: we support "
+ "versions 0x%02x to 0x%02x inclusive but peer "
+ "supports no later than version 0x%02"PRIx8,
+ vconn->name, vconn->min_version, OFP_VERSION,
+ oh->version);
+ vconn->state = VCS_SEND_ERROR;
+ } else {
+ VLOG_DBG("%s: negotiated OpenFlow version 0x%02x "
+ "(we support versions 0x%02x to 0x%02x inclusive, "
+ "peer no later than version 0x%02"PRIx8")",
+ vconn->name, vconn->version, vconn->min_version,
+ OFP_VERSION, oh->version);
+ vconn->state = VCS_CONNECTED;
+ }
+ ofpbuf_delete(b);
+ return;
+ } else {
+ char *s = ofp_to_string(b->data, b->size, 1);
+ VLOG_WARN_RL(&rl, "%s: received message while expecting hello: %s",
+ vconn->name, s);
+ free(s);
+ retval = EPROTO;
+ ofpbuf_delete(b);
+ }
+ }
+
+ if (retval != EAGAIN) {
+ vconn->state = VCS_DISCONNECTED;
+ vconn->error = retval;
+ }
+}
+
+static void
+vcs_send_error(struct vconn *vconn)
+{
+ struct ofp_error_msg *error;
+ struct ofpbuf *b;
+ char s[128];
+ int retval;
+
+ snprintf(s, sizeof s, "We support versions 0x%02x to 0x%02x inclusive but "
+ "you support no later than version 0x%02"PRIx8".",
+ vconn->min_version, OFP_VERSION, vconn->version);
+ error = make_openflow(sizeof *error, OFPT_ERROR, &b);
+ error->type = htons(OFPET_HELLO_FAILED);
+ error->code = htons(OFPHFC_INCOMPATIBLE);
+ ofpbuf_put(b, s, strlen(s));
+ retval = do_send(vconn, b);