]> rtime.felk.cvut.cz Git - lisovros/iproute2_canprio.git/commitdiff
Add ability to set link state with ip
authorStephen Hemminger <stephen.hemminger@vyatta.com>
Thu, 5 Apr 2012 22:08:57 +0000 (15:08 -0700)
committerStephen Hemminger <stephen.hemminger@vyatta.com>
Thu, 5 Apr 2012 22:08:57 +0000 (15:08 -0700)
Exposes existing netlink operations to modify link state of devices.

ip/ip_common.h
ip/ipaddress.c
ip/iplink.c
man/man8/ip-link.8

index b45c5eeff557ce8c78aa6524cda1df72101337fc..62884375aa75243a3916c87794b357b903511f97 100644 (file)
@@ -1,3 +1,4 @@
+extern int get_operstate(const char *name);
 extern int print_linkinfo(const struct sockaddr_nl *who,
                          struct nlmsghdr *n,
                          void *arg);
index aea1a8176b5baa207e405a4607c58fccd0ecf459..9306a372827d192ceb9f72fe05bfc7e8593ed6c5 100644 (file)
@@ -131,6 +131,16 @@ static void print_operstate(FILE *f, __u8 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])
 {
        int qlen;
index 814a92c94d0c3ba8bec8010d7c804ba8c340ec9f..a58e4d06787a687eb9b3c7468ff9219d95a36499 100644 (file)
@@ -433,10 +433,18 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req,
                } else if (strcmp(*argv, "mode") == 0) {
                        int mode;
                        NEXT_ARG();
-                       mode  = get_link_mode(*argv);
+                       mode  get_link_mode(*argv);
                        if (mode < 0)
                                invarg("Invalid link mode\n", *argv);
                        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 {
                        if (strcmp(*argv, "dev") == 0) {
                                NEXT_ARG();
index acc6d2876b24c167c7b3deaf2b8d930c0b4508b8..72f4cfd68036536f3ff74d048deaaea9e7981fe9 100644 (file)
@@ -103,6 +103,9 @@ ip-link \- network device configuration
 .B mode
 .IR LINKMODE " |"
 .br
+.B state
+.IR LINKSTATE " |"
+.br
 .B master
 .IR DEVICE
 .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
 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
 .BI alias " NAME"
 give the device a symbolic name for easy reference.