nl 0.4.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +26 -0
- data/lib/nl/async/dispatcher.rb +2 -2
- data/lib/nl/attribute_set.rb +19 -153
- data/lib/nl/attributes.rb +193 -0
- data/lib/nl/blocking_transport.rb +5 -5
- data/lib/nl/datagram.rb +4 -4
- data/lib/nl/datatypes/checked.rb +66 -0
- data/lib/nl/datatypes/defaults.rb +13 -0
- data/lib/nl/datatypes/scalar.rb +28 -0
- data/lib/nl/datatypes.rb +97 -125
- data/lib/nl/decoder.rb +79 -25
- data/lib/nl/encoder.rb +4 -6
- data/lib/nl/endian.rb +5 -3
- data/lib/nl/exchange.rb +18 -17
- data/lib/nl/genl/protocol.rb +16 -3
- data/lib/nl/genl/wire.rb +9 -3
- data/lib/nl/genl.rb +0 -18
- data/lib/nl/message.rb +21 -0
- data/lib/nl/notification_router.rb +2 -5
- data/lib/nl/raw/protocol.rb +27 -21
- data/lib/nl/raw/wire.rb +20 -50
- data/lib/nl/raw.rb +1 -51
- data/lib/nl/{sub_message.rb → selector.rb} +13 -23
- data/lib/nl/version.rb +1 -1
- data/lib/nl.rb +2 -2
- data/sig/generated/nl/attribute_set.rbs +21 -29
- data/sig/generated/nl/attributes.rbs +51 -0
- data/sig/generated/nl/datagram.rbs +4 -4
- data/sig/generated/nl/datatypes/checked.rbs +31 -0
- data/sig/generated/nl/datatypes/defaults.rbs +11 -0
- data/sig/generated/nl/datatypes/scalar.rbs +11 -0
- data/sig/generated/nl/datatypes.rbs +38 -34
- data/sig/generated/nl/decoder.rbs +12 -4
- data/sig/generated/nl/encoder.rbs +1 -1
- data/sig/generated/nl/exchange.rbs +2 -2
- data/sig/generated/nl/genl/protocol.rbs +3 -1
- data/sig/generated/nl/genl.rbs +0 -15
- data/sig/generated/nl/message.rbs +14 -0
- data/sig/generated/nl/raw/protocol.rbs +29 -43
- data/sig/generated/nl/raw/wire.rbs +0 -36
- data/sig/generated/nl/raw.rbs +0 -35
- data/sig/generated/nl/{sub_message.rbs → selector.rbs} +8 -19
- metadata +14 -6
- data/lib/nl/structured_payload.rb +0 -61
- data/sig/generated/nl/structured_payload.rbs +0 -25
data/lib/nl/exchange.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
require_relative 'error'
|
|
2
2
|
require_relative 'raw/protocol'
|
|
3
|
+
require_relative 'message'
|
|
3
4
|
|
|
4
5
|
module Nl
|
|
5
6
|
# State machine for one Netlink request/reply exchange.
|
|
@@ -46,27 +47,27 @@ module Nl
|
|
|
46
47
|
@mutex = Mutex.new
|
|
47
48
|
end
|
|
48
49
|
|
|
49
|
-
def accept(
|
|
50
|
+
def accept(header, message)
|
|
50
51
|
@mutex.synchronize do
|
|
51
52
|
return if @complete
|
|
52
53
|
|
|
53
|
-
case
|
|
54
|
-
when Raw::
|
|
54
|
+
case message
|
|
55
|
+
when Raw::Unknown
|
|
55
56
|
nil
|
|
56
|
-
when Raw::
|
|
57
|
-
@cancelled ? complete(nil) : fail_with(SystemCallError.new(
|
|
58
|
-
when Raw::
|
|
59
|
-
if
|
|
60
|
-
fail_with(SystemCallError.new(
|
|
57
|
+
when Raw::Error
|
|
58
|
+
@cancelled ? complete(nil) : fail_with(SystemCallError.new(message.errno))
|
|
59
|
+
when Raw::Done
|
|
60
|
+
if message.errno && !@cancelled
|
|
61
|
+
fail_with(SystemCallError.new(message.errno))
|
|
61
62
|
else
|
|
62
63
|
complete(@reply)
|
|
63
64
|
end
|
|
64
|
-
when Raw::
|
|
65
|
+
when Raw::Ack
|
|
65
66
|
accept_ack
|
|
66
|
-
when
|
|
67
|
-
accept_reply(
|
|
67
|
+
when Message
|
|
68
|
+
accept_reply(header, message)
|
|
68
69
|
else
|
|
69
|
-
raise ArgumentError, "unexpected exchange input: #{
|
|
70
|
+
raise ArgumentError, "unexpected exchange input: #{message.inspect}"
|
|
70
71
|
end
|
|
71
72
|
end
|
|
72
73
|
end
|
|
@@ -87,13 +88,13 @@ module Nl
|
|
|
87
88
|
end
|
|
88
89
|
end
|
|
89
90
|
|
|
90
|
-
private def accept_reply(
|
|
91
|
+
private def accept_reply(header, message)
|
|
91
92
|
return if @cancelled
|
|
92
93
|
|
|
93
|
-
multipart = (
|
|
94
|
+
multipart = (header.flags.to_i & Raw::NLM_F_MULTI) != 0
|
|
94
95
|
case @state
|
|
95
96
|
when :dump
|
|
96
|
-
return Item.new(
|
|
97
|
+
return Item.new(message)
|
|
97
98
|
when :no_reply
|
|
98
99
|
return fail_with(ProtocolViolation.new('unexpected data message in a no-reply Netlink response'))
|
|
99
100
|
when :initial
|
|
@@ -106,8 +107,8 @@ module Nl
|
|
|
106
107
|
end
|
|
107
108
|
end
|
|
108
109
|
|
|
109
|
-
@reply ||=
|
|
110
|
-
complete(
|
|
110
|
+
@reply ||= message
|
|
111
|
+
complete(message) if @acked && @state == :single
|
|
111
112
|
end
|
|
112
113
|
|
|
113
114
|
private def complete(value)
|
data/lib/nl/genl/protocol.rb
CHANGED
|
@@ -30,6 +30,19 @@ module Nl
|
|
|
30
30
|
super(Raw::NETLINK_GENERIC)
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
+
private def decode_message(endpoint, header, decoder, message_class)
|
|
34
|
+
unless header.type == endpoint.family_id
|
|
35
|
+
raise ProtocolViolation, "Expected family ID #{endpoint.family_id}, got #{header.type}"
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
command = GenlMsgHdr.decode(decoder).cmd
|
|
39
|
+
unless message_class::TYPE == command
|
|
40
|
+
raise ProtocolViolation, "Expected command #{message_class::TYPE}, got #{command}"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
message_class.decode(decoder)
|
|
44
|
+
end
|
|
45
|
+
|
|
33
46
|
def encode_message(encoder, endpoint, request, seq:, pid:)
|
|
34
47
|
message = request.message
|
|
35
48
|
header = Raw::NlMsgHdr.new(0, request.type, request.flags, seq, pid)
|
|
@@ -48,11 +61,11 @@ module Nl
|
|
|
48
61
|
header.type == endpoint.family_id
|
|
49
62
|
end
|
|
50
63
|
|
|
51
|
-
def
|
|
64
|
+
def decode_notification(endpoint, header, payload, classes)
|
|
52
65
|
return unless notification_frame?(endpoint, header, payload)
|
|
53
66
|
|
|
54
|
-
command =
|
|
55
|
-
classes[command]
|
|
67
|
+
command = GenlMsgHdr.decode(payload).cmd
|
|
68
|
+
classes[command]&.decode(payload)
|
|
56
69
|
end
|
|
57
70
|
end
|
|
58
71
|
end
|
data/lib/nl/genl/wire.rb
CHANGED
|
@@ -66,11 +66,12 @@ module Nl
|
|
|
66
66
|
)
|
|
67
67
|
|
|
68
68
|
class GenlMsgHdr
|
|
69
|
-
FORMAT =
|
|
69
|
+
FORMAT = [
|
|
70
70
|
Endian::Host::U8,
|
|
71
71
|
Endian::Host::U8,
|
|
72
72
|
Endian::Host::U16,
|
|
73
|
-
]
|
|
73
|
+
].freeze
|
|
74
|
+
Ractor.make_shareable(FORMAT) if defined?(Ractor)
|
|
74
75
|
private_constant :FORMAT
|
|
75
76
|
|
|
76
77
|
# Decodes a header from the decoder's current position.
|
|
@@ -79,7 +80,12 @@ module Nl
|
|
|
79
80
|
# @return [GenlMsgHdr] the decoded header
|
|
80
81
|
# @rbs (Decoder decoder) -> instance
|
|
81
82
|
def self.decode(decoder)
|
|
82
|
-
|
|
83
|
+
# Unrolling get_values improves performance for this small header.
|
|
84
|
+
new(
|
|
85
|
+
decoder.get_U8,
|
|
86
|
+
decoder.get_U8,
|
|
87
|
+
decoder.get_host_u16,
|
|
88
|
+
)
|
|
83
89
|
end
|
|
84
90
|
|
|
85
91
|
# Encodes this header at the encoder's current position.
|
data/lib/nl/genl.rb
CHANGED
|
@@ -48,24 +48,6 @@ module Nl
|
|
|
48
48
|
end
|
|
49
49
|
end
|
|
50
50
|
end
|
|
51
|
-
|
|
52
|
-
# Base class for Generic Netlink messages.
|
|
53
|
-
#
|
|
54
|
-
# A Generic Netlink message payload begins with a {GenlMsgHdr}, followed by
|
|
55
|
-
# the optional fixed header and attributes handled by {Raw::Message}.
|
|
56
|
-
class Message < Raw::Message
|
|
57
|
-
# Decodes a Generic Netlink message payload.
|
|
58
|
-
#
|
|
59
|
-
# @param [Decoder] decoder the source decoder
|
|
60
|
-
# @param [Integer] type the family ID from the Netlink message header
|
|
61
|
-
# @return [Message] the decoded message
|
|
62
|
-
# @raise [RuntimeError] if the command does not match the message class's type
|
|
63
|
-
# @rbs (Decoder decoder, type: Integer) -> instance
|
|
64
|
-
def self.decode(decoder, type:)
|
|
65
|
-
genlhdr = GenlMsgHdr.decode(decoder)
|
|
66
|
-
super(decoder, type: genlhdr.cmd)
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
51
|
end
|
|
70
52
|
end
|
|
71
53
|
|
data/lib/nl/message.rb
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require_relative 'attribute_set'
|
|
2
|
+
|
|
3
|
+
module Nl
|
|
4
|
+
# Family payload with fixed-header fields and attribute values stored inline.
|
|
5
|
+
class Message
|
|
6
|
+
include Attributes
|
|
7
|
+
|
|
8
|
+
EMPTY_FIELD_NAMES = [].freeze
|
|
9
|
+
|
|
10
|
+
class << self
|
|
11
|
+
def from_params(params = {})
|
|
12
|
+
build_instance(params)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
private def validate_params(params, header_names, attribute_names)
|
|
16
|
+
unknown = params.keys - header_names - attribute_names
|
|
17
|
+
raise ArgumentError, "unknown parameters: #{unknown.join(', ')}" unless unknown.empty?
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -58,11 +58,8 @@ module Nl
|
|
|
58
58
|
return false unless entry
|
|
59
59
|
return false unless @protocol.notification_frame?(entry.endpoint, header, payload)
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
notification = @protocol.decode_notification(entry.endpoint, header, payload, message_class)
|
|
65
|
-
entry.channel.push(notification)
|
|
61
|
+
notification = @protocol.decode_notification(entry.endpoint, header, payload, entry.classes)
|
|
62
|
+
entry.channel.push(notification) if notification
|
|
66
63
|
true
|
|
67
64
|
rescue => error
|
|
68
65
|
entry&.channel&.fail(error)
|
data/lib/nl/raw/protocol.rb
CHANGED
|
@@ -6,11 +6,13 @@ require_relative '../socket'
|
|
|
6
6
|
|
|
7
7
|
module Nl
|
|
8
8
|
module Raw
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
Ack = Data.define
|
|
10
|
+
Error = Data.define(:errno)
|
|
11
|
+
Done = Data.define(:errno)
|
|
12
|
+
Unknown = Data.define
|
|
13
|
+
ACK = Ack.new
|
|
14
|
+
DONE = Done.new(nil)
|
|
15
|
+
UNKNOWN = Unknown.new
|
|
14
16
|
Request = Data.define(:type, :flags, :message)
|
|
15
17
|
|
|
16
18
|
# A generated raw Netlink family bound to its fixed wire identity.
|
|
@@ -46,37 +48,45 @@ module Nl
|
|
|
46
48
|
end
|
|
47
49
|
end
|
|
48
50
|
|
|
49
|
-
#
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
# Returns a decoded reply or control result for one Netlink frame.
|
|
52
|
+
# @rbs (Endpoint endpoint, NlMsgHdr header, Decoder decoder, Class? message_class) -> (Message | Ack | Done | Error | Unknown)
|
|
53
|
+
def decode_frame(endpoint, header, decoder, message_class)
|
|
52
54
|
if header.type < Raw::NLMSG_MIN_TYPE
|
|
53
55
|
case header.type
|
|
54
56
|
when Raw::NLMSG_ERROR
|
|
55
|
-
errno = decoder.
|
|
57
|
+
errno = decoder.get_host_sint
|
|
56
58
|
if errno.positive?
|
|
57
59
|
raise ProtocolViolation, "expected zero or negative NLMSG_ERROR errno, got #{errno}"
|
|
58
60
|
end
|
|
59
61
|
|
|
60
|
-
errno
|
|
62
|
+
errno == 0 ? ACK : Error.new(-errno)
|
|
61
63
|
when Raw::NLMSG_DONE
|
|
62
|
-
return
|
|
64
|
+
return DONE unless decoder.available?
|
|
63
65
|
|
|
64
|
-
errno = decoder.
|
|
66
|
+
errno = decoder.get_host_sint
|
|
65
67
|
if errno.positive?
|
|
66
68
|
raise ProtocolViolation, "expected zero or negative NLMSG_DONE errno, got #{errno}"
|
|
67
69
|
end
|
|
68
70
|
|
|
69
|
-
|
|
71
|
+
errno < 0 ? Done.new(-errno) : DONE
|
|
70
72
|
else
|
|
71
|
-
|
|
73
|
+
UNKNOWN
|
|
72
74
|
end
|
|
73
75
|
else
|
|
74
76
|
raise ArgumentError, 'reply class is required for a data message' unless message_class
|
|
75
77
|
|
|
76
|
-
|
|
78
|
+
decode_message(endpoint, header, decoder, message_class)
|
|
77
79
|
end
|
|
78
80
|
end
|
|
79
81
|
|
|
82
|
+
private def decode_message(_endpoint, header, decoder, message_class)
|
|
83
|
+
unless message_class::TYPE == header.type
|
|
84
|
+
raise ProtocolViolation, "Expected message type #{message_class::TYPE}, got #{header.type}"
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
message_class.decode(decoder)
|
|
88
|
+
end
|
|
89
|
+
|
|
80
90
|
def send_message(socket, endpoint, request, seq:, pid:)
|
|
81
91
|
encoder = Encoder.new
|
|
82
92
|
encode_message(encoder, endpoint, request, seq:, pid:)
|
|
@@ -100,12 +110,8 @@ module Nl
|
|
|
100
110
|
header.type >= Raw::NLMSG_MIN_TYPE
|
|
101
111
|
end
|
|
102
112
|
|
|
103
|
-
def
|
|
104
|
-
classes[header.type]
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
def decode_notification(endpoint, header, payload, message_class)
|
|
108
|
-
decode_frame(endpoint, header, payload, message_class).message
|
|
113
|
+
def decode_notification(_endpoint, header, payload, classes)
|
|
114
|
+
classes[header.type]&.decode(payload)
|
|
109
115
|
end
|
|
110
116
|
end
|
|
111
117
|
end
|
data/lib/nl/raw/wire.rb
CHANGED
|
@@ -68,13 +68,14 @@ module Nl
|
|
|
68
68
|
)
|
|
69
69
|
|
|
70
70
|
class NlMsgHdr
|
|
71
|
-
FORMAT =
|
|
71
|
+
FORMAT = [
|
|
72
72
|
Endian::Host::U32,
|
|
73
73
|
Endian::Host::U16,
|
|
74
74
|
Endian::Host::U16,
|
|
75
75
|
Endian::Host::U32,
|
|
76
76
|
Endian::Host::U32,
|
|
77
|
-
]
|
|
77
|
+
].freeze
|
|
78
|
+
Ractor.make_shareable(FORMAT) if defined?(Ractor)
|
|
78
79
|
private_constant :FORMAT
|
|
79
80
|
|
|
80
81
|
# Decodes a header from the decoder's current position.
|
|
@@ -83,9 +84,23 @@ module Nl
|
|
|
83
84
|
# @return [NlMsgHdr] the decoded header
|
|
84
85
|
# @rbs (Decoder decoder) -> instance
|
|
85
86
|
def self.decode(decoder)
|
|
86
|
-
|
|
87
|
-
decoder.
|
|
88
|
-
|
|
87
|
+
len = decoder.get_host_u32
|
|
88
|
+
type_flags = decoder.get_host_u32
|
|
89
|
+
if IO::Buffer::HOST_ENDIAN == IO::Buffer::LITTLE_ENDIAN
|
|
90
|
+
type = type_flags & 0xffff
|
|
91
|
+
flags = type_flags >> 16
|
|
92
|
+
else
|
|
93
|
+
type = type_flags >> 16
|
|
94
|
+
flags = type_flags & 0xffff
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
new(
|
|
98
|
+
len,
|
|
99
|
+
type,
|
|
100
|
+
flags,
|
|
101
|
+
decoder.get_host_u32,
|
|
102
|
+
decoder.get_host_u32,
|
|
103
|
+
)
|
|
89
104
|
end
|
|
90
105
|
|
|
91
106
|
# Encodes this header at the encoder's current position.
|
|
@@ -96,51 +111,6 @@ module Nl
|
|
|
96
111
|
def encode(encoder)
|
|
97
112
|
encoder.reserve(Constants::NLMSG_HDRLEN)
|
|
98
113
|
encoder.put_values(FORMAT, to_a)
|
|
99
|
-
encoder.align_to(Constants::NLMSG_ALIGNTO)
|
|
100
|
-
end
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
# Fixed-format header prepended to every Netlink attribute.
|
|
104
|
-
#
|
|
105
|
-
# This corresponds to Linux's +struct nlattr+.
|
|
106
|
-
#
|
|
107
|
-
# @!attribute [rw] len
|
|
108
|
-
# @return [Integer] attribute length in bytes, including this header but
|
|
109
|
-
# excluding trailing alignment padding
|
|
110
|
-
# @!attribute [rw] type
|
|
111
|
-
# @return [Integer] attribute type combined with optional +NLA_F_+ flags
|
|
112
|
-
NlAttr = Struct.new(
|
|
113
|
-
:len, #: Integer
|
|
114
|
-
:type, #: Integer
|
|
115
|
-
)
|
|
116
|
-
|
|
117
|
-
class NlAttr
|
|
118
|
-
FORMAT = Ractor.make_shareable([
|
|
119
|
-
Endian::Host::U16,
|
|
120
|
-
Endian::Host::U16,
|
|
121
|
-
])
|
|
122
|
-
private_constant :FORMAT
|
|
123
|
-
|
|
124
|
-
# Decodes an attribute header from the decoder's current position.
|
|
125
|
-
#
|
|
126
|
-
# @param [Decoder] decoder the source decoder
|
|
127
|
-
# @return [NlAttr] the decoded header
|
|
128
|
-
# @rbs (Decoder decoder) -> instance
|
|
129
|
-
def self.decode(decoder)
|
|
130
|
-
obj = new(*decoder.get_values(FORMAT))
|
|
131
|
-
decoder.align_to(Constants::NLA_ALIGNTO)
|
|
132
|
-
obj
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
# Encodes this attribute header at the encoder's current position.
|
|
136
|
-
#
|
|
137
|
-
# @param [Encoder] encoder the destination encoder
|
|
138
|
-
# @return [void]
|
|
139
|
-
# @rbs (Encoder encoder) -> void
|
|
140
|
-
def encode(encoder)
|
|
141
|
-
encoder.reserve(Constants::NLA_HDRLEN)
|
|
142
|
-
encoder.put_values(FORMAT, to_a)
|
|
143
|
-
encoder.align_to(Constants::NLA_ALIGNTO)
|
|
144
114
|
end
|
|
145
115
|
end
|
|
146
116
|
end
|
data/lib/nl/raw.rb
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
require_relative 'family'
|
|
2
2
|
require_relative 'raw/protocol'
|
|
3
3
|
require_relative 'raw/client'
|
|
4
|
-
require_relative '
|
|
5
|
-
require_relative 'structured_payload'
|
|
4
|
+
require_relative 'message'
|
|
6
5
|
|
|
7
6
|
module Nl
|
|
8
7
|
# Classic (Raw) Netlink families.
|
|
@@ -51,54 +50,5 @@ module Nl
|
|
|
51
50
|
end
|
|
52
51
|
end
|
|
53
52
|
end
|
|
54
|
-
|
|
55
|
-
# Base class for raw Netlink messages.
|
|
56
|
-
#
|
|
57
|
-
# A message may contain a fixed header followed by a set of Netlink
|
|
58
|
-
# attributes.
|
|
59
|
-
class Message
|
|
60
|
-
include Nl::StructuredPayload
|
|
61
|
-
|
|
62
|
-
# @param [Object, nil] fixed_header the family-specific fixed header
|
|
63
|
-
# @param [AttributeSet, nil] attributes the message's attributes
|
|
64
|
-
# @rbs (?untyped fixed_header, ?AttributeSet? attributes) -> void
|
|
65
|
-
def initialize(fixed_header = nil, attributes = self.class::ATTRIBUTE_SET.new)
|
|
66
|
-
super
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
# Appends an attribute to the message.
|
|
70
|
-
#
|
|
71
|
-
# @param [AttributeSet::Attribute] attribute the attribute to append
|
|
72
|
-
# @return [void]
|
|
73
|
-
# @rbs (AttributeSet::Attribute attribute) -> void
|
|
74
|
-
def append_attribute(attribute)
|
|
75
|
-
@attributes << attribute
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
# Decodes a raw Netlink message payload.
|
|
79
|
-
#
|
|
80
|
-
# @param [Decoder] decoder the source decoder
|
|
81
|
-
# @param [Integer] type the message type from its Netlink header
|
|
82
|
-
# @return [Message] the decoded message
|
|
83
|
-
# @raise [RuntimeError] if +type+ does not match the message class's type
|
|
84
|
-
# @rbs (Decoder decoder, type: Integer) -> instance
|
|
85
|
-
def self.decode(decoder, type:)
|
|
86
|
-
unless self::TYPE == type
|
|
87
|
-
raise "Expected message type #{self::TYPE}, got #{type}"
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
super(decoder)
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
class << self
|
|
94
|
-
# Returns the attribute names accepted by this message.
|
|
95
|
-
#
|
|
96
|
-
# @return [Array<Symbol>] the attribute names
|
|
97
|
-
# @rbs () -> Array[Symbol]
|
|
98
|
-
private def attribute_names
|
|
99
|
-
self::ATTRIBUTES
|
|
100
|
-
end
|
|
101
|
-
end
|
|
102
|
-
end
|
|
103
53
|
end
|
|
104
54
|
end
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
require_relative 'structured_payload'
|
|
2
|
-
|
|
3
1
|
module Nl
|
|
4
2
|
module Selector
|
|
3
|
+
EMPTY_VALUES = [].freeze
|
|
4
|
+
Ractor.make_shareable(EMPTY_VALUES) if defined?(Ractor)
|
|
5
|
+
|
|
5
6
|
class MissingSelectorValueError < StandardError
|
|
6
7
|
attr_reader :scope, :index
|
|
7
8
|
|
|
@@ -48,8 +49,14 @@ module Nl
|
|
|
48
49
|
end
|
|
49
50
|
|
|
50
51
|
class State
|
|
51
|
-
def
|
|
52
|
-
|
|
52
|
+
def self.for(local_selector_count, external)
|
|
53
|
+
return EMPTY if local_selector_count == 0 && external.empty?
|
|
54
|
+
|
|
55
|
+
new(local_selector_count, external)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def initialize(local_selector_count, external)
|
|
59
|
+
@local = Array.new(local_selector_count)
|
|
53
60
|
@external = external
|
|
54
61
|
end
|
|
55
62
|
|
|
@@ -69,26 +76,9 @@ module Nl
|
|
|
69
76
|
value = values[key]
|
|
70
77
|
value.nil? ? yield : value
|
|
71
78
|
end
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
# A selector-specific payload containing an optional fixed header followed by
|
|
76
|
-
# an optional set of Netlink attributes.
|
|
77
|
-
class SubMessage
|
|
78
|
-
include StructuredPayload
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
# An unrecognized selector-specific payload retained without interpretation.
|
|
82
|
-
class RawSubMessage < SubMessage
|
|
83
|
-
attr_reader :payload, :nlattr_type_flags
|
|
84
|
-
|
|
85
|
-
def initialize(payload, nlattr_type_flags:)
|
|
86
|
-
@payload = payload
|
|
87
|
-
@nlattr_type_flags = nlattr_type_flags
|
|
88
|
-
end
|
|
89
79
|
|
|
90
|
-
|
|
91
|
-
|
|
80
|
+
EMPTY = new(0, EMPTY_VALUES).freeze
|
|
81
|
+
Ractor.make_shareable(EMPTY) if defined?(Ractor)
|
|
92
82
|
end
|
|
93
83
|
end
|
|
94
84
|
end
|
data/lib/nl/version.rb
CHANGED
data/lib/nl.rb
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
require_relative 'nl/error'
|
|
2
2
|
require_relative 'nl/bitfield32'
|
|
3
3
|
require_relative 'nl/raw/wire'
|
|
4
|
-
require_relative 'nl/
|
|
5
|
-
require_relative 'nl/sub_message'
|
|
4
|
+
require_relative 'nl/selector'
|
|
6
5
|
require_relative 'nl/notification'
|
|
7
6
|
require_relative 'nl/connection'
|
|
8
7
|
require_relative 'nl/family'
|
|
8
|
+
require_relative 'nl/message'
|
|
9
9
|
require_relative 'nl/raw'
|
|
10
10
|
require_relative 'nl/genl'
|
|
11
11
|
require_relative 'nl/socket'
|
|
@@ -1,50 +1,42 @@
|
|
|
1
1
|
# Generated from lib/nl/attribute_set.rb with RBS::Inline
|
|
2
2
|
|
|
3
3
|
module Nl
|
|
4
|
+
# A standalone nested attribute set. Messages share the same operations
|
|
5
|
+
# without allocating this wrapper.
|
|
4
6
|
class AttributeSet
|
|
5
|
-
|
|
6
|
-
attr_accessor value(): untyped
|
|
7
|
+
include Attributes
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
class Attribute
|
|
13
|
-
MULTI: bool
|
|
9
|
+
class Definition < Data
|
|
10
|
+
attr_reader id(): untyped
|
|
14
11
|
|
|
15
|
-
|
|
12
|
+
attr_reader name(): untyped
|
|
16
13
|
|
|
17
|
-
|
|
14
|
+
attr_reader datatype(): untyped
|
|
18
15
|
|
|
19
|
-
|
|
16
|
+
attr_reader multi(): untyped
|
|
20
17
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
def encode: (untyped encoder, ?context: untyped) -> untyped
|
|
24
|
-
end
|
|
18
|
+
attr_reader order(): untyped
|
|
25
19
|
|
|
26
|
-
|
|
20
|
+
attr_reader selector_slot(): untyped
|
|
27
21
|
|
|
28
|
-
|
|
22
|
+
def self.new: (untyped id, untyped name, untyped datatype, untyped multi, untyped order, untyped selector_slot) -> instance
|
|
23
|
+
| (id: untyped, name: untyped, datatype: untyped, multi: untyped, order: untyped, selector_slot: untyped) -> instance
|
|
29
24
|
|
|
30
|
-
|
|
25
|
+
def self.members: () -> [ :id, :name, :datatype, :multi, :order, :selector_slot ]
|
|
31
26
|
|
|
32
|
-
|
|
27
|
+
def members: () -> [ :id, :name, :datatype, :multi, :order, :selector_slot ]
|
|
28
|
+
end
|
|
33
29
|
|
|
34
|
-
|
|
30
|
+
def initialize: (?untyped attributes) -> untyped
|
|
35
31
|
|
|
36
32
|
def encode: (untyped encoder, ?external_selectors: untyped) -> untyped
|
|
37
33
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
def self.decode: (untyped decoder, ?external_selectors: untyped) -> untyped
|
|
43
|
-
|
|
44
|
-
def self.build_attributes: (?untyped params, ?external_selectors: untyped, **untyped keywords) -> untyped
|
|
34
|
+
# Builds an attribute set from attribute names and values.
|
|
35
|
+
# @rbs (?Hash[Symbol, untyped] params) -> instance
|
|
36
|
+
def self.from_params: (?Hash[Symbol, untyped] params) -> instance
|
|
45
37
|
|
|
46
|
-
|
|
38
|
+
def self.decode: (untyped decoder, untyped definitions, untyped local_selector_count, untyped external_selectors) -> untyped
|
|
47
39
|
|
|
48
|
-
|
|
40
|
+
def self.build_instance: (untyped params, ?external_selectors: untyped) -> untyped
|
|
49
41
|
end
|
|
50
42
|
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Generated from lib/nl/attributes.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Nl
|
|
4
|
+
# An opaque attribute payload with the flags needed to re-encode it.
|
|
5
|
+
class RawAttributeValue
|
|
6
|
+
attr_reader payload: untyped
|
|
7
|
+
|
|
8
|
+
attr_reader nlattr_type_flags: untyped
|
|
9
|
+
|
|
10
|
+
def initialize: (untyped payload, nlattr_type_flags: untyped) -> untyped
|
|
11
|
+
|
|
12
|
+
def encode: (untyped encoder, ?external_selectors: untyped) -> untyped
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Ordered attribute operations shared by nested sets and generated payloads.
|
|
16
|
+
module Attributes
|
|
17
|
+
def self.included: (untyped base) -> untyped
|
|
18
|
+
|
|
19
|
+
def []: (untyped type) -> untyped
|
|
20
|
+
|
|
21
|
+
def append_attribute: (untyped type, untyped value) -> untyped
|
|
22
|
+
|
|
23
|
+
LOCAL_SELECTOR_NAMES: untyped
|
|
24
|
+
|
|
25
|
+
EXTERNAL_SELECTOR_NAMES: untyped
|
|
26
|
+
|
|
27
|
+
private def definition_for: (untyped type) -> untyped
|
|
28
|
+
|
|
29
|
+
private def encode1: (untyped encoder, untyped definition, untyped value, untyped context) -> untyped
|
|
30
|
+
|
|
31
|
+
private def encode_attributes: (untyped encoder, ?external_selectors: untyped) -> untyped
|
|
32
|
+
|
|
33
|
+
private def selector_name: (untyped error) -> untyped
|
|
34
|
+
|
|
35
|
+
module ClassMethods
|
|
36
|
+
def by_name: (untyped name) -> untyped
|
|
37
|
+
|
|
38
|
+
def by_type: (untyped type) -> untyped
|
|
39
|
+
|
|
40
|
+
private def decode1: (untyped decoder, untyped context, untyped attributes, untyped definitions) -> untyped
|
|
41
|
+
|
|
42
|
+
private def decode_attributes: (untyped decoder, untyped definitions, untyped local_selector_count, ?external_selectors: untyped) -> untyped
|
|
43
|
+
|
|
44
|
+
private def build_attributes: (untyped params, ?external_selectors: untyped) -> untyped
|
|
45
|
+
|
|
46
|
+
private def coerce: (untyped datatype, untyped value, untyped context) -> untyped
|
|
47
|
+
|
|
48
|
+
private def selector_name: (untyped error) -> untyped
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
module Nl
|
|
4
4
|
# Splits Netlink datagrams into aligned header/payload frames.
|
|
5
5
|
module Datagram
|
|
6
|
-
# @rbs (IO::Buffer buffer) { (Raw::NlMsgHdr,
|
|
7
|
-
# | (IO::Buffer buffer) -> Enumerator[[Raw::NlMsgHdr,
|
|
8
|
-
def self.each_frame: (IO::Buffer buffer) { (Raw::NlMsgHdr,
|
|
9
|
-
| (IO::Buffer buffer) -> Enumerator[[ Raw::NlMsgHdr,
|
|
6
|
+
# @rbs (IO::Buffer buffer) { (Raw::NlMsgHdr, Decoder) -> void } -> nil
|
|
7
|
+
# | (IO::Buffer buffer) -> Enumerator[[Raw::NlMsgHdr, Decoder], nil]
|
|
8
|
+
def self.each_frame: (IO::Buffer buffer) { (Raw::NlMsgHdr, Decoder) -> void } -> nil
|
|
9
|
+
| (IO::Buffer buffer) -> Enumerator[[ Raw::NlMsgHdr, Decoder ], nil]
|
|
10
10
|
end
|
|
11
11
|
end
|