Add more flags to (ip addr) procedures
doc/guile-netlink.texi
| 605 | 605 | network addresses on your machine. They are equivalent to the @command{ip addr} | |
| 606 | 606 | family of commands, from @code{iproute2}. | |
| 607 | 607 | ||
| 608 | - | @deffn {Scheme Procedure} addr-add @var{device} @var{cidr} [@var{#:ipv6?} #f] | |
| 608 | + | @deffn {Scheme Procedure} addr-add @var{device} @var{cidr} [@var{#:ipv6?} #f] @ | |
| 609 | + | [@var{#:peer} @code{(cidr->addr cidr)}] [@var{#:broadcast} #f] @ | |
| 610 | + | [@var{#:anycast} #f] [@var{#:label} #f] [@var{#:scope} @code{'global}] @ | |
| 611 | + | [@var{#:metric} #f] [@var{#:home?} #f] [@var{#:mngtmpaddr?} #f] @ | |
| 612 | + | [@var{#:nodad?} #f] [@var{optimistic?} #f] [@var{noprefixroute?} #f] @ | |
| 613 | + | [@var{#:autojoin?} #f] | |
| 609 | 614 | Add the address given in @var{cidr} to @var{device}. @var{device} can | |
| 610 | 615 | contain the name of the link, as a string, or its index, as a number. | |
| 611 | 616 | ||
… | |||
| 625 | 630 | ||
| 626 | 631 | Note that using the wrong ip type with the wrong value for the @code{#:ipv6?} | |
| 627 | 632 | flag will result in a @code{Bad address} exception from inet-pton. | |
| 633 | + | ||
| 634 | + | Additional flags are available; they follow the same semantics as Iproute2. | |
| 635 | + | For pointopoint interfaces, you can specify the address of the remote endpoint | |
| 636 | + | with @var{#:peer}. You can specify a broadcast or anycast address with | |
| 637 | + | @var{#:broadcast} and @var{#:anycast}. All three require an IP address passed | |
| 638 | + | as a string when specified. | |
| 639 | + | ||
| 640 | + | You can specify a label for the address with @var{#:label}. The parameter must | |
| 641 | + | be a string that is either the name of the device, or starts with the name of | |
| 642 | + | the device, followed by a colon and must contain at most 15 characters. | |
| 643 | + | ||
| 644 | + | You can specify a scope with @var{#:scope}, whose value is either @code{'global}, | |
| 645 | + | @code{'link}, @code{'host} or a numeric value. | |
| 646 | + | ||
| 647 | + | You can specify the priority of the prefix route associated with this address | |
| 648 | + | using @code{#:metric}, a number. | |
| 649 | + | ||
| 650 | + | Finally, this procedures accepts address configuration flags, whose values are | |
| 651 | + | booleans. They are unset by default. Some flags only work for IPv6 addresses, | |
| 652 | + | those are @var{#:home?} to designate this address as the ``home address'', | |
| 653 | + | @var{#:mngtmpaddr?}, @var{#:nodad?} and @var{#:optimistic?}. The flags | |
| 654 | + | @var{#:noprefixroute?} and @var{#:autojoin?} can be set for IPv4 and IPv6 | |
| 655 | + | addresses. | |
| 628 | 656 | @end deffn | |
| 629 | 657 | ||
| 630 | - | @deffn {Scheme Procedure} addr-del @var{device} @var{cidr} [@var{#:ipv6?} #f] | |
| 658 | + | @deffn {Scheme Procedure} addr-del @var{device} @var{cidr} [@var{#:ipv6?} #f] @ | |
| 659 | + | [@var{#:peer} @code{(cidr->addr cidr)}] [@var{#:broadcast} #f] @ | |
| 660 | + | [@var{#:anycast} #f] [@var{#:label} #f] [@var{#:scope} @code{'global}] @ | |
| 661 | + | [@var{#:metric} #f] [@var{#:home?} #f] [@var{#:mngtmpaddr?} #f] @ | |
| 662 | + | [@var{#:nodad?} #f] [@var{optimistic?} #f] [@var{noprefixroute?} #f] @ | |
| 663 | + | [@var{#:autojoin?} #f] | |
| 631 | 664 | Delete the address given in @var{cidr} from @var{device}. @var{device} can | |
| 632 | 665 | contain the name of the link, as a string, or its index, as a number. | |
| 633 | 666 | ||
… | |||
| 647 | 680 | ||
| 648 | 681 | Note that using the wrong ip type with the wrong value for the @code{#:ipv6?} | |
| 649 | 682 | flag will result in a @code{Bad address} exception from inet-pton. | |
| 683 | + | ||
| 684 | + | Additional flags are available, see the description in @code{addr-add} for more | |
| 685 | + | details. | |
| 650 | 686 | @end deffn | |
| 651 | 687 | ||
| 652 | 688 | @deffn {Scheme Procedure} addr-show [@var{device}] | |
ip/addr.scm
| 45 | 45 | (brd addr-brd) | |
| 46 | 46 | (cacheinfo addr-cacheinfo)) | |
| 47 | 47 | ||
| 48 | - | (define* (addr-del device cidr #:key (ipv6? #f) (peer (cidr->addr cidr))) | |
| 48 | + | (define* (addr-del device cidr #:key (ipv6? #f) (peer (cidr->addr cidr)) | |
| 49 | + | (broadcast #f) (anycast #f) | |
| 50 | + | (label #f) (scope 'global) (metric #f) | |
| 51 | + | (home? #f) (mngtmpaddr? #f) (nodad? #f) (optimistic? #f) | |
| 52 | + | (noprefixroute? #f) (autojoin? #f)) | |
| 49 | 53 | (define request-num (random 65535)) | |
| 50 | 54 | (define prefix (cidr->prefix cidr)) | |
| 51 | 55 | (define addr (cidr->addr cidr)) | |
… | |||
| 55 | 59 | ((number? device) device) | |
| 56 | 60 | ((string? device) (link-name->index device)))) | |
| 57 | 61 | ||
| 62 | + | (define scope-num | |
| 63 | + | (match scope | |
| 64 | + | ((? number? scope) scope) | |
| 65 | + | ('global RT_SCOPE_UNIVERSE) | |
| 66 | + | ('host RT_SCOPE_HOST) | |
| 67 | + | ('link RT_SCOPE_LINK))) | |
| 68 | + | ||
| 69 | + | (define ifa-flags | |
| 70 | + | (logior (if (and ipv6? mngtmpaddr?) IFA_F_MANAGETEMPADDR 0) | |
| 71 | + | (if noprefixroute? IFA_F_NOPREFIXROUTE 0) | |
| 72 | + | (if autojoin? IFA_F_MCAUTOJOIN 0))) | |
| 73 | + | ||
| 58 | 74 | (define message | |
| 59 | 75 | (make-message | |
| 60 | 76 | RTM_DELADDR | |
… | |||
| 64 | 80 | (make-addr-message | |
| 65 | 81 | (if ipv6? AF_INET6 AF_INET) | |
| 66 | 82 | (if prefix prefix 0) | |
| 67 | - | 0 | |
| 68 | - | 0 | |
| 83 | + | (logior (if (and ipv6? home?) IFA_F_HOMEADDRESS 0) | |
| 84 | + | (if (and ipv6? nodad?) IFA_F_NODAD 0) | |
| 85 | + | (if (and ipv6? optimistic?) IFA_F_OPTIMISTIC 0)) | |
| 86 | + | scope-num | |
| 69 | 87 | index | |
| 70 | 88 | (list | |
| 71 | 89 | (make-route-attr IFA_LOCAL | |
… | |||
| 85 | 103 | (close-socket sock) | |
| 86 | 104 | (answer-ok? (last answer))))) | |
| 87 | 105 | ||
| 88 | - | (define* (addr-add device cidr #:key (ipv6? #f) (peer (cidr->addr cidr))) | |
| 106 | + | (define* (addr-add device cidr #:key (ipv6? #f) (peer (cidr->addr cidr)) | |
| 107 | + | (broadcast #f) (anycast #f) | |
| 108 | + | (label #f) (scope 'global) (metric #f) | |
| 109 | + | (home? #f) (mngtmpaddr? #f) (nodad? #f) (optimistic? #f) | |
| 110 | + | (noprefixroute? #f) (autojoin? #f)) | |
| 89 | 111 | (define request-num (random 65535)) | |
| 90 | 112 | (define prefix (cidr->prefix cidr)) | |
| 91 | 113 | (define addr (cidr->addr cidr)) | |
… | |||
| 95 | 117 | ((number? device) device) | |
| 96 | 118 | ((string? device) (link-name->index device)))) | |
| 97 | 119 | ||
| 120 | + | (define scope-num | |
| 121 | + | (match scope | |
| 122 | + | ((? number? scope) scope) | |
| 123 | + | ('global RT_SCOPE_UNIVERSE) | |
| 124 | + | ('host RT_SCOPE_HOST) | |
| 125 | + | ('link RT_SCOPE_LINK))) | |
| 126 | + | ||
| 127 | + | (define ifa-flags | |
| 128 | + | (logior (if (and ipv6? mngtmpaddr?) IFA_F_MANAGETEMPADDR 0) | |
| 129 | + | (if noprefixroute? IFA_F_NOPREFIXROUTE 0) | |
| 130 | + | (if autojoin? IFA_F_MCAUTOJOIN 0))) | |
| 131 | + | ||
| 98 | 132 | (define message | |
| 99 | 133 | (make-message | |
| 100 | 134 | RTM_NEWADDR | |
… | |||
| 104 | 138 | (make-addr-message | |
| 105 | 139 | (if ipv6? AF_INET6 AF_INET) | |
| 106 | 140 | (if prefix prefix 0) | |
| 107 | - | 0 | |
| 108 | - | 0 | |
| 141 | + | (logior (if (and ipv6? home?) IFA_F_HOMEADDRESS 0) | |
| 142 | + | (if (and ipv6? nodad?) IFA_F_NODAD 0) | |
| 143 | + | (if (and ipv6? optimistic?) IFA_F_OPTIMISTIC 0)) | |
| 144 | + | scope-num | |
| 109 | 145 | index | |
| 110 | - | (list | |
| 111 | - | (make-route-attr IFA_LOCAL | |
| 146 | + | `(,(make-route-attr IFA_LOCAL | |
| 112 | 147 | ((if ipv6? | |
| 113 | 148 | make-ipv6-route-attr | |
| 114 | 149 | make-ipv4-route-attr) | |
| 115 | 150 | addr)) | |
| 116 | - | (make-route-attr IFA_ADDRESS | |
| 151 | + | ,(make-route-attr IFA_ADDRESS | |
| 117 | 152 | ((if ipv6? | |
| 118 | 153 | make-ipv6-route-attr | |
| 119 | 154 | make-ipv4-route-attr) | |
| 120 | - | peer)))))) | |
| 155 | + | peer)) | |
| 156 | + | ,@(if broadcast | |
| 157 | + | `((,(make-route-attr IFA_BROADCAST | |
| 158 | + | ((if ipv6? | |
| 159 | + | make-ipv6-route-attr | |
| 160 | + | make-ipv4-route-attr) | |
| 161 | + | broadcast)))) | |
| 162 | + | '()) | |
| 163 | + | ,@(if anycast | |
| 164 | + | `((,(make-route-attr IFA_ANYCAST | |
| 165 | + | ((if ipv6? | |
| 166 | + | make-ipv6-route-attr | |
| 167 | + | make-ipv4-route-attr) | |
| 168 | + | anycast)))) | |
| 169 | + | '()) | |
| 170 | + | ,@(if (> ifa-flags 0) | |
| 171 | + | `((,(make-route-attr IFA_FLAGS (make-u32-route-attr ifa-flags)))) | |
| 172 | + | '()) | |
| 173 | + | ,@(if label | |
| 174 | + | `((,(make-route-attr IFA_LABEL (make-string-route-attr label)))) | |
| 175 | + | '()) | |
| 176 | + | ,@(if metric | |
| 177 | + | `((,(make-route-attr IFA_RT_PRIORITY (make-u32-route-attr metric)))) | |
| 178 | + | '()))))) | |
| 121 | 179 | ||
| 122 | 180 | (let ((sock (connect-route))) | |
| 123 | 181 | (send-msg message sock) | |
netlink/route/attrs.scm
| 292 | 292 | (,IFA_ANYCAST . ,address-decoder) | |
| 293 | 293 | (,IFA_FLAGS . ,deserialize-route-attr-data-u32) | |
| 294 | 294 | (,IFA_CACHEINFO . ,deserialize-route-attr-data-route-cache-info) | |
| 295 | + | (,IFA_RT_PRIORITY . ,deserialize-route-attr-data-u32) | |
| 295 | 296 | (default . ,deserialize-route-attr-data-bv))) | |
| 296 | 297 | ||
| 297 | 298 | (define (default-route-route-attr-decoder address-decoder) |