[v9,4/9] net: hoist flag setting code to its own function

Submitted by Tycho Andersen on Oct. 19, 2016, 4:15 p.m.

Details

Message ID 1476893715-24058-5-git-send-email-tycho.andersen@canonical.com
State Superseded
Series "Series without cover letter"
Headers show

Commit Message

Tycho Andersen Oct. 19, 2016, 4:15 p.m.
We'll use this in the next patch to set some macvlan flags.

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
---
 criu/net.c | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/net.c b/criu/net.c
index a6c73e5..4c502cd 100644
--- a/criu/net.c
+++ b/criu/net.c
@@ -989,6 +989,21 @@  static int bridge_link_info(NetDeviceEntry *nde, struct newlink_req *req)
 	return 0;
 }
 
+static int changeflags(int s, char *name, short flags)
+{
+	struct ifreq ifr;
+
+	strlcpy(ifr.ifr_name, name, IFNAMSIZ);
+	ifr.ifr_flags = flags;
+
+	if (ioctl(s, SIOCSIFFLAGS, &ifr) < 0) {
+		pr_perror("couldn't set flags on %s", name);
+		return -1;
+	}
+
+	return 0;
+}
+
 static int restore_link(NetDeviceEntry *nde, int nlsk)
 {
 	pr_info("Restoring link %s type %d\n", nde->name, nde->type);
@@ -1799,13 +1814,8 @@  static int move_to_bridge(struct external *ext, void *arg)
 			goto out;
 
 		ifr.ifr_flags |= IFF_UP;
-		ret = ioctl(s, SIOCSIFFLAGS, &ifr);
-		if (ret < 0) {
-			pr_perror("Can't set flags of interface %s to 0x%x",
-				out, ifr.ifr_flags);
+		if (changeflags(s, out, ifr.ifr_flags) < 0)
 			goto out;
-		}
-
 		ret = 0;
 	}
 out: