Module eco.rtnl
RTNETLINK helpers.
This module provides small helpers to build and parse common rtnetlink message headers used with eco.nl.
Typical workflow:
- open a NETLINK_ROUTE socket via eco.nl.open
- build a netlink request using eco.nl.nlmsg
- append an rtnetlink header (e.g. rtnl.rtgenmsg, rtnl.ifinfomsg, rtnl.rtmsg)
- send and receive; parse replies using rtnl.parse_ifinfomsg, etc.
Many constants from Linux headers are also exported (RTM*, IFF*, IFLA*, IFA*, RTA*, RTNLGRP*, RTMGRP*, RTSCOPE*, RTN*, RTPROT_*).
Functions
| rtgenmsg (t) | Build a struct rtgenmsg. |
| ifinfomsg (t) | Build a struct ifinfomsg. |
| ifaddrmsg (t) | Build a struct ifaddrmsg. |
| rtmsg (t) | Build a struct rtmsg. |
| parse_ifinfomsg (msg) | Parse struct ifinfomsg from a netlink message. |
| parse_ifaddrmsg (msg) | Parse struct ifaddrmsg from a netlink message. |
| parse_rtmsg (msg) | Parse struct rtmsg from a netlink message. |
Functions
- rtgenmsg (t)
-
Build a
struct rtgenmsg.Returns a binary string containing the packed C structure.
Parameters:
- t
table
Table with field:
family(int): address family (e.g. eco.socket.AF_PACKET).
Returns:
-
string
Packed
struct rtgenmsg. - t
table
- ifinfomsg (t)
-
Build a
struct ifinfomsg.Missing fields default to 0.
Parameters:
Returns:
-
string
Packed
struct ifinfomsg. - ifaddrmsg (t)
-
Build a
struct ifaddrmsg.Missing fields default to 0.
Parameters:
- t
table
Table fields:
family(int)prefixlen(int)flags(int)scope(int)index(int)
Returns:
-
string
Packed
struct ifaddrmsg. - t
table
- rtmsg (t)
-
Build a
struct rtmsg.Missing fields default to 0.
Parameters:
- t
table
Table fields:
Returns:
-
string
Packed
struct rtmsg. - t
table
- parse_ifinfomsg (msg)
-
Parse
struct ifinfomsgfrom a netlink message.The input message must currently point to an
RTM_NEWLINKorRTM_DELLINKmessage (see next).Parameters:
- msg nlmsg_ker A kernel message parser from eco.nl.
Returns:
Or
- nil On failure.
- string Error message.
- parse_ifaddrmsg (msg)
-
Parse
struct ifaddrmsgfrom a netlink message.The input message must currently point to an
RTM_NEWADDRmessage.Parameters:
- msg nlmsg_ker A kernel message parser from eco.nl.
Returns:
-
table
Table fields:
family,prefixlen,flags,scope,index.Or
- nil On failure.
- string Error message.
- parse_rtmsg (msg)
-
Parse
struct rtmsgfrom a netlink message.The input message must currently point to an
RTM_NEWROUTEorRTM_DELROUTEmessage.Parameters:
- msg nlmsg_ker A kernel message parser from eco.nl.
Returns:
Or
- nil On failure.
- string Error message.