ip: Move split-flags to utils and make public
ip/link.scm
56 | 56 | (addr link-addr) | |
57 | 57 | (brd link-brd)) | |
58 | 58 | ||
59 | - | (define (split-flags flags) | |
60 | - | (let loop ((max-flag 262144) (flags flags) (result '())) | |
61 | - | (cond | |
62 | - | ((equal? max-flag 1) | |
63 | - | (if (equal? flags 1) | |
64 | - | (cons (int->device-flags 1) result) | |
65 | - | result)) | |
66 | - | ((< flags max-flag) | |
67 | - | (loop (/ max-flag 2) flags result)) | |
68 | - | (else | |
69 | - | (loop (/ max-flag 2) (- flags max-flag) | |
70 | - | (cons | |
71 | - | (int->device-flags max-flag) | |
72 | - | result)))))) | |
73 | - | ||
74 | 59 | (define (get-links) | |
75 | 60 | (define request-num (random 65535)) | |
76 | 61 | (define message | |
… | |||
96 | 81 | (get-attr attrs IFLA_IFNAME) | |
97 | 82 | (link-message-index data) | |
98 | 83 | (link-message-kind data) | |
99 | - | (split-flags (link-message-flags data)) | |
84 | + | (map int->device-flags (split-flags (link-message-flags data))) | |
100 | 85 | (get-attr attrs IFLA_MTU) | |
101 | 86 | (get-attr attrs IFLA_QDISC) | |
102 | 87 | (get-attr attrs IFLA_OPERSTATE) |
ip/utils.scm
1 | 1 | ;;;; Copyright (C) 2021 Julien Lepiller <julien@lepiller.eu> | |
2 | - | ;;;; | |
2 | + | ;;;; | |
3 | 3 | ;;;; This library is free software; you can redistribute it and/or | |
4 | 4 | ;;;; modify it under the terms of the GNU Lesser General Public | |
5 | 5 | ;;;; License as published by the Free Software Foundation; either | |
6 | 6 | ;;;; version 3 of the License, or (at your option) any later version. | |
7 | - | ;;;; | |
7 | + | ;;;; | |
8 | 8 | ;;;; This library is distributed in the hope that it will be useful, | |
9 | 9 | ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | 10 | ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
11 | 11 | ;;;; Lesser General Public License for more details. | |
12 | - | ;;;; | |
12 | + | ;;;; | |
13 | 13 | ;;;; You should have received a copy of the GNU Lesser General Public | |
14 | 14 | ;;;; License along with this library; if not, write to the Free Software | |
15 | 15 | ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
16 | - | ;;;; | |
16 | + | ;;;; | |
17 | 17 | ||
18 | 18 | (define-module (ip utils) | |
19 | 19 | #:use-module (ice-9 match) | |
… | |||
23 | 23 | #:use-module (netlink route attrs) | |
24 | 24 | #:use-module (netlink standard) | |
25 | 25 | #:export (answer-ok? | |
26 | - | get-attr)) | |
26 | + | get-attr | |
27 | + | split-flags)) | |
27 | 28 | ||
28 | 29 | (define (answer-ok? answer) | |
29 | 30 | (cond | |
… | |||
45 | 46 | (match attrs | |
46 | 47 | (() #f) | |
47 | 48 | ((attr) (nl-data-data (route-attr-data attr)))))) | |
49 | + | ||
50 | + | (define (split-flags flags) | |
51 | + | (let loop ((max-flag 262144) (flags flags) (result '())) | |
52 | + | (cond | |
53 | + | ((equal? max-flag 1) | |
54 | + | (if (equal? flags 1) | |
55 | + | (cons 1 result) | |
56 | + | result)) | |
57 | + | ((< flags max-flag) | |
58 | + | (loop (/ max-flag 2) flags result)) | |
59 | + | (else | |
60 | + | (loop (/ max-flag 2) (- flags max-flag) | |
61 | + | (cons max-flag result)))))) |