root/net/if_enc.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. encattach
  2. encstart
  3. encoutput
  4. encioctl

    1 /*      $OpenBSD: if_enc.c,v 1.46 2007/05/26 17:13:30 jason Exp $       */
    2 /*
    3  * The authors of this code are John Ioannidis (ji@tla.org),
    4  * Angelos D. Keromytis (kermit@csd.uch.gr) and 
    5  * Niels Provos (provos@physnet.uni-hamburg.de).
    6  *
    7  * This code was written by John Ioannidis for BSD/OS in Athens, Greece, 
    8  * in November 1995.
    9  *
   10  * Ported to OpenBSD and NetBSD, with additional transforms, in December 1996,
   11  * by Angelos D. Keromytis.
   12  *
   13  * Additional transforms and features in 1997 and 1998 by Angelos D. Keromytis
   14  * and Niels Provos.
   15  *
   16  * Copyright (C) 1995, 1996, 1997, 1998 by John Ioannidis, Angelos D. Keromytis
   17  * and Niels Provos.
   18  * Copyright (c) 2001, Angelos D. Keromytis.
   19  *
   20  * Permission to use, copy, and modify this software with or without fee
   21  * is hereby granted, provided that this entire notice is included in
   22  * all copies of any software which is or includes a copy or
   23  * modification of this software. 
   24  * You may use this code under the GNU public license if you so wish. Please
   25  * contribute changes back to the authors under this freer than GPL license
   26  * so that we may further the use of strong encryption without limitations to
   27  * all.
   28  *
   29  * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR
   30  * IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY
   31  * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE
   32  * MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR
   33  * PURPOSE.
   34  */
   35 
   36 /*
   37  * Encapsulation interface driver.
   38  */
   39 
   40 #include <sys/param.h>
   41 #include <sys/systm.h>
   42 #include <sys/mbuf.h>
   43 #include <sys/socket.h>
   44 #include <sys/ioctl.h>
   45 
   46 #include <net/if.h>
   47 #include <net/if_types.h>
   48 #include <net/route.h>
   49 #include <net/bpf.h>
   50 
   51 #include <net/if_enc.h>
   52 
   53 #ifdef  INET
   54 #include <netinet/in.h>
   55 #include <netinet/in_var.h>
   56 #endif
   57 
   58 #ifdef INET6
   59 #ifndef INET
   60 #include <netinet/in.h>
   61 #endif
   62 #include <netinet6/nd6.h>
   63 #endif /* INET6 */
   64 
   65 #include "bpfilter.h"
   66 #include "enc.h"
   67 
   68 #ifdef ENCDEBUG
   69 #define DPRINTF(x)    do { if (encdebug) printf x ; } while (0)
   70 #else
   71 #define DPRINTF(x)
   72 #endif
   73 
   74 struct enc_softc encif[NENC];
   75 
   76 void    encattach(int);
   77 int     encoutput(struct ifnet *, struct mbuf *, struct sockaddr *,
   78             struct rtentry *);
   79 int     encioctl(struct ifnet *, u_long, caddr_t);
   80 void    encstart(struct ifnet *);
   81 
   82 void
   83 encattach(int nenc)
   84 {
   85         struct ifnet *ifp;
   86         int i;
   87 
   88         bzero(encif, sizeof(encif));
   89 
   90         for (i = 0; i < NENC; i++) {
   91                 ifp = &encif[i].sc_if;
   92                 snprintf(ifp->if_xname, sizeof ifp->if_xname, "enc%d", i);
   93                 ifp->if_softc = &encif[i];
   94                 ifp->if_mtu = ENCMTU;
   95                 ifp->if_ioctl = encioctl;
   96                 ifp->if_output = encoutput;
   97                 ifp->if_start = encstart;
   98                 ifp->if_type = IFT_ENC;
   99                 ifp->if_snd.ifq_maxlen = ifqmaxlen;
  100                 ifp->if_hdrlen = ENC_HDRLEN;
  101                 if_attach(ifp);
  102                 if_alloc_sadl(ifp);
  103 
  104 #if NBPFILTER > 0
  105                 bpfattach(&encif[i].sc_if.if_bpf, ifp, DLT_ENC, ENC_HDRLEN);
  106 #endif
  107         }
  108 }
  109 
  110 /*
  111  * Start output on the enc interface.
  112  */
  113 void
  114 encstart(struct ifnet *ifp)
  115 {
  116         struct mbuf *m;
  117         int s;
  118 
  119         for (;;) {
  120                 s = splnet();
  121                 IF_DROP(&ifp->if_snd);
  122                 IF_DEQUEUE(&ifp->if_snd, m);
  123                 splx(s);
  124 
  125                 if (m == NULL)
  126                         return;
  127                 else
  128                         m_freem(m);
  129         }
  130 }
  131 
  132 int
  133 encoutput(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst,
  134     struct rtentry *rt)
  135 {
  136         m_freem(m);
  137         return (0);
  138 }
  139 
  140 /* ARGSUSED */
  141 int
  142 encioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
  143 {
  144         switch (cmd) {
  145         case SIOCSIFADDR:
  146         case SIOCAIFADDR:
  147         case SIOCSIFDSTADDR:
  148         case SIOCSIFFLAGS:
  149                 if (ifp->if_flags & IFF_UP)
  150                         ifp->if_flags |= IFF_RUNNING;
  151                 else
  152                         ifp->if_flags &= ~IFF_RUNNING;
  153                 break;
  154         default:
  155                 return (EINVAL);
  156         }
  157 
  158         return 0;
  159 }

/* [<][>][^][v][top][bottom][index][help] */