2 * iplink_bond_slave.c Bonding slave device support
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
9 * Authors: Jiri Pirko <jiri@resnulli.us>
13 #include <sys/socket.h>
14 #include <linux/if_bonding.h>
18 #include "ip_common.h"
20 static void print_explain(FILE *f
)
22 fprintf(f
, "Usage: ... bond_slave [ queue_id ID ]\n");
25 static void explain(void)
27 print_explain(stderr
);
30 static const char *slave_states
[] = {
31 [BOND_STATE_ACTIVE
] = "ACTIVE",
32 [BOND_STATE_BACKUP
] = "BACKUP",
35 static void print_slave_state(FILE *f
, struct rtattr
*tb
)
37 unsigned int state
= rta_getattr_u8(tb
);
39 if (state
>= ARRAY_SIZE(slave_states
))
40 print_int(PRINT_ANY
, "state_index", "state %d ", state
);
42 print_string(PRINT_ANY
,
48 static const char *slave_mii_status
[] = {
49 [BOND_LINK_UP
] = "UP",
50 [BOND_LINK_FAIL
] = "GOING_DOWN",
51 [BOND_LINK_DOWN
] = "DOWN",
52 [BOND_LINK_BACK
] = "GOING_BACK",
55 static void print_slave_mii_status(FILE *f
, struct rtattr
*tb
)
57 unsigned int status
= rta_getattr_u8(tb
);
59 if (status
>= ARRAY_SIZE(slave_mii_status
))
65 print_string(PRINT_ANY
,
68 slave_mii_status
[status
]);
71 static void print_slave_oper_state(FILE *fp
, const char *name
, __u16 state
)
73 open_json_array(PRINT_ANY
, name
);
74 print_string(PRINT_FP
, NULL
, " <", NULL
);
75 #define _PF(s, str) if (state & LACP_STATE_##s) { \
76 state &= ~LACP_STATE_##s; \
77 print_string(PRINT_ANY, NULL, \
78 state ? "%s," : "%s", str); }
79 _PF(LACP_ACTIVITY
, "active");
80 _PF(LACP_TIMEOUT
, "short_timeout");
81 _PF(AGGREGATION
, "aggregating");
82 _PF(SYNCHRONIZATION
, "in_sync");
83 _PF(COLLECTING
, "collecting");
84 _PF(DISTRIBUTING
, "distributing");
85 _PF(DEFAULTED
, "defaulted");
86 _PF(EXPIRED
, "expired");
88 close_json_array(PRINT_ANY
, "> ");
91 static void bond_slave_print_opt(struct link_util
*lu
, FILE *f
, struct rtattr
*tb
[])
97 if (tb
[IFLA_BOND_SLAVE_STATE
])
98 print_slave_state(f
, tb
[IFLA_BOND_SLAVE_STATE
]);
100 if (tb
[IFLA_BOND_SLAVE_MII_STATUS
])
101 print_slave_mii_status(f
, tb
[IFLA_BOND_SLAVE_MII_STATUS
]);
103 if (tb
[IFLA_BOND_SLAVE_LINK_FAILURE_COUNT
])
105 "link_failure_count",
106 "link_failure_count %d ",
107 rta_getattr_u32(tb
[IFLA_BOND_SLAVE_LINK_FAILURE_COUNT
]));
109 if (tb
[IFLA_BOND_SLAVE_PERM_HWADDR
])
110 print_string(PRINT_ANY
,
113 ll_addr_n2a(RTA_DATA(tb
[IFLA_BOND_SLAVE_PERM_HWADDR
]),
114 RTA_PAYLOAD(tb
[IFLA_BOND_SLAVE_PERM_HWADDR
]),
117 if (tb
[IFLA_BOND_SLAVE_QUEUE_ID
])
121 rta_getattr_u16(tb
[IFLA_BOND_SLAVE_QUEUE_ID
]));
123 if (tb
[IFLA_BOND_SLAVE_AD_AGGREGATOR_ID
])
126 "ad_aggregator_id %d ",
127 rta_getattr_u16(tb
[IFLA_BOND_SLAVE_AD_AGGREGATOR_ID
]));
129 if (tb
[IFLA_BOND_SLAVE_AD_ACTOR_OPER_PORT_STATE
]) {
130 __u8 state
= rta_getattr_u8(tb
[IFLA_BOND_SLAVE_AD_ACTOR_OPER_PORT_STATE
]);
133 "ad_actor_oper_port_state",
134 "ad_actor_oper_port_state %d ",
136 print_slave_oper_state(f
, "ad_actor_oper_port_state_str", state
);
139 if (tb
[IFLA_BOND_SLAVE_AD_PARTNER_OPER_PORT_STATE
]) {
140 __u16 state
= rta_getattr_u8(tb
[IFLA_BOND_SLAVE_AD_PARTNER_OPER_PORT_STATE
]);
143 "ad_partner_oper_port_state",
144 "ad_partner_oper_port_state %d ",
146 print_slave_oper_state(f
, "ad_partner_oper_port_state_str", state
);
150 static int bond_slave_parse_opt(struct link_util
*lu
, int argc
, char **argv
,
156 if (matches(*argv
, "queue_id") == 0) {
158 if (get_u16(&queue_id
, *argv
, 0))
159 invarg("queue_id is invalid", *argv
);
160 addattr16(n
, 1024, IFLA_BOND_SLAVE_QUEUE_ID
, queue_id
);
162 if (matches(*argv
, "help") != 0)
164 "bond_slave: unknown option \"%s\"?\n",
175 static void bond_slave_print_help(struct link_util
*lu
, int argc
, char **argv
,
181 struct link_util bond_slave_link_util
= {
183 .maxattr
= IFLA_BOND_SLAVE_MAX
,
184 .print_opt
= bond_slave_print_opt
,
185 .parse_opt
= bond_slave_parse_opt
,
186 .print_help
= bond_slave_print_help
,
187 .parse_ifla_xstats
= bond_parse_xstats
,
188 .print_ifla_xstats
= bond_print_xstats
,