Ensure decoding address of the correct type.
doc/guile-netlink.texi
175 | 175 | associating each of them to a deserialization procedure. | |
176 | 176 | @end deffn | |
177 | 177 | ||
178 | - | @deffn {Scheme Variable} %default-route-attr-decoder | |
179 | - | Contains the default association list for the known types of routing attributes. | |
180 | - | This list is defined in @code{(netlink route attrs)}. | |
178 | + | @deffn {Scheme Procedure} default-route-attr-decoder @var{deserialize-addr} | |
179 | + | Creates the default association list for a route protocol, given the specified | |
180 | + | address deserializer. This is useful because the @code{IFA_ADDRESS}, | |
181 | + | @code{IFA_BROADCAST}, etc, contain a different type of address depending on | |
182 | + | the message type or its header. This is defined an @code{(netlink route attrs)} | |
183 | + | and used by the following variables: | |
184 | + | @end deffn | |
185 | + | ||
186 | + | @deffn {Scheme Variable} %default-route-link-attr-decoder | |
187 | + | Contains the default association list for the known types of routing attributes | |
188 | + | for link messages. This list is defined in @code{(netlink route attrs)}. | |
181 | 189 | @end deffn | |
182 | 190 | ||
183 | 191 | @node Constants |
netlink/deserialize.scm
37 | 37 | (,RTM_DELLINK . ,route:deserialize-link-message) | |
38 | 38 | (,RTM_GETLINK . ,route:deserialize-link-message) | |
39 | 39 | (,RTM_SETLINK . ,route:deserialize-link-message)) | |
40 | - | (attr ,route:deserialize-route-attr | |
41 | - | ,@route:%default-route-attr-decoder))) | |
40 | + | (link-attr ,(route:deserialize-route-attr 'link-attr) | |
41 | + | ,@route:%default-route-link-attr-decoder))) |
netlink/route/attrs.scm
40 | 40 | deserialize-route-attr-data-s32 | |
41 | 41 | deserialize-route-attr-data-ethernet | |
42 | 42 | deserialize-route-attr-data-bv | |
43 | - | %default-route-attr-decoder)) | |
43 | + | default-route-attr-decoder | |
44 | + | %default-route-link-attr-decoder)) | |
44 | 45 | ||
45 | 46 | (define-data-type route-attr | |
46 | 47 | attr-type-size | |
… | |||
110 | 111 | (lambda (data pos bv) | |
111 | 112 | (bytevector-copy! data 0 bv pos (bytevector-length data))))) | |
112 | 113 | ||
113 | - | (define (deserialize-route-attr decoder bv pos) | |
114 | - | (let* ((len (bytevector-u16-ref bv pos (native-endianness))) | |
115 | - | (type (bytevector-u16-ref bv (+ pos 2) (native-endianness))) | |
116 | - | (deserialize (get-next-deserialize decoder 'attr type)) | |
117 | - | (data-bv (make-bytevector (- len 4)))) | |
118 | - | (bytevector-copy! bv (+ pos 4) data-bv 0 (- len 4)) | |
119 | - | (make-route-attr | |
120 | - | type | |
121 | - | (deserialize decoder data-bv 0)))) | |
114 | + | (define (deserialize-route-attr message-type) | |
115 | + | (lambda (decoder bv pos) | |
116 | + | (let* ((len (bytevector-u16-ref bv pos (native-endianness))) | |
117 | + | (type (bytevector-u16-ref bv (+ pos 2) (native-endianness))) | |
118 | + | (deserialize (get-next-deserialize decoder message-type type)) | |
119 | + | (data-bv (make-bytevector (- len 4)))) | |
120 | + | (bytevector-copy! bv (+ pos 4) data-bv 0 (- len 4)) | |
121 | + | (make-route-attr | |
122 | + | type | |
123 | + | (deserialize decoder data-bv 0))))) | |
122 | 124 | ||
123 | 125 | (define (deserialize-route-attr-data-string decoder bv pos) | |
124 | 126 | (make-string-route-attr (utf8->string bv))) | |
… | |||
141 | 143 | (bytevector->u8-list bv)) | |
142 | 144 | ":"))) | |
143 | 145 | ||
144 | - | (define %default-route-attr-decoder | |
146 | + | (define %default-route-link-attr-decoder | |
147 | + | (default-route-attr-decoder deserialize-route-attr-data-ethernet)) | |
148 | + | ||
149 | + | (define (default-route-attr-decoder deserialize-addr) | |
145 | 150 | `((,IFLA_IFNAME . ,deserialize-route-attr-data-string) | |
146 | 151 | (,IFLA_QDISC . ,deserialize-route-attr-data-string) | |
147 | 152 | (,IFLA_IFALIAS . ,deserialize-route-attr-data-string) | |
… | |||
170 | 175 | (,IFLA_LINKMODE . ,deserialize-route-attr-data-u8) | |
171 | 176 | (,IFLA_CARRIER . ,deserialize-route-attr-data-u8) | |
172 | 177 | (,IFLA_PROTO_DOWN . ,deserialize-route-attr-data-u8) | |
173 | - | (,IFLA_ADDRESS . ,deserialize-route-attr-data-ethernet) | |
174 | - | (,IFLA_BROADCAST . ,deserialize-route-attr-data-ethernet) | |
175 | - | (,IFLA_PERM_ADDRESS . ,deserialize-route-attr-data-ethernet) | |
178 | + | (,IFLA_ADDRESS . ,deserialize-addr) | |
179 | + | (,IFLA_BROADCAST . ,deserialize-addr) | |
180 | + | (,IFLA_PERM_ADDRESS . ,deserialize-addr) | |
176 | 181 | (default . ,deserialize-route-attr-data-bv))) |
netlink/route/link.scm
65 | 65 | (let loop ((pos (+ pos 16)) (attrs '())) | |
66 | 66 | (if (>= pos len) | |
67 | 67 | attrs | |
68 | - | (let ((attr (deserialize 'attr decoder bv pos))) | |
68 | + | (let ((attr (deserialize 'link-attr decoder bv pos))) | |
69 | 69 | (loop (+ pos (align (data-size attr) 4)) | |
70 | 70 | (cons attr attrs)))))))) |