Class: Nl::Genl::Protocol

Inherits:
Raw::Protocol show all
Defined in:
nl/lib/nl/genl/protocol.rb

Overview

Socket-wide Generic Netlink wire behavior.

Instance Attribute Summary

Attributes inherited from Raw::Protocol

#protonum

Instance Method Summary collapse

Methods inherited from Raw::Protocol

#build_request, #decode_frame, #decode_notification, #send_message

Constructor Details

#initialize ⇒ Protocol

Returns a new instance of Protocol.



29
30
31
# File 'nl/lib/nl/genl/protocol.rb', line 29

def initialize
  super(Raw::NETLINK_GENERIC)
end

Instance Method Details

#encode_message(encoder, endpoint, request, seq:, pid:) ⇒ Object



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

def encode_message(encoder, endpoint, request, seq:, pid:)
  message = request.message
  header = Raw::NlMsgHdr.new(0, request.type, request.flags, seq, pid)
  encoder.measure(Endian::Host::U16) do
    header.encode(encoder)
    Nl::Genl::GenlMsgHdr.new(message.class::TYPE, endpoint.version, 0).encode(encoder)
    message.encode(encoder)
  end
end

#notification_channel_key(endpoint) ⇒ Object



43
# File 'nl/lib/nl/genl/protocol.rb', line 43

def notification_channel_key(endpoint) = endpoint.family_id

#notification_class(endpoint, header, payload, classes) ⇒ Object



51
52
53
54
55
56
# File 'nl/lib/nl/genl/protocol.rb', line 51

def notification_class(endpoint, header, payload, classes)
  return unless notification_frame?(endpoint, header, payload)

  command = Nl::Genl::GenlMsgHdr.decode(Decoder.new(payload)).cmd
  classes[command]
end

#notification_frame?(endpoint, header, _payload) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
# File 'nl/lib/nl/genl/protocol.rb', line 47

def notification_frame?(endpoint, header, _payload)
  header.type == endpoint.family_id
end

#notification_frame_key(header) ⇒ Object



45
# File 'nl/lib/nl/genl/protocol.rb', line 45

def notification_frame_key(header) = header.type

#notification_route_keys(endpoint, _classes) ⇒ Object



44
# File 'nl/lib/nl/genl/protocol.rb', line 44

def notification_route_keys(endpoint, _classes) = [endpoint.family_id]