diff --git a/libc-test/build.rs b/libc-test/build.rs index e0bd795bb0e5..5446a3002294 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -102,6 +102,9 @@ fn do_ctest() { cfg.header("net/route.h"); cfg.header("net/if_arp.h"); } + if linux || android { + cfg.header("linux/if_alg.h"); + } cfg.header("netdb.h"); cfg.header("netinet/in.h"); cfg.header("netinet/ip.h"); @@ -627,6 +630,9 @@ fn do_ctest() { | "RENAME_NOREPLACE" | "RENAME_EXCHANGE" | "RENAME_WHITEOUT" + // ALG_SET_AEAD_* constants are available starting from kernel 3.19 + | "ALG_SET_AEAD_ASSOCLEN" + | "ALG_SET_AEAD_AUTHSIZE" if musl => { true diff --git a/src/unix/notbsd/android/mod.rs b/src/unix/notbsd/android/mod.rs index 2213b75b663e..e8f7007b476e 100644 --- a/src/unix/notbsd/android/mod.rs +++ b/src/unix/notbsd/android/mod.rs @@ -238,6 +238,19 @@ s_no_extra_traits!{ pub ut_addr_v6: [::int32_t; 4], unused: [::c_char; 20], } + + pub struct sockaddr_alg { + pub salg_family: ::sa_family_t, + pub salg_type: [::c_uchar; 14], + pub salg_feat: u32, + pub salg_mask: u32, + pub salg_name: [::c_uchar; 64], + } + + pub struct af_alg_iv { + pub ivlen: u32, + pub iv: [::c_uchar; 0], + } } cfg_if! { @@ -451,6 +464,81 @@ cfg_if! { self.unused.hash(state); } } + + impl PartialEq for sockaddr_alg { + fn eq(&self, other: &sockaddr_alg) -> bool { + self.salg_family == other.salg_family + && self + .salg_type + .iter() + .zip(other.salg_type.iter()) + .all(|(a, b)| a == b) + && self.salg_feat == other.salg_feat + && self.salg_mask == other.salg_mask + && self + .salg_name + .iter() + .zip(other.salg_name.iter()) + .all(|(a, b)| a == b) + } + } + + impl Eq for sockaddr_alg {} + + impl ::fmt::Debug for sockaddr_alg { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("sockaddr_alg") + .field("salg_family", &self.salg_family) + .field("salg_type", &self.salg_type) + .field("salg_feat", &self.salg_feat) + .field("salg_mask", &self.salg_mask) + .field("salg_name", &&self.salg_name[..]) + .finish() + } + } + + impl ::hash::Hash for sockaddr_alg { + fn hash(&self, state: &mut H) { + self.salg_family.hash(state); + self.salg_type.hash(state); + self.salg_feat.hash(state); + self.salg_mask.hash(state); + self.salg_name.hash(state); + } + } + + impl af_alg_iv { + fn as_slice(&self) -> &[u8] { + unsafe { + ::core::slice::from_raw_parts( + self.iv.as_ptr(), + self.ivlen as usize + ) + } + } + } + + impl PartialEq for af_alg_iv { + fn eq(&self, other: &af_alg_iv) -> bool { + *self.as_slice() == *other.as_slice() + } + } + + impl Eq for af_alg_iv {} + + impl ::fmt::Debug for af_alg_iv { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("af_alg_iv") + .field("iv", &self.as_slice()) + .finish() + } + } + + impl ::hash::Hash for af_alg_iv { + fn hash(&self, state: &mut H) { + self.as_slice().hash(state); + } + } } } @@ -1690,6 +1778,16 @@ pub const MODULE_INIT_IGNORE_VERMAGIC: ::c_uint = 0x0002; // Similarity to Linux it's not used but defined for compatibility. pub const ENOATTR: ::c_int = ::ENODATA; +// linux/if_alg.h +pub const ALG_SET_KEY: ::c_int = 1; +pub const ALG_SET_IV: ::c_int = 2; +pub const ALG_SET_OP: ::c_int = 3; +pub const ALG_SET_AEAD_ASSOCLEN: ::c_int = 4; +pub const ALG_SET_AEAD_AUTHSIZE: ::c_int = 5; + +pub const ALG_OP_DECRYPT: ::c_int = 0; +pub const ALG_OP_ENCRYPT: ::c_int = 1; + f! { pub fn CMSG_NXTHDR(mhdr: *const msghdr, cmsg: *const cmsghdr) -> *mut cmsghdr { diff --git a/src/unix/notbsd/linux/mod.rs b/src/unix/notbsd/linux/mod.rs index 03192e6278e3..91e99ef3cac1 100644 --- a/src/unix/notbsd/linux/mod.rs +++ b/src/unix/notbsd/linux/mod.rs @@ -525,6 +525,19 @@ s_no_extra_traits!{ pub d_type: ::c_uchar, pub d_name: [::c_char; 256], } + + pub struct sockaddr_alg { + pub salg_family: ::sa_family_t, + pub salg_type: [::c_uchar; 14], + pub salg_feat: u32, + pub salg_mask: u32, + pub salg_name: [::c_uchar; 64], + } + + pub struct af_alg_iv { + pub ivlen: u32, + pub iv: [::c_uchar; 0], + } } cfg_if! { @@ -670,6 +683,81 @@ cfg_if! { self.size.hash(state); } } + + impl PartialEq for sockaddr_alg { + fn eq(&self, other: &sockaddr_alg) -> bool { + self.salg_family == other.salg_family + && self + .salg_type + .iter() + .zip(other.salg_type.iter()) + .all(|(a, b)| a == b) + && self.salg_feat == other.salg_feat + && self.salg_mask == other.salg_mask + && self + .salg_name + .iter() + .zip(other.salg_name.iter()) + .all(|(a, b)| a == b) + } + } + + impl Eq for sockaddr_alg {} + + impl ::fmt::Debug for sockaddr_alg { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("sockaddr_alg") + .field("salg_family", &self.salg_family) + .field("salg_type", &self.salg_type) + .field("salg_feat", &self.salg_feat) + .field("salg_mask", &self.salg_mask) + .field("salg_name", &&self.salg_name[..]) + .finish() + } + } + + impl ::hash::Hash for sockaddr_alg { + fn hash(&self, state: &mut H) { + self.salg_family.hash(state); + self.salg_type.hash(state); + self.salg_feat.hash(state); + self.salg_mask.hash(state); + self.salg_name.hash(state); + } + } + + impl af_alg_iv { + fn as_slice(&self) -> &[u8] { + unsafe { + ::core::slice::from_raw_parts( + self.iv.as_ptr(), + self.ivlen as usize + ) + } + } + } + + impl PartialEq for af_alg_iv { + fn eq(&self, other: &af_alg_iv) -> bool { + *self.as_slice() == *other.as_slice() + } + } + + impl Eq for af_alg_iv {} + + impl ::fmt::Debug for af_alg_iv { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("af_alg_iv") + .field("iv", &self.as_slice()) + .finish() + } + } + + impl ::hash::Hash for af_alg_iv { + fn hash(&self, state: &mut H) { + self.as_slice().hash(state); + } + } } } @@ -1751,6 +1839,16 @@ pub const SOF_TIMESTAMPING_SOFTWARE: ::c_uint = 1 << 4; pub const SOF_TIMESTAMPING_SYS_HARDWARE: ::c_uint = 1 << 5; pub const SOF_TIMESTAMPING_RAW_HARDWARE: ::c_uint = 1 << 6; +// linux/if_alg.h +pub const ALG_SET_KEY: ::c_int = 1; +pub const ALG_SET_IV: ::c_int = 2; +pub const ALG_SET_OP: ::c_int = 3; +pub const ALG_SET_AEAD_ASSOCLEN: ::c_int = 4; +pub const ALG_SET_AEAD_AUTHSIZE: ::c_int = 5; + +pub const ALG_OP_DECRYPT: ::c_int = 0; +pub const ALG_OP_ENCRYPT: ::c_int = 1; + f! { pub fn CMSG_NXTHDR(mhdr: *const msghdr, cmsg: *const cmsghdr) -> *mut cmsghdr { diff --git a/src/unix/notbsd/linux/other/mod.rs b/src/unix/notbsd/linux/other/mod.rs index 497ea6d70a93..28630e18668f 100644 --- a/src/unix/notbsd/linux/other/mod.rs +++ b/src/unix/notbsd/linux/other/mod.rs @@ -321,7 +321,6 @@ pub const SOL_PNPIPE: ::c_int = 275; pub const SOL_RDS: ::c_int = 276; pub const SOL_IUCV: ::c_int = 277; pub const SOL_CAIF: ::c_int = 278; -pub const SOL_ALG: ::c_int = 279; pub const SOL_NFC: ::c_int = 280; pub const SOL_XDP: ::c_int = 283; diff --git a/src/unix/notbsd/mod.rs b/src/unix/notbsd/mod.rs index baabd6e84dad..a4540f825e0a 100644 --- a/src/unix/notbsd/mod.rs +++ b/src/unix/notbsd/mod.rs @@ -657,6 +657,7 @@ pub const SOL_DCCP: ::c_int = 269; pub const SOL_NETLINK: ::c_int = 270; pub const SOL_TIPC: ::c_int = 271; pub const SOL_BLUETOOTH: ::c_int = 274; +pub const SOL_ALG: ::c_int = 279; pub const AF_UNSPEC: ::c_int = 0; pub const AF_UNIX: ::c_int = 1;