summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-02-25 11:59:13 +0000
committerbors <bors@rust-lang.org>2018-02-25 11:59:13 +0000
commit2c978165b12866a728af12f601b88e9e20daa3e2 (patch)
tree73b5fd642b806e8055764c55f5dfabb322850d0a
parent88c33d45800b2bc869dba4a449857c17a1a2be32 (diff)
parent95befb4b20b39d2b257ed69a10a22ab68995fc12 (diff)
downloadrust-libc-2c978165b12866a728af12f601b88e9e20daa3e2.tar.gz
Auto merge of #922 - faern:add-netlink-structs, r=alexcrichton
Add netlink structs to all notbsd platforms Adding the remaining structs from `<linux/netlink.h>`. Sadly very duplicated, but that's how it ended up when added to all "notbsd" platforms except musl. If there is a better way to structure it to reduce duplication I'm all ears!
-rw-r--r--libc-test/build.rs3
-rw-r--r--src/unix/notbsd/android/mod.rs93
-rw-r--r--src/unix/notbsd/linux/mips/mod.rs51
-rw-r--r--src/unix/notbsd/linux/mod.rs52
-rw-r--r--src/unix/notbsd/linux/other/mod.rs76
5 files changed, 263 insertions, 12 deletions
diff --git a/libc-test/build.rs b/libc-test/build.rs
index 10505db9d9..92865f0481 100644
--- a/libc-test/build.rs
+++ b/libc-test/build.rs
@@ -242,12 +242,13 @@ fn main() {
}
cfg.header("sys/reboot.h");
if !emscripten {
+ cfg.header("linux/netlink.h");
+ cfg.header("linux/genetlink.h");
cfg.header("linux/netfilter_ipv4.h");
cfg.header("linux/fs.h");
}
if !musl {
cfg.header("asm/mman.h");
- cfg.header("linux/netlink.h");
cfg.header("linux/magic.h");
cfg.header("linux/reboot.h");
cfg.header("linux/netfilter/nf_tables.h");
diff --git a/src/unix/notbsd/android/mod.rs b/src/unix/notbsd/android/mod.rs
index cf7a07809d..da74d57da4 100644
--- a/src/unix/notbsd/android/mod.rs
+++ b/src/unix/notbsd/android/mod.rs
@@ -185,6 +185,50 @@ s! {
pub uid: ::uid_t,
pub gid: ::gid_t,
}
+
+ pub struct genlmsghdr {
+ cmd: u8,
+ version: u8,
+ reserved: u16,
+ }
+
+ pub struct nlmsghdr {
+ nlmsg_len: u32,
+ nlmsg_type: u16,
+ nlmsg_flags: u16,
+ nlmsg_seq: u32,
+ nlmsg_pid: u32,
+ }
+
+ pub struct nlmsgerr {
+ error: ::c_int,
+ msg: nlmsghdr,
+ }
+
+ pub struct nl_pktinfo {
+ group: u32,
+ }
+
+ pub struct nl_mmap_req {
+ nm_block_size: ::c_uint,
+ nm_block_nr: ::c_uint,
+ nm_frame_size: ::c_uint,
+ nm_frame_nr: ::c_uint,
+ }
+
+ pub struct nl_mmap_hdr {
+ nm_status: ::c_uint,
+ nm_len: ::c_uint,
+ nm_group: u32,
+ nm_pid: u32,
+ nm_uid: u32,
+ nm_gid: u32,
+ }
+
+ pub struct nlattr {
+ nla_len: u16,
+ nla_type: u16,
+ }
}
pub const O_TRUNC: ::c_int = 512;
@@ -860,6 +904,49 @@ pub const NLMSG_DONE: ::c_int = 0x3;
pub const NLMSG_OVERRUN: ::c_int = 0x4;
pub const NLMSG_MIN_TYPE: ::c_int = 0x10;
+pub const GENL_NAMSIZ: ::c_int = 16;
+
+pub const GENL_MIN_ID: ::c_int = NLMSG_MIN_TYPE;
+pub const GENL_MAX_ID: ::c_int = 1023;
+
+pub const GENL_ADMIN_PERM: ::c_int = 0x01;
+pub const GENL_CMD_CAP_DO: ::c_int = 0x02;
+pub const GENL_CMD_CAP_DUMP: ::c_int = 0x04;
+pub const GENL_CMD_CAP_HASPOL: ::c_int = 0x08;
+pub const GENL_UNS_ADMIN_PERM: ::c_int = 0x10;
+
+pub const GENL_ID_CTRL: ::c_int = NLMSG_MIN_TYPE;
+pub const GENL_ID_VFS_DQUOT: ::c_int = NLMSG_MIN_TYPE + 1;
+pub const GENL_ID_PMCRAID: ::c_int = NLMSG_MIN_TYPE + 2;
+
+pub const CTRL_CMD_UNSPEC: ::c_int = 0;
+pub const CTRL_CMD_NEWFAMILY: ::c_int = 1;
+pub const CTRL_CMD_DELFAMILY: ::c_int = 2;
+pub const CTRL_CMD_GETFAMILY: ::c_int = 3;
+pub const CTRL_CMD_NEWOPS: ::c_int = 4;
+pub const CTRL_CMD_DELOPS: ::c_int = 5;
+pub const CTRL_CMD_GETOPS: ::c_int = 6;
+pub const CTRL_CMD_NEWMCAST_GRP: ::c_int = 7;
+pub const CTRL_CMD_DELMCAST_GRP: ::c_int = 8;
+pub const CTRL_CMD_GETMCAST_GRP: ::c_int = 9;
+
+pub const CTRL_ATTR_UNSPEC: ::c_int = 0;
+pub const CTRL_ATTR_FAMILY_ID: ::c_int = 1;
+pub const CTRL_ATTR_FAMILY_NAME: ::c_int = 2;
+pub const CTRL_ATTR_VERSION: ::c_int = 3;
+pub const CTRL_ATTR_HDRSIZE: ::c_int = 4;
+pub const CTRL_ATTR_MAXATTR: ::c_int = 5;
+pub const CTRL_ATTR_OPS: ::c_int = 6;
+pub const CTRL_ATTR_MCAST_GROUPS: ::c_int = 7;
+
+pub const CTRL_ATTR_OP_UNSPEC: ::c_int = 0;
+pub const CTRL_ATTR_OP_ID: ::c_int = 1;
+pub const CTRL_ATTR_OP_FLAGS: ::c_int = 2;
+
+pub const CTRL_ATTR_MCAST_GRP_UNSPEC: ::c_int = 0;
+pub const CTRL_ATTR_MCAST_GRP_NAME: ::c_int = 1;
+pub const CTRL_ATTR_MCAST_GRP_ID: ::c_int = 2;
+
pub const NETLINK_ADD_MEMBERSHIP: ::c_int = 1;
pub const NETLINK_DROP_MEMBERSHIP: ::c_int = 2;
pub const NETLINK_PKTINFO: ::c_int = 3;
@@ -879,6 +966,8 @@ pub const NLA_F_NESTED: ::c_int = 1 << 15;
pub const NLA_F_NET_BYTEORDER: ::c_int = 1 << 14;
pub const NLA_TYPE_MASK: ::c_int = !(NLA_F_NESTED | NLA_F_NET_BYTEORDER);
+pub const NLA_ALIGNTO: ::c_int = 4;
+
pub const SIGEV_THREAD_ID: ::c_int = 4;
pub const CIBAUD: ::tcflag_t = 0o02003600000;
@@ -1023,6 +1112,10 @@ f! {
let mi = mi as ::dev_t;
((ma & 0xfff) << 8) | (mi & 0xff) | ((mi & 0xfff00) << 12)
}
+
+ pub fn NLA_ALIGN(len: ::c_int) -> ::c_int {
+ return ((len) + NLA_ALIGNTO - 1) & !(NLA_ALIGNTO - 1)
+ }
}
extern {
diff --git a/src/unix/notbsd/linux/mips/mod.rs b/src/unix/notbsd/linux/mips/mod.rs
index 15fdb5007c..ac4f3b4211 100644
--- a/src/unix/notbsd/linux/mips/mod.rs
+++ b/src/unix/notbsd/linux/mips/mod.rs
@@ -39,6 +39,44 @@ s! {
pub c_ispeed: ::speed_t,
pub c_ospeed: ::speed_t,
}
+
+ pub struct nlmsghdr {
+ nlmsg_len: u32,
+ nlmsg_type: u16,
+ nlmsg_flags: u16,
+ nlmsg_seq: u32,
+ nlmsg_pid: u32,
+ }
+
+ pub struct nlmsgerr {
+ error: ::c_int,
+ msg: nlmsghdr,
+ }
+
+ pub struct nl_pktinfo {
+ group: u32,
+ }
+
+ pub struct nl_mmap_req {
+ nm_block_size: ::c_uint,
+ nm_block_nr: ::c_uint,
+ nm_frame_size: ::c_uint,
+ nm_frame_nr: ::c_uint,
+ }
+
+ pub struct nl_mmap_hdr {
+ nm_status: ::c_uint,
+ nm_len: ::c_uint,
+ nm_group: u32,
+ nm_pid: u32,
+ nm_uid: u32,
+ nm_gid: u32,
+ }
+
+ pub struct nlattr {
+ nla_len: u16,
+ nla_type: u16,
+ }
}
pub const SFD_CLOEXEC: ::c_int = 0x080000;
@@ -662,6 +700,13 @@ pub const EHWPOISON: ::c_int = 168;
pub const SIGEV_THREAD_ID: ::c_int = 4;
pub const EPOLLWAKEUP: ::c_int = 0x20000000;
+pub const NLA_ALIGNTO: ::c_int = 4;
+
+pub const GENL_UNS_ADMIN_PERM: ::c_int = 0x10;
+
+pub const GENL_ID_VFS_DQUOT: ::c_int = ::NLMSG_MIN_TYPE + 1;
+pub const GENL_ID_PMCRAID: ::c_int = ::NLMSG_MIN_TYPE + 2;
+
pub const NFT_TABLE_MAXNAMELEN: ::c_int = 32;
pub const NFT_CHAIN_MAXNAMELEN: ::c_int = 32;
pub const NFT_SET_MAXNAMELEN: ::c_int = 32;
@@ -697,6 +742,12 @@ pub const AF_MAX: ::c_int = 42;
#[doc(hidden)]
pub const PF_MAX: ::c_int = AF_MAX;
+f! {
+ pub fn NLA_ALIGN(len: ::c_int) -> ::c_int {
+ return ((len) + NLA_ALIGNTO - 1) & !(NLA_ALIGNTO - 1)
+ }
+}
+
#[link(name = "util")]
extern {
pub fn sysctl(name: *mut ::c_int,
diff --git a/src/unix/notbsd/linux/mod.rs b/src/unix/notbsd/linux/mod.rs
index cb78ee6791..25f7ed3b4a 100644
--- a/src/unix/notbsd/linux/mod.rs
+++ b/src/unix/notbsd/linux/mod.rs
@@ -483,6 +483,12 @@ s! {
__policy: ::c_int,
__pad: [::c_int; 16],
}
+
+ pub struct genlmsghdr {
+ cmd: u8,
+ version: u8,
+ reserved: u16,
+ }
}
pub const ABDAY_1: ::nl_item = 0x20000;
@@ -1264,6 +1270,52 @@ pub const POSIX_SPAWN_SETSIGMASK: ::c_int = 0x08;
pub const POSIX_SPAWN_SETSCHEDPARAM: ::c_int = 0x10;
pub const POSIX_SPAWN_SETSCHEDULER: ::c_int = 0x20;
+pub const NLMSG_NOOP: ::c_int = 0x1;
+pub const NLMSG_ERROR: ::c_int = 0x2;
+pub const NLMSG_DONE: ::c_int = 0x3;
+pub const NLMSG_OVERRUN: ::c_int = 0x4;
+pub const NLMSG_MIN_TYPE: ::c_int = 0x10;
+
+pub const GENL_NAMSIZ: ::c_int = 16;
+
+pub const GENL_MIN_ID: ::c_int = NLMSG_MIN_TYPE;
+pub const GENL_MAX_ID: ::c_int = 1023;
+
+pub const GENL_ADMIN_PERM: ::c_int = 0x01;
+pub const GENL_CMD_CAP_DO: ::c_int = 0x02;
+pub const GENL_CMD_CAP_DUMP: ::c_int = 0x04;
+pub const GENL_CMD_CAP_HASPOL: ::c_int = 0x08;
+
+pub const GENL_ID_CTRL: ::c_int = NLMSG_MIN_TYPE;
+
+pub const CTRL_CMD_UNSPEC: ::c_int = 0;
+pub const CTRL_CMD_NEWFAMILY: ::c_int = 1;
+pub const CTRL_CMD_DELFAMILY: ::c_int = 2;
+pub const CTRL_CMD_GETFAMILY: ::c_int = 3;
+pub const CTRL_CMD_NEWOPS: ::c_int = 4;
+pub const CTRL_CMD_DELOPS: ::c_int = 5;
+pub const CTRL_CMD_GETOPS: ::c_int = 6;
+pub const CTRL_CMD_NEWMCAST_GRP: ::c_int = 7;
+pub const CTRL_CMD_DELMCAST_GRP: ::c_int = 8;
+pub const CTRL_CMD_GETMCAST_GRP: ::c_int = 9;
+
+pub const CTRL_ATTR_UNSPEC: ::c_int = 0;
+pub const CTRL_ATTR_FAMILY_ID: ::c_int = 1;
+pub const CTRL_ATTR_FAMILY_NAME: ::c_int = 2;
+pub const CTRL_ATTR_VERSION: ::c_int = 3;
+pub const CTRL_ATTR_HDRSIZE: ::c_int = 4;
+pub const CTRL_ATTR_MAXATTR: ::c_int = 5;
+pub const CTRL_ATTR_OPS: ::c_int = 6;
+pub const CTRL_ATTR_MCAST_GROUPS: ::c_int = 7;
+
+pub const CTRL_ATTR_OP_UNSPEC: ::c_int = 0;
+pub const CTRL_ATTR_OP_ID: ::c_int = 1;
+pub const CTRL_ATTR_OP_FLAGS: ::c_int = 2;
+
+pub const CTRL_ATTR_MCAST_GRP_UNSPEC: ::c_int = 0;
+pub const CTRL_ATTR_MCAST_GRP_NAME: ::c_int = 1;
+pub const CTRL_ATTR_MCAST_GRP_ID: ::c_int = 2;
+
f! {
pub fn CPU_ZERO(cpuset: &mut cpu_set_t) -> () {
for slot in cpuset.bits.iter_mut() {
diff --git a/src/unix/notbsd/linux/other/mod.rs b/src/unix/notbsd/linux/other/mod.rs
index a94dcb2875..f842d3f3db 100644
--- a/src/unix/notbsd/linux/other/mod.rs
+++ b/src/unix/notbsd/linux/other/mod.rs
@@ -178,6 +178,44 @@ s! {
pub fordblks: ::c_int,
pub keepcost: ::c_int,
}
+
+ pub struct nlmsghdr {
+ nlmsg_len: u32,
+ nlmsg_type: u16,
+ nlmsg_flags: u16,
+ nlmsg_seq: u32,
+ nlmsg_pid: u32,
+ }
+
+ pub struct nlmsgerr {
+ error: ::c_int,
+ msg: nlmsghdr,
+ }
+
+ pub struct nl_pktinfo {
+ group: u32,
+ }
+
+ pub struct nl_mmap_req {
+ nm_block_size: ::c_uint,
+ nm_block_nr: ::c_uint,
+ nm_frame_size: ::c_uint,
+ nm_frame_nr: ::c_uint,
+ }
+
+ pub struct nl_mmap_hdr {
+ nm_status: ::c_uint,
+ nm_len: ::c_uint,
+ nm_group: u32,
+ nm_pid: u32,
+ nm_uid: u32,
+ nm_gid: u32,
+ }
+
+ pub struct nlattr {
+ nla_len: u16,
+ nla_type: u16,
+ }
}
pub const __UT_LINESIZE: usize = 32;
@@ -517,12 +555,6 @@ pub const NLM_F_EXCL: ::c_int = 0x200;
pub const NLM_F_CREATE: ::c_int = 0x400;
pub const NLM_F_APPEND: ::c_int = 0x800;
-pub const NLMSG_NOOP: ::c_int = 0x1;
-pub const NLMSG_ERROR: ::c_int = 0x2;
-pub const NLMSG_DONE: ::c_int = 0x3;
-pub const NLMSG_OVERRUN: ::c_int = 0x4;
-pub const NLMSG_MIN_TYPE: ::c_int = 0x10;
-
pub const NETLINK_ADD_MEMBERSHIP: ::c_int = 1;
pub const NETLINK_DROP_MEMBERSHIP: ::c_int = 2;
pub const NETLINK_PKTINFO: ::c_int = 3;
@@ -538,6 +570,13 @@ pub const NLA_F_NESTED: ::c_int = 1 << 15;
pub const NLA_F_NET_BYTEORDER: ::c_int = 1 << 14;
pub const NLA_TYPE_MASK: ::c_int = !(NLA_F_NESTED | NLA_F_NET_BYTEORDER);
+pub const NLA_ALIGNTO: ::c_int = 4;
+
+pub const GENL_UNS_ADMIN_PERM: ::c_int = 0x10;
+
+pub const GENL_ID_VFS_DQUOT: ::c_int = ::NLMSG_MIN_TYPE + 1;
+pub const GENL_ID_PMCRAID: ::c_int = ::NLMSG_MIN_TYPE + 2;
+
pub const TIOCM_LE: ::c_int = 0x001;
pub const TIOCM_DTR: ::c_int = 0x002;
pub const TIOCM_RTS: ::c_int = 0x004;
@@ -586,13 +625,22 @@ pub const NFPROTO_IPV6: ::c_int = 10;
pub const NFPROTO_DECNET: ::c_int = 12;
pub const NFPROTO_NUMPROTO: ::c_int = 13;
-pub const NFT_TABLE_MAXNAMELEN: ::c_int = 32;
-pub const NFT_CHAIN_MAXNAMELEN: ::c_int = 32;
-pub const NFT_SET_MAXNAMELEN: ::c_int = 32;
-cfg_if! {
- if #[cfg(not(target_arch = "sparc64"))] {
+cfg_if!{
+ if #[cfg(any(target_arch = "arm", target_arch = "powerpc",
+ target_arch = "powerpc64", target_arch = "aarch64"))] {
+ pub const NFT_TABLE_MAXNAMELEN: ::c_int = 32;
+ pub const NFT_CHAIN_MAXNAMELEN: ::c_int = 32;
+ pub const NFT_SET_MAXNAMELEN: ::c_int = 32;
pub const NFT_OBJ_MAXNAMELEN: ::c_int = 32;
+ } else if #[cfg(target_arch = "sparc64")] {
+ pub const NFT_TABLE_MAXNAMELEN: ::c_int = 32;
+ pub const NFT_CHAIN_MAXNAMELEN: ::c_int = 32;
+ pub const NFT_SET_MAXNAMELEN: ::c_int = 32;
} else {
+ pub const NFT_TABLE_MAXNAMELEN: ::c_int = 256;
+ pub const NFT_CHAIN_MAXNAMELEN: ::c_int = 256;
+ pub const NFT_SET_MAXNAMELEN: ::c_int = 256;
+ pub const NFT_OBJ_MAXNAMELEN: ::c_int = 256;
}
}
pub const NFT_USERDATA_MAXLEN: ::c_int = 256;
@@ -643,6 +691,12 @@ cfg_if! {
}
}
+f! {
+ pub fn NLA_ALIGN(len: ::c_int) -> ::c_int {
+ return ((len) + NLA_ALIGNTO - 1) & !(NLA_ALIGNTO - 1)
+ }
+}
+
extern {
pub fn utmpxname(file: *const ::c_char) -> ::c_int;
pub fn getutxent() -> *mut utmpx;