if_enc.c revision 1.32
1/* $OpenBSD: if_enc.c,v 1.32 2000/12/30 22:56:23 angelos Exp $ */ 2 3/* 4 * The authors of this code are John Ioannidis (ji@tla.org), 5 * Angelos D. Keromytis (kermit@csd.uch.gr) and 6 * Niels Provos (provos@physnet.uni-hamburg.de). 7 * 8 * This code was written by John Ioannidis for BSD/OS in Athens, Greece, 9 * in November 1995. 10 * 11 * Ported to OpenBSD and NetBSD, with additional transforms, in December 1996, 12 * by Angelos D. Keromytis. 13 * 14 * Additional transforms and features in 1997 and 1998 by Angelos D. Keromytis 15 * and Niels Provos. 16 * 17 * Copyright (C) 1995, 1996, 1997, 1998 by John Ioannidis, Angelos D. Keromytis 18 * and Niels Provos. 19 * 20 * Permission to use, copy, and modify this software 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/kernel.h> 43#include <sys/mbuf.h> 44#include <sys/socket.h> 45#include <sys/errno.h> 46#include <sys/ioctl.h> 47#include <sys/proc.h> 48 49#include <machine/cpu.h> 50 51#include <net/if.h> 52#include <net/if_types.h> 53#include <net/netisr.h> 54#include <net/route.h> 55#include <net/bpf.h> 56 57#include <netinet/ip_ipsp.h> 58#include <net/if_enc.h> 59 60#ifdef INET 61#include <netinet/in.h> 62#include <netinet/in_systm.h> 63#include <netinet/in_var.h> 64#include <netinet/ip_var.h> 65#include <netinet/ip.h> 66#endif 67 68#ifdef INET6 69#ifndef INET 70#include <netinet/in.h> 71#endif 72#include <netinet/ip6.h> 73#include <netinet6/ip6_var.h> 74#include <netinet6/nd6.h> 75#endif /* INET6 */ 76 77#ifdef ISO 78extern struct ifqueue clnlintrq; 79#endif 80 81#ifdef NS 82extern struct ifqueue nsintrq; 83#endif 84 85#include "bpfilter.h" 86#include "enc.h" 87 88#ifdef ENCDEBUG 89#define DPRINTF(x) do { if (encdebug) printf x ; } while (0) 90#else 91#define DPRINTF(x) 92#endif 93 94#ifndef offsetof 95#define offsetof(s, e) ((int)&((s *)0)->e) 96#endif 97 98struct enc_softc encif[NENC]; 99 100void encattach __P((int)); 101int encoutput __P((struct ifnet *, struct mbuf *, struct sockaddr *, 102 struct rtentry *)); 103int encioctl __P((struct ifnet *, u_long, caddr_t)); 104void encrtrequest __P((int, struct rtentry *, struct sockaddr *)); 105void encstart __P((struct ifnet *)); 106 107extern int ifqmaxlen; 108 109void 110encattach(int nenc) 111{ 112 struct ifnet *ifp; 113 int i; 114 115 bzero(encif, sizeof(encif)); 116 117 for (i = 0; i < NENC; i++) 118 { 119 ifp = &encif[i].sc_if; 120 sprintf(ifp->if_xname, "enc%d", i); 121 ifp->if_softc = &encif[i]; 122 ifp->if_mtu = ENCMTU; 123 ifp->if_ioctl = encioctl; 124 ifp->if_output = encoutput; 125 ifp->if_start = encstart; 126 ifp->if_type = IFT_ENC; 127 ifp->if_snd.ifq_maxlen = ifqmaxlen; 128 ifp->if_hdrlen = ENC_HDRLEN; 129 if_attach(ifp); 130 131#if NBPFILTER > 0 132 bpfattach(&encif[i].sc_if.if_bpf, ifp, DLT_ENC, ENC_HDRLEN); 133#endif 134#ifdef INET6 135 nd6_ifattach(ifp); 136#endif 137 } 138} 139 140/* 141 * Start output on the enc interface. 142 */ 143void 144encstart(ifp) 145struct ifnet *ifp; 146{ 147 struct mbuf *m; 148 int s; 149 150 for (;;) 151 { 152 s = splimp(); 153 IF_DROP(&ifp->if_snd); 154 IF_DEQUEUE(&ifp->if_snd, m); 155 splx(s); 156 157 if (m == NULL) 158 return; 159 else 160 m_freem(m); 161 } 162} 163 164int 165encoutput(ifp, m, dst, rt) 166struct ifnet *ifp; 167register struct mbuf *m; 168struct sockaddr *dst; 169register struct rtentry *rt; 170{ 171 m_freem(m); 172 return 0; 173} 174 175/* ARGSUSED */ 176void 177encrtrequest(cmd, rt, sa) 178int cmd; 179struct rtentry *rt; 180struct sockaddr *sa; 181{ 182 if (rt) 183 rt->rt_rmx.rmx_mtu = ENCMTU; 184} 185 186/* ARGSUSED */ 187int 188encioctl(ifp, cmd, data) 189register struct ifnet *ifp; 190u_long cmd; 191caddr_t data; 192{ 193 switch (cmd) 194 { 195 case SIOCSIFADDR: 196 case SIOCAIFADDR: 197 case SIOCSIFDSTADDR: 198 case SIOCSIFFLAGS: 199 if (ifp->if_flags & IFF_UP) 200 ifp->if_flags |= IFF_RUNNING; 201 else 202 ifp->if_flags &= ~IFF_RUNNING; 203 break; 204 205 default: 206 return EINVAL; 207 } 208 209 return 0; 210} 211