changeset 14:d9db8661d9f3

smsc-daemon: add local socket for sendmt
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 27 Aug 2023 17:15:30 -0800
parents 2c35aad69fea
children ce6bcb84ca30
files smsc-daemon/Makefile smsc-daemon/main.c smsc-daemon/send_mt.c
diffstat 3 files changed, 66 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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
 
--- 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 <ctype.h>
 #include <string.h>
 #include <stdio.h>
+#include <stdint.h>
 #include <stdlib.h>
 #include <errno.h>
 #include <signal.h>
@@ -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);
--- /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 <sys/types.h>
+#include <sys/socket.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <errno.h>
+
+#include <osmocom/core/msgb.h>
+#include <osmocom/core/socket.h>
+#include <osmocom/core/select.h>
+#include <osmocom/core/utils.h>
+#include <osmocom/core/logging.h>
+
+#include <osmocom/gsupclient/gsup_client.h>
+
+#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);
+	}
+}