Add ability to set link state with ip
Exposes existing netlink operations to modify link state of devices.
This commit is contained in:
parent
ae5555d334
commit
4f2fdd44b6
|
|
@ -1,3 +1,4 @@
|
||||||
|
extern int get_operstate(const char *name);
|
||||||
extern int print_linkinfo(const struct sockaddr_nl *who,
|
extern int print_linkinfo(const struct sockaddr_nl *who,
|
||||||
struct nlmsghdr *n,
|
struct nlmsghdr *n,
|
||||||
void *arg);
|
void *arg);
|
||||||
|
|
|
||||||
|
|
@ -131,6 +131,16 @@ static void print_operstate(FILE *f, __u8 state)
|
||||||
fprintf(f, "state %s ", oper_states[state]);
|
fprintf(f, "state %s ", oper_states[state]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int get_operstate(const char *name)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < sizeof(oper_states)/sizeof(oper_states[0]); i++)
|
||||||
|
if (strcasecmp(name, oper_states[i]) == 0)
|
||||||
|
return i;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
static void print_queuelen(FILE *f, struct rtattr *tb[IFLA_MAX + 1])
|
static void print_queuelen(FILE *f, struct rtattr *tb[IFLA_MAX + 1])
|
||||||
{
|
{
|
||||||
int qlen;
|
int qlen;
|
||||||
|
|
|
||||||
10
ip/iplink.c
10
ip/iplink.c
|
|
@ -433,10 +433,18 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req,
|
||||||
} else if (strcmp(*argv, "mode") == 0) {
|
} else if (strcmp(*argv, "mode") == 0) {
|
||||||
int mode;
|
int mode;
|
||||||
NEXT_ARG();
|
NEXT_ARG();
|
||||||
mode = get_link_mode(*argv);
|
mode = get_link_mode(*argv);
|
||||||
if (mode < 0)
|
if (mode < 0)
|
||||||
invarg("Invalid link mode\n", *argv);
|
invarg("Invalid link mode\n", *argv);
|
||||||
addattr8(&req->n, sizeof(*req), IFLA_LINKMODE, mode);
|
addattr8(&req->n, sizeof(*req), IFLA_LINKMODE, mode);
|
||||||
|
} else if (strcmp(*argv, "state") == 0) {
|
||||||
|
int state;
|
||||||
|
NEXT_ARG();
|
||||||
|
state = get_operstate(*argv);
|
||||||
|
if (state < 0)
|
||||||
|
invarg("Invalid operstate\n", *argv);
|
||||||
|
|
||||||
|
addattr8(&req->n, sizeof(*req), IFLA_OPERSTATE, state);
|
||||||
} else {
|
} else {
|
||||||
if (strcmp(*argv, "dev") == 0) {
|
if (strcmp(*argv, "dev") == 0) {
|
||||||
NEXT_ARG();
|
NEXT_ARG();
|
||||||
|
|
|
||||||
|
|
@ -103,6 +103,9 @@ ip-link \- network device configuration
|
||||||
.B mode
|
.B mode
|
||||||
.IR LINKMODE " |"
|
.IR LINKMODE " |"
|
||||||
.br
|
.br
|
||||||
|
.B state
|
||||||
|
.IR LINKSTATE " |"
|
||||||
|
.br
|
||||||
.B master
|
.B master
|
||||||
.IR DEVICE
|
.IR DEVICE
|
||||||
.br
|
.br
|
||||||
|
|
@ -259,6 +262,10 @@ the device will transistion to when it is brought up. Setting
|
||||||
mode changes the behaviour so that device goes into DORMANT state instead
|
mode changes the behaviour so that device goes into DORMANT state instead
|
||||||
of UP when driver is ready.
|
of UP when driver is ready.
|
||||||
|
|
||||||
|
.TP
|
||||||
|
.BI state " LINKSTATE"
|
||||||
|
allows setting the operational link state. The values (defined in RFC2863)
|
||||||
|
are: UP, DOWN, TESTING, UNKNOWN, DORMANT, NOTPRESENT, LOWERLAYERDOWN.
|
||||||
.TP
|
.TP
|
||||||
.BI alias " NAME"
|
.BI alias " NAME"
|
||||||
give the device a symbolic name for easy reference.
|
give the device a symbolic name for easy reference.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue