Line data Source code
1 : /* SPDX-License-Identifier: LGPL-2.1+ */
2 : #pragma once
3 :
4 : #include <netinet/in.h>
5 : #include <linux/if_bonding.h>
6 :
7 : #include "in-addr-util.h"
8 : #include "netdev.h"
9 : #include "ordered-set.h"
10 :
11 : /*
12 : * Maximum number of targets supported by the kernel for a single
13 : * bond netdev.
14 : */
15 : #define NETDEV_BOND_ARP_TARGETS_MAX 16
16 :
17 : typedef enum BondMode {
18 : NETDEV_BOND_MODE_BALANCE_RR = BOND_MODE_ROUNDROBIN,
19 : NETDEV_BOND_MODE_ACTIVE_BACKUP = BOND_MODE_ACTIVEBACKUP,
20 : NETDEV_BOND_MODE_BALANCE_XOR = BOND_MODE_XOR,
21 : NETDEV_BOND_MODE_BROADCAST = BOND_MODE_BROADCAST,
22 : NETDEV_BOND_MODE_802_3AD = BOND_MODE_8023AD,
23 : NETDEV_BOND_MODE_BALANCE_TLB = BOND_MODE_TLB,
24 : NETDEV_BOND_MODE_BALANCE_ALB = BOND_MODE_ALB,
25 : _NETDEV_BOND_MODE_MAX,
26 : _NETDEV_BOND_MODE_INVALID = -1
27 : } BondMode;
28 :
29 : typedef enum BondXmitHashPolicy {
30 : NETDEV_BOND_XMIT_HASH_POLICY_LAYER2 = BOND_XMIT_POLICY_LAYER2,
31 : NETDEV_BOND_XMIT_HASH_POLICY_LAYER34 = BOND_XMIT_POLICY_LAYER34,
32 : NETDEV_BOND_XMIT_HASH_POLICY_LAYER23 = BOND_XMIT_POLICY_LAYER23,
33 : NETDEV_BOND_XMIT_HASH_POLICY_ENCAP23 = BOND_XMIT_POLICY_ENCAP23,
34 : NETDEV_BOND_XMIT_HASH_POLICY_ENCAP34 = BOND_XMIT_POLICY_ENCAP34,
35 : _NETDEV_BOND_XMIT_HASH_POLICY_MAX,
36 : _NETDEV_BOND_XMIT_HASH_POLICY_INVALID = -1
37 : } BondXmitHashPolicy;
38 :
39 : typedef enum BondLacpRate {
40 : NETDEV_BOND_LACP_RATE_SLOW,
41 : NETDEV_BOND_LACP_RATE_FAST,
42 : _NETDEV_BOND_LACP_RATE_MAX,
43 : _NETDEV_BOND_LACP_RATE_INVALID = -1,
44 : } BondLacpRate;
45 :
46 : typedef enum BondAdSelect {
47 : NETDEV_BOND_AD_SELECT_STABLE,
48 : NETDEV_BOND_AD_SELECT_BANDWIDTH,
49 : NETDEV_BOND_AD_SELECT_COUNT,
50 : _NETDEV_BOND_AD_SELECT_MAX,
51 : _NETDEV_BOND_AD_SELECT_INVALID = -1,
52 : } BondAdSelect;
53 :
54 : typedef enum BondFailOverMac {
55 : NETDEV_BOND_FAIL_OVER_MAC_NONE,
56 : NETDEV_BOND_FAIL_OVER_MAC_ACTIVE,
57 : NETDEV_BOND_FAIL_OVER_MAC_FOLLOW,
58 : _NETDEV_BOND_FAIL_OVER_MAC_MAX,
59 : _NETDEV_BOND_FAIL_OVER_MAC_INVALID = -1,
60 : } BondFailOverMac;
61 :
62 : typedef enum BondArpValidate {
63 : NETDEV_BOND_ARP_VALIDATE_NONE,
64 : NETDEV_BOND_ARP_VALIDATE_ACTIVE,
65 : NETDEV_BOND_ARP_VALIDATE_BACKUP,
66 : NETDEV_BOND_ARP_VALIDATE_ALL,
67 : _NETDEV_BOND_ARP_VALIDATE_MAX,
68 : _NETDEV_BOND_ARP_VALIDATE_INVALID = -1,
69 : } BondArpValidate;
70 :
71 : typedef enum BondArpAllTargets {
72 : NETDEV_BOND_ARP_ALL_TARGETS_ANY,
73 : NETDEV_BOND_ARP_ALL_TARGETS_ALL,
74 : _NETDEV_BOND_ARP_ALL_TARGETS_MAX,
75 : _NETDEV_BOND_ARP_ALL_TARGETS_INVALID = -1,
76 : } BondArpAllTargets;
77 :
78 : typedef enum BondPrimaryReselect {
79 : NETDEV_BOND_PRIMARY_RESELECT_ALWAYS,
80 : NETDEV_BOND_PRIMARY_RESELECT_BETTER,
81 : NETDEV_BOND_PRIMARY_RESELECT_FAILURE,
82 : _NETDEV_BOND_PRIMARY_RESELECT_MAX,
83 : _NETDEV_BOND_PRIMARY_RESELECT_INVALID = -1,
84 : } BondPrimaryReselect;
85 :
86 : typedef struct Bond {
87 : NetDev meta;
88 :
89 : BondMode mode;
90 : BondXmitHashPolicy xmit_hash_policy;
91 : BondLacpRate lacp_rate;
92 : BondAdSelect ad_select;
93 : BondFailOverMac fail_over_mac;
94 : BondArpValidate arp_validate;
95 : BondArpAllTargets arp_all_targets;
96 : BondPrimaryReselect primary_reselect;
97 :
98 : int tlb_dynamic_lb;
99 :
100 : bool all_slaves_active;
101 :
102 : unsigned resend_igmp;
103 : unsigned packets_per_slave;
104 : unsigned num_grat_arp;
105 : unsigned min_links;
106 :
107 : uint16_t ad_actor_sys_prio;
108 : uint16_t ad_user_port_key;
109 : struct ether_addr ad_actor_system;
110 :
111 : usec_t miimon;
112 : usec_t updelay;
113 : usec_t downdelay;
114 : usec_t arp_interval;
115 : usec_t lp_interval;
116 :
117 : OrderedSet *arp_ip_targets;
118 : } Bond;
119 :
120 0 : DEFINE_NETDEV_CAST(BOND, Bond);
121 : extern const NetDevVTable bond_vtable;
122 :
123 : int link_set_bond(Link *link);
124 :
125 : const char *bond_mode_to_string(BondMode d) _const_;
126 : BondMode bond_mode_from_string(const char *d) _pure_;
127 :
128 : const char *bond_xmit_hash_policy_to_string(BondXmitHashPolicy d) _const_;
129 : BondXmitHashPolicy bond_xmit_hash_policy_from_string(const char *d) _pure_;
130 :
131 : const char *bond_lacp_rate_to_string(BondLacpRate d) _const_;
132 : BondLacpRate bond_lacp_rate_from_string(const char *d) _pure_;
133 :
134 : const char *bond_fail_over_mac_to_string(BondFailOverMac d) _const_;
135 : BondFailOverMac bond_fail_over_mac_from_string(const char *d) _pure_;
136 :
137 : const char *bond_ad_select_to_string(BondAdSelect d) _const_;
138 : BondAdSelect bond_ad_select_from_string(const char *d) _pure_;
139 :
140 : const char *bond_arp_validate_to_string(BondArpValidate d) _const_;
141 : BondArpValidate bond_arp_validate_from_string(const char *d) _pure_;
142 :
143 : const char *bond_arp_all_targets_to_string(BondArpAllTargets d) _const_;
144 : BondArpAllTargets bond_arp_all_targets_from_string(const char *d) _pure_;
145 :
146 : const char *bond_primary_reselect_to_string(BondPrimaryReselect d) _const_;
147 : BondPrimaryReselect bond_primary_reselect_from_string(const char *d) _pure_;
148 :
149 : CONFIG_PARSER_PROTOTYPE(config_parse_bond_mode);
150 : CONFIG_PARSER_PROTOTYPE(config_parse_bond_xmit_hash_policy);
151 : CONFIG_PARSER_PROTOTYPE(config_parse_bond_lacp_rate);
152 : CONFIG_PARSER_PROTOTYPE(config_parse_bond_ad_select);
153 : CONFIG_PARSER_PROTOTYPE(config_parse_bond_fail_over_mac);
154 : CONFIG_PARSER_PROTOTYPE(config_parse_bond_arp_validate);
155 : CONFIG_PARSER_PROTOTYPE(config_parse_bond_arp_all_targets);
156 : CONFIG_PARSER_PROTOTYPE(config_parse_bond_primary_reselect);
157 : CONFIG_PARSER_PROTOTYPE(config_parse_arp_ip_target_address);
158 : CONFIG_PARSER_PROTOTYPE(config_parse_ad_actor_sys_prio);
159 : CONFIG_PARSER_PROTOTYPE(config_parse_ad_user_port_key);
160 : CONFIG_PARSER_PROTOTYPE(config_parse_ad_actor_system);
|