~james-page/ubuntu/saucy/openvswitch/1.12-snapshot

« back to all changes in this revision

Viewing changes to lib/vconn.c

  • Committer: James Page
  • Date: 2013-08-21 10:16:57 UTC
  • mfrom: (1.1.20)
  • Revision ID: james.page@canonical.com-20130821101657-3o0z0qeiv5zkwlzi
New upstream snapshot

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
    VCS_DISCONNECTED            /* Connection failed or connection closed. */
60
60
};
61
61
 
62
 
static struct vconn_class *vconn_classes[] = {
 
62
static const struct vconn_class *vconn_classes[] = {
63
63
    &tcp_vconn_class,
64
64
    &unix_vconn_class,
65
65
#ifdef HAVE_OPENSSL
67
67
#endif
68
68
};
69
69
 
70
 
static struct pvconn_class *pvconn_classes[] = {
 
70
static const struct pvconn_class *pvconn_classes[] = {
71
71
    &ptcp_pvconn_class,
72
72
    &punix_pvconn_class,
73
73
#ifdef HAVE_OPENSSL
95
95
    size_t i;
96
96
 
97
97
    for (i = 0; i < ARRAY_SIZE(vconn_classes); i++) {
98
 
        struct vconn_class *class = vconn_classes[i];
 
98
        const struct vconn_class *class = vconn_classes[i];
99
99
        ovs_assert(class->name != NULL);
100
100
        ovs_assert(class->open != NULL);
101
101
        if (class->close || class->recv || class->send
110
110
    }
111
111
 
112
112
    for (i = 0; i < ARRAY_SIZE(pvconn_classes); i++) {
113
 
        struct pvconn_class *class = pvconn_classes[i];
 
113
        const struct pvconn_class *class = pvconn_classes[i];
114
114
        ovs_assert(class->name != NULL);
115
115
        ovs_assert(class->listen != NULL);
116
116
        if (class->close || class->accept || class->wait) {
177
177
 * a null pointer into '*classp' if 'name' is in the wrong form or if no such
178
178
 * class exists. */
179
179
static int
180
 
vconn_lookup_class(const char *name, struct vconn_class **classp)
 
180
vconn_lookup_class(const char *name, const struct vconn_class **classp)
181
181
{
182
182
    size_t prefix_len;
183
183
 
186
186
        size_t i;
187
187
 
188
188
        for (i = 0; i < ARRAY_SIZE(vconn_classes); i++) {
189
 
            struct vconn_class *class = vconn_classes[i];
 
189
            const struct vconn_class *class = vconn_classes[i];
190
190
            if (strlen(class->name) == prefix_len
191
191
                && !memcmp(class->name, name, prefix_len)) {
192
192
                *classp = class;
204
204
int
205
205
vconn_verify_name(const char *name)
206
206
{
207
 
    struct vconn_class *class;
 
207
    const struct vconn_class *class;
208
208
    return vconn_lookup_class(name, &class);
209
209
}
210
210
 
225
225
vconn_open(const char *name, uint32_t allowed_versions, uint8_t dscp,
226
226
           struct vconn **vconnp)
227
227
{
228
 
    struct vconn_class *class;
 
228
    const struct vconn_class *class;
229
229
    struct vconn *vconn;
230
230
    char *suffix_copy;
231
231
    int error;
461
461
    } else if (is_pow2((bitmap >> 1) + 1)) {
462
462
        ds_put_cstr(&s, "version ");
463
463
        ofputil_format_version(&s, leftmost_1bit_idx(bitmap));
464
 
        ds_put_cstr(&s, "and earlier");
 
464
        ds_put_cstr(&s, " and earlier");
465
465
    } else {
466
466
        ds_put_cstr(&s, "versions ");
467
467
        ofputil_format_version_bitmap(&s, bitmap);
695
695
        retval = (vconn->class->send)(vconn, msg);
696
696
        if (retval != EAGAIN) {
697
697
            VLOG_DBG_RL(&ofmsg_rl, "%s: sent (%s): %s",
698
 
                        vconn->name, strerror(retval), s);
 
698
                        vconn->name, ovs_strerror(retval), s);
699
699
        }
700
700
        free(s);
701
701
    }
754
754
    return retval;
755
755
}
756
756
 
757
 
/* Waits until a message with a transaction ID matching 'xid' is recived on
 
757
/* Waits until a message with a transaction ID matching 'xid' is received on
758
758
 * 'vconn'.  Returns 0 if successful, in which case the reply is stored in
759
759
 * '*replyp' for the caller to examine and free.  Otherwise returns a positive
760
760
 * errno value, or EOF, and sets '*replyp' to null.
961
961
 * a null pointer into '*classp' if 'name' is in the wrong form or if no such
962
962
 * class exists. */
963
963
static int
964
 
pvconn_lookup_class(const char *name, struct pvconn_class **classp)
 
964
pvconn_lookup_class(const char *name, const struct pvconn_class **classp)
965
965
{
966
966
    size_t prefix_len;
967
967
 
970
970
        size_t i;
971
971
 
972
972
        for (i = 0; i < ARRAY_SIZE(pvconn_classes); i++) {
973
 
            struct pvconn_class *class = pvconn_classes[i];
 
973
            const struct pvconn_class *class = pvconn_classes[i];
974
974
            if (strlen(class->name) == prefix_len
975
975
                && !memcmp(class->name, name, prefix_len)) {
976
976
                *classp = class;
988
988
int
989
989
pvconn_verify_name(const char *name)
990
990
{
991
 
    struct pvconn_class *class;
 
991
    const struct pvconn_class *class;
992
992
    return pvconn_lookup_class(name, &class);
993
993
}
994
994
 
1009
1009
pvconn_open(const char *name, uint32_t allowed_versions, uint8_t dscp,
1010
1010
            struct pvconn **pvconnp)
1011
1011
{
1012
 
    struct pvconn_class *class;
 
1012
    const struct pvconn_class *class;
1013
1013
    struct pvconn *pvconn;
1014
1014
    char *suffix_copy;
1015
1015
    int error;
1109
1109
 *
1110
1110
 * The caller retains ownership of 'name'. */
1111
1111
void
1112
 
vconn_init(struct vconn *vconn, struct vconn_class *class, int connect_status,
1113
 
           const char *name, uint32_t allowed_versions)
 
1112
vconn_init(struct vconn *vconn, const struct vconn_class *class,
 
1113
           int connect_status, const char *name, uint32_t allowed_versions)
1114
1114
{
1115
1115
    memset(vconn, 0, sizeof *vconn);
1116
1116
    vconn->class = class;
1148
1148
}
1149
1149
 
1150
1150
void
1151
 
pvconn_init(struct pvconn *pvconn,  struct pvconn_class *class,
 
1151
pvconn_init(struct pvconn *pvconn, const struct pvconn_class *class,
1152
1152
            const char *name, uint32_t allowed_versions)
1153
1153
{
1154
1154
    pvconn->class = class;