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