Skip to content

Commit a3c5f9b

Browse files
committed
Auto merge of #1616 - mcpherrinm:withandroid, r=gnzlbg
Add sock_extended_err and associated constants from errqueue.h to linux_like This is an alternate version of #1614 that attempts to fix issues with the android ctests by rearranging the headers. Due to long CI cycle time, I've opened it as an alternate PR. Only one or the other should merge, depending if linux_like or linux is the correct place for this. sock_extended_err is a struct returned as a control message when the sockopt IP_RECVERR is set, when recvmsg has the MSG_ERRQUEUE flag set. IP_RECVERR and MSG_ERRQUEUE are constants both already defined here.
2 parents e4121ce + 06938ad commit a3c5f9b

File tree

5 files changed

+90
-22
lines changed

5 files changed

+90
-22
lines changed

libc-test/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,8 @@ harness = false
5252
name = "cmsg"
5353
path = "test/cmsg.rs"
5454
harness = true
55+
56+
[[test]]
57+
name = "errqueue"
58+
path = "test/errqueue.rs"
59+
harness = true

libc-test/build.rs

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ fn do_cc() {
1010
if cfg!(unix) && !target.contains("wasi") {
1111
cc::Build::new().file("src/cmsg.c").compile("cmsg");
1212
}
13+
if target.contains("android") || target.contains("linux") {
14+
cc::Build::new().file("src/errqueue.c").compile("errqueue");
15+
}
1316
}
1417

1518
fn do_ctest() {
@@ -1239,7 +1242,6 @@ fn test_android(target: &str) {
12391242

12401243
headers! { cfg:
12411244
"arpa/inet.h",
1242-
"asm/mman.h",
12431245
"ctype.h",
12441246
"dirent.h",
12451247
"dlfcn.h",
@@ -1248,27 +1250,6 @@ fn test_android(target: &str) {
12481250
"grp.h",
12491251
"ifaddrs.h",
12501252
"limits.h",
1251-
"linux/dccp.h",
1252-
"linux/futex.h",
1253-
"linux/fs.h",
1254-
"linux/genetlink.h",
1255-
"linux/if_alg.h",
1256-
"linux/if_ether.h",
1257-
"linux/if_tun.h",
1258-
"linux/magic.h",
1259-
"linux/memfd.h",
1260-
"linux/module.h",
1261-
"linux/net_tstamp.h",
1262-
"linux/netfilter/nfnetlink.h",
1263-
"linux/netfilter/nfnetlink_log.h",
1264-
"linux/netfilter/nf_tables.h",
1265-
"linux/netfilter_ipv4.h",
1266-
"linux/netfilter_ipv6.h",
1267-
"linux/netlink.h",
1268-
"linux/quota.h",
1269-
"linux/reboot.h",
1270-
"linux/seccomp.h",
1271-
"linux/sockios.h",
12721253
"locale.h",
12731254
"malloc.h",
12741255
"net/ethernet.h",
@@ -1339,6 +1320,34 @@ fn test_android(target: &str) {
13391320
[x86]: "sys/reg.h",
13401321
}
13411322

1323+
// Include linux headers at the end:
1324+
headers! { cfg:
1325+
"asm/mman.h",
1326+
"linux/dccp.h",
1327+
"linux/errqueue.h",
1328+
"linux/futex.h",
1329+
"linux/fs.h",
1330+
"linux/genetlink.h",
1331+
"linux/if_alg.h",
1332+
"linux/if_ether.h",
1333+
"linux/if_tun.h",
1334+
"linux/magic.h",
1335+
"linux/memfd.h",
1336+
"linux/module.h",
1337+
"linux/net_tstamp.h",
1338+
"linux/netfilter/nfnetlink.h",
1339+
"linux/netfilter/nfnetlink_log.h",
1340+
"linux/netfilter/nf_tables.h",
1341+
"linux/netfilter_ipv4.h",
1342+
"linux/netfilter_ipv6.h",
1343+
"linux/netlink.h",
1344+
"linux/quota.h",
1345+
"linux/reboot.h",
1346+
"linux/seccomp.h",
1347+
"linux/sockios.h",
1348+
1349+
}
1350+
13421351
cfg.type_name(move |ty, is_struct, is_union| {
13431352
match ty {
13441353
// Just pass all these through, no need for a "struct" prefix
@@ -2188,6 +2197,7 @@ fn test_linux(target: &str) {
21882197
cfg:
21892198
"asm/mman.h",
21902199
"linux/dccp.h",
2200+
"linux/errqueue.h",
21912201
"linux/falloc.h",
21922202
"linux/fs.h",
21932203
"linux/futex.h",

libc-test/src/errqueue.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <time.h>
2+
#include <linux/errqueue.h>
3+
4+
// SO_EE_OFFENDER is defined as a macro in linux/errqueue.h. This file wraps
5+
// that macro in a function so we can test the reimplementation in this package
6+
// is equivalent.
7+
8+
struct sockaddr *so_ee_offender(struct sock_extended_err *ee) {
9+
return SO_EE_OFFENDER(ee);
10+
}

libc-test/test/errqueue.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//! Compare libc's SO_EE_OFFENDER function against the actual C macro
2+
3+
extern crate libc;
4+
5+
#[cfg(any(target_os = "linux", target_os = "android"))]
6+
mod t {
7+
use libc::{self, sock_extended_err, sockaddr};
8+
9+
extern "C" {
10+
pub fn so_ee_offender(ee: *const sock_extended_err) -> *mut sockaddr;
11+
}
12+
13+
#[test]
14+
fn test_cmsg_data() {
15+
for l in 0..128 {
16+
let ee = l as *const sock_extended_err;
17+
unsafe {
18+
assert_eq!(libc::SO_EE_OFFENDER(ee), so_ee_offender(ee));
19+
}
20+
}
21+
}
22+
}

src/unix/linux_like/mod.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,16 @@ s! {
199199
pub msg_hdr: ::msghdr,
200200
pub msg_len: ::c_uint,
201201
}
202+
203+
pub struct sock_extended_err {
204+
pub ee_errno: u32,
205+
pub ee_origin: u8,
206+
pub ee_type: u8,
207+
pub ee_code: u8,
208+
pub ee_pad: u8,
209+
pub ee_info: u32,
210+
pub ee_data: u32
211+
}
202212
}
203213

204214
s_no_extra_traits! {
@@ -1189,6 +1199,13 @@ pub const ARPHRD_IEEE802154: u16 = 804;
11891199
pub const ARPHRD_VOID: u16 = 0xFFFF;
11901200
pub const ARPHRD_NONE: u16 = 0xFFFE;
11911201

1202+
pub const SO_EE_ORIGIN_NONE: u8 = 0;
1203+
pub const SO_EE_ORIGIN_LOCAL: u8 = 1;
1204+
pub const SO_EE_ORIGIN_ICMP: u8 = 2;
1205+
pub const SO_EE_ORIGIN_ICMP6: u8 = 3;
1206+
pub const SO_EE_ORIGIN_TXSTATUS: u8 = 4;
1207+
pub const SO_EE_ORIGIN_TIMESTAMPING: u8 = SO_EE_ORIGIN_TXSTATUS;
1208+
11921209
const_fn! {
11931210
{const} fn CMSG_ALIGN(len: usize) -> usize {
11941211
len + ::mem::size_of::<usize>() - 1 & !(::mem::size_of::<usize>() - 1)
@@ -1294,6 +1311,10 @@ f! {
12941311
pub fn IPTOS_ECN(x: u8) -> u8 {
12951312
x & ::IPTOS_ECN_MASK
12961313
}
1314+
1315+
pub fn SO_EE_OFFENDER(ee: *const ::sock_extended_err) -> *mut ::sockaddr {
1316+
ee.offset(1) as *mut ::sockaddr
1317+
}
12971318
}
12981319

12991320
extern "C" {

0 commit comments

Comments
 (0)