if_enc.c revision 1.41
1/* $OpenBSD: if_enc.c,v 1.41 2004/09/15 17:46:44 grange 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#ifdef NS 66extern struct ifqueue nsintrq; 67#endif 68 69#include "bpfilter.h" 70#include "enc.h" 71 72#ifdef ENCDEBUG 73#define DPRINTF(x) do { if (encdebug) printf x ; } while (0) 74#else 75#define DPRINTF(x) 76#endif 77 78struct enc_softc encif[NENC]; 79 80void encattach(int); 81int encoutput(struct ifnet *, struct mbuf *, struct sockaddr *, 82 struct rtentry *); 83int encioctl(struct ifnet *, u_long, caddr_t); 84void encrtrequest(int, struct rtentry *, struct sockaddr *); 85void encstart(struct ifnet *); 86 87extern int ifqmaxlen; 88 89void 90encattach(int nenc) 91{ 92 struct ifnet *ifp; 93 int i; 94 95 bzero(encif, sizeof(encif)); 96 97 for (i = 0; i < NENC; i++) 98 { 99 ifp = &encif[i].sc_if; 100 snprintf(ifp->if_xname, sizeof ifp->if_xname, "enc%d", i); 101 ifp->if_softc = &encif[i]; 102 ifp->if_mtu = ENCMTU; 103 ifp->if_ioctl = encioctl; 104 ifp->if_output = encoutput; 105 ifp->if_start = encstart; 106 ifp->if_type = IFT_ENC; 107 ifp->if_snd.ifq_maxlen = ifqmaxlen; 108 ifp->if_hdrlen = ENC_HDRLEN; 109 if_attach(ifp); 110 if_alloc_sadl(ifp); 111 112#if NBPFILTER > 0 113 bpfattach(&encif[i].sc_if.if_bpf, ifp, DLT_ENC, ENC_HDRLEN); 114#endif 115 } 116} 117 118/* 119 * Start output on the enc interface. 120 */ 121void 122encstart(ifp) 123struct ifnet *ifp; 124{ 125 struct mbuf *m; 126 int s; 127 128 for (;;) 129 { 130 s = splimp(); 131 IF_DROP(&ifp->if_snd); 132 IF_DEQUEUE(&ifp->if_snd, m); 133 splx(s); 134 135 if (m == NULL) 136 return; 137 else 138 m_freem(m); 139 } 140} 141 142int 143encoutput(ifp, m, dst, rt) 144struct ifnet *ifp; 145register struct mbuf *m; 146struct sockaddr *dst; 147register struct rtentry *rt; 148{ 149 m_freem(m); 150 return (0); 151} 152 153/* ARGSUSED */ 154void 155encrtrequest(cmd, rt, sa) 156int cmd; 157struct rtentry *rt; 158struct sockaddr *sa; 159{ 160 if (rt) 161 rt->rt_rmx.rmx_mtu = ENCMTU; 162} 163 164/* ARGSUSED */ 165int 166encioctl(ifp, cmd, data) 167register struct ifnet *ifp; 168u_long cmd; 169caddr_t data; 170{ 171 switch (cmd) 172 { 173 case SIOCSIFADDR: 174 case SIOCAIFADDR: 175 case SIOCSIFDSTADDR: 176 case SIOCSIFFLAGS: 177 if (ifp->if_flags & IFF_UP) 178 ifp->if_flags |= IFF_RUNNING; 179 else 180 ifp->if_flags &= ~IFF_RUNNING; 181 break; 182 183 default: 184 return (EINVAL); 185 } 186 187 return 0; 188} 189