[][src]Module neli::consts

C constants defined as types

High level notes

The items in this module are created by macros, which give them the traits necessary to be serialized into Netlink compatible types. The macros are exported - you can use them too! See impl_var, impl_trait, and impl_var_trait.

Note that most of these constants come from the Linux kernel headers, which can be found in /usr/include/linux on many distros. You can also see man 3 netlink, man 7 netlink, and man 7 rtnetlink for more information.

Design decisions

  • Macros are exported so that these conventions are extensible and usable for data types implemented by the user in the case of new netlink families (which is supported by the protocol). In this case, there is no way in which I can support every custom netlink family but my aim is to make this library as flexible as possible so that it is painless to hook your custom netlink data type into the existing library support.
  • Enums are used so that:
    • Values can be checked based on a finite number of inputs as opposed to the range of whatever integer data type C defines as the struct member type. This hopefully makes it easier to catch garbage responses and corruption when an invalid netlink message is sent to the kernel.
    • Only the enum or an enum implementing a marker trait in the case of generics can be used in the appropriate places when constructing netlink messages. This takes guess work out of which constants can be used where. Netlink documentation is not always complete and sometimes takes a bit of trial and error actually sending messages to the kernel to figure out if you are using the correct constants. This setup should let you know at compile time if you are doing something you should not be doing.
  • UnrecognizedVariant is included in each enum because completeness cannot be guaranteed for every constant for every protocol. This allows you to inspect the integer value returned and if you are sure that it is correct, you can use it. If it is a garbage value, this can also be useful for error reporting.

Enums

AddrFamily

General address families for sockets

Af

Internet address families

Arphrd

Interface types

CtrlAttr

Values for nla_type in Nlattr

CtrlAttrMcastGrp

Values for nla_type in Nlattr

CtrlCmd

Values for cmd in Genlmsghdr

GenlId

Values for nl_type in Nlmsghdr

Ifa

Enum for use with Rtattr.rta_type

IfaF

Interface address flags

Iff

Values for ifi_flags in Ifinfomsg

Ifla

Enum for use with Rtattr.rta_type

NlFamily

Values for nl_family in NlSocket

NlmF

Values for nl_flags in Nlmsghdr

Nlmsg

Values for nl_type in Nlmsghdr

Ntf

Arp neighbor cache entry flags

Nud

Arp neighbor cache entry states

RtScope

rtm_scope The distance between destinations

RtTable

rt_class_t Reserved route table identifiers

Rta

Enum for use with Rtattr.rta_type - Values are routing message attributes

RtmF

rtm_flags Flags for rtnetlink messages

Rtn

rtm_type The results of a lookup from a route table

Rtprot

rtm_protocol The origins of routes that are defined in the kernel

Tca

Enum for use with Rtattr.rta_type - Values specify queuing discipline attributes

Traits

Cmd

Trait marking constants valid for use in Genlmsghdr.cmd

NlAttrType

Marker trait for types usable in Nlattr.nla_type

NlType

Trait marking constants valid for use in Nlmsghdr.nl_type

RtaType

Marker trait for Rtattr.rta_type field

Functions

alignto

Reimplementation of alignto macro in C