From 8c33d4a485f1f5742211b7c1b4ea188949b4ed06 Mon Sep 17 00:00:00 2001 From: Alexander Couzens Date: Tue, 22 Dec 2020 15:42:01 +0100 Subject: gprs_ns2_fr: setup_device: allow to setup a new dahdi device When a dahdi device hasn't been set up yet, ioctl IF_GET_PROTO fails with invalid argument. Also fix the device check to skip ioctl's if the device is also in the correct state. Change-Id: I398d056546e35465a2944e1b4a86a8c93b3e5f7a --- src/gb/gprs_ns2_fr.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/gb/gprs_ns2_fr.c b/src/gb/gprs_ns2_fr.c index 1a6b92f7..1b0ec003 100644 --- a/src/gb/gprs_ns2_fr.c +++ b/src/gb/gprs_ns2_fr.c @@ -476,23 +476,24 @@ static int setup_device(const char *netif) req.ifr_settings.size = sizeof(buffer); req.ifr_settings.type = IF_GET_PROTO; + /* EINVAL is returned when no protocol has been set */ rc = ioctl(sock, SIOCWANDEV, &req); - if (rc < 0) { + if (rc < 0 && errno != EINVAL) { LOGP(DLNS, LOGL_ERROR, "%s: Unable to get FR protocol information: %s\n", netif, strerror(errno)); goto err; } /* check if the device is good */ - if (req.ifr_settings.type != IF_PROTO_FR && fr->lmi != LMI_NONE) { - LOGP(DLNS, LOGL_INFO, "%s: has correct frame relay mode and lmi\n", netif); + if (rc == 0 && req.ifr_settings.type == IF_PROTO_FR && fr->lmi == LMI_NONE) { + LOGP(DLNS, LOGL_NOTICE, "%s: has correct frame relay mode and lmi\n", netif); goto ifup; } /* modify the device to match */ rc = set_ifupdown(netif, false); if (rc) { - LOGP(DLNS, LOGL_ERROR, "Unable to bring up the device %s: %s\n", + LOGP(DLNS, LOGL_ERROR, "Unable to bring down the device %s: %s\n", netif, strerror(errno)); goto err; } @@ -516,6 +517,7 @@ static int setup_device(const char *netif) /* monitored events count */ fr->n393 = 4; + LOGP(DLNS, LOGL_INFO, "%s: Setting frame relay related parameters\n", netif); rc = ioctl(sock, SIOCWANDEV, &req); if (rc) { LOGP(DLNS, LOGL_ERROR, "%s: Unable to set FR protocol on information: %s\n", -- cgit v1.2.3