* [PATCH 2/2] Module for ip utility to support veth device
@ 2007-12-18 12:15 Vitaliy Gusev
2007-12-21 17:38 ` Stephen Hemminger
0 siblings, 1 reply; 4+ messages in thread
From: Vitaliy Gusev @ 2007-12-18 12:15 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: netdev, Pavel Emelyanov, Patrick McHardy
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
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH] Virtual ethernet device (v.4)
@ 2007-07-19 9:24 Pavel Emelyanov
2007-07-19 9:30 ` [PATCH] Module for ip utility to support veth device (v.3) Pavel Emelyanov
0 siblings, 1 reply; 4+ messages in thread
From: Pavel Emelyanov @ 2007-07-19 9:24 UTC (permalink / raw)
To: David Miller, Patrick McHardy; +Cc: Linux Netdev List, devel
Veth stands for Virtual ETHernet. It is a simple tunnel driver
that works at the link layer and looks like a pair of ethernet
devices interconnected with each other.
Mainly it allows to communicate between network namespaces but
it can be used as is as well. E.g. one may join to bridged
networking segments together.
Eric recently sent a similar driver called etun with the sysfs
interface. This implementation uses another interface - the
RTM_NRELINK message introduced by Patric.
The newlink callback is organized that way to make it easy to
create the peer device in the separate namespace when we have
them in kernel.
Many thanks to Patrick for reviewing the patches and his advises
on how to make driver cleaner.
Changes from v.3:
* Reserved place for struct ifinfomsg in IFLA_INFO_DATA part
of the packet. This is not used yet, but may be in the
future.
Changes from v.2.1:
* Made the generic routine for link creation to be used
by veth driver, any other tunnel driver that needs to
create several devices at once and rtnl_newlink() code.
Changes from v.2:
* Rebase over latest netdev tree. No actual changes;
* Small code rework.
Changes from v.1:
* Per-cpu statistics;
* Standard convention for nla policy names;
* Module alias added;
* Xmit function fixes noticed by Patric;
* Code cleanup.
The patch for an ip utility is also provided.
Signed-off-by: Pavel Emelianov <xemul@openvz.org>
Acked-by: Patrick McHardy <kaber@trash.net>
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] Module for ip utility to support veth device (v.3)
2007-07-19 9:24 [PATCH] Virtual ethernet device (v.4) Pavel Emelyanov
@ 2007-07-19 9:30 ` Pavel Emelyanov
2007-07-19 9:33 ` [PATCH 2/2] Module for ip utility to support veth device Pavel Emelyanov
0 siblings, 1 reply; 4+ messages in thread
From: Pavel Emelyanov @ 2007-07-19 9:30 UTC (permalink / raw)
To: David Miller, Patrick McHardy; +Cc: Linux Netdev List, devel
The usage is
# ip link add [name] type veth [device parameters] peer [name <name> <other device params>]
This consists of two parts:
1/2 makes some copy-paste changes in ip/iplink.c for generic CLI
attributes parsing,
2/2 the module itself.
Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
Acked-by: Patrick McHardy <kaber@trash.net>
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 2/2] Module for ip utility to support veth device
2007-07-19 9:30 ` [PATCH] Module for ip utility to support veth device (v.3) Pavel Emelyanov
@ 2007-07-19 9:33 ` Pavel Emelyanov
0 siblings, 0 replies; 4+ messages in thread
From: Pavel Emelyanov @ 2007-07-19 9:33 UTC (permalink / raw)
To: David Miller, Patrick McHardy; +Cc: Linux Netdev List, devel
The link_veth.so itself.
Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
Acked-by: Patrick McHardy <kaber@trash.net>
---
Makefile | 6 ++++-
link_veth.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
veth.h | 12 +++++++++++
3 files changed, 80 insertions(+), 1 deletion(-)
diff --git a/ip/Makefile b/ip/Makefile
index 9a5bfe3..b46bce3 100644
--- a/ip/Makefile
+++ b/ip/Makefile
@@ -8,8 +8,9 @@ RTMONOBJ=rtmon.o
ALLOBJ=$(IPOBJ) $(RTMONOBJ)
SCRIPTS=ifcfg rtpr routel routef
TARGETS=ip rtmon
+LIBS=link_veth.so
-all: $(TARGETS) $(SCRIPTS)
+all: $(TARGETS) $(SCRIPTS) $(LIBS)
ip: $(IPOBJ) $(LIBNETLINK) $(LIBUTIL)
@@ -24,3 +25,6 @@ clean:
LDLIBS += -ldl
LDFLAGS += -Wl,-export-dynamic
+
+%.so: %.c
+ $(CC) $(CFLAGS) -shared $< -o $@
diff --git a/ip/link_veth.c b/ip/link_veth.c
new file mode 100644
index 0000000..ded2cdd
--- /dev/null
+++ b/ip/link_veth.c
@@ -0,0 +1,63 @@
+/*
+ * link_veth.c veth driver module
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ *
+ * Authors: Pavel Emelianov <xemul@openvz.org>
+ *
+ */
+
+#include <string.h>
+
+#include "utils.h"
+#include "ip_common.h"
+#include "veth.h"
+
+#define IFNAMSIZ 16
+
+static void usage(void)
+{
+ printf("Usage: ip link add ... type veth "
+ "[peer <peer-name>] [mac <mac>] [peer_mac <mac>]\n");
+}
+
+static int veth_parse_opt(struct link_util *lu, int argc, char **argv,
+ struct nlmsghdr *hdr)
+{
+ char *name, *type, *link, *dev;
+ int err, len;
+ struct rtattr * data;
+
+ 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);
+ if (err < 0)
+ return err;
+
+ if (name) {
+ len = strlen(name) + 1;
+ if (len > IFNAMSIZ)
+ invarg("\"name\" too long\n", *argv);
+ addattr_l(hdr, 1024, IFLA_IFNAME, name, len);
+ }
+
+ data->rta_len = (void *)NLMSG_TAIL(hdr) - (void *)data;
+ return argc - 1 - err;
+}
+
+struct link_util veth_link_util = {
+ .id = "veth",
+ .parse_opt = veth_parse_opt,
+};
diff --git a/ip/veth.h b/ip/veth.h
new file mode 100644
index 0000000..aa2e6f9
--- /dev/null
+++ b/ip/veth.h
@@ -0,0 +1,12 @@
+#ifndef __NET_VETH_H__
+#define __NET_VETH_H__
+
+enum {
+ VETH_INFO_UNSPEC,
+ VETH_INFO_PEER,
+
+ __VETH_INFO_MAX
+#define VETH_INFO_MAX (__VETH_INFO_MAX - 1)
+};
+
+#endif
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 0/2] Virtual ethernet device (v3)
@ 2007-07-12 9:13 Pavel Emelianov
2007-07-12 9:21 ` [PATCH 0/2] Module for ip utility to support veth device (v.3) Pavel Emelianov
0 siblings, 1 reply; 4+ messages in thread
From: Pavel Emelianov @ 2007-07-12 9:13 UTC (permalink / raw)
To: David Miller, Patrick McHardy; +Cc: Linux Netdev List
Veth stands for Virtual ETHernet. It is a simple tunnel driver
that works at the link layer and looks like a pair of ethernet
devices interconnected with each other.
Mainly it allows to communicate between network namespaces but
it can be used as is as well.
Eric recently sent a similar driver called etun with the sysfs
interface. This implementation uses another interface - the
RTM_NRELINK message introduced by Patric.
The newlink callback is organized that way to make it easy to
create the peer device in the separate namespace when we have
them in kernel.
Changes from v.2.1:
* Made the generic routine for link creation to be used
by veth driver, any other tunnel driver that needs to
create several devices at once and rtnl_newlink() code.
Changes from v.2:
* Rebase over latest netdev tree. No actual changes;
* Small code rework.
Changes from v.1:
* percpu statistics;
* standard convention for nla policy names;
* module alias added;
* xmit function fixes noticed by Patric;
* code cleanup.
The patch for an ip utility is also provided.
Signed-off-by: Pavel Emelianov <xemul@openvz.org>
Cc: Patrick McHardy <kaber@trash.net>
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 0/2] Module for ip utility to support veth device (v.3)
2007-07-12 9:13 [PATCH 0/2] Virtual ethernet device (v3) Pavel Emelianov
@ 2007-07-12 9:21 ` Pavel Emelianov
2007-07-12 9:25 ` [PATCH 2/2] Module for ip utility to support veth device Pavel Emelianov
0 siblings, 1 reply; 4+ messages in thread
From: Pavel Emelianov @ 2007-07-12 9:21 UTC (permalink / raw)
To: David Miller, Patrick McHardy; +Cc: Linux Netdev List
The usage is
# ip link add [name] type veth [peer <name>] [mac <mac>] [peer_mac <mac>]
This consists of two parts:
1/2 makes some copy-paste changes in ip/iplink.c for generic CLI
attributes parsing,
2/2 the module itself.
Signed-off-by: Pavel Emelianov <xemul@openvz.org>
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 2/2] Module for ip utility to support veth device
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 ` Pavel Emelianov
0 siblings, 0 replies; 4+ messages in thread
From: Pavel Emelianov @ 2007-07-12 9:25 UTC (permalink / raw)
To: David Miller, Patrick McHardy; +Cc: Linux Netdev List
The link_veth.so itself.
The usage is
ip link add <name> type veth [peer ...]
where ... are the same options as in regular ip link add usage.
Signed-off-by: Pavel Emelianov <xemul@openvz.org>
---
Makefile | 6 +++++-
link_veth.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
veth.h | 12 ++++++++++++
3 files changed, 77 insertions(+), 1 deletion(-)
diff --git a/ip/Makefile b/ip/Makefile
index 9a5bfe3..b46bce3 100644
--- a/ip/Makefile
+++ b/ip/Makefile
@@ -8,8 +8,9 @@ RTMONOBJ=rtmon.o
ALLOBJ=$(IPOBJ) $(RTMONOBJ)
SCRIPTS=ifcfg rtpr routel routef
TARGETS=ip rtmon
+LIBS=link_veth.so
-all: $(TARGETS) $(SCRIPTS)
+all: $(TARGETS) $(SCRIPTS) $(LIBS)
ip: $(IPOBJ) $(LIBNETLINK) $(LIBUTIL)
@@ -24,3 +25,6 @@ clean:
LDLIBS += -ldl
LDFLAGS += -Wl,-export-dynamic
+
+%.so: %.c
+ $(CC) $(CFLAGS) -shared $< -o $@
diff --git a/ip/link_veth.c b/ip/link_veth.c
new file mode 100644
index 0000000..0ceab86
--- /dev/null
+++ b/ip/link_veth.c
@@ -0,0 +1,60 @@
+/*
+ * link_veth.c veth driver module
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ *
+ * Authors: Pavel Emelianov <xemul@openvz.org>
+ *
+ */
+
+#include <string.h>
+
+#include "utils.h"
+#include "ip_common.h"
+#include "veth.h"
+
+#define IFNAMSIZ 16
+
+static void usage(void)
+{
+ printf("Usage: ip link add ... type veth "
+ "[peer <peer-name>] [mac <mac>] [peer_mac <mac>]\n");
+}
+
+static int veth_parse_opt(struct link_util *lu, int argc, char **argv,
+ struct nlmsghdr *hdr)
+{
+ char *name, *type, *link, *dev;
+ int err, len;
+ struct rtattr * data = NLMSG_TAIL(hdr);
+
+ if (strcmp(argv[0], "peer") != 0) {
+ usage();
+ return -1;
+ }
+
+ addattr_l(hdr, 1024, VETH_INFO_PEER, NULL, 0);
+
+ err = iplink_parse(argc - 1, argv + 1, (struct iplink_req *)hdr,
+ &name, &type, &link, &dev);
+ if (err < 0)
+ return err;
+
+ if (name) {
+ len = strlen(name) + 1;
+ if (len > IFNAMSIZ)
+ invarg("\"name\" too long\n", *argv);
+ addattr_l(hdr, 1024, IFLA_IFNAME, name, len);
+ }
+
+ data->rta_len = (void *)NLMSG_TAIL(hdr) - (void *)data;
+ return argc - 1 - err;
+}
+
+struct link_util veth_link_util = {
+ .id = "veth",
+ .parse_opt = veth_parse_opt,
+};
diff --git a/ip/veth.h b/ip/veth.h
new file mode 100644
index 0000000..aa2e6f9
--- /dev/null
+++ b/ip/veth.h
@@ -0,0 +1,12 @@
+#ifndef __NET_VETH_H__
+#define __NET_VETH_H__
+
+enum {
+ VETH_INFO_UNSPEC,
+ VETH_INFO_PEER,
+
+ __VETH_INFO_MAX
+#define VETH_INFO_MAX (__VETH_INFO_MAX - 1)
+};
+
+#endif
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2007-12-21 17:39 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-12-18 12:15 [PATCH 2/2] Module for ip utility to support veth device Vitaliy Gusev
2007-12-21 17:38 ` 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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox