Break passive vconns out into separate pvconn routines and data structures.
[sliver-openvswitch.git] / lib / vconn.c
1 /* Copyright (c) 2008 The Board of Trustees of The Leland Stanford
2  * Junior University
3  * 
4  * We are making the OpenFlow specification and associated documentation
5  * (Software) available for public use and benefit with the expectation
6  * that others will use, modify and enhance the Software and contribute
7  * those enhancements back to the community. However, since we would
8  * like to make the Software available for broadest use, with as few
9  * restrictions as possible permission is hereby granted, free of
10  * charge, to any person obtaining a copy of this Software to deal in
11  * the Software under the copyrights without restriction, including
12  * without limitation the rights to use, copy, modify, merge, publish,
13  * distribute, sublicense, and/or sell copies of the Software, and to
14  * permit persons to whom the Software is furnished to do so, subject to
15  * the following conditions:
16  * 
17  * The above copyright notice and this permission notice shall be
18  * included in all copies or substantial portions of the Software.
19  * 
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23  * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
24  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
25  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
26  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27  * SOFTWARE.
28  * 
29  * The name and trademarks of copyright holder(s) may NOT be used in
30  * advertising or publicity pertaining to the Software or any
31  * derivatives without specific, written prior permission.
32  */
33
34 #include <config.h>
35 #include "vconn-provider.h"
36 #include <assert.h>
37 #include <errno.h>
38 #include <inttypes.h>
39 #include <netinet/in.h>
40 #include <poll.h>
41 #include <stdlib.h>
42 #include <string.h>
43 #include "buffer.h"
44 #include "flow.h"
45 #include "ofp-print.h"
46 #include "openflow.h"
47 #include "poll-loop.h"
48 #include "random.h"
49 #include "util.h"
50
51 #define THIS_MODULE VLM_vconn
52 #include "vlog.h"
53
54 static struct vconn_class *vconn_classes[] = {
55     &tcp_vconn_class,
56     &unix_vconn_class,
57 #ifdef HAVE_NETLINK
58     &netlink_vconn_class,
59 #endif
60 #ifdef HAVE_OPENSSL
61     &ssl_vconn_class,
62 #endif
63 };
64
65 static struct pvconn_class *pvconn_classes[] = {
66     &ptcp_pvconn_class,
67     &punix_pvconn_class,
68 #ifdef HAVE_OPENSSL
69     &pssl_pvconn_class,
70 #endif
71 };
72
73 /* High rate limit because most of the rate-limiting here is individual
74  * OpenFlow messages going over the vconn.  If those are enabled then we
75  * really need to see them. */
76 static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(600, 600);
77
78 /* Check the validity of the vconn class structures. */
79 static void
80 check_vconn_classes(void)
81 {
82 #ifndef NDEBUG
83     size_t i;
84
85     for (i = 0; i < ARRAY_SIZE(vconn_classes); i++) {
86         struct vconn_class *class = vconn_classes[i];
87         assert(class->name != NULL);
88         assert(class->open != NULL);
89         if (class->close || class->recv || class->send || class->wait) {
90             assert(class->close != NULL);
91             assert(class->recv != NULL);
92             assert(class->send != NULL);
93             assert(class->wait != NULL);
94         } else {
95             /* This class delegates to another one. */
96         }
97     }
98
99     for (i = 0; i < ARRAY_SIZE(pvconn_classes); i++) {
100         struct pvconn_class *class = pvconn_classes[i];
101         assert(class->name != NULL);
102         assert(class->listen != NULL);
103         if (class->close || class->accept || class->wait) {
104             assert(class->close != NULL);
105             assert(class->accept != NULL);
106             assert(class->wait != NULL);
107         } else {
108             /* This class delegates to another one. */
109         }
110     }
111 #endif
112 }
113
114 /* Prints information on active (if 'active') and passive (if 'passive')
115  * connection methods supported by the vconn. */
116 void
117 vconn_usage(bool active, bool passive)
118 {
119     /* Really this should be implemented via callbacks into the vconn
120      * providers, but that seems too heavy-weight to bother with at the
121      * moment. */
122     
123     printf("\n");
124     if (active) {
125         printf("Active OpenFlow connection methods:\n");
126 #ifdef HAVE_NETLINK
127         printf("  nl:DP_IDX               "
128                "local datapath DP_IDX\n");
129 #endif
130         printf("  tcp:HOST[:PORT]         "
131                "PORT (default: %d) on remote TCP HOST\n", OFP_TCP_PORT);
132 #ifdef HAVE_OPENSSL
133         printf("  ssl:HOST[:PORT]         "
134                "SSL PORT (default: %d) on remote HOST\n", OFP_SSL_PORT);
135 #endif
136         printf("  unix:FILE               Unix domain socket named FILE\n");
137     }
138
139     if (passive) {
140         printf("Passive OpenFlow connection methods:\n");
141         printf("  ptcp:[PORT]             "
142                "listen to TCP PORT (default: %d)\n",
143                OFP_TCP_PORT);
144 #ifdef HAVE_OPENSSL
145         printf("  pssl:[PORT]             "
146                "listen for SSL on PORT (default: %d)\n",
147                OFP_SSL_PORT);
148 #endif
149         printf("  punix:FILE              "
150                "listen on Unix domain socket FILE\n");
151     }
152
153 #ifdef HAVE_OPENSSL
154     printf("PKI configuration (required to use SSL):\n"
155            "  -p, --private-key=FILE  file with private key\n"
156            "  -c, --certificate=FILE  file with certificate for private key\n"
157            "  -C, --ca-cert=FILE      file with peer CA certificate\n");
158 #endif
159 }
160
161 /* Attempts to connect to an OpenFlow device.  'name' is a connection name in
162  * the form "TYPE:ARGS", where TYPE is an active vconn class's name and ARGS
163  * are vconn class-specific.
164  *
165  * Returns 0 if successful, otherwise a positive errno value.  If successful,
166  * stores a pointer to the new connection in '*vconnp', otherwise a null
167  * pointer.  */
168 int
169 vconn_open(const char *name, struct vconn **vconnp)
170 {
171     size_t prefix_len;
172     size_t i;
173
174     check_vconn_classes();
175
176     *vconnp = NULL;
177     prefix_len = strcspn(name, ":");
178     if (prefix_len == strlen(name)) {
179         return EAFNOSUPPORT;
180     }
181     for (i = 0; i < ARRAY_SIZE(vconn_classes); i++) {
182         struct vconn_class *class = vconn_classes[i];
183         if (strlen(class->name) == prefix_len
184             && !memcmp(class->name, name, prefix_len)) {
185             struct vconn *vconn;
186             char *suffix_copy = xstrdup(name + prefix_len + 1);
187             int retval = class->open(name, suffix_copy, &vconn);
188             free(suffix_copy);
189             if (!retval) {
190                 assert(vconn->connect_status != EAGAIN
191                        || vconn->class->connect);
192                 *vconnp = vconn;
193             }
194             return retval;
195         }
196     }
197     return EAFNOSUPPORT;
198 }
199
200 int
201 vconn_open_block(const char *name, struct vconn **vconnp)
202 {
203     struct vconn *vconn;
204     int error;
205
206     error = vconn_open(name, &vconn);
207     while (error == EAGAIN) {
208         vconn_connect_wait(vconn);
209         poll_block();
210         error = vconn_connect(vconn);
211         assert(error != EINPROGRESS);
212     }
213     if (error) {
214         vconn_close(vconn);
215         *vconnp = NULL;
216     } else {
217         *vconnp = vconn;
218     }
219     return error;
220 }
221
222 /* Closes 'vconn'. */
223 void
224 vconn_close(struct vconn *vconn)
225 {
226     if (vconn != NULL) {
227         char *name = vconn->name;
228         (vconn->class->close)(vconn);
229         free(name);
230     }
231 }
232
233 /* Returns the name of 'vconn', that is, the string passed to vconn_open(). */
234 const char *
235 vconn_get_name(const struct vconn *vconn)
236 {
237     return vconn->name;
238 }
239
240 /* Returns the IP address of the peer, or 0 if the peer is not connected over
241  * an IP-based protocol or if its IP address is not yet known. */
242 uint32_t
243 vconn_get_ip(const struct vconn *vconn) 
244 {
245     return vconn->ip;
246 }
247
248 /* Tries to complete the connection on 'vconn', which must be an active
249  * vconn.  If 'vconn''s connection is complete, returns 0 if the connection
250  * was successful or a positive errno value if it failed.  If the
251  * connection is still in progress, returns EAGAIN. */
252 int
253 vconn_connect(struct vconn *vconn)
254 {
255     if (vconn->connect_status == EAGAIN) {
256         vconn->connect_status = (vconn->class->connect)(vconn);
257         assert(vconn->connect_status != EINPROGRESS);
258     }
259     return vconn->connect_status;
260 }
261
262 /* Tries to receive an OpenFlow message from 'vconn', which must be an active
263  * vconn.  If successful, stores the received message into '*msgp' and returns
264  * 0.  The caller is responsible for destroying the message with
265  * buffer_delete().  On failure, returns a positive errno value and stores a
266  * null pointer into '*msgp'.  On normal connection close, returns EOF.
267  *
268  * vconn_recv will not block waiting for a packet to arrive.  If no packets
269  * have been received, it returns EAGAIN immediately. */
270 int
271 vconn_recv(struct vconn *vconn, struct buffer **msgp)
272 {
273     int retval = vconn_connect(vconn);
274     if (!retval) {
275         retval = (vconn->class->recv)(vconn, msgp);
276         if (!retval) {
277             struct ofp_header *oh;
278
279             if (VLOG_IS_DBG_ENABLED()) {
280                 char *s = ofp_to_string((*msgp)->data, (*msgp)->size, 1);
281                 VLOG_DBG_RL(&rl, "%s: received: %s", vconn->name, s);
282                 free(s);
283             }
284
285             oh = buffer_at_assert(*msgp, 0, sizeof *oh);
286             if (oh->version != OFP_VERSION) {
287                 VLOG_ERR_RL(&rl, "%s: received OpenFlow version %02"PRIx8" "
288                             "!= expected %02x",
289                             vconn->name, oh->version, OFP_VERSION);
290                 buffer_delete(*msgp);
291                 *msgp = NULL;
292                 return EPROTO;
293             }
294         }
295     }
296     if (retval) {
297         *msgp = NULL;
298     }
299     return retval;
300 }
301
302 /* Tries to queue 'msg' for transmission on 'vconn', which must be an active
303  * vconn.  If successful, returns 0, in which case ownership of 'msg' is
304  * transferred to the vconn.  Success does not guarantee that 'msg' has been or
305  * ever will be delivered to the peer, only that it has been queued for
306  * transmission.
307  *
308  * Returns a positive errno value on failure, in which case the caller
309  * retains ownership of 'msg'.
310  *
311  * vconn_send will not block.  If 'msg' cannot be immediately accepted for
312  * transmission, it returns EAGAIN immediately. */
313 int
314 vconn_send(struct vconn *vconn, struct buffer *msg)
315 {
316     int retval = vconn_connect(vconn);
317     if (!retval) {
318         assert(msg->size >= sizeof(struct ofp_header));
319         assert(((struct ofp_header *) msg->data)->length == htons(msg->size));
320         if (!VLOG_IS_DBG_ENABLED()) { 
321             retval = (vconn->class->send)(vconn, msg);
322         } else {
323             char *s = ofp_to_string(msg->data, msg->size, 1);
324             retval = (vconn->class->send)(vconn, msg);
325             if (retval != EAGAIN) {
326                 VLOG_DBG_RL(&rl, "%s: sent (%s): %s", vconn->name, strerror(retval), s);
327             }
328             free(s);
329         }
330     }
331     return retval;
332 }
333
334 /* Same as vconn_send, except that it waits until 'msg' can be transmitted. */
335 int
336 vconn_send_block(struct vconn *vconn, struct buffer *msg)
337 {
338     int retval;
339     while ((retval = vconn_send(vconn, msg)) == EAGAIN) {
340         vconn_send_wait(vconn);
341         poll_block();
342     }
343     return retval;
344 }
345
346 /* Same as vconn_recv, except that it waits until a message is received. */
347 int
348 vconn_recv_block(struct vconn *vconn, struct buffer **msgp)
349 {
350     int retval;
351     while ((retval = vconn_recv(vconn, msgp)) == EAGAIN) {
352         vconn_recv_wait(vconn);
353         poll_block();
354     }
355     return retval;
356 }
357
358 /* Sends 'request' to 'vconn' and blocks until it receives a reply with a
359  * matching transaction ID.  Returns 0 if successful, in which case the reply
360  * is stored in '*replyp' for the caller to examine and free.  Otherwise
361  * returns a positive errno value, or EOF, and sets '*replyp' to null.
362  *
363  * 'request' is always destroyed, regardless of the return value. */
364 int
365 vconn_transact(struct vconn *vconn, struct buffer *request,
366                struct buffer **replyp)
367 {
368     uint32_t send_xid = ((struct ofp_header *) request->data)->xid;
369     int error;
370
371     *replyp = NULL;
372     error = vconn_send_block(vconn, request);
373     if (error) {
374         buffer_delete(request);
375         return error;
376     }
377     for (;;) {
378         uint32_t recv_xid;
379         struct buffer *reply;
380
381         error = vconn_recv_block(vconn, &reply);
382         if (error) {
383             return error;
384         }
385         recv_xid = ((struct ofp_header *) reply->data)->xid;
386         if (send_xid == recv_xid) {
387             *replyp = reply;
388             return 0;
389         }
390
391         VLOG_DBG_RL(&rl, "%s: received reply with xid %08"PRIx32" != expected "
392                     "%08"PRIx32, vconn->name, recv_xid, send_xid);
393         buffer_delete(reply);
394     }
395 }
396
397 void
398 vconn_wait(struct vconn *vconn, enum vconn_wait_type wait)
399 {
400     int connect_status;
401
402     assert(wait == WAIT_CONNECT || wait == WAIT_RECV || wait == WAIT_SEND);
403
404     connect_status = vconn_connect(vconn);
405     if (connect_status) {
406         if (connect_status == EAGAIN) {
407             wait = WAIT_CONNECT;
408         } else {
409             poll_immediate_wake();
410             return;
411         }
412     }
413
414     (vconn->class->wait)(vconn, wait);
415 }
416
417 void
418 vconn_connect_wait(struct vconn *vconn)
419 {
420     vconn_wait(vconn, WAIT_CONNECT);
421 }
422
423 void
424 vconn_recv_wait(struct vconn *vconn)
425 {
426     vconn_wait(vconn, WAIT_RECV);
427 }
428
429 void
430 vconn_send_wait(struct vconn *vconn)
431 {
432     vconn_wait(vconn, WAIT_SEND);
433 }
434
435 /* Attempts to start listening for OpenFlow connections.  'name' is a
436  * connection name in the form "TYPE:ARGS", where TYPE is an passive vconn
437  * class's name and ARGS are vconn class-specific.
438  *
439  * Returns 0 if successful, otherwise a positive errno value.  If successful,
440  * stores a pointer to the new connection in '*pvconnp', otherwise a null
441  * pointer.  */
442 int
443 pvconn_open(const char *name, struct pvconn **pvconnp)
444 {
445     size_t prefix_len;
446     size_t i;
447
448     check_vconn_classes();
449
450     *pvconnp = NULL;
451     prefix_len = strcspn(name, ":");
452     if (prefix_len == strlen(name)) {
453         return EAFNOSUPPORT;
454     }
455     for (i = 0; i < ARRAY_SIZE(pvconn_classes); i++) {
456         struct pvconn_class *class = pvconn_classes[i];
457         if (strlen(class->name) == prefix_len
458             && !memcmp(class->name, name, prefix_len)) {
459             char *suffix_copy = xstrdup(name + prefix_len + 1);
460             int retval = class->listen(name, suffix_copy, pvconnp);
461             free(suffix_copy);
462             if (retval) {
463                 *pvconnp = NULL;
464             }
465             return retval;
466         }
467     }
468     return EAFNOSUPPORT;
469 }
470
471 /* Closes 'pvconn'. */
472 void
473 pvconn_close(struct pvconn *pvconn)
474 {
475     if (pvconn != NULL) {
476         char *name = pvconn->name;
477         (pvconn->class->close)(pvconn);
478         free(name);
479     }
480 }
481
482 /* Tries to accept a new connection on 'pvconn'.  If successful, stores the new
483  * connection in '*new_vconn' and returns 0.  Otherwise, returns a positive
484  * errno value.
485  *
486  * pvconn_accept() will not block waiting for a connection.  If no connection
487  * is ready to be accepted, it returns EAGAIN immediately. */
488 int
489 pvconn_accept(struct pvconn *pvconn, struct vconn **new_vconn)
490 {
491     int retval = (pvconn->class->accept)(pvconn, new_vconn);
492     if (retval) {
493         *new_vconn = NULL;
494     } else {
495         assert((*new_vconn)->connect_status == 0
496                || (*new_vconn)->class->connect);
497     }
498     return retval;
499 }
500
501 void
502 pvconn_wait(struct pvconn *pvconn)
503 {
504     (pvconn->class->wait)(pvconn);
505 }
506
507 /* Allocates and returns the first byte of a buffer 'openflow_len' bytes long,
508  * containing an OpenFlow header with the given 'type' and a random transaction
509  * id.  Stores the new buffer in '*bufferp'.  The caller must free the buffer
510  * when it is no longer needed. */
511 void *
512 make_openflow(size_t openflow_len, uint8_t type, struct buffer **bufferp) 
513 {
514     return make_openflow_xid(openflow_len, type, random_uint32(), bufferp);
515 }
516
517 /* Allocates and returns the first byte of a buffer 'openflow_len' bytes long,
518  * containing an OpenFlow header with the given 'type' and transaction id
519  * 'xid'.  Stores the new buffer in '*bufferp'.  The caller must free the
520  * buffer when it is no longer needed. */
521 void *
522 make_openflow_xid(size_t openflow_len, uint8_t type, uint32_t xid,
523                   struct buffer **bufferp)
524 {
525     struct buffer *buffer;
526     struct ofp_header *oh;
527
528     assert(openflow_len >= sizeof *oh);
529     assert(openflow_len <= UINT16_MAX);
530     buffer = *bufferp = buffer_new(openflow_len);
531     oh = buffer_put_uninit(buffer, openflow_len);
532     memset(oh, 0, openflow_len);
533     oh->version = OFP_VERSION;
534     oh->type = type;
535     oh->length = htons(openflow_len);
536     oh->xid = xid;
537     return oh;
538 }
539
540 /* Updates the 'length' field of the OpenFlow message in 'buffer' to
541  * 'buffer->size'. */
542 void
543 update_openflow_length(struct buffer *buffer) 
544 {
545     struct ofp_header *oh = buffer_at_assert(buffer, 0, sizeof *oh);
546     oh->length = htons(buffer->size); 
547 }
548
549 struct buffer *
550 make_add_flow(const struct flow *flow, uint32_t buffer_id,
551               uint16_t idle_timeout, size_t n_actions)
552 {
553     struct ofp_flow_mod *ofm;
554     size_t size = sizeof *ofm + n_actions * sizeof ofm->actions[0];
555     struct buffer *out = buffer_new(size);
556     ofm = buffer_put_uninit(out, size);
557     memset(ofm, 0, size);
558     ofm->header.version = OFP_VERSION;
559     ofm->header.type = OFPT_FLOW_MOD;
560     ofm->header.length = htons(size);
561     ofm->match.wildcards = htonl(0);
562     ofm->match.in_port = flow->in_port;
563     memcpy(ofm->match.dl_src, flow->dl_src, sizeof ofm->match.dl_src);
564     memcpy(ofm->match.dl_dst, flow->dl_dst, sizeof ofm->match.dl_dst);
565     ofm->match.dl_vlan = flow->dl_vlan;
566     ofm->match.dl_type = flow->dl_type;
567     ofm->match.nw_src = flow->nw_src;
568     ofm->match.nw_dst = flow->nw_dst;
569     ofm->match.nw_proto = flow->nw_proto;
570     ofm->match.tp_src = flow->tp_src;
571     ofm->match.tp_dst = flow->tp_dst;
572     ofm->command = htons(OFPFC_ADD);
573     ofm->idle_timeout = htons(idle_timeout);
574     ofm->hard_timeout = htons(OFP_FLOW_PERMANENT);
575     ofm->buffer_id = htonl(buffer_id);
576     return out;
577 }
578
579 struct buffer *
580 make_add_simple_flow(const struct flow *flow,
581                      uint32_t buffer_id, uint16_t out_port,
582                      uint16_t idle_timeout)
583 {
584     struct buffer *buffer = make_add_flow(flow, buffer_id, idle_timeout, 1);
585     struct ofp_flow_mod *ofm = buffer->data;
586     ofm->actions[0].type = htons(OFPAT_OUTPUT);
587     ofm->actions[0].arg.output.max_len = htons(0);
588     ofm->actions[0].arg.output.port = htons(out_port);
589     return buffer;
590 }
591
592 struct buffer *
593 make_unbuffered_packet_out(const struct buffer *packet,
594                            uint16_t in_port, uint16_t out_port)
595 {
596     struct ofp_packet_out *opo;
597     size_t size = sizeof *opo + sizeof opo->actions[0];
598     struct buffer *out = buffer_new(size + packet->size);
599     opo = buffer_put_uninit(out, size);
600     memset(opo, 0, size);
601     opo->header.version = OFP_VERSION;
602     opo->header.type = OFPT_PACKET_OUT;
603     opo->buffer_id = htonl(UINT32_MAX);
604     opo->in_port = htons(in_port);
605     opo->n_actions = htons(1);
606     opo->actions[0].type = htons(OFPAT_OUTPUT);
607     opo->actions[0].arg.output.max_len = htons(0);
608     opo->actions[0].arg.output.port = htons(out_port);
609     buffer_put(out, packet->data, packet->size);
610     update_openflow_length(out);
611     return out;
612 }
613
614 struct buffer *
615 make_buffered_packet_out(uint32_t buffer_id,
616                          uint16_t in_port, uint16_t out_port)
617 {
618     struct ofp_packet_out *opo;
619     size_t size = sizeof *opo + sizeof opo->actions[0];
620     struct buffer *out = buffer_new(size);
621     opo = buffer_put_uninit(out, size);
622     memset(opo, 0, size);
623     opo->header.version = OFP_VERSION;
624     opo->header.type = OFPT_PACKET_OUT;
625     opo->header.length = htons(size);
626     opo->buffer_id = htonl(buffer_id);
627     opo->in_port = htons(in_port);
628     opo->n_actions = htons(1);
629     opo->actions[0].type = htons(OFPAT_OUTPUT);
630     opo->actions[0].arg.output.max_len = htons(0);
631     opo->actions[0].arg.output.port = htons(out_port);
632     return out;
633 }
634
635 /* Creates and returns an OFPT_ECHO_REQUEST message with an empty payload. */
636 struct buffer *
637 make_echo_request(void)
638 {
639     struct ofp_header *rq;
640     struct buffer *out = buffer_new(sizeof *rq);
641     rq = buffer_put_uninit(out, sizeof *rq);
642     rq->version = OFP_VERSION;
643     rq->type = OFPT_ECHO_REQUEST;
644     rq->length = htons(sizeof *rq);
645     rq->xid = 0;
646     return out;
647 }
648
649 /* Creates and returns an OFPT_ECHO_REPLY message matching the
650  * OFPT_ECHO_REQUEST message in 'rq'. */
651 struct buffer *
652 make_echo_reply(const struct ofp_header *rq)
653 {
654     size_t size = ntohs(rq->length);
655     struct buffer *out = buffer_new(size);
656     struct ofp_header *reply = buffer_put(out, rq, size);
657     reply->type = OFPT_ECHO_REPLY;
658     return out;
659 }
660
661 void
662 vconn_init(struct vconn *vconn, struct vconn_class *class, int connect_status,
663            uint32_t ip, const char *name)
664 {
665     vconn->class = class;
666     vconn->connect_status = connect_status;
667     vconn->ip = ip;
668     vconn->name = xstrdup(name);
669 }
670
671 void
672 pvconn_init(struct pvconn *pvconn, struct pvconn_class *class,
673             const char *name)
674 {
675     pvconn->class = class;
676     pvconn->name = xstrdup(name);
677 }