constify ether_sprintf and a few globals
Hello - This constify's ether_sprintf and some globals and adjusts the users accordingly. Feel free to commit if OK. Index: dev/ic/if_wi_hostap.c === RCS file: /cvs/src/sys/dev/ic/if_wi_hostap.c,v retrieving revision 1.52 diff -u -p -r1.52 if_wi_hostap.c --- dev/ic/if_wi_hostap.c 19 Feb 2018 08:59:52 - 1.52 +++ dev/ic/if_wi_hostap.c 14 Dec 2022 15:32:35 - @@ -76,13 +76,13 @@ struct wihap_sta_info *wihap_sta_find(st int wihap_sta_is_assoc(struct wihap_info *whi, u_int8_t addr[]); void wihap_auth_req(struct wi_softc *sc, struct wi_frame *rxfrm, caddr_t pkt, int len); -void wihap_sta_deauth(struct wi_softc *sc, u_int8_t sta_addr[], +void wihap_sta_deauth(struct wi_softc *sc, const u_int8_t sta_addr[], u_int16_t reason); void wihap_deauth_req(struct wi_softc *sc, struct wi_frame *rxfrm, caddr_t pkt, int len); void wihap_assoc_req(struct wi_softc *sc, struct wi_frame *rxfrm, caddr_t pkt, int len); -void wihap_sta_disassoc(struct wi_softc *sc, u_int8_t sta_addr[], +void wihap_sta_disassoc(struct wi_softc *sc, const u_int8_t sta_addr[], u_int16_t reason); void wihap_disassoc_req(struct wi_softc *sc, struct wi_frame *rxfrm, caddr_t pkt, int len); @@ -204,7 +204,7 @@ wihap_init(struct wi_softc *sc) * Send a disassociation frame to a specified station. */ void -wihap_sta_disassoc(struct wi_softc *sc, u_int8_t sta_addr[], u_int16_t reason) +wihap_sta_disassoc(struct wi_softc *sc, const u_int8_t sta_addr[], u_int16_t reason) { struct wi_80211_hdr *resp_hdr; caddr_t pkt; @@ -233,7 +233,7 @@ wihap_sta_disassoc(struct wi_softc *sc, * Send a deauthentication message to a specified station. */ void -wihap_sta_deauth(struct wi_softc *sc, u_int8_t sta_addr[], u_int16_t reason) +wihap_sta_deauth(struct wi_softc *sc, const u_int8_t sta_addr[], u_int16_t reason) { struct wi_80211_hdr *resp_hdr; caddr_t pkt; Index: dev/pci/if_bwfm_pci.c === RCS file: /cvs/src/sys/dev/pci/if_bwfm_pci.c,v retrieving revision 1.74 diff -u -p -r1.74 if_bwfm_pci.c --- dev/pci/if_bwfm_pci.c 10 Nov 2022 12:14:05 - 1.74 +++ dev/pci/if_bwfm_pci.c 14 Dec 2022 15:32:35 - @@ -1929,7 +1929,7 @@ bwfm_pci_flowring_lookup(struct bwfm_pci { struct ieee80211com *ic = >sc_sc.sc_ic; #ifndef IEEE80211_STA_ONLY - uint8_t *da = mtod(m, uint8_t *); + const uint8_t *da = mtod(m, uint8_t *); #endif int flowid, prio, fifo; int i, found; @@ -1987,7 +1987,7 @@ bwfm_pci_flowring_create(struct bwfm_pci struct ieee80211com *ic = >sc_sc.sc_ic; struct bwfm_cmd_flowring_create cmd; #ifndef IEEE80211_STA_ONLY - uint8_t *da = mtod(m, uint8_t *); + const uint8_t *da = mtod(m, uint8_t *); #endif struct bwfm_pci_msgring *ring; int flowid, prio, fifo; Index: dev/pci/if_ixl.c === RCS file: /cvs/src/sys/dev/pci/if_ixl.c,v retrieving revision 1.84 diff -u -p -r1.84 if_ixl.c --- dev/pci/if_ixl.c5 Aug 2022 13:57:16 - 1.84 +++ dev/pci/if_ixl.c14 Dec 2022 15:32:35 - @@ -1346,7 +1346,7 @@ static intixl_set_vsi(struct ixl_softc static int ixl_get_link_status(struct ixl_softc *); static int ixl_set_link_status(struct ixl_softc *, const struct ixl_aq_desc *); -static int ixl_add_macvlan(struct ixl_softc *, uint8_t *, uint16_t, +static int ixl_add_macvlan(struct ixl_softc *, const uint8_t *, uint16_t, uint16_t); static int ixl_remove_macvlan(struct ixl_softc *, uint8_t *, uint16_t, uint16_t); @@ -4547,7 +4547,7 @@ ixl_restart_an(struct ixl_softc *sc) } static int -ixl_add_macvlan(struct ixl_softc *sc, uint8_t *macaddr, uint16_t vlan, uint16_t flags) +ixl_add_macvlan(struct ixl_softc *sc, const uint8_t *macaddr, uint16_t vlan, uint16_t flags) { struct ixl_aq_desc iaq; struct ixl_aq_add_macvlan *param; Index: dev/pci/if_mcx.c === RCS file: /cvs/src/sys/dev/pci/if_mcx.c,v retrieving revision 1.106 diff -u -p -r1.106 if_mcx.c --- dev/pci/if_mcx.c22 Nov 2022 06:48:32 - 1.106 +++ dev/pci/if_mcx.c14 Dec 2022 15:32:36 - @@ -2564,7 +2564,7 @@ static intmcx_create_flow_group(struct int, int, struct mcx_flow_match *); static int mcx_destroy_flow_group(struct mcx_softc *, int); static int mcx_set_flow_table_entry_mac(struct mcx_softc *, int, int, - uint8_t *, uint32_t); + const uint8_t *, uint32_t); static int mcx_set_flow_table_entry_proto(struct mcx_softc *, int, int, int, int, uint32_t); static int mcx_delete_flow_table_entry(struct
Re: splassert on boot
On 11/23/22 15:18, Vitaliy Makkoveev wrote: On Wed, Nov 23, 2022 at 02:59:05PM -0500, David Hill wrote: Hello - I am seeing splasserts on boot (before kern.splassert=2 can be set) with -current. spdmem0 at iic0 addr 0x50: 8GB DDR3 SDRAM PC3-12800 SO-DIMM isa0 at pcib0 isadma0 at isa0 vga0 at isa0 port 0x3b0/48 iomem 0xa/131072 wsdisplay at vga0 not configured pcppi0 at isa0 port 0x61 spkr0 at pcppi0 vmm0 at mainbus0: VMX/EPT (using slow L1TF mitigation) splassert: pfi_attach_ifgroup: want 2 have 0 splassert: pfi_group_addmember: want 2 have 0 splassert: pfi_attach_ifgroup: want 2 have 0 splassert: pfi_attach_ifgroup: want 2 have 0 splassert: pfi_group_addmember: want 2 have 0 - David The netlock assertion within PF_LOCK() looks wrong. The netlock should be taken first, but only if both locks taken. Index: sys/net/pfvar_priv.h === RCS file: /cvs/src/sys/net/pfvar_priv.h,v retrieving revision 1.21 diff -u -p -r1.21 pfvar_priv.h --- sys/net/pfvar_priv.h11 Nov 2022 17:12:30 - 1.21 +++ sys/net/pfvar_priv.h23 Nov 2022 20:14:13 - @@ -278,7 +278,6 @@ extern struct rwlockpf_lock; extern struct rwlock pf_state_lock; #define PF_LOCK() do { \ - NET_ASSERT_LOCKED();\ rw_enter_write(_lock); \ } while (0) with traceback vmm0 at mainbus0: VMX/EPT (using slow L1TF mitigation) splassert: pfi_attach_ifgroup: want 2 have 0 Starting stack trace... pfi_attach_ifgroup(800ecc80,800ecc80,81f25c9b,800ecca8,8188cf82,82737e30) at pfi_attach_ifgroup+0x42 if_addgroup(8015,81f25c9b,f9c039b9154dadd0,0,8015,822d06e0) at if_addgroup+0x142 enc_clone_create(822d06e0,0,28d493f4921b481d,2,822e5aa0,1f) at enc_clone_create+0xd2 encattach(1,1,8173c274,82737f00,822d06e0,0) at encattach+0x14 main(0,0,2,0,abd41b90,1) at main+0x409 end trace frame: 0x0, count: 252 End of stack trace. splassert: pfi_group_addmember: want 2 have 0 Starting stack trace... pfi_group_addmember(81f25c9b,81f25c9b,81f25c9b,8014a228,8188d442,82737e30) at pfi_group_addmember+0x42 if_addgroup(8015,81f25c9b,f9c039b9154dadd0,0,8015,822d06e0) at if_addgroup+0x1e6 enc_clone_create(822d06e0,0,28d493f4921b481d,2,822e5aa0,1f) at enc_clone_create+0xd2 encattach(1,1,8173c274,82737f00,822d06e0,0) at encattach+0x14 main(0,0,2,0,abd41b90,1) at main+0x409 end trace frame: 0x0, count: 252 End of stack trace. splassert: pfi_attach_ifgroup: want 2 have 0 Starting stack trace... pfi_attach_ifgroup(80102e80,80102e80,80102e80,80102ea8,8188cf82,82737e90) at pfi_attach_ifgroup+0x42 if_creategroup(81f501b2,81f501b2,ea09b7f381ae3cd3,2,822e5b50,822a6790) at if_creategroup+0x6f carpattach(1,1,e1e0b7d5818b2660,822a6790,811da510,82737f00) at carpattach+0x20 main(0,0,2,0,abd41b90,1) at main+0x409 end trace frame: 0x0, count: 253 End of stack trace. splassert: pfi_attach_ifgroup: want 2 have 0 Starting stack trace... pfi_attach_ifgroup(800f2f00,800f2f00,81f77eea,800f2f28,8188cf82,82737e70) at pfi_attach_ifgroup+0x42 if_addgroup(80150800,81f77eea,f9c039b91557e57e,2,80150800,1f) at if_addgroup+0x142 loopattach(1,1,822e5b90,822db440,8169888c,82737f00) at loopattach+0xbc main(0,0,2,0,abd41b90,1) at main+0x409 end trace frame: 0x0, count: 253 End of stack trace. splassert: pfi_group_addmember: want 2 have 0 Starting stack trace... pfi_group_addmember(81f77eea,81f77eea,81f77eea,8014a2e8,8188d442,82737e70) at pfi_group_addmember+0x42 if_addgroup(80150800,81f77eea,f9c039b91557e57e,2,80150800,1f) at if_addgroup+0x1e6 loopattach(1,1,822e5b90,822db440,8169888c,82737f00) at loopattach+0xbc main(0,0,2,0,abd41b90,1) at main+0x409 end trace frame: 0x0, count: 253 End of stack trace.
splassert on boot
Hello - I am seeing splasserts on boot (before kern.splassert=2 can be set) with -current. spdmem0 at iic0 addr 0x50: 8GB DDR3 SDRAM PC3-12800 SO-DIMM isa0 at pcib0 isadma0 at isa0 vga0 at isa0 port 0x3b0/48 iomem 0xa/131072 wsdisplay at vga0 not configured pcppi0 at isa0 port 0x61 spkr0 at pcppi0 vmm0 at mainbus0: VMX/EPT (using slow L1TF mitigation) splassert: pfi_attach_ifgroup: want 2 have 0 splassert: pfi_group_addmember: want 2 have 0 splassert: pfi_attach_ifgroup: want 2 have 0 splassert: pfi_attach_ifgroup: want 2 have 0 splassert: pfi_group_addmember: want 2 have 0 - David
Re: possible fix for Xorg 21.1.1 crashes
On 11/16/21 18:21, Matthieu Herrb wrote: On Tue, Nov 16, 2021 at 11:26:40PM +0100, Matthieu Herrb wrote: Hi, I think I found the bug that causes crashes in X for some people. If X started crashing since you upgraded to the last snapshots, can you try the patch below ? get /usr/xenocara from CVS then cd /usr/xenocara/xserver patch -p0 -E < /this/patch doas make -f Makefile.bsd-wrapper obj doas make -f Makefile.bsd-wrapper build And restart the X server, for example : doas rcctl restart xenodm Here's a more complete fix. Ust this one instead, sorry. The first diff did not help, but this one has kept my X stable for 12 hours so far... - David
postgresql 12 - could not open shared memory segment
Hello - I am using postgresql 12 on OpenBSD 6.8. After a while of running, postgresql starts throwing out errors: 2020-12-03 08:18:35.052 CST [60288] ERROR: could not open shared memory segment "/PostgreSQL.1780529043": No such file or directory 2020-12-03 08:18:35.052 CST [40083] ERROR: could not open shared memory segment "/PostgreSQL.1780529043": No such file or directory 2020-12-03 08:18:35.052 CST [53517] ERROR: could not open shared memory segment "/PostgreSQL.1780529043": No such file or directory 2020-12-03 08:18:35.052 CST [53517] CONTEXT: parallel worker 2020-12-03 08:18:35.054 CST [47581] LOG: background worker "parallel worker" (PID 40083) exited with exit code 1 2020-12-03 08:18:35.055 CST [47581] LOG: background worker "parallel worker" (PID 60288) exited with exit code 1 2020-12-03 08:24:19.583 CST [53517] WARNING: could not remove shared memory segment "/PostgreSQL.1222503421": No such file or directory 2020-12-03 08:24:19.584 CST [31517] WARNING: could not remove shared memory segment "/PostgreSQL.19516083": No such file or directory 2020-12-03 08:24:19.584 CST [53517] WARNING: could not remove shared memory segment "/PostgreSQL.1780529043": No such file or directory in postgresql.conf, dynamic_shared_memory_type is set to posix. /etc/sysctl.conf kern.seminfo.semmni=256 kern.seminfo.semmns=2048 I am wondering there is something I need to adjust... or if anyone has run into this before? Does anyone have any pointers on what to look for? Thanks - David
Re: monotonic clock going backwards?
On 6/6/19 8:49 AM, Mark Kettenis wrote: From: David Hill Date: Thu, 6 Jun 2019 08:22:06 -0400 On 6/6/19 6:56 AM, Scott Cheloha wrote: On Wed, Jun 05, 2019 at 08:33:56PM -0400, David Hill wrote: Hello - I noticed some negative roundtrip times when running traceroute, which uses the monotonic clock to calculate the RTT. If I run the following code, it eventually bombs.?? It bombs quick if I launch Firefox. timespeccmp failed tp1 s:103780 n:63101042 tp2 s:103779 n:761117849 please share your dmesg and the output of sysctl kern.clockrate kern.timecounter Could you also share the output when you run the following code? With and without firefox running? Curious about how frequently this happens. #include #include #include #include int main(void) { struct timespec t0, t1, timeout; timeout.tv_sec = 0; timeout.tv_nsec = 10; for (;;) { clock_gettime(CLOCK_MONOTONIC, ); if (nanosleep(, NULL) == -1) err(1, "nanosleep"); clock_gettime(CLOCK_MONOTONIC, ); if (timespeccmp(, , >)) { printf("%lld.%09ld precedes %lld.%09ld\n", t1.tv_sec, t1.tv_nsec, t0.tv_sec, t0.tv_nsec); } } return 0; } $ sysctl kern.clockrate kern.timecounter kern.clockrate=tick = 1, tickadj = 40, hz = 100, profhz = 100, stathz = 100 kern.timecounter.tick=1 kern.timecounter.timestepwarnings=0 kern.timecounter.hardware=tsc kern.timecounter.choice=i8254(0) acpihpet0(1000) tsc(2000) acpitimer0(1000) 146259.148543164 precedes 146259.450584680 146259.488592813 precedes 146259.790556528 146259.808566236 precedes 146260.110528202 146261.148476141 precedes 146261.450398822 146262.888279505 precedes 146263.190240715 146263.887431808 precedes 146264.189435801 146274.487159451 precedes 146274.789148187 146278.186820816 precedes 146278.488803756 146279.546680181 precedes 146279.848674138 146284.326305557 precedes 146284.628224696 146285.426154861 precedes 146285.728066901 146287.885921929 precedes 146288.187826688 146289.985763711 precedes 146290.287731233 146290.985659041 precedes 146291.287640302 146293.985348615 precedes 146294.287327519 146295.465186742 precedes 146295.767218516 146295.885156426 precedes 146296.187140717 146298.544907956 precedes 146298.846882759 146298.644894308 precedes 146298.946889142 Does this also happen with kern.timecounter.hardware=acpihpet ? Ran the code with kern.timecounter.hardware=acpihpet0 for 10 minutes without any output. With the code still running, I switched to tsc and starting seeing output: 151944.345840447 precedes 151944.647753895 151944.525774690 precedes 151944.827681380 151946.405553296 precedes 151946.707533012 The output stops as soon as I switch back to acpihpet0. I will add that to my /etc/sysctl.conf. Thank you. OpenBSD 6.5-current (GENERIC.MP) #27: Tue Jun 4 15:36:14 EDT 2019 dh...@liver.mindcry.org:/usr/src/sys/arch/amd64/compile/GENERIC.MP real mem = 8418242560 (8028MB) avail mem = 8152993792 (7775MB) mpath0 at root scsibus0 at mpath0: 256 targets mainbus0 at root bios0 at mainbus0: SMBIOS rev. 2.8 @ 0x9a565000 (49 entries) bios0: vendor American Megatrends Inc. version "X420UA.204" date 11/16/2018 bios0: ASUSTeK COMPUTER INC. VivoBook_ASUSLaptop X420UA acpi0 at bios0: rev 2 acpi0: sleep states S0 S3 S4 S5 acpi0: tables DSDT FACP APIC FPDT FIDT ECDT MCFG SSDT SSDT SSDT MSDM SSDT HPET SSDT UEFI SSDT LPIT SSDT SSDT SSDT SSDT DBGP DBG2 DMAR NHLT BGRT TPM2 WSMT acpi0: wakeup devices PXSX(S4) RP06(S4) GLAN(S4) XHC_(S3) XDCI(S4) HDAS(S4) acpitimer0 at acpi0: 3579545 Hz, 24 bits acpimadt0 at acpi0 addr 0xfee0: PC-AT compat cpu0 at mainbus0: apid 0 (boot processor) cpu0: Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz, 3393.27 MHz, 06-8e-0a cpu0: FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,EST,TM2,S SSE3,SDBG,FMA3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,MOVBE,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,PAGE1GB,RDTSCP,LONG,LAHF,ABM,3DNOWP,PERF,ITSC,FSGSBASE,SGX,BMI 1,AVX2,SMEP,BMI2,ERMS,INVPCID,MPX,RDSEED,ADX,SMAP,CLFLUSHOPT,PT,MD_CLEAR,TSXFA,IBRS,IBPB,STIBP,L1DF,SSBD,SENSOR,ARAT,XSAVEOPT,XSAVEC,XGETBV1,XSAVES,MELTDOWN cpu0: 256KB 64b/line 8-way L2 cache cpu0: smt 0, core 0, package 0 mtrr: Pentium Pro MTRR support, 10 var ranges, 88 fixed ranges cpu0: apic clock running at 23MHz cpu0: mwait min=64, max=64, C-substates=0.2.1.2.4.1.1.1, IBE cpu1 at mainbus0: apid 2 (application processor) cpu1: Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz, 3392.09 MHz, 06-8e-0a cpu1: FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,EST,TM2,S SSE3,SDBG,FMA3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,MOVBE,POPCNT,DEADLINE,AES,XSAVE,AVX,F1
Re: monotonic clock going backwards?
On 6/6/19 6:56 AM, Scott Cheloha wrote: On Wed, Jun 05, 2019 at 08:33:56PM -0400, David Hill wrote: Hello - I noticed some negative roundtrip times when running traceroute, which uses the monotonic clock to calculate the RTT. If I run the following code, it eventually bombs.?? It bombs quick if I launch Firefox. timespeccmp failed tp1 s:103780 n:63101042 tp2 s:103779 n:761117849 please share your dmesg and the output of sysctl kern.clockrate kern.timecounter Could you also share the output when you run the following code? With and without firefox running? Curious about how frequently this happens. #include #include #include #include int main(void) { struct timespec t0, t1, timeout; timeout.tv_sec = 0; timeout.tv_nsec = 10; for (;;) { clock_gettime(CLOCK_MONOTONIC, ); if (nanosleep(, NULL) == -1) err(1, "nanosleep"); clock_gettime(CLOCK_MONOTONIC, ); if (timespeccmp(, , >)) { printf("%lld.%09ld precedes %lld.%09ld\n", t1.tv_sec, t1.tv_nsec, t0.tv_sec, t0.tv_nsec); } } return 0; } $ sysctl kern.clockrate kern.timecounter kern.clockrate=tick = 1, tickadj = 40, hz = 100, profhz = 100, stathz = 100 kern.timecounter.tick=1 kern.timecounter.timestepwarnings=0 kern.timecounter.hardware=tsc kern.timecounter.choice=i8254(0) acpihpet0(1000) tsc(2000) acpitimer0(1000) 146259.148543164 precedes 146259.450584680 146259.488592813 precedes 146259.790556528 146259.808566236 precedes 146260.110528202 146261.148476141 precedes 146261.450398822 146262.888279505 precedes 146263.190240715 146263.887431808 precedes 146264.189435801 146274.487159451 precedes 146274.789148187 146278.186820816 precedes 146278.488803756 146279.546680181 precedes 146279.848674138 146284.326305557 precedes 146284.628224696 146285.426154861 precedes 146285.728066901 146287.885921929 precedes 146288.187826688 146289.985763711 precedes 146290.287731233 146290.985659041 precedes 146291.287640302 146293.985348615 precedes 146294.287327519 146295.465186742 precedes 146295.767218516 146295.885156426 precedes 146296.187140717 146298.544907956 precedes 146298.846882759 146298.644894308 precedes 146298.946889142 OpenBSD 6.5-current (GENERIC.MP) #27: Tue Jun 4 15:36:14 EDT 2019 dh...@liver.mindcry.org:/usr/src/sys/arch/amd64/compile/GENERIC.MP real mem = 8418242560 (8028MB) avail mem = 8152993792 (7775MB) mpath0 at root scsibus0 at mpath0: 256 targets mainbus0 at root bios0 at mainbus0: SMBIOS rev. 2.8 @ 0x9a565000 (49 entries) bios0: vendor American Megatrends Inc. version "X420UA.204" date 11/16/2018 bios0: ASUSTeK COMPUTER INC. VivoBook_ASUSLaptop X420UA acpi0 at bios0: rev 2 acpi0: sleep states S0 S3 S4 S5 acpi0: tables DSDT FACP APIC FPDT FIDT ECDT MCFG SSDT SSDT SSDT MSDM SSDT HPET SSDT UEFI SSDT LPIT SSDT SSDT SSDT SSDT DBGP DBG2 DMAR NHLT BGRT TPM2 WSMT acpi0: wakeup devices PXSX(S4) RP06(S4) GLAN(S4) XHC_(S3) XDCI(S4) HDAS(S4) acpitimer0 at acpi0: 3579545 Hz, 24 bits acpimadt0 at acpi0 addr 0xfee0: PC-AT compat cpu0 at mainbus0: apid 0 (boot processor) cpu0: Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz, 3393.27 MHz, 06-8e-0a cpu0: FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,EST,TM2,S SSE3,SDBG,FMA3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,MOVBE,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,PAGE1GB,RDTSCP,LONG,LAHF,ABM,3DNOWP,PERF,ITSC,FSGSBASE,SGX,BMI 1,AVX2,SMEP,BMI2,ERMS,INVPCID,MPX,RDSEED,ADX,SMAP,CLFLUSHOPT,PT,MD_CLEAR,TSXFA,IBRS,IBPB,STIBP,L1DF,SSBD,SENSOR,ARAT,XSAVEOPT,XSAVEC,XGETBV1,XSAVES,MELTDOWN cpu0: 256KB 64b/line 8-way L2 cache cpu0: smt 0, core 0, package 0 mtrr: Pentium Pro MTRR support, 10 var ranges, 88 fixed ranges cpu0: apic clock running at 23MHz cpu0: mwait min=64, max=64, C-substates=0.2.1.2.4.1.1.1, IBE cpu1 at mainbus0: apid 2 (application processor) cpu1: Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz, 3392.09 MHz, 06-8e-0a cpu1: FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,EST,TM2,S SSE3,SDBG,FMA3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,MOVBE,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,PAGE1GB,RDTSCP,LONG,LAHF,ABM,3DNOWP,PERF,ITSC,FSGSBASE,SGX,BMI 1,AVX2,SMEP,BMI2,ERMS,INVPCID,MPX,RDSEED,ADX,SMAP,CLFLUSHOPT,PT,MD_CLEAR,TSXFA,IBRS,IBPB,STIBP,L1DF,SSBD,SENSOR,ARAT,XSAVEOPT,XSAVEC,XGETBV1,XSAVES,MELTDOWN cpu1: 256KB 64b/line 8-way L2 cache cpu1: smt 0, core 1, package 0 cpu2 at mainbus0: apid 4 (application processor) cpu2: Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz, 3392.09 MHz, 06-8e-0a cpu2: FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64
monotonic clock going backwards?
Hello - I noticed some negative roundtrip times when running traceroute, which uses the monotonic clock to calculate the RTT. If I run the following code, it eventually bombs. It bombs quick if I launch Firefox. timespeccmp failed tp1 s:103780 n:63101042 tp2 s:103779 n:761117849 #include #include #include #include int main(void) { int r; struct timespec tp1, tp2, tout; tout.tv_sec = 0; tout.tv_nsec = 10; for (;;) { r = clock_gettime(CLOCK_MONOTONIC, ); if (r == -1) { perror("clock_gettime"); exit(-1); } nanosleep(, NULL); r = clock_gettime(CLOCK_MONOTONIC, ); if (r == -1) { perror("clock_gettime"); exit(-1); } // tp1 should never be larger than tp2 r = timespeccmp(, , >); if (r == 1) { printf("timespeccmp failed\n"); printf("tp1 s:%lld n:%ld\n", tp1.tv_sec, tp1.tv_nsec); printf("tp2 s:%lld n:%ld\n", tp2.tv_sec, tp2.tv_nsec); exit(-1); } } return 0; }
Re: iked: fix retransmission bug after simultaneous rekeying
On Thu, Apr 11, 2019 at 04:32:28PM +0200, Tobias Heider wrote: > Hi, > > this patch fixes a bug that appears after simultaneous > rekeying of the ikesa. Currently the initiator does not set it's > IKED_REQ_INFORMATIONAL flag when sending the delete request and thus rejects > the response to the DELETE INFORMATIONAL request in ikev2_recv. > The request is not removed from the initiators request queue and is > retransmitted over and over. > > The bug can best be reproduced by configuring two iked peers with a short > ikelifetime (e.g. 10) and looking for INFORMATIONAL receives on the > responder side. > > > Index: sbin/iked//ikev2.c > === > RCS file: /mount/openbsd/cvs/src/sbin/iked/ikev2.c,v > retrieving revision 1.168 > diff -u -p -u -r1.168 ikev2.c > --- sbin/iked//ikev2.c27 Feb 2019 06:33:56 - 1.168 > +++ sbin/iked//ikev2.c11 Apr 2019 14:09:35 - > @@ -3539,6 +3539,9 @@ ikev2_ikesa_delete(struct iked *env, str > struct ikev2_delete *del; > > if (initiator) { > + /* XXX: Can not have simultaneous INFORMATIONAL exchanges */ > + if (sa->sa_stateflags & IKED_REQ_INF) > + goto done; > /* Send PAYLOAD_DELETE */ > if ((buf = ibuf_static()) == NULL) > goto done; > @@ -3550,6 +3553,7 @@ ikev2_ikesa_delete(struct iked *env, str > if (ikev2_send_ike_e(env, sa, buf, IKEV2_PAYLOAD_DELETE, > IKEV2_EXCHANGE_INFORMATIONAL, 0) == -1) > goto done; > + sa->sa_stateflags |= IKED_REQ_INF; > log_debug("%s: sent delete, closing SA", __func__); > done: > ibuf_release(buf); > This makes my iked connections much more stable. - David
diff - set ipv6 tclass
Hello - ftp, ntpd, and telnet set IPTOS_LOWDELAY/IPTOS_THROUGHPUT for IPv4 sockets. Should we do it for IPv6 as well? I used IPTOS_DCSP_AF21/IPTOS_DSCP_CS1 to match the values ssh uses by default. Thoughts? Index: usr.bin/ftp/ftp.c === RCS file: /cvs/src/usr.bin/ftp/ftp.c,v retrieving revision 1.100 diff -u -p -r1.100 ftp.c --- usr.bin/ftp/ftp.c 22 Aug 2016 16:27:00 - 1.100 +++ usr.bin/ftp/ftp.c 30 Oct 2018 19:31:34 - @@ -257,10 +257,15 @@ hookup(char *host, char *port) code = -1; goto bad; } - if (hisctladdr.sa.sa_family == AF_INET) { + switch (hisctladdr.sa.sa_family) { + case AF_INET: tos = IPTOS_LOWDELAY; - if (setsockopt(s, IPPROTO_IP, IP_TOS, (char *), sizeof(int)) < 0) - warn("setsockopt TOS (ignored)"); + if (setsockopt(s, IPPROTO_IP, IP_TOS, , sizeof(tos)) < 0) + warn("setsockopt IPTOS_LOWDELAY"); + case AF_INET6: + tos = IPTOS_DSCP_AF21; + if (setsockopt(s, IPPROTO_IPV6, IPV6_TCLASS, , sizeof(tos)) < 0) + warn("setsockopt IPTOS_DSCP_AF21"); } cin = fdopen(s, "r"); cout = fdopen(s, "w"); @@ -1524,11 +1529,17 @@ reinit: warn("connect"); goto bad; } - if (data_addr.sa.sa_family == AF_INET) { + switch (data_addr.sa.sa_family) { + case AF_INET: on = IPTOS_THROUGHPUT; - if (setsockopt(data, IPPROTO_IP, IP_TOS, (char *), - sizeof(int)) < 0) - warn("setsockopt TOS (ignored)"); + if (setsockopt(data, IPPROTO_IP, IP_TOS, , + sizeof(on)) < 0) + warn("setsockopt IPTOS_THROUGHPUT"); + case AF_INET6: + on = IPTOS_DSCP_CS1; + if (setsockopt(data, IPPROTO_IPV6, IPV6_TCLASS, , + sizeof(on)) < 0) + warn("setsockopt IPTOS_DSCP_CS1"); } return (0); } @@ -1682,7 +1693,7 @@ dataconn(const char *lmode) { union sockaddr_union from; socklen_t fromlen = myctladdr.sa.sa_len; - int s; + int s, tos; if (passivemode) return (fdopen(data, lmode)); @@ -1695,12 +1706,16 @@ dataconn(const char *lmode) } (void)close(data); data = s; - if (from.sa.sa_family == AF_INET) { - int tos = IPTOS_THROUGHPUT; - if (setsockopt(s, IPPROTO_IP, IP_TOS, (char *), - sizeof(int)) < 0) { - warn("setsockopt TOS (ignored)"); - } + switch (from.sa.sa_family) { + case AF_INET: + tos = IPTOS_THROUGHPUT; + if (setsockopt(s, IPPROTO_IP, IP_TOS, , sizeof(tos)) < 0) + warn("setsockopt IPTOS_THROUGHPUT"); + case AF_INET6: + tos = IPTOS_DSCP_CS1; + if (setsockopt(s, IPPROTO_IPV6, IPV6_TCLASS, , + sizeof(tos)) < 0) + warn("setsockopt IPTOS_DSCP_CS1"); } return (fdopen(data, lmode)); } Index: usr.bin/telnet/commands.c === RCS file: /cvs/src/usr.bin/telnet/commands.c,v retrieving revision 1.86 diff -u -p -r1.86 commands.c --- usr.bin/telnet/commands.c 30 Sep 2018 14:35:32 - 1.86 +++ usr.bin/telnet/commands.c 30 Oct 2018 19:31:35 - @@ -1742,8 +1742,8 @@ tn(int argc, char *argv[]) { struct addrinfo hints, *res, *res0; char *cmd, *hostp = 0, *portp = 0, *user = 0, *aliasp = 0; -int error, retry; -const int niflags = NI_NUMERICHOST, tos = IPTOS_LOWDELAY; +int error, retry, tos; +const int niflags = NI_NUMERICHOST; if (connected) { printf("?Already connected to %s\r\n", hostname); @@ -1870,11 +1870,13 @@ tn(int argc, char *argv[]) switch (res->ai_family) { case AF_INET: + tos = IPTOS_LOWDELAY; if (setsockopt(net, IPPROTO_IP, IP_TOS, , sizeof(tos)) < 0 && errno != ENOPROTOOPT) perror("telnet: setsockopt (IP_TOS) (ignored)"); break; case AF_INET6: + tos = IPTOS_DSCP_AF21; if (setsockopt(net, IPPROTO_IPV6, IPV6_TCLASS, , sizeof(tos)) < 0 && errno != ENOPROTOOPT) perror("telnet: setsockopt (IPV6_TCLASS) (ignored)"); Index: usr.sbin/ntpd/client.c === RCS file: /cvs/src/usr.sbin/ntpd/client.c,v retrieving revision 1.105 diff
diff: split ctloutput into getopt/setopt
Hello - This diff splits the ctloutput functions into getopt/setopt, which could offer more fine-grained locking. It also removes some indentation and imo is easier to read. Thoughts? Index: net/rtsock.c === RCS file: /cvs/src/sys/net/rtsock.c,v retrieving revision 1.279 diff -u -p -r1.279 rtsock.c --- net/rtsock.c10 Jul 2018 20:28:34 - 1.279 +++ net/rtsock.c18 Oct 2018 15:26:28 - @@ -110,6 +110,8 @@ voidrcb_unref(void *, void *); introute_output(struct mbuf *, struct socket *, struct sockaddr *, struct mbuf *); introute_ctloutput(int, struct socket *, int, int, struct mbuf *); +introute_getopt(struct socket *, int, int, struct mbuf *); +introute_setopt(struct socket *, int, int, struct mbuf *); introute_usrreq(struct socket *, int, struct mbuf *, struct mbuf *, struct mbuf *, struct proc *); void route_input(struct mbuf *m0, struct socket *, sa_family_t); @@ -358,69 +360,98 @@ int route_ctloutput(int op, struct socket *so, int level, int optname, struct mbuf *m) { + int error; + + switch (op) { + case PRCO_SETOPT: + error = route_setopt(so, level, optname, m); + break; + case PRCO_GETOPT: + error = route_getopt(so, level, optname, m); + break; + default: + error = EINVAL; + break; + } + + return error; +} + +int +route_setopt(struct socket *so, int level, int optname, struct mbuf *m) +{ struct rtpcb *rop = sotortpcb(so); int error = 0; unsigned int tid, prio; if (level != AF_ROUTE) - return (EINVAL); + return EINVAL; - switch (op) { - case PRCO_SETOPT: - switch (optname) { - case ROUTE_MSGFILTER: - if (m == NULL || m->m_len != sizeof(unsigned int)) - error = EINVAL; - else - rop->rop_msgfilter = *mtod(m, unsigned int *); - break; - case ROUTE_TABLEFILTER: - if (m == NULL || m->m_len != sizeof(unsigned int)) { - error = EINVAL; - break; - } - tid = *mtod(m, unsigned int *); - if (tid != RTABLE_ANY && !rtable_exists(tid)) - error = ENOENT; - else - rop->rop_rtableid = tid; - break; - case ROUTE_PRIOFILTER: - if (m == NULL || m->m_len != sizeof(unsigned int)) { - error = EINVAL; - break; - } - prio = *mtod(m, unsigned int *); - if (prio > RTP_MAX) - error = EINVAL; - else - rop->rop_priority = prio; - break; - default: - error = ENOPROTOOPT; + switch (optname) { + case ROUTE_MSGFILTER: + if (m == NULL || m->m_len != sizeof(unsigned int)) + error = EINVAL; + else + rop->rop_msgfilter = *mtod(m, unsigned int *); + break; + case ROUTE_TABLEFILTER: + if (m == NULL || m->m_len != sizeof(unsigned int)) { + error = EINVAL; break; } + tid = *mtod(m, unsigned int *); + if (tid != RTABLE_ANY && !rtable_exists(tid)) + error = ENOENT; + else + rop->rop_rtableid = tid; break; - case PRCO_GETOPT: - switch (optname) { - case ROUTE_MSGFILTER: - m->m_len = sizeof(unsigned int); - *mtod(m, unsigned int *) = rop->rop_msgfilter; - break; - case ROUTE_TABLEFILTER: - m->m_len = sizeof(unsigned int); - *mtod(m, unsigned int *) = rop->rop_rtableid; - break; - case ROUTE_PRIOFILTER: - m->m_len = sizeof(unsigned int); - *mtod(m, unsigned int *) = rop->rop_priority; - break; - default: - error = ENOPROTOOPT; + case ROUTE_PRIOFILTER: + if (m == NULL || m->m_len != sizeof(unsigned int)) { + error = EINVAL; break; } + prio = *mtod(m, unsigned int *); + if (prio > RTP_MAX) +
re(4) watchdog timeouts - possible fix
Hello - If I start a certain app that sends a large amount of data to many hosts, I get: re0: watchdog timeout re0: watchdog timeout The diff below is what em(4) does and I am no longer able to cause watchdog timeouts on my re(4). Does this seem correct or more of a hack? Index: dev/ic/re.c === RCS file: /cvs/src/sys/dev/ic/re.c,v retrieving revision 1.202 diff -u -p -r1.202 re.c --- dev/ic/re.c 19 Jun 2017 09:36:27 - 1.202 +++ dev/ic/re.c 31 Aug 2018 19:16:16 - @@ -1817,6 +1817,9 @@ re_start(struct ifqueue *ifq) bpf_mtap_ether(ifp->if_bpf, m, BPF_DIRECTION_OUT); #endif + /* Set timeout in case hardware has problems transmitting */ + ifp->if_timer = 5; + KASSERT(used <= free); free -= used; @@ -1830,7 +1833,6 @@ re_start(struct ifqueue *ifq) if (post == 0) return; - ifp->if_timer = 5; sc->rl_ldata.rl_txq_prodidx = idx; ifq_serialize(ifq, >rl_start); }
more netinet bcopy -> mem{cpy|move}
Hello - Two bcopy->memmove conversions where src and dst are in the same memory space. Perhaps not overlapping, but just being safe. Convert the bcopy's in tcp_respond to memcpy since the destination is a new mbuf header. OK? Index: netinet/ip_ah.c === RCS file: /cvs/src/sys/netinet/ip_ah.c,v retrieving revision 1.138 diff -u -p -r1.138 ip_ah.c --- netinet/ip_ah.c 14 Mar 2018 22:38:46 - 1.138 +++ netinet/ip_ah.c 9 Apr 2018 17:48:20 - @@ -899,8 +899,8 @@ ah_input_cb(struct cryptop *crp) * mbuf...do an overlapping copy of the * remainder of the mbuf over the ESP header. */ - bcopy(mtod(m1, u_char *) + roff + rplen + - ahx->authsize, mtod(m1, u_char *) + roff, + memmove(mtod(m1, u_char *) + roff, + mtod(m1, u_char *) + roff + rplen + ahx->authsize, m1->m_len - (roff + rplen + ahx->authsize)); m1->m_len -= rplen + ahx->authsize; m->m_pkthdr.len -= rplen + ahx->authsize; Index: netinet/tcp_subr.c === RCS file: /cvs/src/sys/netinet/tcp_subr.c,v retrieving revision 1.170 diff -u -p -r1.170 tcp_subr.c --- netinet/tcp_subr.c 2 Apr 2018 14:19:17 - 1.170 +++ netinet/tcp_subr.c 9 Apr 2018 17:48:20 - @@ -328,11 +328,11 @@ tcp_respond(struct tcpcb *tp, caddr_t te th = (struct tcphdr *)(ip6 + 1); tlen = sizeof(*ip6) + sizeof(*th); if (th0) { - bcopy(template, ip6, sizeof(*ip6)); - bcopy(th0, th, sizeof(*th)); + memcpy(ip6, template, sizeof(*ip6)); + memcpy(th, th0, sizeof(*th)); xchg(ip6->ip6_dst, ip6->ip6_src, struct in6_addr); } else { - bcopy(template, ip6, tlen); + memcpy(ip6, template, tlen); } break; #endif /* INET6 */ @@ -341,11 +341,11 @@ tcp_respond(struct tcpcb *tp, caddr_t te th = (struct tcphdr *)(ip + 1); tlen = sizeof(*ip) + sizeof(*th); if (th0) { - bcopy(template, ip, sizeof(*ip)); - bcopy(th0, th, sizeof(*th)); + memcpy(ip, template, sizeof(*ip)); + memcpy(th, th0, sizeof(*th)); xchg(ip->ip_dst.s_addr, ip->ip_src.s_addr, u_int32_t); } else { - bcopy(template, ip, tlen); + memcpy(ip, template, tlen); } break; } Index: netinet/udp_usrreq.c === RCS file: /cvs/src/sys/netinet/udp_usrreq.c,v retrieving revision 1.246 diff -u -p -r1.246 udp_usrreq.c --- netinet/udp_usrreq.c6 Apr 2018 10:59:11 - 1.246 +++ netinet/udp_usrreq.c9 Apr 2018 17:48:20 - @@ -295,8 +295,8 @@ udp_input(struct mbuf **mp, int *offp, i } /* remove the UDP header */ - bcopy(mtod(m, u_char *), - mtod(m, u_char *) + sizeof(struct udphdr), iphlen); + memmove(mtod(m, u_char *) + sizeof(struct udphdr), + mtod(m, u_char *), iphlen); m_adj(m, sizeof(struct udphdr)); skip -= sizeof(struct udphdr);
Re: ufs free()
On Sat, Mar 31, 2018 at 11:15:35PM +0200, Christian Weisgerber wrote: > David Hill: > > > This diff adds sizes to free(), which completes ufs/ffs. > > It's broken at least for softdep+UFS2. This chunk blows up: > > > --- ufs/ffs/ffs_softdep.c 10 Feb 2018 05:24:23 - 1.138 > > +++ ufs/ffs/ffs_softdep.c 29 Mar 2018 02:55:37 - > > @@ -4034,7 +4036,8 @@ handle_written_inodeblock(struct inodede > > *dp1 = *inodedep->id_savedino1; > > else > > *dp2 = *inodedep->id_savedino2; > > - free(inodedep->id_savedino1, M_INODEDEP, 0); > > + free(inodedep->id_savedino1, M_INODEDEP, > > + sizeof(struct ufs1_dinode)); > > inodedep->id_savedino1 = NULL; > > if ((bp->b_flags & B_DELWRI) == 0) > > stat_inode_bitmap++; > > panic: free: size too small 128 <= 256 / 2 (0x8099a700) type inodedep > Stopped at db_enter+0x5: popq%rbp > TIDPIDUID PRFLAGS PFLAGS CPU COMMAND > db_enter() at db_enter+0x5 > panic() at panic+0x129 > free(ff07259d97c8,ff07259d97c8,ff071c6d4ef8) at free+0x35b > handle_written_inodeblock(ff07259d97c8,ff071c6d4e00) at > handle_written_ > inodeblock+0x1b5 > softdep_disk_write_complete(ff071c6d4e00) at > softdep_disk_write_complete+0x > 255 > biodone(ff071bd999e8) at biodone+0x73 > > id_savedino1 and id_savedino2 are a union, so it's pretty clear > that the free() needs to distinguish between the UFS1 and UFS2 cases > like the preceding lines do. > > I don't know if check_inode_unwritten() needs to make the same > distinction: > > > @@ -2307,7 +2307,8 @@ check_inode_unwritten(struct inodedep *i > > if (inodedep->id_state & ONWORKLIST) > > WORKLIST_REMOVE(>id_list); > > if (inodedep->id_savedino1 != NULL) { > > - free(inodedep->id_savedino1, M_INODEDEP, 0); > > + free(inodedep->id_savedino1, M_INODEDEP, > > + sizeof(struct ufs1_dinode)); > > inodedep->id_savedino1 = NULL; > > } > > if (free_inodedep(inodedep) == 0) { > > -- > Christian "naddy" Weisgerber na...@mips.inka.de > Can you try this diff? Index: ufs/ffs/ffs_softdep.c === RCS file: /cvs/src/sys/ufs/ffs/ffs_softdep.c,v retrieving revision 1.139 diff -u -p -r1.139 ffs_softdep.c --- ufs/ffs/ffs_softdep.c 30 Mar 2018 17:35:20 - 1.139 +++ ufs/ffs/ffs_softdep.c 1 Apr 2018 00:55:10 - @@ -2291,6 +2291,8 @@ softdep_freefile(struct vnode *pvp, ufsi STATIC int check_inode_unwritten(struct inodedep *inodedep) { + size_t freesize; + splassert(IPL_BIO); if ((inodedep->id_state & DEPCOMPLETE) != 0 || @@ -2307,8 +2309,11 @@ check_inode_unwritten(struct inodedep *i if (inodedep->id_state & ONWORKLIST) WORKLIST_REMOVE(>id_list); if (inodedep->id_savedino1 != NULL) { - free(inodedep->id_savedino1, M_INODEDEP, - sizeof(struct ufs1_dinode)); + if (inodedep->id_fs->fs_magic == FS_UFS1_MAGIC) + freesize = sizeof(struct ufs1_dinode); + else + freesize = sizeof(struct ufs2_dinode); + free(inodedep->id_savedino1, M_INODEDEP, freesize); inodedep->id_savedino1 = NULL; } if (free_inodedep(inodedep) == 0) { @@ -4006,6 +4011,7 @@ handle_written_inodeblock(struct inodede struct ufs1_dinode *dp1 = NULL; struct ufs2_dinode *dp2 = NULL; int hadchanges, fstype; + size_t freesize; splassert(IPL_BIO); @@ -4015,10 +4021,12 @@ handle_written_inodeblock(struct inodede if (inodedep->id_fs->fs_magic == FS_UFS1_MAGIC) { fstype = UM_UFS1; + freesize = sizeof(struct ufs1_dinode); dp1 = (struct ufs1_dinode *) bp->b_data + ino_to_fsbo(inodedep->id_fs, inodedep->id_ino); } else { fstype = UM_UFS2; + freesize = sizeof(struct ufs2_dinode); dp2 = (struct ufs2_dinode *) bp->b_data + ino_to_fsbo(inodedep->id_fs, inodedep->id_ino); } @@ -4035,8 +4043,7 @@ handle_written_inodeblock(struct inodede *dp1 = *inodedep->id_savedino1; else *dp2 = *inodedep->id_savedino2; - free(inodedep->id_savedino1, M_INODEDEP, - sizeof(struct ufs1_dinode)); + free(inodedep->id_savedino1, M_INODEDEP, freesize); inodedep->id_savedino1 = NULL; if ((bp->b_flags & B_DELWRI) == 0) stat_inode_bitmap++;
arch/amd64 free
Hello - This diff is more involved. In est_acpi_pss_changed, a new table is allocated but n isn't updated, which keep tracks of the number allocated. Set it. In est_init, fake_table was being allocated with 3. Change that to allocate exactly what is need by setting n earlier. Regarding the isa/ section, in _isa_bus_dmamap_create, cookiesize is: cookiesize = sizeof(struct isa_dma_cookie); ... if ((avail_end > ISA_DMA_BOUNCE_THRESHOLD && (flags & ISABUS_DMA_32BIT) == 0) || ((map->_dm_size / NBPG) + 1) > map->_dm_segcnt) { cookieflags |= ID_MIGHT_NEED_BOUNCE; cookiesize += (sizeof(bus_dma_segment_t) * map->_dm_segcnt); } so I am assuming if ID_MIGHT_NEED_BOUNCE is set, that cookiesize gets they larger size. OK? Index: arch/amd64/amd64/est.c === RCS file: /cvs/src/sys/arch/amd64/amd64/est.c,v retrieving revision 1.39 diff -u -p -r1.39 est.c --- arch/amd64/amd64/est.c 6 Mar 2016 22:41:24 - 1.39 +++ arch/amd64/amd64/est.c 31 Mar 2018 19:11:48 - @@ -284,6 +284,7 @@ est_acpi_pss_changed(struct acpicpu_pss free(acpilist, M_DEVBUF, sizeof(struct fqlist)); return; } + acpilist->n = npss; for (i = 0; i < npss; i++) { acpilist->table[i].mhz = pss[i].pss_core_freq; @@ -377,10 +378,13 @@ est_init(struct cpu_info *ci) "list\n", cpu_device); return; } + if (cur == idhi || cur == idlo) + fake_fqlist->n = 2; + else + fake_fqlist->n = 3; - - if ((fake_table = mallocarray(3, sizeof(struct est_op), - M_DEVBUF, M_NOWAIT)) == NULL) { + if ((fake_table = mallocarray(fake_fqlist->n, + sizeof(struct est_op), M_DEVBUF, M_NOWAIT)) == NULL) { free(fake_fqlist, M_DEVBUF, sizeof(struct fqlist)); printf("%s: EST: cannot allocate memory for fake " "table\n", cpu_device); @@ -388,13 +392,12 @@ est_init(struct cpu_info *ci) } fake_table[0].ctrl = idhi; fake_table[0].mhz = MSR2MHZ(idhi, bus_clock); - if (cur == idhi || cur == idlo) { + if (fake_fqlist->n == 2) { printf("%s: using only highest and lowest power " "states\n", cpu_device); fake_table[1].ctrl = idlo; fake_table[1].mhz = MSR2MHZ(idlo, bus_clock); - fake_fqlist->n = 2; } else { printf("%s: using only highest, current and lowest " "power states\n", cpu_device); @@ -404,7 +407,6 @@ est_init(struct cpu_info *ci) fake_table[2].ctrl = idlo; fake_table[2].mhz = MSR2MHZ(idlo, bus_clock); - fake_fqlist->n = 3; } fake_fqlist->vendor = vendor; @@ -441,7 +443,7 @@ est_init(struct cpu_info *ci) return; nospeedstep: - free(est_fqlist->table, M_DEVBUF, 0); + free(est_fqlist->table, M_DEVBUF, est_fqlist->n * sizeof(struct est_op)); free(est_fqlist, M_DEVBUF, sizeof(*est_fqlist)); } Index: arch/amd64/isa/isa_machdep.c === RCS file: /cvs/src/sys/arch/amd64/isa/isa_machdep.c,v retrieving revision 1.29 diff -u -p -r1.29 isa_machdep.c --- arch/amd64/isa/isa_machdep.c14 Oct 2017 04:44:43 - 1.29 +++ arch/amd64/isa/isa_machdep.c31 Mar 2018 19:11:48 - @@ -455,6 +455,7 @@ void _isa_bus_dmamap_destroy(bus_dma_tag_t t, bus_dmamap_t map) { struct isa_dma_cookie *cookie = map->_dm_cookie; + size_t cookiesize = sizeof(struct isa_dma_cookie); /* * Free any bounce pages this map might hold. @@ -462,7 +463,10 @@ _isa_bus_dmamap_destroy(bus_dma_tag_t t, if (cookie->id_flags & ID_HAS_BOUNCE) _isa_dma_free_bouncebuf(t, map); - free(cookie, M_DEVBUF, 0); + if (cookie->id_flags & ID_MIGHT_NEED_BOUNCE) + cookiesize += (sizeof(bus_dma_segment_t) * map->_dm_segcnt); + + free(cookie, M_DEVBUF, cookiesize); _bus_dmamap_destroy(t, map); }
mfs free
Add the free size. (allocated in mfs_vfsops.c) mfsp = malloc(sizeof *mfsp, M_MFSNODE, M_WAITOK | M_ZERO); devvp->v_data = mfsp; OK? Index: ufs/mfs/mfs_vnops.c === RCS file: /cvs/src/sys/ufs/mfs/mfs_vnops.c,v retrieving revision 1.49 diff -u -p -r1.49 mfs_vnops.c --- ufs/mfs/mfs_vnops.c 7 Nov 2016 00:26:33 - 1.49 +++ ufs/mfs/mfs_vnops.c 31 Mar 2018 19:11:58 - @@ -238,7 +238,7 @@ mfs_reclaim(void *v) struct vop_reclaim_args *ap = v; struct vnode *vp = ap->a_vp; - free(vp->v_data, M_MFSNODE, 0); + free(vp->v_data, M_MFSNODE, sizeof(struct mfsnode)); vp->v_data = NULL; return (0); }
netinet memcpy/free
Hello - memcpy can be used on freshly allocated memory. Fill in the free size for it. OK? Index: netinet/tcp_subr.c === RCS file: /cvs/src/sys/netinet/tcp_subr.c,v retrieving revision 1.169 diff -u -p -r1.169 tcp_subr.c --- netinet/tcp_subr.c 18 Mar 2018 21:05:21 - 1.169 +++ netinet/tcp_subr.c 31 Mar 2018 19:12:04 - @@ -952,7 +952,7 @@ tcp_signature_tdb_init(struct tdb *tdbp, tdbp->tdb_amxkey = malloc(ii->ii_authkeylen, M_XDATA, M_NOWAIT); if (tdbp->tdb_amxkey == NULL) return (ENOMEM); - bcopy(ii->ii_authkey, tdbp->tdb_amxkey, ii->ii_authkeylen); + memcpy(tdbp->tdb_amxkey, ii->ii_authkey, ii->ii_authkeylen); tdbp->tdb_amxkeylen = ii->ii_authkeylen; return (0); @@ -963,7 +963,7 @@ tcp_signature_tdb_zeroize(struct tdb *td { if (tdbp->tdb_amxkey) { explicit_bzero(tdbp->tdb_amxkey, tdbp->tdb_amxkeylen); - free(tdbp->tdb_amxkey, M_XDATA, 0); + free(tdbp->tdb_amxkey, M_XDATA, tdbp->tdb_amxkeylen); tdbp->tdb_amxkey = NULL; }
ufs free()
Hello - This diff adds sizes to free(), which completes ufs/ffs. OK? Index: ufs/ffs/ffs_inode.c === RCS file: /cvs/src/sys/ufs/ffs/ffs_inode.c,v retrieving revision 1.76 diff -u -p -r1.76 ffs_inode.c --- ufs/ffs/ffs_inode.c 27 Feb 2016 18:50:38 - 1.76 +++ ufs/ffs/ffs_inode.c 29 Mar 2018 02:55:36 - @@ -560,7 +560,7 @@ ffs_indirtrunc(struct inode *ip, daddr_t } } if (copy != NULL) { - free(copy, M_TEMP, 0); + free(copy, M_TEMP, fs->fs_bsize); } else { bp->b_flags |= B_INVAL; brelse(bp); Index: ufs/ffs/ffs_softdep.c === RCS file: /cvs/src/sys/ufs/ffs/ffs_softdep.c,v retrieving revision 1.138 diff -u -p -r1.138 ffs_softdep.c --- ufs/ffs/ffs_softdep.c 10 Feb 2018 05:24:23 - 1.138 +++ ufs/ffs/ffs_softdep.c 29 Mar 2018 02:55:37 - @@ -2307,7 +2307,8 @@ check_inode_unwritten(struct inodedep *i if (inodedep->id_state & ONWORKLIST) WORKLIST_REMOVE(>id_list); if (inodedep->id_savedino1 != NULL) { - free(inodedep->id_savedino1, M_INODEDEP, 0); + free(inodedep->id_savedino1, M_INODEDEP, + sizeof(struct ufs1_dinode)); inodedep->id_savedino1 = NULL; } if (free_inodedep(inodedep) == 0) { @@ -3845,7 +3846,8 @@ softdep_disk_write_complete(struct buf * if (indirdep->ir_state & GOINGAWAY) panic("disk_write_complete: indirdep gone"); memcpy(bp->b_data, indirdep->ir_saveddata, bp->b_bcount); - free(indirdep->ir_saveddata, M_INDIRDEP, 0); + free(indirdep->ir_saveddata, M_INDIRDEP, + sizeof(struct ufs1_dinode)); indirdep->ir_saveddata = NULL; indirdep->ir_state &= ~UNDONE; indirdep->ir_state |= ATTACHED; @@ -4034,7 +4036,8 @@ handle_written_inodeblock(struct inodede *dp1 = *inodedep->id_savedino1; else *dp2 = *inodedep->id_savedino2; - free(inodedep->id_savedino1, M_INODEDEP, 0); + free(inodedep->id_savedino1, M_INODEDEP, + sizeof(struct ufs1_dinode)); inodedep->id_savedino1 = NULL; if ((bp->b_flags & B_DELWRI) == 0) stat_inode_bitmap++; Index: ufs/ffs/ffs_vfsops.c === RCS file: /cvs/src/sys/ufs/ffs/ffs_vfsops.c,v retrieving revision 1.173 diff -u -p -r1.173 ffs_vfsops.c --- ufs/ffs/ffs_vfsops.c15 Mar 2018 04:22:16 - 1.173 +++ ufs/ffs/ffs_vfsops.c29 Mar 2018 02:55:37 - @@ -447,7 +447,7 @@ success: fs->fs_clean = ronly && (fs->fs_flags & FS_UNCLEAN) == 0 ? 1 : 0; if (ronly) - free(fs->fs_contigdirs, M_UFSMNT, 0); + free(fs->fs_contigdirs, M_UFSMNT, fs->fs_ncg); } if (!ronly) { if (mp->mnt_flag & MNT_SOFTDEP) @@ -837,7 +837,7 @@ ffs_mountfs(struct vnode *devvp, struct size = (blks - i) * fs->fs_fsize; error = bread(devvp, fsbtodb(fs, fs->fs_csaddr + i), size, ); if (error) { - free(fs->fs_csp, M_UFSMNT, 0); + free(fs->fs_csp, M_UFSMNT, fs->fs_cssize); goto out; } memcpy(space, bp->b_data, size); @@ -910,8 +910,8 @@ ffs_mountfs(struct vnode *devvp, struct if (ronly == 0) { if ((fs->fs_flags & FS_DOSOFTDEP) && (error = softdep_mount(devvp, mp, fs, cred)) != 0) { - free(fs->fs_csp, M_UFSMNT, 0); - free(fs->fs_contigdirs, M_UFSMNT, 0); + free(fs->fs_csp, M_UFSMNT, fs->fs_cssize); + free(fs->fs_contigdirs, M_UFSMNT, fs->fs_ncg); goto out; } fs->fs_fmod = 1; @@ -1046,7 +1046,7 @@ ffs_unmount(struct mount *mp, int mntfla fs->fs_clean = 0; return (error); } - free(fs->fs_contigdirs, M_UFSMNT, 0); + free(fs->fs_contigdirs, M_UFSMNT, fs->fs_ncg); } ump->um_devvp->v_specmountpoint = NULL; @@ -1055,7 +1055,7 @@ ffs_unmount(struct mount *mp, int mntfla (void)VOP_CLOSE(ump->um_devvp, fs->fs_ronly ? FREAD : FREAD|FWRITE, NOCRED, p); vput(ump->um_devvp); - free(fs->fs_csp, M_UFSMNT, 0); + free(fs->fs_csp, M_UFSMNT,
Re: use hashfree on pcb hash tables
round #2. keep track of size (num of elements) in the inpcbtable struct. passes regress tests. OK? Index: netinet/in_pcb.c === RCS file: /cvs/src/sys/netinet/in_pcb.c,v retrieving revision 1.228 diff -u -p -r1.228 in_pcb.c --- netinet/in_pcb.c19 Feb 2018 08:59:53 - 1.228 +++ netinet/in_pcb.c29 Mar 2018 02:21:34 - @@ -206,6 +206,7 @@ in_pcbinit(struct inpcbtable *table, int if (table->inpt_lhashtbl == NULL) panic("in_pcbinit: hashinit failed for lport"); table->inpt_count = 0; + table->inpt_size = hashsize; arc4random_buf(>inpt_key, sizeof(table->inpt_key)); } @@ -998,32 +999,34 @@ int in_pcbresize(struct inpcbtable *table, int hashsize) { u_long nhash, nlhash; + int osize; void *nhashtbl, *nlhashtbl, *ohashtbl, *olhashtbl; struct inpcb *inp0, *inp1; ohashtbl = table->inpt_hashtbl; olhashtbl = table->inpt_lhashtbl; + osize = table->inpt_size; nhashtbl = hashinit(hashsize, M_PCB, M_NOWAIT, ); + if (nhashtbl == NULL) + return ENOBUFS; nlhashtbl = hashinit(hashsize, M_PCB, M_NOWAIT, ); - if (nhashtbl == NULL || nlhashtbl == NULL) { - if (nhashtbl != NULL) - free(nhashtbl, M_PCB, 0); - if (nlhashtbl != NULL) - free(nlhashtbl, M_PCB, 0); - return (ENOBUFS); + if (nlhashtbl == NULL) { + hashfree(nhashtbl, hashsize, M_PCB); + return ENOBUFS; } table->inpt_hashtbl = nhashtbl; table->inpt_lhashtbl = nlhashtbl; table->inpt_hash = nhash; table->inpt_lhash = nlhash; + table->inpt_size = hashsize; arc4random_buf(>inpt_key, sizeof(table->inpt_key)); TAILQ_FOREACH_SAFE(inp0, >inpt_queue, inp_queue, inp1) { in_pcbrehash(inp0); } - free(ohashtbl, M_PCB, 0); - free(olhashtbl, M_PCB, 0); + hashfree(ohashtbl, osize, M_PCB); + hashfree(olhashtbl, osize, M_PCB); return (0); } Index: netinet/in_pcb.h === RCS file: /cvs/src/sys/netinet/in_pcb.h,v retrieving revision 1.106 diff -u -p -r1.106 in_pcb.h --- netinet/in_pcb.h1 Dec 2017 10:33:33 - 1.106 +++ netinet/in_pcb.h29 Mar 2018 02:21:34 - @@ -152,7 +152,7 @@ struct inpcbtable { struct inpcbhead *inpt_hashtbl, *inpt_lhashtbl; SIPHASH_KEY inpt_key; u_longinpt_hash, inpt_lhash; - int inpt_count; + int inpt_count, inpt_size; }; /* flags in inp_flags: */
Re: use hashfree on pcb hash tables
Ignore for now. A lovely regress/ test exposes a problem in my diff. :) On Tue, Mar 27, 2018 at 01:11:19PM -0400, David Hill wrote: > Hello - > > The hash tables are allocated with hashinit, so free them with hashfree. > This gives the bonus of calling free() with a size as well. >
use hashfree on pcb hash tables
Hello - The hash tables are allocated with hashinit, so free them with hashfree. This gives the bonus of calling free() with a size as well. OK? Index: in_pcb.c === RCS file: /cvs/src/sys/netinet/in_pcb.c,v retrieving revision 1.228 diff -u -p -r1.228 in_pcb.c --- in_pcb.c19 Feb 2018 08:59:53 - 1.228 +++ in_pcb.c27 Mar 2018 17:06:51 - @@ -997,20 +997,21 @@ in_pcbrehash(struct inpcb *inp) int in_pcbresize(struct inpcbtable *table, int hashsize) { - u_long nhash, nlhash; + u_long nhash, nlhash, ohash, olhash; void *nhashtbl, *nlhashtbl, *ohashtbl, *olhashtbl; struct inpcb *inp0, *inp1; ohashtbl = table->inpt_hashtbl; + ohash = table->inpt_hash; olhashtbl = table->inpt_lhashtbl; + olhash = table->inpt_lhash; nhashtbl = hashinit(hashsize, M_PCB, M_NOWAIT, ); + if (nhashtbl == NULL) + return (ENOBUFS); nlhashtbl = hashinit(hashsize, M_PCB, M_NOWAIT, ); - if (nhashtbl == NULL || nlhashtbl == NULL) { - if (nhashtbl != NULL) - free(nhashtbl, M_PCB, 0); - if (nlhashtbl != NULL) - free(nlhashtbl, M_PCB, 0); + if (nlhashtbl == NULL) { + hashfree(nhashtbl, nhash, M_PCB); return (ENOBUFS); } table->inpt_hashtbl = nhashtbl; @@ -1022,8 +1023,8 @@ in_pcbresize(struct inpcbtable *table, i TAILQ_FOREACH_SAFE(inp0, >inpt_queue, inp_queue, inp1) { in_pcbrehash(inp0); } - free(ohashtbl, M_PCB, 0); - free(olhashtbl, M_PCB, 0); + hashfree(ohashtbl, ohash, M_PCB); + hashfree(olhashtbl, olhash, M_PCB); return (0); }
netinet bcopy -> memcpy/memmove
Hello - A few bcopy conversions to memcpy where the memory does not overlap, otherwise memmove. OK? Index: netinet/ip_ah.c === RCS file: /cvs/src/sys/netinet/ip_ah.c,v retrieving revision 1.138 diff -u -p -r1.138 ip_ah.c --- netinet/ip_ah.c 14 Mar 2018 22:38:46 - 1.138 +++ netinet/ip_ah.c 27 Mar 2018 16:10:03 - @@ -899,8 +899,8 @@ ah_input_cb(struct cryptop *crp) * mbuf...do an overlapping copy of the * remainder of the mbuf over the ESP header. */ - bcopy(mtod(m1, u_char *) + roff + rplen + - ahx->authsize, mtod(m1, u_char *) + roff, + memmove(mtod(m1, u_char *) + roff, + mtod(m1, u_char *) + roff + rplen + ahx->authsize, m1->m_len - (roff + rplen + ahx->authsize)); m1->m_len -= rplen + ahx->authsize; m->m_pkthdr.len -= rplen + ahx->authsize; Index: netinet/tcp_subr.c === RCS file: /cvs/src/sys/netinet/tcp_subr.c,v retrieving revision 1.169 diff -u -p -r1.169 tcp_subr.c --- netinet/tcp_subr.c 18 Mar 2018 21:05:21 - 1.169 +++ netinet/tcp_subr.c 27 Mar 2018 16:10:03 - @@ -328,11 +328,11 @@ tcp_respond(struct tcpcb *tp, caddr_t te th = (struct tcphdr *)(ip6 + 1); tlen = sizeof(*ip6) + sizeof(*th); if (th0) { - bcopy(template, ip6, sizeof(*ip6)); - bcopy(th0, th, sizeof(*th)); + memcpy(ip6, template, sizeof(*ip6)); + memcpy(th, th0, sizeof(*th)); xchg(ip6->ip6_dst, ip6->ip6_src, struct in6_addr); } else { - bcopy(template, ip6, tlen); + memcpy(ip6, template, tlen); } break; #endif /* INET6 */ @@ -341,11 +341,11 @@ tcp_respond(struct tcpcb *tp, caddr_t te th = (struct tcphdr *)(ip + 1); tlen = sizeof(*ip) + sizeof(*th); if (th0) { - bcopy(template, ip, sizeof(*ip)); - bcopy(th0, th, sizeof(*th)); + memcpy(ip, template, sizeof(*ip)); + memcpy(th, th0, sizeof(*th)); xchg(ip->ip_dst.s_addr, ip->ip_src.s_addr, u_int32_t); } else { - bcopy(template, ip, tlen); + memcpy(ip, template, tlen); } break; } @@ -952,7 +952,7 @@ tcp_signature_tdb_init(struct tdb *tdbp, tdbp->tdb_amxkey = malloc(ii->ii_authkeylen, M_XDATA, M_NOWAIT); if (tdbp->tdb_amxkey == NULL) return (ENOMEM); - bcopy(ii->ii_authkey, tdbp->tdb_amxkey, ii->ii_authkeylen); + memcpy(tdbp->tdb_amxkey, ii->ii_authkey, ii->ii_authkeylen); tdbp->tdb_amxkeylen = ii->ii_authkeylen; return (0); Index: netinet/udp_usrreq.c === RCS file: /cvs/src/sys/netinet/udp_usrreq.c,v retrieving revision 1.245 diff -u -p -r1.245 udp_usrreq.c --- netinet/udp_usrreq.c1 Dec 2017 10:33:33 - 1.245 +++ netinet/udp_usrreq.c27 Mar 2018 16:10:03 - @@ -295,8 +295,8 @@ udp_input(struct mbuf **mp, int *offp, i } /* remove the UDP header */ - bcopy(mtod(m, u_char *), - mtod(m, u_char *) + sizeof(struct udphdr), iphlen); + memmove(mtod(m, u_char *) + sizeof(struct udphdr), + mtod(m, u_char *), iphlen); m_adj(m, sizeof(struct udphdr)); skip -= sizeof(struct udphdr);
netinet6 - bcopy -> memcpy
Hello - A few bcopy to memcpy conversions where the memory does not overlap. OK? Index: netinet6/icmp6.c === RCS file: /cvs/src/sys/netinet6/icmp6.c,v retrieving revision 1.221 diff -u -p -r1.221 icmp6.c --- netinet6/icmp6.c14 Dec 2017 14:26:50 - 1.221 +++ netinet6/icmp6.c13 Mar 2018 21:32:32 - @@ -1075,7 +1075,7 @@ icmp6_reflect(struct mbuf *m, size_t off if ((m = m_pullup(m, l)) == NULL) return; } - bcopy((caddr_t), mtod(m, caddr_t), sizeof(nip6)); + memcpy(mtod(m, caddr_t), (caddr_t), sizeof(nip6)); } else /* off == sizeof(struct ip6_hdr) */ { size_t l; l = sizeof(struct ip6_hdr) + sizeof(struct icmp6_hdr); @@ -1268,7 +1268,7 @@ icmp6_redirect_input(struct mbuf *m, int bzero(, sizeof(sin6)); sin6.sin6_family = AF_INET6; sin6.sin6_len = sizeof(struct sockaddr_in6); - bcopy(, _addr, sizeof(reddst6)); + memcpy(_addr, , sizeof(reddst6)); rt = rtalloc(sin6tosa(), 0, m->m_pkthdr.ph_rtableid); if (rt) { if (rt->rt_gateway == NULL || @@ -1376,9 +1376,9 @@ icmp6_redirect_input(struct mbuf *m, int sdst.sin6_family = sgw.sin6_family = ssrc.sin6_family = AF_INET6; sdst.sin6_len = sgw.sin6_len = ssrc.sin6_len = sizeof(struct sockaddr_in6); - bcopy(, _addr, sizeof(struct in6_addr)); - bcopy(, _addr, sizeof(struct in6_addr)); - bcopy(, _addr, sizeof(struct in6_addr)); + memcpy(_addr, , sizeof(struct in6_addr)); + memcpy(_addr, , sizeof(struct in6_addr)); + memcpy(_addr, , sizeof(struct in6_addr)); rtredirect(sin6tosa(), sin6tosa(), sin6tosa(), , m->m_pkthdr.ph_rtableid); @@ -1395,7 +1395,7 @@ icmp6_redirect_input(struct mbuf *m, int bzero(, sizeof(sdst)); sdst.sin6_family = AF_INET6; sdst.sin6_len = sizeof(struct sockaddr_in6); - bcopy(, _addr, sizeof(struct in6_addr)); + memcpy(_addr, , sizeof(struct in6_addr)); pfctlinput(PRC_REDIRECT_HOST, sin6tosa()); } Index: netinet6/in6_ifattach.c === RCS file: /cvs/src/sys/netinet6/in6_ifattach.c,v retrieving revision 1.106 diff -u -p -r1.106 in6_ifattach.c --- netinet6/in6_ifattach.c 13 Mar 2018 13:58:03 - 1.106 +++ netinet6/in6_ifattach.c 13 Mar 2018 21:32:33 - @@ -165,7 +165,7 @@ in6_get_hw_ifid(struct ifnet *ifp, struc /* make EUI64 address */ if (addrlen == 8) - bcopy(addr, >s6_addr[8], 8); + memcpy(>s6_addr[8], addr, 8); else if (addrlen == 6) { in6->s6_addr[8] = addr[0]; in6->s6_addr[9] = addr[1]; @@ -244,7 +244,7 @@ in6_get_soii_ifid(struct ifnet *ifp, str SHA512Update(, ip6_soiikey, sizeof(ip6_soiikey)); SHA512Final(digest, ); - bcopy(digest + (sizeof(digest) - 8), >s6_addr[8], 8); + memcpy(>s6_addr[8], digest + (sizeof(digest) - 8), 8); return 0; } @@ -464,7 +464,7 @@ in6_nigroup(struct ifnet *ifp, const cha sa6->sin6_addr.s6_addr16[0] = htons(0xff02); sa6->sin6_addr.s6_addr16[1] = htons(ifp->if_index); sa6->sin6_addr.s6_addr8[11] = 2; - bcopy(digest, >sin6_addr.s6_addr32[3], + memcpy(>sin6_addr.s6_addr32[3], digest, sizeof(sa6->sin6_addr.s6_addr32[3])); return 0; Index: netinet6/ip6_output.c === RCS file: /cvs/src/sys/netinet6/ip6_output.c,v retrieving revision 1.234 diff -u -p -r1.234 ip6_output.c --- netinet6/ip6_output.c 19 Feb 2018 08:59:53 - 1.234 +++ netinet6/ip6_output.c 13 Mar 2018 21:32:33 - @@ -850,7 +850,7 @@ ip6_copyexthdr(struct mbuf **mp, caddr_t } m->m_len = hlen; if (hdr) - bcopy(hdr, mtod(m, caddr_t), hlen); + memcpy(mtod(m, caddr_t), hdr, hlen); *mp = m; return (0); @@ -918,7 +918,7 @@ ip6_insert_jumboopt(struct ip6_exthdrs * if (!n) return (ENOBUFS); n->m_len = oldoptlen + JUMBOOPTLEN; - bcopy(mtod(mopt, caddr_t), mtod(n, caddr_t), + memcpy(mtod(n, caddr_t), mtod(mopt, caddr_t), oldoptlen); optbuf = mtod(n, u_int8_t *) + oldoptlen; m_freem(mopt);
Re: tcp timeout milliseconds
OK dhill@ On Tue, Feb 06, 2018 at 05:10:17PM +0100, Alexander Bluhm wrote: > Hi, > > Historically TCP timeouts were implemented with pr_slowtimo and > pr_fasttimo. That is the reason why we have two timeout mechanisms > with complicated ticks calculation. > > I would like to move to milliseconds and merge them eventually. > This makes it easier to see the actual values. > > Let's get rid of some easy ticks and hz. > > ok? > > bluhm >
Re: pf statekey inp assertion failed
On Wed, Jun 21, 2017 at 01:21:50AM +0200, Alexander Bluhm wrote: > Hi, > > I saw a crash on an OpenBSD 6.1 based system when a kassert in > pf_state_key_unref() was triggert. > > kernel diagnostic assertion "(sk->inp == NULL) || (sk->inp->inp_pf_sk == > NULL)" > failed: file "../../../../../net/pf.c", line 7155 > > > panic() at panic+0xfe > > __assert() at __assert+0x25 > > pf_state_key_unref() at pf_state_key_unref+0xc6 > > pf_pkt_unlink_state_key() at pf_pkt_unlink_state_key+0x15 > > m_free() at m_free+0xc0 > > soreceive() at soreceive+0xb5d > > recvit() at recvit+0x13a > > sys_recvmsg() at sys_recvmsg+0x107 > > syscall() at syscall+0x2df > > > The problem is that setting the inp pointer in the statekey to NULL > is delayed until the statekey refcounter reaches 0. So the inp > could get linked to another statekey while the mbuf in the socket > buffer was keeping the refcounter at 1. > > The sk->inp should be set to NULL immediately, then the kassert can > get even stricter. > > ok? ok!! dhill@ I hit this too. See bugs@ archives :) > > bluhm > > Index: net/pf.c > === > RCS file: /data/mirror/openbsd/cvs/src/sys/net/pf.c,v > retrieving revision 1.1034 > diff -u -p -r1.1034 pf.c > --- net/pf.c 5 Jun 2017 22:18:28 - 1.1034 > +++ net/pf.c 20 Jun 2017 22:37:43 - > @@ -779,6 +779,7 @@ pf_state_key_detach(struct pf_state *s, > sk->removed = 1; > pf_state_key_unlink_reverse(sk); > pf_inpcb_unlink_state_key(sk->inp); > + sk->inp = NULL; > pf_state_key_unref(sk); > } > } > @@ -7147,8 +7148,7 @@ pf_state_key_unref(struct pf_state_key * > /* state key must be unlinked from reverse key */ > KASSERT(sk->reverse == NULL); > /* state key must be unlinked from socket */ > - KASSERT((sk->inp == NULL) || (sk->inp->inp_pf_sk == NULL)); > - sk->inp = NULL; > + KASSERT(sk->inp == NULL); > pool_put(_state_key_pl, sk); > } > } >
ip_esp/ip_mroute bcopy->mem*
Hello - Convert bcopy to memcpy where the memory does not overlap, otherwise, use memmove. While here, change some previous conversions to a simple assignment. OK? Index: ip_esp.c === RCS file: /cvs/src/sys/netinet/ip_esp.c,v retrieving revision 1.146 diff -u -p -r1.146 ip_esp.c --- ip_esp.c7 Feb 2017 18:18:16 - 1.146 +++ ip_esp.c6 Apr 2017 15:21:27 - @@ -504,7 +504,7 @@ esp_input(struct mbuf *m, struct tdb *td tc->tc_spi = tdb->tdb_spi; tc->tc_proto = tdb->tdb_sproto; tc->tc_rdomain = tdb->tdb_rdomain; - memcpy(>tc_dst, >tdb_dst, sizeof(union sockaddr_union)); + tc->tc_dst = tdb->tdb_dst; /* Decryption descriptor */ if (espx) { @@ -707,8 +707,9 @@ esp_input_cb(struct cryptop *crp) * overlapping copy of the remainder of the mbuf over the ESP * header. */ - bcopy(mtod(m1, u_char *) + roff + hlen, - mtod(m1, u_char *) + roff, m1->m_len - (roff + hlen)); + memmove(mtod(m1, u_char *) + roff, + mtod(m1, u_char *) + roff + hlen, + m1->m_len - (roff + hlen)); m1->m_len -= hlen; m->m_pkthdr.len -= hlen; } @@ -910,7 +911,7 @@ esp_output(struct mbuf *m, struct tdb *t } /* Initialize ESP header. */ - bcopy((caddr_t) >tdb_spi, mtod(mo, caddr_t) + roff, + memcpy(mtod(mo, caddr_t) + roff, (caddr_t) >tdb_spi, sizeof(u_int32_t)); tdb->tdb_rpl++; replay = htonl((u_int32_t)tdb->tdb_rpl); @@ -992,7 +993,7 @@ esp_output(struct mbuf *m, struct tdb *t tc->tc_spi = tdb->tdb_spi; tc->tc_proto = tdb->tdb_sproto; tc->tc_rdomain = tdb->tdb_rdomain; - memcpy(>tc_dst, >tdb_dst, sizeof(union sockaddr_union)); + tc->tc_dst = tdb->tdb_dst; /* Crypto operation descriptor. */ crp->crp_ilen = m->m_pkthdr.len; /* Total input length. */ Index: ip_mroute.c === RCS file: /cvs/src/sys/netinet/ip_mroute.c,v retrieving revision 1.112 diff -u -p -r1.112 ip_mroute.c --- ip_mroute.c 17 Mar 2017 14:59:29 - 1.112 +++ ip_mroute.c 6 Apr 2017 15:21:28 - @@ -951,10 +951,10 @@ add_mfc(struct socket *so, struct mbuf * */ if (mrt_api_config & MRT_API_FLAGS_ALL) { struct mfcctl2 *mp2 = mtod(m, struct mfcctl2 *); - bcopy(mp2, (caddr_t), sizeof(*mp2)); + memcpy((caddr_t), mp2, sizeof(*mp2)); } else { struct mfcctl *mp = mtod(m, struct mfcctl *); - bcopy(mp, (caddr_t), sizeof(*mp)); + memcpy((caddr_t), mp, sizeof(*mp)); memset((caddr_t) + sizeof(struct mfcctl), 0, sizeof(mfcctl2) - sizeof(struct mfcctl)); } @@ -988,7 +988,7 @@ del_mfc(struct socket *so, struct mbuf * mp = mtod(m, struct mfcctl *); - bcopy(mp, (caddr_t), sizeof(*mp)); + memcpy((caddr_t), mp, sizeof(*mp)); memset((caddr_t) + sizeof(struct mfcctl), 0, sizeof(mfcctl2) - sizeof(struct mfcctl));
ip6_input.c and mld6.c bcopy -> memcpy
Hello - The following diff removes bcopy from ip6_input.c and mld6.c by using memcpy as the memory does not overlap. OK? Index: ip6_input.c === RCS file: /cvs/src/sys/netinet6/ip6_input.c,v retrieving revision 1.181 diff -u -p -r1.181 ip6_input.c --- ip6_input.c 6 Mar 2017 08:59:07 - 1.181 +++ ip6_input.c 6 Apr 2017 00:50:46 - @@ -777,7 +777,7 @@ ip6_process_hopopts(struct mbuf *m, u_in return (-1); } optlen = IP6OPT_RTALERT_LEN; - bcopy((caddr_t)(opt + 2), (caddr_t)_val, 2); + memcpy((caddr_t)_val, (caddr_t)(opt + 2), 2); *rtalertp = ntohs(rtalert_val); break; case IP6OPT_JUMBO: @@ -810,9 +810,9 @@ ip6_process_hopopts(struct mbuf *m, u_in /* * We may see jumbolen in unaligned location, so -* we'd need to perform bcopy(). +* we'd need to perform memcpy(). */ - bcopy(opt + 2, , sizeof(jumboplen)); + memcpy(, opt + 2, sizeof(jumboplen)); jumboplen = (u_int32_t)htonl(jumboplen); #if 1 @@ -935,7 +935,7 @@ ip6_savecontrol(struct inpcb *in6p, stru /* RFC 2292 sec. 5 */ if ((in6p->inp_flags & IN6P_PKTINFO) != 0) { struct in6_pktinfo pi6; - bcopy(>ip6_dst, _addr, sizeof(struct in6_addr)); + memcpy(_addr, >ip6_dst, sizeof(struct in6_addr)); if (IN6_IS_SCOPE_EMBED(_addr)) pi6.ipi6_addr.s6_addr16[1] = 0; pi6.ipi6_ifindex = m ? m->m_pkthdr.ph_ifidx : 0; Index: mld6.c === RCS file: /cvs/src/sys/netinet6/mld6.c,v retrieving revision 1.50 diff -u -p -r1.50 mld6.c --- mld6.c 9 Feb 2017 15:23:35 - 1.50 +++ mld6.c 6 Apr 2017 00:50:46 - @@ -109,7 +109,7 @@ mld6_init(void) hbh_buf[3] = 0; hbh_buf[4] = IP6OPT_ROUTER_ALERT; hbh_buf[5] = IP6OPT_RTALERT_LEN - 2; - bcopy((caddr_t)_code, _buf[6], sizeof(u_int16_t)); + memcpy(_buf[6], (caddr_t)_code, sizeof(u_int16_t)); ip6_opts.ip6po_hbh = hbh; }
ipcomp bcopy -> mem*
Hello - This diff converts the existing three bcopy's to memcpy or memmove. The memcpy's are on freshly malloc'd memory so no overlap. OK? Index: netinet/ip_ipcomp.c === RCS file: /cvs/src/sys/netinet/ip_ipcomp.c,v retrieving revision 1.55 diff -u -p -r1.55 ip_ipcomp.c --- netinet/ip_ipcomp.c 17 Feb 2017 14:49:03 - 1.55 +++ netinet/ip_ipcomp.c 24 Mar 2017 16:54:37 - @@ -181,7 +181,7 @@ ipcomp_input(struct mbuf *m, struct tdb tc->tc_spi = tdb->tdb_spi; tc->tc_proto = IPPROTO_IPCOMP; tc->tc_rdomain = tdb->tdb_rdomain; - bcopy(>tdb_dst, >tc_dst, sizeof(union sockaddr_union)); + memcpy(>tc_dst, >tdb_dst, sizeof(union sockaddr_union)); return crypto_dispatch(crp); } @@ -317,8 +317,8 @@ ipcomp_input_cb(struct cryptop *crp) /* Finally, let's relink */ m1->m_next = mo; } else { - bcopy(mtod(m1, u_char *) + roff + hlen, - mtod(m1, u_char *) + roff, + memmove(mtod(m1, u_char *) + roff, + mtod(m1, u_char *) + roff + hlen, m1->m_len - (roff + hlen)); m1->m_len -= hlen; m->m_pkthdr.len -= hlen; @@ -501,7 +501,7 @@ ipcomp_output(struct mbuf *m, struct tdb tc->tc_proto = tdb->tdb_sproto; tc->tc_skip = skip; tc->tc_rdomain = tdb->tdb_rdomain; - bcopy(>tdb_dst, >tc_dst, sizeof(union sockaddr_union)); + memcpy(>tc_dst, >tdb_dst, sizeof(union sockaddr_union)); /* Crypto operation descriptor */ crp->crp_ilen = m->m_pkthdr.len;/* Total input length */
Re: ip_ipip.c / gif(4) percpu counters
On Thu, Mar 09, 2017 at 03:49:21PM +0100, Jeremie Courreges-Anglas wrote: > Martin Pieuchotwrites: > > > On 08/03/17(Wed) 12:03, Jeremie Courreges-Anglas wrote: > >> [...] > >> So here's a refreshed diff that initializes the counters directly from > >> ip_init(). I remove the ipip_init() wrapper to make it clear that > >> ip_init() is responsible for the job. > >> > >> (Still) ok? > > > > I'm against adding more "#if PEUDOIF" in the stack everywhere and it > > makes no sense to move more globals outside of ip_ipip.c. > > The previous diff was just plain wrong. > > > If you really don't want to use .pr_init, then call ipip_input() from > > ip_input(). > > Actually I'm fine with .pr_init. There are other protosw entries that > reach the counters but one shouldn't remove entries carelessly anyway. > > Is this better? > Definitely. OK dhill@ > > Index: netinet/in_proto.c > === > RCS file: /d/cvs/src/sys/netinet/in_proto.c,v > retrieving revision 1.74 > diff -u -p -r1.74 in_proto.c > --- netinet/in_proto.c2 Mar 2017 08:58:24 - 1.74 > +++ netinet/in_proto.c8 Mar 2017 11:56:45 - > @@ -239,7 +239,8 @@ struct protosw inetsw[] = { >.pr_output = rip_output, >.pr_ctloutput = rip_ctloutput, >.pr_usrreq = rip_usrreq, > - .pr_sysctl = ipip_sysctl > + .pr_sysctl = ipip_sysctl, > + .pr_init = ipip_init > }, > { >.pr_type = SOCK_RAW, > @@ -284,7 +285,8 @@ struct protosw inetsw[] = { >.pr_output = rip_output, >.pr_ctloutput = rip_ctloutput, >.pr_usrreq = rip_usrreq, > - .pr_sysctl = ipip_sysctl > + .pr_sysctl = ipip_sysctl, > + .pr_init = ipip_init > }, > #ifdef INET6 > { > Index: netinet/ip_ipip.c > === > RCS file: /d/cvs/src/sys/netinet/ip_ipip.c,v > retrieving revision 1.71 > diff -u -p -r1.71 ip_ipip.c > --- netinet/ip_ipip.c 29 Jan 2017 19:58:47 - 1.71 > +++ netinet/ip_ipip.c 8 Mar 2017 11:59:04 - > @@ -84,7 +84,13 @@ > */ > int ipip_allow = 0; > > -struct ipipstat ipipstat; > +struct cpumem *ipipcounters; > + > +void > +ipip_init(void) > +{ > + ipipcounters = counters_alloc(ipips_ncounters); > +} > > /* > * Really only a wrapper for ipip_input(), for use with pr_input. > @@ -95,7 +101,7 @@ ip4_input(struct mbuf **mp, int *offp, i > /* If we do not accept IP-in-IP explicitly, drop. */ > if (!ipip_allow && ((*mp)->m_flags & (M_AUTH|M_CONF)) == 0) { > DPRINTF(("ip4_input(): dropped due to policy\n")); > - ipipstat.ipips_pdrops++; > + ipipstat_inc(ipips_pdrops); > m_freem(*mp); > return IPPROTO_DONE; > } > @@ -129,7 +135,7 @@ ipip_input(struct mbuf **mp, int *offp, > u_int8_t v; > sa_family_t af; > > - ipipstat.ipips_ipackets++; > + ipipstat_inc(ipips_ipackets); > > m_copydata(m, 0, 1, ); > > @@ -143,7 +149,7 @@ ipip_input(struct mbuf **mp, int *offp, > break; > #endif > default: > - ipipstat.ipips_family++; > + ipipstat_inc(ipips_family); > m_freem(m); > return IPPROTO_DONE; > } > @@ -152,7 +158,7 @@ ipip_input(struct mbuf **mp, int *offp, > if (m->m_len < hlen) { > if ((m = m_pullup(m, hlen)) == NULL) { > DPRINTF(("ipip_input(): m_pullup() failed\n")); > - ipipstat.ipips_hdrops++; > + ipipstat_inc(ipips_hdrops); > return IPPROTO_DONE; > } > } > @@ -179,7 +185,7 @@ ipip_input(struct mbuf **mp, int *offp, > > /* Sanity check */ > if (m->m_pkthdr.len < sizeof(struct ip)) { > - ipipstat.ipips_hdrops++; > + ipipstat_inc(ipips_hdrops); > m_freem(m); > return IPPROTO_DONE; > } > @@ -195,7 +201,7 @@ ipip_input(struct mbuf **mp, int *offp, > break; > #endif > default: > - ipipstat.ipips_family++; > + ipipstat_inc(ipips_family); > m_freem(m); > return IPPROTO_DONE; > } > @@ -206,7 +212,7 @@ ipip_input(struct mbuf **mp, int *offp, > if (m->m_len < hlen) { > if ((m = m_pullup(m, hlen)) == NULL) { > DPRINTF(("ipip_input(): m_pullup() failed\n")); > - ipipstat.ipips_hdrops++; > + ipipstat_inc(ipips_hdrops); > return IPPROTO_DONE; > } > } > @@ -229,7 +235,7 @@ ipip_input(struct mbuf **mp, int *offp, > ECN_ALLOWED_IPSEC : ECN_ALLOWED; > if (!ip_ecn_egress(mode, , >ip_tos)) { > DPRINTF(("ipip_input(): ip_ecn_egress() failed")); > - ipipstat.ipips_pdrops++; > + ipipstat_inc(ipips_pdrops);
Re: Enable TCP ECN by default (for inbound)
On Fri, Oct 07, 2016 at 11:05:28PM -0400, David Hill wrote: > Hello - > > Many operating systems out there are starting to enable TCP ECN by > default, most inbound-only. Linux, FreeBSD, Apple MacOS and iOS. > > This diff mimicks the FreeBSD diff found at > http://marc.info/?l=freebsd-commits-all=146369644516347=2 > > It modifies the net.inet.tcp.ecn from an off and on switch to a > three-way setting: off, on, and inbound-only (0, 1, 2, respectively). > > It also enables TCP ECN by default for inbound connections that request > it. > > My home router has TCP ECN enabled. With 36 hours of uptime, netstat -s > shows: > 16165 ECN connections accepted > 1 ECE packet received > 6 ECE packets sent > 589 CWR packets received > 109 CWR packets sent > > This diff is just to see if there is interest in such a change. If > people seem to like the idea, perhaps I could update the diff to also: > - Remove TCP_ECN kernel option and always compile in support? > - Only allow 0, 1, or 2 via the sysctl net.inet.tcp.ecn knob. > - Update pf.os > > Thoughts? > - David > Here is a diff that doesn't change the default. Index: netinet/tcp_output.c === RCS file: /cvs/src/sys/netinet/tcp_output.c,v retrieving revision 1.119 diff -u -p -r1.119 tcp_output.c --- netinet/tcp_output.c9 Feb 2017 15:19:32 - 1.119 +++ netinet/tcp_output.c4 Mar 2017 21:26:02 - @@ -843,10 +843,12 @@ send: } if (!(tp->t_flags & TF_DISABLE_ECN)) { /* -* if this is a SYN seg, set ECE and CWR. -* set only ECE for SYN-ACK if peer supports ECN. +* If net.inet.tcp.ecn is set to 1 and this is a +* SYN seg, set both ECE and CWR. +* Set only ECE for SYN-ACK if peer supports ECN. */ - if ((flags & (TH_SYN|TH_ACK)) == TH_SYN) + if (tcp_do_ecn == 1 && + (flags & (TH_SYN|TH_ACK)) == TH_SYN) flags |= (TH_ECE|TH_CWR); else if ((tp->t_flags & TF_ECN_PERMIT) && (flags & (TH_SYN|TH_ACK)) == (TH_SYN|TH_ACK)) Index: netinet/tcp_subr.c === RCS file: /cvs/src/sys/netinet/tcp_subr.c,v retrieving revision 1.160 diff -u -p -r1.160 tcp_subr.c --- netinet/tcp_subr.c 9 Feb 2017 15:19:32 - 1.160 +++ netinet/tcp_subr.c 4 Mar 2017 21:26:02 - @@ -110,7 +110,7 @@ int tcp_do_sack = 1;/* RFC 2018 selecti #endif inttcp_ack_on_push = 0;/* set to enable immediate ACK-on-PUSH */ #ifdef TCP_ECN -inttcp_do_ecn = 0; /* RFC3168 ECN enabled/disabled? */ +inttcp_do_ecn = 0; /* RFC3168 TCP ECN 0:off 1:on 2:inbound-only */ #endif inttcp_do_rfc3390 = 2; /* Increase TCP's Initial Window to 10*mss */ Index: netinet/tcp_var.h === RCS file: /cvs/src/sys/netinet/tcp_var.h,v retrieving revision 1.122 diff -u -p -r1.122 tcp_var.h --- netinet/tcp_var.h 9 Feb 2017 15:19:32 - 1.122 +++ netinet/tcp_var.h 4 Mar 2017 21:26:02 - @@ -703,7 +703,7 @@ extern int tcp_do_sack;/* SACK enabled/ extern struct pool sackhl_pool; extern int tcp_sackhole_limit; /* max entries for tcp sack queues */ #endif -extern int tcp_do_ecn; /* RFC3168 ECN enabled/disabled? */ +extern int tcp_do_ecn; /* RFC3168 ECN: 0:off 1:on 2:inbound-only */ extern int tcp_do_rfc3390; /* RFC3390 Increasing TCP's Initial Window */ extern struct pool tcpqe_pool;
Re: pr_output variable arguments
Much easier to read as well. OK On Fri, Mar 03, 2017 at 03:49:08PM +0100, Alexander Bluhm wrote: > Hi, > > I prefer compiler checks over variable argument lists. > So lets convert the pr_output functions. > > ok? > > bluhm > > Index: net/pfkey.c > === > RCS file: /cvs/src/sys/net/pfkey.c,v > retrieving revision 1.38 > diff -u -p -r1.38 pfkey.c > --- net/pfkey.c 2 Mar 2017 08:58:24 - 1.38 > +++ net/pfkey.c 3 Mar 2017 14:45:48 - > @@ -90,10 +90,10 @@ static struct pfkey_version *pfkey_versi > > struct sockaddr pfkey_addr = { 2, PF_KEY, }; > > -/* static struct domain pfkeydomain; */ > -static int pfkey_usrreq(struct socket *socket, int req, struct mbuf *mbuf, > -struct mbuf *nam, struct mbuf *control, struct proc *); > -static int pfkey_output(struct mbuf *mbuf, struct socket *socket); > +int pfkey_usrreq(struct socket *, int , struct mbuf *, struct mbuf *, > +struct mbuf *, struct proc *); > +int pfkey_output(struct mbuf *, struct socket *, struct sockaddr *, > +struct mbuf *); > > void pfkey_init(void); > int pfkey_buildprotosw(void); > @@ -154,8 +154,9 @@ pfkey_sendup(struct socket *socket, stru > return (0); > } > > -static int > -pfkey_output(struct mbuf *mbuf, struct socket *socket) > +int > +pfkey_output(struct mbuf *mbuf, struct socket *socket, struct sockaddr > *dstaddr, > +struct mbuf *control) > { > void *message; > int error = 0; > @@ -230,7 +231,7 @@ pfkey_detach(struct socket *socket, stru > return (rval); > } > > -static int > +int > pfkey_usrreq(struct socket *socket, int req, struct mbuf *mbuf, > struct mbuf *nam, struct mbuf *control, struct proc *p) > { > @@ -266,7 +267,7 @@ static struct protosw pfkey_protosw_temp >.pr_domain = , >.pr_protocol = -1, >.pr_flags = PR_ATOMIC | PR_ADDR, > - .pr_output = (void *) pfkey_output, > + .pr_output = pfkey_output, >.pr_usrreq = pfkey_usrreq > }; > > Index: net/raw_usrreq.c > === > RCS file: /cvs/src/sys/net/raw_usrreq.c,v > retrieving revision 1.28 > diff -u -p -r1.28 raw_usrreq.c > --- net/raw_usrreq.c 23 Jan 2017 16:31:24 - 1.28 > +++ net/raw_usrreq.c 3 Mar 2017 14:45:48 - > @@ -139,7 +139,7 @@ raw_usrreq(struct socket *so, int req, s > error = ENOTCONN; > break; > } > - error = (*so->so_proto->pr_output)(m, so); > + error = (*so->so_proto->pr_output)(m, so, NULL, NULL); > m = NULL; > if (nam) > rp->rcb_faddr = 0; > Index: net/route.h > === > RCS file: /cvs/src/sys/net/route.h,v > retrieving revision 1.157 > diff -u -p -r1.157 route.h > --- net/route.h 2 Mar 2017 17:09:21 - 1.157 > +++ net/route.h 3 Mar 2017 14:45:49 - > @@ -417,7 +417,8 @@ struct sockaddr_in6; > struct bfd_config; > > void route_init(void); > -int route_output(struct mbuf *, ...); > +int route_output(struct mbuf *, struct socket *, struct sockaddr *, > + struct mbuf *); > int route_usrreq(struct socket *, int, struct mbuf *, > struct mbuf *, struct mbuf *, struct proc *); > void rt_ifmsg(struct ifnet *); > Index: net/rtsock.c > === > RCS file: /cvs/src/sys/net/rtsock.c,v > retrieving revision 1.227 > diff -u -p -r1.227 rtsock.c > --- net/rtsock.c 3 Mar 2017 14:22:40 - 1.227 > +++ net/rtsock.c 3 Mar 2017 14:45:49 - > @@ -528,7 +528,8 @@ rt_report(struct rtentry *rt, u_char typ > } > > int > -route_output(struct mbuf *m, ...) > +route_output(struct mbuf *m, struct socket *so, struct sockaddr *dstaddr, > +struct mbuf *control) > { > struct rt_msghdr*rtm = NULL; > struct rtentry *rt = NULL; > @@ -536,19 +537,13 @@ route_output(struct mbuf *m, ...) > int plen, len, seq, newgate = 0, error = 0; > struct ifnet*ifp = NULL; > struct ifaddr *ifa = NULL; > - struct socket *so; > struct rawcb*rp = NULL; > #ifdef MPLS > struct sockaddr_mpls*psa_mpls; > #endif > - va_list ap; > u_inttableid; > u_int8_t prio; > u_char vers, type; > - > - va_start(ap, m); > - so = va_arg(ap, struct socket *); > - va_end(ap); > > if (m == NULL || ((m->m_len < sizeof(int32_t)) && > (m = m_pullup(m, sizeof(int32_t))) == 0)) > Index: netinet/ip_var.h > === > RCS file: /cvs/src/sys/netinet/ip_var.h,v > retrieving revision 1.68 > diff -u -p -r1.68 ip_var.h > --- netinet/ip_var.h 1
ntp_update_second - removed unused var
Hello - time_t *sec is unused in ntp_update_second. OK? Index: kern/kern_tc.c === RCS file: /cvs/src/sys/kern/kern_tc.c,v retrieving revision 1.30 diff -u -p -r1.30 kern_tc.c --- kern/kern_tc.c 9 Feb 2017 20:15:28 - 1.30 +++ kern/kern_tc.c 3 Mar 2017 05:37:17 - @@ -41,7 +41,7 @@ u_int dummy_get_timecount(struct timecounter *); -void ntp_update_second(int64_t *, time_t *); +void ntp_update_second(int64_t *); int sysctl_tc_hardware(void *, size_t *, void *, size_t); int sysctl_tc_choice(void *, size_t *, void *, size_t); @@ -434,7 +434,7 @@ tc_windup(void) if (i > LARGE_STEP) i = 2; for (; i > 0; i--) - ntp_update_second(>th_adjustment, ); + ntp_update_second(>th_adjustment); /* Update the UTC timestamps used by the get*() functions. */ /* XXX shouldn't do this here. Should force non-`get' versions. */ @@ -617,7 +617,7 @@ sysctl_tc(int *name, u_int namelen, void } void -ntp_update_second(int64_t *adjust, time_t *sec) +ntp_update_second(int64_t *adjust) { int64_t adj;
Re: C99 initializers for domains
OK On Wed, Mar 01, 2017 at 01:40:58PM +0100, Martin Pieuchot wrote: > I converted the declarations when I audited the existing 'dom_init' > functions. > > ok? > > Index: kern/uipc_proto.c > === > RCS file: /cvs/src/sys/kern/uipc_proto.c,v > retrieving revision 1.12 > diff -u -p -r1.12 uipc_proto.c > --- kern/uipc_proto.c 22 Feb 2017 19:34:42 - 1.12 > +++ kern/uipc_proto.c 1 Mar 2017 12:05:35 - > @@ -37,9 +37,9 @@ > #include > #include > #include > -#include > +#include > #include > - > + > #include > > /* > @@ -72,6 +72,11 @@ struct protosw unixsw[] = { > } > }; > > -struct domain unixdomain = > -{ AF_LOCAL, "unix", 0, unp_externalize, unp_dispose, > - unixsw, [nitems(unixsw)] }; > +struct domain unixdomain = { > + .dom_family = AF_LOCAL, > + .dom_name = "unix", > + .dom_externalize = unp_externalize, > + .dom_dispose = unp_dispose, > + .dom_protosw = unixsw, > + .dom_protoswNPROTOSW = [nitems(unixsw)] > +}; > Index: net/pfkey.c > === > RCS file: /cvs/src/sys/net/pfkey.c,v > retrieving revision 1.37 > diff -u -p -r1.37 pfkey.c > --- net/pfkey.c 22 Feb 2017 19:34:42 - 1.37 > +++ net/pfkey.c 1 Mar 2017 12:11:31 - > @@ -256,13 +256,9 @@ pfkey_usrreq(struct socket *socket, int > } > > struct domain pfkeydomain = { > - PF_KEY, > - "PF_KEY", > - pfkey_init, /* init */ > - NULL, /* externalize */ > - NULL, /* dispose */ > - NULL, /* protosw */ > - NULL, /* protoswNPROTOSW */ > + .dom_family = PF_KEY, > + .dom_name = "PF_KEY", > + .dom_init = pfkey_init, > }; > > static struct protosw pfkey_protosw_template = { > Index: net/rtsock.c > === > RCS file: /cvs/src/sys/net/rtsock.c,v > retrieving revision 1.223 > diff -u -p -r1.223 rtsock.c > --- net/rtsock.c 22 Feb 2017 19:34:42 - 1.223 > +++ net/rtsock.c 1 Mar 2017 12:33:46 - > @@ -1666,6 +1666,10 @@ struct protosw routesw[] = { > } > }; > > -struct domain routedomain = > -{ PF_ROUTE, "route", route_init, 0, 0, > - routesw, [nitems(routesw)] }; > +struct domain routedomain = { > + .dom_family = PF_ROUTE, > + .dom_name = "route", > + .dom_init = route_init, > + .dom_protosw = routesw, > + .dom_protoswNPROTOSW = [nitems(routesw)] > +}; > Index: netinet/in_proto.c > === > RCS file: /cvs/src/sys/netinet/in_proto.c,v > retrieving revision 1.73 > diff -u -p -r1.73 in_proto.c > --- netinet/in_proto.c22 Feb 2017 19:34:42 - 1.73 > +++ netinet/in_proto.c1 Mar 2017 12:07:53 - > @@ -438,8 +438,12 @@ struct protosw inetsw[] = { > } > }; > > -struct domain inetdomain = > -{ AF_INET, "internet", 0, 0, 0, > - inetsw, [nitems(inetsw)], > - sizeof(struct sockaddr_in), > - offsetof(struct sockaddr_in, sin_addr), 32 }; > +struct domain inetdomain = { > + .dom_family = AF_INET, > + .dom_name = "internet", > + .dom_protosw = inetsw, > + .dom_protoswNPROTOSW = [nitems(inetsw)], > + .dom_rtkeylen = sizeof(struct sockaddr_in), > + .dom_rtoffset = offsetof(struct sockaddr_in, sin_addr), > + .dom_maxplen = 32 > +}; > Index: netinet6/in6_proto.c > === > RCS file: /cvs/src/sys/netinet6/in6_proto.c,v > retrieving revision 1.89 > diff -u -p -r1.89 in6_proto.c > --- netinet6/in6_proto.c 22 Feb 2017 19:34:42 - 1.89 > +++ netinet6/in6_proto.c 1 Mar 2017 12:10:23 - > @@ -340,13 +340,17 @@ struct protosw inet6sw[] = { > } > }; > > -struct domain inet6domain = > -{ AF_INET6, "internet6", 0, 0, 0, > - (struct protosw *)inet6sw, > - (struct protosw *)[nitems(inet6sw)], > - sizeof(struct sockaddr_in6), > - offsetof(struct sockaddr_in6, sin6_addr), 128, > - in6_domifattach, in6_domifdetach, }; > +struct domain inet6domain = { > + .dom_family = AF_INET6, > + .dom_name = "internet6", > + .dom_protosw = (struct protosw *)inet6sw, > + .dom_protoswNPROTOSW = (struct protosw *)[nitems(inet6sw)], > + .dom_rtkeylen = sizeof(struct sockaddr_in6), > + .dom_rtoffset = offsetof(struct sockaddr_in6, sin6_addr), > + .dom_maxplen = 128, > + .dom_ifattach = in6_domifattach, > + .dom_ifdetach = in6_domifdetach > +}; > > /* > * Internet configuration info > Index: netmpls/mpls_proto.c > === > RCS file: /cvs/src/sys/netmpls/mpls_proto.c,v > retrieving revision 1.15 > diff -u -p -r1.15 mpls_proto.c > --- netmpls/mpls_proto.c 27 Feb 2017 19:16:56 - 1.15 > +++ netmpls/mpls_proto.c 1 Mar 2017 12:14:17 - > @@ -46,9 +46,9 @@ > * MPLS address family: needed for the routing table > */ > struct domain mplsdomain = { > -
Re: make sosetopt responsible for m_free
On Mon, Feb 06, 2017 at 01:16:45PM +0100, Martin Pieuchot wrote: > On 03/02/17(Fri) 11:02, David Hill wrote: > > On Fri, Feb 03, 2017 at 09:50:40AM +0100, Martin Pieuchot wrote: > > > On 02/02/17(Thu) 12:12, David Hill wrote: > > > > On Thu, Feb 02, 2017 at 09:34:07AM +0100, Martin Pieuchot wrote: > > > > > On 01/02/17(Wed) 19:27, David Hill wrote: > > > > > > Hello - > > > > > > > > > > > > This diff makes sosetopt responsible for m_free which is much > > > > > > simpler. > > > > > > Requested by bluhm@ > > > > > > > > > > I'd suggest to move the m_free(9) calls to sys_setsockopt(). This > > > > > simplifies the existing code even more and will make it easier to use > > > > > the stack for this temporary storage. > > > > > > > > > > > > > New diff with mpi@'s suggestion. > > > > > > You forgot NFS and BFD that should now call m_free(9) after sosetopt(9). > > > > > > > Indeed! Now with BFD and NFS... > > You're introducing a use after-free in ip_pcbopts(). You need to > allocate/copy the mbuf there. > > I must say I'm a bit afraid of this change because the amount of code it > touches. There might be another use after free somewhere that I missed. > > Maybe we should first split our huge *ctloutput functions. > > One easy move is to split setopt/getopt. > > Then introduce more per-protocol functions instead of having everything > in ip{,6}_ctloutput(). > > For example move all the IPSEC craziness out of these functions. Same > thing with ICMP6... This might sound superfluous but it will help > if/when we decide to have a fine graining for different subsystems. > > I'd also suggest to change the 'struct protosw' declaration to use C99 > initializer. So we can have: > > .pr_ctloutput = ipsec_ctloutput > > This would allow us to grep for "pr_ctloutput" (or pr_setopt) and know > directly which functions to review. > If you are OK with first splitting each *ctloutput into *getopt/*setopt, I will send each diff individually to make review easier. Here is the first split, route_ctloutput. Index: net/rtsock.c === RCS file: /cvs/src/sys/net/rtsock.c,v retrieving revision 1.222 diff -u -p -r1.222 rtsock.c --- net/rtsock.c1 Feb 2017 20:59:47 - 1.222 +++ net/rtsock.c21 Feb 2017 15:52:07 - @@ -98,6 +98,8 @@ struct walkarg { caddr_t w_where, w_tmem; }; +introute_getopt(struct socket *, int, int, struct mbuf *); +introute_setopt(struct socket *, int, int, struct mbuf *); introute_ctloutput(int, struct socket *, int, int, struct mbuf *); void route_input(struct mbuf *m0, sa_family_t); introute_arp_conflict(struct rtentry *, struct rt_addrinfo *); @@ -233,62 +235,86 @@ route_usrreq(struct socket *so, int req, } int -route_ctloutput(int op, struct socket *so, int level, int optname, -struct mbuf *m) +route_getopt(struct socket *so, int level, int optname, struct mbuf *m) +{ + struct routecb *rop = sotoroutecb(so); + int error = 0; + + if (level != AF_ROUTE) + return EINVAL; + + switch (optname) { + case ROUTE_MSGFILTER: + m->m_len = sizeof(unsigned int); + *mtod(m, unsigned int *) = rop->msgfilter; + break; + case ROUTE_TABLEFILTER: + m->m_len = sizeof(unsigned int); + *mtod(m, unsigned int *) = rop->rtableid; + break; + default: + error = ENOPROTOOPT; + break; + } + return error; +} + +int +route_setopt(struct socket *so, int level, int optname, struct mbuf *m) { struct routecb *rop = sotoroutecb(so); int error = 0; unsigned int tid; if (level != AF_ROUTE) { - error = EINVAL; - if (op == PRCO_SETOPT && m) - m_free(m); - return (error); + m_free(m); + return EINVAL; } - switch (op) { - case PRCO_SETOPT: - switch (optname) { - case ROUTE_MSGFILTER: - if (m == NULL || m->m_len != sizeof(unsigned int)) - error = EINVAL; - else - rop->msgfilter = *mtod(m, unsigned int *); - break; - case ROUTE_TABLEFILTER: - if (m == NULL || m->m_len != sizeof(unsigned int)) { - error = EINVAL; - break; -
Re: c99 initialize struct protosw
Here is an updated diff without explicitly setting 0/NULL. Index: kern/uipc_proto.c === RCS file: /cvs/src/sys/kern/uipc_proto.c,v retrieving revision 1.11 diff -u -p -r1.11 uipc_proto.c --- kern/uipc_proto.c 5 Feb 2017 07:57:08 - 1.11 +++ kern/uipc_proto.c 21 Feb 2017 00:42:46 - @@ -49,20 +49,26 @@ extern struct domain unixdomain; /* or at least forward */ struct protosw unixsw[] = { -{ SOCK_STREAM, ,PF_LOCAL, PR_CONNREQUIRED|PR_WANTRCVD|PR_RIGHTS, - 0, 0, 0, 0, - uipc_usrreq, - 0, 0, 0, 0, +{ + .pr_type = SOCK_STREAM, + .pr_domain = , + .pr_protocol = PF_LOCAL, + .pr_flags= PR_CONNREQUIRED|PR_WANTRCVD|PR_RIGHTS, + .pr_usrreq = uipc_usrreq, }, -{ SOCK_SEQPACKET,, PF_LOCAL, PR_ATOMIC|PR_CONNREQUIRED|PR_WANTRCVD|PR_RIGHTS, - 0, 0, 0, 0, - uipc_usrreq, - 0, 0, 0, 0, +{ + .pr_type = SOCK_SEQPACKET, + .pr_domain = , + .pr_protocol = PF_LOCAL, + .pr_flags= PR_ATOMIC|PR_CONNREQUIRED|PR_WANTRCVD|PR_RIGHTS, + .pr_usrreq = uipc_usrreq, }, -{ SOCK_DGRAM, ,PF_LOCAL, PR_ATOMIC|PR_ADDR|PR_RIGHTS, - 0, 0, 0, 0, - uipc_usrreq, - 0, 0, 0, 0, +{ + .pr_type = SOCK_DGRAM, + .pr_domain = , + .pr_protocol = PF_LOCAL, + .pr_flags= PR_ATOMIC|PR_ADDR|PR_RIGHTS, + .pr_usrreq = uipc_usrreq, } }; Index: net/pfkey.c === RCS file: /cvs/src/sys/net/pfkey.c,v retrieving revision 1.36 diff -u -p -r1.36 pfkey.c --- net/pfkey.c 24 Jan 2017 10:08:30 - 1.36 +++ net/pfkey.c 21 Feb 2017 00:42:46 - @@ -266,20 +266,12 @@ struct domain pfkeydomain = { }; static struct protosw pfkey_protosw_template = { - SOCK_RAW, - , - -1, /* protocol */ - PR_ATOMIC | PR_ADDR, - NULL, /* input */ - (void *) pfkey_output, - NULL, /* ctlinput */ - NULL, /* ctloutput */ - pfkey_usrreq, - NULL, /* init */ - NULL, /* fasttimo */ - NULL, /* slowtimo */ - NULL, /* drain */ - NULL/* sysctl */ + .pr_type = SOCK_RAW, + .pr_domain = , + .pr_protocol = -1, + .pr_flags= PR_ATOMIC | PR_ADDR, + .pr_output = (void *) pfkey_output, + .pr_usrreq = pfkey_usrreq }; int Index: net/rtsock.c === RCS file: /cvs/src/sys/net/rtsock.c,v retrieving revision 1.222 diff -u -p -r1.222 rtsock.c --- net/rtsock.c1 Feb 2017 20:59:47 - 1.222 +++ net/rtsock.c21 Feb 2017 00:42:47 - @@ -1654,11 +1654,15 @@ sysctl_rtable_rtstat(void *oldp, size_t extern struct domain routedomain; /* or at least forward */ struct protosw routesw[] = { -{ SOCK_RAW,, 0, PR_ATOMIC|PR_ADDR|PR_WANTRCVD, - 0, route_output, 0, route_ctloutput, - route_usrreq, - raw_init,0, 0, 0, - sysctl_rtable, +{ + .pr_type = SOCK_RAW, + .pr_domain = , + .pr_flags= PR_ATOMIC|PR_ADDR|PR_WANTRCVD, + .pr_output = route_output, + .pr_ctloutput= route_ctloutput, + .pr_usrreq = route_usrreq, + .pr_init = raw_init, + .pr_sysctl = sysctl_rtable } }; Index: netinet/in_proto.c === RCS file: /cvs/src/sys/netinet/in_proto.c,v retrieving revision 1.72 diff -u -p -r1.72 in_proto.c --- netinet/in_proto.c 29 Jan 2017 19:58:47 - 1.72 +++ netinet/in_proto.c 21 Feb 2017 00:42:47 - @@ -175,138 +175,267 @@ u_char ip_protox[IPPROTO_MAX]; struct protosw inetsw[] = { -{ 0, ,0, 0, - 0, 0, 0, 0, - 0, - ip_init, 0, ip_slowtimo,ip_drain, ip_sysctl -}, -{ SOCK_DGRAM, ,IPPROTO_UDP,PR_ATOMIC|PR_ADDR|PR_SPLICE, - udp_input, 0, udp_ctlinput, ip_ctloutput, - udp_usrreq, - udp_init,0, 0, 0, udp_sysctl -}, -{ SOCK_STREAM, ,IPPROTO_TCP, PR_CONNREQUIRED|PR_WANTRCVD|PR_ABRTACPTDIS|PR_SPLICE, - tcp_input, 0, tcp_ctlinput, tcp_ctloutput, - tcp_usrreq, - tcp_init,0, tcp_slowtimo, 0, tcp_sysctl -}, -{ SOCK_RAW,,IPPROTO_RAW,PR_ATOMIC|PR_ADDR, - rip_input, rip_output, 0, rip_ctloutput, - rip_usrreq, - 0, 0, 0, 0, -}, -{ SOCK_RAW,,IPPROTO_ICMP, PR_ATOMIC|PR_ADDR, - icmp_input, rip_output, 0, rip_ctloutput, - rip_usrreq, - icmp_init, 0, 0, 0, icmp_sysctl +{ + .pr_domain = , + .pr_init = ip_init, + .pr_slowtimo =
ip6_ctloutput - check invalid level first
Hello - The *ctloutput functions all check for an invalid level first, except ip6_ctloutput. This diff makes ip6_ctloutput do the same. As a bonus, we save on indentation. No functional change. Index: netinet6/ip6_output.c === RCS file: /cvs/src/sys/netinet6/ip6_output.c,v retrieving revision 1.225 diff -u -p -r1.225 ip6_output.c --- netinet6/ip6_output.c 9 Feb 2017 15:19:32 - 1.225 +++ netinet6/ip6_output.c 20 Feb 2017 21:02:47 - @@ -1062,64 +1062,69 @@ ip6_ctloutput(int op, struct socket *so, privileged = (inp->inp_socket->so_state & SS_PRIV); uproto = (int)so->so_proto->pr_protocol; - if (level == IPPROTO_IPV6) { - switch (op) { - case PRCO_SETOPT: + if (level != IPPROTO_IPV6) { + if (op == PRCO_SETOPT) + m_free(m); + return (EINVAL); + } + + switch (op) { + case PRCO_SETOPT: + switch (optname) { + /* +* Use of some Hop-by-Hop options or some +* Destination options, might require special +* privilege. That is, normal applications +* (without special privilege) might be forbidden +* from setting certain options in outgoing packets, +* and might never see certain options in received +* packets. [RFC 2292 Section 6] +* KAME specific note: +* KAME prevents non-privileged users from sending or +* receiving ANY hbh/dst options in order to avoid +* overhead of parsing options in the kernel. +*/ + case IPV6_RECVHOPOPTS: + case IPV6_RECVDSTOPTS: + if (!privileged) { + error = EPERM; + break; + } + /* FALLTHROUGH */ + case IPV6_UNICAST_HOPS: + case IPV6_MINHOPCOUNT: + case IPV6_HOPLIMIT: + + case IPV6_RECVPKTINFO: + case IPV6_RECVHOPLIMIT: + case IPV6_RECVRTHDR: + case IPV6_RECVPATHMTU: + case IPV6_RECVTCLASS: + case IPV6_V6ONLY: + case IPV6_AUTOFLOWLABEL: + case IPV6_RECVDSTPORT: + if (m == NULL || m->m_len != sizeof(int)) { + error = EINVAL; + break; + } + optval = *mtod(m, int *); switch (optname) { - /* -* Use of some Hop-by-Hop options or some -* Destination options, might require special -* privilege. That is, normal applications -* (without special privilege) might be forbidden -* from setting certain options in outgoing packets, -* and might never see certain options in received -* packets. [RFC 2292 Section 6] -* KAME specific note: -* KAME prevents non-privileged users from sending or -* receiving ANY hbh/dst options in order to avoid -* overhead of parsing options in the kernel. -*/ - case IPV6_RECVHOPOPTS: - case IPV6_RECVDSTOPTS: - if (!privileged) { - error = EPERM; - break; - } - /* FALLTHROUGH */ - case IPV6_UNICAST_HOPS: - case IPV6_MINHOPCOUNT: - case IPV6_HOPLIMIT: - case IPV6_RECVPKTINFO: - case IPV6_RECVHOPLIMIT: - case IPV6_RECVRTHDR: - case IPV6_RECVPATHMTU: - case IPV6_RECVTCLASS: - case IPV6_V6ONLY: - case IPV6_AUTOFLOWLABEL: - case IPV6_RECVDSTPORT: - if (m == NULL || m->m_len != sizeof(int)) { + case IPV6_UNICAST_HOPS: + if (optval < -1 || optval >= 256) error = EINVAL; - break; + else { + /* -1 = kernel default */ + inp->inp_hops = optval; } - optval = *mtod(m, int *); - switch (optname) { - -
Re: c99 initialize struct protosw
On Sat, Feb 18, 2017 at 09:22:44PM -0500, David Hill wrote: > Hello - > > This moves the 'struct protosw' declarations to use C99 initializers. > Requested by mpi@ > Apologies for not explaining the reason for the diff. It would allow us to easily grep for a member, such as pr_ctloutput, and know which functions need review. The goal is to introduce more per-protocol functions instead of having everything in ip{,6}_ctloutput(), with the next diff splitting setopt and getopt up. - David
c99 initialize struct protosw
Hello - This moves the 'struct protosw' declarations to use C99 initializers. Requested by mpi@ Index: kern/uipc_proto.c === RCS file: /cvs/src/sys/kern/uipc_proto.c,v retrieving revision 1.11 diff -u -p -r1.11 uipc_proto.c --- kern/uipc_proto.c 5 Feb 2017 07:57:08 - 1.11 +++ kern/uipc_proto.c 19 Feb 2017 02:15:00 - @@ -49,20 +49,53 @@ extern struct domain unixdomain; /* or at least forward */ struct protosw unixsw[] = { -{ SOCK_STREAM, ,PF_LOCAL, PR_CONNREQUIRED|PR_WANTRCVD|PR_RIGHTS, - 0, 0, 0, 0, - uipc_usrreq, - 0, 0, 0, 0, +{ + .pr_type = SOCK_STREAM, + .pr_domain = , + .pr_protocol = PF_LOCAL, + .pr_flags= PR_CONNREQUIRED|PR_WANTRCVD|PR_RIGHTS, + .pr_input= NULL, + .pr_output = NULL, + .pr_ctlinput = NULL, + .pr_ctloutput= NULL, + .pr_usrreq = uipc_usrreq, + .pr_init = NULL, + .pr_fasttimo = NULL, + .pr_slowtimo = NULL, + .pr_drain= NULL, + .pr_sysctl = NULL }, -{ SOCK_SEQPACKET,, PF_LOCAL, PR_ATOMIC|PR_CONNREQUIRED|PR_WANTRCVD|PR_RIGHTS, - 0, 0, 0, 0, - uipc_usrreq, - 0, 0, 0, 0, +{ + .pr_type = SOCK_SEQPACKET, + .pr_domain = , + .pr_protocol = PF_LOCAL, + .pr_flags= PR_ATOMIC|PR_CONNREQUIRED|PR_WANTRCVD|PR_RIGHTS, + .pr_input= NULL, + .pr_output = NULL, + .pr_ctlinput = NULL, + .pr_ctloutput= NULL, + .pr_usrreq = uipc_usrreq, + .pr_init = NULL, + .pr_fasttimo = NULL, + .pr_slowtimo = NULL, + .pr_drain= NULL, + .pr_sysctl = NULL }, -{ SOCK_DGRAM, ,PF_LOCAL, PR_ATOMIC|PR_ADDR|PR_RIGHTS, - 0, 0, 0, 0, - uipc_usrreq, - 0, 0, 0, 0, +{ + .pr_type = SOCK_DGRAM, + .pr_domain = , + .pr_protocol = PF_LOCAL, + .pr_flags= PR_ATOMIC|PR_ADDR|PR_RIGHTS, + .pr_input= NULL, + .pr_output = NULL, + .pr_ctlinput = NULL, + .pr_ctloutput= NULL, + .pr_usrreq = uipc_usrreq, + .pr_init = NULL, + .pr_fasttimo = NULL, + .pr_slowtimo = NULL, + .pr_drain= NULL, + .pr_sysctl = NULL } }; Index: net/pfkey.c === RCS file: /cvs/src/sys/net/pfkey.c,v retrieving revision 1.36 diff -u -p -r1.36 pfkey.c --- net/pfkey.c 24 Jan 2017 10:08:30 - 1.36 +++ net/pfkey.c 19 Feb 2017 02:15:00 - @@ -266,20 +266,20 @@ struct domain pfkeydomain = { }; static struct protosw pfkey_protosw_template = { - SOCK_RAW, - , - -1, /* protocol */ - PR_ATOMIC | PR_ADDR, - NULL, /* input */ - (void *) pfkey_output, - NULL, /* ctlinput */ - NULL, /* ctloutput */ - pfkey_usrreq, - NULL, /* init */ - NULL, /* fasttimo */ - NULL, /* slowtimo */ - NULL, /* drain */ - NULL/* sysctl */ + .pr_type = SOCK_RAW, + .pr_domain = , + .pr_protocol = -1, + .pr_flags= PR_ATOMIC | PR_ADDR, + .pr_input= NULL, + .pr_output = (void *) pfkey_output, + .pr_ctlinput = NULL, + .pr_ctloutput= NULL, + .pr_usrreq = pfkey_usrreq, + .pr_init = NULL, + .pr_fasttimo = NULL, + .pr_slowtimo = NULL, + .pr_drain= NULL, + .pr_sysctl = NULL }; int Index: net/rtsock.c === RCS file: /cvs/src/sys/net/rtsock.c,v retrieving revision 1.222 diff -u -p -r1.222 rtsock.c --- net/rtsock.c1 Feb 2017 20:59:47 - 1.222 +++ net/rtsock.c19 Feb 2017 02:15:00 - @@ -1654,13 +1654,23 @@ sysctl_rtable_rtstat(void *oldp, size_t extern struct domain routedomain; /* or at least forward */ struct protosw routesw[] = { -{ SOCK_RAW,, 0, PR_ATOMIC|PR_ADDR|PR_WANTRCVD, - 0, route_output, 0, route_ctloutput, - route_usrreq, - raw_init,0, 0, 0, - sysctl_rtable, +{ + .pr_type = SOCK_RAW, + .pr_domain = , + .pr_protocol = 0, + .pr_flags= PR_ATOMIC|PR_ADDR|PR_WANTRCVD, + .pr_input= NULL, + .pr_output = route_output, + .pr_ctlinput = NULL, + .pr_ctloutput= route_ctloutput, + .pr_usrreq = route_usrreq, + .pr_init = raw_init, + .pr_fasttimo = NULL, + .pr_slowtimo = NULL, + .pr_drain= NULL, + .pr_sysctl = sysctl_rtable } -}; +}; struct domain routedomain = { PF_ROUTE, "route", route_init, 0, 0, Index: netinet/in_proto.c === RCS file: /cvs/src/sys/netinet/in_proto.c,v retrieving revision 1.72 diff -u -p -r1.72 in_proto.c --- netinet/in_proto.c 29 Jan 2017 19:58:47 - 1.72 +++ netinet/in_proto.c 19 Feb 2017 02:15:00 - @@ -175,138 +175,380 @@ u_char ip_protox[IPPROTO_MAX]; struct
Re: ipcomp ipv6 output
OK. On Fri, Feb 17, 2017 at 03:09:25PM +0100, Alexander Bluhm wrote: > Hi, > > When using ipcomp(4) with IPv6 transport mode I get this error: > > ping6: sendmsg: Protocol family not supported > > The break in the switch statement is missing since rev 1.1 from 2001. > So I am the first one testing this. > > ok? > > bluhm > > Index: netinet/ip_ipcomp.c > === > RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/ip_ipcomp.c,v > retrieving revision 1.54 > diff -u -p -r1.54 ip_ipcomp.c > --- netinet/ip_ipcomp.c 9 Feb 2017 00:43:58 - 1.54 > +++ netinet/ip_ipcomp.c 17 Feb 2017 13:44:11 - > @@ -411,6 +411,7 @@ ipcomp_output(struct mbuf *m, struct tdb > ipcompstat.ipcomps_toobig++; > return EMSGSIZE; > } > + break; > #endif /* INET6 */ > > default: >
Re: ipsec output failure counter
OK once the XXX from ip_esp.c is removed too. On Tue, Feb 07, 2017 at 06:15:03PM +0100, Alexander Bluhm wrote: > Hi, > > As mentioned before, IPsec packets could be dropped unaccounted if > output after crypto failed. Add a counter for that case. > > ok? > > bluhm > > Index: sys/netinet/ip_ah.c > === > RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/ip_ah.c,v > retrieving revision 1.126 > diff -u -p -r1.126 ip_ah.c > --- sys/netinet/ip_ah.c 7 Feb 2017 15:10:48 - 1.126 > +++ sys/netinet/ip_ah.c 7 Feb 2017 16:55:11 - > @@ -1247,8 +1247,8 @@ ah_output_cb(struct cryptop *crp) > /* No longer needed. */ > crypto_freereq(crp); > > - ipsp_process_done(m, tdb); > - /* XXX missing error counter if ipsp_process_done() drops packet */ > + if (ipsp_process_done(m, tdb)) > + ahstat.ahs_outfail++; > NET_UNLOCK(s); > > baddone: > Index: sys/netinet/ip_ah.h > === > RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/ip_ah.h,v > retrieving revision 1.33 > diff -u -p -r1.33 ip_ah.h > --- sys/netinet/ip_ah.h 10 Jan 2010 12:43:07 - 1.33 > +++ sys/netinet/ip_ah.h 7 Feb 2017 16:55:11 - > @@ -38,8 +38,7 @@ > #ifndef _NETINET_IP_AH_H_ > #define _NETINET_IP_AH_H_ > > -struct ahstat > -{ > +struct ahstat { > u_int32_tahs_hdrops; /* Packet shorter than header shows */ > u_int32_tahs_nopf; /* Protocol family not supported */ > u_int32_tahs_notdb; > @@ -58,10 +57,10 @@ struct ahstat > u_int32_tahs_toobig; /* Packet got larger than IP_MAXPACKET > */ > u_int32_tahs_pdrops; /* Packet blocked due to policy */ > u_int32_tahs_crypto; /* Crypto processing failure */ > +u_int32_tahs_outfail;/* Packet output failure */ > }; > > -struct ah > -{ > +struct ah { > u_int8_t ah_nh; > u_int8_t ah_hl; > u_int16_t ah_rv; > Index: sys/netinet/ip_esp.c > === > RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/ip_esp.c,v > retrieving revision 1.144 > diff -u -p -r1.144 ip_esp.c > --- sys/netinet/ip_esp.c 7 Feb 2017 15:10:48 - 1.144 > +++ sys/netinet/ip_esp.c 7 Feb 2017 16:55:11 - > @@ -1088,7 +1088,8 @@ esp_output_cb(struct cryptop *crp) > crypto_freereq(crp); > > /* Call the IPsec input callback. */ > - ipsp_process_done(m, tdb); > + if (ipsp_process_done(m, tdb)) > + espstat.esps_outfail++; > /* XXX missing error counter if ipsp_process_done() drops packet */ > NET_UNLOCK(s); > return; > Index: sys/netinet/ip_esp.h > === > RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/ip_esp.h,v > retrieving revision 1.43 > diff -u -p -r1.43 ip_esp.h > --- sys/netinet/ip_esp.h 2 Sep 2016 09:39:32 - 1.43 > +++ sys/netinet/ip_esp.h 7 Feb 2017 16:55:11 - > @@ -38,8 +38,7 @@ > #ifndef _NETINET_IP_ESP_H_ > #define _NETINET_IP_ESP_H_ > > -struct espstat > -{ > +struct espstat { > u_int32_tesps_hdrops;/* Packet shorter than header shows */ > u_int32_tesps_nopf; /* Protocol family not supported */ > u_int32_tesps_notdb; > @@ -63,6 +62,7 @@ struct espstat > u_int32_tesps_udpencout; /* Output ESP-in-UDP packets */ > u_int32_tesps_udpinval; /* Invalid input ESP-in-UDP packets */ > u_int32_tesps_udpneeded; /* Trying to use a ESP-in-UDP TDB */ > +u_int32_tesps_outfail; /* Packet output failure */ > }; > > /* > Index: sys/netinet/ip_ipcomp.c > === > RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/ip_ipcomp.c,v > retrieving revision 1.51 > diff -u -p -r1.51 ip_ipcomp.c > --- sys/netinet/ip_ipcomp.c 7 Feb 2017 15:10:48 - 1.51 > +++ sys/netinet/ip_ipcomp.c 7 Feb 2017 16:55:11 - > @@ -579,8 +579,8 @@ ipcomp_output_cb(struct cryptop *crp) > if (rlen < crp->crp_olen) { > /* Compression was useless, we have lost time. */ > crypto_freereq(crp); > - ipsp_process_done(m, tdb); > - /* XXX missing counter if ipsp_process_done() drops packet */ > + if (ipsp_process_done(m, tdb)) > + ipcompstat.ipcomps_outfail++; > NET_UNLOCK(s); > return; > } > @@ -628,8 +628,8 @@ ipcomp_output_cb(struct cryptop *crp) > /* Release the crypto descriptor. */ > crypto_freereq(crp); > > - ipsp_process_done(m, tdb); > - /* XXX missing error counter if ipsp_process_done() drops packet */ > + if (ipsp_process_done(m, tdb)) > + ipcompstat.ipcomps_outfail++; >
Re: make sosetopt responsible for m_free
On Fri, Feb 03, 2017 at 09:50:40AM +0100, Martin Pieuchot wrote: > On 02/02/17(Thu) 12:12, David Hill wrote: > > On Thu, Feb 02, 2017 at 09:34:07AM +0100, Martin Pieuchot wrote: > > > On 01/02/17(Wed) 19:27, David Hill wrote: > > > > Hello - > > > > > > > > This diff makes sosetopt responsible for m_free which is much simpler. > > > > Requested by bluhm@ > > > > > > I'd suggest to move the m_free(9) calls to sys_setsockopt(). This > > > simplifies the existing code even more and will make it easier to use > > > the stack for this temporary storage. > > > > > > > New diff with mpi@'s suggestion. > > You forgot NFS and BFD that should now call m_free(9) after sosetopt(9). > Indeed! Now with BFD and NFS... Index: kern/uipc_socket.c === RCS file: /cvs/src/sys/kern/uipc_socket.c,v retrieving revision 1.176 diff -u -p -r1.176 uipc_socket.c --- kern/uipc_socket.c 1 Feb 2017 20:59:47 - 1.176 +++ kern/uipc_socket.c 3 Feb 2017 16:00:26 - @@ -1551,16 +1551,15 @@ sowwakeup(struct socket *so) } int -sosetopt(struct socket *so, int level, int optname, struct mbuf *m0) +sosetopt(struct socket *so, int level, int optname, struct mbuf *m) { int s, error = 0; - struct mbuf *m = m0; if (level != SOL_SOCKET) { if (so->so_proto && so->so_proto->pr_ctloutput) { NET_LOCK(s); error = (*so->so_proto->pr_ctloutput)(PRCO_SETOPT, so, - level, optname, m0); + level, optname, m); NET_UNLOCK(s); return (error); } @@ -1707,7 +1706,7 @@ sosetopt(struct socket *so, int level, i level = dom->dom_protosw->pr_protocol; NET_LOCK(s); error = (*so->so_proto->pr_ctloutput) - (PRCO_SETOPT, so, level, optname, m0); + (PRCO_SETOPT, so, level, optname, m); NET_UNLOCK(s); return (error); } @@ -1739,14 +1738,11 @@ sosetopt(struct socket *so, int level, i if (error == 0 && so->so_proto && so->so_proto->pr_ctloutput) { NET_LOCK(s); (*so->so_proto->pr_ctloutput)(PRCO_SETOPT, so, - level, optname, m0); + level, optname, m); NET_UNLOCK(s); - m = NULL; /* freed by protocol */ } } bad: - if (m) - (void) m_free(m); return (error); } Index: kern/uipc_syscalls.c === RCS file: /cvs/src/sys/kern/uipc_syscalls.c,v retrieving revision 1.148 diff -u -p -r1.148 uipc_syscalls.c --- kern/uipc_syscalls.c26 Jan 2017 01:58:00 - 1.148 +++ kern/uipc_syscalls.c3 Feb 2017 16:00:26 - @@ -962,19 +962,13 @@ sys_setsockopt(struct proc *p, void *v, goto bad; } } - if (m == NULL) { - error = ENOBUFS; - goto bad; - } error = copyin(SCARG(uap, val), mtod(m, caddr_t), SCARG(uap, valsize)); - if (error) { + if (error) goto bad; - } m->m_len = SCARG(uap, valsize); } error = sosetopt(fp->f_data, SCARG(uap, level), SCARG(uap, name), m); - m = NULL; bad: m_freem(m); FRELE(fp, p); Index: net/bfd.c === RCS file: /cvs/src/sys/net/bfd.c,v retrieving revision 1.58 diff -u -p -r1.58 bfd.c --- net/bfd.c 24 Jan 2017 10:08:30 - 1.58 +++ net/bfd.c 3 Feb 2017 16:00:26 - @@ -418,7 +418,7 @@ bfd_listener(struct bfd_config *bfd, uns struct sockaddr_in *sin; struct sockaddr_in6 *sin6; struct socket *so; - struct mbuf *m = NULL, *mopt = NULL; + struct mbuf *m = NULL, *mopt; int *ip, error; /* sa_family and sa_len must be equal */ @@ -437,6 +437,7 @@ bfd_listener(struct bfd_config *bfd, uns ip = mtod(mopt, int *); *ip = MAXTTL; error = sosetopt(so, IPPROTO_IP, IP_MINTTL, mopt); + m_free(mopt); if (error) { printf("%s: sosetopt error %d\n", __func__, error); @@ -487,7 +488,7 @@ b
Re: make sosetopt responsible for m_free
On Thu, Feb 02, 2017 at 09:34:07AM +0100, Martin Pieuchot wrote: > On 01/02/17(Wed) 19:27, David Hill wrote: > > Hello - > > > > This diff makes sosetopt responsible for m_free which is much simpler. > > Requested by bluhm@ > > I'd suggest to move the m_free(9) calls to sys_setsockopt(). This > simplifies the existing code even more and will make it easier to use > the stack for this temporary storage. > New diff with mpi@'s suggestion. Index: kern/uipc_socket.c === RCS file: /cvs/src/sys/kern/uipc_socket.c,v retrieving revision 1.176 diff -u -p -r1.176 uipc_socket.c --- kern/uipc_socket.c 1 Feb 2017 20:59:47 - 1.176 +++ kern/uipc_socket.c 2 Feb 2017 16:59:45 - @@ -1551,16 +1551,15 @@ sowwakeup(struct socket *so) } int -sosetopt(struct socket *so, int level, int optname, struct mbuf *m0) +sosetopt(struct socket *so, int level, int optname, struct mbuf *m) { int s, error = 0; - struct mbuf *m = m0; if (level != SOL_SOCKET) { if (so->so_proto && so->so_proto->pr_ctloutput) { NET_LOCK(s); error = (*so->so_proto->pr_ctloutput)(PRCO_SETOPT, so, - level, optname, m0); + level, optname, m); NET_UNLOCK(s); return (error); } @@ -1707,7 +1706,7 @@ sosetopt(struct socket *so, int level, i level = dom->dom_protosw->pr_protocol; NET_LOCK(s); error = (*so->so_proto->pr_ctloutput) - (PRCO_SETOPT, so, level, optname, m0); + (PRCO_SETOPT, so, level, optname, m); NET_UNLOCK(s); return (error); } @@ -1739,14 +1738,11 @@ sosetopt(struct socket *so, int level, i if (error == 0 && so->so_proto && so->so_proto->pr_ctloutput) { NET_LOCK(s); (*so->so_proto->pr_ctloutput)(PRCO_SETOPT, so, - level, optname, m0); + level, optname, m); NET_UNLOCK(s); - m = NULL; /* freed by protocol */ } } bad: - if (m) - (void) m_free(m); return (error); } Index: kern/uipc_syscalls.c === RCS file: /cvs/src/sys/kern/uipc_syscalls.c,v retrieving revision 1.148 diff -u -p -r1.148 uipc_syscalls.c --- kern/uipc_syscalls.c26 Jan 2017 01:58:00 - 1.148 +++ kern/uipc_syscalls.c2 Feb 2017 16:59:45 - @@ -962,19 +962,13 @@ sys_setsockopt(struct proc *p, void *v, goto bad; } } - if (m == NULL) { - error = ENOBUFS; - goto bad; - } error = copyin(SCARG(uap, val), mtod(m, caddr_t), SCARG(uap, valsize)); - if (error) { + if (error) goto bad; - } m->m_len = SCARG(uap, valsize); } error = sosetopt(fp->f_data, SCARG(uap, level), SCARG(uap, name), m); - m = NULL; bad: m_freem(m); FRELE(fp, p); Index: net/rtsock.c === RCS file: /cvs/src/sys/net/rtsock.c,v retrieving revision 1.222 diff -u -p -r1.222 rtsock.c --- net/rtsock.c1 Feb 2017 20:59:47 - 1.222 +++ net/rtsock.c2 Feb 2017 16:59:45 - @@ -240,12 +240,8 @@ route_ctloutput(int op, struct socket *s int error = 0; unsigned int tid; - if (level != AF_ROUTE) { - error = EINVAL; - if (op == PRCO_SETOPT && m) - m_free(m); - return (error); - } + if (level != AF_ROUTE) + return EINVAL; switch (op) { case PRCO_SETOPT: @@ -271,7 +267,6 @@ route_ctloutput(int op, struct socket *s error = ENOPROTOOPT; break; } - m_free(m); break; case PRCO_GETOPT: switch (optname) { Index: netinet/ip_mroute.c === RCS file: /cvs/src/sys/netinet/ip_mroute.c,v retrieving revision 1.108 diff -u -p -r1.108 ip_mroute.c --- netinet/ip_mroute.c 1 Feb 2017 20:59:47 - 1.108 +++ netinet/ip_mroute.c 2 Feb 2017 16:59:46 - @@ -209,7 +209,6 @@ ip_mrouter_set(struct socket *so
make sosetopt responsible for m_free
Hello - This diff makes sosetopt responsible for m_free which is much simpler. Requested by bluhm@ Index: kern/uipc_socket.c === RCS file: /cvs/src/sys/kern/uipc_socket.c,v retrieving revision 1.176 diff -u -p -r1.176 uipc_socket.c --- kern/uipc_socket.c 1 Feb 2017 20:59:47 - 1.176 +++ kern/uipc_socket.c 2 Feb 2017 00:13:23 - @@ -1562,6 +1562,7 @@ sosetopt(struct socket *so, int level, i error = (*so->so_proto->pr_ctloutput)(PRCO_SETOPT, so, level, optname, m0); NET_UNLOCK(s); + m_free(m0); return (error); } error = ENOPROTOOPT; @@ -1709,6 +1710,7 @@ sosetopt(struct socket *so, int level, i error = (*so->so_proto->pr_ctloutput) (PRCO_SETOPT, so, level, optname, m0); NET_UNLOCK(s); + m_free(m0); return (error); } error = ENOPROTOOPT; @@ -1741,7 +1743,8 @@ sosetopt(struct socket *so, int level, i (*so->so_proto->pr_ctloutput)(PRCO_SETOPT, so, level, optname, m0); NET_UNLOCK(s); - m = NULL; /* freed by protocol */ + m_free(m0); + m = NULL; } } bad: Index: net/rtsock.c === RCS file: /cvs/src/sys/net/rtsock.c,v retrieving revision 1.222 diff -u -p -r1.222 rtsock.c --- net/rtsock.c1 Feb 2017 20:59:47 - 1.222 +++ net/rtsock.c2 Feb 2017 00:13:23 - @@ -240,12 +240,8 @@ route_ctloutput(int op, struct socket *s int error = 0; unsigned int tid; - if (level != AF_ROUTE) { - error = EINVAL; - if (op == PRCO_SETOPT && m) - m_free(m); - return (error); - } + if (level != AF_ROUTE) + return EINVAL; switch (op) { case PRCO_SETOPT: @@ -271,7 +267,6 @@ route_ctloutput(int op, struct socket *s error = ENOPROTOOPT; break; } - m_free(m); break; case PRCO_GETOPT: switch (optname) { Index: netinet/ip_mroute.c === RCS file: /cvs/src/sys/netinet/ip_mroute.c,v retrieving revision 1.108 diff -u -p -r1.108 ip_mroute.c --- netinet/ip_mroute.c 1 Feb 2017 20:59:47 - 1.108 +++ netinet/ip_mroute.c 2 Feb 2017 00:13:23 - @@ -209,7 +209,6 @@ ip_mrouter_set(struct socket *so, int op break; } - m_free(m); return (error); } Index: netinet/ip_output.c === RCS file: /cvs/src/sys/netinet/ip_output.c,v retrieving revision 1.335 diff -u -p -r1.335 ip_output.c --- netinet/ip_output.c 1 Feb 2017 20:59:47 - 1.335 +++ netinet/ip_output.c 2 Feb 2017 00:13:23 - @@ -853,11 +853,10 @@ ip_ctloutput(int op, struct socket *so, int error = 0; u_int rtid = 0; - if (level != IPPROTO_IP) { - error = EINVAL; - if (op == PRCO_SETOPT) - (void) m_free(m); - } else switch (op) { + if (level != IPPROTO_IP) + return EINVAL; + + switch (op) { case PRCO_SETOPT: switch (optname) { case IP_OPTIONS: @@ -1073,7 +1072,6 @@ ip_ctloutput(int op, struct socket *so, error = ENOPROTOOPT; break; } - m_free(m); break; case PRCO_GETOPT: @@ -1235,12 +1233,11 @@ ip_pcbopts(struct mbuf **pcbopt, struct /* turn off any old options */ m_free(*pcbopt); - *pcbopt = 0; + *pcbopt = NULL; if (m == NULL || m->m_len == 0) { /* * Only turning off any previous options. */ - m_free(m); return (0); } @@ -1316,7 +1313,6 @@ ip_pcbopts(struct mbuf **pcbopt, struct return (0); bad: - (void)m_free(m); return (EINVAL); } Index: netinet/raw_ip.c === RCS file: /cvs/src/sys/netinet/raw_ip.c,v retrieving revision 1.95 diff -u -p -r1.95 raw_ip.c --- netinet/raw_ip.c1 Feb 2017 20:59:47 - 1.95 +++ netinet/raw_ip.c2 Feb 2017 00:13:23 - @@ -305,11 +305,8 @@ rip_ctloutput(int op, struct socket *so, int error = 0; int dir; - if (level !=
Re: Help with the NET_LOCK()
On Tue, Jan 31, 2017 at 09:11:37PM +0100, Alexander Bluhm wrote: > On Tue, Jan 31, 2017 at 12:14:35PM -0500, David Hill wrote: > > with mpi@'s suggestion to pass a struct mbuf * > > We call mbuf variables m and mbuf pointer mp. So you should rename > *mp to m. > > The different policy who has to free the mbuf with > if (op == PRCO_SETOPT) > m_free(*mp); > is not nice. I think it would be better if all the freeing is > done in sosetopt and sogetopt. But this requires more thought > and should not be in this diff. A possible next step. > > bluhm > I was thinking sosetopt in a separate diff.. Updated diff. Index: kern/uipc_socket.c === RCS file: /cvs/src/sys/kern/uipc_socket.c,v retrieving revision 1.175 diff -u -p -r1.175 uipc_socket.c --- kern/uipc_socket.c 27 Jan 2017 20:31:42 - 1.175 +++ kern/uipc_socket.c 31 Jan 2017 20:29:37 - @@ -1560,7 +1560,7 @@ sosetopt(struct socket *so, int level, i if (so->so_proto && so->so_proto->pr_ctloutput) { NET_LOCK(s); error = (*so->so_proto->pr_ctloutput)(PRCO_SETOPT, so, - level, optname, ); + level, optname, m0); NET_UNLOCK(s); return (error); } @@ -1707,7 +1707,7 @@ sosetopt(struct socket *so, int level, i level = dom->dom_protosw->pr_protocol; NET_LOCK(s); error = (*so->so_proto->pr_ctloutput) - (PRCO_SETOPT, so, level, optname, ); + (PRCO_SETOPT, so, level, optname, m0); NET_UNLOCK(s); return (error); } @@ -1739,7 +1739,7 @@ sosetopt(struct socket *so, int level, i if (error == 0 && so->so_proto && so->so_proto->pr_ctloutput) { NET_LOCK(s); (*so->so_proto->pr_ctloutput)(PRCO_SETOPT, so, - level, optname, ); + level, optname, m0); NET_UNLOCK(s); m = NULL; /* freed by protocol */ } @@ -1758,11 +1758,19 @@ sogetopt(struct socket *so, int level, i if (level != SOL_SOCKET) { if (so->so_proto && so->so_proto->pr_ctloutput) { + m = m_get(M_WAIT, MT_SOOPTS); + m->m_len = 0; + NET_LOCK(s); error = (*so->so_proto->pr_ctloutput)(PRCO_GETOPT, so, - level, optname, mp); + level, optname, m); NET_UNLOCK(s); - return (error); + if (error) { + m_free(m); + return (error); + } + *mp = m; + return (0); } else return (ENOPROTOOPT); } else { @@ -1835,7 +1843,6 @@ sogetopt(struct socket *so, int level, i } case SO_RTABLE: - (void)m_free(m); if (so->so_proto && so->so_proto->pr_domain && so->so_proto->pr_domain->dom_protosw && so->so_proto->pr_ctloutput) { @@ -1844,12 +1851,16 @@ sogetopt(struct socket *so, int level, i level = dom->dom_protosw->pr_protocol; NET_LOCK(s); error = (*so->so_proto->pr_ctloutput) - (PRCO_GETOPT, so, level, optname, mp); + (PRCO_GETOPT, so, level, optname, m); NET_UNLOCK(s); - return (error); + if (error) { + (void)m_free(m); + return (error); + } + break; } + (void)m_free(m); return (ENOPROTOOPT); - break; #ifdef SOCKET_SPLICE case SO_SPLICE: @@ -1880,7 +1891,6 @@ sogetopt(struct socket *so, int level, i } (void)m_free(m); return (EOPNOTSUPP); - break; default:
Re: Help with the NET_LOCK()
On Tue, Jan 31, 2017 at 10:43:26AM +0100, Martin Pieuchot wrote: > On 27/01/17(Fri) 14:33, David Hill wrote: > > [...] > > Forgot a file... Try this: > > Is it now possible to pass a 'struct mbuf *' instead of a 'struct mbuf **' > to the pr_ctloutput() functions? > > Changing the signature would ensure we do not miss a call. This would > also simplify the SETOPT case. > with mpi@'s suggestion to pass a struct mbuf * Index: kern/uipc_socket.c === RCS file: /cvs/src/sys/kern/uipc_socket.c,v retrieving revision 1.175 diff -u -p -r1.175 uipc_socket.c --- kern/uipc_socket.c 27 Jan 2017 20:31:42 - 1.175 +++ kern/uipc_socket.c 31 Jan 2017 17:09:42 - @@ -1560,7 +1560,7 @@ sosetopt(struct socket *so, int level, i if (so->so_proto && so->so_proto->pr_ctloutput) { NET_LOCK(s); error = (*so->so_proto->pr_ctloutput)(PRCO_SETOPT, so, - level, optname, ); + level, optname, m0); NET_UNLOCK(s); return (error); } @@ -1707,7 +1707,7 @@ sosetopt(struct socket *so, int level, i level = dom->dom_protosw->pr_protocol; NET_LOCK(s); error = (*so->so_proto->pr_ctloutput) - (PRCO_SETOPT, so, level, optname, ); + (PRCO_SETOPT, so, level, optname, m0); NET_UNLOCK(s); return (error); } @@ -1739,7 +1739,7 @@ sosetopt(struct socket *so, int level, i if (error == 0 && so->so_proto && so->so_proto->pr_ctloutput) { NET_LOCK(s); (*so->so_proto->pr_ctloutput)(PRCO_SETOPT, so, - level, optname, ); + level, optname, m0); NET_UNLOCK(s); m = NULL; /* freed by protocol */ } @@ -1758,11 +1758,19 @@ sogetopt(struct socket *so, int level, i if (level != SOL_SOCKET) { if (so->so_proto && so->so_proto->pr_ctloutput) { + m = m_get(M_WAIT, MT_SOOPTS); + m->m_len = 0; + NET_LOCK(s); error = (*so->so_proto->pr_ctloutput)(PRCO_GETOPT, so, - level, optname, mp); + level, optname, m); NET_UNLOCK(s); - return (error); + if (error) { + m_free(m); + return (error); + } + *mp = m; + return (0); } else return (ENOPROTOOPT); } else { @@ -1835,7 +1843,6 @@ sogetopt(struct socket *so, int level, i } case SO_RTABLE: - (void)m_free(m); if (so->so_proto && so->so_proto->pr_domain && so->so_proto->pr_domain->dom_protosw && so->so_proto->pr_ctloutput) { @@ -1844,12 +1851,16 @@ sogetopt(struct socket *so, int level, i level = dom->dom_protosw->pr_protocol; NET_LOCK(s); error = (*so->so_proto->pr_ctloutput) - (PRCO_GETOPT, so, level, optname, mp); + (PRCO_GETOPT, so, level, optname, m); NET_UNLOCK(s); - return (error); + if (error) { + (void)m_free(m); + return (error); + } + break; } + (void)m_free(m); return (ENOPROTOOPT); - break; #ifdef SOCKET_SPLICE case SO_SPLICE: @@ -1880,7 +1891,6 @@ sogetopt(struct socket *so, int level, i } (void)m_free(m); return (EOPNOTSUPP); - break; default: (void)m_free(m); Index: net/rtsock.c === RCS file: /cvs/src/sys/net/rtsock.c,v retrieving revision 1.221 diff -u -p -r1.221 rtsock.c --- net/rtsock.c31 Jan 2017 10:24
uvm: free sizes diff
Hello - The following diff adds free sizes to free() calls in uvm/. Only one remaining in uvm/. Index: uvm/uvm_amap.c === RCS file: /cvs/src/sys/uvm/uvm_amap.c,v retrieving revision 1.78 diff -u -p -r1.78 uvm_amap.c --- uvm/uvm_amap.c 8 Oct 2016 16:19:44 - 1.78 +++ uvm/uvm_amap.c 30 Jan 2017 21:17:22 - @@ -368,7 +368,7 @@ amap_alloc1(int slots, int waitf, int la return(amap); fail1: - free(amap->am_buckets, M_UVMAMAP, 0); + free(amap->am_buckets, M_UVMAMAP, buckets * sizeof(*amap->am_buckets)); TAILQ_FOREACH_SAFE(chunk, >am_chunks, ac_list, tmp) pool_put(_amap_chunk_pool, chunk); pool_put(_amap_pool, amap); @@ -414,7 +414,7 @@ amap_free(struct vm_amap *amap) #ifdef UVM_AMAP_PPREF if (amap->am_ppref && amap->am_ppref != PPREF_NONE) - free(amap->am_ppref, M_UVMAMAP, 0); + free(amap->am_ppref, M_UVMAMAP, amap->am_nslot * sizeof(int)); #endif if (UVM_AMAP_SMALL(amap)) Index: uvm/uvm_aobj.c === RCS file: /cvs/src/sys/uvm/uvm_aobj.c,v retrieving revision 1.84 diff -u -p -r1.84 uvm_aobj.c --- uvm/uvm_aobj.c 24 Sep 2016 18:40:29 - 1.84 +++ uvm/uvm_aobj.c 30 Jan 2017 21:17:22 - @@ -403,7 +403,7 @@ uao_free(struct uvm_aobj *aobj) uvmexp.swpgonly--; } } - free(aobj->u_swslots, M_UVMAOBJ, 0); + free(aobj->u_swslots, M_UVMAOBJ, aobj->u_pages * sizeof(int)); } /* finally free the aobj itself */ @@ -532,7 +532,7 @@ uao_shrink_array(struct uvm_object *uobj for (i = 0; i < pages; i++) new_swslots[i] = aobj->u_swslots[i]; - free(aobj->u_swslots, M_UVMAOBJ, 0); + free(aobj->u_swslots, M_UVMAOBJ, aobj->u_pages * sizeof(int)); aobj->u_swslots = new_swslots; aobj->u_pages = pages; @@ -585,7 +585,7 @@ uao_grow_array(struct uvm_object *uobj, for (i = 0; i < aobj->u_pages; i++) new_swslots[i] = aobj->u_swslots[i]; - free(aobj->u_swslots, M_UVMAOBJ, 0); + free(aobj->u_swslots, M_UVMAOBJ, aobj->u_pages * sizeof(int)); aobj->u_swslots = new_swslots; aobj->u_pages = pages; @@ -664,7 +664,7 @@ uao_grow_convert(struct uvm_object *uobj } } - free(old_swslots, M_UVMAOBJ, 0); + free(old_swslots, M_UVMAOBJ, aobj->u_pages * sizeof(int)); aobj->u_pages = pages; return 0;
Re: Help with the NET_LOCK()
On Fri, Jan 27, 2017 at 08:09:36PM +0100, Hrvoje Popovski wrote: > On 27.1.2017. 19:14, David Hill wrote: > >> splassert: yield: want 0 have 1 > >> Starting stack trace... > >> yield() at yield+0xac > >> pool_get() at pool_get+0x1ca > >> m_get() at m_get+0x28 > >> ip_ctloutput() at ip_ctloutput+0x4bf > >> sogetopt() at sogetopt+0x7e > >> sys_getsockopt() at sys_getsockopt+0xbf > >> syscall() at syscall+0x27b > >> --- syscall (number 118) --- > >> end of kernel > >> end trace frame: 0x3, count: 250 > >> 0x978bdd844a: > >> End of stack trace. > >> > >> > > Attempted to solve this and am running with this diff: > > > Hi, > > i applied you patch and i'm still seeing this trace > > > splassert: yield: want 0 have 1 > Starting stack trace... > yield() at yield+0xac > pool_get() at pool_get+0x1ca > m_get() at m_get+0x28 > ip_ctloutput() at ip_ctloutput+0x4bf > sogetopt() at sogetopt+0xa1 > sys_getsockopt() at sys_getsockopt+0xbf > syscall() at syscall+0x27b > --- syscall (number 118) --- > end of kernel > end trace frame: 0x3, count: 250 > 0x178f12db8f1a: > End of stack trace. > > > and this one i'm seeing for first time, maybe because of this diff > > splassert: yield: want 0 have 1 > Starting stack trace... > yield() at yield+0xac > malloc() at malloc+0x406 > ip_setmoptions() at ip_setmoptions+0x248 > ip_ctloutput() at ip_ctloutput+0x461 > sosetopt() at sosetopt+0x8e > sys_setsockopt() at sys_setsockopt+0x12d > syscall() at syscall+0x27b > --- syscall (number 105) --- > end of kernel > end trace frame: 0x1f83, count: 250 > 0x91243a37f1a: > End of stack trace. > Forgot a file... Try this: Index: kern/uipc_socket.c === RCS file: /cvs/src/sys/kern/uipc_socket.c,v retrieving revision 1.174 diff -u -p -r1.174 uipc_socket.c --- kern/uipc_socket.c 26 Jan 2017 00:08:50 - 1.174 +++ kern/uipc_socket.c 27 Jan 2017 19:30:31 - @@ -1758,11 +1758,19 @@ sogetopt(struct socket *so, int level, i if (level != SOL_SOCKET) { if (so->so_proto && so->so_proto->pr_ctloutput) { + m = m_get(M_WAIT, MT_SOOPTS); + m->m_len = 0; + NET_LOCK(s); error = (*so->so_proto->pr_ctloutput)(PRCO_GETOPT, so, - level, optname, mp); + level, optname, ); NET_UNLOCK(s); - return (error); + if (error) { + m_free(m); + return (error); + } + *mp = m; + return (0); } else return (ENOPROTOOPT); } else { @@ -1835,21 +1843,25 @@ sogetopt(struct socket *so, int level, i } case SO_RTABLE: - (void)m_free(m); if (so->so_proto && so->so_proto->pr_domain && so->so_proto->pr_domain->dom_protosw && so->so_proto->pr_ctloutput) { struct domain *dom = so->so_proto->pr_domain; level = dom->dom_protosw->pr_protocol; + NET_LOCK(s); error = (*so->so_proto->pr_ctloutput) - (PRCO_GETOPT, so, level, optname, mp); + (PRCO_GETOPT, so, level, optname, ); NET_UNLOCK(s); - return (error); + if (error) { + (void)m_free(m); + return (error); + } + break; } + (void)m_free(m); return (ENOPROTOOPT); - break; #ifdef SOCKET_SPLICE case SO_SPLICE: @@ -1880,7 +1892,6 @@ sogetopt(struct socket *so, int level, i } (void)m_free(m); return (EOPNOTSUPP); - break; default: (void)m_free(m); Index: net/rtsock.c === RCS file: /cvs/src/sys/net/rtsock.c,v retrieving revision 1.220 diff -u -p -r1.220 rtsock.c --- net/rtsock.c24 Jan 2017 00:17:14 - 1
Re: Help with the NET_LOCK()
On Wed, Jan 25, 2017 at 11:14:57AM -0500, David Hill wrote: > On Wed, Jan 25, 2017 at 04:32:25PM +1000, Martin Pieuchot wrote: > > I just enabled the NET_LOCK() again and I'm looking for test reports. > > Please go build a kernel from sources or wait for the next snapshot, > > run it and report back. > > > > If you're looking for some small coding tasks related to the NET_LOCK() > > just do: > > > > # sysctl kern.splassert=2 > > # sysctl kern.pool_debug=2 > > > > Then watch for the traces on your console. > > > > You'll see something like: > > > > Starting stack trace... > > yield(0,1,d09dac52,f5549dbc,d94e9378) at yield+0xa4 > > yield(d0bc8f40,1,f5549e18,80,14) at yield+0xa4 > > pool_get(d0bc8f40,1,f5549ec8,d03ecbfb,d97815f4) at pool_get+0x1ba > > m_get(1,3,f5549ec0,d03a9362,d0bc22e0) at m_get+0x30 > > doaccept(d977e6c4,3,cf7ee4f8,cf7ee4ec,2000) at doaccept+0x193 > > sys_accept(d977e6c4,f5549f5c,f5549f7c,0,f5549fa8) at sys_accept+0x37 > > syscall() at syscall+0x250 > > > > This means accept(2) is doing a memory allocation that can sleep, here > > with m_get(9), while holding the NET_LOCK(). Even if these should be > > ok, it is easy to avoid them. In the case of doaccept() a mbuf could > > be allocated beforehand or simply use the stack for that. > > > > Cheers, > > Martin > > > > splassert: yield: want 0 have 1 > Starting stack trace... > yield() at yield+0xac > pool_get() at pool_get+0x1ca > m_get() at m_get+0x28 > ip_ctloutput() at ip_ctloutput+0x4bf > sogetopt() at sogetopt+0x7e > sys_getsockopt() at sys_getsockopt+0xbf > syscall() at syscall+0x27b > --- syscall (number 118) --- > end of kernel > end trace frame: 0x3, count: 250 > 0x978bdd844a: > End of stack trace. > > Attempted to solve this and am running with this diff: Index: kern/uipc_socket.c === RCS file: /cvs/src/sys/kern/uipc_socket.c,v retrieving revision 1.174 diff -u -p -r1.174 uipc_socket.c --- kern/uipc_socket.c 26 Jan 2017 00:08:50 - 1.174 +++ kern/uipc_socket.c 27 Jan 2017 18:08:26 - @@ -1758,11 +1758,19 @@ sogetopt(struct socket *so, int level, i if (level != SOL_SOCKET) { if (so->so_proto && so->so_proto->pr_ctloutput) { + m = m_get(M_WAIT, MT_SOOPTS); + m->m_len = 0; + NET_LOCK(s); error = (*so->so_proto->pr_ctloutput)(PRCO_GETOPT, so, - level, optname, mp); + level, optname, ); NET_UNLOCK(s); - return (error); + if (error) { + m_free(m); + return (error); + } + *mp = m; + return (0); } else return (ENOPROTOOPT); } else { @@ -1835,21 +1843,25 @@ sogetopt(struct socket *so, int level, i } case SO_RTABLE: - (void)m_free(m); if (so->so_proto && so->so_proto->pr_domain && so->so_proto->pr_domain->dom_protosw && so->so_proto->pr_ctloutput) { struct domain *dom = so->so_proto->pr_domain; level = dom->dom_protosw->pr_protocol; + NET_LOCK(s); error = (*so->so_proto->pr_ctloutput) - (PRCO_GETOPT, so, level, optname, mp); + (PRCO_GETOPT, so, level, optname, ); NET_UNLOCK(s); - return (error); + if (error) { + (void)m_free(m); + return (error); + } + break; } + (void)m_free(m); return (ENOPROTOOPT); - break; #ifdef SOCKET_SPLICE case SO_SPLICE: @@ -1880,7 +1892,6 @@ sogetopt(struct socket *so, int level, i } (void)m_free(m); return (EOPNOTSUPP); - break; default: (void)m_free(m); Index: net/rtsock.c
ip6_output: copypktopts - drop canwait
Hi - copypktopts is only called by ip6_setpktopts with M_NOWAIT. Drop canwait to make this simpler and more readable. Index: ip6_output.c === RCS file: /cvs/src/sys/netinet6/ip6_output.c,v retrieving revision 1.221 diff -u -p -r1.221 ip6_output.c --- ip6_output.c19 Jan 2017 14:49:19 - 1.221 +++ ip6_output.c26 Jan 2017 20:18:00 - @@ -127,7 +127,7 @@ int ip6_insertfraghdr(struct mbuf *, str int ip6_insert_jumboopt(struct ip6_exthdrs *, u_int32_t); int ip6_splithdr(struct mbuf *, struct ip6_exthdrs *); int ip6_getpmtu(struct rtentry *, struct ifnet *, u_long *); -int copypktopts(struct ip6_pktopts *, struct ip6_pktopts *, int); +int copypktopts(struct ip6_pktopts *, struct ip6_pktopts *); static __inline u_int16_t __attribute__((__unused__)) in6_cksum_phdr(const struct in6_addr *, const struct in6_addr *, u_int32_t, u_int32_t); @@ -1839,22 +1839,22 @@ ip6_clearpktopts(struct ip6_pktopts *pkt do {\ if (src->type) {\ size_t hlen = (((struct ip6_ext *)src->type)->ip6e_len + 1) << 3;\ - dst->type = malloc(hlen, M_IP6OPT, canwait);\ - if (dst->type == NULL && canwait == M_NOWAIT)\ + dst->type = malloc(hlen, M_IP6OPT, M_NOWAIT);\ + if (dst->type == NULL)\ goto bad;\ memcpy(dst->type, src->type, hlen);\ }\ } while (/*CONSTCOND*/ 0) int -copypktopts(struct ip6_pktopts *dst, struct ip6_pktopts *src, int canwait) +copypktopts(struct ip6_pktopts *dst, struct ip6_pktopts *src) { dst->ip6po_hlim = src->ip6po_hlim; dst->ip6po_tclass = src->ip6po_tclass; dst->ip6po_flags = src->ip6po_flags; if (src->ip6po_pktinfo) { dst->ip6po_pktinfo = malloc(sizeof(*dst->ip6po_pktinfo), - M_IP6OPT, canwait); + M_IP6OPT, M_NOWAIT); if (dst->ip6po_pktinfo == NULL) goto bad; *dst->ip6po_pktinfo = *src->ip6po_pktinfo; @@ -2256,7 +2256,7 @@ ip6_setpktopts(struct mbuf *control, str * but we can allow this since this option should be rarely * used. */ - if ((error = copypktopts(opt, stickyopt, M_NOWAIT)) != 0) + if ((error = copypktopts(opt, stickyopt)) != 0) return (error); }
Re: Help with the NET_LOCK()
On Wed, Jan 25, 2017 at 11:11:03AM -0500, David Hill wrote: > On Wed, Jan 25, 2017 at 04:32:25PM +1000, Martin Pieuchot wrote: > > I just enabled the NET_LOCK() again and I'm looking for test reports. > > Please go build a kernel from sources or wait for the next snapshot, > > run it and report back. > > > > If you're looking for some small coding tasks related to the NET_LOCK() > > just do: > > > > # sysctl kern.splassert=2 > > # sysctl kern.pool_debug=2 > > > > Then watch for the traces on your console. > > > > You'll see something like: > > > > Starting stack trace... > > yield(0,1,d09dac52,f5549dbc,d94e9378) at yield+0xa4 > > yield(d0bc8f40,1,f5549e18,80,14) at yield+0xa4 > > pool_get(d0bc8f40,1,f5549ec8,d03ecbfb,d97815f4) at pool_get+0x1ba > > m_get(1,3,f5549ec0,d03a9362,d0bc22e0) at m_get+0x30 > > doaccept(d977e6c4,3,cf7ee4f8,cf7ee4ec,2000) at doaccept+0x193 > > sys_accept(d977e6c4,f5549f5c,f5549f7c,0,f5549fa8) at sys_accept+0x37 > > syscall() at syscall+0x250 > > > > This means accept(2) is doing a memory allocation that can sleep, here > > with m_get(9), while holding the NET_LOCK(). Even if these should be > > ok, it is easy to avoid them. In the case of doaccept() a mbuf could > > be allocated beforehand or simply use the stack for that. > > > > Cheers, > > Martin > > > > splassert: yield: want 0 have 1 > Starting stack trace... > yield() at yield+0xac > malloc() at malloc+0x406 > ip6_setmoptions() at ip6_setmoptions+0x65 > ip6_ctloutput() at ip6_ctloutput+0x6d9 > sosetopt() at sosetopt+0x8e > sys_setsockopt() at sys_setsockopt+0x12d > syscall() at syscall+0x27b > --- syscall (number 105) --- > end of kernel > end trace frame: 0x1b1987be0028, count: 250 > 0x1b197d24b80a: > End of stack trace. > > Switch to NOWAIT? Check is already there... Index: netinet6/ip6_output.c === RCS file: /cvs/src/sys/netinet6/ip6_output.c,v retrieving revision 1.221 diff -u -p -r1.221 ip6_output.c --- netinet6/ip6_output.c 19 Jan 2017 14:49:19 - 1.221 +++ netinet6/ip6_output.c 26 Jan 2017 01:10:58 - @@ -1902,7 +1902,7 @@ ip6_setmoptions(int optname, struct ip6_ * allocate one and initialize to default values. */ im6o = (struct ip6_moptions *) - malloc(sizeof(*im6o), M_IPMOPTS, M_WAITOK); + malloc(sizeof(*im6o), M_IPMOPTS, M_NOWAIT); if (im6o == NULL) return (ENOBUFS);
Re: Help with the NET_LOCK()
On Wed, Jan 25, 2017 at 04:32:25PM +1000, Martin Pieuchot wrote: > I just enabled the NET_LOCK() again and I'm looking for test reports. > Please go build a kernel from sources or wait for the next snapshot, > run it and report back. > > If you're looking for some small coding tasks related to the NET_LOCK() > just do: > > # sysctl kern.splassert=2 > # sysctl kern.pool_debug=2 > > Then watch for the traces on your console. > > You'll see something like: > > Starting stack trace... > yield(0,1,d09dac52,f5549dbc,d94e9378) at yield+0xa4 > yield(d0bc8f40,1,f5549e18,80,14) at yield+0xa4 > pool_get(d0bc8f40,1,f5549ec8,d03ecbfb,d97815f4) at pool_get+0x1ba > m_get(1,3,f5549ec0,d03a9362,d0bc22e0) at m_get+0x30 > doaccept(d977e6c4,3,cf7ee4f8,cf7ee4ec,2000) at doaccept+0x193 > sys_accept(d977e6c4,f5549f5c,f5549f7c,0,f5549fa8) at sys_accept+0x37 > syscall() at syscall+0x250 > > This means accept(2) is doing a memory allocation that can sleep, here > with m_get(9), while holding the NET_LOCK(). Even if these should be > ok, it is easy to avoid them. In the case of doaccept() a mbuf could > be allocated beforehand or simply use the stack for that. > > Cheers, > Martin > Allocate the mbuf beforehand. Also, move the setting of nflag closer to where its value is used. Index: uipc_syscalls.c === RCS file: /cvs/src/sys/kern/uipc_syscalls.c,v retrieving revision 1.147 diff -u -p -r1.147 uipc_syscalls.c --- uipc_syscalls.c 25 Jan 2017 07:35:31 - 1.147 +++ uipc_syscalls.c 26 Jan 2017 01:03:13 - @@ -265,7 +265,7 @@ doaccept(struct proc *p, int sock, struc { struct filedesc *fdp = p->p_fd; struct file *fp, *headfp; - struct mbuf *nam = NULL; + struct mbuf *nam; socklen_t namelen; int error, s, tmpfd; struct socket *head, *so; @@ -288,7 +288,8 @@ doaccept(struct proc *p, int sock, struc return (error); } -redo: + nam = m_get(M_WAIT, MT_SONAME); + NET_LOCK(s); head = headfp->f_data; if (isdnssocket(head) || (head->so_options & SO_ACCEPTCONN) == 0) { @@ -318,30 +319,16 @@ redo: goto out; } - /* Figure out whether the new socket should be non-blocking. */ - nflag = flags & SOCK_NONBLOCK_INHERIT ? (headfp->f_flag & FNONBLOCK) - : (flags & SOCK_NONBLOCK ? FNONBLOCK : 0); - - nam = m_get(M_WAIT, MT_SONAME); - - /* -* Check whether the queue emptied while we slept: m_get() may have -* blocked, allowing the connection to be reset or another thread or -* process to accept it. If so, start over. -*/ - if (head->so_qlen == 0) { - NET_UNLOCK(s); - m_freem(nam); - nam = NULL; - goto redo; - } - /* * Do not sleep after we have taken the socket out of the queue. */ so = TAILQ_FIRST(>so_q); if (soqremque(so, 1) == 0) panic("accept"); + + /* Figure out whether the new socket should be non-blocking. */ + nflag = flags & SOCK_NONBLOCK_INHERIT ? (headfp->f_flag & FNONBLOCK) + : (flags & SOCK_NONBLOCK ? FNONBLOCK : 0); /* connection has been removed from the listen queue */ KNOTE(>so_rcv.sb_sel.si_note, 0);
Re: Help with the NET_LOCK()
On Wed, Jan 25, 2017 at 04:32:25PM +1000, Martin Pieuchot wrote: > I just enabled the NET_LOCK() again and I'm looking for test reports. > Please go build a kernel from sources or wait for the next snapshot, > run it and report back. > > If you're looking for some small coding tasks related to the NET_LOCK() > just do: > > # sysctl kern.splassert=2 > # sysctl kern.pool_debug=2 > > Then watch for the traces on your console. > > You'll see something like: > > Starting stack trace... > yield(0,1,d09dac52,f5549dbc,d94e9378) at yield+0xa4 > yield(d0bc8f40,1,f5549e18,80,14) at yield+0xa4 > pool_get(d0bc8f40,1,f5549ec8,d03ecbfb,d97815f4) at pool_get+0x1ba > m_get(1,3,f5549ec0,d03a9362,d0bc22e0) at m_get+0x30 > doaccept(d977e6c4,3,cf7ee4f8,cf7ee4ec,2000) at doaccept+0x193 > sys_accept(d977e6c4,f5549f5c,f5549f7c,0,f5549fa8) at sys_accept+0x37 > syscall() at syscall+0x250 > > This means accept(2) is doing a memory allocation that can sleep, here > with m_get(9), while holding the NET_LOCK(). Even if these should be > ok, it is easy to avoid them. In the case of doaccept() a mbuf could > be allocated beforehand or simply use the stack for that. > > Cheers, > Martin > splassert: yield: want 0 have 1 Starting stack trace... yield() at yield+0xac malloc() at malloc+0x406 import_identity() at import_identity+0x30 import_identities() at import_identities+0x62 pfkeyv2_send() at pfkeyv2_send+0x1074 pfkey_output() at pfkey_output+0x87 raw_usrreq() at raw_usrreq+0x232 sosend() at sosend+0x2ec dofilewritev() at dofilewritev+0x205 sys_writev() at sys_writev+0x6d syscall() at syscall+0x27b --- syscall (number 121) --- end of kernel end trace frame: 0x1ef4e34e5300, count: 246 0x1ef227c2f3aa: End of stack trace.
Re: Help with the NET_LOCK() - socreate
On Wed, Jan 25, 2017 at 07:04:19PM +0100, Alexander Bluhm wrote: > On Wed, Jan 25, 2017 at 11:02:22AM -0500, David Hill wrote: > > splassert: yield: want 0 have 1 > > Starting stack trace... > > yield() at yield+0xac > > pool_get() at pool_get+0x1ca > > socreate() at socreate+0xba > > sys_socket() at sys_socket+0x135 > > syscall() at syscall+0x27b > > --- syscall (number 97) --- > > end of kernel > > end trace frame: 0x1b1a16c05800, count: 252 > > 0x1b197d23277a: > > End of stack trace. > > This one looks easy. We do not need a lock to setup the still > private so structure. > > ok? > > bluhm > Which uncovers: splassert: yield: want 0 have 1 Starting stack trace... yield() at yield+0xac malloc() at malloc+0x406 route_usrreq() at route_usrreq+0xb0 socreate() at socreate+0x15f sys_socket() at sys_socket+0x135 syscall() at syscall+0x27b --- syscall (number 97) --- end of kernel end trace frame: 0x1b171444a720, count: 251 0x1b19e6cfd5ca: End of stack trace.
Re: Help with the NET_LOCK()
On Wed, Jan 25, 2017 at 04:32:25PM +1000, Martin Pieuchot wrote: > I just enabled the NET_LOCK() again and I'm looking for test reports. > Please go build a kernel from sources or wait for the next snapshot, > run it and report back. > > If you're looking for some small coding tasks related to the NET_LOCK() > just do: > > # sysctl kern.splassert=2 > # sysctl kern.pool_debug=2 > > Then watch for the traces on your console. > > You'll see something like: > > Starting stack trace... > yield(0,1,d09dac52,f5549dbc,d94e9378) at yield+0xa4 > yield(d0bc8f40,1,f5549e18,80,14) at yield+0xa4 > pool_get(d0bc8f40,1,f5549ec8,d03ecbfb,d97815f4) at pool_get+0x1ba > m_get(1,3,f5549ec0,d03a9362,d0bc22e0) at m_get+0x30 > doaccept(d977e6c4,3,cf7ee4f8,cf7ee4ec,2000) at doaccept+0x193 > sys_accept(d977e6c4,f5549f5c,f5549f7c,0,f5549fa8) at sys_accept+0x37 > syscall() at syscall+0x250 > > This means accept(2) is doing a memory allocation that can sleep, here > with m_get(9), while holding the NET_LOCK(). Even if these should be > ok, it is easy to avoid them. In the case of doaccept() a mbuf could > be allocated beforehand or simply use the stack for that. > > Cheers, > Martin > splassert: yield: want 0 have 1 Starting stack trace... yield() at yield+0xac pool_get() at pool_get+0x1ca m_get() at m_get+0x28 ip_ctloutput() at ip_ctloutput+0x4bf sogetopt() at sogetopt+0x7e sys_getsockopt() at sys_getsockopt+0xbf syscall() at syscall+0x27b --- syscall (number 118) --- end of kernel end trace frame: 0x3, count: 250 0x978bdd844a: End of stack trace.
Re: Help with the NET_LOCK()
On Wed, Jan 25, 2017 at 04:32:25PM +1000, Martin Pieuchot wrote: > I just enabled the NET_LOCK() again and I'm looking for test reports. > Please go build a kernel from sources or wait for the next snapshot, > run it and report back. > > If you're looking for some small coding tasks related to the NET_LOCK() > just do: > > # sysctl kern.splassert=2 > # sysctl kern.pool_debug=2 > > Then watch for the traces on your console. > > You'll see something like: > > Starting stack trace... > yield(0,1,d09dac52,f5549dbc,d94e9378) at yield+0xa4 > yield(d0bc8f40,1,f5549e18,80,14) at yield+0xa4 > pool_get(d0bc8f40,1,f5549ec8,d03ecbfb,d97815f4) at pool_get+0x1ba > m_get(1,3,f5549ec0,d03a9362,d0bc22e0) at m_get+0x30 > doaccept(d977e6c4,3,cf7ee4f8,cf7ee4ec,2000) at doaccept+0x193 > sys_accept(d977e6c4,f5549f5c,f5549f7c,0,f5549fa8) at sys_accept+0x37 > syscall() at syscall+0x250 > > This means accept(2) is doing a memory allocation that can sleep, here > with m_get(9), while holding the NET_LOCK(). Even if these should be > ok, it is easy to avoid them. In the case of doaccept() a mbuf could > be allocated beforehand or simply use the stack for that. > > Cheers, > Martin > splassert: yield: want 0 have 1 Starting stack trace... yield() at yield+0xac malloc() at malloc+0x406 ip6_setmoptions() at ip6_setmoptions+0x65 ip6_ctloutput() at ip6_ctloutput+0x6d9 sosetopt() at sosetopt+0x8e sys_setsockopt() at sys_setsockopt+0x12d syscall() at syscall+0x27b --- syscall (number 105) --- end of kernel end trace frame: 0x1b1987be0028, count: 250 0x1b197d24b80a: End of stack trace.
Re: Help with the NET_LOCK() - socreate
On Wed, Jan 25, 2017 at 04:32:25PM +1000, Martin Pieuchot wrote: > I just enabled the NET_LOCK() again and I'm looking for test reports. > Please go build a kernel from sources or wait for the next snapshot, > run it and report back. > > If you're looking for some small coding tasks related to the NET_LOCK() > just do: > > # sysctl kern.splassert=2 > # sysctl kern.pool_debug=2 > > Then watch for the traces on your console. > > You'll see something like: > > Starting stack trace... > yield(0,1,d09dac52,f5549dbc,d94e9378) at yield+0xa4 > yield(d0bc8f40,1,f5549e18,80,14) at yield+0xa4 > pool_get(d0bc8f40,1,f5549ec8,d03ecbfb,d97815f4) at pool_get+0x1ba > m_get(1,3,f5549ec0,d03a9362,d0bc22e0) at m_get+0x30 > doaccept(d977e6c4,3,cf7ee4f8,cf7ee4ec,2000) at doaccept+0x193 > sys_accept(d977e6c4,f5549f5c,f5549f7c,0,f5549fa8) at sys_accept+0x37 > syscall() at syscall+0x250 > > This means accept(2) is doing a memory allocation that can sleep, here > with m_get(9), while holding the NET_LOCK(). Even if these should be > ok, it is easy to avoid them. In the case of doaccept() a mbuf could > be allocated beforehand or simply use the stack for that. > > Cheers, > Martin > splassert: yield: want 0 have 1 Starting stack trace... yield() at yield+0xac pool_get() at pool_get+0x1ca socreate() at socreate+0xba sys_socket() at sys_socket+0x135 syscall() at syscall+0x27b --- syscall (number 97) --- end of kernel end trace frame: 0x1b1a16c05800, count: 252 0x1b197d23277a: End of stack trace.
Re: bluhm's splsoftassert
On Tue, Sep 20, 2016 at 04:17:37PM +0200, Mike Belopuhov wrote: > On 20 September 2016 at 15:55, Alexander Bluhm <alexander.bl...@gmx.net> > wrote: > > On Tue, Sep 20, 2016 at 08:21:55AM -0400, David Hill wrote: > >> With bluhm's r1.160 uipc_socket.c. > > > > With splsoftnet() in soshutdown() I can fix this one. > > > > splassert: sowwakeup: want 5 have 0 > > Starting stack trace... > > splassert_check() at splassert_check+0x78 > > sowwakeup() at sowwakeup+0x27 > > uipc_usrreq() at uipc_usrreq+0xfd > > sys_shutdown() at sys_shutdown+0x67 > > syscall() at syscall+0x27b > > --- syscall (number 134) --- > > end of kernel > > end trace frame: 0xe8f2cba5e80, count: 252 > > 0xe8f305dc16a: > > End of stack trace. > > > > ok? > > > > OK mikeb > > Can we assert that *_usrreq is always called under splsoftnet? > I recall fixing some of them for raw sockets and some such and > was wondering if the spl has to be raised before we end up there. > Just playing around with splsoftassert's and had to add the following splsoftnet's to get my machine to be quiet. Index: kern/sys_socket.c === RCS file: /cvs/src/sys/kern/sys_socket.c,v retrieving revision 1.22 diff -u -p -r1.22 sys_socket.c --- kern/sys_socket.c 6 Oct 2016 17:02:10 - 1.22 +++ kern/sys_socket.c 18 Oct 2016 20:15:47 - @@ -167,6 +167,7 @@ int soo_stat(struct file *fp, struct stat *ub, struct proc *p) { struct socket *so = fp->f_data; + int s; memset(ub, 0, sizeof (*ub)); ub->st_mode = S_IFSOCK; @@ -177,8 +178,10 @@ soo_stat(struct file *fp, struct stat *u ub->st_mode |= S_IWUSR | S_IWGRP | S_IWOTH; ub->st_uid = so->so_euid; ub->st_gid = so->so_egid; + s = splsoftnet(); (void) ((*so->so_proto->pr_usrreq)(so, PRU_SENSE, (struct mbuf *)ub, NULL, NULL, p)); + splx(s); return (0); } Index: kern/uipc_syscalls.c === RCS file: /cvs/src/sys/kern/uipc_syscalls.c,v retrieving revision 1.135 diff -u -p -r1.135 uipc_syscalls.c --- kern/uipc_syscalls.c8 Oct 2016 02:16:43 - 1.135 +++ kern/uipc_syscalls.c18 Oct 2016 20:15:47 - @@ -1049,7 +1049,7 @@ sys_getsockname(struct proc *p, void *v, struct socket *so; struct mbuf *m = NULL; socklen_t len; - int error; + int error, s; if ((error = getsock(p, SCARG(uap, fdes), )) != 0) return (error); @@ -1061,7 +1061,9 @@ sys_getsockname(struct proc *p, void *v, if (error) goto bad; m = m_getclr(M_WAIT, MT_SONAME); + s = splsoftnet(); error = (*so->so_proto->pr_usrreq)(so, PRU_SOCKADDR, 0, m, 0, p); + splx(s); if (error) goto bad; error = copyaddrout(p, m, SCARG(uap, asa), len, SCARG(uap, alen)); @@ -1087,7 +1089,7 @@ sys_getpeername(struct proc *p, void *v, struct socket *so; struct mbuf *m = NULL; socklen_t len; - int error; + int error, s; if ((error = getsock(p, SCARG(uap, fdes), )) != 0) return (error); @@ -1103,7 +1105,9 @@ sys_getpeername(struct proc *p, void *v, if (error) goto bad; m = m_getclr(M_WAIT, MT_SONAME); + s = splsoftnet(); error = (*so->so_proto->pr_usrreq)(so, PRU_PEERADDR, 0, m, 0, p); + splx(s); if (error) goto bad; error = copyaddrout(p, m, SCARG(uap, asa), len, SCARG(uap, alen)); Index: net/if.c === RCS file: /cvs/src/sys/net/if.c,v retrieving revision 1.455 diff -u -p -r1.455 if.c --- net/if.c16 Oct 2016 21:45:17 - 1.455 +++ net/if.c18 Oct 2016 20:15:47 - @@ -2072,9 +2072,11 @@ ifioctl(struct socket *so, u_long cmd, c default: if (so->so_proto == 0) return (EOPNOTSUPP); + s = splsoftnet(); error = ((*so->so_proto->pr_usrreq)(so, PRU_CONTROL, (struct mbuf *) cmd, (struct mbuf *) data, (struct mbuf *) ifp, p)); + splx(s); break; } Index: net/pfkey.c === RCS file: /cvs/src/sys/net/pfkey.c,v retrieving revision 1.31 diff -u -p -r1.31 pfkey.c --- net/pfkey.c 5 Sep 2016 15:12:30 - 1.31 +++ net/pfkey.c 18 Oct 2016 20:15:47 - @@ -242,6 +242,8 @@ pfkey_usrreq(struct socket *socket, int { int rval; + splsoftassert(IPL_SOFTNET); + if ((socket->so_proto->pr_protocol > PFKEY_PROTOCOL_MAX) ||
patch: netstat -P - mention allowkmem
Hello - netstat -P now requires kern.allowkmem to be set. Index: netstat.1 === RCS file: /cvs/src/usr.bin/netstat/netstat.1,v retrieving revision 1.79 diff -u -p -r1.79 netstat.1 --- netstat.1 1 Sep 2016 14:20:13 - 1.79 +++ netstat.1 12 Oct 2016 03:37:53 - @@ -234,6 +234,14 @@ option, also print socket, domain and pr Only the super-user can use the .Fl P option. +.Pp +The +.Fl P +option requires the ability to open +.Pa /dev/kmem +which may be restricted based upon the value of the +.Ar kern.allowkmem +.Xr sysctl 8 . .It Fl p Ar protocol Restrict the output to .Ar protocol ,
Enable TCP ECN by default (for inbound)
Hello - Many operating systems out there are starting to enable TCP ECN by default, most inbound-only. Linux, FreeBSD, Apple MacOS and iOS. This diff mimicks the FreeBSD diff found at http://marc.info/?l=freebsd-commits-all=146369644516347=2 It modifies the net.inet.tcp.ecn from an off and on switch to a three-way setting: off, on, and inbound-only (0, 1, 2, respectively). It also enables TCP ECN by default for inbound connections that request it. My home router has TCP ECN enabled. With 36 hours of uptime, netstat -s shows: 16165 ECN connections accepted 1 ECE packet received 6 ECE packets sent 589 CWR packets received 109 CWR packets sent This diff is just to see if there is interest in such a change. If people seem to like the idea, perhaps I could update the diff to also: - Remove TCP_ECN kernel option and always compile in support? - Only allow 0, 1, or 2 via the sysctl net.inet.tcp.ecn knob. - Update pf.os Thoughts? - David Index: netinet/tcp_output.c === RCS file: /cvs/src/sys/netinet/tcp_output.c,v retrieving revision 1.118 diff -u -p -r1.118 tcp_output.c --- netinet/tcp_output.c19 Jul 2016 21:28:43 - 1.118 +++ netinet/tcp_output.c8 Oct 2016 02:30:07 - @@ -845,10 +845,12 @@ send: } if (!(tp->t_flags & TF_DISABLE_ECN)) { /* -* if this is a SYN seg, set ECE and CWR. -* set only ECE for SYN-ACK if peer supports ECN. +* If net.inet.tcp.ecn is set to 1 and this is a +* SYN seg, set both ECE and CWR. +* Set only ECE for SYN-ACK if peer supports ECN. */ - if ((flags & (TH_SYN|TH_ACK)) == TH_SYN) + if (tcp_do_ecn == 1 && + (flags & (TH_SYN|TH_ACK)) == TH_SYN) flags |= (TH_ECE|TH_CWR); else if ((tp->t_flags & TF_ECN_PERMIT) && (flags & (TH_SYN|TH_ACK)) == (TH_SYN|TH_ACK)) Index: netinet/tcp_subr.c === RCS file: /cvs/src/sys/netinet/tcp_subr.c,v retrieving revision 1.156 diff -u -p -r1.156 tcp_subr.c --- netinet/tcp_subr.c 24 Sep 2016 14:51:37 - 1.156 +++ netinet/tcp_subr.c 8 Oct 2016 02:30:07 - @@ -110,7 +110,7 @@ int tcp_do_sack = 1;/* RFC 2018 selecti #endif inttcp_ack_on_push = 0;/* set to enable immediate ACK-on-PUSH */ #ifdef TCP_ECN -inttcp_do_ecn = 0; /* RFC3168 ECN enabled/disabled? */ +inttcp_do_ecn = 2; /* RFC3168 ECN enabled on inbound requests */ #endif inttcp_do_rfc3390 = 2; /* Increase TCP's Initial Window to 10*mss */ Index: netinet/tcp_var.h === RCS file: /cvs/src/sys/netinet/tcp_var.h,v retrieving revision 1.116 diff -u -p -r1.116 tcp_var.h --- netinet/tcp_var.h 4 Oct 2016 13:54:32 - 1.116 +++ netinet/tcp_var.h 8 Oct 2016 02:30:07 - @@ -579,7 +579,7 @@ extern int tcp_do_sack;/* SACK enabled/ extern struct pool sackhl_pool; extern int tcp_sackhole_limit; /* max entries for tcp sack queues */ #endif -extern int tcp_do_ecn; /* RFC3168 ECN enabled/disabled? */ +extern int tcp_do_ecn; /* RFC3168 ECN: 0:off 1:on 2:inbound-only */ extern int tcp_do_rfc3390; /* RFC3390 Increasing TCP's Initial Window */ extern struct pool tcpqe_pool;
Re: Help me testing the netlock
Hi Martin - As soon as machine boots and first packet hits the VPN, it hits the assertion: rw_status() == RW_WRITE (hand-typed) TID PID UID PRFLAGS PFLAGS CPU COMMAND *78967 78967 0 0x14000 0x200 1 crypto __assert at0x25 ip_output() at 0x843 ipsp_process_done() at 0x2ad esp_output_cb at 0x135 taskq_thnread at 0x6c
Re: my final netinet6 bcopy->memcpy
Ping. On Mon, Sep 19, 2016 at 09:22:50PM -0400, David Hill wrote: > Hello - > > Here are the final bcopy->memcpy conversions in netinet6 that I am > comfortable with. There is also one (bcmp()) to (memcmp() != 0) > conversion since the memory is not overlapping. > > This, with the last netinet6 diff, has dropped the number of bcopy() > calls from 62 to 29 in netinet6/ > > Index: icmp6.c > === > RCS file: /cvs/src/sys/netinet6/icmp6.c,v > retrieving revision 1.190 > diff -u -p -r1.190 icmp6.c > --- icmp6.c 24 Aug 2016 09:38:29 - 1.190 > +++ icmp6.c 20 Sep 2016 01:00:36 - > @@ -1401,7 +1401,7 @@ icmp6_redirect_input(struct mbuf *m, int > bzero(, sizeof(sin6)); > sin6.sin6_family = AF_INET6; > sin6.sin6_len = sizeof(struct sockaddr_in6); > - bcopy(, _addr, sizeof(reddst6)); > + memcpy(_addr, , sizeof(reddst6)); > rt = rtalloc(sin6tosa(), 0, m->m_pkthdr.ph_rtableid); > if (rt) { > if (rt->rt_gateway == NULL || > @@ -1509,9 +1509,9 @@ icmp6_redirect_input(struct mbuf *m, int > sdst.sin6_family = sgw.sin6_family = ssrc.sin6_family = > AF_INET6; > sdst.sin6_len = sgw.sin6_len = ssrc.sin6_len = > sizeof(struct sockaddr_in6); > - bcopy(, _addr, sizeof(struct in6_addr)); > - bcopy(, _addr, sizeof(struct in6_addr)); > - bcopy(, _addr, sizeof(struct in6_addr)); > + memcpy(_addr, , sizeof(struct in6_addr)); > + memcpy(_addr, , sizeof(struct in6_addr)); > + memcpy(_addr, , sizeof(struct in6_addr)); > rtredirect(sin6tosa(), sin6tosa(), sin6tosa(), > , m->m_pkthdr.ph_rtableid); > > @@ -1528,7 +1528,7 @@ icmp6_redirect_input(struct mbuf *m, int > bzero(, sizeof(sdst)); > sdst.sin6_family = AF_INET6; > sdst.sin6_len = sizeof(struct sockaddr_in6); > - bcopy(, _addr, sizeof(struct in6_addr)); > + memcpy(_addr, , sizeof(struct in6_addr)); > pfctlinput(PRC_REDIRECT_HOST, sin6tosa()); > } > > Index: in6.c > === > RCS file: /cvs/src/sys/netinet6/in6.c,v > retrieving revision 1.192 > diff -u -p -r1.192 in6.c > --- in6.c 4 Sep 2016 10:32:01 - 1.192 > +++ in6.c 20 Sep 2016 01:00:36 - > @@ -1029,9 +1029,9 @@ in6_lifaddr_ioctl(u_long cmd, caddr_t da > > /* copy args to in6_aliasreq, perform ioctl(SIOCAIFADDR_IN6). */ > bzero(, sizeof(ifra)); > - bcopy(iflr->iflr_name, ifra.ifra_name, sizeof(ifra.ifra_name)); > + memcpy(ifra.ifra_name, iflr->iflr_name, sizeof(ifra.ifra_name)); > > - bcopy(>addr, _addr, > + memcpy(_addr, >addr, > ((struct sockaddr *)>addr)->sa_len); > if (hostid) { > /* fill in hostid part */ > @@ -1042,7 +1042,7 @@ in6_lifaddr_ioctl(u_long cmd, caddr_t da > } > > if (((struct sockaddr *)>dstaddr)->sa_family) { /*XXX*/ > - bcopy(>dstaddr, _dstaddr, > + memcpy(_dstaddr, >dstaddr, > ((struct sockaddr *)>dstaddr)->sa_len); > if (hostid) { > ifra.ifra_dstaddr.sin6_addr.s6_addr32[2] = > @@ -1073,14 +1073,14 @@ in6_lifaddr_ioctl(u_long cmd, caddr_t da > in6_prefixlen2mask(, iflr->prefixlen); > > sin6 = (struct sockaddr_in6 *)>addr; > - bcopy(>sin6_addr, , sizeof(match)); > + memcpy(, >sin6_addr, sizeof(match)); > match.s6_addr32[0] &= mask.s6_addr32[0]; > match.s6_addr32[1] &= mask.s6_addr32[1]; > match.s6_addr32[2] &= mask.s6_addr32[2]; > match.s6_addr32[3] &= mask.s6_addr32[3]; > > /* if you set extra bits, that's wrong */ > - if (bcmp(, >sin6_addr, sizeof(match))) > + if (memcmp(, >sin6_addr, sizeof(match)) != > 0) > return EINVAL; > > cmp = 1; > @@ -1092,7 +1092,7 @@ in6_lifaddr_ioctl(u_long cmd, caddr_t da > /* on deleting an address, do exact match */ > in6_prefixlen2mask(, 128); > sin6 = (struct sockaddr_in6 *)>addr; > -
Re: splassert: sorwakeup: want 5 have 4
On Mon, Sep 26, 2016 at 01:55:01PM +0100, Stuart Henderson wrote: > Seen about a dozen times on a box doing ospfd + ospf6d (for internal > routes), bgpd (for default route) + isakmpd, shortly after startup > after updating: > > splassert: sorwakeup: want 5 have 4 > Starting stack trace... > splassert_check() at splassert_check+0x78 > sorwakeup() at sorwakeup+0x27 > timeout_run() at timeout_run+0x48 > softclock() at softclock+0x14c > softintr_dispatch() at softintr_dispatch+0x8b > Xsoftclock() at Xsoftclock+0x1f > --- interrupt --- > end of kernel > end trace frame: 0x51, count: 251 > 0x8: > End of stack trace. > Perhaps this? Index: rtsock.c === RCS file: /cvs/src/sys/net/rtsock.c,v retrieving revision 1.206 diff -u -p -r1.206 rtsock.c --- rtsock.c24 Sep 2016 19:27:10 - 1.206 +++ rtsock.c26 Sep 2016 17:23:21 - @@ -302,6 +302,7 @@ rt_senddesync(void *data) struct rawcb*rp; struct routecb *rop; struct mbuf *desync_mbuf; + int s; rp = (struct rawcb *)data; rop = (struct routecb *)rp; @@ -317,7 +318,9 @@ rt_senddesync(void *data) (sbappendaddr(>rcb_socket->so_rcv, _src, desync_mbuf, (struct mbuf *)NULL) != 0)) { rop->flags &= ~ROUTECB_FLAG_DESYNC; + s = splsoftnet(); sorwakeup(rp->rcb_socket); + splx(s); } else { m_freem(desync_mbuf); /* Re-add timeout to try sending msg again */
Re: bluhm's splsoftassert
On Wed, Sep 21, 2016 at 12:32:50PM -0400, David Hill wrote: > Hit another. > > splassert: sorwakeup: want 5 have 0 > Starting stack trace... > splassert_check() at splassert_check+0x78 > sorwakeup() at sorwakeup+0x27 > route_input() at route_input+0x284 > ifioctl() at ifioctl+0x765 > sys_ioctl() at sys_ioctl+0x196 > syscall() at syscall+0x27b > --- syscall (number 54) --- > end of kernel > end trace frame: 0x7f7e72f0, count: 251 > 0x10044651af1a: > End of stack trace. > Index: if.c === RCS file: /cvs/src/sys/net/if.c,v retrieving revision 1.449 diff -u -p -r1.449 if.c --- if.c20 Sep 2016 16:14:43 - 1.449 +++ if.c21 Sep 2016 16:51:39 - @@ -1898,7 +1898,9 @@ ifioctl(struct socket *so, u_long cmd, c ifp->if_xflags = (ifp->if_xflags & IFXF_CANTCHANGE) | (ifr->ifr_flags & ~IFXF_CANTCHANGE); + s = splsoftnet(); rt_ifmsg(ifp); + splx(s); break; case SIOCSIFMETRIC:
Re: bluhm's splsoftassert
Hit another. splassert: sorwakeup: want 5 have 0 Starting stack trace... splassert_check() at splassert_check+0x78 sorwakeup() at sorwakeup+0x27 route_input() at route_input+0x284 ifioctl() at ifioctl+0x765 sys_ioctl() at sys_ioctl+0x196 syscall() at syscall+0x27b --- syscall (number 54) --- end of kernel end trace frame: 0x7f7e72f0, count: 251 0x10044651af1a: End of stack trace.
remove splsoftnet from *_clone_destroy
Hello - I believe this is correct. After mikeb@ committed destroying cloneable interfaces under splsoftnet, these aren't needed anymore. Index: if_mpe.c === RCS file: /cvs/src/sys/net/if_mpe.c,v retrieving revision 1.54 diff -u -p -r1.54 if_mpe.c --- if_mpe.c13 Apr 2016 11:41:15 - 1.54 +++ if_mpe.c21 Sep 2016 01:30:27 - @@ -117,15 +117,12 @@ int mpe_clone_destroy(struct ifnet *ifp) { struct mpe_softc*mpeif = ifp->if_softc; - int s; LIST_REMOVE(mpeif, sc_list); if (mpeif->sc_smpls.smpls_label) { - s = splsoftnet(); rt_ifa_del(>sc_ifa, RTF_MPLS, smplstosa(>sc_smpls)); - splx(s); } if_detach(ifp); Index: if_mpw.c === RCS file: /cvs/src/sys/net/if_mpw.c,v retrieving revision 1.14 diff -u -p -r1.14 if_mpw.c --- if_mpw.c13 Apr 2016 11:41:15 - 1.14 +++ if_mpw.c21 Sep 2016 01:30:27 - @@ -120,15 +120,12 @@ int mpw_clone_destroy(struct ifnet *ifp) { struct mpw_softc *sc = ifp->if_softc; - int s; ifp->if_flags &= ~IFF_RUNNING; if (sc->sc_smpls.smpls_label) { - s = splsoftnet(); rt_ifa_del(>sc_ifa, RTF_MPLS, smplstosa(>sc_smpls)); - splx(s); } if_ih_remove(ifp, mpw_input, NULL); Index: if_pfsync.c === RCS file: /cvs/src/sys/net/if_pfsync.c,v retrieving revision 1.231 diff -u -p -r1.231 if_pfsync.c --- if_pfsync.c 15 Sep 2016 02:00:18 - 1.231 +++ if_pfsync.c 21 Sep 2016 01:30:27 - @@ -353,9 +353,7 @@ pfsync_clone_destroy(struct ifnet *ifp) { struct pfsync_softc *sc = ifp->if_softc; struct pfsync_deferral *pd; - int s; - s = splsoftnet(); timeout_del(>sc_bulkfail_tmo); timeout_del(>sc_bulk_tmo); timeout_del(>sc_tmo); @@ -384,7 +382,6 @@ pfsync_clone_destroy(struct ifnet *ifp) free(sc, M_DEVBUF, sizeof(*sc)); pfsyncif = NULL; - splx(s); return (0); }
Re: bluhm's splsoftassert
On Tue, Sep 20, 2016 at 05:04:02PM +0200, Mike Belopuhov wrote: > On Tue, Sep 20, 2016 at 10:51 -0400, David Hill wrote: > > On Tue, Sep 20, 2016 at 09:53:02AM -0400, David Hill wrote: > > > More... > > > > > > splassert: sorwakeup: want 5 have 0 > > > Starting stack trace... > > > splassert_check() at splassert_check+0x78 > > > sorwakeup() at sorwakeup+0x27 > > > route_input() at route_input+0x284 > > > pflog_clone_create() at pflog_clone_create+0xa4 > > > if_clone_create() at if_clone_create+0x7f > > > ifioctl() at ifioctl+0x35a > > > sys_ioctl() at sys_ioctl+0x196 > > > syscall() at syscall+0x27b > > > --- syscall (number 54) --- > > > end of kernel > > > end trace frame: 0x7f7c7930, count: 249 > > > 0x1aeaedf1af1a: > > > End of stack trace. > > > > > > > > > > Another similar... > > > > Sep 20 10:33:25 olive /bsd: splassert: sorwakeup: want 5 have 0 > > Sep 20 10:33:25 olive /bsd: Starting stack trace... > > Sep 20 10:33:25 olive /bsd: splassert_check() at splassert_check+0x78 > > Sep 20 10:33:25 olive /bsd: sorwakeup() at sorwakeup+0x27 > > Sep 20 10:33:25 olive /bsd: route_input() at route_input+0x284 > > Sep 20 10:33:25 olive /bsd: vether_clone_create() at > > vether_clone_create+0xd9 > > Sep 20 10:33:25 olive /bsd: if_clone_create() at if_clone_create+0x7f > > Sep 20 10:33:25 olive /bsd: ifioctl() at ifioctl+0x35a > > Sep 20 10:33:25 olive /bsd: sys_ioctl() at sys_ioctl+0x196 > > Sep 20 10:33:25 olive /bsd: syscall() at syscall+0x27b > > Sep 20 10:33:25 olive /bsd: --- syscall (number 54) --- > > Sep 20 10:33:25 olive /bsd: end of kernel > > Sep 20 10:33:25 olive /bsd: end trace frame: 0x7f7d0df1, count: 249 > > Sep 20 10:33:25 olive /bsd: 0x119ca1c1af1a: > > Sep 20 10:33:25 olive /bsd: End of stack trace. > > > > > > It's all the same. I'm not certain what would be the best way to > go around this, but a cautious approach would be something like this: > just wrapping ifc_create, ifc_destroy in splsoftnet. > > David, can you give this a spin? > > Index: sys/net/if.c > === > RCS file: /home/cvs/src/sys/net/if.c,v > retrieving revision 1.448 > diff -u -p -r1.448 if.c > --- sys/net/if.c 13 Sep 2016 08:15:01 - 1.448 > +++ sys/net/if.c 20 Sep 2016 14:58:57 - > @@ -1041,7 +1041,7 @@ if_clone_create(const char *name, int rd > { > struct if_clone *ifc; > struct ifnet *ifp; > - int unit, ret; > + int unit, ret, s; > > ifc = if_clone_lookup(name, ); > if (ifc == NULL) > @@ -1050,9 +1050,13 @@ if_clone_create(const char *name, int rd > if (ifunit(name) != NULL) > return (EEXIST); > > + s = splsoftnet(); > if ((ret = (*ifc->ifc_create)(ifc, unit)) != 0 || > - (ifp = ifunit(name)) == NULL) > + (ifp = ifunit(name)) == NULL) { > + splx(s); > return (ret); > + } > + splx(s); > > if_addgroup(ifp, ifc->ifc_name); > if (rdomain != 0) > @@ -1069,7 +1073,7 @@ if_clone_destroy(const char *name) > { > struct if_clone *ifc; > struct ifnet *ifp; > - int s; > + int error, s; > > ifc = if_clone_lookup(name, NULL); > if (ifc == NULL) > @@ -1088,7 +1092,10 @@ if_clone_destroy(const char *name) > splx(s); > } > > - return ((*ifc->ifc_destroy)(ifp)); > + s = splsoftnet(); > + error = (*ifc->ifc_destroy)(ifp); > + splx(s); > + return (error); > } > > /* > Works. No more assert and functions normally.
Re: bluhm's splsoftassert
On Tue, Sep 20, 2016 at 09:53:02AM -0400, David Hill wrote: > More... > > splassert: sorwakeup: want 5 have 0 > Starting stack trace... > splassert_check() at splassert_check+0x78 > sorwakeup() at sorwakeup+0x27 > route_input() at route_input+0x284 > pflog_clone_create() at pflog_clone_create+0xa4 > if_clone_create() at if_clone_create+0x7f > ifioctl() at ifioctl+0x35a > sys_ioctl() at sys_ioctl+0x196 > syscall() at syscall+0x27b > --- syscall (number 54) --- > end of kernel > end trace frame: 0x7f7c7930, count: 249 > 0x1aeaedf1af1a: > End of stack trace. > > Another similar... Sep 20 10:33:25 olive /bsd: splassert: sorwakeup: want 5 have 0 Sep 20 10:33:25 olive /bsd: Starting stack trace... Sep 20 10:33:25 olive /bsd: splassert_check() at splassert_check+0x78 Sep 20 10:33:25 olive /bsd: sorwakeup() at sorwakeup+0x27 Sep 20 10:33:25 olive /bsd: route_input() at route_input+0x284 Sep 20 10:33:25 olive /bsd: vether_clone_create() at vether_clone_create+0xd9 Sep 20 10:33:25 olive /bsd: if_clone_create() at if_clone_create+0x7f Sep 20 10:33:25 olive /bsd: ifioctl() at ifioctl+0x35a Sep 20 10:33:25 olive /bsd: sys_ioctl() at sys_ioctl+0x196 Sep 20 10:33:25 olive /bsd: syscall() at syscall+0x27b Sep 20 10:33:25 olive /bsd: --- syscall (number 54) --- Sep 20 10:33:25 olive /bsd: end of kernel Sep 20 10:33:25 olive /bsd: end trace frame: 0x7f7d0df1, count: 249 Sep 20 10:33:25 olive /bsd: 0x119ca1c1af1a: Sep 20 10:33:25 olive /bsd: End of stack trace.
Re: bluhm's splsoftassert
More... splassert: sorwakeup: want 5 have 0 Starting stack trace... splassert_check() at splassert_check+0x78 sorwakeup() at sorwakeup+0x27 route_input() at route_input+0x284 pflog_clone_create() at pflog_clone_create+0xa4 if_clone_create() at if_clone_create+0x7f ifioctl() at ifioctl+0x35a sys_ioctl() at sys_ioctl+0x196 syscall() at syscall+0x27b --- syscall (number 54) --- end of kernel end trace frame: 0x7f7c7930, count: 249 0x1aeaedf1af1a: End of stack trace.
Re: bluhm's splsoftassert
Another splassert: sowwakeup: want 5 have 0 Starting stack trace... splassert_check() at splassert_check+0x78 sowwakeup() at sowwakeup+0x27 uipc_usrreq() at uipc_usrreq+0xfd sys_shutdown() at sys_shutdown+0x67 syscall() at syscall+0x27b --- syscall (number 134) --- end of kernel end trace frame: 0xfd39b922600, count: 252 0xfd2c6bbcffa: End of stack trace.
Re: bluhm's splsoftassert
On Tue, Sep 20, 2016 at 03:16:50PM +0200, Alexander Bluhm wrote: > On Tue, Sep 20, 2016 at 08:21:55AM -0400, David Hill wrote: > > With bluhm's r1.160 uipc_socket.c. > > Here are the first ones that were detected. > > Thanks for the fast report. > > So fifo works around the socket layer. Better call soconnect2() > instead of unp_connect2(). This adds the missing splsoftnet(). > > I think we should demand that socantsendmore() and socantrcvmore() > in uipc_socket2.c should be called with splsoftnet(). Should both socantsendmore() and socantrcvmore() get a splsoftassert() then, for now? > > ok? > > bluhm > > Index: miscfs/fifofs/fifo_vnops.c > === > RCS file: /data/mirror/openbsd/cvs/src/sys/miscfs/fifofs/fifo_vnops.c,v > retrieving revision 1.51 > diff -u -p -r1.51 fifo_vnops.c > --- miscfs/fifofs/fifo_vnops.c7 Jun 2016 06:12:37 - 1.51 > +++ miscfs/fifofs/fifo_vnops.c20 Sep 2016 13:04:56 - > @@ -48,7 +48,6 @@ > #include > #include > #include > -#include > #include > > #include > @@ -143,7 +142,7 @@ fifo_open(void *v) > return (error); > } > fip->fi_writesock = wso; > - if ((error = unp_connect2(wso, rso)) != 0) { > + if ((error = soconnect2(wso, rso)) != 0) { > (void)soclose(wso); > (void)soclose(rso); > free(fip, M_VNODE, sizeof *fip); > @@ -350,20 +349,25 @@ fifo_close(void *v) > struct vop_close_args *ap = v; > struct vnode *vp = ap->a_vp; > struct fifoinfo *fip = vp->v_fifoinfo; > - int error1 = 0, error2 = 0; > + int s, error1 = 0, error2 = 0; > > if (fip == NULL) > return (0); > > if (ap->a_fflag & FREAD) { > - if (--fip->fi_readers == 0) > + if (--fip->fi_readers == 0) { > + s = splsoftnet(); > socantsendmore(fip->fi_writesock); > + splx(s); > + } > } > if (ap->a_fflag & FWRITE) { > if (--fip->fi_writers == 0) { > + s = splsoftnet(); > /* SS_ISDISCONNECTED will result in POLLHUP */ > fip->fi_readsock->so_state |= SS_ISDISCONNECTED; > socantrcvmore(fip->fi_readsock); > + splx(s); > } > } > if (fip->fi_readers == 0 && fip->fi_writers == 0) { >
Re: bluhm's splsoftassert
And another. splassert: sorwakeup: want 5 have 4 Starting stack trace... splassert_check() at splassert_check+0x78 sorwakeup() at sorwakeup+0x27 pfkey_sendup() at pfkey_sendup+0x99 pfkeyv2_sendmessage() at pfkeyv2_sendmessage+0x226 pfkeyv2_expire() at pfkeyv2_expire+0x18d tdb_soft_timeout() at tdb_soft_timeout+0x1c softclock() at softclock+0x144 softintr_dispatch() at softintr_dispatch+0x8b Xsoftclock() at Xsoftclock+0x1f --- interrupt --- end of kernel end trace frame: 0x20, count: 248 0x8: End of stack trace.
Re: bluhm's splsoftassert
Another... splassert: sorwakeup: want 5 have 4 Starting stack trace... splassert_check() at splassert_check+0x78 sorwakeup() at sorwakeup+0x27 pfkey_sendup() at pfkey_sendup+0x99 pfkeyv2_sendmessage() at pfkeyv2_sendmessage+0x226 pfkeyv2_expire() at pfkeyv2_expire+0x18d tdb_timeout() at tdb_timeout+0x2f softclock() at softclock+0x144 softintr_dispatch() at softintr_dispatch+0x8b Xsoftclock() at Xsoftclock+0x1f --- interrupt --- end of kernel end trace frame: 0x20, count: 248 0x8: End of stack trace.
bluhm's splsoftassert
Hello - With bluhm's r1.160 uipc_socket.c. Here are the first ones that were detected. splassert: sowwakeup: want 5 have 0 Starting stack trace... splassert_check() at splassert_check+0x78 sowwakeup() at sowwakeup+0x27 unp_connect2() at unp_connect2+0x62 fifo_open() at fifo_open+0x244 VOP_OPEN() at VOP_OPEN+0x3f vn_open() at vn_open+0x16f doopenat() at doopenat+0x187 syscall() at syscall+0x27b --- syscall (number 5) --- end of kernel end trace frame: 0x199f2ba48898, count: 249 0x199ebb5c6d0a: End of stack trace. splassert: sorwakeup: want 5 have 0 Starting stack trace... splassert_check() at splassert_check+0x78 sorwakeup() at sorwakeup+0x27 soisconnected() at soisconnected+0x46 unp_connect2() at unp_connect2+0x5a fifo_open() at fifo_open+0x244 VOP_OPEN() at VOP_OPEN+0x3f vn_open() at vn_open+0x16f doopenat() at doopenat+0x187 syscall() at syscall+0x27b --- syscall (number 5) --- end of kernel end trace frame: 0x199e63a704a8, count: 248 0x199ebb5c6d0a: End of stack trace. --- Begin Message --- CVSROOT:/cvs Module name:src Changes by: bl...@cvs.openbsd.org 2016/09/20 05:11:44 Modified files: sys/kern : uipc_socket.c Log message: Add some spl softnet assertions that will help us to find the right places for the upcoming network lock. This might trigger some asserts, but we have to find the missing code paths. OK mpi@ --- End Message ---
netinet/ ansify
Hello - Ansify netinet/ Index: ip_ecn.c === RCS file: /cvs/src/sys/netinet/ip_ecn.c,v retrieving revision 1.7 diff -u -p -r1.7 ip_ecn.c --- ip_ecn.c19 Dec 2014 17:14:40 - 1.7 +++ ip_ecn.c20 Sep 2016 01:54:47 - @@ -84,10 +84,7 @@ * call it after you've done the default initialization/copy for the outer. */ void -ip_ecn_ingress(mode, outer, inner) - int mode; - u_int8_t *outer; - u_int8_t *inner; +ip_ecn_ingress(int mode, u_int8_t *outer, u_int8_t *inner) { if (!outer || !inner) panic("NULL pointer passed to ip_ecn_ingress"); @@ -120,10 +117,7 @@ ip_ecn_ingress(mode, outer, inner) * the caller should drop the packet if the return value is 0. */ int -ip_ecn_egress(mode, outer, inner) - int mode; - u_int8_t *outer; - u_int8_t *inner; +ip_ecn_egress(int mode, u_int8_t *outer, u_int8_t *inner) { if (!outer || !inner) panic("NULL pointer passed to ip_ecn_egress"); Index: ip_ether.c === RCS file: /cvs/src/sys/netinet/ip_ether.c,v retrieving revision 1.80 diff -u -p -r1.80 ip_ether.c --- ip_ether.c 2 Dec 2015 08:47:00 - 1.80 +++ ip_ether.c 20 Sep 2016 01:54:47 - @@ -507,11 +507,8 @@ etherip_output(struct mbuf *m, struct td } int -etherip_sysctl(name, namelen, oldp, oldlenp, newp, newlen) - int *name; - u_int namelen; - void *oldp, *newp; - size_t *oldlenp, newlen; +etherip_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, +void *newp, size_t newlen) { /* All sysctl names at this level are terminal. */ if (namelen != 1) Index: ip_ipcomp.c === RCS file: /cvs/src/sys/netinet/ip_ipcomp.c,v retrieving revision 1.47 diff -u -p -r1.47 ip_ipcomp.c --- ip_ipcomp.c 13 Sep 2016 19:56:55 - 1.47 +++ ip_ipcomp.c 20 Sep 2016 01:54:47 - @@ -80,10 +80,7 @@ ipcomp_attach(void) * ipcomp_init() is called when an CPI is being set up. */ int -ipcomp_init(tdbp, xsp, ii) - struct tdb *tdbp; - struct xformsw *xsp; - struct ipsecinit *ii; +ipcomp_init(struct tdb *tdbp, struct xformsw *xsp, struct ipsecinit *ii) { struct comp_algo *tcomp = NULL; struct cryptoini cric; @@ -120,8 +117,7 @@ ipcomp_init(tdbp, xsp, ii) * ipcomp_zeroize() used when IPCA is deleted */ int -ipcomp_zeroize(tdbp) - struct tdb *tdbp; +ipcomp_zeroize(struct tdb *tdbp) { int err; @@ -134,11 +130,7 @@ ipcomp_zeroize(tdbp) * ipcomp_input() gets called to uncompress an input packet */ int -ipcomp_input(m, tdb, skip, protoff) - struct mbuf*m; - struct tdb *tdb; - int skip; - int protoff; +ipcomp_input(struct mbuf *m, struct tdb *tdb, int skip, int protoff) { struct comp_algo *ipcompx = (struct comp_algo *) tdb->tdb_compalgxform; struct tdb_crypto *tc; @@ -361,12 +353,8 @@ baddone: * IPComp output routine, called by ipsp_process_packet() */ int -ipcomp_output(m, tdb, mp, skip, protoff) - struct mbuf*m; - struct tdb *tdb; - struct mbuf **mp; - int skip; - int protoff; +ipcomp_output(struct mbuf *m, struct tdb *tdb, struct mbuf **mp, int skip, +int protoff) { struct comp_algo *ipcompx = (struct comp_algo *) tdb->tdb_compalgxform; int hlen; Index: tcp_subr.c === RCS file: /cvs/src/sys/netinet/tcp_subr.c,v retrieving revision 1.155 diff -u -p -r1.155 tcp_subr.c --- tcp_subr.c 15 Sep 2016 02:00:18 - 1.155 +++ tcp_subr.c 20 Sep 2016 01:54:47 - @@ -186,8 +186,7 @@ tcp_init(void) * into just an IP overlay pointer, with casting as appropriate for v6. rja */ struct mbuf * -tcp_template(tp) - struct tcpcb *tp; +tcp_template(struct tcpcb *tp) { struct inpcb *inp = tp->t_inpcb; struct mbuf *m; @@ -488,9 +487,7 @@ tcp_newtcpcb(struct inpcb *inp) * then send a RST to peer. */ struct tcpcb * -tcp_drop(tp, errno) - struct tcpcb *tp; - int errno; +tcp_drop(struct tcpcb *tp, int errno) { struct socket *so = tp->t_inpcb->inp_socket; @@ -595,9 +592,7 @@ tcp_rscale(struct tcpcb *tp, u_long hiwa * (for now, won't do anything until can select for soft error). */ void -tcp_notify(inp, error) - struct inpcb *inp; - int error; +tcp_notify(struct inpcb *inp, int error) { struct tcpcb *tp = intotcpcb(inp); struct socket *so = inp->inp_socket; @@ -863,9 +858,7 @@ tcp_ctlinput(int cmd, struct sockaddr *s * Path MTU Discovery handlers. */ void -tcp6_mtudisc_callback(sin6, rdomain) - struct sockaddr_in6 *sin6; - u_int rdomain; +tcp6_mtudisc_callback(struct sockaddr_in6 *sin6, u_int rdomain)
my final netinet6 bcopy->memcpy
Hello - Here are the final bcopy->memcpy conversions in netinet6 that I am comfortable with. There is also one (bcmp()) to (memcmp() != 0) conversion since the memory is not overlapping. This, with the last netinet6 diff, has dropped the number of bcopy() calls from 62 to 29 in netinet6/ Index: icmp6.c === RCS file: /cvs/src/sys/netinet6/icmp6.c,v retrieving revision 1.190 diff -u -p -r1.190 icmp6.c --- icmp6.c 24 Aug 2016 09:38:29 - 1.190 +++ icmp6.c 20 Sep 2016 01:00:36 - @@ -1401,7 +1401,7 @@ icmp6_redirect_input(struct mbuf *m, int bzero(, sizeof(sin6)); sin6.sin6_family = AF_INET6; sin6.sin6_len = sizeof(struct sockaddr_in6); - bcopy(, _addr, sizeof(reddst6)); + memcpy(_addr, , sizeof(reddst6)); rt = rtalloc(sin6tosa(), 0, m->m_pkthdr.ph_rtableid); if (rt) { if (rt->rt_gateway == NULL || @@ -1509,9 +1509,9 @@ icmp6_redirect_input(struct mbuf *m, int sdst.sin6_family = sgw.sin6_family = ssrc.sin6_family = AF_INET6; sdst.sin6_len = sgw.sin6_len = ssrc.sin6_len = sizeof(struct sockaddr_in6); - bcopy(, _addr, sizeof(struct in6_addr)); - bcopy(, _addr, sizeof(struct in6_addr)); - bcopy(, _addr, sizeof(struct in6_addr)); + memcpy(_addr, , sizeof(struct in6_addr)); + memcpy(_addr, , sizeof(struct in6_addr)); + memcpy(_addr, , sizeof(struct in6_addr)); rtredirect(sin6tosa(), sin6tosa(), sin6tosa(), , m->m_pkthdr.ph_rtableid); @@ -1528,7 +1528,7 @@ icmp6_redirect_input(struct mbuf *m, int bzero(, sizeof(sdst)); sdst.sin6_family = AF_INET6; sdst.sin6_len = sizeof(struct sockaddr_in6); - bcopy(, _addr, sizeof(struct in6_addr)); + memcpy(_addr, , sizeof(struct in6_addr)); pfctlinput(PRC_REDIRECT_HOST, sin6tosa()); } Index: in6.c === RCS file: /cvs/src/sys/netinet6/in6.c,v retrieving revision 1.192 diff -u -p -r1.192 in6.c --- in6.c 4 Sep 2016 10:32:01 - 1.192 +++ in6.c 20 Sep 2016 01:00:36 - @@ -1029,9 +1029,9 @@ in6_lifaddr_ioctl(u_long cmd, caddr_t da /* copy args to in6_aliasreq, perform ioctl(SIOCAIFADDR_IN6). */ bzero(, sizeof(ifra)); - bcopy(iflr->iflr_name, ifra.ifra_name, sizeof(ifra.ifra_name)); + memcpy(ifra.ifra_name, iflr->iflr_name, sizeof(ifra.ifra_name)); - bcopy(>addr, _addr, + memcpy(_addr, >addr, ((struct sockaddr *)>addr)->sa_len); if (hostid) { /* fill in hostid part */ @@ -1042,7 +1042,7 @@ in6_lifaddr_ioctl(u_long cmd, caddr_t da } if (((struct sockaddr *)>dstaddr)->sa_family) { /*XXX*/ - bcopy(>dstaddr, _dstaddr, + memcpy(_dstaddr, >dstaddr, ((struct sockaddr *)>dstaddr)->sa_len); if (hostid) { ifra.ifra_dstaddr.sin6_addr.s6_addr32[2] = @@ -1073,14 +1073,14 @@ in6_lifaddr_ioctl(u_long cmd, caddr_t da in6_prefixlen2mask(, iflr->prefixlen); sin6 = (struct sockaddr_in6 *)>addr; - bcopy(>sin6_addr, , sizeof(match)); + memcpy(, >sin6_addr, sizeof(match)); match.s6_addr32[0] &= mask.s6_addr32[0]; match.s6_addr32[1] &= mask.s6_addr32[1]; match.s6_addr32[2] &= mask.s6_addr32[2]; match.s6_addr32[3] &= mask.s6_addr32[3]; /* if you set extra bits, that's wrong */ - if (bcmp(, >sin6_addr, sizeof(match))) + if (memcmp(, >sin6_addr, sizeof(match)) != 0) return EINVAL; cmp = 1; @@ -1092,7 +1092,7 @@ in6_lifaddr_ioctl(u_long cmd, caddr_t da /* on deleting an address, do exact match */ in6_prefixlen2mask(, 128); sin6 = (struct sockaddr_in6 *)>addr; - bcopy(>sin6_addr, , sizeof(match)); + memcpy(, >sin6_addr, sizeof(match)); cmp = 1; } @@ -1104,7 +1104,7 @@ in6_lifaddr_ioctl(u_long cmd, caddr_t da if (!cmp) break; - bcopy(IFA_IN6(ifa), , sizeof(candidate)); + memcpy(, IFA_IN6(ifa), sizeof(candidate)); candidate.s6_addr32[0] &=
netinet/tcp_input.c syn_cache_get diff
Hello - Make sure we keep TF_NOPUSH set if TCP_NOPUSH was set. FreeBSD has the same: https://github.com/freebsd/freebsd/blob/c9af4f2541fd437e0805365fbeec46d69e033310/sys/netinet/tcp_syncache.c#L860 Index: netinet/tcp_input.c === RCS file: /cvs/src/sys/netinet/tcp_input.c,v retrieving revision 1.327 diff -u -p -r1.327 tcp_input.c --- netinet/tcp_input.c 15 Sep 2016 02:00:18 - 1.327 +++ netinet/tcp_input.c 18 Sep 2016 17:07:09 - @@ -3798,7 +3798,7 @@ syn_cache_get(struct sockaddr *src, stru (void) m_free(am); tp = intotcpcb(inp); - tp->t_flags = sototcpcb(oso)->t_flags & TF_NODELAY; + tp->t_flags = sototcpcb(oso)->t_flags & (TF_NOPUSH|TF_NODELAY); if (sc->sc_request_r_scale != 15) { tp->requested_s_scale = sc->sc_requested_s_scale; tp->request_r_scale = sc->sc_request_r_scale;
crypto/ bcopy->memcpy
Hello - Here are a few bcopy to memcpy conversions for crypto/ Index: crypto/crypto.c === RCS file: /cvs/src/sys/crypto/crypto.c,v retrieving revision 1.77 diff -u -p -r1.77 crypto.c --- crypto/crypto.c 15 Sep 2016 02:00:17 - 1.77 +++ crypto/crypto.c 16 Sep 2016 17:40:04 - @@ -254,7 +254,7 @@ crypto_get_driverid(u_int8_t flags) return -1; } - bcopy(crypto_drivers, newdrv, + memcpy(newdrv, crypto_drivers, crypto_drivers_num * sizeof(struct cryptocap)); bzero([crypto_drivers_num], crypto_drivers_num * sizeof(struct cryptocap)); Index: crypto/gmac.c === RCS file: /cvs/src/sys/crypto/gmac.c,v retrieving revision 1.8 diff -u -p -r1.8 gmac.c --- crypto/gmac.c 7 Nov 2015 17:46:49 - 1.8 +++ crypto/gmac.c 16 Sep 2016 17:40:04 - @@ -144,7 +144,7 @@ AES_GMAC_Update(void *xctx, const uint8_ (*ghash_update)(>ghash, (uint8_t *)data, len - plen); if (plen) { - bcopy((uint8_t *)data + (len - plen), (uint8_t *)blk, + memcpy((uint8_t *)blk, (uint8_t *)data + (len - plen), plen); (*ghash_update)(>ghash, (uint8_t *)blk, GMAC_BLOCK_LEN); Index: crypto/hmac.c === RCS file: /cvs/src/sys/crypto/hmac.c,v retrieving revision 1.3 diff -u -p -r1.3 hmac.c --- crypto/hmac.c 11 Jan 2011 15:42:05 - 1.3 +++ crypto/hmac.c 16 Sep 2016 17:40:04 - @@ -46,7 +46,7 @@ HMAC_MD5_Init(HMAC_MD5_CTX *ctx, const u } bzero(k_ipad, MD5_BLOCK_LENGTH); - bcopy(ctx->key, k_ipad, ctx->key_len); + memcpy(k_ipad, ctx->key, ctx->key_len); for (i = 0; i < MD5_BLOCK_LENGTH; i++) k_ipad[i] ^= 0x36; @@ -71,7 +71,7 @@ HMAC_MD5_Final(u_int8_t digest[MD5_DIGES MD5Final(digest, >ctx); bzero(k_opad, MD5_BLOCK_LENGTH); - bcopy(ctx->key, k_opad, ctx->key_len); + memcpy(k_opad, ctx->key, ctx->key_len); for (i = 0; i < MD5_BLOCK_LENGTH; i++) k_opad[i] ^= 0x5c; @@ -100,7 +100,7 @@ HMAC_SHA1_Init(HMAC_SHA1_CTX *ctx, const } bzero(k_ipad, SHA1_BLOCK_LENGTH); - bcopy(ctx->key, k_ipad, ctx->key_len); + memcpy(k_ipad, ctx->key, ctx->key_len); for (i = 0; i < SHA1_BLOCK_LENGTH; i++) k_ipad[i] ^= 0x36; @@ -125,7 +125,7 @@ HMAC_SHA1_Final(u_int8_t digest[SHA1_DIG SHA1Final(digest, >ctx); bzero(k_opad, SHA1_BLOCK_LENGTH); - bcopy(ctx->key, k_opad, ctx->key_len); + memcpy(k_opad, ctx->key, ctx->key_len); for (i = 0; i < SHA1_BLOCK_LENGTH; i++) k_opad[i] ^= 0x5c; @@ -154,7 +154,7 @@ HMAC_SHA256_Init(HMAC_SHA256_CTX *ctx, c } bzero(k_ipad, SHA256_BLOCK_LENGTH); - bcopy(ctx->key, k_ipad, ctx->key_len); + memcpy(k_ipad, ctx->key, ctx->key_len); for (i = 0; i < SHA256_BLOCK_LENGTH; i++) k_ipad[i] ^= 0x36; @@ -179,7 +179,7 @@ HMAC_SHA256_Final(u_int8_t digest[SHA256 SHA256Final(digest, >ctx); bzero(k_opad, SHA256_BLOCK_LENGTH); - bcopy(ctx->key, k_opad, ctx->key_len); + memcpy(k_opad, ctx->key, ctx->key_len); for (i = 0; i < SHA256_BLOCK_LENGTH; i++) k_opad[i] ^= 0x5c; Index: crypto/xform.c === RCS file: /cvs/src/sys/crypto/xform.c,v retrieving revision 1.54 diff -u -p -r1.54 xform.c --- crypto/xform.c 10 Dec 2015 21:00:51 - 1.54 +++ crypto/xform.c 16 Sep 2016 17:40:04 - @@ -491,7 +491,7 @@ aes_xts_reinit(caddr_t key, u_int8_t *iv * Prepare tweak as E_k2(IV). IV is specified as LE representation * of a 64-bit block number which we allow to be passed in directly. */ - bcopy(iv, , AES_XTS_IVSIZE); + memcpy(, iv, AES_XTS_IVSIZE); for (i = 0; i < AES_XTS_IVSIZE; i++) { ctx->tweak[i] = blocknum & 0xff; blocknum >>= 8;
netinet bcopy->memcpy
Hello - Here is another diff to switch some bcopy's to memcpy's. Most bcopy's are on freshly alloc'd memory. for netinet/ Index: ip_ah.c === RCS file: /cvs/src/sys/netinet/ip_ah.c,v retrieving revision 1.122 diff -u -p -r1.122 ip_ah.c --- ip_ah.c 13 Sep 2016 19:56:55 - 1.122 +++ ip_ah.c 15 Sep 2016 16:14:33 - @@ -151,7 +151,7 @@ ah_init(struct tdb *tdbp, struct xformsw tdbp->tdb_amxkeylen = ii->ii_authkeylen; tdbp->tdb_amxkey = malloc(tdbp->tdb_amxkeylen, M_XDATA, M_WAITOK); - bcopy(ii->ii_authkey, tdbp->tdb_amxkey, tdbp->tdb_amxkeylen); + memcpy(tdbp->tdb_amxkey, ii->ii_authkey, tdbp->tdb_amxkeylen); /* Initialize crypto session. */ memset(, 0, sizeof(cria)); @@ -312,7 +312,7 @@ ah_massage_headers(struct mbuf **m0, int /* Zeroize all other options. */ count = ptr[off + 1]; - bcopy(ipseczeroes, ptr, count); + memcpy(ptr, ipseczeroes, count); off += count; break; } @@ -422,7 +422,7 @@ ah_massage_headers(struct mbuf **m0, int /* If mutable option, zeroize. */ if (ptr[count] & IP6OPT_MUTABLE) - bcopy(ipseczeroes, ptr + count, + memcpy(ptr + count, ipseczeroes, ptr[count + 1]); count += ad; @@ -642,7 +642,7 @@ ah_input(struct mbuf *m, struct tdb *tdb if ((tdb->tdb_wnd > 0) && (tdb->tdb_flags & TDBF_ESN)) { esn = htonl(esn); - bcopy(, crda->crd_esn, 4); + memcpy(crda->crd_esn, , 4); crda->crd_flags |= CRD_F_ESN; } @@ -689,7 +689,7 @@ ah_input(struct mbuf *m, struct tdb *tdb tc->tc_spi = tdb->tdb_spi; tc->tc_proto = tdb->tdb_sproto; tc->tc_rdomain = tdb->tdb_rdomain; - bcopy(>tdb_dst, >tc_dst, sizeof(union sockaddr_union)); + memcpy(>tc_dst, >tdb_dst, sizeof(union sockaddr_union)); return crypto_dispatch(crp); } @@ -1114,7 +1114,7 @@ ah_output(struct mbuf *m, struct tdb *td u_int32_t esn; esn = htonl((u_int32_t)(tdb->tdb_rpl >> 32)); - bcopy(, crda->crd_esn, 4); + memcpy(crda->crd_esn, , 4); crda->crd_flags |= CRD_F_ESN; } @@ -1138,9 +1138,8 @@ ah_output(struct mbuf *m, struct tdb *td */ switch (tdb->tdb_dst.sa.sa_family) { case AF_INET: - bcopy(((caddr_t)(tc + 1)) + - offsetof(struct ip, ip_len), - (caddr_t) , sizeof(u_int16_t)); + memcpy((caddr_t) , ((caddr_t)(tc + 1)) + + offsetof(struct ip, ip_len), sizeof(u_int16_t)); iplen = htons(ntohs(iplen) + rplen + ahx->authsize); m_copyback(m, offsetof(struct ip, ip_len), sizeof(u_int16_t), , M_NOWAIT); @@ -1148,9 +1147,8 @@ ah_output(struct mbuf *m, struct tdb *td #ifdef INET6 case AF_INET6: - bcopy(((caddr_t)(tc + 1)) + - offsetof(struct ip6_hdr, ip6_plen), - (caddr_t) , sizeof(u_int16_t)); + memcpy((caddr_t) , ((caddr_t)(tc + 1)) + + offsetof(struct ip6_hdr, ip6_plen), sizeof(u_int16_t)); iplen = htons(ntohs(iplen) + rplen + ahx->authsize); m_copyback(m, offsetof(struct ip6_hdr, ip6_plen), sizeof(u_int16_t), , M_NOWAIT); @@ -1188,7 +1186,7 @@ ah_output(struct mbuf *m, struct tdb *td tc->tc_spi = tdb->tdb_spi; tc->tc_proto = tdb->tdb_sproto; tc->tc_rdomain = tdb->tdb_rdomain; - bcopy(>tdb_dst, >tc_dst, sizeof(union sockaddr_union)); + memcpy(>tc_dst, >tdb_dst, sizeof(union sockaddr_union)); return crypto_dispatch(crp); } Index: ip_esp.c === RCS file: /cvs/src/sys/netinet/ip_esp.c,v retrieving revision 1.140 diff -u -p -r1.140 ip_esp.c --- ip_esp.c13 Sep 2016 19:56:55 - 1.140 +++ ip_esp.c15 Sep 2016 16:14:33 - @@ -262,7 +262,7 @@ esp_init(struct tdb *tdbp, struct xforms tdbp->tdb_emxkeylen = ii->ii_enckeylen; tdbp->tdb_emxkey = malloc(tdbp->tdb_emxkeylen, M_XDATA, M_WAITOK); - bcopy(ii->ii_enckey, tdbp->tdb_emxkey, tdbp->tdb_emxkeylen); + memcpy(tdbp->tdb_emxkey, ii->ii_enckey, tdbp->tdb_emxkeylen); memset(, 0, sizeof(crie)); @@ -283,7 +283,7 @@ esp_init(struct tdb *tdbp, struct xforms tdbp->tdb_amxkeylen =
Re: netinet6 free() diff
Hello - Regenerated diff against -current. Index: netinet6/frag6.c === RCS file: /cvs/src/sys/netinet6/frag6.c,v retrieving revision 1.67 diff -u -p -r1.67 frag6.c --- netinet6/frag6.c7 Mar 2016 18:44:00 - 1.67 +++ netinet6/frag6.c19 Aug 2016 12:46:40 - @@ -303,7 +303,7 @@ frag6_input(struct mbuf **mp, int *offp, /* dequeue the fragment. */ LIST_REMOVE(af6, ip6af_list); - free(af6, M_FTABLE, 0); + free(af6, M_FTABLE, sizeof(*af6)); /* adjust pointer. */ ip6err = mtod(merr, struct ip6_hdr *); @@ -348,14 +348,14 @@ frag6_input(struct mbuf **mp, int *offp, ecn0 = (ntohl(af6->ip6af_flow) >> 20) & IPTOS_ECN_MASK; if (ecn == IPTOS_ECN_CE) { if (ecn0 == IPTOS_ECN_NOTECT) { - free(ip6af, M_FTABLE, 0); + free(ip6af, M_FTABLE, sizeof(*ip6af)); goto dropfrag; } if (ecn0 != IPTOS_ECN_CE) af6->ip6af_flow |= htonl(IPTOS_ECN_CE << 20); } if (ecn == IPTOS_ECN_NOTECT && ecn0 != IPTOS_ECN_NOTECT) { - free(ip6af, M_FTABLE, 0); + free(ip6af, M_FTABLE, sizeof(*ip6af)); goto dropfrag; } @@ -384,7 +384,7 @@ frag6_input(struct mbuf **mp, int *offp, i, inet_ntop(AF_INET6, >ip6q_src, ip, sizeof(ip))); #endif - free(ip6af, M_FTABLE, 0); + free(ip6af, M_FTABLE, sizeof(*ip6af)); goto flushfrags; } } @@ -398,7 +398,7 @@ frag6_input(struct mbuf **mp, int *offp, i, inet_ntop(AF_INET6, >ip6q_src, ip, sizeof(ip))); #endif - free(ip6af, M_FTABLE, 0); + free(ip6af, M_FTABLE, sizeof(*ip6af)); goto flushfrags; } } @@ -449,12 +449,12 @@ frag6_input(struct mbuf **mp, int *offp, t = t->m_next; t->m_next = IP6_REASS_MBUF(af6); m_adj(t->m_next, af6->ip6af_offset); - free(af6, M_FTABLE, 0); + free(af6, M_FTABLE, sizeof(*af6)); } /* adjust offset to point where the original next header starts */ offset = ip6af->ip6af_offset - sizeof(struct ip6_frag); - free(ip6af, M_FTABLE, 0); + free(ip6af, M_FTABLE, sizeof(*ip6af)); ip6 = mtod(m, struct ip6_hdr *); ip6->ip6_plen = htons((u_short)next + offset - sizeof(struct ip6_hdr)); ip6->ip6_src = q6->ip6q_src; @@ -465,7 +465,7 @@ frag6_input(struct mbuf **mp, int *offp, if (frag6_deletefraghdr(m, offset) != 0) { TAILQ_REMOVE(_queue, q6, ip6q_queue); frag6_nfrags -= q6->ip6q_nfrag; - free(q6, M_FTABLE, 0); + free(q6, M_FTABLE, sizeof(*q6)); frag6_nfragpackets--; goto dropfrag; } @@ -480,7 +480,7 @@ frag6_input(struct mbuf **mp, int *offp, TAILQ_REMOVE(_queue, q6, ip6q_queue); frag6_nfrags -= q6->ip6q_nfrag; - free(q6, M_FTABLE, 0); + free(q6, M_FTABLE, sizeof(*q6)); frag6_nfragpackets--; if (m->m_flags & M_PKTHDR) { /* Isn't it always true? */ @@ -506,12 +506,12 @@ frag6_input(struct mbuf **mp, int *offp, while ((af6 = LIST_FIRST(>ip6q_asfrag)) != NULL) { LIST_REMOVE(af6, ip6af_list); m_freem(IP6_REASS_MBUF(af6)); - free(af6, M_FTABLE, 0); + free(af6, M_FTABLE, sizeof(*af6)); } ip6stat.ip6s_fragdropped += q6->ip6q_nfrag; TAILQ_REMOVE(_queue, q6, ip6q_queue); frag6_nfrags -= q6->ip6q_nfrag; - free(q6, M_FTABLE, 0); + free(q6, M_FTABLE, sizeof(*q6)); frag6_nfragpackets--; dropfrag: @@ -579,11 +579,11 @@ frag6_freef(struct ip6q *q6) ICMP6_TIME_EXCEED_REASSEMBLY, 0); } else m_freem(m); - free(af6, M_FTABLE, 0); + free(af6, M_FTABLE, sizeof(*af6)); } TAILQ_REMOVE(_queue, q6, ip6q_queue); frag6_nfrags -= q6->ip6q_nfrag; - free(q6, M_FTABLE, 0); + free(q6, M_FTABLE, sizeof(*q6)); frag6_nfragpackets--; } Index: netinet6/in6.c === RCS file: /cvs/src/sys/netinet6/in6.c,v retrieving revision 1.190 diff -u -p -r1.190 in6.c --- netinet6/in6.c 8 Aug 2016 13:09:36 - 1.190 +++ netinet6/in6.c 19 Aug 2016 12:46:41 - @@ -1917,5 +1917,5 @@ in6_domifdetach(struct ifnet *ifp, void
netinet6 free() diff
Hello - Here is a diff to add free sizes to netinet6/ Index: netinet6/frag6.c === RCS file: /cvs/src/sys/netinet6/frag6.c,v retrieving revision 1.67 diff -u -p -r1.67 frag6.c --- netinet6/frag6.c7 Mar 2016 18:44:00 - 1.67 +++ netinet6/frag6.c30 Jul 2016 17:17:14 - @@ -303,7 +303,7 @@ frag6_input(struct mbuf **mp, int *offp, /* dequeue the fragment. */ LIST_REMOVE(af6, ip6af_list); - free(af6, M_FTABLE, 0); + free(af6, M_FTABLE, sizeof(*af6)); /* adjust pointer. */ ip6err = mtod(merr, struct ip6_hdr *); @@ -348,14 +348,14 @@ frag6_input(struct mbuf **mp, int *offp, ecn0 = (ntohl(af6->ip6af_flow) >> 20) & IPTOS_ECN_MASK; if (ecn == IPTOS_ECN_CE) { if (ecn0 == IPTOS_ECN_NOTECT) { - free(ip6af, M_FTABLE, 0); + free(ip6af, M_FTABLE, sizeof(*ip6af)); goto dropfrag; } if (ecn0 != IPTOS_ECN_CE) af6->ip6af_flow |= htonl(IPTOS_ECN_CE << 20); } if (ecn == IPTOS_ECN_NOTECT && ecn0 != IPTOS_ECN_NOTECT) { - free(ip6af, M_FTABLE, 0); + free(ip6af, M_FTABLE, sizeof(*ip6af)); goto dropfrag; } @@ -384,7 +384,7 @@ frag6_input(struct mbuf **mp, int *offp, i, inet_ntop(AF_INET6, >ip6q_src, ip, sizeof(ip))); #endif - free(ip6af, M_FTABLE, 0); + free(ip6af, M_FTABLE, sizeof(*ip6af)); goto flushfrags; } } @@ -398,7 +398,7 @@ frag6_input(struct mbuf **mp, int *offp, i, inet_ntop(AF_INET6, >ip6q_src, ip, sizeof(ip))); #endif - free(ip6af, M_FTABLE, 0); + free(ip6af, M_FTABLE, sizeof(*ip6af)); goto flushfrags; } } @@ -449,12 +449,12 @@ frag6_input(struct mbuf **mp, int *offp, t = t->m_next; t->m_next = IP6_REASS_MBUF(af6); m_adj(t->m_next, af6->ip6af_offset); - free(af6, M_FTABLE, 0); + free(af6, M_FTABLE, sizeof(*af6)); } /* adjust offset to point where the original next header starts */ offset = ip6af->ip6af_offset - sizeof(struct ip6_frag); - free(ip6af, M_FTABLE, 0); + free(ip6af, M_FTABLE, sizeof(*ip6af)); ip6 = mtod(m, struct ip6_hdr *); ip6->ip6_plen = htons((u_short)next + offset - sizeof(struct ip6_hdr)); ip6->ip6_src = q6->ip6q_src; @@ -465,7 +465,7 @@ frag6_input(struct mbuf **mp, int *offp, if (frag6_deletefraghdr(m, offset) != 0) { TAILQ_REMOVE(_queue, q6, ip6q_queue); frag6_nfrags -= q6->ip6q_nfrag; - free(q6, M_FTABLE, 0); + free(q6, M_FTABLE, sizeof(*q6)); frag6_nfragpackets--; goto dropfrag; } @@ -480,7 +480,7 @@ frag6_input(struct mbuf **mp, int *offp, TAILQ_REMOVE(_queue, q6, ip6q_queue); frag6_nfrags -= q6->ip6q_nfrag; - free(q6, M_FTABLE, 0); + free(q6, M_FTABLE, sizeof(*q6)); frag6_nfragpackets--; if (m->m_flags & M_PKTHDR) { /* Isn't it always true? */ @@ -506,12 +506,12 @@ frag6_input(struct mbuf **mp, int *offp, while ((af6 = LIST_FIRST(>ip6q_asfrag)) != NULL) { LIST_REMOVE(af6, ip6af_list); m_freem(IP6_REASS_MBUF(af6)); - free(af6, M_FTABLE, 0); + free(af6, M_FTABLE, sizeof(*af6)); } ip6stat.ip6s_fragdropped += q6->ip6q_nfrag; TAILQ_REMOVE(_queue, q6, ip6q_queue); frag6_nfrags -= q6->ip6q_nfrag; - free(q6, M_FTABLE, 0); + free(q6, M_FTABLE, sizeof(*q6)); frag6_nfragpackets--; dropfrag: @@ -579,11 +579,11 @@ frag6_freef(struct ip6q *q6) ICMP6_TIME_EXCEED_REASSEMBLY, 0); } else m_freem(m); - free(af6, M_FTABLE, 0); + free(af6, M_FTABLE, sizeof(*af6)); } TAILQ_REMOVE(_queue, q6, ip6q_queue); frag6_nfrags -= q6->ip6q_nfrag; - free(q6, M_FTABLE, 0); + free(q6, M_FTABLE, sizeof(*q6)); frag6_nfragpackets--; } Index: netinet6/in6.c === RCS file: /cvs/src/sys/netinet6/in6.c,v retrieving revision 1.189 diff -u -p -r1.189 in6.c --- netinet6/in6.c 13 Jul 2016 08:40:46 - 1.189 +++ netinet6/in6.c 30 Jul 2016 17:17:15 - @@ -1915,5 +1915,5 @@ in6_domifdetach(struct ifnet *ifp, void
Re: nfs_vnops: nfs_lookitup - uninitialized var
Any thoughts on this? On Mon, Jun 06, 2016 at 01:36:05PM -0400, David Hill wrote: > Hello - > > Clang reports a possible user of an uninitalized variable in > nfs_vnops.c line 2605. > > attrflag is uninitialized when calling nfsm_postop_attr(), which is a > macro that only sets attrflag if (info.nmi_mrep != NULL). I am not sure > if that is possible, but maybe a KASSERT(info.nmi_mrep != NULL) before > nfsm_postop_attr() would catch a bug... > > Or just silence it with: > > Index: nfs_vnops.c > === > RCS file: /cvs/src/sys/nfs/nfs_vnops.c,v > retrieving revision 1.169 > diff -u -p -r1.169 nfs_vnops.c > --- nfs_vnops.c 29 Apr 2016 14:40:36 - 1.169 > +++ nfs_vnops.c 6 Jun 2016 17:34:24 - > @@ -2562,7 +2562,7 @@ nfs_lookitup(struct vnode *dvp, char *na > struct vnode *newvp = NULL; > struct nfsnode *np, *dnp = VTONFS(dvp); > caddr_t cp2; > - int error = 0, fhlen, attrflag; > + int error = 0, fhlen, attrflag = 0; > nfsfh_t *nfhp; > > info.nmi_v3 = NFS_ISV3(dvp); >
nfs_vnops: nfs_lookitup - uninitialized var
Hello - Clang reports a possible user of an uninitalized variable in nfs_vnops.c line 2605. attrflag is uninitialized when calling nfsm_postop_attr(), which is a macro that only sets attrflag if (info.nmi_mrep != NULL). I am not sure if that is possible, but maybe a KASSERT(info.nmi_mrep != NULL) before nfsm_postop_attr() would catch a bug... Or just silence it with: Index: nfs_vnops.c === RCS file: /cvs/src/sys/nfs/nfs_vnops.c,v retrieving revision 1.169 diff -u -p -r1.169 nfs_vnops.c --- nfs_vnops.c 29 Apr 2016 14:40:36 - 1.169 +++ nfs_vnops.c 6 Jun 2016 17:34:24 - @@ -2562,7 +2562,7 @@ nfs_lookitup(struct vnode *dvp, char *na struct vnode *newvp = NULL; struct nfsnode *np, *dnp = VTONFS(dvp); caddr_t cp2; - int error = 0, fhlen, attrflag; + int error = 0, fhlen, attrflag = 0; nfsfh_t *nfhp; info.nmi_v3 = NFS_ISV3(dvp);
pcmcia unused function diff
Hello - Remove unused functions. Index: dev/pcmcia/pcmcia.c === RCS file: /cvs/src/sys/dev/pcmcia/pcmcia.c,v retrieving revision 1.46 diff -u -p -r1.46 pcmcia.c --- dev/pcmcia/pcmcia.c 8 Oct 2012 21:47:50 - 1.46 +++ dev/pcmcia/pcmcia.c 2 Jun 2016 16:11:18 - @@ -58,13 +58,7 @@ void pcmcia_attach(struct device *, stru intpcmcia_activate(struct device *, int); intpcmcia_print(void *, const char *); void pcmcia_card_detach_notify(struct device *, void *); - -static inline void pcmcia_socket_enable(pcmcia_chipset_tag_t, -pcmcia_chipset_handle_t *); -static inline void pcmcia_socket_disable(pcmcia_chipset_tag_t, - pcmcia_chipset_handle_t *); - -int pcmcia_card_intr(void *); +intpcmcia_card_intr(void *); struct cfdriver pcmcia_cd = { NULL, "pcmcia", DV_DULL @@ -409,20 +403,6 @@ pcmcia_function_init(pf, cfe) /* Remember which configuration entry we are using. */ pf->cfe = cfe; -} - -static inline void pcmcia_socket_enable(pct, pch) - pcmcia_chipset_tag_t pct; - pcmcia_chipset_handle_t *pch; -{ - pcmcia_chip_socket_enable(pct, pch); -} - -static inline void pcmcia_socket_disable(pct, pch) - pcmcia_chipset_tag_t pct; - pcmcia_chipset_handle_t *pch; -{ - pcmcia_chip_socket_disable(pct, pch); } /* Enable a PCMCIA function */
Re: xhci(4) vs BIOS
On Tue, May 31, 2016 at 06:43:16PM +0200, Martin Pieuchot wrote: > I finally got my hands on a DELL Optiplex 3020. The BIOS on this > machines uses the xHCI controller to handle the keyboard and mouse. > > Turns out that I badly copy/pasted the ehci(4) code to take over the > HC from the BIOS. With the diff below I can now route all my ports > to xhci(4) and the machine no longer hang at boot. > > ok? > Fixes my Dell Latitude. Thanks! David
Re: kernel panic - rtable_match
Great! I appreciate the commit hint. Thanks On Fri, May 27, 2016 at 10:46:32PM +0100, Stuart Henderson wrote: > On 2016/05/27 17:29, David Hill wrote: > > Hello - > > > > Running openbsd current via cvs from today.. > > > > My machine keeps panic'ing with a uvm_fault in rtable_match. > > It locks my whole machine up, so I am unable to type anything. Perhaps > > someone can provide me some debugging printf's? > > I sent mpi some more details when I hit it earlier. Backtrace is here: > > rtable_match() at rtable_match+0x25 > rt_match() at rt_match+0x7b > _rtalloc() at _rtalloc+0x1f > pf_refragment6() at pf_refragment6+0x1f4 > pf_test() at pf_test+0x9ba > ip6_forward() at ip6_forward+0x20f > ip6_input() at ip6_input+0xad9 > ip6intr() at ip6intr+0x18 > if_netisr() at if_netisr+0xdc > taskq_thread() at taskq_thread+0x6c > > I haven't seen it again after backing out this commit: > > http://anoncvs.spacehopper.org/openbsd-sys/commit/?id=ffcc809d2ffdc00af088aa5285957d2472577a9e >
kernel panic - rtable_match
Hello - Running openbsd current via cvs from today.. My machine keeps panic'ing with a uvm_fault in rtable_match. It locks my whole machine up, so I am unable to type anything. Perhaps someone can provide me some debugging printf's? uvm_fault(0x81945e00, 0x1, 0, 1) -> e kernel: page fault trap, code=0 Stopped at rtable_match+0x25: movzbl 0x1(%rsi),%esi ddb{4}> 0x790 + 0x25 = 7b5 0790 : 790: 55 push %rbp 791: 48 89 e5mov%rsp,%rbp 794: 41 57 push %r15 796: 41 56 push %r14 798: 41 55 push %r13 79a: 49 89 f5mov%rsi,%r13 79d: 41 54 push %r12 79f: 53 push %rbx 7a0: 48 83 ec 28 sub$0x28,%rsp 7a4: 48 89 55 b8 mov%rdx,0xffb8(%rbp) 7a8: 48 8b 05 00 00 00 00mov0(%rip),%rax# 7af7af: 48 89 45 d0 mov%rax,0xffd0(%rbp) 7b3: 31 c0 xor%eax,%eax --> 7b5: 0f b6 76 01 movzbl 0x1(%rsi),%esi 7b9: e8 00 00 00 00 callq 7be 7be: 48 85 c0test %rax,%rax 7c1: 48 89 c3mov%rax,%rbx 7c4: 48 c7 45 c0 00 00 00movq $0x0,0xffc0(%rbp) 7cb: 00 7cc: 0f 84 13 01 00 00 je 8e5 7d2: 0f b6 40 2a movzbl 0x2a(%rax),%eax 7d6: 4e 8d 24 28 lea(%rax,%r13,1),%r12 7da: e8 00 00 00 00 callq 7df 7df: 4c 89 e6mov%r12,%rsi 7e2: 48 89 dfmov%rbx,%rdi 7e5: e8 00 00 00 00 callq 7ea 7ea: 48 85 c0test %rax,%rax 7ed: 49 89 c7mov%rax,%r15 7f0: 48 c7 45 c0 00 00 00movq $0x0,0xffc0(%rbp) 7f7: 00 7f8: 0f 84 e2 00 00 00 je 8e0 7fe: 4c 8d 75 c8 lea0xffc8(%rbp),%r14 802: 48 89 c6mov%rax,%rsi 805: 4c 89 f7mov%r14,%rdi 808: e8 00 00 00 00 callq 80d 80d: 48 89 c7mov%rax,%rdi 810: 48 89 45 c0 mov%rax,0xffc0(%rbp) 814: e8 00 00 00 00 callq 819 819: 4c 89 f7mov%r14,%rdi 81c: e8 00 00 00 00 callq 821 821: 48 8b 55 b8 mov0xffb8(%rbp),%rdx 825: 48 8b 7d c0 mov0xffc0(%rbp),%rdi 829: 4c 89 eemov%r13,%rsi 82c: e8 00 00 00 00 callq 831 831: 83 f8 ffcmp$0x,%eax 834: 41 89 c4mov%eax,%r12d 837: 0f 84 a3 00 00 00 je 8e0 83d: 3d ff ff 00 00 cmp$0x,%eax 842: 0f 8f fd 00 00 00 jg 945 848: 4c 89 femov%r15,%rsi 84b: 4c 89 f7mov%r14,%rdi 84e: 31 db xor%ebx,%ebx 850: e8 00 00 00 00 callq 855 855: 48 85 c0test %rax,%rax 858: 74 2d je 887 85a: 66 data16 85b: 66 data16 85c: 90 nop 85d: 66 data16 85e: 66 data16 85f: 90 nop 860: 48 8b 4d c0 mov0xffc0(%rbp),%rcx 864: 48 89 c2mov%rax,%rdx 867: 0f b6 40 6a movzbl 0x6a(%rax),%eax 86b: 48 8d 72 08 lea0x8(%rdx),%rsi 86f: 4c 89 f7mov%r14,%rdi 872: 3a 41 6acmp0x6a(%rcx),%al 875: 0f 94 c0sete %al 878: 0f b6 c0movzbl %al,%eax 87b: 01 c3 add%eax,%ebx 87d: e8 00 00 00 00 callq 882 882: 48 85 c0test %rax,%rax 885: 75 d9 jne860 887: 4c 89 f7mov%r14,%rdi 88a: e8 00 00 00 00 callq
Re: [diff] xhci intel port route freeze
Ugh, not enough testing. Breaks again on resume. Ignore this diff. Too excited about being able to charge my phone with my laptop :) - David
[diff] xhci intel port route freeze
Hello - Looking at the FreeBSD code, their xhci_pci_port_route function is called on activation and not on attach. OpenBSD calles it in xhci_pci_attach and xhci_pci_activate. If I remove it from attach, all my usb devices attach and no longer lock the machine. ugen1 at uhub4 port 2 "Apple Inc. iPhone" rev 2.00/7.01 addr 3 FreeBSD sets the port route function to use if intel in attach but does not call it: https://github.com/freebsd/freebsd/blob/5badcaaa0f325d543c4a79c30c6c91b0e88163fd/sys/dev/usb/controller/xhci_pci.c#L228 FreeBSD calls it in activate: https://github.com/freebsd/freebsd/blob/0f2211c30ded7871b441bfaa1647843f1b4fd0c2/sys/dev/usb/controller/xhci.c#L485 OpenBSD might be missing: https://github.com/freebsd/freebsd/blob/0f2211c30ded7871b441bfaa1647843f1b4fd0c2/sys/dev/usb/controller/xhci.c#L1439-L1445 Index: pci/xhci_pci.c === RCS file: /cvs/src/sys/dev/pci/xhci_pci.c,v retrieving revision 1.7 diff -u -p -r1.7 xhci_pci.c --- pci/xhci_pci.c 2 Nov 2015 14:53:10 - 1.7 +++ pci/xhci_pci.c 6 Feb 2016 16:23:06 - @@ -192,9 +192,6 @@ xhci_pci_attach(struct device *parent, s goto disestablish_ret; } - if (PCI_VENDOR(psc->sc_id) == PCI_VENDOR_INTEL) - xhci_pci_port_route(psc); - /* Attach usb device. */ config_found(self, >sc.sc_bus, usbctlprint);
[diff] IFQ has its own protection
Hello - IFQ has its own protection, so no need for splnet/splx. if_gif.c - use for (;;) to match the other drivers. Index: net/if_gif.c === RCS file: /cvs/src/sys/net/if_gif.c,v retrieving revision 1.83 diff -u -p -r1.83 if_gif.c --- net/if_gif.c5 Dec 2015 10:07:55 - 1.83 +++ net/if_gif.c14 Jan 2016 00:26:10 - @@ -164,13 +164,9 @@ gif_start(struct ifnet *ifp) { struct gif_softc *sc = (struct gif_softc*)ifp; struct mbuf *m; - int s; - while (1) { - s = splnet(); + for (;;) { IFQ_DEQUEUE(>if_snd, m); - splx(s); - if (m == NULL) break; Index: net/if_mpe.c === RCS file: /cvs/src/sys/net/if_mpe.c,v retrieving revision 1.52 diff -u -p -r1.52 if_mpe.c --- net/if_mpe.c5 Dec 2015 10:07:55 - 1.52 +++ net/if_mpe.c14 Jan 2016 00:26:10 - @@ -143,16 +143,12 @@ mpestart(struct ifnet *ifp0) { struct mbuf *m; struct sockaddr *sa = (struct sockaddr *) - int s; sa_family_t af; struct rtentry *rt; struct ifnet*ifp; for (;;) { - s = splnet(); IFQ_DEQUEUE(>if_snd, m); - splx(s); - if (m == NULL) return; Index: net/if_pppx.c === RCS file: /cvs/src/sys/net/if_pppx.c,v retrieving revision 1.48 diff -u -p -r1.48 if_pppx.c --- net/if_pppx.c 5 Dec 2015 16:09:09 - 1.48 +++ net/if_pppx.c 14 Jan 2016 00:26:10 - @@ -995,15 +995,13 @@ pppx_if_start(struct ifnet *ifp) { struct pppx_if *pxi = (struct pppx_if *)ifp->if_softc; struct mbuf *m; - int proto, s; + int proto; if (!ISSET(ifp->if_flags, IFF_RUNNING)) return; for (;;) { - s = splnet(); IFQ_DEQUEUE(>if_snd, m); - splx(s); if (m == NULL) break; Index: net/if_vxlan.c === RCS file: /cvs/src/sys/net/if_vxlan.c,v retrieving revision 1.35 diff -u -p -r1.35 if_vxlan.c --- net/if_vxlan.c 5 Dec 2015 10:07:55 - 1.35 +++ net/if_vxlan.c 14 Jan 2016 00:26:10 - @@ -275,15 +275,12 @@ void vxlanstart(struct ifnet *ifp) { struct mbuf *m; - int s; for (;;) { - s = splnet(); IFQ_DEQUEUE(>if_snd, m); - splx(s); - if (m == NULL) return; + ifp->if_opackets++; #if NBPFILTER > 0
uvm_io: uiomovei -> uiomove
Hello sz is type vsize_t, and vsize_t and vaddr_t are unsigned long on every arch, so I believe this can safely be converted. vaddr_t baseva, endva, pageoffset, kva; vsize_t chunksz, togo, sz; - David Index: uvm/uvm_io.c === RCS file: /cvs/src/sys/uvm/uvm_io.c,v retrieving revision 1.25 diff -u -p -r1.25 uvm_io.c --- uvm/uvm_io.c14 Mar 2015 03:38:53 - 1.25 +++ uvm/uvm_io.c31 Dec 2015 21:46:14 - @@ -109,7 +109,7 @@ uvm_io(vm_map_t map, struct uio *uio, in sz = chunksz - pageoffset; if (sz > togo) sz = togo; - error = uiomovei((caddr_t) (kva + pageoffset), sz, uio); + error = uiomove((caddr_t) (kva + pageoffset), sz, uio); togo -= sz; baseva += chunksz;
Re: initial 11n support for iwn (n, not m)
On Fri, Dec 18, 2015 at 08:52:07PM +, Stuart Henderson wrote: > On 2015/12/17 19:43, Frank Groeneveld wrote: > > iwn0: fatal firmware error > > So this firmware crash... > > > firmware error log: > > error type = "UNKNOWN" (0x14E2) > > program counter = 0x00018100 > > source line = 0x0216 > > error data = 0x0028 > > branch link = 0x000180E2000180E2 > > interrupt link = 0xDBEA > > time= 3006541902 > > I'm seeing the same crash when I associate to a 2GHz channel where > the AP has set a flag in beacons to warn stations that there are > non-11n devices associated. > > Around line 4900 in sys/dev/pci/if_iwn.c you have this: > > case IEEE80211_HTPROT_NONE: > break; > case IEEE80211_HTPROT_NONMEMBER: > case IEEE80211_HTPROT_NONHT_MIXED: > sc->rxon.flags |= > htole32(IWN_RXON_HT_RXON_HT_MODE_MIXED); > break; > > Try this as I suspect it might fix your crash (unless Stefan > comes up with a better change to try first :) > > case IEEE80211_HTPROT_NONE: > break; > case IEEE80211_HTPROT_NONMEMBER: > case IEEE80211_HTPROT_NONHT_MIXED: > if (IEEE80211_IS_CHAN_5GHZ(ni->ni_chan)) > sc->rxon.flags |= > htole32(IWN_RXON_HT_RXON_HT_MODE_MIXED); > break; > I had the firmware bug on Centrino Ultimate-N 6300: iwn0: fatal firmware error firmware error log: error type = "SYSASSERT" (0x0005) program counter = 0x00022278 source line = 0x0218 error data = 0x0218000B branch link = 0x0002225800022258 interrupt link = 0x1532 time= 2127856977 With sthen@'s patch I can associate, dhcp, and use net. Nice find! - David
Re: initial 11n support for iwn (n, not m)
On Wed, Dec 16, 2015 at 05:15:27PM +0100, Stefan Sperling wrote: > On Wed, Dec 16, 2015 at 10:14:49AM -0500, David Hill wrote: > > Hi Stefan - > > > > Thanks for the 11n work! > > > > Unfortunately, your diff breaks iwn on my machine. > > > > iwn0 at pci2 dev 0 function 0 "Intel Centrino Ultimate-N 6300" rev 0x35: > > msi, MIMO 3T3R, MoW, > > > > It spews over and over: > > > > iwn0: fatal firmware error > > firmware error log: > > error type = "SYSASSERT" (0x0005) > > program counter = 0x00022278 > > source line = 0x0218 > > error data = 0x0218000B > > branch link = 0x0002225800022258 > > interrupt link = 0x1532 > > time= 2127856977 > > driver status: > > tx ring 0: qid=0 cur=4 queued=0 > > tx ring 1: qid=1 cur=0 queued=0 > > tx ring 2: qid=2 cur=0 queued=0 > > tx ring 3: qid=3 cur=0 queued=0 > > tx ring 4: qid=4 cur=41 queued=0 > > tx ring 5: qid=5 cur=0 queued=0 > > tx ring 6: qid=6 cur=0 queued=0 > > tx ring 7: qid=7 cur=0 queued=0 > > tx ring 8: qid=8 cur=0 queued=0 > > tx ring 9: qid=9 cur=0 queued=0 > > tx ring 10: qid=10 cur=0 queued=0 > > tx ring 11: qid=11 cur=0 queued=0 > > tx ring 12: qid=12 cur=0 queued=0 > > tx ring 13: qid=13 cur=0 queued=0 > > tx ring 14: qid=14 cur=0 queued=0 > > tx ring 15: qid=15 cur=0 queued=0 > > tx ring 16: qid=16 cur=0 queued=0 > > tx ring 17: qid=17 cur=0 queued=0 > > tx ring 18: qid=18 cur=0 queued=0 > > tx ring 19: qid=19 cur=0 queued=0 > > rx ring: cur=14 > > 802.11 state 4 > > > > Thanks for testing! > > I cannot do much based on the information provided. > Could you recompile with IWM_DEBUG defined, and perhaps place a few > additional printfs at strategic locations, to figure out which > firmware command is last sent before the firmware crashes? > That would help me a great deal. > > If you don't want the firmware to be restarted over and over so it > won't print these lines repeatedly, disabling the init_task which > attempts to recover from firmware crashes might help: > > if (r1 & (IWN_INT_SW_ERR | IWN_INT_HW_ERR)) { > printf("%s: fatal firmware error\n", sc->sc_dev.dv_xname); > /* Dump firmware error log and stop. */ > iwn_fatal_intr(sc); > iwn_stop(ifp, 1); > task_add(systq, >init_task); <-- remove this line > return 1; > } > Little more time to play, but not much. Will play more tonight. I do not have open wifi to test with, wpakey required. 16:21:14.335908 802.11 flags=0<>: probe response, caps=2061<ESS,PRIVACY,SHORT_PREAMBLE,SHORT_SLOTTIME>, ssid (wifi), rates 1M 2M 5M 11M 6M 9M 12M 18M, ds (chan 11), country 'US ', erp 0x00, rsn 0x010fac04010fac04010fac02, xrates 24M 36M 48M 54M, htcaps=<20MHz,TXSTBC,RXSTBC 1 stream,A-MSDU 3839,A-MPDU max 65535,A-MPDU spacing 8.00us,RxMCS 0x>, ifconfig iwn0 up works ifconfig iwn0 scan works but as soon as I use nwid/wpakey to associate, it bombs. ... sending scan command nchan=24 scan finished nchan=24 status=1 chan=165 sending scan command nchan=13 scan finished nchan=13 status=1 chan=13 sending scan command nchan=24 scan finished nchan=24 status=1 chan=165 rxon chan 11 flags 40008025 cck f ofdm 15 setting TX power adding broadcast node timing bintval=400, tstamp=5529864295299, init=306301 iwn_run: htprot = 3 rxon chan 11 flags 44008035 cck f ofdm 15 setting TX power adding BSS node setting link quality for node 0 setting initial differential gains sending request for statistics iwn0: fatal firmware error firmware error log: error type = "SYSASSERT" (0x0005) program counter = 0x00022278 source line = 0x0218 error data = 0x0218000B branch link = 0x0002225800022258 interrupt link = 0x1532 time= 2241458206 driver status: tx ring 0: qid=0 cur=2 queued=0 tx ring 1: qid=1 cur=0 queued=0 tx ring 2: qid=2 cur=0 queued=0 tx ring 3: qid=3 cur=0 queued=0 tx ring 4: qid=4 cur=63 queued=0 tx ring 5: qid=5 cur=0 queued=0 tx ring 6: qid=6 cur=0 queued=0 tx ring 7: qid=7 cur=0 queued=0 tx ring 8: qid=8 cur=0 queued=0 tx ring 9: qid=9 cur=0 queued=0 tx ring 10: qid=10 cur=0 queued=0 tx ring 11: qid=11 cur=0 queued=0 tx ring 12: qid=12 cur=0 queued=0 tx ring 13: qid=13 cur=0 queued=0 tx ring 14: qid=14 cur=0 queued=0 tx ring 15: qid=15 cur=0 queued=0 tx ring 16: qid=16 cur=0 queued=0 tx ring 17: qid=17 cur=0 queued=0 tx ring 18: qid=18 cur=0 queued=0 tx ring 19: qid=19 cur=0 queued=0 rx ring: cur=20 802.11 state 4
Re: initial 11n support for iwn (n, not m)
Hi Stefan - Thanks for the 11n work! Unfortunately, your diff breaks iwn on my machine. iwn0 at pci2 dev 0 function 0 "Intel Centrino Ultimate-N 6300" rev 0x35: msi, MIMO 3T3R, MoW, It spews over and over: iwn0: fatal firmware error firmware error log: error type = "SYSASSERT" (0x0005) program counter = 0x00022278 source line = 0x0218 error data = 0x0218000B branch link = 0x0002225800022258 interrupt link = 0x1532 time= 2127856977 driver status: tx ring 0: qid=0 cur=4 queued=0 tx ring 1: qid=1 cur=0 queued=0 tx ring 2: qid=2 cur=0 queued=0 tx ring 3: qid=3 cur=0 queued=0 tx ring 4: qid=4 cur=41 queued=0 tx ring 5: qid=5 cur=0 queued=0 tx ring 6: qid=6 cur=0 queued=0 tx ring 7: qid=7 cur=0 queued=0 tx ring 8: qid=8 cur=0 queued=0 tx ring 9: qid=9 cur=0 queued=0 tx ring 10: qid=10 cur=0 queued=0 tx ring 11: qid=11 cur=0 queued=0 tx ring 12: qid=12 cur=0 queued=0 tx ring 13: qid=13 cur=0 queued=0 tx ring 14: qid=14 cur=0 queued=0 tx ring 15: qid=15 cur=0 queued=0 tx ring 16: qid=16 cur=0 queued=0 tx ring 17: qid=17 cur=0 queued=0 tx ring 18: qid=18 cur=0 queued=0 tx ring 19: qid=19 cur=0 queued=0 rx ring: cur=14 802.11 state 4
netinet6 - bcopy -> memcpy
Hello - Here are a few bcopy -> memcpy conversions for buffers that do not overlap. Index: sys/netinet6/ip6_forward.c === RCS file: /cvs/src/sys/netinet6/ip6_forward.c,v retrieving revision 1.86 diff -u -p -r1.86 ip6_forward.c --- sys/netinet6/ip6_forward.c 2 Nov 2015 07:22:28 - 1.86 +++ sys/netinet6/ip6_forward.c 2 Dec 2015 17:20:27 - @@ -206,7 +206,7 @@ reroute: } /* We need to do IPsec */ - bcopy(>tdb_dst, , sizeof(sdst)); + memcpy(, >tdb_dst, sizeof(sdst)); sspi = tdb->tdb_spi; sproto = tdb->tdb_sproto; } Index: sys/netinet6/ip6_input.c === RCS file: /cvs/src/sys/netinet6/ip6_input.c,v retrieving revision 1.151 diff -u -p -r1.151 ip6_input.c --- sys/netinet6/ip6_input.c11 Nov 2015 10:23:23 - 1.151 +++ sys/netinet6/ip6_input.c2 Dec 2015 17:20:28 - @@ -804,7 +804,7 @@ ip6_process_hopopts(struct mbuf *m, u_in return (-1); } optlen = IP6OPT_RTALERT_LEN; - bcopy((caddr_t)(opt + 2), (caddr_t)_val, 2); + memcpy(_val, opt + 2, sizeof(rtalert_val)); *rtalertp = ntohs(rtalert_val); break; case IP6OPT_JUMBO: @@ -837,9 +837,9 @@ ip6_process_hopopts(struct mbuf *m, u_in /* * We may see jumbolen in unaligned location, so -* we'd need to perform bcopy(). +* we'd need to perform memcpy(). */ - bcopy(opt + 2, , sizeof(jumboplen)); + memcpy(, opt + 2, sizeof(jumboplen)); jumboplen = (u_int32_t)htonl(jumboplen); #if 1 @@ -962,7 +962,7 @@ ip6_savecontrol(struct inpcb *in6p, stru /* RFC 2292 sec. 5 */ if ((in6p->inp_flags & IN6P_PKTINFO) != 0) { struct in6_pktinfo pi6; - bcopy(>ip6_dst, _addr, sizeof(struct in6_addr)); + memcpy(_addr, >ip6_dst, sizeof(struct in6_addr)); if (IN6_IS_SCOPE_EMBED(_addr)) pi6.ipi6_addr.s6_addr16[1] = 0; pi6.ipi6_ifindex = m ? m->m_pkthdr.ph_ifidx : 0; Index: sys/netinet6/ip6_output.c === RCS file: /cvs/src/sys/netinet6/ip6_output.c,v retrieving revision 1.201 diff -u -p -r1.201 ip6_output.c --- sys/netinet6/ip6_output.c 2 Dec 2015 13:29:26 - 1.201 +++ sys/netinet6/ip6_output.c 2 Dec 2015 17:20:28 - @@ -2015,7 +2015,7 @@ do {\ dst->type = malloc(hlen, M_IP6OPT, canwait);\ if (dst->type == NULL && canwait == M_NOWAIT)\ goto bad;\ - bcopy(src->type, dst->type, hlen);\ + memcpy(dst->type, src->type, hlen);\ }\ } while (/*CONSTCOND*/ 0) Index: sys/netinet6/raw_ip6.c === RCS file: /cvs/src/sys/netinet6/raw_ip6.c,v retrieving revision 1.87 diff -u -p -r1.87 raw_ip6.c --- sys/netinet6/raw_ip6.c 24 Nov 2015 13:37:16 - 1.87 +++ sys/netinet6/raw_ip6.c 2 Dec 2015 17:20:28 - @@ -756,7 +756,7 @@ rip6_usrreq(struct socket *so, int req, bzero(, sizeof(tmp)); tmp.sin6_family = AF_INET6; tmp.sin6_len = sizeof(struct sockaddr_in6); - bcopy(>inp_faddr6, _addr, + memcpy(_addr, >inp_faddr6, sizeof(struct in6_addr)); dst = } else {
Re: netstat -P - no namelist
On Fri, Nov 20, 2015 at 12:07:36PM -0500, David Hill wrote: > Hello - > > I used to use netstat -P to view PCB information. Running -current, I > get 'no namelist' now. Any ideas? > > 0xff0397c4da50 tcp 0 0 127.0.0.1.33845127.0.0.1.18333 > ESTABLISHED > > # netstat -P 0xff0397c4da50 > netstat: no namelist > > Thanks, > David > I am not sure if this is a fix or a hint, but it does provide me with the information I used to get. Did something change that would cause n_type to always be 0 (or unset?) Index: main.c === RCS file: /cvs/src/usr.bin/netstat/main.c,v retrieving revision 1.108 diff -u -p -r1.108 main.c --- main.c 23 Oct 2015 08:18:57 - 1.108 +++ main.c 23 Nov 2015 15:50:57 - @@ -331,7 +331,7 @@ main(int argc, char *argv[]) (need_nlist ? 0 : KVM_NO_FILES), buf)) == NULL) errx(1, "kvm_openfiles: %s", buf); - if (need_nlist && (kvm_nlist(kvmd, nl) < 0 || nl[0].n_type == 0)) { + if (need_nlist && (kvm_nlist(kvmd, nl) < 0)) { if (nlistf) errx(1, "%s: no namelist", nlistf); else
netstat -P - no namelist
Hello - I used to use netstat -P to view PCB information. Running -current, I get 'no namelist' now. Any ideas? 0xff0397c4da50 tcp 0 0 127.0.0.1.33845127.0.0.1.18333 ESTABLISHED # netstat -P 0xff0397c4da50 netstat: no namelist Thanks, David
tcpbench pledge
Hello - pledge starts after getopt because of setrtable. rpath needed incase -k (kvm_openfile) proc needed for drop_gid (setresgid) I believe I've hit every code path. More eyes are welcome. Index: tcpbench.c === RCS file: /cvs/src/usr.bin/tcpbench/tcpbench.c,v retrieving revision 1.46 diff -u -p -r1.46 tcpbench.c --- tcpbench.c 9 Feb 2015 23:46:23 - 1.46 +++ tcpbench.c 10 Nov 2015 16:43:16 - @@ -986,8 +986,6 @@ quit(int sig, short event, void *arg) int main(int argc, char **argv) { - extern int optind; - extern char *optarg; struct timeval tv; unsigned int secs, rtable; @@ -1108,6 +1106,9 @@ main(int argc, char **argv) } } + if (pledge("stdio rpath dns inet id proc", NULL) == -1) + err(1, "pledge"); + argv += optind; argc -= optind; if ((argc != (ptb->sflag ? 0 : 1)) || @@ -1125,6 +1126,9 @@ main(int argc, char **argv) } else drop_gid(); + if (pledge("stdio id dns inet", NULL) == -1) + err(1, "pledge"); + if (!ptb->sflag) host = argv[0]; /* @@ -1169,6 +1173,9 @@ main(int argc, char **argv) errx(1, "getaddrinfo: %s", gai_strerror(herr)); } + if (pledge("stdio id inet", NULL) == -1) + err(1, "pledge"); + if (getrlimit(RLIMIT_NOFILE, ) == -1) err(1, "getrlimit"); if (rl.rlim_cur < MAX_FD) @@ -1177,7 +1184,10 @@ main(int argc, char **argv) err(1, "setrlimit"); if (getrlimit(RLIMIT_NOFILE, ) == -1) err(1, "getrlimit"); - + + if (pledge("stdio inet", NULL) == -1) + err(1, "pledge"); + /* Init world */ TAILQ_INIT(_queue); if ((ptb->dummybuf = malloc(ptb->dummybuf_len)) == NULL) @@ -1216,7 +1226,10 @@ main(int argc, char **argv) } client_init(aitop, nconn, udp_sc, aib); } - + + if (pledge("stdio", NULL) == -1) + err(1, "pledge"); + /* libevent main loop*/ event_dispatch();
ip6_output bcopy->memcpy
Hello - This diff converts some malloc/bcopy to malloc/memcpy. netinet6 didn't get the bcopy->memcpy overhaul like netinet did. Index: netinet6/ip6_output.c === RCS file: /cvs/src/sys/netinet6/ip6_output.c,v retrieving revision 1.189 diff -u -p -r1.189 ip6_output.c --- netinet6/ip6_output.c 23 Sep 2015 08:49:46 - 1.189 +++ netinet6/ip6_output.c 8 Oct 2015 15:09:01 - @@ -2189,7 +2189,7 @@ do {\ dst->type = malloc(hlen, M_IP6OPT, canwait);\ if (dst->type == NULL && canwait == M_NOWAIT)\ goto bad;\ - bcopy(src->type, dst->type, hlen);\ + memcpy(dst->type, src->type, hlen);\ }\ } while (/*CONSTCOND*/ 0) @@ -2211,7 +2211,7 @@ copypktopts(struct ip6_pktopts *dst, str M_IP6OPT, canwait); if (dst->ip6po_nexthop == NULL) goto bad; - bcopy(src->ip6po_nexthop, dst->ip6po_nexthop, + memcpy(dst->ip6po_nexthop, src->ip6po_nexthop, src->ip6po_nexthop->sa_len); } PKTOPT_EXTHDRCPY(ip6po_hbh); @@ -2847,7 +2847,7 @@ ip6_setpktopt(int optname, u_char *buf, opt->ip6po_nexthop = malloc(*buf, M_IP6OPT, M_NOWAIT); if (opt->ip6po_nexthop == NULL) return (ENOBUFS); - bcopy(buf, opt->ip6po_nexthop, *buf); + memcpy(opt->ip6po_nexthop, buf, *buf); break; case IPV6_2292HOPOPTS: @@ -2882,7 +2882,7 @@ ip6_setpktopt(int optname, u_char *buf, opt->ip6po_hbh = malloc(hbhlen, M_IP6OPT, M_NOWAIT); if (opt->ip6po_hbh == NULL) return (ENOBUFS); - bcopy(hbh, opt->ip6po_hbh, hbhlen); + memcpy(opt->ip6po_hbh, hbh, hbhlen); break; } @@ -2945,7 +2945,7 @@ ip6_setpktopt(int optname, u_char *buf, *newdest = malloc(destlen, M_IP6OPT, M_NOWAIT); if (*newdest == NULL) return (ENOBUFS); - bcopy(dest, *newdest, destlen); + memcpy(*newdest, dest, destlen); break; } @@ -2986,7 +2986,7 @@ ip6_setpktopt(int optname, u_char *buf, opt->ip6po_rthdr = malloc(rthlen, M_IP6OPT, M_NOWAIT); if (opt->ip6po_rthdr == NULL) return (ENOBUFS); - bcopy(rth, opt->ip6po_rthdr, rthlen); + memcpy(opt->ip6po_rthdr, rth, rthlen); break; }
Re: kill struct inpcbtable's inpt_lastport
On Sat, Sep 19, 2015 at 07:57:00PM +0200, Vincent Gross wrote: > On 09/18/15 23:39, David Hill wrote: > > On Fri, Sep 18, 2015 at 11:05:55PM +0200, Vincent Gross wrote: > >> On 09/18/15 15:18, David Hill wrote: > >>> Is this 'if (count)' statement needed? We know first > last, so count > >>> will always be positive. lastport will always be set. > >> > >>> if last == first, then the if statement will be false and lastport will > >>> be uninitialized, I believe. > >>> > >> > >> Both remarks are true, but I think it is better to keep a more extensive > >> refactoring in a separate diff, refactoring that shall get rid of this > >> yucky code duplication. > >> > > > > Well, this code changes the current behavior. I'd at least change > > lastport to be initialized to 0 to keep the behavior the same. It was > > previously set to 0 with M_ZERO. > > > > Fixed. Ok ? LGTM. > > Index: sys/netinet/in_pcb.c > === > RCS file: /cvs/src/sys/netinet/in_pcb.c,v > retrieving revision 1.179 > diff -u -p -r1.179 in_pcb.c > --- sys/netinet/in_pcb.c 11 Sep 2015 15:29:47 - 1.179 > +++ sys/netinet/in_pcb.c 19 Sep 2015 17:52:42 - > @@ -199,7 +199,6 @@ in_pcbinit(struct inpcbtable *table, int > >inpt_lhash); > if (table->inpt_lhashtbl == NULL) > panic("in_pcbinit: hashinit failed for lport"); > - table->inpt_lastport = 0; > table->inpt_count = 0; > arc4random_buf(>inpt_key, sizeof(table->inpt_key)); > } > @@ -281,8 +280,8 @@ in_pcbbind(struct inpcb *inp, struct mbu > { > struct socket *so = inp->inp_socket; > struct inpcbtable *table = inp->inp_table; > - u_int16_t *lastport = >inp_table->inpt_lastport; > struct sockaddr_in *sin; > + u_int16_t lastport = 0; > u_int16_t lport = 0; > int wild = 0, reuseport = (so->so_options & SO_REUSEPORT); > int error; > @@ -391,16 +390,16 @@ in_pcbbind(struct inpcb *inp, struct mbu >*/ > count = first - last; > if (count) > - *lastport = first - arc4random_uniform(count); > + lastport = first - arc4random_uniform(count); > > do { > if (count-- < 0)/* completely used? */ > return (EADDRNOTAVAIL); > - --*lastport; > - if (*lastport > first || *lastport < last) > - *lastport = first; > - lport = htons(*lastport); > - } while (in_baddynamic(*lastport, > so->so_proto->pr_protocol) || > + --lastport; > + if (lastport > first || lastport < last) > + lastport = first; > + lport = htons(lastport); > + } while (in_baddynamic(lastport, > so->so_proto->pr_protocol) || > in_pcblookup(table, _addr, 0, > >inp_laddr, lport, wild, inp->inp_rtableid)); > } else { > @@ -409,16 +408,16 @@ in_pcbbind(struct inpcb *inp, struct mbu >*/ > count = last - first; > if (count) > - *lastport = first + arc4random_uniform(count); > + lastport = first + arc4random_uniform(count); > > do { > if (count-- < 0)/* completely used? */ > return (EADDRNOTAVAIL); > - ++*lastport; > - if (*lastport < first || *lastport > last) > - *lastport = first; > - lport = htons(*lastport); > - } while (in_baddynamic(*lastport, > so->so_proto->pr_protocol) || > + ++lastport; > + if (lastport < first || lastport > last) > + lastport = first; > + lport = htons(lastport); > + } while (in_baddynamic(lastport, > so->so_proto->pr_protocol) || > in_pcblookup(table, _addr, 0, >
Re: kill struct inpcbtable's inpt_lastport
On Fri, Sep 18, 2015 at 11:05:55PM +0200, Vincent Gross wrote: > On 09/18/15 15:18, David Hill wrote: > > Is this 'if (count)' statement needed? We know first > last, so count > > will always be positive. lastport will always be set. > > > if last == first, then the if statement will be false and lastport will > > be uninitialized, I believe. > > > > Both remarks are true, but I think it is better to keep a more extensive > refactoring in a separate diff, refactoring that shall get rid of this > yucky code duplication. > Well, this code changes the current behavior. I'd at least change lastport to be initialized to 0 to keep the behavior the same. It was previously set to 0 with M_ZERO. > -- > Vincent Gross >