Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sbin/route add MPLS clue - mpls and tag keywords



details:   https://anonhg.NetBSD.org/src/rev/918cd8cd5ca7
branches:  trunk
changeset: 755884:918cd8cd5ca7
user:      kefren <kefren%NetBSD.org@localhost>
date:      Sat Jun 26 14:29:36 2010 +0000

description:
add MPLS clue - mpls and tag keywords

diffstat:

 sbin/route/keywords.c  |   8 +++--
 sbin/route/keywords.h  |   4 ++-
 sbin/route/keywords.sh |   4 ++-
 sbin/route/route.c     |  72 +++++++++++++++++++++++++++++++++++++++++++++----
 sbin/route/show.c      |  25 +++++++++++++++-
 5 files changed, 100 insertions(+), 13 deletions(-)

diffs (truncated from 320 to 300 lines):

diff -r 6c7f52164682 -r 918cd8cd5ca7 sbin/route/keywords.c
--- a/sbin/route/keywords.c     Sat Jun 26 14:27:55 2010 +0000
+++ b/sbin/route/keywords.c     Sat Jun 26 14:29:36 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: keywords.c,v 1.7 2010/05/12 17:56:13 christos Exp $ */
+/* $NetBSD: keywords.c,v 1.8 2010/06/26 14:29:36 kefren Exp $ */
 
 /* WARNING!  This file was generated by keywords.sh  */
 
@@ -12,8 +12,6 @@
        {"change", K_CHANGE},
        {"cloned", K_CLONED},
        {"cloning", K_CLONING},
-       {"nocloned", K_NOCLONED},
-       {"nocloning", K_NOCLONING},
        {"delete", K_DELETE},
        {"dst", K_DST},
        {"expire", K_EXPIRE},
@@ -57,8 +55,12 @@
        {"xns", K_XNS},
        {"xresolve", K_XRESOLVE},
        {"flushall", K_FLUSHALL},
+       {"nocloned", K_NOCLONED},
+       {"nocloning", K_NOCLONING},
        {"noblackhole", K_NOBLACKHOLE},
        {"noreject", K_NOREJECT},
+       {"mpls", K_MPLS},
+       {"tag", K_TAG},
        {0, 0}
 };
 
diff -r 6c7f52164682 -r 918cd8cd5ca7 sbin/route/keywords.h
--- a/sbin/route/keywords.h     Sat Jun 26 14:27:55 2010 +0000
+++ b/sbin/route/keywords.h     Sat Jun 26 14:29:36 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: keywords.h,v 1.10 2010/05/12 17:56:13 christos Exp $ */
+/* $NetBSD: keywords.h,v 1.11 2010/06/26 14:29:36 kefren Exp $ */
 
 /* WARNING!  This file was generated by keywords.sh  */
 
@@ -61,3 +61,5 @@
 #define        K_NOCLONING     51
 #define        K_NOBLACKHOLE   52
 #define        K_NOREJECT      53
+#define        K_MPLS  54
+#define        K_TAG   55
diff -r 6c7f52164682 -r 918cd8cd5ca7 sbin/route/keywords.sh
--- a/sbin/route/keywords.sh    Sat Jun 26 14:27:55 2010 +0000
+++ b/sbin/route/keywords.sh    Sat Jun 26 14:29:36 2010 +0000
@@ -1,5 +1,5 @@
 #!/bin/sh
-# $NetBSD: keywords.sh,v 1.8 2010/05/12 19:26:33 kefren Exp $
+# $NetBSD: keywords.sh,v 1.9 2010/06/26 14:29:36 kefren Exp $
 # @(#)keywords 8.2 (Berkeley) 3/19/94
 #
 # WARNING!  If you change this file, re-run it!
@@ -61,6 +61,8 @@
 nocloning
 noblackhole
 noreject
+mpls
+tag
 _EOF_
 
 
diff -r 6c7f52164682 -r 918cd8cd5ca7 sbin/route/route.c
--- a/sbin/route/route.c        Sat Jun 26 14:27:55 2010 +0000
+++ b/sbin/route/route.c        Sat Jun 26 14:29:36 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: route.c,v 1.120 2010/05/12 17:56:13 christos Exp $     */
+/*     $NetBSD: route.c,v 1.121 2010/06/26 14:29:36 kefren Exp $       */
 
 /*
  * Copyright (c) 1983, 1989, 1991, 1993
@@ -39,7 +39,7 @@
 #if 0
 static char sccsid[] = "@(#)route.c    8.6 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: route.c,v 1.120 2010/05/12 17:56:13 christos Exp $");
+__RCSID("$NetBSD: route.c,v 1.121 2010/06/26 14:29:36 kefren Exp $");
 #endif
 #endif /* not lint */
 
@@ -57,6 +57,7 @@
 #include <netinet/in.h>
 #include <netatalk/at.h>
 #include <netiso/iso.h>
+#include <netmpls/mpls.h>
 #include <arpa/inet.h>
 #include <netdb.h>
 
@@ -83,13 +84,14 @@
        struct  sockaddr_dl sdl;
 #ifndef SMALL
        struct  sockaddr_iso siso;
+       struct  sockaddr_mpls smpls;
 #endif /* SMALL */
 };
 
 typedef union sockunion *sup;
 
 struct sou {
-       union sockunion so_dst, so_gate, so_mask, so_genmask, so_ifa, so_ifp;
+       union sockunion so_dst, so_gate, so_mask, so_genmask, so_ifa, so_ifp, so_mpls;
 };
 
 static char *any_ntoa(const struct sockaddr *);
@@ -121,7 +123,7 @@
 int    pid, rtm_addrs;
 int    sock;
 int    forcehost, forcenet, doflush, nflag, af, qflag, tflag, Sflag;
-int    iflag, verbose, aflen = sizeof(struct sockaddr_in);
+int    iflag, verbose, aflen = sizeof(struct sockaddr_in), rtag;
 int    locking, lockrest, debugonly, shortoutput;
 struct rt_metrics rt_metrics;
 u_int32_t  rtm_inits;
@@ -575,6 +577,16 @@
                    ((const struct sockaddr_at *)sa)->sat_addr.s_net,
                    ((const struct sockaddr_at *)sa)->sat_addr.s_node);
                break;
+       case AF_MPLS:
+               {
+               union mpls_shim ms;
+
+               ms.s_addr =((const struct sockaddr_mpls*)sa)->smpls_addr.s_addr;
+               ms.s_addr = ntohl(ms.s_addr);
+
+               snprintf(line, sizeof(line), "%u", ms.shim.label);
+               break;
+               }
 #endif /* SMALL */
 
        default:
@@ -819,6 +831,16 @@
                                af = AF_ISO;
                                aflen = sizeof(struct sockaddr_iso);
                                break;
+                       case K_MPLS:
+                               af = AF_MPLS;
+                               aflen = sizeof(struct sockaddr_mpls);
+                               break;
+                       case K_TAG:
+                               if (!--argc)
+                                       usage(1+*argv);
+                               aflen = sizeof(struct sockaddr_mpls);
+                               (void)getaddr(RTA_TAG, *++argv, 0, soup);
+                               break;
 #endif /* SMALL */
 
                        case K_IFACE:
@@ -1140,6 +1162,10 @@
                su = &soup->so_ifa;
                su->sa.sa_family = af;
                break;
+       case RTA_TAG:
+               su = &soup->so_mpls;
+               afamily = AF_MPLS;
+               break;
        default:
                su = NULL;
                usage("Internal Error");
@@ -1245,6 +1271,17 @@
                su->sat.sat_addr.s_node = val;
                rtm_addrs |= RTA_NETMASK;
                return(forcehost || su->sat.sat_addr.s_node != 0);
+       case AF_MPLS:
+               /* Tag should be a positive value, limited to 20 bits */
+               if (atoi(s) < 0 || atoi(s) >= (1 << 20))
+                       errx(1, "bad tag: %s", s);
+               su->smpls.smpls_addr.s_addr = 0;
+               su->smpls.smpls_addr.shim.label = atoi(s);
+               su->smpls.smpls_addr.s_addr =
+                       htonl(su->smpls.smpls_addr.s_addr);
+
+               /* We don't have netmasks for tags  */
+               return 1;
 #endif
 
        case AF_LINK:
@@ -1468,6 +1505,7 @@
        NEXTADDR(RTA_GENMASK, soup->so_genmask);
        NEXTADDR(RTA_IFP, soup->so_ifp);
        NEXTADDR(RTA_IFA, soup->so_ifa);
+       NEXTADDR(RTA_TAG, soup->so_mpls);
        rtm.rtm_msglen = l = cp - (char *)&m_rtmsg;
        if (verbose && ! shortoutput) {
                if (rtm_addrs)
@@ -1574,7 +1612,7 @@
 const char ifnetflags[] =
 "\1UP\2BROADCAST\3DEBUG\4LOOPBACK\5PTP\6NOTRAILERS\7RUNNING\010NOARP\011PPROMISC\012ALLMULTI\013OACTIVE\014SIMPLEX\015LINK0\016LINK1\017LINK2\020MULTICAST";
 const char addrnames[] =
-"\1DST\2GATEWAY\3NETMASK\4GENMASK\5IFP\6IFA\7AUTHOR\010BRD";
+"\1DST\2GATEWAY\3NETMASK\4GENMASK\5IFP\6IFA\7AUTHOR\010BRD\011TAG";
 
 
 #ifndef SMALL
@@ -1739,7 +1777,7 @@
 static int
 print_getmsg(struct rt_msghdr *rtm, int msglen, struct sou *soup)
 {
-       struct sockaddr *dst = NULL, *gate = NULL, *mask = NULL, *ifa = NULL;
+       struct sockaddr *dst = NULL, *gate = NULL, *mask = NULL, *ifa = NULL, *mpls = NULL;
        struct sockaddr_dl *ifp = NULL;
        struct sockaddr *sa;
        char *cp;
@@ -1785,6 +1823,9 @@
                                case RTA_IFA:
                                        ifa = sa;
                                        break;
+                               case RTA_TAG:
+                                       mpls = sa;
+                                       break;
                                }
                                ADVANCE(cp, sa);
                        }
@@ -1812,6 +1853,17 @@
                } else
                        (void)printf("    gateway: %s\n", name);
        }
+       if (mpls) {
+               const char *name;
+               name = routename(mpls, NULL, RTF_HOST);
+               if(shortoutput) {
+                       if (*name == '\0')
+                               return 1;
+                       printf("%s\n", name);
+               } else
+                       printf("        Tag: %s\n", name);
+       }
+               
        if (ifa && ! shortoutput)
                (void)printf(" local addr: %s\n",
                    routename(ifa, NULL, RTF_HOST));
@@ -1986,6 +2038,14 @@
                (void)printf("%s: iso %s; ",
                    which, iso_ntoa(&su->siso.siso_addr));
                break;
+       case AF_MPLS:
+               {
+               union mpls_shim ms;
+               ms.s_addr = ntohl(su->smpls.smpls_addr.s_addr);
+               printf("%s: mpls %u; ",
+                   which, ms.shim.label);
+               }
+               break;
 #endif /* SMALL */
        default:
                (void)printf("%s: (%d) %s; ",
diff -r 6c7f52164682 -r 918cd8cd5ca7 sbin/route/show.c
--- a/sbin/route/show.c Sat Jun 26 14:27:55 2010 +0000
+++ b/sbin/route/show.c Sat Jun 26 14:29:36 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: show.c,v 1.40 2010/01/26 21:27:54 is Exp $     */
+/*     $NetBSD: show.c,v 1.41 2010/06/26 14:29:36 kefren Exp $ */
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)route.c      8.3 (Berkeley) 3/9/94";
 #else
-__RCSID("$NetBSD: show.c,v 1.40 2010/01/26 21:27:54 is Exp $");
+__RCSID("$NetBSD: show.c,v 1.41 2010/06/26 14:29:36 kefren Exp $");
 #endif
 #endif /* not lint */
 
@@ -43,11 +43,13 @@
 #include <sys/socket.h>
 #include <sys/mbuf.h>
 
+#include <arpa/inet.h>
 #include <net/if.h>
 #include <net/if_dl.h>
 #include <net/if_types.h>
 #include <net/route.h>
 #include <netinet/in.h>
+#include <netmpls/mpls.h>
 
 #include <sys/sysctl.h>
 
@@ -138,6 +140,10 @@
                        af = AF_ISO;
                        afname = argv[argc - 1] + 1;
                        break;
+               case K_MPLS:
+                       af = AF_MPLS;
+                       afname = argv[argc - 1] + 1;
+                       break;
 #endif /* SMALL */
                case K_LINK:
                        if (nolink)
@@ -319,6 +325,9 @@
        case AF_ISO:
                afname = "ISO";
                break;
+       case AF_MPLS:
+               afname = "MPLS";
+               break;
 #endif /* SMALL */
        case AF_APPLETALK:



Home | Main Index | Thread Index | Old Index