ip: Move cidr utils to utils.scm

Julien LepillerSun Mar 14 15:57:10+0100 2021

d99b1a4

ip: Move cidr utils to utils.scm

ip/addr.scm

4545
  (brd       addr-brd)
4646
  (cacheinfo addr-cacheinfo))
4747
48-
(define (cidr->addr str)
49-
  (match (string-split str #\/)
50-
    ((addr) addr)
51-
    ((addr prefix) addr)
52-
    (_ (throw 'incorrect-cidr-notation str))))
53-
54-
(define (cidr->prefix str)
55-
  (match (string-split str #\/)
56-
    ((addr) #f)
57-
    ((addr prefix) (string->number prefix))
58-
    (_ (throw 'incorrect-cidr-notation str))))
59-
6048
(define* (addr-del device cidr #:key (ipv6? #f))
6149
  (define request-num (random 65535))
6250
  (define prefix (cidr->prefix cidr))

ip/utils.scm

2424
  #:use-module (netlink standard)
2525
  #:export (answer-ok?
2626
            get-attr
27-
            split-flags))
27+
            split-flags
28+
            cidr->addr
29+
            cidr->prefix))
2830
2931
(define (answer-ok? answer)
3032
  (cond

5961
      (else
6062
        (loop (/ max-flag 2) (- flags max-flag)
6163
              (cons max-flag result))))))
64+
65+
(define (cidr->addr str)
66+
  (match (string-split str #\/)
67+
    ((addr) addr)
68+
    ((addr prefix) addr)
69+
    (_ (throw 'incorrect-cidr-notation str))))
70+
71+
(define (cidr->prefix str)
72+
  (match (string-split str #\/)
73+
    ((addr) #f)
74+
    ((addr prefix) (string->number prefix))
75+
    (_ (throw 'incorrect-cidr-notation str))))