All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vitaliy Gusev <vgusev@openvz.org>
To: Stephen Hemminger <shemminger@linux-foundation.org>
Cc: netdev@vger.kernel.org, Pavel Emelyanov <xemul@openvz.org>,
	Patrick McHardy <kaber@trash.net>
Subject: [PATCH 2/2] Module for ip utility to support veth device
Date: Tue, 18 Dec 2007 15:15:38 +0300	[thread overview]
Message-ID: <200712181515.38565.vgusev@openvz.org> (raw)


module link_veth

Signed-off-by: Vitaliy Gusev <vgusev@openvz.org>

---

 link_veth.c |   76 +++++++++++++++++++-----------------------------------------
 veth.h      |    2 -
 2 files changed, 25 insertions(+), 53 deletions(-)

diff --git a/ip/link_veth.c b/ip/link_veth.c
index a4764f2..226b4ef 100644
--- a/ip/link_veth.c
+++ b/ip/link_veth.c
@@ -10,78 +10,52 @@
  *
  */
 
-#include <stdio.h>
 #include <string.h>
 
 #include "utils.h"
 #include "ip_common.h"
 #include "veth.h"
 
-#define ETH_ALEN	6
+#define	IFNAMSIZ	16
 
 static void usage(void)
 {
-	printf("Usage: ip link add ... type veth "
-			"[peer <peer-name>] [mac <mac>] [peer_mac <mac>]\n");
+	printf("Usage: ip link <options> type veth "
+		"[peer <options>]\nTo get <options> type "
+		"'ip link add help'\n");
 }
 
 static int veth_parse_opt(struct link_util *lu, int argc, char **argv,
 		struct nlmsghdr *hdr)
 {
-	__u8 mac[ETH_ALEN];
+	char *name, *type, *link, *dev;
+	int err, len;
+	struct rtattr * data;
 
-	for (; argc != 0; argv++, argc--) {
-		if (strcmp(*argv, "peer") == 0) {
-			argv++;
-			argc--;
-			if (argc == 0) {
-				usage();
-				return -1;
-			}
-
-			addattr_l(hdr, 1024, VETH_INFO_PEER,
-					*argv, strlen(*argv));
-
-			continue;
-		}
-
-		if (strcmp(*argv, "mac") == 0) {
-			argv++;
-			argc--;
-			if (argc == 0) {
-				usage();
-				return -1;
-			}
-
-			if (hexstring_a2n(*argv, mac, sizeof(mac)) == NULL)
-				return -1;
-
-			addattr_l(hdr, 1024, VETH_INFO_MAC,
-					mac, ETH_ALEN);
-			continue;
-		}
+	if (strcmp(argv[0], "peer") != 0) {
+		usage();
+		return -1;
+	}
 
-		if (strcmp(*argv, "peer_mac") == 0) {
-			argv++;
-			argc--;
-			if (argc == 0) {
-				usage();
-				return -1;
-			}
+	data = NLMSG_TAIL(hdr);
+	addattr_l(hdr, 1024, VETH_INFO_PEER, NULL, 0);
 
-			if (hexstring_a2n(*argv, mac, sizeof(mac)) == NULL)
-				return -1;
+	hdr->nlmsg_len += sizeof(struct ifinfomsg);
 
-			addattr_l(hdr, 1024, VETH_INFO_PEER_MAC,
-					mac, ETH_ALEN);
-			continue;
-		}
+	err = iplink_parse(argc - 1, argv + 1, (struct iplink_req *)hdr,
+			&name, &type, &link, &dev);
+	if (err < 0)
+		return err;
 
-		usage();
-		return -1;
+	if (name) {
+		len = strlen(name) + 1;
+		if (len > IFNAMSIZ)
+			invarg("\"name\" too long\n", *argv);
+		addattr_l(hdr, 1024, IFLA_IFNAME, name, len);
 	}
 
-	return 0;
+	data->rta_len = (void *)NLMSG_TAIL(hdr) - (void *)data;
+	return argc - 1 - err;
 }
 
 struct link_util veth_link_util = {
diff --git a/ip/veth.h b/ip/veth.h
index b84a530..aa2e6f9 100644
--- a/ip/veth.h
+++ b/ip/veth.h
@@ -3,9 +3,7 @@
 
 enum {
 	VETH_INFO_UNSPEC,
-	VETH_INFO_MAC,
 	VETH_INFO_PEER,
-	VETH_INFO_PEER_MAC,
 
 	__VETH_INFO_MAX
 #define VETH_INFO_MAX	(__VETH_INFO_MAX - 1)
-- 
Thank,
Vitaliy Gusev

             reply	other threads:[~2007-12-18 12:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-18 12:15 Vitaliy Gusev [this message]
2007-12-21 17:38 ` [PATCH 2/2] Module for ip utility to support veth device Stephen Hemminger
  -- strict thread matches above, loose matches on Subject: below --
2007-07-19  9:24 [PATCH] Virtual ethernet device (v.4) Pavel Emelyanov
2007-07-19  9:30 ` [PATCH] Module for ip utility to support veth device (v.3) Pavel Emelyanov
2007-07-19  9:33   ` [PATCH 2/2] Module for ip utility to support veth device Pavel Emelyanov
2007-07-12  9:13 [PATCH 0/2] Virtual ethernet device (v3) Pavel Emelianov
2007-07-12  9:21 ` [PATCH 0/2] Module for ip utility to support veth device (v.3) Pavel Emelianov
2007-07-12  9:25   ` [PATCH 2/2] Module for ip utility to support veth device Pavel Emelianov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200712181515.38565.vgusev@openvz.org \
    --to=vgusev@openvz.org \
    --cc=kaber@trash.net \
    --cc=netdev@vger.kernel.org \
    --cc=shemminger@linux-foundation.org \
    --cc=xemul@openvz.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.