Project

ynl

0.0
The project is in a healthy, maintained state
ynl parses YAML Netlink specifications (YNL) and generates Netlink clients for the interfaces they describe.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Runtime

>= 0
= 0.4.2
 Project Readme

Nl - Netlink libraries for Ruby

This repository is the home to three gems:

  • nl -- Core Netlink protocol library.
  • ynl -- YNL (YAML Netlink Specification) parser and code generator.
  • nl-linux -- Client definitions for Linux Netlink subsystems.

Synopsis

require 'nl/linux'
require 'ipaddr'

# List IP addresses by interface
Nl::Raw::Client.open(protonum: Nl::Raw::NETLINK_ROUTE) do |client|
  rtaddr = client.family(Nl::Linux::RtAddr)
  rtlink = client.family(Nl::Linux::RtLink)

  links = rtlink.dump_getlink.to_h { |link| [link.ifi_index, link] }

  rtaddr.dump_getaddr.group_by(&:ifa_index).each do |ifindex, addrs|
    ips = addrs.map { |addr| "#{IPAddr.new_ntoh(addr.address)}/#{addr.ifa_prefixlen}" }
    link = links.fetch(ifindex)

    puts "#{link.ifname}: #{ips.join(', ')}"
  end
end

# List interface speeds
Nl::Linux::Ethtool.open do |ethtool|
  ethtool.dump_linkmodes_get.each do |dev|
    puts "#{dev.header.dev_name}: #{dev.speed} Mbps"
  end
end

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/hanazuki/nl.

License

nl and ynl gems are available under The MIT License. nl-linux gem is dual-licensed under GPL-2.0 WITH Linux-syscall-note and The 3-Clause BSD License because it contains derived works of the Linux kernel's Netlink YAML definitions.

References