Coverage Report

Created: 2023-03-26 07:41

/src/openvswitch/lib/stream-provider.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (c) 2009, 2010, 2012, 2013, 2015 Nicira, Inc.
3
 *
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:
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
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.
15
 */
16
17
#ifndef STREAM_PROVIDER_H
18
#define STREAM_PROVIDER_H 1
19
20
#include <sys/types.h>
21
#include "ovs-replay.h"
22
#include "stream.h"
23
24
/* Active stream connection. */
25
26
/* Active stream connection.
27
 *
28
 * This structure should be treated as opaque by implementation. */
29
struct stream {
30
    const struct stream_class *class;
31
    int state;
32
    int error;
33
    replay_file_t replay_wfd;
34
    char *name;
35
    char *peer_id;
36
};
37
38
void stream_init(struct stream *, const struct stream_class *,
39
                 int connect_status, char *name);
40
static inline void stream_assert_class(const struct stream *stream,
41
                                       const struct stream_class *class)
42
0
{
43
0
    ovs_assert(stream->class == class);
44
0
}
Unexecuted instantiation: unixctl.c:stream_assert_class
Unexecuted instantiation: stream.c:stream_assert_class
Unexecuted instantiation: stream-unix.c:stream_assert_class
Unexecuted instantiation: stream-ssl.c:stream_assert_class
Unexecuted instantiation: stream-fd.c:stream_assert_class
Unexecuted instantiation: stream-replay.c:stream_assert_class
Unexecuted instantiation: stream-tcp.c:stream_assert_class
45
46
struct stream_class {
47
    /* Prefix for connection names, e.g. "tcp", "ssl", "unix". */
48
    const char *name;
49
50
    /* True if this stream needs periodic probes to verify connectivity.  For
51
     * streams which need probes, it can take a long time to notice the
52
     * connection was dropped. */
53
    bool needs_probes;
54
55
    /* Attempts to connect to a peer.  'name' is the full connection name
56
     * provided by the user, e.g. "tcp:1.2.3.4".  This name is useful for error
57
     * messages but must not be modified.
58
     *
59
     * 'suffix' is a copy of 'name' following the colon and may be modified.
60
     * 'dscp' is the DSCP value that the new connection should use in the IP
61
     * packets it sends.
62
     *
63
     * Returns 0 if successful, otherwise a positive errno value.  If
64
     * successful, stores a pointer to the new connection in '*streamp'.
65
     *
66
     * The open function must not block waiting for a connection to complete.
67
     * If the connection cannot be completed immediately, it should return
68
     * EAGAIN (not EINPROGRESS, as returned by the connect system call) and
69
     * continue the connection in the background. */
70
    int (*open)(const char *name, char *suffix, struct stream **streamp,
71
                uint8_t dscp);
72
73
    /* Closes 'stream' and frees associated memory. */
74
    void (*close)(struct stream *stream);
75
76
    /* Tries to complete the connection on 'stream'.  If 'stream''s connection
77
     * is complete, returns 0 if the connection was successful or a positive
78
     * errno value if it failed.  If the connection is still in progress,
79
     * returns EAGAIN.
80
     *
81
     * The connect function must not block waiting for the connection to
82
     * complete; instead, it should return EAGAIN immediately. */
83
    int (*connect)(struct stream *stream);
84
85
    /* Tries to receive up to 'n' bytes from 'stream' into 'buffer', and
86
     * returns:
87
     *
88
     *     - If successful, the number of bytes received (between 1 and 'n').
89
     *
90
     *     - On error, a negative errno value.
91
     *
92
     *     - 0, if the connection has been closed in the normal fashion.
93
     *
94
     * The recv function will not be passed a zero 'n'.
95
     *
96
     * The recv function must not block waiting for data to arrive.  If no data
97
     * have been received, it should return -EAGAIN immediately. */
98
    ssize_t (*recv)(struct stream *stream, void *buffer, size_t n);
99
100
    /* Tries to send up to 'n' bytes of 'buffer' on 'stream', and returns:
101
     *
102
     *     - If successful, the number of bytes sent (between 1 and 'n').
103
     *
104
     *     - On error, a negative errno value.
105
     *
106
     *     - Never returns 0.
107
     *
108
     * The send function will not be passed a zero 'n'.
109
     *
110
     * The send function must not block.  If no bytes can be immediately
111
     * accepted for transmission, it should return -EAGAIN immediately. */
112
    ssize_t (*send)(struct stream *stream, const void *buffer, size_t n);
113
114
    /* Allows 'stream' to perform maintenance activities, such as flushing
115
     * output buffers.
116
     *
117
     * May be null if 'stream' doesn't have anything to do here. */
118
    void (*run)(struct stream *stream);
119
120
    /* Arranges for the poll loop to wake up when 'stream' needs to perform
121
     * maintenance activities.
122
     *
123
     * May be null if 'stream' doesn't have anything to do here. */
124
    void (*run_wait)(struct stream *stream);
125
126
    /* Arranges for the poll loop to wake up when 'stream' is ready to take an
127
     * action of the given 'type'. */
128
    void (*wait)(struct stream *stream, enum stream_wait_type type);
129
};
130

131
/* Passive listener for incoming stream connections.
132
 *
133
 * This structure should be treated as opaque by stream implementations. */
134
struct pstream {
135
    const struct pstream_class *class;
136
    char *name;
137
    ovs_be16 bound_port;
138
    replay_file_t replay_wfd;
139
};
140
141
void pstream_init(struct pstream *, const struct pstream_class *, char *name);
142
void pstream_set_bound_port(struct pstream *, ovs_be16 bound_port);
143
static inline void pstream_assert_class(const struct pstream *pstream,
144
                                        const struct pstream_class *class)
145
0
{
146
0
    ovs_assert(pstream->class == class);
147
0
}
Unexecuted instantiation: unixctl.c:pstream_assert_class
Unexecuted instantiation: stream.c:pstream_assert_class
Unexecuted instantiation: stream-unix.c:pstream_assert_class
Unexecuted instantiation: stream-ssl.c:pstream_assert_class
Unexecuted instantiation: stream-fd.c:pstream_assert_class
Unexecuted instantiation: stream-replay.c:pstream_assert_class
Unexecuted instantiation: stream-tcp.c:pstream_assert_class
148
149
struct pstream_class {
150
    /* Prefix for connection names, e.g. "ptcp", "pssl", "punix". */
151
    const char *name;
152
153
    /* True if this pstream needs periodic probes to verify connectivity.  For
154
     * pstreams which need probes, it can take a long time to notice the
155
     * connection was dropped. */
156
    bool needs_probes;
157
158
    /* Attempts to start listening for stream connections.  'name' is the full
159
     * connection name provided by the user, e.g. "ptcp:1234".  This name is
160
     * useful for error messages but must not be modified.
161
     *
162
     * 'suffix' is a copy of 'name' following the colon and may be modified.
163
     * 'dscp' is the DSCP value that the new connection should use in the IP
164
     * packets it sends.
165
     *
166
     * Returns 0 if successful, otherwise a positive errno value.  If
167
     * successful, stores a pointer to the new connection in '*pstreamp'.
168
     *
169
     * The listen function must not block.  If the connection cannot be
170
     * completed immediately, it should return EAGAIN (not EINPROGRESS, as
171
     * returned by the connect system call) and continue the connection in the
172
     * background. */
173
    int (*listen)(const char *name, char *suffix, struct pstream **pstreamp,
174
                  uint8_t dscp);
175
176
    /* Closes 'pstream' and frees associated memory. */
177
    void (*close)(struct pstream *pstream);
178
179
    /* Tries to accept a new connection on 'pstream'.  If successful, stores
180
     * the new connection in '*new_streamp' and returns 0.  Otherwise, returns
181
     * a positive errno value.
182
     *
183
     * The accept function must not block waiting for a connection.  If no
184
     * connection is ready to be accepted, it should return EAGAIN. */
185
    int (*accept)(struct pstream *pstream, struct stream **new_streamp);
186
187
    /* Arranges for the poll loop to wake up when a connection is ready to be
188
     * accepted on 'pstream'. */
189
    void (*wait)(struct pstream *pstream);
190
};
191
192
/* Active and passive stream classes. */
193
extern const struct stream_class tcp_stream_class;
194
extern const struct pstream_class ptcp_pstream_class;
195
#ifndef _WIN32
196
extern const struct stream_class unix_stream_class;
197
extern const struct pstream_class punix_pstream_class;
198
#else
199
extern const struct stream_class windows_stream_class;
200
extern const struct pstream_class pwindows_pstream_class;
201
#endif
202
#ifdef HAVE_OPENSSL
203
extern const struct stream_class ssl_stream_class;
204
extern const struct pstream_class pssl_pstream_class;
205
#endif
206
extern const struct stream_class replay_stream_class;
207
extern const struct pstream_class preplay_pstream_class;
208
209
#endif /* stream-provider.h */