deserialize.scm
| 1 | ;;;; This file is part of Guile Netlink |
| 2 | ;;;; |
| 3 | ;;;; Copyright (C) 2020 Julien Lepiller <julien@lepiller.eu> |
| 4 | ;;;; |
| 5 | ;;;; This library is free software: you can redistribute it and/or modify |
| 6 | ;;;; it under the terms of the GNU General Public License as published by |
| 7 | ;;;; the Free Software Foundation, either version 3 of the License, or |
| 8 | ;;;; (at your option) any later version. |
| 9 | ;;;; |
| 10 | ;;;; This library is distributed in the hope that it will be useful, |
| 11 | ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | ;;;; GNU General Public License for more details. |
| 14 | ;;;; |
| 15 | ;;;; You should have received a copy of the GNU General Public License |
| 16 | ;;;; along with this library. If not, see <https://www.gnu.org/licenses/>. |
| 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 | (linkinfo-attr ,(route:deserialize-route-attr 'linkinfo-attr) |
| 60 | ,@route:%default-route-link-info-attr-decoder))) |
| 61 |