Skip to content

Commit d44d500

Browse files
acst1223cathay4t
authored andcommitted
fix: enable the latest rtnetlink on Android
The latest version of the rtnetlink crate cannot compile on Android. The reason is that Android uses the AddressFamily defined in address_family_fallback.rs, while the correct one should be that in address_family_linux.rs. This leads to AddressFamily::Bridge used in rtnetlink being undefined on Android. This patch fixes this by adding necessary target_os="android" configs. Since libc::AF_IB & libc::AF_MPLS are not defined on Android, we still confine branches related to those enums to only linux and fuchsia. Signed-off-by: chenzikai <[email protected]>
1 parent 7132a7c commit d44d500

File tree

5 files changed

+41
-9
lines changed

5 files changed

+41
-9
lines changed

src/address_family_linux.rs

+6
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ pub enum AddressFamily {
3939
Pppox,
4040
Wanpipe,
4141
Llc,
42+
#[cfg(not(target_os = "android"))]
4243
Ib,
44+
#[cfg(not(target_os = "android"))]
4345
Mpls,
4446
Can,
4547
Tipc,
@@ -93,7 +95,9 @@ impl From<u8> for AddressFamily {
9395
d if d == libc::AF_PPPOX as u8 => Self::Pppox,
9496
d if d == libc::AF_WANPIPE as u8 => Self::Wanpipe,
9597
d if d == libc::AF_LLC as u8 => Self::Llc,
98+
#[cfg(not(target_os = "android"))]
9699
d if d == libc::AF_IB as u8 => Self::Ib,
100+
#[cfg(not(target_os = "android"))]
97101
d if d == libc::AF_MPLS as u8 => Self::Mpls,
98102
d if d == libc::AF_CAN as u8 => Self::Can,
99103
d if d == libc::AF_TIPC as u8 => Self::Tipc,
@@ -149,7 +153,9 @@ impl From<AddressFamily> for u8 {
149153
AddressFamily::Pppox => libc::AF_PPPOX as u8,
150154
AddressFamily::Wanpipe => libc::AF_WANPIPE as u8,
151155
AddressFamily::Llc => libc::AF_LLC as u8,
156+
#[cfg(not(target_os = "android"))]
152157
AddressFamily::Ib => libc::AF_IB as u8,
158+
#[cfg(not(target_os = "android"))]
153159
AddressFamily::Mpls => libc::AF_MPLS as u8,
154160
AddressFamily::Can => libc::AF_CAN as u8,
155161
AddressFamily::Tipc => libc::AF_TIPC as u8,

src/lib.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,13 @@ mod tests;
3838

3939
pub(crate) mod ip;
4040

41-
#[cfg(any(target_os = "linux", target_os = "fuchsia"))]
41+
#[cfg(any(target_os = "linux", target_os = "fuchsia", target_os = "android"))]
4242
mod address_family_linux;
43-
#[cfg(any(target_os = "linux", target_os = "fuchsia"))]
43+
#[cfg(any(
44+
target_os = "linux",
45+
target_os = "fuchsia",
46+
target_os = "android"
47+
))]
4448
pub use self::address_family_linux::AddressFamily;
4549

4650
#[cfg(target_os = "freebsd")]
@@ -52,12 +56,14 @@ pub use self::address_family_freebsd::AddressFamily;
5256
target_os = "linux",
5357
target_os = "fuchsia",
5458
target_os = "freebsd",
59+
target_os = "android",
5560
)))]
5661
mod address_family_fallback;
5762
#[cfg(not(any(
5863
target_os = "linux",
5964
target_os = "fuchsia",
6065
target_os = "freebsd",
66+
target_os = "android",
6167
)))]
6268
pub use self::address_family_fallback::AddressFamily;
6369

src/link/af_spec/bridge.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<NlaBuffer<&'a T>> for AfSpecBridge {
102102
}
103103
}
104104

105-
#[cfg(any(target_os = "linux", target_os = "fuchsia"))]
105+
#[cfg(any(target_os = "linux", target_os = "fuchsia", target_os = "android"))]
106106
pub(crate) struct VecAfSpecBridge(pub(crate) Vec<AfSpecBridge>);
107107

108-
#[cfg(any(target_os = "linux", target_os = "fuchsia"))]
108+
#[cfg(any(target_os = "linux", target_os = "fuchsia", target_os = "android"))]
109109
impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<NlaBuffer<&'a T>>
110110
for VecAfSpecBridge
111111
{

src/link/af_spec/mod.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ pub use self::inet6_iface_flag::Inet6IfaceFlags;
2323
pub use self::inet6_stats::{Inet6Stats, Inet6StatsBuffer};
2424
pub use self::unspec::AfSpecUnspec;
2525

26-
#[cfg(any(target_os = "linux", target_os = "fuchsia"))]
26+
#[cfg(any(
27+
target_os = "linux",
28+
target_os = "fuchsia",
29+
target_os = "android"
30+
))]
2731
pub(crate) use self::bridge::VecAfSpecBridge;
2832
pub(crate) use self::inet::VecAfSpecInet;
2933
pub(crate) use self::inet6::VecAfSpecInet6;

src/link/attribute.rs

+20-4
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,17 @@ use netlink_packet_utils::{
1111
DecodeError,
1212
};
1313

14-
#[cfg(any(target_os = "linux", target_os = "fuchsia",))]
14+
#[cfg(any(
15+
target_os = "linux",
16+
target_os = "fuchsia",
17+
target_os = "android"
18+
))]
1519
use super::af_spec::VecAfSpecBridge;
16-
#[cfg(any(target_os = "linux", target_os = "fuchsia",))]
20+
#[cfg(any(
21+
target_os = "linux",
22+
target_os = "fuchsia",
23+
target_os = "android"
24+
))]
1725
use super::proto_info::VecLinkProtoInfoBridge;
1826
use super::{
1927
af_spec::VecAfSpecUnspec,
@@ -441,7 +449,11 @@ impl<'a, T: AsRef<[u8]> + ?Sized>
441449
.context(err(payload))?
442450
.0,
443451
),
444-
#[cfg(any(target_os = "linux", target_os = "fuchsia",))]
452+
#[cfg(any(
453+
target_os = "linux",
454+
target_os = "fuchsia",
455+
target_os = "android"
456+
))]
445457
AddressFamily::Bridge => Self::ProtoInfoBridge(
446458
VecLinkProtoInfoBridge::parse(&NlaBuffer::new_checked(
447459
payload,
@@ -650,7 +662,11 @@ impl<'a, T: AsRef<[u8]> + ?Sized>
650662
.0,
651663
)
652664
}
653-
#[cfg(any(target_os = "linux", target_os = "fuchsia",))]
665+
#[cfg(any(
666+
target_os = "linux",
667+
target_os = "fuchsia",
668+
target_os = "android"
669+
))]
654670
AddressFamily::Bridge => {
655671
let err = "invalid IFLA_AF_SPEC value for AF_BRIDGE";
656672
Self::AfSpecBridge(

0 commit comments

Comments
 (0)