# HG changeset patch # User Mychaela Falconia # Date 1693185330 28800 # Node ID d9db8661d9f3070f0e0a3c331e80bb8ac372e910 # Parent 2c35aad69fea21f0610abd9f1e0c13c5e1efcef9 smsc-daemon: add local socket for sendmt diff -r 2c35aad69fea -r d9db8661d9f3 smsc-daemon/Makefile --- a/smsc-daemon/Makefile Sun Aug 27 16:36:59 2023 -0800 +++ b/smsc-daemon/Makefile Sun Aug 27 17:15:30 2023 -0800 @@ -1,7 +1,7 @@ CC= gcc CFLAGS= -O2 -pthread -I/opt/osmocni2/include -I/usr/include/samba-4.0 PROG= proto-smsc-daemon -OBJS= gsup_rx.o main.o record_mo.o +OBJS= gsup_rx.o main.o record_mo.o send_mt.o OSMOLIB=-L/opt/osmocni2/lib -Wl,-rpath,/opt/osmocni2/lib -losmo-gsup-client \ -losmogsm -losmocore -ltalloc diff -r 2c35aad69fea -r d9db8661d9f3 smsc-daemon/main.c --- a/smsc-daemon/main.c Sun Aug 27 16:36:59 2023 -0800 +++ b/smsc-daemon/main.c Sun Aug 27 17:15:30 2023 -0800 @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -30,6 +31,7 @@ #include "logging.h" extern int gsupc_read_cb(struct osmo_gsup_client *gsupc, struct msgb *msg); +extern void setup_local_socket(const char *pathname); #define MAX_IPA_NAME 31 @@ -83,8 +85,9 @@ osmo_init_logging2(ctx, &smsc_log_info); - if (argc != 3) { - fprintf(stderr, "usage: %s ipa-name logfile\n", argv[0]); + if (argc < 3 || argc > 4) { + fprintf(stderr, "usage: %s ipa-name logfile [local-socket]\n", + argv[0]); exit(1); } set_ipa_name(argv[1]); @@ -97,6 +100,8 @@ fprintf(stderr, "error: osmo_gsup_client_create2() failed\n"); exit(1); } + if (argv[3]) + setup_local_socket(argv[3]); while (1) { osmo_select_main(0); diff -r 2c35aad69fea -r d9db8661d9f3 smsc-daemon/send_mt.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/smsc-daemon/send_mt.c Sun Aug 27 17:15:30 2023 -0800 @@ -0,0 +1,58 @@ +/* + * This module holds the code for the local socket: receiving MT-forwardSM.req + * messages from proto-smsc-sendmt and forwarding them to our GSUP connection. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + +#include "logging.h" + +extern struct osmo_gsup_client *g_gc; + +static struct osmo_fd socket_ofd; + +static int localsock_cb(struct osmo_fd *bfd, unsigned int what) +{ + struct msgb *msg; + int rc; + + msg = osmo_gsup_client_msgb_alloc(); + rc = recv(bfd->fd, msg->tail, msgb_tailroom(msg), 0); + if (rc <= 0) { + LOGP(DMAIN, LOGL_ERROR, + "recv from local socket returned %d\n", rc); + return -1; + } + msgb_put(msg, rc); + LOGP(DMAIN, LOGL_INFO, + "forwarding msg of %d bytes from local socket\n", rc); + osmo_gsup_client_send(g_gc, msg); + return 0; +} + +void setup_local_socket(const char *pathname) +{ + int rc; + + socket_ofd.cb = localsock_cb; + rc = osmo_sock_unix_init_ofd(&socket_ofd, SOCK_DGRAM, 0, pathname, + OSMO_SOCK_F_BIND); + if (rc < 0) { + fprintf(stderr, "error: unable to set up local socket\n"); + exit(1); + } +}