guile-netlink/netlink/deserialize.scm

deserialize.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 deserialize)
19
  #:use-module (netlink constant)
20
  #:use-module ((netlink route addr) #:prefix route:)
21
  #:use-module ((netlink route attrs) #:prefix route:)
22
  #:use-module ((netlink route link) #:prefix route:)
23
  #:use-module (netlink standard)
24
  #:use-module (netlink message)
25
  #:export (%default-message-decoder
26
            %default-route-decoder))
27
28
(define %default-message-decoder
29
  `((,NLMSG_NOOP . ,deserialize-no-data)
30
    (,NLMSG_ERROR . ,deserialize-error-message)
31
    (,NLMSG_DONE . ,deserialize-no-data)))
32
33
;; for RTNETLINK
34
(define %default-route-decoder
35
  `((message ,deserialize-message
36
      ,@%default-message-decoder
37
      (,RTM_NEWLINK . ,route:deserialize-link-message)
38
      (,RTM_DELLINK . ,route:deserialize-link-message)
39
      (,RTM_GETLINK . ,route:deserialize-link-message)
40
      (,RTM_SETLINK . ,route:deserialize-link-message)
41
      (,RTM_NEWADDR . ,route:deserialize-addr-message)
42
      (,RTM_DELADDR . ,route:deserialize-addr-message)
43
      (,RTM_GETADDR . ,route:deserialize-addr-message))
44
    (message-hdr ,deserialize-message-header '())
45
    (link-attr ,(route:deserialize-route-attr 'link-attr)
46
               ,@route:%default-route-link-attr-decoder)
47
    (ipv4-attr ,(route:deserialize-route-attr 'ipv4-attr)
48
               ,@route:%default-route-ipv4-attr-decoder)
49
    (ipv6-attr ,(route:deserialize-route-attr 'ipv6-attr)
50
               ,@route:%default-route-ipv6-attr-decoder)))
51