Skip to content

Commit c2904a7

Browse files
committed
Auto merge of #1261 - glebpom:master, r=gnzlbg
Add AF_ALG constants and structures
2 parents 501ca54 + bce3ee3 commit c2904a7

File tree

5 files changed

+203
-1
lines changed

5 files changed

+203
-1
lines changed

libc-test/build.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ fn do_ctest() {
102102
cfg.header("net/route.h");
103103
cfg.header("net/if_arp.h");
104104
}
105+
if linux || android {
106+
cfg.header("linux/if_alg.h");
107+
}
105108
cfg.header("netdb.h");
106109
cfg.header("netinet/in.h");
107110
cfg.header("netinet/ip.h");
@@ -627,6 +630,9 @@ fn do_ctest() {
627630
| "RENAME_NOREPLACE"
628631
| "RENAME_EXCHANGE"
629632
| "RENAME_WHITEOUT"
633+
// ALG_SET_AEAD_* constants are available starting from kernel 3.19
634+
| "ALG_SET_AEAD_ASSOCLEN"
635+
| "ALG_SET_AEAD_AUTHSIZE"
630636
if musl =>
631637
{
632638
true

src/unix/notbsd/android/mod.rs

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,19 @@ s_no_extra_traits!{
236236
pub ut_addr_v6: [::int32_t; 4],
237237
unused: [::c_char; 20],
238238
}
239+
240+
pub struct sockaddr_alg {
241+
pub salg_family: ::sa_family_t,
242+
pub salg_type: [::c_uchar; 14],
243+
pub salg_feat: u32,
244+
pub salg_mask: u32,
245+
pub salg_name: [::c_uchar; 64],
246+
}
247+
248+
pub struct af_alg_iv {
249+
pub ivlen: u32,
250+
pub iv: [::c_uchar; 0],
251+
}
239252
}
240253

241254
cfg_if! {
@@ -449,6 +462,81 @@ cfg_if! {
449462
self.unused.hash(state);
450463
}
451464
}
465+
466+
impl PartialEq for sockaddr_alg {
467+
fn eq(&self, other: &sockaddr_alg) -> bool {
468+
self.salg_family == other.salg_family
469+
&& self
470+
.salg_type
471+
.iter()
472+
.zip(other.salg_type.iter())
473+
.all(|(a, b)| a == b)
474+
&& self.salg_feat == other.salg_feat
475+
&& self.salg_mask == other.salg_mask
476+
&& self
477+
.salg_name
478+
.iter()
479+
.zip(other.salg_name.iter())
480+
.all(|(a, b)| a == b)
481+
}
482+
}
483+
484+
impl Eq for sockaddr_alg {}
485+
486+
impl ::fmt::Debug for sockaddr_alg {
487+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
488+
f.debug_struct("sockaddr_alg")
489+
.field("salg_family", &self.salg_family)
490+
.field("salg_type", &self.salg_type)
491+
.field("salg_feat", &self.salg_feat)
492+
.field("salg_mask", &self.salg_mask)
493+
.field("salg_name", &&self.salg_name[..])
494+
.finish()
495+
}
496+
}
497+
498+
impl ::hash::Hash for sockaddr_alg {
499+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
500+
self.salg_family.hash(state);
501+
self.salg_type.hash(state);
502+
self.salg_feat.hash(state);
503+
self.salg_mask.hash(state);
504+
self.salg_name.hash(state);
505+
}
506+
}
507+
508+
impl af_alg_iv {
509+
fn as_slice(&self) -> &[u8] {
510+
unsafe {
511+
::core::slice::from_raw_parts(
512+
self.iv.as_ptr(),
513+
self.ivlen as usize
514+
)
515+
}
516+
}
517+
}
518+
519+
impl PartialEq for af_alg_iv {
520+
fn eq(&self, other: &af_alg_iv) -> bool {
521+
*self.as_slice() == *other.as_slice()
522+
}
523+
}
524+
525+
impl Eq for af_alg_iv {}
526+
527+
impl ::fmt::Debug for af_alg_iv {
528+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
529+
f.debug_struct("af_alg_iv")
530+
.field("iv", &self.as_slice())
531+
.finish()
532+
}
533+
}
534+
535+
impl ::hash::Hash for af_alg_iv {
536+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
537+
self.as_slice().hash(state);
538+
}
539+
}
452540
}
453541
}
454542

@@ -1692,6 +1780,16 @@ pub const MODULE_INIT_IGNORE_VERMAGIC: ::c_uint = 0x0002;
16921780
// Similarity to Linux it's not used but defined for compatibility.
16931781
pub const ENOATTR: ::c_int = ::ENODATA;
16941782

1783+
// linux/if_alg.h
1784+
pub const ALG_SET_KEY: ::c_int = 1;
1785+
pub const ALG_SET_IV: ::c_int = 2;
1786+
pub const ALG_SET_OP: ::c_int = 3;
1787+
pub const ALG_SET_AEAD_ASSOCLEN: ::c_int = 4;
1788+
pub const ALG_SET_AEAD_AUTHSIZE: ::c_int = 5;
1789+
1790+
pub const ALG_OP_DECRYPT: ::c_int = 0;
1791+
pub const ALG_OP_ENCRYPT: ::c_int = 1;
1792+
16951793
f! {
16961794
pub fn CMSG_NXTHDR(mhdr: *const msghdr,
16971795
cmsg: *const cmsghdr) -> *mut cmsghdr {

src/unix/notbsd/linux/mod.rs

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,19 @@ s_no_extra_traits!{
511511
pub d_type: ::c_uchar,
512512
pub d_name: [::c_char; 256],
513513
}
514+
515+
pub struct sockaddr_alg {
516+
pub salg_family: ::sa_family_t,
517+
pub salg_type: [::c_uchar; 14],
518+
pub salg_feat: u32,
519+
pub salg_mask: u32,
520+
pub salg_name: [::c_uchar; 64],
521+
}
522+
523+
pub struct af_alg_iv {
524+
pub ivlen: u32,
525+
pub iv: [::c_uchar; 0],
526+
}
514527
}
515528

516529
cfg_if! {
@@ -656,6 +669,81 @@ cfg_if! {
656669
self.size.hash(state);
657670
}
658671
}
672+
673+
impl PartialEq for sockaddr_alg {
674+
fn eq(&self, other: &sockaddr_alg) -> bool {
675+
self.salg_family == other.salg_family
676+
&& self
677+
.salg_type
678+
.iter()
679+
.zip(other.salg_type.iter())
680+
.all(|(a, b)| a == b)
681+
&& self.salg_feat == other.salg_feat
682+
&& self.salg_mask == other.salg_mask
683+
&& self
684+
.salg_name
685+
.iter()
686+
.zip(other.salg_name.iter())
687+
.all(|(a, b)| a == b)
688+
}
689+
}
690+
691+
impl Eq for sockaddr_alg {}
692+
693+
impl ::fmt::Debug for sockaddr_alg {
694+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
695+
f.debug_struct("sockaddr_alg")
696+
.field("salg_family", &self.salg_family)
697+
.field("salg_type", &self.salg_type)
698+
.field("salg_feat", &self.salg_feat)
699+
.field("salg_mask", &self.salg_mask)
700+
.field("salg_name", &&self.salg_name[..])
701+
.finish()
702+
}
703+
}
704+
705+
impl ::hash::Hash for sockaddr_alg {
706+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
707+
self.salg_family.hash(state);
708+
self.salg_type.hash(state);
709+
self.salg_feat.hash(state);
710+
self.salg_mask.hash(state);
711+
self.salg_name.hash(state);
712+
}
713+
}
714+
715+
impl af_alg_iv {
716+
fn as_slice(&self) -> &[u8] {
717+
unsafe {
718+
::core::slice::from_raw_parts(
719+
self.iv.as_ptr(),
720+
self.ivlen as usize
721+
)
722+
}
723+
}
724+
}
725+
726+
impl PartialEq for af_alg_iv {
727+
fn eq(&self, other: &af_alg_iv) -> bool {
728+
*self.as_slice() == *other.as_slice()
729+
}
730+
}
731+
732+
impl Eq for af_alg_iv {}
733+
734+
impl ::fmt::Debug for af_alg_iv {
735+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
736+
f.debug_struct("af_alg_iv")
737+
.field("iv", &self.as_slice())
738+
.finish()
739+
}
740+
}
741+
742+
impl ::hash::Hash for af_alg_iv {
743+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
744+
self.as_slice().hash(state);
745+
}
746+
}
659747
}
660748
}
661749

@@ -1702,6 +1790,16 @@ pub const SOF_TIMESTAMPING_SOFTWARE: ::c_uint = 1 << 4;
17021790
pub const SOF_TIMESTAMPING_SYS_HARDWARE: ::c_uint = 1 << 5;
17031791
pub const SOF_TIMESTAMPING_RAW_HARDWARE: ::c_uint = 1 << 6;
17041792

1793+
// linux/if_alg.h
1794+
pub const ALG_SET_KEY: ::c_int = 1;
1795+
pub const ALG_SET_IV: ::c_int = 2;
1796+
pub const ALG_SET_OP: ::c_int = 3;
1797+
pub const ALG_SET_AEAD_ASSOCLEN: ::c_int = 4;
1798+
pub const ALG_SET_AEAD_AUTHSIZE: ::c_int = 5;
1799+
1800+
pub const ALG_OP_DECRYPT: ::c_int = 0;
1801+
pub const ALG_OP_ENCRYPT: ::c_int = 1;
1802+
17051803
f! {
17061804
pub fn CMSG_NXTHDR(mhdr: *const msghdr,
17071805
cmsg: *const cmsghdr) -> *mut cmsghdr {

src/unix/notbsd/linux/other/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,6 @@ pub const SOL_PNPIPE: ::c_int = 275;
321321
pub const SOL_RDS: ::c_int = 276;
322322
pub const SOL_IUCV: ::c_int = 277;
323323
pub const SOL_CAIF: ::c_int = 278;
324-
pub const SOL_ALG: ::c_int = 279;
325324
pub const SOL_NFC: ::c_int = 280;
326325
pub const SOL_XDP: ::c_int = 283;
327326

src/unix/notbsd/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,7 @@ pub const SOL_DCCP: ::c_int = 269;
667667
pub const SOL_NETLINK: ::c_int = 270;
668668
pub const SOL_TIPC: ::c_int = 271;
669669
pub const SOL_BLUETOOTH: ::c_int = 274;
670+
pub const SOL_ALG: ::c_int = 279;
670671

671672
pub const AF_UNSPEC: ::c_int = 0;
672673
pub const AF_UNIX: ::c_int = 1;

0 commit comments

Comments
 (0)