Skip to content

Commit 97ca63f

Browse files
author
Gleb Pomykalov
committed
Move AF_ALG constants and structs to both android and linux
1 parent 32226f5 commit 97ca63f

File tree

3 files changed

+135
-80
lines changed

3 files changed

+135
-80
lines changed

src/unix/notbsd/android/mod.rs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ s! {
192192
pub ipi6_addr: ::in6_addr,
193193
pub ipi6_ifindex: ::c_int,
194194
}
195+
195196
}
196197

197198
s_no_extra_traits!{
@@ -238,6 +239,20 @@ s_no_extra_traits!{
238239
pub ut_addr_v6: [::int32_t; 4],
239240
unused: [::c_char; 20],
240241
}
242+
243+
pub struct sockaddr_alg {
244+
pub salg_family: sa_family_t,
245+
pub salg_type: [::c_uchar; 14],
246+
pub salg_feat: u32,
247+
pub salg_mask: u32,
248+
pub salg_name: [::c_uchar; 64],
249+
}
250+
251+
pub struct af_alg_iv {
252+
pub ivlen: u32,
253+
pub iv: [::c_uchar; 0],
254+
}
255+
241256
}
242257

243258
cfg_if! {
@@ -451,6 +466,48 @@ cfg_if! {
451466
self.unused.hash(state);
452467
}
453468
}
469+
470+
impl PartialEq for sockaddr_alg {
471+
fn eq(&self, other: &sockaddr_alg) -> bool {
472+
self.salg_family == other.salg_family
473+
&& self
474+
.salg_type
475+
.iter()
476+
.zip(other.salg_type.iter())
477+
.all(|(a, b)| a == b)
478+
&& self.salg_feat == other.salg_feat
479+
&& self.salg_mask == other.salg_mask
480+
&& self
481+
.salg_name
482+
.iter()
483+
.zip(other.salg_name.iter())
484+
.all(|(a, b)| a == b)
485+
}
486+
}
487+
488+
impl Eq for sockaddr_alg {}
489+
490+
impl ::fmt::Debug for sockaddr_alg {
491+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
492+
f.debug_struct("sockaddr_alg")
493+
.field("salg_family", &self.salg_family)
494+
// .field("salg_type", &self.salg_type)
495+
.field("salg_feat", &self.salg_feat)
496+
.field("salg_mask", &self.salg_mask)
497+
// .field("salg_name", &self.salg_name)
498+
.finish()
499+
}
500+
}
501+
502+
impl ::hash::Hash for sockaddr_alg {
503+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
504+
self.salg_family.hash(state);
505+
self.salg_type.hash(state);
506+
self.salg_feat.hash(state);
507+
self.salg_mask.hash(state);
508+
self.salg_name.hash(state);
509+
}
510+
}
454511
}
455512
}
456513

@@ -822,6 +879,7 @@ pub const SOL_AX25: ::c_int = 257;
822879
pub const SOL_ATALK: ::c_int = 258;
823880
pub const SOL_NETROM: ::c_int = 259;
824881
pub const SOL_ROSE: ::c_int = 260;
882+
pub const SOL_ALG: ::c_int = 279;
825883

826884
#[doc(hidden)]
827885
pub const AF_MAX: ::c_int = 43;
@@ -1690,6 +1748,16 @@ pub const MODULE_INIT_IGNORE_VERMAGIC: ::c_uint = 0x0002;
16901748
// Similarity to Linux it's not used but defined for compatibility.
16911749
pub const ENOATTR: ::c_int = ::ENODATA;
16921750

1751+
// linux/if_alg.h
1752+
pub const ALG_SET_KEY: ::c_int = 1;
1753+
pub const ALG_SET_IV: ::c_int = 2;
1754+
pub const ALG_SET_OP: ::c_int = 3;
1755+
pub const ALG_SET_AEAD_ASSOCLEN: ::c_int = 4;
1756+
pub const ALG_SET_AEAD_AUTHSIZE: ::c_int = 5;
1757+
1758+
pub const ALG_OP_DECRYPT: ::c_int = 0;
1759+
pub const ALG_OP_ENCRYPT: ::c_int = 1;
1760+
16931761
f! {
16941762
pub fn CMSG_NXTHDR(mhdr: *const msghdr,
16951763
cmsg: *const cmsghdr) -> *mut cmsghdr {

src/unix/notbsd/linux/mod.rs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,11 @@ s! {
507507
pub cookie: ::uint32_t,
508508
pub len: ::uint32_t
509509
}
510+
511+
pub struct af_alg_iv {
512+
pub ivlen: u32,
513+
pub iv: [::c_uchar; 0],
514+
}
510515
}
511516

512517
s_no_extra_traits!{
@@ -525,6 +530,15 @@ s_no_extra_traits!{
525530
pub d_type: ::c_uchar,
526531
pub d_name: [::c_char; 256],
527532
}
533+
534+
pub struct sockaddr_alg {
535+
pub salg_family: sa_family_t,
536+
pub salg_type: [::c_uchar; 14],
537+
pub salg_feat: u32,
538+
pub salg_mask: u32,
539+
pub salg_name: [::c_uchar; 64],
540+
}
541+
528542
}
529543

530544
cfg_if! {
@@ -670,6 +684,49 @@ cfg_if! {
670684
self.size.hash(state);
671685
}
672686
}
687+
688+
689+
impl PartialEq for sockaddr_alg {
690+
fn eq(&self, other: &sockaddr_alg) -> bool {
691+
self.salg_family == other.salg_family
692+
&& self
693+
.salg_type
694+
.iter()
695+
.zip(other.salg_type.iter())
696+
.all(|(a, b)| a == b)
697+
&& self.salg_feat == other.salg_feat
698+
&& self.salg_mask == other.salg_mask
699+
&& self
700+
.salg_name
701+
.iter()
702+
.zip(other.salg_name.iter())
703+
.all(|(a, b)| a == b)
704+
}
705+
}
706+
707+
impl Eq for sockaddr_alg {}
708+
709+
impl ::fmt::Debug for sockaddr_alg {
710+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
711+
f.debug_struct("sockaddr_alg")
712+
.field("salg_family", &self.salg_family)
713+
// .field("salg_type", &self.salg_type)
714+
.field("salg_feat", &self.salg_feat)
715+
.field("salg_mask", &self.salg_mask)
716+
// .field("salg_name", &self.salg_name)
717+
.finish()
718+
}
719+
}
720+
721+
impl ::hash::Hash for sockaddr_alg {
722+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
723+
self.salg_family.hash(state);
724+
self.salg_type.hash(state);
725+
self.salg_feat.hash(state);
726+
self.salg_mask.hash(state);
727+
self.salg_name.hash(state);
728+
}
729+
}
673730
}
674731
}
675732

@@ -1751,6 +1808,16 @@ pub const SOF_TIMESTAMPING_SOFTWARE: ::c_uint = 1 << 4;
17511808
pub const SOF_TIMESTAMPING_SYS_HARDWARE: ::c_uint = 1 << 5;
17521809
pub const SOF_TIMESTAMPING_RAW_HARDWARE: ::c_uint = 1 << 6;
17531810

1811+
// linux/if_alg.h
1812+
pub const ALG_SET_KEY: ::c_int = 1;
1813+
pub const ALG_SET_IV: ::c_int = 2;
1814+
pub const ALG_SET_OP: ::c_int = 3;
1815+
pub const ALG_SET_AEAD_ASSOCLEN: ::c_int = 4;
1816+
pub const ALG_SET_AEAD_AUTHSIZE: ::c_int = 5;
1817+
1818+
pub const ALG_OP_DECRYPT: ::c_int = 0;
1819+
pub const ALG_OP_ENCRYPT: ::c_int = 1;
1820+
17541821
f! {
17551822
pub fn CMSG_NXTHDR(mhdr: *const msghdr,
17561823
cmsg: *const cmsghdr) -> *mut cmsghdr {

src/unix/notbsd/mod.rs

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,6 @@ s! {
209209
pub ar_pln: u8,
210210
pub ar_op: u16,
211211
}
212-
213-
#[cfg(any(target_os = "linux", target_os = "android"))]
214-
pub struct af_alg_iv {
215-
pub ivlen: u32,
216-
pub iv: [::c_uchar; 0],
217-
}
218-
219212
}
220213

221214
s_no_extra_traits!{
@@ -255,16 +248,6 @@ s_no_extra_traits!{
255248
pub machine: [::c_char; 65],
256249
pub domainname: [::c_char; 65]
257250
}
258-
259-
#[cfg(any(target_os = "linux", target_os = "android"))]
260-
pub struct sockaddr_alg {
261-
pub salg_family: sa_family_t,
262-
pub salg_type: [::c_uchar; 14],
263-
pub salg_feat: u32,
264-
pub salg_mask: u32,
265-
pub salg_name: [::c_uchar; 64],
266-
}
267-
268251
}
269252

270253
cfg_if! {
@@ -328,52 +311,6 @@ cfg_if! {
328311
}
329312
}
330313

331-
#[cfg(any(target_os = "linux", target_os = "android"))]
332-
impl PartialEq for sockaddr_alg {
333-
fn eq(&self, other: &sockaddr_alg) -> bool {
334-
self.salg_family == other.salg_family
335-
&& self
336-
.salg_type
337-
.iter()
338-
.zip(other.salg_type.iter())
339-
.all(|(a, b)| a == b)
340-
&& self.salg_feat == other.salg_feat
341-
&& self.salg_mask == other.salg_mask
342-
&& self
343-
.salg_name
344-
.iter()
345-
.zip(other.salg_name.iter())
346-
.all(|(a, b)| a == b)
347-
}
348-
}
349-
350-
#[cfg(any(target_os = "linux", target_os = "android"))]
351-
impl Eq for sockaddr_alg {}
352-
353-
#[cfg(any(target_os = "linux", target_os = "android"))]
354-
impl ::fmt::Debug for sockaddr_alg {
355-
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
356-
f.debug_struct("sockaddr_alg")
357-
.field("salg_family", &self.salg_family)
358-
// .field("salg_type", &self.salg_type)
359-
.field("salg_feat", &self.salg_feat)
360-
.field("salg_mask", &self.salg_mask)
361-
// .field("salg_name", &self.salg_name)
362-
.finish()
363-
}
364-
}
365-
366-
#[cfg(any(target_os = "linux", target_os = "android"))]
367-
impl ::hash::Hash for sockaddr_alg {
368-
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
369-
self.salg_family.hash(state);
370-
self.salg_type.hash(state);
371-
self.salg_feat.hash(state);
372-
self.salg_mask.hash(state);
373-
self.salg_name.hash(state);
374-
}
375-
}
376-
377314
impl PartialEq for utsname {
378315
fn eq(&self, other: &utsname) -> bool {
379316
self.sysname
@@ -720,7 +657,6 @@ pub const SOL_DCCP: ::c_int = 269;
720657
pub const SOL_NETLINK: ::c_int = 270;
721658
pub const SOL_TIPC: ::c_int = 271;
722659
pub const SOL_BLUETOOTH: ::c_int = 274;
723-
#[cfg(any(target_os = "linux", target_os = "android"))]
724660
pub const SOL_ALG: ::c_int = 279;
725661

726662
pub const AF_UNSPEC: ::c_int = 0;
@@ -1193,22 +1129,6 @@ pub const ARPHRD_IEEE802154: u16 = 804;
11931129
pub const ARPHRD_VOID: u16 = 0xFFFF;
11941130
pub const ARPHRD_NONE: u16 = 0xFFFE;
11951131

1196-
#[cfg(any(target_os = "linux", target_os = "android"))]
1197-
pub const ALG_SET_KEY: ::c_int = 1;
1198-
#[cfg(any(target_os = "linux", target_os = "android"))]
1199-
pub const ALG_SET_IV: ::c_int = 2;
1200-
#[cfg(any(target_os = "linux", target_os = "android"))]
1201-
pub const ALG_SET_OP: ::c_int = 3;
1202-
#[cfg(any(target_os = "linux", target_os = "android"))]
1203-
pub const ALG_SET_AEAD_ASSOCLEN: ::c_int = 4;
1204-
#[cfg(any(target_os = "linux", target_os = "android"))]
1205-
pub const ALG_SET_AEAD_AUTHSIZE: ::c_int = 5;
1206-
1207-
#[cfg(any(target_os = "linux", target_os = "android"))]
1208-
pub const ALG_OP_DECRYPT: ::c_int = 0;
1209-
#[cfg(any(target_os = "linux", target_os = "android"))]
1210-
pub const ALG_OP_ENCRYPT: ::c_int = 1;
1211-
12121132
fn CMSG_ALIGN(len: usize) -> usize {
12131133
len + mem::size_of::<usize>() - 1 & !(mem::size_of::<usize>() - 1)
12141134
}

0 commit comments

Comments
 (0)