aboutsummaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
Diffstat (limited to 'sys')
-rw-r--r--sys/amd64/amd64/efirt_machdep.c33
-rw-r--r--sys/amd64/amd64/machdep.c25
-rw-r--r--sys/amd64/amd64/pmap.c234
-rw-r--r--sys/amd64/include/efi.h4
-rw-r--r--sys/cam/cam_xpt.h6
-rw-r--r--sys/cam/mmc/mmc_da.c29
-rw-r--r--sys/cam/scsi/scsi_xpt.c56
-rw-r--r--sys/compat/freebsd32/freebsd32_sysent.c2
-rw-r--r--sys/conf/files56
-rw-r--r--sys/conf/kern.pre.mk4
-rw-r--r--sys/dev/ichiic/ig4_pci.c12
-rw-r--r--sys/dev/mem/memutil.c19
-rw-r--r--sys/dev/mlx5/mlx5_en/mlx5_en_hw_tls_rx.c97
-rw-r--r--sys/dev/nvmf/host/nvmf.c119
-rw-r--r--sys/dev/nvmf/host/nvmf_var.h6
-rw-r--r--sys/dev/nvmf/nvmf.h11
-rw-r--r--sys/dev/random/random_harvestq.c103
-rw-r--r--sys/dev/sound/midi/midi.c670
-rw-r--r--sys/dev/sound/midi/midi.h7
-rw-r--r--sys/dev/sound/midi/mpu401.c44
-rw-r--r--sys/dev/sound/midi/mpu_if.m11
-rw-r--r--sys/dev/sound/midi/sequencer.c2107
-rw-r--r--sys/dev/sound/midi/sequencer.h89
-rw-r--r--sys/dev/sound/midi/synth_if.m312
-rw-r--r--sys/dev/sound/pcm/mixer.c4
-rw-r--r--sys/dev/sound/pcm/sndstat.c7
-rw-r--r--sys/dev/sound/pcm/sound.h8
-rw-r--r--sys/fs/msdosfs/msdosfs_vnops.c3
-rw-r--r--sys/fs/nfs/nfs_commonsubs.c87
-rw-r--r--sys/fs/nfs/nfsproto.h8
-rw-r--r--sys/fs/nfsclient/nfs_clrpcops.c7
-rw-r--r--sys/fs/nfsclient/nfs_clvnops.c23
-rw-r--r--sys/fs/nfsserver/nfs_nfsdport.c52
-rw-r--r--sys/fs/nfsserver/nfs_nfsdserv.c33
-rw-r--r--sys/fs/smbfs/smbfs_vnops.c3
-rw-r--r--sys/fs/tmpfs/tmpfs_vnops.c4
-rw-r--r--sys/kern/init_sysent.c2
-rw-r--r--sys/kern/kern_descrip.c149
-rw-r--r--sys/kern/kern_sig.c18
-rw-r--r--sys/kern/kern_syscalls.c5
-rw-r--r--sys/kern/subr_pctrie.c36
-rw-r--r--sys/kern/sys_pipe.c2
-rw-r--r--sys/kern/syscalls.master2
-rw-r--r--sys/kern/sysv_msg.c2
-rw-r--r--sys/kern/sysv_sem.c2
-rw-r--r--sys/kern/sysv_shm.c2
-rw-r--r--sys/kern/uipc_syscalls.c13
-rw-r--r--sys/kern/uipc_usrreq.c3
-rw-r--r--sys/kern/vfs_aio.c46
-rw-r--r--sys/kern/vfs_default.c1
-rw-r--r--sys/kern/vfs_inotify.c4
-rw-r--r--sys/kern/vfs_syscalls.c17
-rw-r--r--sys/modules/sound/sound/Makefile6
-rw-r--r--sys/net/ethernet.h17
-rw-r--r--sys/net/if_bridge.c305
-rw-r--r--sys/net/if_bridgevar.h29
-rw-r--r--sys/net/if_vlan.c1
-rw-r--r--sys/net/if_vlan_var.h7
-rw-r--r--sys/net/pfvar.h7
-rw-r--r--sys/net80211/ieee80211_node.c30
-rw-r--r--sys/net80211/ieee80211_node.h6
-rw-r--r--sys/net80211/ieee80211_output.c44
-rw-r--r--sys/netinet/in_pcb.c17
-rw-r--r--sys/netinet/in_pcb.h1
-rw-r--r--sys/netinet/tcp_subr.c65
-rw-r--r--sys/netinet/tcp_usrreq.c3
-rw-r--r--sys/netpfil/ipfilter/netinet/fil.c29
-rw-r--r--sys/netpfil/ipfilter/netinet/ip_ftp_pxy.c8
-rw-r--r--sys/netpfil/ipfilter/netinet/ip_htable.c6
-rw-r--r--sys/netpfil/ipfilter/netinet/ip_ipsec_pxy.c4
-rw-r--r--sys/netpfil/ipfilter/netinet/ip_irc_pxy.c7
-rw-r--r--sys/netpfil/ipfilter/netinet/ip_lookup.c4
-rw-r--r--sys/netpfil/ipfilter/netinet/ip_nat.c43
-rw-r--r--sys/netpfil/ipfilter/netinet/ip_nat6.c52
-rw-r--r--sys/netpfil/ipfilter/netinet/ip_netbios_pxy.c5
-rw-r--r--sys/netpfil/ipfilter/netinet/ip_pptp_pxy.c5
-rw-r--r--sys/netpfil/ipfilter/netinet/ip_proxy.c4
-rw-r--r--sys/netpfil/ipfilter/netinet/ip_raudio_pxy.c8
-rw-r--r--sys/netpfil/ipfilter/netinet/ip_rcmd_pxy.c8
-rw-r--r--sys/netpfil/ipfilter/netinet/ip_rpcb_pxy.c8
-rw-r--r--sys/netpfil/ipfilter/netinet/ip_state.c22
-rw-r--r--sys/netpfil/ipfilter/netinet/ip_tftp_pxy.c4
-rw-r--r--sys/netpfil/ipfilter/netinet/ipf_rb.h2
-rw-r--r--sys/netpfil/pf/if_pflog.c2
-rw-r--r--sys/netpfil/pf/if_pfsync.c11
-rw-r--r--sys/netpfil/pf/pf.c8
-rw-r--r--sys/netpfil/pf/pf_ioctl.c177
-rw-r--r--sys/netpfil/pf/pf_nl.c68
-rw-r--r--sys/sys/fcntl.h17
-rw-r--r--sys/sys/filedesc.h2
-rw-r--r--sys/sys/param.h2
-rw-r--r--sys/sys/socket.h6
-rw-r--r--sys/sys/syscallsubr.h1
-rw-r--r--sys/sys/sysent.h9
-rw-r--r--sys/sys/unistd.h2
-rw-r--r--sys/sys/vnode.h2
-rw-r--r--sys/ufs/ufs/ufs_vnops.c3
-rw-r--r--sys/vm/vm_fault.c3
98 files changed, 1702 insertions, 3967 deletions
diff --git a/sys/amd64/amd64/efirt_machdep.c b/sys/amd64/amd64/efirt_machdep.c
index 81a28ebe97ee..fe5d60c978dd 100644
--- a/sys/amd64/amd64/efirt_machdep.c
+++ b/sys/amd64/amd64/efirt_machdep.c
@@ -56,6 +56,13 @@
#include <vm/vm_pager.h>
#include <vm/vm_radix.h>
+/* The EFI regions we're allowed to map. */
+#define EFI_ALLOWED_TYPES_MASK ( \
+ 1u << EFI_MD_TYPE_BS_CODE | 1u << EFI_MD_TYPE_BS_DATA | \
+ 1u << EFI_MD_TYPE_RT_CODE | 1u << EFI_MD_TYPE_RT_DATA | \
+ 1u << EFI_MD_TYPE_FIRMWARE \
+)
+
static pml5_entry_t *efi_pml5;
static pml4_entry_t *efi_pml4;
static vm_object_t obj_1t1_pt;
@@ -181,6 +188,7 @@ efi_create_1t1_map(struct efi_md *map, int ndesc, int descsz)
vm_offset_t va;
uint64_t idx;
int bits, i, mode;
+ bool map_pz = true;
obj_1t1_pt = vm_pager_allocate(OBJT_PHYS, NULL, ptoa(1 +
NPML4EPG + NPML4EPG * NPDPEPG + NPML4EPG * NPDPEPG * NPDEPG),
@@ -198,9 +206,16 @@ efi_create_1t1_map(struct efi_md *map, int ndesc, int descsz)
pmap_pinit_pml4(efi_pmltop_page);
}
+ if ((efi_map_regs & ~EFI_ALLOWED_TYPES_MASK) != 0) {
+ printf("Ignoring the following runtime EFI regions: %#x\n",
+ efi_map_regs & ~EFI_ALLOWED_TYPES_MASK);
+ efi_map_regs &= EFI_ALLOWED_TYPES_MASK;
+ }
+
for (i = 0, p = map; i < ndesc; i++, p = efi_next_descriptor(p,
descsz)) {
- if ((p->md_attr & EFI_MD_ATTR_RT) == 0)
+ if ((p->md_attr & EFI_MD_ATTR_RT) == 0 &&
+ !EFI_MAP_BOOTTYPE_ALLOWED(p->md_type))
continue;
if (p->md_virt != 0 && p->md_virt != p->md_phys) {
if (bootverbose)
@@ -256,6 +271,22 @@ efi_create_1t1_map(struct efi_md *map, int ndesc, int descsz)
}
}
VM_OBJECT_WUNLOCK(obj_1t1_pt);
+ if (p->md_phys == 0)
+ map_pz = false;
+ }
+
+ /*
+ * Some BIOSes tend to access phys 0 during efirt calls,
+ * so map it if we haven't yet.
+ */
+ if (map_pz) {
+ VM_OBJECT_WLOCK(obj_1t1_pt);
+ pte = efi_1t1_pte(0);
+ /* Assume Write-Back */
+ bits = pmap_cache_bits(kernel_pmap, VM_MEMATTR_WRITE_BACK,
+ false) | X86_PG_RW | X86_PG_V;
+ pte_store(pte, bits);
+ VM_OBJECT_WUNLOCK(obj_1t1_pt);
}
return (true);
diff --git a/sys/amd64/amd64/machdep.c b/sys/amd64/amd64/machdep.c
index 032a134bbd4b..f46462b39fa3 100644
--- a/sys/amd64/amd64/machdep.c
+++ b/sys/amd64/amd64/machdep.c
@@ -188,6 +188,12 @@ struct init_ops init_ops = {
*/
vm_paddr_t efi_systbl_phys;
+/*
+ * Bitmap of extra EFI memory region types that should be preserved and mapped
+ * during runtime services calls.
+ */
+uint32_t efi_map_regs;
+
/* Intel ICH registers */
#define ICH_PMBASE 0x400
#define ICH_SMI_EN ICH_PMBASE + 0x30
@@ -645,7 +651,7 @@ add_physmap_entry(uint64_t base, uint64_t length, vm_paddr_t *physmap,
* NB: physmap_idx points to the next free slot.
*/
insert_idx = physmap_idx;
- for (i = 0; i <= physmap_idx; i += 2) {
+ for (i = 0; i < physmap_idx; i += 2) {
if (base < physmap[i + 1]) {
if (base + length <= physmap[i]) {
insert_idx = i;
@@ -659,7 +665,7 @@ add_physmap_entry(uint64_t base, uint64_t length, vm_paddr_t *physmap,
}
/* See if we can prepend to the next entry. */
- if (insert_idx <= physmap_idx && base + length == physmap[insert_idx]) {
+ if (insert_idx < physmap_idx && base + length == physmap[insert_idx]) {
physmap[insert_idx] = base;
return (1);
}
@@ -670,8 +676,6 @@ add_physmap_entry(uint64_t base, uint64_t length, vm_paddr_t *physmap,
return (1);
}
- physmap_idx += 2;
- *physmap_idxp = physmap_idx;
if (physmap_idx == PHYS_AVAIL_ENTRIES) {
printf(
"Too many segments in the physical address map, giving up\n");
@@ -682,11 +686,14 @@ add_physmap_entry(uint64_t base, uint64_t length, vm_paddr_t *physmap,
* Move the last 'N' entries down to make room for the new
* entry if needed.
*/
- for (i = (physmap_idx - 2); i > insert_idx; i -= 2) {
+ for (i = physmap_idx; i > insert_idx; i -= 2) {
physmap[i] = physmap[i - 2];
physmap[i + 1] = physmap[i - 1];
}
+ physmap_idx += 2;
+ *physmap_idxp = physmap_idx;
+
/* Insert the new entry. */
physmap[insert_idx] = base;
physmap[insert_idx + 1] = base + length;
@@ -757,6 +764,7 @@ add_efi_map_entries(struct efi_map_header *efihdr, vm_paddr_t *physmap,
printf("%23s %12s %12s %8s %4s\n",
"Type", "Physical", "Virtual", "#Pages", "Attr");
+ TUNABLE_INT_FETCH("machdep.efirt.regs", &efi_map_regs);
for (i = 0, p = map; i < ndesc; i++,
p = efi_next_descriptor(p, efihdr->descriptor_size)) {
if (boothowto & RB_VERBOSE) {
@@ -794,10 +802,13 @@ add_efi_map_entries(struct efi_map_header *efihdr, vm_paddr_t *physmap,
}
switch (p->md_type) {
- case EFI_MD_TYPE_CODE:
- case EFI_MD_TYPE_DATA:
case EFI_MD_TYPE_BS_CODE:
case EFI_MD_TYPE_BS_DATA:
+ if (EFI_MAP_BOOTTYPE_ALLOWED(p->md_type))
+ continue;
+ /* FALLTHROUGH */
+ case EFI_MD_TYPE_CODE:
+ case EFI_MD_TYPE_DATA:
case EFI_MD_TYPE_FREE:
/*
* We're allowed to use any entry with these types.
diff --git a/sys/amd64/amd64/pmap.c b/sys/amd64/amd64/pmap.c
index 2ab8c3b17e22..9c985df13ddf 100644
--- a/sys/amd64/amd64/pmap.c
+++ b/sys/amd64/amd64/pmap.c
@@ -1301,8 +1301,10 @@ static int pmap_change_props_locked(vm_offset_t va, vm_size_t size,
static bool pmap_demote_pde(pmap_t pmap, pd_entry_t *pde, vm_offset_t va);
static bool pmap_demote_pde_locked(pmap_t pmap, pd_entry_t *pde,
vm_offset_t va, struct rwlock **lockp);
+static bool pmap_demote_pde_mpte(pmap_t pmap, pd_entry_t *pde,
+ vm_offset_t va, struct rwlock **lockp, vm_page_t mpte);
static bool pmap_demote_pdpe(pmap_t pmap, pdp_entry_t *pdpe,
- vm_offset_t va);
+ vm_offset_t va, vm_page_t m);
static int pmap_enter_2mpage(pmap_t pmap, vm_offset_t va, vm_page_t m,
vm_prot_t prot, struct rwlock **lockp);
static int pmap_enter_pde(pmap_t pmap, vm_offset_t va, pd_entry_t newpde,
@@ -1334,7 +1336,7 @@ static pdp_entry_t *pmap_pti_pdpe(vm_offset_t va);
static pd_entry_t *pmap_pti_pde(vm_offset_t va);
static void pmap_pti_wire_pte(void *pte);
static int pmap_remove_pde(pmap_t pmap, pd_entry_t *pdq, vm_offset_t sva,
- struct spglist *free, struct rwlock **lockp);
+ bool remove_pt, struct spglist *free, struct rwlock **lockp);
static int pmap_remove_pte(pmap_t pmap, pt_entry_t *ptq, vm_offset_t sva,
pd_entry_t ptepde, struct spglist *free, struct rwlock **lockp);
static vm_page_t pmap_remove_pt_page(pmap_t pmap, vm_offset_t va);
@@ -5999,7 +6001,7 @@ pmap_demote_pde_abort(pmap_t pmap, vm_offset_t va, pd_entry_t *pde,
SLIST_INIT(&free);
sva = trunc_2mpage(va);
- pmap_remove_pde(pmap, pde, sva, &free, lockp);
+ pmap_remove_pde(pmap, pde, sva, true, &free, lockp);
if ((oldpde & pmap_global_bit(pmap)) == 0)
pmap_invalidate_pde_page(pmap, sva, oldpde);
vm_page_free_pages_toq(&free, true);
@@ -6011,11 +6013,17 @@ static bool
pmap_demote_pde_locked(pmap_t pmap, pd_entry_t *pde, vm_offset_t va,
struct rwlock **lockp)
{
+ return (pmap_demote_pde_mpte(pmap, pde, va, lockp, NULL));
+}
+
+static bool
+pmap_demote_pde_mpte(pmap_t pmap, pd_entry_t *pde, vm_offset_t va,
+ struct rwlock **lockp, vm_page_t mpte)
+{
pd_entry_t newpde, oldpde;
pt_entry_t *firstpte, newpte;
pt_entry_t PG_A, PG_G, PG_M, PG_PKU_MASK, PG_RW, PG_V;
vm_paddr_t mptepa;
- vm_page_t mpte;
int PG_PTE_CACHE;
bool in_kernel;
@@ -6028,61 +6036,65 @@ pmap_demote_pde_locked(pmap_t pmap, pd_entry_t *pde, vm_offset_t va,
PG_PKU_MASK = pmap_pku_mask_bit(pmap);
PMAP_LOCK_ASSERT(pmap, MA_OWNED);
- in_kernel = va >= VM_MAXUSER_ADDRESS;
oldpde = *pde;
KASSERT((oldpde & (PG_PS | PG_V)) == (PG_PS | PG_V),
("pmap_demote_pde: oldpde is missing PG_PS and/or PG_V"));
-
- /*
- * Invalidate the 2MB page mapping and return "failure" if the
- * mapping was never accessed.
- */
- if ((oldpde & PG_A) == 0) {
- KASSERT((oldpde & PG_W) == 0,
- ("pmap_demote_pde: a wired mapping is missing PG_A"));
- pmap_demote_pde_abort(pmap, va, pde, oldpde, lockp);
- return (false);
- }
-
- mpte = pmap_remove_pt_page(pmap, va);
+ KASSERT((oldpde & PG_MANAGED) == 0 || lockp != NULL,
+ ("pmap_demote_pde: lockp for a managed mapping is NULL"));
+ in_kernel = va >= VM_MAXUSER_ADDRESS;
if (mpte == NULL) {
- KASSERT((oldpde & PG_W) == 0,
- ("pmap_demote_pde: page table page for a wired mapping"
- " is missing"));
-
- /*
- * If the page table page is missing and the mapping
- * is for a kernel address, the mapping must belong to
- * the direct map. Page table pages are preallocated
- * for every other part of the kernel address space,
- * so the direct map region is the only part of the
- * kernel address space that must be handled here.
- */
- KASSERT(!in_kernel || (va >= DMAP_MIN_ADDRESS &&
- va < DMAP_MAX_ADDRESS),
- ("pmap_demote_pde: No saved mpte for va %#lx", va));
-
/*
- * If the 2MB page mapping belongs to the direct map
- * region of the kernel's address space, then the page
- * allocation request specifies the highest possible
- * priority (VM_ALLOC_INTERRUPT). Otherwise, the
- * priority is normal.
+ * Invalidate the 2MB page mapping and return "failure" if the
+ * mapping was never accessed.
*/
- mpte = pmap_alloc_pt_page(pmap, pmap_pde_pindex(va),
- (in_kernel ? VM_ALLOC_INTERRUPT : 0) | VM_ALLOC_WIRED);
-
- /*
- * If the allocation of the new page table page fails,
- * invalidate the 2MB page mapping and return "failure".
- */
- if (mpte == NULL) {
+ if ((oldpde & PG_A) == 0) {
+ KASSERT((oldpde & PG_W) == 0,
+ ("pmap_demote_pde: a wired mapping is missing PG_A"));
pmap_demote_pde_abort(pmap, va, pde, oldpde, lockp);
return (false);
}
- if (!in_kernel)
- mpte->ref_count = NPTEPG;
+ mpte = pmap_remove_pt_page(pmap, va);
+ if (mpte == NULL) {
+ KASSERT((oldpde & PG_W) == 0,
+ ("pmap_demote_pde: page table page for a wired mapping is missing"));
+
+ /*
+ * If the page table page is missing and the mapping
+ * is for a kernel address, the mapping must belong to
+ * the direct map. Page table pages are preallocated
+ * for every other part of the kernel address space,
+ * so the direct map region is the only part of the
+ * kernel address space that must be handled here.
+ */
+ KASSERT(!in_kernel || (va >= DMAP_MIN_ADDRESS &&
+ va < DMAP_MAX_ADDRESS),
+ ("pmap_demote_pde: No saved mpte for va %#lx", va));
+
+ /*
+ * If the 2MB page mapping belongs to the direct map
+ * region of the kernel's address space, then the page
+ * allocation request specifies the highest possible
+ * priority (VM_ALLOC_INTERRUPT). Otherwise, the
+ * priority is normal.
+ */
+ mpte = pmap_alloc_pt_page(pmap, pmap_pde_pindex(va),
+ (in_kernel ? VM_ALLOC_INTERRUPT : 0) |
+ VM_ALLOC_WIRED);
+
+ /*
+ * If the allocation of the new page table page fails,
+ * invalidate the 2MB page mapping and return "failure".
+ */
+ if (mpte == NULL) {
+ pmap_demote_pde_abort(pmap, va, pde, oldpde,
+ lockp);
+ return (false);
+ }
+
+ if (!in_kernel)
+ mpte->ref_count = NPTEPG;
+ }
}
mptepa = VM_PAGE_TO_PHYS(mpte);
firstpte = (pt_entry_t *)PHYS_TO_DMAP(mptepa);
@@ -6153,7 +6165,8 @@ pmap_demote_pde_locked(pmap_t pmap, pd_entry_t *pde, vm_offset_t va,
* pmap_remove_kernel_pde: Remove a kernel superpage mapping.
*/
static void
-pmap_remove_kernel_pde(pmap_t pmap, pd_entry_t *pde, vm_offset_t va)
+pmap_remove_kernel_pde(pmap_t pmap, pd_entry_t *pde, vm_offset_t va,
+ bool remove_pt)
{
pd_entry_t newpde;
vm_paddr_t mptepa;
@@ -6161,7 +6174,10 @@ pmap_remove_kernel_pde(pmap_t pmap, pd_entry_t *pde, vm_offset_t va)
KASSERT(pmap == kernel_pmap, ("pmap %p is not kernel_pmap", pmap));
PMAP_LOCK_ASSERT(pmap, MA_OWNED);
- mpte = pmap_remove_pt_page(pmap, va);
+ if (remove_pt)
+ mpte = pmap_remove_pt_page(pmap, va);
+ else
+ mpte = vm_radix_lookup(&pmap->pm_root, pmap_pde_pindex(va));
if (mpte == NULL)
panic("pmap_remove_kernel_pde: Missing pt page.");
@@ -6193,7 +6209,7 @@ pmap_remove_kernel_pde(pmap_t pmap, pd_entry_t *pde, vm_offset_t va)
* pmap_remove_pde: do the things to unmap a superpage in a process
*/
static int
-pmap_remove_pde(pmap_t pmap, pd_entry_t *pdq, vm_offset_t sva,
+pmap_remove_pde(pmap_t pmap, pd_entry_t *pdq, vm_offset_t sva, bool remove_pt,
struct spglist *free, struct rwlock **lockp)
{
struct md_page *pvh;
@@ -6234,7 +6250,7 @@ pmap_remove_pde(pmap_t pmap, pd_entry_t *pdq, vm_offset_t sva,
}
}
if (pmap == kernel_pmap) {
- pmap_remove_kernel_pde(pmap, pdq, sva);
+ pmap_remove_kernel_pde(pmap, pdq, sva, remove_pt);
} else {
mpte = pmap_remove_pt_page(pmap, sva);
if (mpte != NULL) {
@@ -6476,7 +6492,8 @@ pmap_remove1(pmap_t pmap, vm_offset_t sva, vm_offset_t eva, bool map_delete)
*/
if ((ptpaddr & PG_G) == 0)
anyvalid = 1;
- pmap_remove_pde(pmap, pde, sva, &free, &lock);
+ pmap_remove_pde(pmap, pde, sva, true, &free,
+ &lock);
continue;
} else if (!pmap_demote_pde_locked(pmap, pde, sva,
&lock)) {
@@ -7552,13 +7569,36 @@ pmap_enter_pde(pmap_t pmap, vm_offset_t va, pd_entry_t newpde, u_int flags,
/*
* The reference to the PD page that was acquired by
* pmap_alloc_pde() ensures that it won't be freed.
- * However, if the PDE resulted from a promotion, then
+ * However, if the PDE resulted from a promotion, and
+ * the mapping is not from kernel_pmap, then
* a reserved PT page could be freed.
*/
- (void)pmap_remove_pde(pmap, pde, va, &free, lockp);
+ (void)pmap_remove_pde(pmap, pde, va,
+ pmap != kernel_pmap, &free, lockp);
if ((oldpde & PG_G) == 0)
pmap_invalidate_pde_page(pmap, va, oldpde);
} else {
+ if (va >= VM_MAXUSER_ADDRESS) {
+ /*
+ * Try to save the ptp in the trie
+ * before any changes to mappings are
+ * made. Abort on failure.
+ */
+ mt = PHYS_TO_VM_PAGE(*pde & PG_FRAME);
+ if (pmap_insert_pt_page(pmap, mt, false, false)) {
+ if (pdpg != NULL)
+ pdpg->ref_count--;
+ CTR1(KTR_PMAP,
+ "pmap_enter_pde: cannot ins kern ptp va %#lx",
+ va);
+ return (KERN_RESOURCE_SHORTAGE);
+ }
+ /*
+ * Both pmap_remove_pde() and
+ * pmap_remove_ptes() will zero-fill
+ * the kernel page table page.
+ */
+ }
pmap_delayed_invl_start();
if (pmap_remove_ptes(pmap, va, va + NBPDR, pde, &free,
lockp))
@@ -7572,14 +7612,6 @@ pmap_enter_pde(pmap_t pmap, vm_offset_t va, pd_entry_t newpde, u_int flags,
} else {
KASSERT(SLIST_EMPTY(&free),
("pmap_enter_pde: freed kernel page table page"));
-
- /*
- * Both pmap_remove_pde() and pmap_remove_ptes() will
- * leave the kernel page table page zero filled.
- */
- mt = PHYS_TO_VM_PAGE(*pde & PG_FRAME);
- if (pmap_insert_pt_page(pmap, mt, false, false))
- panic("pmap_enter_pde: trie insert failed");
}
}
@@ -9547,7 +9579,7 @@ pmap_unmapdev(void *p, vm_size_t size)
* Tries to demote a 1GB page mapping.
*/
static bool
-pmap_demote_pdpe(pmap_t pmap, pdp_entry_t *pdpe, vm_offset_t va)
+pmap_demote_pdpe(pmap_t pmap, pdp_entry_t *pdpe, vm_offset_t va, vm_page_t m)
{
pdp_entry_t newpdpe, oldpdpe;
pd_entry_t *firstpde, newpde, *pde;
@@ -9564,12 +9596,19 @@ pmap_demote_pdpe(pmap_t pmap, pdp_entry_t *pdpe, vm_offset_t va)
oldpdpe = *pdpe;
KASSERT((oldpdpe & (PG_PS | PG_V)) == (PG_PS | PG_V),
("pmap_demote_pdpe: oldpdpe is missing PG_PS and/or PG_V"));
- pdpg = pmap_alloc_pt_page(pmap, va >> PDPSHIFT,
- VM_ALLOC_WIRED | VM_ALLOC_INTERRUPT);
- if (pdpg == NULL) {
- CTR2(KTR_PMAP, "pmap_demote_pdpe: failure for va %#lx"
- " in pmap %p", va, pmap);
- return (false);
+ if (m == NULL) {
+ pdpg = pmap_alloc_pt_page(pmap, va >> PDPSHIFT,
+ VM_ALLOC_WIRED);
+ if (pdpg == NULL) {
+ CTR2(KTR_PMAP,
+ "pmap_demote_pdpe: failure for va %#lx in pmap %p",
+ va, pmap);
+ return (false);
+ }
+ } else {
+ pdpg = m;
+ pdpg->pindex = va >> PDPSHIFT;
+ pmap_pt_page_count_adj(pmap, 1);
}
pdpgpa = VM_PAGE_TO_PHYS(pdpg);
firstpde = (pd_entry_t *)PHYS_TO_DMAP(pdpgpa);
@@ -9779,7 +9818,7 @@ pmap_change_props_locked(vm_offset_t va, vm_size_t size, vm_prot_t prot,
tmpva += NBPDP;
continue;
}
- if (!pmap_demote_pdpe(kernel_pmap, pdpe, tmpva))
+ if (!pmap_demote_pdpe(kernel_pmap, pdpe, tmpva, NULL))
return (ENOMEM);
}
pde = pmap_pdpe_to_pde(pdpe, tmpva);
@@ -9937,11 +9976,13 @@ pmap_change_props_locked(vm_offset_t va, vm_size_t size, vm_prot_t prot,
}
/*
- * Demotes any mapping within the direct map region that covers more than the
- * specified range of physical addresses. This range's size must be a power
- * of two and its starting address must be a multiple of its size. Since the
- * demotion does not change any attributes of the mapping, a TLB invalidation
- * is not mandatory. The caller may, however, request a TLB invalidation.
+ * Demotes any mapping within the direct map region that covers more
+ * than the specified range of physical addresses. This range's size
+ * must be a power of two and its starting address must be a multiple
+ * of its size, which means that any pdp from the mapping is fully
+ * covered by the range if len > NBPDP. Since the demotion does not
+ * change any attributes of the mapping, a TLB invalidation is not
+ * mandatory. The caller may, however, request a TLB invalidation.
*/
void
pmap_demote_DMAP(vm_paddr_t base, vm_size_t len, bool invalidate)
@@ -9949,38 +9990,67 @@ pmap_demote_DMAP(vm_paddr_t base, vm_size_t len, bool invalidate)
pdp_entry_t *pdpe;
pd_entry_t *pde;
vm_offset_t va;
- bool changed;
+ vm_page_t m, mpte;
+ bool changed, rv __diagused;
if (len == 0)
return;
KASSERT(powerof2(len), ("pmap_demote_DMAP: len is not a power of 2"));
KASSERT((base & (len - 1)) == 0,
("pmap_demote_DMAP: base is not a multiple of len"));
+ WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL, "pmap_demote_DMAP");
+
if (len < NBPDP && base < dmaplimit) {
va = PHYS_TO_DMAP(base);
changed = false;
+
+ /*
+ * Assume that it is fine to sleep there.
+ * The only existing caller of pmap_demote_DMAP() is the
+ * x86_mr_split_dmap() function.
+ */
+ m = vm_page_alloc_noobj(VM_ALLOC_WIRED | VM_ALLOC_WAITOK);
+ if (len < NBPDR) {
+ mpte = vm_page_alloc_noobj(VM_ALLOC_WIRED |
+ VM_ALLOC_WAITOK);
+ } else
+ mpte = NULL;
+
PMAP_LOCK(kernel_pmap);
pdpe = pmap_pdpe(kernel_pmap, va);
if ((*pdpe & X86_PG_V) == 0)
panic("pmap_demote_DMAP: invalid PDPE");
if ((*pdpe & PG_PS) != 0) {
- if (!pmap_demote_pdpe(kernel_pmap, pdpe, va))
- panic("pmap_demote_DMAP: PDPE failed");
+ rv = pmap_demote_pdpe(kernel_pmap, pdpe, va, m);
+ KASSERT(rv, ("pmap_demote_DMAP: PDPE failed"));
changed = true;
+ m = NULL;
}
if (len < NBPDR) {
pde = pmap_pdpe_to_pde(pdpe, va);
if ((*pde & X86_PG_V) == 0)
panic("pmap_demote_DMAP: invalid PDE");
if ((*pde & PG_PS) != 0) {
- if (!pmap_demote_pde(kernel_pmap, pde, va))
- panic("pmap_demote_DMAP: PDE failed");
+ mpte->pindex = pmap_pde_pindex(va);
+ pmap_pt_page_count_adj(kernel_pmap, 1);
+ rv = pmap_demote_pde_mpte(kernel_pmap, pde, va,
+ NULL, mpte);
+ KASSERT(rv, ("pmap_demote_DMAP: PDE failed"));
changed = true;
+ mpte = NULL;
}
}
if (changed && invalidate)
pmap_invalidate_page(kernel_pmap, va);
PMAP_UNLOCK(kernel_pmap);
+ if (m != NULL) {
+ vm_page_unwire_noq(m);
+ vm_page_free(m);
+ }
+ if (mpte != NULL) {
+ vm_page_unwire_noq(mpte);
+ vm_page_free(mpte);
+ }
}
}
diff --git a/sys/amd64/include/efi.h b/sys/amd64/include/efi.h
index b47c4aa27ac7..439f2f0b317d 100644
--- a/sys/amd64/include/efi.h
+++ b/sys/amd64/include/efi.h
@@ -53,6 +53,10 @@
#define EFI_TIME_OWNED() mtx_assert(&atrtc_time_lock, MA_OWNED)
#define EFI_RT_HANDLE_FAULTS_DEFAULT 1
+
+#define EFI_MAP_BOOTTYPE_ALLOWED(type) (((efi_map_regs >> (type)) & 1) != 0)
+
+extern uint32_t efi_map_regs;
#endif
struct efirt_callinfo {
diff --git a/sys/cam/cam_xpt.h b/sys/cam/cam_xpt.h
index 06ef52580120..57225a0ae92d 100644
--- a/sys/cam/cam_xpt.h
+++ b/sys/cam/cam_xpt.h
@@ -145,15 +145,15 @@ uint32_t xpt_poll_setup(union ccb *start_ccb);
void xpt_sim_poll(struct cam_sim *sim);
/*
- * Perform a path inquiry at the request priority. The bzero may be
- * unnecessary.
+ * Perform a path inquiry at the request priority. bzero may be redundant for
+ * allocated CCBs, but for the on-stack CCBs it's required.
*/
static inline void
xpt_path_inq(struct ccb_pathinq *cpi, struct cam_path *path)
{
bzero(cpi, sizeof(*cpi));
- xpt_setup_ccb(&cpi->ccb_h, path, CAM_PRIORITY_NORMAL);
+ xpt_setup_ccb(&cpi->ccb_h, path, CAM_PRIORITY_NONE);
cpi->ccb_h.func_code = XPT_PATH_INQ;
xpt_action((union ccb *)cpi);
}
diff --git a/sys/cam/mmc/mmc_da.c b/sys/cam/mmc/mmc_da.c
index 9246f95a080e..f7c478076144 100644
--- a/sys/cam/mmc/mmc_da.c
+++ b/sys/cam/mmc/mmc_da.c
@@ -789,7 +789,8 @@ sddaregister(struct cam_periph *periph, void *arg)
static int
mmc_exec_app_cmd(struct cam_periph *periph, union ccb *ccb,
- struct mmc_command *cmd) {
+ struct mmc_command *cmd)
+{
int err;
/* Send APP_CMD first */
@@ -843,7 +844,8 @@ mmc_exec_app_cmd(struct cam_periph *periph, union ccb *ccb,
}
static int
-mmc_app_get_scr(struct cam_periph *periph, union ccb *ccb, uint32_t *rawscr) {
+mmc_app_get_scr(struct cam_periph *periph, union ccb *ccb, uint32_t *rawscr)
+{
int err;
struct mmc_command cmd;
struct mmc_data d;
@@ -869,7 +871,8 @@ mmc_app_get_scr(struct cam_periph *periph, union ccb *ccb, uint32_t *rawscr) {
static int
mmc_send_ext_csd(struct cam_periph *periph, union ccb *ccb,
- uint8_t *rawextcsd, size_t buf_len) {
+ uint8_t *rawextcsd, size_t buf_len)
+{
int err;
struct mmc_data d;
@@ -966,14 +969,16 @@ mmc_switch(struct cam_periph *periph, union ccb *ccb,
}
static uint32_t
-mmc_get_spec_vers(struct cam_periph *periph) {
+mmc_get_spec_vers(struct cam_periph *periph)
+{
struct sdda_softc *softc = (struct sdda_softc *)periph->softc;
return (softc->csd.spec_vers);
}
static uint64_t
-mmc_get_media_size(struct cam_periph *periph) {
+mmc_get_media_size(struct cam_periph *periph)
+{
struct sdda_softc *softc = (struct sdda_softc *)periph->softc;
return (softc->mediasize);
@@ -992,7 +997,8 @@ mmc_get_cmd6_timeout(struct cam_periph *periph)
static int
mmc_sd_switch(struct cam_periph *periph, union ccb *ccb,
uint8_t mode, uint8_t grp, uint8_t value,
- uint8_t *res) {
+ uint8_t *res)
+{
struct mmc_data mmc_d;
uint32_t arg;
int err;
@@ -1069,7 +1075,8 @@ mmc_set_timing(struct cam_periph *periph,
}
static void
-sdda_start_init_task(void *context, int pending) {
+sdda_start_init_task(void *context, int pending)
+{
union ccb *new_ccb;
struct cam_periph *periph;
@@ -1088,7 +1095,8 @@ sdda_start_init_task(void *context, int pending) {
}
static void
-sdda_set_bus_width(struct cam_periph *periph, union ccb *ccb, int width) {
+sdda_set_bus_width(struct cam_periph *periph, union ccb *ccb, int width)
+{
struct sdda_softc *softc = (struct sdda_softc *)periph->softc;
struct mmc_params *mmcp = &periph->path->device->mmc_ident_data;
int err;
@@ -1523,10 +1531,7 @@ sdda_add_part(struct cam_periph *periph, u_int type, const char *name,
bioq_init(&part->bio_queue);
- bzero(&cpi, sizeof(cpi));
- xpt_setup_ccb(&cpi.ccb_h, periph->path, CAM_PRIORITY_NONE);
- cpi.ccb_h.func_code = XPT_PATH_INQ;
- xpt_action((union ccb *)&cpi);
+ xpt_path_inq(&cpi, periph->path);
/*
* Register this media as a disk
diff --git a/sys/cam/scsi/scsi_xpt.c b/sys/cam/scsi/scsi_xpt.c
index 439dd2050a95..bef35243af98 100644
--- a/sys/cam/scsi/scsi_xpt.c
+++ b/sys/cam/scsi/scsi_xpt.c
@@ -1915,6 +1915,15 @@ typedef struct {
int lunindex[0];
} scsi_scan_bus_info;
+static void
+free_scan_info(scsi_scan_bus_info *scan_info)
+{
+ KASSERT(scan_info->cpi != NULL,
+ ("scan_info (%p) missing its ccb_pathinq CCB\n", scan_info));
+ xpt_free_ccb((union ccb *)scan_info->cpi);
+ free(scan_info, M_CAMXPT);
+}
+
/*
* To start a scan, request_ccb is an XPT_SCAN_BUS ccb.
* As the scan progresses, scsi_scan_bus is used as the
@@ -1945,10 +1954,7 @@ scsi_scan_bus(struct cam_periph *periph, union ccb *request_ccb)
xpt_done(request_ccb);
return;
}
- xpt_setup_ccb(&work_ccb->ccb_h, request_ccb->ccb_h.path,
- request_ccb->ccb_h.pinfo.priority);
- work_ccb->ccb_h.func_code = XPT_PATH_INQ;
- xpt_action(work_ccb);
+ xpt_path_inq(&work_ccb->cpi, request_ccb->ccb_h.path);
if (work_ccb->ccb_h.status != CAM_REQ_CMP) {
request_ccb->ccb_h.status = work_ccb->ccb_h.status;
xpt_free_ccb(work_ccb);
@@ -2037,16 +2043,14 @@ scsi_scan_bus(struct cam_periph *periph, union ccb *request_ccb)
printf(
"scsi_scan_bus: xpt_create_path failed with status %#x, bus scan halted\n",
status);
- free(scan_info, M_CAMXPT);
+ free_scan_info(scan_info);
request_ccb->ccb_h.status = status;
- xpt_free_ccb(work_ccb);
xpt_done(request_ccb);
break;
}
work_ccb = xpt_alloc_ccb_nowait();
if (work_ccb == NULL) {
- xpt_free_ccb((union ccb *)scan_info->cpi);
- free(scan_info, M_CAMXPT);
+ free_scan_info(scan_info);
xpt_free_path(path);
request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
xpt_done(request_ccb);
@@ -2179,16 +2183,16 @@ scsi_scan_bus(struct cam_periph *periph, union ccb *request_ccb)
* Check to see if we scan any further luns.
*/
if (next_target) {
- int done;
+ bool done;
/*
* Free the current request path- we're done with it.
*/
xpt_free_path(oldpath);
hop_again:
- done = 0;
+ done = false;
if (scan_info->request_ccb->ccb_h.func_code == XPT_SCAN_TGT) {
- done = 1;
+ done = true;
} else if (scan_info->cpi->hba_misc & PIM_SEQSCAN) {
scan_info->counter++;
if (scan_info->counter ==
@@ -2197,23 +2201,22 @@ scsi_scan_bus(struct cam_periph *periph, union ccb *request_ccb)
}
if (scan_info->counter >=
scan_info->cpi->max_target+1) {
- done = 1;
+ done = true;
}
} else {
scan_info->counter--;
if (scan_info->counter == 0) {
- done = 1;
+ done = true;
}
}
if (done) {
mtx_unlock(mtx);
xpt_free_ccb(request_ccb);
- xpt_free_ccb((union ccb *)scan_info->cpi);
request_ccb = scan_info->request_ccb;
CAM_DEBUG(request_ccb->ccb_h.path,
CAM_DEBUG_TRACE,
("SCAN done for %p\n", scan_info));
- free(scan_info, M_CAMXPT);
+ free_scan_info(scan_info);
request_ccb->ccb_h.status = CAM_REQ_CMP;
xpt_done(request_ccb);
break;
@@ -2233,9 +2236,8 @@ scsi_scan_bus(struct cam_periph *periph, union ccb *request_ccb)
"scsi_scan_bus: xpt_create_path failed with status %#x, bus scan halted\n",
status);
xpt_free_ccb(request_ccb);
- xpt_free_ccb((union ccb *)scan_info->cpi);
request_ccb = scan_info->request_ccb;
- free(scan_info, M_CAMXPT);
+ free_scan_info(scan_info);
request_ccb->ccb_h.status = status;
xpt_done(request_ccb);
break;
@@ -2294,10 +2296,7 @@ scsi_scan_lun(struct cam_periph *periph, struct cam_path *path,
CAM_DEBUG(path, CAM_DEBUG_TRACE, ("scsi_scan_lun\n"));
- memset(&cpi, 0, sizeof(cpi));
- xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
- cpi.ccb_h.func_code = XPT_PATH_INQ;
- xpt_action((union ccb *)&cpi);
+ xpt_path_inq(&cpi, path);
if (cpi.ccb_h.status != CAM_REQ_CMP) {
if (request_ccb != NULL) {
@@ -2421,10 +2420,7 @@ scsi_devise_transport(struct cam_path *path)
struct scsi_inquiry_data *inq_buf;
/* Get transport information from the SIM */
- memset(&cpi, 0, sizeof(cpi));
- xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
- cpi.ccb_h.func_code = XPT_PATH_INQ;
- xpt_action((union ccb *)&cpi);
+ xpt_path_inq(&cpi, path);
inq_buf = NULL;
if ((path->device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0)
@@ -2732,10 +2728,7 @@ scsi_set_transfer_settings(struct ccb_trans_settings *cts, struct cam_path *path
inq_data = &device->inq_data;
scsi = &cts->proto_specific.scsi;
- memset(&cpi, 0, sizeof(cpi));
- xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
- cpi.ccb_h.func_code = XPT_PATH_INQ;
- xpt_action((union ccb *)&cpi);
+ xpt_path_inq(&cpi, path);
/* SCSI specific sanity checking */
if ((cpi.hba_inquiry & PI_TAG_ABLE) == 0
@@ -3046,10 +3039,7 @@ _scsi_announce_periph(struct cam_periph *periph, u_int *speed, u_int *freq, stru
return;
/* Ask the SIM for its base transfer speed */
- memset(&cpi, 0, sizeof(cpi));
- xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NORMAL);
- cpi.ccb_h.func_code = XPT_PATH_INQ;
- xpt_action((union ccb *)&cpi);
+ xpt_path_inq(&cpi, path);
/* Report connection speed */
*speed = cpi.base_transfer_speed;
diff --git a/sys/compat/freebsd32/freebsd32_sysent.c b/sys/compat/freebsd32/freebsd32_sysent.c
index 3718a1b0c8ee..ef0aff8bf852 100644
--- a/sys/compat/freebsd32/freebsd32_sysent.c
+++ b/sys/compat/freebsd32/freebsd32_sysent.c
@@ -659,7 +659,7 @@ struct sysent freebsd32_sysent[] = {
{ .sy_narg = AS(getrlimitusage_args), .sy_call = (sy_call_t *)sys_getrlimitusage, .sy_auevent = AUE_NULL, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 589 = getrlimitusage */
{ .sy_narg = AS(fchroot_args), .sy_call = (sy_call_t *)sys_fchroot, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 590 = fchroot */
{ .sy_narg = AS(freebsd32_setcred_args), .sy_call = (sy_call_t *)freebsd32_setcred, .sy_auevent = AUE_SETCRED, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 591 = freebsd32_setcred */
- { .sy_narg = AS(exterrctl_args), .sy_call = (sy_call_t *)sys_exterrctl, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 592 = exterrctl */
+ { .sy_narg = AS(exterrctl_args), .sy_call = (sy_call_t *)sys_exterrctl, .sy_auevent = AUE_NULL, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 592 = exterrctl */
{ .sy_narg = AS(inotify_add_watch_at_args), .sy_call = (sy_call_t *)sys_inotify_add_watch_at, .sy_auevent = AUE_INOTIFY, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 593 = inotify_add_watch_at */
{ .sy_narg = AS(inotify_rm_watch_args), .sy_call = (sy_call_t *)sys_inotify_rm_watch, .sy_auevent = AUE_INOTIFY, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 594 = inotify_rm_watch */
};
diff --git a/sys/conf/files b/sys/conf/files
index dd6f9a3021d4..74d251c2b608 100644
--- a/sys/conf/files
+++ b/sys/conf/files
@@ -598,42 +598,24 @@ contrib/dev/acpica/components/utilities/utxface.c optional acpi
contrib/dev/acpica/components/utilities/utxferror.c optional acpi
contrib/dev/acpica/components/utilities/utxfinit.c optional acpi
contrib/dev/acpica/os_specific/service_layers/osgendbg.c optional acpi acpi_debug
-netpfil/ipfilter/netinet/fil.c optional ipfilter inet \
- compile-with "${NORMAL_C} ${NO_WSELF_ASSIGN} -Wno-unused -I$S/netpfil/ipfilter"
-netpfil/ipfilter/netinet/ip_auth.c optional ipfilter inet \
- compile-with "${NORMAL_C} -Wno-unused -I$S/netpfil/ipfilter"
-netpfil/ipfilter/netinet/ip_fil_freebsd.c optional ipfilter inet \
- compile-with "${NORMAL_C} -Wno-unused -I$S/netpfil/ipfilter"
-netpfil/ipfilter/netinet/ip_frag.c optional ipfilter inet \
- compile-with "${NORMAL_C} -Wno-unused -I$S/netpfil/ipfilter"
-netpfil/ipfilter/netinet/ip_log.c optional ipfilter inet \
- compile-with "${NORMAL_C} -I$S/netpfil/ipfilter"
-netpfil/ipfilter/netinet/ip_nat.c optional ipfilter inet \
- compile-with "${NORMAL_C} -Wno-unused -I$S/netpfil/ipfilter"
-netpfil/ipfilter/netinet/ip_proxy.c optional ipfilter inet \
- compile-with "${NORMAL_C} ${NO_WSELF_ASSIGN} -Wno-unused -I$S/netpfil/ipfilter"
-netpfil/ipfilter/netinet/ip_state.c optional ipfilter inet \
- compile-with "${NORMAL_C} -Wno-unused -I$S/netpfil/ipfilter"
-netpfil/ipfilter/netinet/ip_lookup.c optional ipfilter inet \
- compile-with "${NORMAL_C} ${NO_WSELF_ASSIGN} -Wno-unused -Wno-error -I$S/netpfil/ipfilter"
-netpfil/ipfilter/netinet/ip_pool.c optional ipfilter inet \
- compile-with "${NORMAL_C} -Wno-unused -I$S/netpfil/ipfilter"
-netpfil/ipfilter/netinet/ip_htable.c optional ipfilter inet \
- compile-with "${NORMAL_C} -Wno-unused -I$S/netpfil/ipfilter ${NO_WTAUTOLOGICAL_POINTER_COMPARE}"
-netpfil/ipfilter/netinet/ip_sync.c optional ipfilter inet \
- compile-with "${NORMAL_C} -Wno-unused -I$S/netpfil/ipfilter"
-netpfil/ipfilter/netinet/mlfk_ipl.c optional ipfilter inet \
- compile-with "${NORMAL_C} -I$S/netpfil/ipfilter"
-netpfil/ipfilter/netinet/ip_nat6.c optional ipfilter inet \
- compile-with "${NORMAL_C} -Wno-unused -I$S/netpfil/ipfilter"
-netpfil/ipfilter/netinet/ip_rules.c optional ipfilter inet \
- compile-with "${NORMAL_C} -I$S/netpfil/ipfilter"
-netpfil/ipfilter/netinet/ip_scan.c optional ipfilter inet \
- compile-with "${NORMAL_C} -Wno-unused -I$S/netpfil/ipfilter"
-netpfil/ipfilter/netinet/ip_dstlist.c optional ipfilter inet \
- compile-with "${NORMAL_C} -Wno-unused -I$S/netpfil/ipfilter"
-netpfil/ipfilter/netinet/radix_ipf.c optional ipfilter inet \
- compile-with "${NORMAL_C} -I$S/netpfil/ipfilter"
+netpfil/ipfilter/netinet/fil.c optional ipfilter inet compile-with "${IPFILTER_C}"
+netpfil/ipfilter/netinet/ip_auth.c optional ipfilter inet compile-with "${IPFILTER_C}"
+netpfil/ipfilter/netinet/ip_fil_freebsd.c optional ipfilter inet compile-with "${IPFILTER_C}"
+netpfil/ipfilter/netinet/ip_frag.c optional ipfilter inet compile-with "${IPFILTER_C}"
+netpfil/ipfilter/netinet/ip_log.c optional ipfilter inet compile-with "${IPFILTER_C}"
+netpfil/ipfilter/netinet/ip_nat.c optional ipfilter inet compile-with "${IPFILTER_C}"
+netpfil/ipfilter/netinet/ip_proxy.c optional ipfilter inet compile-with "${IPFILTER_C}"
+netpfil/ipfilter/netinet/ip_state.c optional ipfilter inet compile-with "${IPFILTER_C}"
+netpfil/ipfilter/netinet/ip_lookup.c optional ipfilter inet compile-with "${IPFILTER_C}"
+netpfil/ipfilter/netinet/ip_pool.c optional ipfilter inet compile-with "${IPFILTER_C}"
+netpfil/ipfilter/netinet/ip_htable.c optional ipfilter inet compile-with "${IPFILTER_C}"
+netpfil/ipfilter/netinet/ip_sync.c optional ipfilter inet compile-with "${IPFILTER_C}"
+netpfil/ipfilter/netinet/mlfk_ipl.c optional ipfilter inet compile-with "${IPFILTER_C}"
+netpfil/ipfilter/netinet/ip_nat6.c optional ipfilter inet compile-with "${IPFILTER_C}"
+netpfil/ipfilter/netinet/ip_rules.c optional ipfilter inet compile-with "${IPFILTER_C}"
+netpfil/ipfilter/netinet/ip_scan.c optional ipfilter inet compile-with "${IPFILTER_C}"
+netpfil/ipfilter/netinet/ip_dstlist.c optional ipfilter inet compile-with "${IPFILTER_C}"
+netpfil/ipfilter/netinet/radix_ipf.c optional ipfilter inet compile-with "${IPFILTER_C}"
contrib/libfdt/fdt.c optional fdt
contrib/libfdt/fdt_ro.c optional fdt
contrib/libfdt/fdt_rw.c optional fdt
@@ -3173,8 +3155,6 @@ dev/sound/midi/midi.c optional sound
dev/sound/midi/mpu401.c optional sound
dev/sound/midi/mpu_if.m optional sound
dev/sound/midi/mpufoi_if.m optional sound
-dev/sound/midi/sequencer.c optional sound
-dev/sound/midi/synth_if.m optional sound
dev/spibus/acpi_spibus.c optional acpi spibus
dev/spibus/ofw_spibus.c optional fdt spibus
dev/spibus/spibus.c optional spibus \
diff --git a/sys/conf/kern.pre.mk b/sys/conf/kern.pre.mk
index e6e42b33a9b7..78178065e15b 100644
--- a/sys/conf/kern.pre.mk
+++ b/sys/conf/kern.pre.mk
@@ -290,6 +290,10 @@ BNXT_CFLAGS= -I$S/dev/bnxt/bnxt_en ${OFEDCFLAGS}
BNXT_C_NOIMP= ${CC} -c -o ${.TARGET} ${BNXT_CFLAGS} ${WERROR}
BNXT_C= ${BNXT_C_NOIMP} ${.IMPSRC}
+# IP Filter
+IPFILTER_CFLAGS= -I$S/netpfil/ipfilter
+IPFILTER_C= ${NORMAL_C} ${IPFILTER_CFLAGS}
+
GEN_CFILES= $S/$M/$M/genassym.c ${MFILES:T:S/.m$/.c/}
SYSTEM_CFILES= config.c env.c hints.c vnode_if.c
SYSTEM_DEP= Makefile ${SYSTEM_OBJS}
diff --git a/sys/dev/ichiic/ig4_pci.c b/sys/dev/ichiic/ig4_pci.c
index 0195466150eb..3a49e220e335 100644
--- a/sys/dev/ichiic/ig4_pci.c
+++ b/sys/dev/ichiic/ig4_pci.c
@@ -186,6 +186,12 @@ static int ig4iic_pci_detach(device_t dev);
#define PCI_CHIP_METEORLAKE_M_I2C_3 0x7e518086
#define PCI_CHIP_METEORLAKE_M_I2C_4 0x7e7a8086
#define PCI_CHIP_METEORLAKE_M_I2C_5 0x7e7b8086
+#define PCI_CHIP_ARROWLAKE_U_I2C_0 0x77788086
+#define PCI_CHIP_ARROWLAKE_U_I2C_1 0x77798086
+#define PCI_CHIP_ARROWLAKE_U_I2C_2 0x777a8086
+#define PCI_CHIP_ARROWLAKE_U_I2C_3 0x777b8086
+#define PCI_CHIP_ARROWLAKE_U_I2C_4 0x77508086
+#define PCI_CHIP_ARROWLAKE_U_I2C_5 0x77518086
struct ig4iic_pci_device {
uint32_t devid;
@@ -316,6 +322,12 @@ static struct ig4iic_pci_device ig4iic_pci_devices[] = {
{ PCI_CHIP_METEORLAKE_M_I2C_3, "Intel Meteor Lake-M I2C Controller-3", IG4_TIGERLAKE},
{ PCI_CHIP_METEORLAKE_M_I2C_4, "Intel Meteor Lake-M I2C Controller-4", IG4_TIGERLAKE},
{ PCI_CHIP_METEORLAKE_M_I2C_5, "Intel Meteor Lake-M I2C Controller-5", IG4_TIGERLAKE},
+ { PCI_CHIP_ARROWLAKE_U_I2C_0, "Intel Arrow Lake-H/U I2C Controller-0", IG4_TIGERLAKE},
+ { PCI_CHIP_ARROWLAKE_U_I2C_1, "Intel Arrow Lake-H/U I2C Controller-1", IG4_TIGERLAKE},
+ { PCI_CHIP_ARROWLAKE_U_I2C_2, "Intel Arrow Lake-H/U I2C Controller-2", IG4_TIGERLAKE},
+ { PCI_CHIP_ARROWLAKE_U_I2C_3, "Intel Arrow Lake-H/U I2C Controller-3", IG4_TIGERLAKE},
+ { PCI_CHIP_ARROWLAKE_U_I2C_4, "Intel Arrow Lake-H/U I2C Controller-4", IG4_TIGERLAKE},
+ { PCI_CHIP_ARROWLAKE_U_I2C_5, "Intel Arrow Lake-H/U I2C Controller-5", IG4_TIGERLAKE},
};
static int
diff --git a/sys/dev/mem/memutil.c b/sys/dev/mem/memutil.c
index cf9714d6ec8f..20ce337df0ab 100644
--- a/sys/dev/mem/memutil.c
+++ b/sys/dev/mem/memutil.c
@@ -26,15 +26,14 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <sys/param.h>
+#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/memrange.h>
-#include <sys/rwlock.h>
-#include <sys/systm.h>
+#include <sys/sx.h>
-static struct rwlock mr_lock;
+static struct sx mr_lock;
/*
* Implementation-neutral, kernel-callable functions for manipulating
@@ -46,7 +45,7 @@ mem_range_init(void)
if (mem_range_softc.mr_op == NULL)
return;
- rw_init(&mr_lock, "memrange");
+ sx_init(&mr_lock, "memrange");
mem_range_softc.mr_op->init(&mem_range_softc);
}
@@ -56,7 +55,7 @@ mem_range_destroy(void)
if (mem_range_softc.mr_op == NULL)
return;
- rw_destroy(&mr_lock);
+ sx_destroy(&mr_lock);
}
int
@@ -67,12 +66,12 @@ mem_range_attr_get(struct mem_range_desc *mrd, int *arg)
if (mem_range_softc.mr_op == NULL)
return (EOPNOTSUPP);
nd = *arg;
- rw_rlock(&mr_lock);
+ sx_slock(&mr_lock);
if (nd == 0)
*arg = mem_range_softc.mr_ndesc;
else
bcopy(mem_range_softc.mr_desc, mrd, nd * sizeof(*mrd));
- rw_runlock(&mr_lock);
+ sx_sunlock(&mr_lock);
return (0);
}
@@ -83,8 +82,8 @@ mem_range_attr_set(struct mem_range_desc *mrd, int *arg)
if (mem_range_softc.mr_op == NULL)
return (EOPNOTSUPP);
- rw_wlock(&mr_lock);
+ sx_xlock(&mr_lock);
ret = mem_range_softc.mr_op->set(&mem_range_softc, mrd, arg);
- rw_wunlock(&mr_lock);
+ sx_xunlock(&mr_lock);
return (ret);
}
diff --git a/sys/dev/mlx5/mlx5_en/mlx5_en_hw_tls_rx.c b/sys/dev/mlx5/mlx5_en/mlx5_en_hw_tls_rx.c
index 8b8f2e570245..4de451f1b039 100644
--- a/sys/dev/mlx5/mlx5_en/mlx5_en_hw_tls_rx.c
+++ b/sys/dev/mlx5/mlx5_en/mlx5_en_hw_tls_rx.c
@@ -42,13 +42,30 @@
static if_snd_tag_free_t mlx5e_tls_rx_snd_tag_free;
static if_snd_tag_modify_t mlx5e_tls_rx_snd_tag_modify;
+static if_snd_tag_status_str_t mlx5e_tls_rx_snd_tag_status_str;
static const struct if_snd_tag_sw mlx5e_tls_rx_snd_tag_sw = {
.snd_tag_modify = mlx5e_tls_rx_snd_tag_modify,
.snd_tag_free = mlx5e_tls_rx_snd_tag_free,
+ .snd_tag_status_str = mlx5e_tls_rx_snd_tag_status_str,
.type = IF_SND_TAG_TYPE_TLS_RX
};
+static const char *mlx5e_tls_rx_progress_params_auth_state_str[] = {
+ [MLX5E_TLS_RX_PROGRESS_PARAMS_AUTH_STATE_NO_OFFLOAD] = "no_offload",
+ [MLX5E_TLS_RX_PROGRESS_PARAMS_AUTH_STATE_OFFLOAD] = "offload",
+ [MLX5E_TLS_RX_PROGRESS_PARAMS_AUTH_STATE_AUTHENTICATION] =
+ "authentication",
+};
+
+static const char *mlx5e_tls_rx_progress_params_record_tracker_state_str[] = {
+ [MLX5E_TLS_RX_PROGRESS_PARAMS_RECORD_TRACKER_STATE_START] = "start",
+ [MLX5E_TLS_RX_PROGRESS_PARAMS_RECORD_TRACKER_STATE_TRACKING] =
+ "tracking",
+ [MLX5E_TLS_RX_PROGRESS_PARAMS_RECORD_TRACKER_STATE_SEARCHING] =
+ "searching",
+};
+
MALLOC_DEFINE(M_MLX5E_TLS_RX, "MLX5E_TLS_RX", "MLX5 ethernet HW TLS RX");
/* software TLS RX context */
@@ -250,7 +267,8 @@ mlx5e_tls_rx_send_progress_parameters_sync(struct mlx5e_iq *iq,
mtx_unlock(&iq->lock);
while (1) {
- if (wait_for_completion_timeout(&ptag->progress_complete, hz) != 0)
+ if (wait_for_completion_timeout(&ptag->progress_complete,
+ msecs_to_jiffies(1000)) != 0)
break;
priv = container_of(iq, struct mlx5e_channel, iq)->priv;
if (priv->mdev->state == MLX5_DEVICE_STATE_INTERNAL_ERROR ||
@@ -331,7 +349,8 @@ done:
* Zero is returned upon success, else some error happened.
*/
static int
-mlx5e_tls_rx_receive_progress_parameters(struct mlx5e_iq *iq, struct mlx5e_tls_rx_tag *ptag)
+mlx5e_tls_rx_receive_progress_parameters(struct mlx5e_iq *iq,
+ struct mlx5e_tls_rx_tag *ptag, mlx5e_iq_callback_t *cb)
{
struct mlx5e_get_tls_progress_params_wqe *wqe;
const u32 ds_cnt = DIV_ROUND_UP(sizeof(*wqe), MLX5_SEND_WQE_DS);
@@ -367,7 +386,7 @@ mlx5e_tls_rx_receive_progress_parameters(struct mlx5e_iq *iq, struct mlx5e_tls_r
memcpy(iq->doorbell.d32, &wqe->ctrl, sizeof(iq->doorbell.d32));
iq->data[pi].num_wqebbs = DIV_ROUND_UP(ds_cnt, MLX5_SEND_WQEBB_NUM_DS);
- iq->data[pi].callback = &mlx5e_tls_rx_receive_progress_parameters_cb;
+ iq->data[pi].callback = cb;
iq->data[pi].arg = ptag;
m_snd_tag_ref(&ptag->tag);
@@ -819,6 +838,7 @@ mlx5e_tls_rx_snd_tag_alloc(if_t ifp,
}
ptag->flow_rule = flow_rule;
+ init_completion(&ptag->progress_complete);
return (0);
@@ -968,7 +988,8 @@ mlx5e_tls_rx_snd_tag_modify(struct m_snd_tag *pmt, union if_snd_tag_modify_param
params->tls_rx.tls_rec_length,
params->tls_rx.tls_seq_number) &&
ptag->tcp_resync_pending == 0) {
- err = mlx5e_tls_rx_receive_progress_parameters(iq, ptag);
+ err = mlx5e_tls_rx_receive_progress_parameters(iq, ptag,
+ &mlx5e_tls_rx_receive_progress_parameters_cb);
if (err != 0) {
MLX5E_TLS_RX_STAT_INC(ptag, rx_resync_err, 1);
} else {
@@ -1001,6 +1022,74 @@ mlx5e_tls_rx_snd_tag_free(struct m_snd_tag *pmt)
queue_work(priv->tls_rx.wq, &ptag->work);
}
+static void
+mlx5e_tls_rx_str_status_cb(void *arg)
+{
+ struct mlx5e_tls_rx_tag *ptag;
+
+ ptag = (struct mlx5e_tls_rx_tag *)arg;
+ complete_all(&ptag->progress_complete);
+ m_snd_tag_rele(&ptag->tag);
+}
+
+static int
+mlx5e_tls_rx_snd_tag_status_str(struct m_snd_tag *pmt, char *buf, size_t *sz)
+{
+ int err, out_size;
+ struct mlx5e_iq *iq;
+ void *buffer;
+ uint32_t tracker_state_val;
+ uint32_t auth_state_val;
+ struct mlx5e_priv *priv;
+ struct mlx5e_tls_rx_tag *ptag =
+ container_of(pmt, struct mlx5e_tls_rx_tag, tag);
+
+ if (buf == NULL)
+ return (0);
+
+ MLX5E_TLS_RX_TAG_LOCK(ptag);
+ priv = container_of(ptag->tls_rx, struct mlx5e_priv, tls_rx);
+ iq = mlx5e_tls_rx_get_iq(priv, ptag->flowid, ptag->flowtype);
+ reinit_completion(&ptag->progress_complete);
+ err = mlx5e_tls_rx_receive_progress_parameters(iq, ptag,
+ &mlx5e_tls_rx_str_status_cb);
+ MLX5E_TLS_RX_TAG_UNLOCK(ptag);
+ if (err != 0)
+ return (err);
+
+ for (;;) {
+ if (wait_for_completion_timeout(&ptag->progress_complete,
+ msecs_to_jiffies(1000)) != 0)
+ break;
+ if (priv->mdev->state == MLX5_DEVICE_STATE_INTERNAL_ERROR ||
+ pci_channel_offline(priv->mdev->pdev) != 0)
+ return (ENXIO);
+ }
+ buffer = mlx5e_tls_rx_get_progress_buffer(ptag);
+ tracker_state_val = MLX5_GET(tls_progress_params, buffer,
+ record_tracker_state);
+ auth_state_val = MLX5_GET(tls_progress_params, buffer, auth_state);
+
+ /* Validate tracker state value is in range */
+ if (tracker_state_val >
+ MLX5E_TLS_RX_PROGRESS_PARAMS_RECORD_TRACKER_STATE_SEARCHING)
+ return (EINVAL);
+
+ /* Validate auth state value is in range */
+ if (auth_state_val >
+ MLX5E_TLS_RX_PROGRESS_PARAMS_AUTH_STATE_AUTHENTICATION)
+ return (EINVAL);
+
+ out_size = snprintf(buf, *sz, "tracker_state: %s, auth_state: %s",
+ mlx5e_tls_rx_progress_params_record_tracker_state_str[
+ tracker_state_val],
+ mlx5e_tls_rx_progress_params_auth_state_str[auth_state_val]);
+
+ if (out_size <= *sz)
+ *sz = out_size;
+ return (0);
+}
+
#else
int
diff --git a/sys/dev/nvmf/host/nvmf.c b/sys/dev/nvmf/host/nvmf.c
index dbdd4568bdf1..1ac0d142443b 100644
--- a/sys/dev/nvmf/host/nvmf.c
+++ b/sys/dev/nvmf/host/nvmf.c
@@ -27,6 +27,7 @@
#include <dev/nvmf/host/nvmf_var.h>
static struct cdevsw nvmf_cdevsw;
+static struct taskqueue *nvmf_tq;
bool nvmf_fail_disconnect = false;
SYSCTL_BOOL(_kern_nvmf, OID_AUTO, fail_on_disconnection, CTLFLAG_RWTUN,
@@ -34,7 +35,10 @@ SYSCTL_BOOL(_kern_nvmf, OID_AUTO, fail_on_disconnection, CTLFLAG_RWTUN,
MALLOC_DEFINE(M_NVMF, "nvmf", "NVMe over Fabrics host");
+static void nvmf_controller_loss_task(void *arg, int pending);
static void nvmf_disconnect_task(void *arg, int pending);
+static void nvmf_request_reconnect(struct nvmf_softc *sc);
+static void nvmf_request_reconnect_task(void *arg, int pending);
static void nvmf_shutdown_pre_sync(void *arg, int howto);
static void nvmf_shutdown_post_sync(void *arg, int howto);
@@ -294,6 +298,9 @@ nvmf_establish_connection(struct nvmf_softc *sc, nvlist_t *nvl)
admin = nvlist_get_nvlist(nvl, "admin");
io = nvlist_get_nvlist_array(nvl, "io", &num_io_queues);
kato = dnvlist_get_number(nvl, "kato", 0);
+ sc->reconnect_delay = dnvlist_get_number(nvl, "reconnect_delay", 0);
+ sc->controller_loss_timeout = dnvlist_get_number(nvl,
+ "controller_loss_timeout", 0);
/* Setup the admin queue. */
sc->admin = nvmf_init_qp(sc, trtype, admin, "admin queue", 0);
@@ -504,6 +511,10 @@ nvmf_attach(device_t dev)
callout_init(&sc->ka_tx_timer, 1);
sx_init(&sc->connection_lock, "nvmf connection");
TASK_INIT(&sc->disconnect_task, 0, nvmf_disconnect_task, sc);
+ TIMEOUT_TASK_INIT(nvmf_tq, &sc->controller_loss_task, 0,
+ nvmf_controller_loss_task, sc);
+ TIMEOUT_TASK_INIT(nvmf_tq, &sc->request_reconnect_task, 0,
+ nvmf_request_reconnect_task, sc);
oid = SYSCTL_ADD_NODE(device_get_sysctl_ctx(dev),
SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, "ioq",
@@ -603,7 +614,9 @@ out:
nvmf_destroy_aer(sc);
- taskqueue_drain(taskqueue_thread, &sc->disconnect_task);
+ taskqueue_drain_timeout(nvmf_tq, &sc->request_reconnect_task);
+ taskqueue_drain_timeout(nvmf_tq, &sc->controller_loss_task);
+ taskqueue_drain(nvmf_tq, &sc->disconnect_task);
sx_destroy(&sc->connection_lock);
nvlist_destroy(sc->rparams);
free(sc->cdata, M_NVMF);
@@ -613,7 +626,7 @@ out:
void
nvmf_disconnect(struct nvmf_softc *sc)
{
- taskqueue_enqueue(taskqueue_thread, &sc->disconnect_task);
+ taskqueue_enqueue(nvmf_tq, &sc->disconnect_task);
}
static void
@@ -676,6 +689,74 @@ nvmf_disconnect_task(void *arg, int pending __unused)
nvmf_destroy_qp(sc->admin);
sc->admin = NULL;
+ if (sc->reconnect_delay != 0)
+ nvmf_request_reconnect(sc);
+ if (sc->controller_loss_timeout != 0)
+ taskqueue_enqueue_timeout(nvmf_tq,
+ &sc->controller_loss_task, sc->controller_loss_timeout *
+ hz);
+
+ sx_xunlock(&sc->connection_lock);
+}
+
+static void
+nvmf_controller_loss_task(void *arg, int pending)
+{
+ struct nvmf_softc *sc = arg;
+ device_t dev;
+ int error;
+
+ bus_topo_lock();
+ sx_xlock(&sc->connection_lock);
+ if (sc->admin != NULL || sc->detaching) {
+ /* Reconnected or already detaching. */
+ sx_xunlock(&sc->connection_lock);
+ bus_topo_unlock();
+ return;
+ }
+
+ sc->controller_timedout = true;
+ sx_xunlock(&sc->connection_lock);
+
+ /*
+ * XXX: Doing this from here is a bit ugly. We don't have an
+ * extra reference on `dev` but bus_topo_lock should block any
+ * concurrent device_delete_child invocations.
+ */
+ dev = sc->dev;
+ error = device_delete_child(root_bus, dev);
+ if (error != 0)
+ device_printf(dev,
+ "failed to detach after controller loss: %d\n", error);
+ bus_topo_unlock();
+}
+
+static void
+nvmf_request_reconnect(struct nvmf_softc *sc)
+{
+ char buf[64];
+
+ sx_assert(&sc->connection_lock, SX_LOCKED);
+
+ snprintf(buf, sizeof(buf), "name=\"%s\"", device_get_nameunit(sc->dev));
+ devctl_notify("nvme", "controller", "RECONNECT", buf);
+ taskqueue_enqueue_timeout(nvmf_tq, &sc->request_reconnect_task,
+ sc->reconnect_delay * hz);
+}
+
+static void
+nvmf_request_reconnect_task(void *arg, int pending)
+{
+ struct nvmf_softc *sc = arg;
+
+ sx_xlock(&sc->connection_lock);
+ if (sc->admin != NULL || sc->detaching || sc->controller_timedout) {
+ /* Reconnected or already detaching. */
+ sx_xunlock(&sc->connection_lock);
+ return;
+ }
+
+ nvmf_request_reconnect(sc);
sx_xunlock(&sc->connection_lock);
}
@@ -699,7 +780,7 @@ nvmf_reconnect_host(struct nvmf_softc *sc, struct nvmf_ioc_nv *nv)
}
sx_xlock(&sc->connection_lock);
- if (sc->admin != NULL || sc->detaching) {
+ if (sc->admin != NULL || sc->detaching || sc->controller_timedout) {
error = EBUSY;
goto out;
}
@@ -745,6 +826,9 @@ nvmf_reconnect_host(struct nvmf_softc *sc, struct nvmf_ioc_nv *nv)
nvmf_reconnect_sim(sc);
nvmf_rescan_all_ns(sc);
+
+ taskqueue_cancel_timeout(nvmf_tq, &sc->request_reconnect_task, NULL);
+ taskqueue_cancel_timeout(nvmf_tq, &sc->controller_loss_task, NULL);
out:
sx_xunlock(&sc->connection_lock);
nvlist_destroy(nvl);
@@ -852,7 +936,21 @@ nvmf_detach(device_t dev)
}
free(sc->io, M_NVMF);
- taskqueue_drain(taskqueue_thread, &sc->disconnect_task);
+ taskqueue_drain(nvmf_tq, &sc->disconnect_task);
+ if (taskqueue_cancel_timeout(nvmf_tq, &sc->request_reconnect_task,
+ NULL) != 0)
+ taskqueue_drain_timeout(nvmf_tq, &sc->request_reconnect_task);
+
+ /*
+ * Don't cancel/drain the controller loss task if that task
+ * has fired and is triggering the detach.
+ */
+ if (!sc->controller_timedout) {
+ if (taskqueue_cancel_timeout(nvmf_tq, &sc->controller_loss_task,
+ NULL) != 0)
+ taskqueue_drain_timeout(nvmf_tq,
+ &sc->controller_loss_task);
+ }
if (sc->admin != NULL)
nvmf_destroy_qp(sc->admin);
@@ -1154,14 +1252,25 @@ static struct cdevsw nvmf_cdevsw = {
static int
nvmf_modevent(module_t mod, int what, void *arg)
{
+ int error;
+
switch (what) {
case MOD_LOAD:
- return (nvmf_ctl_load());
+ error = nvmf_ctl_load();
+ if (error != 0)
+ return (error);
+
+ nvmf_tq = taskqueue_create("nvmf", M_WAITOK | M_ZERO,
+ taskqueue_thread_enqueue, &nvmf_tq);
+ taskqueue_start_threads(&nvmf_tq, 1, PWAIT, "nvmf taskq");
+ return (0);
case MOD_QUIESCE:
return (0);
case MOD_UNLOAD:
nvmf_ctl_unload();
destroy_dev_drain(&nvmf_cdevsw);
+ if (nvmf_tq != NULL)
+ taskqueue_free(nvmf_tq);
return (0);
default:
return (EOPNOTSUPP);
diff --git a/sys/dev/nvmf/host/nvmf_var.h b/sys/dev/nvmf/host/nvmf_var.h
index e45a31f413a4..606245b3969c 100644
--- a/sys/dev/nvmf/host/nvmf_var.h
+++ b/sys/dev/nvmf/host/nvmf_var.h
@@ -75,9 +75,15 @@ struct nvmf_softc {
struct callout ka_rx_timer;
sbintime_t ka_rx_sbt;
+ struct timeout_task request_reconnect_task;
+ struct timeout_task controller_loss_task;
+ uint32_t reconnect_delay;
+ uint32_t controller_loss_timeout;
+
struct sx connection_lock;
struct task disconnect_task;
bool detaching;
+ bool controller_timedout;
u_int num_aer;
struct nvmf_aer *aer;
diff --git a/sys/dev/nvmf/nvmf.h b/sys/dev/nvmf/nvmf.h
index d4e7b1511e9d..9b2b4c1dea40 100644
--- a/sys/dev/nvmf/nvmf.h
+++ b/sys/dev/nvmf/nvmf.h
@@ -27,6 +27,13 @@
#define NVMF_NN (1024)
/*
+ * Default timeouts for Fabrics hosts. These match values used by
+ * Linux.
+ */
+#define NVMF_DEFAULT_RECONNECT_DELAY 10
+#define NVMF_DEFAULT_CONTROLLER_LOSS 600
+
+/*
* (data, size) is the userspace buffer for a packed nvlist.
*
* For requests that copyout an nvlist, len is the amount of data
@@ -68,6 +75,8 @@ struct nvmf_ioc_nv {
*
* number trtype
* number kato (optional)
+ * number reconnect_delay (optional)
+ * number controller_loss_timeout (optional)
* qpair handoff nvlist admin
* qpair handoff nvlist array io
* binary cdata struct nvme_controller_data
@@ -81,6 +90,8 @@ struct nvmf_ioc_nv {
* string hostnqn
* number num_io_queues
* number kato (optional)
+ * number reconnect_delay (optional)
+ * number controller_loss_timeout (optional)
* number io_qsize
* bool sq_flow_control
*
diff --git a/sys/dev/random/random_harvestq.c b/sys/dev/random/random_harvestq.c
index ee37bda36496..395310b115fb 100644
--- a/sys/dev/random/random_harvestq.c
+++ b/sys/dev/random/random_harvestq.c
@@ -131,30 +131,14 @@ static struct harvest_context {
/* The context of the kernel thread processing harvested entropy */
struct proc *hc_kthread_proc;
/*
- * Lockless ring buffer holding entropy events
- * If ring.in == ring.out,
- * the buffer is empty.
- * If ring.in != ring.out,
- * the buffer contains harvested entropy.
- * If (ring.in + 1) == ring.out (mod RANDOM_RING_MAX),
- * the buffer is full.
- *
- * NOTE: ring.in points to the last added element,
- * and ring.out points to the last consumed element.
- *
- * The ring.in variable needs locking as there are multiple
- * sources to the ring. Only the sources may change ring.in,
- * but the consumer may examine it.
- *
- * The ring.out variable does not need locking as there is
- * only one consumer. Only the consumer may change ring.out,
- * but the sources may examine it.
+ * A pair of buffers for queued events. New events are added to the
+ * active queue while the kthread processes the other one in parallel.
*/
- struct entropy_ring {
+ struct entropy_buffer {
struct harvest_event ring[RANDOM_RING_MAX];
- volatile u_int in;
- volatile u_int out;
- } hc_entropy_ring;
+ u_int pos;
+ } hc_entropy_buf[2];
+ u_int hc_active_buf;
struct fast_entropy_accumulator {
volatile u_int pos;
uint32_t buf[RANDOM_ACCUM_MAX];
@@ -183,37 +167,41 @@ random_harvestq_fast_process_event(struct harvest_event *event)
static void
random_kthread(void)
{
- u_int maxloop, ring_out, i;
+ struct harvest_context *hc;
- /*
- * Locking is not needed as this is the only place we modify ring.out, and
- * we only examine ring.in without changing it. Both of these are volatile,
- * and this is a unique thread.
- */
+ hc = &harvest_context;
for (random_kthread_control = 1; random_kthread_control;) {
- /* Deal with events, if any. Restrict the number we do in one go. */
- maxloop = RANDOM_RING_MAX;
- while (harvest_context.hc_entropy_ring.out != harvest_context.hc_entropy_ring.in) {
- ring_out = (harvest_context.hc_entropy_ring.out + 1)%RANDOM_RING_MAX;
- random_harvestq_fast_process_event(harvest_context.hc_entropy_ring.ring + ring_out);
- harvest_context.hc_entropy_ring.out = ring_out;
- if (!--maxloop)
- break;
- }
+ struct entropy_buffer *buf;
+ u_int entries;
+
+ /* Deal with queued events. */
+ RANDOM_HARVEST_LOCK();
+ buf = &hc->hc_entropy_buf[hc->hc_active_buf];
+ entries = buf->pos;
+ buf->pos = 0;
+ hc->hc_active_buf = (hc->hc_active_buf + 1) %
+ nitems(hc->hc_entropy_buf);
+ RANDOM_HARVEST_UNLOCK();
+ for (u_int i = 0; i < entries; i++)
+ random_harvestq_fast_process_event(&buf->ring[i]);
+
+ /* Poll sources of noise. */
random_sources_feed();
+
/* XXX: FIX!! Increase the high-performance data rate? Need some measurements first. */
- for (i = 0; i < RANDOM_ACCUM_MAX; i++) {
- if (harvest_context.hc_entropy_fast_accumulator.buf[i]) {
- random_harvest_direct(harvest_context.hc_entropy_fast_accumulator.buf + i, sizeof(harvest_context.hc_entropy_fast_accumulator.buf[0]), RANDOM_UMA);
- harvest_context.hc_entropy_fast_accumulator.buf[i] = 0;
+ for (u_int i = 0; i < RANDOM_ACCUM_MAX; i++) {
+ if (hc->hc_entropy_fast_accumulator.buf[i]) {
+ random_harvest_direct(&hc->hc_entropy_fast_accumulator.buf[i],
+ sizeof(hc->hc_entropy_fast_accumulator.buf[0]), RANDOM_UMA);
+ hc->hc_entropy_fast_accumulator.buf[i] = 0;
}
}
/* XXX: FIX!! This is a *great* place to pass hardware/live entropy to random(9) */
- tsleep_sbt(&harvest_context.hc_kthread_proc, 0, "-",
+ tsleep_sbt(&hc->hc_kthread_proc, 0, "-",
SBT_1S/RANDOM_KTHREAD_HZ, 0, C_PREL(1));
}
random_kthread_control = -1;
- wakeup(&harvest_context.hc_kthread_proc);
+ wakeup(&hc->hc_kthread_proc);
kproc_exit(0);
/* NOTREACHED */
}
@@ -435,7 +423,7 @@ random_harvestq_init(void *unused __unused)
hc_source_mask = almost_everything_mask;
RANDOM_HARVEST_INIT_LOCK();
- harvest_context.hc_entropy_ring.in = harvest_context.hc_entropy_ring.out = 0;
+ harvest_context.hc_active_buf = 0;
}
SYSINIT(random_device_h_init, SI_SUB_RANDOM, SI_ORDER_THIRD, random_harvestq_init, NULL);
@@ -540,9 +528,9 @@ SYSUNINIT(random_device_h_init, SI_SUB_RANDOM, SI_ORDER_THIRD, random_harvestq_d
* This is supposed to be fast; do not do anything slow in here!
* It is also illegal (and morally reprehensible) to insert any
* high-rate data here. "High-rate" is defined as a data source
- * that will usually cause lots of failures of the "Lockless read"
- * check a few lines below. This includes the "always-on" sources
- * like the Intel "rdrand" or the VIA Nehamiah "xstore" sources.
+ * that is likely to fill up the buffer in much less than 100ms.
+ * This includes the "always-on" sources like the Intel "rdrand"
+ * or the VIA Nehamiah "xstore" sources.
*/
/* XXXRW: get_cyclecount() is cheap on most modern hardware, where cycle
* counters are built in, but on older hardware it will do a real time clock
@@ -551,28 +539,29 @@ SYSUNINIT(random_device_h_init, SI_SUB_RANDOM, SI_ORDER_THIRD, random_harvestq_d
void
random_harvest_queue_(const void *entropy, u_int size, enum random_entropy_source origin)
{
+ struct harvest_context *hc;
+ struct entropy_buffer *buf;
struct harvest_event *event;
- u_int ring_in;
- KASSERT(origin >= RANDOM_START && origin < ENTROPYSOURCE, ("%s: origin %d invalid\n", __func__, origin));
+ KASSERT(origin >= RANDOM_START && origin < ENTROPYSOURCE,
+ ("%s: origin %d invalid", __func__, origin));
+
+ hc = &harvest_context;
RANDOM_HARVEST_LOCK();
- ring_in = (harvest_context.hc_entropy_ring.in + 1)%RANDOM_RING_MAX;
- if (ring_in != harvest_context.hc_entropy_ring.out) {
- /* The ring is not full */
- event = harvest_context.hc_entropy_ring.ring + ring_in;
+ buf = &hc->hc_entropy_buf[hc->hc_active_buf];
+ if (buf->pos < RANDOM_RING_MAX) {
+ event = &buf->ring[buf->pos++];
event->he_somecounter = random_get_cyclecount();
event->he_source = origin;
- event->he_destination = harvest_context.hc_destination[origin]++;
+ event->he_destination = hc->hc_destination[origin]++;
if (size <= sizeof(event->he_entropy)) {
event->he_size = size;
memcpy(event->he_entropy, entropy, size);
- }
- else {
+ } else {
/* Big event, so squash it */
event->he_size = sizeof(event->he_entropy[0]);
event->he_entropy[0] = jenkins_hash(entropy, size, (uint32_t)(uintptr_t)event);
}
- harvest_context.hc_entropy_ring.in = ring_in;
}
RANDOM_HARVEST_UNLOCK();
}
diff --git a/sys/dev/sound/midi/midi.c b/sys/dev/sound/midi/midi.c
index fbfb69de2913..6753f864ba9c 100644
--- a/sys/dev/sound/midi/midi.c
+++ b/sys/dev/sound/midi/midi.c
@@ -30,12 +30,6 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
- /*
- * Parts of this file started out as NetBSD: midi.c 1.31
- * They are mostly gone. Still the most obvious will be the state
- * machine midi_in
- */
-
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/queue.h>
@@ -66,7 +60,6 @@
#include "mpu_if.h"
#include <dev/sound/midi/midiq.h>
-#include "synth_if.h"
MALLOC_DEFINE(M_MIDI, "midi buffers", "Midi data allocation area");
#ifndef KOBJMETHOD_END
@@ -79,17 +72,6 @@ enum midi_states {
MIDI_IN_START, MIDI_IN_SYSEX, MIDI_IN_DATA
};
-/*
- * The MPU interface current has init() uninit() inqsize() outqsize()
- * callback() : fiddle with the tx|rx status.
- */
-
-#include "mpu_if.h"
-
-/*
- * /dev/rmidi Structure definitions
- */
-
#define MIDI_NAMELEN 16
struct snd_midi {
KOBJ_FIELDS;
@@ -115,95 +97,13 @@ struct snd_midi {
* complete command packets. */
struct proc *async;
struct cdev *dev;
- struct synth_midi *synth;
- int synth_flags;
TAILQ_ENTRY(snd_midi) link;
};
-struct synth_midi {
- KOBJ_FIELDS;
- struct snd_midi *m;
-};
-
-static synth_open_t midisynth_open;
-static synth_close_t midisynth_close;
-static synth_writeraw_t midisynth_writeraw;
-static synth_killnote_t midisynth_killnote;
-static synth_startnote_t midisynth_startnote;
-static synth_setinstr_t midisynth_setinstr;
-static synth_alloc_t midisynth_alloc;
-static synth_controller_t midisynth_controller;
-static synth_bender_t midisynth_bender;
-
-static kobj_method_t midisynth_methods[] = {
- KOBJMETHOD(synth_open, midisynth_open),
- KOBJMETHOD(synth_close, midisynth_close),
- KOBJMETHOD(synth_writeraw, midisynth_writeraw),
- KOBJMETHOD(synth_setinstr, midisynth_setinstr),
- KOBJMETHOD(synth_startnote, midisynth_startnote),
- KOBJMETHOD(synth_killnote, midisynth_killnote),
- KOBJMETHOD(synth_alloc, midisynth_alloc),
- KOBJMETHOD(synth_controller, midisynth_controller),
- KOBJMETHOD(synth_bender, midisynth_bender),
- KOBJMETHOD_END
-};
-
-DEFINE_CLASS(midisynth, midisynth_methods, 0);
-
-/*
- * Module Exports & Interface
- *
- * struct midi_chan *midi_init(MPU_CLASS cls, int unit, int chan,
- * void *cookie)
- * int midi_uninit(struct snd_midi *)
- *
- * 0 == no error
- * EBUSY or other error
- *
- * int midi_in(struct snd_midi *, char *buf, int count)
- * int midi_out(struct snd_midi *, char *buf, int count)
- *
- * midi_{in,out} return actual size transfered
- *
- */
-
-/*
- * midi_devs tailq, holder of all rmidi instances protected by midistat_lock
- */
-
TAILQ_HEAD(, snd_midi) midi_devs;
-/*
- * /dev/midistat variables and declarations, protected by midistat_lock
- */
-
struct sx mstat_lock;
-static int midistat_isopen = 0;
-static struct sbuf midistat_sbuf;
-static struct cdev *midistat_dev;
-
-/*
- * /dev/midistat dev_t declarations
- */
-
-static d_open_t midistat_open;
-static d_close_t midistat_close;
-static d_read_t midistat_read;
-
-static struct cdevsw midistat_cdevsw = {
- .d_version = D_VERSION,
- .d_open = midistat_open,
- .d_close = midistat_close,
- .d_read = midistat_read,
- .d_name = "midistat",
-};
-
-/*
- * /dev/rmidi dev_t declarations, struct variable access is protected by
- * locks contained within the structure.
- */
-
static d_open_t midi_open;
static d_close_t midi_close;
static d_ioctl_t midi_ioctl;
@@ -222,41 +122,18 @@ static struct cdevsw midi_cdevsw = {
.d_name = "rmidi",
};
-/*
- * Prototypes of library functions
- */
-
static int midi_destroy(struct snd_midi *, int);
-static int midistat_prepare(struct sbuf * s);
static int midi_load(void);
static int midi_unload(void);
-/*
- * Misc declr.
- */
SYSCTL_NODE(_hw, OID_AUTO, midi, CTLFLAG_RD | CTLFLAG_MPSAFE, 0,
"Midi driver");
-static SYSCTL_NODE(_hw_midi, OID_AUTO, stat, CTLFLAG_RD | CTLFLAG_MPSAFE, 0,
- "Status device");
int midi_debug;
/* XXX: should this be moved into debug.midi? */
SYSCTL_INT(_hw_midi, OID_AUTO, debug, CTLFLAG_RW, &midi_debug, 0, "");
-int midi_dumpraw;
-SYSCTL_INT(_hw_midi, OID_AUTO, dumpraw, CTLFLAG_RW, &midi_dumpraw, 0, "");
-
-int midi_instroff;
-SYSCTL_INT(_hw_midi, OID_AUTO, instroff, CTLFLAG_RW, &midi_instroff, 0, "");
-
-int midistat_verbose;
-SYSCTL_INT(_hw_midi_stat, OID_AUTO, verbose, CTLFLAG_RW,
- &midistat_verbose, 0, "");
-
#define MIDI_DEBUG(l,a) if(midi_debug>=l) a
-/*
- * CODE START
- */
void
midistat_lock(void)
@@ -285,9 +162,6 @@ midistat_lockassert(void)
* what unit number is used.
*
* It is an error to call midi_init with an already used unit/channel combo.
- *
- * Returns NULL on error
- *
*/
struct snd_midi *
midi_init(kobj_class_t cls, int unit, int channel, void *cookie)
@@ -326,9 +200,6 @@ midi_init(kobj_class_t cls, int unit, int channel, void *cookie)
MIDI_DEBUG(1, printf("midiinit #2: unit %d/%d.\n", unit, channel));
m = malloc(sizeof(*m), M_MIDI, M_WAITOK | M_ZERO);
- m->synth = malloc(sizeof(*m->synth), M_MIDI, M_WAITOK | M_ZERO);
- kobj_init((kobj_t)m->synth, &midisynth_class);
- m->synth->m = m;
kobj_init((kobj_t)m, cls);
inqsize = MPU_INQSIZE(m, cookie);
outqsize = MPU_OUTQSIZE(m, cookie);
@@ -393,7 +264,6 @@ err2:
if (MIDIQ_BUF(m->outq))
free(MIDIQ_BUF(m->outq), M_MIDI);
err1:
- free(m->synth, M_MIDI);
free(m, M_MIDI);
err0:
midistat_unlock();
@@ -405,9 +275,7 @@ err0:
* midi_uninit does not call MIDI_UNINIT, as since this is the implementors
* entry point. midi_uninit if fact, does not send any methods. A call to
* midi_uninit is a defacto promise that you won't manipulate ch anymore
- *
*/
-
int
midi_uninit(struct snd_midi *m)
{
@@ -440,13 +308,6 @@ exit:
return err;
}
-/*
- * midi_in: process all data until the queue is full, then discards the rest.
- * Since midi_in is a state machine, data discards can cause it to get out of
- * whack. Process as much as possible. It calls, wakeup, selnotify and
- * psignal at most once.
- */
-
#ifdef notdef
static int midi_lengths[] = {2, 2, 2, 2, 1, 1, 2, 0};
@@ -460,6 +321,12 @@ static int midi_lengths[] = {2, 2, 2, 2, 1, 1, 2, 0};
#define MIDI_SYSEX_START 0xF0
#define MIDI_SYSEX_END 0xF7
+/*
+ * midi_in: process all data until the queue is full, then discards the rest.
+ * Since midi_in is a state machine, data discards can cause it to get out of
+ * whack. Process as much as possible. It calls, wakeup, selnotify and
+ * psignal at most once.
+ */
int
midi_in(struct snd_midi *m, uint8_t *buf, int size)
{
@@ -627,9 +494,6 @@ midi_out(struct snd_midi *m, uint8_t *buf, int size)
return used;
}
-/*
- * /dev/rmidi#.# device access functions
- */
int
midi_open(struct cdev *i_dev, int flags, int mode, struct thread *td)
{
@@ -934,434 +798,6 @@ midi_poll(struct cdev *i_dev, int events, struct thread *td)
}
/*
- * /dev/midistat device functions
- *
- */
-static int
-midistat_open(struct cdev *i_dev, int flags, int mode, struct thread *td)
-{
- int error;
-
- MIDI_DEBUG(1, printf("midistat_open\n"));
-
- midistat_lock();
- if (midistat_isopen) {
- midistat_unlock();
- return EBUSY;
- }
- midistat_isopen = 1;
- sbuf_new(&midistat_sbuf, NULL, 4096, SBUF_AUTOEXTEND);
- error = (midistat_prepare(&midistat_sbuf) > 0) ? 0 : ENOMEM;
- if (error)
- midistat_isopen = 0;
- midistat_unlock();
- return error;
-}
-
-static int
-midistat_close(struct cdev *i_dev, int flags, int mode, struct thread *td)
-{
- MIDI_DEBUG(1, printf("midistat_close\n"));
- midistat_lock();
- if (!midistat_isopen) {
- midistat_unlock();
- return EBADF;
- }
- sbuf_delete(&midistat_sbuf);
- midistat_isopen = 0;
- midistat_unlock();
- return 0;
-}
-
-static int
-midistat_read(struct cdev *i_dev, struct uio *uio, int flag)
-{
- long l;
- int err;
-
- MIDI_DEBUG(4, printf("midistat_read\n"));
- midistat_lock();
- if (!midistat_isopen) {
- midistat_unlock();
- return EBADF;
- }
- if (uio->uio_offset < 0 || uio->uio_offset > sbuf_len(&midistat_sbuf)) {
- midistat_unlock();
- return EINVAL;
- }
- err = 0;
- l = lmin(uio->uio_resid, sbuf_len(&midistat_sbuf) - uio->uio_offset);
- if (l > 0) {
- err = uiomove(sbuf_data(&midistat_sbuf) + uio->uio_offset, l,
- uio);
- }
- midistat_unlock();
- return err;
-}
-
-/*
- * Module library functions
- */
-
-static int
-midistat_prepare(struct sbuf *s)
-{
- struct snd_midi *m;
-
- midistat_lockassert();
-
- sbuf_printf(s, "FreeBSD Midi Driver (midi2)\n");
- if (TAILQ_EMPTY(&midi_devs)) {
- sbuf_printf(s, "No devices installed.\n");
- sbuf_finish(s);
- return sbuf_len(s);
- }
- sbuf_printf(s, "Installed devices:\n");
-
- TAILQ_FOREACH(m, &midi_devs, link) {
- mtx_lock(&m->lock);
- sbuf_printf(s, "%s [%d/%d:%s]", m->name, m->unit, m->channel,
- MPU_PROVIDER(m, m->cookie));
- sbuf_printf(s, "%s", MPU_DESCR(m, m->cookie, midistat_verbose));
- sbuf_printf(s, "\n");
- mtx_unlock(&m->lock);
- }
-
- sbuf_finish(s);
- return sbuf_len(s);
-}
-
-#ifdef notdef
-/*
- * Convert IOCTL command to string for debugging
- */
-
-static char *
-midi_cmdname(int cmd)
-{
- static struct {
- int cmd;
- char *name;
- } *tab, cmdtab_midiioctl[] = {
-#define A(x) {x, ## x}
- /*
- * Once we have some real IOCTLs define, the following will
- * be relavant.
- *
- * A(SNDCTL_MIDI_PRETIME), A(SNDCTL_MIDI_MPUMODE),
- * A(SNDCTL_MIDI_MPUCMD), A(SNDCTL_SYNTH_INFO),
- * A(SNDCTL_MIDI_INFO), A(SNDCTL_SYNTH_MEMAVL),
- * A(SNDCTL_FM_LOAD_INSTR), A(SNDCTL_FM_4OP_ENABLE),
- * A(MIOSPASSTHRU), A(MIOGPASSTHRU), A(AIONWRITE),
- * A(AIOGSIZE), A(AIOSSIZE), A(AIOGFMT), A(AIOSFMT),
- * A(AIOGMIX), A(AIOSMIX), A(AIOSTOP), A(AIOSYNC),
- * A(AIOGCAP),
- */
-#undef A
- {
- -1, "unknown"
- },
- };
-
- for (tab = cmdtab_midiioctl; tab->cmd != cmd && tab->cmd != -1; tab++);
- return tab->name;
-}
-
-#endif /* notdef */
-
-/*
- * midisynth
- */
-
-int
-midisynth_open(void *n, void *arg, int flags)
-{
- struct snd_midi *m = ((struct synth_midi *)n)->m;
- int retval;
-
- MIDI_DEBUG(1, printf("midisynth_open %s %s\n",
- flags & FREAD ? "M_RX" : "", flags & FWRITE ? "M_TX" : ""));
-
- if (m == NULL)
- return ENXIO;
-
- mtx_lock(&m->lock);
- mtx_lock(&m->qlock);
-
- retval = 0;
-
- if (flags & FREAD) {
- if (MIDIQ_SIZE(m->inq) == 0)
- retval = ENXIO;
- else if (m->flags & M_RX)
- retval = EBUSY;
- if (retval)
- goto err;
- }
- if (flags & FWRITE) {
- if (MIDIQ_SIZE(m->outq) == 0)
- retval = ENXIO;
- else if (m->flags & M_TX)
- retval = EBUSY;
- if (retval)
- goto err;
- }
- m->busy++;
-
- /*
- * TODO: Consider m->async = 0;
- */
-
- if (flags & FREAD) {
- m->flags |= M_RX | M_RXEN;
- /*
- * Only clear the inq, the outq might still have data to drain
- * from a previous session
- */
- MIDIQ_CLEAR(m->inq);
- m->rchan = 0;
- }
-
- if (flags & FWRITE) {
- m->flags |= M_TX;
- m->wchan = 0;
- }
- m->synth_flags = flags & (FREAD | FWRITE);
-
- MPU_CALLBACK(m, m->cookie, m->flags);
-
-err: mtx_unlock(&m->qlock);
- mtx_unlock(&m->lock);
- MIDI_DEBUG(2, printf("midisynth_open: return %d.\n", retval));
- return retval;
-}
-
-int
-midisynth_close(void *n)
-{
- struct snd_midi *m = ((struct synth_midi *)n)->m;
- int retval;
- int oldflags;
-
- MIDI_DEBUG(1, printf("midisynth_close %s %s\n",
- m->synth_flags & FREAD ? "M_RX" : "",
- m->synth_flags & FWRITE ? "M_TX" : ""));
-
- if (m == NULL)
- return ENXIO;
-
- mtx_lock(&m->lock);
- mtx_lock(&m->qlock);
-
- if ((m->synth_flags & FREAD && !(m->flags & M_RX)) ||
- (m->synth_flags & FWRITE && !(m->flags & M_TX))) {
- retval = ENXIO;
- goto err;
- }
- m->busy--;
-
- oldflags = m->flags;
-
- if (m->synth_flags & FREAD)
- m->flags &= ~(M_RX | M_RXEN);
- if (m->synth_flags & FWRITE)
- m->flags &= ~M_TX;
-
- if ((m->flags & (M_TXEN | M_RXEN)) != (oldflags & (M_RXEN | M_TXEN)))
- MPU_CALLBACK(m, m->cookie, m->flags);
-
- MIDI_DEBUG(1, printf("midi_close: closed, busy = %d.\n", m->busy));
-
- mtx_unlock(&m->qlock);
- mtx_unlock(&m->lock);
- retval = 0;
-err: return retval;
-}
-
-/*
- * Always blocking.
- */
-
-int
-midisynth_writeraw(void *n, uint8_t *buf, size_t len)
-{
- struct snd_midi *m = ((struct synth_midi *)n)->m;
- int retval;
- int used;
- int i;
-
- MIDI_DEBUG(4, printf("midisynth_writeraw\n"));
-
- retval = 0;
-
- if (m == NULL)
- return ENXIO;
-
- mtx_lock(&m->lock);
- mtx_lock(&m->qlock);
-
- if (!(m->flags & M_TX))
- goto err1;
-
- if (midi_dumpraw)
- printf("midi dump: ");
-
- while (len > 0) {
- while (MIDIQ_AVAIL(m->outq) == 0) {
- if (!(m->flags & M_TXEN)) {
- m->flags |= M_TXEN;
- MPU_CALLBACK(m, m->cookie, m->flags);
- }
- mtx_unlock(&m->lock);
- m->wchan = 1;
- MIDI_DEBUG(3, printf("midisynth_writeraw msleep\n"));
- retval = msleep(&m->wchan, &m->qlock,
- PCATCH | PDROP, "midi TX", 0);
- /*
- * We slept, maybe things have changed since last
- * dying check
- */
- if (retval == EINTR)
- goto err0;
-
- if (retval)
- goto err0;
- mtx_lock(&m->lock);
- mtx_lock(&m->qlock);
- m->wchan = 0;
- if (!m->busy)
- goto err1;
- }
-
- /*
- * We are certain than data can be placed on the queue
- */
-
- used = MIN(MIDIQ_AVAIL(m->outq), len);
- used = MIN(used, MIDI_WSIZE);
- MIDI_DEBUG(5,
- printf("midi_synth: resid %zu len %jd avail %jd\n",
- len, (intmax_t)MIDIQ_LEN(m->outq),
- (intmax_t)MIDIQ_AVAIL(m->outq)));
-
- if (midi_dumpraw)
- for (i = 0; i < used; i++)
- printf("%x ", buf[i]);
-
- MIDIQ_ENQ(m->outq, buf, used);
- len -= used;
-
- /*
- * Inform the bottom half that data can be written
- */
- if (!(m->flags & M_TXEN)) {
- m->flags |= M_TXEN;
- MPU_CALLBACK(m, m->cookie, m->flags);
- }
- }
- /*
- * If we Made it here then transfer is good
- */
- if (midi_dumpraw)
- printf("\n");
-
- retval = 0;
-err1: mtx_unlock(&m->qlock);
- mtx_unlock(&m->lock);
-err0: return retval;
-}
-
-static int
-midisynth_killnote(void *n, uint8_t chn, uint8_t note, uint8_t vel)
-{
- u_char c[3];
-
- if (note > 127 || chn > 15)
- return (EINVAL);
-
- if (vel > 127)
- vel = 127;
-
- if (vel == 64) {
- c[0] = 0x90 | (chn & 0x0f); /* Note on. */
- c[1] = (u_char)note;
- c[2] = 0;
- } else {
- c[0] = 0x80 | (chn & 0x0f); /* Note off. */
- c[1] = (u_char)note;
- c[2] = (u_char)vel;
- }
-
- return midisynth_writeraw(n, c, 3);
-}
-
-static int
-midisynth_setinstr(void *n, uint8_t chn, uint16_t instr)
-{
- u_char c[2];
-
- if (instr > 127 || chn > 15)
- return EINVAL;
-
- c[0] = 0xc0 | (chn & 0x0f); /* Progamme change. */
- c[1] = instr + midi_instroff;
-
- return midisynth_writeraw(n, c, 2);
-}
-
-static int
-midisynth_startnote(void *n, uint8_t chn, uint8_t note, uint8_t vel)
-{
- u_char c[3];
-
- if (note > 127 || chn > 15)
- return EINVAL;
-
- if (vel > 127)
- vel = 127;
-
- c[0] = 0x90 | (chn & 0x0f); /* Note on. */
- c[1] = (u_char)note;
- c[2] = (u_char)vel;
-
- return midisynth_writeraw(n, c, 3);
-}
-static int
-midisynth_alloc(void *n, uint8_t chan, uint8_t note)
-{
- return chan;
-}
-
-static int
-midisynth_controller(void *n, uint8_t chn, uint8_t ctrlnum, uint16_t val)
-{
- u_char c[3];
-
- if (ctrlnum > 127 || chn > 15)
- return EINVAL;
-
- c[0] = 0xb0 | (chn & 0x0f); /* Control Message. */
- c[1] = ctrlnum;
- c[2] = val;
- return midisynth_writeraw(n, c, 3);
-}
-
-static int
-midisynth_bender(void *n, uint8_t chn, uint16_t val)
-{
- u_char c[3];
-
- if (val > 16383 || chn > 15)
- return EINVAL;
-
- c[0] = 0xe0 | (chn & 0x0f); /* Pitch bend. */
- c[1] = (u_char)val & 0x7f;
- c[2] = (u_char)(val >> 7) & 0x7f;
-
- return midisynth_writeraw(n, c, 3);
-}
-
-/*
* Single point of midi destructions.
*/
static int
@@ -1381,24 +817,16 @@ midi_destroy(struct snd_midi *m, int midiuninit)
free(MIDIQ_BUF(m->outq), M_MIDI);
mtx_destroy(&m->qlock);
mtx_destroy(&m->lock);
- free(m->synth, M_MIDI);
free(m, M_MIDI);
return 0;
}
-/*
- * Load and unload functions, creates the /dev/midistat device
- */
-
static int
midi_load(void)
{
sx_init(&mstat_lock, "midistat lock");
TAILQ_INIT(&midi_devs);
- midistat_dev = make_dev(&midistat_cdevsw, MIDI_DEV_MIDICTL, UID_ROOT,
- GID_WHEEL, 0666, "midistat");
-
return 0;
}
@@ -1411,9 +839,6 @@ midi_unload(void)
MIDI_DEBUG(1, printf("midi_unload()\n"));
retval = EBUSY;
midistat_lock();
- if (midistat_isopen)
- goto exit0;
-
TAILQ_FOREACH_SAFE(m, &midi_devs, link, tmp) {
mtx_lock(&m->lock);
if (m->busy)
@@ -1421,28 +846,21 @@ midi_unload(void)
else
retval = midi_destroy(m, 1);
if (retval)
- goto exit1;
+ goto exit;
}
midistat_unlock();
- destroy_dev(midistat_dev);
- /*
- * Made it here then unload is complete
- */
sx_destroy(&mstat_lock);
return 0;
-exit1:
+exit:
mtx_unlock(&m->lock);
-exit0:
midistat_unlock();
if (retval)
MIDI_DEBUG(2, printf("midi_unload: failed\n"));
return retval;
}
-extern int seq_modevent(module_t mod, int type, void *data);
-
static int
midi_modevent(module_t mod, int type, void *data)
{
@@ -1453,14 +871,10 @@ midi_modevent(module_t mod, int type, void *data)
switch (type) {
case MOD_LOAD:
retval = midi_load();
- if (retval == 0)
- retval = seq_modevent(mod, type, data);
break;
case MOD_UNLOAD:
retval = midi_unload();
- if (retval == 0)
- retval = seq_modevent(mod, type, data);
break;
default:
@@ -1470,73 +884,5 @@ midi_modevent(module_t mod, int type, void *data)
return retval;
}
-kobj_t
-midimapper_addseq(void *arg1, int *unit, void **cookie)
-{
- unit = NULL;
-
- return (kobj_t)arg1;
-}
-
-int
-midimapper_open_locked(void *arg1, void **cookie)
-{
- int retval = 0;
- struct snd_midi *m;
-
- midistat_lockassert();
- TAILQ_FOREACH(m, &midi_devs, link) {
- retval++;
- }
-
- return retval;
-}
-
-int
-midimapper_open(void *arg1, void **cookie)
-{
- int retval;
-
- midistat_lock();
- retval = midimapper_open_locked(arg1, cookie);
- midistat_unlock();
-
- return retval;
-}
-
-int
-midimapper_close(void *arg1, void *cookie)
-{
- return 0;
-}
-
-kobj_t
-midimapper_fetch_synth_locked(void *arg, void *cookie, int unit)
-{
- struct snd_midi *m;
- int retval = 0;
-
- midistat_lockassert();
- TAILQ_FOREACH(m, &midi_devs, link) {
- if (unit == retval)
- return (kobj_t)m->synth;
- retval++;
- }
-
- return NULL;
-}
-
-kobj_t
-midimapper_fetch_synth(void *arg, void *cookie, int unit)
-{
- kobj_t synth;
-
- midistat_lock();
- synth = midimapper_fetch_synth_locked(arg, cookie, unit);
- midistat_unlock();
-
- return synth;
-}
-
DEV_MODULE(midi, midi_modevent, NULL);
MODULE_VERSION(midi, 1);
diff --git a/sys/dev/sound/midi/midi.h b/sys/dev/sound/midi/midi.h
index 2254fab690e9..286e84264ef3 100644
--- a/sys/dev/sound/midi/midi.h
+++ b/sys/dev/sound/midi/midi.h
@@ -51,11 +51,4 @@ int midi_uninit(struct snd_midi *_m);
int midi_out(struct snd_midi *_m, uint8_t *_buf, int _size);
int midi_in(struct snd_midi *_m, uint8_t *_buf, int _size);
-kobj_t midimapper_addseq(void *arg1, int *unit, void **cookie);
-int midimapper_open_locked(void *arg1, void **cookie);
-int midimapper_open(void *arg1, void **cookie);
-int midimapper_close(void *arg1, void *cookie);
-kobj_t midimapper_fetch_synth_locked(void *arg, void *cookie, int unit);
-kobj_t midimapper_fetch_synth(void *arg, void *cookie, int unit);
-
#endif
diff --git a/sys/dev/sound/midi/mpu401.c b/sys/dev/sound/midi/mpu401.c
index 2be285bc0040..224ebb1b01f4 100644
--- a/sys/dev/sound/midi/mpu401.c
+++ b/sys/dev/sound/midi/mpu401.c
@@ -88,8 +88,6 @@ static int mpu401_minqsize(struct snd_midi *, void *);
static int mpu401_moutqsize(struct snd_midi *, void *);
static void mpu401_mcallback(struct snd_midi *, void *, int);
static void mpu401_mcallbackp(struct snd_midi *, void *, int);
-static const char *mpu401_mdescr(struct snd_midi *, void *, int);
-static const char *mpu401_mprovider(struct snd_midi *, void *);
static kobj_method_t mpu401_methods[] = {
KOBJMETHOD(mpu_init, mpu401_minit),
@@ -98,8 +96,6 @@ static kobj_method_t mpu401_methods[] = {
KOBJMETHOD(mpu_outqsize, mpu401_moutqsize),
KOBJMETHOD(mpu_callback, mpu401_mcallback),
KOBJMETHOD(mpu_callbackp, mpu401_mcallbackp),
- KOBJMETHOD(mpu_descr, mpu401_mdescr),
- KOBJMETHOD(mpu_provider, mpu401_mprovider),
KOBJMETHOD_END
};
@@ -122,24 +118,12 @@ mpu401_intr(struct mpu401 *m)
int i;
int s;
-/*
- printf("mpu401_intr\n");
-*/
#define RXRDY(m) ( (STATUS(m) & MPU_INPUTBUSY) == 0)
#define TXRDY(m) ( (STATUS(m) & MPU_OUTPUTBUSY) == 0)
-#if 0
-#define D(x,l) printf("mpu401_intr %d %x %s %s\n",l, x, x&MPU_INPUTBUSY?"RX":"", x&MPU_OUTPUTBUSY?"TX":"")
-#else
-#define D(x,l)
-#endif
i = 0;
s = STATUS(m);
- D(s, 1);
while ((s & MPU_INPUTBUSY) == 0 && i < MPU_INTR_BUF) {
b[i] = READ(m);
-/*
- printf("mpu401_intr in i %d d %d\n", i, b[i]);
-*/
i++;
s = STATUS(m);
}
@@ -148,15 +132,9 @@ mpu401_intr(struct mpu401 *m)
i = 0;
while (!(s & MPU_OUTPUTBUSY) && i < MPU_INTR_BUF) {
if (midi_out(m->mid, b, 1)) {
-/*
- printf("mpu401_intr out i %d d %d\n", i, b[0]);
-*/
WRITE(m, *b);
} else {
-/*
- printf("mpu401_intr write: no output\n");
-*/
return 0;
}
i++;
@@ -262,13 +240,7 @@ static void
mpu401_mcallback(struct snd_midi *sm, void *arg, int flags)
{
struct mpu401 *m = arg;
-#if 0
- printf("mpu401_callback %s %s %s %s\n",
- flags & M_RX ? "M_RX" : "",
- flags & M_TX ? "M_TX" : "",
- flags & M_RXEN ? "M_RXEN" : "",
- flags & M_TXEN ? "M_TXEN" : "");
-#endif
+
if (flags & M_TXEN && m->si) {
callout_reset(&m->timer, 1, mpu401_timeout, m);
}
@@ -278,19 +250,5 @@ mpu401_mcallback(struct snd_midi *sm, void *arg, int flags)
static void
mpu401_mcallbackp(struct snd_midi *sm, void *arg, int flags)
{
-/* printf("mpu401_callbackp\n"); */
mpu401_mcallback(sm, arg, flags);
}
-
-static const char *
-mpu401_mdescr(struct snd_midi *sm, void *arg, int verbosity)
-{
-
- return "descr mpu401";
-}
-
-static const char *
-mpu401_mprovider(struct snd_midi *m, void *arg)
-{
- return "provider mpu401";
-}
diff --git a/sys/dev/sound/midi/mpu_if.m b/sys/dev/sound/midi/mpu_if.m
index b7cb586c5dd0..835d887f703a 100644
--- a/sys/dev/sound/midi/mpu_if.m
+++ b/sys/dev/sound/midi/mpu_if.m
@@ -56,17 +56,6 @@ METHOD void callback {
int _flags;
};
-METHOD const char * provider {
- struct snd_midi *_kobj;
- void *_cookie;
-};
-
-METHOD const char * descr {
- struct snd_midi *_kobj;
- void *_cookie;
- int _verbosity;
-};
-
METHOD int uninit {
struct snd_midi *_kobj;
void *_cookie;
diff --git a/sys/dev/sound/midi/sequencer.c b/sys/dev/sound/midi/sequencer.c
deleted file mode 100644
index 03b71688175c..000000000000
--- a/sys/dev/sound/midi/sequencer.c
+++ /dev/null
@@ -1,2107 +0,0 @@
-/*-
- * SPDX-License-Identifier: BSD-2-Clause
- *
- * Copyright (c) 2003 Mathew Kanner
- * Copyright (c) 1993 Hannu Savolainen
- * 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.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
- */
-
-/*
- * The sequencer personality manager.
- */
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/ioccom.h>
-
-#include <sys/filio.h>
-#include <sys/lock.h>
-#include <sys/sockio.h>
-#include <sys/fcntl.h>
-#include <sys/proc.h>
-#include <sys/sysctl.h>
-
-#include <sys/kernel.h> /* for DATA_SET */
-
-#include <sys/module.h>
-#include <sys/conf.h>
-#include <sys/file.h>
-#include <sys/uio.h>
-#include <sys/syslog.h>
-#include <sys/errno.h>
-#include <sys/malloc.h>
-#include <sys/bus.h>
-#include <machine/resource.h>
-#include <machine/bus.h>
-#include <machine/clock.h> /* for DELAY */
-#include <sys/soundcard.h>
-#include <sys/rman.h>
-#include <sys/mman.h>
-#include <sys/poll.h>
-#include <sys/mutex.h>
-#include <sys/condvar.h>
-#include <sys/kthread.h>
-#include <sys/unistd.h>
-#include <sys/selinfo.h>
-#include <sys/sx.h>
-
-#ifdef HAVE_KERNEL_OPTION_HEADERS
-#include "opt_snd.h"
-#endif
-
-#include <dev/sound/midi/midi.h>
-#include <dev/sound/midi/midiq.h>
-#include "synth_if.h"
-
-#include <dev/sound/midi/sequencer.h>
-
-#define TMR_TIMERBASE 13
-
-#define SND_DEV_SEQ 1 /* Sequencer output /dev/sequencer (FM
- * synthesizer and MIDI output) */
-#define SND_DEV_MUSIC 8 /* /dev/music, level 2 interface */
-
-/* Length of a sequencer event. */
-#define EV_SZ 8
-#define IEV_SZ 8
-
-/* Lookup modes */
-#define LOOKUP_EXIST (0)
-#define LOOKUP_OPEN (1)
-#define LOOKUP_CLOSE (2)
-
-#define MIDIDEV(y) (dev2unit(y) & 0x0f)
-
-/* These are the entries to the sequencer driver. */
-static d_open_t mseq_open;
-static d_close_t mseq_close;
-static d_ioctl_t mseq_ioctl;
-static d_read_t mseq_read;
-static d_write_t mseq_write;
-static d_poll_t mseq_poll;
-
-static struct cdevsw seq_cdevsw = {
- .d_version = D_VERSION,
- .d_open = mseq_open,
- .d_close = mseq_close,
- .d_read = mseq_read,
- .d_write = mseq_write,
- .d_ioctl = mseq_ioctl,
- .d_poll = mseq_poll,
- .d_name = "sequencer",
-};
-
-struct seq_softc {
- KOBJ_FIELDS;
-
- struct mtx seq_lock, q_lock;
- struct cv empty_cv, reset_cv, in_cv, out_cv, state_cv, th_cv;
-
- MIDIQ_HEAD(, u_char) in_q, out_q;
-
- u_long flags;
- /* Flags (protected by flag_mtx of mididev_info) */
- int fflags; /* Access mode */
- int music;
-
- int out_water; /* Sequence output threshould */
- snd_sync_parm sync_parm; /* AIOSYNC parameter set */
- struct thread *sync_thread; /* AIOSYNCing thread */
- struct selinfo in_sel, out_sel;
- int midi_number;
- struct cdev *seqdev, *musicdev;
- int unit;
- int maxunits;
- kobj_t *midis;
- int *midi_flags;
- kobj_t mapper;
- void *mapper_cookie;
- struct timeval timerstop, timersub;
- int timerbase, tempo;
- int timerrun;
- int done;
- int playing;
- int recording;
- int busy;
- int pre_event_timeout;
- int waiting;
-};
-
-/*
- * Module specific stuff, including how many sequecers
- * we currently own.
- */
-
-SYSCTL_NODE(_hw_midi, OID_AUTO, seq, CTLFLAG_RD | CTLFLAG_MPSAFE, 0,
- "Midi sequencer");
-
-int seq_debug;
-/* XXX: should this be moved into debug.midi? */
-SYSCTL_INT(_hw_midi_seq, OID_AUTO, debug, CTLFLAG_RW, &seq_debug, 0, "");
-
-midi_cmdtab cmdtab_seqevent[] = {
- {SEQ_NOTEOFF, "SEQ_NOTEOFF"},
- {SEQ_NOTEON, "SEQ_NOTEON"},
- {SEQ_WAIT, "SEQ_WAIT"},
- {SEQ_PGMCHANGE, "SEQ_PGMCHANGE"},
- {SEQ_SYNCTIMER, "SEQ_SYNCTIMER"},
- {SEQ_MIDIPUTC, "SEQ_MIDIPUTC"},
- {SEQ_DRUMON, "SEQ_DRUMON"},
- {SEQ_DRUMOFF, "SEQ_DRUMOFF"},
- {SEQ_ECHO, "SEQ_ECHO"},
- {SEQ_AFTERTOUCH, "SEQ_AFTERTOUCH"},
- {SEQ_CONTROLLER, "SEQ_CONTROLLER"},
- {SEQ_BALANCE, "SEQ_BALANCE"},
- {SEQ_VOLMODE, "SEQ_VOLMODE"},
- {SEQ_FULLSIZE, "SEQ_FULLSIZE"},
- {SEQ_PRIVATE, "SEQ_PRIVATE"},
- {SEQ_EXTENDED, "SEQ_EXTENDED"},
- {EV_SEQ_LOCAL, "EV_SEQ_LOCAL"},
- {EV_TIMING, "EV_TIMING"},
- {EV_CHN_COMMON, "EV_CHN_COMMON"},
- {EV_CHN_VOICE, "EV_CHN_VOICE"},
- {EV_SYSEX, "EV_SYSEX"},
- {-1, NULL},
-};
-
-midi_cmdtab cmdtab_seqioctl[] = {
- {SNDCTL_SEQ_RESET, "SNDCTL_SEQ_RESET"},
- {SNDCTL_SEQ_SYNC, "SNDCTL_SEQ_SYNC"},
- {SNDCTL_SYNTH_INFO, "SNDCTL_SYNTH_INFO"},
- {SNDCTL_SEQ_CTRLRATE, "SNDCTL_SEQ_CTRLRATE"},
- {SNDCTL_SEQ_GETOUTCOUNT, "SNDCTL_SEQ_GETOUTCOUNT"},
- {SNDCTL_SEQ_GETINCOUNT, "SNDCTL_SEQ_GETINCOUNT"},
- {SNDCTL_SEQ_PERCMODE, "SNDCTL_SEQ_PERCMODE"},
- {SNDCTL_FM_LOAD_INSTR, "SNDCTL_FM_LOAD_INSTR"},
- {SNDCTL_SEQ_TESTMIDI, "SNDCTL_SEQ_TESTMIDI"},
- {SNDCTL_SEQ_RESETSAMPLES, "SNDCTL_SEQ_RESETSAMPLES"},
- {SNDCTL_SEQ_NRSYNTHS, "SNDCTL_SEQ_NRSYNTHS"},
- {SNDCTL_SEQ_NRMIDIS, "SNDCTL_SEQ_NRMIDIS"},
- {SNDCTL_SEQ_GETTIME, "SNDCTL_SEQ_GETTIME"},
- {SNDCTL_MIDI_INFO, "SNDCTL_MIDI_INFO"},
- {SNDCTL_SEQ_THRESHOLD, "SNDCTL_SEQ_THRESHOLD"},
- {SNDCTL_SYNTH_MEMAVL, "SNDCTL_SYNTH_MEMAVL"},
- {SNDCTL_FM_4OP_ENABLE, "SNDCTL_FM_4OP_ENABLE"},
- {SNDCTL_PMGR_ACCESS, "SNDCTL_PMGR_ACCESS"},
- {SNDCTL_SEQ_PANIC, "SNDCTL_SEQ_PANIC"},
- {SNDCTL_SEQ_OUTOFBAND, "SNDCTL_SEQ_OUTOFBAND"},
- {SNDCTL_TMR_TIMEBASE, "SNDCTL_TMR_TIMEBASE"},
- {SNDCTL_TMR_START, "SNDCTL_TMR_START"},
- {SNDCTL_TMR_STOP, "SNDCTL_TMR_STOP"},
- {SNDCTL_TMR_CONTINUE, "SNDCTL_TMR_CONTINUE"},
- {SNDCTL_TMR_TEMPO, "SNDCTL_TMR_TEMPO"},
- {SNDCTL_TMR_SOURCE, "SNDCTL_TMR_SOURCE"},
- {SNDCTL_TMR_METRONOME, "SNDCTL_TMR_METRONOME"},
- {SNDCTL_TMR_SELECT, "SNDCTL_TMR_SELECT"},
- {SNDCTL_MIDI_PRETIME, "SNDCTL_MIDI_PRETIME"},
- {AIONWRITE, "AIONWRITE"},
- {AIOGSIZE, "AIOGSIZE"},
- {AIOSSIZE, "AIOSSIZE"},
- {AIOGFMT, "AIOGFMT"},
- {AIOSFMT, "AIOSFMT"},
- {AIOGMIX, "AIOGMIX"},
- {AIOSMIX, "AIOSMIX"},
- {AIOSTOP, "AIOSTOP"},
- {AIOSYNC, "AIOSYNC"},
- {AIOGCAP, "AIOGCAP"},
- {-1, NULL},
-};
-
-midi_cmdtab cmdtab_timer[] = {
- {TMR_WAIT_REL, "TMR_WAIT_REL"},
- {TMR_WAIT_ABS, "TMR_WAIT_ABS"},
- {TMR_STOP, "TMR_STOP"},
- {TMR_START, "TMR_START"},
- {TMR_CONTINUE, "TMR_CONTINUE"},
- {TMR_TEMPO, "TMR_TEMPO"},
- {TMR_ECHO, "TMR_ECHO"},
- {TMR_CLOCK, "TMR_CLOCK"},
- {TMR_SPP, "TMR_SPP"},
- {TMR_TIMESIG, "TMR_TIMESIG"},
- {-1, NULL},
-};
-
-midi_cmdtab cmdtab_seqcv[] = {
- {MIDI_NOTEOFF, "MIDI_NOTEOFF"},
- {MIDI_NOTEON, "MIDI_NOTEON"},
- {MIDI_KEY_PRESSURE, "MIDI_KEY_PRESSURE"},
- {-1, NULL},
-};
-
-midi_cmdtab cmdtab_seqccmn[] = {
- {MIDI_CTL_CHANGE, "MIDI_CTL_CHANGE"},
- {MIDI_PGM_CHANGE, "MIDI_PGM_CHANGE"},
- {MIDI_CHN_PRESSURE, "MIDI_CHN_PRESSURE"},
- {MIDI_PITCH_BEND, "MIDI_PITCH_BEND"},
- {MIDI_SYSTEM_PREFIX, "MIDI_SYSTEM_PREFIX"},
- {-1, NULL},
-};
-
-#ifndef KOBJMETHOD_END
-#define KOBJMETHOD_END { NULL, NULL }
-#endif
-
-/*
- * static const char *mpu401_mprovider(kobj_t obj, struct mpu401 *m);
- */
-
-static kobj_method_t seq_methods[] = {
- /* KOBJMETHOD(mpu_provider,mpu401_mprovider), */
- KOBJMETHOD_END
-};
-
-DEFINE_CLASS(sequencer, seq_methods, 0);
-
-/* The followings are the local function. */
-static int seq_convertold(u_char *event, u_char *out);
-
-/*
- * static void seq_midiinput(struct seq_softc * scp, void *md);
- */
-static void seq_reset(struct seq_softc *scp);
-static int seq_sync(struct seq_softc *scp);
-
-static int seq_processevent(struct seq_softc *scp, u_char *event);
-
-static int seq_timing(struct seq_softc *scp, u_char *event);
-static int seq_local(struct seq_softc *scp, u_char *event);
-
-static int seq_chnvoice(struct seq_softc *scp, kobj_t md, u_char *event);
-static int seq_chncommon(struct seq_softc *scp, kobj_t md, u_char *event);
-static int seq_sysex(struct seq_softc *scp, kobj_t md, u_char *event);
-
-static int seq_fetch_mid(struct seq_softc *scp, int unit, kobj_t *md);
-void seq_copytoinput(struct seq_softc *scp, u_char *event, int len);
-int seq_modevent(module_t mod, int type, void *data);
-struct seq_softc *seqs[10];
-static struct mtx seqinfo_mtx;
-static u_long nseq = 0;
-
-static void timer_start(struct seq_softc *t);
-static void timer_stop(struct seq_softc *t);
-static void timer_setvals(struct seq_softc *t, int tempo, int timerbase);
-static void timer_wait(struct seq_softc *t, int ticks, int wait_abs);
-static int timer_now(struct seq_softc *t);
-
-static void
-timer_start(struct seq_softc *t)
-{
- t->timerrun = 1;
- getmicrotime(&t->timersub);
-}
-
-static void
-timer_continue(struct seq_softc *t)
-{
- struct timeval now;
-
- if (t->timerrun == 1)
- return;
- t->timerrun = 1;
- getmicrotime(&now);
- timevalsub(&now, &t->timerstop);
- timevaladd(&t->timersub, &now);
-}
-
-static void
-timer_stop(struct seq_softc *t)
-{
- t->timerrun = 0;
- getmicrotime(&t->timerstop);
-}
-
-static void
-timer_setvals(struct seq_softc *t, int tempo, int timerbase)
-{
- t->tempo = tempo;
- t->timerbase = timerbase;
-}
-
-static void
-timer_wait(struct seq_softc *t, int ticks, int wait_abs)
-{
- struct timeval now, when;
- int ret;
- unsigned long long i;
-
- while (t->timerrun == 0) {
- SEQ_DEBUG(2, printf("Timer wait when timer isn't running\n"));
- /*
- * The old sequencer used timeouts that only increased
- * the timer when the timer was running.
- * Hence the sequencer would stick (?) if the
- * timer was disabled.
- */
- cv_wait(&t->reset_cv, &t->seq_lock);
- if (t->playing == 0)
- return;
- }
-
- i = ticks * 60ull * 1000000ull / (t->tempo * t->timerbase);
-
- when.tv_sec = i / 1000000;
- when.tv_usec = i % 1000000;
-
-#if 0
- printf("timer_wait tempo %d timerbase %d ticks %d abs %d u_sec %llu\n",
- t->tempo, t->timerbase, ticks, wait_abs, i);
-#endif
-
- if (wait_abs != 0) {
- getmicrotime(&now);
- timevalsub(&now, &t->timersub);
- timevalsub(&when, &now);
- }
- if (when.tv_sec < 0 || when.tv_usec < 0) {
- SEQ_DEBUG(3,
- printf("seq_timer error negative time %lds.%06lds\n",
- (long)when.tv_sec, (long)when.tv_usec));
- return;
- }
- i = when.tv_sec * 1000000ull;
- i += when.tv_usec;
- i *= hz;
- i /= 1000000ull;
-#if 0
- printf("seq_timer usec %llu ticks %llu\n",
- when.tv_sec * 1000000ull + when.tv_usec, i);
-#endif
- t->waiting = 1;
- ret = cv_timedwait(&t->reset_cv, &t->seq_lock, i + 1);
- t->waiting = 0;
-
- if (ret != EWOULDBLOCK)
- SEQ_DEBUG(3, printf("seq_timer didn't timeout\n"));
-
-}
-
-static int
-timer_now(struct seq_softc *t)
-{
- struct timeval now;
- unsigned long long i;
- int ret;
-
- if (t->timerrun == 0)
- now = t->timerstop;
- else
- getmicrotime(&now);
-
- timevalsub(&now, &t->timersub);
-
- i = now.tv_sec * 1000000ull;
- i += now.tv_usec;
- i *= t->timerbase;
-/* i /= t->tempo; */
- i /= 1000000ull;
-
- ret = i;
- /*
- * printf("timer_now: %llu %d\n", i, ret);
- */
-
- return ret;
-}
-
-static void
-seq_eventthread(void *arg)
-{
- struct seq_softc *scp = arg;
- u_char event[EV_SZ];
-
- mtx_lock(&scp->seq_lock);
- SEQ_DEBUG(2, printf("seq_eventthread started\n"));
- while (scp->done == 0) {
-restart:
- while (scp->playing == 0) {
- cv_wait(&scp->state_cv, &scp->seq_lock);
- if (scp->done)
- goto done;
- }
-
- while (MIDIQ_EMPTY(scp->out_q)) {
- cv_broadcast(&scp->empty_cv);
- cv_wait(&scp->out_cv, &scp->seq_lock);
- if (scp->playing == 0)
- goto restart;
- if (scp->done)
- goto done;
- }
-
- MIDIQ_DEQ(scp->out_q, event, EV_SZ);
-
- if (MIDIQ_AVAIL(scp->out_q) < scp->out_water) {
- cv_broadcast(&scp->out_cv);
- selwakeup(&scp->out_sel);
- }
- seq_processevent(scp, event);
- }
-
-done:
- cv_broadcast(&scp->th_cv);
- mtx_unlock(&scp->seq_lock);
- SEQ_DEBUG(2, printf("seq_eventthread finished\n"));
- kproc_exit(0);
-}
-
-/*
- * seq_processevent: This maybe called by the event thread or the IOCTL
- * handler for queued and out of band events respectively.
- */
-static int
-seq_processevent(struct seq_softc *scp, u_char *event)
-{
- int ret;
- kobj_t m;
-
- ret = 0;
-
- if (event[0] == EV_SEQ_LOCAL)
- ret = seq_local(scp, event);
- else if (event[0] == EV_TIMING)
- ret = seq_timing(scp, event);
- else if (event[0] != EV_CHN_VOICE &&
- event[0] != EV_CHN_COMMON &&
- event[0] != EV_SYSEX &&
- event[0] != SEQ_MIDIPUTC) {
- ret = 1;
- SEQ_DEBUG(2, printf("seq_processevent not known %d\n",
- event[0]));
- } else if (seq_fetch_mid(scp, event[1], &m) != 0) {
- ret = 1;
- SEQ_DEBUG(2, printf("seq_processevent midi unit not found %d\n",
- event[1]));
- } else
- switch (event[0]) {
- case EV_CHN_VOICE:
- ret = seq_chnvoice(scp, m, event);
- break;
- case EV_CHN_COMMON:
- ret = seq_chncommon(scp, m, event);
- break;
- case EV_SYSEX:
- ret = seq_sysex(scp, m, event);
- break;
- case SEQ_MIDIPUTC:
- mtx_unlock(&scp->seq_lock);
- ret = SYNTH_WRITERAW(m, &event[2], 1);
- mtx_lock(&scp->seq_lock);
- break;
- }
- return ret;
-}
-
-static int
-seq_addunit(void)
-{
- struct seq_softc *scp;
- int ret;
- u_char *buf;
-
- gone_in(15, "Warning! MIDI sequencer to be removed soon: no longer "
- "needed or used\n");
-
- /* Allocate the softc. */
- ret = ENOMEM;
- scp = malloc(sizeof(*scp), M_DEVBUF, M_NOWAIT | M_ZERO);
- if (scp == NULL) {
- SEQ_DEBUG(1, printf("seq_addunit: softc allocation failed.\n"));
- goto err;
- }
- kobj_init((kobj_t)scp, &sequencer_class);
-
- buf = malloc(sizeof(*buf) * EV_SZ * 1024, M_TEMP, M_NOWAIT | M_ZERO);
- if (buf == NULL)
- goto err;
- MIDIQ_INIT(scp->in_q, buf, EV_SZ * 1024);
- buf = malloc(sizeof(*buf) * EV_SZ * 1024, M_TEMP, M_NOWAIT | M_ZERO);
- if (buf == NULL)
- goto err;
- MIDIQ_INIT(scp->out_q, buf, EV_SZ * 1024);
- ret = EINVAL;
-
- scp->midis = malloc(sizeof(kobj_t) * 32, M_TEMP, M_NOWAIT | M_ZERO);
- scp->midi_flags = malloc(sizeof(*scp->midi_flags) * 32, M_TEMP,
- M_NOWAIT | M_ZERO);
-
- if (scp->midis == NULL || scp->midi_flags == NULL)
- goto err;
-
- scp->flags = 0;
-
- mtx_init(&scp->seq_lock, "seqflq", NULL, 0);
- cv_init(&scp->state_cv, "seqstate");
- cv_init(&scp->empty_cv, "seqempty");
- cv_init(&scp->reset_cv, "seqtimer");
- cv_init(&scp->out_cv, "seqqout");
- cv_init(&scp->in_cv, "seqqin");
- cv_init(&scp->th_cv, "seqstart");
-
- /*
- * Init the damn timer
- */
-
- scp->mapper = midimapper_addseq(scp, &scp->unit, &scp->mapper_cookie);
- if (scp->mapper == NULL)
- goto err;
-
- scp->seqdev = make_dev(&seq_cdevsw, SND_DEV_SEQ, UID_ROOT, GID_WHEEL,
- 0666, "sequencer%d", scp->unit);
-
- scp->musicdev = make_dev(&seq_cdevsw, SND_DEV_MUSIC, UID_ROOT,
- GID_WHEEL, 0666, "music%d", scp->unit);
-
- if (scp->seqdev == NULL || scp->musicdev == NULL)
- goto err;
- /*
- * TODO: Add to list of sequencers this module provides
- */
-
- ret =
- kproc_create
- (seq_eventthread, scp, NULL, RFHIGHPID, 0,
- "sequencer %02d", scp->unit);
-
- if (ret)
- goto err;
-
- scp->seqdev->si_drv1 = scp->musicdev->si_drv1 = scp;
-
- SEQ_DEBUG(2, printf("sequencer %d created scp %p\n", scp->unit, scp));
-
- ret = 0;
-
- mtx_lock(&seqinfo_mtx);
- seqs[nseq++] = scp;
- mtx_unlock(&seqinfo_mtx);
-
- goto ok;
-
-err:
- if (scp != NULL) {
- if (scp->seqdev != NULL)
- destroy_dev(scp->seqdev);
- if (scp->musicdev != NULL)
- destroy_dev(scp->musicdev);
- /*
- * TODO: Destroy mutex and cv
- */
- if (scp->midis != NULL)
- free(scp->midis, M_TEMP);
- if (scp->midi_flags != NULL)
- free(scp->midi_flags, M_TEMP);
- if (scp->out_q.b)
- free(scp->out_q.b, M_TEMP);
- if (scp->in_q.b)
- free(scp->in_q.b, M_TEMP);
- free(scp, M_DEVBUF);
- }
-ok:
- return ret;
-}
-
-static int
-seq_delunit(int unit)
-{
- struct seq_softc *scp = seqs[unit];
- int i;
-
- //SEQ_DEBUG(4, printf("seq_delunit: %d\n", unit));
- SEQ_DEBUG(1, printf("seq_delunit: 1 \n"));
- mtx_lock(&scp->seq_lock);
-
- scp->playing = 0;
- scp->done = 1;
- cv_broadcast(&scp->out_cv);
- cv_broadcast(&scp->state_cv);
- cv_broadcast(&scp->reset_cv);
- SEQ_DEBUG(1, printf("seq_delunit: 2 \n"));
- cv_wait(&scp->th_cv, &scp->seq_lock);
- SEQ_DEBUG(1, printf("seq_delunit: 3.0 \n"));
- mtx_unlock(&scp->seq_lock);
- SEQ_DEBUG(1, printf("seq_delunit: 3.1 \n"));
-
- cv_destroy(&scp->state_cv);
- SEQ_DEBUG(1, printf("seq_delunit: 4 \n"));
- cv_destroy(&scp->empty_cv);
- SEQ_DEBUG(1, printf("seq_delunit: 5 \n"));
- cv_destroy(&scp->reset_cv);
- SEQ_DEBUG(1, printf("seq_delunit: 6 \n"));
- cv_destroy(&scp->out_cv);
- SEQ_DEBUG(1, printf("seq_delunit: 7 \n"));
- cv_destroy(&scp->in_cv);
- SEQ_DEBUG(1, printf("seq_delunit: 8 \n"));
- cv_destroy(&scp->th_cv);
-
- SEQ_DEBUG(1, printf("seq_delunit: 10 \n"));
- if (scp->seqdev)
- destroy_dev(scp->seqdev);
- SEQ_DEBUG(1, printf("seq_delunit: 11 \n"));
- if (scp->musicdev)
- destroy_dev(scp->musicdev);
- SEQ_DEBUG(1, printf("seq_delunit: 12 \n"));
- scp->seqdev = scp->musicdev = NULL;
- if (scp->midis != NULL)
- free(scp->midis, M_TEMP);
- SEQ_DEBUG(1, printf("seq_delunit: 13 \n"));
- if (scp->midi_flags != NULL)
- free(scp->midi_flags, M_TEMP);
- SEQ_DEBUG(1, printf("seq_delunit: 14 \n"));
- free(scp->out_q.b, M_TEMP);
- SEQ_DEBUG(1, printf("seq_delunit: 15 \n"));
- free(scp->in_q.b, M_TEMP);
-
- SEQ_DEBUG(1, printf("seq_delunit: 16 \n"));
-
- mtx_destroy(&scp->seq_lock);
- SEQ_DEBUG(1, printf("seq_delunit: 17 \n"));
- free(scp, M_DEVBUF);
-
- mtx_lock(&seqinfo_mtx);
- for (i = unit; i < (nseq - 1); i++)
- seqs[i] = seqs[i + 1];
- nseq--;
- mtx_unlock(&seqinfo_mtx);
-
- return 0;
-}
-
-int
-seq_modevent(module_t mod, int type, void *data)
-{
- int retval, r;
-
- retval = 0;
-
- switch (type) {
- case MOD_LOAD:
- mtx_init(&seqinfo_mtx, "seqmod", NULL, 0);
- retval = seq_addunit();
- break;
-
- case MOD_UNLOAD:
- while (nseq) {
- r = seq_delunit(nseq - 1);
- if (r) {
- retval = r;
- break;
- }
- }
- if (nseq == 0) {
- retval = 0;
- mtx_destroy(&seqinfo_mtx);
- }
- break;
-
- default:
- break;
- }
-
- return retval;
-}
-
-static int
-seq_fetch_mid(struct seq_softc *scp, int unit, kobj_t *md)
-{
-
- if (unit >= scp->midi_number || unit < 0)
- return EINVAL;
-
- *md = scp->midis[unit];
-
- return 0;
-}
-
-int
-mseq_open(struct cdev *i_dev, int flags, int mode, struct thread *td)
-{
- struct seq_softc *scp = i_dev->si_drv1;
- int i;
-
- gone_in(15, "Warning! MIDI sequencer to be removed soon: no longer "
- "needed or used\n");
-
- if (scp == NULL)
- return ENXIO;
-
- SEQ_DEBUG(3, printf("seq_open: scp %p unit %d, flags 0x%x.\n",
- scp, scp->unit, flags));
-
- /*
- * Mark this device busy.
- */
-
- midistat_lock();
- mtx_lock(&scp->seq_lock);
- if (scp->busy) {
- mtx_unlock(&scp->seq_lock);
- midistat_unlock();
- SEQ_DEBUG(2, printf("seq_open: unit %d is busy.\n", scp->unit));
- return EBUSY;
- }
- scp->fflags = flags;
- /*
- if ((scp->fflags & O_NONBLOCK) != 0)
- scp->flags |= SEQ_F_NBIO;
- */
- scp->music = MIDIDEV(i_dev) == SND_DEV_MUSIC;
-
- /*
- * Enumerate the available midi devices
- */
- scp->midi_number = 0;
- scp->maxunits = midimapper_open_locked(scp->mapper, &scp->mapper_cookie);
-
- if (scp->maxunits == 0)
- SEQ_DEBUG(2, printf("seq_open: no midi devices\n"));
-
- for (i = 0; i < scp->maxunits; i++) {
- scp->midis[scp->midi_number] =
- midimapper_fetch_synth_locked(scp->mapper,
- scp->mapper_cookie, i);
- if (scp->midis[scp->midi_number]) {
- if (SYNTH_OPEN(scp->midis[scp->midi_number], scp,
- scp->fflags) != 0)
- scp->midis[scp->midi_number] = NULL;
- else {
- scp->midi_flags[scp->midi_number] =
- SYNTH_QUERY(scp->midis[scp->midi_number]);
- scp->midi_number++;
- }
- }
- }
- midistat_unlock();
-
- timer_setvals(scp, 60, 100);
-
- timer_start(scp);
- timer_stop(scp);
- /*
- * actually, if we're in rdonly mode, we should start the timer
- */
- /*
- * TODO: Handle recording now
- */
-
- scp->out_water = MIDIQ_SIZE(scp->out_q) / 2;
-
- scp->busy = 1;
- mtx_unlock(&scp->seq_lock);
-
- SEQ_DEBUG(2, printf("seq_open: opened, mode %s.\n",
- scp->music ? "music" : "sequencer"));
- SEQ_DEBUG(2,
- printf("Sequencer %d %p opened maxunits %d midi_number %d:\n",
- scp->unit, scp, scp->maxunits, scp->midi_number));
- for (i = 0; i < scp->midi_number; i++)
- SEQ_DEBUG(3, printf(" midi %d %p\n", i, scp->midis[i]));
-
- return 0;
-}
-
-/*
- * mseq_close
- */
-int
-mseq_close(struct cdev *i_dev, int flags, int mode, struct thread *td)
-{
- int i;
- struct seq_softc *scp = i_dev->si_drv1;
- int ret;
-
- if (scp == NULL)
- return ENXIO;
-
- SEQ_DEBUG(2, printf("seq_close: unit %d.\n", scp->unit));
-
- mtx_lock(&scp->seq_lock);
-
- ret = ENXIO;
- if (scp->busy == 0)
- goto err;
-
- seq_reset(scp);
- seq_sync(scp);
-
- for (i = 0; i < scp->midi_number; i++)
- if (scp->midis[i])
- SYNTH_CLOSE(scp->midis[i]);
-
- midimapper_close(scp->mapper, scp->mapper_cookie);
-
- timer_stop(scp);
-
- scp->busy = 0;
- ret = 0;
-
-err:
- SEQ_DEBUG(3, printf("seq_close: closed ret = %d.\n", ret));
- mtx_unlock(&scp->seq_lock);
- return ret;
-}
-
-int
-mseq_read(struct cdev *i_dev, struct uio *uio, int ioflag)
-{
- int retval, used;
- struct seq_softc *scp = i_dev->si_drv1;
-
-#define SEQ_RSIZE 32
- u_char buf[SEQ_RSIZE];
-
- if (scp == NULL)
- return ENXIO;
-
- SEQ_DEBUG(7, printf("mseq_read: unit %d, resid %zd.\n",
- scp->unit, uio->uio_resid));
-
- mtx_lock(&scp->seq_lock);
- if ((scp->fflags & FREAD) == 0) {
- SEQ_DEBUG(2, printf("mseq_read: unit %d is not for reading.\n",
- scp->unit));
- retval = EIO;
- goto err1;
- }
- /*
- * Begin recording.
- */
- /*
- * if ((scp->flags & SEQ_F_READING) == 0)
- */
- /*
- * TODO, start recording if not alread
- */
-
- /*
- * I think the semantics are to return as soon
- * as possible.
- * Second thought, it doesn't seem like midimoutain
- * expects that at all.
- * TODO: Look up in some sort of spec
- */
-
- while (uio->uio_resid > 0) {
- while (MIDIQ_EMPTY(scp->in_q)) {
- retval = EWOULDBLOCK;
- /*
- * I wish I knew which one to care about
- */
-
- if (scp->fflags & O_NONBLOCK)
- goto err1;
- if (ioflag & O_NONBLOCK)
- goto err1;
-
- retval = cv_wait_sig(&scp->in_cv, &scp->seq_lock);
- if (retval != 0)
- goto err1;
- }
-
- used = MIN(MIDIQ_LEN(scp->in_q), uio->uio_resid);
- used = MIN(used, SEQ_RSIZE);
-
- SEQ_DEBUG(8, printf("midiread: uiomove cc=%d\n", used));
- MIDIQ_DEQ(scp->in_q, buf, used);
- mtx_unlock(&scp->seq_lock);
- retval = uiomove(buf, used, uio);
- mtx_lock(&scp->seq_lock);
- if (retval)
- goto err1;
- }
-
- retval = 0;
-err1:
- mtx_unlock(&scp->seq_lock);
- SEQ_DEBUG(6, printf("mseq_read: ret %d, resid %zd.\n",
- retval, uio->uio_resid));
-
- return retval;
-}
-
-int
-mseq_write(struct cdev *i_dev, struct uio *uio, int ioflag)
-{
- u_char event[EV_SZ], newevent[EV_SZ], ev_code;
- struct seq_softc *scp = i_dev->si_drv1;
- int retval;
- int used;
-
- SEQ_DEBUG(7, printf("seq_write: unit %d, resid %zd.\n",
- scp->unit, uio->uio_resid));
-
- if (scp == NULL)
- return ENXIO;
-
- mtx_lock(&scp->seq_lock);
-
- if ((scp->fflags & FWRITE) == 0) {
- SEQ_DEBUG(2, printf("seq_write: unit %d is not for writing.\n",
- scp->unit));
- retval = EIO;
- goto err0;
- }
- while (uio->uio_resid > 0) {
- while (MIDIQ_AVAIL(scp->out_q) == 0) {
- retval = EWOULDBLOCK;
- if (scp->fflags & O_NONBLOCK)
- goto err0;
- if (ioflag & O_NONBLOCK)
- goto err0;
- SEQ_DEBUG(8, printf("seq_write cvwait\n"));
-
- scp->playing = 1;
- cv_broadcast(&scp->out_cv);
- cv_broadcast(&scp->state_cv);
-
- retval = cv_wait_sig(&scp->out_cv, &scp->seq_lock);
- /*
- * We slept, maybe things have changed since last
- * dying check
- */
- if (retval != 0)
- goto err0;
-#if 0
- /*
- * Useless test
- */
- if (scp != i_dev->si_drv1)
- retval = ENXIO;
-#endif
- }
-
- used = MIN(uio->uio_resid, 4);
-
- SEQ_DEBUG(8, printf("seqout: resid %zd len %jd avail %jd\n",
- uio->uio_resid, (intmax_t)MIDIQ_LEN(scp->out_q),
- (intmax_t)MIDIQ_AVAIL(scp->out_q)));
-
- if (used != 4) {
- retval = ENXIO;
- goto err0;
- }
- mtx_unlock(&scp->seq_lock);
- retval = uiomove(event, used, uio);
- mtx_lock(&scp->seq_lock);
- if (retval)
- goto err0;
-
- ev_code = event[0];
- SEQ_DEBUG(8, printf("seq_write: unit %d, event %s.\n",
- scp->unit, midi_cmdname(ev_code, cmdtab_seqevent)));
-
- /* Have a look at the event code. */
- if (ev_code == SEQ_FULLSIZE) {
- /*
- * TODO: restore code for SEQ_FULLSIZE
- */
-#if 0
- /*
- * A long event, these are the patches/samples for a
- * synthesizer.
- */
- midiunit = *(u_short *)&event[2];
- mtx_lock(&sd->seq_lock);
- ret = lookup_mididev(scp, midiunit, LOOKUP_OPEN, &md);
- mtx_unlock(&sd->seq_lock);
- if (ret != 0)
- return (ret);
-
- SEQ_DEBUG(printf("seq_write: loading a patch to the unit %d.\n", midiunit));
-
- ret = md->synth.loadpatch(md, *(short *)&event[0], buf,
- p + 4, count, 0);
- return (ret);
-#else
- /*
- * For now, just flush the darn buffer
- */
- SEQ_DEBUG(2,
- printf("seq_write: SEQ_FULLSIZE flusing buffer.\n"));
- while (uio->uio_resid > 0) {
- mtx_unlock(&scp->seq_lock);
- retval = uiomove(event, MIN(EV_SZ, uio->uio_resid), uio);
- mtx_lock(&scp->seq_lock);
- if (retval)
- goto err0;
- }
- retval = 0;
- goto err0;
-#endif
- }
- retval = EINVAL;
- if (ev_code >= 128) {
- int error;
-
- /*
- * Some sort of an extended event. The size is eight
- * bytes. scoop extra info.
- */
- if (scp->music && ev_code == SEQ_EXTENDED) {
- SEQ_DEBUG(2, printf("seq_write: invalid level two event %x.\n", ev_code));
- goto err0;
- }
- mtx_unlock(&scp->seq_lock);
- if (uio->uio_resid < 4)
- error = EINVAL;
- else
- error = uiomove((caddr_t)&event[4], 4, uio);
- mtx_lock(&scp->seq_lock);
- if (error) {
- SEQ_DEBUG(2,
- printf("seq_write: user memory mangled?\n"));
- goto err0;
- }
- } else {
- /*
- * Size four event.
- */
- if (scp->music) {
- SEQ_DEBUG(2, printf("seq_write: four byte event in music mode.\n"));
- goto err0;
- }
- }
- if (ev_code == SEQ_MIDIPUTC) {
- /*
- * TODO: event[2] is unit number to receive char.
- * Range check it.
- */
- }
- if (scp->music) {
-#ifdef not_ever_ever
- if (event[0] == EV_TIMING &&
- (event[1] == TMR_START || event[1] == TMR_STOP)) {
- /*
- * For now, try to make midimoutain work by
- * forcing these events to be processed
- * immediately.
- */
- seq_processevent(scp, event);
- } else
- MIDIQ_ENQ(scp->out_q, event, EV_SZ);
-#else
- MIDIQ_ENQ(scp->out_q, event, EV_SZ);
-#endif
- } else {
- if (seq_convertold(event, newevent) > 0)
- MIDIQ_ENQ(scp->out_q, newevent, EV_SZ);
-#if 0
- else
- goto err0;
-#endif
- }
- }
-
- scp->playing = 1;
- cv_broadcast(&scp->state_cv);
- cv_broadcast(&scp->out_cv);
-
- retval = 0;
-
-err0:
- SEQ_DEBUG(6,
- printf("seq_write done: leftover buffer length %zd retval %d\n",
- uio->uio_resid, retval));
- mtx_unlock(&scp->seq_lock);
- return retval;
-}
-
-int
-mseq_ioctl(struct cdev *i_dev, u_long cmd, caddr_t arg, int mode,
- struct thread *td)
-{
- int midiunit, ret, tmp;
- struct seq_softc *scp = i_dev->si_drv1;
- struct synth_info *synthinfo;
- struct midi_info *midiinfo;
- u_char event[EV_SZ];
- u_char newevent[EV_SZ];
-
- kobj_t md;
-
- /*
- * struct snd_size *sndsize;
- */
-
- if (scp == NULL)
- return ENXIO;
-
- SEQ_DEBUG(6, printf("seq_ioctl: unit %d, cmd %s.\n",
- scp->unit, midi_cmdname(cmd, cmdtab_seqioctl)));
-
- ret = 0;
-
- switch (cmd) {
- case SNDCTL_SEQ_GETTIME:
- /*
- * ioctl needed by libtse
- */
- mtx_lock(&scp->seq_lock);
- *(int *)arg = timer_now(scp);
- mtx_unlock(&scp->seq_lock);
- SEQ_DEBUG(6, printf("seq_ioctl: gettime %d.\n", *(int *)arg));
- ret = 0;
- break;
- case SNDCTL_TMR_METRONOME:
- /* fallthrough */
- case SNDCTL_TMR_SOURCE:
- /*
- * Not implemented
- */
- ret = 0;
- break;
- case SNDCTL_TMR_TEMPO:
- event[1] = TMR_TEMPO;
- event[4] = *(int *)arg & 0xFF;
- event[5] = (*(int *)arg >> 8) & 0xFF;
- event[6] = (*(int *)arg >> 16) & 0xFF;
- event[7] = (*(int *)arg >> 24) & 0xFF;
- goto timerevent;
- case SNDCTL_TMR_TIMEBASE:
- event[1] = TMR_TIMERBASE;
- event[4] = *(int *)arg & 0xFF;
- event[5] = (*(int *)arg >> 8) & 0xFF;
- event[6] = (*(int *)arg >> 16) & 0xFF;
- event[7] = (*(int *)arg >> 24) & 0xFF;
- goto timerevent;
- case SNDCTL_TMR_START:
- event[1] = TMR_START;
- goto timerevent;
- case SNDCTL_TMR_STOP:
- event[1] = TMR_STOP;
- goto timerevent;
- case SNDCTL_TMR_CONTINUE:
- event[1] = TMR_CONTINUE;
-timerevent:
- event[0] = EV_TIMING;
- mtx_lock(&scp->seq_lock);
- if (!scp->music) {
- ret = EINVAL;
- mtx_unlock(&scp->seq_lock);
- break;
- }
- seq_processevent(scp, event);
- mtx_unlock(&scp->seq_lock);
- break;
- case SNDCTL_TMR_SELECT:
- SEQ_DEBUG(2,
- printf("seq_ioctl: SNDCTL_TMR_SELECT not supported\n"));
- ret = EINVAL;
- break;
- case SNDCTL_SEQ_SYNC:
- if (mode == O_RDONLY) {
- ret = 0;
- break;
- }
- mtx_lock(&scp->seq_lock);
- ret = seq_sync(scp);
- mtx_unlock(&scp->seq_lock);
- break;
- case SNDCTL_SEQ_PANIC:
- /* fallthrough */
- case SNDCTL_SEQ_RESET:
- /*
- * SNDCTL_SEQ_PANIC == SNDCTL_SEQ_RESET
- */
- mtx_lock(&scp->seq_lock);
- seq_reset(scp);
- mtx_unlock(&scp->seq_lock);
- ret = 0;
- break;
- case SNDCTL_SEQ_TESTMIDI:
- mtx_lock(&scp->seq_lock);
- /*
- * TODO: SNDCTL_SEQ_TESTMIDI now means "can I write to the
- * device?".
- */
- mtx_unlock(&scp->seq_lock);
- break;
-#if 0
- case SNDCTL_SEQ_GETINCOUNT:
- if (mode == O_WRONLY)
- *(int *)arg = 0;
- else {
- mtx_lock(&scp->seq_lock);
- *(int *)arg = scp->in_q.rl;
- mtx_unlock(&scp->seq_lock);
- SEQ_DEBUG(printf("seq_ioctl: incount %d.\n",
- *(int *)arg));
- }
- ret = 0;
- break;
- case SNDCTL_SEQ_GETOUTCOUNT:
- if (mode == O_RDONLY)
- *(int *)arg = 0;
- else {
- mtx_lock(&scp->seq_lock);
- *(int *)arg = scp->out_q.fl;
- mtx_unlock(&scp->seq_lock);
- SEQ_DEBUG(printf("seq_ioctl: outcount %d.\n",
- *(int *)arg));
- }
- ret = 0;
- break;
-#endif
- case SNDCTL_SEQ_CTRLRATE:
- if (*(int *)arg != 0) {
- ret = EINVAL;
- break;
- }
- mtx_lock(&scp->seq_lock);
- *(int *)arg = scp->timerbase;
- mtx_unlock(&scp->seq_lock);
- SEQ_DEBUG(3, printf("seq_ioctl: ctrlrate %d.\n", *(int *)arg));
- ret = 0;
- break;
- /*
- * TODO: ioctl SNDCTL_SEQ_RESETSAMPLES
- */
-#if 0
- case SNDCTL_SEQ_RESETSAMPLES:
- mtx_lock(&scp->seq_lock);
- ret = lookup_mididev(scp, *(int *)arg, LOOKUP_OPEN, &md);
- mtx_unlock(&scp->seq_lock);
- if (ret != 0)
- break;
- ret = midi_ioctl(MIDIMKDEV(major(i_dev), *(int *)arg,
- SND_DEV_MIDIN), cmd, arg, mode, td);
- break;
-#endif
- case SNDCTL_SEQ_NRSYNTHS:
- mtx_lock(&scp->seq_lock);
- *(int *)arg = scp->midi_number;
- mtx_unlock(&scp->seq_lock);
- SEQ_DEBUG(3, printf("seq_ioctl: synths %d.\n", *(int *)arg));
- ret = 0;
- break;
- case SNDCTL_SEQ_NRMIDIS:
- mtx_lock(&scp->seq_lock);
- if (scp->music)
- *(int *)arg = 0;
- else {
- /*
- * TODO: count the numbder of devices that can WRITERAW
- */
- *(int *)arg = scp->midi_number;
- }
- mtx_unlock(&scp->seq_lock);
- SEQ_DEBUG(3, printf("seq_ioctl: midis %d.\n", *(int *)arg));
- ret = 0;
- break;
- /*
- * TODO: ioctl SNDCTL_SYNTH_MEMAVL
- */
-#if 0
- case SNDCTL_SYNTH_MEMAVL:
- mtx_lock(&scp->seq_lock);
- ret = lookup_mididev(scp, *(int *)arg, LOOKUP_OPEN, &md);
- mtx_unlock(&scp->seq_lock);
- if (ret != 0)
- break;
- ret = midi_ioctl(MIDIMKDEV(major(i_dev), *(int *)arg,
- SND_DEV_MIDIN), cmd, arg, mode, td);
- break;
-#endif
- case SNDCTL_SEQ_OUTOFBAND:
- for (ret = 0; ret < EV_SZ; ret++)
- event[ret] = (u_char)arg[0];
-
- mtx_lock(&scp->seq_lock);
- if (scp->music)
- ret = seq_processevent(scp, event);
- else {
- if (seq_convertold(event, newevent) > 0)
- ret = seq_processevent(scp, newevent);
- else
- ret = EINVAL;
- }
- mtx_unlock(&scp->seq_lock);
- break;
- case SNDCTL_SYNTH_INFO:
- synthinfo = (struct synth_info *)arg;
- midiunit = synthinfo->device;
- mtx_lock(&scp->seq_lock);
- if (seq_fetch_mid(scp, midiunit, &md) == 0) {
- bzero(synthinfo, sizeof(*synthinfo));
- synthinfo->name[0] = 'f';
- synthinfo->name[1] = 'a';
- synthinfo->name[2] = 'k';
- synthinfo->name[3] = 'e';
- synthinfo->name[4] = 's';
- synthinfo->name[5] = 'y';
- synthinfo->name[6] = 'n';
- synthinfo->name[7] = 't';
- synthinfo->name[8] = 'h';
- synthinfo->device = midiunit;
- synthinfo->synth_type = SYNTH_TYPE_MIDI;
- synthinfo->capabilities = scp->midi_flags[midiunit];
- ret = 0;
- } else
- ret = EINVAL;
- mtx_unlock(&scp->seq_lock);
- break;
- case SNDCTL_MIDI_INFO:
- midiinfo = (struct midi_info *)arg;
- midiunit = midiinfo->device;
- mtx_lock(&scp->seq_lock);
- if (seq_fetch_mid(scp, midiunit, &md) == 0) {
- bzero(midiinfo, sizeof(*midiinfo));
- midiinfo->name[0] = 'f';
- midiinfo->name[1] = 'a';
- midiinfo->name[2] = 'k';
- midiinfo->name[3] = 'e';
- midiinfo->name[4] = 'm';
- midiinfo->name[5] = 'i';
- midiinfo->name[6] = 'd';
- midiinfo->name[7] = 'i';
- midiinfo->device = midiunit;
- midiinfo->capabilities = scp->midi_flags[midiunit];
- /*
- * TODO: What devtype?
- */
- midiinfo->dev_type = 0x01;
- ret = 0;
- } else
- ret = EINVAL;
- mtx_unlock(&scp->seq_lock);
- break;
- case SNDCTL_SEQ_THRESHOLD:
- mtx_lock(&scp->seq_lock);
- RANGE(*(int *)arg, 1, MIDIQ_SIZE(scp->out_q) - 1);
- scp->out_water = *(int *)arg;
- mtx_unlock(&scp->seq_lock);
- SEQ_DEBUG(3, printf("seq_ioctl: water %d.\n", *(int *)arg));
- ret = 0;
- break;
- case SNDCTL_MIDI_PRETIME:
- tmp = *(int *)arg;
- if (tmp < 0)
- tmp = 0;
- mtx_lock(&scp->seq_lock);
- scp->pre_event_timeout = (hz * tmp) / 10;
- *(int *)arg = scp->pre_event_timeout;
- mtx_unlock(&scp->seq_lock);
- SEQ_DEBUG(3, printf("seq_ioctl: pretime %d.\n", *(int *)arg));
- ret = 0;
- break;
- case SNDCTL_FM_4OP_ENABLE:
- case SNDCTL_PMGR_IFACE:
- case SNDCTL_PMGR_ACCESS:
- /*
- * Patch manager and fm are ded, ded, ded.
- */
- /* fallthrough */
- default:
- /*
- * TODO: Consider ioctl default case.
- * Old code used to
- * if ((scp->fflags & O_ACCMODE) == FREAD) {
- * ret = EIO;
- * break;
- * }
- * Then pass on the ioctl to device 0
- */
- SEQ_DEBUG(2,
- printf("seq_ioctl: unsupported IOCTL %ld.\n", cmd));
- ret = EINVAL;
- break;
- }
-
- return ret;
-}
-
-int
-mseq_poll(struct cdev *i_dev, int events, struct thread *td)
-{
- int ret, lim;
- struct seq_softc *scp = i_dev->si_drv1;
-
- SEQ_DEBUG(3, printf("seq_poll: unit %d.\n", scp->unit));
- SEQ_DEBUG(1, printf("seq_poll: unit %d.\n", scp->unit));
-
- mtx_lock(&scp->seq_lock);
-
- ret = 0;
-
- /* Look up the appropriate queue and select it. */
- if ((events & (POLLOUT | POLLWRNORM)) != 0) {
- /* Start playing. */
- scp->playing = 1;
- cv_broadcast(&scp->state_cv);
- cv_broadcast(&scp->out_cv);
-
- lim = scp->out_water;
-
- if (MIDIQ_AVAIL(scp->out_q) < lim)
- /* No enough space, record select. */
- selrecord(td, &scp->out_sel);
- else
- /* We can write now. */
- ret |= events & (POLLOUT | POLLWRNORM);
- }
- if ((events & (POLLIN | POLLRDNORM)) != 0) {
- /* TODO: Start recording. */
-
- /* Find out the boundary. */
- lim = 1;
- if (MIDIQ_LEN(scp->in_q) < lim)
- /* No data ready, record select. */
- selrecord(td, &scp->in_sel);
- else
- /* We can read now. */
- ret |= events & (POLLIN | POLLRDNORM);
- }
- mtx_unlock(&scp->seq_lock);
-
- return (ret);
-}
-
-#if 0
-static void
-sein_qtr(void *p, void /* mididev_info */ *md)
-{
- struct seq_softc *scp;
-
- scp = (struct seq_softc *)p;
-
- mtx_lock(&scp->seq_lock);
-
- /* Restart playing if we have the data to output. */
- if (scp->queueout_pending)
- seq_callback(scp, SEQ_CB_START | SEQ_CB_WR);
- /* Check the midi device if we are reading. */
- if ((scp->flags & SEQ_F_READING) != 0)
- seq_midiinput(scp, md);
-
- mtx_unlock(&scp->seq_lock);
-}
-
-#endif
-/*
- * seq_convertold
- * Was the old playevent. Use this to convert and old
- * style /dev/sequencer event to a /dev/music event
- */
-static int
-seq_convertold(u_char *event, u_char *out)
-{
- int used;
- u_char dev, chn, note, vel;
-
- out[0] = out[1] = out[2] = out[3] = out[4] = out[5] = out[6] =
- out[7] = 0;
-
- dev = 0;
- chn = event[1];
- note = event[2];
- vel = event[3];
-
- used = 0;
-
-restart:
- /*
- * TODO: Debug statement
- */
- switch (event[0]) {
- case EV_TIMING:
- case EV_CHN_VOICE:
- case EV_CHN_COMMON:
- case EV_SYSEX:
- case EV_SEQ_LOCAL:
- out[0] = event[0];
- out[1] = event[1];
- out[2] = event[2];
- out[3] = event[3];
- out[4] = event[4];
- out[5] = event[5];
- out[6] = event[6];
- out[7] = event[7];
- used += 8;
- break;
- case SEQ_NOTEOFF:
- out[0] = EV_CHN_VOICE;
- out[1] = dev;
- out[2] = MIDI_NOTEOFF;
- out[3] = chn;
- out[4] = note;
- out[5] = 255;
- used += 4;
- break;
-
- case SEQ_NOTEON:
- out[0] = EV_CHN_VOICE;
- out[1] = dev;
- out[2] = MIDI_NOTEON;
- out[3] = chn;
- out[4] = note;
- out[5] = vel;
- used += 4;
- break;
-
- /*
- * wait delay = (event[2] << 16) + (event[3] << 8) + event[4]
- */
-
- case SEQ_PGMCHANGE:
- out[0] = EV_CHN_COMMON;
- out[1] = dev;
- out[2] = MIDI_PGM_CHANGE;
- out[3] = chn;
- out[4] = note;
- out[5] = vel;
- used += 4;
- break;
-/*
- out[0] = EV_TIMING;
- out[1] = dev;
- out[2] = MIDI_PGM_CHANGE;
- out[3] = chn;
- out[4] = note;
- out[5] = vel;
- SEQ_DEBUG(4,printf("seq_playevent: synctimer\n"));
- break;
-*/
-
- case SEQ_MIDIPUTC:
- SEQ_DEBUG(4,
- printf("seq_playevent: put data 0x%02x, unit %d.\n",
- event[1], event[2]));
- /*
- * Pass through to the midi device.
- * device = event[2]
- * data = event[1]
- */
- out[0] = SEQ_MIDIPUTC;
- out[1] = dev;
- out[2] = chn;
- used += 4;
- break;
-#ifdef notyet
- case SEQ_ECHO:
- /*
- * This isn't handled here yet because I don't know if I can
- * just use four bytes events. There might be consequences
- * in the _read routing
- */
- if (seq_copytoinput(scp, event, 4) == EAGAIN) {
- ret = QUEUEFULL;
- break;
- }
- ret = MORE;
- break;
-#endif
- case SEQ_EXTENDED:
- switch (event[1]) {
- case SEQ_NOTEOFF:
- case SEQ_NOTEON:
- case SEQ_PGMCHANGE:
- event++;
- used = 4;
- goto restart;
- break;
- case SEQ_AFTERTOUCH:
- /*
- * SYNTH_AFTERTOUCH(md, event[3], event[4])
- */
- case SEQ_BALANCE:
- /*
- * SYNTH_PANNING(md, event[3], (char)event[4])
- */
- case SEQ_CONTROLLER:
- /*
- * SYNTH_CONTROLLER(md, event[3], event[4], *(short *)&event[5])
- */
- case SEQ_VOLMODE:
- /*
- * SYNTH_VOLUMEMETHOD(md, event[3])
- */
- default:
- SEQ_DEBUG(2,
- printf("seq_convertold: SEQ_EXTENDED type %d"
- "not handled\n", event[1]));
- break;
- }
- break;
- case SEQ_WAIT:
- out[0] = EV_TIMING;
- out[1] = TMR_WAIT_REL;
- out[4] = event[2];
- out[5] = event[3];
- out[6] = event[4];
-
- SEQ_DEBUG(5, printf("SEQ_WAIT %d",
- event[2] + (event[3] << 8) + (event[4] << 24)));
-
- used += 4;
- break;
-
- case SEQ_ECHO:
- case SEQ_SYNCTIMER:
- case SEQ_PRIVATE:
- default:
- SEQ_DEBUG(2,
- printf("seq_convertold: event type %d not handled %d %d %d\n",
- event[0], event[1], event[2], event[3]));
- break;
- }
- return used;
-}
-
-/*
- * Writting to the sequencer buffer never blocks and drops
- * input which cannot be queued
- */
-void
-seq_copytoinput(struct seq_softc *scp, u_char *event, int len)
-{
-
- mtx_assert(&scp->seq_lock, MA_OWNED);
-
- if (MIDIQ_AVAIL(scp->in_q) < len) {
- /*
- * ENOROOM? EINPUTDROPPED? ETOUGHLUCK?
- */
- SEQ_DEBUG(2, printf("seq_copytoinput: queue full\n"));
- } else {
- MIDIQ_ENQ(scp->in_q, event, len);
- selwakeup(&scp->in_sel);
- cv_broadcast(&scp->in_cv);
- }
-
-}
-
-static int
-seq_chnvoice(struct seq_softc *scp, kobj_t md, u_char *event)
-{
- int ret, voice;
- u_char cmd, chn, note, parm;
-
- ret = 0;
- cmd = event[2];
- chn = event[3];
- note = event[4];
- parm = event[5];
-
- mtx_assert(&scp->seq_lock, MA_OWNED);
-
- SEQ_DEBUG(5, printf("seq_chnvoice: unit %d, dev %d, cmd %s,"
- " chn %d, note %d, parm %d.\n", scp->unit, event[1],
- midi_cmdname(cmd, cmdtab_seqcv), chn, note, parm));
-
- voice = SYNTH_ALLOC(md, chn, note);
-
- mtx_unlock(&scp->seq_lock);
-
- switch (cmd) {
- case MIDI_NOTEON:
- if (note < 128 || note == 255) {
-#if 0
- if (scp->music && chn == 9) {
- /*
- * This channel is a percussion. The note
- * number is the patch number.
- */
- /*
- mtx_unlock(&scp->seq_lock);
- if (SYNTH_SETINSTR(md, voice, 128 + note)
- == EAGAIN) {
- mtx_lock(&scp->seq_lock);
- return (QUEUEFULL);
- }
- mtx_lock(&scp->seq_lock);
- */
- note = 60; /* Middle C. */
- }
-#endif
- if (scp->music) {
- /*
- mtx_unlock(&scp->seq_lock);
- if (SYNTH_SETUPVOICE(md, voice, chn)
- == EAGAIN) {
- mtx_lock(&scp->seq_lock);
- return (QUEUEFULL);
- }
- mtx_lock(&scp->seq_lock);
- */
- }
- SYNTH_STARTNOTE(md, voice, note, parm);
- }
- break;
- case MIDI_NOTEOFF:
- SYNTH_KILLNOTE(md, voice, note, parm);
- break;
- case MIDI_KEY_PRESSURE:
- SYNTH_AFTERTOUCH(md, voice, parm);
- break;
- default:
- ret = 1;
- SEQ_DEBUG(2, printf("seq_chnvoice event type %d not handled\n",
- event[1]));
- break;
- }
-
- mtx_lock(&scp->seq_lock);
- return ret;
-}
-
-static int
-seq_chncommon(struct seq_softc *scp, kobj_t md, u_char *event)
-{
- int ret;
- u_short w14;
- u_char cmd, chn, p1;
-
- ret = 0;
- cmd = event[2];
- chn = event[3];
- p1 = event[4];
- w14 = *(u_short *)&event[6];
-
- SEQ_DEBUG(5, printf("seq_chncommon: unit %d, dev %d, cmd %s, chn %d,"
- " p1 %d, w14 %d.\n", scp->unit, event[1],
- midi_cmdname(cmd, cmdtab_seqccmn), chn, p1, w14));
- mtx_unlock(&scp->seq_lock);
- switch (cmd) {
- case MIDI_PGM_CHANGE:
- SEQ_DEBUG(4, printf("seq_chncommon pgmchn chn %d pg %d\n",
- chn, p1));
- SYNTH_SETINSTR(md, chn, p1);
- break;
- case MIDI_CTL_CHANGE:
- SEQ_DEBUG(4, printf("seq_chncommon ctlch chn %d pg %d %d\n",
- chn, p1, w14));
- SYNTH_CONTROLLER(md, chn, p1, w14);
- break;
- case MIDI_PITCH_BEND:
- if (scp->music) {
- /*
- * TODO: MIDI_PITCH_BEND
- */
-#if 0
- mtx_lock(&md->synth.vc_mtx);
- md->synth.chn_info[chn].bender_value = w14;
- if (md->midiunit >= 0) {
- /*
- * Handle all of the notes playing on this
- * channel.
- */
- key = ((int)chn << 8);
- for (i = 0; i < md->synth.alloc.max_voice; i++)
- if ((md->synth.alloc.map[i] & 0xff00) == key) {
- mtx_unlock(&md->synth.vc_mtx);
- mtx_unlock(&scp->seq_lock);
- if (md->synth.bender(md, i, w14) == EAGAIN) {
- mtx_lock(&scp->seq_lock);
- return (QUEUEFULL);
- }
- mtx_lock(&scp->seq_lock);
- }
- } else {
- mtx_unlock(&md->synth.vc_mtx);
- mtx_unlock(&scp->seq_lock);
- if (md->synth.bender(md, chn, w14) == EAGAIN) {
- mtx_lock(&scp->seq_lock);
- return (QUEUEFULL);
- }
- mtx_lock(&scp->seq_lock);
- }
-#endif
- } else
- SYNTH_BENDER(md, chn, w14);
- break;
- default:
- ret = 1;
- SEQ_DEBUG(2,
- printf("seq_chncommon event type %d not handled.\n",
- event[1]));
- break;
- }
- mtx_lock(&scp->seq_lock);
- return ret;
-}
-
-static int
-seq_timing(struct seq_softc *scp, u_char *event)
-{
- int param;
- int ret;
-
- ret = 0;
- param = event[4] + (event[5] << 8) +
- (event[6] << 16) + (event[7] << 24);
-
- SEQ_DEBUG(5, printf("seq_timing: unit %d, cmd %d, param %d.\n",
- scp->unit, event[1], param));
- switch (event[1]) {
- case TMR_WAIT_REL:
- timer_wait(scp, param, 0);
- break;
- case TMR_WAIT_ABS:
- timer_wait(scp, param, 1);
- break;
- case TMR_START:
- timer_start(scp);
- cv_broadcast(&scp->reset_cv);
- break;
- case TMR_STOP:
- timer_stop(scp);
- /*
- * The following cv_broadcast isn't needed since we only
- * wait for 0->1 transitions. It probably won't hurt
- */
- cv_broadcast(&scp->reset_cv);
- break;
- case TMR_CONTINUE:
- timer_continue(scp);
- cv_broadcast(&scp->reset_cv);
- break;
- case TMR_TEMPO:
- if (param < 8)
- param = 8;
- if (param > 360)
- param = 360;
- SEQ_DEBUG(4, printf("Timer set tempo %d\n", param));
- timer_setvals(scp, param, scp->timerbase);
- break;
- case TMR_TIMERBASE:
- if (param < 1)
- param = 1;
- if (param > 1000)
- param = 1000;
- SEQ_DEBUG(4, printf("Timer set timerbase %d\n", param));
- timer_setvals(scp, scp->tempo, param);
- break;
- case TMR_ECHO:
- /*
- * TODO: Consider making 4-byte events for /dev/sequencer
- * PRO: Maybe needed by legacy apps
- * CON: soundcard.h has been warning for a while many years
- * to expect 8 byte events.
- */
-#if 0
- if (scp->music)
- seq_copytoinput(scp, event, 8);
- else {
- param = (param << 8 | SEQ_ECHO);
- seq_copytoinput(scp, (u_char *)&param, 4);
- }
-#else
- seq_copytoinput(scp, event, 8);
-#endif
- break;
- default:
- SEQ_DEBUG(2, printf("seq_timing event type %d not handled.\n",
- event[1]));
- ret = 1;
- break;
- }
- return ret;
-}
-
-static int
-seq_local(struct seq_softc *scp, u_char *event)
-{
- int ret;
-
- ret = 0;
- mtx_assert(&scp->seq_lock, MA_OWNED);
-
- SEQ_DEBUG(5, printf("seq_local: unit %d, cmd %d\n", scp->unit,
- event[1]));
- switch (event[1]) {
- default:
- SEQ_DEBUG(1, printf("seq_local event type %d not handled\n",
- event[1]));
- ret = 1;
- break;
- }
- return ret;
-}
-
-static int
-seq_sysex(struct seq_softc *scp, kobj_t md, u_char *event)
-{
- int i, l;
-
- mtx_assert(&scp->seq_lock, MA_OWNED);
- SEQ_DEBUG(5, printf("seq_sysex: unit %d device %d\n", scp->unit,
- event[1]));
- l = 0;
- for (i = 0; i < 6 && event[i + 2] != 0xff; i++)
- l = i + 1;
- if (l > 0) {
- mtx_unlock(&scp->seq_lock);
- if (SYNTH_SENDSYSEX(md, &event[2], l) == EAGAIN) {
- mtx_lock(&scp->seq_lock);
- return 1;
- }
- mtx_lock(&scp->seq_lock);
- }
- return 0;
-}
-
-/*
- * Reset no longer closes the raw devices nor seq_sync's
- * Callers are IOCTL and seq_close
- */
-static void
-seq_reset(struct seq_softc *scp)
-{
- int chn, i;
- kobj_t m;
-
- mtx_assert(&scp->seq_lock, MA_OWNED);
-
- SEQ_DEBUG(5, printf("seq_reset: unit %d.\n", scp->unit));
-
- /*
- * Stop reading and writing.
- */
-
- /* scp->recording = 0; */
- scp->playing = 0;
- cv_broadcast(&scp->state_cv);
- cv_broadcast(&scp->out_cv);
- cv_broadcast(&scp->reset_cv);
-
- /*
- * For now, don't reset the timers.
- */
- MIDIQ_CLEAR(scp->in_q);
- MIDIQ_CLEAR(scp->out_q);
-
- for (i = 0; i < scp->midi_number; i++) {
- m = scp->midis[i];
- mtx_unlock(&scp->seq_lock);
- SYNTH_RESET(m);
- for (chn = 0; chn < 16; chn++) {
- SYNTH_CONTROLLER(m, chn, 123, 0);
- SYNTH_CONTROLLER(m, chn, 121, 0);
- SYNTH_BENDER(m, chn, 1 << 13);
- }
- mtx_lock(&scp->seq_lock);
- }
-}
-
-/*
- * seq_sync
- * *really* flush the output queue
- * flush the event queue, then flush the synthsisers.
- * Callers are IOCTL and close
- */
-
-#define SEQ_SYNC_TIMEOUT 8
-static int
-seq_sync(struct seq_softc *scp)
-{
- int i, rl, sync[16], done;
-
- mtx_assert(&scp->seq_lock, MA_OWNED);
-
- SEQ_DEBUG(4, printf("seq_sync: unit %d.\n", scp->unit));
-
- /*
- * Wait until output queue is empty. Check every so often to see if
- * the queue is moving along. If it isn't just abort.
- */
- while (!MIDIQ_EMPTY(scp->out_q)) {
- if (!scp->playing) {
- scp->playing = 1;
- cv_broadcast(&scp->state_cv);
- cv_broadcast(&scp->out_cv);
- }
- rl = MIDIQ_LEN(scp->out_q);
-
- i = cv_timedwait_sig(&scp->out_cv,
- &scp->seq_lock, SEQ_SYNC_TIMEOUT * hz);
-
- if (i == EINTR || i == ERESTART) {
- if (i == EINTR) {
- /*
- * XXX: I don't know why we stop playing
- */
- scp->playing = 0;
- cv_broadcast(&scp->out_cv);
- }
- return i;
- }
- if (i == EWOULDBLOCK && rl == MIDIQ_LEN(scp->out_q) &&
- scp->waiting == 0) {
- /*
- * A queue seems to be stuck up. Give up and clear
- * queues.
- */
- MIDIQ_CLEAR(scp->out_q);
- scp->playing = 0;
- cv_broadcast(&scp->state_cv);
- cv_broadcast(&scp->out_cv);
- cv_broadcast(&scp->reset_cv);
-
- /*
- * TODO: Consider if the raw devices need to be flushed
- */
-
- SEQ_DEBUG(1, printf("seq_sync queue stuck, aborting\n"));
-
- return i;
- }
- }
-
- scp->playing = 0;
- /*
- * Since syncing a midi device might block, unlock scp->seq_lock.
- */
-
- mtx_unlock(&scp->seq_lock);
- for (i = 0; i < scp->midi_number; i++)
- sync[i] = 1;
-
- do {
- done = 1;
- for (i = 0; i < scp->midi_number; i++)
- if (sync[i]) {
- if (SYNTH_INSYNC(scp->midis[i]) == 0)
- sync[i] = 0;
- else
- done = 0;
- }
- if (!done)
- DELAY(5000);
-
- } while (!done);
-
- mtx_lock(&scp->seq_lock);
- return 0;
-}
-
-char *
-midi_cmdname(int cmd, midi_cmdtab *tab)
-{
- while (tab->name != NULL) {
- if (cmd == tab->cmd)
- return (tab->name);
- tab++;
- }
-
- return ("unknown");
-}
diff --git a/sys/dev/sound/midi/sequencer.h b/sys/dev/sound/midi/sequencer.h
deleted file mode 100644
index 22ea0ae6c1b6..000000000000
--- a/sys/dev/sound/midi/sequencer.h
+++ /dev/null
@@ -1,89 +0,0 @@
-/*-
- * SPDX-License-Identifier: BSD-2-Clause
- *
- * Copyright (c) 2003 Mathew Kanner
- * Copyright (c) 1999 Seigo Tanimura
- * 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.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
- */
-
-/*
- * Include file for the midi sequence driver.
- */
-
-#ifndef _SEQUENCER_H_
-#define _SEQUENCER_H_
-
-#define NSEQ_MAX 16
-
-/*
- * many variables should be reduced to a range. Here define a macro
- */
-
-#define RANGE(var, low, high) (var) = \
-((var)<(low)?(low) : (var)>(high)?(high) : (var))
-
-#ifdef _KERNEL
-
-void seq_timer(void *arg);
-
-SYSCTL_DECL(_hw_midi_seq);
-
-extern int seq_debug;
-
-#define SEQ_DEBUG(y, x) \
- do { \
- if (seq_debug >= y) { \
- (x); \
- } \
- } while (0)
-
-SYSCTL_DECL(_hw_midi);
-
-#endif /* _KERNEL */
-
-#define SYNTHPROP_MIDI 1
-#define SYNTHPROP_SYNTH 2
-#define SYNTHPROP_RX 4
-#define SYNTHPROP_TX 8
-
-struct _midi_cmdtab {
- int cmd;
- char *name;
-};
-typedef struct _midi_cmdtab midi_cmdtab;
-extern midi_cmdtab cmdtab_seqevent[];
-extern midi_cmdtab cmdtab_seqioctl[];
-extern midi_cmdtab cmdtab_timer[];
-extern midi_cmdtab cmdtab_seqcv[];
-extern midi_cmdtab cmdtab_seqccmn[];
-
-char *midi_cmdname(int cmd, midi_cmdtab * tab);
-
-enum {
- MORE,
- TIMERARMED,
- QUEUEFULL
-};
-
-#endif
diff --git a/sys/dev/sound/midi/synth_if.m b/sys/dev/sound/midi/synth_if.m
deleted file mode 100644
index a763b3422bc6..000000000000
--- a/sys/dev/sound/midi/synth_if.m
+++ /dev/null
@@ -1,312 +0,0 @@
-#-
-# Copyright (c) 2003 Mathew Kanner
-# 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.
-#
-# THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
-#
-#
-
-INTERFACE synth;
-
-#include <sys/systm.h>
-
-CODE {
-
-synth_killnote_t nokillnote;
-synth_startnote_t nostartnote;
-synth_setinstr_t nosetinstr;
-synth_hwcontrol_t nohwcontrol;
-synth_aftertouch_t noaftertouch;
-synth_panning_t nopanning;
-synth_controller_t nocontroller;
-synth_volumemethod_t novolumemethod;
-synth_bender_t nobender;
-synth_setupvoice_t nosetupvoice;
-synth_sendsysex_t nosendsysex;
-synth_allocvoice_t noallocvoice;
-synth_writeraw_t nowriteraw;
-synth_reset_t noreset;
-synth_shortname_t noshortname;
-synth_open_t noopen;
-synth_close_t noclose;
-synth_query_t noquery;
-synth_insync_t noinsync;
-synth_alloc_t noalloc;
-
- int
- nokillnote(void *_kobj, uint8_t _chn, uint8_t _note, uint8_t _vel)
- {
- printf("nokillnote\n");
- return 0;
- }
-
- int
- noopen(void *_kobj, void *_arg, int mode)
- {
- printf("noopen\n");
- return 0;
- }
-
- int
- noquery(void *_kboj)
- {
- printf("noquery\n");
- return 0;
- }
-
- int
- nostartnote(void *_kb, uint8_t _voice, uint8_t _note, uint8_t _parm)
- {
- printf("nostartnote\n");
- return 0;
- }
-
- int
- nosetinstr(void *_kb, uint8_t _chn, uint16_t _patchno)
- {
- printf("nosetinstr\n");
- return 0;
- }
-
- int
- nohwcontrol(void *_kb, uint8_t *_event)
- {
- printf("nohwcontrol\n");
- return 0;
- }
-
- int
- noaftertouch ( void /* X */ * _kobj, uint8_t _x1, uint8_t _x2)
- {
- printf("noaftertouch\n");
- return 0;
- }
-
- int
- nopanning ( void /* X */ * _kobj, uint8_t _x1, uint8_t _x2)
- {
- printf("nopanning\n");
- return 0;
- }
-
- int
- nocontroller ( void /* X */ * _kobj, uint8_t _x1, uint8_t _x2, uint16_t _x3)
- {
- printf("nocontroller\n");
- return 0;
- }
-
- int
- novolumemethod (
- void /* X */ * _kobj,
- uint8_t _x1)
- {
- printf("novolumemethod\n");
- return 0;
- }
-
- int
- nobender ( void /* X */ * _kobj, uint8_t _voice, uint16_t _bend)
- {
- printf("nobender\n");
- return 0;
- }
-
- int
- nosetupvoice ( void /* X */ * _kobj, uint8_t _voice, uint8_t _chn)
- {
-
- printf("nosetupvoice\n");
- return 0;
- }
-
- int
- nosendsysex ( void /* X */ * _kobj, void * _buf, size_t _len)
- {
- printf("nosendsysex\n");
- return 0;
- }
-
- int
- noallocvoice ( void /* X */ * _kobj, uint8_t _chn, uint8_t _note, void *_x)
- {
- printf("noallocvoice\n");
- return 0;
- }
-
- int
- nowriteraw ( void /* X */ * _kobjt, uint8_t * _buf, size_t _len)
- {
- printf("nowriteraw\n");
- return 1;
- }
-
- int
- noreset ( void /* X */ * _kobjt)
- {
-
- printf("noreset\n");
- return 0;
- }
-
- char *
- noshortname (void /* X */ * _kobjt)
- {
- printf("noshortname\n");
- return "noshortname";
- }
-
- int
- noclose ( void /* X */ * _kobjt)
- {
-
- printf("noclose\n");
- return 0;
- }
-
- int
- noinsync (void /* X */ * _kobjt)
- {
-
- printf("noinsync\n");
- return 0;
- }
-
- int
- noalloc ( void /* x */ * _kbojt, uint8_t _chn, uint8_t _note)
- {
- printf("noalloc\n");
- return 0;
- }
-}
-
-METHOD int killnote {
- void /* X */ *_kobj;
- uint8_t _chan;
- uint8_t _note;
- uint8_t _vel;
-} DEFAULT nokillnote;
-
-METHOD int startnote {
- void /* X */ *_kobj;
- uint8_t _voice;
- uint8_t _note;
- uint8_t _parm;
-} DEFAULT nostartnote;
-
-METHOD int setinstr {
- void /* X */ *_kobj;
- uint8_t _chn;
- uint16_t _patchno;
-} DEFAULT nosetinstr;
-
-METHOD int hwcontrol {
- void /* X */ *_kobj;
- uint8_t *_event;
-} DEFAULT nohwcontrol;
-
-METHOD int aftertouch {
- void /* X */ *_kobj;
- uint8_t _x1;
- uint8_t _x2;
-} DEFAULT noaftertouch;
-
-METHOD int panning {
- void /* X */ *_kobj;
- uint8_t _x1;
- uint8_t _x2;
-} DEFAULT nopanning;
-
-METHOD int controller {
- void /* X */ *_kobj;
- uint8_t _x1;
- uint8_t _x2;
- uint16_t _x3;
-} DEFAULT nocontroller;
-
-METHOD int volumemethod {
- void /* X */ *_kobj;
- uint8_t _x1;
-} DEFAULT novolumemethod;
-
-METHOD int bender {
- void /* X */ *_kobj;
- uint8_t _voice;
- uint16_t _bend;
-} DEFAULT nobender;
-
-METHOD int setupvoice {
- void /* X */ *_kobj;
- uint8_t _voice;
- uint8_t _chn;
-} DEFAULT nosetupvoice;
-
-METHOD int sendsysex {
- void /* X */ *_kobj;
- void *_buf;
- size_t _len;
-} DEFAULT nosendsysex;
-
-METHOD int allocvoice {
- void /* X */ *_kobj;
- uint8_t _chn;
- uint8_t _note;
- void *_x;
-} DEFAULT noallocvoice;
-
-METHOD int writeraw {
- void /* X */ *_kobjt;
- uint8_t *_buf;
- size_t _len;
-} DEFAULT nowriteraw;
-
-METHOD int reset {
- void /* X */ *_kobjt;
-} DEFAULT noreset;
-
-METHOD char * shortname {
- void /* X */ *_kobjt;
-} DEFAULT noshortname;
-
-METHOD int open {
- void /* X */ *_kobjt;
- void *_sythn;
- int _mode;
-} DEFAULT noopen;
-
-METHOD int close {
- void /* X */ *_kobjt;
-} DEFAULT noclose;
-
-METHOD int query {
- void /* X */ *_kobjt;
-} DEFAULT noquery;
-
-METHOD int insync {
- void /* X */ *_kobjt;
-} DEFAULT noinsync;
-
-METHOD int alloc {
- void /* x */ *_kbojt;
- uint8_t _chn;
- uint8_t _note;
-} DEFAULT noalloc;
diff --git a/sys/dev/sound/pcm/mixer.c b/sys/dev/sound/pcm/mixer.c
index 092af3298f0e..f281dff36248 100644
--- a/sys/dev/sound/pcm/mixer.c
+++ b/sys/dev/sound/pcm/mixer.c
@@ -750,8 +750,8 @@ mixer_init(device_t dev, kobj_class_t cls, void *devinfo)
mixer_setrecsrc(m, 0); /* Set default input. */
- pdev = make_dev(&mixer_cdevsw, SND_DEV_CTL, UID_ROOT, GID_WHEEL, 0666,
- "mixer%d", unit);
+ pdev = make_dev(&mixer_cdevsw, 0, UID_ROOT, GID_WHEEL, 0666, "mixer%d",
+ unit);
pdev->si_drv1 = m;
snddev->mixer_dev = pdev;
diff --git a/sys/dev/sound/pcm/sndstat.c b/sys/dev/sound/pcm/sndstat.c
index 509a35c5a038..51d0fb3bb686 100644
--- a/sys/dev/sound/pcm/sndstat.c
+++ b/sys/dev/sound/pcm/sndstat.c
@@ -52,7 +52,6 @@
#define SS_TYPE_PCM 1
#define SS_TYPE_MIDI 2
-#define SS_TYPE_SEQUENCER 3
static d_open_t sndstat_open;
static void sndstat_close(void *);
@@ -1165,8 +1164,6 @@ sndstat_register(device_t dev, char *str)
type = SS_TYPE_PCM;
else if (!strcmp(devtype, "midi"))
type = SS_TYPE_MIDI;
- else if (!strcmp(devtype, "sequencer"))
- type = SS_TYPE_SEQUENCER;
else
return (EINVAL);
@@ -1441,8 +1438,8 @@ static void
sndstat_sysinit(void *p)
{
sx_init(&sndstat_lock, "sndstat lock");
- sndstat_dev = make_dev(&sndstat_cdevsw, SND_DEV_STATUS,
- UID_ROOT, GID_WHEEL, 0644, "sndstat");
+ sndstat_dev = make_dev(&sndstat_cdevsw, 0, UID_ROOT, GID_WHEEL, 0644,
+ "sndstat");
}
SYSINIT(sndstat_sysinit, SI_SUB_DRIVERS, SI_ORDER_FIRST, sndstat_sysinit, NULL);
diff --git a/sys/dev/sound/pcm/sound.h b/sys/dev/sound/pcm/sound.h
index 315452e294d1..6bd435d0ea25 100644
--- a/sys/dev/sound/pcm/sound.h
+++ b/sys/dev/sound/pcm/sound.h
@@ -148,14 +148,6 @@ struct snd_mixer;
#define RANGE(var, low, high) (var) = \
(((var)<(low))? (low) : ((var)>(high))? (high) : (var))
-enum {
- SND_DEV_CTL = 0, /* Control port /dev/mixer */
- SND_DEV_SEQ, /* Sequencer /dev/sequencer */
- SND_DEV_MIDIN, /* Raw midi access */
- SND_DEV_DSP, /* Digitized voice /dev/dsp */
- SND_DEV_STATUS, /* /dev/sndstat */
-};
-
#define DSP_DEFAULT_SPEED 8000
extern int snd_unit;
diff --git a/sys/fs/msdosfs/msdosfs_vnops.c b/sys/fs/msdosfs/msdosfs_vnops.c
index 120b97ba72d5..5db61c8951f6 100644
--- a/sys/fs/msdosfs/msdosfs_vnops.c
+++ b/sys/fs/msdosfs/msdosfs_vnops.c
@@ -1942,6 +1942,9 @@ msdosfs_pathconf(struct vop_pathconf_args *ap)
case _PC_NO_TRUNC:
*ap->a_retval = 0;
return (0);
+ case _PC_HAS_HIDDENSYSTEM:
+ *ap->a_retval = 1;
+ return (0);
default:
return (vop_stdpathconf(ap));
}
diff --git a/sys/fs/nfs/nfs_commonsubs.c b/sys/fs/nfs/nfs_commonsubs.c
index f46b0d282861..4c498e96a3c0 100644
--- a/sys/fs/nfs/nfs_commonsubs.c
+++ b/sys/fs/nfs/nfs_commonsubs.c
@@ -630,6 +630,10 @@ nfscl_fillsattr(struct nfsrv_descript *nd, struct vattr *vap,
NFSSETBIT_ATTRBIT(&attrbits, NFSATTRBIT_OWNERGROUP);
if ((flags & NFSSATTR_FULL) && vap->va_size != VNOVAL)
NFSSETBIT_ATTRBIT(&attrbits, NFSATTRBIT_SIZE);
+ if ((flags & NFSSATTR_FULL) && vap->va_flags != VNOVAL) {
+ NFSSETBIT_ATTRBIT(&attrbits, NFSATTRBIT_HIDDEN);
+ NFSSETBIT_ATTRBIT(&attrbits, NFSATTRBIT_SYSTEM);
+ }
if (vap->va_atime.tv_sec != VNOVAL)
NFSSETBIT_ATTRBIT(&attrbits, NFSATTRBIT_TIMEACCESSSET);
if (vap->va_mtime.tv_sec != VNOVAL)
@@ -1314,6 +1318,7 @@ nfsv4_loadattr(struct nfsrv_descript *nd, vnode_t vp,
u_int32_t freenum = 0, tuint;
u_int64_t uquad = 0, thyp, thyp2;
uint16_t tui16;
+ long has_pathconf;
#ifdef QUOTA
struct dqblk dqb;
uid_t savuid;
@@ -1421,6 +1426,16 @@ nfsv4_loadattr(struct nfsrv_descript *nd, vnode_t vp,
NFSCLRBIT_ATTRBIT(&checkattrbits, NFSATTRBIT_ACL);
NFSCLRBIT_ATTRBIT(&checkattrbits, NFSATTRBIT_ACLSUPPORT);
}
+ /* Some filesystems do not support uf_hidden */
+ if (vp == NULL || VOP_PATHCONF(vp,
+ _PC_HAS_HIDDENSYSTEM, &has_pathconf) != 0)
+ has_pathconf = 0;
+ if (has_pathconf == 0) {
+ NFSCLRBIT_ATTRBIT(&checkattrbits,
+ NFSATTRBIT_HIDDEN);
+ NFSCLRBIT_ATTRBIT(&checkattrbits,
+ NFSATTRBIT_SYSTEM);
+ }
if (!NFSEQUAL_ATTRBIT(&retattrbits, &checkattrbits)
|| retnotsup)
*retcmpp = NFSERR_NOTSAME;
@@ -1521,15 +1536,13 @@ nfsv4_loadattr(struct nfsrv_descript *nd, vnode_t vp,
NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
if (compare) {
if (!(*retcmpp)) {
- long has_named_attr;
-
if (vp == NULL || VOP_PATHCONF(vp,
- _PC_HAS_NAMEDATTR, &has_named_attr)
+ _PC_HAS_NAMEDATTR, &has_pathconf)
!= 0)
- has_named_attr = 0;
- if ((has_named_attr != 0 &&
+ has_pathconf = 0;
+ if ((has_pathconf != 0 &&
*tl != newnfs_true) ||
- (has_named_attr == 0 &&
+ (has_pathconf == 0 &&
*tl != newnfs_false))
*retcmpp = NFSERR_NOTSAME;
}
@@ -1792,9 +1805,17 @@ nfsv4_loadattr(struct nfsrv_descript *nd, vnode_t vp,
free(cp2, M_NFSSTRING);
break;
case NFSATTRBIT_HIDDEN:
- NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
- if (compare && !(*retcmpp))
- *retcmpp = NFSERR_ATTRNOTSUPP;
+ NFSM_DISSECT(tl, uint32_t *, NFSX_UNSIGNED);
+ if (compare) {
+ if (!(*retcmpp) && ((*tl == newnfs_true &&
+ (nap->na_flags & UF_HIDDEN) == 0) ||
+ (*tl == newnfs_false &&
+ (nap->na_flags & UF_HIDDEN) != 0)))
+ *retcmpp = NFSERR_NOTSAME;
+ } else if (nap != NULL) {
+ if (*tl == newnfs_true)
+ nap->na_flags |= UF_HIDDEN;
+ }
attrsum += NFSX_UNSIGNED;
break;
case NFSATTRBIT_HOMOGENEOUS:
@@ -2166,9 +2187,17 @@ nfsv4_loadattr(struct nfsrv_descript *nd, vnode_t vp,
attrsum += NFSX_HYPER;
break;
case NFSATTRBIT_SYSTEM:
- NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
- if (compare && !(*retcmpp))
- *retcmpp = NFSERR_ATTRNOTSUPP;
+ NFSM_DISSECT(tl, uint32_t *, NFSX_UNSIGNED);
+ if (compare) {
+ if (!(*retcmpp) && ((*tl == newnfs_true &&
+ (nap->na_flags & UF_SYSTEM) == 0) ||
+ (*tl == newnfs_false &&
+ (nap->na_flags & UF_SYSTEM) != 0)))
+ *retcmpp = NFSERR_NOTSAME;
+ } else if (nap != NULL) {
+ if (*tl == newnfs_true)
+ nap->na_flags |= UF_SYSTEM;
+ }
attrsum += NFSX_UNSIGNED;
break;
case NFSATTRBIT_TIMEACCESS:
@@ -2634,7 +2663,7 @@ nfsv4_fillattr(struct nfsrv_descript *nd, struct mount *mp, vnode_t vp,
size_t atsiz;
bool xattrsupp;
short irflag;
- long has_named_attr;
+ long has_pathconf;
#ifdef QUOTA
struct dqblk dqb;
uid_t savuid;
@@ -2751,6 +2780,14 @@ nfsv4_fillattr(struct nfsrv_descript *nd, struct mount *mp, vnode_t vp,
NFSCLRBIT_ATTRBIT(&attrbits,NFSATTRBIT_ACLSUPPORT);
NFSCLRBIT_ATTRBIT(&attrbits,NFSATTRBIT_ACL);
}
+ if (cred == NULL || p == NULL || vp == NULL ||
+ VOP_PATHCONF(vp, _PC_HAS_HIDDENSYSTEM,
+ &has_pathconf) != 0)
+ has_pathconf = 0;
+ if (has_pathconf == 0) {
+ NFSCLRBIT_ATTRBIT(&attrbits, NFSATTRBIT_HIDDEN);
+ NFSCLRBIT_ATTRBIT(&attrbits, NFSATTRBIT_SYSTEM);
+ }
retnum += nfsrv_putattrbit(nd, &attrbits);
break;
case NFSATTRBIT_TYPE:
@@ -2791,10 +2828,10 @@ nfsv4_fillattr(struct nfsrv_descript *nd, struct mount *mp, vnode_t vp,
break;
case NFSATTRBIT_NAMEDATTR:
NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED);
- if (VOP_PATHCONF(vp, _PC_HAS_NAMEDATTR, &has_named_attr)
- != 0)
- has_named_attr = 0;
- if (has_named_attr != 0)
+ if (VOP_PATHCONF(vp, _PC_HAS_NAMEDATTR,
+ &has_pathconf) != 0)
+ has_pathconf = 0;
+ if (has_pathconf != 0)
*tl = newnfs_true;
else
*tl = newnfs_false;
@@ -2899,6 +2936,14 @@ nfsv4_fillattr(struct nfsrv_descript *nd, struct mount *mp, vnode_t vp,
*tl = 0;
retnum += 2 * NFSX_UNSIGNED;
break;
+ case NFSATTRBIT_HIDDEN:
+ NFSM_BUILD(tl, uint32_t *, NFSX_UNSIGNED);
+ if ((vap->va_flags & UF_HIDDEN) != 0)
+ *tl = newnfs_true;
+ else
+ *tl = newnfs_false;
+ retnum += NFSX_UNSIGNED;
+ break;
case NFSATTRBIT_HOMOGENEOUS:
NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED);
if (fsinf.fs_properties & NFSV3FSINFO_HOMOGENEOUS)
@@ -3088,6 +3133,14 @@ nfsv4_fillattr(struct nfsrv_descript *nd, struct mount *mp, vnode_t vp,
txdr_hyper(vap->va_bytes, tl);
retnum += NFSX_HYPER;
break;
+ case NFSATTRBIT_SYSTEM:
+ NFSM_BUILD(tl, uint32_t *, NFSX_UNSIGNED);
+ if ((vap->va_flags & UF_SYSTEM) != 0)
+ *tl = newnfs_true;
+ else
+ *tl = newnfs_false;
+ retnum += NFSX_UNSIGNED;
+ break;
case NFSATTRBIT_TIMEACCESS:
NFSM_BUILD(tl, u_int32_t *, NFSX_V4TIME);
txdr_nfsv4time(&vap->va_atime, tl);
diff --git a/sys/fs/nfs/nfsproto.h b/sys/fs/nfs/nfsproto.h
index eff53e1a384e..cb5a80e8df73 100644
--- a/sys/fs/nfs/nfsproto.h
+++ b/sys/fs/nfs/nfsproto.h
@@ -1142,6 +1142,7 @@ struct nfsv3_sattr {
NFSATTRBM_FILESFREE | \
NFSATTRBM_FILESTOTAL | \
NFSATTRBM_FSLOCATIONS | \
+ NFSATTRBM_HIDDEN | \
NFSATTRBM_HOMOGENEOUS | \
NFSATTRBM_MAXFILESIZE | \
NFSATTRBM_MAXLINK | \
@@ -1163,6 +1164,7 @@ struct nfsv3_sattr {
NFSATTRBM_SPACEFREE | \
NFSATTRBM_SPACETOTAL | \
NFSATTRBM_SPACEUSED | \
+ NFSATTRBM_SYSTEM | \
NFSATTRBM_TIMEACCESS | \
NFSATTRBM_TIMECREATE | \
NFSATTRBM_TIMEDELTA | \
@@ -1210,11 +1212,13 @@ struct nfsv3_sattr {
*/
#define NFSATTRBIT_SETABLE0 \
(NFSATTRBM_SIZE | \
+ NFSATTRBM_HIDDEN | \
NFSATTRBM_ACL)
#define NFSATTRBIT_SETABLE1 \
(NFSATTRBM_MODE | \
NFSATTRBM_OWNER | \
NFSATTRBM_OWNERGROUP | \
+ NFSATTRBM_SYSTEM | \
NFSATTRBM_TIMECREATE | \
NFSATTRBM_TIMEACCESSSET | \
NFSATTRBM_TIMEMODIFYSET)
@@ -1254,6 +1258,7 @@ struct nfsv3_sattr {
NFSATTRBM_SIZE | \
NFSATTRBM_FSID | \
NFSATTRBM_FILEID | \
+ NFSATTRBM_HIDDEN | \
NFSATTRBM_MAXREAD)
/*
@@ -1266,6 +1271,7 @@ struct nfsv3_sattr {
NFSATTRBM_OWNERGROUP | \
NFSATTRBM_RAWDEV | \
NFSATTRBM_SPACEUSED | \
+ NFSATTRBM_SYSTEM | \
NFSATTRBM_TIMEACCESS | \
NFSATTRBM_TIMECREATE | \
NFSATTRBM_TIMEMETADATA | \
@@ -1288,6 +1294,7 @@ struct nfsv3_sattr {
NFSATTRBM_SIZE | \
NFSATTRBM_FSID | \
NFSATTRBM_FILEID | \
+ NFSATTRBM_HIDDEN | \
NFSATTRBM_MAXREAD)
/*
@@ -1298,6 +1305,7 @@ struct nfsv3_sattr {
NFSATTRBM_NUMLINKS | \
NFSATTRBM_RAWDEV | \
NFSATTRBM_SPACEUSED | \
+ NFSATTRBM_SYSTEM | \
NFSATTRBM_TIMEACCESS | \
NFSATTRBM_TIMECREATE | \
NFSATTRBM_TIMEMETADATA | \
diff --git a/sys/fs/nfsclient/nfs_clrpcops.c b/sys/fs/nfsclient/nfs_clrpcops.c
index c07da6f9275f..e0e66baca44d 100644
--- a/sys/fs/nfsclient/nfs_clrpcops.c
+++ b/sys/fs/nfsclient/nfs_clrpcops.c
@@ -4158,6 +4158,13 @@ nfsrpc_readdirplus(vnode_t vp, struct uio *uiop, nfsuint64 *cookiep,
if (!NFSISSET_ATTRBIT(&dnp->n_vattr.na_suppattr,
NFSATTRBIT_TIMECREATE))
NFSCLRBIT_ATTRBIT(&attrbits, NFSATTRBIT_TIMECREATE);
+ if (!NFSISSET_ATTRBIT(&dnp->n_vattr.na_suppattr,
+ NFSATTRBIT_HIDDEN) ||
+ !NFSISSET_ATTRBIT(&dnp->n_vattr.na_suppattr,
+ NFSATTRBIT_SYSTEM)) {
+ NFSCLRBIT_ATTRBIT(&attrbits, NFSATTRBIT_HIDDEN);
+ NFSCLRBIT_ATTRBIT(&attrbits, NFSATTRBIT_SYSTEM);
+ }
}
/*
diff --git a/sys/fs/nfsclient/nfs_clvnops.c b/sys/fs/nfsclient/nfs_clvnops.c
index 0049d7edca33..fa451887e73e 100644
--- a/sys/fs/nfsclient/nfs_clvnops.c
+++ b/sys/fs/nfsclient/nfs_clvnops.c
@@ -1074,21 +1074,29 @@ nfs_setattr(struct vop_setattr_args *ap)
int error = 0;
u_quad_t tsize;
struct timespec ts;
+ struct nfsmount *nmp;
#ifndef nolint
tsize = (u_quad_t)0;
#endif
/*
- * Setting of flags and marking of atimes are not supported.
+ * Only setting of UF_HIDDEN and UF_SYSTEM are supported and
+ * only for NFSv4 servers that support them.
*/
- if (vap->va_flags != VNOVAL)
+ nmp = VFSTONFS(vp->v_mount);
+ if (vap->va_flags != VNOVAL && (!NFSHASNFSV4(nmp) ||
+ (vap->va_flags & ~(UF_HIDDEN | UF_SYSTEM)) != 0 ||
+ ((vap->va_flags & UF_HIDDEN) != 0 &&
+ !NFSISSET_ATTRBIT(&np->n_vattr.na_suppattr, NFSATTRBIT_HIDDEN)) ||
+ ((vap->va_flags & UF_SYSTEM) != 0 &&
+ !NFSISSET_ATTRBIT(&np->n_vattr.na_suppattr, NFSATTRBIT_SYSTEM))))
return (EOPNOTSUPP);
/*
* Disallow write attempts if the filesystem is mounted read-only.
*/
- if ((vap->va_flags != VNOVAL || vap->va_uid != (uid_t)VNOVAL ||
+ if ((vap->va_flags != (u_long)VNOVAL || vap->va_uid != (uid_t)VNOVAL ||
vap->va_gid != (gid_t)VNOVAL || vap->va_atime.tv_sec != VNOVAL ||
vap->va_mtime.tv_sec != VNOVAL ||
vap->va_birthtime.tv_sec != VNOVAL ||
@@ -4754,6 +4762,15 @@ nfs_pathconf(struct vop_pathconf_args *ap)
else
*ap->a_retval = 0;
break;
+ case _PC_HAS_HIDDENSYSTEM:
+ if (NFS_ISV4(vp) && NFSISSET_ATTRBIT(&np->n_vattr.na_suppattr,
+ NFSATTRBIT_HIDDEN) &&
+ NFSISSET_ATTRBIT(&np->n_vattr.na_suppattr,
+ NFSATTRBIT_SYSTEM))
+ *ap->a_retval = 1;
+ else
+ *ap->a_retval = 0;
+ break;
default:
error = vop_stdpathconf(ap);
diff --git a/sys/fs/nfsserver/nfs_nfsdport.c b/sys/fs/nfsserver/nfs_nfsdport.c
index 3bf54d82b959..43ee0383669f 100644
--- a/sys/fs/nfsserver/nfs_nfsdport.c
+++ b/sys/fs/nfsserver/nfs_nfsdport.c
@@ -449,6 +449,7 @@ nfsvno_getattr(struct vnode *vp, struct nfsvattr *nvap,
}
nvap->na_bsdflags = 0;
+ nvap->na_flags = 0;
error = VOP_GETATTR(vp, &nvap->na_vattr, nd->nd_cred);
if (lockedit != 0)
NFSVOPUNLOCK(vp);
@@ -1651,10 +1652,11 @@ nfsvno_rename(struct nameidata *fromndp, struct nameidata *tondp,
}
if (fvp == tvp) {
/*
- * If source and destination are the same, there is nothing to
- * do. Set error to -1 to indicate this.
+ * If source and destination are the same, there is
+ * nothing to do. Set error to EJUSTRETURN to indicate
+ * this.
*/
- error = -1;
+ error = EJUSTRETURN;
goto out;
}
if (nd->nd_flag & ND_NFSV4) {
@@ -1696,10 +1698,26 @@ nfsvno_rename(struct nameidata *fromndp, struct nameidata *tondp,
" dsdvp=%p\n", dsdvp[0]);
}
out:
- if (!error) {
+ mp = NULL;
+ if (error == 0) {
+ error = VOP_GETWRITEMOUNT(tondp->ni_dvp, &mp);
+ if (error == 0) {
+ if (mp == NULL) {
+ error = ENOENT;
+ } else {
+ error = lockmgr(&mp->mnt_renamelock,
+ LK_EXCLUSIVE | LK_NOWAIT, NULL);
+ if (error != 0)
+ error = ERELOOKUP;
+ }
+ }
+ }
+ if (error == 0) {
error = VOP_RENAME(fromndp->ni_dvp, fromndp->ni_vp,
&fromndp->ni_cnd, tondp->ni_dvp, tondp->ni_vp,
&tondp->ni_cnd);
+ lockmgr(&mp->mnt_renamelock, LK_RELEASE, 0);
+ vfs_rel(mp);
} else {
if (tdvp == tvp)
vrele(tdvp);
@@ -1709,8 +1727,13 @@ out:
vput(tvp);
vrele(fromndp->ni_dvp);
vrele(fvp);
- if (error == -1)
+ if (error == EJUSTRETURN) {
error = 0;
+ } else if (error == ERELOOKUP && mp != NULL) {
+ lockmgr(&mp->mnt_renamelock, LK_EXCLUSIVE, 0);
+ lockmgr(&mp->mnt_renamelock, LK_RELEASE, 0);
+ vfs_rel(mp);
+ }
}
/*
@@ -3127,6 +3150,9 @@ nfsv4_sattr(struct nfsrv_descript *nd, vnode_t vp, struct nfsvattr *nvap,
bitpos = NFSATTRBIT_MAX;
} else {
bitpos = 0;
+ if (NFSISSET_ATTRBIT(attrbitp, NFSATTRBIT_HIDDEN) ||
+ NFSISSET_ATTRBIT(attrbitp, NFSATTRBIT_SYSTEM))
+ nvap->na_flags = 0;
}
moderet = 0;
for (; bitpos < NFSATTRBIT_MAX; bitpos++) {
@@ -3163,9 +3189,11 @@ nfsv4_sattr(struct nfsrv_descript *nd, vnode_t vp, struct nfsvattr *nvap,
attrsum += NFSX_UNSIGNED;
break;
case NFSATTRBIT_HIDDEN:
- NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
- if (!nd->nd_repstat)
- nd->nd_repstat = NFSERR_ATTRNOTSUPP;
+ NFSM_DISSECT(tl, uint32_t *, NFSX_UNSIGNED);
+ if (nd->nd_repstat == 0) {
+ if (*tl == newnfs_true)
+ nvap->na_flags |= UF_HIDDEN;
+ }
attrsum += NFSX_UNSIGNED;
break;
case NFSATTRBIT_MIMETYPE:
@@ -3240,9 +3268,11 @@ nfsv4_sattr(struct nfsrv_descript *nd, vnode_t vp, struct nfsvattr *nvap,
attrsum += (NFSX_UNSIGNED + NFSM_RNDUP(j));
break;
case NFSATTRBIT_SYSTEM:
- NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED);
- if (!nd->nd_repstat)
- nd->nd_repstat = NFSERR_ATTRNOTSUPP;
+ NFSM_DISSECT(tl, uint32_t *, NFSX_UNSIGNED);
+ if (nd->nd_repstat == 0) {
+ if (*tl == newnfs_true)
+ nvap->na_flags |= UF_SYSTEM;
+ }
attrsum += NFSX_UNSIGNED;
break;
case NFSATTRBIT_TIMEACCESSSET:
diff --git a/sys/fs/nfsserver/nfs_nfsdserv.c b/sys/fs/nfsserver/nfs_nfsdserv.c
index 4e15d55eb312..f7564ade401b 100644
--- a/sys/fs/nfsserver/nfs_nfsdserv.c
+++ b/sys/fs/nfsserver/nfs_nfsdserv.c
@@ -403,8 +403,10 @@ nfsrvd_setattr(struct nfsrv_descript *nd, __unused int isdgram,
if (error)
goto nfsmout;
- /* For NFSv4, only va_uid is used from nva2. */
+ /* For NFSv4, only va_uid and va_flags is used from nva2. */
NFSSETBIT_ATTRBIT(&retbits, NFSATTRBIT_OWNER);
+ NFSSETBIT_ATTRBIT(&retbits, NFSATTRBIT_HIDDEN);
+ NFSSETBIT_ATTRBIT(&retbits, NFSATTRBIT_SYSTEM);
preat_ret = nfsvno_getattr(vp, &nva2, nd, p, 1, &retbits);
if (!nd->nd_repstat)
nd->nd_repstat = preat_ret;
@@ -463,6 +465,9 @@ nfsrvd_setattr(struct nfsrv_descript *nd, __unused int isdgram,
&nva, &attrbits, exp, p);
if (!nd->nd_repstat && (nd->nd_flag & ND_NFSV4)) {
+ u_long oldflags;
+
+ oldflags = nva2.na_flags;
/*
* For V4, try setting the attributes in sets, so that the
* reply bitmap will be correct for an error case.
@@ -532,6 +537,32 @@ nfsrvd_setattr(struct nfsrv_descript *nd, __unused int isdgram,
NFSSETBIT_ATTRBIT(&retbits, NFSATTRBIT_MODESETMASKED);
}
}
+ if (!nd->nd_repstat &&
+ (NFSISSET_ATTRBIT(&attrbits, NFSATTRBIT_HIDDEN) ||
+ NFSISSET_ATTRBIT(&attrbits, NFSATTRBIT_SYSTEM))) {
+ if (NFSISSET_ATTRBIT(&attrbits, NFSATTRBIT_HIDDEN)) {
+ if ((nva.na_flags & UF_HIDDEN) != 0)
+ oldflags |= UF_HIDDEN;
+ else
+ oldflags &= ~UF_HIDDEN;
+ }
+ if (NFSISSET_ATTRBIT(&attrbits, NFSATTRBIT_SYSTEM)) {
+ if ((nva.na_flags & UF_SYSTEM) != 0)
+ oldflags |= UF_SYSTEM;
+ else
+ oldflags &= ~UF_SYSTEM;
+ }
+ NFSVNO_ATTRINIT(&nva2);
+ NFSVNO_SETATTRVAL(&nva2, flags, oldflags);
+ nd->nd_repstat = nfsvno_setattr(vp, &nva2, nd->nd_cred, p,
+ exp);
+ if (!nd->nd_repstat) {
+ if (NFSISSET_ATTRBIT(&attrbits, NFSATTRBIT_HIDDEN))
+ NFSSETBIT_ATTRBIT(&retbits, NFSATTRBIT_HIDDEN);
+ if (NFSISSET_ATTRBIT(&attrbits, NFSATTRBIT_SYSTEM))
+ NFSSETBIT_ATTRBIT(&retbits, NFSATTRBIT_SYSTEM);
+ }
+ }
#ifdef NFS4_ACL_EXTATTR_NAME
if (!nd->nd_repstat && aclp->acl_cnt > 0 &&
diff --git a/sys/fs/smbfs/smbfs_vnops.c b/sys/fs/smbfs/smbfs_vnops.c
index c30995508c00..5d412cabadb8 100644
--- a/sys/fs/smbfs/smbfs_vnops.c
+++ b/sys/fs/smbfs/smbfs_vnops.c
@@ -810,6 +810,9 @@ smbfs_pathconf(struct vop_pathconf_args *ap)
case _PC_NO_TRUNC:
*retval = 1;
break;
+ case _PC_HAS_HIDDENSYSTEM:
+ *retval = 1;
+ break;
default:
error = vop_stdpathconf(ap);
}
diff --git a/sys/fs/tmpfs/tmpfs_vnops.c b/sys/fs/tmpfs/tmpfs_vnops.c
index c99d0732be50..9d2a587b177a 100644
--- a/sys/fs/tmpfs/tmpfs_vnops.c
+++ b/sys/fs/tmpfs/tmpfs_vnops.c
@@ -1691,6 +1691,10 @@ tmpfs_pathconf(struct vop_pathconf_args *v)
*retval = PAGE_SIZE;
break;
+ case _PC_HAS_HIDDENSYSTEM:
+ *retval = 1;
+ break;
+
default:
error = vop_stdpathconf(v);
}
diff --git a/sys/kern/init_sysent.c b/sys/kern/init_sysent.c
index 34e71a0665ed..91792430d24c 100644
--- a/sys/kern/init_sysent.c
+++ b/sys/kern/init_sysent.c
@@ -658,7 +658,7 @@ struct sysent sysent[] = {
{ .sy_narg = AS(getrlimitusage_args), .sy_call = (sy_call_t *)sys_getrlimitusage, .sy_auevent = AUE_NULL, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 589 = getrlimitusage */
{ .sy_narg = AS(fchroot_args), .sy_call = (sy_call_t *)sys_fchroot, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 590 = fchroot */
{ .sy_narg = AS(setcred_args), .sy_call = (sy_call_t *)sys_setcred, .sy_auevent = AUE_SETCRED, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 591 = setcred */
- { .sy_narg = AS(exterrctl_args), .sy_call = (sy_call_t *)sys_exterrctl, .sy_auevent = AUE_NULL, .sy_flags = 0, .sy_thrcnt = SY_THR_STATIC }, /* 592 = exterrctl */
+ { .sy_narg = AS(exterrctl_args), .sy_call = (sy_call_t *)sys_exterrctl, .sy_auevent = AUE_NULL, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 592 = exterrctl */
{ .sy_narg = AS(inotify_add_watch_at_args), .sy_call = (sy_call_t *)sys_inotify_add_watch_at, .sy_auevent = AUE_INOTIFY, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 593 = inotify_add_watch_at */
{ .sy_narg = AS(inotify_rm_watch_args), .sy_call = (sy_call_t *)sys_inotify_rm_watch, .sy_auevent = AUE_INOTIFY, .sy_flags = SYF_CAPENABLED, .sy_thrcnt = SY_THR_STATIC }, /* 594 = inotify_rm_watch */
};
diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c
index ac4b6ac3f457..93bdd41d1515 100644
--- a/sys/kern/kern_descrip.c
+++ b/sys/kern/kern_descrip.c
@@ -38,9 +38,11 @@
#include "opt_ddb.h"
#include "opt_ktrace.h"
+#define EXTERR_CATEGORY EXTERR_CAT_FILEDESC
#include <sys/systm.h>
#include <sys/capsicum.h>
#include <sys/conf.h>
+#include <sys/exterrvar.h>
#include <sys/fcntl.h>
#include <sys/file.h>
#include <sys/filedesc.h>
@@ -478,6 +480,90 @@ kern_fcntl_freebsd(struct thread *td, int fd, int cmd, intptr_t arg)
return (error);
}
+struct flags_trans_elem {
+ u_int f;
+ u_int t;
+};
+
+static u_int
+flags_trans(const struct flags_trans_elem *ftes, int nitems, u_int from_flags)
+{
+ u_int res;
+ int i;
+
+ res = 0;
+ for (i = 0; i < nitems; i++) {
+ if ((from_flags & ftes[i].f) != 0)
+ res |= ftes[i].t;
+ }
+ return (res);
+}
+
+static uint8_t
+fd_to_fde_flags(int fd_flags)
+{
+ static const struct flags_trans_elem fd_to_fde_flags_s[] = {
+ { .f = FD_CLOEXEC, .t = UF_EXCLOSE },
+ { .f = FD_CLOFORK, .t = UF_FOCLOSE },
+ { .f = FD_RESOLVE_BENEATH, .t = UF_RESOLVE_BENEATH },
+ };
+
+ return (flags_trans(fd_to_fde_flags_s, nitems(fd_to_fde_flags_s),
+ fd_flags));
+}
+
+static int
+fde_to_fd_flags(uint8_t fde_flags)
+{
+ static const struct flags_trans_elem fde_to_fd_flags_s[] = {
+ { .f = UF_EXCLOSE, .t = FD_CLOEXEC },
+ { .f = UF_FOCLOSE, .t = FD_CLOFORK },
+ { .f = UF_RESOLVE_BENEATH, .t = FD_RESOLVE_BENEATH },
+ };
+
+ return (flags_trans(fde_to_fd_flags_s, nitems(fde_to_fd_flags_s),
+ fde_flags));
+}
+
+static uint8_t
+fddup_to_fde_flags(int fddup_flags)
+{
+ static const struct flags_trans_elem fddup_to_fde_flags_s[] = {
+ { .f = FDDUP_FLAG_CLOEXEC, .t = UF_EXCLOSE },
+ { .f = FDDUP_FLAG_CLOFORK, .t = UF_FOCLOSE },
+ };
+
+ return (flags_trans(fddup_to_fde_flags_s, nitems(fddup_to_fde_flags_s),
+ fddup_flags));
+}
+
+static uint8_t
+close_range_to_fde_flags(int close_range_flags)
+{
+ static const struct flags_trans_elem close_range_to_fde_flags_s[] = {
+ { .f = CLOSE_RANGE_CLOEXEC, .t = UF_EXCLOSE },
+ { .f = CLOSE_RANGE_CLOFORK, .t = UF_FOCLOSE },
+ };
+
+ return (flags_trans(close_range_to_fde_flags_s,
+ nitems(close_range_to_fde_flags_s), close_range_flags));
+}
+
+static uint8_t
+open_to_fde_flags(int open_flags, bool sticky_orb)
+{
+ static const struct flags_trans_elem open_to_fde_flags_s[] = {
+ { .f = O_CLOEXEC, .t = UF_EXCLOSE },
+ { .f = O_CLOFORK, .t = UF_FOCLOSE },
+ { .f = O_RESOLVE_BENEATH, .t = UF_RESOLVE_BENEATH },
+ };
+ _Static_assert(open_to_fde_flags_s[nitems(open_to_fde_flags_s) - 1].f ==
+ O_RESOLVE_BENEATH, "O_RESOLVE_BENEATH must be last, for sticky_orb");
+
+ return (flags_trans(open_to_fde_flags_s, nitems(open_to_fde_flags_s) -
+ (sticky_orb ? 0 : 1), open_flags));
+}
+
int
kern_fcntl(struct thread *td, int fd, int cmd, intptr_t arg)
{
@@ -492,6 +578,7 @@ kern_fcntl(struct thread *td, int fd, int cmd, intptr_t arg)
int error, flg, kif_sz, seals, tmp, got_set, got_cleared;
uint64_t bsize;
off_t foffset;
+ int flags;
error = 0;
flg = F_POSIX;
@@ -511,6 +598,11 @@ kern_fcntl(struct thread *td, int fd, int cmd, intptr_t arg)
error = kern_dup(td, FDDUP_FCNTL, FDDUP_FLAG_CLOEXEC, fd, tmp);
break;
+ case F_DUPFD_CLOFORK:
+ tmp = arg;
+ error = kern_dup(td, FDDUP_FCNTL, FDDUP_FLAG_CLOFORK, fd, tmp);
+ break;
+
case F_DUP2FD:
tmp = arg;
error = kern_dup(td, FDDUP_FIXED, 0, fd, tmp);
@@ -526,10 +618,7 @@ kern_fcntl(struct thread *td, int fd, int cmd, intptr_t arg)
FILEDESC_SLOCK(fdp);
fde = fdeget_noref(fdp, fd);
if (fde != NULL) {
- td->td_retval[0] =
- ((fde->fde_flags & UF_EXCLOSE) ? FD_CLOEXEC : 0) |
- ((fde->fde_flags & UF_RESOLVE_BENEATH) ?
- FD_RESOLVE_BENEATH : 0);
+ td->td_retval[0] = fde_to_fd_flags(fde->fde_flags);
error = 0;
}
FILEDESC_SUNLOCK(fdp);
@@ -543,10 +632,8 @@ kern_fcntl(struct thread *td, int fd, int cmd, intptr_t arg)
/*
* UF_RESOLVE_BENEATH is sticky and cannot be cleared.
*/
- fde->fde_flags = (fde->fde_flags & ~UF_EXCLOSE) |
- ((arg & FD_CLOEXEC) != 0 ? UF_EXCLOSE : 0) |
- ((arg & FD_RESOLVE_BENEATH) != 0 ?
- UF_RESOLVE_BENEATH : 0);
+ fde->fde_flags = (fde->fde_flags &
+ ~(UF_EXCLOSE | UF_FOCLOSE)) | fd_to_fde_flags(arg);
error = 0;
}
FILEDESC_XUNLOCK(fdp);
@@ -916,7 +1003,17 @@ revert_f_setfl:
break;
default:
- error = EINVAL;
+ if ((cmd & ((1u << F_DUP3FD_SHIFT) - 1)) != F_DUP3FD)
+ return (EXTERROR(EINVAL, "invalid fcntl cmd"));
+ /* Handle F_DUP3FD */
+ flags = (cmd >> F_DUP3FD_SHIFT);
+ if ((flags & ~(FD_CLOEXEC | FD_CLOFORK)) != 0)
+ return (EXTERROR(EINVAL, "invalid flags for F_DUP3FD"));
+ tmp = arg;
+ error = kern_dup(td, FDDUP_FIXED,
+ ((flags & FD_CLOEXEC) != 0 ? FDDUP_FLAG_CLOEXEC : 0) |
+ ((flags & FD_CLOFORK) != 0 ? FDDUP_FLAG_CLOFORK : 0),
+ fd, tmp);
break;
}
return (error);
@@ -946,7 +1043,7 @@ kern_dup(struct thread *td, u_int mode, int flags, int old, int new)
fdp = p->p_fd;
oioctls = NULL;
- MPASS((flags & ~(FDDUP_FLAG_CLOEXEC)) == 0);
+ MPASS((flags & ~(FDDUP_FLAG_CLOEXEC | FDDUP_FLAG_CLOFORK)) == 0);
MPASS(mode < FDDUP_LASTMODE);
AUDIT_ARG_FD(old);
@@ -971,8 +1068,7 @@ kern_dup(struct thread *td, u_int mode, int flags, int old, int new)
goto unlock;
if (mode == FDDUP_FIXED && old == new) {
td->td_retval[0] = new;
- if (flags & FDDUP_FLAG_CLOEXEC)
- fdp->fd_ofiles[new].fde_flags |= UF_EXCLOSE;
+ fdp->fd_ofiles[new].fde_flags |= fddup_to_fde_flags(flags);
error = 0;
goto unlock;
}
@@ -1047,10 +1143,8 @@ kern_dup(struct thread *td, u_int mode, int flags, int old, int new)
fde_copy(oldfde, newfde);
filecaps_copy_finish(&oldfde->fde_caps, &newfde->fde_caps,
nioctls);
- if ((flags & FDDUP_FLAG_CLOEXEC) != 0)
- newfde->fde_flags = oldfde->fde_flags | UF_EXCLOSE;
- else
- newfde->fde_flags = oldfde->fde_flags & ~UF_EXCLOSE;
+ newfde->fde_flags = (oldfde->fde_flags & ~(UF_EXCLOSE | UF_FOCLOSE)) |
+ fddup_to_fde_flags(flags);
#ifdef CAPABILITIES
seqc_write_end(&newfde->fde_seqc);
#endif
@@ -1416,13 +1510,14 @@ kern_close(struct thread *td, int fd)
}
static int
-close_range_cloexec(struct thread *td, u_int lowfd, u_int highfd)
+close_range_flags(struct thread *td, u_int lowfd, u_int highfd, int flags)
{
struct filedesc *fdp;
struct fdescenttbl *fdt;
struct filedescent *fde;
- int fd;
+ int fd, fde_flags;
+ fde_flags = close_range_to_fde_flags(flags);
fdp = td->td_proc->p_fd;
FILEDESC_XLOCK(fdp);
fdt = atomic_load_ptr(&fdp->fd_files);
@@ -1434,7 +1529,7 @@ close_range_cloexec(struct thread *td, u_int lowfd, u_int highfd)
for (; fd <= highfd; fd++) {
fde = &fdt->fdt_ofiles[fd];
if (fde->fde_file != NULL)
- fde->fde_flags |= UF_EXCLOSE;
+ fde->fde_flags |= fde_flags;
}
out_locked:
FILEDESC_XUNLOCK(fdp);
@@ -1492,8 +1587,8 @@ kern_close_range(struct thread *td, int flags, u_int lowfd, u_int highfd)
return (EINVAL);
}
- if ((flags & CLOSE_RANGE_CLOEXEC) != 0)
- return (close_range_cloexec(td, lowfd, highfd));
+ if ((flags & (CLOSE_RANGE_CLOEXEC | CLOSE_RANGE_CLOFORK)) != 0)
+ return (close_range_flags(td, lowfd, highfd, flags));
return (close_range_impl(td, lowfd, highfd));
}
@@ -1513,7 +1608,7 @@ sys_close_range(struct thread *td, struct close_range_args *uap)
AUDIT_ARG_CMD(uap->highfd);
AUDIT_ARG_FFLAGS(uap->flags);
- if ((uap->flags & ~(CLOSE_RANGE_CLOEXEC)) != 0)
+ if ((uap->flags & ~(CLOSE_RANGE_CLOEXEC | CLOSE_RANGE_CLOFORK)) != 0)
return (EINVAL);
return (kern_close_range(td, uap->flags, uap->lowfd, uap->highfd));
}
@@ -2171,8 +2266,7 @@ _finstall(struct filedesc *fdp, struct file *fp, int fd, int flags,
seqc_write_begin(&fde->fde_seqc);
#endif
fde->fde_file = fp;
- fde->fde_flags = ((flags & O_CLOEXEC) != 0 ? UF_EXCLOSE : 0) |
- ((flags & O_RESOLVE_BENEATH) != 0 ? UF_RESOLVE_BENEATH : 0);
+ fde->fde_flags = open_to_fde_flags(flags, true);
if (fcaps != NULL)
filecaps_move(fcaps, &fde->fde_caps);
else
@@ -2432,6 +2526,7 @@ fdcopy(struct filedesc *fdp)
newfdp->fd_freefile = fdp->fd_freefile;
FILEDESC_FOREACH_FDE(fdp, i, ofde) {
if ((ofde->fde_file->f_ops->fo_flags & DFLAG_PASSABLE) == 0 ||
+ (ofde->fde_flags & UF_FOCLOSE) != 0 ||
!fhold(ofde->fde_file)) {
if (newfdp->fd_freefile == fdp->fd_freefile)
newfdp->fd_freefile = i;
@@ -2729,6 +2824,12 @@ fdcloseexec(struct thread *td)
fdfree(fdp, i);
(void) closefp(fdp, i, fp, td, false, false);
FILEDESC_UNLOCK_ASSERT(fdp);
+ } else if (fde->fde_flags & UF_FOCLOSE) {
+ /*
+ * https://austingroupbugs.net/view.php?id=1851
+ * FD_CLOFORK should not be preserved across exec
+ */
+ fde->fde_flags &= ~UF_FOCLOSE;
}
}
}
diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c
index 4565abc4b540..5d51aa675cb7 100644
--- a/sys/kern/kern_sig.c
+++ b/sys/kern/kern_sig.c
@@ -1050,8 +1050,7 @@ osigaction(struct thread *td, struct osigaction_args *uap)
int
osigreturn(struct thread *td, struct osigreturn_args *uap)
{
-
- return (nosys(td, (struct nosys_args *)uap));
+ return (kern_nosys(td, 0));
}
#endif
#endif /* COMPAT_43 */
@@ -4139,7 +4138,7 @@ coredump(struct thread *td)
struct flock lf;
struct vattr vattr;
size_t fullpathsize;
- int error, error1, locked;
+ int error, error1, jid, locked, ppid, sig;
char *name; /* name of corefile */
void *rl_cookie;
off_t limit;
@@ -4168,6 +4167,10 @@ coredump(struct thread *td)
PROC_UNLOCK(p);
return (EFBIG);
}
+
+ ppid = p->p_oppid;
+ sig = p->p_sig;
+ jid = p->p_ucred->cr_prison->pr_id;
PROC_UNLOCK(p);
error = corefile_open(p->p_comm, cred->cr_uid, p->p_pid, td,
@@ -4253,6 +4256,9 @@ coredump(struct thread *td)
}
devctl_safe_quote_sb(sb, name);
sbuf_putc(sb, '"');
+
+ sbuf_printf(sb, " jid=%d pid=%d ppid=%d signo=%d",
+ jid, p->p_pid, ppid, sig);
if (sbuf_finish(sb) == 0)
devctl_notify("kernel", "signal", "coredump", sbuf_data(sb));
out2:
@@ -4281,6 +4287,12 @@ struct nosys_args {
int
nosys(struct thread *td, struct nosys_args *args)
{
+ return (kern_nosys(td, args->dummy));
+}
+
+int
+kern_nosys(struct thread *td, int dummy)
+{
struct proc *p;
p = td->td_proc;
diff --git a/sys/kern/kern_syscalls.c b/sys/kern/kern_syscalls.c
index 24406763a93a..a93d711e7597 100644
--- a/sys/kern/kern_syscalls.c
+++ b/sys/kern/kern_syscalls.c
@@ -35,6 +35,7 @@
#include <sys/resourcevar.h>
#include <sys/sx.h>
#include <sys/syscall.h>
+#include <sys/syscallsubr.h>
#include <sys/sysent.h>
#include <sys/sysproto.h>
#include <sys/systm.h>
@@ -50,14 +51,14 @@ int
lkmnosys(struct thread *td, struct nosys_args *args)
{
- return (nosys(td, args));
+ return (kern_nosys(td, 0));
}
int
lkmressys(struct thread *td, struct nosys_args *args)
{
- return (nosys(td, args));
+ return (kern_nosys(td, 0));
}
struct sysent nosys_sysent = {
diff --git a/sys/kern/subr_pctrie.c b/sys/kern/subr_pctrie.c
index 3a3548bad52b..bb86c779b936 100644
--- a/sys/kern/subr_pctrie.c
+++ b/sys/kern/subr_pctrie.c
@@ -691,21 +691,23 @@ _pctrie_lookup_ge(struct pctrie *ptree, struct pctrie_node *node,
*/
if (node == PCTRIE_NULL || *pctrie_toval(node) < index) {
/* Climb the path to find a node with a descendant > index. */
- for (node = parent; node != NULL; node = pctrie_parent(node)) {
- slot = pctrie_slot(node, index) + 1;
- if ((node->pn_popmap >> slot) != 0)
+ node = NULL;
+ while (parent != NULL) {
+ slot = pctrie_slot(parent, index) + 1;
+ if ((parent->pn_popmap >> slot) != 0)
break;
+ node = parent;
+ parent = pctrie_parent(node);
}
- if (node == NULL) {
+ if (parent == NULL) {
if (parent_out != NULL)
- *parent_out = NULL;
+ *parent_out = node;
return (NULL);
}
/* Step to the least child with a descendant > index. */
- slot += ffs(node->pn_popmap >> slot) - 1;
- parent = node;
- node = pctrie_node_load(&node->pn_child[slot], NULL,
+ slot += ffs(parent->pn_popmap >> slot) - 1;
+ node = pctrie_node_load(&parent->pn_child[slot], NULL,
PCTRIE_LOCKED);
}
/* Descend to the least leaf of the subtrie. */
@@ -785,21 +787,23 @@ _pctrie_lookup_le(struct pctrie *ptree, struct pctrie_node *node,
*/
if (node == PCTRIE_NULL || *pctrie_toval(node) > index) {
/* Climb the path to find a node with a descendant < index. */
- for (node = parent; node != NULL; node = pctrie_parent(node)) {
- slot = pctrie_slot(node, index);
- if ((node->pn_popmap & ((1 << slot) - 1)) != 0)
+ node = NULL;
+ while (parent != NULL) {
+ slot = pctrie_slot(parent, index);
+ if ((parent->pn_popmap & ((1 << slot) - 1)) != 0)
break;
+ node = parent;
+ parent = pctrie_parent(node);
}
- if (node == NULL) {
+ if (parent == NULL) {
if (parent_out != NULL)
- *parent_out = NULL;
+ *parent_out = node;
return (NULL);
}
/* Step to the greatest child with a descendant < index. */
- slot = ilog2(node->pn_popmap & ((1 << slot) - 1));
- parent = node;
- node = pctrie_node_load(&node->pn_child[slot], NULL,
+ slot = ilog2(parent->pn_popmap & ((1 << slot) - 1));
+ node = pctrie_node_load(&parent->pn_child[slot], NULL,
PCTRIE_LOCKED);
}
/* Descend to the greatest leaf of the subtrie. */
diff --git a/sys/kern/sys_pipe.c b/sys/kern/sys_pipe.c
index 9340779918a2..ed651da96b14 100644
--- a/sys/kern/sys_pipe.c
+++ b/sys/kern/sys_pipe.c
@@ -548,7 +548,7 @@ sys_pipe2(struct thread *td, struct pipe2_args *uap)
{
int error, fildes[2];
- if (uap->flags & ~(O_CLOEXEC | O_NONBLOCK))
+ if ((uap->flags & ~(O_CLOEXEC | O_CLOFORK | O_NONBLOCK)) != 0)
return (EINVAL);
error = kern_pipe(td, fildes, uap->flags, NULL, NULL);
if (error)
diff --git a/sys/kern/syscalls.master b/sys/kern/syscalls.master
index 2ab17e036d5c..90559fab6086 100644
--- a/sys/kern/syscalls.master
+++ b/sys/kern/syscalls.master
@@ -3349,7 +3349,7 @@
size_t size
);
}
-592 AUE_NULL STD {
+592 AUE_NULL STD|CAPENABLED {
int exterrctl(
u_int op,
u_int flags,
diff --git a/sys/kern/sysv_msg.c b/sys/kern/sysv_msg.c
index 11141d197aec..a545a0a54c25 100644
--- a/sys/kern/sysv_msg.c
+++ b/sys/kern/sysv_msg.c
@@ -1724,7 +1724,7 @@ freebsd32_msgsys(struct thread *td, struct freebsd32_msgsys_args *uap)
return (sys_msgsys(td, (struct msgsys_args *)uap));
}
#else
- return (nosys(td, NULL));
+ return (kern_nosys(td, 0));
#endif
}
diff --git a/sys/kern/sysv_sem.c b/sys/kern/sysv_sem.c
index e399517010fc..a99e1a4de14e 100644
--- a/sys/kern/sysv_sem.c
+++ b/sys/kern/sysv_sem.c
@@ -1904,7 +1904,7 @@ freebsd32_semsys(struct thread *td, struct freebsd32_semsys_args *uap)
return (sys_semsys(td, (struct semsys_args *)uap));
}
#else
- return (nosys(td, NULL));
+ return (kern_nosys(td, 0));
#endif
}
diff --git a/sys/kern/sysv_shm.c b/sys/kern/sysv_shm.c
index 60e3fe92a4b7..8d1a469127c6 100644
--- a/sys/kern/sysv_shm.c
+++ b/sys/kern/sysv_shm.c
@@ -1474,7 +1474,7 @@ freebsd32_shmsys(struct thread *td, struct freebsd32_shmsys_args *uap)
return (EINVAL);
}
#else
- return (nosys(td, NULL));
+ return (kern_nosys(td, 0));
#endif
}
diff --git a/sys/kern/uipc_syscalls.c b/sys/kern/uipc_syscalls.c
index ad8485028987..133724ac76c5 100644
--- a/sys/kern/uipc_syscalls.c
+++ b/sys/kern/uipc_syscalls.c
@@ -151,6 +151,10 @@ kern_socket(struct thread *td, int domain, int type, int protocol)
type &= ~SOCK_CLOEXEC;
oflag |= O_CLOEXEC;
}
+ if ((type & SOCK_CLOFORK) != 0) {
+ type &= ~SOCK_CLOFORK;
+ oflag |= O_CLOFORK;
+ }
if ((type & SOCK_NONBLOCK) != 0) {
type &= ~SOCK_NONBLOCK;
fflag |= FNONBLOCK;
@@ -352,7 +356,8 @@ kern_accept4(struct thread *td, int s, struct sockaddr *sa, int flags,
goto done;
#endif
error = falloc_caps(td, &nfp, &fd,
- (flags & SOCK_CLOEXEC) ? O_CLOEXEC : 0, &fcaps);
+ ((flags & SOCK_CLOEXEC) != 0 ? O_CLOEXEC : 0) |
+ ((flags & SOCK_CLOFORK) != 0 ? O_CLOFORK : 0), &fcaps);
if (error != 0)
goto done;
SOCK_LOCK(head);
@@ -435,7 +440,7 @@ int
sys_accept4(struct thread *td, struct accept4_args *uap)
{
- if (uap->flags & ~(SOCK_CLOEXEC | SOCK_NONBLOCK))
+ if ((uap->flags & ~(SOCK_CLOEXEC | SOCK_CLOFORK | SOCK_NONBLOCK)) != 0)
return (EINVAL);
return (accept1(td, uap->s, uap->name, uap->anamelen, uap->flags));
@@ -557,6 +562,10 @@ kern_socketpair(struct thread *td, int domain, int type, int protocol,
type &= ~SOCK_CLOEXEC;
oflag |= O_CLOEXEC;
}
+ if ((type & SOCK_CLOFORK) != 0) {
+ type &= ~SOCK_CLOFORK;
+ oflag |= O_CLOFORK;
+ }
if ((type & SOCK_NONBLOCK) != 0) {
type &= ~SOCK_NONBLOCK;
fflag |= FNONBLOCK;
diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c
index 72bd0246db11..0056dac65c7d 100644
--- a/sys/kern/uipc_usrreq.c
+++ b/sys/kern/uipc_usrreq.c
@@ -3463,7 +3463,8 @@ unp_externalize(struct mbuf *control, struct mbuf **controlp, int flags)
UNP_LINK_UNLOCK_ASSERT();
- fdflags = (flags & MSG_CMSG_CLOEXEC) ? O_CLOEXEC : 0;
+ fdflags = ((flags & MSG_CMSG_CLOEXEC) ? O_CLOEXEC : 0) |
+ ((flags & MSG_CMSG_CLOFORK) ? O_CLOFORK : 0);
error = 0;
if (controlp != NULL) /* controlp == NULL => free control messages */
diff --git a/sys/kern/vfs_aio.c b/sys/kern/vfs_aio.c
index 97dc854c9386..02973146068d 100644
--- a/sys/kern/vfs_aio.c
+++ b/sys/kern/vfs_aio.c
@@ -301,7 +301,7 @@ static TAILQ_HEAD(,kaiocb) aio_jobs; /* (c) Async job list */
static struct unrhdr *aiod_unr;
static void aio_biocleanup(struct bio *bp);
-void aio_init_aioinfo(struct proc *p);
+static int aio_init_aioinfo(struct proc *p);
static int aio_onceonly(void);
static int aio_free_entry(struct kaiocb *job);
static void aio_process_rw(struct kaiocb *job);
@@ -309,7 +309,7 @@ static void aio_process_sync(struct kaiocb *job);
static void aio_process_mlock(struct kaiocb *job);
static void aio_schedule_fsync(void *context, int pending);
static int aio_newproc(int *);
-int aio_aqueue(struct thread *td, struct aiocb *ujob,
+static int aio_aqueue(struct thread *td, struct aiocb *ujob,
struct aioliojob *lio, int type, struct aiocb_ops *ops);
static int aio_queue_file(struct file *fp, struct kaiocb *job);
static void aio_biowakeup(struct bio *bp);
@@ -422,10 +422,11 @@ aio_onceonly(void)
* Init the per-process aioinfo structure. The aioinfo limits are set
* per-process for user limit (resource) management.
*/
-void
+static int
aio_init_aioinfo(struct proc *p)
{
struct kaioinfo *ki;
+ int error;
ki = uma_zalloc(kaio_zone, M_WAITOK);
mtx_init(&ki->kaio_mtx, "aiomtx", NULL, MTX_DEF | MTX_NEW);
@@ -451,8 +452,20 @@ aio_init_aioinfo(struct proc *p)
uma_zfree(kaio_zone, ki);
}
- while (num_aio_procs < MIN(target_aio_procs, max_aio_procs))
- aio_newproc(NULL);
+ error = 0;
+ while (num_aio_procs < MIN(target_aio_procs, max_aio_procs)) {
+ error = aio_newproc(NULL);
+ if (error != 0) {
+ /*
+ * At least one worker is enough to have AIO
+ * functional. Clear error in that case.
+ */
+ if (num_aio_procs > 0)
+ error = 0;
+ break;
+ }
+ }
+ return (error);
}
static int
@@ -1476,7 +1489,7 @@ static struct aiocb_ops aiocb_ops_osigevent = {
* Queue a new AIO request. Choosing either the threaded or direct bio VCHR
* technique is done in this code.
*/
-int
+static int
aio_aqueue(struct thread *td, struct aiocb *ujob, struct aioliojob *lj,
int type, struct aiocb_ops *ops)
{
@@ -1490,8 +1503,11 @@ aio_aqueue(struct thread *td, struct aiocb *ujob, struct aioliojob *lj,
int fd, kqfd;
u_short evflags;
- if (p->p_aioinfo == NULL)
- aio_init_aioinfo(p);
+ if (p->p_aioinfo == NULL) {
+ error = aio_init_aioinfo(p);
+ if (error != 0)
+ goto err1;
+ }
ki = p->p_aioinfo;
@@ -2213,8 +2229,11 @@ kern_lio_listio(struct thread *td, int mode, struct aiocb * const *uacb_list,
if (nent < 0 || nent > max_aio_queue_per_proc)
return (EINVAL);
- if (p->p_aioinfo == NULL)
- aio_init_aioinfo(p);
+ if (p->p_aioinfo == NULL) {
+ error = aio_init_aioinfo(p);
+ if (error != 0)
+ return (error);
+ }
ki = p->p_aioinfo;
@@ -2503,8 +2522,11 @@ kern_aio_waitcomplete(struct thread *td, struct aiocb **ujobp,
timo = tvtohz(&atv);
}
- if (p->p_aioinfo == NULL)
- aio_init_aioinfo(p);
+ if (p->p_aioinfo == NULL) {
+ error = aio_init_aioinfo(p);
+ if (error != 0)
+ return (error);
+ }
ki = p->p_aioinfo;
error = 0;
diff --git a/sys/kern/vfs_default.c b/sys/kern/vfs_default.c
index 2a01ec1e307e..fd6202a1424c 100644
--- a/sys/kern/vfs_default.c
+++ b/sys/kern/vfs_default.c
@@ -456,6 +456,7 @@ vop_stdpathconf(struct vop_pathconf_args *ap)
case _PC_MAC_PRESENT:
case _PC_NAMEDATTR_ENABLED:
case _PC_HAS_NAMEDATTR:
+ case _PC_HAS_HIDDENSYSTEM:
*ap->a_retval = 0;
return (0);
default:
diff --git a/sys/kern/vfs_inotify.c b/sys/kern/vfs_inotify.c
index 9562350c897f..2b42228465a4 100644
--- a/sys/kern/vfs_inotify.c
+++ b/sys/kern/vfs_inotify.c
@@ -503,7 +503,7 @@ inotify_can_coalesce(struct inotify_softc *sc, struct inotify_event *evp)
return (prev != NULL && prev->ev.mask == evp->mask &&
prev->ev.wd == evp->wd && prev->ev.cookie == evp->cookie &&
prev->ev.len == evp->len &&
- (evp->len == 0 || strcmp(prev->ev.name, evp->name) == 0));
+ memcmp(prev->ev.name, evp->name, evp->len) == 0);
}
static void
@@ -760,9 +760,11 @@ vn_inotify_add_watch(struct vnode *vp, struct inotify_softc *sc, uint32_t mask,
* directory if it's specified as a vnode.
*/
vrefact(vp);
+ VOP_UNLOCK(vp);
NDINIT_ATVP(&nd, LOOKUP, NOFOLLOW, UIO_SYSSPACE,
dp->d_name, vp);
error = namei(&nd);
+ vn_lock(vp, LK_SHARED | LK_RETRY);
if (error != 0)
break;
vn_irflag_set_cond(nd.ni_vp, VIRF_INOTIFY_PARENT);
diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c
index d880733cbfe7..c71e0d9ee569 100644
--- a/sys/kern/vfs_syscalls.c
+++ b/sys/kern/vfs_syscalls.c
@@ -4314,10 +4314,6 @@ kern_getdirentries(struct thread *td, int fd, char *buf, size_t count,
vp = fp->f_vnode;
foffset = foffset_lock(fp, 0);
unionread:
- if (vp->v_type != VDIR) {
- error = EINVAL;
- goto fail;
- }
if (__predict_false((vp->v_vflag & VV_UNLINKED) != 0)) {
error = ENOENT;
goto fail;
@@ -4330,6 +4326,19 @@ unionread:
auio.uio_segflg = bufseg;
auio.uio_td = td;
vn_lock(vp, LK_SHARED | LK_RETRY);
+ /*
+ * We want to return ENOTDIR for anything that is not VDIR, but
+ * not for VBAD, and we can't check for VBAD while the vnode is
+ * unlocked.
+ */
+ if (vp->v_type != VDIR) {
+ if (vp->v_type == VBAD)
+ error = EBADF;
+ else
+ error = ENOTDIR;
+ VOP_UNLOCK(vp);
+ goto fail;
+ }
AUDIT_ARG_VNODE1(vp);
loff = auio.uio_offset = foffset;
#ifdef MAC
diff --git a/sys/modules/sound/sound/Makefile b/sys/modules/sound/sound/Makefile
index d2cfed2f4b6a..f3978e9bd9cc 100644
--- a/sys/modules/sound/sound/Makefile
+++ b/sys/modules/sound/sound/Makefile
@@ -13,11 +13,11 @@ SRCS+= feeder.c feeder_rate.c feeder_volume.c
SRCS+= feeder_chain.c feeder_eq.c feeder_format.c
SRCS+= feeder_matrix.c feeder_mixer.c
SRCS+= feeder_eq_gen.h feeder_rate_gen.h snd_fxdiv_gen.h
-SRCS+= mpu_if.h mpufoi_if.h synth_if.h
-SRCS+= mpu_if.c mpufoi_if.c synth_if.c
+SRCS+= mpu_if.h mpufoi_if.h
+SRCS+= mpu_if.c mpufoi_if.c
SRCS+= ac97.c buffer.c channel.c dsp.c
SRCS+= mixer.c sndstat.c sound.c vchan.c
-SRCS+= midi.c mpu401.c sequencer.c
+SRCS+= midi.c mpu401.c
feeder_eq_gen.h: ${SYSDIR}/tools/sound/feeder_eq_mkfilter.awk
${AWK} -f ${SYSDIR}/tools/sound/feeder_eq_mkfilter.awk -- ${FEEDER_EQ_PRESETS} > ${.TARGET}
diff --git a/sys/net/ethernet.h b/sys/net/ethernet.h
index 6eefedba8775..cf4f75bd0b6c 100644
--- a/sys/net/ethernet.h
+++ b/sys/net/ethernet.h
@@ -81,6 +81,23 @@ struct ether_addr {
(addr)[3] | (addr)[4] | (addr)[5]) == 0x00)
/*
+ * 802.1q VID constants from IEEE 802.1Q-2014, table 9-2.
+ */
+
+/* Null VID: The tag contains only PCP (priority) and DEI information. */
+#define DOT1Q_VID_NULL 0x0
+/* The default PVID for a bridge port. NB: bridge(4) does not honor this. */
+#define DOT1Q_VID_DEF_PVID 0x1
+/* The default SR_PVID for SRP Stream related traffic. */
+#define DOT1Q_VID_DEF_SR_PVID 0x2
+/* A VID reserved for implementation use, not permitted on the wire. */
+#define DOT1Q_VID_RSVD_IMPL 0xfff
+/* The lowest valid VID. */
+#define DOT1Q_VID_MIN 0x1
+/* The highest valid VID. */
+#define DOT1Q_VID_MAX 0xffe
+
+/*
* This is the type of the VLAN ID inside the tag, not the tag itself.
*/
typedef uint16_t ether_vlanid_t;
diff --git a/sys/net/if_bridge.c b/sys/net/if_bridge.c
index bc421a8e156d..5b3ee740d75e 100644
--- a/sys/net/if_bridge.c
+++ b/sys/net/if_bridge.c
@@ -254,6 +254,8 @@ struct bridge_iflist {
uint32_t bif_addrcnt; /* cur. # of addresses */
uint32_t bif_addrexceeded;/* # of address violations */
struct epoch_context bif_epoch_ctx;
+ ether_vlanid_t bif_untagged; /* untagged vlan id */
+ ifbvlan_set_t bif_vlan_set; /* allowed tagged vlans */
};
/*
@@ -331,13 +333,12 @@ static void bridge_inject(struct ifnet *, struct mbuf *);
static int bridge_output(struct ifnet *, struct mbuf *, struct sockaddr *,
struct rtentry *);
static int bridge_enqueue(struct bridge_softc *, struct ifnet *,
- struct mbuf *);
+ struct mbuf *, struct bridge_iflist *);
static void bridge_rtdelete(struct bridge_softc *, struct ifnet *ifp, int);
static void bridge_forward(struct bridge_softc *, struct bridge_iflist *,
struct mbuf *m);
static bool bridge_member_ifaddrs(void);
-
static void bridge_timer(void *);
static void bridge_broadcast(struct bridge_softc *, struct ifnet *,
@@ -353,6 +354,9 @@ static void bridge_rtage(struct bridge_softc *);
static void bridge_rtflush(struct bridge_softc *, int);
static int bridge_rtdaddr(struct bridge_softc *, const uint8_t *,
ether_vlanid_t);
+static bool bridge_vfilter_in(const struct bridge_iflist *, struct mbuf *);
+static bool bridge_vfilter_out(const struct bridge_iflist *,
+ const struct mbuf *);
static void bridge_rtable_init(struct bridge_softc *);
static void bridge_rtable_fini(struct bridge_softc *);
@@ -400,6 +404,9 @@ static int bridge_ioctl_sma(struct bridge_softc *, void *);
static int bridge_ioctl_sifprio(struct bridge_softc *, void *);
static int bridge_ioctl_sifcost(struct bridge_softc *, void *);
static int bridge_ioctl_sifmaxaddr(struct bridge_softc *, void *);
+static int bridge_ioctl_sifuntagged(struct bridge_softc *, void *);
+static int bridge_ioctl_sifvlanset(struct bridge_softc *, void *);
+static int bridge_ioctl_gifvlanset(struct bridge_softc *, void *);
static int bridge_ioctl_addspan(struct bridge_softc *, void *);
static int bridge_ioctl_delspan(struct bridge_softc *, void *);
static int bridge_ioctl_gbparam(struct bridge_softc *, void *);
@@ -618,6 +625,14 @@ static const struct bridge_control bridge_control_table[] = {
{ bridge_ioctl_sifmaxaddr, sizeof(struct ifbreq),
BC_F_COPYIN|BC_F_SUSER },
+ { bridge_ioctl_sifuntagged, sizeof(struct ifbreq),
+ BC_F_COPYIN|BC_F_SUSER },
+
+ { bridge_ioctl_sifvlanset, sizeof(struct ifbif_vlan_req),
+ BC_F_COPYIN|BC_F_SUSER },
+
+ { bridge_ioctl_gifvlanset, sizeof(struct ifbif_vlan_req),
+ BC_F_COPYIN|BC_F_COPYOUT },
};
static const int bridge_control_table_size = nitems(bridge_control_table);
@@ -832,6 +847,7 @@ bridge_clone_create(struct if_clone *ifc, char *name, size_t len,
ifp->if_softc = sc;
if_initname(ifp, bridge_name, ifd->unit);
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
+ ifp->if_capabilities = ifp->if_capenable = IFCAP_VLAN_HWTAGGING;
ifp->if_ioctl = bridge_ioctl;
#ifdef ALTQ
ifp->if_start = bridge_altq_start;
@@ -954,6 +970,7 @@ bridge_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
struct ifbaconf ifbaconf;
struct ifbrparam ifbrparam;
struct ifbropreq ifbropreq;
+ struct ifbif_vlan_req ifvlanreq;
} args;
struct ifdrv *ifd = (struct ifdrv *) data;
const struct bridge_control *bc;
@@ -1495,6 +1512,7 @@ bridge_ioctl_gifflags(struct bridge_softc *sc, void *arg)
req->ifbr_addrcnt = bif->bif_addrcnt;
req->ifbr_addrmax = bif->bif_addrmax;
req->ifbr_addrexceeded = bif->bif_addrexceeded;
+ req->ifbr_untagged = bif->bif_untagged;
/* Copy STP state options as flags */
if (bp->bp_operedge)
@@ -1873,6 +1891,84 @@ bridge_ioctl_sifmaxaddr(struct bridge_softc *sc, void *arg)
}
static int
+bridge_ioctl_sifuntagged(struct bridge_softc *sc, void *arg)
+{
+ struct ifbreq *req = arg;
+ struct bridge_iflist *bif;
+
+ bif = bridge_lookup_member(sc, req->ifbr_ifsname);
+ if (bif == NULL)
+ return (ENOENT);
+
+ if (req->ifbr_untagged > DOT1Q_VID_MAX)
+ return (EINVAL);
+
+ if (req->ifbr_untagged != DOT1Q_VID_NULL)
+ bif->bif_flags |= IFBIF_VLANFILTER;
+ bif->bif_untagged = req->ifbr_untagged;
+ return (0);
+}
+
+static int
+bridge_ioctl_sifvlanset(struct bridge_softc *sc, void *arg)
+{
+ struct ifbif_vlan_req *req = arg;
+ struct bridge_iflist *bif;
+
+ bif = bridge_lookup_member(sc, req->bv_ifname);
+ if (bif == NULL)
+ return (ENOENT);
+
+ /* Reject invalid VIDs. */
+ if (BRVLAN_TEST(&req->bv_set, DOT1Q_VID_NULL) ||
+ BRVLAN_TEST(&req->bv_set, DOT1Q_VID_RSVD_IMPL))
+ return (EINVAL);
+
+ switch (req->bv_op) {
+ /* Replace the existing vlan set with the new set */
+ case BRDG_VLAN_OP_SET:
+ BIT_COPY(BRVLAN_SETSIZE, &req->bv_set, &bif->bif_vlan_set);
+ break;
+
+ /* Modify the existing vlan set to add the given vlans */
+ case BRDG_VLAN_OP_ADD:
+ BIT_OR(BRVLAN_SETSIZE, &bif->bif_vlan_set, &req->bv_set);
+ break;
+
+ /* Modify the existing vlan set to remove the given vlans */
+ case BRDG_VLAN_OP_DEL:
+ BIT_ANDNOT(BRVLAN_SETSIZE, &bif->bif_vlan_set, &req->bv_set);
+ break;
+
+ /* Invalid or unknown operation */
+ default:
+ return (EINVAL);
+ }
+
+ /*
+ * The only reason to modify the VLAN access list is to use VLAN
+ * filtering on this interface, so enable it automatically.
+ */
+ bif->bif_flags |= IFBIF_VLANFILTER;
+
+ return (0);
+}
+
+static int
+bridge_ioctl_gifvlanset(struct bridge_softc *sc, void *arg)
+{
+ struct ifbif_vlan_req *req = arg;
+ struct bridge_iflist *bif;
+
+ bif = bridge_lookup_member(sc, req->bv_ifname);
+ if (bif == NULL)
+ return (ENOENT);
+
+ BIT_COPY(BRVLAN_SETSIZE, &bif->bif_vlan_set, &req->bv_set);
+ return (0);
+}
+
+static int
bridge_ioctl_addspan(struct bridge_softc *sc, void *arg)
{
struct ifbreq *req = arg;
@@ -2150,12 +2246,25 @@ bridge_stop(struct ifnet *ifp, int disable)
*
*/
static int
-bridge_enqueue(struct bridge_softc *sc, struct ifnet *dst_ifp, struct mbuf *m)
+bridge_enqueue(struct bridge_softc *sc, struct ifnet *dst_ifp, struct mbuf *m,
+ struct bridge_iflist *bif)
{
int len, err = 0;
short mflags;
struct mbuf *m0;
+ /*
+ * Find the bridge member port this packet is being sent on, if the
+ * caller didn't already provide it.
+ */
+ if (bif == NULL)
+ bif = bridge_lookup_member_if(sc, dst_ifp);
+ if (bif == NULL) {
+ /* Perhaps the interface was removed from the bridge */
+ m_freem(m);
+ return (EINVAL);
+ }
+
/* We may be sending a fragment so traverse the mbuf */
for (; m; m = m0) {
m0 = m->m_nextpkt;
@@ -2164,6 +2273,18 @@ bridge_enqueue(struct bridge_softc *sc, struct ifnet *dst_ifp, struct mbuf *m)
mflags = m->m_flags;
/*
+ * If VLAN filtering is enabled, and the native VLAN ID of the
+ * outgoing interface matches the VLAN ID of the frame, remove
+ * the VLAN header.
+ */
+ if ((bif->bif_flags & IFBIF_VLANFILTER) &&
+ bif->bif_untagged != DOT1Q_VID_NULL &&
+ VLANTAGOF(m) == bif->bif_untagged) {
+ m->m_flags &= ~M_VLANTAG;
+ m->m_pkthdr.ether_vtag = 0;
+ }
+
+ /*
* If underlying interface can not do VLAN tag insertion itself
* then attach a packet tag that holds it.
*/
@@ -2234,7 +2355,7 @@ bridge_dummynet(struct mbuf *m, struct ifnet *ifp)
return;
}
- bridge_enqueue(sc, ifp, m);
+ bridge_enqueue(sc, ifp, m, NULL);
}
/*
@@ -2329,7 +2450,7 @@ bridge_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *sa,
}
}
- bridge_enqueue(sc, dst_if, mc);
+ bridge_enqueue(sc, dst_if, mc, bif);
}
if (used == 0)
m_freem(m);
@@ -2347,7 +2468,7 @@ sendunicast:
return (0);
}
- bridge_enqueue(sc, dst_if, m);
+ bridge_enqueue(sc, dst_if, m, NULL);
return (0);
}
@@ -2364,17 +2485,18 @@ bridge_transmit(struct ifnet *ifp, struct mbuf *m)
struct ether_header *eh;
struct ifnet *dst_if;
int error = 0;
+ ether_vlanid_t vlan;
sc = ifp->if_softc;
ETHER_BPF_MTAP(ifp, m);
eh = mtod(m, struct ether_header *);
+ vlan = VLANTAGOF(m);
if (((m->m_flags & (M_BCAST|M_MCAST)) == 0) &&
- (dst_if = bridge_rtlookup(sc, eh->ether_dhost, DOT1Q_VID_NULL)) !=
- NULL) {
- error = bridge_enqueue(sc, dst_if, m);
+ (dst_if = bridge_rtlookup(sc, eh->ether_dhost, vlan)) != NULL) {
+ error = bridge_enqueue(sc, dst_if, m, NULL);
} else
bridge_broadcast(sc, ifp, m, 0);
@@ -2435,18 +2557,18 @@ bridge_forward(struct bridge_softc *sc, struct bridge_iflist *sbif,
struct bridge_iflist *dbif;
struct ifnet *src_if, *dst_if, *ifp;
struct ether_header *eh;
- uint16_t vlan;
uint8_t *dst;
int error;
+ ether_vlanid_t vlan;
NET_EPOCH_ASSERT();
src_if = m->m_pkthdr.rcvif;
ifp = sc->sc_ifp;
+ vlan = VLANTAGOF(m);
if_inc_counter(ifp, IFCOUNTER_IPACKETS, 1);
if_inc_counter(ifp, IFCOUNTER_IBYTES, m->m_pkthdr.len);
- vlan = VLANTAGOF(m);
if ((sbif->bif_flags & IFBIF_STP) &&
sbif->bif_stp.bp_state == BSTP_IFSTATE_DISCARDING)
@@ -2555,6 +2677,10 @@ bridge_forward(struct bridge_softc *sc, struct bridge_iflist *sbif,
if (sbif->bif_flags & dbif->bif_flags & IFBIF_PRIVATE)
goto drop;
+ /* Do VLAN filtering. */
+ if (!bridge_vfilter_out(dbif, m))
+ goto drop;
+
if ((dbif->bif_flags & IFBIF_STP) &&
dbif->bif_stp.bp_state == BSTP_IFSTATE_DISCARDING)
goto drop;
@@ -2566,7 +2692,7 @@ bridge_forward(struct bridge_softc *sc, struct bridge_iflist *sbif,
return;
}
- bridge_enqueue(sc, dst_if, m);
+ bridge_enqueue(sc, dst_if, m, dbif);
return;
drop:
@@ -2636,6 +2762,15 @@ bridge_input(struct ifnet *ifp, struct mbuf *m)
return (NULL);
}
+ /* Do VLAN filtering. */
+ if (!bridge_vfilter_in(bif, m)) {
+ if_inc_counter(sc->sc_ifp, IFCOUNTER_IERRORS, 1);
+ m_freem(m);
+ return (NULL);
+ }
+ /* bridge_vfilter_in() may add a tag */
+ vlan = VLANTAGOF(m);
+
bridge_span(sc, m);
if (m->m_flags & (M_BCAST|M_MCAST)) {
@@ -2761,6 +2896,15 @@ bridge_input(struct ifnet *ifp, struct mbuf *m)
} \
if ((iface) != bifp) \
ETHER_BPF_MTAP(iface, m); \
+ /* Pass tagged packets to if_vlan, if it's loaded */ \
+ if (VLANTAGOF(m) != 0) { \
+ if (bifp->if_vlantrunk == NULL) { \
+ m_freem(m); \
+ return (NULL); \
+ } \
+ (*vlan_input_p)(bifp, m); \
+ return (NULL); \
+ } \
return (m); \
} \
\
@@ -2817,6 +2961,30 @@ bridge_inject(struct ifnet *ifp, struct mbuf *m)
{
struct bridge_softc *sc;
+ if (ifp->if_type == IFT_L2VLAN) {
+ /*
+ * vlan(4) gives us the vlan ifnet, so we need to get the
+ * bridge softc to get a pointer to ether_input to send the
+ * packet to.
+ */
+ struct ifnet *bifp = NULL;
+
+ if (vlan_trunkdev_p == NULL) {
+ m_freem(m);
+ return;
+ }
+
+ bifp = vlan_trunkdev_p(ifp);
+ if (bifp == NULL) {
+ m_freem(m);
+ return;
+ }
+
+ sc = if_getsoftc(bifp);
+ sc->sc_if_input(ifp, m);
+ return;
+ }
+
KASSERT((if_getcapenable(ifp) & IFCAP_NETMAP) != 0,
("%s: iface %s is not running in netmap mode",
__func__, if_name(ifp)));
@@ -2867,6 +3035,10 @@ bridge_broadcast(struct bridge_softc *sc, struct ifnet *src_if,
if (sbif && (sbif->bif_flags & dbif->bif_flags & IFBIF_PRIVATE))
continue;
+ /* Do VLAN filtering. */
+ if (!bridge_vfilter_out(dbif, m))
+ continue;
+
if ((dbif->bif_flags & IFBIF_STP) &&
dbif->bif_stp.bp_state == BSTP_IFSTATE_DISCARDING)
continue;
@@ -2910,7 +3082,7 @@ bridge_broadcast(struct bridge_softc *sc, struct ifnet *src_if,
continue;
}
- bridge_enqueue(sc, dst_if, mc);
+ bridge_enqueue(sc, dst_if, mc, dbif);
}
if (used == 0)
m_freem(m);
@@ -2946,11 +3118,116 @@ bridge_span(struct bridge_softc *sc, struct mbuf *m)
continue;
}
- bridge_enqueue(sc, dst_if, mc);
+ bridge_enqueue(sc, dst_if, mc, bif);
}
}
/*
+ * Incoming VLAN filtering. Given a frame and the member interface it was
+ * received on, decide whether the port configuration allows it.
+ */
+static bool
+bridge_vfilter_in(const struct bridge_iflist *sbif, struct mbuf *m)
+{
+ ether_vlanid_t vlan;
+
+ vlan = VLANTAGOF(m);
+ /* Make sure the vlan id is reasonable. */
+ if (vlan > DOT1Q_VID_MAX)
+ return (false);
+
+ /* If VLAN filtering isn't enabled, pass everything. */
+ if ((sbif->bif_flags & IFBIF_VLANFILTER) == 0)
+ return (true);
+
+ if (vlan == DOT1Q_VID_NULL) {
+ /*
+ * The frame doesn't have a tag. If the interface does not
+ * have an untagged vlan configured, drop the frame.
+ */
+ if (sbif->bif_untagged == DOT1Q_VID_NULL)
+ return (false);
+
+ /*
+ * Otherwise, insert a new tag based on the interface's
+ * untagged vlan id.
+ */
+ m->m_pkthdr.ether_vtag = sbif->bif_untagged;
+ m->m_flags |= M_VLANTAG;
+ } else {
+ /*
+ * The frame has a tag, so check it matches the interface's
+ * vlan access list. We explicitly do not accept tagged
+ * frames for the untagged vlan id here (unless it's also
+ * in the access list).
+ */
+ if (!BRVLAN_TEST(&sbif->bif_vlan_set, vlan))
+ return (false);
+ }
+
+ /* Accept the frame. */
+ return (true);
+}
+
+/*
+ * Outgoing VLAN filtering. Given a frame, its vlan, and the member interface
+ * we intend to send it to, decide whether the port configuration allows it to
+ * be sent.
+ */
+static bool
+bridge_vfilter_out(const struct bridge_iflist *dbif, const struct mbuf *m)
+{
+ struct ether_header *eh;
+ ether_vlanid_t vlan;
+
+ NET_EPOCH_ASSERT();
+
+ /* If VLAN filtering isn't enabled, pass everything. */
+ if ((dbif->bif_flags & IFBIF_VLANFILTER) == 0)
+ return (true);
+
+ vlan = VLANTAGOF(m);
+
+ /*
+ * Always allow untagged 802.1D STP frames, even if they would
+ * otherwise be dropped. This is required for STP to work on
+ * a filtering bridge.
+ *
+ * Tagged STP (Cisco PVST+) is a non-standard extension, so
+ * handle those frames via the normal filtering path.
+ */
+ eh = mtod(m, struct ether_header *);
+ if (vlan == DOT1Q_VID_NULL &&
+ memcmp(eh->ether_dhost, bstp_etheraddr, ETHER_ADDR_LEN) == 0)
+ return (true);
+
+ /*
+ * If the frame wasn't assigned to a vlan at ingress, drop it.
+ * We can't forward these frames to filtering ports because we
+ * don't know what VLAN they're supposed to be in.
+ */
+ if (vlan == DOT1Q_VID_NULL)
+ return (false);
+
+ /*
+ * If the frame's vlan matches the interfaces's untagged vlan,
+ * allow it.
+ */
+ if (vlan == dbif->bif_untagged)
+ return (true);
+
+ /*
+ * If the frame's vlan is on the interface's tagged access list,
+ * allow it.
+ */
+ if (BRVLAN_TEST(&dbif->bif_vlan_set, vlan))
+ return (true);
+
+ /* The frame was not permitted, so drop it. */
+ return (false);
+}
+
+/*
* bridge_rtupdate:
*
* Add a bridge routing entry.
diff --git a/sys/net/if_bridgevar.h b/sys/net/if_bridgevar.h
index 90beb6c96d82..97b63e3d4416 100644
--- a/sys/net/if_bridgevar.h
+++ b/sys/net/if_bridgevar.h
@@ -78,6 +78,8 @@
#define _NET_IF_BRIDGEVAR_H_
#include <sys/types.h>
+#include <sys/_bitset.h>
+#include <sys/bitset.h>
#include <sys/callout.h>
#include <sys/queue.h>
#include <sys/condvar.h>
@@ -122,6 +124,9 @@
#define BRDGSPROTO 28 /* set protocol (ifbrparam) */
#define BRDGSTXHC 29 /* set tx hold count (ifbrparam) */
#define BRDGSIFAMAX 30 /* set max interface addrs (ifbreq) */
+#define BRDGSIFUNTAGGED 31 /* set if untagged vlan */
+#define BRDGSIFVLANSET 32 /* set if vlan set */
+#define BRDGGIFVLANSET 33 /* get if vlan set */
/*
* Generic bridge control request.
@@ -139,6 +144,7 @@ struct ifbreq {
uint32_t ifbr_addrcnt; /* member if addr number */
uint32_t ifbr_addrmax; /* member if addr max */
uint32_t ifbr_addrexceeded; /* member if addr violations */
+ ether_vlanid_t ifbr_untagged; /* member if untagged vlan */
uint8_t pad[32];
};
@@ -155,10 +161,11 @@ struct ifbreq {
#define IFBIF_BSTP_ADMEDGE 0x0200 /* member stp admin edge enabled */
#define IFBIF_BSTP_ADMCOST 0x0400 /* member stp admin path cost */
#define IFBIF_PRIVATE 0x0800 /* if is a private segment */
+#define IFBIF_VLANFILTER 0x1000 /* if does vlan filtering */
#define IFBIFBITS "\020\001LEARNING\002DISCOVER\003STP\004SPAN" \
"\005STICKY\014PRIVATE\006EDGE\007AUTOEDGE\010PTP" \
- "\011AUTOPTP"
+ "\011AUTOPTP\015VLANFILTER"
#define IFBIFMASK ~(IFBIF_BSTP_EDGE|IFBIF_BSTP_AUTOEDGE|IFBIF_BSTP_PTP| \
IFBIF_BSTP_AUTOPTP|IFBIF_BSTP_ADMEDGE| \
IFBIF_BSTP_ADMCOST) /* not saved */
@@ -304,6 +311,26 @@ struct ifbpstpconf {
eaddr[5] = pv >> 0; \
} while (0)
+/*
+ * Bridge VLAN access request.
+ */
+#define BRVLAN_SETSIZE 4096
+typedef __BITSET_DEFINE(ifbvlan_set, BRVLAN_SETSIZE) ifbvlan_set_t;
+
+#define BRVLAN_SET(set, bit) __BIT_SET(BRVLAN_SETSIZE, (bit), set)
+#define BRVLAN_CLR(set, bit) __BIT_CLR(BRVLAN_SETSIZE, (bit), set)
+#define BRVLAN_TEST(set, bit) __BIT_ISSET(BRVLAN_SETSIZE, (bit), set)
+
+#define BRDG_VLAN_OP_SET 1 /* replace current vlan set */
+#define BRDG_VLAN_OP_ADD 2 /* add vlans to current set */
+#define BRDG_VLAN_OP_DEL 3 /* remove vlans from current set */
+
+struct ifbif_vlan_req {
+ char bv_ifname[IFNAMSIZ];
+ uint8_t bv_op;
+ ifbvlan_set_t bv_set;
+};
+
#ifdef _KERNEL
#define BRIDGE_INPUT(_ifp, _m) do { \
diff --git a/sys/net/if_vlan.c b/sys/net/if_vlan.c
index e9e1c82cb688..22fcb7bf7c64 100644
--- a/sys/net/if_vlan.c
+++ b/sys/net/if_vlan.c
@@ -1673,6 +1673,7 @@ vlan_config(struct ifvlan *ifv, struct ifnet *p, uint16_t vid,
*/
if (p->if_type != IFT_ETHER &&
p->if_type != IFT_L2VLAN &&
+ p->if_type != IFT_BRIDGE &&
(p->if_capenable & IFCAP_VLAN_HWTAGGING) == 0)
return (EPROTONOSUPPORT);
if ((p->if_flags & VLAN_IFFLAGS) != VLAN_IFFLAGS)
diff --git a/sys/net/if_vlan_var.h b/sys/net/if_vlan_var.h
index f0b09445d04b..695bb81f77b3 100644
--- a/sys/net/if_vlan_var.h
+++ b/sys/net/if_vlan_var.h
@@ -126,13 +126,6 @@ struct vlanreq {
#define VLAN_PCP_MAX 7
-#define DOT1Q_VID_NULL 0x0
-#define DOT1Q_VID_DEF_PVID 0x1
-#define DOT1Q_VID_DEF_SR_PVID 0x2
-#define DOT1Q_VID_RSVD_IMPL 0xfff
-#define DOT1Q_VID_MIN 1 /* minimum valid vlan id */
-#define DOT1Q_VID_MAX 4094 /* maximum valid vlan id */
-
/*
* 802.1q full tag. Proto and vid are stored in host byte order.
*/
diff --git a/sys/net/pfvar.h b/sys/net/pfvar.h
index 1416f0c2cdbe..36fab1a03ee6 100644
--- a/sys/net/pfvar.h
+++ b/sys/net/pfvar.h
@@ -551,6 +551,9 @@ extern struct sx pf_end_lock;
#endif /* PF_INET_INET6 */
#ifdef _KERNEL
+
+void unhandled_af(int) __dead2;
+
static void inline
pf_addrcpy(struct pf_addr *dst, const struct pf_addr *src, sa_family_t af)
{
@@ -565,6 +568,8 @@ pf_addrcpy(struct pf_addr *dst, const struct pf_addr *src, sa_family_t af)
memcpy(&dst->v6, &src->v6, sizeof(dst->v6));
break;
#endif /* INET6 */
+ default:
+ unhandled_af(af);
}
}
#endif
@@ -2300,7 +2305,6 @@ VNET_DECLARE(struct pf_krule *, pf_rulemarker);
#define V_pf_rulemarker VNET(pf_rulemarker)
#endif
-void unhandled_af(int) __dead2;
int pf_start(void);
int pf_stop(void);
void pf_initialize(void);
@@ -2670,6 +2674,7 @@ int pf_ioctl_get_addrs(struct pf_nl_pooladdr *);
int pf_ioctl_get_addr(struct pf_nl_pooladdr *);
int pf_ioctl_get_rulesets(struct pfioc_ruleset *);
int pf_ioctl_get_ruleset(struct pfioc_ruleset *);
+int pf_ioctl_natlook(struct pfioc_natlook *);
void pf_krule_free(struct pf_krule *);
void pf_krule_clear_counters(struct pf_krule *);
diff --git a/sys/net80211/ieee80211_node.c b/sys/net80211/ieee80211_node.c
index ad17af6778a1..a201d1b278f0 100644
--- a/sys/net80211/ieee80211_node.c
+++ b/sys/net80211/ieee80211_node.c
@@ -3138,6 +3138,36 @@ ieee80211_getsignal(struct ieee80211vap *vap, int8_t *rssi, int8_t *noise)
}
/**
+ * @brief Increment the given TID TX sequence, return the current one.
+ *
+ * @param ni ieee80211_node to operate on
+ * @param tid TID, or IEEE80211_NONQOS_TID
+ * @returns sequence number, from 0 .. 4095 inclusive, post increments
+ */
+ieee80211_seq ieee80211_tx_seqno_fetch_incr(struct ieee80211_node *ni,
+ uint8_t tid)
+{
+ ieee80211_seq seq;
+
+ seq = ni->ni_txseqs[tid];
+ ni->ni_txseqs[tid] = (ni->ni_txseqs[tid] + 1) % IEEE80211_SEQ_RANGE;
+ return (seq);
+}
+
+/**
+ * @brief Return the current sequence number for the given TID
+ *
+ * @param ni ieee80211_node to operate on
+ * @param tid TID, or IEEE80211_NONQOS_TID
+ * @returns sequence number, from 0 .. 4095 inclusive
+ */
+ieee80211_seq ieee80211_tx_seqno_fetch(const struct ieee80211_node *ni,
+ uint8_t tid)
+{
+ return (ni->ni_txseqs[tid]);
+}
+
+/**
* @brief return a dot11rate / ratecode representing the current transmit rate
*
* This is the API call for legacy / 802.11n drivers and rate control APIs
diff --git a/sys/net80211/ieee80211_node.h b/sys/net80211/ieee80211_node.h
index c83eee04a8dc..ef25fa0d7fdd 100644
--- a/sys/net80211/ieee80211_node.h
+++ b/sys/net80211/ieee80211_node.h
@@ -531,6 +531,12 @@ void ieee80211_node_leave(struct ieee80211_node *);
int8_t ieee80211_getrssi(struct ieee80211vap *);
void ieee80211_getsignal(struct ieee80211vap *, int8_t *, int8_t *);
+/* TX sequence space related routines */
+ieee80211_seq ieee80211_tx_seqno_fetch_incr(struct ieee80211_node *,
+ uint8_t);
+ieee80211_seq ieee80211_tx_seqno_fetch(const struct ieee80211_node *,
+ uint8_t);
+
/*
* Node transmit rate specific manipulation.
*
diff --git a/sys/net80211/ieee80211_output.c b/sys/net80211/ieee80211_output.c
index a4151f807882..afe83ea0805c 100644
--- a/sys/net80211/ieee80211_output.c
+++ b/sys/net80211/ieee80211_output.c
@@ -4195,17 +4195,15 @@ ieee80211_tx_complete(struct ieee80211_node *ni, struct mbuf *m, int status)
* Check the frame type and TID and assign a suitable sequence number
* from the correct sequence number space.
*
+ * This implements the components of 802.11-2020 10.3.2.14.2
+ * (Transmitter Requirements) that net80211 currently supports.
+ *
* It assumes the mbuf has been encapsulated, and has the TID assigned
* if it is a QoS frame.
*
* Note this also clears any existing fragment ID in the header, so it
* must be called first before assigning fragment IDs.
*
- * For now this implements parts of 802.11-2012; it doesn't do all of
- * the needed checks for full compliance (notably QoS-Data NULL frames).
- *
- * TODO: update to 802.11-2020 10.3.2.14.2 (Transmitter Requirements)
- *
* @param ni ieee80211_node this frame will be transmitted to
* @param arg_tid A temporary check, existing callers may set
* this to a TID variable they were using, and this routine
@@ -4239,16 +4237,30 @@ ieee80211_output_seqno_assign(struct ieee80211_node *ni, int arg_tid,
"%s: called; TID mismatch; tid=%u, arg_tid=%d\n",
__func__, tid, arg_tid);
- if (IEEE80211_HAS_SEQ(type, subtype)) {
- /*
- * 802.11-2012 9.3.2.10 - QoS multicast frames
- * come out of a different seqno space.
- */
- if (IEEE80211_IS_MULTICAST(wh->i_addr1))
- seqno = ni->ni_txseqs[IEEE80211_NONQOS_TID]++;
- else
- seqno = ni->ni_txseqs[tid]++;
- } else
+
+ /* 802.11-2020 10.3.2.14.2 (Transmitter Requirements) sections */
+
+ /* SNS7 - unicast PV1 management frame */
+
+ /* SNS6 - unicast PV1 data frame */
+
+ /* SNS5 - QoS NULL frames */
+ if (IEEE80211_QOS_HAS_SEQ(wh) && IEEE80211_IS_QOS_NULL(wh))
+ seqno = ieee80211_tx_seqno_fetch_incr(ni, IEEE80211_NONQOS_TID);
+
+ /* SNS4 - QMF STA transmitting a QMF */
+
+ /* SNS3 - QoS STA; Time Priority Management frame */
+
+ /* SNS2 - unicast QoS STA, data frame, excluding SNS5 */
+ else if (IEEE80211_QOS_HAS_SEQ(wh) &&
+ !IEEE80211_IS_MULTICAST(wh->i_addr1))
+ seqno = ieee80211_tx_seqno_fetch_incr(ni, tid);
+
+ /* SNS1 - Baseline (everything else) */
+ else if (IEEE80211_HAS_SEQ(type, subtype))
+ seqno = ieee80211_tx_seqno_fetch_incr(ni, IEEE80211_NONQOS_TID);
+ else
seqno = 0;
/*
@@ -4276,7 +4288,7 @@ ieee80211_output_beacon_seqno_assign(struct ieee80211_node *ni, struct mbuf *m)
wh = mtod(m, struct ieee80211_frame *);
- seqno = ni->ni_txseqs[IEEE80211_NONQOS_TID]++;
+ seqno = ieee80211_tx_seqno_fetch_incr(ni, IEEE80211_NONQOS_TID);
*(uint16_t *)&wh->i_seq[0] =
htole16(seqno << IEEE80211_SEQ_SEQ_SHIFT);
M_SEQNO_SET(m, seqno);
diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c
index bccd4b84561a..dbe48242381d 100644
--- a/sys/netinet/in_pcb.c
+++ b/sys/netinet/in_pcb.c
@@ -1745,6 +1745,23 @@ in_pcbrele(struct inpcb *inp, const inp_lookup_t lock)
}
/*
+ * Dereference and rlock inp, for which the caller must own the
+ * reference. Returns true if inp no longer usable, false otherwise.
+ */
+bool
+in_pcbrele_rlock(struct inpcb *inp)
+{
+ INP_RLOCK(inp);
+ if (in_pcbrele_rlocked(inp))
+ return (true);
+ if ((inp->inp_flags & INP_FREED) != 0) {
+ INP_RUNLOCK(inp);
+ return (true);
+ }
+ return (false);
+}
+
+/*
* Unconditionally schedule an inpcb to be freed by decrementing its
* reference count, which should occur only after the inpcb has been detached
* from its socket. If another thread holds a temporary reference (acquired
diff --git a/sys/netinet/in_pcb.h b/sys/netinet/in_pcb.h
index 57cf15ca37fc..9e0618e87601 100644
--- a/sys/netinet/in_pcb.h
+++ b/sys/netinet/in_pcb.h
@@ -681,6 +681,7 @@ void in_pcbref(struct inpcb *);
bool in_pcbrele(struct inpcb *, inp_lookup_t);
bool in_pcbrele_rlocked(struct inpcb *);
bool in_pcbrele_wlocked(struct inpcb *);
+bool in_pcbrele_rlock(struct inpcb *inp);
typedef bool inp_match_t(const struct inpcb *, void *);
struct inpcb_iterator {
diff --git a/sys/netinet/tcp_subr.c b/sys/netinet/tcp_subr.c
index cd42a67294a6..db415f6bdf03 100644
--- a/sys/netinet/tcp_subr.c
+++ b/sys/netinet/tcp_subr.c
@@ -2720,9 +2720,15 @@ tcp_ktlslist_locked(SYSCTL_HANDLER_ARGS, bool export_keys)
ksr->snd_tag->sw->snd_tag_status_str !=
NULL) {
sz = SND_TAG_STATUS_MAXLEN;
- ksr->snd_tag->sw->snd_tag_status_str(
+ in_pcbref(inp);
+ INP_RUNLOCK(inp);
+ error = ksr->snd_tag->sw->
+ snd_tag_status_str(
ksr->snd_tag, NULL, &sz);
- len += sz;
+ if (in_pcbrele_rlock(inp))
+ return (EDEADLK);
+ if (error == 0)
+ len += sz;
}
}
kss = so->so_snd.sb_tls_info;
@@ -2739,9 +2745,15 @@ tcp_ktlslist_locked(SYSCTL_HANDLER_ARGS, bool export_keys)
kss->snd_tag->sw->snd_tag_status_str !=
NULL) {
sz = SND_TAG_STATUS_MAXLEN;
- kss->snd_tag->sw->snd_tag_status_str(
+ in_pcbref(inp);
+ INP_RUNLOCK(inp);
+ error = kss->snd_tag->sw->
+ snd_tag_status_str(
kss->snd_tag, NULL, &sz);
- len += sz;
+ if (in_pcbrele_rlock(inp))
+ return (EDEADLK);
+ if (error == 0)
+ len += sz;
}
}
if (p) {
@@ -2811,9 +2823,16 @@ tcp_ktlslist_locked(SYSCTL_HANDLER_ARGS, bool export_keys)
if (ksr->snd_tag != NULL &&
ksr->snd_tag->sw->snd_tag_status_str != NULL) {
sz = SND_TAG_STATUS_MAXLEN;
- ksr->snd_tag->sw->snd_tag_status_str(
+ in_pcbref(inp);
+ INP_RUNLOCK(inp);
+ error = ksr->snd_tag->sw->snd_tag_status_str(
ksr->snd_tag, buf + len, &sz);
- len += sz;
+ if (in_pcbrele_rlock(inp))
+ return (EDEADLK);
+ if (error == 0) {
+ xktls->rcv.drv_st_len = sz;
+ len += sz;
+ }
}
}
if (kss != NULL && kss->gen == xig.xig_gen) {
@@ -2828,9 +2847,16 @@ tcp_ktlslist_locked(SYSCTL_HANDLER_ARGS, bool export_keys)
if (kss->snd_tag != NULL &&
kss->snd_tag->sw->snd_tag_status_str != NULL) {
sz = SND_TAG_STATUS_MAXLEN;
- kss->snd_tag->sw->snd_tag_status_str(
+ in_pcbref(inp);
+ INP_RUNLOCK(inp);
+ error = kss->snd_tag->sw->snd_tag_status_str(
kss->snd_tag, buf + len, &sz);
- len += sz;
+ if (in_pcbrele_rlock(inp))
+ return (EDEADLK);
+ if (error == 0) {
+ xktls->snd.drv_st_len = sz;
+ len += sz;
+ }
}
}
len = roundup2(len, __alignof(*xktls));
@@ -2858,12 +2884,23 @@ tcp_ktlslist_locked(SYSCTL_HANDLER_ARGS, bool export_keys)
static int
tcp_ktlslist1(SYSCTL_HANDLER_ARGS, bool export_keys)
{
- int res;
-
- sx_xlock(&ktlslist_lock);
- res = tcp_ktlslist_locked(oidp, arg1, arg2, req, export_keys);
- sx_xunlock(&ktlslist_lock);
- return (res);
+ int repeats, error;
+
+ for (repeats = 0; repeats < 100; repeats++) {
+ if (sx_xlock_sig(&ktlslist_lock))
+ return (EINTR);
+ error = tcp_ktlslist_locked(oidp, arg1, arg2, req,
+ export_keys);
+ sx_xunlock(&ktlslist_lock);
+ if (error != EDEADLK)
+ break;
+ if (sig_intr() != 0) {
+ error = EINTR;
+ break;
+ }
+ req->oldidx = 0;
+ }
+ return (error);
}
static int
diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c
index 3ea561e63503..687b0d538666 100644
--- a/sys/netinet/tcp_usrreq.c
+++ b/sys/netinet/tcp_usrreq.c
@@ -1520,7 +1520,8 @@ tcp6_connect(struct tcpcb *tp, struct sockaddr_in6 *sin6, struct thread *td)
INP_WLOCK_ASSERT(inp);
if (__predict_false((so->so_state &
- (SS_ISCONNECTING | SS_ISCONNECTED)) != 0))
+ (SS_ISCONNECTING | SS_ISCONNECTED | SS_ISDISCONNECTING |
+ SS_ISDISCONNECTED)) != 0))
return (EISCONN);
if (__predict_false((so->so_options & SO_REUSEPORT_LB) != 0))
return (EOPNOTSUPP);
diff --git a/sys/netpfil/ipfilter/netinet/fil.c b/sys/netpfil/ipfilter/netinet/fil.c
index 2a75190a3ec7..2fcea433295f 100644
--- a/sys/netpfil/ipfilter/netinet/fil.c
+++ b/sys/netpfil/ipfilter/netinet/fil.c
@@ -437,7 +437,7 @@ static inline void
ipf_pr_ipv6hdr(fr_info_t *fin)
{
ip6_t *ip6 = (ip6_t *)fin->fin_ip;
- int p, go = 1, i, hdrcount;
+ int p, go = 1, i;
fr_ip_t *fi = &fin->fin_fi;
fin->fin_off = 0;
@@ -464,7 +464,6 @@ ipf_pr_ipv6hdr(fr_info_t *fin)
if (IN6_IS_ADDR_MULTICAST(&fi->fi_dst.in6))
fin->fin_flx |= FI_MULTICAST|FI_MBCAST;
- hdrcount = 0;
while (go && !(fin->fin_flx & FI_SHORT)) {
switch (p)
{
@@ -542,7 +541,6 @@ ipf_pr_ipv6hdr(fr_info_t *fin)
go = 0;
break;
}
- hdrcount++;
/*
* It is important to note that at this point, for the
@@ -2590,14 +2588,13 @@ ipf_scanlist(fr_info_t *fin, u_32_t pass)
/* functions called from the IPFilter "mainline" in ipf_check(). */
/* ------------------------------------------------------------------------ */
frentry_t *
-ipf_acctpkt(fr_info_t *fin, u_32_t *passp)
+ipf_acctpkt(fr_info_t *fin, u_32_t *passp __unused)
{
ipf_main_softc_t *softc = fin->fin_main_soft;
char group[FR_GROUPLEN];
frentry_t *fr, *frsave;
u_32_t pass, rulen;
- passp = passp;
fr = softc->ipf_acct[fin->fin_out][softc->ipf_active];
if (fr != NULL) {
@@ -4200,7 +4197,7 @@ ipf_getstat(ipf_main_softc_t *softc, friostat_t *fiop, int rev)
(rev / 10000) % 100,
(rev / 100) % 100);
#else
- rev = rev;
+ (void)rev; /* UNUSED */
(void) strncpy(fiop->f_version, ipfilter_version,
sizeof(fiop->f_version));
#endif
@@ -4408,13 +4405,12 @@ frrequest(ipf_main_softc_t *softc, int unit, ioctlcmd_t req, caddr_t data,
OP_ZERO /* zero statistics and counters */ }
addrem = OP_ADD;
frentry_t frd, *fp, *f, **fprev, **ftail;
- void *ptr, *uptr, *cptr;
+ void *ptr, *uptr;
u_int *p, *pp;
frgroup_t *fg;
char *group;
ptr = NULL;
- cptr = NULL;
fg = NULL;
fp = &frd;
if (makecopy != 0) {
@@ -4532,7 +4528,6 @@ frrequest(ipf_main_softc_t *softc, int unit, ioctlcmd_t req, caddr_t data,
}
ptr = NULL;
- cptr = NULL;
if (FR_ISACCOUNT(fp->fr_flags))
unit = IPL_LOGCOUNT;
@@ -7314,11 +7309,10 @@ ipf_resolvedest(ipf_main_softc_t *softc, char *base, frdest_t *fdp, int v)
/* for both IPv4 and IPv6 on the same physical NIC. */
/* ------------------------------------------------------------------------ */
void *
-ipf_resolvenic(ipf_main_softc_t *softc, char *name, int v)
+ipf_resolvenic(ipf_main_softc_t *softc __unused, char *name, int v)
{
void *nic;
- softc = softc; /* gcc -Wextra */
if (name[0] == '\0')
return (NULL);
@@ -7455,6 +7449,10 @@ ipf_token_find(ipf_main_softc_t *softc, int type, int uid, void *ptr)
{
ipftoken_t *it, *new;
+ KMALLOC(new, ipftoken_t *);
+ if (new != NULL)
+ bzero((char *)new, sizeof(*new));
+
WRITE_ENTER(&softc->ipf_tokens);
for (it = softc->ipf_token_head; it != NULL; it = it->ipt_next) {
if ((ptr == it->ipt_ctx) && (type == it->ipt_type) &&
@@ -7463,10 +7461,6 @@ ipf_token_find(ipf_main_softc_t *softc, int type, int uid, void *ptr)
}
if (it == NULL) {
- KMALLOC(new, ipftoken_t *);
- if (new != NULL)
- bzero((char *)new, sizeof(*new));
-
it = new;
new = NULL;
if (it == NULL) {
@@ -7478,6 +7472,11 @@ ipf_token_find(ipf_main_softc_t *softc, int type, int uid, void *ptr)
it->ipt_type = type;
it->ipt_ref = 1;
} else {
+ if (new != NULL) {
+ KFREE(new);
+ new = NULL;
+ }
+
if (it->ipt_complete > 0)
it = NULL;
else
diff --git a/sys/netpfil/ipfilter/netinet/ip_ftp_pxy.c b/sys/netpfil/ipfilter/netinet/ip_ftp_pxy.c
index 482e0b456ae5..8c9317c38326 100644
--- a/sys/netpfil/ipfilter/netinet/ip_ftp_pxy.c
+++ b/sys/netpfil/ipfilter/netinet/ip_ftp_pxy.c
@@ -219,7 +219,7 @@ ipf_p_ftp_soft_destroy(ipf_main_softc_t *softc, void *arg)
int
-ipf_p_ftp_new(void *arg, fr_info_t *fin, ap_session_t *aps, nat_t *nat)
+ipf_p_ftp_new(void *arg, fr_info_t *fin, ap_session_t *aps, nat_t *nat __unused)
{
ftpinfo_t *ftp;
ftpside_t *f;
@@ -228,8 +228,6 @@ ipf_p_ftp_new(void *arg, fr_info_t *fin, ap_session_t *aps, nat_t *nat)
if (ftp == NULL)
return (-1);
- nat = nat; /* LINT */
-
aps->aps_data = ftp;
aps->aps_psiz = sizeof(ftpinfo_t);
aps->aps_sport = htons(fin->fin_sport);
@@ -1715,7 +1713,9 @@ ipf_p_ftp_eprt4(ipf_ftp_softc_t *softf, fr_info_t *fin, ip_t *ip, nat_t *nat,
return (0);
if (c != delim)
return (0);
- addr |= addr;
+#if 0
+ addr |= (addr << 0);
+#endif
/*
* Get the port number
diff --git a/sys/netpfil/ipfilter/netinet/ip_htable.c b/sys/netpfil/ipfilter/netinet/ip_htable.c
index 22d427b87a71..91b375f80db1 100644
--- a/sys/netpfil/ipfilter/netinet/ip_htable.c
+++ b/sys/netpfil/ipfilter/netinet/ip_htable.c
@@ -343,6 +343,7 @@ ipf_htable_create(ipf_main_softc_t *softc, void *arg, iplookupop_t *op)
iph->iph_ref = 1;
iph->iph_list = NULL;
iph->iph_tail = &iph->iph_list;
+ iph->iph_unit = unit;
iph->iph_next = softh->ipf_htables[unit + 1];
iph->iph_pnext = &softh->ipf_htables[unit + 1];
if (softh->ipf_htables[unit + 1] != NULL)
@@ -603,7 +604,7 @@ ipf_htent_remove(ipf_main_softc_t *softc, void *arg, iphtable_t *iph,
switch (iph->iph_type & ~IPHASH_ANON)
{
case IPHASH_GROUPMAP :
- if (ipe->ipe_group != NULL)
+ if (ipe->ipe_ptr != NULL)
ipf_group_del(softc, ipe->ipe_ptr, NULL);
break;
@@ -973,7 +974,6 @@ ipf_htent_find(iphtable_t *iph, iphtent_t *ipeo)
{
iphtent_t ipe, *ent;
u_int hv;
- int bits;
bcopy((char *)ipeo, (char *)&ipe, sizeof(ipe));
ipe.ipe_addr.i6[0] &= ipe.ipe_mask.i6[0];
@@ -981,7 +981,6 @@ ipf_htent_find(iphtable_t *iph, iphtent_t *ipeo)
ipe.ipe_addr.i6[2] &= ipe.ipe_mask.i6[2];
ipe.ipe_addr.i6[3] &= ipe.ipe_mask.i6[3];
if (ipe.ipe_family == AF_INET) {
- bits = count4bits(ipe.ipe_mask.in4_addr);
ipe.ipe_addr.i6[1] = 0;
ipe.ipe_addr.i6[2] = 0;
ipe.ipe_addr.i6[3] = 0;
@@ -993,7 +992,6 @@ ipf_htent_find(iphtable_t *iph, iphtent_t *ipeo)
} else
#ifdef USE_INET6
if (ipe.ipe_family == AF_INET6) {
- bits = count6bits(ipe.ipe_mask.i6);
hv = IPE_V6_HASH_FN(ipe.ipe_addr.i6,
ipe.ipe_mask.i6, iph->iph_size);
} else
diff --git a/sys/netpfil/ipfilter/netinet/ip_ipsec_pxy.c b/sys/netpfil/ipfilter/netinet/ip_ipsec_pxy.c
index c6e4be17e22e..d5103c2944dc 100644
--- a/sys/netpfil/ipfilter/netinet/ip_ipsec_pxy.c
+++ b/sys/netpfil/ipfilter/netinet/ip_ipsec_pxy.c
@@ -341,15 +341,13 @@ ipf_p_ipsec_inout(void *arg, fr_info_t *fin, ap_session_t *aps, nat_t *nat)
* UDP/TCP port numbers).
*/
int
-ipf_p_ipsec_match(fr_info_t *fin, ap_session_t *aps, nat_t *nat)
+ipf_p_ipsec_match(fr_info_t *fin, ap_session_t *aps, nat_t *nat __unused)
{
ipsec_pxy_t *ipsec;
u_32_t cookies[4];
mb_t *m;
int off;
- nat = nat; /* LINT */
-
if ((fin->fin_dlen < sizeof(cookies)) || (fin->fin_flx & FI_FRAG))
return (-1);
diff --git a/sys/netpfil/ipfilter/netinet/ip_irc_pxy.c b/sys/netpfil/ipfilter/netinet/ip_irc_pxy.c
index 026459299efd..aa9e84be19ed 100644
--- a/sys/netpfil/ipfilter/netinet/ip_irc_pxy.c
+++ b/sys/netpfil/ipfilter/netinet/ip_irc_pxy.c
@@ -221,7 +221,7 @@ ipf_p_irc_complete(ircinfo_t *ircp, char *buf, size_t len)
int
-ipf_p_irc_new(void *arg, fr_info_t *fin, ap_session_t *aps, nat_t *nat)
+ipf_p_irc_new(void *arg, fr_info_t *fin, ap_session_t *aps, nat_t *nat __unused)
{
ircinfo_t *irc;
@@ -232,8 +232,6 @@ ipf_p_irc_new(void *arg, fr_info_t *fin, ap_session_t *aps, nat_t *nat)
if (irc == NULL)
return (-1);
- nat = nat; /* LINT */
-
aps->aps_data = irc;
aps->aps_psiz = sizeof(ircinfo_t);
@@ -422,8 +420,7 @@ ipf_p_irc_send(fr_info_t *fin, nat_t *nat)
int
-ipf_p_irc_out(void *arg, fr_info_t *fin, ap_session_t *aps, nat_t *nat)
+ipf_p_irc_out(void *arg, fr_info_t *fin, ap_session_t *aps __unused, nat_t *nat)
{
- aps = aps; /* LINT */
return (ipf_p_irc_send(fin, nat));
}
diff --git a/sys/netpfil/ipfilter/netinet/ip_lookup.c b/sys/netpfil/ipfilter/netinet/ip_lookup.c
index b46d1b875003..a52dbef00166 100644
--- a/sys/netpfil/ipfilter/netinet/ip_lookup.c
+++ b/sys/netpfil/ipfilter/netinet/ip_lookup.c
@@ -230,13 +230,11 @@ ipf_lookup_soft_destroy(ipf_main_softc_t *softc, void *arg)
/* ------------------------------------------------------------------------ */
int
ipf_lookup_ioctl(ipf_main_softc_t *softc, caddr_t data, ioctlcmd_t cmd,
- int mode, int uid, void *ctx)
+ int mode __unused, int uid, void *ctx)
{
int err;
SPL_INT(s);
- mode = mode; /* LINT */
-
SPL_NET(s);
switch (cmd)
diff --git a/sys/netpfil/ipfilter/netinet/ip_nat.c b/sys/netpfil/ipfilter/netinet/ip_nat.c
index a13c6129a287..972511f43bd5 100644
--- a/sys/netpfil/ipfilter/netinet/ip_nat.c
+++ b/sys/netpfil/ipfilter/netinet/ip_nat.c
@@ -3224,13 +3224,10 @@ ipf_nat_finalise(fr_info_t *fin, nat_t *nat)
ipf_nat_softc_t *softn = softc->ipf_nat_soft;
u_32_t sum1, sum2, sumd;
frentry_t *fr;
- u_32_t flags;
#if SOLARIS && defined(_KERNEL) && defined(ICK_M_CTL_MAGIC)
qpktinfo_t *qpi = fin->fin_qpi;
#endif
- flags = nat->nat_flags;
-
switch (nat->nat_pr[0])
{
case IPPROTO_ICMP :
@@ -3538,8 +3535,8 @@ ipf_nat_icmperrorlookup(fr_info_t *fin, int dir)
{
ipf_main_softc_t *softc = fin->fin_main_soft;
ipf_nat_softc_t *softn = softc->ipf_nat_soft;
- int flags = 0, type, minlen;
- icmphdr_t *icmp, *orgicmp;
+ int flags = 0, minlen;
+ icmphdr_t *orgicmp;
nat_stat_side_t *nside;
tcphdr_t *tcp = NULL;
u_short data[2];
@@ -3547,8 +3544,6 @@ ipf_nat_icmperrorlookup(fr_info_t *fin, int dir)
ip_t *oip;
u_int p;
- icmp = fin->fin_dp;
- type = icmp->icmp_type;
nside = &softn->ipf_nat_stats.ns_side[fin->fin_out];
/*
* Does it at least have the return (basic) IP header ?
@@ -3999,9 +3994,7 @@ ipf_nat_inlookup(fr_info_t *fin, u_int flags, u_int p,
ipf_main_softc_t *softc = fin->fin_main_soft;
ipf_nat_softc_t *softn = softc->ipf_nat_soft;
u_short sport, dport;
- grehdr_t *gre;
ipnat_t *ipn;
- u_int sflags;
nat_t *nat;
int nflags;
u_32_t dst;
@@ -4009,9 +4002,7 @@ ipf_nat_inlookup(fr_info_t *fin, u_int flags, u_int p,
u_int hv, rhv;
ifp = fin->fin_ifp;
- gre = NULL;
dst = mapdst.s_addr;
- sflags = flags & NAT_TCPUDPICMP;
switch (p)
{
@@ -4330,14 +4321,12 @@ ipf_nat_outlookup(fr_info_t *fin, u_int flags, u_int p,
ipf_main_softc_t *softc = fin->fin_main_soft;
ipf_nat_softc_t *softn = softc->ipf_nat_soft;
u_short sport, dport;
- u_int sflags;
ipnat_t *ipn;
nat_t *nat;
void *ifp;
u_int hv;
ifp = fin->fin_ifp;
- sflags = flags & IPN_TCPUDPICMP;
switch (p)
{
@@ -4756,7 +4745,6 @@ ipf_nat_checkout(fr_info_t *fin, u_32_t *passp)
struct ifnet *ifp, *sifp;
ipf_main_softc_t *softc;
ipf_nat_softc_t *softn;
- icmphdr_t *icmp = NULL;
tcphdr_t *tcp = NULL;
int rval, natfailed;
u_int nflags = 0;
@@ -4802,8 +4790,6 @@ ipf_nat_checkout(fr_info_t *fin, u_32_t *passp)
nflags = IPN_UDP;
break;
case IPPROTO_ICMP :
- icmp = fin->fin_dp;
-
/*
* This is an incoming packet, so the destination is
* the icmp_id and the source port equals 0
@@ -5463,7 +5449,10 @@ ipf_nat_in(fr_info_t *fin, nat_t *nat, int natadd, u_32_t nflags)
{
ipf_main_softc_t *softc = fin->fin_main_soft;
ipf_nat_softc_t *softn = softc->ipf_nat_soft;
- u_32_t sumd, ipsumd, sum1, sum2;
+ u_32_t sumd, sum1, sum2;
+#if !defined(_KERNEL) || SOLARIS
+ u_32_t ipsumd;
+#endif
icmphdr_t *icmp;
tcphdr_t *tcp;
ipnat_t *np;
@@ -5499,7 +5488,9 @@ ipf_nat_in(fr_info_t *fin, nat_t *nat, int natadd, u_32_t nflags)
ipf_sync_update(softc, SMC_NAT, fin, nat->nat_sync);
+#if !defined(_KERNEL) || SOLARIS
ipsumd = nat->nat_ipsumd;
+#endif
/*
* Fix up checksums, not by recalculating them, but
* simply computing adjustments.
@@ -5521,7 +5512,9 @@ ipf_nat_in(fr_info_t *fin, nat_t *nat, int natadd, u_32_t nflags)
sum1 = nat->nat_osrcaddr;
sum2 = nat->nat_nsrcaddr;
CALC_SUMD(sum1, sum2, sumd);
+#if !defined(_KERNEL) || SOLARIS
ipsumd -= sumd;
+#endif
}
fin->fin_ip->ip_dst = nat->nat_ndstip;
fin->fin_daddr = nat->nat_ndstaddr;
@@ -5538,7 +5531,9 @@ ipf_nat_in(fr_info_t *fin, nat_t *nat, int natadd, u_32_t nflags)
sum1 = nat->nat_odstaddr;
sum2 = nat->nat_ndstaddr;
CALC_SUMD(sum1, sum2, sumd);
+#if !defined(_KERNEL) || SOLARIS
ipsumd -= sumd;
+#endif
}
fin->fin_ip->ip_dst = nat->nat_osrcip;
fin->fin_daddr = nat->nat_osrcaddr;
@@ -7352,30 +7347,18 @@ ipf_nat_nextaddr(fr_info_t *fin, nat_addr_t *na, u_32_t *old, u_32_t *dst)
{
ipf_main_softc_t *softc = fin->fin_main_soft;
ipf_nat_softc_t *softn = softc->ipf_nat_soft;
- u_32_t amin, amax, new;
+ u_32_t new;
i6addr_t newip;
int error;
new = 0;
- amin = na->na_addr[0].in4.s_addr;
switch (na->na_atype)
{
case FRI_RANGE :
- amax = na->na_addr[1].in4.s_addr;
- break;
-
case FRI_NETMASKED :
case FRI_DYNAMIC :
case FRI_NORMAL :
- /*
- * Compute the maximum address by adding the inverse of the
- * netmask to the minimum address.
- */
- amax = ~na->na_addr[1].in4.s_addr;
- amax |= amin;
- break;
-
case FRI_LOOKUP :
break;
diff --git a/sys/netpfil/ipfilter/netinet/ip_nat6.c b/sys/netpfil/ipfilter/netinet/ip_nat6.c
index dbe19c40c2f2..6d5913177b90 100644
--- a/sys/netpfil/ipfilter/netinet/ip_nat6.c
+++ b/sys/netpfil/ipfilter/netinet/ip_nat6.c
@@ -1130,9 +1130,6 @@ ipf_nat6_finalise(fr_info_t *fin, nat_t *nat)
ipf_nat_softc_t *softn = softc->ipf_nat_soft;
u_32_t sum1, sum2, sumd;
frentry_t *fr;
- u_32_t flags;
-
- flags = nat->nat_flags;
switch (fin->fin_p)
{
@@ -1355,8 +1352,8 @@ ipf_nat6_icmperrorlookup(fr_info_t *fin, int dir)
{
ipf_main_softc_t *softc = fin->fin_main_soft;
ipf_nat_softc_t *softn = softc->ipf_nat_soft;
- struct icmp6_hdr *icmp6, *orgicmp;
- int flags = 0, type, minlen;
+ struct icmp6_hdr *orgicmp;
+ int flags = 0, minlen;
nat_stat_side_t *nside;
tcphdr_t *tcp = NULL;
u_short data[2];
@@ -1365,8 +1362,6 @@ ipf_nat6_icmperrorlookup(fr_info_t *fin, int dir)
u_int p;
minlen = 40;
- icmp6 = fin->fin_dp;
- type = icmp6->icmp6_type;
nside = &softn->ipf_nat_stats.ns_side6[fin->fin_out];
/*
* Does it at least have the return (basic) IP header ?
@@ -1500,9 +1495,8 @@ ipf_nat6_ip6subtract(i6addr_t *ip1, i6addr_t *ip2)
i6addr_t l1, l2, d;
u_short *s1, *s2, *ds;
u_32_t r;
- int i, neg;
+ int i;
- neg = 0;
l1 = *ip1;
l2 = *ip2;
s1 = (u_short *)&l1;
@@ -1519,7 +1513,6 @@ ipf_nat6_ip6subtract(i6addr_t *ip1, i6addr_t *ip2)
}
if (s2[0] > s1[0]) {
ds[0] = s2[0] + 0x10000 - s1[0];
- neg = 1;
} else {
ds[0] = s2[0] - s1[0];
}
@@ -1869,9 +1862,9 @@ ipf_nat6_inlookup(fr_info_t *fin, u_int flags, u_int p,
ipf_main_softc_t *softc = fin->fin_main_soft;
ipf_nat_softc_t *softn = softc->ipf_nat_soft;
u_short sport, dport;
- grehdr_t *gre;
+#ifdef IPF_V6_PROXIES
ipnat_t *ipn;
- u_int sflags;
+#endif
nat_t *nat;
int nflags;
i6addr_t dst;
@@ -1881,10 +1874,7 @@ ipf_nat6_inlookup(fr_info_t *fin, u_int flags, u_int p,
ifp = fin->fin_ifp;
sport = 0;
dport = 0;
- gre = NULL;
dst.in6 = *mapdst;
- sflags = flags & NAT_TCPUDPICMP;
-
switch (p)
{
case IPPROTO_TCP :
@@ -1962,8 +1952,8 @@ ipf_nat6_inlookup(fr_info_t *fin, u_int flags, u_int p,
if ((nat->nat_flags & IPN_TCPUDP) != 0) {
- ipn = nat->nat_ptr;
#ifdef IPF_V6_PROXIES
+ ipn = nat->nat_ptr;
if ((ipn != NULL) && (nat->nat_aps != NULL))
if (appr_match(fin, nat) != 0)
continue;
@@ -2192,14 +2182,14 @@ ipf_nat6_outlookup(fr_info_t *fin, u_int flags, u_int p,
ipf_main_softc_t *softc = fin->fin_main_soft;
ipf_nat_softc_t *softn = softc->ipf_nat_soft;
u_short sport, dport;
- u_int sflags;
+#ifdef IPF_V6_PROXIES
ipnat_t *ipn;
+#endif
nat_t *nat;
void *ifp;
u_int hv;
ifp = fin->fin_ifp;
- sflags = flags & IPN_TCPUDPICMP;
sport = 0;
dport = 0;
@@ -2280,8 +2270,8 @@ ipf_nat6_outlookup(fr_info_t *fin, u_int flags, u_int p,
break;
}
- ipn = nat->nat_ptr;
#ifdef IPF_V6_PROXIES
+ ipn = nat->nat_ptr;
if ((ipn != NULL) && (nat->nat_aps != NULL))
if (appr_match(fin, nat) != 0)
continue;
@@ -2568,7 +2558,6 @@ ipf_nat6_checkout(fr_info_t *fin, u_32_t *passp)
ipf_nat_softc_t *softn = softc->ipf_nat_soft;
struct icmp6_hdr *icmp6 = NULL;
struct ifnet *ifp, *sifp;
- tcphdr_t *tcp = NULL;
int rval, natfailed;
ipnat_t *np = NULL;
u_int nflags = 0;
@@ -2621,9 +2610,6 @@ ipf_nat6_checkout(fr_info_t *fin, u_32_t *passp)
default :
break;
}
-
- if ((nflags & IPN_TCPUDP))
- tcp = fin->fin_dp;
}
ipa = fin->fin_src6;
@@ -2965,7 +2951,9 @@ ipf_nat6_checkin(fr_info_t *fin, u_32_t *passp)
int rval, natfailed;
struct ifnet *ifp;
i6addr_t ipa, iph;
- tcphdr_t *tcp;
+#ifdef IPF_V6_PROXIES
+ tcphdr_t *tcp = NULL;
+#endif
u_short dport;
ipnat_t *np;
nat_t *nat;
@@ -2973,7 +2961,6 @@ ipf_nat6_checkin(fr_info_t *fin, u_32_t *passp)
if (softn->ipf_nat_stats.ns_rules == 0 || softn->ipf_nat_lock != 0)
return (0);
- tcp = NULL;
icmp6 = NULL;
dport = 0;
natadd = 1;
@@ -3014,7 +3001,9 @@ ipf_nat6_checkin(fr_info_t *fin, u_32_t *passp)
}
if ((nflags & IPN_TCPUDP)) {
+#ifdef IPF_V6_PROXIES
tcp = fin->fin_dp;
+#endif
dport = fin->fin_data[1];
}
}
@@ -3802,32 +3791,19 @@ ipf_nat6_nextaddr(fr_info_t *fin, nat_addr_t *na, i6addr_t *old, i6addr_t *dst)
ipf_main_softc_t *softc = fin->fin_main_soft;
ipf_nat_softc_t *softn = softc->ipf_nat_soft;
i6addr_t newip, new;
- u_32_t amin, amax;
int error;
new.i6[0] = 0;
new.i6[1] = 0;
new.i6[2] = 0;
new.i6[3] = 0;
- amin = na->na_addr[0].in4.s_addr;
switch (na->na_atype)
{
case FRI_RANGE :
- amax = na->na_addr[1].in4.s_addr;
- break;
-
case FRI_NETMASKED :
case FRI_DYNAMIC :
case FRI_NORMAL :
- /*
- * Compute the maximum address by adding the inverse of the
- * netmask to the minimum address.
- */
- amax = ~na->na_addr[1].in4.s_addr;
- amax |= amin;
- break;
-
case FRI_LOOKUP :
break;
diff --git a/sys/netpfil/ipfilter/netinet/ip_netbios_pxy.c b/sys/netpfil/ipfilter/netinet/ip_netbios_pxy.c
index 2ad642adfbcd..f9c1ab50b8a2 100644
--- a/sys/netpfil/ipfilter/netinet/ip_netbios_pxy.c
+++ b/sys/netpfil/ipfilter/netinet/ip_netbios_pxy.c
@@ -67,7 +67,7 @@ ipf_p_netbios_main_unload(void)
int
-ipf_p_netbios_out(void *arg, fr_info_t *fin, ap_session_t *aps, nat_t *nat)
+ipf_p_netbios_out(void *arg, fr_info_t *fin, ap_session_t *aps __unused, nat_t *nat __unused)
{
char dgmbuf[6];
int off, dlen;
@@ -75,9 +75,6 @@ ipf_p_netbios_out(void *arg, fr_info_t *fin, ap_session_t *aps, nat_t *nat)
ip_t *ip;
mb_t *m;
- aps = aps; /* LINT */
- nat = nat; /* LINT */
-
m = fin->fin_m;
dlen = fin->fin_dlen - sizeof(*udp);
/*
diff --git a/sys/netpfil/ipfilter/netinet/ip_pptp_pxy.c b/sys/netpfil/ipfilter/netinet/ip_pptp_pxy.c
index 0ac19b067d2d..dc4c67dc14f0 100644
--- a/sys/netpfil/ipfilter/netinet/ip_pptp_pxy.c
+++ b/sys/netpfil/ipfilter/netinet/ip_pptp_pxy.c
@@ -281,7 +281,6 @@ ipf_p_pptp_nextmessage(fr_info_t *fin, nat_t *nat, pptp_pxy_t *pptp, int rev)
tcphdr_t *tcp;
int dlen, off;
u_short len;
- char *msg;
tcp = fin->fin_dp;
dlen = fin->fin_dlen - (TCP_OFF(tcp) << 2);
@@ -310,8 +309,6 @@ ipf_p_pptp_nextmessage(fr_info_t *fin, nat_t *nat, pptp_pxy_t *pptp, int rev)
return (-1);
}
- msg = (char *)fin->fin_dp + (TCP_OFF(tcp) << 2);
-
while (dlen > 0) {
off += pptps->pptps_bytes;
if (pptps->pptps_gothdr == 0) {
@@ -337,7 +334,6 @@ ipf_p_pptp_nextmessage(fr_info_t *fin, nat_t *nat, pptp_pxy_t *pptp, int rev)
}
}
dlen -= len;
- msg += len;
off += len;
pptps->pptps_gothdr = 1;
@@ -381,7 +377,6 @@ ipf_p_pptp_nextmessage(fr_info_t *fin, nat_t *nat, pptp_pxy_t *pptp, int rev)
pptps->pptps_len = 0;
start += len;
- msg += len;
dlen -= len;
}
diff --git a/sys/netpfil/ipfilter/netinet/ip_proxy.c b/sys/netpfil/ipfilter/netinet/ip_proxy.c
index 9785fc37d3da..9fb6dbd2a9e1 100644
--- a/sys/netpfil/ipfilter/netinet/ip_proxy.c
+++ b/sys/netpfil/ipfilter/netinet/ip_proxy.c
@@ -679,14 +679,12 @@ ipf_proxy_ok(fr_info_t *fin, tcphdr_t *tcp, ipnat_t *np)
/* ------------------------------------------------------------------------ */
int
ipf_proxy_ioctl(ipf_main_softc_t *softc, caddr_t data, ioctlcmd_t cmd,
- int mode, void *ctx)
+ int mode __unused, void *ctx)
{
ap_ctl_t ctl;
caddr_t ptr;
int error;
- mode = mode; /* LINT */
-
switch (cmd)
{
case SIOCPROXY :
diff --git a/sys/netpfil/ipfilter/netinet/ip_raudio_pxy.c b/sys/netpfil/ipfilter/netinet/ip_raudio_pxy.c
index 2cfaaa58200f..94f0e3ada707 100644
--- a/sys/netpfil/ipfilter/netinet/ip_raudio_pxy.c
+++ b/sys/netpfil/ipfilter/netinet/ip_raudio_pxy.c
@@ -49,12 +49,10 @@ ipf_p_raudio_main_unload(void)
* Setup for a new proxy to handle Real Audio.
*/
int
-ipf_p_raudio_new(void *arg, fr_info_t *fin, ap_session_t *aps, nat_t *nat)
+ipf_p_raudio_new(void *arg, fr_info_t *fin, ap_session_t *aps, nat_t *nat __unused)
{
raudio_t *rap;
- nat = nat; /* LINT */
-
if (fin->fin_v != 4)
return (-1);
@@ -72,7 +70,7 @@ ipf_p_raudio_new(void *arg, fr_info_t *fin, ap_session_t *aps, nat_t *nat)
int
-ipf_p_raudio_out(void *arg, fr_info_t *fin, ap_session_t *aps, nat_t *nat)
+ipf_p_raudio_out(void *arg, fr_info_t *fin, ap_session_t *aps, nat_t *nat __unused)
{
raudio_t *rap = aps->aps_data;
unsigned char membuf[512 + 1], *s;
@@ -82,8 +80,6 @@ ipf_p_raudio_out(void *arg, fr_info_t *fin, ap_session_t *aps, nat_t *nat)
int len = 0;
mb_t *m;
- nat = nat; /* LINT */
-
/*
* If we've already processed the start messages, then nothing left
* for the proxy to do.
diff --git a/sys/netpfil/ipfilter/netinet/ip_rcmd_pxy.c b/sys/netpfil/ipfilter/netinet/ip_rcmd_pxy.c
index 778f14f442de..b85794e75499 100644
--- a/sys/netpfil/ipfilter/netinet/ip_rcmd_pxy.c
+++ b/sys/netpfil/ipfilter/netinet/ip_rcmd_pxy.c
@@ -63,18 +63,12 @@ ipf_p_rcmd_main_unload(void)
* Setup for a new RCMD proxy.
*/
int
-ipf_p_rcmd_new(void *arg, fr_info_t *fin, ap_session_t *aps, nat_t *nat)
+ipf_p_rcmd_new(void *arg, fr_info_t *fin __unused, ap_session_t *aps, nat_t *nat)
{
tcphdr_t *tcp = (tcphdr_t *)fin->fin_dp;
rcmdinfo_t *rc;
ipnat_t *ipn;
- ipnat_t *np;
- int size;
- fin = fin; /* LINT */
-
- np = nat->nat_ptr;
- size = np->in_size;
KMALLOC(rc, rcmdinfo_t *);
if (rc == NULL) {
#ifdef IP_RCMD_PROXY_DEBUG
diff --git a/sys/netpfil/ipfilter/netinet/ip_rpcb_pxy.c b/sys/netpfil/ipfilter/netinet/ip_rpcb_pxy.c
index f8f4d2d325e1..c608f84d7b3b 100644
--- a/sys/netpfil/ipfilter/netinet/ip_rpcb_pxy.c
+++ b/sys/netpfil/ipfilter/netinet/ip_rpcb_pxy.c
@@ -144,12 +144,10 @@ ipf_p_rpcb_main_unload(void)
/* Allocate resources for per-session proxy structures. */
/* -------------------------------------------------------------------- */
int
-ipf_p_rpcb_new(void *arg, fr_info_t *fin, ap_session_t *aps, nat_t *nat)
+ipf_p_rpcb_new(void *arg, fr_info_t *fin, ap_session_t *aps, nat_t *nat __unused)
{
rpcb_session_t *rs;
- nat = nat; /* LINT */
-
if (fin->fin_v != 4)
return (-1);
@@ -1023,10 +1021,8 @@ ipf_p_rpcb_lookup(rpcb_session_t *rs, u_32_t xid)
/* Free the RPCB transaction record rx from the chain of entries. */
/* -------------------------------------------------------------------- */
static void
-ipf_p_rpcb_deref(rpcb_session_t *rs, rpcb_xact_t *rx)
+ipf_p_rpcb_deref(rpcb_session_t *rs __unused, rpcb_xact_t *rx)
{
- rs = rs; /* LINT */
-
if (rx == NULL)
return;
diff --git a/sys/netpfil/ipfilter/netinet/ip_state.c b/sys/netpfil/ipfilter/netinet/ip_state.c
index 8fe11e3f1215..36fdf23cd062 100644
--- a/sys/netpfil/ipfilter/netinet/ip_state.c
+++ b/sys/netpfil/ipfilter/netinet/ip_state.c
@@ -883,7 +883,7 @@ ipf_state_putent(ipf_main_softc_t *softc, ipf_state_softc_t *softs,
{
ipstate_t *is, *isn;
ipstate_save_t ips;
- int error, out, i;
+ int error, i;
frentry_t *fr;
char *name;
@@ -929,7 +929,6 @@ ipf_state_putent(ipf_main_softc_t *softc, ipf_state_softc_t *softs,
return (ENOMEM);
}
bcopy((char *)&ips.ips_fr, (char *)fr, sizeof(*fr));
- out = fr->fr_flags & FR_OUTQUE ? 1 : 0;
isn->is_rule = fr;
ips.ips_is.is_rule = fr;
MUTEX_NUKE(&fr->fr_lock);
@@ -2207,20 +2206,6 @@ ipf_state_tcpinwindow(fr_info_t *fin, tcpdata_t *fdata, tcpdata_t *tdata,
(ackskew >= -1) && (ackskew <= 1)) {
inseq = 1;
} else if (!(flags & IS_TCPFSM)) {
- int i;
-
- i = (fin->fin_rev << 1) + fin->fin_out;
-
-#if 0
- if (is_pkts[i]0 == 0) {
- /*
- * Picking up a connection in the middle, the "next"
- * packet seen from a direction that is new should be
- * accepted, even if it appears out of sequence.
- */
- inseq = 1;
- } else
-#endif
if (!(fdata->td_winflags &
(TCP_WSCALE_SEEN|TCP_WSCALE_FIRST))) {
/*
@@ -2616,7 +2601,7 @@ ipf_checkicmpmatchingstate(fr_info_t *fin)
icmphdr_t *icmp;
fr_info_t ofin;
tcphdr_t *tcp;
- int type, len;
+ int len;
u_char pr;
ip_t *oip;
u_int hv;
@@ -2634,7 +2619,6 @@ ipf_checkicmpmatchingstate(fr_info_t *fin)
return (NULL);
}
ic = fin->fin_dp;
- type = ic->icmp_type;
oip = (ip_t *)((char *)ic + ICMPERR_ICMPHLEN);
/*
@@ -4362,7 +4346,6 @@ ipf_checkicmp6matchingstate(fr_info_t *fin)
ip6_t *oip6;
u_char pr;
u_int hv;
- int type;
/*
* Does it at least have the return (basic) IP header ?
@@ -4377,7 +4360,6 @@ ipf_checkicmp6matchingstate(fr_info_t *fin)
}
ic6 = fin->fin_dp;
- type = ic6->icmp6_type;
oip6 = (ip6_t *)((char *)ic6 + ICMPERR_ICMPHLEN);
if (fin->fin_plen < sizeof(*oip6)) {
diff --git a/sys/netpfil/ipfilter/netinet/ip_tftp_pxy.c b/sys/netpfil/ipfilter/netinet/ip_tftp_pxy.c
index d81de100120b..3c737b38aacc 100644
--- a/sys/netpfil/ipfilter/netinet/ip_tftp_pxy.c
+++ b/sys/netpfil/ipfilter/netinet/ip_tftp_pxy.c
@@ -151,7 +151,7 @@ ipf_p_tftp_in(void *arg, fr_info_t *fin, ap_session_t *aps, nat_t *nat)
int
-ipf_p_tftp_new(void *arg, fr_info_t *fin, ap_session_t *aps, nat_t *nat)
+ipf_p_tftp_new(void *arg, fr_info_t *fin __unused, ap_session_t *aps, nat_t *nat)
{
udphdr_t *udp;
tftpinfo_t *ti;
@@ -159,8 +159,6 @@ ipf_p_tftp_new(void *arg, fr_info_t *fin, ap_session_t *aps, nat_t *nat)
ipnat_t *np;
int size;
- fin = fin; /* LINT */
-
np = nat->nat_ptr;
size = np->in_size;
diff --git a/sys/netpfil/ipfilter/netinet/ipf_rb.h b/sys/netpfil/ipfilter/netinet/ipf_rb.h
index e047c7f44a4a..334311502aab 100644
--- a/sys/netpfil/ipfilter/netinet/ipf_rb.h
+++ b/sys/netpfil/ipfilter/netinet/ipf_rb.h
@@ -305,13 +305,11 @@ _n##_rb_walktree(struct _n##_rb_head *head, _n##_rb_walker_t func, void *arg)\
_t *prev; \
_t *next; \
_t *node = head->top._f.right; \
- _t *base; \
\
while (node != &_n##_rb_zero) \
node = node->_f.left; \
\
for (;;) { \
- base = node; \
prev = node; \
while ((node->_f.parent->_f.right == node) && \
(node != &_n##_rb_zero)) { \
diff --git a/sys/netpfil/pf/if_pflog.c b/sys/netpfil/pf/if_pflog.c
index 6a87ea2471cb..0a84f9d680ac 100644
--- a/sys/netpfil/pf/if_pflog.c
+++ b/sys/netpfil/pf/if_pflog.c
@@ -289,7 +289,7 @@ pflog_packet(uint8_t action, u_int8_t reason,
if (pd->lookup.done > 0)
hdr.uid = pd->lookup.uid;
else
- hdr.uid = UID_MAX;
+ hdr.uid = -1;
hdr.pid = NO_PID;
hdr.rule_uid = rm->cuid;
hdr.rule_pid = rm->cpid;
diff --git a/sys/netpfil/pf/if_pfsync.c b/sys/netpfil/pf/if_pfsync.c
index fdedb9424117..2391edaf1a5a 100644
--- a/sys/netpfil/pf/if_pfsync.c
+++ b/sys/netpfil/pf/if_pfsync.c
@@ -763,6 +763,10 @@ pfsync_state_import(union pfsync_state_union *sp, int flags, int msg_version)
__func__, msg_version);
}
+ if (! (st->act.rtableid == -1 ||
+ (st->act.rtableid >= 0 && st->act.rtableid < rt_numfibs)))
+ goto cleanup;
+
st->id = sp->pfs_1301.id;
st->creatorid = sp->pfs_1301.creatorid;
pf_state_peer_ntoh(&sp->pfs_1301.src, &st->src);
@@ -1083,7 +1087,7 @@ pfsync_in_ins(struct mbuf *m, int offset, int count, int flags, int action)
msg_version = PFSYNC_MSG_VERSION_1400;
break;
default:
- V_pfsyncstats.pfsyncs_badact++;
+ V_pfsyncstats.pfsyncs_badver++;
return (-1);
}
@@ -1110,9 +1114,8 @@ pfsync_in_ins(struct mbuf *m, int offset, int count, int flags, int action)
continue;
}
- if (pfsync_state_import(sp, flags, msg_version) == ENOMEM)
- /* Drop out, but process the rest of the actions. */
- break;
+ if (pfsync_state_import(sp, flags, msg_version) != 0)
+ V_pfsyncstats.pfsyncs_badact++;
}
return (total_len);
diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c
index 127b29320acb..d5f01e5c4956 100644
--- a/sys/netpfil/pf/pf.c
+++ b/sys/netpfil/pf/pf.c
@@ -4579,7 +4579,7 @@ pf_match_port(u_int8_t op, u_int16_t a1, u_int16_t a2, u_int16_t p)
static int
pf_match_uid(u_int8_t op, uid_t a1, uid_t a2, uid_t u)
{
- if (u == UID_MAX && op != PF_OP_EQ && op != PF_OP_NE)
+ if (u == -1 && op != PF_OP_EQ && op != PF_OP_NE)
return (0);
return (pf_match(op, a1, a2, u));
}
@@ -4587,7 +4587,7 @@ pf_match_uid(u_int8_t op, uid_t a1, uid_t a2, uid_t u)
static int
pf_match_gid(u_int8_t op, gid_t a1, gid_t a2, gid_t g)
{
- if (g == GID_MAX && op != PF_OP_EQ && op != PF_OP_NE)
+ if (g == -1 && op != PF_OP_EQ && op != PF_OP_NE)
return (0);
return (pf_match(op, a1, a2, g));
}
@@ -4914,8 +4914,8 @@ pf_socket_lookup(struct pf_pdesc *pd)
struct inpcbinfo *pi;
struct inpcb *inp;
- pd->lookup.uid = UID_MAX;
- pd->lookup.gid = GID_MAX;
+ pd->lookup.uid = -1;
+ pd->lookup.gid = -1;
switch (pd->proto) {
case IPPROTO_TCP:
diff --git a/sys/netpfil/pf/pf_ioctl.c b/sys/netpfil/pf/pf_ioctl.c
index 357b2be194a5..c96741023db9 100644
--- a/sys/netpfil/pf/pf_ioctl.c
+++ b/sys/netpfil/pf/pf_ioctl.c
@@ -2155,51 +2155,51 @@ pf_ioctl_addrule(struct pf_krule *rule, uint32_t ticket,
rule->rcv_kif = NULL;
if (rule->rtableid > 0 && rule->rtableid >= rt_numfibs)
- error = EBUSY;
+ ERROUT(EBUSY);
#ifdef ALTQ
/* set queue IDs */
if (rule->qname[0] != 0) {
if ((rule->qid = pf_qname2qid(rule->qname)) == 0)
- error = EBUSY;
+ ERROUT(EBUSY);
else if (rule->pqname[0] != 0) {
if ((rule->pqid =
pf_qname2qid(rule->pqname)) == 0)
- error = EBUSY;
+ ERROUT(EBUSY);
} else
rule->pqid = rule->qid;
}
#endif
if (rule->tagname[0])
if ((rule->tag = pf_tagname2tag(rule->tagname)) == 0)
- error = EBUSY;
+ ERROUT(EBUSY);
if (rule->match_tagname[0])
if ((rule->match_tag =
pf_tagname2tag(rule->match_tagname)) == 0)
- error = EBUSY;
+ ERROUT(EBUSY);
if (rule->rt && !rule->direction)
- error = EINVAL;
+ ERROUT(EINVAL);
if (!rule->log)
rule->logif = 0;
if (! pf_init_threshold(&rule->pktrate, rule->pktrate.limit,
rule->pktrate.seconds))
- error = ENOMEM;
+ ERROUT(ENOMEM);
if (pf_addr_setup(ruleset, &rule->src.addr, rule->af))
- error = ENOMEM;
+ ERROUT(ENOMEM);
if (pf_addr_setup(ruleset, &rule->dst.addr, rule->af))
- error = ENOMEM;
+ ERROUT(ENOMEM);
if (pf_kanchor_setup(rule, ruleset, anchor_call))
- error = EINVAL;
+ ERROUT(EINVAL);
if (rule->scrub_flags & PFSTATE_SETPRIO &&
(rule->set_prio[0] > PF_PRIO_MAX ||
rule->set_prio[1] > PF_PRIO_MAX))
- error = EINVAL;
+ ERROUT(EINVAL);
for (int i = 0; i < 3; i++) {
TAILQ_FOREACH(pa, &V_pf_pabuf[i], entries)
if (pa->addr.type == PF_ADDR_TABLE) {
pa->addr.p.tbl = pfr_attach_table(ruleset,
pa->addr.v.tblname);
if (pa->addr.p.tbl == NULL)
- error = ENOMEM;
+ ERROUT(ENOMEM);
}
}
@@ -2207,7 +2207,7 @@ pf_ioctl_addrule(struct pf_krule *rule, uint32_t ticket,
if (rule->overload_tblname[0]) {
if ((rule->overload_tbl = pfr_attach_table(ruleset,
rule->overload_tblname)) == NULL)
- error = EINVAL;
+ ERROUT(EINVAL);
else
rule->overload_tbl->pfrkt_flags |=
PFR_TFLAG_ACTIVE;
@@ -2230,23 +2230,19 @@ pf_ioctl_addrule(struct pf_krule *rule, uint32_t ticket,
if (((rule->action == PF_NAT) || (rule->action == PF_RDR) ||
(rule->action == PF_BINAT)) && rule->anchor == NULL &&
TAILQ_FIRST(&rule->rdr.list) == NULL) {
- error = EINVAL;
+ ERROUT(EINVAL);
}
if (rule->rt > PF_NOPFROUTE && (TAILQ_FIRST(&rule->route.list) == NULL)) {
- error = EINVAL;
+ ERROUT(EINVAL);
}
if (rule->action == PF_PASS && (rule->rdr.opts & PF_POOL_STICKYADDR ||
rule->nat.opts & PF_POOL_STICKYADDR) && !rule->keep_state) {
- error = EINVAL;
+ ERROUT(EINVAL);
}
- if (error) {
- pf_free_rule(rule);
- rule = NULL;
- ERROUT(error);
- }
+ MPASS(error == 0);
rule->nat.cur = TAILQ_FIRST(&rule->nat.list);
rule->rdr.cur = TAILQ_FIRST(&rule->rdr.list);
@@ -2699,7 +2695,7 @@ pf_ioctl_get_addr(struct pf_nl_pooladdr *pp)
PF_RULES_RLOCK_TRACKER;
- pp->anchor[sizeof(pp->anchor) - 1] = 0;
+ pp->anchor[sizeof(pp->anchor) - 1] = '\0';
PF_RULES_RLOCK();
pool = pf_get_kpool(pp->anchor, pp->ticket, pp->r_action,
@@ -2732,7 +2728,7 @@ pf_ioctl_get_rulesets(struct pfioc_ruleset *pr)
PF_RULES_RLOCK_TRACKER;
- pr->path[sizeof(pr->path) - 1] = 0;
+ pr->path[sizeof(pr->path) - 1] = '\0';
PF_RULES_RLOCK();
if ((ruleset = pf_find_kruleset(pr->path)) == NULL) {
@@ -2771,7 +2767,7 @@ pf_ioctl_get_ruleset(struct pfioc_ruleset *pr)
return (ENOENT);
}
- pr->name[0] = 0;
+ pr->name[0] = '\0';
if (ruleset == &pf_main_ruleset) {
/* XXX kludge for pf_main_ruleset */
RB_FOREACH(anchor, pf_kanchor_global, &V_pf_anchors)
@@ -2796,6 +2792,78 @@ pf_ioctl_get_ruleset(struct pfioc_ruleset *pr)
return (error);
}
+int
+pf_ioctl_natlook(struct pfioc_natlook *pnl)
+{
+ struct pf_state_key *sk;
+ struct pf_kstate *state;
+ struct pf_state_key_cmp key;
+ int m = 0, direction = pnl->direction;
+ int sidx, didx;
+
+ /* NATLOOK src and dst are reversed, so reverse sidx/didx */
+ sidx = (direction == PF_IN) ? 1 : 0;
+ didx = (direction == PF_IN) ? 0 : 1;
+
+ if (!pnl->proto ||
+ PF_AZERO(&pnl->saddr, pnl->af) ||
+ PF_AZERO(&pnl->daddr, pnl->af) ||
+ ((pnl->proto == IPPROTO_TCP ||
+ pnl->proto == IPPROTO_UDP) &&
+ (!pnl->dport || !pnl->sport)))
+ return (EINVAL);
+
+ switch (pnl->direction) {
+ case PF_IN:
+ case PF_OUT:
+ case PF_INOUT:
+ break;
+ default:
+ return (EINVAL);
+ }
+
+ switch (pnl->af) {
+#ifdef INET
+ case AF_INET:
+ break;
+#endif /* INET */
+#ifdef INET6
+ case AF_INET6:
+ break;
+#endif /* INET6 */
+ default:
+ return (EAFNOSUPPORT);
+ }
+
+ bzero(&key, sizeof(key));
+ key.af = pnl->af;
+ key.proto = pnl->proto;
+ pf_addrcpy(&key.addr[sidx], &pnl->saddr, pnl->af);
+ key.port[sidx] = pnl->sport;
+ pf_addrcpy(&key.addr[didx], &pnl->daddr, pnl->af);
+ key.port[didx] = pnl->dport;
+
+ state = pf_find_state_all(&key, direction, &m);
+ if (state == NULL)
+ return (ENOENT);
+
+ if (m > 1) {
+ PF_STATE_UNLOCK(state);
+ return (E2BIG); /* more than one state */
+ }
+
+ sk = state->key[sidx];
+ pf_addrcpy(&pnl->rsaddr,
+ &sk->addr[sidx], sk->af);
+ pnl->rsport = sk->port[sidx];
+ pf_addrcpy(&pnl->rdaddr,
+ &sk->addr[didx], sk->af);
+ pnl->rdport = sk->port[didx];
+ PF_STATE_UNLOCK(state);
+
+ return (0);
+}
+
static int
pfioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flags, struct thread *td)
{
@@ -3502,7 +3570,7 @@ DIOCADDRULENV_error:
break;
}
- pr->anchor[sizeof(pr->anchor) - 1] = 0;
+ pr->anchor[sizeof(pr->anchor) - 1] = '\0';
/* Frees rule on error */
error = pf_ioctl_addrule(rule, pr->ticket, pr->pool_ticket,
@@ -3514,7 +3582,7 @@ DIOCADDRULENV_error:
case DIOCGETRULES: {
struct pfioc_rule *pr = (struct pfioc_rule *)addr;
- pr->anchor[sizeof(pr->anchor) - 1] = 0;
+ pr->anchor[sizeof(pr->anchor) - 1] = '\0';
error = pf_ioctl_getrules(pr);
@@ -3653,7 +3721,7 @@ DIOCGETRULENV_error:
u_int32_t nr = 0;
int rs_num;
- pcr->anchor[sizeof(pcr->anchor) - 1] = 0;
+ pcr->anchor[sizeof(pcr->anchor) - 1] = '\0';
if (pcr->action < PF_CHANGE_ADD_HEAD ||
pcr->action > PF_CHANGE_GET_TICKET) {
@@ -4133,51 +4201,8 @@ DIOCGETSTATESV2_full:
case DIOCNATLOOK: {
struct pfioc_natlook *pnl = (struct pfioc_natlook *)addr;
- struct pf_state_key *sk;
- struct pf_kstate *state;
- struct pf_state_key_cmp key;
- int m = 0, direction = pnl->direction;
- int sidx, didx;
-
- /* NATLOOK src and dst are reversed, so reverse sidx/didx */
- sidx = (direction == PF_IN) ? 1 : 0;
- didx = (direction == PF_IN) ? 0 : 1;
-
- if (!pnl->proto ||
- PF_AZERO(&pnl->saddr, pnl->af) ||
- PF_AZERO(&pnl->daddr, pnl->af) ||
- ((pnl->proto == IPPROTO_TCP ||
- pnl->proto == IPPROTO_UDP) &&
- (!pnl->dport || !pnl->sport)))
- error = EINVAL;
- else {
- bzero(&key, sizeof(key));
- key.af = pnl->af;
- key.proto = pnl->proto;
- pf_addrcpy(&key.addr[sidx], &pnl->saddr, pnl->af);
- key.port[sidx] = pnl->sport;
- pf_addrcpy(&key.addr[didx], &pnl->daddr, pnl->af);
- key.port[didx] = pnl->dport;
-
- state = pf_find_state_all(&key, direction, &m);
- if (state == NULL) {
- error = ENOENT;
- } else {
- if (m > 1) {
- PF_STATE_UNLOCK(state);
- error = E2BIG; /* more than one state */
- } else {
- sk = state->key[sidx];
- pf_addrcpy(&pnl->rsaddr,
- &sk->addr[sidx], sk->af);
- pnl->rsport = sk->port[sidx];
- pf_addrcpy(&pnl->rdaddr,
- &sk->addr[didx], sk->af);
- pnl->rdport = sk->port[didx];
- PF_STATE_UNLOCK(state);
- }
- }
- }
+
+ error = pf_ioctl_natlook(pnl);
break;
}
@@ -4498,7 +4523,7 @@ DIOCGETSTATESV2_full:
struct pf_kruleset *ruleset;
struct pfi_kkif *kif = NULL;
- pca->anchor[sizeof(pca->anchor) - 1] = 0;
+ pca->anchor[sizeof(pca->anchor) - 1] = '\0';
if (pca->action < PF_CHANGE_ADD_HEAD ||
pca->action > PF_CHANGE_REMOVE) {
@@ -4629,7 +4654,7 @@ DIOCCHANGEADDR_error:
case DIOCGETRULESETS: {
struct pfioc_ruleset *pr = (struct pfioc_ruleset *)addr;
- pr->path[sizeof(pr->path) - 1] = 0;
+ pr->path[sizeof(pr->path) - 1] = '\0';
error = pf_ioctl_get_rulesets(pr);
break;
@@ -4638,7 +4663,7 @@ DIOCCHANGEADDR_error:
case DIOCGETRULESET: {
struct pfioc_ruleset *pr = (struct pfioc_ruleset *)addr;
- pr->path[sizeof(pr->path) - 1] = 0;
+ pr->path[sizeof(pr->path) - 1] = '\0';
error = pf_ioctl_get_ruleset(pr);
break;
@@ -5362,7 +5387,7 @@ DIOCCHANGEADDR_error:
PF_RULES_WLOCK();
/* First makes sure everything will succeed. */
for (i = 0, ioe = ioes; i < io->size; i++, ioe++) {
- ioe->anchor[sizeof(ioe->anchor) - 1] = 0;
+ ioe->anchor[sizeof(ioe->anchor) - 1] = '\0';
switch (ioe->rs_num) {
case PF_RULESET_ETH:
ers = pf_find_keth_ruleset(ioe->anchor);
diff --git a/sys/netpfil/pf/pf_nl.c b/sys/netpfil/pf/pf_nl.c
index d5d6dc70255e..73933c022ca2 100644
--- a/sys/netpfil/pf/pf_nl.c
+++ b/sys/netpfil/pf/pf_nl.c
@@ -1256,23 +1256,13 @@ pf_handle_clear_status(struct nlmsghdr *hdr, struct nl_pstate *npt)
return (0);
}
-struct pf_nl_natlook {
- sa_family_t af;
- uint8_t direction;
- uint8_t proto;
- struct pf_addr src;
- struct pf_addr dst;
- uint16_t sport;
- uint16_t dport;
-};
-
-#define _OUT(_field) offsetof(struct pf_nl_natlook, _field)
+#define _OUT(_field) offsetof(struct pfioc_natlook, _field)
static const struct nlattr_parser nla_p_natlook[] = {
{ .type = PF_NL_AF, .off = _OUT(af), .cb = nlattr_get_uint8 },
{ .type = PF_NL_DIRECTION, .off = _OUT(direction), .cb = nlattr_get_uint8 },
{ .type = PF_NL_PROTO, .off = _OUT(proto), .cb = nlattr_get_uint8 },
- { .type = PF_NL_SRC_ADDR, .off = _OUT(src), .cb = nlattr_get_in6_addr },
- { .type = PF_NL_DST_ADDR, .off = _OUT(dst), .cb = nlattr_get_in6_addr },
+ { .type = PF_NL_SRC_ADDR, .off = _OUT(saddr), .cb = nlattr_get_in6_addr },
+ { .type = PF_NL_DST_ADDR, .off = _OUT(daddr), .cb = nlattr_get_in6_addr },
{ .type = PF_NL_SRC_PORT, .off = _OUT(sport), .cb = nlattr_get_uint16 },
{ .type = PF_NL_DST_PORT, .off = _OUT(dport), .cb = nlattr_get_uint16 },
};
@@ -1282,63 +1272,31 @@ NL_DECLARE_PARSER(natlook_parser, struct genlmsghdr, nlf_p_empty, nla_p_natlook)
static int
pf_handle_natlook(struct nlmsghdr *hdr, struct nl_pstate *npt)
{
- struct pf_nl_natlook attrs = {};
- struct pf_state_key_cmp key = {};
+ struct pfioc_natlook attrs = {};
struct nl_writer *nw = npt->nw;
- struct pf_state_key *sk;
- struct pf_kstate *state;
struct genlmsghdr *ghdr_new;
- int error, m = 0;
- int sidx, didx;
+ int error;
error = nl_parse_nlmsg(hdr, &natlook_parser, npt, &attrs);
if (error != 0)
return (error);
- if (attrs.proto == 0 ||
- PF_AZERO(&attrs.src, attrs.af) ||
- PF_AZERO(&attrs.dst, attrs.af) ||
- ((attrs.proto == IPPROTO_TCP || attrs.proto == IPPROTO_UDP) &&
- (attrs.sport == 0 || attrs.dport == 0)))
- return (EINVAL);
-
- /* NATLOOK src and dst are reversed, so reverse sidx/didx */
- sidx = (attrs.direction == PF_IN) ? 1 : 0;
- didx = (attrs.direction == PF_IN) ? 0 : 1;
-
- key.af = attrs.af;
- key.proto = attrs.proto;
- pf_addrcpy(&key.addr[sidx], &attrs.src, attrs.af);
- key.port[sidx] = attrs.sport;
- pf_addrcpy(&key.addr[didx], &attrs.dst, attrs.af);
- key.port[didx] = attrs.dport;
-
- state = pf_find_state_all(&key, attrs.direction, &m);
- if (state == NULL)
- return (ENOENT);
- if (m > 1) {
- PF_STATE_UNLOCK(state);
- return (E2BIG);
- }
+ error = pf_ioctl_natlook(&attrs);
+ if (error != 0)
+ return (error);
- if (!nlmsg_reply(nw, hdr, sizeof(struct genlmsghdr))) {
- PF_STATE_UNLOCK(state);
+ if (!nlmsg_reply(nw, hdr, sizeof(struct genlmsghdr)))
return (ENOMEM);
- }
ghdr_new = nlmsg_reserve_object(nw, struct genlmsghdr);
ghdr_new->cmd = PFNL_CMD_NATLOOK;
ghdr_new->version = 0;
ghdr_new->reserved = 0;
- sk = state->key[sidx];
-
- nlattr_add_in6_addr(nw, PF_NL_SRC_ADDR, &sk->addr[sidx].v6);
- nlattr_add_in6_addr(nw, PF_NL_DST_ADDR, &sk->addr[didx].v6);
- nlattr_add_u16(nw, PF_NL_SRC_PORT, sk->port[sidx]);
- nlattr_add_u16(nw, PF_NL_DST_PORT, sk->port[didx]);
-
- PF_STATE_UNLOCK(state);
+ nlattr_add_in6_addr(nw, PF_NL_SRC_ADDR, &attrs.rsaddr.v6);
+ nlattr_add_in6_addr(nw, PF_NL_DST_ADDR, &attrs.rdaddr.v6);
+ nlattr_add_u16(nw, PF_NL_SRC_PORT, attrs.rsport);
+ nlattr_add_u16(nw, PF_NL_DST_PORT, attrs.rdport);
if (!nlmsg_end(nw)) {
nlmsg_abort(nw);
diff --git a/sys/sys/fcntl.h b/sys/sys/fcntl.h
index dd9fccf5cf38..18d3928e91c7 100644
--- a/sys/sys/fcntl.h
+++ b/sys/sys/fcntl.h
@@ -144,6 +144,10 @@ typedef __pid_t pid_t;
#define O_XATTR O_NAMEDATTR /* Solaris compatibility */
#endif
+#if __POSIX_VISIBLE >= 202405
+#define O_CLOFORK 0x08000000
+#endif
+
/*
* !!! DANGER !!!
*
@@ -280,6 +284,16 @@ typedef __pid_t pid_t;
#define F_GET_SEALS 20
#define F_ISUNIONSTACK 21 /* Kludge for libc, don't use it. */
#define F_KINFO 22 /* Return kinfo_file for this fd */
+#endif /* __BSD_VISIBLE */
+
+#if __POSIX_VISIBLE >= 202405
+#define F_DUPFD_CLOFORK 23 /* Like F_DUPFD, but FD_CLOFORK is set */
+#endif
+
+#if __BSD_VISIBLE
+#define F_DUP3FD 24 /* Used with dup3() */
+
+#define F_DUP3FD_SHIFT 16 /* Shift used for F_DUP3FD */
/* Seals (F_ADD_SEALS, F_GET_SEALS). */
#define F_SEAL_SEAL 0x0001 /* Prevent adding sealings */
@@ -292,6 +306,9 @@ typedef __pid_t pid_t;
#define FD_CLOEXEC 1 /* close-on-exec flag */
#define FD_RESOLVE_BENEATH 2 /* all lookups relative to fd have
O_RESOLVE_BENEATH semantics */
+#if __POSIX_VISIBLE >= 202405
+#define FD_CLOFORK 4 /* close-on-fork flag */
+#endif
/* record locking flags (F_GETLK, F_SETLK, F_SETLKW) */
#define F_RDLCK 1 /* shared or read lock */
diff --git a/sys/sys/filedesc.h b/sys/sys/filedesc.h
index 55969b2ff4b3..0a388c90de26 100644
--- a/sys/sys/filedesc.h
+++ b/sys/sys/filedesc.h
@@ -149,6 +149,7 @@ struct filedesc_to_leader {
*/
#define UF_EXCLOSE 0x01 /* auto-close on exec */
#define UF_RESOLVE_BENEATH 0x02 /* lookups must be beneath this dir */
+#define UF_FOCLOSE 0x04 /* auto-close on fork */
#ifdef _KERNEL
@@ -221,6 +222,7 @@ enum {
/* Flags for kern_dup(). */
#define FDDUP_FLAG_CLOEXEC 0x1 /* Atomically set UF_EXCLOSE. */
+#define FDDUP_FLAG_CLOFORK 0x2 /* Atomically set UF_FOCLOSE. */
/* For backward compatibility. */
#define falloc(td, resultfp, resultfd, flags) \
diff --git a/sys/sys/param.h b/sys/sys/param.h
index 57eb8ebcf12c..af116d6e3f7a 100644
--- a/sys/sys/param.h
+++ b/sys/sys/param.h
@@ -74,7 +74,7 @@
* cannot include sys/param.h and should only be updated here.
*/
#undef __FreeBSD_version
-#define __FreeBSD_version 1500050
+#define __FreeBSD_version 1500051
/*
* __FreeBSD_kernel__ indicates that this system uses the kernel of FreeBSD,
diff --git a/sys/sys/socket.h b/sys/sys/socket.h
index 5e7c554c34cf..cdd4fa3b4b89 100644
--- a/sys/sys/socket.h
+++ b/sys/sys/socket.h
@@ -111,10 +111,11 @@ typedef __uintptr_t uintptr_t;
*/
#define SOCK_CLOEXEC 0x10000000
#define SOCK_NONBLOCK 0x20000000
+#define SOCK_CLOFORK 0x40000000
#ifdef _KERNEL
/*
* Flags for accept1(), kern_accept4() and solisten_dequeue, in addition
- * to SOCK_CLOEXEC and SOCK_NONBLOCK.
+ * to SOCK_CLOEXEC, SOCK_CLOFORK and SOCK_NONBLOCK.
*/
#define ACCEPT4_INHERIT 0x1
#define ACCEPT4_COMPAT 0x2
@@ -478,6 +479,9 @@ struct msghdr {
#define MSG_MORETOCOME 0x00100000 /* additional data pending */
#define MSG_TLSAPPDATA 0x00200000 /* do not soreceive() alert rec. (TLS) */
#endif
+#if __BSD_VISIBLE
+#define MSG_CMSG_CLOFORK 0x00400000 /* make received fds close-on-fork */
+#endif
/*
* Header for ancillary data objects in msg_control buffer.
diff --git a/sys/sys/syscallsubr.h b/sys/sys/syscallsubr.h
index fe6dd9e14fb4..fd183ffbc7a4 100644
--- a/sys/sys/syscallsubr.h
+++ b/sys/sys/syscallsubr.h
@@ -257,6 +257,7 @@ int kern_munlock(struct thread *td, uintptr_t addr, size_t size);
int kern_munmap(struct thread *td, uintptr_t addr, size_t size);
int kern_nanosleep(struct thread *td, struct timespec *rqt,
struct timespec *rmt);
+int kern_nosys(struct thread *td, int dummy);
int kern_ntp_adjtime(struct thread *td, struct timex *ntv, int *retvalp);
int kern_ogetdirentries(struct thread *td, struct ogetdirentries_args *uap,
long *ploff);
diff --git a/sys/sys/sysent.h b/sys/sys/sysent.h
index 6314b03142e7..4ddfc8516053 100644
--- a/sys/sys/sysent.h
+++ b/sys/sys/sysent.h
@@ -79,11 +79,10 @@ struct sysent { /* system call table */
*/
#define SYF_CAPENABLED 0x00000001
-#define SY_THR_FLAGMASK 0x7
-#define SY_THR_STATIC 0x1
-#define SY_THR_DRAINING 0x2
-#define SY_THR_ABSENT 0x4
-#define SY_THR_INCR 0x8
+#define SY_THR_STATIC 0x01
+#define SY_THR_DRAINING 0x02
+#define SY_THR_ABSENT 0x04
+#define SY_THR_INCR 0x08
#ifdef KLD_MODULE
#define SY_THR_STATIC_KLD 0
diff --git a/sys/sys/unistd.h b/sys/sys/unistd.h
index f5caea2e3919..c291c1dc2b95 100644
--- a/sys/sys/unistd.h
+++ b/sys/sys/unistd.h
@@ -156,6 +156,7 @@
#define _PC_DEALLOC_PRESENT 65
#define _PC_NAMEDATTR_ENABLED 66
#define _PC_HAS_NAMEDATTR 67
+#define _PC_HAS_HIDDENSYSTEM 68
#endif
/* From OpenSolaris, used by SEEK_DATA/SEEK_HOLE. */
@@ -210,6 +211,7 @@
* close_range() options.
*/
#define CLOSE_RANGE_CLOEXEC (1<<2)
+#define CLOSE_RANGE_CLOFORK (1<<3)
#endif /* __BSD_VISIBLE */
diff --git a/sys/sys/vnode.h b/sys/sys/vnode.h
index 3ed469bdce6d..2c6947103c94 100644
--- a/sys/sys/vnode.h
+++ b/sys/sys/vnode.h
@@ -1032,7 +1032,7 @@ void vop_rename_fail(struct vop_rename_args *ap);
#define VOP_WRITE_POST(ap, ret) \
noffset = (ap)->a_uio->uio_offset; \
if (noffset > ooffset) { \
- if (VN_KNLIST_EMPTY((ap)->a_vp)) { \
+ if (!VN_KNLIST_EMPTY((ap)->a_vp)) { \
VFS_KNOTE_LOCKED((ap)->a_vp, NOTE_WRITE | \
(noffset > osize ? NOTE_EXTEND : 0)); \
} \
diff --git a/sys/ufs/ufs/ufs_vnops.c b/sys/ufs/ufs/ufs_vnops.c
index 74cb094bdfe4..53fac4b0665e 100644
--- a/sys/ufs/ufs/ufs_vnops.c
+++ b/sys/ufs/ufs/ufs_vnops.c
@@ -2720,6 +2720,9 @@ ufs_pathconf(
case _PC_SYMLINK_MAX:
*ap->a_retval = MAXPATHLEN;
break;
+ case _PC_HAS_HIDDENSYSTEM:
+ *ap->a_retval = 1;
+ break;
default:
error = vop_stdpathconf(ap);
diff --git a/sys/vm/vm_fault.c b/sys/vm/vm_fault.c
index 21584abacfa3..3e57e8d4f1d0 100644
--- a/sys/vm/vm_fault.c
+++ b/sys/vm/vm_fault.c
@@ -1441,8 +1441,7 @@ vm_fault_busy_sleep(struct faultstate *fs)
}
vm_object_pip_wakeup(fs->object);
vm_fault_unlock_map(fs);
- if (fs->m != vm_page_lookup(fs->object, fs->pindex) ||
- !vm_page_busy_sleep(fs->m, "vmpfw", 0))
+ if (!vm_page_busy_sleep(fs->m, "vmpfw", 0))
VM_OBJECT_UNLOCK(fs->object);
VM_CNT_INC(v_intrans);
vm_object_deallocate(fs->first_object);