Reorg to separate different NETLINK_ROUTE functions. Try adding vlan interfaces
This commit is contained in:
@@ -5,16 +5,17 @@ require 'netlink/route'
|
||||
|
||||
nl = Netlink::Route::Socket.new
|
||||
puts "\n*** Before adding address"
|
||||
nl.addrs["lo"][Socket::AF_INET].each { |x| puts x.address }
|
||||
nl.if.addrs["lo"][Socket::AF_INET].each { |x| puts x.address }
|
||||
|
||||
begin
|
||||
nl.add_addr(:index=>"lo", :local=>"1.2.3.4", :prefixlen=>32)
|
||||
rescue Errno::EEXIST
|
||||
end
|
||||
puts "\n*** After adding address"
|
||||
nl.addrs["lo"][Socket::AF_INET].each { |x| puts x.address }
|
||||
begin
|
||||
nl.if.add_addr(:index=>"lo", :local=>"1.2.3.4", :prefixlen=>32)
|
||||
rescue Errno::EEXIST
|
||||
puts "Already exists"
|
||||
end
|
||||
nl.if.addrs["lo"][Socket::AF_INET].each { |x| puts x.address }
|
||||
|
||||
nl.delete_addr(:index=>"lo", :local=>"1.2.3.4", :prefixlen=>32)
|
||||
puts "\n*** After deleting address"
|
||||
nl.addrs["lo"][Socket::AF_INET].each { |x| puts x.address }
|
||||
nl.if.delete_addr(:index=>"lo", :local=>"1.2.3.4", :prefixlen=>32)
|
||||
nl.if.addrs["lo"][Socket::AF_INET].each { |x| puts x.address }
|
||||
|
||||
|
30
examples/add_vlan.rb
Normal file
30
examples/add_vlan.rb
Normal file
@@ -0,0 +1,30 @@
|
||||
LIBDIR = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
|
||||
$LOAD_PATH.unshift LIBDIR
|
||||
|
||||
require 'netlink/route'
|
||||
require 'pp'
|
||||
|
||||
nl = Netlink::Route::Socket.new
|
||||
puts "\n*** Before adding VLAN"
|
||||
pp nl.if.select { |lnk| lnk.kind?("vlan") }
|
||||
|
||||
puts "\n*** After adding VLAN on lo"
|
||||
begin
|
||||
nl.if.add_link(:link=>"lo",
|
||||
:linkinfo=>Netlink::LinkInfo.new(
|
||||
:kind=>"vlan", :data=>Netlink::VlanInfo.new(
|
||||
:id=>1234, #:flags => Netlink::VlanFlags.new(:flags=>Netlink::VLAN_FLAG_LOOSE_BINDING, :mask=>0xffffffff)
|
||||
)))
|
||||
rescue Errno::EEXIST
|
||||
puts "Already present"
|
||||
end
|
||||
pp nl.if.select { |lnk| lnk.kind?("vlan") }
|
||||
|
||||
puts "\n*** After deleting VLANs from lo"
|
||||
nl.if.each do |lnk|
|
||||
if lnk.kind?('vlan') && nl.if.name(lnk.link) == 'lo'
|
||||
nl.if.delete_link(lnk.index)
|
||||
end
|
||||
end
|
||||
pp nl.if.select { |lnk| lnk.kind?("vlan") }
|
||||
|
@@ -9,8 +9,8 @@ require 'netlink/route'
|
||||
# and then manipulated internally.
|
||||
|
||||
nl = Netlink::Route::Socket.new
|
||||
pp nl.link["eth0"]
|
||||
pp nl.addrs["eth0"]
|
||||
pp nl.if["eth0"]
|
||||
pp nl.if.addrs["eth0"]
|
||||
|
||||
# Find the route with the shortest prefix len (probably default route)
|
||||
pp nl.routes[Socket::AF_INET].min_by { |route| route.dst_len }
|
||||
pp nl.rt[Socket::AF_INET].min_by { |route| route.dst_len }
|
||||
|
@@ -9,8 +9,8 @@ require 'netlink/route'
|
||||
|
||||
nl = Netlink::Route::Socket.new
|
||||
puts "*** links ***"
|
||||
pp nl.read_links
|
||||
pp nl.if.read_links
|
||||
puts "*** addrs ***"
|
||||
pp nl.read_addrs(:family => Socket::AF_INET)
|
||||
pp nl.if.read_addrs(:family => Socket::AF_INET)
|
||||
puts "*** routes ***"
|
||||
pp nl.read_routes(:family => Socket::AF_INET)
|
||||
pp nl.rt.read_routes(:family => Socket::AF_INET)
|
||||
|
Reference in New Issue
Block a user