From patchwork Thu Aug 9 09:55:11 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: michael-dev X-Patchwork-Id: 176041 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from maxx.maxx.shmoo.com (maxx.shmoo.com [205.134.188.171]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "maxx.shmoo.com", Issuer "CA Cert Signing Authority" (not verified)) by ozlabs.org (Postfix) with ESMTPS id E3C7E2C00D6 for ; Thu, 9 Aug 2012 19:55:45 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 569C89C224; Thu, 9 Aug 2012 05:55:43 -0400 (EDT) X-Virus-Scanned: amavisd-new at maxx.shmoo.com Received: from maxx.maxx.shmoo.com ([127.0.0.1]) by localhost (maxx.shmoo.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id CQN9sQhyKFlt; Thu, 9 Aug 2012 05:55:43 -0400 (EDT) Received: from maxx.shmoo.com (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 812169C34F; Thu, 9 Aug 2012 05:55:25 -0400 (EDT) X-Original-To: mailman-post+hostap@maxx.shmoo.com Delivered-To: mailman-post+hostap@maxx.shmoo.com Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id CB9BB9C235 for ; Thu, 9 Aug 2012 05:55:23 -0400 (EDT) X-Virus-Scanned: amavisd-new at maxx.shmoo.com Received: from maxx.maxx.shmoo.com ([127.0.0.1]) by localhost (maxx.shmoo.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 3iVXtj26aJlV for ; Thu, 9 Aug 2012 05:55:20 -0400 (EDT) Received: from a251.fem.tu-ilmenau.de (gast-001.fem.tu-ilmenau.de [141.24.44.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 350779C22B for ; Thu, 9 Aug 2012 05:55:12 -0400 (EDT) Received: from localhost6.localdomain6 (localhost.localdomain [127.0.0.1]) by konsullaptop.a-keller (Postfix) with ESMTP id BBED022156A; Thu, 9 Aug 2012 11:55:11 +0200 (CEST) Subject: [PATCH v2 3/4] use netlink to remove vlan interface To: hostap@lists.shmoo.com From: Michael Braun Date: Thu, 09 Aug 2012 11:55:11 +0200 Message-ID: <20120809095511.14256.49884.stgit@localhost6.localdomain6> In-Reply-To: <20120809095325.14256.38207.stgit@localhost6.localdomain6> References: <20120809095325.14256.38207.stgit@localhost6.localdomain6> User-Agent: StGit/0.15 MIME-Version: 1.0 Cc: projekt-wlan@fem.tu-ilmenau.de X-BeenThere: hostap@lists.shmoo.com X-Mailman-Version: 2.1.9 Precedence: list List-Id: HostAP Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: hostap-bounces@lists.shmoo.com Errors-To: hostap-bounces@lists.shmoo.com --- src/ap/vlan_init.c | 35 ----------------------------------- src/ap/vlan_util.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/ap/vlan_util.h | 1 + 3 files changed, 53 insertions(+), 35 deletions(-) diff --git a/src/ap/vlan_init.c b/src/ap/vlan_init.c index b1e8f42..8f6be69 100644 --- a/src/ap/vlan_init.c +++ b/src/ap/vlan_init.c @@ -336,41 +336,6 @@ static int br_getnumports(const char *br_name) } -static int vlan_rem(const char *if_name) -{ - int fd; - struct vlan_ioctl_args if_request; - - wpa_printf(MSG_DEBUG, "VLAN: vlan_rem(%s)", if_name); - if ((os_strlen(if_name) + 1) > sizeof(if_request.device1)) { - wpa_printf(MSG_ERROR, "VLAN: Interface name too long: '%s'", - if_name); - return -1; - } - - 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(&if_request, 0, sizeof(if_request)); - - os_strlcpy(if_request.device1, if_name, sizeof(if_request.device1)); - if_request.cmd = DEL_VLAN_CMD; - - if (ioctl(fd, SIOCSIFVLAN, &if_request) < 0) { - wpa_printf(MSG_ERROR, "VLAN: %s: DEL_VLAN_CMD failed for %s: " - "%s", __func__, if_name, strerror(errno)); - close(fd); - return -1; - } - - close(fd); - return 0; -} - - static void vlan_newlink(char *ifname, struct hostapd_data *hapd) { char vlan_ifname[IFNAMSIZ]; diff --git a/src/ap/vlan_util.c b/src/ap/vlan_util.c index 3c2ccc8..99f1fa2 100644 --- a/src/ap/vlan_util.c +++ b/src/ap/vlan_util.c @@ -126,4 +126,56 @@ vlan_add_error: return ret; } + +int vlan_rem(const char *if_name) +{ + int ret = -1; + struct nl_sock *handle = 0; + struct nl_cache *cache = 0; + struct rtnl_link *link = 0; + + wpa_printf(MSG_DEBUG, "VLAN: vlan_rem(if_name=%s)", + if_name); + + handle = nl_socket_alloc(); + if (!handle) { + wpa_printf(MSG_ERROR, "VLAN: failed to open netlink socket"); + goto vlan_rem_error; + } + + if (nl_connect(handle, NETLINK_ROUTE) < 0) { + wpa_printf(MSG_ERROR, "VLAN: failed to connect to netlink"); + goto vlan_rem_error; + } + + if (rtnl_link_alloc_cache(handle, AF_UNSPEC, &cache) < 0) { + cache = NULL; + wpa_printf(MSG_ERROR, "VLAN: failed to alloc cache"); + goto vlan_rem_error; + } + + if (!(link = rtnl_link_get_by_name(cache, if_name))) { + /* link does not exist */ + wpa_printf(MSG_ERROR, "VLAN: interface %s does not exists", if_name); + goto vlan_rem_error; + } + + if (rtnl_link_delete(handle, link) < 0) { + wpa_printf(MSG_ERROR, "VLAN: failed to remove link %s", if_name); + goto vlan_rem_error; + } + + ret = 0; + +vlan_rem_error: + if (link) + rtnl_link_put(link); + if (cache) + nl_cache_free(cache); + if (handle) + nl_socket_free(handle); + return ret; +} + + #endif diff --git a/src/ap/vlan_util.h b/src/ap/vlan_util.h index 673c546..1a54b1b 100644 --- a/src/ap/vlan_util.h +++ b/src/ap/vlan_util.h @@ -10,5 +10,6 @@ #define VLAN_UTIL_H int vlan_add(const char *if_name, int vid, const char* vlan_if_name); +int vlan_rem(const char *if_name); #endif