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