Class: Nl::Protocols::Genl

Inherits:
Raw
  • Object
show all
Defined in:
lib/nl/protocols/genl.rb

Overview

The Generic Netlink protocol

Defined Under Namespace

Classes: GenlMsgHdr, Message

Instance Attribute Summary

Attributes inherited from Raw

#name, #protonum

Instance Method Summary collapse

Methods inherited from Raw

#decode_message, #exchange_message, #recv_message, #send_message

Constructor Details

#initialize(name, family_id: nil) ⇒ Genl

Returns a new instance of Genl.



22
23
24
25
# File 'lib/nl/protocols/genl.rb', line 22

def initialize(name, family_id: nil)
  super(name, Core::NETLINK_GENERIC)
  @family_id = family_id || default_family_id(name)
end

Instance Method Details

#encode_message(encoder, message) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/nl/protocols/genl.rb', line 31

def encode_message(encoder, message)
  cmd = message.nlmsg_header.type
  encoder.measure(Endian::Host::U16) do
    message.nlmsg_header.type = family_id
    message.nlmsg_header.encode(encoder)
    message.nlmsg_header.type = cmd
    GenlMsgHdr.new(cmd, 1, 0).encode(encoder)
    message.fixed_header&.encode(encoder)
    message.attributes.encode(encoder)
  end
end

#family_idObject



27
28
29
# File 'lib/nl/protocols/genl.rb', line 27

def family_id
  @family_id or raise NotImplementedError, "Genetlink family ID for '#{name}' must be resolved via nlctrl"
end