2 * Copyright (c) 2008, 2009, 2010, 2011, 2012 Nicira Networks.
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"
31 #include "ofp-print.h"
34 #include "openflow/nicira-ext.h"
35 #include "openflow/openflow.h"
37 #include "poll-loop.h"
42 VLOG_DEFINE_THIS_MODULE(vconn);
44 COVERAGE_DEFINE(vconn_open);
45 COVERAGE_DEFINE(vconn_received);
46 COVERAGE_DEFINE(vconn_sent);
48 /* State of an active vconn.*/
50 /* This is the ordinary progression of states. */
51 VCS_CONNECTING, /* Underlying vconn is not connected. */
52 VCS_SEND_HELLO, /* Waiting to send OFPT_HELLO message. */
53 VCS_RECV_HELLO, /* Waiting to receive OFPT_HELLO message. */
54 VCS_CONNECTED, /* Connection established. */
56 /* These states are entered only when something goes wrong. */
57 VCS_SEND_ERROR, /* Sending OFPT_ERROR message. */
58 VCS_DISCONNECTED /* Connection failed or connection closed. */
61 static struct vconn_class *vconn_classes[] = {
69 static struct pvconn_class *pvconn_classes[] = {
77 /* Rate limit for individual OpenFlow messages going over the vconn, output at
78 * DBG level. This is very high because, if these are enabled, it is because
79 * we really need to see them. */
80 static struct vlog_rate_limit ofmsg_rl = VLOG_RATE_LIMIT_INIT(600, 600);
82 /* Rate limit for OpenFlow message parse errors. These always indicate a bug
83 * in the peer and so there's not much point in showing a lot of them. */
84 static struct vlog_rate_limit bad_ofmsg_rl = VLOG_RATE_LIMIT_INIT(1, 5);
86 static int do_recv(struct vconn *, struct ofpbuf **);
87 static int do_send(struct vconn *, struct ofpbuf *);
89 /* Check the validity of the vconn class structures. */
91 check_vconn_classes(void)
96 for (i = 0; i < ARRAY_SIZE(vconn_classes); i++) {
97 struct vconn_class *class = vconn_classes[i];
98 assert(class->name != NULL);
99 assert(class->open != NULL);
100 if (class->close || class->recv || class->send
101 || class->run || class->run_wait || class->wait) {
102 assert(class->close != NULL);
103 assert(class->recv != NULL);
104 assert(class->send != NULL);
105 assert(class->wait != NULL);
107 /* This class delegates to another one. */
111 for (i = 0; i < ARRAY_SIZE(pvconn_classes); i++) {
112 struct pvconn_class *class = pvconn_classes[i];
113 assert(class->name != NULL);
114 assert(class->listen != NULL);
115 if (class->close || class->accept || class->wait) {
116 assert(class->close != NULL);
117 assert(class->accept != NULL);
118 assert(class->wait != NULL);
120 /* This class delegates to another one. */
126 /* Prints information on active (if 'active') and passive (if 'passive')
127 * connection methods supported by the vconn. If 'bootstrap' is true, also
128 * advertises options to bootstrap the CA certificate. */
130 vconn_usage(bool active, bool passive, bool bootstrap OVS_UNUSED)
132 /* Really this should be implemented via callbacks into the vconn
133 * providers, but that seems too heavy-weight to bother with at the
138 printf("Active OpenFlow connection methods:\n");
139 printf(" tcp:IP[:PORT] "
140 "PORT (default: %d) at remote IP\n", OFP_TCP_PORT);
142 printf(" ssl:IP[:PORT] "
143 "SSL PORT (default: %d) at remote IP\n", OFP_SSL_PORT);
145 printf(" unix:FILE Unix domain socket named FILE\n");
149 printf("Passive OpenFlow connection methods:\n");
150 printf(" ptcp:[PORT][:IP] "
151 "listen to TCP PORT (default: %d) on IP\n",
154 printf(" pssl:[PORT][:IP] "
155 "listen for SSL on PORT (default: %d) on IP\n",
158 printf(" punix:FILE "
159 "listen on Unix domain socket FILE\n");
163 printf("PKI configuration (required to use SSL):\n"
164 " -p, --private-key=FILE file with private key\n"
165 " -c, --certificate=FILE file with certificate for private key\n"
166 " -C, --ca-cert=FILE file with peer CA certificate\n");
168 printf(" --bootstrap-ca-cert=FILE file with peer CA certificate "
169 "to read or create\n");
174 /* Given 'name', a connection name in the form "TYPE:ARGS", stores the class
175 * named "TYPE" into '*classp' and returns 0. Returns EAFNOSUPPORT and stores
176 * a null pointer into '*classp' if 'name' is in the wrong form or if no such
179 vconn_lookup_class(const char *name, struct vconn_class **classp)
183 prefix_len = strcspn(name, ":");
184 if (name[prefix_len] != '\0') {
187 for (i = 0; i < ARRAY_SIZE(vconn_classes); i++) {
188 struct vconn_class *class = vconn_classes[i];
189 if (strlen(class->name) == prefix_len
190 && !memcmp(class->name, name, prefix_len)) {
201 /* Returns 0 if 'name' is a connection name in the form "TYPE:ARGS" and TYPE is
202 * a supported connection type, otherwise EAFNOSUPPORT. */
204 vconn_verify_name(const char *name)
206 struct vconn_class *class;
207 return vconn_lookup_class(name, &class);
210 /* Attempts to connect to an OpenFlow device. 'name' is a connection name in
211 * the form "TYPE:ARGS", where TYPE is an active vconn class's name and ARGS
212 * are vconn class-specific.
214 * The vconn will automatically negotiate an OpenFlow protocol version
215 * acceptable to both peers on the connection. The version negotiated will be
216 * no lower than 'min_version' and no higher than OFP10_VERSION.
218 * Returns 0 if successful, otherwise a positive errno value. If successful,
219 * stores a pointer to the new connection in '*vconnp', otherwise a null
222 vconn_open(const char *name, int min_version, struct vconn **vconnp)
224 struct vconn_class *class;
229 COVERAGE_INC(vconn_open);
230 check_vconn_classes();
232 /* Look up the class. */
233 error = vconn_lookup_class(name, &class);
238 /* Call class's "open" function. */
239 suffix_copy = xstrdup(strchr(name, ':') + 1);
240 error = class->open(name, suffix_copy, &vconn);
247 assert(vconn->state != VCS_CONNECTING || vconn->class->connect);
248 vconn->min_version = min_version;
257 /* Allows 'vconn' to perform maintenance activities, such as flushing output
260 vconn_run(struct vconn *vconn)
262 if (vconn->class->run) {
263 (vconn->class->run)(vconn);
267 /* Arranges for the poll loop to wake up when 'vconn' needs to perform
268 * maintenance activities. */
270 vconn_run_wait(struct vconn *vconn)
272 if (vconn->class->run_wait) {
273 (vconn->class->run_wait)(vconn);
278 vconn_open_block(const char *name, int min_version, struct vconn **vconnp)
285 error = vconn_open(name, min_version, &vconn);
287 while ((error = vconn_connect(vconn)) == EAGAIN) {
289 vconn_run_wait(vconn);
290 vconn_connect_wait(vconn);
293 assert(error != EINPROGRESS);
305 /* Closes 'vconn'. */
307 vconn_close(struct vconn *vconn)
310 char *name = vconn->name;
311 (vconn->class->close)(vconn);
316 /* Returns the name of 'vconn', that is, the string passed to vconn_open(). */
318 vconn_get_name(const struct vconn *vconn)
323 /* Returns the IP address of the peer, or 0 if the peer is not connected over
324 * an IP-based protocol or if its IP address is not yet known. */
326 vconn_get_remote_ip(const struct vconn *vconn)
328 return vconn->remote_ip;
331 /* Returns the transport port of the peer, or 0 if the connection does not
332 * contain a port or if the port is not yet known. */
334 vconn_get_remote_port(const struct vconn *vconn)
336 return vconn->remote_port;
339 /* Returns the IP address used to connect to the peer, or 0 if the
340 * connection is not an IP-based protocol or if its IP address is not
343 vconn_get_local_ip(const struct vconn *vconn)
345 return vconn->local_ip;
348 /* Returns the transport port used to connect to the peer, or 0 if the
349 * connection does not contain a port or if the port is not yet known. */
351 vconn_get_local_port(const struct vconn *vconn)
353 return vconn->local_port;
356 /* Returns the OpenFlow version negotiated with the peer, or -1 if version
357 * negotiation is not yet complete.
359 * A vconn that has successfully connected (that is, vconn_connect() or
360 * vconn_send() or vconn_recv() has returned 0) always negotiated a version. */
362 vconn_get_version(const struct vconn *vconn)
364 return vconn->version;
368 vcs_connecting(struct vconn *vconn)
370 int retval = (vconn->class->connect)(vconn);
371 assert(retval != EINPROGRESS);
373 vconn->state = VCS_SEND_HELLO;
374 } else if (retval != EAGAIN) {
375 vconn->state = VCS_DISCONNECTED;
376 vconn->error = retval;
381 vcs_send_hello(struct vconn *vconn)
386 make_openflow(sizeof(struct ofp_header), OFPT_HELLO, &b);
387 retval = do_send(vconn, b);
389 vconn->state = VCS_RECV_HELLO;
392 if (retval != EAGAIN) {
393 vconn->state = VCS_DISCONNECTED;
394 vconn->error = retval;
400 vcs_recv_hello(struct vconn *vconn)
405 retval = do_recv(vconn, &b);
407 struct ofp_header *oh = b->data;
409 if (oh->type == OFPT_HELLO) {
410 if (b->size > sizeof *oh) {
411 struct ds msg = DS_EMPTY_INITIALIZER;
412 ds_put_format(&msg, "%s: extra-long hello:\n", vconn->name);
413 ds_put_hex_dump(&msg, b->data, b->size, 0, true);
414 VLOG_WARN_RL(&bad_ofmsg_rl, "%s", ds_cstr(&msg));
418 vconn->version = MIN(OFP10_VERSION, oh->version);
419 if (vconn->version < vconn->min_version) {
420 VLOG_WARN_RL(&bad_ofmsg_rl,
421 "%s: version negotiation failed: we support "
422 "versions 0x%02x to 0x%02x inclusive but peer "
423 "supports no later than version 0x%02"PRIx8,
424 vconn->name, vconn->min_version, OFP10_VERSION,
426 vconn->state = VCS_SEND_ERROR;
428 VLOG_DBG("%s: negotiated OpenFlow version 0x%02x "
429 "(we support versions 0x%02x to 0x%02x inclusive, "
430 "peer no later than version 0x%02"PRIx8")",
431 vconn->name, vconn->version, vconn->min_version,
432 OFP10_VERSION, oh->version);
433 vconn->state = VCS_CONNECTED;
438 char *s = ofp_to_string(b->data, b->size, 1);
439 VLOG_WARN_RL(&bad_ofmsg_rl,
440 "%s: received message while expecting hello: %s",
448 if (retval != EAGAIN) {
449 vconn->state = VCS_DISCONNECTED;
450 vconn->error = retval == EOF ? ECONNRESET : retval;
455 vcs_send_error(struct vconn *vconn)
461 snprintf(s, sizeof s, "We support versions 0x%02x to 0x%02x inclusive but "
462 "you support no later than version 0x%02"PRIx8".",
463 vconn->min_version, OFP10_VERSION, vconn->version);
464 b = ofperr_encode_hello(OFPERR_OFPHFC_INCOMPATIBLE,
465 ofperr_domain_from_version(vconn->version), s);
466 retval = do_send(vconn, b);
470 if (retval != EAGAIN) {
471 vconn->state = VCS_DISCONNECTED;
472 vconn->error = retval ? retval : EPROTO;
476 /* Tries to complete the connection on 'vconn'. If 'vconn''s connection is
477 * complete, returns 0 if the connection was successful or a positive errno
478 * value if it failed. If the connection is still in progress, returns
481 vconn_connect(struct vconn *vconn)
483 enum vconn_state last_state;
485 assert(vconn->min_version > 0);
487 last_state = vconn->state;
488 switch (vconn->state) {
490 vcs_connecting(vconn);
494 vcs_send_hello(vconn);
498 vcs_recv_hello(vconn);
505 vcs_send_error(vconn);
508 case VCS_DISCONNECTED:
514 } while (vconn->state != last_state);
519 /* Tries to receive an OpenFlow message from 'vconn'. If successful, stores
520 * the received message into '*msgp' and returns 0. The caller is responsible
521 * for destroying the message with ofpbuf_delete(). On failure, returns a
522 * positive errno value and stores a null pointer into '*msgp'. On normal
523 * connection close, returns EOF.
525 * vconn_recv will not block waiting for a packet to arrive. If no packets
526 * have been received, it returns EAGAIN immediately. */
528 vconn_recv(struct vconn *vconn, struct ofpbuf **msgp)
530 int retval = vconn_connect(vconn);
532 retval = do_recv(vconn, msgp);
538 do_recv(struct vconn *vconn, struct ofpbuf **msgp)
540 int retval = (vconn->class->recv)(vconn, msgp);
542 struct ofp_header *oh;
544 COVERAGE_INC(vconn_received);
545 if (VLOG_IS_DBG_ENABLED()) {
546 char *s = ofp_to_string((*msgp)->data, (*msgp)->size, 1);
547 VLOG_DBG_RL(&ofmsg_rl, "%s: received: %s", vconn->name, s);
551 oh = ofpbuf_at_assert(*msgp, 0, sizeof *oh);
552 if ((oh->version != vconn->version || oh->version == 0)
553 && oh->type != OFPT_HELLO
554 && oh->type != OFPT_ERROR
555 && oh->type != OFPT_ECHO_REQUEST
556 && oh->type != OFPT_ECHO_REPLY
557 && oh->type != OFPT_VENDOR)
559 if (vconn->version == 0) {
560 VLOG_ERR_RL(&bad_ofmsg_rl,
561 "%s: received OpenFlow message type %"PRIu8" "
562 "before version negotiation complete",
563 vconn->name, oh->type);
565 VLOG_ERR_RL(&bad_ofmsg_rl,
566 "%s: received OpenFlow version 0x%02"PRIx8" "
568 vconn->name, oh->version, vconn->version);
570 ofpbuf_delete(*msgp);
580 /* Tries to queue 'msg' for transmission on 'vconn'. If successful, returns 0,
581 * in which case ownership of 'msg' is transferred to the vconn. Success does
582 * not guarantee that 'msg' has been or ever will be delivered to the peer,
583 * only that it has been queued for transmission.
585 * Returns a positive errno value on failure, in which case the caller
586 * retains ownership of 'msg'.
588 * vconn_send will not block. If 'msg' cannot be immediately accepted for
589 * transmission, it returns EAGAIN immediately. */
591 vconn_send(struct vconn *vconn, struct ofpbuf *msg)
593 int retval = vconn_connect(vconn);
595 retval = do_send(vconn, msg);
601 do_send(struct vconn *vconn, struct ofpbuf *msg)
605 assert(msg->size >= sizeof(struct ofp_header));
606 assert(((struct ofp_header *) msg->data)->length == htons(msg->size));
607 if (!VLOG_IS_DBG_ENABLED()) {
608 COVERAGE_INC(vconn_sent);
609 retval = (vconn->class->send)(vconn, msg);
611 char *s = ofp_to_string(msg->data, msg->size, 1);
612 retval = (vconn->class->send)(vconn, msg);
613 if (retval != EAGAIN) {
614 VLOG_DBG_RL(&ofmsg_rl, "%s: sent (%s): %s",
615 vconn->name, strerror(retval), s);
622 /* Same as vconn_send, except that it waits until 'msg' can be transmitted. */
624 vconn_send_block(struct vconn *vconn, struct ofpbuf *msg)
630 while ((retval = vconn_send(vconn, msg)) == EAGAIN) {
632 vconn_run_wait(vconn);
633 vconn_send_wait(vconn);
639 /* Same as vconn_recv, except that it waits until a message is received. */
641 vconn_recv_block(struct vconn *vconn, struct ofpbuf **msgp)
647 while ((retval = vconn_recv(vconn, msgp)) == EAGAIN) {
649 vconn_run_wait(vconn);
650 vconn_recv_wait(vconn);
656 /* Waits until a message with a transaction ID matching 'xid' is recived on
657 * 'vconn'. Returns 0 if successful, in which case the reply is stored in
658 * '*replyp' for the caller to examine and free. Otherwise returns a positive
659 * errno value, or EOF, and sets '*replyp' to null.
661 * 'request' is always destroyed, regardless of the return value. */
663 vconn_recv_xid(struct vconn *vconn, ovs_be32 xid, struct ofpbuf **replyp)
667 struct ofpbuf *reply;
670 error = vconn_recv_block(vconn, &reply);
675 recv_xid = ((struct ofp_header *) reply->data)->xid;
676 if (xid == recv_xid) {
681 VLOG_DBG_RL(&bad_ofmsg_rl, "%s: received reply with xid %08"PRIx32
682 " != expected %08"PRIx32,
683 vconn->name, ntohl(recv_xid), ntohl(xid));
684 ofpbuf_delete(reply);
688 /* Sends 'request' to 'vconn' and blocks until it receives a reply with a
689 * matching transaction ID. Returns 0 if successful, in which case the reply
690 * is stored in '*replyp' for the caller to examine and free. Otherwise
691 * returns a positive errno value, or EOF, and sets '*replyp' to null.
693 * 'request' should be an OpenFlow request that requires a reply. Otherwise,
694 * if there is no reply, this function can end up blocking forever (or until
695 * the peer drops the connection).
697 * 'request' is always destroyed, regardless of the return value. */
699 vconn_transact(struct vconn *vconn, struct ofpbuf *request,
700 struct ofpbuf **replyp)
702 ovs_be32 send_xid = ((struct ofp_header *) request->data)->xid;
706 error = vconn_send_block(vconn, request);
708 ofpbuf_delete(request);
710 return error ? error : vconn_recv_xid(vconn, send_xid, replyp);
713 /* Sends 'request' followed by a barrier request to 'vconn', then blocks until
714 * it receives a reply to the barrier. If successful, stores the reply to
715 * 'request' in '*replyp', if one was received, and otherwise NULL, then
716 * returns 0. Otherwise returns a positive errno value, or EOF, and sets
719 * This function is useful for sending an OpenFlow request that doesn't
720 * ordinarily include a reply but might report an error in special
723 * 'request' is always destroyed, regardless of the return value. */
725 vconn_transact_noreply(struct vconn *vconn, struct ofpbuf *request,
726 struct ofpbuf **replyp)
728 ovs_be32 request_xid;
729 ovs_be32 barrier_xid;
730 struct ofpbuf *barrier;
736 request_xid = ((struct ofp_header *) request->data)->xid;
737 error = vconn_send_block(vconn, request);
739 ofpbuf_delete(request);
744 barrier = ofputil_encode_barrier_request();
745 barrier_xid = ((struct ofp_header *) barrier->data)->xid;
746 error = vconn_send_block(vconn, barrier);
748 ofpbuf_delete(barrier);
757 error = vconn_recv_block(vconn, &msg);
759 ofpbuf_delete(*replyp);
764 msg_xid = ((struct ofp_header *) msg->data)->xid;
765 if (msg_xid == request_xid) {
767 VLOG_WARN_RL(&bad_ofmsg_rl, "%s: duplicate replies with "
768 "xid %08"PRIx32, vconn->name, ntohl(msg_xid));
769 ofpbuf_delete(*replyp);
774 if (msg_xid == barrier_xid) {
777 VLOG_DBG_RL(&bad_ofmsg_rl, "%s: reply with xid %08"PRIx32
778 " != expected %08"PRIx32" or %08"PRIx32,
779 vconn->name, ntohl(msg_xid),
780 ntohl(request_xid), ntohl(barrier_xid));
786 /* vconn_transact_noreply() for a list of "struct ofpbuf"s, sent one by one.
787 * All of the requests on 'requests' are always destroyed, regardless of the
790 vconn_transact_multiple_noreply(struct vconn *vconn, struct list *requests,
791 struct ofpbuf **replyp)
793 struct ofpbuf *request, *next;
795 LIST_FOR_EACH_SAFE (request, next, list_node, requests) {
798 list_remove(&request->list_node);
800 error = vconn_transact_noreply(vconn, request, replyp);
801 if (error || *replyp) {
802 ofpbuf_list_delete(requests);
812 vconn_wait(struct vconn *vconn, enum vconn_wait_type wait)
814 assert(wait == WAIT_CONNECT || wait == WAIT_RECV || wait == WAIT_SEND);
816 switch (vconn->state) {
833 case VCS_DISCONNECTED:
834 poll_immediate_wake();
837 (vconn->class->wait)(vconn, wait);
841 vconn_connect_wait(struct vconn *vconn)
843 vconn_wait(vconn, WAIT_CONNECT);
847 vconn_recv_wait(struct vconn *vconn)
849 vconn_wait(vconn, WAIT_RECV);
853 vconn_send_wait(struct vconn *vconn)
855 vconn_wait(vconn, WAIT_SEND);
858 /* Given 'name', a connection name in the form "TYPE:ARGS", stores the class
859 * named "TYPE" into '*classp' and returns 0. Returns EAFNOSUPPORT and stores
860 * a null pointer into '*classp' if 'name' is in the wrong form or if no such
863 pvconn_lookup_class(const char *name, struct pvconn_class **classp)
867 prefix_len = strcspn(name, ":");
868 if (name[prefix_len] != '\0') {
871 for (i = 0; i < ARRAY_SIZE(pvconn_classes); i++) {
872 struct pvconn_class *class = pvconn_classes[i];
873 if (strlen(class->name) == prefix_len
874 && !memcmp(class->name, name, prefix_len)) {
885 /* Returns 0 if 'name' is a connection name in the form "TYPE:ARGS" and TYPE is
886 * a supported connection type, otherwise EAFNOSUPPORT. */
888 pvconn_verify_name(const char *name)
890 struct pvconn_class *class;
891 return pvconn_lookup_class(name, &class);
894 /* Attempts to start listening for OpenFlow connections. 'name' is a
895 * connection name in the form "TYPE:ARGS", where TYPE is an passive vconn
896 * class's name and ARGS are vconn class-specific.
898 * Returns 0 if successful, otherwise a positive errno value. If successful,
899 * stores a pointer to the new connection in '*pvconnp', otherwise a null
902 pvconn_open(const char *name, struct pvconn **pvconnp)
904 struct pvconn_class *class;
905 struct pvconn *pvconn;
909 check_vconn_classes();
911 /* Look up the class. */
912 error = pvconn_lookup_class(name, &class);
917 /* Call class's "open" function. */
918 suffix_copy = xstrdup(strchr(name, ':') + 1);
919 error = class->listen(name, suffix_copy, &pvconn);
934 /* Returns the name that was used to open 'pvconn'. The caller must not
935 * modify or free the name. */
937 pvconn_get_name(const struct pvconn *pvconn)
942 /* Closes 'pvconn'. */
944 pvconn_close(struct pvconn *pvconn)
946 if (pvconn != NULL) {
947 char *name = pvconn->name;
948 (pvconn->class->close)(pvconn);
953 /* Tries to accept a new connection on 'pvconn'. If successful, stores the new
954 * connection in '*new_vconn' and returns 0. Otherwise, returns a positive
957 * The new vconn will automatically negotiate an OpenFlow protocol version
958 * acceptable to both peers on the connection. The version negotiated will be
959 * no lower than 'min_version' and no higher than OFP10_VERSION.
961 * pvconn_accept() will not block waiting for a connection. If no connection
962 * is ready to be accepted, it returns EAGAIN immediately. */
964 pvconn_accept(struct pvconn *pvconn, int min_version, struct vconn **new_vconn)
966 int retval = (pvconn->class->accept)(pvconn, new_vconn);
970 assert((*new_vconn)->state != VCS_CONNECTING
971 || (*new_vconn)->class->connect);
972 (*new_vconn)->min_version = min_version;
978 pvconn_wait(struct pvconn *pvconn)
980 (pvconn->class->wait)(pvconn);
983 /* Initializes 'vconn' as a new vconn named 'name', implemented via 'class'.
984 * The initial connection status, supplied as 'connect_status', is interpreted
987 * - 0: 'vconn' is connected. Its 'send' and 'recv' functions may be
988 * called in the normal fashion.
990 * - EAGAIN: 'vconn' is trying to complete a connection. Its 'connect'
991 * function should be called to complete the connection.
993 * - Other positive errno values indicate that the connection failed with
994 * the specified error.
996 * After calling this function, vconn_close() must be used to destroy 'vconn',
997 * otherwise resources will be leaked.
999 * The caller retains ownership of 'name'. */
1001 vconn_init(struct vconn *vconn, struct vconn_class *class, int connect_status,
1004 vconn->class = class;
1005 vconn->state = (connect_status == EAGAIN ? VCS_CONNECTING
1006 : !connect_status ? VCS_SEND_HELLO
1007 : VCS_DISCONNECTED);
1008 vconn->error = connect_status;
1010 vconn->min_version = 0;
1011 vconn->remote_ip = 0;
1012 vconn->remote_port = 0;
1013 vconn->local_ip = 0;
1014 vconn->local_port = 0;
1015 vconn->name = xstrdup(name);
1016 assert(vconn->state != VCS_CONNECTING || class->connect);
1020 vconn_set_remote_ip(struct vconn *vconn, ovs_be32 ip)
1022 vconn->remote_ip = ip;
1026 vconn_set_remote_port(struct vconn *vconn, ovs_be16 port)
1028 vconn->remote_port = port;
1032 vconn_set_local_ip(struct vconn *vconn, ovs_be32 ip)
1034 vconn->local_ip = ip;
1038 vconn_set_local_port(struct vconn *vconn, ovs_be16 port)
1040 vconn->local_port = port;
1044 pvconn_init(struct pvconn *pvconn, struct pvconn_class *class,
1047 pvconn->class = class;
1048 pvconn->name = xstrdup(name);