osmith has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-upf/+/39161?usp=email )
Change subject: upf_gtp: automatically clean old gtp devices ......................................................................
upf_gtp: automatically clean old gtp devices
If osmo-upf crashes without running the destructor, we may have a leftover gtp device. This can be simulated with "killall -9 osmo-upf".
Clean it up automatically.
Related: SYS#7240 Depends: libgtpnl Ib99bd8eed854014a5c9118c23e4058a41f3145f2 Change-Id: I7bb5c1ed51f4e05964688ee77b8de77fd3c0f345 --- M src/osmo-upf/upf_gtp.c 1 file changed, 14 insertions(+), 4 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-upf refs/changes/61/39161/1
diff --git a/src/osmo-upf/upf_gtp.c b/src/osmo-upf/upf_gtp.c index e2c6d07..78acd47 100644 --- a/src/osmo-upf/upf_gtp.c +++ b/src/osmo-upf/upf_gtp.c @@ -178,6 +178,13 @@ return 0; }
+static int dev_gtp_create(struct upf_gtp_dev *dev, int gtp0_fd, int gtp1_fd) +{ + if (dev->sgsn_mode) + return gtp_dev_create_sgsn(-1, dev->name, gtp0_fd, gtp1_fd); + return gtp_dev_create(-1, dev->name, gtp0_fd, gtp1_fd); +} + int upf_gtp_dev_open(const char *name, bool create_gtp_dev, const char *local_addr, bool listen_for_gtpv0, bool sgsn_mode) { const struct osmo_sockaddr any = { @@ -235,10 +242,13 @@ if (create_gtp_dev) { int gtp0_fd = listen_for_gtpv0 ? dev->gtpv0.ofd.fd : -1; int gtp1_fd = dev->gtpv1.ofd.fd; - if (dev->sgsn_mode) - rc = gtp_dev_create_sgsn(-1, dev->name, gtp0_fd, gtp1_fd); - else - rc = gtp_dev_create(-1, dev->name, gtp0_fd, gtp1_fd); + + rc = dev_gtp_create(dev, gtp0_fd, gtp1_fd); + if (rc == -EEXIST && gtp_dev_destroy(dev->name) == 0) { + LOG_GTP_DEV(dev, LOGL_ERROR, "deleted GTP device from unclean shutdown\n"); + rc = dev_gtp_create(dev, gtp0_fd, gtp1_fd); + } + if (rc < 0) { LOG_GTP_DEV(dev, LOGL_ERROR, "Cannot create GTP device: rc=%d\n", rc); /* name = NULL: signal to the destructor that it does not need to delete the device */