sync with head. yamt-lazymbuf
authoryamt <yamt@NetBSD.org>
Mon, 03 Sep 2007 14:41:57 +0000
branchyamt-lazymbuf
changeset 288718 f4846e4be676
parent 288717 e3f004290844
child 288719 2585b0d1dc7d
sync with head.
sys/miscfs/procfs/procfs_vnops.c
sys/miscfs/specfs/spec_vnops.c
sys/miscfs/specfs/specdev.h
sys/miscfs/syncfs/sync_subr.c
sys/miscfs/syncfs/sync_vnops.c
sys/miscfs/umapfs/umap_subr.c
sys/miscfs/umapfs/umap_vfsops.c
sys/net/agr/ieee8023ad_lacp.c
sys/net/agr/if_agr.c
sys/net/agr/if_agrether.c
sys/net/agr/if_agrether_hash.c
sys/net/agr/if_agrsubr.c
sys/net/agr/if_agrtimer.c
sys/net/agr/if_agrvar_impl.h
sys/net/bpf.c
sys/net/bpfdesc.h
sys/net/bridgestp.c
sys/net/if.c
sys/net/if.h
sys/net/if_arcsubr.c
sys/net/if_arp.h
sys/net/if_atmsubr.c
sys/net/if_bridge.c
sys/net/if_bridgevar.h
sys/net/if_dl.h
sys/net/if_ecosubr.c
sys/net/if_ether.h
sys/net/if_etherip.c
sys/net/if_etherip.h
sys/net/if_ethersubr.c
sys/net/if_faith.c
sys/net/if_fddi.h
sys/net/if_fddisubr.c
sys/net/if_gif.c
sys/net/if_gif.h
sys/net/if_gre.c
sys/net/if_gre.h
sys/net/if_hippi.h
sys/net/if_hippisubr.c
sys/net/if_ieee1394.h
sys/net/if_ieee1394subr.c
sys/net/if_loop.c
sys/net/if_media.c
sys/net/if_ppp.c
sys/net/if_pppoe.c
sys/net/if_pppoe.h
sys/net/if_pppvar.h
sys/net/if_sl.c
sys/net/if_slvar.h
sys/net/if_spppsubr.c
sys/net/if_srt.c
sys/net/if_stf.c
sys/net/if_strip.c
sys/net/if_stripvar.h
sys/net/if_tap.c
sys/net/if_token.h
sys/net/if_tokensubr.c
sys/net/if_tun.c
sys/net/if_vlan.c
sys/net/link_proto.c
sys/net/net_osdep.h
sys/net/netisr.h
sys/net/netisr_dispatch.h
sys/net/ppp_tty.c
sys/net/radix.c
sys/net/radix.h
sys/net/raw_cb.c
sys/net/raw_usrreq.c
sys/net/route.c
sys/net/route.h
sys/net/rtsock.c
sys/net/slcompress.c
sys/net80211/ieee80211_input.c
sys/net80211/ieee80211_ioctl.c
sys/net80211/ieee80211_netbsd.c
sys/net80211/ieee80211_netbsd.h
sys/net80211/ieee80211_output.c
sys/net80211/ieee80211_radiotap.h
sys/net80211/ieee80211_var.h
sys/netatalk/aarp.c
sys/netatalk/at_control.c
sys/netatalk/at_extern.h
sys/netatalk/at_proto.c
sys/netatalk/at_var.h
sys/netatalk/ddp_input.c
sys/netatalk/ddp_usrreq.c
sys/netbt/bluetooth.h
sys/netbt/bt_proto.c
sys/netbt/hci.h
sys/netbt/hci_event.c
sys/netbt/hci_link.c
sys/netbt/hci_socket.c
sys/netbt/hci_unit.c
sys/netbt/l2cap.h
sys/netbt/l2cap_lower.c
sys/netbt/l2cap_misc.c
sys/netbt/l2cap_signal.c
sys/netbt/l2cap_socket.c
sys/netbt/l2cap_upper.c
sys/netbt/rfcomm.h
sys/netbt/rfcomm_dlc.c
sys/netbt/rfcomm_session.c
sys/netbt/rfcomm_socket.c
sys/netbt/rfcomm_upper.c
sys/netbt/sco_socket.c
sys/netbt/sco_upper.c
sys/netinet/Makefile
sys/netinet/files.netinet
sys/netinet/if_arp.c
sys/netinet/if_atm.c
sys/netinet/if_inarp.h
sys/netinet/igmp.c
sys/netinet/in.c
sys/netinet/in.h
sys/netinet/in4_cksum.c
sys/netinet/in_gif.c
sys/netinet/in_offload.c
sys/netinet/in_offload.h
sys/netinet/in_pcb.c
sys/netinet/in_pcb_hdr.h
sys/netinet/in_proto.c
sys/netinet/in_route.c
sys/netinet/in_route.h
sys/netinet/in_var.h
sys/netinet/ip6.h
sys/netinet/ip_carp.c
sys/netinet/ip_encap.c
sys/netinet/ip_etherip.c
sys/netinet/ip_flow.c
sys/netinet/ip_gre.c
sys/netinet/ip_icmp.c
sys/netinet/ip_input.c
sys/netinet/ip_mroute.c
sys/netinet/ip_mroute.h
sys/netinet/ip_output.c
sys/netinet/ip_var.h
sys/netinet/raw_ip.c
sys/netinet/tcp.h
sys/netinet/tcp_congctl.c
sys/netinet/tcp_debug.c
sys/netinet/tcp_debug.h
sys/netinet/tcp_input.c
sys/netinet/tcp_output.c
sys/netinet/tcp_sack.c
sys/netinet/tcp_subr.c
sys/netinet/tcp_timer.c
sys/netinet/tcp_timer.h
sys/netinet/tcp_usrreq.c
sys/netinet/tcp_var.h
sys/netinet/udp_usrreq.c
sys/netinet6/ah_aesxcbcmac.c
sys/netinet6/ah_core.c
sys/netinet6/ah_input.c
sys/netinet6/ah_output.c
sys/netinet6/esp_aesctr.c
sys/netinet6/esp_core.c
sys/netinet6/esp_input.c
sys/netinet6/esp_output.c
sys/netinet6/files.netinet6
sys/netinet6/frag6.c
sys/netinet6/icmp6.c
sys/netinet6/in6.c
sys/netinet6/in6.h
sys/netinet6/in6_cksum.c
sys/netinet6/in6_gif.c
sys/netinet6/in6_ifattach.c
sys/netinet6/in6_offload.c
sys/netinet6/in6_offload.h
sys/netinet6/in6_pcb.c
sys/netinet6/in6_pcb.h
sys/netinet6/in6_proto.c
sys/netinet6/in6_src.c
sys/netinet6/in6_var.h
sys/netinet6/ip6_etherip.c
sys/netinet6/ip6_flow.c
sys/netinet6/ip6_forward.c
sys/netinet6/ip6_input.c
sys/netinet6/ip6_mroute.c
sys/netinet6/ip6_mroute.h
sys/netinet6/ip6_output.c
sys/netinet6/ip6_var.h
sys/netinet6/ip6protosw.h
sys/netinet6/ipcomp_core.c
sys/netinet6/ipcomp_input.c
sys/netinet6/ipcomp_output.c
sys/netinet6/ipsec.c
sys/netinet6/ipsec.h
sys/netinet6/mld6.c
sys/netinet6/nd6.c
sys/netinet6/nd6.h
sys/netinet6/nd6_nbr.c
sys/netinet6/nd6_rtr.c
sys/netinet6/raw_ip6.c
sys/netinet6/route6.c
sys/netinet6/udp6_output.c
sys/netinet6/udp6_usrreq.c
sys/netipsec/ipsec.c
sys/netipsec/ipsec.h
sys/netipsec/ipsec6.h
sys/netipsec/ipsec_input.c
sys/netipsec/ipsec_mbuf.c
sys/netipsec/ipsec_netbsd.c
sys/netipsec/ipsec_output.c
sys/netipsec/key.c
sys/netipsec/key.h
sys/netipsec/key_debug.c
sys/netipsec/key_debug.h
sys/netipsec/keydb.h
sys/netipsec/keysock.c
sys/netipsec/keysock.h
sys/netipsec/xform.h
sys/netipsec/xform_ah.c
sys/netipsec/xform_esp.c
sys/netipsec/xform_ipcomp.c
sys/netipsec/xform_ipip.c
sys/netisdn/i4b_ctl.c
sys/netisdn/i4b_i4bdrv.c
sys/netisdn/i4b_ipr.c
sys/netisdn/i4b_isppp.c
sys/netisdn/i4b_isppp.h
sys/netisdn/i4b_l1l2.h
sys/netisdn/i4b_l2.c
sys/netisdn/i4b_l2.h
sys/netisdn/i4b_l4mgmt.c
sys/netisdn/i4b_rbch.c
sys/netisdn/i4b_tel.c
sys/netisdn/i4b_trace.c
sys/netiso/clnp.h
sys/netiso/clnp_er.c
sys/netiso/clnp_frag.c
sys/netiso/clnp_input.c
sys/netiso/clnp_options.c
sys/netiso/clnp_output.c
sys/netiso/clnp_raw.c
sys/netiso/clnp_subr.c
sys/netiso/cltp_usrreq.c
sys/netiso/eonvar.h
sys/netiso/esis.c
sys/netiso/esis.h
sys/netiso/idrp_usrreq.c
sys/netiso/if_eon.c
sys/netiso/iso.c
sys/netiso/iso.h
sys/netiso/iso_chksum.c
sys/netiso/iso_pcb.c
sys/netiso/iso_pcb.h
sys/netiso/iso_proto.c
sys/netiso/iso_snpac.c
sys/netiso/iso_var.h
sys/netiso/tp_cons.c
sys/netiso/tp_emit.c
sys/netiso/tp_inet.c
sys/netiso/tp_input.c
sys/netiso/tp_iso.c
sys/netiso/tp_meas.c
sys/netiso/tp_output.c
sys/netiso/tp_param.h
sys/netiso/tp_pcb.c
sys/netiso/tp_pcb.h
sys/netiso/tp_subr.c
sys/netiso/tp_subr2.c
sys/netiso/tp_timer.c
sys/netiso/tp_trace.c
sys/netiso/tp_usrreq.c
sys/netiso/tp_var.h
sys/netkey/key.c
sys/netkey/key.h
sys/netkey/key_debug.c
sys/netkey/key_debug.h
sys/netkey/keydb.h
sys/netkey/keysock.c
sys/netnatm/natm.c
sys/netnatm/natm_proto.c
sys/netsmb/mchain.h
sys/netsmb/smb_dev.c
sys/netsmb/smb_iod.c
sys/netsmb/smb_rq.c
sys/netsmb/smb_smb.c
sys/netsmb/smb_trantcp.c
sys/netsmb/smb_usr.c
sys/netsmb/subr_mchain.c
sys/nfs/krpc_subr.c
sys/nfs/nfs.h
sys/nfs/nfs_bio.c
sys/nfs/nfs_boot.c
sys/nfs/nfs_bootdhcp.c
sys/nfs/nfs_bootparam.c
sys/nfs/nfs_bootstatic.c
sys/nfs/nfs_export.c
sys/nfs/nfs_kq.c
sys/nfs/nfs_node.c
sys/nfs/nfs_serv.c
sys/nfs/nfs_socket.c
sys/nfs/nfs_srvcache.c
sys/nfs/nfs_subs.c
sys/nfs/nfs_syscalls.c
sys/nfs/nfs_var.h
sys/nfs/nfs_vfsops.c
sys/nfs/nfs_vnops.c
sys/nfs/nfsdiskless.h
sys/nfs/nfsm_subs.h
sys/nfs/nfsmount.h
sys/nfs/nfsnode.h
sys/nfs/nfsrvcache.h
sys/opencrypto/criov.c
sys/opencrypto/crypto.c
sys/opencrypto/cryptodev.c
sys/opencrypto/cryptodev.h
sys/opencrypto/cryptosoft.c
sys/opencrypto/cryptosoft.h
sys/opencrypto/cryptosoft_xform.c
sys/opencrypto/deflate.c
sys/rump/Makefile
sys/rump/Makefile.rump
sys/rump/README.dirs
sys/rump/fs/Makefile
sys/rump/fs/Makefile.rumpfs
sys/rump/fs/bin/Makefile
sys/rump/fs/bin/Makefile.inc
sys/rump/fs/bin/cd9660fs/Makefile
sys/rump/fs/bin/cd9660fs/cd9660fs.c
sys/rump/fs/bin/efs/Makefile
sys/rump/fs/bin/efs/efs.c
sys/rump/fs/bin/ext2fs/Makefile
sys/rump/fs/bin/ext2fs/ext2fs.c
sys/rump/fs/bin/ffs/Makefile
sys/rump/fs/bin/ffs/ffs.c
sys/rump/fs/bin/fsconsole/Makefile
sys/rump/fs/bin/fsconsole/fsconsole.c
sys/rump/fs/bin/hfs/Makefile
sys/rump/fs/bin/hfs/hfs.c
sys/rump/fs/bin/lfs/Makefile
sys/rump/fs/bin/lfs/lfs.c
sys/rump/fs/bin/msdosfs/Makefile
sys/rump/fs/bin/msdosfs/msdosfs.c
sys/rump/fs/bin/ntfs/Makefile
sys/rump/fs/bin/ntfs/ntfs.c
sys/rump/fs/bin/tmpfs/Makefile
sys/rump/fs/bin/tmpfs/tmpfs.c
sys/rump/fs/bin/udf/Makefile
sys/rump/fs/bin/udf/udf.c
sys/rump/fs/lib/Makefile
sys/rump/fs/lib/Makefile.inc
sys/rump/fs/lib/libcd9660fs/Makefile
sys/rump/fs/lib/libefs/Makefile
sys/rump/fs/lib/libext2fs/Makefile
sys/rump/fs/lib/libffs/Makefile
sys/rump/fs/lib/libhfs/Makefile
sys/rump/fs/lib/liblfs/Makefile
sys/rump/fs/lib/libmsdosfs/Makefile
sys/rump/fs/lib/libnfs/Makefile
sys/rump/fs/lib/libntfs/Makefile
sys/rump/fs/lib/libp2k/Makefile
sys/rump/fs/lib/libp2k/p2k.c
sys/rump/fs/lib/libp2k/p2k.h
sys/rump/fs/lib/libtmpfs/Makefile
sys/rump/fs/lib/libudf/Makefile
sys/rump/fs/lib/libufs/Makefile
sys/rump/fs/lib/libufs/fs_ffs.h
sys/rump/fs/lib/libukfs/Makefile
sys/rump/fs/lib/libukfs/ukfs.c
sys/rump/fs/lib/libukfs/ukfs.h
sys/rump/include/machine/bswap.h
sys/rump/include/machine/cpu.h
sys/rump/include/machine/intr.h
sys/rump/include/machine/pmap.h
sys/rump/librump/Makefile
sys/rump/librump/rumpkern/Makefile
sys/rump/librump/rumpkern/auth.c
sys/rump/librump/rumpkern/emul.c
sys/rump/librump/rumpkern/fstrans_stub.c
sys/rump/librump/rumpkern/genfs.c
sys/rump/librump/rumpkern/lock.c
sys/rump/librump/rumpkern/lock_stub.c
sys/rump/librump/rumpkern/misc_stub.c
sys/rump/librump/rumpkern/opt/config_file.h
sys/rump/librump/rumpkern/opt/fs_ffs.h
sys/rump/librump/rumpkern/opt/fs_union.h
sys/rump/librump/rumpkern/opt/opt_bufcache.h
sys/rump/librump/rumpkern/opt/opt_ddb.h
sys/rump/librump/rumpkern/opt/opt_hz.h
sys/rump/librump/rumpkern/opt/opt_ktrace.h
sys/rump/librump/rumpkern/opt/opt_multiprocessor.h
sys/rump/librump/rumpkern/opt/opt_nmbclusters.h
sys/rump/librump/rumpkern/opt/opt_ptrace.h
sys/rump/librump/rumpkern/opt/opt_revcache.h
sys/rump/librump/rumpkern/opt/opt_rtc_offset.h
sys/rump/librump/rumpkern/opt/opt_softdep.h
sys/rump/librump/rumpkern/opt/opt_sysv.h
sys/rump/librump/rumpkern/opt/opt_sysvparam.h
sys/rump/librump/rumpkern/opt/opt_vnode_lockdebug.h
sys/rump/librump/rumpkern/opt/veriexec.h
sys/rump/librump/rumpkern/pmap_stub.c
sys/rump/librump/rumpkern/pool.c
sys/rump/librump/rumpkern/rump.c
sys/rump/librump/rumpkern/rump.h
sys/rump/librump/rumpkern/rump_private.h
sys/rump/librump/rumpkern/specfs.c
sys/rump/librump/rumpkern/vfs.c
sys/rump/librump/rumpkern/vfsops_stub.c
sys/rump/librump/rumpkern/vm.c
sys/rump/librump/rumpuser/Makefile
sys/rump/librump/rumpuser/rumpuser.c
sys/rump/librump/rumpuser/rumpuser.h
sys/secmodel/bsd44/secmodel_bsd44_securelevel.c
sys/sys/Makefile
sys/sys/aio.h
sys/sys/ataio.h
sys/sys/audioio.h
sys/sys/bootblock.h
sys/sys/buf.h
sys/sys/callback.h
sys/sys/callout.h
sys/sys/cctr.h
sys/sys/cdio.h
sys/sys/clockctl.h
sys/sys/condvar.h
sys/sys/conf.h
sys/sys/cpu.h
sys/sys/cpu_data.h
sys/sys/cpuio.h
sys/sys/device.h
sys/sys/disk.h
sys/sys/disklabel.h
sys/sys/dkio.h
sys/sys/domain.h
sys/sys/endian.h
sys/sys/envsys.h
sys/sys/evcnt.h
sys/sys/event.h
sys/sys/exec.h
sys/sys/exec_elf.h
sys/sys/extent.h
sys/sys/file.h
sys/sys/fileassoc.h
sys/sys/filedesc.h
sys/sys/fstrans.h
sys/sys/fstypes.h
sys/sys/gcq.h
sys/sys/gennameih.awk
sys/sys/idle.h
sys/sys/ioccom.h
sys/sys/kauth.h
sys/sys/kcont.h
sys/sys/kernel.h
sys/sys/kprintf.h
sys/sys/ksyms.h
sys/sys/kthread.h
sys/sys/ktrace.h
sys/sys/lkm.h
sys/sys/localedef.h
sys/sys/lock.h
sys/sys/lockdebug.h
sys/sys/lwp.h
sys/sys/malloc.h
sys/sys/mallocvar.h
sys/sys/mbuf.h
sys/sys/mman.h
sys/sys/mount.h
sys/sys/mutex.h
sys/sys/namei.h
sys/sys/namei.src
sys/sys/param.h
sys/sys/pax.h
sys/sys/pipe.h
sys/sys/pool.h
sys/sys/power.h
sys/sys/proc.h
sys/sys/prot.h
sys/sys/protosw.h
sys/sys/ptrace.h
sys/sys/queue.h
sys/sys/ras.h
sys/sys/resourcevar.h
sys/sys/sched.h
sys/sys/scsiio.h
sys/sys/select.h
sys/sys/selinfo.h
sys/sys/sem.h
sys/sys/siginfo.h
sys/sys/simplelock.h
sys/sys/sleepq.h
sys/sys/socket.h
sys/sys/socketvar.h
sys/sys/sockio.h
sys/sys/spl.h
sys/sys/statvfs.h
sys/sys/syncobj.h
sys/sys/syscall.h
sys/sys/syscallargs.h
sys/sys/sysctl.h
sys/sys/systm.h
sys/sys/systrace.h
sys/sys/time.h
sys/sys/timepps.h
sys/sys/timevar.h
sys/sys/tty.h
sys/sys/types.h
sys/sys/ucred.h
sys/sys/un.h
sys/sys/unistd.h
sys/sys/unpcb.h
sys/sys/uuid.h
sys/sys/verified_exec.h
sys/sys/vfs_syscalls.h
sys/sys/vmem.h
sys/sys/vnode.h
sys/sys/vnode_if.h
sys/sys/wait.h
sys/sys/workqueue.h
sys/ufs/ext2fs/ext2fs_extern.h
sys/ufs/ext2fs/ext2fs_inode.c
sys/ufs/ext2fs/ext2fs_lookup.c
sys/ufs/ext2fs/ext2fs_readwrite.c
sys/ufs/ext2fs/ext2fs_vfsops.c
sys/ufs/ext2fs/ext2fs_vnops.c
sys/ufs/ffs/ffs_alloc.c
sys/ufs/ffs/ffs_balloc.c
sys/ufs/ffs/ffs_extern.h
sys/ufs/ffs/ffs_inode.c
sys/ufs/ffs/ffs_snapshot.c
sys/ufs/ffs/ffs_softdep.c
sys/ufs/ffs/ffs_softdep.stub.c
sys/ufs/ffs/ffs_vfsops.c
sys/ufs/ffs/ffs_vnops.c
sys/ufs/ffs/softdep.h
sys/ufs/lfs/lfs_alloc.c
sys/ufs/lfs/lfs_bio.c
sys/ufs/lfs/lfs_debug.c
sys/ufs/lfs/lfs_extern.h
sys/ufs/lfs/lfs_inode.c
sys/ufs/lfs/lfs_segment.c
sys/ufs/lfs/lfs_subr.c
sys/ufs/lfs/lfs_syscalls.c
sys/ufs/lfs/lfs_vfsops.c
sys/ufs/lfs/lfs_vnops.c
sys/ufs/mfs/mfs_extern.h
sys/ufs/mfs/mfs_vfsops.c
sys/ufs/mfs/mfs_vnops.c
sys/ufs/mfs/mfsnode.h
sys/ufs/ufs/dirhash.h
sys/ufs/ufs/extattr.h
sys/ufs/ufs/inode.h
sys/ufs/ufs/quota.h
sys/ufs/ufs/ufs_bmap.c
sys/ufs/ufs/ufs_dirhash.c
sys/ufs/ufs/ufs_extattr.c
sys/ufs/ufs/ufs_extern.h
sys/ufs/ufs/ufs_ihash.c
sys/ufs/ufs/ufs_inode.c
sys/ufs/ufs/ufs_lookup.c
sys/ufs/ufs/ufs_quota.c
sys/ufs/ufs/ufs_readwrite.c
sys/ufs/ufs/ufs_vfsops.c
sys/ufs/ufs/ufs_vnops.c
sys/ufs/ufs/ufsmount.h
sys/uvm/files.uvm
sys/uvm/uvm.h
sys/uvm/uvm_amap.c
sys/uvm/uvm_amap.h
sys/uvm/uvm_anon.c
sys/uvm/uvm_aobj.c
sys/uvm/uvm_bio.c
sys/uvm/uvm_device.c
sys/uvm/uvm_extern.h
sys/uvm/uvm_fault.c
sys/uvm/uvm_glue.c
sys/uvm/uvm_init.c
sys/uvm/uvm_io.c
sys/uvm/uvm_km.c
sys/uvm/uvm_loan.c
sys/uvm/uvm_map.c
sys/uvm/uvm_map.h
sys/uvm/uvm_meter.c
sys/uvm/uvm_mmap.c
sys/uvm/uvm_mremap.c
sys/uvm/uvm_page.c
sys/uvm/uvm_page.h
sys/uvm/uvm_pager.c
sys/uvm/uvm_pager.h
sys/uvm/uvm_pdaemon.c
sys/uvm/uvm_pdpolicy_clockpro.c
sys/uvm/uvm_pglist.c
sys/uvm/uvm_pmap.h
sys/uvm/uvm_readahead.c
sys/uvm/uvm_swap.c
sys/uvm/uvm_vnode.c
--- a/sys/miscfs/procfs/procfs_vnops.c	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/miscfs/procfs/procfs_vnops.c	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: procfs_vnops.c,v 1.123.2.3 2007/02/26 09:11:31 yamt Exp $	*/
+/*	$NetBSD: procfs_vnops.c,v 1.123.2.4 2007/09/03 14:41:57 yamt Exp $	*/
 
 /*-
  * Copyright (c) 2006, 2007 The NetBSD Foundation, Inc.
@@ -112,7 +112,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: procfs_vnops.c,v 1.123.2.3 2007/02/26 09:11:31 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: procfs_vnops.c,v 1.123.2.4 2007/09/03 14:41:57 yamt Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -181,6 +181,7 @@
 	{ DT_LNK, N("cwd"),	PFScwd,		NULL },
 	{ DT_LNK, N("root"),	PFSchroot,	NULL },
 	{ DT_LNK, N("emul"),	PFSemul,	NULL },
+	{ DT_REG, N("statm"),	PFSstatm,	procfs_validfile_linux },
 #ifdef __HAVE_PROCFS_MACHDEP
 	PROCFS_MACHDEP_NODETYPE_DEFNS
 #endif
@@ -200,6 +201,8 @@
 	{ DT_REG, N("uptime"),      PFSuptime,         procfs_validfile_linux },
 	{ DT_REG, N("mounts"),	    PFSmounts,	       procfs_validfile_linux },
 	{ DT_REG, N("devices"),     PFSdevices,        procfs_validfile_linux },
+	{ DT_REG, N("stat"),	    PFScpustat,        procfs_validfile_linux },
+	{ DT_REG, N("loadavg"),	    PFSloadavg,        procfs_validfile_linux },
 #undef N
 };
 static const int nproc_root_targets =
@@ -575,13 +578,24 @@
 		vp = target->p_cwdi->cwdi_rdir;
 		break;
 	case PFSexe:
-		rvp = rootvnode;
 		vp = target->p_textvp;
 		break;
 	default:
 		return (NULL);
 	}
 
+	/*
+	 * XXX: this horrible kludge avoids locking panics when
+	 * attempting to lookup links that point to within procfs
+	 */
+	if (vp != NULL && vp->v_tag == VT_PROCFS) {
+		if (bpp) {
+			*--bp = '/';
+			*bpp = bp;
+		}
+		return vp;
+	}
+
 	if (rvp == NULL)
 		rvp = rootvnode;
 	mutex_exit(&target->p_mutex);	/* XXXSMP */
@@ -589,8 +603,14 @@
 	    len / 2, 0, caller) != 0) {
 		vp = NULL;
 		if (bpp) {
-			bp = *bpp;
-			*--bp = '/';
+/* 
+			if (t == PFSexe) {
+				snprintf(path, len, "%s/%d/file"
+				    mp->mnt_stat.f_mntonname, pfs->pfs_pid);
+			} else */ {
+				bp = *bpp;
+				*--bp = '/';
+			}
 		}
 	}
 	mutex_enter(&target->p_mutex);	/* XXXSMP */
@@ -724,6 +744,7 @@
 	case PFSmaps:
 	case PFScmdline:
 	case PFSemul:
+	case PFSstatm:
 		vap->va_nlink = 1;
 		vap->va_uid = kauth_cred_geteuid(procp->p_cred);
 		vap->va_gid = kauth_cred_getegid(procp->p_cred);
@@ -733,6 +754,8 @@
 	case PFScpuinfo:
 	case PFSuptime:
 	case PFSmounts:
+	case PFScpustat:
+	case PFSloadavg:
 		vap->va_nlink = 1;
 		vap->va_uid = vap->va_gid = 0;
 		break;
@@ -840,6 +863,9 @@
 	case PFScpuinfo:
 	case PFSuptime:
 	case PFSmounts:
+	case PFScpustat:
+	case PFSloadavg:
+	case PFSstatm:
 		vap->va_bytes = vap->va_size = 0;
 		break;
 	case PFSmap:
@@ -1209,9 +1235,9 @@
 	    UIO_MX - offsetof(struct dirent, d_name), "%ld", (long)p->p_pid);
 	d.d_type = DT_DIR;
 
-	rw_exit(&proclist_lock);
+	mutex_exit(&proclist_lock);
 	error = uiomove(&d, UIO_MX, uiop);
-	rw_enter(&proclist_lock, RW_READER);
+	mutex_enter(&proclist_lock);
 	if (error) {
 		ctxp->error = error;
 		return -1;
@@ -1550,13 +1576,15 @@
 
 		if ((error = procfs_proc_lock(pfs->pfs_pid, &pown, ESRCH)) != 0)
 			return error;
+
 		mutex_enter(&pown->p_mutex);
 		fp = fd_getfile(pown->p_fd, pfs->pfs_fd);
 		mutex_exit(&pown->p_mutex);
-		if (error != 0) {
+		if (fp == NULL) {
 			procfs_proc_unlock(pown);
-			return (EBADF);
+			return EBADF;
 		}
+
 		FILE_USE(fp);
 		switch (fp->f_type) {
 		case DTYPE_VNODE:
@@ -1574,11 +1602,20 @@
 			}
 			bp = path + MAXPATHLEN;
 			*--bp = '\0';
-			vp = curproc->p_cwdi->cwdi_rdir;	/* XXXSMP */
-			if (vp == NULL)
-				vp = rootvnode;
-			error = getcwd_common(vxp, vp, &bp, path,
-			    MAXPATHLEN / 2, 0, curlwp);
+
+			/*
+			 * XXX: kludge to avoid locking against ourselves
+			 * in getcwd()
+			 */
+			if (vxp->v_tag == VT_PROCFS) {
+				*--bp = '/';
+			} else {
+				vp = curproc->p_cwdi->cwdi_rdir; /* XXXSMP */
+				if (vp == NULL)
+					vp = rootvnode;
+				error = getcwd_common(vxp, vp, &bp, path,
+				    MAXPATHLEN / 2, 0, curlwp);
+			}
 			FILE_UNUSE(fp, curlwp);
 			if (error)
 				break;
--- a/sys/miscfs/specfs/spec_vnops.c	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/miscfs/specfs/spec_vnops.c	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: spec_vnops.c,v 1.81.2.2 2006/12/30 20:50:18 yamt Exp $	*/
+/*	$NetBSD: spec_vnops.c,v 1.81.2.3 2007/09/03 14:41:57 yamt Exp $	*/
 
 /*
  * Copyright (c) 1989, 1993
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: spec_vnops.c,v 1.81.2.2 2006/12/30 20:50:18 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: spec_vnops.c,v 1.81.2.3 2007/09/03 14:41:57 yamt Exp $");
 
 #include <sys/param.h>
 #include <sys/proc.h>
@@ -130,8 +130,7 @@
  * Trivial lookup routine that always fails.
  */
 int
-spec_lookup(v)
-	void *v;
+spec_lookup(void *v)
 {
 	struct vop_lookup_args /* {
 		struct vnode *a_dvp;
@@ -161,8 +160,7 @@
  */
 /* ARGSUSED */
 int
-spec_open(v)
-	void *v;
+spec_open(void *v)
 {
 	struct vop_open_args /* {
 		struct vnode *a_vp;
@@ -172,12 +170,9 @@
 	} */ *ap = v;
 	struct lwp *l = ap->a_l;
 	struct vnode *vp = ap->a_vp;
-	const struct bdevsw *bdev;
-	const struct cdevsw *cdev;
 	dev_t dev = (dev_t)vp->v_rdev;
 	int error;
 	struct partinfo pi;
-	int (*d_ioctl)(dev_t, u_long, caddr_t, int, struct lwp *);
 	enum kauth_device_req req;
 
 	/*
@@ -194,39 +189,26 @@
 	switch (vp->v_type) {
 
 	case VCHR:
-		cdev = cdevsw_lookup(dev);
-		if (cdev == NULL)
-			return (ENXIO);
-
 		req = M2K(ap->a_mode);
-
 		error = kauth_authorize_device_spec(ap->a_cred, req, vp);
 		if (error)
 			return (error);
 
-		if (cdev->d_type == D_TTY)
+		if (cdev_type(dev) == D_TTY)
 			vp->v_flag |= VISTTY;
 		VOP_UNLOCK(vp, 0);
-		error = (*cdev->d_open)(dev, ap->a_mode, S_IFCHR, l);
+		error = cdev_open(dev, ap->a_mode, S_IFCHR, l);
 		vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
-		if (cdev->d_type != D_DISK)
+		if (cdev_type(dev) != D_DISK)
 			return error;
-		d_ioctl = cdev->d_ioctl;
 		break;
 
 	case VBLK:
-		bdev = bdevsw_lookup(dev);
-		if (bdev == NULL)
-			return (ENXIO);
-
 		req = M2K(ap->a_mode);
-
 		error = kauth_authorize_device_spec(ap->a_cred, req, vp);
 		if (error)
 			return (error);
-
-		error = (*bdev->d_open)(dev, ap->a_mode, S_IFBLK, l);
-		d_ioctl = bdev->d_ioctl;
+		error = bdev_open(dev, ap->a_mode, S_IFBLK, l);
 		break;
 
 	case VNON:
@@ -244,8 +226,13 @@
 
 	if (error)
 		return error;
-	if (!(*d_ioctl)(vp->v_rdev, DIOCGPART, (caddr_t)&pi, FREAD, curlwp))
-		vp->v_size = (voff_t)pi.disklab->d_secsize * pi.part->p_size;
+	if (vp->v_type == VCHR)
+		error = cdev_ioctl(vp->v_rdev, DIOCGPART, &pi, FREAD, curlwp);
+	else
+		error = bdev_ioctl(vp->v_rdev, DIOCGPART, &pi, FREAD, curlwp);
+	if (error == 0)
+		uvm_vnp_setsize(vp,
+		    (voff_t)pi.disklab->d_secsize * pi.part->p_size);
 	return 0;
 }
 
@@ -254,8 +241,7 @@
  */
 /* ARGSUSED */
 int
-spec_read(v)
-	void *v;
+spec_read(void *v)
 {
 	struct vop_read_args /* {
 		struct vnode *a_vp;
@@ -267,8 +253,6 @@
 	struct uio *uio = ap->a_uio;
  	struct lwp *l = curlwp;
 	struct buf *bp;
-	const struct bdevsw *bdev;
-	const struct cdevsw *cdev;
 	daddr_t bn;
 	int bsize, bscale;
 	struct partinfo dpart;
@@ -289,11 +273,7 @@
 
 	case VCHR:
 		VOP_UNLOCK(vp, 0);
-		cdev = cdevsw_lookup(vp->v_rdev);
-		if (cdev != NULL)
-			error = (*cdev->d_read)(vp->v_rdev, uio, ap->a_ioflag);
-		else
-			error = ENXIO;
+		error = cdev_read(vp->v_rdev, uio, ap->a_ioflag);
 		vn_lock(vp, LK_SHARED | LK_RETRY);
 		return (error);
 
@@ -301,10 +281,7 @@
 		if (uio->uio_offset < 0)
 			return (EINVAL);
 		bsize = BLKDEV_IOSIZE;
-		bdev = bdevsw_lookup(vp->v_rdev);
-		if (bdev != NULL &&
-		    (*bdev->d_ioctl)(vp->v_rdev, DIOCGPART, (caddr_t)&dpart,
-				     FREAD, l) == 0) {
+		if (bdev_ioctl(vp->v_rdev, DIOCGPART, &dpart, FREAD, l) == 0) {
 			if (dpart.part->p_fstype == FS_BSDFFS &&
 			    dpart.part->p_frag != 0 && dpart.part->p_fsize != 0)
 				bsize = dpart.part->p_frag *
@@ -337,8 +314,7 @@
  */
 /* ARGSUSED */
 int
-spec_write(v)
-	void *v;
+spec_write(void *v)
 {
 	struct vop_write_args /* {
 		struct vnode *a_vp;
@@ -350,8 +326,6 @@
 	struct uio *uio = ap->a_uio;
 	struct lwp *l = curlwp;
 	struct buf *bp;
-	const struct bdevsw *bdev;
-	const struct cdevsw *cdev;
 	daddr_t bn;
 	int bsize, bscale;
 	struct partinfo dpart;
@@ -370,11 +344,7 @@
 
 	case VCHR:
 		VOP_UNLOCK(vp, 0);
-		cdev = cdevsw_lookup(vp->v_rdev);
-		if (cdev != NULL)
-			error = (*cdev->d_write)(vp->v_rdev, uio, ap->a_ioflag);
-		else
-			error = ENXIO;
+		error = cdev_write(vp->v_rdev, uio, ap->a_ioflag);
 		vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
 		return (error);
 
@@ -384,10 +354,7 @@
 		if (uio->uio_offset < 0)
 			return (EINVAL);
 		bsize = BLKDEV_IOSIZE;
-		bdev = bdevsw_lookup(vp->v_rdev);
-		if (bdev != NULL &&
-		    (*bdev->d_ioctl)(vp->v_rdev, DIOCGPART, (caddr_t)&dpart,
-				    FREAD, l) == 0) {
+		if (bdev_ioctl(vp->v_rdev, DIOCGPART, &dpart, FREAD, l) == 0) {
 			if (dpart.part->p_fstype == FS_BSDFFS &&
 			    dpart.part->p_frag != 0 && dpart.part->p_fsize != 0)
 				bsize = dpart.part->p_frag *
@@ -415,7 +382,7 @@
 					bawrite(bp);
 				else
 					bdwrite(bp);
-				if (bp->b_flags & B_ERROR)
+				if (bp->b_error != 0)
 					error = bp->b_error;
 			}
 		} while (error == 0 && uio->uio_resid > 0 && n != 0);
@@ -432,8 +399,7 @@
  */
 /* ARGSUSED */
 int
-spec_ioctl(v)
-	void *v;
+spec_ioctl(void *v)
 {
 	struct vop_ioctl_args /* {
 		struct vnode *a_vp;
@@ -443,8 +409,6 @@
 		kauth_cred_t a_cred;
 		struct lwp *a_l;
 	} */ *ap = v;
-	const struct bdevsw *bdev;
-	const struct cdevsw *cdev;
 	struct vnode *vp;
 	dev_t dev;
 
@@ -467,24 +431,18 @@
 	switch (vp->v_type) {
 
 	case VCHR:
-		cdev = cdevsw_lookup(dev);
-		if (cdev == NULL)
-			return (ENXIO);
-		return ((*cdev->d_ioctl)(dev, ap->a_command, ap->a_data,
-		    ap->a_fflag, ap->a_l));
+		return cdev_ioctl(dev, ap->a_command, ap->a_data,
+		    ap->a_fflag, ap->a_l);
 
 	case VBLK:
-		bdev = bdevsw_lookup(dev);
-		if (bdev == NULL)
-			return (ENXIO);
 		if (ap->a_command == 0 && (long)ap->a_data == B_TAPE) {
-			if (bdev->d_type == D_TAPE)
+			if (bdev_type(dev) == D_TAPE)
 				return (0);
 			else
 				return (1);
 		}
-		return ((*bdev->d_ioctl)(dev, ap->a_command, ap->a_data,
-		   ap->a_fflag, ap->a_l));
+		return bdev_ioctl(dev, ap->a_command, ap->a_data,
+		   ap->a_fflag, ap->a_l);
 
 	default:
 		panic("spec_ioctl");
@@ -494,15 +452,13 @@
 
 /* ARGSUSED */
 int
-spec_poll(v)
-	void *v;
+spec_poll(void *v)
 {
 	struct vop_poll_args /* {
 		struct vnode *a_vp;
 		int a_events;
 		struct lwp *a_l;
 	} */ *ap = v;
-	const struct cdevsw *cdev;
 	struct vnode *vp;
 	dev_t dev;
 
@@ -525,10 +481,7 @@
 	switch (vp->v_type) {
 
 	case VCHR:
-		cdev = cdevsw_lookup(dev);
-		if (cdev == NULL)
-			return (POLLERR);
-		return (*cdev->d_poll)(dev, ap->a_events, ap->a_l);
+		return cdev_poll(dev, ap->a_events, ap->a_l);
 
 	default:
 		return (genfs_poll(v));
@@ -537,24 +490,19 @@
 
 /* ARGSUSED */
 int
-spec_kqfilter(v)
-	void *v;
+spec_kqfilter(void *v)
 {
 	struct vop_kqfilter_args /* {
 		struct vnode	*a_vp;
 		struct proc	*a_kn;
 	} */ *ap = v;
-	const struct cdevsw *cdev;
 	dev_t dev;
 
 	switch (ap->a_vp->v_type) {
 
 	case VCHR:
 		dev = ap->a_vp->v_rdev;
-		cdev = cdevsw_lookup(dev);
-		if (cdev == NULL)
-			return (ENXIO);
-		return (*cdev->d_kqfilter)(dev, ap->a_kn);
+		return cdev_kqfilter(dev, ap->a_kn);
 	default:
 		/*
 		 * Block devices don't support kqfilter, and refuse it
@@ -565,12 +513,32 @@
 }
 
 /*
+ * Allow mapping of only D_DISK.  This is called only for VBLK.
+ */
+int
+spec_mmap(void *v)
+{
+	struct vop_mmap_args /* {
+		struct vnode *a_vp;
+		vm_prot_t a_prot;
+		kauth_cred_t a_cred;
+		struct lwp *a_l;
+	} */ *ap = v;
+	struct vnode *vp = ap->a_vp;
+
+	KASSERT(vp->v_type == VBLK);
+	if (bdev_type(vp->v_rdev) != D_DISK)
+		return EINVAL;
+
+	return 0;
+}
+
+/*
  * Synch buffers associated with a block device
  */
 /* ARGSUSED */
 int
-spec_fsync(v)
-	void *v;
+spec_fsync(void *v)
 {
 	struct vop_fsync_args /* {
 		struct vnode *a_vp;
@@ -591,8 +559,7 @@
  * Just call the device strategy routine
  */
 int
-spec_strategy(v)
-	void *v;
+spec_strategy(void *v)
 {
 	struct vop_strategy_args /* {
 		struct vnode *a_vp;
@@ -606,8 +573,8 @@
 	error = 0;
 	bp->b_dev = vp->v_rdev;
 	if (!(bp->b_flags & B_READ) &&
-	    (LIST_FIRST(&bp->b_dep)) != NULL && bioops.io_start)
-		(*bioops.io_start)(bp);
+	    (LIST_FIRST(&bp->b_dep)) != NULL && bioopsp)
+		bioopsp->io_start(bp);
 
 	if (!(bp->b_flags & B_READ) && !SLIST_EMPTY(&vp->v_spec_cow_head)) {
 		SPEC_COW_LOCK(vp->v_specinfo, s);
@@ -631,19 +598,17 @@
 
 	if (error) {
 		bp->b_error = error;
-		bp->b_flags |= B_ERROR;
 		biodone(bp);
 		return (error);
 	}
 
-	DEV_STRATEGY(bp);
+	bdev_strategy(bp);
 
 	return (0);
 }
 
 int
-spec_inactive(v)
-	void *v;
+spec_inactive(void *v)
 {
 	struct vop_inactive_args /* {
 		struct vnode *a_vp;
@@ -658,8 +623,7 @@
  * This is a noop, simply returning what one has been given.
  */
 int
-spec_bmap(v)
-	void *v;
+spec_bmap(void *v)
 {
 	struct vop_bmap_args /* {
 		struct vnode *a_vp;
@@ -683,8 +647,7 @@
  */
 /* ARGSUSED */
 int
-spec_close(v)
-	void *v;
+spec_close(void *v)
 {
 	struct vop_close_args /* {
 		struct vnode *a_vp;
@@ -693,11 +656,8 @@
 		struct lwp *a_l;
 	} */ *ap = v;
 	struct vnode *vp = ap->a_vp;
-	const struct bdevsw *bdev;
-	const struct cdevsw *cdev;
 	struct session *sess;
 	dev_t dev = vp->v_rdev;
-	int (*devclose)(dev_t, int, int, struct lwp *);
 	int mode, error, count, flags, flags1;
 
 	count = vcount(vp);
@@ -719,18 +679,25 @@
 		 * guarantee that the vrele() will do the final close on the
 		 * actual tty device.
 		 */
+		mutex_enter(&proclist_lock);
 		if (count == 2 && ap->a_l &&
 		    vp == (sess = ap->a_l->l_proc->p_session)->s_ttyvp) {
 			sess->s_ttyvp = NULL;
 			if (sess->s_ttyp->t_session != NULL) {
 				sess->s_ttyp->t_pgrp = NULL;
 				sess->s_ttyp->t_session = NULL;
+				mutex_exit(&proclist_lock);
 				SESSRELE(sess);
-			} else if (sess->s_ttyp->t_pgrp != NULL)
-				panic("spec_close: spurious pgrp ref");
+			} else {
+				if (sess->s_ttyp->t_pgrp != NULL)
+					panic("spec_close: spurious pgrp ref");
+				mutex_exit(&proclist_lock);
+			}
 			vrele(vp);
 			count--;
-		}
+		} else
+			mutex_exit(&proclist_lock);
+
 		/*
 		 * If the vnode is locked, then we are in the midst
 		 * of forcably closing the device, otherwise we only
@@ -738,11 +705,6 @@
 		 */
 		if (count > 1 && (flags & VXLOCK) == 0)
 			return (0);
-		cdev = cdevsw_lookup(dev);
-		if (cdev != NULL)
-			devclose = cdev->d_close;
-		else
-			devclose = NULL;
 		mode = S_IFCHR;
 		break;
 
@@ -766,11 +728,6 @@
 		 */
 		if (count > 1 && (flags & VXLOCK) == 0)
 			return (0);
-		bdev = bdevsw_lookup(dev);
-		if (bdev != NULL)
-			devclose = bdev->d_close;
-		else
-			devclose = NULL;
 		mode = S_IFBLK;
 		break;
 
@@ -790,16 +747,16 @@
 	/*
 	 * If we're able to block, release the vnode lock & reacquire. We
 	 * might end up sleeping for someone else who wants our queues. They
-	 * won't get them if we hold the vnode locked. Also, if VXLOCK is set,
-	 * don't release the lock as we won't be able to regain it.
+	 * won't get them if we hold the vnode locked. Also, if VXLOCK is
+	 * set, don't release the lock as we won't be able to regain it.
 	 */
 	if (!(flags1 & FNONBLOCK))
 		VOP_UNLOCK(vp, 0);
 
-	if (devclose != NULL)
-		error = (*devclose)(dev, flags1, mode, ap->a_l);
+	if (vp->v_type == VBLK)
+		error = bdev_close(dev, flags1, mode, ap->a_l);
 	else
-		error = ENXIO;
+		error = cdev_close(dev, flags1, mode, ap->a_l);
 
 	if (!(flags1 & FNONBLOCK))
 		vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
@@ -811,8 +768,7 @@
  * Print out the contents of a special device vnode.
  */
 int
-spec_print(v)
-	void *v;
+spec_print(void *v)
 {
 	struct vop_print_args /* {
 		struct vnode *a_vp;
@@ -827,8 +783,7 @@
  * Return POSIX pathconf information applicable to special devices.
  */
 int
-spec_pathconf(v)
-	void *v;
+spec_pathconf(void *v)
 {
 	struct vop_pathconf_args /* {
 		struct vnode *a_vp;
@@ -868,8 +823,7 @@
  * Advisory record locking support.
  */
 int
-spec_advlock(v)
-	void *v;
+spec_advlock(void *v)
 {
 	struct vop_advlock_args /* {
 		struct vnode *a_vp;
--- a/sys/miscfs/specfs/specdev.h	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/miscfs/specfs/specdev.h	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: specdev.h,v 1.26.12.1 2006/06/21 15:10:26 yamt Exp $	*/
+/*	$NetBSD: specdev.h,v 1.26.12.2 2007/09/03 14:41:59 yamt Exp $	*/
 
 /*
  * Copyright (c) 1990, 1993
@@ -118,7 +118,7 @@
 int	spec_poll(void *);
 int	spec_kqfilter(void *);
 #define spec_revoke	genfs_revoke
-#define	spec_mmap	genfs_mmap
+int	spec_mmap(void *);
 int	spec_fsync(void *);
 #define	spec_seek	genfs_nullop		/* XXX should query device */
 #define	spec_remove	genfs_badop
@@ -143,6 +143,5 @@
 #define	spec_bwrite	vn_bwrite
 #define	spec_getpages	genfs_getpages
 #define	spec_putpages	genfs_putpages
-int	spec_size(void *);
 
 #endif /* _MISCFS_SPECFS_SPECDEV_H_ */
--- a/sys/miscfs/syncfs/sync_subr.c	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/miscfs/syncfs/sync_subr.c	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: sync_subr.c,v 1.18.2.3 2007/02/26 09:11:32 yamt Exp $	*/
+/*	$NetBSD: sync_subr.c,v 1.18.2.4 2007/09/03 14:41:59 yamt Exp $	*/
 
 /*
  * Copyright 1997 Marshall Kirk McKusick. All Rights Reserved.
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sync_subr.c,v 1.18.2.3 2007/02/26 09:11:32 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sync_subr.c,v 1.18.2.4 2007/09/03 14:41:59 yamt Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -167,7 +167,6 @@
 {
 	struct synclist *slp;
 	struct vnode *vp;
-	struct mount *mp;
 	long starttime;
 	int s;
 
@@ -190,14 +189,10 @@
 		mutex_enter(&syncer_mutex);
 
 		while ((vp = TAILQ_FIRST(slp)) != NULL) {
-			if (vn_start_write(vp, &mp, V_NOWAIT) == 0) {
-				if (vn_lock(vp, LK_EXCLUSIVE | LK_NOWAIT)
-				    == 0) {
-					(void) VOP_FSYNC(vp, curlwp->l_cred,
-					    FSYNC_LAZY, 0, 0, curlwp);
-					VOP_UNLOCK(vp, 0);
-				}
-				vn_finished_write(mp, 0);
+			if (vn_lock(vp, LK_EXCLUSIVE | LK_NOWAIT) == 0) {
+				(void) VOP_FSYNC(vp, curlwp->l_cred,
+				    FSYNC_LAZY, 0, 0, curlwp);
+				VOP_UNLOCK(vp, 0);
 			}
 			s = splbio();
 			if (TAILQ_FIRST(slp) == vp) {
@@ -217,8 +212,8 @@
 		/*
 		 * Do soft update processing.
 		 */
-		if (bioops.io_sync)
-			(*bioops.io_sync)(NULL);
+		if (bioopsp)
+			bioopsp->io_sync(NULL);
 
 		mutex_exit(&syncer_mutex);
 
--- a/sys/miscfs/syncfs/sync_vnops.c	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/miscfs/syncfs/sync_vnops.c	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: sync_vnops.c,v 1.11.16.2 2006/12/30 20:50:18 yamt Exp $	*/
+/*	$NetBSD: sync_vnops.c,v 1.11.16.3 2007/09/03 14:41:59 yamt Exp $	*/
 
 /*
  * Copyright 1997 Marshall Kirk McKusick. All Rights Reserved.
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sync_vnops.c,v 1.11.16.2 2006/12/30 20:50:18 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sync_vnops.c,v 1.11.16.3 2007/09/03 14:41:59 yamt Exp $");
 
 #include <sys/param.h>
 #include <sys/proc.h>
@@ -155,16 +155,11 @@
 	 */
 	simple_lock(&mountlist_slock);
 	if (vfs_busy(mp, LK_NOWAIT, &mountlist_slock) == 0) {
-		if (vn_start_write(NULL, &mp, V_NOWAIT) != 0) {
-			vfs_unbusy(mp);
-			return (0);
-		}
 		asyncflag = mp->mnt_flag & MNT_ASYNC;
 		mp->mnt_flag &= ~MNT_ASYNC;
 		VFS_SYNC(mp, MNT_LAZY, ap->a_cred, ap->a_l);
 		if (asyncflag)
 			mp->mnt_flag |= MNT_ASYNC;
-		vn_finished_write(mp, 0);
 		vfs_unbusy(mp);
 	} else
 		simple_unlock(&mountlist_slock);
--- a/sys/miscfs/umapfs/umap_subr.c	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/miscfs/umapfs/umap_subr.c	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: umap_subr.c,v 1.21.4.1 2006/06/21 15:10:26 yamt Exp $	*/
+/*	$NetBSD: umap_subr.c,v 1.21.4.2 2007/09/03 14:41:59 yamt Exp $	*/
 
 /*
  * Copyright (c) 1999 National Aeronautics & Space Administration
@@ -68,7 +68,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: umap_subr.c,v 1.21.4.1 2006/06/21 15:10:26 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: umap_subr.c,v 1.21.4.2 2007/09/03 14:41:59 yamt Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -194,5 +194,5 @@
 			groups[i] = NULLGROUP;
 	}
 
-	kauth_cred_setgroups(credp, groups, ngroups, -1);
+	kauth_cred_setgroups(credp, groups, ngroups, -1, UIO_SYSSPACE);
 }
--- a/sys/miscfs/umapfs/umap_vfsops.c	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/miscfs/umapfs/umap_vfsops.c	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: umap_vfsops.c,v 1.53.2.3 2007/02/26 09:11:32 yamt Exp $	*/
+/*	$NetBSD: umap_vfsops.c,v 1.53.2.4 2007/09/03 14:42:00 yamt Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -41,7 +41,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: umap_vfsops.c,v 1.53.2.3 2007/02/26 09:11:32 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: umap_vfsops.c,v 1.53.2.4 2007/09/03 14:42:00 yamt Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -57,22 +57,21 @@
 #include <miscfs/umapfs/umap.h>
 #include <miscfs/genfs/layer_extern.h>
 
-int	umapfs_mount(struct mount *, const char *, void *,
-			  struct nameidata *, struct lwp *);
-int	umapfs_unmount(struct mount *, int, struct lwp *);
+VFS_PROTOS(umapfs);
 
 /*
  * Mount umap layer
  */
 int
-umapfs_mount(mp, path, data, ndp, l)
+umapfs_mount(mp, path, data, data_len, l)
 	struct mount *mp;
 	const char *path;
 	void *data;
-	struct nameidata *ndp;
+	size_t *data_len;
 	struct lwp *l;
 {
-	struct umap_args args;
+	struct nameidata nd;
+	struct umap_args *args = data;
 	struct vnode *lowerrootvp, *vp;
 	struct umap_mount *amp;
 	int error;
@@ -80,14 +79,18 @@
 	int i;
 #endif
 
+	if (*data_len < sizeof *args)
+		return EINVAL;
+
 	if (mp->mnt_flag & MNT_GETARGS) {
 		amp = MOUNTTOUMAPMOUNT(mp);
 		if (amp == NULL)
 			return EIO;
-		args.la.target = NULL;
-		args.nentries = amp->info_nentries;
-		args.gnentries = amp->info_gnentries;
-		return copyout(&args, data, sizeof(args));
+		args->la.target = NULL;
+		args->nentries = amp->info_nentries;
+		args->gnentries = amp->info_gnentries;
+		*data_len = sizeof *args;
+		return 0;
 	}
 
 	/* only for root */
@@ -100,13 +103,6 @@
 #endif
 
 	/*
-	 * Get argument
-	 */
-	error = copyin(data, &args, sizeof(struct umap_args));
-	if (error)
-		return (error);
-
-	/*
 	 * Update is not supported
 	 */
 	if (mp->mnt_flag & MNT_UPDATE)
@@ -115,15 +111,15 @@
 	/*
 	 * Find lower node
 	 */
-	NDINIT(ndp, LOOKUP, FOLLOW|LOCKLEAF,
-		UIO_USERSPACE, args.umap_target, l);
-	if ((error = namei(ndp)) != 0)
+	NDINIT(&nd, LOOKUP, FOLLOW|LOCKLEAF,
+		UIO_USERSPACE, args->umap_target, l);
+	if ((error = namei(&nd)) != 0)
 		return (error);
 
 	/*
 	 * Sanity check on lower vnode
 	 */
-	lowerrootvp = ndp->ni_vp;
+	lowerrootvp = nd.ni_vp;
 #ifdef UMAPFS_DIAGNOSTIC
 	printf("vp = %p, check for VDIR...\n", lowerrootvp);
 #endif
@@ -142,7 +138,6 @@
 	memset(amp, 0, sizeof(struct umap_mount));
 
 	mp->mnt_data = amp;
-	mp->mnt_leaf = lowerrootvp->v_mount->mnt_leaf;
 	amp->umapm_vfs = lowerrootvp->v_mount;
 	if (amp->umapm_vfs->mnt_flag & MNT_LOCAL)
 		mp->mnt_flag |= MNT_LOCAL;
@@ -150,37 +145,37 @@
 	/*
 	 * Now copy in the number of entries and maps for umap mapping.
 	 */
-	if (args.nentries > MAPFILEENTRIES || args.gnentries > GMAPFILEENTRIES) {
+	if (args->nentries > MAPFILEENTRIES || args->gnentries > GMAPFILEENTRIES) {
 		vput(lowerrootvp);
 		return (error);
 	}
 
-	amp->info_nentries = args.nentries;
-	amp->info_gnentries = args.gnentries;
-	error = copyin(args.mapdata, amp->info_mapdata,
-	    2*sizeof(u_long)*args.nentries);
+	amp->info_nentries = args->nentries;
+	amp->info_gnentries = args->gnentries;
+	error = copyin(args->mapdata, amp->info_mapdata,
+	    2*sizeof(u_long)*args->nentries);
 	if (error) {
 		vput(lowerrootvp);
 		return (error);
 	}
 
 #ifdef UMAPFS_DIAGNOSTIC
-	printf("umap_mount:nentries %d\n",args.nentries);
-	for (i = 0; i < args.nentries; i++)
+	printf("umap_mount:nentries %d\n",args->nentries);
+	for (i = 0; i < args->nentries; i++)
 		printf("   %ld maps to %ld\n", amp->info_mapdata[i][0],
 	 	    amp->info_mapdata[i][1]);
 #endif
 
-	error = copyin(args.gmapdata, amp->info_gmapdata,
-	    2*sizeof(u_long)*args.gnentries);
+	error = copyin(args->gmapdata, amp->info_gmapdata,
+	    2*sizeof(u_long)*args->gnentries);
 	if (error) {
 		vput(lowerrootvp);
 		return (error);
 	}
 
 #ifdef UMAPFS_DIAGNOSTIC
-	printf("umap_mount:gnentries %d\n",args.gnentries);
-	for (i = 0; i < args.gnentries; i++)
+	printf("umap_mount:gnentries %d\n",args->gnentries);
+	for (i = 0; i < args->gnentries; i++)
 		printf("\tgroup %ld maps to %ld\n",
 		    amp->info_gmapdata[i][0],
 	 	    amp->info_gmapdata[i][1]);
@@ -225,8 +220,8 @@
 	vp->v_flag |= VROOT;
 	amp->umapm_rootvp = vp;
 
-	error = set_statvfs_info(path, UIO_USERSPACE, args.umap_target,
-	    UIO_USERSPACE, mp, l);
+	error = set_statvfs_info(path, UIO_USERSPACE, args->umap_target,
+	    UIO_USERSPACE, mp->mnt_op->vfs_name, mp, l);
 #ifdef UMAPFS_DIAGNOSTIC
 	printf("umapfs_mount: lower %s, alias at %s\n",
 		mp->mnt_stat.f_mntfromname, mp->mnt_stat.f_mntonname);
@@ -251,17 +246,7 @@
 	if (mntflags & MNT_FORCE)
 		flags |= FORCECLOSE;
 
-	/*
-	 * Clear out buffer cache.  I don't think we
-	 * ever get anything cached at this level at the
-	 * moment, but who knows...
-	 */
-#ifdef notyet
-	mntflushbuf(mp, 0);
-	if (mntinvalbuf(mp, 1))
-		return (EBUSY);
-#endif
-	if (rtvp->v_usecount > 1)
+	if (rtvp->v_usecount > 1 && (mntflags & MNT_FORCE) == 0)
 		return (EBUSY);
 	if ((error = vflush(mp, rtvp, flags)) != 0)
 		return (error);
@@ -315,6 +300,7 @@
 
 struct vfsops umapfs_vfsops = {
 	MOUNT_UMAP,
+	sizeof (struct umap_args),
 	umapfs_mount,
 	layerfs_start,
 	umapfs_unmount,
@@ -331,7 +317,7 @@
 	NULL,				/* vfs_mountroot */
 	layerfs_snapshot,
 	vfs_stdextattrctl,
-	vfs_stdsuspendctl,
+	(void *)eopnotsupp,		/* vfs_suspendctl */
 	umapfs_vnodeopv_descs,
 	0,				/* vfs_refcount */
 	{ NULL, NULL },
--- a/sys/net/agr/ieee8023ad_lacp.c	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/agr/ieee8023ad_lacp.c	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee8023ad_lacp.c,v 1.1.8.2 2007/02/26 09:11:38 yamt Exp $	*/
+/*	$NetBSD: ieee8023ad_lacp.c,v 1.1.8.3 2007/09/03 14:42:25 yamt Exp $	*/
 
 /*-
  * Copyright (c)2005 YAMAMOTO Takashi,
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ieee8023ad_lacp.c,v 1.1.8.2 2007/02/26 09:11:38 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee8023ad_lacp.c,v 1.1.8.3 2007/09/03 14:42:25 yamt Exp $");
 
 #include <sys/param.h>
 #include <sys/callout.h>
@@ -96,7 +96,6 @@
 	struct agr_port *port;
 	struct lacp_port *lp;
 	int error = 0;
-	int s;
 
 	port = ifp->if_agrprivate; /* XXX race with agr_remport. */
 	if (__predict_false(port->port_flags & AGRPORT_DETACHING)) {
@@ -150,7 +149,7 @@
 		goto bad;
 	}
 
-	s = AGR_LOCK(sc);
+	AGR_LOCK(sc);
 	lp = LACP_PORT(port);
 
 #if defined(LACP_DEBUG)
@@ -161,7 +160,7 @@
 #endif /* defined(LACP_DEBUG) */
 	lacp_sm_rx(lp, du);
 
-	AGR_UNLOCK(sc, s);
+	AGR_UNLOCK(sc);
 
 	m_freem(m);
 
@@ -179,7 +178,7 @@
 
 	info->lip_systemid.lsi_prio = htobe16(LACP_SYSTEM_PRIO);
 	memcpy(&info->lip_systemid.lsi_mac,
-	    LLADDR(port->port_ifp->if_sadl), ETHER_ADDR_LEN);
+	    CLLADDR(port->port_ifp->if_sadl), ETHER_ADDR_LEN);
 	info->lip_portid.lpi_prio = htobe16(LACP_PORT_PRIO);
 	info->lip_portid.lpi_portno = htobe16(port->port_ifp->if_index);
 	info->lip_state = lp->lp_state;
@@ -420,12 +419,11 @@
 {
 	struct agr_softc *sc = vp;
 	struct lacp_softc *lsc = LACP_SOFTC(sc);
-	int s;
 
-	s = AGR_LOCK(sc);
+	AGR_LOCK(sc);
 	LACP_DPRINTF((NULL, "%s\n", __func__));
 	lsc->lsc_suppress_distributing = false;
-	AGR_UNLOCK(sc, s);
+	AGR_UNLOCK(sc);
 }
 
 /* -------------------- */
@@ -444,13 +442,12 @@
 ieee8023ad_portfini(struct agr_port *port)
 {
 	struct agr_softc *sc = AGR_SC_FROM_PORT(port);
-	int s;
 
-	s = AGR_LOCK(sc);
+	AGR_LOCK(sc);
 
 	lacp_portfini(port);
 
-	AGR_UNLOCK(sc, s);
+	AGR_UNLOCK(sc);
 }
 
 void
@@ -461,7 +458,7 @@
 
 	lsc->lsc_active_aggregator = NULL;
 	TAILQ_INIT(&lsc->lsc_aggregators);
-	callout_init(&lsc->lsc_transit_callout);
+	callout_init(&lsc->lsc_transit_callout, 0);
 	callout_setfunc(&lsc->lsc_transit_callout, lacp_transit_expire, sc);
 }
 
--- a/sys/net/agr/if_agr.c	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/agr/if_agr.c	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_agr.c,v 1.1.8.3 2007/02/26 09:11:38 yamt Exp $	*/
+/*	$NetBSD: if_agr.c,v 1.1.8.4 2007/09/03 14:42:26 yamt Exp $	*/
 
 /*-
  * Copyright (c)2005 YAMAMOTO Takashi,
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_agr.c,v 1.1.8.3 2007/02/26 09:11:38 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_agr.c,v 1.1.8.4 2007/09/03 14:42:26 yamt Exp $");
 
 #include "bpfilter.h"
 #include "opt_inet.h"
@@ -73,9 +73,9 @@
 static int agr_remport(struct ifnet *, struct ifnet *);
 static int agrreq_copyin(const void *, struct agrreq *);
 static int agrreq_copyout(void *, struct agrreq *);
-static int agr_ioctl(struct ifnet *, u_long, caddr_t);
+static int agr_ioctl(struct ifnet *, u_long, void *);
 static struct agr_port *agr_select_tx_port(struct agr_softc *, struct mbuf *);
-static int agr_ioctl_filter(struct ifnet *, u_long, caddr_t);
+static int agr_ioctl_filter(struct ifnet *, u_long, void *);
 static void agr_reset_iftype(struct ifnet *);
 static int agr_config_promisc(struct agr_softc *);
 static int agrport_config_promisc_callback(struct agr_port *, void *);
@@ -135,37 +135,32 @@
  * EXPORTED AGR-INTERNAL FUNCTIONS
  */
 
-int
+void
 agr_lock(struct agr_softc *sc)
 {
-	int s;
 
-	s = splnet();
-	simple_lock(&sc->sc_lock);
-
-	return s;
+	mutex_enter(&sc->sc_lock);
 }
 
 void
-agr_unlock(struct agr_softc *sc, int savedipl)
+agr_unlock(struct agr_softc *sc)
 {
 
-	simple_unlock(&sc->sc_lock);
-	splx(savedipl);
+	mutex_exit(&sc->sc_lock);
 }
 
 void
 agr_ioctl_lock(struct agr_softc *sc)
 {
 
-	lockmgr(&sc->sc_ioctl_lock, LK_EXCLUSIVE, NULL);
+	mutex_enter(&sc->sc_ioctl_lock);
 }
 
 void
 agr_ioctl_unlock(struct agr_softc *sc)
 {
 
-	lockmgr(&sc->sc_ioctl_lock, LK_RELEASE, NULL);
+	mutex_exit(&sc->sc_ioctl_lock);
 }
 
 /*
@@ -204,7 +199,7 @@
 }
 
 int
-agrport_ioctl(struct agr_port *port, u_long cmd, caddr_t arg)
+agrport_ioctl(struct agr_port *port, u_long cmd, void *arg)
 {
 	struct ifnet *ifp = port->port_ifp;
 
@@ -226,8 +221,8 @@
 
 	sc = agr_alloc_softc();
 	TAILQ_INIT(&sc->sc_ports);
-	lockinit(&sc->sc_ioctl_lock, PSOCK, "agrioctl", 0, 0);
-	simple_lock_init(&sc->sc_lock);
+	mutex_init(&sc->sc_ioctl_lock, MUTEX_DRIVER, IPL_NONE);
+	mutex_init(&sc->sc_lock, MUTEX_DRIVER, IPL_NET);
 	agrtimer_init(sc);
 	ifp = &sc->sc_if;
 	snprintf(ifp->if_xname, sizeof(ifp->if_xname), "%s%d",
@@ -261,22 +256,23 @@
 {
 	struct agr_softc *sc = ifp->if_softc;
 	int error;
-	int s;
 
 	agr_ioctl_lock(sc);
 
-	s = AGR_LOCK(sc);
+	AGR_LOCK(sc);
 	if (sc->sc_nports > 0) {
 		error = EBUSY;
 	} else {
 		error = 0;
 	}
-	AGR_UNLOCK(sc, s);
+	AGR_UNLOCK(sc);
 
 	agr_ioctl_unlock(sc);
 
 	if (error == 0) {
 		if_detach(ifp);
+		mutex_destroy(&sc->sc_ioctl_lock);
+		mutex_destroy(&sc->sc_lock);
 		agr_free_softc(sc);
 	}
 
@@ -317,9 +313,8 @@
 {
 	struct agr_softc *sc = ifp->if_softc;
 	struct mbuf *m;
-	int s;
 
-	s = AGR_LOCK(sc);
+	AGR_LOCK(sc);
 
 	while (/* CONSTCOND */ 1) {
 		struct agr_port *port;
@@ -349,7 +344,7 @@
 		}
 	}
 
-	AGR_UNLOCK(sc, s);
+	AGR_UNLOCK(sc);
 
 	ifp->if_flags &= ~IFF_OACTIVE;
 }
@@ -472,7 +467,6 @@
 	struct agr_softc *sc = ifp->if_softc;
 	struct agr_port *port = NULL;
 	int error = 0;
-	int s;
 
 	if (ifp_port->if_ioctl == NULL) {
 		error = EOPNOTSUPP;
@@ -528,7 +522,7 @@
 		}
 	}
 
-	memcpy(port->port_origlladdr, LLADDR(ifp_port->if_sadl),
+	memcpy(port->port_origlladdr, CLLADDR(ifp_port->if_sadl),
 	    ifp_port->if_addrlen);
 
 	/*
@@ -536,7 +530,7 @@
 	 */
 
 	error = (*ifp_port->if_ioctl)(ifp_port, SIOCSIFADDR,
-	    (caddr_t)TAILQ_FIRST(&ifp->if_addrlist));
+	    (void *)TAILQ_FIRST(&ifp->if_addrlist));
 
 	if (error) {
 		printf("%s: SIOCSIFADDR error %d\n", __func__, error);
@@ -545,7 +539,7 @@
 	port->port_flags |= AGRPORT_LADDRCHANGED;
 
 	ifp->if_type = ifp_port->if_type;
-	s = AGR_LOCK(sc);
+	AGR_LOCK(sc);
 
 	port->port_ifp = ifp_port;
 	ifp_port->if_agrprivate = port;
@@ -558,7 +552,7 @@
 
 	port->port_flags |= AGRPORT_ATTACHED;
 
-	AGR_UNLOCK(sc, s);
+	AGR_UNLOCK(sc);
 
 	error = (*sc->sc_iftop->iftop_portinit)(sc, port);
 	if (error) {
@@ -575,9 +569,9 @@
 		goto cleanup;
 	}
 
-	s = AGR_LOCK(sc);
+	AGR_LOCK(sc);
 	port->port_flags &= ~AGRPORT_LARVAL;
-	AGR_UNLOCK(sc, s);
+	AGR_UNLOCK(sc);
 out:
 	if (error && port) {
 		free(port, M_DEVBUF);
@@ -610,7 +604,6 @@
 	struct agr_softc *sc = ifp->if_softc;
 	struct agr_port *port;
 	int error = 0;
-	int s;
 
 	if (ifp_port->if_agrprivate == NULL) {
 		error = ENOENT;
@@ -633,9 +626,9 @@
 	}
 #endif
 
-	s = AGR_LOCK(sc);
+	AGR_LOCK(sc);
 	port->port_flags |= AGRPORT_DETACHING;
-	AGR_UNLOCK(sc, s);
+	AGR_UNLOCK(sc);
 
 	error = (*sc->sc_iftop->iftop_portfini)(sc, port);
 	if (error) {
@@ -681,7 +674,6 @@
 	struct ifnet *ifp_port = port->port_ifp;
 	int error;
 	int result = 0;
-	int s;
 
 	error = agrport_config_promisc(port, false);
 	if (error) {
@@ -697,28 +689,19 @@
 			error = (*ifp_port->if_init)(ifp_port);
 		}
 #else
-		struct sockaddr_dl *sdl;
+		union {
+			struct sockaddr sa;
+			struct sockaddr_dl sdl;
+			struct sockaddr_storage ss;
+		} u;
 		struct ifaddr ifa;
-		int sdllen;
-		int addrlen;
 
-		addrlen = ifp_port->if_addrlen;
-		sdllen = sizeof(*sdl) - sizeof(sdl->sdl_data) + addrlen;
-		sdl = malloc(sdllen, M_TEMP, M_WAITOK);
-		if (sdl == NULL) {
-			error = ENOMEM;
-		} else {
-			memset(sdl, 0, sdllen);
-			sdl->sdl_len = sdllen;
-			sdl->sdl_family = AF_LINK;
-			sdl->sdl_type = ifp_port->if_type;
-			sdl->sdl_alen = addrlen;
-			memcpy(LLADDR(sdl), port->port_origlladdr, addrlen);
-			memset(&ifa, 0, sizeof(ifa));
-			ifa.ifa_addr = (struct sockaddr *)sdl;
-			error = agrport_ioctl(port, SIOCSIFADDR, (caddr_t)&ifa);
-			free(sdl, M_TEMP);
-		}
+		sockaddr_dl_init(&u.sdl, sizeof(u.ss),
+		    0, ifp_port->if_type, NULL, 0,
+		    port->port_origlladdr, ifp_port->if_addrlen);
+		memset(&ifa, 0, sizeof(ifa));
+		ifa.ifa_addr = &u.sa;
+		error = agrport_ioctl(port, SIOCSIFADDR, &ifa);
 #endif
 		if (error) {
 			printf("%s: if_init error %d\n", __func__, error);
@@ -728,7 +711,7 @@
 		}
 	}
 
-	s = AGR_LOCK(sc);
+	AGR_LOCK(sc);
 	if ((port->port_flags & AGRPORT_ATTACHED)) {
 		ifp_port->if_agrprivate = NULL;
 
@@ -740,7 +723,7 @@
 
 		port->port_flags &= ~AGRPORT_ATTACHED;
 	}
-	AGR_UNLOCK(sc, s);
+	AGR_UNLOCK(sc);
 
 	return result;
 }
@@ -759,7 +742,7 @@
 
 /* XXX an incomplete hack; can't filter ioctls handled ifioctl(). */
 static int
-agr_ioctl_filter(struct ifnet *ifp, u_long cmd, caddr_t arg)
+agr_ioctl_filter(struct ifnet *ifp, u_long cmd, void *arg)
 {
 	struct agr_port *port = ifp->if_agrprivate;
 	int error;
@@ -812,7 +795,7 @@
 }
 
 static int
-agr_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
+agr_ioctl(struct ifnet *ifp, u_long cmd, void *data)
 {
 	struct agr_softc *sc = ifp->if_softc;
 	struct ifreq *ifr = (struct ifreq *)data;
@@ -847,7 +830,7 @@
 
 	case SIOCGIFADDR:
 		sa = (struct sockaddr *)&ifr->ifr_data;
-		memcpy(sa->sa_data, LLADDR(ifp->if_sadl), ifp->if_addrlen);
+		memcpy(sa->sa_data, CLLADDR(ifp->if_sadl), ifp->if_addrlen);
 		break;
 
 #if 0 /* notyet */
--- a/sys/net/agr/if_agrether.c	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/agr/if_agrether.c	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_agrether.c,v 1.1.8.2 2007/02/26 09:11:39 yamt Exp $	*/
+/*	$NetBSD: if_agrether.c,v 1.1.8.3 2007/09/03 14:42:26 yamt Exp $	*/
 
 /*-
  * Copyright (c)2005 YAMAMOTO Takashi,
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_agrether.c,v 1.1.8.2 2007/02/26 09:11:39 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_agrether.c,v 1.1.8.3 2007/09/03 14:42:26 yamt Exp $");
 
 #include <sys/param.h>
 #include <sys/callout.h>
@@ -99,7 +99,7 @@
 
 	sc->sc_iftprivate = priv;
 
-	ether_ifattach(ifp, LLADDR(ifp_port->if_sadl));
+	ether_ifattach(ifp, CLLADDR(ifp_port->if_sadl));
 	ec->ec_capabilities =
 	    ETHERCAP_VLAN_MTU | ETHERCAP_VLAN_HWTAGGING | ETHERCAP_JUMBO_MTU;
 
@@ -169,7 +169,7 @@
 	memcpy(&ifr.ifr_addr.sa_data,
 	    &ethermulticastaddr_slowprotocols, 
 	    sizeof(ethermulticastaddr_slowprotocols));
-	error = agrport_ioctl(port, SIOCADDMULTI, (caddr_t)&ifr);
+	error = agrport_ioctl(port, SIOCADDMULTI, (void *)&ifr);
 	if (error) {
 		free(port->port_iftprivate, M_DEVBUF);
 		port->port_iftprivate = NULL;
@@ -199,7 +199,7 @@
 	memcpy(&ifr.ifr_addr.sa_data,
 	    &ethermulticastaddr_slowprotocols, 
 	    sizeof(ethermulticastaddr_slowprotocols));
-	error = agrport_ioctl(port, SIOCDELMULTI, (caddr_t)&ifr);
+	error = agrport_ioctl(port, SIOCDELMULTI, (void *)&ifr);
 	if (error) {
 		return error;
 	}
--- a/sys/net/agr/if_agrether_hash.c	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/agr/if_agrether_hash.c	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_agrether_hash.c,v 1.1 2005/03/18 11:11:50 yamt Exp $	*/
+/*	$NetBSD: if_agrether_hash.c,v 1.1.8.1 2007/09/03 14:42:26 yamt Exp $	*/
 
 /*-
  * Copyright (c)2005 YAMAMOTO Takashi,
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_agrether_hash.c,v 1.1 2005/03/18 11:11:50 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_agrether_hash.c,v 1.1.8.1 2007/09/03 14:42:26 yamt Exp $");
 
 #include <sys/param.h>
 #include <sys/mbuf.h>
@@ -127,6 +127,7 @@
 	} else if (etype == htobe16(ETHERTYPE_IPV6)) {
 		struct ip6_hdr ip6_store;
 		const struct ip6_hdr *ip6;
+		uint32_t flowlabel;
 
 		ip6 = agr_m_extract(m, off, sizeof(*ip6), &ip6_store);
 		if (ip6 == NULL) {
@@ -137,7 +138,8 @@
 		hash = HASH(&ip6->ip6_dst, sizeof(ip6->ip6_dst), hash);
 		/* hash = HASH(&ip6->ip6_nxt, sizeof(ip6->ip6_nxt), hash); */
 
-		/* use flow label? */
+		flowlabel = ip6->ip6_flow & IPV6_FLOWLABEL_MASK;
+		hash = HASH(&flowlabel, sizeof(flowlabel), hash);
 
 		/* use port numbers for tcp and udp? */
 	}
--- a/sys/net/agr/if_agrsubr.c	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/agr/if_agrsubr.c	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_agrsubr.c,v 1.1.8.2 2007/02/26 09:11:39 yamt Exp $	*/
+/*	$NetBSD: if_agrsubr.c,v 1.1.8.3 2007/09/03 14:42:26 yamt Exp $	*/
 
 /*-
  * Copyright (c)2005 YAMAMOTO Takashi,
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_agrsubr.c,v 1.1.8.2 2007/02/26 09:11:39 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_agrsubr.c,v 1.1.8.3 2007/09/03 14:42:26 yamt Exp $");
 
 #include "bpfilter.h"
 #include "opt_inet.h"
@@ -52,14 +52,14 @@
 };
 
 static struct agr_mc_entry *agr_mc_lookup(struct agr_multiaddrs *,
-    const struct ifreq *);
+    const struct sockaddr *);
 static int agrport_mc_add_callback(struct agr_port *, void *);
 static int agrport_mc_del_callback(struct agr_port *, void *);
 static int agrmc_mc_add_callback(struct agr_mc_entry *, void *);
 static int agrmc_mc_del_callback(struct agr_mc_entry *, void *);
 
-static int agr_mc_add(struct agr_multiaddrs *, const struct ifreq *);
-static int agr_mc_del(struct agr_multiaddrs *, const struct ifreq *);
+static int agr_mc_add(struct agr_multiaddrs *, const struct sockaddr *);
+static int agr_mc_del(struct agr_multiaddrs *, const struct sockaddr *);
 
 int
 agr_mc_purgeall(struct agr_softc *sc, struct agr_multiaddrs *ama)
@@ -74,7 +74,7 @@
 			/* XXX XXX */
 			printf("%s: error %d\n", __func__, error);
 		}
-		
+		TAILQ_REMOVE(&ama->ama_addrs, ame, ame_q);
 		free(ame, M_DEVBUF);
 	}
 
@@ -93,11 +93,9 @@
 /* ==================== */
 
 static struct agr_mc_entry *
-agr_mc_lookup(struct agr_multiaddrs *ama, const struct ifreq *ifr)
+agr_mc_lookup(struct agr_multiaddrs *ama, const struct sockaddr *sa)
 {
 	struct agr_mc_entry *ame;
-	const struct sockaddr *sa;
-	sa = &ifr->ifr_addr;
 
 	TAILQ_FOREACH(ame, &ama->ama_addrs, ame_q) {
 		if (!memcmp(&ame->ame_ifr.ifr_ss, sa, sa->sa_len))
@@ -129,12 +127,11 @@
 }
 
 static int
-agr_mc_add(struct agr_multiaddrs *ama, const struct ifreq *ifr)
+agr_mc_add(struct agr_multiaddrs *ama, const struct sockaddr *sa)
 {
 	struct agr_mc_entry *ame;
-	const struct sockaddr *sa;
 
-	ame = agr_mc_lookup(ama, ifr);
+	ame = agr_mc_lookup(ama, sa);
 	if (ame) {
 		ame->ame_refcnt++;
 		return 0;
@@ -144,19 +141,19 @@
 	if (ame == NULL)
 		return ENOMEM;
 
-	sa = &ifr->ifr_addr;
 	memcpy(&ame->ame_ifr.ifr_ss, sa, sa->sa_len);
 	ame->ame_refcnt = 1;
+	TAILQ_INSERT_TAIL(&ama->ama_addrs, ame, ame_q);
 
 	return ENETRESET;
 }
 
 static int
-agr_mc_del(struct agr_multiaddrs *ama, const struct ifreq *ifr)
+agr_mc_del(struct agr_multiaddrs *ama, const struct sockaddr *sa)
 {
 	struct agr_mc_entry *ame;
 
-	ame = agr_mc_lookup(ama, ifr);
+	ame = agr_mc_lookup(ama, sa);
 	if (ame == NULL)
 		return ENOENT;
 
@@ -164,6 +161,7 @@
 	if (ame->ame_refcnt > 0)
 		return 0;
 
+	TAILQ_REMOVE(&ama->ama_addrs, ame, ame_q);
 	free(ame, M_DEVBUF);
 
 	return ENETRESET;
@@ -233,7 +231,7 @@
 agrport_mc_del_callback(struct agr_port *port, void *arg)
 {
 
-	return agrport_ioctl(port, SIOCADDMULTI, arg);
+	return agrport_ioctl(port, SIOCDELMULTI, arg);
 }
 
 int
@@ -243,9 +241,9 @@
 	int error;
 
 	if (add)
-		error = agr_mc_add(ama, ifr);
+		error = agr_mc_add(ama, ifreq_getaddr(SIOCADDMULTI, ifr));
 	else
-		error = agr_mc_del(ama, ifr);
+		error = agr_mc_del(ama, ifreq_getaddr(SIOCDELMULTI, ifr));
 
 	if (error != ENETRESET)
 		return error;
@@ -264,7 +262,7 @@
 
 	memset(&ifmr, 0, sizeof(ifmr));
 	ifmr.ifm_count = 0;
-	error = agrport_ioctl(port, SIOCGIFMEDIA, (caddr_t)&ifmr);
+	error = agrport_ioctl(port, SIOCGIFMEDIA, (void *)&ifmr);
 
 	if (error == 0) {
 		*media = ifmr.ifm_active;
--- a/sys/net/agr/if_agrtimer.c	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/agr/if_agrtimer.c	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_agrtimer.c,v 1.1.8.1 2006/06/21 15:10:45 yamt Exp $	*/
+/*	$NetBSD: if_agrtimer.c,v 1.1.8.2 2007/09/03 14:42:27 yamt Exp $	*/
 
 /*-
  * Copyright (c)2005 YAMAMOTO Takashi,
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_agrtimer.c,v 1.1.8.1 2006/06/21 15:10:45 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_agrtimer.c,v 1.1.8.2 2007/09/03 14:42:27 yamt Exp $");
 
 #include <sys/param.h>
 #include <sys/callout.h>
@@ -46,7 +46,7 @@
 agrtimer_init(struct agr_softc *sc)
 {
 
-	callout_init(&sc->sc_callout);
+	callout_init(&sc->sc_callout, 0);
 	callout_setfunc(&sc->sc_callout, agrtimer_tick, sc);
 }
 
@@ -69,11 +69,10 @@
 {
 	struct agr_softc *sc = arg;
 	const struct agr_iftype_ops *iftop = sc->sc_iftop;
-	int s;
 
 	KASSERT(iftop);
 
-	s = AGR_LOCK(sc);
+	AGR_LOCK(sc);
 	if (iftop->iftop_tick) {
 		(*iftop->iftop_tick)(sc);
 	}
@@ -81,7 +80,7 @@
 		agr_port_foreach(sc, agrtimer_port_tick, sc);
 	}
 	callout_schedule(&sc->sc_callout, hz);
-	AGR_UNLOCK(sc, s);
+	AGR_UNLOCK(sc);
 }
 
 static int
--- a/sys/net/agr/if_agrvar_impl.h	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/agr/if_agrvar_impl.h	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_agrvar_impl.h,v 1.1.8.3 2007/02/26 09:11:39 yamt Exp $	*/
+/*	$NetBSD: if_agrvar_impl.h,v 1.1.8.4 2007/09/03 14:42:27 yamt Exp $	*/
 
 /*-
  * Copyright (c)2005 YAMAMOTO Takashi,
@@ -33,7 +33,7 @@
  * implementaion details for agr(4) driver.  (contrast to if_agrvar.h)
  */
 
-#include <sys/lock.h>
+#include <sys/mutex.h>
 #include <sys/queue.h>
 
 struct agr_port;
@@ -43,7 +43,7 @@
 	struct ifnet *port_agrifp;
 	struct ifnet *port_ifp;
 	TAILQ_ENTRY(agr_port) port_q;
-	int (*port_ioctl)(struct ifnet *, u_long, caddr_t);
+	int (*port_ioctl)(struct ifnet *, u_long, void *);
 	void *port_iftprivate;
 	int port_flags;
 	u_int port_media;
@@ -103,8 +103,8 @@
 };
 
 struct agr_softc {
-	struct lock sc_ioctl_lock;
-	struct simplelock sc_lock;
+	kmutex_t sc_ioctl_lock;
+	kmutex_t sc_lock;
 	struct callout sc_callout;
 	int sc_nports;
 	TAILQ_HEAD(, agr_port) sc_ports;
@@ -118,16 +118,16 @@
 	((struct agr_softc *)(port)->port_agrifp->if_softc)
 
 #define	AGR_LOCK(sc)		agr_lock(sc)
-#define	AGR_UNLOCK(sc, s)	agr_unlock((sc), (s))
-#define	AGR_ASSERT_LOCKED(sc)	LOCK_ASSERT(simple_lock_held(&(sc)->sc_lock))
+#define	AGR_UNLOCK(sc)		agr_unlock(sc)
+#define	AGR_ASSERT_LOCKED(sc)	KASSERT(mutex_owned(&(sc)->sc_lock))
 
-int agr_lock(struct agr_softc *);
-void agr_unlock(struct agr_softc *, int);
+void agr_lock(struct agr_softc *);
+void agr_unlock(struct agr_softc *);
 
 void agr_ioctl_lock(struct agr_softc *);
 void agr_ioctl_unlock(struct agr_softc *);
 
-int agrport_ioctl(struct agr_port *, u_long, caddr_t);
+int agrport_ioctl(struct agr_port *, u_long, void *);
 
 struct agr_softc *agr_alloc_softc(void);
 void agr_free_softc(struct agr_softc *);
--- a/sys/net/bpf.c	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/bpf.c	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpf.c,v 1.109.2.3 2006/12/30 20:50:20 yamt Exp $	*/
+/*	$NetBSD: bpf.c,v 1.109.2.4 2007/09/03 14:42:00 yamt Exp $	*/
 
 /*
  * Copyright (c) 1990, 1991, 1993
@@ -39,7 +39,13 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.109.2.3 2006/12/30 20:50:20 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bpf.c,v 1.109.2.4 2007/09/03 14:42:00 yamt Exp $");
+
+#if defined(_KERNEL_OPT)
+#include "opt_bpf.h"
+#include "sl.h"
+#include "strip.h"
+#endif
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -78,11 +84,8 @@
 #include <netinet/in.h>
 #include <netinet/if_inarp.h>
 
-#if defined(_KERNEL_OPT)
-#include "opt_bpf.h"
-#include "sl.h"
-#include "strip.h"
-#endif
+
+#include <compat/sys/sockio.h>
 
 #ifndef BPF_BUFSIZE
 /*
@@ -112,7 +115,7 @@
  * Use a mutex to avoid a race condition between gathering the stats/peers
  * and opening/closing the device.
  */
-struct simplelock bpf_slock;
+static kmutex_t bpf_mtx;
 
 /*
  *  bpf_iflist is the list of interfaces; each corresponds to an ifnet
@@ -367,11 +370,11 @@
 void
 bpfilterattach(int n)
 {
-	simple_lock_init(&bpf_slock);
+	mutex_init(&bpf_mtx, MUTEX_DEFAULT, IPL_NONE);
 
-	simple_lock(&bpf_slock);
+	mutex_enter(&bpf_mtx);
 	LIST_INIT(&bpf_list);
-	simple_unlock(&bpf_slock);
+	mutex_exit(&bpf_mtx);
 
 	bpf_gstats.bs_recv = 0;
 	bpf_gstats.bs_drop = 0;
@@ -398,11 +401,11 @@
 	d->bd_bufsize = bpf_bufsize;
 	d->bd_seesent = 1;
 	d->bd_pid = l->l_proc->p_pid;
-	callout_init(&d->bd_callout);
+	callout_init(&d->bd_callout, 0);
 
-	simple_lock(&bpf_slock);
+	mutex_enter(&bpf_mtx);
 	LIST_INSERT_HEAD(&bpf_list, d, bd_list);
-	simple_unlock(&bpf_slock);
+	mutex_exit(&bpf_mtx);
 
 	return fdclone(l, fp, fd, flag, &bpf_fileops, d);
 }
@@ -431,9 +434,10 @@
 		bpf_detachd(d);
 	splx(s);
 	bpf_freed(d);
-	simple_lock(&bpf_slock);
+	mutex_enter(&bpf_mtx);
 	LIST_REMOVE(d, bd_list);
-	simple_unlock(&bpf_slock);
+	mutex_exit(&bpf_mtx);
+	callout_destroy(&d->bd_callout);
 	free(d, M_DEVBUF);
 	fp->f_data = NULL;
 
@@ -562,8 +566,6 @@
 		fownsignal(d->bd_pgid, SIGIO, 0, 0, NULL);
 
 	selnotify(&d->bd_sel, 0);
-	/* XXX */
-	d->bd_sel.sel_pid = 0;
 }
 
 
@@ -795,6 +797,9 @@
 	/*
 	 * Set interface name.
 	 */
+#ifdef OBIOCGETIF
+	case OBIOCGETIF:
+#endif
 	case BIOCGETIF:
 		if (d->bd_bif == 0)
 			error = EINVAL;
@@ -805,6 +810,9 @@
 	/*
 	 * Set interface.
 	 */
+#ifdef OBIOCSETIF
+	case OBIOCSETIF:
+#endif
 	case BIOCSETIF:
 		error = bpf_setif(d, addr);
 		break;
@@ -1009,7 +1017,7 @@
 		    strcmp(ifp->if_xname, ifr->ifr_name) != 0)
 			continue;
 		/* skip additional entry */
-		if ((caddr_t *)bp->bif_driverp != &ifp->if_bpf)
+		if ((void **)bp->bif_driverp != &ifp->if_bpf)
 			continue;
 		/*
 		 * We found the requested interface.
@@ -1444,7 +1452,7 @@
 	/*
 	 * Append the bpf header.
 	 */
-	hp = (struct bpf_hdr *)(d->bd_sbuf + curlen);
+	hp = (struct bpf_hdr *)((char *)d->bd_sbuf + curlen);
 	hp->bh_tstamp = *tv;
 	hp->bh_datalen = pktlen;
 	hp->bh_hdrlen = hdrlen;
@@ -1601,7 +1609,7 @@
 	struct bpf_if *bp;
 
 	for (bp = bpf_iflist; bp != NULL; bp = bp->bif_next) {
-		if ((caddr_t *)bp->bif_driverp == &ifp->if_bpf)
+		if ((void **)bp->bif_driverp == &ifp->if_bpf)
 			break;
 	}
 	if (bp == NULL)
@@ -1734,7 +1742,7 @@
 	if (elem_size < 1 || elem_count < 0)
 		return (EINVAL);
 
-	simple_lock(&bpf_slock);
+	mutex_enter(&bpf_mtx);
 	LIST_FOREACH(dp, &bpf_list, bd_list) {
 		if (len >= elem_size && elem_count > 0) {
 #define BPF_EXT(field)	dpe.bde_ ## field = dp->bd_ ## field
@@ -1769,7 +1777,7 @@
 				elem_count--;
 		}
 	}
-	simple_unlock(&bpf_slock);
+	mutex_exit(&bpf_mtx);
 
 	*oldlenp = needed;
 
--- a/sys/net/bpfdesc.h	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/bpfdesc.h	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: bpfdesc.h,v 1.22.2.1 2006/06/21 15:10:26 yamt Exp $	*/
+/*	$NetBSD: bpfdesc.h,v 1.22.2.2 2007/09/03 14:42:00 yamt Exp $	*/
 
 /*
  * Copyright (c) 1990, 1991, 1993
@@ -59,9 +59,9 @@
 	 *   fbuf (free) - When read is done, put cluster here.
 	 * On receiving, if sbuf is full and fbuf is 0, packet is dropped.
 	 */
-	caddr_t		bd_sbuf;	/* store slot */
-	caddr_t		bd_hbuf;	/* hold slot */
-	caddr_t		bd_fbuf;	/* free slot */
+	void *		bd_sbuf;	/* store slot */
+	void *		bd_hbuf;	/* hold slot */
+	void *		bd_fbuf;	/* free slot */
 	int 		bd_slen;	/* current length of store buffer */
 	int 		bd_hlen;	/* current length of hold buffer */
 
@@ -89,7 +89,7 @@
 	u_char		bd_pad;		/* explicit alignment */
 	struct selinfo	bd_sel;		/* bsd select info */
 #endif
-	struct callout	bd_callout;	/* for BPF timeouts with select */
+	callout_t	bd_callout;	/* for BPF timeouts with select */
 	pid_t		bd_pid;		/* corresponding PID */
 	LIST_ENTRY(bpf_d) bd_list;	/* list of all BPF's */
 };
--- a/sys/net/bridgestp.c	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/bridgestp.c	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: bridgestp.c,v 1.6.4.2 2006/12/30 20:50:20 yamt Exp $	*/
+/*	$NetBSD: bridgestp.c,v 1.6.4.3 2007/09/03 14:42:01 yamt 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.6.4.2 2006/12/30 20:50:20 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bridgestp.c,v 1.6.4.3 2007/09/03 14:42:01 yamt Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -265,11 +265,11 @@
 	bpdu.cbu_hellotime = htons(cu->cu_hello_time);
 	bpdu.cbu_forwarddelay = htons(cu->cu_forward_delay);
 
-	memcpy(eh->ether_shost, LLADDR(ifp->if_sadl), ETHER_ADDR_LEN);
+	memcpy(eh->ether_shost, CLLADDR(ifp->if_sadl), ETHER_ADDR_LEN);
 	memcpy(eh->ether_dhost, bstp_etheraddr, ETHER_ADDR_LEN);
 	eh->ether_type = htons(sizeof(bpdu));
 
-	memcpy(mtod(m, caddr_t) + sizeof(*eh), &bpdu, sizeof(bpdu));
+	memcpy(mtod(m, char *) + sizeof(*eh), &bpdu, sizeof(bpdu));
 
 	s = splnet();
 	bridge_enqueue(sc, ifp, m, 0);
@@ -375,7 +375,7 @@
 
 	eh = mtod(m, struct ether_header *);
 
-	memcpy(eh->ether_shost, LLADDR(ifp->if_sadl), ETHER_ADDR_LEN);
+	memcpy(eh->ether_shost, CLLADDR(ifp->if_sadl), ETHER_ADDR_LEN);
 	memcpy(eh->ether_dhost, bstp_etheraddr, ETHER_ADDR_LEN);
 	eh->ether_type = htons(sizeof(bpdu));
 
@@ -385,7 +385,7 @@
 	bpdu.tbu_protover = 0;
 	bpdu.tbu_bpdutype = BSTP_MSGTYPE_TCN;
 
-	memcpy(mtod(m, caddr_t) + sizeof(*eh), &bpdu, sizeof(bpdu));
+	memcpy(mtod(m, char *) + sizeof(*eh), &bpdu, sizeof(bpdu));
 
 	s = splnet();
 	bridge_enqueue(sc, ifp, m, 0);
@@ -614,7 +614,7 @@
 	    (m = m_pullup(m, sizeof(tpdu))) == NULL)
 		goto out;
 
-	memcpy(&tpdu, mtod(m, caddr_t), sizeof(tpdu));
+	memcpy(&tpdu, mtod(m, void *), sizeof(tpdu));
 
 	if (tpdu.tbu_dsap != LLC_8021D_LSAP ||
 	    tpdu.tbu_ssap != LLC_8021D_LSAP ||
@@ -632,7 +632,7 @@
 		if (m->m_len < sizeof(cpdu) &&
 		    (m = m_pullup(m, sizeof(cpdu))) == NULL)
 			goto out;
-		memcpy(&cpdu, mtod(m, caddr_t), sizeof(cpdu));
+		memcpy(&cpdu, mtod(m, void *), sizeof(cpdu));
 
 		cu.cu_rootid =
 		    (((uint64_t)ntohs(cpdu.cbu_rootpri)) << 48) |
@@ -822,8 +822,8 @@
 			mif = bif;
 			continue;
 		}
-		if (memcmp(LLADDR(bif->bif_ifp->if_sadl),
-		    LLADDR(mif->bif_ifp->if_sadl), ETHER_ADDR_LEN) < 0) {
+		if (memcmp(CLLADDR(bif->bif_ifp->if_sadl),
+		    CLLADDR(mif->bif_ifp->if_sadl), ETHER_ADDR_LEN) < 0) {
 			mif = bif;
 			continue;
 		}
@@ -835,12 +835,12 @@
 
 	sc->sc_bridge_id =
 	    (((uint64_t)sc->sc_bridge_priority) << 48) |
-	    (((uint64_t)LLADDR(mif->bif_ifp->if_sadl)[0]) << 40) |
-	    (((uint64_t)LLADDR(mif->bif_ifp->if_sadl)[1]) << 32) |
-	    (LLADDR(mif->bif_ifp->if_sadl)[2] << 24) |
-	    (LLADDR(mif->bif_ifp->if_sadl)[3] << 16) |
-	    (LLADDR(mif->bif_ifp->if_sadl)[4] << 8) |
-	    (LLADDR(mif->bif_ifp->if_sadl)[5]);
+	    (((uint64_t)CLLADDR(mif->bif_ifp->if_sadl)[0]) << 40) |
+	    (((uint64_t)CLLADDR(mif->bif_ifp->if_sadl)[1]) << 32) |
+	    (CLLADDR(mif->bif_ifp->if_sadl)[2] << 24) |
+	    (CLLADDR(mif->bif_ifp->if_sadl)[3] << 16) |
+	    (CLLADDR(mif->bif_ifp->if_sadl)[4] << 8) |
+	    (CLLADDR(mif->bif_ifp->if_sadl)[5]);
 
 	sc->sc_designated_root = sc->sc_bridge_id;
 	sc->sc_root_path_cost = 0;
--- a/sys/net/if.c	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/if.c	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.159.2.3 2007/02/26 09:11:32 yamt Exp $	*/
+/*	$NetBSD: if.c,v 1.159.2.4 2007/09/03 14:42:01 yamt Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc.
@@ -97,14 +97,10 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.159.2.3 2007/02/26 09:11:32 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.159.2.4 2007/09/03 14:42:01 yamt Exp $");
 
 #include "opt_inet.h"
 
-#include "opt_compat_linux.h"
-#include "opt_compat_svr4.h"
-#include "opt_compat_ultrix.h"
-#include "opt_compat_43.h"
 #include "opt_atalk.h"
 #include "opt_natm.h"
 #include "opt_pfil_hooks.h"
@@ -151,20 +147,18 @@
 #include <netinet/ip_carp.h>
 #endif
 
-#if defined(COMPAT_43) || defined(COMPAT_LINUX) || defined(COMPAT_SVR4) || defined(COMPAT_ULTRIX) || defined(LKM)
-#define COMPAT_OSOCK
+#include <compat/sys/sockio.h>
 #include <compat/sys/socket.h>
-#endif
 
 MALLOC_DEFINE(M_IFADDR, "ifaddr", "interface address");
 MALLOC_DEFINE(M_IFMADDR, "ether_multi", "link-level multicast address");
 
 int	ifqmaxlen = IFQ_MAXLEN;
-struct	callout if_slowtimo_ch;
+callout_t if_slowtimo_ch;
 
 int netisr;			/* scheduling bits for network */
 
-static int	if_rt_walktree(struct radix_node *, void *);
+static int	if_rt_walktree(struct rtentry *, void *);
 
 static struct if_clone *if_clone_lookup(const char *, int *);
 static int	if_clone_list(struct if_clonereq *);
@@ -188,7 +182,7 @@
 ifinit(void)
 {
 
-	callout_init(&if_slowtimo_ch);
+	callout_init(&if_slowtimo_ch, 0);
 	if_slowtimo(NULL);
 #ifdef PFIL_HOOKS
 	if_pfil.ph_type = PFIL_TYPE_IFNET;
@@ -208,7 +202,7 @@
     const struct sockaddr *so, struct rtentry *rt)
 {
 
-	return (ENXIO);
+	return ENXIO;
 }
 
 void
@@ -226,17 +220,17 @@
 }
 
 int
-if_nullioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
+if_nullioctl(struct ifnet *ifp, u_long cmd, void *data)
 {
 
-	return (ENXIO);
+	return ENXIO;
 }
 
 int
 if_nullinit(struct ifnet *ifp)
 {
 
-	return (ENXIO);
+	return ENXIO;
 }
 
 void
@@ -277,8 +271,8 @@
 if_alloc_sadl(struct ifnet *ifp)
 {
 	unsigned socksize, ifasize;
-	int namelen, masklen;
-	struct sockaddr_dl *sdl;
+	int addrlen, namelen;
+	struct sockaddr_dl *mask, *sdl;
 	struct ifaddr *ifa;
 
 	/*
@@ -290,23 +284,20 @@
 		if_free_sadl(ifp);
 
 	namelen = strlen(ifp->if_xname);
-	masklen = offsetof(struct sockaddr_dl, sdl_data[0]) + namelen;
-	socksize = masklen + ifp->if_addrlen;
-#define ROUNDUP(a) (1 + (((a) - 1) | (sizeof(long) - 1)))
-	if (socksize < sizeof(*sdl))
-		socksize = sizeof(*sdl);
-	socksize = ROUNDUP(socksize);
+	addrlen = ifp->if_addrlen;
+	socksize = roundup(sockaddr_dl_measure(namelen, addrlen), sizeof(long));
 	ifasize = sizeof(*ifa) + 2 * socksize;
 	ifa = (struct ifaddr *)malloc(ifasize, M_IFADDR, M_WAITOK);
-	memset((caddr_t)ifa, 0, ifasize);
+	memset(ifa, 0, ifasize);
+
 	sdl = (struct sockaddr_dl *)(ifa + 1);
-	sdl->sdl_len = socksize;
-	sdl->sdl_family = AF_LINK;
-	bcopy(ifp->if_xname, sdl->sdl_data, namelen);
-	sdl->sdl_nlen = namelen;
-	sdl->sdl_alen = ifp->if_addrlen;
-	sdl->sdl_index = ifp->if_index;
-	sdl->sdl_type = ifp->if_type;
+	mask = (struct sockaddr_dl *)(socksize + (char *)sdl);
+
+	sockaddr_dl_init(sdl, socksize, ifp->if_index, ifp->if_type,
+	    ifp->if_xname, namelen, NULL, addrlen);
+	mask->sdl_len = sockaddr_dl_measure(namelen, 0);
+	memset(&mask->sdl_data[0], 0xff, namelen);
+
 	ifnet_addrs[ifp->if_index] = ifa;
 	IFAREF(ifa);
 	ifa->ifa_ifp = ifp;
@@ -315,11 +306,7 @@
 	IFAREF(ifa);
 	ifa->ifa_addr = (struct sockaddr *)sdl;
 	ifp->if_sadl = sdl;
-	sdl = (struct sockaddr_dl *)(socksize + (caddr_t)sdl);
-	ifa->ifa_netmask = (struct sockaddr *)sdl;
-	sdl->sdl_len = masklen;
-	while (namelen != 0)
-		sdl->sdl_data[--namelen] = 0xff;
+	ifa->ifa_netmask = (struct sockaddr *)mask;
 }
 
 /*
@@ -369,7 +356,7 @@
 	TAILQ_INIT(&ifp->if_addrlist);
 	TAILQ_INSERT_TAIL(&ifnet, ifp, if_list);
 	ifp->if_index = if_index;
-	if (ifindex2ifnet == 0)
+	if (ifindex2ifnet == NULL)
 		if_index++;
 	else
 		while (ifp->if_index < if_indexlim &&
@@ -406,10 +393,10 @@
 	 *	struct ifadd **ifnet_addrs
 	 *	struct ifnet **ifindex2ifnet
 	 */
-	if (ifnet_addrs == 0 || ifindex2ifnet == 0 ||
+	if (ifnet_addrs == NULL || ifindex2ifnet == NULL ||
 	    ifp->if_index >= if_indexlim) {
 		size_t m, n, oldlim;
-		caddr_t q;
+		void *q;
 
 		oldlim = if_indexlim;
 		while (ifp->if_index >= if_indexlim)
@@ -418,22 +405,22 @@
 		/* grow ifnet_addrs */
 		m = oldlim * sizeof(struct ifaddr *);
 		n = if_indexlim * sizeof(struct ifaddr *);
-		q = (caddr_t)malloc(n, M_IFADDR, M_WAITOK);
+		q = (void *)malloc(n, M_IFADDR, M_WAITOK);
 		memset(q, 0, n);
-		if (ifnet_addrs) {
-			bcopy((caddr_t)ifnet_addrs, q, m);
-			free((caddr_t)ifnet_addrs, M_IFADDR);
+		if (ifnet_addrs != NULL) {
+			memcpy(q, ifnet_addrs, m);
+			free((void *)ifnet_addrs, M_IFADDR);
 		}
 		ifnet_addrs = (struct ifaddr **)q;
 
 		/* grow ifindex2ifnet */
 		m = oldlim * sizeof(struct ifnet *);
 		n = if_indexlim * sizeof(struct ifnet *);
-		q = (caddr_t)malloc(n, M_IFADDR, M_WAITOK);
+		q = (void *)malloc(n, M_IFADDR, M_WAITOK);
 		memset(q, 0, n);
-		if (ifindex2ifnet) {
-			bcopy((caddr_t)ifindex2ifnet, q, m);
-			free((caddr_t)ifindex2ifnet, M_IFADDR);
+		if (ifindex2ifnet != NULL) {
+			memcpy(q, (void *)ifindex2ifnet, m);
+			free((void *)ifindex2ifnet, M_IFADDR);
 		}
 		ifindex2ifnet = (struct ifnet **)q;
 	}
@@ -487,7 +474,7 @@
 	int s;
 
 	s = splnet();
-	TAILQ_FOREACH(ifp, &ifnet, if_list)
+	IFNET_FOREACH(ifp)
 		if_attachdomain1(ifp);
 	splx(s);
 }
@@ -503,7 +490,7 @@
 	/* address family dependent data region */
 	memset(ifp->if_afdata, 0, sizeof(ifp->if_afdata));
 	DOMAIN_FOREACH(dp) {
-		if (dp->dom_ifattach)
+		if (dp->dom_ifattach != NULL)
 			ifp->if_afdata[dp->dom_family] =
 			    (*dp->dom_ifattach)(ifp);
 	}
@@ -554,7 +541,6 @@
 #endif
 	struct domain *dp;
 	const struct protosw *pr;
-	struct radix_node_head *rnh;
 	int s, i, family, purged;
 
 	/*
@@ -580,16 +566,10 @@
 
 #if NCARP > 0
 	/* Remove the interface from any carp group it is a part of.  */
-	if (ifp->if_carp && ifp->if_type != IFT_CARP)
+	if (ifp->if_carp != NULL && ifp->if_type != IFT_CARP)
 		carp_ifdetach(ifp);
 #endif
 
-#ifdef PFIL_HOOKS
-	(void)pfil_run_hooks(&if_pfil,
-	    (struct mbuf **)PFIL_IFNET_DETACH, ifp, PFIL_IFNET);
-	(void)pfil_head_unregister(&ifp->if_pfil);
-#endif
-
 	/*
 	 * Rip all the addresses off the interface.  This should make
 	 * all of the routes go away.
@@ -654,13 +634,11 @@
 	if_free_sadl(ifp);
 
 	/* Walk the routing table looking for stragglers. */
-	for (i = 0; i <= AF_MAX; i++) {
-		if ((rnh = rt_tables[i]) != NULL)
-			(void) (*rnh->rnh_walktree)(rnh, if_rt_walktree, ifp);
-	}
+	for (i = 0; i <= AF_MAX; i++)
+		(void)rt_walktree(i, if_rt_walktree, ifp);
 
 	DOMAIN_FOREACH(dp) {
-		if (dp->dom_ifdetach && ifp->if_afdata[dp->dom_family])
+		if (dp->dom_ifdetach != NULL && ifp->if_afdata[dp->dom_family])
 			(*dp->dom_ifdetach)(ifp,
 			    ifp->if_afdata[dp->dom_family]);
 
@@ -677,17 +655,20 @@
 		 * addresses.  (Protocols which might store ifnet
 		 * pointers are marked with PR_PURGEIF.)
 		 */
-		for (pr = dp->dom_protosw;
-		     pr < dp->dom_protoswNPROTOSW; pr++) {
+		for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) {
 			so.so_proto = pr;
-			if (pr->pr_usrreq != NULL &&
-			    pr->pr_flags & PR_PURGEIF)
-				(void) (*pr->pr_usrreq)(&so,
-				    PRU_PURGEIF, NULL, NULL,
-				    (struct mbuf *) ifp, curlwp);
+			if (pr->pr_usrreq != NULL && pr->pr_flags & PR_PURGEIF)
+				(void)(*pr->pr_usrreq)(&so, PRU_PURGEIF, NULL,
+				    NULL, (struct mbuf *)ifp, curlwp);
 		}
 	}
 
+#ifdef PFIL_HOOKS
+	(void)pfil_run_hooks(&if_pfil,
+	    (struct mbuf **)PFIL_IFNET_DETACH, ifp, PFIL_IFNET);
+	(void)pfil_head_unregister(&ifp->if_pfil);
+#endif
+
 	/* Announce that the interface is gone. */
 	rt_ifannouncemsg(ifp, IFAN_DEPARTURE);
 
@@ -715,7 +696,7 @@
 	struct mbuf *m, *prev, *next;
 
 	prev = NULL;
-	for (m = q->ifq_head; m; m = next) {
+	for (m = q->ifq_head; m != NULL; m = next) {
 		next = m->m_nextpkt;
 #ifdef DIAGNOSTIC
 		if ((m->m_flags & M_PKTHDR) == 0) {
@@ -728,7 +709,7 @@
 			continue;
 		}
 
-		if (prev)
+		if (prev != NULL)
 			prev->m_nextpkt = m->m_nextpkt;
 		else
 			q->ifq_head = m->m_nextpkt;
@@ -747,25 +728,25 @@
  * ifnet.
  */
 static int
-if_rt_walktree(struct radix_node *rn, void *v)
+if_rt_walktree(struct rtentry *rt, void *v)
 {
 	struct ifnet *ifp = (struct ifnet *)v;
-	struct rtentry *rt = (struct rtentry *)rn;
 	int error;
 
-	if (rt->rt_ifp == ifp) {
-		/* Delete the entry. */
-		++rt->rt_refcnt;
-		error = rtrequest(RTM_DELETE, rt_key(rt), rt->rt_gateway,
-		    rt_mask(rt), rt->rt_flags, NULL);
-		KASSERT((rt->rt_flags & RTF_UP) == 0);
-		rt->rt_ifp = NULL;
-		RTFREE(rt);
-		if (error)
-			printf("%s: warning: unable to delete rtentry @ %p, "
-			    "error = %d\n", ifp->if_xname, rt, error);
-	}
-	return (0);
+	if (rt->rt_ifp != ifp)
+		return 0;
+
+	/* Delete the entry. */
+	++rt->rt_refcnt;
+	error = rtrequest(RTM_DELETE, rt_getkey(rt), rt->rt_gateway,
+	    rt_mask(rt), rt->rt_flags, NULL);
+	KASSERT((rt->rt_flags & RTF_UP) == 0);
+	rt->rt_ifp = NULL;
+	RTFREE(rt);
+	if (error != 0)
+		printf("%s: warning: unable to delete rtentry @ %p, "
+		    "error = %d\n", ifp->if_xname, rt, error);
+	return 0;
 }
 
 /*
@@ -779,12 +760,12 @@
 
 	ifc = if_clone_lookup(name, &unit);
 	if (ifc == NULL)
-		return (EINVAL);
+		return EINVAL;
 
 	if (ifunit(name) != NULL)
-		return (EEXIST);
+		return EEXIST;
 
-	return ((*ifc->ifc_create)(ifc, unit));
+	return (*ifc->ifc_create)(ifc, unit);
 }
 
 /*
@@ -798,16 +779,16 @@
 
 	ifc = if_clone_lookup(name, NULL);
 	if (ifc == NULL)
-		return (EINVAL);
+		return EINVAL;
 
 	ifp = ifunit(name);
 	if (ifp == NULL)
-		return (ENXIO);
+		return ENXIO;
 
 	if (ifc->ifc_destroy == NULL)
-		return (EOPNOTSUPP);
+		return EOPNOTSUPP;
 
-	return ((*ifc->ifc_destroy)(ifp));
+	return (*ifc->ifc_destroy)(ifp);
 }
 
 /*
@@ -827,29 +808,29 @@
 		continue;
 
 	if (cp == name || cp - name == IFNAMSIZ || !*cp)
-		return (NULL);	/* No name or unit number */
+		return NULL;	/* No name or unit number */
 
 	LIST_FOREACH(ifc, &if_cloners, ifc_list) {
 		if (strlen(ifc->ifc_name) == cp - name &&
-		    !strncmp(name, ifc->ifc_name, cp - name))
+		    strncmp(name, ifc->ifc_name, cp - name) == 0)
 			break;
 	}
 
 	if (ifc == NULL)
-		return (NULL);
+		return NULL;
 
 	unit = 0;
 	while (cp - name < IFNAMSIZ && *cp) {
 		if (*cp < '0' || *cp > '9' || unit > INT_MAX / 10) {
 			/* Bogus unit number. */
-			return (NULL);
+			return NULL;
 		}
 		unit = (unit * 10) + (*cp++ - '0');
 	}
 
 	if (unitp != NULL)
 		*unitp = unit;
-	return (ifc);
+	return ifc;
 }
 
 /*
@@ -887,11 +868,11 @@
 	ifcr->ifcr_total = if_cloners_count;
 	if ((dst = ifcr->ifcr_buffer) == NULL) {
 		/* Just asking how many there are. */
-		return (0);
+		return 0;
 	}
 
 	if (ifcr->ifcr_count < 0)
-		return (EINVAL);
+		return EINVAL;
 
 	count = (if_cloners_count < ifcr->ifcr_count) ?
 	    if_cloners_count : ifcr->ifcr_count;
@@ -902,11 +883,17 @@
 		if (outbuf[sizeof(outbuf) - 1] != '\0')
 			return ENAMETOOLONG;
 		error = copyout(outbuf, dst, sizeof(outbuf));
-		if (error)
+		if (error != 0)
 			break;
 	}
 
-	return (error);
+	return error;
+}
+
+static inline int
+equal(const struct sockaddr *sa1, const struct sockaddr *sa2)
+{
+	return sockaddr_cmp(sa1, sa2) == 0;
 }
 
 /*
@@ -919,26 +906,23 @@
 	struct ifnet *ifp;
 	struct ifaddr *ifa;
 
-#define	equal(a1, a2) \
-  (bcmp((a1), (a2), ((const struct sockaddr *)(a1))->sa_len) == 0)
-
-	TAILQ_FOREACH(ifp, &ifnet, if_list) {
+	IFNET_FOREACH(ifp) {
 		if (ifp->if_output == if_nulloutput)
 			continue;
 		TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_list) {
 			if (ifa->ifa_addr->sa_family != addr->sa_family)
 				continue;
 			if (equal(addr, ifa->ifa_addr))
-				return (ifa);
+				return ifa;
 			if ((ifp->if_flags & IFF_BROADCAST) &&
 			    ifa->ifa_broadaddr &&
 			    /* IP6 doesn't have broadcast */
 			    ifa->ifa_broadaddr->sa_len != 0 &&
 			    equal(ifa->ifa_broadaddr, addr))
-				return (ifa);
+				return ifa;
 		}
 	}
-	return (NULL);
+	return NULL;
 }
 
 /*
@@ -951,21 +935,20 @@
 	struct ifnet *ifp;
 	struct ifaddr *ifa;
 
-	TAILQ_FOREACH(ifp, &ifnet, if_list) {
+	IFNET_FOREACH(ifp) {
 		if (ifp->if_output == if_nulloutput)
 			continue;
-		if (ifp->if_flags & IFF_POINTOPOINT) {
-			TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_list) {
-				if (ifa->ifa_addr->sa_family !=
-				      addr->sa_family ||
-				    ifa->ifa_dstaddr == NULL)
-					continue;
-				if (equal(addr, ifa->ifa_dstaddr))
-					return (ifa);
-			}
+		if ((ifp->if_flags & IFF_POINTOPOINT) == 0)
+			continue;
+		TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_list) {
+			if (ifa->ifa_addr->sa_family != addr->sa_family ||
+			    ifa->ifa_dstaddr == NULL)
+				continue;
+			if (equal(addr, ifa->ifa_dstaddr))
+				return ifa;
 		}
 	}
-	return (NULL);
+	return NULL;
 }
 
 /*
@@ -983,17 +966,17 @@
 	const char *addr_data = addr->sa_data, *cplim;
 
 	if (af == AF_LINK) {
-		sdl = (const struct sockaddr_dl *)addr;
+		sdl = satocsdl(addr);
 		if (sdl->sdl_index && sdl->sdl_index < if_indexlim &&
 		    ifindex2ifnet[sdl->sdl_index] &&
 		    ifindex2ifnet[sdl->sdl_index]->if_output != if_nulloutput)
-			return (ifnet_addrs[sdl->sdl_index]);
+			return ifnet_addrs[sdl->sdl_index];
 	}
 #ifdef NETATALK
 	if (af == AF_APPLETALK) {
 		const struct sockaddr_at *sat, *sat2;
 		sat = (const struct sockaddr_at *)addr;
-		TAILQ_FOREACH(ifp, &ifnet, if_list) {
+		IFNET_FOREACH(ifp) {
 			if (ifp->if_output == if_nulloutput)
 				continue;
 			ifa = at_ifawithnet((const struct sockaddr_at *)addr, ifp);
@@ -1001,23 +984,23 @@
 				continue;
 			sat2 = (struct sockaddr_at *)ifa->ifa_addr;
 			if (sat2->sat_addr.s_net == sat->sat_addr.s_net)
-				return (ifa); /* exact match */
+				return ifa; /* exact match */
 			if (ifa_maybe == NULL) {
 				/* else keep the if with the right range */
 				ifa_maybe = ifa;
 			}
 		}
-		return (ifa_maybe);
+		return ifa_maybe;
 	}
 #endif
-	TAILQ_FOREACH(ifp, &ifnet, if_list) {
+	IFNET_FOREACH(ifp) {
 		if (ifp->if_output == if_nulloutput)
 			continue;
 		TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_list) {
 			const char *cp, *cp2, *cp3;
 
 			if (ifa->ifa_addr->sa_family != af ||
-			    ifa->ifa_netmask == 0)
+			    ifa->ifa_netmask == NULL)
  next:				continue;
 			cp = addr_data;
 			cp2 = ifa->ifa_addr->sa_data;
@@ -1030,13 +1013,13 @@
 					goto next;
 				}
 			}
-			if (ifa_maybe == 0 ||
-			    rn_refines((caddr_t)ifa->ifa_netmask,
-			    (caddr_t)ifa_maybe->ifa_netmask))
+			if (ifa_maybe == NULL ||
+			    rn_refines((void *)ifa->ifa_netmask,
+			    (void *)ifa_maybe->ifa_netmask))
 				ifa_maybe = ifa;
 		}
 	}
-	return (ifa_maybe);
+	return ifa_maybe;
 }
 
 /*
@@ -1049,8 +1032,8 @@
 
 	if ((ia = ifa_ifwithaddr(addr)) || (ia = ifa_ifwithdstaddr(addr)) ||
 	    (ia = ifa_ifwithnet(addr)))
-		return (ia);
-	return (NULL);
+		return ia;
+	return NULL;
 }
 
 /*
@@ -1062,7 +1045,7 @@
 	struct ifnet *ifp;
 	struct ifaddr *ifa;
 
-	TAILQ_FOREACH(ifp, &ifnet, if_list) {
+	IFNET_FOREACH(ifp) {
 		if (ifp->if_output == if_nulloutput)
 			continue;
 		TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_list) {
@@ -1087,20 +1070,20 @@
 	u_int af = addr->sa_family;
 
 	if (ifp->if_output == if_nulloutput)
-		return (NULL);
+		return NULL;
 
 	if (af >= AF_MAX)
-		return (NULL);
+		return NULL;
 
 	TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_list) {
 		if (ifa->ifa_addr->sa_family != af)
 			continue;
 		ifa_maybe = ifa;
-		if (ifa->ifa_netmask == 0) {
+		if (ifa->ifa_netmask == NULL) {
 			if (equal(addr, ifa->ifa_addr) ||
 			    (ifa->ifa_dstaddr &&
 			     equal(addr, ifa->ifa_dstaddr)))
-				return (ifa);
+				return ifa;
 			continue;
 		}
 		cp = addr->sa_data;
@@ -1112,9 +1095,9 @@
 				break;
 		}
 		if (cp3 == cplim)
-			return (ifa);
+			return ifa;
 	}
-	return (ifa_maybe);
+	return ifa_maybe;
 }
 
 /*
@@ -1126,11 +1109,11 @@
 link_rtrequest(int cmd, struct rtentry *rt, struct rt_addrinfo *info)
 {
 	struct ifaddr *ifa;
-	struct sockaddr *dst;
+	const struct sockaddr *dst;
 	struct ifnet *ifp;
 
-	if (cmd != RTM_ADD || ((ifa = rt->rt_ifa) == 0) ||
-	    ((ifp = ifa->ifa_ifp) == 0) || ((dst = rt_key(rt)) == 0))
+	if (cmd != RTM_ADD || ((ifa = rt->rt_ifa) == NULL) ||
+	    ((ifp = ifa->ifa_ifp) == NULL) || ((dst = rt_getkey(rt)) == NULL))
 		return;
 	if ((ifa = ifaof_ifpforaddr(dst, ifp)) != NULL) {
 		rt_replace_ifa(rt, ifa);
@@ -1145,15 +1128,15 @@
 void
 if_link_state_change(struct ifnet *ifp, int link_state)
 {
+	if (ifp->if_link_state == link_state)
+		return;
+	ifp->if_link_state = link_state;
 	/* Notify that the link state has changed. */
-	if (ifp->if_link_state != link_state) {
-		ifp->if_link_state = link_state;
-		rt_ifmsg(ifp);
+	rt_ifmsg(ifp);
 #if NCARP > 0
-		if (ifp->if_carp)
-			carp_carpdev_state(ifp);
+	if (ifp->if_carp)
+		carp_carpdev_state(ifp);
 #endif
-	}
 }
 
 /*
@@ -1218,15 +1201,14 @@
 	struct ifnet *ifp;
 	int s = splnet();
 
-	TAILQ_FOREACH(ifp, &ifnet, if_list) {
+	IFNET_FOREACH(ifp) {
 		if (ifp->if_timer == 0 || --ifp->if_timer)
 			continue;
-		if (ifp->if_watchdog)
+		if (ifp->if_watchdog != NULL)
 			(*ifp->if_watchdog)(ifp);
 	}
 	splx(s);
-	callout_reset(&if_slowtimo_ch, hz / IFNET_SLOWHZ,
-	    if_slowtimo, NULL);
+	callout_reset(&if_slowtimo_ch, hz / IFNET_SLOWHZ, if_slowtimo, NULL);
 }
 
 /*
@@ -1251,13 +1233,13 @@
 		 * consult IFF_PROMISC when it is is brought up.
 		 */
 		if (ifp->if_pcount++ != 0)
-			return (0);
+			return 0;
 		ifp->if_flags |= IFF_PROMISC;
 		if ((ifp->if_flags & IFF_UP) == 0)
-			return (0);
+			return 0;
 	} else {
 		if (--ifp->if_pcount > 0)
-			return (0);
+			return 0;
 		ifp->if_flags &= ~IFF_PROMISC;
 		/*
 		 * If the device is not configured up, we should not need to
@@ -1266,17 +1248,17 @@
 		 * again next time interface comes up).
 		 */
 		if ((ifp->if_flags & IFF_UP) == 0)
-			return (0);
+			return 0;
 	}
 	memset(&ifr, 0, sizeof(ifr));
 	ifr.ifr_flags = ifp->if_flags;
-	ret = (*ifp->if_ioctl)(ifp, SIOCSIFFLAGS, (caddr_t) &ifr);
+	ret = (*ifp->if_ioctl)(ifp, SIOCSIFFLAGS, (void *) &ifr);
 	/* Restore interface state if not successful. */
 	if (ret != 0) {
 		ifp->if_pcount = pcount;
 		ifp->if_flags = flags;
 	}
-	return (ret);
+	return ret;
 }
 
 /*
@@ -1303,68 +1285,87 @@
 	 */
 	if (i == IFNAMSIZ || (cp != name && *cp == '\0')) {
 		if (unit >= if_indexlim)
-			return (NULL);
+			return NULL;
 		ifp = ifindex2ifnet[unit];
 		if (ifp == NULL || ifp->if_output == if_nulloutput)
-			return (NULL);
-		return (ifp);
+			return NULL;
+		return ifp;
 	}
 
-	TAILQ_FOREACH(ifp, &ifnet, if_list) {
+	IFNET_FOREACH(ifp) {
 		if (ifp->if_output == if_nulloutput)
 			continue;
 	 	if (strcmp(ifp->if_xname, name) == 0)
-			return (ifp);
+			return ifp;
 	}
-	return (NULL);
+	return NULL;
 }
 
 /*
  * Interface ioctls.
  */
 int
-ifioctl(struct socket *so, u_long cmd, caddr_t data, struct lwp *l)
+ifioctl(struct socket *so, u_long cmd, void *data, struct lwp *l)
 {
 	struct ifnet *ifp;
 	struct ifreq *ifr;
 	struct ifcapreq *ifcr;
 	struct ifdatareq *ifdr;
 	int s, error = 0;
+#if defined(COMPAT_OSOCK) || defined(COMPAT_OIFREQ)
+	u_long ocmd = cmd;
+#endif
 	short oif_flags;
+#ifdef COMPAT_OIFREQ
+	struct ifreq ifrb;
+	struct oifreq *oifr = NULL;
+#endif
 
 	switch (cmd) {
-
-	case SIOCGIFCONF:
+#ifdef COMPAT_OIFREQ
 	case OSIOCGIFCONF:
-		return (ifconf(cmd, data));
+	case OOSIOCGIFCONF:
+		return compat_ifconf(cmd, data);
+#endif
+	case SIOCGIFCONF:
+		return ifconf(cmd, data);
 	}
-	ifr = (struct ifreq *)data;
-	ifcr = (struct ifcapreq *)data;
-	ifdr = (struct ifdatareq *)data;
+
+#ifdef COMPAT_OIFREQ
+	cmd = compat_cvtcmd(cmd);
+	if (cmd != ocmd) {
+		oifr = data;
+		data = ifr = &ifrb;
+		ifreqo2n(oifr, ifr);
+	} else
+#endif
+		ifr = data;
+	ifcr = data;
+	ifdr = data;
 
 	ifp = ifunit(ifr->ifr_name);
 
 	switch (cmd) {
 	case SIOCIFCREATE:
 	case SIOCIFDESTROY:
-		if (l) {
+		if (l != NULL) {
 			error = kauth_authorize_network(l->l_cred,
 			    KAUTH_NETWORK_INTERFACE,
 			    KAUTH_REQ_NETWORK_INTERFACE_SETPRIV, ifp,
 			    (void *)cmd, NULL);
-			if (error)
+			if (error != 0)
 				return error;
 		}
-		return ((cmd == SIOCIFCREATE) ?
+		return (cmd == SIOCIFCREATE) ?
 			if_clone_create(ifr->ifr_name) :
-			if_clone_destroy(ifr->ifr_name));
+			if_clone_destroy(ifr->ifr_name);
 
 	case SIOCIFGCLONERS:
-		return (if_clone_list((struct if_clonereq *)data));
+		return if_clone_list((struct if_clonereq *)data);
 	}
 
-	if (ifp == 0)
-		return (ENXIO);
+	if (ifp == NULL)
+		return ENXIO;
 
 	switch (cmd) {
 	case SIOCSIFFLAGS:
@@ -1382,17 +1383,19 @@
 	case SIOCDELMULTI:
 	case SIOCSIFMEDIA:
 	case SIOCSDRVSPEC:
+	case SIOCG80211:
+	case SIOCS80211:
 	case SIOCS80211NWID:
 	case SIOCS80211NWKEY:
 	case SIOCS80211POWER:
 	case SIOCS80211BSSID:
 	case SIOCS80211CHANNEL:
-		if (l) {
+		if (l != NULL) {
 			error = kauth_authorize_network(l->l_cred,
 			    KAUTH_NETWORK_INTERFACE,
 			    KAUTH_REQ_NETWORK_INTERFACE_SETPRIV, ifp,
 			    (void *)cmd, NULL);
-			if (error)
+			if (error != 0)
 				return error;
 		}
 	}
@@ -1430,7 +1433,7 @@
 		ifp->if_flags = (ifp->if_flags & IFF_CANTCHANGE) |
 			(ifr->ifr_flags &~ IFF_CANTCHANGE);
 		if (ifp->if_ioctl)
-			(void) (*ifp->if_ioctl)(ifp, cmd, data);
+			(void)(*ifp->if_ioctl)(ifp, cmd, data);
 		break;
 
 	case SIOCGIFCAP:
@@ -1440,9 +1443,9 @@
 
 	case SIOCSIFCAP:
 		if ((ifcr->ifcr_capenable & ~ifp->if_capabilities) != 0)
-			return (EINVAL);
+			return EINVAL;
 		if (ifp->if_ioctl == NULL)
-			return (EOPNOTSUPP);
+			return EOPNOTSUPP;
 
 		/* Must prevent race with packet reception here. */
 		s = splnet();
@@ -1496,8 +1499,8 @@
 			 * when it is brought up later.
 			 */
 			if (ifp->if_flags & IFF_UP)
-				(void) (*ifp->if_ioctl)(ifp, SIOCSIFFLAGS,
-				    (caddr_t) &ifrq);
+				(void)(*ifp->if_ioctl)(ifp, SIOCSIFFLAGS,
+				    (void *)&ifrq);
 		}
 		splx(s);
 		break;
@@ -1525,7 +1528,7 @@
 		u_long oldmtu = ifp->if_mtu;
 
 		if (ifp->if_ioctl == NULL)
-			return (EOPNOTSUPP);
+			return EOPNOTSUPP;
 		error = (*ifp->if_ioctl)(ifp, cmd, data);
 
 		/*
@@ -1551,22 +1554,24 @@
 	case SIOCGIFPDSTADDR:
 	case SIOCGLIFPHYADDR:
 	case SIOCGIFMEDIA:
-		if (ifp->if_ioctl == 0)
-			return (EOPNOTSUPP);
-		error = (*ifp->if_ioctl)(ifp, cmd, data);
-		break;
-
-	case SIOCSDRVSPEC:
+	case SIOCG80211:
+	case SIOCS80211:
 	case SIOCS80211NWID:
 	case SIOCS80211NWKEY:
 	case SIOCS80211POWER:
 	case SIOCS80211BSSID:
 	case SIOCS80211CHANNEL:
+		if (ifp->if_ioctl == NULL)
+			return EOPNOTSUPP;
+		error = (*ifp->if_ioctl)(ifp, cmd, data);
+		break;
+
+	case SIOCSDRVSPEC:
 	default:
-		if (so->so_proto == 0)
-			return (EOPNOTSUPP);
+		if (so->so_proto == NULL)
+			return EOPNOTSUPP;
 #ifdef COMPAT_OSOCK
-		error = compat_ifioctl(so, cmd, data, l);
+		error = compat_ifioctl(so, ocmd, cmd, data, l);
 #else
 		error = ((*so->so_proto->pr_usrreq)(so, PRU_CONTROL,
 		    (struct mbuf *)cmd, (struct mbuf *)data,
@@ -1584,8 +1589,12 @@
 		}
 #endif
 	}
+#ifdef COMPAT_OIFREQ
+	if (cmd != ocmd)
+		ifreqn2o(oifr, ifr);
+#endif
 
-	return (error);
+	return error;
 }
 
 /*
@@ -1596,22 +1605,20 @@
  */
 /*ARGSUSED*/
 int
-ifconf(u_long cmd, caddr_t data)
+ifconf(u_long cmd, void *data)
 {
 	struct ifconf *ifc = (struct ifconf *)data;
 	struct ifnet *ifp;
 	struct ifaddr *ifa;
 	struct ifreq ifr, *ifrp;
-	int space = ifc->ifc_len, error = 0;
-	const int sz = (int)sizeof(ifr);
-	int sign;
+	int space, error = 0;
+	const int sz = offsetof(struct ifreq, ifr_ifru) +
+	    sizeof(struct sockaddr);
 
-	if ((ifrp = ifc->ifc_req) == NULL) {
+	if ((ifrp = ifc->ifc_req) == NULL)
 		space = 0;
-		sign = -1;
-	} else {
-		sign = 1;
-	}
+	else
+		space = ifc->ifc_len;
 	IFNET_FOREACH(ifp) {
 		(void)strncpy(ifr.ifr_name, ifp->if_xname,
 		    sizeof(ifr.ifr_name));
@@ -1619,66 +1626,69 @@
 			return ENAMETOOLONG;
 		if (TAILQ_EMPTY(&ifp->if_addrlist)) {
 			memset(&ifr.ifr_addr, 0, sizeof(ifr.ifr_addr));
-			if (ifrp != NULL && space >= sz) {
+			if (space >= sz) {
 				error = copyout(&ifr, ifrp, sz);
-				if (error)
-					break;
+				if (error != 0)
+					return (error);
 				ifrp++;
 			}
-			space -= sizeof(ifr) * sign;
+			space -= sizeof(struct ifreq);
 			continue;
 		}
 
 		TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_list) {
 			struct sockaddr *sa = ifa->ifa_addr;
-#ifdef COMPAT_OSOCK
-			if (cmd == OSIOCGIFCONF) {
-				struct osockaddr *osa =
-					 (struct osockaddr *)&ifr.ifr_addr;
-				/*
-				 * If it does not fit, we don't bother with it
-				 */
-				if (sa->sa_len > sizeof(*osa))
-					continue;
+			if (sa->sa_len <= sizeof(*sa)) {
 				ifr.ifr_addr = *sa;
-				osa->sa_family = sa->sa_family;
-				if (ifrp != NULL && space >= sz) {
+				if (space >= sz) {
 					error = copyout(&ifr, ifrp, sz);
 					ifrp++;
 				}
-			} else
-#endif
-			if (sa->sa_len <= sizeof(*sa)) {
-				ifr.ifr_addr = *sa;
-				if (ifrp != NULL && space >= sz) {
-					error = copyout(&ifr, ifrp, sz);
-					ifrp++;
-				}
+				space -= sizeof(struct ifreq);
 			} else {
-				space -= (sa->sa_len - sizeof(*sa)) * sign;
-				if (ifrp != NULL && space >= sz) {
-					error = copyout(&ifr, ifrp,
-					    sizeof(ifr.ifr_name));
-					if (error == 0) {
-						error = copyout(sa,
-						    &ifrp->ifr_addr,
-						    sa->sa_len);
-					}
-					ifrp = (struct ifreq *)
-						(sa->sa_len +
-						 (caddr_t)&ifrp->ifr_addr);
-				}
+				space -= sa->sa_len - sizeof(*sa) + sz;
+				if (space < 0)
+					continue;
+				error = copyout(&ifr, ifrp,
+				    sizeof(ifr.ifr_name));
+				if (error == 0)
+					error = copyout(sa,
+					    &ifrp->ifr_addr, sa->sa_len);
+				ifrp = (struct ifreq *)
+				    (sa->sa_len + (char *)&ifrp->ifr_addr);
 			}
-			if (error)
-				break;
-			space -= sz * sign;
+			if (error != 0)
+				return (error);
 		}
 	}
 	if (ifrp != NULL)
 		ifc->ifc_len -= space;
 	else
-		ifc->ifc_len = space;
-	return (error);
+		ifc->ifc_len = -space;
+	return (0);
+}
+
+int
+ifreq_setaddr(const u_long cmd, struct ifreq *ifr, const struct sockaddr *sa)
+{
+	uint8_t len;
+	u_long ncmd;
+	const uint8_t osockspace = sizeof(ifr->ifr_addr);
+	const uint8_t sockspace = sizeof(ifr->ifr_ifru.ifru_space);
+
+#ifdef INET6
+	if (cmd == SIOCGIFPSRCADDR_IN6 || cmd == SIOCGIFPDSTADDR_IN6)
+		len = MIN(sizeof(struct sockaddr_in6), sa->sa_len);
+	else
+#endif /* INET6 */
+	if ((ncmd = compat_cvtcmd(cmd)) != cmd)
+		len = MIN(sockspace, sa->sa_len);
+	else
+		len = MIN(osockspace, sa->sa_len);
+	sockaddr_copy(&ifr->ifr_addr, len, sa);
+	if (len < sa->sa_len)
+		return EFBIG;
+	return 0;
 }
 
 /*
@@ -1695,15 +1705,14 @@
 	int error;
 
 	IFQ_ENQUEUE(&ifp->if_snd, m, pktattr, error);
-	if (error) {
-		splx(s);
-		return error;
-	}
+	if (error != 0)
+		goto out;
 	ifp->if_obytes += len;
 	if (mflags & M_MCAST)
 		ifp->if_omcasts++;
 	if ((ifp->if_flags & IFF_OACTIVE) == 0)
 		(*ifp->if_start)(ifp);
+out:
 	splx(s);
 	return error;
 }
@@ -1727,8 +1736,7 @@
 			m_freem(m);
 			if (error == 0)
 				error = ENOBUFS;
-		}
-		else
+		} else
 			IF_ENQUEUE(ifq, m);
 	} else
 		IFQ_ENQUEUE(&ifp->if_snd, m, pktattr, error);
@@ -1736,7 +1744,6 @@
 		++ifp->if_oerrors;
 		return error;
 	}
-
 	return 0;
 }
 
--- a/sys/net/if.h	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/if.h	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.h,v 1.110.2.3 2007/02/26 09:11:33 yamt Exp $	*/
+/*	$NetBSD: if.h,v 1.110.2.4 2007/09/03 14:42:01 yamt Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc.
@@ -244,7 +244,7 @@
 	TAILQ_HEAD(, ifaddr) if_addrlist; /* linked list of addresses per if */
 	char	if_xname[IFNAMSIZ];	/* external name (name + unit) */
 	int	if_pcount;		/* number of promiscuous listeners */
-	caddr_t	if_bpf;			/* packet filter structure */
+	void *	if_bpf;			/* packet filter structure */
 	u_short	if_index;		/* numeric abbreviation for this if */
 	short	if_timer;		/* time 'til if_watchdog called */
 	short	if_flags;		/* up/down, broadcast, etc. */
@@ -262,7 +262,7 @@
 	void	(*if_start)		/* initiate output routine */
 		    (struct ifnet *);
 	int	(*if_ioctl)		/* ioctl routine */
-		    (struct ifnet *, u_long, caddr_t);
+		    (struct ifnet *, u_long, void *);
 	int	(*if_init)		/* init routine */
 		    (struct ifnet *);
 	void	(*if_stop)		/* stop routine */
@@ -280,7 +280,7 @@
 	uint64_t if_capabilities;	/* interface capabilities */
 	uint64_t if_capenable;		/* capabilities enabled */
 	union {
-		caddr_t		carp_s;	/* carp structure (used by !carp ifs) */
+		void *		carp_s;	/* carp structure (used by !carp ifs) */
 		struct ifnet	*carp_d;/* ptr to carpdev (used by carp ifs) */
 	} if_carp_ptr;
 #define if_carp		if_carp_ptr.carp_s
@@ -537,12 +537,13 @@
 		struct	sockaddr ifru_addr;
 		struct	sockaddr ifru_dstaddr;
 		struct	sockaddr ifru_broadaddr;
+		struct	sockaddr_storage ifru_space;
 		short	ifru_flags;
 		int	ifru_metric;
 		int	ifru_mtu;
 		int	ifru_dlt;
 		u_int	ifru_value;
-		caddr_t	ifru_data;
+		void *	ifru_data;
 		struct {
 			uint32_t	b_buflen;
 			void		*b_buf;
@@ -564,6 +565,19 @@
 #define	ifr_buflen	ifr_ifru.ifru_b.b_buflen
 };
 
+#ifdef _KERNEL
+#define	ifreq_setdstaddr	ifreq_setaddr
+#define	ifreq_setbroadaddr	ifreq_setaddr
+#define	ifreq_getdstaddr	ifreq_getaddr
+#define	ifreq_getbroadaddr	ifreq_getaddr
+
+static inline const struct sockaddr *
+ifreq_getaddr(u_long cmd, const struct ifreq *ifr)
+{
+	return &ifr->ifr_addr;
+}
+#endif /* _KERNEL */
+
 struct ifcapreq {
 	char		ifcr_name[IFNAMSIZ];	/* if name, e.g. "en0" */
 	uint64_t	ifcr_capabilities;	/* supported capabiliites */
@@ -611,7 +625,7 @@
 struct	ifconf {
 	int	ifc_len;		/* size of associated buffer */
 	union {
-		caddr_t	ifcu_buf;
+		void *	ifcu_buf;
 		struct	ifreq *ifcu_req;
 	} ifc_ifcu;
 #define	ifc_buf	ifc_ifcu.ifcu_buf	/* buffer address */
@@ -743,7 +757,7 @@
 			(pattr)->pattr_class = (*(ifq)->altq_classify)	\
 				((ifq)->altq_clfier, (m), (af));	\
 		(pattr)->pattr_af = (af);				\
-		(pattr)->pattr_hdr = mtod((m), caddr_t);		\
+		(pattr)->pattr_hdr = mtod((m), void *);		\
 	}								\
 } while (/*CONSTCOND*/ 0)
 #else /* ! ALTQ */
@@ -796,6 +810,8 @@
 
 void    ether_input(struct ifnet *, struct mbuf *);
 
+int ifreq_setaddr(u_long, struct ifreq *, const struct sockaddr *);
+
 void	if_alloc_sadl(struct ifnet *);
 void	if_free_sadl(struct ifnet *);
 void	if_attach(struct ifnet *);
@@ -807,9 +823,9 @@
 void	if_link_state_change(struct ifnet *, int);
 void	if_slowtimo(void *);
 void	if_up(struct ifnet *);
-int	ifconf(u_long, caddr_t);
+int	ifconf(u_long, void *);
 void	ifinit(void);
-int	ifioctl(struct socket *, u_long, caddr_t, struct lwp *);
+int	ifioctl(struct socket *, u_long, void *, struct lwp *);
 int	ifpromisc(struct ifnet *, int);
 struct	ifnet *ifunit(const char *);
 
@@ -835,7 +851,7 @@
 int	ifq_enqueue2(struct ifnet *, struct ifqueue *, struct mbuf * ALTQ_COMMA
     ALTQ_DECL(struct altq_pktattr *));
 
-int	loioctl(struct ifnet *, u_long, caddr_t);
+int	loioctl(struct ifnet *, u_long, void *);
 void	loopattach(int);
 int	looutput(struct ifnet *,
 	   struct mbuf *, const struct sockaddr *, struct rtentry *);
@@ -849,7 +865,7 @@
 	    const struct sockaddr *, struct rtentry *);
 void	if_nullinput(struct ifnet *, struct mbuf *);
 void	if_nullstart(struct ifnet *);
-int	if_nullioctl(struct ifnet *, u_long, caddr_t);
+int	if_nullioctl(struct ifnet *, u_long, void *);
 int	if_nullinit(struct ifnet *);
 void	if_nullstop(struct ifnet *, int);
 void	if_nullwatchdog(struct ifnet *);
--- a/sys/net/if_arcsubr.c	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/if_arcsubr.c	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_arcsubr.c,v 1.49.2.2 2007/02/26 09:11:33 yamt Exp $	*/
+/*	$NetBSD: if_arcsubr.c,v 1.49.2.3 2007/09/03 14:42:02 yamt Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Ignatios Souvatzis
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_arcsubr.c,v 1.49.2.2 2007/02/26 09:11:33 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_arcsubr.c,v 1.49.2.3 2007/09/03 14:42:02 yamt Exp $");
 
 #include "opt_inet.h"
 
@@ -135,7 +135,7 @@
 	m = m0;
 	mcopy = m1 = NULL;
 
-	myself = *LLADDR(ifp->if_sadl);
+	myself = *CLLADDR(ifp->if_sadl);
 
 	if ((rt = rt0)) {
 		if ((rt->rt_flags & RTF_UP) == 0) {
@@ -622,8 +622,8 @@
 void
 arc_storelladdr(struct ifnet *ifp, uint8_t lla)
 {
-
-	*(LLADDR(ifp->if_sadl)) = lla;
+	(void)sockaddr_dl_setaddr(ifp->if_sadl, ifp->if_sadl->sdl_len, &lla,
+	    sizeof(lla));
 	ifp->if_mtu = ARC_PHDS_MAXMTU;
 }
 
--- a/sys/net/if_arp.h	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/if_arp.h	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_arp.h,v 1.24.16.1 2006/06/21 15:10:27 yamt Exp $	*/
+/*	$NetBSD: if_arp.h,v 1.24.16.2 2007/09/03 14:42:02 yamt Exp $	*/
 
 /*
  * Copyright (c) 1986, 1993
@@ -71,15 +71,15 @@
 	u_int8_t  ar_tha[];	/* target hardware address */
 	u_int8_t  ar_tpa[];	/* target protocol address */
 #endif
-#define ar_sha(ap) (((caddr_t)((ap)+1))+0)
-#define ar_spa(ap) (((caddr_t)((ap)+1))+(ap)->ar_hln)
+#define ar_sha(ap) (((char *)((ap)+1))+0)
+#define ar_spa(ap) (((char *)((ap)+1))+(ap)->ar_hln)
 #define ar_tha(ap) \
 	(ntohs((ap)->ar_hrd) == ARPHRD_IEEE1394 \
-		? NULL : (((caddr_t)((ap)+1))+(ap)->ar_hln+(ap)->ar_pln))
+		? NULL : (((char *)((ap)+1))+(ap)->ar_hln+(ap)->ar_pln))
 #define ar_tpa(ap) \
 	(ntohs((ap)->ar_hrd) == ARPHRD_IEEE1394 \
-		? (((caddr_t)((ap)+1))+(ap)->ar_hln+(ap)->ar_pln) \
-		: (((caddr_t)((ap)+1))+(ap)->ar_hln+(ap)->ar_pln+(ap)->ar_hln))
+		? (((char *)((ap)+1))+(ap)->ar_hln+(ap)->ar_pln) \
+		: (((char *)((ap)+1))+(ap)->ar_hln+(ap)->ar_pln+(ap)->ar_hln))
 } __attribute__((__packed__));
 
 
--- a/sys/net/if_atmsubr.c	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/if_atmsubr.c	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: if_atmsubr.c,v 1.35.2.2 2007/02/26 09:11:33 yamt Exp $       */
+/*      $NetBSD: if_atmsubr.c,v 1.35.2.3 2007/09/03 14:42:03 yamt Exp $       */
 
 /*
  *
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_atmsubr.c,v 1.35.2.2 2007/02/26 09:11:33 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_atmsubr.c,v 1.35.2.3 2007/09/03 14:42:03 yamt Exp $");
 
 #include "opt_inet.h"
 #include "opt_gateway.h"
@@ -297,6 +297,10 @@
 #endif /* INET */
 #ifdef INET6
 	  case ETHERTYPE_IPV6:
+#ifdef GATEWAY  
+		if (ip6flow_fastforward(m))
+			return;
+#endif
 		  schednetisr(NETISR_IPV6);
 		  inq = &ip6intrq;
 		  break;
--- a/sys/net/if_bridge.c	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/if_bridge.c	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_bridge.c,v 1.31.2.3 2007/02/26 09:11:33 yamt Exp $	*/
+/*	$NetBSD: if_bridge.c,v 1.31.2.4 2007/09/03 14:42:03 yamt Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -80,7 +80,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.31.2.3 2007/02/26 09:11:33 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.31.2.4 2007/09/03 14:42:03 yamt Exp $");
 
 #include "opt_bridge_ipf.h"
 #include "opt_inet.h"
@@ -178,7 +178,7 @@
 static int	bridge_clone_create(struct if_clone *, int);
 static int	bridge_clone_destroy(struct ifnet *);
 
-static int	bridge_ioctl(struct ifnet *, u_long, caddr_t);
+static int	bridge_ioctl(struct ifnet *, u_long, void *);
 static int	bridge_init(struct ifnet *);
 static void	bridge_stop(struct ifnet *, int);
 static void	bridge_start(struct ifnet *);
@@ -343,7 +343,7 @@
 {
 
 	pool_init(&bridge_rtnode_pool, sizeof(struct bridge_rtnode),
-	    0, 0, 0, "brtpl", NULL);
+	    0, 0, 0, "brtpl", NULL, IPL_NET);
 
 	LIST_INIT(&bridge_list);
 	if_clone_attach(&bridge_cloner);
@@ -377,8 +377,8 @@
 	/* Initialize our routing table. */
 	bridge_rtable_init(sc);
 
-	callout_init(&sc->sc_brcallout);
-	callout_init(&sc->sc_bstpcallout);
+	callout_init(&sc->sc_brcallout, 0);
+	callout_init(&sc->sc_bstpcallout, 0);
 
 	LIST_INIT(&sc->sc_iflist);
 
@@ -446,7 +446,7 @@
  *	Handle a control request from the operator.
  */
 static int
-bridge_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
+bridge_ioctl(struct ifnet *ifp, u_long cmd, void *data)
 {
 	struct bridge_softc *sc = ifp->if_softc;
 	struct lwp *l = curlwp;	/* XXX */
@@ -1514,7 +1514,7 @@
 	 */
 	LIST_FOREACH(bif, &sc->sc_iflist, bif_next) {
 		/* It is destined for us. */
-		if (memcmp(LLADDR(bif->bif_ifp->if_sadl), eh->ether_dhost,
+		if (memcmp(CLLADDR(bif->bif_ifp->if_sadl), eh->ether_dhost,
 		    ETHER_ADDR_LEN) == 0
 #if NCARP > 0
 		    || (bif->bif_ifp->if_carp && carp_ourether(bif->bif_ifp->if_carp,
@@ -1529,7 +1529,7 @@
 		}
 
 		/* We just received a packet that we sent out. */
-		if (memcmp(LLADDR(bif->bif_ifp->if_sadl), eh->ether_shost,
+		if (memcmp(CLLADDR(bif->bif_ifp->if_sadl), eh->ether_shost,
 		    ETHER_ADDR_LEN) == 0
 #if NCARP > 0
 		    || (bif->bif_ifp->if_carp && carp_ourether(bif->bif_ifp->if_carp,
@@ -2016,12 +2016,12 @@
 	}
 
 	/* Strip off the Ethernet header and keep a copy. */
-	m_copydata(*mp, 0, ETHER_HDR_LEN, (caddr_t) &eh2);
+	m_copydata(*mp, 0, ETHER_HDR_LEN, (void *) &eh2);
 	m_adj(*mp, ETHER_HDR_LEN);
 
 	/* Strip off snap header, if present */
 	if (snap) {
-		m_copydata(*mp, 0, sizeof(struct llc), (caddr_t) &llc1);
+		m_copydata(*mp, 0, sizeof(struct llc), (void *) &llc1);
 		m_adj(*mp, sizeof(struct llc));
 	}
 
@@ -2061,13 +2061,13 @@
 		M_PREPEND(*mp, sizeof(struct llc), M_DONTWAIT);
 		if (*mp == NULL)
 			return error;
-		bcopy(&llc1, mtod(*mp, caddr_t), sizeof(struct llc));
+		bcopy(&llc1, mtod(*mp, void *), sizeof(struct llc));
 	}
 
 	M_PREPEND(*mp, ETHER_HDR_LEN, M_DONTWAIT);
 	if (*mp == NULL)
 		return error;
-	bcopy(&eh2, mtod(*mp, caddr_t), ETHER_HDR_LEN);
+	bcopy(&eh2, mtod(*mp, void *), ETHER_HDR_LEN);
 
 	return 0;
 
@@ -2099,7 +2099,7 @@
 	if (*mp == NULL)
 		return -1;
 
-	if (IP_HDR_ALIGNED_P(mtod(m, caddr_t)) == 0) {
+	if (IP_HDR_ALIGNED_P(mtod(m, void *)) == 0) {
 		if ((m = m_copyup(m, sizeof(struct ip),
 			(max_linkhdr + 3) & ~3)) == NULL) {
 			/* XXXJRT new stat, please */
@@ -2201,7 +2201,7 @@
          * it.  Otherwise, if it is aligned, make sure the entire base
          * IPv6 header is in the first mbuf of the chain.
          */
-        if (IP6_HDR_ALIGNED_P(mtod(m, caddr_t)) == 0) {
+        if (IP6_HDR_ALIGNED_P(mtod(m, void *)) == 0) {
                 struct ifnet *inifp = m->m_pkthdr.rcvif;
                 if ((m = m_copyup(m, sizeof(struct ip6_hdr),
                                   (max_linkhdr + 3) & ~3)) == NULL) {
--- a/sys/net/if_bridgevar.h	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/if_bridgevar.h	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_bridgevar.h,v 1.7.2.2 2007/02/26 09:11:33 yamt Exp $	*/
+/*	$NetBSD: if_bridgevar.h,v 1.7.2.3 2007/09/03 14:42:03 yamt Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -149,7 +149,7 @@
 struct ifbifconf {
 	uint32_t	ifbic_len;	/* buffer size */
 	union {
-		caddr_t	ifbicu_buf;
+		void *	ifbicu_buf;
 		struct ifbreq *ifbicu_req;
 	} ifbic_ifbicu;
 #define	ifbic_buf	ifbic_ifbicu.ifbicu_buf
@@ -178,7 +178,7 @@
 struct ifbaconf {
 	uint32_t	ifbac_len;	/* buffer size */
 	union {
-		caddr_t ifbacu_buf;
+		void *ifbacu_buf;
 		struct ifbareq *ifbacu_req;
 	} ifbac_ifbacu;
 #define	ifbac_buf	ifbac_ifbacu.ifbacu_buf
@@ -293,8 +293,8 @@
 	uint32_t		sc_brtmax;	/* max # of addresses */
 	uint32_t		sc_brtcnt;	/* cur. # of addresses */
 	uint32_t		sc_brttimeout;	/* rt timeout in seconds */
-	struct callout		sc_brcallout;	/* bridge callout */
-	struct callout		sc_bstpcallout;	/* STP callout */
+	callout_t		sc_brcallout;	/* bridge callout */
+	callout_t		sc_bstpcallout;	/* STP callout */
 	LIST_HEAD(, bridge_iflist) sc_iflist;	/* member interface list */
 	LIST_HEAD(, bridge_rtnode) *sc_rthash;	/* our forwarding table */
 	LIST_HEAD(, bridge_rtnode) sc_rtlist;	/* list version of above */
--- a/sys/net/if_dl.h	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/if_dl.h	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_dl.h,v 1.16.2.1 2006/06/21 15:10:27 yamt Exp $	*/
+/*	$NetBSD: if_dl.h,v 1.16.2.2 2007/09/03 14:42:03 yamt Exp $	*/
 
 /*
  * Copyright (c) 1990, 1993
@@ -70,15 +70,28 @@
 	u_char	    sdl_nlen;	/* interface name length, no trailing 0 reqd. */
 	u_char	    sdl_alen;	/* link level address length */
 	u_char	    sdl_slen;	/* link layer selector length */
-	char	    sdl_data[12]; /* minimum work area, can be larger;
-				     contains both if name and ll address */
+	/* minimum work area, can be larger; contains both if name
+	 * and ll address
+	 */
+	char	    sdl_data[12];
 };
 
+#define	satosdl(__sa)	((struct sockaddr_dl *)(__sa))
+#define	satocsdl(__sa)	((const struct sockaddr_dl *)(__sa))
+
 /* We do arithmetic directly with these, so keep them char instead of void */
 #define LLADDR(s) ((char *)((s)->sdl_data + (s)->sdl_nlen))
 #define CLLADDR(s) ((const char *)((s)->sdl_data + (s)->sdl_nlen))
 
-#ifndef _KERNEL
+#ifdef _KERNEL
+uint8_t sockaddr_dl_measure(uint8_t, uint8_t);
+struct sockaddr *sockaddr_dl_alloc(uint16_t, uint8_t,
+    const void *, uint8_t, const void *, uint8_t, int);
+struct sockaddr_dl *sockaddr_dl_init(struct sockaddr_dl *, socklen_t, uint16_t,
+    uint8_t, const void *, uint8_t, const void *, uint8_t);
+struct sockaddr_dl *sockaddr_dl_setaddr(struct sockaddr_dl *, socklen_t,
+    const void *, uint8_t);
+#else
 
 #include <sys/cdefs.h>
 
--- a/sys/net/if_ecosubr.c	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/if_ecosubr.c	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ecosubr.c,v 1.16.2.1 2006/06/21 15:10:27 yamt Exp $	*/
+/*	$NetBSD: if_ecosubr.c,v 1.16.2.2 2007/09/03 14:42:03 yamt Exp $	*/
 
 /*-
  * Copyright (c) 2001 Ben Harris
@@ -58,7 +58,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_ecosubr.c,v 1.16.2.1 2006/06/21 15:10:27 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ecosubr.c,v 1.16.2.2 2007/09/03 14:42:03 yamt Exp $");
 
 #include "bpfilter.h"
 #include "opt_inet.h"
@@ -102,7 +102,7 @@
     struct rtentry *);
 static void eco_input(struct ifnet *, struct mbuf *);
 static void eco_start(struct ifnet *);
-static int eco_ioctl(struct ifnet *, u_long, caddr_t);
+static int eco_ioctl(struct ifnet *, u_long, void *);
 
 static int eco_interestingp(struct ifnet *ifp, struct mbuf *m);
 static struct mbuf *eco_immediate(struct ifnet *ifp, struct mbuf *m);
@@ -130,7 +130,8 @@
 
 /*	ifp->if_baudrate...; */
 	if_alloc_sadl(ifp);
-	memcpy(LLADDR(ifp->if_sadl), lla, ifp->if_addrlen);
+	(void)sockaddr_dl_setaddr(ifp->if_sadl, ifp->if_sadl->sdl_len, lla,
+	    ifp->if_addrlen);
 
 	ifp->if_broadcastaddr = eco_broadcastaddr;
 
@@ -306,7 +307,7 @@
 	eh = mtod(m, struct eco_header *);
 	*eh = ehdr;
 	if (!hdrcmplt)
-		memcpy(eh->eco_shost, LLADDR(ifp->if_sadl),
+		memcpy(eh->eco_shost, CLLADDR(ifp->if_sadl),
 		    ECO_ADDR_LEN);
 
 	if ((m->m_flags & M_BCAST) == 0) {
@@ -375,7 +376,7 @@
 	/* Copy the mbuf header and trim it off. */
 	/* XXX use m_split? */
 	eh = &ehdr;
-	m_copydata(m, 0, ECO_HDR_LEN, (caddr_t)eh);
+	m_copydata(m, 0, ECO_HDR_LEN, (void *)eh);
 	m_adj(m, ECO_HDR_LEN);
 
 	switch (eh->eco_port) {
@@ -413,7 +414,7 @@
 			m1->m_pkthdr.len = m1->m_len;
 			MH_ALIGN(m1, m1->m_len);
 			ah = mtod(m1, struct arphdr *);
-			bzero((caddr_t)ah, m1->m_len);
+			bzero((void *)ah, m1->m_len);
 			ah->ar_pro = htons(ETHERTYPE_IP);
 			ah->ar_hln = ifp->if_data.ifi_addrlen;
 			ah->ar_pln = sizeof(struct in_addr);
@@ -517,7 +518,7 @@
 }
 
 static int
-eco_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
+eco_ioctl(struct ifnet *ifp, u_long cmd, void *data)
 {
 	struct ifreq *ifr = (struct ifreq *)data;
 	struct ifaddr *ifa = (struct ifaddr *)data;
@@ -604,7 +605,7 @@
 		    ECO_ADDR_LEN) == 0) {
 			/* Broadcast */
 			eco_input(ifp, m);
-		} else if (memcmp(eh->eco_dhost, LLADDR(ifp->if_sadl),
+		} else if (memcmp(eh->eco_dhost, CLLADDR(ifp->if_sadl),
 		    ECO_ADDR_LEN) == 0) {
 			/* Unicast for us */
 			if (eh->eco_port == ECO_PORT_IMMEDIATE)
@@ -730,9 +731,9 @@
 		reh = mtod(n, struct eco_header *);
 		memcpy(reh->eco_dhost, eh->eco_shost,
 		    ECO_ADDR_LEN);
-		memcpy(reh->eco_shost, LLADDR(ifp->if_sadl),
+		memcpy(reh->eco_shost, CLLADDR(ifp->if_sadl),
 		    ECO_ADDR_LEN);
-		memcpy(mtod(n, caddr_t) + ECO_SHDR_LEN, machinepeek_data,
+		memcpy(mtod(n, void *) + ECO_SHDR_LEN, machinepeek_data,
 		    sizeof(machinepeek_data));
 		m_freem(m);
 		return n;
@@ -760,7 +761,7 @@
 	n->m_len = n->m_pkthdr.len = ECO_SHDR_LEN;
 	reh = mtod(n, struct eco_header *);
 	memcpy(reh->eco_dhost, eh->eco_shost, ECO_ADDR_LEN);
-	memcpy(reh->eco_shost, LLADDR(ifp->if_sadl), ECO_ADDR_LEN);
+	memcpy(reh->eco_shost, CLLADDR(ifp->if_sadl), ECO_ADDR_LEN);
 	return n;
 }
 
@@ -831,7 +832,7 @@
 		m_freem(m);
 		return;
 	}
-	callout_init(&er->er_callout);
+	callout_init(&er->er_callout, 0);
 	er->er_packet = m;
 	er->er_ifp = ifp;
 	s = splnet();
@@ -850,6 +851,7 @@
 	s = splnet();
 	LIST_REMOVE(er, er_link);
 	splx(s);
+	callout_destroy(&er->er_callout);
 	FREE(er, M_TEMP);
 }
 
--- a/sys/net/if_ether.h	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/if_ether.h	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ether.h,v 1.39.2.3 2007/02/26 09:11:33 yamt Exp $	*/
+/*	$NetBSD: if_ether.h,v 1.39.2.4 2007/09/03 14:42:04 yamt Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1993
@@ -173,7 +173,7 @@
 extern const uint8_t ether_ipmulticast_min[ETHER_ADDR_LEN];
 extern const uint8_t ether_ipmulticast_max[ETHER_ADDR_LEN];
 
-int	ether_ioctl(struct ifnet *, u_long, caddr_t);
+int	ether_ioctl(struct ifnet *, u_long, void *);
 int	ether_addmulti (struct ifreq *, struct ethercom *);
 int	ether_delmulti (struct ifreq *, struct ethercom *);
 int	ether_changeaddr (struct ifreq *, struct ethercom *);
--- a/sys/net/if_etherip.c	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/if_etherip.c	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: if_etherip.c,v 1.4.2.2 2006/12/30 20:50:20 yamt Exp $        */
+/*      $NetBSD: if_etherip.c,v 1.4.2.3 2007/09/03 14:42:04 yamt Exp $        */
 
 /*
  *  Copyright (c) 2006, Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org>
@@ -140,6 +140,8 @@
 #include <netinet6/ip6protosw.h>
 #endif /* INET6 */
 
+#include <compat/sys/sockio.h>
+
 static int etherip_node;
 static int etherip_sysctl_handler(SYSCTLFN_PROTO);
 SYSCTL_SETUP_PROTO(sysctl_etherip_setup);
@@ -157,7 +159,7 @@
 static void etherip_start(struct ifnet *);
 static void etherip_stop(struct ifnet *, int);
 static int  etherip_init(struct ifnet *);
-static int  etherip_ioctl(struct ifnet *, u_long, caddr_t);
+static int  etherip_ioctl(struct ifnet *, u_long, void *);
 
 static int  etherip_mediachange(struct ifnet *);
 static void etherip_mediastatus(struct ifnet *, struct ifmediareq *);
@@ -211,9 +213,7 @@
 	uint32_t ui;
 	int error;
 
-#ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
 	sc->sc_si  = NULL;
-#endif
 	sc->sc_src = NULL;
 	sc->sc_dst = NULL;
 
@@ -321,6 +321,7 @@
 	etherip_delete_tunnel(ifp);
 	ether_ifdetach(ifp);
 	if_detach(ifp);
+	rtcache_free(&sc->sc_ro);
 	ifmedia_delete_instance(&sc->sc_im, IFM_INST_ANY);
 
 	return 0;
@@ -353,12 +354,8 @@
 {
 	struct etherip_softc *sc = (struct etherip_softc *)ifp->if_softc;
 
-#ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
 	if(sc->sc_si)
 		softintr_schedule(sc->sc_si);
-#else
-	etheripintr(sc);
-#endif
 }
 
 static void
@@ -404,10 +401,10 @@
 }
 
 static int
-etherip_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
+etherip_ioctl(struct ifnet *ifp, u_long cmd, void *data)
 {
 	struct etherip_softc *sc = (struct etherip_softc *)ifp->if_softc;
-	struct ifreq *ifr = (struct ifreq *)data;
+	struct ifreq *ifr = data;
 	struct sockaddr *src, *dst;
 	int s, error;
 
@@ -473,6 +470,9 @@
 		error = 0;
 		break;
 
+#ifdef OSIOCSIFMEDIA
+	case OSIOCSIFMEDIA:
+#endif
 	case SIOCSIFMEDIA:
 	case SIOCGIFMEDIA:
 		s = splnet();
@@ -523,12 +523,10 @@
 		/* XXX both end must be valid? (I mean, not 0.0.0.0) */
 	}
 
-#ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
 	if (sc->sc_si) {
 		softintr_disestablish(sc->sc_si);
 		sc->sc_si = NULL;
 	}
-#endif
 
 	ifp->if_flags &= ~IFF_RUNNING;
 
@@ -545,11 +543,9 @@
 
 	ifp->if_flags |= IFF_RUNNING;
 
-#ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
 	sc->sc_si = softintr_establish(IPL_SOFTNET, etheripintr, sc);
 	if (sc->sc_si == NULL)
 		error = ENOMEM;
-#endif
 
 out:
 	splx(s);
@@ -565,12 +561,10 @@
 
 	s = splsoftnet();
 
-#ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
 	if (sc->sc_si) {
 		softintr_disestablish(sc->sc_si);
 		sc->sc_si = NULL;
 	}
-#endif
 
 	if (sc->sc_src) {
 		FREE(sc->sc_src, M_IFADDR);
@@ -588,7 +582,6 @@
 static int
 etherip_init(struct ifnet *ifp)
 {
-#ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
 	struct etherip_softc *sc = ifp->if_softc;
 
 	if (sc->sc_si == NULL)
@@ -596,7 +589,6 @@
 
 	if (sc->sc_si == NULL)
 		return(ENOMEM);
-#endif
 
 	ifp->if_flags |= IFF_RUNNING;
 	etherip_start(ifp);
@@ -686,11 +678,12 @@
 	int error;
 	size_t len;
 	char addr[3 * ETHER_ADDR_LEN];
+	char enaddr[ETHER_ADDR_LEN];
 
 	node = *rnode;
 	sc = node.sysctl_data;
 	ifp = &sc->sc_ec.ec_if;
-	(void)ether_snprintf(addr, sizeof(addr), LLADDR(ifp->if_sadl));
+	(void)ether_snprintf(addr, sizeof(addr), CLLADDR(ifp->if_sadl));
 	node.sysctl_data = addr;
 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
 	if (error || newp == NULL)
@@ -701,7 +694,9 @@
 		return EINVAL;
 
 	/* Commit change */
-	if (ether_nonstatic_aton(LLADDR(ifp->if_sadl), addr) != 0)
+	if (ether_nonstatic_aton(enaddr, addr) != 0 ||
+	    sockaddr_dl_setaddr(ifp->if_sadl, ifp->if_sadl->sdl_len,
+	                        enaddr, ETHER_ADDR_LEN) == NULL)
 		return EINVAL;
 
 	return error;
--- a/sys/net/if_etherip.h	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/if_etherip.h	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: if_etherip.h,v 1.2.2.2 2006/12/30 20:50:20 yamt Exp $        */
+/*      $NetBSD: if_etherip.h,v 1.2.2.3 2007/09/03 14:42:04 yamt Exp $        */
 
 /*
  *  Copyright (c) 2006, Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org>
@@ -52,17 +52,11 @@
 #ifdef INET
                 struct route     scr_ro;        /* cached inet route          */
 #endif
-#ifdef INET6
-                struct route_in6 scr_ro6;       /* cached inet6 route         */
-#endif
         } sc_scr;
-#ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
         void *sc_si;                            /* softintr handle            */
-#endif
         LIST_ENTRY(etherip_softc) etherip_list; /* list of etherip tunnels    */
 };
 #define sc_ro  sc_scr.scr_ro
-#define sc_ro6 sc_scr.scr_ro6
 
 struct etherip_header {
         u_int8_t eip_ver;       /* version/reserved */
--- a/sys/net/if_ethersubr.c	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/if_ethersubr.c	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ethersubr.c,v 1.126.2.3 2007/02/26 09:11:33 yamt Exp $	*/
+/*	$NetBSD: if_ethersubr.c,v 1.126.2.4 2007/09/03 14:42:04 yamt 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.126.2.3 2007/02/26 09:11:33 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.126.2.4 2007/09/03 14:42:04 yamt Exp $");
 
 #include "opt_inet.h"
 #include "opt_atalk.h"
@@ -204,7 +204,7 @@
  	uint8_t esrc[6], edst[6];
 	struct mbuf *m = m0;
 	struct rtentry *rt;
-	struct mbuf *mcopy = (struct mbuf *)0;
+	struct mbuf *mcopy = NULL;
 	struct ether_header *eh;
 	struct ifnet *ifp = ifp0;
 	ALTQ_DECL(struct altq_pktattr pktattr;)
@@ -294,7 +294,7 @@
 		if (m->m_flags & M_BCAST)
                 	(void)memcpy(edst, etherbroadcastaddr, sizeof(edst));
 		else {
-			caddr_t tha = ar_tha(ah);
+			void *tha = ar_tha(ah);
 
 			KASSERT(tha);
 			memcpy(edst, tha, sizeof(edst));
@@ -356,7 +356,7 @@
 			memcpy(llc.llc_snap_org_code, at_org_code,
 			    sizeof(llc.llc_snap_org_code));
 			llc.llc_snap_ether_type = htons(ETHERTYPE_ATALK);
-			memcpy(mtod(m, caddr_t), &llc, sizeof(struct llc));
+			memcpy(mtod(m, void *), &llc, sizeof(struct llc));
 		} else {
 			etype = htons(ETHERTYPE_ATALK);
 		}
@@ -377,11 +377,11 @@
 	case AF_ISO: {
 		int	snpalen;
 		struct	llc *l;
-		struct sockaddr_dl *sdl;
+		const struct sockaddr_dl *sdl;
 
-		if (rt && (sdl = (struct sockaddr_dl *)rt->rt_gateway) &&
+		if (rt && (sdl = satocsdl(rt->rt_gateway)) &&
 		    sdl->sdl_family == AF_LINK && sdl->sdl_alen > 0) {
-			memcpy(edst, LLADDR(sdl), sizeof(edst));
+			memcpy(edst, CLLADDR(sdl), sizeof(edst));
 		} else {
 			error = iso_snparesolve(ifp,
 			    (const struct sockaddr_iso *)dst,
@@ -398,7 +398,7 @@
 			if (mcopy) {
 				eh = mtod(mcopy, struct ether_header *);
 				memcpy(eh->ether_dhost, edst, sizeof(edst));
-				memcpy(eh->ether_shost, LLADDR(ifp->if_sadl),
+				memcpy(eh->ether_shost, CLLADDR(ifp->if_sadl),
 				    sizeof(edst));
 			}
 		}
@@ -462,12 +462,12 @@
 	if (hdrcmplt)
 		memcpy(eh->ether_shost, esrc, sizeof(eh->ether_shost));
 	else
-	 	memcpy(eh->ether_shost, LLADDR(ifp->if_sadl),
+	 	memcpy(eh->ether_shost, CLLADDR(ifp->if_sadl),
 		    sizeof(eh->ether_shost));
 
 #if NCARP > 0
 	if (ifp0 != ifp && ifp0->if_type == IFT_CARP) {
-	 	memcpy(eh->ether_shost, LLADDR(ifp0->if_sadl),
+	 	memcpy(eh->ether_shost, CLLADDR(ifp0->if_sadl),
 		    sizeof(eh->ether_shost));
 	}
 #endif /* NCARP > 0 */
@@ -524,7 +524,7 @@
 	struct ether_header *eh;
 	u_int16_t ether_type;
 	int hlen, af, hdrsize;
-	caddr_t hdr;
+	void *hdr;
 
 	hlen = ETHER_HDR_LEN;
 	eh = mtod(m, struct ether_header *);
@@ -584,7 +584,7 @@
 	m->m_data += hlen;
 	m->m_len -= hlen;
 
-	hdr = mtod(m, caddr_t);
+	hdr = mtod(m, void *);
 
 	if (ALTQ_NEEDS_CLASSIFY(ifq))
 		pktattr->pattr_class =
@@ -651,7 +651,7 @@
 		 * if it came from us.
 		 */
 		if ((ifp->if_flags & IFF_SIMPLEX) == 0 &&
-		    memcmp(LLADDR(ifp->if_sadl), eh->ether_shost,
+		    memcmp(CLLADDR(ifp->if_sadl), eh->ether_shost,
 		    ETHER_ADDR_LEN) == 0) {
 			m_freem(m);
 			return;
@@ -712,7 +712,7 @@
 #endif /* NCARP > 0 */
 		if ((m->m_flags & (M_BCAST|M_MCAST)) == 0 &&
 		    (ifp->if_flags & IFF_PROMISC) != 0 &&
-		    memcmp(LLADDR(ifp->if_sadl), eh->ether_dhost,
+		    memcmp(CLLADDR(ifp->if_sadl), eh->ether_dhost,
 			   ETHER_ADDR_LEN) != 0) {
 			m->m_flags |= M_PROMISC;
 		}
@@ -797,12 +797,7 @@
 			m_freem(m);
 		} else
 			IF_ENQUEUE(inq, m);
-#ifndef __HAVE_GENERIC_SOFT_INTERRUPTS
-		if (!callout_pending(&pppoe_softintr))
-			callout_reset(&pppoe_softintr, 1, pppoe_softintr_handler, NULL);
-#else
 		softintr_schedule(pppoe_softintr);
-#endif
 		return;
 #endif /* NPPPOE > 0 */
 	case ETHERTYPE_SLOWPROTOCOLS: {
@@ -880,6 +875,10 @@
 #endif
 #ifdef INET6
 		case ETHERTYPE_IPV6:
+#ifdef GATEWAY  
+			if (ip6flow_fastforward(m))
+				return;
+#endif
 			schednetisr(NETISR_IPV6);
 			inq = &ip6intrq;
 			break;
@@ -989,7 +988,7 @@
 				/* XXX we can optimize here? */
 				if (m->m_flags & (M_BCAST | M_MCAST))
 					memcpy(eh->ether_dhost,
-					    LLADDR(ifp->if_sadl),
+					    CLLADDR(ifp->if_sadl),
 					    ETHER_ADDR_LEN);
 				sa.sa_family = AF_UNSPEC;
 				sa.sa_len = sizeof(sa);
@@ -1076,7 +1075,8 @@
 		ifp->if_baudrate = IF_Mbps(10);		/* just a default */
 
 	if_alloc_sadl(ifp);
-	memcpy(LLADDR(ifp->if_sadl), lla, ifp->if_addrlen);
+	(void)sockaddr_dl_setaddr(ifp->if_sadl, ifp->if_sadl->sdl_len,
+	    lla, ifp->if_addrlen);
 
 	LIST_INIT(&ec->ec_multiaddrs);
 	ifp->if_broadcastaddr = etherbroadcastaddr;
@@ -1339,7 +1339,8 @@
 	u_char addrhi[ETHER_ADDR_LEN];
 	int s = splnet(), error;
 
-	error = ether_multiaddr(&ifr->ifr_addr, addrlo, addrhi);
+	error = ether_multiaddr(&ifr->ifr_addr, addrlo,
+	    addrhi);
 	if (error != 0) {
 		splx(s);
 		return error;
@@ -1397,7 +1398,8 @@
 	u_char addrhi[ETHER_ADDR_LEN];
 	int s = splnet(), error;
 
-	error = ether_multiaddr(&ifr->ifr_addr, addrlo, addrhi);
+	error = ether_multiaddr(&ifr->ifr_addr, addrlo,
+	    addrhi);
 	if (error != 0) {
 		splx(s);
 		return (error);
@@ -1437,7 +1439,7 @@
  * called at splnet().
  */
 int
-ether_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
+ether_ioctl(struct ifnet *ifp, u_long cmd, void *data)
 {
 	struct ethercom *ec = (void *) ifp;
 	struct ifreq *ifr = (struct ifreq *)data;
@@ -1450,8 +1452,7 @@
 		switch (ifa->ifa_addr->sa_family) {
 		case AF_LINK:
 		    {
-			struct sockaddr_dl *sdl =
-			    (struct sockaddr_dl *) ifa->ifa_addr;
+			const struct sockaddr_dl *sdl = satocsdl(ifa->ifa_addr);
 
 			if (sdl->sdl_type != IFT_ETHER ||
 			    sdl->sdl_alen != ifp->if_addrlen) {
@@ -1459,7 +1460,8 @@
 				break;
 			}
 
-			memcpy(LLADDR(ifp->if_sadl), LLADDR(sdl),
+			(void)sockaddr_dl_setaddr(ifp->if_sadl,
+			    ifp->if_sadl->sdl_len, CLLADDR(sdl),
 			    ifp->if_addrlen);
 
 			/* Set new address. */
@@ -1483,7 +1485,7 @@
 
 	case SIOCGIFADDR:
 		memcpy(((struct sockaddr *)&ifr->ifr_data)->sa_data,
-		    LLADDR(ifp->if_sadl), ETHER_ADDR_LEN);
+		    CLLADDR(ifp->if_sadl), ETHER_ADDR_LEN);
 		break;
 
 	case SIOCSIFMTU:
--- a/sys/net/if_faith.c	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/if_faith.c	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_faith.c,v 1.30.12.3 2007/02/26 09:11:34 yamt Exp $	*/
+/*	$NetBSD: if_faith.c,v 1.30.12.4 2007/09/03 14:42:05 yamt Exp $	*/
 /*	$KAME: if_faith.c,v 1.21 2001/02/20 07:59:26 itojun Exp $	*/
 
 /*
@@ -40,7 +40,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_faith.c,v 1.30.12.3 2007/02/26 09:11:34 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_faith.c,v 1.30.12.4 2007/09/03 14:42:05 yamt Exp $");
 
 #include "opt_inet.h"
 
@@ -83,7 +83,7 @@
 
 #include <net/net_osdep.h>
 
-static int	faithioctl(struct ifnet *, u_long, caddr_t);
+static int	faithioctl(struct ifnet *, u_long, void *);
 static int	faithoutput(struct ifnet *, struct mbuf *,
 		            const struct sockaddr *, struct rtentry *);
 static void	faithrtrequest(int, struct rtentry *, struct rt_addrinfo *);
@@ -225,7 +225,7 @@
  */
 /* ARGSUSED */
 static int
-faithioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
+faithioctl(struct ifnet *ifp, u_long cmd, void *data)
 {
 	struct ifaddr *ifa;
 	struct ifreq *ifr = (struct ifreq *)data;
--- a/sys/net/if_fddi.h	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/if_fddi.h	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_fddi.h,v 1.9.38.1 2006/06/21 15:10:27 yamt Exp $	*/
+/*	$NetBSD: if_fddi.h,v 1.9.38.2 2007/09/03 14:42:05 yamt Exp $	*/
 
 /*
  * Copyright (c) 1995 Matt Thomas (thomas@lkg.dec.com)
@@ -83,12 +83,10 @@
 #define	fddibroadcastaddr	etherbroadcastaddr
 #define	fddi_ipmulticast_min	ether_ipmulticast_min
 #define	fddi_ipmulticast_max	ether_ipmulticast_max
-#define	fddi_addmulti		ether_addmulti
-#define	fddi_delmulti		ether_delmulti
 #define	fddi_sprintf		ether_sprintf
 
 #if defined(__NetBSD__)
-void    fddi_ifattach(struct ifnet *, caddr_t);
+void    fddi_ifattach(struct ifnet *, void *);
 #else
 void    fddi_ifattach(struct ifnet *);
 #endif
--- a/sys/net/if_fddisubr.c	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/if_fddisubr.c	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_fddisubr.c,v 1.56.2.3 2007/02/26 09:11:34 yamt Exp $	*/
+/*	$NetBSD: if_fddisubr.c,v 1.56.2.4 2007/09/03 14:42:05 yamt 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.56.2.3 2007/02/26 09:11:34 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_fddisubr.c,v 1.56.2.4 2007/09/03 14:42:05 yamt Exp $");
 
 #include "opt_inet.h"
 #include "opt_atalk.h"
@@ -194,6 +194,7 @@
 #endif
 
 #define	FDDIADDR(ifp)		LLADDR((ifp)->if_sadl)
+#define	CFDDIADDR(ifp)		CLLADDR((ifp)->if_sadl)
 
 static	int fddi_output(struct ifnet *, struct mbuf *,
 	    const struct sockaddr *, struct rtentry *);
@@ -214,7 +215,7 @@
 	struct mbuf *m = m0;
 	struct rtentry *rt;
 	struct fddi_header *fh;
-	struct mbuf *mcopy = (struct mbuf *)0;
+	struct mbuf *mcopy = NULL;
 	struct ifnet *ifp = ifp0;
 	ALTQ_DECL(struct altq_pktattr pktattr;)
 
@@ -279,7 +280,7 @@
                 	memcpy(edst, fddibroadcastaddr, sizeof(edst));
 		else if (m->m_flags & M_MCAST) {
 			ETHER_MAP_IP_MULTICAST(&satocsin(dst)->sin_addr,
-			    (caddr_t)edst);
+			    (char *)edst);
 		} else if (!arpresolve(ifp, rt, m, dst, edst))
 			return (0);	/* if not yet resolved */
 		/* If broadcasting on a simplex interface, loopback a copy */
@@ -304,7 +305,7 @@
 		if (m->m_flags & M_BCAST)
                 	memcpy(edst, etherbroadcastaddr, sizeof(edst));
 		else {
-			caddr_t tha = ar_tha(ah);
+			void *tha = ar_tha(ah);
 
 			KASSERT(tha);
 			memcpy(edst, tha, sizeof(edst));
@@ -370,7 +371,7 @@
 			memcpy(llc.llc_snap_org_code, at_org_code,
 			    sizeof(at_org_code));
 			llc.llc_snap_ether_type = htons(ETHERTYPE_ATALK);
-			memcpy(mtod(m, caddr_t), &llc, sizeof(struct llc));
+			memcpy(mtod(m, void *), &llc, sizeof(struct llc));
 			etype = 0;
 		} else {
 			etype = htons(ETHERTYPE_ATALK);
@@ -382,11 +383,11 @@
 	case AF_ISO: {
 		int	snpalen;
 		struct	llc *l;
-		struct sockaddr_dl *sdl;
+		const struct sockaddr_dl *sdl;
 
-		if (rt && (sdl = (struct sockaddr_dl *)rt->rt_gateway) &&
+		if (rt && (sdl = satocsdl(rt->rt_gateway)) &&
 		    sdl->sdl_family == AF_LINK && sdl->sdl_alen > 0) {
-			memcpy(edst, LLADDR(sdl), sizeof(edst));
+			memcpy(edst, CLLADDR(sdl), sizeof(edst));
 		} else if ((error =
 			    iso_snparesolve(ifp, (const struct sockaddr_iso *)dst,
 					    (char *)edst, &snpalen)) != 0)
@@ -400,7 +401,7 @@
 			if (mcopy) {
 				fh = mtod(mcopy, struct fddi_header *);
 				memcpy(fh->fddi_dhost, edst, sizeof (edst));
-				memcpy(fh->fddi_shost, FDDIADDR(ifp),
+				memcpy(fh->fddi_shost, CFDDIADDR(ifp),
 				    sizeof (edst));
 			}
 		}
@@ -516,7 +517,7 @@
 	if (hdrcmplt)
 		memcpy(fh->fddi_shost, esrc, sizeof(fh->fddi_shost));
 	else
-		memcpy(fh->fddi_shost, FDDIADDR(ifp), sizeof(fh->fddi_shost));
+		memcpy(fh->fddi_shost, CFDDIADDR(ifp), sizeof(fh->fddi_shost));
 
 #if NCARP > 0
 	if (ifp0 != ifp && ifp0->if_type == IFT_CARP)
@@ -565,7 +566,7 @@
 			m->m_flags |= M_MCAST;
 		ifp->if_imcasts++;
 	} else if ((ifp->if_flags & IFF_PROMISC)
-	    && memcmp(FDDIADDR(ifp), (caddr_t)fh->fddi_dhost,
+	    && memcmp(CFDDIADDR(ifp), (void *)fh->fddi_dhost,
 		    sizeof(fh->fddi_dhost)) != 0) {
 		m_freem(m);
 		return;
@@ -651,6 +652,10 @@
 #endif
 #ifdef INET6
 		case ETHERTYPE_IPV6:
+#ifdef GATEWAY  
+			if (ip6flow_fastforward(m))
+				return;
+#endif
 			schednetisr(NETISR_IPV6);
 			inq = &ip6intrq;
 			break;
@@ -715,7 +720,7 @@
 			l->llc_ssap = c;
 			eh = (struct ether_header *)sa.sa_data;
 			if (m->m_flags & (M_BCAST | M_MCAST))
-				memcpy(eh->ether_dhost, FDDIADDR(ifp), 6);
+				memcpy(eh->ether_dhost, CFDDIADDR(ifp), 6);
 			sa.sa_family = AF_UNSPEC;
 			sa.sa_len = sizeof(sa);
 			for (i = 0; i < 6; i++) {
@@ -758,7 +763,7 @@
  * Perform common duties while attaching to interface list
  */
 void
-fddi_ifattach(struct ifnet *ifp, caddr_t lla)
+fddi_ifattach(struct ifnet *ifp, void *lla)
 {
 	struct ethercom *ec = (struct ethercom *)ifp;
 
@@ -782,7 +787,8 @@
 
 	LIST_INIT(&ec->ec_multiaddrs);
 	if_alloc_sadl(ifp);
-	memcpy(LLADDR(ifp->if_sadl), lla, ifp->if_addrlen);
+	sockaddr_dl_setaddr(ifp->if_sadl, ifp->if_sadl->sdl_len, lla,
+	    ifp->if_addrlen);
 
 	ifp->if_broadcastaddr = fddibroadcastaddr;
 #if NBPFILTER > 0
--- a/sys/net/if_gif.c	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/if_gif.c	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_gif.c,v 1.54.2.3 2007/02/26 09:11:34 yamt Exp $	*/
+/*	$NetBSD: if_gif.c,v 1.54.2.4 2007/09/03 14:42:06 yamt 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.54.2.3 2007/02/26 09:11:34 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_gif.c,v 1.54.2.4 2007/09/03 14:42:06 yamt Exp $");
 
 #include "opt_inet.h"
 #include "opt_iso.h"
@@ -91,9 +91,6 @@
 #include <net/net_osdep.h>
 
 void	gifattach(int);
-#ifndef __HAVE_GENERIC_SOFT_INTERRUPTS
-static void	gifnetisr(void);
-#endif
 static void	gifintr(void *);
 #ifdef ISO
 static struct mbuf *gif_eon_encap(struct mbuf *);
@@ -188,8 +185,8 @@
 #if NBPFILTER > 0
 	bpfdetach(ifp);
 #endif
+	if_detach(ifp);
 	rtcache_free(&sc->gif_ro);
-	if_detach(ifp);
 
 	free(sc, M_DEVBUF);
 
@@ -236,7 +233,7 @@
 	if (m->m_pkthdr.len < sizeof(ip))
 		return 0;
 
-	m_copydata(m, 0, sizeof(ip), (caddr_t)&ip);
+	m_copydata(m, 0, sizeof(ip), (void *)&ip);
 
 	switch (ip.ip_v) {
 #ifdef INET
@@ -330,12 +327,7 @@
 	}
 	splx(s);
 
-#ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
 	softintr_schedule(sc->gif_si);
-#else
-	/* XXX bad spl level? */
-	gifnetisr();
-#endif
 	error = 0;
 
   end:
@@ -345,19 +337,6 @@
 	return error;
 }
 
-#ifndef __HAVE_GENERIC_SOFT_INTERRUPTS
-static void
-gifnetisr(void)
-{
-	struct gif_softc *sc;
-
-	for (sc = LIST_FIRST(&gif_softc_list); sc != NULL;
-	     sc = LIST_NEXT(sc, gif_list)) {
-		gifintr(sc);
-	}
-}
-#endif
-
 static void
 gifintr(void *arg)
 {
@@ -498,7 +477,7 @@
 
 /* XXX how should we handle IPv6 scope on SIOC[GS]IFPHYADDR? */
 int
-gif_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
+gif_ioctl(struct ifnet *ifp, u_long cmd, void *data)
 {
 	struct lwp *l = curlwp;	/* XXX */
 	struct gif_softc *sc  = (struct gif_softc*)ifp;
@@ -689,7 +668,7 @@
 		}
 		if (src->sa_len > size)
 			return EINVAL;
-		bcopy((caddr_t)src, (caddr_t)dst, src->sa_len);
+		memcpy(dst, src, src->sa_len);
 		break;
 
 	case SIOCGIFPDSTADDR:
@@ -721,7 +700,7 @@
 		}
 		if (src->sa_len > size)
 			return EINVAL;
-		bcopy((caddr_t)src, (caddr_t)dst, src->sa_len);
+		memcpy(dst, src, src->sa_len);
 		break;
 
 	case SIOCGLIFPHYADDR:
@@ -737,7 +716,7 @@
 		size = sizeof(((struct if_laddrreq *)data)->addr);
 		if (src->sa_len > size)
 			return EINVAL;
-		bcopy((caddr_t)src, (caddr_t)dst, src->sa_len);
+		memcpy(dst, src, src->sa_len);
 
 		/* copy dst */
 		src = sc->gif_pdst;
@@ -746,7 +725,7 @@
 		size = sizeof(((struct if_laddrreq *)data)->dstaddr);
 		if (src->sa_len > size)
 			return EINVAL;
-		bcopy((caddr_t)src, (caddr_t)dst, src->sa_len);
+		memcpy(dst, src, src->sa_len);
 		break;
 
 	case SIOCSIFFLAGS:
@@ -772,8 +751,7 @@
 
 	s = splsoftnet();
 
-	for (sc2 = LIST_FIRST(&gif_softc_list); sc2 != NULL;
-	     sc2 = LIST_NEXT(sc2, gif_list)) {
+	LIST_FOREACH(sc2, &gif_softc_list, gif_list) {
 		if (sc2 == sc)
 			continue;
 		if (!sc2->gif_pdst || !sc2->gif_psrc)
@@ -784,8 +762,8 @@
 		    sc2->gif_psrc->sa_len != src->sa_len)
 			continue;
 		/* can't configure same pair of address onto two gifs */
-		if (bcmp(sc2->gif_pdst, dst, dst->sa_len) == 0 &&
-		    bcmp(sc2->gif_psrc, src, src->sa_len) == 0) {
+		if (memcmp(sc2->gif_pdst, dst, dst->sa_len) == 0 &&
+		    memcmp(sc2->gif_psrc, src, src->sa_len) == 0) {
 			error = EADDRNOTAVAIL;
 			goto bad;
 		}
@@ -793,12 +771,10 @@
 		/* 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)
@@ -815,22 +791,20 @@
 #endif
 		}
 
-#ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
 	sc->gif_si = softintr_establish(IPL_SOFTNET, gifintr, sc);
 	if (sc->gif_si == NULL) {
 		error = ENOMEM;
 		goto bad;
 	}
-#endif
 
 	osrc = sc->gif_psrc;
 	sa = (struct sockaddr *)malloc(src->sa_len, M_IFADDR, M_WAITOK);
-	bcopy((caddr_t)src, (caddr_t)sa, src->sa_len);
+	memcpy(sa, src, src->sa_len);
 	sc->gif_psrc = sa;
 
 	odst = sc->gif_pdst;
 	sa = (struct sockaddr *)malloc(dst->sa_len, M_IFADDR, M_WAITOK);
-	bcopy((caddr_t)dst, (caddr_t)sa, dst->sa_len);
+	memcpy(sa, dst, dst->sa_len);
 	sc->gif_pdst = sa;
 
 	switch (sc->gif_psrc->sa_family) {
@@ -850,17 +824,17 @@
 	}
 	if (error) {
 		/* rollback */
-		free((caddr_t)sc->gif_psrc, M_IFADDR);
-		free((caddr_t)sc->gif_pdst, M_IFADDR);
+		free((void *)sc->gif_psrc, M_IFADDR);
+		free((void *)sc->gif_pdst, M_IFADDR);
 		sc->gif_psrc = osrc;
 		sc->gif_pdst = odst;
 		goto bad;
 	}
 
 	if (osrc)
-		free((caddr_t)osrc, M_IFADDR);
+		free((void *)osrc, M_IFADDR);
 	if (odst)
-		free((caddr_t)odst, M_IFADDR);
+		free((void *)odst, M_IFADDR);
 
 	if (sc->gif_psrc && sc->gif_pdst)
 		ifp->if_flags |= IFF_RUNNING;
@@ -871,12 +845,10 @@
 	return 0;
 
  bad:
-#ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
 	if (sc->gif_si) {
 		softintr_disestablish(sc->gif_si);
 		sc->gif_si = NULL;
 	}
-#endif
 	if (sc->gif_psrc && sc->gif_pdst)
 		ifp->if_flags |= IFF_RUNNING;
 	else
@@ -894,18 +866,16 @@
 
 	s = splsoftnet();
 
-#ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
 	if (sc->gif_si) {
 		softintr_disestablish(sc->gif_si);
 		sc->gif_si = NULL;
 	}
-#endif
 	if (sc->gif_psrc) {
-		free((caddr_t)sc->gif_psrc, M_IFADDR);
+		free((void *)sc->gif_psrc, M_IFADDR);
 		sc->gif_psrc = NULL;
 	}
 	if (sc->gif_pdst) {
-		free((caddr_t)sc->gif_pdst, M_IFADDR);
+		free((void *)sc->gif_pdst, M_IFADDR);
 		sc->gif_pdst = NULL;
 	}
 	/* it is safe to detach from both */
@@ -952,7 +922,7 @@
 		struct mbuf mhead;
 		memset(&mhead, 0, sizeof(mhead));
 		ehdr->cksum = 0;
-		mhead.m_data = (caddr_t)ehdr;
+		mhead.m_data = (void *)ehdr;
 		mhead.m_len = sizeof(*ehdr);
 		mhead.m_next = 0;
 		iso_gen_csum(&mhead, offsetof(struct eonhdr, cksum),
--- a/sys/net/if_gif.h	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/if_gif.h	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_gif.h,v 1.11.2.3 2007/02/26 09:11:34 yamt Exp $	*/
+/*	$NetBSD: if_gif.h,v 1.11.2.4 2007/09/03 14:42:06 yamt Exp $	*/
 /*	$KAME: if_gif.h,v 1.23 2001/07/27 09:21:42 itojun Exp $	*/
 
 /*
@@ -54,24 +54,16 @@
 	struct sockaddr	*gif_pdst; /* Physical dst addr */
 	union {
 		struct route  gifscr_ro;    /* xxx */
-#ifdef INET6
-		struct route_in6 gifscr_ro6; /* xxx */
-#endif
 	} gifsc_gifscr;
 	int		gif_flags;
 	const struct encaptab *encap_cookie4;
 	const struct encaptab *encap_cookie6;
 	LIST_ENTRY(gif_softc) gif_list;	/* list of all gifs */
-#ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
 	void	*gif_si;		/* softintr handle */
-#endif
 };
 #define GIF_ROUTE_TTL	10
 
 #define gif_ro gifsc_gifscr.gifscr_ro
-#ifdef INET6
-#define gif_ro6 gifsc_gifscr.gifscr_ro6
-#endif
 
 #define GIF_MTU		(1280)	/* Default MTU */
 #define	GIF_MTU_MIN	(1280)	/* Minimum MTU */
@@ -82,7 +74,7 @@
 void	gif_input(struct mbuf *, int, struct ifnet *);
 int	gif_output(struct ifnet *, struct mbuf *,
 		   const struct sockaddr *, struct rtentry *);
-int	gif_ioctl(struct ifnet *, u_long, caddr_t);
+int	gif_ioctl(struct ifnet *, u_long, void *);
 int	gif_set_tunnel(struct ifnet *, struct sockaddr *, struct sockaddr *);
 void	gif_delete_tunnel(struct ifnet *);
 #ifdef GIF_ENCAPCHECK
--- a/sys/net/if_gre.c	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/if_gre.c	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_gre.c,v 1.57.2.3 2007/02/26 09:11:34 yamt Exp $ */
+/*	$NetBSD: if_gre.c,v 1.57.2.4 2007/09/03 14:42:06 yamt Exp $ */
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -48,7 +48,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_gre.c,v 1.57.2.3 2007/02/26 09:11:34 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_gre.c,v 1.57.2.4 2007/09/03 14:42:06 yamt Exp $");
 
 #include "opt_gre.h"
 #include "opt_inet.h"
@@ -72,6 +72,9 @@
 #include <sys/kauth.h>
 #endif
 
+#include <sys/kernel.h>
+#include <sys/mutex.h>
+#include <sys/condvar.h>
 #include <sys/kthread.h>
 
 #include <machine/cpu.h>
@@ -106,6 +109,8 @@
 
 #include <net/if_gre.h>
 
+#include <compat/sys/socket.h>
+#include <compat/sys/sockio.h>
 /*
  * It is not easy to calculate the right value for a GRE MTU.
  * We leave this task to the admin and use the same default that
@@ -114,9 +119,10 @@
 #define GREMTU 1476
 
 #ifdef GRE_DEBUG
+int gre_debug = 0;
 #define	GRE_DPRINTF(__sc, __fmt, ...)				\
 	do {							\
-		if (((__sc)->sc_if.if_flags & IFF_DEBUG) != 0)	\
+		if (gre_debug || ((__sc)->sc_if.if_flags & IFF_DEBUG) != 0)\
 			printf(__fmt, __VA_ARGS__);		\
 	} while (/*CONSTCOND*/0)
 #else
@@ -134,42 +140,32 @@
 
 static int	gre_output(struct ifnet *, struct mbuf *,
 			   const struct sockaddr *, struct rtentry *);
-static int	gre_ioctl(struct ifnet *, u_long, caddr_t);
+static int	gre_ioctl(struct ifnet *, u_long, void *);
 
+static void gre_thread(void *);
 static int	gre_compute_route(struct gre_softc *sc);
 
+static void gre_closef(struct file **, struct lwp *);
 static int gre_getsockname(struct socket *, struct mbuf *, struct lwp *);
 static int gre_getpeername(struct socket *, struct mbuf *, struct lwp *);
 static int gre_getnames(struct socket *, struct lwp *, struct sockaddr_in *,
     struct sockaddr_in *);
 
+/* Calling thread must hold sc->sc_mtx. */
 static void
-gre_stop(volatile int *running)
+gre_join(struct gre_softc *sc)
 {
-	*running = 0;
-	wakeup(running);
+	while (sc->sc_running != 0)
+		cv_wait(&sc->sc_join_cv, &sc->sc_mtx);
 }
 
-static void
-gre_join(volatile int *running)
-{
-	int s;
-
-	s = splnet();
-	while (*running != 0) {
-		splx(s);
-		tsleep(running, PSOCK, "grejoin", 0);
-		s = splnet();
-	}
-	splx(s);
-}
-
+/* Calling thread must hold sc->sc_mtx. */
 static void
 gre_wakeup(struct gre_softc *sc)
 {
 	GRE_DPRINTF(sc, "%s: enter\n", __func__);
-	sc->sc_waitchan = 1;
-	wakeup(&sc->sc_waitchan);
+	sc->sc_haswork = 1;
+	cv_signal(&sc->sc_work_cv);
 }
 
 static int
@@ -179,6 +175,10 @@
 
 	sc = malloc(sizeof(struct gre_softc), M_DEVBUF, M_WAITOK);
 	memset(sc, 0, sizeof(struct gre_softc));
+	mutex_init(&sc->sc_mtx, MUTEX_DRIVER, IPL_NET);
+	cv_init(&sc->sc_work_cv, "gre work");
+	cv_init(&sc->sc_join_cv, "gre join");
+	cv_init(&sc->sc_soparm_cv, "gre soparm");
 
 	snprintf(sc->sc_if.if_xname, sizeof(sc->sc_if.if_xname), "%s%d",
 	    ifc->ifc_name, unit);
@@ -191,8 +191,8 @@
 	sc->sc_if.if_flags = IFF_POINTOPOINT|IFF_MULTICAST;
 	sc->sc_if.if_output = gre_output;
 	sc->sc_if.if_ioctl = gre_ioctl;
-	sc->g_dst.s_addr = sc->g_src.s_addr = INADDR_ANY;
-	sc->g_dstport = sc->g_srcport = 0;
+	sc->sc_dst.s_addr = sc->sc_src.s_addr = INADDR_ANY;
+	sc->sc_dstport = sc->sc_srcport = 0;
 	sc->sc_proto = IPPROTO_GRE;
 	sc->sc_snd.ifq_maxlen = 256;
 	sc->sc_if.if_flags |= IFF_LINK0;
@@ -201,6 +201,10 @@
 #if NBPFILTER > 0
 	bpfattach(&sc->sc_if, DLT_NULL, sizeof(u_int32_t));
 #endif
+	sc->sc_running = 1;
+	if (kthread_create(PRI_NONE, 0, NULL, gre_thread, sc,
+	    NULL, sc->sc_if.if_xname) != 0)
+		sc->sc_running = 0;
 	LIST_INSERT_HEAD(&gre_softc_list, sc, sc_list);
 	return 0;
 }
@@ -208,33 +212,31 @@
 static int
 gre_clone_destroy(struct ifnet *ifp)
 {
-	int s;
 	struct gre_softc *sc = ifp->if_softc;
 
 	LIST_REMOVE(sc, sc_list);
 #if NBPFILTER > 0
 	bpfdetach(ifp);
 #endif
-	s = splnet();
-	ifp->if_flags &= ~IFF_UP;
+	if_detach(ifp);
+	mutex_enter(&sc->sc_mtx);
+	sc->sc_dying = 1;
 	gre_wakeup(sc);
-	splx(s);
-	gre_join(&sc->sc_thread);
-	s = splnet();
+	gre_join(sc);
+	mutex_exit(&sc->sc_mtx);
 	rtcache_free(&sc->route);
-	if_detach(ifp);
-	splx(s);
-	if (sc->sc_fp != NULL) {
-		closef(sc->sc_fp, curlwp);
-		sc->sc_fp = NULL;
-	}
+
+	cv_destroy(&sc->sc_soparm_cv);
+	cv_destroy(&sc->sc_join_cv);
+	cv_destroy(&sc->sc_work_cv);
+	mutex_destroy(&sc->sc_mtx);
 	free(sc, M_DEVBUF);
 
 	return 0;
 }
 
 static void
-gre_receive(struct socket *so, caddr_t arg, int waitflag)
+gre_receive(struct socket *so, void *arg, int waitflag)
 {
 	struct gre_softc *sc = (struct gre_softc *)arg;
 
@@ -244,9 +246,10 @@
 }
 
 static void
-gre_upcall_add(struct socket *so, caddr_t arg)
+gre_upcall_add(struct socket *so, void *arg)
 {
 	/* XXX What if the kernel already set an upcall? */
+	KASSERT((so->so_rcv.sb_flags & SB_UPCALL) == 0);
 	so->so_upcallarg = arg;
 	so->so_upcall = gre_receive;
 	so->so_rcv.sb_flags |= SB_UPCALL;
@@ -282,8 +285,7 @@
 }
 
 static int
-gre_socreate1(struct gre_softc *sc, struct lwp *l, struct gre_soparm *sp,
-    struct socket **sop)
+gre_socreate1(struct gre_softc *sc, struct lwp *l, struct socket **sop)
 {
 	int rc;
 	struct mbuf *m;
@@ -299,16 +301,14 @@
 
 	so = *sop;
 
-	gre_upcall_add(so, (caddr_t)sc);
+	gre_upcall_add(so, sc);
 	if ((m = gre_getsockmbuf(so)) == NULL) {
 		rc = ENOBUFS;
 		goto out;
 	}
 	sin = mtod(m, struct sockaddr_in *);
-	sin->sin_len = m->m_len = sizeof(struct sockaddr_in);
-	sin->sin_family = AF_INET;
-	sin->sin_addr = sc->g_src;
-	sin->sin_port = sc->g_srcport;
+	sockaddr_in_init(sin, &sc->sc_src, sc->sc_srcport);
+	m->m_len = sin->sin_len;
 
 	GRE_DPRINTF(sc, "%s: bind 0x%08" PRIx32 " port %d\n", __func__,
 	    sin->sin_addr.s_addr, ntohs(sin->sin_port));
@@ -317,17 +317,16 @@
 		goto out;
 	}
 
-	if (sc->g_srcport == 0) {
+	if (sc->sc_srcport == 0) {
 		if ((rc = gre_getsockname(so, m, l)) != 0) {
-			GRE_DPRINTF(sc, "%s: gre_getsockname failed\n",
-			    __func__);
+			GRE_DPRINTF(sc, "%s: gre_getsockname\n", __func__);
 			goto out;
 		}
-		sc->g_srcport = sin->sin_port;
+		sc->sc_srcport = sin->sin_port;
 	}
 
-	sin->sin_addr = sc->g_dst;
-	sin->sin_port = sc->g_dstport;
+	sockaddr_in_init(sin, &sc->sc_dst, sc->sc_dstport);
+	m->m_len = sin->sin_len;
 
 	if ((rc = soconnect(so, m, l)) != 0) {
 		GRE_DPRINTF(sc, "%s: soconnect failed\n", __func__);
@@ -336,11 +335,12 @@
 
 	*mtod(m, int *) = ip_gre_ttl;
 	m->m_len = sizeof(int);
+	KASSERT(so->so_proto && so->so_proto->pr_ctloutput);
 	rc = (*so->so_proto->pr_ctloutput)(PRCO_SETOPT, so, IPPROTO_IP, IP_TTL,
 	    &m);
 	m = NULL;
 	if (rc != 0) {
-		printf("%s: setopt ttl failed\n", __func__);
+		GRE_DPRINTF(sc, "%s: setopt ttl failed\n", __func__);
 		rc = 0;
 	}
 out:
@@ -348,147 +348,150 @@
 
 	if (rc != 0)
 		gre_sodestroy(sop);
-	else
-		*sp = sc->sc_soparm;
+	else {
+		sc->sc_if.if_flags |= IFF_RUNNING;
+		sc->sc_soparm = sc->sc_newsoparm;
+	}
 
 	return rc;
 }
 
 static void
+gre_do_recv(struct gre_softc *sc, struct socket *so, lwp_t *l)
+{
+	for (;;) {
+		int flags, rc;
+		const struct gre_h *gh;
+		struct mbuf *m;
+
+		flags = MSG_DONTWAIT;
+		sc->sc_uio.uio_resid = 1000000;
+		rc = (*so->so_receive)(so, NULL, &sc->sc_uio, &m, NULL, &flags);
+		/* TBD Back off if ECONNREFUSED (indicates
+		 * ICMP Port Unreachable)?
+		 */
+		if (rc == EWOULDBLOCK) {
+			GRE_DPRINTF(sc, "%s: so_receive EWOULDBLOCK\n",
+			    __func__);
+			break;
+		} else if (rc != 0 || m == NULL) {
+			GRE_DPRINTF(sc, "%s: rc %d m %p\n",
+			    sc->sc_if.if_xname, rc, (void *)m);
+			continue;
+		} else
+			GRE_DPRINTF(sc, "%s: so_receive ok\n", __func__);
+		if (m->m_len < sizeof(*gh) &&
+		    (m = m_pullup(m, sizeof(*gh))) == NULL) {
+			GRE_DPRINTF(sc, "%s: m_pullup failed\n", __func__);
+			continue;
+		}
+		gh = mtod(m, const struct gre_h *);
+
+		if (gre_input3(sc, m, 0, gh, 0) == 0) {
+			GRE_DPRINTF(sc, "%s: dropping unsupported\n", __func__);
+			m_freem(m);
+		}
+	}
+}
+
+static void
+gre_do_send(struct gre_softc *sc, struct socket *so, lwp_t *l)
+{
+	for (;;) {
+		int rc;
+		struct mbuf *m;
+
+		mutex_enter(&sc->sc_mtx);
+		IF_DEQUEUE(&sc->sc_snd, m);
+		mutex_exit(&sc->sc_mtx);
+		if (m == NULL)
+			break;
+		GRE_DPRINTF(sc, "%s: dequeue\n", __func__);
+		if ((so->so_state & SS_ISCONNECTED) == 0) {
+			GRE_DPRINTF(sc, "%s: not connected\n", __func__);
+			m_freem(m);
+			continue;
+		}
+		rc = (*so->so_send)(so, NULL, NULL, m, NULL, 0, l);
+		/* XXX handle ENOBUFS? */
+		if (rc != 0)
+			GRE_DPRINTF(sc, "%s: so_send failed\n",
+			    __func__);
+	}
+}
+
+static struct socket *
+gre_reconf(struct gre_softc *sc, struct socket *so, lwp_t *l)
+{
+	struct ifnet *ifp = &sc->sc_if;
+
+	GRE_DPRINTF(sc, "%s: enter\n", __func__);
+
+shutdown:
+	if (sc->sc_soparm.sp_fp != NULL) {
+		GRE_DPRINTF(sc, "%s: l.%d\n", __func__, __LINE__);
+		gre_upcall_remove(so);
+		gre_closef(&sc->sc_soparm.sp_fp, curlwp);
+		so = NULL;
+	} else if (so != NULL)
+		gre_sodestroy(&so);
+
+	if (sc->sc_dying)
+		GRE_DPRINTF(sc, "%s: dying\n", __func__);
+	else if ((ifp->if_flags & IFF_UP) != IFF_UP)
+		GRE_DPRINTF(sc, "%s: down\n", __func__);
+	else if (sc->sc_proto != IPPROTO_UDP)
+		GRE_DPRINTF(sc, "%s: not UDP\n", __func__);
+	else if (sc->sc_newsoparm.sp_fp != NULL) {
+		sc->sc_soparm = sc->sc_newsoparm;
+		sc->sc_newsoparm.sp_fp = NULL;
+		so = (struct socket *)sc->sc_soparm.sp_fp->f_data;
+		gre_upcall_add(so, sc);
+	} else if (gre_socreate1(sc, l, &so) != 0) {
+		sc->sc_dying = 1;
+		goto shutdown;
+	}
+	cv_signal(&sc->sc_soparm_cv);
+	if (so != NULL)
+		sc->sc_if.if_flags |= IFF_RUNNING;
+	else if (sc->sc_proto == IPPROTO_UDP)
+		sc->sc_if.if_flags &= ~IFF_RUNNING;
+	return so;
+}
+
+static void
 gre_thread1(struct gre_softc *sc, struct lwp *l)
 {
-	int flags, rc, s;
-	const struct gre_h *gh;
 	struct ifnet *ifp = &sc->sc_if;
-	struct mbuf *m;
 	struct socket *so = NULL;
-	struct uio uio;
-	struct gre_soparm sp;
 
 	GRE_DPRINTF(sc, "%s: enter\n", __func__);
-	s = splnet();
 
-	sc->sc_waitchan = 1;
-
-	memset(&sp, 0, sizeof(sp));
-	memset(&uio, 0, sizeof(uio));
-
-	ifp->if_flags |= IFF_RUNNING;
-
-	for (;;) {
-		while (sc->sc_waitchan == 0) {
-			splx(s);
+	while (!sc->sc_dying) {
+		while (sc->sc_haswork == 0) {
 			GRE_DPRINTF(sc, "%s: sleeping\n", __func__);
-			tsleep(&sc->sc_waitchan, PSOCK, "grewait", 0);
-			s = splnet();
-		}
-		sc->sc_waitchan = 0;
-		GRE_DPRINTF(sc, "%s: awake\n", __func__);
-		if ((ifp->if_flags & IFF_UP) != IFF_UP) {
-			GRE_DPRINTF(sc, "%s: not up & running; exiting\n",
-			    __func__);
-			break;
-		}
-		if (sc->sc_proto != IPPROTO_UDP) {
-			GRE_DPRINTF(sc, "%s: not udp; exiting\n", __func__);
-			break;
-		}
-		/* XXX optimize */ 
-		if (so == NULL || memcmp(&sp, &sc->sc_soparm, sizeof(sp)) != 0){
-			GRE_DPRINTF(sc, "%s: parameters changed\n", __func__);
-
-			if (sp.sp_fp != NULL) {
-				FILE_UNUSE(sp.sp_fp, NULL);
-				sp.sp_fp = NULL;
-				so = NULL;
-			} else if (so != NULL)
-				gre_sodestroy(&so);
-
-			if (sc->sc_fp != NULL) {
-				so = (struct socket *)sc->sc_fp->f_data;
-				gre_upcall_add(so, (caddr_t)sc);
-				sp = sc->sc_soparm;
-				FILE_USE(sp.sp_fp);
-			} else if (gre_socreate1(sc, l, &sp, &so) != 0)
-				goto out;
+			cv_wait(&sc->sc_work_cv, &sc->sc_mtx);
 		}
-		for (;;) {
-			flags = MSG_DONTWAIT;
-			uio.uio_resid = 1000000;
-			rc = (*so->so_receive)(so, NULL, &uio, &m, NULL,
-			    &flags);
-			/* TBD Back off if ECONNREFUSED (indicates
-			 * ICMP Port Unreachable)?
-			 */
-			if (rc == EWOULDBLOCK) {
-				GRE_DPRINTF(sc, "%s: so_receive EWOULDBLOCK\n",
-				    __func__);
-				break;
-			} else if (rc != 0 || m == NULL) {
-				GRE_DPRINTF(sc, "%s: rc %d m %p\n",
-				    ifp->if_xname, rc, (void *)m);
-				continue;
-			} else
-				GRE_DPRINTF(sc, "%s: so_receive ok\n",
-				    __func__);
-			if (m->m_len < sizeof(*gh) &&
-			    (m = m_pullup(m, sizeof(*gh))) == NULL) {
-				GRE_DPRINTF(sc, "%s: m_pullup failed\n",
-				    __func__);
-				continue;
-			}
-			gh = mtod(m, const struct gre_h *);
+		sc->sc_haswork = 0;
+
+		GRE_DPRINTF(sc, "%s: awake\n", __func__);
 
-			if (gre_input3(sc, m, 0, IPPROTO_GRE, gh) == 0) {
-				GRE_DPRINTF(sc, "%s: dropping unsupported\n",
-				    __func__);
-				ifp->if_ierrors++;
-				m_freem(m);
-			}
+		/* XXX optimize */ 
+		if ((ifp->if_flags & IFF_UP) != IFF_UP ||
+		    sc->sc_proto != IPPROTO_UDP || so == NULL ||
+		    sc->sc_newsoparm.sp_fp != NULL ||
+		    memcmp(&sc->sc_soparm, &sc->sc_newsoparm,
+		           offsetof(struct gre_soparm, sp_fp)) != 0)
+			so = gre_reconf(sc, so, l);
+		mutex_exit(&sc->sc_mtx);
+		if (so != NULL) {
+			gre_do_recv(sc, so, l);
+			gre_do_send(sc, so, l);
 		}
-		for (;;) {
-			IF_DEQUEUE(&sc->sc_snd, m);
-			if (m == NULL)
-				break;
-			GRE_DPRINTF(sc, "%s: dequeue\n", __func__);
-			if ((so->so_state & SS_ISCONNECTED) == 0) {
-				GRE_DPRINTF(sc, "%s: not connected\n",
-				    __func__);
-				m_freem(m);
-				continue;
-			}
-			rc = (*so->so_send)(so, NULL, NULL, m, NULL, 0, l);
-			/* XXX handle ENOBUFS? */
-			if (rc != 0)
-				GRE_DPRINTF(sc, "%s: so_send failed\n",
-				    __func__);
-		}
-		/* Give the software interrupt queues a chance to
-		 * run, or else when I send a ping from gre0 to gre1 on
-		 * the same host, gre0 will not wake for the reply.
-		 */
-		splx(s);
-		s = splnet();
+		mutex_enter(&sc->sc_mtx);
 	}
-	if (sp.sp_fp != NULL) {
-		GRE_DPRINTF(sc, "%s: removing upcall\n", __func__);
-		gre_upcall_remove(so);
-		FILE_UNUSE(sp.sp_fp, NULL);
-		sp.sp_fp = NULL;
-	} else if (so != NULL)
-		gre_sodestroy(&so);
-out:
-	GRE_DPRINTF(sc, "%s: stopping\n", __func__);
-	if (sc->sc_proto == IPPROTO_UDP)
-		ifp->if_flags &= ~IFF_RUNNING;
-	while (!IF_IS_EMPTY(&sc->sc_snd)) {
-		IF_DEQUEUE(&sc->sc_snd, m);
-		m_freem(m);
-	}
-	gre_stop(&sc->sc_thread);
-	/* must not touch sc after this! */
-	GRE_DPRINTF(sc, "%s: restore ipl\n", __func__);
-	splx(s);
+	sc->sc_running = 0;
+	cv_signal(&sc->sc_join_cv);
 }
 
 static void
@@ -496,75 +499,75 @@
 {
 	struct gre_softc *sc = (struct gre_softc *)arg;
 
+	mutex_enter(&sc->sc_mtx);
 	gre_thread1(sc, curlwp);
+	mutex_exit(&sc->sc_mtx);
+
 	/* must not touch sc after this! */
 	kthread_exit(0);
 }
 
+/* Calling thread must hold sc->sc_mtx. */
 int
-gre_input3(struct gre_softc *sc, struct mbuf *m, int hlen, u_char proto,
-    const struct gre_h *gh)
+gre_input3(struct gre_softc *sc, struct mbuf *m, int hlen,
+    const struct gre_h *gh, int mtx_held)
 {
 	u_int16_t flags;
 #if NBPFILTER > 0
 	u_int32_t af = AF_INET;		/* af passed to BPF tap */
 #endif
-	int s, isr;
+	int isr;
 	struct ifqueue *ifq;
 
 	sc->sc_if.if_ipackets++;
 	sc->sc_if.if_ibytes += m->m_pkthdr.len;
 
-	switch (proto) {
-	case IPPROTO_GRE:
-		hlen += sizeof(struct gre_h);
+	hlen += sizeof(struct gre_h);
 
-		/* process GRE flags as packet can be of variable len */
-		flags = ntohs(gh->flags);
+	/* process GRE flags as packet can be of variable len */
+	flags = ntohs(gh->flags);
 
-		/* Checksum & Offset are present */
-		if ((flags & GRE_CP) | (flags & GRE_RP))
-			hlen += 4;
-		/* We don't support routing fields (variable length) */
-		if (flags & GRE_RP)
-			return 0;
-		if (flags & GRE_KP)
-			hlen += 4;
-		if (flags & GRE_SP)
-			hlen += 4;
+	/* Checksum & Offset are present */
+	if ((flags & GRE_CP) | (flags & GRE_RP))
+		hlen += 4;
+	/* We don't support routing fields (variable length) */
+	if (flags & GRE_RP) {
+		sc->sc_if.if_ierrors++;
+		return 0;
+	}
+	if (flags & GRE_KP)
+		hlen += 4;
+	if (flags & GRE_SP)
+		hlen += 4;
 
-		switch (ntohs(gh->ptype)) { /* ethertypes */
-		case ETHERTYPE_IP: /* shouldn't need a schednetisr(), as */
-			ifq = &ipintrq;          /* we are in ip_input */
-			isr = NETISR_IP;
-			break;
+	switch (ntohs(gh->ptype)) { /* ethertypes */
+	case ETHERTYPE_IP: /* shouldn't need a schednetisr(), as */
+		ifq = &ipintrq;          /* we are in ip_input */
+		isr = NETISR_IP;
+		break;
 #ifdef NETATALK
-		case ETHERTYPE_ATALK:
-			ifq = &atintrq1;
-			isr = NETISR_ATALK;
+	case ETHERTYPE_ATALK:
+		ifq = &atintrq1;
+		isr = NETISR_ATALK;
 #if NBPFILTER > 0
-			af = AF_APPLETALK;
+		af = AF_APPLETALK;
 #endif
-			break;
+		break;
 #endif
 #ifdef INET6
-		case ETHERTYPE_IPV6:
-			GRE_DPRINTF(sc, "%s: IPv6 packet\n", __func__);
-			ifq = &ip6intrq;
-			isr = NETISR_IPV6;
+	case ETHERTYPE_IPV6:
+		GRE_DPRINTF(sc, "%s: IPv6 packet\n", __func__);
+		ifq = &ip6intrq;
+		isr = NETISR_IPV6;
 #if NBPFILTER > 0
-			af = AF_INET6;
-#endif
-			break;
+		af = AF_INET6;
 #endif
-		default:	   /* others not yet supported */
-			printf("%s: unhandled ethertype 0x%04x\n", __func__,
-			    ntohs(gh->ptype));
-			return 0;
-		}
 		break;
-	default:
-		/* others not yet supported */
+#endif
+	default:	   /* others not yet supported */
+		GRE_DPRINTF(sc, "%s: unhandled ethertype 0x%04x\n", __func__,
+		    ntohs(gh->ptype));
+		sc->sc_if.if_noproto++;
 		return 0;
 	}
 
@@ -582,7 +585,8 @@
 
 	m->m_pkthdr.rcvif = &sc->sc_if;
 
-	s = splnet();		/* possible */
+	if (!mtx_held)
+		mutex_enter(&sc->sc_mtx);
 	if (IF_QFULL(ifq)) {
 		IF_DROP(ifq);
 		m_freem(m);
@@ -591,7 +595,8 @@
 	}
 	/* we need schednetisr since the address family may change */
 	schednetisr(isr);
-	splx(s);
+	if (!mtx_held)
+		mutex_exit(&sc->sc_mtx);
 
 	return 1;	/* packet is done, no further processing needed */
 }
@@ -604,7 +609,7 @@
 gre_output(struct ifnet *ifp, struct mbuf *m, const struct sockaddr *dst,
 	   struct rtentry *rt)
 {
-	int error = 0, hlen;
+	int error = 0, hlen, msiz;
 	struct gre_softc *sc = ifp->if_softc;
 	struct greip *gi;
 	struct gre_h *gh;
@@ -613,8 +618,10 @@
 	u_int16_t etype = 0;
 	struct mobile_h mob_h;
 
-	if ((ifp->if_flags & (IFF_UP | IFF_RUNNING)) == 0 ||
-	    sc->g_src.s_addr == INADDR_ANY || sc->g_dst.s_addr == INADDR_ANY) {
+	if ((ifp->if_flags & (IFF_UP | IFF_RUNNING)) !=
+	    (IFF_UP | IFF_RUNNING) ||
+	    sc->sc_src.s_addr == INADDR_ANY ||
+	    sc->sc_dst.s_addr == INADDR_ANY) {
 		m_freem(m);
 		error = ENETDOWN;
 		goto end;
@@ -632,56 +639,54 @@
 
 	switch (sc->sc_proto) {
 	case IPPROTO_MOBILE:
-		if (dst->sa_family == AF_INET) {
-			int msiz;
-
-			if (M_UNWRITABLE(m, sizeof(*ip)) &&
-			    (m = m_pullup(m, sizeof(*ip))) == NULL) {
-				error = ENOBUFS;
-				goto end;
-			}
-			ip = mtod(m, struct ip *);
-
-			memset(&mob_h, 0, MOB_H_SIZ_L);
-			mob_h.proto = (ip->ip_p) << 8;
-			mob_h.odst = ip->ip_dst.s_addr;
-			ip->ip_dst.s_addr = sc->g_dst.s_addr;
-
-			/*
-			 * If the packet comes from our host, we only change
-			 * the destination address in the IP header.
-			 * Else we also need to save and change the source
-			 */
-			if (in_hosteq(ip->ip_src, sc->g_src)) {
-				msiz = MOB_H_SIZ_S;
-			} else {
-				mob_h.proto |= MOB_H_SBIT;
-				mob_h.osrc = ip->ip_src.s_addr;
-				ip->ip_src.s_addr = sc->g_src.s_addr;
-				msiz = MOB_H_SIZ_L;
-			}
-			HTONS(mob_h.proto);
-			mob_h.hcrc = gre_in_cksum((u_int16_t *)&mob_h, msiz);
-
-			M_PREPEND(m, msiz, M_DONTWAIT);
-			if (m == NULL) {
-				error = ENOBUFS;
-				goto end;
-			}
-			/* XXX Assuming that ip does not dangle after
-			 * M_PREPEND.  In practice, that's true, but
-			 * that's in M_PREPEND's contract.
-			 */
-			memmove(mtod(m, caddr_t), ip, sizeof(*ip));
-			ip = mtod(m, struct ip *);
-			memcpy((caddr_t)(ip + 1), &mob_h, (unsigned)msiz);
-			ip->ip_len = htons(ntohs(ip->ip_len) + msiz);
-		} else {  /* AF_INET */
+		if (dst->sa_family != AF_INET) {
 			IF_DROP(&ifp->if_snd);
 			m_freem(m);
 			error = EINVAL;
 			goto end;
 		}
+
+		if (M_UNWRITABLE(m, sizeof(*ip)) &&
+		    (m = m_pullup(m, sizeof(*ip))) == NULL) {
+			error = ENOBUFS;
+			goto end;
+		}
+		ip = mtod(m, struct ip *);
+
+		memset(&mob_h, 0, MOB_H_SIZ_L);
+		mob_h.proto = (ip->ip_p) << 8;
+		mob_h.odst = ip->ip_dst.s_addr;
+		ip->ip_dst.s_addr = sc->sc_dst.s_addr;
+
+		/*
+		 * If the packet comes from our host, we only change
+		 * the destination address in the IP header.
+		 * Else we also need to save and change the source
+		 */
+		if (in_hosteq(ip->ip_src, sc->sc_src))
+			msiz = MOB_H_SIZ_S;
+		else {
+			mob_h.proto |= MOB_H_SBIT;
+			mob_h.osrc = ip->ip_src.s_addr;
+			ip->ip_src.s_addr = sc->sc_src.s_addr;
+			msiz = MOB_H_SIZ_L;
+		}
+		HTONS(mob_h.proto);
+		mob_h.hcrc = gre_in_cksum((u_int16_t *)&mob_h, msiz);
+
+		M_PREPEND(m, msiz, M_DONTWAIT);
+		if (m == NULL) {
+			error = ENOBUFS;
+			goto end;
+		}
+		/* XXX Assuming that ip does not dangle after
+		 * M_PREPEND.  In practice, that's true, but
+		 * that's not in M_PREPEND's contract.
+		 */
+		memmove(mtod(m, void *), ip, sizeof(*ip));
+		ip = mtod(m, struct ip *);
+		memcpy(ip + 1, &mob_h, (size_t)msiz);
+		ip->ip_len = htons(ntohs(ip->ip_len) + msiz);
 		break;
 	case IPPROTO_UDP:
 	case IPPROTO_GRE:
@@ -751,8 +756,8 @@
 		/* we don't have any GRE flags for now */
 		memset(gh, 0, sizeof(*gh));
 		gh->ptype = htons(etype);
-		eip->ip_src = sc->g_src;
-		eip->ip_dst = sc->g_dst;
+		eip->ip_src = sc->sc_src;
+		eip->ip_dst = sc->sc_dst;
 		eip->ip_hl = (sizeof(struct ip)) >> 2;
 		eip->ip_ttl = ip_gre_ttl;
 		eip->ip_tos = ip_tos;
@@ -789,67 +794,53 @@
 		rtcache_init(&sc->route);
 	else
 		rtcache_check(&sc->route);
-	if (sc->route.ro_rt == NULL)
+	if (sc->route.ro_rt == NULL) {
+		m_freem(m);
 		goto end;
-	if (sc->route.ro_rt->rt_ifp->if_softc == sc)
-		rtcache_free(&sc->route);
-	else
-		error = ip_output(m, NULL, &sc->route, 0,
-		    (struct ip_moptions *)NULL, (struct socket *)NULL);
+	}
+	if (sc->route.ro_rt->rt_ifp->if_softc == sc) {
+		rtcache_clear(&sc->route);
+		m_freem(m);
+	} else
+		error = ip_output(m, NULL, &sc->route, 0, NULL, NULL);
   end:
 	if (error)
 		ifp->if_oerrors++;
 	return error;
 }
 
-/* gre_kick must be synchronized with network interrupts in order
- * to synchronize access to gre_softc members, so call it with
- * interrupt priority level set to IPL_NET or greater.
- */
+/* Calling thread must hold sc->sc_mtx. */
 static int
 gre_kick(struct gre_softc *sc)
 {
-	int rc;
-	struct ifnet *ifp = &sc->sc_if;
-
-	if (sc->sc_proto == IPPROTO_UDP && (ifp->if_flags & IFF_UP) == IFF_UP &&
-	    !sc->sc_thread) {
-		sc->sc_thread = 1;
-		rc = kthread_create1(gre_thread, (void *)sc, NULL,
-		    ifp->if_xname);
-		if (rc != 0)
-			gre_stop(&sc->sc_thread);
-		return rc;
-	} else {
-		gre_wakeup(sc);
-		return 0;
-	}
+	if (!sc->sc_running)
+		return EBUSY;
+	gre_wakeup(sc);
+	return 0;
 }
 
+/* Calling thread must hold sc->sc_mtx. */
 static int
 gre_getname(struct socket *so, int req, struct mbuf *nam, struct lwp *l)
 {
-	int s, error;
-
-	s = splsoftnet();
-	error = (*so->so_proto->pr_usrreq)(so, req, (struct mbuf *)0,
-	    nam, (struct mbuf *)0, l);
-	splx(s);
-	return error;
+	return (*so->so_proto->pr_usrreq)(so, req, NULL, nam, NULL, l);
 }
 
+/* Calling thread must hold sc->sc_mtx. */
 static int
 gre_getsockname(struct socket *so, struct mbuf *nam, struct lwp *l)
 {
 	return gre_getname(so, PRU_SOCKADDR, nam, l);
 }
 
+/* Calling thread must hold sc->sc_mtx. */
 static int
 gre_getpeername(struct socket *so, struct mbuf *nam, struct lwp *l)
 {
 	return gre_getname(so, PRU_PEERADDR, nam, l);
 }
 
+/* Calling thread must hold sc->sc_mtx. */
 static int
 gre_getnames(struct socket *so, struct lwp *l, struct sockaddr_in *src,
     struct sockaddr_in *dst)
@@ -884,23 +875,35 @@
 	return rc;
 }
 
+static void
+gre_closef(struct file **fpp, struct lwp *l)
+{
+	struct file *fp = *fpp;
+
+	simple_lock(&fp->f_slock);
+	FILE_USE(fp);
+	closef(fp, l);
+	*fpp = NULL;
+}
+
 static int
-gre_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
+gre_ioctl(struct ifnet *ifp, const u_long cmd, void *data)
 {
 	u_char oproto;
-	struct file *fp, *ofp;
+	struct file *fp;
 	struct socket *so;
 	struct sockaddr_in dst, src;
 	struct proc *p = curproc;	/* XXX */
 	struct lwp *l = curlwp;	/* XXX */
-	struct ifreq *ifr = (struct ifreq *)data;
+	struct ifreq *ifr;
 	struct if_laddrreq *lifr = (struct if_laddrreq *)data;
 	struct gre_softc *sc = ifp->if_softc;
-	int s;
 	struct sockaddr_in si;
-	struct sockaddr *sa = NULL;
+	const struct sockaddr *sa;
 	int error = 0;
 
+	ifr = data;
+
 	switch (cmd) {
 	case SIOCSIFFLAGS:
 	case SIOCSIFMTU:
@@ -920,7 +923,7 @@
 		break;
 	}
 
-	s = splnet();
+	mutex_enter(&sc->sc_mtx);
 	switch (cmd) {
 	case SIOCSIFADDR:
 		ifp->if_flags |= IFF_UP;
@@ -960,11 +963,11 @@
 		break;
 	case SIOCADDMULTI:
 	case SIOCDELMULTI:
-		if (ifr == 0) {
+		if (ifr == NULL) {
 			error = EAFNOSUPPORT;
 			break;
 		}
-		switch (ifr->ifr_addr.sa_family) {
+		switch (ifreq_getaddr(cmd, ifr)->sa_family) {
 #ifdef INET
 		case AF_INET:
 			break;
@@ -1011,29 +1014,29 @@
 		 */
 		sa = &ifr->ifr_addr;
 		if (cmd == GRESADDRS) {
-			sc->g_src = (satosin(sa))->sin_addr;
-			sc->g_srcport = satosin(sa)->sin_port;
+			sc->sc_src = satocsin(sa)->sin_addr;
+			sc->sc_srcport = satocsin(sa)->sin_port;
 		}
 		if (cmd == GRESADDRD) {
 			if (sc->sc_proto == IPPROTO_UDP &&
-			    satosin(sa)->sin_port == 0) {
+			    satocsin(sa)->sin_port == 0) {
 				error = EINVAL;
 				break;
 			}
-			sc->g_dst = (satosin(sa))->sin_addr;
-			sc->g_dstport = satosin(sa)->sin_port;
+			sc->sc_dst = satocsin(sa)->sin_addr;
+			sc->sc_dstport = satocsin(sa)->sin_port;
 		}
 	recompute:
 		if (sc->sc_proto == IPPROTO_UDP ||
-		    (sc->g_src.s_addr != INADDR_ANY &&
-		     sc->g_dst.s_addr != INADDR_ANY)) {
-			if (sc->sc_fp != NULL) {
-				closef(sc->sc_fp, l);
-				sc->sc_fp = NULL;
+		    (sc->sc_src.s_addr != INADDR_ANY &&
+		     sc->sc_dst.s_addr != INADDR_ANY)) {
+			rtcache_free(&sc->route);
+			if (sc->sc_proto == IPPROTO_UDP) {
+				if ((error = gre_kick(sc)) == 0)
+					ifp->if_flags |= IFF_RUNNING;
+				else
+					ifp->if_flags &= ~IFF_RUNNING;
 			}
-			rtcache_free(&sc->route);
-			if (sc->sc_proto == IPPROTO_UDP)
-				error = gre_kick(sc);
 			else if (gre_compute_route(sc) == 0)
 				ifp->if_flags |= IFF_RUNNING;
 			else
@@ -1041,63 +1044,89 @@
 		}
 		break;
 	case GREGADDRS:
-		memset(&si, 0, sizeof(si));
-		si.sin_family = AF_INET;
-		si.sin_len = sizeof(struct sockaddr_in);
-		si.sin_addr.s_addr = sc->g_src.s_addr;
-		sa = sintosa(&si);
-		ifr->ifr_addr = *sa;
+		sockaddr_in_init(&si, &sc->sc_src,
+		    (sc->sc_proto == IPPROTO_UDP) ? sc->sc_srcport : 0);
+		ifr->ifr_addr = *sintosa(&si);
 		break;
 	case GREGADDRD:
-		memset(&si, 0, sizeof(si));
-		si.sin_family = AF_INET;
-		si.sin_len = sizeof(struct sockaddr_in);
-		si.sin_addr.s_addr = sc->g_dst.s_addr;
-		sa = sintosa(&si);
-		ifr->ifr_addr = *sa;
+		sockaddr_in_init(&si, &sc->sc_dst,
+		    (sc->sc_proto == IPPROTO_UDP) ? sc->sc_dstport : 0);
+		ifr->ifr_addr = *sintosa(&si);
 		break;
 	case GREDSOCK:
-		if (sc->sc_proto != IPPROTO_UDP)
-			return EINVAL;
-		if (sc->sc_fp != NULL) {
-			closef(sc->sc_fp, l);
-			sc->sc_fp = NULL;
-			error = gre_kick(sc);
+		if (sc->sc_proto != IPPROTO_UDP) {
+			error = EINVAL;
+			break;
 		}
+		ifp->if_flags &= ~IFF_UP;
+		gre_wakeup(sc);
 		break;
 	case GRESSOCK:
-		if (sc->sc_proto != IPPROTO_UDP)
-			return EINVAL;
-		/* getsock() will FILE_USE() the descriptor for us */
-		if ((error = getsock(p->p_fd, (int)ifr->ifr_value, &fp)) != 0)
+		if (sc->sc_proto != IPPROTO_UDP) {
+			GRE_DPRINTF(sc, "%s: l.%d\n", __func__, __LINE__);
+			error = EINVAL;
 			break;
+		}
+		/* getsock() will FILE_USE() and unlock the descriptor for us */
+		if ((error = getsock(p->p_fd, (int)ifr->ifr_value, &fp)) != 0) {
+			GRE_DPRINTF(sc, "%s: l.%d\n", __func__, __LINE__);
+			error = EINVAL;
+			break;
+		}
 		so = (struct socket *)fp->f_data;
 		if (so->so_type != SOCK_DGRAM) {
+			GRE_DPRINTF(sc, "%s: l.%d\n", __func__, __LINE__);
 			FILE_UNUSE(fp, NULL);
 			error = EINVAL;
 			break;
 		}
 		/* check address */
 		if ((error = gre_getnames(so, curlwp, &src, &dst)) != 0) {
+			GRE_DPRINTF(sc, "%s: l.%d\n", __func__, __LINE__);
 			FILE_UNUSE(fp, NULL);
 			break;
 		}
 
+                /* Increase reference count.  Now that our reference
+                 * to the file descriptor is counted, this thread
+                 * can release our "use" of the descriptor, but it
+                 * will not be destroyed by some other thread's
+                 * action.  This thread needs to release its use,
+                 * too, because one and only one thread can have
+                 * use of the descriptor at once.  The kernel thread
+                 * will pick up the use if it needs it.
+		 */
+
 		fp->f_count++;
+		GRE_DPRINTF(sc, "%s: l.%d f_count %d\n", __func__, __LINE__,
+		    fp->f_count);
+		FILE_UNUSE(fp, NULL);
 
-		ofp = sc->sc_fp;
-		sc->sc_fp = fp;
-		if ((error = gre_kick(sc)) != 0) {
-			closef(fp, l);
-			sc->sc_fp = ofp;
+		while (sc->sc_newsoparm.sp_fp != NULL && error == 0) {
+			GRE_DPRINTF(sc, "%s: l.%d\n", __func__, __LINE__);
+			error = cv_timedwait_sig(&sc->sc_soparm_cv, &sc->sc_mtx,
+					         MAX(1, hz / 2));
+		}
+		if (error == 0) {
+			GRE_DPRINTF(sc, "%s: l.%d\n", __func__, __LINE__);
+			sc->sc_newsoparm.sp_fp = fp;
+			ifp->if_flags |= IFF_UP;
+		}
+
+		if (error != 0 || (error = gre_kick(sc)) != 0) {
+			GRE_DPRINTF(sc, "%s: l.%d\n", __func__, __LINE__);
+			gre_closef(&fp, l);
 			break;
 		}
-		sc->g_src = src.sin_addr;
-		sc->g_srcport = src.sin_port;
-		sc->g_dst = dst.sin_addr;
-		sc->g_dstport = dst.sin_port;
-		if (ofp != NULL)
-			closef(ofp, l);
+		/* fp does not any longer belong to this thread. */
+		sc->sc_src = src.sin_addr;
+		sc->sc_srcport = src.sin_port;
+		sc->sc_dst = dst.sin_addr;
+		sc->sc_dstport = dst.sin_port;
+		GRE_DPRINTF(sc, "%s: sock 0x%08" PRIx32 " port %d -> "
+		    "0x%08" PRIx32 " port %d\n", __func__,
+		    src.sin_addr.s_addr, ntohs(src.sin_port),
+		    dst.sin_addr.s_addr, ntohs(dst.sin_port));
 		break;
 	case SIOCSLIFPHYADDR:
 		if (lifr->addr.ss_family != AF_INET ||
@@ -1110,40 +1139,33 @@
 			error = EINVAL;
 			break;
 		}
-		sc->g_src = satosin(&lifr->addr)->sin_addr;
-		sc->g_dst = satosin(&lifr->dstaddr)->sin_addr;
-		sc->g_srcport = satosin(&lifr->addr)->sin_port;
-		sc->g_dstport = satosin(&lifr->dstaddr)->sin_port;
+		sc->sc_src = satocsin(&lifr->addr)->sin_addr;
+		sc->sc_dst = satocsin(&lifr->dstaddr)->sin_addr;
+		sc->sc_srcport = satocsin(&lifr->addr)->sin_port;
+		sc->sc_dstport = satocsin(&lifr->dstaddr)->sin_port;
 		goto recompute;
 	case SIOCDIFPHYADDR:
-		sc->g_src.s_addr = INADDR_ANY;
-		sc->g_dst.s_addr = INADDR_ANY;
-		sc->g_srcport = 0;
-		sc->g_dstport = 0;
+		sc->sc_src.s_addr = INADDR_ANY;
+		sc->sc_dst.s_addr = INADDR_ANY;
+		sc->sc_srcport = 0;
+		sc->sc_dstport = 0;
 		goto recompute;
 	case SIOCGLIFPHYADDR:
-		if (sc->g_src.s_addr == INADDR_ANY ||
-		    sc->g_dst.s_addr == INADDR_ANY) {
+		if (sc->sc_src.s_addr == INADDR_ANY ||
+		    sc->sc_dst.s_addr == INADDR_ANY) {
 			error = EADDRNOTAVAIL;
 			break;
 		}
-		memset(&si, 0, sizeof(si));
-		si.sin_family = AF_INET;
-		si.sin_len = sizeof(struct sockaddr_in);
-		si.sin_addr = sc->g_src;
-		if (sc->sc_proto == IPPROTO_UDP)
-			si.sin_port = sc->g_srcport;
-		memcpy(&lifr->addr, &si, sizeof(si));
-		si.sin_addr = sc->g_dst;
-		if (sc->sc_proto == IPPROTO_UDP)
-			si.sin_port = sc->g_dstport;
-		memcpy(&lifr->dstaddr, &si, sizeof(si));
+		sockaddr_in_init(satosin(&lifr->addr), &sc->sc_src,
+		    (sc->sc_proto == IPPROTO_UDP) ? sc->sc_srcport : 0);
+		sockaddr_in_init(satosin(&lifr->dstaddr), &sc->sc_dst,
+		    (sc->sc_proto == IPPROTO_UDP) ? sc->sc_dstport : 0);
 		break;
 	default:
 		error = EINVAL;
 		break;
 	}
-	splx(s);
+	mutex_exit(&sc->sc_mtx);
 	return error;
 }
 
@@ -1154,28 +1176,25 @@
 gre_compute_route(struct gre_softc *sc)
 {
 	struct route *ro;
+	union {
+		struct sockaddr		dst;
+		struct sockaddr_in	dst4;
+	} u;
 
 	ro = &sc->route;
 
-	memset(ro, 0, sizeof(struct route));
-	satosin(&ro->ro_dst)->sin_addr = sc->g_dst;
-	ro->ro_dst.sa_family = AF_INET;
-	ro->ro_dst.sa_len = sizeof(ro->ro_dst);
-
-#ifdef DIAGNOSTIC
-	printf("%s: searching for a route to %s", sc->sc_if.if_xname,
-	    inet_ntoa(satocsin(rtcache_getdst(ro))->sin_addr));
-#endif
+	memset(ro, 0, sizeof(*ro));
+	sockaddr_in_init(&u.dst4, &sc->sc_dst, 0);
+	rtcache_setdst(ro, &u.dst);
 
 	rtcache_init(ro);
 
 	if (ro->ro_rt == NULL || ro->ro_rt->rt_ifp->if_softc == sc) {
-#ifdef DIAGNOSTIC
-		if (ro->ro_rt == NULL)
-			printf(" - no route found!\n");
-		else
-			printf(" - route loops back to ourself!\n");
-#endif
+		GRE_DPRINTF(sc, "%s: route to %s %s\n", sc->sc_if.if_xname,
+		    inet_ntoa(u.dst4.sin_addr),
+		    (ro->ro_rt == NULL)
+		        ?  "does not exist"
+			: "loops back to ourself");
 		rtcache_free(ro);
 		return EADDRNOTAVAIL;
 	}
--- a/sys/net/if_gre.h	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/if_gre.h	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_gre.h,v 1.14.4.3 2007/02/26 09:11:34 yamt Exp $ */
+/*	$NetBSD: if_gre.h,v 1.14.4.4 2007/09/03 14:42:07 yamt Exp $ */
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -40,6 +40,8 @@
 #define _NET_IF_GRE_H_
 
 #include <sys/queue.h>
+#include <sys/mutex.h>
+#include <sys/condvar.h>
 
 #ifdef _KERNEL
 struct gre_soparm {
@@ -52,20 +54,27 @@
 
 struct gre_softc {
 	struct ifnet		sc_if;
-	volatile int		sc_waitchan;
-	volatile int		sc_thread;
+	kmutex_t		sc_mtx;
+	kcondvar_t		sc_soparm_cv;
+	kcondvar_t		sc_join_cv;
+	kcondvar_t		sc_work_cv;
+	int			sc_haswork;
+	int			sc_running;
+	int			sc_dying;
 	struct ifqueue		sc_snd;
 	struct gre_soparm	sc_soparm;
+	struct gre_soparm	sc_newsoparm;
 	LIST_ENTRY(gre_softc)	sc_list;
-	struct route route;	/* routing entry that determines, where a
+	struct route route;	/* routing entry that determines where a
 				   encapsulated packet should go */
 	int			sc_proto;	/* protocol of encapsulator */
+	struct uio		sc_uio;
 };
-#define	g_src		sc_soparm.sp_src
-#define	g_srcport	sc_soparm.sp_srcport
-#define	g_dst		sc_soparm.sp_dst
-#define	g_dstport	sc_soparm.sp_dstport
-#define	sc_fp		sc_soparm.sp_fp
+
+#define	sc_src		sc_newsoparm.sp_src
+#define	sc_srcport	sc_newsoparm.sp_srcport
+#define	sc_dst		sc_newsoparm.sp_dst
+#define	sc_dstport	sc_newsoparm.sp_dstport
 
 struct gre_h {
 	u_int16_t flags;	/* GRE flags */
@@ -163,8 +172,8 @@
 extern struct gre_softc_head gre_softc_list;
 
 u_int16_t gre_in_cksum(u_short *, u_int);
-int gre_input3(struct gre_softc *, struct mbuf *, int, u_char,
-    const struct gre_h *);
+int gre_input3(struct gre_softc *, struct mbuf *, int, const struct gre_h *,
+    int);
 #endif /* _KERNEL */
 
 #endif /* !_NET_IF_GRE_H_ */
--- a/sys/net/if_hippi.h	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/if_hippi.h	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_hippi.h,v 1.7.4.1 2006/06/21 15:10:27 yamt Exp $	*/
+/*	$NetBSD: if_hippi.h,v 1.7.4.2 2007/09/03 14:42:07 yamt Exp $	*/
 
 /*
  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -81,7 +81,7 @@
 
 
 #ifdef _KERNEL
-void    hippi_ifattach(struct ifnet *, caddr_t);
+void    hippi_ifattach(struct ifnet *, void *);
 void    hippi_ip_input(struct ifnet *, struct mbuf *);
 #endif /* _KERNEL */
 #endif /* !_NET_IF_HIPPI_H_ */
--- a/sys/net/if_hippisubr.c	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/if_hippisubr.c	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_hippisubr.c,v 1.20.2.2 2007/02/26 09:11:34 yamt Exp $	*/
+/*	$NetBSD: if_hippisubr.c,v 1.20.2.3 2007/09/03 14:42:08 yamt Exp $	*/
 
 /*
  * Copyright (c) 1982, 1989, 1993
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_hippisubr.c,v 1.20.2.2 2007/02/26 09:11:34 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_hippisubr.c,v 1.20.2.3 2007/09/03 14:42:08 yamt Exp $");
 
 #include "opt_inet.h"
 
@@ -69,8 +69,6 @@
 
 #define senderr(e) { error = (e); goto bad;}
 
-#define SDL(x) ((const struct sockaddr_dl *)x)
-
 #ifndef llc_snap
 #define	llc_snap	llc_un.type_snap
 #endif
@@ -151,9 +149,9 @@
 	case AF_INET:
 		if (rt) {
 			const struct sockaddr_dl *sdl =
-				(const struct sockaddr_dl *)SDL(rt->rt_gateway);
+			    satocsdl(rt->rt_gateway);
 			if (sdl->sdl_family == AF_LINK && sdl->sdl_alen != 0)
-				bcopy(CLLADDR(sdl), &ifield, sizeof(ifield));
+				memcpy(&ifield, CLLADDR(sdl), sizeof(ifield));
 		}
 		if (!ifield)  /* XXX:  bogus check, but helps us get going */
 			senderr(EHOSTUNREACH);
@@ -165,9 +163,9 @@
 	case AF_INET6:
 		if (rt) {
 			const struct sockaddr_dl *sdl =
-				(const struct sockaddr_dl *)SDL(rt->rt_gateway);
+			    satocsdl(rt->rt_gateway);
 			if (sdl->sdl_family == AF_LINK && sdl->sdl_alen != 0)
-				bcopy(CLLADDR(sdl), &ifield, sizeof(ifield));
+				memcpy(&ifield, CLLADDR(sdl), sizeof(ifield));
 		}
 		if (!ifield)  /* XXX:  bogus check, but helps us get going */
 			senderr(EHOSTUNREACH);
@@ -191,7 +189,7 @@
 		l->llc_dsap = l->llc_ssap = LLC_SNAP_LSAP;
 		l->llc_snap.org_code[0] = l->llc_snap.org_code[1] =
 			l->llc_snap.org_code[2] = 0;
-		bcopy((caddr_t) &htype, (caddr_t) &l->llc_snap.ether_type,
+		bcopy((void *) &htype, (void *) &l->llc_snap.ether_type,
 		      sizeof(u_int16_t));
 	}
 
@@ -219,7 +217,7 @@
 
 	if (d2_len % 8 != 0) {
 		static u_int32_t buffer[2] = {0, 0};
-		m_copyback(m, m->m_pkthdr.len, 8 - d2_len % 8, (caddr_t) buffer);
+		m_copyback(m, m->m_pkthdr.len, 8 - d2_len % 8, (void *) buffer);
 	}
 
 	return ifq_enqueue(ifp, m ALTQ_COMMA ALTQ_DECL(&pktattr));
@@ -330,7 +328,7 @@
  * Perform common duties while attaching to interface list
  */
 void
-hippi_ifattach(struct ifnet *ifp, caddr_t lla)
+hippi_ifattach(struct ifnet *ifp, void *lla)
 {
 
 	ifp->if_type = IFT_HIPPI;
@@ -343,7 +341,8 @@
 	ifp->if_baudrate = IF_Mbps(800);	/* XXX double-check */
 
 	if_alloc_sadl(ifp);
-	memcpy(LLADDR(ifp->if_sadl), lla, ifp->if_addrlen);
+	sockaddr_dl_setaddr(ifp->if_sadl, ifp->if_sadl->sdl_len, lla,
+	    ifp->if_addrlen);
 
 #if NBPFILTER > 0
 	bpfattach(ifp, DLT_HIPPI, sizeof(struct hippi_header));
--- a/sys/net/if_ieee1394.h	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/if_ieee1394.h	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ieee1394.h,v 1.3.42.1 2006/06/21 15:10:27 yamt Exp $	*/
+/*	$NetBSD: if_ieee1394.h,v 1.3.42.2 2007/09/03 14:42:08 yamt Exp $	*/
 
 /*
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -118,7 +118,7 @@
 void ieee1394_input(struct ifnet *, struct mbuf *, u_int16_t);
 void ieee1394_ifattach(struct ifnet *, const struct ieee1394_hwaddr *);
 void ieee1394_ifdetach(struct ifnet *);
-int  ieee1394_ioctl(struct ifnet *, u_long, caddr_t);
+int  ieee1394_ioctl(struct ifnet *, u_long, void *);
 struct mbuf * ieee1394_fragment(struct ifnet *, struct mbuf *, int, u_int16_t);
 void ieee1394_drain(struct ifnet *);
 void ieee1394_watchdog(struct ifnet *);
--- a/sys/net/if_ieee1394subr.c	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/if_ieee1394subr.c	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ieee1394subr.c,v 1.28.10.2 2007/02/26 09:11:34 yamt Exp $	*/
+/*	$NetBSD: if_ieee1394subr.c,v 1.28.10.3 2007/09/03 14:42:08 yamt Exp $	*/
 
 /*
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_ieee1394subr.c,v 1.28.10.2 2007/02/26 09:11:34 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ieee1394subr.c,v 1.28.10.3 2007/09/03 14:42:08 yamt Exp $");
 
 #include "opt_inet.h"
 #include "bpfilter.h"
@@ -98,7 +98,8 @@
 	int s, hdrlen, error = 0;
 	struct rtentry *rt;
 	struct mbuf *mcopy = NULL;
-	struct ieee1394_hwaddr *hwdst, *myaddr, baddr;
+	struct ieee1394_hwaddr *hwdst, baddr;
+	const struct ieee1394_hwaddr *myaddr;
 	ALTQ_DECL(struct altq_pktattr pktattr;)
 #ifdef INET
 	struct arphdr *ah;
@@ -215,7 +216,7 @@
 
 	if (mcopy)
 		looutput(ifp, mcopy, dst, rt);
-	myaddr = (struct ieee1394_hwaddr *)LLADDR(ifp->if_sadl);
+	myaddr = (const struct ieee1394_hwaddr *)CLLADDR(ifp->if_sadl);
 #if NBPFILTER > 0
 	if (ifp->if_bpf) {
 		struct ieee1394_bpfhdr h;
@@ -395,7 +396,7 @@
 	if (ifp->if_bpf) {
 		struct ieee1394_bpfhdr h;
 		struct m_tag *mtag;
-		struct ieee1394_hwaddr *myaddr;
+		const struct ieee1394_hwaddr *myaddr;
 
 		mtag = m_tag_locate(m,
 		    MTAG_FIREWIRE, MTAG_FIREWIRE_SENDER_EUID, 0);
@@ -408,7 +409,8 @@
 			    ((const struct ieee1394_hwaddr *)
 			    ifp->if_broadcastaddr)->iha_uid, 8);
 		else {
-			myaddr = (struct ieee1394_hwaddr *)LLADDR(ifp->if_sadl);
+			myaddr =
+			  (const struct ieee1394_hwaddr *)CLLADDR(ifp->if_sadl);
 			memcpy(h.ibh_dhost, myaddr->iha_uid, 8);
 		}
 		h.ibh_type = htons(etype);
@@ -692,7 +694,8 @@
 		ifp->if_baudrate = IF_Mbps(100);
 
 	if_alloc_sadl(ifp);
-	memcpy(LLADDR(ifp->if_sadl), hwaddr, ifp->if_addrlen);
+	(void)sockaddr_dl_setaddr(ifp->if_sadl, ifp->if_sadl->sdl_len,
+	    hwaddr, ifp->if_addrlen);
 
 	baddr = malloc(ifp->if_addrlen, M_DEVBUF, M_WAITOK);
 	memset(baddr->iha_uid, 0xff, IEEE1394_ADDR_LEN);
@@ -722,7 +725,7 @@
 }
 
 int
-ieee1394_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
+ieee1394_ioctl(struct ifnet *ifp, u_long cmd, void *data)
 {
 	struct ifreq *ifr = (struct ifreq *)data;
 	struct ifaddr *ifa = (struct ifaddr *)data;
@@ -759,7 +762,7 @@
 
 	case SIOCGIFADDR:
 		memcpy(((struct sockaddr *)&ifr->ifr_data)->sa_data,
-		    LLADDR(ifp->if_sadl), IEEE1394_ADDR_LEN);
+		    CLLADDR(ifp->if_sadl), IEEE1394_ADDR_LEN);
 		    break;
 
 	case SIOCSIFMTU:
--- a/sys/net/if_loop.c	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/if_loop.c	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_loop.c,v 1.55.4.3 2007/02/26 09:11:35 yamt Exp $	*/
+/*	$NetBSD: if_loop.c,v 1.55.4.4 2007/09/03 14:42:09 yamt Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -65,7 +65,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_loop.c,v 1.55.4.3 2007/02/26 09:11:35 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_loop.c,v 1.55.4.4 2007/09/03 14:42:09 yamt Exp $");
 
 #include "opt_inet.h"
 #include "opt_atalk.h"
@@ -410,7 +410,7 @@
  */
 /* ARGSUSED */
 int
-loioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
+loioctl(struct ifnet *ifp, u_long cmd, void *data)
 {
 	struct ifaddr *ifa;
 	struct ifreq *ifr;
@@ -445,7 +445,7 @@
 			error = EAFNOSUPPORT;		/* XXX */
 			break;
 		}
-		switch (ifr->ifr_addr.sa_family) {
+		switch (ifreq_getaddr(cmd, ifr)->sa_family) {
 
 #ifdef INET
 		case AF_INET:
--- a/sys/net/if_media.c	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/if_media.c	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_media.c,v 1.24 2005/02/26 22:45:09 perry Exp $	*/
+/*	$NetBSD: if_media.c,v 1.24.4.1 2007/09/03 14:42:09 yamt Exp $	*/
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -83,7 +83,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_media.c,v 1.24 2005/02/26 22:45:09 perry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_media.c,v 1.24.4.1 2007/09/03 14:42:09 yamt Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -234,12 +234,20 @@
 	struct ifmedia_entry *match;
 	struct ifmediareq *ifmr = (struct ifmediareq *) ifr;
 	int error = 0;
+#ifdef OSIOCSIFMEDIA
+	struct oifreq *oifr = (struct oifreq *)ifr;
+#endif
 
 	if (ifp == NULL || ifr == NULL || ifm == NULL)
 		return (EINVAL);
 
 	switch (cmd) {
 
+#ifdef OSIOCSIFMEDIA
+	case OSIOCSIFMEDIA:
+		ifr->ifr_media = oifr->ifr_media;
+		/*FALLTHROUGH*/
+#endif
 	/*
 	 * Set the current media.
 	 */
--- a/sys/net/if_ppp.c	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/if_ppp.c	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ppp.c,v 1.101.2.3 2007/02/26 09:11:35 yamt Exp $	*/
+/*	$NetBSD: if_ppp.c,v 1.101.2.4 2007/09/03 14:42:09 yamt Exp $	*/
 /*	Id: if_ppp.c,v 1.6 1997/03/04 03:33:00 paulus Exp 	*/
 
 /*
@@ -102,7 +102,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_ppp.c,v 1.101.2.3 2007/02/26 09:11:35 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ppp.c,v 1.101.2.4 2007/09/03 14:42:09 yamt Exp $");
 
 #include "ppp.h"
 
@@ -167,7 +167,7 @@
 #include <net/ppp-comp.h>
 #endif
 
-static int	pppsioctl(struct ifnet *, u_long, caddr_t);
+static int	pppsioctl(struct ifnet *, u_long, void *);
 static void	ppp_requeue(struct ppp_softc *);
 static void	ppp_ccp(struct ppp_softc *, struct mbuf *m, int rcvd);
 static void	ppp_ccp_closed(struct ppp_softc *);
@@ -177,9 +177,6 @@
 static void	ppp_ifstart(struct ifnet *ifp);
 #endif
 
-#ifndef __HAVE_GENERIC_SOFT_INTERRUPTS
-void		pppnetisr(void);
-#endif
 static void	pppintr(void *);
 
 /*
@@ -298,7 +295,7 @@
 
     (void)snprintf(sc->sc_if.if_xname, sizeof(sc->sc_if.if_xname), "%s%d",
 	name, sc->sc_unit = unit);
-    callout_init(&sc->sc_timo_ch);
+    callout_init(&sc->sc_timo_ch, 0);
     sc->sc_if.if_softc = sc;
     sc->sc_if.if_mtu = PPP_MTU;
     sc->sc_if.if_flags = IFF_POINTOPOINT | IFF_MULTICAST;
@@ -377,13 +374,11 @@
     if (sc == NULL)
 	sc = ppp_create(ppp_cloner.ifc_name, -1);
 
-#ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
     sc->sc_si = softintr_establish(IPL_SOFTNET, pppintr, sc);
     if (sc->sc_si == NULL) {
 	printf("%s: unable to establish softintr\n", sc->sc_if.if_xname);
 	return (NULL);
     }
-#endif
     sc->sc_flags = 0;
     sc->sc_mru = PPP_MRU;
     sc->sc_relinq = NULL;
@@ -415,9 +410,7 @@
 {
     struct mbuf *m;
 
-#ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
     softintr_disestablish(sc->sc_si);
-#endif
     if_down(&sc->sc_if);
     sc->sc_if.if_flags &= ~(IFF_UP|IFF_RUNNING);
     sc->sc_devp = NULL;
@@ -488,7 +481,7 @@
  * Ioctl routine for generic ppp devices.
  */
 int
-pppioctl(struct ppp_softc *sc, u_long cmd, caddr_t data, int flag,
+pppioctl(struct ppp_softc *sc, u_long cmd, void *data, int flag,
     struct lwp *l)
 {
     int s, error, flags, mru, npx;
@@ -702,7 +695,7 @@
 	if (newcodelen != 0) {
 	    newcode = malloc(newcodelen, M_DEVBUF, M_WAITOK);
 	    /* WAITOK -- malloc() never fails. */
-	    if ((error = copyin((caddr_t)nbp->bf_insns, (caddr_t)newcode,
+	    if ((error = copyin((void *)nbp->bf_insns, (void *)newcode,
 			       newcodelen)) != 0) {
 		free(newcode, M_DEVBUF);
 		return error;
@@ -753,7 +746,7 @@
  * Process an ioctl request to the ppp network interface.
  */
 static int
-pppsioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
+pppsioctl(struct ifnet *ifp, u_long cmd, void *data)
 {
     struct lwp *l = curlwp;	/* XXX */
     struct ppp_softc *sc = ifp->if_softc;
@@ -817,11 +810,11 @@
 
     case SIOCADDMULTI:
     case SIOCDELMULTI:
-	if (ifr == 0) {
+	if (ifr == NULL) {
 	    error = EAFNOSUPPORT;
 	    break;
 	}
-	switch (ifr->ifr_addr.sa_family) {
+	switch (ifreq_getaddr(cmd, ifr)->sa_family) {
 #ifdef INET
 	case AF_INET:
 	    break;
@@ -1116,11 +1109,7 @@
     int s = splhigh();	/* XXX IMP ME HARDER */
 
     sc->sc_flags &= ~SC_TBUSY;
-#ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
     softintr_schedule(sc->sc_si);
-#else
-    schednetisr(NETISR_PPP);
-#endif
     splx(s);
 }
 
@@ -1270,18 +1259,6 @@
     return m;
 }
 
-#ifndef __HAVE_GENERIC_SOFT_INTERRUPTS
-void
-pppnetisr(void)
-{
-	struct ppp_softc *sc;
-
-	for (sc = LIST_FIRST(&ppp_softc_list); sc != NULL;
-	    sc = LIST_NEXT(sc, sc_iflist))
-		pppintr(sc);
-}
-#endif
-
 /*
  * Software interrupt routine, called at splsoftnet.
  */
@@ -1437,11 +1414,7 @@
     if (lost)
 	m->m_flags |= M_ERRMARK;
     IF_ENQUEUE(&sc->sc_rawq, m);
-#ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
     softintr_schedule(sc->sc_si);
-#else
-    schednetisr(NETISR_PPP);
-#endif
     splx(s);
 }
 
@@ -1633,7 +1606,7 @@
     if (ilen <= MHLEN && M_IS_CLUSTER(m)) {
 	MGETHDR(mp, M_DONTWAIT, MT_DATA);
 	if (mp != NULL) {
-	    m_copydata(m, 0, ilen, mtod(mp, caddr_t));
+	    m_copydata(m, 0, ilen, mtod(mp, void *));
 	    m_freem(m);
 	    m = mp;
 	    m->m_len = ilen;
@@ -1712,6 +1685,10 @@
 	m->m_pkthdr.len -= PPP_HDRLEN;
 	m->m_data += PPP_HDRLEN;
 	m->m_len -= PPP_HDRLEN;
+#ifdef GATEWAY  
+	if (ip6flow_fastforward(m))
+		return;
+#endif
 	schednetisr(NETISR_IPV6);
 	inq = &ip6intrq;
 	break;
--- a/sys/net/if_pppoe.c	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/if_pppoe.c	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_pppoe.c,v 1.60.2.2 2006/12/30 20:50:20 yamt Exp $ */
+/* $NetBSD: if_pppoe.c,v 1.60.2.3 2007/09/03 14:42:10 yamt 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.60.2.2 2006/12/30 20:50:20 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_pppoe.c,v 1.60.2.3 2007/09/03 14:42:10 yamt Exp $");
 
 #include "pppoe.h"
 #include "bpfilter.h"
@@ -145,7 +145,7 @@
 	u_int8_t *sc_hunique;		/* content of host unique we must echo back */
 	size_t sc_hunique_len;		/* length of host unique */
 #endif
-	struct callout sc_timeout;	/* timeout while not in session state */
+	callout_t sc_timeout;	/* timeout while not in session state */
 	int sc_padi_retried;		/* number of PADI retries already done */
 	int sc_padr_retried;		/* number of PADR retries already done */
 };
@@ -154,13 +154,8 @@
 struct ifqueue ppoediscinq = { .ifq_maxlen = IFQ_MAXLEN };
 struct ifqueue ppoeinq = { .ifq_maxlen = IFQ_MAXLEN };
 
-#ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
-void * pppoe_softintr = NULL;
+void *pppoe_softintr = NULL;
 static void pppoe_softintr_handler(void *);
-#else
-struct callout pppoe_softintr = CALLOUT_INITIALIZER;
-void pppoe_softintr_handler(void *);
-#endif
 
 extern int sppp_ioctl(struct ifnet *, unsigned long, void *);
 
@@ -175,7 +170,7 @@
 static int pppoe_connect(struct pppoe_softc *);
 static int pppoe_disconnect(struct pppoe_softc *);
 static void pppoe_abort_connect(struct pppoe_softc *);
-static int pppoe_ioctl(struct ifnet *, unsigned long, caddr_t);
+static int pppoe_ioctl(struct ifnet *, unsigned long, void *);
 static void pppoe_tls(struct sppp *);
 static void pppoe_tlf(struct sppp *);
 static void pppoe_start(struct ifnet *);
@@ -220,9 +215,7 @@
 	LIST_INIT(&pppoe_softc_list);
 	if_clone_attach(&pppoe_cloner);
 
-#ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
 	pppoe_softintr = softintr_establish(IPL_SOFTNET, pppoe_softintr_handler, NULL);
-#endif
 }
 
 static int
@@ -250,7 +243,7 @@
 	/* changed to real address later */
 	memcpy(&sc->sc_dest, etherbroadcastaddr, sizeof(sc->sc_dest));
 
-	callout_init(&sc->sc_timeout);
+	callout_init(&sc->sc_timeout, 0);
 
 	sc->sc_sppp.pp_if.if_start = pppoe_start;
 	sc->sc_sppp.pp_tls = pppoe_tls;
@@ -295,6 +288,7 @@
 		free(sc->sc_service_name, M_DEVBUF);
 	if (sc->sc_ac_cookie)
 		free(sc->sc_ac_cookie, M_DEVBUF);
+	callout_destroy(&sc->sc_timeout);
 	free(sc, M_DEVBUF);
 
 	return (0);
@@ -364,22 +358,12 @@
 	return sc;
 }
 
-#ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
 static void
 pppoe_softintr_handler(void *dummy)
 {
 	/* called at splsoftnet() */
 	pppoe_input();
 }
-#else
-void
-pppoe_softintr_handler(void *dummy)
-{
-	int s = splnet();
-	pppoe_input();
-	splx(s);
-}
-#endif
 
 /* called at appropriate protection level */
 static void
@@ -461,7 +445,7 @@
 		m = NULL;
 		goto done;
 	}
-	ph = (struct pppoehdr *)(mtod(n, caddr_t) + noff);
+	ph = (struct pppoehdr *)(mtod(n, char *) + noff);
 	if (ph->vertype != PPPOE_VERTYPE) {
 		printf("pppoe: unknown version/type packet: 0x%x\n",
 		    ph->vertype);
@@ -487,7 +471,7 @@
 			m = NULL;
 			goto done;
 		}
-		pt = (struct pppoetag *)(mtod(n, caddr_t) + noff);
+		pt = (struct pppoetag *)(mtod(n, char *) + noff);
 		tag = ntohs(pt->tag);
 		len = ntohs(pt->len);
 		if (off + len > m->m_pkthdr.len) {
@@ -512,10 +496,10 @@
 				break;
 			}
 #ifdef PPPOE_SERVER
-			hunique = mtod(n, caddr_t) + noff;
+			hunique = mtod(n, u_int8_t *) + noff;
 			hunique_len = len;
 #endif
-			sc = pppoe_find_softc_by_hunique(mtod(n, caddr_t) + noff,
+			sc = pppoe_find_softc_by_hunique(mtod(n, char *) + noff,
 			    len, m->m_pkthdr.rcvif);
 			if (sc != NULL)
 				devname = sc->sc_sppp.pp_if.if_xname;
@@ -529,7 +513,7 @@
 					m = NULL;
 					break;
 				}
-				ac_cookie = mtod(n, caddr_t) + noff;
+				ac_cookie = mtod(n, char *) + noff;
 				ac_cookie_len = len;
 			}
 			break;
@@ -554,7 +538,7 @@
 				    &noff);
 				if (n && error) {
 					strncpy(error, 
-					    mtod(n, caddr_t) + noff, len);
+					    mtod(n, char *) + noff, len);
 					error[len] = '\0';
 				}
 			}
@@ -847,7 +831,7 @@
 }
 
 static int
-pppoe_ioctl(struct ifnet *ifp, unsigned long cmd, caddr_t data)
+pppoe_ioctl(struct ifnet *ifp, unsigned long cmd, void *data)
 {
 	struct lwp *l = curlwp;	/* XXX */
 	struct pppoe_softc *sc = (struct pppoe_softc*)ifp;
--- a/sys/net/if_pppoe.h	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/if_pppoe.h	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_pppoe.h,v 1.7.2.1 2006/06/21 15:10:27 yamt Exp $ */
+/* $NetBSD: if_pppoe.h,v 1.7.2.2 2007/09/03 14:42:10 yamt Exp $ */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -74,12 +74,7 @@
 extern struct ifqueue ppoediscinq;
 extern struct ifqueue ppoeinq;
 
-#ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
-extern void * pppoe_softintr;			/* softinterrupt cookie */
-#else
-extern struct callout pppoe_softintr;		/* callout (poor mans softint) */
-extern void pppoe_softintr_handler(void*);	/* handler function */
-#endif
+extern void *pppoe_softintr;			/* softinterrupt cookie */
 
 #endif /* _KERNEL */
 #endif /* !_NET_IF_PPPOE_H_ */
--- a/sys/net/if_pppvar.h	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/if_pppvar.h	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_pppvar.h,v 1.19.12.3 2007/02/26 09:11:35 yamt Exp $	*/
+/*	$NetBSD: if_pppvar.h,v 1.19.12.4 2007/09/03 14:42:10 yamt Exp $	*/
 /*	Id: if_pppvar.h,v 1.3 1996/07/01 01:04:37 paulus Exp	 */
 
 /*
@@ -115,9 +115,7 @@
 	void	*sc_rc_state;		/* receive decompressor state */
 	time_t	sc_last_sent;		/* time (secs) last NP pkt sent */
 	time_t	sc_last_recv;		/* time (secs) last NP pkt rcvd */
-#ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
 	void	*sc_si;			/* software interrupt handle */
-#endif
 #ifdef PPP_FILTER
 	/* Filter for packets to pass. */
 	struct	bpf_program sc_pass_filt_in;
@@ -156,7 +154,7 @@
 
 struct	ppp_softc *pppalloc(pid_t);
 void	pppdealloc(struct ppp_softc *);
-int	pppioctl(struct ppp_softc *, u_long, caddr_t, int, struct lwp *);
+int	pppioctl(struct ppp_softc *, u_long, void *, int, struct lwp *);
 void	ppp_restart(struct ppp_softc *);
 void	ppppktin(struct ppp_softc *, struct mbuf *, int);
 struct	mbuf *ppp_dequeue(struct ppp_softc *);
--- a/sys/net/if_sl.c	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/if_sl.c	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_sl.c,v 1.91.2.3 2007/02/26 09:11:35 yamt Exp $	*/
+/*	$NetBSD: if_sl.c,v 1.91.2.4 2007/09/03 14:42:10 yamt Exp $	*/
 
 /*
  * Copyright (c) 1987, 1989, 1992, 1993
@@ -60,7 +60,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_sl.c,v 1.91.2.3 2007/02/26 09:11:35 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_sl.c,v 1.91.2.4 2007/09/03 14:42:10 yamt Exp $");
 
 #include "opt_inet.h"
 #include "bpfilter.h"
@@ -187,9 +187,6 @@
 #define TRANS_FRAME_END		0xdc		/* transposed frame end */
 #define TRANS_FRAME_ESCAPE	0xdd		/* transposed frame esc */
 
-#ifndef __HAVE_GENERIC_SOFT_INTERRUPTS
-void	slnetisr(void);
-#endif
 static void	slintr(void *);
 
 static int	slinit(struct sl_softc *);
@@ -197,12 +194,12 @@
 
 static int	slclose(struct tty *, int);
 static int	slinput(int, struct tty *);
-static int	slioctl(struct ifnet *, u_long, caddr_t);
+static int	slioctl(struct ifnet *, u_long, void *);
 static int	slopen(dev_t, struct tty *);
 static int	sloutput(struct ifnet *, struct mbuf *, const struct sockaddr *,
 			 struct rtentry *);
 static int	slstart(struct tty *);
-static int	sltioctl(struct tty *, u_long, caddr_t, int, struct lwp *);
+static int	sltioctl(struct tty *, u_long, void *, int, struct lwp *);
 
 static struct linesw slip_disc = {
 	.l_name = "slip",
@@ -317,19 +314,15 @@
 
 	LIST_FOREACH(sc, &sl_softc_list, sc_iflist)
 		if (sc->sc_ttyp == NULL) {
-#ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
 			sc->sc_si = softintr_establish(IPL_SOFTNET,
 			    slintr, sc);
 			if (sc->sc_si == NULL)
 				return ENOMEM;
-#endif
 			if (slinit(sc) == 0) {
-#ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
 				softintr_disestablish(sc->sc_si);
-#endif
 				return ENOBUFS;
 			}
-			tp->t_sc = (caddr_t)sc;
+			tp->t_sc = (void *)sc;
 			sc->sc_ttyp = tp;
 			sc->sc_if.if_baudrate = tp->t_ospeed;
 			s = spltty();
@@ -354,9 +347,7 @@
 				error = clalloc(&tp->t_outq, 2 * SLMAX + 2, 0);
 				if (error) {
 					splx(s);
-#ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
 					softintr_disestablish(sc->sc_si);
-#endif
 					/*
 					 * clalloc() might return -1 which
 					 * is no good, so we need to return
@@ -387,9 +378,7 @@
 	sc = tp->t_sc;
 
 	if (sc != NULL) {
-#ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
 		softintr_disestablish(sc->sc_si);
-#endif
 		s = splnet();
 		if_down(&sc->sc_if);
 		IF_PURGE(&sc->sc_fastq);
@@ -429,7 +418,7 @@
  */
 /* ARGSUSED */
 static int
-sltioctl(struct tty *tp, u_long cmd, caddr_t data, int flag,
+sltioctl(struct tty *tp, u_long cmd, void *data, int flag,
     struct lwp *l)
 {
 	struct sl_softc *sc = (struct sl_softc *)tp->t_sc;
@@ -554,15 +543,7 @@
 	 */
 	if (sc == NULL)
 		return 0;
-#ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
 	softintr_schedule(sc->sc_si);
-#else
-    {
-	int s = splhigh();
-	schednetisr(NETISR_SLIP);
-	splx(s);
-    }
-#endif
 	return 0;
 }
 
@@ -679,15 +660,7 @@
 			goto error;
 
 		IF_ENQUEUE(&sc->sc_inq, m);
-#ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
 		softintr_schedule(sc->sc_si);
-#else
-	    {
-		int s = splhigh();
-		schednetisr(NETISR_SLIP);
-		splx(s);
-	    }
-#endif
 		goto newpack;
 	}
 	if (sc->sc_mp < sc->sc_ep) {
@@ -709,20 +682,6 @@
 	return 0;
 }
 
-#ifndef __HAVE_GENERIC_SOFT_INTERRUPTS
-void
-slnetisr(void)
-{
-	struct sl_softc *sc;
-
-	LIST_FOREACH(sc, &sl_softc_list, sc_iflist) {
-		if (sc->sc_ttyp == NULL)
-			continue;
-		slintr(sc);
-	}
-}
-#endif
-
 static void
 slintr(void *arg)
 {
@@ -967,7 +926,7 @@
 			}
 		}
 #endif
-		m->m_data = (caddr_t) pktstart;
+		m->m_data = (void *) pktstart;
 		m->m_pkthdr.len = m->m_len = len;
 #if NBPFILTER > 0
 		if (sc->sc_if.if_bpf) {
@@ -988,7 +947,7 @@
 			MGETHDR(n, M_DONTWAIT, MT_DATA);
 			pktlen = m->m_pkthdr.len;
 			M_MOVE_PKTHDR(n, m);
-			memcpy(mtod(n, caddr_t), mtod(m, caddr_t), pktlen);
+			memcpy(mtod(n, void *), mtod(m, void *), pktlen);
 			n->m_len = m->m_len;
 			m_freem(m);
 			m = n;
@@ -1017,7 +976,7 @@
  * Process an ioctl request.
  */
 static int
-slioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
+slioctl(struct ifnet *ifp, u_long cmd, void *data)
 {
 	struct ifaddr *ifa = (struct ifaddr *)data;
 	struct ifreq *ifr = (struct ifreq *)data;
@@ -1058,7 +1017,7 @@
 			error = EAFNOSUPPORT;		/* XXX */
 			break;
 		}
-		switch (ifr->ifr_addr.sa_family) {
+		switch (ifreq_getaddr(cmd, ifr)->sa_family) {
 
 #ifdef INET
 		case AF_INET:
--- a/sys/net/if_slvar.h	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/if_slvar.h	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_slvar.h,v 1.27.4.1 2006/06/21 15:10:27 yamt Exp $	*/
+/*	$NetBSD: if_slvar.h,v 1.27.4.2 2007/09/03 14:42:11 yamt Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -57,9 +57,7 @@
 	long	sc_starttime;		/* time of first abort in window */
 	long	sc_oqlen;		/* previous output queue size */
 	long	sc_otimeout;		/* number of times output's stalled */
-#ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
 	void	*sc_si;			/* softintr handle */
-#endif
 #ifdef __NetBSD__
 	int	sc_oldbufsize;		/* previous output buffer size */
 	int	sc_oldbufquot;		/* previous output buffer quoting */
--- a/sys/net/if_spppsubr.c	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/if_spppsubr.c	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_spppsubr.c,v 1.85.2.3 2007/02/26 09:11:35 yamt Exp $	 */
+/*	$NetBSD: if_spppsubr.c,v 1.85.2.4 2007/09/03 14:42:11 yamt Exp $	 */
 
 /*
  * Synchronous PPP/Cisco link level subroutines.
@@ -41,7 +41,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.85.2.3 2007/02/26 09:11:35 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_spppsubr.c,v 1.85.2.4 2007/09/03 14:42:11 yamt Exp $");
 
 #include "opt_inet.h"
 #include "opt_ipx.h"
@@ -246,7 +246,7 @@
 };
 
 static struct sppp *spppq;
-static struct callout keepalive_ch;
+static callout_t keepalive_ch;
 
 #ifdef INET
 /*
@@ -724,7 +724,7 @@
 			    m->m_len >= sizeof(struct ip) + (ip->ip_hl << 2) +
 			    sizeof(struct tcphdr)) {
 				th = (struct tcphdr *)
-				    ((caddr_t)ip + (ip->ip_hl << 2));
+				    ((char *)ip + (ip->ip_hl << 2));
 			}
 		} else
 			ip = NULL;
@@ -897,7 +897,7 @@
 
 	/* Initialize keepalive handler. */
 	if (! spppq) {
-		callout_init(&keepalive_ch);
+		callout_init(&keepalive_ch, 0);
 		callout_reset(&keepalive_ch, hz * LCP_KEEPALIVE_INTERVAL, sppp_keepalive, NULL);
 	}
 
@@ -1075,7 +1075,8 @@
 #define ifr_mtu ifr_metric
 #endif
 	case SIOCSIFMTU:
-		if (ifr->ifr_mtu < 128 || ifr->ifr_mtu > sp->lcp.their_mru) {
+		if (ifr->ifr_mtu < PPP_MINMRU ||
+		    ifr->ifr_mtu > sp->lcp.their_mru) {
 			error = EINVAL;
 			break;
 		}
@@ -1085,7 +1086,8 @@
 #endif
 #ifdef SLIOCSETMTU
 	case SLIOCSETMTU:
-		if (*(short *)data < 128 || *(short *)data > sp->lcp.their_mru)
+		if (*(short *)data < PPP_MINMRU ||
+		    *(short *)data > sp->lcp.their_mru)
 		{
 			error = EINVAL;
 			break;
@@ -2007,7 +2009,12 @@
 	sp->pp_seq[IDX_LCP] = 0;
 	sp->pp_rseq[IDX_LCP] = 0;
 	sp->lcp.protos = 0;
-	sp->lcp.mru = sp->lcp.their_mru = PP_MTU;
+	if (sp->pp_if.if_mtu < PP_MTU) {
+		sp->lcp.mru = sp->pp_if.if_mtu;
+		sp->lcp.opts |= (1 << LCP_OPT_MRU);
+	} else
+		sp->lcp.mru = PP_MTU;
+	sp->lcp.their_mru = PP_MTU;
 
 	/*
 	 * Initialize counters and timeout values.  Note that we don't
@@ -2020,7 +2027,7 @@
 	sp->lcp.max_terminate = 2;
 	sp->lcp.max_configure = 10;
 	sp->lcp.max_failure = 10;
-	callout_init(&sp->ch[IDX_LCP]);
+	callout_init(&sp->ch[IDX_LCP], 0);
 }
 
 static void
@@ -2394,11 +2401,18 @@
 			break;
 		case LCP_OPT_MRU:
 			/*
-			 * Should not be rejected anyway, since we only
-			 * negotiate a MRU if explicitly requested by
-			 * peer.
+			 * We try to negotiate a lower MRU if the underlying
+			 * link's MTU is less than PP_MTU (e.g. PPPoE). If the
+			 * peer rejects this lower rate, fallback to the
+			 * default.
 			 */
+			if (debug) {
+				addlog("%s: warning: peer rejected our MRU of "
+				    "%ld bytes. Defaulting to %d bytes\n",
+				    ifp->if_xname, sp->lcp.mru, PP_MTU);
+			}
 			sp->lcp.opts &= ~(1 << LCP_OPT_MRU);
+			sp->lcp.mru = PP_MTU;
 			break;
 		case LCP_OPT_AUTH_PROTO:
 			/*
@@ -2494,8 +2508,8 @@
 				u_int mru = p[2] * 256 + p[3];
 				if (debug)
 					addlog(" %d", mru);
-				if (mru < PP_MTU || mru > PP_MAX_MRU)
-					mru = PP_MTU;
+				if (mru < PPP_MINMRU || mru > sp->pp_if.if_mtu)
+					mru = sp->pp_if.if_mtu;
 				sp->lcp.mru = mru;
 				sp->lcp.opts |= (1 << LCP_OPT_MRU);
 			}
@@ -2740,7 +2754,7 @@
 	sp->fail_counter[IDX_IPCP] = 0;
 	sp->pp_seq[IDX_IPCP] = 0;
 	sp->pp_rseq[IDX_IPCP] = 0;
-	callout_init(&sp->ch[IDX_IPCP]);
+	callout_init(&sp->ch[IDX_IPCP], 0);
 }
 
 static void
@@ -3279,7 +3293,7 @@
 	sp->fail_counter[IDX_IPV6CP] = 0;
 	sp->pp_seq[IDX_IPV6CP] = 0;
 	sp->pp_rseq[IDX_IPV6CP] = 0;
-	callout_init(&sp->ch[IDX_IPV6CP]);
+	callout_init(&sp->ch[IDX_IPV6CP], 0);
 }
 
 static void
@@ -4142,7 +4156,7 @@
 	sp->fail_counter[IDX_CHAP] = 0;
 	sp->pp_seq[IDX_CHAP] = 0;
 	sp->pp_rseq[IDX_CHAP] = 0;
-	callout_init(&sp->ch[IDX_CHAP]);
+	callout_init(&sp->ch[IDX_CHAP], 0);
 }
 
 static void
@@ -4494,8 +4508,8 @@
 	sp->fail_counter[IDX_PAP] = 0;
 	sp->pp_seq[IDX_PAP] = 0;
 	sp->pp_rseq[IDX_PAP] = 0;
-	callout_init(&sp->ch[IDX_PAP]);
-	callout_init(&sp->pap_my_to_ch);
+	callout_init(&sp->ch[IDX_PAP], 0);
+	callout_init(&sp->pap_my_to_ch, 0);
 }
 
 static void
--- a/sys/net/if_srt.c	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/if_srt.c	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_srt.c,v 1.2.2.3 2007/02/26 09:11:36 yamt Exp $ */
+/* $NetBSD: if_srt.c,v 1.2.2.4 2007/09/03 14:42:12 yamt Exp $ */
 /* This file is in the public domain. */
 
 #include "opt_inet.h"
@@ -128,7 +128,7 @@
 
 /* Network device interface. */
 
-static int srt_if_ioctl(struct ifnet *intf, u_long cmd, caddr_t data)
+static int srt_if_ioctl(struct ifnet *intf, u_long cmd, void *data)
 {
  struct ifaddr *ifa;
  struct ifreq *ifr;
@@ -328,7 +328,7 @@
 static int srt_ioctl(
 	dev_t dev,
 	u_long cmd,
-	caddr_t data,
+	void *data,
 	int flag,
 	struct lwp *l )
 {
--- a/sys/net/if_stf.c	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/if_stf.c	Mon Sep 03 14:41:57 2007 +0000
@@ -1,5 +1,5 @@
-/*	$NetBSD: if_stf.c,v 1.48.2.3 2007/02/26 09:11:36 yamt Exp $	*/
-/*	$KAME: if_stf.c,v 1.62 2001/06/07 22:32:16 itojun Exp $	*/
+/*	$NetBSD: if_stf.c,v 1.48.2.4 2007/09/03 14:42:12 yamt Exp $	*/
+/*	$KAME: if_stf.c,v 1.62 2001/06/07 22:32:16 itojun Exp $ */
 
 /*
  * Copyright (C) 2000 WIDE Project.
@@ -75,7 +75,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_stf.c,v 1.48.2.3 2007/02/26 09:11:36 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_stf.c,v 1.48.2.4 2007/09/03 14:42:12 yamt Exp $");
 
 #include "opt_inet.h"
 
@@ -135,11 +135,7 @@
 
 struct stf_softc {
 	struct ifnet	sc_if;	   /* common area */
-	union {
-		struct route  __sc_ro4;
-		struct route_in6 __sc_ro6; /* just for safety */
-	} __sc_ro46;
-#define sc_ro	__sc_ro46.__sc_ro4
+	struct route	sc_ro;
 	const struct encaptab *encap_cookie;
 	LIST_ENTRY(stf_softc) sc_list;
 };
@@ -178,7 +174,7 @@
 static int stf_checkaddr6(struct stf_softc *, const struct in6_addr *,
 	struct ifnet *);
 static void stf_rtrequest(int, struct rtentry *, struct rt_addrinfo *);
-static int stf_ioctl(struct ifnet *, u_long, caddr_t);
+static int stf_ioctl(struct ifnet *, u_long, void *);
 
 /* ARGSUSED */
 void
@@ -239,6 +235,7 @@
 	bpfdetach(ifp);
 #endif
 	if_detach(ifp);
+	rtcache_free(&sc->sc_ro);
 	free(sc, M_DEVBUF);
 
 	return (0);
@@ -266,7 +263,7 @@
 	if (proto != IPPROTO_IPV6)
 		return 0;
 
-	m_copydata(m, 0, sizeof(ip), (caddr_t)&ip);
+	m_copydata(m, 0, sizeof(ip), (void *)&ip);
 
 	if (ip.ip_v != 4)
 		return 0;
@@ -338,11 +335,14 @@
 	struct stf_softc *sc;
 	const struct sockaddr_in6 *dst6;
 	const struct in_addr *in4;
-	struct sockaddr_in *dst4;
 	u_int8_t tos;
 	struct ip *ip;
 	struct ip6_hdr *ip6;
 	struct in6_ifaddr *ia6;
+	union {
+		struct sockaddr		dst;
+		struct sockaddr_in	dst4;
+	} u;
 
 	sc = (struct stf_softc*)ifp;
 	dst6 = (const struct sockaddr_in6 *)dst;
@@ -416,22 +416,11 @@
 	else
 		ip_ecn_ingress(ECN_NOCARE, &ip->ip_tos, &tos);
 
-	dst4 = (struct sockaddr_in *)&sc->sc_ro.ro_dst;
-	if (dst4->sin_family != AF_INET ||
-	    bcmp(&dst4->sin_addr, &ip->ip_dst, sizeof(ip->ip_dst)) != 0)
-		rtcache_free(&sc->sc_ro);
-	else
-		rtcache_check(&sc->sc_ro);
-	if (sc->sc_ro.ro_rt == NULL) {
-		dst4->sin_family = AF_INET;
-		dst4->sin_len = sizeof(struct sockaddr_in);
-		bcopy(&ip->ip_dst, &dst4->sin_addr, sizeof(dst4->sin_addr));
-		rtcache_init(&sc->sc_ro);
-		if (sc->sc_ro.ro_rt == NULL) {
-			m_freem(m);
-			ifp->if_oerrors++;
-			return ENETUNREACH;
-		}
+	sockaddr_in_init(&u.dst4, &ip->ip_dst, 0);
+	if (rtcache_lookup(&sc->sc_ro, &u.dst) == NULL) {
+		m_freem(m);
+		ifp->if_oerrors++;
+		return ENETUNREACH;
 	}
 
 	/* If the route constitutes infinite encapsulation, punt. */
@@ -443,8 +432,7 @@
 	}
 
 	ifp->if_opackets++;
-	return ip_output(m, NULL, &sc->sc_ro, 0,
-	    (struct ip_moptions *)NULL, (struct socket *)NULL);
+	return ip_output(m, NULL, &sc->sc_ro, 0, NULL, NULL);
 }
 
 static int
@@ -686,7 +674,7 @@
 }
 
 static int
-stf_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
+stf_ioctl(struct ifnet *ifp, u_long cmd, void *data)
 {
 	struct lwp		*l = curlwp;	/* XXX */
 	struct ifaddr		*ifa;
@@ -715,7 +703,8 @@
 	case SIOCADDMULTI:
 	case SIOCDELMULTI:
 		ifr = (struct ifreq *)data;
-		if (ifr != NULL && ifr->ifr_addr.sa_family == AF_INET6)
+		if (ifr != NULL &&
+		    ifreq_getaddr(cmd, ifr)->sa_family == AF_INET6)
 			;
 		else
 			error = EAFNOSUPPORT;
@@ -723,7 +712,7 @@
 
 	case SIOCSIFMTU:
 		if ((error = kauth_authorize_generic(l->l_cred,
-		    KAUTH_GENERIC_ISSUSER, &l->l_acflag)) != 0)
+		    KAUTH_GENERIC_ISSUSER, NULL)) != 0)
 			break;
 		ifr = (struct ifreq *)data;
 		mtu = ifr->ifr_mtu;
--- a/sys/net/if_strip.c	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/if_strip.c	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_strip.c,v 1.60.2.3 2007/02/26 09:11:36 yamt Exp $	*/
+/*	$NetBSD: if_strip.c,v 1.60.2.4 2007/09/03 14:42:13 yamt Exp $	*/
 /*	from: NetBSD: if_sl.c,v 1.38 1996/02/13 22:00:23 christos Exp $	*/
 
 /*
@@ -87,7 +87,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_strip.c,v 1.60.2.3 2007/02/26 09:11:36 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_strip.c,v 1.60.2.4 2007/09/03 14:42:13 yamt Exp $");
 
 #include "opt_inet.h"
 #include "bpfilter.h"
@@ -221,9 +221,6 @@
 
 #define STRIP_FRAME_END		0x0D		/* carriage return */
 
-#ifndef __HAVE_GENERIC_SOFT_INTERRUPTS
-void	stripnetisr(void);
-#endif
 static void	stripintr(void *);
 
 static int	stripinit(struct strip_softc *);
@@ -333,12 +330,12 @@
 
 static int	stripclose(struct tty *, int);
 static int	stripinput(int, struct tty *);
-static int	stripioctl(struct ifnet *, u_long, caddr_t);
+static int	stripioctl(struct ifnet *, u_long, void *);
 static int	stripopen(dev_t, struct tty *);
 static int	stripoutput(struct ifnet *,
 		    struct mbuf *, const struct sockaddr *, struct rtentry *);
 static int	stripstart(struct tty *);
-static int	striptioctl(struct tty *, u_long, caddr_t, int, struct lwp *);
+static int	striptioctl(struct tty *, u_long, void *, int, struct lwp *);
 
 static struct linesw strip_disc = {
 	.l_name = "strip",
@@ -371,7 +368,7 @@
 	sc->sc_unit = unit;
 	(void)snprintf(sc->sc_if.if_xname, sizeof(sc->sc_if.if_xname),
 	    "%s%d", ifc->ifc_name, unit);
-	callout_init(&sc->sc_timo_ch);
+	callout_init(&sc->sc_timo_ch, 0);
 	sc->sc_if.if_softc = sc;
 	sc->sc_if.if_mtu = SLMTU;
 	sc->sc_if.if_flags = 0;
@@ -491,17 +488,13 @@
 
 	LIST_FOREACH(sc, &strip_softc_list, sc_iflist) {
 		if (sc->sc_ttyp == NULL) {
-#ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
 			sc->sc_si = softintr_establish(IPL_SOFTNET,
 			    stripintr, sc);
-#endif
 			if (stripinit(sc) == 0) {
-#ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
 				softintr_disestablish(sc->sc_si);
-#endif
 				return (ENOBUFS);
 			}
-			tp->t_sc = (caddr_t)sc;
+			tp->t_sc = (void *)sc;
 			sc->sc_ttyp = tp;
 			sc->sc_if.if_baudrate = tp->t_ospeed;
 			ttyflush(tp, FREAD | FWRITE);
@@ -523,9 +516,7 @@
 				error = clalloc(&tp->t_outq, 3*SLMTU, 0);
 				if (error) {
 					splx(s);
-#ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
 					softintr_disestablish(sc->sc_si);
-#endif
 					/*
 					 * clalloc() might return -1 which
 					 * is no good, so we need to return
@@ -567,9 +558,7 @@
 	sc = tp->t_sc;
 
 	if (sc != NULL) {
-#ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
 		softintr_disestablish(sc->sc_si);
-#endif
 		s = splnet();
 		/*
 		 * Cancel watchdog timer, which stops the "probe-for-death"/
@@ -594,11 +583,11 @@
 		IF_PURGE(&sc->sc_inq);
 
 		/* XXX */
-		free((caddr_t)(sc->sc_rxbuf - SLBUFSIZE + SLMAX), M_DEVBUF);
+		free((void *)(sc->sc_rxbuf - SLBUFSIZE + SLMAX), M_DEVBUF);
 		sc->sc_rxbuf = NULL;
 
 		/* XXX */
-		free((caddr_t)(sc->sc_txbuf - SLBUFSIZE + SLMAX), M_DEVBUF);
+		free((void *)(sc->sc_txbuf - SLBUFSIZE + SLMAX), M_DEVBUF);
 		sc->sc_txbuf = NULL;
 
 		if (sc->sc_flags & SC_TIMEOUT) {
@@ -627,7 +616,7 @@
  */
 /* ARGSUSED */
 int
-striptioctl(struct tty *tp, u_long cmd, caddr_t data, int flag,
+striptioctl(struct tty *tp, u_long cmd, void *data, int flag,
     struct lwp *l)
 {
 	struct strip_softc *sc = (struct strip_softc *)tp->t_sc;
@@ -767,15 +756,13 @@
 		return (EHOSTUNREACH);
 	}
 
-#define SDL(__a)          ((const struct sockaddr_dl *)(__a))
-
 #ifdef DEBUG
 	if (rt) {
 	   	printf("stripout, rt: dst af%d gw af%d",
-		    rt_key(rt)->sa_family, rt->rt_gateway->sa_family);
-		if (rt_key(rt)->sa_family == AF_INET)
+		    rt_getkey(rt)->sa_family, rt->rt_gateway->sa_family);
+		if (rt_getkey(rt)->sa_family == AF_INET)
 		  printf(" dst %x",
-		      satocsin(rt_key(rt))->sin_addr.s_addr);
+		      satocsin(rt_getkey(rt))->sin_addr.s_addr);
 		printf("\n");
 	}
 #endif
@@ -786,19 +773,17 @@
 
                 /* assume rt is never NULL */
                 if (rt == NULL || rt->rt_gateway->sa_family != AF_LINK
-                    || SDL(rt->rt_gateway)->sdl_alen != ifp->if_addrlen) {
+                    || satocsdl(rt->rt_gateway)->sdl_alen != ifp->if_addrlen) {
 		  	DPRINTF(("strip: could not arp starmode addr %x\n",
 			 satocsin(dst)->sin_addr.s_addr));
 			m_freem(m);
 			return (EHOSTUNREACH);
 		}
-		/*bcopy(LLADDR(SDL(rt->rt_gateway)), dldst, ifp->if_addrlen);*/
-                dldst = CLLADDR(SDL(rt->rt_gateway));
+                dldst = CLLADDR(satocsdl(rt->rt_gateway));
                 break;
 
 	case AF_LINK:
-		/*bcopy(LLADDR(SDL(rt->rt_gateway)), dldst, ifp->if_addrlen);*/
-		dldst = CLLADDR(SDL(dst));
+		dldst = CLLADDR(satocsdl(dst));
 		break;
 
 	default:
@@ -926,15 +911,7 @@
 	 */
 	if (sc == NULL)
 		return (0);
-#ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
 	softintr_schedule(sc->sc_si);
-#else
-    {
-	int s = splhigh();
-	schednetisr(NETISR_STRIP);
-	splx(s);
-    }
-#endif
 	return (0);
 }
 
@@ -1065,15 +1042,7 @@
 		goto error;
 
 	IF_ENQUEUE(&sc->sc_inq, m);
-#ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
 	softintr_schedule(sc->sc_si);
-#else
-    {
-	int s = splhigh();
-	schednetisr(NETISR_STRIP);
-	splx(s);
-    }
-#endif
 	goto newpack;
 
 error:
@@ -1086,20 +1055,6 @@
 	return (0);
 }
 
-#ifndef __HAVE_GENERIC_SOFT_INTERRUPTS
-void
-stripnetisr(void)
-{
-	struct strip_softc *sc;
-
-	LIST_FOREACH(sc, &strip_softc_list, sc_iflist) {
-		if (sc->sc_ttyp == NULL)
-			continue;
-		stripintr(sc);
-	}
-}
-#endif
-
 static void
 stripintr(void *arg)
 {
@@ -1267,7 +1222,7 @@
 			}
 		}
 #endif
-		m->m_data = (caddr_t) pktstart;
+		m->m_data = (void *) pktstart;
 		m->m_pkthdr.len = m->m_len = len;
 #if NPBFILTER > 0
 		if (sc->sc_if.if_bpf) {
@@ -1288,7 +1243,7 @@
 			MGETHDR(n, M_DONTWAIT, MT_DATA);
 			pktlen = m->m_pkthdr.len;
 			M_MOVE_PKTHDR(n, m);
-			memcpy(mtod(n, caddr_t), mtod(m, caddr_t), pktlen);
+			memcpy(mtod(n, void *), mtod(m, void *), pktlen);
 			n->m_len = m->m_len;
 			m_freem(m);
 			m = n;
@@ -1317,7 +1272,7 @@
  * Process an ioctl request.
  */
 int
-stripioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
+stripioctl(struct ifnet *ifp, u_long cmd, void *data)
 {
 	struct ifaddr *ifa = (struct ifaddr *)data;
 	struct ifreq *ifr;
@@ -1346,7 +1301,7 @@
 			error = EAFNOSUPPORT;		/* XXX */
 			break;
 		}
-		switch (ifr->ifr_addr.sa_family) {
+		switch (ifreq_getaddr(cmd, ifr)->sa_family) {
 
 #ifdef INET
 		case AF_INET:
--- a/sys/net/if_stripvar.h	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/if_stripvar.h	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_stripvar.h,v 1.13.12.1 2006/06/21 15:10:27 yamt Exp $	*/
+/*	$NetBSD: if_stripvar.h,v 1.13.12.2 2007/09/03 14:42:13 yamt Exp $	*/
 
 #ifndef _NET_IF_STRIPVAR_H_
 #define _NET_IF_STRIPVAR_H_
@@ -22,9 +22,7 @@
 	u_int	sc_flags;		/* see below */
 	long	sc_oqlen;		/* previous output queue size */
 	long	sc_otimeout;		/* number of times output's stalled */
-#ifdef __HAVE_GENERIC_SOFT_INTERRUPTS
 	void	*sc_si;			/* softintr handle */
-#endif
 #ifdef __NetBSD__
 	int	sc_oldbufsize;		/* previous output buffer size */
 	int	sc_oldbufquot;		/* previous output buffer quoting */
--- a/sys/net/if_tap.c	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/if_tap.c	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_tap.c,v 1.10.2.2 2006/12/30 20:50:20 yamt Exp $	*/
+/*	$NetBSD: if_tap.c,v 1.10.2.3 2007/09/03 14:42:13 yamt 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.10.2.2 2006/12/30 20:50:20 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_tap.c,v 1.10.2.3 2007/09/03 14:42:13 yamt Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "bpfilter.h"
@@ -73,6 +73,8 @@
 #include <net/bpf.h>
 #endif
 
+#include <compat/sys/sockio.h>
+
 /*
  * sysctl node management
  *
@@ -130,7 +132,7 @@
 static int	tap_dev_close(struct tap_softc *);
 static int	tap_dev_read(int, struct uio *, int);
 static int	tap_dev_write(int, struct uio *, int);
-static int	tap_dev_ioctl(int, u_long, caddr_t, struct lwp *);
+static int	tap_dev_ioctl(int, u_long, void *, struct lwp *);
 static int	tap_dev_poll(int, int, struct lwp *);
 static int	tap_dev_kqfilter(int, struct knote *);
 
@@ -164,7 +166,7 @@
 static int	tap_cdev_close(dev_t, int, int, struct lwp *);
 static int	tap_cdev_read(dev_t, struct uio *, int);
 static int	tap_cdev_write(dev_t, struct uio *, int);
-static int	tap_cdev_ioctl(dev_t, u_long, caddr_t, int, struct lwp *);
+static int	tap_cdev_ioctl(dev_t, u_long, void *, int, struct lwp *);
 static int	tap_cdev_poll(dev_t, int, struct lwp *);
 static int	tap_cdev_kqfilter(dev_t, struct knote *);
 
@@ -199,7 +201,7 @@
 static void	tap_start(struct ifnet *);
 static void	tap_stop(struct ifnet *, int);
 static int	tap_init(struct ifnet *);
-static int	tap_ioctl(struct ifnet *, u_long, caddr_t);
+static int	tap_ioctl(struct ifnet *, u_long, void *);
 
 /* This is an internal function to keep tap_ioctl readable */
 static int	tap_lifaddr(struct ifnet *, u_long, struct ifaliasreq *);
@@ -259,9 +261,6 @@
 	uint32_t ui;
 	int error;
 
-	aprint_normal("%s: faking Ethernet device\n",
-	    self->dv_xname);
-
 	/*
 	 * In order to obtain unique initial Ethernet address on a host,
 	 * do some randomisation using the current uptime.  It's not meant
@@ -271,7 +270,7 @@
 	ui = (tv.tv_sec ^ tv.tv_usec) & 0xffffff;
 	memcpy(enaddr+3, (u_int8_t *)&ui, 3);
 
-	aprint_normal("%s: Ethernet address %s\n", sc->sc_dev.dv_xname,
+	aprint_verbose("%s: Ethernet address %s\n", device_xname(&sc->sc_dev),
 	    ether_snprintf(enaddrstr, sizeof(enaddrstr), enaddr));
 
 	/*
@@ -486,7 +485,7 @@
  * called under splnet().
  */
 static int
-tap_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
+tap_ioctl(struct ifnet *ifp, u_long cmd, void *data)
 {
 	struct tap_softc *sc = (struct tap_softc *)ifp->if_softc;
 	struct ifreq *ifr = (struct ifreq *)data;
@@ -495,6 +494,9 @@
 	s = splnet();
 
 	switch (cmd) {
+#ifdef OSIOCSIFMEDIA
+	case OSIOCSIFMEDIA:
+#endif
 	case SIOCSIFMEDIA:
 	case SIOCGIFMEDIA:
 		error = ifmedia_ioctl(ifp, ifr, &sc->sc_im, cmd);
@@ -526,7 +528,8 @@
 	if (sa->sa_family != AF_LINK)
 		return (EINVAL);
 
-	memcpy(LLADDR(ifp->if_sadl), sa->sa_data, ETHER_ADDR_LEN);
+	(void)sockaddr_dl_setaddr(ifp->if_sadl, ifp->if_sadl->sdl_len,
+	    sa->sa_data, ETHER_ADDR_LEN);
 
 	return (0);
 }
@@ -591,11 +594,6 @@
  *     interface cloning API, and call tap_clone_create above.
  *   opening the cloning device node, whose minor number is TAP_CLONER.
  *     See below for an explanation on how this part work.
- *
- * config_attach_pseudo can be called with unit = DVUNIT_ANY to have
- * autoconf(9) choose a unit number for us.  This is what happens when
- * the cloner is openend, while the ifcloner interface creates a device
- * with a specific unit number.
  */
 static struct tap_softc *
 tap_clone_creator(int unit)
@@ -605,8 +603,14 @@
 	cf = malloc(sizeof(*cf), M_DEVBUF, M_WAITOK);
 	cf->cf_name = tap_cd.cd_name;
 	cf->cf_atname = tap_ca.ca_name;
-	cf->cf_unit = unit;
-	cf->cf_fstate = FSTATE_STAR;
+	if (unit == -1) {
+		/* let autoconf find the first free one */
+		cf->cf_unit = 0;
+		cf->cf_fstate = FSTATE_STAR;
+	} else {
+		cf->cf_unit = unit;
+		cf->cf_fstate = FSTATE_NOTFOUND;
+	}
 
 	return (struct tap_softc *)config_attach_pseudo(cf);
 }
@@ -709,7 +713,7 @@
 	if ((error = falloc(l, &fp, &fd)) != 0)
 		return (error);
 
-	if ((sc = tap_clone_creator(DVUNIT_ANY)) == NULL) {
+	if ((sc = tap_clone_creator(-1)) == NULL) {
 		FILE_UNUSE(fp, l);
 		ffree(fp);
 		return (ENXIO);
@@ -893,7 +897,7 @@
 	 * One read is one packet.
 	 */
 	do {
-		error = uiomove(mtod(m, caddr_t),
+		error = uiomove(mtod(m, void *),
 		    min(m->m_len, uio->uio_resid), uio);
 		MFREE(m, n);
 		m = n;
@@ -953,7 +957,7 @@
 			}
 		}
 		(*mp)->m_len = min(MHLEN, uio->uio_resid);
-		error = uiomove(mtod(*mp, caddr_t), (*mp)->m_len, uio);
+		error = uiomove(mtod(*mp, void *), (*mp)->m_len, uio);
 		mp = &(*mp)->m_next;
 	}
 	if (error) {
@@ -977,7 +981,7 @@
 }
 
 static int
-tap_cdev_ioctl(dev_t dev, u_long cmd, caddr_t data, int flags,
+tap_cdev_ioctl(dev_t dev, u_long cmd, void *data, int flags,
     struct lwp *l)
 {
 	return tap_dev_ioctl(minor(dev), cmd, data, l);
@@ -986,11 +990,11 @@
 static int
 tap_fops_ioctl(struct file *fp, u_long cmd, void *data, struct lwp *l)
 {
-	return tap_dev_ioctl((intptr_t)fp->f_data, cmd, (caddr_t)data, l);
+	return tap_dev_ioctl((intptr_t)fp->f_data, cmd, (void *)data, l);
 }
 
 static int
-tap_dev_ioctl(int unit, u_long cmd, caddr_t data, struct lwp *l)
+tap_dev_ioctl(int unit, u_long cmd, void *data, struct lwp *l)
 {
 	struct tap_softc *sc =
 	    (struct tap_softc *)device_lookup(&tap_cd, unit);
@@ -1035,6 +1039,9 @@
 		else
 			sc->sc_flags &= ~TAP_NBIO;
 		break;
+#ifdef OTAPGIFNAME
+	case OTAPGIFNAME:
+#endif
 	case TAPGIFNAME:
 		{
 			struct ifreq *ifr = (struct ifreq *)data;
@@ -1070,7 +1077,7 @@
 	int revents = 0;
 
 	if (sc == NULL)
-		return (ENXIO);
+		return POLLERR;
 
 	if (events & (POLLIN|POLLRDNORM)) {
 		struct ifnet *ifp = &sc->sc_ec.ec_if;
@@ -1276,11 +1283,12 @@
 	int error;
 	size_t len;
 	char addr[3 * ETHER_ADDR_LEN];
+	uint8_t enaddr[ETHER_ADDR_LEN];
 
 	node = *rnode;
 	sc = node.sysctl_data;
 	ifp = &sc->sc_ec.ec_if;
-	(void)ether_snprintf(addr, sizeof(addr), LLADDR(ifp->if_sadl));
+	(void)ether_snprintf(addr, sizeof(addr), CLLADDR(ifp->if_sadl));
 	node.sysctl_data = addr;
 	error = sysctl_lookup(SYSCTLFN_CALL(&node));
 	if (error || newp == NULL)
@@ -1291,7 +1299,9 @@
 		return (EINVAL);
 
 	/* Commit change */
-	if (ether_nonstatic_aton(LLADDR(ifp->if_sadl), addr) != 0)
+	if (ether_nonstatic_aton(enaddr, addr) != 0 ||
+	    sockaddr_dl_setaddr(ifp->if_sadl, ifp->if_sadl->sdl_len, enaddr,
+	                        ETHER_ADDR_LEN) == NULL)
 		return (EINVAL);
 	return (error);
 }
--- a/sys/net/if_token.h	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/if_token.h	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_token.h,v 1.10.4.1 2006/06/21 15:10:27 yamt Exp $	*/
+/*	$NetBSD: if_token.h,v 1.10.4.2 2007/09/03 14:42:14 yamt Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1993
@@ -116,11 +116,9 @@
 #define	tokenbroadcastaddr	etherbroadcastaddr
 #define	token_ipmulticast_min	ether_ipmulticast_min
 #define	token_ipmulticast_max	ether_ipmulticast_max
-#define	token_addmulti		ether_addmulti
-#define	token_delmulti		ether_delmulti
 #define	token_sprintf		ether_sprintf
 
-void    token_ifattach(struct ifnet *, caddr_t);
+void    token_ifattach(struct ifnet *, void *);
 void    token_ifdetach(struct ifnet *);
 #endif
 
--- a/sys/net/if_tokensubr.c	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/if_tokensubr.c	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_tokensubr.c,v 1.32.2.3 2007/02/26 09:11:36 yamt Exp $	*/
+/*	$NetBSD: if_tokensubr.c,v 1.32.2.4 2007/09/03 14:42:14 yamt Exp $	*/
 
 /*
  * Copyright (c) 1982, 1989, 1993
@@ -99,7 +99,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_tokensubr.c,v 1.32.2.3 2007/02/26 09:11:36 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_tokensubr.c,v 1.32.2.4 2007/09/03 14:42:14 yamt Exp $");
 
 #include "opt_inet.h"
 #include "opt_atalk.h"
@@ -194,12 +194,12 @@
 	u_char edst[ISO88025_ADDR_LEN];
 	struct mbuf *m = m0;
 	struct rtentry *rt;
-	struct mbuf *mcopy = (struct mbuf *)0;
+	struct mbuf *mcopy = NULL;
 	struct token_header *trh;
 #ifdef INET
 	struct arphdr *ah = (struct arphdr *)ifp0;
 #endif /* INET */
-	struct token_rif *rif = (struct  token_rif *)0;
+	struct token_rif *rif = NULL;
 	struct token_rif bcastrif;
 	struct ifnet *ifp = ifp0;
 	size_t riflen = 0;
@@ -315,10 +315,10 @@
 			memcpy(edst, tokenbroadcastaddr, sizeof(edst));
 		}
 		else {
-			caddr_t tha = (caddr_t)ar_tha(ah);
+			void *tha = (void *)ar_tha(ah);
 			KASSERT(tha);
 			if (tha)
-				bcopy(tha, (caddr_t)edst, sizeof(edst));
+				bcopy(tha, (void *)edst, sizeof(edst));
 			trh = (struct token_header *)M_TRHSTART(m);
 			trh->token_ac = TOKEN_AC;
 			trh->token_fc = TOKEN_FC;
@@ -328,9 +328,9 @@
 				trrif = TOKEN_RIF(trh);
 				riflen = (ntohs(trrif->tr_rcf) & TOKEN_RCF_LEN_MASK) >> 8;
 			}
-			bcopy((caddr_t)edst, (caddr_t)trh->token_dhost,
+			bcopy((void *)edst, (void *)trh->token_dhost,
 			    sizeof (edst));
-			bcopy(LLADDR(ifp->if_sadl), (caddr_t)trh->token_shost,
+			bcopy(CLLADDR(ifp->if_sadl), (void *)trh->token_shost,
 			    sizeof(trh->token_shost));
 			if (riflen != 0)
 				trh->token_shost[0] |= TOKEN_RI_PRESENT;
@@ -348,11 +348,11 @@
 	case AF_ISO: {
 		int	snpalen;
 		struct	llc *l;
-		struct sockaddr_dl *sdl;
+		const struct sockaddr_dl *sdl;
 
-		if (rt && (sdl = (struct sockaddr_dl *)rt->rt_gateway) &&
+		if (rt && (sdl = satocsdl(rt->rt_gateway)) &&
 		    sdl->sdl_family == AF_LINK && sdl->sdl_alen > 0) {
-			bcopy(LLADDR(sdl), (caddr_t)edst, sizeof(edst));
+			memcpy(edst, CLLADDR(sdl), sizeof(edst));
 		}
 		else if ((error = iso_snparesolve(ifp,
 		    (const struct sockaddr_iso *)dst, (char *)edst, &snpalen)))
@@ -365,10 +365,10 @@
 			M_PREPEND(mcopy, sizeof (*trh), M_DONTWAIT);
 			if (mcopy) {
 				trh = mtod(mcopy, struct token_header *);
-				bcopy((caddr_t)edst,
-				    (caddr_t)trh->token_dhost, sizeof (edst));
-				bcopy(LLADDR(ifp->if_sadl),
-				    (caddr_t)trh->token_shost, sizeof (edst));
+				bcopy((void *)edst,
+				    (void *)trh->token_dhost, sizeof (edst));
+				bcopy(CLLADDR(ifp->if_sadl),
+				    (void *)trh->token_shost, sizeof (edst));
 			}
 		}
 		M_PREPEND(m, 3, M_DONTWAIT);
@@ -430,7 +430,7 @@
 		l->llc_dsap = l->llc_ssap = LLC_SNAP_LSAP;
 		l->llc_snap.org_code[0] = l->llc_snap.org_code[1] =
 		    l->llc_snap.org_code[2] = 0;
-		bcopy((caddr_t) &etype, (caddr_t) &l->llc_snap.ether_type,
+		bcopy((void *) &etype, (void *) &l->llc_snap.ether_type,
 		    sizeof(u_int16_t));
 	}
 
@@ -445,8 +445,8 @@
 	trh = mtod(m, struct token_header *);
 	trh->token_ac = TOKEN_AC;
 	trh->token_fc = TOKEN_FC;
-	bcopy((caddr_t)edst, (caddr_t)trh->token_dhost, sizeof (edst));
-	bcopy(LLADDR(ifp->if_sadl), (caddr_t)trh->token_shost,
+	bcopy((void *)edst, (void *)trh->token_dhost, sizeof (edst));
+	bcopy(CLLADDR(ifp->if_sadl), (void *)trh->token_shost,
 	    sizeof(trh->token_shost));
 
 	if (riflen != 0) {
@@ -462,7 +462,7 @@
 
 #if NCARP > 0
 	if (ifp0 != ifp && ifp0->if_type == IFT_CARP) {
-		bcopy(LLADDR(ifp0->if_sadl), (caddr_t)trh->token_shost,	    
+		bcopy(CLLADDR(ifp0->if_sadl), (void *)trh->token_shost,	    
 		    sizeof(trh->token_shost));
 	}
 #endif /* NCARP > 0 */
@@ -601,8 +601,8 @@
 			l->llc_dsap = l->llc_ssap;
 			l->llc_ssap = c;
 			if (m->m_flags & (M_BCAST | M_MCAST))
-				bcopy(LLADDR(ifp->if_sadl),
-				    (caddr_t)trh->token_dhost,
+				bcopy(CLLADDR(ifp->if_sadl),
+				    (void *)trh->token_dhost,
 				    ISO88025_ADDR_LEN);
 			sa.sa_family = AF_UNSPEC;
 			sa.sa_len = sizeof(sa);
@@ -649,7 +649,7 @@
  * Perform common duties while attaching to interface list
  */
 void
-token_ifattach(struct ifnet *ifp, caddr_t lla)
+token_ifattach(struct ifnet *ifp, void *lla)
 {
 
 	ifp->if_type = IFT_ISO88025;
@@ -665,7 +665,8 @@
 #endif
 
 	if_alloc_sadl(ifp);
-	memcpy(LLADDR(ifp->if_sadl), lla, ifp->if_addrlen);
+	sockaddr_dl_setaddr(ifp->if_sadl, ifp->if_sadl->sdl_len, lla,
+	    ifp->if_addrlen);
 
 #if NBPFILTER > 0
 	bpfattach(ifp, DLT_IEEE802, sizeof(struct token_header));
--- a/sys/net/if_tun.c	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/if_tun.c	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_tun.c,v 1.76.8.3 2007/02/26 09:11:36 yamt Exp $	*/
+/*	$NetBSD: if_tun.c,v 1.76.8.4 2007/09/03 14:42:21 yamt 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.76.8.3 2007/02/26 09:11:36 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_tun.c,v 1.76.8.4 2007/09/03 14:42:21 yamt Exp $");
 
 #include "opt_inet.h"
 
@@ -71,7 +71,7 @@
 static LIST_HEAD(, tun_softc) tunz_softc_list;
 static struct simplelock tun_softc_lock;
 
-static int	tun_ioctl(struct ifnet *, u_long, caddr_t);
+static int	tun_ioctl(struct ifnet *, u_long, void *);
 static int	tun_output(struct ifnet *, struct mbuf *,
 			const struct sockaddr *, struct rtentry *rt);
 static int	tun_clone_create(struct if_clone *, int);
@@ -242,7 +242,7 @@
 
 	if (tp->tun_flags & TUN_RWAIT) {
 		tp->tun_flags &= ~TUN_RWAIT;
-		wakeup((caddr_t)tp);
+		wakeup((void *)tp);
 	}
 	if (tp->tun_flags & TUN_ASYNC && tp->tun_pgid)
 		fownsignal(tp->tun_pgid, SIGIO, POLL_HUP, 0, NULL);
@@ -420,7 +420,7 @@
  * Process an ioctl request.
  */
 static int
-tun_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
+tun_ioctl(struct ifnet *ifp, u_long cmd, void *data)
 {
 	int		error = 0, s;
 	struct tun_softc *tp = (struct tun_softc *)(ifp->if_softc);
@@ -457,7 +457,7 @@
 	        	error = EAFNOSUPPORT;           /* XXX */
 			break;
 		}
-		switch (ifr->ifr_addr.sa_family) {
+		switch (ifreq_getaddr(cmd, ifr)->sa_family) {
 #ifdef INET
 		case AF_INET:
 			break;
@@ -582,7 +582,7 @@
 
 	if (tp->tun_flags & TUN_RWAIT) {
 		tp->tun_flags &= ~TUN_RWAIT;
-		wakeup((caddr_t)tp);
+		wakeup((void *)tp);
 	}
 	if (tp->tun_flags & TUN_ASYNC && tp->tun_pgid)
 		fownsignal(tp->tun_pgid, SIGIO, POLL_IN, POLLIN|POLLRDNORM,
@@ -599,7 +599,7 @@
  * the cdevsw interface is now pretty minimal.
  */
 int
-tunioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct lwp *l)
+tunioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l)
 {
 	struct tun_softc *tp;
 	int s, error = 0;
@@ -743,7 +743,7 @@
 				goto out;
 			}
 			tp->tun_flags |= TUN_RWAIT;
-			if (ltsleep((caddr_t)tp, PZERO|PCATCH|PNORELOCK,
+			if (ltsleep((void *)tp, PZERO|PCATCH|PNORELOCK,
 					"tunread", 0, &tp->tun_lock) != 0) {
 				error = EINTR;
 				goto out_nolock;
@@ -774,7 +774,7 @@
 	while (m0 && uio->uio_resid > 0 && error == 0) {
 		len = min(uio->uio_resid, m0->m_len);
 		if (len != 0)
-			error = uiomove(mtod(m0, caddr_t), len, uio);
+			error = uiomove(mtod(m0, void *), len, uio);
 		MFREE(m0, m);
 		m0 = m;
 	}
@@ -831,7 +831,7 @@
 			error = EIO;
 			goto out0;
 		}
-		error = uiomove((caddr_t)&dst, sizeof(dst), uio);
+		error = uiomove((void *)&dst, sizeof(dst), uio);
 		if (dst.sa_len > sizeof(dst)) {
 			/* Duh.. */
 			char discard;
@@ -846,7 +846,7 @@
 			error = EIO;
 			goto out0;
 		}
-		error = uiomove((caddr_t)&family, sizeof(family), uio);
+		error = uiomove((void *)&family, sizeof(family), uio);
 		dst.sa_family = ntohl(family);
 	} else {
 #ifdef INET
@@ -893,7 +893,7 @@
 	mp = &top;
 	while (error == 0 && uio->uio_resid > 0) {
 		m->m_len = min(mlen, uio->uio_resid);
-		error = uiomove(mtod(m, caddr_t), m->m_len, uio);
+		error = uiomove(mtod(m, void *), m->m_len, uio);
 		*mp = m;
 		mp = &m->m_next;
 		if (error == 0 && uio->uio_resid > 0) {
@@ -968,7 +968,7 @@
 	if (!IF_IS_EMPTY(&ifp->if_snd)) {
 		if (tp->tun_flags & TUN_RWAIT) {
 			tp->tun_flags &= ~TUN_RWAIT;
-			wakeup((caddr_t)tp);
+			wakeup((void *)tp);
 		}
 		if (tp->tun_flags & TUN_ASYNC && tp->tun_pgid)
 			fownsignal(tp->tun_pgid, SIGIO, POLL_OUT,
--- a/sys/net/if_vlan.c	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/if_vlan.c	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vlan.c,v 1.46.2.2 2006/12/30 20:50:20 yamt Exp $	*/
+/*	$NetBSD: if_vlan.c,v 1.46.2.3 2007/09/03 14:42:21 yamt Exp $	*/
 
 /*-
  * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
@@ -85,7 +85,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.46.2.2 2006/12/30 20:50:20 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.46.2.3 2007/09/03 14:42:21 yamt Exp $");
 
 #include "opt_inet.h"
 #include "bpfilter.h"
@@ -178,7 +178,7 @@
 static int	vlan_clone_create(struct if_clone *, int);
 static int	vlan_clone_destroy(struct ifnet *);
 static int	vlan_config(struct ifvlan *, struct ifnet *);
-static int	vlan_ioctl(struct ifnet *, u_long, caddr_t);
+static int	vlan_ioctl(struct ifnet *, u_long, void *);
 static void	vlan_start(struct ifnet *);
 static void	vlan_unconfig(struct ifnet *);
 
@@ -302,7 +302,7 @@
 
 				ifr.ifr_flags = p->if_flags;
 				error = (*p->if_ioctl)(p, SIOCSIFFLAGS,
-				    (caddr_t) &ifr);
+				    (void *) &ifr);
 				if (error) {
 					if (ec->ec_nvlans-- == 1)
 						ec->ec_capenable &=
@@ -338,7 +338,7 @@
 		/*
 		 * We inherit the parent's Ethernet address.
 		 */
-		ether_ifattach(ifp, LLADDR(p->if_sadl));
+		ether_ifattach(ifp, CLLADDR(p->if_sadl));
 		ifp->if_hdrlen = sizeof(struct ether_vlan_header); /* XXX? */
 		break;
 	    }
@@ -395,7 +395,7 @@
 
 				ifr.ifr_flags = ifv->ifv_p->if_flags;
 				(void) (*ifv->ifv_p->if_ioctl)(ifv->ifv_p,
-				    SIOCSIFFLAGS, (caddr_t) &ifr);
+				    SIOCSIFFLAGS, (void *) &ifr);
 			}
 		}
 
@@ -464,7 +464,7 @@
 }
 
 static int
-vlan_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
+vlan_ioctl(struct ifnet *ifp, u_long cmd, void *data)
 {
 	struct lwp *l = curlwp;	/* XXX */
 	struct ifvlan *ifv = ifp->if_softc;
@@ -498,7 +498,7 @@
 
 	case SIOCGIFADDR:
 		sa = (struct sockaddr *)&ifr->ifr_data;
-		memcpy(sa->sa_data, LLADDR(ifp->if_sadl), ifp->if_addrlen);
+		memcpy(sa->sa_data, CLLADDR(ifp->if_sadl), ifp->if_addrlen);
 		break;
 
 	case SIOCSIFMTU:
@@ -617,7 +617,7 @@
 	LIST_INSERT_HEAD(&ifv->ifv_mc_listhead, mc, mc_entries);
 
 	error = (*ifv->ifv_p->if_ioctl)(ifv->ifv_p, SIOCADDMULTI,
-	    (caddr_t)ifr);
+	    (void *)ifr);
 	if (error != 0)
 		goto ioctl_failed;
 	return (error);
@@ -652,7 +652,7 @@
 
 	/* We no longer use this multicast address.  Tell parent so. */
 	error = (*ifv->ifv_p->if_ioctl)(ifv->ifv_p, SIOCDELMULTI,
-	    (caddr_t)ifr);
+	    (void *)ifr);
 	if (error == 0) {
 		/* And forget about this address. */
 		for (mc = LIST_FIRST(&ifv->ifv_mc_listhead); mc != NULL;
@@ -690,7 +690,7 @@
 	memcpy(ifr->ifr_name, ifp->if_xname, IFNAMSIZ);
 	while ((mc = LIST_FIRST(&ifv->ifv_mc_listhead)) != NULL) {
 		memcpy(&ifr->ifr_addr, &mc->mc_addr, mc->mc_addr.ss_len);
-		(void)(*ifp->if_ioctl)(ifp, SIOCDELMULTI, (caddr_t)ifr);
+		(void)(*ifp->if_ioctl)(ifp, SIOCDELMULTI, (void *)ifr);
 		LIST_REMOVE(mc, mc_entries);
 		FREE(mc, M_DEVBUF);
 	}
@@ -784,8 +784,8 @@
 				 * Transform the Ethernet header into an
 				 * Ethernet header with 802.1Q encapsulation.
 				 */
-				memmove(mtod(m, caddr_t),
-				    mtod(m, caddr_t) + ifv->ifv_encaplen,
+				memmove(mtod(m, void *),
+				    mtod(m, char *) + ifv->ifv_encaplen,
 				    sizeof(struct ether_header));
 				evl = mtod(m, struct ether_vlan_header *);
 				evl->evl_proto = evl->evl_encap_proto;
@@ -909,8 +909,8 @@
 	 * header has already been fixed up above.
 	 */
 	if (mtag == NULL) {
-		memmove(mtod(m, caddr_t) + ifv->ifv_encaplen,
-		    mtod(m, caddr_t), sizeof(struct ether_header));
+		memmove(mtod(m, char *) + ifv->ifv_encaplen,
+		    mtod(m, void *), sizeof(struct ether_header));
 		m_adj(m, ifv->ifv_encaplen);
 	}
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/net/link_proto.c	Mon Sep 03 14:41:57 2007 +0000
@@ -0,0 +1,237 @@
+/*	$NetBSD: link_proto.c,v 1.3.2.2 2007/09/03 14:42:22 yamt Exp $	*/
+
+/*-
+ * Copyright (c) 1982, 1986, 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.
+ *
+ *	@(#)uipc_proto.c	8.2 (Berkeley) 2/14/95
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: link_proto.c,v 1.3.2.2 2007/09/03 14:42:22 yamt Exp $");
+
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <sys/protosw.h>
+#include <sys/domain.h>
+#include <sys/mbuf.h>
+#include <sys/un.h>
+#include <sys/socketvar.h>
+
+#include <net/if.h>
+#include <net/if_dl.h>
+#include <net/raw_cb.h>
+
+static int sockaddr_dl_cmp(const struct sockaddr *, const struct sockaddr *);
+
+/*
+ * Definitions of protocols supported in the link-layer domain.
+ */
+
+DOMAIN_DEFINE(linkdomain);	/* forward define and add to link set */
+
+struct domain linkdomain = {
+	.dom_family = AF_LINK,
+	.dom_name = "link",
+	.dom_externalize = NULL,
+	.dom_dispose = NULL,
+	.dom_protosw = NULL,
+	.dom_protoswNPROTOSW = NULL,
+	.dom_sockaddr_cmp = sockaddr_dl_cmp
+};
+
+/* Compare the field at byte offsets [fieldstart, fieldend) in
+ * two memory regions, [l, l + llen) and [r, r + llen).
+ */
+static inline int
+submemcmp(const void *l, const void *r,
+    const uint_fast8_t llen, const uint_fast8_t rlen,
+    const uint_fast8_t fieldstart, const uint_fast8_t fieldend)
+{
+	uint_fast8_t cmpend, minlen;
+	const uint8_t *lb = l, *rb = r;
+	int rc;
+
+	minlen = MIN(llen, rlen);
+
+	/* The field is missing from one region.  The shorter region is the
+	 * lesser region.
+	 */
+	if (fieldstart >= minlen)
+		return llen - rlen;
+
+	/* Two empty, present fields are always equal. */
+	if (fieldstart > fieldend)
+		return 0;
+
+	cmpend = MIN(fieldend, minlen);
+
+	rc = memcmp(&lb[fieldstart], &rb[fieldstart], cmpend - fieldstart);
+
+	if (rc != 0)
+		return rc;
+	/* If one or both fields are truncated, then the shorter is the lesser
+	 * field.
+	 */
+	if (minlen < fieldend)
+		return llen - rlen;
+	/* Fields are full-length and equal.  The fields are equal. */
+	return 0;
+}
+
+uint8_t
+sockaddr_dl_measure(uint8_t namelen, uint8_t addrlen)
+{
+	return offsetof(struct sockaddr_dl, sdl_data[namelen + addrlen]);
+}
+
+struct sockaddr *
+sockaddr_dl_alloc(uint16_t ifindex, uint8_t type,
+    const void *name, uint8_t namelen, const void *addr, uint8_t addrlen,
+    int flags)
+{
+	struct sockaddr *sa;
+	socklen_t len;
+
+	len = sockaddr_dl_measure(namelen, addrlen);
+	sa = sockaddr_alloc(AF_LINK, len, flags);
+
+	if (sa == NULL)
+		return NULL;
+
+	if (sockaddr_dl_init(satosdl(sa), len, ifindex, type, name, namelen,
+	    addr, addrlen) == NULL) {
+		sockaddr_free(sa);
+		return NULL;
+	}
+
+	return sa;
+}
+
+struct sockaddr_dl *
+sockaddr_dl_init(struct sockaddr_dl *sdl, socklen_t socklen, uint16_t ifindex,
+    uint8_t type, const void *name, uint8_t namelen, const void *addr,
+    uint8_t addrlen)
+{
+	socklen_t len;
+
+	sdl->sdl_family = AF_LINK;
+	sdl->sdl_slen = 0;
+	len = sockaddr_dl_measure(namelen, addrlen);
+	if (len > socklen) {
+		sdl->sdl_len = socklen;
+#ifdef DIAGNOSTIC
+		printf("%s: too long: %" PRIu8 " > %" PRIu8 "\n", __func__, len,
+		    socklen);
+#endif
+		return NULL;
+	}
+	sdl->sdl_len = len;
+	sdl->sdl_index = ifindex;
+	sdl->sdl_type = type;
+	memset(&sdl->sdl_data[0], 0, namelen + addrlen);
+	if (name != NULL) {
+		memcpy(&sdl->sdl_data[0], name, namelen);
+		sdl->sdl_nlen = namelen;
+	} else
+		sdl->sdl_nlen = 0;
+	if (addr != NULL) {
+		memcpy(&sdl->sdl_data[sdl->sdl_nlen], addr, addrlen);
+		sdl->sdl_alen = addrlen;
+	} else
+		sdl->sdl_alen = 0;
+	return sdl;
+}
+
+static int
+sockaddr_dl_cmp(const struct sockaddr *sa1, const struct sockaddr *sa2)
+{
+	int rc;
+	const uint_fast8_t indexofs = offsetof(struct sockaddr_dl, sdl_index);
+	const uint_fast8_t nlenofs = offsetof(struct sockaddr_dl, sdl_nlen);
+	uint_fast8_t dataofs = offsetof(struct sockaddr_dl, sdl_data[0]);
+	const struct sockaddr_dl *sdl1, *sdl2;
+
+	sdl1 = satocsdl(sa1);
+	sdl2 = satocsdl(sa2);
+
+	rc = submemcmp(sdl1, sdl2, sdl1->sdl_len, sdl2->sdl_len,
+	    indexofs, nlenofs);
+
+	if (rc != 0)
+		return rc;
+
+	rc = submemcmp(sdl1, sdl2, sdl1->sdl_len, sdl2->sdl_len,
+	    dataofs, dataofs + MIN(sdl1->sdl_nlen, sdl2->sdl_nlen));
+
+	if (rc != 0)
+		return rc;
+
+	if (sdl1->sdl_nlen != sdl2->sdl_nlen)
+		return sdl1->sdl_nlen - sdl2->sdl_nlen;
+
+	dataofs += sdl1->sdl_nlen;
+
+	rc = submemcmp(sdl1, sdl2, sdl1->sdl_len, sdl2->sdl_len,
+	    dataofs, dataofs + MIN(sdl1->sdl_alen, sdl2->sdl_alen));
+
+	if (rc != 0)
+		return rc;
+
+	if (sdl1->sdl_alen != sdl2->sdl_alen)
+		return sdl1->sdl_alen - sdl2->sdl_alen;
+
+	dataofs += sdl1->sdl_alen;
+
+	rc = submemcmp(sdl1, sdl2, sdl1->sdl_len, sdl2->sdl_len,
+	    dataofs, dataofs + MIN(sdl1->sdl_slen, sdl2->sdl_slen));
+
+	if (sdl1->sdl_slen != sdl2->sdl_slen)
+		return sdl1->sdl_slen - sdl2->sdl_slen;
+
+	return sdl1->sdl_len - sdl2->sdl_len;
+}
+
+struct sockaddr_dl *
+sockaddr_dl_setaddr(struct sockaddr_dl *sdl, socklen_t socklen,
+    const void *addr, uint8_t addrlen)
+{
+	socklen_t len;
+
+	len = sockaddr_dl_measure(sdl->sdl_nlen, addrlen);
+	if (len > socklen) {
+#ifdef DIAGNOSTIC
+		printf("%s: too long: %" PRIu8 " > %" PRIu8 "\n", __func__, len,
+		    socklen);
+#endif
+		return NULL;
+	}
+	memcpy(&sdl->sdl_data[sdl->sdl_nlen], addr, addrlen);
+	sdl->sdl_alen = addrlen;
+	sdl->sdl_len = len;
+	return sdl;
+}
--- a/sys/net/net_osdep.h	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/net_osdep.h	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: net_osdep.h,v 1.10.4.3 2007/02/26 09:11:36 yamt Exp $	*/
+/*	$NetBSD: net_osdep.h,v 1.10.4.4 2007/09/03 14:42:22 yamt Exp $	*/
 /*	$KAME: net_osdep.h,v 1.51 2001/07/06 06:21:43 itojun Exp $	*/
 
 /*
@@ -104,7 +104,7 @@
  *
  * - bpf:
  *	OpenBSD, NetBSD 1.5, BSDI [34]
- *		need caddr_t * (= if_bpf **) and struct ifnet *
+ *		need void ** (= if_bpf **) and struct ifnet *
  *	FreeBSD 2, FreeBSD 3, NetBSD post-1.5N
  *		need only struct ifnet * as argument
  *
--- a/sys/net/netisr.h	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/netisr.h	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: netisr.h,v 1.33.4.2 2006/12/30 20:50:20 yamt Exp $ */
+/* $NetBSD: netisr.h,v 1.33.4.3 2007/09/03 14:42:22 yamt Exp $ */
 
 /*
  * Copyright (c) 1980, 1986, 1989, 1993
@@ -54,11 +54,6 @@
 #include "opt_iso.h"
 #include "opt_natm.h"
 #include "arp.h"
-#ifndef __HAVE_GENERIC_SOFT_INTERRUPTS
-#include "sl.h"
-#include "strip.h"
-#include "ppp.h"
-#endif
 #endif /* !defined(_LKM) */
 
 #if !defined(_LOCORE)
@@ -97,18 +92,6 @@
 #include <netatalk/at_extern.h>
 #endif
 
-#ifndef __HAVE_GENERIC_SOFT_INTERRUPTS		/* XXX XXX XXX */
-#if NSL > 0
-extern void slnetisr(void);
-#endif
-#if NSTRIP > 0
-extern void stripnetisr(void);
-#endif
-#if NPPP > 0
-extern void pppnetisr(void);
-#endif
-#endif /* __HAVE_GENERIC_SOFT_INTERRUPTS */
-
 #endif /* !defined(_LOCORE) */
 #endif /* defined(_KERNEL) */
 
@@ -129,11 +112,6 @@
 #define	NETISR_ISDN	26		/* same as AF_E164 */
 #define	NETISR_NATM	27		/* same as AF_NATM */
 #define	NETISR_ARP	28		/* same as AF_ARP */
-#ifndef __HAVE_GENERIC_SOFT_INTERRUPTS
-#define	NETISR_SLIP	29		/* for SLIP processing */
-#define	NETISR_STRIP	30		/* for STRIP processing */
-#define	NETISR_PPP	31		/* for PPP processing */
-#endif
 
 #if defined(_KERNEL) && !defined(_LOCORE)
 
--- a/sys/net/netisr_dispatch.h	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/netisr_dispatch.h	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: netisr_dispatch.h,v 1.11.4.2 2006/12/30 20:50:20 yamt Exp $ */
+/* $NetBSD: netisr_dispatch.h,v 1.11.4.3 2007/09/03 14:42:22 yamt Exp $ */
 
 #ifndef _NET_NETISR_DISPATCH_H_
 #define _NET_NETISR_DISPATCH_H_
@@ -45,14 +45,5 @@
 #ifdef NATM
 	DONETISR(NETISR_NATM,natmintr);
 #endif
-#if NSL > 0 && !defined(__HAVE_GENERIC_SOFT_INTERRUPTS)
-	DONETISR(NETISR_SLIP,slnetisr);
-#endif
-#if NSTRIP > 0 && !defined(__HAVE_GENERIC_SOFT_INTERRUPTS)
-	DONETISR(NETISR_STRIP,stripnetisr);
-#endif
-#if NPPP > 0 && !defined(__HAVE_GENERIC_SOFT_INTERRUPTS)
-	DONETISR(NETISR_PPP,pppnetisr);
-#endif
 
 #endif /* !_NET_NETISR_DISPATCH_H_ */
--- a/sys/net/ppp_tty.c	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/ppp_tty.c	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: ppp_tty.c,v 1.38.2.3 2007/02/26 09:11:36 yamt Exp $	*/
+/*	$NetBSD: ppp_tty.c,v 1.38.2.4 2007/09/03 14:42:23 yamt Exp $	*/
 /*	Id: ppp_tty.c,v 1.3 1996/07/01 01:04:11 paulus Exp 	*/
 
 /*
@@ -93,7 +93,7 @@
 /* from NetBSD: if_ppp.c,v 1.15.2.2 1994/07/28 05:17:58 cgd Exp */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ppp_tty.c,v 1.38.2.3 2007/02/26 09:11:36 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ppp_tty.c,v 1.38.2.4 2007/09/03 14:42:23 yamt Exp $");
 
 #include "ppp.h"
 
@@ -137,7 +137,7 @@
 static int	pppclose(struct tty *tp, int flag);
 static int	pppread(struct tty *tp, struct uio *uio, int flag);
 static int	pppwrite(struct tty *tp, struct uio *uio, int flag);
-static int	ppptioctl(struct tty *tp, u_long cmd, caddr_t data, int flag,
+static int	ppptioctl(struct tty *tp, u_long cmd, void *data, int flag,
 			  struct lwp *);
 static int	pppinput(int c, struct tty *tp);
 static int	pppstart(struct tty *tp);
@@ -250,7 +250,7 @@
     sc->sc_if.if_flags |= IFF_RUNNING;
     sc->sc_if.if_baudrate = tp->t_ospeed;
 
-    tp->t_sc = (caddr_t) sc;
+    tp->t_sc = (void *) sc;
     ttyflush(tp, FREAD | FWRITE);
 
     splx(s);
@@ -349,7 +349,7 @@
 	    splx(s);
 	    return (EWOULDBLOCK);
 	}
-	error = ttysleep(tp, (caddr_t)&tp->t_rawq, TTIPRI|PCATCH, ttyin, 0);
+	error = ttysleep(tp, (void *)&tp->t_rawq, TTIPRI|PCATCH, ttyin, 0);
 	if (error) {
 	    splx(s);
 	    return error;
@@ -436,7 +436,7 @@
  */
 /* ARGSUSED */
 static int
-ppptioctl(struct tty *tp, u_long cmd, caddr_t data, int flag, struct lwp *l)
+ppptioctl(struct tty *tp, u_long cmd, void *data, int flag, struct lwp *l)
 {
     struct ppp_softc *sc = (struct ppp_softc *) tp->t_sc;
     int error, s;
@@ -678,7 +678,7 @@
 		/* call device driver IOCTL to transmit a frame */
 		cdev = cdevsw_lookup(tp->t_dev);
 		if (cdev == NULL ||
-		    (*cdev->d_ioctl)(tp->t_dev, TIOCXMTFRAME, (caddr_t)&m,
+		    (*cdev->d_ioctl)(tp->t_dev, TIOCXMTFRAME, (void *)&m,
 				     0, 0)) {
 			/* busy or error, set as current packet */
 			sc->sc_outm = m;
--- a/sys/net/radix.c	Mon Sep 03 14:31:56 2007 +0000
+++ b/sys/net/radix.c	Mon Sep 03 14:41:57 2007 +0000
@@ -1,4 +1,4 @@
-/*	$NetBSD: radix.c,v 1.29.2.3 2007/02/26 09:11:37 yamt Exp $	*/
+/*	$NetBSD: radix.c,v 1.29.2.4 2007/09/03 14:42:23 yamt Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1993
@@ -36,7 +36,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: radix.c,v 1.29.2.3 2007/02/26 09:11:37 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: radix.c,v 1.29.2.4 2007/09/03 14:42:23 yamt Exp $");
 
 #ifndef _NET_RADIX_H_
 #include <sys/param.h>
@@ -134,7 +134,7 @@
 		else
 			x = x->rn_l;
 	}
-	return (x);
+	return x;
 }
 
 struct radix_node *
@@ -184,7 +184,7 @@
 		for (lim2 = m - longer; m < lim2; )
 			if (*m++)
 				return 1;
-	return (!masks_are_equal);
+	return !masks_are_equal;
 }
 
 struct radix_node *
@@ -198,12 +198,12 @@
 
 	if (m_arg) {
 		if ((x = rn_addmask(m_arg, 1, head->rnh_treetop->rn_off)) == 0)
-			return (0);
+			return NULL;
 		netmask = x->rn_key;
 	}
 	x = rn_match(v_arg, head);
-	if (x && netmask) {
-		while (x && x->rn_mask != netmask)
+	if (x != NULL && netmask != NULL) {
+		while (x != NULL && x->rn_mask != netmask)
 			x = x->rn_dupedkey;
 	}
 	return x;
@@ -323,7 +323,7 @@
 			do {
 				if (m->rm_flags & RNF_NORMAL) {