diff --git a/src/osmo-upf/upf_gtp.c b/src/osmo-upf/upf_gtp.c index e2c6d07..528937b 100644 --- a/src/osmo-upf/upf_gtp.c +++ b/src/osmo-upf/upf_gtp.c @@ -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 */