Commit d0f32d8a authored by Robert Schmidt's avatar Robert Schmidt

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)
parent ae5702d0
...@@ -88,21 +88,30 @@ static bool setInterfaceParameter(int sock_fd, const char *ifn, int af, const ch ...@@ -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; 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) 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}; struct ifreq ifr = {0};
strncpy(ifr.ifr_name, ifn, sizeof(ifr.ifr_name)); 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) { 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 { } else {
ifr.ifr_flags &= (~IFF_UP); ifr.ifr_flags &= ~IFF_UP;
} }
bool success = ioctl(sock_fd, SIOCSIFFLAGS, (caddr_t)&ifr) == 0; success = ioctl(sock_fd, SIOCSIFFLAGS, (caddr_t)&ifr) == 0;
if (!success) { if (!success)
const char* action = if_action == INTERFACE_DOWN ? "DOWN" : "UP"; goto fail_interface_state;
LOG_E(OIP, "Bringing interface %s for %s: ioctl call failed: %d, %s\n", action, ifn, errno, strerror(errno)); return true;
}
return success; 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) // non blocking full configuration of the interface (address, and the two lest octets of the address)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment