Subject: kern/34907: Can not send packets on ppp link using BPF
To: None <kern-bug-people@netbsd.org, gnats-admin@netbsd.org,>
From: None <tbeadle@nexthop.com>
List: netbsd-bugs
Date: 10/25/2006 14:20:00
>Number:         34907
>Category:       kern
>Synopsis:       Can not send packets on ppp link using BPF
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Oct 25 14:20:00 +0000 2006
>Originator:     Tommy Beadle
>Release:        3.0
>Organization:
Nexthop.com
>Environment:
NetBSD rack3-boxb 3.0 NetBSD 3.0 (NEXTHOP-PIM-2) #2: Tue Oct 24 11:25:51 EDT 2006  root@labtest:/usr/src/sys/arch/i386/compile/NEXTHOP-PIM-2 i386
>Description:
When attempting to use the BPF interface for sending packets out a ppp interface, an errno of EIO is returned from write() and the packet is not sent.  Using an ethernet interface, this does not happen.  The reason seems to be that the ioctl call for BIOCGDLT returns a data link type of DLT_PPP_SERIAL and in bpf_movein(), that is not listed as a supported data link type.  DLT_PPP is listed, but not DLT_PPP_SERIAL.  It also seems that the hlen for DLT_PPP in that function is incorrect, as it should be 4 instead of 0.
>How-To-Repeat:
Use something like the following code segment...
==============================================================
fd = open("/dev/bpf0", O_RDWR);

strncpy(ifr.ifr_name, "ppp0", sizeof(ifr.ifr_name));

if (ioctl(fd, BIOCSETIF, (caddr_t)&ifr) < 0) {
    printf("bpf_open_write: errno = %d, fd = %d\n", errno, fd);
    (void)close(fd);
    return 0;
}

if (ioctl(fd, BIOCGDLT, (caddr_t)dlt, sizeof(u_int)) < 0 ) {
    printf("Unable to get interface datalink type.\n");
    printf("errno = %d, fd = %d\n", errno, fd);
    (void)close(fd);
    return 0;
}

result = write(fd, buff, total_len);
=================================================================
...write returns a value < 0 and errno is set to EIO.
>Fix:
--- net/bpf.c.old       2006-10-24 11:17:43.000000000 -0400
+++ net/bpf.c   2006-10-24 11:21:24.000000000 -0400
@@ -188,8 +188,9 @@
                break;

        case DLT_PPP:
+       case DLT_PPP_SERIAL:
                sockp->sa_family = AF_UNSPEC;
-               hlen = 0;
+               hlen = 4;
                align = 0;
                break;