all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Alexey Abramov via Guix-patches via <guix-patches@gnu.org>
To: 58382@debbugs.gnu.org
Subject: [bug#58382] [PATCH 3/3] link: Add partial support for bond interfaces
Date: Sat,  8 Oct 2022 18:53:14 +0200	[thread overview]
Message-ID: <20221008165314.14056-3-levenson@mmer.org> (raw)
In-Reply-To: <20221008165314.14056-1-levenson@mmer.org>

* ip/link.scm (link-add): Support specific arguments for `bond' type link.
(bond-type-args): New function. Implement mode, miimon and lacp-rate
configuration for bonds.
(alist->keyword+value): New function.
* netlink/constant.scm: Define bond specific information. Define constants for
bond modes.
---
 ip/link.scm          | 65 ++++++++++++++++++++++++++++++++++++++++++++
 netlink/constant.scm | 30 ++++++++++++++++++++
 2 files changed, 95 insertions(+)

diff --git a/ip/link.scm b/ip/link.scm
index 70ab79f..f6144c0 100644
--- a/ip/link.scm
+++ b/ip/link.scm
@@ -249,6 +249,70 @@ criteria."
       (close-socket sock)
       (answer-ok? (last answer)))))
 
+(define* (bond-type-args #:key (mode #f) (miimon #f) (lacp-active #f) (lacp-rate #f)
+                         (primary #f) (primary-reselect #f))
+  `(,@(if mode
+          (list
+           (make-route-attr IFLA_BOND_MODE
+             (match mode
+               ("balance-rr" (make-u8-route-attr BOND_MODE_ROUNDROBIN))
+               ("active-backup" (make-u8-route-attr BOND_MODE_ACTIVEBACKUP))
+               ("balance-xor" (make-u8-route-attr BOND_MODE_XOR))
+               ("broadcast" (make-u8-route-attr BOND_MODE_BROADCAST))
+               ("802.3ad" (make-u8-route-attr BOND_MODE_8023AD))
+               ("balance-tlb" (make-u8-route-attr BOND_MODE_TLB))
+               ("balance-alb" (make-u8-route-attr BOND_MODE_ALB))
+               (_ (raise (condition
+                          (&message
+                           (message "Bond field `mode' can be defined as balance-rr|active-backup|balance-xor|broadcast|802.3ad|balance-tlb|balance-alb" ))))))))
+          '())
+    ,@(if miimon
+          (list
+           (make-route-attr IFLA_BOND_MIIMON
+             (make-u32-route-attr miimon)))
+          '())
+    ,@(if primary
+          (list
+           (make-route-attr IFLA_BOND_PRIMARY
+             (make-u32-route-attr (link-name->index primary))))
+          '())
+    ,@(if primary-reselect
+          (list
+           (make-route-attr IFLA_BOND_PRIMARY_RESELECT
+             (match primary-reselect
+               ("always" (make-u8-route-attr BOND_PRIMARY_RESELECT_ALWAYS))
+               ("better" (make-u8-route-attr BOND_PRIMARY_RESELECT_BETTER))
+               ("failure" (make-u8-route-attr BOND_PRIMARY_RESELECT_FAILURE))
+               (_ (raise (condition
+                          (&message
+                           (message "Bond field `primary-reselect' can be defined as always|better|failure" ))))))))
+          '())
+    ,@(if lacp-active
+          (list
+           (make-route-attr IFLA_BOND_AD_LACP_ACTIVE
+             (match lacp-active
+               ("on" (make-u8-route-attr BOND_AD_LACP_ACTIVE_ON))
+               ("off" (make-u8-route-attr BOND_AD_LACP_ACTIVE_OFF))
+               (_ (raise (condition
+                          (&message
+                           (message "Bond field `lacp-active' can be defined as off|on" ))))))))
+          '())
+    ,@(if lacp-rate
+          (list
+           (make-route-attr IFLA_BOND_AD_LACP_RATE
+             (match lacp-rate
+               ("slow" (make-u8-route-attr 0))
+               ("fast" (make-u8-route-attr 1))
+               (_ (raise (condition
+                          (&message
+                           (message "Bond field `lacp-rate' can be defined as slow|fast"))))))))
+          '())))
+
+(define (alist->keyword+value alist)
+  (fold (match-lambda*
+          (((k . v) r)
+           (cons* (symbol->keyword k) v r))) '() alist))
+
 (define* (link-add name type #:key (type-args '()))
   (define request-num (random 65535))
   (define type-data
@@ -268,6 +332,7 @@ criteria."
                              (make-string-route-attr
                                (assoc-ref type-args 'peer)))))))
                '())))
+      ("bond" (apply bond-type-args (alist->keyword+value type-args)))
       ;; TODO: unsupported for now
       (_ '())))
   (define message
diff --git a/netlink/constant.scm b/netlink/constant.scm
index ce5e15e..7c72fc1 100644
--- a/netlink/constant.scm
+++ b/netlink/constant.scm
@@ -82,6 +82,36 @@
   IFLA_VLAN_UNSPEC IFLA_VLAN_ID IFLA_VLAN_FLAGS IFLA_VLAN_EGRESS_QOS
   IFLA_VLAN_INGRESS_QOS IFLA_VLAN_PROTOCOL)
 
+(define-enum int->bond-linkinfo
+  IFLA_BOND_UNSPEC IFLA_BOND_MODE IFLA_BOND_ACTIVE_SLAVE IFLA_BOND_MIIMON
+  IFLA_BOND_UPDELAY IFLA_BOND_DOWNDELAY IFLA_BOND_USE_CARRIER IFLA_BOND_ARP_INTERVAL
+  IFLA_BOND_ARP_IP_TARGET IFLA_BOND_ARP_VALIDATE IFLA_BOND_ARP_ALL_TARGETS
+  IFLA_BOND_PRIMARY IFLA_BOND_PRIMARY_RESELECT IFLA_BOND_FAIL_OVER_MAC IFLA_BOND_XMIT_HASH_POLICY
+  IFLA_BOND_RESEND_IGMP IFLA_BOND_NUM_PEER_NOTIF IFLA_BOND_ALL_SLAVES_ACTIVE
+  IFLA_BOND_MIN_LINKS IFLA_BOND_LP_INTERVAL IFLA_BOND_PACKETS_PER_SLAVE
+  IFLA_BOND_AD_LACP_RATE IFLA_BOND_AD_SELECT IFLA_BOND_AD_INFO IFLA_BOND_AD_ACTOR_SYS_PRIO
+  IFLA_BOND_AD_USER_PORT_KEY IFLA_BOND_AD_ACTOR_SYSTEM IFLA_BOND_TLB_DYNAMIC_LB
+  IFLA_BOND_PEER_NOTIF_DELAY IFLA_BOND_AD_LACP_ACTIVE IFLA_BOND_MISSED_MAX IFLA_BOND_NS_IP6_TARGET)
+
+;; see iproute2/ip/iplink_bond.c for mode_tbl
+(define-public BOND_MODE_ROUNDROBIN 0)
+(define-public BOND_MODE_ACTIVEBACKUP 1)
+(define-public BOND_MODE_XOR 2)
+(define-public BOND_MODE_BROADCAST 3)
+(define-public BOND_MODE_8023AD 4)
+(define-public BOND_MODE_TLB 5)
+;; TLB + RLB (receive load balancing)
+(define-public BOND_MODE_ALB 6)
+
+;; see iproute2/ip/iplink_bond.c primary_reselect_tbl
+(define-public BOND_PRIMARY_RESELECT_ALWAYS 0)
+(define-public BOND_PRIMARY_RESELECT_BETTER 1)
+(define-public BOND_PRIMARY_RESELECT_FAILURE 2)
+
+;; see iproute2/ip/iplink_bond.c for lacp_active_tbl
+(define-public BOND_AD_LACP_ACTIVE_OFF 0)
+(define-public BOND_AD_LACP_ACTIVE_ON 1)
+
 (define-enum int->addr-attr-kind
   IFA_UNSPEC IFA_ADDRESS IFA_LOCAL IFA_LABEL IFA_BROADCAST
   IFA_ANYCAST IFA_CACHEINFO IFA_MULTICAST IFA_FLAGS
-- 
2.36.1





  parent reply	other threads:[~2022-10-08 16:54 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-08 16:50 [bug#58382] [PATCH 0/3] guile-netlink: Add support for bonds Alexey Abramov via Guix-patches via
2022-10-08 16:53 ` [bug#58382] [PATCH 1/3] link: Pass correct attribute and a payload to rename a link Alexey Abramov via Guix-patches via
2022-10-08 16:53   ` [bug#58382] [PATCH 2/3] link: Allow to bound interfaces to bonds Alexey Abramov via Guix-patches via
2022-10-08 16:53   ` Alexey Abramov via Guix-patches via [this message]
2022-10-09 13:45 ` bug#58382: [PATCH 0/3] guile-netlink: Add support for bonds Julien Lepiller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221008165314.14056-3-levenson@mmer.org \
    --to=guix-patches@gnu.org \
    --cc=58382@debbugs.gnu.org \
    --cc=levenson@mmer.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.