From d0f32d8aad72ff433a6b33016d8137858584890e Mon Sep 17 00:00:00 2001 From: Robert Schmidt Date: Thu, 1 Aug 2024 18:46:07 +0200 Subject: [PATCH] Refactor change_interface_state() - Read interface flags before setting status to not inadvertently overwrite existing flags - Set interface flag point-to-point, remove multicast (I think a UE is not supposed to send anywhere else than to the UPF, so it seems to not make sense to declare the interface as multicast) --- openair2/RRC/NAS/nas_config.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/openair2/RRC/NAS/nas_config.c b/openair2/RRC/NAS/nas_config.c index f744c065c5..c1e85a3360 100644 --- a/openair2/RRC/NAS/nas_config.c +++ b/openair2/RRC/NAS/nas_config.c @@ -88,21 +88,30 @@ static bool setInterfaceParameter(int sock_fd, const char *ifn, int af, const ch typedef enum { INTERFACE_DOWN, INTERFACE_UP } if_action_t; static bool change_interface_state(int sock_fd, const char *ifn, if_action_t if_action) { + const char* action = if_action == INTERFACE_DOWN ? "DOWN" : "UP"; + struct ifreq ifr = {0}; strncpy(ifr.ifr_name, ifn, sizeof(ifr.ifr_name)); + /* get flags of this interface: see netdevice(7) */ + bool success = ioctl(sock_fd, SIOCGIFFLAGS, (caddr_t)&ifr) == 0; + if (!success) + goto fail_interface_state; if (if_action == INTERFACE_UP) { - ifr.ifr_flags |= IFF_UP | IFF_NOARP | IFF_MULTICAST; + ifr.ifr_flags |= IFF_UP | IFF_NOARP | IFF_POINTOPOINT; + ifr.ifr_flags &= ~IFF_MULTICAST; } else { - ifr.ifr_flags &= (~IFF_UP); + ifr.ifr_flags &= ~IFF_UP; } - bool success = ioctl(sock_fd, SIOCSIFFLAGS, (caddr_t)&ifr) == 0; - if (!success) { - const char* action = if_action == INTERFACE_DOWN ? "DOWN" : "UP"; - LOG_E(OIP, "Bringing interface %s for %s: ioctl call failed: %d, %s\n", action, ifn, errno, strerror(errno)); - } - return success; + success = ioctl(sock_fd, SIOCSIFFLAGS, (caddr_t)&ifr) == 0; + if (!success) + goto fail_interface_state; + return true; + +fail_interface_state: + LOG_E(OIP, "Bringing interface %s for %s: ioctl call failed: %d, %s\n", action, ifn, errno, strerror(errno)); + return false; } // non blocking full configuration of the interface (address, and the two lest octets of the address)