nl 0.4.1 → 0.4.2
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 +2 -0
- data/lib/nl/endian.rb +1 -2
- data/lib/nl/family.rb +33 -15
- data/lib/nl/genl/client.rb +1 -0
- data/lib/nl/genl/wire.rb +1 -0
- data/lib/nl/genl.rb +0 -2
- data/lib/nl/raw/client.rb +1 -1
- data/lib/nl/raw/wire.rb +1 -0
- data/lib/nl/socket.rb +21 -5
- data/lib/nl/version.rb +1 -1
- data/sig/generated/nl/endian.rbs +1 -0
- data/sig/generated/nl/family.rbs +40 -22
- data/sig/generated/nl/raw/client.rbs +0 -1
- data/sig/generated/nl/socket.rbs +29 -10
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 79ef39fff2bdef294954fb2504056339d504229a5ea65c967319f16bdbe23baf
|
|
4
|
+
data.tar.gz: b5f40b4f424d888406b6d2d6998e2182a5303fc2d4c4ad5d5be6c9d95005731d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 61b396c794cbb4b65538ecaf605aa954b01ec4bbf53d80169b5cc0804c6176405b5c75dc6776f5a5af63091ef94a1f02fd48604c4a801836cadde0567b8a8855
|
|
7
|
+
data.tar.gz: 37cbe64bd74bd5d47fca5c5306ee8f490dfe84445595e8db7ed02716de2abbe2eff3594b806ef9ece125ab03d11fd9f4aa826347447aafce62f5e5c00941bcd7
|
data/CHANGELOG.md
CHANGED
data/lib/nl/endian.rb
CHANGED
data/lib/nl/family.rb
CHANGED
|
@@ -34,18 +34,20 @@ module Nl
|
|
|
34
34
|
# end
|
|
35
35
|
|
|
36
36
|
class Family
|
|
37
|
-
DEFAULT_NOTIFICATION_CAPACITY = Connection::DEFAULT_NOTIFICATION_CAPACITY
|
|
37
|
+
DEFAULT_NOTIFICATION_CAPACITY = Connection::DEFAULT_NOTIFICATION_CAPACITY #: Integer
|
|
38
38
|
|
|
39
|
+
# Socket-owning family.
|
|
40
|
+
#
|
|
41
|
+
# {Family} instances that owns sockets are extended with this module.
|
|
39
42
|
module Session
|
|
40
|
-
|
|
43
|
+
# Closes the Netlink socket owned by this {Family}.
|
|
44
|
+
# @rbs () -> void
|
|
45
|
+
def close
|
|
41
46
|
@connection.close
|
|
42
47
|
end
|
|
43
48
|
end
|
|
44
49
|
|
|
45
|
-
|
|
46
|
-
# @rbs connection: _Connection
|
|
47
|
-
# @rbs endpoint: Raw::Endpoint
|
|
48
|
-
# @rbs return: instance
|
|
50
|
+
# @rbs (_Connection connection, endpoint: Raw::Endpoint) -> instance
|
|
49
51
|
def initialize(connection, endpoint:)
|
|
50
52
|
@endpoint = endpoint
|
|
51
53
|
@connection = connection
|
|
@@ -59,38 +61,54 @@ module Nl
|
|
|
59
61
|
@connection.exchange(@endpoint, kind, request_class, reply_class, args, &block)
|
|
60
62
|
end
|
|
61
63
|
|
|
62
|
-
|
|
64
|
+
# Returns if this family supports asynchronous operations.
|
|
65
|
+
#
|
|
66
|
+
# @rbs () -> bool
|
|
67
|
+
def async_capable?
|
|
63
68
|
@connection.async_capable?
|
|
64
69
|
end
|
|
65
70
|
|
|
66
|
-
# Adds multicast memberships to the
|
|
67
|
-
#
|
|
71
|
+
# Adds multicast memberships to the netlink socket.
|
|
72
|
+
#
|
|
73
|
+
# Membership is additive and remains active until explicitly removed or the owner closes.
|
|
74
|
+
#
|
|
75
|
+
# @param [Array<Symbol>] groups
|
|
76
|
+
# @return [Family] self
|
|
77
|
+
# @rbs (Symbol *groups) -> self
|
|
68
78
|
def subscribe(*groups)
|
|
69
79
|
@connection.add_memberships(multicast_group_ids(groups))
|
|
70
80
|
self
|
|
71
81
|
end
|
|
72
82
|
|
|
83
|
+
# Removes multicast memberships from the netlink socket.
|
|
84
|
+
#
|
|
85
|
+
# @param [Array<Symbol>] groups
|
|
86
|
+
# @return [Family] self
|
|
87
|
+
# @rbs (Symbol *groups) -> self
|
|
73
88
|
def unsubscribe(*groups)
|
|
74
89
|
@connection.drop_memberships(multicast_group_ids(groups))
|
|
75
90
|
self
|
|
76
91
|
end
|
|
77
92
|
|
|
93
|
+
# Receives the next unsolicited message.
|
|
94
|
+
#
|
|
95
|
+
# @rbs (?timeout: Integer?) -> Message
|
|
78
96
|
def receive_notification(timeout: nil)
|
|
79
97
|
@notification_stream.next(timeout:)
|
|
80
98
|
end
|
|
81
99
|
|
|
100
|
+
# Receives unsolicited messages.
|
|
101
|
+
#
|
|
102
|
+
# @rbs () { (Message) -> void } -> void
|
|
82
103
|
def each_notification(&block)
|
|
83
104
|
return @notification_stream.each unless block
|
|
84
105
|
|
|
85
106
|
@notification_stream.each(&block)
|
|
86
107
|
end
|
|
87
108
|
|
|
88
|
-
# Builds a
|
|
89
|
-
#
|
|
90
|
-
|
|
91
|
-
# @rbs operations_class: Class
|
|
92
|
-
# @rbs stream_capacity: Integer?
|
|
93
|
-
# @rbs return: untyped
|
|
109
|
+
# Builds a asynchronous-operation facade.
|
|
110
|
+
#
|
|
111
|
+
# @rbs (Class operations_class, ?stream_capacity: Integer?) -> untyped
|
|
94
112
|
private def build_async_facade(operations_class, stream_capacity: nil)
|
|
95
113
|
unless async_capable?
|
|
96
114
|
raise Async::UnavailableError, 'async operations require an executor'
|
data/lib/nl/genl/client.rb
CHANGED
data/lib/nl/genl/wire.rb
CHANGED
data/lib/nl/genl.rb
CHANGED
data/lib/nl/raw/client.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# Raw Netlink client handling
|
|
2
|
+
#-
|
|
2
3
|
|
|
3
4
|
require_relative '../connection'
|
|
4
5
|
require_relative 'protocol'
|
|
@@ -73,7 +74,6 @@ module Nl
|
|
|
73
74
|
# Closes the underlying Netlink connection.
|
|
74
75
|
#
|
|
75
76
|
# @return [void]
|
|
76
|
-
#--
|
|
77
77
|
# @rbs () -> void
|
|
78
78
|
def close
|
|
79
79
|
@connection.close
|
data/lib/nl/raw/wire.rb
CHANGED
data/lib/nl/socket.rb
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
# Netlink sockets
|
|
2
|
-
|
|
3
1
|
require 'socket'
|
|
4
2
|
|
|
5
3
|
module Nl
|
|
6
4
|
# Netlink socket
|
|
7
5
|
class Socket < ::Socket
|
|
8
6
|
module Constants
|
|
9
|
-
# From
|
|
7
|
+
# From linux/socket.h
|
|
8
|
+
#-
|
|
10
9
|
PF_NETLINK = AF_NETLINK = 16
|
|
11
10
|
|
|
12
|
-
# From
|
|
11
|
+
# From linux/netlink.h
|
|
12
|
+
#-
|
|
13
13
|
SOL_NETLINK = 270
|
|
14
14
|
NETLINK_ADD_MEMBERSHIP = 1
|
|
15
15
|
NETLINK_DROP_MEMBERSHIP = 2
|
|
@@ -17,17 +17,28 @@ module Nl
|
|
|
17
17
|
include Constants
|
|
18
18
|
|
|
19
19
|
class << self
|
|
20
|
+
# Packs Netlink socket address
|
|
21
|
+
#
|
|
22
|
+
# @rbs (Integer pid, Integer groups) -> String
|
|
20
23
|
def pack_sockaddr_nl(pid, groups) = [Socket::AF_NETLINK, 0, pid, groups].pack('S!S!LL')
|
|
21
24
|
alias sockaddr_nl pack_sockaddr_nl
|
|
22
25
|
|
|
26
|
+
# Unpacks Netlink socket address
|
|
27
|
+
#
|
|
28
|
+
# @rbs (String) -> [Integer, Integer]
|
|
23
29
|
def unpack_sockaddr_nl(sockaddr) = sockaddr.unpack('S!S!LL')[2..3]
|
|
24
30
|
end
|
|
25
31
|
|
|
26
|
-
# @param
|
|
32
|
+
# @param [Integer] protonum Netlink protocol number
|
|
33
|
+
# @rbs (Integer) -> void
|
|
27
34
|
def initialize(protonum)
|
|
28
35
|
super(PF_NETLINK, SOCK_RAW, protonum)
|
|
29
36
|
end
|
|
30
37
|
|
|
38
|
+
# Opens a Netlink socket for the specified protocol number.
|
|
39
|
+
#
|
|
40
|
+
# @rbs (Integer protonum) -> instance
|
|
41
|
+
# | [R] (Integer protonum) { (instance) -> R } -> R
|
|
31
42
|
def self.open(protonum)
|
|
32
43
|
return new(protonum) unless block_given?
|
|
33
44
|
begin
|
|
@@ -39,16 +50,21 @@ module Nl
|
|
|
39
50
|
end
|
|
40
51
|
|
|
41
52
|
# @return [Integer] Local Netlink port ID assigned to this socket
|
|
53
|
+
# @rbs () -> Integer
|
|
42
54
|
def local_port_id
|
|
43
55
|
Socket.unpack_sockaddr_nl(local_address.to_sockaddr).first
|
|
44
56
|
end
|
|
45
57
|
|
|
46
58
|
# Adds this socket to a Netlink multicast group.
|
|
59
|
+
#
|
|
60
|
+
# @rbs (Integer group_id) -> void
|
|
47
61
|
def add_membership(group_id)
|
|
48
62
|
setsockopt(SOL_NETLINK, NETLINK_ADD_MEMBERSHIP, group_id)
|
|
49
63
|
end
|
|
50
64
|
|
|
51
65
|
# Removes this socket from a Netlink multicast group.
|
|
66
|
+
#
|
|
67
|
+
# @rbs (Integer group_id) -> void
|
|
52
68
|
def drop_membership(group_id)
|
|
53
69
|
setsockopt(SOL_NETLINK, NETLINK_DROP_MEMBERSHIP, group_id)
|
|
54
70
|
end
|
data/lib/nl/version.rb
CHANGED
data/sig/generated/nl/endian.rbs
CHANGED
data/sig/generated/nl/family.rbs
CHANGED
|
@@ -26,38 +26,56 @@ module Nl
|
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
class Family
|
|
29
|
-
DEFAULT_NOTIFICATION_CAPACITY:
|
|
29
|
+
DEFAULT_NOTIFICATION_CAPACITY: Integer
|
|
30
30
|
|
|
31
|
+
# Socket-owning family.
|
|
32
|
+
#
|
|
33
|
+
# {Family} instances that owns sockets are extended with this module.
|
|
31
34
|
module Session
|
|
32
|
-
|
|
35
|
+
# Closes the Netlink socket owned by this {Family}.
|
|
36
|
+
# @rbs () -> void
|
|
37
|
+
def close: () -> void
|
|
33
38
|
end
|
|
34
39
|
|
|
35
|
-
#
|
|
36
|
-
# @rbs connection: _Connection
|
|
37
|
-
# @rbs endpoint: Raw::Endpoint
|
|
38
|
-
# @rbs return: instance
|
|
40
|
+
# @rbs (_Connection connection, endpoint: Raw::Endpoint) -> instance
|
|
39
41
|
def initialize: (_Connection connection, endpoint: Raw::Endpoint) -> instance
|
|
40
42
|
|
|
41
43
|
private def exchange_message: (untyped kind, untyped request_class, untyped reply_class, untyped args) ?{ (?) -> untyped } -> untyped
|
|
42
44
|
|
|
45
|
+
# Returns if this family supports asynchronous operations.
|
|
46
|
+
#
|
|
47
|
+
# @rbs () -> bool
|
|
43
48
|
def async_capable?: () -> bool
|
|
44
49
|
|
|
45
|
-
# Adds multicast memberships to the
|
|
46
|
-
#
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
#
|
|
56
|
-
#
|
|
57
|
-
#
|
|
58
|
-
# @rbs
|
|
59
|
-
|
|
60
|
-
|
|
50
|
+
# Adds multicast memberships to the netlink socket.
|
|
51
|
+
#
|
|
52
|
+
# Membership is additive and remains active until explicitly removed or the owner closes.
|
|
53
|
+
#
|
|
54
|
+
# @param [Array<Symbol>] groups
|
|
55
|
+
# @return [Family] self
|
|
56
|
+
# @rbs (Symbol *groups) -> self
|
|
57
|
+
def subscribe:
|
|
58
|
+
|
|
59
|
+
# Removes multicast memberships from the netlink socket.
|
|
60
|
+
#
|
|
61
|
+
# @param [Array<Symbol>] groups
|
|
62
|
+
# @return [Family] self
|
|
63
|
+
# @rbs (Symbol *groups) -> self
|
|
64
|
+
def unsubscribe:
|
|
65
|
+
|
|
66
|
+
# Receives the next unsolicited message.
|
|
67
|
+
#
|
|
68
|
+
# @rbs (?timeout: Integer?) -> Message
|
|
69
|
+
def receive_notification: (?timeout: Integer?) -> Message
|
|
70
|
+
|
|
71
|
+
# Receives unsolicited messages.
|
|
72
|
+
#
|
|
73
|
+
# @rbs () { (Message) -> void } -> void
|
|
74
|
+
def each_notification: () { (Message) -> void } -> void
|
|
75
|
+
|
|
76
|
+
# Builds a asynchronous-operation facade.
|
|
77
|
+
#
|
|
78
|
+
# @rbs (Class operations_class, ?stream_capacity: Integer?) -> untyped
|
|
61
79
|
private def build_async_facade: (Class operations_class, ?stream_capacity: Integer?) -> untyped
|
|
62
80
|
|
|
63
81
|
private def exchange_message_async: (untyped kind, untyped request_class, untyped reply_class, untyped args, ?stream_capacity: untyped) -> untyped
|
data/sig/generated/nl/socket.rbs
CHANGED
|
@@ -4,10 +4,12 @@ module Nl
|
|
|
4
4
|
# Netlink socket
|
|
5
5
|
class Socket < ::Socket
|
|
6
6
|
module Constants
|
|
7
|
-
# From
|
|
7
|
+
# From linux/socket.h
|
|
8
|
+
# -
|
|
8
9
|
PF_NETLINK: untyped
|
|
9
10
|
|
|
10
|
-
# From
|
|
11
|
+
# From linux/netlink.h
|
|
12
|
+
# -
|
|
11
13
|
SOL_NETLINK: ::Integer
|
|
12
14
|
|
|
13
15
|
NETLINK_ADD_MEMBERSHIP: ::Integer
|
|
@@ -17,24 +19,41 @@ module Nl
|
|
|
17
19
|
|
|
18
20
|
include Constants
|
|
19
21
|
|
|
20
|
-
|
|
22
|
+
# Packs Netlink socket address
|
|
23
|
+
#
|
|
24
|
+
# @rbs (Integer pid, Integer groups) -> String
|
|
25
|
+
def self.pack_sockaddr_nl: (Integer pid, Integer groups) -> String
|
|
21
26
|
|
|
22
27
|
alias self.sockaddr_nl self.pack_sockaddr_nl
|
|
23
28
|
|
|
24
|
-
|
|
29
|
+
# Unpacks Netlink socket address
|
|
30
|
+
#
|
|
31
|
+
# @rbs (String) -> [Integer, Integer]
|
|
32
|
+
def self.unpack_sockaddr_nl: (String) -> [ Integer, Integer ]
|
|
25
33
|
|
|
26
|
-
# @param
|
|
27
|
-
|
|
34
|
+
# @param [Integer] protonum Netlink protocol number
|
|
35
|
+
# @rbs (Integer) -> void
|
|
36
|
+
def initialize: (Integer) -> void
|
|
28
37
|
|
|
29
|
-
|
|
38
|
+
# Opens a Netlink socket for the specified protocol number.
|
|
39
|
+
#
|
|
40
|
+
# @rbs (Integer protonum) -> instance
|
|
41
|
+
# | [R] (Integer protonum) { (instance) -> R } -> R
|
|
42
|
+
def self.open: (Integer protonum) -> instance
|
|
43
|
+
| [R] (Integer protonum) { (instance) -> R } -> R
|
|
30
44
|
|
|
31
45
|
# @return [Integer] Local Netlink port ID assigned to this socket
|
|
32
|
-
|
|
46
|
+
# @rbs () -> Integer
|
|
47
|
+
def local_port_id: () -> Integer
|
|
33
48
|
|
|
34
49
|
# Adds this socket to a Netlink multicast group.
|
|
35
|
-
|
|
50
|
+
#
|
|
51
|
+
# @rbs (Integer group_id) -> void
|
|
52
|
+
def add_membership: (Integer group_id) -> void
|
|
36
53
|
|
|
37
54
|
# Removes this socket from a Netlink multicast group.
|
|
38
|
-
|
|
55
|
+
#
|
|
56
|
+
# @rbs (Integer group_id) -> void
|
|
57
|
+
def drop_membership: (Integer group_id) -> void
|
|
39
58
|
end
|
|
40
59
|
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.
|
|
4
|
+
version: 0.4.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Kasumi Hanazuki
|
|
@@ -93,7 +93,7 @@ licenses:
|
|
|
93
93
|
- MIT
|
|
94
94
|
metadata:
|
|
95
95
|
homepage_uri: https://github.com/hanazuki/nl
|
|
96
|
-
source_code_uri: https://github.com/hanazuki/nl/tree/v0.4.
|
|
96
|
+
source_code_uri: https://github.com/hanazuki/nl/tree/v0.4.2
|
|
97
97
|
changelog_uri: https://github.com/hanazuki/nl/blob/master/CHANGELOG.md
|
|
98
98
|
rdoc_options: []
|
|
99
99
|
require_paths:
|