Patch #: 3 Type: update Priority: medium Modification: add support for Berkeley Packet Filter Modification: add support for 386BSD/FreeBSD (Phase 1) Submitted: Dave Matthews Archived: munnari.OZ.AU mac/cap.patches/uar.1.0.patch03 Application: 'cd uar; patch -p < uar.1.0.patch03' *** uar.h.orig Sun Oct 24 20:31:26 1993 --- uar.h Fri Dec 10 01:17:26 1993 *************** *** 15,21 **** * djh@munnari.OZ.AU * * $Author: djh $ ! * $Revision: 1.1.1.1 $ * */ --- 15,21 ---- * djh@munnari.OZ.AU * * $Author: djh $ ! * $Revision: 1.1.1.2 $ * */ *************** *** 34,42 **** #endif /* AIX */ #include #include ! #ifndef sony_news #include ! #endif /* sony_news */ #include #include #include --- 34,42 ---- #endif /* AIX */ #include #include ! #if (!(defined(sony_news) || defined(__386BSD__))) #include ! #endif /* sony_news || __386BSD__ */ #include #include #include *** pf.c.orig Sun Oct 24 19:22:49 1993 --- pf.c Fri Dec 10 00:21:38 1993 *************** *** 21,30 **** * SGI IRIX SNOOP PF for promisc, DRAIN PF for non-promisc * Sony NEWS-OS 4.N rawether (RAWETH) [Phase 1 only for 4.0] * Hewlett Packard HP-UX Link Level Access (LLAPF) * AIX Ethernet Device (AIXETH) * * $Author: djh $ ! * $Revision: 1.12 $ * */ --- 21,31 ---- * SGI IRIX SNOOP PF for promisc, DRAIN PF for non-promisc * Sony NEWS-OS 4.N rawether (RAWETH) [Phase 1 only for 4.0] * Hewlett Packard HP-UX Link Level Access (LLAPF) + * Berkeley Packet Filter (BPFILT) * AIX Ethernet Device (AIXETH) * * $Author: djh $ ! * $Revision: 1.13 $ * */ *************** *** 62,67 **** --- 63,72 ---- #define AIXETH #endif AIX + #ifdef __386BSD__ + #define BPFILT + #endif __386BSD__ + #include #include #include *************** *** 92,97 **** --- 97,103 ---- #endif ENETPF #ifdef BPFILT + #include #include #endif BPFILT *************** *** 150,160 **** */ #ifdef MAPFUNCS ! #define bcopy(a,b,l) memcpy((char *)(b),(char *)(a),(l)) ! #define bcmp(a,b,l) memcmp((char *)(a),(char *)(b),(l)) ! #define bzero(a,l) memset((char *)(a),0,(l)) ! #define rindex(s,c) strrchr((char *)(s),(c)) ! #define index(s,c) strchr((char *)(s),(c)) #endif MAPFUNCS /* --- 156,166 ---- */ #ifdef MAPFUNCS ! #define bcopy(a,b,l) memcpy((char *)(b),(char *)(a),(l)) ! #define bcmp(a,b,l) memcmp((char *)(a),(char *)(b),(l)) ! #define bzero(a,l) memset((char *)(a),0,(l)) ! #define rindex(s,c) strrchr((char *)(s),(c)) ! #define index(s,c) strchr((char *)(s),(c)) #endif MAPFUNCS /* *************** *** 178,184 **** --- 184,192 ---- #ifdef BPFILT #define USE_WRITEV #define USE_GIFADDR + #ifndef __386BSD__ /* no multicast support, yet */ #define USE_SADDMULTI + #endif __386BSD__ #endif BPFILT #ifdef UPFILT *************** *** 205,210 **** --- 213,220 ---- #ifdef AIXETH #endif AIXETH + #define READBUFSIZ 1600 + /* * variables * *************** *** 219,224 **** --- 229,238 ---- long dlpibuf[MAXDLBUF]; #endif DLPIPF + #if (defined(sgi) || defined(BPFILT)) + char ibuf[READBUFSIZ]; + #endif /* sgi || BPFILT */ + struct ifreq ifr; extern int errno; extern int promisc; *************** *** 433,438 **** --- 447,476 ---- #ifdef BPFILT + { struct bpf_version vers; + u_int pf_bufsize = READBUFSIZ; + + /* check the version number */ + if ((ioctl(s, BIOCVERSION, &vers)) < 0) { + perror("BIOCVERSION"); + return(-1); + } + if (vers.bv_major != BPF_MAJOR_VERSION + || vers.bv_minor < BPF_MINOR_VERSION) { + fprintf(stderr, "Incompatible BPF version\n"); + return(-1); + } + /* we have to read EXACTLY the buffer size */ + if ((ioctl(s, BIOCSBLEN, &pf_bufsize)) < 0) { + perror("BIOCSBLEN"); + return(-1); + } + if (pf_bufsize != READBUFSIZ) { + fprintf(stderr, "Can't set exact BPF buffer size\n"); + return(-1); + } + } + /* bind to interface */ if (ioctl(s, BIOCSETIF, (caddr_t)&ifr) < 0) { perror("BIOCSETIF"); return(-1); *************** *** 664,685 **** #ifdef BPFILT ! static struct bpf_insn insns[] = { ! BPF_STMT(LdHOp, 12), ! BPF_JUMP(EQOp, htons(prot), 1, 6), ! BPF_STMT(LdHOp, 12), ! BPF_JUMP(EQOp, htons(0x0800), 1, 3), ! BPF_STMT(LdHOp, 42), ! BPF_JUMP(EQOp, htons(0xface), 1, 2), ! BPF_STMT(RetOp, 1), ! BPF_STMT(RetOp, 0) ! }; ! static struct bpf_program filter = { ! sizeof(insns)/sizeof(struct bpf_insn), ! insns ! }; ! if (ioctl(s, BIOCSETF, (caddr_t)&filter) < 0) { perror("BIOCSETF"); return(-1); } --- 702,774 ---- #ifdef BPFILT ! /* ! * Dave Matthews ! * dcjm@dcs.ed.ac.uk ! * dave@prolingua.co.uk ! * ! */ ! #define PROG_SIZE 7 ! int ppf = 0; ! struct bpf_program pf; ! struct bpf_insn pf_insns[PROG_SIZE]; ! extern int errno; ! ! #define s_offset(structp, element) (&(((structp)0)->element)) ! ! offset = ((int)s_offset(struct ether_header *, ether_type)); ! ! if (typ == 2) /* EtherTalk Phase 2 */ ! offset += 8; /* 2 bytes length + 6 bytes of 802.2 and SNAP */ ! ! pf_insns[ppf].code = BPF_LD+BPF_H+BPF_ABS; ! pf_insns[ppf].jt = 0; ! pf_insns[ppf].jf = 0; ! pf_insns[ppf].k = offset; ! ppf++; ! ! pf_insns[ppf].code = BPF_JMP+BPF_JEQ+BPF_K; ! pf_insns[ppf].jt = 1; ! pf_insns[ppf].jf = 0; ! pf_insns[ppf].k = prot; ! ppf++; ! ! pf_insns[ppf].code = BPF_RET+BPF_K; /* Fail */ ! pf_insns[ppf].jt = 0; ! pf_insns[ppf].jf = 0; ! pf_insns[ppf].k = 0; ! ppf++; ! ! if (typ == 0) { /* IPtalk */ ! pf_insns[ppf].code = BPF_LD+BPF_H+BPF_ABS; ! pf_insns[ppf].jt = 0; ! pf_insns[ppf].jf = 0; ! pf_insns[ppf].k = offset+30; ! ppf++; ! ! pf_insns[ppf].code = BPF_JMP+BPF_JEQ+BPF_K; ! pf_insns[ppf].jt = 1; ! pf_insns[ppf].jf = 0; ! pf_insns[ppf].k = 0xface; ! ppf++; ! ! pf_insns[ppf].code = BPF_RET+BPF_K; /* Fail */ ! pf_insns[ppf].jt = 0; ! pf_insns[ppf].jf = 0; ! pf_insns[ppf].k = 0; ! ppf++; ! } ! pf_insns[ppf].code = BPF_RET+BPF_K; /* Success */ ! pf_insns[ppf].jt = 0; ! pf_insns[ppf].jf = 0; ! pf_insns[ppf].k = (u_int)-1; ! ppf++; ! ! pf.bf_len = ppf; ! pf.bf_insns = pf_insns; ! ! if (ioctl(s, BIOCSETF, &pf) < 0) { perror("BIOCSETF"); return(-1); } *************** *** 794,800 **** perror("SIOCGIFADDR"); return(-1); } ! #ifdef sgi sa = (struct sockaddr *)&ifr.ifr_data; #else sgi sa = (struct sockaddr *)ifr.ifr_data; --- 883,889 ---- perror("SIOCGIFADDR"); return(-1); } ! #if (defined(sgi) || defined(__386BSD__)) sa = (struct sockaddr *)&ifr.ifr_data; #else sgi sa = (struct sockaddr *)ifr.ifr_data; *************** *** 1154,1163 **** u_char *buf; { #ifdef sgi u_char *p; int cc, off; - char ibuf[1600]; struct snoopheader *sh; if (promisc) --- 1243,1271 ---- u_char *buf; { + #ifdef BPFILT + int cc; + struct bpf_hdr *bp; + + /* must read EXACTLY the buffer size */ + if ((cc = read(fd, ibuf, sizeof(ibuf))) <= 0) + return(cc); + + bp = (struct bpf_hdr *)ibuf; + cc = bp->bh_caplen; + + if (cc > len) + cc = len; + + bcopy(ibuf+bp->bh_hdrlen, (char *)buf, cc); + + return(cc); + #endif BPFILT + + #ifdef sgi u_char *p; int cc, off; struct snoopheader *sh; if (promisc) *************** *** 1173,1180 **** if (cc > len) cc = len; - bcopy(ibuf+off, buf, cc); return(cc); #endif sgi --- 1281,1289 ---- if (cc > len) cc = len; + bcopy(ibuf+off, (char *)buf, cc); + return(cc); #endif sgi *************** *** 1193,1205 **** } if (fis.vtype != off) return(-1); ! bcopy(fis.value.s, buf, off); return(cc+off); #endif hpux ! #ifndef sgi return(read(fd, (char *)buf, len)); ! #endif sgi } /* --- 1302,1314 ---- } if (fis.vtype != off) return(-1); ! bcopy(fis.value.s, (char *)buf, off); return(cc+off); #endif hpux ! #if (!(defined(sgi) || defined(BPFILT))) return(read(fd, (char *)buf, len)); ! #endif /* sgi || BPFILT */ } /* *** Makefile.orig Fri Dec 10 01:29:12 1993 --- Makefile Fri Dec 10 02:04:03 1993 *************** *** 11,16 **** --- 11,17 ---- # The defines for specific packet filters are # -DSNITPF SUN NIT PF (default) # -DUPFILT ULTRIX PF (default) + # -DBPFILT BERKELEY PF # -DENETPF ENET PF # # For Sony NEWS OS4.2 or later to allow use of EtherTalk Phase 2 *************** *** 28,33 **** --- 29,38 ---- # For DEC Aplha OSF/1, Phase 1 or Phase 2 # CFLAGS= # LIBS=pfopen.o + # + # For 386BSD, FreeBSD + # CFLAGS=-DBPFILT + # LIBS= # CFLAGS= LIBS= *** README.orig Fri Dec 10 01:29:24 1993 --- README Fri Dec 10 02:24:48 1993 *************** *** 4,10 **** The University of Melbourne djh@munnari.OZ.AU October, 1993 ! version 1.0.2 --- 4,10 ---- The University of Melbourne djh@munnari.OZ.AU October, 1993 ! version 1.0.3 *************** *** 17,24 **** Native EtherTalk mode, but on a wider variety of host types. UAR currently supports Phase 1 and Phase 2 EtherTalk networks connected ! to SUN, DEC ULTRIX, SGI IRIX, Sony NEWS 4.2, HP-UX 8.07 and IBM RS6000 AIX ! workstations, and Phase 1 only on Sony NEWS pre-4.2 workstations. NOTICE --- 17,25 ---- Native EtherTalk mode, but on a wider variety of host types. UAR currently supports Phase 1 and Phase 2 EtherTalk networks connected ! to SUN, DEC ULTRIX/Alpha, SGI IRIX, Sony NEWS 4.2, HP-UX 8.07 and IBM RS6000 ! AIX workstations, and Phase 1 only on Sony NEWS pre-4.2 and 386BSD/FreeBSD ! workstations. NOTICE *************** *** 307,312 **** --- 308,321 ---- You MUST manually set the define for LIBS=pfopen.o in the Makefile and copy /usr/lib/examples/packetfilter/pfopen.c to the UAR directory. + + ----------------------- + Notes for 386BSD users: + + You must install the Berkeley Packet Filter on your system and define + -DBPFILT in the CFLAGS= line in the Makefile. At this stage, 386BSD + supports only Phase 1 EtherTalk due to limitations in multicast support + in the 386BSD ethernet driver. -------------------------- (edited ARNS version, as of July '93 UAR is untested on Sony NEWS)