From owner-freebsd-net@FreeBSD.ORG Sun Aug 4 19:31:40 2013 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 6D406881 for ; Sun, 4 Aug 2013 19:31:40 +0000 (UTC) (envelope-from rpaulo@felyko.com) Received: from felyko.com (felyko.com [IPv6:2607:f2f8:a528::3:1337:ca7]) by mx1.freebsd.org (Postfix) with ESMTP id 53DDE25D0 for ; Sun, 4 Aug 2013 19:31:40 +0000 (UTC) Received: from [IPv6:2601:9:4d00:119:c1a4:5299:ada4:3d28] (unknown [IPv6:2601:9:4d00:119:c1a4:5299:ada4:3d28]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by felyko.com (Postfix) with ESMTPSA id C3B6B3981E; Sun, 4 Aug 2013 12:31:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=felyko.com; s=mail; t=1375644700; bh=QcO4qCyOiz/o6WYVPnWUUac2366/ohoBLgjrhKnw7NA=; h=Subject:From:In-Reply-To:Date:Cc:References:To; b=ca2my3TGdNU1gbTcBPuEehayW3e3glo5zn3WpqDjL7elehkjbXr44MyFL7l4u7EpZ Za7wgHfsfE4A0qzodBthE5XhUylE3H2/RutdnQsfxplbxQwSwJhgjGPuGwuPFcYo5O pEO0uSLX9wLBXvZPmYkR53bie+jui5GeLevBLSMg= Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 6.5 \(1508\)) Subject: Re: BPF_MISC+BPF_COP and BPF_COPX From: Rui Paulo In-Reply-To: <20130804191310.2FFBB14A152@mail.netbsd.org> Date: Sun, 4 Aug 2013 12:31:38 -0700 Content-Transfer-Encoding: quoted-printable Message-Id: <9813E50B-C557-4FE1-BADF-A2CFFCBB8BD7@felyko.com> References: <20130804191310.2FFBB14A152@mail.netbsd.org> To: Mindaugas Rasiukevicius X-Mailer: Apple Mail (2.1508) Cc: tech-net@netbsd.org, guy@alum.mit.edu, freebsd-net@freebsd.org X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 04 Aug 2013 19:31:40 -0000 On 4 Aug 2013, at 12:12, Mindaugas Rasiukevicius = wrote: > Hello, >=20 > I would like propose new BPF instructions for the misc category: = BPF_COP > and BPF_COPX. It would provide a capability of calling an external > function - think of BPF "coprocessor". The argument for BPF_COP is an > index to a pre-loaded array of function pointers. BPF_COPX takes the > function index from the register X rather than a constant. >=20 > BPF_STMT(BPF_MISC+BPF_COP, 0), /* A <- funcs[0](...) */ >=20 > typedef uint32_t(*bpf_copfunc_t)(struct mbuf *pkt, > uint32_t A, uint32_t *M); >=20 > int bpf_set_cop(bpf_ctx_t *c, bpf_copfunc_t funcs[], size_t n); >=20 > The arguments passed to a called function would be the packet, = accumulator > and the memory store. The return value would be stored in the = accumulator > and the register X would be reset to 0. Note that the function may = also > change the memory store. If the function index is out of range, then = the > register X would be set to 0xffffffff. >=20 > Note that bpf_filter(9) would need to take some context structure = (which is > preferable in general). >=20 > Comments? Why do you need this in the first place?=20 Are you sure this is a safe design? Adding this functionality to BPF = makes me a little nervous as an error in the implementation leads to = kernel code execution (I could be able to call random kernel functions). -- Rui Paulo