Rename messages to match their C names
This commit is contained in:
@@ -118,7 +118,7 @@ module Netlink
|
|||||||
RTM_GETDCB = 78
|
RTM_GETDCB = 78
|
||||||
RTM_SETDCB = 79
|
RTM_SETDCB = 79
|
||||||
|
|
||||||
# Route#type
|
# RT#type
|
||||||
RTN_UNSPEC = 0
|
RTN_UNSPEC = 0
|
||||||
RTN_UNICAST = 1
|
RTN_UNICAST = 1
|
||||||
RTN_LOCAL = 2
|
RTN_LOCAL = 2
|
||||||
@@ -132,7 +132,7 @@ module Netlink
|
|||||||
RTN_NAT = 10
|
RTN_NAT = 10
|
||||||
RTN_XRESOLVE = 11
|
RTN_XRESOLVE = 11
|
||||||
|
|
||||||
# Route#protocol
|
# RT#protocol
|
||||||
RTPROT_UNSPEC = 0
|
RTPROT_UNSPEC = 0
|
||||||
RTPROT_REDIRECT = 1
|
RTPROT_REDIRECT = 1
|
||||||
RTPROT_KERNEL = 2
|
RTPROT_KERNEL = 2
|
||||||
@@ -148,20 +148,20 @@ module Netlink
|
|||||||
RTPROT_NTK = 15
|
RTPROT_NTK = 15
|
||||||
RTPROT_DHCP = 16
|
RTPROT_DHCP = 16
|
||||||
|
|
||||||
# Route#scope, Addr#scope
|
# RT#scope, IFAddr#scope
|
||||||
RT_SCOPE_UNIVERSE = 0
|
RT_SCOPE_UNIVERSE = 0
|
||||||
RT_SCOPE_SITE = 200
|
RT_SCOPE_SITE = 200
|
||||||
RT_SCOPE_LINK = 253
|
RT_SCOPE_LINK = 253
|
||||||
RT_SCOPE_HOST = 254
|
RT_SCOPE_HOST = 254
|
||||||
RT_SCOPE_NOWHERE = 255
|
RT_SCOPE_NOWHERE = 255
|
||||||
|
|
||||||
# Route#flags
|
# RT#flags
|
||||||
RTM_F_NOTIFY = 0x100
|
RTM_F_NOTIFY = 0x100
|
||||||
RTM_F_CLONED = 0x200
|
RTM_F_CLONED = 0x200
|
||||||
RTM_F_EQUALIZE = 0x400
|
RTM_F_EQUALIZE = 0x400
|
||||||
RTM_F_PREFIX = 0x800
|
RTM_F_PREFIX = 0x800
|
||||||
|
|
||||||
# Route#table (reserved values)
|
# RT#table (reserved values)
|
||||||
RT_TABLE_UNSPEC = 0
|
RT_TABLE_UNSPEC = 0
|
||||||
RT_TABLE_COMPAT = 252
|
RT_TABLE_COMPAT = 252
|
||||||
RT_TABLE_DEFAULT = 253
|
RT_TABLE_DEFAULT = 253
|
||||||
@@ -183,7 +183,7 @@ module Netlink
|
|||||||
RTA_CACHEINFO = 12
|
RTA_CACHEINFO = 12
|
||||||
RTA_TABLE = 15
|
RTA_TABLE = 15
|
||||||
|
|
||||||
# Keys for Route#metrics
|
# Keys for RT#metrics
|
||||||
RTAX_UNSPEC = 0
|
RTAX_UNSPEC = 0
|
||||||
RTAX_LOCK = 1
|
RTAX_LOCK = 1
|
||||||
RTAX_MTU = 2
|
RTAX_MTU = 2
|
||||||
|
@@ -67,7 +67,7 @@ module Netlink
|
|||||||
|
|
||||||
# L2 addresses are presented as ASCII hex. You may optionally include
|
# L2 addresses are presented as ASCII hex. You may optionally include
|
||||||
# colons, hyphens or dots.
|
# colons, hyphens or dots.
|
||||||
# Link.new(:address => "00:11:22:33:44:55") # this is OK
|
# IFInfo.new(:address => "00:11:22:33:44:55") # this is OK
|
||||||
define_type :l2addr,
|
define_type :l2addr,
|
||||||
:pack => lambda { |val,obj| [val.delete(":-.")].pack("H*") },
|
:pack => lambda { |val,obj| [val.delete(":-.")].pack("H*") },
|
||||||
:unpack => lambda { |val,obj| val.unpack("H*").first }
|
:unpack => lambda { |val,obj| val.unpack("H*").first }
|
||||||
@@ -75,15 +75,15 @@ module Netlink
|
|||||||
# L3 addresses are presented as IPAddr objects where possible. When
|
# L3 addresses are presented as IPAddr objects where possible. When
|
||||||
# setting an address, you may provide an IPAddr object, an IP in readable
|
# setting an address, you may provide an IPAddr object, an IP in readable
|
||||||
# string form, or an integer. All of the following are acceptable:
|
# string form, or an integer. All of the following are acceptable:
|
||||||
# Addr.new(:family=>Socket::AF_INET, :address=>IPAddr.new("1.2.3.4"))
|
# IFAddr.new(:family=>Socket::AF_INET, :address=>IPAddr.new("1.2.3.4"))
|
||||||
# Addr.new(:family=>Socket::AF_INET, :address=>"1.2.3.4")
|
# IFAddr.new(:family=>Socket::AF_INET, :address=>"1.2.3.4")
|
||||||
# Addr.new(:family=>Socket::AF_INET, :address=>0x01020304)
|
# IFAddr.new(:family=>Socket::AF_INET, :address=>0x01020304)
|
||||||
# Furthermore, the 'family' will be set automatically if it is unset
|
# Furthermore, the 'family' will be set automatically if it is unset
|
||||||
# at the time the message is encoded:
|
# at the time the message is encoded:
|
||||||
# Addr.new(:address=>IPAddr.new("1.2.3.4")).to_s # ok
|
# IFAddr.new(:address=>IPAddr.new("1.2.3.4")).to_s # ok
|
||||||
# Addr.new(:address=>"1.2.3.4").to_s # ok
|
# IFAddr.new(:address=>"1.2.3.4").to_s # ok
|
||||||
# Addr.new(:address=>0x01020304).to_s # error, unknown family
|
# IFAddr.new(:address=>0x01020304).to_s # error, unknown family
|
||||||
# Addr.new(:address=>"1.2.3.4", :local=>"::1").to_s # error, mismatched families
|
# IFAddr.new(:address=>"1.2.3.4", :local=>"::1").to_s # error, mismatched families
|
||||||
define_type :l3addr,
|
define_type :l3addr,
|
||||||
:pack => lambda { |val,obj|
|
:pack => lambda { |val,obj|
|
||||||
case obj.family
|
case obj.family
|
||||||
|
@@ -22,7 +22,7 @@ module Netlink
|
|||||||
IFMap = Struct.new :mem_start, :mem_end, :base_addr, :irq, :dma, :port
|
IFMap = Struct.new :mem_start, :mem_end, :base_addr, :irq, :dma, :port
|
||||||
|
|
||||||
# struct ifinfomsg
|
# struct ifinfomsg
|
||||||
class Link < RtattrMessage
|
class IFInfo < RtattrMessage
|
||||||
code RTM_NEWLINK, RTM_DELLINK, RTM_GETLINK
|
code RTM_NEWLINK, RTM_DELLINK, RTM_GETLINK
|
||||||
|
|
||||||
field :family, :uchar # Socket::AF_*
|
field :family, :uchar # Socket::AF_*
|
||||||
@@ -73,7 +73,7 @@ module Netlink
|
|||||||
IFACacheInfo = Struct.new :prefered, :valid, :cstamp, :tstamp
|
IFACacheInfo = Struct.new :prefered, :valid, :cstamp, :tstamp
|
||||||
|
|
||||||
# struct ifaddrmsg
|
# struct ifaddrmsg
|
||||||
class Addr < RtattrMessage
|
class IFAddr < RtattrMessage
|
||||||
code RTM_NEWADDR, RTM_DELADDR, RTM_GETADDR
|
code RTM_NEWADDR, RTM_DELADDR, RTM_GETADDR
|
||||||
|
|
||||||
field :family, :uchar # Socket::AF_*
|
field :family, :uchar # Socket::AF_*
|
||||||
@@ -96,7 +96,7 @@ module Netlink
|
|||||||
RTACacheInfo = Struct.new :clntref, :lastuse, :expires, :error, :used, :id, :ts, :tsage
|
RTACacheInfo = Struct.new :clntref, :lastuse, :expires, :error, :used, :id, :ts, :tsage
|
||||||
|
|
||||||
# struct rtmsg
|
# struct rtmsg
|
||||||
class Route < RtattrMessage
|
class RT < RtattrMessage
|
||||||
code RTM_NEWROUTE, RTM_DELROUTE, RTM_GETROUTE
|
code RTM_NEWROUTE, RTM_DELROUTE, RTM_GETROUTE
|
||||||
|
|
||||||
field :family, :uchar # Socket::AF_*
|
field :family, :uchar # Socket::AF_*
|
||||||
@@ -144,33 +144,33 @@ module Netlink
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Download a list of links (interfaces). Either returns an array of
|
# Download a list of links (interfaces). Either returns an array of
|
||||||
# Netlink::Link objects, or yields them to the supplied block.
|
# Netlink::IFInfo objects, or yields them to the supplied block.
|
||||||
#
|
#
|
||||||
# res = nl.link_list
|
# res = nl.read_links
|
||||||
# p res
|
# p res
|
||||||
# [#<Netlink::Link {:family=>0, :pad=>0, :type=>772, :index=>1,
|
# [#<Netlink::IFInfo {:family=>0, :pad=>0, :type=>772, :index=>1,
|
||||||
# :flags=>65609, :change=>0, :ifname=>"lo", :txqlen=>0, :operstate=>0,
|
# :flags=>65609, :change=>0, :ifname=>"lo", :txqlen=>0, :operstate=>0,
|
||||||
# :linkmode=>0, :mtu=>16436, :qdisc=>"noqueue", :map=>"...",
|
# :linkmode=>0, :mtu=>16436, :qdisc=>"noqueue", :map=>"...",
|
||||||
# :address=>"\x00\x00\x00\x00\x00\x00", :broadcast=>"\x00\x00\x00\x00\x00\x00",
|
# :address=>"\x00\x00\x00\x00\x00\x00", :broadcast=>"\x00\x00\x00\x00\x00\x00",
|
||||||
# :stats=>#<struct Netlink::LinkStats rx_packets=22, ...>,
|
# :stats32=>#<struct Netlink::LinkStats rx_packets=22, ...>,
|
||||||
# :stats64=>#<struct Netlink::LinkStats rx_packets=22, ...>}>, ...]
|
# :stats64=>#<struct Netlink::LinkStats rx_packets=22, ...>}>, ...]
|
||||||
def read_links(opt=nil, &blk)
|
def read_links(opt=nil, &blk)
|
||||||
send_request RTM_GETLINK, Link.new(opt),
|
send_request RTM_GETLINK, IFInfo.new(opt),
|
||||||
NLM_F_ROOT | NLM_F_MATCH | NLM_F_REQUEST
|
NLM_F_ROOT | NLM_F_MATCH | NLM_F_REQUEST
|
||||||
receive_until_done(RTM_NEWLINK, &blk)
|
receive_until_done(RTM_NEWLINK, &blk)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Download a list of routes. Either returns an array of
|
# Download a list of routes. Either returns an array of
|
||||||
# Netlink::Route objects, or yields them to the supplied block.
|
# Netlink::RT objects, or yields them to the supplied block.
|
||||||
#
|
#
|
||||||
# A hash of kernel options may be supplied, but you might also have
|
# A hash of kernel options may be supplied, but you might also have
|
||||||
# to perform your own filtering. e.g.
|
# to perform your own filtering. e.g.
|
||||||
# rt.read_routes(:family=>Socket::AF_INET) # works
|
# rt.read_routes(:family=>Socket::AF_INET) # works
|
||||||
# rt.read_routes(:protocol=>Netlink::RTPROT_STATIC) # ignored
|
# rt.read_routes(:protocol=>Netlink::RTPROT_STATIC) # ignored
|
||||||
#
|
#
|
||||||
# res = nl.routes(:family => Socket::AF_INET)
|
# res = nl.read_routes(:family => Socket::AF_INET)
|
||||||
# p res
|
# p res
|
||||||
# [#<Netlink::Route {:family=>2, :dst_len=>32, :src_len=>0, :tos=>0,
|
# [#<Netlink::RT {:family=>2, :dst_len=>32, :src_len=>0, :tos=>0,
|
||||||
# :table=>255, :protocol=>2, :scope=>253, :type=>3, :flags=>0, :table2=>255,
|
# :table=>255, :protocol=>2, :scope=>253, :type=>3, :flags=>0, :table2=>255,
|
||||||
# :dst=>#<IPAddr: IPv4:127.255.255.255/255.255.255.255>,
|
# :dst=>#<IPAddr: IPv4:127.255.255.255/255.255.255.255>,
|
||||||
# :prefsrc=>#<IPAddr: IPv4:127.0.0.1/255.255.255.255>, :oif=>1}>, ...]
|
# :prefsrc=>#<IPAddr: IPv4:127.0.0.1/255.255.255.255>, :oif=>1}>, ...]
|
||||||
@@ -178,29 +178,29 @@ module Netlink
|
|||||||
# Note that not all attributes will always be present. In particular,
|
# Note that not all attributes will always be present. In particular,
|
||||||
# a defaultroute (dst_len=0) misses out the dst address completely:
|
# a defaultroute (dst_len=0) misses out the dst address completely:
|
||||||
#
|
#
|
||||||
# [#<Netlink::Route {:family=>2, :dst_len=>0, :src_len=>0, :tos=>0,
|
# [#<Netlink::RT {:family=>2, :dst_len=>0, :src_len=>0, :tos=>0,
|
||||||
# :table=>254, :protocol=>4, :scope=>0, :type=>1, :flags=>0, :table2=>254,
|
# :table=>254, :protocol=>4, :scope=>0, :type=>1, :flags=>0, :table2=>254,
|
||||||
# :gateway=>#<IPAddr: IPv4:10.69.255.253/255.255.255.255>, :oif=>2}>, ...]
|
# :gateway=>#<IPAddr: IPv4:10.69.255.253/255.255.255.255>, :oif=>2}>, ...]
|
||||||
def read_routes(opt=nil, &blk)
|
def read_routes(opt=nil, &blk)
|
||||||
send_request RTM_GETROUTE, Route.new(opt),
|
send_request RTM_GETROUTE, RT.new(opt),
|
||||||
NLM_F_ROOT | NLM_F_MATCH | NLM_F_REQUEST
|
NLM_F_ROOT | NLM_F_MATCH | NLM_F_REQUEST
|
||||||
receive_until_done(RTM_NEWROUTE, &blk)
|
receive_until_done(RTM_NEWROUTE, &blk)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Download a list of link addresses. Either returns an array of
|
# Download a list of link addresses. Either returns an array of
|
||||||
# Netlink::Addr objects, or yields them to the supplied block.
|
# Netlink::IFAddr objects, or yields them to the supplied block.
|
||||||
# You will need to use the 'index' to cross reference to the interface.
|
# You will need to use the 'index' to cross reference to the interface.
|
||||||
#
|
#
|
||||||
# A hash of kernel options may be supplied, but likely only :family
|
# A hash of kernel options may be supplied, but likely only :family
|
||||||
# is honoured.
|
# is honoured.
|
||||||
#
|
#
|
||||||
# res = nl.addrs(:family => Socket::AF_INET)
|
# res = nl.read_addrs(:family => Socket::AF_INET)
|
||||||
# p res
|
# p res
|
||||||
# [#<Netlink::Addr {:family=>2, :prefixlen=>8, :flags=>128, :scope=>254,
|
# [#<Netlink::IFAddr {:family=>2, :prefixlen=>8, :flags=>128, :scope=>254,
|
||||||
# :index=>1, :address=>#<IPAddr: IPv4:127.0.0.1/255.255.255.255>,
|
# :index=>1, :address=>#<IPAddr: IPv4:127.0.0.1/255.255.255.255>,
|
||||||
# :local=>#<IPAddr: IPv4:127.0.0.1/255.255.255.255>, :label=>"lo"}>, ...]
|
# :local=>#<IPAddr: IPv4:127.0.0.1/255.255.255.255>, :label=>"lo"}>, ...]
|
||||||
def read_addrs(opt=nil, &blk)
|
def read_addrs(opt=nil, &blk)
|
||||||
send_request RTM_GETADDR, Addr.new(opt),
|
send_request RTM_GETADDR, IFAddr.new(opt),
|
||||||
NLM_F_ROOT | NLM_F_MATCH | NLM_F_REQUEST
|
NLM_F_ROOT | NLM_F_MATCH | NLM_F_REQUEST
|
||||||
receive_until_done(RTM_NEWADDR, &blk)
|
receive_until_done(RTM_NEWADDR, &blk)
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user