*BSD News Article 23611


Return to BSD News archive

Newsgroups: comp.os.386bsd.bugs
Path: sserve!newshost.anu.edu.au!munnari.oz.au!constellation!osuunx.ucc.okstate.edu!moe.ksu.ksu.edu!vixen.cso.uiuc.edu!sdd.hp.com!cs.utexas.edu!uunet!pipex!uknet!festival!dcs.ed.ac.uk!dcjm
From: dcjm@cs.ed.ac.uk (Dave Matthews)
Subject: Berkeley Packet Filter fixes
Message-ID: <CGA04M.9tG@dcs.ed.ac.uk>
Sender: cnews@dcs.ed.ac.uk (UseNet News Admin)
Reply-To: dcjm@cs.ed.ac.uk (Dave Matthews)
Organization: Department of Computer Science, Edinburgh Univ
Date: Wed, 10 Nov 1993 12:31:34 GMT
Lines: 66


While porting CAP to 386bsd/pk0.2.4 and now to FreeBSD Release 1.0
I found a couple of bugs associated with the packet filter. Here
are the fixes.  I'm posting them here because they apply to
FreeBSD and 386bsd/pk0.2.4 and possibly to other *BSD.

The first occurs when using the packet filter to write raw
ethernet packets.  The header consisting of the sender and
destination addresses and the protocol is removed and later
added back on, but with the byte order of the protocol reversed.
The fix ensures that the byte order in the protocol field is
swapped when it is removed.

The second fix ensures that SIOCGIFADDR works for BPF as claimed
in the man pages, by adding it to the ed driver.  Similar fixes
will be needed for other ethernet drivers.
Dave Matthews.

*** /usr/src/sys/net/bpf.c.ORIG	Sat Oct 16 18:42:49 1993
--- /usr/src/sys/net/bpf.c	Mon Nov  8 08:48:00 1993
***************
*** 198,207 ****
--- 198,215 ----
  		m->m_off += hlen;
  #endif
  		error = UIOMOVE((caddr_t)sockp->sa_data, hlen, UIO_WRITE, uio);
  		if (error)
  			goto bad;
+ 
+ 		if (linktype == DLT_EN10MB) {
+ 			/* Adjust the protocol field. */
+ 			struct ether_header *eh;
+ 			eh = (struct ether_header *)sockp->sa_data;
+ 			eh->ether_type = ntohs(eh->ether_type);
+ 		}
+ 
  	}
  	error = UIOMOVE(mtod(m, caddr_t), len - hlen, UIO_WRITE, uio);
  	if (!error)
  		return (0);
   bad:
*** /usr/src/sys/i386/isa/if_ed.c.ORIG	Mon Nov  8 16:36:22 1993
--- /usr/src/sys/i386/isa/if_ed.c	Mon Nov  8 08:44:06 1993
***************
*** 1925,1934 ****
--- 1925,1944 ----
  			}
  		}
  
  		break;
  
+ #if NBPFILTER > 0
+ 	case SIOCGIFADDR: { /* This is passed on by the packet filter. */
+ 		struct sockaddr *sa;
+ 		sa = (struct sockaddr *)&ifr->ifr_data;
+ 		bcopy((caddr_t)sc->arpcom.ac_enaddr, (caddr_t) sa->sa_data,
+ 			ETHER_ADDR_LEN);
+ 		break;
+ 		}
+ #endif
+ 
  	default:
  		error = EINVAL;
  	}
  	(void) splx(s);
  	return (error);