route: Add #:onlink? argument to route-add

Skyler FerrisSun Oct 29 08:52:09+0100 2023

62b6039

route: Add #:onlink? argument to route-add * ip/route.scm: (route-add) And #:onlink? argument & set the appropriate flag. * netlink/constant.scm: Add RTNH_F_* flags * doc/guile-netlink.texi (Route): Document it.

doc/guile-netlink.texi

740740
@deffn {Scheme Procedure} route-add @var{dest} [@var{#:ipv6?} #f] @
741741
    [@var{#:device} #f] [@var{#:table} RT_TABLE_MAIN] [@var{#:protocol} #f] @
742742
    [@var{#:scope} RT_SCOPE_LINK] [@var{#:type} RTN_UNICAST] @
743-
    [@var{#:priority} #f] [@var{#:src} #f] [@var{#:via} #f]
743+
    [@var{#:priority} #f] [@var{#:src} #f] [@var{#:via} #f] @
744+
    [@var{onlink?} #f]
744745
Add the route described by the argmuents.  @var{dest} is the destination network,
745746
in cidr notation (@code{addr/prefix}) or the string @code{"default"}.
746747

768769
If set, @var{#:via} is the gateway address.  This is not in cidr notation, as
769770
the gateway is a single address, not a network.
770771
772+
If set, @var{#:onlink?} adds the RTNH_F_ONLINK flag, which allows using the rule
773+
as if the next hop (specified by the @var{#:via} option) was present on the
774+
interface, even if its address is not part of the interface's network.
775+
771776
@example
772777
(route-add "default" #:device "enp1s0" #:via "192.0.2.1")
773778
(route-add "192.0.2.0/24" #:device "enp1s0" #:src "192.0.2.15")

ip/route.scm

112112
(define* (route-add dest
113113
                    #:key (ipv6? #f) (device #f) (table RT_TABLE_MAIN)
114114
                          (protocol RTPROT_BOOT) (scope RT_SCOPE_UNIVERSE)
115-
                          (type RTN_UNICAST) (priority #f) (src #f) (via #f))
115+
                          (type RTN_UNICAST) (priority #f) (src #f) (via #f)
116+
                          (onlink? #f))
116117
  (define request-num (random 65535))
117118
118119
  (define index

136137
        (or protocol 0)
137138
        scope
138139
        type
139-
        0
140+
        (if onlink? RTNH_F_ONLINK 0)
140141
        `(,@(if (equal? dest "default")
141142
                '()
142143
                (list (make-route-attr RTA_DST

netlink/constant.scm

340340
  (RT_TABLE_MAIN 254)
341341
  (RT_TABLE_LOCAL 255))
342342
343+
;; rtnh_flags
344+
(define-enum int->rtnh-flag
345+
  RTNH_F_DEAD
346+
  RTNH_F_PERVASIVE
347+
  (RTNH_F_ONLINK 4)
348+
  (RTNH_F_OFFLOAD 8)
349+
  (RTNH_F_LINKDOWN 16)
350+
  (RTNH_F_UNRESOLVED 32)
351+
  (RTNH_F_TRAP 64))
352+
343353
;; link type
344354
;; more at include/uapi/linux/if_arp.h
345355
(define-enum int->link-type