From 7c03c08229ee0aa5f98ddf15d2dccb805e7f94b4 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Fri, 25 Mar 2016 17:56:07 +0200 Subject: [PATCH] vlan: Move ifconfig helpers to a separate file This removes final ioctl() use within vlan_init.c. Signed-off-by: Jouni Malinen --- hostapd/Android.mk | 1 + hostapd/Makefile | 1 + src/ap/vlan_ifconfig.c | 63 ++++++++++++++++++++++++++++++++++++++++++ src/ap/vlan_init.c | 53 ++--------------------------------- 4 files changed, 68 insertions(+), 50 deletions(-) create mode 100644 src/ap/vlan_ifconfig.c diff --git a/hostapd/Android.mk b/hostapd/Android.mk index f251475a0..67ca1295b 100644 --- a/hostapd/Android.mk +++ b/hostapd/Android.mk @@ -175,6 +175,7 @@ ifdef CONFIG_NO_VLAN L_CFLAGS += -DCONFIG_NO_VLAN else OBJS += src/ap/vlan_init.c +OBJS += src/ap/vlan_ifconfig.c OBJS += src/ap/vlan.c ifdef CONFIG_FULL_DYNAMIC_VLAN # Define CONFIG_FULL_DYNAMIC_VLAN to have hostapd manipulate bridges diff --git a/hostapd/Makefile b/hostapd/Makefile index c4fa4c082..5b3611afe 100644 --- a/hostapd/Makefile +++ b/hostapd/Makefile @@ -194,6 +194,7 @@ ifdef CONFIG_NO_VLAN CFLAGS += -DCONFIG_NO_VLAN else OBJS += ../src/ap/vlan_init.o +OBJS += ../src/ap/vlan_ifconfig.o OBJS += ../src/ap/vlan.o ifdef CONFIG_FULL_DYNAMIC_VLAN # Define CONFIG_FULL_DYNAMIC_VLAN to have hostapd manipulate bridges diff --git a/src/ap/vlan_ifconfig.c b/src/ap/vlan_ifconfig.c new file mode 100644 index 000000000..6a4d10cd4 --- /dev/null +++ b/src/ap/vlan_ifconfig.c @@ -0,0 +1,63 @@ +/* + * hostapd / VLAN ifconfig helpers + * Copyright 2003, Instant802 Networks, Inc. + * Copyright 2005-2006, Devicescape Software, Inc. + * Copyright (c) 2009, Jouni Malinen + * + * This software may be distributed under the terms of the BSD license. + * See README for more details. + */ + +#include "utils/includes.h" +#include +#include + +#include "utils/common.h" +#include "vlan_util.h" + + +int ifconfig_helper(const char *if_name, int up) +{ + int fd; + struct ifreq ifr; + + if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { + wpa_printf(MSG_ERROR, "VLAN: %s: socket(AF_INET,SOCK_STREAM) " + "failed: %s", __func__, strerror(errno)); + return -1; + } + + os_memset(&ifr, 0, sizeof(ifr)); + os_strlcpy(ifr.ifr_name, if_name, IFNAMSIZ); + + if (ioctl(fd, SIOCGIFFLAGS, &ifr) != 0) { + wpa_printf(MSG_ERROR, "VLAN: %s: ioctl(SIOCGIFFLAGS) failed " + "for interface %s: %s", + __func__, if_name, strerror(errno)); + close(fd); + return -1; + } + + if (up) + ifr.ifr_flags |= IFF_UP; + else + ifr.ifr_flags &= ~IFF_UP; + + if (ioctl(fd, SIOCSIFFLAGS, &ifr) != 0) { + wpa_printf(MSG_ERROR, "VLAN: %s: ioctl(SIOCSIFFLAGS) failed " + "for interface %s (up=%d): %s", + __func__, if_name, up, strerror(errno)); + close(fd); + return -1; + } + + close(fd); + return 0; +} + + +int ifconfig_up(const char *if_name) +{ + wpa_printf(MSG_DEBUG, "VLAN: Set interface %s up", if_name); + return ifconfig_helper(if_name, 1); +} diff --git a/src/ap/vlan_init.c b/src/ap/vlan_init.c index d2c511e1f..b8ca4f759 100644 --- a/src/ap/vlan_init.c +++ b/src/ap/vlan_init.c @@ -9,6 +9,9 @@ */ #include "utils/includes.h" +#include +/* Avoid conflicts due to NetBSD net/if.h if_type define with driver.h */ +#undef if_type #include "utils/common.h" #include "hostapd.h" @@ -18,56 +21,6 @@ #include "vlan_init.h" #include "vlan_util.h" -#include -#include - - -int ifconfig_helper(const char *if_name, int up) -{ - int fd; - struct ifreq ifr; - - if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { - wpa_printf(MSG_ERROR, "VLAN: %s: socket(AF_INET,SOCK_STREAM) " - "failed: %s", __func__, strerror(errno)); - return -1; - } - - os_memset(&ifr, 0, sizeof(ifr)); - os_strlcpy(ifr.ifr_name, if_name, IFNAMSIZ); - - if (ioctl(fd, SIOCGIFFLAGS, &ifr) != 0) { - wpa_printf(MSG_ERROR, "VLAN: %s: ioctl(SIOCGIFFLAGS) failed " - "for interface %s: %s", - __func__, if_name, strerror(errno)); - close(fd); - return -1; - } - - if (up) - ifr.ifr_flags |= IFF_UP; - else - ifr.ifr_flags &= ~IFF_UP; - - if (ioctl(fd, SIOCSIFFLAGS, &ifr) != 0) { - wpa_printf(MSG_ERROR, "VLAN: %s: ioctl(SIOCSIFFLAGS) failed " - "for interface %s (up=%d): %s", - __func__, if_name, up, strerror(errno)); - close(fd); - return -1; - } - - close(fd); - return 0; -} - - -int ifconfig_up(const char *if_name) -{ - wpa_printf(MSG_DEBUG, "VLAN: Set interface %s up", if_name); - return ifconfig_helper(if_name, 1); -} - static int vlan_if_add(struct hostapd_data *hapd, struct hostapd_vlan *vlan, int existsok)