cacheinfo structs
This commit is contained in:
@@ -15,6 +15,9 @@ module Netlink
|
|||||||
:tx_window_errors,
|
:tx_window_errors,
|
||||||
:rx_compressed, :tx_compressed
|
:rx_compressed, :tx_compressed
|
||||||
|
|
||||||
|
RTACacheInfo = Struct.new :clntref, :lastuse, :expires, :error, :used, :id, :ts, :tsage
|
||||||
|
IFACacheInfo = Struct.new :prefered, :valid, :cstamp, :tstamp
|
||||||
|
|
||||||
# Base class for Netlink messages
|
# Base class for Netlink messages
|
||||||
class Message
|
class Message
|
||||||
# Map of numeric message type code => message class
|
# Map of numeric message type code => message class
|
||||||
@@ -44,6 +47,14 @@ module Netlink
|
|||||||
:pack => lambda { |val| val.to_a.pack("Q23") },
|
:pack => lambda { |val| val.to_a.pack("Q23") },
|
||||||
:unpack => lambda { |str| LinkStats.new(*(str.unpack("Q23"))) },
|
:unpack => lambda { |str| LinkStats.new(*(str.unpack("Q23"))) },
|
||||||
},
|
},
|
||||||
|
:rta_cacheinfo => {
|
||||||
|
:pack => lambda { |val| val.to_a.pack("L*") },
|
||||||
|
:unpack => lambda { |str| RTACacheInfo.new(*(str.unpack("L*"))) },
|
||||||
|
},
|
||||||
|
:ifa_cacheinfo => {
|
||||||
|
:pack => lambda { |val| val.to_a.pack("L*") },
|
||||||
|
:unpack => lambda { |str| IFACacheInfo.new(*(str.unpack("L*"))) },
|
||||||
|
},
|
||||||
:l3addr => {
|
:l3addr => {
|
||||||
:pack => lambda { |val| val.hton },
|
:pack => lambda { |val| val.hton },
|
||||||
:unpack => lambda { |val| IPAddr.new_ntoh(val) },
|
:unpack => lambda { |val| IPAddr.new_ntoh(val) },
|
||||||
@@ -270,7 +281,7 @@ module Netlink
|
|||||||
rtattr :label, IFA_LABEL, :cstring
|
rtattr :label, IFA_LABEL, :cstring
|
||||||
rtattr :broadcast, IFA_BROADCAST, :l3addr
|
rtattr :broadcast, IFA_BROADCAST, :l3addr
|
||||||
rtattr :anycast, IFA_ANYCAST, :l3addr
|
rtattr :anycast, IFA_ANYCAST, :l3addr
|
||||||
rtattr :cacheinfo, IFA_CACHEINFO
|
rtattr :cacheinfo, IFA_CACHEINFO, :ifa_cacheinfo
|
||||||
rtattr :multicast, IFA_MULTICAST, :l3addr
|
rtattr :multicast, IFA_MULTICAST, :l3addr
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -295,7 +306,7 @@ module Netlink
|
|||||||
rtattr :metrics, RTA_METRICS
|
rtattr :metrics, RTA_METRICS
|
||||||
rtattr :multipath, RTA_MULTIPATH
|
rtattr :multipath, RTA_MULTIPATH
|
||||||
rtattr :flow, RTA_FLOW
|
rtattr :flow, RTA_FLOW
|
||||||
rtattr :cacheinfo, RTA_CACHEINFO
|
rtattr :cacheinfo, RTA_CACHEINFO, :rta_cacheinfo
|
||||||
rtattr :table2, RTA_TABLE, :uint32 # NOTE: table in two places!
|
rtattr :table2, RTA_TABLE, :uint32 # NOTE: table in two places!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@@ -93,14 +93,14 @@ if __FILE__ == $0
|
|||||||
addrs = nl.addrs_by_index(:family=>Socket::AF_UNSPEC)
|
addrs = nl.addrs_by_index(:family=>Socket::AF_UNSPEC)
|
||||||
routes = nl.routes_by_oif(:family=>Socket::AF_UNSPEC)
|
routes = nl.routes_by_oif(:family=>Socket::AF_UNSPEC)
|
||||||
links.each do |link|
|
links.each do |link|
|
||||||
#p link
|
p link if $VERBOSE
|
||||||
puts "#{link.ifname}"
|
puts "#{link.ifname}"
|
||||||
addrs[link.index].each do |addr|
|
addrs[link.index].each do |addr|
|
||||||
#p addr
|
p addr if $VERBOSE
|
||||||
puts " family=#{addr.family} #{addr.address}/#{addr.prefixlen} label=#{addr.label}"
|
puts " family=#{addr.family} #{addr.address}/#{addr.prefixlen} label=#{addr.label}"
|
||||||
end
|
end
|
||||||
routes[link.index].each do |route|
|
routes[link.index].each do |route|
|
||||||
#p route
|
p route if $VERBOSE
|
||||||
puts " >> family=#{route.family} #{route.dst}/#{route.dst_len} gw=#{route.gateway}"
|
puts " >> family=#{route.family} #{route.dst}/#{route.dst_len} gw=#{route.gateway}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user