guile-netlink/doc/guile-netlink.texi

guile-netlink.texi

1
\input texinfo
2
@setfilename guile-netlink.info
3
@documentencoding UTF-8
4
@settitle guile-netlink
5
6
@include version.texi
7
8
@copying
9
Copyright @copyright{} 2020 Julien Lepiller
10
11
@quotation
12
Permission is granted to copy, distribute and/or modify this document
13
under the terms of the GNU Free Documentation License, Version 1.3 or
14
any later version published by the Free Software Foundation; with no
15
Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.  A
16
copy of the license is included in the section entitled ``GNU Free
17
Documentation License''.
18
@end quotation
19
@end copying
20
21
@titlepage
22
@end titlepage
23
24
@contents
25
26
@node Top
27
@top guile-netlink
28
29
This document describes guile-netlink version @value{VERSION}, a guile
30
implementation of the netlink protocol.
31
32
@menu
33
* Introduction::           What is netlink?
34
* API Reference::          Description of the library interface.
35
* IP Library::             High-level functions for network devices.
36
37
@detailmenu
38
--- The Detailed Node Listing ---
39
40
API Reference
41
42
* Common API::             Common functions and data types for defining netlink
43
                           protocols.
44
* Netlink API::            Common structures and data types for every protocols.
45
* Rtnetlink API::          The ROUTE_NETLINK protocol.
46
47
IP Library
48
49
* Link::                   Actions on network links.
50
* Addr::                   Actions on network addresses.
51
* Route::                  Actions on network routes.
52
53
@end detailmenu
54
@end menu
55
56
@node Introduction
57
@chapter Introduction
58
59
Netlink is an inter-process communication protocol that can be used for
60
communication between processes, or with the kernel.  It is implemented by
61
Linux.
62
63
Many protocols exist on top of Netlink.  The most famous are used to configure
64
network-related functions in the kernel, such as firewall, route table or
65
IP addresses of interfaces.
66
67
This library implements the low-level bits of the code by providing data
68
structures that are close to their C counterpart, and basic procedures to
69
initiate communication.
70
71
@node API Reference
72
@chapter API Reference
73
74
@node Common API
75
@section Common API
76
77
Guile-netlink implements a common API for expressing other protocols.  This
78
section describes how to use this API to augment guile-netlink with additional
79
protocols.
80
81
@node Data Types
82
@subsection Data Types
83
84
Guile-netlink defines data types that are used in the various Netlink protocols.
85
We need to be able to serialize and deserialize data that guile-netlink
86
understands, but we also want to let users of guile-netlink extend this process
87
easily.  This need has lead to the creating of the following data structure,
88
defined in @code{(netlink data}).
89
90
@deffn {Datatype} nl-data
91
92
@table @asis
93
@item @code{data}
94
The data that is held by this record.
95
96
@item @code{size-proc}
97
A procedure that takes a data (of the same type as the data recorded in the
98
@code{data} field) and returns the size of its serialization.
99
100
@item @code{serialization-proc}
101
A procedure that takes a data (of the same type as the data recorded in the
102
@code{data} field), the position at which to start serializing, and a
103
bytevector in which to serialize.  This procedure should modify the bytevector
104
and its return value is ignored.
105
106
@end table
107
@end deffn
108
109
The module also defines the following function, that takes a @code{nl-data}
110
structure and provides its serialization in a bytevector:
111
112
@deffn {Scheme Procedure} serialize @var{data} @var{pos} @var{bv}
113
Takes a @code{nl-data} structure as @var{data}, a position @var{pos} in
114
the bytevector @var{bv}, and returns an unspecified value.
115
116
This function updates the bytevector and adds the serialization of @var{data}
117
into @var{bv} at @var{pos}.
118
@end deffn
119
120
By providing a @code{nl-data} structure, we defer the knowledge of how to
121
serialize the data to the structure itself, instead of the @code{serialize}
122
function.  This allows for more flexibility and extensibility, as the user
123
of the procedure can pass any kind of data, even if it is not yet supported by
124
guile-netlink.
125
126
Similarly, we need to be able to deserialize netlink answers into a data
127
structure.  To do so, we also defer the knowledge of the datastructure to
128
deserialize to, to a decoder structure that is passed to the deserialization
129
procedure.  @code{(netlink data)} also defines the following procedures to
130
deserialize data:
131
132
@deffn {Scheme Procedure} deserialize @var{type} @var{decoder} @var{bv} @var{pos}
133
Takes a bytevector @var{bv} and starts deserializing the data starting at
134
position @var{pos}.  To do so, it uses the @var{type} variable as the lookup
135
key in the @var{decoder}.  @var{type} is a symbol that represents the type of
136
data to deserialize to.
137
138
The decoder is a structure that associates each known type to its deserializer
139
(a function that takes a decoder, a bytevector and a position and returns some
140
data) and an alist that associates a type (an integer, as returned by the
141
protocol in use) to the proper decoder of that type.
142
@end deffn
143
144
@deffn {Scheme Procedure} get-current-deserialize @var{decoder} @var{current-type}
145
Takes a decoder and a type, and returns the deserialization procedure associated
146
with the type (a symbol) in @var{decoder}.
147
@end deffn
148
149
@deffn {Scheme Procedure} get-next-deserialize @var{decoder} @var{current-type} @
150
    @var{target-type}
151
Takes a decoder, a type (a symbol that represents the type of data being
152
deserialized) and another type (an integer as returned by the protocol), and
153
returns the deserialization procedure needed to continue decoding the data
154
associated with the currently being deserialized data.
155
156
For example, when decoding an answer in the netlink protocol, we first deserialize
157
the header into a @code{message} structure.  That header contains a type field
158
that contains an integer constant representing the type of data of the body.
159
Similarly, when deserializing a routing attribute in the rtnetlink protocol,
160
we first find a header of the attribute that defines an integer constant
161
corresponding to the type of attribute in the body.
162
163
By knowing the context in which the type is declared, this procedure can return
164
the correct deserializing procedure.  For instance, when deserializing a
165
@code{message}, type @code{16} means @code{RTM_NEWLINK} in the rtnetlink
166
protocol, whereas it means @code{IFLA_OPERSTATE} when deserializing a
167
@code{route-attribute}.
168
@end deffn
169
170
guile-netlink provides the following default decoder for the rtnetlink
171
protocol in @code{(netlink deserialize)}:
172
173
@deffn {Scheme Variable} %default-route-decoder
174
Contains the default decoder for the NETLINK_ROUTE protocol.
175
@end deffn
176
177
For convenience, guile-netlink defines the following structures that can be used
178
to create a custom decoder.
179
180
@deffn {Scheme Variable} %default-message-decoder
181
Contains the default association list for the common message types of netlink,
182
associating each of them to a deserialization procedure.
183
@end deffn
184
185
@deffn {Scheme Procedure} default-route-attr-decoder @var{deserialize-addr}
186
Creates the default association list for a route protocol, given the specified
187
address deserializer.  This is useful because the @code{IFA_ADDRESS},
188
@code{IFA_BROADCAST}, etc, contain a different type of address depending on
189
the message type or its header.  This is defined an @code{(netlink route attrs)}
190
and used by the following variables:
191
@end deffn
192
193
@deffn {Scheme Variable} %default-route-link-attr-decoder
194
Contains the default association list for the known types of routing attributes
195
for link messages.  This list is defined in @code{(netlink route attrs)}.
196
@end deffn
197
198
@node Constants
199
@subsection Constants
200
201
Guile-netlink defines constants used by the Netlink protocols in the
202
@code{(netlink constant)} module.  The constants are the ones present in the
203
kernel and are too numerous to list here.  Please see the source for the
204
complete list.
205
206
The module also defines the following macro:
207
208
@deffn {Scheme Macro} define-enum @var{integer->symbol} @var{name-spec} ...
209
This macros defines an enumeration.  @var{integer->symbol} is the name of
210
a procedure that is publicly defined, that takes an integer and returns the
211
associated symbol in the enumeration.
212
213
The macro also publicly defines variables whose names are in @var{name-spec}
214
to an integer.
215
216
A @var{name-spec} is either a single name, and the associated value is 0 for
217
the first @var{name-spec}, or one more than the previous @var{name-spec}.
218
It can also be a pair of a name and an integer, in which case the associated
219
value is that integer.  For instance:
220
221
@example
222
(define-enum get-foo FOO0 FOO1 (FOO10 10) FOO11 FOO12)
223
(get-foo 9) -> #<unspecified>
224
(get-foo 0) -> FOO0
225
FOO11 -> 11
226
@end example
227
@end deffn
228
229
@node Netlink Connections
230
@subsection Netlink Connections
231
232
The @code{(netlink connection)} module defines the following procedures, used
233
to connect and communicate with another process or the kernel using a netlink
234
socket.
235
236
@deffn {Scheme Procedure} get-addr @var{family} @var{pid} @var{groups}
237
Return a bytevector that represents a netlink address.  @var{family}
238
should be @code{AF_NETLINK}, @var{pid} is the PID of the process with which
239
to communicate or 0 for the kernel. @var{groups} is an integer representing
240
the set of broadcast groups to which the connection subscribes.
241
@end deffn
242
243
@deffn {Scheme Procedure} connect @var{proto} @var{addr}
244
Creates a netlink socket for @var{proto} and binds it to @var{addr}.
245
246
@var{proto} is the integer representing the protocol.  For instance, rtnetlink
247
can be selected by usin @code{NETLINK_ROUTE} (defined in
248
@code{(netlink constant)}).
249
250
@var{addr} is a bytevector, as returned by @code{get-addr}.
251
@end deffn
252
253
@deffn {Scheme Procedure} connect-route [#:groups @code{0}]
254
This procedure is a wrapper for @code{connect} that creates a socket for the
255
rtnetlink protocol, binds it to the kernel and returns it.  By passing the
256
optional @var{groups} keyword, you can select broadcast groups to subscribe to.
257
@end deffn
258
259
@deffn {Scheme Procedure} send-msg @var{msg} @var{sock} [#:@var{addr}]
260
Send @var{msg} (it must be of type message, @xref{Netlink Headers}) to
261
@var{addr} using @var{sock}.  If not passed, @var{addr} is the address of
262
the kernel.
263
@end deffn
264
265
@deffn {Scheme Procedure} receive-msg @var{sock} [#:@var{addr}]
266
Receives a message from @var{sock} from @var{addr}.  This procedure is blocking.
267
If not passed, @var{addr} defaults to the address of the kernel.  This
268
procedure returns the message as a bytevector, that you can deserialize with
269
@code{deserialize} (@xref{Data Types})
270
@end deffn
271
272
@deffn {Scheme Procedure} receive-and-decode-msg @var{sock} @var{decoder} @
273
    [#:@var{addr}]
274
Receives one or more messages from @var{sock} from @var{addr}.  this procedure
275
is blocking.  If not passed, @var{addr} defaults to the address of the kernel.
276
This procedure returns a list of messages that were decoded using @var{decoder}.
277
278
When the answer has the @code{NLM_F_MULTI} flag, this procedure decodes the next
279
message, until it receives a @code{NLMSG_DONE} message.  It returns the list
280
of every netlink messages it received, including the @code{NLMSG_DONE}.
281
@end deffn
282
283
@node Netlink API
284
@section Netlink API
285
286
This section introduces the data structures used for all the netlink protocols.
287
First, we introduce the structure of a netlink message, then we present the
288
standard types of netlink messages, that can be used with every protocol.
289
290
@node Netlink Headers
291
@subsection Netlink Headers
292
293
The @code{(netlink message)} module defines the message structure that contains
294
a netlink message.  It is composed of a header and a body, and is the data
295
structure to pass to @code{send-msg} (@xref{Netlink Connections}).
296
297
This module defines the following data structure:
298
299
@deffn {Datatype} message
300
@table @asis
301
@item @code{type}
302
The type of data in the body of the message.  For instance, @code{RTM_GETLINK}.
303
304
@item @code{flags}
305
The set of flags that are set in the header.  For instance,
306
@code{(logior NLM_F_REQUEST NLM_F_DUMP)}.
307
308
@item @code{seq}
309
The sequence number of the message.  If this message is an answer to a request,
310
it must keep the same sequence number.  Otherwise, you must generate a new and
311
unique sequence number, to track the answers.
312
313
@item @code{pid}
314
The PID of the receiving process, or 0 for the kernel.
315
316
@item @code{data}
317
The actual body, as an @code{nl-data} structure.
318
319
@end table
320
@end deffn
321
322
@node Standard Message Types
323
@subsection Standard Message Types
324
325
The @code{(netlink standard)} module defines the set of standard message types
326
and their data type.
327
328
@deffn {Datatype} error-message
329
@table @asis
330
@item @code{err}
331
The error code, as a negative number.
332
333
@item @code{hdr}
334
The message on which this error applies.
335
336
@end table
337
338
@deffn {Scheme Variable} no-data
339
This variable defines the absence of data.  This is useful when a structure
340
is expecting a body part, but the protocol specifically defines that it should
341
not take any data in some cases.  For instance, a @code{NLMSG_NOOP} message
342
takes no data, so the @code{data} field of the message will contain this
343
@code{no-data} value.
344
@end deffn
345
346
@end deffn
347
348
@node Rtnetlink API
349
@section Rtnetlink API
350
@cindex rtnetlink
351
@cindex ROUTE_NETLINK
352
353
This section describes the support for rtnetlink in guile-netlink.  Rtnetlink
354
is the protocol responsible for everything related to network routing.  It
355
allows you to manage links, addresses, routing tables, neighbor chaces,
356
routing rules, queueing disciplines, traffic classes, traffic filters and
357
more.
358
359
@node Routing Attributes
360
@subsection Routing Attributes
361
362
The @code{(netlink route attrs)} module defines the following data types:
363
364
@deffn {Datatype} route-attr
365
This defines a header structure for the attribute, as well as its body.
366
367
@table @asis
368
@item @code{type}
369
This is the type of the attribute, for instance @code{IFLA_ADDRESS}.
370
371
@item @code{data}
372
This is the body of the attribute, ie.@: its value.
373
@end table
374
@end deffn
375
376
The module also defines additional data types that are not represented as
377
a record, but by a simple type.  For each of the following types, there is
378
a @code{make-*-route-attr} procedure to produce a @code{nl-data} value
379
for this type.  There is also @code{deserialize-route-attr-data-*} procedure
380
to deserialize a value of this type.
381
382
@table @asis
383
@item @code{u8}
384
A one-byte unsigned integer
385
@item @code{u16}
386
A two-bytes unsigned integer
387
@item @code{u32}
388
A four-bytes unsigned integer
389
@item @code{s32}
390
A four-bytes signed integer
391
@item @code{string}
392
A string
393
@item @code{ethernet}
394
An ethernet address.  Its value is a string that represents that address,
395
for instnace @code{"01:23:45:67:89:ab"}
396
@item @code{ipv4}
397
An IPv4 address.  Its value is a string that represents that address,
398
for instnace @code{"192.0.2.152"}
399
@item @code{ipv6}
400
An IPv6 address.  Its value is a string that represents that address,
401
for instnace @code{"2001:db8::0123:4567:89ab:cdef"}
402
@item @code{bv}
403
A bytevector.  This is used by default when the type is not supported.
404
@end table
405
406
@node Link Messages
407
@subsection Link Messages
408
409
The @code{(netlink route link)} package defines the following data type:
410
411
@deffn {Datatype} link-message
412
This datatype represents a link message with its routing attributes.  This type
413
of message is expected when using the @var{RTM_*LINK} message types.
414
415
@table @asis
416
@item @code{family}
417
The network family, defined as @code{AF_UNSPEC} in the rtnetlink documentation,
418
although it holds different values in practice.
419
420
@item @code{type}
421
The device type.
422
423
@item @code{index}
424
The index of the device.  This is used to select a specific device by its index,
425
or 0 to not filter by device index.
426
427
@item @code{flags}
428
The device flags.  See @code{man 7 netdevices} for a list.
429
430
@item @code{attrs}
431
A list of attributes.  This field must contain a list of @code{nl-data}
432
structures, not a structure by itself.
433
@end table
434
@end deffn
435
436
@node Address Messages
437
@subsection Address Messages
438
439
The @code{(netlink route addr)} package defines the following data type:
440
441
@deffn {Datatype} addr-message
442
This datatype represents an address message with its routing attributes.  This
443
type of message is expected when using the @var{RTM_*ADDR} message types.
444
445
@table @asis
446
@item @code{family}
447
The network family, either @code{AF_INET} for IPv4 addresses, or @code{AF_INET6}
448
for IPv6 addresses.
449
450
@item @code{prefix-len}
451
The prefix length, i.e.@: the length of the prefix mask, in bits, if defined
452
for the address family.
453
454
@item @code{flags}
455
Address flags.  This can be a flag word of @code{IFA_F_SECONDARY} for secondary
456
address (old alias interface), @code{IFA_F_PERMANENT} for a permanent
457
address set by the user and other undocumented flags.
458
459
@item @code{scope}
460
The address scope.
461
462
@item @code{index}
463
The index of the device this address is for.
464
465
@item @code{attrs}
466
A list of attributes.  This field must contain a list of @code{nl-data}
467
structures, not a structure by itself.
468
@end table
469
@end deffn
470
471
@node IP Library
472
@chapter IP Library
473
474
This library comes with higher-level procedures that let you access and modify
475
the state of network on your computer.
476
477
@node Link
478
@section Link
479
480
The @code{(ip link)} module introduces procedures to access and modify the
481
network links on your machine.  They are equivalent to the @command{ip link}
482
family of commands, from @code{iproute2}.
483
484
@deffn {Datatype} <link>
485
486
Datatype representing the status of a network link.
487
488
get-links                                                           
489
            print-link                                                          
490
                                                                                
491
            <link> make-link link?                                              
492
            link-name link-id link-type link-flags link-mtu link-qdisc          
493
            link-state link-mode link-group link-qlen link-addr link-brd
494
495
@table @asis
496
@item @code{name}
497
Name of the link, such as @code{"enp1s0"}.
498
499
@item @code{id}
500
Index of the link, a unique number used to identify the link.
501
502
@item @code{type}
503
Type of the link, as an integer.
504
505
@item @code{flags}
506
Flags associated with the device, as a list of symbols, such as
507
@code{'(UP LOOPBACK)}.
508
509
@item @code{mtu}
510
MTU of the link, as an integer.
511
512
@item @code{qdisc}
513
Queuing discipline of the link, as a string, such as @code{"noqueue"}.
514
515
@item @code{state}
516
State of the link, as an integer.  Use @code{int->operstate} from
517
@code{(netlink constant)} to get a symbol, such as @code{IF_OPER_UP}.
518
519
@item @code{mode}
520
Mode of the link.  0 means @code{DORMANT}, 1 means @code{DEFAULT}.
521
522
@item @code{group}
523
Identifier of the group it belongs to.  0 for @code{default}.
524
525
@item @code{qlen}
526
Size of the queue.
527
528
@item @code{addr}
529
Ethernet address of the link, as a string.
530
531
@item @code{brd}
532
Broadcast (ethernet) address of the link, as a string.
533
534
@end table
535
@end deffn
536
537
@deffn {Scheme Procedure} get-links
538
Returns the list of existing links in the system, as a list of @code{<link>}
539
objects.
540
@end deffn
541
542
@deffn {Sceme Procedure} print-link @var{link}
543
Display @var{link} on the standard output, using a format similar to
544
@command{ip link} from @code{iproute2}.
545
@end deffn
546
547
@deffn {Scheme Procedure} link-set @var{device} [#:up @code{#f}] @
548
  [#:down @code{#f}] [#:type @code{#f}] [#:arp-on @code{#f}] @
549
  [#:arp-off @code{#f}] [#:dynamic-on @code{#f}] [#:dynamic-off @code{#f}] @
550
  [#:multicast-on @code{#f}] [#:multicast-off @code{#f}] @
551
  [#:allmulticast-on @code{#f}] [#:allmulticast-off @code{#f}] @
552
  [#:promisc-on @code{#f}] [#:promisc-off @code{#f}] [#:trailers-on @code{#f}] @
553
  [#:trailers-off @code{#f}] [#:carrier-on @code{#f}] [#:carrier-off @code{#f}] @
554
  [#:txqueuelen @code{#f}] [#:name @code{#f}] [#:address @code{#f}] @
555
  [#:broadcast @code{#f}] [#:mtu @code{#f}] [#:netns @code{#f}]
556
Modify an existing link and set its flags and attributes to the ones specified
557
by the various keywords.  When a keyword is omited, the corresponding attribute
558
is not changed.
559
560
@var{device} can be a device index (as a number) or a device name (as a string).
561
562
Do not set @code{#:up} and @code{#:down} at the same time.  Do not set
563
@code{*-on} and @code{*-off} at the same time.
564
@end deffn
565
566
@deffn {Scheme Procedure} link-show [#:device @code{#f}] [#:group @code{#f}] @
567
  [#:up @code{#f}] [#:master @code{#f}] [#:vrf @code{#f}] [#:type @code{#f}]
568
Print the set of devices on standard output.  Setting any of the keyword to a
569
non-false value will filter the results to only show results that match the
570
corresponding value.  You may set more than one keyword.
571
@end deffn
572
573
@deffn {Scheme Procedure} link-add @var{name} @var{type} [#:type-args @code{'()}]
574
Add a new link with given name and type.  Additional arguments can be passed to
575
control the state of the link at creation. @var{type-args} is an association
576
list containing additional values for the given type.
577
578
When @var{type} is @code{"vlan"}, @var{type-args} can contain a number associated
579
with @code{'id}: the VLAN id to be created and a link name associated with
580
@code{"link"}: the name of the link on which the vlan is created.
581
582
The following is an example in which we create a new vlan link:
583
@example
584
;; same as "ip l add link eth0 name eth0.7 type vlan id 7"
585
(link-add "eth0.7" "vlan" #:type-args '((id . 7) (link . "eth0")))
586
@end example
587
588
When @var{type} is @code{"veth"}, @var{type-args} can contain a string associated
589
with @code{'peer}: the name of the peer.
590
591
The following is an example in which we create a new veth (virtual ethernet)
592
pair and give them a name:
593
@example
594
;; same as "ip l add v0p0 type veth peer v0p1"
595
(link-add "v0p0" "veth" #:type-args '((peer . "v0p1")))
596
@end example
597
@end deffn
598
599
@deffn {Scheme Procedure} link-del @var{device}
600
Delete a link.  @var{device} can contain the name of the link, as a string,
601
or its index, as a number.
602
@end deffn
603
604
@node Addr
605
@section Addr
606
607
The @code{(ip addr)} module introduces procedures to access and modify the
608
network addresses on your machine.  They are equivalent to the @command{ip addr}
609
family of commands, from @code{iproute2}.
610
611
@deffn {Scheme Procedure} addr-add @var{device} @var{cidr} [@var{#:ipv6?} #f] @
612
        [@var{#:peer} @code{(cidr->addr cidr)}] [@var{#:broadcast} #f] @
613
        [@var{#:anycast} #f] [@var{#:label} #f] [@var{#:scope} @code{'global}] @
614
        [@var{#:metric} #f] [@var{#:home?} #f] [@var{#:mngtmpaddr?} #f] @
615
        [@var{#:nodad?} #f] [@var{optimistic?} #f] [@var{noprefixroute?} #f] @
616
        [@var{#:autojoin?} #f]
617
Add the address given in @var{cidr} to @var{device}. @var{device} can
618
contain the name of the link, as a string, or its index, as a number.
619
620
@var{cidr} must be a string containing the address and prefix length, in
621
CIDR notation (@code{addr/prefix}).
622
623
@example
624
(addr-add "enp1s0" "192.0.2.15/24")
625
@end example
626
627
If you wish to add an IPv6 address instead, set @code{#:ipv6} to @code{#t},
628
as in the following example.
629
630
@example
631
(addr-add "enp1s0" "2001:db8::1a4c/64" #:ipv6? #t)
632
@end example
633
634
Note that using the wrong ip type with the wrong value for the @code{#:ipv6?}
635
flag will result in a @code{Bad address} exception from inet-pton.
636
637
Additional flags are available; they follow the same semantics as Iproute2.
638
For pointopoint interfaces, you can specify the address of the remote endpoint
639
with @var{#:peer}. You can specify a broadcast or anycast address with
640
@var{#:broadcast} and @var{#:anycast}. All three require an IP address passed
641
as a string when specified.
642
643
You can specify a label for the address with @var{#:label}. The parameter must
644
be a string that is either the name of the device, or starts with the name of
645
the device, followed by a colon and must contain at most 15 characters.
646
647
You can specify a scope with @var{#:scope}, whose value is either @code{'global},
648
@code{'link}, @code{'host} or a numeric value.
649
650
You can specify the priority of the prefix route associated with this address
651
using @code{#:metric}, a number.
652
653
Finally, this procedures accepts address configuration flags, whose values are
654
booleans.  They are unset by default.  Some flags only work for IPv6 addresses,
655
those are @var{#:home?} to designate this address as the ``home address'',
656
@var{#:mngtmpaddr?}, @var{#:nodad?} and @var{#:optimistic?}. The flags
657
@var{#:noprefixroute?} and @var{#:autojoin?} can be set for IPv4 and IPv6
658
addresses.
659
@end deffn
660
661
@deffn {Scheme Procedure} addr-del @var{device} @var{cidr} [@var{#:ipv6?} #f] @
662
        [@var{#:peer} @code{(cidr->addr cidr)}] [@var{#:broadcast} #f] @
663
        [@var{#:anycast} #f] [@var{#:label} #f] [@var{#:scope} @code{'global}] @
664
        [@var{#:metric} #f] [@var{#:home?} #f] [@var{#:mngtmpaddr?} #f] @
665
        [@var{#:nodad?} #f] [@var{optimistic?} #f] [@var{noprefixroute?} #f] @
666
        [@var{#:autojoin?} #f]
667
Delete the address given in @var{cidr} from @var{device}. @var{device} can
668
contain the name of the link, as a string, or its index, as a number.
669
670
@var{cidr} must be a string containing the address and prefix length, in
671
CIDR notation (@code{addr/prefix}).
672
673
@example
674
(addr-del "enp1s0" "192.0.2.15/24")
675
@end example
676
677
If you wish to remove an IPv6 address instead, set @code{#:ipv6} to @code{#t},
678
as in the following example.
679
680
@example
681
(addr-del "enp1s0" "2001:db8::1a4c/64" #:ipv6? #t)
682
@end example
683
684
Note that using the wrong ip type with the wrong value for the @code{#:ipv6?}
685
flag will result in a @code{Bad address} exception from inet-pton.
686
687
Additional flags are available, see the description in @code{addr-add} for more
688
details.
689
@end deffn
690
691
@deffn {Scheme Procedure} addr-show [@var{device}]
692
Print the list of addresses for each device on standard output.  Setting
693
@code{device} to a link name or link identifier will restrict the output
694
to addresses of that device.
695
@end deffn
696
697
@node Route
698
@section Route
699
700
The @code{(ip route)} module introduces procedures to access and modify the
701
network routes on your machine.  They are equivalent to the @command{ip route}
702
family of commands, from @code{iproute2}.
703
704
@deffn {Scheme Procedure} route-add @var{dest} [@var{#:ipv6?} #f] @
705
    [@var{#:device} #f] [@var{#:table} RT_TABLE_MAIN] [@var{#:protocol} #f] @
706
    [@var{#:scope} RT_SCOPE_LINK] [@var{#:type} RTN_UNICAST] @
707
    [@var{#:priority} #f] [@var{#:src} #f] [@var{#:via} #f]
708
Add the route described by the argmuents.  @var{dest} is the destination network,
709
in cidr notation (@code{addr/prefix}) or the string @code{"default"}.
710
711
@var{#:device} is the name or index of a network link. @var{#:table} is the
712
index of a routing table, one of @code{RT_TABLE_COMPAT}, @code{RT_TABLE_DEFAULT},
713
@code{RT_TABLE_MAIN} or @code{RT_TABLE_LOCAL}, as defined in
714
@code{(netlink constant)}.
715
716
If it is set, @var{#:protocol} must be the routing protocol, @code{RTPROT_*},
717
as defined in @code{(netlink constant)}.
718
719
@var{#:scope} must be the scope of the route, one of @code{RT_SCOPE_*}, as
720
defined in @code{(netlink constant)}.
721
722
@var{#:type} must be the type of route, one of @code{RTN_*}, as defined in
723
@code{(netlink constant)}.
724
725
If set, @var{#:priority} is a number specifying the priority of the rule
726
when the kernel is looking for a matching rule.  This is also known as the
727
metric of the route.
728
729
If set, @var{#:src} is the source address in cidr notation, or as a single
730
address.
731
732
If set, @var{#:via} is the gateway address.  This is not in cidr notation, as
733
the gateway is a single address, not a network.
734
735
@example
736
(route-add "default" #:device "enp1s0" #:via "192.0.2.1")
737
(route-add "192.0.2.0/24" #:device "enp1s0" #:src "192.0.2.15")
738
@end example
739
740
If you wish to add an IPv6 route instead, set @code{#:ipv6} to @code{#t},
741
as in the following example.
742
743
@example
744
(addr-add "2001:db8::/64" #:device "enp1s0" #:src "2001:db8::1a4c" #:ipv6? #t)
745
@end example
746
747
Note that using the wrong ip type with the wrong value for the @code{#:ipv6?}
748
flag will result in a @code{Bad address} exception from inet-pton.
749
@end deffn
750
751
@deffn {Scheme Procedure} route-del @var{dest} [@var{#:ipv6?} #f] @
752
    [@var{#:device} #f] [@var{#:table} RT_TABLE_MAIN] [@var{#:protocol} #f] @
753
    [@var{#:scope} #f] [@var{#:type} #f] [@var{#:priority} #f] @
754
    [@var{#:src} #f] [@var{#:via} #f]
755
Delete the route given in arguments.  The arguments follow the same structure
756
as @code{route-add}.  By specifying more arguments, you can narrow down the
757
search for the rule to delete further.  Each call will only remove one route,
758
so being more precise ensures you target the rule you wish to delete.  It
759
is not clear which route is deleted if multiple routes match your query.
760
@end deffn
761
762
@deffn {Scheme Procedure} route-show [@var{#:table} RT_TABLE_MAIN] @
763
    [@var{#:family} AF_UNSPEC]
764
Print the list of routes on standard output.  Note that, contrary to
765
@command{ip route show}, we show both IPv4 and IPv6 routes.  To narrow down the
766
number of routes displayed, you can specify the family as in this example.
767
768
@example
769
(route-show #:family AF_INET6)
770
@end example
771
@end deffn
772
773
@bye
774