From owner-freebsd-net@freebsd.org Fri Apr 29 12:34:54 2016 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 9879BB1FD19 for ; Fri, 29 Apr 2016 12:34:54 +0000 (UTC) (envelope-from smithi@nimnet.asn.au) Received: from sola.nimnet.asn.au (paqi.nimnet.asn.au [115.70.110.159]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 09E231E05 for ; Fri, 29 Apr 2016 12:34:53 +0000 (UTC) (envelope-from smithi@nimnet.asn.au) Received: from localhost (localhost [127.0.0.1]) by sola.nimnet.asn.au (8.14.2/8.14.2) with ESMTP id u3TCYUuS031329; Fri, 29 Apr 2016 22:34:31 +1000 (EST) (envelope-from smithi@nimnet.asn.au) Date: Fri, 29 Apr 2016 22:34:30 +1000 (EST) From: Ian Smith To: lpa lpa cc: Nikolay Denev , "freebsd-net@freebsd.org" Subject: Re: Working divert socket example prog? In-Reply-To: Message-ID: <20160429221202.J16195@sola.nimnet.asn.au> References: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.21 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, 29 Apr 2016 12:34:54 -0000 On Fri, 29 Apr 2016 00:32:05 -0300, lpa lpa wrote: > On Thu, Apr 28, 2016 at 4:06 PM, Nikolay Denev wrote: >> Hi, >> >> Have you looked at the natd(8) source code? > yes but it's a complete application, it does a lot of stuff and I am > not able to "clean" it up to become a simple divert application which > reinjects packet so I can measure something. I was not able, so far, > to make thementioned divert-loop work, not breaking natd is a much > longer step to a non programmer You could have a look at Mike Makonnen's ipfw-classifyd, which diverts packets with the intent of applying Linux L7 filters to traffic, then feeding matching packets via dummynet pipes, originally for throttling P2P applications and such. You don't need to be interested in what it does with packets to benefit from knowing how it works; it's maybe an order of magnitude simpler than natd; and it can return from divert to different ipfw rule numbers. This didn't become a port, not sure why, but maybe it might help you (though you'd still need some coding to make it useful for your needs): http://people.freebsd.org/~mtm/ipfw-classifyd.tar.bz2 cheers, Ian > On Thu, Apr 28, 2016 at 7:21 AM, lpa lpa > wrote: > > Do anyone have a working example code of a divert loop program? > > > > I tried building this one[1] but it seems to be for FreeBSD 5 and won't > > build on latest system. I want to make simple measurement of pps rate > for a > > packet traveling inside a divert socket and getting reinjected back while > > printing some logs. > > > > However I am not a coder :( > > > > Thank you. > > > > [1]https://github.com/DianeRay/divert-loop/tree/master/divert-loop