From owner-freebsd-net@freebsd.org Fri Dec 15 05:58:57 2017 Return-Path: Delivered-To: freebsd-net@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 16EA4E9C140 for ; Fri, 15 Dec 2017 05:58:57 +0000 (UTC) (envelope-from jim@netgate.com) Received: from mail-oi0-x230.google.com (mail-oi0-x230.google.com [IPv6:2607:f8b0:4003:c06::230]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id C6F6F68AA4 for ; Fri, 15 Dec 2017 05:58:56 +0000 (UTC) (envelope-from jim@netgate.com) Received: by mail-oi0-x230.google.com with SMTP id l6so5478207oih.11 for ; Thu, 14 Dec 2017 21:58:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=netgate.com; s=google; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=5rT23gZZh91gzZJdSdce7lzSNT350ch5Haxq39V4mDI=; b=nEake+i6eB52uqKTizIfGAVWzGLkT6dz2RCenbncdGZiyUr6qdTy2U/ObM2KuwFcdB p3wT6JfIRxwAYn8IDoueBTa2MnKqrom2v/s+1+z9hFZYo0k6Ay6liRjyyKgVfonxd/Q1 QqO6BclG0Upa16LxwQJyt+hPE0zyJ4WGnhwoY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=5rT23gZZh91gzZJdSdce7lzSNT350ch5Haxq39V4mDI=; b=SiMjvVxG8719NvNAjWtNDrjz+dt2juDxts4QW9tr1biilqHvbFtmGC/C76CtrAHdzU USkhulRGyGqnUs0LLuaI94j8F6wBPGy7gBrkkdyjJeB8N3NhfLRZJj29wEXkNUnn2amR NDsNRqdGhhylIyr9T3ImRoYwk5x2YJ8Zmnx3nmdHIcFJikrRBx4yfsJTyAVArc6bXQ8V pWSK9xkiVJZHu3wO55fn0HrbJDrHBG6tGeiEwJozreOvqx4vwirY8t1zEDdMv4dkFPl5 2+9XqGGZ8XMeXfHFalvkSJEXNVTKrLyJlk+v9kWd+FRJEf/uR20X91mwkAABPMg2PCvb 3mEw== X-Gm-Message-State: AKGB3mI5EsuYJ24eLGucezJF6mjxDAiii2gYR2jf7pTcRkKVg7IYEFCO YwrDp0Th3UbMqM6d9fA00iV3YQ== X-Google-Smtp-Source: ACJfBovy+NzbTKychHDx6ek0N1hLzta79MsqOz7BY51mJaZI7HFIMsH9FLbiC5eeJl6jRf0bkDOx3w== X-Received: by 10.202.194.214 with SMTP id s205mr5856092oif.357.1513317535735; Thu, 14 Dec 2017 21:58:55 -0800 (PST) Received: from [172.21.0.169] (65-36-116-65.dyn.grandenetworks.net. [65.36.116.65]) by smtp.gmail.com with ESMTPSA id b127sm2638610oih.18.2017.12.14.21.58.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Dec 2017 21:58:55 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 11.2 \(3445.5.20\)) Subject: Re: Netmap: Build a network SPAN/TAP from netmap From: Jim Thompson In-Reply-To: Date: Thu, 14 Dec 2017 23:58:54 -0600 Cc: "freebsd-net@freebsd.org" Content-Transfer-Encoding: quoted-printable Message-Id: <3F8E159B-33FC-428E-9A18-64CC298EDBDD@netgate.com> References: To: Ming Fu X-Mailer: Apple Mail (2.3445.5.20) X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 15 Dec 2017 05:58:57 -0000 > On Dec 14, 2017, at 12:00 PM, Ming Fu wrote: >=20 > Hi, >=20 > I am trying to explore the possibility to build a network SPAN/TAP = from netmap. Similar to the bridge sample, but all packet going through = the bridge also get copied to a SPAN port. How do I duplicate or clone = an incoming packet and send the original to bridge peer and the cloned = one to the SPAN port? Is there an API like FreeBsd m_copypacket() for = netmap? Would it work for Linux as well? >=20 > Thanks > Ming Ming, I=E2=80=99d look at adapting netmap monitors. = https://github.com/luigirizzo/netmap/blob/master/sys/dev/netmap/netmap_mon= itor.c For the rest of the solution, look at netmap_user.h, where it explains = how to open a port in monitor mode. https://github.com/luigirizzo/netmap/blob/master/sys/net/netmap_user.h Essentially, once you have an active netmap port e.g. netmap:ix0, you = can sniff the traffic by opening additional netmap ports named netmap:ix0/r (for rx traffic) or netmap:ix0/t (for tx) or even = netmap:ix0/rt (for both tx and rx) The rest of the code (to inject frames back down another interface) can = be lifted from the bridge sample. You could also look at SF-TAP. http://sf-tap.github.io Jim