From owner-freebsd-net@FreeBSD.ORG Sun Aug 4 19:13:11 2013 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 7C69BAA for ; Sun, 4 Aug 2013 19:13:11 +0000 (UTC) (envelope-from rmind@netbsd.org) Received: from mail.netbsd.org (mail.NetBSD.org [IPv6:2001:4f8:3:7::25]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 6B26224E0 for ; Sun, 4 Aug 2013 19:13:11 +0000 (UTC) Received: from ws (localhost [IPv6:::1]) by mail.netbsd.org (Postfix) with SMTP id 2FFBB14A152; Sun, 4 Aug 2013 19:13:10 +0000 (UTC) Date: Sun, 4 Aug 2013 20:12:49 +0100 From: Mindaugas Rasiukevicius To: tech-net@netbsd.org, freebsd-net@freebsd.org Subject: BPF_MISC+BPF_COP and BPF_COPX X-Mailer: mail(1) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-Id: <20130804191310.2FFBB14A152@mail.netbsd.org> Cc: guy@alum.mit.edu 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:13:11 -0000 Hello, 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. BPF_STMT(BPF_MISC+BPF_COP, 0), /* A <- funcs[0](...) */ typedef uint32_t(*bpf_copfunc_t)(struct mbuf *pkt, uint32_t A, uint32_t *M); int bpf_set_cop(bpf_ctx_t *c, bpf_copfunc_t funcs[], size_t n); 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. Note that bpf_filter(9) would need to take some context structure (which is preferable in general). Comments? -- Mindaugas