diff --git a/debian/changelog b/debian/changelog index d906f16..b99a110 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +ruby-linux-netlink (0.16-1+wheezy1) stable; urgency=medium + + * New upstream release. + + -- Patrick J Cherry Tue, 26 Aug 2014 16:33:48 +0100 + ruby-linux-netlink (0.15-1+wheezy1) stable; urgency=low * New upstream release. diff --git a/lib/linux/constants.rb b/lib/linux/constants.rb index 8c28a54..7c432f6 100644 --- a/lib/linux/constants.rb +++ b/lib/linux/constants.rb @@ -310,24 +310,27 @@ module Linux VLAN_FLAG_MVRP = 0x8 # from linux/if_addr.h - IFA_UNSPEC = 0 - IFA_ADDRESS = 1 - IFA_LOCAL = 2 - IFA_LABEL = 3 - IFA_BROADCAST = 4 - IFA_ANYCAST = 5 - IFA_CACHEINFO = 6 - IFA_MULTICAST = 7 + IFA_UNSPEC = 0 + IFA_ADDRESS = 1 + IFA_LOCAL = 2 + IFA_LABEL = 3 + IFA_BROADCAST = 4 + IFA_ANYCAST = 5 + IFA_CACHEINFO = 6 + IFA_MULTICAST = 7 + IFA_FLAGS = 8 - IFA_F_SECONDARY = 0x01 - IFA_F_TEMPORARY = IFA_F_SECONDARY - IFA_F_NODAD = 0x02 - IFA_F_OPTIMISTIC = 0x04 - IFA_F_DADFAILED = 0x08 - IFA_F_HOMEADDRESS = 0x10 - IFA_F_DEPRECATED = 0x20 - IFA_F_TENTATIVE = 0x40 - IFA_F_PERMANENT = 0x80 + IFA_F_SECONDARY = 0x01 + IFA_F_TEMPORARY = IFA_F_SECONDARY + IFA_F_NODAD = 0x02 + IFA_F_OPTIMISTIC = 0x04 + IFA_F_DADFAILED = 0x08 + IFA_F_HOMEADDRESS = 0x10 + IFA_F_DEPRECATED = 0x20 + IFA_F_TENTATIVE = 0x40 + IFA_F_PERMANENT = 0x80 + IFA_F_MANAGETEMPADDR = 0x100 + IFA_F_NOPREFIXROUTE = 0x200 # from linux/if_arp.h - selected subset ARPHRD_NETROM = 0 diff --git a/lib/linux/netlink/message.rb b/lib/linux/netlink/message.rb index e2214b9..4bafb11 100644 --- a/lib/linux/netlink/message.rb +++ b/lib/linux/netlink/message.rb @@ -187,7 +187,7 @@ module Netlink warn "Duplicate attribute #{name} (#{code}): #{attrs[name].inspect} -> #{val.inspect}" if attrs[name] attrs[name] = val else - warn "Unknown attribute #{code}, in class #{self}, value #{val.inspect}" + warn "Unknown attribute #{code}, in class #{self}, value #{val.inspect}" if $DEBUG attrs[code] = val end end diff --git a/lib/linux/netlink/nlsocket.rb b/lib/linux/netlink/nlsocket.rb index 5f6ba45..8cdf9ea 100644 --- a/lib/linux/netlink/nlsocket.rb +++ b/lib/linux/netlink/nlsocket.rb @@ -58,14 +58,16 @@ module Netlink # :timeout => N (seconds, default to DEFAULT_TIMEOUT. Pass nil for no timeout) # :junk_handler => lambda { ... } for unexpected packets def initialize(opt) - @socket ||= opt[:socket] || ::Socket.new( + @socket = opt[:socket] || ::Socket.new( Socket::AF_NETLINK, Socket::SOCK_DGRAM, opt[:protocol] || (raise "Missing :protocol") ) @socket.bind(NLSocket.sockaddr(opt)) unless opt[:socket] @seq = opt[:seq] || Time.now.to_i - @pid = opt[:pid] || $$ + + @pid = @socket.getsockname.unpack(SOCKADDR_PACK)[2] + @timeout = opt.has_key?(:timeout) ? opt[:timeout] : DEFAULT_TIMEOUT if opt.has_key?(:junk_handler) @junk_handler = opt[:junk_handler] @@ -75,7 +77,7 @@ module Netlink } end end - + # Close the Netlink socket def close @socket.close @@ -85,7 +87,7 @@ module Netlink def next_seq @seq = (@seq + 1) & 0xffffffff end - + # Add a header and send a single message over the socket. # type:: the message type code # msg:: the message to send (without header) @@ -203,7 +205,7 @@ module Netlink end end end - + # Receive one datagram from kernel. Validates the sender, and returns # the raw binary message. Raises an exception on timeout or if the # kernel closes the socket. diff --git a/lib/linux/netlink/route/addr_handler.rb b/lib/linux/netlink/route/addr_handler.rb index 1e4c393..b3bb422 100644 --- a/lib/linux/netlink/route/addr_handler.rb +++ b/lib/linux/netlink/route/addr_handler.rb @@ -24,6 +24,10 @@ module Netlink :pack => lambda { |val,obj| val.to_a.pack("L*") }, :unpack => lambda { |str,obj| IFACacheInfo.new(*(str.unpack("L*"))) } rtattr :multicast, IFA_MULTICAST, :l3addr + + # TODO: is there any difference between flags and ifa_flags? The latter only + # shows up on newer kernels + rtattr :ifa_flags, IFA_FLAGS, :uint end module Route diff --git a/test/t_route.rb b/test/t_route.rb index 6212794..a9ab25c 100644 --- a/test/t_route.rb +++ b/test/t_route.rb @@ -1,10 +1,6 @@ -require File.join(File.dirname(__FILE__), 'test_helper') +require File.expand_path( File.join(File.dirname(__FILE__), 'test_helper') ) require 'linux/netlink/route' -# Note: multiple sockets bound to the same PID seem to cause timeout problems. -# (Should we use different algorithm for generating the PID? PID + seq?) -$ip ||= Linux::Netlink::Route::Socket.new - # # Ruby 1.8.7 appears to lack the KeyError constant. # @@ -15,7 +11,7 @@ end class TestAddr < Test::Unit::TestCase context "With netlink route socket" do setup do - @ip = $ip + @ip = Linux::Netlink::Route::Socket.new @ifname = nil end @@ -25,12 +21,25 @@ class TestAddr < Test::Unit::TestCase rescue KeyError, IndexError # Do nothing end + + @ip.close end test "Read link type" do assert_equal Linux::ARPHRD_LOOPBACK, @ip.link["lo"].type end + test "Both sockets work if two are open at the same time" do + begin + @ip2 = Linux::Netlink::Route::Socket.new + + assert_kind_of Enumerable, @ip.route.list + assert_kind_of Enumerable, @ip2.route.list + ensure + @ip2.close + end + end + def create_test_interface(ifname = "test_#{$$}") begin @ip.link.add(