open5gs/lib/sctp/ogs-sctp.h
Sukchan Lee 6f11a78079 If SCTP use SOCK_STREAM, Use BUFFERING method.
Most of the time, an application wants to perform some amount of data buffering
in addition to just responding to events. When we want to write data,
for example, the usual pattern runs something like:

1. Decide that we want to write some data to a connection;
   put that data in a buffer.
2. Wait for the connection to become writable
3. Write as much of the data as we can
4. Remember how much we wrote, and if we still have more data to write,
   wait for the connection to become writable again.

Now, Open5GS implements the above method by default when transmitting data
in a stream type socket.
2020-11-11 13:21:32 -05:00

137 lines
3.7 KiB
C

/*
* Copyright (C) 2019 by Sukchan Lee <acetcom@gmail.com>
*
* This file is part of Open5GS.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef OGS_SCTP_H
#define OGS_SCTP_H
#include "ogs-core.h"
#include "sctp/sctp-config.h"
#define OGS_SCTP_INSIDE
/* Nothing */
#undef OGS_SCTP_INSIDE
#ifdef __cplusplus
extern "C" {
#endif
extern int __ogs_sctp_domain;
#undef OGS_LOG_DOMAIN
#define OGS_LOG_DOMAIN __ogs_sctp_domain
#define OGS_S1AP_SCTP_PORT 36412
#define OGS_SGSAP_SCTP_PORT 29118
#define OGS_NGAP_SCTP_PORT 38412
#define OGS_SCTP_S1AP_PPID 18
#define OGS_SCTP_X2AP_PPID 27
#define OGS_SCTP_SGSAP_PPID 0
#define OGS_SCTP_NGAP_PPID 60
#define ogs_sctp_ppid_in_pkbuf(__pkBUF) (__pkBUF)->param[0]
#define ogs_sctp_stream_no_in_pkbuf(__pkBUF) (__pkBUF)->param[1]
#if HAVE_USRSCTP
#undef MSG_NOTIFICATION
#define MSG_NOTIFICATION 0x2000
#ifndef INET
#define INET 1
#endif
#ifndef INET6
#define INET6 1
#endif
#include <usrsctp.h>
ogs_sockaddr_t *ogs_usrsctp_remote_addr(union sctp_sockstore *store);
void ogs_sctp_destroy(ogs_sock_t *sock);
ogs_sock_t *ogs_sctp_accept(ogs_sock_t *sock);
#else
#if HAVE_NETINET_SCTP_H
#include <netinet/sctp.h>
#endif
#define ogs_sctp_destroy ogs_sock_destroy
#define ogs_sctp_accept ogs_sock_accept
#endif
#define DEFAULT_SCTP_MAX_NUM_OF_OSTREAMS 30
typedef struct ogs_sctp_sock_s {
int type; /* SOCK_STREAM or SOCK_SEQPACKET */
ogs_sock_t *sock; /* Socket */
ogs_sockaddr_t *addr; /* Address */
struct {
ogs_poll_t *read; /* Read Poll */
ogs_poll_t *write; /* Write Poll */
} poll;
ogs_list_t write_queue; /* Write Queue for Sending S1AP message */
} ogs_sctp_sock_t;
typedef struct ogs_sctp_info_s {
uint32_t ppid;
uint16_t stream_no;
uint16_t inbound_streams;
uint16_t outbound_streams;
} ogs_sctp_info_t;
void ogs_sctp_init(uint16_t port);
void ogs_sctp_final(void);
ogs_sock_t *ogs_sctp_socket(int family, int type, ogs_socknode_t *node);
void ogs_sctp_set_option(ogs_sockopt_t *option, ogs_socknode_t *node);
ogs_sock_t *ogs_sctp_server(int type, ogs_socknode_t *node);
ogs_sock_t *ogs_sctp_client(int type, ogs_socknode_t *node);
int ogs_sctp_bind(ogs_sock_t *sock, ogs_sockaddr_t *sa_list);
int ogs_sctp_connect(ogs_sock_t *sock, ogs_sockaddr_t *sa_list);
int ogs_sctp_listen(ogs_sock_t *sock);
int ogs_sctp_sendmsg(ogs_sock_t *sock, const void *msg, size_t len,
ogs_sockaddr_t *to, uint32_t ppid, uint16_t stream_no);
int ogs_sctp_recvmsg(ogs_sock_t *sock, void *msg, size_t len,
ogs_sockaddr_t *from, ogs_sctp_info_t *sinfo, int *msg_flags);
int ogs_sctp_recvdata(ogs_sock_t *sock, void *msg, size_t len,
ogs_sockaddr_t *from, ogs_sctp_info_t *sinfo);
int ogs_sctp_senddata(ogs_sock_t *sock,
ogs_pkbuf_t *pkbuf, ogs_sockaddr_t *addr);
void ogs_sctp_write_to_buffer(ogs_sctp_sock_t *sctp, ogs_pkbuf_t *pkbuf);
void ogs_sctp_flush_and_destroy(ogs_sctp_sock_t *sctp);
#ifdef __cplusplus
}
#endif
#endif /* OGS_SCTP_H */