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