if_enc.c revision 1.44
1/* $OpenBSD: if_enc.c,v 1.44 2006/06/28 12:02:26 claudio 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 74struct enc_softc encif[NENC]; 75 76void encattach(int); 77int encoutput(struct ifnet *, struct mbuf *, struct sockaddr *, 78 struct rtentry *); 79int encioctl(struct ifnet *, u_long, caddr_t); 80void encstart(struct ifnet *); 81 82extern int ifqmaxlen; 83 84void 85encattach(int nenc) 86{ 87 struct ifnet *ifp; 88 int i; 89 90 bzero(encif, sizeof(encif)); 91 92 for (i = 0; i < NENC; i++) 93 { 94 ifp = &encif[i].sc_if; 95 snprintf(ifp->if_xname, sizeof ifp->if_xname, "enc%d", i); 96 ifp->if_softc = &encif[i]; 97 ifp->if_mtu = ENCMTU; 98 ifp->if_ioctl = encioctl; 99 ifp->if_output = encoutput; 100 ifp->if_start = encstart; 101 ifp->if_type = IFT_ENC; 102 ifp->if_snd.ifq_maxlen = ifqmaxlen; 103 ifp->if_hdrlen = ENC_HDRLEN; 104 if_attach(ifp); 105 if_alloc_sadl(ifp); 106 107#if NBPFILTER > 0 108 bpfattach(&encif[i].sc_if.if_bpf, ifp, DLT_ENC, ENC_HDRLEN); 109#endif 110 } 111} 112 113/* 114 * Start output on the enc interface. 115 */ 116void 117encstart(ifp) 118struct ifnet *ifp; 119{ 120 struct mbuf *m; 121 int s; 122 123 for (;;) 124 { 125 s = splnet(); 126 IF_DROP(&ifp->if_snd); 127 IF_DEQUEUE(&ifp->if_snd, m); 128 splx(s); 129 130 if (m == NULL) 131 return; 132 else 133 m_freem(m); 134 } 135} 136 137int 138encoutput(ifp, m, dst, rt) 139struct ifnet *ifp; 140register struct mbuf *m; 141struct sockaddr *dst; 142register struct rtentry *rt; 143{ 144 m_freem(m); 145 return (0); 146} 147 148/* ARGSUSED */ 149int 150encioctl(ifp, cmd, data) 151register struct ifnet *ifp; 152u_long cmd; 153caddr_t data; 154{ 155 switch (cmd) 156 { 157 case SIOCSIFADDR: 158 case SIOCAIFADDR: 159 case SIOCSIFDSTADDR: 160 case SIOCSIFFLAGS: 161 if (ifp->if_flags & IFF_UP) 162 ifp->if_flags |= IFF_RUNNING; 163 else 164 ifp->if_flags &= ~IFF_RUNNING; 165 break; 166 167 default: 168 return (EINVAL); 169 } 170 171 return 0; 172} 173