Cleanup to sys/net/ bpf.c bpf_filter.c bsd_comp.c

看板DFBSD_submit作者時間21年前 (2004/06/14 00:02), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/2 (看更多)
This is a multi-part message in MIME format. --------------010605030404000306050508 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit ANSIfication, style(9), and removal of obsolete preprocessor conditionals. (Obviously can wait until after first release / USENIX.) -- Tim Wickberg me@k9mach3.org --------------010605030404000306050508 Content-Type: text/plain; name="net.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="net.patch" Index: sys/net/bpf.c =================================================================== RCS file: /home/dcvs/src/sys/net/bpf.c,v retrieving revision 1.18 diff -u -p -r1.18 bpf.c --- sys/net/bpf.c 2 Jun 2004 14:42:57 -0000 1.18 +++ sys/net/bpf.c 13 Jun 2004 07:05:01 -0000 @@ -61,12 +61,7 @@ #include <sys/sockio.h> #include <sys/ttycom.h> #include <sys/filedesc.h> - -#if defined(sparc) && BSD < 199103 -#include <sys/stream.h> -#endif #include <sys/poll.h> - #include <sys/socket.h> #include <sys/vnode.h> @@ -83,20 +78,8 @@ MALLOC_DEFINE(M_BPF, "BPF", "BPF data"); #if NBPF > 0 -/* - * Older BSDs don't have kernel malloc. - */ -#if BSD < 199103 -extern bcopy(); -static caddr_t bpf_alloc(); -#include <net/bpf_compat.h> -#define BPF_BUFSIZE (MCLBYTES-8) -#define UIOMOVE(cp, len, code, uio) uiomove(cp, len, code, uio) -#else #define BPF_BUFSIZE 4096 #define UIOMOVE(cp, len, code, uio) uiomove(cp, len, uio) -#endif - #define PRINET 26 /* interruptible */ /* @@ -159,11 +142,8 @@ static struct cdevsw bpf_cdevsw = { static int -bpf_movein(uio, linktype, mp, sockp, datlen) - struct uio *uio; - int linktype, *datlen; - struct mbuf **mp; - struct sockaddr *sockp; +bpf_movein(struct uio *uio, int linktype, struct mbuf **mp, + struct sockaddr *sockp, int *datlen) { struct mbuf *m; int error; @@ -193,14 +173,8 @@ bpf_movein(uio, linktype, mp, sockp, dat break; case DLT_FDDI: -#if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__bsdi__) sockp->sa_family = AF_IMPLINK; hlen = 0; -#else - sockp->sa_family = AF_UNSPEC; - /* XXX 4(FORMAC)+6(dst)+6(src)+3(LLC)+5(SNAP) */ - hlen = 24; -#endif break; case DLT_RAW: @@ -209,7 +183,6 @@ bpf_movein(uio, linktype, mp, sockp, dat hlen = 0; break; -#if defined(__DragonFly__) || defined(__FreeBSD__) case DLT_ATM_RFC1483: /* * en atm driver requires 4-byte atm pseudo header. @@ -219,7 +192,7 @@ bpf_movein(uio, linktype, mp, sockp, dat sockp->sa_family = AF_UNSPEC; hlen = 12; /* XXX 4(ATM_PH) + 3(LLC) + 5(SNAP) */ break; -#endif + case DLT_PPP: sockp->sa_family = AF_UNSPEC; hlen = 4; /* This should match PPP_HDRLEN */ @@ -238,13 +211,8 @@ bpf_movein(uio, linktype, mp, sockp, dat if (m == 0) return (ENOBUFS); if (len > MHLEN) { -#if BSD >= 199103 MCLGET(m, MB_WAIT); if ((m->m_flags & M_EXT) == 0) { -#else - MCLGET(m); - if (m->m_len != MCLBYTES) { -#endif error = ENOBUFS; goto bad; } @@ -258,11 +226,7 @@ bpf_movein(uio, linktype, mp, sockp, dat if (hlen != 0) { m->m_pkthdr.len -= hlen; m->m_len -= hlen; -#if BSD >= 199103 m->m_data += hlen; /* XXX */ -#else - m->m_off += hlen; -#endif error = UIOMOVE((caddr_t)sockp->sa_data, hlen, UIO_WRITE, uio); if (error) goto bad; @@ -280,9 +244,7 @@ bpf_movein(uio, linktype, mp, sockp, dat * Must be called at splimp. */ static void -bpf_attachd(d, bp) - struct bpf_d *d; - struct bpf_if *bp; +bpf_attachd(struct bpf_d *d, struct bpf_if *bp) { /* * Point d at bp, and add d to the interface's list of listeners. @@ -300,8 +262,7 @@ bpf_attachd(d, bp) * Detach a file from its interface. */ static void -bpf_detachd(d) - struct bpf_d *d; +bpf_detachd(struct bpf_d *d) { struct bpf_d **p; struct bpf_if *bp; @@ -376,11 +337,7 @@ bpfopen(dev_t dev, int flags, int fmt, s */ /* ARGSUSED */ static int -bpfclose(dev, flags, fmt, td) - dev_t dev; - int flags; - int fmt; - struct thread *td; +bpfclose(dev_t dev, int flags, int fmt, struct thread *td) { struct bpf_d *d = dev->si_drv1; int s; @@ -401,63 +358,21 @@ bpfclose(dev, flags, fmt, td) } /* - * Support for SunOS, which does not have tsleep. - */ -#if BSD < 199103 -static -bpf_timeout(arg) - caddr_t arg; -{ - struct bpf_d *d = (struct bpf_d *)arg; - d->bd_timedout = 1; - wakeup(arg); -} - -#define BPF_SLEEP(chan, pri, s, t) bpf_sleep((struct bpf_d *)chan) - -int -bpf_sleep(d) - struct bpf_d *d; -{ - int rto = d->bd_rtout; - int st; - - if (rto != 0) { - d->bd_timedout = 0; - timeout(bpf_timeout, (caddr_t)d, rto); - } - st = sleep((caddr_t)d, PRINET|PCATCH); - if (rto != 0) { - if (d->bd_timedout == 0) - untimeout(bpf_timeout, (caddr_t)d); - else if (st == 0) - return EWOULDBLOCK; - } - return (st != 0) ? EINTR : 0; -} -#else -#define BPF_SLEEP tsleep -#endif - /* * Rotate the packet buffers in descriptor d. Move the store buffer * into the hold slot, and the free buffer into the store slot. * Zero the length of the new store buffer. */ -#define ROTATE_BUFFERS(d) \ - (d)->bd_hbuf = (d)->bd_sbuf; \ - (d)->bd_hlen = (d)->bd_slen; \ - (d)->bd_sbuf = (d)->bd_fbuf; \ - (d)->bd_slen = 0; \ +#define ROTATE_BUFFERS(d) \ + (d)->bd_hbuf = (d)->bd_sbuf; \ + (d)->bd_hlen = (d)->bd_slen; \ + (d)->bd_sbuf = (d)->bd_fbuf; \ + (d)->bd_slen = 0; \ (d)->bd_fbuf = 0; /* * bpfread - read next chunk of packets from buffers */ -static int -bpfread(dev, uio, ioflag) - dev_t dev; - struct uio *uio; - int ioflag; +static int +bpfread(dev_t dev, struct uio *uio, int ioflag) { struct bpf_d *d = dev->si_drv1; int timed_out; @@ -507,7 +422,7 @@ bpfread(dev, uio, ioflag) splx(s); return (EWOULDBLOCK); } - error = BPF_SLEEP((caddr_t)d, PCATCH, "bpf", d->bd_rtout); + error = tsleep((caddr_t)d, PCATCH, "bpf", d->bd_rtout); if (error == EINTR || error == ERESTART) { splx(s); return (error); @@ -560,8 +475,7 @@ bpfread(dev, uio, ioflag) * If there are processes sleeping on this descriptor, wake them up. */ static inline void -bpf_wakeup(d) - struct bpf_d *d; +bpf_wakeup(struct bpf_d *d) { if (d->bd_state == BPF_WAITING) { callout_stop(&d->bd_callout); @@ -571,22 +485,13 @@ bpf_wakeup(d) if (d->bd_async && d->bd_sig && d->bd_sigio) pgsigio(d->bd_sigio, d->bd_sig, 0); -#if BSD >= 199103 selwakeup(&d->bd_sel); /* XXX */ d->bd_sel.si_pid = 0; -#else - if (d->bd_selproc) { - selwakeup(d->bd_selproc, (int)d->bd_selcoll); - d->bd_selcoll = 0; - d->bd_selproc = 0; - } -#endif } static void -bpf_timed_out(arg) - void *arg; +bpf_timed_out(void *arg) { struct bpf_d *d = (struct bpf_d *)arg; int s; @@ -600,11 +505,8 @@ bpf_timed_out(arg) splx(s); } -static int -bpfwrite(dev, uio, ioflag) - dev_t dev; - struct uio *uio; - int ioflag; +static int +bpfwrite(dev_t dev, struct uio *uio, int ioflag) { struct bpf_d *d = dev->si_drv1; struct ifnet *ifp; @@ -632,11 +534,7 @@ bpfwrite(dev, uio, ioflag) dst.sa_family = pseudo_AF_HDRCMPLT; s = splnet(); -#if BSD >= 199103 error = (*ifp->if_output)(ifp, m, &dst, (struct rtentry *)0); -#else - error = (*ifp->if_output)(ifp, m, &dst); -#endif splx(s); /* * The driver frees the mbuf. @@ -649,8 +547,7 @@ bpfwrite(dev, uio, ioflag) * receive and drop counts. Should be called at splimp. */ static void -reset_d(d) - struct bpf_d *d; +reset_d(struct bpf_d *d) { if (d->bd_hbuf) { /* Free the hold buffer. */ @@ -744,9 +641,6 @@ bpfioctl(dev_t dev, u_long cmd, caddr_t * Set buffer length. */ case BIOCSBLEN: -#if BSD < 199103 - error = EINVAL; -#else if (d->bd_bif != 0) error = EINVAL; else { @@ -758,7 +652,6 @@ bpfioctl(dev_t dev, u_long cmd, caddr_t *(u_int *)addr = size = BPF_MINBUFSIZE; d->bd_bufsize = size; } -#endif break; /* @@ -962,9 +855,7 @@ bpfioctl(dev_t dev, u_long cmd, caddr_t * free it and replace it. Returns EINVAL for bogus requests. */ static int -bpf_setf(d, fp) - struct bpf_d *d; - struct bpf_program *fp; +bpf_setf(struct bpf_d *d, struct bpf_program *fp) { struct bpf_insn *fcode, *old; u_int flen, size; @@ -1009,9 +900,7 @@ bpf_setf(d, fp) * Return an errno or 0. */ static int -bpf_setif(d, ifr) - struct bpf_d *d; - struct ifreq *ifr; +bpf_setif(struct bpf_d *d, struct ifreq *ifr) { struct bpf_if *bp; int s, error; @@ -1113,10 +1002,7 @@ bpfpoll(dev_t dev, int events, struct th * buffer. */ void -bpf_tap(ifp, pkt, pktlen) - struct ifnet *ifp; - u_char *pkt; - u_int pktlen; +bpf_tap(struct ifnet *ifp, u_char *pkt, u_int pktlen) { struct bpf_if *bp; struct bpf_d *d; @@ -1140,10 +1026,7 @@ bpf_tap(ifp, pkt, pktlen) * from m_copydata in sys/uipc_mbuf.c. */ static void -bpf_mcopy(src_arg, dst_arg, len) - const void *src_arg; - void *dst_arg; - size_t len; +bpf_mcopy(const void *src_arg, void *dst_arg, size_t len) { const struct mbuf *m; u_int count; @@ -1166,9 +1049,7 @@ bpf_mcopy(src_arg, dst_arg, len) * Incoming linkage from device drivers, when packet is in an mbuf chain. */ void -bpf_mtap(ifp, m) - struct ifnet *ifp; - struct mbuf *m; +bpf_mtap(struct ifnet *ifp, struct mbuf *m) { struct bpf_if *bp = ifp->if_bpf; struct bpf_d *d; @@ -1198,11 +1079,8 @@ bpf_mtap(ifp, m) * pkt is really an mbuf. */ static void -catchpacket(d, pkt, pktlen, snaplen, cpfn) - struct bpf_d *d; - u_char *pkt; - u_int pktlen, snaplen; - void (*cpfn) (const void *, void *, size_t); +catchpacket(struct bpf_d *d, u_char *pkt, u_int pktlen, u_int snaplen, + void (*cpfn) (const void *, void *, size_t)) { struct bpf_hdr *hp; int totlen, curlen; @@ -1251,13 +1129,7 @@ catchpacket(d, pkt, pktlen, snaplen, cpf * Append the bpf header. */ hp = (struct bpf_hdr *)(d->bd_sbuf + curlen); -#if BSD >= 199103 microtime(&hp->bh_tstamp); -#elif defined(sun) - uniqtime(&hp->bh_tstamp); -#else - hp->bh_tstamp = time; -#endif hp->bh_datalen = pktlen; hp->bh_hdrlen = hdrlen; /* @@ -1271,8 +1143,7 @@ catchpacket(d, pkt, pktlen, snaplen, cpf * Initialize all nonzero fields of a descriptor. */ static int -bpf_allocbufs(d) - struct bpf_d *d; +bpf_allocbufs(struct bpf_d *d) { d->bd_fbuf = (caddr_t)malloc(d->bd_bufsize, M_BPF, M_WAITOK); if (d->bd_fbuf == 0) @@ -1293,8 +1164,7 @@ bpf_allocbufs(d) * Called on close. */ static void -bpf_freed(d) - struct bpf_d *d; +bpf_freed(struct bpf_d *d) { /* * We don't need to lock out interrupts since this descriptor has @@ -1319,9 +1189,7 @@ bpf_freed(d) * headers are not yet supporrted). */ void -bpfattach(ifp, dlt, hdrlen) - struct ifnet *ifp; - u_int dlt, hdrlen; +bpfattach(struct ifnet *ifp, u_int dlt, u_int hdrlen) { struct bpf_if *bp; @@ -1354,8 +1222,7 @@ bpfattach(ifp, dlt, hdrlen) * ENXIO. */ void -bpfdetach(ifp) - struct ifnet *ifp; +bpfdetach(struct ifnet *ifp) { struct bpf_if *bp, *bp_prev; struct bpf_d *d; @@ -1413,39 +1280,27 @@ SYSINIT(bpfdev,SI_SUB_DRIVERS,SI_ORDER_M */ void -bpf_tap(ifp, pkt, pktlen) - struct ifnet *ifp; - u_char *pkt; - u_int pktlen; +bpf_tap(struct ifnet *ifp, u_char *pkt, u_int pktlen) { } void -bpf_mtap(ifp, m) - struct ifnet *ifp; - struct mbuf *m; +bpf_mtap(struct ifnet *ifp, struct mbuf *m) { } void -bpfattach(ifp, dlt, hdrlen) - struct ifnet *ifp; - u_int dlt, hdrlen; +bpfattach(struct ifnet *ifp, u_int dlt, u_int hdrlen) { } void -bpfdetach(ifp) - struct ifnet *ifp; +bpfdetach(struct ifnet *ifp) { } u_int -bpf_filter(pc, p, wirelen, buflen) - const struct bpf_insn *pc; - u_char *p; - u_int wirelen; - u_int buflen; +bpf_filter(const struct bpf_insn *pc, u_char *p, u_int wirelen, u_int buflen) { return -1; /* "no filter" behaviour */ } Index: sys/net/bpf_filter.c =================================================================== RCS file: /home/dcvs/src/sys/net/bpf_filter.c,v retrieving revision 1.4 diff -u -p -r1.4 bpf_filter.c --- sys/net/bpf_filter.c 26 Aug 2003 20:49:47 -0000 1.4 +++ sys/net/bpf_filter.c 13 Jun 2004 07:10:18 -0000 @@ -43,10 +43,6 @@ #include <sys/param.h> -#ifdef sun -#include <netinet/in.h> -#endif - #if defined(sparc) || defined(mips) || defined(ibm032) || defined(__alpha__) #define BPF_ALIGN #endif @@ -71,27 +67,24 @@ #endif #include <net/bpf.h> #ifdef _KERNEL -#define MINDEX(m, k) \ -{ \ - int len = m->m_len; \ - \ - while (k >= len) { \ - k -= len; \ - m = m->m_next; \ - if (m == 0) \ - return 0; \ - len = m->m_len; \ - } \ +#define MINDEX(m, k) \ +{ \ + int len = m->m_len; \ + \ + while (k >= len) { \ + k -= len; \ + m = m->m_next; \ + if (m == 0) \ + return 0; \ + len = m->m_len; \ + } \ } static u_int16_t m_xhalf (struct mbuf *m, bpf_u_int32 k, int *err); static u_int32_t m_xword (struct mbuf *m, bpf_u_int32 k, int *err); static u_int32_t -m_xword(m, k, err) - struct mbuf *m; - bpf_u_int32 k; - int *err; +m_xword(struct mbuf *m, bpf_u_int32 k, int *err) { size_t len; u_char *cp, *np; @@ -144,10 +137,7 @@ m_xword(m, k, err) } static u_int16_t -m_xhalf(m, k, err) - struct mbuf *m; - bpf_u_int32 k; - int *err; +m_xhalf(struct mbuf *m, bpf_u_int32 k, int *err) { size_t len; u_char *cp; @@ -183,21 +173,18 @@ m_xhalf(m, k, err) * buflen is the amount of data present */ u_int -bpf_filter(pc, p, wirelen, buflen) - const struct bpf_insn *pc; - u_char *p; - u_int wirelen; - u_int buflen; +bpf_filter(const struct bpf_insn *pc, u_char *p, u_int wirelen, u_int buflen) { u_int32_t A = 0, X = 0; bpf_u_int32 k; int32_t mem[BPF_MEMWORDS]; - if (pc == 0) + if (pc == 0) { /* * No filter means accept all. */ return (u_int)-1; + } --pc; while (1) { @@ -518,9 +505,7 @@ bpf_filter(pc, p, wirelen, buflen) * Otherwise, a bogus program could easily crash the system. */ int -bpf_validate(f, len) - const struct bpf_insn *f; - int len; +bpf_validate(const struct bpf_insn *f, int len) { int i; const struct bpf_insn *p; Index: sys/net/bsd_comp.c =================================================================== RCS file: /home/dcvs/src/sys/net/bsd_comp.c,v retrieving revision 1.6 diff -u -p -r1.6 bsd_comp.c --- sys/net/bsd_comp.c 2 Jun 2004 14:42:57 -0000 1.6 +++ sys/net/bsd_comp.c 13 Jun 2004 07:20:48 -0000 @@ -194,8 +194,7 @@ struct compressor ppp_bsd_compress = { * clear the dictionary */ static void -bsd_clear(db) - struct bsd_db *db; +bsd_clear(struct bsd_db *db) { db->clear_count++; db->max_ent = FIRST-1; @@ -220,8 +219,7 @@ bsd_clear(db) * must compute the same ratio. */ static int /* 1=output CLEAR */ -bsd_check(db) - struct bsd_db *db; +bsd_check(struct bsd_db *db) { u_int new_ratio; @@ -261,9 +259,7 @@ bsd_check(db) * Return statistics. */ static void -bsd_comp_stats(state, stats) - void *state; - struct compstat *stats; +bsd_comp_stats(void *state, struct compstat *stats) { struct bsd_db *db = (struct bsd_db *) state; u_int out; @@ -288,8 +284,7 @@ bsd_comp_stats(state, stats) * Reset state, as on a CCP ResetReq. */ static void -bsd_reset(state) - void *state; +bsd_reset(void *state) { struct bsd_db *db = (struct bsd_db *) state; @@ -302,9 +297,7 @@ bsd_reset(state) * Allocate space for a (de) compressor. */ static void * -bsd_alloc(options, opt_len, decomp) - u_char *options; - int opt_len, decomp; +bsd_alloc(u_char *options, int opt_len, int decomp) { int bits; u_int newlen, hsize, hshift, maxmaxcode; @@ -365,8 +358,7 @@ bsd_alloc(options, opt_len, decomp) } static void -bsd_free(state) - void *state; +bsd_free(void *state) { struct bsd_db *db = (struct bsd_db *) state; @@ -376,17 +368,13 @@ bsd_free(state) } static void * -bsd_comp_alloc(options, opt_len) - u_char *options; - int opt_len; +bsd_comp_alloc(u_char *options, int opt_len) { return bsd_alloc(options, opt_len, 0); } static void * -bsd_decomp_alloc(options, opt_len) - u_char *options; - int opt_len; +bsd_decomp_alloc(u_char *options, int opt_len) { return bsd_alloc(options, opt_len, 1); } @@ -395,10 +383,8 @@ bsd_decomp_alloc(options, opt_len) * Initialize the database. */ static int -bsd_init(db, options, opt_len, unit, hdrlen, mru, debug, decomp) - struct bsd_db *db; - u_char *options; - int opt_len, unit, hdrlen, mru, debug, decomp; +bsd_init(struct bsd_db *db, u_char *options, int opt_len, int unit, + int hdrlen, int mru, int debug, int decomp) { int i; @@ -434,23 +420,19 @@ bsd_init(db, options, opt_len, unit, hdr } static int -bsd_comp_init(state, options, opt_len, unit, hdrlen, debug) - void *state; - u_char *options; - int opt_len, unit, hdrlen, debug; +bsd_comp_init(void *state, u_char *options, int opt_len, int unit, + int hdrlen, int debug) { return bsd_init((struct bsd_db *) state, options, opt_len, unit, hdrlen, 0, debug, 0); } static int -bsd_decomp_init(state, options, opt_len, unit, hdrlen, mru, debug) - void *state; - u_char *options; - int opt_len, unit, hdrlen, mru, debug; +bsd_decomp_init(void *state, u_char *options, int opt_len, + int unit, int hdrlen, int mru, int debug) { - return bsd_init((struct bsd_db *) state, options, opt_len, - unit, hdrlen, mru, debug, 1); + return bsd_init((struct bsd_db *) state, options, opt_len, + unit, hdrlen, mru, debug, 1); } @@ -458,14 +440,14 @@ bsd_decomp_init(state, options, opt_len, * compress a packet * One change from the BSD compress command is that when the * code size expands, we do not output a bunch of padding. + * **mret - return compressed mbuf chain here + * *mp - from here + * slen - uncompressed length + * maxolen - max compressed length */ int /* new slen */ -bsd_compress(state, mret, mp, slen, maxolen) - void *state; - struct mbuf **mret; /* return compressed mbuf chain here */ - struct mbuf *mp; /* from here */ - int slen; /* uncompressed length */ - int maxolen; /* max compressed length */ +bsd_compress(void *state, struct mbuf **mret, struct mbuf *mp, + int slen, int maxolen) { struct bsd_db *db = (struct bsd_db *) state; int hshift = db->hshift; @@ -677,9 +659,7 @@ bsd_compress(state, mret, mp, slen, maxo * incompressible data by pretending to compress the incoming data. */ static void -bsd_incomp(state, dmsg) - void *state; - struct mbuf *dmsg; +bsd_incomp(void *state, struct mbuf *dmsg) { struct bsd_db *db = (struct bsd_db *) state; u_int hshift = db->hshift; @@ -807,9 +787,7 @@ bsd_incomp(state, dmsg) * compression, even though they are detected by inspecting the input. */ int -bsd_decompress(state, cmp, dmpp) - void *state; - struct mbuf *cmp, **dmpp; +bsd_decompress(void *state, struct mbuf *cmp, struct mbuf **dmpp) { struct bsd_db *db = (struct bsd_db *) state; u_int max_ent = db->max_ent; --------------010605030404000306050508--
文章代碼(AID): #10p7gf00 (DFBSD_submit)
文章代碼(AID): #10p7gf00 (DFBSD_submit)