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 const char *slave_states
[] = {
21 [BOND_STATE_ACTIVE
] = "ACTIVE",
22 [BOND_STATE_BACKUP
] = "BACKUP",
25 static void print_slave_state(FILE *f
, struct rtattr
*tb
)
27 unsigned int state
= rta_getattr_u8(tb
);
29 if (state
>= ARRAY_SIZE(slave_states
))
30 fprintf(f
, "state %d ", state
);
32 fprintf(f
, "state %s ", slave_states
[state
]);
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",
42 static void print_slave_mii_status(FILE *f
, struct rtattr
*tb
)
44 unsigned int status
= rta_getattr_u8(tb
);
46 if (status
>= ARRAY_SIZE(slave_mii_status
))
47 fprintf(f
, "mii_status %d ", status
);
49 fprintf(f
, "mii_status %s ", slave_mii_status
[status
]);
52 static void bond_slave_print_opt(struct link_util
*lu
, FILE *f
, struct rtattr
*tb
[])
58 if (tb
[IFLA_BOND_SLAVE_STATE
])
59 print_slave_state(f
, tb
[IFLA_BOND_SLAVE_STATE
]);
61 if (tb
[IFLA_BOND_SLAVE_MII_STATUS
])
62 print_slave_mii_status(f
, tb
[IFLA_BOND_SLAVE_MII_STATUS
]);
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
]));
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
]),
74 if (tb
[IFLA_BOND_SLAVE_QUEUE_ID
])
75 fprintf(f
, "queue_id %d ",
76 rta_getattr_u16(tb
[IFLA_BOND_SLAVE_QUEUE_ID
]));
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
]));
82 if (tb
[IFLA_BOND_SLAVE_AD_ACTOR_OPER_PORT_STATE
])
83 fprintf(f
, "ad_actor_oper_port_state %d ",
84 rta_getattr_u8(tb
[IFLA_BOND_SLAVE_AD_ACTOR_OPER_PORT_STATE
]));
86 if (tb
[IFLA_BOND_SLAVE_AD_PARTNER_OPER_PORT_STATE
])
87 fprintf(f
, "ad_partner_oper_port_state %d ",
88 rta_getattr_u16(tb
[IFLA_BOND_SLAVE_AD_PARTNER_OPER_PORT_STATE
]));
91 static int bond_slave_parse_opt(struct link_util
*lu
, int argc
, char **argv
,
97 if (matches(*argv
, "queue_id") == 0) {
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
);
109 struct link_util bond_slave_link_util
= {
111 .maxattr
= IFLA_BOND_SLAVE_MAX
,
112 .print_opt
= bond_slave_print_opt
,
113 .parse_opt
= bond_slave_parse_opt
,