added three new flags for link layer control (LLC)
[unix-history] / usr / src / sbin / ifconfig / ifconfig.c
index 1f112c4..f36b62b 100644 (file)
@@ -2,7 +2,33 @@
  * Copyright (c) 1983 Regents of the University of California.
  * All rights reserved.
  *
  * Copyright (c) 1983 Regents of the University of California.
  * All rights reserved.
  *
- * %sccs.include.redist.c%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
@@ -12,31 +38,34 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)ifconfig.c 4.27 (Berkeley) %G%";
+static char sccsid[] = "@(#)ifconfig.c 5.1 (Berkeley) 2/28/91";
 #endif /* not lint */
 
 #endif /* not lint */
 
-#include <sys/types.h>
+#include <sys/param.h>
 #include <sys/socket.h>
 #include <sys/ioctl.h>
 
 #include <net/if.h>
 #include <netinet/in.h>
 #include <sys/socket.h>
 #include <sys/ioctl.h>
 
 #include <net/if.h>
 #include <netinet/in.h>
+#include <arpa/inet.h>
 
 #define        NSIP
 #include <netns/ns.h>
 #include <netns/ns_if.h>
 
 #define        NSIP
 #include <netns/ns.h>
 #include <netns/ns_if.h>
+#include <netdb.h>
 
 #define EON
 #include <netiso/iso.h>
 #include <netiso/iso_var.h>
 #include <sys/protosw.h>
 
 
 #define EON
 #include <netiso/iso.h>
 #include <netiso/iso_var.h>
 #include <sys/protosw.h>
 
+#include <unistd.h>
 #include <stdio.h>
 #include <errno.h>
 #include <ctype.h>
 #include <stdio.h>
 #include <errno.h>
 #include <ctype.h>
-#include <netdb.h>
+#include <stdlib.h>
+#include <string.h>
 
 
-extern int errno;
 struct ifreq           ifr, ridreq;
 struct ifaliasreq      addreq;
 struct iso_ifreq       iso_ridreq;
 struct ifreq           ifr, ridreq;
 struct ifaliasreq      addreq;
 struct iso_ifreq       iso_ridreq;
@@ -46,6 +75,7 @@ struct        sockaddr_in     netmask;
 char   name[30];
 int    flags;
 int    metric;
 char   name[30];
 int    flags;
 int    metric;
+int    nsellength = 1;
 int    setaddr;
 int    setipdst;
 int    doalias;
 int    setaddr;
 int    setipdst;
 int    doalias;
@@ -56,7 +86,7 @@ extern        int errno;
 
 int    setifflags(), setifaddr(), setifdstaddr(), setifnetmask();
 int    setifmetric(), setifbroadaddr(), setifipdst();
 
 int    setifflags(), setifaddr(), setifdstaddr(), setifnetmask();
 int    setifmetric(), setifbroadaddr(), setifipdst();
-int    notealias(), setsnpaoffset();
+int    notealias(), setsnpaoffset(), setnsellength();
 
 #define        NEXTARG         0xffffff
 
 
 #define        NEXTARG         0xffffff
 
@@ -83,9 +113,16 @@ struct      cmd {
 #endif
        { "netmask",    NEXTARG,        setifnetmask },
        { "metric",     NEXTARG,        setifmetric },
 #endif
        { "netmask",    NEXTARG,        setifnetmask },
        { "metric",     NEXTARG,        setifmetric },
-       { "snpaoffset", NEXTARG,        setsnpaoffset },
        { "broadcast",  NEXTARG,        setifbroadaddr },
        { "ipdst",      NEXTARG,        setifipdst },
        { "broadcast",  NEXTARG,        setifbroadaddr },
        { "ipdst",      NEXTARG,        setifipdst },
+       { "snpaoffset", NEXTARG,        setsnpaoffset },
+       { "nsellength", NEXTARG,        setnsellength },
+       { "llc0",       IFF_LLC0,       setifflags } ,
+       { "-llc0",      -IFF_LLC0,      setifflags } ,
+       { "llc1",       IFF_LLC1,       setifflags } ,
+       { "-llc1",      -IFF_LLC1,      setifflags } ,
+       { "llc2",       IFF_LLC2,       setifflags } ,
+       { "-llc2",      -IFF_LLC2,      setifflags } ,
        { 0,            0,              setifaddr },
        { 0,            0,              setifdstaddr },
 };
        { 0,            0,              setifaddr },
        { 0,            0,              setifdstaddr },
 };
@@ -122,17 +159,6 @@ struct afswtch {
 
 struct afswtch *afp;   /*the address family being set or asked about*/
 
 
 struct afswtch *afp;   /*the address family being set or asked about*/
 
-int testing = 0;
-Ioctl(a,b,c) {
-       int error = 0;
-       if (testing)
-               printf("would call ioctl with %x, %x, %x\n", a, b, c);
-       else
-               error = ioctl(a, b, c);
-       return error;
-}
-#define ioctl(a, b, c) Ioctl(a,b,c)
-
 main(argc, argv)
        int argc;
        char *argv[];
 main(argc, argv)
        int argc;
        char *argv[];
@@ -141,12 +167,13 @@ main(argc, argv)
        register struct afswtch *rafp;
 
        if (argc < 2) {
        register struct afswtch *rafp;
 
        if (argc < 2) {
-               fprintf(stderr, "usage: ifconfig interface\n%s%s%s%s%s",
+               fprintf(stderr, "usage: ifconfig interface\n%s%s%s%s%s%s",
                    "\t[ af [ address [ dest_addr ] ] [ up ] [ down ]",
                            "[ netmask mask ] ]\n",
                    "\t[ metric n ]\n",
                    "\t[ trailers | -trailers ]\n",
                    "\t[ af [ address [ dest_addr ] ] [ up ] [ down ]",
                            "[ netmask mask ] ]\n",
                    "\t[ metric n ]\n",
                    "\t[ trailers | -trailers ]\n",
-                   "\t[ arp | -arp ]\n");
+                   "\t[ arp | -arp ]\n",
+                   "\t[ llc0 | -llc0 ] [ llc1 | -llc1 ] [ llc2 | -llc2 ] \n");
                exit(1);
        }
        argc--, argv++;
                exit(1);
        }
        argc--, argv++;
@@ -198,6 +225,8 @@ main(argc, argv)
                }
                argc--, argv++;
        }
                }
                argc--, argv++;
        }
+       if (af == AF_ISO)
+               adjust_nsellength();
        if (setipdst && af==AF_NS) {
                struct nsip_req rq;
                int size = sizeof(rq);
        if (setipdst && af==AF_NS) {
                struct nsip_req rq;
                int size = sizeof(rq);
@@ -329,7 +358,7 @@ setsnpaoffset(val)
 
 #define        IFFBITS \
 "\020\1UP\2BROADCAST\3DEBUG\4LOOPBACK\5POINTOPOINT\6NOTRAILERS\7RUNNING\10NOARP\
 
 #define        IFFBITS \
 "\020\1UP\2BROADCAST\3DEBUG\4LOOPBACK\5POINTOPOINT\6NOTRAILERS\7RUNNING\10NOARP\
-"
+\11PROMISC\12ALLMULTI\13OACTIVE\14SIMPLEX\15LLC0\16LLC1\16LLC2"
 
 /*
  * Print the status of the interface.  If an address family was
 
 /*
  * Print the status of the interface.  If an address family was
@@ -458,33 +487,37 @@ iso_status(force)
                perror("ifconfig: socket");
                exit(1);
        }
                perror("ifconfig: socket");
                exit(1);
        }
-       if (ioctl(s, SIOCGIFADDR, (caddr_t)&ifr) < 0) {
+       bzero((caddr_t)&ifr, sizeof(ifr));
+       strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
+       if (ioctl(s, SIOCGIFADDR_ISO, (caddr_t)&ifr) < 0) {
                if (errno == EADDRNOTAVAIL || errno == EAFNOSUPPORT) {
                        if (!force)
                                return;
                        bzero((char *)&ifr.ifr_Addr, sizeof(ifr.ifr_Addr));
                if (errno == EADDRNOTAVAIL || errno == EAFNOSUPPORT) {
                        if (!force)
                                return;
                        bzero((char *)&ifr.ifr_Addr, sizeof(ifr.ifr_Addr));
-               } else
-                       perror("ioctl (SIOCGIFADDR)");
+               } else {
+                       perror("ioctl (SIOCGIFADDR_ISO)");
+                       exit(1);
+               }
        }
        strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name);
        siso = &ifr.ifr_Addr;
        }
        strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name);
        siso = &ifr.ifr_Addr;
-       printf("\tiso %s ", iso_ntoa(siso->siso_addr));
-       if (ioctl(s, SIOCGIFNETMASK, (caddr_t)&ifr) < 0) {
+       printf("\tiso %s ", iso_ntoa(&siso->siso_addr));
+       if (ioctl(s, SIOCGIFNETMASK_ISO, (caddr_t)&ifr) < 0) {
                if (errno != EADDRNOTAVAIL)
                if (errno != EADDRNOTAVAIL)
-                       perror("ioctl (SIOCGIFNETMASK)");
+                       perror("ioctl (SIOCGIFNETMASK_ISO)");
        } else {
        } else {
-               printf("\n netmask %s ", iso_ntoa(siso->siso_addr));
+               printf(" netmask %s ", iso_ntoa(&siso->siso_addr));
        }
        if (flags & IFF_POINTOPOINT) {
        }
        if (flags & IFF_POINTOPOINT) {
-               if (ioctl(s, SIOCGIFDSTADDR, (caddr_t)&ifr) < 0) {
+               if (ioctl(s, SIOCGIFDSTADDR_ISO, (caddr_t)&ifr) < 0) {
                        if (errno == EADDRNOTAVAIL)
                            bzero((char *)&ifr.ifr_Addr, sizeof(ifr.ifr_Addr));
                        else
                        if (errno == EADDRNOTAVAIL)
                            bzero((char *)&ifr.ifr_Addr, sizeof(ifr.ifr_Addr));
                        else
-                           Perror("ioctl (SIOCGIFDSTADDR)");
+                           Perror("ioctl (SIOCGIFDSTADDR_ISO)");
                }
                strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
                siso = &ifr.ifr_Addr;
                }
                strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
                siso = &ifr.ifr_Addr;
-               printf("--> %s ", iso_ntoa(siso->siso_addr));
+               printf("--> %s ", iso_ntoa(&siso->siso_addr));
        }
        putchar('\n');
 }
        }
        putchar('\n');
 }
@@ -601,14 +634,44 @@ SISO(iso_addreq.ifra_mask), SISO(iso_addreq.ifra_dstaddr)};
 iso_getaddr(addr, which)
 char *addr;
 {
 iso_getaddr(addr, which)
 char *addr;
 {
-       struct sockaddr_iso *siso = sisotab[which];
+       register struct sockaddr_iso *siso = sisotab[which];
        struct iso_addr *iso_addr();
        siso->siso_addr = *iso_addr(addr);
        struct iso_addr *iso_addr();
        siso->siso_addr = *iso_addr(addr);
+
        if (which == MASK) {
                siso->siso_len = TSEL(siso) - (caddr_t)(siso);
                siso->siso_nlen = 0;
        } else {
        if (which == MASK) {
                siso->siso_len = TSEL(siso) - (caddr_t)(siso);
                siso->siso_nlen = 0;
        } else {
-           siso->siso_family = AF_ISO;
-           siso->siso_len =  sizeof(*siso);
+               siso->siso_len = sizeof(*siso);
+               siso->siso_family = AF_ISO;
+       }
+}
+
+setnsellength(val)
+       char *val;
+{
+       nsellength = atoi(val);
+       if (nsellength < 0) {
+               fprintf(stderr, "Negative NSEL length is absurd\n");
+               exit (1);
        }
        }
+       if (afp == 0 || afp->af_af != AF_ISO) {
+               fprintf(stderr, "Setting NSEL length valid only for iso\n");
+               exit (1);
+       }
+}
+
+fixnsel(s)
+register struct sockaddr_iso *s;
+{
+       if (s->siso_family == 0)
+               return;
+       s->siso_tlen = nsellength;
+}
+
+adjust_nsellength()
+{
+       fixnsel(sisotab[RIDADDR]);
+       fixnsel(sisotab[ADDR]);
+       fixnsel(sisotab[DSTADDR]);
 }
 }