]> rtime.felk.cvut.cz Git - lisovros/iproute2_canprio.git/blobdiff - ip/iptunnel.c
iproute2: man page and /bin/ip disagree on del vs delete
[lisovros/iproute2_canprio.git] / ip / iptunnel.c
index 1cd9fbd68e6b694baad802d45a1681e6a902d083..38ccd87c7191bb53ab64770258904683af80c293 100644 (file)
@@ -18,8 +18,8 @@
 #include <sys/socket.h>
 #include <arpa/inet.h>
 #include <sys/ioctl.h>
-#include <linux/if.h>
-#include <linux/if_arp.h>
+#include <net/if.h>
+#include <net/if_arp.h>
 #include <linux/ip.h>
 #include <linux/if_tunnel.h>
 
@@ -231,7 +231,7 @@ static int parse_args(int argc, char **argv, int cmd, struct ip_tunnel_parm *p)
        }
 
        if (medium[0]) {
-               p->link = tnl_ioctl_get_ifindex(medium);
+               p->link = if_nametoindex(medium);
                if (p->link == 0)
                        return -1;
        }
@@ -306,12 +306,8 @@ static void print_tunnel(struct ip_tunnel_parm *p)
        struct ip_tunnel_6rd ip6rd;
        char s1[1024];
        char s2[1024];
-       char s3[64];
-       char s4[64];
 
        memset(&ip6rd, 0, sizeof(ip6rd));
-       inet_ntop(AF_INET, &p->i_key, s3, sizeof(s3));
-       inet_ntop(AF_INET, &p->o_key, s4, sizeof(s4));
 
        /* Do not use format_host() for local addr,
         * symbolic name will not be useful.
@@ -342,7 +338,7 @@ static void print_tunnel(struct ip_tunnel_parm *p)
        }
 
        if (p->link) {
-               char *n = tnl_ioctl_get_ifname(p->link);
+               const char *n = ll_index_to_name(p->link);
                if (n)
                        printf(" dev %s ", n);
        }
@@ -365,7 +361,7 @@ static void print_tunnel(struct ip_tunnel_parm *p)
        if (!(p->iph.frag_off&htons(IP_DF)))
                printf(" nopmtudisc");
 
-       if (!tnl_ioctl_get_6rd(p->name, &ip6rd) && ip6rd.prefixlen) {
+       if (p->iph.protocol == IPPROTO_IPV6 && !tnl_ioctl_get_6rd(p->name, &ip6rd) && ip6rd.prefixlen) {
                printf(" 6rd-prefix %s/%u ",
                       inet_ntop(AF_INET6, &ip6rd.prefix, s1, sizeof(s1)),
                       ip6rd.prefixlen);
@@ -377,12 +373,12 @@ static void print_tunnel(struct ip_tunnel_parm *p)
        }
 
        if ((p->i_flags&GRE_KEY) && (p->o_flags&GRE_KEY) && p->o_key == p->i_key)
-               printf(" key %s", s3);
+               printf(" key %u", ntohl(p->i_key));
        else if ((p->i_flags|p->o_flags)&GRE_KEY) {
                if (p->i_flags&GRE_KEY)
-                       printf(" ikey %s ", s3);
+                       printf(" ikey %u ", ntohl(p->i_key));
                if (p->o_flags&GRE_KEY)
-                       printf(" okey %s ", s4);
+                       printf(" okey %u ", ntohl(p->o_key));
        }
 
        if (p->i_flags&GRE_SEQ)
@@ -402,7 +398,6 @@ static int do_tunnels_list(struct ip_tunnel_parm *p)
        rx_fifo, rx_frame,
        tx_bytes, tx_packets, tx_errs, tx_drops,
        tx_fifo, tx_colls, tx_carrier, rx_multi;
-       int type;
        struct ip_tunnel_parm p1;
 
        char buf[512];
@@ -412,15 +407,22 @@ static int do_tunnels_list(struct ip_tunnel_parm *p)
                return -1;
        }
 
-       fgets(buf, sizeof(buf), fp);
-       fgets(buf, sizeof(buf), fp);
+       /* skip header lines */
+       if (!fgets(buf, sizeof(buf), fp) ||
+           !fgets(buf, sizeof(buf), fp)) {
+               fprintf(stderr, "/proc/net/dev read error\n");
+               fclose(fp);
+               return -1;
+       }
 
        while (fgets(buf, sizeof(buf), fp) != NULL) {
+               int index, type;
                char *ptr;
                buf[sizeof(buf) - 1] = 0;
                if ((ptr = strchr(buf, ':')) == NULL ||
                    (*ptr++ = 0, sscanf(buf, "%s", name) != 1)) {
                        fprintf(stderr, "Wrong format of /proc/net/dev. Sorry.\n");
+                       fclose(fp);
                        return -1;
                }
                if (sscanf(ptr, "%ld%ld%ld%ld%ld%ld%ld%*d%ld%ld%ld%ld%ld%ld%ld",
@@ -431,7 +433,10 @@ static int do_tunnels_list(struct ip_tunnel_parm *p)
                        continue;
                if (p->name[0] && strcmp(p->name, name))
                        continue;
-               type = tnl_ioctl_get_iftype(name);
+               index = ll_name_to_index(name);
+               if (index == 0)
+                       continue;
+               type = ll_index_to_type(index);
                if (type == -1) {
                        fprintf(stderr, "Failed to get type of [%s]\n", name);
                        continue;
@@ -459,6 +464,7 @@ static int do_tunnels_list(struct ip_tunnel_parm *p)
                }
                printf("\n");
        }
+       fclose(fp);
        return 0;
 }
 
@@ -467,6 +473,7 @@ static int do_show(int argc, char **argv)
        int err;
        struct ip_tunnel_parm p;
 
+       ll_init_map(&rth);
        if (parse_args(argc, argv, SIOCGETTUNNEL, &p) < 0)
                return -1;
 
@@ -613,7 +620,7 @@ int do_iptunnel(int argc, char **argv)
                        return do_add(SIOCADDTUNNEL, argc-1, argv+1);
                if (matches(*argv, "change") == 0)
                        return do_add(SIOCCHGTUNNEL, argc-1, argv+1);
-               if (matches(*argv, "del") == 0)
+               if (matches(*argv, "delete") == 0)
                        return do_del(argc-1, argv+1);
                if (matches(*argv, "show") == 0 ||
                    matches(*argv, "lst") == 0 ||