diff --git a/libc-test/build.rs b/libc-test/build.rs index 662273ae41afcaacc40fe9184e68fa91ad824ff1..cea009b7b36e53819ce78b9480b24891ec182c55 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 8737bc791a5f8ec9a6af7a4e6ed1d0da0a126fab..2f62a0930da2d201fa59957ec47b1253297374f6 100644 --- a/src/unix/notbsd/android/mod.rs +++ b/src/unix/notbsd/android/mod.rs @@ -236,6 +236,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! { @@ -449,6 +462,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<H: ::hash::Hasher>(&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<H: ::hash::Hasher>(&self, state: &mut H) { + self.as_slice().hash(state); + } + } } } @@ -1692,6 +1780,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 8eedf9e0576fb6e9b0bf134f3b07859a6cabd069..b9ecc9de9f4393ff5e00bac10fe50bc18e307269 100644 --- a/src/unix/notbsd/linux/mod.rs +++ b/src/unix/notbsd/linux/mod.rs @@ -511,6 +511,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! { @@ -656,6 +669,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<H: ::hash::Hasher>(&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<H: ::hash::Hasher>(&self, state: &mut H) { + self.as_slice().hash(state); + } + } } } @@ -1702,6 +1790,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 9d6af2bad8a75995ca314ec726441c6851a54f86..d289f05385a6a90a98045944cf3ddbc98f5d4983 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 bc898b654be0116ce56ff362ef7b33a34dfa1ae7..714f5c8495abf2f14ac125ef883861f711deccbe 100644 --- a/src/unix/notbsd/mod.rs +++ b/src/unix/notbsd/mod.rs @@ -667,6 +667,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;