NetInfo

Gathers information about network devices plugged into system, their
relationships including link aggregation, or bridges and VLANs running on
top of network device and IPv4 and IPv6 addresses bound to that devices.

We will refer to network device as NIC and to address as interface
in subsequent documentation.

Linux

Walks /sys/class/net to collect NICs and their properties and hierarchy.
Uses getifaddrs() to fetch information on IP addresses.

NOTE: Because 8021q driver not supports SYSFS bindings, we deduce vlan id
from NIC name if it contains dot.

NOTE: To distiguish IPv4 interface, IPv6 interface and NIC which have same name
in getifaddrs() logic, it puts interfaces into "ip" or "ipv4" namespaces.

Solaris

Uses libdlmgmt library to gather network devices. Like libpicl it has broken
implementation, so some of the calls are work-arounded using kstat.

Because Solaris 10 doesn't support getifaddrs(), it uses SIOCGLIFNUM and
SIOCGLIFCONF ioctls to collect interfaces.

NOTE: To distiguish IPv4 interface, IPv6 interface and NIC which have same name
in getifaddrs() logic, it puts interfaces into "ip" or "ipv4" namespaces.

Windows

Fetch information about network objects using GetAdaptersAddresses

NOTE: Doesn't support WMI because latter doen't provide MMU, also
does not have support for teaming, VLAN and other virtual NICs.

NOTE: To distinguish interface address and NIC name, it adds id
as an end to NIC name, i.e. "Local Area Connection #1:0"

WMI

WMI-based implementation of NetInfo. Currently not supported.

Uses Win32_NetworkAdapter WMI table to gather information

Functions

HI_NET_TO_OBJ, HI_NET_FROM_OBJ, HI_NET_PARENT, HI_NET_PARENT_OBJ


Conversion macros

#define HI_NET_FROM_OBJ(object)
#define HI_NET_TO_OBJ(object)
#define HI_NET_PARENT_OBJ(object)
#define HI_NET_PARENT(object)

hi_net_add

public


Add network object to a global list

STATIC_INLINE void hi_net_add(hi_net_object_t* netobj) 

hi_net_attach

public


Attach network object to parent as a slave

ARGUMENTS

STATIC_INLINE void hi_net_attach(hi_net_object_t* netobj, hi_net_object_t* parent) 

hi_net_find

public


Find network object by it's name

ARGUMENTS

RETURN VALUES
network object or NULL if it wasn't found

STATIC_INLINE hi_net_object_t* hi_net_find(const char* name) 

hi_net_list

public


Probe system's network objects (if needed) and return pointer
to global network object list head

ARGUMENTS

RETURN VALUES
pointer to head or NULL if probe failed

STATIC_INLINE list_head_t* hi_net_list(boolean_t reprobe) 

Types

typedef enum hi_net_device_type


Type of NIC

typedef enum hi_net_device_type {
    HI_NET_UNKNOWN,
    HI_NET_ETHERNET,
    HI_NET_X25,
    HI_NET_TOKEN_RING,
    HI_NET_WIRELESS,
    HI_NET_INFINIBAND,
    HI_NET_POINT_TO_POINT,
    HI_NET_TUNNEL,
    HI_NET_VIRTUAL,

    HI_NET_DEV_MAX
} hi_net_device_type_t;

typedef enum hi_net_device_duplex


Current state of NIC link

NOTES
Not all NICs support reporting of simplex or half-duplex, thus full-duplex will be used

typedef enum hi_net_device_duplex {
    HI_NET_NO_LINK,
    HI_NET_SIMPLEX,
    HI_NET_HALF_DUPLEX,
    HI_NET_FULL_DUPLEX
} hi_net_device_duplex_t;

typedef struct hi_net_device


NIC descriptor

MEMBERS

typedef struct hi_net_device {
    hi_net_device_type_t     type;
    long                     speed;
    hi_net_device_duplex_t    duplex;
    int                         mtu;

    char                    address[HI_NET_DEV_ADDR_STRLEN];
} hi_net_device_t;

typedef struct hi_net_address_flags


Interface flags

MEMBERS

NOTES
For information on nofailover and deprecated see ifconfig(1M)

typedef struct hi_net_address_flags {
    boolean_t    up;
    boolean_t    running;
    boolean_t    dynamic;
    /* For Solaris IPMP */
    boolean_t    nofailover;
    boolean_t     deprecated;
} hi_net_address_flags_t;

typedef struct hi_net_ipv4_address


IPv4 interface

address and netmask are represented as strings in dotted decimal notation.

typedef struct hi_net_ipv4_address {
    hi_net_address_flags_t flags;
    char address[HI_NET_IPv4_STRLEN];
    char netmask[HI_NET_IPv4_STRLEN];
} hi_net_ipv4_address_t;

typedef struct hi_net_ipv6_address


IPv4 interface

address and netmask are represented as strings in RFC5952 format

NOTES
inet_ntop() and similiar functions are used to convert IPv6 address to string

typedef struct hi_net_ipv6_address {
    hi_net_address_flags_t flags;
    char address[HI_NET_IPv6_STRLEN];
    char netmask[HI_NET_IPv6_STRLEN];
} hi_net_ipv6_address_t;

typedef enum hi_net_object_type


Type of NetInfo object

VALUES

typedef enum hi_net_object_type {
    HI_NET_LOOPBACK,
    HI_NET_DEVICE,
    HI_NET_VLAN,
    HI_NET_BRIDGE,
    HI_NET_BOND,
    HI_NET_SWITCH,
    HI_NET_IPv4_ADDRESS,
    HI_NET_IPv6_ADDRESS,

    HI_NET_MAXIMUM
} hi_net_object_type_t;

typedef struct hi_net_object


NetInfo descriptor

MEMBERS

typedef struct hi_net_object {
    hi_object_header_t        hdr;
#define n_net_name          hdr.name
    
    hi_net_object_type_t     type;

    union {
        hi_net_device_t     device;
        hi_net_ipv4_address_t ipv4_address;
        hi_net_ipv6_address_t ipv6_address;
        int vlan_id;
    };
} hi_net_object_t;