Move align to a common module.

Julien LepillerMon Feb 01 22:49:00+0100 2021

f8e7ad6

Move align to a common module.

Makefile.am

77
  netlink/message.scm \
88
  netlink/standard.scm \
99
  netlink/deserialize.scm \
10+
  netlink/route.scm \
1011
  netlink/route/addr.scm \
1112
  netlink/route/attrs.scm \
1213
  netlink/route/link.scm \

netlink/route.scm unknown status 1

1+
;;;; Copyright (C) 2021 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)
19+
  #:export (align))
20+
21+
(define (align pos to)
22+
  (+ pos -1 (- to (modulo (- pos 1) to))))

netlink/route/addr.scm

1818
(define-module (netlink route addr)
1919
  #:use-module (ice-9 match)
2020
  #:use-module (netlink data)
21+
  #:use-module (netlink route)
2122
  #:use-module (netlink route attrs)
2223
  #:use-module (srfi srfi-9)
2324
  #:use-module (rnrs bytevectors)

3132
            addr-message-attrs
3233
            deserialize-addr-message))
3334
34-
(define (align pos to)
35-
  (+ pos -1 (- to (modulo (- pos 1) to))))
36-
3735
(define-data-type addr-message
3836
  (lambda (msg)
3937
    (+ 8 (apply + (map (lambda (d) (align (data-size d) 4)) attrs))))

netlink/route/link.scm

1818
(define-module (netlink route link)
1919
  #:use-module (ice-9 match)
2020
  #:use-module (netlink data)
21+
  #:use-module (netlink route)
2122
  #:use-module (netlink route attrs)
2223
  #:use-module (srfi srfi-9)
2324
  #:use-module (rnrs bytevectors)

3031
            link-message-attrs
3132
            deserialize-link-message))
3233
33-
(define (align pos to)
34-
  (+ pos -1 (- to (modulo (- pos 1) to))))
35-
3634
(define-data-type link-message
3735
  (lambda (msg)
3836
    (+ 16 (apply + (map (lambda (d) (align (data-size d) 4)) attrs))))

netlink/route/route.scm

1818
(define-module (netlink route route)
1919
  #:use-module (ice-9 match)
2020
  #:use-module (netlink data)
21+
  #:use-module (netlink route)
2122
  #:use-module (netlink route attrs)
2223
  #:use-module (srfi srfi-9)
2324
  #:use-module (rnrs bytevectors)

3536
            route-message-attrs
3637
            deserialize-route-message))
3738
38-
(define (align pos to)
39-
  (+ pos -1 (- to (modulo (- pos 1) to))))
40-
4139
(define-data-type route-message
4240
  (lambda (msg)
4341
    (+ 12 (apply + (map (lambda (d) (align (data-size d) 4)) attrs))))