[PATCH 0/3] guile-netlink: Add support for bonds

  • Done
  • quality assurance status badge
Details
2 participants
  • Julien Lepiller
  • Alexey Abramov
Owner
unassigned
Submitted by
Alexey Abramov
Severity
normal
A
A
Alexey Abramov wrote on 8 Oct 2022 18:50
(address . guix-patches@gnu.org)
20221008165043.13177-1-levenson@mmer.org
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
A
A
Alexey Abramov wrote on 8 Oct 2022 18:53
[PATCH 1/3] link: Pass correct attribute and a payload to rename a link
(address . 58382@debbugs.gnu.org)
20221008165314.14056-1-levenson@mmer.org
* 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(-)

Toggle diff (17 lines)
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
A
A
Alexey Abramov wrote on 8 Oct 2022 18:53
[PATCH 2/3] link: Allow to bound interfaces to bonds
(address . 58382@debbugs.gnu.org)
20221008165314.14056-2-levenson@mmer.org
* 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(-)

Toggle diff (28 lines)
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
A
A
Alexey Abramov wrote on 8 Oct 2022 18:53
[PATCH 3/3] link: Add partial support for bond interfaces
(address . 58382@debbugs.gnu.org)
20221008165314.14056-3-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(+)

Toggle diff (126 lines)
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
J
J
Julien Lepiller wrote on 9 Oct 2022 15:45
Re: [bug#58382] [PATCH 0/3] guile-netlink: Add support for bonds
(name . Alexey Abramov)(address . levenson@mmer.org)(address . 58382-done@debbugs.gnu.org)
20221009154509.424df1c8@sybil.lepiller.eu
Le Sat, 8 Oct 2022 18:50:43 +0200,
Alexey Abramov via Guix-patches via <guix-patches@gnu.org> a écrit :

Toggle quote (19 lines)
> 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 :)
Closed
?
Your comment

This issue is archived.

To comment on this conversation send an email to 58382@debbugs.gnu.org

To respond to this issue using the mumi CLI, first switch to it
mumi current 58382
Then, you may apply the latest patchset in this issue (with sign off)
mumi am -- -s
Or, compose a reply to this issue
mumi compose
Or, send patches to this issue
mumi send-email *.patch