libnet/
sys.rs

1// Copyright 2021 Oxide Computer Company
2
3// For the moment, the code in this file stylistically follows c conventions
4// more than rust, for this reason the following warnings are disabled.
5#![allow(non_upper_case_globals)]
6#![allow(non_camel_case_types)]
7#![allow(non_snake_case)]
8#![allow(improper_ctypes)]
9#![allow(dead_code)]
10#![allow(deref_nullptr)]
11
12use libc::{in6_addr, sockaddr_in6, sockaddr_storage};
13
14use std::os::raw::{
15    c_char, c_int, c_longlong, c_uchar, c_uint, c_ulong, c_ulonglong, c_ushort,
16};
17
18pub type id_t = c_int;
19pub type uint_t = c_uint;
20pub type zoneid_t = id_t;
21pub type caddr_t = *mut c_char;
22pub type uchar_t = c_uchar;
23pub type ushort_t = c_ushort;
24pub type pid_t = c_int;
25pub type kid_t = c_int;
26pub type size_t = ulong_t;
27pub type longlong_t = c_longlong;
28pub type hrtime_t = longlong_t;
29pub type u_longlong_t = c_ulonglong;
30pub type ulong_t = c_ulong;
31
32pub const boolean_t_B_FALSE: boolean_t = 0;
33pub const boolean_t_B_TRUE: boolean_t = 1;
34pub type boolean_t = c_uint;
35
36pub const MAXMACADDRLEN: u32 = 20;
37pub const MAXPATHLEN: u32 = 1024;
38pub const MAXNAMELEN: u32 = 256;
39pub const MAXLINKNAMELEN: u32 = 32;
40pub const ETHERADDRL: u32 = 6;
41
42pub const LIFC_NOXMIT: u32 = 1;
43pub const LIFC_EXTERNAL_SOURCE: u32 = 2;
44pub const LIFC_TEMPORARY: u32 = 4;
45pub const LIFC_ALLZONES: u32 = 8;
46pub const LIFC_UNDER_IPMP: u32 = 16;
47pub const LIFC_ENABLED: u32 = 32;
48
49#[cfg(target_os = "linux")]
50type ioc_t = u64;
51#[cfg(target_os = "illumos")]
52type ioc_t = i32;
53#[cfg(target_os = "macos")]
54type ioc_t = u64;
55
56#[cfg(target_os = "linux")]
57pub type addr_family_t = u16;
58#[cfg(target_os = "illumos")]
59pub type addr_family_t = u16;
60#[cfg(target_os = "macos")]
61pub type addr_family_t = u8;
62
63pub const DLD_IOC: ioc_t = 0x0D1D;
64pub const AGGR_IOC: ioc_t = 0x0A66;
65pub const VNIC_IOC: ioc_t = 0x0171;
66pub const SIMNET_IOC: ioc_t = 0x5132;
67pub const IPTUN_IOC: ioc_t = 0x454A;
68pub const BRIDGE_IOC: ioc_t = 0xB81D;
69pub const IBPART_IOC: ioc_t = 0x6171;
70pub const TFPORT_IOC: ioc_t = 0x1d1c;
71
72pub const IOCPARM_MASK: u32 = 0xff;
73pub const IOC_OUT: u32 = 0x40000000;
74pub const IOC_IN: u32 = 0x80000000;
75pub const IOC_INOUT: u32 = IOC_OUT | IOC_IN;
76
77pub const STR: ioc_t = ('S' as ioc_t) << 8;
78pub const I_PUSH: ioc_t = STR | 0o2;
79pub const I_POP: ioc_t = STR | 0o3;
80pub const I_PLINK: ioc_t = STR | 0o26;
81pub const I_PUNLINK: ioc_t = STR | 0o27;
82pub const I_STR: ioc_t = STR | 0o10;
83
84pub const IP_MOD_NAME: &[u8; 3] = b"ip\0";
85pub const ARP_MOD_NAME: &[u8; 4] = b"arp\0";
86
87pub type nvlist_t = nvlist;
88#[repr(C)]
89#[derive(Debug, Copy, Clone)]
90pub struct nvlist {
91    pub nvl_version: i32,
92    pub nvl_nvflag: u32,
93    pub nvl_priv: u64,
94    pub nvl_flag: u32,
95    pub nvl_pad: i32,
96}
97
98macro_rules! DLD_IOC_CMD {
99    ($modid:expr, $cmdid:expr) => {
100        ($modid << 16) | $cmdid
101    };
102}
103
104macro_rules! DLDIOC {
105    ($cmdid:expr) => {
106        DLD_IOC_CMD!(DLD_IOC, $cmdid)
107    };
108}
109
110macro_rules! IOW {
111    ($x:expr, $y:expr, $t:ty) => {
112        IOC_IN
113            | (std::mem::size_of::<$t>() as u32 & IOCPARM_MASK) << 16
114            | ($x as u32) << 8
115            | $y
116    };
117}
118
119macro_rules! IOWR {
120    ($x:expr, $y:expr, $t:ty) => {
121        IOC_INOUT
122            | (std::mem::size_of::<$t>() as u32 & IOCPARM_MASK) << 16
123            | ($x as u32) << 8
124            | $y
125    };
126}
127
128macro_rules! IOWRN {
129    ($x:expr, $y:expr, $t:expr) => {
130        IOC_INOUT | ($t & IOCPARM_MASK) << 16 | ($x as u32) << 8 | $y
131    };
132}
133
134pub type sa_family_t = u16;
135#[repr(C)]
136#[derive(Debug, Copy, Clone)]
137pub struct lifnum {
138    pub lifn_family: sa_family_t,
139    pub lifn_flags: ::std::os::raw::c_int,
140    pub lifn_count: ::std::os::raw::c_int,
141}
142
143#[repr(C)]
144#[derive(Copy, Clone)]
145pub struct lifreq {
146    pub lifr_name: [::std::os::raw::c_char; 32usize],
147    pub lifr_lifru1: lifreq_ru1,
148    pub lifr_type: uint_t,
149    pub lifr_lifru: lifreq_ru,
150}
151
152impl lifreq {
153    pub fn new() -> Self {
154        lifreq {
155            lifr_name: [0; 32usize],
156            lifr_lifru1: lifreq_ru1 { lifru_ppa: 0 },
157            lifr_type: 0,
158            lifr_lifru: lifreq_ru { lifru_flags: 0 },
159        }
160    }
161}
162
163impl Default for lifreq {
164    fn default() -> lifreq {
165        lifreq {
166            lifr_name: [0; 32usize],
167            lifr_lifru1: lifreq_ru1 { lifru_ppa: 0 },
168            lifr_type: 0,
169            lifr_lifru: lifreq_ru { lifru_flags: 0 },
170        }
171    }
172}
173
174#[repr(C)]
175#[derive(Copy, Clone)]
176pub union lifreq_ru1 {
177    pub lifru_addrlen: ::std::os::raw::c_int,
178    pub lifru_ppa: uint_t,
179}
180
181#[repr(C)]
182#[derive(Copy, Clone)]
183pub union lifreq_ru {
184    pub lifru_addr: sockaddr_storage,
185    pub lifru_dstaddr: sockaddr_storage,
186    pub lifru_broadaddr: sockaddr_storage,
187    pub lifru_token: sockaddr_storage,
188    pub lifru_subnet: sockaddr_storage,
189    pub lifru_index: ::std::os::raw::c_int,
190    pub lifru_flags: u64,
191    pub lifru_metric: ::std::os::raw::c_int,
192    pub lifru_mtu: uint_t,
193    pub lif_muxid: [::std::os::raw::c_int; 2usize],
194    pub lifru_nd_req: lif_nd_req,
195    pub lifru_ifinfo_req: lif_ifinfo_req,
196    pub lifru_groupname: [::std::os::raw::c_char; 32usize],
197    pub lifru_binding: [::std::os::raw::c_char; 32usize],
198    pub lifru_zoneid: zoneid_t,
199    pub lifru_dadstate: uint_t,
200}
201
202#[repr(C)]
203#[derive(Copy, Clone)]
204pub struct lifconf {
205    pub lifc_family: sa_family_t,
206    pub lifc_flags: ::std::os::raw::c_int,
207    pub lifc_len: ::std::os::raw::c_int,
208    pub lifc_lifcu: lifconf_lifcu,
209}
210#[repr(C)]
211#[derive(Copy, Clone)]
212pub union lifconf_lifcu {
213    pub lifcu_buf: caddr_t,
214    pub lifcu_req: *mut lifreq,
215}
216
217#[repr(C)]
218#[derive(Debug, Copy, Clone)]
219pub struct lif_ifinfo_req {
220    pub lir_maxhops: u8,
221    pub lir_reachtime: u32,
222    pub lir_reachretrans: u32,
223    pub lir_maxmtu: u32,
224}
225
226#[repr(C)]
227#[derive(Copy, Clone)]
228pub struct lif_nd_req {
229    pub lnr_addr: sockaddr_storage,
230    pub lnr_state_create: u8,
231    pub lnr_state_same_lla: u8,
232    pub lnr_state_diff_lla: u8,
233    pub lnr_hdw_len: ::std::os::raw::c_int,
234    pub lnr_flags: ::std::os::raw::c_int,
235    pub lnr_pad0: ::std::os::raw::c_int,
236    pub lnr_hdw_addr: [::std::os::raw::c_char; 64usize],
237}
238
239#[repr(C)]
240#[derive(Copy, Clone)]
241pub struct strioctl {
242    pub ic_cmd: c_int,
243    pub ic_timeout: c_int,
244    pub ic_len: c_int,
245    pub ic_dp: *mut c_char,
246}
247
248impl strioctl {
249    pub fn new() -> Self {
250        strioctl {
251            ic_cmd: 0,
252            ic_timeout: 0,
253            ic_len: 0,
254            ic_dp: std::ptr::null_mut::<c_char>(),
255        }
256    }
257}
258
259impl Default for strioctl {
260    fn default() -> Self {
261        Self::new()
262    }
263}
264
265pub const LIFNAMSIZ: usize = 32;
266
267pub const DLDIOC_MACADDRGET: ioc_t = DLDIOC!(0x15);
268pub const DLDIOC_GETMACPROP: ioc_t = DLDIOC!(0x1c);
269pub const SIOCLIFREMOVEIF: ioc_t = IOW!('i', 110, lifreq) as ioc_t;
270pub const SIOCLIFADDIF: ioc_t = IOWR!('i', 111, lifreq) as ioc_t;
271pub const SIOCSLIFADDR: ioc_t = IOW!('i', 112, lifreq) as ioc_t;
272pub const SIOCGLIFADDR: ioc_t = IOWR!('i', 113, lifreq) as ioc_t;
273pub const SIOCSLIFFLAGS: ioc_t = IOW!('i', 116, lifreq) as ioc_t;
274pub const SIOCGLIFFLAGS: ioc_t = IOWR!('i', 117, lifreq) as ioc_t;
275pub const SIOCGLIFNETMASK: ioc_t = IOWR!('i', 125, lifreq) as ioc_t;
276pub const SIOCSLIFNETMASK: ioc_t = IOW!('i', 126, lifreq) as ioc_t;
277pub const SIOCSLIFNAME: ioc_t = IOWR!('i', 129, lifreq) as ioc_t;
278pub const SIOCGLIFNUM: ioc_t = IOWR!('i', 130, lifnum) as ioc_t;
279pub const SIOCGLIFMUXID: ioc_t = IOWR!('i', 131, lifreq) as ioc_t;
280pub const SIOCSLIFMUXID: ioc_t = IOW!('i', 132, lifreq) as ioc_t;
281pub const SIOCGLIFINDEX: ioc_t = IOWR!('i', 133, lifreq) as ioc_t;
282pub const SIOCLIFGETND: ioc_t = IOWR!('i', 142, lifreq) as ioc_t;
283pub const SIOCGLIFCONF: ioc_t = IOWRN!('i', 165, 16) as ioc_t;
284pub const SIOCGLIFDADSTATE: ioc_t = IOWR!('i', 190, lifreq) as ioc_t;
285pub const SIOCSLIFPREFIX: ioc_t = IOWR!('i', 191, lifreq) as ioc_t;
286
287macro_rules! SIMNETIOC {
288    ($cmdid:expr) => {
289        DLD_IOC_CMD!(SIMNET_IOC, $cmdid)
290    };
291}
292pub const SIMNET_IOC_CREATE: ioc_t = SIMNETIOC!(1);
293pub const SIMNET_IOC_DELETE: ioc_t = SIMNETIOC!(2);
294pub const SIMNET_IOC_INFO: ioc_t = SIMNETIOC!(3);
295pub const SIMNET_IOC_MODIFY: ioc_t = SIMNETIOC!(4);
296
297macro_rules! TFPORTIOC {
298    ($cmdid:expr) => {
299        DLD_IOC_CMD!(TFPORT_IOC, $cmdid)
300    };
301}
302pub const TFPORT_IOC_CREATE: ioc_t = TFPORTIOC!(1);
303pub const TFPORT_IOC_DELETE: ioc_t = TFPORTIOC!(2);
304pub const TFPORT_IOC_INFO: ioc_t = TFPORTIOC!(3);
305
306macro_rules! VNICIOC {
307    ($cmdid:expr) => {
308        DLD_IOC_CMD!(VNIC_IOC, $cmdid)
309    };
310}
311
312pub const VNIC_IOC_CREATE: ioc_t = VNICIOC!(1);
313pub const VNIC_IOC_DELETE: ioc_t = VNICIOC!(2);
314pub const VNIC_IOC_INFO: ioc_t = VNICIOC!(3);
315pub const VNIC_IOC_MODIFY: ioc_t = VNICIOC!(4);
316
317//TODO work to get ipmgmt types exported by illumos, but not with ipadm types in
318//the mix, this will require some work on the ipmgmt data structures to
319//eradicate dladm types
320
321//XXX dupe with crate::ip::IpmgmtAddrObjRval
322pub type ipmgmt_aobjop_rval_t = ipmgmt_aobjop_rval_s;
323#[repr(C)]
324#[derive(Copy, Clone)]
325pub struct ipmgmt_aobjop_rval_s {
326    pub ir_err: i32,
327    pub ir_aobjname: [::std::os::raw::c_char; 64usize],
328    pub ir_ifname: [::std::os::raw::c_char; 32usize],
329    pub ir_lnum: i32,
330    pub ir_family: sa_family_t,
331    pub ir_flags: u32,
332    pub ir_atype: ipadm_addr_type_t,
333    pub ir_atype_cache: ipmgmt_addr_type_cache_u,
334}
335
336pub const ipmgmt_door_cmd_type_t_IPMGMT_CMD_SETPROP: ipmgmt_door_cmd_type_t = 1;
337pub const ipmgmt_door_cmd_type_t_IPMGMT_CMD_SETIF: ipmgmt_door_cmd_type_t = 2;
338pub const ipmgmt_door_cmd_type_t_IPMGMT_CMD_SETADDR: ipmgmt_door_cmd_type_t = 3;
339pub const ipmgmt_door_cmd_type_t_IPMGMT_CMD_GETPROP: ipmgmt_door_cmd_type_t = 4;
340pub const ipmgmt_door_cmd_type_t_IPMGMT_CMD_GETIF: ipmgmt_door_cmd_type_t = 5;
341pub const ipmgmt_door_cmd_type_t_IPMGMT_CMD_GETADDR: ipmgmt_door_cmd_type_t = 6;
342pub const ipmgmt_door_cmd_type_t_IPMGMT_CMD_RESETIF: ipmgmt_door_cmd_type_t = 7;
343pub const ipmgmt_door_cmd_type_t_IPMGMT_CMD_RESETADDR: ipmgmt_door_cmd_type_t =
344    8;
345pub const ipmgmt_door_cmd_type_t_IPMGMT_CMD_RESETPROP: ipmgmt_door_cmd_type_t =
346    9;
347pub const ipmgmt_door_cmd_type_t_IPMGMT_CMD_INITIF: ipmgmt_door_cmd_type_t = 10;
348pub const ipmgmt_door_cmd_type_t_IPMGMT_CMD_ADDROBJ_LOOKUPADD:
349    ipmgmt_door_cmd_type_t = 11;
350pub const ipmgmt_door_cmd_type_t_IPMGMT_CMD_ADDROBJ_SETLIFNUM:
351    ipmgmt_door_cmd_type_t = 12;
352pub const ipmgmt_door_cmd_type_t_IPMGMT_CMD_ADDROBJ_ADD:
353    ipmgmt_door_cmd_type_t = 13;
354pub const ipmgmt_door_cmd_type_t_IPMGMT_CMD_LIF2ADDROBJ:
355    ipmgmt_door_cmd_type_t = 14;
356pub const ipmgmt_door_cmd_type_t_IPMGMT_CMD_AOBJNAME2ADDROBJ:
357    ipmgmt_door_cmd_type_t = 15;
358pub type ipmgmt_door_cmd_type_t = ::std::os::raw::c_uint;
359
360#[repr(C)]
361#[derive(Copy, Clone)]
362pub union ipmgmt_addr_type_cache_u {
363    pub ipmgmt_ipv6_cache_s: ipmgmt_addr_type_cache_ipv6,
364    pub ipmgmt_dhcp_cache_s: ipmgmt_addr_type_cache_dhcp,
365}
366
367#[repr(C)]
368#[derive(Copy, Clone)]
369pub struct ipmgmt_addr_type_cache_ipv6 {
370    pub ipmgmt_linklocal: boolean_t,
371    pub ipmgmt_ifid: sockaddr_in6,
372}
373
374#[repr(C)]
375#[derive(Debug, Copy, Clone)]
376pub struct ipmgmt_addr_type_cache_dhcp {
377    pub ipmgmt_reqhost: [::std::os::raw::c_char; 256usize],
378}
379
380pub type ipmgmt_aobjop_arg_t = ipmgmt_aobjop_arg_s;
381#[repr(C)]
382#[derive(Debug, Copy, Clone)]
383pub struct ipmgmt_aobjop_arg_s {
384    pub ia_cmd: ipmgmt_door_cmd_type_t,
385    pub ia_flags: u32,
386    pub ia_aobjname: [::std::os::raw::c_char; 64usize],
387    pub ia_ifname: [::std::os::raw::c_char; 32usize],
388    pub ia_lnum: i32,
389    pub ia_family: sa_family_t,
390    pub ia_atype: ipadm_addr_type_t,
391}
392
393//TODO no ipadm types
394
395pub type ipadm_dbwrite_cbarg_t = ipadm_dbwrite_cbarg_s;
396
397#[repr(C)]
398#[derive(Debug, Copy, Clone)]
399pub struct ipadm_dbwrite_cbarg_s {
400    pub dbw_nvl: *mut nvlist_t,
401    pub dbw_flags: uint_t,
402}
403
404pub type ipadm_if_info_t = ipadm_if_info_s;
405#[repr(C)]
406#[derive(Debug, Copy, Clone)]
407pub struct ipadm_if_info_list_s {
408    pub ifil_next: *mut ipadm_if_info_list_s,
409    pub ifil_ifi: ipadm_if_info_t,
410}
411
412#[repr(C)]
413#[derive(Debug, Copy, Clone)]
414pub struct ipadm_if_info_s {
415    pub ifi_name: [::std::os::raw::c_char; 32usize],
416    pub ifi_state: ipadm_if_state_t,
417    pub ifi_cflags: uint_t,
418    pub ifi_pflags: uint_t,
419}
420
421pub const ipadm_if_state_t_IFIS_OK: ipadm_if_state_t = 0;
422pub const ipadm_if_state_t_IFIS_DOWN: ipadm_if_state_t = 1;
423pub const ipadm_if_state_t_IFIS_FAILED: ipadm_if_state_t = 2;
424pub const ipadm_if_state_t_IFIS_OFFLINE: ipadm_if_state_t = 3;
425pub const ipadm_if_state_t_IFIS_DISABLED: ipadm_if_state_t = 4;
426pub type ipadm_if_state_t = ::std::os::raw::c_uint;
427
428pub type ipadm_if_info_list_t = ipadm_if_info_list_s;
429pub const ipadm_addr_state_t_IFA_DISABLED: ipadm_addr_state_t = 0;
430pub const ipadm_addr_state_t_IFA_DUPLICATE: ipadm_addr_state_t = 1;
431pub const ipadm_addr_state_t_IFA_DOWN: ipadm_addr_state_t = 2;
432pub const ipadm_addr_state_t_IFA_TENTATIVE: ipadm_addr_state_t = 3;
433pub const ipadm_addr_state_t_IFA_OK: ipadm_addr_state_t = 4;
434pub const ipadm_addr_state_t_IFA_INACCESSIBLE: ipadm_addr_state_t = 5;
435pub type ipadm_addr_state_t = ::std::os::raw::c_uint;
436pub const ipadm_addr_type_t_IPADM_ADDR_NONE: ipadm_addr_type_t = 0;
437pub const ipadm_addr_type_t_IPADM_ADDR_STATIC: ipadm_addr_type_t = 1;
438pub const ipadm_addr_type_t_IPADM_ADDR_IPV6_ADDRCONF: ipadm_addr_type_t = 2;
439pub const ipadm_addr_type_t_IPADM_ADDR_DHCP: ipadm_addr_type_t = 3;
440pub type ipadm_addr_type_t = ::std::os::raw::c_uint;
441
442pub type datalink_id_t = u32;
443#[repr(C)]
444#[derive(Debug, Copy, Clone)]
445pub struct dld_ioc_macaddrget {
446    pub dig_linkid: datalink_id_t,
447    pub dig_count: uint_t,
448    pub dig_size: uint_t,
449}
450pub type dld_ioc_macaddrget_t = dld_ioc_macaddrget;
451
452#[repr(C)]
453#[derive(Debug, Copy, Clone)]
454pub struct dld_macaddrinfo {
455    pub dmi_slot: uint_t,
456    pub dmi_flags: uint_t,
457    pub dmi_addrlen: uint_t,
458    pub dmi_addr: [uchar_t; 20usize],
459    pub dmi_client_name: [::std::os::raw::c_char; 256usize],
460    pub dma_client_linkid: datalink_id_t,
461}
462pub type dld_macaddrinfo_t = dld_macaddrinfo;
463
464#[repr(C)]
465#[derive(Debug, Copy, Clone)]
466pub struct dld_ioc_macprop_s<T: ?Sized> {
467    pub pr_flags: uint_t,
468    pub pr_linkid: datalink_id_t,
469    pub pr_num: mac_prop_id_t,
470    pub pr_perm_flags: uint_t,
471    pub pr_name: [::std::os::raw::c_char; 256usize],
472    pub pr_valsize: uint_t,
473    pub pr_val: T,
474}
475pub type dld_ioc_macprop_t<T> = dld_ioc_macprop_s<T>;
476
477pub const mac_prop_id_t_MAC_PROP_PRIVATE: mac_prop_id_t = u32::MAX;
478pub const mac_prop_id_t_MAC_PROP_DUPLEX: mac_prop_id_t = 0x00000001;
479pub const mac_prop_id_t_MAC_PROP_SPEED: mac_prop_id_t = 2;
480pub const mac_prop_id_t_MAC_PROP_STATUS: mac_prop_id_t = 3;
481pub const mac_prop_id_t_MAC_PROP_AUTONEG: mac_prop_id_t = 4;
482pub const mac_prop_id_t_MAC_PROP_EN_AUTONEG: mac_prop_id_t = 5;
483pub const mac_prop_id_t_MAC_PROP_MTU: mac_prop_id_t = 6;
484pub const mac_prop_id_t_MAC_PROP_ZONE: mac_prop_id_t = 7;
485pub const mac_prop_id_t_MAC_PROP_AUTOPUSH: mac_prop_id_t = 8;
486pub const mac_prop_id_t_MAC_PROP_FLOWCTRL: mac_prop_id_t = 9;
487pub const mac_prop_id_t_MAC_PROP_ADV_1000FDX_CAP: mac_prop_id_t = 10;
488pub const mac_prop_id_t_MAC_PROP_EN_1000FDX_CAP: mac_prop_id_t = 11;
489pub const mac_prop_id_t_MAC_PROP_ADV_1000HDX_CAP: mac_prop_id_t = 12;
490pub const mac_prop_id_t_MAC_PROP_EN_1000HDX_CAP: mac_prop_id_t = 13;
491pub const mac_prop_id_t_MAC_PROP_ADV_100FDX_CAP: mac_prop_id_t = 14;
492pub const mac_prop_id_t_MAC_PROP_EN_100FDX_CAP: mac_prop_id_t = 15;
493pub const mac_prop_id_t_MAC_PROP_ADV_100HDX_CAP: mac_prop_id_t = 16;
494pub const mac_prop_id_t_MAC_PROP_EN_100HDX_CAP: mac_prop_id_t = 17;
495pub const mac_prop_id_t_MAC_PROP_ADV_10FDX_CAP: mac_prop_id_t = 18;
496pub const mac_prop_id_t_MAC_PROP_EN_10FDX_CAP: mac_prop_id_t = 19;
497pub const mac_prop_id_t_MAC_PROP_ADV_10HDX_CAP: mac_prop_id_t = 20;
498pub const mac_prop_id_t_MAC_PROP_EN_10HDX_CAP: mac_prop_id_t = 21;
499pub const mac_prop_id_t_MAC_PROP_ADV_100T4_CAP: mac_prop_id_t = 22;
500pub const mac_prop_id_t_MAC_PROP_EN_100T4_CAP: mac_prop_id_t = 23;
501pub const mac_prop_id_t_MAC_PROP_IPTUN_HOPLIMIT: mac_prop_id_t = 24;
502pub const mac_prop_id_t_MAC_PROP_IPTUN_ENCAPLIMIT: mac_prop_id_t = 25;
503pub const mac_prop_id_t_MAC_PROP_WL_ESSID: mac_prop_id_t = 26;
504pub const mac_prop_id_t_MAC_PROP_WL_BSSID: mac_prop_id_t = 27;
505pub const mac_prop_id_t_MAC_PROP_WL_BSSTYPE: mac_prop_id_t = 28;
506pub const mac_prop_id_t_MAC_PROP_WL_LINKSTATUS: mac_prop_id_t = 29;
507pub const mac_prop_id_t_MAC_PROP_WL_DESIRED_RATES: mac_prop_id_t = 30;
508pub const mac_prop_id_t_MAC_PROP_WL_SUPPORTED_RATES: mac_prop_id_t = 31;
509pub const mac_prop_id_t_MAC_PROP_WL_AUTH_MODE: mac_prop_id_t = 32;
510pub const mac_prop_id_t_MAC_PROP_WL_ENCRYPTION: mac_prop_id_t = 33;
511pub const mac_prop_id_t_MAC_PROP_WL_RSSI: mac_prop_id_t = 34;
512pub const mac_prop_id_t_MAC_PROP_WL_PHY_CONFIG: mac_prop_id_t = 35;
513pub const mac_prop_id_t_MAC_PROP_WL_CAPABILITY: mac_prop_id_t = 36;
514pub const mac_prop_id_t_MAC_PROP_WL_WPA: mac_prop_id_t = 37;
515pub const mac_prop_id_t_MAC_PROP_WL_SCANRESULTS: mac_prop_id_t = 38;
516pub const mac_prop_id_t_MAC_PROP_WL_POWER_MODE: mac_prop_id_t = 39;
517pub const mac_prop_id_t_MAC_PROP_WL_RADIO: mac_prop_id_t = 40;
518pub const mac_prop_id_t_MAC_PROP_WL_ESS_LIST: mac_prop_id_t = 41;
519pub const mac_prop_id_t_MAC_PROP_WL_KEY_TAB: mac_prop_id_t = 42;
520pub const mac_prop_id_t_MAC_PROP_WL_CREATE_IBSS: mac_prop_id_t = 43;
521pub const mac_prop_id_t_MAC_PROP_WL_SETOPTIE: mac_prop_id_t = 44;
522pub const mac_prop_id_t_MAC_PROP_WL_DELKEY: mac_prop_id_t = 45;
523pub const mac_prop_id_t_MAC_PROP_WL_KEY: mac_prop_id_t = 46;
524pub const mac_prop_id_t_MAC_PROP_WL_MLME: mac_prop_id_t = 47;
525pub const mac_prop_id_t_MAC_PROP_TAGMODE: mac_prop_id_t = 48;
526pub const mac_prop_id_t_MAC_PROP_ADV_10GFDX_CAP: mac_prop_id_t = 49;
527pub const mac_prop_id_t_MAC_PROP_EN_10GFDX_CAP: mac_prop_id_t = 50;
528pub const mac_prop_id_t_MAC_PROP_PVID: mac_prop_id_t = 51;
529pub const mac_prop_id_t_MAC_PROP_LLIMIT: mac_prop_id_t = 52;
530pub const mac_prop_id_t_MAC_PROP_LDECAY: mac_prop_id_t = 53;
531pub const mac_prop_id_t_MAC_PROP_RESOURCE: mac_prop_id_t = 54;
532pub const mac_prop_id_t_MAC_PROP_RESOURCE_EFF: mac_prop_id_t = 55;
533pub const mac_prop_id_t_MAC_PROP_RXRINGSRANGE: mac_prop_id_t = 56;
534pub const mac_prop_id_t_MAC_PROP_TXRINGSRANGE: mac_prop_id_t = 57;
535pub const mac_prop_id_t_MAC_PROP_MAX_TX_RINGS_AVAIL: mac_prop_id_t = 58;
536pub const mac_prop_id_t_MAC_PROP_MAX_RX_RINGS_AVAIL: mac_prop_id_t = 59;
537pub const mac_prop_id_t_MAC_PROP_MAX_RXHWCLNT_AVAIL: mac_prop_id_t = 60;
538pub const mac_prop_id_t_MAC_PROP_MAX_TXHWCLNT_AVAIL: mac_prop_id_t = 61;
539pub const mac_prop_id_t_MAC_PROP_IB_LINKMODE: mac_prop_id_t = 62;
540pub const mac_prop_id_t_MAC_PROP_VN_PROMISC_FILTERED: mac_prop_id_t = 63;
541pub const mac_prop_id_t_MAC_PROP_SECONDARY_ADDRS: mac_prop_id_t = 64;
542pub const mac_prop_id_t_MAC_PROP_ADV_40GFDX_CAP: mac_prop_id_t = 65;
543pub const mac_prop_id_t_MAC_PROP_EN_40GFDX_CAP: mac_prop_id_t = 66;
544pub const mac_prop_id_t_MAC_PROP_ADV_100GFDX_CAP: mac_prop_id_t = 67;
545pub const mac_prop_id_t_MAC_PROP_EN_100GFDX_CAP: mac_prop_id_t = 68;
546pub const mac_prop_id_t_MAC_PROP_ADV_2500FDX_CAP: mac_prop_id_t = 69;
547pub const mac_prop_id_t_MAC_PROP_EN_2500FDX_CAP: mac_prop_id_t = 70;
548pub const mac_prop_id_t_MAC_PROP_ADV_5000FDX_CAP: mac_prop_id_t = 71;
549pub const mac_prop_id_t_MAC_PROP_EN_5000FDX_CAP: mac_prop_id_t = 72;
550pub const mac_prop_id_t_MAC_PROP_ADV_25GFDX_CAP: mac_prop_id_t = 73;
551pub const mac_prop_id_t_MAC_PROP_EN_25GFDX_CAP: mac_prop_id_t = 74;
552pub const mac_prop_id_t_MAC_PROP_ADV_50GFDX_CAP: mac_prop_id_t = 75;
553pub const mac_prop_id_t_MAC_PROP_EN_50GFDX_CAP: mac_prop_id_t = 76;
554pub const mac_prop_id_t_MAC_PROP_EN_FEC_CAP: mac_prop_id_t = 77;
555pub const mac_prop_id_t_MAC_PROP_ADV_FEC_CAP: mac_prop_id_t = 78;
556pub type mac_prop_id_t = ::std::os::raw::c_uint;
557
558#[repr(C)]
559#[derive(Debug, Copy, Clone)]
560pub struct rt_metrics {
561    pub locks: u32,    /* Kernel must leave  these  values alone */
562    pub mtu: u32,      /* MTU for this path */
563    pub hopcount: u32, /* max hops expected */
564    pub expire: u32,   /* lifetime for route, e.g., redirect */
565    pub recvpipe: u32, /* inbound delay-bandwidth  product */
566    pub sendpipe: u32, /* outbound delay-bandwidth product */
567    pub ssthresh: u32, /* outbound gateway buffer limit */
568    pub rtt: u32,      /* estimated round trip time */
569    pub rttvar: u32,   /* estimated rtt variance */
570    pub pksent: u32,   /* packets sent using this route */
571}
572
573#[repr(C)]
574#[derive(Debug, Copy, Clone)]
575pub struct rt_msghdr {
576    pub msglen: ushort_t, /* to skip over non-understood messages */
577    pub version: uchar_t, /* future binary compatibility */
578    pub typ: uchar_t,     /* message type */
579    pub index: ushort_t,  /* index for associated ifp */
580    pub flags: c_int,     /* flags,  incl  kern  &  message, e.g., DONE */
581    pub addrs: c_int,     /* bitmask identifying sockaddrs in msg */
582    pub pid: pid_t,       /* identify sender */
583    pub seq: c_int,       /* for sender to identify action */
584    pub errno: c_int,     /* why failed */
585    pub used: c_int,      /* from rtentry */
586    pub inits: uint_t,    /* which values we are initializing */
587    pub rmx: rt_metrics,  /* metrics themselves */
588}
589
590impl Default for rt_msghdr {
591    fn default() -> Self {
592        unsafe {
593            rt_msghdr {
594                msglen: std::mem::size_of::<rt_msghdr>() as u16,
595                version: RTM_VERSION as u8,
596                typ: RTM_GETALL as u8,
597                addrs: 0,
598                pid: getpid(),
599                seq: 1701,
600                errno: 0,
601                flags: 0,
602                used: 0,
603                inits: 0,
604                index: 0,
605                rmx: rt_metrics {
606                    locks: 0,
607                    mtu: 0,
608                    hopcount: 0,
609                    expire: 0,
610                    recvpipe: 0,
611                    sendpipe: 0,
612                    ssthresh: 0,
613                    rtt: 0,
614                    rttvar: 0,
615                    pksent: 0,
616                },
617            }
618        }
619    }
620}
621
622impl Default for ipmgmt_aobjop_rval_t {
623    fn default() -> Self {
624        ipmgmt_aobjop_rval_t {
625            ir_err: 0,
626            ir_aobjname: [0; 64usize],
627            ir_ifname: [0; 32usize],
628            ir_lnum: 0,
629            ir_family: 0,
630            ir_flags: 0,
631            ir_atype: 0,
632            ir_atype_cache: ipmgmt_addr_type_cache_u {
633                ipmgmt_ipv6_cache_s: ipmgmt_addr_type_cache_ipv6 {
634                    ipmgmt_linklocal: 0,
635                    ipmgmt_ifid: sockaddr_in6 {
636                        sin6_family: 0,
637                        sin6_port: 0,
638                        sin6_flowinfo: 0,
639                        sin6_addr: in6_addr { s6_addr: [0; 16] },
640                        sin6_scope_id: 0,
641                        ..unsafe { std::mem::zeroed() }
642                    },
643                },
644            },
645        }
646    }
647}
648
649pub const IFF_UP: u32 = 1;
650pub const IFF_BROADCAST: u32 = 2;
651pub const IFF_DEBUG: u32 = 4;
652pub const IFF_LOOPBACK: u32 = 8;
653pub const IFF_POINTOPOINT: u32 = 16;
654pub const IFF_NOTRAILERS: u32 = 32;
655pub const IFF_RUNNING: u32 = 64;
656pub const IFF_NOARP: u32 = 128;
657pub const IFF_PROMISC: u32 = 256;
658pub const IFF_ALLMULTI: u32 = 512;
659pub const IFF_INTELLIGENT: u32 = 1024;
660pub const IFF_MULTICAST: u32 = 2048;
661pub const IFF_MULTI_BCAST: u32 = 4096;
662pub const IFF_UNNUMBERED: u32 = 8192;
663pub const IFF_DHCPRUNNING: u32 = 16384;
664pub const IFF_PRIVATE: u32 = 32768;
665pub const IFF_NOXMIT: u32 = 65536;
666pub const IFF_NOLOCAL: u32 = 131072;
667pub const IFF_DEPRECATED: u32 = 262144;
668pub const IFF_ADDRCONF: u32 = 524288;
669pub const IFF_ROUTER: u32 = 1048576;
670pub const IFF_NONUD: u32 = 2097152;
671pub const IFF_ANYCAST: u32 = 4194304;
672pub const IFF_NORTEXCH: u32 = 8388608;
673pub const IFF_IPV4: u32 = 16777216;
674pub const IFF_IPV6: u32 = 33554432;
675pub const IFF_NOACCEPT: u32 = 67108864;
676pub const IFF_NOFAILOVER: u32 = 134217728;
677pub const IFF_FAILED: u32 = 268435456;
678pub const IFF_STANDBY: u32 = 536870912;
679pub const IFF_INACTIVE: u32 = 1073741824;
680pub const IFF_OFFLINE: u32 = 2147483648;
681pub const IFF_XRESOLV: u64 = 4294967296;
682pub const IFF_COS_ENABLED: u64 = 8589934592;
683pub const IFF_PREFERRED: u64 = 17179869184;
684pub const IFF_TEMPORARY: u64 = 34359738368;
685pub const IFF_FIXEDMTU: u64 = 68719476736;
686pub const IFF_VIRTUAL: u64 = 137438953472;
687pub const IFF_DUPLICATE: u64 = 274877906944;
688pub const IFF_IPMP: u64 = 549755813888;
689pub const IFF_VRRP: u64 = 1099511627776;
690pub const IFF_NOLINKLOCAL: u64 = 2199023255552;
691pub const IFF_L3PROTECT: u64 = 4398046511104;
692pub const IFF_CANTCHANGE: u64 = 8736013826906;
693pub const IFF_IPMP_CANTCHANGE: u32 = 268435456;
694pub const IFF_IPMP_INVALID: u64 = 8256487552;
695
696pub const IPMGMT_APPEND: u32 = 0x00000001;
697pub const IPMGMT_REMOVE: u32 = 0x00000002;
698pub const IPMGMT_ACTIVE: u32 = 0x00000004;
699pub const IPMGMT_PERSIST: u32 = 0x00000008;
700pub const IPMGMT_INIT: u32 = 0x00000010;
701pub const IPMGMT_PROPS_ONLY: u32 = 0x00000020;
702pub const IPMGMT_UPDATE_IF: u32 = 0x00000040;
703pub const IPMGMT_UPDATE_IPMP: u32 = 0x00000080;
704
705fn errno_ptr() -> *mut c_int {
706    cfg_if::cfg_if! {
707        if #[cfg(target_os = "illumos")] {
708            unsafe { libc::___errno() }
709        } else if #[cfg(target_os = "linux")] {
710            unsafe { libc::__errno_location() }
711        } else if #[cfg(target_os = "macos")] {
712            unsafe { libc::__error() }
713        }else {
714            compile_fail!("only linux and illumos are currently supported")
715        }
716    }
717}
718
719pub fn errno() -> c_int {
720    unsafe { *errno_ptr() }
721}
722
723pub fn clear_errno() {
724    unsafe {
725        *errno_ptr() = 0;
726    }
727}
728
729pub fn errno_string() -> String {
730    err_string(errno())
731}
732
733pub fn err_string(err: i32) -> String {
734    // We could attempt to grow `buf` if we get back `ERANGE`, but (a) 128 bytes
735    // is probably more than enought and (b) if we fail we have a fallback plan
736    // anyway.
737    let mut buf = [0; 128];
738    let ret = unsafe { libc::strerror_r(err, buf.as_mut_ptr(), buf.len()) };
739    if ret == 0 {
740        // TODO-cleanup We could use `CStr::from_bytes_until_nul()` to avoid
741        // this `unsafe` block once it's stabilized. For now, `buf` contains
742        // many nul bytes (after the one added by `strerror_r`, so we'll use
743        // `CStr::from_ptr()` to search for the first nul.
744        let cstr = unsafe { std::ffi::CStr::from_ptr(buf.as_ptr()) };
745        if let Ok(s) = cstr.to_str() {
746            return s.to_string();
747        }
748    }
749
750    // Either `strerror_r` or conversion to a a UTF8 string failed; fall back
751    // to a message that just includes the error number
752    format!("unknown failure (errno {})", err)
753}
754
755pub type kstat_ctl_t = kstat_ctl;
756extern "C" {
757    pub fn kstat_open() -> *mut kstat_ctl_t;
758    pub fn kstat_lookup(
759        arg1: *mut kstat_ctl_t,
760        arg2: *mut ::std::os::raw::c_char,
761        arg3: ::std::os::raw::c_int,
762        arg4: *mut ::std::os::raw::c_char,
763    ) -> *mut kstat_t;
764    pub fn kstat_close(arg1: *mut kstat_ctl_t) -> ::std::os::raw::c_int;
765    pub fn kstat_read(
766        arg1: *mut kstat_ctl_t,
767        arg2: *mut kstat_t,
768        arg3: *mut ::std::os::raw::c_void,
769    ) -> kid_t;
770    pub fn kstat_write(
771        arg1: *mut kstat_ctl_t,
772        arg2: *mut kstat_t,
773        arg3: *mut ::std::os::raw::c_void,
774    ) -> kid_t;
775    pub fn kstat_data_lookup(
776        arg1: *mut kstat_t,
777        arg2: *mut ::std::os::raw::c_char,
778    ) -> *mut ::std::os::raw::c_void;
779}
780
781#[repr(C)]
782#[derive(Debug, Copy, Clone)]
783pub struct kstat_ctl {
784    pub kc_chain_id: kid_t,
785    pub kc_chain: *mut kstat_t,
786    pub kc_kd: ::std::os::raw::c_int,
787}
788
789#[repr(C)]
790#[derive(Debug, Copy, Clone)]
791pub struct kstat {
792    pub ks_crtime: hrtime_t,
793    pub ks_next: *mut kstat,
794    pub ks_kid: kid_t,
795    pub ks_module: [::std::os::raw::c_char; 31usize],
796    pub ks_resv: uchar_t,
797    pub ks_instance: ::std::os::raw::c_int,
798    pub ks_name: [::std::os::raw::c_char; 31usize],
799    pub ks_type: uchar_t,
800    pub ks_class: [::std::os::raw::c_char; 31usize],
801    pub ks_flags: uchar_t,
802    pub ks_data: *mut ::std::os::raw::c_void,
803    pub ks_ndata: uint_t,
804    pub ks_data_size: size_t,
805    pub ks_snaptime: hrtime_t,
806    pub ks_update: ::std::option::Option<
807        unsafe extern "C" fn(
808            arg1: *mut kstat,
809            arg2: ::std::os::raw::c_int,
810        ) -> ::std::os::raw::c_int,
811    >,
812    pub ks_private: *mut ::std::os::raw::c_void,
813    pub ks_snapshot: ::std::option::Option<
814        unsafe extern "C" fn(
815            arg1: *mut kstat,
816            arg2: *mut ::std::os::raw::c_void,
817            arg3: ::std::os::raw::c_int,
818        ) -> ::std::os::raw::c_int,
819    >,
820    pub ks_lock: *mut ::std::os::raw::c_void,
821}
822pub type kstat_t = kstat;
823
824pub const glif_dad_state_t_DAD_IN_PROGRESS: glif_dad_state_t = 1;
825pub const glif_dad_state_t_DAD_DONE: glif_dad_state_t = 2;
826pub type glif_dad_state_t = ::std::os::raw::c_uint;
827
828pub const DL_CSMACD: u32 = 0;
829pub const DL_TPB: u32 = 1;
830pub const DL_TPR: u32 = 2;
831pub const DL_METRO: u32 = 3;
832pub const DL_ETHER: u32 = 4;
833pub const DL_HDLC: u32 = 5;
834pub const DL_CHAR: u32 = 6;
835pub const DL_CTCA: u32 = 7;
836pub const DL_FDDI: u32 = 8;
837pub const DL_FC: u32 = 16;
838pub const DL_ATM: u32 = 17;
839pub const DL_IPATM: u32 = 18;
840pub const DL_X25: u32 = 19;
841pub const DL_ISDN: u32 = 20;
842pub const DL_HIPPI: u32 = 21;
843pub const DL_100VG: u32 = 22;
844pub const DL_100VGTPR: u32 = 23;
845pub const DL_ETH_CSMA: u32 = 24;
846pub const DL_100BT: u32 = 25;
847pub const DL_IB: u32 = 26;
848pub const DL_FRAME: u32 = 10;
849pub const DL_MPFRAME: u32 = 11;
850pub const DL_ASYNC: u32 = 12;
851pub const DL_IPX25: u32 = 13;
852pub const DL_LOOP: u32 = 14;
853pub const DL_OTHER: u32 = 9;
854
855pub const link_state_t_LINK_STATE_UNKNOWN: link_state_t = -1;
856pub const link_state_t_LINK_STATE_DOWN: link_state_t = 0;
857pub const link_state_t_LINK_STATE_UP: link_state_t = 1;
858pub type link_state_t = ::std::os::raw::c_int;
859
860#[repr(C)]
861#[derive(Copy, Clone)]
862pub struct kstat_named {
863    pub name: [::std::os::raw::c_char; 31usize],
864    pub data_type: uchar_t,
865    pub value: kstat_named_value,
866}
867#[repr(C)]
868#[derive(Copy, Clone)]
869pub union kstat_named_value {
870    pub c: [::std::os::raw::c_char; 16usize],
871    pub i32_: i32,
872    pub ui32: u32,
873    pub str_: kstat_named_value_str,
874    pub i64_: i64,
875    pub ui64: u64,
876    pub l: ::std::os::raw::c_long,
877    pub ul: ulong_t,
878    pub ll: longlong_t,
879    pub ull: u_longlong_t,
880    pub f: f32,
881    pub d: f64,
882}
883#[repr(C)]
884#[derive(Copy, Clone)]
885pub struct kstat_named_value_str {
886    pub addr: kstat_named_value_str_addr,
887    pub len: u32,
888}
889#[repr(C)]
890#[derive(Copy, Clone)]
891pub union kstat_named_value_str_addr {
892    pub ptr: *mut ::std::os::raw::c_char,
893    pub __pad: [::std::os::raw::c_char; 8usize],
894}
895
896pub type kstat_named_t = kstat_named;
897#[repr(C)]
898#[derive(Copy, Clone)]
899pub struct vopstats {
900    pub nopen: kstat_named_t,
901    pub nclose: kstat_named_t,
902    pub nread: kstat_named_t,
903    pub read_bytes: kstat_named_t,
904    pub nwrite: kstat_named_t,
905    pub write_bytes: kstat_named_t,
906    pub nioctl: kstat_named_t,
907    pub nsetfl: kstat_named_t,
908    pub ngetattr: kstat_named_t,
909    pub nsetattr: kstat_named_t,
910    pub naccess: kstat_named_t,
911    pub nlookup: kstat_named_t,
912    pub ncreate: kstat_named_t,
913    pub nremove: kstat_named_t,
914    pub nlink: kstat_named_t,
915    pub nrename: kstat_named_t,
916    pub nmkdir: kstat_named_t,
917    pub nrmdir: kstat_named_t,
918    pub nreaddir: kstat_named_t,
919    pub readdir_bytes: kstat_named_t,
920    pub nsymlink: kstat_named_t,
921    pub nreadlink: kstat_named_t,
922    pub nfsync: kstat_named_t,
923    pub ninactive: kstat_named_t,
924    pub nfid: kstat_named_t,
925    pub nrwlock: kstat_named_t,
926    pub nrwunlock: kstat_named_t,
927    pub nseek: kstat_named_t,
928    pub ncmp: kstat_named_t,
929    pub nfrlock: kstat_named_t,
930    pub nspace: kstat_named_t,
931    pub nrealvp: kstat_named_t,
932    pub ngetpage: kstat_named_t,
933    pub nputpage: kstat_named_t,
934    pub nmap: kstat_named_t,
935    pub naddmap: kstat_named_t,
936    pub ndelmap: kstat_named_t,
937    pub npoll: kstat_named_t,
938    pub ndump: kstat_named_t,
939    pub npathconf: kstat_named_t,
940    pub npageio: kstat_named_t,
941    pub ndumpctl: kstat_named_t,
942    pub ndispose: kstat_named_t,
943    pub nsetsecattr: kstat_named_t,
944    pub ngetsecattr: kstat_named_t,
945    pub nshrlock: kstat_named_t,
946    pub nvnevent: kstat_named_t,
947    pub nreqzcbuf: kstat_named_t,
948    pub nretzcbuf: kstat_named_t,
949}
950
951pub const KSTAT_STRLEN: u32 = 31;
952pub const KSTAT_TYPE_RAW: u32 = 0;
953pub const KSTAT_TYPE_NAMED: u32 = 1;
954pub const KSTAT_TYPE_INTR: u32 = 2;
955pub const KSTAT_TYPE_IO: u32 = 3;
956pub const KSTAT_TYPE_TIMER: u32 = 4;
957pub const KSTAT_NUM_TYPES: u32 = 5;
958pub const KSTAT_FLAG_VIRTUAL: u32 = 1;
959pub const KSTAT_FLAG_VAR_SIZE: u32 = 2;
960pub const KSTAT_FLAG_WRITABLE: u32 = 4;
961pub const KSTAT_FLAG_PERSISTENT: u32 = 8;
962pub const KSTAT_FLAG_DORMANT: u32 = 16;
963pub const KSTAT_FLAG_INVALID: u32 = 32;
964pub const KSTAT_FLAG_LONGSTRINGS: u32 = 64;
965pub const KSTAT_READ: u32 = 0;
966pub const KSTAT_WRITE: u32 = 1;
967pub const KSTAT_DATA_CHAR: u32 = 0;
968pub const KSTAT_DATA_INT32: u32 = 1;
969pub const KSTAT_DATA_UINT32: u32 = 2;
970pub const KSTAT_DATA_INT64: u32 = 3;
971pub const KSTAT_DATA_UINT64: u32 = 4;
972pub const KSTAT_DATA_LONG: u32 = 3;
973pub const KSTAT_DATA_ULONG: u32 = 4;
974pub const KSTAT_DATA_STRING: u32 = 9;
975pub const KSTAT_DATA_LONGLONG: u32 = 3;
976pub const KSTAT_DATA_ULONGLONG: u32 = 4;
977pub const KSTAT_DATA_FLOAT: u32 = 5;
978pub const KSTAT_DATA_DOUBLE: u32 = 6;
979pub const KSTAT_INTR_HARD: u32 = 0;
980pub const KSTAT_INTR_SOFT: u32 = 1;
981pub const KSTAT_INTR_WATCHDOG: u32 = 2;
982pub const KSTAT_INTR_SPURIOUS: u32 = 3;
983pub const KSTAT_INTR_MULTSVC: u32 = 4;
984pub const KSTAT_NUM_INTRS: u32 = 5;
985
986pub const EPERM: u32 = 1;
987pub const ENOENT: u32 = 2;
988pub const ESRCH: u32 = 3;
989pub const EINTR: u32 = 4;
990pub const EIO: u32 = 5;
991pub const ENXIO: u32 = 6;
992pub const E2BIG: u32 = 7;
993pub const ENOEXEC: u32 = 8;
994pub const EBADF: u32 = 9;
995pub const ECHILD: u32 = 10;
996pub const EAGAIN: u32 = 11;
997pub const ENOMEM: u32 = 12;
998pub const EACCES: u32 = 13;
999pub const EFAULT: u32 = 14;
1000pub const ENOTBLK: u32 = 15;
1001pub const EBUSY: u32 = 16;
1002pub const EEXIST: u32 = 17;
1003pub const EXDEV: u32 = 18;
1004pub const ENODEV: u32 = 19;
1005pub const ENOTDIR: u32 = 20;
1006pub const EISDIR: u32 = 21;
1007pub const EINVAL: u32 = 22;
1008pub const ENFILE: u32 = 23;
1009pub const EMFILE: u32 = 24;
1010pub const ENOTTY: u32 = 25;
1011pub const ETXTBSY: u32 = 26;
1012pub const EFBIG: u32 = 27;
1013pub const ENOSPC: u32 = 28;
1014pub const ESPIPE: u32 = 29;
1015pub const EROFS: u32 = 30;
1016pub const EMLINK: u32 = 31;
1017pub const EPIPE: u32 = 32;
1018pub const EDOM: u32 = 33;
1019pub const ERANGE: u32 = 34;
1020pub const ENOMSG: u32 = 35;
1021pub const EIDRM: u32 = 36;
1022pub const ECHRNG: u32 = 37;
1023pub const EL2NSYNC: u32 = 38;
1024pub const EL3HLT: u32 = 39;
1025pub const EL3RST: u32 = 40;
1026pub const ELNRNG: u32 = 41;
1027pub const EUNATCH: u32 = 42;
1028pub const ENOCSI: u32 = 43;
1029pub const EL2HLT: u32 = 44;
1030pub const EDEADLK: u32 = 45;
1031pub const ENOLCK: u32 = 46;
1032pub const ECANCELED: u32 = 47;
1033pub const ENOTSUP: u32 = 48;
1034pub const EDQUOT: u32 = 49;
1035pub const EBADE: u32 = 50;
1036pub const EBADR: u32 = 51;
1037pub const EXFULL: u32 = 52;
1038pub const ENOANO: u32 = 53;
1039pub const EBADRQC: u32 = 54;
1040pub const EBADSLT: u32 = 55;
1041pub const EDEADLOCK: u32 = 56;
1042pub const EBFONT: u32 = 57;
1043pub const EOWNERDEAD: u32 = 58;
1044pub const ENOTRECOVERABLE: u32 = 59;
1045pub const ENOSTR: u32 = 60;
1046pub const ENODATA: u32 = 61;
1047pub const ETIME: u32 = 62;
1048pub const ENOSR: u32 = 63;
1049pub const ENONET: u32 = 64;
1050pub const ENOPKG: u32 = 65;
1051pub const EREMOTE: u32 = 66;
1052pub const ENOLINK: u32 = 67;
1053pub const EADV: u32 = 68;
1054pub const ESRMNT: u32 = 69;
1055pub const ECOMM: u32 = 70;
1056pub const EPROTO: u32 = 71;
1057pub const ELOCKUNMAPPED: u32 = 72;
1058pub const ENOTACTIVE: u32 = 73;
1059pub const EMULTIHOP: u32 = 74;
1060pub const EBADMSG: u32 = 77;
1061pub const ENAMETOOLONG: u32 = 78;
1062pub const EOVERFLOW: u32 = 79;
1063pub const ENOTUNIQ: u32 = 80;
1064pub const EBADFD: u32 = 81;
1065pub const EREMCHG: u32 = 82;
1066pub const ELIBACC: u32 = 83;
1067pub const ELIBBAD: u32 = 84;
1068pub const ELIBSCN: u32 = 85;
1069pub const ELIBMAX: u32 = 86;
1070pub const ELIBEXEC: u32 = 87;
1071pub const EILSEQ: u32 = 88;
1072pub const ENOSYS: u32 = 89;
1073pub const ELOOP: u32 = 90;
1074pub const ERESTART: u32 = 91;
1075pub const ESTRPIPE: u32 = 92;
1076pub const ENOTEMPTY: u32 = 93;
1077pub const EUSERS: u32 = 94;
1078pub const ENOTSOCK: u32 = 95;
1079pub const EDESTADDRREQ: u32 = 96;
1080pub const EMSGSIZE: u32 = 97;
1081pub const EPROTOTYPE: u32 = 98;
1082pub const ENOPROTOOPT: u32 = 99;
1083pub const EPROTONOSUPPORT: u32 = 120;
1084pub const ESOCKTNOSUPPORT: u32 = 121;
1085pub const EOPNOTSUPP: u32 = 122;
1086pub const EPFNOSUPPORT: u32 = 123;
1087pub const EAFNOSUPPORT: u32 = 124;
1088pub const EADDRINUSE: u32 = 125;
1089pub const EADDRNOTAVAIL: u32 = 126;
1090pub const ENETDOWN: u32 = 127;
1091pub const ENETUNREACH: u32 = 128;
1092pub const ENETRESET: u32 = 129;
1093pub const ECONNABORTED: u32 = 130;
1094pub const ECONNRESET: u32 = 131;
1095pub const ENOBUFS: u32 = 132;
1096pub const EISCONN: u32 = 133;
1097pub const ENOTCONN: u32 = 134;
1098pub const ESHUTDOWN: u32 = 143;
1099pub const ETOOMANYREFS: u32 = 144;
1100pub const ETIMEDOUT: u32 = 145;
1101pub const ECONNREFUSED: u32 = 146;
1102pub const EHOSTDOWN: u32 = 147;
1103pub const EHOSTUNREACH: u32 = 148;
1104pub const EWOULDBLOCK: u32 = 11;
1105pub const EALREADY: u32 = 149;
1106pub const EINPROGRESS: u32 = 150;
1107pub const ESTALE: u32 = 151;
1108
1109pub const RTM_VERSION: u32 = 3;
1110pub const RTM_ADD: u32 = 1;
1111pub const RTM_DELETE: u32 = 2;
1112pub const RTM_CHANGE: u32 = 3;
1113pub const RTM_GET: u32 = 4;
1114pub const RTM_LOSING: u32 = 5;
1115pub const RTM_REDIRECT: u32 = 6;
1116pub const RTM_MISS: u32 = 7;
1117pub const RTM_LOCK: u32 = 8;
1118pub const RTM_OLDADD: u32 = 9;
1119pub const RTM_OLDDEL: u32 = 10;
1120pub const RTM_RESOLVE: u32 = 11;
1121pub const RTM_NEWADDR: u32 = 12;
1122pub const RTM_DELADDR: u32 = 13;
1123pub const RTM_IFINFO: u32 = 14;
1124pub const RTM_CHGADDR: u32 = 15;
1125pub const RTM_FREEADDR: u32 = 16;
1126pub const RTM_GETALL: u32 = 17;
1127
1128pub const RTA_DST: u32 = 0x1;
1129pub const RTA_GATEWAY: u32 = 0x2;
1130pub const RTA_NETMASK: u32 = 0x4;
1131pub const RTA_GENMASK: u32 = 0x8;
1132pub const RTA_IFP: u32 = 0x10;
1133pub const RTA_IFA: u32 = 0x20;
1134pub const RTA_AUTHOR: u32 = 0x40;
1135pub const RTA_BRD: u32 = 0x80;
1136pub const RTA_SRC: u32 = 0x100;
1137pub const RTA_DELAY: u32 = 0x200;
1138
1139pub const RTF_UP: u32 = 0x1; /* route usable */
1140pub const RTF_GATEWAY: u32 = 0x2; /* destination is a gateway */
1141pub const RTF_HOST: u32 = 0x4; /* host entry (net otherwise) */
1142pub const RTF_REJECT: u32 = 0x8; /* host or net unreachable */
1143pub const RTF_DYNAMIC: u32 = 0x10; /* created dynamically (by redirect) */
1144pub const RTF_MODIFIED: u32 = 0x20; /* modified dynamically (by redirect) */
1145pub const RTF_DONE: u32 = 0x40; /* message confirmed */
1146pub const RTF_MASK: u32 = 0x80; /* subnet mask present */
1147pub const RTF_CLONING: u32 = 0x100; /* generate new routes on use */
1148pub const RTF_XRESOLVE: u32 = 0x200; /* external daemon resolves name */
1149pub const RTF_LLINFO: u32 = 0x400; /* generated by ARP or ESIS */
1150pub const RTF_STATIC: u32 = 0x800; /* manually added */
1151pub const RTF_BLACKHOLE: u32 = 0x1000; /* just discard pkts (during updates) */
1152pub const RTF_PRIVATE: u32 = 0x2000; /* do not advertise this route */
1153pub const RTF_PROTO2: u32 = 0x4000; /* protocol specific routing flag */
1154pub const RTF_PROTO1: u32 = 0x8000; /* protocol specific routing flag */
1155pub const RTF_MULTIRT: u32 = 0x10000; /* multiroute */
1156pub const RTF_SETSRC: u32 = 0x20000; /* set default outgoing src address */
1157pub const RTF_INDIRECT: u32 = 0x40000; /* gateway not directly reachable */
1158pub const RTF_KERNEL: u32 = 0x80000; /* created by kernel; can't delete */
1159pub const RTF_ZONE: u32 = 0x100000; /* (NGZ only) route from global zone */
1160
1161extern "C" {
1162    pub fn getpid() -> pid_t;
1163}
1164
1165/* error codes */
1166#[repr(C)]
1167pub enum IpadmStatusT {
1168    Success,            /* No error occurred */
1169    Failure,            /* Generic failure */
1170    Eauth,              /* Insufficient user authorizations */
1171    Eperm,              /* Permission denied */
1172    NoBufs,             /* No Buffer space available */
1173    NoMemory,           /* Insufficient memory */
1174    BadAddr,            /* Invalid address */
1175    BadProtocol,        /* Wrong protocol family for operation */
1176    DadFound,           /* Duplicate address detected */
1177    Exists,             /* Already exists */
1178    IfExists,           /* Interface already exists */
1179    AddrobjExists,      /* Address object already exists */
1180    AddrconfExists,     /* Addrconf already in progress */
1181    Enxio,              /* Interface does not exist */
1182    GrpNotEmpty,        /* IPMP Group non-empty on unplumb */
1183    InvalidArg,         /* Invalid argument */
1184    InvalidName,        /* Invalid name */
1185    DlpiFailure,        /* Could not open DLPI link */
1186    DladmFailure,       /* DLADM error encountered */
1187    PropUnknown,        /* Unknown property */
1188    Erange,             /* Value is outside the allowed range */
1189    Esrch,              /* Value does not exist */
1190    Eoverflow,          /* Number of values exceed the allowed limit*/
1191    NotFound,           /* Object not found */
1192    IfInuse,            /* Interface already in use */
1193    AddrInuse,          /* Address alrelady in use */
1194    BadHostname,        /* hostname maps to multiple IP addresses */
1195    AddrNotavail,       /* Can't assign requested address */
1196    AllAddrsNotEnabled, /* All addresses could not be enabled */
1197    NdpdNotRunning,     /* in.ndpd not running */
1198    DhcpStartError,     /* Cannot start dhcpagent */
1199    DhcpIpcError,       /* Cannot communicate with dhcpagent */
1200    DhcpIpcTimeout,     /* Communication with dhcpagent timed out */
1201    TemporaryObj,       /* Permanent operation on temporary object */
1202    IpcError,           /* Cannot communicate with ipmgmtd */
1203    OpDisableObj,       /* Operation on disable object */
1204    NotSup,             /* Operation not supported */
1205    Ebade,              /* Invalid data exchange with ipmgmtd */
1206    GzPerm,             /* Operation not permitted on from-gz intf */
1207}
1208
1209pub const NDF_ISROUTER_ON: i32 = 0x1;
1210pub const NDF_ISROUTER_off: i32 = 0x2;
1211pub const NDF_ANYCAST_ON: i32 = 0x4;
1212pub const NDF_ANYCAST_OFF: i32 = 0x8;
1213pub const NDF_PROXY_ON: i32 = 0x10;
1214pub const NDF_PROXY_OFF: i32 = 0x20;
1215pub const NDF_STATIC: i32 = 0x40;