Skip to content

Commit 8778e77

Browse files
committed
Auto merge of #3095 - devnexen:linux_sctp1, r=JohnTitor
linux starting adding sctp support
2 parents 4dc0041 + eba949d commit 8778e77

File tree

3 files changed

+233
-1
lines changed

3 files changed

+233
-1
lines changed

libc-test/build.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3235,8 +3235,8 @@ fn test_linux(target: &str) {
32353235
"linux/reboot.h",
32363236
"linux/rtnetlink.h",
32373237
"linux/sched.h",
3238+
"linux/sctp.h",
32383239
"linux/seccomp.h",
3239-
"linux/sched.h",
32403240
"linux/sock_diag.h",
32413241
"linux/sockios.h",
32423242
"linux/uinput.h",
@@ -3398,6 +3398,8 @@ fn test_linux(target: &str) {
33983398
// FIXME: Unignore once we update Ubuntu to 22.04
33993399
"mallinfo2" if sparc64 => true,
34003400
"ptrace_rseq_configuration" if sparc64 => true,
3401+
"sctp_initmsg" | "sctp_sndrcvinfo" | "sctp_sndinfo" | "sctp_rcvinfo"
3402+
| "sctp_nxtinfo" | "sctp_prinfo" | "sctp_authinfo" => true,
34013403

34023404
_ => false,
34033405
}
@@ -3657,6 +3659,7 @@ fn test_linux(target: &str) {
36573659
| "IFLA_TSO_MAX_SEGS" // linux v5.18+
36583660
| "IFLA_ALLMULTI" // linux v6.0+
36593661
=> true,
3662+
"SCTP_FUTURE_ASSOC" | "SCTP_CURRENT_ASSOC" | "SCTP_ALL_ASSOC" | "SCTP_PEER_ADDR_THLDS_V2" => true, // linux 5.5+
36603663

36613664
_ => false,
36623665
}

libc-test/semver/linux.txt

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,6 +1338,7 @@ MSG_INFO
13381338
MSG_MORE
13391339
MSG_NOERROR
13401340
MSG_NOSIGNAL
1341+
MSG_NOTIFICATION
13411342
MSG_RST
13421343
MSG_STAT
13431344
MSG_SYN
@@ -2159,6 +2160,70 @@ SCM_J1939_ERRQUEUE
21592160
SCM_J1939_PRIO
21602161
SCM_TIMESTAMP
21612162
SCM_TIMESTAMPING
2163+
SCTP_ABORT
2164+
SCTP_ADDR_OVER
2165+
SCTP_ALL_ASSOC
2166+
SCTP_ASSOCINFO
2167+
SCTP_AUTH_CHUNK
2168+
SCTP_AUTH_ACTIVE_KEY
2169+
SCTP_AUTH_DEACTIVATE_KEY
2170+
SCTP_AUTH_DELETE_KEY
2171+
SCTP_AUTH_KEY
2172+
SCTP_AUTO_ASCONF
2173+
SCTP_AUTOCLOSE
2174+
SCTP_CONTEXT
2175+
SCTP_CURRENT_ASSOC
2176+
SCTP_DELAYED_ACK
2177+
SCTP_DELAYED_ACK_TIME
2178+
SCTP_DELAYED_SACK
2179+
SCTP_DEFAULT_SEND_PARAM
2180+
SCTP_DEFAULT_SNDINFO
2181+
SCTP_ENABLE_CHANGE_ASSOC_REQ
2182+
SCTP_ENABLE_RESET_ASSOC_REQ
2183+
SCTP_ENABLE_RESET_STREAM_REQ
2184+
SCTP_ENABLE_STRRESET_MASK
2185+
SCTP_EOF
2186+
SCTP_EVENTS
2187+
SCTP_FRAGMENT_INTERLEAVE
2188+
SCTP_FUTURE_ASSOC
2189+
SCTP_GET_ASSOC_ID_LIST
2190+
SCTP_GET_ASSOC_NUMBER
2191+
SCTP_GET_PEER_ADDR_INFO
2192+
SCTP_HMAC_IDENT
2193+
SCTP_I_WANT_MAPPED_V4_ADDR
2194+
SCTP_INIT
2195+
SCTP_INITMSG
2196+
SCTP_LOCAL_AUTH_CHUNKS
2197+
SCTP_MAX_BURST
2198+
SCTP_MAXSEG
2199+
SCTP_NODELAY
2200+
SCTP_NOTIFICATION
2201+
SCTP_NXTINFO
2202+
SCTP_PARTIAL_DELIVERY_POINT
2203+
SCTP_PEER_ADDR_PARAMS
2204+
SCTP_PEER_ADDR_THLDS
2205+
SCTP_PEER_ADDR_THLDS_V2
2206+
SCTP_PEER_AUTH_CHUNKS
2207+
SCTP_PR_SCTP_ALL
2208+
SCTP_PR_SCTP_NONE
2209+
SCTP_PR_SCTP_MASK
2210+
SCTP_PR_SCTP_MAX
2211+
SCTP_PR_SCTP_PRIO
2212+
SCTP_PR_SCTP_RTX
2213+
SCTP_PR_SCTP_TTL
2214+
SCTP_PRIMARY_ADDR
2215+
SCTP_RECVNXTINFO
2216+
SCTP_RECVRCVINFO
2217+
SCTP_REUSE_PORT
2218+
SCTP_RTOINFO
2219+
SCTP_SACK_IMMEDIATELY
2220+
SCTP_SENDALL
2221+
SCTP_SET_PEER_PRIMARY_ADDR
2222+
SCTP_SNDRCV
2223+
SCTP_STATUS
2224+
SCTP_STREAM_RESET_INCOMING
2225+
SCTP_STREAM_RESET_OUTGOING
2226+
SCTP_UNORDERED
21622227
SECCOMP_FILTER_FLAG_LOG
21632228
SECCOMP_FILTER_FLAG_SPEC_ALLOW
21642229
SECCOMP_FILTER_FLAG_TSYNC
@@ -3247,6 +3312,7 @@ sched_rr_get_interval
32473312
sched_setaffinity
32483313
sched_setparam
32493314
sched_setscheduler
3315+
sctp_assoc_t
32503316
seccomp_data
32513317
seed48
32523318
seekdir

src/unix/linux_like/linux/mod.rs

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ pub type name_t = u64;
4848

4949
pub type iconv_t = *mut ::c_void;
5050

51+
// linux/sctp.h
52+
pub type sctp_assoc_t = ::__s32;
53+
5154
#[cfg_attr(feature = "extra_traits", derive(Debug))]
5255
pub enum fpos64_t {} // FIXME: fill this out with a struct
5356
impl ::Copy for fpos64_t {}
@@ -625,6 +628,63 @@ s! {
625628
pub flag: *mut ::c_int,
626629
pub val: ::c_int,
627630
}
631+
632+
// linux/sctp.h
633+
634+
pub struct sctp_initmsg {
635+
pub sinit_num_ostreams: ::__u16,
636+
pub sinit_max_instreams: ::__u16,
637+
pub sinit_max_attempts: ::__u16,
638+
pub sinit_max_init_timeo: ::__u16,
639+
}
640+
641+
pub struct sctp_sndrcvinfo {
642+
pub sinfo_stream: ::__u16,
643+
pub sinfo_ssn: ::__u16,
644+
pub sinfo_flags: ::__u16,
645+
pub sinfo_ppid: ::__u32,
646+
pub sinfo_context: ::__u32,
647+
pub sinfo_timetolive: ::__u32,
648+
pub sinfo_tsn: ::__u32,
649+
pub sinfo_cumtsn: ::__u32,
650+
pub sinfo_assoc_id: ::sctp_assoc_t,
651+
}
652+
653+
pub struct sctp_sndinfo {
654+
pub snd_sid: ::__u16,
655+
pub snd_flags: ::__u16,
656+
pub snd_ppid: ::__u32,
657+
pub snd_context: ::__u32,
658+
pub snd_assoc_id: ::sctp_assoc_t,
659+
}
660+
661+
pub struct sctp_rcvinfo {
662+
pub rcv_sid: ::__u16,
663+
pub rcv_ssn: ::__u16,
664+
pub rcv_flags: ::__u16,
665+
pub rcv_ppid: ::__u32,
666+
pub rcv_tsn: ::__u32,
667+
pub rcv_cumtsn: ::__u32,
668+
pub rcv_context: ::__u32,
669+
pub rcv_assoc_id: ::sctp_assoc_t,
670+
}
671+
672+
pub struct sctp_nxtinfo {
673+
pub nxt_sid: ::__u16,
674+
pub nxt_flags: ::__u16,
675+
pub nxt_ppid: ::__u32,
676+
pub nxt_length: ::__u32,
677+
pub nxt_assoc_id: ::sctp_assoc_t,
678+
}
679+
680+
pub struct sctp_prinfo {
681+
pub pr_policy: ::__u16,
682+
pub pr_value: ::__u32,
683+
}
684+
685+
pub struct sctp_authinfo {
686+
pub auth_keynumber: ::__u16,
687+
}
628688
}
629689

630690
s_no_extra_traits! {
@@ -1853,6 +1913,7 @@ pub const IPC_STAT: ::c_int = 2;
18531913
pub const IPC_INFO: ::c_int = 3;
18541914
pub const MSG_STAT: ::c_int = 11;
18551915
pub const MSG_INFO: ::c_int = 12;
1916+
pub const MSG_NOTIFICATION: ::c_int = 0x8000;
18561917

18571918
pub const MSG_NOERROR: ::c_int = 0o10000;
18581919
pub const MSG_EXCEPT: ::c_int = 0o20000;
@@ -3651,6 +3712,82 @@ pub const J1939_EE_INFO_RX_ABORT: ::c_int = 4;
36513712

36523713
pub const J1939_FILTER_MAX: ::c_int = 512;
36533714

3715+
// linux/sctp.h
3716+
pub const SCTP_FUTURE_ASSOC: ::c_int = 0;
3717+
pub const SCTP_CURRENT_ASSOC: ::c_int = 1;
3718+
pub const SCTP_ALL_ASSOC: ::c_int = 2;
3719+
pub const SCTP_RTOINFO: ::c_int = 0;
3720+
pub const SCTP_ASSOCINFO: ::c_int = 1;
3721+
pub const SCTP_INITMSG: ::c_int = 2;
3722+
pub const SCTP_NODELAY: ::c_int = 3;
3723+
pub const SCTP_AUTOCLOSE: ::c_int = 4;
3724+
pub const SCTP_SET_PEER_PRIMARY_ADDR: ::c_int = 5;
3725+
pub const SCTP_PRIMARY_ADDR: ::c_int = 6;
3726+
pub const SCTP_ADAPTATION_LAYER: ::c_int = 7;
3727+
pub const SCTP_DISABLE_FRAGMENTS: ::c_int = 8;
3728+
pub const SCTP_PEER_ADDR_PARAMS: ::c_int = 9;
3729+
pub const SCTP_DEFAULT_SEND_PARAM: ::c_int = 10;
3730+
pub const SCTP_EVENTS: ::c_int = 11;
3731+
pub const SCTP_I_WANT_MAPPED_V4_ADDR: ::c_int = 12;
3732+
pub const SCTP_MAXSEG: ::c_int = 13;
3733+
pub const SCTP_STATUS: ::c_int = 14;
3734+
pub const SCTP_GET_PEER_ADDR_INFO: ::c_int = 15;
3735+
pub const SCTP_DELAYED_ACK_TIME: ::c_int = 16;
3736+
pub const SCTP_DELAYED_ACK: ::c_int = SCTP_DELAYED_ACK_TIME;
3737+
pub const SCTP_DELAYED_SACK: ::c_int = SCTP_DELAYED_ACK_TIME;
3738+
pub const SCTP_CONTEXT: ::c_int = 17;
3739+
pub const SCTP_FRAGMENT_INTERLEAVE: ::c_int = 18;
3740+
pub const SCTP_PARTIAL_DELIVERY_POINT: ::c_int = 19;
3741+
pub const SCTP_MAX_BURST: ::c_int = 20;
3742+
pub const SCTP_AUTH_CHUNK: ::c_int = 21;
3743+
pub const SCTP_HMAC_IDENT: ::c_int = 22;
3744+
pub const SCTP_AUTH_KEY: ::c_int = 23;
3745+
pub const SCTP_AUTH_ACTIVE_KEY: ::c_int = 24;
3746+
pub const SCTP_AUTH_DELETE_KEY: ::c_int = 25;
3747+
pub const SCTP_PEER_AUTH_CHUNKS: ::c_int = 26;
3748+
pub const SCTP_LOCAL_AUTH_CHUNKS: ::c_int = 27;
3749+
pub const SCTP_GET_ASSOC_NUMBER: ::c_int = 28;
3750+
pub const SCTP_GET_ASSOC_ID_LIST: ::c_int = 29;
3751+
pub const SCTP_AUTO_ASCONF: ::c_int = 30;
3752+
pub const SCTP_PEER_ADDR_THLDS: ::c_int = 31;
3753+
pub const SCTP_RECVRCVINFO: ::c_int = 32;
3754+
pub const SCTP_RECVNXTINFO: ::c_int = 33;
3755+
pub const SCTP_DEFAULT_SNDINFO: ::c_int = 34;
3756+
pub const SCTP_AUTH_DEACTIVATE_KEY: ::c_int = 35;
3757+
pub const SCTP_REUSE_PORT: ::c_int = 36;
3758+
pub const SCTP_PEER_ADDR_THLDS_V2: ::c_int = 37;
3759+
pub const SCTP_PR_SCTP_NONE: ::c_int = 0x0000;
3760+
pub const SCTP_PR_SCTP_TTL: ::c_int = 0x0010;
3761+
pub const SCTP_PR_SCTP_RTX: ::c_int = 0x0020;
3762+
pub const SCTP_PR_SCTP_PRIO: ::c_int = 0x0030;
3763+
pub const SCTP_PR_SCTP_MAX: ::c_int = SCTP_PR_SCTP_PRIO;
3764+
pub const SCTP_PR_SCTP_MASK: ::c_int = 0x0030;
3765+
pub const SCTP_ENABLE_RESET_STREAM_REQ: ::c_int = 0x01;
3766+
pub const SCTP_ENABLE_RESET_ASSOC_REQ: ::c_int = 0x02;
3767+
pub const SCTP_ENABLE_CHANGE_ASSOC_REQ: ::c_int = 0x04;
3768+
pub const SCTP_ENABLE_STRRESET_MASK: ::c_int = 0x07;
3769+
pub const SCTP_STREAM_RESET_INCOMING: ::c_int = 0x01;
3770+
pub const SCTP_STREAM_RESET_OUTGOING: ::c_int = 0x02;
3771+
3772+
pub const SCTP_INIT: ::c_int = 0;
3773+
pub const SCTP_SNDRCV: ::c_int = 1;
3774+
pub const SCTP_SNDINFO: ::c_int = 2;
3775+
pub const SCTP_RCVINFO: ::c_int = 3;
3776+
pub const SCTP_NXTINFO: ::c_int = 4;
3777+
pub const SCTP_PRINFO: ::c_int = 5;
3778+
pub const SCTP_AUTHINFO: ::c_int = 6;
3779+
pub const SCTP_DSTADDRV4: ::c_int = 7;
3780+
pub const SCTP_DSTADDRV6: ::c_int = 8;
3781+
3782+
pub const SCTP_UNORDERED: ::c_int = 1 << 0;
3783+
pub const SCTP_ADDR_OVER: ::c_int = 1 << 1;
3784+
pub const SCTP_ABORT: ::c_int = 1 << 2;
3785+
pub const SCTP_SACK_IMMEDIATELY: ::c_int = 1 << 3;
3786+
pub const SCTP_SENDALL: ::c_int = 1 << 6;
3787+
pub const SCTP_PR_SCTP_ALL: ::c_int = 1 << 7;
3788+
pub const SCTP_NOTIFICATION: ::c_int = MSG_NOTIFICATION;
3789+
pub const SCTP_EOF: ::c_int = ::MSG_FIN;
3790+
36543791
f! {
36553792
pub fn NLA_ALIGN(len: ::c_int) -> ::c_int {
36563793
return ((len) + NLA_ALIGNTO - 1) & !(NLA_ALIGNTO - 1)
@@ -3726,6 +3863,20 @@ f! {
37263863
set1.bits == set2.bits
37273864
}
37283865

3866+
pub fn SCTP_PR_INDEX(policy: ::c_int) -> ::c_int {
3867+
policy >> 4 - 1
3868+
}
3869+
3870+
pub fn SCTP_PR_POLICY(policy: ::c_int) -> ::c_int {
3871+
policy & SCTP_PR_SCTP_MASK
3872+
}
3873+
3874+
pub fn SCTP_PR_SET_POLICY(flags: &mut ::c_int, policy: ::c_int) -> () {
3875+
*flags &= !SCTP_PR_SCTP_MASK;
3876+
*flags |= policy;
3877+
()
3878+
}
3879+
37293880
pub fn major(dev: ::dev_t) -> ::c_uint {
37303881
let mut major = 0;
37313882
major |= (dev & 0x00000000000fff00) >> 8;
@@ -3792,6 +3943,18 @@ safe_f! {
37923943
dev |= (minor & 0xffffff00) << 12;
37933944
dev
37943945
}
3946+
3947+
pub {const} fn SCTP_PR_TTL_ENABLED(policy: ::c_int) -> bool {
3948+
policy == SCTP_PR_SCTP_TTL
3949+
}
3950+
3951+
pub {const} fn SCTP_PR_RTX_ENABLED(policy: ::c_int) -> bool {
3952+
policy == SCTP_PR_SCTP_RTX
3953+
}
3954+
3955+
pub {const} fn SCTP_PR_PRIO_ENABLED(policy: ::c_int) -> bool {
3956+
policy == SCTP_PR_SCTP_PRIO
3957+
}
37953958
}
37963959

37973960
cfg_if! {

0 commit comments

Comments
 (0)