sync with head. elad-kernelauth
authorelad <elad@NetBSD.org>
Wed, 19 Apr 2006 04:46:10 +0000
branchelad-kernelauth
changeset 288301 7518f42b94c8
parent 288300 a9b70a0c1834
child 288302 060f92cd31a7
sync with head.
sys/miscfs/fdesc/fdesc_vnops.c
sys/miscfs/genfs/genfs_node.h
sys/miscfs/genfs/genfs_vnops.c
sys/miscfs/kernfs/kernfs.h
sys/miscfs/kernfs/kernfs_vnops.c
sys/miscfs/umapfs/umap_vnops.c
sys/net/bridgestp.c
sys/net/if.h
sys/net/if_ether.h
sys/net/if_ethersubr.c
sys/net/if_fddisubr.c
sys/net/if_gif.c
sys/net/if_media.h
sys/net/if_pppoe.c
sys/net/if_tap.c
sys/net/if_tokensubr.c
sys/net/if_tun.c
sys/net/if_tun.h
sys/net/route.c
sys/net/rtsock.c
sys/net/slcompress.c
sys/net/zlib.c
sys/net80211/_ieee80211.h
sys/net80211/ieee80211.c
sys/net80211/ieee80211.h
sys/net80211/ieee80211_acl.c
sys/net80211/ieee80211_crypto_ccmp.c
sys/net80211/ieee80211_crypto_none.c
sys/net80211/ieee80211_crypto_tkip.c
sys/net80211/ieee80211_crypto_wep.c
sys/net80211/ieee80211_input.c
sys/net80211/ieee80211_ioctl.c
sys/net80211/ieee80211_node.c
sys/net80211/ieee80211_radiotap.h
sys/net80211/ieee80211_var.h
sys/netatalk/at_control.c
sys/netatalk/ddp_usrreq.c
sys/netccitt/llc_input.c
sys/netccitt/llc_subr.c
sys/netccitt/llc_timer.c
sys/netccitt/pk_output.c
sys/netinet/icmp6.h
sys/netinet/ip_icmp.c
sys/netinet/ip_input.c
sys/netinet/tcp_input.c
sys/netinet/tcp_output.c
sys/netinet/tcp_subr.c
sys/netinet/tcp_timer.c
sys/netinet/tcp_usrreq.c
sys/netinet6/icmp6.c
sys/netinet6/in6.c
sys/netinet6/in6.h
sys/netinet6/in6_src.c
sys/netinet6/ip6_input.c
sys/netinet6/ip6_output.c
sys/netinet6/nd6.c
sys/netinet6/nd6_rtr.c
sys/netipsec/ipsec.c
sys/netipsec/ipsec.h
sys/netipsec/ipsec_netbsd.c
sys/netipsec/xform_ah.c
sys/netipsec/xform_esp.c
sys/netisdn/i4b_q931.c
sys/netiso/iso_chksum.c
sys/netiso/tp_emit.c
sys/netiso/tp_output.c
sys/netiso/tp_pcb.c
sys/netns/idp_usrreq.c
sys/netns/ns_error.c
sys/netns/spp_usrreq.c
sys/netsmb/smb_iod.c
sys/netsmb/smb_subr.c
--- a/sys/miscfs/fdesc/fdesc_vnops.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/miscfs/fdesc/fdesc_vnops.c	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: fdesc_vnops.c,v 1.90.4.1 2006/03/08 01:34:34 elad Exp $	*/
+/*	$NetBSD: fdesc_vnops.c,v 1.90.4.2 2006/04/19 04:52:46 elad Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -41,7 +41,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fdesc_vnops.c,v 1.90.4.1 2006/03/08 01:34:34 elad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdesc_vnops.c,v 1.90.4.2 2006/04/19 04:52:46 elad Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -786,7 +786,7 @@
 			default:
 				KASSERT(fdp != NULL);
 				j = (int)i - 2;
-				if (fdp->fd_ofiles[j] == NULL ||
+				if (fdp == NULL || fdp->fd_ofiles[j] == NULL ||
 				    FILE_IS_USABLE(fdp->fd_ofiles[j]) == 0)
 					continue;
 				d.d_fileno = j + FD_STDIN;
--- a/sys/miscfs/genfs/genfs_node.h	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/miscfs/genfs/genfs_node.h	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: genfs_node.h,v 1.9.10.1 2006/03/08 01:34:34 elad Exp $ */
+/* $NetBSD: genfs_node.h,v 1.9.10.2 2006/04/19 04:52:46 elad Exp $ */
 
 /*
  * Copyright (c) 2001 Chuck Silvers.
@@ -62,8 +62,6 @@
 	(void)0;
 
 /* Flags to GOP_SIZE */
-#define	GOP_SIZE_READ	0x1	/* Advise how many pages to read */
-#define	GOP_SIZE_WRITE	0x2	/* Tell how many pages to write */
 #define	GOP_SIZE_MEM	0x4	/* in-memory size */
 
 /* Flags to GOP_MARKUPDATE */
--- a/sys/miscfs/genfs/genfs_vnops.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/miscfs/genfs/genfs_vnops.c	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: genfs_vnops.c,v 1.122.4.1 2006/03/08 01:34:34 elad Exp $	*/
+/*	$NetBSD: genfs_vnops.c,v 1.122.4.2 2006/04/19 04:52:46 elad Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: genfs_vnops.c,v 1.122.4.1 2006/03/08 01:34:34 elad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: genfs_vnops.c,v 1.122.4.2 2006/04/19 04:52:46 elad Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_nfsserver.h"
@@ -439,7 +439,7 @@
 	} */ *ap = v;
 
 	off_t newsize, diskeof, memeof;
-	off_t offset, origoffset, startoffset, endoffset, raoffset;
+	off_t offset, origoffset, startoffset, endoffset;
 	daddr_t lbn, blkno;
 	int i, error, npages, orignpages, npgs, run, ridx, pidx, pcount;
 	int fs_bshift, fs_bsize, dev_bshift;
@@ -475,13 +475,13 @@
 	error = 0;
 	origoffset = ap->a_offset;
 	orignpages = *ap->a_count;
-	GOP_SIZE(vp, vp->v_size, &diskeof, GOP_SIZE_READ);
+	GOP_SIZE(vp, vp->v_size, &diskeof, 0);
 	if (flags & PGO_PASTEOF) {
 		newsize = MAX(vp->v_size,
 		    origoffset + (orignpages << PAGE_SHIFT));
-		GOP_SIZE(vp, newsize, &memeof, GOP_SIZE_READ|GOP_SIZE_MEM);
+		GOP_SIZE(vp, newsize, &memeof, GOP_SIZE_MEM);
 	} else {
-		GOP_SIZE(vp, vp->v_size, &memeof, GOP_SIZE_READ|GOP_SIZE_MEM);
+		GOP_SIZE(vp, vp->v_size, &memeof, GOP_SIZE_MEM);
 	}
 	KASSERT(ap->a_centeridx >= 0 || ap->a_centeridx <= orignpages);
 	KASSERT((origoffset & (PAGE_SIZE - 1)) == 0 && origoffset >= 0);
@@ -600,7 +600,6 @@
 	}
 	if (i == npages) {
 		UVMHIST_LOG(ubchist, "returning cached pages", 0,0,0,0);
-		raoffset = origoffset + (orignpages << PAGE_SHIFT);
 		npages += ridx;
 		goto out;
 	}
@@ -609,7 +608,7 @@
 	 * if PGO_OVERWRITE is set, don't bother reading the pages.
 	 */
 
-	if (flags & PGO_OVERWRITE) {
+	if (overwrite) {
 		UVMHIST_LOG(ubchist, "PGO_OVERWRITE",0,0,0,0);
 
 		for (i = 0; i < npages; i++) {
@@ -834,7 +833,6 @@
 	}
 	putiobuf(mbp);
 	uvm_pagermapout(kva, npages);
-	raoffset = startoffset + totalbytes;
 
 	/*
 	 * if this we encountered a hole then we have to do a little more work.
@@ -1426,7 +1424,7 @@
 	UVMHIST_LOG(ubchist, "vp %p pgs %p npages %d flags 0x%x",
 	    vp, pgs, npages, flags);
 
-	GOP_SIZE(vp, vp->v_size, &eof, GOP_SIZE_WRITE);
+	GOP_SIZE(vp, vp->v_size, &eof, 0);
 	if (vp->v_type != VBLK) {
 		fs_bshift = vp->v_mount->mnt_fs_bshift;
 		dev_bshift = vp->v_mount->mnt_dev_bshift;
--- a/sys/miscfs/kernfs/kernfs.h	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/miscfs/kernfs/kernfs.h	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: kernfs.h,v 1.26 2005/12/11 12:24:51 christos Exp $	*/
+/*	$NetBSD: kernfs.h,v 1.26.10.1 2006/04/19 04:52:46 elad Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -144,11 +144,13 @@
  * Data types for the kernfs file operations.
  */
 typedef enum {
+	KERNFS_XREAD,
 	KERNFS_XWRITE,
 	KERNFS_FILEOP_CLOSE,
 	KERNFS_FILEOP_GETATTR,
 	KERNFS_FILEOP_IOCTL,
 	KERNFS_FILEOP_OPEN,
+	KERNFS_FILEOP_READ,
 	KERNFS_FILEOP_WRITE,
 } kfsfileop;
 
@@ -158,6 +160,8 @@
 	union {
 		void			*_kf_genop;
 		int			(*_kf_vop)(void *);
+		int			(*_kf_xread)
+			(const struct kernfs_node *, char *, size_t);
 		int			(*_kf_xwrite)
 			(const struct kernfs_node *, char *, size_t);
 	} _kf_opfn;
@@ -165,6 +169,7 @@
 };
 #define	kf_genop	_kf_opfn
 #define	kf_vop		_kf_opfn._kf_vop
+#define	kf_xread	_kf_opfn._kf_xread
 #define	kf_xwrite	_kf_opfn._kf_xwrite
 
 typedef struct kern_target kernfs_parentdir_t;
--- a/sys/miscfs/kernfs/kernfs_vnops.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/miscfs/kernfs/kernfs_vnops.c	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: kernfs_vnops.c,v 1.117.4.1 2006/03/08 01:34:34 elad Exp $	*/
+/*	$NetBSD: kernfs_vnops.c,v 1.117.4.2 2006/04/19 04:52:46 elad Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -39,7 +39,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kernfs_vnops.c,v 1.117.4.1 2006/03/08 01:34:34 elad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kernfs_vnops.c,v 1.117.4.2 2006/04/19 04:52:46 elad Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ipsec.h"
@@ -151,20 +151,25 @@
 #endif
 
 int kernfs_try_fileop(kfstype, kfsfileop, void *, int);
+int kernfs_try_xread(kfstype, const struct kernfs_node *, char *,
+    size_t, int);
 int kernfs_try_xwrite(kfstype, const struct kernfs_node *, char *,
     size_t, int);
 
+static int kernfs_default_xread(void *v);
 static int kernfs_default_xwrite(void *v);
 static int kernfs_default_fileop_getattr(void *);
 
 /* must include all fileop's */
 const struct kernfs_fileop kernfs_default_fileops[] = {
+  { .kf_fileop = KERNFS_XREAD },
   { .kf_fileop = KERNFS_XWRITE },
   { .kf_fileop = KERNFS_FILEOP_OPEN },
   { .kf_fileop = KERNFS_FILEOP_GETATTR,
     .kf_genop = {kernfs_default_fileop_getattr} },
   { .kf_fileop = KERNFS_FILEOP_IOCTL },
   { .kf_fileop = KERNFS_FILEOP_CLOSE },
+  { .kf_fileop = KERNFS_FILEOP_READ, .kf_genop = {kernfs_default_xread} },
   { .kf_fileop = KERNFS_FILEOP_WRITE, .kf_genop = {kernfs_default_xwrite} },
 };
 
@@ -910,7 +915,7 @@
 }
 
 int
-kernfs_read(v)
+kernfs_default_xread(v)
 	void *v;
 {
 	struct vop_read_args /* {
@@ -940,6 +945,21 @@
 	return (error);
 }
 
+int
+kernfs_read(v)
+	void *v;
+{
+	struct vop_read_args /* {
+		struct vnode *a_vp;
+		struct uio *a_uio;
+		int  a_ioflag;
+		struct ucred *a_cred;
+	} */ *ap = v;
+	struct kernfs_node *kfs = VTOKERN(ap->a_vp);
+
+	return kernfs_try_fileop(kfs->kfs_type, KERNFS_FILEOP_READ, v, 0);
+}
+
 static int
 kernfs_default_xwrite(v)
 	void *v;
@@ -1122,9 +1142,9 @@
 						break;
 				} else {
 					dkt = SIMPLEQ_NEXT(dkt, dkt_queue);
-					if (dkt == NULL)
-						break;
 				}
+				if (dkt == NULL)
+					break;
 				kt = &dkt->dkt_kt;
 			}
 			if (kt->kt_tag == KFSdevice) {
--- a/sys/miscfs/umapfs/umap_vnops.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/miscfs/umapfs/umap_vnops.c	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: umap_vnops.c,v 1.35.10.1 2006/03/08 01:34:34 elad Exp $	*/
+/*	$NetBSD: umap_vnops.c,v 1.35.10.2 2006/04/19 04:52:47 elad Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -39,7 +39,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: umap_vnops.c,v 1.35.10.1 2006/03/08 01:34:34 elad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: umap_vnops.c,v 1.35.10.2 2006/04/19 04:52:47 elad Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -301,7 +301,7 @@
 			printf("umap_bypass: returning-user was %d\n",
 			    kauth_cred_geteuid(credp));
 
-		if (savecredp != NOCRED) {
+		if (savecredp != NOCRED && credpp) {
 			kauth_cred_free(credp);
 			*credpp = savecredp;
 			if ((flags & LAYERFS_MBYPASSDEBUG) && credpp &&
@@ -384,7 +384,7 @@
 		umap_mapids(mp, compcredp);
 	}
 
-	if ((flags & LAYERFS_MBYPASSDEBUG) && kauth_cred_geteuid(compcredp) != 0)
+	if ((flags & LAYERFS_MBYPASSDEBUG) && compcredp && kauth_cred_geteuid(compcredp) != 0)
 		printf("umap_lookup: component credit user now %d, group %d\n",
 		    kauth_cred_geteuid(compcredp), kauth_cred_getegid(compcredp));
 
@@ -426,7 +426,8 @@
 			    kauth_cred_geteuid(compcredp));
 
 	if (savecompcredp != NOCRED) {
-		kauth_cred_free(compcredp);
+		if (compcredp)
+			kauth_cred_free(compcredp);
 		cnp->cn_cred = savecompcredp;
 		if ((flags & LAYERFS_MBYPASSDEBUG) && savecompcredp &&
 				kauth_cred_geteuid(savecompcredp) != 0)
--- a/sys/net/bridgestp.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/net/bridgestp.c	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: bridgestp.c,v 1.7 2005/12/11 12:24:51 christos Exp $	*/
+/*	$NetBSD: bridgestp.c,v 1.7.10.1 2006/04/19 04:46:10 elad Exp $	*/
 
 /*
  * Copyright (c) 2000 Jason L. Wright (jason@thought.net)
@@ -40,7 +40,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bridgestp.c,v 1.7 2005/12/11 12:24:51 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bridgestp.c,v 1.7.10.1 2006/04/19 04:46:10 elad Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -355,11 +355,13 @@
 {
 	struct bstp_tbpdu bpdu;
 	struct bridge_iflist *bif = sc->sc_root_port;
-	struct ifnet *ifp = bif->bif_ifp;
+	struct ifnet *ifp;
 	struct ether_header *eh;
 	struct mbuf *m;
 	int s;
 
+	KASSERT(bif != NULL);
+	ifp = bif->bif_ifp;
 	if ((ifp->if_flags & IFF_RUNNING) == 0)
 		return;
 
--- a/sys/net/if.h	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/net/if.h	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.h,v 1.114 2005/12/11 23:05:24 thorpej Exp $	*/
+/*	$NetBSD: if.h,v 1.114.10.1 2006/04/19 04:46:10 elad Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc.
@@ -776,8 +776,6 @@
 extern struct ifnet *lo0ifp;
 extern size_t if_indexlim;
 
-char	*ether_sprintf(const u_char *);
-
 void	if_alloc_sadl(struct ifnet *);
 void	if_free_sadl(struct ifnet *);
 void	if_attach(struct ifnet *);
--- a/sys/net/if_ether.h	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/net/if_ether.h	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ether.h,v 1.41 2006/01/29 09:57:59 jdolecek Exp $	*/
+/*	$NetBSD: if_ether.h,v 1.41.8.1 2006/04/19 04:46:10 elad Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1993
@@ -280,6 +280,7 @@
 void	ether_ifdetach(struct ifnet *);
 
 char	*ether_sprintf(const u_int8_t *);
+char	*ether_snprintf(char *, size_t, const u_int8_t *);
 
 u_int32_t ether_crc32_le(const u_int8_t *, size_t);
 u_int32_t ether_crc32_be(const u_int8_t *, size_t);
--- a/sys/net/if_ethersubr.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/net/if_ethersubr.c	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ethersubr.c,v 1.128 2005/12/11 23:05:24 thorpej Exp $	*/
+/*	$NetBSD: if_ethersubr.c,v 1.128.10.1 2006/04/19 04:46:10 elad Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.128 2005/12/11 23:05:24 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.128.10.1 2006/04/19 04:46:10 elad Exp $");
 
 #include "opt_inet.h"
 #include "opt_atalk.h"
@@ -422,8 +422,8 @@
 #ifdef	LLC
 /*	case AF_NSAP: */
 	case AF_CCITT: {
-		struct sockaddr_dl *sdl =
-			(struct sockaddr_dl *) rt -> rt_gateway;
+		struct sockaddr_dl *sdl = rt ? 
+			(struct sockaddr_dl *) rt -> rt_gateway : NULL;
 
 		if (sdl && sdl->sdl_family == AF_LINK
 		    && sdl->sdl_alen > 0) {
@@ -1088,17 +1088,24 @@
 char *
 ether_sprintf(const u_char *ap)
 {
-	static char etherbuf[18];
-	char *cp = etherbuf;
-	int i;
+	static char etherbuf[3 * ETHER_ADDR_LEN];
+	return ether_snprintf(etherbuf, sizeof(etherbuf), ap);
+	return etherbuf;
+}
 
-	for (i = 0; i < 6; i++) {
+char *
+ether_snprintf(char *buf, size_t len, const u_char *ap)
+{
+	char *cp = buf;
+	size_t i;
+
+	for (i = 0; i < len / 3; i++) {
 		*cp++ = hexdigits[*ap >> 4];
 		*cp++ = hexdigits[*ap++ & 0xf];
 		*cp++ = ':';
 	}
-	*--cp = 0;
-	return (etherbuf);
+	*--cp = '\0';
+	return buf;
 }
 
 /*
--- a/sys/net/if_fddisubr.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/net/if_fddisubr.c	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_fddisubr.c,v 1.58 2005/12/11 23:05:25 thorpej Exp $	*/
+/*	$NetBSD: if_fddisubr.c,v 1.58.10.1 2006/04/19 04:46:10 elad Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -96,7 +96,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_fddisubr.c,v 1.58 2005/12/11 23:05:25 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_fddisubr.c,v 1.58.10.1 2006/04/19 04:46:10 elad Exp $");
 
 #include "opt_inet.h"
 #include "opt_atalk.h"
@@ -414,8 +414,8 @@
 #ifdef	LLC
 /*	case AF_NSAP: */
 	case AF_CCITT: {
-		struct sockaddr_dl *sdl =
-			(struct sockaddr_dl *) rt->rt_gateway;
+		struct sockaddr_dl *sdl = rt ? 
+			(struct sockaddr_dl *) rt->rt_gateway : NULL;
 
 		if (sdl && sdl->sdl_family == AF_LINK
 		    && sdl->sdl_alen > 0) {
--- a/sys/net/if_gif.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/net/if_gif.c	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_gif.c,v 1.57.10.2 2006/03/10 15:05:22 elad Exp $	*/
+/*	$NetBSD: if_gif.c,v 1.57.10.3 2006/04/19 04:46:10 elad Exp $	*/
 /*	$KAME: if_gif.c,v 1.76 2001/08/20 02:01:02 kjc Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.57.10.2 2006/03/10 15:05:22 elad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.57.10.3 2006/04/19 04:46:10 elad Exp $");
 
 #include "opt_inet.h"
 #include "opt_iso.h"
@@ -847,6 +847,13 @@
 		/* XXX both end must be valid? (I mean, not 0.0.0.0) */
 	}
 
+#ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
+	if (sc->gif_si) {
+		softintr_disestablish(sc->gif_si);
+		sc->gif_si = NULL;
+	}
+#endif
+
 	/* XXX we can detach from both, but be polite just in case */
 	if (sc->gif_psrc)
 		switch (sc->gif_psrc->sa_family) {
--- a/sys/net/if_media.h	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/net/if_media.h	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_media.h,v 1.43 2005/12/10 23:21:38 elad Exp $	*/
+/*	$NetBSD: if_media.h,v 1.43.10.1 2006/04/19 04:46:10 elad Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000, 2001 The NetBSD Foundation, Inc.
@@ -231,10 +231,10 @@
 #define	IFM_IEEE80211_TURBO	 0x00000800	/* Operate in Turbo mode */
 
 /* operating mode for multi-mode devices */
-#define	IFM_IEEE80211_11A	0x00010000	/* 5Ghz, OFDM mode */
+#define	IFM_IEEE80211_11A	0x00010000	/* 5 GHz, OFDM mode */
 #define	IFM_IEEE80211_11B	0x00020000	/* Direct Sequence mode */
-#define	IFM_IEEE80211_11G	0x00030000	/* 2Ghz, CCK mode */
-#define	IFM_IEEE80211_FH	0x00040000	/* 2Ghz, GFSK mode */
+#define	IFM_IEEE80211_11G	0x00030000	/* 2 GHz, CCK mode */
+#define	IFM_IEEE80211_FH	0x00040000	/* 2 GHz, GFSK mode */
 
 /*
  * Shared media sub-types
--- a/sys/net/if_pppoe.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/net/if_pppoe.c	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_pppoe.c,v 1.64.8.2 2006/03/10 15:05:22 elad Exp $ */
+/* $NetBSD: if_pppoe.c,v 1.64.8.3 2006/04/19 04:46:10 elad Exp $ */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.64.8.2 2006/03/10 15:05:22 elad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.64.8.3 2006/04/19 04:46:10 elad Exp $");
 
 #include "pppoe.h"
 #include "bpfilter.h"
@@ -708,7 +708,8 @@
 	}
 
 done:
-	m_freem(m);
+	if (m)
+		m_freem(m);
 	return;
 }
 
--- a/sys/net/if_tap.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/net/if_tap.c	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_tap.c,v 1.13.4.1 2006/03/08 01:11:55 elad Exp $	*/
+/*	$NetBSD: if_tap.c,v 1.13.4.2 2006/04/19 04:46:10 elad Exp $	*/
 
 /*
  *  Copyright (c) 2003, 2004 The NetBSD Foundation.
@@ -43,7 +43,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_tap.c,v 1.13.4.1 2006/03/08 01:11:55 elad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_tap.c,v 1.13.4.2 2006/04/19 04:46:10 elad Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "bpfilter.h"
@@ -123,7 +123,6 @@
 
 /* Ethernet address helper functions */
 
-static char	*tap_ether_sprintf(char *, const u_char *);
 static int	tap_ether_aton(u_char *, char *);
 
 CFATTACH_DECL(tap, sizeof(struct tap_softc),
@@ -254,7 +253,7 @@
 	struct ifnet *ifp;
 	u_int8_t enaddr[ETHER_ADDR_LEN] =
 	    { 0xf2, 0x0b, 0xa4, 0xff, 0xff, 0xff };
-	char enaddrstr[18];
+	char enaddrstr[3 * ETHER_ADDR_LEN];
 	uint32_t ui;
 	int error;
 	const struct sysctlnode *node;
@@ -271,7 +270,7 @@
 	memcpy(enaddr+3, (u_int8_t *)&ui, 3);
 
 	aprint_normal("%s: Ethernet address %s\n", sc->sc_dev.dv_xname,
-	    tap_ether_sprintf(enaddrstr, enaddr));
+	    ether_snprintf(enaddrstr, sizeof(enaddrstr), enaddr));
 
 	/*
 	 * Why 1000baseT? Why not? You can add more.
@@ -325,7 +324,8 @@
 	    &node, CTLFLAG_READWRITE,
 	    CTLTYPE_STRING, sc->sc_dev.dv_xname, NULL,
 	    tap_sysctl_handler, 0, sc, 18,
-	    CTL_NET, AF_LINK, tap_node, sc->sc_dev.dv_unit, CTL_EOL)) != 0)
+	    CTL_NET, AF_LINK, tap_node, device_unit(&sc->sc_dev),
+	    CTL_EOL)) != 0)
 		aprint_error("%s: sysctl_createv returned %d, ignoring\n",
 		    sc->sc_dev.dv_xname, error);
 
@@ -379,7 +379,7 @@
 	 * CTL_EOL.
 	 */
 	if ((error = sysctl_destroyv(NULL, CTL_NET, AF_LINK, tap_node,
-	    sc->sc_dev.dv_unit, CTL_EOL)) != 0)
+	    device_unit(&sc->sc_dev), CTL_EOL)) != 0)
 		aprint_error("%s: sysctl_destroyv returned %d, ignoring\n",
 		    sc->sc_dev.dv_xname, error);
 	ether_ifdetach(ifp);
@@ -617,7 +617,7 @@
 int
 tap_clone_destroyer(struct device *dev)
 {
-	struct cfdata *cf = dev->dv_cfdata;
+	struct cfdata *cf = device_cfdata(dev);
 	int error;
 
 	if ((error = config_detach(dev, 0)) != 0)
@@ -710,7 +710,7 @@
 	sc->sc_flags |= TAP_INUSE;
 
 	return fdclone(l, fp, fd, FREAD|FWRITE, &tap_fileops,
-	    (void *)(intptr_t)sc->sc_dev.dv_unit);
+	    (void *)(intptr_t)device_unit(&sc->sc_dev));
 }
 
 /*
@@ -1266,12 +1266,12 @@
 	struct ifnet *ifp;
 	int error;
 	size_t len;
-	char addr[18];
+	char addr[3 * ETHER_ADDR_LEN];
 
 	node = *rnode;
 	sc = node.sysctl_data;
 	ifp = &sc->sc_ec.ec_if;
-	(void)tap_ether_sprintf(addr, LLADDR(ifp->if_sadl));
+	(void)ether_snprintf(addr, sizeof(addr), LLADDR(ifp->if_sadl));
 	node.sysctl_data = addr;
 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
 	if (error || newp == NULL)
@@ -1323,56 +1323,3 @@
 	memcpy(dest, val, 6);
 	return (0);
 }
-
-/*
- * ether_sprintf made thread-safer.
- *
- * Copied over from sys/net/if_ethersubr.c, with a change to avoid the use
- * of a static buffer.
- */
-
-/*
- * Copyright (c) 1982, 1989, 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. 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.
- *
- *      @(#)if_ethersubr.c      8.2 (Berkeley) 4/4/96
- */
-
-static char *
-tap_ether_sprintf(char *dest, const u_char *ap)
-{
-	char *cp = dest;
-	int i;
-
-	for (i = 0; i < 6; i++) {
-		*cp++ = hexdigits[*ap >> 4];
-		*cp++ = hexdigits[*ap++ & 0xf];
-		*cp++ = ':';
-	}
-	*--cp = 0;
-	return (dest);
-}
--- a/sys/net/if_tokensubr.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/net/if_tokensubr.c	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_tokensubr.c,v 1.34 2005/12/11 23:05:25 thorpej Exp $	*/
+/*	$NetBSD: if_tokensubr.c,v 1.34.10.1 2006/04/19 04:46:10 elad Exp $	*/
 
 /*
  * Copyright (c) 1982, 1989, 1993
@@ -99,7 +99,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_tokensubr.c,v 1.34 2005/12/11 23:05:25 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_tokensubr.c,v 1.34.10.1 2006/04/19 04:46:10 elad Exp $");
 
 #include "opt_inet.h"
 #include "opt_atalk.h"
@@ -402,8 +402,8 @@
 #ifdef	LLC
 /*	case AF_NSAP: */
 	case AF_CCITT: {
-		struct sockaddr_dl *sdl =
-		    (struct sockaddr_dl *) rt -> rt_gateway;
+		struct sockaddr_dl *sdl = rt ? 
+		    (struct sockaddr_dl *) rt -> rt_gateway : NULL;
 
 		if (sdl && sdl->sdl_family == AF_LINK
 		    && sdl->sdl_alen > 0) {
--- a/sys/net/if_tun.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/net/if_tun.c	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_tun.c,v 1.82.4.2 2006/03/10 15:05:22 elad Exp $	*/
+/*	$NetBSD: if_tun.c,v 1.82.4.3 2006/04/19 04:46:10 elad Exp $	*/
 
 /*
  * Copyright (c) 1988, Julian Onions <jpo@cs.nott.ac.uk>
@@ -15,7 +15,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_tun.c,v 1.82.4.2 2006/03/10 15:05:22 elad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_tun.c,v 1.82.4.3 2006/04/19 04:46:10 elad Exp $");
 
 #include "opt_inet.h"
 #include "opt_ns.h"
@@ -542,7 +542,9 @@
 				goto out;
 			}
 			bcopy(dst, mtod(m0, char *), dst->sa_len);
-		} else {
+		}
+
+		if (tp->tun_flags & TUN_IFHEAD) {
 			/* Prepend the address family */
 			M_PREPEND(m0, sizeof(*af), M_DONTWAIT);
 			if (m0 == NULL) {
@@ -552,6 +554,15 @@
 			}
 			af = mtod(m0,uint32_t *);
 			*af = htonl(dst->sa_family);
+		} else {
+#ifdef INET     
+			if (dst->sa_family != AF_INET)
+#endif
+			{
+				m_freem(m0);
+				error = EAFNOSUPPORT;
+				goto out;
+			}
 		}
 		/* FALLTHROUGH */
 	case AF_UNSPEC:
@@ -633,12 +644,25 @@
 		break;
 
 	case TUNSLMODE:
-		if (*(int *)data)
+		if (*(int *)data) {
 			tp->tun_flags |= TUN_PREPADDR;
-		else
+			tp->tun_flags &= ~TUN_IFHEAD;
+		} else
 			tp->tun_flags &= ~TUN_PREPADDR;
 		break;
 
+	case TUNSIFHEAD:
+		if (*(int *)data) {
+			tp->tun_flags |= TUN_IFHEAD;
+			tp->tun_flags &= TUN_PREPADDR;
+		} else
+			tp->tun_flags &= ~TUN_IFHEAD;
+		break;
+
+	case TUNGIFHEAD:
+		*(int *)data = (tp->tun_flags & TUN_IFHEAD);
+		break;
+
 	case FIONBIO:
 		if (*(int *)data)
 			tp->tun_flags |= TUN_NBIO;
@@ -820,13 +844,17 @@
 					goto out0;
 				}
 		}
-	} else {
+	} else if (tp->tun_flags & TUN_IFHEAD) {
 		if (uio->uio_resid < sizeof(family)){
 			error = EIO;
 			goto out0;
 		}
 		error = uiomove((caddr_t)&family, sizeof(family), uio);
 		dst.sa_family = ntohl(family);
+	} else {
+#ifdef INET
+		dst.sa_family = AF_INET;
+#endif
 	}
 
 	if (uio->uio_resid > TUNMTU) {
@@ -847,6 +875,7 @@
 	case AF_INET6:
 		ifq = &ip6intrq;
 		isr = NETISR_IPV6;
+		break;
 #endif
 	default:
 		error = EAFNOSUPPORT;
--- a/sys/net/if_tun.h	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/net/if_tun.h	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_tun.h,v 1.13 2005/12/11 12:24:51 christos Exp $	*/
+/*	$NetBSD: if_tun.h,v 1.13.10.1 2006/04/19 04:46:10 elad Exp $	*/
 
 /*
  * Copyright (c) 1988, Julian Onions <jpo@cs.nott.ac.uk>
@@ -33,6 +33,7 @@
 #define	TUN_ASYNC	0x0080
 #define	TUN_NBIO	0x0100
 #define	TUN_PREPADDR	0x0200
+#define	TUN_IFHEAD	0x0400
 
 #define	TUN_READY	(TUN_OPEN | TUN_INITED | TUN_IASET)
 
@@ -53,5 +54,7 @@
 #define	TUNGDEBUG	_IOR('t', 89, int)
 #define	TUNSIFMODE	_IOW('t', 88, int)
 #define	TUNSLMODE	_IOW('t', 87, int)
+#define	TUNSIFHEAD	_IOW('t', 66, int)
+#define	TUNGIFHEAD	_IOR('t', 65, int)
 
 #endif /* !_NET_IF_TUN_H_ */
--- a/sys/net/route.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/net/route.c	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: route.c,v 1.67 2005/12/11 12:24:52 christos Exp $	*/
+/*	$NetBSD: route.c,v 1.67.10.1 2006/04/19 04:46:10 elad Exp $	*/
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -98,7 +98,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.67 2005/12/11 12:24:52 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.67.10.1 2006/04/19 04:46:10 elad Exp $");
 
 #include "opt_ns.h"
 
@@ -126,8 +126,6 @@
 #include <netns/ns.h>
 #endif
 
-#define	SA(p) ((struct sockaddr *)(p))
-
 struct	route_cb route_cb;
 struct	rtstat	rtstat;
 struct	radix_node_head *rt_tables[AF_MAX+1];
@@ -179,7 +177,7 @@
 	struct radix_node_head *rnh = rt_tables[dst->sa_family];
 	struct rtentry *rt;
 	struct radix_node *rn;
-	struct rtentry *newrt = 0;
+	struct rtentry *newrt = NULL;
 	struct rt_addrinfo info;
 	int  s = splsoftnet(), err = 0, msgtype = RTM_MISS;
 
@@ -187,13 +185,14 @@
 	    ((rn->rn_flags & RNF_ROOT) == 0)) {
 		newrt = rt = (struct rtentry *)rn;
 		if (report && (rt->rt_flags & RTF_CLONING)) {
-			err = rtrequest(RTM_RESOLVE, dst, SA(0),
-					      SA(0), 0, &newrt);
+			err = rtrequest(RTM_RESOLVE, dst, NULL, NULL, 0,
+			    &newrt);
 			if (err) {
 				newrt = rt;
 				rt->rt_refcnt++;
 				goto miss;
 			}
+			KASSERT(newrt != NULL);
 			if ((rt = newrt) && (rt->rt_flags & RTF_XRESOLVE)) {
 				msgtype = RTM_RESOLVE;
 				goto miss;
@@ -228,7 +227,7 @@
 {
 	struct ifaddr *ifa;
 
-	if (rt == 0)
+	if (rt == NULL)
 		panic("rtfree");
 	rt->rt_refcnt--;
 	if (rt->rt_refcnt <= 0 && (rt->rt_flags & RTF_UP) == 0) {
@@ -278,12 +277,12 @@
 {
 	struct rtentry *rt;
 	int error = 0;
-	u_quad_t *stat = 0;
+	u_quad_t *stat = NULL;
 	struct rt_addrinfo info;
 	struct ifaddr *ifa;
 
 	/* verify the gateway is directly reachable */
-	if ((ifa = ifa_ifwithnet(gateway)) == 0) {
+	if ((ifa = ifa_ifwithnet(gateway)) == NULL) {
 		error = ENETUNREACH;
 		goto out;
 	}
@@ -310,7 +309,7 @@
 	 * which use routing redirects generated by smart gateways
 	 * to dynamically build the routing tables.
 	 */
-	if ((rt == 0) || (rt_mask(rt) && rt_mask(rt)->sa_len < 2))
+	if ((rt == NULL) || (rt_mask(rt) && rt_mask(rt)->sa_len < 2))
 		goto create;
 	/*
 	 * Don't listen to the redirect if it's
@@ -446,10 +445,10 @@
 		 * as our clue to the interface.  Otherwise
 		 * we can use the local address.
 		 */
-		ifa = 0;
+		ifa = NULL;
 		if (flags & RTF_HOST)
 			ifa = ifa_ifwithdstaddr(dst);
-		if (ifa == 0)
+		if (ifa == NULL)
 			ifa = ifa_ifwithaddr(gateway);
 	} else {
 		/*
@@ -459,15 +458,15 @@
 		 */
 		ifa = ifa_ifwithdstaddr(gateway);
 	}
-	if (ifa == 0)
+	if (ifa == NULL)
 		ifa = ifa_ifwithnet(gateway);
-	if (ifa == 0) {
+	if (ifa == NULL) {
 		struct rtentry *rt = rtalloc1(dst, 0);
-		if (rt == 0)
-			return (0);
+		if (rt == NULL)
+			return NULL;
 		rt->rt_refcnt--;
-		if ((ifa = rt->rt_ifa) == 0)
-			return (0);
+		if ((ifa = rt->rt_ifa) == NULL)
+			return NULL;
 	}
 	if (ifa->ifa_addr->sa_family != dst->sa_family) {
 		struct ifaddr *oifa = ifa;
@@ -494,22 +493,16 @@
 	return rtrequest1(req, &info, ret_nrt);
 }
 
-/*
- * These (questionable) definitions of apparent local variables apply
- * to the next function.  XXXXXX!!!
- */
-#define dst	info->rti_info[RTAX_DST]
-#define gateway	info->rti_info[RTAX_GATEWAY]
-#define netmask	info->rti_info[RTAX_NETMASK]
-#define ifaaddr	info->rti_info[RTAX_IFA]
-#define ifpaddr	info->rti_info[RTAX_IFP]
-#define flags	info->rti_flags
-
 int
 rt_getifa(struct rt_addrinfo *info)
 {
 	struct ifaddr *ifa;
 	int error = 0;
+	const struct sockaddr *dst = info->rti_info[RTAX_DST];
+	const struct sockaddr *gateway = info->rti_info[RTAX_GATEWAY];
+	const struct sockaddr *ifaaddr = info->rti_info[RTAX_IFA];
+	const struct sockaddr *ifpaddr = info->rti_info[RTAX_IFP];
+	int flags = info->rti_flags;
 
 	/*
 	 * ifp may be specified by sockaddr_dl when protocol address
@@ -552,33 +545,37 @@
 	struct ifaddr *ifa;
 	struct sockaddr *ndst;
 	struct sockaddr_storage deldst;
+	const struct sockaddr *dst = info->rti_info[RTAX_DST];
+	const struct sockaddr *gateway = info->rti_info[RTAX_GATEWAY];
+	const struct sockaddr *netmask = info->rti_info[RTAX_NETMASK];
+	int flags = info->rti_flags;
 #define senderr(x) { error = x ; goto bad; }
 
-	if ((rnh = rt_tables[dst->sa_family]) == 0)
+	if ((rnh = rt_tables[dst->sa_family]) == NULL)
 		senderr(ESRCH);
 	if (flags & RTF_HOST)
-		netmask = 0;
+		netmask = NULL;
 	switch (req) {
 	case RTM_DELETE:
 		if (netmask) {
 			rt_maskedcopy(dst, (struct sockaddr *)&deldst, netmask);
 			dst = (struct sockaddr *)&deldst;
 		}
-		if ((rn = rnh->rnh_lookup(dst, netmask, rnh)) == 0)
+		if ((rn = rnh->rnh_lookup(dst, netmask, rnh)) == NULL)
 			senderr(ESRCH);
 		rt = (struct rtentry *)rn;
 		if ((rt->rt_flags & RTF_CLONING) != 0) {
 			/* clean up any cloned children */
 			rtflushclone(rnh, rt);
 		}
-		if ((rn = rnh->rnh_deladdr(dst, netmask, rnh)) == 0)
+		if ((rn = rnh->rnh_deladdr(dst, netmask, rnh)) == NULL)
 			senderr(ESRCH);
 		if (rn->rn_flags & (RNF_ACTIVE | RNF_ROOT))
 			panic ("rtrequest delete");
 		rt = (struct rtentry *)rn;
 		if (rt->rt_gwroute) {
-			rt = rt->rt_gwroute; RTFREE(rt);
-			(rt = (struct rtentry *)rn)->rt_gwroute = 0;
+			RTFREE(rt->rt_gwroute);
+			rt->rt_gwroute = NULL;
 		}
 		if (rt->rt_parent) {
 			rt->rt_parent->rt_refcnt--;
@@ -597,7 +594,7 @@
 		break;
 
 	case RTM_RESOLVE:
-		if (ret_nrt == 0 || (rt = *ret_nrt) == 0)
+		if (ret_nrt == NULL || (rt = *ret_nrt) == NULL)
 			senderr(EINVAL);
 		if ((rt->rt_flags & RTF_CLONING) == 0)
 			senderr(EINVAL);
@@ -605,17 +602,17 @@
 		flags = rt->rt_flags & ~(RTF_CLONING | RTF_STATIC);
 		flags |= RTF_CLONED;
 		gateway = rt->rt_gateway;
-		if ((netmask = rt->rt_genmask) == 0)
+		if ((netmask = rt->rt_genmask) == NULL)
 			flags |= RTF_HOST;
 		goto makeroute;
 
 	case RTM_ADD:
-		if (info->rti_ifa == 0 && (error = rt_getifa(info)))
+		if (info->rti_ifa == NULL && (error = rt_getifa(info)))
 			senderr(error);
 		ifa = info->rti_ifa;
 	makeroute:
 		rt = pool_get(&rtentry_pool, PR_NOWAIT);
-		if (rt == 0)
+		if (rt == NULL)
 			senderr(ENOBUFS);
 		Bzero(rt, sizeof(*rt));
 		rt->rt_flags = RTF_UP | flags;
@@ -647,7 +644,7 @@
 			}
 			RTFREE(crt);
 		}
-		if (rn == 0) {
+		if (rn == NULL) {
 			IFAFREE(ifa);
 			if ((rt->rt_flags & RTF_CLONED) != 0 && rt->rt_parent)
 				rtfree(rt->rt_parent);
@@ -674,13 +671,6 @@
 	return (error);
 }
 
-#undef dst
-#undef gateway
-#undef netmask
-#undef ifaaddr
-#undef ifpaddr
-#undef flags
-
 int
 rt_setgate( struct rtentry *rt0, const struct sockaddr *dst,
 	const struct sockaddr *gate)
@@ -689,16 +679,16 @@
 	u_int dlen = ROUNDUP(dst->sa_len), glen = ROUNDUP(gate->sa_len);
 	struct rtentry *rt = rt0;
 
-	if (rt->rt_gateway == 0 || glen > ROUNDUP(rt->rt_gateway->sa_len)) {
+	if (rt->rt_gateway == NULL || glen > ROUNDUP(rt->rt_gateway->sa_len)) {
 		old = (caddr_t)rt_key(rt);
 		R_Malloc(new, caddr_t, dlen + glen);
-		if (new == 0)
+		if (new == NULL)
 			return 1;
 		Bzero(new, dlen + glen);
 		rt->rt_nodes->rn_key = new;
 	} else {
 		new = __UNCONST(rt->rt_nodes->rn_key); /*XXXUNCONST*/
-		old = 0;
+		old = NULL;
 	}
 	Bcopy(gate, (rt->rt_gateway = (struct sockaddr *)(new + dlen)), glen);
 	if (old) {
@@ -706,8 +696,8 @@
 		Free(old);
 	}
 	if (rt->rt_gwroute) {
-		rt = rt->rt_gwroute; RTFREE(rt);
-		rt = rt0; rt->rt_gwroute = 0;
+		RTFREE(rt->rt_gwroute);
+		rt->rt_gwroute = NULL;
 	}
 	if (rt->rt_flags & RTF_GATEWAY) {
 		rt->rt_gwroute = rtalloc1(gate, 1);
@@ -758,7 +748,7 @@
 	struct rtentry *rt;
 	struct sockaddr *dst, *odst;
 	struct sockaddr_storage deldst;
-	struct rtentry *nrt = 0;
+	struct rtentry *nrt = NULL;
 	int error;
 	struct rt_addrinfo info;
 
--- a/sys/net/rtsock.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/net/rtsock.c	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtsock.c,v 1.81.4.2 2006/03/10 15:05:23 elad Exp $	*/
+/*	$NetBSD: rtsock.c,v 1.81.4.3 2006/04/19 04:46:10 elad Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.81.4.2 2006/03/10 15:05:23 elad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.81.4.3 2006/04/19 04:46:10 elad Exp $");
 
 #include "opt_inet.h"
 
@@ -494,7 +494,7 @@
 	}
 	/* Check for bad data length.  */
 	if (cp != cplim) {
-		if (i == RTAX_NETMASK + 1 &&
+		if (i == RTAX_NETMASK + 1 && sa &&
 		    cp - ROUNDUP(sa->sa_len) + sa->sa_len == cplim)
 			/*
 			 * The last sockaddr was netmask.
@@ -930,6 +930,7 @@
 		rtm->rtm_flags = rt->rt_flags;
 		rtm->rtm_use = rt->rt_use;
 		rtm->rtm_rmx = rt->rt_rmx;
+		KASSERT(rt->rt_ifp != NULL);
 		rtm->rtm_index = rt->rt_ifp->if_index;
 		rtm->rtm_errno = rtm->rtm_pid = rtm->rtm_seq = 0;
 		rtm->rtm_addrs = info.rti_addrs;
--- a/sys/net/slcompress.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/net/slcompress.c	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: slcompress.c,v 1.28 2005/12/11 23:05:25 thorpej Exp $   */
+/*	$NetBSD: slcompress.c,v 1.28.10.1 2006/04/19 04:46:10 elad Exp $   */
 /*	Id: slcompress.c,v 1.3 1996/05/24 07:04:47 paulus Exp 	*/
 
 /*
@@ -41,7 +41,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: slcompress.c,v 1.28 2005/12/11 23:05:25 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: slcompress.c,v 1.28.10.1 2006/04/19 04:46:10 elad Exp $");
 
 #include "opt_inet.h"
 #ifdef INET
@@ -433,7 +433,7 @@
 	int vjlen;
 	u_int hlen;
 
-	cp = bufp? *bufp: NULL;
+	cp = *bufp;
 	vjlen = sl_uncompress_tcp_core(cp, len, len, type, comp, &hdr, &hlen);
 	if (vjlen < 0)
 		return (0);	/* error */
--- a/sys/net/zlib.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/net/zlib.c	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: zlib.c,v 1.23 2006/01/14 18:58:05 christos Exp $	*/
+/*	$NetBSD: zlib.c,v 1.23.8.1 2006/04/19 04:46:10 elad Exp $	*/
 /*
  * This file is derived from various .h and .c files from the zlib-1.0.4
  * distribution by Jean-loup Gailly and Mark Adler, with some additions
@@ -11,7 +11,7 @@
  * - added inflateIncomp and deflateOutputPending
  * - allow strm->next_out to be NULL, meaning discard the output
  *
- * $Id: zlib.c,v 1.23 2006/01/14 18:58:05 christos Exp $
+ * $Id: zlib.c,v 1.23.8.1 2006/04/19 04:46:10 elad Exp $
  */
 
 /*
@@ -22,7 +22,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: zlib.c,v 1.23 2006/01/14 18:58:05 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: zlib.c,v 1.23.8.1 2006/04/19 04:46:10 elad Exp $");
 
 #define NO_DUMMY_DECL
 #define NO_ZCFUNCS
@@ -45,7 +45,7 @@
    subject to change. Applications should only use zlib.h.
  */
 
-/* @(#) $Id: zlib.c,v 1.23 2006/01/14 18:58:05 christos Exp $ */
+/* @(#) $Id: zlib.c,v 1.23.8.1 2006/04/19 04:46:10 elad Exp $ */
 
 #ifndef _Z_UTIL_H
 #define _Z_UTIL_H
@@ -88,7 +88,6 @@
 #endif /* __KERNEL__ */
 #endif /* _KERNEL || KERNEL */
 
-
 #ifndef local
 #  define local static
 #endif
@@ -295,7 +294,7 @@
    subject to change. Applications should only use zlib.h.
  */
 
-/* @(#) $Id: zlib.c,v 1.23 2006/01/14 18:58:05 christos Exp $ */
+/* @(#) $Id: zlib.c,v 1.23.8.1 2006/04/19 04:46:10 elad Exp $ */
 
 #ifndef _DEFLATE_H
 #define _DEFLATE_H
@@ -657,7 +656,7 @@
  *
  */
 
-/* @(#) $Id: zlib.c,v 1.23 2006/01/14 18:58:05 christos Exp $ */
+/* @(#) $Id: zlib.c,v 1.23.8.1 2006/04/19 04:46:10 elad Exp $ */
 
 /* #include "deflate.h" */
 
@@ -2031,7 +2030,7 @@
  *          Addison-Wesley, 1983. ISBN 0-201-06672-6.
  */
 
-/* @(#) $Id: zlib.c,v 1.23 2006/01/14 18:58:05 christos Exp $ */
+/* @(#) $Id: zlib.c,v 1.23.8.1 2006/04/19 04:46:10 elad Exp $ */
 
 /* #define GEN_TREES_H */
 
@@ -4768,6 +4767,8 @@
 
       /* backup over finished tables */
       mask = (1 << w) - 1;      /* needed on HP, cc -O bug */
+      if (h == -1)
+	return Z_BUF_ERROR;
       while ((i & mask) != x[h])
       {
         h--;                    /* don't need to update q */
@@ -5907,7 +5908,7 @@
  * For conditions of distribution and use, see copyright notice in zlib.h
  */
 
-/* @(#) $Id: zlib.c,v 1.23 2006/01/14 18:58:05 christos Exp $ */
+/* @(#) $Id: zlib.c,v 1.23.8.1 2006/04/19 04:46:10 elad Exp $ */
 
 /* #include "zlib.h" */
 
--- a/sys/net80211/_ieee80211.h	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/net80211/_ieee80211.h	Wed Apr 19 04:46:10 2006 +0000
@@ -103,7 +103,7 @@
  * Channels are specified by frequency and attributes.
  */
 struct ieee80211_channel {
-	u_int16_t	ic_freq;	/* setting in Mhz */
+	u_int16_t	ic_freq;	/* setting in MHz */
 	u_int16_t	ic_flags;	/* see below */
 };
 
--- a/sys/net80211/ieee80211.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/net80211/ieee80211.c	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211.c,v 1.44 2006/03/02 03:38:48 dyoung Exp $	*/
+/*	$NetBSD: ieee80211.c,v 1.44.4.1 2006/04/19 04:46:11 elad Exp $	*/
 /*-
  * Copyright (c) 2001 Atsushi Onoe
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
@@ -36,7 +36,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211.c,v 1.22 2005/08/10 16:22:29 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211.c,v 1.44 2006/03/02 03:38:48 dyoung Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211.c,v 1.44.4.1 2006/04/19 04:46:11 elad Exp $");
 #endif
 
 /*
@@ -280,7 +280,7 @@
 			return (freq - 2407) / 5;
 		else
 			return 15 + ((freq - 2512) / 20);
-	} else if (flags & IEEE80211_CHAN_5GHZ) {	/* 5Ghz band */
+	} else if (flags & IEEE80211_CHAN_5GHZ) {	/* 5 GHz band */
 		return (freq - 5000) / 5;
 	} else {				/* either, guess */
 		if (freq == 2484)
@@ -326,7 +326,7 @@
 			return 2407 + chan*5;
 		else
 			return 2512 + ((chan-15)*20);
-	} else if (flags & IEEE80211_CHAN_5GHZ) {/* 5Ghz band */
+	} else if (flags & IEEE80211_CHAN_5GHZ) {/* 5 GHz band */
 		return 5000 + (chan*5);
 	} else {				/* either, guess */
 		if (chan == 14)
--- a/sys/net80211/ieee80211.h	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/net80211/ieee80211.h	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211.h,v 1.16 2005/12/10 23:26:35 elad Exp $	*/
+/*	$NetBSD: ieee80211.h,v 1.16.10.1 2006/04/19 04:46:11 elad Exp $	*/
 /*-
  * Copyright (c) 2001 Atsushi Onoe
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
@@ -421,15 +421,17 @@
 	u_int8_t	tim_bitmap[1];		/* variable-length bitmap */
 } __packed;
 
+struct ieee80211_band {
+	u_int8_t schan;			/* starting channel */
+	u_int8_t nchan;			/* number channels */
+	u_int8_t maxtxpwr;		/* tx power cap */
+} __packed;
+
 struct ieee80211_country_ie {
 	u_int8_t	ie;			/* IEEE80211_ELEMID_COUNTRY */
 	u_int8_t	len;
 	u_int8_t	cc[3];			/* ISO CC+(I)ndoor/(O)utdoor */
-	struct {
-		u_int8_t schan;			/* starting channel */
-		u_int8_t nchan;			/* number channels */
-		u_int8_t maxtxpwr;		/* tx power cap */
-	} band[4] __packed;			/* up to 4 sub bands */
+	struct ieee80211_band band[4];		/* up to 4 sub bands */
 } __packed;
 
 #define IEEE80211_CHALLENGE_LEN		128
--- a/sys/net80211/ieee80211_acl.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/net80211/ieee80211_acl.c	Wed Apr 19 04:46:10 2006 +0000
@@ -34,7 +34,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_acl.c,v 1.4 2005/08/13 17:31:48 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_acl.c,v 1.4 2005/11/18 16:40:08 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_acl.c,v 1.4.10.1 2006/04/19 04:46:11 elad Exp $");
 #endif
 
 /*
@@ -292,8 +292,7 @@
 			ireq->i_len = space;	/* return required space */
 			return 0;		/* NB: must not error */
 		}
-		MALLOC(ap, struct ieee80211req_maclist *, space,
-			M_TEMP, M_NOWAIT);
+		ap = malloc(space, M_TEMP, M_NOWAIT);
 		if (ap == NULL)
 			return ENOMEM;
 		i = 0;
--- a/sys/net80211/ieee80211_crypto_ccmp.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/net80211/ieee80211_crypto_ccmp.c	Wed Apr 19 04:46:10 2006 +0000
@@ -34,7 +34,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_crypto_ccmp.c,v 1.7 2005/07/11 03:06:23 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto_ccmp.c,v 1.4 2005/11/18 16:57:22 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto_ccmp.c,v 1.4.10.1 2006/04/19 04:46:11 elad Exp $");
 #endif
 
 /*
@@ -53,6 +53,7 @@
 #include <sys/socket.h>
 
 #include <net/if.h>
+#include <net/if_ether.h>
 #include <net/if_media.h>
 
 #include <net80211/ieee80211_var.h>
--- a/sys/net80211/ieee80211_crypto_none.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/net80211/ieee80211_crypto_none.c	Wed Apr 19 04:46:10 2006 +0000
@@ -34,7 +34,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_crypto_none.c,v 1.5 2005/06/10 16:11:24 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto_none.c,v 1.4 2005/12/11 12:24:54 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto_none.c,v 1.4.10.1 2006/04/19 04:46:11 elad Exp $");
 #endif
 
 /*
@@ -47,6 +47,7 @@
 #include <sys/socket.h>
 
 #include <net/if.h>
+#include <net/if_ether.h>
 #include <net/if_media.h>
 
 #include <net80211/ieee80211_var.h>
--- a/sys/net80211/ieee80211_crypto_tkip.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/net80211/ieee80211_crypto_tkip.c	Wed Apr 19 04:46:10 2006 +0000
@@ -34,7 +34,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_crypto_tkip.c,v 1.10 2005/08/08 18:46:35 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto_tkip.c,v 1.4 2005/11/18 16:40:08 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto_tkip.c,v 1.4.10.1 2006/04/19 04:46:11 elad Exp $");
 #endif
 
 /*
@@ -54,6 +54,7 @@
 #include <sys/socket.h>
 
 #include <net/if.h>
+#include <net/if_ether.h>
 #include <net/if_media.h>
 
 #include <net80211/ieee80211_var.h>
--- a/sys/net80211/ieee80211_crypto_wep.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/net80211/ieee80211_crypto_wep.c	Wed Apr 19 04:46:10 2006 +0000
@@ -34,7 +34,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_crypto_wep.c,v 1.7 2005/06/10 16:11:24 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto_wep.c,v 1.4 2005/11/18 16:57:22 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_crypto_wep.c,v 1.4.10.1 2006/04/19 04:46:11 elad Exp $");
 #endif
 
 /*
@@ -50,6 +50,7 @@
 #include <sys/socket.h>
 
 #include <net/if.h>
+#include <net/if_ether.h>
 #include <net/if_media.h>
 
 #include <net80211/ieee80211_var.h>
--- a/sys/net80211/ieee80211_input.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/net80211/ieee80211_input.c	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_input.c,v 1.57 2006/03/02 03:38:48 dyoung Exp $	*/
+/*	$NetBSD: ieee80211_input.c,v 1.57.4.1 2006/04/19 04:46:11 elad Exp $	*/
 /*-
  * Copyright (c) 2001 Atsushi Onoe
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
@@ -36,7 +36,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_input.c,v 1.81 2005/08/10 16:22:29 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_input.c,v 1.57 2006/03/02 03:38:48 dyoung Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_input.c,v 1.57.4.1 2006/04/19 04:46:11 elad Exp $");
 #endif
 
 #include "opt_inet.h"
@@ -1780,7 +1780,7 @@
 	if (*iep == NULL || (*iep)[1] != ie[1]) {
 		if (*iep != NULL)
 			FREE(*iep, M_DEVBUF);
-		MALLOC(*iep, void*, ielen, M_DEVBUF, M_NOWAIT);
+		*iep = malloc(ielen, M_DEVBUF, M_NOWAIT);
 	}
 	if (*iep != NULL)
 		memcpy(*iep, ie, ielen);
--- a/sys/net80211/ieee80211_ioctl.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/net80211/ieee80211_ioctl.c	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_ioctl.c,v 1.30.4.2 2006/03/10 15:14:16 elad Exp $	*/
+/*	$NetBSD: ieee80211_ioctl.c,v 1.30.4.3 2006/04/19 04:46:11 elad Exp $	*/
 /*-
  * Copyright (c) 2001 Atsushi Onoe
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
@@ -36,7 +36,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_ioctl.c,v 1.35 2005/08/30 14:27:47 avatar Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_ioctl.c,v 1.30.4.2 2006/03/10 15:14:16 elad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_ioctl.c,v 1.30.4.3 2006/04/19 04:46:11 elad Exp $");
 #endif
 
 /*
@@ -1204,7 +1204,7 @@
 
 		space = req.space;
 		/* XXX M_WAITOK after driver lock released */
-		MALLOC(p, void *, space, M_TEMP, M_NOWAIT);
+		p = malloc(space, M_TEMP, M_NOWAIT);
 		if (p == NULL)
 			return ENOMEM;
 		req.si = p;
@@ -1562,7 +1562,7 @@
 	if (ireq->i_len > IEEE80211_MAX_OPT_IE)
 		return EINVAL;
 	/* NB: data.length is validated by the wireless extensions code */
-	MALLOC(ie, void *, (u_long)ireq->i_len, M_DEVBUF, M_WAITOK);
+	ie = malloc(ireq->i_len, M_DEVBUF, M_WAITOK);
 	if (ie == NULL)
 		return ENOMEM;
 	error = copyin(ireq->i_data, ie, ireq->i_len);
--- a/sys/net80211/ieee80211_node.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/net80211/ieee80211_node.c	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_node.c,v 1.52 2006/03/02 03:38:48 dyoung Exp $	*/
+/*	$NetBSD: ieee80211_node.c,v 1.52.4.1 2006/04/19 04:46:11 elad Exp $	*/
 /*-
  * Copyright (c) 2001 Atsushi Onoe
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
@@ -36,7 +36,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_node.c,v 1.65 2005/08/13 17:50:21 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_node.c,v 1.52 2006/03/02 03:38:48 dyoung Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_node.c,v 1.52.4.1 2006/04/19 04:46:11 elad Exp $");
 #endif
 
 #include "opt_inet.h"
@@ -130,9 +130,8 @@
 
 	if (ic->ic_max_aid > IEEE80211_AID_MAX)
 		ic->ic_max_aid = IEEE80211_AID_MAX;
-	MALLOC(ic->ic_aid_bitmap, u_int32_t *,
-		howmany(ic->ic_max_aid, 32) * sizeof(u_int32_t),
-		M_DEVBUF, M_NOWAIT | M_ZERO);
+	ic->ic_aid_bitmap = malloc(howmany(ic->ic_max_aid, 32) *
+	    sizeof(u_int32_t), M_DEVBUF, M_NOWAIT | M_ZERO);
 	if (ic->ic_aid_bitmap == NULL) {
 		/* XXX no way to recover */
 		printf("%s: no memory for AID bitmap!\n", __func__);
@@ -141,8 +140,7 @@
 
 	/* XXX defer until using hostap/ibss mode */
 	ic->ic_tim_len = howmany(ic->ic_max_aid, 8) * sizeof(u_int8_t);
-	MALLOC(ic->ic_tim_bitmap, u_int8_t *, ic->ic_tim_len,
-		M_DEVBUF, M_NOWAIT | M_ZERO);
+	ic->ic_tim_bitmap = malloc(ic->ic_tim_len, M_DEVBUF, M_NOWAIT | M_ZERO);
 	if (ic->ic_tim_bitmap == NULL) {
 		/* XXX no way to recover */
 		printf("%s: no memory for TIM bitmap!\n", __func__);
@@ -588,7 +586,7 @@
 		if (maxa != maxb)
 			return maxa - maxb;
 		/* XXX use freq for channel preference */
-		/* for now just prefer 5Ghz band to all other bands */
+		/* for now just prefer 5 GHz band to all other bands */
 		if (IEEE80211_IS_CHAN_5GHZ(a->ni_chan) &&
 		   !IEEE80211_IS_CHAN_5GHZ(b->ni_chan))
 			return 1;
@@ -846,28 +844,42 @@
 }
 
 int
-ieee80211_get_rate(struct ieee80211com *ic)
+ieee80211_get_rate(const struct ieee80211_node * const ni)
 {
 #define	RATE(_ix)	(ni->ni_rates.rs_rates[(_ix)] & IEEE80211_RATE_VAL)
 	int ix, rate;
-	const struct ieee80211_node *ni;
+	struct ieee80211com *ic = ni->ni_ic;
 	const struct ieee80211_rateset *rs;
 
-	ni = ic->ic_bss;
-
+	IASSERT(ni != NULL, ("ni != NULL"));
+	IASSERT(ieee80211_node_refcnt(ni) > 0,
+	    ("refcnt(ni) == %d", ieee80211_node_refcnt(ni)));
+	IASSERT(ic != NULL, ("ic != NULL"));
 	if (ic->ic_fixed_rate != IEEE80211_FIXED_RATE_NONE) {
 		rs = &ic->ic_sup_rates[ic->ic_curmode];
 		rate = rs->rs_rates[ic->ic_fixed_rate] & IEEE80211_RATE_VAL;
 		for (ix = ni->ni_rates.rs_nrates - 1;
 		     ix >= 0 && RATE(ix) != rate; ix--)
 			;
-		IASSERT(ix >= 0,
-			("fixed rate %d not in rate set", ic->ic_fixed_rate));
+		if (ix < 0) {
+			IEEE80211_DPRINTF(ic, IEEE80211_MSG_DEBUG,
+			    "%s: fixed rate %d (%d.%d Mb/s) not in rate set",
+			    __func__, ic->ic_fixed_rate, (rate * 5) / 10,
+			    (rate * 5) % 10);
+			goto no_rate;
+		}
 	} else if (ic->ic_state == IEEE80211_S_RUN)
 		rate = ni->ni_rates.rs_rates[ni->ni_txrate];
-	else
-		rate = 0;
-
+	else {
+no_rate:
+		rs = &ni->ni_rates;
+		/* Choose node's lowest basic rate, or else its lowest rate. */
+		for (ix = 0; ix < rs->rs_nrates; ix++) {
+			if (rs->rs_rates[ix] & IEEE80211_RATE_BASIC)
+				return rs->rs_rates[ix] & IEEE80211_RATE_VAL;
+		}
+		return ni->ni_rates.rs_rates[0] & IEEE80211_RATE_VAL;
+	}
 	return rate & IEEE80211_RATE_VAL;
 }
 
@@ -2389,9 +2401,9 @@
 	nt->nt_timeout = timeout;
 	nt->nt_keyixmax = keyixmax;
 	if (nt->nt_keyixmax > 0) {
-		MALLOC(nt->nt_keyixmap, struct ieee80211_node **,
-			keyixmax * sizeof(struct ieee80211_node *),
-			M_80211_NODE, M_NOWAIT | M_ZERO);
+		nt->nt_keyixmap = malloc(keyixmax *
+		    sizeof(struct ieee80211_node *), M_80211_NODE,
+		    M_NOWAIT | M_ZERO);
 		if (nt->nt_keyixmap == NULL)
 			if_printf(ic->ic_ifp,
 			    "Cannot allocate key index map with %u entries\n",
--- a/sys/net80211/ieee80211_radiotap.h	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/net80211/ieee80211_radiotap.h	Wed Apr 19 04:46:10 2006 +0000
@@ -1,5 +1,5 @@
 /* $FreeBSD: src/sys/net80211/ieee80211_radiotap.h,v 1.5 2005/01/22 20:12:05 sam Exp $ */
-/* $NetBSD: ieee80211_radiotap.h,v 1.14 2005/12/10 23:26:35 elad Exp $ */
+/* $NetBSD: ieee80211_radiotap.h,v 1.14.10.1 2006/04/19 04:46:11 elad Exp $ */
 
 /*-
  * Copyright (c) 2003, 2004 David Young.  All rights reserved.
@@ -32,11 +32,11 @@
 #ifndef _NET80211_IEEE80211_RADIOTAP_H_
 #define _NET80211_IEEE80211_RADIOTAP_H_
 
-/* A generic radio capture format is desirable. There is one for
- * Linux, but it is neither rigidly defined (there were not even
- * units given for some fields) nor easily extensible.
+/* A generic radio capture format is desirable. It must be
+ * rigidly defined (e.g., units for fields should be given),
+ * and easily extensible.
  *
- * I suggest the following extensible radio capture format. It is
+ * The following is an extensible radio capture format. It is
  * based on a bitmap indicating which fields are present.
  *
  * I am trying to describe precisely what the application programmer
@@ -57,7 +57,11 @@
  */
 #define IEEE80211_RADIOTAP_HDRLEN	64
 
-/* The radio capture header precedes the 802.11 header. */
+/*
+ * The radio capture header precedes the 802.11 header.
+ *
+ * Note well: all radiotap fields are little-endian.
+ */
 struct ieee80211_radiotap_header {
 	u_int8_t	it_version;	/* Version 0. Only increases
 					 * for drastic changes,
@@ -79,7 +83,8 @@
 					 */
 } __attribute__((__packed__));
 
-/* Name                                 Data type       Units
+/*
+ * Name                                 Data type       Units
  * ----                                 ---------       -----
  *
  * IEEE80211_RADIOTAP_TSFT              u_int64_t       microseconds
--- a/sys/net80211/ieee80211_var.h	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/net80211/ieee80211_var.h	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_var.h,v 1.23 2006/03/02 03:38:48 dyoung Exp $	*/
+/*	$NetBSD: ieee80211_var.h,v 1.23.4.1 2006/04/19 04:46:11 elad Exp $	*/
 /*-
  * Copyright (c) 2001 Atsushi Onoe
  * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
@@ -309,7 +309,7 @@
 int	ieee80211_setmode(struct ieee80211com *, enum ieee80211_phymode);
 enum ieee80211_phymode ieee80211_chan2mode(struct ieee80211com *,
 		struct ieee80211_channel *);
-int	ieee80211_get_rate(struct ieee80211com *);
+int	ieee80211_get_rate(const struct ieee80211_node *);
 
 /* 
  * Key update synchronization methods.  XXX should not be visible.
--- a/sys/netatalk/at_control.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/netatalk/at_control.c	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: at_control.c,v 1.11.10.2 2006/03/10 15:14:16 elad Exp $	 */
+/*	$NetBSD: at_control.c,v 1.11.10.3 2006/04/19 04:46:11 elad Exp $	 */
 
 /*
  * Copyright (c) 1990,1994 Regents of The University of Michigan.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: at_control.c,v 1.11.10.2 2006/03/10 15:14:16 elad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: at_control.c,v 1.11.10.3 2006/04/19 04:46:11 elad Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -128,7 +128,7 @@
 		 * If we are not superuser, then we don't get to do these
 		 * ops.
 		 */
-		if (kauth_authorize_generic(p->p_cred, KAUTH_GENERIC_ISSUSER,
+		if (p && kauth_authorize_generic(p->p_cred, KAUTH_GENERIC_ISSUSER,
 				      &p->p_acflag))
 			return (EPERM);
 
--- a/sys/netatalk/ddp_usrreq.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/netatalk/ddp_usrreq.c	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ddp_usrreq.c,v 1.14.10.2 2006/03/10 15:14:16 elad Exp $	 */
+/*	$NetBSD: ddp_usrreq.c,v 1.14.10.3 2006/04/19 04:46:11 elad Exp $	 */
 
 /*
  * Copyright (c) 1990,1991 Regents of The University of Michigan.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ddp_usrreq.c,v 1.14.10.2 2006/03/10 15:14:16 elad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ddp_usrreq.c,v 1.14.10.3 2006/04/19 04:46:11 elad Exp $");
 
 #include "opt_mbuftrace.h"
 
@@ -273,7 +273,7 @@
 			    sat->sat_port >= ATPORT_LAST)
 				return (EINVAL);
 
-			if (sat->sat_port < ATPORT_RESERVED &&
+			if (sat->sat_port < ATPORT_RESERVED && p &&
 			    kauth_authorize_generic(p->p_cred, KAUTH_GENERIC_ISSUSER,
 					      &p->p_acflag))
 				return (EACCES);
--- a/sys/netccitt/llc_input.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/netccitt/llc_input.c	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: llc_input.c,v 1.16 2005/12/11 12:24:54 christos Exp $	*/
+/*	$NetBSD: llc_input.c,v 1.16.10.1 2006/04/19 04:46:11 elad Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -76,7 +76,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: llc_input.c,v 1.16 2005/12/11 12:24:54 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: llc_input.c,v 1.16.10.1 2006/04/19 04:46:11 elad Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -268,7 +268,8 @@
 			   		frame->llc_window = linkp->llcl_window;
 			   	else frame->llc_window = sapinfo->si_window;
 			 	frame->llc_fid = 9;			/* XXX */
-			  	frame->llc_class = sapinfo->si_class;
+			  	frame->llc_class =
+				    sapinfo ? sapinfo->si_class : 1;
 			 	frame->llc_ssap = frame->llc_dsap;
 			} else {
 			 	frame->llc_window = 0;
@@ -481,9 +482,10 @@
 
 	case PRC_CONNECT_REQUEST:
 		if (linkp == 0) {
-			if ((linkp = llc_newlink((struct sockaddr_dl *) nlrt->rt_gateway,
+			if (nlrt == NULL ||
+			    (linkp = llc_newlink((struct sockaddr_dl *) nlrt->rt_gateway,
 						 nlrt->rt_ifp, nlrt,
-						 pcb, llrt)) == 0)
+						 pcb, llrt)) == NULL)
 				return (0);
 			((struct npaidbentry *)llrt->rt_llinfo)->np_link = linkp;
 			i = splnet();
--- a/sys/netccitt/llc_subr.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/netccitt/llc_subr.c	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: llc_subr.c,v 1.22 2005/12/11 12:24:54 christos Exp $	*/
+/*	$NetBSD: llc_subr.c,v 1.22.10.1 2006/04/19 04:46:11 elad Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -76,7 +76,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: llc_subr.c,v 1.22 2005/12/11 12:24:54 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: llc_subr.c,v 1.22.10.1 2006/04/19 04:46:11 elad Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -2331,7 +2331,7 @@
 		llcwindow = LLC_MAX_WINDOW;
 
 	/* allocate memory for window buffer */
-	MALLOC(nlinkp->llcl_output_buffers, struct mbuf **,
+	nlinkp->llcl_output_buffers = malloc(
 	       llcwindow * sizeof(struct mbuf *), M_PCB, M_NOWAIT|M_ZERO);
 	if (nlinkp->llcl_output_buffers == 0) {
 		FREE(nlinkp, M_PCB);
--- a/sys/netccitt/llc_timer.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/netccitt/llc_timer.c	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: llc_timer.c,v 1.10 2005/12/11 12:24:54 christos Exp $	*/
+/*	$NetBSD: llc_timer.c,v 1.10.10.1 2006/04/19 04:46:11 elad Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -76,7 +76,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: llc_timer.c,v 1.10 2005/12/11 12:24:54 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: llc_timer.c,v 1.10.10.1 2006/04/19 04:46:11 elad Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -180,8 +180,8 @@
 				 * timers are running any more.
 				 */
 				if (llc_anytimersup(linkp) == 0) {
+					LLC_STOPTIMER(linkp,AGE);
 					llc_dellink(linkp);
-					LLC_STOPTIMER(linkp,AGE);
 					goto gone;
 				} else {
 					LLC_STARTTIMER(linkp,AGE);
--- a/sys/netccitt/pk_output.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/netccitt/pk_output.c	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: pk_output.c,v 1.20 2005/12/11 12:24:54 christos Exp $	*/
+/*	$NetBSD: pk_output.c,v 1.20.10.1 2006/04/19 04:46:11 elad Exp $	*/
 
 /*
  * Copyright (c) 1991, 1992, 1993
@@ -78,7 +78,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pk_output.c,v 1.20 2005/12/11 12:24:54 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pk_output.c,v 1.20.10.1 2006/04/19 04:46:11 elad Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -103,9 +103,9 @@
 {
 	struct x25_packet *xp;
 	struct mbuf *m;
-	struct pkcb *pkp = lcp->lcd_pkp;
+	struct pkcb *pkp;
 
-	if (lcp == 0 || pkp == 0) {
+	if (lcp == 0 || (pkp = lcp->lcd_pkp) == 0) {
 		printf("pk_output: zero arg\n");
 		return;
 	}
--- a/sys/netinet/icmp6.h	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/netinet/icmp6.h	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: icmp6.h,v 1.34 2006/03/05 23:47:08 rpaulo Exp $	*/
+/*	$NetBSD: icmp6.h,v 1.34.2.1 2006/04/19 04:46:11 elad Exp $	*/
 /*	$KAME: icmp6.h,v 1.84 2003/04/23 10:26:51 itojun Exp $	*/
 
 
@@ -112,9 +112,9 @@
 #endif
 
 #define ND_ROUTER_SOLICIT		133	/* router solicitation */
-#define ND_ROUTER_ADVERT		134	/* router advertisment */
+#define ND_ROUTER_ADVERT		134	/* router advertisement */
 #define ND_NEIGHBOR_SOLICIT		135	/* neighbor solicitation */
-#define ND_NEIGHBOR_ADVERT		136	/* neighbor advertisment */
+#define ND_NEIGHBOR_ADVERT		136	/* neighbor advertisement */
 #define ND_REDIRECT			137	/* redirect */
 
 #define ICMP6_ROUTER_RENUMBERING	138	/* router renumbering */
--- a/sys/netinet/ip_icmp.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/netinet/ip_icmp.c	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_icmp.c,v 1.97 2005/11/10 13:40:38 christos Exp $	*/
+/*	$NetBSD: ip_icmp.c,v 1.97.12.1 2006/04/19 04:46:11 elad Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -101,7 +101,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_icmp.c,v 1.97 2005/11/10 13:40:38 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_icmp.c,v 1.97.12.1 2006/04/19 04:46:11 elad Exp $");
 
 #include "opt_ipsec.h"
 
@@ -167,9 +167,9 @@
     LIST_HEAD_INITIALIZER(&icmp_mtudisc_callbacks);
 
 #if 0
-static int	ip_next_mtu(int, int);
+static u_int	ip_next_mtu(u_int, int);
 #else
-/*static*/ int	ip_next_mtu(int, int);
+/*static*/ u_int	ip_next_mtu(u_int, int);
 #endif
 
 extern int icmperrppslim;
@@ -405,7 +405,7 @@
 		goto freeit;
 	}
 	i = hlen + min(icmplen, ICMP_ADVLENMIN);
-	if (m->m_len < i && (m = m_pullup(m, i)) == 0) {
+	if ((m->m_len < i || M_READONLY(m)) && (m = m_pullup(m, i)) == 0) {
 		icmpstat.icps_tooshort++;
 		return;
 	}
@@ -1123,8 +1123,8 @@
  * given current value MTU.  If DIR is less than zero, a larger plateau
  * is returned; otherwise, a smaller value is returned.
  */
-int
-ip_next_mtu(int mtu, int dir)	/* XXX */
+u_int
+ip_next_mtu(u_int mtu, int dir)	/* XXX */
 {
 	int i;
 
--- a/sys/netinet/ip_input.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/netinet/ip_input.c	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_input.c,v 1.224 2006/02/18 17:47:07 joerg Exp $	*/
+/*	$NetBSD: ip_input.c,v 1.224.4.1 2006/04/19 04:46:11 elad Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -98,7 +98,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.224 2006/02/18 17:47:07 joerg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.224.4.1 2006/04/19 04:46:11 elad Exp $");
 
 #include "opt_inet.h"
 #include "opt_gateway.h"
@@ -732,7 +732,7 @@
 	}
 	if (ia != NULL)
 		goto ours;
-	if (m->m_pkthdr.rcvif->if_flags & IFF_BROADCAST) {
+	if (m->m_pkthdr.rcvif && m->m_pkthdr.rcvif->if_flags & IFF_BROADCAST) {
 		IFADDR_FOREACH(ifa, m->m_pkthdr.rcvif) {
 			if (ifa->ifa_addr->sa_family != AF_INET)
 				continue;
--- a/sys/netinet/tcp_input.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/netinet/tcp_input.c	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_input.c,v 1.239 2006/02/18 17:34:49 rpaulo Exp $	*/
+/*	$NetBSD: tcp_input.c,v 1.239.4.1 2006/04/19 04:46:11 elad Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -150,7 +150,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.239 2006/02/18 17:34:49 rpaulo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.239.4.1 2006/04/19 04:46:11 elad Exp $");
 
 #include "opt_inet.h"
 #include "opt_ipsec.h"
@@ -1293,6 +1293,7 @@
 			m_freem(in6p->in6p_options);
 			in6p->in6p_options = 0;
 		}
+		KASSERT(ip6 != NULL);
 		ip6_savecontrol(in6p, &in6p->in6p_options, ip6, m);
 	}
 #endif
--- a/sys/netinet/tcp_output.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/netinet/tcp_output.c	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_output.c,v 1.141 2005/12/24 20:45:09 perry Exp $	*/
+/*	$NetBSD: tcp_output.c,v 1.141.10.1 2006/04/19 04:46:11 elad Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -140,7 +140,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tcp_output.c,v 1.141 2005/12/24 20:45:09 perry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_output.c,v 1.141.10.1 2006/04/19 04:46:11 elad Exp $");
 
 #include "opt_inet.h"
 #include "opt_ipsec.h"
@@ -248,7 +248,7 @@
 	struct rtentry *rt;
 	struct ifnet *ifp;
 	int size;
-	int iphlen;
+	int hdrlen;
 	int optlen;
 
 #ifdef DIAGNOSTIC
@@ -258,12 +258,12 @@
 	switch (tp->t_family) {
 #ifdef INET
 	case AF_INET:
-		iphlen = sizeof(struct ip);
+		hdrlen = sizeof(struct ip) + sizeof(struct tcphdr);
 		break;
 #endif
 #ifdef INET6
 	case AF_INET6:
-		iphlen = sizeof(struct ip6_hdr);
+		hdrlen = sizeof(struct ip6_hdr) + sizeof(struct tcphdr);
 		break;
 #endif
 	default:
@@ -300,21 +300,19 @@
 			 * smaller than 1280, use 1280 as packet size and
 			 * attach fragment header.
 			 */
-			size = IPV6_MMTU - iphlen - sizeof(struct ip6_frag) -
-			    sizeof(struct tcphdr);
+			size = IPV6_MMTU - hdrlen - sizeof(struct ip6_frag);
 		} else
-			size = rt->rt_rmx.rmx_mtu - iphlen -
-			    sizeof(struct tcphdr);
+			size = rt->rt_rmx.rmx_mtu - hdrlen;
 #else
-		size = rt->rt_rmx.rmx_mtu - iphlen - sizeof(struct tcphdr);
+		size = rt->rt_rmx.rmx_mtu - hdrlen;
 #endif
 	} else if (ifp->if_flags & IFF_LOOPBACK)
-		size = ifp->if_mtu - iphlen - sizeof(struct tcphdr);
+		size = ifp->if_mtu - hdrlen;
 #ifdef INET
 	else if (inp && tp->t_mtudisc)
-		size = ifp->if_mtu - iphlen - sizeof(struct tcphdr);
+		size = ifp->if_mtu - hdrlen;
 	else if (inp && in_localaddr(inp->inp_faddr))
-		size = ifp->if_mtu - iphlen - sizeof(struct tcphdr);
+		size = ifp->if_mtu - hdrlen;
 #endif
 #ifdef INET6
 	else if (in6p) {
@@ -324,7 +322,7 @@
 			struct in_addr d;
 			bcopy(&in6p->in6p_faddr.s6_addr32[3], &d, sizeof(d));
 			if (tp->t_mtudisc || in_localaddr(d))
-				size = ifp->if_mtu - iphlen - sizeof(struct tcphdr);
+				size = ifp->if_mtu - hdrlen;
 		} else
 #endif
 		{
@@ -333,7 +331,7 @@
 			 * or the node must use packet size <= 1280.
 			 */
 			size = tp->t_mtudisc ? IN6_LINKMTU(ifp) : IPV6_MMTU;
-			size -= (iphlen + sizeof(struct tcphdr));
+			size -= hdrlen;
 		}
 	}
 #endif
--- a/sys/netinet/tcp_subr.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/netinet/tcp_subr.c	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_subr.c,v 1.196 2005/12/11 12:24:58 christos Exp $	*/
+/*	$NetBSD: tcp_subr.c,v 1.196.10.1 2006/04/19 04:46:11 elad Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -98,7 +98,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tcp_subr.c,v 1.196 2005/12/11 12:24:58 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_subr.c,v 1.196.10.1 2006/04/19 04:46:11 elad Exp $");
 
 #include "opt_inet.h"
 #include "opt_ipsec.h"
@@ -1929,7 +1929,10 @@
 		bufsize = rt->rt_rmx.rmx_sendpipe;
 	else
 #endif
+	{
+		KASSERT(so != NULL);
 		bufsize = so->so_snd.sb_hiwat;
+	}
 	if (bufsize < mss)
 		mss = bufsize;
 	else {
@@ -1996,7 +1999,10 @@
 		bufsize = rt->rt_rmx.rmx_recvpipe;
 	else
 #endif
+	{
+		KASSERT(so != NULL);
 		bufsize = so->so_rcv.sb_hiwat;
+	}
 	if (bufsize > tp->t_ourmss) {
 		bufsize = roundup(bufsize, tp->t_ourmss);
 		if (bufsize > sb_max)
--- a/sys/netinet/tcp_timer.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/netinet/tcp_timer.c	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_timer.c,v 1.73 2005/12/11 12:24:58 christos Exp $	*/
+/*	$NetBSD: tcp_timer.c,v 1.73.10.1 2006/04/19 04:46:11 elad Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -100,7 +100,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tcp_timer.c,v 1.73 2005/12/11 12:24:58 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_timer.c,v 1.73.10.1 2006/04/19 04:46:11 elad Exp $");
 
 #include "opt_inet.h"
 #include "opt_tcp_debug.h"
@@ -566,6 +566,7 @@
 	if (tp->t_in6pcb)
 		so = tp->t_in6pcb->in6p_socket;
 #endif
+	KASSERT(so != NULL);
 	if (so->so_options & SO_KEEPALIVE &&
 	    tp->t_state <= TCPS_CLOSE_WAIT) {
 	    	if ((tcp_maxidle > 0) &&
--- a/sys/netinet/tcp_usrreq.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/netinet/tcp_usrreq.c	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_usrreq.c,v 1.113.10.1 2006/03/08 01:19:40 elad Exp $	*/
+/*	$NetBSD: tcp_usrreq.c,v 1.113.10.2 2006/04/19 04:46:11 elad Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -100,7 +100,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tcp_usrreq.c,v 1.113.10.1 2006/03/08 01:19:40 elad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_usrreq.c,v 1.113.10.2 2006/04/19 04:46:11 elad Exp $");
 
 #include "opt_inet.h"
 #include "opt_ipsec.h"
@@ -918,7 +918,8 @@
 #endif
 		else
 			so = NULL;
-		soisdisconnected(so);
+		if (so)
+			soisdisconnected(so);
 		/*
 		 * If we are in FIN_WAIT_2, we arrived here because the
 		 * application did a shutdown of the send side.  Like the
@@ -1216,19 +1217,24 @@
 	if (namelen != 4)
 		return (EINVAL);
 
+	if (oldp != NULL) {
+		    len = *oldlenp;
+		    elem_size = name[2];
+		    elem_count = name[3];
+		    if (elem_size != sizeof(pcb))
+			    return EINVAL;
+	} else {
+		    len = 0;
+		    elem_count = INT_MAX;
+		    elem_size = sizeof(pcb);
+	}
 	error = 0;
 	dp = oldp;
-	len = (oldp != NULL) ? *oldlenp : 0;
 	op = name[0];
 	arg = name[1];
-	elem_size = name[2];
-	elem_count = name[3];
-	out_size = MIN(sizeof(pcb), elem_size);
+	out_size = elem_size;
 	needed = 0;
 
-	elem_count = INT_MAX;
-	elem_size = out_size = sizeof(pcb);
-
 	if (namelen == 1 && name[0] == CTL_QUERY)
 		return (sysctl_query(SYSCTLFN_CALL(rnode)));
 
@@ -1237,7 +1243,7 @@
 
 	pf = oname[1];
 	proto = oname[2];
-	pf2 = (oldp == NULL) ? 0 : pf;
+	pf2 = (oldp != NULL) ? pf : 0;
 
 	CIRCLEQ_FOREACH(inph, &pcbtbl->inpt_queue, inph_queue) {
 #ifdef INET
--- a/sys/netinet6/icmp6.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/netinet6/icmp6.c	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: icmp6.c,v 1.115 2006/03/05 23:47:08 rpaulo Exp $	*/
+/*	$NetBSD: icmp6.c,v 1.115.2.1 2006/04/19 04:46:11 elad Exp $	*/
 /*	$KAME: icmp6.c,v 1.217 2001/06/20 15:03:29 jinmei Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: icmp6.c,v 1.115 2006/03/05 23:47:08 rpaulo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: icmp6.c,v 1.115.2.1 2006/04/19 04:46:11 elad Exp $");
 
 #include "opt_inet.h"
 #include "opt_ipsec.h"
@@ -163,6 +163,7 @@
 static void icmp6_mtudisc_timeout __P((struct rtentry *, struct rttimer *));
 static void icmp6_redirect_timeout __P((struct rtentry *, struct rttimer *));
 
+
 void
 icmp6_init()
 {
@@ -454,6 +455,8 @@
 	int icmp6len = m->m_pkthdr.len - *offp;
 	int code, sum, noff;
 
+#define ICMP6_MAXLEN (sizeof(*nip6) + sizeof(*nicmp6) + 4)
+	KASSERT(ICMP6_MAXLEN < MCLBYTES);
 	icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_msg);
 
 	/*
@@ -605,19 +608,13 @@
 		if ((n->m_flags & M_EXT) != 0 ||
 		    n->m_len < off + sizeof(struct icmp6_hdr)) {
 			struct mbuf *n0 = n;
-			const int maxlen = sizeof(*nip6) + sizeof(*nicmp6);
 
 			/*
 			 * Prepare an internal mbuf.  m_pullup() doesn't
 			 * always copy the length we specified.
 			 */
-			if (maxlen >= MCLBYTES) {
-				/* Give up remote */
-				m_freem(n0);
-				break;
-			}
 			MGETHDR(n, M_DONTWAIT, n0->m_type);
-			if (n && maxlen >= MHLEN) {
+			if (n && ICMP6_MAXLEN >= MHLEN) {
 				MCLGET(n, M_DONTWAIT);
 				if ((n->m_flags & M_EXT) == 0) {
 					m_free(n);
@@ -725,20 +722,15 @@
 			noff = sizeof(struct ip6_hdr);
 		} else {
 			u_char *p;
-			int maxlen, maxhlen;
+			int maxhlen;
 
 			if ((icmp6_nodeinfo & 5) != 5)
 				break;
 
 			if (code != 0)
 				goto badcode;
-			maxlen = sizeof(*nip6) + sizeof(*nicmp6) + 4;
-			if (maxlen >= MCLBYTES) {
-				/* Give up remote */
-				break;
-			}
 			MGETHDR(n, M_DONTWAIT, m->m_type);
-			if (n && maxlen > MHLEN) {
+			if (n && ICMP6_MAXLEN > MHLEN) {
 				MCLGET(n, M_DONTWAIT);
 				if ((n->m_flags & M_EXT) == 0) {
 					m_free(n);
@@ -751,7 +743,7 @@
 			}
 			n->m_pkthdr.rcvif = NULL;
 			n->m_len = 0;
-			maxhlen = M_TRAILINGSPACE(n) - maxlen;
+			maxhlen = M_TRAILINGSPACE(n) - ICMP6_MAXLEN;
 			if (maxhlen > hostnamelen)
 				maxhlen = hostnamelen;
 			/*
--- a/sys/netinet6/in6.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/netinet6/in6.c	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: in6.c,v 1.99.2.2 2006/03/10 15:20:54 elad Exp $	*/
+/*	$NetBSD: in6.c,v 1.99.2.3 2006/04/19 04:46:11 elad Exp $	*/
 /*	$KAME: in6.c,v 1.198 2001/07/18 09:12:38 itojun Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.99.2.2 2006/03/10 15:20:54 elad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.99.2.3 2006/04/19 04:46:11 elad Exp $");
 
 #include "opt_inet.h"
 #include "opt_pfil_hooks.h"
@@ -1921,7 +1921,7 @@
 	int bytelen, bitlen;
 
 	/* sanity check */
-	if (0 > len || len > 128) {
+	if (len < 0 || len > 128) {
 		log(LOG_ERR, "in6_are_prefix_equal: invalid prefix length(%d)\n",
 		    len);
 		return (0);
@@ -1949,7 +1949,7 @@
 	int bytelen, bitlen, i;
 
 	/* sanity check */
-	if (0 > len || len > 128) {
+	if (len < 0 || len > 128) {
 		log(LOG_ERR, "in6_prefixlen2mask: invalid prefix length(%d)\n",
 		    len);
 		return;
--- a/sys/netinet6/in6.h	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/netinet6/in6.h	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: in6.h,v 1.52 2006/02/16 20:17:20 perry Exp $	*/
+/*	$NetBSD: in6.h,v 1.52.4.1 2006/04/19 04:46:11 elad Exp $	*/
 /*	$KAME: in6.h,v 1.83 2001/03/29 02:55:07 jinmei Exp $	*/
 
 /*
@@ -359,6 +359,9 @@
 	((IN6_IS_ADDR_LINKLOCAL(a)) ||	\
 	 (IN6_IS_ADDR_MC_LINKLOCAL(a)))
 
+#define	IN6_IS_SCOPE_EMBEDDABLE(__a)	\
+    (IN6_IS_SCOPE_LINKLOCAL(__a) || IN6_IS_ADDR_MC_INTFACELOCAL(__a))
+
 #define IFA6_IS_DEPRECATED(a) \
 	((a)->ia6_lifetime.ia6t_pltime != ND6_INFINITE_LIFETIME && \
 	 (u_int32_t)((time.tv_sec - (a)->ia6_updatetime)) > \
--- a/sys/netinet6/in6_src.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/netinet6/in6_src.c	Wed Apr 19 04:46:10 2006 +0000
@@ -65,7 +65,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in6_src.c,v 1.23.8.2 2006/03/10 15:20:54 elad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6_src.c,v 1.23.8.3 2006/04/19 04:46:12 elad Exp $");
 
 #include "opt_inet.h"
 
@@ -1011,7 +1011,7 @@
 	}
 	if (oldp || oldlenp) {
 		struct walkarg w;
-		size_t oldlen = (oldlenp ? *oldlenp : 0);
+		size_t oldlen = *oldlenp;
 
 		bzero(&w, sizeof(w));
 		w.w_given = oldlen;
--- a/sys/netinet6/ip6_input.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/netinet6/ip6_input.c	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6_input.c,v 1.83 2006/03/05 23:47:08 rpaulo Exp $	*/
+/*	$NetBSD: ip6_input.c,v 1.83.2.1 2006/04/19 04:46:12 elad Exp $	*/
 /*	$KAME: ip6_input.c,v 1.188 2001/03/29 05:34:31 itojun Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.83 2006/03/05 23:47:08 rpaulo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.83.2.1 2006/04/19 04:46:12 elad Exp $");
 
 #include "opt_inet.h"
 #include "opt_ipsec.h"
@@ -1030,7 +1030,6 @@
 	struct ip6_hdr *ip6;
 	struct mbuf *m;
 {
-
 #ifdef SO_TIMESTAMP
 	if (in6p->in6p_socket->so_options & SO_TIMESTAMP) {
 		struct timeval tv;
@@ -1063,9 +1062,8 @@
 		struct in6_pktinfo pi6;
 		bcopy(&ip6->ip6_dst, &pi6.ipi6_addr, sizeof(struct in6_addr));
 		in6_clearscope(&pi6.ipi6_addr);	/* XXX */
-		pi6.ipi6_ifindex = (m && m->m_pkthdr.rcvif)
-					? m->m_pkthdr.rcvif->if_index
-					: 0;
+		pi6.ipi6_ifindex = m->m_pkthdr.rcvif ?
+		    m->m_pkthdr.rcvif->if_index : 0;
 		*mp = sbcreatecontrol((caddr_t) &pi6,
 		    sizeof(struct in6_pktinfo), IPV6_PKTINFO, IPPROTO_IPV6);
 		if (*mp)
--- a/sys/netinet6/ip6_output.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/netinet6/ip6_output.c	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6_output.c,v 1.95.2.2 2006/03/10 15:20:54 elad Exp $	*/
+/*	$NetBSD: ip6_output.c,v 1.95.2.3 2006/04/19 04:46:12 elad Exp $	*/
 /*	$KAME: ip6_output.c,v 1.172 2001/03/25 09:55:56 itojun Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip6_output.c,v 1.95.2.2 2006/03/10 15:20:54 elad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_output.c,v 1.95.2.3 2006/04/19 04:46:12 elad Exp $");
 
 #include "opt_inet.h"
 #include "opt_ipsec.h"
@@ -845,6 +845,7 @@
 	tlen = m->m_pkthdr.len;
 
 	dontfrag = 0;
+#ifdef notdef
 	if (dontfrag && alwaysfrag) {	/* case 4 */
 		/* conflicting request - can't transmit */
 		error = EMSGSIZE;
@@ -871,7 +872,7 @@
 		error = EMSGSIZE;
 		goto bad;
 	}
-
+#endif
 	/*
 	 * transmit packet without fragmentation
 	 */
--- a/sys/netinet6/nd6.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/netinet6/nd6.c	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: nd6.c,v 1.99 2006/03/05 23:47:08 rpaulo Exp $	*/
+/*	$NetBSD: nd6.c,v 1.99.2.1 2006/04/19 04:46:12 elad Exp $	*/
 /*	$KAME: nd6.c,v 1.279 2002/06/08 11:16:51 itojun Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nd6.c,v 1.99 2006/03/05 23:47:08 rpaulo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nd6.c,v 1.99.2.1 2006/04/19 04:46:12 elad Exp $");
 
 #include "opt_ipsec.h"
 
@@ -114,6 +114,7 @@
 static int regen_tmpaddr __P((struct in6_ifaddr *));
 static struct llinfo_nd6 *nd6_free __P((struct rtentry *, int));
 static void nd6_llinfo_timer __P((void *));
+static void clear_llinfo_pqueue __P((struct llinfo_nd6 *));
 
 struct callout nd6_slowtimo_ch = CALLOUT_INITIALIZER;
 struct callout nd6_timer_ch = CALLOUT_INITIALIZER;
@@ -457,14 +458,20 @@
 		} else {
 			struct mbuf *m = ln->ln_hold;
 			if (m) {
+				struct mbuf *m0;
+
 				/*
 				 * assuming every packet in ln_hold has
 				 * the same IP header
 				 */
-				ln->ln_hold = NULL;
+				m0 = m->m_nextpkt;
+				m->m_nextpkt = NULL;
 				icmp6_error2(m, ICMP6_DST_UNREACH,
 				    ICMP6_DST_UNREACH_ADDR, 0, rt->rt_ifp);
-			}
+
+				ln->ln_hold = m0;
+				clear_llinfo_pqueue(ln);
+ 			}
 			(void)nd6_free(rt, 0);
 			ln = NULL;
 		}
@@ -1378,8 +1385,7 @@
 		nd6_llinfo_settimer(ln, -1);
 		rt->rt_llinfo = 0;
 		rt->rt_flags &= ~RTF_LLINFO;
-		if (ln->ln_hold)
-			m_freem(ln->ln_hold);
+		clear_llinfo_pqueue(ln);
 		Free((caddr_t)ln);
 	}
 }
@@ -2059,7 +2065,7 @@
 		while (i >= nd6_maxqueuelen) {
 			m_hold = ln->ln_hold;
 			ln->ln_hold = ln->ln_hold->m_nextpkt;
-			m_free(m_hold);
+			m_freem(m_hold);
 			i--;
 		}
 	} else {
@@ -2179,6 +2185,22 @@
 	return (1);
 }
 
+static void 
+clear_llinfo_pqueue(ln)
+	struct llinfo_nd6 *ln;
+{
+	struct mbuf *m_hold, *m_hold_next;
+
+	for (m_hold = ln->ln_hold; m_hold; m_hold = m_hold_next) {
+		m_hold_next = m_hold->m_nextpkt;
+		m_hold->m_nextpkt = NULL;
+		m_freem(m_hold);
+	}
+
+	ln->ln_hold = NULL;
+	return;
+}
+ 
 int
 nd6_sysctl(name, oldp, oldlenp, newp, newlen)
 	int name;
@@ -2275,11 +2297,11 @@
 	}
 
 	if (oldp) {
-		*oldlenp = l;	/* (caddr_t)d - (caddr_t)oldp */
 		if (l > ol)
 			error = ENOMEM;
-	} else
-		*oldlenp = l;
+	}
+	if (oldlenp)
+		*oldlenp = l;	/* (caddr_t)d - (caddr_t)oldp */
 
 	splx(s);
 
--- a/sys/netinet6/nd6_rtr.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/netinet6/nd6_rtr.c	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: nd6_rtr.c,v 1.57 2006/03/06 20:33:52 rpaulo Exp $	*/
+/*	$NetBSD: nd6_rtr.c,v 1.57.2.1 2006/04/19 04:46:12 elad Exp $	*/
 /*	$KAME: nd6_rtr.c,v 1.95 2001/02/07 08:09:47 itojun Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nd6_rtr.c,v 1.57 2006/03/06 20:33:52 rpaulo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nd6_rtr.c,v 1.57.2.1 2006/04/19 04:46:12 elad Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -269,16 +269,7 @@
 	memset(&drtr, 0, sizeof(drtr));
 	drtr.rtaddr = saddr6;
 	drtr.flags  = nd_ra->nd_ra_flags_reserved;
-	if (rtpref(&drtr) == RTPREF_RESERVED) {
-		/*
-		 * "reserved" router preference should be treated as
-		 * 0-lifetime.  Note that rtpref() covers the case that the
-		 * kernel is not cnofigured to support the preference
-		 * extension.
-		 */
-		drtr.rtlifetime = 0;
-	} else 
-		drtr.rtlifetime = ntohs(nd_ra->nd_ra_router_lifetime);
+	drtr.rtlifetime = ntohs(nd_ra->nd_ra_router_lifetime);
 	drtr.expire = time.tv_sec + drtr.rtlifetime;
 	drtr.ifp = ifp;
 	/* unspecified or not? (RFC 2461 6.3.4) */
@@ -736,9 +727,8 @@
 	case ND_RA_FLAG_RTPREF_HIGH:
 		return (RTPREF_HIGH);
 	case ND_RA_FLAG_RTPREF_MEDIUM:
+	case ND_RA_FLAG_RTPREF_RSV:
 		return (RTPREF_MEDIUM);
-	case ND_RA_FLAG_RTPREF_RSV:
-		return (RTPREF_RESERVED);
 	case ND_RA_FLAG_RTPREF_LOW:
 		return (RTPREF_LOW);
 	default:
--- a/sys/netipsec/ipsec.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/netipsec/ipsec.c	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ipsec.c,v 1.20 2006/02/25 02:28:58 wiz Exp $	*/
+/*	$NetBSD: ipsec.c,v 1.20.4.1 2006/04/19 04:46:19 elad Exp $	*/
 /*	$FreeBSD: /usr/local/www/cvsroot/FreeBSD/src/sys/netipsec/ipsec.c,v 1.2.2.2 2003/07/01 01:38:13 sam Exp $	*/
 /*	$KAME: ipsec.c,v 1.103 2001/05/24 07:14:18 sakane Exp $	*/
 
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ipsec.c,v 1.20 2006/02/25 02:28:58 wiz Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ipsec.c,v 1.20.4.1 2006/04/19 04:46:19 elad Exp $");
 
 /*
  * IPsec controller part.
@@ -104,6 +104,18 @@
 
 #ifdef IPSEC_DEBUG
 int ipsec_debug = 1;
+
+/*      
+ * When set to 1, IPsec will send packets with the same sequence number.
+ * This allows to verify if the other side has proper replay attacks detection.
+ */
+int ipsec_replay = 0;
+
+/*  
+ * When set 1, IPsec will send packets with corrupted HMAC.
+ * This allows to verify if the other side properly detects modified packets.
+ */
+int ipsec_integrity = 0;
 #else
 int ipsec_debug = 0;
 #endif
@@ -172,6 +184,10 @@
 	crypto_support,	CTLFLAG_RW,	&crypto_support,0, "");
 SYSCTL_STRUCT(_net_inet_ipsec, OID_AUTO,
 	ipsecstats,	CTLFLAG_RD,	&newipsecstat,	newipsecstat, "");
+SYSCTL_INT(_net_inet_ipsec, OID_AUTO, test_replay, CTLFLAG_RW, &ipsec_replay, 0,
+    "Emulate replay attack");
+SYSCTL_INT(_net_inet_ipsec, OID_AUTO, test_integrity, CTLFLAG_RW,
+    &ipsec_integrity, 0, "Emulate man-in-the-middle attack");
 #endif /* __FreeBSD__ */
 
 #ifdef INET6
--- a/sys/netipsec/ipsec.h	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/netipsec/ipsec.h	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ipsec.h,v 1.14 2006/02/16 20:17:20 perry Exp $	*/
+/*	$NetBSD: ipsec.h,v 1.14.4.1 2006/04/19 04:46:19 elad Exp $	*/
 /*	$FreeBSD: /usr/local/www/cvsroot/FreeBSD/src/sys/netipsec/ipsec.h,v 1.2.4.2 2004/02/14 22:23:23 bms Exp $	*/
 /*	$KAME: ipsec.h,v 1.53 2001/11/20 08:32:38 itojun Exp $	*/
 
@@ -219,6 +219,10 @@
 };
 
 extern int ipsec_debug;
+#ifdef IPSEC_DEBUG
+extern int ipsec_replay;
+extern int ipsec_integrity;
+#endif
 
 extern struct newipsecstat newipsecstat;
 extern struct secpolicy ip4_def_policy;
--- a/sys/netipsec/ipsec_netbsd.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/netipsec/ipsec_netbsd.c	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ipsec_netbsd.c,v 1.15 2005/12/11 12:25:05 christos Exp $	*/
+/*	$NetBSD: ipsec_netbsd.c,v 1.15.10.1 2006/04/19 04:46:19 elad Exp $	*/
 /*	$KAME: esp_input.c,v 1.60 2001/09/04 08:43:19 itojun Exp $	*/
 /*	$KAME: ah_input.c,v 1.64 2001/09/04 08:43:19 itojun Exp $	*/
 
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ipsec_netbsd.c,v 1.15 2005/12/11 12:25:05 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ipsec_netbsd.c,v 1.15.10.1 2006/04/19 04:46:19 elad Exp $");
 
 #include "opt_inet.h"
 #include "opt_ipsec.h"
@@ -359,6 +359,36 @@
 	return (0);
 }
 
+#ifdef IPSEC_DEBUG
+static int
+sysctl_fast_ipsec_test(SYSCTLFN_ARGS)
+{
+	int t, error;
+	struct sysctlnode node;
+
+	node = *rnode; 
+	t = *(int*)rnode->sysctl_data;
+	node.sysctl_data = &t;
+	error = sysctl_lookup(SYSCTLFN_CALL(&node));
+	if (error || newp == NULL)
+		return (error);
+
+	if (t < 0 || t > 1)
+		return EINVAL;
+
+	if (rnode->sysctl_data == &ipsec_replay)
+		printf("fast_ipsec: Anti-Replay service %s\n",
+		    (t == 1) ? "deactivated" : "activated");
+	else if (rnode->sysctl_data == &ipsec_integrity)
+		 printf("fast_ipsec: HMAC corruption %s\n",
+		     (t == 0) ? "deactivated" : "activated");
+
+	*(int*)rnode->sysctl_data = t;
+
+	return 0;
+}
+#endif
+
 /* XXX will need a different oid at parent */
 SYSCTL_SETUP(sysctl_net_inet_fast_ipsec_setup, "sysctl net.inet.ipsec subtree setup")
 {
@@ -551,4 +581,20 @@
 		       NULL, 0, &ipsecstat, sizeof(ipsecstat),
 		       CTL_NET, PF_INET, ipproto_ipsec,
 		       CTL_CREATE, CTL_EOL);
+#ifdef IPSEC_DEBUG
+	sysctl_createv(clog, 0, NULL, NULL,
+		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
+		       CTLTYPE_INT, "test_replay",
+		       SYSCTL_DESCR("Emulate replay attack"),
+		       sysctl_fast_ipsec_test, 0, &ipsec_replay, 0,
+		       CTL_NET, PF_INET, ipproto_ipsec,
+		       CTL_CREATE, CTL_EOL);
+	sysctl_createv(clog, 0, NULL, NULL,
+		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
+		       CTLTYPE_INT, "test_integrity",
+		       SYSCTL_DESCR("Emulate man-in-the-middle attack"),
+		       sysctl_fast_ipsec_test, 0, &ipsec_integrity, 0,
+		       CTL_NET, PF_INET, ipproto_ipsec,
+		       CTL_CREATE, CTL_EOL);
+#endif
 }
--- a/sys/netipsec/xform_ah.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/netipsec/xform_ah.c	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: xform_ah.c,v 1.9 2005/12/11 12:25:06 christos Exp $	*/
+/*	$NetBSD: xform_ah.c,v 1.9.10.1 2006/04/19 04:46:19 elad Exp $	*/
 /*	$FreeBSD: src/sys/netipsec/xform_ah.c,v 1.1.4.1 2003/01/24 05:11:36 sam Exp $	*/
 /*	$OpenBSD: ip_ah.c,v 1.63 2001/06/26 06:18:58 angelos Exp $ */
 /*
@@ -39,7 +39,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xform_ah.c,v 1.9 2005/12/11 12:25:06 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xform_ah.c,v 1.9.10.1 2006/04/19 04:46:19 elad Exp $");
 
 #include "opt_inet.h"
 #ifdef __FreeBSD__
@@ -1071,7 +1071,11 @@
 			error = EINVAL;
 			goto bad;
 		}
-		sav->replay->count++;
+#ifdef IPSEC_DEBUG
+		/* Emulate replay attack when ipsec_replay is TRUE. */
+		if (!ipsec_replay)
+#endif
+			sav->replay->count++;
 		ah->ah_seq = htonl(sav->replay->count);
 	}
 
@@ -1247,6 +1251,20 @@
 	free(tc, M_XDATA);
 	crypto_freereq(crp);
 
+#ifdef IPSEC_DEBUG
+	/* Emulate man-in-the-middle attack when ipsec_integrity is TRUE. */
+	if (ipsec_integrity) {
+		int alen;
+
+		/*
+		 * Corrupt HMAC if we want to test integrity verification of
+		 * the other side.
+		 */
+		alen = AUTHSIZE(sav);
+		m_copyback(m, m->m_pkthdr.len - alen, alen, ipseczeroes);
+	}
+#endif
+
 	/* NB: m is reclaimed by ipsec_process_done. */
 	err = ipsec_process_done(m, isr);
 	KEY_FREESAV(&sav);
--- a/sys/netipsec/xform_esp.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/netipsec/xform_esp.c	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: xform_esp.c,v 1.7 2005/12/11 12:25:06 christos Exp $	*/
+/*	$NetBSD: xform_esp.c,v 1.7.10.1 2006/04/19 04:46:19 elad Exp $	*/
 /*	$FreeBSD: src/sys/netipsec/xform_esp.c,v 1.2.2.1 2003/01/24 05:11:36 sam Exp $	*/
 /*	$OpenBSD: ip_esp.c,v 1.69 2001/06/26 06:18:59 angelos Exp $ */
 
@@ -39,7 +39,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xform_esp.c,v 1.7 2005/12/11 12:25:06 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xform_esp.c,v 1.7.10.1 2006/04/19 04:46:19 elad Exp $");
 
 #include "opt_inet.h"
 #ifdef __FreeBSD__
@@ -568,6 +568,23 @@
 	 */
 	m->m_flags |= M_DECRYPTED;
 
+	/*
+	 * Update replay sequence number, if appropriate.
+	 */
+	if (sav->replay) {
+		u_int32_t seq;
+
+		m_copydata(m, skip + offsetof(struct newesp, esp_seq),
+		    sizeof (seq), (caddr_t) &seq);
+		if (ipsec_updatereplay(ntohl(seq), sav)) {
+			DPRINTF(("%s: packet replay check for %s\n", __func__,
+			    ipsec_logsastr(sav)));
+			espstat.esps_replay++;
+			error = ENOBUFS;
+			goto bad;
+		}
+	}
+
 	/* Determine the ESP header length */
 	if (sav->flags & SADB_X_EXT_OLD)
 		hlen = sizeof (struct esp) + sav->ivlen;
@@ -753,7 +770,15 @@
 	/* Initialize ESP header. */
 	bcopy((caddr_t) &sav->spi, mtod(mo, caddr_t) + roff, sizeof(u_int32_t));
 	if (sav->replay) {
-		u_int32_t replay = htonl(++(sav->replay->count));
+		u_int32_t replay;
+
+#ifdef IPSEC_DEBUG
+		/* Emulate replay attack when ipsec_replay is TRUE. */
+		if (!ipsec_replay)
+#endif
+			sav->replay->count++;
+
+		replay = htonl(sav->replay->count);
 		bcopy((caddr_t) &replay,
 		    mtod(mo, caddr_t) + roff + sizeof(u_int32_t),
 		    sizeof(u_int32_t));
@@ -932,6 +957,24 @@
 	free(tc, M_XDATA);
 	crypto_freereq(crp);
 
+#ifdef IPSEC_DEBUG
+	/* Emulate man-in-the-middle attack when ipsec_integrity is TRUE. */
+	if (ipsec_integrity) {
+		static unsigned char ipseczeroes[AH_HMAC_HASHLEN];
+		struct auth_hash *esph;
+
+		/*
+		 * Corrupt HMAC if we want to test integrity verification of
+		 * the other side.
+		 */
+		esph = sav->tdb_authalgxform;
+		if (esph !=  NULL) {
+			m_copyback(m, m->m_pkthdr.len - AH_HMAC_HASHLEN,
+			    AH_HMAC_HASHLEN, ipseczeroes);
+		}
+	}
+#endif
+
 	/* NB: m is reclaimed by ipsec_process_done. */
 	err = ipsec_process_done(m, isr);
 	KEY_FREESAV(&sav);
--- a/sys/netisdn/i4b_q931.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/netisdn/i4b_q931.c	Wed Apr 19 04:46:10 2006 +0000
@@ -27,7 +27,7 @@
  *	i4b_q931.c - Q931 received messages handling
  *	--------------------------------------------
  *
- *	$Id: i4b_q931.c,v 1.18 2005/12/11 12:25:06 christos Exp $
+ *	$Id: i4b_q931.c,v 1.18.10.1 2006/04/19 04:46:19 elad Exp $
  *
  * $FreeBSD$
  *
@@ -36,7 +36,7 @@
  *---------------------------------------------------------------------------*/
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: i4b_q931.c,v 1.18 2005/12/11 12:25:06 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i4b_q931.c,v 1.18.10.1 2006/04/19 04:46:19 elad Exp $");
 
 #ifdef __FreeBSD__
 #include "i4bq931.h"
@@ -298,7 +298,7 @@
 			{
 				case 0x80:	/* speech */
 				case 0x89:	/* restricted digital info */
-				case 0x90:	/* 3.1KHz audio */
+				case 0x90:	/* 3.1 kHz audio */
 /* XXX */				cd->bprot = BPROT_NONE;
 					NDBGL3(L3_P_MSG, "IEI_BEARERCAP - Telephony");
 					break;
--- a/sys/netiso/iso_chksum.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/netiso/iso_chksum.c	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: iso_chksum.c,v 1.21 2005/12/11 12:25:12 christos Exp $	*/
+/*	$NetBSD: iso_chksum.c,v 1.21.10.1 2006/04/19 04:46:19 elad Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -75,7 +75,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: iso_chksum.c,v 1.21 2005/12/11 12:25:12 christos Exp $");
+__KERNEL_RCSID(1, "$NetBSD: iso_chksum.c,v 1.21.10.1 2006/04/19 04:46:19 elad Exp $");
 
 #include "opt_iso.h"
 
@@ -267,10 +267,12 @@
 #endif
 
 	c1 = (((c0 * (l - n)) - c1) % 255);
-	*xloc = (u_char) ((c1 < 0) ? c1 + 255 : c1);
+	if (xloc)
+		*xloc = (u_char) ((c1 < 0) ? c1 + 255 : c1);
 
 	c1 = (-(int) (c1 + c0)) % 255;
-	*yloc = (u_char) (c1 < 0 ? c1 + 255 : c1);
+	if (yloc)
+		*yloc = (u_char) (c1 < 0 ? c1 + 255 : c1);
 
 #ifdef ARGO_DEBUG
 	if (argo_debug[D_CHKSUM]) {
--- a/sys/netiso/tp_emit.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/netiso/tp_emit.c	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: tp_emit.c,v 1.22 2005/12/11 12:25:12 christos Exp $	*/
+/*	$NetBSD: tp_emit.c,v 1.22.10.1 2006/04/19 04:46:19 elad Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -72,7 +72,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tp_emit.c,v 1.22 2005/12/11 12:25:12 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tp_emit.c,v 1.22.10.1 2006/04/19 04:46:19 elad Exp $");
 
 #include "opt_iso.h"
 
@@ -204,13 +204,13 @@
 	} else {
 		MGETHDR(m, M_DONTWAIT, TPMT_TPHDR);
 	}
-	m->m_data += max_hdr;
 	if (m == NULL) {
 		if (data != (struct mbuf *) 0)
 			m_freem(data);
 		error = ENOBUFS;
 		goto done;
 	}
+	m->m_data += max_hdr;
 	m->m_len = sizeof(struct tpdu);
 	m->m_nextpkt = NULL;
 
--- a/sys/netiso/tp_output.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/netiso/tp_output.c	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: tp_output.c,v 1.27.10.2 2006/03/10 15:14:17 elad Exp $	*/
+/*	$NetBSD: tp_output.c,v 1.27.10.3 2006/04/19 04:46:19 elad Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -62,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tp_output.c,v 1.27.10.2 2006/03/10 15:14:17 elad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tp_output.c,v 1.27.10.3 2006/04/19 04:46:19 elad Exp $");
 
 #include "opt_inet.h"
 #include "opt_iso.h"
@@ -413,7 +413,7 @@
 		error = ENOTSOCK;
 		goto done;
 	}
-	if (*mp == NULL) {
+	if (mp && *mp == NULL) {
 		struct mbuf *m;
 
 		MGET(m, M_DONTWAIT, TPMT_SONAME);	/* does off, type, next */
--- a/sys/netiso/tp_pcb.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/netiso/tp_pcb.c	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: tp_pcb.c,v 1.28 2005/12/28 09:18:46 christos Exp $	*/
+/*	$NetBSD: tp_pcb.c,v 1.28.10.1 2006/04/19 04:46:19 elad Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -68,7 +68,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tp_pcb.c,v 1.28 2005/12/28 09:18:46 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tp_pcb.c,v 1.28.10.1 2006/04/19 04:46:19 elad Exp $");
 
 #include "opt_inet.h"
 #include "opt_iso.h"
@@ -692,8 +692,11 @@
 	ASSERT(tpcb->tp_nlproto->nlp_afamily == tpcb->tp_domain);
 
 	/* nothing to do for iso case */
-	if (dom == AF_INET)
+	if (dom == AF_INET) {
+		/* tp_set_npcb sets it */
+		KASSERT(so->so_pcb != NULL);
 		sotoinpcb(so)->inp_ppcb = (caddr_t) tpcb;
+	}
 
 	return 0;
 
--- a/sys/netns/idp_usrreq.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/netns/idp_usrreq.c	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: idp_usrreq.c,v 1.25.10.2 2006/03/10 15:14:17 elad Exp $	*/
+/*	$NetBSD: idp_usrreq.c,v 1.25.10.3 2006/04/19 04:46:19 elad Exp $	*/
 
 /*
  * Copyright (c) 1984, 1985, 1986, 1987, 1993
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: idp_usrreq.c,v 1.25.10.2 2006/03/10 15:14:17 elad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: idp_usrreq.c,v 1.25.10.3 2006/04/19 04:46:19 elad Exp $");
 
 #include "opt_ns.h"			/* NSIP: Xerox NS over IP */
 
@@ -155,7 +155,6 @@
 	struct mbuf *m;
 	struct idp *idp;
 	int len = m0->m_pkthdr.len;
-	struct mbuf *mprev = NULL;
 	extern int idpcksum;
 	va_list ap;
 
@@ -168,6 +167,11 @@
 	 */
 
 	if (len & 1) {
+		struct mbuf *mprev;
+
+		for (mprev = NULL, m = m0; m; m = m->m_next)
+			mprev = m;
+
 		m = mprev;
 		if ((m->m_flags & M_EXT) == 0 &&
 			(m->m_len + m->m_data < &m->m_dat[MLEN])) {
--- a/sys/netns/ns_error.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/netns/ns_error.c	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ns_error.c,v 1.18 2005/12/11 12:25:16 christos Exp $	*/
+/*	$NetBSD: ns_error.c,v 1.18.10.1 2006/04/19 04:46:19 elad Exp $	*/
 
 /*
  * Copyright (c) 1984, 1988, 1993
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ns_error.c,v 1.18 2005/12/11 12:25:16 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ns_error.c,v 1.18.10.1 2006/04/19 04:46:19 elad Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -233,7 +233,7 @@
 	if (ns_errprintfs)
 		printf("ns_err_input, type %d param %d\n", type, param);
 #endif
-	if (type >= NS_ERR_TOO_BIG) {
+	if (type > NS_ERR_TOO_BIG) {
 		goto badcode;
 	}
 	ns_errstat.ns_es_outhist[ns_err_x(type)]++;
--- a/sys/netns/spp_usrreq.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/netns/spp_usrreq.c	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: spp_usrreq.c,v 1.43 2005/12/11 12:25:16 christos Exp $	*/
+/*	$NetBSD: spp_usrreq.c,v 1.43.10.1 2006/04/19 04:46:19 elad Exp $	*/
 
 /*
  * Copyright (c) 1984, 1985, 1986, 1987, 1993
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: spp_usrreq.c,v 1.43 2005/12/11 12:25:16 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: spp_usrreq.c,v 1.43.10.1 2006/04/19 04:46:19 elad Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -1033,15 +1033,17 @@
 		 * must make a copy of this packet for
 		 * idp_output to monkey with
 		 */
-		m = m_copy(m, 0, (int)M_COPYALL);
-		if (m == NULL) {
-			return (ENOBUFS);
+		if (m) {
+			m = m_copy(m, 0, (int)M_COPYALL);
+			if (m == NULL) {
+				return (ENOBUFS);
+			}
+			si = mtod(m, struct spidp *);
+			if (SSEQ_LT(si->si_seq, cb->s_smax))
+				sppstat.spps_sndrexmitpack++;
+			else
+				sppstat.spps_sndpack++;
 		}
-		si = mtod(m, struct spidp *);
-		if (SSEQ_LT(si->si_seq, cb->s_smax))
-			sppstat.spps_sndrexmitpack++;
-		else
-			sppstat.spps_sndpack++;
 	} else if (cb->s_force || cb->s_flags & SF_ACKNOW) {
 		/*
 		 * Must send an acknowledgement or a probe
@@ -1125,6 +1127,8 @@
 		si->si_alo = htons(alo);
 		si->si_ack = htons(cb->s_ack);
 
+		if (m == NULL)
+			return EINVAL;
 		if (idpcksum) {
 			si->si_sum = 0;
 			len = ntohs(si->si_len);
--- a/sys/netsmb/smb_iod.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/netsmb/smb_iod.c	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: smb_iod.c,v 1.25 2005/12/24 20:45:09 perry Exp $	*/
+/*	$NetBSD: smb_iod.c,v 1.25.10.1 2006/04/19 04:46:19 elad Exp $	*/
 
 /*
  * Copyright (c) 2000-2001 Boris Popov
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: smb_iod.c,v 1.25 2005/12/24 20:45:09 perry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: smb_iod.c,v 1.25.10.1 2006/04/19 04:46:19 elad Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -290,7 +290,7 @@
 	/*
 	 * Check for fatal errors
 	 */
-	if (SMB_TRAN_FATAL(vcp, error)) {
+	if (vcp && SMB_TRAN_FATAL(vcp, error)) {
 		/*
 		 * No further attempts should be made
 		 */
--- a/sys/netsmb/smb_subr.c	Wed Apr 19 04:32:08 2006 +0000
+++ b/sys/netsmb/smb_subr.c	Wed Apr 19 04:46:10 2006 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: smb_subr.c,v 1.24.10.1 2006/03/08 01:24:59 elad Exp $	*/
+/*	$NetBSD: smb_subr.c,v 1.24.10.2 2006/04/19 04:46:19 elad Exp $	*/
 
 /*
  * Copyright (c) 2000-2001 Boris Popov
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: smb_subr.c,v 1.24.10.1 2006/03/08 01:24:59 elad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: smb_subr.c,v 1.24.10.2 2006/04/19 04:46:19 elad Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -65,13 +65,9 @@
 void
 smb_makescred(struct smb_cred *scred, struct lwp *l, kauth_cred_t cred)
 {
-	struct proc *p;
-
 	if (l) {
-		p = l ? l->l_proc : NULL;
-
 		scred->scr_l = l;
-		scred->scr_cred = cred ? cred : p->p_cred;
+		scred->scr_cred = cred ? cred : l->l_proc->p_cred;
 	} else {
 		scred->scr_l = NULL;
 		scred->scr_cred = cred ? cred : NULL;