]> git.proxmox.com Git - mirror_iproute2.git/blob - ip/iplink_bond_slave.c
Merge branch 'master' into net-next
[mirror_iproute2.git] / ip / iplink_bond_slave.c
1 /*
2 * iplink_bond_slave.c Bonding slave device support
3 *
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.
8 *
9 * Authors: Jiri Pirko <jiri@resnulli.us>
10 */
11
12 #include <stdio.h>
13 #include <sys/socket.h>
14 #include <linux/if_bonding.h>
15
16 #include "rt_names.h"
17 #include "utils.h"
18 #include "ip_common.h"
19
20 static const char *slave_states[] = {
21 [BOND_STATE_ACTIVE] = "ACTIVE",
22 [BOND_STATE_BACKUP] = "BACKUP",
23 };
24
25 static void print_slave_state(FILE *f, struct rtattr *tb)
26 {
27 unsigned int state = rta_getattr_u8(tb);
28
29 if (state >= sizeof(slave_states) / sizeof(slave_states[0]))
30 fprintf(f, "state %d ", state);
31 else
32 fprintf(f, "state %s ", slave_states[state]);
33 }
34
35 static const char *slave_mii_status[] = {
36 [BOND_LINK_UP] = "UP",
37 [BOND_LINK_FAIL] = "GOING_DOWN",
38 [BOND_LINK_DOWN] = "DOWN",
39 [BOND_LINK_BACK] = "GOING_BACK",
40 };
41
42 static void print_slave_mii_status(FILE *f, struct rtattr *tb)
43 {
44 unsigned int status = rta_getattr_u8(tb);
45
46 if (status >= sizeof(slave_mii_status) / sizeof(slave_mii_status[0]))
47 fprintf(f, "mii_status %d ", status);
48 else
49 fprintf(f, "mii_status %s ", slave_mii_status[status]);
50 }
51
52 static void bond_slave_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
53 {
54 SPRINT_BUF(b1);
55 if (!tb)
56 return;
57
58 if (tb[IFLA_BOND_SLAVE_STATE])
59 print_slave_state(f, tb[IFLA_BOND_SLAVE_STATE]);
60
61 if (tb[IFLA_BOND_SLAVE_MII_STATUS])
62 print_slave_mii_status(f, tb[IFLA_BOND_SLAVE_MII_STATUS]);
63
64 if (tb[IFLA_BOND_SLAVE_LINK_FAILURE_COUNT])
65 fprintf(f, "link_failure_count %d ",
66 rta_getattr_u32(tb[IFLA_BOND_SLAVE_LINK_FAILURE_COUNT]));
67
68 if (tb[IFLA_BOND_SLAVE_PERM_HWADDR])
69 fprintf(f, "perm_hwaddr %s ",
70 ll_addr_n2a(RTA_DATA(tb[IFLA_BOND_SLAVE_PERM_HWADDR]),
71 RTA_PAYLOAD(tb[IFLA_BOND_SLAVE_PERM_HWADDR]),
72 0, b1, sizeof(b1)));
73
74 if (tb[IFLA_BOND_SLAVE_QUEUE_ID])
75 fprintf(f, "queue_id %d ",
76 rta_getattr_u16(tb[IFLA_BOND_SLAVE_QUEUE_ID]));
77
78 if (tb[IFLA_BOND_SLAVE_AD_AGGREGATOR_ID])
79 fprintf(f, "ad_aggregator_id %d ",
80 rta_getattr_u16(tb[IFLA_BOND_SLAVE_AD_AGGREGATOR_ID]));
81
82 if (tb[IFLA_BOND_SLAVE_AD_ACTOR_OPER_PORT_STATE])
83 fprintf(f, "ad_actor_oper_port_state %d\n",
84 rta_getattr_u8(tb[IFLA_BOND_SLAVE_AD_ACTOR_OPER_PORT_STATE]));
85
86 if (tb[IFLA_BOND_SLAVE_AD_PARTNER_OPER_PORT_STATE])
87 fprintf(f, "ad_partner_oper_port_state %d\n",
88 rta_getattr_u16(tb[IFLA_BOND_SLAVE_AD_PARTNER_OPER_PORT_STATE]));
89 }
90
91 static int bond_slave_parse_opt(struct link_util *lu, int argc, char **argv,
92 struct nlmsghdr *n)
93 {
94 __u16 queue_id;
95
96 while (argc > 0) {
97 if (matches(*argv, "queue_id") == 0) {
98 NEXT_ARG();
99 if (get_u16(&queue_id, *argv, 0))
100 invarg("queue_id is invalid", *argv);
101 addattr16(n, 1024, IFLA_BOND_SLAVE_QUEUE_ID, queue_id);
102 }
103 argc--, argv++;
104 }
105
106 return 0;
107 }
108
109 struct link_util bond_slave_link_util = {
110 .id = "bond",
111 .maxattr = IFLA_BOND_SLAVE_MAX,
112 .print_opt = bond_slave_print_opt,
113 .parse_opt = bond_slave_parse_opt,
114 .slave = true,
115 };
116