rsmnl_linux/
ifh.rs

1use libc::{c_uchar, c_uint, c_ulong, c_ushort};
2
3pub const IFNAMSIZ: usize = 16;
4pub const IFALIASZ: usize = 256;
5pub const ALTIFNAMSIZ: usize = 128;
6
7#[repr(C)]
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
9pub enum NetDeviceFlags {
10    // IFF_
11    Up = 1 << 0,          // sysfs
12    Broadcast = 1 << 1,   // volatile
13    Debug = 1 << 2,       // sysfs
14    Loopback = 1 << 3,    // volatile
15    Pointopoint = 1 << 4, // volatile
16    Notrailers = 1 << 5,  // sysfs
17    Running = 1 << 6,     // volatile
18    Noarp = 1 << 7,       // sysfs
19    Promisc = 1 << 8,     // sysfs
20    Allmulti = 1 << 9,    // sysfs
21    Master = 1 << 10,     // volatile
22    Slave = 1 << 11,      // volatile
23    Multicast = 1 << 12,  // sysfs
24    Portsel = 1 << 13,    // sysfs
25    Automedia = 1 << 14,  // sysfs
26    Dynamic = 1 << 15,    // sysfs
27    LowerUp = 1 << 16,    // volatile
28    Dormant = 1 << 17,    // volatile
29    Echo = 1 << 18,       // volatile
30}
31pub const IFF_UP: c_uint = NetDeviceFlags::Up as c_uint;
32pub const IFF_BROADCAST: c_uint = NetDeviceFlags::Broadcast as c_uint;
33pub const IFF_DEBUG: c_uint = NetDeviceFlags::Debug as c_uint;
34pub const IFF_LOOPBACK: c_uint = NetDeviceFlags::Loopback as c_uint;
35pub const IFF_POINTOPOINT: c_uint = NetDeviceFlags::Pointopoint as c_uint;
36pub const IFF_NOTRAILERS: c_uint = NetDeviceFlags::Notrailers as c_uint;
37pub const IFF_RUNNING: c_uint = NetDeviceFlags::Running as c_uint;
38pub const IFF_NOARP: c_uint = NetDeviceFlags::Noarp as c_uint;
39pub const IFF_PROMISC: c_uint = NetDeviceFlags::Promisc as c_uint;
40pub const IFF_ALLMULTI: c_uint = NetDeviceFlags::Allmulti as c_uint;
41pub const IFF_MASTER: c_uint = NetDeviceFlags::Master as c_uint;
42pub const IFF_SLAVE: c_uint = NetDeviceFlags::Slave as c_uint;
43pub const IFF_MULTICAST: c_uint = NetDeviceFlags::Multicast as c_uint;
44pub const IFF_PORTSEL: c_uint = NetDeviceFlags::Portsel as c_uint;
45pub const IFF_AUTOMEDIA: c_uint = NetDeviceFlags::Automedia as c_uint;
46pub const IFF_DYNAMIC: c_uint = NetDeviceFlags::Dynamic as c_uint;
47pub const IFF_LOWER_UP: c_uint = NetDeviceFlags::LowerUp as c_uint;
48pub const IFF_DORMANT: c_uint = NetDeviceFlags::Dormant as c_uint;
49pub const IFF_ECHO: c_uint = NetDeviceFlags::Echo as c_uint;
50pub const IFF_VOLATILE: c_uint = IFF_LOOPBACK
51    | IFF_POINTOPOINT
52    | IFF_BROADCAST
53    | IFF_ECHO
54    | IFF_MASTER
55    | IFF_SLAVE
56    | IFF_RUNNING
57    | IFF_LOWER_UP
58    | IFF_DORMANT;
59
60pub const IF_GET_IFACE: c_uint = 0x0001; // for querying only
61pub const IF_GET_PROTO: c_uint = 0x0002;
62
63// For definitions see hdlc.h
64pub const IF_IFACE_V35: c_uint = 0x1000; // V.35 serial interface
65pub const IF_IFACE_V24: c_uint = 0x1001; // V.24 serial interface
66pub const IF_IFACE_X21: c_uint = 0x1002; // X.21 serial interface
67pub const IF_IFACE_T1: c_uint = 0x1003; // T1 telco serial interface
68pub const IF_IFACE_E1: c_uint = 0x1004; // E1 telco serial interface
69pub const IF_IFACE_SYNC_SERIAL: c_uint = 0x1005; // can't be set by software
70pub const IF_IFACE_X21D: c_uint = 0x1006; // X.21 Dual Clocking (FarSite)
71
72// For definitions see hdlc.h
73pub const IF_PROTO_HDLC: c_uint = 0x2000; // raw HDLC protocol		*/
74pub const IF_PROTO_PPP: c_uint = 0x2001; // PPP protocol			*/
75pub const IF_PROTO_CISCO: c_uint = 0x2002; // Cisco HDLC protocol		*/
76pub const IF_PROTO_FR: c_uint = 0x2003; // Frame Relay protocol		*/
77pub const IF_PROTO_FR_ADD_PVC: c_uint = 0x2004; //    Create FR PVC		*/
78pub const IF_PROTO_FR_DEL_PVC: c_uint = 0x2005; //    Delete FR PVC		*/
79pub const IF_PROTO_X25: c_uint = 0x2006; // X.25				*/
80pub const IF_PROTO_HDLC_ETH: c_uint = 0x2007; // raw HDLC, Ethernet emulation	*/
81pub const IF_PROTO_FR_ADD_ETH_PVC: c_uint = 0x2008; //  Create FR Ethernet-bridged PVC */
82pub const IF_PROTO_FR_DEL_ETH_PVC: c_uint = 0x2009; //  Delete FR Ethernet-bridged PVC */
83pub const IF_PROTO_FR_PVC: c_uint = 0x200A; // for reading PVC status	*/
84pub const IF_PROTO_FR_ETH_PVC: c_uint = 0x200B;
85pub const IF_PROTO_RAW: c_uint = 0x200C; // RAW Socket                   */
86                                         // RFC 2863 operational status */
87#[repr(u8)]
88#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
89pub enum IfOper {
90    // IF_OPER_
91    Unknown,
92    Notpresent,
93    Down,
94    Lowerlayerdown,
95    Testing,
96    Dormant,
97    Up,
98}
99pub const IF_OPER_UNKNOWN: u8 = IfOper::Unknown as u8;
100pub const IF_OPER_NOTPRESENT: u8 = IfOper::Notpresent as u8;
101pub const IF_OPER_DOWN: u8 = IfOper::Down as u8;
102pub const IF_OPER_LOWERLAYERDOWN: u8 = IfOper::Lowerlayerdown as u8;
103pub const IF_OPER_TESTING: u8 = IfOper::Testing as u8;
104pub const IF_OPER_DORMANT: u8 = IfOper::Dormant as u8;
105pub const IF_OPER_UP: u8 = IfOper::Up as u8;
106
107// link modes */
108#[repr(u8)]
109#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
110pub enum IfLinkMode {
111    // IF_LINK_MODE_
112    Default = 0,
113    Dormant, // limit upward transition to dormant */
114    Testing, // limit upward transition to testing */
115}
116pub const IF_LINK_MODE_DEFAULT: u8 = IfLinkMode::Default as u8;
117pub const IF_LINK_MODE_DORMANT: u8 = IfLinkMode::Dormant as u8;
118pub const IF_LINK_MODE_TESTING: u8 = IfLinkMode::Testing as u8;
119
120// Device mapping structure. I'd just gone off and designed a
121// beautiful scheme using only loadable modules with arguments
122// for driver options and along come the PCMCIA people 8)
123//
124// Ah well. The get() side of this is good for WDSETUP, and it'll
125// be handy for debugging things. The set side is fine for now and
126// being very small might be worth keeping for clean configuration.
127
128// for compatibility with glibc net/if.h
129// seems to be same as if_link.h::struct rtnl_link_ifmap
130#[repr(C)]
131#[derive(Debug, Clone, Copy)]
132pub struct Ifmap {
133    mem_start: c_ulong,
134    mem_end: c_ulong,
135    base_addr: c_ushort,
136    irq: c_uchar,
137    dma: c_uchar,
138    port: c_uchar, // 3 bytes spare
139}
140
141// XXX: then the rest has raw ...
142//   struct if_settings
143//   struct ifreq and its unit handling
144//   struct ifconf