OSDN Git Service

Switch to ifc_add_address() for setcfg
authorErik Kline <ek@google.com>
Fri, 5 Feb 2016 09:06:15 +0000 (18:06 +0900)
committerLorenzo Colitti <lorenzo@google.com>
Tue, 16 Feb 2016 04:34:20 +0000 (13:34 +0900)
This avoids the issue where, for example, 10.0.0.1/8 is added first,
then 10.0.0.1/8 is deleted, and 10.0.0.1/24 is added.  Netlink changes
observed at the wrong time would make it seem as though IPv4 had
been lost when in fact everthing was fine.

Bug: 26991160

(cherry picked from commit 397fbc056c1ae1478f0311feab3a8a44cc6a4685)

Change-Id: Ia5a5fcdd01e0950ac099c2054d74f0c52aa20b9c

server/CommandListener.cpp

index 2c69333..af757c9 100644 (file)
@@ -357,18 +357,18 @@ int CommandListener::InterfaceCmd::runCommand(SocketClient *cli,
                 // Handle flags only case
                 index = 3;
             } else {
-                if (ifc_set_addr(argv[2], addr.s_addr)) {
-                    cli->sendMsg(ResponseCode::OperationFailed, "Failed to set address", true);
+                if (ifc_set_addr(argv[2], 0)) {
+                    cli->sendMsg(ResponseCode::OperationFailed, "Failed to clear address", true);
                     ifc_close();
                     return 0;
                 }
-
-                // Set prefix length on a non zero address
-                if (addr.s_addr != 0 && ifc_set_prefixLength(argv[2], atoi(argv[4]))) {
-                   cli->sendMsg(ResponseCode::OperationFailed, "Failed to set prefixLength", true);
-                   ifc_close();
-                   return 0;
-               }
+                if (addr.s_addr != 0) {
+                    if (ifc_add_address(argv[2], argv[3], atoi(argv[4]))) {
+                        cli->sendMsg(ResponseCode::OperationFailed, "Failed to set address", true);
+                        ifc_close();
+                        return 0;
+                    }
+                }
             }
 
             /* Process flags */