From b39ff5da76f9e2825f88e883b2b9e90ff1cdd053 Mon Sep 17 00:00:00 2001 From: Brian Candler Date: Sun, 1 May 2011 09:20:23 +0100 Subject: [PATCH] Rename messages to match their C names --- lib/netlink/constants.rb | 12 ++++++------ lib/netlink/message.rb | 16 ++++++++-------- lib/netlink/route.rb | 34 +++++++++++++++++----------------- 3 files changed, 31 insertions(+), 31 deletions(-) diff --git a/lib/netlink/constants.rb b/lib/netlink/constants.rb index f2ac379..eb1b6f1 100644 --- a/lib/netlink/constants.rb +++ b/lib/netlink/constants.rb @@ -118,7 +118,7 @@ module Netlink RTM_GETDCB = 78 RTM_SETDCB = 79 - # Route#type + # RT#type RTN_UNSPEC = 0 RTN_UNICAST = 1 RTN_LOCAL = 2 @@ -132,7 +132,7 @@ module Netlink RTN_NAT = 10 RTN_XRESOLVE = 11 - # Route#protocol + # RT#protocol RTPROT_UNSPEC = 0 RTPROT_REDIRECT = 1 RTPROT_KERNEL = 2 @@ -148,20 +148,20 @@ module Netlink RTPROT_NTK = 15 RTPROT_DHCP = 16 - # Route#scope, Addr#scope + # RT#scope, IFAddr#scope RT_SCOPE_UNIVERSE = 0 RT_SCOPE_SITE = 200 RT_SCOPE_LINK = 253 RT_SCOPE_HOST = 254 RT_SCOPE_NOWHERE = 255 - # Route#flags + # RT#flags RTM_F_NOTIFY = 0x100 RTM_F_CLONED = 0x200 RTM_F_EQUALIZE = 0x400 RTM_F_PREFIX = 0x800 - # Route#table (reserved values) + # RT#table (reserved values) RT_TABLE_UNSPEC = 0 RT_TABLE_COMPAT = 252 RT_TABLE_DEFAULT = 253 @@ -183,7 +183,7 @@ module Netlink RTA_CACHEINFO = 12 RTA_TABLE = 15 - # Keys for Route#metrics + # Keys for RT#metrics RTAX_UNSPEC = 0 RTAX_LOCK = 1 RTAX_MTU = 2 diff --git a/lib/netlink/message.rb b/lib/netlink/message.rb index a165594..dc83e8d 100644 --- a/lib/netlink/message.rb +++ b/lib/netlink/message.rb @@ -67,7 +67,7 @@ module Netlink # L2 addresses are presented as ASCII hex. You may optionally include # 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, :pack => lambda { |val,obj| [val.delete(":-.")].pack("H*") }, :unpack => lambda { |val,obj| val.unpack("H*").first } @@ -75,15 +75,15 @@ module Netlink # L3 addresses are presented as IPAddr objects where possible. When # setting an address, you may provide an IPAddr object, an IP in readable # string form, or an integer. All of the following are acceptable: - # Addr.new(:family=>Socket::AF_INET, :address=>IPAddr.new("1.2.3.4")) - # Addr.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=>IPAddr.new("1.2.3.4")) + # IFAddr.new(:family=>Socket::AF_INET, :address=>"1.2.3.4") + # IFAddr.new(:family=>Socket::AF_INET, :address=>0x01020304) # Furthermore, the 'family' will be set automatically if it is unset # at the time the message is encoded: - # Addr.new(:address=>IPAddr.new("1.2.3.4")).to_s # ok - # Addr.new(:address=>"1.2.3.4").to_s # ok - # Addr.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=>IPAddr.new("1.2.3.4")).to_s # ok + # IFAddr.new(:address=>"1.2.3.4").to_s # ok + # IFAddr.new(:address=>0x01020304).to_s # error, unknown family + # IFAddr.new(:address=>"1.2.3.4", :local=>"::1").to_s # error, mismatched families define_type :l3addr, :pack => lambda { |val,obj| case obj.family diff --git a/lib/netlink/route.rb b/lib/netlink/route.rb index 4172b92..4a692c8 100644 --- a/lib/netlink/route.rb +++ b/lib/netlink/route.rb @@ -22,7 +22,7 @@ module Netlink IFMap = Struct.new :mem_start, :mem_end, :base_addr, :irq, :dma, :port # struct ifinfomsg - class Link < RtattrMessage + class IFInfo < RtattrMessage code RTM_NEWLINK, RTM_DELLINK, RTM_GETLINK field :family, :uchar # Socket::AF_* @@ -73,7 +73,7 @@ module Netlink IFACacheInfo = Struct.new :prefered, :valid, :cstamp, :tstamp # struct ifaddrmsg - class Addr < RtattrMessage + class IFAddr < RtattrMessage code RTM_NEWADDR, RTM_DELADDR, RTM_GETADDR field :family, :uchar # Socket::AF_* @@ -96,7 +96,7 @@ module Netlink RTACacheInfo = Struct.new :clntref, :lastuse, :expires, :error, :used, :id, :ts, :tsage # struct rtmsg - class Route < RtattrMessage + class RT < RtattrMessage code RTM_NEWROUTE, RTM_DELROUTE, RTM_GETROUTE field :family, :uchar # Socket::AF_* @@ -144,33 +144,33 @@ module Netlink end # 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 - # [#0, :pad=>0, :type=>772, :index=>1, + # [#0, :pad=>0, :type=>772, :index=>1, # :flags=>65609, :change=>0, :ifname=>"lo", :txqlen=>0, :operstate=>0, # :linkmode=>0, :mtu=>16436, :qdisc=>"noqueue", :map=>"...", # :address=>"\x00\x00\x00\x00\x00\x00", :broadcast=>"\x00\x00\x00\x00\x00\x00", - # :stats=>#, + # :stats32=>#, # :stats64=>#}>, ...] 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 receive_until_done(RTM_NEWLINK, &blk) end # 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 # to perform your own filtering. e.g. # rt.read_routes(:family=>Socket::AF_INET) # works # 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 - # [#2, :dst_len=>32, :src_len=>0, :tos=>0, + # [#2, :dst_len=>32, :src_len=>0, :tos=>0, # :table=>255, :protocol=>2, :scope=>253, :type=>3, :flags=>0, :table2=>255, # :dst=>#, # :prefsrc=>#, :oif=>1}>, ...] @@ -178,29 +178,29 @@ module Netlink # Note that not all attributes will always be present. In particular, # a defaultroute (dst_len=0) misses out the dst address completely: # - # [#2, :dst_len=>0, :src_len=>0, :tos=>0, + # [#2, :dst_len=>0, :src_len=>0, :tos=>0, # :table=>254, :protocol=>4, :scope=>0, :type=>1, :flags=>0, :table2=>254, # :gateway=>#, :oif=>2}>, ...] 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 receive_until_done(RTM_NEWROUTE, &blk) end # 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. # # A hash of kernel options may be supplied, but likely only :family # is honoured. # - # res = nl.addrs(:family => Socket::AF_INET) + # res = nl.read_addrs(:family => Socket::AF_INET) # p res - # [#2, :prefixlen=>8, :flags=>128, :scope=>254, + # [#2, :prefixlen=>8, :flags=>128, :scope=>254, # :index=>1, :address=>#, # :local=>#, :label=>"lo"}>, ...] 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 receive_until_done(RTM_NEWADDR, &blk) end