Skip to content

Commit 2c97816

Browse files
committed
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!
2 parents 88c33d4 + 95befb4 commit 2c97816

File tree

5 files changed

+263
-12
lines changed

5 files changed

+263
-12
lines changed

libc-test/build.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,13 @@ fn main() {
242242
}
243243
cfg.header("sys/reboot.h");
244244
if !emscripten {
245+
cfg.header("linux/netlink.h");
246+
cfg.header("linux/genetlink.h");
245247
cfg.header("linux/netfilter_ipv4.h");
246248
cfg.header("linux/fs.h");
247249
}
248250
if !musl {
249251
cfg.header("asm/mman.h");
250-
cfg.header("linux/netlink.h");
251252
cfg.header("linux/magic.h");
252253
cfg.header("linux/reboot.h");
253254
cfg.header("linux/netfilter/nf_tables.h");

src/unix/notbsd/android/mod.rs

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,50 @@ s! {
185185
pub uid: ::uid_t,
186186
pub gid: ::gid_t,
187187
}
188+
189+
pub struct genlmsghdr {
190+
cmd: u8,
191+
version: u8,
192+
reserved: u16,
193+
}
194+
195+
pub struct nlmsghdr {
196+
nlmsg_len: u32,
197+
nlmsg_type: u16,
198+
nlmsg_flags: u16,
199+
nlmsg_seq: u32,
200+
nlmsg_pid: u32,
201+
}
202+
203+
pub struct nlmsgerr {
204+
error: ::c_int,
205+
msg: nlmsghdr,
206+
}
207+
208+
pub struct nl_pktinfo {
209+
group: u32,
210+
}
211+
212+
pub struct nl_mmap_req {
213+
nm_block_size: ::c_uint,
214+
nm_block_nr: ::c_uint,
215+
nm_frame_size: ::c_uint,
216+
nm_frame_nr: ::c_uint,
217+
}
218+
219+
pub struct nl_mmap_hdr {
220+
nm_status: ::c_uint,
221+
nm_len: ::c_uint,
222+
nm_group: u32,
223+
nm_pid: u32,
224+
nm_uid: u32,
225+
nm_gid: u32,
226+
}
227+
228+
pub struct nlattr {
229+
nla_len: u16,
230+
nla_type: u16,
231+
}
188232
}
189233

190234
pub const O_TRUNC: ::c_int = 512;
@@ -860,6 +904,49 @@ pub const NLMSG_DONE: ::c_int = 0x3;
860904
pub const NLMSG_OVERRUN: ::c_int = 0x4;
861905
pub const NLMSG_MIN_TYPE: ::c_int = 0x10;
862906

907+
pub const GENL_NAMSIZ: ::c_int = 16;
908+
909+
pub const GENL_MIN_ID: ::c_int = NLMSG_MIN_TYPE;
910+
pub const GENL_MAX_ID: ::c_int = 1023;
911+
912+
pub const GENL_ADMIN_PERM: ::c_int = 0x01;
913+
pub const GENL_CMD_CAP_DO: ::c_int = 0x02;
914+
pub const GENL_CMD_CAP_DUMP: ::c_int = 0x04;
915+
pub const GENL_CMD_CAP_HASPOL: ::c_int = 0x08;
916+
pub const GENL_UNS_ADMIN_PERM: ::c_int = 0x10;
917+
918+
pub const GENL_ID_CTRL: ::c_int = NLMSG_MIN_TYPE;
919+
pub const GENL_ID_VFS_DQUOT: ::c_int = NLMSG_MIN_TYPE + 1;
920+
pub const GENL_ID_PMCRAID: ::c_int = NLMSG_MIN_TYPE + 2;
921+
922+
pub const CTRL_CMD_UNSPEC: ::c_int = 0;
923+
pub const CTRL_CMD_NEWFAMILY: ::c_int = 1;
924+
pub const CTRL_CMD_DELFAMILY: ::c_int = 2;
925+
pub const CTRL_CMD_GETFAMILY: ::c_int = 3;
926+
pub const CTRL_CMD_NEWOPS: ::c_int = 4;
927+
pub const CTRL_CMD_DELOPS: ::c_int = 5;
928+
pub const CTRL_CMD_GETOPS: ::c_int = 6;
929+
pub const CTRL_CMD_NEWMCAST_GRP: ::c_int = 7;
930+
pub const CTRL_CMD_DELMCAST_GRP: ::c_int = 8;
931+
pub const CTRL_CMD_GETMCAST_GRP: ::c_int = 9;
932+
933+
pub const CTRL_ATTR_UNSPEC: ::c_int = 0;
934+
pub const CTRL_ATTR_FAMILY_ID: ::c_int = 1;
935+
pub const CTRL_ATTR_FAMILY_NAME: ::c_int = 2;
936+
pub const CTRL_ATTR_VERSION: ::c_int = 3;
937+
pub const CTRL_ATTR_HDRSIZE: ::c_int = 4;
938+
pub const CTRL_ATTR_MAXATTR: ::c_int = 5;
939+
pub const CTRL_ATTR_OPS: ::c_int = 6;
940+
pub const CTRL_ATTR_MCAST_GROUPS: ::c_int = 7;
941+
942+
pub const CTRL_ATTR_OP_UNSPEC: ::c_int = 0;
943+
pub const CTRL_ATTR_OP_ID: ::c_int = 1;
944+
pub const CTRL_ATTR_OP_FLAGS: ::c_int = 2;
945+
946+
pub const CTRL_ATTR_MCAST_GRP_UNSPEC: ::c_int = 0;
947+
pub const CTRL_ATTR_MCAST_GRP_NAME: ::c_int = 1;
948+
pub const CTRL_ATTR_MCAST_GRP_ID: ::c_int = 2;
949+
863950
pub const NETLINK_ADD_MEMBERSHIP: ::c_int = 1;
864951
pub const NETLINK_DROP_MEMBERSHIP: ::c_int = 2;
865952
pub const NETLINK_PKTINFO: ::c_int = 3;
@@ -879,6 +966,8 @@ pub const NLA_F_NESTED: ::c_int = 1 << 15;
879966
pub const NLA_F_NET_BYTEORDER: ::c_int = 1 << 14;
880967
pub const NLA_TYPE_MASK: ::c_int = !(NLA_F_NESTED | NLA_F_NET_BYTEORDER);
881968

969+
pub const NLA_ALIGNTO: ::c_int = 4;
970+
882971
pub const SIGEV_THREAD_ID: ::c_int = 4;
883972

884973
pub const CIBAUD: ::tcflag_t = 0o02003600000;
@@ -1023,6 +1112,10 @@ f! {
10231112
let mi = mi as ::dev_t;
10241113
((ma & 0xfff) << 8) | (mi & 0xff) | ((mi & 0xfff00) << 12)
10251114
}
1115+
1116+
pub fn NLA_ALIGN(len: ::c_int) -> ::c_int {
1117+
return ((len) + NLA_ALIGNTO - 1) & !(NLA_ALIGNTO - 1)
1118+
}
10261119
}
10271120

10281121
extern {

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,44 @@ s! {
3939
pub c_ispeed: ::speed_t,
4040
pub c_ospeed: ::speed_t,
4141
}
42+
43+
pub struct nlmsghdr {
44+
nlmsg_len: u32,
45+
nlmsg_type: u16,
46+
nlmsg_flags: u16,
47+
nlmsg_seq: u32,
48+
nlmsg_pid: u32,
49+
}
50+
51+
pub struct nlmsgerr {
52+
error: ::c_int,
53+
msg: nlmsghdr,
54+
}
55+
56+
pub struct nl_pktinfo {
57+
group: u32,
58+
}
59+
60+
pub struct nl_mmap_req {
61+
nm_block_size: ::c_uint,
62+
nm_block_nr: ::c_uint,
63+
nm_frame_size: ::c_uint,
64+
nm_frame_nr: ::c_uint,
65+
}
66+
67+
pub struct nl_mmap_hdr {
68+
nm_status: ::c_uint,
69+
nm_len: ::c_uint,
70+
nm_group: u32,
71+
nm_pid: u32,
72+
nm_uid: u32,
73+
nm_gid: u32,
74+
}
75+
76+
pub struct nlattr {
77+
nla_len: u16,
78+
nla_type: u16,
79+
}
4280
}
4381

4482
pub const SFD_CLOEXEC: ::c_int = 0x080000;
@@ -662,6 +700,13 @@ pub const EHWPOISON: ::c_int = 168;
662700
pub const SIGEV_THREAD_ID: ::c_int = 4;
663701
pub const EPOLLWAKEUP: ::c_int = 0x20000000;
664702

703+
pub const NLA_ALIGNTO: ::c_int = 4;
704+
705+
pub const GENL_UNS_ADMIN_PERM: ::c_int = 0x10;
706+
707+
pub const GENL_ID_VFS_DQUOT: ::c_int = ::NLMSG_MIN_TYPE + 1;
708+
pub const GENL_ID_PMCRAID: ::c_int = ::NLMSG_MIN_TYPE + 2;
709+
665710
pub const NFT_TABLE_MAXNAMELEN: ::c_int = 32;
666711
pub const NFT_CHAIN_MAXNAMELEN: ::c_int = 32;
667712
pub const NFT_SET_MAXNAMELEN: ::c_int = 32;
@@ -697,6 +742,12 @@ pub const AF_MAX: ::c_int = 42;
697742
#[doc(hidden)]
698743
pub const PF_MAX: ::c_int = AF_MAX;
699744

745+
f! {
746+
pub fn NLA_ALIGN(len: ::c_int) -> ::c_int {
747+
return ((len) + NLA_ALIGNTO - 1) & !(NLA_ALIGNTO - 1)
748+
}
749+
}
750+
700751
#[link(name = "util")]
701752
extern {
702753
pub fn sysctl(name: *mut ::c_int,

src/unix/notbsd/linux/mod.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,12 @@ s! {
483483
__policy: ::c_int,
484484
__pad: [::c_int; 16],
485485
}
486+
487+
pub struct genlmsghdr {
488+
cmd: u8,
489+
version: u8,
490+
reserved: u16,
491+
}
486492
}
487493

488494
pub const ABDAY_1: ::nl_item = 0x20000;
@@ -1264,6 +1270,52 @@ pub const POSIX_SPAWN_SETSIGMASK: ::c_int = 0x08;
12641270
pub const POSIX_SPAWN_SETSCHEDPARAM: ::c_int = 0x10;
12651271
pub const POSIX_SPAWN_SETSCHEDULER: ::c_int = 0x20;
12661272

1273+
pub const NLMSG_NOOP: ::c_int = 0x1;
1274+
pub const NLMSG_ERROR: ::c_int = 0x2;
1275+
pub const NLMSG_DONE: ::c_int = 0x3;
1276+
pub const NLMSG_OVERRUN: ::c_int = 0x4;
1277+
pub const NLMSG_MIN_TYPE: ::c_int = 0x10;
1278+
1279+
pub const GENL_NAMSIZ: ::c_int = 16;
1280+
1281+
pub const GENL_MIN_ID: ::c_int = NLMSG_MIN_TYPE;
1282+
pub const GENL_MAX_ID: ::c_int = 1023;
1283+
1284+
pub const GENL_ADMIN_PERM: ::c_int = 0x01;
1285+
pub const GENL_CMD_CAP_DO: ::c_int = 0x02;
1286+
pub const GENL_CMD_CAP_DUMP: ::c_int = 0x04;
1287+
pub const GENL_CMD_CAP_HASPOL: ::c_int = 0x08;
1288+
1289+
pub const GENL_ID_CTRL: ::c_int = NLMSG_MIN_TYPE;
1290+
1291+
pub const CTRL_CMD_UNSPEC: ::c_int = 0;
1292+
pub const CTRL_CMD_NEWFAMILY: ::c_int = 1;
1293+
pub const CTRL_CMD_DELFAMILY: ::c_int = 2;
1294+
pub const CTRL_CMD_GETFAMILY: ::c_int = 3;
1295+
pub const CTRL_CMD_NEWOPS: ::c_int = 4;
1296+
pub const CTRL_CMD_DELOPS: ::c_int = 5;
1297+
pub const CTRL_CMD_GETOPS: ::c_int = 6;
1298+
pub const CTRL_CMD_NEWMCAST_GRP: ::c_int = 7;
1299+
pub const CTRL_CMD_DELMCAST_GRP: ::c_int = 8;
1300+
pub const CTRL_CMD_GETMCAST_GRP: ::c_int = 9;
1301+
1302+
pub const CTRL_ATTR_UNSPEC: ::c_int = 0;
1303+
pub const CTRL_ATTR_FAMILY_ID: ::c_int = 1;
1304+
pub const CTRL_ATTR_FAMILY_NAME: ::c_int = 2;
1305+
pub const CTRL_ATTR_VERSION: ::c_int = 3;
1306+
pub const CTRL_ATTR_HDRSIZE: ::c_int = 4;
1307+
pub const CTRL_ATTR_MAXATTR: ::c_int = 5;
1308+
pub const CTRL_ATTR_OPS: ::c_int = 6;
1309+
pub const CTRL_ATTR_MCAST_GROUPS: ::c_int = 7;
1310+
1311+
pub const CTRL_ATTR_OP_UNSPEC: ::c_int = 0;
1312+
pub const CTRL_ATTR_OP_ID: ::c_int = 1;
1313+
pub const CTRL_ATTR_OP_FLAGS: ::c_int = 2;
1314+
1315+
pub const CTRL_ATTR_MCAST_GRP_UNSPEC: ::c_int = 0;
1316+
pub const CTRL_ATTR_MCAST_GRP_NAME: ::c_int = 1;
1317+
pub const CTRL_ATTR_MCAST_GRP_ID: ::c_int = 2;
1318+
12671319
f! {
12681320
pub fn CPU_ZERO(cpuset: &mut cpu_set_t) -> () {
12691321
for slot in cpuset.bits.iter_mut() {

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

Lines changed: 65 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,44 @@ s! {
178178
pub fordblks: ::c_int,
179179
pub keepcost: ::c_int,
180180
}
181+
182+
pub struct nlmsghdr {
183+
nlmsg_len: u32,
184+
nlmsg_type: u16,
185+
nlmsg_flags: u16,
186+
nlmsg_seq: u32,
187+
nlmsg_pid: u32,
188+
}
189+
190+
pub struct nlmsgerr {
191+
error: ::c_int,
192+
msg: nlmsghdr,
193+
}
194+
195+
pub struct nl_pktinfo {
196+
group: u32,
197+
}
198+
199+
pub struct nl_mmap_req {
200+
nm_block_size: ::c_uint,
201+
nm_block_nr: ::c_uint,
202+
nm_frame_size: ::c_uint,
203+
nm_frame_nr: ::c_uint,
204+
}
205+
206+
pub struct nl_mmap_hdr {
207+
nm_status: ::c_uint,
208+
nm_len: ::c_uint,
209+
nm_group: u32,
210+
nm_pid: u32,
211+
nm_uid: u32,
212+
nm_gid: u32,
213+
}
214+
215+
pub struct nlattr {
216+
nla_len: u16,
217+
nla_type: u16,
218+
}
181219
}
182220

183221
pub const __UT_LINESIZE: usize = 32;
@@ -517,12 +555,6 @@ pub const NLM_F_EXCL: ::c_int = 0x200;
517555
pub const NLM_F_CREATE: ::c_int = 0x400;
518556
pub const NLM_F_APPEND: ::c_int = 0x800;
519557

520-
pub const NLMSG_NOOP: ::c_int = 0x1;
521-
pub const NLMSG_ERROR: ::c_int = 0x2;
522-
pub const NLMSG_DONE: ::c_int = 0x3;
523-
pub const NLMSG_OVERRUN: ::c_int = 0x4;
524-
pub const NLMSG_MIN_TYPE: ::c_int = 0x10;
525-
526558
pub const NETLINK_ADD_MEMBERSHIP: ::c_int = 1;
527559
pub const NETLINK_DROP_MEMBERSHIP: ::c_int = 2;
528560
pub const NETLINK_PKTINFO: ::c_int = 3;
@@ -538,6 +570,13 @@ pub const NLA_F_NESTED: ::c_int = 1 << 15;
538570
pub const NLA_F_NET_BYTEORDER: ::c_int = 1 << 14;
539571
pub const NLA_TYPE_MASK: ::c_int = !(NLA_F_NESTED | NLA_F_NET_BYTEORDER);
540572

573+
pub const NLA_ALIGNTO: ::c_int = 4;
574+
575+
pub const GENL_UNS_ADMIN_PERM: ::c_int = 0x10;
576+
577+
pub const GENL_ID_VFS_DQUOT: ::c_int = ::NLMSG_MIN_TYPE + 1;
578+
pub const GENL_ID_PMCRAID: ::c_int = ::NLMSG_MIN_TYPE + 2;
579+
541580
pub const TIOCM_LE: ::c_int = 0x001;
542581
pub const TIOCM_DTR: ::c_int = 0x002;
543582
pub const TIOCM_RTS: ::c_int = 0x004;
@@ -586,13 +625,22 @@ pub const NFPROTO_IPV6: ::c_int = 10;
586625
pub const NFPROTO_DECNET: ::c_int = 12;
587626
pub const NFPROTO_NUMPROTO: ::c_int = 13;
588627

589-
pub const NFT_TABLE_MAXNAMELEN: ::c_int = 32;
590-
pub const NFT_CHAIN_MAXNAMELEN: ::c_int = 32;
591-
pub const NFT_SET_MAXNAMELEN: ::c_int = 32;
592-
cfg_if! {
593-
if #[cfg(not(target_arch = "sparc64"))] {
628+
cfg_if!{
629+
if #[cfg(any(target_arch = "arm", target_arch = "powerpc",
630+
target_arch = "powerpc64", target_arch = "aarch64"))] {
631+
pub const NFT_TABLE_MAXNAMELEN: ::c_int = 32;
632+
pub const NFT_CHAIN_MAXNAMELEN: ::c_int = 32;
633+
pub const NFT_SET_MAXNAMELEN: ::c_int = 32;
594634
pub const NFT_OBJ_MAXNAMELEN: ::c_int = 32;
635+
} else if #[cfg(target_arch = "sparc64")] {
636+
pub const NFT_TABLE_MAXNAMELEN: ::c_int = 32;
637+
pub const NFT_CHAIN_MAXNAMELEN: ::c_int = 32;
638+
pub const NFT_SET_MAXNAMELEN: ::c_int = 32;
595639
} else {
640+
pub const NFT_TABLE_MAXNAMELEN: ::c_int = 256;
641+
pub const NFT_CHAIN_MAXNAMELEN: ::c_int = 256;
642+
pub const NFT_SET_MAXNAMELEN: ::c_int = 256;
643+
pub const NFT_OBJ_MAXNAMELEN: ::c_int = 256;
596644
}
597645
}
598646
pub const NFT_USERDATA_MAXLEN: ::c_int = 256;
@@ -643,6 +691,12 @@ cfg_if! {
643691
}
644692
}
645693

694+
f! {
695+
pub fn NLA_ALIGN(len: ::c_int) -> ::c_int {
696+
return ((len) + NLA_ALIGNTO - 1) & !(NLA_ALIGNTO - 1)
697+
}
698+
}
699+
646700
extern {
647701
pub fn utmpxname(file: *const ::c_char) -> ::c_int;
648702
pub fn getutxent() -> *mut utmpx;

0 commit comments

Comments
 (0)