From patchwork Fri Jan 15 15:46:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stuart Haslam X-Patchwork-Id: 59873 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp624881lbb; Fri, 15 Jan 2016 07:46:20 -0800 (PST) X-Received: by 10.140.25.149 with SMTP id 21mr14290772qgt.89.1452872780507; Fri, 15 Jan 2016 07:46:20 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id z192si13858846qka.1.2016.01.15.07.46.20; Fri, 15 Jan 2016 07:46:20 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dkim=neutral (body hash did not verify) header.i=@linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 0D0C061941; Fri, 15 Jan 2016 15:46:20 +0000 (UTC) Authentication-Results: lists.linaro.org; dkim=fail reason="verification failed; unprotected key" header.d=linaro.org header.i=@linaro.org header.b=UwQZgE+K; dkim-adsp=none (unprotected policy); dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 1A90F61944; Fri, 15 Jan 2016 15:46:15 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 9366661944; Fri, 15 Jan 2016 15:46:11 +0000 (UTC) Received: from mail-wm0-f45.google.com (mail-wm0-f45.google.com [74.125.82.45]) by lists.linaro.org (Postfix) with ESMTPS id 82B2B6193B for ; Fri, 15 Jan 2016 15:46:09 +0000 (UTC) Received: by mail-wm0-f45.google.com with SMTP id u188so28238278wmu.1 for ; Fri, 15 Jan 2016 07:46:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id; bh=cmMX7koY9onJWrFNRkOI9K44TraQQgcBa523dbOHMHM=; b=UwQZgE+KFlcLEntSk+VxVS3A2yBSMR8o0qtyBRN2CjEmi7WhUzNLDk3uIsYsa0OUYu vwY4KAQl1yASF6hWHyE3FTl6MydmJ/7Kkf/FKnqQhPJLi2TVAf6tecukergNhmhzSbZV kA6TKvpNJW//X+5T7W3PorU40zupU45MZJFNk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id; bh=cmMX7koY9onJWrFNRkOI9K44TraQQgcBa523dbOHMHM=; b=SF3Y9Z0I/i5iQ4z9z/YK8CUG7oiliXgmCpSKD0uYSRgU8MA4JelJMV8pEGLudW2TVC LqAKx8xCWNZ+P5hpUZ7c49vq0datqbsi2sMPzvE7ddgdQU68ZQze38O8bW71nA4dpiKS MgSCvKW/fiuIU2LnGm4Kzd8hXtM89sRe3bWmmKtl/08Fom7+iiTfSoI6LLy+qPbDRirc VVUewccBpy9vUVGUleM+DWO3HUUXh+sc2zUmh++iJ3JCnxEYgMZyhc+PqVpXm4j1qOWy qqaY/wlSN4CX44m74xvHIL0l9qq1fNAl/OQrowuQhTgrVk9V4f7B5zoTzPROIoSz22i1 OeVQ== X-Gm-Message-State: ALoCoQl5TR1Y6GRufXZhQq5fHCm2p5vM1QkFBll8/7y1lTS5M+V7xYcM/ImaoTsDIzM80ya5Buc3jRy503jFllY9Aq4mFvyHlg== X-Received: by 10.194.113.227 with SMTP id jb3mr10953660wjb.49.1452872768236; Fri, 15 Jan 2016 07:46:08 -0800 (PST) Received: from e106441.emea.arm.com ([2001:41d0:a:3cb4::1]) by smtp.gmail.com with ESMTPSA id c26sm3043224wmi.21.2016.01.15.07.46.07 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 15 Jan 2016 07:46:07 -0800 (PST) From: Stuart Haslam To: lng-odp@lists.linaro.org Date: Fri, 15 Jan 2016 15:46:05 +0000 Message-Id: <1452872765-14197-1-git-send-email-stuart.haslam@linaro.org> X-Mailer: git-send-email 2.1.1 X-Topics: patch Subject: [lng-odp] [PATCH] linux-generic: pktio: support multiple loop interfaces X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" The current implementation supports only a single loop interface named "loop", but it's sometimes useful to use multiple loopback interfaces to avoid the need to multiplex based on packet data. Allow interfaces named "loop" or "loopN" where supported numbers for N are 0-254. Signed-off-by: Stuart Haslam --- .../linux-generic/include/odp_packet_io_internal.h | 1 + platform/linux-generic/pktio/loop.c | 40 +++++++++++++++++----- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/platform/linux-generic/include/odp_packet_io_internal.h b/platform/linux-generic/include/odp_packet_io_internal.h index 4d73952..1645670 100644 --- a/platform/linux-generic/include/odp_packet_io_internal.h +++ b/platform/linux-generic/include/odp_packet_io_internal.h @@ -45,6 +45,7 @@ struct pktio_if_ops; typedef struct { odp_queue_t loopq; /**< loopback queue for "loop" device */ odp_bool_t promisc; /**< promiscuous mode state */ + unsigned char if_mac[ETH_ALEN]; /**< MAC address for the interface */ } pkt_loop_t; #ifdef HAVE_PCAP diff --git a/platform/linux-generic/pktio/loop.c b/platform/linux-generic/pktio/loop.c index 95644c4..911eca8 100644 --- a/platform/linux-generic/pktio/loop.c +++ b/platform/linux-generic/pktio/loop.c @@ -19,27 +19,50 @@ #include #include +#include #include -/* MAC address for the "loop" interface */ -static const char pktio_loop_mac[] = {0x02, 0xe9, 0x34, 0x80, 0x73, 0x01}; +/* MAC address for the "loop" interface. When a numbered interface is + * opened, the number suffix replaces the last digit of the MAC address, + * e.g. loop1 has MAC 02:e9:34:80:73:01 */ +static const char pktio_loop_mac[] = {0x02, 0xe9, 0x34, 0x80, 0x73, 0xff}; static int loopback_open(odp_pktio_t id, pktio_entry_t *pktio_entry, const char *devname, odp_pool_t pool ODP_UNUSED) { - if (strcmp(devname, "loop")) + char loopq_name[ODP_QUEUE_NAME_LEN]; + int loop_num = -1; + + if (strncmp(devname, "loop", 4)) return -1; - char loopq_name[ODP_QUEUE_NAME_LEN]; + devname += strlen("loop"); + + /* valid names are loop[0-254] */ + if (*devname != '\0') { + const char *p = devname; - snprintf(loopq_name, sizeof(loopq_name), "%" PRIu64 "-pktio_loopq", - odp_pktio_to_u64(id)); + while (*p != '\0') + if (!isdigit(*p++)) + return -1; + + loop_num = atoi(devname); + if (loop_num >= 0xff) + return -1; + } + + snprintf(loopq_name, sizeof(loopq_name), "%" PRIu64 "-pktio_loop%s", + odp_pktio_to_u64(id), devname); pktio_entry->s.pkt_loop.loopq = odp_queue_create(loopq_name, ODP_QUEUE_TYPE_POLL, NULL); if (pktio_entry->s.pkt_loop.loopq == ODP_QUEUE_INVALID) return -1; + memcpy(pktio_entry->s.pkt_loop.if_mac, pktio_loop_mac, ETH_ALEN); + if (loop_num != -1) + pktio_entry->s.pkt_loop.if_mac[ETH_ALEN-1] = loop_num; + return 0; } @@ -104,10 +127,9 @@ static int loopback_mtu_get(pktio_entry_t *pktio_entry ODP_UNUSED) return INT_MAX; } -static int loopback_mac_addr_get(pktio_entry_t *pktio_entry ODP_UNUSED, - void *mac_addr) +static int loopback_mac_addr_get(pktio_entry_t *pktio_entry, void *mac_addr) { - memcpy(mac_addr, pktio_loop_mac, ETH_ALEN); + memcpy(mac_addr, pktio_entry->s.pkt_loop.if_mac, ETH_ALEN); return ETH_ALEN; }