diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2017-01-09 14:47:04 +0100 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2017-01-10 11:03:27 +0100 |
commit | 0577772720a4ecb050a230f75346f90b246e93c8 (patch) | |
tree | a3fba8bb57e77c932e08dd0d4bbe49adb6312e5e /freebsd/sys | |
parent | Update to FreeBSD head 2016-12-10 (diff) | |
download | rtems-libbsd-0577772720a4ecb050a230f75346f90b246e93c8.tar.bz2 |
Update to FreeBSD head 2017-01-09
Git mirror commit 1f8e4a995a6ede4bdb24e6d335ccda2bdb0175ab.
Diffstat (limited to 'freebsd/sys')
73 files changed, 2835 insertions, 1724 deletions
diff --git a/freebsd/sys/arm/xilinx/zy7_slcr.c b/freebsd/sys/arm/xilinx/zy7_slcr.c index dc6475c0..e7b8ce77 100644 --- a/freebsd/sys/arm/xilinx/zy7_slcr.c +++ b/freebsd/sys/arm/xilinx/zy7_slcr.c @@ -507,7 +507,7 @@ zy7_pl_fclk_enabled(int unit) } int -zy7_pl_level_shifters_enabled() +zy7_pl_level_shifters_enabled(void) { struct zy7_slcr_softc *sc = zy7_slcr_softc_p; @@ -524,7 +524,7 @@ zy7_pl_level_shifters_enabled() } void -zy7_pl_level_shifters_enable() +zy7_pl_level_shifters_enable(void) { struct zy7_slcr_softc *sc = zy7_slcr_softc_p; @@ -539,7 +539,7 @@ zy7_pl_level_shifters_enable() } void -zy7_pl_level_shifters_disable() +zy7_pl_level_shifters_disable(void) { struct zy7_slcr_softc *sc = zy7_slcr_softc_p; diff --git a/freebsd/sys/cam/scsi/scsi_all.c b/freebsd/sys/cam/scsi/scsi_all.c index 9e8924c5..6ebf9eec 100644 --- a/freebsd/sys/cam/scsi/scsi_all.c +++ b/freebsd/sys/cam/scsi/scsi_all.c @@ -1240,58 +1240,58 @@ static struct asc_table_entry asc_table[] = { { SST(0x0A, 0x00, SS_FATAL | ENOSPC, "Error log overflow") }, /* DTLPWROMAEBKVF */ - { SST(0x0B, 0x00, SS_RDEF, + { SST(0x0B, 0x00, SS_NOP | SSQ_PRINT_SENSE, "Warning") }, /* DTLPWROMAEBKVF */ - { SST(0x0B, 0x01, SS_RDEF, + { SST(0x0B, 0x01, SS_NOP | SSQ_PRINT_SENSE, "Warning - specified temperature exceeded") }, /* DTLPWROMAEBKVF */ - { SST(0x0B, 0x02, SS_RDEF, + { SST(0x0B, 0x02, SS_NOP | SSQ_PRINT_SENSE, "Warning - enclosure degraded") }, /* DTLPWROMAEBKVF */ - { SST(0x0B, 0x03, SS_RDEF, /* XXX TBD */ + { SST(0x0B, 0x03, SS_NOP | SSQ_PRINT_SENSE, "Warning - background self-test failed") }, /* DTLPWRO AEBKVF */ - { SST(0x0B, 0x04, SS_RDEF, /* XXX TBD */ + { SST(0x0B, 0x04, SS_NOP | SSQ_PRINT_SENSE, "Warning - background pre-scan detected medium error") }, /* DTLPWRO AEBKVF */ - { SST(0x0B, 0x05, SS_RDEF, /* XXX TBD */ + { SST(0x0B, 0x05, SS_NOP | SSQ_PRINT_SENSE, "Warning - background medium scan detected medium error") }, /* DTLPWROMAEBKVF */ - { SST(0x0B, 0x06, SS_RDEF, /* XXX TBD */ + { SST(0x0B, 0x06, SS_NOP | SSQ_PRINT_SENSE, "Warning - non-volatile cache now volatile") }, /* DTLPWROMAEBKVF */ - { SST(0x0B, 0x07, SS_RDEF, /* XXX TBD */ + { SST(0x0B, 0x07, SS_NOP | SSQ_PRINT_SENSE, "Warning - degraded power to non-volatile cache") }, /* DTLPWROMAEBKVF */ - { SST(0x0B, 0x08, SS_RDEF, /* XXX TBD */ + { SST(0x0B, 0x08, SS_NOP | SSQ_PRINT_SENSE, "Warning - power loss expected") }, /* D */ - { SST(0x0B, 0x09, SS_RDEF, /* XXX TBD */ + { SST(0x0B, 0x09, SS_NOP | SSQ_PRINT_SENSE, "Warning - device statistics notification available") }, /* DTLPWROMAEBKVF */ - { SST(0x0B, 0x0A, SS_RDEF, /* XXX TBD */ + { SST(0x0B, 0x0A, SS_NOP | SSQ_PRINT_SENSE, "Warning - High critical temperature limit exceeded") }, /* DTLPWROMAEBKVF */ - { SST(0x0B, 0x0B, SS_RDEF, /* XXX TBD */ + { SST(0x0B, 0x0B, SS_NOP | SSQ_PRINT_SENSE, "Warning - Low critical temperature limit exceeded") }, /* DTLPWROMAEBKVF */ - { SST(0x0B, 0x0C, SS_RDEF, /* XXX TBD */ + { SST(0x0B, 0x0C, SS_NOP | SSQ_PRINT_SENSE, "Warning - High operating temperature limit exceeded") }, /* DTLPWROMAEBKVF */ - { SST(0x0B, 0x0D, SS_RDEF, /* XXX TBD */ + { SST(0x0B, 0x0D, SS_NOP | SSQ_PRINT_SENSE, "Warning - Low operating temperature limit exceeded") }, /* DTLPWROMAEBKVF */ - { SST(0x0B, 0x0E, SS_RDEF, /* XXX TBD */ + { SST(0x0B, 0x0E, SS_NOP | SSQ_PRINT_SENSE, "Warning - High citical humidity limit exceeded") }, /* DTLPWROMAEBKVF */ - { SST(0x0B, 0x0F, SS_RDEF, /* XXX TBD */ + { SST(0x0B, 0x0F, SS_NOP | SSQ_PRINT_SENSE, "Warning - Low citical humidity limit exceeded") }, /* DTLPWROMAEBKVF */ - { SST(0x0B, 0x10, SS_RDEF, /* XXX TBD */ + { SST(0x0B, 0x10, SS_NOP | SSQ_PRINT_SENSE, "Warning - High operating humidity limit exceeded") }, /* DTLPWROMAEBKVF */ - { SST(0x0B, 0x11, SS_RDEF, /* XXX TBD */ + { SST(0x0B, 0x11, SS_NOP | SSQ_PRINT_SENSE, "Warning - Low operating humidity limit exceeded") }, /* T R */ { SST(0x0C, 0x00, SS_RDEF, @@ -2620,253 +2620,259 @@ static struct asc_table_entry asc_table[] = { { SST(0x5C, 0x02, SS_RDEF, "Spindles not synchronized") }, /* DTLPWROMAEBKVF */ - { SST(0x5D, 0x00, SS_RDEF, + { SST(0x5D, 0x00, SS_NOP | SSQ_PRINT_SENSE, "Failure prediction threshold exceeded") }, /* R B */ - { SST(0x5D, 0x01, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x01, SS_NOP | SSQ_PRINT_SENSE, "Media failure prediction threshold exceeded") }, /* R */ - { SST(0x5D, 0x02, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x02, SS_NOP | SSQ_PRINT_SENSE, "Logical unit failure prediction threshold exceeded") }, /* R */ - { SST(0x5D, 0x03, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x03, SS_NOP | SSQ_PRINT_SENSE, "Spare area exhaustion prediction threshold exceeded") }, /* D B */ - { SST(0x5D, 0x10, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x10, SS_NOP | SSQ_PRINT_SENSE, "Hardware impending failure general hard drive failure") }, /* D B */ - { SST(0x5D, 0x11, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x11, SS_NOP | SSQ_PRINT_SENSE, "Hardware impending failure drive error rate too high") }, /* D B */ - { SST(0x5D, 0x12, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x12, SS_NOP | SSQ_PRINT_SENSE, "Hardware impending failure data error rate too high") }, /* D B */ - { SST(0x5D, 0x13, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x13, SS_NOP | SSQ_PRINT_SENSE, "Hardware impending failure seek error rate too high") }, /* D B */ - { SST(0x5D, 0x14, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x14, SS_NOP | SSQ_PRINT_SENSE, "Hardware impending failure too many block reassigns") }, /* D B */ - { SST(0x5D, 0x15, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x15, SS_NOP | SSQ_PRINT_SENSE, "Hardware impending failure access times too high") }, /* D B */ - { SST(0x5D, 0x16, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x16, SS_NOP | SSQ_PRINT_SENSE, "Hardware impending failure start unit times too high") }, /* D B */ - { SST(0x5D, 0x17, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x17, SS_NOP | SSQ_PRINT_SENSE, "Hardware impending failure channel parametrics") }, /* D B */ - { SST(0x5D, 0x18, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x18, SS_NOP | SSQ_PRINT_SENSE, "Hardware impending failure controller detected") }, /* D B */ - { SST(0x5D, 0x19, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x19, SS_NOP | SSQ_PRINT_SENSE, "Hardware impending failure throughput performance") }, /* D B */ - { SST(0x5D, 0x1A, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x1A, SS_NOP | SSQ_PRINT_SENSE, "Hardware impending failure seek time performance") }, /* D B */ - { SST(0x5D, 0x1B, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x1B, SS_NOP | SSQ_PRINT_SENSE, "Hardware impending failure spin-up retry count") }, /* D B */ - { SST(0x5D, 0x1C, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x1C, SS_NOP | SSQ_PRINT_SENSE, "Hardware impending failure drive calibration retry count") }, /* D B */ - { SST(0x5D, 0x20, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x1D, SS_NOP | SSQ_PRINT_SENSE, + "Hardware impending failure power loss protection circuit") }, + /* D B */ + { SST(0x5D, 0x20, SS_NOP | SSQ_PRINT_SENSE, "Controller impending failure general hard drive failure") }, /* D B */ - { SST(0x5D, 0x21, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x21, SS_NOP | SSQ_PRINT_SENSE, "Controller impending failure drive error rate too high") }, /* D B */ - { SST(0x5D, 0x22, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x22, SS_NOP | SSQ_PRINT_SENSE, "Controller impending failure data error rate too high") }, /* D B */ - { SST(0x5D, 0x23, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x23, SS_NOP | SSQ_PRINT_SENSE, "Controller impending failure seek error rate too high") }, /* D B */ - { SST(0x5D, 0x24, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x24, SS_NOP | SSQ_PRINT_SENSE, "Controller impending failure too many block reassigns") }, /* D B */ - { SST(0x5D, 0x25, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x25, SS_NOP | SSQ_PRINT_SENSE, "Controller impending failure access times too high") }, /* D B */ - { SST(0x5D, 0x26, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x26, SS_NOP | SSQ_PRINT_SENSE, "Controller impending failure start unit times too high") }, /* D B */ - { SST(0x5D, 0x27, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x27, SS_NOP | SSQ_PRINT_SENSE, "Controller impending failure channel parametrics") }, /* D B */ - { SST(0x5D, 0x28, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x28, SS_NOP | SSQ_PRINT_SENSE, "Controller impending failure controller detected") }, /* D B */ - { SST(0x5D, 0x29, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x29, SS_NOP | SSQ_PRINT_SENSE, "Controller impending failure throughput performance") }, /* D B */ - { SST(0x5D, 0x2A, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x2A, SS_NOP | SSQ_PRINT_SENSE, "Controller impending failure seek time performance") }, /* D B */ - { SST(0x5D, 0x2B, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x2B, SS_NOP | SSQ_PRINT_SENSE, "Controller impending failure spin-up retry count") }, /* D B */ - { SST(0x5D, 0x2C, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x2C, SS_NOP | SSQ_PRINT_SENSE, "Controller impending failure drive calibration retry count") }, /* D B */ - { SST(0x5D, 0x30, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x30, SS_NOP | SSQ_PRINT_SENSE, "Data channel impending failure general hard drive failure") }, /* D B */ - { SST(0x5D, 0x31, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x31, SS_NOP | SSQ_PRINT_SENSE, "Data channel impending failure drive error rate too high") }, /* D B */ - { SST(0x5D, 0x32, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x32, SS_NOP | SSQ_PRINT_SENSE, "Data channel impending failure data error rate too high") }, /* D B */ - { SST(0x5D, 0x33, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x33, SS_NOP | SSQ_PRINT_SENSE, "Data channel impending failure seek error rate too high") }, /* D B */ - { SST(0x5D, 0x34, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x34, SS_NOP | SSQ_PRINT_SENSE, "Data channel impending failure too many block reassigns") }, /* D B */ - { SST(0x5D, 0x35, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x35, SS_NOP | SSQ_PRINT_SENSE, "Data channel impending failure access times too high") }, /* D B */ - { SST(0x5D, 0x36, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x36, SS_NOP | SSQ_PRINT_SENSE, "Data channel impending failure start unit times too high") }, /* D B */ - { SST(0x5D, 0x37, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x37, SS_NOP | SSQ_PRINT_SENSE, "Data channel impending failure channel parametrics") }, /* D B */ - { SST(0x5D, 0x38, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x38, SS_NOP | SSQ_PRINT_SENSE, "Data channel impending failure controller detected") }, /* D B */ - { SST(0x5D, 0x39, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x39, SS_NOP | SSQ_PRINT_SENSE, "Data channel impending failure throughput performance") }, /* D B */ - { SST(0x5D, 0x3A, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x3A, SS_NOP | SSQ_PRINT_SENSE, "Data channel impending failure seek time performance") }, /* D B */ - { SST(0x5D, 0x3B, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x3B, SS_NOP | SSQ_PRINT_SENSE, "Data channel impending failure spin-up retry count") }, /* D B */ - { SST(0x5D, 0x3C, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x3C, SS_NOP | SSQ_PRINT_SENSE, "Data channel impending failure drive calibration retry count") }, /* D B */ - { SST(0x5D, 0x40, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x40, SS_NOP | SSQ_PRINT_SENSE, "Servo impending failure general hard drive failure") }, /* D B */ - { SST(0x5D, 0x41, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x41, SS_NOP | SSQ_PRINT_SENSE, "Servo impending failure drive error rate too high") }, /* D B */ - { SST(0x5D, 0x42, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x42, SS_NOP | SSQ_PRINT_SENSE, "Servo impending failure data error rate too high") }, /* D B */ - { SST(0x5D, 0x43, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x43, SS_NOP | SSQ_PRINT_SENSE, "Servo impending failure seek error rate too high") }, /* D B */ - { SST(0x5D, 0x44, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x44, SS_NOP | SSQ_PRINT_SENSE, "Servo impending failure too many block reassigns") }, /* D B */ - { SST(0x5D, 0x45, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x45, SS_NOP | SSQ_PRINT_SENSE, "Servo impending failure access times too high") }, /* D B */ - { SST(0x5D, 0x46, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x46, SS_NOP | SSQ_PRINT_SENSE, "Servo impending failure start unit times too high") }, /* D B */ - { SST(0x5D, 0x47, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x47, SS_NOP | SSQ_PRINT_SENSE, "Servo impending failure channel parametrics") }, /* D B */ - { SST(0x5D, 0x48, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x48, SS_NOP | SSQ_PRINT_SENSE, "Servo impending failure controller detected") }, /* D B */ - { SST(0x5D, 0x49, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x49, SS_NOP | SSQ_PRINT_SENSE, "Servo impending failure throughput performance") }, /* D B */ - { SST(0x5D, 0x4A, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x4A, SS_NOP | SSQ_PRINT_SENSE, "Servo impending failure seek time performance") }, /* D B */ - { SST(0x5D, 0x4B, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x4B, SS_NOP | SSQ_PRINT_SENSE, "Servo impending failure spin-up retry count") }, /* D B */ - { SST(0x5D, 0x4C, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x4C, SS_NOP | SSQ_PRINT_SENSE, "Servo impending failure drive calibration retry count") }, /* D B */ - { SST(0x5D, 0x50, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x50, SS_NOP | SSQ_PRINT_SENSE, "Spindle impending failure general hard drive failure") }, /* D B */ - { SST(0x5D, 0x51, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x51, SS_NOP | SSQ_PRINT_SENSE, "Spindle impending failure drive error rate too high") }, /* D B */ - { SST(0x5D, 0x52, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x52, SS_NOP | SSQ_PRINT_SENSE, "Spindle impending failure data error rate too high") }, /* D B */ - { SST(0x5D, 0x53, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x53, SS_NOP | SSQ_PRINT_SENSE, "Spindle impending failure seek error rate too high") }, /* D B */ - { SST(0x5D, 0x54, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x54, SS_NOP | SSQ_PRINT_SENSE, "Spindle impending failure too many block reassigns") }, /* D B */ - { SST(0x5D, 0x55, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x55, SS_NOP | SSQ_PRINT_SENSE, "Spindle impending failure access times too high") }, /* D B */ - { SST(0x5D, 0x56, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x56, SS_NOP | SSQ_PRINT_SENSE, "Spindle impending failure start unit times too high") }, /* D B */ - { SST(0x5D, 0x57, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x57, SS_NOP | SSQ_PRINT_SENSE, "Spindle impending failure channel parametrics") }, /* D B */ - { SST(0x5D, 0x58, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x58, SS_NOP | SSQ_PRINT_SENSE, "Spindle impending failure controller detected") }, /* D B */ - { SST(0x5D, 0x59, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x59, SS_NOP | SSQ_PRINT_SENSE, "Spindle impending failure throughput performance") }, /* D B */ - { SST(0x5D, 0x5A, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x5A, SS_NOP | SSQ_PRINT_SENSE, "Spindle impending failure seek time performance") }, /* D B */ - { SST(0x5D, 0x5B, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x5B, SS_NOP | SSQ_PRINT_SENSE, "Spindle impending failure spin-up retry count") }, /* D B */ - { SST(0x5D, 0x5C, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x5C, SS_NOP | SSQ_PRINT_SENSE, "Spindle impending failure drive calibration retry count") }, /* D B */ - { SST(0x5D, 0x60, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x60, SS_NOP | SSQ_PRINT_SENSE, "Firmware impending failure general hard drive failure") }, /* D B */ - { SST(0x5D, 0x61, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x61, SS_NOP | SSQ_PRINT_SENSE, "Firmware impending failure drive error rate too high") }, /* D B */ - { SST(0x5D, 0x62, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x62, SS_NOP | SSQ_PRINT_SENSE, "Firmware impending failure data error rate too high") }, /* D B */ - { SST(0x5D, 0x63, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x63, SS_NOP | SSQ_PRINT_SENSE, "Firmware impending failure seek error rate too high") }, /* D B */ - { SST(0x5D, 0x64, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x64, SS_NOP | SSQ_PRINT_SENSE, "Firmware impending failure too many block reassigns") }, /* D B */ - { SST(0x5D, 0x65, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x65, SS_NOP | SSQ_PRINT_SENSE, "Firmware impending failure access times too high") }, /* D B */ - { SST(0x5D, 0x66, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x66, SS_NOP | SSQ_PRINT_SENSE, "Firmware impending failure start unit times too high") }, /* D B */ - { SST(0x5D, 0x67, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x67, SS_NOP | SSQ_PRINT_SENSE, "Firmware impending failure channel parametrics") }, /* D B */ - { SST(0x5D, 0x68, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x68, SS_NOP | SSQ_PRINT_SENSE, "Firmware impending failure controller detected") }, /* D B */ - { SST(0x5D, 0x69, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x69, SS_NOP | SSQ_PRINT_SENSE, "Firmware impending failure throughput performance") }, /* D B */ - { SST(0x5D, 0x6A, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x6A, SS_NOP | SSQ_PRINT_SENSE, "Firmware impending failure seek time performance") }, /* D B */ - { SST(0x5D, 0x6B, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x6B, SS_NOP | SSQ_PRINT_SENSE, "Firmware impending failure spin-up retry count") }, /* D B */ - { SST(0x5D, 0x6C, SS_RDEF, /* XXX TBD */ + { SST(0x5D, 0x6C, SS_NOP | SSQ_PRINT_SENSE, "Firmware impending failure drive calibration retry count") }, + /* D B */ + { SST(0x5D, 0x73, SS_NOP | SSQ_PRINT_SENSE, + "Media impending failure endurance limit met") }, /* DTLPWROMAEBKVF */ - { SST(0x5D, 0xFF, SS_RDEF, + { SST(0x5D, 0xFF, SS_NOP | SSQ_PRINT_SENSE, "Failure prediction threshold exceeded (false)") }, /* DTLPWRO A K */ { SST(0x5E, 0x00, SS_RDEF, @@ -3744,335 +3750,300 @@ scsi_find_desc(struct scsi_sense_data_desc *sense, u_int sense_len, #endif /* __rtems__ */ /* - * Fill in SCSI sense data with the specified parameters. This routine can - * fill in either fixed or descriptor type sense data. + * Fill in SCSI descriptor sense data with the specified parameters. */ -void -scsi_set_sense_data_va(struct scsi_sense_data *sense_data, - scsi_sense_data_type sense_format, int current_error, - int sense_key, int asc, int ascq, va_list ap) +static void +scsi_set_sense_data_desc_va(struct scsi_sense_data *sense_data, + u_int *sense_len, scsi_sense_data_type sense_format, int current_error, + int sense_key, int asc, int ascq, va_list ap) { - int descriptor_sense; + struct scsi_sense_data_desc *sense; scsi_sense_elem_type elem_type; + int space, len; + uint8_t *desc, *data; - /* - * Determine whether to return fixed or descriptor format sense - * data. If the user specifies SSD_TYPE_NONE for some reason, - * they'll just get fixed sense data. - */ - if (sense_format == SSD_TYPE_DESC) - descriptor_sense = 1; - else - descriptor_sense = 0; - - /* - * Zero the sense data, so that we don't pass back any garbage data - * to the user. - */ memset(sense_data, 0, sizeof(*sense_data)); + sense = (struct scsi_sense_data_desc *)sense_data; + if (current_error != 0) + sense->error_code = SSD_DESC_CURRENT_ERROR; + else + sense->error_code = SSD_DESC_DEFERRED_ERROR; + sense->sense_key = sense_key; + sense->add_sense_code = asc; + sense->add_sense_code_qual = ascq; + sense->flags = 0; + + desc = &sense->sense_desc[0]; + space = *sense_len - offsetof(struct scsi_sense_data_desc, sense_desc); + while ((elem_type = va_arg(ap, scsi_sense_elem_type)) != + SSD_ELEM_NONE) { + if (elem_type >= SSD_ELEM_MAX) { + printf("%s: invalid sense type %d\n", __func__, + elem_type); + break; + } + len = va_arg(ap, int); + data = va_arg(ap, uint8_t *); - if (descriptor_sense != 0) { - struct scsi_sense_data_desc *sense; - - sense = (struct scsi_sense_data_desc *)sense_data; - /* - * The descriptor sense format eliminates the use of the - * valid bit. - */ - if (current_error != 0) - sense->error_code = SSD_DESC_CURRENT_ERROR; - else - sense->error_code = SSD_DESC_DEFERRED_ERROR; - sense->sense_key = sense_key; - sense->add_sense_code = asc; - sense->add_sense_code_qual = ascq; - /* - * Start off with no extra length, since the above data - * fits in the standard descriptor sense information. - */ - sense->extra_len = 0; - while ((elem_type = (scsi_sense_elem_type)va_arg(ap, - scsi_sense_elem_type)) != SSD_ELEM_NONE) { - int sense_len, len_to_copy; - uint8_t *data; - - if (elem_type >= SSD_ELEM_MAX) { - printf("%s: invalid sense type %d\n", __func__, - elem_type); + switch (elem_type) { + case SSD_ELEM_SKIP: + break; + case SSD_ELEM_DESC: + if (space < len) { + sense->flags |= SSDD_SDAT_OVFL; break; } + bcopy(data, desc, len); + desc += len; + space -= len; + break; + case SSD_ELEM_SKS: { + struct scsi_sense_sks *sks = (void *)desc; - sense_len = (int)va_arg(ap, int); - len_to_copy = MIN(sense_len, SSD_EXTRA_MAX - - sense->extra_len); - data = (uint8_t *)va_arg(ap, uint8_t *); - - /* - * We've already consumed the arguments for this one. - */ - if (elem_type == SSD_ELEM_SKIP) - continue; - - switch (elem_type) { - case SSD_ELEM_DESC: { - - /* - * This is a straight descriptor. All we - * need to do is copy the data in. - */ - bcopy(data, &sense->sense_desc[ - sense->extra_len], len_to_copy); - sense->extra_len += len_to_copy; + if (len > sizeof(sks->sense_key_spec)) + break; + if (space < sizeof(*sks)) { + sense->flags |= SSDD_SDAT_OVFL; break; } - case SSD_ELEM_SKS: { - struct scsi_sense_sks sks; - - bzero(&sks, sizeof(sks)); + sks->desc_type = SSD_DESC_SKS; + sks->length = sizeof(*sks) - + (offsetof(struct scsi_sense_sks, length) + 1); + bcopy(data, &sks->sense_key_spec, len); + desc += sizeof(*sks); + space -= sizeof(*sks); + break; + } + case SSD_ELEM_COMMAND: { + struct scsi_sense_command *cmd = (void *)desc; - /* - * This is already-formatted sense key - * specific data. We just need to fill out - * the header and copy everything in. - */ - bcopy(data, &sks.sense_key_spec, - MIN(len_to_copy, - sizeof(sks.sense_key_spec))); - - sks.desc_type = SSD_DESC_SKS; - sks.length = sizeof(sks) - - offsetof(struct scsi_sense_sks, reserved1); - bcopy(&sks,&sense->sense_desc[sense->extra_len], - sizeof(sks)); - sense->extra_len += sizeof(sks); + if (len > sizeof(cmd->command_info)) + break; + if (space < sizeof(*cmd)) { + sense->flags |= SSDD_SDAT_OVFL; break; } - case SSD_ELEM_INFO: - case SSD_ELEM_COMMAND: { - struct scsi_sense_command cmd; - struct scsi_sense_info info; - uint8_t *data_dest; - uint8_t *descriptor; - int descriptor_size, i, copy_len; - - bzero(&cmd, sizeof(cmd)); - bzero(&info, sizeof(info)); - - /* - * Command or information data. The - * operate in pretty much the same way. - */ - if (elem_type == SSD_ELEM_COMMAND) { - len_to_copy = MIN(len_to_copy, - sizeof(cmd.command_info)); - descriptor = (uint8_t *)&cmd; - descriptor_size = sizeof(cmd); - data_dest =(uint8_t *)&cmd.command_info; - cmd.desc_type = SSD_DESC_COMMAND; - cmd.length = sizeof(cmd) - - offsetof(struct scsi_sense_command, - reserved); - } else { - len_to_copy = MIN(len_to_copy, - sizeof(info.info)); - descriptor = (uint8_t *)&info; - descriptor_size = sizeof(cmd); - data_dest = (uint8_t *)&info.info; - info.desc_type = SSD_DESC_INFO; - info.byte2 = SSD_INFO_VALID; - info.length = sizeof(info) - - offsetof(struct scsi_sense_info, - byte2); - } - - /* - * Copy this in reverse because the spec - * (SPC-4) says that when 4 byte quantities - * are stored in this 8 byte field, the - * first four bytes shall be 0. - * - * So we fill the bytes in from the end, and - * if we have less than 8 bytes to copy, - * the initial, most significant bytes will - * be 0. - */ - for (i = sense_len - 1; i >= 0 && - len_to_copy > 0; i--, len_to_copy--) - data_dest[len_to_copy - 1] = data[i]; + cmd->desc_type = SSD_DESC_COMMAND; + cmd->length = sizeof(*cmd) - + (offsetof(struct scsi_sense_command, length) + 1); + bcopy(data, &cmd->command_info[ + sizeof(cmd->command_info) - len], len); + desc += sizeof(*cmd); + space -= sizeof(*cmd); + break; + } + case SSD_ELEM_INFO: { + struct scsi_sense_info *info = (void *)desc; - /* - * This calculation looks much like the - * initial len_to_copy calculation, but - * we have to do it again here, because - * we're looking at a larger amount that - * may or may not fit. It's not only the - * data the user passed in, but also the - * rest of the descriptor. - */ - copy_len = MIN(descriptor_size, - SSD_EXTRA_MAX - sense->extra_len); - bcopy(descriptor, &sense->sense_desc[ - sense->extra_len], copy_len); - sense->extra_len += copy_len; + if (len > sizeof(info->info)) break; - } - case SSD_ELEM_FRU: { - struct scsi_sense_fru fru; - int copy_len; - - bzero(&fru, sizeof(fru)); - - fru.desc_type = SSD_DESC_FRU; - fru.length = sizeof(fru) - - offsetof(struct scsi_sense_fru, reserved); - fru.fru = *data; - - copy_len = MIN(sizeof(fru), SSD_EXTRA_MAX - - sense->extra_len); - bcopy(&fru, &sense->sense_desc[ - sense->extra_len], copy_len); - sense->extra_len += copy_len; + if (space < sizeof(*info)) { + sense->flags |= SSDD_SDAT_OVFL; break; } - case SSD_ELEM_STREAM: { - struct scsi_sense_stream stream_sense; - int copy_len; - - bzero(&stream_sense, sizeof(stream_sense)); - stream_sense.desc_type = SSD_DESC_STREAM; - stream_sense.length = sizeof(stream_sense) - - offsetof(struct scsi_sense_stream, reserved); - stream_sense.byte3 = *data; - - copy_len = MIN(sizeof(stream_sense), - SSD_EXTRA_MAX - sense->extra_len); - bcopy(&stream_sense, &sense->sense_desc[ - sense->extra_len], copy_len); - sense->extra_len += copy_len; + info->desc_type = SSD_DESC_INFO; + info->length = sizeof(*info) - + (offsetof(struct scsi_sense_info, length) + 1); + info->byte2 = SSD_INFO_VALID; + bcopy(data, &info->info[sizeof(info->info) - len], len); + desc += sizeof(*info); + space -= sizeof(*info); + break; + } + case SSD_ELEM_FRU: { + struct scsi_sense_fru *fru = (void *)desc; + + if (len > sizeof(fru->fru)) break; - } - default: - /* - * We shouldn't get here, but if we do, do - * nothing. We've already consumed the - * arguments above. - */ + if (space < sizeof(*fru)) { + sense->flags |= SSDD_SDAT_OVFL; break; } + fru->desc_type = SSD_DESC_FRU; + fru->length = sizeof(*fru) - + (offsetof(struct scsi_sense_fru, length) + 1); + fru->fru = *data; + desc += sizeof(*fru); + space -= sizeof(*fru); + break; } - } else { - struct scsi_sense_data_fixed *sense; - - sense = (struct scsi_sense_data_fixed *)sense_data; - - if (current_error != 0) - sense->error_code = SSD_CURRENT_ERROR; - else - sense->error_code = SSD_DEFERRED_ERROR; + case SSD_ELEM_STREAM: { + struct scsi_sense_stream *stream = (void *)desc; - sense->flags = sense_key; - sense->add_sense_code = asc; - sense->add_sense_code_qual = ascq; - /* - * We've set the ASC and ASCQ, so we have 6 more bytes of - * valid data. If we wind up setting any of the other - * fields, we'll bump this to 10 extra bytes. - */ - sense->extra_len = 6; - - while ((elem_type = (scsi_sense_elem_type)va_arg(ap, - scsi_sense_elem_type)) != SSD_ELEM_NONE) { - int sense_len, len_to_copy; - uint8_t *data; - - if (elem_type >= SSD_ELEM_MAX) { - printf("%s: invalid sense type %d\n", __func__, - elem_type); + if (len > sizeof(stream->byte3)) + break; + if (space < sizeof(*stream)) { + sense->flags |= SSDD_SDAT_OVFL; break; } + stream->desc_type = SSD_DESC_STREAM; + stream->length = sizeof(*stream) - + (offsetof(struct scsi_sense_stream, length) + 1); + stream->byte3 = *data; + desc += sizeof(*stream); + space -= sizeof(*stream); + break; + } + default: /* - * If we get in here, just bump the extra length to - * 10 bytes. That will encompass anything we're - * going to set here. + * We shouldn't get here, but if we do, do nothing. + * We've already consumed the arguments above. */ - sense->extra_len = 10; - sense_len = (int)va_arg(ap, int); - data = (uint8_t *)va_arg(ap, uint8_t *); + break; + } + } + sense->extra_len = desc - &sense->sense_desc[0]; + *sense_len = offsetof(struct scsi_sense_data_desc, extra_len) + 1 + + sense->extra_len; +} - switch (elem_type) { - case SSD_ELEM_SKS: - /* - * The user passed in pre-formatted sense - * key specific data. - */ - bcopy(data, &sense->sense_key_spec[0], - MIN(sizeof(sense->sense_key_spec), - sense_len)); - break; - case SSD_ELEM_INFO: - case SSD_ELEM_COMMAND: { - uint8_t *data_dest; - int i; - - if (elem_type == SSD_ELEM_COMMAND) { - data_dest = &sense->cmd_spec_info[0]; - len_to_copy = MIN(sense_len, - sizeof(sense->cmd_spec_info)); - } else { - data_dest = &sense->info[0]; - len_to_copy = MIN(sense_len, - sizeof(sense->info)); - /* - * We're setting the info field, so - * set the valid bit. - */ - sense->error_code |= SSD_ERRCODE_VALID; - } +/* + * Fill in SCSI fixed sense data with the specified parameters. + */ +static void +scsi_set_sense_data_fixed_va(struct scsi_sense_data *sense_data, + u_int *sense_len, scsi_sense_data_type sense_format, int current_error, + int sense_key, int asc, int ascq, va_list ap) +{ + struct scsi_sense_data_fixed *sense; + scsi_sense_elem_type elem_type; + uint8_t *data; + int len; - /* - * Copy this in reverse so that if we have - * less than 4 bytes to fill, the least - * significant bytes will be at the end. - * If we have more than 4 bytes, only the - * least significant bytes will be included. - */ - for (i = sense_len - 1; i >= 0 && - len_to_copy > 0; i--, len_to_copy--) - data_dest[len_to_copy - 1] = data[i]; + memset(sense_data, 0, sizeof(*sense_data)); + sense = (struct scsi_sense_data_fixed *)sense_data; + if (current_error != 0) + sense->error_code = SSD_CURRENT_ERROR; + else + sense->error_code = SSD_DEFERRED_ERROR; + sense->flags = sense_key & SSD_KEY; + sense->extra_len = 0; + if (*sense_len >= 13) { + sense->add_sense_code = asc; + sense->extra_len = MAX(sense->extra_len, 5); + } else + sense->flags |= SSD_SDAT_OVFL; + if (*sense_len >= 14) { + sense->add_sense_code_qual = ascq; + sense->extra_len = MAX(sense->extra_len, 6); + } else + sense->flags |= SSD_SDAT_OVFL; + + while ((elem_type = va_arg(ap, scsi_sense_elem_type)) != + SSD_ELEM_NONE) { + if (elem_type >= SSD_ELEM_MAX) { + printf("%s: invalid sense type %d\n", __func__, + elem_type); + break; + } + len = va_arg(ap, int); + data = va_arg(ap, uint8_t *); + switch (elem_type) { + case SSD_ELEM_SKIP: + break; + case SSD_ELEM_SKS: + if (len > sizeof(sense->sense_key_spec)) break; - } - case SSD_ELEM_FRU: - sense->fru = *data; + if (*sense_len < 18) { + sense->flags |= SSD_SDAT_OVFL; break; - case SSD_ELEM_STREAM: - sense->flags |= *data; + } + bcopy(data, &sense->sense_key_spec[0], len); + sense->extra_len = MAX(sense->extra_len, 10); + break; + case SSD_ELEM_COMMAND: + if (*sense_len < 12) { + sense->flags |= SSD_SDAT_OVFL; break; - case SSD_ELEM_DESC: - default: - - /* - * If the user passes in descriptor sense, - * we can't handle that in fixed format. - * So just skip it, and any unknown argument - * types. - */ + } + if (len > sizeof(sense->cmd_spec_info)) { + data += len - sizeof(sense->cmd_spec_info); + len -= len - sizeof(sense->cmd_spec_info); + } + bcopy(data, &sense->cmd_spec_info[ + sizeof(sense->cmd_spec_info) - len], len); + sense->extra_len = MAX(sense->extra_len, 4); + break; + case SSD_ELEM_INFO: + /* Set VALID bit only if no overflow. */ + sense->error_code |= SSD_ERRCODE_VALID; + while (len > sizeof(sense->info)) { + if (data[0] != 0) + sense->error_code &= ~SSD_ERRCODE_VALID; + data ++; + len --; + } + bcopy(data, &sense->info[sizeof(sense->info) - len], len); + break; + case SSD_ELEM_FRU: + if (*sense_len < 15) { + sense->flags |= SSD_SDAT_OVFL; break; } + sense->fru = *data; + sense->extra_len = MAX(sense->extra_len, 7); + break; + case SSD_ELEM_STREAM: + sense->flags |= *data & + (SSD_ILI | SSD_EOM | SSD_FILEMARK); + break; + default: + + /* + * We can't handle that in fixed format. Skip it. + */ + break; } } + *sense_len = offsetof(struct scsi_sense_data_fixed, extra_len) + 1 + + sense->extra_len; +} + +/* + * Fill in SCSI sense data with the specified parameters. This routine can + * fill in either fixed or descriptor type sense data. + */ +void +scsi_set_sense_data_va(struct scsi_sense_data *sense_data, u_int *sense_len, + scsi_sense_data_type sense_format, int current_error, + int sense_key, int asc, int ascq, va_list ap) +{ + + if (*sense_len > SSD_FULL_SIZE) + *sense_len = SSD_FULL_SIZE; + if (sense_format == SSD_TYPE_DESC) + scsi_set_sense_data_desc_va(sense_data, sense_len, + sense_format, current_error, sense_key, asc, ascq, ap); + else + scsi_set_sense_data_fixed_va(sense_data, sense_len, + sense_format, current_error, sense_key, asc, ascq, ap); +} + +void +scsi_set_sense_data(struct scsi_sense_data *sense_data, + scsi_sense_data_type sense_format, int current_error, + int sense_key, int asc, int ascq, ...) +{ + va_list ap; + u_int sense_len = SSD_FULL_SIZE; + + va_start(ap, ascq); + scsi_set_sense_data_va(sense_data, &sense_len, sense_format, + current_error, sense_key, asc, ascq, ap); + va_end(ap); } void -scsi_set_sense_data(struct scsi_sense_data *sense_data, +scsi_set_sense_data_len(struct scsi_sense_data *sense_data, u_int *sense_len, scsi_sense_data_type sense_format, int current_error, - int sense_key, int asc, int ascq, ...) + int sense_key, int asc, int ascq, ...) { va_list ap; va_start(ap, ascq); - scsi_set_sense_data_va(sense_data, sense_format, current_error, - sense_key, asc, ascq, ap); + scsi_set_sense_data_va(sense_data, sense_len, sense_format, + current_error, sense_key, asc, ascq, ap); va_end(ap); } @@ -4708,6 +4679,26 @@ scsi_sense_ata_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, sbuf_printf(sb, "device: %02x, ", res->device); } +void +scsi_sense_forwarded_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, + u_int sense_len, uint8_t *cdb, int cdb_len, + struct scsi_inquiry_data *inq_data, + struct scsi_sense_desc_header *header) +{ + struct scsi_sense_forwarded *forwarded; + const char *sense_key_desc; + const char *asc_desc; + int error_code, sense_key, asc, ascq; + + forwarded = (struct scsi_sense_forwarded *)header; + scsi_extract_sense_len((struct scsi_sense_data *)forwarded->sense_data, + forwarded->length - 2, &error_code, &sense_key, &asc, &ascq, 1); + scsi_sense_desc(sense_key, asc, ascq, NULL, &sense_key_desc, &asc_desc); + + sbuf_printf(sb, "Forwarded sense: %s asc:%x,%x (%s): ", + sense_key_desc, asc, ascq, asc_desc); +} + /* * Generic sense descriptor printing routine. This is used when we have * not yet implemented a specific printing routine for this descriptor. @@ -4755,7 +4746,8 @@ struct scsi_sense_desc_printer { {SSD_DESC_STREAM, scsi_sense_stream_sbuf}, {SSD_DESC_BLOCK, scsi_sense_block_sbuf}, {SSD_DESC_ATA, scsi_sense_ata_sbuf}, - {SSD_DESC_PROGRESS, scsi_sense_progress_sbuf} + {SSD_DESC_PROGRESS, scsi_sense_progress_sbuf}, + {SSD_DESC_FORWARDED, scsi_sense_forwarded_sbuf} }; void @@ -5693,6 +5685,32 @@ scsi_devid_is_lun_name(uint8_t *bufp) } int +scsi_devid_is_lun_md5(uint8_t *bufp) +{ + struct scsi_vpd_id_descriptor *descr; + + descr = (struct scsi_vpd_id_descriptor *)bufp; + if ((descr->id_type & SVPD_ID_ASSOC_MASK) != SVPD_ID_ASSOC_LUN) + return 0; + if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_MD5_LUN_ID) + return 0; + return 1; +} + +int +scsi_devid_is_lun_uuid(uint8_t *bufp) +{ + struct scsi_vpd_id_descriptor *descr; + + descr = (struct scsi_vpd_id_descriptor *)bufp; + if ((descr->id_type & SVPD_ID_ASSOC_MASK) != SVPD_ID_ASSOC_LUN) + return 0; + if ((descr->id_type & SVPD_ID_TYPE_MASK) != SVPD_ID_TYPE_UUID) + return 0; + return 1; +} + +int scsi_devid_is_port_naa(uint8_t *bufp) { struct scsi_vpd_id_descriptor *descr; @@ -7618,24 +7636,34 @@ scsi_inquiry(struct ccb_scsiio *csio, u_int32_t retries, } void -scsi_mode_sense(struct ccb_scsiio *csio, u_int32_t retries, - void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, int dbd, u_int8_t page_code, - u_int8_t page, u_int8_t *param_buf, u_int32_t param_len, - u_int8_t sense_len, u_int32_t timeout) +scsi_mode_sense(struct ccb_scsiio *csio, uint32_t retries, + void (*cbfcnp)(struct cam_periph *, union ccb *), uint8_t tag_action, + int dbd, uint8_t pc, uint8_t page, uint8_t *param_buf, uint32_t param_len, + uint8_t sense_len, uint32_t timeout) { - scsi_mode_sense_len(csio, retries, cbfcnp, tag_action, dbd, - page_code, page, param_buf, param_len, 0, - sense_len, timeout); + scsi_mode_sense_subpage(csio, retries, cbfcnp, tag_action, dbd, + pc, page, 0, param_buf, param_len, 0, sense_len, timeout); } void -scsi_mode_sense_len(struct ccb_scsiio *csio, u_int32_t retries, - void (*cbfcnp)(struct cam_periph *, union ccb *), - u_int8_t tag_action, int dbd, u_int8_t page_code, - u_int8_t page, u_int8_t *param_buf, u_int32_t param_len, - int minimum_cmd_size, u_int8_t sense_len, u_int32_t timeout) +scsi_mode_sense_len(struct ccb_scsiio *csio, uint32_t retries, + void (*cbfcnp)(struct cam_periph *, union ccb *), uint8_t tag_action, + int dbd, uint8_t pc, uint8_t page, uint8_t *param_buf, uint32_t param_len, + int minimum_cmd_size, uint8_t sense_len, uint32_t timeout) +{ + + scsi_mode_sense_subpage(csio, retries, cbfcnp, tag_action, dbd, + pc, page, 0, param_buf, param_len, minimum_cmd_size, + sense_len, timeout); +} + +void +scsi_mode_sense_subpage(struct ccb_scsiio *csio, uint32_t retries, + void (*cbfcnp)(struct cam_periph *, union ccb *), uint8_t tag_action, + int dbd, uint8_t pc, uint8_t page, uint8_t subpage, uint8_t *param_buf, + uint32_t param_len, int minimum_cmd_size, uint8_t sense_len, + uint32_t timeout) { u_int8_t cdb_len; @@ -7654,7 +7682,8 @@ scsi_mode_sense_len(struct ccb_scsiio *csio, u_int32_t retries, scsi_cmd->opcode = MODE_SENSE_6; if (dbd != 0) scsi_cmd->byte2 |= SMS_DBD; - scsi_cmd->page = page_code | page; + scsi_cmd->page = pc | page; + scsi_cmd->subpage = subpage; scsi_cmd->length = param_len; cdb_len = sizeof(*scsi_cmd); } else { @@ -7668,7 +7697,8 @@ scsi_mode_sense_len(struct ccb_scsiio *csio, u_int32_t retries, scsi_cmd->opcode = MODE_SENSE_10; if (dbd != 0) scsi_cmd->byte2 |= SMS_DBD; - scsi_cmd->page = page_code | page; + scsi_cmd->page = pc | page; + scsi_cmd->subpage = subpage; scsi_ulto2b(param_len, scsi_cmd->length); cdb_len = sizeof(*scsi_cmd); } diff --git a/freebsd/sys/cam/scsi/scsi_all.h b/freebsd/sys/cam/scsi/scsi_all.h index 9c1376cf..64c45fb2 100644 --- a/freebsd/sys/cam/scsi/scsi_all.h +++ b/freebsd/sys/cam/scsi/scsi_all.h @@ -228,6 +228,7 @@ struct scsi_mode_select_6 u_int8_t opcode; u_int8_t byte2; #define SMS_SP 0x01 +#define SMS_RTD 0x02 #define SMS_PF 0x10 u_int8_t unused[2]; u_int8_t length; @@ -662,6 +663,14 @@ struct scsi_log_fua_stat_and_perf { uint8_t fuanv_write_int[8]; }; +struct scsi_log_informational_exceptions { + struct scsi_log_param_header hdr; +#define SLP_IE_GEN 0x0000 + uint8_t ie_asc; + uint8_t ie_ascq; + uint8_t temperature; +}; + struct scsi_control_page { u_int8_t page_code; u_int8_t page_length; @@ -765,21 +774,6 @@ struct scsi_caching_page { uint8_t non_cache_seg_size[3]; }; -/* - * XXX KDM move this off to a vendor shim. - */ -struct copan_debugconf_subpage { - uint8_t page_code; -#define DBGCNF_PAGE_CODE 0x00 - uint8_t subpage; -#define DBGCNF_SUBPAGE_CODE 0xF0 - uint8_t page_length[2]; - uint8_t page_version; -#define DBGCNF_VERSION 0x00 - uint8_t ctl_time_io_secs[2]; -}; - - struct scsi_info_exceptions_page { u_int8_t page_code; #define SIEP_PAGE_SAVABLE 0x80 /* Page is savable */ @@ -793,6 +787,12 @@ struct scsi_info_exceptions_page { #define SIEP_FLAGS_EBACKERR 0x02 #define SIEP_FLAGS_LOGERR 0x01 u_int8_t mrie; +#define SIEP_MRIE_NO 0x00 +#define SIEP_MRIE_UA 0x02 +#define SIEP_MRIE_REC_COND 0x03 +#define SIEP_MRIE_REC_UNCOND 0x04 +#define SIEP_MRIE_NO_SENSE 0x05 +#define SIEP_MRIE_ON_REQ 0x06 u_int8_t interval_timer[4]; u_int8_t report_count[4]; }; @@ -1457,6 +1457,7 @@ struct scsi_report_supported_opcodes #define RSO_OPTIONS_ALL 0x00 #define RSO_OPTIONS_OC 0x01 #define RSO_OPTIONS_OC_SA 0x02 +#define RSO_OPTIONS_OC_ASA 0x03 uint8_t requested_opcode; uint8_t requested_service_action[2]; uint8_t length[4]; @@ -1482,6 +1483,10 @@ struct scsi_report_supported_opcodes_descr uint8_t flags; #define RSO_SERVACTV 0x01 #define RSO_CTDP 0x02 +#define RSO_CDLP_MASK 0x0c +#define RSO_CDLP_NO 0x00 +#define RSO_CDLP_A 0x04 +#define RSO_CDLP_B 0x08 uint8_t cdb_length[2]; struct scsi_report_supported_opcodes_timeout timeout[0]; }; @@ -1497,6 +1502,10 @@ struct scsi_report_supported_opcodes_one uint8_t reserved; uint8_t support; #define RSO_ONE_CTDP 0x80 +#define RSO_ONE_CDLP_MASK 0x18 +#define RSO_ONE_CDLP_NO 0x00 +#define RSO_ONE_CDLP_A 0x08 +#define RSO_ONE_CDLP_B 0x10 #define RSO_ONE_SUP_MASK 0x07 #define RSO_ONE_SUP_UNAVAIL 0x00 #define RSO_ONE_SUP_NOT_SUP 0x01 @@ -1510,7 +1519,9 @@ struct scsi_report_supported_tmf { uint8_t opcode; uint8_t service_action; - uint8_t reserved[4]; + uint8_t options; +#define RST_REPD 0x80 + uint8_t reserved[3]; uint8_t length[4]; uint8_t reserved1; uint8_t control; @@ -1531,7 +1542,34 @@ struct scsi_report_supported_tmf_data #define RST_ITNRS 0x01 #define RST_QTSS 0x02 #define RST_QAES 0x04 - uint8_t reserved[2]; + uint8_t reserved; + uint8_t length; +}; + +struct scsi_report_supported_tmf_ext_data +{ + uint8_t byte1; + uint8_t byte2; + uint8_t reserved; + uint8_t length; + uint8_t byte5; +#define RST_TMFTMOV 0x01 + uint8_t reserved2; + uint8_t byte7; +#define RST_WAKETS 0x01 +#define RST_TRTS 0x02 +#define RST_QTTS 0x04 +#define RST_LURTS 0x08 +#define RST_CTSTS 0x10 +#define RST_CACATS 0x20 +#define RST_ATSTS 0x40 +#define RST_ATTS 0x80 + uint8_t byte8; +#define RST_ITNRTS 0x01 +#define RST_QTSTS 0x02 +#define RST_QAETS 0x04 + uint8_t long_timeout[4]; + uint8_t short_timeout[4]; }; struct scsi_report_timestamp @@ -2157,6 +2195,7 @@ struct scsi_inquiry_data #define SCSI_REV_SPC2 4 #define SCSI_REV_SPC3 5 #define SCSI_REV_SPC4 6 +#define SCSI_REV_SPC5 7 #define SID_ECMA 0x38 #define SID_ISO 0xC0 @@ -2477,10 +2516,17 @@ struct scsi_vpd_extended_inquiry_data #define SVPD_EID_NV_SUP 0x02 #define SVPD_EID_V_SUP 0x01 uint8_t flags4; +#define SVPD_EID_NO_PI_CHK 0x20 #define SVPD_EID_P_I_I_SUP 0x10 -#define SVPD_EID_LUICLT 0x01 +#define SVPD_EID_LUICLR 0x01 uint8_t flags5; +#define SVPD_EID_LUCT_MASK 0xe0 +#define SVPD_EID_LUCT_NOT_REP 0x00 +#define SVPD_EID_LUCT_CONGL 0x20 +#define SVPD_EID_LUCT_GROUP 0x40 #define SVPD_EID_R_SUP 0x10 +#define SVPD_EID_RTD_SUP 0x08 +#define SVPD_EID_HSSRELEF 0x02 #define SVPD_EID_CBCS 0x01 uint8_t flags6; #define SVPD_EID_MULTI_I_T_FW 0x0F @@ -2491,10 +2537,16 @@ struct scsi_vpd_extended_inquiry_data uint8_t est[2]; uint8_t flags7; #define SVPD_EID_POA_SUP 0x80 -#define SVPD_EID_HRA_SUP 0x80 -#define SVPD_EID_VSA_SUP 0x80 +#define SVPD_EID_HRA_SUP 0x40 +#define SVPD_EID_VSA_SUP 0x20 uint8_t max_sense_length; - uint8_t reserved2[50]; + uint8_t bind_flags; +#define SVPD_EID_IBS 0x80 +#define SVPD_EID_IAS 0x40 +#define SVPD_EID_SAC 0x04 +#define SVPD_EID_NRD1 0x02 +#define SVPD_EID_NRD0 0x01 + uint8_t reserved2[49]; }; struct scsi_vpd_mode_page_policy_descr @@ -3145,11 +3197,12 @@ struct scsi_sense_data_fixed #define SSD_KEY_BLANK_CHECK 0x08 #define SSD_KEY_Vendor_Specific 0x09 #define SSD_KEY_COPY_ABORTED 0x0a -#define SSD_KEY_ABORTED_COMMAND 0x0b +#define SSD_KEY_ABORTED_COMMAND 0x0b #define SSD_KEY_EQUAL 0x0c #define SSD_KEY_VOLUME_OVERFLOW 0x0d #define SSD_KEY_MISCOMPARE 0x0e -#define SSD_KEY_COMPLETED 0x0f +#define SSD_KEY_COMPLETED 0x0f +#define SSD_SDAT_OVFL 0x10 #define SSD_ILI 0x20 #define SSD_EOM 0x40 #define SSD_FILEMARK 0x80 @@ -3187,7 +3240,9 @@ struct scsi_sense_data_desc uint8_t sense_key; uint8_t add_sense_code; uint8_t add_sense_code_qual; - uint8_t reserved[3]; + uint8_t flags; +#define SSDD_SDAT_OVFL 0x80 + uint8_t reserved[2]; /* * Note that SPC-4, section 4.5.2.1 says that the extra_len field * must be less than or equal to 244. @@ -3481,6 +3536,8 @@ struct scsi_sense_forwarded #define SSD_FORWARDED_SDS_UNK 0x00 #define SSD_FORWARDED_SDS_EXSRC 0x01 #define SSD_FORWARDED_SDS_EXDST 0x02 + uint8_t status; + uint8_t sense_data[]; }; /* @@ -3653,13 +3710,15 @@ void scsi_desc_iterate(struct scsi_sense_data_desc *sense, u_int sense_len, void *), void *arg); uint8_t *scsi_find_desc(struct scsi_sense_data_desc *sense, u_int sense_len, uint8_t desc_type); -void scsi_set_sense_data(struct scsi_sense_data *sense_data, +void scsi_set_sense_data(struct scsi_sense_data *sense_data, scsi_sense_data_type sense_format, int current_error, int sense_key, int asc, int ascq, ...) ; +void scsi_set_sense_data_len(struct scsi_sense_data *sense_data, + u_int *sense_len, scsi_sense_data_type sense_format, int current_error, + int sense_key, int asc, int ascq, ...) ; void scsi_set_sense_data_va(struct scsi_sense_data *sense_data, - scsi_sense_data_type sense_format, - int current_error, int sense_key, int asc, - int ascq, va_list ap); + u_int *sense_len, scsi_sense_data_type sense_format, + int current_error, int sense_key, int asc, int ascq, va_list ap); int scsi_get_sense_info(struct scsi_sense_data *sense_data, u_int sense_len, uint8_t info_type, uint64_t *info, int64_t *signed_info); @@ -3713,6 +3772,10 @@ void scsi_sense_ata_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, u_int sense_len, uint8_t *cdb, int cdb_len, struct scsi_inquiry_data *inq_data, struct scsi_sense_desc_header *header); +void scsi_sense_forwarded_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, + u_int sense_len, uint8_t *cdb, int cdb_len, + struct scsi_inquiry_data *inq_data, + struct scsi_sense_desc_header *header); void scsi_sense_generic_sbuf(struct sbuf *sb, struct scsi_sense_data *sense, u_int sense_len, uint8_t *cdb, int cdb_len, struct scsi_inquiry_data *inq_data, @@ -3769,6 +3832,8 @@ int scsi_devid_is_lun_eui64(uint8_t *bufp); int scsi_devid_is_lun_naa(uint8_t *bufp); int scsi_devid_is_lun_name(uint8_t *bufp); int scsi_devid_is_lun_t10(uint8_t *bufp); +int scsi_devid_is_lun_md5(uint8_t *bufp); +int scsi_devid_is_lun_uuid(uint8_t *bufp); int scsi_devid_is_port_naa(uint8_t *bufp); struct scsi_vpd_id_descriptor * scsi_get_devid(struct scsi_vpd_device_id *id, uint32_t len, @@ -3912,21 +3977,24 @@ void scsi_inquiry(struct ccb_scsiio *csio, u_int32_t retries, u_int8_t sense_len, u_int32_t timeout); void scsi_mode_sense(struct ccb_scsiio *csio, u_int32_t retries, - void (*cbfcnp)(struct cam_periph *, - union ccb *), - u_int8_t tag_action, int dbd, - u_int8_t page_code, u_int8_t page, - u_int8_t *param_buf, u_int32_t param_len, - u_int8_t sense_len, u_int32_t timeout); + void (*cbfcnp)(struct cam_periph *, union ccb *), + uint8_t tag_action, int dbd, uint8_t pc, uint8_t page, + uint8_t *param_buf, uint32_t param_len, + uint8_t sense_len, uint32_t timeout); void scsi_mode_sense_len(struct ccb_scsiio *csio, u_int32_t retries, - void (*cbfcnp)(struct cam_periph *, - union ccb *), - u_int8_t tag_action, int dbd, - u_int8_t page_code, u_int8_t page, - u_int8_t *param_buf, u_int32_t param_len, - int minimum_cmd_size, u_int8_t sense_len, - u_int32_t timeout); + void (*cbfcnp)(struct cam_periph *, union ccb *), + uint8_t tag_action, int dbd, uint8_t pc, uint8_t page, + uint8_t *param_buf, uint32_t param_len, + int minimum_cmd_size, uint8_t sense_len, uint32_t timeout); + +void scsi_mode_sense_subpage(struct ccb_scsiio *csio, + uint32_t retries, + void (*cbfcnp)(struct cam_periph *, union ccb *), + uint8_t tag_action, int dbd, uint8_t pc, + uint8_t page, uint8_t subpage, + uint8_t *param_buf, uint32_t param_len, + int minimum_cmd_size, uint8_t sense_len, uint32_t timeout); void scsi_mode_select(struct ccb_scsiio *csio, u_int32_t retries, void (*cbfcnp)(struct cam_periph *, diff --git a/freebsd/sys/cam/scsi/scsi_da.h b/freebsd/sys/cam/scsi/scsi_da.h index e6eb95f1..a679114d 100644 --- a/freebsd/sys/cam/scsi/scsi_da.h +++ b/freebsd/sys/cam/scsi/scsi_da.h @@ -634,6 +634,20 @@ struct scsi_da_rw_recovery_page { u_int8_t recovery_time_limit[2]; }; +struct scsi_da_verify_recovery_page { + u_int8_t page_code; +#define SMS_VERIFY_ERROR_RECOVERY_PAGE 0x07 + u_int8_t page_length; + u_int8_t byte3; +#define SMS_VER_EER 0x08 +#define SMS_VER_PER 0x04 +#define SMS_VER_DTE 0x02 +#define SMS_VER_DCR 0x01 + u_int8_t read_retry_count; + u_int8_t reserved[6]; + u_int8_t recovery_time_limit[2]; +}; + __BEGIN_DECLS /* * XXX These are only left out of the kernel build to silence warnings. If, diff --git a/freebsd/sys/dev/mmc/mmc.c b/freebsd/sys/dev/mmc/mmc.c index d3c9fcb2..a3232248 100644 --- a/freebsd/sys/dev/mmc/mmc.c +++ b/freebsd/sys/dev/mmc/mmc.c @@ -403,7 +403,7 @@ mmc_wait_for_req(struct mmc_softc *sc, struct mmc_request *req) msleep(req, &sc->sc_mtx, 0, "mmcreq", 0); MMC_UNLOCK(sc); if (mmc_debug > 2 || (mmc_debug > 0 && req->cmd->error != MMC_ERR_NONE)) - device_printf(sc->dev, "CMD%d RESULT: %d\n", + device_printf(sc->dev, "CMD%d RESULT: %d\n", req->cmd->opcode, req->cmd->error); return (0); } @@ -513,7 +513,7 @@ mmc_idle_cards(struct mmc_softc *sc) { device_t dev; struct mmc_command cmd; - + dev = sc->dev; mmcbr_set_chip_select(dev, cs_high); mmcbr_update_ios(dev); @@ -797,7 +797,7 @@ mmc_test_bus_width(struct mmc_softc *sc) data.len = 8; data.flags = MMC_DATA_WRITE; mmc_wait_for_cmd(sc, &cmd, 0); - + memset(&cmd, 0, sizeof(cmd)); memset(&data, 0, sizeof(data)); cmd.opcode = MMC_BUSTEST_R; @@ -810,7 +810,7 @@ mmc_test_bus_width(struct mmc_softc *sc) data.flags = MMC_DATA_READ; err = mmc_wait_for_cmd(sc, &cmd, 0); sc->squelched--; - + mmcbr_set_bus_width(sc->dev, bus_width_1); mmcbr_update_ios(sc->dev); @@ -834,7 +834,7 @@ mmc_test_bus_width(struct mmc_softc *sc) data.len = 4; data.flags = MMC_DATA_WRITE; mmc_wait_for_cmd(sc, &cmd, 0); - + memset(&cmd, 0, sizeof(cmd)); memset(&data, 0, sizeof(data)); cmd.opcode = MMC_BUSTEST_R; @@ -1019,7 +1019,7 @@ mmc_decode_csd_sd(uint32_t *raw_csd, struct mmc_csd *csd) csd->r2w_factor = 1 << mmc_get_bits(raw_csd, 128, 26, 3); csd->write_bl_len = 1 << mmc_get_bits(raw_csd, 128, 22, 4); csd->write_bl_partial = mmc_get_bits(raw_csd, 128, 21, 1); - } else + } else panic("unknown SD CSD version"); } @@ -1351,9 +1351,9 @@ mmc_discover_cards(struct mmc_softc *sc) if (ivar->csd.csd_structure > 0) ivar->high_cap = 1; ivar->tran_speed = ivar->csd.tran_speed; - ivar->erase_sector = ivar->csd.erase_sector * + ivar->erase_sector = ivar->csd.erase_sector * ivar->csd.write_bl_len / MMC_SECTOR_SIZE; - + err = mmc_send_status(sc, ivar->rca, &status); if (err != MMC_ERR_NONE) { device_printf(sc->dev, @@ -1448,7 +1448,7 @@ mmc_discover_cards(struct mmc_softc *sc) mmc_decode_csd_mmc(ivar->raw_csd, &ivar->csd); ivar->sec_count = ivar->csd.capacity / MMC_SECTOR_SIZE; ivar->tran_speed = ivar->csd.tran_speed; - ivar->erase_sector = ivar->csd.erase_sector * + ivar->erase_sector = ivar->csd.erase_sector * ivar->csd.write_bl_len / MMC_SECTOR_SIZE; err = mmc_send_status(sc, ivar->rca, &status); @@ -1657,7 +1657,7 @@ mmc_calculate_clock(struct mmc_softc *sc) int nkid, i, f_max; device_t *kids; struct mmc_ivars *ivar; - + f_max = mmcbr_get_f_max(sc->dev); max_dtr = max_hs_dtr = f_max; if ((mmcbr_get_caps(sc->dev) & MMC_CAP_HSPEED)) @@ -1772,7 +1772,7 @@ static void mmc_delayed_attach(void *xsc) { struct mmc_softc *sc = xsc; - + mmc_scan(sc); config_intrhook_disestablish(&sc->config_intrhook); } diff --git a/freebsd/sys/dev/mmc/mmcreg.h b/freebsd/sys/dev/mmc/mmcreg.h index f25c0f63..ba4ca93a 100644 --- a/freebsd/sys/dev/mmc/mmcreg.h +++ b/freebsd/sys/dev/mmc/mmcreg.h @@ -355,8 +355,8 @@ struct mmc_request { */ #define MMC_OCR_VOLTAGE 0x3fffffffU /* Vdd Voltage mask */ #define MMC_OCR_LOW_VOLTAGE (1u << 7) /* Low Voltage Range -- tbd */ +#define MMC_OCR_MIN_VOLTAGE_SHIFT 7 #define MMC_OCR_200_210 (1U << 8) /* Vdd voltage 2.00 ~ 2.10 */ -#define MMC_OCR_MIN_VOLTAGE_SHIFT 8 #define MMC_OCR_210_220 (1U << 9) /* Vdd voltage 2.10 ~ 2.20 */ #define MMC_OCR_220_230 (1U << 10) /* Vdd voltage 2.20 ~ 2.30 */ #define MMC_OCR_230_240 (1U << 11) /* Vdd voltage 2.30 ~ 2.40 */ diff --git a/freebsd/sys/dev/pci/pci.c b/freebsd/sys/dev/pci/pci.c index 211562f0..2eba4ca2 100644 --- a/freebsd/sys/dev/pci/pci.c +++ b/freebsd/sys/dev/pci/pci.c @@ -358,6 +358,11 @@ static int pci_do_msix = 1; SYSCTL_INT(_hw_pci, OID_AUTO, enable_msix, CTLFLAG_RWTUN, &pci_do_msix, 1, "Enable support for MSI-X interrupts"); +static int pci_msix_rewrite_table = 0; +SYSCTL_INT(_hw_pci, OID_AUTO, msix_rewrite_table, CTLFLAG_RWTUN, + &pci_msix_rewrite_table, 0, + "Rewrite entire MSI-X table when updating MSI-X entries"); + static int pci_honor_msi_blacklist = 1; SYSCTL_INT(_hw_pci, OID_AUTO, honor_msi_blacklist, CTLFLAG_RDTUN, &pci_honor_msi_blacklist, 1, "Honor chipset blacklist for MSI/MSI-X"); @@ -1486,11 +1491,10 @@ pci_find_extcap_method(device_t dev, device_t child, int capability, /* * Support for MSI-X message interrupts. */ -void -pci_enable_msix_method(device_t dev, device_t child, u_int index, - uint64_t address, uint32_t data) +static void +pci_write_msix_entry(device_t dev, u_int index, uint64_t address, uint32_t data) { - struct pci_devinfo *dinfo = device_get_ivars(child); + struct pci_devinfo *dinfo = device_get_ivars(dev); struct pcicfg_msix *msix = &dinfo->cfg.msix; uint32_t offset; @@ -1499,6 +1503,31 @@ pci_enable_msix_method(device_t dev, device_t child, u_int index, bus_write_4(msix->msix_table_res, offset, address & 0xffffffff); bus_write_4(msix->msix_table_res, offset + 4, address >> 32); bus_write_4(msix->msix_table_res, offset + 8, data); +} + +void +pci_enable_msix_method(device_t dev, device_t child, u_int index, + uint64_t address, uint32_t data) +{ + + if (pci_msix_rewrite_table) { + struct pci_devinfo *dinfo = device_get_ivars(child); + struct pcicfg_msix *msix = &dinfo->cfg.msix; + + /* + * Some VM hosts require MSIX to be disabled in the + * control register before updating the MSIX table + * entries are allowed. It is not enough to only + * disable MSIX while updating a single entry. MSIX + * must be disabled while updating all entries in the + * table. + */ + pci_write_config(child, + msix->msix_location + PCIR_MSIX_CTRL, + msix->msix_ctrl & ~PCIM_MSIXCTRL_MSIX_ENABLE, 2); + pci_resume_msix(child); + } else + pci_write_msix_entry(child, index, address, data); /* Enable MSI -> HT mapping. */ pci_ht_map_msi(child, address); @@ -1574,7 +1603,8 @@ pci_resume_msix(device_t dev) if (mte->mte_vector == 0 || mte->mte_handlers == 0) continue; mv = &msix->msix_vectors[mte->mte_vector - 1]; - pci_enable_msix(dev, i, mv->mv_address, mv->mv_data); + pci_write_msix_entry(dev, i, mv->mv_address, + mv->mv_data); pci_unmask_msix(dev, i); } } @@ -4411,12 +4441,20 @@ pci_setup_intr(device_t dev, device_t child, struct resource *irq, int flags, mv->mv_address = addr; mv->mv_data = data; } - if (mte->mte_handlers == 0) { + + /* + * The MSIX table entry must be made valid by + * incrementing the mte_handlers before + * calling pci_enable_msix() and + * pci_resume_msix(). Else the MSIX rewrite + * table quirk will not work as expected. + */ + mte->mte_handlers++; + if (mte->mte_handlers == 1) { pci_enable_msix(child, rid - 1, mv->mv_address, mv->mv_data); pci_unmask_msix(child, rid - 1); } - mte->mte_handlers++; } /* diff --git a/freebsd/sys/dev/usb/usb_hub.c b/freebsd/sys/dev/usb/usb_hub.c index d27728e9..b7d5b597 100644 --- a/freebsd/sys/dev/usb/usb_hub.c +++ b/freebsd/sys/dev/usb/usb_hub.c @@ -2264,6 +2264,11 @@ usb_needs_explore(struct usb_bus *bus, uint8_t do_probe) DPRINTF("\n"); + if (cold != 0) { + DPRINTF("Cold\n"); + return; + } + if (bus == NULL) { DPRINTF("No bus pointer!\n"); return; @@ -2329,6 +2334,26 @@ usb_needs_explore_all(void) } /*------------------------------------------------------------------------* + * usb_needs_explore_init + * + * This function will ensure that the USB controllers are not enumerated + * until the "cold" variable is cleared. + *------------------------------------------------------------------------*/ +static void +usb_needs_explore_init(void *arg) +{ + /* + * The cold variable should be cleared prior to this function + * being called: + */ + if (cold == 0) + usb_needs_explore_all(); + else + DPRINTFN(-1, "Cold variable is still set!\n"); +} +SYSINIT(usb_needs_explore_init, SI_SUB_KICK_SCHEDULER, SI_ORDER_SECOND, usb_needs_explore_init, NULL); + +/*------------------------------------------------------------------------* * usb_bus_power_update * * This function will ensure that all USB devices on the given bus are diff --git a/freebsd/sys/dev/usb/usb_process.c b/freebsd/sys/dev/usb/usb_process.c index 569550e6..060cc18a 100644 --- a/freebsd/sys/dev/usb/usb_process.c +++ b/freebsd/sys/dev/usb/usb_process.c @@ -461,8 +461,8 @@ usb_proc_drain(struct usb_process *up) up->up_csleep = 0; cv_signal(&up->up_cv); } +#ifndef EARLY_AP_STARTUP /* Check if we are still cold booted */ - if (cold) { #ifndef __rtems__ USB_THREAD_SUSPEND(up->up_ptr); @@ -473,6 +473,7 @@ usb_proc_drain(struct usb_process *up) BSD_ASSERT(0); #endif /* __rtems__ */ } +#endif cv_wait(&up->up_cv, up->up_mtx); } /* Check if someone is waiting - should not happen */ diff --git a/freebsd/sys/kern/kern_event.c b/freebsd/sys/kern/kern_event.c index ca9c1de7..473414ae 100644 --- a/freebsd/sys/kern/kern_event.c +++ b/freebsd/sys/kern/kern_event.c @@ -50,7 +50,6 @@ __FBSDID("$FreeBSD$"); #include <sys/fcntl.h> #include <sys/kthread.h> #include <sys/selinfo.h> -#include <sys/stdatomic.h> #include <sys/queue.h> #include <sys/event.h> #include <sys/eventvar.h> @@ -71,13 +70,12 @@ __FBSDID("$FreeBSD$"); #ifdef KTRACE #include <sys/ktrace.h> #endif +#include <machine/atomic.h> #include <vm/uma.h> #ifdef __rtems__ #include <machine/rtems-bsd-syscall-api.h> -#define KN_INFLUX 0x10 /* knote is in flux */ - /* Maintain a global kqueue list on RTEMS */ static struct kqlist fd_kqlist; #endif /* __rtems__ */ @@ -153,6 +151,7 @@ static const rtems_filesystem_file_handlers_r kqueueops; static int knote_attach(struct knote *kn, struct kqueue *kq); static void knote_drop(struct knote *kn, struct thread *td); +static void knote_drop_detached(struct knote *kn, struct thread *td); static void knote_enqueue(struct knote *kn); static void knote_dequeue(struct knote *kn); static void knote_init(void); @@ -209,12 +208,12 @@ static struct filterops user_filtops = { }; static uma_zone_t knote_zone; -static atomic_uint kq_ncallouts = ATOMIC_VAR_INIT(0); +static unsigned int kq_ncallouts = 0; static unsigned int kq_calloutmax = 4 * 1024; SYSCTL_UINT(_kern, OID_AUTO, kq_calloutmax, CTLFLAG_RW, &kq_calloutmax, 0, "Maximum number of callouts allocated for kqueue"); -/* XXX - ensure not KN_INFLUX?? */ +/* XXX - ensure not influx ? */ #define KNOTE_ACTIVATE(kn, islock) do { \ if ((islock)) \ mtx_assert(&(kn)->kn_kq->kq_lock, MA_OWNED); \ @@ -275,6 +274,32 @@ kn_list_unlock(struct knlist *knl) } } +static bool +kn_in_flux(struct knote *kn) +{ + + return (kn->kn_influx > 0); +} + +static void +kn_enter_flux(struct knote *kn) +{ + + KQ_OWNED(kn->kn_kq); + MPASS(kn->kn_influx < INT_MAX); + kn->kn_influx++; +} + +static bool +kn_leave_flux(struct knote *kn) +{ + + KQ_OWNED(kn->kn_kq); + MPASS(kn->kn_influx > 0); + kn->kn_influx--; + return (kn->kn_influx == 0); +} + #define KNL_ASSERT_LOCK(knl, islocked) do { \ if (islocked) \ KNL_ASSERT_LOCKED(knl); \ @@ -538,7 +563,7 @@ knote_fork(struct knlist *list, int pid) SLIST_FOREACH(kn, &list->kl_list, kn_selnext) { kq = kn->kn_kq; KQ_LOCK(kq); - if ((kn->kn_status & (KN_INFLUX | KN_SCAN)) == KN_INFLUX) { + if (kn_in_flux(kn) && (kn->kn_status & KN_SCAN) == 0) { KQ_UNLOCK(kq); continue; } @@ -561,7 +586,7 @@ knote_fork(struct knlist *list, int pid) * track the child. Drop the locks in preparation for * the call to kqueue_register(). */ - kn->kn_status |= KN_INFLUX; + kn_enter_flux(kn); KQ_UNLOCK(kq); list->kl_unlock(list->kl_lockarg); @@ -601,7 +626,7 @@ knote_fork(struct knlist *list, int pid) if (kn->kn_fop->f_event(kn, NOTE_FORK)) KNOTE_ACTIVATE(kn, 0); KQ_LOCK(kq); - kn->kn_status &= ~KN_INFLUX; + kn_leave_flux(kn); KQ_UNLOCK_FLUX(kq); list->kl_lock(list->kl_lockarg); } @@ -632,7 +657,7 @@ timer2sbintime(intptr_t data, int flags) case NOTE_SECONDS: #ifdef __LP64__ if (data > (SBT_MAX / SBT_1S)) - return SBT_MAX; + return (SBT_MAX); #endif return ((sbintime_t)data << 32); case NOTE_MSECONDS: /* FALLTHROUGH */ @@ -641,7 +666,7 @@ timer2sbintime(intptr_t data, int flags) int64_t secs = data / 1000; #ifdef __LP64__ if (secs > (SBT_MAX / SBT_1S)) - return SBT_MAX; + return (SBT_MAX); #endif return (secs << 32 | MS_TO_SBT(data % 1000)); } @@ -651,7 +676,7 @@ timer2sbintime(intptr_t data, int flags) int64_t secs = data / 1000000; #ifdef __LP64__ if (secs > (SBT_MAX / SBT_1S)) - return SBT_MAX; + return (SBT_MAX); #endif return (secs << 32 | US_TO_SBT(data % 1000000)); } @@ -661,34 +686,40 @@ timer2sbintime(intptr_t data, int flags) int64_t secs = data / 1000000000; #ifdef __LP64__ if (secs > (SBT_MAX / SBT_1S)) - return SBT_MAX; + return (SBT_MAX); #endif return (secs << 32 | US_TO_SBT(data % 1000000000)); } - return NS_TO_SBT(data); + return (NS_TO_SBT(data)); default: break; } return (-1); } +struct kq_timer_cb_data { + struct callout c; + sbintime_t next; /* next timer event fires at */ + sbintime_t to; /* precalculated timer period */ +}; + static void filt_timerexpire(void *knx) { - struct callout *calloutp; struct knote *kn; + struct kq_timer_cb_data *kc; kn = knx; kn->kn_data++; KNOTE_ACTIVATE(kn, 0); /* XXX - handle locking */ - if ((kn->kn_flags & EV_ONESHOT) != EV_ONESHOT) { - calloutp = (struct callout *)kn->kn_hook; - *kn->kn_ptr.p_nexttime += timer2sbintime(kn->kn_sdata, - kn->kn_sfflags); - callout_reset_sbt_on(calloutp, *kn->kn_ptr.p_nexttime, 0, - filt_timerexpire, kn, PCPU_GET(cpuid), C_ABSOLUTE); - } + if ((kn->kn_flags & EV_ONESHOT) != 0) + return; + + kc = kn->kn_ptr.p_v; + kc->next += kc->to; + callout_reset_sbt_on(&kc->c, kc->next, 0, filt_timerexpire, kn, + PCPU_GET(cpuid), C_ABSOLUTE); } /* @@ -697,39 +728,36 @@ filt_timerexpire(void *knx) static int filt_timerattach(struct knote *kn) { - struct callout *calloutp; + struct kq_timer_cb_data *kc; sbintime_t to; unsigned int ncallouts; - if ((intptr_t)kn->kn_sdata < 0) + if (kn->kn_sdata < 0) return (EINVAL); - if ((intptr_t)kn->kn_sdata == 0 && (kn->kn_flags & EV_ONESHOT) == 0) + if (kn->kn_sdata == 0 && (kn->kn_flags & EV_ONESHOT) == 0) kn->kn_sdata = 1; /* Only precision unit are supported in flags so far */ - if (kn->kn_sfflags & ~NOTE_TIMER_PRECMASK) + if ((kn->kn_sfflags & ~NOTE_TIMER_PRECMASK) != 0) return (EINVAL); to = timer2sbintime(kn->kn_sdata, kn->kn_sfflags); if (to < 0) return (EINVAL); - ncallouts = atomic_load_explicit(&kq_ncallouts, memory_order_relaxed); do { + ncallouts = kq_ncallouts; if (ncallouts >= kq_calloutmax) return (ENOMEM); - } while (!atomic_compare_exchange_weak_explicit(&kq_ncallouts, - &ncallouts, ncallouts + 1, memory_order_relaxed, - memory_order_relaxed)); + } while (!atomic_cmpset_int(&kq_ncallouts, ncallouts, ncallouts + 1)); kn->kn_flags |= EV_CLEAR; /* automatically set */ kn->kn_status &= ~KN_DETACHED; /* knlist_add clears it */ - kn->kn_ptr.p_nexttime = malloc(sizeof(sbintime_t), M_KQUEUE, M_WAITOK); - calloutp = malloc(sizeof(*calloutp), M_KQUEUE, M_WAITOK); - callout_init(calloutp, 1); - kn->kn_hook = calloutp; - *kn->kn_ptr.p_nexttime = to + sbinuptime(); - callout_reset_sbt_on(calloutp, *kn->kn_ptr.p_nexttime, 0, - filt_timerexpire, kn, PCPU_GET(cpuid), C_ABSOLUTE); + kn->kn_ptr.p_v = kc = malloc(sizeof(*kc), M_KQUEUE, M_WAITOK); + callout_init(&kc->c, 1); + kc->next = to + sbinuptime(); + kc->to = to; + callout_reset_sbt_on(&kc->c, kc->next, 0, filt_timerexpire, kn, + PCPU_GET(cpuid), C_ABSOLUTE); return (0); } @@ -737,14 +765,13 @@ filt_timerattach(struct knote *kn) static void filt_timerdetach(struct knote *kn) { - struct callout *calloutp; + struct kq_timer_cb_data *kc; unsigned int old; - calloutp = (struct callout *)kn->kn_hook; - callout_drain(calloutp); - free(calloutp, M_KQUEUE); - free(kn->kn_ptr.p_nexttime, M_KQUEUE); - old = atomic_fetch_sub_explicit(&kq_ncallouts, 1, memory_order_relaxed); + kc = kn->kn_ptr.p_v; + callout_drain(&kc->c); + free(kc, M_KQUEUE); + old = atomic_fetchadd_int(&kq_ncallouts, -1); KASSERT(old > 0, ("Number of callouts cannot become negative")); kn->kn_status |= KN_DETACHED; /* knlist_remove sets it */ } @@ -1386,7 +1413,7 @@ findkn: } /* knote is in the process of changing, wait for it to stabilize. */ - if (kn != NULL && (kn->kn_status & KN_INFLUX) == KN_INFLUX) { + if (kn != NULL && kn_in_flux(kn)) { KQ_GLOBAL_UNLOCK(&kq_global, haskqglobal); if (filedesc_unlock) { FILEDESC_XUNLOCK(td->td_proc->p_fd); @@ -1430,7 +1457,8 @@ findkn: kn->kn_kevent = *kev; kn->kn_kevent.flags &= ~(EV_ADD | EV_DELETE | EV_ENABLE | EV_DISABLE | EV_FORCEONESHOT); - kn->kn_status = KN_INFLUX|KN_DETACHED; + kn->kn_status = KN_DETACHED; + kn_enter_flux(kn); error = knote_attach(kn, kq); KQ_UNLOCK(kq); @@ -1440,7 +1468,7 @@ findkn: } if ((error = kn->kn_fop->f_attach(kn)) != 0) { - knote_drop(kn, td); + knote_drop_detached(kn, td); goto done; } knl = kn_list_lock(kn); @@ -1454,10 +1482,8 @@ findkn: } if (kev->flags & EV_DELETE) { - kn->kn_status |= KN_INFLUX; + kn_enter_flux(kn); KQ_UNLOCK(kq); - if (!(kn->kn_status & KN_DETACHED)) - kn->kn_fop->f_detach(kn); knote_drop(kn, td); goto done; } @@ -1472,7 +1498,8 @@ findkn: * but doing so will not reset any filter which has already been * triggered. */ - kn->kn_status |= KN_INFLUX | KN_SCAN; + kn->kn_status |= KN_SCAN; + kn_enter_flux(kn); KQ_UNLOCK(kq); knl = kn_list_lock(kn); kn->kn_kevent.udata = kev->udata; @@ -1507,7 +1534,8 @@ done_ev_add: if ((kn->kn_status & (KN_ACTIVE | KN_DISABLED | KN_QUEUED)) == KN_ACTIVE) knote_enqueue(kn); - kn->kn_status &= ~(KN_INFLUX | KN_SCAN); + kn->kn_status &= ~KN_SCAN; + kn_leave_flux(kn); kn_list_unlock(knl); KQ_UNLOCK_FLUX(kq); @@ -1674,7 +1702,7 @@ kqueue_task(void *arg, int pending) /* * Scan, update kn_data (if not ONESHOT), and copyout triggered events. - * We treat KN_MARKER knotes as if they are INFLUX. + * We treat KN_MARKER knotes as if they are in flux. */ static int kqueue_scan(struct kqueue *kq, int maxevents, struct kevent_copyops *k_ops, @@ -1748,7 +1776,7 @@ retry: kn = TAILQ_FIRST(&kq->kq_head); if ((kn->kn_status == KN_MARKER && kn != marker) || - (kn->kn_status & KN_INFLUX) == KN_INFLUX) { + kn_in_flux(kn)) { if (influx) { influx = 0; KQ_FLUX_WAKEUP(kq); @@ -1771,40 +1799,37 @@ retry: goto retry; goto done; } - KASSERT((kn->kn_status & KN_INFLUX) == 0, - ("KN_INFLUX set when not suppose to be")); + KASSERT(!kn_in_flux(kn), + ("knote %p is unexpectedly in flux", kn)); if ((kn->kn_flags & EV_DROP) == EV_DROP) { kn->kn_status &= ~KN_QUEUED; - kn->kn_status |= KN_INFLUX; + kn_enter_flux(kn); kq->kq_count--; KQ_UNLOCK(kq); /* - * We don't need to lock the list since we've marked - * it _INFLUX. + * We don't need to lock the list since we've + * marked it as in flux. */ - if (!(kn->kn_status & KN_DETACHED)) - kn->kn_fop->f_detach(kn); knote_drop(kn, td); KQ_LOCK(kq); continue; } else if ((kn->kn_flags & EV_ONESHOT) == EV_ONESHOT) { kn->kn_status &= ~KN_QUEUED; - kn->kn_status |= KN_INFLUX; + kn_enter_flux(kn); kq->kq_count--; KQ_UNLOCK(kq); /* - * We don't need to lock the list since we've marked - * it _INFLUX. + * We don't need to lock the list since we've + * marked the knote as being in flux. */ *kevp = kn->kn_kevent; - if (!(kn->kn_status & KN_DETACHED)) - kn->kn_fop->f_detach(kn); knote_drop(kn, td); KQ_LOCK(kq); kn = NULL; } else { - kn->kn_status |= KN_INFLUX | KN_SCAN; + kn->kn_status |= KN_SCAN; + kn_enter_flux(kn); KQ_UNLOCK(kq); if ((kn->kn_status & KN_KQUEUE) == KN_KQUEUE) KQ_GLOBAL_LOCK(&kq_global, haskqglobal); @@ -1812,9 +1837,9 @@ retry: if (kn->kn_fop->f_event(kn, 0) == 0) { KQ_LOCK(kq); KQ_GLOBAL_UNLOCK(&kq_global, haskqglobal); - kn->kn_status &= - ~(KN_QUEUED | KN_ACTIVE | KN_INFLUX | + kn->kn_status &= ~(KN_QUEUED | KN_ACTIVE | KN_SCAN); + kn_leave_flux(kn); kq->kq_count--; kn_list_unlock(knl); influx = 1; @@ -1844,7 +1869,8 @@ retry: } else TAILQ_INSERT_TAIL(&kq->kq_head, kn, kn_tqe); - kn->kn_status &= ~(KN_INFLUX | KN_SCAN); + kn->kn_status &= ~KN_SCAN; + kn_leave_flux(kn); kn_list_unlock(knl); influx = 1; } @@ -2019,15 +2045,13 @@ kqueue_drain(struct kqueue *kq, struct thread *td) for (i = 0; i < kq->kq_knlistsize; i++) { while ((kn = SLIST_FIRST(&kq->kq_knlist[i])) != NULL) { - if ((kn->kn_status & KN_INFLUX) == KN_INFLUX) { + if (kn_in_flux(kn)) { kq->kq_state |= KQ_FLUXWAIT; msleep(kq, &kq->kq_lock, PSOCK, "kqclo1", 0); continue; } - kn->kn_status |= KN_INFLUX; + kn_enter_flux(kn); KQ_UNLOCK(kq); - if (!(kn->kn_status & KN_DETACHED)) - kn->kn_fop->f_detach(kn); knote_drop(kn, td); KQ_LOCK(kq); } @@ -2035,16 +2059,14 @@ kqueue_drain(struct kqueue *kq, struct thread *td) if (kq->kq_knhashmask != 0) { for (i = 0; i <= kq->kq_knhashmask; i++) { while ((kn = SLIST_FIRST(&kq->kq_knhash[i])) != NULL) { - if ((kn->kn_status & KN_INFLUX) == KN_INFLUX) { + if (kn_in_flux(kn)) { kq->kq_state |= KQ_FLUXWAIT; msleep(kq, &kq->kq_lock, PSOCK, "kqclo2", 0); continue; } - kn->kn_status |= KN_INFLUX; + kn_enter_flux(kn); KQ_UNLOCK(kq); - if (!(kn->kn_status & KN_DETACHED)) - kn->kn_fop->f_detach(kn); knote_drop(kn, td); KQ_LOCK(kq); } @@ -2205,7 +2227,7 @@ knote(struct knlist *list, long hint, int lockflags) list->kl_lock(list->kl_lockarg); /* - * If we unlock the list lock (and set KN_INFLUX), we can + * If we unlock the list lock (and enter influx), we can * eliminate the kqueue scheduling, but this will introduce * four lock/unlock's for each knote to test. Also, marker * would be needed to keep iteration position, since filters @@ -2214,7 +2236,7 @@ knote(struct knlist *list, long hint, int lockflags) SLIST_FOREACH_SAFE(kn, &list->kl_list, kn_selnext, tkn) { kq = kn->kn_kq; KQ_LOCK(kq); - if ((kn->kn_status & (KN_INFLUX | KN_SCAN)) == KN_INFLUX) { + if (kn_in_flux(kn) && (kn->kn_status & KN_SCAN) == 0) { /* * Do not process the influx notes, except for * the influx coming from the kq unlock in the @@ -2225,11 +2247,11 @@ knote(struct knlist *list, long hint, int lockflags) */ KQ_UNLOCK(kq); } else if ((lockflags & KNF_NOKQLOCK) != 0) { - kn->kn_status |= KN_INFLUX; + kn_enter_flux(kn); KQ_UNLOCK(kq); error = kn->kn_fop->f_event(kn, hint); KQ_LOCK(kq); - kn->kn_status &= ~KN_INFLUX; + kn_leave_flux(kn); if (error) KNOTE_ACTIVATE(kn, 1); KQ_UNLOCK_FLUX(kq); @@ -2251,10 +2273,12 @@ knote(struct knlist *list, long hint, int lockflags) void knlist_add(struct knlist *knl, struct knote *kn, int islocked) { + KNL_ASSERT_LOCK(knl, islocked); KQ_NOTOWNED(kn->kn_kq); - KASSERT((kn->kn_status & (KN_INFLUX|KN_DETACHED)) == - (KN_INFLUX|KN_DETACHED), ("knote not KN_INFLUX and KN_DETACHED")); + KASSERT(kn_in_flux(kn), ("knote %p not in flux", kn)); + KASSERT((kn->kn_status & KN_DETACHED) != 0, + ("knote %p was not detached", kn)); if (!islocked) knl->kl_lock(knl->kl_lockarg); SLIST_INSERT_HEAD(&knl->kl_list, kn, kn_selnext); @@ -2270,12 +2294,13 @@ static void knlist_remove_kq(struct knlist *knl, struct knote *kn, int knlislocked, int kqislocked) { - KASSERT(!(!!kqislocked && !knlislocked), ("kq locked w/o knl locked")); + + KASSERT(!kqislocked || knlislocked, ("kq locked w/o knl locked")); KNL_ASSERT_LOCK(knl, knlislocked); mtx_assert(&kn->kn_kq->kq_lock, kqislocked ? MA_OWNED : MA_NOTOWNED); - if (!kqislocked) - KASSERT((kn->kn_status & (KN_INFLUX|KN_DETACHED)) == KN_INFLUX, - ("knlist_remove called w/o knote being KN_INFLUX or already removed")); + KASSERT(kqislocked || kn_in_flux(kn), ("knote %p not in flux", kn)); + KASSERT((kn->kn_status & KN_DETACHED) == 0, + ("knote %p was already detached", kn)); if (!knlislocked) knl->kl_lock(knl->kl_lockarg); SLIST_REMOVE(&knl->kl_list, kn, knote, kn_selnext); @@ -2304,12 +2329,12 @@ knlist_empty(struct knlist *knl) { KNL_ASSERT_LOCKED(knl); - return SLIST_EMPTY(&knl->kl_list); + return (SLIST_EMPTY(&knl->kl_list)); } -static struct mtx knlist_lock; +static struct mtx knlist_lock; MTX_SYSINIT(knlist_lock, &knlist_lock, "knlist lock for lockless objects", - MTX_DEF); + MTX_DEF); static void knlist_mtx_lock(void *arg); static void knlist_mtx_unlock(void *arg); @@ -2434,17 +2459,8 @@ void knlist_destroy(struct knlist *knl) { -#ifdef INVARIANTS - /* - * if we run across this error, we need to find the offending - * driver and have it call knlist_clear or knlist_delete. - */ - if (!SLIST_EMPTY(&knl->kl_list)) - printf("WARNING: destroying knlist w/ knotes on it!\n"); -#endif - - knl->kl_lockarg = knl->kl_lock = knl->kl_unlock = NULL; - SLIST_INIT(&knl->kl_list); + KASSERT(KNLIST_EMPTY(knl), + ("destroying knlist %p with knotes on it", knl)); } void @@ -2481,30 +2497,29 @@ again: /* need to reacquire lock since we have dropped it */ SLIST_FOREACH_SAFE(kn, &knl->kl_list, kn_selnext, kn2) { kq = kn->kn_kq; KQ_LOCK(kq); - if ((kn->kn_status & KN_INFLUX)) { + if (kn_in_flux(kn)) { KQ_UNLOCK(kq); continue; } knlist_remove_kq(knl, kn, 1, 1); if (killkn) { - kn->kn_status |= KN_INFLUX | KN_DETACHED; + kn_enter_flux(kn); KQ_UNLOCK(kq); - knote_drop(kn, td); + knote_drop_detached(kn, td); } else { /* Make sure cleared knotes disappear soon */ - kn->kn_flags |= (EV_EOF | EV_ONESHOT); + kn->kn_flags |= EV_EOF | EV_ONESHOT; KQ_UNLOCK(kq); } kq = NULL; } if (!SLIST_EMPTY(&knl->kl_list)) { - /* there are still KN_INFLUX remaining */ + /* there are still in flux knotes remaining */ kn = SLIST_FIRST(&knl->kl_list); kq = kn->kn_kq; KQ_LOCK(kq); - KASSERT(kn->kn_status & KN_INFLUX, - ("knote removed w/o list lock")); + KASSERT(kn_in_flux(kn), ("knote removed w/o list lock")); knl->kl_unlock(knl->kl_lockarg); kq->kq_state |= KQ_FLUXWAIT; msleep(kq, &kq->kq_lock, PSOCK | PDROP, "kqkclr", 0); @@ -2556,7 +2571,7 @@ again: influx = 0; while (kq->kq_knlistsize > fd && (kn = SLIST_FIRST(&kq->kq_knlist[fd])) != NULL) { - if (kn->kn_status & KN_INFLUX) { + if (kn_in_flux(kn)) { /* someone else might be waiting on our knote */ if (influx) wakeup(kq); @@ -2564,12 +2579,10 @@ again: msleep(kq, &kq->kq_lock, PSOCK, "kqflxwt", 0); goto again; } - kn->kn_status |= KN_INFLUX; + kn_enter_flux(kn); KQ_UNLOCK(kq); - if (!(kn->kn_status & KN_DETACHED)) - kn->kn_fop->f_detach(kn); - knote_drop(kn, td); influx = 1; + knote_drop(kn, td); KQ_LOCK(kq); } KQ_UNLOCK_FLUX(kq); @@ -2584,42 +2597,47 @@ knote_attach(struct knote *kn, struct kqueue *kq) { struct klist *list; - KASSERT(kn->kn_status & KN_INFLUX, ("knote not marked INFLUX")); + KASSERT(kn_in_flux(kn), ("knote %p not marked influx", kn)); KQ_OWNED(kq); if (kn->kn_fop->f_isfd) { if (kn->kn_id >= kq->kq_knlistsize) - return ENOMEM; + return (ENOMEM); list = &kq->kq_knlist[kn->kn_id]; } else { if (kq->kq_knhash == NULL) - return ENOMEM; + return (ENOMEM); list = &kq->kq_knhash[KN_HASH(kn->kn_id, kq->kq_knhashmask)]; } - SLIST_INSERT_HEAD(list, kn, kn_link); - - return 0; + return (0); } -/* - * knote must already have been detached using the f_detach method. - * no lock need to be held, it is assumed that the KN_INFLUX flag is set - * to prevent other removal. - */ static void knote_drop(struct knote *kn, struct thread *td) { + + if ((kn->kn_status & KN_DETACHED) == 0) + kn->kn_fop->f_detach(kn); + knote_drop_detached(kn, td); +} + +static void +knote_drop_detached(struct knote *kn, struct thread *td) +{ struct kqueue *kq; struct klist *list; kq = kn->kn_kq; + KASSERT((kn->kn_status & KN_DETACHED) != 0, + ("knote %p still attached", kn)); KQ_NOTOWNED(kq); - KASSERT((kn->kn_status & KN_INFLUX) == KN_INFLUX, - ("knote_drop called without KN_INFLUX set in kn_status")); KQ_LOCK(kq); + KASSERT(kn->kn_influx == 1, + ("knote_drop called on %p with influx %d", kn, kn->kn_influx)); + if (kn->kn_fop->f_isfd) list = &kq->kq_knlist[kn->kn_id]; else @@ -2709,13 +2727,11 @@ kqfd_register(int fd, struct kevent *kev, struct thread *td, int waitok) goto noacquire; error = kqueue_register(kq, kev, td, waitok); - kqueue_release(kq, 0); noacquire: fdrop(fp, td); - - return error; + return (error); } #ifdef __rtems__ static const rtems_filesystem_file_handlers_r kqueueops = { diff --git a/freebsd/sys/kern/kern_synch.c b/freebsd/sys/kern/kern_synch.c index 6a8e7754..7109e798 100644 --- a/freebsd/sys/kern/kern_synch.c +++ b/freebsd/sys/kern/kern_synch.c @@ -353,7 +353,8 @@ pause_sbt(const char *wmesg, sbintime_t sbt, sbintime_t pr, int flags) sbt = tick_sbt; #ifndef __rtems__ - if (cold || kdb_active || SCHEDULER_STOPPED()) { + if ((cold && curthread == &thread0) || kdb_active || + SCHEDULER_STOPPED()) { /* * We delay one second at a time to avoid overflowing the * system specific DELAY() function(s): diff --git a/freebsd/sys/kern/kern_sysctl.c b/freebsd/sys/kern/kern_sysctl.c index 07ddded9..9553f4c7 100644 --- a/freebsd/sys/kern/kern_sysctl.c +++ b/freebsd/sys/kern/kern_sysctl.c @@ -684,6 +684,9 @@ sysctl_remove_oid_locked(struct sysctl_oid *oidp, int del, int recurse) if (oidp->oid_descr) free(__DECONST(char *, oidp->oid_descr), M_SYSCTLOID); + if (oidp->oid_label) + free(__DECONST(char *, oidp->oid_label), + M_SYSCTLOID); free(__DECONST(char *, oidp->oid_name), M_SYSCTLOID); free(oidp, M_SYSCTLOID); } @@ -697,7 +700,8 @@ sysctl_remove_oid_locked(struct sysctl_oid *oidp, int del, int recurse) struct sysctl_oid * sysctl_add_oid(struct sysctl_ctx_list *clist, struct sysctl_oid_list *parent, int number, const char *name, int kind, void *arg1, intmax_t arg2, - int (*handler)(SYSCTL_HANDLER_ARGS), const char *fmt, const char *descr) + int (*handler)(SYSCTL_HANDLER_ARGS), const char *fmt, const char *descr, + const char *label) { struct sysctl_oid *oidp; @@ -734,6 +738,8 @@ sysctl_add_oid(struct sysctl_ctx_list *clist, struct sysctl_oid_list *parent, oidp->oid_fmt = fmt; if (descr != NULL) oidp->oid_descr = strdup(descr, M_SYSCTLOID); + if (label != NULL) + oidp->oid_label = strdup(label, M_SYSCTLOID); /* Update the context, if used */ if (clist != NULL) sysctl_ctx_entry_add(clist, oidp); @@ -821,7 +827,8 @@ SYSINIT(sysctl, SI_SUB_KMEM, SI_ORDER_FIRST, sysctl_register_all, 0); * {0,2,...} return the next OID. * {0,3} return the OID of the name in "new" * {0,4,...} return the kind & format info for the "..." OID. - * {0,5,...} return the description the "..." OID. + * {0,5,...} return the description of the "..." OID. + * {0,6,...} return the aggregation label of the "..." OID. */ #ifdef SYSCTL_DEBUG @@ -1182,6 +1189,31 @@ sysctl_sysctl_oiddescr(SYSCTL_HANDLER_ARGS) static SYSCTL_NODE(_sysctl, 5, oiddescr, CTLFLAG_RD|CTLFLAG_MPSAFE|CTLFLAG_CAPRD, sysctl_sysctl_oiddescr, ""); +static int +sysctl_sysctl_oidlabel(SYSCTL_HANDLER_ARGS) +{ + struct sysctl_oid *oid; + struct rm_priotracker tracker; + int error; + + SYSCTL_RLOCK(&tracker); + error = sysctl_find_oid(arg1, arg2, &oid, NULL, req); + if (error) + goto out; + + if (oid->oid_label == NULL) { + error = ENOENT; + goto out; + } + error = SYSCTL_OUT(req, oid->oid_label, strlen(oid->oid_label) + 1); + out: + SYSCTL_RUNLOCK(&tracker); + return (error); +} + +static SYSCTL_NODE(_sysctl, 6, oidlabel, + CTLFLAG_RD | CTLFLAG_MPSAFE | CTLFLAG_CAPRD, sysctl_sysctl_oidlabel, ""); + /* * Default "handler" functions. */ diff --git a/freebsd/sys/kern/subr_bus.c b/freebsd/sys/kern/subr_bus.c index 1175456c..e8339c93 100644 --- a/freebsd/sys/kern/subr_bus.c +++ b/freebsd/sys/kern/subr_bus.c @@ -292,10 +292,10 @@ device_sysctl_init(device_t dev) return; devclass_sysctl_init(dc); sysctl_ctx_init(&dev->sysctl_ctx); - dev->sysctl_tree = SYSCTL_ADD_NODE(&dev->sysctl_ctx, + dev->sysctl_tree = SYSCTL_ADD_NODE_WITH_LABEL(&dev->sysctl_ctx, SYSCTL_CHILDREN(dc->sysctl_tree), OID_AUTO, dev->nameunit + strlen(dc->name), - CTLFLAG_RD, NULL, ""); + CTLFLAG_RD, NULL, "", "device_index"); SYSCTL_ADD_PROC(&dev->sysctl_ctx, SYSCTL_CHILDREN(dev->sysctl_tree), OID_AUTO, "%desc", CTLTYPE_STRING | CTLFLAG_RD, dev, DEVICE_SYSCTL_DESC, device_sysctl_handler, "A", diff --git a/freebsd/sys/kern/subr_counter.c b/freebsd/sys/kern/subr_counter.c index 2625b179..c34f1cac 100644 --- a/freebsd/sys/kern/subr_counter.c +++ b/freebsd/sys/kern/subr_counter.c @@ -121,3 +121,59 @@ sysctl_handle_counter_u64_array(SYSCTL_HANDLER_ARGS) return (0); } + +/* + * MP-friendly version of ppsratecheck(). + * + * Returns non-negative if we are in the rate, negative otherwise. + * 0 - rate limit not reached. + * -1 - rate limit reached. + * >0 - rate limit was reached before, and was just reset. The return value + * is number of events since last reset. + */ +int64_t +counter_ratecheck(struct counter_rate *cr, int64_t limit) +{ + int64_t val; + int now; + + val = cr->cr_over; + now = ticks; + + if (now - cr->cr_ticks >= hz) { + /* + * Time to clear the structure, we are in the next second. + * First try unlocked read, and then proceed with atomic. + */ + if ((cr->cr_lock == 0) && + atomic_cmpset_acq_int(&cr->cr_lock, 0, 1)) { + /* + * Check if other thread has just went through the + * reset sequence before us. + */ + if (now - cr->cr_ticks >= hz) { + val = counter_u64_fetch(cr->cr_rate); + counter_u64_zero(cr->cr_rate); + cr->cr_over = 0; + cr->cr_ticks = now; + if (val <= limit) + val = 0; + } + atomic_store_rel_int(&cr->cr_lock, 0); + } else + /* + * We failed to lock, in this case other thread may + * be running counter_u64_zero(), so it is not safe + * to do an update, we skip it. + */ + return (val); + } + + counter_u64_add(cr->cr_rate, 1); + if (cr->cr_over != 0) + return (-1); + if (counter_u64_fetch(cr->cr_rate) > limit) + val = cr->cr_over = -1; + + return (val); +} diff --git a/freebsd/sys/kern/subr_sleepqueue.c b/freebsd/sys/kern/subr_sleepqueue.c index a42c62f8..d0288d67 100644 --- a/freebsd/sys/kern/subr_sleepqueue.c +++ b/freebsd/sys/kern/subr_sleepqueue.c @@ -1111,7 +1111,7 @@ int sleepq_broadcast(void *wchan, int flags, int pri, int queue) { struct sleepqueue *sq; - struct thread *td; + struct thread *td, *tdn; int wakeup_swapper; CTR2(KTR_PROC, "sleepq_broadcast(%p, %d)", wchan, flags); @@ -1123,9 +1123,14 @@ sleepq_broadcast(void *wchan, int flags, int pri, int queue) KASSERT(sq->sq_type == (flags & SLEEPQ_TYPE), ("%s: mismatch between sleep/wakeup and cv_*", __func__)); - /* Resume all blocked threads on the sleep queue. */ + /* + * Resume all blocked threads on the sleep queue. The last thread will + * be given ownership of sq and may re-enqueue itself before + * sleepq_resume_thread() returns, so we must cache the "next" queue + * item at the beginning of the final iteration. + */ wakeup_swapper = 0; - while ((td = TAILQ_FIRST(&sq->sq_blocked[queue])) != NULL) { + TAILQ_FOREACH_SAFE(td, &sq->sq_blocked[queue], td_slpq, tdn) { thread_lock(td); wakeup_swapper |= sleepq_resume_thread(sq, td, pri); thread_unlock(td); diff --git a/freebsd/sys/kern/sys_socket.c b/freebsd/sys/kern/sys_socket.c index a2537652..19567b5f 100644 --- a/freebsd/sys/kern/sys_socket.c +++ b/freebsd/sys/kern/sys_socket.c @@ -774,6 +774,8 @@ retry: if (td->td_ru.ru_msgrcv != ru_before) job->msgrcv = 1; } else { + if (!TAILQ_EMPTY(&sb->sb_aiojobq)) + flags |= MSG_MORETOCOME; uio.uio_rw = UIO_WRITE; ru_before = td->td_ru.ru_msgsnd; #ifdef MAC diff --git a/freebsd/sys/kern/uipc_socket.c b/freebsd/sys/kern/uipc_socket.c index c086ee7c..5f01844d 100644 --- a/freebsd/sys/kern/uipc_socket.c +++ b/freebsd/sys/kern/uipc_socket.c @@ -1207,6 +1207,7 @@ sosend_dgram(struct socket *so, struct sockaddr *addr, struct uio *uio, (resid <= 0)) ? PRUS_EOF : /* If there is more to send set PRUS_MORETOCOME */ + (flags & MSG_MORETOCOME) || (resid > 0 && space > 0) ? PRUS_MORETOCOME : 0, top, addr, control, td); if (dontroute) { @@ -1395,6 +1396,7 @@ restart: (resid <= 0)) ? PRUS_EOF : /* If there is more to send set PRUS_MORETOCOME. */ + (flags & MSG_MORETOCOME) || (resid > 0 && space > 0) ? PRUS_MORETOCOME : 0, top, addr, control, td); if (dontroute) { diff --git a/freebsd/sys/mips/include/machine/cpuregs.h b/freebsd/sys/mips/include/machine/cpuregs.h index 26bee195..b6f2433e 100644 --- a/freebsd/sys/mips/include/machine/cpuregs.h +++ b/freebsd/sys/mips/include/machine/cpuregs.h @@ -171,6 +171,11 @@ #define MIPS_CCA_CACHED MIPS_CCA_CCS #endif +#if defined(CPU_XBURST) +#define MIPS_CCA_UA 0x01 +#define MIPS_CCA_WC MIPS_CCA_UA +#endif + #ifndef MIPS_CCA_UNCACHED #define MIPS_CCA_UNCACHED MIPS_CCA_UC #endif diff --git a/freebsd/sys/net/if.c b/freebsd/sys/net/if.c index e1c525bd..882eee5c 100644 --- a/freebsd/sys/net/if.c +++ b/freebsd/sys/net/if.c @@ -2302,7 +2302,7 @@ static int ifhwioctl(u_long cmd, struct ifnet *ifp, caddr_t data, struct thread *td) { struct ifreq *ifr; - int error = 0; + int error = 0, do_ifup = 0; int new_flags, temp_flags; size_t namelen, onamelen; size_t descrlen; @@ -2429,7 +2429,7 @@ ifhwioctl(u_long cmd, struct ifnet *ifp, caddr_t data, struct thread *td) if_down(ifp); } else if (new_flags & IFF_UP && (ifp->if_flags & IFF_UP) == 0) { - if_up(ifp); + do_ifup = 1; } /* See if permanently promiscuous mode bit is about to flip */ if ((ifp->if_flags ^ new_flags) & IFF_PPROMISC) { @@ -2448,6 +2448,8 @@ ifhwioctl(u_long cmd, struct ifnet *ifp, caddr_t data, struct thread *td) if (ifp->if_ioctl) { (void) (*ifp->if_ioctl)(ifp, cmd, data); } + if (do_ifup) + if_up(ifp); getmicrotime(&ifp->if_lastchange); break; diff --git a/freebsd/sys/net/if_lagg.c b/freebsd/sys/net/if_lagg.c index 9cfb7b8b..b5b61364 100644 --- a/freebsd/sys/net/if_lagg.c +++ b/freebsd/sys/net/if_lagg.c @@ -1024,7 +1024,7 @@ lagg_port_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data) return (error); fallback: - if (lp->lp_ioctl != NULL) + if (lp != NULL && lp->lp_ioctl != NULL) return ((*lp->lp_ioctl)(ifp, cmd, data)); return (EINVAL); diff --git a/freebsd/sys/net/if_media.h b/freebsd/sys/net/if_media.h index 86439950..b6c999d3 100644 --- a/freebsd/sys/net/if_media.h +++ b/freebsd/sys/net/if_media.h @@ -264,6 +264,7 @@ uint64_t ifmedia_baudrate(int); #define IFM_IEEE80211_OFDM27 23 /* OFDM 27Mbps */ /* NB: not enough bits to express MCS fully */ #define IFM_IEEE80211_MCS 24 /* HT MCS rate */ +#define IFM_IEEE80211_VHT 25 /* HT MCS rate */ #define IFM_IEEE80211_ADHOC 0x00000100 /* Operate in Adhoc mode */ #define IFM_IEEE80211_HOSTAP 0x00000200 /* Operate in Host AP mode */ @@ -280,6 +281,8 @@ uint64_t ifmedia_baudrate(int); #define IFM_IEEE80211_FH 0x00040000 /* 2Ghz, GFSK mode */ #define IFM_IEEE80211_11NA 0x00050000 /* 5Ghz, HT mode */ #define IFM_IEEE80211_11NG 0x00060000 /* 2Ghz, HT mode */ +#define IFM_IEEE80211_VHT5G 0x00070000 /* 5Ghz, VHT mode */ +#define IFM_IEEE80211_VHT2G 0x00080000 /* 2Ghz, VHT mode */ /* * ATM @@ -570,6 +573,7 @@ struct ifmedia_description { { IFM_IEEE80211_OFDM4, "OFDM/4.5Mbps" }, \ { IFM_IEEE80211_OFDM27, "OFDM/27Mbps" }, \ { IFM_IEEE80211_MCS, "MCS" }, \ + { IFM_IEEE80211_VHT, "VHT" }, \ { 0, NULL }, \ } @@ -609,6 +613,7 @@ struct ifmedia_description { { IFM_IEEE80211_OFDM4, "OFDM4.5" }, \ { IFM_IEEE80211_OFDM27, "OFDM27" }, \ { IFM_IEEE80211_MCS, "MCS" }, \ + { IFM_IEEE80211_VHT, "VHT" }, \ { 0, NULL }, \ } @@ -631,6 +636,8 @@ struct ifmedia_description { { IFM_IEEE80211_FH, "fh" }, \ { IFM_IEEE80211_11NA, "11na" }, \ { IFM_IEEE80211_11NG, "11ng" }, \ + { IFM_IEEE80211_VHT5G, "11ac" }, \ + { IFM_IEEE80211_VHT2G, "11ac2" }, \ { 0, NULL }, \ } diff --git a/freebsd/sys/netinet/icmp_var.h b/freebsd/sys/netinet/icmp_var.h index d3e72bc2..d76679f6 100644 --- a/freebsd/sys/netinet/icmp_var.h +++ b/freebsd/sys/netinet/icmp_var.h @@ -96,7 +96,7 @@ extern int badport_bandlim(int); #define BANDLIM_RST_OPENPORT 4 /* No connection, listener */ #define BANDLIM_ICMP6_UNREACH 5 #define BANDLIM_SCTP_OOTB 6 -#define BANDLIM_MAX 6 +#define BANDLIM_MAX 7 #endif #endif diff --git a/freebsd/sys/netinet/ip_carp.c b/freebsd/sys/netinet/ip_carp.c index 6b683f45..5f67b6f5 100644 --- a/freebsd/sys/netinet/ip_carp.c +++ b/freebsd/sys/netinet/ip_carp.c @@ -583,27 +583,96 @@ carp6_input(struct mbuf **mp, int *offp, int proto) } #endif /* INET6 */ +/* + * This routine should not be necessary at all, but some switches + * (VMWare ESX vswitches) can echo our own packets back at us, + * and we must ignore them or they will cause us to drop out of + * MASTER mode. + * + * We cannot catch all cases of network loops. Instead, what we + * do here is catch any packet that arrives with a carp header + * with a VHID of 0, that comes from an address that is our own. + * These packets are by definition "from us" (even if they are from + * a misconfigured host that is pretending to be us). + * + * The VHID test is outside this mini-function. + */ +static int +carp_source_is_self(struct mbuf *m, struct ifaddr *ifa, sa_family_t af) +{ +#ifdef INET + struct ip *ip4; + struct in_addr in4; +#endif +#ifdef INET6 + struct ip6_hdr *ip6; + struct in6_addr in6; +#endif + + switch (af) { +#ifdef INET + case AF_INET: + ip4 = mtod(m, struct ip *); + in4 = ifatoia(ifa)->ia_addr.sin_addr; + return (in4.s_addr == ip4->ip_src.s_addr); +#endif +#ifdef INET6 + case AF_INET6: + ip6 = mtod(m, struct ip6_hdr *); + in6 = ifatoia6(ifa)->ia_addr.sin6_addr; + return (memcmp(&in6, &ip6->ip6_src, sizeof(in6)) == 0); +#endif + default: + break; + } + return (0); +} + static void carp_input_c(struct mbuf *m, struct carp_header *ch, sa_family_t af) { struct ifnet *ifp = m->m_pkthdr.rcvif; - struct ifaddr *ifa; + struct ifaddr *ifa, *match; struct carp_softc *sc; uint64_t tmp_counter; struct timeval sc_tv, ch_tv; + int error; - /* verify that the VHID is valid on the receiving interface */ + /* + * Verify that the VHID is valid on the receiving interface. + * + * There should be just one match. If there are none + * the VHID is not valid and we drop the packet. If + * there are multiple VHID matches, take just the first + * one, for compatibility with previous code. While we're + * scanning, check for obvious loops in the network topology + * (these should never happen, and as noted above, we may + * miss real loops; this is just a double-check). + */ IF_ADDR_RLOCK(ifp); - IFNET_FOREACH_IFA(ifp, ifa) - if (ifa->ifa_addr->sa_family == af && - ifa->ifa_carp->sc_vhid == ch->carp_vhid) { - ifa_ref(ifa); - break; - } + error = 0; + match = NULL; + IFNET_FOREACH_IFA(ifp, ifa) { + if (match == NULL && ifa->ifa_carp != NULL && + ifa->ifa_addr->sa_family == af && + ifa->ifa_carp->sc_vhid == ch->carp_vhid) + match = ifa; + if (ch->carp_vhid == 0 && carp_source_is_self(m, ifa, af)) + error = ELOOP; + } + ifa = error ? NULL : match; + if (ifa != NULL) + ifa_ref(ifa); IF_ADDR_RUNLOCK(ifp); if (ifa == NULL) { - CARPSTATS_INC(carps_badvhid); + if (error == ELOOP) { + CARP_DEBUG("dropping looped packet on interface %s\n", + ifp->if_xname); + CARPSTATS_INC(carps_badif); /* ??? */ + } else { + CARPSTATS_INC(carps_badvhid); + } m_freem(m); return; } @@ -789,12 +858,41 @@ carp_send_ad_error(struct carp_softc *sc, int error) } } +/* + * Pick the best ifaddr on the given ifp for sending CARP + * advertisements. + * + * "Best" here is defined by ifa_preferred(). This function is much + * much like ifaof_ifpforaddr() except that we just use ifa_preferred(). + * + * (This could be simplified to return the actual address, except that + * it has a different format in AF_INET and AF_INET6.) + */ +static struct ifaddr * +carp_best_ifa(int af, struct ifnet *ifp) +{ + struct ifaddr *ifa, *best; + + if (af >= AF_MAX) + return (NULL); + best = NULL; + IF_ADDR_RLOCK(ifp); + TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) { + if (ifa->ifa_addr->sa_family == af && + (best == NULL || ifa_preferred(best, ifa))) + best = ifa; + } + IF_ADDR_RUNLOCK(ifp); + if (best != NULL) + ifa_ref(best); + return (best); +} + static void carp_send_ad_locked(struct carp_softc *sc) { struct carp_header ch; struct timeval tv; - struct sockaddr sa; struct ifaddr *ifa; struct carp_header *ch_ptr; struct mbuf *m; @@ -843,9 +941,7 @@ carp_send_ad_locked(struct carp_softc *sc) ip->ip_sum = 0; ip_fillid(ip); - bzero(&sa, sizeof(sa)); - sa.sa_family = AF_INET; - ifa = ifaof_ifpforaddr(&sa, sc->sc_carpdev); + ifa = carp_best_ifa(AF_INET, sc->sc_carpdev); if (ifa != NULL) { ip->ip_src.s_addr = ifatoia(ifa)->ia_addr.sin_addr.s_addr; @@ -889,11 +985,9 @@ carp_send_ad_locked(struct carp_softc *sc) ip6->ip6_vfc |= IPV6_VERSION; ip6->ip6_hlim = CARP_DFLTTL; ip6->ip6_nxt = IPPROTO_CARP; - bzero(&sa, sizeof(sa)); /* set the source address */ - sa.sa_family = AF_INET6; - ifa = ifaof_ifpforaddr(&sa, sc->sc_carpdev); + ifa = carp_best_ifa(AF_INET6, sc->sc_carpdev); if (ifa != NULL) { bcopy(IFA_IN6(ifa), &ip6->ip6_src, sizeof(struct in6_addr)); diff --git a/freebsd/sys/netinet/ip_fastfwd.c b/freebsd/sys/netinet/ip_fastfwd.c index bc4d70b4..1d948781 100644 --- a/freebsd/sys/netinet/ip_fastfwd.c +++ b/freebsd/sys/netinet/ip_fastfwd.c @@ -402,8 +402,9 @@ passout: */ m_clrprotoflags(m); - IP_PROBE(send, NULL, NULL, ip, nh.nh_ifp, - ip, NULL); + IP_PROBE(send, NULL, NULL, + mtod(m, struct ip *), nh.nh_ifp, + mtod(m, struct ip *), NULL); /* XXX: we can use cached route here */ error = (*nh.nh_ifp->if_output)(nh.nh_ifp, m, (struct sockaddr *)&dst, NULL); diff --git a/freebsd/sys/netinet/ip_icmp.c b/freebsd/sys/netinet/ip_icmp.c index a1331cac..b1816458 100644 --- a/freebsd/sys/netinet/ip_icmp.c +++ b/freebsd/sys/netinet/ip_icmp.c @@ -975,44 +975,59 @@ ip_next_mtu(int mtu, int dir) * the 'final' error, but it doesn't make sense to solve the printing * delay with more complex code. */ +struct icmp_rate { + const char *descr; + struct counter_rate cr; +}; +static VNET_DEFINE(struct icmp_rate, icmp_rates[BANDLIM_MAX]) = { + { "icmp unreach response" }, + { "icmp ping response" }, + { "icmp tstamp response" }, + { "closed port RST response" }, + { "open port RST response" }, + { "icmp6 unreach response" }, + { "sctp ootb response" } +}; +#define V_icmp_rates VNET(icmp_rates) + +static void +icmp_bandlimit_init(void) +{ + + for (int i = 0; i < BANDLIM_MAX; i++) { + V_icmp_rates[i].cr.cr_rate = counter_u64_alloc(M_WAITOK); + V_icmp_rates[i].cr.cr_ticks = ticks; + } +} +VNET_SYSINIT(icmp_bandlimit, SI_SUB_PROTO_DOMAIN, SI_ORDER_ANY, + icmp_bandlimit_init, NULL); + +static void +icmp_bandlimit_uninit(void) +{ + + for (int i = 0; i < BANDLIM_MAX; i++) + counter_u64_free(V_icmp_rates[i].cr.cr_rate); +} +VNET_SYSUNINIT(icmp_bandlimit, SI_SUB_PROTO_DOMAIN, SI_ORDER_THIRD, + icmp_bandlimit_uninit, NULL); int badport_bandlim(int which) { + int64_t pps; -#define N(a) (sizeof (a) / sizeof (a[0])) - static struct rate { - const char *type; - struct timeval lasttime; - int curpps; - } rates[BANDLIM_MAX+1] = { - { "icmp unreach response" }, - { "icmp ping response" }, - { "icmp tstamp response" }, - { "closed port RST response" }, - { "open port RST response" }, - { "icmp6 unreach response" }, - { "sctp ootb response" } - }; + if (V_icmplim == 0 || which == BANDLIM_UNLIMITED) + return (0); - /* - * Return ok status if feature disabled or argument out of range. - */ - if (V_icmplim > 0 && (u_int) which < N(rates)) { - struct rate *r = &rates[which]; - int opps = r->curpps; + KASSERT(which >= 0 && which < BANDLIM_MAX, + ("%s: which %d", __func__, which)); - if (!ppsratecheck(&r->lasttime, &r->curpps, V_icmplim)) - return -1; /* discard packet */ - /* - * If we've dropped below the threshold after having - * rate-limited traffic print the message. This preserves - * the previous behaviour at the expense of added complexity. - */ - if (V_icmplim_output && opps > V_icmplim) - log(LOG_NOTICE, "Limiting %s from %d to %d packets/sec\n", - r->type, opps, V_icmplim); - } - return 0; /* okay to send packet */ -#undef N + pps = counter_ratecheck(&V_icmp_rates[which].cr, V_icmplim); + if (pps == -1) + return (-1); + if (pps > 0 && V_icmplim_output) + log(LOG_NOTICE, "Limiting %s from %jd to %d packets/sec\n", + V_icmp_rates[which].descr, (intmax_t )pps, V_icmplim); + return (0); } diff --git a/freebsd/sys/netinet/ip_input.c b/freebsd/sys/netinet/ip_input.c index a2278616..9061d41b 100644 --- a/freebsd/sys/netinet/ip_input.c +++ b/freebsd/sys/netinet/ip_input.c @@ -552,24 +552,35 @@ tooshort: m_adj(m, ip_len - m->m_pkthdr.len); } - /* Try to forward the packet, but if we fail continue */ + /* + * Try to forward the packet, but if we fail continue. + * ip_tryforward() does inbound and outbound packet firewall + * processing. If firewall has decided that destination becomes + * our local address, it sets M_FASTFWD_OURS flag. In this + * case skip another inbound firewall processing and update + * ip pointer. + */ + if (V_ipforwarding != 0 #ifdef IPSEC - /* For now we do not handle IPSEC in tryforward. */ - if (!key_havesp(IPSEC_DIR_INBOUND) && !key_havesp(IPSEC_DIR_OUTBOUND) && - (V_ipforwarding == 1)) - if (ip_tryforward(m) == NULL) + && !key_havesp(IPSEC_DIR_INBOUND) + && !key_havesp(IPSEC_DIR_OUTBOUND) +#endif + ) { + if ((m = ip_tryforward(m)) == NULL) return; + if (m->m_flags & M_FASTFWD_OURS) { + m->m_flags &= ~M_FASTFWD_OURS; + ip = mtod(m, struct ip *); + goto ours; + } + } +#ifdef IPSEC /* * Bypass packet filtering for packets previously handled by IPsec. */ if (ip_ipsec_filtertunnel(m)) goto passin; -#else - if (V_ipforwarding == 1) - if (ip_tryforward(m) == NULL) - return; -#endif /* IPSEC */ - +#endif /* * Run through list of hooks for input packets. * diff --git a/freebsd/sys/netinet/ip_output.c b/freebsd/sys/netinet/ip_output.c index 5436ea2d..541acb2f 100644 --- a/freebsd/sys/netinet/ip_output.c +++ b/freebsd/sys/netinet/ip_output.c @@ -698,7 +698,8 @@ sendit: */ m_clrprotoflags(m); - IP_PROBE(send, NULL, NULL, ip, ifp, ip, NULL); + IP_PROBE(send, NULL, NULL, mtod(m, struct ip *), ifp, + mtod(m, struct ip *), NULL); error = (*ifp->if_output)(ifp, m, (const struct sockaddr *)gw, ro); } else diff --git a/freebsd/sys/netinet/sctp_asconf.c b/freebsd/sys/netinet/sctp_asconf.c index 5d86e520..04a813d3 100644 --- a/freebsd/sys/netinet/sctp_asconf.c +++ b/freebsd/sys/netinet/sctp_asconf.c @@ -99,7 +99,7 @@ sctp_asconf_success_response(uint32_t id) } static struct mbuf * -sctp_asconf_error_response(uint32_t id, uint16_t cause, uint8_t * error_tlv, +sctp_asconf_error_response(uint32_t id, uint16_t cause, uint8_t *error_tlv, uint16_t tlv_length) { struct mbuf *m_reply = NULL; @@ -134,7 +134,7 @@ sctp_asconf_error_response(uint32_t id, uint16_t cause, uint8_t * error_tlv, return (NULL); } if (error_tlv != NULL) { - tlv = (uint8_t *) (error + 1); + tlv = (uint8_t *)(error + 1); memcpy(tlv, error_tlv, tlv_length); } SCTP_BUF_LEN(m_reply) = aph->ph.param_length; @@ -224,7 +224,7 @@ sctp_process_asconf_add_ip(struct sockaddr *src, struct sctp_asconf_paramhdr *ap #endif default: m_reply = sctp_asconf_error_response(aph->correlation_id, - SCTP_CAUSE_INVALID_PARAM, (uint8_t *) aph, + SCTP_CAUSE_INVALID_PARAM, (uint8_t *)aph, aparam_length); return (m_reply); } /* end switch */ @@ -239,7 +239,7 @@ sctp_process_asconf_add_ip(struct sockaddr *src, struct sctp_asconf_paramhdr *ap /* add the address */ if (bad_address) { m_reply = sctp_asconf_error_response(aph->correlation_id, - SCTP_CAUSE_INVALID_PARAM, (uint8_t *) aph, + SCTP_CAUSE_INVALID_PARAM, (uint8_t *)aph, aparam_length); } else if (sctp_add_remote_addr(stcb, sa, &net, stcb->asoc.port, SCTP_DONOT_SETSCOPE, @@ -247,7 +247,7 @@ sctp_process_asconf_add_ip(struct sockaddr *src, struct sctp_asconf_paramhdr *ap SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_add_ip: error adding address\n"); m_reply = sctp_asconf_error_response(aph->correlation_id, - SCTP_CAUSE_RESOURCE_SHORTAGE, (uint8_t *) aph, + SCTP_CAUSE_RESOURCE_SHORTAGE, (uint8_t *)aph, aparam_length); } else { /* notify upper layer */ @@ -369,7 +369,7 @@ sctp_process_asconf_delete_ip(struct sockaddr *src, #endif default: m_reply = sctp_asconf_error_response(aph->correlation_id, - SCTP_CAUSE_UNRESOLVABLE_ADDR, (uint8_t *) aph, + SCTP_CAUSE_UNRESOLVABLE_ADDR, (uint8_t *)aph, aparam_length); return (m_reply); } @@ -379,7 +379,7 @@ sctp_process_asconf_delete_ip(struct sockaddr *src, /* trying to delete the source address! */ SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_delete_ip: tried to delete source addr\n"); m_reply = sctp_asconf_error_response(aph->correlation_id, - SCTP_CAUSE_DELETING_SRC_ADDR, (uint8_t *) aph, + SCTP_CAUSE_DELETING_SRC_ADDR, (uint8_t *)aph, aparam_length); return (m_reply); } @@ -393,7 +393,7 @@ sctp_process_asconf_delete_ip(struct sockaddr *src, /* what error to reply with?? */ m_reply = sctp_asconf_error_response(aph->correlation_id, - SCTP_CAUSE_REQUEST_REFUSED, (uint8_t *) aph, + SCTP_CAUSE_REQUEST_REFUSED, (uint8_t *)aph, aparam_length); } else if (response_required) { m_reply = @@ -412,7 +412,7 @@ sctp_process_asconf_delete_ip(struct sockaddr *src, /* only one address in the asoc */ SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_delete_ip: tried to delete last IP addr!\n"); m_reply = sctp_asconf_error_response(aph->correlation_id, - SCTP_CAUSE_DELETING_LAST_ADDR, (uint8_t *) aph, + SCTP_CAUSE_DELETING_LAST_ADDR, (uint8_t *)aph, aparam_length); } else { if (response_required) { @@ -494,7 +494,7 @@ sctp_process_asconf_set_primary(struct sockaddr *src, #endif default: m_reply = sctp_asconf_error_response(aph->correlation_id, - SCTP_CAUSE_UNRESOLVABLE_ADDR, (uint8_t *) aph, + SCTP_CAUSE_UNRESOLVABLE_ADDR, (uint8_t *)aph, aparam_length); return (m_reply); } @@ -565,7 +565,7 @@ sctp_process_asconf_set_primary(struct sockaddr *src, "process_asconf_set_primary: set primary failed!\n"); /* must have been an invalid address, so report */ m_reply = sctp_asconf_error_response(aph->correlation_id, - SCTP_CAUSE_UNRESOLVABLE_ADDR, (uint8_t *) aph, + SCTP_CAUSE_UNRESOLVABLE_ADDR, (uint8_t *)aph, aparam_length); } @@ -660,7 +660,7 @@ sctp_handle_asconf(struct mbuf *m, unsigned int offset, /* skip the lookup address parameter */ offset += sizeof(struct sctp_asconf_chunk); - p_addr = (struct sctp_ipv6addr_param *)sctp_m_getptr(m, offset, sizeof(struct sctp_paramhdr), (uint8_t *) & aparam_buf); + p_addr = (struct sctp_ipv6addr_param *)sctp_m_getptr(m, offset, sizeof(struct sctp_paramhdr), (uint8_t *)&aparam_buf); if (p_addr == NULL) { SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: couldn't get lookup addr!\n"); @@ -670,7 +670,7 @@ sctp_handle_asconf(struct mbuf *m, unsigned int offset, /* param_length is already validated in process_control... */ offset += ntohs(p_addr->ph.param_length); /* skip lookup addr */ /* get pointer to first asconf param in ASCONF */ - aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, sizeof(struct sctp_asconf_paramhdr), (uint8_t *) & aparam_buf); + aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, sizeof(struct sctp_asconf_paramhdr), (uint8_t *)&aparam_buf); if (aph == NULL) { SCTPDBG(SCTP_DEBUG_ASCONF1, "Empty ASCONF received?\n"); goto send_reply; @@ -767,7 +767,7 @@ sctp_handle_asconf(struct mbuf *m, unsigned int offset, /* get pointer to next asconf param */ aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, sizeof(struct sctp_asconf_paramhdr), - (uint8_t *) & aparam_buf); + (uint8_t *)&aparam_buf); if (aph == NULL) { /* can't get an asconf paramhdr */ SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: can't get asconf param hdr!\n"); @@ -1096,7 +1096,7 @@ sctp_path_check_and_react(struct sctp_tcb *stcb, struct sctp_ifa *newifa) * NOT corresponding to the current nexthop, the path will * not be changed. */ - SCTP_RTALLOC((sctp_route_t *) & net->ro, + SCTP_RTALLOC((sctp_route_t *)&net->ro, stcb->sctp_ep->def_vrf_id, stcb->sctp_ep->fibnum); if (net->ro.ro_rt == NULL) @@ -1106,7 +1106,7 @@ sctp_path_check_and_react(struct sctp_tcb *stcb, struct sctp_ifa *newifa) switch (net->ro._l_addr.sa.sa_family) { #ifdef INET case AF_INET: - if (sctp_v4src_match_nexthop(newifa, (sctp_route_t *) & net->ro)) { + if (sctp_v4src_match_nexthop(newifa, (sctp_route_t *)&net->ro)) { changed = 1; } break; @@ -1114,7 +1114,7 @@ sctp_path_check_and_react(struct sctp_tcb *stcb, struct sctp_ifa *newifa) #ifdef INET6 case AF_INET6: if (sctp_v6src_match_nexthop( - &newifa->address.sin6, (sctp_route_t *) & net->ro)) { + &newifa->address.sin6, (sctp_route_t *)&net->ro)) { changed = 1; } break; @@ -2421,8 +2421,10 @@ sctp_is_addr_pending(struct sctp_tcb *stcb, struct sctp_ifa *sctp_ifa) } } - /* we want to find the sequences which consist of ADD -> DEL -> ADD - * or DEL -> ADD */ + /* + * we want to find the sequences which consist of ADD -> DEL -> ADD + * or DEL -> ADD + */ if (add_cnt > del_cnt || (add_cnt == del_cnt && last_param_type == SCTP_ADD_IP_ADDRESS)) { return (1); @@ -2474,8 +2476,10 @@ sctp_find_valid_localaddr(struct sctp_tcb *stcb, int addr_locked) if (sctp_is_addr_restricted(stcb, sctp_ifa) && (!sctp_is_addr_pending(stcb, sctp_ifa))) continue; - /* found a valid local v4 address to - * use */ + /* + * found a valid local v4 address to + * use + */ if (addr_locked == SCTP_ADDR_NOT_LOCKED) SCTP_IPI_ADDR_RUNLOCK(); return (&sctp_ifa->address.sa); @@ -2492,8 +2496,10 @@ sctp_find_valid_localaddr(struct sctp_tcb *stcb, int addr_locked) } sin6 = &sctp_ifa->address.sin6; if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) { - /* we skip unspecifed - * addresses */ + /* + * we skip unspecifed + * addresses + */ continue; } if (prison_check_ip6(stcb->sctp_ep->ip_inp.inp.inp_cred, @@ -2510,8 +2516,10 @@ sctp_find_valid_localaddr(struct sctp_tcb *stcb, int addr_locked) if (sctp_is_addr_restricted(stcb, sctp_ifa) && (!sctp_is_addr_pending(stcb, sctp_ifa))) continue; - /* found a valid local v6 address to - * use */ + /* + * found a valid local v6 address to + * use + */ if (addr_locked == SCTP_ADDR_NOT_LOCKED) SCTP_IPI_ADDR_RUNLOCK(); return (&sctp_ifa->address.sa); @@ -2779,7 +2787,7 @@ sctp_process_initack_addresses(struct sctp_tcb *stcb, struct mbuf *m, /* go through the addresses in the init-ack */ ph = (struct sctp_paramhdr *) sctp_m_getptr(m, offset, sizeof(struct sctp_paramhdr), - (uint8_t *) & tmp_param); + (uint8_t *)&tmp_param); while (ph != NULL) { ptype = ntohs(ph->param_type); plen = ntohs(ph->param_length); @@ -2793,7 +2801,7 @@ sctp_process_initack_addresses(struct sctp_tcb *stcb, struct mbuf *m, a6p = (struct sctp_ipv6addr_param *) sctp_m_getptr(m, offset, sizeof(struct sctp_ipv6addr_param), - (uint8_t *) & addr6_store); + (uint8_t *)&addr6_store); if (plen != sizeof(struct sctp_ipv6addr_param) || a6p == NULL) { return; @@ -2814,7 +2822,7 @@ sctp_process_initack_addresses(struct sctp_tcb *stcb, struct mbuf *m, /* get the entire IPv4 address param */ a4p = (struct sctp_ipv4addr_param *)sctp_m_getptr(m, offset, sizeof(struct sctp_ipv4addr_param), - (uint8_t *) & addr4_store); + (uint8_t *)&addr4_store); if (plen != sizeof(struct sctp_ipv4addr_param) || a4p == NULL) { return; @@ -2876,7 +2884,7 @@ next_addr: if ((offset + sizeof(struct sctp_paramhdr)) > length) return; ph = (struct sctp_paramhdr *)sctp_m_getptr(m, offset, - sizeof(struct sctp_paramhdr), (uint8_t *) & tmp_param); + sizeof(struct sctp_paramhdr), (uint8_t *)&tmp_param); } /* while */ } @@ -2927,7 +2935,7 @@ sctp_addr_in_initack(struct mbuf *m, uint32_t offset, uint32_t length, struct so } /* go through the addresses in the init-ack */ ph = (struct sctp_paramhdr *)sctp_m_getptr(m, offset, - sizeof(struct sctp_paramhdr), (uint8_t *) & tmp_param); + sizeof(struct sctp_paramhdr), (uint8_t *)&tmp_param); while (ph != NULL) { ptype = ntohs(ph->param_type); plen = ntohs(ph->param_length); @@ -2943,7 +2951,7 @@ sctp_addr_in_initack(struct mbuf *m, uint32_t offset, uint32_t length, struct so a6p = (struct sctp_ipv6addr_param *) sctp_m_getptr(m, offset, sizeof(struct sctp_ipv6addr_param), - (uint8_t *) & addr6_store); + (uint8_t *)&addr6_store); if (a6p == NULL) { return (0); } @@ -2973,7 +2981,7 @@ sctp_addr_in_initack(struct mbuf *m, uint32_t offset, uint32_t length, struct so a4p = (struct sctp_ipv4addr_param *) sctp_m_getptr(m, offset, sizeof(struct sctp_ipv4addr_param), - (uint8_t *) & addr4_store); + (uint8_t *)&addr4_store); if (a4p == NULL) { return (0); } @@ -2995,7 +3003,7 @@ sctp_addr_in_initack(struct mbuf *m, uint32_t offset, uint32_t length, struct so } ph = (struct sctp_paramhdr *) sctp_m_getptr(m, offset, sizeof(struct sctp_paramhdr), - (uint8_t *) & tmp_param); + (uint8_t *)&tmp_param); } /* while */ /* not found! */ return (0); diff --git a/freebsd/sys/netinet/sctp_auth.c b/freebsd/sys/netinet/sctp_auth.c index 19e30718..4bcb2459 100644 --- a/freebsd/sys/netinet/sctp_auth.c +++ b/freebsd/sys/netinet/sctp_auth.c @@ -53,7 +53,7 @@ __FBSDID("$FreeBSD$"); void -sctp_clear_chunklist(sctp_auth_chklist_t * chklist) +sctp_clear_chunklist(sctp_auth_chklist_t *chklist) { bzero(chklist, sizeof(*chklist)); /* chklist->num_chunks = 0; */ @@ -75,14 +75,14 @@ sctp_alloc_chunklist(void) } void -sctp_free_chunklist(sctp_auth_chklist_t * list) +sctp_free_chunklist(sctp_auth_chklist_t *list) { if (list != NULL) SCTP_FREE(list, SCTP_M_AUTH_CL); } sctp_auth_chklist_t * -sctp_copy_chunklist(sctp_auth_chklist_t * list) +sctp_copy_chunklist(sctp_auth_chklist_t *list) { sctp_auth_chklist_t *new_list; @@ -104,7 +104,7 @@ sctp_copy_chunklist(sctp_auth_chklist_t * list) * add a chunk to the required chunks list */ int -sctp_auth_add_chunk(uint8_t chunk, sctp_auth_chklist_t * list) +sctp_auth_add_chunk(uint8_t chunk, sctp_auth_chklist_t *list) { if (list == NULL) return (-1); @@ -130,7 +130,7 @@ sctp_auth_add_chunk(uint8_t chunk, sctp_auth_chklist_t * list) * delete a chunk from the required chunks list */ int -sctp_auth_delete_chunk(uint8_t chunk, sctp_auth_chklist_t * list) +sctp_auth_delete_chunk(uint8_t chunk, sctp_auth_chklist_t *list) { if (list == NULL) return (-1); @@ -146,7 +146,7 @@ sctp_auth_delete_chunk(uint8_t chunk, sctp_auth_chklist_t * list) } size_t -sctp_auth_get_chklist_size(const sctp_auth_chklist_t * list) +sctp_auth_get_chklist_size(const sctp_auth_chklist_t *list) { if (list == NULL) return (0); @@ -159,7 +159,7 @@ sctp_auth_get_chklist_size(const sctp_auth_chklist_t * list) * guarantee ptr has space for up to 256 bytes */ int -sctp_serialize_auth_chunks(const sctp_auth_chklist_t * list, uint8_t * ptr) +sctp_serialize_auth_chunks(const sctp_auth_chklist_t *list, uint8_t *ptr) { int i, count = 0; @@ -176,7 +176,7 @@ sctp_serialize_auth_chunks(const sctp_auth_chklist_t * list, uint8_t * ptr) } int -sctp_pack_auth_chunks(const sctp_auth_chklist_t * list, uint8_t * ptr) +sctp_pack_auth_chunks(const sctp_auth_chklist_t *list, uint8_t *ptr) { int i, size = 0; @@ -208,8 +208,8 @@ sctp_pack_auth_chunks(const sctp_auth_chklist_t * list, uint8_t * ptr) } int -sctp_unpack_auth_chunks(const uint8_t * ptr, uint8_t num_chunks, - sctp_auth_chklist_t * list) +sctp_unpack_auth_chunks(const uint8_t *ptr, uint8_t num_chunks, + sctp_auth_chklist_t *list) { int i; int size; @@ -259,14 +259,14 @@ sctp_alloc_key(uint32_t keylen) } void -sctp_free_key(sctp_key_t * key) +sctp_free_key(sctp_key_t *key) { if (key != NULL) SCTP_FREE(key, SCTP_M_AUTH_KY); } void -sctp_print_key(sctp_key_t * key, const char *str) +sctp_print_key(sctp_key_t *key, const char *str) { uint32_t i; @@ -285,7 +285,7 @@ sctp_print_key(sctp_key_t * key, const char *str) } void -sctp_show_key(sctp_key_t * key, const char *str) +sctp_show_key(sctp_key_t *key, const char *str) { uint32_t i; @@ -304,7 +304,7 @@ sctp_show_key(sctp_key_t * key, const char *str) } static uint32_t -sctp_get_keylen(sctp_key_t * key) +sctp_get_keylen(sctp_key_t *key) { if (key != NULL) return (key->keylen); @@ -331,7 +331,7 @@ sctp_generate_random_key(uint32_t keylen) } sctp_key_t * -sctp_set_key(uint8_t * key, uint32_t keylen) +sctp_set_key(uint8_t *key, uint32_t keylen) { sctp_key_t *new_key; @@ -351,7 +351,7 @@ sctp_set_key(uint8_t * key, uint32_t keylen) * 0 if key1 = key2 */ static int -sctp_compare_key(sctp_key_t * key1, sctp_key_t * key2) +sctp_compare_key(sctp_key_t *key1, sctp_key_t *key2) { uint32_t maxlen; uint32_t i; @@ -402,7 +402,7 @@ sctp_compare_key(sctp_key_t * key1, sctp_key_t * key2) * order for concatenation */ sctp_key_t * -sctp_compute_hashkey(sctp_key_t * key1, sctp_key_t * key2, sctp_key_t * shared) +sctp_compute_hashkey(sctp_key_t *key1, sctp_key_t *key2, sctp_key_t *shared) { uint32_t keylen; sctp_key_t *new_key; @@ -476,7 +476,7 @@ sctp_alloc_sharedkey(void) } void -sctp_free_sharedkey(sctp_sharedkey_t * skey) +sctp_free_sharedkey(sctp_sharedkey_t *skey) { if (skey == NULL) return; @@ -502,7 +502,7 @@ sctp_find_sharedkey(struct sctp_keyhead *shared_keys, uint16_t key_id) int sctp_insert_sharedkey(struct sctp_keyhead *shared_keys, - sctp_sharedkey_t * new_skey) + sctp_sharedkey_t *new_skey) { sctp_sharedkey_t *skey; @@ -596,7 +596,7 @@ sctp_auth_key_release(struct sctp_tcb *stcb, uint16_t key_id, int so_locked } static sctp_sharedkey_t * -sctp_copy_sharedkey(const sctp_sharedkey_t * skey) +sctp_copy_sharedkey(const sctp_sharedkey_t *skey) { sctp_sharedkey_t *new_skey; @@ -654,7 +654,7 @@ sctp_alloc_hmaclist(uint16_t num_hmacs) } void -sctp_free_hmaclist(sctp_hmaclist_t * list) +sctp_free_hmaclist(sctp_hmaclist_t *list) { if (list != NULL) { SCTP_FREE(list, SCTP_M_AUTH_HL); @@ -663,7 +663,7 @@ sctp_free_hmaclist(sctp_hmaclist_t * list) } int -sctp_auth_add_hmacid(sctp_hmaclist_t * list, uint16_t hmac_id) +sctp_auth_add_hmacid(sctp_hmaclist_t *list, uint16_t hmac_id) { int i; @@ -691,7 +691,7 @@ sctp_auth_add_hmacid(sctp_hmaclist_t * list, uint16_t hmac_id) } sctp_hmaclist_t * -sctp_copy_hmaclist(sctp_hmaclist_t * list) +sctp_copy_hmaclist(sctp_hmaclist_t *list) { sctp_hmaclist_t *new_list; int i; @@ -729,7 +729,7 @@ sctp_default_supported_hmaclist(void) * find the best HMAC id to use for the peer based on local support */ uint16_t -sctp_negotiate_hmacid(sctp_hmaclist_t * peer, sctp_hmaclist_t * local) +sctp_negotiate_hmacid(sctp_hmaclist_t *peer, sctp_hmaclist_t *local) { int i, j; @@ -756,7 +756,7 @@ sctp_negotiate_hmacid(sctp_hmaclist_t * peer, sctp_hmaclist_t * local) * caller must guarantee ptr has appropriate space */ int -sctp_serialize_hmaclist(sctp_hmaclist_t * list, uint8_t * ptr) +sctp_serialize_hmaclist(sctp_hmaclist_t *list, uint8_t *ptr) { int i; uint16_t hmac_id; @@ -802,7 +802,7 @@ sctp_alloc_authinfo(void) } void -sctp_free_authinfo(sctp_authinfo_t * authinfo) +sctp_free_authinfo(sctp_authinfo_t *authinfo) { if (authinfo == NULL) return; @@ -860,7 +860,7 @@ sctp_get_hmac_block_len(uint16_t hmac_algo) } static void -sctp_hmac_init(uint16_t hmac_algo, sctp_hash_context_t * ctx) +sctp_hmac_init(uint16_t hmac_algo, sctp_hash_context_t *ctx) { switch (hmac_algo) { case SCTP_AUTH_HMAC_ID_SHA1: @@ -877,8 +877,8 @@ sctp_hmac_init(uint16_t hmac_algo, sctp_hash_context_t * ctx) } static void -sctp_hmac_update(uint16_t hmac_algo, sctp_hash_context_t * ctx, - uint8_t * text, uint32_t textlen) +sctp_hmac_update(uint16_t hmac_algo, sctp_hash_context_t *ctx, + uint8_t *text, uint32_t textlen) { switch (hmac_algo) { case SCTP_AUTH_HMAC_ID_SHA1: @@ -895,8 +895,8 @@ sctp_hmac_update(uint16_t hmac_algo, sctp_hash_context_t * ctx, } static void -sctp_hmac_final(uint16_t hmac_algo, sctp_hash_context_t * ctx, - uint8_t * digest) +sctp_hmac_final(uint16_t hmac_algo, sctp_hash_context_t *ctx, + uint8_t *digest) { switch (hmac_algo) { case SCTP_AUTH_HMAC_ID_SHA1: @@ -923,8 +923,8 @@ sctp_hmac_final(uint16_t hmac_algo, sctp_hash_context_t * ctx, * resultant digest. */ uint32_t -sctp_hmac(uint16_t hmac_algo, uint8_t * key, uint32_t keylen, - uint8_t * text, uint32_t textlen, uint8_t * digest) +sctp_hmac(uint16_t hmac_algo, uint8_t *key, uint32_t keylen, + uint8_t *text, uint32_t textlen, uint8_t *digest) { uint32_t digestlen; uint32_t blocklen; @@ -983,8 +983,8 @@ sctp_hmac(uint16_t hmac_algo, uint8_t * key, uint32_t keylen, /* mbuf version */ uint32_t -sctp_hmac_m(uint16_t hmac_algo, uint8_t * key, uint32_t keylen, - struct mbuf *m, uint32_t m_offset, uint8_t * digest, uint32_t trailer) +sctp_hmac_m(uint16_t hmac_algo, uint8_t *key, uint32_t keylen, + struct mbuf *m, uint32_t m_offset, uint8_t *digest, uint32_t trailer) { uint32_t digestlen; uint32_t blocklen; @@ -1031,17 +1031,17 @@ sctp_hmac_m(uint16_t hmac_algo, uint8_t * key, uint32_t keylen, sctp_hmac_update(hmac_algo, &ctx, ipad, blocklen); /* find the correct starting mbuf and offset (get start of text) */ m_tmp = m; - while ((m_tmp != NULL) && (m_offset >= (uint32_t) SCTP_BUF_LEN(m_tmp))) { + while ((m_tmp != NULL) && (m_offset >= (uint32_t)SCTP_BUF_LEN(m_tmp))) { m_offset -= SCTP_BUF_LEN(m_tmp); m_tmp = SCTP_BUF_NEXT(m_tmp); } /* now use the rest of the mbuf chain for the text */ while (m_tmp != NULL) { if ((SCTP_BUF_NEXT(m_tmp) == NULL) && trailer) { - sctp_hmac_update(hmac_algo, &ctx, mtod(m_tmp, uint8_t *) + m_offset, + sctp_hmac_update(hmac_algo, &ctx, mtod(m_tmp, uint8_t *)+m_offset, SCTP_BUF_LEN(m_tmp) - (trailer + m_offset)); } else { - sctp_hmac_update(hmac_algo, &ctx, mtod(m_tmp, uint8_t *) + m_offset, + sctp_hmac_update(hmac_algo, &ctx, mtod(m_tmp, uint8_t *)+m_offset, SCTP_BUF_LEN(m_tmp) - m_offset); } @@ -1066,9 +1066,9 @@ sctp_hmac_m(uint16_t hmac_algo, uint8_t * key, uint32_t keylen, * Returns -1 on error, 0 on success. */ int -sctp_verify_hmac(uint16_t hmac_algo, uint8_t * key, uint32_t keylen, - uint8_t * text, uint32_t textlen, - uint8_t * digest, uint32_t digestlen) +sctp_verify_hmac(uint16_t hmac_algo, uint8_t *key, uint32_t keylen, + uint8_t *text, uint32_t textlen, + uint8_t *digest, uint32_t digestlen) { uint32_t len; uint8_t temp[SCTP_AUTH_DIGEST_LEN_MAX]; @@ -1099,8 +1099,8 @@ sctp_verify_hmac(uint16_t hmac_algo, uint8_t * key, uint32_t keylen, * the keylen exceeds the HMAC block len). */ uint32_t -sctp_compute_hmac(uint16_t hmac_algo, sctp_key_t * key, uint8_t * text, - uint32_t textlen, uint8_t * digest) +sctp_compute_hmac(uint16_t hmac_algo, sctp_key_t *key, uint8_t *text, + uint32_t textlen, uint8_t *digest) { uint32_t digestlen; uint32_t blocklen; @@ -1134,8 +1134,8 @@ sctp_compute_hmac(uint16_t hmac_algo, sctp_key_t * key, uint8_t * text, /* mbuf version */ uint32_t -sctp_compute_hmac_m(uint16_t hmac_algo, sctp_key_t * key, struct mbuf *m, - uint32_t m_offset, uint8_t * digest) +sctp_compute_hmac_m(uint16_t hmac_algo, sctp_key_t *key, struct mbuf *m, + uint32_t m_offset, uint8_t *digest) { uint32_t digestlen; uint32_t blocklen; @@ -1166,7 +1166,7 @@ sctp_compute_hmac_m(uint16_t hmac_algo, sctp_key_t * key, struct mbuf *m, } int -sctp_auth_is_supported_hmac(sctp_hmaclist_t * list, uint16_t id) +sctp_auth_is_supported_hmac(sctp_hmaclist_t *list, uint16_t id) { int i; @@ -1424,7 +1424,7 @@ sctp_auth_get_cookie_params(struct sctp_tcb *stcb, struct mbuf *m, length += offset; phdr = (struct sctp_paramhdr *)sctp_m_getptr(m, offset, - sizeof(struct sctp_paramhdr), (uint8_t *) & tmp_param); + sizeof(struct sctp_paramhdr), (uint8_t *)&tmp_param); while (phdr != NULL) { ptype = ntohs(phdr->param_type); plen = ntohs(phdr->param_length); @@ -1491,7 +1491,7 @@ sctp_auth_get_cookie_params(struct sctp_tcb *stcb, struct mbuf *m, if (offset + sizeof(struct sctp_paramhdr) > length) break; phdr = (struct sctp_paramhdr *)sctp_m_getptr(m, offset, sizeof(struct sctp_paramhdr), - (uint8_t *) & tmp_param); + (uint8_t *)&tmp_param); } /* concatenate the full random key */ keylen = sizeof(*p_random) + random_len + sizeof(*hmacs) + hmacs_len; @@ -1601,14 +1601,14 @@ sctp_bzero_m(struct mbuf *m, uint32_t m_offset, uint32_t size) /* find the correct starting mbuf and offset (get start position) */ m_tmp = m; - while ((m_tmp != NULL) && (m_offset >= (uint32_t) SCTP_BUF_LEN(m_tmp))) { + while ((m_tmp != NULL) && (m_offset >= (uint32_t)SCTP_BUF_LEN(m_tmp))) { m_offset -= SCTP_BUF_LEN(m_tmp); m_tmp = SCTP_BUF_NEXT(m_tmp); } /* now use the rest of the mbuf chain */ while ((m_tmp != NULL) && (size > 0)) { - data = mtod(m_tmp, uint8_t *) + m_offset; - if (size > (uint32_t) SCTP_BUF_LEN(m_tmp)) { + data = mtod(m_tmp, uint8_t *)+m_offset; + if (size > (uint32_t)SCTP_BUF_LEN(m_tmp)) { bzero(data, SCTP_BUF_LEN(m_tmp)); size -= SCTP_BUF_LEN(m_tmp); } else { diff --git a/freebsd/sys/netinet/sctp_auth.h b/freebsd/sys/netinet/sctp_auth.h index b98764e2..04fd6464 100644 --- a/freebsd/sys/netinet/sctp_auth.h +++ b/freebsd/sys/netinet/sctp_auth.h @@ -51,12 +51,12 @@ __FBSDID("$FreeBSD$"); typedef union sctp_hash_context { SCTP_SHA1_CTX sha1; SCTP_SHA256_CTX sha256; -} sctp_hash_context_t; +} sctp_hash_context_t; typedef struct sctp_key { uint32_t keylen; uint8_t key[]; -} sctp_key_t; +} sctp_key_t; typedef struct sctp_shared_key { LIST_ENTRY(sctp_shared_key) next; @@ -64,7 +64,7 @@ typedef struct sctp_shared_key { uint32_t refcount; /* reference count */ uint16_t keyid; /* shared key ID */ uint8_t deactivated; /* key is deactivated */ -} sctp_sharedkey_t; +} sctp_sharedkey_t; LIST_HEAD(sctp_keyhead, sctp_shared_key); @@ -72,14 +72,14 @@ LIST_HEAD(sctp_keyhead, sctp_shared_key); typedef struct sctp_auth_chklist { uint8_t chunks[256]; uint8_t num_chunks; -} sctp_auth_chklist_t; +} sctp_auth_chklist_t; /* hmac algos supported list */ typedef struct sctp_hmaclist { uint16_t max_algo; /* max algorithms allocated */ uint16_t num_algo; /* num algorithms used */ uint16_t hmac[]; -} sctp_hmaclist_t; +} sctp_hmaclist_t; /* authentication info */ typedef struct sctp_authinformation { @@ -91,7 +91,7 @@ typedef struct sctp_authinformation { uint16_t active_keyid; /* active send keyid */ uint16_t assoc_keyid; /* current send keyid (cached) */ uint16_t recv_keyid; /* last recv keyid (cached) */ -} sctp_authinfo_t; +} sctp_authinfo_t; @@ -106,42 +106,42 @@ typedef struct sctp_authinformation { /* socket option api functions */ extern sctp_auth_chklist_t *sctp_alloc_chunklist(void); -extern void sctp_free_chunklist(sctp_auth_chklist_t * chklist); -extern void sctp_clear_chunklist(sctp_auth_chklist_t * chklist); -extern sctp_auth_chklist_t *sctp_copy_chunklist(sctp_auth_chklist_t * chklist); -extern int sctp_auth_add_chunk(uint8_t chunk, sctp_auth_chklist_t * list); -extern int sctp_auth_delete_chunk(uint8_t chunk, sctp_auth_chklist_t * list); -extern size_t sctp_auth_get_chklist_size(const sctp_auth_chklist_t * list); +extern void sctp_free_chunklist(sctp_auth_chklist_t *chklist); +extern void sctp_clear_chunklist(sctp_auth_chklist_t *chklist); +extern sctp_auth_chklist_t *sctp_copy_chunklist(sctp_auth_chklist_t *chklist); +extern int sctp_auth_add_chunk(uint8_t chunk, sctp_auth_chklist_t *list); +extern int sctp_auth_delete_chunk(uint8_t chunk, sctp_auth_chklist_t *list); +extern size_t sctp_auth_get_chklist_size(const sctp_auth_chklist_t *list); extern int -sctp_serialize_auth_chunks(const sctp_auth_chklist_t * list, - uint8_t * ptr); +sctp_serialize_auth_chunks(const sctp_auth_chklist_t *list, + uint8_t *ptr); extern int -sctp_pack_auth_chunks(const sctp_auth_chklist_t * list, - uint8_t * ptr); +sctp_pack_auth_chunks(const sctp_auth_chklist_t *list, + uint8_t *ptr); extern int -sctp_unpack_auth_chunks(const uint8_t * ptr, uint8_t num_chunks, - sctp_auth_chklist_t * list); +sctp_unpack_auth_chunks(const uint8_t *ptr, uint8_t num_chunks, + sctp_auth_chklist_t *list); /* key handling */ extern sctp_key_t *sctp_alloc_key(uint32_t keylen); -extern void sctp_free_key(sctp_key_t * key); -extern void sctp_print_key(sctp_key_t * key, const char *str); -extern void sctp_show_key(sctp_key_t * key, const char *str); +extern void sctp_free_key(sctp_key_t *key); +extern void sctp_print_key(sctp_key_t *key, const char *str); +extern void sctp_show_key(sctp_key_t *key, const char *str); extern sctp_key_t *sctp_generate_random_key(uint32_t keylen); -extern sctp_key_t *sctp_set_key(uint8_t * key, uint32_t keylen); +extern sctp_key_t *sctp_set_key(uint8_t *key, uint32_t keylen); extern sctp_key_t * -sctp_compute_hashkey(sctp_key_t * key1, sctp_key_t * key2, - sctp_key_t * shared); +sctp_compute_hashkey(sctp_key_t *key1, sctp_key_t *key2, + sctp_key_t *shared); /* shared key handling */ extern sctp_sharedkey_t *sctp_alloc_sharedkey(void); -extern void sctp_free_sharedkey(sctp_sharedkey_t * skey); +extern void sctp_free_sharedkey(sctp_sharedkey_t *skey); extern sctp_sharedkey_t * sctp_find_sharedkey(struct sctp_keyhead *shared_keys, uint16_t key_id); extern int sctp_insert_sharedkey(struct sctp_keyhead *shared_keys, - sctp_sharedkey_t * new_skey); + sctp_sharedkey_t *new_skey); extern int sctp_copy_skeylist(const struct sctp_keyhead *src, struct sctp_keyhead *dest); @@ -155,42 +155,42 @@ sctp_auth_key_release(struct sctp_tcb *stcb, uint16_t keyid, /* hmac list handling */ extern sctp_hmaclist_t *sctp_alloc_hmaclist(uint16_t num_hmacs); -extern void sctp_free_hmaclist(sctp_hmaclist_t * list); -extern int sctp_auth_add_hmacid(sctp_hmaclist_t * list, uint16_t hmac_id); -extern sctp_hmaclist_t *sctp_copy_hmaclist(sctp_hmaclist_t * list); +extern void sctp_free_hmaclist(sctp_hmaclist_t *list); +extern int sctp_auth_add_hmacid(sctp_hmaclist_t *list, uint16_t hmac_id); +extern sctp_hmaclist_t *sctp_copy_hmaclist(sctp_hmaclist_t *list); extern sctp_hmaclist_t *sctp_default_supported_hmaclist(void); extern uint16_t -sctp_negotiate_hmacid(sctp_hmaclist_t * peer, - sctp_hmaclist_t * local); -extern int sctp_serialize_hmaclist(sctp_hmaclist_t * list, uint8_t * ptr); +sctp_negotiate_hmacid(sctp_hmaclist_t *peer, + sctp_hmaclist_t *local); +extern int sctp_serialize_hmaclist(sctp_hmaclist_t *list, uint8_t *ptr); extern int sctp_verify_hmac_param(struct sctp_auth_hmac_algo *hmacs, uint32_t num_hmacs); extern sctp_authinfo_t *sctp_alloc_authinfo(void); -extern void sctp_free_authinfo(sctp_authinfo_t * authinfo); +extern void sctp_free_authinfo(sctp_authinfo_t *authinfo); /* keyed-HMAC functions */ extern uint32_t sctp_get_auth_chunk_len(uint16_t hmac_algo); extern uint32_t sctp_get_hmac_digest_len(uint16_t hmac_algo); extern uint32_t -sctp_hmac(uint16_t hmac_algo, uint8_t * key, uint32_t keylen, - uint8_t * text, uint32_t textlen, uint8_t * digest); +sctp_hmac(uint16_t hmac_algo, uint8_t *key, uint32_t keylen, + uint8_t *text, uint32_t textlen, uint8_t *digest); extern int -sctp_verify_hmac(uint16_t hmac_algo, uint8_t * key, uint32_t keylen, - uint8_t * text, uint32_t textlen, uint8_t * digest, uint32_t digestlen); +sctp_verify_hmac(uint16_t hmac_algo, uint8_t *key, uint32_t keylen, + uint8_t *text, uint32_t textlen, uint8_t *digest, uint32_t digestlen); extern uint32_t -sctp_compute_hmac(uint16_t hmac_algo, sctp_key_t * key, - uint8_t * text, uint32_t textlen, uint8_t * digest); -extern int sctp_auth_is_supported_hmac(sctp_hmaclist_t * list, uint16_t id); +sctp_compute_hmac(uint16_t hmac_algo, sctp_key_t *key, + uint8_t *text, uint32_t textlen, uint8_t *digest); +extern int sctp_auth_is_supported_hmac(sctp_hmaclist_t *list, uint16_t id); /* mbuf versions */ extern uint32_t -sctp_hmac_m(uint16_t hmac_algo, uint8_t * key, uint32_t keylen, - struct mbuf *m, uint32_t m_offset, uint8_t * digest, uint32_t trailer); +sctp_hmac_m(uint16_t hmac_algo, uint8_t *key, uint32_t keylen, + struct mbuf *m, uint32_t m_offset, uint8_t *digest, uint32_t trailer); extern uint32_t -sctp_compute_hmac_m(uint16_t hmac_algo, sctp_key_t * key, - struct mbuf *m, uint32_t m_offset, uint8_t * digest); +sctp_compute_hmac_m(uint16_t hmac_algo, sctp_key_t *key, + struct mbuf *m, uint32_t m_offset, uint8_t *digest); /* * authentication routines @@ -212,7 +212,7 @@ sctp_fill_hmac_digest_m(struct mbuf *m, uint32_t auth_offset, struct sctp_auth_chunk *auth, struct sctp_tcb *stcb, uint16_t key_id); extern struct mbuf * sctp_add_auth_chunk(struct mbuf *m, struct mbuf **m_end, - struct sctp_auth_chunk **auth_ret, uint32_t * offset, + struct sctp_auth_chunk **auth_ret, uint32_t *offset, struct sctp_tcb *stcb, uint8_t chunk); extern int sctp_handle_auth(struct sctp_tcb *stcb, struct sctp_auth_chunk *ch, diff --git a/freebsd/sys/netinet/sctp_bsd_addr.c b/freebsd/sys/netinet/sctp_bsd_addr.c index 72c63d76..b3cb2ce3 100644 --- a/freebsd/sys/netinet/sctp_bsd_addr.c +++ b/freebsd/sys/netinet/sctp_bsd_addr.c @@ -479,7 +479,7 @@ again_locked: lenat++; *lenat = value; lenat++; - tick_tock = (uint32_t *) lenat; + tick_tock = (uint32_t *)lenat; lenat++; *tick_tock = sctp_get_tick_count(); copyto = (void *)lenat; @@ -500,7 +500,7 @@ no_log: int -sctp_copy_out_packet_log(uint8_t * target, int length) +sctp_copy_out_packet_log(uint8_t *target, int length) { /* * We wind through the packet log starting at start copying up to diff --git a/freebsd/sys/netinet/sctp_bsd_addr.h b/freebsd/sys/netinet/sctp_bsd_addr.h index 5fb1efb4..8c0383a5 100644 --- a/freebsd/sys/netinet/sctp_bsd_addr.h +++ b/freebsd/sys/netinet/sctp_bsd_addr.h @@ -53,7 +53,7 @@ void sctp_gather_internal_ifa_flags(struct sctp_ifa *ifa); #ifdef SCTP_PACKET_LOGGING void sctp_packet_log(struct mbuf *m); -int sctp_copy_out_packet_log(uint8_t * target, int length); +int sctp_copy_out_packet_log(uint8_t *target, int length); #endif diff --git a/freebsd/sys/netinet/sctp_cc_functions.c b/freebsd/sys/netinet/sctp_cc_functions.c index 49670e9b..b153d325 100644 --- a/freebsd/sys/netinet/sctp_cc_functions.c +++ b/freebsd/sys/netinet/sctp_cc_functions.c @@ -124,7 +124,7 @@ sctp_cwnd_update_after_fr(struct sctp_tcb *stcb, t_ssthresh += net->ssthresh; t_cwnd += net->cwnd; if (net->lastsa > 0) { - t_ucwnd_sbw += (uint64_t) net->cwnd / (uint64_t) net->lastsa; + t_ucwnd_sbw += (uint64_t)net->cwnd / (uint64_t)net->lastsa; } } if (t_ucwnd_sbw == 0) { @@ -152,27 +152,31 @@ sctp_cwnd_update_after_fr(struct sctp_tcb *stcb, if ((asoc->sctp_cmt_on_off == SCTP_CMT_RPV1) || (asoc->sctp_cmt_on_off == SCTP_CMT_RPV2)) { if (asoc->sctp_cmt_on_off == SCTP_CMT_RPV1) { - net->ssthresh = (uint32_t) (((uint64_t) 4 * - (uint64_t) net->mtu * - (uint64_t) net->ssthresh) / - (uint64_t) t_ssthresh); + net->ssthresh = (uint32_t)(((uint64_t)4 * + (uint64_t)net->mtu * + (uint64_t)net->ssthresh) / + (uint64_t)t_ssthresh); } if (asoc->sctp_cmt_on_off == SCTP_CMT_RPV2) { uint32_t srtt; srtt = net->lastsa; - /* lastsa>>3; we don't need - * to devide ... */ + /* + * lastsa>>3; we don't need + * to devide ... + */ if (srtt == 0) { srtt = 1; } - /* Short Version => Equal to - * Contel Version MBe */ - net->ssthresh = (uint32_t) (((uint64_t) 4 * - (uint64_t) net->mtu * - (uint64_t) net->cwnd) / - ((uint64_t) srtt * + /* + * Short Version => Equal to + * Contel Version MBe + */ + net->ssthresh = (uint32_t)(((uint64_t)4 * + (uint64_t)net->mtu * + (uint64_t)net->cwnd) / + ((uint64_t)srtt * t_ucwnd_sbw)); /* INCREASE FACTOR */ ; } @@ -251,7 +255,7 @@ cc_bw_same(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw, { uint64_t oth, probepoint; - probepoint = (((uint64_t) net->cwnd) << 32); + probepoint = (((uint64_t)net->cwnd) << 32); if (net->rtt > net->cc_mod.rtcc.lbw_rtt + rtt_offset) { /* * rtt increased we don't update bw.. so we don't update the @@ -387,7 +391,7 @@ cc_bw_decrease(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw, uint6 uint64_t oth, probepoint; /* Bandwidth decreased. */ - probepoint = (((uint64_t) net->cwnd) << 32); + probepoint = (((uint64_t)net->cwnd) << 32); if (net->rtt > net->cc_mod.rtcc.lbw_rtt + rtt_offset) { /* rtt increased */ /* Did we add more */ @@ -403,8 +407,10 @@ cc_bw_decrease(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw, uint6 net->flight_size, probepoint); if (net->cc_mod.rtcc.ret_from_eq) { - /* Switch over to CA if we are less - * aggressive */ + /* + * Switch over to CA if we are less + * aggressive + */ net->ssthresh = net->cwnd - 1; net->partial_bytes_acked = 0; } @@ -530,7 +536,7 @@ cc_bw_increase(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw, uint6 * attention to the inst_ind since our overall sum is increasing. */ /* PROBE POINT 0 */ - probepoint = (((uint64_t) net->cwnd) << 32); + probepoint = (((uint64_t)net->cwnd) << 32); SDT_PROBE5(sctp, cwnd, net, rttvar, vtag, ((net->cc_mod.rtcc.lbw << 32) | nbw), @@ -612,8 +618,8 @@ cc_bw_limit(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw) */ bw_shift = SCTP_BASE_SYSCTL(sctp_rttvar_bw); rtt = stcb->asoc.my_vtag; - vtag = (rtt << 32) | (((uint32_t) (stcb->sctp_ep->sctp_lport)) << 16) | (stcb->rport); - probepoint = (((uint64_t) net->cwnd) << 32); + vtag = (rtt << 32) | (((uint32_t)(stcb->sctp_ep->sctp_lport)) << 16) | (stcb->rport); + probepoint = (((uint64_t)net->cwnd) << 32); rtt = net->rtt; if (net->cc_mod.rtcc.rtt_set_this_sack) { net->cc_mod.rtcc.rtt_set_this_sack = 0; @@ -633,7 +639,7 @@ cc_bw_limit(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw) probepoint |= ((0xb << 16) | inst_ind); } else { inst_ind = net->cc_mod.rtcc.last_inst_ind; - inst_bw = bytes_for_this_rtt / (uint64_t) (net->rtt); + inst_bw = bytes_for_this_rtt / (uint64_t)(net->rtt); /* Can't determine do not change */ probepoint |= ((0xc << 16) | inst_ind); } @@ -705,11 +711,11 @@ sctp_cwnd_update_after_sack_common(struct sctp_tcb *stcb, if (srtt > 0) { uint64_t tmp; - t_ucwnd_sbw += (uint64_t) net->cwnd / (uint64_t) srtt; - t_path_mptcp += (((uint64_t) net->cwnd) << SHIFT_MPTCP_MULTI_Z) / - (((uint64_t) net->mtu) * (uint64_t) srtt); - tmp = (((uint64_t) net->cwnd) << SHIFT_MPTCP_MULTI_N) / - ((uint64_t) net->mtu * (uint64_t) (srtt * srtt)); + t_ucwnd_sbw += (uint64_t)net->cwnd / (uint64_t)srtt; + t_path_mptcp += (((uint64_t)net->cwnd) << SHIFT_MPTCP_MULTI_Z) / + (((uint64_t)net->mtu) * (uint64_t)srtt); + tmp = (((uint64_t)net->cwnd) << SHIFT_MPTCP_MULTI_N) / + ((uint64_t)net->mtu * (uint64_t)(srtt * srtt)); if (tmp > max_path) { max_path = tmp; } @@ -797,10 +803,10 @@ sctp_cwnd_update_after_sack_common(struct sctp_tcb *stcb, } else { uint64_t vtag, probepoint; - probepoint = (((uint64_t) net->cwnd) << 32); + probepoint = (((uint64_t)net->cwnd) << 32); probepoint |= ((0xa << 16) | 0); vtag = (net->rtt << 32) | - (((uint32_t) (stcb->sctp_ep->sctp_lport)) << 16) | + (((uint32_t)(stcb->sctp_ep->sctp_lport)) << 16) | (stcb->rport); SDT_PROBE5(sctp, cwnd, net, rttvar, @@ -832,13 +838,13 @@ sctp_cwnd_update_after_sack_common(struct sctp_tcb *stcb, old_cwnd = net->cwnd; switch (asoc->sctp_cmt_on_off) { case SCTP_CMT_RPV1: - limit = (uint32_t) (((uint64_t) net->mtu * - (uint64_t) SCTP_BASE_SYSCTL(sctp_L2_abc_variable) * - (uint64_t) net->ssthresh) / - (uint64_t) t_ssthresh); - incr = (uint32_t) (((uint64_t) net->net_ack * - (uint64_t) net->ssthresh) / - (uint64_t) t_ssthresh); + limit = (uint32_t)(((uint64_t)net->mtu * + (uint64_t)SCTP_BASE_SYSCTL(sctp_L2_abc_variable) * + (uint64_t)net->ssthresh) / + (uint64_t)t_ssthresh); + incr = (uint32_t)(((uint64_t)net->net_ack * + (uint64_t)net->ssthresh) / + (uint64_t)t_ssthresh); if (incr > limit) { incr = limit; } @@ -847,20 +853,22 @@ sctp_cwnd_update_after_sack_common(struct sctp_tcb *stcb, } break; case SCTP_CMT_RPV2: - /* lastsa>>3; we don't need - * to divide ... */ + /* + * lastsa>>3; we don't need + * to divide ... + */ srtt = net->lastsa; if (srtt == 0) { srtt = 1; } - limit = (uint32_t) (((uint64_t) net->mtu * - (uint64_t) SCTP_BASE_SYSCTL(sctp_L2_abc_variable) * - (uint64_t) net->cwnd) / - ((uint64_t) srtt * t_ucwnd_sbw)); + limit = (uint32_t)(((uint64_t)net->mtu * + (uint64_t)SCTP_BASE_SYSCTL(sctp_L2_abc_variable) * + (uint64_t)net->cwnd) / + ((uint64_t)srtt * t_ucwnd_sbw)); /* INCREASE FACTOR */ - incr = (uint32_t) (((uint64_t) net->net_ack * - (uint64_t) net->cwnd) / - ((uint64_t) srtt * t_ucwnd_sbw)); + incr = (uint32_t)(((uint64_t)net->net_ack * + (uint64_t)net->cwnd) / + ((uint64_t)srtt * t_ucwnd_sbw)); /* INCREASE FACTOR */ if (incr > limit) { incr = limit; @@ -870,11 +878,11 @@ sctp_cwnd_update_after_sack_common(struct sctp_tcb *stcb, } break; case SCTP_CMT_MPTCP: - limit = (uint32_t) (((uint64_t) net->mtu * + limit = (uint32_t)(((uint64_t)net->mtu * mptcp_like_alpha * - (uint64_t) SCTP_BASE_SYSCTL(sctp_L2_abc_variable)) >> + (uint64_t)SCTP_BASE_SYSCTL(sctp_L2_abc_variable)) >> SHIFT_MPTCP_MULTI); - incr = (uint32_t) (((uint64_t) net->net_ack * + incr = (uint32_t)(((uint64_t)net->net_ack * mptcp_like_alpha) >> SHIFT_MPTCP_MULTI); if (incr > limit) { @@ -924,23 +932,25 @@ sctp_cwnd_update_after_sack_common(struct sctp_tcb *stcb, old_cwnd = net->cwnd; switch (asoc->sctp_cmt_on_off) { case SCTP_CMT_RPV1: - incr = (uint32_t) (((uint64_t) net->mtu * - (uint64_t) net->ssthresh) / - (uint64_t) t_ssthresh); + incr = (uint32_t)(((uint64_t)net->mtu * + (uint64_t)net->ssthresh) / + (uint64_t)t_ssthresh); if (incr == 0) { incr = 1; } break; case SCTP_CMT_RPV2: - /* lastsa>>3; we don't need - * to divide ... */ + /* + * lastsa>>3; we don't need + * to divide ... + */ srtt = net->lastsa; if (srtt == 0) { srtt = 1; } - incr = (uint32_t) ((uint64_t) net->mtu * - (uint64_t) net->cwnd / - ((uint64_t) srtt * + incr = (uint32_t)((uint64_t)net->mtu * + (uint64_t)net->cwnd / + ((uint64_t)srtt * t_ucwnd_sbw)); /* INCREASE FACTOR */ if (incr == 0) { @@ -948,8 +958,8 @@ sctp_cwnd_update_after_sack_common(struct sctp_tcb *stcb, } break; case SCTP_CMT_MPTCP: - incr = (uint32_t) ((mptcp_like_alpha * - (uint64_t) net->cwnd) >> + incr = (uint32_t)((mptcp_like_alpha * + (uint64_t)net->cwnd) >> SHIFT_MPTCP_MULTI); if (incr > net->mtu) { incr = net->mtu; @@ -1023,7 +1033,7 @@ sctp_cwnd_update_after_timeout(struct sctp_tcb *stcb, struct sctp_nets *net) srtt = lnet->lastsa; /* lastsa>>3; we don't need to divide ... */ if (srtt > 0) { - t_ucwnd_sbw += (uint64_t) lnet->cwnd / (uint64_t) srtt; + t_ucwnd_sbw += (uint64_t)lnet->cwnd / (uint64_t)srtt; } } if (t_ssthresh < 1) { @@ -1033,10 +1043,10 @@ sctp_cwnd_update_after_timeout(struct sctp_tcb *stcb, struct sctp_nets *net) t_ucwnd_sbw = 1; } if (stcb->asoc.sctp_cmt_on_off == SCTP_CMT_RPV1) { - net->ssthresh = (uint32_t) (((uint64_t) 4 * - (uint64_t) net->mtu * - (uint64_t) net->ssthresh) / - (uint64_t) t_ssthresh); + net->ssthresh = (uint32_t)(((uint64_t)4 * + (uint64_t)net->mtu * + (uint64_t)net->ssthresh) / + (uint64_t)t_ssthresh); } else { uint64_t cc_delta; @@ -1045,9 +1055,9 @@ sctp_cwnd_update_after_timeout(struct sctp_tcb *stcb, struct sctp_nets *net) if (srtt == 0) { srtt = 1; } - cc_delta = t_ucwnd_sbw * (uint64_t) srtt / 2; + cc_delta = t_ucwnd_sbw * (uint64_t)srtt / 2; if (cc_delta < t_cwnd) { - net->ssthresh = (uint32_t) ((uint64_t) t_cwnd - cc_delta); + net->ssthresh = (uint32_t)((uint64_t)t_cwnd - cc_delta); } else { net->ssthresh = net->mtu; } @@ -1100,8 +1110,10 @@ sctp_cwnd_update_after_ecn_echo_common(struct sctp_tcb *stcb, struct sctp_nets * sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_SAT); } } else { - /* Further tuning down required over the drastic - * original cut */ + /* + * Further tuning down required over the drastic + * original cut + */ net->ssthresh -= (net->mtu * num_pkt_lost); net->cwnd -= (net->mtu * num_pkt_lost); if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) { @@ -1115,8 +1127,10 @@ sctp_cwnd_update_after_ecn_echo_common(struct sctp_tcb *stcb, struct sctp_nets * net->ssthresh = net->cwnd / 2; if (net->ssthresh < net->mtu) { net->ssthresh = net->mtu; - /* here back off the timer as well, to slow - * us down */ + /* + * here back off the timer as well, to slow + * us down + */ net->RTO <<= 1; } net->cwnd = net->ssthresh; @@ -1136,7 +1150,7 @@ sctp_cwnd_update_after_ecn_echo_common(struct sctp_tcb *stcb, struct sctp_nets * static void sctp_cwnd_update_after_packet_dropped(struct sctp_tcb *stcb, struct sctp_nets *net, struct sctp_pktdrop_chunk *cp, - uint32_t * bottle_bw, uint32_t * on_queue) + uint32_t *bottle_bw, uint32_t *on_queue) { uint32_t bw_avail; unsigned int incr; @@ -1154,7 +1168,7 @@ sctp_cwnd_update_after_packet_dropped(struct sctp_tcb *stcb, *on_queue = net->flight_size; } /* rtt is measured in micro seconds, bottle_bw in bytes per second */ - bw_avail = (uint32_t) (((uint64_t) (*bottle_bw) * net->rtt) / (uint64_t) 1000000); + bw_avail = (uint32_t)(((uint64_t)(*bottle_bw) * net->rtt) / (uint64_t)1000000); if (bw_avail > *bottle_bw) { /* * Cap the growth to no more than the bottle neck. This can @@ -1333,9 +1347,9 @@ sctp_cwnd_new_rtcc_transmission_begins(struct sctp_tcb *stcb, if (net->cc_mod.rtcc.lbw) { /* Clear the old bw.. we went to 0 in-flight */ - vtag = (net->rtt << 32) | (((uint32_t) (stcb->sctp_ep->sctp_lport)) << 16) | + vtag = (net->rtt << 32) | (((uint32_t)(stcb->sctp_ep->sctp_lport)) << 16) | (stcb->rport); - probepoint = (((uint64_t) net->cwnd) << 32); + probepoint = (((uint64_t)net->cwnd) << 32); /* Probe point 8 */ probepoint |= ((8 << 16) | 0); SDT_PROBE5(sctp, cwnd, net, rttvar, @@ -1363,8 +1377,10 @@ sctp_cwnd_new_rtcc_transmission_begins(struct sctp_tcb *stcb, cwnd_in_mtu = SCTP_BASE_SYSCTL(sctp_initial_cwnd); if (cwnd_in_mtu == 0) { - /* Using 0 means that the value of RFC 4960 - * is used. */ + /* + * Using 0 means that the value of RFC 4960 + * is used. + */ cwnd = min((net->mtu * 4), max((2 * net->mtu), SCTP_INITIAL_CWND)); } else { /* @@ -1376,8 +1392,10 @@ sctp_cwnd_new_rtcc_transmission_begins(struct sctp_tcb *stcb, cwnd = (net->mtu - sizeof(struct sctphdr)) * cwnd_in_mtu; } if (net->cwnd > cwnd) { - /* Only set if we are not a timeout (i.e. - * down to 1 mtu) */ + /* + * Only set if we are not a timeout (i.e. + * down to 1 mtu) + */ net->cwnd = cwnd; } } @@ -1392,10 +1410,10 @@ sctp_set_rtcc_initial_cc_param(struct sctp_tcb *stcb, sctp_set_initial_cc_param(stcb, net); stcb->asoc.use_precise_time = 1; - probepoint = (((uint64_t) net->cwnd) << 32); + probepoint = (((uint64_t)net->cwnd) << 32); probepoint |= ((9 << 16) | 0); vtag = (net->rtt << 32) | - (((uint32_t) (stcb->sctp_ep->sctp_lport)) << 16) | + (((uint32_t)(stcb->sctp_ep->sctp_lport)) << 16) | (stcb->rport); SDT_PROBE5(sctp, cwnd, net, rttvar, vtag, @@ -1616,7 +1634,7 @@ sctp_hs_cwnd_increase(struct sctp_tcb *stcb, struct sctp_nets *net) } } net->last_hs_used = indx; - incr = (((int32_t) sctp_cwnd_adjust[indx].increase) << 10); + incr = (((int32_t)sctp_cwnd_adjust[indx].increase) << 10); net->cwnd += incr; } sctp_enforce_cwnd_limit(&stcb->asoc, net); @@ -1642,7 +1660,7 @@ sctp_hs_cwnd_decrease(struct sctp_tcb *stcb, struct sctp_nets *net) } else { /* drop by the proper amount */ net->ssthresh = net->cwnd - (int)((net->cwnd / 100) * - (int32_t) sctp_cwnd_adjust[net->last_hs_used].drop_percent); + (int32_t)sctp_cwnd_adjust[net->last_hs_used].drop_percent); net->cwnd = net->ssthresh; /* now where are we */ indx = net->last_hs_used; @@ -1953,7 +1971,7 @@ htcp_beta_update(struct htcp *ca, uint32_t minRTT, uint32_t maxRTT) return; } } - if (ca->modeswitch && minRTT > (uint32_t) MSEC_TO_TICKS(10) && maxRTT) { + if (ca->modeswitch && minRTT > (uint32_t)MSEC_TO_TICKS(10) && maxRTT) { ca->beta = (minRTT << 7) / maxRTT; if (ca->beta < BETA_MIN) ca->beta = BETA_MIN; @@ -1972,7 +1990,7 @@ htcp_alpha_update(struct htcp *ca) uint32_t factor = 1; uint32_t diff = htcp_cong_time(ca); - if (diff > (uint32_t) hz) { + if (diff > (uint32_t)hz) { diff -= hz; factor = 1 + (10 * diff + ((diff / 2) * (diff / 2) / hz)) / hz; } @@ -2007,8 +2025,10 @@ htcp_param_update(struct sctp_nets *net) htcp_beta_update(&net->cc_mod.htcp_ca, minRTT, maxRTT); htcp_alpha_update(&net->cc_mod.htcp_ca); - /* add slowly fading memory for maxRTT to accommodate routing - * changes etc */ + /* + * add slowly fading memory for maxRTT to accommodate routing + * changes etc + */ if (minRTT > 0 && maxRTT > minRTT) net->cc_mod.htcp_ca.maxRTT = minRTT + ((maxRTT - minRTT) * 95) / 100; } diff --git a/freebsd/sys/netinet/sctp_crc32.c b/freebsd/sys/netinet/sctp_crc32.c index 9130feb2..99aebe48 100644 --- a/freebsd/sys/netinet/sctp_crc32.c +++ b/freebsd/sys/netinet/sctp_crc32.c @@ -92,7 +92,7 @@ sctp_calculate_cksum(struct mbuf *m, uint32_t offset) at = m; /* find the correct mbuf and offset into mbuf */ - while ((at != NULL) && (offset > (uint32_t) SCTP_BUF_LEN(at))) { + while ((at != NULL) && (offset > (uint32_t)SCTP_BUF_LEN(at))) { offset -= SCTP_BUF_LEN(at); /* update remaining offset * left */ at = SCTP_BUF_NEXT(at); @@ -105,7 +105,7 @@ sctp_calculate_cksum(struct mbuf *m, uint32_t offset) } if (offset) { /* we only offset once into the first mbuf */ - if (offset < (uint32_t) SCTP_BUF_LEN(at)) + if (offset < (uint32_t)SCTP_BUF_LEN(at)) offset = 0; else offset -= SCTP_BUF_LEN(at); @@ -133,9 +133,9 @@ sctp_delayed_cksum(struct mbuf *m, uint32_t offset) SCTP_STAT_INCR(sctps_sendswcrc); offset += offsetof(struct sctphdr, checksum); - if (offset + sizeof(uint32_t) > (uint32_t) (m->m_len)) { + if (offset + sizeof(uint32_t) > (uint32_t)(m->m_len)) { SCTP_PRINTF("sctp_delayed_cksum(): m->len: %d, off: %d.\n", - (uint32_t) m->m_len, offset); + (uint32_t)m->m_len, offset); /* * XXX this shouldn't happen, but if it does, the correct * behavior may be to insert the checksum in the appropriate @@ -143,6 +143,6 @@ sctp_delayed_cksum(struct mbuf *m, uint32_t offset) */ return; } - *(uint32_t *) (m->m_data + offset) = checksum; + *(uint32_t *)(m->m_data + offset) = checksum; #endif } diff --git a/freebsd/sys/netinet/sctp_indata.c b/freebsd/sys/netinet/sctp_indata.c index d9449a66..57f13a13 100644 --- a/freebsd/sys/netinet/sctp_indata.c +++ b/freebsd/sys/netinet/sctp_indata.c @@ -98,14 +98,14 @@ sctp_calc_rwnd(struct sctp_tcb *stcb, struct sctp_association *asoc) return (calc); } /* get actual space */ - calc = (uint32_t) sctp_sbspace(&stcb->asoc, &stcb->sctp_socket->so_rcv); + calc = (uint32_t)sctp_sbspace(&stcb->asoc, &stcb->sctp_socket->so_rcv); /* * take out what has NOT been put on socket queue and we yet hold * for putting up. */ - calc = sctp_sbspace_sub(calc, (uint32_t) (asoc->size_on_reasm_queue + + calc = sctp_sbspace_sub(calc, (uint32_t)(asoc->size_on_reasm_queue + asoc->cnt_on_reasm_queue * MSIZE)); - calc = sctp_sbspace_sub(calc, (uint32_t) (asoc->size_on_all_streams + + calc = sctp_sbspace_sub(calc, (uint32_t)(asoc->size_on_all_streams + asoc->cnt_on_all_streams * MSIZE)); if (calc == 0) { /* out of space */ @@ -335,16 +335,18 @@ sctp_place_control_in_stream(struct sctp_stream_in *strm, { struct sctp_queued_to_read *at; struct sctp_readhead *q; - uint8_t bits, unordered; + uint8_t flags, unordered; - bits = (control->sinfo_flags >> 8); - unordered = bits & SCTP_DATA_UNORDERED; + flags = (control->sinfo_flags >> 8); + unordered = flags & SCTP_DATA_UNORDERED; if (unordered) { q = &strm->uno_inqueue; if (asoc->idata_supported == 0) { if (!TAILQ_EMPTY(q)) { - /* Only one stream can be here in old style - * -- abort */ + /* + * Only one stream can be here in old style + * -- abort + */ return (-1); } TAILQ_INSERT_TAIL(q, control, next_instrm); @@ -354,8 +356,10 @@ sctp_place_control_in_stream(struct sctp_stream_in *strm, } else { q = &strm->inqueue; } - if ((bits & SCTP_DATA_NOT_FRAG) == SCTP_DATA_NOT_FRAG) { - control->end_added = control->last_frag_seen = control->first_frag_seen = 1; + if ((flags & SCTP_DATA_NOT_FRAG) == SCTP_DATA_NOT_FRAG) { + control->end_added = 1; + control->first_frag_seen = 1; + control->last_frag_seen = 1; } if (TAILQ_EMPTY(q)) { /* Empty queue */ @@ -396,8 +400,7 @@ sctp_place_control_in_stream(struct sctp_stream_in *strm, sctp_log_strm_del(control, at, SCTP_STR_LOG_FROM_INSERT_TL); } - TAILQ_INSERT_AFTER(q, - at, control, next_instrm); + TAILQ_INSERT_AFTER(q, at, control, next_instrm); if (unordered) { control->on_strm_q = SCTP_ON_UNORDERED; } else { @@ -436,7 +439,7 @@ sctp_abort_in_reasm(struct sctp_tcb *stcb, chk->rec.data.tsn, chk->rec.data.sid, chk->rec.data.fsn, - (uint16_t) chk->rec.data.mid); + (uint16_t)chk->rec.data.mid); } oper = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg); sctp_m_freem(chk->data); @@ -473,7 +476,6 @@ sctp_clean_up_control(struct sctp_tcb *stcb, struct sctp_queued_to_read *control */ static void sctp_queue_data_to_stream(struct sctp_tcb *stcb, - struct sctp_stream_in *strm, struct sctp_association *asoc, struct sctp_queued_to_read *control, int *abort_flag, int *need_reasm) { @@ -499,16 +501,17 @@ sctp_queue_data_to_stream(struct sctp_tcb *stcb, int queue_needed; uint32_t nxt_todel; struct mbuf *op_err; + struct sctp_stream_in *strm; char msg[SCTP_DIAG_INFO_LEN]; + strm = &asoc->strmin[control->sinfo_stream]; if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) { sctp_log_strm_del(control, NULL, SCTP_STR_LOG_FROM_INTO_STRD); } if (SCTP_MID_GT((asoc->idata_supported), strm->last_mid_delivered, control->mid)) { /* The incoming sseq is behind where we last delivered? */ SCTPDBG(SCTP_DEBUG_INDATA1, "Duplicate S-SEQ: %u delivered: %u from peer, Abort association\n", - control->mid, strm->last_mid_delivered); -protocol_error: + strm->last_mid_delivered, control->mid); /* * throw it in the stream so it gets cleaned up in * association destruction @@ -520,10 +523,10 @@ protocol_error: control->sinfo_stream, control->mid); } else { snprintf(msg, sizeof(msg), "Delivered SSN=%4.4x, got TSN=%8.8x, SID=%4.4x, SSN=%4.4x", - (uint16_t) strm->last_mid_delivered, + (uint16_t)strm->last_mid_delivered, control->sinfo_tsn, control->sinfo_stream, - (uint16_t) control->mid); + (uint16_t)control->mid); } op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg); stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_2; @@ -532,9 +535,6 @@ protocol_error: return; } - if ((SCTP_TSN_GE(asoc->cumulative_tsn, control->sinfo_tsn)) && (asoc->idata_supported == 0)) { - goto protocol_error; - } queue_needed = 1; asoc->size_on_all_streams += control->length; sctp_ucount_incr(asoc->cnt_on_all_streams); @@ -836,8 +836,10 @@ restart: TAILQ_INSERT_TAIL(&nc->reasm, tchk, sctp_next); tchk = TAILQ_FIRST(&control->reasm); } - /* Now lets add it to the queue - * after removing control */ + /* + * Now lets add it to the queue + * after removing control + */ TAILQ_INSERT_TAIL(&strm->uno_inqueue, nc, next_instrm); nc->on_strm_q = SCTP_ON_UNORDERED; if (control->on_strm_q) { @@ -861,8 +863,10 @@ restart: } sctp_wakeup_the_read_socket(stcb->sctp_ep, stcb, SCTP_SO_NOT_LOCKED); if ((nc->first_frag_seen) && !TAILQ_EMPTY(&nc->reasm)) { - /* Switch to the new guy and - * continue */ + /* + * Switch to the new guy and + * continue + */ control = nc; goto restart; } else { @@ -922,8 +926,10 @@ sctp_inject_old_unordered_data(struct sctp_tcb *stcb, uint32_t tmp; if (SCTP_TSN_GT(chk->rec.data.fsn, control->fsn_included)) { - /* Easy way the start of a new guy beyond - * the lowest */ + /* + * Easy way the start of a new guy beyond + * the lowest + */ goto place_chunk; } if ((chk->rec.data.fsn == control->fsn_included) || @@ -974,7 +980,8 @@ sctp_inject_old_unordered_data(struct sctp_tcb *stcb, goto place_chunk; } control->first_frag_seen = 1; - control->top_fsn = control->fsn_included = chk->rec.data.fsn; + control->fsn_included = chk->rec.data.fsn; + control->top_fsn = chk->rec.data.fsn; control->sinfo_tsn = chk->rec.data.tsn; control->sinfo_ppid = chk->rec.data.ppid; control->data = chk->data; @@ -1041,7 +1048,7 @@ sctp_deliver_reasm_check(struct sctp_tcb *stcb, struct sctp_association *asoc, } control = TAILQ_FIRST(&strm->uno_inqueue); - if ((control) && + if ((control != NULL) && (asoc->idata_supported == 0)) { /* Special handling needed for "old" data format */ if (sctp_handle_old_unordered_data(stcb, asoc, strm, control, pd_point, inp_read_lock_held)) { @@ -1138,8 +1145,10 @@ done_un: } } if (strm->pd_api_started) { - /* Can't add more must have gotten an un-ordered above being - * partially delivered. */ + /* + * Can't add more must have gotten an un-ordered above being + * partially delivered. + */ return (0); } deliver_more: @@ -1171,15 +1180,21 @@ deliver_more: ret++; } if (((control->sinfo_flags >> 8) & SCTP_DATA_NOT_FRAG) == SCTP_DATA_NOT_FRAG) { - /* A singleton now slipping through - mark - * it non-revokable too */ + /* + * A singleton now slipping through - mark + * it non-revokable too + */ sctp_mark_non_revokable(asoc, control->sinfo_tsn); } else if (control->end_added == 0) { - /* Check if we can defer adding until its - * all there */ + /* + * Check if we can defer adding until its + * all there + */ if ((control->length < pd_point) || (strm->pd_api_started)) { - /* Don't need it or cannot add more - * (one being delivered that way) */ + /* + * Don't need it or cannot add more + * (one being delivered that way) + */ goto out; } } @@ -1238,6 +1253,8 @@ sctp_add_chk_to_control(struct sctp_queued_to_read *control, chk->data = NULL; if (chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) { control->first_frag_seen = 1; + control->sinfo_tsn = chk->rec.data.tsn; + control->sinfo_ppid = chk->rec.data.ppid; } if (chk->rec.data.rcv_flags & SCTP_DATA_LAST_FRAG) { /* Its complete */ @@ -1278,7 +1295,6 @@ sctp_add_chk_to_control(struct sctp_queued_to_read *control, */ static void sctp_queue_data_for_reasm(struct sctp_tcb *stcb, struct sctp_association *asoc, - struct sctp_stream_in *strm, struct sctp_queued_to_read *control, struct sctp_tmit_chunk *chk, int created_control, @@ -1286,8 +1302,10 @@ sctp_queue_data_for_reasm(struct sctp_tcb *stcb, struct sctp_association *asoc, { uint32_t next_fsn; struct sctp_tmit_chunk *at, *nat; + struct sctp_stream_in *strm; int do_wakeup, unordered; + strm = &asoc->strmin[control->sinfo_stream]; /* * For old un-ordered data chunks. */ @@ -1349,6 +1367,8 @@ sctp_queue_data_for_reasm(struct sctp_tcb *stcb, struct sctp_association *asoc, return; } control->first_frag_seen = 1; + control->sinfo_ppid = chk->rec.data.ppid; + control->sinfo_tsn = chk->rec.data.tsn; control->fsn_included = chk->rec.data.fsn; control->data = chk->data; sctp_mark_non_revokable(asoc, chk->rec.data.tsn); @@ -1381,8 +1401,10 @@ sctp_queue_data_for_reasm(struct sctp_tcb *stcb, struct sctp_association *asoc, * we know the first FSN (which is the TSN). */ if (SCTP_TSN_GE(control->fsn_included, chk->rec.data.fsn)) { - /* We have already delivered up to - * this so its a dup */ + /* + * We have already delivered up to + * this so its a dup + */ sctp_abort_in_reasm(stcb, control, chk, abort_flag, SCTP_FROM_SCTP_INDATA + SCTP_LOC_9); @@ -1409,8 +1431,10 @@ sctp_queue_data_for_reasm(struct sctp_tcb *stcb, struct sctp_association *asoc, */ if (SCTP_TSN_GE(control->fsn_included, chk->rec.data.fsn)) { - /* We have already delivered up to - * this so its a dup */ + /* + * We have already delivered up to + * this so its a dup + */ SCTPDBG(SCTP_DEBUG_XXX, "New fsn: %u is already seen in included_fsn: %u -- abort\n", chk->rec.data.fsn, control->fsn_included); @@ -1420,8 +1444,10 @@ sctp_queue_data_for_reasm(struct sctp_tcb *stcb, struct sctp_association *asoc, return; } } - /* validate not beyond top FSN if we have seen last - * one */ + /* + * validate not beyond top FSN if we have seen last + * one + */ if (SCTP_TSN_GT(chk->rec.data.fsn, control->top_fsn)) { SCTPDBG(SCTP_DEBUG_XXX, "New fsn: %u is beyond or at top_fsn: %u -- abort\n", @@ -1455,8 +1481,10 @@ sctp_queue_data_for_reasm(struct sctp_tcb *stcb, struct sctp_association *asoc, inserted = 1; break; } else if (at->rec.data.fsn == chk->rec.data.fsn) { - /* Gak, He sent me a duplicate str seq - * number */ + /* + * Gak, He sent me a duplicate str seq + * number + */ /* * foo bar, I guess I will just free this * new guy, should we abort too? FIX ME @@ -1561,13 +1589,11 @@ sctp_find_reasm_entry(struct sctp_stream_in *strm, uint32_t mid, int ordered, in static int sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct sctp_association *asoc, struct mbuf **m, int offset, int chk_length, - struct sctp_nets *net, uint32_t * high_tsn, int *abort_flag, - int *break_flag, int last_chunk, uint8_t chtype) + struct sctp_nets *net, uint32_t *high_tsn, int *abort_flag, + int *break_flag, int last_chunk, uint8_t chk_type) { /* Process a data chunk */ /* struct sctp_tmit_chunk *chk; */ - struct sctp_data_chunk *ch; - struct sctp_idata_chunk *nch, chunk_buf; struct sctp_tmit_chunk *chk; uint32_t tsn, fsn, gap, mid; struct mbuf *dmbuf; @@ -1578,58 +1604,63 @@ sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct sctp_association *asoc, char msg[SCTP_DIAG_INFO_LEN]; struct sctp_queued_to_read *control = NULL; uint32_t ppid; - uint8_t chunk_flags; + uint8_t chk_flags; struct sctp_stream_reset_list *liste; - struct sctp_stream_in *strm; int ordered; size_t clen; int created_control = 0; - chk = NULL; - if (chtype == SCTP_IDATA) { - nch = (struct sctp_idata_chunk *)sctp_m_getptr(*m, offset, - sizeof(struct sctp_idata_chunk), (uint8_t *) & chunk_buf); - ch = (struct sctp_data_chunk *)nch; + if (chk_type == SCTP_IDATA) { + struct sctp_idata_chunk *chunk, chunk_buf; + + chunk = (struct sctp_idata_chunk *)sctp_m_getptr(*m, offset, + sizeof(struct sctp_idata_chunk), (uint8_t *)&chunk_buf); + chk_flags = chunk->ch.chunk_flags; clen = sizeof(struct sctp_idata_chunk); - tsn = ntohl(ch->dp.tsn); - mid = ntohl(nch->dp.mid); - ppid = nch->dp.ppid_fsn.ppid; - if (ch->ch.chunk_flags & SCTP_DATA_FIRST_FRAG) + tsn = ntohl(chunk->dp.tsn); + sid = ntohs(chunk->dp.sid); + mid = ntohl(chunk->dp.mid); + if (chk_flags & SCTP_DATA_FIRST_FRAG) { fsn = 0; - else - fsn = ntohl(nch->dp.ppid_fsn.fsn); + ppid = chunk->dp.ppid_fsn.ppid; + } else { + fsn = ntohl(chunk->dp.ppid_fsn.fsn); + ppid = 0xffffffff; /* Use as an invalid value. */ + } } else { - ch = (struct sctp_data_chunk *)sctp_m_getptr(*m, offset, - sizeof(struct sctp_data_chunk), (uint8_t *) & chunk_buf); - tsn = ntohl(ch->dp.tsn); - ppid = ch->dp.ppid; + struct sctp_data_chunk *chunk, chunk_buf; + + chunk = (struct sctp_data_chunk *)sctp_m_getptr(*m, offset, + sizeof(struct sctp_data_chunk), (uint8_t *)&chunk_buf); + chk_flags = chunk->ch.chunk_flags; clen = sizeof(struct sctp_data_chunk); + tsn = ntohl(chunk->dp.tsn); + sid = ntohs(chunk->dp.sid); + mid = (uint32_t)(ntohs(chunk->dp.ssn)); fsn = tsn; - mid = (uint32_t) (ntohs(ch->dp.ssn)); - nch = NULL; + ppid = chunk->dp.ppid; } - chunk_flags = ch->ch.chunk_flags; if ((size_t)chk_length == clen) { /* * Need to send an abort since we had a empty data chunk. */ - op_err = sctp_generate_no_user_data_cause(ch->dp.tsn); + op_err = sctp_generate_no_user_data_cause(tsn); stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_14; sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED); *abort_flag = 1; return (0); } - if ((chunk_flags & SCTP_DATA_SACK_IMMEDIATELY) == SCTP_DATA_SACK_IMMEDIATELY) { + if ((chk_flags & SCTP_DATA_SACK_IMMEDIATELY) == SCTP_DATA_SACK_IMMEDIATELY) { asoc->send_sack = 1; } - ordered = ((chunk_flags & SCTP_DATA_UNORDERED) == 0); + ordered = ((chk_flags & SCTP_DATA_UNORDERED) == 0); if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) { sctp_log_map(tsn, asoc->cumulative_tsn, asoc->highest_tsn_inside_map, SCTP_MAP_TSN_ENTERS); } if (stcb == NULL) { return (0); } - SCTP_LTRACE_CHK(stcb->sctp_ep, stcb, ch->ch.chunk_type, tsn); + SCTP_LTRACE_CHK(stcb->sctp_ep, stcb, chk_type, tsn); if (SCTP_TSN_GE(asoc->cumulative_tsn, tsn)) { /* It is a duplicate */ SCTP_STAT_INCR(sctps_recvdupdata); @@ -1647,7 +1678,7 @@ sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct sctp_association *asoc, /* Can't hold the bit in the mapping at max array, toss it */ return (0); } - if (gap >= (uint32_t) (asoc->mapping_array_size << 3)) { + if (gap >= (uint32_t)(asoc->mapping_array_size << 3)) { SCTP_TCB_LOCK_ASSERT(stcb); if (sctp_expand_mapping_array(asoc, gap)) { /* Can't expand, drop it */ @@ -1692,8 +1723,6 @@ sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct sctp_association *asoc, */ /* Is the stream valid? */ - sid = ntohs(ch->dp.sid); - if (sid >= asoc->streamincnt) { struct sctp_error_invalid_stream *cause; @@ -1711,7 +1740,7 @@ sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct sctp_association *asoc, SCTP_BUF_LEN(op_err) = sizeof(struct sctp_error_invalid_stream); cause->cause.code = htons(SCTP_CAUSE_INVALID_STREAM); cause->cause.length = htons(sizeof(struct sctp_error_invalid_stream)); - cause->stream_id = ch->dp.sid; + cause->stream_id = htons(sid); cause->reserved = htons(0); sctp_queue_op_err(stcb, op_err); } @@ -1727,13 +1756,12 @@ sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct sctp_association *asoc, } return (0); } - strm = &asoc->strmin[sid]; /* * If its a fragmented message, lets see if we can find the control * on the reassembly queues. */ - if ((chtype == SCTP_IDATA) && - ((chunk_flags & SCTP_DATA_FIRST_FRAG) == 0) && + if ((chk_type == SCTP_IDATA) && + ((chk_flags & SCTP_DATA_FIRST_FRAG) == 0) && (fsn == 0)) { /* * The first *must* be fsn 0, and other (middle/end) pieces @@ -1741,13 +1769,13 @@ sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct sctp_association *asoc, * wrap around. Ignore is for now. */ snprintf(msg, sizeof(msg), "FSN zero for MID=%8.8x, but flags=%2.2x", - mid, chunk_flags); + mid, chk_flags); goto err_out; } - control = sctp_find_reasm_entry(strm, mid, ordered, asoc->idata_supported); + control = sctp_find_reasm_entry(&asoc->strmin[sid], mid, ordered, asoc->idata_supported); SCTPDBG(SCTP_DEBUG_XXX, "chunk_flags:0x%x look for control on queues %p\n", - chunk_flags, control); - if ((chunk_flags & SCTP_DATA_NOT_FRAG) != SCTP_DATA_NOT_FRAG) { + chk_flags, control); + if ((chk_flags & SCTP_DATA_NOT_FRAG) != SCTP_DATA_NOT_FRAG) { /* See if we can find the re-assembly entity */ if (control != NULL) { /* We found something, does it belong? */ @@ -1761,15 +1789,19 @@ sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct sctp_association *asoc, return (0); } if (ordered && ((control->sinfo_flags >> 8) & SCTP_DATA_UNORDERED)) { - /* We can't have a switched order with an - * unordered chunk */ + /* + * We can't have a switched order with an + * unordered chunk + */ snprintf(msg, sizeof(msg), "All fragments of a user message must be ordered or unordered (TSN=%8.8x)", tsn); goto err_out; } if (!ordered && (((control->sinfo_flags >> 8) & SCTP_DATA_UNORDERED) == 0)) { - /* We can't have a switched unordered with a - * ordered chunk */ + /* + * We can't have a switched unordered with a + * ordered chunk + */ snprintf(msg, sizeof(msg), "All fragments of a user message must be ordered or unordered (TSN=%8.8x)", tsn); goto err_out; @@ -1784,7 +1816,7 @@ sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct sctp_association *asoc, if (control != NULL) { if (ordered || asoc->idata_supported) { SCTPDBG(SCTP_DEBUG_XXX, "chunk_flags: 0x%x dup detected on MID: %u\n", - chunk_flags, mid); + chk_flags, mid); snprintf(msg, sizeof(msg), "Duplicate MID=%8.8x detected.", mid); goto err_out; } else { @@ -1830,7 +1862,7 @@ sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct sctp_association *asoc, #endif } /* now is it in the mapping array of what we have accepted? */ - if (nch == NULL) { + if (chk_type == SCTP_DATA) { if (SCTP_TSN_GT(tsn, asoc->highest_tsn_inside_map) && SCTP_TSN_GT(tsn, asoc->highest_tsn_inside_nr_map)) { /* Nope not in the valid range dump it */ @@ -1878,9 +1910,9 @@ sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct sctp_association *asoc, * way our stream sequence numbers could have wrapped. We of course * only validate the FIRST fragment so the bit must be set. */ - if ((chunk_flags & SCTP_DATA_FIRST_FRAG) && + if ((chk_flags & SCTP_DATA_FIRST_FRAG) && (TAILQ_EMPTY(&asoc->resetHead)) && - (chunk_flags & SCTP_DATA_UNORDERED) == 0 && + (chk_flags & SCTP_DATA_UNORDERED) == 0 && SCTP_MID_GE(asoc->idata_supported, asoc->strmin[sid].last_mid_delivered, mid)) { /* The incoming sseq is behind where we last delivered? */ SCTPDBG(SCTP_DEBUG_INDATA1, "EVIL/Broken-Dup S-SEQ: %u delivered: %u from peer, Abort!\n", @@ -1894,10 +1926,10 @@ sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct sctp_association *asoc, mid); } else { snprintf(msg, sizeof(msg), "Delivered SSN=%4.4x, got TSN=%8.8x, SID=%4.4x, SSN=%4.4x", - (uint16_t) asoc->strmin[sid].last_mid_delivered, + (uint16_t)asoc->strmin[sid].last_mid_delivered, tsn, sid, - (uint16_t) mid); + (uint16_t)mid); } op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg); stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_16; @@ -1905,17 +1937,13 @@ sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct sctp_association *asoc, *abort_flag = 1; return (0); } - /************************************ - * From here down we may find ch-> invalid - * so its a good idea NOT to use it. - *************************************/ - if (nch) { + if (chk_type == SCTP_IDATA) { the_len = (chk_length - sizeof(struct sctp_idata_chunk)); } else { the_len = (chk_length - sizeof(struct sctp_data_chunk)); } if (last_chunk == 0) { - if (nch) { + if (chk_type == SCTP_IDATA) { dmbuf = SCTP_M_COPYM(*m, (offset + sizeof(struct sctp_idata_chunk)), the_len, M_NOWAIT); @@ -1935,7 +1963,7 @@ sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct sctp_association *asoc, dmbuf = *m; /* lop off the top part */ - if (nch) { + if (chk_type == SCTP_IDATA) { m_adj(dmbuf, (offset + sizeof(struct sctp_idata_chunk))); } else { m_adj(dmbuf, (offset + sizeof(struct sctp_data_chunk))); @@ -1964,7 +1992,7 @@ sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct sctp_association *asoc, return (0); } /* - * Now no matter what we need a control, get one if we don't have + * Now no matter what, we need a control, get one if we don't have * one (we may have gotten it above when we found the message was * fragmented */ @@ -1973,23 +2001,26 @@ sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct sctp_association *asoc, sctp_build_readq_entry_mac(control, stcb, asoc->context, net, tsn, ppid, sid, - chunk_flags, + chk_flags, NULL, fsn, mid); if (control == NULL) { SCTP_STAT_INCR(sctps_nomem); return (0); } - if ((chunk_flags & SCTP_DATA_NOT_FRAG) == SCTP_DATA_NOT_FRAG) { + if ((chk_flags & SCTP_DATA_NOT_FRAG) == SCTP_DATA_NOT_FRAG) { control->data = dmbuf; control->tail_mbuf = NULL; - control->end_added = control->last_frag_seen = control->first_frag_seen = 1; - control->top_fsn = control->fsn_included = fsn; + control->end_added = 1; + control->last_frag_seen = 1; + control->first_frag_seen = 1; + control->fsn_included = fsn; + control->top_fsn = fsn; } created_control = 1; } SCTPDBG(SCTP_DEBUG_XXX, "chunk_flags: 0x%x ordered: %d MID: %u control: %p\n", - chunk_flags, ordered, mid, control); - if ((chunk_flags & SCTP_DATA_NOT_FRAG) == SCTP_DATA_NOT_FRAG && + chk_flags, ordered, mid, control); + if ((chk_flags & SCTP_DATA_NOT_FRAG) == SCTP_DATA_NOT_FRAG && TAILQ_EMPTY(&asoc->resetHead) && ((ordered == 0) || (SCTP_MID_EQ(asoc->idata_supported, asoc->strmin[sid].last_mid_delivered + 1, mid) && @@ -2013,9 +2044,9 @@ sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct sctp_association *asoc, control, &stcb->sctp_socket->so_rcv, 1, SCTP_READ_LOCK_NOT_HELD, SCTP_SO_NOT_LOCKED); - if ((chunk_flags & SCTP_DATA_UNORDERED) == 0) { + if ((chk_flags & SCTP_DATA_UNORDERED) == 0) { /* for ordered, bump what we delivered */ - strm->last_mid_delivered++; + asoc->strmin[sid].last_mid_delivered++; } SCTP_STAT_INCR(sctps_recvexpress); if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) { @@ -2026,7 +2057,7 @@ sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct sctp_association *asoc, goto finish_express_del; } /* Now will we need a chunk too? */ - if ((chunk_flags & SCTP_DATA_NOT_FRAG) != SCTP_DATA_NOT_FRAG) { + if ((chk_flags & SCTP_DATA_NOT_FRAG) != SCTP_DATA_NOT_FRAG) { sctp_alloc_a_chunk(stcb, chk); if (chk == NULL) { /* No memory so we drop the chunk */ @@ -2045,7 +2076,7 @@ sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct sctp_association *asoc, chk->rec.data.ppid = ppid; chk->rec.data.context = stcb->asoc.context; chk->rec.data.doing_fast_retransmit = 0; - chk->rec.data.rcv_flags = chunk_flags; + chk->rec.data.rcv_flags = chk_flags; chk->asoc = asoc; chk->send_size = the_len; chk->whoTo = net; @@ -2068,7 +2099,7 @@ sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct sctp_association *asoc, } } /* Now is it complete (i.e. not fragmented)? */ - if ((chunk_flags & SCTP_DATA_NOT_FRAG) == SCTP_DATA_NOT_FRAG) { + if ((chk_flags & SCTP_DATA_NOT_FRAG) == SCTP_DATA_NOT_FRAG) { /* * Special check for when streams are resetting. We could be * more smart about this and check the actual stream to see @@ -2112,7 +2143,7 @@ sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct sctp_association *asoc, } goto finish_express_del; } - if (chunk_flags & SCTP_DATA_UNORDERED) { + if (chk_flags & SCTP_DATA_UNORDERED) { /* queue directly into socket buffer */ SCTPDBG(SCTP_DEBUG_XXX, "Unordered data to be read control: %p MID: %u\n", control, mid); @@ -2125,7 +2156,7 @@ sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct sctp_association *asoc, } else { SCTPDBG(SCTP_DEBUG_XXX, "Queue control: %p for reordering MID: %u\n", control, mid); - sctp_queue_data_to_stream(stcb, strm, asoc, control, abort_flag, &need_reasm_check); + sctp_queue_data_to_stream(stcb, asoc, control, abort_flag, &need_reasm_check); if (*abort_flag) { if (last_chunk) { *m = NULL; @@ -2140,7 +2171,7 @@ sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct sctp_association *asoc, SCTPDBG(SCTP_DEBUG_XXX, "Queue data to stream for reasm control: %p MID: %u\n", control, mid); - sctp_queue_data_for_reasm(stcb, asoc, strm, control, chk, created_control, abort_flag, tsn); + sctp_queue_data_for_reasm(stcb, asoc, control, chk, created_control, abort_flag, tsn); if (*abort_flag) { /* * the assoc is now gone and chk was put onto the reasm @@ -2174,6 +2205,10 @@ finish_express_del: sctp_log_map(asoc->mapping_array_base_tsn, asoc->cumulative_tsn, asoc->highest_tsn_inside_map, SCTP_MAP_PREPARE_SLIDE); } + if (need_reasm_check) { + (void)sctp_deliver_reasm_check(stcb, asoc, &asoc->strmin[sid], SCTP_READ_LOCK_NOT_HELD); + need_reasm_check = 0; + } /* check the special flag for stream resets */ if (((liste = TAILQ_FIRST(&asoc->resetHead)) != NULL) && SCTP_TSN_GE(asoc->cumulative_tsn, liste->tsn)) { @@ -2195,10 +2230,14 @@ finish_express_del: /* All can be removed */ TAILQ_FOREACH_SAFE(ctl, &asoc->pending_reply_queue, next, nctl) { TAILQ_REMOVE(&asoc->pending_reply_queue, ctl, next); - sctp_queue_data_to_stream(stcb, strm, asoc, ctl, abort_flag, &need_reasm_check); + sctp_queue_data_to_stream(stcb, asoc, ctl, abort_flag, &need_reasm_check); if (*abort_flag) { return (0); } + if (need_reasm_check) { + (void)sctp_deliver_reasm_check(stcb, asoc, &asoc->strmin[ctl->sinfo_stream], SCTP_READ_LOCK_NOT_HELD); + need_reasm_check = 0; + } } } else { TAILQ_FOREACH_SAFE(ctl, &asoc->pending_reply_queue, next, nctl) { @@ -2211,22 +2250,16 @@ finish_express_del: * ctl->sinfo_tsn > liste->tsn */ TAILQ_REMOVE(&asoc->pending_reply_queue, ctl, next); - sctp_queue_data_to_stream(stcb, strm, asoc, ctl, abort_flag, &need_reasm_check); + sctp_queue_data_to_stream(stcb, asoc, ctl, abort_flag, &need_reasm_check); if (*abort_flag) { return (0); } + if (need_reasm_check) { + (void)sctp_deliver_reasm_check(stcb, asoc, &asoc->strmin[ctl->sinfo_stream], SCTP_READ_LOCK_NOT_HELD); + need_reasm_check = 0; + } } } - /* - * Now service re-assembly to pick up anything that has been - * held on reassembly queue? - */ - (void)sctp_deliver_reasm_check(stcb, asoc, strm, SCTP_READ_LOCK_NOT_HELD); - need_reasm_check = 0; - } - if (need_reasm_check) { - /* Another one waits ? */ - (void)sctp_deliver_reasm_check(stcb, asoc, strm, SCTP_READ_LOCK_NOT_HELD); } return (1); } @@ -2389,8 +2422,8 @@ sctp_slide_mapping_arrays(struct sctp_tcb *stcb) if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) { sctp_log_map(old_base, old_cumack, old_highest, SCTP_MAP_PREPARE_SLIDE); - sctp_log_map((uint32_t) slide_from, (uint32_t) slide_end, - (uint32_t) lgap, SCTP_MAP_SLIDE_FROM); + sctp_log_map((uint32_t)slide_from, (uint32_t)slide_end, + (uint32_t)lgap, SCTP_MAP_SLIDE_FROM); } if (distance + slide_from > asoc->mapping_array_size || distance < 0) { @@ -2402,8 +2435,8 @@ sctp_slide_mapping_arrays(struct sctp_tcb *stcb) */ if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) { - sctp_log_map((uint32_t) distance, (uint32_t) slide_from, - (uint32_t) asoc->mapping_array_size, + sctp_log_map((uint32_t)distance, (uint32_t)slide_from, + (uint32_t)asoc->mapping_array_size, SCTP_MAP_SLIDE_NONE); } } else { @@ -2439,13 +2472,17 @@ sctp_sack_check(struct sctp_tcb *stcb, int was_a_gap) { struct sctp_association *asoc; uint32_t highest_tsn; + int is_a_gap; + sctp_slide_mapping_arrays(stcb); asoc = &stcb->asoc; if (SCTP_TSN_GT(asoc->highest_tsn_inside_nr_map, asoc->highest_tsn_inside_map)) { highest_tsn = asoc->highest_tsn_inside_nr_map; } else { highest_tsn = asoc->highest_tsn_inside_map; } + /* Is there a gap now? */ + is_a_gap = SCTP_TSN_GT(highest_tsn, stcb->asoc.cumulative_tsn); /* * Now we need to see if we need to queue a sack or just start the @@ -2464,13 +2501,10 @@ sctp_sack_check(struct sctp_tcb *stcb, int was_a_gap) } sctp_send_shutdown(stcb, ((stcb->asoc.alternate) ? stcb->asoc.alternate : stcb->asoc.primary_destination)); - sctp_send_sack(stcb, SCTP_SO_NOT_LOCKED); + if (is_a_gap) { + sctp_send_sack(stcb, SCTP_SO_NOT_LOCKED); + } } else { - int is_a_gap; - - /* is there a gap now ? */ - is_a_gap = SCTP_TSN_GT(highest_tsn, stcb->asoc.cumulative_tsn); - /* * CMT DAC algorithm: increase number of packets received * since last ack @@ -2484,7 +2518,8 @@ sctp_sack_check(struct sctp_tcb *stcb, int was_a_gap) (stcb->asoc.numduptsns) || /* we have dup's */ (is_a_gap) || /* is still a gap */ (stcb->asoc.delayed_ack == 0) || /* Delayed sack disabled */ - (stcb->asoc.data_pkts_seen >= stcb->asoc.sack_freq) /* hit limit of pkts */ ) { + (stcb->asoc.data_pkts_seen >= stcb->asoc.sack_freq) /* hit limit of pkts */ + ) { if ((stcb->asoc.sctp_cmt_on_off > 0) && (SCTP_BASE_SYSCTL(sctp_cmt_use_dac)) && @@ -2527,7 +2562,7 @@ sctp_sack_check(struct sctp_tcb *stcb, int was_a_gap) int sctp_process_data(struct mbuf **mm, int iphlen, int *offset, int length, struct sctp_inpcb *inp, struct sctp_tcb *stcb, - struct sctp_nets *net, uint32_t * high_tsn) + struct sctp_nets *net, uint32_t *high_tsn) { struct sctp_chunkhdr *ch, chunk_buf; struct sctp_association *asoc; @@ -2588,7 +2623,7 @@ sctp_process_data(struct mbuf **mm, int iphlen, int *offset, int length, } /* get pointer to the first chunk header */ ch = (struct sctp_chunkhdr *)sctp_m_getptr(m, *offset, - sizeof(struct sctp_chunkhdr), (uint8_t *) & chunk_buf); + sizeof(struct sctp_chunkhdr), (uint8_t *)&chunk_buf); if (ch == NULL) { return (1); } @@ -2733,7 +2768,7 @@ sctp_process_data(struct mbuf **mm, int iphlen, int *offset, int length, if (op_err != NULL) { cause = mtod(op_err, struct sctp_gen_error_cause *); cause->code = htons(SCTP_CAUSE_UNRECOG_CHUNK); - cause->length = htons((uint16_t) (chk_length + sizeof(struct sctp_gen_error_cause))); + cause->length = htons((uint16_t)(chk_length + sizeof(struct sctp_gen_error_cause))); SCTP_BUF_LEN(op_err) = sizeof(struct sctp_gen_error_cause); SCTP_BUF_NEXT(op_err) = SCTP_M_COPYM(m, *offset, chk_length, M_NOWAIT); if (SCTP_BUF_NEXT(op_err) != NULL) { @@ -2747,7 +2782,8 @@ sctp_process_data(struct mbuf **mm, int iphlen, int *offset, int length, /* discard the rest of this packet */ stop_proc = 1; } /* else skip this bad chunk and - * continue... */ break; + * continue... */ + break; } /* switch of chunk type */ } *offset += SCTP_SIZE32(chk_length); @@ -2757,7 +2793,7 @@ sctp_process_data(struct mbuf **mm, int iphlen, int *offset, int length, continue; } ch = (struct sctp_chunkhdr *)sctp_m_getptr(m, *offset, - sizeof(struct sctp_chunkhdr), (uint8_t *) & chunk_buf); + sizeof(struct sctp_chunkhdr), (uint8_t *)&chunk_buf); if (ch == NULL) { *offset = length; stop_proc = 1; @@ -2800,8 +2836,8 @@ static int sctp_process_segment_range(struct sctp_tcb *stcb, struct sctp_tmit_chunk **p_tp1, uint32_t last_tsn, uint16_t frag_strt, uint16_t frag_end, int nr_sacking, int *num_frs, - uint32_t * biggest_newly_acked_tsn, - uint32_t * this_sack_lowest_newack, + uint32_t *biggest_newly_acked_tsn, + uint32_t *this_sack_lowest_newack, int *rto_ok) { struct sctp_tmit_chunk *tp1; @@ -2922,7 +2958,7 @@ sctp_process_segment_range(struct sctp_tcb *stcb, struct sctp_tmit_chunk **p_tp1 sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_GAP, tp1->whoTo->flight_size, tp1->book_size, - (uint32_t) (uintptr_t) tp1->whoTo, + (uint32_t)(uintptr_t)tp1->whoTo, tp1->rec.data.tsn); } sctp_flight_size_decrease(tp1); @@ -3004,8 +3040,10 @@ sctp_process_segment_range(struct sctp_tcb *stcb, struct sctp_tmit_chunk **p_tp1 } tp1->sent = SCTP_DATAGRAM_NR_ACKED; if (tp1->data) { - /* sa_ignore - * NO_NULL_CHK */ + /* + * sa_ignore + * NO_NULL_CHK + */ sctp_free_bufspace(stcb, &stcb->asoc, tp1, 1); sctp_m_freem(tp1->data); tp1->data = NULL; @@ -3014,7 +3052,8 @@ sctp_process_segment_range(struct sctp_tcb *stcb, struct sctp_tmit_chunk **p_tp1 } } break; - } /* if (tp1->tsn == theTSN) */ if (SCTP_TSN_GT(tp1->rec.data.tsn, theTSN)) { + } /* if (tp1->tsn == theTSN) */ + if (SCTP_TSN_GT(tp1->rec.data.tsn, theTSN)) { break; } tp1 = TAILQ_NEXT(tp1, sctp_next); @@ -3036,8 +3075,8 @@ sctp_process_segment_range(struct sctp_tcb *stcb, struct sctp_tmit_chunk **p_tp1 static int sctp_handle_segments(struct mbuf *m, int *offset, struct sctp_tcb *stcb, struct sctp_association *asoc, - uint32_t last_tsn, uint32_t * biggest_tsn_acked, - uint32_t * biggest_newly_acked_tsn, uint32_t * this_sack_lowest_newack, + uint32_t last_tsn, uint32_t *biggest_tsn_acked, + uint32_t *biggest_newly_acked_tsn, uint32_t *this_sack_lowest_newack, int num_seg, int num_nr_seg, int *rto_ok) { struct sctp_gap_ack_block *frag, block; @@ -3058,7 +3097,7 @@ sctp_handle_segments(struct mbuf *m, int *offset, struct sctp_tcb *stcb, struct tp1 = TAILQ_FIRST(&asoc->sent_queue); } frag = (struct sctp_gap_ack_block *)sctp_m_getptr(m, *offset, - sizeof(struct sctp_gap_ack_block), (uint8_t *) & block); + sizeof(struct sctp_gap_ack_block), (uint8_t *)&block); *offset += sizeof(block); if (frag == NULL) { return (chunk_freed); @@ -3128,7 +3167,7 @@ sctp_check_for_revoked(struct sctp_tcb *stcb, sctp_misc_ints(SCTP_FLIGHT_LOG_UP_REVOKE, tp1->whoTo->flight_size, tp1->book_size, - (uint32_t) (uintptr_t) tp1->whoTo, + (uint32_t)(uintptr_t)tp1->whoTo, tp1->rec.data.tsn); } sctp_flight_size_increase(tp1); @@ -3442,7 +3481,7 @@ sctp_strike_gap_ack_chunks(struct sctp_tcb *stcb, struct sctp_association *asoc, sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_RSND, (tp1->whoTo ? (tp1->whoTo->flight_size) : 0), tp1->book_size, - (uint32_t) (uintptr_t) tp1->whoTo, + (uint32_t)(uintptr_t)tp1->whoTo, tp1->rec.data.tsn); } if (tp1->whoTo) { @@ -3465,8 +3504,10 @@ sctp_strike_gap_ack_chunks(struct sctp_tcb *stcb, struct sctp_association *asoc, if ((stcb->asoc.prsctp_supported) && (PR_SCTP_RTX_ENABLED(tp1->flags))) { - /* Has it been retransmitted tv_sec times? - - * we store the retran count there. */ + /* + * Has it been retransmitted tv_sec times? - + * we store the retran count there. + */ if (tp1->snd_count > tp1->rec.data.timetodrop.tv_sec) { /* Yes, so drop it */ if (tp1->data != NULL) { @@ -3478,8 +3519,10 @@ sctp_strike_gap_ack_chunks(struct sctp_tcb *stcb, struct sctp_association *asoc, continue; } } - /* SCTP_PRINTF("OK, we are now ready to FR this - * guy\n"); */ + /* + * SCTP_PRINTF("OK, we are now ready to FR this + * guy\n"); + */ if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) { sctp_log_fr(tp1->rec.data.tsn, tp1->snd_count, 0, SCTP_FR_MARKED); @@ -3499,14 +3542,18 @@ sctp_strike_gap_ack_chunks(struct sctp_tcb *stcb, struct sctp_association *asoc, alt = tp1->whoTo; /* sa_ignore NO_NULL_CHK */ if (asoc->sctp_cmt_pf > 0) { - /* JRS 5/18/07 - If CMT PF is on, + /* + * JRS 5/18/07 - If CMT PF is on, * use the PF version of - * find_alt_net() */ + * find_alt_net() + */ alt = sctp_find_alternate_net(stcb, alt, 2); } else { - /* JRS 5/18/07 - If only CMT is on, + /* + * JRS 5/18/07 - If only CMT is on, * use the CMT version of - * find_alt_net() */ + * find_alt_net() + */ /* sa_ignore NO_NULL_CHK */ alt = sctp_find_alternate_net(stcb, alt, 1); } @@ -3744,7 +3791,7 @@ sctp_window_probe_recovery(struct sctp_tcb *stcb, sctp_misc_ints(SCTP_FLIGHT_LOG_DWN_WP_FWD, tp1->whoTo ? tp1->whoTo->flight_size : 0, tp1->book_size, - (uint32_t) (uintptr_t) tp1->whoTo, + (uint32_t)(uintptr_t)tp1->whoTo, tp1->rec.data.tsn); return; } @@ -3763,7 +3810,7 @@ sctp_window_probe_recovery(struct sctp_tcb *stcb, sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_WP, tp1->whoTo->flight_size, tp1->book_size, - (uint32_t) (uintptr_t) tp1->whoTo, + (uint32_t)(uintptr_t)tp1->whoTo, tp1->rec.data.tsn); } } @@ -3802,7 +3849,7 @@ sctp_express_handle_sack(struct sctp_tcb *stcb, uint32_t cumack, } else if (asoc->last_acked_seq == cumack) { /* Window update sack */ asoc->peers_rwnd = sctp_sbspace_sub(rwnd, - (uint32_t) (asoc->total_flight + (asoc->total_flight_count * SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)))); + (uint32_t)(asoc->total_flight + (asoc->total_flight_count * SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)))); if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) { /* SWS sender side engages */ asoc->peers_rwnd = 0; @@ -3879,7 +3926,7 @@ sctp_express_handle_sack(struct sctp_tcb *stcb, uint32_t cumack, sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_CA, tp1->whoTo->flight_size, tp1->book_size, - (uint32_t) (uintptr_t) tp1->whoTo, + (uint32_t)(uintptr_t)tp1->whoTo, tp1->rec.data.tsn); } sctp_flight_size_decrease(tp1); @@ -4037,8 +4084,10 @@ sctp_express_handle_sack(struct sctp_tcb *stcb, uint32_t cumack, } if (net == stcb->asoc.primary_destination) { if (stcb->asoc.alternate) { - /* release the alternate, - * primary is good */ + /* + * release the alternate, + * primary is good + */ sctp_free_remote_addr(stcb->asoc.alternate); stcb->asoc.alternate = NULL; } @@ -4078,7 +4127,7 @@ sctp_express_handle_sack(struct sctp_tcb *stcb, uint32_t cumack, } /* RWND update */ asoc->peers_rwnd = sctp_sbspace_sub(rwnd, - (uint32_t) (asoc->total_flight + (asoc->total_flight_count * SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)))); + (uint32_t)(asoc->total_flight + (asoc->total_flight_count * SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)))); if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) { /* SWS sender side engages */ asoc->peers_rwnd = 0; @@ -4121,8 +4170,10 @@ again: } } else { if (net->window_probe) { - /* In window probes we must assure a timer - * is still running there */ + /* + * In window probes we must assure a timer + * is still running there + */ net->window_probe = 0; if (!SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer)) { SCTP_OS_TIMER_START(&net->rxt_timer.timer, to_ticks, @@ -4361,8 +4412,8 @@ sctp_handle_sack(struct mbuf *m, int offset_seg, int offset_dup, uint32_t *dupdata, dblock; for (i = 0; i < num_dup; i++) { - dupdata = (uint32_t *) sctp_m_getptr(m, offset_dup + i * sizeof(uint32_t), - sizeof(uint32_t), (uint8_t *) & dblock); + dupdata = (uint32_t *)sctp_m_getptr(m, offset_dup + i * sizeof(uint32_t), + sizeof(uint32_t), (uint8_t *)&dblock); if (dupdata == NULL) { break; } @@ -4493,7 +4544,7 @@ hopeless_peer: sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_CA, tp1->whoTo->flight_size, tp1->book_size, - (uint32_t) (uintptr_t) tp1->whoTo, + (uint32_t)(uintptr_t)tp1->whoTo, tp1->rec.data.tsn); } sctp_flight_size_decrease(tp1); @@ -4764,7 +4815,7 @@ hopeless_peer: sctp_misc_ints(SCTP_FLIGHT_LOG_UP_REVOKE, tp1->whoTo->flight_size, tp1->book_size, - (uint32_t) (uintptr_t) tp1->whoTo, + (uint32_t)(uintptr_t)tp1->whoTo, tp1->rec.data.tsn); } sctp_flight_size_increase(tp1); @@ -4807,8 +4858,10 @@ hopeless_peer: } if (net == stcb->asoc.primary_destination) { if (stcb->asoc.alternate) { - /* release the alternate, - * primary is good */ + /* + * release the alternate, + * primary is good + */ sctp_free_remote_addr(stcb->asoc.alternate); stcb->asoc.alternate = NULL; } @@ -4977,7 +5030,7 @@ hopeless_peer: asoc->peers_rwnd, asoc->total_flight, (asoc->total_flight_count * SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)), a_rwnd); } asoc->peers_rwnd = sctp_sbspace_sub(a_rwnd, - (uint32_t) (asoc->total_flight + (asoc->total_flight_count * SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)))); + (uint32_t)(asoc->total_flight + (asoc->total_flight_count * SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)))); if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) { /* SWS sender side engages */ asoc->peers_rwnd = 0; @@ -5019,8 +5072,10 @@ again: } } else { if (net->window_probe) { - /* In window probes we must assure a timer - * is still running there */ + /* + * In window probes we must assure a timer + * is still running there + */ if (!SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer)) { sctp_timer_start(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, stcb, net); @@ -5171,8 +5226,10 @@ sctp_kick_prsctp_reorder_queue(struct sctp_tcb *stcb, } else { /* Its a fragmented message */ if (ctl->first_frag_seen) { - /* Make it so this is next to - * deliver, we restore later */ + /* + * Make it so this is next to + * deliver, we restore later + */ strmin->last_mid_delivered = ctl->mid - 1; need_reasm_check = 1; break; @@ -5236,8 +5293,10 @@ sctp_kick_prsctp_reorder_queue(struct sctp_tcb *stcb, } else { /* Its a fragmented message */ if (ctl->first_frag_seen) { - /* Make it so this is next to - * deliver */ + /* + * Make it so this is next to + * deliver + */ strmin->last_mid_delivered = ctl->mid - 1; need_reasm_check = 1; break; @@ -5466,7 +5525,7 @@ sctp_handle_forward_tsn(struct sctp_tcb *stcb, if (asoc->idata_supported) { stseq_m = (struct sctp_strseq_mid *)sctp_m_getptr(m, offset, sizeof(struct sctp_strseq_mid), - (uint8_t *) & strseqbuf_m); + (uint8_t *)&strseqbuf_m); offset += sizeof(struct sctp_strseq_mid); if (stseq_m == NULL) { break; @@ -5482,13 +5541,13 @@ sctp_handle_forward_tsn(struct sctp_tcb *stcb, } else { stseq = (struct sctp_strseq *)sctp_m_getptr(m, offset, sizeof(struct sctp_strseq), - (uint8_t *) & strseqbuf); + (uint8_t *)&strseqbuf); offset += sizeof(struct sctp_strseq); if (stseq == NULL) { break; } sid = ntohs(stseq->sid); - mid = (uint32_t) ntohs(stseq->ssn); + mid = (uint32_t)ntohs(stseq->ssn); ordered = 1; } /* Convert */ diff --git a/freebsd/sys/netinet/sctp_indata.h b/freebsd/sys/netinet/sctp_indata.h index e277ae88..badd269d 100644 --- a/freebsd/sys/netinet/sctp_indata.h +++ b/freebsd/sys/netinet/sctp_indata.h @@ -79,7 +79,7 @@ sctp_build_ctl_nchunk(struct sctp_inpcb *inp, void sctp_set_rwnd(struct sctp_tcb *, struct sctp_association *); uint32_t -sctp_calc_rwnd(struct sctp_tcb *stcb, struct sctp_association *asoc); + sctp_calc_rwnd(struct sctp_tcb *stcb, struct sctp_association *asoc); void sctp_express_handle_sack(struct sctp_tcb *stcb, uint32_t cumack, diff --git a/freebsd/sys/netinet/sctp_input.c b/freebsd/sys/netinet/sctp_input.c index 3c596c48..7e84ebd1 100644 --- a/freebsd/sys/netinet/sctp_input.c +++ b/freebsd/sys/netinet/sctp_input.c @@ -462,7 +462,7 @@ sctp_process_init_ack(struct mbuf *m, int iphlen, int offset, return (-1); } asoc = &stcb->asoc; - asoc->peer_supports_nat = (uint8_t) nat_friendly; + asoc->peer_supports_nat = (uint8_t)nat_friendly; /* process the peer's parameters in the INIT-ACK */ retval = sctp_process_init((struct sctp_init_chunk *)cp, stcb); if (retval < 0) { @@ -534,7 +534,7 @@ sctp_process_init_ack(struct mbuf *m, int iphlen, int offset, if (retval == -3) { uint16_t len; - len = (uint16_t) (sizeof(struct sctp_error_missing_param) + sizeof(uint16_t)); + len = (uint16_t)(sizeof(struct sctp_error_missing_param) + sizeof(uint16_t)); /* We abort with an error of missing mandatory param */ op_err = sctp_get_mbuf_for_msg(len, 0, M_NOWAIT, 1, MT_DATA); if (op_err != NULL) { @@ -709,8 +709,10 @@ sctp_handle_nat_colliding_state(struct sctp_tcb *stcb) LIST_REMOVE(stcb, sctp_asocs); stcb->asoc.my_vtag = sctp_select_a_tag(stcb->sctp_ep, stcb->sctp_ep->sctp_lport, stcb->rport, 1); head = &SCTP_BASE_INFO(sctp_asochash)[SCTP_PCBHASH_ASOC(stcb->asoc.my_vtag, SCTP_BASE_INFO(hashasocmark))]; - /* put it in the bucket in the vtag hash of assoc's for the - * system */ + /* + * put it in the bucket in the vtag hash of assoc's for the + * system + */ LIST_INSERT_HEAD(head, stcb, sctp_asocs); sctp_send_initiate(stcb->sctp_ep, stcb, SCTP_SO_NOT_LOCKED); return (1); @@ -728,8 +730,10 @@ sctp_handle_nat_colliding_state(struct sctp_tcb *stcb) sctp_toss_old_cookies(stcb, &stcb->asoc); stcb->asoc.my_vtag = sctp_select_a_tag(stcb->sctp_ep, stcb->sctp_ep->sctp_lport, stcb->rport, 1); head = &SCTP_BASE_INFO(sctp_asochash)[SCTP_PCBHASH_ASOC(stcb->asoc.my_vtag, SCTP_BASE_INFO(hashasocmark))]; - /* put it in the bucket in the vtag hash of assoc's for the - * system */ + /* + * put it in the bucket in the vtag hash of assoc's for the + * system + */ LIST_INSERT_HEAD(head, stcb, sctp_asocs); sctp_send_initiate(stcb->sctp_ep, stcb, SCTP_SO_NOT_LOCKED); return (1); @@ -939,8 +943,10 @@ sctp_handle_shutdown(struct sctp_shutdown_chunk *cp, (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT)) { SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_RECEIVED); SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING); - /* notify upper layer that peer has initiated a - * shutdown */ + /* + * notify upper layer that peer has initiated a + * shutdown + */ sctp_ulp_notify(SCTP_NOTIFY_PEER_SHUTDOWN, stcb, 0, NULL, SCTP_SO_NOT_LOCKED); /* reset time */ @@ -1101,7 +1107,7 @@ sctp_process_unrecog_chunk(struct sctp_tcb *stcb, struct sctp_paramhdr *phdr, default: SCTPDBG(SCTP_DEBUG_INPUT2, "Peer does not support chunk type %d(%x)??\n", - chk->chunk_type, (uint32_t) chk->chunk_type); + chk->chunk_type, (uint32_t)chk->chunk_type); break; } } @@ -1144,7 +1150,7 @@ sctp_process_unrecog_param(struct sctp_tcb *stcb, struct sctp_paramhdr *phdr) default: SCTPDBG(SCTP_DEBUG_INPUT2, "Peer does not support param type %d(%x)??\n", - pbad->param_type, (uint32_t) pbad->param_type); + pbad->param_type, (uint32_t)pbad->param_type); break; } } @@ -1514,7 +1520,7 @@ sctp_process_cookie_existing(struct mbuf *m, int iphlen, int offset, init_cp = (struct sctp_init_chunk *) sctp_m_getptr(m, init_offset, sizeof(struct sctp_init_chunk), - (uint8_t *) & init_buf); + (uint8_t *)&init_buf); if (init_cp == NULL) { /* could not pull a INIT chunk in cookie */ return (NULL); @@ -1529,7 +1535,7 @@ sctp_process_cookie_existing(struct mbuf *m, int iphlen, int offset, initack_offset = init_offset + SCTP_SIZE32(ntohs(init_cp->ch.chunk_length)); initack_cp = (struct sctp_init_ack_chunk *) sctp_m_getptr(m, initack_offset, sizeof(struct sctp_init_ack_chunk), - (uint8_t *) & initack_buf); + (uint8_t *)&initack_buf); if (initack_cp == NULL) { /* could not pull INIT-ACK chunk in cookie */ return (NULL); @@ -2063,7 +2069,7 @@ sctp_process_cookie_new(struct mbuf *m, int iphlen, int offset, init_offset = offset + sizeof(struct sctp_cookie_echo_chunk); init_cp = (struct sctp_init_chunk *) sctp_m_getptr(m, init_offset, sizeof(struct sctp_init_chunk), - (uint8_t *) & init_buf); + (uint8_t *)&init_buf); if (init_cp == NULL) { /* could not pull a INIT chunk in cookie */ SCTPDBG(SCTP_DEBUG_INPUT1, @@ -2081,7 +2087,7 @@ sctp_process_cookie_new(struct mbuf *m, int iphlen, int offset, */ initack_cp = (struct sctp_init_ack_chunk *) sctp_m_getptr(m, initack_offset, sizeof(struct sctp_init_ack_chunk), - (uint8_t *) & initack_buf); + (uint8_t *)&initack_buf); if (initack_cp == NULL) { /* could not pull INIT-ACK chunk in cookie */ SCTPDBG(SCTP_DEBUG_INPUT1, "process_cookie_new: could not pull INIT-ACK chunk hdr\n"); @@ -2491,17 +2497,17 @@ sctp_handle_cookie_echo(struct mbuf *m, int iphlen, int offset, (ep->current_secret_number != ep->last_secret_number)) { /* it's the old cookie */ (void)sctp_hmac_m(SCTP_HMAC, - (uint8_t *) ep->secret_key[(int)ep->last_secret_number], + (uint8_t *)ep->secret_key[(int)ep->last_secret_number], SCTP_SECRET_SIZE, m, cookie_offset, calc_sig, 0); } else { /* it's the current cookie */ (void)sctp_hmac_m(SCTP_HMAC, - (uint8_t *) ep->secret_key[(int)ep->current_secret_number], + (uint8_t *)ep->secret_key[(int)ep->current_secret_number], SCTP_SECRET_SIZE, m, cookie_offset, calc_sig, 0); } /* get the signature */ SCTP_INP_RUNLOCK(l_inp); - sig = (uint8_t *) sctp_m_getptr(m_sig, 0, SCTP_SIGNATURE_SIZE, (uint8_t *) & tmp_sig); + sig = (uint8_t *)sctp_m_getptr(m_sig, 0, SCTP_SIGNATURE_SIZE, (uint8_t *)&tmp_sig); if (sig == NULL) { /* couldn't find signature */ sctp_m_freem(m_sig); @@ -2514,7 +2520,7 @@ sctp_handle_cookie_echo(struct mbuf *m, int iphlen, int offset, (ep->current_secret_number != ep->last_secret_number)) { /* compute digest with old */ (void)sctp_hmac_m(SCTP_HMAC, - (uint8_t *) ep->secret_key[(int)ep->last_secret_number], + (uint8_t *)ep->secret_key[(int)ep->last_secret_number], SCTP_SECRET_SIZE, m, cookie_offset, calc_sig, 0); /* compare */ if (memcmp(calc_sig, sig, SCTP_SIGNATURE_SIZE) == 0) @@ -2542,7 +2548,7 @@ sctp_handle_cookie_echo(struct mbuf *m, int iphlen, int offset, SCTPDBG(SCTP_DEBUG_INPUT2, "handle_cookie_echo: cookie signature validation failed!\n"); SCTPDBG(SCTP_DEBUG_INPUT2, "offset = %u, cookie_offset = %u, sig_offset = %u\n", - (uint32_t) offset, cookie_offset, sig_offset); + (uint32_t)offset, cookie_offset, sig_offset); return (NULL); } /* @@ -2863,8 +2869,10 @@ sctp_handle_cookie_echo(struct mbuf *m, int iphlen, int offset, sctp_ulp_notify(SCTP_NOTIFY_INTERFACE_CONFIRMED, (*stcb), 0, (void *)netl, SCTP_SO_NOT_LOCKED); } - /* Pull it from the incomplete queue and wake the - * guy */ + /* + * Pull it from the incomplete queue and wake the + * guy + */ #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING) atomic_add_int(&(*stcb)->asoc.refcnt, 1); SCTP_TCB_UNLOCK((*stcb)); @@ -3076,8 +3084,10 @@ sctp_handle_ecn_echo(struct sctp_ecne_chunk *cp, } if (SCTP_TSN_GT(tsn, net->cwr_window_tsn) && ((override_bit & SCTP_CWR_REDUCE_OVERRIDE) == 0)) { - /* JRS - Use the congestion control given in the pluggable - * CC module */ + /* + * JRS - Use the congestion control given in the pluggable + * CC module + */ stcb->asoc.cc_functions.sctp_cwnd_update_after_ecn_echo(stcb, net, 0, pkt_cnt); /* * We reduce once every RTT. So we will only lower cwnd at @@ -3273,7 +3283,7 @@ process_chunk_drop(struct sctp_tcb *stcb, struct sctp_chunk_desc *desc, SCTP_STAT_INCR(sctps_pdrpdizrw); return (0); } - ddp = (uint8_t *) (mtod(tp1->data, caddr_t)+ + ddp = (uint8_t *)(mtod(tp1->data, caddr_t)+ sizeof(struct sctp_data_chunk)); { unsigned int iii; @@ -3328,7 +3338,7 @@ process_chunk_drop(struct sctp_tcb *stcb, struct sctp_chunk_desc *desc, sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_PDRP, tp1->whoTo->flight_size, tp1->book_size, - (uint32_t) (uintptr_t) stcb, + (uint32_t)(uintptr_t)stcb, tp1->rec.data.tsn); } if (tp1->sent < SCTP_DATAGRAM_RESEND) { @@ -3400,8 +3410,10 @@ process_chunk_drop(struct sctp_tcb *stcb, struct sctp_chunk_desc *desc, case SCTP_HEARTBEAT_REQUEST: /* resend a demand HB */ if ((stcb->asoc.overall_error_count + 3) < stcb->asoc.max_send_times) { - /* Only retransmit if we KNOW we wont destroy the - * tcb */ + /* + * Only retransmit if we KNOW we wont destroy the + * tcb + */ sctp_send_hb(stcb, net, SCTP_SO_NOT_LOCKED); } break; @@ -3457,7 +3469,7 @@ process_chunk_drop(struct sctp_tcb *stcb, struct sctp_chunk_desc *desc, } void -sctp_reset_in_stream(struct sctp_tcb *stcb, uint32_t number_entries, uint16_t * list) +sctp_reset_in_stream(struct sctp_tcb *stcb, uint32_t number_entries, uint16_t *list) { uint32_t i; uint16_t temp; @@ -3485,7 +3497,7 @@ sctp_reset_in_stream(struct sctp_tcb *stcb, uint32_t number_entries, uint16_t * } static void -sctp_reset_out_streams(struct sctp_tcb *stcb, uint32_t number_entries, uint16_t * list) +sctp_reset_out_streams(struct sctp_tcb *stcb, uint32_t number_entries, uint16_t *list) { uint32_t i; uint16_t temp; @@ -3510,7 +3522,7 @@ sctp_reset_out_streams(struct sctp_tcb *stcb, uint32_t number_entries, uint16_t } static void -sctp_reset_clear_pending(struct sctp_tcb *stcb, uint32_t number_entries, uint16_t * list) +sctp_reset_clear_pending(struct sctp_tcb *stcb, uint32_t number_entries, uint16_t *list) { uint32_t i; uint16_t temp; @@ -3642,8 +3654,10 @@ sctp_handle_stream_reset_response(struct sctp_tcb *stcb, } else if (action == SCTP_STREAM_RESET_RESULT_DENIED) { sctp_ulp_notify(SCTP_NOTIFY_STR_RESET_DENIED_OUT, stcb, number_entries, req_out_param->list_of_streams, SCTP_SO_NOT_LOCKED); } else if (action == SCTP_STREAM_RESET_RESULT_IN_PROGRESS) { - /* Set it up so we don't stop - * retransmitting */ + /* + * Set it up so we don't stop + * retransmitting + */ asoc->stream_reset_outstanding++; stcb->asoc.str_reset_seq_out--; asoc->stream_reset_out_is_outstanding = 1; @@ -3745,8 +3759,8 @@ sctp_handle_stream_reset_response(struct sctp_tcb *stcb, stcb->asoc.sending_seq = ntohl(resp->receivers_next_tsn); stcb->asoc.last_acked_seq = stcb->asoc.cumulative_tsn; - sctp_reset_out_streams(stcb, 0, (uint16_t *) NULL); - sctp_reset_in_stream(stcb, 0, (uint16_t *) NULL); + sctp_reset_out_streams(stcb, 0, (uint16_t *)NULL); + sctp_reset_in_stream(stcb, 0, (uint16_t *)NULL); sctp_notify_stream_reset_tsn(stcb, stcb->asoc.sending_seq, (stcb->asoc.mapping_array_base_tsn + 1), 0); } else if (action == SCTP_STREAM_RESET_RESULT_DENIED) { sctp_notify_stream_reset_tsn(stcb, stcb->asoc.sending_seq, (stcb->asoc.mapping_array_base_tsn + 1), @@ -3879,8 +3893,8 @@ sctp_handle_str_reset_request_tsn(struct sctp_tcb *stcb, asoc->last_sending_seq[0] = asoc->sending_seq; asoc->last_base_tsnsent[1] = asoc->last_base_tsnsent[0]; asoc->last_base_tsnsent[0] = asoc->mapping_array_base_tsn; - sctp_reset_out_streams(stcb, 0, (uint16_t *) NULL); - sctp_reset_in_stream(stcb, 0, (uint16_t *) NULL); + sctp_reset_out_streams(stcb, 0, (uint16_t *)NULL); + sctp_reset_in_stream(stcb, 0, (uint16_t *)NULL); asoc->last_reset_action[0] = SCTP_STREAM_RESET_RESULT_PERFORMED; sctp_notify_stream_reset_tsn(stcb, asoc->sending_seq, (asoc->mapping_array_base_tsn + 1), 0); } @@ -4129,9 +4143,9 @@ sctp_handle_str_reset_add_out_strm(struct sctp_tcb *stcb, struct sctp_tmit_chunk #ifdef __GNUC__ __attribute__((noinline)) #endif - static int - sctp_handle_stream_reset(struct sctp_tcb *stcb, struct mbuf *m, int offset, - struct sctp_chunkhdr *ch_req) +static int +sctp_handle_stream_reset(struct sctp_tcb *stcb, struct mbuf *m, int offset, + struct sctp_chunkhdr *ch_req) { uint16_t remaining_length, param_len, ptype; struct sctp_paramhdr pstore; @@ -4185,7 +4199,7 @@ strres_nochunk: SCTP_BUF_LEN(chk->data) = SCTP_SIZE32(chk->send_size); offset += sizeof(struct sctp_chunkhdr); while (remaining_length >= sizeof(struct sctp_paramhdr)) { - ph = (struct sctp_paramhdr *)sctp_m_getptr(m, offset, sizeof(pstore), (uint8_t *) & pstore); + ph = (struct sctp_paramhdr *)sctp_m_getptr(m, offset, sizeof(pstore), (uint8_t *)&pstore); if (ph == NULL) { /* TSNH */ break; @@ -4197,7 +4211,7 @@ strres_nochunk: break; } ph = (struct sctp_paramhdr *)sctp_m_getptr(m, offset, min(param_len, sizeof(cstore)), - (uint8_t *) & cstore); + (uint8_t *)&cstore); if (ph == NULL) { /* TSNH */ break; @@ -4330,7 +4344,7 @@ sctp_handle_packet_dropped(struct sctp_pktdrop_chunk *cp, /* XXX possible chlen underflow */ memset(&desc, 0, sizeof(desc)); } - trunc_len = (uint16_t) ntohs(cp->trunc_len); + trunc_len = (uint16_t)ntohs(cp->trunc_len); if (trunc_len > limit) { trunc_len = limit; } @@ -4376,7 +4390,7 @@ sctp_handle_packet_dropped(struct sctp_pktdrop_chunk *cp, unsigned int iii; dcp = (struct sctp_data_chunk *)ch; - ddp = (uint8_t *) (dcp + 1); + ddp = (uint8_t *)(dcp + 1); for (iii = 0; iii < sizeof(desc.data_bytes); iii++) { desc.data_bytes[iii] = ddp[iii]; } @@ -4467,13 +4481,13 @@ sctp_handle_packet_dropped(struct sctp_pktdrop_chunk *cp, #ifdef __GNUC__ __attribute__((noinline)) #endif - static struct sctp_tcb * - sctp_process_control(struct mbuf *m, int iphlen, int *offset, int length, - struct sockaddr *src, struct sockaddr *dst, - struct sctphdr *sh, struct sctp_chunkhdr *ch, struct sctp_inpcb *inp, - struct sctp_tcb *stcb, struct sctp_nets **netp, int *fwd_tsn_seen, - uint8_t mflowtype, uint32_t mflowid, uint16_t fibnum, - uint32_t vrf_id, uint16_t port) +static struct sctp_tcb * +sctp_process_control(struct mbuf *m, int iphlen, int *offset, int length, + struct sockaddr *src, struct sockaddr *dst, + struct sctphdr *sh, struct sctp_chunkhdr *ch, struct sctp_inpcb *inp, + struct sctp_tcb *stcb, struct sctp_nets **netp, int *fwd_tsn_seen, + uint8_t mflowtype, uint32_t mflowid, uint16_t fibnum, + uint32_t vrf_id, uint16_t port) { struct sctp_association *asoc; struct mbuf *op_err; @@ -4697,8 +4711,10 @@ __attribute__((noinline)) return (NULL); } } - } /* end if !SCTP_COOKIE_ECHO *//* process all - * control chunks... */ + } /* end if !SCTP_COOKIE_ECHO */ + /* + * process all control chunks... + */ if (((ch->chunk_type == SCTP_SELECTIVE_ACK) || (ch->chunk_type == SCTP_NR_SELECTIVE_ACK) || (ch->chunk_type == SCTP_HEARTBEAT_REQUEST)) && @@ -4945,7 +4961,7 @@ process_control_chunks: cum_ack = ntohl(sack->sack.cum_tsn_ack); num_seg = ntohs(sack->sack.num_gap_ack_blks); num_dup = ntohs(sack->sack.num_dup_tsns); - a_rwnd = (uint32_t) ntohl(sack->sack.a_rwnd); + a_rwnd = (uint32_t)ntohl(sack->sack.a_rwnd); if (sizeof(struct sctp_sack_chunk) + num_seg * sizeof(struct sctp_gap_ack_block) + num_dup * sizeof(uint32_t) != chk_length) { @@ -4992,8 +5008,10 @@ process_control_chunks: } } break; - /* EY - nr_sack: If the received chunk is an - * nr_sack chunk */ + /* + * EY - nr_sack: If the received chunk is an + * nr_sack chunk + */ case SCTP_NR_SELECTIVE_ACK: { struct sctp_nr_sack_chunk *nr_sack; @@ -5030,7 +5048,7 @@ process_control_chunks: num_seg = ntohs(nr_sack->nr_sack.num_gap_ack_blks); num_nr_seg = ntohs(nr_sack->nr_sack.num_nr_gap_ack_blks); num_dup = ntohs(nr_sack->nr_sack.num_dup_tsns); - a_rwnd = (uint32_t) ntohl(nr_sack->nr_sack.a_rwnd); + a_rwnd = (uint32_t)ntohl(nr_sack->nr_sack.a_rwnd); if (sizeof(struct sctp_nr_sack_chunk) + (num_seg + num_nr_seg) * sizeof(struct sctp_gap_ack_block) + num_dup * sizeof(uint32_t) != chk_length) { @@ -5589,10 +5607,10 @@ process_control_chunks: op_err = sctp_get_mbuf_for_msg(sizeof(struct sctp_gen_error_cause), 0, M_NOWAIT, 1, MT_DATA); if (op_err != NULL) { - len = min(SCTP_SIZE32(chk_length), (uint32_t) (length - *offset)); + len = min(SCTP_SIZE32(chk_length), (uint32_t)(length - *offset)); cause = mtod(op_err, struct sctp_gen_error_cause *); cause->code = htons(SCTP_CAUSE_UNRECOG_CHUNK); - cause->length = htons((uint16_t) (len + sizeof(struct sctp_gen_error_cause))); + cause->length = htons((uint16_t)(len + sizeof(struct sctp_gen_error_cause))); SCTP_BUF_LEN(op_err) = sizeof(struct sctp_gen_error_cause); SCTP_BUF_NEXT(op_err) = SCTP_M_COPYM(m, *offset, len, M_NOWAIT); if (SCTP_BUF_NEXT(op_err) != NULL) { @@ -5611,7 +5629,8 @@ process_control_chunks: /* discard this packet */ *offset = length; return (stcb); - } /* else skip this bad chunk and continue... */ break; + } /* else skip this bad chunk and continue... */ + break; } /* switch (ch->chunk_type) */ diff --git a/freebsd/sys/netinet/sctp_input.h b/freebsd/sys/netinet/sctp_input.h index 148864b6..25df0f3b 100644 --- a/freebsd/sys/netinet/sctp_input.h +++ b/freebsd/sys/netinet/sctp_input.h @@ -54,7 +54,7 @@ sctp_find_stream_reset(struct sctp_tcb *stcb, uint32_t seq, void sctp_reset_in_stream(struct sctp_tcb *stcb, uint32_t number_entries, - uint16_t * list); + uint16_t *list); int sctp_is_there_unsent_data(struct sctp_tcb *stcb, int so_locked); diff --git a/freebsd/sys/netinet/sctp_output.c b/freebsd/sys/netinet/sctp_output.c index 94f9d866..a27f2a3e 100644 --- a/freebsd/sys/netinet/sctp_output.c +++ b/freebsd/sys/netinet/sctp_output.c @@ -1939,7 +1939,7 @@ sctp_is_address_in_scope(struct sctp_ifa *ifa, } static struct mbuf * -sctp_add_addr_to_mbuf(struct mbuf *m, struct sctp_ifa *ifa, uint16_t * len) +sctp_add_addr_to_mbuf(struct mbuf *m, struct sctp_ifa *ifa, uint16_t *len) { #if defined(INET) || defined(INET6) struct sctp_paramhdr *parmh; @@ -1950,12 +1950,12 @@ sctp_add_addr_to_mbuf(struct mbuf *m, struct sctp_ifa *ifa, uint16_t * len) switch (ifa->address.sa.sa_family) { #ifdef INET case AF_INET: - plen = (uint16_t) sizeof(struct sctp_ipv4addr_param); + plen = (uint16_t)sizeof(struct sctp_ipv4addr_param); break; #endif #ifdef INET6 case AF_INET6: - plen = (uint16_t) sizeof(struct sctp_ipv6addr_param); + plen = (uint16_t)sizeof(struct sctp_ipv6addr_param); break; #endif default: @@ -2030,7 +2030,7 @@ struct mbuf * sctp_add_addresses_to_i_ia(struct sctp_inpcb *inp, struct sctp_tcb *stcb, struct sctp_scoping *scope, struct mbuf *m_at, int cnt_inits_to, - uint16_t * padding_len, uint16_t * chunk_len) + uint16_t *padding_len, uint16_t *chunk_len) { struct sctp_vrf *vrf = NULL; int cnt, limit_out = 0, total_count; @@ -2140,8 +2140,10 @@ skip_count: cnt++; total_count++; if (cnt >= 2) { - /* two from each - * address */ + /* + * two from each + * address + */ break; } if (total_count > SCTP_ADDRESS_LIMIT) { @@ -2452,7 +2454,7 @@ sctp_is_addr_in_ep(struct sctp_inpcb *inp, struct sctp_ifa *ifa) static struct sctp_ifa * sctp_choose_boundspecific_inp(struct sctp_inpcb *inp, - sctp_route_t * ro, + sctp_route_t *ro, uint32_t vrf_id, int non_asoc_addr_ok, uint8_t dest_is_priv, @@ -2584,7 +2586,7 @@ once_again_too: static struct sctp_ifa * sctp_choose_boundspecific_stcb(struct sctp_inpcb *inp, struct sctp_tcb *stcb, - sctp_route_t * ro, + sctp_route_t *ro, uint32_t vrf_id, uint8_t dest_is_priv, uint8_t dest_is_loop, @@ -2778,7 +2780,7 @@ sctp_select_nth_preferred_addr_from_ifn_boundall(struct sctp_ifn *ifn, uint8_t dest_is_priv, int addr_wanted, sa_family_t fam, - sctp_route_t * ro + sctp_route_t *ro ) { struct sctp_ifa *ifa, *sifa; @@ -2827,8 +2829,10 @@ sctp_select_nth_preferred_addr_from_ifn_boundall(struct sctp_ifn *ifn, if (fam == AF_INET6 && IN6_IS_ADDR_LINKLOCAL(&sifa->address.sin6.sin6_addr) && IN6_IS_ADDR_LINKLOCAL(&sin6.sin6_addr)) { - /* link-local <-> link-local must belong to the same - * scope. */ + /* + * link-local <-> link-local must belong to the same + * scope. + */ memcpy(&lsa6, &sifa->address.sin6, sizeof(struct sockaddr_in6)); (void)sa6_recoverscope(&lsa6); if (sin6.sin6_scope_id != lsa6.sin6_scope_id) { @@ -2949,7 +2953,7 @@ static struct sctp_ifa * sctp_choose_boundall(struct sctp_inpcb *inp, struct sctp_tcb *stcb, struct sctp_nets *net, - sctp_route_t * ro, + sctp_route_t *ro, uint32_t vrf_id, uint8_t dest_is_priv, uint8_t dest_is_loop, @@ -3302,7 +3306,7 @@ out: struct sctp_ifa * sctp_source_address_selection(struct sctp_inpcb *inp, struct sctp_tcb *stcb, - sctp_route_t * ro, + sctp_route_t *ro, struct sctp_nets *net, int non_asoc_addr_ok, uint32_t vrf_id) { @@ -3810,7 +3814,7 @@ sctp_findassociation_cmsgs(struct sctp_inpcb **inp_p, static struct mbuf * sctp_add_cookie(struct mbuf *init, int init_offset, - struct mbuf *initack, int initack_offset, struct sctp_state_cookie *stc_in, uint8_t ** signature) + struct mbuf *initack, int initack_offset, struct sctp_state_cookie *stc_in, uint8_t **signature) { struct mbuf *copy_init, *copy_initack, *m_at, *sig, *mret; struct sctp_state_cookie *stc; @@ -3889,7 +3893,7 @@ sctp_add_cookie(struct mbuf *init, int init_offset, SCTP_BUF_LEN(sig) = 0; SCTP_BUF_NEXT(m_at) = sig; sig_offset = 0; - foo = (uint8_t *) (mtod(sig, caddr_t)+sig_offset); + foo = (uint8_t *)(mtod(sig, caddr_t)+sig_offset); memset(foo, 0, SCTP_SIGNATURE_SIZE); *signature = foo; SCTP_BUF_LEN(sig) += SCTP_SIGNATURE_SIZE; @@ -4102,7 +4106,7 @@ sctp_lowlevel_chunk_output(struct sctp_inpcb *inp, memset(&iproute, 0, sizeof(iproute)); memcpy(&ro->ro_dst, to, to->sa_len); } else { - ro = (sctp_route_t *) & net->ro; + ro = (sctp_route_t *)&net->ro; } /* Now the address selection part */ ip->ip_dst.s_addr = ((struct sockaddr_in *)to)->sin_addr.s_addr; @@ -4165,7 +4169,7 @@ sctp_lowlevel_chunk_output(struct sctp_inpcb *inp, udp = (struct udphdr *)((caddr_t)ip + sizeof(struct ip)); udp->uh_sport = htons(SCTP_BASE_SYSCTL(sctp_udp_tunneling_port)); udp->uh_dport = port; - udp->uh_ulen = htons((uint16_t) (packet_length - sizeof(struct ip))); + udp->uh_ulen = htons((uint16_t)(packet_length - sizeof(struct ip))); if (V_udp_cksum) { udp->uh_sum = in_pseudo(ip->ip_src.s_addr, ip->ip_dst.s_addr, udp->uh_ulen + htons(IPPROTO_UDP)); } else { @@ -4203,9 +4207,9 @@ sctp_lowlevel_chunk_output(struct sctp_inpcb *inp, memcpy(&iproute, ro, sizeof(*ro)); } SCTPDBG(SCTP_DEBUG_OUTPUT3, "Calling ipv4 output routine from low level src addr:%x\n", - (uint32_t) (ntohl(ip->ip_src.s_addr))); + (uint32_t)(ntohl(ip->ip_src.s_addr))); SCTPDBG(SCTP_DEBUG_OUTPUT3, "Destination is %x\n", - (uint32_t) (ntohl(ip->ip_dst.s_addr))); + (uint32_t)(ntohl(ip->ip_dst.s_addr))); SCTPDBG(SCTP_DEBUG_OUTPUT3, "RTP route is %p through\n", (void *)ro->ro_rt); @@ -4266,8 +4270,10 @@ sctp_lowlevel_chunk_output(struct sctp_inpcb *inp, /* free tempy routes */ RO_RTFREE(ro); } else { - /* PMTU check versus smallest asoc MTU goes - * here */ + /* + * PMTU check versus smallest asoc MTU goes + * here + */ if ((ro->ro_rt != NULL) && (net->ro._s_addr)) { uint32_t mtu; @@ -4359,10 +4365,10 @@ sctp_lowlevel_chunk_output(struct sctp_inpcb *inp, } if (net == NULL) { memset(&ip6route, 0, sizeof(ip6route)); - ro = (sctp_route_t *) & ip6route; + ro = (sctp_route_t *)&ip6route; memcpy(&ro->ro_dst, sin6, sin6->sin6_len); } else { - ro = (sctp_route_t *) & net->ro; + ro = (sctp_route_t *)&net->ro; } /* * We assume here that inp_flow is in host byte @@ -4391,7 +4397,7 @@ sctp_lowlevel_chunk_output(struct sctp_inpcb *inp, } else { ip6h->ip6_nxt = IPPROTO_SCTP; } - ip6h->ip6_plen = (uint16_t) (packet_length - sizeof(struct ip6_hdr)); + ip6h->ip6_plen = (uint16_t)(packet_length - sizeof(struct ip6_hdr)); ip6h->ip6_dst = sin6->sin6_addr; /* @@ -4510,7 +4516,7 @@ sctp_lowlevel_chunk_output(struct sctp_inpcb *inp, udp = (struct udphdr *)((caddr_t)ip6h + sizeof(struct ip6_hdr)); udp->uh_sport = htons(SCTP_BASE_SYSCTL(sctp_udp_tunneling_port)); udp->uh_dport = port; - udp->uh_ulen = htons((uint16_t) (packet_length - sizeof(struct ip6_hdr))); + udp->uh_ulen = htons((uint16_t)(packet_length - sizeof(struct ip6_hdr))); udp->uh_sum = 0; sctphdr = (struct sctphdr *)((caddr_t)udp + sizeof(struct udphdr)); } else { @@ -4542,8 +4548,10 @@ sctp_lowlevel_chunk_output(struct sctp_inpcb *inp, SCTPDBG_ADDR(SCTP_DEBUG_OUTPUT3, (struct sockaddr *)sin6); if (net) { sin6 = (struct sockaddr_in6 *)&net->ro._l_addr; - /* preserve the port and scope for link - * local send */ + /* + * preserve the port and scope for link + * local send + */ prev_scope = sin6->sin6_scope_id; prev_port = sin6->sin6_port; } @@ -4609,8 +4617,10 @@ sctp_lowlevel_chunk_output(struct sctp_inpcb *inp, /* Now if we had a temp route free it */ RO_RTFREE(ro); } else { - /* PMTU check versus smallest asoc MTU goes - * here */ + /* + * PMTU check versus smallest asoc MTU goes + * here + */ if (ro->ro_rt == NULL) { /* Route was freed */ if (net->ro._s_addr && @@ -4670,7 +4680,7 @@ sctp_send_initiate(struct sctp_inpcb *inp, struct sctp_tcb *stcb, int so_locked struct sctp_supported_chunk_types_param *pr_supported; struct sctp_paramhdr *ph; int cnt_inits_to = 0; - int ret; + int error; uint16_t num_ext, chunk_len, padding_len, parameter_len; /* INIT's always go to the primary (and usually ONLY address) */ @@ -4713,7 +4723,7 @@ sctp_send_initiate(struct sctp_inpcb *inp, struct sctp_tcb *stcb, int so_locked SCTPDBG(SCTP_DEBUG_OUTPUT4, "Sending INIT - mbuf?\n"); return; } - chunk_len = (uint16_t) sizeof(struct sctp_init_chunk); + chunk_len = (uint16_t)sizeof(struct sctp_init_chunk); padding_len = 0; /* Now lets put the chunk header in place */ init = mtod(m, struct sctp_init_chunk *); @@ -4733,7 +4743,7 @@ sctp_send_initiate(struct sctp_inpcb *inp, struct sctp_tcb *stcb, int so_locked /* Adaptation layer indication parameter */ if (inp->sctp_ep.adaptation_layer_indicator_provided) { - parameter_len = (uint16_t) sizeof(struct sctp_adaptation_layer_indication); + parameter_len = (uint16_t)sizeof(struct sctp_adaptation_layer_indication); ali = (struct sctp_adaptation_layer_indication *)(mtod(m, caddr_t)+chunk_len); ali->ph.param_type = htons(SCTP_ULP_ADAPTATION); ali->ph.param_length = htons(parameter_len); @@ -4742,7 +4752,7 @@ sctp_send_initiate(struct sctp_inpcb *inp, struct sctp_tcb *stcb, int so_locked } /* ECN parameter */ if (stcb->asoc.ecn_supported == 1) { - parameter_len = (uint16_t) sizeof(struct sctp_paramhdr); + parameter_len = (uint16_t)sizeof(struct sctp_paramhdr); ph = (struct sctp_paramhdr *)(mtod(m, caddr_t)+chunk_len); ph->param_type = htons(SCTP_ECN_CAPABLE); ph->param_length = htons(parameter_len); @@ -4750,7 +4760,7 @@ sctp_send_initiate(struct sctp_inpcb *inp, struct sctp_tcb *stcb, int so_locked } /* PR-SCTP supported parameter */ if (stcb->asoc.prsctp_supported == 1) { - parameter_len = (uint16_t) sizeof(struct sctp_paramhdr); + parameter_len = (uint16_t)sizeof(struct sctp_paramhdr); ph = (struct sctp_paramhdr *)(mtod(m, caddr_t)+chunk_len); ph->param_type = htons(SCTP_PRSCTP_SUPPORTED); ph->param_length = htons(parameter_len); @@ -4758,7 +4768,7 @@ sctp_send_initiate(struct sctp_inpcb *inp, struct sctp_tcb *stcb, int so_locked } /* Add NAT friendly parameter. */ if (SCTP_BASE_SYSCTL(sctp_inits_include_nat_friendly)) { - parameter_len = (uint16_t) sizeof(struct sctp_paramhdr); + parameter_len = (uint16_t)sizeof(struct sctp_paramhdr); ph = (struct sctp_paramhdr *)(mtod(m, caddr_t)+chunk_len); ph->param_type = htons(SCTP_HAS_NAT_SUPPORT); ph->param_length = htons(parameter_len); @@ -4793,7 +4803,7 @@ sctp_send_initiate(struct sctp_inpcb *inp, struct sctp_tcb *stcb, int so_locked pr_supported->chunk_types[num_ext++] = SCTP_PACKET_DROPPED; } if (num_ext > 0) { - parameter_len = (uint16_t) sizeof(struct sctp_supported_chunk_types_param) + num_ext; + parameter_len = (uint16_t)sizeof(struct sctp_supported_chunk_types_param) + num_ext; pr_supported->ph.param_type = htons(SCTP_SUPPORTED_CHUNK_EXT); pr_supported->ph.param_length = htons(parameter_len); padding_len = SCTP_SIZE32(parameter_len) - parameter_len; @@ -4811,7 +4821,7 @@ sctp_send_initiate(struct sctp_inpcb *inp, struct sctp_tcb *stcb, int so_locked padding_len = 0; } randp = (struct sctp_auth_random *)(mtod(m, caddr_t)+chunk_len); - parameter_len = (uint16_t) sizeof(struct sctp_auth_random) + stcb->asoc.authinfo.random_len; + parameter_len = (uint16_t)sizeof(struct sctp_auth_random) + stcb->asoc.authinfo.random_len; /* random key already contains the header */ memcpy(randp, stcb->asoc.authinfo.random->key, parameter_len); padding_len = SCTP_SIZE32(parameter_len) - parameter_len; @@ -4827,11 +4837,11 @@ sctp_send_initiate(struct sctp_inpcb *inp, struct sctp_tcb *stcb, int so_locked padding_len = 0; } hmacs = (struct sctp_auth_hmac_algo *)(mtod(m, caddr_t)+chunk_len); - parameter_len = (uint16_t) (sizeof(struct sctp_auth_hmac_algo) + + parameter_len = (uint16_t)(sizeof(struct sctp_auth_hmac_algo) + stcb->asoc.local_hmacs->num_algo * sizeof(uint16_t)); hmacs->ph.param_type = htons(SCTP_HMAC_LIST); hmacs->ph.param_length = htons(parameter_len); - sctp_serialize_hmaclist(stcb->asoc.local_hmacs, (uint8_t *) hmacs->hmac_ids); + sctp_serialize_hmaclist(stcb->asoc.local_hmacs, (uint8_t *)hmacs->hmac_ids); padding_len = SCTP_SIZE32(parameter_len) - parameter_len; chunk_len += parameter_len; } @@ -4845,7 +4855,7 @@ sctp_send_initiate(struct sctp_inpcb *inp, struct sctp_tcb *stcb, int so_locked padding_len = 0; } chunks = (struct sctp_auth_chunk_list *)(mtod(m, caddr_t)+chunk_len); - parameter_len = (uint16_t) (sizeof(struct sctp_auth_chunk_list) + + parameter_len = (uint16_t)(sizeof(struct sctp_auth_chunk_list) + sctp_auth_get_chklist_size(stcb->asoc.local_auth_chunks)); chunks->ph.param_type = htons(SCTP_CHUNK_LIST); chunks->ph.param_length = htons(parameter_len); @@ -4863,7 +4873,7 @@ sctp_send_initiate(struct sctp_inpcb *inp, struct sctp_tcb *stcb, int so_locked chunk_len += padding_len; padding_len = 0; } - parameter_len = (uint16_t) sizeof(struct sctp_cookie_perserve_param); + parameter_len = (uint16_t)sizeof(struct sctp_cookie_perserve_param); cookie_preserve = (struct sctp_cookie_perserve_param *)(mtod(m, caddr_t)+chunk_len); cookie_preserve->ph.param_type = htons(SCTP_COOKIE_PRESERVE); cookie_preserve->ph.param_length = htons(parameter_len); @@ -4879,12 +4889,12 @@ sctp_send_initiate(struct sctp_inpcb *inp, struct sctp_tcb *stcb, int so_locked chunk_len += padding_len; padding_len = 0; } - parameter_len = (uint16_t) sizeof(struct sctp_paramhdr); + parameter_len = (uint16_t)sizeof(struct sctp_paramhdr); if (stcb->asoc.scope.ipv4_addr_legal) { - parameter_len += (uint16_t) sizeof(uint16_t); + parameter_len += (uint16_t)sizeof(uint16_t); } if (stcb->asoc.scope.ipv6_addr_legal) { - parameter_len += (uint16_t) sizeof(uint16_t); + parameter_len += (uint16_t)sizeof(uint16_t); } sup_addr = (struct sctp_supported_addr_param *)(mtod(m, caddr_t)+chunk_len); sup_addr->ph.param_type = htons(SCTP_SUPPORTED_ADDRTYPE); @@ -4919,14 +4929,21 @@ sctp_send_initiate(struct sctp_inpcb *inp, struct sctp_tcb *stcb, int so_locked } } SCTPDBG(SCTP_DEBUG_OUTPUT4, "Sending INIT - calls lowlevel_output\n"); - ret = sctp_lowlevel_chunk_output(inp, stcb, net, + if ((error = sctp_lowlevel_chunk_output(inp, stcb, net, (struct sockaddr *)&net->ro._l_addr, m, 0, NULL, 0, 0, 0, 0, inp->sctp_lport, stcb->rport, htonl(0), net->port, NULL, 0, 0, - so_locked); - SCTPDBG(SCTP_DEBUG_OUTPUT4, "lowlevel_output - %d\n", ret); + so_locked))) { + SCTPDBG(SCTP_DEBUG_OUTPUT4, "Gak send error %d\n", error); + if (error == ENOBUFS) { + stcb->asoc.ifp_had_enobuf = 1; + SCTP_STAT_INCR(sctps_lowlevelerr); + } + } else { + stcb->asoc.ifp_had_enobuf = 0; + } SCTP_STAT_INCR_COUNTER64(sctps_outcontrolchunks); (void)SCTP_GETTIME_TIMEVAL(&net->last_sent_time); } @@ -5494,6 +5511,7 @@ sctp_send_initiate_ack(struct sctp_inpcb *inp, struct sctp_tcb *stcb, uint16_t his_limit, i_want; int abort_flag; int nat_friendly = 0; + int error; struct socket *so; uint16_t num_ext, chunk_len, padding_len, parameter_len; @@ -5563,7 +5581,7 @@ do_a_abort: sctp_m_freem(op_err); return; } - chunk_len = (uint16_t) sizeof(struct sctp_init_ack_chunk); + chunk_len = (uint16_t)sizeof(struct sctp_init_ack_chunk); padding_len = 0; /* @@ -5680,8 +5698,10 @@ do_a_abort: * show up in our scoped count. */ cnt_inits_to = 1; - /* pull out the scope_id from - * incoming pkt */ + /* + * pull out the scope_id from + * incoming pkt + */ } else if (IN6_IS_ADDR_SITELOCAL(&src6->sin6_addr) || IN6_IS_ADDR_SITELOCAL(&dst6->sin6_addr)) { /* @@ -5743,7 +5763,7 @@ do_a_abort: * did the selection. */ net->ro._s_addr = sctp_source_address_selection(inp, - stcb, (sctp_route_t *) & net->ro, + stcb, (sctp_route_t *)&net->ro, net, 0, vrf_id); if (net->ro._s_addr == NULL) return; @@ -5773,7 +5793,7 @@ do_a_abort: * done the selection. */ net->ro._s_addr = sctp_source_address_selection(inp, - stcb, (sctp_route_t *) & net->ro, + stcb, (sctp_route_t *)&net->ro, net, 0, vrf_id); if (net->ro._s_addr == NULL) return; @@ -5881,7 +5901,7 @@ do_a_abort: /* adaptation layer indication parameter */ if (inp->sctp_ep.adaptation_layer_indicator_provided) { - parameter_len = (uint16_t) sizeof(struct sctp_adaptation_layer_indication); + parameter_len = (uint16_t)sizeof(struct sctp_adaptation_layer_indication); ali = (struct sctp_adaptation_layer_indication *)(mtod(m, caddr_t)+chunk_len); ali->ph.param_type = htons(SCTP_ULP_ADAPTATION); ali->ph.param_length = htons(parameter_len); @@ -5891,7 +5911,7 @@ do_a_abort: /* ECN parameter */ if (((asoc != NULL) && (asoc->ecn_supported == 1)) || ((asoc == NULL) && (inp->ecn_supported == 1))) { - parameter_len = (uint16_t) sizeof(struct sctp_paramhdr); + parameter_len = (uint16_t)sizeof(struct sctp_paramhdr); ph = (struct sctp_paramhdr *)(mtod(m, caddr_t)+chunk_len); ph->param_type = htons(SCTP_ECN_CAPABLE); ph->param_length = htons(parameter_len); @@ -5900,7 +5920,7 @@ do_a_abort: /* PR-SCTP supported parameter */ if (((asoc != NULL) && (asoc->prsctp_supported == 1)) || ((asoc == NULL) && (inp->prsctp_supported == 1))) { - parameter_len = (uint16_t) sizeof(struct sctp_paramhdr); + parameter_len = (uint16_t)sizeof(struct sctp_paramhdr); ph = (struct sctp_paramhdr *)(mtod(m, caddr_t)+chunk_len); ph->param_type = htons(SCTP_PRSCTP_SUPPORTED); ph->param_length = htons(parameter_len); @@ -5908,7 +5928,7 @@ do_a_abort: } /* Add NAT friendly parameter */ if (nat_friendly) { - parameter_len = (uint16_t) sizeof(struct sctp_paramhdr); + parameter_len = (uint16_t)sizeof(struct sctp_paramhdr); ph = (struct sctp_paramhdr *)(mtod(m, caddr_t)+chunk_len); ph->param_type = htons(SCTP_HAS_NAT_SUPPORT); ph->param_length = htons(parameter_len); @@ -5951,7 +5971,7 @@ do_a_abort: pr_supported->chunk_types[num_ext++] = SCTP_PACKET_DROPPED; } if (num_ext > 0) { - parameter_len = (uint16_t) sizeof(struct sctp_supported_chunk_types_param) + num_ext; + parameter_len = (uint16_t)sizeof(struct sctp_supported_chunk_types_param) + num_ext; pr_supported->ph.param_type = htons(SCTP_SUPPORTED_CHUNK_EXT); pr_supported->ph.param_length = htons(parameter_len); padding_len = SCTP_SIZE32(parameter_len) - parameter_len; @@ -5971,7 +5991,7 @@ do_a_abort: } /* generate and add RANDOM parameter */ randp = (struct sctp_auth_random *)(mtod(m, caddr_t)+chunk_len); - parameter_len = (uint16_t) sizeof(struct sctp_auth_random) + + parameter_len = (uint16_t)sizeof(struct sctp_auth_random) + SCTP_AUTH_RANDOM_SIZE_DEFAULT; randp->ph.param_type = htons(SCTP_RANDOM); randp->ph.param_length = htons(parameter_len); @@ -5986,9 +6006,9 @@ do_a_abort: } /* add HMAC_ALGO parameter */ hmacs = (struct sctp_auth_hmac_algo *)(mtod(m, caddr_t)+chunk_len); - parameter_len = (uint16_t) sizeof(struct sctp_auth_hmac_algo) + + parameter_len = (uint16_t)sizeof(struct sctp_auth_hmac_algo) + sctp_serialize_hmaclist(inp->sctp_ep.local_hmacs, - (uint8_t *) hmacs->hmac_ids); + (uint8_t *)hmacs->hmac_ids); hmacs->ph.param_type = htons(SCTP_HMAC_LIST); hmacs->ph.param_length = htons(parameter_len); padding_len = SCTP_SIZE32(parameter_len) - parameter_len; @@ -6001,7 +6021,7 @@ do_a_abort: } /* add CHUNKS parameter */ chunks = (struct sctp_auth_chunk_list *)(mtod(m, caddr_t)+chunk_len); - parameter_len = (uint16_t) sizeof(struct sctp_auth_chunk_list) + + parameter_len = (uint16_t)sizeof(struct sctp_auth_chunk_list) + sctp_serialize_auth_chunks(inp->sctp_ep.local_auth_chunks, chunks->chunk_types); chunks->ph.param_type = htons(SCTP_CHUNK_LIST); @@ -6087,9 +6107,9 @@ do_a_abort: * though thus we set trailer. */ (void)sctp_hmac_m(SCTP_HMAC, - (uint8_t *) inp->sctp_ep.secret_key[(int)(inp->sctp_ep.current_secret_number)], + (uint8_t *)inp->sctp_ep.secret_key[(int)(inp->sctp_ep.current_secret_number)], SCTP_SECRET_SIZE, m_cookie, sizeof(struct sctp_paramhdr), - (uint8_t *) signature, SCTP_SIGNATURE_SIZE); + (uint8_t *)signature, SCTP_SIGNATURE_SIZE); /* * We sifa 0 here to NOT set IP_DF if its IPv4, we ignore the return * here since the timer will drive a retranmission. @@ -6106,12 +6126,24 @@ do_a_abort: over_addr = NULL; } - (void)sctp_lowlevel_chunk_output(inp, NULL, NULL, to, m, 0, NULL, 0, 0, + if ((error = sctp_lowlevel_chunk_output(inp, NULL, NULL, to, m, 0, NULL, 0, 0, 0, 0, inp->sctp_lport, sh->src_port, init_chk->init.initiate_tag, port, over_addr, mflowtype, mflowid, - SCTP_SO_NOT_LOCKED); + SCTP_SO_NOT_LOCKED))) { + SCTPDBG(SCTP_DEBUG_OUTPUT4, "Gak send error %d\n", error); + if (error == ENOBUFS) { + if (asoc != NULL) { + asoc->ifp_had_enobuf = 1; + } + SCTP_STAT_INCR(sctps_lowlevelerr); + } + } else { + if (asoc != NULL) { + asoc->ifp_had_enobuf = 0; + } + } SCTP_STAT_INCR_COUNTER64(sctps_outcontrolchunks); } @@ -6167,9 +6199,9 @@ sctp_prune_prsctp(struct sctp_tcb *stcb, if (freed_spc >= dataout) { return; } - } /* if chunk was present */ - } /* if of sufficient priority */ - } /* if chunk has enabled */ + } /* if chunk was present */ + } /* if of sufficient priority */ + } /* if chunk has enabled */ } /* tailqforeach */ TAILQ_FOREACH_SAFE(chk, &asoc->send_queue, sctp_next, nchk) { @@ -6190,11 +6222,11 @@ sctp_prune_prsctp(struct sctp_tcb *stcb, if (freed_spc >= dataout) { return; } - } /* end if chk->data */ - } /* end if right class */ - } /* end if chk pr-sctp */ + } /* end if chk->data */ + } /* end if right class */ + } /* end if chk pr-sctp */ } /* tailqforeachsafe (chk) */ - } /* if enabled in asoc */ + } /* if enabled in asoc */ } int @@ -6437,8 +6469,10 @@ error_out: /* get the prepend space */ SCTP_BUF_RESV_UF(outchain, (SCTP_FIRST_MBUF_RESV + 4)); } else { - /* We really should not get a NULL - * in endofchain */ + /* + * We really should not get a NULL + * in endofchain + */ /* find end */ m = outchain; while (m) { @@ -6450,8 +6484,10 @@ error_out: } /* sanity */ if (*endofchain == NULL) { - /* huh, TSNH XXX maybe we - * should panic */ + /* + * huh, TSNH XXX maybe we + * should panic + */ sctp_m_freem(outchain); goto new_mbuf; } @@ -6614,7 +6650,7 @@ sctp_sendall_iterator(struct sctp_inpcb *inp, struct sctp_tcb *stcb, void *ptr, ph = mtod(m, struct sctp_paramhdr *); ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT); - ph->param_length = htons((uint16_t) (sizeof(struct sctp_paramhdr) + ca->sndlen)); + ph->param_length = htons((uint16_t)(sizeof(struct sctp_paramhdr) + ca->sndlen)); } /* * We add one here to keep the assoc from dis-appearing on @@ -6650,13 +6686,17 @@ sctp_sendall_iterator(struct sctp_inpcb *inp, struct sctp_tcb *stcb, void *ptr, if ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete) (stcb, asoc)) { goto abort_anyway; } - /* there is nothing queued to send, so I'm - * done... */ + /* + * there is nothing queued to send, so I'm + * done... + */ if ((SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) && (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_RECEIVED) && (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_ACK_SENT)) { - /* only send SHUTDOWN the first time - * through */ + /* + * only send SHUTDOWN the first time + * through + */ if (SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) { SCTP_STAT_DECR_GAUGE32(sctps_currestab); } @@ -6979,7 +7019,7 @@ all_done: sctp_misc_ints(SCTP_FLIGHT_LOG_UP, data_list[i]->whoTo->flight_size, data_list[i]->book_size, - (uint32_t) (uintptr_t) data_list[i]->whoTo, + (uint32_t)(uintptr_t)data_list[i]->whoTo, data_list[i]->rec.data.tsn); } sctp_flight_size_increase(data_list[i]); @@ -6989,7 +7029,7 @@ all_done: asoc->peers_rwnd, data_list[i]->send_size, SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)); } asoc->peers_rwnd = sctp_sbspace_sub(asoc->peers_rwnd, - (uint32_t) (data_list[i]->send_size + SCTP_BASE_SYSCTL(sctp_peer_chunk_oh))); + (uint32_t)(data_list[i]->send_size + SCTP_BASE_SYSCTL(sctp_peer_chunk_oh))); if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) { /* SWS sender side engages */ asoc->peers_rwnd = 0; @@ -7287,8 +7327,10 @@ re_look: SCTP_TCB_SEND_LOCK(stcb); send_lock_up = 1; if (sp->msg_is_complete) { - /* the sender finished the - * msg */ + /* + * the sender finished the + * msg + */ goto re_look; } } @@ -7480,10 +7522,10 @@ dont_do_it: } if (stcb->asoc.idata_supported == 0) { sctp_snd_sb_alloc(stcb, sizeof(struct sctp_data_chunk)); - chk->book_size = chk->send_size = (uint16_t) (to_move + sizeof(struct sctp_data_chunk)); + chk->book_size = chk->send_size = (uint16_t)(to_move + sizeof(struct sctp_data_chunk)); } else { sctp_snd_sb_alloc(stcb, sizeof(struct sctp_idata_chunk)); - chk->book_size = chk->send_size = (uint16_t) (to_move + sizeof(struct sctp_idata_chunk)); + chk->book_size = chk->send_size = (uint16_t)(to_move + sizeof(struct sctp_idata_chunk)); } chk->book_size_scale = 0; chk->sent = SCTP_DATAGRAM_UNSENT; @@ -7537,8 +7579,8 @@ dont_do_it: chk->rec.data.tsn = atomic_fetchadd_int(&asoc->sending_seq, 1); if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_AT_SEND_2_OUTQ) { sctp_misc_ints(SCTP_STRMOUT_LOG_SEND, - (uint32_t) (uintptr_t) stcb, sp->length, - (uint32_t) ((chk->rec.data.sid << 16) | (0x0000ffff & chk->rec.data.mid)), + (uint32_t)(uintptr_t)stcb, sp->length, + (uint32_t)((chk->rec.data.sid << 16) | (0x0000ffff & chk->rec.data.mid)), chk->rec.data.tsn); } if (stcb->asoc.idata_supported == 0) { @@ -7572,7 +7614,7 @@ dont_do_it: dchkh->ch.chunk_flags = chk->rec.data.rcv_flags; dchkh->dp.tsn = htonl(chk->rec.data.tsn); dchkh->dp.sid = htons(strq->sid); - dchkh->dp.ssn = htons((uint16_t) chk->rec.data.mid); + dchkh->dp.ssn = htons((uint16_t)chk->rec.data.mid); dchkh->dp.ppid = chk->rec.data.ppid; dchkh->ch.chunk_length = htons(chk->send_size); } else { @@ -8177,8 +8219,10 @@ again_one_more_time: net->port, NULL, 0, 0, so_locked))) { - /* error, we could not - * output */ + /* + * error, we could not + * output + */ SCTPDBG(SCTP_DEBUG_OUTPUT3, "Gak send error %d\n", error); if (from_where == 0) { SCTP_STAT_INCR(sctps_lowlevelerrusr); @@ -8251,12 +8295,16 @@ again_one_more_time: * to where the sack is going.. */ if (chk->whoTo == net) { - /* Don't transmit it to where its - * going (current net) */ + /* + * Don't transmit it to where its + * going (current net) + */ continue; } else if (sack_goes_to == net) { - /* But do transmit it to this - * address */ + /* + * But do transmit it to this + * address + */ goto skip_net_check; } } @@ -8449,8 +8497,10 @@ again_one_more_time: net->port, NULL, 0, 0, so_locked))) { - /* error, we could not - * output */ + /* + * error, we could not + * output + */ SCTPDBG(SCTP_DEBUG_OUTPUT3, "Gak send error %d\n", error); if (from_where == 0) { SCTP_STAT_INCR(sctps_lowlevelerrusr); @@ -8647,13 +8697,17 @@ again_one_more_time: override_ok = 0; SCTP_STAT_INCR_COUNTER64(sctps_outcontrolchunks); } else if (override_ok) { - /* use this data's - * keyid */ + /* + * use this data's + * keyid + */ auth_keyid = chk->auth_keyid; override_ok = 0; } else if (auth_keyid != chk->auth_keyid) { - /* different keyid, - * so done bundling */ + /* + * different keyid, + * so done bundling + */ break; } } @@ -8732,7 +8786,8 @@ again_one_more_time: break; } } /* for (chunk gather loop for this net) */ -} /* if asoc.state OPEN */ no_data_fill: + } /* if asoc.state OPEN */ +no_data_fill: /* Is there something to send for this destination? */ if (outchain) { /* We may need to start a control timer or two */ @@ -8788,8 +8843,8 @@ again_one_more_time: SCTP_STAT_INCR(sctps_lowlevelerrusr); } if (error == ENOBUFS) { - SCTP_STAT_INCR(sctps_lowlevelerr); asoc->ifp_had_enobuf = 1; + SCTP_STAT_INCR(sctps_lowlevelerr); } if (error == EHOSTUNREACH) { /* @@ -8912,7 +8967,7 @@ sctp_queue_op_err(struct sctp_tcb *stcb, struct mbuf *op_err) return; } chk->copy_by_ref = 0; - chk->send_size = (uint16_t) chunk_length; + chk->send_size = (uint16_t)chunk_length; chk->sent = SCTP_DATAGRAM_UNSENT; chk->snd_count = 0; chk->asoc = &stcb->asoc; @@ -9166,40 +9221,61 @@ sctp_send_shutdown(struct sctp_tcb *stcb, struct sctp_nets *net) struct sctp_shutdown_chunk *shutdown_cp; struct sctp_tmit_chunk *chk; - m_shutdown = sctp_get_mbuf_for_msg(sizeof(struct sctp_shutdown_chunk), 0, M_NOWAIT, 1, MT_HEADER); - if (m_shutdown == NULL) { - /* no mbuf's */ - return; + TAILQ_FOREACH(chk, &stcb->asoc.control_send_queue, sctp_next) { + if (chk->rec.chunk_id.id == SCTP_SHUTDOWN) { + /* We already have a SHUTDOWN queued. Reuse it. */ + if (chk->whoTo) { + sctp_free_remote_addr(chk->whoTo); + chk->whoTo = NULL; + } + break; + } } - SCTP_BUF_RESV_UF(m_shutdown, SCTP_MIN_OVERHEAD); - sctp_alloc_a_chunk(stcb, chk); if (chk == NULL) { - /* no memory */ - sctp_m_freem(m_shutdown); - return; - } - chk->copy_by_ref = 0; - chk->rec.chunk_id.id = SCTP_SHUTDOWN; - chk->rec.chunk_id.can_take_data = 1; - chk->flags = 0; - chk->send_size = sizeof(struct sctp_shutdown_chunk); - chk->sent = SCTP_DATAGRAM_UNSENT; - chk->snd_count = 0; - chk->flags = 0; - chk->asoc = &stcb->asoc; - chk->data = m_shutdown; - chk->whoTo = net; - if (chk->whoTo) { - atomic_add_int(&chk->whoTo->ref_count, 1); + m_shutdown = sctp_get_mbuf_for_msg(sizeof(struct sctp_shutdown_chunk), 0, M_NOWAIT, 1, MT_HEADER); + if (m_shutdown == NULL) { + /* no mbuf's */ + return; + } + SCTP_BUF_RESV_UF(m_shutdown, SCTP_MIN_OVERHEAD); + sctp_alloc_a_chunk(stcb, chk); + if (chk == NULL) { + /* no memory */ + sctp_m_freem(m_shutdown); + return; + } + chk->copy_by_ref = 0; + chk->rec.chunk_id.id = SCTP_SHUTDOWN; + chk->rec.chunk_id.can_take_data = 1; + chk->flags = 0; + chk->send_size = sizeof(struct sctp_shutdown_chunk); + chk->sent = SCTP_DATAGRAM_UNSENT; + chk->snd_count = 0; + chk->flags = 0; + chk->asoc = &stcb->asoc; + chk->data = m_shutdown; + chk->whoTo = net; + if (chk->whoTo) { + atomic_add_int(&chk->whoTo->ref_count, 1); + } + shutdown_cp = mtod(m_shutdown, struct sctp_shutdown_chunk *); + shutdown_cp->ch.chunk_type = SCTP_SHUTDOWN; + shutdown_cp->ch.chunk_flags = 0; + shutdown_cp->ch.chunk_length = htons(chk->send_size); + shutdown_cp->cumulative_tsn_ack = htonl(stcb->asoc.cumulative_tsn); + SCTP_BUF_LEN(m_shutdown) = chk->send_size; + TAILQ_INSERT_TAIL(&chk->asoc->control_send_queue, chk, sctp_next); + chk->asoc->ctrl_queue_cnt++; + } else { + TAILQ_REMOVE(&stcb->asoc.control_send_queue, chk, sctp_next); + chk->whoTo = net; + if (chk->whoTo) { + atomic_add_int(&chk->whoTo->ref_count, 1); + } + shutdown_cp = mtod(chk->data, struct sctp_shutdown_chunk *); + shutdown_cp->cumulative_tsn_ack = htonl(stcb->asoc.cumulative_tsn); + TAILQ_INSERT_TAIL(&stcb->asoc.control_send_queue, chk, sctp_next); } - shutdown_cp = mtod(m_shutdown, struct sctp_shutdown_chunk *); - shutdown_cp->ch.chunk_type = SCTP_SHUTDOWN; - shutdown_cp->ch.chunk_flags = 0; - shutdown_cp->ch.chunk_length = htons(chk->send_size); - shutdown_cp->cumulative_tsn_ack = htonl(stcb->asoc.cumulative_tsn); - SCTP_BUF_LEN(m_shutdown) = chk->send_size; - TAILQ_INSERT_TAIL(&chk->asoc->control_send_queue, chk, sctp_next); - chk->asoc->ctrl_queue_cnt++; return; } @@ -9455,8 +9531,14 @@ sctp_chunk_retransmission(struct sctp_inpcb *inp, chk->whoTo->port, NULL, 0, 0, so_locked))) { - SCTP_STAT_INCR(sctps_lowlevelerr); + SCTPDBG(SCTP_DEBUG_OUTPUT3, "Gak send error %d\n", error); + if (error == ENOBUFS) { + asoc->ifp_had_enobuf = 1; + SCTP_STAT_INCR(sctps_lowlevelerr); + } return (error); + } else { + asoc->ifp_had_enobuf = 0; } endofchain = NULL; auth = NULL; @@ -9672,8 +9754,10 @@ one_chunk_around: auth_keyid = fwd->auth_keyid; override_ok = 0; } else if (fwd->auth_keyid != auth_keyid) { - /* different keyid, - * so done bundling */ + /* + * different keyid, + * so done bundling + */ break; } } @@ -9725,8 +9809,14 @@ one_chunk_around: 0, 0, so_locked))) { /* error, we could not output */ - SCTP_STAT_INCR(sctps_lowlevelerr); + SCTPDBG(SCTP_DEBUG_OUTPUT3, "Gak send error %d\n", error); + if (error == ENOBUFS) { + asoc->ifp_had_enobuf = 1; + SCTP_STAT_INCR(sctps_lowlevelerr); + } return (error); + } else { + asoc->ifp_had_enobuf = 0; } endofchain = NULL; auth = NULL; @@ -9795,14 +9885,14 @@ one_chunk_around: asoc->peers_rwnd, data_list[i]->send_size, SCTP_BASE_SYSCTL(sctp_peer_chunk_oh)); } asoc->peers_rwnd = sctp_sbspace_sub(asoc->peers_rwnd, - (uint32_t) (data_list[i]->send_size + + (uint32_t)(data_list[i]->send_size + SCTP_BASE_SYSCTL(sctp_peer_chunk_oh))); } if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) { sctp_misc_ints(SCTP_FLIGHT_LOG_UP_RSND, data_list[i]->whoTo->flight_size, data_list[i]->book_size, - (uint32_t) (uintptr_t) data_list[i]->whoTo, + (uint32_t)(uintptr_t)data_list[i]->whoTo, data_list[i]->rec.data.tsn); } sctp_flight_size_increase(data_list[i]); @@ -10049,9 +10139,11 @@ do_it_again: if (asoc->max_burst > 0) { if (SCTP_BASE_SYSCTL(sctp_use_cwnd_based_maxburst)) { if ((net->flight_size + (asoc->max_burst * net->mtu)) < net->cwnd) { - /* JRS - Use the congestion + /* + * JRS - Use the congestion * control given in the - * congestion control module */ + * congestion control module + */ asoc->cc_functions.sctp_cwnd_update_after_output(stcb, net, asoc->max_burst); if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_MAXBURST_ENABLE) { sctp_log_maxburst(stcb, net, 0, asoc->max_burst, SCTP_MAX_BURST_APPLIED); @@ -10061,8 +10153,10 @@ do_it_again: net->fast_retran_ip = 0; } else { if (net->flight_size == 0) { - /* Should be decaying the - * cwnd here */ + /* + * Should be decaying the + * cwnd here + */ ; } } @@ -10392,7 +10486,7 @@ sctp_fill_in_rest: strseq_m++; } else { strseq->sid = htons(at->rec.data.sid); - strseq->ssn = htons((uint16_t) at->rec.data.mid); + strseq->ssn = htons((uint16_t)at->rec.data.mid); strseq++; } i++; @@ -10747,7 +10841,7 @@ sctp_send_sack(struct sctp_tcb *stcb, int so_locked } /* now we must add any dups we are going to report. */ if ((limit_reached == 0) && (asoc->numduptsns)) { - dup = (uint32_t *) gap_descriptor; + dup = (uint32_t *)gap_descriptor; for (i = 0; i < asoc->numduptsns; i++) { *dup = htonl(asoc->dup_tsns[i]); dup++; @@ -10764,7 +10858,7 @@ sctp_send_sack(struct sctp_tcb *stcb, int so_locked * queue. */ if (type == SCTP_SELECTIVE_ACK) { - a_chk->send_size = (uint16_t) (sizeof(struct sctp_sack_chunk) + + a_chk->send_size = (uint16_t)(sizeof(struct sctp_sack_chunk) + (num_gap_blocks + num_nr_gap_blocks) * sizeof(struct sctp_gap_ack_block) + num_dups * sizeof(int32_t)); SCTP_BUF_LEN(a_chk->data) = a_chk->send_size; @@ -10776,7 +10870,7 @@ sctp_send_sack(struct sctp_tcb *stcb, int so_locked sack->ch.chunk_flags = flags; sack->ch.chunk_length = htons(a_chk->send_size); } else { - a_chk->send_size = (uint16_t) (sizeof(struct sctp_nr_sack_chunk) + + a_chk->send_size = (uint16_t)(sizeof(struct sctp_nr_sack_chunk) + (num_gap_blocks + num_nr_gap_blocks) * sizeof(struct sctp_gap_ack_block) + num_dups * sizeof(int32_t)); SCTP_BUF_LEN(a_chk->data) = a_chk->send_size; @@ -10812,6 +10906,7 @@ sctp_send_abort_tcb(struct sctp_tcb *stcb, struct mbuf *operr, int so_locked struct sctp_nets *net; uint32_t vtag; uint32_t auth_offset = 0; + int error; uint16_t cause_len, chunk_len, padding_len; SCTP_TCB_LOCK_ASSERT(stcb); @@ -10842,13 +10937,13 @@ sctp_send_abort_tcb(struct sctp_tcb *stcb, struct mbuf *operr, int so_locked cause_len = 0; m_last = NULL; for (m = operr; m; m = SCTP_BUF_NEXT(m)) { - cause_len += (uint16_t) SCTP_BUF_LEN(m); + cause_len += (uint16_t)SCTP_BUF_LEN(m); if (SCTP_BUF_NEXT(m) == NULL) { m_last = m; } } SCTP_BUF_LEN(m_abort) = sizeof(struct sctp_abort_chunk); - chunk_len = (uint16_t) sizeof(struct sctp_abort_chunk) + cause_len; + chunk_len = (uint16_t)sizeof(struct sctp_abort_chunk) + cause_len; padding_len = SCTP_SIZE32(chunk_len) - chunk_len; if (m_out == NULL) { /* NO Auth chunk prepended, so reserve space in front */ @@ -10883,13 +10978,21 @@ sctp_send_abort_tcb(struct sctp_tcb *stcb, struct mbuf *operr, int so_locked return; } } - (void)sctp_lowlevel_chunk_output(stcb->sctp_ep, stcb, net, + if ((error = sctp_lowlevel_chunk_output(stcb->sctp_ep, stcb, net, (struct sockaddr *)&net->ro._l_addr, m_out, auth_offset, auth, stcb->asoc.authinfo.active_keyid, 1, 0, 0, stcb->sctp_ep->sctp_lport, stcb->rport, htonl(vtag), stcb->asoc.primary_destination->port, NULL, 0, 0, - so_locked); + so_locked))) { + SCTPDBG(SCTP_DEBUG_OUTPUT3, "Gak send error %d\n", error); + if (error == ENOBUFS) { + stcb->asoc.ifp_had_enobuf = 1; + SCTP_STAT_INCR(sctps_lowlevelerr); + } + } else { + stcb->asoc.ifp_had_enobuf = 0; + } SCTP_STAT_INCR_COUNTER64(sctps_outcontrolchunks); } @@ -10902,6 +11005,7 @@ sctp_send_shutdown_complete(struct sctp_tcb *stcb, struct mbuf *m_shutdown_comp; struct sctp_shutdown_complete_chunk *shutdown_complete; uint32_t vtag; + int error; uint8_t flags; m_shutdown_comp = sctp_get_mbuf_for_msg(sizeof(struct sctp_chunkhdr), 0, M_NOWAIT, 1, MT_HEADER); @@ -10921,14 +11025,22 @@ sctp_send_shutdown_complete(struct sctp_tcb *stcb, shutdown_complete->ch.chunk_flags = flags; shutdown_complete->ch.chunk_length = htons(sizeof(struct sctp_shutdown_complete_chunk)); SCTP_BUF_LEN(m_shutdown_comp) = sizeof(struct sctp_shutdown_complete_chunk); - (void)sctp_lowlevel_chunk_output(stcb->sctp_ep, stcb, net, + if ((error = sctp_lowlevel_chunk_output(stcb->sctp_ep, stcb, net, (struct sockaddr *)&net->ro._l_addr, m_shutdown_comp, 0, NULL, 0, 1, 0, 0, stcb->sctp_ep->sctp_lport, stcb->rport, htonl(vtag), net->port, NULL, 0, 0, - SCTP_SO_NOT_LOCKED); + SCTP_SO_NOT_LOCKED))) { + SCTPDBG(SCTP_DEBUG_OUTPUT3, "Gak send error %d\n", error); + if (error == ENOBUFS) { + stcb->asoc.ifp_had_enobuf = 1; + SCTP_STAT_INCR(sctps_lowlevelerr); + } + } else { + stcb->asoc.ifp_had_enobuf = 0; + } SCTP_STAT_INCR_COUNTER64(sctps_outcontrolchunks); return; } @@ -11081,7 +11193,7 @@ sctp_send_resp_msg(struct sockaddr *src, struct sockaddr *dst, udp->uh_sport = htons(SCTP_BASE_SYSCTL(sctp_udp_tunneling_port)); udp->uh_dport = port; udp->uh_sum = 0; - udp->uh_ulen = htons((uint16_t) (sizeof(struct udphdr) + + udp->uh_ulen = htons((uint16_t)(sizeof(struct udphdr) + sizeof(struct sctphdr) + sizeof(struct sctp_chunkhdr) + cause_len + padding_len)); @@ -11107,7 +11219,7 @@ sctp_send_resp_msg(struct sockaddr *src, struct sockaddr *dst, } else { ch->chunk_flags = SCTP_HAD_NO_TCB; } - ch->chunk_length = htons((uint16_t) (sizeof(struct sctp_chunkhdr) + cause_len)); + ch->chunk_length = htons((uint16_t)(sizeof(struct sctp_chunkhdr) + cause_len)); len += sizeof(struct sctp_chunkhdr); len += cause_len + padding_len; @@ -11156,7 +11268,7 @@ sctp_send_resp_msg(struct sockaddr *src, struct sockaddr *dst, #endif #ifdef INET6 case AF_INET6: - ip6->ip6_plen = (uint16_t) (len - sizeof(struct ip6_hdr)); + ip6->ip6_plen = (uint16_t)(len - sizeof(struct ip6_hdr)); if (port) { #if defined(SCTP_WITH_NO_CSUM) SCTP_STAT_INCR(sctps_sendnocrc); @@ -11272,7 +11384,7 @@ sctp_send_hb(struct sctp_tcb *stcb, struct sctp_nets *net, int so_locked hb->heartbeat.hb_info.time_value_1 = now.tv_sec; hb->heartbeat.hb_info.time_value_2 = now.tv_usec; /* Did our user request this one, put it in */ - hb->heartbeat.hb_info.addr_family = (uint8_t) net->ro._l_addr.sa.sa_family; + hb->heartbeat.hb_info.addr_family = (uint8_t)net->ro._l_addr.sa.sa_family; hb->heartbeat.hb_info.addr_len = net->ro._l_addr.sa.sa_len; if (net->dest_state & SCTP_ADDR_UNCONFIRMED) { /* @@ -11423,7 +11535,7 @@ sctp_send_packet_dropped(struct sctp_tcb *stcb, struct sctp_nets *net, /* Validate that we do not have an ABORT in here. */ offset = iphlen + sizeof(struct sctphdr); ch = (struct sctp_chunkhdr *)sctp_m_getptr(m, offset, - sizeof(*ch), (uint8_t *) & chunk_buf); + sizeof(*ch), (uint8_t *)&chunk_buf); while (ch != NULL) { chk_length = ntohs(ch->chunk_length); if (chk_length < sizeof(*ch)) { @@ -11447,7 +11559,7 @@ sctp_send_packet_dropped(struct sctp_tcb *stcb, struct sctp_nets *net, } offset += SCTP_SIZE32(chk_length); ch = (struct sctp_chunkhdr *)sctp_m_getptr(m, offset, - sizeof(*ch), (uint8_t *) & chunk_buf); + sizeof(*ch), (uint8_t *)&chunk_buf); } if ((len + SCTP_MAX_OVERHEAD + sizeof(struct sctp_pktdrop_chunk)) > @@ -11483,7 +11595,7 @@ jump_out: * Len is already adjusted to size minus overhead above take * out the pkt_drop chunk itself from it. */ - chk->send_size = (uint16_t) (len - sizeof(struct sctp_pktdrop_chunk)); + chk->send_size = (uint16_t)(len - sizeof(struct sctp_pktdrop_chunk)); len = chk->send_size; } else { /* no truncation needed */ @@ -11544,8 +11656,10 @@ sctp_send_cwr(struct sctp_tcb *stcb, struct sctp_nets *net, uint32_t high_tsn, u asoc = &stcb->asoc; TAILQ_FOREACH(chk, &asoc->control_send_queue, sctp_next) { if ((chk->rec.chunk_id.id == SCTP_ECN_CWR) && (net == chk->whoTo)) { - /* found a previous CWR queued to same destination - * update it if needed */ + /* + * found a previous CWR queued to same destination + * update it if needed + */ uint32_t ctsn; cwr = mtod(chk->data, struct sctp_cwr_chunk *); @@ -11621,7 +11735,7 @@ sctp_add_stream_reset_out(struct sctp_tcb *stcb, struct sctp_tmit_chunk *chk, if (number_entries > SCTP_MAX_STREAMS_AT_ONCE_RESET) { number_entries = SCTP_MAX_STREAMS_AT_ONCE_RESET; } - len = (uint16_t) (sizeof(struct sctp_stream_reset_out_request) + (sizeof(uint16_t) * number_entries)); + len = (uint16_t)(sizeof(struct sctp_stream_reset_out_request) + (sizeof(uint16_t) * number_entries)); req_out->ph.param_type = htons(SCTP_STR_RESET_OUT_REQUEST); req_out->ph.param_length = htons(len); req_out->request_seq = htonl(seq); @@ -11665,7 +11779,7 @@ sctp_add_stream_reset_out(struct sctp_tcb *stcb, struct sctp_tmit_chunk *chk, static void sctp_add_stream_reset_in(struct sctp_tmit_chunk *chk, - int number_entries, uint16_t * list, + int number_entries, uint16_t *list, uint32_t seq) { uint16_t len, old_len, i; @@ -11678,7 +11792,7 @@ sctp_add_stream_reset_in(struct sctp_tmit_chunk *chk, /* get to new offset for the param. */ req_in = (struct sctp_stream_reset_in_request *)((caddr_t)ch + len); /* now how long will this param be? */ - len = (uint16_t) (sizeof(struct sctp_stream_reset_in_request) + (sizeof(uint16_t) * number_entries)); + len = (uint16_t)(sizeof(struct sctp_stream_reset_in_request) + (sizeof(uint16_t) * number_entries)); req_in->ph.param_type = htons(SCTP_STR_RESET_IN_REQUEST); req_in->ph.param_length = htons(len); req_in->request_seq = htonl(seq); @@ -11994,7 +12108,7 @@ sctp_send_stream_reset_out_if_possible(struct sctp_tcb *stcb, int so_locked) int sctp_send_str_reset_req(struct sctp_tcb *stcb, - uint16_t number_entries, uint16_t * list, + uint16_t number_entries, uint16_t *list, uint8_t send_in_req, uint8_t send_tsn_req, uint8_t add_stream, @@ -12122,8 +12236,10 @@ sctp_send_str_reset_req(struct sctp_tcb *stcb, stcb->asoc.strmout[i].sid = i; stcb->asoc.strmout[i].state = oldstream[i].state; /* FIX ME FIX ME */ - /* This should be a SS_COPY operation FIX ME STREAM - * SCHEDULER EXPERT */ + /* + * This should be a SS_COPY operation FIX ME STREAM + * SCHEDULER EXPERT + */ stcb->asoc.ss_functions.sctp_ss_init_stream(stcb, &stcb->asoc.strmout[i], &oldstream[i]); /* now anything on those queues? */ TAILQ_FOREACH_SAFE(sp, &oldstream[i].outqueue, next, nsp) { @@ -12227,7 +12343,7 @@ sctp_copy_resume(struct uio *uio, int max_send_len, int user_marks_eor, int *error, - uint32_t * sndout, + uint32_t *sndout, struct mbuf **new_tail) { struct mbuf *m; @@ -12308,8 +12424,8 @@ sctp_copy_it_in(struct sctp_tcb *stcb, (void)SCTP_GETTIME_TIMEVAL(&sp->ts); sp->sid = srcv->sinfo_stream; - sp->length = (uint32_t) min(uio->uio_resid, max_send_len); - if ((sp->length == (uint32_t) uio->uio_resid) && + sp->length = (uint32_t)min(uio->uio_resid, max_send_len); + if ((sp->length == (uint32_t)uio->uio_resid) && ((user_marks_eor == 0) || (srcv->sinfo_flags & SCTP_EOF) || (user_marks_eor && (srcv->sinfo_flags & SCTP_EOR)))) { @@ -12653,8 +12769,10 @@ sctp_lower_sosend(struct socket *so, } if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) { stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_CONNECTED; - /* Set the connected flag so we can queue - * data */ + /* + * Set the connected flag so we can queue + * data + */ soisconnecting(so); } hold_tcblock = 1; @@ -12664,8 +12782,10 @@ sctp_lower_sosend(struct socket *so, } else { SCTP_PRINTF("Huh-3? create lock should have been on??\n"); } - /* Turn on queue only flag to prevent data from - * being sent */ + /* + * Turn on queue only flag to prevent data from + * being sent + */ queue_only = 1; asoc = &stcb->asoc; SCTP_SET_STATE(asoc, SCTP_STATE_COOKIE_WAIT); @@ -12865,7 +12985,7 @@ sctp_lower_sosend(struct socket *so, /* now move forward the data pointer */ ph = mtod(mm, struct sctp_paramhdr *); ph->param_type = htons(SCTP_CAUSE_USER_INITIATED_ABT); - ph->param_length = htons((uint16_t) (sizeof(struct sctp_paramhdr) + tot_out)); + ph->param_length = htons((uint16_t)(sizeof(struct sctp_paramhdr) + tot_out)); ph++; SCTP_BUF_LEN(mm) = tot_out + sizeof(struct sctp_paramhdr); if (top == NULL) { @@ -13160,8 +13280,10 @@ skip_preblock: } /* PR-SCTP? */ if ((asoc->prsctp_supported) && (asoc->sent_queue_cnt_removeable > 0)) { - /* This is ugly but we must assure locking - * order */ + /* + * This is ugly but we must assure locking + * order + */ if (hold_tcblock == 0) { SCTP_TCB_LOCK(stcb); hold_tcblock = 1; @@ -13438,8 +13560,10 @@ dataless_eof: msg); sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_LOCKED); - /* now relock the stcb so everything - * is sane */ + /* + * now relock the stcb so everything + * is sane + */ hold_tcblock = 0; stcb = NULL; goto out; @@ -13513,8 +13637,10 @@ skip_out_eof: if ((queue_only == 0) && (nagle_applies == 0) && (stcb->asoc.peers_rwnd && un_sent)) { /* we can attempt to send too. */ if (hold_tcblock == 0) { - /* If there is activity recv'ing sacks no need to - * send */ + /* + * If there is activity recv'ing sacks no need to + * send + */ if (SCTP_TCB_TRYLOCK(stcb)) { sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_USR_SEND, SCTP_SO_LOCKED); hold_tcblock = 1; @@ -13588,7 +13714,7 @@ out_unlocked: */ struct mbuf * sctp_add_auth_chunk(struct mbuf *m, struct mbuf **m_end, - struct sctp_auth_chunk **auth_ret, uint32_t * offset, + struct sctp_auth_chunk **auth_ret, uint32_t *offset, struct sctp_tcb *stcb, uint8_t chunk) { struct mbuf *m_auth; @@ -13643,7 +13769,7 @@ sctp_add_auth_chunk(struct mbuf *m, struct mbuf **m_end, #ifdef INET6 int -sctp_v6src_match_nexthop(struct sockaddr_in6 *src6, sctp_route_t * ro) +sctp_v6src_match_nexthop(struct sockaddr_in6 *src6, sctp_route_t *ro) { struct nd_prefix *pfx = NULL; struct nd_pfxrouter *pfxrtr = NULL; @@ -13695,7 +13821,7 @@ sctp_v6src_match_nexthop(struct sockaddr_in6 *src6, sctp_route_t * ro) #endif int -sctp_v4src_match_nexthop(struct sctp_ifa *sifa, sctp_route_t * ro) +sctp_v4src_match_nexthop(struct sctp_ifa *sifa, sctp_route_t *ro) { #ifdef INET struct sockaddr_in *sin, *mask; diff --git a/freebsd/sys/netinet/sctp_output.h b/freebsd/sys/netinet/sctp_output.h index b2441a6f..cd90b7d7 100644 --- a/freebsd/sys/netinet/sctp_output.h +++ b/freebsd/sys/netinet/sctp_output.h @@ -47,7 +47,7 @@ sctp_add_addresses_to_i_ia(struct sctp_inpcb *inp, struct sctp_scoping *scope, struct mbuf *m_at, int cnt_inits_to, - uint16_t * padding_len, uint16_t * chunk_len); + uint16_t *padding_len, uint16_t *chunk_len); int sctp_is_addr_restricted(struct sctp_tcb *, struct sctp_ifa *); @@ -64,13 +64,13 @@ int struct sctp_ifa * sctp_source_address_selection(struct sctp_inpcb *inp, struct sctp_tcb *stcb, - sctp_route_t * ro, struct sctp_nets *net, + sctp_route_t *ro, struct sctp_nets *net, int non_asoc_addr_ok, uint32_t vrf_id); int - sctp_v6src_match_nexthop(struct sockaddr_in6 *src6, sctp_route_t * ro); + sctp_v6src_match_nexthop(struct sockaddr_in6 *src6, sctp_route_t *ro); int - sctp_v4src_match_nexthop(struct sctp_ifa *sifa, sctp_route_t * ro); + sctp_v4src_match_nexthop(struct sctp_ifa *sifa, sctp_route_t *ro); void sctp_send_initiate(struct sctp_inpcb *, struct sctp_tcb *, int diff --git a/freebsd/sys/netinet/sctp_pcb.c b/freebsd/sys/netinet/sctp_pcb.c index ca86a139..4cd7bf0b 100644 --- a/freebsd/sys/netinet/sctp_pcb.c +++ b/freebsd/sys/netinet/sctp_pcb.c @@ -1214,8 +1214,10 @@ sctp_tcb_special_locate(struct sctp_inpcb **inp_p, struct sockaddr *from, if (netp != NULL) { *netp = net; } - /* Update the endpoint - * pointer */ + /* + * Update the endpoint + * pointer + */ *inp_p = inp; SCTP_INP_RUNLOCK(inp); return (stcb); @@ -1236,8 +1238,10 @@ sctp_tcb_special_locate(struct sctp_inpcb **inp_p, struct sockaddr *from, if (netp != NULL) { *netp = net; } - /* Update the endpoint - * pointer */ + /* + * Update the endpoint + * pointer + */ *inp_p = inp; SCTP_INP_RUNLOCK(inp); return (stcb); @@ -1565,7 +1569,7 @@ sctp_findasoc_ep_asocid_locked(struct sctp_inpcb *inp, sctp_assoc_t asoc_id, int SCTP_PRINTF("TSNH ep_associd0\n"); return (NULL); } - id = (uint32_t) asoc_id; + id = (uint32_t)asoc_id; head = &inp->sctp_asocidhash[SCTP_PCBHASH_ASOC(id, inp->hashasocidmark)]; if (head == NULL) { /* invalid id TSNH */ @@ -1664,8 +1668,10 @@ sctp_endpoint_probe(struct sockaddr *nam, struct sctppcbhead *head, case AF_INET: if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) && SCTP_IPV6_V6ONLY(inp)) { - /* IPv4 on a IPv6 socket with ONLY - * IPv6 set */ + /* + * IPv4 on a IPv6 socket with ONLY + * IPv6 set + */ SCTP_INP_RUNLOCK(inp); continue; } @@ -1678,8 +1684,10 @@ sctp_endpoint_probe(struct sockaddr *nam, struct sctppcbhead *head, #endif #ifdef INET6 case AF_INET6: - /* A V6 address and the endpoint is NOT - * bound V6 */ + /* + * A V6 address and the endpoint is NOT + * bound V6 + */ if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) { SCTP_INP_RUNLOCK(inp); continue; @@ -2177,8 +2185,10 @@ sctp_findassoc_by_vtag(struct sockaddr *from, struct sockaddr *to, uint32_t vtag continue; } if (remote_tag) { - /* If we have both vtags that's all we match - * on */ + /* + * If we have both vtags that's all we match + * on + */ if (stcb->asoc.peer_vtag == remote_tag) { /* * If both tags match we consider it @@ -2311,7 +2321,7 @@ sctp_findassociation_ep_asconf(struct mbuf *m, int offset, __func__); return NULL; } - ptype = (int)((uint32_t) ntohs(phdr->param_type)); + ptype = (int)((uint32_t)ntohs(phdr->param_type)); /* get the correlation address */ switch (ptype) { #ifdef INET6 @@ -2443,13 +2453,13 @@ sctp_inpcb_alloc(struct socket *so, uint32_t vrf_id) inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT; inp->max_cwnd = 0; inp->sctp_cmt_on_off = SCTP_BASE_SYSCTL(sctp_cmt_on_off); - inp->ecn_supported = (uint8_t) SCTP_BASE_SYSCTL(sctp_ecn_enable); - inp->prsctp_supported = (uint8_t) SCTP_BASE_SYSCTL(sctp_pr_enable); - inp->auth_supported = (uint8_t) SCTP_BASE_SYSCTL(sctp_auth_enable); - inp->asconf_supported = (uint8_t) SCTP_BASE_SYSCTL(sctp_asconf_enable); - inp->reconfig_supported = (uint8_t) SCTP_BASE_SYSCTL(sctp_reconfig_enable); - inp->nrsack_supported = (uint8_t) SCTP_BASE_SYSCTL(sctp_nrsack_enable); - inp->pktdrop_supported = (uint8_t) SCTP_BASE_SYSCTL(sctp_pktdrop_enable); + inp->ecn_supported = (uint8_t)SCTP_BASE_SYSCTL(sctp_ecn_enable); + inp->prsctp_supported = (uint8_t)SCTP_BASE_SYSCTL(sctp_pr_enable); + inp->auth_supported = (uint8_t)SCTP_BASE_SYSCTL(sctp_auth_enable); + inp->asconf_supported = (uint8_t)SCTP_BASE_SYSCTL(sctp_asconf_enable); + inp->reconfig_supported = (uint8_t)SCTP_BASE_SYSCTL(sctp_reconfig_enable); + inp->nrsack_supported = (uint8_t)SCTP_BASE_SYSCTL(sctp_nrsack_enable); + inp->pktdrop_supported = (uint8_t)SCTP_BASE_SYSCTL(sctp_pktdrop_enable); inp->idata_supported = 0; inp->fibnum = so->so_fibnum; @@ -2871,8 +2881,10 @@ sctp_inpcb_bind(struct socket *so, struct sockaddr *addr, #ifdef INET6 case AF_INET6: { - /* Only for pure IPv6 Address. (No IPv4 - * Mapped!) */ + /* + * Only for pure IPv6 Address. (No IPv4 + * Mapped!) + */ struct sockaddr_in6 *sin6; sin6 = (struct sockaddr_in6 *)addr; @@ -2949,8 +2961,10 @@ sctp_inpcb_bind(struct socket *so, struct sockaddr *addr, /* unlock info */ if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) && (sctp_is_feature_on(inp_tmp, SCTP_PCB_FLAGS_PORTREUSE))) { - /* Ok, must be one-2-one and - * allowing port re-use */ + /* + * Ok, must be one-2-one and + * allowing port re-use + */ port_reuse_active = 1; goto continue_anyway; } @@ -2973,8 +2987,10 @@ sctp_inpcb_bind(struct socket *so, struct sockaddr *addr, /* unlock info */ if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) && (sctp_is_feature_on(inp_tmp, SCTP_PCB_FLAGS_PORTREUSE))) { - /* Ok, must be one-2-one and - * allowing port re-use */ + /* + * Ok, must be one-2-one and + * allowing port re-use + */ port_reuse_active = 1; goto continue_anyway; } @@ -3273,8 +3289,10 @@ sctp_iterator_inp_being_freed(struct sctp_inpcb *inp) SCTP_INP_INCR_REF(it->inp); } } - /* When its put in the refcnt is incremented so decr - * it */ + /* + * When its put in the refcnt is incremented so decr + * it + */ SCTP_INP_DECR_REF(inp); } } @@ -3933,7 +3951,7 @@ sctp_add_remote_addr(struct sctp_tcb *stcb, struct sockaddr *newaddr, sin6->sin6_scope_id = 0; } #endif - SCTP_RTALLOC((sctp_route_t *) & net->ro, + SCTP_RTALLOC((sctp_route_t *)&net->ro, stcb->asoc.vrf_id, stcb->sctp_ep->fibnum); @@ -3941,7 +3959,7 @@ sctp_add_remote_addr(struct sctp_tcb *stcb, struct sockaddr *newaddr, /* Get source address */ net->ro._s_addr = sctp_source_address_selection(stcb->sctp_ep, stcb, - (sctp_route_t *) & net->ro, + (sctp_route_t *)&net->ro, net, 0, stcb->asoc.vrf_id); @@ -3959,8 +3977,10 @@ sctp_add_remote_addr(struct sctp_tcb *stcb, struct sockaddr *newaddr, rmtu = SCTP_GATHER_MTU_FROM_ROUTE(net->ro._s_addr, &net->ro._l_addr.sa, net->ro.ro_rt); if (rmtu == 0) { - /* Start things off to match mtu of - * interface please. */ + /* + * Start things off to match mtu of + * interface please. + */ SCTP_SET_MTU_OF_ROUTE(&net->ro._l_addr.sa, net->ro.ro_rt, net->mtu); } else { @@ -3993,7 +4013,7 @@ sctp_add_remote_addr(struct sctp_tcb *stcb, struct sockaddr *newaddr, } #if defined(INET) || defined(INET6) if (net->port) { - net->mtu -= (uint32_t) sizeof(struct udphdr); + net->mtu -= (uint32_t)sizeof(struct udphdr); } #endif if (from == SCTP_ALLOC_ASOC) { @@ -4127,7 +4147,7 @@ try_again: } id = inp->sctp_associd_counter; inp->sctp_associd_counter++; - lstcb = sctp_findasoc_ep_asocid_locked(inp, (sctp_assoc_t) id, 0); + lstcb = sctp_findasoc_ep_asocid_locked(inp, (sctp_assoc_t)id, 0); if (lstcb) { goto try_again; } @@ -5451,8 +5471,10 @@ sctp_del_local_addr_ep(struct sctp_inpcb *inp, struct sctp_ifa *ifa) if (stcb->asoc.last_used_address == laddr) /* delete this address */ stcb->asoc.last_used_address = NULL; - /* Now spin through all the nets and purge any ref - * to laddr */ + /* + * Now spin through all the nets and purge any ref + * to laddr + */ TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { if (net->ro._s_addr == laddr->ifa) { /* Yep, purge src address selected */ @@ -5749,12 +5771,12 @@ sctp_pcb_init() (void)SCTP_GETTIME_TIMEVAL(&tv); #if defined(__FreeBSD__) && defined(SMP) && defined(SCTP_USE_PERCPU_STAT) bzero(SCTP_BASE_STATS, (sizeof(struct sctpstat) * (mp_maxid + 1))); - SCTP_BASE_STATS[PCPU_GET(cpuid)].sctps_discontinuitytime.tv_sec = (uint32_t) tv.tv_sec; - SCTP_BASE_STATS[PCPU_GET(cpuid)].sctps_discontinuitytime.tv_usec = (uint32_t) tv.tv_usec; + SCTP_BASE_STATS[PCPU_GET(cpuid)].sctps_discontinuitytime.tv_sec = (uint32_t)tv.tv_sec; + SCTP_BASE_STATS[PCPU_GET(cpuid)].sctps_discontinuitytime.tv_usec = (uint32_t)tv.tv_usec; #else bzero(&SCTP_BASE_STATS, sizeof(struct sctpstat)); - SCTP_BASE_STAT(sctps_discontinuitytime).tv_sec = (uint32_t) tv.tv_sec; - SCTP_BASE_STAT(sctps_discontinuitytime).tv_usec = (uint32_t) tv.tv_usec; + SCTP_BASE_STAT(sctps_discontinuitytime).tv_sec = (uint32_t)tv.tv_sec; + SCTP_BASE_STAT(sctps_discontinuitytime).tv_usec = (uint32_t)tv.tv_usec; #endif /* init the empty list of (All) Endpoints */ LIST_INIT(&SCTP_BASE_INFO(listhead)); @@ -6228,8 +6250,10 @@ sctp_load_addresses_from_init(struct sctp_tcb *stcb, struct mbuf *m, struct mbuf *op_err; char msg[SCTP_DIAG_INFO_LEN]; - /* in setup state we - * abort this guy */ + /* + * in setup state we + * abort this guy + */ snprintf(msg, sizeof(msg), "%s:%d at %s", __FILE__, __LINE__, __func__); op_err = sctp_generate_cause(SCTP_BASE_SYSCTL(sctp_diag_info_code), @@ -6271,8 +6295,10 @@ sctp_load_addresses_from_init(struct sctp_tcb *stcb, struct mbuf *m, goto next_param; } if (IN6_IS_ADDR_LINKLOCAL(&sin6.sin6_addr)) { - /* Link local make no sense without - * scope */ + /* + * Link local make no sense without + * scope + */ goto next_param; } sa = (struct sockaddr *)&sin6; @@ -6323,8 +6349,10 @@ sctp_load_addresses_from_init(struct sctp_tcb *stcb, struct mbuf *m, struct mbuf *op_err; char msg[SCTP_DIAG_INFO_LEN]; - /* in setup state we - * abort this guy */ + /* + * in setup state we + * abort this guy + */ snprintf(msg, sizeof(msg), "%s:%d at %s", __FILE__, __LINE__, __func__); op_err = sctp_generate_cause(SCTP_BASE_SYSCTL(sctp_diag_info_code), diff --git a/freebsd/sys/netinet/sctp_pcb.h b/freebsd/sys/netinet/sctp_pcb.h index a2a1e7d7..86fae1f4 100644 --- a/freebsd/sys/netinet/sctp_pcb.h +++ b/freebsd/sys/netinet/sctp_pcb.h @@ -379,8 +379,10 @@ struct sctp_inpcb { /* list of addrs in use by the EP, NULL if bound-all */ struct sctpladdr sctp_addr_list; - /* used for source address selection rotation when we are subset - * bound */ + /* + * used for source address selection rotation when we are subset + * bound + */ struct sctp_laddr *next_addr_touse; /* back pointer to our socket */ diff --git a/freebsd/sys/netinet/sctp_structs.h b/freebsd/sys/netinet/sctp_structs.h index 22a3c736..f7371748 100644 --- a/freebsd/sys/netinet/sctp_structs.h +++ b/freebsd/sys/netinet/sctp_structs.h @@ -715,7 +715,7 @@ struct sctp_cc_functions { struct sctp_nets *net, int in_window, int num_pkt_lost); void (*sctp_cwnd_update_after_packet_dropped) (struct sctp_tcb *stcb, struct sctp_nets *net, struct sctp_pktdrop_chunk *cp, - uint32_t * bottle_bw, uint32_t * on_queue); + uint32_t *bottle_bw, uint32_t *on_queue); void (*sctp_cwnd_update_after_output) (struct sctp_tcb *stcb, struct sctp_nets *net, int burst_limit); void (*sctp_cwnd_update_packet_transmitted) (struct sctp_tcb *stcb, @@ -752,7 +752,7 @@ struct sctp_ss_functions { void (*sctp_ss_packet_done) (struct sctp_tcb *stcb, struct sctp_nets *net, struct sctp_association *asoc); int (*sctp_ss_get_value) (struct sctp_tcb *stcb, struct sctp_association *asoc, - struct sctp_stream_out *strq, uint16_t * value); + struct sctp_stream_out *strq, uint16_t *value); int (*sctp_ss_set_value) (struct sctp_tcb *stcb, struct sctp_association *asoc, struct sctp_stream_out *strq, uint16_t value); int (*sctp_ss_is_user_msgs_incomplete) (struct sctp_tcb *stcb, struct sctp_association *asoc); @@ -881,8 +881,10 @@ struct sctp_association { /* JRS - the congestion control functions are in this struct */ struct sctp_cc_functions cc_functions; - /* JRS - value to store the currently loaded congestion control - * module */ + /* + * JRS - value to store the currently loaded congestion control + * module + */ uint32_t congestion_control_module; /* RS - the stream scheduling functions are in this struct */ struct sctp_ss_functions ss_functions; diff --git a/freebsd/sys/netinet/sctp_sysctl.c b/freebsd/sys/netinet/sctp_sysctl.c index 152a2996..ea3b3d9c 100644 --- a/freebsd/sys/netinet/sctp_sysctl.c +++ b/freebsd/sys/netinet/sctp_sysctl.c @@ -312,8 +312,8 @@ sctp_sysctl_copy_out_local_addresses(struct sctp_inpcb *inp, struct sctp_tcb *st continue; memset((void *)&xladdr, 0, sizeof(struct xsctp_laddr)); memcpy((void *)&xladdr.address, (const void *)&laddr->ifa->address, sizeof(union sctp_sockstore)); - xladdr.start_time.tv_sec = (uint32_t) laddr->start_time.tv_sec; - xladdr.start_time.tv_usec = (uint32_t) laddr->start_time.tv_usec; + xladdr.start_time.tv_sec = (uint32_t)laddr->start_time.tv_sec; + xladdr.start_time.tv_usec = (uint32_t)laddr->start_time.tv_usec; SCTP_INP_RUNLOCK(inp); SCTP_INP_INFO_RUNLOCK(); error = SYSCTL_OUT(req, &xladdr, sizeof(struct xsctp_laddr)); @@ -418,10 +418,10 @@ sctp_sysctl_handle_assoclist(SYSCTL_HANDLER_ARGS) } else { xinpcb.qlen = so->so_qlen; xinpcb.qlen_old = so->so_qlen > USHRT_MAX ? - USHRT_MAX : (uint16_t) so->so_qlen; + USHRT_MAX : (uint16_t)so->so_qlen; xinpcb.maxqlen = so->so_qlimit; xinpcb.maxqlen_old = so->so_qlimit > USHRT_MAX ? - USHRT_MAX : (uint16_t) so->so_qlimit; + USHRT_MAX : (uint16_t)so->so_qlimit; } SCTP_INP_INCR_REF(inp); SCTP_INP_RUNLOCK(inp); @@ -448,7 +448,7 @@ sctp_sysctl_handle_assoclist(SYSCTL_HANDLER_ARGS) if (stcb->asoc.primary_destination != NULL) xstcb.primary_addr = stcb->asoc.primary_destination->ro._l_addr; xstcb.heartbeat_interval = stcb->asoc.heart_beat_delay; - xstcb.state = (uint32_t) sctp_map_assoc_state(stcb->asoc.state); + xstcb.state = (uint32_t)sctp_map_assoc_state(stcb->asoc.state); /* 7.0 does not support these */ xstcb.assoc_id = sctp_get_associd(stcb); xstcb.peers_rwnd = stcb->asoc.peers_rwnd; @@ -460,10 +460,10 @@ sctp_sysctl_handle_assoclist(SYSCTL_HANDLER_ARGS) xstcb.T1_expireries = stcb->asoc.timoinit + stcb->asoc.timocookie; xstcb.T2_expireries = stcb->asoc.timoshutdown + stcb->asoc.timoshutdownack; xstcb.retransmitted_tsns = stcb->asoc.marked_retrans; - xstcb.start_time.tv_sec = (uint32_t) stcb->asoc.start_time.tv_sec; - xstcb.start_time.tv_usec = (uint32_t) stcb->asoc.start_time.tv_usec; - xstcb.discontinuity_time.tv_sec = (uint32_t) stcb->asoc.discontinuity_time.tv_sec; - xstcb.discontinuity_time.tv_usec = (uint32_t) stcb->asoc.discontinuity_time.tv_usec; + xstcb.start_time.tv_sec = (uint32_t)stcb->asoc.start_time.tv_sec; + xstcb.start_time.tv_usec = (uint32_t)stcb->asoc.start_time.tv_usec; + xstcb.discontinuity_time.tv_sec = (uint32_t)stcb->asoc.discontinuity_time.tv_sec; + xstcb.discontinuity_time.tv_usec = (uint32_t)stcb->asoc.discontinuity_time.tv_usec; xstcb.total_sends = stcb->total_sends; xstcb.total_recvs = stcb->total_recvs; xstcb.local_tag = stcb->asoc.my_vtag; @@ -507,8 +507,8 @@ sctp_sysctl_handle_assoclist(SYSCTL_HANDLER_ARGS) xraddr.rtt = net->rtt / 1000; xraddr.heartbeat_interval = net->heart_beat_delay; xraddr.ssthresh = net->ssthresh; - xraddr.start_time.tv_sec = (uint32_t) net->start_time.tv_sec; - xraddr.start_time.tv_usec = (uint32_t) net->start_time.tv_usec; + xraddr.start_time.tv_sec = (uint32_t)net->start_time.tv_sec; + xraddr.start_time.tv_usec = (uint32_t)net->start_time.tv_usec; SCTP_INP_RUNLOCK(inp); SCTP_INP_INFO_RUNLOCK(); error = SYSCTL_OUT(req, &xraddr, sizeof(struct xsctp_raddr)); diff --git a/freebsd/sys/netinet/sctp_timer.c b/freebsd/sys/netinet/sctp_timer.c index 2d427e48..6b4b0be0 100644 --- a/freebsd/sys/netinet/sctp_timer.c +++ b/freebsd/sys/netinet/sctp_timer.c @@ -145,8 +145,8 @@ sctp_threshold_management(struct sctp_inpcb *inp, struct sctp_tcb *stcb, } SCTPDBG(SCTP_DEBUG_TIMER4, "Overall error count for %p now %d thresh:%u state:%x\n", (void *)&stcb->asoc, stcb->asoc.overall_error_count, - (uint32_t) threshold, - ((net == NULL) ? (uint32_t) 0 : (uint32_t) net->dest_state)); + (uint32_t)threshold, + ((net == NULL) ? (uint32_t)0 : (uint32_t)net->dest_state)); /* * We specifically do not do >= to give the assoc one more change * before we fail it. @@ -195,8 +195,10 @@ sctp_find_alternate_net(struct sctp_tcb *stcb, */ if (mode == 2) { TAILQ_FOREACH(mnet, &stcb->asoc.nets, sctp_next) { - /* JRS 5/14/07 - If the destination is unreachable - * or unconfirmed, skip it. */ + /* + * JRS 5/14/07 - If the destination is unreachable + * or unconfirmed, skip it. + */ if (((mnet->dest_state & SCTP_ADDR_REACHABLE) != SCTP_ADDR_REACHABLE) || (mnet->dest_state & SCTP_ADDR_UNCONFIRMED)) { continue; @@ -287,7 +289,7 @@ sctp_find_alternate_net(struct sctp_tcb *stcb, return (max_cwnd_net); } } /* JRS 5/14/07 - If mode is set to 1, use the - * CMT policy for choosing an alternate net. */ + * CMT policy for choosing an alternate net. */ else if (mode == 1) { TAILQ_FOREACH(mnet, &stcb->asoc.nets, sctp_next) { if (((mnet->dest_state & SCTP_ADDR_REACHABLE) != SCTP_ADDR_REACHABLE) || @@ -658,7 +660,7 @@ start_again: sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_RSND_TO, chk->whoTo->flight_size, chk->book_size, - (uint32_t) (uintptr_t) chk->whoTo, + (uint32_t)(uintptr_t)chk->whoTo, chk->rec.data.tsn); } sctp_flight_size_decrease(chk); @@ -786,7 +788,7 @@ start_again: sctp_misc_ints(SCTP_FLIGHT_LOG_UP, chk->whoTo->flight_size, chk->book_size, - (uint32_t) (uintptr_t) chk->whoTo, + (uint32_t)(uintptr_t)chk->whoTo, chk->rec.data.tsn); } sctp_flight_size_increase(chk); @@ -1433,8 +1435,8 @@ sctp_heartbeat_timer(struct sctp_inpcb *inp, struct sctp_tcb *stcb, SCTP_GETTIME_TIMEVAL(&diff); timevalsub(&diff, &net->last_sent_time); - ms_gone_by = (uint32_t) (diff.tv_sec * 1000) + - (uint32_t) (diff.tv_usec / 1000); + ms_gone_by = (uint32_t)(diff.tv_sec * 1000) + + (uint32_t)(diff.tv_usec / 1000); } else { ms_gone_by = 0xffffffff; } @@ -1475,7 +1477,7 @@ sctp_pathmtu_timer(struct sctp_inpcb *inp, net->ro._s_addr = sctp_source_address_selection(inp, stcb, - (sctp_route_t *) & net->ro, + (sctp_route_t *)&net->ro, net, 0, stcb->asoc.vrf_id); #if defined(INET6) && defined(SCTP_EMBEDDED_V6_SCOPE) if (net->ro._l_addr.sa.sa_family == AF_INET6) { diff --git a/freebsd/sys/netinet/sctp_usrreq.c b/freebsd/sys/netinet/sctp_usrreq.c index e3e398d4..ebaa58d4 100644 --- a/freebsd/sys/netinet/sctp_usrreq.c +++ b/freebsd/sys/netinet/sctp_usrreq.c @@ -72,9 +72,9 @@ sctp_init(void) * Allow a user to take no more than 1/2 the number of clusters or * the SB_MAX whichever is smaller for the send window. */ - sb_max_adj = (u_long)((u_quad_t) (SB_MAX) * MCLBYTES / (MSIZE + MCLBYTES)); + sb_max_adj = (u_long)((u_quad_t)(SB_MAX) * MCLBYTES / (MSIZE + MCLBYTES)); SCTP_BASE_SYSCTL(sctp_sendspace) = min(sb_max_adj, - (((uint32_t) nmbclusters / 2) * SCTP_DEFAULT_MAXSEGMENT)); + (((uint32_t)nmbclusters / 2) * SCTP_DEFAULT_MAXSEGMENT)); /* * Now for the recv window, should we take the same amount? or * should I do 1/2 the SB_MAX instead in the SB_MAX min above. For @@ -136,7 +136,7 @@ sctp_pathmtu_adjustment(struct sctp_tcb *stcb, uint16_t nxtsz) sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_PMTU, chk->whoTo->flight_size, chk->book_size, - (uint32_t) (uintptr_t) chk->whoTo, + (uint32_t)(uintptr_t)chk->whoTo, chk->rec.data.tsn); } /* Clear any time so NO RTT is being done */ @@ -977,8 +977,10 @@ sctp_shutdown(struct socket *so) } } sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, stcb->sctp_ep, stcb, netp); - /* XXX: Why do this in the case where we have still data - * queued? */ + /* + * XXX: Why do this in the case where we have still data + * queued? + */ sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED); SCTP_TCB_UNLOCK(stcb); SCTP_INP_RUNLOCK(inp); @@ -1481,7 +1483,7 @@ sctp_do_connect_x(struct socket *so, struct sctp_inpcb *inp, void *optval, SCTP_FROM_SCTP_USRREQ + SCTP_LOC_7); goto out_now; } - a_id = (sctp_assoc_t *) optval; + a_id = (sctp_assoc_t *)optval; *a_id = sctp_get_associd(stcb); /* initialize authentication parameters for the assoc */ @@ -1813,8 +1815,10 @@ flags_out: } SCTP_TCB_UNLOCK(stcb); } else { - /* Can't get stream value without - * association */ + /* + * Can't get stream value without + * association + */ SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); error = EINVAL; } @@ -2178,7 +2182,7 @@ flags_out: SCTP_CHECK_AND_CAST(value, optval, uint32_t, *optsize); /* FIXME MT: change to sctp_assoc_value? */ - SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value); + SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value); if (stcb) { size = 0; @@ -2208,7 +2212,7 @@ flags_out: } } SCTP_TCB_UNLOCK(stcb); - *value = (uint32_t) size; + *value = (uint32_t)size; *optsize = sizeof(uint32_t); } else { SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOTCONN); @@ -2934,7 +2938,7 @@ flags_out: } else { /* copy in the chunks */ (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks); - sac->gauth_number_of_chunks = (uint32_t) size; + sac->gauth_number_of_chunks = (uint32_t)size; *optsize = sizeof(struct sctp_authchunks) + size; } SCTP_TCB_UNLOCK(stcb); @@ -2953,7 +2957,7 @@ flags_out: } else { /* copy in the chunks */ (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks); - sac->gauth_number_of_chunks = (uint32_t) size; + sac->gauth_number_of_chunks = (uint32_t)size; *optsize = sizeof(struct sctp_authchunks) + size; } SCTP_INP_RUNLOCK(inp); @@ -2984,7 +2988,7 @@ flags_out: } else { /* copy in the chunks */ (void)sctp_serialize_auth_chunks(chklist, sac->gauth_chunks); - sac->gauth_number_of_chunks = (uint32_t) size; + sac->gauth_number_of_chunks = (uint32_t)size; *optsize = sizeof(struct sctp_authchunks) + size; } SCTP_TCB_UNLOCK(stcb); @@ -3590,14 +3594,14 @@ flags_out: SCTP_FIND_STCB(inp, stcb, av->assoc_id); if (stcb) { - av->assoc_value = (uint32_t) stcb->asoc.local_strreset_support; + av->assoc_value = (uint32_t)stcb->asoc.local_strreset_support; SCTP_TCB_UNLOCK(stcb); } else { if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || (av->assoc_id == SCTP_FUTURE_ASSOC)) { SCTP_INP_RLOCK(inp); - av->assoc_value = (uint32_t) inp->local_strreset_support; + av->assoc_value = (uint32_t)inp->local_strreset_support; SCTP_INP_RUNLOCK(inp); } else { SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); @@ -3889,10 +3893,12 @@ sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize, (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS))) { inp->idata_supported = 1; } else { - /* Must have Frag + /* + * Must have Frag * interleave and * stream interleave - * on */ + * on + */ SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); error = EINVAL; } @@ -4103,8 +4109,10 @@ sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize, } SCTP_INP_RUNLOCK(inp); } else { - /* Can't set stream value without - * association */ + /* + * Can't set stream value without + * association + */ SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); error = EINVAL; } @@ -4270,7 +4278,7 @@ sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize, * insert/replace it */ if (size > 0) { - key = sctp_set_key(sca->sca_key, (uint32_t) size); + key = sctp_set_key(sca->sca_key, (uint32_t)size); if (key == NULL) { SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM); error = ENOMEM; @@ -4307,7 +4315,7 @@ sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize, * insert/replace it */ if (size > 0) { - key = sctp_set_key(sca->sca_key, (uint32_t) size); + key = sctp_set_key(sca->sca_key, (uint32_t)size); if (key == NULL) { SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM); error = ENOMEM; @@ -4334,15 +4342,17 @@ sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize, LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) { SCTP_TCB_LOCK(stcb); shared_keys = &stcb->asoc.shared_keys; - /* clear the cached keys for - * this key id */ + /* + * clear the cached keys for + * this key id + */ sctp_clear_cachedkeys(stcb, sca->sca_keynumber); /* * create the new shared key * and insert/replace it */ if (size > 0) { - key = sctp_set_key(sca->sca_key, (uint32_t) size); + key = sctp_set_key(sca->sca_key, (uint32_t)size); if (key == NULL) { SCTP_TCB_UNLOCK(stcb); continue; @@ -4378,7 +4388,7 @@ sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize, error = EINVAL; break; } - hmaclist = sctp_alloc_hmaclist((uint16_t) shmac->shmac_number_of_idents); + hmaclist = sctp_alloc_hmaclist((uint16_t)shmac->shmac_number_of_idents); if (hmaclist == NULL) { SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOMEM); error = ENOMEM; @@ -4549,7 +4559,7 @@ sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize, } SCTP_FIND_STCB(inp, stcb, av->assoc_id); if (stcb) { - stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value; + stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value; SCTP_TCB_UNLOCK(stcb); } else { if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || @@ -4557,7 +4567,7 @@ sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize, (av->assoc_id == SCTP_FUTURE_ASSOC) || (av->assoc_id == SCTP_ALL_ASSOC)) { SCTP_INP_WLOCK(inp); - inp->local_strreset_support = (uint8_t) av->assoc_value; + inp->local_strreset_support = (uint8_t)av->assoc_value; SCTP_INP_WUNLOCK(inp); } if ((av->assoc_id == SCTP_CURRENT_ASSOC) || @@ -4565,7 +4575,7 @@ sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize, SCTP_INP_RLOCK(inp); LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) { SCTP_TCB_LOCK(stcb); - stcb->asoc.local_strreset_support = (uint8_t) av->assoc_value; + stcb->asoc.local_strreset_support = (uint8_t)av->assoc_value; SCTP_TCB_UNLOCK(stcb); } SCTP_INP_RUNLOCK(inp); @@ -4734,8 +4744,10 @@ sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize, int cnt; addstream |= 2; - /* We allocate inside - * sctp_send_str_reset_req() */ + /* + * We allocate inside + * sctp_send_str_reset_req() + */ add_i_strmcnt = stradd->sas_instrms; cnt = add_i_strmcnt; cnt += stcb->asoc.streamincnt; @@ -4762,7 +4774,7 @@ sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize, uint32_t *value; SCTP_CHECK_AND_CAST(value, optval, uint32_t, optsize); - SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t) * value); + SCTP_FIND_STCB(inp, stcb, (sctp_assoc_t)*value); if (stcb == NULL) { SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOENT); error = ENOENT; @@ -4783,8 +4795,10 @@ sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize, SCTP_TCB_UNLOCK(stcb); break; } - /* Is there any data pending in the send or sent - * queues? */ + /* + * Is there any data pending in the send or sent + * queues? + */ if (!TAILQ_EMPTY(&stcb->asoc.send_queue) || !TAILQ_EMPTY(&stcb->asoc.sent_queue)) { busy_out: @@ -4930,8 +4944,10 @@ sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize, (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) || (av->assoc_id == SCTP_FUTURE_ASSOC)) { SCTP_INP_WLOCK(inp); - /* FIXME MT: I think this is not in - * tune with the API ID */ + /* + * FIXME MT: I think this is not in + * tune with the API ID + */ if (av->assoc_value) { inp->sctp_frag_point = (av->assoc_value + ovh); } else { @@ -5074,8 +5090,10 @@ sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize, } SCTP_TCB_UNLOCK(stcb); } - /* Send up the sender dry event only for 1-to-1 - * style sockets. */ + /* + * Send up the sender dry event only for 1-to-1 + * style sockets. + */ if (events->sctp_sender_dry_event) { if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) { @@ -5786,8 +5804,10 @@ sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize, goto out_of_it; } if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) { - /* Must validate the ifa found is in - * our ep */ + /* + * Must validate the ifa found is in + * our ep + */ struct sctp_laddr *laddr; int found = 0; @@ -6543,8 +6563,10 @@ sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize, (av->assoc_id == SCTP_FUTURE_ASSOC)) { if ((av->assoc_value == 0) && (inp->asconf_supported == 1)) { - /* AUTH is required for - * ASCONF */ + /* + * AUTH is required for + * ASCONF + */ SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); error = EINVAL; } else { @@ -6580,8 +6602,10 @@ sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize, (av->assoc_id == SCTP_FUTURE_ASSOC)) { if ((av->assoc_value != 0) && (inp->auth_supported == 0)) { - /* AUTH is required for - * ASCONF */ + /* + * AUTH is required for + * ASCONF + */ SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL); error = EINVAL; } else { @@ -7013,8 +7037,10 @@ sctp_listen(struct socket *so, int backlog, struct thread *p) ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) && ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) && (tinp->sctp_socket->so_qlimit)) { - /* we have a listener already and - * its not this inp. */ + /* + * we have a listener already and + * its not this inp. + */ SCTP_INP_DECR_REF(tinp); return (EADDRINUSE); } else if (tinp) { @@ -7055,8 +7081,10 @@ sctp_listen(struct socket *so, int backlog, struct thread *p) ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) == 0) && ((tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) && (tinp->sctp_socket->so_qlimit)) { - /* we have a listener already and its not - * this inp. */ + /* + * we have a listener already and its not + * this inp. + */ SCTP_INP_DECR_REF(tinp); return (EADDRINUSE); } else if (tinp) { @@ -7296,7 +7324,7 @@ sctp_ingetaddr(struct socket *so, struct sockaddr **addr) vrf_id = inp->def_vrf_id; sctp_ifa = sctp_source_address_selection(inp, stcb, - (sctp_route_t *) & net->ro, + (sctp_route_t *)&net->ro, net, 0, vrf_id); if (sctp_ifa) { sin->sin_addr = sctp_ifa->address.sin.sin_addr; diff --git a/freebsd/sys/netinet/sctputil.c b/freebsd/sys/netinet/sctputil.c index 136b4bb6..79bb0620 100644 --- a/freebsd/sys/netinet/sctputil.c +++ b/freebsd/sys/netinet/sctputil.c @@ -96,7 +96,7 @@ sctp_log_closing(struct sctp_inpcb *inp, struct sctp_tcb *stcb, int16_t loc) sctp_clog.x.close.sctp_flags = inp->sctp_flags; if (stcb) { sctp_clog.x.close.stcb = (void *)stcb; - sctp_clog.x.close.state = (uint16_t) stcb->asoc.state; + sctp_clog.x.close.state = (uint16_t)stcb->asoc.state; } else { sctp_clog.x.close.stcb = 0; sctp_clog.x.close.state = 0; @@ -229,12 +229,12 @@ sctp_log_mb(struct mbuf *m, int from) struct sctp_cwnd_log sctp_clog; sctp_clog.x.mb.mp = m; - sctp_clog.x.mb.mbuf_flags = (uint8_t) (SCTP_BUF_GET_FLAGS(m)); - sctp_clog.x.mb.size = (uint16_t) (SCTP_BUF_LEN(m)); + sctp_clog.x.mb.mbuf_flags = (uint8_t)(SCTP_BUF_GET_FLAGS(m)); + sctp_clog.x.mb.size = (uint16_t)(SCTP_BUF_LEN(m)); sctp_clog.x.mb.data = SCTP_BUF_AT(m, 0); if (SCTP_BUF_IS_EXTENDED(m)) { sctp_clog.x.mb.ext = SCTP_BUF_EXTEND_BASE(m); - sctp_clog.x.mb.refcnt = (uint8_t) (SCTP_BUF_EXTEND_REFCNT(m)); + sctp_clog.x.mb.refcnt = (uint8_t)(SCTP_BUF_EXTEND_REFCNT(m)); } else { sctp_clog.x.mb.ext = 0; sctp_clog.x.mb.refcnt = 0; @@ -270,11 +270,11 @@ sctp_log_strm_del(struct sctp_queued_to_read *control, struct sctp_queued_to_rea } sctp_clog.x.strlog.stcb = control->stcb; sctp_clog.x.strlog.n_tsn = control->sinfo_tsn; - sctp_clog.x.strlog.n_sseq = (uint16_t) control->mid; + sctp_clog.x.strlog.n_sseq = (uint16_t)control->mid; sctp_clog.x.strlog.strm = control->sinfo_stream; if (poschk != NULL) { sctp_clog.x.strlog.e_tsn = poschk->sinfo_tsn; - sctp_clog.x.strlog.e_sseq = (uint16_t) poschk->mid; + sctp_clog.x.strlog.e_sseq = (uint16_t)poschk->mid; } else { sctp_clog.x.strlog.e_tsn = 0; sctp_clog.x.strlog.e_sseq = 0; @@ -471,12 +471,12 @@ sctp_wakeup_log(struct sctp_tcb *stcb, uint32_t wake_cnt, int from) sctp_clog.x.wake.sent_q = stcb->asoc.sent_queue_cnt; if (stcb->asoc.stream_queue_cnt < 0xff) - sctp_clog.x.wake.stream_qcnt = (uint8_t) stcb->asoc.stream_queue_cnt; + sctp_clog.x.wake.stream_qcnt = (uint8_t)stcb->asoc.stream_queue_cnt; else sctp_clog.x.wake.stream_qcnt = 0xff; if (stcb->asoc.chunks_on_out_queue < 0xff) - sctp_clog.x.wake.chunks_on_oque = (uint8_t) stcb->asoc.chunks_on_out_queue; + sctp_clog.x.wake.chunks_on_oque = (uint8_t)stcb->asoc.chunks_on_out_queue; else sctp_clog.x.wake.chunks_on_oque = 0xff; @@ -492,7 +492,7 @@ sctp_wakeup_log(struct sctp_tcb *stcb, uint32_t wake_cnt, int from) if (stcb->sctp_socket) { struct socket *so = stcb->sctp_socket; - sctp_clog.x.wake.sbflags = (uint8_t) ((so->so_snd.sb_flags & 0x00ff)); + sctp_clog.x.wake.sbflags = (uint8_t)((so->so_snd.sb_flags & 0x00ff)); } else { sctp_clog.x.wake.sbflags = 0xff; } @@ -511,12 +511,12 @@ sctp_log_block(uint8_t from, struct sctp_association *asoc, size_t sendlen) struct sctp_cwnd_log sctp_clog; sctp_clog.x.blk.onsb = asoc->total_output_queue_size; - sctp_clog.x.blk.send_sent_qcnt = (uint16_t) (asoc->send_queue_cnt + asoc->sent_queue_cnt); + sctp_clog.x.blk.send_sent_qcnt = (uint16_t)(asoc->send_queue_cnt + asoc->sent_queue_cnt); sctp_clog.x.blk.peer_rwnd = asoc->peers_rwnd; - sctp_clog.x.blk.stream_qcnt = (uint16_t) asoc->stream_queue_cnt; - sctp_clog.x.blk.chunks_on_oque = (uint16_t) asoc->chunks_on_out_queue; - sctp_clog.x.blk.flight_size = (uint16_t) (asoc->total_flight / 1024); - sctp_clog.x.blk.sndlen = (uint32_t) sendlen; + sctp_clog.x.blk.stream_qcnt = (uint16_t)asoc->stream_queue_cnt; + sctp_clog.x.blk.chunks_on_oque = (uint16_t)asoc->chunks_on_out_queue; + sctp_clog.x.blk.flight_size = (uint16_t)(asoc->total_flight / 1024); + sctp_clog.x.blk.sndlen = (uint32_t)sendlen; SCTP_CTR6(KTR_SCTP, "SCTP:%d[%d]:%x-%x-%x-%x", SCTP_LOG_EVENT_BLOCK, from, @@ -558,8 +558,8 @@ sctp_print_audit_report(void) SCTP_PRINTF("\n"); cnt = 0; } - SCTP_PRINTF("%2.2x%2.2x ", (uint32_t) sctp_audit_data[i][0], - (uint32_t) sctp_audit_data[i][1]); + SCTP_PRINTF("%2.2x%2.2x ", (uint32_t)sctp_audit_data[i][0], + (uint32_t)sctp_audit_data[i][1]); cnt++; if ((cnt % 14) == 0) SCTP_PRINTF("\n"); @@ -577,8 +577,8 @@ sctp_print_audit_report(void) SCTP_PRINTF("\n"); cnt = 0; } - SCTP_PRINTF("%2.2x%2.2x ", (uint32_t) sctp_audit_data[i][0], - (uint32_t) sctp_audit_data[i][1]); + SCTP_PRINTF("%2.2x%2.2x ", (uint32_t)sctp_audit_data[i][0], + (uint32_t)sctp_audit_data[i][1]); cnt++; if ((cnt % 14) == 0) SCTP_PRINTF("\n"); @@ -830,9 +830,9 @@ sctp_fill_random_store(struct sctp_pcb *m) * numbers, but thats ok too since that is random as well :-> */ m->store_at = 0; - (void)sctp_hmac(SCTP_HMAC, (uint8_t *) m->random_numbers, - sizeof(m->random_numbers), (uint8_t *) & m->random_counter, - sizeof(m->random_counter), (uint8_t *) m->random_store); + (void)sctp_hmac(SCTP_HMAC, (uint8_t *)m->random_numbers, + sizeof(m->random_numbers), (uint8_t *)&m->random_counter, + sizeof(m->random_counter), (uint8_t *)m->random_store); m->random_counter++; } @@ -869,7 +869,7 @@ retry: sctp_fill_random_store(inp); } p = &inp->random_store[store_at]; - xp = (uint32_t *) p; + xp = (uint32_t *)p; x = *xp; return (x); } @@ -978,7 +978,7 @@ sctp_init_asoc(struct sctp_inpcb *inp, struct sctp_tcb *stcb, asoc->nrsack_supported = inp->nrsack_supported; asoc->pktdrop_supported = inp->pktdrop_supported; asoc->idata_supported = inp->idata_supported; - asoc->sctp_cmt_pf = (uint8_t) 0; + asoc->sctp_cmt_pf = (uint8_t)0; asoc->sctp_frag_point = inp->sctp_frag_point; asoc->sctp_features = inp->sctp_features; asoc->default_dscp = inp->sctp_ep.default_dscp; @@ -1484,8 +1484,10 @@ sctp_handle_addr_wq(void) sctp_asconf_iterator_end, NULL, 0); if (ret) { SCTP_PRINTF("Failed to initiate iterator for handle_addr_wq\n"); - /* Freeing if we are stopping or put back on the - * addr_wq. */ + /* + * Freeing if we are stopping or put back on the + * addr_wq. + */ if (SCTP_BASE_VAR(sctp_pcb_initialized) == 0) { sctp_asconf_iterator_end(asc, 0); } else { @@ -1522,7 +1524,7 @@ sctp_timeout_handler(void *t) did_output = 1; #ifdef SCTP_AUDITING_ENABLED - sctp_audit_log(0xF0, (uint8_t) tmr->type); + sctp_audit_log(0xF0, (uint8_t)tmr->type); sctp_auditing(3, inp, stcb, net); #endif @@ -1917,7 +1919,7 @@ sctp_timeout_handler(void *t) break; } #ifdef SCTP_AUDITING_ENABLED - sctp_audit_log(0xF1, (uint8_t) type); + sctp_audit_log(0xF1, (uint8_t)type); if (inp) sctp_auditing(5, inp, stcb, net); #endif @@ -2479,14 +2481,16 @@ sctp_calculate_rto(struct sctp_tcb *stcb, } timevalsub(&now, old); /* store the current RTT in us */ - net->rtt = (uint64_t) 1000000 *(uint64_t) now.tv_sec + - (uint64_t) now.tv_usec; + net->rtt = (uint64_t)1000000 *(uint64_t)now.tv_sec + + (uint64_t)now.tv_usec; /* compute rtt in ms */ - rtt = (int32_t) (net->rtt / 1000); + rtt = (int32_t)(net->rtt / 1000); if ((asoc->cc_functions.sctp_rtt_calculated) && (rtt_from_sack == SCTP_RTT_FROM_DATA)) { - /* Tell the CC module that a new update has just occurred - * from a sack */ + /* + * Tell the CC module that a new update has just occurred + * from a sack + */ (*asoc->cc_functions.sctp_rtt_calculated) (stcb, net, &now); } /* @@ -2562,7 +2566,7 @@ sctp_calculate_rto(struct sctp_tcb *stcb, * is >= 'len' returns NULL if there there isn't 'len' bytes in the chain. */ caddr_t -sctp_m_getptr(struct mbuf *m, int off, int len, uint8_t * in_ptr) +sctp_m_getptr(struct mbuf *m, int off, int len, uint8_t *in_ptr) { uint32_t count; uint8_t *ptr; @@ -2611,7 +2615,7 @@ sctp_get_next_param(struct mbuf *m, { /* This just provides a typed signature to Peter's Pull routine */ return ((struct sctp_paramhdr *)sctp_m_getptr(m, offset, pull_limit, - (uint8_t *) pull)); + (uint8_t *)pull)); } @@ -2974,7 +2978,7 @@ sctp_notify_send_failed(struct sctp_tcb *stcb, uint8_t sent, uint32_t error, } else { ssfe->ssfe_flags = SCTP_DATA_UNSENT; } - ssfe->ssfe_length = (uint32_t) (notifhdr_len + payload_len); + ssfe->ssfe_length = (uint32_t)(notifhdr_len + payload_len); ssfe->ssfe_error = error; /* not exactly what the user sent in, but should be close :) */ ssfe->ssfe_info.snd_sid = chk->rec.data.sid; @@ -2992,11 +2996,11 @@ sctp_notify_send_failed(struct sctp_tcb *stcb, uint8_t sent, uint32_t error, } else { ssf->ssf_flags = SCTP_DATA_UNSENT; } - ssf->ssf_length = (uint32_t) (notifhdr_len + payload_len); + ssf->ssf_length = (uint32_t)(notifhdr_len + payload_len); ssf->ssf_error = error; /* not exactly what the user sent in, but should be close :) */ ssf->ssf_info.sinfo_stream = chk->rec.data.sid; - ssf->ssf_info.sinfo_ssn = (uint16_t) chk->rec.data.mid; + ssf->ssf_info.sinfo_ssn = (uint16_t)chk->rec.data.mid; ssf->ssf_info.sinfo_flags = chk->rec.data.rcv_flags; ssf->ssf_info.sinfo_ppid = chk->rec.data.ppid; ssf->ssf_info.sinfo_context = chk->rec.data.context; @@ -3078,7 +3082,7 @@ sctp_notify_send_failed2(struct sctp_tcb *stcb, uint32_t error, memset(ssfe, 0, notifhdr_len); ssfe->ssfe_type = SCTP_SEND_FAILED_EVENT; ssfe->ssfe_flags = SCTP_DATA_UNSENT; - ssfe->ssfe_length = (uint32_t) (notifhdr_len + sp->length); + ssfe->ssfe_length = (uint32_t)(notifhdr_len + sp->length); ssfe->ssfe_error = error; /* not exactly what the user sent in, but should be close :) */ ssfe->ssfe_info.snd_sid = sp->sid; @@ -3096,7 +3100,7 @@ sctp_notify_send_failed2(struct sctp_tcb *stcb, uint32_t error, memset(ssf, 0, notifhdr_len); ssf->ssf_type = SCTP_SEND_FAILED; ssf->ssf_flags = SCTP_DATA_UNSENT; - ssf->ssf_length = (uint32_t) (notifhdr_len + sp->length); + ssf->ssf_length = (uint32_t)(notifhdr_len + sp->length); ssf->ssf_error = error; /* not exactly what the user sent in, but should be close :) */ ssf->ssf_info.sinfo_stream = sp->sid; @@ -3513,7 +3517,7 @@ sctp_notify_stream_reset_tsn(struct sctp_tcb *stcb, uint32_t sending_tsn, uint32 static void sctp_notify_stream_reset(struct sctp_tcb *stcb, - int number_entries, uint16_t * list, int flag) + int number_entries, uint16_t *list, int flag) { struct mbuf *m_notify; struct sctp_queued_to_read *control; @@ -3721,7 +3725,7 @@ sctp_ulp_notify(uint32_t notification, struct sctp_tcb *stcb, { uint32_t val; - val = *((uint32_t *) data); + val = *((uint32_t *)data); sctp_notify_partial_delivery_indication(stcb, error, val, so_locked); break; @@ -3750,25 +3754,25 @@ sctp_ulp_notify(uint32_t notification, struct sctp_tcb *stcb, } break; case SCTP_NOTIFY_STR_RESET_SEND: - sctp_notify_stream_reset(stcb, error, ((uint16_t *) data), SCTP_STREAM_RESET_OUTGOING_SSN); + sctp_notify_stream_reset(stcb, error, ((uint16_t *)data), SCTP_STREAM_RESET_OUTGOING_SSN); break; case SCTP_NOTIFY_STR_RESET_RECV: - sctp_notify_stream_reset(stcb, error, ((uint16_t *) data), SCTP_STREAM_RESET_INCOMING); + sctp_notify_stream_reset(stcb, error, ((uint16_t *)data), SCTP_STREAM_RESET_INCOMING); break; case SCTP_NOTIFY_STR_RESET_FAILED_OUT: - sctp_notify_stream_reset(stcb, error, ((uint16_t *) data), + sctp_notify_stream_reset(stcb, error, ((uint16_t *)data), (SCTP_STREAM_RESET_OUTGOING_SSN | SCTP_STREAM_RESET_FAILED)); break; case SCTP_NOTIFY_STR_RESET_DENIED_OUT: - sctp_notify_stream_reset(stcb, error, ((uint16_t *) data), + sctp_notify_stream_reset(stcb, error, ((uint16_t *)data), (SCTP_STREAM_RESET_OUTGOING_SSN | SCTP_STREAM_RESET_DENIED)); break; case SCTP_NOTIFY_STR_RESET_FAILED_IN: - sctp_notify_stream_reset(stcb, error, ((uint16_t *) data), + sctp_notify_stream_reset(stcb, error, ((uint16_t *)data), (SCTP_STREAM_RESET_INCOMING | SCTP_STREAM_RESET_FAILED)); break; case SCTP_NOTIFY_STR_RESET_DENIED_IN: - sctp_notify_stream_reset(stcb, error, ((uint16_t *) data), + sctp_notify_stream_reset(stcb, error, ((uint16_t *)data), (SCTP_STREAM_RESET_INCOMING | SCTP_STREAM_RESET_DENIED)); break; case SCTP_NOTIFY_ASCONF_ADD_IP: @@ -3788,17 +3792,17 @@ sctp_ulp_notify(uint32_t notification, struct sctp_tcb *stcb, break; case SCTP_NOTIFY_AUTH_NEW_KEY: sctp_notify_authentication(stcb, SCTP_AUTH_NEW_KEY, error, - (uint16_t) (uintptr_t) data, + (uint16_t)(uintptr_t)data, so_locked); break; case SCTP_NOTIFY_AUTH_FREE_KEY: sctp_notify_authentication(stcb, SCTP_AUTH_FREE_KEY, error, - (uint16_t) (uintptr_t) data, + (uint16_t)(uintptr_t)data, so_locked); break; case SCTP_NOTIFY_NO_PEER_AUTH: sctp_notify_authentication(stcb, SCTP_AUTH_NO_AUTH, error, - (uint16_t) (uintptr_t) data, + (uint16_t)(uintptr_t)data, so_locked); break; case SCTP_NOTIFY_SENDER_DRY: @@ -4148,7 +4152,7 @@ sctp_handle_ootb(struct mbuf *m, int iphlen, int offset, } contains_init_chunk = 0; ch = (struct sctp_chunkhdr *)sctp_m_getptr(m, offset, - sizeof(*ch), (uint8_t *) & chunk_buf); + sizeof(*ch), (uint8_t *)&chunk_buf); while (ch != NULL) { chk_length = ntohs(ch->chunk_length); if (chk_length < sizeof(*ch)) { @@ -4181,7 +4185,7 @@ sctp_handle_ootb(struct mbuf *m, int iphlen, int offset, } offset += SCTP_SIZE32(chk_length); ch = (struct sctp_chunkhdr *)sctp_m_getptr(m, offset, - sizeof(*ch), (uint8_t *) & chunk_buf); + sizeof(*ch), (uint8_t *)&chunk_buf); } if ((SCTP_BASE_SYSCTL(sctp_blackhole) == 0) || ((SCTP_BASE_SYSCTL(sctp_blackhole) == 1) && @@ -4197,7 +4201,7 @@ sctp_handle_ootb(struct mbuf *m, int iphlen, int offset, * if there is return 1, else return 0. */ int -sctp_is_there_an_abort_here(struct mbuf *m, int iphlen, uint32_t * vtagfill) +sctp_is_there_an_abort_here(struct mbuf *m, int iphlen, uint32_t *vtagfill) { struct sctp_chunkhdr *ch; struct sctp_init_chunk *init_chk, chunk_buf; @@ -4206,7 +4210,7 @@ sctp_is_there_an_abort_here(struct mbuf *m, int iphlen, uint32_t * vtagfill) offset = iphlen + sizeof(struct sctphdr); ch = (struct sctp_chunkhdr *)sctp_m_getptr(m, offset, sizeof(*ch), - (uint8_t *) & chunk_buf); + (uint8_t *)&chunk_buf); while (ch != NULL) { chk_length = ntohs(ch->chunk_length); if (chk_length < sizeof(*ch)) { @@ -4221,7 +4225,7 @@ sctp_is_there_an_abort_here(struct mbuf *m, int iphlen, uint32_t * vtagfill) if (ch->chunk_type == SCTP_INITIATION) { /* need to update the Vtag */ init_chk = (struct sctp_init_chunk *)sctp_m_getptr(m, - offset, sizeof(*init_chk), (uint8_t *) & chunk_buf); + offset, sizeof(*init_chk), (uint8_t *)&chunk_buf); if (init_chk != NULL) { *vtagfill = ntohl(init_chk->init.initiate_tag); } @@ -4229,7 +4233,7 @@ sctp_is_there_an_abort_here(struct mbuf *m, int iphlen, uint32_t * vtagfill) /* Nope, move to the next chunk */ offset += SCTP_SIZE32(chk_length); ch = (struct sctp_chunkhdr *)sctp_m_getptr(m, offset, - sizeof(*ch), (uint8_t *) & chunk_buf); + sizeof(*ch), (uint8_t *)&chunk_buf); } return (0); } @@ -4615,7 +4619,7 @@ sctp_generate_cause(uint16_t code, char *info) if (info_len > (SCTP_MAX_CAUSE_LENGTH - sizeof(struct sctp_paramhdr))) { return (NULL); } - len = (uint16_t) (sizeof(struct sctp_paramhdr) + info_len); + len = (uint16_t)(sizeof(struct sctp_paramhdr) + info_len); m = sctp_get_mbuf_for_msg(len, 0, M_NOWAIT, 1, MT_DATA); if (m != NULL) { SCTP_BUF_LEN(m) = len; @@ -4634,14 +4638,14 @@ sctp_generate_no_user_data_cause(uint32_t tsn) struct sctp_error_no_user_data *no_user_data_cause; uint16_t len; - len = (uint16_t) sizeof(struct sctp_error_no_user_data); + len = (uint16_t)sizeof(struct sctp_error_no_user_data); m = sctp_get_mbuf_for_msg(len, 0, M_NOWAIT, 1, MT_DATA); if (m != NULL) { SCTP_BUF_LEN(m) = len; no_user_data_cause = mtod(m, struct sctp_error_no_user_data *); no_user_data_cause->cause.code = htons(SCTP_CAUSE_NO_USER_DATA); no_user_data_cause->cause.length = htons(len); - no_user_data_cause->tsn = tsn; /* tsn is passed in as NBO */ + no_user_data_cause->tsn = htonl(tsn); } return (m); } @@ -4794,8 +4798,10 @@ sctp_release_pr_sctp_chunk(struct sctp_tcb *stcb, struct sctp_tmit_chunk *tp1, do_wakeup_routine = 1; tp1->sent = SCTP_FORWARD_TSN_SKIP; TAILQ_REMOVE(&stcb->asoc.send_queue, tp1, sctp_next); - /* on to the sent queue so we can wait for it to be - * passed by. */ + /* + * on to the sent queue so we can wait for it to be + * passed by. + */ TAILQ_INSERT_TAIL(&stcb->asoc.sent_queue, tp1, sctp_next); stcb->asoc.send_queue_cnt--; @@ -5028,8 +5034,8 @@ sctp_find_ifa_by_addr(struct sockaddr *addr, uint32_t vrf_id, int holds_lock) hash_head = &vrf->vrf_addr_hash[(hash_of_addr & vrf->vrf_addr_hashmark)]; if (hash_head == NULL) { SCTP_PRINTF("hash_of_addr:%x mask:%x table:%x - ", - hash_of_addr, (uint32_t) vrf->vrf_addr_hashmark, - (uint32_t) (hash_of_addr & vrf->vrf_addr_hashmark)); + hash_of_addr, (uint32_t)vrf->vrf_addr_hashmark, + (uint32_t)(hash_of_addr & vrf->vrf_addr_hashmark)); sctp_print_address(addr); SCTP_PRINTF("No such bucket for address\n"); if (holds_lock == 0) @@ -5071,7 +5077,7 @@ sctp_find_ifa_by_addr(struct sockaddr *addr, uint32_t vrf_id, int holds_lock) } static void -sctp_user_rcvd(struct sctp_tcb *stcb, uint32_t * freed_so_far, int hold_rlock, +sctp_user_rcvd(struct sctp_tcb *stcb, uint32_t *freed_so_far, int hold_rlock, uint32_t rwnd_req) { /* User pulled some data, do we need a rwnd update? */ @@ -5233,11 +5239,11 @@ sctp_sorecvmsg(struct socket *so, in_eeor_mode = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR); if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_RECV_RWND_LOGGING_ENABLE) { sctp_misc_ints(SCTP_SORECV_ENTER, - rwnd_req, in_eeor_mode, so->so_rcv.sb_cc, (uint32_t) uio->uio_resid); + rwnd_req, in_eeor_mode, so->so_rcv.sb_cc, (uint32_t)uio->uio_resid); } if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_RECV_RWND_LOGGING_ENABLE) { sctp_misc_ints(SCTP_SORECV_ENTERPL, - rwnd_req, block_allowed, so->so_rcv.sb_cc, (uint32_t) uio->uio_resid); + rwnd_req, block_allowed, so->so_rcv.sb_cc, (uint32_t)uio->uio_resid); } error = sblock(&so->so_rcv, (block_allowed ? SBL_WAIT : 0)); if (error) { @@ -5288,8 +5294,10 @@ restart_nosblocks: * connect. */ if (inp->sctp_flags & SCTP_PCB_FLAGS_WAS_ABORTED) { - /* You were aborted, passive side - * always hits here */ + /* + * You were aborted, passive side + * always hits here + */ SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTPUTIL, ECONNRESET); error = ECONNRESET; } @@ -5388,8 +5396,10 @@ restart_nosblocks: } if ((control->length == 0) && (control->end_added == 1)) { - /* Do we also need to check for (control->pdapi_aborted == - * 1)? */ + /* + * Do we also need to check for (control->pdapi_aborted == + * 1)? + */ if (hold_rlock == 0) { hold_rlock = 1; SCTP_INP_READ_LOCK(inp); @@ -5530,7 +5540,7 @@ found_one: /* First lets get off the sinfo and sockaddr info */ if ((sinfo != NULL) && (filling_sinfo != 0)) { sinfo->sinfo_stream = control->sinfo_stream; - sinfo->sinfo_ssn = (uint16_t) control->mid; + sinfo->sinfo_ssn = (uint16_t)control->mid; sinfo->sinfo_flags = control->sinfo_flags; sinfo->sinfo_ppid = control->sinfo_ppid; sinfo->sinfo_context = control->sinfo_context; @@ -5606,7 +5616,7 @@ found_one: entry = &inp->readlog[index]; entry->vtag = control->sinfo_assoc_id; entry->strm = control->sinfo_stream; - entry->seq = (uint16_t) control->mid; + entry->seq = (uint16_t)control->mid; entry->sz = control->length; entry->flgs = control->sinfo_flags; } @@ -5732,8 +5742,10 @@ get_more_data: atomic_subtract_int(&control->length, cp_len); control->data = sctp_m_free(m); m = control->data; - /* been through it all, must hold sb - * lock ok to null tail */ + /* + * been through it all, must hold sb + * lock ok to null tail + */ if (control->data == NULL) { #ifdef INVARIANTS if ((control->end_added == 0) || @@ -5866,7 +5878,7 @@ get_more_data: } if ((uio->uio_resid == 0) || ((in_eeor_mode) && - (copied_so_far >= (uint32_t) max(so->so_rcv.sb_lowat, 1)))) { + (copied_so_far >= (uint32_t)max(so->so_rcv.sb_lowat, 1)))) { goto release; } /* @@ -5952,8 +5964,10 @@ wait_some_more: */ SCTP_INP_READ_LOCK(inp); if ((control->length > 0) && (control->data == NULL)) { - /* big trouble.. we have the lock and its - * corrupt? */ + /* + * big trouble.. we have the lock and its + * corrupt? + */ #ifdef INVARIANTS panic("Impossible data==NULL length !=0"); #endif @@ -6084,13 +6098,13 @@ out: if (stcb) { sctp_misc_ints(SCTP_SORECV_DONE, freed_so_far, - (uint32_t) ((uio) ? (slen - uio->uio_resid) : slen), + (uint32_t)((uio) ? (slen - uio->uio_resid) : slen), stcb->asoc.my_rwnd, so->so_rcv.sb_cc); } else { sctp_misc_ints(SCTP_SORECV_DONE, freed_so_far, - (uint32_t) ((uio) ? (slen - uio->uio_resid) : slen), + (uint32_t)((uio) ? (slen - uio->uio_resid) : slen), 0, so->so_rcv.sb_cc); } @@ -6668,8 +6682,10 @@ sctp_local_addr_count(struct sctp_tcb *stcb) sin = &sctp_ifa->address.sin; if (sin->sin_addr.s_addr == 0) { - /* skip unspecified - * addrs */ + /* + * skip unspecified + * addrs + */ continue; } if (prison_check_ip4(stcb->sctp_ep->ip_inp.inp.inp_cred, @@ -7099,7 +7115,7 @@ sctp_recv_icmp6_tunneled_packet(int cmd, struct sockaddr *sa, void *d, void *ctx code = ICMP6_PARAMPROB_NEXTHEADER; } sctp6_notify(inp, stcb, net, type, code, - (uint16_t) ntohl(ip6cp->ip6c_icmp6->icmp6_mtu)); + (uint16_t)ntohl(ip6cp->ip6c_icmp6->icmp6_mtu)); } else { if ((stcb == NULL) && (inp != NULL)) { /* reduce inp's ref-count */ diff --git a/freebsd/sys/netinet/sctputil.h b/freebsd/sys/netinet/sctputil.h index a3a4f3c6..dd45e49a 100644 --- a/freebsd/sys/netinet/sctputil.h +++ b/freebsd/sys/netinet/sctputil.h @@ -65,10 +65,10 @@ void * Function prototypes */ int32_t -sctp_map_assoc_state(int); + sctp_map_assoc_state(int); uint32_t -sctp_get_ifa_hash_val(struct sockaddr *addr); + sctp_get_ifa_hash_val(struct sockaddr *addr); struct sctp_ifa * sctp_find_ifa_in_ep(struct sctp_inpcb *inp, struct sockaddr *addr, int hold_lock); diff --git a/freebsd/sys/netinet/tcp_hostcache.c b/freebsd/sys/netinet/tcp_hostcache.c index e0c4b493..d26688e5 100644 --- a/freebsd/sys/netinet/tcp_hostcache.c +++ b/freebsd/sys/netinet/tcp_hostcache.c @@ -71,10 +71,12 @@ __FBSDID("$FreeBSD$"); #include <rtems/bsd/sys/param.h> #include <sys/systm.h> +#include <sys/jail.h> #include <sys/kernel.h> #include <rtems/bsd/sys/lock.h> #include <sys/mutex.h> #include <sys/malloc.h> +#include <sys/proc.h> #include <sys/sbuf.h> #include <sys/socket.h> #include <sys/socketvar.h> @@ -627,6 +629,9 @@ sysctl_tcp_hc_list(SYSCTL_HANDLER_ARGS) char ip6buf[INET6_ADDRSTRLEN]; #endif + if (jailed_without_vnet(curthread->td_ucred) != 0) + return (EPERM); + sbuf_new(&sb, NULL, linesize * (V_tcp_hostcache.cache_count + 1), SBUF_INCLUDENUL); diff --git a/freebsd/sys/netinet/tcp_input.c b/freebsd/sys/netinet/tcp_input.c index 7e07fc0a..bc77edbc 100644 --- a/freebsd/sys/netinet/tcp_input.c +++ b/freebsd/sys/netinet/tcp_input.c @@ -1410,7 +1410,7 @@ tfo_socket_result: tcp_trace(TA_INPUT, ostate, tp, (void *)tcp_saveipgen, &tcp_savetcp, 0); #endif - TCP_PROBE3(debug__input, tp, th, mtod(m, const char *)); + TCP_PROBE3(debug__input, tp, th, m); tcp_dooptions(&to, optp, optlen, TO_SYN); #ifdef TCP_RFC7413 if (syncache_add(&inc, &to, th, inp, &so, m, NULL, NULL)) @@ -1458,7 +1458,7 @@ tfo_socket_result: } #endif - TCP_PROBE5(receive, NULL, tp, mtod(m, const char *), tp, th); + TCP_PROBE5(receive, NULL, tp, m, tp, th); /* * Segment belongs to a connection in SYN_SENT, ESTABLISHED or later @@ -1470,7 +1470,7 @@ tfo_socket_result: return (IPPROTO_DONE); dropwithreset: - TCP_PROBE5(receive, NULL, tp, mtod(m, const char *), tp, th); + TCP_PROBE5(receive, NULL, tp, m, tp, th); if (ti_locked == TI_RLOCKED) { INP_INFO_RUNLOCK(&V_tcbinfo); @@ -1494,7 +1494,7 @@ dropwithreset: dropunlock: if (m != NULL) - TCP_PROBE5(receive, NULL, tp, mtod(m, const char *), tp, th); + TCP_PROBE5(receive, NULL, tp, m, tp, th); if (ti_locked == TI_RLOCKED) { INP_INFO_RUNLOCK(&V_tcbinfo); @@ -1828,8 +1828,7 @@ tcp_do_segment(struct mbuf *m, struct tcphdr *th, struct socket *so, (void *)tcp_saveipgen, &tcp_savetcp, 0); #endif - TCP_PROBE3(debug__input, tp, th, - mtod(m, const char *)); + TCP_PROBE3(debug__input, tp, th, m); if (tp->snd_una == tp->snd_max) tcp_timer_activate(tp, TT_REXMT, 0); else if (!tcp_timer_active(tp, TT_PERSIST)) @@ -1875,7 +1874,7 @@ tcp_do_segment(struct mbuf *m, struct tcphdr *th, struct socket *so, tcp_trace(TA_INPUT, ostate, tp, (void *)tcp_saveipgen, &tcp_savetcp, 0); #endif - TCP_PROBE3(debug__input, tp, th, mtod(m, const char *)); + TCP_PROBE3(debug__input, tp, th, m); /* * Automatic sizing of receive socket buffer. Often the send @@ -2037,7 +2036,7 @@ tcp_do_segment(struct mbuf *m, struct tcphdr *th, struct socket *so, } if ((thflags & (TH_ACK|TH_RST)) == (TH_ACK|TH_RST)) { TCP_PROBE5(connect__refused, NULL, tp, - mtod(m, const char *), tp, th); + m, tp, th); tp = tcp_drop(tp, ECONNREFUSED); } if (thflags & TH_RST) @@ -2090,7 +2089,7 @@ tcp_do_segment(struct mbuf *m, struct tcphdr *th, struct socket *so, } else { tcp_state_change(tp, TCPS_ESTABLISHED); TCP_PROBE5(connect__established, NULL, tp, - mtod(m, const char *), tp, th); + m, tp, th); cc_conn_init(tp); tcp_timer_activate(tp, TT_KEEP, TP_KEEPIDLE(tp)); @@ -2470,7 +2469,7 @@ tcp_do_segment(struct mbuf *m, struct tcphdr *th, struct socket *so, } else { tcp_state_change(tp, TCPS_ESTABLISHED); TCP_PROBE5(accept__established, NULL, tp, - mtod(m, const char *), tp, th); + m, tp, th); #ifdef TCP_RFC7413 if (tp->t_tfo_pending) { tcp_fastopen_decrement_counter(tp->t_tfo_pending); @@ -3204,7 +3203,7 @@ dodata: /* XXX */ tcp_trace(TA_INPUT, ostate, tp, (void *)tcp_saveipgen, &tcp_savetcp, 0); #endif - TCP_PROBE3(debug__input, tp, th, mtod(m, const char *)); + TCP_PROBE3(debug__input, tp, th, m); /* * Return any desired output. @@ -3252,7 +3251,7 @@ dropafterack: tcp_trace(TA_DROP, ostate, tp, (void *)tcp_saveipgen, &tcp_savetcp, 0); #endif - TCP_PROBE3(debug__input, tp, th, mtod(m, const char *)); + TCP_PROBE3(debug__input, tp, th, m); if (ti_locked == TI_RLOCKED) INP_INFO_RUNLOCK(&V_tcbinfo); ti_locked = TI_UNLOCKED; @@ -3293,7 +3292,7 @@ drop: tcp_trace(TA_DROP, ostate, tp, (void *)tcp_saveipgen, &tcp_savetcp, 0); #endif - TCP_PROBE3(debug__input, tp, th, mtod(m, const char *)); + TCP_PROBE3(debug__input, tp, th, m); if (tp != NULL) INP_WUNLOCK(tp->t_inpcb); m_freem(m); diff --git a/freebsd/sys/netinet/tcp_output.c b/freebsd/sys/netinet/tcp_output.c index a310512e..b39b0bdf 100644 --- a/freebsd/sys/netinet/tcp_output.c +++ b/freebsd/sys/netinet/tcp_output.c @@ -547,6 +547,11 @@ after_sack_rexmit: * (except for the sequence number) for all generated packets. This * makes it impossible to transmit any options which vary per generated * segment or packet. + * + * IPv4 handling has a clear separation of ip options and ip header + * flags while IPv6 combines both in in6p_outputopts. ip6_optlen() does + * the right thing below to provide length of just ip options and thus + * checking for ipoptlen is enough to decide if ip options are present. */ #ifdef IPSEC /* @@ -555,14 +560,25 @@ after_sack_rexmit: */ ipsec_optlen = ipsec_hdrsiz_tcp(tp); #endif + +#ifdef INET6 + if (isipv6) + ipoptlen = ip6_optlen(tp->t_inpcb); + else +#endif + if (tp->t_inpcb->inp_options) + ipoptlen = tp->t_inpcb->inp_options->m_len - + offsetof(struct ipoption, ipopt_list); + else + ipoptlen = 0; +#ifdef IPSEC + ipoptlen += ipsec_optlen; +#endif + if ((tp->t_flags & TF_TSO) && V_tcp_do_tso && len > tp->t_maxseg && ((tp->t_flags & TF_SIGNATURE) == 0) && tp->rcv_numsacks == 0 && sack_rxmit == 0 && -#ifdef IPSEC - ipsec_optlen == 0 && -#endif - tp->t_inpcb->inp_options == NULL && - tp->t_inpcb->in6p_options == NULL) + ipoptlen == 0) tso = 1; if (sack_rxmit) { @@ -835,20 +851,6 @@ send: hdrlen += optlen = tcp_addoptions(&to, opt); } -#ifdef INET6 - if (isipv6) - ipoptlen = ip6_optlen(tp->t_inpcb); - else -#endif - if (tp->t_inpcb->inp_options) - ipoptlen = tp->t_inpcb->inp_options->m_len - - offsetof(struct ipoption, ipopt_list); - else - ipoptlen = 0; -#ifdef IPSEC - ipoptlen += ipsec_optlen; -#endif - /* * Adjust data length if insertion of options will * bump the packet length beyond the t_maxseg length. @@ -1339,7 +1341,7 @@ send: ipov->ih_len = save; } #endif /* TCPDEBUG */ - TCP_PROBE3(debug__output, tp, th, mtod(m, const char *)); + TCP_PROBE3(debug__output, tp, th, m); /* * Fill in IP length and desired time to live and diff --git a/freebsd/sys/netinet/tcp_sack.c b/freebsd/sys/netinet/tcp_sack.c index c7e32cba..170d263e 100644 --- a/freebsd/sys/netinet/tcp_sack.c +++ b/freebsd/sys/netinet/tcp_sack.c @@ -472,9 +472,6 @@ tcp_sack_doack(struct tcpcb *tp, struct tcpopt *to, tcp_seq th_ack) tp->snd_fack = sblkp->end; sack_changed = 1; } - /* We must have at least one SACK hole in scoreboard. */ - KASSERT(!TAILQ_EMPTY(&tp->snd_holes), - ("SACK scoreboard must not be empty")); cur = TAILQ_LAST(&tp->snd_holes, sackhole_head); /* Last SACK hole. */ /* * Since the incoming sack blocks are sorted, we can process them diff --git a/freebsd/sys/netinet/tcp_subr.c b/freebsd/sys/netinet/tcp_subr.c index 4f196a15..ae50bb3e 100644 --- a/freebsd/sys/netinet/tcp_subr.c +++ b/freebsd/sys/netinet/tcp_subr.c @@ -1162,12 +1162,11 @@ tcp_respond(struct tcpcb *tp, void *ipgen, struct tcphdr *th, struct mbuf *m, if (tp == NULL || (inp->inp_socket->so_options & SO_DEBUG)) tcp_trace(TA_OUTPUT, 0, tp, mtod(m, void *), th, 0); #endif - TCP_PROBE3(debug__output, tp, th, mtod(m, const char *)); + TCP_PROBE3(debug__output, tp, th, m); if (flags & TH_RST) - TCP_PROBE5(accept__refused, NULL, NULL, mtod(m, const char *), - tp, nth); + TCP_PROBE5(accept__refused, NULL, NULL, m, tp, nth); - TCP_PROBE5(send, NULL, tp, mtod(m, const char *), tp, nth); + TCP_PROBE5(send, NULL, tp, m, tp, nth); #ifdef INET6 if (isipv6) (void) ip6_output(m, NULL, NULL, 0, NULL, NULL, inp); diff --git a/freebsd/sys/netinet/tcp_syncache.c b/freebsd/sys/netinet/tcp_syncache.c index 453d5ba4..6d05be85 100644 --- a/freebsd/sys/netinet/tcp_syncache.c +++ b/freebsd/sys/netinet/tcp_syncache.c @@ -1180,7 +1180,7 @@ syncache_add(struct in_conninfo *inc, struct tcpopt *to, struct tcphdr *th, struct syncache_head *sch; struct mbuf *ipopts = NULL; u_int ltflags; - int win, sb_hiwat, ip_ttl, ip_tos; + int win, ip_ttl, ip_tos; char *s; int rv = 0; #ifdef INET6 @@ -1218,7 +1218,6 @@ syncache_add(struct in_conninfo *inc, struct tcpopt *to, struct tcphdr *th, ip_ttl = inp->inp_ip_ttl; ip_tos = inp->inp_ip_tos; win = sbspace(&so->so_rcv); - sb_hiwat = so->so_rcv.sb_hiwat; ltflags = (tp->t_flags & (TF_NOOPT | TF_SIGNATURE)); #ifdef TCP_RFC7413 diff --git a/freebsd/sys/netinet6/in6_var.h b/freebsd/sys/netinet6/in6_var.h index 77e5920b..d7c10384 100644 --- a/freebsd/sys/netinet6/in6_var.h +++ b/freebsd/sys/netinet6/in6_var.h @@ -819,6 +819,7 @@ void in6_newaddrmsg(struct in6_ifaddr *, int); /* * Extended API for IPv6 FIB support. */ +struct mbuf *ip6_tryforward(struct mbuf *); void in6_rtredirect(struct sockaddr *, struct sockaddr *, struct sockaddr *, int, struct sockaddr *, u_int); int in6_rtrequest(int, struct sockaddr *, struct sockaddr *, diff --git a/freebsd/sys/netinet6/ip6_fastfwd.c b/freebsd/sys/netinet6/ip6_fastfwd.c new file mode 100644 index 00000000..8ce6a87e --- /dev/null +++ b/freebsd/sys/netinet6/ip6_fastfwd.c @@ -0,0 +1,297 @@ +#include <machine/rtems-bsd-kernel-space.h> + +/*- + * Copyright (c) 2014-2016 Andrey V. Elsukov <ae@FreeBSD.org> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); + +#include <rtems/bsd/local/opt_inet6.h> +#include <rtems/bsd/local/opt_ipstealth.h> + +#include <rtems/bsd/sys/param.h> +#include <sys/systm.h> +#include <sys/mbuf.h> +#include <sys/socket.h> +#include <sys/kernel.h> +#include <sys/sysctl.h> + +#include <net/if.h> +#include <net/if_var.h> +#include <net/route.h> +#include <net/pfil.h> +#include <net/vnet.h> + +#include <netinet/in.h> +#include <netinet/in_kdtrace.h> +#include <netinet/in_var.h> +#include <netinet/ip_var.h> +#include <netinet/ip6.h> +#include <netinet/icmp6.h> +#include <netinet6/in6_var.h> +#include <netinet6/in6_fib.h> +#include <netinet6/ip6_var.h> +#include <netinet6/nd6.h> + +static int +ip6_findroute(struct nhop6_basic *pnh, const struct sockaddr_in6 *dst, + struct mbuf *m) +{ + + if (fib6_lookup_nh_basic(M_GETFIB(m), &dst->sin6_addr, + dst->sin6_scope_id, 0, dst->sin6_flowinfo, pnh) != 0) { + IP6STAT_INC(ip6s_noroute); + IP6STAT_INC(ip6s_cantforward); + icmp6_error(m, ICMP6_DST_UNREACH, + ICMP6_DST_UNREACH_NOROUTE, 0); + return (EHOSTUNREACH); + } + if (pnh->nh_flags & NHF_BLACKHOLE) { + IP6STAT_INC(ip6s_cantforward); + m_freem(m); + return (EHOSTUNREACH); + } + + if (pnh->nh_flags & NHF_REJECT) { + IP6STAT_INC(ip6s_cantforward); + icmp6_error(m, ICMP6_DST_UNREACH, + ICMP6_DST_UNREACH_REJECT, 0); + return (EHOSTUNREACH); + } + return (0); +} + +struct mbuf* +ip6_tryforward(struct mbuf *m) +{ + struct sockaddr_in6 dst; + struct nhop6_basic nh; + struct m_tag *fwd_tag; + struct ip6_hdr *ip6; + struct ifnet *rcvif; + uint32_t plen; + int error; + + /* + * Fallback conditions to ip6_input for slow path processing. + */ + ip6 = mtod(m, struct ip6_hdr *); + if (ip6->ip6_nxt == IPPROTO_HOPOPTS || + IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst) || + IN6_IS_ADDR_LINKLOCAL(&ip6->ip6_dst) || + IN6_IS_ADDR_LINKLOCAL(&ip6->ip6_src) || + IN6_IS_ADDR_UNSPECIFIED(&ip6->ip6_src) || + in6_localip(&ip6->ip6_dst)) + return (m); + /* + * Check that the amount of data in the buffers + * is as at least much as the IPv6 header would have us expect. + * Trim mbufs if longer than we expect. + * Drop packet if shorter than we expect. + */ + rcvif = m->m_pkthdr.rcvif; + plen = ntohs(ip6->ip6_plen); + if (plen == 0) { + /* + * Jumbograms must have hop-by-hop header and go via + * slow path. + */ + IP6STAT_INC(ip6s_badoptions); + goto dropin; + } + if (m->m_pkthdr.len - sizeof(struct ip6_hdr) < plen) { + IP6STAT_INC(ip6s_tooshort); + in6_ifstat_inc(rcvif, ifs6_in_truncated); + goto dropin; + } + if (m->m_pkthdr.len > sizeof(struct ip6_hdr) + plen) { + if (m->m_len == m->m_pkthdr.len) { + m->m_len = sizeof(struct ip6_hdr) + plen; + m->m_pkthdr.len = sizeof(struct ip6_hdr) + plen; + } else + m_adj(m, sizeof(struct ip6_hdr) + plen - + m->m_pkthdr.len); + } + + /* + * Hop limit. + */ +#ifdef IPSTEALTH + if (!V_ip6stealth) +#endif + if (ip6->ip6_hlim <= IPV6_HLIMDEC) { + icmp6_error(m, ICMP6_TIME_EXCEEDED, + ICMP6_TIME_EXCEED_TRANSIT, 0); + m = NULL; + goto dropin; + } + + bzero(&dst, sizeof(dst)); + dst.sin6_family = AF_INET6; + dst.sin6_len = sizeof(dst); + dst.sin6_addr = ip6->ip6_dst; + + /* + * Incoming packet firewall processing. + */ + if (!PFIL_HOOKED(&V_inet6_pfil_hook)) + goto passin; + if (pfil_run_hooks(&V_inet6_pfil_hook, &m, rcvif, PFIL_IN, + NULL) != 0 || m == NULL) + goto dropin; + /* + * If packet filter sets the M_FASTFWD_OURS flag, this means + * that new destination or next hop is our local address. + * So, we can just go back to ip6_input. + * XXX: should we decrement ip6_hlim in such case? + * + * Also it can forward packet to another destination, e.g. + * M_IP6_NEXTHOP flag is set and fwd_tag is attached to mbuf. + */ + if (m->m_flags & M_FASTFWD_OURS) + return (m); + + ip6 = mtod(m, struct ip6_hdr *); + if ((m->m_flags & M_IP6_NEXTHOP) && + (fwd_tag = m_tag_find(m, PACKET_TAG_IPFORWARD, NULL)) != NULL) { + /* + * Now we will find route to forwarded by pfil destination. + */ + bcopy((fwd_tag + 1), &dst, sizeof(dst)); + m->m_flags &= ~M_IP6_NEXTHOP; + m_tag_delete(m, fwd_tag); + } else { + /* Update dst since pfil could change it */ + dst.sin6_addr = ip6->ip6_dst; + } +passin: + /* + * Find route to destination. + */ + if (ip6_findroute(&nh, &dst, m) != 0) { + m = NULL; + in6_ifstat_inc(rcvif, ifs6_in_noroute); + goto dropin; + } + /* + * We used slow path processing for packets with scoped addresses. + * So, scope checks aren't needed here. + */ + if (m->m_pkthdr.len > nh.nh_mtu) { + in6_ifstat_inc(nh.nh_ifp, ifs6_in_toobig); + icmp6_error(m, ICMP6_PACKET_TOO_BIG, 0, nh.nh_mtu); + m = NULL; + goto dropout; + } + + /* + * Outgoing packet firewall processing. + */ + if (!PFIL_HOOKED(&V_inet6_pfil_hook)) + goto passout; + if (pfil_run_hooks(&V_inet6_pfil_hook, &m, nh.nh_ifp, PFIL_OUT, + NULL) != 0 || m == NULL) + goto dropout; + /* + * If packet filter sets the M_FASTFWD_OURS flag, this means + * that new destination or next hop is our local address. + * So, we can just go back to ip6_input. + * + * Also it can forward packet to another destination, e.g. + * M_IP6_NEXTHOP flag is set and fwd_tag is attached to mbuf. + */ + if (m->m_flags & M_FASTFWD_OURS) { + /* + * XXX: we did one hop and should decrement hop limit. But + * now we are the destination and just don't pay attention. + */ + return (m); + } + /* + * Again. A packet filter could change the destination address. + */ + ip6 = mtod(m, struct ip6_hdr *); + if (m->m_flags & M_IP6_NEXTHOP) + fwd_tag = m_tag_find(m, PACKET_TAG_IPFORWARD, NULL); + else + fwd_tag = NULL; + + if (fwd_tag != NULL || + !IN6_ARE_ADDR_EQUAL(&dst.sin6_addr, &ip6->ip6_dst)) { + if (fwd_tag != NULL) { + bcopy((fwd_tag + 1), &dst, sizeof(dst)); + m->m_flags &= ~M_IP6_NEXTHOP; + m_tag_delete(m, fwd_tag); + } else + dst.sin6_addr = ip6->ip6_dst; + /* + * Redo route lookup with new destination address + */ + if (ip6_findroute(&nh, &dst, m) != 0) { + m = NULL; + goto dropout; + } + } +passout: +#ifdef IPSTEALTH + if (!V_ip6stealth) +#endif + { + ip6->ip6_hlim -= IPV6_HLIMDEC; + } + + m_clrprotoflags(m); /* Avoid confusing lower layers. */ + IP_PROBE(send, NULL, NULL, ip6, nh.nh_ifp, NULL, ip6); + + /* + * XXX: we need to use destination address with embedded scope + * zone id, because LLTABLE uses such form of addresses for lookup. + */ + dst.sin6_addr = nh.nh_addr; + if (IN6_IS_SCOPE_LINKLOCAL(&dst.sin6_addr)) + dst.sin6_addr.s6_addr16[1] = htons(nh.nh_ifp->if_index & 0xffff); + + error = (*nh.nh_ifp->if_output)(nh.nh_ifp, m, + (struct sockaddr *)&dst, NULL); + if (error != 0) { + in6_ifstat_inc(nh.nh_ifp, ifs6_out_discard); + IP6STAT_INC(ip6s_cantforward); + } else { + in6_ifstat_inc(nh.nh_ifp, ifs6_out_forward); + IP6STAT_INC(ip6s_forward); + } + return (NULL); +dropin: + in6_ifstat_inc(rcvif, ifs6_in_discard); + goto drop; +dropout: + in6_ifstat_inc(nh.nh_ifp, ifs6_out_discard); +drop: + if (m != NULL) + m_freem(m); + return (NULL); +} + diff --git a/freebsd/sys/netinet6/ip6_input.c b/freebsd/sys/netinet6/ip6_input.c index 6af5acd7..e34ac0e6 100644 --- a/freebsd/sys/netinet6/ip6_input.c +++ b/freebsd/sys/netinet6/ip6_input.c @@ -121,6 +121,7 @@ __FBSDID("$FreeBSD$"); #include <netinet6/in6_rss.h> #ifdef IPSEC +#include <netipsec/key.h> #include <netipsec/ipsec.h> #include <netinet6/ip6_ipsec.h> #include <netipsec/ipsec6.h> @@ -550,12 +551,20 @@ ip6_input(struct mbuf *m) struct in6_addr odst; struct ip6_hdr *ip6; struct in6_ifaddr *ia; + struct ifnet *rcvif; u_int32_t plen; u_int32_t rtalert = ~0; int off = sizeof(struct ip6_hdr), nest; int nxt, ours = 0; int srcrt = 0; + /* + * Drop the packet if IPv6 operation is disabled on the interface. + */ + rcvif = m->m_pkthdr.rcvif; + if ((ND_IFINFO(rcvif)->flags & ND6_IFF_IFDISABLED)) + goto bad; + #ifdef IPSEC /* * should the inner packet be considered authentic? @@ -590,20 +599,15 @@ ip6_input(struct mbuf *m) if (m->m_next) { if (m->m_flags & M_LOOP) { IP6STAT_INC(ip6s_m2m[V_loif->if_index]); - } else if (m->m_pkthdr.rcvif->if_index < IP6S_M2MMAX) - IP6STAT_INC( - ip6s_m2m[m->m_pkthdr.rcvif->if_index]); + } else if (rcvif->if_index < IP6S_M2MMAX) + IP6STAT_INC(ip6s_m2m[rcvif->if_index]); else IP6STAT_INC(ip6s_m2m[0]); } else IP6STAT_INC(ip6s_m1); } - /* drop the packet if IPv6 operation is disabled on the IF */ - if ((ND_IFINFO(m->m_pkthdr.rcvif)->flags & ND6_IFF_IFDISABLED)) - goto bad; - - in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_receive); + in6_ifstat_inc(rcvif, ifs6_in_receive); IP6STAT_INC(ip6s_total); #ifndef PULLDOWN_TEST @@ -619,10 +623,8 @@ ip6_input(struct mbuf *m) n = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR); else n = m_gethdr(M_NOWAIT, MT_DATA); - if (n == NULL) { - m_freem(m); - return; /* ENOBUFS */ - } + if (n == NULL) + goto bad; m_move_pkthdr(n, m); m_copydata(m, 0, n->m_pkthdr.len, mtod(n, caddr_t)); @@ -634,26 +636,22 @@ ip6_input(struct mbuf *m) #endif if (m->m_len < sizeof(struct ip6_hdr)) { - struct ifnet *inifp; - inifp = m->m_pkthdr.rcvif; if ((m = m_pullup(m, sizeof(struct ip6_hdr))) == NULL) { IP6STAT_INC(ip6s_toosmall); - in6_ifstat_inc(inifp, ifs6_in_hdrerr); - return; + in6_ifstat_inc(rcvif, ifs6_in_hdrerr); + goto bad; } } ip6 = mtod(m, struct ip6_hdr *); - if ((ip6->ip6_vfc & IPV6_VERSION_MASK) != IPV6_VERSION) { IP6STAT_INC(ip6s_badvers); - in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_hdrerr); + in6_ifstat_inc(rcvif, ifs6_in_hdrerr); goto bad; } IP6STAT_INC(ip6s_nxthist[ip6->ip6_nxt]); - - IP_PROBE(receive, NULL, NULL, ip6, m->m_pkthdr.rcvif, NULL, ip6); + IP_PROBE(receive, NULL, NULL, ip6, rcvif, NULL, ip6); /* * Check against address spoofing/corruption. @@ -664,7 +662,7 @@ ip6_input(struct mbuf *m) * XXX: "badscope" is not very suitable for a multicast source. */ IP6STAT_INC(ip6s_badscope); - in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_addrerr); + in6_ifstat_inc(rcvif, ifs6_in_addrerr); goto bad; } if (IN6_IS_ADDR_MC_INTFACELOCAL(&ip6->ip6_dst) && @@ -676,7 +674,7 @@ ip6_input(struct mbuf *m) * as the outgoing/incoming interface. */ IP6STAT_INC(ip6s_badscope); - in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_addrerr); + in6_ifstat_inc(rcvif, ifs6_in_addrerr); goto bad; } if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst) && @@ -688,7 +686,7 @@ ip6_input(struct mbuf *m) * a packet is received, it must be silently dropped. */ IP6STAT_INC(ip6s_badscope); - in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_addrerr); + in6_ifstat_inc(rcvif, ifs6_in_addrerr); goto bad; } #ifdef ALTQ @@ -712,7 +710,7 @@ ip6_input(struct mbuf *m) if (IN6_IS_ADDR_V4MAPPED(&ip6->ip6_src) || IN6_IS_ADDR_V4MAPPED(&ip6->ip6_dst)) { IP6STAT_INC(ip6s_badscope); - in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_addrerr); + in6_ifstat_inc(rcvif, ifs6_in_addrerr); goto bad; } #if 0 @@ -730,14 +728,36 @@ ip6_input(struct mbuf *m) goto bad; } #endif + /* + * Try to forward the packet, but if we fail continue. + * ip6_tryforward() does inbound and outbound packet firewall + * processing. If firewall has decided that destination becomes + * our local address, it sets M_FASTFWD_OURS flag. In this + * case skip another inbound firewall processing and update + * ip6 pointer. + */ + if (V_ip6_forwarding != 0 +#ifdef IPSEC + && !key_havesp(IPSEC_DIR_INBOUND) + && !key_havesp(IPSEC_DIR_OUTBOUND) +#endif + ) { + if ((m = ip6_tryforward(m)) == NULL) + return; + if (m->m_flags & M_FASTFWD_OURS) { + m->m_flags &= ~M_FASTFWD_OURS; + ours = 1; + ip6 = mtod(m, struct ip6_hdr *); + goto hbhcheck; + } + } #ifdef IPSEC /* * Bypass packet filtering for packets previously handled by IPsec. */ if (ip6_ipsec_filtertunnel(m)) goto passin; -#endif /* IPSEC */ - +#endif /* * Run through list of hooks for input packets. * @@ -745,12 +765,12 @@ ip6_input(struct mbuf *m) * (e.g. by NAT rewriting). When this happens, * tell ip6_forward to do the right thing. */ - odst = ip6->ip6_dst; /* Jump over all PFIL processing if hooks are not active. */ if (!PFIL_HOOKED(&V_inet6_pfil_hook)) goto passin; + odst = ip6->ip6_dst; if (pfil_run_hooks(&V_inet6_pfil_hook, &m, m->m_pkthdr.rcvif, PFIL_IN, NULL)) return; @@ -790,8 +810,8 @@ passin: IP6STAT_INC(ip6s_badscope); /* XXX */ goto bad; } - if (in6_setscope(&ip6->ip6_src, m->m_pkthdr.rcvif, NULL) || - in6_setscope(&ip6->ip6_dst, m->m_pkthdr.rcvif, NULL)) { + if (in6_setscope(&ip6->ip6_src, rcvif, NULL) || + in6_setscope(&ip6->ip6_dst, rcvif, NULL)) { IP6STAT_INC(ip6s_badscope); goto bad; } @@ -801,7 +821,7 @@ passin: */ if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)) { ours = 1; - in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_mcast); + in6_ifstat_inc(rcvif, ifs6_in_mcast); goto hbhcheck; } /* @@ -836,7 +856,6 @@ passin: */ if (!V_ip6_forwarding) { IP6STAT_INC(ip6s_cantforward); - in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_discard); goto bad; } @@ -868,7 +887,7 @@ passin: */ if (m->m_pkthdr.len - sizeof(struct ip6_hdr) < plen) { IP6STAT_INC(ip6s_tooshort); - in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_truncated); + in6_ifstat_inc(rcvif, ifs6_in_truncated); goto bad; } if (m->m_pkthdr.len > sizeof(struct ip6_hdr) + plen) { @@ -895,10 +914,8 @@ passin: * XXX TODO: Check hlim and multicast scope here to avoid * unnecessarily calling into ip6_mforward(). */ - if (ip6_mforward && - ip6_mforward(ip6, m->m_pkthdr.rcvif, m)) { + if (ip6_mforward && ip6_mforward(ip6, rcvif, m)) { IP6STAT_INC(ip6s_cantforward); - in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_discard); goto bad; } } else if (!ours) { @@ -920,7 +937,7 @@ passin: if (IN6_IS_ADDR_V4MAPPED(&ip6->ip6_src) || IN6_IS_ADDR_V4MAPPED(&ip6->ip6_dst)) { IP6STAT_INC(ip6s_badscope); - in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_addrerr); + in6_ifstat_inc(rcvif, ifs6_in_addrerr); goto bad; } @@ -928,7 +945,7 @@ passin: * Tell launch routine the next header */ IP6STAT_INC(ip6s_delivered); - in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_deliver); + in6_ifstat_inc(rcvif, ifs6_in_deliver); nest = 0; while (nxt != IPPROTO_DONE) { @@ -943,7 +960,7 @@ passin: */ if (m->m_pkthdr.len < off) { IP6STAT_INC(ip6s_tooshort); - in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_truncated); + in6_ifstat_inc(rcvif, ifs6_in_truncated); goto bad; } @@ -961,7 +978,9 @@ passin: } return; bad: - m_freem(m); + in6_ifstat_inc(rcvif, ifs6_in_discard); + if (m != NULL) + m_freem(m); } /* diff --git a/freebsd/sys/netinet6/nd6.c b/freebsd/sys/netinet6/nd6.c index 3e019a62..757130b8 100644 --- a/freebsd/sys/netinet6/nd6.c +++ b/freebsd/sys/netinet6/nd6.c @@ -912,7 +912,7 @@ nd6_timer(void *arg) struct nd_defrouter *dr, *ndr; struct nd_prefix *pr, *npr; struct in6_ifaddr *ia6, *nia6; - bool onlink_locked; + uint64_t genid; TAILQ_INIT(&drq); LIST_INIT(&prl); @@ -1024,7 +1024,6 @@ nd6_timer(void *arg) } ND6_WLOCK(); - onlink_locked = false; restart: LIST_FOREACH_SAFE(pr, &V_nd_prefix, ndpr_entry, npr) { /* @@ -1047,22 +1046,19 @@ restart: continue; } if ((pr->ndpr_stateflags & NDPRF_ONLINK) != 0) { - if (!onlink_locked) { - onlink_locked = ND6_ONLINK_TRYLOCK(); - if (!onlink_locked) { - ND6_WUNLOCK(); - ND6_ONLINK_LOCK(); - onlink_locked = true; - ND6_WLOCK(); - goto restart; - } - } + genid = V_nd6_list_genid; + nd6_prefix_ref(pr); + ND6_WUNLOCK(); + ND6_ONLINK_LOCK(); (void)nd6_prefix_offlink(pr); + ND6_ONLINK_UNLOCK(); + ND6_WLOCK(); + nd6_prefix_rele(pr); + if (genid != V_nd6_list_genid) + goto restart; } } ND6_WUNLOCK(); - if (onlink_locked) - ND6_ONLINK_UNLOCK(); while ((pr = LIST_FIRST(&prl)) != NULL) { LIST_REMOVE(pr, ndpr_entry); diff --git a/freebsd/sys/netinet6/nd6_rtr.c b/freebsd/sys/netinet6/nd6_rtr.c index 33d8fa2a..f1ef143e 100644 --- a/freebsd/sys/netinet6/nd6_rtr.c +++ b/freebsd/sys/netinet6/nd6_rtr.c @@ -1124,8 +1124,6 @@ void nd6_prefix_unlink(struct nd_prefix *pr, struct nd_prhead *list) { - KASSERT(pr->ndpr_addrcnt == 0, - ("prefix %p has referencing addresses", pr)); ND6_WLOCK_ASSERT(); LIST_REMOVE(pr, ndpr_entry); diff --git a/freebsd/sys/netinet6/sctp6_usrreq.c b/freebsd/sys/netinet6/sctp6_usrreq.c index 735de62a..751c18fd 100644 --- a/freebsd/sys/netinet6/sctp6_usrreq.c +++ b/freebsd/sys/netinet6/sctp6_usrreq.c @@ -308,7 +308,7 @@ sctp6_ctlinput(int cmd, struct sockaddr *pktdst, void *d) * verification tag of the SCTP common header. */ if (ip6cp->ip6c_m->m_pkthdr.len < - (int32_t) (ip6cp->ip6c_off + offsetof(struct sctphdr, checksum))) { + (int32_t)(ip6cp->ip6c_off + offsetof(struct sctphdr, checksum))) { return; } /* Copy out the port numbers and the verification tag. */ @@ -390,7 +390,7 @@ sctp6_ctlinput(int cmd, struct sockaddr *pktdst, void *d) sctp6_notify(inp, stcb, net, ip6cp->ip6c_icmp6->icmp6_type, ip6cp->ip6c_icmp6->icmp6_code, - (uint16_t) ntohl(ip6cp->ip6c_icmp6->icmp6_mtu)); + (uint16_t)ntohl(ip6cp->ip6c_icmp6->icmp6_mtu)); } else { if ((stcb == NULL) && (inp != NULL)) { /* reduce inp's ref-count */ @@ -1003,7 +1003,7 @@ sctp6_getaddr(struct socket *so, struct sockaddr **addr) return (ENOENT); } vrf_id = inp->def_vrf_id; - sctp_ifa = sctp_source_address_selection(inp, stcb, (sctp_route_t *) & net->ro, net, 0, vrf_id); + sctp_ifa = sctp_source_address_selection(inp, stcb, (sctp_route_t *)&net->ro, net, 0, vrf_id); if (sctp_ifa) { sin6->sin6_addr = sctp_ifa->address.sin6.sin6_addr; } diff --git a/freebsd/sys/netpfil/pf/if_pfsync.c b/freebsd/sys/netpfil/pf/if_pfsync.c index d82a6b74..5543bb54 100644 --- a/freebsd/sys/netpfil/pf/if_pfsync.c +++ b/freebsd/sys/netpfil/pf/if_pfsync.c @@ -163,8 +163,8 @@ static struct pfsync_q pfsync_qs[] = { { pfsync_out_del, sizeof(struct pfsync_del_c), PFSYNC_ACT_DEL_C } }; -static void pfsync_q_ins(struct pf_state *, int); -static void pfsync_q_del(struct pf_state *); +static void pfsync_q_ins(struct pf_state *, int, bool); +static void pfsync_q_del(struct pf_state *, bool); static void pfsync_update_state(struct pf_state *); @@ -544,7 +544,7 @@ pfsync_state_import(struct pfsync_state *sp, u_int8_t flags) if (!(flags & PFSYNC_SI_IOCTL)) { st->state_flags &= ~PFSTATE_NOSYNC; if (st->state_flags & PFSTATE_ACK) { - pfsync_q_ins(st, PFSYNC_S_IACK); + pfsync_q_ins(st, PFSYNC_S_IACK, true); pfsync_push(sc); } } @@ -1670,7 +1670,7 @@ pfsync_insert_state(struct pf_state *st) if (sc->sc_len == PFSYNC_MINPKT) callout_reset(&sc->sc_tmo, 1 * hz, pfsync_timeout, V_pfsyncif); - pfsync_q_ins(st, PFSYNC_S_INS); + pfsync_q_ins(st, PFSYNC_S_INS, true); PFSYNC_UNLOCK(sc); st->sync_updates = 0; @@ -1791,7 +1791,7 @@ static void pfsync_update_state(struct pf_state *st) { struct pfsync_softc *sc = V_pfsyncif; - int sync = 0; + bool sync = false, ref = true; PF_STATE_LOCK_ASSERT(st); PFSYNC_LOCK(sc); @@ -1800,7 +1800,7 @@ pfsync_update_state(struct pf_state *st) pfsync_undefer_state(st, 0); if (st->state_flags & PFSTATE_NOSYNC) { if (st->sync_state != PFSYNC_S_NONE) - pfsync_q_del(st); + pfsync_q_del(st, true); PFSYNC_UNLOCK(sc); return; } @@ -1817,14 +1817,17 @@ pfsync_update_state(struct pf_state *st) if (st->key[PF_SK_WIRE]->proto == IPPROTO_TCP) { st->sync_updates++; if (st->sync_updates >= sc->sc_maxupdates) - sync = 1; + sync = true; } break; case PFSYNC_S_IACK: - pfsync_q_del(st); + pfsync_q_del(st, false); + ref = false; + /* FALLTHROUGH */ + case PFSYNC_S_NONE: - pfsync_q_ins(st, PFSYNC_S_UPD_C); + pfsync_q_ins(st, PFSYNC_S_UPD_C, ref); st->sync_updates = 0; break; @@ -1882,13 +1885,14 @@ static void pfsync_update_state_req(struct pf_state *st) { struct pfsync_softc *sc = V_pfsyncif; + bool ref = true; PF_STATE_LOCK_ASSERT(st); PFSYNC_LOCK(sc); if (st->state_flags & PFSTATE_NOSYNC) { if (st->sync_state != PFSYNC_S_NONE) - pfsync_q_del(st); + pfsync_q_del(st, true); PFSYNC_UNLOCK(sc); return; } @@ -1896,9 +1900,12 @@ pfsync_update_state_req(struct pf_state *st) switch (st->sync_state) { case PFSYNC_S_UPD_C: case PFSYNC_S_IACK: - pfsync_q_del(st); + pfsync_q_del(st, false); + ref = false; + /* FALLTHROUGH */ + case PFSYNC_S_NONE: - pfsync_q_ins(st, PFSYNC_S_UPD); + pfsync_q_ins(st, PFSYNC_S_UPD, ref); pfsync_push(sc); break; @@ -1919,13 +1926,14 @@ static void pfsync_delete_state(struct pf_state *st) { struct pfsync_softc *sc = V_pfsyncif; + bool ref = true; PFSYNC_LOCK(sc); if (st->state_flags & PFSTATE_ACK) pfsync_undefer_state(st, 1); if (st->state_flags & PFSTATE_NOSYNC) { if (st->sync_state != PFSYNC_S_NONE) - pfsync_q_del(st); + pfsync_q_del(st, true); PFSYNC_UNLOCK(sc); return; } @@ -1933,30 +1941,27 @@ pfsync_delete_state(struct pf_state *st) if (sc->sc_len == PFSYNC_MINPKT) callout_reset(&sc->sc_tmo, 1 * hz, pfsync_timeout, V_pfsyncif); - pf_ref_state(st); - switch (st->sync_state) { case PFSYNC_S_INS: /* We never got to tell the world so just forget about it. */ - pfsync_q_del(st); + pfsync_q_del(st, true); break; case PFSYNC_S_UPD_C: case PFSYNC_S_UPD: case PFSYNC_S_IACK: - pfsync_q_del(st); - /* FALLTHROUGH to putting it on the del list */ + pfsync_q_del(st, false); + ref = false; + /* FALLTHROUGH */ case PFSYNC_S_NONE: - pfsync_q_ins(st, PFSYNC_S_DEL); + pfsync_q_ins(st, PFSYNC_S_DEL, ref); break; default: panic("%s: unexpected sync state %d", __func__, st->sync_state); } - pf_release_state(st); - PFSYNC_UNLOCK(sc); } @@ -1984,7 +1989,7 @@ pfsync_clear_states(u_int32_t creatorid, const char *ifname) } static void -pfsync_q_ins(struct pf_state *st, int q) +pfsync_q_ins(struct pf_state *st, int q, bool ref) { struct pfsync_softc *sc = V_pfsyncif; size_t nlen = pfsync_qs[q].len; @@ -2008,11 +2013,12 @@ pfsync_q_ins(struct pf_state *st, int q) sc->sc_len += nlen; TAILQ_INSERT_TAIL(&sc->sc_qs[q], st, sync_list); st->sync_state = q; - pf_ref_state(st); + if (ref) + pf_ref_state(st); } static void -pfsync_q_del(struct pf_state *st) +pfsync_q_del(struct pf_state *st, bool unref) { struct pfsync_softc *sc = V_pfsyncif; int q = st->sync_state; @@ -2024,7 +2030,8 @@ pfsync_q_del(struct pf_state *st) sc->sc_len -= pfsync_qs[q].len; TAILQ_REMOVE(&sc->sc_qs[q], st, sync_list); st->sync_state = PFSYNC_S_NONE; - pf_release_state(st); + if (unref) + pf_release_state(st); if (TAILQ_EMPTY(&sc->sc_qs[q])) sc->sc_len -= sizeof(struct pfsync_subheader); diff --git a/freebsd/sys/sys/conf.h b/freebsd/sys/sys/conf.h index 78bb1e2a..084cab22 100644 --- a/freebsd/sys/sys/conf.h +++ b/freebsd/sys/sys/conf.h @@ -311,7 +311,6 @@ int make_dev_physpath_alias(int _flags, struct cdev **_cdev, const char *_physpath); void dev_lock(void); void dev_unlock(void); -void setconf(void); #ifdef KLD_MODULE #define MAKEDEV_ETERNAL_KLD 0 @@ -351,6 +350,8 @@ int dev_stdclone(char *_name, char **_namep, const char *_stem, int *_unit); EVENTHANDLER_DECLARE(dev_clone, dev_clone_fn); /* Stuff relating to kernel-dump */ +struct kerneldumpcrypto; +struct kerneldumpheader; struct dumperinfo { dumper_t *dumper; /* Dumping function. */ @@ -360,12 +361,18 @@ struct dumperinfo { off_t mediaoffset; /* Initial offset in bytes. */ off_t mediasize; /* Space available in bytes. */ void *blockbuf; /* Buffer for padding shorter dump blocks */ + struct kerneldumpcrypto *kdc; /* Kernel dump crypto. */ }; -int set_dumper(struct dumperinfo *, const char *_devname, struct thread *td); +int set_dumper(struct dumperinfo *di, const char *devname, struct thread *td, + uint8_t encrypt, const uint8_t *key, uint32_t encryptedkeysize, + const uint8_t *encryptedkey); int dump_write(struct dumperinfo *, void *, vm_offset_t, off_t, size_t); int dump_write_pad(struct dumperinfo *, void *, vm_offset_t, off_t, size_t, size_t *); +int dump_write_header(struct dumperinfo *di, struct kerneldumpheader *kdh, + vm_offset_t physical, off_t offset); +int dump_write_key(struct dumperinfo *di, vm_offset_t physical, off_t offset); int doadump(boolean_t); #ifndef __rtems__ extern int dumping; /* system is dumping */ diff --git a/freebsd/sys/sys/counter.h b/freebsd/sys/sys/counter.h index 2ce71341..5046d41d 100644 --- a/freebsd/sys/sys/counter.h +++ b/freebsd/sys/sys/counter.h @@ -59,5 +59,18 @@ uint64_t counter_u64_fetch(counter_u64_t); for (int i = 0; i < (n); i++) \ counter_u64_zero((a)[i]); \ } while (0) + +/* + * counter(9) based rate checking. + */ +struct counter_rate { + counter_u64_t cr_rate; /* Events since last second */ + volatile int cr_lock; /* Lock to clean the struct */ + int cr_ticks; /* Ticks on last clean */ + int cr_over; /* Over limit since cr_ticks? */ +}; + +int64_t counter_ratecheck(struct counter_rate *, int64_t); + #endif /* _KERNEL */ #endif /* ! __SYS_COUNTER_H__ */ diff --git a/freebsd/sys/sys/eventhandler.h b/freebsd/sys/sys/eventhandler.h index 845b28c1..d03cd054 100644 --- a/freebsd/sys/sys/eventhandler.h +++ b/freebsd/sys/sys/eventhandler.h @@ -277,4 +277,11 @@ typedef void (*ada_probe_veto_fn)(void *, struct cam_path *, struct ata_params *, int *); EVENTHANDLER_DECLARE(ada_probe_veto, ada_probe_veto_fn); +/* Swap device events */ +struct swdevt; +typedef void (*swapon_fn)(void *, struct swdevt *); +typedef void (*swapoff_fn)(void *, struct swdevt *); +EVENTHANDLER_DECLARE(swapon, swapon_fn); +EVENTHANDLER_DECLARE(swapoff, swapoff_fn); + #endif /* _SYS_EVENTHANDLER_H_ */ diff --git a/freebsd/sys/sys/mount.h b/freebsd/sys/sys/mount.h index 1bf583a6..acc9b81b 100644 --- a/freebsd/sys/sys/mount.h +++ b/freebsd/sys/sys/mount.h @@ -597,6 +597,7 @@ struct uio; #ifdef MALLOC_DECLARE MALLOC_DECLARE(M_MOUNT); +MALLOC_DECLARE(M_STATFS); #endif extern int maxvfsconf; /* highest defined filesystem type */ diff --git a/freebsd/sys/sys/mutex.h b/freebsd/sys/sys/mutex.h index 84feea7c..3cec5dbd 100644 --- a/freebsd/sys/sys/mutex.h +++ b/freebsd/sys/sys/mutex.h @@ -448,10 +448,16 @@ extern struct mtx_pool *mtxpool_sleep; _sleep((chan), &(mtx)->lock_object, (pri), (wmesg), \ tick_sbt * (timo), 0, C_HARDCLOCK) +#define MTX_READ_VALUE(m) ((m)->mtx_lock) + #define mtx_initialized(m) lock_initialized(&(m)->lock_object) #ifndef __rtems__ -#define mtx_owned(m) (((m)->mtx_lock & ~MTX_FLAGMASK) == (uintptr_t)curthread) +#define lv_mtx_owner(v) ((struct thread *)((v) & ~MTX_FLAGMASK)) + +#define mtx_owner(m) lv_mtx_owner(MTX_READ_VALUE(m)) + +#define mtx_owned(m) (mtx_owner(m) == curthread) #define mtx_recursed(m) ((m)->mtx_recurse != 0) #else /* __rtems__ */ diff --git a/freebsd/sys/sys/seq.h b/freebsd/sys/sys/seq.h index 228be2f2..94be8a4c 100644 --- a/freebsd/sys/sys/seq.h +++ b/freebsd/sys/sys/seq.h @@ -59,7 +59,6 @@ typedef uint32_t seq_t; * lobj = gobj; * if (seq_consistent(&gobj->seq, seq)) * break; - * cpu_spinwait(); * } * foo(lobj); */ diff --git a/freebsd/sys/sys/socket.h b/freebsd/sys/sys/socket.h index ea3d9b6b..9429f5a1 100644 --- a/freebsd/sys/sys/socket.h +++ b/freebsd/sys/sys/socket.h @@ -435,6 +435,7 @@ struct msghdr { #endif #ifdef _KERNEL #define MSG_SOCALLBCK 0x10000 /* for use by socket callbacks - soreceive (TCP) */ +#define MSG_MORETOCOME 0x20000 /* additional data pending */ #endif /* diff --git a/freebsd/sys/sys/sysctl.h b/freebsd/sys/sys/sysctl.h index 291b7e44..988cec2e 100644 --- a/freebsd/sys/sys/sysctl.h +++ b/freebsd/sys/sys/sysctl.h @@ -192,6 +192,7 @@ struct sysctl_oid { int oid_refcnt; u_int oid_running; const char *oid_descr; + const char *oid_label; }; #define SYSCTL_IN(r, p, l) (r->newfunc)(r, p, l) @@ -270,7 +271,7 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry); #endif /* This macro is only for internal use */ -#define SYSCTL_OID_RAW(id, parent_child_head, nbr, name, kind, a1, a2, handler, fmt, descr) \ +#define SYSCTL_OID_RAW(id, parent_child_head, nbr, name, kind, a1, a2, handler, fmt, descr, label) \ struct sysctl_oid id = { \ .oid_parent = (parent_child_head), \ .oid_children = SLIST_HEAD_INITIALIZER(&id.oid_children), \ @@ -281,69 +282,81 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry); .oid_name = (name), \ .oid_handler = (handler), \ .oid_fmt = (fmt), \ - .oid_descr = __DESCR(descr) \ + .oid_descr = __DESCR(descr), \ + .oid_label = (label), \ }; \ DATA_SET(sysctl_set, id) /* This constructs a static "raw" MIB oid. */ -#ifndef __rtems__ #define SYSCTL_OID(parent, nbr, name, kind, a1, a2, handler, fmt, descr) \ - static SYSCTL_OID_RAW(sysctl__##parent##_##name, \ - SYSCTL_CHILDREN(&sysctl__##parent), \ - nbr, #name, kind, a1, a2, handler, fmt, descr) + SYSCTL_OID_WITH_LABEL(parent, nbr, name, kind, a1, a2, \ + handler, fmt, descr, NULL) + +#ifndef __rtems__ +#define SYSCTL_OID_WITH_LABEL(parent, nbr, name, kind, a1, a2, handler, fmt, descr, label) \ + static SYSCTL_OID_RAW(sysctl__##parent##_##name, \ + SYSCTL_CHILDREN(&sysctl__##parent), \ + nbr, #name, kind, a1, a2, handler, fmt, descr, label) #else /* __rtems__ */ -#define SYSCTL_OID(parent, nbr, name, kind, a1, a2, handler, fmt, descr) \ - static SYSCTL_OID_RAW(_bsd_sysctl__##parent##_##name, \ - SYSCTL_CHILDREN(&_bsd_sysctl__##parent), \ - nbr, #name, kind, a1, a2, handler, fmt, descr) +#define SYSCTL_OID_WITH_LABEL(parent, nbr, name, kind, a1, a2, handler, fmt, descr, label) \ + static SYSCTL_OID_RAW(_bsd_sysctl__##parent##_##name, \ + SYSCTL_CHILDREN(&_bsd_sysctl__##parent), \ + nbr, #name, kind, a1, a2, handler, fmt, descr, label) #endif /* __rtems__ */ /* This constructs a global "raw" MIB oid. */ #ifndef __rtems__ -#define SYSCTL_OID_GLOBAL(parent, nbr, name, kind, a1, a2, handler, fmt, descr) \ +#define SYSCTL_OID_GLOBAL(parent, nbr, name, kind, a1, a2, handler, fmt, descr, label) \ SYSCTL_OID_RAW(sysctl__##parent##_##name, \ SYSCTL_CHILDREN(&sysctl__##parent), \ - nbr, #name, kind, a1, a2, handler, fmt, descr) + nbr, #name, kind, a1, a2, handler, fmt, descr, label) #else /* __rtems__ */ -#define SYSCTL_OID_GLOBAL(parent, nbr, name, kind, a1, a2, handler, fmt, descr) \ +#define SYSCTL_OID_GLOBAL(parent, nbr, name, kind, a1, a2, handler, fmt, descr, label) \ SYSCTL_OID_RAW(_bsd_sysctl__##parent##_##name, \ SYSCTL_CHILDREN(&_bsd_sysctl__##parent), \ - nbr, #name, kind, a1, a2, handler, fmt, descr) + nbr, #name, kind, a1, a2, handler, fmt, descr, label) #endif /* __rtems__ */ #define SYSCTL_ADD_OID(ctx, parent, nbr, name, kind, a1, a2, handler, fmt, descr) \ - sysctl_add_oid(ctx, parent, nbr, name, kind, a1, a2, handler, fmt, __DESCR(descr)) + sysctl_add_oid(ctx, parent, nbr, name, kind, a1, a2, handler, fmt, __DESCR(descr), NULL) /* This constructs a root node from which other nodes can hang. */ #ifndef __rtems__ #define SYSCTL_ROOT_NODE(nbr, name, access, handler, descr) \ SYSCTL_OID_RAW(sysctl___##name, &sysctl__children, \ nbr, #name, CTLTYPE_NODE|(access), NULL, 0, \ - handler, "N", descr); \ + handler, "N", descr, NULL); \ CTASSERT(((access) & CTLTYPE) == 0 || \ ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_NODE) #else /* __rtems__ */ #define SYSCTL_ROOT_NODE(nbr, name, access, handler, descr) \ SYSCTL_OID_RAW(_bsd_sysctl___##name, &sysctl__children, \ nbr, #name, CTLTYPE_NODE|(access), NULL, 0, \ - handler, "N", descr); \ + handler, "N", descr, NULL); \ CTASSERT(((access) & CTLTYPE) == 0 || \ ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_NODE) #endif /* __rtems__ */ /* This constructs a node from which other oids can hang. */ -#define SYSCTL_NODE(parent, nbr, name, access, handler, descr) \ +#define SYSCTL_NODE(parent, nbr, name, access, handler, descr) \ + SYSCTL_NODE_WITH_LABEL(parent, nbr, name, access, handler, descr, NULL) + +#define SYSCTL_NODE_WITH_LABEL(parent, nbr, name, access, handler, descr, label) \ SYSCTL_OID_GLOBAL(parent, nbr, name, CTLTYPE_NODE|(access), \ - NULL, 0, handler, "N", descr); \ + NULL, 0, handler, "N", descr, label); \ CTASSERT(((access) & CTLTYPE) == 0 || \ ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_NODE) #define SYSCTL_ADD_NODE(ctx, parent, nbr, name, access, handler, descr) \ + SYSCTL_ADD_NODE_WITH_LABEL(ctx, parent, nbr, name, access, \ + handler, descr, NULL) + +#define SYSCTL_ADD_NODE_WITH_LABEL(ctx, parent, nbr, name, access, handler, descr, label) \ ({ \ CTASSERT(((access) & CTLTYPE) == 0 || \ ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_NODE); \ sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_NODE|(access), \ - NULL, 0, handler, "N", __DESCR(descr)); \ + NULL, 0, handler, "N", __DESCR(descr), label); \ }) #define SYSCTL_ADD_ROOT_NODE(ctx, nbr, name, access, handler, descr) \ @@ -352,7 +365,7 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry); ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_NODE); \ sysctl_add_oid(ctx, &sysctl__children, nbr, name, \ CTLTYPE_NODE|(access), \ - NULL, 0, handler, "N", __DESCR(descr)); \ + NULL, 0, handler, "N", __DESCR(descr), NULL); \ }) /* Oid for a string. len can be 0 to indicate '\0' termination. */ @@ -368,7 +381,8 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry); CTASSERT(((access) & CTLTYPE) == 0 || \ ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_STRING); \ sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_STRING|(access), \ - __arg, len, sysctl_handle_string, "A", __DESCR(descr)); \ + __arg, len, sysctl_handle_string, "A", __DESCR(descr), \ + NULL); \ }) /* Oid for a bool. If ptr is NULL, val is returned. */ @@ -386,7 +400,8 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry); CTASSERT(((access) & CTLTYPE) == 0); \ sysctl_add_oid(ctx, parent, nbr, name, \ CTLTYPE_U8 | CTLFLAG_MPSAFE | (access), \ - __ptr, val, sysctl_handle_bool, "CU", __DESCR(descr)); \ + __ptr, val, sysctl_handle_bool, "CU", __DESCR(descr), \ + NULL); \ }) /* Oid for a signed 8-bit int. If ptr is NULL, val is returned. */ @@ -406,7 +421,7 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry); ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S8); \ sysctl_add_oid(ctx, parent, nbr, name, \ CTLTYPE_S8 | CTLFLAG_MPSAFE | (access), \ - __ptr, val, sysctl_handle_8, "C", __DESCR(descr)); \ + __ptr, val, sysctl_handle_8, "C", __DESCR(descr), NULL); \ }) /* Oid for an unsigned 8-bit int. If ptr is NULL, val is returned. */ @@ -426,7 +441,7 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry); ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U8); \ sysctl_add_oid(ctx, parent, nbr, name, \ CTLTYPE_U8 | CTLFLAG_MPSAFE | (access), \ - __ptr, val, sysctl_handle_8, "CU", __DESCR(descr)); \ + __ptr, val, sysctl_handle_8, "CU", __DESCR(descr), NULL); \ }) /* Oid for a signed 16-bit int. If ptr is NULL, val is returned. */ @@ -446,7 +461,7 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry); ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S16); \ sysctl_add_oid(ctx, parent, nbr, name, \ CTLTYPE_S16 | CTLFLAG_MPSAFE | (access), \ - __ptr, val, sysctl_handle_16, "S", __DESCR(descr)); \ + __ptr, val, sysctl_handle_16, "S", __DESCR(descr), NULL); \ }) /* Oid for an unsigned 16-bit int. If ptr is NULL, val is returned. */ @@ -466,7 +481,7 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry); ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U16); \ sysctl_add_oid(ctx, parent, nbr, name, \ CTLTYPE_U16 | CTLFLAG_MPSAFE | (access), \ - __ptr, val, sysctl_handle_16, "SU", __DESCR(descr)); \ + __ptr, val, sysctl_handle_16, "SU", __DESCR(descr), NULL); \ }) /* Oid for a signed 32-bit int. If ptr is NULL, val is returned. */ @@ -486,7 +501,7 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry); ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S32); \ sysctl_add_oid(ctx, parent, nbr, name, \ CTLTYPE_S32 | CTLFLAG_MPSAFE | (access), \ - __ptr, val, sysctl_handle_32, "I", __DESCR(descr)); \ + __ptr, val, sysctl_handle_32, "I", __DESCR(descr), NULL); \ }) /* Oid for an unsigned 32-bit int. If ptr is NULL, val is returned. */ @@ -506,7 +521,7 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry); ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U32); \ sysctl_add_oid(ctx, parent, nbr, name, \ CTLTYPE_U32 | CTLFLAG_MPSAFE | (access), \ - __ptr, val, sysctl_handle_32, "IU", __DESCR(descr)); \ + __ptr, val, sysctl_handle_32, "IU", __DESCR(descr), NULL); \ }) /* Oid for a signed 64-bit int. If ptr is NULL, val is returned. */ @@ -526,7 +541,7 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry); ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S64); \ sysctl_add_oid(ctx, parent, nbr, name, \ CTLTYPE_S64 | CTLFLAG_MPSAFE | (access), \ - __ptr, val, sysctl_handle_64, "Q", __DESCR(descr)); \ + __ptr, val, sysctl_handle_64, "Q", __DESCR(descr), NULL); \ }) /* Oid for an unsigned 64-bit int. If ptr is NULL, val is returned. */ @@ -546,16 +561,19 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry); ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U64); \ sysctl_add_oid(ctx, parent, nbr, name, \ CTLTYPE_U64 | CTLFLAG_MPSAFE | (access), \ - __ptr, val, sysctl_handle_64, "QU", __DESCR(descr)); \ + __ptr, val, sysctl_handle_64, "QU", __DESCR(descr), NULL); \ }) /* Oid for an int. If ptr is SYSCTL_NULL_INT_PTR, val is returned. */ #define SYSCTL_NULL_INT_PTR ((int *)NULL) -#define SYSCTL_INT(parent, nbr, name, access, ptr, val, descr) \ - SYSCTL_OID(parent, nbr, name, \ - CTLTYPE_INT | CTLFLAG_MPSAFE | (access), \ - ptr, val, sysctl_handle_int, "I", descr); \ - CTASSERT((((access) & CTLTYPE) == 0 || \ +#define SYSCTL_INT(parent, nbr, name, access, ptr, val, descr) \ + SYSCTL_INT_WITH_LABEL(parent, nbr, name, access, ptr, val, descr, NULL) + +#define SYSCTL_INT_WITH_LABEL(parent, nbr, name, access, ptr, val, descr, label) \ + SYSCTL_OID_WITH_LABEL(parent, nbr, name, \ + CTLTYPE_INT | CTLFLAG_MPSAFE | (access), \ + ptr, val, sysctl_handle_int, "I", descr, label); \ + CTASSERT((((access) & CTLTYPE) == 0 || \ ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT) && \ sizeof(int) == sizeof(*(ptr))) @@ -566,7 +584,7 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry); ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT); \ sysctl_add_oid(ctx, parent, nbr, name, \ CTLTYPE_INT | CTLFLAG_MPSAFE | (access), \ - __ptr, val, sysctl_handle_int, "I", __DESCR(descr)); \ + __ptr, val, sysctl_handle_int, "I", __DESCR(descr), NULL); \ }) /* Oid for an unsigned int. If ptr is NULL, val is returned. */ @@ -586,7 +604,7 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry); ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_UINT); \ sysctl_add_oid(ctx, parent, nbr, name, \ CTLTYPE_UINT | CTLFLAG_MPSAFE | (access), \ - __ptr, val, sysctl_handle_int, "IU", __DESCR(descr)); \ + __ptr, val, sysctl_handle_int, "IU", __DESCR(descr), NULL); \ }) /* Oid for a long. The pointer must be non NULL. */ @@ -606,7 +624,7 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry); ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_LONG); \ sysctl_add_oid(ctx, parent, nbr, name, \ CTLTYPE_LONG | CTLFLAG_MPSAFE | (access), \ - __ptr, 0, sysctl_handle_long, "L", __DESCR(descr)); \ + __ptr, 0, sysctl_handle_long, "L", __DESCR(descr), NULL); \ }) /* Oid for an unsigned long. The pointer must be non NULL. */ @@ -626,7 +644,7 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry); ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_ULONG); \ sysctl_add_oid(ctx, parent, nbr, name, \ CTLTYPE_ULONG | CTLFLAG_MPSAFE | (access), \ - __ptr, 0, sysctl_handle_long, "LU", __DESCR(descr)); \ + __ptr, 0, sysctl_handle_long, "LU", __DESCR(descr), NULL); \ }) /* Oid for a quad. The pointer must be non NULL. */ @@ -646,7 +664,7 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry); ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S64); \ sysctl_add_oid(ctx, parent, nbr, name, \ CTLTYPE_S64 | CTLFLAG_MPSAFE | (access), \ - __ptr, 0, sysctl_handle_64, "Q", __DESCR(descr)); \ + __ptr, 0, sysctl_handle_64, "Q", __DESCR(descr), NULL); \ }) #define SYSCTL_NULL_UQUAD_PTR ((uint64_t *)NULL) @@ -665,7 +683,7 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry); ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U64); \ sysctl_add_oid(ctx, parent, nbr, name, \ CTLTYPE_U64 | CTLFLAG_MPSAFE | (access), \ - __ptr, 0, sysctl_handle_64, "QU", __DESCR(descr)); \ + __ptr, 0, sysctl_handle_64, "QU", __DESCR(descr), NULL); \ }) /* Oid for a CPU dependent variable */ @@ -679,12 +697,12 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry); __ret = sysctl_add_oid(ctx, parent, nbr, name, \ CTLTYPE_U64 | CTLFLAG_MPSAFE | (access), \ (ptr), 0, sysctl_handle_64, "QU", \ - __DESCR(descr)); \ + __DESCR(descr), NULL); \ } else { \ __ret = sysctl_add_oid(ctx, parent, nbr, name, \ CTLTYPE_UINT | CTLFLAG_MPSAFE | (access), \ (ptr), 0, sysctl_handle_int, "IU", \ - __DESCR(descr)); \ + __DESCR(descr), NULL); \ } \ __ret; \ }) @@ -706,7 +724,8 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry); ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U64); \ sysctl_add_oid(ctx, parent, nbr, name, \ CTLTYPE_U64 | CTLFLAG_MPSAFE | (access), \ - __ptr, 0, sysctl_handle_counter_u64, "QU", __DESCR(descr)); \ + __ptr, 0, sysctl_handle_counter_u64, "QU", __DESCR(descr), \ + NULL); \ }) /* Oid for an array of counter(9)s. The pointer and length must be non zero. */ @@ -728,7 +747,7 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry); sysctl_add_oid(ctx, parent, nbr, name, \ CTLTYPE_OPAQUE | CTLFLAG_MPSAFE | (access), \ __ptr, len, sysctl_handle_counter_u64_array, "S", \ - __DESCR(descr)); \ + __DESCR(descr), NULL); \ }) /* Oid for an opaque object. Specified by a pointer and a length. */ @@ -743,7 +762,7 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry); CTASSERT(((access) & CTLTYPE) == 0 || \ ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE); \ sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_OPAQUE|(access), \ - ptr, len, sysctl_handle_opaque, fmt, __DESCR(descr)); \ + ptr, len, sysctl_handle_opaque, fmt, __DESCR(descr), NULL); \ }) /* Oid for a struct. Specified by a pointer and a type. */ @@ -760,7 +779,7 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry); ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE); \ sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_OPAQUE|(access), \ (ptr), sizeof(struct type), \ - sysctl_handle_opaque, "S," #type, __DESCR(descr)); \ + sysctl_handle_opaque, "S," #type, __DESCR(descr), NULL); \ }) /* Oid for a procedure. Specified by a pointer and an arg. */ @@ -773,7 +792,7 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry); ({ \ CTASSERT(((access) & CTLTYPE) != 0); \ sysctl_add_oid(ctx, parent, nbr, name, (access), \ - (ptr), (arg), (handler), (fmt), __DESCR(descr)); \ + (ptr), (arg), (handler), (fmt), __DESCR(descr), NULL); \ }) /* Oid to handle limits on uma(9) zone specified by pointer. */ @@ -791,7 +810,8 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry); ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT); \ sysctl_add_oid(ctx, parent, nbr, name, \ CTLTYPE_INT | CTLFLAG_MPSAFE | (access), \ - __ptr, 0, sysctl_handle_uma_zone_max, "I", __DESCR(descr)); \ + __ptr, 0, sysctl_handle_uma_zone_max, "I", __DESCR(descr), \ + NULL); \ }) /* Oid to obtain current use of uma(9) zone specified by pointer. */ @@ -809,7 +829,8 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry); ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT); \ sysctl_add_oid(ctx, parent, nbr, name, \ CTLTYPE_INT | CTLFLAG_MPSAFE | CTLFLAG_RD | (access), \ - __ptr, 0, sysctl_handle_uma_zone_cur, "I", __DESCR(descr)); \ + __ptr, 0, sysctl_handle_uma_zone_cur, "I", __DESCR(descr), \ + NULL); \ }) /* @@ -817,8 +838,8 @@ TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry); * kernel features. */ #define FEATURE(name, desc) \ - SYSCTL_INT(_kern_features, OID_AUTO, name, CTLFLAG_RD | CTLFLAG_CAPRD, \ - SYSCTL_NULL_INT_PTR, 1, desc) + SYSCTL_INT_WITH_LABEL(_kern_features, OID_AUTO, name, \ + CTLFLAG_RD | CTLFLAG_CAPRD, SYSCTL_NULL_INT_PTR, 1, desc, "feature") #endif /* _KERNEL */ @@ -1037,7 +1058,7 @@ extern char kern_ident[]; struct sysctl_oid *sysctl_add_oid(struct sysctl_ctx_list *clist, struct sysctl_oid_list *parent, int nbr, const char *name, int kind, void *arg1, intmax_t arg2, int (*handler)(SYSCTL_HANDLER_ARGS), - const char *fmt, const char *descr); + const char *fmt, const char *descr, const char *label); int sysctl_remove_name(struct sysctl_oid *parent, const char *name, int del, int recurse); void sysctl_rename_oid(struct sysctl_oid *oidp, const char *name); diff --git a/freebsd/sys/sys/sysproto.h b/freebsd/sys/sys/sysproto.h index b3c944bf..a1673035 100644 --- a/freebsd/sys/sys/sysproto.h +++ b/freebsd/sys/sys/sysproto.h @@ -3,7 +3,7 @@ * * DO NOT EDIT-- this file is automatically generated. * $FreeBSD$ - * created from FreeBSD: head/sys/kern/syscalls.master 309677 2016-12-07 16:11:55Z rwatson + * created from FreeBSD: head/sys/kern/syscalls.master 310638 2016-12-27 20:21:11Z jhb */ #ifndef _SYS_SYSPROTO_H_ @@ -1147,7 +1147,7 @@ struct mac_syscall_args { struct getfsstat_args { char buf_l_[PADL_(struct statfs *)]; struct statfs * buf; char buf_r_[PADR_(struct statfs *)]; char bufsize_l_[PADL_(long)]; long bufsize; char bufsize_r_[PADR_(long)]; - char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; + char mode_l_[PADL_(int)]; int mode; char mode_r_[PADR_(int)]; }; struct statfs_args { char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; @@ -2395,7 +2395,7 @@ int ogetdirentries(struct thread *, struct ogetdirentries_args *); struct freebsd4_getfsstat_args { char buf_l_[PADL_(struct ostatfs *)]; struct ostatfs * buf; char buf_r_[PADR_(struct ostatfs *)]; char bufsize_l_[PADL_(long)]; long bufsize; char bufsize_r_[PADR_(long)]; - char flags_l_[PADL_(int)]; int flags; char flags_r_[PADR_(int)]; + char mode_l_[PADL_(int)]; int mode; char mode_r_[PADR_(int)]; }; struct freebsd4_statfs_args { char path_l_[PADL_(char *)]; char * path; char path_r_[PADR_(char *)]; diff --git a/freebsd/sys/sys/systm.h b/freebsd/sys/sys/systm.h index d2205a7a..2f781e9e 100644 --- a/freebsd/sys/sys/systm.h +++ b/freebsd/sys/sys/systm.h @@ -272,8 +272,8 @@ int vsnprintf(char *, size_t, const char *, __va_list) __printflike(3, 0); int vsnrprintf(char *, size_t, int, const char *, __va_list) __printflike(4, 0); int vsprintf(char *buf, const char *, __va_list) __printflike(2, 0); int ttyprintf(struct tty *, const char *, ...) __printflike(2, 3); -int sscanf(const char *, char const *, ...) __nonnull(1) __nonnull(2); -int vsscanf(const char *, char const *, __va_list) __nonnull(1) __nonnull(2); +int sscanf(const char *, char const *, ...) __nonnull(1) __nonnull(2) __scanflike(2, 3); +int vsscanf(const char *, char const *, __va_list) __nonnull(1) __nonnull(2) __scanflike(2, 0); long strtol(const char *, char **, int) __nonnull(1); u_long strtoul(const char *, char **, int) __nonnull(1); quad_t strtoq(const char *, char **, int) __nonnull(1); diff --git a/freebsd/sys/sys/vnode.h b/freebsd/sys/sys/vnode.h index 5400fe1c..e125b0de 100644 --- a/freebsd/sys/sys/vnode.h +++ b/freebsd/sys/sys/vnode.h @@ -829,6 +829,7 @@ void vput(struct vnode *vp); void vrele(struct vnode *vp); void vref(struct vnode *vp); void vrefl(struct vnode *vp); +void vrefact(struct vnode *vp); int vrefcnt(struct vnode *vp); void v_addpollinfo(struct vnode *vp); diff --git a/freebsd/sys/vm/uma_core.c b/freebsd/sys/vm/uma_core.c index 00ac3e5a..357895c0 100644 --- a/freebsd/sys/vm/uma_core.c +++ b/freebsd/sys/vm/uma_core.c @@ -1231,7 +1231,7 @@ page_free(void *mem, vm_size_t size, uint8_t flags) else if (flags & UMA_SLAB_KERNEL) vmem = kernel_arena; else - panic("UMA: page_free used with invalid flags %d", flags); + panic("UMA: page_free used with invalid flags %x", flags); kmem_free(vmem, (vm_offset_t)mem, size); #else /* __rtems__ */ |