]> git.proxmox.com Git - mirror_iproute2.git/blob - ip/iplink_bond_slave.c
tc/m_gact: Drop dead code
[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 void print_explain(FILE *f)
21 {
22 fprintf(f, "Usage: ... bond_slave [ queue_id ID ]\n");
23 }
24
25 static void explain(void)
26 {
27 print_explain(stderr);
28 }
29
30 static const char *slave_states[] = {
31 [BOND_STATE_ACTIVE] = "ACTIVE",
32 [BOND_STATE_BACKUP] = "BACKUP",
33 };
34
35 static void print_slave_state(FILE *f, struct rtattr *tb)
36 {
37 unsigned int state = rta_getattr_u8(tb);
38
39 if (state >= ARRAY_SIZE(slave_states))
40 fprintf(f, "state %d ", state);
41 else
42 fprintf(f, "state %s ", slave_states[state]);
43 }
44
45 static const char *slave_mii_status[] = {
46 [BOND_LINK_UP] = "UP",
47 [BOND_LINK_FAIL] = "GOING_DOWN",
48 [BOND_LINK_DOWN] = "DOWN",
49 [BOND_LINK_BACK] = "GOING_BACK",
50 };
51
52 static void print_slave_mii_status(FILE *f, struct rtattr *tb)
53 {
54 unsigned int status = rta_getattr_u8(tb);
55
56 if (status >= ARRAY_SIZE(slave_mii_status))
57 fprintf(f, "mii_status %d ", status);
58 else
59 fprintf(f, "mii_status %s ", slave_mii_status[status]);
60 }
61
62 static void bond_slave_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
63 {
64 SPRINT_BUF(b1);
65 if (!tb)
66 return;
67
68 if (tb[IFLA_BOND_SLAVE_STATE])
69 print_slave_state(f, tb[IFLA_BOND_SLAVE_STATE]);
70
71 if (tb[IFLA_BOND_SLAVE_MII_STATUS])
72 print_slave_mii_status(f, tb[IFLA_BOND_SLAVE_MII_STATUS]);
73
74 if (tb[IFLA_BOND_SLAVE_LINK_FAILURE_COUNT])
75 fprintf(f, "link_failure_count %d ",
76 rta_getattr_u32(tb[IFLA_BOND_SLAVE_LINK_FAILURE_COUNT]));
77
78 if (tb[IFLA_BOND_SLAVE_PERM_HWADDR])
79 fprintf(f, "perm_hwaddr %s ",
80 ll_addr_n2a(RTA_DATA(tb[IFLA_BOND_SLAVE_PERM_HWADDR]),
81 RTA_PAYLOAD(tb[IFLA_BOND_SLAVE_PERM_HWADDR]),
82 0, b1, sizeof(b1)));
83
84 if (tb[IFLA_BOND_SLAVE_QUEUE_ID])
85 fprintf(f, "queue_id %d ",
86 rta_getattr_u16(tb[IFLA_BOND_SLAVE_QUEUE_ID]));
87
88 if (tb[IFLA_BOND_SLAVE_AD_AGGREGATOR_ID])
89 fprintf(f, "ad_aggregator_id %d ",
90 rta_getattr_u16(tb[IFLA_BOND_SLAVE_AD_AGGREGATOR_ID]));
91
92 if (tb[IFLA_BOND_SLAVE_AD_ACTOR_OPER_PORT_STATE])
93 fprintf(f, "ad_actor_oper_port_state %d ",
94 rta_getattr_u8(tb[IFLA_BOND_SLAVE_AD_ACTOR_OPER_PORT_STATE]));
95
96 if (tb[IFLA_BOND_SLAVE_AD_PARTNER_OPER_PORT_STATE])
97 fprintf(f, "ad_partner_oper_port_state %d ",
98 rta_getattr_u16(tb[IFLA_BOND_SLAVE_AD_PARTNER_OPER_PORT_STATE]));
99 }
100
101 static int bond_slave_parse_opt(struct link_util *lu, int argc, char **argv,
102 struct nlmsghdr *n)
103 {
104 __u16 queue_id;
105
106 while (argc > 0) {
107 if (matches(*argv, "queue_id") == 0) {
108 NEXT_ARG();
109 if (get_u16(&queue_id, *argv, 0))
110 invarg("queue_id is invalid", *argv);
111 addattr16(n, 1024, IFLA_BOND_SLAVE_QUEUE_ID, queue_id);
112 } else {
113 if (matches(*argv, "help") != 0)
114 fprintf(stderr,
115 "bond_slave: unknown option \"%s\"?\n",
116 *argv);
117 explain();
118 return -1;
119 }
120 argc--, argv++;
121 }
122
123 return 0;
124 }
125
126 static void bond_slave_print_help(struct link_util *lu, int argc, char **argv,
127 FILE *f)
128 {
129 print_explain(f);
130 }
131
132 struct link_util bond_slave_link_util = {
133 .id = "bond_slave",
134 .maxattr = IFLA_BOND_SLAVE_MAX,
135 .print_opt = bond_slave_print_opt,
136 .parse_opt = bond_slave_parse_opt,
137 .print_help = bond_slave_print_help,
138 };