Skip to content

Commit e078dd6

Browse files
committed
Auto merge of #3095 - devnexen:linux_sctp1, r=JohnTitor
linux starting adding sctp support
2 parents 38b9a40 + 78cc6ab commit e078dd6

File tree

3 files changed

+237
-1
lines changed

3 files changed

+237
-1
lines changed

libc-test/build.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3229,8 +3229,8 @@ fn test_linux(target: &str) {
32293229
"linux/reboot.h",
32303230
"linux/rtnetlink.h",
32313231
"linux/sched.h",
3232+
"linux/sctp.h",
32323233
"linux/seccomp.h",
3233-
"linux/sched.h",
32343234
"linux/sock_diag.h",
32353235
"linux/sockios.h",
32363236
"linux/uinput.h",
@@ -3651,6 +3651,7 @@ fn test_linux(target: &str) {
36513651
| "IFLA_TSO_MAX_SEGS" // linux v5.18+
36523652
| "IFLA_ALLMULTI" // linux v6.0+
36533653
=> true,
3654+
"SCTP_FUTURE_ASSOC" | "SCTP_CURRENT_ASSOC" | "SCTP_ALL_ASSOC" | "CTP_PEER_ADDR_THLDS_V2" => true,
36543655

36553656
_ => false,
36563657
}

libc-test/semver/linux.txt

+73
Original file line numberDiff line numberDiff line change
@@ -1324,6 +1324,7 @@ MSG_INFO
13241324
MSG_MORE
13251325
MSG_NOERROR
13261326
MSG_NOSIGNAL
1327+
MSG_NOTIFICATION
13271328
MSG_RST
13281329
MSG_STAT
13291330
MSG_SYN
@@ -2145,6 +2146,70 @@ SCM_J1939_ERRQUEUE
21452146
SCM_J1939_PRIO
21462147
SCM_TIMESTAMP
21472148
SCM_TIMESTAMPING
2149+
SCTP_ABORT
2150+
SCTP_ADDR_OVER
2151+
SCTP_ALL_ASSOC
2152+
SCTP_ASSOCINFO
2153+
SCTP_AUTH_CHUNK
2154+
SCTP_AUTH_ACTIVE_KEY
2155+
SCTP_AUTH_DEACTIVATE_KEY
2156+
SCTP_AUTH_DELETE_KEY
2157+
SCTP_AUTH_KEY
2158+
SCTP_AUTO_ASCONF
2159+
SCTP_AUTOCLOSE
2160+
SCTP_CONTEXT
2161+
SCTP_CURRENT_ASSOC
2162+
SCTP_DELAYED_ACK
2163+
SCTP_DELAYED_ACK_TIME
2164+
SCTP_DELAYED_SACK
2165+
SCTP_DEFAULT_SEND_PARAM
2166+
SCTP_DEFAULT_SNDINFO
2167+
SCTP_ENABLE_CHANGE_ASSOC_REQ
2168+
SCTP_ENABLE_RESET_ASSOC_REQ
2169+
SCTP_ENABLE_RESET_STREAM_REQ
2170+
SCTP_ENABLE_STRRESET_MASK
2171+
SCTP_EOF
2172+
SCTP_EVENTS
2173+
SCTP_FRAGMENT_INTERLEAVE
2174+
SCTP_FUTURE_ASSOC
2175+
SCTP_GET_ASSOC_ID_LIST
2176+
SCTP_GET_ASSOC_NUMBER
2177+
SCTP_GET_PEER_ADDR_INFO
2178+
SCTP_HMAC_IDENT
2179+
SCTP_I_WANT_MAPPED_V4_ADDR
2180+
SCTP_INIT
2181+
SCTP_INITMSG
2182+
SCTP_LOCAL_AUTH_CHUNKS
2183+
SCTP_MAX_BURST
2184+
SCTP_MAXSEG
2185+
SCTP_NODELAY
2186+
SCTP_NOTIFICATION
2187+
SCTP_NXTINFO
2188+
SCTP_PARTIAL_DELIVERY_POINT
2189+
SCTP_PEER_ADDR_PARAMS
2190+
SCTP_PEER_ADDR_THLDS
2191+
SCTP_PEER_ADDR_THLDS_V2
2192+
SCTP_PEER_AUTH_CHUNKS
2193+
SCTP_PR_SCTP_ALL
2194+
SCTP_PR_SCTP_NONE
2195+
SCTP_PR_SCTP_MASK
2196+
SCTP_PR_SCTP_MAX
2197+
SCTP_PR_SCTP_PRIO
2198+
SCTP_PR_SCTP_RTX
2199+
SCTP_PR_SCTP_TTL
2200+
SCTP_PRIMARY_ADDR
2201+
SCTP_RECVNXTINFO
2202+
SCTP_RECVRCVINFO
2203+
SCTP_REUSE_PORT
2204+
SCTP_RTOINFO
2205+
SCTP_SACK_IMMEDIATELY
2206+
SCTP_SENDALL
2207+
SCTP_SET_PEER_PRIMARY_ADDR
2208+
SCTP_SNDRCV
2209+
SCTP_STATUS
2210+
SCTP_STREAM_RESET_INCOMING
2211+
SCTP_STREAM_RESET_OUTGOING
2212+
SCTP_UNORDERED
21482213
SECCOMP_FILTER_FLAG_LOG
21492214
SECCOMP_FILTER_FLAG_SPEC_ALLOW
21502215
SECCOMP_FILTER_FLAG_TSYNC
@@ -3233,6 +3298,14 @@ sched_rr_get_interval
32333298
sched_setaffinity
32343299
sched_setparam
32353300
sched_setscheduler
3301+
sctp_assoc_t
3302+
sctp_authinfo
3303+
sctp_initmsg
3304+
sctp_nxtinfo
3305+
sctp_prinfo
3306+
sctp_rcvinfo
3307+
sctp_sndinfo
3308+
sctp_sndrcvinfo
32363309
seccomp_data
32373310
seed48
32383311
seekdir

src/unix/linux_like/linux/mod.rs

+162
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,62 @@ s! {
625628
pub flag: *mut ::c_int,
626629
pub val: ::c_int,
627630
}
631+
632+
// linux/sctp.h
633+
pub struct sctp_initmsg {
634+
pub sinit_num_ostreams: ::__u16,
635+
pub sinit_max_instreams: ::__u16,
636+
pub sinit_max_attempts: ::__u16,
637+
pub sinit_max_init_timeo: ::__u16,
638+
}
639+
640+
pub struct sctp_sndrcvinfo {
641+
pub sinfo_stream: ::__u16,
642+
pub sinfo_ssn: ::__u16,
643+
pub sinfo_flags: ::__u16,
644+
pub sinfo_ppid: ::__u32,
645+
pub sinfo_context: ::__u32,
646+
pub sinfo_timetolive: ::__u32,
647+
pub sinfo_tsn: ::__u32,
648+
pub sinfo_cumtsn: ::__u32,
649+
pub sinfo_assoc_id: ::sctp_assoc_t,
650+
}
651+
652+
pub struct sctp_sndinfo {
653+
pub snd_sid: ::__u16,
654+
pub snd_flags: ::__u16,
655+
pub snd_ppid: ::__u32,
656+
pub snd_context: ::__u32,
657+
pub snd_assoc_id: ::sctp_assoc_t,
658+
}
659+
660+
pub struct sctp_rcvinfo {
661+
pub rcv_sid: ::__u16,
662+
pub rcv_ssn: ::__u16,
663+
pub rcv_flags: ::__u16,
664+
pub rcv_ppid: ::__u32,
665+
pub rcv_tsn: ::__u32,
666+
pub rcv_cumtsn: ::__u32,
667+
pub rcv_context: ::__u32,
668+
pub rcv_assoc_id: ::sctp_assoc_t,
669+
}
670+
671+
pub struct sctp_nxtinfo {
672+
pub nxt_sid: ::__u16,
673+
pub nxt_flags: ::__u16,
674+
pub nxt_ppid: ::__u32,
675+
pub nxt_length: ::__u32,
676+
pub nxt_assoc_id: ::sctp_assoc_t,
677+
}
678+
679+
pub struct sctp_prinfo {
680+
pub pr_policy: ::__u16,
681+
pub pr_value: ::__u32,
682+
}
683+
684+
pub struct sctp_authinfo {
685+
pub auth_keynumber: ::__u16,
686+
}
628687
}
629688

630689
s_no_extra_traits! {
@@ -1853,6 +1912,7 @@ pub const IPC_STAT: ::c_int = 2;
18531912
pub const IPC_INFO: ::c_int = 3;
18541913
pub const MSG_STAT: ::c_int = 11;
18551914
pub const MSG_INFO: ::c_int = 12;
1915+
pub const MSG_NOTIFICATION: ::c_int = 0x8000;
18561916

18571917
pub const MSG_NOERROR: ::c_int = 0o10000;
18581918
pub const MSG_EXCEPT: ::c_int = 0o20000;
@@ -3630,6 +3690,82 @@ pub const J1939_EE_INFO_RX_ABORT: ::c_int = 4;
36303690

36313691
pub const J1939_FILTER_MAX: ::c_int = 512;
36323692

3693+
// linux/sctp.h
3694+
pub const SCTP_FUTURE_ASSOC: ::c_int = 0;
3695+
pub const SCTP_CURRENT_ASSOC: ::c_int = 1;
3696+
pub const SCTP_ALL_ASSOC: ::c_int = 2;
3697+
pub const SCTP_RTOINFO: ::c_int = 0;
3698+
pub const SCTP_ASSOCINFO: ::c_int = 1;
3699+
pub const SCTP_INITMSG: ::c_int = 2;
3700+
pub const SCTP_NODELAY: ::c_int = 3;
3701+
pub const SCTP_AUTOCLOSE: ::c_int = 4;
3702+
pub const SCTP_SET_PEER_PRIMARY_ADDR: ::c_int = 5;
3703+
pub const SCTP_PRIMARY_ADDR: ::c_int = 6;
3704+
pub const SCTP_ADAPTATION_LAYER: ::c_int = 7;
3705+
pub const SCTP_DISABLE_FRAGMENTS: ::c_int = 8;
3706+
pub const SCTP_PEER_ADDR_PARAMS: ::c_int = 9;
3707+
pub const SCTP_DEFAULT_SEND_PARAM: ::c_int = 10;
3708+
pub const SCTP_EVENTS: ::c_int = 11;
3709+
pub const SCTP_I_WANT_MAPPED_V4_ADDR: ::c_int = 12;
3710+
pub const SCTP_MAXSEG: ::c_int = 13;
3711+
pub const SCTP_STATUS: ::c_int = 14;
3712+
pub const SCTP_GET_PEER_ADDR_INFO: ::c_int = 15;
3713+
pub const SCTP_DELAYED_ACK_TIME: ::c_int = 16;
3714+
pub const SCTP_DELAYED_ACK: ::c_int = SCTP_DELAYED_ACK_TIME;
3715+
pub const SCTP_DELAYED_SACK: ::c_int = SCTP_DELAYED_ACK_TIME;
3716+
pub const SCTP_CONTEXT: ::c_int = 17;
3717+
pub const SCTP_FRAGMENT_INTERLEAVE: ::c_int = 18;
3718+
pub const SCTP_PARTIAL_DELIVERY_POINT: ::c_int = 19;
3719+
pub const SCTP_MAX_BURST: ::c_int = 20;
3720+
pub const SCTP_AUTH_CHUNK: ::c_int = 21;
3721+
pub const SCTP_HMAC_IDENT: ::c_int = 22;
3722+
pub const SCTP_AUTH_KEY: ::c_int = 23;
3723+
pub const SCTP_AUTH_ACTIVE_KEY: ::c_int = 24;
3724+
pub const SCTP_AUTH_DELETE_KEY: ::c_int = 25;
3725+
pub const SCTP_PEER_AUTH_CHUNKS: ::c_int = 26;
3726+
pub const SCTP_LOCAL_AUTH_CHUNKS: ::c_int = 27;
3727+
pub const SCTP_GET_ASSOC_NUMBER: ::c_int = 28;
3728+
pub const SCTP_GET_ASSOC_ID_LIST: ::c_int = 29;
3729+
pub const SCTP_AUTO_ASCONF: ::c_int = 30;
3730+
pub const SCTP_PEER_ADDR_THLDS: ::c_int = 31;
3731+
pub const SCTP_RECVRCVINFO: ::c_int = 32;
3732+
pub const SCTP_RECVNXTINFO: ::c_int = 33;
3733+
pub const SCTP_DEFAULT_SNDINFO: ::c_int = 34;
3734+
pub const SCTP_AUTH_DEACTIVATE_KEY: ::c_int = 35;
3735+
pub const SCTP_REUSE_PORT: ::c_int = 36;
3736+
pub const SCTP_PEER_ADDR_THLDS_V2: ::c_int = 37;
3737+
pub const SCTP_PR_SCTP_NONE: ::c_int = 0x0000;
3738+
pub const SCTP_PR_SCTP_TTL: ::c_int = 0x0010;
3739+
pub const SCTP_PR_SCTP_RTX: ::c_int = 0x0020;
3740+
pub const SCTP_PR_SCTP_PRIO: ::c_int = 0x0030;
3741+
pub const SCTP_PR_SCTP_MAX: ::c_int = SCTP_PR_SCTP_PRIO;
3742+
pub const SCTP_PR_SCTP_MASK: ::c_int = 0x0030;
3743+
pub const SCTP_ENABLE_RESET_STREAM_REQ: ::c_int = 0x01;
3744+
pub const SCTP_ENABLE_RESET_ASSOC_REQ: ::c_int = 0x02;
3745+
pub const SCTP_ENABLE_CHANGE_ASSOC_REQ: ::c_int = 0x04;
3746+
pub const SCTP_ENABLE_STRRESET_MASK: ::c_int = 0x07;
3747+
pub const SCTP_STREAM_RESET_INCOMING: ::c_int = 0x01;
3748+
pub const SCTP_STREAM_RESET_OUTGOING: ::c_int = 0x02;
3749+
3750+
pub const SCTP_INIT: ::c_int = 0;
3751+
pub const SCTP_SNDRCV: ::c_int = 1;
3752+
pub const SCTP_SNDINFO: ::c_int = 2;
3753+
pub const SCTP_RCVINFO: ::c_int = 3;
3754+
pub const SCTP_NXTINFO: ::c_int = 4;
3755+
pub const SCTP_PRINFO: ::c_int = 5;
3756+
pub const SCTP_AUTHINFO: ::c_int = 6;
3757+
pub const SCTP_DSTADDRV4: ::c_int = 7;
3758+
pub const SCTP_DSTADDRV6: ::c_int = 8;
3759+
3760+
pub const SCTP_UNORDERED: ::c_int = 1 << 0;
3761+
pub const SCTP_ADDR_OVER: ::c_int = 1 << 1;
3762+
pub const SCTP_ABORT: ::c_int = 1 << 2;
3763+
pub const SCTP_SACK_IMMEDIATELY: ::c_int = 1 << 3;
3764+
pub const SCTP_SENDALL: ::c_int = 1 << 6;
3765+
pub const SCTP_PR_SCTP_ALL: ::c_int = 1 << 7;
3766+
pub const SCTP_NOTIFICATION: ::c_int = MSG_NOTIFICATION;
3767+
pub const SCTP_EOF: ::c_int = ::MSG_FIN;
3768+
36333769
f! {
36343770
pub fn NLA_ALIGN(len: ::c_int) -> ::c_int {
36353771
return ((len) + NLA_ALIGNTO - 1) & !(NLA_ALIGNTO - 1)
@@ -3705,6 +3841,20 @@ f! {
37053841
set1.bits == set2.bits
37063842
}
37073843

3844+
pub fn SCTP_PR_INDEX(policy: ::c_int) -> ::c_int {
3845+
policy >> 4 - 1
3846+
}
3847+
3848+
pub fn SCTP_PR_POLICY(policy: ::c_int) -> ::c_int {
3849+
policy & SCTP_PR_SCTP_MASK
3850+
}
3851+
3852+
pub fn SCTP_PR_SET_POLICY(flags: &mut ::c_int, policy: ::c_int) -> () {
3853+
*flags &= !SCTP_PR_SCTP_MASK;
3854+
*flags |= policy;
3855+
()
3856+
}
3857+
37083858
pub fn major(dev: ::dev_t) -> ::c_uint {
37093859
let mut major = 0;
37103860
major |= (dev & 0x00000000000fff00) >> 8;
@@ -3771,6 +3921,18 @@ safe_f! {
37713921
dev |= (minor & 0xffffff00) << 12;
37723922
dev
37733923
}
3924+
3925+
pub {const} fn SCTP_PR_TTL_ENABLED(policy: ::c_int) -> bool {
3926+
policy == SCTP_PR_SCTP_TTL
3927+
}
3928+
3929+
pub {const} fn SCTP_PR_RTX_ENABLED(policy: ::c_int) -> bool {
3930+
policy == SCTP_PR_SCTP_RTX
3931+
}
3932+
3933+
pub {const} fn SCTP_PR_PRIO_ENABLED(policy: ::c_int) -> bool {
3934+
policy == SCTP_PR_SCTP_PRIO
3935+
}
37743936
}
37753937

37763938
cfg_if! {

0 commit comments

Comments
 (0)