Skip to content

Commit 34096f8

Browse files
committed
Auto merge of #3101 - devnexen:fbsd_sctp1, r=JohnTitor
freebsd add initial sctp support
2 parents 8edb82d + 4e26292 commit 34096f8

File tree

3 files changed

+311
-0
lines changed

3 files changed

+311
-0
lines changed

libc-test/build.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1935,6 +1935,7 @@ fn test_freebsd(target: &str) {
19351935
"netdb.h",
19361936
"netinet/ip.h",
19371937
"netinet/in.h",
1938+
"netinet/sctp.h",
19381939
"netinet/tcp.h",
19391940
"netinet/udp.h",
19401941
"poll.h",
@@ -2408,6 +2409,8 @@ fn test_freebsd(target: &str) {
24082409
// `snap_time` is a `long double`, but it's a nightmare to bind correctly in rust
24092410
// for the moment, so it's a best effort thing...
24102411
("statinfo", "snap_time") => true,
2412+
("sctp_sndrcvinfo", "__reserve_pad") => true,
2413+
("sctp_extrcvinfo", "__reserve_pad") => true,
24112414

24122415
_ => false,
24132416
}

libc-test/semver/freebsd.txt

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,6 +1079,49 @@ SCHED_RR
10791079
SCM_CREDS
10801080
SCM_RIGHTS
10811081
SCM_TIMESTAMP
1082+
SCTP_ALL_ASSOC
1083+
SCTP_ADAPTATION_LAYER
1084+
SCTP_ADAPTION_LAYER
1085+
SCTP_ASSOCINFO
1086+
SCTP_AUTHINFO
1087+
SCTP_AUTH_CHUNK
1088+
SCTP_AUTH_ACTIVE_KEY
1089+
SCTP_AUTH_DEACTIVATE_KEY
1090+
SCTP_AUTH_DELETE_KEY
1091+
SCTP_AUTH_KEY
1092+
SCTP_AUTO_ASCONF
1093+
SCTP_AUTOCLOSE
1094+
SCTP_CONTEXT
1095+
SCTP_CURRENT_ASSOC
1096+
SCTP_DEFAULT_SEND_PARAM
1097+
SCTP_DELAYED_SACK
1098+
SCTP_DISABLE_FRAGMENTS
1099+
SCTP_DSTADDRV4
1100+
SCTP_DSTADDRV6
1101+
SCTP_EVENTS
1102+
SCTP_EXPLICIT_EOR
1103+
SCTP_EXTRCV
1104+
SCTP_FRAGMENT_INTERLEAVE
1105+
SCTP_FUTURE_ASSOC
1106+
SCTP_HMAC_IDENT
1107+
SCTP_INIT
1108+
SCTP_INITMSG
1109+
SCTP_I_WANT_MAPPED_V4_ADDR
1110+
SCTP_MAXBURST
1111+
SCTP_MAX_BURST
1112+
SCTP_MAXSEG
1113+
SCTP_NODELAY
1114+
SCTP_NXTINFO
1115+
SCTP_PARTIAL_DELIVERY_POINT
1116+
SCTP_PEER_ADDR_PARAMS
1117+
SCTP_PRIMARY_ADDR
1118+
SCTP_REUSE_PORT
1119+
SCTP_PRINFO
1120+
SCTP_RTOINFO
1121+
SCTP_SET_PEER_PRIMARY_ADDR
1122+
SCTP_SNDINFO
1123+
SCTP_SNDRCV
1124+
SCTP_USE_EXT_RCVINFO
10821125
SEEK_DATA
10831126
SEEK_HOLE
10841127
SEM_FAILED
@@ -1886,6 +1929,21 @@ sched_param
18861929
sched_rr_get_interval
18871930
sched_setparam
18881931
sched_setscheduler
1932+
sctphdr
1933+
sctp_assoc_t
1934+
sctp_authinfo
1935+
sctp_chunkhdr
1936+
sctp_default_prinfo
1937+
sctp_event
1938+
sctp_event_subscribe
1939+
sctp_extrcvinfo
1940+
sctp_initmsg
1941+
sctp_nxtinfo
1942+
sctp_prinfo
1943+
sctp_rcvinfo
1944+
sctp_sndinfo
1945+
sctp_sndrcvinfo
1946+
sctp_paramhdr
18891947
sdallocx
18901948
seed48
18911949
seekdir

src/unix/bsd/freebsdlike/freebsd/mod.rs

Lines changed: 250 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ pub type au_asid_t = ::pid_t;
4646

4747
pub type cpusetid_t = ::c_int;
4848

49+
pub type sctp_assoc_t = u32;
50+
4951
#[cfg_attr(feature = "extra_traits", derive(Debug, Hash, PartialEq, Eq))]
5052
#[repr(u32)]
5153
pub enum devstat_support_flags {
@@ -1019,6 +1021,110 @@ s! {
10191021
__priva: [[::uintptr_t; 32]; 8],
10201022
__privb: [::uintptr_t; 2],
10211023
}
1024+
1025+
pub struct sctp_event {
1026+
pub se_assoc_id: ::sctp_assoc_t,
1027+
pub se_type: u16,
1028+
pub se_on: u8,
1029+
}
1030+
1031+
pub struct sctp_event_subscribe {
1032+
pub sctp_data_io_event: u8,
1033+
pub sctp_association_event: u8,
1034+
pub sctp_address_event: u8,
1035+
pub sctp_send_failure_event: u8,
1036+
pub sctp_peer_error_event: u8,
1037+
pub sctp_shutdown_event: u8,
1038+
pub sctp_partial_delivery_event: u8,
1039+
pub sctp_adaptation_layer_event: u8,
1040+
pub sctp_authentication_event: u8,
1041+
pub sctp_sender_dry_event: u8,
1042+
pub sctp_stream_reset_event: u8,
1043+
}
1044+
1045+
pub struct sctp_initmsg {
1046+
pub sinit_num_ostreams: u16,
1047+
pub sinit_max_instreams: u16,
1048+
pub sinit_max_attempts: u16,
1049+
pub sinit_max_init_timeo: u16,
1050+
}
1051+
1052+
pub struct sctp_sndrcvinfo {
1053+
pub sinfo_stream: u16,
1054+
pub sinfo_ssn: u16,
1055+
pub sinfo_flags: u16,
1056+
pub sinfo_ppid: u32,
1057+
pub sinfo_context: u32,
1058+
pub sinfo_timetolive: u32,
1059+
pub sinfo_tsn: u32,
1060+
pub sinfo_cumtsn: u32,
1061+
pub sinfo_assoc_id: ::sctp_assoc_t,
1062+
pub sinfo_keynumber: u16,
1063+
pub sinfo_keynumber_valid: u16,
1064+
pub __reserve_pad: [[u8; 23]; 4],
1065+
}
1066+
1067+
pub struct sctp_extrcvinfo {
1068+
pub sinfo_stream: u16,
1069+
pub sinfo_ssn: u16,
1070+
pub sinfo_flags: u16,
1071+
pub sinfo_ppid: u32,
1072+
pub sinfo_context: u32,
1073+
pub sinfo_timetolive: u32,
1074+
pub sinfo_tsn: u32,
1075+
pub sinfo_cumtsn: u32,
1076+
pub sinfo_assoc_id: ::sctp_assoc_t,
1077+
pub serinfo_next_flags: u16,
1078+
pub serinfo_next_stream: u16,
1079+
pub serinfo_next_aid: u32,
1080+
pub serinfo_next_length: u32,
1081+
pub serinfo_next_ppid: u32,
1082+
pub sinfo_keynumber: u16,
1083+
pub sinfo_keynumber_valid: u16,
1084+
pub __reserve_pad: [[u8; 19]; 4],
1085+
}
1086+
1087+
pub struct sctp_sndinfo {
1088+
pub snd_sid: u16,
1089+
pub snd_flags: u16,
1090+
pub snd_ppid: u32,
1091+
pub snd_context: u32,
1092+
pub snd_assoc_id: ::sctp_assoc_t,
1093+
}
1094+
1095+
pub struct sctp_prinfo {
1096+
pub pr_policy: u16,
1097+
pub pr_value: u32,
1098+
}
1099+
1100+
pub struct sctp_default_prinfo {
1101+
pub pr_policy: u16,
1102+
pub pr_value: u32,
1103+
pub pr_assoc_id: ::sctp_assoc_t,
1104+
}
1105+
1106+
pub struct sctp_authinfo {
1107+
pub auth_keynumber: u16,
1108+
}
1109+
1110+
pub struct sctp_rcvinfo {
1111+
pub rcv_sid: u16,
1112+
pub rcv_ssn: u16,
1113+
pub rcv_flags: u16,
1114+
pub rcv_ppid: u32,
1115+
pub rcv_tsn: u32,
1116+
pub rcv_cumtsn: u32,
1117+
pub rcv_context: u32,
1118+
pub rcv_assoc_id: ::sctp_assoc_t,
1119+
}
1120+
1121+
pub struct sctp_nxtinfo {
1122+
pub nxt_sid: u16,
1123+
pub nxt_flags: u16,
1124+
pub nxt_ppid: u32,
1125+
pub nxt_length: u32,
1126+
pub nxt_assoc_id: ::sctp_assoc_t,
1127+
}
10221128
}
10231129

10241130
s_no_extra_traits! {
@@ -1229,6 +1335,27 @@ s_no_extra_traits! {
12291335
pub ifdr_vendor: u32,
12301336
pub ifdr_msg: [::c_char; ::IFDR_MSG_SIZE as usize],
12311337
}
1338+
1339+
#[repr(packed)]
1340+
pub struct sctphdr {
1341+
pub src_port: u16,
1342+
pub dest_port: u16,
1343+
pub v_tag: u32,
1344+
pub checksum: u32,
1345+
}
1346+
1347+
#[repr(packed)]
1348+
pub struct sctp_chunkhdr {
1349+
pub chunk_type: u8,
1350+
pub chunk_flags: u8,
1351+
pub chunk_length: u16,
1352+
}
1353+
1354+
#[repr(packed)]
1355+
pub struct sctp_paramhdr {
1356+
pub param_type: u16,
1357+
pub param_length: u16,
1358+
}
12321359
}
12331360

12341361
cfg_if! {
@@ -1890,6 +2017,81 @@ cfg_if! {
18902017
self.__ifi_lastchange.hash(state);
18912018
}
18922019
}
2020+
2021+
impl PartialEq for sctphdr {
2022+
fn eq(&self, other: &sctphdr) -> bool {
2023+
return {self.src_port} == {other.src_port} &&
2024+
{self.dest_port} == {other.dest_port} &&
2025+
{self.v_tag} == {other.v_tag} &&
2026+
{self.checksum} == {other.checksum}
2027+
}
2028+
}
2029+
impl Eq for sctphdr {}
2030+
impl ::fmt::Debug for sctphdr {
2031+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
2032+
f.debug_struct("sctphdr")
2033+
.field("src_port", &{self.src_port})
2034+
.field("dest_port", &{self.dest_port})
2035+
.field("v_tag", &{self.v_tag})
2036+
.field("checksum", &{self.checksum})
2037+
.finish()
2038+
}
2039+
}
2040+
impl ::hash::Hash for sctphdr {
2041+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
2042+
{self.src_port}.hash(state);
2043+
{self.dest_port}.hash(state);
2044+
{self.v_tag}.hash(state);
2045+
{self.checksum}.hash(state);
2046+
}
2047+
}
2048+
2049+
impl PartialEq for sctp_chunkhdr {
2050+
fn eq(&self, other: &sctp_chunkhdr) -> bool {
2051+
return {self.chunk_type} == {other.chunk_type} &&
2052+
{self.chunk_flags} == {other.chunk_flags} &&
2053+
{self.chunk_length} == {other.chunk_length}
2054+
}
2055+
}
2056+
impl Eq for sctp_chunkhdr {}
2057+
impl ::fmt::Debug for sctp_chunkhdr {
2058+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
2059+
f.debug_struct("sctp_chunkhdr")
2060+
.field("chunk_type", &{self.chunk_type})
2061+
.field("chunk_flags", &{self.chunk_flags})
2062+
.field("chunk_length", &{self.chunk_length})
2063+
.finish()
2064+
}
2065+
}
2066+
impl ::hash::Hash for sctp_chunkhdr {
2067+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
2068+
{self.chunk_type}.hash(state);
2069+
{self.chunk_flags}.hash(state);
2070+
{self.chunk_length}.hash(state);
2071+
}
2072+
}
2073+
2074+
impl PartialEq for sctp_paramhdr {
2075+
fn eq(&self, other: &sctp_paramhdr) -> bool {
2076+
return {self.param_type} == {other.param_type} &&
2077+
{self.param_length} == {other.param_length}
2078+
}
2079+
}
2080+
impl Eq for sctp_paramhdr {}
2081+
impl ::fmt::Debug for sctp_paramhdr {
2082+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
2083+
f.debug_struct("sctp_paramhdr")
2084+
.field("param_type", &{self.param_type})
2085+
.field("param_length", &{self.param_length})
2086+
.finish()
2087+
}
2088+
}
2089+
impl ::hash::Hash for sctp_paramhdr {
2090+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
2091+
{self.param_type}.hash(state);
2092+
{self.param_length}.hash(state);
2093+
}
2094+
}
18932095
}
18942096
}
18952097

@@ -3818,6 +4020,54 @@ pub const SIGTHR: ::c_int = 32;
38184020
pub const SIGLWP: ::c_int = SIGTHR;
38194021
pub const SIGLIBRT: ::c_int = 33;
38204022

4023+
// netinet/sctp.h
4024+
pub const SCTP_FUTURE_ASSOC: ::c_int = 0;
4025+
pub const SCTP_CURRENT_ASSOC: ::c_int = 1;
4026+
pub const SCTP_ALL_ASSOC: ::c_int = 2;
4027+
4028+
pub const SCTP_INIT: ::c_int = 0x0001;
4029+
pub const SCTP_SNDRCV: ::c_int = 0x0002;
4030+
pub const SCTP_EXTRCV: ::c_int = 0x0003;
4031+
pub const SCTP_SNDINFO: ::c_int = 0x0004;
4032+
pub const SCTP_RCVINFO: ::c_int = 0x0005;
4033+
pub const SCTP_NXTINFO: ::c_int = 0x0006;
4034+
pub const SCTP_PRINFO: ::c_int = 0x0007;
4035+
pub const SCTP_AUTHINFO: ::c_int = 0x0008;
4036+
pub const SCTP_DSTADDRV4: ::c_int = 0x0009;
4037+
pub const SCTP_DSTADDRV6: ::c_int = 0x000a;
4038+
4039+
pub const SCTP_RTOINFO: ::c_int = 0x00000001;
4040+
pub const SCTP_ASSOCINFO: ::c_int = 0x00000002;
4041+
pub const SCTP_INITMSG: ::c_int = 0x00000003;
4042+
pub const SCTP_NODELAY: ::c_int = 0x00000004;
4043+
pub const SCTP_AUTOCLOSE: ::c_int = 0x00000005;
4044+
pub const SCTP_SET_PEER_PRIMARY_ADDR: ::c_int = 0x00000006;
4045+
pub const SCTP_PRIMARY_ADDR: ::c_int = 0x00000007;
4046+
pub const SCTP_ADAPTATION_LAYER: ::c_int = 0x00000008;
4047+
pub const SCTP_ADAPTION_LAYER: ::c_int = 0x00000008;
4048+
pub const SCTP_DISABLE_FRAGMENTS: ::c_int = 0x00000009;
4049+
pub const SCTP_PEER_ADDR_PARAMS: ::c_int = 0x0000000a;
4050+
pub const SCTP_DEFAULT_SEND_PARAM: ::c_int = 0x0000000b;
4051+
pub const SCTP_EVENTS: ::c_int = 0x0000000c;
4052+
pub const SCTP_I_WANT_MAPPED_V4_ADDR: ::c_int = 0x0000000d;
4053+
pub const SCTP_MAXSEG: ::c_int = 0x0000000e;
4054+
pub const SCTP_DELAYED_SACK: ::c_int = 0x0000000f;
4055+
pub const SCTP_FRAGMENT_INTERLEAVE: ::c_int = 0x00000010;
4056+
pub const SCTP_PARTIAL_DELIVERY_POINT: ::c_int = 0x00000011;
4057+
pub const SCTP_AUTH_CHUNK: ::c_int = 0x00000012;
4058+
pub const SCTP_AUTH_KEY: ::c_int = 0x00000013;
4059+
pub const SCTP_HMAC_IDENT: ::c_int = 0x00000014;
4060+
pub const SCTP_AUTH_ACTIVE_KEY: ::c_int = 0x00000015;
4061+
pub const SCTP_AUTH_DELETE_KEY: ::c_int = 0x00000016;
4062+
pub const SCTP_USE_EXT_RCVINFO: ::c_int = 0x00000017;
4063+
pub const SCTP_AUTO_ASCONF: ::c_int = 0x00000018;
4064+
pub const SCTP_MAXBURST: ::c_int = 0x00000019;
4065+
pub const SCTP_MAX_BURST: ::c_int = 0x00000019;
4066+
pub const SCTP_CONTEXT: ::c_int = 0x0000001a;
4067+
pub const SCTP_EXPLICIT_EOR: ::c_int = 0x00000001b;
4068+
pub const SCTP_REUSE_PORT: ::c_int = 0x00000001c;
4069+
pub const SCTP_AUTH_DEACTIVATE_KEY: ::c_int = 0x00000001d;
4070+
38214071
const_fn! {
38224072
{const} fn _ALIGN(p: usize) -> usize {
38234073
(p + _ALIGNBYTES) & !_ALIGNBYTES

0 commit comments

Comments
 (0)