Decode cacheinfo structure

Julien LepillerSun Mar 14 03:48:57+0100 2021

ce20112

Decode cacheinfo structure

ip/addr.scm

201201
     (when cacheinfo
202202
       (if (member 'IFA_F_PERMANENT flags)
203203
           (format #t "        valid_lft forever preferred_lft forever~%")
204-
           (format #t "        valid_lft ??sec preferred_lft ??sec~%"))))))
204+
           (format #t "        valid_lft ~asec preferred_lft ~asec~%"
205+
                   (route-cache-info-attr-type-valid cacheinfo)
206+
                   (route-cache-info-attr-type-prefered cacheinfo)))))))
205207
206208
207209
(define* (addr-show #:optional (device #f))

netlink/route/attrs.scm

2828
           route-attr-kind
2929
           route-attr-data
3030
           route-attr-size
31+
           make-route-cache-info-attr
32+
           route-cache-info-attr?
33+
           route-cache-info-attr-prefered
34+
           route-cache-info-attr-valid
35+
           route-cache-info-attr-cstamp
36+
           route-cache-info-attr-tstamp
37+
           route-cache-info-attr-type-prefered
38+
           route-cache-info-attr-type-valid
39+
           route-cache-info-attr-type-cstamp
40+
           route-cache-info-attr-type-tstamp
3141
           make-u8-route-attr
3242
           make-u16-route-attr
3343
           make-u32-route-attr

3747
           make-ethernet-route-attr
3848
           make-ipv4-route-attr
3949
           make-ipv6-route-attr
50+
           make-addr-cache-info-attr
4051
           make-bv-route-attr
4152
           deserialize-route-attr
4253
           deserialize-route-attr-data-u8

4859
           deserialize-route-attr-data-ethernet
4960
           deserialize-route-attr-data-ipv4
5061
           deserialize-route-attr-data-ipv6
62+
           deserialize-route-attr-data-route-cache-info
5163
           deserialize-route-attr-data-bv
5264
           %default-route-addr-ipv4-attr-decoder
5365
           %default-route-addr-ipv6-attr-decoder

7991
(define (attr-type-size attr)
8092
  (+ 4 (data-size (route-attr-type-data attr))))
8193
94+
(define-data-type route-cache-info-attr
95+
  (const 16)
96+
  (lambda (attr pos bv)
97+
    (match attr
98+
      (($ route-cache-info-attr-type prefered valid cstamp tstamp)
99+
       (bytevector-u32-set! bv pos prefered (native-endianness))
100+
       (bytevector-u32-set! bv (+ pos 4) valid (native-endianness))
101+
       (bytevector-u32-set! bv (+ pos 8) cstamp (native-endianness))
102+
       (bytevector-u32-set! bv (+ pos 12) tstamp (native-endianness)))))
103+
  (prefered route-cache-info-attr-prefered route-cache-info-attr-type-prefered)
104+
  (valid route-cache-info-attr-valid route-cache-info-attr-type-valid)
105+
  (cstamp route-cache-info-attr-cstamp route-cache-info-attr-type-cstamp)
106+
  (tstamp route-cache-info-attr-tstamp route-cache-info-attr-type-tstamp))
107+
82108
(define (make-u8-route-attr num)
83109
  (make-nl-data
84110
    num

231257
  (make-ipv6-route-attr
232258
    (inet-ntop AF_INET6 (ipv6->number bv))))
233259
260+
(define (deserialize-route-attr-data-route-cache-info decoder bv pos)
261+
  (make-route-cache-info-attr
262+
    (bytevector-u32-ref bv pos (native-endianness))
263+
    (bytevector-u32-ref bv (+ pos 4) (native-endianness))
264+
    (bytevector-u32-ref bv (+ pos 8) (native-endianness))
265+
    (bytevector-u32-ref bv (+ pos 12) (native-endianness))))
266+
234267
(define %default-route-link-attr-decoder
235268
  `((,IFLA_ADDRESS . ,deserialize-route-attr-data-ethernet)
236269
    (,IFLA_BROADCAST . ,deserialize-route-attr-data-ethernet)

258291
    (,IFA_BROADCAST . ,address-decoder)
259292
    (,IFA_ANYCAST . ,address-decoder)
260293
    (,IFA_FLAGS . ,deserialize-route-attr-data-u32)
261-
    ;; TODO: struct ifa_cacheinfo
262-
    ;(,IFA_CACHEINFO . ,deserialize-route-attr-data-cache-info)
294+
    (,IFA_CACHEINFO . ,deserialize-route-attr-data-route-cache-info)
263295
    (default . ,deserialize-route-attr-data-bv)))
264296
265297
(define (default-route-route-attr-decoder address-decoder)