[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#63516: [PATCH Guile-Netlink 06/11] link: Extract 'new-link-message->
From: |
Ludovic Courtès |
Subject: |
bug#63516: [PATCH Guile-Netlink 06/11] link: Extract 'new-link-message->link'. |
Date: |
Tue, 23 May 2023 14:39:46 +0200 |
* ip/link.scm (new-link-message->link): New procedure.
(get-links): Use it, and use 'filter-map' instead of 'filter' followed
by 'map'.
---
ip/link.scm | 42 ++++++++++++++++++++----------------------
1 file changed, 20 insertions(+), 22 deletions(-)
diff --git a/ip/link.scm b/ip/link.scm
index 814a008..7e0ae6b 100644
--- a/ip/link.scm
+++ b/ip/link.scm
@@ -59,6 +59,25 @@
(addr link-addr)
(brd link-brd))
+(define (new-link-message->link msg)
+ "If MSG has type 'RTM_NEWLINK', return the corresponding <link> object.
+Otherwise return #f."
+ (and (eqv? (message-kind msg) RTM_NEWLINK)
+ (let* ((data (message-data msg))
+ (attrs (link-message-attrs data)))
+ (make-link (get-attr attrs IFLA_IFNAME)
+ (link-message-index data)
+ (link-message-kind data)
+ (map int->device-flags (split-flags (link-message-flags
data)))
+ (get-attr attrs IFLA_MTU)
+ (get-attr attrs IFLA_QDISC)
+ (get-attr attrs IFLA_OPERSTATE)
+ (get-attr attrs IFLA_LINKMODE)
+ (get-attr attrs IFLA_GROUP)
+ (get-attr attrs IFLA_TXQLEN)
+ (get-attr attrs IFLA_ADDRESS)
+ (get-attr attrs IFLA_BROADCAST)))))
+
(define (get-links)
(define request-num (random 65535))
(define message
@@ -72,28 +91,7 @@
(let ((sock (connect-route)))
(send-msg message sock)
(let* ((answer (receive-and-decode-msg sock %default-route-decoder))
- (links (filter
- (lambda (msg) (equal? (message-kind msg) RTM_NEWLINK))
- answer))
- (links
- (map
- (lambda (msg)
- (let* ((data (message-data msg))
- (attrs (link-message-attrs data)))
- (make-link
- (get-attr attrs IFLA_IFNAME)
- (link-message-index data)
- (link-message-kind data)
- (map int->device-flags (split-flags (link-message-flags
data)))
- (get-attr attrs IFLA_MTU)
- (get-attr attrs IFLA_QDISC)
- (get-attr attrs IFLA_OPERSTATE)
- (get-attr attrs IFLA_LINKMODE)
- (get-attr attrs IFLA_GROUP)
- (get-attr attrs IFLA_TXQLEN)
- (get-attr attrs IFLA_ADDRESS)
- (get-attr attrs IFLA_BROADCAST))))
- links)))
+ (links (filter-map new-link-message->link answer)))
(close-port sock)
links)))
--
2.40.1
- bug#63516: [PATCH Guile-Netlink 00/11] Add 'wait-for-link' and related code, (continued)
- bug#63516: [PATCH Guile-Netlink 00/11] Add 'wait-for-link' and related code, Ludovic Courtès, 2023/05/23
- bug#63516: [PATCH Guile-Netlink 07/11] addr: Extract 'new-address-message->address'., Ludovic Courtès, 2023/05/23
- bug#63516: [PATCH Guile-Netlink 04/11] connection: Add support for suspendable sockets., Ludovic Courtès, 2023/05/23
- bug#63516: [PATCH Guile-Netlink 02/11] connection: Use Guile's 'socket' procedure to open a socket., Ludovic Courtès, 2023/05/23
- bug#63516: [PATCH Guile-Netlink 01/11] connection: Remove unused procedure., Ludovic Courtès, 2023/05/23
- bug#63516: [PATCH Guile-Netlink 03/11] connection: Throw upon errors in FFI bindings., Ludovic Courtès, 2023/05/23
- bug#63516: [PATCH Guile-Netlink 08/11] connection: Add 'add-socket-membership'., Ludovic Courtès, 2023/05/23
- bug#63516: [PATCH Guile-Netlink 10/11] doc: Add indexes., Ludovic Courtès, 2023/05/23
- bug#63516: [PATCH Guile-Netlink 09/11] error: Add 'sub-type' field to '&netlink-decoder-error' and use it., Ludovic Courtès, 2023/05/23
- bug#63516: [PATCH Guile-Netlink 11/11] link: Add 'wait-for-link'., Ludovic Courtès, 2023/05/23
- bug#63516: [PATCH Guile-Netlink 06/11] link: Extract 'new-link-message->link'.,
Ludovic Courtès <=
- bug#63516: [PATCH Guile-Netlink 05/11] connection: Allow users to pass extra SOCK_ flags to 'socket'., Ludovic Courtès, 2023/05/23
- bug#63516: [PATCH Guile-Netlink 00/11] Add 'wait-for-link' and related code, Julien Lepiller, 2023/05/23
- bug#63516: [PATCH Guile-Netlink 00/11] Add 'wait-for-link' and related code, Ludovic Courtès, 2023/05/24
- bug#63516: [PATCH Guile-Netlink 00/11] Add 'wait-for-link' and related code, Julien Lepiller, 2023/05/24