libosmo-netif 1.4.0.40-1042.202403152026
Osmocom network interface library
stream.h
Go to the documentation of this file.
1#pragma once
2
3#include <stdbool.h>
4#include <stdint.h>
5#include <unistd.h>
6
7#include <osmocom/core/msgb.h>
8
21#define OSMO_STREAM_SCTP_MSG_FLAGS_NOTIFICATION 0x80 /* sctp_recvmsg() flags=MSG_NOTIFICATION, msgb_data() contains "union sctp_notification*" */
22#define msgb_sctp_msg_flags(msg) (msg)->cb[2]
23
25#define msgb_sctp_ppid(msg) (msg)->cb[3]
27#define msgb_sctp_stream(msg) (msg)->cb[4]
28
31
34
35void osmo_stream_srv_link_set_name(struct osmo_stream_srv_link *link, const char *name);
36const char *osmo_stream_srv_link_get_name(const struct osmo_stream_srv_link *link);
37void osmo_stream_srv_link_set_nodelay(struct osmo_stream_srv_link *link, bool nodelay);
38void osmo_stream_srv_link_set_addr(struct osmo_stream_srv_link *link, const char *addr);
39int osmo_stream_srv_link_set_addrs(struct osmo_stream_srv_link *link, const char **addr, size_t addrcnt);
40void osmo_stream_srv_link_set_port(struct osmo_stream_srv_link *link, uint16_t port);
41void osmo_stream_srv_link_set_proto(struct osmo_stream_srv_link *link, uint16_t proto);
42int osmo_stream_srv_link_set_type(struct osmo_stream_srv_link *link, int type);
43int osmo_stream_srv_link_set_domain(struct osmo_stream_srv_link *link, int domain);
44void osmo_stream_srv_link_set_accept_cb(struct osmo_stream_srv_link *link, int (*accept_cb)(struct osmo_stream_srv_link *link, int fd));
45void osmo_stream_srv_link_set_data(struct osmo_stream_srv_link *link, void *data);
48struct osmo_fd *osmo_stream_srv_link_get_ofd(struct osmo_stream_srv_link *link);
53
54enum osmo_stream_srv_link_param {
55 OSMO_STREAM_SRV_LINK_PAR_SCTP_SOCKOPT_AUTH_SUPPORTED, /* uint8_t: 0 disable, 1 enable, 2 force disable, 3 force enable */
56 OSMO_STREAM_SRV_LINK_PAR_SCTP_SOCKOPT_ASCONF_SUPPORTED, /* uint8_t: 0 disable, 1 enable, 2 force disable, 3 force enable */
57 OSMO_STREAM_SRV_LINK_PAR_SCTP_INIT_NUM_OSTREAMS, /* uint16_t: amount of streams */
58 OSMO_STREAM_SRV_LINK_PAR_SCTP_INIT_MAX_INSTREAMS, /* uint16_t: amount of streams */
59};
60
61int osmo_stream_srv_link_set_param(struct osmo_stream_srv_link *link, enum osmo_stream_srv_link_param par,
62 void *val, size_t val_len);
63
66struct osmo_stream_srv;
67
68struct 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);
69struct osmo_stream_srv *osmo_stream_srv_create2(void *ctx, struct osmo_stream_srv_link *link, int fd, void *data);
70void osmo_stream_srv_set_name(struct osmo_stream_srv *conn, const char *name);
71const char *osmo_stream_srv_get_name(const struct osmo_stream_srv *conn);
72void osmo_stream_srv_set_read_cb(struct osmo_stream_srv *conn, int (*read_cb)(struct osmo_stream_srv *conn, struct msgb *msg));
73void osmo_stream_srv_set_closed_cb(struct osmo_stream_srv *conn, int (*closed_cb)(struct osmo_stream_srv *conn));
76const char *osmo_stream_srv_get_sockname(const struct osmo_stream_srv *conn);
77struct osmo_fd *osmo_stream_srv_get_ofd(struct osmo_stream_srv *srv);
78int osmo_stream_srv_get_fd(const struct osmo_stream_srv *srv);
80
82void osmo_stream_srv_set_data(struct osmo_stream_srv *conn, void *data);
83
85 int (*segmentation_cb)(struct msgb *msg));
86
87void osmo_stream_srv_send(struct osmo_stream_srv *conn, struct msgb *msg);
88int osmo_stream_srv_recv(struct osmo_stream_srv *conn, struct msgb *msg);
89
90void osmo_stream_srv_clear_tx_queue(struct osmo_stream_srv *conn);
91
93struct osmo_stream_cli;
94
95void osmo_stream_cli_set_name(struct osmo_stream_cli *cli, const char *name);
96const char *osmo_stream_cli_get_name(const struct osmo_stream_cli *cli);
97void osmo_stream_cli_set_nodelay(struct osmo_stream_cli *cli, bool nodelay);
98void osmo_stream_cli_set_addr(struct osmo_stream_cli *cli, const char *addr);
99int osmo_stream_cli_set_addrs(struct osmo_stream_cli *cli, const char **addr, size_t addrcnt);
100void osmo_stream_cli_set_port(struct osmo_stream_cli *cli, uint16_t port);
101int osmo_stream_cli_set_type(struct osmo_stream_cli *cli, int type);
102int osmo_stream_cli_set_domain(struct osmo_stream_cli *cli, int domain);
103void osmo_stream_cli_set_proto(struct osmo_stream_cli *cli, uint16_t proto);
104void osmo_stream_cli_set_local_addr(struct osmo_stream_cli *cli, const char *addr);
105int osmo_stream_cli_set_local_addrs(struct osmo_stream_cli *cli, const char **addr, size_t addrcnt);
106void osmo_stream_cli_set_local_port(struct osmo_stream_cli *cli, uint16_t port);
107void osmo_stream_cli_set_data(struct osmo_stream_cli *cli, void *data);
108void osmo_stream_cli_set_reconnect_timeout(struct osmo_stream_cli *cli, int timeout);
110char *osmo_stream_cli_get_sockname(const struct osmo_stream_cli *cli);
111struct osmo_fd *osmo_stream_cli_get_ofd(struct osmo_stream_cli *cli);
112int osmo_stream_cli_get_fd(const struct osmo_stream_cli *cli);
113void osmo_stream_cli_set_connect_cb(struct osmo_stream_cli *cli, int (*connect_cb)(struct osmo_stream_cli *cli));
114void osmo_stream_cli_set_disconnect_cb(struct osmo_stream_cli *cli, int (*disconnect_cb)(struct osmo_stream_cli *cli));
115void osmo_stream_cli_set_read_cb(struct osmo_stream_cli *cli, int (*read_cb)(struct osmo_stream_cli *cli));
116void osmo_stream_cli_set_read_cb2(struct osmo_stream_cli *cli, int (*read_cb)(struct osmo_stream_cli *cli, struct msgb *msg));
117void osmo_stream_cli_set_segmentation_cb(struct osmo_stream_cli *cli, int (*segmentation_cb)(struct msgb *msg));
120
121struct osmo_stream_cli *osmo_stream_cli_create(void *ctx);
123
125int osmo_stream_cli_open2(struct osmo_stream_cli *cli, int reconnect) \
126 OSMO_DEPRECATED("Use osmo_stream_cli_set_reconnect_timeout() or osmo_stream_cli_reconnect() instead");
127void osmo_stream_cli_close(struct osmo_stream_cli *cli);
128
129void osmo_stream_cli_send(struct osmo_stream_cli *cli, struct msgb *msg);
130int osmo_stream_cli_recv(struct osmo_stream_cli *cli, struct msgb *msg);
131
132void osmo_stream_cli_clear_tx_queue(struct osmo_stream_cli *cli);
133
134enum osmo_stream_cli_param {
135 OSMO_STREAM_CLI_PAR_SCTP_SOCKOPT_AUTH_SUPPORTED, /* uint8_t: 0 disable, 1 enable, 2 force disable, 3 force enable */
136 OSMO_STREAM_CLI_PAR_SCTP_SOCKOPT_ASCONF_SUPPORTED, /* uint8_t: 0 disable, 1 enable, 2 force disable, 3 force enable */
137 OSMO_STREAM_CLI_PAR_SCTP_INIT_NUM_OSTREAMS, /* uint16_t: amount of streams */
138 OSMO_STREAM_CLI_PAR_SCTP_INIT_MAX_INSTREAMS, /* uint16_t: amount of streams */
139 OSMO_STREAM_CLI_PAR_SCTP_INIT_MAX_ATTEMPTS, /* uint16_t: amount of attempts */
140 OSMO_STREAM_CLI_PAR_SCTP_INIT_TIMEOUT, /* uint16_t: milliseconds */
141};
142
143int osmo_stream_cli_set_param(struct osmo_stream_cli *cli, enum osmo_stream_cli_param par,
144 void *val, size_t val_len);
145
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:541
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:746
int osmo_stream_cli_recv(struct osmo_stream_cli *cli, struct msgb *msg)
Receive data via an Osmocom stream client.
Definition: stream_cli.c:1052
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.
Definition: stream_cli.c:609
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:531
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:131
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:813
struct osmo_stream_cli * osmo_stream_cli_create(void *ctx)
Create an Osmocom stream client.
Definition: stream_cli.c:409
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:294
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:866
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:433
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:785
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:765
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:281
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.
Definition: stream_srv.c:925
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:505
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:687
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:222
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:964
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:1002
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:587
const char * osmo_stream_srv_get_sockname(const struct osmo_stream_srv *conn)
Get the stream server socket description.
Definition: stream_srv.c:950
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:668
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:716
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:333
int osmo_stream_srv_link_open(struct osmo_stream_srv_link *link)
Open the stream server link.
Definition: stream_srv.c:452
void * osmo_stream_cli_get_data(struct osmo_stream_cli *cli)
Get application private data of the stream client socket.
Definition: stream_cli.c:724
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:210
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:598
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:269
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:895
bool osmo_stream_cli_is_connected(struct osmo_stream_cli *cli)
Check if Osmocom Stream Client is in connected state.
Definition: stream_cli.c:150
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:417
char * osmo_stream_srv_link_get_sockname(const struct osmo_stream_srv_link *link)
Get description of the stream server link e.
Definition: stream_srv.c:404
int osmo_stream_srv_get_fd(const struct osmo_stream_srv *srv)
Get File Descriptor of the stream server.
Definition: stream_srv.c:974
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:906
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:886
void osmo_stream_srv_link_destroy(struct osmo_stream_srv_link *link)
Destroy the stream server link.
Definition: stream_srv.c:442
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:823
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:633
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:313
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:915
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:991
void osmo_stream_cli_destroy(struct osmo_stream_cli *cli)
Destroy a Osmocom stream client (includes close)
Definition: stream_cli.c:799
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:1026
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:873
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.
Definition: stream_cli.c:552
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:1004
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:179
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.
Definition: stream_srv.c:246
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:756
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:576
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:886
int osmo_stream_srv_recv(struct osmo_stream_srv *conn, struct msgb *msg)
Receive data via Osmocom stream server.
Definition: stream_srv.c:1071
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:342
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:234
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:776
void osmo_stream_cli_close(struct osmo_stream_cli *cli)
Close an Osmocom Stream Client.
Definition: stream_cli.c:177
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:519
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:877
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:789
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:707
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:201
void * osmo_stream_srv_get_data(struct osmo_stream_srv *conn)
Get application private data of the stream server.
Definition: stream_srv.c:942
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:425
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:655
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:520
char * osmo_stream_cli_get_sockname(const struct osmo_stream_cli *cli)
Get the stream client socket description.
Definition: stream_cli.c:732
int osmo_stream_cli_get_fd(const struct osmo_stream_cli *cli)
Get file descriptor of the stream client socket.
Definition: stream_cli.c:214
Definition: stream_cli.c:93
Definition: stream_srv.c:574