libc/new/linux_uapi/linux/
netlink.rs1use crate::prelude::*;
4
5pub const NETLINK_ROUTE: c_int = 0;
6pub const NETLINK_UNUSED: c_int = 1;
7pub const NETLINK_USERSOCK: c_int = 2;
8pub const NETLINK_FIREWALL: c_int = 3;
9pub const NETLINK_SOCK_DIAG: c_int = 4;
10pub const NETLINK_NFLOG: c_int = 5;
11pub const NETLINK_XFRM: c_int = 6;
12pub const NETLINK_SELINUX: c_int = 7;
13pub const NETLINK_ISCSI: c_int = 8;
14pub const NETLINK_AUDIT: c_int = 9;
15pub const NETLINK_FIB_LOOKUP: c_int = 10;
16pub const NETLINK_CONNECTOR: c_int = 11;
17pub const NETLINK_NETFILTER: c_int = 12;
18pub const NETLINK_IP6_FW: c_int = 13;
19pub const NETLINK_DNRTMSG: c_int = 14;
20pub const NETLINK_KOBJECT_UEVENT: c_int = 15;
21pub const NETLINK_GENERIC: c_int = 16;
22pub const NETLINK_SCSITRANSPORT: c_int = 18;
23pub const NETLINK_ECRYPTFS: c_int = 19;
24pub const NETLINK_RDMA: c_int = 20;
25pub const NETLINK_CRYPTO: c_int = 21;
26
27pub const NETLINK_INET_DIAG: c_int = NETLINK_SOCK_DIAG;
28
29pub const MAX_LINKS: c_int = 32;
30
31s! {
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
48pub const NLM_F_REQUEST: c_int = 1;
49pub const NLM_F_MULTI: c_int = 2;
50pub const NLM_F_ACK: c_int = 4;
51pub const NLM_F_ECHO: c_int = 8;
52pub const NLM_F_DUMP_INTR: c_int = 16;
53pub const NLM_F_DUMP_FILTERED: c_int = 32;
54
55pub const NLM_F_ROOT: c_int = 0x100;
56pub const NLM_F_MATCH: c_int = 0x200;
57pub const NLM_F_ATOMIC: c_int = 0x400;
58pub const NLM_F_DUMP: c_int = NLM_F_ROOT | NLM_F_MATCH;
59
60pub const NLM_F_REPLACE: c_int = 0x100;
61pub const NLM_F_EXCL: c_int = 0x200;
62pub const NLM_F_CREATE: c_int = 0x400;
63pub const NLM_F_APPEND: c_int = 0x800;
64
65pub const NLM_F_NONREC: c_int = 0x100;
66
67pub const NLM_F_CAPPED: c_int = 0x100;
68pub const NLM_F_ACK_TLVS: c_int = 0x200;
69
70const NLMSG_ALIGNTO: c_uint = 4;
71
72const NLMSG_HDRLEN: c_int = NLMSG_ALIGN(size_of::<nlmsghdr>());
73
74f! {
75 pub const safe fn NLMSG_ALIGN(size: size_t) -> c_int {
76 ((size + NLMSG_ALIGNTO as size_t - 1) & !(NLMSG_ALIGNTO as size_t - 1)) as c_int
77 }
78
79 pub const safe fn NLMSG_LENGTH(size: size_t) -> c_int {
80 size as c_int + NLMSG_HDRLEN
81 }
82
83 pub const safe fn NLMSG_SPACE(size: size_t) -> c_int {
84 NLMSG_ALIGN(NLMSG_LENGTH(size) as size_t)
85 }
86
87 pub unsafe fn NLMSG_DATA(nlh: *mut nlmsghdr) -> *mut c_void {
88 nlh.cast::<c_char>()
89 .wrapping_add(NLMSG_HDRLEN as usize)
90 .cast::<c_void>()
91 }
92
93 pub unsafe fn NLMSG_NEXT(nlh: *mut nlmsghdr, size: &mut c_int) -> *mut nlmsghdr {
94 *size -= NLMSG_ALIGN((*nlh).nlmsg_len as size_t);
95 nlh.cast::<c_char>()
96 .wrapping_add(NLMSG_ALIGN((*nlh).nlmsg_len as size_t) as usize)
97 .cast::<nlmsghdr>()
98 }
99
100 pub unsafe fn NLMSG_OK(nlh: *const nlmsghdr, size: c_int) -> bool {
101 size >= size_of::<nlmsghdr>() as c_int
102 && (*nlh).nlmsg_len >= size_of::<nlmsghdr>() as c_uint
103 && (*nlh).nlmsg_len <= size as c_uint
104 }
105
106 pub unsafe fn NLMSG_PAYLOAD(nlh: *const nlmsghdr, size: c_int) -> c_int {
107 (*nlh).nlmsg_len as c_int - NLMSG_SPACE(size as size_t)
108 }
109}
110
111pub const NLMSG_NOOP: c_int = 0x1;
112pub const NLMSG_ERROR: c_int = 0x2;
113pub const NLMSG_DONE: c_int = 0x3;
114pub const NLMSG_OVERRUN: c_int = 0x4;
115
116pub const NLMSG_MIN_TYPE: c_int = 0x10;
117
118s! {
119 pub struct nlmsgerr {
120 pub error: c_int,
121 pub msg: nlmsghdr,
122 }
123}
124
125pub const NETLINK_ADD_MEMBERSHIP: c_int = 1;
126pub const NETLINK_DROP_MEMBERSHIP: c_int = 2;
127pub const NETLINK_PKTINFO: c_int = 3;
128pub const NETLINK_BROADCAST_ERROR: c_int = 4;
129pub const NETLINK_NO_ENOBUFS: c_int = 5;
130pub const NETLINK_RX_RING: c_int = 6;
131pub const NETLINK_TX_RING: c_int = 7;
132pub const NETLINK_LISTEN_ALL_NSID: c_int = 8;
133pub const NETLINK_LIST_MEMBERSHIPS: c_int = 9;
134pub const NETLINK_CAP_ACK: c_int = 10;
135pub const NETLINK_EXT_ACK: c_int = 11;
136pub const NETLINK_GET_STRICT_CHK: c_int = 12;
137
138s! {
139 pub struct nl_pktinfo {
140 pub group: u32,
141 }
142
143 pub struct nl_mmap_req {
144 pub nm_block_size: c_uint,
145 pub nm_block_nr: c_uint,
146 pub nm_frame_size: c_uint,
147 pub nm_frame_nr: c_uint,
148 }
149
150 pub struct nl_mmap_hdr {
151 pub nm_status: c_uint,
152 pub nm_len: c_uint,
153 pub nm_group: u32,
154 pub nm_pid: u32,
155 pub nm_uid: u32,
156 pub nm_gid: u32,
157 }
158}
159
160s! {
161 pub struct nlattr {
162 pub nla_len: u16,
163 pub nla_type: u16,
164 }
165}
166
167pub const NLA_F_NESTED: c_int = 1 << 15;
168pub const NLA_F_NET_BYTEORDER: c_int = 1 << 14;
169pub const NLA_TYPE_MASK: c_int = !(NLA_F_NESTED | NLA_F_NET_BYTEORDER);
170
171pub const NLA_ALIGNTO: c_int = 4;
172
173f! {
174 pub unsafe fn NLA_ALIGN(len: c_int) -> c_int {
175 return ((len) + NLA_ALIGNTO - 1) & !(NLA_ALIGNTO - 1);
176 }
177}