2 * Copyright (c) 2008, 2009, 2010, 2011, 2012 Nicira, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "vconn-provider.h"
22 #include <netinet/in.h>
27 #include "dynamic-string.h"
28 #include "fatal-signal.h"
30 #include "ofp-errors.h"
32 #include "ofp-print.h"
35 #include "openflow/nicira-ext.h"
36 #include "openflow/openflow.h"
38 #include "poll-loop.h"
42 #include "socket-util.h"
44 VLOG_DEFINE_THIS_MODULE(vconn);
46 COVERAGE_DEFINE(vconn_open);
47 COVERAGE_DEFINE(vconn_received);
48 COVERAGE_DEFINE(vconn_sent);
50 /* State of an active vconn.*/
52 /* This is the ordinary progression of states. */
53 VCS_CONNECTING, /* Underlying vconn is not connected. */
54 VCS_SEND_HELLO, /* Waiting to send OFPT_HELLO message. */
55 VCS_RECV_HELLO, /* Waiting to receive OFPT_HELLO message. */
56 VCS_CONNECTED, /* Connection established. */
58 /* These states are entered only when something goes wrong. */
59 VCS_SEND_ERROR, /* Sending OFPT_ERROR message. */
60 VCS_DISCONNECTED /* Connection failed or connection closed. */
63 static struct vconn_class *vconn_classes[] = {
71 static struct pvconn_class *pvconn_classes[] = {
79 /* Rate limit for individual OpenFlow messages going over the vconn, output at
80 * DBG level. This is very high because, if these are enabled, it is because
81 * we really need to see them. */
82 static struct vlog_rate_limit ofmsg_rl = VLOG_RATE_LIMIT_INIT(600, 600);
84 /* Rate limit for OpenFlow message parse errors. These always indicate a bug
85 * in the peer and so there's not much point in showing a lot of them. */
86 static struct vlog_rate_limit bad_ofmsg_rl = VLOG_RATE_LIMIT_INIT(1, 5);
88 static int do_recv(struct vconn *, struct ofpbuf **);
89 static int do_send(struct vconn *, struct ofpbuf *);
91 /* Check the validity of the vconn class structures. */
93 check_vconn_classes(void)
98 for (i = 0; i < ARRAY_SIZE(vconn_classes); i++) {
99 struct vconn_class *class = vconn_classes[i];
100 assert(class->name != NULL);
101 assert(class->open != NULL);
102 if (class->close || class->recv || class->send
103 || class->run || class->run_wait || class->wait) {
104 assert(class->close != NULL);
105 assert(class->recv != NULL);
106 assert(class->send != NULL);
107 assert(class->wait != NULL);
109 /* This class delegates to another one. */
113 for (i = 0; i < ARRAY_SIZE(pvconn_classes); i++) {
114 struct pvconn_class *class = pvconn_classes[i];
115 assert(class->name != NULL);
116 assert(class->listen != NULL);
117 if (class->close || class->accept || class->wait) {
118 assert(class->close != NULL);
119 assert(class->accept != NULL);
120 assert(class->wait != NULL);
122 /* This class delegates to another one. */
128 /* Prints information on active (if 'active') and passive (if 'passive')
129 * connection methods supported by the vconn. If 'bootstrap' is true, also
130 * advertises options to bootstrap the CA certificate. */
132 vconn_usage(bool active, bool passive, bool bootstrap OVS_UNUSED)
134 /* Really this should be implemented via callbacks into the vconn
135 * providers, but that seems too heavy-weight to bother with at the
140 printf("Active OpenFlow connection methods:\n");
141 printf(" tcp:IP[:PORT] "
142 "PORT (default: %d) at remote IP\n", OFP_TCP_PORT);
144 printf(" ssl:IP[:PORT] "
145 "SSL PORT (default: %d) at remote IP\n", OFP_SSL_PORT);
147 printf(" unix:FILE Unix domain socket named FILE\n");
151 printf("Passive OpenFlow connection methods:\n");
152 printf(" ptcp:[PORT][:IP] "
153 "listen to TCP PORT (default: %d) on IP\n",
156 printf(" pssl:[PORT][:IP] "
157 "listen for SSL on PORT (default: %d) on IP\n",
160 printf(" punix:FILE "
161 "listen on Unix domain socket FILE\n");
165 printf("PKI configuration (required to use SSL):\n"
166 " -p, --private-key=FILE file with private key\n"
167 " -c, --certificate=FILE file with certificate for private key\n"
168 " -C, --ca-cert=FILE file with peer CA certificate\n");
170 printf(" --bootstrap-ca-cert=FILE file with peer CA certificate "
171 "to read or create\n");
176 /* Given 'name', a connection name in the form "TYPE:ARGS", stores the class
177 * named "TYPE" into '*classp' and returns 0. Returns EAFNOSUPPORT and stores
178 * a null pointer into '*classp' if 'name' is in the wrong form or if no such
181 vconn_lookup_class(const char *name, struct vconn_class **classp)
185 prefix_len = strcspn(name, ":");
186 if (name[prefix_len] != '\0') {
189 for (i = 0; i < ARRAY_SIZE(vconn_classes); i++) {
190 struct vconn_class *class = vconn_classes[i];
191 if (strlen(class->name) == prefix_len
192 && !memcmp(class->name, name, prefix_len)) {
203 /* Returns 0 if 'name' is a connection name in the form "TYPE:ARGS" and TYPE is
204 * a supported connection type, otherwise EAFNOSUPPORT. */
206 vconn_verify_name(const char *name)
208 struct vconn_class *class;
209 return vconn_lookup_class(name, &class);
212 /* Attempts to connect to an OpenFlow device. 'name' is a connection name in
213 * the form "TYPE:ARGS", where TYPE is an active vconn class's name and ARGS
214 * are vconn class-specific.
216 * The vconn will automatically negotiate an OpenFlow protocol version
217 * acceptable to both peers on the connection. The version negotiated will be
218 * no lower than 'min_version' and no higher than OFP10_VERSION.
220 * Returns 0 if successful, otherwise a positive errno value. If successful,
221 * stores a pointer to the new connection in '*vconnp', otherwise a null
224 vconn_open(const char *name, int min_version, struct vconn **vconnp,
227 struct vconn_class *class;
232 COVERAGE_INC(vconn_open);
233 check_vconn_classes();
235 /* Look up the class. */
236 error = vconn_lookup_class(name, &class);
241 /* Call class's "open" function. */
242 suffix_copy = xstrdup(strchr(name, ':') + 1);
243 error = class->open(name, suffix_copy, &vconn, dscp);
250 assert(vconn->state != VCS_CONNECTING || vconn->class->connect);
251 vconn->min_version = min_version;
260 /* Allows 'vconn' to perform maintenance activities, such as flushing output
263 vconn_run(struct vconn *vconn)
265 if (vconn->class->run) {
266 (vconn->class->run)(vconn);
270 /* Arranges for the poll loop to wake up when 'vconn' needs to perform
271 * maintenance activities. */
273 vconn_run_wait(struct vconn *vconn)
275 if (vconn->class->run_wait) {
276 (vconn->class->run_wait)(vconn);
281 vconn_open_block(const char *name, enum ofp_version min_version,
282 struct vconn **vconnp)
289 error = vconn_open(name, min_version, &vconn, DSCP_DEFAULT);
291 while ((error = vconn_connect(vconn)) == EAGAIN) {
293 vconn_run_wait(vconn);
294 vconn_connect_wait(vconn);
297 assert(error != EINPROGRESS);
309 /* Closes 'vconn'. */
311 vconn_close(struct vconn *vconn)
314 char *name = vconn->name;
315 (vconn->class->close)(vconn);
320 /* Returns the name of 'vconn', that is, the string passed to vconn_open(). */
322 vconn_get_name(const struct vconn *vconn)
327 /* Returns the IP address of the peer, or 0 if the peer is not connected over
328 * an IP-based protocol or if its IP address is not yet known. */
330 vconn_get_remote_ip(const struct vconn *vconn)
332 return vconn->remote_ip;
335 /* Returns the transport port of the peer, or 0 if the connection does not
336 * contain a port or if the port is not yet known. */
338 vconn_get_remote_port(const struct vconn *vconn)
340 return vconn->remote_port;
343 /* Returns the IP address used to connect to the peer, or 0 if the
344 * connection is not an IP-based protocol or if its IP address is not
347 vconn_get_local_ip(const struct vconn *vconn)
349 return vconn->local_ip;
352 /* Returns the transport port used to connect to the peer, or 0 if the
353 * connection does not contain a port or if the port is not yet known. */
355 vconn_get_local_port(const struct vconn *vconn)
357 return vconn->local_port;
360 /* Returns the OpenFlow version negotiated with the peer, or -1 if version
361 * negotiation is not yet complete.
363 * A vconn that has successfully connected (that is, vconn_connect() or
364 * vconn_send() or vconn_recv() has returned 0) always negotiated a version. */
366 vconn_get_version(const struct vconn *vconn)
368 return vconn->version;
372 vcs_connecting(struct vconn *vconn)
374 int retval = (vconn->class->connect)(vconn);
375 assert(retval != EINPROGRESS);
377 vconn->state = VCS_SEND_HELLO;
378 } else if (retval != EAGAIN) {
379 vconn->state = VCS_DISCONNECTED;
380 vconn->error = retval;
385 vcs_send_hello(struct vconn *vconn)
390 b = ofpraw_alloc(OFPRAW_OFPT_HELLO, OFP10_VERSION, 0);
391 retval = do_send(vconn, b);
393 vconn->state = VCS_RECV_HELLO;
396 if (retval != EAGAIN) {
397 vconn->state = VCS_DISCONNECTED;
398 vconn->error = retval;
404 vcs_recv_hello(struct vconn *vconn)
409 retval = do_recv(vconn, &b);
411 const struct ofp_header *oh = b->data;
415 error = ofptype_decode(&type, b->data);
416 if (!error && type == OFPTYPE_HELLO) {
417 if (b->size > sizeof *oh) {
418 struct ds msg = DS_EMPTY_INITIALIZER;
419 ds_put_format(&msg, "%s: extra-long hello:\n", vconn->name);
420 ds_put_hex_dump(&msg, b->data, b->size, 0, true);
421 VLOG_WARN_RL(&bad_ofmsg_rl, "%s", ds_cstr(&msg));
425 vconn->version = MIN(OFP10_VERSION, oh->version);
426 if (vconn->version < vconn->min_version) {
427 VLOG_WARN_RL(&bad_ofmsg_rl,
428 "%s: version negotiation failed: we support "
429 "versions 0x%02x to 0x%02x inclusive but peer "
430 "supports no later than version 0x%02"PRIx8,
431 vconn->name, vconn->min_version, OFP10_VERSION,
433 vconn->state = VCS_SEND_ERROR;
435 VLOG_DBG("%s: negotiated OpenFlow version 0x%02x "
436 "(we support versions 0x%02x to 0x%02x inclusive, "
437 "peer no later than version 0x%02"PRIx8")",
438 vconn->name, vconn->version, vconn->min_version,
439 OFP10_VERSION, oh->version);
440 vconn->state = VCS_CONNECTED;
445 char *s = ofp_to_string(b->data, b->size, 1);
446 VLOG_WARN_RL(&bad_ofmsg_rl,
447 "%s: received message while expecting hello: %s",
455 if (retval != EAGAIN) {
456 vconn->state = VCS_DISCONNECTED;
457 vconn->error = retval == EOF ? ECONNRESET : retval;
462 vcs_send_error(struct vconn *vconn)
468 snprintf(s, sizeof s, "We support versions 0x%02x to 0x%02x inclusive but "
469 "you support no later than version 0x%02"PRIx8".",
470 vconn->min_version, OFP10_VERSION, vconn->version);
471 b = ofperr_encode_hello(OFPERR_OFPHFC_INCOMPATIBLE,
472 ofperr_domain_from_version(vconn->version), s);
473 retval = do_send(vconn, b);
477 if (retval != EAGAIN) {
478 vconn->state = VCS_DISCONNECTED;
479 vconn->error = retval ? retval : EPROTO;
483 /* Tries to complete the connection on 'vconn'. If 'vconn''s connection is
484 * complete, returns 0 if the connection was successful or a positive errno
485 * value if it failed. If the connection is still in progress, returns
488 vconn_connect(struct vconn *vconn)
490 enum vconn_state last_state;
492 assert(vconn->min_version > 0);
494 last_state = vconn->state;
495 switch (vconn->state) {
497 vcs_connecting(vconn);
501 vcs_send_hello(vconn);
505 vcs_recv_hello(vconn);
512 vcs_send_error(vconn);
515 case VCS_DISCONNECTED:
521 } while (vconn->state != last_state);
526 /* Tries to receive an OpenFlow message from 'vconn'. If successful, stores
527 * the received message into '*msgp' and returns 0. The caller is responsible
528 * for destroying the message with ofpbuf_delete(). On failure, returns a
529 * positive errno value and stores a null pointer into '*msgp'. On normal
530 * connection close, returns EOF.
532 * vconn_recv will not block waiting for a packet to arrive. If no packets
533 * have been received, it returns EAGAIN immediately. */
535 vconn_recv(struct vconn *vconn, struct ofpbuf **msgp)
540 retval = vconn_connect(vconn);
542 retval = do_recv(vconn, &msg);
545 const struct ofp_header *oh = msg->data;
546 if (oh->version != vconn->version) {
549 if (ofptype_decode(&type, msg->data)
550 || (type != OFPTYPE_HELLO &&
551 type != OFPTYPE_ERROR &&
552 type != OFPTYPE_ECHO_REQUEST &&
553 type != OFPTYPE_ECHO_REPLY)) {
554 VLOG_ERR_RL(&bad_ofmsg_rl, "%s: received OpenFlow version "
555 "0x%02"PRIx8" != expected %02x",
556 vconn->name, oh->version, vconn->version);
563 *msgp = retval ? NULL : msg;
568 do_recv(struct vconn *vconn, struct ofpbuf **msgp)
570 int retval = (vconn->class->recv)(vconn, msgp);
572 COVERAGE_INC(vconn_received);
573 if (VLOG_IS_DBG_ENABLED()) {
574 char *s = ofp_to_string((*msgp)->data, (*msgp)->size, 1);
575 VLOG_DBG_RL(&ofmsg_rl, "%s: received: %s", vconn->name, s);
582 /* Tries to queue 'msg' for transmission on 'vconn'. If successful, returns 0,
583 * in which case ownership of 'msg' is transferred to the vconn. Success does
584 * not guarantee that 'msg' has been or ever will be delivered to the peer,
585 * only that it has been queued for transmission.
587 * Returns a positive errno value on failure, in which case the caller
588 * retains ownership of 'msg'.
590 * vconn_send will not block. If 'msg' cannot be immediately accepted for
591 * transmission, it returns EAGAIN immediately. */
593 vconn_send(struct vconn *vconn, struct ofpbuf *msg)
595 int retval = vconn_connect(vconn);
597 retval = do_send(vconn, msg);
603 do_send(struct vconn *vconn, struct ofpbuf *msg)
607 assert(msg->size >= sizeof(struct ofp_header));
609 ofpmsg_update_length(msg);
610 if (!VLOG_IS_DBG_ENABLED()) {
611 COVERAGE_INC(vconn_sent);
612 retval = (vconn->class->send)(vconn, msg);
614 char *s = ofp_to_string(msg->data, msg->size, 1);
615 retval = (vconn->class->send)(vconn, msg);
616 if (retval != EAGAIN) {
617 VLOG_DBG_RL(&ofmsg_rl, "%s: sent (%s): %s",
618 vconn->name, strerror(retval), s);
625 /* Same as vconn_send, except that it waits until 'msg' can be transmitted. */
627 vconn_send_block(struct vconn *vconn, struct ofpbuf *msg)
633 while ((retval = vconn_send(vconn, msg)) == EAGAIN) {
635 vconn_run_wait(vconn);
636 vconn_send_wait(vconn);
642 /* Same as vconn_recv, except that it waits until a message is received. */
644 vconn_recv_block(struct vconn *vconn, struct ofpbuf **msgp)
650 while ((retval = vconn_recv(vconn, msgp)) == EAGAIN) {
652 vconn_run_wait(vconn);
653 vconn_recv_wait(vconn);
659 /* Waits until a message with a transaction ID matching 'xid' is recived on
660 * 'vconn'. Returns 0 if successful, in which case the reply is stored in
661 * '*replyp' for the caller to examine and free. Otherwise returns a positive
662 * errno value, or EOF, and sets '*replyp' to null.
664 * 'request' is always destroyed, regardless of the return value. */
666 vconn_recv_xid(struct vconn *vconn, ovs_be32 xid, struct ofpbuf **replyp)
670 struct ofpbuf *reply;
673 error = vconn_recv_block(vconn, &reply);
678 recv_xid = ((struct ofp_header *) reply->data)->xid;
679 if (xid == recv_xid) {
684 VLOG_DBG_RL(&bad_ofmsg_rl, "%s: received reply with xid %08"PRIx32
685 " != expected %08"PRIx32,
686 vconn->name, ntohl(recv_xid), ntohl(xid));
687 ofpbuf_delete(reply);
691 /* Sends 'request' to 'vconn' and blocks until it receives a reply with a
692 * matching transaction ID. Returns 0 if successful, in which case the reply
693 * is stored in '*replyp' for the caller to examine and free. Otherwise
694 * returns a positive errno value, or EOF, and sets '*replyp' to null.
696 * 'request' should be an OpenFlow request that requires a reply. Otherwise,
697 * if there is no reply, this function can end up blocking forever (or until
698 * the peer drops the connection).
700 * 'request' is always destroyed, regardless of the return value. */
702 vconn_transact(struct vconn *vconn, struct ofpbuf *request,
703 struct ofpbuf **replyp)
705 ovs_be32 send_xid = ((struct ofp_header *) request->data)->xid;
709 error = vconn_send_block(vconn, request);
711 ofpbuf_delete(request);
713 return error ? error : vconn_recv_xid(vconn, send_xid, replyp);
716 /* Sends 'request' followed by a barrier request to 'vconn', then blocks until
717 * it receives a reply to the barrier. If successful, stores the reply to
718 * 'request' in '*replyp', if one was received, and otherwise NULL, then
719 * returns 0. Otherwise returns a positive errno value, or EOF, and sets
722 * This function is useful for sending an OpenFlow request that doesn't
723 * ordinarily include a reply but might report an error in special
726 * 'request' is always destroyed, regardless of the return value. */
728 vconn_transact_noreply(struct vconn *vconn, struct ofpbuf *request,
729 struct ofpbuf **replyp)
731 ovs_be32 request_xid;
732 ovs_be32 barrier_xid;
733 struct ofpbuf *barrier;
739 request_xid = ((struct ofp_header *) request->data)->xid;
740 error = vconn_send_block(vconn, request);
742 ofpbuf_delete(request);
747 barrier = ofputil_encode_barrier_request();
748 barrier_xid = ((struct ofp_header *) barrier->data)->xid;
749 error = vconn_send_block(vconn, barrier);
751 ofpbuf_delete(barrier);
760 error = vconn_recv_block(vconn, &msg);
762 ofpbuf_delete(*replyp);
767 msg_xid = ((struct ofp_header *) msg->data)->xid;
768 if (msg_xid == request_xid) {
770 VLOG_WARN_RL(&bad_ofmsg_rl, "%s: duplicate replies with "
771 "xid %08"PRIx32, vconn->name, ntohl(msg_xid));
772 ofpbuf_delete(*replyp);
777 if (msg_xid == barrier_xid) {
780 VLOG_DBG_RL(&bad_ofmsg_rl, "%s: reply with xid %08"PRIx32
781 " != expected %08"PRIx32" or %08"PRIx32,
782 vconn->name, ntohl(msg_xid),
783 ntohl(request_xid), ntohl(barrier_xid));
789 /* vconn_transact_noreply() for a list of "struct ofpbuf"s, sent one by one.
790 * All of the requests on 'requests' are always destroyed, regardless of the
793 vconn_transact_multiple_noreply(struct vconn *vconn, struct list *requests,
794 struct ofpbuf **replyp)
796 struct ofpbuf *request, *next;
798 LIST_FOR_EACH_SAFE (request, next, list_node, requests) {
801 list_remove(&request->list_node);
803 error = vconn_transact_noreply(vconn, request, replyp);
804 if (error || *replyp) {
805 ofpbuf_list_delete(requests);
815 vconn_wait(struct vconn *vconn, enum vconn_wait_type wait)
817 assert(wait == WAIT_CONNECT || wait == WAIT_RECV || wait == WAIT_SEND);
819 switch (vconn->state) {
836 case VCS_DISCONNECTED:
837 poll_immediate_wake();
840 (vconn->class->wait)(vconn, wait);
844 vconn_connect_wait(struct vconn *vconn)
846 vconn_wait(vconn, WAIT_CONNECT);
850 vconn_recv_wait(struct vconn *vconn)
852 vconn_wait(vconn, WAIT_RECV);
856 vconn_send_wait(struct vconn *vconn)
858 vconn_wait(vconn, WAIT_SEND);
861 /* Given 'name', a connection name in the form "TYPE:ARGS", stores the class
862 * named "TYPE" into '*classp' and returns 0. Returns EAFNOSUPPORT and stores
863 * a null pointer into '*classp' if 'name' is in the wrong form or if no such
866 pvconn_lookup_class(const char *name, struct pvconn_class **classp)
870 prefix_len = strcspn(name, ":");
871 if (name[prefix_len] != '\0') {
874 for (i = 0; i < ARRAY_SIZE(pvconn_classes); i++) {
875 struct pvconn_class *class = pvconn_classes[i];
876 if (strlen(class->name) == prefix_len
877 && !memcmp(class->name, name, prefix_len)) {
888 /* Returns 0 if 'name' is a connection name in the form "TYPE:ARGS" and TYPE is
889 * a supported connection type, otherwise EAFNOSUPPORT. */
891 pvconn_verify_name(const char *name)
893 struct pvconn_class *class;
894 return pvconn_lookup_class(name, &class);
897 /* Attempts to start listening for OpenFlow connections. 'name' is a
898 * connection name in the form "TYPE:ARGS", where TYPE is an passive vconn
899 * class's name and ARGS are vconn class-specific.
901 * Returns 0 if successful, otherwise a positive errno value. If successful,
902 * stores a pointer to the new connection in '*pvconnp', otherwise a null
905 pvconn_open(const char *name, struct pvconn **pvconnp, uint8_t dscp)
907 struct pvconn_class *class;
908 struct pvconn *pvconn;
912 check_vconn_classes();
914 /* Look up the class. */
915 error = pvconn_lookup_class(name, &class);
920 /* Call class's "open" function. */
921 suffix_copy = xstrdup(strchr(name, ':') + 1);
922 error = class->listen(name, suffix_copy, &pvconn, dscp);
937 /* Returns the name that was used to open 'pvconn'. The caller must not
938 * modify or free the name. */
940 pvconn_get_name(const struct pvconn *pvconn)
945 /* Closes 'pvconn'. */
947 pvconn_close(struct pvconn *pvconn)
949 if (pvconn != NULL) {
950 char *name = pvconn->name;
951 (pvconn->class->close)(pvconn);
956 /* Tries to accept a new connection on 'pvconn'. If successful, stores the new
957 * connection in '*new_vconn' and returns 0. Otherwise, returns a positive
960 * The new vconn will automatically negotiate an OpenFlow protocol version
961 * acceptable to both peers on the connection. The version negotiated will be
962 * no lower than 'min_version' and no higher than OFP10_VERSION.
964 * pvconn_accept() will not block waiting for a connection. If no connection
965 * is ready to be accepted, it returns EAGAIN immediately. */
967 pvconn_accept(struct pvconn *pvconn, int min_version, struct vconn **new_vconn)
969 int retval = (pvconn->class->accept)(pvconn, new_vconn);
973 assert((*new_vconn)->state != VCS_CONNECTING
974 || (*new_vconn)->class->connect);
975 (*new_vconn)->min_version = min_version;
981 pvconn_wait(struct pvconn *pvconn)
983 (pvconn->class->wait)(pvconn);
986 /* Initializes 'vconn' as a new vconn named 'name', implemented via 'class'.
987 * The initial connection status, supplied as 'connect_status', is interpreted
990 * - 0: 'vconn' is connected. Its 'send' and 'recv' functions may be
991 * called in the normal fashion.
993 * - EAGAIN: 'vconn' is trying to complete a connection. Its 'connect'
994 * function should be called to complete the connection.
996 * - Other positive errno values indicate that the connection failed with
997 * the specified error.
999 * After calling this function, vconn_close() must be used to destroy 'vconn',
1000 * otherwise resources will be leaked.
1002 * The caller retains ownership of 'name'. */
1004 vconn_init(struct vconn *vconn, struct vconn_class *class, int connect_status,
1007 vconn->class = class;
1008 vconn->state = (connect_status == EAGAIN ? VCS_CONNECTING
1009 : !connect_status ? VCS_SEND_HELLO
1010 : VCS_DISCONNECTED);
1011 vconn->error = connect_status;
1013 vconn->min_version = 0;
1014 vconn->remote_ip = 0;
1015 vconn->remote_port = 0;
1016 vconn->local_ip = 0;
1017 vconn->local_port = 0;
1018 vconn->name = xstrdup(name);
1019 assert(vconn->state != VCS_CONNECTING || class->connect);
1023 vconn_set_remote_ip(struct vconn *vconn, ovs_be32 ip)
1025 vconn->remote_ip = ip;
1029 vconn_set_remote_port(struct vconn *vconn, ovs_be16 port)
1031 vconn->remote_port = port;
1035 vconn_set_local_ip(struct vconn *vconn, ovs_be32 ip)
1037 vconn->local_ip = ip;
1041 vconn_set_local_port(struct vconn *vconn, ovs_be16 port)
1043 vconn->local_port = port;
1047 pvconn_init(struct pvconn *pvconn, struct pvconn_class *class,
1050 pvconn->class = class;
1051 pvconn->name = xstrdup(name);