aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeels Hofmeyr <nhofmeyr@sysmocom.de>2015-12-02 15:43:10 +0100
committerNeels Hofmeyr <nhofmeyr@sysmocom.de>2015-12-03 11:47:12 +0100
commit996ec1d73150366fa105b7d42ba8003fb018fcf8 (patch)
treee28855041a38c61e5d437d40202e017e5145a10e
parent18d304961249c7815cf3a78ebd1697a4efd9ab42 (diff)
gtphub: wrap gtphub_write() for test suite.
Sponsored-by: On-Waves ehi
-rw-r--r--openbsc/include/openbsc/gtphub.h4
-rw-r--r--openbsc/src/gprs/Makefile.am4
-rw-r--r--openbsc/src/gprs/gtphub.c24
-rw-r--r--openbsc/src/gprs/gtphub_sock.c58
-rw-r--r--openbsc/tests/gtphub/Makefile.am3
-rw-r--r--openbsc/tests/gtphub/gtphub_test.c18
6 files changed, 84 insertions, 27 deletions
diff --git a/openbsc/include/openbsc/gtphub.h b/openbsc/include/openbsc/gtphub.h
index a260fed75..c98603b4e 100644
--- a/openbsc/include/openbsc/gtphub.h
+++ b/openbsc/include/openbsc/gtphub.h
@@ -510,3 +510,7 @@ void gtphub_resolved_ggsn(struct gtphub *hub, const char *apn_oi_str,
time_t now);
const char *gtphub_port_str(struct gtphub_peer_port *port);
+
+int gtphub_write(const struct osmo_fd *to,
+ const struct osmo_sockaddr *to_addr,
+ const uint8_t *buf, size_t buf_len);
diff --git a/openbsc/src/gprs/Makefile.am b/openbsc/src/gprs/Makefile.am
index 634948dfb..295fb86e8 100644
--- a/openbsc/src/gprs/Makefile.am
+++ b/openbsc/src/gprs/Makefile.am
@@ -34,8 +34,8 @@ osmo_sgsn_LDADD = \
-lgtp $(OSMO_LIBS) $(LIBOSMOABIS_LIBS) $(LIBCARES_LIBS) \
$(LIBCRYPTO_LIBS) -lrt
-osmo_gtphub_SOURCES = gtphub_main.c gtphub.c gtphub_ares.c gtphub_vty.c \
- sgsn_ares.c gprs_utils.c
+osmo_gtphub_SOURCES = gtphub_main.c gtphub.c gtphub_sock.c gtphub_ares.c \
+ gtphub_vty.c sgsn_ares.c gprs_utils.c
osmo_gtphub_LDADD = \
$(top_builddir)/src/libcommon/libcommon.a \
-lgtp $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS) $(LIBOSMOVTY_LIBS) \
diff --git a/openbsc/src/gprs/gtphub.c b/openbsc/src/gprs/gtphub.c
index 27c70166e..55b900492 100644
--- a/openbsc/src/gprs/gtphub.c
+++ b/openbsc/src/gprs/gtphub.c
@@ -1741,30 +1741,6 @@ static int gtphub_handle_pdp_ctx(struct gtphub *hub,
}
-static int gtphub_write(const struct osmo_fd *to,
- const struct osmo_sockaddr *to_addr,
- const uint8_t *buf, size_t buf_len)
-{
- errno = 0;
- ssize_t sent = sendto(to->fd, buf, buf_len, 0,
- (struct sockaddr*)&to_addr->a, to_addr->l);
- LOG(LOGL_DEBUG, "to %s\n", osmo_sockaddr_to_str(to_addr));
-
- if (sent == -1) {
- LOG(LOGL_ERROR, "error: %s\n", strerror(errno));
- return -EINVAL;
- }
-
- if (sent != buf_len)
- LOG(LOGL_ERROR, "sent(%d) != data_len(%d)\n",
- (int)sent, (int)buf_len);
- else
- LOG(LOGL_DEBUG, "Sent %d\n%s\n",
- (int)sent, osmo_hexdump(buf, sent));
-
- return 0;
-}
-
static int gtphub_send_del_pdp_ctx(struct gtphub *hub,
struct gtphub_tunnel *tun,
int to_side)
diff --git a/openbsc/src/gprs/gtphub_sock.c b/openbsc/src/gprs/gtphub_sock.c
new file mode 100644
index 000000000..6ea1735c4
--- /dev/null
+++ b/openbsc/src/gprs/gtphub_sock.c
@@ -0,0 +1,58 @@
+/* GTP Hub Implementation */
+
+/* (C) 2015 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
+ * All Rights Reserved
+ *
+ * gtphub_sock.c.
+ *
+ * This file is kept separate so that these functions can be wrapped for
+ * gtphub_test.c. When a function and its callers are in the same compilational
+ * unit, the wrappability may be optimized away.
+ *
+ * Author: Neels Hofmeyr
+ *
+ * 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 Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <openbsc/gtphub.h>
+#include <openbsc/debug.h>
+
+/* Convenience makro, note: only within this C file. */
+#define LOG(level, fmt, args...) \
+ LOGP(DGTPHUB, level, fmt, ##args)
+
+int gtphub_write(const struct osmo_fd *to,
+ const struct osmo_sockaddr *to_addr,
+ const uint8_t *buf, size_t buf_len)
+{
+ errno = 0;
+ ssize_t sent = sendto(to->fd, buf, buf_len, 0,
+ (struct sockaddr*)&to_addr->a, to_addr->l);
+ LOG(LOGL_DEBUG, "to %s\n", osmo_sockaddr_to_str(to_addr));
+
+ if (sent == -1) {
+ LOG(LOGL_ERROR, "error: %s\n", strerror(errno));
+ return -EINVAL;
+ }
+
+ if (sent != buf_len)
+ LOG(LOGL_ERROR, "sent(%d) != data_len(%d)\n",
+ (int)sent, (int)buf_len);
+ else
+ LOG(LOGL_DEBUG, "Sent %d\n%s\n",
+ (int)sent, osmo_hexdump(buf, sent));
+
+ return 0;
+}
+
diff --git a/openbsc/tests/gtphub/Makefile.am b/openbsc/tests/gtphub/Makefile.am
index bcaf4fa06..dcb721150 100644
--- a/openbsc/tests/gtphub/Makefile.am
+++ b/openbsc/tests/gtphub/Makefile.am
@@ -13,7 +13,8 @@ endif
gtphub_test_SOURCES = gtphub_test.c
gtphub_test_LDFLAGS = \
-Wl,--wrap=gtphub_resolve_ggsn_addr \
- -Wl,--wrap=gtphub_ares_init
+ -Wl,--wrap=gtphub_ares_init \
+ -Wl,--wrap=gtphub_write
gtphub_test_LDADD = \
$(top_builddir)/src/gprs/gtphub.o \
diff --git a/openbsc/tests/gtphub/gtphub_test.c b/openbsc/tests/gtphub/gtphub_test.c
index 0d93e5a0e..0992d7972 100644
--- a/openbsc/tests/gtphub/gtphub_test.c
+++ b/openbsc/tests/gtphub/gtphub_test.c
@@ -508,6 +508,24 @@ int __wrap_gtphub_ares_init(struct gtphub *hub)
return 0;
}
+/* override, requires '-Wl,--wrap=gtphub_write' */
+int __real_gtphub_write(const struct osmo_fd *to,
+ const struct osmo_sockaddr *to_addr,
+ const uint8_t *buf, size_t buf_len);
+
+int __wrap_gtphub_write(const struct osmo_fd *to,
+ const struct osmo_sockaddr *to_addr,
+ const uint8_t *buf, size_t buf_len)
+{
+ printf("Out-of-band gtphub_write(%d):\n"
+ "to %s\n"
+ "%s\n",
+ (int)buf_len,
+ osmo_sockaddr_to_str(to_addr),
+ osmo_hexdump(buf, buf_len));
+ return 0;
+}
+
#define buf_len 1024
static uint8_t buf[buf_len];
static uint8_t *reply_buf;