libosmo-netif 1.4.0.35-6987.202403142026
Osmocom network interface library
stream.h
1#pragma once
2
3#include <stdbool.h>
4#include <stdint.h>
5#include <unistd.h>
6
7#include <osmocom/core/msgb.h>
8
14#define OSMO_STREAM_SCTP_MSG_FLAGS_NOTIFICATION 0x80 /* sctp_recvmsg() flags=MSG_NOTIFICATION, msgb_data() contains "union sctp_notification*" */
15#define msgb_sctp_msg_flags(msg) (msg)->cb[2]
16
18#define msgb_sctp_ppid(msg) (msg)->cb[3]
20#define msgb_sctp_stream(msg) (msg)->cb[4]
21
24
27
28void osmo_stream_srv_link_set_name(struct osmo_stream_srv_link *link, const char *name);
29const char *osmo_stream_srv_link_get_name(const struct osmo_stream_srv_link *link);
30void osmo_stream_srv_link_set_nodelay(struct osmo_stream_srv_link *link, bool nodelay);
31void osmo_stream_srv_link_set_addr(struct osmo_stream_srv_link *link, const char *addr);
32int osmo_stream_srv_link_set_addrs(struct osmo_stream_srv_link *link, const char **addr, size_t addrcnt);
33void osmo_stream_srv_link_set_port(struct osmo_stream_srv_link *link, uint16_t port);
34void osmo_stream_srv_link_set_proto(struct osmo_stream_srv_link *link, uint16_t proto);
35int osmo_stream_srv_link_set_type(struct osmo_stream_srv_link *link, int type);
36int osmo_stream_srv_link_set_domain(struct osmo_stream_srv_link *link, int domain);
37void osmo_stream_srv_link_set_accept_cb(struct osmo_stream_srv_link *link, int (*accept_cb)(struct osmo_stream_srv_link *link, int fd));
38void osmo_stream_srv_link_set_data(struct osmo_stream_srv_link *link, void *data);
41struct osmo_fd *osmo_stream_srv_link_get_ofd(struct osmo_stream_srv_link *link);
46
47enum osmo_stream_srv_link_param {
48 OSMO_STREAM_SRV_LINK_PAR_SCTP_SOCKOPT_AUTH_SUPPORTED, /* uint8_t: 0 disable, 1 enable, 2 force disable, 3 force enable */
49 OSMO_STREAM_SRV_LINK_PAR_SCTP_SOCKOPT_ASCONF_SUPPORTED, /* uint8_t: 0 disable, 1 enable, 2 force disable, 3 force enable */
50 OSMO_STREAM_SRV_LINK_PAR_SCTP_INIT_NUM_OSTREAMS, /* uint16_t: amount of streams */
51 OSMO_STREAM_SRV_LINK_PAR_SCTP_INIT_MAX_INSTREAMS, /* uint16_t: amount of streams */
52};
53
54int osmo_stream_srv_link_set_param(struct osmo_stream_srv_link *link, enum osmo_stream_srv_link_param par,
55 void *val, size_t val_len);
56
59struct osmo_stream_srv;
60
61struct osmo_stream_srv *osmo_stream_srv_create(void *ctx, struct osmo_stream_srv_link *link, int fd, int (*read_cb)(struct osmo_stream_srv *conn), int (*closed_cb)(struct osmo_stream_srv *conn), void *data);
62struct osmo_stream_srv *osmo_stream_srv_create2(void *ctx, struct osmo_stream_srv_link *link, int fd, void *data);
63void osmo_stream_srv_set_name(struct osmo_stream_srv *conn, const char *name);
64const char *osmo_stream_srv_get_name(const struct osmo_stream_srv *conn);
65void osmo_stream_srv_set_read_cb(struct osmo_stream_srv *conn, int (*read_cb)(struct osmo_stream_srv *conn, struct msgb *msg));
66void osmo_stream_srv_set_closed_cb(struct osmo_stream_srv *conn, int (*closed_cb)(struct osmo_stream_srv *conn));
69const char *osmo_stream_srv_get_sockname(const struct osmo_stream_srv *conn);
70struct osmo_fd *osmo_stream_srv_get_ofd(struct osmo_stream_srv *srv);
71int osmo_stream_srv_get_fd(const struct osmo_stream_srv *srv);
73
75void osmo_stream_srv_set_data(struct osmo_stream_srv *conn, void *data);
76
78 int (*segmentation_cb)(struct msgb *msg));
79
80void osmo_stream_srv_send(struct osmo_stream_srv *conn, struct msgb *msg);
81int osmo_stream_srv_recv(struct osmo_stream_srv *conn, struct msgb *msg);
82
83void osmo_stream_srv_clear_tx_queue(struct osmo_stream_srv *conn);
84
86struct osmo_stream_cli;
87
88void osmo_stream_cli_set_name(struct osmo_stream_cli *cli, const char *name);
89const char *osmo_stream_cli_get_name(const struct osmo_stream_cli *cli);
90void osmo_stream_cli_set_nodelay(struct osmo_stream_cli *cli, bool nodelay);
91void osmo_stream_cli_set_addr(struct osmo_stream_cli *cli, const char *addr);
92int osmo_stream_cli_set_addrs(struct osmo_stream_cli *cli, const char **addr, size_t addrcnt);
93void osmo_stream_cli_set_port(struct osmo_stream_cli *cli, uint16_t port);
94int osmo_stream_cli_set_type(struct osmo_stream_cli *cli, int type);
95int osmo_stream_cli_set_domain(struct osmo_stream_cli *cli, int domain);
96void osmo_stream_cli_set_proto(struct osmo_stream_cli *cli, uint16_t proto);
97void osmo_stream_cli_set_local_addr(struct osmo_stream_cli *cli, const char *addr);
98int osmo_stream_cli_set_local_addrs(struct osmo_stream_cli *cli, const char **addr, size_t addrcnt);
99void osmo_stream_cli_set_local_port(struct osmo_stream_cli *cli, uint16_t port);
100void osmo_stream_cli_set_data(struct osmo_stream_cli *cli, void *data);
101void osmo_stream_cli_set_reconnect_timeout(struct osmo_stream_cli *cli, int timeout);
103char *osmo_stream_cli_get_sockname(const struct osmo_stream_cli *cli);
104struct osmo_fd *osmo_stream_cli_get_ofd(struct osmo_stream_cli *cli);
105int osmo_stream_cli_get_fd(const struct osmo_stream_cli *cli);
106void osmo_stream_cli_set_connect_cb(struct osmo_stream_cli *cli, int (*connect_cb)(struct osmo_stream_cli *cli));
107void osmo_stream_cli_set_disconnect_cb(struct osmo_stream_cli *cli, int (*disconnect_cb)(struct osmo_stream_cli *cli));
108void osmo_stream_cli_set_read_cb(struct osmo_stream_cli *cli, int (*read_cb)(struct osmo_stream_cli *cli));
109void osmo_stream_cli_set_read_cb2(struct osmo_stream_cli *cli, int (*read_cb)(struct osmo_stream_cli *cli, struct msgb *msg));
110void osmo_stream_cli_set_segmentation_cb(struct osmo_stream_cli *cli, int (*segmentation_cb)(struct msgb *msg));
113
114struct osmo_stream_cli *osmo_stream_cli_create(void *ctx);
116
118int osmo_stream_cli_open2(struct osmo_stream_cli *cli, int reconnect) \
119 OSMO_DEPRECATED("Use osmo_stream_cli_set_reconnect_timeout() or osmo_stream_cli_reconnect() instead");
120void osmo_stream_cli_close(struct osmo_stream_cli *cli);
121
122void osmo_stream_cli_send(struct osmo_stream_cli *cli, struct msgb *msg);
123int osmo_stream_cli_recv(struct osmo_stream_cli *cli, struct msgb *msg);
124
125void osmo_stream_cli_clear_tx_queue(struct osmo_stream_cli *cli);
126
127enum osmo_stream_cli_param {
128 OSMO_STREAM_CLI_PAR_SCTP_SOCKOPT_AUTH_SUPPORTED, /* uint8_t: 0 disable, 1 enable, 2 force disable, 3 force enable */
129 OSMO_STREAM_CLI_PAR_SCTP_SOCKOPT_ASCONF_SUPPORTED, /* uint8_t: 0 disable, 1 enable, 2 force disable, 3 force enable */
130 OSMO_STREAM_CLI_PAR_SCTP_INIT_NUM_OSTREAMS, /* uint16_t: amount of streams */
131 OSMO_STREAM_CLI_PAR_SCTP_INIT_MAX_INSTREAMS, /* uint16_t: amount of streams */
132 OSMO_STREAM_CLI_PAR_SCTP_INIT_MAX_ATTEMPTS, /* uint16_t: amount of attempts */
133 OSMO_STREAM_CLI_PAR_SCTP_INIT_TIMEOUT, /* uint16_t: milliseconds */
134};
135
136int osmo_stream_cli_set_param(struct osmo_stream_cli *cli, enum osmo_stream_cli_param par,
137 void *val, size_t val_len);
138
void osmo_stream_cli_set_addr(struct osmo_stream_cli *cli, const char *addr)
Set the remote address to which we connect.
Definition: stream_cli.c:545
struct osmo_fd * osmo_stream_cli_get_ofd(struct osmo_stream_cli *cli)
Get Osmocom File Descriptor of the stream client socket.
Definition: stream_cli.c:750
int osmo_stream_cli_recv(struct osmo_stream_cli *cli, struct msgb *msg)
Receive data via an Osmocom stream client.
Definition: stream_cli.c:1056
int osmo_stream_cli_set_local_addrs(struct osmo_stream_cli *cli, const char **addr, size_t addrcnt)
Set the local address set to which we connect. Useful for protocols allowing bind to more than one ad...
Definition: stream_cli.c:613
const char * osmo_stream_cli_get_name(const struct osmo_stream_cli *cli)
Retrieve name previously set on the cli object (see osmo_stream_cli_set_name())
Definition: stream_cli.c:535
void osmo_stream_cli_reconnect(struct osmo_stream_cli *cli)
Re-connect an Osmocom Stream Client If re-connection is enabled for this client (which is the case un...
Definition: stream_cli.c:135
int osmo_stream_cli_open2(struct osmo_stream_cli *cli, int reconnect) OSMO_DEPRECATED("Use osmo_stream_cli_set_reconnect_timeout() or osmo_stream_cli_reconnect() instead")
DEPRECATED: use osmo_stream_cli_set_reconnect_timeout() or osmo_stream_cli_reconnect() instead!...
Definition: stream_cli.c:817
struct osmo_stream_cli * osmo_stream_cli_create(void *ctx)
Create an Osmocom stream client.
Definition: stream_cli.c:413
int osmo_stream_srv_link_set_type(struct osmo_stream_srv_link *link, int type)
Set the socket type for the stream server link.
Definition: stream_srv.c:298
void osmo_stream_srv_set_name(struct osmo_stream_srv *conn, const char *name)
Set a name on the srv object (used during logging)
Definition: stream_srv.c:870
void osmo_stream_srv_link_set_accept_cb(struct osmo_stream_srv_link *link, int(*accept_cb)(struct osmo_stream_srv_link *link, int fd))
Set the accept() call-back of the stream server link.
Definition: stream_srv.c:437
struct osmo_stream_srv * osmo_stream_srv_create(void *ctx, struct osmo_stream_srv_link *link, int fd, int(*read_cb)(struct osmo_stream_srv *conn), int(*closed_cb)(struct osmo_stream_srv *conn), void *data)
Create a Stream Server inside the specified link.
Definition: stream_srv.c:789
void osmo_stream_cli_set_disconnect_cb(struct osmo_stream_cli *cli, int(*disconnect_cb)(struct osmo_stream_cli *cli))
Set the call-back function called on disconnect of the stream client socket.
Definition: stream_cli.c:769
void osmo_stream_srv_link_set_proto(struct osmo_stream_srv_link *link, uint16_t proto)
Set the protocol for the stream server link.
Definition: stream_srv.c:285
void osmo_stream_srv_set_segmentation_cb(struct osmo_stream_srv *conn, int(*segmentation_cb)(struct msgb *msg))
Set the segmentation callback for target osmo_stream_srv structure. The connection has to have been e...
Definition: stream_srv.c:929
bool osmo_stream_srv_link_is_opened(const struct osmo_stream_srv_link *link)
Check whether the stream server link is opened.
Definition: stream_srv.c:509
int osmo_stream_cli_set_domain(struct osmo_stream_cli *cli, int domain)
Set the socket type for the stream server link.
Definition: stream_cli.c:691
void osmo_stream_srv_link_set_nodelay(struct osmo_stream_srv_link *link, bool nodelay)
Set the NODELAY socket option to avoid Nagle-like behavior Setting this to nodelay=true will automati...
Definition: stream_srv.c:226
struct osmo_fd * osmo_stream_srv_get_ofd(struct osmo_stream_srv *srv)
Get Osmocom File Descriptor of the stream server.
Definition: stream_srv.c:968
void osmo_stream_srv_destroy(struct osmo_stream_srv *conn)
Destroy given Stream Server This function closes the Stream Server socket, unregisters from select lo...
Definition: stream_srv.c:1006
void osmo_stream_cli_set_local_port(struct osmo_stream_cli *cli, uint16_t port)
Set the local port number for the socket (to be bound to)
Definition: stream_cli.c:591
const char * osmo_stream_srv_get_sockname(const struct osmo_stream_srv *conn)
Get the stream server socket description.
Definition: stream_srv.c:954
int osmo_stream_cli_set_type(struct osmo_stream_cli *cli, int type)
Set the socket type for the stream server link.
Definition: stream_cli.c:672
void osmo_stream_cli_set_data(struct osmo_stream_cli *cli, void *data)
Set application private data of the stream client socket.
Definition: stream_cli.c:720
void osmo_stream_srv_link_set_data(struct osmo_stream_srv_link *link, void *data)
Set application private data of the stream server link.
Definition: stream_srv.c:337
int osmo_stream_srv_link_open(struct osmo_stream_srv_link *link)
Open the stream server link. This actually initializes the underlying socket and binds it to the conf...
Definition: stream_srv.c:456
void * osmo_stream_cli_get_data(struct osmo_stream_cli *cli)
Get application private data of the stream client socket.
Definition: stream_cli.c:728
const char * osmo_stream_srv_link_get_name(const struct osmo_stream_srv_link *link)
Retrieve name previously set on the srv_link object (see osmo_stream_srv_link_set_name())
Definition: stream_srv.c:214
void osmo_stream_cli_set_local_addr(struct osmo_stream_cli *cli, const char *addr)
Set the local address for the socket (to be bound to)
Definition: stream_cli.c:602
void osmo_stream_srv_link_set_port(struct osmo_stream_srv_link *link, uint16_t port)
Set the local port number to which we bind.
Definition: stream_srv.c:273
void osmo_stream_srv_set_closed_cb(struct osmo_stream_srv *conn, int(*closed_cb)(struct osmo_stream_srv *conn))
Set the call-back function called when the stream server socket was closed.
Definition: stream_srv.c:899
bool osmo_stream_cli_is_connected(struct osmo_stream_cli *cli)
Check if Osmocom Stream Client is in connected state.
Definition: stream_cli.c:154
struct osmo_fd * osmo_stream_srv_link_get_ofd(struct osmo_stream_srv_link *link)
Get Osmocom File Descriptor of the stream server link.
Definition: stream_srv.c:421
char * osmo_stream_srv_link_get_sockname(const struct osmo_stream_srv_link *link)
Get description of the stream server link e. g. 127.0.0.1:1234.
Definition: stream_srv.c:408
int osmo_stream_srv_get_fd(const struct osmo_stream_srv *srv)
Get File Descriptor of the stream server.
Definition: stream_srv.c:978
void osmo_stream_srv_set_flush_and_destroy(struct osmo_stream_srv *conn)
Prepare to send out all pending messages on the connection's Tx queue and then automatically destroy ...
Definition: stream_srv.c:910
int osmo_stream_cli_open(struct osmo_stream_cli *cli)
Open connection of an Osmocom stream client By default the client will automatically reconnect after ...
Definition: stream_cli.c:890
void osmo_stream_srv_link_destroy(struct osmo_stream_srv_link *link)
Destroy the stream server link. Closes + Releases Memory.
Definition: stream_srv.c:446
struct osmo_stream_srv * osmo_stream_srv_create2(void *ctx, struct osmo_stream_srv_link *link, int fd, void *data)
Create a Stream Server inside the specified link.
Definition: stream_srv.c:827
void osmo_stream_cli_set_proto(struct osmo_stream_cli *cli, uint16_t proto)
Set the protocol for the stream client socket.
Definition: stream_cli.c:637
int osmo_stream_srv_link_set_domain(struct osmo_stream_srv_link *link, int domain)
Set the socket type for the stream server link.
Definition: stream_srv.c:317
void osmo_stream_srv_set_data(struct osmo_stream_srv *conn, void *data)
Set application private data of the stream server.
Definition: stream_srv.c:919
struct osmo_stream_srv_link * osmo_stream_srv_get_master(struct osmo_stream_srv *conn)
Get the master (Link) from a Stream Server.
Definition: stream_srv.c:995
void osmo_stream_cli_destroy(struct osmo_stream_cli *cli)
Destroy a Osmocom stream client (includes close)
Definition: stream_cli.c:803
void osmo_stream_srv_send(struct osmo_stream_srv *conn, struct msgb *msg)
Enqueue data to be sent via an Osmocom stream server.
Definition: stream_srv.c:1030
void osmo_stream_cli_set_nodelay(struct osmo_stream_cli *cli, bool nodelay)
Set the NODELAY socket option to avoid Nagle-like behavior Setting this to nodelay=true will automati...
Definition: stream_cli.c:877
int osmo_stream_cli_set_addrs(struct osmo_stream_cli *cli, const char **addr, size_t addrcnt)
Set the remote address set to which we connect. Useful for protocols allowing connecting to more than...
Definition: stream_cli.c:556
void osmo_stream_cli_send(struct osmo_stream_cli *cli, struct msgb *msg)
Enqueue data to be sent via an Osmocom stream client.
Definition: stream_cli.c:1008
struct osmo_stream_srv_link * osmo_stream_srv_link_create(void *ctx)
Create an Osmocom Stream Server Link A Stream Server Link is the listen()+accept() "parent" to indivi...
Definition: stream_srv.c:183
int osmo_stream_srv_link_set_addrs(struct osmo_stream_srv_link *link, const char **addr, size_t addrcnt)
Set the local address set to which we bind. Useful for protocols allowing bind on more than one addre...
Definition: stream_srv.c:250
void osmo_stream_cli_set_connect_cb(struct osmo_stream_cli *cli, int(*connect_cb)(struct osmo_stream_cli *cli))
Set the call-back function called on connect of the stream client socket.
Definition: stream_cli.c:760
void osmo_stream_cli_set_port(struct osmo_stream_cli *cli, uint16_t port)
Set the remote port number to which we connect.
Definition: stream_cli.c:580
void osmo_stream_srv_set_read_cb(struct osmo_stream_srv *conn, int(*read_cb)(struct osmo_stream_srv *conn, struct msgb *msg))
Set the call-back function when data was read from the stream server socket Only for osmo_stream_srv ...
Definition: stream_srv.c:890
int osmo_stream_srv_recv(struct osmo_stream_srv *conn, struct msgb *msg)
Receive data via Osmocom stream server.
Definition: stream_srv.c:1075
void * osmo_stream_srv_link_get_data(struct osmo_stream_srv_link *link)
Get application private data of the stream server link.
Definition: stream_srv.c:346
void osmo_stream_srv_link_set_addr(struct osmo_stream_srv_link *link, const char *addr)
Set the local address to which we bind.
Definition: stream_srv.c:238
void osmo_stream_cli_set_read_cb(struct osmo_stream_cli *cli, int(*read_cb)(struct osmo_stream_cli *cli))
Set the call-back function called to read from the stream client socket This function will configure ...
Definition: stream_cli.c:780
void osmo_stream_cli_close(struct osmo_stream_cli *cli)
Close an Osmocom Stream Client.
Definition: stream_cli.c:181
void osmo_stream_srv_link_close(struct osmo_stream_srv_link *link)
Close the stream server link and unregister from select loop Does not destroy the server link,...
Definition: stream_srv.c:523
const char * osmo_stream_srv_get_name(const struct osmo_stream_srv *conn)
Retrieve name previously set on the srv object (see osmo_stream_srv_set_name())
Definition: stream_srv.c:881
void osmo_stream_cli_set_read_cb2(struct osmo_stream_cli *cli, int(*read_cb)(struct osmo_stream_cli *cli, struct msgb *msg))
Set the call-back function called to read from the stream client socket This function will configure ...
Definition: stream_cli.c:793
void osmo_stream_cli_set_reconnect_timeout(struct osmo_stream_cli *cli, int timeout)
Set the reconnect time of the stream client socket.
Definition: stream_cli.c:711
void osmo_stream_srv_link_set_name(struct osmo_stream_srv_link *link, const char *name)
Set a name on the srv_link object (used during logging)
Definition: stream_srv.c:205
void * osmo_stream_srv_get_data(struct osmo_stream_srv *conn)
Get application private data of the stream server.
Definition: stream_srv.c:946
int osmo_stream_srv_link_get_fd(const struct osmo_stream_srv_link *link)
Get File Descriptor of the stream server link.
Definition: stream_srv.c:429
void osmo_stream_cli_set_segmentation_cb(struct osmo_stream_cli *cli, int(*segmentation_cb)(struct msgb *msg))
Set the segmentation callback for the client.
Definition: stream_cli.c:659
void osmo_stream_cli_set_name(struct osmo_stream_cli *cli, const char *name)
Set a name on the cli object (used during logging)
Definition: stream_cli.c:524
char * osmo_stream_cli_get_sockname(const struct osmo_stream_cli *cli)
Get the stream client socket description.
Definition: stream_cli.c:736
int osmo_stream_cli_get_fd(const struct osmo_stream_cli *cli)
Get file descriptor of the stream client socket.
Definition: stream_cli.c:218
Definition: stream_cli.c:97
Definition: stream_srv.c:578