upf_gtp: automatically delete 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
This commit is contained in:
Oliver Smith
2024-12-17 13:26:56 +01:00
parent 12d7cf87a9
commit 81ca6a0d16

View File

@@ -178,6 +178,13 @@ static int dev_resolve_ifidx(struct upf_gtp_dev *dev)
return 0;
}
static int upf_gtp_dev_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 @@ int upf_gtp_dev_open(const char *name, bool create_gtp_dev, const char *local_ad
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 = upf_gtp_dev_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 = upf_gtp_dev_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 */