From patchwork Fri Aug 1 16:01:12 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 34724 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f72.google.com (mail-oa0-f72.google.com [209.85.219.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 2F852202A1 for ; Fri, 1 Aug 2014 16:04:40 +0000 (UTC) Received: by mail-oa0-f72.google.com with SMTP id m1sf21189913oag.7 for ; Fri, 01 Aug 2014 09:04:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:mime-version:cc:subject:precedence:list-id :list-unsubscribe:list-post:list-help:list-subscribe:sender :errors-to:x-original-sender:x-original-authentication-results :mailing-list:list-archive:content-length:content-type :content-transfer-encoding; bh=pc8qgudgzCz7VRLALI2xCjyMnqcnMc92XP/cOfKYrcs=; b=B/07l4/FIbpBFvA7izJEWnkH0KINekpMBpWhpeEKPcW5wslP/BBoxE440RLHZAnt77 Q4q+RE9brVWF8GSy7mGhreiHDpTltcPZYRHcuQqMBoSHLekVQ97a6KhuLZaGT08idYL0 0WXkv1fShm4rJr76e7U3kEzin/TYmaVZdc3Q4N8tOoPJDwvz79ulk3CIBDrqfKosRdc9 WjRwsDkLXzdmiRuARbuDoMOPXwB85uCSaK+YfJDbIPjTdUcnEt3KCianHx7MLPfWVCJq 08dgXSU2McY7pjpshho34o3tBX+bEbyoXawt9SLD2IaETS4IwCbSEZytO+78Nyt/tv4/ xHMw== X-Gm-Message-State: ALoCoQmydebgAv+FbpZAC/KBOfHjG19sbt9usqE2s2feV5EGI3AL6EHMOKMp5bwqg0I9l2lMBXaZ X-Received: by 10.182.27.35 with SMTP id q3mr2612054obg.34.1406909079081; Fri, 01 Aug 2014 09:04:39 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.18.194 with SMTP id 60ls1345891qgf.7.gmail; Fri, 01 Aug 2014 09:04:39 -0700 (PDT) X-Received: by 10.220.50.8 with SMTP id x8mr7508993vcf.18.1406909078977; Fri, 01 Aug 2014 09:04:38 -0700 (PDT) Received: from mail-vc0-f180.google.com (mail-vc0-f180.google.com [209.85.220.180]) by mx.google.com with ESMTPS id py3si7683576vdb.107.2014.08.01.09.04.38 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 01 Aug 2014 09:04:38 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.180 as permitted sender) client-ip=209.85.220.180; Received: by mail-vc0-f180.google.com with SMTP id ij19so6836837vcb.25 for ; Fri, 01 Aug 2014 09:04:38 -0700 (PDT) X-Received: by 10.52.129.200 with SMTP id ny8mr6233768vdb.27.1406909078859; Fri, 01 Aug 2014 09:04:38 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp122085vcb; Fri, 1 Aug 2014 09:04:38 -0700 (PDT) X-Received: by 10.68.191.34 with SMTP id gv2mr7405693pbc.13.1406909077742; Fri, 01 Aug 2014 09:04:37 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id d11si7396047igz.33.2014.08.01.09.04.37 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 01 Aug 2014 09:04:37 -0700 (PDT) Received-SPF: none (google.com: xen-devel-bounces@lists.xen.org does not designate permitted sender hosts) client-ip=50.57.142.19; Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XDFHr-0006ni-FM; Fri, 01 Aug 2014 16:02:31 +0000 Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XDFHq-0006mr-8f for xen-devel@lists.xensource.com; Fri, 01 Aug 2014 16:02:30 +0000 Received: from [85.158.143.35:3807] by server-3.bemta-4.messagelabs.com id 62/91-06192-51ABBD35; Fri, 01 Aug 2014 16:02:29 +0000 X-Env-Sender: Stefano.Stabellini@citrix.com X-Msg-Ref: server-8.tower-21.messagelabs.com!1406908943!12946099!3 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n X-StarScan-Received: X-StarScan-Version: 6.11.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 27250 invoked from network); 1 Aug 2014 16:02:28 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-8.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 1 Aug 2014 16:02:28 -0000 X-IronPort-AV: E=Sophos;i="5.01,780,1400025600"; d="scan'208";a="158517042" Received: from ukmail1.uk.xensource.com (10.80.16.128) by smtprelay.citrix.com (10.13.107.78) with Microsoft SMTP Server id 14.3.181.6; Fri, 1 Aug 2014 12:02:27 -0400 Received: from kaball.uk.xensource.com ([10.80.2.59]) by ukmail1.uk.xensource.com with esmtp (Exim 4.69) (envelope-from ) id 1XDFHh-0006OT-Vw; Fri, 01 Aug 2014 17:02:22 +0100 From: Stefano Stabellini To: Date: Fri, 1 Aug 2014 17:01:12 +0100 Message-ID: <1406908873-17256-2-git-send-email-stefano.stabellini@eu.citrix.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: MIME-Version: 1.0 X-DLP: MIA1 Cc: Roger Pau Monne , xen-devel@lists.xensource.com, qemu-devel@nongnu.org, Stefano Stabellini Subject: [Xen-devel] [PULL 2/3] tap-bsd: implement a FreeBSD only version of tap_open X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Post: , List-Help: , List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: stefano.stabellini@eu.citrix.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.180 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Archive: From: Roger Pau Monne The current behaviour of tap_open for BSD systems differ greatly from it's Linux counterpart. Since FreeBSD supports interface renaming and tap device cloning by opening /dev/tap, implement a FreeBSD specific version of tap_open that behaves like it's Linux counterpart. This is specially important for toolstacks that use Qemu (like Xen libxl), in order to have a unified behaviour across suported platforms. Signed-off-by: Roger Pau Monné Signed-off-by: Stefano Stabellini Reviewed-by: Stefan Hajnoczi --- net/tap-bsd.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/net/tap-bsd.c b/net/tap-bsd.c index 90f8a02..bf91bd0 100644 --- a/net/tap-bsd.c +++ b/net/tap-bsd.c @@ -27,12 +27,13 @@ #include "sysemu/sysemu.h" #include "qemu/error-report.h" -#ifdef __NetBSD__ +#if defined(__NetBSD__) || defined(__FreeBSD__) #include #include #include #endif +#ifndef __FreeBSD__ int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required, int mq_required) { @@ -108,6 +109,73 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr, return fd; } +#else /* __FreeBSD__ */ + +#define PATH_NET_TAP "/dev/tap" + +int tap_open(char *ifname, int ifname_size, int *vnet_hdr, + int vnet_hdr_required, int mq_required) +{ + int fd, s, ret; + struct ifreq ifr; + + TFR(fd = open(PATH_NET_TAP, O_RDWR)); + if (fd < 0) { + error_report("could not open %s: %s", PATH_NET_TAP, strerror(errno)); + return -1; + } + + memset(&ifr, 0, sizeof(ifr)); + + ret = ioctl(fd, TAPGIFNAME, (void *)&ifr); + if (ret < 0) { + error_report("could not get tap interface name"); + goto error; + } + + if (ifname[0] != '\0') { + /* User requested the interface to have a specific name */ + s = socket(AF_LOCAL, SOCK_DGRAM, 0); + if (s < 0) { + error_report("could not open socket to set interface name"); + goto error; + } + ifr.ifr_data = ifname; + ret = ioctl(s, SIOCSIFNAME, (void *)&ifr); + close(s); + if (ret < 0) { + error_report("could not set tap interface name"); + goto error; + } + } else { + pstrcpy(ifname, ifname_size, ifr.ifr_name); + } + + if (*vnet_hdr) { + /* BSD doesn't have IFF_VNET_HDR */ + *vnet_hdr = 0; + + if (vnet_hdr_required && !*vnet_hdr) { + error_report("vnet_hdr=1 requested, but no kernel " + "support for IFF_VNET_HDR available"); + goto error; + } + } + if (mq_required) { + error_report("mq_required requested, but not kernel support" + "for IFF_MULTI_QUEUE available"); + goto error; + } + + fcntl(fd, F_SETFL, O_NONBLOCK); + return fd; + +error: + close(fd); + return -1; +} +#endif /* __FreeBSD__ */ + int tap_set_sndbuf(int fd, const NetdevTapOptions *tap) { return 0;