Rename plural to singular; cleaner and more consistent with 'ip' utility
This commit is contained in:
@@ -3,19 +3,19 @@ $LOAD_PATH.unshift LIBDIR
|
||||
|
||||
require 'netlink/route'
|
||||
|
||||
nl = Netlink::Route::Socket.new
|
||||
ip = Netlink::Route::Socket.new
|
||||
puts "\n*** Before adding address"
|
||||
nl.addrs.list(:index=>"lo", :family=>Socket::AF_INET) { |x| puts x.address }
|
||||
ip.addr.list(:index=>"lo", :family=>Socket::AF_INET) { |x| puts x.address }
|
||||
|
||||
puts "\n*** After adding address"
|
||||
begin
|
||||
nl.addrs.add(:index=>"lo", :local=>"1.2.3.4", :prefixlen=>32)
|
||||
ip.addr.add(:index=>"lo", :local=>"1.2.3.4", :prefixlen=>32)
|
||||
rescue Errno::EEXIST
|
||||
puts "Already exists"
|
||||
end
|
||||
nl.addrs.list(:index=>"lo", :family=>Socket::AF_INET) { |x| puts x.address }
|
||||
ip.addr.list(:index=>"lo", :family=>Socket::AF_INET) { |x| puts x.address }
|
||||
|
||||
puts "\n*** After deleting address"
|
||||
nl.addrs.delete(:index=>"lo", :local=>"1.2.3.4", :prefixlen=>32)
|
||||
nl.addrs.list(:index=>"lo", :family=>Socket::AF_INET) { |x| puts x.address }
|
||||
ip.addr.delete(:index=>"lo", :local=>"1.2.3.4", :prefixlen=>32)
|
||||
ip.addr.list(:index=>"lo", :family=>Socket::AF_INET) { |x| puts x.address }
|
||||
|
||||
|
@@ -3,19 +3,19 @@ $LOAD_PATH.unshift LIBDIR
|
||||
|
||||
require 'netlink/route'
|
||||
|
||||
nl = Netlink::Route::Socket.new
|
||||
ip = Netlink::Route::Socket.new
|
||||
puts "\n*** Before adding route"
|
||||
nl.routes.list(:family=>Socket::AF_INET, :table=>Netlink::RT_TABLE_MAIN) { |x| p x }
|
||||
ip.route.list(:family=>Socket::AF_INET, :table=>Netlink::RT_TABLE_MAIN) { |x| p x }
|
||||
|
||||
puts "\n*** After adding route"
|
||||
begin
|
||||
nl.routes.add(:oif=>"lo", :dst=>"1.2.3.4", :dst_len=>32, :gateway=>"127.0.0.1")
|
||||
ip.route.add(:oif=>"lo", :dst=>"1.2.3.4", :dst_len=>32, :gateway=>"127.0.0.1")
|
||||
rescue Errno::EEXIST
|
||||
puts "Already exists"
|
||||
end
|
||||
nl.routes.list(:family=>Socket::AF_INET, :table=>Netlink::RT_TABLE_MAIN) { |x| p x }
|
||||
ip.route.list(:family=>Socket::AF_INET, :table=>Netlink::RT_TABLE_MAIN) { |x| p x }
|
||||
|
||||
puts "\n*** After deleting route"
|
||||
nl.routes.delete(:oif=>"lo", :dst=>"1.2.3.4", :dst_len=>32, :gateway=>"127.0.0.1")
|
||||
nl.routes.list(:family=>Socket::AF_INET, :table=>Netlink::RT_TABLE_MAIN) { |x| p x }
|
||||
ip.route.delete(:oif=>"lo", :dst=>"1.2.3.4", :dst_len=>32, :gateway=>"127.0.0.1")
|
||||
ip.route.list(:family=>Socket::AF_INET, :table=>Netlink::RT_TABLE_MAIN) { |x| p x }
|
||||
|
||||
|
@@ -4,18 +4,18 @@ $LOAD_PATH.unshift LIBDIR
|
||||
require 'netlink/route'
|
||||
require 'pp'
|
||||
|
||||
nl = Netlink::Route::Socket.new
|
||||
ip = Netlink::Route::Socket.new
|
||||
puts "\n*** Before adding VLAN"
|
||||
pp nl.vlans.list(:link=>"lo").to_a
|
||||
pp ip.vlan.list(:link=>"lo").to_a
|
||||
|
||||
puts "\n*** After adding VLAN on lo"
|
||||
begin
|
||||
nl.vlans.add(:link=>"lo", :vlan_id=>1234)
|
||||
ip.vlan.add(:link=>"lo", :vlan_id=>1234)
|
||||
rescue Errno::EEXIST
|
||||
puts "Already present"
|
||||
end
|
||||
pp nl.vlans.list(:link=>"lo").to_a
|
||||
pp ip.vlan.list(:link=>"lo").to_a
|
||||
|
||||
puts "\n*** After deleting VLANs from lo"
|
||||
nl.vlans.delete(:link=>"lo", :vlan_id=>1234)
|
||||
pp nl.vlans.list(:link=>"lo").to_a
|
||||
ip.vlan.delete(:link=>"lo", :vlan_id=>1234)
|
||||
pp ip.vlan.list(:link=>"lo").to_a
|
||||
|
@@ -8,20 +8,20 @@ require 'netlink/route'
|
||||
# The data is memoized - that is, it's downloaded from the kernel once
|
||||
# and then manipulated internally.
|
||||
|
||||
rt = Netlink::Route::Socket.new
|
||||
ip = Netlink::Route::Socket.new
|
||||
|
||||
puts "\nInterface eth0:"
|
||||
pp rt.links["eth0"]
|
||||
pp ip.link["eth0"]
|
||||
|
||||
puts "\nAddresses on interface eth0:"
|
||||
pp rt.addrs.list(:index=>"eth0").to_a
|
||||
pp ip.addr.list(:index=>"eth0").to_a
|
||||
|
||||
puts "\nAll routes in main routing table:"
|
||||
pp rt.routes.list(:table=>Netlink::RT_TABLE_MAIN).to_a
|
||||
pp ip.route.list(:table=>Netlink::RT_TABLE_MAIN).to_a
|
||||
|
||||
puts "\nV4 default route is probably:"
|
||||
pp rt.routes.list(:family=>Socket::AF_INET, :table=>Netlink::RT_TABLE_MAIN).
|
||||
pp ip.route.list(:family=>Socket::AF_INET, :table=>Netlink::RT_TABLE_MAIN).
|
||||
min_by { |route| route.dst_len }
|
||||
|
||||
puts "\nTraffic to 192.168.1.1 goes out via:"
|
||||
puts rt.ifname(rt.routes.get(:dst=>"192.168.1.1").oif)
|
||||
puts ip.ifname(ip.route.get(:dst=>"192.168.1.1").oif)
|
||||
|
@@ -7,10 +7,10 @@ require 'netlink/route'
|
||||
# Example of use of low-level API for NETLINK_ROUTE socket.
|
||||
# Each of these method calls performs a netlink protocol exchange.
|
||||
|
||||
rt = Netlink::Route::Socket.new
|
||||
ip = Netlink::Route::Socket.new
|
||||
puts "*** links ***"
|
||||
pp rt.links.read_links
|
||||
pp ip.link.read_link
|
||||
puts "*** addrs ***"
|
||||
pp rt.addrs.read_addrs
|
||||
pp ip.addr.read_addr
|
||||
puts "*** routes ***"
|
||||
pp rt.routes.read_routes
|
||||
pp ip.route.read_route
|
||||
|
Reference in New Issue
Block a user