nl 0.3.0 → 0.4.1
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 +13 -0
- data/Rakefile +7 -0
- data/lib/nl/async/dispatcher.rb +16 -16
- data/lib/nl/async/driver.rb +0 -2
- data/lib/nl/async/mailbox.rb +0 -2
- data/lib/nl/async/operation.rb +0 -2
- data/lib/nl/async.rb +0 -2
- data/lib/nl/attribute_set.rb +173 -0
- data/lib/nl/bitfield32.rb +86 -0
- data/lib/nl/blocking_transport.rb +12 -12
- data/lib/nl/connection.rb +7 -9
- data/lib/nl/datagram.rb +7 -9
- data/lib/nl/datatypes.rb +454 -0
- data/lib/nl/decoder.rb +4 -0
- data/lib/nl/endian.rb +10 -0
- data/lib/nl/exchange.rb +40 -18
- data/lib/nl/family.rb +18 -41
- data/lib/nl/genl/client.rb +104 -0
- data/lib/nl/genl/protocol.rb +59 -0
- data/lib/nl/genl/wire.rb +94 -0
- data/lib/nl/genl.rb +61 -61
- data/lib/nl/notification.rb +3 -6
- data/lib/nl/notification_router.rb +30 -23
- data/lib/nl/raw/client.rb +83 -0
- data/lib/nl/raw/protocol.rb +112 -0
- data/lib/nl/raw/wire.rb +146 -0
- data/lib/nl/raw.rb +104 -0
- data/lib/nl/sequence_allocator.rb +0 -2
- data/lib/nl/structured_payload.rb +61 -0
- data/lib/nl/sub_message.rb +94 -0
- data/lib/nl/version.rb +1 -1
- data/lib/nl.rb +5 -6
- data/sig/generated/nl/async/dispatcher.rbs +53 -0
- data/sig/generated/nl/async/driver.rbs +21 -0
- data/sig/generated/nl/async/mailbox.rbs +32 -0
- data/sig/generated/nl/async/operation.rbs +123 -0
- data/sig/generated/nl/async.rbs +9 -0
- data/sig/generated/nl/attribute_set.rbs +50 -0
- data/sig/generated/nl/bitfield32.rbs +41 -0
- data/sig/generated/nl/blocking_transport.rbs +33 -0
- data/sig/generated/nl/connection.rbs +26 -0
- data/sig/generated/nl/datagram.rbs +11 -0
- data/sig/generated/nl/datatypes.rbs +181 -0
- data/sig/generated/nl/decoder.rbs +38 -0
- data/sig/generated/nl/encoder.rbs +29 -0
- data/sig/generated/nl/endian.rbs +28 -0
- data/sig/generated/nl/error.rbs +27 -0
- data/sig/generated/nl/exchange.rbs +75 -0
- data/sig/generated/nl/family.rbs +71 -0
- data/sig/generated/nl/genl/client.rbs +74 -0
- data/sig/generated/nl/genl/protocol.rbs +37 -0
- data/sig/generated/nl/genl/wire.rbs +113 -0
- data/sig/generated/nl/genl.rbs +50 -0
- data/sig/generated/nl/notification.rbs +53 -0
- data/sig/generated/nl/notification_router.rbs +30 -0
- data/sig/generated/nl/raw/client.rbs +50 -0
- data/sig/generated/nl/raw/protocol.rbs +122 -0
- data/sig/generated/nl/raw/wire.rbs +151 -0
- data/sig/generated/nl/raw.rbs +70 -0
- data/sig/generated/nl/sequence_allocator.rbs +15 -0
- data/sig/generated/nl/socket.rbs +40 -0
- data/sig/generated/nl/structured_payload.rbs +25 -0
- data/sig/generated/nl/sub_message.rbs +74 -0
- data/sig/generated/nl/version.rbs +5 -0
- data/sig/generated/nl.rbs +2 -0
- metadata +48 -7
- data/lib/nl/core.rb +0 -94
- data/lib/nl/genl/connection.rb +0 -89
- data/lib/nl/protocols/genl.rb +0 -74
- data/lib/nl/protocols/raw.rb +0 -460
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# Generated from lib/nl/raw/wire.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Nl
|
|
4
|
+
module Raw
|
|
5
|
+
# Constants from <linux/netlink.h>
|
|
6
|
+
module Constants
|
|
7
|
+
NETLINK_ROUTE: ::Integer
|
|
8
|
+
|
|
9
|
+
NETLINK_NETFILTER: ::Integer
|
|
10
|
+
|
|
11
|
+
NETLINK_GENERIC: ::Integer
|
|
12
|
+
|
|
13
|
+
NLM_F_REQUEST: ::Integer
|
|
14
|
+
|
|
15
|
+
NLM_F_MULTI: ::Integer
|
|
16
|
+
|
|
17
|
+
NLM_F_ACK: ::Integer
|
|
18
|
+
|
|
19
|
+
NLM_F_ECHO: ::Integer
|
|
20
|
+
|
|
21
|
+
NLM_F_DUMP_INTR: ::Integer
|
|
22
|
+
|
|
23
|
+
NLM_F_DUMP_FILTERED: ::Integer
|
|
24
|
+
|
|
25
|
+
NLM_F_ROOT: ::Integer
|
|
26
|
+
|
|
27
|
+
NLM_F_MATCH: ::Integer
|
|
28
|
+
|
|
29
|
+
NLM_F_ATOMIC: ::Integer
|
|
30
|
+
|
|
31
|
+
NLM_F_DUMP: untyped
|
|
32
|
+
|
|
33
|
+
NLM_F_REPLACE: ::Integer
|
|
34
|
+
|
|
35
|
+
NLM_F_EXCL: ::Integer
|
|
36
|
+
|
|
37
|
+
NLM_F_CREATE: ::Integer
|
|
38
|
+
|
|
39
|
+
NLM_F_APPEND: ::Integer
|
|
40
|
+
|
|
41
|
+
NLMSG_ALIGNTO: ::Integer
|
|
42
|
+
|
|
43
|
+
NLMSG_HDRLEN: ::Integer
|
|
44
|
+
|
|
45
|
+
NLMSG_NOOP: ::Integer
|
|
46
|
+
|
|
47
|
+
NLMSG_ERROR: ::Integer
|
|
48
|
+
|
|
49
|
+
NLMSG_DONE: ::Integer
|
|
50
|
+
|
|
51
|
+
NLMSG_OVERRUN: ::Integer
|
|
52
|
+
|
|
53
|
+
NLMSG_MIN_TYPE: ::Integer
|
|
54
|
+
|
|
55
|
+
NLA_F_NESTED: untyped
|
|
56
|
+
|
|
57
|
+
NLA_F_NET_BYTEORDER: untyped
|
|
58
|
+
|
|
59
|
+
NLA_TYPE_MASK: untyped
|
|
60
|
+
|
|
61
|
+
NLA_ALIGNTO: ::Integer
|
|
62
|
+
|
|
63
|
+
NLA_HDRLEN: ::Integer
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
include Constants
|
|
67
|
+
|
|
68
|
+
# Fixed-format metadata header prepended to every Netlink message.
|
|
69
|
+
#
|
|
70
|
+
# This corresponds to Linux's +struct nlmsghdr+.
|
|
71
|
+
#
|
|
72
|
+
# @!attribute [rw] len
|
|
73
|
+
# @return [Integer] message length in bytes, including this header
|
|
74
|
+
# @!attribute [rw] type
|
|
75
|
+
# @return [Integer] message content type
|
|
76
|
+
# @!attribute [rw] flags
|
|
77
|
+
# @return [Integer] bitwise combination of +NLM_F_+ flags
|
|
78
|
+
# @!attribute [rw] seq
|
|
79
|
+
# @return [Integer] sequence number used to correlate requests and replies
|
|
80
|
+
# @!attribute [rw] pid
|
|
81
|
+
# @return [Integer] sender's Netlink port ID
|
|
82
|
+
class NlMsgHdr < Struct[Integer]
|
|
83
|
+
attr_accessor len(): Integer
|
|
84
|
+
|
|
85
|
+
attr_accessor type(): Integer
|
|
86
|
+
|
|
87
|
+
attr_accessor flags(): Integer
|
|
88
|
+
|
|
89
|
+
attr_accessor seq(): Integer
|
|
90
|
+
|
|
91
|
+
attr_accessor pid(): Integer
|
|
92
|
+
|
|
93
|
+
def self.new: (?Integer len, ?Integer type, ?Integer flags, ?Integer seq, ?Integer pid) -> instance
|
|
94
|
+
| (?len: Integer, ?type: Integer, ?flags: Integer, ?seq: Integer, ?pid: Integer) -> instance
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
class NlMsgHdr
|
|
98
|
+
FORMAT: untyped
|
|
99
|
+
|
|
100
|
+
# Decodes a header from the decoder's current position.
|
|
101
|
+
#
|
|
102
|
+
# @param [Decoder] decoder the source decoder
|
|
103
|
+
# @return [NlMsgHdr] the decoded header
|
|
104
|
+
# @rbs (Decoder decoder) -> instance
|
|
105
|
+
def self.decode: (Decoder decoder) -> instance
|
|
106
|
+
|
|
107
|
+
# Encodes this header at the encoder's current position.
|
|
108
|
+
#
|
|
109
|
+
# @param [Encoder] encoder the destination encoder
|
|
110
|
+
# @return [void]
|
|
111
|
+
# @rbs (Encoder encoder) -> void
|
|
112
|
+
def encode: (Encoder encoder) -> void
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
# Fixed-format header prepended to every Netlink attribute.
|
|
116
|
+
#
|
|
117
|
+
# This corresponds to Linux's +struct nlattr+.
|
|
118
|
+
#
|
|
119
|
+
# @!attribute [rw] len
|
|
120
|
+
# @return [Integer] attribute length in bytes, including this header but
|
|
121
|
+
# excluding trailing alignment padding
|
|
122
|
+
# @!attribute [rw] type
|
|
123
|
+
# @return [Integer] attribute type combined with optional +NLA_F_+ flags
|
|
124
|
+
class NlAttr < Struct[Integer]
|
|
125
|
+
attr_accessor len(): Integer
|
|
126
|
+
|
|
127
|
+
attr_accessor type(): Integer
|
|
128
|
+
|
|
129
|
+
def self.new: (?Integer len, ?Integer type) -> instance
|
|
130
|
+
| (?len: Integer, ?type: Integer) -> instance
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
class NlAttr
|
|
134
|
+
FORMAT: untyped
|
|
135
|
+
|
|
136
|
+
# Decodes an attribute header from the decoder's current position.
|
|
137
|
+
#
|
|
138
|
+
# @param [Decoder] decoder the source decoder
|
|
139
|
+
# @return [NlAttr] the decoded header
|
|
140
|
+
# @rbs (Decoder decoder) -> instance
|
|
141
|
+
def self.decode: (Decoder decoder) -> instance
|
|
142
|
+
|
|
143
|
+
# Encodes this attribute header at the encoder's current position.
|
|
144
|
+
#
|
|
145
|
+
# @param [Encoder] encoder the destination encoder
|
|
146
|
+
# @return [void]
|
|
147
|
+
# @rbs (Encoder encoder) -> void
|
|
148
|
+
def encode: (Encoder encoder) -> void
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
end
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# Generated from lib/nl/raw.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Nl
|
|
4
|
+
# Classic (Raw) Netlink families.
|
|
5
|
+
module Raw
|
|
6
|
+
# Base class for Raw Netlink families.
|
|
7
|
+
class Family < Nl::Family
|
|
8
|
+
# Opens a session for this raw Netlink family.
|
|
9
|
+
#
|
|
10
|
+
# @overload open(executor: nil, notification_capacity: DEFAULT_NOTIFICATION_CAPACITY)
|
|
11
|
+
# The caller is responsible for closing the session.
|
|
12
|
+
# @param [:thread, :fiber, nil] executor the asynchronous executor, or `nil` for blocking operation
|
|
13
|
+
# @param [Integer] notification_capacity the maximum number of queued notifications
|
|
14
|
+
# @return [Family] the opened family session
|
|
15
|
+
# @overload open(executor: nil, notification_capacity: DEFAULT_NOTIFICATION_CAPACITY, &block)
|
|
16
|
+
# The session is automatically closed after the block returns.
|
|
17
|
+
# @param [:thread, :fiber, nil] executor the asynchronous executor, or `nil` for blocking operation
|
|
18
|
+
# @param [Integer] notification_capacity the maximum number of queued notifications
|
|
19
|
+
# @yieldparam [Family] session the opened family session
|
|
20
|
+
# @return [Object] the value returned from the block
|
|
21
|
+
# @rbs (?executor: executor?, ?notification_capacity: Integer?) -> (Nl::Family::Session & instance)
|
|
22
|
+
# | [R] (?executor: executor?, ?notification_capacity: Integer?) { (instance) -> R } -> R
|
|
23
|
+
def self.open: (?executor: executor?, ?notification_capacity: Integer?) -> (Nl::Family::Session & instance)
|
|
24
|
+
| [R] (?executor: executor?, ?notification_capacity: Integer?) { (instance) -> R } -> R
|
|
25
|
+
|
|
26
|
+
# Builds a session that owns its underlying client.
|
|
27
|
+
#
|
|
28
|
+
# @param [:thread, :fiber, nil] executor the asynchronous executor, or `nil` for blocking operation
|
|
29
|
+
# @param [Integer] notification_capacity the maximum number of queued notifications
|
|
30
|
+
# @return [Family] the opened family session
|
|
31
|
+
# @rbs (executor: executor?, notification_capacity: Integer) -> (Nl::Family::Session & instance)
|
|
32
|
+
private def self.build_session: (executor: executor?, notification_capacity: Integer) -> (Nl::Family::Session & instance)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Base class for raw Netlink messages.
|
|
36
|
+
#
|
|
37
|
+
# A message may contain a fixed header followed by a set of Netlink
|
|
38
|
+
# attributes.
|
|
39
|
+
class Message
|
|
40
|
+
include Nl::StructuredPayload
|
|
41
|
+
|
|
42
|
+
# @param [Object, nil] fixed_header the family-specific fixed header
|
|
43
|
+
# @param [AttributeSet, nil] attributes the message's attributes
|
|
44
|
+
# @rbs (?untyped fixed_header, ?AttributeSet? attributes) -> void
|
|
45
|
+
def initialize: (?untyped fixed_header, ?AttributeSet? attributes) -> void
|
|
46
|
+
|
|
47
|
+
# Appends an attribute to the message.
|
|
48
|
+
#
|
|
49
|
+
# @param [AttributeSet::Attribute] attribute the attribute to append
|
|
50
|
+
# @return [void]
|
|
51
|
+
# @rbs (AttributeSet::Attribute attribute) -> void
|
|
52
|
+
def append_attribute: (AttributeSet::Attribute attribute) -> void
|
|
53
|
+
|
|
54
|
+
# Decodes a raw Netlink message payload.
|
|
55
|
+
#
|
|
56
|
+
# @param [Decoder] decoder the source decoder
|
|
57
|
+
# @param [Integer] type the message type from its Netlink header
|
|
58
|
+
# @return [Message] the decoded message
|
|
59
|
+
# @raise [RuntimeError] if +type+ does not match the message class's type
|
|
60
|
+
# @rbs (Decoder decoder, type: Integer) -> instance
|
|
61
|
+
def self.decode: (Decoder decoder, type: Integer) -> instance
|
|
62
|
+
|
|
63
|
+
# Returns the attribute names accepted by this message.
|
|
64
|
+
#
|
|
65
|
+
# @return [Array<Symbol>] the attribute names
|
|
66
|
+
# @rbs () -> Array[Symbol]
|
|
67
|
+
private def self.attribute_names: () -> Array[Symbol]
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Generated from lib/nl/sequence_allocator.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Nl
|
|
4
|
+
# Allocates nonzero 32-bit Netlink sequence numbers.
|
|
5
|
+
class SequenceAllocator
|
|
6
|
+
MAX: ::Integer
|
|
7
|
+
|
|
8
|
+
def initialize: () -> untyped
|
|
9
|
+
|
|
10
|
+
# Returns the next sequence number not rejected by the optional block.
|
|
11
|
+
def next: () -> untyped
|
|
12
|
+
|
|
13
|
+
private def advance: () -> untyped
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Generated from lib/nl/socket.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Nl
|
|
4
|
+
# Netlink socket
|
|
5
|
+
class Socket < ::Socket
|
|
6
|
+
module Constants
|
|
7
|
+
# From include/linux/socket.h
|
|
8
|
+
PF_NETLINK: untyped
|
|
9
|
+
|
|
10
|
+
# From include/uapi/linux/netlink.h
|
|
11
|
+
SOL_NETLINK: ::Integer
|
|
12
|
+
|
|
13
|
+
NETLINK_ADD_MEMBERSHIP: ::Integer
|
|
14
|
+
|
|
15
|
+
NETLINK_DROP_MEMBERSHIP: ::Integer
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
include Constants
|
|
19
|
+
|
|
20
|
+
def self.pack_sockaddr_nl: (untyped pid, untyped groups) -> untyped
|
|
21
|
+
|
|
22
|
+
alias self.sockaddr_nl self.pack_sockaddr_nl
|
|
23
|
+
|
|
24
|
+
def self.unpack_sockaddr_nl: (untyped sockaddr) -> untyped
|
|
25
|
+
|
|
26
|
+
# @param protonum [Integer] Netlink protocol number
|
|
27
|
+
def initialize: (untyped protonum) -> untyped
|
|
28
|
+
|
|
29
|
+
def self.open: (untyped protonum) -> untyped
|
|
30
|
+
|
|
31
|
+
# @return [Integer] Local Netlink port ID assigned to this socket
|
|
32
|
+
def local_port_id: () -> untyped
|
|
33
|
+
|
|
34
|
+
# Adds this socket to a Netlink multicast group.
|
|
35
|
+
def add_membership: (untyped group_id) -> untyped
|
|
36
|
+
|
|
37
|
+
# Removes this socket from a Netlink multicast group.
|
|
38
|
+
def drop_membership: (untyped group_id) -> untyped
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Generated from lib/nl/structured_payload.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Nl
|
|
4
|
+
# Shared handling for a payload containing an optional fixed header followed
|
|
5
|
+
# by an optional attribute set.
|
|
6
|
+
module StructuredPayload
|
|
7
|
+
def self.included: (untyped base) -> untyped
|
|
8
|
+
|
|
9
|
+
attr_accessor fixed_header: untyped
|
|
10
|
+
|
|
11
|
+
attr_accessor attributes: untyped
|
|
12
|
+
|
|
13
|
+
def initialize: (?untyped fixed_header, ?untyped attributes) -> untyped
|
|
14
|
+
|
|
15
|
+
module ClassMethods
|
|
16
|
+
def from_params: (?untyped params, ?external_selectors: untyped, **untyped keywords) -> untyped
|
|
17
|
+
|
|
18
|
+
def decode: (untyped decoder, ?external_selectors: untyped) -> untyped
|
|
19
|
+
|
|
20
|
+
private def attribute_names: () -> untyped
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def encode: (untyped encoder, ?external_selectors: untyped) -> untyped
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Generated from lib/nl/sub_message.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Nl
|
|
4
|
+
module Selector
|
|
5
|
+
class MissingSelectorValueError < StandardError
|
|
6
|
+
attr_reader scope: untyped
|
|
7
|
+
|
|
8
|
+
attr_reader index: untyped
|
|
9
|
+
|
|
10
|
+
def initialize: (untyped scope, untyped index) -> untyped
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
class UnknownSelectorValueError < StandardError
|
|
14
|
+
attr_reader value: untyped
|
|
15
|
+
|
|
16
|
+
def initialize: (untyped value) -> untyped
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
module Reference
|
|
20
|
+
def select: (untyped context, untyped formats) -> untyped
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
class Local < Data
|
|
24
|
+
attr_reader index(): untyped
|
|
25
|
+
|
|
26
|
+
def self.new: (untyped index) -> instance
|
|
27
|
+
| (index: untyped) -> instance
|
|
28
|
+
|
|
29
|
+
def self.members: () -> [ :index ]
|
|
30
|
+
|
|
31
|
+
def members: () -> [ :index ]
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
class External < Data
|
|
35
|
+
attr_reader index(): untyped
|
|
36
|
+
|
|
37
|
+
def self.new: (untyped index) -> instance
|
|
38
|
+
| (index: untyped) -> instance
|
|
39
|
+
|
|
40
|
+
def self.members: () -> [ :index ]
|
|
41
|
+
|
|
42
|
+
def members: () -> [ :index ]
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
class State
|
|
46
|
+
def initialize: (untyped local_count, untyped external) -> untyped
|
|
47
|
+
|
|
48
|
+
def set_local: (untyped index, untyped value) -> untyped
|
|
49
|
+
|
|
50
|
+
def fetch_local: (untyped index) -> untyped
|
|
51
|
+
|
|
52
|
+
def fetch_external: (untyped index) -> untyped
|
|
53
|
+
|
|
54
|
+
def fetch: (untyped values, untyped key) -> untyped
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# A selector-specific payload containing an optional fixed header followed by
|
|
59
|
+
# an optional set of Netlink attributes.
|
|
60
|
+
class SubMessage
|
|
61
|
+
include StructuredPayload
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# An unrecognized selector-specific payload retained without interpretation.
|
|
65
|
+
class RawSubMessage < SubMessage
|
|
66
|
+
attr_reader payload: untyped
|
|
67
|
+
|
|
68
|
+
attr_reader nlattr_type_flags: untyped
|
|
69
|
+
|
|
70
|
+
def initialize: (untyped payload, nlattr_type_flags: untyped) -> untyped
|
|
71
|
+
|
|
72
|
+
def encode: (untyped encoder, ?external_selectors: untyped) -> untyped
|
|
73
|
+
end
|
|
74
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: nl
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Kasumi Hanazuki
|
|
@@ -28,10 +28,12 @@ files:
|
|
|
28
28
|
- lib/nl/async/driver.rb
|
|
29
29
|
- lib/nl/async/mailbox.rb
|
|
30
30
|
- lib/nl/async/operation.rb
|
|
31
|
+
- lib/nl/attribute_set.rb
|
|
32
|
+
- lib/nl/bitfield32.rb
|
|
31
33
|
- lib/nl/blocking_transport.rb
|
|
32
34
|
- lib/nl/connection.rb
|
|
33
|
-
- lib/nl/core.rb
|
|
34
35
|
- lib/nl/datagram.rb
|
|
36
|
+
- lib/nl/datatypes.rb
|
|
35
37
|
- lib/nl/decoder.rb
|
|
36
38
|
- lib/nl/encoder.rb
|
|
37
39
|
- lib/nl/endian.rb
|
|
@@ -39,20 +41,59 @@ files:
|
|
|
39
41
|
- lib/nl/exchange.rb
|
|
40
42
|
- lib/nl/family.rb
|
|
41
43
|
- lib/nl/genl.rb
|
|
42
|
-
- lib/nl/genl/
|
|
44
|
+
- lib/nl/genl/client.rb
|
|
45
|
+
- lib/nl/genl/protocol.rb
|
|
46
|
+
- lib/nl/genl/wire.rb
|
|
43
47
|
- lib/nl/notification.rb
|
|
44
48
|
- lib/nl/notification_router.rb
|
|
45
|
-
- lib/nl/
|
|
46
|
-
- lib/nl/
|
|
49
|
+
- lib/nl/raw.rb
|
|
50
|
+
- lib/nl/raw/client.rb
|
|
51
|
+
- lib/nl/raw/protocol.rb
|
|
52
|
+
- lib/nl/raw/wire.rb
|
|
47
53
|
- lib/nl/sequence_allocator.rb
|
|
48
54
|
- lib/nl/socket.rb
|
|
55
|
+
- lib/nl/structured_payload.rb
|
|
56
|
+
- lib/nl/sub_message.rb
|
|
49
57
|
- lib/nl/version.rb
|
|
58
|
+
- sig/generated/nl.rbs
|
|
59
|
+
- sig/generated/nl/async.rbs
|
|
60
|
+
- sig/generated/nl/async/dispatcher.rbs
|
|
61
|
+
- sig/generated/nl/async/driver.rbs
|
|
62
|
+
- sig/generated/nl/async/mailbox.rbs
|
|
63
|
+
- sig/generated/nl/async/operation.rbs
|
|
64
|
+
- sig/generated/nl/attribute_set.rbs
|
|
65
|
+
- sig/generated/nl/bitfield32.rbs
|
|
66
|
+
- sig/generated/nl/blocking_transport.rbs
|
|
67
|
+
- sig/generated/nl/connection.rbs
|
|
68
|
+
- sig/generated/nl/datagram.rbs
|
|
69
|
+
- sig/generated/nl/datatypes.rbs
|
|
70
|
+
- sig/generated/nl/decoder.rbs
|
|
71
|
+
- sig/generated/nl/encoder.rbs
|
|
72
|
+
- sig/generated/nl/endian.rbs
|
|
73
|
+
- sig/generated/nl/error.rbs
|
|
74
|
+
- sig/generated/nl/exchange.rbs
|
|
75
|
+
- sig/generated/nl/family.rbs
|
|
76
|
+
- sig/generated/nl/genl.rbs
|
|
77
|
+
- sig/generated/nl/genl/client.rbs
|
|
78
|
+
- sig/generated/nl/genl/protocol.rbs
|
|
79
|
+
- sig/generated/nl/genl/wire.rbs
|
|
80
|
+
- sig/generated/nl/notification.rbs
|
|
81
|
+
- sig/generated/nl/notification_router.rbs
|
|
82
|
+
- sig/generated/nl/raw.rbs
|
|
83
|
+
- sig/generated/nl/raw/client.rbs
|
|
84
|
+
- sig/generated/nl/raw/protocol.rbs
|
|
85
|
+
- sig/generated/nl/raw/wire.rbs
|
|
86
|
+
- sig/generated/nl/sequence_allocator.rbs
|
|
87
|
+
- sig/generated/nl/socket.rbs
|
|
88
|
+
- sig/generated/nl/structured_payload.rbs
|
|
89
|
+
- sig/generated/nl/sub_message.rbs
|
|
90
|
+
- sig/generated/nl/version.rbs
|
|
50
91
|
homepage: https://github.com/hanazuki/nl
|
|
51
92
|
licenses:
|
|
52
93
|
- MIT
|
|
53
94
|
metadata:
|
|
54
95
|
homepage_uri: https://github.com/hanazuki/nl
|
|
55
|
-
source_code_uri: https://github.com/hanazuki/nl/tree/v0.
|
|
96
|
+
source_code_uri: https://github.com/hanazuki/nl/tree/v0.4.1
|
|
56
97
|
changelog_uri: https://github.com/hanazuki/nl/blob/master/CHANGELOG.md
|
|
57
98
|
rdoc_options: []
|
|
58
99
|
require_paths:
|
|
@@ -68,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
68
109
|
- !ruby/object:Gem::Version
|
|
69
110
|
version: '0'
|
|
70
111
|
requirements: []
|
|
71
|
-
rubygems_version: 4.0.
|
|
112
|
+
rubygems_version: 4.0.16
|
|
72
113
|
specification_version: 4
|
|
73
114
|
summary: Netlink protocol support for Ruby
|
|
74
115
|
test_files: []
|
data/lib/nl/core.rb
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
# Netlink wire definitions
|
|
2
|
-
|
|
3
|
-
require_relative 'endian'
|
|
4
|
-
|
|
5
|
-
module Nl
|
|
6
|
-
module Core
|
|
7
|
-
module Constants
|
|
8
|
-
# From include/uapi/linux/netlink.h
|
|
9
|
-
NETLINK_ROUTE = 0
|
|
10
|
-
NETLINK_NETFILTER = 12
|
|
11
|
-
NETLINK_GENERIC = 16
|
|
12
|
-
|
|
13
|
-
NLM_F_REQUEST = 1
|
|
14
|
-
NLM_F_MULTI = 2
|
|
15
|
-
NLM_F_ACK = 4
|
|
16
|
-
NLM_F_ECHO = 8
|
|
17
|
-
NLM_F_DUMP_INTR = 16
|
|
18
|
-
NLM_F_DUMP_FILTERED = 32
|
|
19
|
-
NLM_F_ROOT = 0x100
|
|
20
|
-
NLM_F_MATCH = 0x200
|
|
21
|
-
NLM_F_ATOMIC = 0x400
|
|
22
|
-
NLM_F_DUMP = NLM_F_ROOT | NLM_F_MATCH
|
|
23
|
-
NLM_F_REPLACE = 0x100
|
|
24
|
-
NLM_F_EXCL = 0x200
|
|
25
|
-
NLM_F_CREATE = 0x400
|
|
26
|
-
NLM_F_APPEND = 0x800
|
|
27
|
-
|
|
28
|
-
NLMSG_ALIGNTO = 4
|
|
29
|
-
NLMSG_HDRLEN = 16
|
|
30
|
-
|
|
31
|
-
NLMSG_NOOP = 0x1
|
|
32
|
-
NLMSG_ERROR = 0x2
|
|
33
|
-
NLMSG_DONE = 0x3
|
|
34
|
-
NLMSG_OVERRUN = 0x4
|
|
35
|
-
|
|
36
|
-
NLMSG_MIN_TYPE = 0x10
|
|
37
|
-
|
|
38
|
-
NLA_F_NESTED = 1 << 15
|
|
39
|
-
NLA_F_NET_BYTEORDER = 1 << 14
|
|
40
|
-
NLA_TYPE_MASK = ~(NLA_F_NESTED | NLA_F_NET_BYTEORDER)
|
|
41
|
-
|
|
42
|
-
NLA_ALIGNTO = 4
|
|
43
|
-
NLA_HDRLEN = 4
|
|
44
|
-
end
|
|
45
|
-
include Constants
|
|
46
|
-
|
|
47
|
-
NlMsgHdr = Struct.new(:len, :type, :flags, :seq, :pid)
|
|
48
|
-
# Message header
|
|
49
|
-
class NlMsgHdr
|
|
50
|
-
FORMAT = Ractor.make_shareable([
|
|
51
|
-
Endian::Host::U32,
|
|
52
|
-
Endian::Host::U16,
|
|
53
|
-
Endian::Host::U16,
|
|
54
|
-
Endian::Host::U32,
|
|
55
|
-
Endian::Host::U32,
|
|
56
|
-
])
|
|
57
|
-
private_constant :FORMAT
|
|
58
|
-
|
|
59
|
-
def self.decode(decoder)
|
|
60
|
-
obj = new(*decoder.get_values(FORMAT))
|
|
61
|
-
decoder.align_to(Constants::NLMSG_ALIGNTO)
|
|
62
|
-
obj
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def encode(encoder)
|
|
66
|
-
encoder.reserve(Constants::NLMSG_HDRLEN)
|
|
67
|
-
encoder.put_values(FORMAT, to_a)
|
|
68
|
-
encoder.align_to(Constants::NLMSG_ALIGNTO)
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
NlAttr = Struct.new(:len, :type)
|
|
73
|
-
# Attribute header
|
|
74
|
-
class NlAttr
|
|
75
|
-
FORMAT = Ractor.make_shareable([
|
|
76
|
-
Endian::Host::U16,
|
|
77
|
-
Endian::Host::U16,
|
|
78
|
-
])
|
|
79
|
-
private_constant :FORMAT
|
|
80
|
-
|
|
81
|
-
def self.decode(decoder)
|
|
82
|
-
obj = new(*decoder.get_values(FORMAT))
|
|
83
|
-
decoder.align_to(Constants::NLA_ALIGNTO)
|
|
84
|
-
obj
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
def encode(encoder)
|
|
88
|
-
encoder.reserve(Constants::NLA_HDRLEN)
|
|
89
|
-
encoder.put_values(FORMAT, to_a)
|
|
90
|
-
encoder.align_to(Constants::NLA_ALIGNTO)
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
end
|
data/lib/nl/genl/connection.rb
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
# Generic Netlink connection handling
|
|
2
|
-
#--
|
|
3
|
-
# rbs_inline: enabled
|
|
4
|
-
|
|
5
|
-
require_relative '../connection'
|
|
6
|
-
require_relative '../core'
|
|
7
|
-
require_relative '../protocols/genl'
|
|
8
|
-
|
|
9
|
-
module Nl
|
|
10
|
-
module Genl
|
|
11
|
-
FamilyInfo = Data.define(:id, :multicast_groups) do
|
|
12
|
-
def self.from_reply(reply)
|
|
13
|
-
groups = (reply.mcast_groups || []).to_h do |attributes|
|
|
14
|
-
[attributes[:name].value.to_sym, attributes[:id].value]
|
|
15
|
-
end
|
|
16
|
-
new(id: reply.family_id, multicast_groups: groups.freeze)
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
class Connection
|
|
21
|
-
#--
|
|
22
|
-
# @rbs (resolver: ^(instance, ::String) -> (Integer | FamilyInfo | untyped), ?executor: executor?, ?notification_capacity: Integer?) -> instance
|
|
23
|
-
# | [R] (resolver: ^(instance, ::String) -> (Integer | FamilyInfo | untyped), ?executor: executor?, ?notification_capacity: Integer?) { (instance) -> R } -> R
|
|
24
|
-
def self.open(resolver:, executor: nil, notification_capacity: Nl::Connection::DEFAULT_NOTIFICATION_CAPACITY)
|
|
25
|
-
conn = new(resolver:, executor:, notification_capacity:)
|
|
26
|
-
if block_given?
|
|
27
|
-
begin
|
|
28
|
-
yield conn
|
|
29
|
-
ensure
|
|
30
|
-
conn.close
|
|
31
|
-
end
|
|
32
|
-
else
|
|
33
|
-
conn
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
#--
|
|
38
|
-
# @rbs resolver: ^(instance, ::String) -> (Integer | FamilyInfo | untyped)
|
|
39
|
-
# @rbs executor: executor?
|
|
40
|
-
# @rbs return: instance
|
|
41
|
-
def initialize(resolver:, executor: nil, notification_capacity: Nl::Connection::DEFAULT_NOTIFICATION_CAPACITY)
|
|
42
|
-
@resolver = resolver
|
|
43
|
-
@family_cache = {}
|
|
44
|
-
@family_cache_mutex = Mutex.new
|
|
45
|
-
@connection = Nl::Connection.new(
|
|
46
|
-
protocol: Protocols::Genl,
|
|
47
|
-
executor:,
|
|
48
|
-
notification_capacity:,
|
|
49
|
-
)
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def family(family_class)
|
|
53
|
-
proto = family_class::PROTOCOL
|
|
54
|
-
info = family_info(proto)
|
|
55
|
-
family_class.new(
|
|
56
|
-
@connection,
|
|
57
|
-
protocol: Protocols::Genl.new(
|
|
58
|
-
proto.name,
|
|
59
|
-
family_id: info.id,
|
|
60
|
-
multicast_groups: info.multicast_groups,
|
|
61
|
-
),
|
|
62
|
-
)
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def close
|
|
66
|
-
@connection.close
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
private def family_info(protocol)
|
|
70
|
-
id = protocol.family_id
|
|
71
|
-
FamilyInfo.new(id:, multicast_groups: {}.freeze)
|
|
72
|
-
rescue NotImplementedError
|
|
73
|
-
cached_info = @family_cache_mutex.synchronize { @family_cache[protocol.name] }
|
|
74
|
-
return cached_info if cached_info
|
|
75
|
-
|
|
76
|
-
resolved = @resolver.call(self, protocol.name)
|
|
77
|
-
info = case resolved
|
|
78
|
-
when Integer
|
|
79
|
-
FamilyInfo.new(id: resolved, multicast_groups: {}.freeze)
|
|
80
|
-
when FamilyInfo
|
|
81
|
-
resolved
|
|
82
|
-
else
|
|
83
|
-
FamilyInfo.from_reply(resolved)
|
|
84
|
-
end
|
|
85
|
-
@family_cache_mutex.synchronize { @family_cache[protocol.name] ||= info }
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
end
|
|
89
|
-
end
|