From 668c8041976e530264d55b5338df791b91ef7d9e Mon Sep 17 00:00:00 2001 From: Pau Espin Pedrol Date: Mon, 19 Sep 2022 14:45:24 +0200 Subject: [PATCH] stream: Provide caller with SCTP flags during osmo_stream_*_recv() The user may want to check the flags in order to know if the content pointed at by msgb is an sctp_notification structure, and not in-band data. This is useful for the user in order to gain connection state such as SCTP RESET notification, which means the client reconnected reusing the same socket, loosing all higher layers state. The MSG_NOTIFICATION from netinet/sctp.h is not reused, and instead an osmocom specific flag (and bitmask) is used. This is done in order to fit the flags in one byte, since for instance MSG_NOTIFICATION requires 2 bytes in my system (0x8000). Related: SYS#6113 Change-Id: I0ee94846a15a23950b9d70eaaef1251267296bdd --- include/osmocom/netif/stream.h | 4 ++++ src/stream.c | 1 + 2 files changed, 5 insertions(+) diff --git a/include/osmocom/netif/stream.h b/include/osmocom/netif/stream.h index b82dff1..489fc5d 100644 --- a/include/osmocom/netif/stream.h +++ b/include/osmocom/netif/stream.h @@ -9,6 +9,10 @@ * @{ */ +/*! \brief Access SCTP flags from the msgb control buffer */ +#define OSMO_STREAM_SCTP_MSG_FLAGS_NOTIFICATION 0x80 /* sctp_recvmsg() flags=MSG_NOTIFICATION, msgb_data() contains "union sctp_notification*" */ +#define msgb_sctp_msg_flags(msg) (msg)->cb[2] + /*! \brief Access the SCTP PPID from the msgb control buffer */ #define msgb_sctp_ppid(msg) (msg)->cb[3] /*! \brief Access the SCTP Stream ID from the msgb control buffer */ diff --git a/src/stream.c b/src/stream.c index bc209af..b45b730 100644 --- a/src/stream.c +++ b/src/stream.c @@ -1476,6 +1476,7 @@ static int _sctp_recvmsg_wrapper(int fd, struct msgb *msg) if (flags & MSG_NOTIFICATION) { union sctp_notification *notif = (union sctp_notification *)msgb_data(msg); LOGP(DLINP, LOGL_DEBUG, "NOTIFICATION %u flags=0x%x\n", notif->sn_header.sn_type, notif->sn_header.sn_flags); + msgb_sctp_msg_flags(msg) = OSMO_STREAM_SCTP_MSG_FLAGS_NOTIFICATION; switch (notif->sn_header.sn_type) { case SCTP_ASSOC_CHANGE: LOGP(DLINP, LOGL_DEBUG, "===> ASSOC CHANGE:");