Merge attr list deserializing
netlink/route/addr.scm
| 64 | 64 | (bytevector-u8-ref bv (+ pos 2)) | |
| 65 | 65 | (bytevector-u8-ref bv (+ pos 3)) | |
| 66 | 66 | (bytevector-u32-ref bv (+ pos 4) (native-endianness)) | |
| 67 | - | (let ((len (bytevector-length bv))) | |
| 68 | - | (let loop ((pos (+ pos 8)) (attrs '())) | |
| 69 | - | (if (>= pos len) | |
| 70 | - | attrs | |
| 71 | - | (let ((attr (deserialize (cond | |
| 72 | - | ((equal? family AF_INET) 'ipv4-addr-attr) | |
| 73 | - | ((equal? family AF_INET6) 'ipv6-addr-attr) | |
| 74 | - | (else (throw 'unknown-family family))) | |
| 75 | - | decoder bv pos))) | |
| 76 | - | (loop (+ pos (align (data-size attr) 4)) | |
| 77 | - | (cons attr attrs))))))))) | |
| 67 | + | (deserialize-attr-list | |
| 68 | + | (cond | |
| 69 | + | ((equal? family AF_INET) 'ipv4-addr-attr) | |
| 70 | + | ((equal? family AF_INET6) 'ipv6-addr-attr) | |
| 71 | + | (else (throw 'unknown-family family))) | |
| 72 | + | decoder bv (+ pos 8))))) |
netlink/route/attrs.scm
| 19 | 19 | #:use-module (ice-9 match) | |
| 20 | 20 | #:use-module (netlink constant) | |
| 21 | 21 | #:use-module (netlink data) | |
| 22 | + | #:use-module (netlink route) | |
| 22 | 23 | #:use-module (rnrs bytevectors) | |
| 23 | 24 | #:use-module (srfi srfi-9) | |
| 24 | - | #:export(make-route-attr | |
| 25 | + | #:export(deserialize-attr-list | |
| 26 | + | make-route-attr | |
| 25 | 27 | route-attr? | |
| 26 | 28 | route-attr-kind | |
| 27 | 29 | route-attr-data | |
… | |||
| 51 | 53 | %default-route-route-ipv4-attr-decoder | |
| 52 | 54 | %default-route-route-ipv6-attr-decoder)) | |
| 53 | 55 | ||
| 56 | + | (define (deserialize-attr-list context decoder bv pos) | |
| 57 | + | (let ((len (bytevector-length bv))) | |
| 58 | + | (let loop ((pos pos) (attrs '())) | |
| 59 | + | (if (>= pos len) | |
| 60 | + | attrs | |
| 61 | + | (let ((attr (deserialize context decoder bv pos))) | |
| 62 | + | (loop (+ pos (align (data-size attr) 4)) | |
| 63 | + | (cons attr attrs))))))) | |
| 64 | + | ||
| 54 | 65 | (define-data-type route-attr | |
| 55 | 66 | attr-type-size | |
| 56 | 67 | (lambda (attr pos bv) | |
netlink/route/link.scm
| 62 | 62 | (bytevector-u32-ref bv (+ pos 4) (native-endianness)) | |
| 63 | 63 | (bytevector-u32-ref bv (+ pos 8) (native-endianness)) | |
| 64 | 64 | (bytevector-u32-ref bv (+ pos 12) (native-endianness)) | |
| 65 | - | (let ((len (bytevector-length bv))) | |
| 66 | - | (let loop ((pos (+ pos 16)) (attrs '())) | |
| 67 | - | (if (>= pos len) | |
| 68 | - | attrs | |
| 69 | - | (let ((attr (deserialize 'link-attr decoder bv pos))) | |
| 70 | - | (loop (+ pos (align (data-size attr) 4)) | |
| 71 | - | (cons attr attrs)))))))) | |
| 65 | + | (deserialize-attr-list 'link-attr decoder bv (+ pos 16)))) |
netlink/route/route.scm
| 81 | 81 | (bytevector-u8-ref bv (+ pos 6)) | |
| 82 | 82 | (bytevector-u8-ref bv (+ pos 7)) | |
| 83 | 83 | (bytevector-u32-ref bv (+ pos 8) (native-endianness)) | |
| 84 | - | (let ((len (bytevector-length bv))) | |
| 85 | - | (let loop ((pos (+ pos 12)) (attrs '())) | |
| 86 | - | (if (>= pos len) | |
| 87 | - | attrs | |
| 88 | - | (let ((attr (deserialize (cond | |
| 89 | - | ((equal? family AF_INET) 'ipv4-route-attr) | |
| 90 | - | ((equal? family AF_INET6) 'ipv6-route-attr) | |
| 91 | - | (else (throw 'unknown-family family))) | |
| 92 | - | decoder bv pos))) | |
| 93 | - | (loop (+ pos (align (data-size attr) 4)) | |
| 94 | - | (cons attr attrs))))))))) | |
| 84 | + | (deserialize-attr-list | |
| 85 | + | (cond | |
| 86 | + | ((equal? family AF_INET) 'ipv4-route-attr) | |
| 87 | + | ((equal? family AF_INET6) 'ipv6-route-attr) | |
| 88 | + | (else (throw 'unknown-family family))) | |
| 89 | + | decoder bv (+ pos 12))))) |