libosmo-netif  1.4.0.19-26cd.202401052026
Osmocom network interface library
stream_srv.c File Reference

Osmocom stream socket helpers (server side) More...

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <time.h>
#include <sys/fcntl.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <osmocom/core/timer.h>
#include <osmocom/core/select.h>
#include <osmocom/core/utils.h>
#include <osmocom/gsm/tlv.h>
#include <osmocom/core/msgb.h>
#include <osmocom/core/osmo_io.h>
#include <osmocom/core/panic.h>
#include <osmocom/core/logging.h>
#include <osmocom/core/talloc.h>
#include <osmocom/core/socket.h>
#include <osmocom/netif/stream.h>
#include <osmocom/netif/stream_private.h>
#include "config.h"
#include <osmocom/netif/sctp.h>

Data Structures

struct  osmo_stream_srv_link
 
struct  osmo_stream_srv
 

Macros

#define LOGSLNK(link, level, fmt, args...)
 
#define LOGSSRV(srv, level, fmt, args...)
 
#define OSMO_STREAM_SRV_F_RECONF   (1 << 0)
 
#define OSMO_STREAM_SRV_F_NODELAY   (1 << 1)
 
#define OSMO_STREAM_SRV_F_FLUSH_DESTROY   (1 << 0)
 

Functions

static int _setsockopt_nosigpipe (struct osmo_stream_srv_link *link, int new_fd)
 
static int osmo_stream_srv_link_ofd_cb (struct osmo_fd *ofd, unsigned int what)
 
struct osmo_stream_srv_linkosmo_stream_srv_link_create (void *ctx)
 Create an Osmocom Stream Server Link A Stream Server Link is the listen()+accept() "parent" to individual Stream Servers. More...
 
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) More...
 
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 automatically set the NODELAY socket option on any socket established via this server link, before calling the accept_cb() More...
 
void osmo_stream_srv_link_set_addr (struct osmo_stream_srv_link *link, const char *addr)
 Set the local address to which we bind. More...
 
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 address (such as SCTP) More...
 
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. More...
 
void osmo_stream_srv_link_set_proto (struct osmo_stream_srv_link *link, uint16_t proto)
 Set the protocol for the stream server link. More...
 
int osmo_stream_srv_link_set_type (struct osmo_stream_srv_link *link, int type)
 Set the socket type for the stream server link. More...
 
int osmo_stream_srv_link_set_domain (struct osmo_stream_srv_link *link, int domain)
 Set the socket type for the stream server link. More...
 
void osmo_stream_srv_link_set_data (struct osmo_stream_srv_link *link, void *data)
 Set application private data of the stream server link. More...
 
void * osmo_stream_srv_link_get_data (struct osmo_stream_srv_link *link)
 Get application private data of the stream server link. More...
 
static char * get_local_sockname_buf (char *buf, size_t buf_len, int fd, int proto)
 
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. More...
 
struct osmo_fd * osmo_stream_srv_link_get_ofd (struct osmo_stream_srv_link *link)
 Get Osmocom File Descriptor of the stream server link. More...
 
int osmo_stream_srv_link_get_fd (const struct osmo_stream_srv_link *link)
 Get File Descriptor of the stream server link. More...
 
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. More...
 
void osmo_stream_srv_link_destroy (struct osmo_stream_srv_link *link)
 Destroy the stream server link. Closes + Releases Memory. More...
 
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 configured ip/port. More...
 
bool osmo_stream_srv_link_is_opened (const struct osmo_stream_srv_link *link)
 Check whether the stream server link is opened. More...
 
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, merely closes it! More...
 
int osmo_stream_srv_link_set_param (struct osmo_stream_srv_link *link, enum osmo_stream_srv_link_param par, void *val, size_t val_len)
 
static void stream_srv_iofd_read_cb (struct osmo_io_fd *iofd, int res, struct msgb *msg)
 
static void stream_srv_iofd_write_cb (struct osmo_io_fd *iofd, int res, struct msgb *msg)
 
static int osmo_stream_srv_read (struct osmo_stream_srv *conn)
 
static void osmo_stream_srv_write (struct osmo_stream_srv *conn)
 
static int osmo_stream_srv_cb (struct osmo_fd *ofd, unsigned int what)
 
struct osmo_stream_srvosmo_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. More...
 
struct osmo_stream_srvosmo_stream_srv_create2 (void *ctx, struct osmo_stream_srv_link *link, int fd, void *data)
 Create a Stream Server inside the specified link. More...
 
void osmo_stream_srv_set_name (struct osmo_stream_srv *conn, const char *name)
 Set a name on the srv object (used during logging) More...
 
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 created with osmo_stream_srv_create2() More...
 
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. More...
 
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 the stream with osmo_stream_srv_destroy(). This function disables queuing of new messages on the connection and also disables reception of new messages on the connection. More...
 
void osmo_stream_srv_set_data (struct osmo_stream_srv *conn, void *data)
 Set application private data of the stream server. More...
 
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 established prior to calling this function. More...
 
void * osmo_stream_srv_get_data (struct osmo_stream_srv *conn)
 Get application private data of the stream server. More...
 
const char * osmo_stream_srv_get_sockname (const struct osmo_stream_srv *conn)
 Get the stream server socket description. More...
 
struct osmo_fd * osmo_stream_srv_get_ofd (struct osmo_stream_srv *conn)
 Get Osmocom File Descriptor of the stream server. More...
 
int osmo_stream_srv_get_fd (const struct osmo_stream_srv *conn)
 Get File Descriptor of the stream server. More...
 
struct osmo_stream_srv_linkosmo_stream_srv_get_master (struct osmo_stream_srv *conn)
 Get the master (Link) from a Stream Server. More...
 
void osmo_stream_srv_destroy (struct osmo_stream_srv *conn)
 Destroy given Stream Server This function closes the Stream Server socket, unregisters from select loop, invokes the connection's closed_cb() callback to allow API users to clean up any associated state they have for this connection, and then de-allocates associated memory. More...
 
void osmo_stream_srv_send (struct osmo_stream_srv *conn, struct msgb *msg)
 Enqueue data to be sent via an Osmocom stream server. More...
 
int osmo_stream_srv_recv (struct osmo_stream_srv *conn, struct msgb *msg)
 Receive data via Osmocom stream server. More...
 
void osmo_stream_srv_clear_tx_queue (struct osmo_stream_srv *conn)
 

Variables

static struct osmo_io_ops srv_ioops
 

Detailed Description

Osmocom stream socket helpers (server side)