diff --git a/Makefile.am b/Makefile.am index dc89836f1..58fbc2ff1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -18,7 +18,7 @@ if BUILD_DOCS SUBD_DOCS= doc endif -SUBDIRS= libexecinfo libucl libxxHash makeann $(SUBD_MOD) \ +SUBDIRS= libexecinfo libucl libxxHash libre makeann $(SUBD_MOD) \ $(SUBD_ELP) src $(SUBD_UDCNT) tests \ $(SUBD_EAUD) ${SUBD_DOCS} diff --git a/configure.ac b/configure.ac index 0232ea36b..1205d1ea9 100644 --- a/configure.ac +++ b/configure.ac @@ -411,7 +411,7 @@ AC_CONFIG_FILES([Makefile src/Makefile makeann/Makefile tests/Makefile extractaudio/Makefile libexecinfo/Makefile modules/Makefile modules/acct_csv/Makefile modules/acct_rtcp_hep/Makefile modules/catch_dtmf/Makefile modules/badmod/Makefile libxxHash/Makefile - modules/dtls_gw/Makefile + libre/Makefile modules/dtls_gw/Makefile modules/ice_lite/Makefile pertools/Makefile pertools/udp_contention/Makefile libucl/Makefile python/sippy_lite/sippy/Time/clock_dtime.py doc/Makefile]) diff --git a/modules/Makefile.am b/modules/Makefile.am index 9e0ba099f..a5b3658e5 100644 --- a/modules/Makefile.am +++ b/modules/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS= acct_csv acct_rtcp_hep catch_dtmf badmod +SUBDIRS= acct_csv acct_rtcp_hep catch_dtmf badmod ice_lite if BUILD_CRYPTO SUBDIRS+= dtls_gw endif diff --git a/modules/ice_lite/Makefile.am b/modules/ice_lite/Makefile.am new file mode 100644 index 000000000..1a06a3fda --- /dev/null +++ b/modules/ice_lite/Makefile.am @@ -0,0 +1,33 @@ +include $(top_srcdir)/m4/memdeb.ami +include $(top_srcdir)/m4/ccflags.ami +include $(top_srcdir)/m4/coverage.ami +include $(top_srcdir)/m4/rtpp_module.ami + +pkglib_LTLIBRARIES = rtpp_ice_lite.la rtpp_ice_lite_debug.la + +if ENABLE_LIBRTPPROXY +noinst_LTLIBRARIES = librtpp_ice_lite.la +endif + +rtpp_ice_lite_la_SOURCES = rtpp_ice_lite.c +rtpp_ice_lite_la_LDFLAGS = -avoid-version -module -shared $(LTO_FLAG) $(LDFLAG_SYMEXPORT) +rtpp_ice_lite_la_CPPFLAGS = -DRTPP_MODULE -Dmalloc=mod_malloc \ + -Dfree=mod_free -Drealloc=mod_realloc -DRTPP_MOD_NAME="ice_lite" \ + -I$(top_srcdir)/external/libre/include -I$(top_srcdir)/external/libre/src \ + -I$(top_srcdir)/libre +CFLAGS_rtpp_ice_lite_common = -std=c11 -D_BSD_SOURCE -D_XOPEN_SOURCE $(LTO_FLAG) +rtpp_ice_lite_la_CFLAGS = $(OPT_CFLAGS) $(CFLAGS_rtpp_ice_lite_common) +rtpp_ice_lite_la_LIBADD = $(top_srcdir)/libre/libre.la -lcrypto + +rtpp_ice_lite_debug_la_SOURCES = $(rtpp_ice_lite_la_SOURCES) +rtpp_ice_lite_debug_la_LIBADD = $(top_srcdir)/libre/libre_debug.la $(RTPP_MEMDEB_LDADD) -lcrypto +rtpp_ice_lite_debug_la_LDFLAGS = $(rtpp_ice_lite_la_LDFLAGS) +rtpp_ice_lite_debug_la_CPPFLAGS = $(rtpp_ice_lite_la_CPPFLAGS) \ + $(RTPP_MEMDEB_CPPFLAGS) -DMEMDEB_APP="ice_lite" +rtpp_ice_lite_debug_la_CFLAGS = $(NOPT_CFLAGS) $(CFLAGS_rtpp_ice_lite_common) \ + $(RTPP_MEMDEB_CFLAGS) + +librtpp_ice_lite_la_SOURCES = $(rtpp_ice_lite_la_SOURCES) +librtpp_ice_lite_la_CPPFLAGS = $(rtpp_ice_lite_la_CPPFLAGS) -DLIBRTPPROXY +librtpp_ice_lite_la_CFLAGS = $(rtpp_ice_lite_la_CFLAGS) +librtpp_ice_lite_la_LIBADD = $(rtpp_ice_lite_la_LIBADD) diff --git a/modules/ice_lite/rtpp_ice_lite.c b/modules/ice_lite/rtpp_ice_lite.c new file mode 100644 index 000000000..020eb39e0 --- /dev/null +++ b/modules/ice_lite/rtpp_ice_lite.c @@ -0,0 +1,634 @@ +/* + * Copyright (c) 2019-2020 Sippy Software, Inc., http://www.sippysoft.com + * Copyright (c) 2019 Maxim Sobolev + * Copyright (c) 2019 Razvan Crainea + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "config_pp.h" + +#include "rtpp_types.h" +#include "rtpp_debug.h" +#include "rtpp_module.h" +#include "rtpp_module_wthr.h" +#include "rtpp_module_cplane.h" +#include "rtpp_log.h" +#include "rtpp_log_obj.h" +#include "rtpp_refcnt.h" +#include "rtpp_cfg.h" +#include "rtpp_wi.h" +#include "rtpp_wi_sgnl.h" +#include "rtpp_wi_data.h" +#include "rtpp_queue.h" +#include "rtpp_stream.h" +#include "rtp.h" +#include "rtpp_network.h" +#include "rtpp_time.h" +#include "rtp_packet.h" +#include "rtpp_timeout_data.h" +#include "rtpp_command_args.h" +#include "rtpp_command_sub.h" +#include "rtpp_util.h" +#include "rtpp_session.h" +#include "rtpp_stream.h" +#include "rtpp_pipe.h" +#include "rtpp_proc_async.h" +#include "rtpp_netio_async.h" +#include "rtpp_netaddr.h" +#include "advanced/packet_processor.h" +#include "advanced/pproc_manager.h" + +#include "rtpp_re.h" +#include "re_types.h" +#include "re_fmt.h" +#include "re_sa.h" +#include "re_ice.h" +#include "re_udp.h" +#include "re_mem.h" +#include "re_list.h" +#include "re_tmr.h" +#include "re_mbuf.h" +#include "re_stun.h" +#include "ice/ice.h" + +struct rtpp_module_priv { + struct rtpp_anetio_cf *netio_cf; +}; + +struct ila_sock { + struct sa laddr; + struct rtpp_netaddr *raddr; + struct sthread_args *sender; + struct rtpp_stream *strmp_in; + udp_helper_recv_h *rh; + void *rh_arg; +}; + +struct ice_lite_agent_cfg { + struct rtpp_refcnt *rcnt; + struct icem *icem; + struct ila_sock *sock; + struct mbuf *mb; + struct rtpp_anetio_cf *netio_cf; +}; + +static struct rtpp_module_priv *rtpp_ice_lite_ctor(const struct rtpp_cfg *); +static void rtpp_ice_lite_dtor(struct rtpp_module_priv *); +static void rtpp_ice_lite_worker(const struct rtpp_wthrdata *); +static int rtpp_ice_lite_handle_command(struct rtpp_module_priv *, + const struct rtpp_subc_ctx *); +static int rtp_packet_is_stun(struct pkt_proc_ctx *); +static enum pproc_action rtpp_ice_lite_enqueue(const struct pkt_proc_ctx *); + +#ifdef RTPP_CHECK_LEAKS +#include "rtpp_memdeb_internal.h" +void *_libre_memdeb; +RTPP_MEMDEB_APP_STATIC; +#endif + +#if !defined(LIBRTPPROXY) +struct rtpp_minfo rtpp_module = { +#else +struct rtpp_minfo rtpp_module_ice_lite = { +#endif + .descr.name = "ice_lite", + .descr.ver = MI_VER_INIT(), + .descr.module_id = 5, + .proc.ctor = rtpp_ice_lite_ctor, + .proc.dtor = rtpp_ice_lite_dtor, + .wapi = &(const struct rtpp_wthr_handlers){.main_thread = rtpp_ice_lite_worker}, + .capi = &(const struct rtpp_cplane_handlers){.ul_subc_handle = rtpp_ice_lite_handle_command}, +#ifdef RTPP_CHECK_LEAKS + .memdeb_p = &MEMDEB_SYM +#endif +}; + +static void +generate_random_string(char *buffer, int length) +{ + const char charset[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "0123456789" + "+/"; + int charset_size = sizeof(charset) - 1; + + for (int i = 0; i < length; i++) { + int key = rand() % charset_size; + buffer[i] = charset[key]; + } + buffer[length] = '\0'; +} + +struct wipkt { + const struct rtp_packet *pkt; + struct ice_lite_agent_cfg *ila_c; + struct rtpp_stream *strmp_in; +}; + +void +re_dbg_printf(int level, const char *buf, int len) +{ + mod_log(level, "%.*s", len, buf); +} + +int +udp_register_helper(struct udp_helper **uhp, struct udp_sock *us, int layer, + udp_helper_send_h *sh, udp_helper_recv_h *rh, void *arg) +{ + struct ila_sock *sock = (struct ila_sock *)us; + mod_log(RTPP_LOG_ERR, "udp_register_helper(%p, %p, %d, %p, %p, %p)", uhp, us, layer, sh, rh, arg); + assert(sock->rh == NULL && sock->rh_arg == NULL); + sock->rh = rh; + sock->rh_arg = arg; + return (0); +} + +static void +rtpp2re_sa(struct sa *sad, const struct sockaddr *sas) +{ + + memcpy(&sad->u.sa, sas, SA_LEN(sas)); + sad->len = SA_LEN(sas); +} + +static void +re2rtpp_sa(struct sockaddr *sad, const struct sa *sas) +{ + + memcpy(sad, &sas->u.sa, sas->len); + assert(sas->len == SA_LEN(sad)); +} + +int +udp_send(struct udp_sock *us, const struct sa *dst, struct mbuf *mb) +{ + struct ila_sock *sock = (struct ila_sock *)us; + struct rtp_packet *packet; + + packet = rtp_packet_alloc(); + if (packet == NULL) + return (ENOMEM); + memcpy(packet->data.buf, mb->buf, mb->end); + packet->size = mb->end; + CALL_SMETHOD(sock->raddr, set, &dst->u.sa, dst->len); + CALL_SMETHOD(sock->strmp_in, send_pkt_to, sock->sender, packet, sock->raddr); + return (0); +} + +static void +rtpp_ice_lite_worker(const struct rtpp_wthrdata *wp) +{ +// struct rtpp_module_priv *pvt; + struct rtpp_wi *wi; + struct wipkt *wip; + const struct rtp_packet *pkt; + struct mbuf *mb; + struct ice_lite_agent_cfg *ila_c; + +// pvt = wp->mpvt; + for (;;) { + wi = rtpp_queue_get_item(wp->mod_q, 0); + if (wi == wp->sigterm) { + RTPP_OBJ_DECREF(wi); + break; + } + wip = rtpp_wi_data_get_ptr(wi, sizeof(*wip), sizeof(*wip)); + pkt = wip->pkt; + ila_c = wip->ila_c; + mb = ila_c->mb; + *mb = (struct mbuf){.buf = (uint8_t *)pkt->data.buf, .end = pkt->size, + .size = sizeof(pkt->data.buf)}; + struct sa raddr = {0}; + rtpp2re_sa(&raddr, sstosa(&pkt->raddr)); + ila_c->sock->sender = rtpp_anetio_pick_sender(ila_c->netio_cf); + ila_c->sock->strmp_in = wip->strmp_in; + ila_c->sock->rh(&raddr, mb, ila_c->sock->rh_arg); + RTPP_OBJ_DECREF(pkt); + RTPP_OBJ_DECREF(wip->strmp_in); + RTPP_OBJ_DECREF(ila_c); + RTPP_OBJ_DECREF(wi); + } +} + +static void +ice_lite_data_dtor(struct ice_lite_agent_cfg *pvt) +{ + + RTPP_OBJ_DECREF(pvt->sock->raddr); + mem_deref(pvt->mb); + mem_deref(pvt->sock); + mem_deref(pvt->icem); + mod_free(pvt); + RC_DECREF(RTPP_MOD_SELF.module_rcnt); +} + +int +udp_local_get(const struct udp_sock *us, struct sa *local) +{ + struct ila_sock *sock = (struct ila_sock *)us; + *local = sock->laddr; + return (0); +} + +static struct ice_lite_agent_cfg * +ice_lite_data_ctor(const struct rtpp_subc_ctx *ctxp, + const rtpp_str_t *ice_rufrag, const rtpp_str_t *ice_rpwd, + struct rtpp_anetio_cf *netio_cf) +{ + struct ice_lite_agent_cfg *ila_c; + rtpp_str_mutble_t lufrag, lpwd; + uint64_t tiebrk = 1; + + ila_c = mod_rzmalloc(sizeof(*ila_c), offsetof(typeof(*ila_c), rcnt)); + if (ila_c == NULL) + goto e0; + lufrag.s = alloca(ice_rufrag->len + 1); + lpwd.s = alloca(ice_rpwd->len + 1); + if (lufrag.s == NULL || lpwd.s == NULL) + goto e1; + lufrag.len = ice_rufrag->len; + generate_random_string(lufrag.s, lufrag.len); + lpwd.len = ice_rpwd->len; + generate_random_string(lpwd.s, lpwd.len); + if (icem_alloc(&ila_c->icem, ICE_MODE_LITE, ICE_ROLE_CONTROLLED, IPPROTO_UDP, 0, + tiebrk, lufrag.s, lpwd.s, NULL, NULL) != 0) + goto e1; + ila_c->sock = mem_zalloc(sizeof(*ila_c->sock), NULL); + if (ila_c->sock == NULL) + goto e2; + ila_c->mb = mem_zalloc(sizeof(*ila_c->mb), NULL); + if (ila_c->mb == NULL) + goto e3; + ila_c->sock->raddr = rtpp_netaddr_ctor(); + if (ila_c->sock->raddr == NULL) + goto e4; + ila_c->netio_cf = netio_cf; + icem_sdp_decode(ila_c->icem, "ice-ufrag", ice_rufrag->s); + icem_sdp_decode(ila_c->icem, "ice-pwd", ice_rpwd->s); + RC_INCREF(RTPP_MOD_SELF.module_rcnt); + CALL_SMETHOD(ila_c->rcnt, attach, (rtpp_refcnt_dtor_t)ice_lite_data_dtor, ila_c); + return (ila_c); +e4: + mem_deref(ila_c->mb); +e3: + mem_deref(ila_c->sock); +e2: + mem_deref(ila_c->icem); +e1: + mod_free(ila_c); +e0: + return (NULL); +} + +enum ril_cmd {RIL_CMD_A, RIL_CMD_C, RIL_CMD_S, RIL_CMD_D, RIL_CMD_U}; +#define ICE_COMPID_RTP 1 +#define ICE_COMPID_RTCP 2 + +static int +ice_lite_handle_candidate(struct ice_lite_agent_cfg *ila_c, int c, const rtpp_str_t *v) +{ + struct rtpp_command_argsp args = {.c = c, .v = v}; + int err = rtpp_cand_decode(ila_c->icem, &args); + return (err); +} + +int url_quote(const char *ibuf, char *obuf, int ilen, int olen) { + const char *hex = "0123456789ABCDEF"; + const unsigned char *cp; + unsigned char *ocp = (unsigned char *)obuf; + int outlen = 0; + + for (cp = (const unsigned char *)ibuf; ilen-- > 0; cp++) { + if ((*cp >= 'A' && *cp <= 'Z') || + (*cp >= 'a' && *cp <= 'z') || + (*cp >= '0' && *cp <= '9') || + *cp == '-' || *cp == '_' || *cp == '.' || *cp == '~') { + if ((olen - outlen) == 0) + return -1; + *ocp++ = *cp; + outlen++; + } else { + if ((olen - outlen) < 3) + return -1; + *ocp++ = '%'; + *ocp++ = hex[*cp >> 4]; + *ocp++ = hex[*cp & 0x0F]; + outlen += 3; + } + } + return outlen; +} + +static int +cand_printf_handler(const char *p, size_t size, void *arg) +{ + rtpp_str_mutble_t *resp = (rtpp_str_mutble_t *)arg; + if (size + 1 > resp->len) + return (ENOMEM); +#if 0 + resp->s[0] = ' '; + resp->len -= 1; + resp->s += 1; +#endif + int len = url_quote(p, resp->s, size, resp->len); + if (len < 0) + return (ENOMEM); + resp->s += len; + resp->len -= len; + return (0); +} + +#define APPEND(bs, ss) ({size_t len = strlcpy(bs->s, ss, bs->len); int err = (len > bs->len); bs->len -= (err) ? 0:len, bs->s += (err) ? 0:len; err;}) + +static int +ice_lite_handle_start(struct ice_lite_agent_cfg *ila_c, const struct rtpp_stream *isp, + rtpp_str_mutble_t *resp) +{ + int err; + struct sa *laddr; + + laddr = &ila_c->sock->laddr; + if (laddr->len == 0) { + memcpy(&laddr->u.sa, isp->laddr, SA_LEN(isp->laddr)); + laddr->len = SA_LEN(isp->laddr); + sa_set_port(laddr, isp->port); + + err = icem_comp_add(ila_c->icem, ICE_COMPID_RTP, ila_c->sock); + if (err != 0) + return (err); + err = icem_cand_add(ila_c->icem, ICE_COMPID_RTP, 0, NULL, laddr); + if (err != 0) + return (err); + } + if (APPEND(resp, ila_c->icem->lufrag) < 0) + return (ENOMEM); + if (APPEND(resp, " ") < 0) + return (ENOMEM); + if (APPEND(resp, ila_c->icem->lpwd) < 0) + return (ENOMEM); + struct re_printf pt = {.vph = cand_printf_handler, .arg = resp}; + struct list *canlist = icem_lcandl(ila_c->icem); + for(struct le *le = canlist->head; le; le = le->next) { + if (APPEND(resp, " c:") < 0) + return (ENOMEM); + err = ice_cand_encode(&pt, (struct ice_cand *)le->data); + if (err != 0) + return (err); + } + return (0); +} + +static int +rtpp_ice_lite_handle_command(struct rtpp_module_priv *pvt, + const struct rtpp_subc_ctx *ctxp) +{ + struct ice_lite_agent_cfg *ila_c; + const rtpp_str_t *rufrag, *rpwd; + enum ril_cmd ril_cmd; + const rtpp_str_t *argv = rtpp_str_fix(&ctxp->subc_args->v[1]); + int argc = ctxp->subc_args->c - 1; + struct rtpp_stream *ice_strmp; + + if (argc < 1) { + mod_log(RTPP_LOG_ERR, "expected at least 1 parameter: %d", + argc); + return (-1); + } + {static int b=0; while (b);} + + switch (argv[0].s[0] | argv[0].s[1]) { + case 'a': + case 'A': + if (argc != 3) + goto invalmode; + ril_cmd = RIL_CMD_A; + break; + + case 'c': + case 'C': + if (argc < 9) + goto invalmode; + ril_cmd = RIL_CMD_C; + break; + + case 's': + case 'S': + if (argc != 1) + goto invalmode; + ril_cmd = RIL_CMD_S; + break; + + case 'd': + case 'D': + if (argc != 1) + goto invalmode; + ril_cmd = RIL_CMD_D; + break; + + case 'u': + case 'U': + if (argc != 1) + goto invalmode; + ril_cmd = RIL_CMD_U; + break; + + default: + goto invalmode; + } + + switch (ril_cmd) { + case RIL_CMD_A: + rufrag = rtpp_str_fix(&argv[1]); + rpwd = rtpp_str_fix(&argv[2]); + case RIL_CMD_C: + case RIL_CMD_D: + ice_strmp = ctxp->strmp_in; + break; + + case RIL_CMD_S: + case RIL_CMD_U: + ice_strmp = ctxp->strmp_out; + break; + } + +#if 0 + if (ctxp->subc_args->c < 3) { + RTPP_LOG(RTPP_MOD_SELF.log, RTPP_LOG_DBUG, "no 'ice_ufrag ice_pwd' specified (sp=%p)", + ctxp->sessp); + return (-1); + } + + if (ctxp->subc_args->c > 3) { + RTPP_LOG(RTPP_MOD_SELF.log, RTPP_LOG_DBUG, "too many arguments (sp=%p)", + ctxp->sessp); + return (-1); + } + + ufrag = rtpp_str_fix(&ctxp->subc_args->v[1]); + pwd = rtpp_str_fix(&ctxp->subc_args->v[2]); +#endif + + struct packet_processor_if stun_poi; + + int lookup_res = CALL_SMETHOD(ice_strmp->pproc_manager, lookup, pvt, &stun_poi); + + if (lookup_res != 0) { + ila_c = stun_poi.arg; + } + + if (ril_cmd == RIL_CMD_D || ril_cmd == RIL_CMD_U) { + if (lookup_res == 0) { + return (-1); + } + CALL_SMETHOD(ice_strmp->pproc_manager, unreg, pvt); + goto out; + } + + if ((ril_cmd == RIL_CMD_C || ril_cmd == RIL_CMD_S) && lookup_res == 0) { + return (-1); + } + + if (ril_cmd == RIL_CMD_C) { + if (ice_lite_handle_candidate(ila_c, argc - 1, argv + 1) != 0) { + goto e0; + } + goto out; + } + + if (ril_cmd == RIL_CMD_S) { + rtpp_str_mutble_t resp = {.s = ctxp->resp->buf_t, .len = sizeof(ctxp->resp->buf_t)}; + if (ice_lite_handle_start(ila_c, ice_strmp, &resp) != 0) { + goto e0; + } + goto out; + } + + if (ril_cmd == RIL_CMD_A && lookup_res == 0) { + ila_c = ice_lite_data_ctor(ctxp, rufrag, rpwd, pvt->netio_cf); + if (ila_c == NULL) { + return (-1); + } + stun_poi = (struct packet_processor_if) { + .descr = "stun/ice", + .taste = rtp_packet_is_stun, + .enqueue = rtpp_ice_lite_enqueue, + .key = pvt, + .arg = ila_c, + .rcnt = ila_c->rcnt + }; + if (CALL_SMETHOD(ctxp->strmp_in->pproc_manager, reg, PPROC_ORD_RECV, &stun_poi) < 0) + goto e0; + } +out: + RTPP_OBJ_DECREF(ila_c); + return (0); + +invalmode: + RTPP_LOG(RTPP_MOD_SELF.log, RTPP_LOG_ERR, "invalid mode: \"%s\"", + argv[0].s); + return (-1); +e0: + RTPP_OBJ_DECREF(ila_c); + return (-1); +} + +#define STUN_MAGIC 0x2112A442 + +static int +rtp_packet_is_stun(struct pkt_proc_ctx *pktx) +{ + struct ice_lite_agent_cfg *ila_c; + const struct rtp_packet *pktp = pktx->pktp; + + if (pktp->size < 20) + return (false); + + if (ntohl(*(uint32_t *)(pktp->data.buf + 4)) != STUN_MAGIC) + return (false); + + ila_c = pktx->pproc->arg; + pktx->auxp = ila_c; + + return (true); +} + +static enum pproc_action +rtpp_ice_lite_enqueue(const struct pkt_proc_ctx *pktx) +{ + struct rtpp_wi *wi; + struct wipkt *wip; + struct ice_lite_agent_cfg *ila_c; + + ila_c = (struct ice_lite_agent_cfg *)pktx->auxp; + wi = rtpp_wi_malloc_udata((void **)&wip, sizeof(struct wipkt)); + if (wi == NULL) + return (PPROC_ACT_DROP); + RTPP_OBJ_INCREF(pktx->pktp); + wip->pkt = pktx->pktp; + RTPP_OBJ_INCREF(ila_c); + wip->ila_c = ila_c; + RTPP_OBJ_INCREF(pktx->strmp_in); + wip->strmp_in = pktx->strmp_in; + rtpp_queue_put_item(wi, RTPP_MOD_SELF.wthr.mod_q); + return (PPROC_ACT_DROP); +} + +static struct rtpp_module_priv * +rtpp_ice_lite_ctor(const struct rtpp_cfg *cfsp) +{ + struct rtpp_module_priv *pvt; + + pvt = mod_zmalloc(sizeof(struct rtpp_module_priv)); + if (pvt == NULL) { + goto e0; + } + pvt->netio_cf = cfsp->rtpp_proc_cf->netio; +#ifdef RTPP_CHECK_LEAKS + _libre_memdeb = *rtpp_module.memdeb_p; +#endif + return (pvt); + +e0: + return (NULL); +} + +static void +rtpp_ice_lite_dtor(struct rtpp_module_priv *pvt) +{ + + mod_free(pvt); + return; +} diff --git a/src/rtpp_module_if_static.h b/src/rtpp_module_if_static.h index e818b5eaa..67066c989 100644 --- a/src/rtpp_module_if_static.h +++ b/src/rtpp_module_if_static.h @@ -35,8 +35,9 @@ struct rtpp_modules { struct rtpp_minfo *acct_rtcp_hep; struct rtpp_minfo *catch_dtmf; struct rtpp_minfo *dtls_gw; + struct rtpp_minfo *ice_lite; }; - struct rtpp_minfo *all[5]; + struct rtpp_minfo *all[6]; }; };