[CRIU] [PATCH 4/4] iproute: Ability to create links with ifindex
Pavel Emelyanov
xemul at parallels.com
Thu Aug 2 00:51:38 EDT 2012
Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
include/utils.h | 2 +-
ip/iplink.c | 11 ++++++++---
ip/link_veth.c | 14 ++++++++------
3 files changed, 17 insertions(+), 10 deletions(-)
diff --git a/include/utils.h b/include/utils.h
index 496db68..f560ded 100644
--- a/include/utils.h
+++ b/include/utils.h
@@ -153,5 +153,5 @@ extern int makeargs(char *line, char *argv[], int maxargs);
struct iplink_req;
int iplink_parse(int argc, char **argv, struct iplink_req *req,
char **name, char **type, char **link, char **dev,
- int *group);
+ int *group, int *index);
#endif /* __UTILS_H__ */
diff --git a/ip/iplink.c b/ip/iplink.c
index 679091e..3238530 100644
--- a/ip/iplink.c
+++ b/ip/iplink.c
@@ -271,7 +271,7 @@ int iplink_parse_vf(int vf, int *argcp, char ***argvp,
int iplink_parse(int argc, char **argv, struct iplink_req *req,
- char **name, char **type, char **link, char **dev, int *group)
+ char **name, char **type, char **link, char **dev, int *group, int *index)
{
int ret, len;
char abuf[32];
@@ -445,6 +445,9 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req,
invarg("Invalid operstate\n", *argv);
addattr8(&req->n, sizeof(*req), IFLA_OPERSTATE, state);
+ } else if (strcmp(*argv, "index") == 0) {
+ NEXT_ARG();
+ *index = atoi(*argv);
} else {
if (strcmp(*argv, "dev") == 0) {
NEXT_ARG();
@@ -471,7 +474,7 @@ static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv)
int group;
struct link_util *lu = NULL;
struct iplink_req req;
- int ret;
+ int ret, index = 0;
memset(&req, 0, sizeof(req));
@@ -480,7 +483,7 @@ static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv)
req.n.nlmsg_type = cmd;
req.i.ifi_family = preferred_family;
- ret = iplink_parse(argc, argv, &req, &name, &type, &link, &dev, &group);
+ ret = iplink_parse(argc, argv, &req, &name, &type, &link, &dev, &group, &index);
if (ret < 0)
return ret;
@@ -542,6 +545,8 @@ static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv)
}
addattr_l(&req.n, sizeof(req), IFLA_LINK, &ifindex, 4);
}
+
+ req.i.ifi_index = index;
}
if (name) {
diff --git a/ip/link_veth.c b/ip/link_veth.c
index 3d19b01..83e82f6 100644
--- a/ip/link_veth.c
+++ b/ip/link_veth.c
@@ -31,22 +31,24 @@ static int veth_parse_opt(struct link_util *lu, int argc, char **argv,
int err, len;
struct rtattr * data;
int group;
+ int index = 0;
+ struct ifinfomsg ifmp;
if (strcmp(argv[0], "peer") != 0) {
usage();
return -1;
}
- data = NLMSG_TAIL(hdr);
- addattr_l(hdr, 1024, VETH_INFO_PEER, NULL, 0);
-
- hdr->nlmsg_len += sizeof(struct ifinfomsg);
-
err = iplink_parse(argc - 1, argv + 1, (struct iplink_req *)hdr,
- &name, &type, &link, &dev, &group);
+ &name, &type, &link, &dev, &group, &index);
if (err < 0)
return err;
+ data = NLMSG_TAIL(hdr);
+ memset(&ifmp, 0, sizeof(ifmp));
+ ifmp.ifi_index = index;
+ addattr_l(hdr, 1024, VETH_INFO_PEER, &ifmp, sizeof(ifmp));
+
if (name) {
len = strlen(name) + 1;
if (len > IFNAMSIZ)
--
1.7.1
More information about the CRIU
mailing list