unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
* [bug#58382] [PATCH 0/3] guile-netlink: Add support for bonds
@ 2022-10-08 16:50 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-09 13:45 ` bug#58382: [PATCH 0/3] guile-netlink: Add support for bonds Julien Lepiller
  0 siblings, 2 replies; 5+ messages in thread
From: Alexey Abramov via Guix-patches via @ 2022-10-08 16:50 UTC (permalink / raw)
  To: 58382

With these patches, guile-netlink can be used to build bonds. bond-type-args
function accepts keys that people would be set to bond interfaces via 'ip link
set'. 'ip link help bond' shows the list of all passable settings. Only few of
them are implemented right now.

Master field was also added to 'link-set' in order to bind interfaces to their
masters in case of bonding.

Alexey Abramov (3):
  link: Pass correct attribute and a payload to rename a link
  link: Allow to bound interfaces to bonds
  link: Add partial support for bond interfaces

 ip/link.scm          | 77 ++++++++++++++++++++++++++++++++++++++++++--
 netlink/constant.scm | 30 +++++++++++++++++
 2 files changed, 104 insertions(+), 3 deletions(-)

-- 
2.36.1





^ permalink raw reply	[flat|nested] 5+ messages in thread

* [bug#58382] [PATCH 1/3] link: Pass correct attribute and a payload to rename a link
  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 ` 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   ` [bug#58382] [PATCH 3/3] link: Add partial support for bond interfaces Alexey Abramov via Guix-patches via
  2022-10-09 13:45 ` bug#58382: [PATCH 0/3] guile-netlink: Add support for bonds Julien Lepiller
  1 sibling, 2 replies; 5+ messages in thread
From: Alexey Abramov via Guix-patches via @ 2022-10-08 16:53 UTC (permalink / raw)
  To: 58382

* ip/link.scm(link-set): Send IFLA_IFNAME attribute with a new desired
interfaces name.
---
 ip/link.scm | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/ip/link.scm b/ip/link.scm
index ecd1072..521cffa 100644
--- a/ip/link.scm
+++ b/ip/link.scm
@@ -211,8 +211,8 @@ criteria."
                 '())
           ,@(if name
                 (list
-                  (make-route-attr IFLA_TXQLEN
-                    (make-u32-route-attr txqueuelen)))
+                  (make-route-attr IFLA_IFNAME
+                    (make-string-route-attr name)))
                 '())
           ,@(if address
                 (list
-- 
2.36.1





^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [bug#58382] [PATCH 2/3] link: Allow to bound interfaces to bonds
  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   ` Alexey Abramov via Guix-patches via
  2022-10-08 16:53   ` [bug#58382] [PATCH 3/3] link: Add partial support for bond interfaces Alexey Abramov via Guix-patches via
  1 sibling, 0 replies; 5+ messages in thread
From: Alexey Abramov via Guix-patches via @ 2022-10-08 16:53 UTC (permalink / raw)
  To: 58382

* ip/link.scm (link-set): Add new argument `master'. It is suppose to
be a name of the master interface to which our current device has to
be bound.
---
 ip/link.scm | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/ip/link.scm b/ip/link.scm
index 521cffa..70ab79f 100644
--- a/ip/link.scm
+++ b/ip/link.scm
@@ -164,7 +164,8 @@ criteria."
                    (trailers-on #f) (trailers-off #f)
                    (carrier-on #f) (carrier-off #f)
                    (txqueuelen #f) (name #f) (address #f)
-                   (broadcast #f) (mtu #f) (netns #f))
+                   (broadcast #f) (mtu #f) (netns #f)
+                   (master #f))
   (define request-num (random 65535))
   (define id (if (number? device) device (link-name->index device)))
   (define netnsfd (cond
@@ -229,6 +230,11 @@ criteria."
                   (make-route-attr IFLA_MTU
                     (make-u32-route-attr mtu)))
                 '())
+          ,@(if master
+                (list
+                  (make-route-attr IFLA_MASTER
+                    (make-u32-route-attr (link-name->index master))))
+                '())
           ,@(if netns
                 (list
                   (make-route-attr IFLA_NET_NS_FD
-- 
2.36.1





^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [bug#58382] [PATCH 3/3] link: Add partial support for bond interfaces
  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
  1 sibling, 0 replies; 5+ messages in thread
From: Alexey Abramov via Guix-patches via @ 2022-10-08 16:53 UTC (permalink / raw)
  To: 58382

* 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





^ permalink raw reply related	[flat|nested] 5+ messages in thread

* bug#58382: [PATCH 0/3] guile-netlink: Add support for bonds
  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-09 13:45 ` Julien Lepiller
  1 sibling, 0 replies; 5+ messages in thread
From: Julien Lepiller @ 2022-10-09 13:45 UTC (permalink / raw)
  To: Alexey Abramov; +Cc: 58382-done

Le Sat,  8 Oct 2022 18:50:43 +0200,
Alexey Abramov via Guix-patches via <guix-patches@gnu.org> a écrit :

> With these patches, guile-netlink can be used to build bonds.
> bond-type-args function accepts keys that people would be set to bond
> interfaces via 'ip link set'. 'ip link help bond' shows the list of
> all passable settings. Only few of them are implemented right now.
> 
> Master field was also added to 'link-set' in order to bind interfaces
> to their masters in case of bonding.
> 
> Alexey Abramov (3):
>   link: Pass correct attribute and a payload to rename a link
>   link: Allow to bound interfaces to bonds
>   link: Add partial support for bond interfaces
> 
>  ip/link.scm          | 77
> ++++++++++++++++++++++++++++++++++++++++++-- netlink/constant.scm |
> 30 +++++++++++++++++ 2 files changed, 104 insertions(+), 3
> deletions(-)
> 

Thanks, applied to guile-netlink :) I adjusted the commit messages a
bit, and used define-enum for bond mode. I didn't test though, so I
hope it works :)




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-10-09 13:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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   ` [bug#58382] [PATCH 3/3] link: Add partial support for bond interfaces Alexey Abramov via Guix-patches via
2022-10-09 13:45 ` bug#58382: [PATCH 0/3] guile-netlink: Add support for bonds Julien Lepiller

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).