Skip to content

Commit 0803fae

Browse files
committed
linux: Restructure netlink to src/new
Move netlink types defined in UAPI to the `new` module. This resolves the following build error on uclibc platforms: error[E0425]: cannot find value `NLMSG_MIN_TYPE` in the crate root --> /home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/libc-0.2.179/src/unix/linux_like/linux/mod.rs:1999:48 | 1999 | pub const NFNL_MSG_BATCH_BEGIN: c_int = crate::NLMSG_MIN_TYPE; | ^^^^^^^^^^^^^^ not found in the crate root | note: found an item that was configured out --> /home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/libc-0.2.179/src/unix/linux_like/linux_l4re_shared.rs:1222:19 | 1200 | if #[cfg(not(target_env = "uclibc"))] { | ----------------------- the item is gated here ... 1222 | pub const NLMSG_MIN_TYPE: c_int = 0x10; | ^^^^^^^^^^^^^^ Fixes: 2fe1d91 ("Separate L4Re from Linux code and enable tests") (backport <#4915>) (cherry picked from commit e0ed72d)
1 parent 72f4c1a commit 0803fae

9 files changed

Lines changed: 153 additions & 124 deletions

File tree

libc-test/semver/linux-gnu.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ LOGIN_PROCESS
117117
Lmid_t
118118
MADV_COLLAPSE
119119
MAXTC
120-
MAX_LINKS
121120
MINIX2_SUPER_MAGIC
122121
MINIX2_SUPER_MAGIC2
123122
MINIX3_SUPER_MAGIC
@@ -637,9 +636,6 @@ malloc_usable_size
637636
mallopt
638637
mempcpy
639638
mq_notify
640-
nl_mmap_hdr
641-
nl_mmap_req
642-
nl_pktinfo
643639
ntp_adjtime
644640
ntp_gettime
645641
ntptimeval

libc-test/semver/linux.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,6 +1641,7 @@ MAP_TYPE
16411641
MAXTTL
16421642
MAX_ADDR_LEN
16431643
MAX_IPOPTLEN
1644+
MAX_LINKS
16441645
MCAST_BLOCK_SOURCE
16451646
MCAST_EXCLUDE
16461647
MCAST_INCLUDE
@@ -4128,6 +4129,9 @@ nice
41284129
nl_item
41294130
nl_langinfo
41304131
nl_langinfo_l
4132+
nl_mmap_hdr
4133+
nl_mmap_req
4134+
nl_pktinfo
41314135
nlattr
41324136
nlmsgerr
41334137
nlmsghdr

src/new/linux_uapi/linux/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
55
pub(crate) mod can;
66
pub(crate) mod keyctl;
7+
pub(crate) mod netlink;
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
//! Header: `uapi/linux/netlink.h`
2+
3+
use crate::prelude::*;
4+
5+
pub const NETLINK_ROUTE: c_int = 0;
6+
pub const NETLINK_UNUSED: c_int = 1;
7+
pub const NETLINK_USERSOCK: c_int = 2;
8+
pub const NETLINK_FIREWALL: c_int = 3;
9+
pub const NETLINK_SOCK_DIAG: c_int = 4;
10+
pub const NETLINK_NFLOG: c_int = 5;
11+
pub const NETLINK_XFRM: c_int = 6;
12+
pub const NETLINK_SELINUX: c_int = 7;
13+
pub const NETLINK_ISCSI: c_int = 8;
14+
pub const NETLINK_AUDIT: c_int = 9;
15+
pub const NETLINK_FIB_LOOKUP: c_int = 10;
16+
pub const NETLINK_CONNECTOR: c_int = 11;
17+
pub const NETLINK_NETFILTER: c_int = 12;
18+
pub const NETLINK_IP6_FW: c_int = 13;
19+
pub const NETLINK_DNRTMSG: c_int = 14;
20+
pub const NETLINK_KOBJECT_UEVENT: c_int = 15;
21+
pub const NETLINK_GENERIC: c_int = 16;
22+
pub const NETLINK_SCSITRANSPORT: c_int = 18;
23+
pub const NETLINK_ECRYPTFS: c_int = 19;
24+
pub const NETLINK_RDMA: c_int = 20;
25+
pub const NETLINK_CRYPTO: c_int = 21;
26+
27+
pub const NETLINK_INET_DIAG: c_int = NETLINK_SOCK_DIAG;
28+
29+
pub const MAX_LINKS: c_int = 32;
30+
31+
s! {
32+
pub struct sockaddr_nl {
33+
pub nl_family: crate::sa_family_t,
34+
nl_pad: Padding<c_ushort>,
35+
pub nl_pid: u32,
36+
pub nl_groups: u32,
37+
}
38+
39+
pub struct nlmsghdr {
40+
pub nlmsg_len: u32,
41+
pub nlmsg_type: u16,
42+
pub nlmsg_flags: u16,
43+
pub nlmsg_seq: u32,
44+
pub nlmsg_pid: u32,
45+
}
46+
}
47+
48+
pub const NLM_F_REQUEST: c_int = 1;
49+
pub const NLM_F_MULTI: c_int = 2;
50+
pub const NLM_F_ACK: c_int = 4;
51+
pub const NLM_F_ECHO: c_int = 8;
52+
pub const NLM_F_DUMP_INTR: c_int = 16;
53+
pub const NLM_F_DUMP_FILTERED: c_int = 32;
54+
55+
pub const NLM_F_ROOT: c_int = 0x100;
56+
pub const NLM_F_MATCH: c_int = 0x200;
57+
pub const NLM_F_ATOMIC: c_int = 0x400;
58+
pub const NLM_F_DUMP: c_int = NLM_F_ROOT | NLM_F_MATCH;
59+
60+
pub const NLM_F_REPLACE: c_int = 0x100;
61+
pub const NLM_F_EXCL: c_int = 0x200;
62+
pub const NLM_F_CREATE: c_int = 0x400;
63+
pub const NLM_F_APPEND: c_int = 0x800;
64+
65+
pub const NLM_F_NONREC: c_int = 0x100;
66+
67+
pub const NLM_F_CAPPED: c_int = 0x100;
68+
pub const NLM_F_ACK_TLVS: c_int = 0x200;
69+
70+
pub const NLMSG_NOOP: c_int = 0x1;
71+
pub const NLMSG_ERROR: c_int = 0x2;
72+
pub const NLMSG_DONE: c_int = 0x3;
73+
pub const NLMSG_OVERRUN: c_int = 0x4;
74+
75+
pub const NLMSG_MIN_TYPE: c_int = 0x10;
76+
77+
s! {
78+
pub struct nlmsgerr {
79+
pub error: c_int,
80+
pub msg: nlmsghdr,
81+
}
82+
}
83+
84+
pub const NETLINK_ADD_MEMBERSHIP: c_int = 1;
85+
pub const NETLINK_DROP_MEMBERSHIP: c_int = 2;
86+
pub const NETLINK_PKTINFO: c_int = 3;
87+
pub const NETLINK_BROADCAST_ERROR: c_int = 4;
88+
pub const NETLINK_NO_ENOBUFS: c_int = 5;
89+
pub const NETLINK_RX_RING: c_int = 6;
90+
pub const NETLINK_TX_RING: c_int = 7;
91+
pub const NETLINK_LISTEN_ALL_NSID: c_int = 8;
92+
pub const NETLINK_LIST_MEMBERSHIPS: c_int = 9;
93+
pub const NETLINK_CAP_ACK: c_int = 10;
94+
pub const NETLINK_EXT_ACK: c_int = 11;
95+
pub const NETLINK_GET_STRICT_CHK: c_int = 12;
96+
97+
s! {
98+
pub struct nl_pktinfo {
99+
pub group: u32,
100+
}
101+
102+
pub struct nl_mmap_req {
103+
pub nm_block_size: c_uint,
104+
pub nm_block_nr: c_uint,
105+
pub nm_frame_size: c_uint,
106+
pub nm_frame_nr: c_uint,
107+
}
108+
109+
pub struct nl_mmap_hdr {
110+
pub nm_status: c_uint,
111+
pub nm_len: c_uint,
112+
pub nm_group: u32,
113+
pub nm_pid: u32,
114+
pub nm_uid: u32,
115+
pub nm_gid: u32,
116+
}
117+
}
118+
119+
s! {
120+
pub struct nlattr {
121+
pub nla_len: u16,
122+
pub nla_type: u16,
123+
}
124+
}
125+
126+
pub const NLA_F_NESTED: c_int = 1 << 15;
127+
pub const NLA_F_NET_BYTEORDER: c_int = 1 << 14;
128+
pub const NLA_TYPE_MASK: c_int = !(NLA_F_NESTED | NLA_F_NET_BYTEORDER);
129+
130+
pub const NLA_ALIGNTO: c_int = 4;
131+
132+
f! {
133+
pub fn NLA_ALIGN(len: c_int) -> c_int {
134+
return ((len) + NLA_ALIGNTO - 1) & !(NLA_ALIGNTO - 1);
135+
}
136+
}

src/new/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ cfg_if! {
181181
pub use linux::can::raw::*;
182182
pub use linux::can::*;
183183
pub use linux::keyctl::*;
184+
pub use linux::netlink::*;
184185
#[cfg(target_env = "gnu")]
185186
pub use net::route::*;
186187
} else if #[cfg(target_vendor = "apple")] {

src/unix/linux_like/l4re/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,16 @@ pub const TIOCGICOUNT: Ioctl = 0x545D;
186186

187187
pub const BLKSSZGET: Ioctl = 0x1268;
188188

189+
cfg_if! {
190+
if #[cfg(not(target_env = "uclibc"))] {
191+
pub const NLMSG_NOOP: c_int = 0x1;
192+
pub const NLMSG_ERROR: c_int = 0x2;
193+
pub const NLMSG_DONE: c_int = 0x3;
194+
pub const NLMSG_OVERRUN: c_int = 0x4;
195+
pub const NLMSG_MIN_TYPE: c_int = 0x10;
196+
}
197+
}
198+
189199
cfg_if! {
190200
if #[cfg(target_env = "uclibc")] {
191201
mod uclibc;

src/unix/linux_like/linux/gnu/mod.rs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -133,26 +133,6 @@ s! {
133133
pub keepcost: size_t,
134134
}
135135

136-
pub struct nl_pktinfo {
137-
pub group: u32,
138-
}
139-
140-
pub struct nl_mmap_req {
141-
pub nm_block_size: c_uint,
142-
pub nm_block_nr: c_uint,
143-
pub nm_frame_size: c_uint,
144-
pub nm_frame_nr: c_uint,
145-
}
146-
147-
pub struct nl_mmap_hdr {
148-
pub nm_status: c_uint,
149-
pub nm_len: c_uint,
150-
pub nm_group: u32,
151-
pub nm_pid: u32,
152-
pub nm_uid: u32,
153-
pub nm_gid: u32,
154-
}
155-
156136
pub struct ntptimeval {
157137
pub time: crate::timeval,
158138
pub maxerror: c_long,
@@ -810,8 +790,6 @@ pub const NDA_SRC_VNI: c_ushort = 11;
810790
pub const UNAME26: c_int = 0x0020000;
811791
pub const FDPIC_FUNCPTRS: c_int = 0x0080000;
812792

813-
pub const MAX_LINKS: c_int = 32;
814-
815793
pub const GENL_UNS_ADMIN_PERM: c_int = 0x10;
816794

817795
pub const GENL_ID_VFS_DQUOT: c_int = crate::NLMSG_MIN_TYPE + 1;

src/unix/linux_like/linux/mod.rs

Lines changed: 1 addition & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -473,24 +473,6 @@ s! {
473473
pub newfd_flags: __u32,
474474
}
475475

476-
pub struct nlmsghdr {
477-
pub nlmsg_len: u32,
478-
pub nlmsg_type: u16,
479-
pub nlmsg_flags: u16,
480-
pub nlmsg_seq: u32,
481-
pub nlmsg_pid: u32,
482-
}
483-
484-
pub struct nlmsgerr {
485-
pub error: c_int,
486-
pub msg: nlmsghdr,
487-
}
488-
489-
pub struct nlattr {
490-
pub nla_len: u16,
491-
pub nla_type: u16,
492-
}
493-
494476
pub struct in6_ifreq {
495477
pub ifr6_addr: crate::in6_addr,
496478
pub ifr6_prefixlen: u32,
@@ -1063,13 +1045,6 @@ s! {
10631045
pub token_count: crate::__u32,
10641046
}
10651047

1066-
pub struct sockaddr_nl {
1067-
pub nl_family: crate::sa_family_t,
1068-
nl_pad: Padding<c_ushort>,
1069-
pub nl_pid: u32,
1070-
pub nl_groups: u32,
1071-
}
1072-
10731048
pub struct sockaddr_alg {
10741049
pub salg_family: crate::sa_family_t,
10751050
pub salg_type: [c_uchar; 14],
@@ -2653,70 +2628,8 @@ pub const NDA_VNI: c_ushort = 7;
26532628
pub const NDA_IFINDEX: c_ushort = 8;
26542629

26552630
// linux/netlink.h
2656-
pub const NLA_ALIGNTO: c_int = 4;
2657-
2658-
pub const NETLINK_ROUTE: c_int = 0;
2659-
pub const NETLINK_UNUSED: c_int = 1;
2660-
pub const NETLINK_USERSOCK: c_int = 2;
2661-
pub const NETLINK_FIREWALL: c_int = 3;
2662-
pub const NETLINK_SOCK_DIAG: c_int = 4;
2663-
pub const NETLINK_NFLOG: c_int = 5;
2664-
pub const NETLINK_XFRM: c_int = 6;
2665-
pub const NETLINK_SELINUX: c_int = 7;
2666-
pub const NETLINK_ISCSI: c_int = 8;
2667-
pub const NETLINK_AUDIT: c_int = 9;
2668-
pub const NETLINK_FIB_LOOKUP: c_int = 10;
2669-
pub const NETLINK_CONNECTOR: c_int = 11;
2670-
pub const NETLINK_NETFILTER: c_int = 12;
2671-
pub const NETLINK_IP6_FW: c_int = 13;
2672-
pub const NETLINK_DNRTMSG: c_int = 14;
2673-
pub const NETLINK_KOBJECT_UEVENT: c_int = 15;
2674-
pub const NETLINK_GENERIC: c_int = 16;
2675-
pub const NETLINK_SCSITRANSPORT: c_int = 18;
2676-
pub const NETLINK_ECRYPTFS: c_int = 19;
2677-
pub const NETLINK_RDMA: c_int = 20;
2678-
pub const NETLINK_CRYPTO: c_int = 21;
2679-
pub const NETLINK_INET_DIAG: c_int = NETLINK_SOCK_DIAG;
2680-
2681-
pub const NLM_F_REQUEST: c_int = 1;
2682-
pub const NLM_F_MULTI: c_int = 2;
2683-
pub const NLM_F_ACK: c_int = 4;
2684-
pub const NLM_F_ECHO: c_int = 8;
2685-
pub const NLM_F_DUMP_INTR: c_int = 16;
2686-
pub const NLM_F_DUMP_FILTERED: c_int = 32;
2687-
2688-
pub const NLM_F_ROOT: c_int = 0x100;
2689-
pub const NLM_F_MATCH: c_int = 0x200;
2690-
pub const NLM_F_ATOMIC: c_int = 0x400;
2691-
pub const NLM_F_DUMP: c_int = NLM_F_ROOT | NLM_F_MATCH;
2692-
2693-
pub const NLM_F_REPLACE: c_int = 0x100;
2694-
pub const NLM_F_EXCL: c_int = 0x200;
2695-
pub const NLM_F_CREATE: c_int = 0x400;
2696-
pub const NLM_F_APPEND: c_int = 0x800;
2697-
2698-
pub const NLM_F_NONREC: c_int = 0x100;
2699-
pub const NLM_F_BULK: c_int = 0x200;
27002631

2701-
pub const NLM_F_CAPPED: c_int = 0x100;
2702-
pub const NLM_F_ACK_TLVS: c_int = 0x200;
2703-
2704-
pub const NETLINK_ADD_MEMBERSHIP: c_int = 1;
2705-
pub const NETLINK_DROP_MEMBERSHIP: c_int = 2;
2706-
pub const NETLINK_PKTINFO: c_int = 3;
2707-
pub const NETLINK_BROADCAST_ERROR: c_int = 4;
2708-
pub const NETLINK_NO_ENOBUFS: c_int = 5;
2709-
pub const NETLINK_RX_RING: c_int = 6;
2710-
pub const NETLINK_TX_RING: c_int = 7;
2711-
pub const NETLINK_LISTEN_ALL_NSID: c_int = 8;
2712-
pub const NETLINK_LIST_MEMBERSHIPS: c_int = 9;
2713-
pub const NETLINK_CAP_ACK: c_int = 10;
2714-
pub const NETLINK_EXT_ACK: c_int = 11;
2715-
pub const NETLINK_GET_STRICT_CHK: c_int = 12;
2716-
2717-
pub const NLA_F_NESTED: c_int = 1 << 15;
2718-
pub const NLA_F_NET_BYTEORDER: c_int = 1 << 14;
2719-
pub const NLA_TYPE_MASK: c_int = !(NLA_F_NESTED | NLA_F_NET_BYTEORDER);
2632+
pub const NLM_F_BULK: c_int = 0x200;
27202633

27212634
// linux/rtnetlink.h
27222635
pub const TCA_UNSPEC: c_ushort = 0;
@@ -4056,10 +3969,6 @@ pub const SI_DETHREAD: c_int = -7;
40563969
pub const TRAP_PERF: c_int = 6;
40573970

40583971
f! {
4059-
pub fn NLA_ALIGN(len: c_int) -> c_int {
4060-
return ((len) + NLA_ALIGNTO - 1) & !(NLA_ALIGNTO - 1);
4061-
}
4062-
40633972
pub fn SCTP_PR_INDEX(policy: c_int) -> c_int {
40643973
policy >> (4 - 1)
40653974
}

src/unix/linux_like/linux_l4re_shared.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,12 +1214,6 @@ cfg_if! {
12141214
pub const MFD_HUGE_16GB: c_uint = 0x88000000;
12151215
pub const MFD_HUGE_MASK: c_uint = 63;
12161216
pub const MFD_HUGE_SHIFT: c_uint = 26;
1217-
1218-
pub const NLMSG_NOOP: c_int = 0x1;
1219-
pub const NLMSG_ERROR: c_int = 0x2;
1220-
pub const NLMSG_DONE: c_int = 0x3;
1221-
pub const NLMSG_OVERRUN: c_int = 0x4;
1222-
pub const NLMSG_MIN_TYPE: c_int = 0x10;
12231217
}
12241218
}
12251219

0 commit comments

Comments
 (0)