From: Jeffrey Hsu Date: Tue, 21 Dec 2004 02:54:48 +0000 (+0000) Subject: Clean up the routing and networking code before I parallelize routing. X-Git-Tag: v2.0.1~9430 X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/f23061d4208e8952b8e2a68ce5848b2821bd8f6e Clean up the routing and networking code before I parallelize routing. --- diff --git a/sys/dev/netif/sbsh/if_sbsh.c b/sys/dev/netif/sbsh/if_sbsh.c index 29c39e914a..5f7af5d9cf 100644 --- a/sys/dev/netif/sbsh/if_sbsh.c +++ b/sys/dev/netif/sbsh/if_sbsh.c @@ -24,7 +24,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/sbsh/if_sbsh.c,v 1.3.2.1 2003/04/15 18:15:07 fjoe Exp $ - * $DragonFly: src/sys/dev/netif/sbsh/if_sbsh.c,v 1.12 2004/07/23 07:16:28 joerg Exp $ + * $DragonFly: src/sys/dev/netif/sbsh/if_sbsh.c,v 1.13 2004/12/21 02:54:14 hsu Exp $ */ #include @@ -459,7 +459,7 @@ sbsh_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred *cr) ds.status_3 = ((volatile u_int8_t *)sc->cmdp)[0x3c2]; bcopy(&sc->in_stats, ifr->ifr_data, sizeof(struct sbni16_stats)); - bcopy(&ds, ifr->ifr_data + sizeof(struct sbni16_stats), + bcopy(&ds, (char *)ifr->ifr_data + sizeof(struct sbni16_stats), sizeof(struct dsl_stats)); break; diff --git a/sys/net/bpf.c b/sys/net/bpf.c index 287a8d8f51..f7e3105978 100644 --- a/sys/net/bpf.c +++ b/sys/net/bpf.c @@ -38,7 +38,7 @@ * @(#)bpf.c 8.2 (Berkeley) 3/28/94 * * $FreeBSD: src/sys/net/bpf.c,v 1.59.2.12 2002/04/14 21:41:48 luigi Exp $ - * $DragonFly: src/sys/net/bpf.c,v 1.19 2004/07/07 15:16:04 joerg Exp $ + * $DragonFly: src/sys/net/bpf.c,v 1.20 2004/12/21 02:54:14 hsu Exp $ */ #include "use_bpf.h" @@ -182,7 +182,7 @@ bpf_movein(struct uio *uio, int linktype, struct mbuf **mp, * specified anyway. */ sockp->sa_family = AF_UNSPEC; - hlen = 12; /* XXX 4(ATM_PH) + 3(LLC) + 5(SNAP) */ + hlen = 12; /* XXX 4(ATM_PH) + 3(LLC) + 5(SNAP) */ break; case DLT_PPP: @@ -200,11 +200,11 @@ bpf_movein(struct uio *uio, int linktype, struct mbuf **mp, return(EIO); MGETHDR(m, MB_WAIT, MT_DATA); - if (m == 0) + if (m == NULL) return(ENOBUFS); if (len > MHLEN) { MCLGET(m, MB_WAIT); - if ((m->m_flags & M_EXT) == 0) { + if (!(m->m_flags & M_EXT)) { error = ENOBUFS; goto bad; } @@ -244,9 +244,7 @@ bpf_attachd(struct bpf_d *d, struct bpf_if *bp) * it will divert packets to bpf. */ d->bd_bif = bp; - d->bd_next = bp->bif_dlist; - bp->bif_dlist = d; - + SLIST_INSERT_HEAD(&bp->bif_dlist, d, bd_next); bp->bif_ifp->if_bpf = bp; } @@ -256,7 +254,6 @@ bpf_attachd(struct bpf_d *d, struct bpf_if *bp) static void bpf_detachd(struct bpf_d *d) { - struct bpf_d **p; struct bpf_if *bp; bp = d->bd_bif; @@ -276,20 +273,15 @@ bpf_detachd(struct bpf_d *d) } } /* Remove d from the interface's descriptor list. */ - p = &bp->bif_dlist; - while (*p != d) { - p = &(*p)->bd_next; - if (*p == NULL) - panic("bpf_detachd: descriptor not in list"); - } - *p = (*p)->bd_next; - if (bp->bif_dlist == NULL) { + SLIST_REMOVE(&bp->bif_dlist, d, bpf_d, bd_next); + + if (SLIST_EMPTY(&bp->bif_dlist)) { /* * Let the driver know that there are no more listeners. */ - d->bd_bif->bif_ifp->if_bpf = 0; + d->bd_bif->bif_ifp->if_bpf = NULL; } - d->bd_bif = 0; + d->bd_bif = NULL; } /* @@ -310,7 +302,7 @@ bpfopen(dev_t dev, int flags, int fmt, struct thread *td) d = dev->si_drv1; /* - * Each minor can be opened by only one process. If the requested + * Each minor can be opened by only one process. If the requested * minor is in use, return EBUSY. */ if (d != NULL) @@ -345,7 +337,7 @@ bpfclose(dev_t dev, int flags, int fmt, struct thread *td) bpf_detachd(d); splx(s); bpf_freed(d); - dev->si_drv1 = 0; + dev->si_drv1 = NULL; free(d, M_BPF); return(0); @@ -361,7 +353,7 @@ bpfclose(dev_t dev, int flags, int fmt, struct thread *td) (d)->bd_hlen = (d)->bd_slen; \ (d)->bd_sbuf = (d)->bd_fbuf; \ (d)->bd_slen = 0; \ - (d)->bd_fbuf = 0; + (d)->bd_fbuf = NULL; /* * bpfread - read next chunk of packets from buffers */ @@ -390,7 +382,7 @@ bpfread(dev_t dev, struct uio *uio, int ioflag) * ends when the timeout expires or when enough packets * have arrived to fill the store buffer. */ - while (d->bd_hbuf == 0) { + while (d->bd_hbuf == NULL) { if ((d->bd_immediate || timed_out) && d->bd_slen != 0) { /* * A packet(s) either arrived since the previous @@ -457,7 +449,7 @@ bpfread(dev_t dev, struct uio *uio, int ioflag) s = splimp(); d->bd_fbuf = d->bd_hbuf; - d->bd_hbuf = 0; + d->bd_hbuf = NULL; d->bd_hlen = 0; splx(s); @@ -475,7 +467,7 @@ bpf_wakeup(struct bpf_d *d) callout_stop(&d->bd_callout); d->bd_state = BPF_IDLE; } - wakeup((caddr_t)d); + wakeup(d); if (d->bd_async && d->bd_sig && d->bd_sigio) pgsigio(d->bd_sigio, d->bd_sig, 0); @@ -509,7 +501,7 @@ bpfwrite(dev_t dev, struct uio *uio, int ioflag) static struct sockaddr dst; int datlen; - if (d->bd_bif == 0) + if (d->bd_bif == NULL) return(ENXIO); ifp = d->bd_bif->bif_ifp; @@ -546,7 +538,7 @@ reset_d(struct bpf_d *d) if (d->bd_hbuf) { /* Free the hold buffer. */ d->bd_fbuf = d->bd_hbuf; - d->bd_hbuf = 0; + d->bd_hbuf = NULL; } d->bd_slen = 0; d->bd_hlen = 0; @@ -614,7 +606,7 @@ bpfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td) { struct ifnet *ifp; - if (d->bd_bif == 0) + if (d->bd_bif == NULL) error = EINVAL; else { ifp = d->bd_bif->bif_ifp; @@ -668,7 +660,7 @@ bpfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td) * Put interface into promiscuous mode. */ case BIOCPROMISC: - if (d->bd_bif == 0) { + if (d->bd_bif == NULL) { /* * No interface attached yet. */ @@ -688,7 +680,7 @@ bpfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td) * Get device parameters. */ case BIOCGDLT: - if (d->bd_bif == 0) + if (d->bd_bif == NULL) error = EINVAL; else *(u_int *)addr = d->bd_bif->bif_dlt; @@ -698,7 +690,7 @@ bpfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td) * Get interface name. */ case BIOCGETIF: - if (d->bd_bif == 0) + if (d->bd_bif == NULL) error = EINVAL; else { struct ifnet *const ifp = d->bd_bif->bif_ifp; @@ -827,7 +819,7 @@ bpfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct thread *td) case BIOCSRSIG: /* Set receive signal */ { - u_int sig; + u_int sig; sig = *(u_int *)addr; @@ -856,15 +848,15 @@ bpf_setf(struct bpf_d *d, struct bpf_program *fp) int s; old = d->bd_filter; - if (fp->bf_insns == 0) { + if (fp->bf_insns == NULL) { if (fp->bf_len != 0) return(EINVAL); s = splimp(); - d->bd_filter = 0; + d->bd_filter = NULL; reset_d(d); splx(s); if (old != 0) - free((caddr_t)old, M_BPF); + free(old, M_BPF); return(0); } flen = fp->bf_len; @@ -873,18 +865,18 @@ bpf_setf(struct bpf_d *d, struct bpf_program *fp) size = flen * sizeof(*fp->bf_insns); fcode = (struct bpf_insn *)malloc(size, M_BPF, M_WAITOK); - if (copyin((caddr_t)fp->bf_insns, (caddr_t)fcode, size) == 0 && + if (copyin(fp->bf_insns, fcode, size) == 0 && bpf_validate(fcode, (int)flen)) { s = splimp(); d->bd_filter = fcode; reset_d(d); splx(s); if (old != 0) - free((caddr_t)old, M_BPF); + free(old, M_BPF); return(0); } - free((caddr_t)fcode, M_BPF); + free(fcode, M_BPF); return(EINVAL); } @@ -901,7 +893,7 @@ bpf_setif(struct bpf_d *d, struct ifreq *ifr) struct ifnet *theywant; theywant = ifunit(ifr->ifr_name); - if (theywant == 0) + if (theywant == NULL) return(ENXIO); /* @@ -910,7 +902,7 @@ bpf_setif(struct bpf_d *d, struct ifreq *ifr) for (bp = bpf_iflist; bp != 0; bp = bp->bif_next) { struct ifnet *ifp = bp->bif_ifp; - if (ifp == 0 || ifp != theywant) + if (ifp == NULL || ifp != theywant) continue; /* * We found the requested interface. @@ -919,7 +911,7 @@ bpf_setif(struct bpf_d *d, struct ifreq *ifr) * If we're already attached to requested interface, * just flush the buffer. */ - if ((ifp->if_flags & IFF_UP) == 0) + if (!(ifp->if_flags & IFF_UP)) return(ENETDOWN); if (d->bd_sbuf == NULL) { @@ -1000,16 +992,16 @@ bpfpoll(dev_t dev, int events, struct thread *td) void bpf_tap(struct ifnet *ifp, u_char *pkt, u_int pktlen) { - struct bpf_if *bp; + struct bpf_if *bp = ifp->if_bpf; struct bpf_d *d; u_int slen; + /* * Note that the ipl does not have to be raised at this point. * The only problem that could arise here is that if two different * interfaces shared any data. This is not the case. */ - bp = ifp->if_bpf; - for (d = bp->bif_dlist; d != 0; d = d->bd_next) { + SLIST_FOREACH(d, &bp->bif_dlist, bd_next) { ++d->bd_rcount; slen = bpf_filter(d->bd_filter, pkt, pktlen, pktlen); if (slen != 0) @@ -1053,10 +1045,10 @@ bpf_mtap(struct ifnet *ifp, struct mbuf *m) struct mbuf *m0; pktlen = 0; - for (m0 = m; m0 != 0; m0 = m0->m_next) + for (m0 = m; m0 != NULL; m0 = m0->m_next) pktlen += m0->m_len; - for (d = bp->bif_dlist; d != 0; d = d->bd_next) { + SLIST_FOREACH(d, &bp->bif_dlist, bd_next) { if (!d->bd_seesent && (m->m_pkthdr.rcvif == NULL)) continue; ++d->bd_rcount; @@ -1101,7 +1093,7 @@ catchpacket(struct bpf_d *d, u_char *pkt, u_int pktlen, u_int snaplen, * Rotate the buffers if we can, then wakeup any * pending reads. */ - if (d->bd_fbuf == 0) { + if (d->bd_fbuf == NULL) { /* * We haven't completed the previous read yet, * so drop the packet. @@ -1167,15 +1159,15 @@ bpf_freed(struct bpf_d *d) * been detached from its interface and it yet hasn't been marked * free. */ - if (d->bd_sbuf != 0) { + if (d->bd_sbuf != NULL) { free(d->bd_sbuf, M_BPF); - if (d->bd_hbuf != 0) + if (d->bd_hbuf != NULL) free(d->bd_hbuf, M_BPF); - if (d->bd_fbuf != 0) + if (d->bd_fbuf != NULL) free(d->bd_fbuf, M_BPF); } if (d->bd_filter) - free((caddr_t)d->bd_filter, M_BPF); + free(d->bd_filter, M_BPF); } /* @@ -1197,7 +1189,7 @@ bpfattach(struct ifnet *ifp, u_int dlt, u_int hdrlen) bp->bif_next = bpf_iflist; bpf_iflist = bp; - bp->bif_ifp->if_bpf = 0; + bp->bif_ifp->if_bpf = NULL; /* * Compute the length of the bpf header. This is not necessarily @@ -1241,7 +1233,7 @@ bpfdetach(struct ifnet *ifp) return; } - while ((d = bp->bif_dlist) != NULL) { + while ((d = SLIST_FIRST(&bp->bif_dlist)) != NULL) { bpf_detachd(d); bpf_wakeup(d); } diff --git a/sys/net/bpf.h b/sys/net/bpf.h index 6624029d41..95731049e6 100644 --- a/sys/net/bpf.h +++ b/sys/net/bpf.h @@ -39,7 +39,7 @@ * @(#)bpf.h 1.34 (LBL) 6/16/96 * * $FreeBSD: src/sys/net/bpf.h,v 1.21.2.4 2002/07/05 14:40:00 fenner Exp $ - * $DragonFly: src/sys/net/bpf.h,v 1.6 2004/09/19 22:32:47 joerg Exp $ + * $DragonFly: src/sys/net/bpf.h,v 1.7 2004/12/21 02:54:14 hsu Exp $ */ #ifndef _NET_BPF_H_ @@ -294,7 +294,7 @@ struct bpf_hdr { #define BPF_H 0x08 #define BPF_B 0x10 #define BPF_MODE(code) ((code) & 0xe0) -#define BPF_IMM 0x00 +#define BPF_IMM 0x00 #define BPF_ABS 0x20 #define BPF_IND 0x40 #define BPF_MEM 0x60 diff --git a/sys/net/bpf_compat.h b/sys/net/bpf_compat.h deleted file mode 100644 index f7c5b57030..0000000000 --- a/sys/net/bpf_compat.h +++ /dev/null @@ -1,55 +0,0 @@ -/*- - * Copyright (c) 1992, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)bpf_compat.h 8.1 (Berkeley) 6/10/93 - * $FreeBSD: src/sys/net/bpf_compat.h,v 1.6 1999/08/28 00:48:13 peter Exp $ - * $DragonFly: src/sys/net/Attic/bpf_compat.h,v 1.2 2003/06/17 04:28:47 dillon Exp $ - */ - -#ifndef _NET_BPF_COMPAT_H_ -#define _NET_BPF_COMPAT_H_ - -/* - * Some hacks for compatibility across SunOS and 4.4BSD. We emulate malloc - * and free with mbuf clusters. We store a pointer to the mbuf in the first - * word of the mbuf and return 8 bytes passed the start of data (for double - * word alignment). We cannot just use offsets because clusters are not at - * a fixed offset from the associated mbuf. Sorry for this kludge. - */ -#define malloc(size, type, canwait) bpf_alloc(size, canwait) -#define free(cp, type) m_free(*(struct mbuf **)(cp - 8)) -#define M_WAITOK M_WAIT - -/* This mapping works for our purposes. */ -#define ERESTART EINTR - -#endif diff --git a/sys/net/bpf_filter.c b/sys/net/bpf_filter.c index b487f397e5..3e969c337a 100644 --- a/sys/net/bpf_filter.c +++ b/sys/net/bpf_filter.c @@ -38,7 +38,7 @@ * @(#)bpf_filter.c 8.1 (Berkeley) 6/10/93 * * $FreeBSD: src/sys/net/bpf_filter.c,v 1.17 1999/12/29 04:38:31 peter Exp $ - * $DragonFly: src/sys/net/bpf_filter.c,v 1.5 2004/07/27 01:24:28 cpressey Exp $ + * $DragonFly: src/sys/net/bpf_filter.c,v 1.6 2004/12/21 02:54:14 hsu Exp $ */ #include @@ -70,7 +70,7 @@ #define MINDEX(m, k) \ { \ int len = m->m_len; \ - \ + \ while (k >= len) { \ k -= len; \ m = m->m_next; \ diff --git a/sys/net/bpfdesc.h b/sys/net/bpfdesc.h index 143cc84f29..90fc8f98eb 100644 --- a/sys/net/bpfdesc.h +++ b/sys/net/bpfdesc.h @@ -38,7 +38,7 @@ * @(#)bpfdesc.h 8.1 (Berkeley) 6/10/93 * * $FreeBSD: src/sys/net/bpfdesc.h,v 1.14.2.2 2001/12/17 19:32:33 jdp Exp $ - * $DragonFly: src/sys/net/bpfdesc.h,v 1.2 2003/06/17 04:28:47 dillon Exp $ + * $DragonFly: src/sys/net/bpfdesc.h,v 1.3 2004/12/21 02:54:14 hsu Exp $ */ #ifndef _NET_BPFDESC_H_ @@ -51,7 +51,7 @@ * Descriptor associated with each open bpf file. */ struct bpf_d { - struct bpf_d *bd_next; /* Linked list of descriptors */ + SLIST_ENTRY(bpf_d) bd_next; /* Linked list of descriptors */ /* * Buffer slots: two mbuf clusters buffer the incoming packets. * The model has three slots. Sbuf is always occupied. @@ -64,14 +64,14 @@ struct bpf_d { caddr_t bd_sbuf; /* store slot */ caddr_t bd_hbuf; /* hold slot */ caddr_t bd_fbuf; /* free slot */ - int bd_slen; /* current length of store buffer */ - int bd_hlen; /* current length of hold buffer */ + int bd_slen; /* current length of store buffer */ + int bd_hlen; /* current length of hold buffer */ int bd_bufsize; /* absolute length of buffers */ struct bpf_if * bd_bif; /* interface descriptor */ u_long bd_rtout; /* Read timeout in 'ticks' */ - struct bpf_insn *bd_filter; /* filter code */ + struct bpf_insn *bd_filter; /* filter code */ u_long bd_rcount; /* number of packets received */ u_long bd_dcount; /* number of packets dropped */ @@ -104,7 +104,7 @@ struct bpf_d { */ struct bpf_if { struct bpf_if *bif_next; /* list of all interfaces */ - struct bpf_d *bif_dlist; /* descriptor list */ + SLIST_HEAD(, bpf_d) bif_dlist; /* descriptor list */ u_int bif_dlt; /* link layer type */ u_int bif_hdrlen; /* length of header (with padding) */ struct ifnet *bif_ifp; /* corresponding interface */ diff --git a/sys/net/bsd_comp.c b/sys/net/bsd_comp.c index 029ee4a1b0..46b79eaf1e 100644 --- a/sys/net/bsd_comp.c +++ b/sys/net/bsd_comp.c @@ -41,7 +41,7 @@ * This version is for use with mbufs on BSD-derived systems. * * $FreeBSD: src/sys/net/bsd_comp.c,v 1.11.2.1 2002/04/14 21:41:48 luigi Exp $ - * $DragonFly: src/sys/net/bsd_comp.c,v 1.7 2004/07/27 01:24:28 cpressey Exp $ + * $DragonFly: src/sys/net/bsd_comp.c,v 1.8 2004/12/21 02:54:14 hsu Exp $ */ #include @@ -440,8 +440,8 @@ bsd_decomp_init(void *state, u_char *options, int 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 + * **mret - return compressed mbuf chain here + * *mp - from here * slen - uncompressed length * maxolen - max compressed length */ @@ -755,7 +755,7 @@ bsd_incomp(void *state, struct mbuf *dmsg) bitno += n_bits; /* output (count) the last code */ db->bytes_out += bitno/8; db->in_count += ilen; - (void)bsd_check(db); + bsd_check(db); ++db->incomp_count; db->incomp_bytes += ilen; diff --git a/sys/net/ethernet.h b/sys/net/ethernet.h index e516aa6132..15154e4527 100644 --- a/sys/net/ethernet.h +++ b/sys/net/ethernet.h @@ -2,7 +2,7 @@ * Fundamental constants relating to ethernet. * * $FreeBSD: src/sys/net/ethernet.h,v 1.12.2.8 2002/12/01 14:03:09 sobomax Exp $ - * $DragonFly: src/sys/net/ethernet.h,v 1.9 2004/07/26 14:41:17 joerg Exp $ + * $DragonFly: src/sys/net/ethernet.h,v 1.10 2004/12/21 02:54:14 hsu Exp $ * */ @@ -92,23 +92,23 @@ extern const uint8_t etherbroadcastaddr[ETHER_ADDR_LEN]; /* 0x0400 Nixdorf */ #define ETHERTYPE_NS 0x0600 /* XNS */ #define ETHERTYPE_NSAT 0x0601 /* XNS Address Translation (3Mb only) */ -#define ETHERTYPE_DLOG1 0x0660 /* DLOG (?) */ -#define ETHERTYPE_DLOG2 0x0661 /* DLOG (?) */ +#define ETHERTYPE_DLOG1 0x0660 /* DLOG (?) */ +#define ETHERTYPE_DLOG2 0x0661 /* DLOG (?) */ #define ETHERTYPE_IP 0x0800 /* IP protocol */ #define ETHERTYPE_X75 0x0801 /* X.75 Internet */ #define ETHERTYPE_NBS 0x0802 /* NBS Internet */ #define ETHERTYPE_ECMA 0x0803 /* ECMA Internet */ -#define ETHERTYPE_CHAOS 0x0804 /* CHAOSnet */ +#define ETHERTYPE_CHAOS 0x0804 /* CHAOSnet */ #define ETHERTYPE_X25 0x0805 /* X.25 Level 3 */ #define ETHERTYPE_ARP 0x0806 /* Address resolution protocol */ #define ETHERTYPE_NSCOMPAT 0x0807 /* XNS Compatibility */ -#define ETHERTYPE_FRARP 0x0808 /* Frame Relay ARP (RFC1701) */ +#define ETHERTYPE_FRARP 0x0808 /* Frame Relay ARP (RFC1701) */ /* 0x081C Symbolics Private */ /* 0x0888 - 0x088A Xyplex */ #define ETHERTYPE_UBDEBUG 0x0900 /* Ungermann-Bass network debugger */ #define ETHERTYPE_IEEEPUP 0x0A00 /* Xerox IEEE802.3 PUP */ #define ETHERTYPE_IEEEPUPAT 0x0A01 /* Xerox IEEE802.3 PUP Address Translation */ -#define ETHERTYPE_VINES 0x0BAD /* Banyan VINES */ +#define ETHERTYPE_VINES 0x0BAD /* Banyan VINES */ #define ETHERTYPE_VINESLOOP 0x0BAE /* Banyan VINES Loopback */ #define ETHERTYPE_VINESECHO 0x0BAF /* Banyan VINES Echo */ @@ -122,7 +122,7 @@ extern const uint8_t etherbroadcastaddr[ETHER_ADDR_LEN]; #define ETHERTYPE_NTRAILER 16 #define ETHERTYPE_DCA 0x1234 /* DCA - Multicast */ -#define ETHERTYPE_VALID 0x1600 /* VALID system protocol */ +#define ETHERTYPE_VALID 0x1600 /* VALID system protocol */ #define ETHERTYPE_DOGFIGHT 0x1989 /* Artificial Horizons ("Aviator" dogfight simulator [on Sun]) */ #define ETHERTYPE_RCL 0x1995 /* Datapoint Corporation (RCL lan protocol) */ @@ -387,7 +387,7 @@ __BEGIN_DECLS struct ether_addr *ether_aton (const char *); int ether_hostton (const char *, struct ether_addr *); int ether_line (const char *, struct ether_addr *, char *); -char *ether_ntoa (const struct ether_addr *); +char *ether_ntoa (const struct ether_addr *); int ether_ntohost (char *, const struct ether_addr *); __END_DECLS diff --git a/sys/net/faith/if_faith.c b/sys/net/faith/if_faith.c index 918f28911a..0ee99988a0 100644 --- a/sys/net/faith/if_faith.c +++ b/sys/net/faith/if_faith.c @@ -33,7 +33,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/net/if_faith.c,v 1.3.2.6 2002/04/28 05:40:25 suz Exp $ - * $DragonFly: src/sys/net/faith/if_faith.c,v 1.8 2004/03/23 22:19:06 hsu Exp $ + * $DragonFly: src/sys/net/faith/if_faith.c,v 1.9 2004/12/21 02:54:15 hsu Exp $ */ /* * derived from @@ -368,9 +368,9 @@ faithprefix(in6) sin6.sin6_family = AF_INET6; sin6.sin6_len = sizeof(struct sockaddr_in6); sin6.sin6_addr = *in6; - rt = rtalloc1((struct sockaddr *)&sin6, 0, 0UL); + rt = rtlookup((struct sockaddr *)&sin6, 0, 0UL); if (rt && rt->rt_ifp && rt->rt_ifp->if_type == IFT_FAITH && - (rt->rt_ifp->if_flags & IFF_UP) != 0) + (rt->rt_ifp->if_flags & IFF_UP)) ret = 1; else ret = 0; diff --git a/sys/net/hostcache.c b/sys/net/hostcache.c index be2df15afd..9b11354117 100644 --- a/sys/net/hostcache.c +++ b/sys/net/hostcache.c @@ -27,7 +27,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/net/hostcache.c,v 1.6.2.1 2002/04/14 21:41:48 luigi Exp $ - * $DragonFly: src/sys/net/Attic/hostcache.c,v 1.3 2004/09/15 20:38:36 joerg Exp $ + * $DragonFly: src/sys/net/Attic/hostcache.c,v 1.4 2004/12/21 02:54:14 hsu Exp $ */ #include @@ -77,8 +77,7 @@ hc_init(int af, struct hccallback *hccb, int init_nelem, int primes) hct->hct_nentries = nelem; hct->hct_primes = primes; callout_init(&hc_timeout_h); - callout_reset(&hc_timeout_h, hc_timeout_interval * hz, - hc_timeout, hct); + callout_reset(&hc_timeout_h, hc_timeout_interval * hz, hc_timeout, hct); return 0; } @@ -99,15 +98,15 @@ hc_get(struct sockaddr *sa) if (cmpsa(hc->hc_host, sa) == 0) break; } - if (hc == 0) - return 0; + if (hc == NULL) + return NULL; s = splnet(); - if (hc->hc_rt && (hc->hc_rt->rt_flags & RTF_UP) == 0) { + if (hc->hc_rt && !(hc->hc_rt->rt_flags & RTF_UP)) { RTFREE(hc->hc_rt); - hc->hc_rt = 0; + hc->hc_rt = NULL; } - if (hc->hc_rt == 0) { - hc->hc_rt = rtalloc1(hc->hc_host, 1, 0); + if (hc->hc_rt == NULL) { + hc->hc_rt = rtlookup(hc->hc_host, 1, 0); } hc_ref(hc); splx(s); @@ -162,7 +161,7 @@ hc_insert(struct hcentry *hc) if (cmpsa(hc2->hc_host, hc->hc_host) == 0) break; } - if (hc2 != 0) + if (hc2 != NULL) return EEXIST; hc->hc_hct = hct; s = splnet(); diff --git a/sys/net/hostcache.h b/sys/net/hostcache.h index d1d17a23d0..c367160fc2 100644 --- a/sys/net/hostcache.h +++ b/sys/net/hostcache.h @@ -27,7 +27,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/net/hostcache.h,v 1.4 1999/12/29 04:38:32 peter Exp $ - * $DragonFly: src/sys/net/Attic/hostcache.h,v 1.2 2003/06/17 04:28:47 dillon Exp $ + * $DragonFly: src/sys/net/Attic/hostcache.h,v 1.3 2004/12/21 02:54:14 hsu Exp $ */ #ifndef _NET_HOSTCACHE_H @@ -56,7 +56,7 @@ struct hcentry { struct rtentry *hc_rt; /* route to get there */ /* struct nexthop *hc_nh; */ int hc_refcnt; /* reference count */ - struct hctable *hc_hct; /* back ref to table */ + struct hctable *hc_hct; /* back ref to table */ }; struct hccallback { diff --git a/sys/net/if.c b/sys/net/if.c index a42ec181c4..3589184c81 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -31,8 +31,8 @@ * SUCH DAMAGE. * * @(#)if.c 8.3 (Berkeley) 1/4/94 - * $FreeBSD: src/sys/net/if.c,v 1.185 2004/03/13 02:35:03 brooks Exp $ - * $DragonFly: src/sys/net/if.c,v 1.22 2004/09/15 19:34:55 joerg Exp $ + * $FreeBSD: src/sys/net/if.c,v 1.185 2004/03/13 02:35:03 brooks Exp $ + * $DragonFly: src/sys/net/if.c,v 1.23 2004/12/21 02:54:14 hsu Exp $ */ #include "opt_compat.h" @@ -123,8 +123,7 @@ struct callout if_slowtimo_timer; */ /* ARGSUSED*/ void -ifinit(dummy) - void *dummy; +ifinit(void *dummy) { struct ifnet *ifp; int s; @@ -147,14 +146,12 @@ int if_index = 0; struct ifaddr **ifnet_addrs; struct ifnet **ifindex2ifnet = NULL; - /* * Attach an interface to the * list of "active" interfaces. */ void -if_attach(ifp) - struct ifnet *ifp; +if_attach(struct ifnet *ifp) { unsigned socksize, ifasize; int namelen, masklen; @@ -181,13 +178,13 @@ if_attach(ifp) TAILQ_INIT(&ifp->if_prefixhead); LIST_INIT(&ifp->if_multiaddrs); getmicrotime(&ifp->if_lastchange); - if (ifnet_addrs == 0 || if_index >= if_indexlim) { + if (ifnet_addrs == NULL || if_index >= if_indexlim) { unsigned n = (if_indexlim <<= 1) * sizeof(ifa); caddr_t q = malloc(n, M_IFADDR, M_WAITOK); bzero(q, n); - if (ifnet_addrs) { - bcopy((caddr_t)ifnet_addrs, (caddr_t)q, n/2); - free((caddr_t)ifnet_addrs, M_IFADDR); + if (ifnet_addrs != NULL) { + bcopy(ifnet_addrs, q, n/2); + free(ifnet_addrs, M_IFADDR); } ifnet_addrs = (struct ifaddr **)q; @@ -196,8 +193,8 @@ if_attach(ifp) q = malloc(n, M_IFADDR, M_WAITOK); bzero(q, n); if (ifindex2ifnet) { - bcopy((caddr_t)ifindex2ifnet, q, n/2); - free((caddr_t)ifindex2ifnet, M_IFADDR); + bcopy(ifindex2ifnet, q, n/2); + free(ifindex2ifnet, M_IFADDR); } ifindex2ifnet = (struct ifnet **)q; } @@ -218,7 +215,7 @@ if_attach(ifp) ifasize = sizeof(*ifa) + 2 * socksize; ifa = (struct ifaddr *)malloc(ifasize, M_IFADDR, M_WAITOK); if (ifa) { - bzero((caddr_t)ifa, ifasize); + bzero(ifa, ifasize); sdl = (struct sockaddr_dl *)(ifa + 1); sdl->sdl_len = socksize; sdl->sdl_family = AF_LINK; @@ -249,8 +246,7 @@ if_attach(ifp) * list of "active" interfaces. */ void -if_detach(ifp) - struct ifnet *ifp; +if_detach(struct ifnet *ifp) { struct ifaddr *ifa; struct radix_node_head *rnh; @@ -280,7 +276,7 @@ if_detach(ifp) if (ifa->ifa_addr && ifa->ifa_addr->sa_family == AF_INET) { struct ifaliasreq ifr; - bzero(&ifr, sizeof(ifr)); + bzero(&ifr, sizeof ifr); ifr.ifra_addr = *ifa->ifa_addr; if (ifa->ifa_dstaddr) ifr.ifra_broadaddr = *ifa->ifa_dstaddr; @@ -319,7 +315,7 @@ if_detach(ifp) for (i = 1; i <= AF_MAX; i++) { if ((rnh = rt_tables[i]) == NULL) continue; - (void) rnh->rnh_walktree(rnh, if_rtdel, ifp); + rnh->rnh_walktree(rnh, if_rtdel, ifp); } /* Announce that the interface is gone. */ @@ -333,7 +329,7 @@ if_detach(ifp) /* * Delete Routes for a Network Interface - * + * * Called for each routing entry via the rnh->rnh_walktree() call above * to delete all route entries referencing a detaching network interface. * @@ -347,9 +343,7 @@ if_detach(ifp) * */ static int -if_rtdel(rn, arg) - struct radix_node *rn; - void *arg; +if_rtdel(struct radix_node *rn, void *arg) { struct rtentry *rt = (struct rtentry *)rn; struct ifnet *ifp = arg; @@ -361,7 +355,7 @@ if_rtdel(rn, arg) * Protect (sorta) against walktree recursion problems * with cloned routes */ - if ((rt->rt_flags & RTF_UP) == 0) + if (!(rt->rt_flags & RTF_UP)) return (0); err = rtrequest(RTM_DELETE, rt_key(rt), rt->rt_gateway, @@ -379,9 +373,7 @@ if_rtdel(rn, arg) * Create a clone network interface. */ int -if_clone_create(name, len) - char *name; - int len; +if_clone_create(char *name, int len) { struct if_clone *ifc; char *dp; @@ -402,8 +394,8 @@ if_clone_create(name, len) * Find a free unit if none was given. */ if (wildcard) { - while ((bytoff < ifc->ifc_bmlen) - && (ifc->ifc_units[bytoff] == 0xff)) + while (bytoff < ifc->ifc_bmlen && + ifc->ifc_units[bytoff] == 0xff) bytoff++; if (bytoff >= ifc->ifc_bmlen) return (ENOSPC); @@ -455,8 +447,7 @@ if_clone_create(name, len) * Destroy a clone network interface. */ int -if_clone_destroy(name) - const char *name; +if_clone_destroy(const char *name) { struct if_clone *ifc; struct ifnet *ifp; @@ -494,9 +485,7 @@ if_clone_destroy(name) * Look up a network interface cloner. */ struct if_clone * -if_clone_lookup(name, unitp) - const char *name; - int *unitp; +if_clone_lookup(const char *name, int *unitp) { struct if_clone *ifc; const char *cp; @@ -537,8 +526,7 @@ if_clone_lookup(name, unitp) * Register a network interface cloner. */ void -if_clone_attach(ifc) - struct if_clone *ifc; +if_clone_attach(struct if_clone *ifc) { int bytoff, bitoff; int err; @@ -579,8 +567,7 @@ if_clone_attach(ifc) * Unregister a network interface cloner. */ void -if_clone_detach(ifc) - struct if_clone *ifc; +if_clone_detach(struct if_clone *ifc) { LIST_REMOVE(ifc, ifc_list); @@ -592,8 +579,7 @@ if_clone_detach(ifc) * Provide list of interface cloners to userspace. */ int -if_clone_list(ifcr) - struct if_clonereq *ifcr; +if_clone_list(struct if_clonereq *ifcr) { char outbuf[IFNAMSIZ], *dst; struct if_clone *ifc; @@ -625,16 +611,15 @@ if_clone_list(ifcr) /* * Locate an interface based on a complete address. */ -/*ARGSUSED*/ struct ifaddr * -ifa_ifwithaddr(addr) - struct sockaddr *addr; +ifa_ifwithaddr(struct sockaddr *addr) { struct ifnet *ifp; struct ifaddr *ifa; #define equal(a1, a2) \ - (bcmp((caddr_t)(a1), (caddr_t)(a2), ((struct sockaddr *)(a1))->sa_len) == 0) + (bcmp((a1), (a2), ((struct sockaddr *)(a1))->sa_len) == 0) + TAILQ_FOREACH(ifp, &ifnet, if_link) TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) { if (ifa->ifa_addr->sa_family != addr->sa_family) @@ -652,10 +637,8 @@ ifa_ifwithaddr(addr) /* * Locate the point to point interface with a given destination address. */ -/*ARGSUSED*/ struct ifaddr * -ifa_ifwithdstaddr(addr) - struct sockaddr *addr; +ifa_ifwithdstaddr(struct sockaddr *addr) { struct ifnet *ifp; struct ifaddr *ifa; @@ -676,8 +659,7 @@ ifa_ifwithdstaddr(addr) * is most specific found. */ struct ifaddr * -ifa_ifwithnet(addr) - struct sockaddr *addr; +ifa_ifwithnet(struct sockaddr *addr) { struct ifnet *ifp; struct ifaddr *ifa; @@ -714,15 +696,15 @@ next: continue; * The trouble is that we don't know the * netmask for the remote end. */ - if (ifa->ifa_dstaddr != 0 - && equal(addr, ifa->ifa_dstaddr)) - return (ifa); + if (ifa->ifa_dstaddr != 0 && + equal(addr, ifa->ifa_dstaddr)) + return (ifa); } else { /* * if we have a special address handler, * then use it instead of the generic one. */ - if (ifa->ifa_claim_addr) { + if (ifa->ifa_claim_addr) { if ((*ifa->ifa_claim_addr)(ifa, addr)) { return (ifa); } else { @@ -755,8 +737,8 @@ next: continue; * for an even better one. */ if (ifa_maybe == 0 || - rn_refines((caddr_t)ifa->ifa_netmask, - (caddr_t)ifa_maybe->ifa_netmask)) + rn_refines((char *)ifa->ifa_netmask, + (char *)ifa_maybe->ifa_netmask)) ifa_maybe = ifa; } } @@ -769,9 +751,7 @@ next: continue; * a given address. */ struct ifaddr * -ifaof_ifpforaddr(addr, ifp) - struct sockaddr *addr; - struct ifnet *ifp; +ifaof_ifpforaddr(struct sockaddr *addr, struct ifnet *ifp) { struct ifaddr *ifa; char *cp, *cp2, *cp3; @@ -818,23 +798,20 @@ ifaof_ifpforaddr(addr, ifp) * This should be moved to /sys/net/link.c eventually. */ static void -link_rtrequest(cmd, rt, info) - int cmd; - struct rtentry *rt; - struct rt_addrinfo *info; +link_rtrequest(int cmd, struct rtentry *rt, struct rt_addrinfo *info) { struct ifaddr *ifa; struct sockaddr *dst; struct ifnet *ifp; - if (cmd != RTM_ADD || ((ifa = rt->rt_ifa) == 0) || - ((ifp = ifa->ifa_ifp) == 0) || ((dst = rt_key(rt)) == 0)) + if (cmd != RTM_ADD || (ifa = rt->rt_ifa) == NULL || + (ifp = ifa->ifa_ifp) == NULL || (dst = rt_key(rt)) == NULL) return; ifa = ifaof_ifpforaddr(dst, ifp); - if (ifa) { + if (ifa != NULL) { IFAFREE(rt->rt_ifa); + IFAREF(ifa); rt->rt_ifa = ifa; - ifa->ifa_refcnt++; if (ifa->ifa_rtrequest && ifa->ifa_rtrequest != link_rtrequest) ifa->ifa_rtrequest(cmd, rt, info); } @@ -846,9 +823,7 @@ link_rtrequest(cmd, rt, info) * NOTE: must be called at splnet or eqivalent. */ void -if_unroute(ifp, flag, fam) - struct ifnet *ifp; - int flag, fam; +if_unroute(struct ifnet *ifp, int flag, int fam) { struct ifaddr *ifa; @@ -867,9 +842,7 @@ if_unroute(ifp, flag, fam) * NOTE: must be called at splnet or eqivalent. */ void -if_route(ifp, flag, fam) - struct ifnet *ifp; - int flag, fam; +if_route(struct ifnet *ifp, int flag, int fam) { struct ifaddr *ifa; @@ -890,8 +863,7 @@ if_route(ifp, flag, fam) * NOTE: must be called at splnet or eqivalent. */ void -if_down(ifp) - struct ifnet *ifp; +if_down(struct ifnet *ifp) { if_unroute(ifp, IFF_UP, AF_UNSPEC); @@ -903,8 +875,7 @@ if_down(ifp) * NOTE: must be called at splnet or eqivalent. */ void -if_up(ifp) - struct ifnet *ifp; +if_up(struct ifnet *ifp) { if_route(ifp, IFF_UP, AF_UNSPEC); @@ -914,8 +885,7 @@ if_up(ifp) * Flush an interface queue. */ static void -if_qflush(ifq) - struct ifqueue *ifq; +if_qflush(struct ifqueue *ifq) { struct mbuf *m, *n; @@ -935,8 +905,7 @@ if_qflush(ifq) * call the appropriate interface routine on expiration. */ static void -if_slowtimo(arg) - void *arg; +if_slowtimo(void *arg) { struct ifnet *ifp; int s = splimp(); @@ -977,8 +946,7 @@ ifunit(const char *name) * interface structure pointer. */ struct ifnet * -if_withname(sa) - struct sockaddr *sa; +if_withname(struct sockaddr *sa) { char ifname[IFNAMSIZ+1]; struct sockaddr_dl *sdl = (struct sockaddr_dl *)sa; @@ -1033,7 +1001,7 @@ ifioctl(struct socket *so, u_long cmd, caddr_t data, struct thread *td) return ((cmd == SIOCIFCREATE) ? if_clone_create(ifr->ifr_name, sizeof(ifr->ifr_name)) : if_clone_destroy(ifr->ifr_name)); - + case SIOCIFGCLONERS: return (if_clone_list((struct if_clonereq *)data)); } @@ -1093,8 +1061,7 @@ ifioctl(struct socket *so, u_long cmd, caddr_t data, struct thread *td) ifp->if_flags &= ~IFF_PROMISC; } if (ifp->if_ioctl) - (void) (*ifp->if_ioctl)(ifp, cmd, data, - td->td_proc->p_ucred); + (*ifp->if_ioctl)(ifp, cmd, data, td->td_proc->p_ucred); getmicrotime(&ifp->if_lastchange); break; @@ -1104,54 +1071,54 @@ ifioctl(struct socket *so, u_long cmd, caddr_t data, struct thread *td) return (error); if (ifr->ifr_reqcap & ~ifp->if_capabilities) return (EINVAL); - (void) (*ifp->if_ioctl)(ifp, cmd, data, td->td_proc->p_ucred); + (*ifp->if_ioctl)(ifp, cmd, data, td->td_proc->p_ucred); break; - case SIOCSIFNAME: - error = suser(td); - if (error != 0) - return (error); - error = copyinstr(ifr->ifr_data, new_name, IFNAMSIZ, NULL); - if (error != 0) - return (error); + case SIOCSIFNAME: + error = suser(td); + if (error != 0) + return (error); + error = copyinstr(ifr->ifr_data, new_name, IFNAMSIZ, NULL); + if (error != 0) + return (error); if (new_name[0] == '\0') return (EINVAL); - if (ifunit(new_name) != NULL) - return (EEXIST); + if (ifunit(new_name) != NULL) + return (EEXIST); EVENTHANDLER_INVOKE(ifnet_detach_event, ifp); - - /* Announce the departure of the interface. */ - rt_ifannouncemsg(ifp, IFAN_DEPARTURE); - - strlcpy(ifp->if_xname, new_name, sizeof(ifp->if_xname)); - ifa = TAILQ_FIRST(&ifp->if_addrhead); - /* XXX IFA_LOCK(ifa); */ - sdl = (struct sockaddr_dl *)ifa->ifa_addr; - namelen = strlen(new_name); - onamelen = sdl->sdl_nlen; - /* - * Move the address if needed. This is safe because we - * allocate space for a name of length IFNAMSIZ when we - * create this in if_attach(). - */ - if (namelen != onamelen) { - bcopy(sdl->sdl_data + onamelen, - sdl->sdl_data + namelen, sdl->sdl_alen); - } - bcopy(new_name, sdl->sdl_data, namelen); - sdl->sdl_nlen = namelen; - sdl = (struct sockaddr_dl *)ifa->ifa_netmask; - bzero(sdl->sdl_data, onamelen); - while (namelen != 0) - sdl->sdl_data[--namelen] = 0xff; - /* XXX IFA_UNLOCK(ifa) */ + + /* Announce the departure of the interface. */ + rt_ifannouncemsg(ifp, IFAN_DEPARTURE); + + strlcpy(ifp->if_xname, new_name, sizeof(ifp->if_xname)); + ifa = TAILQ_FIRST(&ifp->if_addrhead); + /* XXX IFA_LOCK(ifa); */ + sdl = (struct sockaddr_dl *)ifa->ifa_addr; + namelen = strlen(new_name); + onamelen = sdl->sdl_nlen; + /* + * Move the address if needed. This is safe because we + * allocate space for a name of length IFNAMSIZ when we + * create this in if_attach(). + */ + if (namelen != onamelen) { + bcopy(sdl->sdl_data + onamelen, + sdl->sdl_data + namelen, sdl->sdl_alen); + } + bcopy(new_name, sdl->sdl_data, namelen); + sdl->sdl_nlen = namelen; + sdl = (struct sockaddr_dl *)ifa->ifa_netmask; + bzero(sdl->sdl_data, onamelen); + while (namelen != 0) + sdl->sdl_data[--namelen] = 0xff; + /* XXX IFA_UNLOCK(ifa) */ EVENTHANDLER_INVOKE(ifnet_attach_event, ifp); - - /* Announce the return of the interface. */ - rt_ifannouncemsg(ifp, IFAN_ARRIVAL); - break; + + /* Announce the return of the interface. */ + rt_ifannouncemsg(ifp, IFAN_ARRIVAL); + break; case SIOCSIFMETRIC: error = suser(td); @@ -1170,7 +1137,7 @@ ifioctl(struct socket *so, u_long cmd, caddr_t data, struct thread *td) error = (*ifp->if_ioctl)(ifp, cmd, data, td->td_proc->p_ucred); if (error == 0) getmicrotime(&ifp->if_lastchange); - return(error); + return (error); case SIOCSIFMTU: { @@ -1244,7 +1211,7 @@ ifioctl(struct socket *so, u_long cmd, caddr_t data, struct thread *td) case SIOCGIFSTATUS: ifs = (struct ifstat *)data; ifs->ascii[0] = '\0'; - + case SIOCGIFPSRCADDR: case SIOCGIFPDSTADDR: case SIOCGLIFPHYADDR: @@ -1340,9 +1307,7 @@ ifioctl(struct socket *so, u_long cmd, caddr_t data, struct thread *td) * Results are undefined if the "off" and "on" requests are not matched. */ int -ifpromisc(ifp, pswitch) - struct ifnet *ifp; - int pswitch; +ifpromisc(struct ifnet *ifp, int pswitch) { struct ifreq ifr; int error; @@ -1390,7 +1355,6 @@ ifpromisc(ifp, pswitch) * in later ioctl's (above) to get * other information. */ -/*ARGSUSED*/ static int ifconf(u_long cmd, caddr_t data, struct thread *td) { @@ -1405,7 +1369,7 @@ ifconf(u_long cmd, caddr_t data, struct thread *td) TAILQ_FOREACH(ifp, &ifnet, if_link) { int addrs; - if (space <= sizeof (ifr)) + if (space <= sizeof ifr) break; if (strlcpy(ifr.ifr_name, ifp->if_xname, sizeof(ifr.ifr_name)) >= sizeof(ifr.ifr_name)) { @@ -1415,7 +1379,7 @@ ifconf(u_long cmd, caddr_t data, struct thread *td) addrs = 0; TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) { - if (space <= sizeof(ifr)) + if (space <= sizeof ifr) break; sa = ifa->ifa_addr; if (td->td_proc->p_ucred->cr_prison && @@ -1428,42 +1392,39 @@ ifconf(u_long cmd, caddr_t data, struct thread *td) (struct osockaddr *)&ifr.ifr_addr; ifr.ifr_addr = *sa; osa->sa_family = sa->sa_family; - error = copyout((caddr_t)&ifr, (caddr_t)ifrp, - sizeof (ifr)); + error = copyout(&ifr, ifrp, sizeof ifr); ifrp++; } else #endif if (sa->sa_len <= sizeof(*sa)) { ifr.ifr_addr = *sa; - error = copyout((caddr_t)&ifr, (caddr_t)ifrp, - sizeof (ifr)); + error = copyout(&ifr, ifrp, sizeof ifr); ifrp++; } else { - if (space < sizeof (ifr) + sa->sa_len - + if (space < (sizeof ifr) + sa->sa_len - sizeof(*sa)) break; space -= sa->sa_len - sizeof(*sa); - error = copyout((caddr_t)&ifr, (caddr_t)ifrp, - sizeof (ifr.ifr_name)); + error = copyout(&ifr, ifrp, + sizeof ifr.ifr_name); if (error == 0) - error = copyout((caddr_t)sa, - (caddr_t)&ifrp->ifr_addr, sa->sa_len); + error = copyout(sa, &ifrp->ifr_addr, + sa->sa_len); ifrp = (struct ifreq *) (sa->sa_len + (caddr_t)&ifrp->ifr_addr); } if (error) break; - space -= sizeof (ifr); + space -= sizeof ifr; } if (error) break; if (!addrs) { - bzero((caddr_t)&ifr.ifr_addr, sizeof(ifr.ifr_addr)); - error = copyout((caddr_t)&ifr, (caddr_t)ifrp, - sizeof (ifr)); + bzero(&ifr.ifr_addr, sizeof ifr.ifr_addr); + error = copyout(&ifr, ifrp, sizeof ifr); if (error) break; - space -= sizeof (ifr); + space -= sizeof ifr; ifrp++; } } @@ -1475,9 +1436,7 @@ ifconf(u_long cmd, caddr_t data, struct thread *td) * Just like if_promisc(), but for all-multicast-reception mode. */ int -if_allmulti(ifp, onswitch) - struct ifnet *ifp; - int onswitch; +if_allmulti(struct ifnet *ifp, int onswitch) { int error = 0; int s = splimp(); @@ -1515,10 +1474,10 @@ if_allmulti(ifp, onswitch) * The link layer provides a routine which converts */ int -if_addmulti(ifp, sa, retifma) - struct ifnet *ifp; /* interface to manipulate */ - struct sockaddr *sa; /* address to add */ - struct ifmultiaddr **retifma; +if_addmulti( + struct ifnet *ifp, /* interface to manipulate */ + struct sockaddr *sa, /* address to add */ + struct ifmultiaddr **retifma) { struct sockaddr *llsa, *dupsa; int error, s; @@ -1606,9 +1565,7 @@ if_addmulti(ifp, sa, retifma) * if the request does not match an existing membership. */ int -if_delmulti(ifp, sa) - struct ifnet *ifp; - struct sockaddr *sa; +if_delmulti(struct ifnet *ifp, struct sockaddr *sa) { struct ifmultiaddr *ifma; int s; @@ -1740,9 +1697,7 @@ if_setlladdr(struct ifnet *ifp, const u_char *lladdr, int len) } struct ifmultiaddr * -ifmaof_ifpforaddr(sa, ifp) - struct sockaddr *sa; - struct ifnet *ifp; +ifmaof_ifpforaddr(struct sockaddr *sa, struct ifnet *ifp) { struct ifmultiaddr *ifma; diff --git a/sys/net/if.h b/sys/net/if.h index 34bea82d3f..a4f5422946 100644 --- a/sys/net/if.h +++ b/sys/net/if.h @@ -32,7 +32,7 @@ * * @(#)if.h 8.1 (Berkeley) 6/10/93 * $FreeBSD: src/sys/net/if.h,v 1.58.2.9 2002/08/30 14:23:38 sobomax Exp $ - * $DragonFly: src/sys/net/if.h,v 1.11 2004/07/06 11:44:37 joerg Exp $ + * $DragonFly: src/sys/net/if.h,v 1.12 2004/12/21 02:54:14 hsu Exp $ */ #ifndef _NET_IF_H_ @@ -243,7 +243,7 @@ struct ifreq { int ifru_mtu; int ifru_phys; int ifru_media; - caddr_t ifru_data; + void *ifru_data; int ifru_cap[2]; } ifr_ifru; #define ifr_addr ifr_ifru.ifru_addr /* address */ @@ -324,13 +324,6 @@ struct if_laddrreq { struct sockaddr_storage dstaddr; /* out */ }; -#ifdef _KERNEL -#ifdef MALLOC_DECLARE -MALLOC_DECLARE(M_IFADDR); -MALLOC_DECLARE(M_IFMADDR); -#endif -#endif - #ifndef _KERNEL struct if_nameindex { u_int if_index; /* 1, 2, ... */ diff --git a/sys/net/if_arcsubr.c b/sys/net/if_arcsubr.c index c9b7b2c032..7a7f882d61 100644 --- a/sys/net/if_arcsubr.c +++ b/sys/net/if_arcsubr.c @@ -1,6 +1,6 @@ /* $NetBSD: if_arcsubr.c,v 1.36 2001/06/14 05:44:23 itojun Exp $ */ /* $FreeBSD: src/sys/net/if_arcsubr.c,v 1.1.2.5 2003/02/05 18:42:15 fjoe Exp $ */ -/* $DragonFly: src/sys/net/Attic/if_arcsubr.c,v 1.10 2004/07/23 07:16:30 joerg Exp $ */ +/* $DragonFly: src/sys/net/Attic/if_arcsubr.c,v 1.11 2004/12/21 02:54:14 hsu Exp $ */ /* * Copyright (c) 1994, 1995 Ignatios Souvatzis @@ -106,44 +106,16 @@ const uint8_t arcbroadcastaddr[1] = {0}; */ static int arc_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, - struct rtentry *rt0) + struct rtentry *rt) { - struct rtentry *rt; - struct arccom *ac; struct arc_header *ah; int error; u_int8_t atype, adst; int loop_copy = 0; int isphds; - if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING)) - return(ENETDOWN); /* m, m1 aren't initialized yet */ - - error = 0; - ac = (struct arccom *)ifp; - - if ((rt = rt0)) { - if ((rt->rt_flags & RTF_UP) == 0) { - if ((rt0 = rt = rtalloc1(dst, 1, 0UL))) - rt->rt_refcnt--; - else - senderr(EHOSTUNREACH); - } - if (rt->rt_flags & RTF_GATEWAY) { - if (rt->rt_gwroute == 0) - goto lookup; - if (((rt = rt->rt_gwroute)->rt_flags & RTF_UP) == 0) { - rtfree(rt); rt = rt0; - lookup: rt->rt_gwroute = rtalloc1(rt->rt_gateway, 1, 0UL); - if ((rt = rt->rt_gwroute) == 0) - senderr(EHOSTUNREACH); - } - } - if (rt->rt_flags & RTF_REJECT) - if (rt->rt_rmx.rmx_expire == 0 || - time_second < rt->rt_rmx.rmx_expire) - senderr(rt == rt0 ? EHOSTDOWN : EHOSTUNREACH); - } + if ((ifp->if_flags & (IFF_UP | IFF_RUNNING)) != (IFF_UP | IFF_RUNNING)) + return (ENETDOWN); /* m, m1 aren't initialized yet */ switch (dst->sa_family) { #ifdef INET @@ -156,7 +128,7 @@ arc_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, adst = ifp->if_broadcastaddr[0]; else if (ifp->if_flags & IFF_NOARP) adst = ntohl(SIN(dst)->sin_addr.s_addr) & 0xFF; - else if (!arpresolve(ifp, rt, m, dst, &adst, rt0)) + else if (!arpresolve(ifp, rt, m, dst, &adst)) return 0; /* not resolved yet */ atype = (ifp->if_flags & IFF_LINK0) ? @@ -165,13 +137,8 @@ arc_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, #endif #ifdef INET6 case AF_INET6: -#ifdef OLDIP6OUTPUT - if (!nd6_resolve(ifp, rt, m, dst, (u_char *)&adst)) - return(0); /* if not yet resolves */ -#else if (!nd6_storelladdr(ifp, rt, m, dst, (u_char *)&adst)) - return(0); /* it must be impossible, but... */ -#endif /* OLDIP6OUTPUT */ + return (0); /* it must be impossible, but... */ atype = ARCTYPE_INET6; break; #endif @@ -215,7 +182,7 @@ arc_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, isphds = arc_isphds(atype); M_PREPEND(m, isphds ? ARC_HDRNEWLEN : ARC_HDRLEN, MB_DONTWAIT); - if (m == 0) + if (m == NULL) senderr(ENOBUFS); ah = mtod(m, struct arc_header *); ah->arc_type = atype; @@ -229,11 +196,11 @@ arc_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, if ((ifp->if_flags & IFF_SIMPLEX) && (loop_copy != -1)) { if ((m->m_flags & M_BCAST) || (loop_copy > 0)) { - struct mbuf *n = m_copy(m, 0, (int)M_COPYALL); + struct mbuf *n = m_copypacket(m, MB_DONTWAIT); - (void) if_simloop(ifp, n, dst->sa_family, ARC_HDRLEN); + if_simloop(ifp, n, dst->sa_family, ARC_HDRLEN); } else if (ah->arc_dhost == ah->arc_shost) { - (void) if_simloop(ifp, m, dst->sa_family, ARC_HDRLEN); + if_simloop(ifp, m, dst->sa_family, ARC_HDRLEN); return (0); /* XXX */ } } @@ -246,7 +213,7 @@ arc_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, senderr(ENOBUFS); } - return (error); + return (0); bad: if (m) @@ -481,7 +448,7 @@ arc_defrag(ifp, m) /* is it the last one? */ if (af->af_lastseen > af->af_maxflag) { af->af_packet = NULL; - return(m1); + return (m1); } else return NULL; } diff --git a/sys/net/if_arp.h b/sys/net/if_arp.h index 021552b422..20a679eca3 100644 --- a/sys/net/if_arp.h +++ b/sys/net/if_arp.h @@ -32,7 +32,7 @@ * * @(#)if_arp.h 8.1 (Berkeley) 6/10/93 * $FreeBSD: src/sys/net/if_arp.h,v 1.14.2.3 2002/02/20 23:34:09 fjoe Exp $ - * $DragonFly: src/sys/net/if_arp.h,v 1.4 2004/07/17 09:43:05 joerg Exp $ + * $DragonFly: src/sys/net/if_arp.h,v 1.5 2004/12/21 02:54:14 hsu Exp $ */ #ifndef _NET_IF_ARP_H_ @@ -50,10 +50,10 @@ */ struct arphdr { u_short ar_hrd; /* format of hardware address */ -#define ARPHRD_ETHER 1 /* ethernet hardware format */ +#define ARPHRD_ETHER 1 /* ethernet hardware format */ #define ARPHRD_IEEE802 6 /* token-ring hardware format */ #define ARPHRD_ARCNET 7 /* arcnet hardware format */ -#define ARPHRD_FRELAY 15 /* frame relay hardware format */ +#define ARPHRD_FRELAY 15 /* frame relay hardware format */ u_short ar_pro; /* format of protocol address */ u_char ar_hln; /* length of hardware address */ u_char ar_pln; /* length of protocol address */ @@ -62,7 +62,7 @@ struct arphdr { #define ARPOP_REPLY 2 /* response to previous request */ #define ARPOP_REVREQUEST 3 /* request protocol address given hardware */ #define ARPOP_REVREPLY 4 /* response giving protocol address */ -#define ARPOP_INVREQUEST 8 /* request to identify peer */ +#define ARPOP_INVREQUEST 8 /* request to identify peer */ #define ARPOP_INVREPLY 9 /* response identifying peer */ /* * The remaining fields are variable in size, @@ -111,7 +111,7 @@ struct arpcom { /* * The ifnet struct _must_ be at the head of this structure. */ - struct ifnet ac_if; /* network-visible interface */ + struct ifnet ac_if; /* network-visible interface */ u_char ac_enaddr[6]; /* ethernet hardware address */ int ac_multicnt; /* length of ac_multiaddrs list */ void *ac_netgraph; /* ng_ether(4) netgraph node info */ diff --git a/sys/net/if_atm.h b/sys/net/if_atm.h index 3a9b8a156d..255e8596a6 100644 --- a/sys/net/if_atm.h +++ b/sys/net/if_atm.h @@ -1,6 +1,6 @@ /* $NetBSD: if_atm.h,v 1.7 1996/11/09 23:02:27 chuck Exp $ */ /* $FreeBSD: src/sys/net/if_atm.h,v 1.4 1999/12/29 04:38:34 peter Exp $ */ -/* $DragonFly: src/sys/net/if_atm.h,v 1.4 2004/02/13 17:45:49 joerg Exp $ */ +/* $DragonFly: src/sys/net/if_atm.h,v 1.5 2004/12/21 02:54:14 hsu Exp $ */ /* * @@ -39,9 +39,11 @@ */ #if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__bsdi__) -#define RTALLOC1(A,B) rtalloc1((A),(B)) -#elif defined(__DragonFly__) || defined(__FreeBSD__) -#define RTALLOC1(A,B) rtalloc1((A),(B),0UL) +#define RTALLOC1(A,B) rtalloc1((A), (B)) +#elif defined(__DragonFly__) +#define RTALLOC1(A,B) rtlookup((A), (B), 0UL) +#elif defined(__FreeBSD__) +#define RTALLOC1(A,B) rtalloc1((A), (B), 0UL) #endif /* diff --git a/sys/net/if_ethersubr.c b/sys/net/if_ethersubr.c index 9e20768572..21a95c9dff 100644 --- a/sys/net/if_ethersubr.c +++ b/sys/net/if_ethersubr.c @@ -32,7 +32,7 @@ * * @(#)if_ethersubr.c 8.1 (Berkeley) 6/10/93 * $FreeBSD: src/sys/net/if_ethersubr.c,v 1.70.2.33 2003/04/28 15:45:53 archie Exp $ - * $DragonFly: src/sys/net/if_ethersubr.c,v 1.20 2004/12/14 18:46:08 hsu Exp $ + * $DragonFly: src/sys/net/if_ethersubr.c,v 1.21 2004/12/21 02:54:14 hsu Exp $ */ #include "opt_atalk.h" @@ -76,8 +76,8 @@ #include #include int (*ef_inputp)(struct ifnet*, struct ether_header *eh, struct mbuf *m); -int (*ef_outputp)(struct ifnet *ifp, struct mbuf **mp, - struct sockaddr *dst, short *tp, int *hlen); +int (*ef_outputp)(struct ifnet *ifp, struct mbuf **mp, struct sockaddr *dst, + short *tp, int *hlen); #endif #ifdef NS @@ -93,8 +93,8 @@ int ether_inputdebug = 0; #include #include -#define llc_snap_org_code llc_un.type_snap.org_code -#define llc_snap_ether_type llc_un.type_snap.ether_type +#define llc_snap_org_code llc_un.type_snap.org_code +#define llc_snap_ether_type llc_un.type_snap.ether_type extern u_char at_org_code[3]; extern u_char aarp_org_code[3]; @@ -115,7 +115,9 @@ int (*vlan_input_tag_p)(struct mbuf *m, uint16_t t); static int ether_output(struct ifnet *, struct mbuf *, struct sockaddr *, struct rtentry *); -/* bridge support */ +/* + * bridge support + */ int do_bridge; bridge_in_t *bridge_in_ptr; bdg_forward_t *bdg_forward_ptr; @@ -128,8 +130,8 @@ const uint8_t etherbroadcastaddr[ETHER_ADDR_LEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; -#define senderr(e) do { error = (e); goto bad;} while (0) -#define IFP2AC(IFP) ((struct arpcom *)IFP) +#define gotoerr(e) do { error = (e); goto bad;} while (0) +#define IFP2AC(ifp) ((struct arpcom *)(ifp)) int ether_ipfw_chk(struct mbuf **m0, struct ifnet *dst, @@ -145,180 +147,144 @@ static int ether_ipfw; */ static int ether_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, - struct rtentry *rt0) + struct rtentry *rt) { - short type; - int error = 0, hdrcmplt = 0; - u_char esrc[6], edst[6]; - struct rtentry *rt; - struct ether_header *eh; + struct ether_header *eh, *deh; + u_char *edst; int loop_copy = 0; - int hlen; /* link layer header lenght */ + int hlen = ETHER_HDR_LEN; /* link layer header length */ struct arpcom *ac = IFP2AC(ifp); + int error; - if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING)) - senderr(ENETDOWN); - rt = rt0; - if (rt) { - if ((rt->rt_flags & RTF_UP) == 0) { - rt0 = rt = rtalloc1(dst, 1, 0UL); - if (rt0) - rt->rt_refcnt--; - else - senderr(EHOSTUNREACH); - } - if (rt->rt_flags & RTF_GATEWAY) { - if (rt->rt_gwroute == 0) - goto lookup; - if (((rt = rt->rt_gwroute)->rt_flags & RTF_UP) == 0) { - rtfree(rt); rt = rt0; - lookup: rt->rt_gwroute = rtalloc1(rt->rt_gateway, 1, - 0UL); - if ((rt = rt->rt_gwroute) == 0) - senderr(EHOSTUNREACH); - } - } - if (rt->rt_flags & RTF_REJECT) - if (rt->rt_rmx.rmx_expire == 0 || - time_second < rt->rt_rmx.rmx_expire) - senderr(rt == rt0 ? EHOSTDOWN : EHOSTUNREACH); - } - hlen = ETHER_HDR_LEN; + if ((ifp->if_flags & (IFF_UP | IFF_RUNNING)) != (IFF_UP | IFF_RUNNING)) + gotoerr(ENETDOWN); + + M_PREPEND(m, sizeof(struct ether_header), MB_DONTWAIT); + if (m == NULL) + gotoerr(ENOBUFS); + eh = mtod(m, struct ether_header *); + edst = eh->ether_dhost; + + /* Fill in the destination ethernet address and frame type. */ switch (dst->sa_family) { #ifdef INET case AF_INET: - if (!arpresolve(ifp, rt, m, dst, edst, rt0)) + if (!arpresolve(ifp, rt, m, dst, edst)) return (0); /* if not yet resolved */ - type = htons(ETHERTYPE_IP); + eh->ether_type = htons(ETHERTYPE_IP); break; #endif #ifdef INET6 case AF_INET6: - if (!nd6_storelladdr(&ac->ac_if, rt, m, dst, (u_char *)edst)) { - /* Something bad happened */ - return(0); - } - type = htons(ETHERTYPE_IPV6); + if (!nd6_storelladdr(&ac->ac_if, rt, m, dst, edst)) + return (0); /* Something bad happened. */ + eh->ether_type = htons(ETHERTYPE_IPV6); break; #endif #ifdef IPX case AF_IPX: - if (ef_outputp) { - error = ef_outputp(ifp, &m, dst, &type, &hlen); - if (error) - goto bad; - } else - type = htons(ETHERTYPE_IPX); - bcopy((caddr_t)&(((struct sockaddr_ipx *)dst)->sipx_addr.x_host), - (caddr_t)edst, sizeof (edst)); + if (ef_outputp != NULL) { + error = ef_outputp(ifp, &m, dst, &eh->ether_type, + &hlen); + if (error) + goto bad; + } else { + eh->ether_type = htons(ETHERTYPE_IPX); + bcopy(&(((struct sockaddr_ipx *)dst)->sipx_addr.x_host), + edst, ETHER_ADDR_LEN); + } break; #endif #ifdef NETATALK - case AF_APPLETALK: - { - struct at_ifaddr *aa; - - if ((aa = at_ifawithnet((struct sockaddr_at *)dst)) == NULL) { - goto bad; - } - if (!aarpresolve(ac, m, (struct sockaddr_at *)dst, edst)) - return (0); - /* - * In the phase 2 case, need to prepend an mbuf for the llc header. - * Since we must preserve the value of m, which is passed to us by - * value, we m_copy() the first mbuf, and use it for our llc header. - */ - if ( aa->aa_flags & AFA_PHASE2 ) { - struct llc llc; - - M_PREPEND(m, sizeof(struct llc), MB_WAIT); - llc.llc_dsap = llc.llc_ssap = LLC_SNAP_LSAP; - llc.llc_control = LLC_UI; - bcopy(at_org_code, llc.llc_snap_org_code, sizeof(at_org_code)); - llc.llc_snap_ether_type = htons( ETHERTYPE_AT ); - bcopy(&llc, mtod(m, caddr_t), sizeof(struct llc)); - type = htons(m->m_pkthdr.len); - hlen = sizeof(struct llc) + ETHER_HDR_LEN; - } else { - type = htons(ETHERTYPE_AT); - } - break; + case AF_APPLETALK: { + struct at_ifaddr *aa; + + if ((aa = at_ifawithnet((struct sockaddr_at *)dst)) == NULL) { + error = 0; /* XXX */ + goto bad; + } + /* + * In the phase 2 case, need to prepend an mbuf for + * the llc header. Since we must preserve the value + * of m, which is passed to us by value, we m_copy() + * the first mbuf, and use it for our llc header. + */ + if (aa->aa_flags & AFA_PHASE2) { + struct llc llc; + + M_PREPEND(m, sizeof(struct llc), MB_DONTWAIT); + llc.llc_dsap = llc.llc_ssap = LLC_SNAP_LSAP; + llc.llc_control = LLC_UI; + bcopy(at_org_code, llc.llc_snap_org_code, + sizeof at_org_code); + llc.llc_snap_ether_type = htons(ETHERTYPE_AT); + bcopy(&llc, mtod(m, caddr_t), sizeof(struct llc)); + eh->ether_type = htons(m->m_pkthdr.len); + hlen = sizeof(struct llc) + ETHER_HDR_LEN; + } else { + eh->ether_type = htons(ETHERTYPE_AT); + } + if (!aarpresolve(ac, m, (struct sockaddr_at *)dst, edst)) + return (0); + break; } #endif /* NETATALK */ #ifdef NS case AF_NS: - switch(ns_nettype){ + switch(ns_nettype) { default: - case 0x8137: /* Novell Ethernet_II Ethernet TYPE II */ - type = 0x8137; + case 0x8137: /* Novell Ethernet_II Ethernet TYPE II */ + eh->ether_type = 0x8137; break; - case 0x0: /* Novell 802.3 */ - type = htons( m->m_pkthdr.len); + case 0x0: /* Novell 802.3 */ + eh->ether_type = htons(m->m_pkthdr.len); break; - case 0xe0e0: /* Novell 802.2 and Token-Ring */ - M_PREPEND(m, 3, MB_WAIT); - type = htons( m->m_pkthdr.len); + case 0xe0e0: /* Novell 802.2 and Token-Ring */ + M_PREPEND(m, 3, MB_DONTWAIT); + eh->ether_type = htons(m->m_pkthdr.len); cp = mtod(m, u_char *); *cp++ = 0xE0; *cp++ = 0xE0; *cp++ = 0x03; break; } - bcopy((caddr_t)&(((struct sockaddr_ns *)dst)->sns_addr.x_host), - (caddr_t)edst, sizeof (edst)); + bcopy(&(((struct sockaddr_ns *)dst)->sns_addr.x_host), edst, + ETHER_ADDR_LEN); /* * XXX if ns_thishost is the same as the node's ethernet * address then just the default code will catch this anyhow. * So I'm not sure if this next clause should be here at all? * [JRE] */ - if (!bcmp((caddr_t)edst, (caddr_t)&ns_thishost, sizeof(edst))){ + if (bcmp(edst, &ns_thishost, ETHER_ADDR_LEN) == 0) { m->m_pkthdr.rcvif = ifp; netisr_dispatch(NETISR_NS, m); return (error); } - if (!bcmp((caddr_t)edst, (caddr_t)&ns_broadhost, sizeof(edst))){ + if (bcmp(edst, &ns_broadhost, ETHER_ADDR_LEN) == 0) m->m_flags |= M_BCAST; - } break; #endif /* NS */ - case pseudo_AF_HDRCMPLT: - hdrcmplt = 1; - eh = (struct ether_header *)dst->sa_data; - (void)memcpy(esrc, eh->ether_shost, sizeof (esrc)); - /* FALLTHROUGH */ - case AF_UNSPEC: loop_copy = -1; /* if this is for us, don't do it */ - eh = (struct ether_header *)dst->sa_data; - (void)memcpy(edst, eh->ether_dhost, sizeof (edst)); - type = eh->ether_type; + deh = (struct ether_header *)dst->sa_data; + memcpy(edst, deh->ether_dhost, ETHER_ADDR_LEN); + eh->ether_type = deh->ether_type; break; default: printf("%s: can't handle af%d\n", ifp->if_xname, dst->sa_family); - senderr(EAFNOSUPPORT); + gotoerr(EAFNOSUPPORT); } - /* - * Add local net header. If no space in first mbuf, - * allocate another. - */ - M_PREPEND(m, sizeof (struct ether_header), MB_DONTWAIT); - if (m == 0) - senderr(ENOBUFS); - eh = mtod(m, struct ether_header *); - (void)memcpy(&eh->ether_type, &type, - sizeof(eh->ether_type)); - (void)memcpy(eh->ether_dhost, edst, sizeof (edst)); - if (hdrcmplt) - (void)memcpy(eh->ether_shost, esrc, - sizeof(eh->ether_shost)); + if (dst->sa_family == pseudo_AF_HDRCMPLT) /* unlikely */ + memcpy(eh->ether_shost, + ((struct ether_header *)dst->sa_data)->ether_shost, + ETHER_ADDR_LEN); else - (void)memcpy(eh->ether_shost, ac->ac_enaddr, - sizeof(eh->ether_shost)); + memcpy(eh->ether_shost, ac->ac_enaddr, ETHER_ADDR_LEN); /* * If a simplex interface, and the packet is being sent to our @@ -333,25 +299,25 @@ ether_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, int csum_flags = 0; if (m->m_pkthdr.csum_flags & CSUM_IP) - csum_flags |= (CSUM_IP_CHECKED|CSUM_IP_VALID); + csum_flags |= (CSUM_IP_CHECKED | CSUM_IP_VALID); if (m->m_pkthdr.csum_flags & CSUM_DELAY_DATA) - csum_flags |= (CSUM_DATA_VALID|CSUM_PSEUDO_HDR); + csum_flags |= (CSUM_DATA_VALID | CSUM_PSEUDO_HDR); if ((m->m_flags & M_BCAST) || (loop_copy > 0)) { struct mbuf *n; - if ((n = m_copy(m, 0, (int)M_COPYALL)) != NULL) { + if ((n = m_copypacket(m, MB_DONTWAIT)) != NULL) { n->m_pkthdr.csum_flags |= csum_flags; if (csum_flags & CSUM_DATA_VALID) n->m_pkthdr.csum_data = 0xffff; - (void)if_simloop(ifp, n, dst->sa_family, hlen); + if_simloop(ifp, n, dst->sa_family, hlen); } else ifp->if_iqdrops++; - } else if (bcmp(eh->ether_dhost, - eh->ether_shost, ETHER_ADDR_LEN) == 0) { + } else if (bcmp(eh->ether_dhost, eh->ether_shost, + ETHER_ADDR_LEN) == 0) { m->m_pkthdr.csum_flags |= csum_flags; if (csum_flags & CSUM_DATA_VALID) m->m_pkthdr.csum_data = 0xffff; - (void) if_simloop(ifp, m, dst->sa_family, hlen); + if_simloop(ifp, m, dst->sa_family, hlen); return (0); /* XXX */ } } @@ -378,13 +344,11 @@ bad: if (m != NULL) * in the first mbuf (if BRIDGE'ing). */ int -ether_output_frame(ifp, m) - struct ifnet *ifp; - struct mbuf *m; +ether_output_frame(struct ifnet *ifp, struct mbuf *m) { + struct ip_fw *rule = NULL; int error = 0; int s; - struct ip_fw *rule = NULL; /* Extract info from dummynet tag, ignore others */ for (; m->m_type == MT_TAG; m = m->m_next) @@ -417,12 +381,12 @@ no_bridge: if (ether_ipfw_chk(&m, ifp, &rule, eh, 0) == 0) { if (m) { m_freem(m); - return ENOBUFS; /* pkt dropped */ + return ENOBUFS; /* pkt dropped */ } else return 0; /* consumed e.g. in a pipe */ } /* packet was ok, restore the ethernet header */ - if ( (void *)(eh + 1) == (void *)m->m_data) { + if ((void *)(eh + 1) == (void *)m->m_data) { m->m_data -= ETHER_HDR_LEN ; m->m_len += ETHER_HDR_LEN ; m->m_pkthdr.len += ETHER_HDR_LEN ; @@ -453,12 +417,16 @@ no_bridge: * to distinguish that case from ether_output_frame(); */ int -ether_ipfw_chk(struct mbuf **m0, struct ifnet *dst, - struct ip_fw **rule, struct ether_header *eh, int shared) +ether_ipfw_chk( + struct mbuf **m0, + struct ifnet *dst, + struct ip_fw **rule, + struct ether_header *eh, + int shared) { struct ether_header save_eh = *eh; /* might be a ptr in m */ - int i; struct ip_fw_args args; + int i; if (*rule != NULL && fw_one_pass) return 1; /* dummynet packet, already partially processed */ @@ -467,8 +435,8 @@ ether_ipfw_chk(struct mbuf **m0, struct ifnet *dst, * I need some amt of data to be contiguous, and in case others need * the packet (shared==1) also better be in the first mbuf. */ - i = min( (*m0)->m_pkthdr.len, max_protohdr); - if ( shared || (*m0)->m_len < i) { + i = min((*m0)->m_pkthdr.len, max_protohdr); + if (shared || (*m0)->m_len < i) { *m0 = m_pullup(*m0, i); if (*m0 == NULL) return 0; @@ -484,7 +452,7 @@ ether_ipfw_chk(struct mbuf **m0, struct ifnet *dst, *m0 = args.m; *rule = args.rule; - if ( (i & IP_FW_PORT_DENY_FLAG) || *m0 == NULL) /* drop */ + if ((i & IP_FW_PORT_DENY_FLAG) || *m0 == NULL) /* drop */ return 0; if (i == 0) /* a PASS rule. */ @@ -509,7 +477,7 @@ ether_ipfw_chk(struct mbuf **m0, struct ifnet *dst, * Prepend the header, optimize for the common case of * eh pointing into the mbuf. */ - if ( (void *)(eh + 1) == (void *)m->m_data) { + if ((void *)(eh + 1) == (void *)m->m_data) { m->m_data -= ETHER_HDR_LEN ; m->m_len += ETHER_HDR_LEN ; m->m_pkthdr.len += ETHER_HDR_LEN ; @@ -623,16 +591,14 @@ ether_input(struct ifnet *ifp, struct ether_header *eh, struct mbuf *m) } eh = &save_eh ; } - if (bif == BDG_LOCAL - || bif == BDG_BCAST - || bif == BDG_MCAST) - goto recvLocal; /* receive locally */ + if (bif == BDG_LOCAL || bif == BDG_BCAST || bif == BDG_MCAST) + goto recvLocal; /* receive locally */ /* If not local and not multicast, just drop it */ if (m != NULL) m_freem(m); return; - } + } recvLocal: /* Continue with upper layer processing */ @@ -643,10 +609,7 @@ recvLocal: * Upper layer processing for a received Ethernet packet. */ void -ether_demux(ifp, eh, m) - struct ifnet *ifp; - struct ether_header *eh; - struct mbuf *m; +ether_demux(struct ifnet *ifp, struct ether_header *eh, struct mbuf *m) { int isr; u_short ether_type; @@ -665,22 +628,22 @@ ether_demux(ifp, eh, m) if (rule) /* packet was already bridged */ goto post_stats; - if (! (BDG_ACTIVE(ifp) ) ) - /* Discard packet if upper layers shouldn't see it because it was - unicast to a different Ethernet address. If the driver is working - properly, then this situation can only happen when the interface - is in promiscuous mode. */ - if ((ifp->if_flags & IFF_PROMISC) != 0 - && (eh->ether_dhost[0] & 1) == 0 - && bcmp(eh->ether_dhost, - IFP2AC(ifp)->ac_enaddr, ETHER_ADDR_LEN) != 0 - && (ifp->if_flags & IFF_PPROMISC) == 0) { + /* + * Discard packet if upper layers shouldn't see it because + * it was unicast to a different Ethernet address. If the + * driver is working properly, then this situation can only + * happen when the interface is in promiscuous mode. + */ + if (!BDG_ACTIVE(ifp) && + (ifp->if_flags & IFF_PROMISC) && + (eh->ether_dhost[0] & 1) == 0 && + !bcmp(eh->ether_dhost, IFP2AC(ifp)->ac_enaddr, ETHER_ADDR_LEN) && + !(ifp->if_flags & IFF_PPROMISC)) { m_freem(m); return; } - /* Discard packet if interface is not up */ - if ((ifp->if_flags & IFF_UP) == 0) { + if (!(ifp->if_flags & IFF_UP)) { m_freem(m); return; } @@ -741,12 +704,12 @@ post_stats: #endif /* NS */ #ifdef NETATALK - case ETHERTYPE_AT: + case ETHERTYPE_AT: isr = NETISR_ATALK1; - break; - case ETHERTYPE_AARP: + break; + case ETHERTYPE_AARP: isr = NETISR_AARP; - break; + break; #endif /* NETATALK */ case ETHERTYPE_VLAN: /* XXX lock ? */ @@ -784,7 +747,7 @@ post_stats: if (l->llc_dsap == LLC_SNAP_LSAP && l->llc_ssap == LLC_SNAP_LSAP && l->llc_control == LLC_UI) { - if (bcmp(&(l->llc_snap_org_code)[0], at_org_code, + if (bcmp(&(l->llc_snap_org_code)[0], at_org_code, sizeof(at_org_code)) == 0 && ntohs(l->llc_snap_ether_type) == ETHERTYPE_AT) { m_adj(m, sizeof(struct llc)); @@ -836,7 +799,7 @@ ether_ifattach_bpf(struct ifnet *ifp, uint8_t *lla, u_int dlt, u_int hdrlen) ifp->if_mtu = ETHERMTU; ifp->if_resolvemulti = ether_resolvemulti; if (ifp->if_baudrate == 0) - ifp->if_baudrate = 10000000; + ifp->if_baudrate = 10000000; ifa = ifnet_addrs[ifp->if_index - 1]; KASSERT(ifa != NULL, ("%s: no lladdr!\n", __FUNCTION__)); sdl = (struct sockaddr_dl *)ifa->ifa_addr; @@ -884,10 +847,7 @@ SYSCTL_INT(_net_link_ether, OID_AUTO, ipfw, CTLFLAG_RW, ðer_ipfw,0,"Pass ether pkts through firewall"); int -ether_ioctl(ifp, command, data) - struct ifnet *ifp; - int command; - caddr_t data; +ether_ioctl(struct ifnet *ifp, int command, caddr_t data) { struct ifaddr *ifa = (struct ifaddr *) data; struct ifreq *ifr = (struct ifreq *) data; @@ -910,23 +870,16 @@ ether_ioctl(ifp, command, data) */ case AF_IPX: { - struct ipx_addr *ina = &(IA_SIPX(ifa)->sipx_addr); + struct ipx_addr *ina = &IA_SIPX(ifa)->sipx_addr; struct arpcom *ac = IFP2AC(ifp); if (ipx_nullhost(*ina)) - ina->x_host = - *(union ipx_host *) - ac->ac_enaddr; - else { - bcopy((caddr_t) ina->x_host.c_host, - (caddr_t) ac->ac_enaddr, - sizeof(ac->ac_enaddr)); - } + ina->x_host = *(union ipx_host *) ac->ac_enaddr; + else + bcopy(ina->x_host.c_host, ac->ac_enaddr, + sizeof ac->ac_enaddr); - /* - * Set new address - */ - ifp->if_init(ifp->if_softc); + ifp->if_init(ifp->if_softc); /* Set new address. */ break; } #endif @@ -940,13 +893,10 @@ ether_ioctl(ifp, command, data) struct arpcom *ac = IFP2AC(ifp); if (ns_nullhost(*ina)) - ina->x_host = - *(union ns_host *) (ac->ac_enaddr); - else { - bcopy((caddr_t) ina->x_host.c_host, - (caddr_t) ac->ac_enaddr, - sizeof(ac->ac_enaddr)); - } + ina->x_host = *(union ns_host *)(ac->ac_enaddr); + else + bcopy(ina->x_host.c_host, ac->ac_enaddr, + sizeof ac->ac_enaddr); /* * Set new address @@ -962,13 +912,9 @@ ether_ioctl(ifp, command, data) break; case SIOCGIFADDR: - { - struct sockaddr *sa; - - sa = (struct sockaddr *) & ifr->ifr_data; - bcopy(IFP2AC(ifp)->ac_enaddr, - (caddr_t) sa->sa_data, ETHER_ADDR_LEN); - } + bcopy(IFP2AC(ifp)->ac_enaddr, + ((struct sockaddr *)ifr->ifr_data)->sa_data, + ETHER_ADDR_LEN); break; case SIOCSIFMTU: @@ -989,10 +935,10 @@ ether_ioctl(ifp, command, data) } int -ether_resolvemulti(ifp, llsa, sa) - struct ifnet *ifp; - struct sockaddr **llsa; - struct sockaddr *sa; +ether_resolvemulti( + struct ifnet *ifp, + struct sockaddr **llsa, + struct sockaddr *sa) { struct sockaddr_dl *sdl; struct sockaddr_in *sin; @@ -1092,7 +1038,7 @@ ether_crc32_le(const uint8_t *buf, size_t len) } } - return(crc); + return (crc); } #else uint32_t @@ -1115,7 +1061,7 @@ ether_crc32_le(const uint8_t *buf, size_t len) crc = (crc >> 4) ^ crctab[crc & 0xf]; } - return(crc); + return (crc); } #endif @@ -1138,5 +1084,5 @@ ether_crc32_be(const uint8_t *buf, size_t len) } } - return(crc); + return (crc); } diff --git a/sys/net/if_fddisubr.c b/sys/net/if_fddisubr.c index 0959446867..88866f77c1 100644 --- a/sys/net/if_fddisubr.c +++ b/sys/net/if_fddisubr.c @@ -34,7 +34,7 @@ * * from: if_ethersubr.c,v 1.5 1994/12/13 22:31:45 wollman Exp * $FreeBSD: src/sys/net/if_fddisubr.c,v 1.41.2.8 2002/02/20 23:34:09 fjoe Exp $ - * $DragonFly: src/sys/net/Attic/if_fddisubr.c,v 1.12 2004/12/14 18:46:08 hsu Exp $ + * $DragonFly: src/sys/net/Attic/if_fddisubr.c,v 1.13 2004/12/21 02:54:14 hsu Exp $ */ #include "opt_atalk.h" @@ -72,7 +72,7 @@ #endif #ifdef IPX -#include +#include #include #endif @@ -112,10 +112,10 @@ static int fddi_output(struct ifnet *, struct mbuf *, struct sockaddr *, #define llc_snap llc_un.type_snap #endif -#if defined(__bsdi__) || defined(__NetBSD__) -#define RTALLOC1(a, b) rtalloc1(a, b) +#if defined(__DragonFly__) +#define RTALLOC1(a, b) rtlookup(a, b, 0UL) #define ARPRESOLVE(a, b, c, d, e, f) arpresolve(a, b, c, d, e) -#elif defined(__DragonFly__) || defined(__FreeBSD__) +#elif defined(__FreeBSD__) #define RTALLOC1(a, b) rtalloc1(a, b, 0UL) #define ARPRESOLVE(a, b, c, d, e, f) arpresolve(a, b, c, d, e, f) #endif @@ -128,54 +128,23 @@ static int fddi_output(struct ifnet *, struct mbuf *, struct sockaddr *, */ static int fddi_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, - struct rtentry *rt0) + struct rtentry *rt) { + struct arpcom *ac = (struct arpcom *)ifp; u_int16_t type; - int s, loop_copy = 0, error = 0, hdrcmplt = 0; - u_char esrc[6], edst[6]; - struct rtentry *rt; + u_char esrc[6], edst[6]; struct fddi_header *fh; - struct arpcom *ac = (struct arpcom *)ifp; + boolean_t hdrcmplt = FALSE; + int s, loop_copy = 0, error; if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING)) senderr(ENETDOWN); - getmicrotime(&ifp->if_lastchange); -#if !defined(__bsdi__) || _BSDI_VERSION >= 199401 - if ((rt = rt0) != NULL) { - if ((rt->rt_flags & RTF_UP) == 0) { - if ((rt0 = rt = RTALLOC1(dst, 1)) != NULL) - rt->rt_refcnt--; - else - senderr(EHOSTUNREACH); - } - if (rt->rt_flags & RTF_GATEWAY) { - if (rt->rt_gwroute == 0) - goto lookup; - if (((rt = rt->rt_gwroute)->rt_flags & RTF_UP) == 0) { - rtfree(rt); rt = rt0; - lookup: rt->rt_gwroute = RTALLOC1(rt->rt_gateway, 1); - if ((rt = rt->rt_gwroute) == 0) - senderr(EHOSTUNREACH); - } - } - if (rt->rt_flags & RTF_REJECT) - if (rt->rt_rmx.rmx_expire == 0 || - time_second < rt->rt_rmx.rmx_expire) - senderr(rt == rt0 ? EHOSTDOWN : EHOSTUNREACH); - } -#endif - switch (dst->sa_family) { + switch (dst->sa_family) { #ifdef INET case AF_INET: { -#if !defined(__bsdi__) || _BSDI_VERSION >= 199401 - if (!ARPRESOLVE(ifp, rt, m, dst, edst, rt0)) - return (0); /* if not yet resolved */ -#else - int usetrailers; - if (!arpresolve(ac, m, &((struct sockaddr_in *)dst)->sin_addr, edst, &usetrailers)) + if (!arpresolve(ifp, rt, m, dst, edst)) return (0); /* if not yet resolved */ -#endif type = htons(ETHERTYPE_IP); break; } @@ -184,7 +153,7 @@ fddi_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, case AF_INET6: if (!nd6_storelladdr(&ac->ac_if, rt, m, dst, (u_char *)edst)) { /* Something bad happened */ - return(0); + return (0); } type = htons(ETHERTYPE_IPV6); break; @@ -192,67 +161,77 @@ fddi_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, #ifdef IPX case AF_IPX: type = htons(ETHERTYPE_IPX); - bcopy((caddr_t)&(((struct sockaddr_ipx *)dst)->sipx_addr.x_host), - (caddr_t)edst, sizeof (edst)); + bcopy(&(((struct sockaddr_ipx *)dst)->sipx_addr.x_host), edst, + sizeof edst); break; #endif #ifdef NETATALK case AF_APPLETALK: { - struct at_ifaddr *aa; - if (!aarpresolve(ac, m, (struct sockaddr_at *)dst, edst)) - return (0); - /* - * ifaddr is the first thing in at_ifaddr - */ - if ((aa = at_ifawithnet( (struct sockaddr_at *)dst)) == 0) - goto bad; - - /* - * In the phase 2 case, we need to prepend an mbuf for the llc header. - * Since we must preserve the value of m, which is passed to us by - * value, we m_copy() the first mbuf, and use it for our llc header. - */ - if (aa->aa_flags & AFA_PHASE2) { - struct llc llc; - - M_PREPEND(m, sizeof(struct llc), MB_WAIT); - if (m == 0) - senderr(ENOBUFS); - llc.llc_dsap = llc.llc_ssap = LLC_SNAP_LSAP; - llc.llc_control = LLC_UI; - bcopy(at_org_code, llc.llc_snap_org_code, sizeof(at_org_code)); - llc.llc_snap_ether_type = htons(ETHERTYPE_AT); - bcopy(&llc, mtod(m, caddr_t), sizeof(struct llc)); - type = 0; - } else { - type = htons(ETHERTYPE_AT); - } - break; + struct at_ifaddr *aa; + + if (!aarpresolve((struct arpcom *) ifp, m, + (struct sockaddr_at *)dst, edst)) + return (0); + + /* + * ifaddr is the first thing in at_ifaddr + */ + if ((aa = at_ifawithnet((struct sockaddr_at *)dst)) == NULL) { + error = 0; /* XXX */ + goto bad; + } + + /* + * In the phase 2 case, we need to prepend an mbuf + * for the llc header. Since we must preserve the + * value of m, which is passed to us by value, we + * m_copy() the first mbuf, and use it for our llc + * header. + */ + if (aa->aa_flags & AFA_PHASE2) { + struct llc llc; + + M_PREPEND(m, sizeof(struct llc), MB_WAIT); + if (m == NULL) + senderr(ENOBUFS); + llc.llc_dsap = llc.llc_ssap = LLC_SNAP_LSAP; + llc.llc_control = LLC_UI; + bcopy(at_org_code, llc.llc_snap_org_code, + sizeof at_org_code); + llc.llc_snap_ether_type = htons(ETHERTYPE_AT); + bcopy(&llc, mtod(m, caddr_t), sizeof(struct llc)); + type = 0; + } else { + type = htons(ETHERTYPE_AT); + } + break; } #endif /* NETATALK */ #ifdef NS case AF_NS: type = htons(ETHERTYPE_NS); - bcopy((caddr_t)&(((struct sockaddr_ns *)dst)->sns_addr.x_host), - (caddr_t)edst, sizeof (edst)); + bcopy(&(((struct sockaddr_ns *)dst)->sns_addr.x_host), edst, + sizeof edst); break; #endif case pseudo_AF_HDRCMPLT: { struct ether_header *eh; - hdrcmplt = 1; + + hdrcmplt = TRUE; eh = (struct ether_header *)dst->sa_data; - (void)memcpy((caddr_t)esrc, (caddr_t)eh->ether_shost, sizeof (esrc)); + memcpy(esrc, eh->ether_shost, sizeof esrc); /* FALLTHROUGH */ } case AF_UNSPEC: { struct ether_header *eh; + loop_copy = -1; eh = (struct ether_header *)dst->sa_data; - (void)memcpy((caddr_t)edst, (caddr_t)eh->ether_dhost, sizeof (edst)); + memcpy(edst, eh->ether_dhost, sizeof edst); if (*edst & 1) m->m_flags |= (M_BCAST|M_MCAST); type = eh->ether_type; @@ -267,7 +246,7 @@ fddi_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, case FDDIFC_LLC_ASYNC: { /* legal priorities are 0 through 7 */ if ((fh->fddi_fc & FDDIFC_Z) > 7) - goto bad; + goto bad; break; } case FDDIFC_LLC_SYNC: { @@ -284,12 +263,12 @@ fddi_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, } default: { /* anything else is too dangerous */ - goto bad; + goto bad; } } error = 0; if (fh->fddi_dhost[0] & 1) - m->m_flags |= (M_BCAST|M_MCAST); + m->m_flags |= (M_BCAST | M_MCAST); goto queue_it; } default: @@ -300,36 +279,36 @@ fddi_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, if (type != 0) { struct llc *l; - M_PREPEND(m, sizeof (struct llc), MB_DONTWAIT); - if (m == 0) - senderr(ENOBUFS); + + M_PREPEND(m, sizeof(struct llc), MB_DONTWAIT); + if (m == NULL) + return (ENOBUFS); l = mtod(m, struct llc *); l->llc_control = LLC_UI; l->llc_dsap = l->llc_ssap = LLC_SNAP_LSAP; - l->llc_snap.org_code[0] = l->llc_snap.org_code[1] = l->llc_snap.org_code[2] = 0; - (void)memcpy((caddr_t) &l->llc_snap.ether_type, (caddr_t) &type, - sizeof(u_int16_t)); + l->llc_snap.org_code[0] = l->llc_snap.org_code[1] = + l->llc_snap.org_code[2] = 0; + memcpy(&l->llc_snap.ether_type, &type, sizeof(u_int16_t)); } /* * Add local net header. If no space in first mbuf, * allocate another. */ - M_PREPEND(m, sizeof (struct fddi_header), MB_DONTWAIT); - if (m == 0) - senderr(ENOBUFS); + M_PREPEND(m, sizeof(struct fddi_header), MB_DONTWAIT); + if (m == NULL) + return (ENOBUFS); fh = mtod(m, struct fddi_header *); fh->fddi_fc = FDDIFC_LLC_ASYNC|FDDIFC_LLC_PRIO4; - (void)memcpy((caddr_t)fh->fddi_dhost, (caddr_t)edst, sizeof (edst)); - queue_it: + memcpy(fh->fddi_dhost, edst, sizeof edst); + +queue_it: if (hdrcmplt) - (void)memcpy((caddr_t)fh->fddi_shost, (caddr_t)esrc, - sizeof(fh->fddi_shost)); + memcpy(fh->fddi_shost, esrc, sizeof fh->fddi_shost); else - (void)memcpy((caddr_t)fh->fddi_shost, (caddr_t)ac->ac_enaddr, - sizeof(fh->fddi_shost)); + memcpy(fh->fddi_shost, ac->ac_enaddr, sizeof fh->fddi_shost); /* - * If a simplex interface, and the packet is being sent to our + memcpy(fh->fddi_shost, ac->ac_enaddr, sizeof fh->fddi_shost); * Ethernet address or a broadcast address, loopback a copy. * XXX To make a simplex device behave exactly like a duplex * device, we should copy in the case of sending to our own @@ -340,15 +319,15 @@ fddi_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, if ((ifp->if_flags & IFF_SIMPLEX) && (loop_copy != -1)) { if ((m->m_flags & M_BCAST) || loop_copy) { - struct mbuf *n = m_copy(m, 0, (int)M_COPYALL); - - (void) if_simloop(ifp, - n, dst->sa_family, sizeof(struct fddi_header)); - } else if (bcmp(fh->fddi_dhost, - fh->fddi_shost, sizeof(fh->fddi_shost)) == 0) { - (void) if_simloop(ifp, - m, dst->sa_family, sizeof(struct fddi_header)); - return(0); /* XXX */ + struct mbuf *n = m_copypacket(m, MB_DONTWAIT); + + if_simloop(ifp, n, dst->sa_family, + sizeof(struct fddi_header)); + } else if (bcmp(fh->fddi_dhost, fh->fddi_shost, + sizeof(fh->fddi_shost)) == 0) { + if_simloop(ifp, m, dst->sa_family, + sizeof(struct fddi_header)); + senderr(0); /* XXX */ } } @@ -370,7 +349,7 @@ fddi_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, (*ifp->if_start)(ifp); splx(s); - return (error); + return (0); bad: if (m) @@ -403,7 +382,7 @@ fddi_input(struct ifnet *ifp, struct mbuf *m) return; } getmicrotime(&ifp->if_lastchange); - ifp->if_ibytes += m->m_pkthdr.len + sizeof (*fh); + ifp->if_ibytes += m->m_pkthdr.len + sizeof *fh; if (fh->fddi_dhost[0] & 1) { if (bcmp(ifp->if_broadcastaddr, fh->fddi_dhost, ifp->if_addrlen) == 0) @@ -412,8 +391,8 @@ fddi_input(struct ifnet *ifp, struct mbuf *m) m->m_flags |= M_MCAST; ifp->if_imcasts++; } else if ((ifp->if_flags & IFF_PROMISC) && - bcmp(((struct arpcom *)ifp)->ac_enaddr, (caddr_t)fh->fddi_dhost, - sizeof(fh->fddi_dhost)) != 0) { + bcmp(((struct arpcom *)ifp)->ac_enaddr, fh->fddi_dhost, + sizeof fh->fddi_dhost) != 0) { m_freem(m); return; } @@ -449,7 +428,7 @@ fddi_input(struct ifnet *ifp, struct mbuf *m) if (bcmp(&(l->llc_snap_org_code)[0], aarp_org_code, sizeof(aarp_org_code)) == 0 && ntohs(l->llc_snap_ether_type) == ETHERTYPE_AARP) { - m_adj( m, sizeof( struct llc )); + m_adj(m, sizeof(struct llc)); isr = NETISR_AARP; break; } @@ -479,11 +458,11 @@ fddi_input(struct ifnet *ifp, struct mbuf *m) isr = NETISR_IPV6; break; #endif -#ifdef IPX - case ETHERTYPE_IPX: +#ifdef IPX + case ETHERTYPE_IPX: isr = NETISR_IPX; - break; -#endif + break; +#endif #ifdef NS case ETHERTYPE_NS: isr = NETISR_NS; @@ -494,7 +473,7 @@ fddi_input(struct ifnet *ifp, struct mbuf *m) isr = NETISR_DECNET; break; #endif -#ifdef NETATALK +#ifdef NETATALK case ETHERTYPE_AT: isr = NETISR_ATALK1; break; @@ -510,7 +489,7 @@ fddi_input(struct ifnet *ifp, struct mbuf *m) break; } #endif /* INET || NS */ - + default: /* printf("fddi_input: unknown dsap 0x%x\n", l->llc_dsap); */ ifp->if_noproto++; @@ -566,8 +545,8 @@ fddi_ifattach(ifp) sdl->sdl_family == AF_LINK) { sdl->sdl_type = IFT_FDDI; sdl->sdl_alen = ifp->if_addrlen; - bcopy((caddr_t)((struct arpcom *)ifp)->ac_enaddr, - LLADDR(sdl), ifp->if_addrlen); + bcopy(((struct arpcom *)ifp)->ac_enaddr, LLADDR(sdl), + ifp->if_addrlen); break; } #endif diff --git a/sys/net/if_iso88025subr.c b/sys/net/if_iso88025subr.c index 511571f51a..d83d82f9b7 100644 --- a/sys/net/if_iso88025subr.c +++ b/sys/net/if_iso88025subr.c @@ -7,7 +7,7 @@ * * Questions, comments or suggestions should be directed to * Larry Lile . - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -31,14 +31,14 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/net/if_iso88025subr.c,v 1.7.2.7 2002/06/18 00:15:31 kbyanc Exp $ - * $DragonFly: src/sys/net/Attic/if_iso88025subr.c,v 1.9 2004/07/23 07:16:30 joerg Exp $ + * $DragonFly: src/sys/net/Attic/if_iso88025subr.c,v 1.10 2004/12/21 02:54:14 hsu Exp $ * */ /* * * General ISO 802.5 (Token Ring) support routines - * + * */ #include "opt_inet.h" @@ -49,7 +49,7 @@ #include #include #include -#include +#include #include #include @@ -104,120 +104,98 @@ iso88025_ifattach(struct ifnet *ifp) if (ifp->if_mtu == 0) ifp->if_mtu = ISO88025_DEFAULT_MTU; - ifa = ifnet_addrs[ifp->if_index - 1]; - if (ifa == 0) { - printf("iso88025_ifattach: no lladdr!\n"); - return; - } - sdl = (struct sockaddr_dl *)ifa->ifa_addr; - sdl->sdl_type = IFT_ISO88025; - sdl->sdl_alen = ifp->if_addrlen; - bcopy(((struct arpcom *)ifp)->ac_enaddr, LLADDR(sdl), ifp->if_addrlen); + ifa = ifnet_addrs[ifp->if_index - 1]; + if (ifa == NULL) { + printf("iso88025_ifattach: no lladdr!\n"); + return; + } + sdl = (struct sockaddr_dl *)ifa->ifa_addr; + sdl->sdl_type = IFT_ISO88025; + sdl->sdl_alen = ifp->if_addrlen; + bcopy(((struct arpcom *)ifp)->ac_enaddr, LLADDR(sdl), ifp->if_addrlen); bpfattach(ifp, DLT_IEEE802, sizeof(struct iso88025_header)); } int iso88025_ioctl(struct ifnet *ifp, int command, caddr_t data) { - struct ifaddr *ifa = (struct ifaddr *) data; - struct ifreq *ifr = (struct ifreq *) data; - int error = 0; + struct ifaddr *ifa = (struct ifaddr *) data; + struct ifreq *ifr = (struct ifreq *) data; + int error = 0; - switch (command) { - case SIOCSIFADDR: - ifp->if_flags |= IFF_UP; + switch (command) { + case SIOCSIFADDR: + ifp->if_flags |= IFF_UP; - switch (ifa->ifa_addr->sa_family) { + switch (ifa->ifa_addr->sa_family) { #ifdef INET - case AF_INET: - ifp->if_init(ifp->if_softc); /* before arpwhohas */ - arp_ifinit(ifp, ifa); - break; + case AF_INET: + ifp->if_init(ifp->if_softc); /* before arpwhohas */ + arp_ifinit(ifp, ifa); + break; #endif - default: - ifp->if_init(ifp->if_softc); - break; - } - break; - - case SIOCGIFADDR: - { - struct sockaddr *sa; - - sa = (struct sockaddr *) & ifr->ifr_data; - bcopy(((struct arpcom *)ifp->if_softc)->ac_enaddr, - (caddr_t) sa->sa_data, ISO88025_ADDR_LEN); - } - break; - - case SIOCSIFMTU: - /* - * Set the interface MTU. - */ - if (ifr->ifr_mtu > ISO88025_MAX_MTU) { - error = EINVAL; - } else { - ifp->if_mtu = ifr->ifr_mtu; - } - break; - } - return (error); + default: + ifp->if_init(ifp->if_softc); + break; + } + break; + + case SIOCGIFADDR: + bcopy(((struct arpcom *)ifp->if_softc)->ac_enaddr, + ((struct sockaddr *)ifr->ifr_data)->sa_data, + ISO88025_ADDR_LEN); + break; + + case SIOCSIFMTU: + /* + * Set the interface MTU. + */ + if (ifr->ifr_mtu > ISO88025_MAX_MTU) { + error = EINVAL; + } else { + ifp->if_mtu = ifr->ifr_mtu; + } + break; + } + return (error); } /* * ISO88025 encapsulation */ static int -iso88025_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, struct rtentry *rt0) +iso88025_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, + struct rtentry *rt0) { struct iso88025_header *th; struct iso88025_header gen_th; struct iso88025_sockaddr_data *sd = (struct iso88025_sockaddr_data *)dst->sa_data; - struct llc *l; + struct llc *l; struct sockaddr_dl *sdl = NULL; - int s, error = 0, rif_len = 0; - u_char edst[6]; + int s, error = 0, rif_len = 0; + u_char edst[6]; struct rtentry *rt; int len = m->m_pkthdr.len, loop_copy = 0; struct arpcom *ac = (struct arpcom *)ifp; if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING)) senderr(ENETDOWN); - rt = rt0; - if (rt) { - if ((rt->rt_flags & RTF_UP) == 0) { - rt0 = rt = rtalloc1(dst, 1, 0UL); - if (rt0) - rt->rt_refcnt--; - else - senderr(EHOSTUNREACH); - } - if (rt->rt_flags & RTF_GATEWAY) { - if (rt->rt_gwroute == 0) - goto lookup; - if (((rt = rt->rt_gwroute)->rt_flags & RTF_UP) == 0) { - rtfree(rt); rt = rt0; - lookup: rt->rt_gwroute = rtalloc1(rt->rt_gateway, 1, - 0UL); - if ((rt = rt->rt_gwroute) == 0) - senderr(EHOSTUNREACH); - } - } - if (rt->rt_flags & RTF_REJECT) - if (rt->rt_rmx.rmx_expire == 0 || - time_second < rt->rt_rmx.rmx_expire) - senderr(rt == rt0 ? EHOSTDOWN : EHOSTUNREACH); - } - /* Calculate routing info length based on arp table entry */ + if (rt0 == NULL) + senderr(EHOSTUNREACH); + error = rt_llroute(dst, rt0, &rt); + if (error != 0) + senderr(error); + + /* Calculate routing info length based on arp table entry. */ if (rt && (sdl = (struct sockaddr_dl *)rt->rt_gateway)) if (SDL_ISO88025(sdl)->trld_rcf != NULL) rif_len = TR_RCF_RIFLEN(SDL_ISO88025(sdl)->trld_rcf); - /* Generate a generic 802.5 header for the packet */ + /* Generate a generic 802.5 header for the packet. */ gen_th.ac = TR_AC; gen_th.fc = TR_LLC_FRAME; - memcpy(gen_th.iso88025_shost, ac->ac_enaddr, sizeof(ac->ac_enaddr)); + memcpy(gen_th.iso88025_shost, ac->ac_enaddr, sizeof ac->ac_enaddr); if (rif_len) { gen_th.iso88025_shost[0] |= TR_RII; if (rif_len > 2) { @@ -225,20 +203,20 @@ iso88025_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, struct memcpy(gen_th.rd, sdl->sdl_route, rif_len - 2); } } - + switch (dst->sa_family) { #ifdef INET case AF_INET: - if (!arpresolve(ifp, rt, m, dst, edst, rt0)) + if (!arpresolve(ifp, rt0, m, dst, edst)) return (0); /* if not yet resolved */ /* Add LLC and SNAP headers */ M_PREPEND(m, 8, MB_DONTWAIT); - if (m == 0) - senderr(ENOBUFS); + if (m == NULL) + return (ENOBUFS); l = mtod(m, struct llc *); - l->llc_un.type_snap.ether_type = htons(ETHERTYPE_IP); - l->llc_dsap = l->llc_ssap = LLC_SNAP_LSAP; + l->llc_un.type_snap.ether_type = htons(ETHERTYPE_IP); + l->llc_dsap = l->llc_ssap = LLC_SNAP_LSAP; l->llc_un.type_snap.control = LLC_UI; l->llc_un.type_snap.org_code[0] = 0x0; l->llc_un.type_snap.org_code[1] = 0x0; @@ -256,7 +234,7 @@ iso88025_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, struct * mbuf provided, ac/fc are set in sa_data. sockaddr.sa_data * should be a iso88025_sockaddr_data structure see iso88025.h */ - loop_copy = -1; + loop_copy = -1; sd = (struct iso88025_sockaddr_data *)dst->sa_data; gen_th.ac = sd->ac; gen_th.fc = sd->fc; @@ -275,45 +253,44 @@ iso88025_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, struct * Add local net header. If no space in first mbuf, * allocate another. */ - + M_PREPEND(m, ISO88025_HDR_LEN + rif_len, MB_DONTWAIT); - if (m == 0) - senderr(ENOBUFS); + if (m == NULL) + return (ENOBUFS); /* Copy as much of the generic header as is needed into the mbuf */ th = mtod(m, struct iso88025_header *); memcpy(th, &gen_th, ISO88025_HDR_LEN + rif_len); - /* - * If a simplex interface, and the packet is being sent to our - * Ethernet address or a broadcast address, loopback a copy. - * XXX To make a simplex device behave exactly like a duplex - * device, we should copy in the case of sending to our own - * ethernet address (thus letting the original actually appear - * on the wire). However, we don't do that here for security - * reasons and compatibility with the original behavior. - */ - if ((ifp->if_flags & IFF_SIMPLEX) && - (loop_copy != -1)) { - if ((m->m_flags & M_BCAST) || (loop_copy > 0)) { - struct mbuf *n = m_copy(m, 0, (int)M_COPYALL); - (void) if_simloop(ifp, - n, dst->sa_family, ISO88025_HDR_LEN); - } else if (bcmp(th->iso88025_dhost, - th->iso88025_shost, ETHER_ADDR_LEN) == 0) { - (void) if_simloop(ifp, - m, dst->sa_family, ISO88025_HDR_LEN); - return(0); /* XXX */ - } - } - - s = splimp(); + /* + * If a simplex interface, and the packet is being sent to our + * Ethernet address or a broadcast address, loopback a copy. + * XXX To make a simplex device behave exactly like a duplex + * device, we should copy in the case of sending to our own + * ethernet address (thus letting the original actually appear + * on the wire). However, we don't do that here for security + * reasons and compatibility with the original behavior. + */ + if ((ifp->if_flags & IFF_SIMPLEX) && + (loop_copy != -1)) { + if ((m->m_flags & M_BCAST) || (loop_copy > 0)) { + struct mbuf *n = m_copypacket(m, MB_DONTWAIT); + + if_simloop(ifp, n, dst->sa_family, ISO88025_HDR_LEN); + } else if (bcmp(th->iso88025_dhost, + th->iso88025_shost, ETHER_ADDR_LEN) == 0) { + if_simloop(ifp, m, dst->sa_family, ISO88025_HDR_LEN); + return (0); /* XXX */ + } + } + + s = splimp(); /* * Queue message on interface, and start output if interface * not yet active. */ if (IF_QFULL(&ifp->if_snd)) { - printf("iso88025_output: packet dropped QFULL.\n"); + printf("iso88025_output: packet dropped QFULL.\n"); IF_DROP(&ifp->if_snd); splx(s); senderr(ENOBUFS); @@ -321,7 +298,7 @@ iso88025_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst, struct if (m->m_flags & M_MCAST) ifp->if_omcasts++; IF_ENQUEUE(&ifp->if_snd, m); - if ((ifp->if_flags & IFF_OACTIVE) == 0) + if (!(ifp->if_flags & IFF_OACTIVE)) (*ifp->if_start)(ifp); splx(s); ifp->if_obytes += len + ISO88025_HDR_LEN + 8; @@ -344,7 +321,7 @@ iso88025_input(struct ifnet *ifp, struct mbuf *m) int isr, hdr_len; u_short ether_type; - if ((ifp->if_flags & IFF_UP) == 0) { + if (!(ifp->if_flags & IFF_UP)) { m_freem(m); return; } @@ -383,8 +360,8 @@ iso88025_input(struct ifnet *ifp, struct mbuf *m) l->llc_dsap = l->llc_ssap; l->llc_ssap = c; if (m->m_flags & (M_BCAST | M_MCAST)) - bcopy((caddr_t)ac->ac_enaddr, - (caddr_t)th->iso88025_dhost, ISO88025_ADDR_LEN); + bcopy(ac->ac_enaddr, th->iso88025_dhost, + ISO88025_ADDR_LEN); sa.sa_family = AF_UNSPEC; sa.sa_len = sizeof(sa); th2 = (struct iso88025_sockaddr_data *)sa.sa_data; @@ -404,9 +381,9 @@ iso88025_input(struct ifnet *ifp, struct mbuf *m) return; } - m->m_pkthdr.len -= 8; - m->m_len -= 8; - m->m_data += 8; /* Length of LLC header in our case */ + m->m_pkthdr.len -= 8; + m->m_len -= 8; + m->m_data += 8; /* Length of LLC header in our case */ ifp->if_ibytes += m->m_pkthdr.len + sizeof(*th); if (th->iso88025_dhost[0] & 1) { @@ -415,7 +392,7 @@ iso88025_input(struct ifnet *ifp, struct mbuf *m) m->m_flags |= M_BCAST; else m->m_flags |= M_MCAST; - } + } if (m->m_flags & (M_BCAST|M_MCAST)) ifp->if_imcasts++; @@ -424,7 +401,7 @@ iso88025_input(struct ifnet *ifp, struct mbuf *m) switch (ether_type) { #ifdef INET case ETHERTYPE_IP: - th->iso88025_shost[0] &= ~(TR_RII); + th->iso88025_shost[0] &= ~(TR_RII); if (ipflow_fastforward(m)) return; isr = NETISR_IP; @@ -436,7 +413,7 @@ iso88025_input(struct ifnet *ifp, struct mbuf *m) return; } isr = NETISR_ARP; - break; + break; #endif default: m_freem(m); diff --git a/sys/net/if_loop.c b/sys/net/if_loop.c index e271427362..6c768c58bf 100644 --- a/sys/net/if_loop.c +++ b/sys/net/if_loop.c @@ -32,7 +32,7 @@ * * @(#)if_loop.c 8.1 (Berkeley) 6/10/93 * $FreeBSD: src/sys/net/if_loop.c,v 1.47.2.8 2003/06/01 01:46:11 silby Exp $ - * $DragonFly: src/sys/net/if_loop.c,v 1.11 2004/06/02 14:42:57 eirikn Exp $ + * $DragonFly: src/sys/net/if_loop.c,v 1.12 2004/12/21 02:54:14 hsu Exp $ */ /* @@ -108,31 +108,30 @@ struct ifnet loif[NLOOP]; /* ARGSUSED */ static void -loopattach(dummy) - void *dummy; +loopattach(void *dummy) { struct ifnet *ifp; - int i = 0; - - for (ifp = loif; i < NLOOP; ifp++) { - if_initname(ifp, "lo", i++); - ifp->if_mtu = LOMTU; - ifp->if_flags = IFF_LOOPBACK | IFF_MULTICAST; - ifp->if_ioctl = loioctl; - ifp->if_output = looutput; - ifp->if_type = IFT_LOOP; - ifp->if_snd.ifq_maxlen = ifqmaxlen; - if_attach(ifp); - bpfattach(ifp, DLT_NULL, sizeof(u_int)); + int i; + + for (i = 0, ifp = loif; i < NLOOP; i++, ifp++) { + if_initname(ifp, "lo", i); + ifp->if_mtu = LOMTU; + ifp->if_flags = IFF_LOOPBACK | IFF_MULTICAST; + ifp->if_ioctl = loioctl; + ifp->if_output = looutput; + ifp->if_type = IFT_LOOP; + ifp->if_snd.ifq_maxlen = ifqmaxlen; + if_attach(ifp); + bpfattach(ifp, DLT_NULL, sizeof(u_int)); } } int -looutput(ifp, m, dst, rt) - struct ifnet *ifp; - struct mbuf *m; - struct sockaddr *dst; - struct rtentry *rt; +looutput( + struct ifnet *ifp, + struct mbuf *m, + struct sockaddr *dst, + struct rtentry *rt) { struct mbuf *n; @@ -181,7 +180,7 @@ looutput(ifp, m, dst, rt) return (EAFNOSUPPORT); } #endif - return(if_simloop(ifp, m, dst->sa_family, 0)); + return (if_simloop(ifp, m, dst->sa_family, 0)); } /* @@ -194,13 +193,8 @@ looutput(ifp, m, dst, rt) * * This function expects the packet to include the media header of length hlen. */ - int -if_simloop(ifp, m, af, hlen) - struct ifnet *ifp; - struct mbuf *m; - int af; - int hlen; +if_simloop(struct ifnet *ifp, struct mbuf *m, int af, int hlen) { int isr; @@ -295,10 +289,7 @@ if_simloop(ifp, m, af, hlen) /* ARGSUSED */ static void -lortrequest(cmd, rt, info) - int cmd; - struct rtentry *rt; - struct rt_addrinfo *info; +lortrequest(int cmd, struct rtentry *rt, struct rt_addrinfo *info) { if (rt) { rt->rt_rmx.rmx_mtu = rt->rt_ifp->if_mtu; /* for ISO */ @@ -307,8 +298,7 @@ lortrequest(cmd, rt, info) * should be at least twice the MTU plus a little more for * overhead. */ - rt->rt_rmx.rmx_recvpipe = - rt->rt_rmx.rmx_sendpipe = 3 * LOMTU; + rt->rt_rmx.rmx_recvpipe = rt->rt_rmx.rmx_sendpipe = 3 * LOMTU; } } @@ -317,11 +307,7 @@ lortrequest(cmd, rt, info) */ /* ARGSUSED */ int -loioctl(ifp, cmd, data, cr) - struct ifnet *ifp; - u_long cmd; - caddr_t data; - struct ucred *cr; +loioctl(struct ifnet *ifp, u_long cmd, caddr_t data, struct ucred *cr) { struct ifaddr *ifa; struct ifreq *ifr = (struct ifreq *)data; diff --git a/sys/net/if_media.c b/sys/net/if_media.c index 5d25d87402..1364ea6479 100644 --- a/sys/net/if_media.c +++ b/sys/net/if_media.c @@ -1,6 +1,6 @@ /* $NetBSD: if_media.c,v 1.1 1997/03/17 02:55:15 thorpej Exp $ */ /* $FreeBSD: src/sys/net/if_media.c,v 1.9.2.4 2001/07/04 00:12:38 brooks Exp $ */ -/* $DragonFly: src/sys/net/if_media.c,v 1.6 2004/04/22 04:21:29 dillon Exp $ */ +/* $DragonFly: src/sys/net/if_media.c,v 1.7 2004/12/21 02:54:14 hsu Exp $ */ /* * Copyright (c) 1997 @@ -60,7 +60,7 @@ * Compile-time options: * IFMEDIA_DEBUG: * turn on implementation-level debug printfs. - * Useful for debugging newly-ported drivers. + * Useful for debugging newly-ported drivers. */ static struct ifmedia_entry *ifmedia_match (struct ifmedia *ifm, @@ -201,7 +201,7 @@ ifmedia_ioctl(ifp, ifr, ifm, cmd) int error = 0, sticky; if (ifp == NULL || ifr == NULL || ifm == NULL) - return(EINVAL); + return (EINVAL); switch (cmd) { diff --git a/sys/net/if_types.h b/sys/net/if_types.h index 2b9dc04a95..3256d47e29 100644 --- a/sys/net/if_types.h +++ b/sys/net/if_types.h @@ -32,7 +32,7 @@ * * @(#)if_types.h 8.3 (Berkeley) 4/28/95 * $FreeBSD: src/sys/net/if_types.h,v 1.8.2.4 2002/12/23 23:02:21 kbyanc Exp $ - * $DragonFly: src/sys/net/if_types.h,v 1.3 2004/09/19 22:32:47 joerg Exp $ + * $DragonFly: src/sys/net/if_types.h,v 1.4 2004/12/21 02:54:14 hsu Exp $ * $NetBSD: if_types.h,v 1.16 2000/04/19 06:30:53 itojun Exp $ */ @@ -44,7 +44,7 @@ * This list is derived from the SNMP list of ifTypes, originally * documented in RFC1573, now maintained as: * - * ftp.isi.edu/in-notes/iana/assignments/smi-numbers + * ftp.isi.edu/in-notes/iana/assignments/smi-numbers */ #define IFT_OTHER 0x1 /* none of the following */ diff --git a/sys/net/if_var.h b/sys/net/if_var.h index c5bf53885c..4e09ec6a48 100644 --- a/sys/net/if_var.h +++ b/sys/net/if_var.h @@ -32,7 +32,7 @@ * * From: @(#)if.h 8.1 (Berkeley) 6/10/93 * $FreeBSD: src/sys/net/if_var.h,v 1.18.2.16 2003/04/15 18:11:19 fjoe Exp $ - * $DragonFly: src/sys/net/if_var.h,v 1.18 2004/09/15 19:33:36 joerg Exp $ + * $DragonFly: src/sys/net/if_var.h,v 1.19 2004/12/21 02:54:14 hsu Exp $ */ #ifndef _NET_IF_VAR_H_ @@ -138,7 +138,7 @@ struct ifqueue { */ struct ifnet { void *if_softc; /* pointer to driver state */ - TAILQ_ENTRY(ifnet) if_link; /* all struct ifnets are chained */ + TAILQ_ENTRY(ifnet) if_link; /* all struct ifnets are chained */ char if_xname[IFNAMSIZ]; /* external name (name + unit) */ const char *if_dname; /* driver name */ int if_dunit; /* unit or IF_DUNIT_NONE */ @@ -444,7 +444,7 @@ struct ifprefix { */ struct ifmultiaddr { LIST_ENTRY(ifmultiaddr) ifma_link; /* queue macro glue */ - struct sockaddr *ifma_addr; /* address this membership is for */ + struct sockaddr *ifma_addr; /* address this membership is for */ struct sockaddr *ifma_lladdr; /* link-layer translation, if any */ struct ifnet *ifma_ifp; /* back-pointer to interface */ u_int ifma_refcount; /* reference count */ @@ -465,13 +465,25 @@ EVENTHANDLER_DECLARE(ifnet_detach_event, ifnet_detach_event_handler_t); typedef void (*if_clone_event_handler_t)(void *, struct if_clone *); EVENTHANDLER_DECLARE(if_clone_event, if_clone_event_handler_t); -#define IFAFREE(ifa) \ - do { \ - if ((ifa)->ifa_refcnt <= 0) \ - ifafree(ifa); \ - else \ - (ifa)->ifa_refcnt--; \ - } while (0) +static __inline void +IFAREF(struct ifaddr *ifa) +{ + ++ifa->ifa_refcnt; +} + +#include + +MALLOC_DECLARE(M_IFADDR); +MALLOC_DECLARE(M_IFMADDR); + +static __inline void +IFAFREE(struct ifaddr *ifa) +{ + if (ifa->ifa_refcnt <= 0) + free(ifa, M_IFADDR); + else + ifa->ifa_refcnt--; +} extern struct ifnethead ifnet; extern struct ifnet **ifindex2ifnet; diff --git a/sys/net/net_osdep.h b/sys/net/net_osdep.h index 4cc66c9ed9..b2f4ae515f 100644 --- a/sys/net/net_osdep.h +++ b/sys/net/net_osdep.h @@ -1,7 +1,7 @@ /* * $KAME: net_osdep.h,v 1.68 2001/12/21 08:14:58 itojun Exp $ * $FreeBSD: src/sys/net/net_osdep.h,v 1.1.2.3 2002/04/28 05:40:25 suz Exp $ - * $DragonFly: src/sys/net/net_osdep.h,v 1.5 2004/06/04 01:46:49 dillon Exp $ + * $DragonFly: src/sys/net/net_osdep.h,v 1.6 2004/12/21 02:54:14 hsu Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -295,9 +295,6 @@ extern const char *if_name (struct ifnet *); #define if_addrlist if_addrhead #define if_list if_link -/* sys/net/if.h */ -#define IFAREF(ifa) do { ++(ifa)->ifa_refcnt; } while (0) - #define WITH_CONVERT_AND_STRIP_IP_LEN #if 1 /* at this moment, all OSes do this */ diff --git a/sys/net/pf/pf.c b/sys/net/pf/pf.c index ac64541be7..f664adad94 100644 --- a/sys/net/pf/pf.c +++ b/sys/net/pf/pf.c @@ -1,7 +1,7 @@ /* $FreeBSD: src/sys/contrib/pf/net/pf.c,v 1.19 2004/09/11 11:18:25 mlaier Exp $ */ /* $OpenBSD: pf.c,v 1.433.2.2 2004/07/17 03:22:34 brad Exp $ */ /* add $OpenBSD: pf.c,v 1.448 2004/05/11 07:34:11 dhartmei Exp $ */ -/* $DragonFly: src/sys/net/pf/pf.c,v 1.2 2004/11/30 16:02:21 joerg Exp $ */ +/* $DragonFly: src/sys/net/pf/pf.c,v 1.3 2004/12/21 02:54:15 hsu Exp $ */ /* * Copyright (c) 2004 The DragonFly Project. All rights reserved. @@ -4854,7 +4854,7 @@ pf_routable(struct pf_addr *addr, sa_family_t af) dst->sin_family = af; dst->sin_len = sizeof(*dst); dst->sin_addr = addr->v4; - rtalloc_ign(&ro, (RTF_CLONING|RTF_PRCLONING)); + rtalloc_ign(&ro, (RTF_CLONING | RTF_PRCLONING)); if (ro.ro_rt != NULL) { ret = 1; diff --git a/sys/net/radix.c b/sys/net/radix.c index a294221e95..5a33bfd9a4 100644 --- a/sys/net/radix.c +++ b/sys/net/radix.c @@ -32,7 +32,7 @@ * * @(#)radix.c 8.4 (Berkeley) 11/2/94 * $FreeBSD: src/sys/net/radix.c,v 1.20.2.3 2002/04/28 05:40:25 suz Exp $ - * $DragonFly: src/sys/net/radix.c,v 1.7 2004/12/15 00:11:04 hsu Exp $ + * $DragonFly: src/sys/net/radix.c,v 1.8 2004/12/21 02:54:14 hsu Exp $ */ /* @@ -55,13 +55,13 @@ */ #define clen(c) (*(u_char *)(c)) -static int rn_walktree_from(struct radix_node_head *h, u_char *a, u_char *m, +static int rn_walktree_from(struct radix_node_head *h, char *a, char *m, walktree_f_t *f, void *w); static int rn_walktree(struct radix_node_head *, walktree_f_t *, void *); static struct radix_node *rn_insert(char *, struct radix_node_head *, boolean_t *, - struct radix_node [2]), + struct radix_node [2]), *rn_newpair(char *, int, struct radix_node[2]), *rn_search(const char *, struct radix_node *), *rn_search_m(const char *, struct radix_node *, const char *); @@ -70,7 +70,6 @@ static int max_keylen; static struct radix_mask *rn_mkfreelist; static struct radix_node_head *mask_rnhead; static char *addmask_key; -static char normal_chars[] = {0, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, -1}; static char *rn_zeros, *rn_ones; #define rn_masktop (mask_rnhead->rnh_treetop) @@ -178,17 +177,17 @@ rn_refines(char *m, char *n) lim -= longer; while (n < lim) { if (*n & ~(*m)) - return 0; + return FALSE; if (*n++ != *m++) masks_are_equal = FALSE; } while (n < lim2) if (*n++) - return 0; + return FALSE; if (masks_are_equal && (longer < 0)) for (lim2 = m - longer; m < lim2; ) if (*m++) - return 1; + return TRUE; return (!masks_are_equal); } @@ -362,11 +361,8 @@ rn_newpair(char *key, int indexbit, struct radix_node nodes[2]) } static struct radix_node * -rn_insert( - char *key, - struct radix_node_head *head, - boolean_t *dupentry, - struct radix_node nodes[2]) +rn_insert(char *key, struct radix_node_head *head, boolean_t *dupentry, + struct radix_node nodes[2]) { struct radix_node *top = head->rnh_treetop; int head_off = top->rn_offset, klen = clen(key); @@ -374,7 +370,7 @@ rn_insert( char *cp = key + head_off; int b; struct radix_node *tt; - /* + /* * Find first bit at which the key and t->rn_key differ */ { @@ -489,6 +485,10 @@ rn_addmask(char *netmask, boolean_t search, int skip) for (cp = netmask + skip; cp < cplim && clen(cp) == 0xff;) cp++; if (cp != cplim) { + static const char normal_chars[] = { + 0, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, -1 + }; + for (j = 0x80; (j & *cp) != 0; j >>= 1) b++; if (*cp != normal_chars[b] || cp != (cplim - 1)) @@ -593,7 +593,7 @@ rn_addroute(char *key, char *netmask, struct radix_node_head *head, (tt = treenodes)->rn_dupedkey = t; tt->rn_flags = t->rn_flags; tt->rn_parent = x = t->rn_parent; - t->rn_parent = tt; /* parent */ + t->rn_parent = tt; /* parent */ if (x->rn_left == t) x->rn_left = tt; else @@ -831,9 +831,11 @@ on1: mp = &m->rm_next; *mp = t->rn_mklist; } else { - /* If there are any key,mask pairs in a sibling - duped-key chain, some subset will appear sorted - in the same order attached to our mklist */ + /* + * If there are any (key, mask) pairs in a sibling + * duped-key chain, some subset will appear sorted + * in the same order attached to our mklist. + */ for (m = t->rn_mklist; m && x; x = x->rn_dupedkey) if (m == x->rn_mklist) { struct radix_mask *mm = m->rm_next; @@ -880,12 +882,12 @@ out: * exit. */ static int -rn_walktree_from(struct radix_node_head *h, u_char *xa, u_char *xm, +rn_walktree_from(struct radix_node_head *h, char *xa, char *xm, walktree_f_t *f, void *w) { struct radix_node *base, *next; struct radix_node *rn, *last = NULL /* shut up gcc */; - int stopping = 0; + boolean_t stopping = FALSE; int lastb, error; /* @@ -936,7 +938,7 @@ rn_walktree_from(struct radix_node_head *h, u_char *xa, u_char *xm, /* if went up beyond last, stop */ if (rn->rn_bit < lastb) { - stopping = 1; + stopping = TRUE; /* printf("up too far\n"); */ } } @@ -956,7 +958,7 @@ rn_walktree_from(struct radix_node_head *h, u_char *xa, u_char *xm, if (rn->rn_flags & RNF_ROOT) { /* printf("root, stopping"); */ - stopping = 1; + stopping = TRUE; } } @@ -1005,7 +1007,7 @@ int rn_inithead(void **head, int off) { struct radix_node_head *rnh; - struct radix_node *t, *left, *right; + struct radix_node *root, *left, *right; if (*head) return (1); @@ -1015,25 +1017,26 @@ rn_inithead(void **head, int off) bzero(rnh, sizeof (*rnh)); *head = rnh; - t = rn_newpair(rn_zeros, off, rnh->rnh_nodes); + root = rn_newpair(rn_zeros, off, rnh->rnh_nodes); right = rnh->rnh_nodes + 2; - t->rn_right = right; - t->rn_parent = t; + root->rn_parent = root; + root->rn_flags = RNF_ROOT | RNF_ACTIVE; + root->rn_right = right; - left = t->rn_left; - left->rn_flags = t->rn_flags = RNF_ROOT | RNF_ACTIVE; + left = root->rn_left; left->rn_bit = -1 - off; + left->rn_flags = RNF_ROOT | RNF_ACTIVE; *right = *left; right->rn_key = rn_ones; + rnh->rnh_treetop = root; rnh->rnh_addaddr = rn_addroute; rnh->rnh_deladdr = rn_delete; rnh->rnh_matchaddr = rn_match; rnh->rnh_lookup = rn_lookup; rnh->rnh_walktree = rn_walktree; rnh->rnh_walktree_from = rn_walktree_from; - rnh->rnh_treetop = t; return (1); } diff --git a/sys/net/radix.h b/sys/net/radix.h index e71bf0871f..cec0302396 100644 --- a/sys/net/radix.h +++ b/sys/net/radix.h @@ -32,7 +32,7 @@ * * @(#)radix.h 8.2 (Berkeley) 10/31/94 * $FreeBSD: src/sys/net/radix.h,v 1.16.2.1 2000/05/03 19:17:11 wollman Exp $ - * $DragonFly: src/sys/net/radix.h,v 1.7 2004/12/15 07:32:26 hsu Exp $ + * $DragonFly: src/sys/net/radix.h,v 1.8 2004/12/21 02:54:14 hsu Exp $ */ #ifndef _RADIX_H_ @@ -128,7 +128,7 @@ struct radix_node_head { /* traverse tree below a */ int (*rnh_walktree_from) - (struct radix_node_head *head, u_char *a, u_char *m, + (struct radix_node_head *head, char *a, char *m, walktree_f_t *f, void *w); /* do something when the last ref drops */ @@ -159,15 +159,15 @@ struct radix_node_head { #define Free(p) free(p, M_RTABLE); #endif -void rn_init (void); -int rn_inithead (void **, int); +void rn_init (void); +int rn_inithead (void **, int); boolean_t rn_refines (char *, char *); struct radix_node *rn_addmask (char *, boolean_t, int), - *rn_addroute (char *, char *, struct radix_node_head *, - struct radix_node [2]), - *rn_delete (char *, char *, struct radix_node_head *), - *rn_lookup (char *key, char *mask, - struct radix_node_head *head), - *rn_match (char *, struct radix_node_head *); + *rn_addroute (char *, char *, struct radix_node_head *, + struct radix_node [2]), + *rn_delete (char *, char *, struct radix_node_head *), + *rn_lookup (char *key, char *mask, + struct radix_node_head *head), + *rn_match (char *, struct radix_node_head *); #endif /* _RADIX_H_ */ diff --git a/sys/net/raw_cb.c b/sys/net/raw_cb.c index e2871aa4fc..4f49208aba 100644 --- a/sys/net/raw_cb.c +++ b/sys/net/raw_cb.c @@ -32,7 +32,7 @@ * * @(#)raw_cb.c 8.1 (Berkeley) 6/10/93 * $FreeBSD: src/sys/net/raw_cb.c,v 1.16 1999/08/28 00:48:27 peter Exp $ - * $DragonFly: src/sys/net/raw_cb.c,v 1.8 2004/06/04 04:30:55 dillon Exp $ + * $DragonFly: src/sys/net/raw_cb.c,v 1.9 2004/12/21 02:54:14 hsu Exp $ */ #include @@ -97,7 +97,7 @@ raw_detach(struct rawcb *rp) so->so_pcb = 0; sofree(so); LIST_REMOVE(rp, list); - free((caddr_t)(rp), M_PCB); + free(rp, M_PCB); } /* diff --git a/sys/net/raw_usrreq.c b/sys/net/raw_usrreq.c index 8f1918b932..dd3717f7a2 100644 --- a/sys/net/raw_usrreq.c +++ b/sys/net/raw_usrreq.c @@ -32,7 +32,7 @@ * * @(#)raw_usrreq.c 8.1 (Berkeley) 6/10/93 * $FreeBSD: src/sys/net/raw_usrreq.c,v 1.18 1999/08/28 00:48:28 peter Exp $ - * $DragonFly: src/sys/net/raw_usrreq.c,v 1.7 2004/06/06 19:16:07 dillon Exp $ + * $DragonFly: src/sys/net/raw_usrreq.c,v 1.8 2004/12/21 02:54:14 hsu Exp $ */ #include @@ -97,10 +97,11 @@ raw_input(m0, proto, src, dst) continue; if (last) { struct mbuf *n; - n = m_copy(m, 0, (int)M_COPYALL); + + n = m_copypacket(m, MB_DONTWAIT); if (n) { - if (sbappendaddr(&last->so_rcv, src, - n, (struct mbuf *)0) == 0) + if (sbappendaddr(&last->so_rcv, src, n, + (struct mbuf *)0) == 0) /* should notify about lost packet */ m_freem(n); else { @@ -112,8 +113,7 @@ raw_input(m0, proto, src, dst) last = rp->rcb_socket; } if (last) { - if (sbappendaddr(&last->so_rcv, src, - m, (struct mbuf *)0) == 0) + if (sbappendaddr(&last->so_rcv, src, m, (struct mbuf *)0) == 0) m_freem(m); else { sorwakeup(last); diff --git a/sys/net/route.c b/sys/net/route.c index 12dfb9c372..6bf6803eae 100644 --- a/sys/net/route.c +++ b/sys/net/route.c @@ -32,7 +32,7 @@ * * @(#)route.c 8.3 (Berkeley) 1/9/95 * $FreeBSD: src/sys/net/route.c,v 1.59.2.10 2003/01/17 08:04:00 ru Exp $ - * $DragonFly: src/sys/net/route.c,v 1.9 2004/12/15 00:11:04 hsu Exp $ + * $DragonFly: src/sys/net/route.c,v 1.10 2004/12/21 02:54:14 hsu Exp $ */ #include "opt_inet.h" @@ -51,17 +51,12 @@ #include #include -#define SA(p) ((struct sockaddr *)(p)) - -struct route_cb route_cb; static struct rtstat rtstat; struct radix_node_head *rt_tables[AF_MAX+1]; -static int rttrash; /* routes not in table but not freed */ - -static void rt_maskedcopy (struct sockaddr *, struct sockaddr *, - struct sockaddr *); -static void rtable_init (void **); +static void rt_maskedcopy (struct sockaddr *, struct sockaddr *, + struct sockaddr *); +static void rtable_init (void **); static void rtable_init(void **table) @@ -84,6 +79,11 @@ route_init() /* * Packet routing routines. */ + +/* + * Lookup and fill in the ro_rt rtentry field in a route structure given + * an address in the ro_dst field. + */ void rtalloc(struct route *ro) { @@ -93,190 +93,116 @@ rtalloc(struct route *ro) void rtalloc_ign(struct route *ro, u_long ignore) { - struct rtentry *rt; int s; - if ((rt = ro->ro_rt) != NULL) { - if (rt->rt_ifp != NULL && rt->rt_flags & RTF_UP) + if (ro->ro_rt != NULL) { + if (ro->ro_rt->rt_ifp != NULL && ro->ro_rt->rt_flags & RTF_UP) return; - /* XXX - We are probably always at splnet here already. */ - s = splnet(); - RTFREE(rt); + s = splnet(); /* XXX probably always at splnet here already */ + rtfree(ro->ro_rt); ro->ro_rt = NULL; splx(s); } - ro->ro_rt = rtalloc1(&ro->ro_dst, 1, ignore); + ro->ro_rt = rtlookup(&ro->ro_dst, 1, ignore); } /* - * Look up the route that matches the address given - * Or, at least try.. Create a cloned route if needed. + * Look up the route that matches the given 'dst' address. + * + * Create a cloned route if the route is a cloning route + * and RTF_CLONING or RTF_PRCLONING are not being ignored. + * + * In either case, the returned route has its refcnt incremented. */ struct rtentry * -rtalloc1(struct sockaddr *dst, int report, u_long ignflags) +rtlookup(struct sockaddr *dst, int report, u_long ignflags) { struct radix_node_head *rnh = rt_tables[dst->sa_family]; struct rtentry *rt; struct radix_node *rn; - struct rtentry *newrt = NULL; struct rt_addrinfo info; u_long nflags; - int s = splnet(), err = 0, msgtype = RTM_MISS; + int s, err, msgtype; - /* - * Look up the address in the table for that Address Family - */ - if (rnh != NULL && (rn = rnh->rnh_matchaddr((char *)dst, rnh)) && - !(rn->rn_flags & RNF_ROOT)) { - /* - * If we find it and it's not the root node, then - * get a refernce on the rtentry associated. - */ - newrt = rt = (struct rtentry *)rn; + s = splnet(); + if (rnh != NULL && (rn = rnh->rnh_matchaddr((char *)dst, rnh))) { + rt = (struct rtentry *)rn; nflags = rt->rt_flags & ~ignflags; if (report && (nflags & (RTF_CLONING | RTF_PRCLONING))) { - /* - * We are apparently adding (report = 0 in delete). - * If it requires that it be cloned, do so. - * (This implies it wasn't a HOST route.) - */ - err = rtrequest(RTM_RESOLVE, dst, SA(0), - SA(0), 0, &newrt); - if (err) { - /* - * If the cloning didn't succeed, maybe - * what we have will do. Return that. - */ - newrt = rt; + struct rtentry *clonedroute; + + clonedroute = rt; /* value used in rtrequest()! */ + err = rtrequest(RTM_RESOLVE, dst, NULL, NULL, 0, + &clonedroute); + if (err != 0) { + /* use original route on clone failure */ rt->rt_refcnt++; - goto miss; + goto reportmiss; + } else { + rt = clonedroute; /* use cloned route */ } - if ((rt = newrt) && (rt->rt_flags & RTF_XRESOLVE)) { + if (clonedroute->rt_flags & RTF_XRESOLVE) { /* - * If the new route specifies it be - * externally resolved, then go do that. + * The new cloned route needs external + * resolution. */ msgtype = RTM_RESOLVE; - goto miss; + goto reportmsg; } /* Inform listeners of the new route. */ bzero(&info, sizeof(info)); - info.rti_info[RTAX_DST] = rt_key(rt); - info.rti_info[RTAX_NETMASK] = rt_mask(rt); - info.rti_info[RTAX_GATEWAY] = rt->rt_gateway; - if (rt->rt_ifp != NULL) { + info.rti_info[RTAX_DST] = rt_key(clonedroute); + info.rti_info[RTAX_NETMASK] = rt_mask(clonedroute); + info.rti_info[RTAX_GATEWAY] = clonedroute->rt_gateway; + if (clonedroute->rt_ifp != NULL) { info.rti_info[RTAX_IFP] = - TAILQ_FIRST(&rt->rt_ifp->if_addrhead)-> - ifa_addr; - info.rti_info[RTAX_IFA] = rt->rt_ifa->ifa_addr; + TAILQ_FIRST(&clonedroute->rt_ifp + ->if_addrhead)->ifa_addr; + info.rti_info[RTAX_IFA] = + clonedroute->rt_ifa->ifa_addr; } - rt_missmsg(RTM_ADD, &info, rt->rt_flags, 0); + rt_missmsg(RTM_ADD, &info, clonedroute->rt_flags, 0); } else - rt->rt_refcnt++; + rt->rt_refcnt++; /* most common case */ } else { - /* - * Either we hit the root or couldn't find any match, - * Which basically means - * "caint get there frm here" - */ + rt = NULL; rtstat.rts_unreach++; -miss: if (report) { - /* - * If required, report the failure to the supervising - * Authorities. - * For a delete, this is not an error. (report == 0) - */ + err = 0; +reportmiss: + msgtype = RTM_MISS; +reportmsg: bzero(&info, sizeof(info)); info.rti_info[RTAX_DST] = dst; rt_missmsg(msgtype, &info, 0, err); } } splx(s); - return (newrt); + return (rt); } -/* - * Remove a reference count from an rtentry. - * If the count gets low enough, take it out of the routing table - */ void rtfree(struct rtentry *rt) { - /* - * find the tree for that address family - */ struct radix_node_head *rnh = rt_tables[rt_key(rt)->sa_family]; - struct ifaddr *ifa; - - if (rt == NULL || rnh == NULL) - panic("rtfree"); - /* - * decrement the reference count by one and if it reaches 0, - * and there is a close function defined, call the close function - */ - rt->rt_refcnt--; - if(rnh->rnh_close && rt->rt_refcnt == 0) { + --rt->rt_refcnt; + if (rnh->rnh_close && rt->rt_refcnt == 0) rnh->rnh_close((struct radix_node *)rt, rnh); - } - - /* - * If we are no longer "up" (and ref == 0) - * then we can free the resources associated - * with the route. - */ if (rt->rt_refcnt <= 0 && !(rt->rt_flags & RTF_UP)) { - if (rt->rt_nodes->rn_flags & (RNF_ACTIVE | RNF_ROOT)) - panic ("rtfree 2"); - /* - * the rtentry must have been removed from the routing table - * so it is represented in rttrash.. remove that now. - */ - rttrash--; - -#ifdef DIAGNOSTIC - if (rt->rt_refcnt < 0) { - printf("rtfree: %p not freed (neg refs)\n", rt); - return; - } -#endif - - /* - * release references on items we hold them on.. - * e.g other routes and ifaddrs. - */ - if((ifa = rt->rt_ifa)) - IFAFREE(ifa); - if (rt->rt_parent) { + KASSERT(!(rt->rt_nodes->rn_flags & (RNF_ACTIVE | RNF_ROOT)), + ("rtfree: rn_flags 0x%x ", rt->rt_nodes->rn_flags)); + KASSERT(rt->rt_refcnt == 0, + ("rtfree: rt_refcnt %ld", rt->rt_refcnt)); + if (rt->rt_ifa != NULL) + IFAFREE(rt->rt_ifa); + if (rt->rt_parent != NULL) RTFREE(rt->rt_parent); - } - - /* - * The key is separatly alloc'd so free it (see rt_setgate()). - * This also frees the gateway, as they are always malloc'd - * together. - */ - Free(rt_key(rt)); - - /* - * and the rtentry itself of course - */ + Free(rt_key(rt)); /* Also frees gateway. See rt_setgate(). */ Free(rt); } } -void -ifafree(struct ifaddr *ifa) -{ - if (ifa == NULL) - panic("ifafree"); - if (ifa->ifa_refcnt == 0) - free(ifa, M_IFADDR); - else - ifa->ifa_refcnt--; -} - #define sa_equal(a1, a2) (bcmp((a1), (a2), (a1)->sa_len) == 0) /* @@ -298,41 +224,44 @@ rtredirect( struct rtentry **rtp) { struct rtentry *rt; - int error = 0; - short *stat = NULL; struct rt_addrinfo info; struct ifaddr *ifa; + short *stat = NULL; + int error; /* verify the gateway is directly reachable */ if ((ifa = ifa_ifwithnet(gateway)) == NULL) { error = ENETUNREACH; goto out; } - rt = rtalloc1(dst, 0, 0UL); + /* * If the redirect isn't from our current router for this dst, * it's either old or wrong. If it redirects us to ourselves, * we have a routing loop, perhaps as a result of an interface * going down recently. */ - if (!(flags & RTF_DONE) && rt && - (!sa_equal(src, rt->rt_gateway) || rt->rt_ifa != ifa)) + if (!(flags & RTF_DONE) && + (rt = rtlookup(dst, 0, 0UL)) != NULL && + (!sa_equal(src, rt->rt_gateway) || rt->rt_ifa != ifa)) { error = EINVAL; - else if (ifa_ifwithaddr(gateway)) + goto done; + } else if (ifa_ifwithaddr(gateway)) { error = EHOSTUNREACH; - if (error) goto done; + } + /* * Create a new entry if we just got back a wildcard entry * or the the lookup failed. This is necessary for hosts * which use routing redirects generated by smart gateways * to dynamically build the routing tables. */ - if ((rt == NULL) || (rt_mask(rt) != NULL && rt_mask(rt)->sa_len < 2)) + if (rt == NULL || (rt_mask(rt) != NULL && rt_mask(rt)->sa_len < 2)) goto create; + /* - * Don't listen to the redirect if it's - * for a route to an interface. + * Don't listen to the redirect if it's for a route to an interface. */ if (rt->rt_flags & RTF_GATEWAY) { if ((!(rt->rt_flags & RTF_HOST)) && (flags & RTF_HOST)) { @@ -340,8 +269,8 @@ rtredirect( * Changing from route to net => route to host. * Create new route, rather than smashing route to net. */ - create: - if (rt) +create: + if (rt != NULL) rtfree(rt); flags |= RTF_GATEWAY | RTF_DYNAMIC; bzero(&info, sizeof(info)); @@ -363,25 +292,28 @@ rtredirect( rt->rt_flags |= RTF_MODIFIED; flags |= RTF_MODIFIED; stat = &rtstat.rts_newgateway; - /* - * add the key and gateway (in one malloc'd chunk). - */ + /* Add the key and gateway (in one malloc'ed chunk). */ rt_setgate(rt, rt_key(rt), gateway); + error = 0; } - } else + } else { error = EHOSTUNREACH; + } + done: - if (rt) { - if (rtp != NULL && !error) + if (rt != NULL) { + if (rtp != NULL && error == 0) *rtp = rt; else rtfree(rt); } + out: - if (error) + if (error != 0) rtstat.rts_badredirect++; else if (stat != NULL) (*stat)++; + bzero(&info, sizeof(info)); info.rti_info[RTAX_DST] = dst; info.rti_info[RTAX_GATEWAY] = gateway; @@ -412,7 +344,7 @@ ifa_ifwithroute(int flags, struct sockaddr *dst, struct sockaddr *gateway) if (!(flags & RTF_GATEWAY)) { /* * If we are adding a route to an interface, - * and the interface is a pt to pt link + * and the interface is a point-to-point link, * we should search for the destination * as our clue to the interface. Otherwise * we can use the local address. @@ -434,7 +366,8 @@ ifa_ifwithroute(int flags, struct sockaddr *dst, struct sockaddr *gateway) if (ifa == NULL) ifa = ifa_ifwithnet(gateway); if (ifa == NULL) { - struct rtentry *rt = rtalloc1(gateway, 0, 0UL); + struct rtentry *rt = rtlookup(gateway, 0, 0UL); + if (rt == NULL) return (NULL); rt->rt_refcnt--; @@ -443,6 +376,7 @@ ifa_ifwithroute(int flags, struct sockaddr *dst, struct sockaddr *gateway) } if (ifa->ifa_addr->sa_family != dst->sa_family) { struct ifaddr *oifa = ifa; + ifa = ifaof_ifpforaddr(dst, ifa->ifa_ifp); if (ifa == NULL) ifa = oifa; @@ -458,29 +392,6 @@ struct rtfc_arg { struct radix_node_head *rnh; }; -/* - * Do appropriate manipulations of a routing tree given - * all the bits of info needed - */ -int -rtrequest( - int req, - struct sockaddr *dst, - struct sockaddr *gateway, - struct sockaddr *netmask, - int flags, - struct rtentry **ret_nrt) -{ - struct rt_addrinfo info; - - bzero(&info, sizeof(info)); - info.rti_flags = flags; - info.rti_info[RTAX_DST] = dst; - info.rti_info[RTAX_GATEWAY] = gateway; - info.rti_info[RTAX_NETMASK] = netmask; - return rtrequest1(req, &info, ret_nrt); -} - int rt_getifa(struct rt_addrinfo *info) { @@ -522,6 +433,29 @@ rt_getifa(struct rt_addrinfo *info) return (error); } +/* + * Do appropriate manipulations of a routing tree given + * all the bits of info needed + */ +int +rtrequest( + int req, + struct sockaddr *dst, + struct sockaddr *gateway, + struct sockaddr *netmask, + int flags, + struct rtentry **ret_nrt) +{ + struct rt_addrinfo info; + + bzero(&info, sizeof info); + info.rti_flags = flags; + info.rti_info[RTAX_DST] = dst; + info.rti_info[RTAX_GATEWAY] = gateway; + info.rti_info[RTAX_NETMASK] = netmask; + return rtrequest1(req, &info, ret_nrt); +} + int rtrequest1(int req, struct rt_addrinfo *info, struct rtentry **ret_nrt) { @@ -531,16 +465,18 @@ rtrequest1(int req, struct rt_addrinfo *info, struct rtentry **ret_nrt) struct radix_node_head *rnh; struct ifaddr *ifa; struct sockaddr *ndst; - int s = splnet(); int error = 0; + int s; #define gotoerr(x) { error = x ; goto bad; } + s = splnet(); /* * Find the correct routing tree to use for this Address Family */ if ((rnh = rt_tables[dst->sa_family]) == NULL) gotoerr(EAFNOSUPPORT); + /* * If we are adding a host route then we don't want to put * a netmask in the tree, nor do we want to clone it. @@ -549,71 +485,52 @@ rtrequest1(int req, struct rt_addrinfo *info, struct rtentry **ret_nrt) info->rti_info[RTAX_NETMASK] = NULL; info->rti_flags &= ~(RTF_CLONING | RTF_PRCLONING); } + switch (req) { case RTM_DELETE: - /* - * Remove the item from the tree and return it. - * Complain if it is not there and do no more processing. - */ - if ((rn = rnh->rnh_deladdr((char *)dst, - (char *)info->rti_info[RTAX_NETMASK], rnh)) == NULL) + /* Remove the item from the tree. */ + rn = rnh->rnh_deladdr((char *)info->rti_info[RTAX_DST], + (char *)info->rti_info[RTAX_NETMASK], + rnh); + if (rn == NULL) gotoerr(ESRCH); - if (rn->rn_flags & (RNF_ACTIVE | RNF_ROOT)) - panic ("rtrequest delete"); + KASSERT(!(rn->rn_flags & (RNF_ACTIVE | RNF_ROOT)), + ("rnh_deladdr returned flags 0x%x", rn->rn_flags)); rt = (struct rtentry *)rn; - /* - * Now search what's left of the subtree for any cloned - * routes which might have been formed from this node. - */ + /* Free any routes cloned from this one. */ if ((rt->rt_flags & (RTF_CLONING | RTF_PRCLONING)) && rt_mask(rt) != NULL) { - rnh->rnh_walktree_from(rnh, (char *)dst, + rnh->rnh_walktree_from(rnh, (char *)rt_key(rt), (char *)rt_mask(rt), rt_fixdelete, rt); } - /* - * Remove any external references we may have. - * This might result in another rtentry being freed if - * we held its last reference. - */ - if (rt->rt_gwroute) { - rt = rt->rt_gwroute; - RTFREE(rt); - (rt = (struct rtentry *)rn)->rt_gwroute = NULL; + if (rt->rt_gwroute != NULL) { + RTFREE(rt->rt_gwroute); + rt->rt_gwroute = NULL; } /* * NB: RTF_UP must be set during the search above, * because we might delete the last ref, causing * rt to get freed prematurely. - * eh? then why not just add a reference? - * I'm not sure how RTF_UP helps matters. (JRE) */ rt->rt_flags &= ~RTF_UP; - /* - * give the protocol a chance to keep things in sync. - */ + /* Give the protocol a chance to keep things in sync. */ if ((ifa = rt->rt_ifa) && ifa->ifa_rtrequest) ifa->ifa_rtrequest(RTM_DELETE, rt, info); - /* - * one more rtentry floating around that is not - * linked to the routing table. - */ - rttrash++; - /* * If the caller wants it, then it can have it, * but it's up to it to free the rtentry as we won't be * doing it. */ - if (ret_nrt != NULL) + if (ret_nrt != NULL) { *ret_nrt = rt; - else if (rt->rt_refcnt <= 0) { - rt->rt_refcnt++; /* make a 1->0 transition */ + } else if (rt->rt_refcnt <= 0) { + rt->rt_refcnt++; /* refcnt > 0 required for rtfree() */ rtfree(rt); } break; @@ -631,41 +548,29 @@ rtrequest1(int req, struct rt_addrinfo *info, struct rtentry **ret_nrt) goto makeroute; case RTM_ADD: - if ((info->rti_flags & RTF_GATEWAY) && - !info->rti_info[RTAX_GATEWAY]) - panic("rtrequest: GATEWAY but no gateway"); + KASSERT(!(info->rti_flags & RTF_GATEWAY) || + info->rti_info[RTAX_GATEWAY] != NULL, + ("rtrequest: GATEWAY but no gateway")); if (info->rti_ifa == NULL && (error = rt_getifa(info))) gotoerr(error); ifa = info->rti_ifa; - makeroute: - R_Malloc(rt, struct rtentry *, sizeof(*rt)); + R_Malloc(rt, struct rtentry *, sizeof *rt); if (rt == NULL) gotoerr(ENOBUFS); - bzero(rt, sizeof(*rt)); + bzero(rt, sizeof *rt); rt->rt_flags = RTF_UP | info->rti_flags; - /* - * Add the gateway. Possibly re-malloc-ing the storage for it - * also add the rt_gwroute if possible. - */ - if ((error = rt_setgate(rt, dst, info->rti_info[RTAX_GATEWAY])) - != 0) { + error = rt_setgate(rt, dst, info->rti_info[RTAX_GATEWAY]); + if (error != 0) { Free(rt); gotoerr(error); } - /* - * point to the (possibly newly malloc'd) dest address. - */ ndst = rt_key(rt); - - /* - * make sure it contains the value we want (masked if needed). - */ - if (info->rti_info[RTAX_NETMASK] != NULL) { + if (info->rti_info[RTAX_NETMASK] != NULL) rt_maskedcopy(dst, ndst, info->rti_info[RTAX_NETMASK]); - } else + else bcopy(dst, ndst, dst->sa_len); /* @@ -673,7 +578,7 @@ makeroute: * This moved from below so that rnh->rnh_addaddr() can * examine the ifa and ifa->ifa_ifp if it so desires. */ - ifa->ifa_refcnt++; + IFAREF(ifa); rt->rt_ifa = ifa; rt->rt_ifp = ifa->ifa_ifp; /* XXX mtu manipulation will be done in rnh_addaddr -- itojun */ @@ -682,57 +587,53 @@ makeroute: (char *)info->rti_info[RTAX_NETMASK], rnh, rt->rt_nodes); if (rn == NULL) { - struct rtentry *rt2; + struct rtentry *oldrt; + /* - * Uh-oh, we already have one of these in the tree. - * We do a special hack: if the route that's already - * there was generated by the protocol-cloning - * mechanism, then we just blow it away and retry - * the insertion of the new one. + * We already have one of these in the tree. + * We do a special hack: if the old route was + * cloned, then we blow it away and try + * re-inserting the new one. */ - rt2 = rtalloc1(dst, 0, RTF_PRCLONING); - if (rt2 != NULL && rt2->rt_parent) { - rtrequest(RTM_DELETE, - (struct sockaddr *)rt_key(rt2), - rt2->rt_gateway, - rt_mask(rt2), rt2->rt_flags, 0); - RTFREE(rt2); - rn = rnh->rnh_addaddr((char *)ndst, - (char *)info->rti_info[RTAX_NETMASK], - rnh, rt->rt_nodes); - } else if (rt2 != NULL) { - /* undo the extra ref we got */ - RTFREE(rt2); + oldrt = rtlookup(ndst, 0, RTF_CLONING | RTF_PRCLONING); + if (oldrt != NULL) { + --oldrt->rt_refcnt; + if (oldrt->rt_flags & RTF_WASCLONED) { + rtrequest(RTM_DELETE, rt_key(oldrt), + oldrt->rt_gateway, + rt_mask(oldrt), + oldrt->rt_flags, NULL); + rn = rnh->rnh_addaddr((char *)ndst, + (char *) + info->rti_info[RTAX_NETMASK], + rnh, rt->rt_nodes); + } } } /* * If it still failed to go into the tree, - * then un-make it (this should be a function) + * then un-make it (this should be a function). */ if (rn == NULL) { - if (rt->rt_gwroute) + if (rt->rt_gwroute != NULL) rtfree(rt->rt_gwroute); - if (rt->rt_ifa) { - IFAFREE(rt->rt_ifa); - } + IFAFREE(ifa); Free(rt_key(rt)); Free(rt); gotoerr(EEXIST); } - rt->rt_parent = 0; - /* * If we got here from RESOLVE, then we are cloning * so clone the rest, and note that we * are a clone (and increment the parent's references) */ if (req == RTM_RESOLVE) { - rt->rt_rmx = (*ret_nrt)->rt_rmx; /* copy metrics */ - rt->rt_rmx.rmx_pksent = 0; /* reset packet counter */ + rt->rt_rmx = (*ret_nrt)->rt_rmx; /* copy metrics */ + rt->rt_rmx.rmx_pksent = 0; /* reset packet counter */ if ((*ret_nrt)->rt_flags & - (RTF_CLONING | RTF_PRCLONING)) { + (RTF_CLONING | RTF_PRCLONING)) { rt->rt_parent = *ret_nrt; (*ret_nrt)->rt_refcnt++; } @@ -742,7 +643,7 @@ makeroute: * if this protocol has something to add to this then * allow it to do that as well. */ - if (ifa->ifa_rtrequest) + if (ifa->ifa_rtrequest != NULL) ifa->ifa_rtrequest(req, rt, info); /* @@ -752,21 +653,20 @@ makeroute: */ if (req == RTM_ADD && !(rt->rt_flags & RTF_HOST) && rt_mask(rt) != NULL) { - struct rtfc_arg arg; - arg.rnh = rnh; - arg.rt0 = rt; + struct rtfc_arg arg = { rt, rnh }; + rnh->rnh_walktree_from(rnh, (char *)rt_key(rt), (char *)rt_mask(rt), rt_fixchange, &arg); } /* - * actually return a resultant rtentry and - * give the caller a single reference. + * Return the resulting rtentry, + * increasing the number of references by one. */ if (ret_nrt != NULL) { - *ret_nrt = rt; rt->rt_refcnt++; + *ret_nrt = rt; } break; default: @@ -792,9 +692,8 @@ rt_fixdelete(struct radix_node *rn, void *vp) if (rt->rt_parent == rt0 && !(rt->rt_flags & (RTF_PINNED | RTF_CLONING | RTF_PRCLONING))) { - return rtrequest(RTM_DELETE, rt_key(rt), - (struct sockaddr *)0, rt_mask(rt), - rt->rt_flags, (struct rtentry **)0); + return rtrequest(RTM_DELETE, rt_key(rt), NULL, rt_mask(rt), + rt->rt_flags, NULL); } return 0; } @@ -831,29 +730,27 @@ rt_fixchange(struct radix_node *rn, void *vp) printf("rt_fixchange: rt %p, rt0 %p\n", rt, rt0); #endif - if (!rt->rt_parent || + if (rt->rt_parent == NULL || (rt->rt_flags & (RTF_PINNED | RTF_CLONING | RTF_PRCLONING))) { #ifdef DEBUG - if(rtfcdebug) printf("no parent, pinned or cloning\n"); + if (rtfcdebug) printf("no parent, pinned or cloning\n"); #endif return 0; } if (rt->rt_parent == rt0) { #ifdef DEBUG - if(rtfcdebug) printf("parent match\n"); + if (rtfcdebug) printf("parent match\n"); #endif - return rtrequest(RTM_DELETE, rt_key(rt), - (struct sockaddr *)0, rt_mask(rt), - rt->rt_flags, (struct rtentry **)0); + return rtrequest(RTM_DELETE, rt_key(rt), NULL, rt_mask(rt), + rt->rt_flags, NULL); } /* * There probably is a function somewhere which does this... * if not, there should be. */ - len = imin(((struct sockaddr *)rt_key(rt0))->sa_len, - ((struct sockaddr *)rt_key(rt))->sa_len); + len = imin(rt_key(rt0)->sa_len, rt_key(rt)->sa_len); xk1 = (u_char *)rt_key(rt0); xm1 = (u_char *)rt_mask(rt0); @@ -861,8 +758,8 @@ rt_fixchange(struct radix_node *rn, void *vp) /* avoid applying a less specific route */ xmp = (u_char *)rt_mask(rt->rt_parent); - mlen = ((struct sockaddr *)rt_key(rt->rt_parent))->sa_len; - if (mlen > ((struct sockaddr *)rt_key(rt0))->sa_len) { + mlen = rt_key(rt->rt_parent)->sa_len; + if (mlen > rt_key(rt0)->sa_len) { #ifdef DEBUG if (rtfcdebug) printf("rt_fixchange: inserting a less " @@ -884,7 +781,7 @@ rt_fixchange(struct radix_node *rn, void *vp) for (i = rnh->rnh_treetop->rn_offset; i < len; i++) { if ((xk2[i] & xm1[i]) != xk1[i]) { #ifdef DEBUG - if(rtfcdebug) printf("no match\n"); + if (rtfcdebug) printf("no match\n"); #endif return 0; } @@ -895,10 +792,10 @@ rt_fixchange(struct radix_node *rn, void *vp) * changed/added under the node's mask. So, get rid of it. */ #ifdef DEBUG - if(rtfcdebug) printf("deleting\n"); + if (rtfcdebug) printf("deleting\n"); #endif - return rtrequest(RTM_DELETE, rt_key(rt), (struct sockaddr *)0, - rt_mask(rt), rt->rt_flags, (struct rtentry **)0); + return rtrequest(RTM_DELETE, rt_key(rt), NULL, rt_mask(rt), + rt->rt_flags, NULL); } #define ROUNDUP(a) (a>0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long)) @@ -906,7 +803,7 @@ rt_fixchange(struct radix_node *rn, void *vp) int rt_setgate(struct rtentry *rt0, struct sockaddr *dst, struct sockaddr *gate) { - caddr_t newkey, oldkey; + char *space, *oldspace; int dlen = ROUNDUP(dst->sa_len), glen = ROUNDUP(gate->sa_len); struct rtentry *rt = rt0; struct radix_node_head *rnh = rt_tables[dst->sa_family]; @@ -916,78 +813,78 @@ rt_setgate(struct rtentry *rt0, struct sockaddr *dst, struct sockaddr *gate) * will interfere with keeping LLINFO in the routing * table, so disallow it. */ - if (((rt0->rt_flags & (RTF_HOST|RTF_GATEWAY|RTF_LLINFO)) == - (RTF_HOST|RTF_GATEWAY)) && - (dst->sa_len == gate->sa_len) && - (bcmp(dst, gate, dst->sa_len) == 0)) { + if (((rt0->rt_flags & (RTF_HOST | RTF_GATEWAY | RTF_LLINFO)) == + (RTF_HOST | RTF_GATEWAY)) && + dst->sa_len == gate->sa_len && + sa_equal(dst, gate)) { /* * The route might already exist if this is an RTM_CHANGE * or a routing redirect, so try to delete it. */ if (rt_key(rt0) != NULL) rtrequest(RTM_DELETE, rt_key(rt0), rt0->rt_gateway, - rt_mask(rt0), rt0->rt_flags, 0); + rt_mask(rt0), rt0->rt_flags, NULL); return EADDRNOTAVAIL; } /* - * Both dst and gateway are stored in the same malloc'd chunk + * Both dst and gateway are stored in the same malloc'ed chunk * (If I ever get my hands on....) * if we need to malloc a new chunk, then keep the old one around * till we don't need it any more. */ if (rt->rt_gateway == NULL || glen > ROUNDUP(rt->rt_gateway->sa_len)) { - oldkey = (caddr_t)rt_key(rt); - R_Malloc(newkey, caddr_t, dlen + glen); - if (newkey == NULL) + oldspace = (char *)rt_key(rt); + R_Malloc(space, char *, dlen + glen); + if (space == NULL) return ENOBUFS; - rt->rt_nodes->rn_key = newkey; + rt->rt_nodes->rn_key = space; } else { - /* - * otherwise just overwrite the old one - */ - newkey = rt->rt_nodes->rn_key; - oldkey = NULL; + space = (char *)rt_key(rt); /* Just use the old space. */ + oldspace = NULL; } - /* - * copy the new gateway value into the memory chunk - */ - rt->rt_gateway = (struct sockaddr *)(newkey + dlen); + /* Set the gateway value. */ + rt->rt_gateway = (struct sockaddr *)(space + dlen); bcopy(gate, rt->rt_gateway, glen); - /* - * if we are replacing the chunk (or it's new) we need to - * replace the dst as well - */ - if (oldkey != NULL) { - bcopy(dst, newkey, dlen); - Free(oldkey); + if (oldspace != NULL) { + /* + * If we allocated a new chunk, preserve the original dst. + * This way, rt_setgate() really just sets the gate + * and leaves the dst field alone. + */ + bcopy(dst, space, dlen); + Free(oldspace); } /* - * If there is already a gwroute, it's now almost definitly wrong + * If there is already a gwroute, it's now almost definitely wrong * so drop it. */ if (rt->rt_gwroute != NULL) { RTFREE(rt->rt_gwroute); rt->rt_gwroute = NULL; } - /* - * Cloning loop avoidance: - * In the presence of protocol-cloning and bad configuration, - * it is possible to get stuck in bottomless mutual recursion - * (rtrequest rt_setgate rtalloc1). We avoid this by not allowing - * protocol-cloning to operate for gateways (which is probably the - * correct choice anyway), and avoid the resulting reference loops - * by disallowing any route to run through itself as a gateway. - * This is obviously mandatory when we get rt->rt_output(). - */ if (rt->rt_flags & RTF_GATEWAY) { - rt->rt_gwroute = rtalloc1(gate, 1, RTF_PRCLONING); + /* + * Cloning loop avoidance: In the presence of + * protocol-cloning and bad configuration, it is + * possible to get stuck in bottomless mutual recursion + * (rtrequest rt_setgate rtlookup). We avoid this + * by not allowing protocol-cloning to operate for + * gateways (which is probably the correct choice + * anyway), and avoid the resulting reference loops + * by disallowing any route to run through itself as + * a gateway. This is obviously mandatory when we + * get rt->rt_output(). + * + * This breaks TTCP! XXX JH + */ + rt->rt_gwroute = rtlookup(gate, 1, RTF_PRCLONING); if (rt->rt_gwroute == rt) { - RTFREE(rt->rt_gwroute); - rt->rt_gwroute = 0; + rt->rt_gwroute = NULL; + --rt->rt_refcnt; return EDQUOT; /* failure */ } } @@ -998,10 +895,9 @@ rt_setgate(struct rtentry *rt0, struct sockaddr *dst, struct sockaddr *gate) * (we don't yet have one during adds). */ if (!(rt->rt_flags & RTF_HOST) && rt_mask(rt) != NULL) { - struct rtfc_arg arg; - arg.rnh = rnh; - arg.rt0 = rt; - rnh->rnh_walktree_from(rnh, (char*)rt_key(rt), + struct rtfc_arg arg = { rt, rnh }; + + rnh->rnh_walktree_from(rnh, (char *)rt_key(rt), (char *)rt_mask(rt), rt_fixchange, &arg); } @@ -1010,8 +906,10 @@ rt_setgate(struct rtentry *rt0, struct sockaddr *dst, struct sockaddr *gate) } static void -rt_maskedcopy(struct sockaddr *src, struct sockaddr *dst, - struct sockaddr *netmask) +rt_maskedcopy( + struct sockaddr *src, + struct sockaddr *dst, + struct sockaddr *netmask) { u_char *cp1 = (u_char *)src; u_char *cp2 = (u_char *)dst; @@ -1026,7 +924,41 @@ rt_maskedcopy(struct sockaddr *src, struct sockaddr *dst, while (cp2 < cplim) *cp2++ = *cp1++ & *cp3++; if (cp2 < cplim2) - bzero(cp2, (unsigned)(cplim2 - cp2)); + bzero(cp2, cplim2 - cp2); +} + +int +rt_llroute(struct sockaddr *dst, struct rtentry *rt0, struct rtentry **drt) +{ + struct rtentry *up_rt, *rt; + + if (!(rt0->rt_flags & RTF_UP)) { + up_rt = rtlookup(dst, 1, 0UL); + if (up_rt == NULL) + return (EHOSTUNREACH); + up_rt->rt_refcnt--; + } else + up_rt = rt0; + if (up_rt->rt_flags & RTF_GATEWAY) { + if (up_rt->rt_gwroute == NULL) { + up_rt->rt_gwroute = rtlookup(up_rt->rt_gateway, 1, 0UL); + if (up_rt->rt_gwroute == NULL) + return (EHOSTUNREACH); + } else if (!(up_rt->rt_gwroute->rt_flags & RTF_UP)) { + rtfree(up_rt->rt_gwroute); + up_rt->rt_gwroute = rtlookup(up_rt->rt_gateway, 1, 0UL); + if (up_rt->rt_gwroute == NULL) + return (EHOSTUNREACH); + } + rt = up_rt->rt_gwroute; + } else + rt = up_rt; + if (rt->rt_flags & RTF_REJECT && + (rt->rt_rmx.rmx_expire == 0 || /* rt doesn't expire */ + time_second < rt->rt_rmx.rmx_expire)) /* rt not expired */ + return (rt->rt_flags & RTF_HOST ? EHOSTDOWN : EHOSTUNREACH); + *drt = rt; + return 0; } /* @@ -1036,16 +968,14 @@ rt_maskedcopy(struct sockaddr *src, struct sockaddr *dst, int rtinit(struct ifaddr *ifa, int cmd, int flags) { + struct sockaddr *dst, *deldst, *netmask; struct rtentry *rt; - struct sockaddr *dst; - struct sockaddr *deldst; - struct sockaddr *netmask; - struct mbuf *m = NULL; struct rtentry *nrt = NULL; + struct mbuf *m = NULL; struct radix_node_head *rnh; struct radix_node *rn; - int error; struct rt_addrinfo info; + int error; if (flags & RTF_HOST) { dst = ifa->ifa_dstaddr; @@ -1068,7 +998,7 @@ rtinit(struct ifaddr *ifa, int cmd, int flags) if (netmask != NULL) { m = m_get(MB_DONTWAIT, MT_SONAME); if (m == NULL) - return(ENOBUFS); + return (ENOBUFS); deldst = mtod(m, struct sockaddr *); rt_maskedcopy(dst, deldst, netmask); dst = deldst; @@ -1078,13 +1008,12 @@ rtinit(struct ifaddr *ifa, int cmd, int flags) * contains the correct info. */ if ((rnh = rt_tables[dst->sa_family]) == NULL || - (rn = rnh->rnh_lookup((char *)dst, (char *)netmask, - rnh)) == NULL || - (rn->rn_flags & RNF_ROOT) || + (rn = rnh->rnh_lookup((char *)dst, + (char *)netmask, rnh)) == NULL || ((struct rtentry *)rn)->rt_ifa != ifa || - !sa_equal(SA(rn->rn_key), dst)) { + !sa_equal((struct sockaddr *)rn->rn_key, dst)) { if (m != NULL) - (void) m_free(m); + m_free(m); return (flags & RTF_HOST ? EHOSTUNREACH : ENETUNREACH); } /* XXX */ @@ -1132,7 +1061,7 @@ rtinit(struct ifaddr *ifa, int cmd, int flags) } } if (m != NULL) - (void) m_free(m); + m_free(m); return (error); } diff --git a/sys/net/route.h b/sys/net/route.h index f48fd0659a..1f6e9e91a1 100644 --- a/sys/net/route.h +++ b/sys/net/route.h @@ -32,7 +32,7 @@ * * @(#)route.h 8.4 (Berkeley) 1/9/95 * $FreeBSD: src/sys/net/route.h,v 1.36.2.5 2002/02/01 11:48:01 ru Exp $ - * $DragonFly: src/sys/net/route.h,v 1.6 2004/12/15 00:11:04 hsu Exp $ + * $DragonFly: src/sys/net/route.h,v 1.7 2004/12/21 02:54:14 hsu Exp $ */ #ifndef _NET_ROUTE_H_ @@ -99,6 +99,7 @@ struct mbuf; #ifndef RNF_NORMAL #include #endif + struct rtentry { struct radix_node rt_nodes[2]; /* tree glue, and other values */ #define rt_key(r) ((struct sockaddr *)((r)->rt_nodes->rn_key)) @@ -109,13 +110,13 @@ struct rtentry { struct ifnet *rt_ifp; /* the answer: interface to use */ struct ifaddr *rt_ifa; /* the answer: interface to use */ struct sockaddr *rt_genmask; /* for generation of cloned routes */ - caddr_t rt_llinfo; /* pointer to link level info cache */ + void *rt_llinfo; /* pointer to link level info cache */ struct rt_metrics rt_rmx; /* metrics used by rx'ing protocols */ struct rtentry *rt_gwroute; /* implied entry for gatewayed routes */ - int (*rt_output) (struct ifnet *, struct mbuf *, - struct sockaddr *, struct rtentry *); + int (*rt_output) (struct ifnet *, struct mbuf *, struct sockaddr *, + struct rtentry *); /* output routine for this (rt,if) */ - struct rtentry *rt_parent; /* cloning parent of this route */ + struct rtentry *rt_parent; /* cloning parent of this route */ void *rt_filler2; /* more filler */ }; @@ -156,7 +157,7 @@ struct ortentry { #define RTF_PROTO3 0x40000 /* protocol specific routing flag */ /* 0x80000 unused */ #define RTF_PINNED 0x100000 /* future use */ -#define RTF_LOCAL 0x200000 /* route represents a local address */ +#define RTF_LOCAL 0x200000 /* route represents a local address */ #define RTF_BROADCAST 0x400000 /* route represents a bcast address */ #define RTF_MULTICAST 0x800000 /* route represents a mcast address */ /* 0x1000000 and up unassigned */ @@ -266,24 +267,7 @@ struct rt_addrinfo { #define sa_author rti_info[RTAX_AUTHOR] #define sa_bcastaddr rti_info[RTAX_BRD] -struct route_cb { - int ip_count; - int ip6_count; - int ipx_count; - int ns_count; - int any_count; -}; - #ifdef _KERNEL -#define RTFREE(rt) \ - do { \ - if ((rt)->rt_refcnt <= 1) \ - rtfree(rt); \ - else \ - (rt)->rt_refcnt--; \ - } while (0) - -extern struct route_cb route_cb; extern struct radix_node_head *rt_tables[AF_MAX+1]; struct ifmultiaddr; @@ -293,6 +277,8 @@ void route_init (void); int rt_getifa (struct rt_addrinfo *); void rt_ifannouncemsg (struct ifnet *, int); void rt_ifmsg (struct ifnet *); +int rt_llroute (struct sockaddr *dst, struct rtentry *rt0, + struct rtentry **drt); void rt_missmsg (int, struct rt_addrinfo *, int, int); void rt_newaddrmsg (int, struct ifaddr *, int, struct rtentry *); void rt_newmaddrmsg (int, struct ifmultiaddr *); @@ -301,7 +287,7 @@ int rt_setgate (struct rtentry *, void rtalloc (struct route *); void rtalloc_ign (struct route *, u_long); struct rtentry * - rtalloc1 (struct sockaddr *, int, u_long); + rtlookup (struct sockaddr *, int, u_long); void rtfree (struct rtentry *); int rtinit (struct ifaddr *, int, int); int rtioctl (u_long, caddr_t, struct thread *); @@ -310,6 +296,15 @@ void rtredirect (struct sockaddr *, struct sockaddr *, int rtrequest (int, struct sockaddr *, struct sockaddr *, struct sockaddr *, int, struct rtentry **); int rtrequest1 (int, struct rt_addrinfo *, struct rtentry **); + +static __inline void +RTFREE(struct rtentry *rt) +{ + if (rt->rt_refcnt <= 1) + rtfree(rt); + else + --rt->rt_refcnt; +} #endif #endif diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c index 8f8140680f..a12ef88943 100644 --- a/sys/net/rtsock.c +++ b/sys/net/rtsock.c @@ -32,7 +32,7 @@ * * @(#)rtsock.c 8.7 (Berkeley) 10/12/95 * $FreeBSD: src/sys/net/rtsock.c,v 1.44.2.11 2002/12/04 14:05:41 ru Exp $ - * $DragonFly: src/sys/net/rtsock.c,v 1.16 2004/12/15 00:11:04 hsu Exp $ + * $DragonFly: src/sys/net/rtsock.c,v 1.17 2004/12/21 02:54:14 hsu Exp $ */ @@ -56,6 +56,14 @@ MALLOC_DEFINE(M_RTABLE, "routetbl", "routing tables"); +static struct route_cb { + int ip_count; + int ip6_count; + int ipx_count; + int ns_count; + int any_count; +} route_cb; + static struct sockaddr route_dst = { 2, PF_ROUTE, }; static struct sockaddr route_src = { 2, PF_ROUTE, }; static struct sockaddr sa_zero = { sizeof(sa_zero), AF_INET, }; @@ -76,7 +84,7 @@ static int sysctl_dumpentry (struct radix_node *rn, void *vw); static int sysctl_iflist (int af, struct walkarg *w); static int route_output(struct mbuf *, struct socket *, ...); static void rt_setmetrics (u_long, struct rt_metrics *, - struct rt_metrics *); + struct rt_metrics *); /* * It really doesn't make any sense at all for this code to share much @@ -86,6 +94,7 @@ static int rts_abort(struct socket *so) { int s, error; + s = splnet(); error = raw_usrreqs.pru_abort(so); splx(s); @@ -102,6 +111,7 @@ rts_attach(struct socket *so, int proto, struct pru_attach_info *ai) if (sotorawcb(so) != NULL) return EISCONN; /* XXX panic? */ + MALLOC(rp, struct rawcb *, sizeof *rp, M_PCB, M_WAITOK|M_ZERO); if (rp == NULL) return ENOBUFS; @@ -148,6 +158,7 @@ static int rts_bind(struct socket *so, struct sockaddr *nam, struct thread *td) { int s, error; + s = splnet(); error = raw_usrreqs.pru_bind(so, nam, td); /* xxx just EINVAL */ splx(s); @@ -158,6 +169,7 @@ static int rts_connect(struct socket *so, struct sockaddr *nam, struct thread *td) { int s, error; + s = splnet(); error = raw_usrreqs.pru_connect(so, nam, td); /* XXX just EINVAL */ splx(s); @@ -200,6 +212,7 @@ static int rts_disconnect(struct socket *so) { int s, error; + s = splnet(); error = raw_usrreqs.pru_disconnect(so); splx(s); @@ -212,6 +225,7 @@ static int rts_peeraddr(struct socket *so, struct sockaddr **nam) { int s, error; + s = splnet(); error = raw_usrreqs.pru_peeraddr(so, nam); splx(s); @@ -226,6 +240,7 @@ rts_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *nam, struct mbuf *control, struct thread *td) { int s, error; + s = splnet(); error = raw_usrreqs.pru_send(so, flags, m, nam, control, td); splx(s); @@ -238,6 +253,7 @@ static int rts_shutdown(struct socket *so) { int s, error; + s = splnet(); error = raw_usrreqs.pru_shutdown(so); splx(s); @@ -248,6 +264,7 @@ static int rts_sockaddr(struct socket *so, struct sockaddr **nam) { int s, error; + s = splnet(); error = raw_usrreqs.pru_sockaddr(so, nam); splx(s); @@ -272,6 +289,7 @@ route_output(struct mbuf *m, struct socket *so, ...) struct radix_node_head *rnh; struct ifnet *ifp = NULL; struct ifaddr *ifa = NULL; + struct rawcb *rp = NULL; struct pr_output_info *oi; struct rt_addrinfo info; int len, error = 0; @@ -405,7 +423,7 @@ route_output(struct mbuf *m, struct socket *so, ...) bcopy(rtm, new_rtm, rtm->rtm_msglen); Free(rtm); rtm = new_rtm; } - (void)rt_msg2(rtm->rtm_type, &info, (caddr_t)rtm, NULL); + rt_msg2(rtm->rtm_type, &info, (caddr_t)rtm, NULL); rtm->rtm_flags = rt->rt_flags; rtm->rtm_rmx = rt->rt_rmx; rtm->rtm_addrs = info.rti_addrs; @@ -428,23 +446,23 @@ route_output(struct mbuf *m, struct socket *so, ...) } if (info.sa_gateway != NULL && (error = rt_setgate(rt, rt_key(rt), - info.sa_gateway)) != 0) + info.sa_gateway)) != 0) gotoerr(error); if ((ifa = info.rti_ifa) != NULL) { struct ifaddr *oifa = rt->rt_ifa; if (oifa != ifa) { - if (oifa && oifa->ifa_rtrequest) - oifa->ifa_rtrequest(RTM_DELETE, rt, - &info); - IFAFREE(rt->rt_ifa); - rt->rt_ifa = ifa; - ifa->ifa_refcnt++; - rt->rt_ifp = info.rti_ifp; + if (oifa && oifa->ifa_rtrequest) + oifa->ifa_rtrequest(RTM_DELETE, + rt, &info); + IFAFREE(rt->rt_ifa); + rt->rt_ifa = ifa; + IFAREF(ifa); + rt->rt_ifp = info.rti_ifp; } } rt_setmetrics(rtm->rtm_inits, &rtm->rtm_rmx, - &rt->rt_rmx); + &rt->rt_rmx); if (rt->rt_ifa && rt->rt_ifa->ifa_rtrequest) rt->rt_ifa->ifa_rtrequest(RTM_ADD, rt, &info); if (info.sa_genmask != NULL) @@ -473,8 +491,6 @@ flush: } if (rt) rtfree(rt); - { - struct rawcb *rp = NULL; /* * Check to see if we don't want our own messages. */ @@ -505,7 +521,6 @@ flush: raw_input(m, &route_proto, &route_src, &route_dst); if (rp != NULL) rp->rcb_proto.sp_family = PF_ROUTE; - } return (error); } @@ -710,18 +725,16 @@ again: /* * This routine is called to generate a message from the routing - * socket indicating that a redirect has occured, a routing lookup + * socket indicating that a redirect has occurred, a routing lookup * has failed, or that a protocol has detected timeouts to a particular * destination. */ void -rt_missmsg(type, rtinfo, flags, error) - int type, flags, error; - struct rt_addrinfo *rtinfo; +rt_missmsg(int type, struct rt_addrinfo *rtinfo, int flags, int error) { + struct sockaddr *sa = rtinfo->rti_info[RTAX_DST]; struct rt_msghdr *rtm; struct mbuf *m; - struct sockaddr *sa = rtinfo->sa_dst; if (route_cb.any_count == 0) return; @@ -777,8 +790,11 @@ rt_ifamsg(int cmd, struct ifaddr *ifa) info.sa_ifpaddr = TAILQ_FIRST(&ifp->if_addrhead)->ifa_addr; info.sa_netmask = ifa->ifa_netmask; info.sa_bcastaddr = ifa->ifa_dstaddr; - if ((m = rt_msg1(cmd, &info)) == NULL) + + m = rt_msg1(cmd, &info); + if (m == NULL) return; + ifam = mtod(m, struct ifa_msghdr *); ifam->ifam_index = ifp->if_index; ifam->ifam_metric = ifa->ifa_metric; @@ -786,6 +802,7 @@ rt_ifamsg(int cmd, struct ifaddr *ifa) ifam->ifam_addrs = info.rti_addrs; route_proto.sp_protocol = sa ? sa->sa_family : 0; + raw_input(m, &route_proto, &route_src, &route_dst); } @@ -800,12 +817,16 @@ rt_rtmsg(int cmd, struct ifaddr *ifa, int error, struct rtentry *rt) if (rt == NULL) return; + bzero(&info, sizeof(info)); info.sa_netmask = rt_mask(rt); info.sa_dst = sa = rt_key(rt); info.sa_gateway = rt->rt_gateway; - if ((m = rt_msg1(cmd, &info)) == NULL) + + m = rt_msg1(cmd, &info); + if (m == NULL) return; + rtm = mtod(m, struct rt_msghdr *); rtm->rtm_index = ifp->if_index; rtm->rtm_flags |= rt->rt_flags; @@ -813,6 +834,7 @@ rt_rtmsg(int cmd, struct ifaddr *ifa, int error, struct rtentry *rt) rtm->rtm_addrs = info.rti_addrs; route_proto.sp_protocol = sa ? sa->sa_family : 0; + raw_input(m, &route_proto, &route_src, &route_dst); } @@ -872,12 +894,16 @@ rt_newmaddrmsg(cmd, ifma) * (similarly to how ARP entries, e.g., are presented). */ info.sa_gateway = ifma->ifma_lladdr; - if ((m = rt_msg1(cmd, &info)) == NULL) + + m = rt_msg1(cmd, &info); + if (m == NULL) return; + ifmam = mtod(m, struct ifma_msghdr *); ifmam->ifmam_index = ifp->if_index; ifmam->ifmam_addrs = info.rti_addrs; route_proto.sp_protocol = ifma->ifma_addr->sa_family; + raw_input(m, &route_proto, &route_src, &route_dst); } @@ -896,15 +922,20 @@ rt_ifannouncemsg(ifp, what) if (route_cb.any_count == 0) return; + bzero(&info, sizeof(info)); + m = rt_msg1(RTM_IFANNOUNCE, &info); if (m == NULL) return; + ifan = mtod(m, struct if_announcemsghdr *); ifan->ifan_index = ifp->if_index; strlcpy(ifan->ifan_name, ifp->if_xname, sizeof(ifan->ifan_name)); ifan->ifan_what = what; + route_proto.sp_protocol = 0; + raw_input(m, &route_proto, &route_src, &route_dst); } @@ -923,6 +954,7 @@ sysctl_dumpentry(rn, vw) if (w->w_op == NET_RT_FLAGS && !(rt->rt_flags & w->w_arg)) return 0; + bzero(&info, sizeof(info)); info.sa_dst = rt_key(rt); info.sa_gateway = rt->rt_gateway; @@ -1038,7 +1070,7 @@ sysctl_rtsock(SYSCTL_HANDLER_ARGS) for (i = 1; i <= AF_MAX; i++) if ((rnh = rt_tables[i]) && (af == 0 || af == i) && (error = rnh->rnh_walktree(rnh, - sysctl_dumpentry, &w))) + sysctl_dumpentry, &w))) break; break; diff --git a/sys/net/stf/if_stf.c b/sys/net/stf/if_stf.c index d15d806541..a2e98898d0 100644 --- a/sys/net/stf/if_stf.c +++ b/sys/net/stf/if_stf.c @@ -1,5 +1,5 @@ /* $FreeBSD: src/sys/net/if_stf.c,v 1.1.2.11 2003/01/23 21:06:44 sam Exp $ */ -/* $DragonFly: src/sys/net/stf/if_stf.c,v 1.11 2004/11/30 19:21:26 joerg Exp $ */ +/* $DragonFly: src/sys/net/stf/if_stf.c,v 1.12 2004/12/21 02:54:15 hsu Exp $ */ /* $KAME: if_stf.c,v 1.73 2001/12/03 11:08:30 keiichi Exp $ */ /* @@ -480,7 +480,7 @@ stf_checkaddr4(sc, in, inifp) sin.sin_family = AF_INET; sin.sin_len = sizeof(struct sockaddr_in); sin.sin_addr = *in; - rt = rtalloc1((struct sockaddr *)&sin, 0, 0UL); + rt = rtlookup((struct sockaddr *)&sin, 0, 0UL); if (!rt || rt->rt_ifp != inifp) { #if 0 log(LOG_WARNING, "%s: packet from 0x%x dropped " diff --git a/sys/net/zlib.c b/sys/net/zlib.c index 47a557b360..1c22bd23c5 100644 --- a/sys/net/zlib.c +++ b/sys/net/zlib.c @@ -11,7 +11,7 @@ * - allow strm->next_out to be NULL, meaning discard the output * * $FreeBSD: src/sys/net/zlib.c,v 1.10.2.3 2002/03/24 23:12:48 jedgar Exp $ - * $DragonFly: src/sys/net/zlib.c,v 1.6 2004/02/13 17:45:49 joerg Exp $ + * $DragonFly: src/sys/net/zlib.c,v 1.7 2004/12/21 02:54:14 hsu Exp $ */ /* @@ -1601,7 +1601,7 @@ local block_state deflate_stored(s, flush) s->lookahead = 0; /* Emit a stored block if pending_buf will be full: */ - max_start = s->block_start + max_block_size; + max_start = s->block_start + max_block_size; if (s->strstart == 0 || (ulg)s->strstart >= max_start) { /* strstart == 0 is possible when wraparound on 16-bit machine */ s->lookahead = (uInt)(s->strstart - max_start); @@ -4069,7 +4069,7 @@ z_stream *z; n -= t; z->total_out += t; s->read = q; /* drag read pointer forward */ -/* WWRAP */ /* expand WWRAP macro by hand to handle s->read */ +/* WWRAP */ /* expand WWRAP macro by hand to handle s->read */ if (q == s->end) { s->read = q = s->window; m = WAVAIL; diff --git a/sys/net/zlib.h b/sys/net/zlib.h index fef416cfc7..7d6be0904a 100644 --- a/sys/net/zlib.h +++ b/sys/net/zlib.h @@ -1,5 +1,5 @@ /* $FreeBSD: src/sys/net/zlib.h,v 1.7.2.1 2002/07/31 14:13:05 rwatson Exp $ */ -/* $DragonFly: src/sys/net/zlib.h,v 1.3 2004/02/13 17:45:49 joerg Exp $ */ +/* $DragonFly: src/sys/net/zlib.h,v 1.4 2004/12/21 02:54:14 hsu Exp $ */ /* * This file is derived from zlib.h and zconf.h from the zlib-1.0.4 @@ -74,7 +74,7 @@ extern "C" { # define deflateInit_ z_deflateInit_ # define deflate z_deflate # define deflateEnd z_deflateEnd -# define inflateInit_ z_inflateInit_ +# define inflateInit_ z_inflateInit_ # define inflate z_inflate # define inflateEnd z_inflateEnd # define deflateInit2_ z_deflateInit2_ diff --git a/sys/netinet/icmp6.h b/sys/netinet/icmp6.h index 43306fe0ee..c58fee2473 100644 --- a/sys/netinet/icmp6.h +++ b/sys/netinet/icmp6.h @@ -1,5 +1,5 @@ /* $FreeBSD: src/sys/netinet/icmp6.h,v 1.2.2.5 2002/06/29 18:31:11 ume Exp $ */ -/* $DragonFly: src/sys/netinet/icmp6.h,v 1.4 2004/09/23 16:44:32 joerg Exp $ */ +/* $DragonFly: src/sys/netinet/icmp6.h,v 1.5 2004/12/21 02:54:15 hsu Exp $ */ /* $KAME: icmp6.h,v 1.46 2001/04/27 15:09:48 itojun Exp $ */ /* @@ -100,7 +100,7 @@ struct icmp6_hdr { #define ICMP6_ECHO_REQUEST 128 /* echo service */ #define ICMP6_ECHO_REPLY 129 /* echo reply */ #define ICMP6_MEMBERSHIP_QUERY 130 /* group membership query */ -#define MLD_LISTENER_QUERY 130 /* multicast listener query */ +#define MLD_LISTENER_QUERY 130 /* multicast listener query */ #define ICMP6_MEMBERSHIP_REPORT 131 /* group membership report */ #define MLD_LISTENER_REPORT 131 /* multicast listener report */ #define ICMP6_MEMBERSHIP_REDUCTION 132 /* group membership termination */ @@ -134,7 +134,7 @@ struct icmp6_hdr { #define ICMP6_HADISCOV_REQUEST 202 /* XXX To be defined */ #define ICMP6_HADISCOV_REPLY 203 /* XXX To be defined */ - + #ifndef _KERNEL #define MLD6_MTRACE_RESP MLD_MTRACE_RESP #define MLD6_MTRACE MLD_MTRACE @@ -143,16 +143,16 @@ struct icmp6_hdr { #define ICMP6_MAXTYPE 203 #define ICMP6_DST_UNREACH_NOROUTE 0 /* no route to destination */ -#define ICMP6_DST_UNREACH_ADMIN 1 /* administratively prohibited */ +#define ICMP6_DST_UNREACH_ADMIN 1 /* administratively prohibited */ #define ICMP6_DST_UNREACH_NOTNEIGHBOR 2 /* not a neighbor(obsolete) */ #define ICMP6_DST_UNREACH_BEYONDSCOPE 2 /* beyond scope of source address */ #define ICMP6_DST_UNREACH_ADDR 3 /* address unreachable */ #define ICMP6_DST_UNREACH_NOPORT 4 /* port unreachable */ -#define ICMP6_TIME_EXCEED_TRANSIT 0 /* ttl==0 in transit */ +#define ICMP6_TIME_EXCEED_TRANSIT 0 /* ttl==0 in transit */ #define ICMP6_TIME_EXCEED_REASSEMBLY 1 /* ttl==0 in reass */ -#define ICMP6_PARAMPROB_HEADER 0 /* erroneous header field */ +#define ICMP6_PARAMPROB_HEADER 0 /* erroneous header field */ #define ICMP6_PARAMPROB_NEXTHEADER 1 /* unrecognized next header */ #define ICMP6_PARAMPROB_OPTION 2 /* unrecognized option */ @@ -205,7 +205,7 @@ struct mld_hdr { */ struct nd_router_solicit { /* router solicitation */ - struct icmp6_hdr nd_rs_hdr; + struct icmp6_hdr nd_rs_hdr; /* could be followed by options */ } __attribute__((__packed__)); @@ -345,7 +345,7 @@ struct nd_opt_route_info { /* route info */ */ struct icmp6_namelookup { - struct icmp6_hdr icmp6_nl_hdr; + struct icmp6_hdr icmp6_nl_hdr; u_int8_t icmp6_nl_nonce[8]; int32_t icmp6_nl_ttl; #if 0 @@ -453,7 +453,7 @@ struct icmp6_router_renum { /* router renumbering header */ #define rr_type rr_hdr.icmp6_type #define rr_code rr_hdr.icmp6_code #define rr_cksum rr_hdr.icmp6_cksum -#define rr_seqnum rr_hdr.icmp6_data32[0] +#define rr_seqnum rr_hdr.icmp6_data32[0] struct rr_pco_match { /* match prefix part */ u_int8_t rpm_code; @@ -694,8 +694,8 @@ do { \ #define icmp6_ifoutstat_inc(ifp, type, code) \ do { \ icmp6_ifstat_inc(ifp, ifs6_out_msg); \ - if (type < ICMP6_INFOMSG_MASK) \ - icmp6_ifstat_inc(ifp, ifs6_out_error); \ + if (type < ICMP6_INFOMSG_MASK) \ + icmp6_ifstat_inc(ifp, ifs6_out_error); \ switch(type) { \ case ICMP6_DST_UNREACH: \ icmp6_ifstat_inc(ifp, ifs6_out_dstunreach); \ diff --git a/sys/netinet/icmp_var.h b/sys/netinet/icmp_var.h index 843e24dc87..1d8369a16b 100644 --- a/sys/netinet/icmp_var.h +++ b/sys/netinet/icmp_var.h @@ -32,7 +32,7 @@ * * @(#)icmp_var.h 8.1 (Berkeley) 6/10/93 * $FreeBSD: src/sys/netinet/icmp_var.h,v 1.15.2.2 2001/12/07 09:23:11 ru Exp $ - * $DragonFly: src/sys/netinet/icmp_var.h,v 1.4 2004/09/19 22:32:48 joerg Exp $ + * $DragonFly: src/sys/netinet/icmp_var.h,v 1.5 2004/12/21 02:54:15 hsu Exp $ */ #ifndef _NETINET_ICMP_VAR_H_ @@ -53,16 +53,16 @@ struct icmpstat { u_long icps_oldicmp; /* no error 'cuz old was icmp */ u_long icps_outhist[ICMP_MAXTYPE + 1]; /* statistics related to input messages processed */ - u_long icps_badcode; /* icmp_code out of range */ + u_long icps_badcode; /* icmp_code out of range */ u_long icps_tooshort; /* packet < ICMP_MINLEN */ u_long icps_checksum; /* bad checksum */ u_long icps_badlen; /* calculated bound mismatch */ u_long icps_reflect; /* number of responses */ u_long icps_inhist[ICMP_MAXTYPE + 1]; - u_long icps_bmcastecho; /* b/mcast echo requests dropped */ - u_long icps_bmcasttstamp; /* b/mcast tstamp requests dropped */ + u_long icps_bmcastecho; /* b/mcast echo requests dropped */ + u_long icps_bmcasttstamp; /* b/mcast tstamp requests dropped */ u_long icps_badaddr; /* bad return address */ - u_long icps_noroute; /* no route back */ + u_long icps_noroute; /* no route back */ }; /* diff --git a/sys/netinet/if_atm.c b/sys/netinet/if_atm.c index 4f86163703..f8674d13d9 100644 --- a/sys/netinet/if_atm.c +++ b/sys/netinet/if_atm.c @@ -15,7 +15,7 @@ * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: - * This product includes software developed by Charles D. Cranor and + * This product includes software developed by Charles D. Cranor and * Washington University. * 4. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. @@ -32,7 +32,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/netinet/if_atm.c,v 1.8.2.1 2001/12/20 10:30:18 ru Exp $ - * $DragonFly: src/sys/netinet/if_atm.c,v 1.5 2004/03/23 22:19:07 hsu Exp $ + * $DragonFly: src/sys/netinet/if_atm.c,v 1.6 2004/12/21 02:54:15 hsu Exp $ */ /* @@ -71,10 +71,9 @@ /* * atm_rtrequest: handle ATM rt request (in support of generic code) * inputs: "req" = request code - * "rt" = route entry - * "info" = rt_addrinfo + * "rt" = route entry + * "info" = rt_addrinfo */ - void atm_rtrequest(req, rt, info) int req; @@ -108,7 +107,7 @@ atm_rtrequest(req, rt, info) * case we are being called via "ifconfig" to set the address. */ - if ((rt->rt_flags & RTF_HOST) == 0) { + if ((rt->rt_flags & RTF_HOST) == 0) { rt_setgate(rt,rt_key(rt),(struct sockaddr *)&null_sdl); gate = rt->rt_gateway; SDL(gate)->sdl_type = rt->rt_ifp->if_type; @@ -139,14 +138,14 @@ atm_rtrequest(req, rt, info) if (sin->sin_family != AF_INET) goto failed; aph = (struct atm_pseudohdr *) LLADDR(SDL(gate)); - npcb = npcb_add(NULL, rt->rt_ifp, ATM_PH_VCI(aph), + npcb = npcb_add(NULL, rt->rt_ifp, ATM_PH_VCI(aph), ATM_PH_VPI(aph)); - if (npcb == NULL) + if (npcb == NULL) goto failed; npcb->npcb_flags |= NPCB_IP; npcb->ipaddr.s_addr = sin->sin_addr.s_addr; /* XXX: move npcb to llinfo when ATM ARP is ready */ - rt->rt_llinfo = (caddr_t) npcb; + rt->rt_llinfo = npcb; rt->rt_flags |= RTF_LLINFO; #endif /* @@ -154,8 +153,8 @@ atm_rtrequest(req, rt, info) */ bcopy(LLADDR(SDL(gate)), &api.aph, sizeof(api.aph)); api.rxhand = NULL; - if (rt->rt_ifp->if_ioctl(rt->rt_ifp, SIOCATMENA, - (caddr_t)&api, (struct ucred *)NULL) != 0) { + if (rt->rt_ifp->if_ioctl(rt->rt_ifp, SIOCATMENA, (caddr_t)&api, + (struct ucred *)NULL) != 0) { printf("atm: couldn't add VC\n"); goto failed; } @@ -173,8 +172,8 @@ failed: rt->rt_flags &= ~RTF_LLINFO; } #endif - rtrequest(RTM_DELETE, rt_key(rt), (struct sockaddr *)0, - rt_mask(rt), 0, (struct rtentry **) 0); + rtrequest(RTM_DELETE, rt_key(rt), (struct sockaddr *) NULL, + rt_mask(rt), 0, (struct rtentry **) NULL); break; case RTM_DELETE: @@ -185,8 +184,7 @@ failed: */ if (rt->rt_flags & RTF_LLINFO) { - npcb_free((struct natmpcb *)rt->rt_llinfo, - NPCB_DESTROY); + npcb_free(rt->rt_llinfo, NPCB_DESTROY); rt->rt_llinfo = NULL; rt->rt_flags &= ~RTF_LLINFO; } @@ -197,8 +195,8 @@ failed: bcopy(LLADDR(SDL(gate)), &api.aph, sizeof(api.aph)); api.rxhand = NULL; - (void)rt->rt_ifp->if_ioctl(rt->rt_ifp, SIOCATMDIS, - (caddr_t)&api, (struct ucred *)NULL); + rt->rt_ifp->if_ioctl(rt->rt_ifp, SIOCATMDIS, (caddr_t)&api, + (struct ucred *)NULL); break; } @@ -212,7 +210,7 @@ failed: * [3] "dst" = sockaddr_in (IP) address of dest. * output: * [4] "desten" = ATM pseudo header which we will fill in VPI/VCI info - * return: + * return: * 0 == resolve FAILED; note that "m" gets m_freem'd in this case * 1 == resolve OK; desten contains result * @@ -240,7 +238,7 @@ struct atm_pseudohdr *desten; /* OUT */ rt = RTALLOC1(dst, 0); if (rt == NULL) goto bad; /* failed */ rt->rt_refcnt--; /* don't keep LL references */ - if ((rt->rt_flags & RTF_GATEWAY) != 0 || + if ((rt->rt_flags & RTF_GATEWAY) != 0 || (rt->rt_flags & RTF_LLINFO) == 0 || /* XXX: are we using LLINFO? */ rt->rt_gateway->sa_family != AF_LINK) { @@ -249,7 +247,7 @@ struct atm_pseudohdr *desten; /* OUT */ } /* - * note that rt_gateway is a sockaddr_dl which contains the + * note that rt_gateway is a sockaddr_dl which contains the * atm_pseudohdr data structure for this route. we currently * don't need any rt_llinfo info (but will if we want to support * ATM ARP [c.f. if_ether.c]). diff --git a/sys/netinet/if_atm.h b/sys/netinet/if_atm.h index 30f3e0ddf2..115573bca3 100644 --- a/sys/netinet/if_atm.h +++ b/sys/netinet/if_atm.h @@ -1,5 +1,5 @@ /* $FreeBSD: src/sys/netinet/if_atm.h,v 1.2.6.2 2001/12/20 10:30:18 ru Exp $ */ -/* $DragonFly: src/sys/netinet/if_atm.h,v 1.3 2003/08/23 11:18:00 rob Exp $ */ +/* $DragonFly: src/sys/netinet/if_atm.h,v 1.4 2004/12/21 02:54:15 hsu Exp $ */ /* $NetBSD: if_atm.h,v 1.2 1996/07/03 17:17:17 chuck Exp $ */ /* @@ -17,8 +17,8 @@ * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: - * This product includes software developed by Charles D. Cranor and - * Washington University. + * This product includes software developed by Charles D. Cranor and + * Washington University. * 4. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * @@ -44,5 +44,5 @@ struct rtentry; struct sockaddr; void atm_rtrequest (int, struct rtentry *, struct rt_addrinfo *); -int atmresolve (struct rtentry *, struct mbuf *, struct sockaddr *, +int atmresolve (struct rtentry *, struct mbuf *, struct sockaddr *, struct atm_pseudohdr *); diff --git a/sys/netinet/if_ether.c b/sys/netinet/if_ether.c index de45f9b8ad..d45f2f3366 100644 --- a/sys/netinet/if_ether.c +++ b/sys/netinet/if_ether.c @@ -32,7 +32,7 @@ * * @(#)if_ether.c 8.1 (Berkeley) 6/10/93 * $FreeBSD: src/sys/netinet/if_ether.c,v 1.64.2.23 2003/04/11 07:23:15 fjoe Exp $ - * $DragonFly: src/sys/netinet/if_ether.c,v 1.20 2004/12/14 18:46:08 hsu Exp $ + * $DragonFly: src/sys/netinet/if_ether.c,v 1.21 2004/12/21 02:54:15 hsu Exp $ */ /* @@ -88,12 +88,12 @@ static int arpt_down = 20; /* once declared down, don't send for 20 sec */ SYSCTL_INT(_net_link_ether_inet, OID_AUTO, prune_intvl, CTLFLAG_RW, &arpt_prune, 0, ""); -SYSCTL_INT(_net_link_ether_inet, OID_AUTO, max_age, CTLFLAG_RW, +SYSCTL_INT(_net_link_ether_inet, OID_AUTO, max_age, CTLFLAG_RW, &arpt_keep, 0, ""); SYSCTL_INT(_net_link_ether_inet, OID_AUTO, host_down_time, CTLFLAG_RW, &arpt_down, 0, ""); -#define rt_expire rt_rmx.rmx_expire +#define rt_expire rt_rmx.rmx_expire struct llinfo_arp { LIST_ENTRY(llinfo_arp) la_le; @@ -105,8 +105,6 @@ struct llinfo_arp { static LIST_HEAD(, llinfo_arp) llinfo_arp; -static int arp_inuse, arp_allocated, arpinit_done; - static int arp_maxtries = 5; static int useloopback = 1; /* use loopback interface for local traffic */ static int arp_proxyall = 0; @@ -125,7 +123,7 @@ static int arpintr(struct netmsg *); static void arptfree (struct llinfo_arp *); static void arptimer (void *); static struct llinfo_arp - *arplookup (u_long, int, int); + *arplookup (in_addr_t addr, boolean_t create, boolean_t proxy); #ifdef INET static void in_arpinput (struct mbuf *); #endif @@ -137,8 +135,7 @@ static struct callout arptimer_ch; */ /* ARGSUSED */ static void -arptimer(ignored_arg) - void *ignored_arg; +arptimer(void *ignored_arg) { int s = splnet(); struct llinfo_arp *la, *nla; @@ -155,31 +152,31 @@ arptimer(ignored_arg) * Parallel to llc_rtrequest. */ static void -arp_rtrequest(req, rt, info) - int req; - struct rtentry *rt; - struct rt_addrinfo *info; +arp_rtrequest(int req, struct rtentry *rt, struct rt_addrinfo *info) { struct sockaddr *gate = rt->rt_gateway; - struct llinfo_arp *la = (struct llinfo_arp *)rt->rt_llinfo; - static struct sockaddr_dl null_sdl = {sizeof(null_sdl), AF_LINK}; + struct llinfo_arp *la = rt->rt_llinfo; + + struct sockaddr_dl null_sdl = { sizeof(null_sdl), AF_LINK }; + static boolean_t arpinit_done; + static int arp_inuse, arp_allocated; /* for debugging only */ if (!arpinit_done) { - arpinit_done = 1; + arpinit_done = TRUE; callout_init(&arptimer_ch); callout_reset(&arptimer_ch, hz, arptimer, NULL); } if (rt->rt_flags & RTF_GATEWAY) return; - switch (req) { + switch (req) { case RTM_ADD: /* * XXX: If this is a manually added route to interface * such as older version of routed or gated might provide, * restore cloning bit. */ - if ((rt->rt_flags & RTF_HOST) == 0 && + if (!(rt->rt_flags & RTF_HOST) && SIN(rt_mask(rt))->sin_addr.s_addr != 0xffffffff) rt->rt_flags |= RTF_CLONING; if (rt->rt_flags & RTF_CLONING) { @@ -187,7 +184,7 @@ arp_rtrequest(req, rt, info) * Case 1: This route should come from a route to iface. */ rt_setgate(rt, rt_key(rt), - (struct sockaddr *)&null_sdl); + (struct sockaddr *)&null_sdl); gate = rt->rt_gateway; SDL(gate)->sdl_type = rt->rt_ifp->if_type; SDL(gate)->sdl_index = rt->rt_ifp->if_index; @@ -199,30 +196,30 @@ arp_rtrequest(req, rt, info) arprequest(rt->rt_ifp, &SIN(rt_key(rt))->sin_addr, &SIN(rt_key(rt))->sin_addr, - (u_char *)LLADDR(SDL(gate))); + LLADDR(SDL(gate))); /*FALLTHROUGH*/ case RTM_RESOLVE: if (gate->sa_family != AF_LINK || - gate->sa_len < sizeof(null_sdl)) { + gate->sa_len < sizeof(struct sockaddr_dl)) { log(LOG_DEBUG, "arp_rtrequest: bad gateway value\n"); break; } SDL(gate)->sdl_type = rt->rt_ifp->if_type; SDL(gate)->sdl_index = rt->rt_ifp->if_index; - if (la != 0) + if (la != NULL) break; /* This happens on a route change */ /* * Case 2: This route may come from cloning, or a manual route * add with a LL address. */ R_Malloc(la, struct llinfo_arp *, sizeof(*la)); - rt->rt_llinfo = (caddr_t)la; - if (la == 0) { + rt->rt_llinfo = la; + if (la == NULL) { log(LOG_DEBUG, "arp_rtrequest: malloc failed\n"); break; } arp_inuse++, arp_allocated++; - bzero(la, sizeof(*la)); + bzero(la, sizeof *la); la->la_rt = rt; rt->rt_flags |= RTF_LLINFO; LIST_INSERT_HEAD(&llinfo_arp, la, la_le); @@ -233,8 +230,8 @@ arp_rtrequest(req, rt, info) * in `arp -a' listings as unresolved. It's not actually * functional. Then the same for broadcast. */ - if (IN_MULTICAST(ntohl(SIN(rt_key(rt))->sin_addr.s_addr)) - && rt->rt_ifp->if_type != IFT_ARCNET) { + if (IN_MULTICAST(ntohl(SIN(rt_key(rt))->sin_addr.s_addr)) && + rt->rt_ifp->if_type != IFT_ARCNET) { ETHER_MAP_IP_MULTICAST(&SIN(rt_key(rt))->sin_addr, LLADDR(SDL(gate))); SDL(gate)->sdl_alen = 6; @@ -250,35 +247,36 @@ arp_rtrequest(req, rt, info) if (SIN(rt_key(rt))->sin_addr.s_addr == (IA_SIN(rt->rt_ifa))->sin_addr.s_addr) { - /* - * This test used to be - * if (loif.if_flags & IFF_UP) - * It allowed local traffic to be forced - * through the hardware by configuring the loopback down. - * However, it causes problems during network configuration - * for boards that can't receive packets they send. - * It is now necessary to clear "useloopback" and remove - * the route to force traffic out to the hardware. - */ + /* + * This test used to be + * if (loif.if_flags & IFF_UP) + * It allowed local traffic to be forced + * through the hardware by configuring the + * loopback down. However, it causes problems + * during network configuration for boards + * that can't receive packets they send. It + * is now necessary to clear "useloopback" and + * remove the route to force traffic out to + * the hardware. + */ rt->rt_expire = 0; bcopy(IF_LLADDR(rt->rt_ifp), LLADDR(SDL(gate)), SDL(gate)->sdl_alen = rt->rt_ifp->if_addrlen); if (useloopback) rt->rt_ifp = loif; - } break; case RTM_DELETE: - if (la == 0) + if (la == NULL) break; arp_inuse--; LIST_REMOVE(la, la_le); - rt->rt_llinfo = 0; + rt->rt_llinfo = NULL; rt->rt_flags &= ~RTF_LLINFO; - if (la->la_hold) + if (la->la_hold != NULL) m_freem(la->la_hold); - Free((caddr_t)la); + Free(la); } } @@ -289,23 +287,22 @@ arp_rtrequest(req, rt, info) * - arp header source ethernet address */ static void -arprequest(ifp, sip, tip, enaddr) - struct ifnet *ifp; - struct in_addr *sip, *tip; - u_char *enaddr; +arprequest(struct ifnet *ifp, struct in_addr *sip, struct in_addr *tip, + u_char *enaddr) { struct mbuf *m; struct ether_header *eh; struct arc_header *arh; struct arphdr *ah; struct sockaddr sa; - static u_char llcx[] = { 0x82, 0x40, LLC_SNAP_LSAP, LLC_SNAP_LSAP, - LLC_UI, 0x00, 0x00, 0x00, 0x08, 0x06 }; + static u_char llcx[] = { 0x82, 0x40, LLC_SNAP_LSAP, LLC_SNAP_LSAP, + LLC_UI, 0x00, 0x00, 0x00, 0x08, 0x06 }; u_short ar_hrd; if ((m = m_gethdr(MB_DONTWAIT, MT_DATA)) == NULL) return; - m->m_pkthdr.rcvif = (struct ifnet *)0; + m->m_pkthdr.rcvif = (struct ifnet *)NULL; + switch (ifp->if_type) { case IFT_ARCNET: ar_hrd = htons(ARPHRD_ARCNET); @@ -329,9 +326,9 @@ arprequest(ifp, sip, tip, enaddr) m->m_pkthdr.len = m->m_len; MH_ALIGN(m, m->m_len); - (void)memcpy(mtod(m, caddr_t), llcx, sizeof(llcx)); + memcpy(mtod(m, caddr_t), llcx, sizeof(llcx)); memcpy(sa.sa_data, ifp->if_broadcastaddr, ifp->if_addrlen); - (void)memcpy(sa.sa_data + 6, enaddr, 6); + memcpy(sa.sa_data + 6, enaddr, 6); sa.sa_data[6] |= TR_RII; sa.sa_data[12] = TR_AC; sa.sa_data[13] = TR_LLC_FRAME; @@ -352,7 +349,7 @@ arprequest(ifp, sip, tip, enaddr) MH_ALIGN(m, m->m_len); eh = (struct ether_header *)sa.sa_data; - /* if_output will not swap */ + /* if_output() will not swap */ eh->ether_type = htons(ETHERTYPE_ARP); memcpy(eh->ether_dhost, ifp->if_broadcastaddr, ifp->if_addrlen); @@ -365,14 +362,14 @@ arprequest(ifp, sip, tip, enaddr) ah->ar_hln = ifp->if_addrlen; /* hardware address length */ ah->ar_pln = sizeof(struct in_addr); /* protocol address length */ ah->ar_op = htons(ARPOP_REQUEST); - (void)memcpy(ar_sha(ah), enaddr, ah->ar_hln); + memcpy(ar_sha(ah), enaddr, ah->ar_hln); memset(ar_tha(ah), 0, ah->ar_hln); - (void)memcpy(ar_spa(ah), sip, ah->ar_pln); - (void)memcpy(ar_tpa(ah), tip, ah->ar_pln); + memcpy(ar_spa(ah), sip, ah->ar_pln); + memcpy(ar_tpa(ah), tip, ah->ar_pln); sa.sa_family = AF_UNSPEC; sa.sa_len = sizeof(sa); - (*ifp->if_output)(ifp, m, &sa, (struct rtentry *)0); + (*ifp->if_output)(ifp, m, &sa, (struct rtentry *)NULL); } /* @@ -386,15 +383,15 @@ arprequest(ifp, sip, tip, enaddr) * taken over here, either now or for later transmission. */ int -arpresolve(ifp, rt, m, dst, desten, rt0) - struct ifnet *ifp; - struct rtentry *rt; - struct mbuf *m; - struct sockaddr *dst; - u_char *desten; - struct rtentry *rt0; +arpresolve( + struct ifnet *ifp, + struct rtentry *rt0, + struct mbuf *m, + struct sockaddr *dst, + u_char *desten) { - struct llinfo_arp *la = 0; + struct rtentry *rt; + struct llinfo_arp *la = NULL; struct sockaddr_dl *sdl; if (m->m_flags & M_BCAST) { /* broadcast */ @@ -403,16 +400,21 @@ arpresolve(ifp, rt, m, dst, desten, rt0) } if (m->m_flags & M_MCAST && ifp->if_type != IFT_ARCNET) {/* multicast */ ETHER_MAP_IP_MULTICAST(&SIN(dst)->sin_addr, desten); - return(1); + return (1); } - if (rt) - la = (struct llinfo_arp *)rt->rt_llinfo; - if (la == 0) { - la = arplookup(SIN(dst)->sin_addr.s_addr, 1, 0); - if (la) + if (rt0 != NULL) { + if (rt_llroute(dst, rt0, &rt) != 0) { + m_freem(m); + return 0; + } + la = rt->rt_llinfo; + } + if (la == NULL) { + la = arplookup(SIN(dst)->sin_addr.s_addr, TRUE, FALSE); + if (la != NULL) rt = la->la_rt; } - if (la == 0 || rt == 0) { + if (la == NULL || rt == NULL) { log(LOG_DEBUG, "arpresolve: can't allocate llinfo for %s%s%s\n", inet_ntoa(SIN(dst)->sin_addr), la ? "la" : "", rt ? "rt" : ""); @@ -438,7 +440,7 @@ arpresolve(ifp, rt, m, dst, desten, rt0) &SIN(dst)->sin_addr, IF_LLADDR(ifp)); la->la_preempt--; - } + } bcopy(LLADDR(sdl), desten, sdl->sdl_alen); return 1; @@ -458,7 +460,7 @@ arpresolve(ifp, rt, m, dst, desten, rt0) * response yet. Replace the held mbuf with this * latest one. */ - if (la->la_hold) + if (la->la_hold != NULL) m_freem(la->la_hold); la->la_hold = m; if (rt->rt_expire || ((rt->rt_flags & RTF_STATIC) && !sdl->sdl_alen)) { @@ -552,8 +554,7 @@ SYSCTL_INT(_net_link_ether_inet, OID_AUTO, log_arp_wrong_iface, CTLFLAG_RW, "log arp packets arriving on the wrong interface"); static void -in_arpinput(m) - struct mbuf *m; +in_arpinput(struct mbuf *m) { struct arphdr *ah; struct ifnet *ifp = m->m_pkthdr.rcvif; @@ -579,8 +580,8 @@ in_arpinput(m) ah = mtod(m, struct arphdr *); op = ntohs(ah->ar_op); - (void)memcpy(&isaddr, ar_spa(ah), sizeof (isaddr)); - (void)memcpy(&itaddr, ar_tpa(ah), sizeof (itaddr)); + memcpy(&isaddr, ar_spa(ah), sizeof isaddr); + memcpy(&itaddr, ar_tpa(ah), sizeof itaddr); #ifdef BRIDGE #define BRIDGE_TEST (do_bridge) #else @@ -640,12 +641,13 @@ match: itaddr = myaddr; goto reply; } - la = arplookup(isaddr.s_addr, itaddr.s_addr == myaddr.s_addr, 0); + la = arplookup(isaddr.s_addr, (itaddr.s_addr == myaddr.s_addr), FALSE); if (la && (rt = la->la_rt) && (sdl = SDL(rt->rt_gateway))) { /* the following is not an error when doing bridging */ if (!BRIDGE_TEST && rt->rt_ifp != ifp) { if (log_arp_wrong_iface) - log(LOG_ERR, "arp: %s is on %s but got reply from %*D on %s\n", + log(LOG_ERR, + "arp: %s is on %s but got reply from %*D on %s\n", inet_ntoa(isaddr), rt->rt_ifp->if_xname, ifp->if_addrlen, (u_char *)ar_sha(ah), ":", @@ -655,7 +657,8 @@ match: if (sdl->sdl_alen && bcmp(ar_sha(ah), LLADDR(sdl), sdl->sdl_alen)) { if (rt->rt_expire) - log(LOG_INFO, "arp: %s moved from %*D to %*D on %s\n", + log(LOG_INFO, + "arp: %s moved from %*D to %*D on %s\n", inet_ntoa(isaddr), ifp->if_addrlen, (u_char *)LLADDR(sdl), ":", ifp->if_addrlen, (u_char *)ar_sha(ah), ":", @@ -687,8 +690,7 @@ match: ah->ar_hln, ifp->if_addrlen); goto reply; } - (void)memcpy(LLADDR(sdl), ar_sha(ah), - sdl->sdl_alen = ah->ar_hln); + memcpy(LLADDR(sdl), ar_sha(ah), sdl->sdl_alen = ah->ar_hln); /* * If we receive an arp from a token-ring station over * a token-ring nic then try to save the source @@ -725,10 +727,9 @@ match: rt->rt_flags &= ~RTF_REJECT; la->la_asked = 0; la->la_preempt = arp_maxtries; - if (la->la_hold) { - (*ifp->if_output)(ifp, la->la_hold, - rt_key(rt), rt); - la->la_hold = 0; + if (la->la_hold != NULL) { + (*ifp->if_output)(ifp, la->la_hold, rt_key(rt), rt); + la->la_hold = NULL; } } reply: @@ -738,10 +739,10 @@ reply: } if (itaddr.s_addr == myaddr.s_addr) { /* I am the target */ - (void)memcpy(ar_tha(ah), ar_sha(ah), ah->ar_hln); - (void)memcpy(ar_sha(ah), IF_LLADDR(ifp), ah->ar_hln); + memcpy(ar_tha(ah), ar_sha(ah), ah->ar_hln); + memcpy(ar_sha(ah), IF_LLADDR(ifp), ah->ar_hln); } else { - la = arplookup(itaddr.s_addr, 0, SIN_PROXY); + la = arplookup(itaddr.s_addr, FALSE, SIN_PROXY); if (la == NULL) { struct sockaddr_in sin; @@ -755,7 +756,7 @@ reply: sin.sin_len = sizeof sin; sin.sin_addr = itaddr; - rt = rtalloc1((struct sockaddr *)&sin, 0, 0UL); + rt = rtlookup((struct sockaddr *)&sin, 0, 0UL); if (!rt) { m_freem(m); return; @@ -766,27 +767,27 @@ reply: * over who claims what Ether address. */ if (rt->rt_ifp == ifp) { - rtfree(rt); + --rt->rt_refcnt; m_freem(m); return; } - (void)memcpy(ar_tha(ah), ar_sha(ah), ah->ar_hln); - (void)memcpy(ar_sha(ah), IF_LLADDR(ifp), ah->ar_hln); - rtfree(rt); + memcpy(ar_tha(ah), ar_sha(ah), ah->ar_hln); + memcpy(ar_sha(ah), IF_LLADDR(ifp), ah->ar_hln); + --rt->rt_refcnt; #ifdef DEBUG_PROXY printf("arp: proxying for %s\n", inet_ntoa(itaddr)); #endif } else { rt = la->la_rt; - (void)memcpy(ar_tha(ah), ar_sha(ah), ah->ar_hln); + memcpy(ar_tha(ah), ar_sha(ah), ah->ar_hln); sdl = SDL(rt->rt_gateway); - (void)memcpy(ar_sha(ah), LLADDR(sdl), ah->ar_hln); + memcpy(ar_sha(ah), LLADDR(sdl), ah->ar_hln); } } - (void)memcpy(ar_tpa(ah), ar_spa(ah), ah->ar_pln); - (void)memcpy(ar_spa(ah), &itaddr, ah->ar_pln); + memcpy(ar_tpa(ah), ar_spa(ah), ah->ar_pln); + memcpy(ar_spa(ah), &itaddr, ah->ar_pln); ah->ar_op = htons(ARPOP_REPLY); ah->ar_pro = htons(ETHERTYPE_IP); /* let's be sure! */ switch (ifp->if_type) { @@ -822,8 +823,7 @@ reply: */ default: eh = (struct ether_header *)sa.sa_data; - (void)memcpy(eh->ether_dhost, ar_tha(ah), - sizeof(eh->ether_dhost)); + memcpy(eh->ether_dhost, ar_tha(ah), sizeof(eh->ether_dhost)); eh->ether_type = htons(ETHERTYPE_ARP); break; } @@ -848,41 +848,39 @@ arptfree(la) { struct rtentry *rt = la->la_rt; struct sockaddr_dl *sdl; + if (rt == NULL) panic("arptfree"); sdl = SDL(rt->rt_gateway); - if (sdl && ((rt->rt_refcnt > 0 && sdl->sdl_family == AF_LINK) || + if (sdl && ((rt->rt_refcnt > 0 && sdl->sdl_family == AF_LINK) || (rt->rt_flags & RTF_STATIC))) { sdl->sdl_alen = 0; la->la_preempt = la->la_asked = 0; rt->rt_flags &= ~RTF_REJECT; return; } - rtrequest(RTM_DELETE, rt_key(rt), (struct sockaddr *)0, rt_mask(rt), - 0, (struct rtentry **)0); + rtrequest(RTM_DELETE, rt_key(rt), NULL, rt_mask(rt), 0, NULL); } /* * Lookup or enter a new address in arptab. */ static struct llinfo_arp * -arplookup(addr, create, proxy) - u_long addr; - int create, proxy; +arplookup(in_addr_t addr, boolean_t create, boolean_t proxy) { struct rtentry *rt; - static struct sockaddr_inarp sin = {sizeof(sin), AF_INET }; - const char *why = 0; + static struct sockaddr_inarp sin = { sizeof(sin), AF_INET }; + const char *why = NULL; sin.sin_addr.s_addr = addr; sin.sin_other = proxy ? SIN_PROXY : 0; - rt = rtalloc1((struct sockaddr *)&sin, create, 0UL); - if (rt == 0) - return (0); + rt = rtlookup((struct sockaddr *)&sin, create, 0UL); + if (rt == NULL) + return (NULL); rt->rt_refcnt--; if (rt->rt_flags & RTF_GATEWAY) why = "host is not on local network"; - else if ((rt->rt_flags & RTF_LLINFO) == 0) + else if (!(rt->rt_flags & RTF_LLINFO)) why = "could not allocate llinfo"; else if (rt->rt_gateway->sa_family != AF_LINK) why = "gateway route is not ours"; @@ -892,27 +890,22 @@ arplookup(addr, create, proxy) log(LOG_DEBUG, "arplookup %s failed: %s\n", inet_ntoa(sin.sin_addr), why); } - - /* if there are no references to this route, purge it */ - if (rt->rt_refcnt <= 0 && - (rt->rt_flags & RTF_WASCLONED) == RTF_WASCLONED) { - rtrequest(RTM_DELETE, - (struct sockaddr *)rt_key(rt), rt->rt_gateway, - rt_mask(rt), rt->rt_flags, 0); + if (rt->rt_refcnt <= 0 && (rt->rt_flags & RTF_WASCLONED)) { + /* No references to this route. Purge it. */ + rtrequest(RTM_DELETE, rt_key(rt), rt->rt_gateway, + rt_mask(rt), rt->rt_flags, NULL); } - return (0); + return (NULL); } - return ((struct llinfo_arp *)rt->rt_llinfo); + return (rt->rt_llinfo); } void -arp_ifinit(ifp, ifa) - struct ifnet *ifp; - struct ifaddr *ifa; +arp_ifinit(struct ifnet *ifp, struct ifaddr *ifa) { - if (ntohl(IA_SIN(ifa)->sin_addr.s_addr) != INADDR_ANY) - arprequest(ifp, &IA_SIN(ifa)->sin_addr, - &IA_SIN(ifa)->sin_addr, IF_LLADDR(ifp)); + if (IA_SIN(ifa)->sin_addr.s_addr != INADDR_ANY) + arprequest(ifp, &IA_SIN(ifa)->sin_addr, &IA_SIN(ifa)->sin_addr, + IF_LLADDR(ifp)); ifa->ifa_rtrequest = arp_rtrequest; ifa->ifa_flags |= RTF_CLONING; } diff --git a/sys/netinet/if_ether.h b/sys/netinet/if_ether.h index dd0f4911a9..9e987da571 100644 --- a/sys/netinet/if_ether.h +++ b/sys/netinet/if_ether.h @@ -32,7 +32,7 @@ * * @(#)if_ether.h 8.3 (Berkeley) 5/2/95 * $FreeBSD: src/sys/netinet/if_ether.h,v 1.24.2.1 2002/02/13 21:38:56 fjoe Exp $ - * $DragonFly: src/sys/netinet/if_ether.h,v 1.4 2003/09/15 23:38:14 hsu Exp $ + * $DragonFly: src/sys/netinet/if_ether.h,v 1.5 2004/12/21 02:54:15 hsu Exp $ */ #ifndef _NETINET_IF_ETHER_H_ @@ -65,7 +65,7 @@ #define ETHER_MAP_IPV6_MULTICAST(ip6addr, enaddr) \ /* struct in6_addr *ip6addr; */ \ /* u_char enaddr[ETHER_ADDR_LEN]; */ \ -{ \ +{ \ (enaddr)[0] = 0x33; \ (enaddr)[1] = 0x33; \ (enaddr)[2] = ((u_char *)ip6addr)[12]; \ @@ -115,7 +115,7 @@ extern u_char ether_ipmulticast_min[ETHER_ADDR_LEN]; extern u_char ether_ipmulticast_max[ETHER_ADDR_LEN]; int arpresolve (struct ifnet *, struct rtentry *, struct mbuf *, - struct sockaddr *, u_char *, struct rtentry *); + struct sockaddr *, u_char *); void arp_ifinit (struct ifnet *, struct ifaddr *); #endif diff --git a/sys/netinet/if_fddi.h b/sys/netinet/if_fddi.h index 6dc082746f..0a5a158a5c 100644 --- a/sys/netinet/if_fddi.h +++ b/sys/netinet/if_fddi.h @@ -34,7 +34,7 @@ * * @(#)if_fddi.h 8.1 (Berkeley) 6/10/93 * $FreeBSD: src/sys/netinet/if_fddi.h,v 1.8 1999/12/29 04:40:58 peter Exp $ - * $DragonFly: src/sys/netinet/Attic/if_fddi.h,v 1.4 2004/07/23 07:16:31 joerg Exp $ + * $DragonFly: src/sys/netinet/Attic/if_fddi.h,v 1.5 2004/12/21 02:54:15 hsu Exp $ */ #ifndef _NETINET_IF_FDDI_H_ @@ -67,7 +67,7 @@ struct fddi_header { #define FDDIFC_LLC_PRIO5 5 #define FDDIFC_LLC_PRIO6 6 #define FDDIFC_LLC_PRIO7 7 -#define FDDIFC_LLC_SYNC 0xd0 +#define FDDIFC_LLC_SYNC 0xd0 #define FDDIFC_SMT 0x40 #if defined(_KERNEL) diff --git a/sys/netinet/igmp.c b/sys/netinet/igmp.c index f0b753ea04..952055e9ac 100644 --- a/sys/netinet/igmp.c +++ b/sys/netinet/igmp.c @@ -36,7 +36,7 @@ * * @(#)igmp.c 8.1 (Berkeley) 7/19/93 * $FreeBSD: src/sys/netinet/igmp.c,v 1.29.2.2 2003/01/23 21:06:44 sam Exp $ - * $DragonFly: src/sys/netinet/igmp.c,v 1.9 2004/06/03 18:30:03 joerg Exp $ + * $DragonFly: src/sys/netinet/igmp.c,v 1.10 2004/12/21 02:54:15 hsu Exp $ */ /* @@ -123,30 +123,30 @@ static struct router_info * find_rti(ifp) struct ifnet *ifp; { - struct router_info *rti = Head; + struct router_info *rti = Head; #ifdef IGMP_DEBUG printf("[igmp.c, _find_rti] --> entering \n"); #endif - while (rti) { - if (rti->rti_ifp == ifp) { + while (rti) { + if (rti->rti_ifp == ifp) { #ifdef IGMP_DEBUG printf("[igmp.c, _find_rti] --> found old entry \n"); #endif - return rti; - } - rti = rti->rti_next; - } + return rti; + } + rti = rti->rti_next; + } MALLOC(rti, struct router_info *, sizeof *rti, M_IGMP, M_INTWAIT); - rti->rti_ifp = ifp; - rti->rti_type = IGMP_V2_ROUTER; - rti->rti_time = 0; - rti->rti_next = Head; - Head = rti; + rti->rti_ifp = ifp; + rti->rti_type = IGMP_V2_ROUTER; + rti->rti_time = 0; + rti->rti_next = Head; + Head = rti; #ifdef IGMP_DEBUG printf("[igmp.c, _find_rti] --> created an entry \n"); #endif - return rti; + return rti; } void @@ -445,51 +445,51 @@ igmp_sendpkt(inm, type, addr) int type; unsigned long addr; { - struct mbuf *m; - struct igmp *igmp; - struct ip *ip; - struct ip_moptions imo; + struct mbuf *m; + struct igmp *igmp; + struct ip *ip; + struct ip_moptions imo; - MGETHDR(m, MB_DONTWAIT, MT_HEADER); - if (m == NULL) - return; + MGETHDR(m, MB_DONTWAIT, MT_HEADER); + if (m == NULL) + return; m->m_pkthdr.rcvif = loif; m->m_pkthdr.len = sizeof(struct ip) + IGMP_MINLEN; MH_ALIGN(m, IGMP_MINLEN + sizeof(struct ip)); m->m_data += sizeof(struct ip); - m->m_len = IGMP_MINLEN; - igmp = mtod(m, struct igmp *); - igmp->igmp_type = type; - igmp->igmp_code = 0; - igmp->igmp_group = inm->inm_addr; - igmp->igmp_cksum = 0; - igmp->igmp_cksum = in_cksum(m, IGMP_MINLEN); - - m->m_data -= sizeof(struct ip); - m->m_len += sizeof(struct ip); - ip = mtod(m, struct ip *); - ip->ip_tos = 0; - ip->ip_len = sizeof(struct ip) + IGMP_MINLEN; - ip->ip_off = 0; - ip->ip_p = IPPROTO_IGMP; - ip->ip_src.s_addr = INADDR_ANY; - ip->ip_dst.s_addr = addr ? addr : igmp->igmp_group.s_addr; - - imo.imo_multicast_ifp = inm->inm_ifp; - imo.imo_multicast_ttl = 1; - imo.imo_multicast_vif = -1; - /* - * Request loopback of the report if we are acting as a multicast - * router, so that the process-level routing demon can hear it. - */ - imo.imo_multicast_loop = (ip_mrouter != NULL); + m->m_len = IGMP_MINLEN; + igmp = mtod(m, struct igmp *); + igmp->igmp_type = type; + igmp->igmp_code = 0; + igmp->igmp_group = inm->inm_addr; + igmp->igmp_cksum = 0; + igmp->igmp_cksum = in_cksum(m, IGMP_MINLEN); + + m->m_data -= sizeof(struct ip); + m->m_len += sizeof(struct ip); + ip = mtod(m, struct ip *); + ip->ip_tos = 0; + ip->ip_len = sizeof(struct ip) + IGMP_MINLEN; + ip->ip_off = 0; + ip->ip_p = IPPROTO_IGMP; + ip->ip_src.s_addr = INADDR_ANY; + ip->ip_dst.s_addr = addr ? addr : igmp->igmp_group.s_addr; + + imo.imo_multicast_ifp = inm->inm_ifp; + imo.imo_multicast_ttl = 1; + imo.imo_multicast_vif = -1; + /* + * Request loopback of the report if we are acting as a multicast + * router, so that the process-level routing demon can hear it. + */ + imo.imo_multicast_loop = (ip_mrouter != NULL); /* * XXX * Do we have to worry about reentrancy here? Don't think so. */ - ip_output(m, router_alert, &igmprt, 0, &imo, NULL); + ip_output(m, router_alert, &igmprt, 0, &imo, NULL); - ++igmpstat.igps_snd_reports; + ++igmpstat.igps_snd_reports; } diff --git a/sys/netinet/igmp.h b/sys/netinet/igmp.h index 503b199310..b1a538621b 100644 --- a/sys/netinet/igmp.h +++ b/sys/netinet/igmp.h @@ -36,7 +36,7 @@ * * @(#)igmp.h 8.1 (Berkeley) 6/10/93 * $FreeBSD: src/sys/netinet/igmp.h,v 1.10 1999/08/28 00:49:15 peter Exp $ - * $DragonFly: src/sys/netinet/igmp.h,v 1.2 2003/06/17 04:28:51 dillon Exp $ + * $DragonFly: src/sys/netinet/igmp.h,v 1.3 2004/12/21 02:54:15 hsu Exp $ */ #ifndef _NETINET_IGMP_H_ @@ -54,35 +54,34 @@ * IGMP packet format. */ struct igmp { - u_char igmp_type; /* version & type of IGMP message */ - u_char igmp_code; /* subtype for routing msgs */ - u_short igmp_cksum; /* IP-style checksum */ - struct in_addr igmp_group; /* group address being reported */ -}; /* (zero for queries) */ + u_char igmp_type; /* version & type of IGMP message */ + u_char igmp_code; /* subtype for routing msgs */ + u_short igmp_cksum; /* IP-style checksum */ + struct in_addr igmp_group; /* group address being reported */ +}; /* (zero for queries) */ #define IGMP_MINLEN 8 /* * Message types, including version number. */ -#define IGMP_MEMBERSHIP_QUERY 0x11 /* membership query */ +#define IGMP_MEMBERSHIP_QUERY 0x11 /* membership query */ #define IGMP_V1_MEMBERSHIP_REPORT 0x12 /* Ver. 1 membership report */ #define IGMP_V2_MEMBERSHIP_REPORT 0x16 /* Ver. 2 membership report */ -#define IGMP_V2_LEAVE_GROUP 0x17 /* Leave-group message */ +#define IGMP_V2_LEAVE_GROUP 0x17 /* Leave-group message */ -#define IGMP_DVMRP 0x13 /* DVMRP routing message */ -#define IGMP_PIM 0x14 /* PIM routing message */ +#define IGMP_DVMRP 0x13 /* DVMRP routing message */ +#define IGMP_PIM 0x14 /* PIM routing message */ #define IGMP_MTRACE_RESP 0x1e /* traceroute resp.(to sender)*/ -#define IGMP_MTRACE 0x1f /* mcast traceroute messages */ +#define IGMP_MTRACE 0x1f /* mcast traceroute messages */ -#define IGMP_MAX_HOST_REPORT_DELAY 10 /* max delay for response to */ - /* query (in seconds) according */ - /* to RFC1112 */ +#define IGMP_MAX_HOST_REPORT_DELAY 10 /* max delay for response to + * query (in seconds) according + * to RFC1112 */ - -#define IGMP_TIMER_SCALE 10 /* denotes that the igmp code field */ - /* specifies time in 10th of seconds*/ +#define IGMP_TIMER_SCALE 10 /* denotes that the igmp code field + * specifies time in 10th of seconds*/ /* * The following four defininitions are for backwards compatibility. diff --git a/sys/netinet/in.c b/sys/netinet/in.c index 1ab53c02de..9f02c923bf 100644 --- a/sys/netinet/in.c +++ b/sys/netinet/in.c @@ -32,7 +32,7 @@ * * @(#)in.c 8.4 (Berkeley) 1/9/95 * $FreeBSD: src/sys/netinet/in.c,v 1.44.2.14 2002/11/08 00:45:50 suz Exp $ - * $DragonFly: src/sys/netinet/in.c,v 1.12 2004/09/10 14:02:01 joerg Exp $ + * $DragonFly: src/sys/netinet/in.c,v 1.13 2004/12/21 02:54:15 hsu Exp $ */ #include "opt_bootp.h" @@ -67,7 +67,7 @@ static int in_ifinit (struct ifnet *, struct in_ifaddr *, struct sockaddr_in *, int); static int subnetsarelocal = 0; -SYSCTL_INT(_net_inet_ip, OID_AUTO, subnets_are_local, CTLFLAG_RW, +SYSCTL_INT(_net_inet_ip, OID_AUTO, subnets_are_local, CTLFLAG_RW, &subnetsarelocal, 0, ""); struct in_multihead in_multihead; /* XXX BSS initialization */ @@ -134,7 +134,7 @@ struct sockaddr_in *ap; ap->sin_len = 0; while (--cp >= cplim) - if (*cp) { + if (*cp) { (ap)->sin_len = cp - (char *) (ap) + 1; break; } @@ -355,10 +355,10 @@ in_control(so, cmd, data, ifp, td) } if (ia->ia_flags & IFA_ROUTE) { ia->ia_ifa.ifa_dstaddr = (struct sockaddr *)&oldaddr; - rtinit(&(ia->ia_ifa), (int)RTM_DELETE, RTF_HOST); + rtinit(&ia->ia_ifa, RTM_DELETE, RTF_HOST); ia->ia_ifa.ifa_dstaddr = (struct sockaddr *)&ia->ia_dstaddr; - rtinit(&(ia->ia_ifa), (int)RTM_ADD, RTF_HOST|RTF_UP); + rtinit(&ia->ia_ifa, RTM_ADD, RTF_HOST | RTF_UP); } return (0); @@ -658,9 +658,9 @@ in_ifscrub(ifp, ia) if ((ia->ia_flags & IFA_ROUTE) == 0) return; if (ifp->if_flags & (IFF_LOOPBACK|IFF_POINTOPOINT)) - rtinit(&(ia->ia_ifa), (int)RTM_DELETE, RTF_HOST); + rtinit(&ia->ia_ifa, RTM_DELETE, RTF_HOST); else - rtinit(&(ia->ia_ifa), (int)RTM_DELETE, 0); + rtinit(&ia->ia_ifa, RTM_DELETE, 0); ia->ia_flags &= ~IFA_ROUTE; } @@ -693,7 +693,7 @@ in_ifinit(ifp, ia, sin, scrub) */ if (ifp->if_ioctl && (error = (*ifp->if_ioctl)(ifp, SIOCSIFADDR, (caddr_t)ia, - (struct ucred *)NULL))) { + (struct ucred *)NULL))) { splx(s); /* LIST_REMOVE(ia, ia_hash) is done in in_control */ ia->ia_addr = oldaddr; @@ -782,9 +782,7 @@ in_ifinit(ifp, ia, sin, scrub) * Return 1 if the address might be a local broadcast address. */ int -in_broadcast(in, ifp) - struct in_addr in; - struct ifnet *ifp; +in_broadcast(struct in_addr in, struct ifnet *ifp) { struct ifaddr *ifa; u_long t; diff --git a/sys/netinet/in.h b/sys/netinet/in.h index c8a20e3774..e79fe684ef 100644 --- a/sys/netinet/in.h +++ b/sys/netinet/in.h @@ -32,7 +32,7 @@ * * @(#)in.h 8.3 (Berkeley) 1/3/94 * $FreeBSD: src/sys/netinet/in.h,v 1.48.2.10 2003/08/24 08:24:38 hsu Exp $ - * $DragonFly: src/sys/netinet/in.h,v 1.9 2004/09/19 22:32:48 joerg Exp $ + * $DragonFly: src/sys/netinet/in.h,v 1.10 2004/12/21 02:54:15 hsu Exp $ */ #ifndef _NETINET_IN_H_ @@ -67,7 +67,7 @@ #define IPPROTO_ICMP 1 /* control message protocol */ #define IPPROTO_IGMP 2 /* group mgmt protocol */ #define IPPROTO_GGP 3 /* gateway^2 (deprecated) */ -#define IPPROTO_IPV4 4 /* IPv4 encapsulation */ +#define IPPROTO_IPV4 4 /* IPv4 encapsulation */ #define IPPROTO_IPIP IPPROTO_IPV4 /* for compatibility */ #define IPPROTO_TCP 6 /* tcp */ #define IPPROTO_ST 7 /* Stream protocol II */ @@ -92,7 +92,7 @@ #define IPPROTO_LEAF2 26 /* Leaf-2 */ #define IPPROTO_RDP 27 /* Reliable Data */ #define IPPROTO_IRTP 28 /* Reliable Transaction */ -#define IPPROTO_TP 29 /* tp-4 w/ class negotiation */ +#define IPPROTO_TP 29 /* tp-4 w/ class negotiation */ #define IPPROTO_BLT 30 /* Bulk Data Transfer */ #define IPPROTO_NSP 31 /* Network Services */ #define IPPROTO_INP 32 /* Merit Internodal */ @@ -109,7 +109,7 @@ #define IPPROTO_ROUTING 43 /* IP6 routing header */ #define IPPROTO_FRAGMENT 44 /* IP6 fragmentation header */ #define IPPROTO_IDRP 45 /* InterDomain Routing*/ -#define IPPROTO_RSVP 46 /* resource reservation */ +#define IPPROTO_RSVP 46 /* resource reservation */ #define IPPROTO_GRE 47 /* General Routing Encap. */ #define IPPROTO_MHRP 48 /* Mobile Host Routing */ #define IPPROTO_BHA 49 /* BHA */ @@ -168,7 +168,7 @@ /* 101-254: Partly Unassigned */ #define IPPROTO_PIM 103 /* Protocol Independent Mcast */ #define IPPROTO_PGM 113 /* PGM */ -#define IPPROTO_PFSYNC 240 /* PFSYNC */ +#define IPPROTO_PFSYNC 240 /* PFSYNC */ /* 255: Reserved */ /* BSD Private, local use, namespace incursion */ #define IPPROTO_DIVERT 254 /* divert pseudo-protocol */ @@ -212,20 +212,17 @@ * Administrator looking for you with a heavy object. * * For a slightly more orthodox text view on this: + * ftp://ftp.isi.edu/in-notes/iana/assignments/port-numbers * - * ftp://ftp.isi.edu/in-notes/iana/assignments/port-numbers - * - * port numbers are divided into three ranges: - * - * 0 - 1023 Well Known Ports - * 1024 - 49151 Registered Ports - * 49152 - 65535 Dynamic and/or Private Ports - * + * port numbers are divided into three ranges: + * 0 - 1023 Well Known Ports + * 1024 - 49151 Registered Ports + * 49152 - 65535 Dynamic and/or Private Ports */ /* * Ports < IPPORT_RESERVED are reserved for - * privileged processes (e.g. root). (IP_PORTRANGE_LOW) + * privileged processes (e.g. root). (IP_PORTRANGE_LOW) * Ports > IPPORT_USERRESERVED are reserved * for servers, not necessarily privileged. (IP_PORTRANGE_DEFAULT) */ @@ -310,7 +307,7 @@ struct sockaddr_in { char sin_zero[8]; }; -#define INET_ADDRSTRLEN 16 +#define INET_ADDRSTRLEN 16 /* * Options for use with [gs]etsockopt at the IP level. @@ -340,11 +337,11 @@ struct sockaddr_in { #define IP_IPSEC_POLICY 21 /* int; set/get security policy */ #define IP_FAITH 22 /* bool; accept FAITH'ed connections */ -#define IP_FW_ADD 50 /* add a firewall rule to chain */ -#define IP_FW_DEL 51 /* delete a firewall rule from chain */ -#define IP_FW_FLUSH 52 /* flush firewall rule chain */ -#define IP_FW_ZERO 53 /* clear single/all firewall counter(s) */ -#define IP_FW_GET 54 /* get entire firewall rule chain */ +#define IP_FW_ADD 50 /* add a firewall rule to chain */ +#define IP_FW_DEL 51 /* delete a firewall rule from chain */ +#define IP_FW_FLUSH 52 /* flush firewall rule chain */ +#define IP_FW_ZERO 53 /* clear single/all firewall counter(s) */ +#define IP_FW_GET 54 /* get entire firewall rule chain */ #define IP_FW_RESETLOG 55 /* reset logging counters */ #define IP_DUMMYNET_CONFIGURE 60 /* add/configure a dummynet pipe */ @@ -487,7 +484,7 @@ struct ip_mreq { { "rtminexpire", CTLTYPE_INT }, \ { "rtmaxcache", CTLTYPE_INT }, \ { "sourceroute", CTLTYPE_INT }, \ - { "directed-broadcast", CTLTYPE_INT }, \ + { "directed-broadcast", CTLTYPE_INT }, \ { "intr-queue-maxlen", CTLTYPE_INT }, \ { "intr-queue-drops", CTLTYPE_INT }, \ { "stats", CTLTYPE_STRUCT }, \ @@ -511,7 +508,7 @@ struct thread; int in_broadcast (struct in_addr, struct ifnet *); int in_canforward (struct in_addr); int in_localaddr (struct in_addr); -char *inet_ntoa (struct in_addr); /* in libkern */ +char *inet_ntoa (struct in_addr); /* in libkern */ int prison_ip (struct thread *td, int flag, u_int32_t *ip); void prison_remote_ip (struct thread *td, int flag, u_int32_t *ip); diff --git a/sys/netinet/in_cksum.c b/sys/netinet/in_cksum.c index 259883284d..837f56f4e9 100644 --- a/sys/netinet/in_cksum.c +++ b/sys/netinet/in_cksum.c @@ -1,13 +1,13 @@ /* * Copyright (c) 2003,2004 The DragonFly Project. All rights reserved. - * + * * This code is derived from software contributed to The DragonFly Project * by Matthew Dillon - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: - * + * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright @@ -17,7 +17,7 @@ * 3. Neither the name of The DragonFly Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific, prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS @@ -30,8 +30,8 @@ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. - * - * $DragonFly: src/sys/netinet/in_cksum.c,v 1.7 2004/09/30 10:21:07 joerg Exp $ + * + * $DragonFly: src/sys/netinet/in_cksum.c,v 1.8 2004/12/21 02:54:15 hsu Exp $ */ #include @@ -61,9 +61,9 @@ * 0xffff + 0xffff = 0xfffe + C = 0xffff (so no second carry occurs). * * 0x8142 + 0x8243 = 0x0385 + C = 0x0386 (checksum is in same byte order - * 0x4281 + 0x4382 = 0x8603 as the data regardless of arch) + * 0x4281 + 0x4382 = 0x8603 as the data regardless of arch) * - * This works with 16, 32, 64, etc... bits as long as we deal with the + * This works with 16, 32, 64, etc... bits as long as we deal with the * carry when collapsing it back down to 16 bits. */ @@ -82,9 +82,9 @@ in_cksum_range(struct mbuf *m, int nxt, int offset, int bytes) if (nxt != 0) { uint32_t sum32; - struct ipovly ipov; + struct ipovly ipov; - /* pseudo header */ + /* pseudo header */ if (offset < sizeof(struct ipovly)) panic("in_cksum_range: offset too short"); if (m->m_len < sizeof(struct ip)) diff --git a/sys/netinet/in_gif.c b/sys/netinet/in_gif.c index b62e964a22..07b1985f2c 100644 --- a/sys/netinet/in_gif.c +++ b/sys/netinet/in_gif.c @@ -1,6 +1,6 @@ /* * $FreeBSD: src/sys/netinet/in_gif.c,v 1.5.2.11 2003/01/23 21:06:45 sam Exp $ - * $DragonFly: src/sys/netinet/in_gif.c,v 1.10 2004/06/03 18:30:03 joerg Exp $ + * $DragonFly: src/sys/netinet/in_gif.c,v 1.11 2004/12/21 02:54:15 hsu Exp $ * $KAME: in_gif.c,v 1.54 2001/05/14 14:02:16 itojun Exp $ */ /* @@ -71,10 +71,10 @@ #include /* ipstat */ static int gif_validate4 (const struct ip *, struct gif_softc *, - struct ifnet *); + struct ifnet *); extern struct domain inetdomain; -struct protosw in_gif_protosw = +const struct protosw in_gif_protosw = { SOCK_RAW, &inetdomain, 0/*IPPROTO_IPV[46]*/, PR_ATOMIC|PR_ADDR, in_gif_input, rip_output, 0, rip_ctloutput, cpu0_soport, @@ -337,7 +337,7 @@ gif_validate4(ip, sc, ifp) sin.sin_family = AF_INET; sin.sin_len = sizeof(struct sockaddr_in); sin.sin_addr = ip->ip_src; - rt = rtalloc1((struct sockaddr *)&sin, 0, 0UL); + rt = rtlookup((struct sockaddr *)&sin, 0, 0UL); if (!rt || rt->rt_ifp != ifp) { #if 0 log(LOG_WARNING, "%s: packet from 0x%x dropped " @@ -345,10 +345,10 @@ gif_validate4(ip, sc, ifp) (u_int32_t)ntohl(sin.sin_addr.s_addr)); #endif if (rt) - rtfree(rt); + --rt->rt_refcnt; return 0; } - rtfree(rt); + --rt->rt_refcnt; } return 32 * 2; diff --git a/sys/netinet/in_hostcache.c b/sys/netinet/in_hostcache.c index 2913a55e15..8fb7dbf87a 100644 --- a/sys/netinet/in_hostcache.c +++ b/sys/netinet/in_hostcache.c @@ -12,7 +12,7 @@ * no representations about the suitability of this software for any * purpose. It is provided "as is" without express or implied * warranty. - * + * * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF @@ -27,7 +27,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/netinet/in_hostcache.c,v 1.3 1999/08/28 00:49:16 peter Exp $ - * $DragonFly: src/sys/netinet/Attic/in_hostcache.c,v 1.3 2004/06/06 19:16:08 dillon Exp $ + * $DragonFly: src/sys/netinet/Attic/in_hostcache.c,v 1.4 2004/12/21 02:54:15 hsu Exp $ */ #include @@ -75,7 +75,7 @@ inhc_alloc(struct sockaddr_in *sin) if (inhc != 0) return inhc; - rt = rtalloc1(inhc->inhc_hc.hc_host, 1, 0); + rt = rtlookup(inhc->inhc_hc.hc_host, 1, 0); if (rt == 0) return 0; diff --git a/sys/netinet/in_hostcache.h b/sys/netinet/in_hostcache.h index ed28907203..1f0385983b 100644 --- a/sys/netinet/in_hostcache.h +++ b/sys/netinet/in_hostcache.h @@ -12,7 +12,7 @@ * no representations about the suitability of this software for any * purpose. It is provided "as is" without express or implied * warranty. - * + * * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF @@ -27,7 +27,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/netinet/in_hostcache.h,v 1.3 1999/12/29 04:40:59 peter Exp $ - * $DragonFly: src/sys/netinet/Attic/in_hostcache.h,v 1.2 2003/06/17 04:28:51 dillon Exp $ + * $DragonFly: src/sys/netinet/Attic/in_hostcache.h,v 1.3 2004/12/21 02:54:15 hsu Exp $ */ #ifndef _NETINET_IN_HOSTCACHE_H diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c index 29471ff794..4008d8ed51 100644 --- a/sys/netinet/in_pcb.c +++ b/sys/netinet/in_pcb.c @@ -1,10 +1,10 @@ /* * Copyright (c) 2004 Jeffrey M. Hsu. All rights reserved. * Copyright (c) 2004 The DragonFly Project. All rights reserved. - * + * * This code is derived from software contributed to The DragonFly Project * by Jeffrey M. Hsu. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -16,7 +16,7 @@ * 3. Neither the name of The DragonFly Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific, prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS @@ -82,7 +82,7 @@ * * @(#)in_pcb.c 8.4 (Berkeley) 5/24/95 * $FreeBSD: src/sys/netinet/in_pcb.c,v 1.59.2.27 2004/01/02 04:06:42 ambrisko Exp $ - * $DragonFly: src/sys/netinet/in_pcb.c,v 1.28 2004/12/20 11:03:16 joerg Exp $ + * $DragonFly: src/sys/netinet/in_pcb.c,v 1.29 2004/12/21 02:54:15 hsu Exp $ */ #include "opt_ipsec.h" @@ -228,7 +228,7 @@ in_pcballoc(struct socket *so, struct inpcbinfo *pcbinfo) inp = zalloc(pcbinfo->ipi_zone); if (inp == NULL) return (ENOBUFS); - bzero((caddr_t)inp, sizeof *inp); + bzero(inp, sizeof *inp); inp->inp_gencnt = ++pcbinfo->ipi_gencnt; inp->inp_pcbinfo = inp->inp_cpcbinfo = pcbinfo; inp->inp_socket = so; @@ -245,7 +245,7 @@ in_pcballoc(struct socket *so, struct inpcbinfo *pcbinfo) if (ip6_auto_flowlabel) inp->inp_flags |= IN6P_AUTOFLOWLABEL; #endif - so->so_pcb = (caddr_t)inp; + so->so_pcb = inp; LIST_INSERT_HEAD(&pcbinfo->pcblisthead, inp, inp_list); pcbinfo->ipi_count++; return (0); @@ -496,7 +496,7 @@ in_pcbladdr(inp, nam, plocal_sin) (!(ro->ro_rt->rt_flags & RTF_UP) || ro->ro_dst.sa_family != AF_INET || satosin(&ro->ro_dst)->sin_addr.s_addr != - sin->sin_addr.s_addr || + sin->sin_addr.s_addr || inp->inp_socket->so_options & SO_DONTROUTE)) { RTFREE(ro->ro_rt); ro->ro_rt = (struct rtentry *)NULL; @@ -639,7 +639,7 @@ in_pcbdetach(inp) so->so_pcb = 0; sofree(so); if (inp->inp_options) - (void)m_free(inp->inp_options); + m_free(inp->inp_options); if (inp->inp_route.ro_rt) rtfree(inp->inp_route.ro_rt); ip_freemoptions(inp->inp_moptions); @@ -804,14 +804,14 @@ in_losing(inp) struct rt_addrinfo info; if ((rt = inp->inp_route.ro_rt)) { - bzero((caddr_t)&info, sizeof info); + bzero(&info, sizeof info); info.rti_flags = rt->rt_flags; info.rti_info[RTAX_DST] = rt_key(rt); info.rti_info[RTAX_GATEWAY] = rt->rt_gateway; info.rti_info[RTAX_NETMASK] = rt_mask(rt); rt_missmsg(RTM_LOSING, &info, rt->rt_flags, 0); if (rt->rt_flags & RTF_DYNAMIC) - (void) rtrequest1(RTM_DELETE, &info, NULL); + rtrequest1(RTM_DELETE, &info, NULL); inp->inp_route.ro_rt = NULL; rtfree(rt); /* @@ -934,7 +934,7 @@ in_pcblookup_hash(pcbinfo, faddr, fport_arg, laddr, lport_arg, wildcard, ifp) if (in_hosteq(inp->inp_faddr, faddr) && in_hosteq(inp->inp_laddr, laddr) && inp->inp_fport == fport && inp->inp_lport == lport) { - /* found */ + /* found */ return (inp); } } @@ -1225,7 +1225,7 @@ in_pcblist_global(SYSCTL_HANDLER_ARGS) bzero(&xi, sizeof(xi)); xi.xi_len = sizeof(xi); while (i < n) { - error = SYSCTL_OUT(req, &xi, sizeof(xi)); + error = SYSCTL_OUT(req, &xi, sizeof xi); ++i; } } diff --git a/sys/netinet/in_pcb.h b/sys/netinet/in_pcb.h index 125d8c93b6..effeb88d77 100644 --- a/sys/netinet/in_pcb.h +++ b/sys/netinet/in_pcb.h @@ -1,10 +1,10 @@ /* * Copyright (c) 2004 Jeffrey M. Hsu. All rights reserved. * Copyright (c) 2004 The DragonFly Project. All rights reserved. - * + * * This code is derived from software contributed to The DragonFly Project * by Jeffrey M. Hsu. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -16,7 +16,7 @@ * 3. Neither the name of The DragonFly Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific, prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS @@ -82,7 +82,7 @@ * * @(#)in_pcb.h 8.1 (Berkeley) 6/10/93 * $FreeBSD: src/sys/netinet/in_pcb.h,v 1.32.2.7 2003/01/24 05:11:34 sam Exp $ - * $DragonFly: src/sys/netinet/in_pcb.h,v 1.18 2004/12/20 11:03:16 joerg Exp $ + * $DragonFly: src/sys/netinet/in_pcb.h,v 1.19 2004/12/21 02:54:15 hsu Exp $ */ #ifndef _NETINET_IN_PCB_H_ @@ -152,7 +152,7 @@ struct in_endpoints { * XXX * At some point struct route should possibly change to: * struct rtentry *rt - * struct in_endpoints *ie; + * struct in_endpoints *ie; */ struct in_conninfo { u_int8_t inc_flags; @@ -192,7 +192,7 @@ struct inpcb { /* local and foreign ports, local and foreign addr */ struct in_conninfo inp_inc; - caddr_t inp_ppcb; /* pointer to per-protocol pcb */ + void *inp_ppcb; /* pointer to per-protocol pcb */ struct inpcbinfo *inp_pcbinfo; /* PCB list info */ struct inpcbinfo *inp_cpcbinfo;/* back pointer for connection table */ struct socket *inp_socket; /* back pointer to socket */ @@ -363,7 +363,7 @@ struct inpcbinfo { /* XXX documentation, prefixes */ #define INP_SOCKAF(so) so->so_proto->pr_domain->dom_family -#define INP_CHECK_SOCKAF(so, af) (INP_SOCKAF(so) == af) +#define INP_CHECK_SOCKAF(so, af) (INP_SOCKAF(so) == af) #ifdef _KERNEL extern int ipport_lowfirstauto; diff --git a/sys/netinet/in_proto.c b/sys/netinet/in_proto.c index f6834e3080..9cefd88c29 100644 --- a/sys/netinet/in_proto.c +++ b/sys/netinet/in_proto.c @@ -32,7 +32,7 @@ * * @(#)in_proto.c 8.2 (Berkeley) 2/9/95 * $FreeBSD: src/sys/netinet/in_proto.c,v 1.53.2.7 2003/08/24 08:24:38 hsu Exp $ - * $DragonFly: src/sys/netinet/in_proto.c,v 1.9 2004/11/30 19:21:26 joerg Exp $ + * $DragonFly: src/sys/netinet/in_proto.c,v 1.10 2004/12/21 02:54:15 hsu Exp $ */ #include "opt_ipdivert.h" @@ -146,21 +146,21 @@ struct protosw inetsw[] = { }, #ifdef IPSEC { SOCK_RAW, &inetdomain, IPPROTO_AH, PR_ATOMIC|PR_ADDR, - ah4_input, 0, 0, 0, + ah4_input, 0, 0, 0, cpu0_soport, 0, 0, 0, 0, &nousrreqs }, #ifdef IPSEC_ESP { SOCK_RAW, &inetdomain, IPPROTO_ESP, PR_ATOMIC|PR_ADDR, - esp4_input, 0, 0, 0, + esp4_input, 0, 0, 0, cpu0_soport, 0, 0, 0, 0, &nousrreqs }, #endif { SOCK_RAW, &inetdomain, IPPROTO_IPCOMP, PR_ATOMIC|PR_ADDR, - ipcomp4_input, 0, 0, 0, + ipcomp4_input, 0, 0, 0, cpu0_soport, 0, 0, 0, 0, &nousrreqs @@ -168,28 +168,28 @@ struct protosw inetsw[] = { #endif /* IPSEC */ #ifdef FAST_IPSEC { SOCK_RAW, &inetdomain, IPPROTO_AH, PR_ATOMIC|PR_ADDR, - ipsec4_common_input, 0, 0, 0, + ipsec4_common_input, 0, 0, 0, cpu0_soport, 0, 0, 0, 0, &nousrreqs }, { SOCK_RAW, &inetdomain, IPPROTO_ESP, PR_ATOMIC|PR_ADDR, - ipsec4_common_input, 0, 0, 0, + ipsec4_common_input, 0, 0, 0, cpu0_soport, 0, 0, 0, 0, &nousrreqs }, { SOCK_RAW, &inetdomain, IPPROTO_IPCOMP, PR_ATOMIC|PR_ADDR, - ipsec4_common_input, 0, 0, 0, + ipsec4_common_input, 0, 0, 0, cpu0_soport, 0, 0, 0, 0, &nousrreqs }, #endif /* FAST_IPSEC */ { SOCK_RAW, &inetdomain, IPPROTO_IPV4, PR_ATOMIC|PR_ADDR|PR_LASTHDR, - encap4_input, 0, 0, rip_ctloutput, + encap4_input, 0, 0, rip_ctloutput, cpu0_soport, - encap_init, 0, 0, 0, + encap_init, 0, 0, 0, &rip_usrreqs }, { SOCK_RAW, &inetdomain, IPPROTO_MOBILE, PR_ATOMIC|PR_ADDR|PR_LASTHDR, @@ -206,7 +206,7 @@ struct protosw inetsw[] = { }, # ifdef INET6 { SOCK_RAW, &inetdomain, IPPROTO_IPV6, PR_ATOMIC|PR_ADDR|PR_LASTHDR, - encap4_input, 0, 0, rip_ctloutput, + encap4_input, 0, 0, rip_ctloutput, cpu0_soport, encap_init, 0, 0, 0, &rip_usrreqs @@ -214,7 +214,7 @@ struct protosw inetsw[] = { #endif #ifdef IPDIVERT { SOCK_RAW, &inetdomain, IPPROTO_DIVERT, PR_ATOMIC|PR_ADDR, - div_input, 0, 0, ip_ctloutput, + div_input, 0, 0, ip_ctloutput, cpu0_soport, div_init, 0, 0, 0, &div_usrreqs, @@ -264,7 +264,7 @@ struct protosw inetsw[] = { extern int in_inithead (void **, int); struct domain inetdomain = - { AF_INET, "internet", 0, 0, 0, + { AF_INET, "internet", 0, 0, 0, (struct protosw *)inetsw, (struct protosw *)&inetsw[sizeof(inetsw)/sizeof(inetsw[0])], 0, in_inithead, 32, sizeof(struct sockaddr_in) diff --git a/sys/netinet/in_rmx.c b/sys/netinet/in_rmx.c index 63f76d8b85..2c71421997 100644 --- a/sys/netinet/in_rmx.c +++ b/sys/netinet/in_rmx.c @@ -27,7 +27,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/netinet/in_rmx.c,v 1.37.2.3 2002/08/09 14:49:23 ru Exp $ - * $DragonFly: src/sys/netinet/in_rmx.c,v 1.6 2004/12/14 18:46:08 hsu Exp $ + * $DragonFly: src/sys/netinet/in_rmx.c,v 1.7 2004/12/21 02:54:15 hsu Exp $ */ /* @@ -57,7 +57,7 @@ #include #include -#define RTPRF_OURS RTF_PROTO3 /* set on routes we manage */ +#define RTPRF_EXPIRING RTF_PROTO3 /* set on routes we manage */ static struct callout in_rtqtimo_ch; @@ -78,9 +78,8 @@ in_addroute(char *key, char *mask, struct radix_node_head *head, if (IN_MULTICAST(ntohl(sin->sin_addr.s_addr))) rt->rt_flags |= RTF_MULTICAST; - if (!(rt->rt_flags & (RTF_HOST | RTF_CLONING | RTF_MULTICAST))) { + if (!(rt->rt_flags & (RTF_HOST | RTF_CLONING | RTF_MULTICAST))) rt->rt_flags |= RTF_PRCLONING; - } /* * A little bit of help for both IP output and input: @@ -115,26 +114,25 @@ in_addroute(char *key, char *mask, struct radix_node_head *head, ret = rn_addroute(key, mask, head, treenodes); if (ret == NULL && rt->rt_flags & RTF_HOST) { struct rtentry *rt2; + /* * We are trying to add a host route, but can't. * Find out if it is because of an * ARP entry and delete it if so. */ - rt2 = rtalloc1((struct sockaddr *)sin, 0, + rt2 = rtlookup((struct sockaddr *)sin, 0, RTF_CLONING | RTF_PRCLONING); if (rt2) { + --rt->rt_refcnt; if (rt2->rt_flags & RTF_LLINFO && - rt2->rt_flags & RTF_HOST && - rt2->rt_gateway && - rt2->rt_gateway->sa_family == AF_LINK) { - rtrequest(RTM_DELETE, - (struct sockaddr *)rt_key(rt2), - rt2->rt_gateway, - rt_mask(rt2), rt2->rt_flags, 0); - ret = rn_addroute(key, mask, head, - treenodes); + rt2->rt_flags & RTF_HOST && + rt2->rt_gateway && + rt2->rt_gateway->sa_family == AF_LINK) { + rtrequest(RTM_DELETE, rt_key(rt2), + rt2->rt_gateway, rt_mask(rt2), + rt2->rt_flags, NULL); + ret = rn_addroute(key, mask, head, treenodes); } - RTFREE(rt2); } } @@ -152,7 +150,7 @@ in_addroute(char *key, char *mask, struct radix_node_head *head, } /* - * This code is the inverse of in_clsroute: on first reference, if we + * This code is the inverse of in_closeroute: on first reference, if we * were managing the route, stop doing so and set the expiration timer * back off again. */ @@ -163,8 +161,8 @@ in_matchroute(char *key, struct radix_node_head *head) struct rtentry *rt = (struct rtentry *)rn; if (rt != NULL && rt->rt_refcnt == 0) { /* this is first reference */ - if (rt->rt_flags & RTPRF_OURS) { - rt->rt_flags &= ~RTPRF_OURS; + if (rt->rt_flags & RTPRF_EXPIRING) { + rt->rt_flags &= ~RTPRF_EXPIRING; rt->rt_rmx.rmx_expire = 0; } } @@ -174,23 +172,23 @@ in_matchroute(char *key, struct radix_node_head *head) static int rtq_reallyold = 60*60; /* one hour is ``really old'' */ SYSCTL_INT(_net_inet_ip, IPCTL_RTEXPIRE, rtexpire, CTLFLAG_RW, &rtq_reallyold , 0, - "Default expiration time on dynamically learned routes"); + "Default expiration time on cloned routes"); static int rtq_minreallyold = 10; /* never automatically crank down to less */ SYSCTL_INT(_net_inet_ip, IPCTL_RTMINEXPIRE, rtminexpire, CTLFLAG_RW, &rtq_minreallyold , 0, - "Minimum time to attempt to hold onto dynamically learned routes"); + "Minimum time to attempt to hold onto cloned routes"); static int rtq_toomany = 128; /* 128 cached routes is ``too many'' */ SYSCTL_INT(_net_inet_ip, IPCTL_RTMAXCACHE, rtmaxcache, CTLFLAG_RW, - &rtq_toomany , 0, "Upper limit on dynamically learned routes"); + &rtq_toomany , 0, "Upper limit on cloned routes"); /* * On last reference drop, mark the route as belong to us so that it can be * timed out. */ static void -in_clsroute(struct radix_node *rn, struct radix_node_head *head) +in_closeroute(struct radix_node *rn, struct radix_node_head *head) { struct rtentry *rt = (struct rtentry *)rn; @@ -200,7 +198,7 @@ in_clsroute(struct radix_node *rn, struct radix_node_head *head) if ((rt->rt_flags & (RTF_LLINFO | RTF_HOST)) != RTF_HOST) return; - if ((rt->rt_flags & (RTF_WASCLONED | RTPRF_OURS)) != RTF_WASCLONED) + if ((rt->rt_flags & (RTF_WASCLONED | RTPRF_EXPIRING)) != RTF_WASCLONED) return; /* @@ -209,13 +207,11 @@ in_clsroute(struct radix_node *rn, struct radix_node_head *head) * waiting for a timeout cycle to kill it. */ if (rtq_reallyold != 0) { - rt->rt_flags |= RTPRF_OURS; + rt->rt_flags |= RTPRF_EXPIRING; rt->rt_rmx.rmx_expire = time_second + rtq_reallyold; } else { - rtrequest(RTM_DELETE, - (struct sockaddr *)rt_key(rt), - rt->rt_gateway, rt_mask(rt), - rt->rt_flags, 0); + rtrequest(RTM_DELETE, rt_key(rt), rt->rt_gateway, rt_mask(rt), + rt->rt_flags, NULL); } } @@ -240,17 +236,14 @@ in_rtqkill(struct radix_node *rn, void *rock) struct rtentry *rt = (struct rtentry *)rn; int err; - if (rt->rt_flags & RTPRF_OURS) { + if (rt->rt_flags & RTPRF_EXPIRING) { ap->found++; - if (ap->draining || rt->rt_rmx.rmx_expire <= time_second) { if (rt->rt_refcnt > 0) panic("rtqkill route really not free"); - err = rtrequest(RTM_DELETE, - (struct sockaddr *)rt_key(rt), - rt->rt_gateway, rt_mask(rt), - rt->rt_flags, 0); + err = rtrequest(RTM_DELETE, rt_key(rt), rt->rt_gateway, + rt_mask(rt), rt->rt_flags, NULL); if (err) { log(LOG_WARNING, "in_rtqkill: error %d\n", err); } else { @@ -358,7 +351,7 @@ in_inithead(void **head, int off) rnh = *head; rnh->rnh_addaddr = in_addroute; rnh->rnh_matchaddr = in_matchroute; - rnh->rnh_close = in_clsroute; + rnh->rnh_close = in_closeroute; callout_init(&in_rtqtimo_ch); in_rtqtimo(rnh); /* kick off timeout first time */ return 1; @@ -398,8 +391,8 @@ in_ifadownkill(struct radix_node *rn, void *xap) * so that behavior is not needed there. */ rt->rt_flags &= ~(RTF_CLONING | RTF_PRCLONING); - err = rtrequest(RTM_DELETE, (struct sockaddr *)rt_key(rt), - rt->rt_gateway, rt_mask(rt), rt->rt_flags, 0); + err = rtrequest(RTM_DELETE, rt_key(rt), rt->rt_gateway, + rt_mask(rt), rt->rt_flags, NULL); if (err) { log(LOG_WARNING, "in_ifadownkill: error %d\n", err); } diff --git a/sys/netinet/in_var.h b/sys/netinet/in_var.h index 9287fa58f6..d1c51ad9cd 100644 --- a/sys/netinet/in_var.h +++ b/sys/netinet/in_var.h @@ -32,7 +32,7 @@ * * @(#)in_var.h 8.2 (Berkeley) 1/9/95 * $FreeBSD: src/sys/netinet/in_var.h,v 1.33.2.3 2001/12/14 20:09:34 jlemon Exp $ - * $DragonFly: src/sys/netinet/in_var.h,v 1.7 2004/04/13 00:14:01 hsu Exp $ + * $DragonFly: src/sys/netinet/in_var.h,v 1.8 2004/12/21 02:54:15 hsu Exp $ */ #ifndef _NETINET_IN_VAR_H_ @@ -87,7 +87,7 @@ struct in_aliasreq { extern struct in_addr zeroin_addr; extern u_char inetctlerrmap[]; -/* +/* * Hash table for IP addresses. */ extern LIST_HEAD(in_ifaddrhashhead, in_ifaddr) *in_ifaddrhashtbl; diff --git a/sys/netinet/ip6.h b/sys/netinet/ip6.h index 2565d8e57f..bef8c3e417 100644 --- a/sys/netinet/ip6.h +++ b/sys/netinet/ip6.h @@ -1,5 +1,5 @@ /* $FreeBSD: src/sys/netinet/ip6.h,v 1.2.2.2 2001/07/03 11:01:46 ume Exp $ */ -/* $DragonFly: src/sys/netinet/ip6.h,v 1.4 2004/09/24 12:39:25 joerg Exp $ */ +/* $DragonFly: src/sys/netinet/ip6.h,v 1.5 2004/12/21 02:54:15 hsu Exp $ */ /* $KAME: ip6.h,v 1.18 2001/03/29 05:34:30 itojun Exp $ */ /* @@ -149,7 +149,7 @@ struct ip6_dest { #define IP6OPT_RTALERT_LEN 4 #define IP6OPT_RTALERT_MLD 0 /* Datagram contains an MLD message */ #define IP6OPT_RTALERT_RSVP 1 /* Datagram contains an RSVP message */ -#define IP6OPT_RTALERT_ACTNET 2 /* contains an Active Networks msg */ +#define IP6OPT_RTALERT_ACTNET 2 /* contains an Active Networks msg */ #define IP6OPT_MINLEN 2 #define IP6OPT_BINDING_UPDATE 0xc6 /* 11 0 00110 */ diff --git a/sys/netinet/ip_demux.c b/sys/netinet/ip_demux.c index be7dbfa04e..5869e6818f 100644 --- a/sys/netinet/ip_demux.c +++ b/sys/netinet/ip_demux.c @@ -1,10 +1,10 @@ /* * Copyright (c) 2003, 2004 Jeffrey M. Hsu. All rights reserved. * Copyright (c) 2003, 2004 The DragonFly Project. All rights reserved. - * + * * This code is derived from software contributed to The DragonFly Project * by Jeffrey M. Hsu. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -16,7 +16,7 @@ * 3. Neither the name of The DragonFly Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific, prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS @@ -30,7 +30,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/netinet/ip_demux.c,v 1.28 2004/10/20 05:00:36 hsu Exp $ + * $DragonFly: src/sys/netinet/ip_demux.c,v 1.29 2004/12/21 02:54:15 hsu Exp $ */ /* @@ -384,7 +384,7 @@ tcp_thread_init(void) int cpu; for (cpu = 0; cpu < ncpus2; cpu++) { - lwkt_create(tcpmsg_service_loop, NULL, NULL, + lwkt_create(tcpmsg_service_loop, NULL, NULL, &tcp_thread[cpu], 0, cpu, "tcp_thread %d", cpu); tcp_thread[cpu].td_msgport.mp_putport = netmsg_put_port; } diff --git a/sys/netinet/ip_divert.c b/sys/netinet/ip_divert.c index f1c81df25e..ed8d435b25 100644 --- a/sys/netinet/ip_divert.c +++ b/sys/netinet/ip_divert.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/netinet/ip_divert.c,v 1.42.2.6 2003/01/23 21:06:45 sam Exp $ - * $DragonFly: src/sys/netinet/ip_divert.c,v 1.15 2004/12/03 20:29:53 joerg Exp $ + * $DragonFly: src/sys/netinet/ip_divert.c,v 1.16 2004/12/21 02:54:15 hsu Exp $ */ #include "opt_inet.h" @@ -193,10 +193,10 @@ divert_packet(struct mbuf *m, int incoming, int port, int rule) bzero(&divsrc.sin_zero, sizeof(divsrc.sin_zero)); if (m->m_pkthdr.rcvif) { /* - * Hide the actual interface name in there in the + * Hide the actual interface name in there in the * sin_zero array. XXX This needs to be moved to a * different sockaddr type for divert, e.g. - * sockaddr_div with multiple fields like + * sockaddr_div with multiple fields like * sockaddr_dl. Presently we have only 7 bytes * but that will do for now as most interfaces * are 4 or less + 2 or less bytes for unit. @@ -209,7 +209,7 @@ divert_packet(struct mbuf *m, int incoming, int port, int rule) * and re-uses the sockaddr_in as suggested in the man pages, * this iface name will come along for the ride. * (see div_output for the other half of this.) - */ + */ snprintf(divsrc.sin_zero, sizeof(divsrc.sin_zero), m->m_pkthdr.rcvif->if_xname); } @@ -233,7 +233,7 @@ divert_packet(struct mbuf *m, int incoming, int port, int rule) m_freem(m); ipstat.ips_noproto++; ipstat.ips_delivered--; - } + } } /* diff --git a/sys/netinet/ip_flow.c b/sys/netinet/ip_flow.c index 89ee4308f7..7b5ad02b12 100644 --- a/sys/netinet/ip_flow.c +++ b/sys/netinet/ip_flow.c @@ -34,7 +34,7 @@ * POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/netinet/ip_flow.c,v 1.9.2.2 2001/11/04 17:35:31 luigi Exp $ - * $DragonFly: src/sys/netinet/ip_flow.c,v 1.4 2004/05/03 15:18:25 hmp Exp $ + * $DragonFly: src/sys/netinet/ip_flow.c,v 1.5 2004/12/21 02:54:15 hsu Exp $ */ #include @@ -191,6 +191,7 @@ ipflow_free( struct ipflow *ipf) { int s; + /* * Remove the flow from the hash table (at elevated IPL). * Once it's off the list, we can deal with it at normal @@ -224,7 +225,7 @@ ipflow_reap( goto done; /* * choose the one that's been least recently used - * or has had the least uses in the last 1.5 + * or has had the least uses in the last 1.5 * intervals. */ if (maybe_ipf == NULL @@ -298,8 +299,8 @@ ipflow_create(const struct route *ro, struct mbuf *m) if (ipflow_inuse == IPFLOW_MAX) { ipf = ipflow_reap(); } else { - ipf = malloc(sizeof(*ipf), M_IPFLOW, - M_INTWAIT | M_NULLOK); + ipf = malloc(sizeof(*ipf), M_IPFLOW, + M_INTWAIT | M_NULLOK); if (ipf == NULL) return; ipflow_inuse++; diff --git a/sys/netinet/ip_gre.c b/sys/netinet/ip_gre.c index 80224337b4..f75b74c480 100644 --- a/sys/netinet/ip_gre.c +++ b/sys/netinet/ip_gre.c @@ -1,6 +1,6 @@ /* - * $NetBSD: ip_gre.c,v 1.21 2002/08/14 00:23:30 itojun Exp $ - * $DragonFly: src/sys/netinet/ip_gre.c,v 1.7 2004/06/03 18:30:03 joerg Exp $ + * $NetBSD: ip_gre.c,v 1.21 2002/08/14 00:23:30 itojun Exp $ + * $DragonFly: src/sys/netinet/ip_gre.c,v 1.8 2004/12/21 02:54:15 hsu Exp $ * * Copyright (c) 1998 The NetBSD Foundation, Inc. * All rights reserved. @@ -18,8 +18,8 @@ * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: - * This product includes software developed by the NetBSD - * Foundation, Inc. and its contributors. + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. * 4. Neither the name of The NetBSD Foundation nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. @@ -93,7 +93,7 @@ #include #if 1 -void gre_inet_ntoa(struct in_addr in); /* XXX */ +void gre_inet_ntoa(struct in_addr in); /* XXX */ #endif static struct gre_softc *gre_lookup(struct mbuf *, u_int8_t); @@ -120,7 +120,7 @@ gre_input(struct mbuf *m, ...) ret = gre_input2(m, off, proto); /* - * ret == 0 : packet not processed, meaning that + * ret == 0 : packet not processed, meaning that * no matching tunnel that is up is found. * we inject it to raw ip socket to see if anyone picks it up. */ diff --git a/sys/netinet/ip_gre.h b/sys/netinet/ip_gre.h index 0279ae3ba1..02ca259cc7 100644 --- a/sys/netinet/ip_gre.h +++ b/sys/netinet/ip_gre.h @@ -1,6 +1,6 @@ /* * $NetBSD: ip_gre.h,v 1.5 2002/06/09 16:33:40 itojun Exp $ - * $DragonFly: src/sys/netinet/ip_gre.h,v 1.3 2004/06/03 18:30:03 joerg Exp $ + * $DragonFly: src/sys/netinet/ip_gre.h,v 1.4 2004/12/21 02:54:15 hsu Exp $ * * Copyright (c) 1998 The NetBSD Foundation, Inc. * All rights reserved. @@ -18,8 +18,8 @@ * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: - * This product includes software developed by the NetBSD - * Foundation, Inc. and its contributors. + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. * 4. Neither the name of The NetBSD Foundation nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. diff --git a/sys/netinet/ip_icmp.c b/sys/netinet/ip_icmp.c index 8b1eaf58f3..aca9320187 100644 --- a/sys/netinet/ip_icmp.c +++ b/sys/netinet/ip_icmp.c @@ -32,7 +32,7 @@ * * @(#)ip_icmp.c 8.2 (Berkeley) 1/4/94 * $FreeBSD: src/sys/netinet/ip_icmp.c,v 1.39.2.19 2003/01/24 05:11:34 sam Exp $ - * $DragonFly: src/sys/netinet/ip_icmp.c,v 1.13 2004/10/15 22:59:10 hsu Exp $ + * $DragonFly: src/sys/netinet/ip_icmp.c,v 1.14 2004/12/21 02:54:15 hsu Exp $ */ #include "opt_ipsec.h" @@ -88,20 +88,20 @@ SYSCTL_INT(_net_inet_icmp, ICMPCTL_MASKREPL, maskrepl, CTLFLAG_RW, &icmpmaskrepl, 0, ""); static int drop_redirect = 0; -SYSCTL_INT(_net_inet_icmp, OID_AUTO, drop_redirect, CTLFLAG_RW, +SYSCTL_INT(_net_inet_icmp, OID_AUTO, drop_redirect, CTLFLAG_RW, &drop_redirect, 0, ""); static int log_redirect = 0; -SYSCTL_INT(_net_inet_icmp, OID_AUTO, log_redirect, CTLFLAG_RW, +SYSCTL_INT(_net_inet_icmp, OID_AUTO, log_redirect, CTLFLAG_RW, &log_redirect, 0, ""); -#ifdef ICMP_BANDLIM - -/* +#ifdef ICMP_BANDLIM + +/* * ICMP error-response bandwidth limiting sysctl. If not enabled, sysctl * variable content is -1 and read-only. - */ - + */ + static int icmplim = 200; SYSCTL_INT(_net_inet_icmp, ICMPCTL_ICMPLIM, icmplim, CTLFLAG_RW, &icmplim, 0, ""); @@ -111,7 +111,7 @@ static int icmplim = -1; SYSCTL_INT(_net_inet_icmp, ICMPCTL_ICMPLIM, icmplim, CTLFLAG_RD, &icmplim, 0, ""); -#endif +#endif static int icmplim_output = 1; SYSCTL_INT(_net_inet_icmp, OID_AUTO, icmplim_output, CTLFLAG_RW, @@ -413,7 +413,7 @@ icmp_input(struct mbuf *m, ...) * (if given) and then notify as usual. The ULPs will * notice that the MTU has changed and adapt accordingly. * If no new MTU was suggested, then we guess a new one - * less than the current value. If the new MTU is + * less than the current value. If the new MTU is * unreasonably small (arbitrarily set at 296), then * we reset the MTU to the interface value and enable the * lock bit, indicating that we are no longer doing MTU @@ -423,10 +423,10 @@ icmp_input(struct mbuf *m, ...) struct rtentry *rt; int mtu; - rt = rtalloc1((struct sockaddr *)&icmpsrc, 0, + rt = rtlookup((struct sockaddr *)&icmpsrc, 0, RTF_CLONING | RTF_PRCLONING); - if (rt && (rt->rt_flags & RTF_HOST) - && !(rt->rt_rmx.rmx_locks & RTV_MTU)) { + if (rt && (rt->rt_flags & RTF_HOST) && + !(rt->rt_rmx.rmx_locks & RTV_MTU)) { mtu = ntohs(icp->icmp_nextmtu); if (!mtu) mtu = ip_next_mtu(rt->rt_rmx.rmx_mtu, @@ -444,7 +444,7 @@ icmp_input(struct mbuf *m, ...) } } if (rt) - RTFREE(rt); + --rt->rt_refcnt; } #endif @@ -687,46 +687,48 @@ match: } if (opts) { #ifdef ICMPPRINTFS - if (icmpprintfs) - printf("icmp_reflect optlen %d rt %d => ", - optlen, opts->m_len); + if (icmpprintfs) + printf("icmp_reflect optlen %d rt %d => ", + optlen, opts->m_len); #endif - for (cnt = optlen; cnt > 0; cnt -= len, cp += len) { - opt = cp[IPOPT_OPTVAL]; - if (opt == IPOPT_EOL) - break; - if (opt == IPOPT_NOP) - len = 1; - else { - if (cnt < IPOPT_OLEN + sizeof(*cp)) - break; - len = cp[IPOPT_OLEN]; - if (len < IPOPT_OLEN + sizeof(*cp) || - len > cnt) - break; - } - /* - * Should check for overflow, but it "can't happen" - */ - if (opt == IPOPT_RR || opt == IPOPT_TS || - opt == IPOPT_SECURITY) { - bcopy((caddr_t)cp, - mtod(opts, caddr_t) + opts->m_len, len); - opts->m_len += len; - } - } - /* Terminate & pad, if necessary */ - cnt = opts->m_len % 4; - if (cnt) { - for (; cnt < 4; cnt++) { - *(mtod(opts, caddr_t) + opts->m_len) = - IPOPT_EOL; - opts->m_len++; - } - } + for (cnt = optlen; cnt > 0; cnt -= len, cp += len) { + opt = cp[IPOPT_OPTVAL]; + if (opt == IPOPT_EOL) + break; + if (opt == IPOPT_NOP) + len = 1; + else { + if (cnt < IPOPT_OLEN + sizeof(*cp)) + break; + len = cp[IPOPT_OLEN]; + if (len < IPOPT_OLEN + sizeof(*cp) || + len > cnt) + break; + } + /* + * Should check for overflow, but it + * "can't happen". + */ + if (opt == IPOPT_RR || opt == IPOPT_TS || + opt == IPOPT_SECURITY) { + bcopy((caddr_t)cp, + mtod(opts, caddr_t) + opts->m_len, + len); + opts->m_len += len; + } + } + /* Terminate & pad, if necessary */ + cnt = opts->m_len % 4; + if (cnt) { + for (; cnt < 4; cnt++) { + *(mtod(opts, caddr_t) + opts->m_len) = + IPOPT_EOL; + opts->m_len++; + } + } #ifdef ICMPPRINTFS - if (icmpprintfs) - printf("%d\n", opts->m_len); + if (icmpprintfs) + printf("%d\n", opts->m_len); #endif } /* @@ -747,7 +749,7 @@ match: icmp_send(m, opts, ro); done: if (opts) - (void)m_free(opts); + m_free(opts); if (ro && ro->ro_rt) RTFREE(ro->ro_rt); } @@ -783,7 +785,7 @@ icmp_send(m, opts, rt) buf, inet_ntoa(ip->ip_src)); } #endif - (void) ip_output(m, opts, rt, 0, NULL, NULL); + ip_output(m, opts, rt, 0, NULL, NULL); } n_time @@ -838,12 +840,11 @@ ip_next_mtu(mtu, dir) #endif #ifdef ICMP_BANDLIM - /* * badport_bandlim() - check for ICMP bandwidth limit * * Return 0 if it is ok to send an ICMP error response, -1 if we have - * hit our bandwidth limit and it is not ok. + * hit our bandwidth limit and it is not ok. * * If icmplim is <= 0, the feature is disabled and 0 is returned. * @@ -854,10 +855,9 @@ ip_next_mtu(mtu, dir) * Note that the printing of the error message is delayed so we can * properly print the icmp error rate that the system was trying to do * (i.e. 22000/100 pps, etc...). This can cause long delays in printing - * the 'final' error, but it doesn't make sense to solve the printing + * the 'final' error, but it doesn't make sense to solve the printing * delay with more complex code. */ - int badport_bandlim(int which) { @@ -906,7 +906,4 @@ badport_bandlim(int which) } return(0); } - #endif - - diff --git a/sys/netinet/ip_id.c b/sys/netinet/ip_id.c index bcc698352a..34801efaa1 100644 --- a/sys/netinet/ip_id.c +++ b/sys/netinet/ip_id.c @@ -35,10 +35,10 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/sys/netinet/ip_id.c,v 1.1.2.1 2001/07/19 06:37:26 kris Exp $ - * $DragonFly: src/sys/netinet/ip_id.c,v 1.3 2003/08/23 11:18:00 rob Exp $ + * $DragonFly: src/sys/netinet/ip_id.c,v 1.4 2004/12/21 02:54:15 hsu Exp $ */ -/* +/* * seed = random 15bit * n = prime, g0 = generator to n, * j = random so that gcd(j,n-1) == 1 @@ -46,7 +46,7 @@ * * X[0] = random seed. * X[n] = a*X[n-1]+b mod m is a Linear Congruential Generator - * with a = 7^(even random) mod m, + * with a = 7^(even random) mod m, * b = random with gcd(b,m) == 1 * m = 31104 and a maximal period of m-1. * @@ -74,7 +74,7 @@ #define PFAC_N 3 const static u_int16_t pfacts[PFAC_N] = { - 2, + 2, 3, 2729 }; @@ -121,15 +121,15 @@ pmod(gen, exp, mod) return (s); } -/* - * Initalizes the seed and chooses a suitable generator. Also toggles +/* + * Initalizes the seed and chooses a suitable generator. Also toggles * the msb flag. The msb flag is used to generate two distinct * cycles of random numbers and thus avoiding reuse of ids. * - * This function is called from id_randomid() when needed, an + * This function is called from id_randomid() when needed, an * application does not have to worry about it. */ -static void +static void ip_initid(void) { u_int16_t j, i; @@ -157,7 +157,7 @@ ip_initid(void) j = tmp % RU_N; tmp = tmp >> 16; - /* + /* * Do a fast gcd(j,RU_N-1), so we can find a j with * gcd(j, RU_N-1) == 1, giving a new generator for * RU_GEN^j mod RU_N @@ -170,7 +170,7 @@ ip_initid(void) if (i>=PFAC_N) noprime = 0; - else + else j = (j+1) % RU_N; } @@ -178,7 +178,7 @@ ip_initid(void) ru_counter = 0; ru_reseed = time.tv_sec + RU_OUT; - ru_msb = ru_msb == 0x8000 ? 0 : 0x8000; + ru_msb = ru_msb == 0x8000 ? 0 : 0x8000; } u_int16_t diff --git a/sys/netinet/ip_input.c b/sys/netinet/ip_input.c index d87ee8f4c9..7296b88248 100644 --- a/sys/netinet/ip_input.c +++ b/sys/netinet/ip_input.c @@ -1,10 +1,10 @@ /* * Copyright (c) 2003, 2004 Jeffrey M. Hsu. All rights reserved. * Copyright (c) 2003, 2004 The DragonFly Project. All rights reserved. - * + * * This code is derived from software contributed to The DragonFly Project * by Jeffrey M. Hsu. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -16,7 +16,7 @@ * 3. Neither the name of The DragonFly Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific, prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS @@ -82,7 +82,7 @@ * * @(#)ip_input.c 8.2 (Berkeley) 1/4/94 * $FreeBSD: src/sys/netinet/ip_input.c,v 1.130.2.52 2003/03/07 07:01:28 silby Exp $ - * $DragonFly: src/sys/netinet/ip_input.c,v 1.39 2004/12/20 17:15:40 dillon Exp $ + * $DragonFly: src/sys/netinet/ip_input.c,v 1.40 2004/12/21 02:54:15 hsu Exp $ */ #define _IP_VHL @@ -240,10 +240,10 @@ sysctl_ipstats(SYSCTL_HANDLER_ARGS) int cpu, error = 0; for (cpu = 0; cpu < ncpus; ++cpu) { - if ((error = SYSCTL_OUT(req, (void *)&ipstats_ary[cpu], + if ((error = SYSCTL_OUT(req, &ipstats_ary[cpu], sizeof(struct ip_stats)))) break; - if ((error = SYSCTL_IN(req, (void *)&ipstats_ary[cpu], + if ((error = SYSCTL_IN(req, &ipstats_ary[cpu], sizeof(struct ip_stats)))) break; } @@ -618,7 +618,7 @@ iphack: */ if (pfil_has_hooks(&inet_pfil_hook)) { odst = ip->ip_dst; - if (pfil_run_hooks(&inet_pfil_hook, &m, + if (pfil_run_hooks(&inet_pfil_hook, &m, m->m_pkthdr.rcvif, PFIL_IN)) { return; } @@ -1557,8 +1557,8 @@ dropit: /* * locate outgoing interface */ - (void)memcpy(&ipaddr.sin_addr, cp + off, - sizeof(ipaddr.sin_addr)); + memcpy(&ipaddr.sin_addr, cp + off, + sizeof ipaddr.sin_addr); if (opt == IPOPT_SSRR) { #define INA struct in_ifaddr * @@ -1574,7 +1574,7 @@ dropit: goto bad; } ip->ip_dst = ipaddr.sin_addr; - (void)memcpy(cp + off, &(IA_SIN(ia)->sin_addr), + memcpy(cp + off, &IA_SIN(ia)->sin_addr, sizeof(struct in_addr)); cp[IPOPT_OFFSET] += sizeof(struct in_addr); /* @@ -1600,8 +1600,8 @@ dropit: off--; /* 0 origin */ if (off > optlen - (int)sizeof(struct in_addr)) break; - (void)memcpy(&ipaddr.sin_addr, &ip->ip_dst, - sizeof(ipaddr.sin_addr)); + memcpy(&ipaddr.sin_addr, &ip->ip_dst, + sizeof ipaddr.sin_addr); /* * locate outgoing interface; if we're the destination, * use the incoming interface (should be same). @@ -1613,7 +1613,7 @@ dropit: code = ICMP_UNREACH_HOST; goto bad; } - (void)memcpy(cp + off, &(IA_SIN(ia)->sin_addr), + memcpy(cp + off, &IA_SIN(ia)->sin_addr, sizeof(struct in_addr)); cp[IPOPT_OFFSET] += sizeof(struct in_addr); break; @@ -1656,7 +1656,7 @@ dropit: m->m_pkthdr.rcvif); if (ia == NULL) continue; - (void)memcpy(sin, &IA_SIN(ia)->sin_addr, + memcpy(sin, &IA_SIN(ia)->sin_addr, sizeof(struct in_addr)); cp[IPOPT_OFFSET] += sizeof(struct in_addr); off += sizeof(struct in_addr); @@ -1668,7 +1668,7 @@ dropit: code = &cp[IPOPT_OFFSET] - (u_char *)ip; goto bad; } - (void)memcpy(&ipaddr.sin_addr, sin, + memcpy(&ipaddr.sin_addr, sin, sizeof(struct in_addr)); if (ifa_ifwithaddr((SA)&ipaddr) == NULL) continue; @@ -1681,7 +1681,7 @@ dropit: goto bad; } ntime = iptime(); - (void)memcpy(cp + off, &ntime, sizeof(n_time)); + memcpy(cp + off, &ntime, sizeof(n_time)); cp[IPOPT_OFFSET] += sizeof(n_time); } } @@ -1787,7 +1787,7 @@ ip_srcroute(void) */ ip_srcrt.nop = IPOPT_NOP; ip_srcrt.srcopt[IPOPT_OFFSET] = IPOPT_MINOFF; - (void)memcpy(mtod(m, caddr_t) + sizeof(struct in_addr), &ip_srcrt.nop, + memcpy(mtod(m, caddr_t) + sizeof(struct in_addr), &ip_srcrt.nop, OPTSIZ); q = (struct in_addr *)(mtod(m, caddr_t) + sizeof(struct in_addr) + OPTSIZ); diff --git a/sys/netinet/ip_output.c b/sys/netinet/ip_output.c index a3dc1a6064..d94226f029 100644 --- a/sys/netinet/ip_output.c +++ b/sys/netinet/ip_output.c @@ -28,7 +28,7 @@ * * @(#)ip_output.c 8.3 (Berkeley) 1/21/94 * $FreeBSD: src/sys/netinet/ip_output.c,v 1.99.2.37 2003/04/15 06:44:45 silby Exp $ - * $DragonFly: src/sys/netinet/ip_output.c,v 1.22 2004/10/15 22:59:10 hsu Exp $ + * $DragonFly: src/sys/netinet/ip_output.c,v 1.23 2004/12/21 02:54:15 hsu Exp $ */ #define _IP_VHL @@ -187,7 +187,7 @@ ip_output(struct mbuf *m0, struct mbuf *opt, struct route *ro, } m = m0; - KASSERT(!m || (m->m_flags & M_PKTHDR) != 0, ("ip_output: no HDR")); + KASSERT(!m || (m->m_flags & M_PKTHDR), ("ip_output: no HDR")); if (ro == NULL) { ro = &iproute; @@ -214,7 +214,7 @@ ip_output(struct mbuf *m0, struct mbuf *opt, struct route *ro, /* * Fill in IP header. */ - if ((flags & (IP_FORWARDING|IP_RAWOUTPUT)) == 0) { + if (!(flags & (IP_FORWARDING|IP_RAWOUTPUT))) { ip->ip_vhl = IP_MAKE_VHL(IPVERSION, hlen >> 2); ip->ip_off &= IP_DF; #ifdef RANDOM_IP_ID @@ -235,13 +235,14 @@ ip_output(struct mbuf *m0, struct mbuf *opt, struct route *ro, * The address family should also be checked in case of sharing the * cache with IPv6. */ - if (ro->ro_rt && ((ro->ro_rt->rt_flags & RTF_UP) == 0 || - dst->sin_family != AF_INET || - dst->sin_addr.s_addr != pkt_dst.s_addr)) { + if (ro->ro_rt && + (!(ro->ro_rt->rt_flags & RTF_UP) || + dst->sin_family != AF_INET || + dst->sin_addr.s_addr != pkt_dst.s_addr)) { RTFREE(ro->ro_rt); - ro->ro_rt = (struct rtentry *)0; + ro->ro_rt = (struct rtentry *)NULL; } - if (ro->ro_rt == 0) { + if (ro->ro_rt == NULL) { bzero(dst, sizeof(*dst)); dst->sin_family = AF_INET; dst->sin_len = sizeof(*dst); @@ -252,8 +253,8 @@ ip_output(struct mbuf *m0, struct mbuf *opt, struct route *ro, * short circuit routing lookup. */ if (flags & IP_ROUTETOIF) { - if ((ia = ifatoia(ifa_ifwithdstaddr(sintosa(dst)))) == 0 && - (ia = ifatoia(ifa_ifwithnet(sintosa(dst)))) == 0) { + if ((ia = ifatoia(ifa_ifwithdstaddr(sintosa(dst)))) == NULL && + (ia = ifatoia(ifa_ifwithnet(sintosa(dst)))) == NULL) { ipstat.ips_noroute++; error = ENETUNREACH; goto bad; @@ -262,7 +263,7 @@ ip_output(struct mbuf *m0, struct mbuf *opt, struct route *ro, ip->ip_ttl = 1; isbroadcast = in_broadcast(dst->sin_addr, ifp); } else if (IN_MULTICAST(ntohl(ip->ip_dst.s_addr)) && - imo != NULL && imo->imo_multicast_ifp != NULL) { + imo != NULL && imo->imo_multicast_ifp != NULL) { /* * Bypass the normal routing lookup for multicast * packets if the interface is specified. @@ -280,9 +281,9 @@ ip_output(struct mbuf *m0, struct mbuf *opt, struct route *ro, * the link layer, as this is probably required in all cases * for correct operation (as it is for ARP). */ - if (ro->ro_rt == 0) + if (ro->ro_rt == NULL) rtalloc_ign(ro, RTF_PRCLONING); - if (ro->ro_rt == 0) { + if (ro->ro_rt == NULL) { ipstat.ips_noroute++; error = EHOSTUNREACH; goto bad; @@ -323,7 +324,7 @@ ip_output(struct mbuf *m0, struct mbuf *opt, struct route *ro, * Confirm that the outgoing interface supports multicast. */ if ((imo == NULL) || (imo->imo_multicast_vif == -1)) { - if ((ifp->if_flags & IFF_MULTICAST) == 0) { + if (!(ifp->if_flags & IFF_MULTICAST)) { ipstat.ips_noroute++; error = ENETUNREACH; goto bad; @@ -362,7 +363,7 @@ ip_output(struct mbuf *m0, struct mbuf *opt, struct route *ro, * above, will be forwarded by the ip_input() routine, * if necessary. */ - if (ip_mrouter && (flags & IP_FORWARDING) == 0) { + if (ip_mrouter && !(flags & IP_FORWARDING)) { /* * If rsvp daemon is not running, do not * set ip_moptions. This ensures that the packet @@ -426,11 +427,11 @@ ip_output(struct mbuf *m0, struct mbuf *opt, struct route *ro, * such a packet. */ if (isbroadcast) { - if ((ifp->if_flags & IFF_BROADCAST) == 0) { + if (!(ifp->if_flags & IFF_BROADCAST)) { error = EADDRNOTAVAIL; goto bad; } - if ((flags & IP_ALLOWBROADCAST) == 0) { + if (!(flags & IP_ALLOWBROADCAST)) { error = EACCES; goto bad; } @@ -555,7 +556,7 @@ sendit: hlen = ip->ip_hl << 2; #endif if (ro->ro_rt == NULL) { - if ((flags & IP_ROUTETOIF) == 0) { + if (!(flags & IP_ROUTETOIF)) { printf("ip_output: " "can't update route after IPsec processing\n"); error = EHOSTUNREACH; /*XXX*/ @@ -595,7 +596,7 @@ skip_ipsec: } /* * There are four return cases: - * sp != NULL apply IPsec policy + * sp != NULL apply IPsec policy * sp == NULL, error == 0 no IPsec handling needed * sp == NULL, error == -EINVAL discard packet w/o error * sp == NULL, error != 0 discard packet, report error @@ -681,9 +682,9 @@ skip_ipsec: /* * If deferred crypto processing is needed, check that * the interface supports it. - */ + */ mtag = m_tag_find(m, PACKET_TAG_IPSEC_OUT_CRYPTO_NEEDED, NULL); - if (mtag != NULL && (ifp->if_capenable & IFCAP_IPSEC) == 0) { + if (mtag != NULL && !(ifp->if_capenable & IFCAP_IPSEC)) { /* notify IPsec to do its own crypto */ ipsp_skipcrypto_unmark((struct tdb_ident *)(mtag + 1)); error = EHOSTUNREACH; @@ -699,7 +700,7 @@ spd_done: * - Firewall: deny/allow/etc. * - Wrap: fake packet's addr/port * - Encapsulate: put it in another IP and send out. - */ + */ /* * Run through list of hooks for output packets. @@ -725,7 +726,7 @@ spd_done: m = args.m; dst = args.next_hop; - /* + /* * On return we must do the following: * m == NULL -> drop the pkt (old interface, deprecated) * (off & IP_FW_PORT_DENY_FLAG) -> drop the pkt (new interface) @@ -749,16 +750,16 @@ spd_done: ip = mtod(m, struct ip *); if (off == 0 && dst == old) /* common case */ goto pass; - if (DUMMYNET_LOADED && (off & IP_FW_PORT_DYNT_FLAG) != 0) { + if (DUMMYNET_LOADED && (off & IP_FW_PORT_DYNT_FLAG)) { /* * pass the pkt to dummynet. Need to include * pipe number, m, ifp, ro, dst because these are * not recomputed in the next pass. * All other parameters have been already used and - * so they are not needed anymore. + * so they are not needed anymore. * XXX note: if the ifp or ro entry are deleted * while a pkt is in dummynet, we are in trouble! - */ + */ args.ro = ro; args.dst = dst; args.flags = flags; @@ -768,11 +769,11 @@ spd_done: goto done; } #ifdef IPDIVERT - if (off != 0 && (off & IP_FW_PORT_DYNT_FLAG) == 0) { + if (off != 0 && !(off & IP_FW_PORT_DYNT_FLAG)) { struct mbuf *clone = NULL; /* Clone packet if we're doing a 'tee' */ - if ((off & IP_FW_PORT_TEE_FLAG) != 0) + if ((off & IP_FW_PORT_TEE_FLAG)) clone = m_dup(m, MB_DONTWAIT); /* @@ -845,19 +846,19 @@ spd_done: /* * We need to figure out if we have been forwarded - * to a local socket. If so, then we should somehow + * to a local socket. If so, then we should somehow * "loop back" to ip_input, and get directed to the * PCB as if we had received this packet. This is * because it may be dificult to identify the packets * you want to forward until they are being output * and have selected an interface. (e.g. locally * initiated packets) If we used the loopback inteface, - * we would not be able to control what happens + * we would not be able to control what happens * as the packet runs through ip_input() as * it is done through a ISR. */ - LIST_FOREACH(ia, - INADDR_HASH(dst->sin_addr.s_addr), ia_hash) { + LIST_FOREACH(ia, INADDR_HASH(dst->sin_addr.s_addr), + ia_hash) { /* * If the addr to forward to is one * of ours, we pretend to @@ -867,7 +868,7 @@ spd_done: dst->sin_addr.s_addr) break; } - if (ia) { /* tell ip_input "dont filter" */ + if (ia != NULL) { /* tell ip_input "dont filter" */ struct m_hdr tag; tag.mh_type = MT_TAG; @@ -889,18 +890,17 @@ spd_done: ip_input((struct mbuf *)&tag); goto done; } - /* Some of the logic for this was - * nicked from above. + /* Some of the logic for this was nicked from above. * * This rewrites the cached route in a local PCB. * Is this what we want to do? */ bcopy(dst, &ro_fwd->ro_dst, sizeof(*dst)); - ro_fwd->ro_rt = 0; + ro_fwd->ro_rt = NULL; rtalloc_ign(ro_fwd, RTF_PRCLONING); - if (ro_fwd->ro_rt == 0) { + if (ro_fwd->ro_rt == NULL) { ipstat.ips_noroute++; error = EHOSTUNREACH; goto bad; @@ -933,20 +933,20 @@ spd_done: goto pass ; } - /* - * if we get here, none of the above matches, and - * we have to drop the pkt - */ + /* + * if we get here, none of the above matches, and + * we have to drop the pkt + */ m_freem(m); - error = EACCES; /* not sure this is the right error msg */ - goto done; + error = EACCES; /* not sure this is the right error msg */ + goto done; } pass: /* 127/8 must not appear on wire - RFC1122. */ if ((ntohl(ip->ip_dst.s_addr) >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET || (ntohl(ip->ip_src.s_addr) >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET) { - if ((ifp->if_flags & IFF_LOOPBACK) == 0) { + if (!(ifp->if_flags & IFF_LOOPBACK)) { ipstat.ips_badaddr++; error = EADDRNOTAVAIL; goto bad; @@ -966,7 +966,7 @@ pass: * care of the fragmentation for us, can just send directly. */ if (ip->ip_len <= ifp->if_mtu || ((ifp->if_hwassist & CSUM_FRAGMENT) && - (ip->ip_off & IP_DF) == 0)) { + !(ip->ip_off & IP_DF))) { ip->ip_len = htons(ip->ip_len); ip->ip_off = htons(ip->ip_off); ip->ip_sum = 0; @@ -1041,7 +1041,7 @@ pass: goto bad; for (; m; m = m0) { m0 = m->m_nextpkt; - m->m_nextpkt = 0; + m->m_nextpkt = NULL; #ifdef IPSEC /* clean ipsec history once it goes out of the node */ ipsec_delaux(m); @@ -1121,17 +1121,17 @@ ip_fragment(struct ip *ip, struct mbuf **m_frag, int mtu, * If the interface will not calculate checksums on * fragmented packets, then do it here. */ - if (m0->m_pkthdr.csum_flags & CSUM_DELAY_DATA && - (if_hwassist_flags & CSUM_IP_FRAGS) == 0) { + if ((m0->m_pkthdr.csum_flags & CSUM_DELAY_DATA) && + !(if_hwassist_flags & CSUM_IP_FRAGS)) { in_delayed_cksum(m0); m0->m_pkthdr.csum_flags &= ~CSUM_DELAY_DATA; } if (len > PAGE_SIZE) { - /* - * Fragment large datagrams such that each segment - * contains a multiple of PAGE_SIZE amount of data, - * plus headers. This enables a receiver to perform + /* + * Fragment large datagrams such that each segment + * contains a multiple of PAGE_SIZE amount of data, + * plus headers. This enables a receiver to perform * page-flipping zero-copy optimizations. * * XXX When does this help given that sender and receiver @@ -1145,7 +1145,7 @@ ip_fragment(struct ip *ip, struct mbuf **m_frag, int mtu, off += m->m_len; /* - * firstlen (off - hlen) must be aligned on an + * firstlen (off - hlen) must be aligned on an * 8-byte boundary */ if (off < hlen) @@ -1180,7 +1180,7 @@ smart_frag_failure: int mhlen = sizeof (struct ip); MGETHDR(m, MB_DONTWAIT, MT_HEADER); - if (m == 0) { + if (m == NULL) { error = ENOBUFS; ipstat.ips_odropped++; goto done; @@ -1208,14 +1208,14 @@ smart_frag_failure: mhip->ip_off |= IP_MF; mhip->ip_len = htons((u_short)(len + mhlen)); m->m_next = m_copy(m0, off, len); - if (m->m_next == 0) { /* copy failed */ + if (m->m_next == NULL) { /* copy failed */ m_free(m); error = ENOBUFS; /* ??? */ ipstat.ips_odropped++; goto done; } m->m_pkthdr.len = mhlen + len; - m->m_pkthdr.rcvif = (struct ifnet *)0; + m->m_pkthdr.rcvif = (struct ifnet *)NULL; m->m_pkthdr.csum_flags = m0->m_pkthdr.csum_flags; mhip->ip_off = htons(mhip->ip_off); mhip->ip_sum = 0; @@ -1302,11 +1302,11 @@ ip_insertoptions(m, opt, phlen) ip->ip_dst = p->ipopt_dst; if (m->m_flags & M_EXT || m->m_data - optlen < m->m_pktdat) { MGETHDR(n, MB_DONTWAIT, MT_HEADER); - if (n == 0) { + if (n == NULL) { *phlen = 0; return (m); } - n->m_pkthdr.rcvif = (struct ifnet *)0; + n->m_pkthdr.rcvif = (struct ifnet *)NULL; n->m_pkthdr.len = m->m_pkthdr.len + optlen; m->m_len -= sizeof(struct ip); m->m_data += sizeof(struct ip); @@ -1314,12 +1314,12 @@ ip_insertoptions(m, opt, phlen) m = n; m->m_len = optlen + sizeof(struct ip); m->m_data += max_linkhdr; - (void)memcpy(mtod(m, void *), ip, sizeof(struct ip)); + memcpy(mtod(m, void *), ip, sizeof(struct ip)); } else { m->m_data -= optlen; m->m_len += optlen; m->m_pkthdr.len += optlen; - ovbcopy((caddr_t)ip, mtod(m, caddr_t), sizeof(struct ip)); + ovbcopy(ip, mtod(m, caddr_t), sizeof(struct ip)); } ip = mtod(m, struct ip *); bcopy(p->ipopt_list, ip + 1, optlen); @@ -1403,7 +1403,7 @@ ip_ctloutput(so, sopt) break; } MGET(m, sopt->sopt_td ? MB_WAIT : MB_DONTWAIT, MT_HEADER); - if (m == 0) { + if (m == NULL) { error = ENOBUFS; break; } @@ -1536,7 +1536,7 @@ ip_ctloutput(so, sopt) case IP_OPTIONS: case IP_RETOPTS: if (inp->inp_options) - error = sooptcopyout(sopt, + error = sooptcopyout(sopt, mtod(inp->inp_options, char *), inp->inp_options->m_len); @@ -1612,7 +1612,7 @@ ip_ctloutput(so, sopt) caddr_t req = NULL; size_t len = 0; - if (m != 0) { + if (m != NULL) { req = mtod(m, caddr_t); len = m->m_len; } @@ -1640,10 +1640,7 @@ ip_ctloutput(so, sopt) * with destination address if source routed. */ static int -ip_pcbopts(optname, pcbopt, m) - int optname; - struct mbuf **pcbopt; - struct mbuf *m; +ip_pcbopts(int optname, struct mbuf **pcbopt, struct mbuf *m) { int cnt, optlen; u_char *cp; @@ -1651,14 +1648,14 @@ ip_pcbopts(optname, pcbopt, m) /* turn off any old options */ if (*pcbopt) - (void)m_free(*pcbopt); + m_free(*pcbopt); *pcbopt = 0; - if (m == (struct mbuf *)0 || m->m_len == 0) { + if (m == NULL || m->m_len == 0) { /* * Only turning off any previous options. */ - if (m) - (void)m_free(m); + if (m != NULL) + m_free(m); return (0); } @@ -1674,7 +1671,7 @@ ip_pcbopts(optname, pcbopt, m) cnt = m->m_len; m->m_len += sizeof(struct in_addr); cp = mtod(m, u_char *) + sizeof(struct in_addr); - ovbcopy(mtod(m, caddr_t), (caddr_t)cp, (unsigned)cnt); + ovbcopy(mtod(m, caddr_t), cp, cnt); bzero(mtod(m, caddr_t), sizeof(struct in_addr)); for (; cnt > 0; cnt -= optlen, cp += optlen) { @@ -1714,16 +1711,15 @@ ip_pcbopts(optname, pcbopt, m) /* * Move first hop before start of options. */ - bcopy((caddr_t)&cp[IPOPT_OFFSET+1], mtod(m, caddr_t), + bcopy(&cp[IPOPT_OFFSET+1], mtod(m, caddr_t), sizeof(struct in_addr)); /* * Then copy rest of options back * to close up the deleted entry. */ - ovbcopy((caddr_t)(&cp[IPOPT_OFFSET+1] + - sizeof(struct in_addr)), - &cp[IPOPT_OFFSET+1], - (unsigned)cnt - (IPOPT_MINOFF - 1)); + ovbcopy(&cp[IPOPT_OFFSET+1] + sizeof(struct in_addr), + &cp[IPOPT_OFFSET+1], + cnt - (IPOPT_MINOFF - 1)); break; } } @@ -1733,7 +1729,7 @@ ip_pcbopts(optname, pcbopt, m) return (0); bad: - (void)m_free(m); + m_free(m); return (EINVAL); } @@ -1749,9 +1745,7 @@ bad: * following RFC1724 section 3.3, 0.0.0.0/8 is interpreted as interface index. */ static struct ifnet * -ip_multicast_if(a, ifindexp) - struct in_addr *a; - int *ifindexp; +ip_multicast_if(struct in_addr *a, int *ifindexp) { int ifindex; struct ifnet *ifp; @@ -1775,9 +1769,7 @@ ip_multicast_if(a, ifindexp) * Set the IP multicast options in response to user setsockopt(). */ static int -ip_setmoptions(sopt, imop) - struct sockopt *sopt; - struct ip_moptions **imop; +ip_setmoptions(struct sockopt *sopt, struct ip_moptions **imop) { int error = 0; int i; @@ -1849,7 +1841,7 @@ ip_setmoptions(sopt, imop) */ s = splimp(); ifp = ip_multicast_if(&addr, &ifindex); - if (ifp == NULL || (ifp->if_flags & IFF_MULTICAST) == 0) { + if (ifp == NULL || !(ifp->if_flags & IFF_MULTICAST)) { splx(s); error = EADDRNOTAVAIL; break; @@ -1877,7 +1869,7 @@ ip_setmoptions(sopt, imop) imo->imo_multicast_ttl = ttl; } else { u_int ttl; - error = sooptcopyin(sopt, &ttl, sizeof ttl, + error = sooptcopyin(sopt, &ttl, sizeof ttl, sizeof ttl); if (error) break; @@ -1930,7 +1922,7 @@ ip_setmoptions(sopt, imop) * the route to the given multicast address. */ if (mreq.imr_interface.s_addr == INADDR_ANY) { - bzero((caddr_t)&ro, sizeof(ro)); + bzero(&ro, sizeof(ro)); dst = (struct sockaddr_in *)&ro.ro_dst; dst->sin_len = sizeof(*dst); dst->sin_family = AF_INET; @@ -1952,7 +1944,7 @@ ip_setmoptions(sopt, imop) * See if we found an interface, and confirm that it * supports multicast. */ - if (ifp == NULL || (ifp->if_flags & IFF_MULTICAST) == 0) { + if (ifp == NULL || !(ifp->if_flags & IFF_MULTICAST)) { error = EADDRNOTAVAIL; splx(s); break; @@ -2073,9 +2065,7 @@ ip_setmoptions(sopt, imop) * Return the IP multicast options in response to user getsockopt(). */ static int -ip_getmoptions(sopt, imo) - struct sockopt *sopt; - struct ip_moptions *imo; +ip_getmoptions(struct sockopt *sopt, struct ip_moptions *imo) { struct in_addr addr; struct in_ifaddr *ia; @@ -2084,7 +2074,7 @@ ip_getmoptions(sopt, imo) error = 0; switch (sopt->sopt_name) { - case IP_MULTICAST_VIF: + case IP_MULTICAST_VIF: if (imo != NULL) optval = imo->imo_multicast_vif; else @@ -2107,7 +2097,7 @@ ip_getmoptions(sopt, imo) break; case IP_MULTICAST_TTL: - if (imo == 0) + if (imo == NULL) optval = coptval = IP_DEFAULT_MULTICAST_TTL; else optval = coptval = imo->imo_multicast_ttl; @@ -2118,7 +2108,7 @@ ip_getmoptions(sopt, imo) break; case IP_MULTICAST_LOOP: - if (imo == 0) + if (imo == NULL) optval = coptval = IP_DEFAULT_MULTICAST_LOOP; else optval = coptval = imo->imo_multicast_loop; @@ -2139,8 +2129,7 @@ ip_getmoptions(sopt, imo) * Discard the IP multicast options. */ void -ip_freemoptions(imo) - struct ip_moptions *imo; +ip_freemoptions(struct ip_moptions *imo) { int i; @@ -2168,11 +2157,11 @@ ip_mloopback(ifp, m, dst, hlen) struct ip *ip; struct mbuf *copym; - copym = m_copy(m, 0, M_COPYALL); + copym = m_copypacket(m, MB_DONTWAIT); if (copym != NULL && (copym->m_flags & M_EXT || copym->m_len < hlen)) copym = m_pullup(copym, hlen); if (copym != NULL) { - /* + /* * if the checksum hasn't been computed, mark it as valid */ if (copym->m_pkthdr.csum_flags & CSUM_DELAY_DATA) { diff --git a/sys/netinet/ip_var.h b/sys/netinet/ip_var.h index ea931f998e..134b1b8a27 100644 --- a/sys/netinet/ip_var.h +++ b/sys/netinet/ip_var.h @@ -32,7 +32,7 @@ * * @(#)ip_var.h 8.2 (Berkeley) 1/9/95 * $FreeBSD: src/sys/netinet/ip_var.h,v 1.50.2.13 2003/08/24 08:24:38 hsu Exp $ - * $DragonFly: src/sys/netinet/ip_var.h,v 1.12 2004/10/20 05:00:36 hsu Exp $ + * $DragonFly: src/sys/netinet/ip_var.h,v 1.13 2004/12/21 02:54:15 hsu Exp $ */ #ifndef _NETINET_IP_VAR_H_ @@ -101,10 +101,10 @@ struct ip_moptions { #ifdef _KERNEL #if defined(SMP) -#define _GD mycpu -#define ipstat ipstats_ary[_GD->gd_cpuid] +#define _GD mycpu +#define ipstat ipstats_ary[_GD->gd_cpuid] #else /* !SMP */ -#define ipstat ipstats_ary[0] +#define ipstat ipstats_ary[0] #endif struct ip_stats; diff --git a/sys/netinet/tcp.h b/sys/netinet/tcp.h index 1f05878d3f..d2c04eda4b 100644 --- a/sys/netinet/tcp.h +++ b/sys/netinet/tcp.h @@ -32,7 +32,7 @@ * * @(#)tcp.h 8.1 (Berkeley) 6/10/93 * $FreeBSD: src/sys/netinet/tcp.h,v 1.13.2.3 2001/03/01 22:08:42 jlemon Exp $ - * $DragonFly: src/sys/netinet/tcp.h,v 1.4 2004/11/14 00:49:08 hsu Exp $ + * $DragonFly: src/sys/netinet/tcp.h,v 1.5 2004/12/21 02:54:15 hsu Exp $ */ #ifndef _NETINET_TCP_H_ @@ -130,7 +130,7 @@ struct tcphdr { #define TCP_MAX_WINSHIFT 14 /* maximum window shift */ -#define TCP_MAXBURST 4 /* maximum segments in a burst */ +#define TCP_MAXBURST 4 /* maximum segments in a burst */ #define TCP_MAXHLEN (0xf<<2) /* max length of header in bytes */ #define TCP_MAXOLEN (TCP_MAXHLEN - sizeof(struct tcphdr)) diff --git a/sys/netinet/tcp_debug.h b/sys/netinet/tcp_debug.h index ab56fb43bf..63eb3d7d26 100644 --- a/sys/netinet/tcp_debug.h +++ b/sys/netinet/tcp_debug.h @@ -32,7 +32,7 @@ * * @(#)tcp_debug.h 8.1 (Berkeley) 6/10/93 * $FreeBSD: src/sys/netinet/tcp_debug.h,v 1.11 2000/01/29 11:49:05 shin Exp $ - * $DragonFly: src/sys/netinet/tcp_debug.h,v 1.2 2003/06/17 04:28:51 dillon Exp $ + * $DragonFly: src/sys/netinet/tcp_debug.h,v 1.3 2004/12/21 02:54:15 hsu Exp $ */ #ifndef _NETINET_TCP_DEBUG_H_ @@ -62,7 +62,7 @@ struct tcp_debug { struct tcpcb td_cb; }; -#define TA_INPUT 0 +#define TA_INPUT 0 #define TA_OUTPUT 1 #define TA_USER 2 #define TA_RESPOND 3 diff --git a/sys/netinet/tcp_input.c b/sys/netinet/tcp_input.c index 99965f3401..a8dad662f2 100644 --- a/sys/netinet/tcp_input.c +++ b/sys/netinet/tcp_input.c @@ -82,7 +82,7 @@ * * @(#)tcp_input.c 8.12 (Berkeley) 5/24/95 * $FreeBSD: src/sys/netinet/tcp_input.c,v 1.107.2.38 2003/05/21 04:46:41 cjc Exp $ - * $DragonFly: src/sys/netinet/tcp_input.c,v 1.45 2004/12/08 23:59:01 hsu Exp $ + * $DragonFly: src/sys/netinet/tcp_input.c,v 1.46 2004/12/21 02:54:15 hsu Exp $ */ #include "opt_ipfw.h" /* for ipfw_fwd */ @@ -494,7 +494,7 @@ tcp6_input(struct mbuf **mp, int *offp, int proto) ip6 = mtod(m, struct ip6_hdr *); icmp6_error(m, ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_ADDR, - (caddr_t)&ip6->ip6_dst - (caddr_t)ip6); + offsetof(struct ip6_hdr, ip6_dst)); return (IPPROTO_DONE); } @@ -1225,7 +1225,7 @@ after_listen: sowwakeup(so); if (so->so_snd.sb_cc) - (void) tcp_output(tp); + tcp_output(tp); return; } } else if (tiwin == tp->snd_wnd && @@ -1847,7 +1847,7 @@ trimthenstep6: * later; if not, do so now to pass queued data to user. */ if (tlen == 0 && !(thflags & TH_FIN)) - (void) tcp_reass(tp, NULL, NULL, NULL); + tcp_reass(tp, NULL, NULL, NULL); /* fall into ... */ /* @@ -1906,7 +1906,7 @@ trimthenstep6: * packets in the network. */ tp->snd_cwnd += tp->t_maxseg; - (void) tcp_output(tp); + tcp_output(tp); } } else if (SEQ_LT(th->th_ack, tp->snd_recover)) { tp->t_dupacks = 0; @@ -1940,7 +1940,7 @@ fastretransmit: old_snd_nxt = tp->snd_nxt; tp->snd_nxt = th->th_ack; tp->snd_cwnd = tp->t_maxseg; - (void) tcp_output(tp); + tcp_output(tp); ++tcpstat.tcps_sndfastrexmit; tp->snd_cwnd = tp->snd_ssthresh; tp->rexmt_high = tp->snd_nxt; @@ -1970,7 +1970,7 @@ fastretransmit: tp->snd_cwnd = ownd + (tp->t_dupacks - tp->snd_limited) * tp->t_maxseg; - (void) tcp_output(tp); + tcp_output(tp); tp->snd_cwnd = oldcwnd; sent = tp->snd_max - oldsndmax; if (sent > tp->t_maxseg) { @@ -1993,9 +1993,9 @@ fastretransmit: tp->t_dupacks + 1 >= iceildiv(ownd, tp->t_maxseg) && (!TCP_DO_SACK(tp) || - ownd <= tp->t_maxseg || + ownd <= tp->t_maxseg || tcp_sack_has_sacked(&tp->scb, - ownd - tp->t_maxseg))) { + ownd - tp->t_maxseg))) { ++tcpstat.tcps_sndearlyrexmit; tp->t_flags |= TF_EARLYREXMT; goto fastretransmit; @@ -2488,15 +2488,14 @@ dodata: /* XXX */ #ifdef TCPDEBUG if (so->so_options & SO_DEBUG) - tcp_trace(TA_INPUT, ostate, tp, (void *)tcp_saveipgen, - &tcp_savetcp, 0); + tcp_trace(TA_INPUT, ostate, tp, tcp_saveipgen, &tcp_savetcp, 0); #endif /* * Return any desired output. */ if (needoutput || (tp->t_flags & TF_ACKNOW)) - (void) tcp_output(tp); + tcp_output(tp); return; dropafterack: @@ -2523,12 +2522,11 @@ dropafterack: } #ifdef TCPDEBUG if (so->so_options & SO_DEBUG) - tcp_trace(TA_DROP, ostate, tp, (void *)tcp_saveipgen, - &tcp_savetcp, 0); + tcp_trace(TA_DROP, ostate, tp, tcp_saveipgen, &tcp_savetcp, 0); #endif m_freem(m); tp->t_flags |= TF_ACKNOW; - (void) tcp_output(tp); + tcp_output(tp); return; dropwithreset: @@ -2562,8 +2560,7 @@ dropwithreset: #ifdef TCPDEBUG if (tp == NULL || (tp->t_inpcb->inp_socket->so_options & SO_DEBUG)) - tcp_trace(TA_DROP, ostate, tp, (void *)tcp_saveipgen, - &tcp_savetcp, 0); + tcp_trace(TA_DROP, ostate, tp, tcp_saveipgen, &tcp_savetcp, 0); #endif if (thflags & TH_ACK) /* mtod() below is safe as long as hdr dropping is delayed */ @@ -2584,8 +2581,7 @@ drop: */ #ifdef TCPDEBUG if (tp == NULL || (tp->t_inpcb->inp_socket->so_options & SO_DEBUG)) - tcp_trace(TA_DROP, ostate, tp, (void *)tcp_saveipgen, - &tcp_savetcp, 0); + tcp_trace(TA_DROP, ostate, tp, tcp_saveipgen, &tcp_savetcp, 0); #endif m_freem(m); return; @@ -2981,7 +2977,7 @@ tcp_mss(struct tcpcb *tp, int offer) if (bufsize > sb_max) bufsize = sb_max; if (bufsize > so->so_snd.sb_hiwat) - (void)sbreserve(&so->so_snd, bufsize, so, NULL); + sbreserve(&so->so_snd, bufsize, so, NULL); } tp->t_maxseg = mss; @@ -2994,7 +2990,7 @@ tcp_mss(struct tcpcb *tp, int offer) if (bufsize > sb_max) bufsize = sb_max; if (bufsize > so->so_rcv.sb_hiwat) - (void)sbreserve(&so->so_rcv, bufsize, so, NULL); + sbreserve(&so->so_rcv, bufsize, so, NULL); } /* @@ -3069,7 +3065,7 @@ tcp_newreno_partial_ack(struct tcpcb *tp, struct tcphdr *th, int acked) /* Set snd_cwnd to one segment beyond acknowledged offset. */ tp->snd_cwnd = tp->t_maxseg; tp->t_flags |= TF_ACKNOW; - (void) tcp_output(tp); + tcp_output(tp); if (SEQ_GT(old_snd_nxt, tp->snd_nxt)) tp->snd_nxt = old_snd_nxt; /* partial window deflation */ diff --git a/sys/netinet/tcp_output.c b/sys/netinet/tcp_output.c index 63c1d633bd..c276be535c 100644 --- a/sys/netinet/tcp_output.c +++ b/sys/netinet/tcp_output.c @@ -1,10 +1,10 @@ /* * Copyright (c) 2004 Jeffrey M. Hsu. All rights reserved. * Copyright (c) 2004 The DragonFly Project. All rights reserved. - * + * * This code is derived from software contributed to The DragonFly Project * by Jeffrey M. Hsu. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -16,7 +16,7 @@ * 3. Neither the name of The DragonFly Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific, prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS @@ -82,7 +82,7 @@ * * @(#)tcp_output.c 8.4 (Berkeley) 5/24/95 * $FreeBSD: src/sys/netinet/tcp_output.c,v 1.39.2.20 2003/01/29 22:45:36 hsu Exp $ - * $DragonFly: src/sys/netinet/tcp_output.c,v 1.20 2004/11/14 00:49:08 hsu Exp $ + * $DragonFly: src/sys/netinet/tcp_output.c,v 1.21 2004/12/21 02:54:15 hsu Exp $ */ #include "opt_inet6.h" @@ -398,7 +398,7 @@ again: * It is unclear why we would need to do a pure window update * past 2 segments if we are going to do one at 1/2 the high * water mark anyway, especially since under normal conditions - * the user program will drain the socket buffer quickly. + * the user program will drain the socket buffer quickly. * The 2-segment pure window update will often add a large * number of extra, unnecessary acks to the stream. * @@ -486,7 +486,7 @@ send: opt[0] = TCPOPT_MAXSEG; opt[1] = TCPOLEN_MAXSEG; mss = htons((u_short) tcp_mssopt(tp)); - (void)memcpy(opt + 2, &mss, sizeof(mss)); + memcpy(opt + 2, &mss, sizeof mss); optlen = TCPOLEN_MAXSEG; if ((tp->t_flags & TF_REQ_SCALE) && @@ -696,7 +696,7 @@ send: } else { m->m_next = m_copy(so->so_snd.sb_mb, off, (int) len); if (m->m_next == NULL) { - (void) m_free(m); + m_free(m); error = ENOBUFS; goto out; } diff --git a/sys/netinet/tcp_seq.h b/sys/netinet/tcp_seq.h index a996a183d6..2daccea10d 100644 --- a/sys/netinet/tcp_seq.h +++ b/sys/netinet/tcp_seq.h @@ -1,10 +1,10 @@ /* * Copyright (c) 2003, 2004 Jeffrey M. Hsu. All rights reserved. * Copyright (c) 2003, 2004 The DragonFly Project. All rights reserved. - * + * * This code is derived from software contributed to The DragonFly Project * by Jeffrey M. Hsu. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -16,7 +16,7 @@ * 3. Neither the name of The DragonFly Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific, prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS @@ -82,7 +82,7 @@ * * @(#)tcp_seq.h 8.3 (Berkeley) 6/21/95 * $FreeBSD: src/sys/netinet/tcp_seq.h,v 1.11.2.7 2003/02/03 02:33:10 hsu Exp $ - * $DragonFly: src/sys/netinet/tcp_seq.h,v 1.6 2004/11/14 00:49:08 hsu Exp $ + * $DragonFly: src/sys/netinet/tcp_seq.h,v 1.7 2004/12/21 02:54:15 hsu Exp $ */ #ifndef _NETINET_TCP_SEQ_H_ diff --git a/sys/netinet/tcp_subr.c b/sys/netinet/tcp_subr.c index 57617efe3e..f9ae62cba7 100644 --- a/sys/netinet/tcp_subr.c +++ b/sys/netinet/tcp_subr.c @@ -1,10 +1,10 @@ /* * Copyright (c) 2003, 2004 Jeffrey M. Hsu. All rights reserved. * Copyright (c) 2003, 2004 The DragonFly Project. All rights reserved. - * + * * This code is derived from software contributed to The DragonFly Project * by Jeffrey M. Hsu. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -16,7 +16,7 @@ * 3. Neither the name of The DragonFly Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific, prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS @@ -82,7 +82,7 @@ * * @(#)tcp_subr.c 8.2 (Berkeley) 5/24/95 * $FreeBSD: src/sys/netinet/tcp_subr.c,v 1.73.2.31 2003/01/24 05:11:34 sam Exp $ - * $DragonFly: src/sys/netinet/tcp_subr.c,v 1.42 2004/12/20 11:03:16 joerg Exp $ + * $DragonFly: src/sys/netinet/tcp_subr.c,v 1.43 2004/12/21 02:54:15 hsu Exp $ */ #include "opt_compat.h" @@ -161,7 +161,7 @@ struct inpcbinfo tcbinfo[MAXCPU]; struct tcpcbackqhead tcpcbackq[MAXCPU]; int tcp_mssdflt = TCP_MSS; -SYSCTL_INT(_net_inet_tcp, TCPCTL_MSSDFLT, mssdflt, CTLFLAG_RW, +SYSCTL_INT(_net_inet_tcp, TCPCTL_MSSDFLT, mssdflt, CTLFLAG_RW, &tcp_mssdflt, 0, "Default TCP Maximum Segment Size"); #ifdef INET6 @@ -172,16 +172,16 @@ SYSCTL_INT(_net_inet_tcp, TCPCTL_V6MSSDFLT, v6mssdflt, CTLFLAG_RW, #if 0 static int tcp_rttdflt = TCPTV_SRTTDFLT / PR_SLOWHZ; -SYSCTL_INT(_net_inet_tcp, TCPCTL_RTTDFLT, rttdflt, CTLFLAG_RW, +SYSCTL_INT(_net_inet_tcp, TCPCTL_RTTDFLT, rttdflt, CTLFLAG_RW, &tcp_rttdflt, 0, "Default maximum TCP Round Trip Time"); #endif int tcp_do_rfc1323 = 1; -SYSCTL_INT(_net_inet_tcp, TCPCTL_DO_RFC1323, rfc1323, CTLFLAG_RW, +SYSCTL_INT(_net_inet_tcp, TCPCTL_DO_RFC1323, rfc1323, CTLFLAG_RW, &tcp_do_rfc1323, 0, "Enable rfc1323 (high performance TCP) extensions"); int tcp_do_rfc1644 = 0; -SYSCTL_INT(_net_inet_tcp, TCPCTL_DO_RFC1644, rfc1644, CTLFLAG_RW, +SYSCTL_INT(_net_inet_tcp, TCPCTL_DO_RFC1644, rfc1644, CTLFLAG_RW, &tcp_do_rfc1644, 0, "Enable rfc1644 (TTCP) extensions"); static int tcp_tcbhashsize = 0; @@ -193,11 +193,11 @@ SYSCTL_INT(_net_inet_tcp, OID_AUTO, do_tcpdrain, CTLFLAG_RW, &do_tcpdrain, 0, "Enable tcp_drain routine for extra help when low on mbufs"); /* XXX JH */ -SYSCTL_INT(_net_inet_tcp, OID_AUTO, pcbcount, CTLFLAG_RD, +SYSCTL_INT(_net_inet_tcp, OID_AUTO, pcbcount, CTLFLAG_RD, &tcbinfo[0].ipi_count, 0, "Number of active PCBs"); static int icmp_may_rst = 1; -SYSCTL_INT(_net_inet_tcp, OID_AUTO, icmp_may_rst, CTLFLAG_RW, &icmp_may_rst, 0, +SYSCTL_INT(_net_inet_tcp, OID_AUTO, icmp_may_rst, CTLFLAG_RW, &icmp_may_rst, 0, "Certain ICMP unreachable messages may abort connections in SYN_SENT"); static int tcp_isn_reseed_interval = 0; @@ -205,8 +205,8 @@ SYSCTL_INT(_net_inet_tcp, OID_AUTO, isn_reseed_interval, CTLFLAG_RW, &tcp_isn_reseed_interval, 0, "Seconds between reseeding of ISN secret"); /* - * TCP bandwidth limiting sysctls. Note that the default lower bound of - * 1024 exists only for debugging. A good production default would be + * TCP bandwidth limiting sysctls. Note that the default lower bound of + * 1024 exists only for debugging. A good production default would be * something like 6100. */ static int tcp_inflight_enable = 0; @@ -244,10 +244,10 @@ sysctl_tcpstats(SYSCTL_HANDLER_ARGS) int cpu, error = 0; for (cpu = 0; cpu < ncpus; ++cpu) { - if ((error = SYSCTL_OUT(req, (void *)&tcpstats_ary[cpu], + if ((error = SYSCTL_OUT(req, &tcpstats_ary[cpu], sizeof(struct tcp_stats)))) break; - if ((error = SYSCTL_IN(req, (void *)&tcpstats_ary[cpu], + if ((error = SYSCTL_IN(req, &tcpstats_ary[cpu], sizeof(struct tcp_stats)))) break; } @@ -383,7 +383,7 @@ tcp_init() void tcpmsg_service_loop(void *dummy) -{ +{ struct netmsg *msg; while ((msg = lwkt_waitport(&curthread->td_msgport, NULL))) { @@ -477,7 +477,7 @@ tcp_maketemplate(struct tcpcb *tp) if ((tmp = mpipe_alloc_nowait(&tcptemp_mpipe)) == NULL) return (NULL); - tcp_fillheaders(tp, (void *)&tmp->tt_ipgen, (void *)&tmp->tt_t); + tcp_fillheaders(tp, &tmp->tt_ipgen, &tmp->tt_t); return (tmp); } @@ -614,7 +614,7 @@ tcp_respond(struct tcpcb *tp, void *ipgen, struct tcphdr *th, struct mbuf *m, tlen - sizeof(struct ip6_hdr)); ip6->ip6_hlim = in6_selecthlim(tp ? tp->t_inpcb : NULL, (ro6 && ro6->ro_rt) ? - ro6->ro_rt->rt_ifp : NULL); + ro6->ro_rt->rt_ifp : NULL); } else { nth->th_sum = in_pseudo(ip->ip_src.s_addr, ip->ip_dst.s_addr, htons((u_short)(tlen - sizeof(struct ip) + ip->ip_p))); @@ -626,15 +626,14 @@ tcp_respond(struct tcpcb *tp, void *ipgen, struct tcphdr *th, struct mbuf *m, tcp_trace(TA_OUTPUT, 0, tp, mtod(m, void *), th, 0); #endif if (isipv6) { - (void)ip6_output(m, NULL, ro6, ipflags, NULL, NULL, - tp ? tp->t_inpcb : NULL); + ip6_output(m, NULL, ro6, ipflags, NULL, NULL, + tp ? tp->t_inpcb : NULL); if ((ro6 == &sro6) && (ro6->ro_rt != NULL)) { RTFREE(ro6->ro_rt); ro6->ro_rt = NULL; } } else { - (void)ip_output(m, NULL, ro, ipflags, NULL, - tp ? tp->t_inpcb : NULL); + ip_output(m, NULL, ro, ipflags, NULL, tp ? tp->t_inpcb : NULL); if ((ro == &sro) && (ro->ro_rt != NULL)) { RTFREE(ro->ro_rt); ro->ro_rt = NULL; @@ -698,7 +697,7 @@ tcp_newtcpcb(struct inpcb *inp) * which may match an IPv4-mapped IPv6 address. */ inp->inp_ip_ttl = ip_defttl; - inp->inp_ppcb = (caddr_t)tp; + inp->inp_ppcb = tp; tcp_sack_tcpcb_init(tp); return (tp); /* XXX */ } @@ -714,7 +713,7 @@ tcp_drop(struct tcpcb *tp, int errno) if (TCPS_HAVERCVDSYN(tp->t_state)) { tp->t_state = TCPS_CLOSED; - (void) tcp_output(tp); + tcp_output(tp); tcpstat.tcps_drops++; } else tcpstat.tcps_conndrops++; @@ -959,7 +958,7 @@ no_valid_rt: msg->nm_inp = inp; msg->nm_pcbinfo = &tcbinfo[cpu]; lwkt_sendmsg(tcp_cport(cpu), &msg->nm_lmsg); - } else + } else #endif { /* note: detach removes any wildcard hash entry */ @@ -1083,7 +1082,7 @@ tcp_notify(struct inpcb *inp, int error) else tp->t_softerror = error; #if 0 - wakeup((caddr_t) &so->so_timeo); + wakeup(&so->so_timeo); sorwakeup(so); sowwakeup(so); #endif @@ -1123,7 +1122,7 @@ tcp_pcblist(SYSCTL_HANDLER_ARGS) /* * OK, now we're committed to doing something. Run the inpcb list - * for each cpu in the system and construct the output. Use a + * for each cpu in the system and construct the output. Use a * list placemarker to deal with list changes occuring during * copyout blockages (but otherwise depend on being on the correct * cpu to avoid races). @@ -1182,7 +1181,7 @@ tcp_pcblist(SYSCTL_HANDLER_ARGS) bzero(&xt, sizeof(xt)); xt.xt_len = sizeof(xt); while (i < n) { - error = SYSCTL_OUT(req, &xt, sizeof (xt)); + error = SYSCTL_OUT(req, &xt, sizeof xt); if (error) break; ++i; @@ -1623,12 +1622,9 @@ tcp_mtudisc(struct inpcb *inp, int errno) struct rtentry * tcp_rtlookup(struct in_conninfo *inc) { - struct route *ro; - struct rtentry *rt; + struct route *ro = &inc->inc_route; - ro = &inc->inc_route; - rt = ro->ro_rt; - if (rt == NULL || !(rt->rt_flags & RTF_UP)) { + if (ro->ro_rt == NULL || !(ro->ro_rt->rt_flags & RTF_UP)) { /* No route yet, so try to acquire one */ if (inc->inc_faddr.s_addr != INADDR_ANY) { /* @@ -1641,22 +1637,18 @@ tcp_rtlookup(struct in_conninfo *inc) ((struct sockaddr_in *) &ro->ro_dst)->sin_addr = inc->inc_faddr; rtalloc(ro); - rt = ro->ro_rt; } } - return (rt); + return (ro->ro_rt); } #ifdef INET6 struct rtentry * tcp_rtlookup6(struct in_conninfo *inc) { - struct route_in6 *ro6; - struct rtentry *rt; + struct route_in6 *ro6 = &inc->inc6_route; - ro6 = &inc->inc6_route; - rt = ro6->ro_rt; - if (rt == NULL || !(rt->rt_flags & RTF_UP)) { + if (ro6->ro_rt == NULL || !(ro6->ro_rt->rt_flags & RTF_UP)) { /* No route yet, so try to acquire one */ if (!IN6_IS_ADDR_UNSPECIFIED(&inc->inc6_faddr)) { /* @@ -1668,10 +1660,9 @@ tcp_rtlookup6(struct in_conninfo *inc) ro6->ro_dst.sin6_len = sizeof(struct sockaddr_in6); ro6->ro_dst.sin6_addr = inc->inc6_faddr; rtalloc((struct route *)ro6); - rt = ro6->ro_rt; } } - return (rt); + return (ro6->ro_rt); } #endif @@ -1767,13 +1758,13 @@ tcp_cleartaocache() * side of the connection. * * BACKGROUND: TCP makes no provision for the management of buffer space - * at the end points or at the intermediate routers and switches. A TCP + * at the end points or at the intermediate routers and switches. A TCP * stream, whether using NewReno or not, will eventually buffer as * many packets as it is able and the only reason this typically works is * due to the fairly small default buffers made available for a connection * (typicaly 16K or 32K). As machines use larger windows and/or window * scaling it is now fairly easy for even a single TCP connection to blow-out - * all available buffer space not only on the local interface, but on + * all available buffer space not only on the local interface, but on * intermediate routers and switches as well. NewReno makes a misguided * attempt to 'solve' this problem by waiting for an actual failure to occur, * then backing off, then steadily increasing the window again until another @@ -1795,7 +1786,7 @@ tcp_cleartaocache() * * The second method is to limit the window to the bandwidth delay product * of the link. This is the method we implement. RTT variances and our - * own manipulation of the congestion window, bwnd, can potentially + * own manipulation of the congestion window, bwnd, can potentially * destabilize the algorithm. For this reason we have to stabilize the * elements used to calculate the window. We do this by using the minimum * observed RTT, the long term average of the observed bandwidth, and @@ -1867,7 +1858,7 @@ tcp_xmit_bandwidth_limit(struct tcpcb *tp, tcp_seq ack_seq) * Situations Handled: * (1) Prevents over-queueing of packets on LANs, especially on * high speed LANs, allowing larger TCP buffers to be - * specified, and also does a good job preventing + * specified, and also does a good job preventing * over-queueing of packets over choke points like modems * (at least for the transmit side). * @@ -1879,7 +1870,7 @@ tcp_xmit_bandwidth_limit(struct tcpcb *tp, tcp_seq ack_seq) * connections implementing the same algorithm (this may need * a little work). * - * (4) Stability value (defaults to 20 = 2 maximal packets) can + * (4) Stability value (defaults to 20 = 2 maximal packets) can * be adjusted with a sysctl but typically only needs to be on * very slow connections. A value no smaller then 5 should * be used, but only reduce this default if you have no other diff --git a/sys/netinet/tcp_syncache.c b/sys/netinet/tcp_syncache.c index f9eb2246af..6bdfd879d7 100644 --- a/sys/netinet/tcp_syncache.c +++ b/sys/netinet/tcp_syncache.c @@ -1,10 +1,10 @@ /* * Copyright (c) 2003, 2004 Jeffrey M. Hsu. All rights reserved. * Copyright (c) 2003, 2004 The DragonFly Project. All rights reserved. - * + * * This code is derived from software contributed to The DragonFly Project * by Jeffrey M. Hsu. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -16,7 +16,7 @@ * 3. Neither the name of The DragonFly Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific, prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS @@ -86,7 +86,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/netinet/tcp_syncache.c,v 1.5.2.14 2003/02/24 04:02:27 silby Exp $ - * $DragonFly: src/sys/netinet/tcp_syncache.c,v 1.19 2004/11/14 00:49:08 hsu Exp $ + * $DragonFly: src/sys/netinet/tcp_syncache.c,v 1.20 2004/12/21 02:54:15 hsu Exp $ */ #include "opt_inet6.h" @@ -151,7 +151,7 @@ static int tcp_syncookies = 1; SYSCTL_INT(_net_inet_tcp, OID_AUTO, syncookies, CTLFLAG_RW, - &tcp_syncookies, 0, + &tcp_syncookies, 0, "Use TCP SYN cookies if the syncache overflows"); static void syncache_drop(struct syncache *, struct syncache_head *); @@ -159,7 +159,7 @@ static void syncache_free(struct syncache *); static void syncache_insert(struct syncache *, struct syncache_head *); struct syncache *syncache_lookup(struct in_conninfo *, struct syncache_head **); static int syncache_respond(struct syncache *, struct mbuf *); -static struct socket *syncache_socket(struct syncache *, struct socket *); +static struct socket *syncache_socket(struct syncache *, struct socket *); static void syncache_timer(void *); static u_int32_t syncookie_generate(struct syncache *); static struct syncache *syncookie_lookup(struct in_conninfo *, @@ -233,16 +233,16 @@ SYSCTL_INT(_net_inet_tcp_syncache, OID_AUTO, rexmtlimit, CTLFLAG_RW, static MALLOC_DEFINE(M_SYNCACHE, "syncache", "TCP syncache"); -#define SYNCACHE_HASH(inc, mask) \ +#define SYNCACHE_HASH(inc, mask) \ ((tcp_syncache.hash_secret ^ \ (inc)->inc_faddr.s_addr ^ \ - ((inc)->inc_faddr.s_addr >> 16) ^ \ + ((inc)->inc_faddr.s_addr >> 16) ^ \ (inc)->inc_fport ^ (inc)->inc_lport) & mask) -#define SYNCACHE_HASH6(inc, mask) \ +#define SYNCACHE_HASH6(inc, mask) \ ((tcp_syncache.hash_secret ^ \ - (inc)->inc6_faddr.s6_addr32[0] ^ \ - (inc)->inc6_faddr.s6_addr32[3] ^ \ + (inc)->inc6_faddr.s6_addr32[0] ^ \ + (inc)->inc6_faddr.s6_addr32[3] ^ \ (inc)->inc_fport ^ (inc)->inc_lport) & mask) #define ENDPTS_EQ(a, b) ( \ @@ -280,22 +280,21 @@ syncache_free(struct syncache *sc) #endif if (sc->sc_ipopts) - (void) m_free(sc->sc_ipopts); + m_free(sc->sc_ipopts); if (isipv6) rt = sc->sc_route6.ro_rt; else rt = sc->sc_route.ro_rt; if (rt != NULL) { /* - * If this is the only reference to a protocol cloned + * If this is the only reference to a protocol cloned * route, remove it immediately. */ if (rt->rt_flags & RTF_WASCLONED && - (sc->sc_flags & SCF_KEEPROUTE) == 0 && + !(sc->sc_flags & SCF_KEEPROUTE) && rt->rt_refcnt == 1) { - rtrequest(RTM_DELETE, rt_key(rt), - rt->rt_gateway, rt_mask(rt), - rt->rt_flags, NULL); + rtrequest(RTM_DELETE, rt_key(rt), rt->rt_gateway, + rt_mask(rt), rt->rt_flags, NULL); } RTFREE(rt); } @@ -314,16 +313,16 @@ syncache_init(void) tcp_syncache.rexmt_limit = SYNCACHE_MAXREXMTS; tcp_syncache.hash_secret = arc4random(); - TUNABLE_INT_FETCH("net.inet.tcp.syncache.hashsize", + TUNABLE_INT_FETCH("net.inet.tcp.syncache.hashsize", &tcp_syncache.hashsize); - TUNABLE_INT_FETCH("net.inet.tcp.syncache.cachelimit", + TUNABLE_INT_FETCH("net.inet.tcp.syncache.cachelimit", &tcp_syncache.cache_limit); - TUNABLE_INT_FETCH("net.inet.tcp.syncache.bucketlimit", + TUNABLE_INT_FETCH("net.inet.tcp.syncache.bucketlimit", &tcp_syncache.bucket_limit); if (!powerof2(tcp_syncache.hashsize)) { - printf("WARNING: syncache hash size is not a power of 2.\n"); + printf("WARNING: syncache hash size is not a power of 2.\n"); tcp_syncache.hashsize = 512; /* safe default */ - } + } tcp_syncache.hashmask = tcp_syncache.hashsize - 1; lwkt_initport_null_rport(&syncache_null_rport, NULL); @@ -356,7 +355,7 @@ syncache_init(void) syncache_percpu->mrec[i].msg.nm_mrec = &syncache_percpu->mrec[i]; lwkt_initmsg(&syncache_percpu->mrec[i].msg.nm_lmsg, - &syncache_null_rport, 0, + &syncache_null_rport, 0, lwkt_cmd_func(syncache_timer_handler), lwkt_cmd_op_none); } @@ -500,7 +499,7 @@ syncache_timer_handler(lwkt_msg_t msg) slot = ((struct netmsg_sc_timer *)msg)->nm_mrec->slot; syncache_percpu = &tcp_syncache_percpu[mycpu->gd_cpuid]; - nsc = TAILQ_FIRST(&syncache_percpu->timerq[slot]); + nsc = TAILQ_FIRST(&syncache_percpu->timerq[slot]); while (nsc != NULL) { if (ticks < nsc->sc_rxttime) break; /* finished because timerq sorted by time */ @@ -519,7 +518,7 @@ syncache_timer_handler(lwkt_msg_t msg) * to modify another entry, so do not obtain the next * entry on the timer chain until it has completed. */ - (void) syncache_respond(sc, NULL); + syncache_respond(sc, NULL); nsc = TAILQ_NEXT(sc, sc_timerq); tcpstat.tcps_sc_retransmitted++; TAILQ_REMOVE(&syncache_percpu->timerq[slot], sc, sc_timerq); @@ -714,7 +713,7 @@ syncache_socket(sc, lso) */ if (isipv6) inp->in6p_laddr = in6addr_any; - else + else inp->inp_laddr.s_addr = INADDR_ANY; inp->inp_lport = 0; goto abort; @@ -734,7 +733,7 @@ syncache_socket(sc, lso) * copied, since it stores previously received options and is * used to detect if each new option is different than the * previous one and hence should be passed to a user. - * If we copied in6p_inputopts, a user would not be able to + * If we copied in6p_inputopts, a user would not be able to * receive options just after calling the accept system call. */ inp->inp_flags |= oinp->inp_flags & INP_CONTROLOPTS; @@ -825,7 +824,7 @@ syncache_socket(sc, lso) * If the SYN,ACK was retransmitted, reset cwnd to 1 segment. */ if (sc->sc_rxtslot != 0) - tp->snd_cwnd = tp->t_maxseg; + tp->snd_cwnd = tp->t_maxseg; callout_reset(tp->tt_keep, tcp_keepinit, tcp_timer_keep, tp); tcpstat.tcps_accepts++; @@ -833,7 +832,7 @@ syncache_socket(sc, lso) abort: if (so != NULL) - (void) soabort(so); + soabort(so); return (NULL); } @@ -858,11 +857,11 @@ syncache_expand(inc, th, sop, m) sc = syncache_lookup(inc, &sch); if (sc == NULL) { /* - * There is no syncache entry, so see if this ACK is + * There is no syncache entry, so see if this ACK is * a returning syncookie. To do this, first: * A. See if this socket has had a syncache entry dropped in * the past. We don't want to accept a bogus syncookie - * if we've never received a SYN. + * if we've never received a SYN. * B. check that the syncookie is valid. If it is, then * cobble up a fake syncache entry, and return. */ @@ -886,7 +885,7 @@ syncache_expand(inc, th, sop, m) #if 0 resetandabort: /* XXXjlemon check this - is this correct? */ - (void) tcp_respond(NULL, m, m, th, + tcp_respond(NULL, m, m, th, th->th_seq + tlen, (tcp_seq)0, TH_RST | TH_ACK); #endif m_freem(m); /* XXX only needed for above */ @@ -962,7 +961,7 @@ syncache_add(inc, to, th, sop, m) * forget it and use the new one we've been given. */ if (sc->sc_ipopts) - (void) m_free(sc->sc_ipopts); + m_free(sc->sc_ipopts); sc->sc_ipopts = ipopts; } /* @@ -986,7 +985,7 @@ syncache_add(inc, to, th, sop, m) TAILQ_REMOVE(&syncache_percpu->timerq[sc->sc_rxtslot], sc, sc_timerq); syncache_timeout(syncache_percpu, sc, sc->sc_rxtslot); - tcpstat.tcps_sndacks++; + tcpstat.tcps_sndacks++; tcpstat.tcps_sndtotal++; } *sop = NULL; @@ -1093,9 +1092,9 @@ syncache_add(inc, to, th, sop, m) * - otherwise do a normal 3-way handshake. */ taop = tcp_gettaocache(&sc->sc_inc); - if ((to->to_flags & TOF_CC) != 0) { - if (((tp->t_flags & TF_NOPUSH) != 0) && - sc->sc_flags & SCF_CC && + if (to->to_flags & TOF_CC) { + if ((tp->t_flags & TF_NOPUSH) && + sc->sc_flags & SCF_CC && taop != NULL && taop->tao_cc != 0 && CC_GT(to->to_cc, taop->tao_cc)) { sc->sc_rxtslot = 0; @@ -1154,7 +1153,7 @@ syncache_respond(sc, m) if (rt != NULL) mssopt = rt->rt_ifp->if_mtu - (sizeof(struct ip6_hdr) + sizeof(struct tcphdr)); - else + else mssopt = tcp_v6mssdflt; hlen = sizeof(struct ip6_hdr); } else { @@ -1162,7 +1161,7 @@ syncache_respond(sc, m) if (rt != NULL) mssopt = rt->rt_ifp->if_mtu - (sizeof(struct ip) + sizeof(struct tcphdr)); - else + else mssopt = tcp_mssdflt; hlen = sizeof(struct ip); } @@ -1176,7 +1175,7 @@ syncache_respond(sc, m) ((sc->sc_flags & SCF_TIMESTAMP) ? TCPOLEN_TSTAMP_APPA : 0) + ((sc->sc_flags & SCF_CC) ? TCPOLEN_CC_APPA * 2 : 0) + ((sc->sc_flags & SCF_SACK_PERMITTED) ? - TCPOLEN_SACK_PERMITTED_ALIGNED : 0); + TCPOLEN_SACK_PERMITTED_ALIGNED : 0); } tlen = hlen + sizeof(struct tcphdr) + optlen; @@ -1278,9 +1277,9 @@ syncache_respond(sc, m) } /* - * Send CC and CC.echo if we received CC from our peer. - */ - if (sc->sc_flags & SCF_CC) { + * Send CC and CC.echo if we received CC from our peer. + */ + if (sc->sc_flags & SCF_CC) { u_int32_t *lp = (u_int32_t *)(optp); *lp++ = htonl(TCPOPT_CC_HDR(TCPOPT_CC)); @@ -1306,8 +1305,8 @@ no_options: error = ip6_output(m, NULL, ro6, 0, NULL, NULL, sc->sc_tp->t_inpcb); } else { - th->th_sum = in_pseudo(ip->ip_src.s_addr, ip->ip_dst.s_addr, - htons(tlen - hlen + IPPROTO_TCP)); + th->th_sum = in_pseudo(ip->ip_src.s_addr, ip->ip_dst.s_addr, + htons(tlen - hlen + IPPROTO_TCP)); m->m_pkthdr.csum_flags = CSUM_TCP; m->m_pkthdr.csum_data = offsetof(struct tcphdr, th_sum); error = ip_output(m, sc->sc_ipopts, &sc->sc_route, 0, NULL, @@ -1338,7 +1337,7 @@ no_options: #define SYNCOOKIE_NSECRETS (1 << SYNCOOKIE_WNDBITS) #define SYNCOOKIE_TIMEOUT \ (hz * (1 << SYNCOOKIE_WNDBITS) / (1 << SYNCOOKIE_TIMESHIFT)) -#define SYNCOOKIE_DATAMASK ((3 << SYNCOOKIE_WNDBITS) | SYNCOOKIE_WNDMASK) +#define SYNCOOKIE_DATAMASK ((3 << SYNCOOKIE_WNDBITS) | SYNCOOKIE_WNDMASK) static struct { u_int32_t ts_secbits[4]; @@ -1363,9 +1362,9 @@ CTASSERT(sizeof(struct md5_add) == 28); /* * Consider the problem of a recreated (and retransmitted) cookie. If the - * original SYN was accepted, the connection is established. The second - * SYN is inflight, and if it arrives with an ISN that falls within the - * receive window, the connection is killed. + * original SYN was accepted, the connection is established. The second + * SYN is inflight, and if it arrives with an ISN that falls within the + * receive window, the connection is killed. * * However, since cookies have other problems, this may not be worth * worrying about. @@ -1456,7 +1455,7 @@ syncookie_lookup(inc, th, so) MD5Add(add); MD5Final((u_char *)&md5_buffer, &syn_ctx); data ^= md5_buffer[0]; - if ((data & ~SYNCOOKIE_DATAMASK) != 0) + if (data & ~SYNCOOKIE_DATAMASK) return (NULL); data = data >> SYNCOOKIE_WNDBITS; diff --git a/sys/netinet/tcp_timer.c b/sys/netinet/tcp_timer.c index 39b372c296..1ebf966466 100644 --- a/sys/netinet/tcp_timer.c +++ b/sys/netinet/tcp_timer.c @@ -1,10 +1,10 @@ /* * Copyright (c) 2003, 2004 Jeffrey M. Hsu. All rights reserved. * Copyright (c) 2003, 2004 The DragonFly Project. All rights reserved. - * + * * This code is derived from software contributed to The DragonFly Project * by Jeffrey M. Hsu. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -16,7 +16,7 @@ * 3. Neither the name of The DragonFly Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific, prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS @@ -82,7 +82,7 @@ * * @(#)tcp_timer.c 8.2 (Berkeley) 5/24/95 * $FreeBSD: src/sys/netinet/tcp_timer.c,v 1.34.2.14 2003/02/03 02:33:41 hsu Exp $ - * $DragonFly: src/sys/netinet/tcp_timer.c,v 1.12 2004/11/14 00:49:08 hsu Exp $ + * $DragonFly: src/sys/netinet/tcp_timer.c,v 1.13 2004/12/21 02:54:15 hsu Exp $ */ #include "opt_compat.h" @@ -138,7 +138,7 @@ sysctl_msec_to_ticks(SYSCTL_HANDLER_ARGS) return (EINVAL); *(int *)oidp->oid_arg1 = tt; - return (0); + return (0); } int tcp_keepinit; @@ -157,7 +157,7 @@ int tcp_delacktime; SYSCTL_PROC(_net_inet_tcp, TCPCTL_DELACKTIME, delacktime, CTLTYPE_INT|CTLFLAG_RW, &tcp_delacktime, 0, sysctl_msec_to_ticks, "I", "Time before a delayed ACK is sent"); - + int tcp_msl; SYSCTL_PROC(_net_inet_tcp, OID_AUTO, msl, CTLTYPE_INT|CTLFLAG_RW, &tcp_msl, 0, sysctl_msec_to_ticks, "I", "Maximum segment lifetime"); @@ -171,7 +171,7 @@ SYSCTL_PROC(_net_inet_tcp, OID_AUTO, rexmit_slop, CTLTYPE_INT|CTLFLAG_RW, &tcp_rexmit_slop, 0, sysctl_msec_to_ticks, "I", "Retransmission Timer Slop"); static int always_keepalive = 0; -SYSCTL_INT(_net_inet_tcp, OID_AUTO, always_keepalive, CTLFLAG_RW, +SYSCTL_INT(_net_inet_tcp, OID_AUTO, always_keepalive, CTLFLAG_RW, &always_keepalive , 0, "Assume SO_KEEPALIVE on all TCP connections"); static int tcp_keepcnt = TCPTV_KEEPCNT; @@ -235,7 +235,7 @@ tcp_timer_delack(void *xtp) tp->t_flags |= TF_ACKNOW; tcpstat.tcps_delack++; - (void) tcp_output(tp); + tcp_output(tp); splx(s); } @@ -270,8 +270,7 @@ tcp_timer_2msl(void *xtp) #ifdef TCPDEBUG if (tp && (tp->t_inpcb->inp_socket->so_options & SO_DEBUG)) - tcp_trace(TA_USER, ostate, tp, (void *)0, (struct tcphdr *)0, - PRU_SLOWTIMO); + tcp_trace(TA_USER, ostate, tp, NULL, NULL, PRU_SLOWTIMO); #endif splx(s); } @@ -331,8 +330,7 @@ tcp_timer_keep(void *xtp) #ifdef TCPDEBUG if (tp->t_inpcb->inp_socket->so_options & SO_DEBUG) - tcp_trace(TA_USER, ostate, tp, (void *)0, (struct tcphdr *)0, - PRU_SLOWTIMO); + tcp_trace(TA_USER, ostate, tp, NULL, NULL, PRU_SLOWTIMO); #endif splx(s); return; @@ -343,8 +341,7 @@ dropit: #ifdef TCPDEBUG if (tp && (tp->t_inpcb->inp_socket->so_options & SO_DEBUG)) - tcp_trace(TA_USER, ostate, tp, (void *)0, (struct tcphdr *)0, - PRU_SLOWTIMO); + tcp_trace(TA_USER, ostate, tp, NULL, NULL, PRU_SLOWTIMO); #endif splx(s); } @@ -386,14 +383,13 @@ tcp_timer_persist(void *xtp) } tcp_setpersist(tp); tp->t_flags |= TF_FORCE; - (void) tcp_output(tp); + tcp_output(tp); tp->t_flags &= ~TF_FORCE; out: #ifdef TCPDEBUG if (tp && tp->t_inpcb->inp_socket->so_options & SO_DEBUG) - tcp_trace(TA_USER, ostate, tp, (void *)0, (struct tcphdr *)0, - PRU_SLOWTIMO); + tcp_trace(TA_USER, ostate, tp, NULL, NULL, PRU_SLOWTIMO); #endif splx(s); } @@ -471,10 +467,10 @@ tcp_timer_rexmt(void *xtp) if (tp->t_rxtshift == 1) { /* * first retransmit; record ssthresh and cwnd so they can - * be recovered if this turns out to be a "bad" retransmit. - * A retransmit is considered "bad" if an ACK for this + * be recovered if this turns out to be a "bad" retransmit. + * A retransmit is considered "bad" if an ACK for this * segment is received within RTT/2 interval; the assumption - * here is that the ACK was already in flight. See + * here is that the ACK was already in flight. See * "On Estimating End-to-End Network Path Properties" by * Allman and Paxson for more details. */ @@ -493,9 +489,9 @@ tcp_timer_rexmt(void *xtp) tp->t_rttmin, TCPTV_REXMTMAX); /* * Disable rfc1323 and rfc1644 if we havn't got any response to - * our third SYN to work-around some broken terminal servers - * (most of which have hopefully been retired) that have bad VJ - * header compression code which trashes TCP segments containing + * our third SYN to work-around some broken terminal servers + * (most of which have hopefully been retired) that have bad VJ + * header compression code which trashes TCP segments containing * unknown-to-them TCP options. */ if ((tp->t_state == TCPS_SYN_SENT) && (tp->t_rxtshift == 3)) @@ -562,13 +558,12 @@ tcp_timer_rexmt(void *xtp) tp->t_dupacks = 0; } EXIT_FASTRECOVERY(tp); - (void) tcp_output(tp); + tcp_output(tp); out: #ifdef TCPDEBUG if (tp && (tp->t_inpcb->inp_socket->so_options & SO_DEBUG)) - tcp_trace(TA_USER, ostate, tp, (void *)0, (struct tcphdr *)0, - PRU_SLOWTIMO); + tcp_trace(TA_USER, ostate, tp, NULL, NULL, PRU_SLOWTIMO); #endif splx(s); } diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c index 5381cef64d..412f3678a2 100644 --- a/sys/netinet/tcp_usrreq.c +++ b/sys/netinet/tcp_usrreq.c @@ -1,10 +1,10 @@ /* * Copyright (c) 2003, 2004 Jeffrey M. Hsu. All rights reserved. * Copyright (c) 2003, 2004 The DragonFly Project. All rights reserved. - * + * * This code is derived from software contributed to The DragonFly Project * by Jeffrey M. Hsu. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -16,7 +16,7 @@ * 3. Neither the name of The DragonFly Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific, prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS @@ -82,7 +82,7 @@ * * From: @(#)tcp_usrreq.c 8.2 (Berkeley) 1/3/94 * $FreeBSD: src/sys/netinet/tcp_usrreq.c,v 1.51.2.17 2002/10/11 11:46:44 ume Exp $ - * $DragonFly: src/sys/netinet/tcp_usrreq.c,v 1.30 2004/12/16 03:37:30 dillon Exp $ + * $DragonFly: src/sys/netinet/tcp_usrreq.c,v 1.31 2004/12/21 02:54:15 hsu Exp $ */ #include "opt_ipsec.h" @@ -145,7 +145,7 @@ extern char *tcpstates[]; /* XXX ??? */ static int tcp_attach (struct socket *, struct pru_attach_info *); -static int tcp_connect (struct tcpcb *, struct sockaddr *, +static int tcp_connect (struct tcpcb *, struct sockaddr *, struct thread *); #ifdef INET6 static int tcp6_connect (struct tcpcb *, struct sockaddr *, @@ -243,7 +243,7 @@ tcp_usr_detach(struct socket *so) tp = intotcpcb(inp); \ TCPDEBUG1(); \ } while(0) - + #define COMMON_END(req) out: TCPDEBUG2(req); splx(s); return error; goto out @@ -646,7 +646,7 @@ tcp_usr_rcvd(struct socket *so, int flags) * generally are caller-frees. */ static int -tcp_usr_send(struct socket *so, int flags, struct mbuf *m, +tcp_usr_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *nam, struct mbuf *control, struct thread *td) { int s = splnet(); @@ -763,7 +763,7 @@ tcp_usr_send(struct socket *so, int flags, struct mbuf *m, error = tcp_output(tp); tp->t_flags &= ~TF_FORCE; } - COMMON_END((flags & PRUS_OOB) ? PRU_SENDOOB : + COMMON_END((flags & PRUS_OOB) ? PRU_SENDOOB : ((flags & PRUS_EOF) ? PRU_SEND_EOF : PRU_SEND)); } @@ -845,14 +845,14 @@ tcp_connect_oncpu(struct tcpcb *tp, struct sockaddr_in *sin, oinp = in_pcblookup_hash(&tcbinfo[mycpu->gd_cpuid], sin->sin_addr, sin->sin_port, inp->inp_laddr.s_addr != INADDR_ANY ? - inp->inp_laddr : if_sin->sin_addr, + inp->inp_laddr : if_sin->sin_addr, inp->inp_lport, 0, NULL); if (oinp != NULL) { if (oinp != inp && (otp = intotcpcb(oinp)) != NULL && otp->t_state == TCPS_TIME_WAIT && (ticks - otp->t_starttime) < tcp_msl && (otp->t_flags & TF_RCVD_CC)) - (void) tcp_close(otp); + tcp_close(otp); else return (EADDRINUSE); } @@ -1186,10 +1186,10 @@ tcp_ctloutput(so, sopt) * be set by the route). */ u_long tcp_sendspace = 1024*32; -SYSCTL_INT(_net_inet_tcp, TCPCTL_SENDSPACE, sendspace, CTLFLAG_RW, +SYSCTL_INT(_net_inet_tcp, TCPCTL_SENDSPACE, sendspace, CTLFLAG_RW, &tcp_sendspace , 0, "Maximum outgoing TCP datagram size"); u_long tcp_recvspace = 57344; /* largest multiple of PAGE_SIZE < 64k */ -SYSCTL_INT(_net_inet_tcp, TCPCTL_RECVSPACE, recvspace, CTLFLAG_RW, +SYSCTL_INT(_net_inet_tcp, TCPCTL_RECVSPACE, recvspace, CTLFLAG_RW, &tcp_recvspace , 0, "Maximum incoming TCP datagram size"); /* @@ -1268,7 +1268,7 @@ tcp_disconnect(tp) sbflush(&so->so_rcv); tp = tcp_usrclosed(tp); if (tp) - (void) tcp_output(tp); + tcp_output(tp); } return (tp); } diff --git a/sys/netinet/tcp_var.h b/sys/netinet/tcp_var.h index 624ed013fc..c7ac7a4220 100644 --- a/sys/netinet/tcp_var.h +++ b/sys/netinet/tcp_var.h @@ -1,10 +1,10 @@ /* * Copyright (c) 2003, 2004 Jeffrey M. Hsu. All rights reserved. * Copyright (c) 2003, 2004 The DragonFly Project. All rights reserved. - * + * * This code is derived from software contributed to The DragonFly Project * by Jeffrey M. Hsu. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -16,7 +16,7 @@ * 3. Neither the name of The DragonFly Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific, prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS @@ -82,7 +82,7 @@ * * @(#)tcp_var.h 8.4 (Berkeley) 5/24/95 * $FreeBSD: src/sys/netinet/tcp_var.h,v 1.56.2.13 2003/02/03 02:34:07 hsu Exp $ - * $DragonFly: src/sys/netinet/tcp_var.h,v 1.26 2004/11/14 00:49:08 hsu Exp $ + * $DragonFly: src/sys/netinet/tcp_var.h,v 1.27 2004/12/21 02:54:15 hsu Exp $ */ #ifndef _NETINET_TCP_VAR_H_ @@ -276,14 +276,14 @@ struct tcpcb { #ifdef _KERNEL #if defined(SMP) -#define _GD mycpu +#define _GD mycpu #define tcpstat tcpstats_ary[_GD->gd_cpuid] -#else /* !SMP */ +#else #define tcpstat tcpstats_ary[0] #endif struct tcp_stats; -extern struct tcp_stats tcpstats_ary[MAXCPU]; +extern struct tcp_stats tcpstats_ary[MAXCPU]; static const int tcprexmtthresh = 3; #endif @@ -408,29 +408,29 @@ struct tcpopt { tcp_cc to_cc; /* holds CC or CCnew */ tcp_cc to_ccecho; u_int16_t to_mss; - u_int8_t to_requested_s_scale; - u_int8_t to_pad; + u_int8_t to_requested_s_scale; + u_int8_t to_pad; int to_nsackblocks; struct raw_sackblock *to_sackblocks; }; struct syncache { inp_gen_t sc_inp_gencnt; /* pointer check */ - struct tcpcb *sc_tp; /* tcb for listening socket */ + struct tcpcb *sc_tp; /* tcb for listening socket */ struct mbuf *sc_ipopts; /* source route */ - struct in_conninfo sc_inc; /* addresses */ + struct in_conninfo sc_inc; /* addresses */ #define sc_route sc_inc.inc_route #define sc_route6 sc_inc.inc6_route u_int32_t sc_tsrecent; tcp_cc sc_cc_send; /* holds CC or CCnew */ tcp_cc sc_cc_recv; - tcp_seq sc_irs; /* seq from peer */ - tcp_seq sc_iss; /* our ISS */ + tcp_seq sc_irs; /* seq from peer */ + tcp_seq sc_iss; /* our ISS */ u_long sc_rxttime; /* retransmit time */ - u_int16_t sc_rxtslot; /* retransmit counter */ + u_int16_t sc_rxtslot; /* retransmit counter */ u_int16_t sc_peer_mss; /* peer's MSS */ u_int16_t sc_wnd; /* advertised window */ - u_int8_t sc_requested_s_scale:4, + u_int8_t sc_requested_s_scale:4, sc_request_r_scale:4; u_int8_t sc_flags; #define SCF_NOOPT 0x01 /* no TCP options */ @@ -448,7 +448,7 @@ struct syncache_head { TAILQ_HEAD(, syncache) sch_bucket; u_int sch_length; }; - + /* * The TAO cache entry which is stored in the protocol family specific * portion of the route metrics. @@ -457,14 +457,16 @@ struct rmxp_tao { tcp_cc tao_cc; /* latest CC in valid SYN */ tcp_cc tao_ccsent; /* latest CC sent to peer */ u_short tao_mssopt; /* peer's cached MSS */ + #ifdef notyet u_short tao_flags; /* cache status flags */ #define TAOF_DONT 0x0001 /* peer doesn't understand rfc1644 */ #define TAOF_OK 0x0002 /* peer does understand rfc1644 */ #define TAOF_UNDEF 0 /* we don't know yet */ -#endif /* notyet */ +#endif }; -#define rmx_taop(r) ((struct rmxp_tao *)(r).rmx_filler) + +#define rmx_taop(rt) ((struct rmxp_tao *)(rt).rmx_filler) #define intotcpcb(ip) ((struct tcpcb *)(ip)->inp_ppcb) #define sototcpcb(so) (intotcpcb(sotoinpcb(so))) diff --git a/sys/netinet/tcpip.h b/sys/netinet/tcpip.h index 18a045dc8c..475d7af91b 100644 --- a/sys/netinet/tcpip.h +++ b/sys/netinet/tcpip.h @@ -32,7 +32,7 @@ * * @(#)tcpip.h 8.1 (Berkeley) 6/10/93 * $FreeBSD: src/sys/netinet/tcpip.h,v 1.8 1999/08/28 00:49:34 peter Exp $ - * $DragonFly: src/sys/netinet/tcpip.h,v 1.2 2003/06/17 04:28:51 dillon Exp $ + * $DragonFly: src/sys/netinet/tcpip.h,v 1.3 2004/12/21 02:54:15 hsu Exp $ */ #ifndef _NETINET_TCPIP_H_ @@ -42,7 +42,7 @@ * Tcp+ip header, after ip options removed. */ struct tcpiphdr { - struct ipovly ti_i; /* overlaid ip structure */ + struct ipovly ti_i; /* overlaid ip structure */ struct tcphdr ti_t; /* tcp header */ }; #ifdef notyet @@ -50,7 +50,7 @@ struct tcpiphdr { * Tcp+ip header, after ip options removed but including TCP options. */ struct full_tcpiphdr { - struct ipovly ti_i; /* overlaid ip structure */ + struct ipovly ti_i; /* overlaid ip structure */ struct tcphdr ti_t; /* tcp header */ char ti_o[TCP_MAXOLEN]; /* space for tcp options */ }; diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c index 51f21de3d4..d2d8b5d88d 100644 --- a/sys/netinet/udp_usrreq.c +++ b/sys/netinet/udp_usrreq.c @@ -1,10 +1,10 @@ /* * Copyright (c) 2004 Jeffrey M. Hsu. All rights reserved. * Copyright (c) 2004 The DragonFly Project. All rights reserved. - * + * * This code is derived from software contributed to The DragonFly Project * by Jeffrey M. Hsu. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -16,7 +16,7 @@ * 3. Neither the name of The DragonFly Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific, prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS @@ -82,7 +82,7 @@ * * @(#)udp_usrreq.c 8.6 (Berkeley) 5/23/95 * $FreeBSD: src/sys/netinet/udp_usrreq.c,v 1.64.2.18 2003/01/24 05:11:34 sam Exp $ - * $DragonFly: src/sys/netinet/udp_usrreq.c,v 1.28 2004/12/03 20:29:53 joerg Exp $ + * $DragonFly: src/sys/netinet/udp_usrreq.c,v 1.29 2004/12/21 02:54:15 hsu Exp $ */ #include "opt_ipsec.h" @@ -147,7 +147,7 @@ SYSCTL_INT(_net_inet_udp, UDPCTL_CHECKSUM, checksum, CTLFLAG_RW, &udpcksum, 0, ""); int log_in_vain = 0; -SYSCTL_INT(_net_inet_udp, OID_AUTO, log_in_vain, CTLFLAG_RW, +SYSCTL_INT(_net_inet_udp, OID_AUTO, log_in_vain, CTLFLAG_RW, &log_in_vain, 0, "Log all incoming UDP packets"); static int blackhole = 0; @@ -311,7 +311,7 @@ udp_input(struct mbuf *m, ...) if (m->m_pkthdr.csum_flags & CSUM_PSEUDO_HDR) uh->uh_sum = m->m_pkthdr.csum_data; else - uh->uh_sum = in_pseudo(ip->ip_src.s_addr, + uh->uh_sum = in_pseudo(ip->ip_src.s_addr, ip->ip_dst.s_addr, htonl((u_short)len + m->m_pkthdr.csum_data + IPPROTO_UDP)); uh->uh_sum ^= 0xffff; @@ -403,7 +403,7 @@ udp_input(struct mbuf *m, ...) ; else #endif /*FAST_IPSEC*/ - if ((n = m_copy(m, 0, M_COPYALL)) != NULL) + if ((n = m_copypacket(m, MB_DONTWAIT)) != NULL) udp_append(last, ip, n, iphlen + sizeof(struct udphdr)); @@ -508,7 +508,7 @@ udp_input(struct mbuf *m, ...) #endif ip_savecontrol(inp, &opts, ip, m); } - m_adj(m, iphlen + sizeof(struct udphdr)); + m_adj(m, iphlen + sizeof(struct udphdr)); #ifdef INET6 if (inp->inp_vflag & INP_IPV6) { in6_sin_2_v4mapsin6(&udp_in, &udp_in6.uin6_sin); @@ -623,13 +623,13 @@ udp_ctlinput(cmd, sa, vip) struct ip *ip = vip; struct udphdr *uh; void (*notify) (struct inpcb *, int) = udp_notify; - struct in_addr faddr; + struct in_addr faddr; struct inpcb *inp; int s; faddr = ((struct sockaddr_in *)sa)->sin_addr; if (sa->sa_family != AF_INET || faddr.s_addr == INADDR_ANY) - return; + return; if (PRC_IS_REDIRECT(cmd)) { ip = 0; @@ -642,13 +642,13 @@ udp_ctlinput(cmd, sa, vip) s = splnet(); uh = (struct udphdr *)((caddr_t)ip + (ip->ip_hl << 2)); inp = in_pcblookup_hash(&udbinfo, faddr, uh->uh_dport, - ip->ip_src, uh->uh_sport, 0, NULL); + ip->ip_src, uh->uh_sport, 0, NULL); if (inp != NULL && inp->inp_socket != NULL) (*notify)(inp, inetctlerrmap[cmd]); splx(s); } else in_pcbnotifyall(&udbinfo.pcblisthead, faddr, inetctlerrmap[cmd], - notify); + notify); } SYSCTL_PROC(_net_inet_udp, UDPCTL_PCBLIST, pcblist, CTLFLAG_RD, &udbinfo, 0, @@ -664,7 +664,7 @@ udp_getcred(SYSCTL_HANDLER_ARGS) error = suser(req->td); if (error) return (error); - error = SYSCTL_IN(req, addrs, sizeof(addrs)); + error = SYSCTL_IN(req, addrs, sizeof addrs); if (error) return (error); s = splnet(); @@ -781,7 +781,7 @@ udp_output(inp, m, dstaddr, control, td) * Set up checksum and output datagram. */ if (udpcksum) { - ui->ui_sum = in_pseudo(ui->ui_src.s_addr, ui->ui_dst.s_addr, + ui->ui_sum = in_pseudo(ui->ui_src.s_addr, ui->ui_dst.s_addr, htons((u_short)len + sizeof(struct udphdr) + IPPROTO_UDP)); m->m_pkthdr.csum_flags = CSUM_UDP; m->m_pkthdr.csum_data = offsetof(struct udphdr, uh_sum); @@ -983,9 +983,9 @@ udp_shutdown(struct socket *so) } struct pr_usrreqs udp_usrreqs = { - udp_abort, pru_accept_notsupp, udp_attach, udp_bind, udp_connect, - pru_connect2_notsupp, in_control, udp_detach, udp_disconnect, - pru_listen_notsupp, in_setpeeraddr, pru_rcvd_notsupp, + udp_abort, pru_accept_notsupp, udp_attach, udp_bind, udp_connect, + pru_connect2_notsupp, in_control, udp_detach, udp_disconnect, + pru_listen_notsupp, in_setpeeraddr, pru_rcvd_notsupp, pru_rcvoob_notsupp, udp_send, pru_sense_null, udp_shutdown, in_setsockaddr, sosendudp, soreceive, sopoll }; diff --git a/sys/netinet/udp_var.h b/sys/netinet/udp_var.h index 63f95c9db0..be489b0072 100644 --- a/sys/netinet/udp_var.h +++ b/sys/netinet/udp_var.h @@ -1,10 +1,10 @@ /* * Copyright (c) 2003, 2004 Jeffrey M. Hsu. All rights reserved. * Copyright (c) 2003, 2004 The DragonFly Project. All rights reserved. - * + * * This code is derived from software contributed to The DragonFly Project * by Jeffrey M. Hsu. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -16,7 +16,7 @@ * 3. Neither the name of The DragonFly Project nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific, prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS @@ -82,7 +82,7 @@ * * @(#)udp_var.h 8.1 (Berkeley) 6/10/93 * $FreeBSD: src/sys/netinet/udp_var.h,v 1.22.2.1 2001/02/18 07:12:25 luigi Exp $ - * $DragonFly: src/sys/netinet/udp_var.h,v 1.12 2004/07/08 22:07:35 hsu Exp $ + * $DragonFly: src/sys/netinet/udp_var.h,v 1.13 2004/12/21 02:54:15 hsu Exp $ */ #ifndef _NETINET_UDP_VAR_H_ @@ -92,7 +92,7 @@ * UDP kernel structures and variables. */ struct udpiphdr { - struct ipovly ui_i; /* overlaid ip structure */ + struct ipovly ui_i; /* overlaid ip structure */ struct udphdr ui_u; /* udp header */ }; #define ui_x1 ui_i.ih_x1 diff --git a/sys/netinet6/frag6.c b/sys/netinet6/frag6.c index 0ef0ebc7e5..5c1325d107 100644 --- a/sys/netinet6/frag6.c +++ b/sys/netinet6/frag6.c @@ -1,5 +1,5 @@ /* $FreeBSD: src/sys/netinet6/frag6.c,v 1.2.2.6 2002/04/28 05:40:26 suz Exp $ */ -/* $DragonFly: src/sys/netinet6/frag6.c,v 1.6 2004/06/02 14:43:01 eirikn Exp $ */ +/* $DragonFly: src/sys/netinet6/frag6.c,v 1.7 2004/12/21 02:54:47 hsu Exp $ */ /* $KAME: frag6.c,v 1.33 2002/01/07 11:34:48 kjc Exp $ */ /* @@ -157,11 +157,11 @@ frag6_input(struct mbuf **mp, int *offp, int proto) #ifdef IN6_IFSTAT_STRICT /* find the destination interface of the packet. */ dst = (struct sockaddr_in6 *)&ro.ro_dst; - if (ro.ro_rt - && ((ro.ro_rt->rt_flags & RTF_UP) == 0 - || !IN6_ARE_ADDR_EQUAL(&dst->sin6_addr, &ip6->ip6_dst))) { - RTFREE(ro.ro_rt); - ro.ro_rt = (struct rtentry *)0; + if (ro.ro_rt && + (!(ro.ro_rt->rt_flags & RTF_UP) || + !IN6_ARE_ADDR_EQUAL(&dst->sin6_addr, &ip6->ip6_dst))) { + rtfree(ro.ro_rt); + ro.ro_rt = (struct rtentry *)NULL; } if (ro.ro_rt == NULL) { bzero(dst, sizeof(*dst)); @@ -174,7 +174,7 @@ frag6_input(struct mbuf **mp, int *offp, int proto) dstifp = ((struct in6_ifaddr *)ro.ro_rt->rt_ifa)->ia_ifp; #else /* we are violating the spec, this is not the destination interface */ - if ((m->m_flags & M_PKTHDR) != 0) + if (m->m_flags & M_PKTHDR) dstifp = m->m_pkthdr.rcvif; #endif @@ -662,11 +662,11 @@ frag6_slowtimo(void) */ if (ip6_forward_rt.ro_rt) { RTFREE(ip6_forward_rt.ro_rt); - ip6_forward_rt.ro_rt = 0; + ip6_forward_rt.ro_rt = NULL; } if (ipsrcchk_rt.ro_rt) { RTFREE(ipsrcchk_rt.ro_rt); - ipsrcchk_rt.ro_rt = 0; + ipsrcchk_rt.ro_rt = NULL; } #endif diff --git a/sys/netinet6/icmp6.c b/sys/netinet6/icmp6.c index 9a748caeb4..54598f88c6 100644 --- a/sys/netinet6/icmp6.c +++ b/sys/netinet6/icmp6.c @@ -1,5 +1,5 @@ /* $FreeBSD: src/sys/netinet6/icmp6.c,v 1.6.2.13 2003/05/06 06:46:58 suz Exp $ */ -/* $DragonFly: src/sys/netinet6/icmp6.c,v 1.13 2004/10/15 22:59:10 hsu Exp $ */ +/* $DragonFly: src/sys/netinet6/icmp6.c,v 1.14 2004/12/21 02:54:47 hsu Exp $ */ /* $KAME: icmp6.c,v 1.211 2001/04/04 05:56:20 itojun Exp $ */ /* @@ -1140,13 +1140,11 @@ icmp6_mtudisc_update(struct ip6ctlparam *ip6cp, int validated) htons(m->m_pkthdr.rcvif->if_index); } /* sin6.sin6_scope_id = XXX: should be set if DST is a scoped addr */ - rt = rtalloc1((struct sockaddr *)&sin6, 0, - RTF_CLONING | RTF_PRCLONING); + rt = rtlookup((struct sockaddr *)&sin6, 0, RTF_CLONING | RTF_PRCLONING); - if (rt && (rt->rt_flags & RTF_HOST) - && !(rt->rt_rmx.rmx_locks & RTV_MTU)) { - if (mtu < IPV6_MMTU) { - /* xxx */ + if (rt && (rt->rt_flags & RTF_HOST) && + !(rt->rt_rmx.rmx_locks & RTV_MTU)) { + if (mtu < IPV6_MMTU) { /* XXX */ rt->rt_rmx.rmx_locks |= RTV_MTU; } else if (mtu < rt->rt_ifp->if_mtu && rt->rt_rmx.rmx_mtu > mtu) { @@ -1154,9 +1152,8 @@ icmp6_mtudisc_update(struct ip6ctlparam *ip6cp, int validated) rt->rt_rmx.rmx_mtu = mtu; } } - if (rt) { /* XXX: need braces to avoid conflict with else in RTFREE. */ - RTFREE(rt); - } + if (rt) + --rt->rt_refcnt; } /* @@ -2256,8 +2253,8 @@ icmp6_redirect_input(struct mbuf *m, int off) bzero(&sin6, sizeof(sin6)); sin6.sin6_family = AF_INET6; sin6.sin6_len = sizeof(struct sockaddr_in6); - bcopy(&reddst6, &sin6.sin6_addr, sizeof(reddst6)); - rt = rtalloc1((struct sockaddr *)&sin6, 0, 0UL); + bcopy(&reddst6, &sin6.sin6_addr, sizeof reddst6); + rt = rtlookup((struct sockaddr *)&sin6, 0, 0UL); if (rt) { if (rt->rt_gateway == NULL || rt->rt_gateway->sa_family != AF_INET6) { @@ -2265,7 +2262,7 @@ icmp6_redirect_input(struct mbuf *m, int off) "ICMP6 redirect rejected; no route " "with inet6 gateway found for redirect dst: %s\n", icmp6_redirect_diag(&src6, &reddst6, &redtgt6))); - RTFREE(rt); + --rt->rt_refcnt; goto bad; } @@ -2277,7 +2274,7 @@ icmp6_redirect_input(struct mbuf *m, int off) "%s\n", ip6_sprintf(gw6), icmp6_redirect_diag(&src6, &reddst6, &redtgt6))); - RTFREE(rt); + --rt->rt_refcnt; goto bad; } } else { @@ -2287,7 +2284,7 @@ icmp6_redirect_input(struct mbuf *m, int off) icmp6_redirect_diag(&src6, &reddst6, &redtgt6))); goto bad; } - RTFREE(rt); + --rt->rt_refcnt; rt = NULL; } if (IN6_IS_ADDR_MULTICAST(&reddst6)) { diff --git a/sys/netinet6/in6.c b/sys/netinet6/in6.c index c9889e3513..7a756c8e0f 100644 --- a/sys/netinet6/in6.c +++ b/sys/netinet6/in6.c @@ -1,5 +1,5 @@ /* $FreeBSD: src/sys/netinet6/in6.c,v 1.7.2.9 2002/04/28 05:40:26 suz Exp $ */ -/* $DragonFly: src/sys/netinet6/in6.c,v 1.9 2004/09/10 14:02:01 joerg Exp $ */ +/* $DragonFly: src/sys/netinet6/in6.c,v 1.10 2004/12/21 02:54:47 hsu Exp $ */ /* $KAME: in6.c,v 1.259 2002/01/21 11:37:50 keiichi Exp $ */ /* @@ -223,9 +223,9 @@ in6_ifaddloop(struct ifaddr *ifa) struct rtentry *rt; /* If there is no loopback entry, allocate one. */ - rt = rtalloc1(ifa->ifa_addr, 0, 0); - if (rt == NULL || (rt->rt_flags & RTF_HOST) == 0 || - (rt->rt_ifp->if_flags & IFF_LOOPBACK) == 0) + rt = rtlookup(ifa->ifa_addr, 0, 0); + if (rt == NULL || !(rt->rt_flags & RTF_HOST) || + !(rt->rt_ifp->if_flags & IFF_LOOPBACK)) in6_ifloop_request(RTM_ADD, ifa); if (rt) rt->rt_refcnt--; @@ -275,9 +275,9 @@ in6_ifremloop(struct ifaddr *ifa) * a subnet-router anycast address on an interface attahced * to a shared medium. */ - rt = rtalloc1(ifa->ifa_addr, 0, 0); - if (rt != NULL && (rt->rt_flags & RTF_HOST) != 0 && - (rt->rt_ifp->if_flags & IFF_LOOPBACK) != 0) { + rt = rtlookup(ifa->ifa_addr, 0, 0); + if (rt != NULL && (rt->rt_flags & RTF_HOST) && + (rt->rt_ifp->if_flags & IFF_LOOPBACK)) { rt->rt_refcnt--; in6_ifloop_request(RTM_DELETE, ifa); } diff --git a/sys/netinet6/in6_gif.c b/sys/netinet6/in6_gif.c index 8af7e31f26..365b8ac76d 100644 --- a/sys/netinet6/in6_gif.c +++ b/sys/netinet6/in6_gif.c @@ -1,5 +1,5 @@ /* $FreeBSD: src/sys/netinet6/in6_gif.c,v 1.2.2.7 2003/01/23 21:06:47 sam Exp $ */ -/* $DragonFly: src/sys/netinet6/in6_gif.c,v 1.8 2004/06/03 15:04:51 joerg Exp $ */ +/* $DragonFly: src/sys/netinet6/in6_gif.c,v 1.9 2004/12/21 02:54:47 hsu Exp $ */ /* $KAME: in6_gif.c,v 1.49 2001/05/14 14:02:17 itojun Exp $ */ /* @@ -327,7 +327,7 @@ gif_validate6(const struct ip6_hdr *ip6, struct gif_softc *sc, sin6.sin6_scope_id = 0; /* XXX */ #endif - rt = rtalloc1((struct sockaddr *)&sin6, 0, 0UL); + rt = rtlookup((struct sockaddr *)&sin6, 0, 0UL); if (!rt || rt->rt_ifp != ifp) { #if 0 log(LOG_WARNING, "%s: packet from %s dropped " @@ -335,10 +335,10 @@ gif_validate6(const struct ip6_hdr *ip6, struct gif_softc *sc, ip6_sprintf(&sin6.sin6_addr)); #endif if (rt) - rtfree(rt); + --rt->rt_refcnt; return 0; } - rtfree(rt); + --rt->rt_refcnt; } return 128 * 2; diff --git a/sys/netinet6/in6_ifattach.c b/sys/netinet6/in6_ifattach.c index c8c8428dc0..48b4e25e93 100644 --- a/sys/netinet6/in6_ifattach.c +++ b/sys/netinet6/in6_ifattach.c @@ -1,5 +1,5 @@ /* $FreeBSD: src/sys/netinet6/in6_ifattach.c,v 1.2.2.6 2002/04/28 05:40:26 suz Exp $ */ -/* $DragonFly: src/sys/netinet6/in6_ifattach.c,v 1.8 2004/09/19 22:32:48 joerg Exp $ */ +/* $DragonFly: src/sys/netinet6/in6_ifattach.c,v 1.9 2004/12/21 02:54:47 hsu Exp $ */ /* $KAME: in6_ifattach.c,v 1.118 2001/05/24 07:44:00 itojun Exp $ */ /* @@ -893,10 +893,10 @@ in6_ifdetach(struct ifnet *ifp) ia = (struct in6_ifaddr *)ifa; /* remove from the routing table */ - if ((ia->ia_flags & IFA_ROUTE) - && (rt = rtalloc1((struct sockaddr *)&ia->ia_addr, 0, 0UL))) { + if ((ia->ia_flags & IFA_ROUTE) && + (rt = rtlookup((struct sockaddr *)&ia->ia_addr, 0, 0UL))) { rtflags = rt->rt_flags; - rtfree(rt); + --rt->rt_refcnt; rtrequest(RTM_DELETE, (struct sockaddr *)&ia->ia_addr, (struct sockaddr *)&ia->ia_addr, @@ -954,11 +954,11 @@ in6_ifdetach(struct ifnet *ifp) sin6.sin6_family = AF_INET6; sin6.sin6_addr = in6addr_linklocal_allnodes; sin6.sin6_addr.s6_addr16[1] = htons(ifp->if_index); - rt = rtalloc1((struct sockaddr *)&sin6, 0, 0UL); + rt = rtlookup((struct sockaddr *)&sin6, 0, 0UL); if (rt && rt->rt_ifp == ifp) { + --rt->rt_refcnt; rtrequest(RTM_DELETE, (struct sockaddr *)rt_key(rt), rt->rt_gateway, rt_mask(rt), rt->rt_flags, 0); - rtfree(rt); } } diff --git a/sys/netinet6/in6_pcb.c b/sys/netinet6/in6_pcb.c index 3cabae6c73..a537cc6080 100644 --- a/sys/netinet6/in6_pcb.c +++ b/sys/netinet6/in6_pcb.c @@ -1,5 +1,5 @@ /* $FreeBSD: src/sys/netinet6/in6_pcb.c,v 1.10.2.9 2003/01/24 05:11:35 sam Exp $ */ -/* $DragonFly: src/sys/netinet6/in6_pcb.c,v 1.18 2004/10/15 22:59:10 hsu Exp $ */ +/* $DragonFly: src/sys/netinet6/in6_pcb.c,v 1.19 2004/12/21 02:54:47 hsu Exp $ */ /* $KAME: in6_pcb.c,v 1.31 2001/05/21 05:45:10 jinmei Exp $ */ /* @@ -514,21 +514,20 @@ in6_selectsrc(struct sockaddr_in6 *dstsock, struct ip6_pktopts *opts, if (ro->ro_rt && !IN6_ARE_ADDR_EQUAL(&satosin6(&ro->ro_dst)->sin6_addr, dst)) { RTFREE(ro->ro_rt); - ro->ro_rt = (struct rtentry *)0; + ro->ro_rt = NULL; } - if (ro->ro_rt == (struct rtentry *)0 || - ro->ro_rt->rt_ifp == (struct ifnet *)0) { + if (ro->ro_rt == NULL || ro->ro_rt->rt_ifp == NULL) { struct sockaddr_in6 *dst6; /* No route yet, so try to acquire one */ bzero(&ro->ro_dst, sizeof(struct sockaddr_in6)); - dst6 = (struct sockaddr_in6 *)&ro->ro_dst; + dst6 = &ro->ro_dst; dst6->sin6_family = AF_INET6; dst6->sin6_len = sizeof(struct sockaddr_in6); dst6->sin6_addr = *dst; if (IN6_IS_ADDR_MULTICAST(dst)) { - ro->ro_rt = rtalloc1(&((struct route *)ro) - ->ro_dst, 0, 0UL); + ro->ro_rt = rtlookup( + (struct sockaddr *)&ro->ro_dst, 0, 0UL); } else { rtalloc((struct route *)ro); } diff --git a/sys/netinet6/in6_rmx.c b/sys/netinet6/in6_rmx.c index ad94316c96..05232d90c0 100644 --- a/sys/netinet6/in6_rmx.c +++ b/sys/netinet6/in6_rmx.c @@ -1,5 +1,5 @@ /* $FreeBSD: src/sys/netinet6/in6_rmx.c,v 1.1.2.3 2002/04/28 05:40:27 suz Exp $ */ -/* $DragonFly: src/sys/netinet6/in6_rmx.c,v 1.7 2004/12/14 18:46:08 hsu Exp $ */ +/* $DragonFly: src/sys/netinet6/in6_rmx.c,v 1.8 2004/12/21 02:54:47 hsu Exp $ */ /* $KAME: in6_rmx.c,v 1.11 2001/07/26 06:53:16 jinmei Exp $ */ /* @@ -157,14 +157,16 @@ in6_addroute(char *key, char *mask, struct radix_node_head *head, ret = rn_addroute(key, mask, head, treenodes); if (ret == NULL && rt->rt_flags & RTF_HOST) { struct rtentry *rt2; + /* * We are trying to add a host route, but can't. * Find out if it is because of an * ARP entry and delete it if so. */ - rt2 = rtalloc1((struct sockaddr *)sin6, 0, + rt2 = rtlookup((struct sockaddr *)sin6, 0, RTF_CLONING | RTF_PRCLONING); if (rt2 != NULL) { + --rt2->rt_refcnt; if (rt2->rt_flags & RTF_LLINFO && rt2->rt_flags & RTF_HOST && rt2->rt_gateway && @@ -176,7 +178,6 @@ in6_addroute(char *key, char *mask, struct radix_node_head *head, ret = rn_addroute(key, mask, head, treenodes); } - RTFREE(rt2); } } else if (ret == NULL && rt->rt_flags & RTF_CLONING) { struct rtentry *rt2; @@ -193,7 +194,7 @@ in6_addroute(char *key, char *mask, struct radix_node_head *head, * net route entry, 3ffe:0501:: -> if0. * This case should not raise an error. */ - rt2 = rtalloc1((struct sockaddr *)sin6, 0, + rt2 = rtlookup((struct sockaddr *)sin6, 0, RTF_CLONING | RTF_PRCLONING); if (rt2 != NULL) { if ((rt2->rt_flags & (RTF_CLONING|RTF_HOST|RTF_GATEWAY)) @@ -203,7 +204,7 @@ in6_addroute(char *key, char *mask, struct radix_node_head *head, rt2->rt_ifp == rt->rt_ifp) { ret = rt2->rt_nodes; } - RTFREE(rt2); + --rt2->rt_refcnt; } } return ret; diff --git a/sys/netinet6/in6_src.c b/sys/netinet6/in6_src.c index fd9aab25cf..32b02a7d1d 100644 --- a/sys/netinet6/in6_src.c +++ b/sys/netinet6/in6_src.c @@ -1,5 +1,5 @@ /* $FreeBSD: src/sys/netinet6/in6_src.c,v 1.1.2.3 2002/02/26 18:02:06 ume Exp $ */ -/* $DragonFly: src/sys/netinet6/in6_src.c,v 1.7 2004/05/20 18:30:36 cpressey Exp $ */ +/* $DragonFly: src/sys/netinet6/in6_src.c,v 1.8 2004/12/21 02:54:47 hsu Exp $ */ /* $KAME: in6_src.c,v 1.37 2001/03/29 05:34:31 itojun Exp $ */ /* @@ -241,22 +241,21 @@ in6_selectsrc(struct sockaddr_in6 *dstsock, struct ip6_pktopts *opts, !IN6_ARE_ADDR_EQUAL(&satosin6(&ro->ro_dst)->sin6_addr, dst))) { RTFREE(ro->ro_rt); - ro->ro_rt = (struct rtentry *)0; + ro->ro_rt = NULL; } - if (ro->ro_rt == (struct rtentry *)0 || - ro->ro_rt->rt_ifp == (struct ifnet *)0) { + if (ro->ro_rt == NULL || ro->ro_rt->rt_ifp == NULL) { struct sockaddr_in6 *sa6; /* No route yet, so try to acquire one */ bzero(&ro->ro_dst, sizeof(struct sockaddr_in6)); - sa6 = (struct sockaddr_in6 *)&ro->ro_dst; + sa6 = &ro->ro_dst; sa6->sin6_family = AF_INET6; sa6->sin6_len = sizeof(struct sockaddr_in6); sa6->sin6_addr = *dst; sa6->sin6_scope_id = dstsock->sin6_scope_id; if (IN6_IS_ADDR_MULTICAST(dst)) { - ro->ro_rt = rtalloc1(&((struct route *)ro) - ->ro_dst, 0, 0UL); + ro->ro_rt = rtlookup( + (struct sockaddr *)&ro->ro_dst, 0, 0UL); } else { rtalloc((struct route *)ro); } diff --git a/sys/netinet6/ip6_input.c b/sys/netinet6/ip6_input.c index 919cbb5db3..f88ce32da2 100644 --- a/sys/netinet6/ip6_input.c +++ b/sys/netinet6/ip6_input.c @@ -1,5 +1,5 @@ /* $FreeBSD: src/sys/netinet6/ip6_input.c,v 1.11.2.15 2003/01/24 05:11:35 sam Exp $ */ -/* $DragonFly: src/sys/netinet6/ip6_input.c,v 1.21 2004/10/15 22:59:10 hsu Exp $ */ +/* $DragonFly: src/sys/netinet6/ip6_input.c,v 1.22 2004/12/21 02:54:47 hsu Exp $ */ /* $KAME: ip6_input.c,v 1.259 2002/01/21 04:58:09 jinmei Exp $ */ /* @@ -530,7 +530,7 @@ ip6_input(struct netmsg *msg) } bzero(&ip6_forward_rt.ro_dst, sizeof(struct sockaddr_in6)); - dst6 = (struct sockaddr_in6 *)&ip6_forward_rt.ro_dst; + dst6 = &ip6_forward_rt.ro_dst; dst6->sin6_len = sizeof(struct sockaddr_in6); dst6->sin6_family = AF_INET6; dst6->sin6_addr = ip6->ip6_dst; diff --git a/sys/netinet6/ip6_output.c b/sys/netinet6/ip6_output.c index 7f9f8e2351..fbf4d412ff 100644 --- a/sys/netinet6/ip6_output.c +++ b/sys/netinet6/ip6_output.c @@ -1,5 +1,5 @@ /* $FreeBSD: src/sys/netinet6/ip6_output.c,v 1.13.2.18 2003/01/24 05:11:35 sam Exp $ */ -/* $DragonFly: src/sys/netinet6/ip6_output.c,v 1.14 2004/10/15 22:59:10 hsu Exp $ */ +/* $DragonFly: src/sys/netinet6/ip6_output.c,v 1.15 2004/12/21 02:54:47 hsu Exp $ */ /* $KAME: ip6_output.c,v 1.279 2002/01/26 06:12:30 jinmei Exp $ */ /* @@ -686,11 +686,11 @@ skip_ipsec2:; * ``net'' ff00::/8). */ if (ifp == NULL) { - if (ro->ro_rt == 0) { - ro->ro_rt = rtalloc1((struct sockaddr *) - &ro->ro_dst, 0, 0UL); + if (ro->ro_rt == NULL) { + ro->ro_rt = rtlookup( + (struct sockaddr *)&ro->ro_dst, 0, 0UL); } - if (ro->ro_rt == 0) { + if (ro->ro_rt == NULL) { ip6stat.ip6s_noroute++; error = EHOSTUNREACH; /* XXX in6_ifstat_inc(ifp, ifs6_out_discard) */ @@ -771,6 +771,7 @@ skip_ipsec2:; /* The first hop and the final destination may differ. */ struct sockaddr_in6 *sin6_fin = (struct sockaddr_in6 *)&ro_pmtu->ro_dst; + if (ro_pmtu->ro_rt && ((ro->ro_rt->rt_flags & RTF_UP) == 0 || !IN6_ARE_ADDR_EQUAL(&sin6_fin->sin6_addr, &finaldst))) { diff --git a/sys/netinet6/nd6.c b/sys/netinet6/nd6.c index 0fc6b5ce4d..8e55e18e6a 100644 --- a/sys/netinet6/nd6.c +++ b/sys/netinet6/nd6.c @@ -1,5 +1,5 @@ /* $FreeBSD: src/sys/netinet6/nd6.c,v 1.2.2.15 2003/05/06 06:46:58 suz Exp $ */ -/* $DragonFly: src/sys/netinet6/nd6.c,v 1.11 2004/12/14 18:46:08 hsu Exp $ */ +/* $DragonFly: src/sys/netinet6/nd6.c,v 1.12 2004/12/21 02:54:47 hsu Exp $ */ /* $KAME: nd6.c,v 1.144 2001/05/24 07:44:00 itojun Exp $ */ /* @@ -789,8 +789,8 @@ nd6_lookup(struct in6_addr *addr6, int create, struct ifnet *ifp) #ifdef SCOPEDROUTING sin6.sin6_scope_id = in6_addr2scopeid(ifp, addr6); #endif - rt = rtalloc1((struct sockaddr *)&sin6, create, 0UL); - if (rt && (rt->rt_flags & RTF_LLINFO) == 0) { + rt = rtlookup((struct sockaddr *)&sin6, create, 0UL); + if (rt && !(rt->rt_flags & RTF_LLINFO)) { /* * This is the case for the default route. * If we want to create a neighbor cache for the address, we @@ -798,8 +798,8 @@ nd6_lookup(struct in6_addr *addr6, int create, struct ifnet *ifp) * interface route. */ if (create) { - RTFREE(rt); - rt = 0; + --rt->rt_refcnt; + rt = NULL; } } if (!rt) { @@ -1845,10 +1845,9 @@ nd6_output(struct ifnet *ifp, struct ifnet *origifp, struct mbuf *m0, * next hop determination. This routine is derived from ether_outpout. */ if (rt) { - if ((rt->rt_flags & RTF_UP) == 0) { - if ((rt0 = rt = rtalloc1((struct sockaddr *)dst, 1, 0UL)) != - NULL) - { + if (!(rt->rt_flags & RTF_UP)) { + if ((rt0 = rt = + rtlookup((struct sockaddr *)dst, 1, 0UL))) { rt->rt_refcnt--; if (rt->rt_ifp != ifp) { /* XXX: loop care? */ @@ -1883,12 +1882,13 @@ nd6_output(struct ifnet *ifp, struct ifnet *origifp, struct mbuf *m0, goto sendpkt; } - if (rt->rt_gwroute == 0) + if (rt->rt_gwroute == NULL) goto lookup; - if (((rt = rt->rt_gwroute)->rt_flags & RTF_UP) == 0) { - rtfree(rt); rt = rt0; - lookup: rt->rt_gwroute = rtalloc1(rt->rt_gateway, 1, 0UL); - if ((rt = rt->rt_gwroute) == 0) + if (!(rt->rt_gwroute->rt_flags & RTF_UP)) { + rtfree(rt->rt_gwroute); +lookup: rt->rt_gwroute = rtlookup(rt->rt_gateway, 1, + 0UL); + if (rt->rt_gwroute == NULL) senderr(EHOSTUNREACH); } } @@ -1992,7 +1992,7 @@ nd6_output(struct ifnet *ifp, struct ifnet *origifp, struct mbuf *m0, if (m) m_freem(m); return (error); -} +} #undef senderr int @@ -2024,10 +2024,12 @@ nd6_need_cache(struct ifnet *ifp) } int -nd6_storelladdr(struct ifnet *ifp, struct rtentry *rt, struct mbuf *m, +nd6_storelladdr(struct ifnet *ifp, struct rtentry *rt0, struct mbuf *m, struct sockaddr *dst, u_char *desten) { struct sockaddr_dl *sdl; + struct rtentry *rt; + if (m->m_flags & M_MCAST) { switch (ifp->if_type) { @@ -2053,12 +2055,15 @@ nd6_storelladdr(struct ifnet *ifp, struct rtentry *rt, struct mbuf *m, return(0); } } - - if (rt == NULL) { + if (rt0 == NULL) { /* this could happen, if we could not allocate memory */ m_freem(m); return(0); } + if (rt_llroute(dst, rt0, &rt) != 0) { + m_freem(m); + return (0); + } if (rt->rt_gateway->sa_family != AF_LINK) { printf("nd6_storelladdr: something odd happens\n"); m_freem(m); diff --git a/sys/netinet6/nd6_nbr.c b/sys/netinet6/nd6_nbr.c index deee34b624..0b1cd387cc 100644 --- a/sys/netinet6/nd6_nbr.c +++ b/sys/netinet6/nd6_nbr.c @@ -1,5 +1,5 @@ /* $FreeBSD: src/sys/netinet6/nd6_nbr.c,v 1.4.2.6 2003/01/23 21:06:47 sam Exp $ */ -/* $DragonFly: src/sys/netinet6/nd6_nbr.c,v 1.6 2004/08/02 13:22:33 joerg Exp $ */ +/* $DragonFly: src/sys/netinet6/nd6_nbr.c,v 1.7 2004/12/21 02:54:47 hsu Exp $ */ /* $KAME: nd6_nbr.c,v 1.86 2002/01/21 02:33:04 jinmei Exp $ */ /* @@ -212,8 +212,8 @@ nd6_ns_input(struct mbuf *m, int off, int icmp6len) tsin6.sin6_family = AF_INET6; tsin6.sin6_addr = taddr6; - rt = rtalloc1((struct sockaddr *)&tsin6, 0, 0); - if (rt && (rt->rt_flags & RTF_ANNOUNCE) != 0 && + rt = rtlookup((struct sockaddr *)&tsin6, 0, 0); + if (rt && (rt->rt_flags & RTF_ANNOUNCE) && rt->rt_gateway->sa_family == AF_LINK) { /* * proxy NDP for single entry @@ -226,7 +226,7 @@ nd6_ns_input(struct mbuf *m, int off, int icmp6len) } } if (rt) - rtfree(rt); + --rt->rt_refcnt; } if (!ifa) { /* diff --git a/sys/netinet6/nd6_rtr.c b/sys/netinet6/nd6_rtr.c index da539eacc5..bbf9aab577 100644 --- a/sys/netinet6/nd6_rtr.c +++ b/sys/netinet6/nd6_rtr.c @@ -1,5 +1,5 @@ /* $FreeBSD: src/sys/netinet6/nd6_rtr.c,v 1.2.2.5 2003/04/05 10:28:53 ume Exp $ */ -/* $DragonFly: src/sys/netinet6/nd6_rtr.c,v 1.5 2004/12/14 18:46:08 hsu Exp $ */ +/* $DragonFly: src/sys/netinet6/nd6_rtr.c,v 1.6 2004/12/21 02:54:47 hsu Exp $ */ /* $KAME: nd6_rtr.c,v 1.111 2001/04/27 01:37:15 jinmei Exp $ */ /* @@ -1804,7 +1804,7 @@ in6_tmpifadd(ia0, forcegen) if (ia0->ia6_lifetime.ia6t_preferred != 0) { pltime0 = IFA6_IS_DEPRECATED(ia0) ? 0 : (ia0->ia6_lifetime.ia6t_preferred - time_second); - if (pltime0 > ip6_temp_preferred_lifetime - ip6_desync_factor){ + if (pltime0 > ip6_temp_preferred_lifetime - ip6_desync_factor) { pltime0 = ip6_temp_preferred_lifetime - ip6_desync_factor; } diff --git a/sys/netproto/atalk/aarp.c b/sys/netproto/atalk/aarp.c index 89acb384ec..21b995bedc 100644 --- a/sys/netproto/atalk/aarp.c +++ b/sys/netproto/atalk/aarp.c @@ -3,7 +3,7 @@ * All Rights Reserved. * * $FreeBSD: src/sys/netatalk/aarp.c,v 1.12.2.2 2001/06/23 20:43:09 iedowse Exp $ - * $DragonFly: src/sys/netproto/atalk/aarp.c,v 1.14 2004/09/16 21:55:03 joerg Exp $ + * $DragonFly: src/sys/netproto/atalk/aarp.c,v 1.15 2004/12/21 02:54:48 hsu Exp $ */ #include "opt_atalk.h" @@ -140,8 +140,7 @@ aarpwhohas( struct arpcom *ac, struct sockaddr_at *sat ) ea->aarp_hln = sizeof( ea->aarp_sha ); ea->aarp_pln = sizeof( ea->aarp_spu ); ea->aarp_op = htons( AARPOP_REQUEST ); - bcopy((caddr_t)ac->ac_enaddr, (caddr_t)ea->aarp_sha, - sizeof( ea->aarp_sha )); + bcopy(ac->ac_enaddr, ea->aarp_sha, sizeof ea->aarp_sha); /* * We need to check whether the output ethernet type should @@ -206,49 +205,46 @@ aarpresolve( ac, m, destsat, desten ) struct aarptab *aat; int s; - if ( at_broadcast( destsat )) { + if (at_broadcast(destsat)) { m->m_flags |= M_BCAST; - if ((aa = at_ifawithnet( destsat )) == NULL) { - m_freem( m ); - return( 0 ); + if ((aa = at_ifawithnet(destsat)) == NULL) { + m_freem(m); + return (0); } - if ( aa->aa_flags & AFA_PHASE2 ) { - bcopy( (caddr_t)atmulticastaddr, (caddr_t)desten, - sizeof( atmulticastaddr )); - } else { + if (aa->aa_flags & AFA_PHASE2) + bcopy(atmulticastaddr, desten, sizeof atmulticastaddr); + else bcopy(ac->ac_if.if_broadcastaddr, desten, ac->ac_if.if_addrlen); - } - return( 1 ); + return (1); } s = splimp(); AARPTAB_LOOK( aat, destsat->sat_addr ); - if ( aat == 0 ) { /* No entry */ + if (aat == NULL) { /* No entry */ aat = aarptnew( &destsat->sat_addr ); - if ( aat == 0 ) { - panic( "aarpresolve: no free entry" ); + if (aat == NULL) { + panic("aarpresolve: no free entry"); } aat->aat_hold = m; - aarpwhohas( ac, destsat ); - splx( s ); - return( 0 ); + aarpwhohas(ac, destsat); + splx(s); + return (0); } /* found an entry */ aat->aat_timer = 0; - if ( aat->aat_flags & ATF_COM ) { /* entry is COMplete */ - bcopy( (caddr_t)aat->aat_enaddr, (caddr_t)desten, - sizeof( aat->aat_enaddr )); - splx( s ); - return( 1 ); + if (aat->aat_flags & ATF_COM) { /* entry is COMplete */ + bcopy(aat->aat_enaddr, desten, sizeof aat->aat_enaddr); + splx(s); + return (1); } /* entry has not completed */ - if ( aat->aat_hold ) { - m_freem( aat->aat_hold ); + if (aat->aat_hold) { + m_freem(aat->aat_hold); } aat->aat_hold = m; - aarpwhohas( ac, destsat ); - splx( s ); - return( 0 ); + aarpwhohas(ac, destsat); + splx(s); + return (0); } int @@ -297,7 +293,7 @@ at_aarpinput( struct arpcom *ac, struct mbuf *m) { struct ether_aarp *ea; struct ifaddr *ifa; - struct at_ifaddr *aa; + struct at_ifaddr *aa = NULL; struct aarptab *aat; struct ether_header *eh; struct llc *llc; @@ -316,19 +312,19 @@ at_aarpinput( struct arpcom *ac, struct mbuf *m) return; } - op = ntohs( ea->aarp_op ); - bcopy( ea->aarp_tpnet, &net, sizeof( net )); + op = ntohs(ea->aarp_op); + bcopy(ea->aarp_tpnet, &net, sizeof net); if ( net != 0 ) { /* should be ATADDR_ANYNET? */ sat.sat_len = sizeof(struct sockaddr_at); sat.sat_family = AF_APPLETALK; sat.sat_addr.s_net = net; - if ((aa = at_ifawithnet( &sat )) == NULL) { + if ((aa = at_ifawithnet(&sat)) == NULL) { m_freem( m ); return; } - bcopy( ea->aarp_spnet, &spa.s_net, sizeof( spa.s_net )); - bcopy( ea->aarp_tpnet, &tpa.s_net, sizeof( tpa.s_net )); + bcopy(ea->aarp_spnet, &spa.s_net, sizeof spa.s_net); + bcopy(ea->aarp_tpnet, &tpa.s_net, sizeof tpa.s_net); } else { /* * Since we don't know the net, we just look for the first @@ -521,7 +517,7 @@ aarpprobe( void *arg ) struct ether_header *eh; struct ether_aarp *ea; struct ifaddr *ifa; - struct at_ifaddr *aa; + struct at_ifaddr *aa = NULL; struct llc *llc; struct sockaddr sa;