neels has uploaded this change for review. (
https://gerrit.osmocom.org/c/osmo-upf/+/28686
)
Change subject: add cmdline --mockup-gtp for VTY tests
......................................................................
add cmdline --mockup-gtp for VTY tests
To avoid actions that require cap_net_admin permissions on build
servers, add this cmdline option to "dry run" all kernel GTP / NFT
actions.
On startup, osmo-upf opens sockets to GTP kernel module / NFT ctx.
However, on build servers, this would require giving cap_net_admin
permissions just to run the VTY tests.
Related: SYS#5599
Change-Id: I3b9c796186307fd8562abcff3f0ccfab0e88b6c8
---
M include/osmocom/upf/upf.h
M src/osmo-upf/osmo_upf_main.c
M src/osmo-upf/up_gtp_action.c
M src/osmo-upf/upf_gtp.c
M tests/Makefile.am
5 files changed, 37 insertions(+), 3 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-upf refs/changes/86/28686/1
diff --git a/include/osmocom/upf/upf.h b/include/osmocom/upf/upf.h
index b8065dd..449e253 100644
--- a/include/osmocom/upf/upf.h
+++ b/include/osmocom/upf/upf.h
@@ -73,6 +73,9 @@
struct up_endpoint *ep;
} pfcp;
struct {
+ /* --mockup-gtp cmdline option */
+ bool mockup;
+
/* GTP devices as in osmo-upf.cfg */
struct gtp_vty_cfg vty_cfg;
diff --git a/src/osmo-upf/osmo_upf_main.c b/src/osmo-upf/osmo_upf_main.c
index 302d957..883f827 100644
--- a/src/osmo-upf/osmo_upf_main.c
+++ b/src/osmo-upf/osmo_upf_main.c
@@ -64,6 +64,7 @@
const char *config_file;
int daemonize;
enum vty_ref_gen_mode vty_ref_gen_mode;
+ bool mockup_gtp;
} upf_cmdline_config = {
.config_file = "osmo-upf.cfg",
.vty_ref_gen_mode = VTY_REF_GEN_MODE_DEFAULT,
@@ -87,6 +88,9 @@
printf("\nVTY reference generation:\n");
printf(" --vty-ref-xml Generate the VTY reference XML output and
exit.\n");
printf(" --vty-ref-mode MODE Mode for --vty-ref-xml:\n");
+
+ printf("\nTesting:\n");
+ printf(" --mockup-gtp Do not use GTP kernel features, just
ack.\n");
/* List all VTY ref gen modes */
for (vty_ref_gen_mode_name = vty_ref_gen_mode_names; vty_ref_gen_mode_name->str;
vty_ref_gen_mode_name++)
printf(" %s: %s\n",
@@ -110,6 +114,9 @@
get_value_string(vty_ref_gen_mode_desc, upf_cmdline_config.vty_ref_gen_mode));
vty_dump_xml_ref_mode(stdout, upf_cmdline_config.vty_ref_gen_mode);
exit(0);
+ case 3:
+ upf_cmdline_config.mockup_gtp = true;
+ break;
default:
fprintf(stderr, "%s: error parsing cmdline options\n", prog_name);
exit(2);
@@ -128,6 +135,7 @@
{"version", 0, 0, 'V' },
{"vty-ref-mode", 1, &long_option, 1},
{"vty-ref-xml", 0, &long_option, 2},
+ {"mockup-gtp", 0, &long_option, 3},
{0, 0, 0, 0}
};
@@ -289,6 +297,7 @@
/* Parse options */
handle_options(argc, argv);
+ g_upf->gtp.mockup = upf_cmdline_config.mockup_gtp;
rc = vty_read_config_file(upf_cmdline_config.config_file, NULL);
if (rc < 0) {
diff --git a/src/osmo-upf/up_gtp_action.c b/src/osmo-upf/up_gtp_action.c
index 47aa3ac..1f2d96c 100644
--- a/src/osmo-upf/up_gtp_action.c
+++ b/src/osmo-upf/up_gtp_action.c
@@ -81,6 +81,12 @@
struct upf_gtp_dev *gtp_dev;
int rc;
+ if (g_upf->gtp.mockup) {
+ LOG_UP_GTP_ACTION(a, LOGL_ERROR, "--mockup-gtp active, skipping GTP action
%s\n",
+ enable ? "enable" : "disable");
+ return 0;
+ }
+
switch (a->kind) {
case UP_GTP_U_ENDECAPS:
/* use the first available GTP device.
diff --git a/src/osmo-upf/upf_gtp.c b/src/osmo-upf/upf_gtp.c
index e3435a9..d4065ef 100644
--- a/src/osmo-upf/upf_gtp.c
+++ b/src/osmo-upf/upf_gtp.c
@@ -95,6 +95,8 @@
static int upf_gtp_dev_destruct(struct upf_gtp_dev *dev);
+/* Allocate state for one GTP device, add to g_upf->gtp.devs and return the created
device. If state for the device of
+ * that name already exists, do nothing and return NULL. */
static struct upf_gtp_dev *upf_gtp_dev_alloc(const char *name, const char *local_addr)
{
struct upf_gtp_dev *dev = upf_gtp_dev_find_by_name(name);
@@ -157,7 +159,7 @@
int upf_gtp_dev_open(const char *name, bool create_gtp_dev, const char *local_addr, bool
listen_for_gtpv0, bool sgsn_mode)
{
- struct osmo_sockaddr any = {
+ const struct osmo_sockaddr any = {
.u.sin = {
.sin_family = AF_INET,
.sin_port = 0,
@@ -167,7 +169,14 @@
},
};
int rc;
- struct upf_gtp_dev *dev = upf_gtp_dev_alloc(name, local_addr);
+ struct upf_gtp_dev *dev;
+
+ if (g_upf->gtp.mockup) {
+ LOGP(DGTP, LOGL_NOTICE, "--mockup-gtp active: not opening GTP device
'%s'\n", name);
+ return 0;
+ }
+
+ dev = upf_gtp_dev_alloc(name, local_addr);
if (!dev)
return -EIO;
@@ -245,9 +254,16 @@
/* Open an MNL socket which allows to create and remove GTP devices (requires
CAP_NET_ADMIN). */
int upf_gtp_genl_open()
{
+ if (g_upf->gtp.mockup) {
+ LOGP(DGTP, LOGL_NOTICE, "--mockup-gtp active: not opening mnl_socket\n");
+ return 0;
+ }
+
+ /* Already open? */
if (g_upf->gtp.nl && g_upf->gtp.genl_id >= 0)
return 0;
+ /* sanity / paranoia: if re-opening, make sure the previous socket is closed */
if (g_upf->gtp.nl)
upf_gtp_genl_close();
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 66510f0..ab14ed3 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -48,7 +48,7 @@
vty-test:
osmo_verify_transcript_vty.py -v \
-n OsmoUPF -p 4275 \
- -r "$(top_builddir)/src/osmo-upf/osmo-upf -c
$(top_srcdir)/doc/examples/osmo-upf/osmo-upf.cfg" \
+ -r "$(top_builddir)/src/osmo-upf/osmo-upf --mockup-gtp -c
$(top_srcdir)/doc/examples/osmo-upf/osmo-upf.cfg" \
$(U) $(srcdir)/$(VTY_TEST)
check-local: atconfig $(TESTSUITE)
--
To view, visit
https://gerrit.osmocom.org/c/osmo-upf/+/28686
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-upf
Gerrit-Branch: master
Gerrit-Change-Id: I3b9c796186307fd8562abcff3f0ccfab0e88b6c8
Gerrit-Change-Number: 28686
Gerrit-PatchSet: 1
Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de>
Gerrit-MessageType: newchange