guile-netlink/netlink/route/link.scm

link.scm

1
;;;; Copyright (C) 2020 Julien Lepiller <julien@lepiller.eu>
2
;;;; 
3
;;;; This library is free software; you can redistribute it and/or
4
;;;; modify it under the terms of the GNU Lesser General Public
5
;;;; License as published by the Free Software Foundation; either
6
;;;; version 3 of the License, or (at your option) any later version.
7
;;;; 
8
;;;; This library is distributed in the hope that it will be useful,
9
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
10
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11
;;;; Lesser General Public License for more details.
12
;;;; 
13
;;;; You should have received a copy of the GNU Lesser General Public
14
;;;; License along with this library; if not, write to the Free Software
15
;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
;;;; 
17
18
(define-module (netlink route link)
19
  #:use-module (ice-9 match)
20
  #:use-module (netlink data)
21
  #:use-module (netlink route)
22
  #:use-module (netlink route attrs)
23
  #:use-module (srfi srfi-9)
24
  #:use-module (rnrs bytevectors)
25
  #:export (make-link-message
26
            link-message?
27
            link-message-family
28
            link-message-kind
29
            link-message-index
30
            link-message-flags
31
            link-message-attrs
32
            deserialize-link-message))
33
34
(define-data-type link-message
35
  (lambda (msg)
36
     (+ 16 (route-attr-list-size (link-message-type-attrs msg))))
37
  (lambda (msg pos bv)
38
    (match msg
39
      (($ link-message-type family type index flags change attrs)
40
       (bytevector-u16-set! bv pos family (native-endianness))
41
       (bytevector-u16-set! bv (+ pos 2) type (native-endianness))
42
       (bytevector-u32-set! bv (+ pos 4) index (native-endianness))
43
       (bytevector-u32-set! bv (+ pos 8) flags (native-endianness))
44
       (bytevector-u32-set! bv (+ pos 12) change (native-endianness))
45
       (serialize-route-attr-list attrs (+ pos 16) bv))))
46
  (family link-message-family link-message-type-family)
47
  (type link-message-kind link-message-type-type)
48
  (index link-message-index link-message-type-index)
49
  (flags link-message-flags link-message-type-flags)
50
  (change link-message-change link-message-type-change)
51
  (attrs link-message-attrs link-message-type-attrs))
52
53
(define (deserialize-link-message decoder bv pos)
54
  (make-link-message
55
    (bytevector-u16-ref bv pos (native-endianness))
56
    (bytevector-u16-ref bv (+ pos 2) (native-endianness))
57
    (bytevector-u32-ref bv (+ pos 4) (native-endianness))
58
    (bytevector-u32-ref bv (+ pos 8) (native-endianness))
59
    (bytevector-u32-ref bv (+ pos 12) (native-endianness))
60
    (deserialize-attr-list 'link-attr decoder bv (+ pos 16))))
61