1/* $NetBSD: if_atmsubr.c,v 1.10 1997/03/11 23:19:51 chuck Exp $ */ 2 3/* 4 * 5 * Copyright (c) 1996 Charles D. Cranor and Washington University. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. All advertising materials mentioning features or use of this software 17 * must display the following acknowledgement: 18 * This product includes software developed by Charles D. Cranor and 19 * Washington University. 20 * 4. The name of the author may not be used to endorse or promote products 21 * derived from this software without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 *
|
34 * $FreeBSD: head/sys/net/if_atmsubr.c 111774 2003-03-03 00:21:52Z mdodd $
|
34 * $FreeBSD: head/sys/net/if_atmsubr.c 111888 2003-03-04 23:19:55Z jlemon $ |
35 */ 36 37/* 38 * if_atmsubr.c 39 */ 40 41#include "opt_inet.h" 42#include "opt_inet6.h" 43#include "opt_mac.h" 44#include "opt_natm.h" 45 46#include <sys/param.h> 47#include <sys/systm.h> 48#include <sys/mac.h> 49#include <sys/mbuf.h> 50#include <sys/socket.h> 51#include <sys/sockio.h> 52#include <sys/errno.h> 53 54#include <net/if.h> 55#include <net/netisr.h> 56#include <net/route.h> 57#include <net/if_dl.h> 58#include <net/if_types.h> 59#include <net/if_atm.h> 60 61#include <netinet/in.h> 62#include <netinet/if_atm.h> 63#include <netinet/if_ether.h> /* XXX: for ETHERTYPE_* */ 64#if defined(INET) || defined(INET6) 65#include <netinet/in_var.h> 66#endif 67#ifdef NATM 68#include <netnatm/natm.h> 69#endif 70 71#ifndef ETHERTYPE_IPV6 72#define ETHERTYPE_IPV6 0x86dd 73#endif 74 75#define senderr(e) { error = (e); goto bad;} 76 77/* 78 * atm_output: ATM output routine 79 * inputs: 80 * "ifp" = ATM interface to output to 81 * "m0" = the packet to output 82 * "dst" = the sockaddr to send to (either IP addr, or raw VPI/VCI) 83 * "rt0" = the route to use 84 * returns: error code [0 == ok] 85 * 86 * note: special semantic: if (dst == NULL) then we assume "m" already 87 * has an atm_pseudohdr on it and just send it directly. 88 * [for native mode ATM output] if dst is null, then 89 * rt0 must also be NULL. 90 */ 91 92int 93atm_output(ifp, m0, dst, rt0) 94 struct ifnet *ifp; 95 struct mbuf *m0; 96 struct sockaddr *dst; 97 struct rtentry *rt0; 98{ 99 u_int16_t etype = 0; /* if using LLC/SNAP */ 100 int error = 0, sz; 101 struct atm_pseudohdr atmdst, *ad; 102 struct mbuf *m = m0; 103 struct rtentry *rt; 104 struct atmllc *atmllc; 105 struct atmllc *llc_hdr = NULL; 106 u_int32_t atm_flags; 107 108#ifdef MAC 109 error = mac_check_ifnet_transmit(ifp, m); 110 if (error) 111 senderr(error); 112#endif 113 114 if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING)) 115 senderr(ENETDOWN); 116 117 /* 118 * check route 119 */ 120 error = rt_check(&rt, &rt0, dst); 121 if (error) 122 goto bad; 123 124 /* 125 * check for non-native ATM traffic (dst != NULL) 126 */ 127 if (dst) { 128 switch (dst->sa_family) { 129#if defined(INET) || defined(INET6) 130 case AF_INET: 131 case AF_INET6: 132 if (dst->sa_family == AF_INET6) 133 etype = htons(ETHERTYPE_IPV6); 134 else 135 etype = htons(ETHERTYPE_IP); 136 if (!atmresolve(rt, m, dst, &atmdst)) { 137 m = NULL; 138 /* XXX: atmresolve already free'd it */ 139 senderr(EHOSTUNREACH); 140 /* XXX: put ATMARP stuff here */ 141 /* XXX: watch who frees m on failure */ 142 } 143 break; 144#endif /* INET || INET6 */ 145 146 case AF_UNSPEC: 147 /* 148 * XXX: bpfwrite. assuming dst contains 12 bytes 149 * (atm pseudo header (4) + LLC/SNAP (8)) 150 */ 151 bcopy(dst->sa_data, &atmdst, sizeof(atmdst)); 152 llc_hdr = (struct atmllc *)(dst->sa_data + sizeof(atmdst)); 153 break; 154 155 default: 156#if defined(__NetBSD__) || defined(__OpenBSD__) 157 printf("%s: can't handle af%d\n", ifp->if_xname, 158 dst->sa_family); 159#elif defined(__FreeBSD__) || defined(__bsdi__) 160 printf("%s%d: can't handle af%d\n", ifp->if_name, 161 ifp->if_unit, dst->sa_family); 162#endif 163 senderr(EAFNOSUPPORT); 164 } 165 166 /* 167 * must add atm_pseudohdr to data 168 */ 169 sz = sizeof(atmdst); 170 atm_flags = ATM_PH_FLAGS(&atmdst); 171 if (atm_flags & ATM_PH_LLCSNAP) sz += 8; /* sizeof snap == 8 */ 172 M_PREPEND(m, sz, M_DONTWAIT); 173 if (m == 0) 174 senderr(ENOBUFS); 175 ad = mtod(m, struct atm_pseudohdr *); 176 *ad = atmdst; 177 if (atm_flags & ATM_PH_LLCSNAP) { 178 atmllc = (struct atmllc *)(ad + 1); 179 if (llc_hdr == NULL) { 180 bcopy(ATMLLC_HDR, atmllc->llchdr, 181 sizeof(atmllc->llchdr)); 182 ATM_LLC_SETTYPE(atmllc, etype); 183 /* note: already in network order */ 184 } 185 else 186 bcopy(llc_hdr, atmllc, sizeof(struct atmllc)); 187 } 188 } 189 190 /* 191 * Queue message on interface, and start output if interface 192 * not yet active. 193 */ 194 if (! IF_HANDOFF(&ifp->if_snd, m, ifp)) 195 return (ENOBUFS); 196 return (error); 197 198bad: 199 if (m) 200 m_freem(m); 201 return (error); 202} 203 204/* 205 * Process a received ATM packet; 206 * the packet is in the mbuf chain m. 207 */ 208void 209atm_input(ifp, ah, m, rxhand) 210 struct ifnet *ifp; 211 struct atm_pseudohdr *ah; 212 struct mbuf *m; 213 void *rxhand; 214{
|
215 struct ifqueue *inq;
|
215 int isr; |
216 u_int16_t etype = ETHERTYPE_IP; /* default */ 217 int s; 218 219 if ((ifp->if_flags & IFF_UP) == 0) { 220 m_freem(m); 221 return; 222 } 223#ifdef MAC 224 mac_create_mbuf_from_ifnet(ifp, m); 225#endif 226 ifp->if_ibytes += m->m_pkthdr.len; 227 228 if (rxhand) { 229#ifdef NATM 230 struct natmpcb *npcb = rxhand; 231 s = splimp(); /* in case 2 atm cards @ diff lvls */ 232 npcb->npcb_inq++; /* count # in queue */ 233 splx(s);
|
234 schednetisr(NETISR_NATM);
235 inq = &natmintrq;
|
234 isr = NETISR_NATM; |
235 m->m_pkthdr.rcvif = rxhand; /* XXX: overload */ 236#else 237 printf("atm_input: NATM detected but not configured in kernel\n"); 238 m_freem(m); 239 return; 240#endif 241 } else { 242 /* 243 * handle LLC/SNAP header, if present 244 */ 245 if (ATM_PH_FLAGS(ah) & ATM_PH_LLCSNAP) { 246 struct atmllc *alc; 247 if (m->m_len < sizeof(*alc) && 248 (m = m_pullup(m, sizeof(*alc))) == 0) 249 return; /* failed */ 250 alc = mtod(m, struct atmllc *); 251 if (bcmp(alc, ATMLLC_HDR, 6)) { 252#if defined(__NetBSD__) || defined(__OpenBSD__) 253 printf("%s: recv'd invalid LLC/SNAP frame [vp=%d,vc=%d]\n", 254 ifp->if_xname, ATM_PH_VPI(ah), ATM_PH_VCI(ah)); 255#elif defined(__FreeBSD__) || defined(__bsdi__) 256 printf("%s%d: recv'd invalid LLC/SNAP frame [vp=%d,vc=%d]\n", 257 ifp->if_name, ifp->if_unit, ATM_PH_VPI(ah), ATM_PH_VCI(ah)); 258#endif 259 m_freem(m); 260 return; 261 } 262 etype = ATM_LLC_TYPE(alc); 263 m_adj(m, sizeof(*alc)); 264 } 265 266 switch (etype) { 267#ifdef INET 268 case ETHERTYPE_IP:
|
270 schednetisr(NETISR_IP);
271 inq = &ipintrq;
|
269 isr = NETISR_IP; |
270 break; 271#endif 272#ifdef INET6 273 case ETHERTYPE_IPV6:
|
276 schednetisr(NETISR_IPV6);
277 inq = &ip6intrq;
|
274 isr = NETISR_IPV6; |
275 break; 276#endif 277 default: 278 m_freem(m); 279 return; 280 } 281 }
|
285
286 (void) IF_HANDOFF(inq, m, NULL);
|
282 netisr_dispatch(isr, m); |
283} 284 285/* 286 * Perform common duties while attaching to interface list 287 */ 288void 289atm_ifattach(ifp) 290 struct ifnet *ifp; 291{ 292 struct ifaddr *ifa; 293 struct sockaddr_dl *sdl; 294 295 ifp->if_type = IFT_ATM; 296 ifp->if_addrlen = 0; 297 ifp->if_hdrlen = 0; 298 ifp->if_mtu = ATMMTU; 299 ifp->if_output = atm_output; 300#if 0 301 ifp->if_input = atm_input; 302#endif 303 ifp->if_snd.ifq_maxlen = 50; /* dummy */ 304 305#if defined(__NetBSD__) || defined(__OpenBSD__) 306 TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_list) 307#elif defined(__FreeBSD__) && (__FreeBSD__ > 2) 308 for (ifa = TAILQ_FIRST(&ifp->if_addrhead); ifa; 309 ifa = TAILQ_NEXT(ifa, ifa_link)) 310#elif defined(__FreeBSD__) || defined(__bsdi__) 311 for (ifa = ifp->if_addrlist; ifa; ifa = ifa->ifa_next) 312#endif 313 if ((sdl = (struct sockaddr_dl *)ifa->ifa_addr) && 314 sdl->sdl_family == AF_LINK) { 315 sdl->sdl_type = IFT_ATM; 316 sdl->sdl_alen = ifp->if_addrlen; 317#ifdef notyet /* if using ATMARP, store hardware address using the next line */ 318 bcopy(ifp->hw_addr, LLADDR(sdl), ifp->if_addrlen); 319#endif 320 break; 321 } 322 323}
|