From 62aaa249f3f14a5714bfcacd45290a359ec009d9 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sun, 29 Jan 2023 16:11:14 +0000 Subject: [PATCH] linux starting adding sctp support --- libc-test/build.rs | 3 +- libc-test/semver/linux.txt | 73 ++++++++++++++ src/unix/linux_like/linux/mod.rs | 162 +++++++++++++++++++++++++++++++ 3 files changed, 237 insertions(+), 1 deletion(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index 24dc7f8c3d663..2932b44f103f8 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -3226,8 +3226,8 @@ fn test_linux(target: &str) { "linux/reboot.h", "linux/rtnetlink.h", "linux/sched.h", + "linux/sctp.h", "linux/seccomp.h", - "linux/sched.h", "linux/sock_diag.h", "linux/sockios.h", "linux/uinput.h", @@ -3648,6 +3648,7 @@ fn test_linux(target: &str) { | "IFLA_TSO_MAX_SEGS" // linux v5.18+ | "IFLA_ALLMULTI" // linux v6.0+ => true, + "SCTP_FUTURE_ASSOC" | "SCTP_CURRENT_ASSOC" | "SCTP_ALL_ASSOC" | "SCTP_PEER_ADDR_THLDS_V2" => true, _ => false, } diff --git a/libc-test/semver/linux.txt b/libc-test/semver/linux.txt index 2907fc09e219f..65fcaaddec4a3 100644 --- a/libc-test/semver/linux.txt +++ b/libc-test/semver/linux.txt @@ -1324,6 +1324,7 @@ MSG_INFO MSG_MORE MSG_NOERROR MSG_NOSIGNAL +MSG_NOTIFICATION MSG_RST MSG_STAT MSG_SYN @@ -2145,6 +2146,70 @@ SCM_J1939_ERRQUEUE SCM_J1939_PRIO SCM_TIMESTAMP SCM_TIMESTAMPING +SCTP_ABORT +SCTP_ADDR_OVER +SCTP_ALL_ASSOC +SCTP_ASSOCINFO +SCTP_AUTH_CHUNK +SCTP_AUTH_ACTIVE_KEY +SCTP_AUTH_DEACTIVATE_KEY +SCTP_AUTH_DELETE_KEY +SCTP_AUTH_KEY +SCTP_AUTO_ASCONF +SCTP_AUTOCLOSE +SCTP_CONTEXT +SCTP_CURRENT_ASSOC +SCTP_DELAYED_ACK +SCTP_DELAYED_ACK_TIME +SCTP_DELAYED_SACK +SCTP_DEFAULT_SEND_PARAM +SCTP_DEFAULT_SNDINFO +SCTP_ENABLE_CHANGE_ASSOC_REQ +SCTP_ENABLE_RESET_ASSOC_REQ +SCTP_ENABLE_RESET_STREAM_REQ +SCTP_ENABLE_STRRESET_MASK +SCTP_EOF +SCTP_EVENTS +SCTP_FRAGMENT_INTERLEAVE +SCTP_FUTURE_ASSOC +SCTP_GET_ASSOC_ID_LIST +SCTP_GET_ASSOC_NUMBER +SCTP_GET_PEER_ADDR_INFO +SCTP_HMAC_IDENT +SCTP_I_WANT_MAPPED_V4_ADDR +SCTP_INIT +SCTP_INITMSG +SCTP_LOCAL_AUTH_CHUNKS +SCTP_MAX_BURST +SCTP_MAXSEG +SCTP_NODELAY +SCTP_NOTIFICATION +SCTP_NXTINFO +SCTP_PARTIAL_DELIVERY_POINT +SCTP_PEER_ADDR_PARAMS +SCTP_PEER_ADDR_THLDS +SCTP_PEER_ADDR_THLDS_V2 +SCTP_PEER_AUTH_CHUNKS +SCTP_PR_SCTP_ALL +SCTP_PR_SCTP_NONE +SCTP_PR_SCTP_MASK +SCTP_PR_SCTP_MAX +SCTP_PR_SCTP_PRIO +SCTP_PR_SCTP_RTX +SCTP_PR_SCTP_TTL +SCTP_PRIMARY_ADDR +SCTP_RECVNXTINFO +SCTP_RECVRCVINFO +SCTP_REUSE_PORT +SCTP_RTOINFO +SCTP_SACK_IMMEDIATELY +SCTP_SENDALL +SCTP_SET_PEER_PRIMARY_ADDR +SCTP_SNDRCV +SCTP_STATUS +SCTP_STREAM_RESET_INCOMING +SCTP_STREAM_RESET_OUTGOING +SCTP_UNORDERED SECCOMP_FILTER_FLAG_LOG SECCOMP_FILTER_FLAG_SPEC_ALLOW SECCOMP_FILTER_FLAG_TSYNC @@ -3233,6 +3298,14 @@ sched_rr_get_interval sched_setaffinity sched_setparam sched_setscheduler +sctp_assoc_t +sctp_authinfo +sctp_initmsg +sctp_nxtinfo +sctp_prinfo +sctp_rcvinfo +sctp_sndinfo +sctp_sndrcvinfo seccomp_data seed48 seekdir diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index 3481dcc044c50..afa4db85dc90a 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -48,6 +48,9 @@ pub type name_t = u64; pub type iconv_t = *mut ::c_void; +// linux/sctp.h +pub type sctp_assoc_t = ::__s32; + #[cfg_attr(feature = "extra_traits", derive(Debug))] pub enum fpos64_t {} // FIXME: fill this out with a struct impl ::Copy for fpos64_t {} @@ -625,6 +628,62 @@ s! { pub flag: *mut ::c_int, pub val: ::c_int, } + + // linux/sctp.h + pub struct sctp_initmsg { + pub sinit_num_ostreams: ::__u16, + pub sinit_max_instreams: ::__u16, + pub sinit_max_attempts: ::__u16, + pub sinit_max_init_timeo: ::__u16, + } + + pub struct sctp_sndrcvinfo { + pub sinfo_stream: ::__u16, + pub sinfo_ssn: ::__u16, + pub sinfo_flags: ::__u16, + pub sinfo_ppid: ::__u32, + pub sinfo_context: ::__u32, + pub sinfo_timetolive: ::__u32, + pub sinfo_tsn: ::__u32, + pub sinfo_cumtsn: ::__u32, + pub sinfo_assoc_id: ::sctp_assoc_t, + } + + pub struct sctp_sndinfo { + pub snd_sid: ::__u16, + pub snd_flags: ::__u16, + pub snd_ppid: ::__u32, + pub snd_context: ::__u32, + pub snd_assoc_id: ::sctp_assoc_t, + } + + pub struct sctp_rcvinfo { + pub rcv_sid: ::__u16, + pub rcv_ssn: ::__u16, + pub rcv_flags: ::__u16, + pub rcv_ppid: ::__u32, + pub rcv_tsn: ::__u32, + pub rcv_cumtsn: ::__u32, + pub rcv_context: ::__u32, + pub rcv_assoc_id: ::sctp_assoc_t, + } + + pub struct sctp_nxtinfo { + pub nxt_sid: ::__u16, + pub nxt_flags: ::__u16, + pub nxt_ppid: ::__u32, + pub nxt_length: ::__u32, + pub nxt_assoc_id: ::sctp_assoc_t, + } + + pub struct sctp_prinfo { + pub pr_policy: ::__u16, + pub pr_value: ::__u32, + } + + pub struct sctp_authinfo { + pub auth_keynumber: ::__u16, + } } s_no_extra_traits! { @@ -1853,6 +1912,7 @@ pub const IPC_STAT: ::c_int = 2; pub const IPC_INFO: ::c_int = 3; pub const MSG_STAT: ::c_int = 11; pub const MSG_INFO: ::c_int = 12; +pub const MSG_NOTIFICATION: ::c_int = 0x8000; pub const MSG_NOERROR: ::c_int = 0o10000; pub const MSG_EXCEPT: ::c_int = 0o20000; @@ -3630,6 +3690,82 @@ pub const J1939_EE_INFO_RX_ABORT: ::c_int = 4; pub const J1939_FILTER_MAX: ::c_int = 512; +// linux/sctp.h +pub const SCTP_FUTURE_ASSOC: ::c_int = 0; +pub const SCTP_CURRENT_ASSOC: ::c_int = 1; +pub const SCTP_ALL_ASSOC: ::c_int = 2; +pub const SCTP_RTOINFO: ::c_int = 0; +pub const SCTP_ASSOCINFO: ::c_int = 1; +pub const SCTP_INITMSG: ::c_int = 2; +pub const SCTP_NODELAY: ::c_int = 3; +pub const SCTP_AUTOCLOSE: ::c_int = 4; +pub const SCTP_SET_PEER_PRIMARY_ADDR: ::c_int = 5; +pub const SCTP_PRIMARY_ADDR: ::c_int = 6; +pub const SCTP_ADAPTATION_LAYER: ::c_int = 7; +pub const SCTP_DISABLE_FRAGMENTS: ::c_int = 8; +pub const SCTP_PEER_ADDR_PARAMS: ::c_int = 9; +pub const SCTP_DEFAULT_SEND_PARAM: ::c_int = 10; +pub const SCTP_EVENTS: ::c_int = 11; +pub const SCTP_I_WANT_MAPPED_V4_ADDR: ::c_int = 12; +pub const SCTP_MAXSEG: ::c_int = 13; +pub const SCTP_STATUS: ::c_int = 14; +pub const SCTP_GET_PEER_ADDR_INFO: ::c_int = 15; +pub const SCTP_DELAYED_ACK_TIME: ::c_int = 16; +pub const SCTP_DELAYED_ACK: ::c_int = SCTP_DELAYED_ACK_TIME; +pub const SCTP_DELAYED_SACK: ::c_int = SCTP_DELAYED_ACK_TIME; +pub const SCTP_CONTEXT: ::c_int = 17; +pub const SCTP_FRAGMENT_INTERLEAVE: ::c_int = 18; +pub const SCTP_PARTIAL_DELIVERY_POINT: ::c_int = 19; +pub const SCTP_MAX_BURST: ::c_int = 20; +pub const SCTP_AUTH_CHUNK: ::c_int = 21; +pub const SCTP_HMAC_IDENT: ::c_int = 22; +pub const SCTP_AUTH_KEY: ::c_int = 23; +pub const SCTP_AUTH_ACTIVE_KEY: ::c_int = 24; +pub const SCTP_AUTH_DELETE_KEY: ::c_int = 25; +pub const SCTP_PEER_AUTH_CHUNKS: ::c_int = 26; +pub const SCTP_LOCAL_AUTH_CHUNKS: ::c_int = 27; +pub const SCTP_GET_ASSOC_NUMBER: ::c_int = 28; +pub const SCTP_GET_ASSOC_ID_LIST: ::c_int = 29; +pub const SCTP_AUTO_ASCONF: ::c_int = 30; +pub const SCTP_PEER_ADDR_THLDS: ::c_int = 31; +pub const SCTP_RECVRCVINFO: ::c_int = 32; +pub const SCTP_RECVNXTINFO: ::c_int = 33; +pub const SCTP_DEFAULT_SNDINFO: ::c_int = 34; +pub const SCTP_AUTH_DEACTIVATE_KEY: ::c_int = 35; +pub const SCTP_REUSE_PORT: ::c_int = 36; +pub const SCTP_PEER_ADDR_THLDS_V2: ::c_int = 37; +pub const SCTP_PR_SCTP_NONE: ::c_int = 0x0000; +pub const SCTP_PR_SCTP_TTL: ::c_int = 0x0010; +pub const SCTP_PR_SCTP_RTX: ::c_int = 0x0020; +pub const SCTP_PR_SCTP_PRIO: ::c_int = 0x0030; +pub const SCTP_PR_SCTP_MAX: ::c_int = SCTP_PR_SCTP_PRIO; +pub const SCTP_PR_SCTP_MASK: ::c_int = 0x0030; +pub const SCTP_ENABLE_RESET_STREAM_REQ: ::c_int = 0x01; +pub const SCTP_ENABLE_RESET_ASSOC_REQ: ::c_int = 0x02; +pub const SCTP_ENABLE_CHANGE_ASSOC_REQ: ::c_int = 0x04; +pub const SCTP_ENABLE_STRRESET_MASK: ::c_int = 0x07; +pub const SCTP_STREAM_RESET_INCOMING: ::c_int = 0x01; +pub const SCTP_STREAM_RESET_OUTGOING: ::c_int = 0x02; + +pub const SCTP_INIT: ::c_int = 0; +pub const SCTP_SNDRCV: ::c_int = 1; +pub const SCTP_SNDINFO: ::c_int = 2; +pub const SCTP_RCVINFO: ::c_int = 3; +pub const SCTP_NXTINFO: ::c_int = 4; +pub const SCTP_PRINFO: ::c_int = 5; +pub const SCTP_AUTHINFO: ::c_int = 6; +pub const SCTP_DSTADDRV4: ::c_int = 7; +pub const SCTP_DSTADDRV6: ::c_int = 8; + +pub const SCTP_UNORDERED: ::c_int = 1 << 0; +pub const SCTP_ADDR_OVER: ::c_int = 1 << 1; +pub const SCTP_ABORT: ::c_int = 1 << 2; +pub const SCTP_SACK_IMMEDIATELY: ::c_int = 1 << 3; +pub const SCTP_SENDALL: ::c_int = 1 << 6; +pub const SCTP_PR_SCTP_ALL: ::c_int = 1 << 7; +pub const SCTP_NOTIFICATION: ::c_int = MSG_NOTIFICATION; +pub const SCTP_EOF: ::c_int = ::MSG_FIN; + f! { pub fn NLA_ALIGN(len: ::c_int) -> ::c_int { return ((len) + NLA_ALIGNTO - 1) & !(NLA_ALIGNTO - 1) @@ -3705,6 +3841,20 @@ f! { set1.bits == set2.bits } + pub fn SCTP_PR_INDEX(policy: ::c_int) -> ::c_int { + policy >> 4 - 1 + } + + pub fn SCTP_PR_POLICY(policy: ::c_int) -> ::c_int { + policy & SCTP_PR_SCTP_MASK + } + + pub fn SCTP_PR_SET_POLICY(flags: &mut ::c_int, policy: ::c_int) -> () { + *flags &= !SCTP_PR_SCTP_MASK; + *flags |= policy; + () + } + pub fn major(dev: ::dev_t) -> ::c_uint { let mut major = 0; major |= (dev & 0x00000000000fff00) >> 8; @@ -3771,6 +3921,18 @@ safe_f! { dev |= (minor & 0xffffff00) << 12; dev } + + pub {const} fn SCTP_PR_TTL_ENABLED(policy: ::c_int) -> bool { + policy == SCTP_PR_SCTP_TTL + } + + pub {const} fn SCTP_PR_RTX_ENABLED(policy: ::c_int) -> bool { + policy == SCTP_PR_SCTP_RTX + } + + pub {const} fn SCTP_PR_PRIO_ENABLED(policy: ::c_int) -> bool { + policy == SCTP_PR_SCTP_PRIO + } } cfg_if! {