From owner-freebsd-bugs@FreeBSD.ORG Mon Oct 18 11:30:26 2004 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 4E37216A4CF for ; Mon, 18 Oct 2004 11:30:26 +0000 (GMT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 13D3743D46 for ; Mon, 18 Oct 2004 11:30:26 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.11/8.12.11) with ESMTP id i9IBUP1v055028 for ; Mon, 18 Oct 2004 11:30:25 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.11/8.12.11/Submit) id i9IBUP0D055026; Mon, 18 Oct 2004 11:30:25 GMT (envelope-from gnats) Resent-Date: Mon, 18 Oct 2004 11:30:25 GMT Resent-Message-Id: <200410181130.i9IBUP0D055026@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Brian Candler Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 60B8D16A4CE for ; Mon, 18 Oct 2004 11:23:50 +0000 (GMT) Received: from sasl.smtp.pobox.com (puzzle.sasl.smtp.pobox.com [207.8.226.4]) by mx1.FreeBSD.org (Postfix) with ESMTP id 047B043D48 for ; Mon, 18 Oct 2004 11:23:50 +0000 (GMT) (envelope-from b.candler@pobox.com) Received: from localhost.localdomain (localhost [127.0.0.1]) by puzzle.pobox.com (Postfix) with ESMTP id DB35A13905A for ; Mon, 18 Oct 2004 07:23:44 -0400 (EDT) Received: from vaio.linnet.org (host217-40-157-153.in-addr.btopenworld.com [217.40.157.153]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by puzzle.pobox.com (Postfix) with ESMTP id 47640138DB7 for ; Mon, 18 Oct 2004 07:23:44 -0400 (EDT) Received: from brian by vaio.linnet.org with local (Exim 4.30) id 1CJVcA-000LK3-Hz for FreeBSD-gnats-submit@freebsd.org; Mon, 18 Oct 2004 12:23:46 +0100 Message-Id: Date: Mon, 18 Oct 2004 12:23:46 +0100 From: Brian Candler To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Subject: bin/72814: libpcap opens bpf as O_RDONLY - doesn't work with ucarp X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Brian Candler List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 18 Oct 2004 11:30:26 -0000 >Number: 72814 >Category: bin >Synopsis: libpcap opens bpf as O_RDONLY - doesn't work with ucarp >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Mon Oct 18 11:30:25 GMT 2004 >Closed-Date: >Last-Modified: >Originator: Brian Candler >Release: FreeBSD 4.10-STABLE i386 >Organization: >Environment: System: FreeBSD vaio.linnet.org 4.10-STABLE FreeBSD 4.10-STABLE #0: Sun Sep 26 17:08:21 BST 2004 root@vaio.linnet.org:/usr/obj/usr/src/sys/VAIO i386 also tested with FreeBSD-5.2.1-RELEASE >Description: libpcap opens /dev/bpfX as O_RDONLY rather than O_RDWR. This affects applications which open bpf using pcap_open_live, then get the fileno and try to use it to send packets. The particular application I have a problem with is ucarp - http://www.ucarp.org/ - which is a VRRP-type failover system deriving from OpenBSD. I do realise that carp may find its way into the FreeBSD kernel post 5.3 but a userland implementation is still convenient. However note that NetBSD works with ucarp, and NetBSD opens the bpf device in O_RDWR mode unconditionally: http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libpcap/pcap-bpf.c?rev=1.12 (search for bpf_open) NetBSD and FreeBSD apparently both imported libpcap-0.8.3, so I don't know where this difference arose. >How-To-Repeat: See src/contrib/libpcap/pcap-bpf.c search for 'bpf_open' Try installing and running ucarp - it silently fails to send packets. Changing O_RDONLY to O_RDWR and make install for libpcap fixes it. >Fix: Consider: (1) Changing libpcap to open in O_RDWR mode unconditionally, as NetBSD does (2) Changing libpcap to attempt open in O_RDWR mode, fallback to O_RDONLY if it fails. */ do { (void)snprintf(device, sizeof(device), "/dev/bpf%d", n++); - fd = open(device, O_RDONLY); + fd = open(device, O_RDWR); + if (fd < 0 && errno == EACCES) + fd = open(device, O_RDONLY); } while (fd < 0 && errno == EBUSY); /* (3) Adding a new entry point to libpcap which does the same as pcap_open_live but uses O_RDWR instead of O_RDONLY >Release-Note: >Audit-Trail: >Unformatted: