Auto merge of #1261 - glebpom:master, r=gnzlbg

Add AF_ALG constants and structures
This commit is contained in:
bors 2019-02-20 08:43:11 +00:00
commit c2904a70fa
5 changed files with 203 additions and 1 deletions

View File

@ -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

View File

@ -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 {

View File

@ -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 {

View File

@ -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;

View File

@ -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;