[PATCH] Module for ip utility to support veth device (v.4)

2007-12-18 Thread Vitaliy Gusev
The usage is
# ip link add [name]  [device parameters] type veth [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 [EMAIL PROTECTED]

--
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/2] Introduce iplink_parse() routine

2007-12-18 Thread Vitaliy Gusev
;
+   char *link = NULL;
+   char *type = NULL;
+   struct link_util *lu = NULL;
+   struct iplink_req req;
+   int ret;
+
+   memset(req, 0, sizeof(req));
+
+   req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
+   req.n.nlmsg_flags = NLM_F_REQUEST|flags;
+   req.n.nlmsg_type = cmd;
+   req.i.ifi_family = preferred_family;
+
+   ret = iplink_parse(argc, argv, req, name, type, link, dev);
+   if (ret  0)
+   return ret;
+
+   argc -= ret;
+   argv += ret;
ll_init_map(rth);
 
if (type) {
-- 
Thank,
Vitaliy Gusev
--
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/2] Module for ip utility to support veth device

2007-12-18 Thread Vitaliy Gusev

module link_veth

Signed-off-by: Vitaliy Gusev [EMAIL PROTECTED]

---

 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
+#defineIFNAMSIZ16
 
 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
--
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] Fix lost export-dynamic

2007-12-17 Thread Vitaliy Gusev
get_link_kind() fails for statically linked modules (vlan, veth, etc.) if ip 
was linked without export-dynamic.

Signed-off-by: Vitaliy Gusev [EMAIL PROTECTED]

-- 
Thank,
Vitaliy Gusev
diff --git a/ip/Makefile b/ip/Makefile
index 448efb9..b427d58 100644
--- a/ip/Makefile
+++ b/ip/Makefile
@@ -24,3 +24,5 @@ clean:
rm -f $(ALLOBJ) $(TARGETS)
 
 LDLIBS += -ldl
+
+LDFLAGS += -Wl,-export-dynamic