]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netinet/if_atm.c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
22 /* $NetBSD: if_atm.c,v 1.6 1996/10/13 02:03:01 christos Exp $ */
26 * Copyright (c) 1996 Charles D. Cranor and Washington University.
27 * All rights reserved.
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
32 * 1. Redistributions of source code must retain the above copyright
33 * notice, this list of conditions and the following disclaimer.
34 * 2. Redistributions in binary form must reproduce the above copyright
35 * notice, this list of conditions and the following disclaimer in the
36 * documentation and/or other materials provided with the distribution.
37 * 3. All advertising materials mentioning features or use of this software
38 * must display the following acknowledgement:
39 * This product includes software developed by Charles D. Cranor and
40 * Washington University.
41 * 4. The name of the author may not be used to endorse or promote products
42 * derived from this software without specific prior written permission.
44 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
45 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
46 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
47 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
48 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
49 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
50 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
51 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
52 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
53 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
55 * $FreeBSD: src/sys/netinet/if_atm.c,v 1.8 1999/12/07 17:39:06 shin Exp $
59 * IP <=> ATM address resolution.
62 #if defined(INET) || defined(INET6)
64 #include <sys/param.h>
65 #include <sys/systm.h>
66 #include <sys/queue.h>
68 #include <sys/socket.h>
69 #include <sys/sockio.h>
70 #include <sys/syslog.h>
73 #include <net/if_dl.h>
74 #include <net/route.h>
75 #include <net/if_atm.h>
77 #include <netinet/in.h>
78 #include <netinet/if_atm.h>
83 #include <netnatm/natm.h>
87 #define SDL(s) ((struct sockaddr_dl *)s)
90 * atm_rtrequest: handle ATM rt request (in support of generic code)
91 * inputs: "req" = request code
97 atm_rtrequest(req
, rt
, sa
)
99 register struct rtentry
*rt
;
102 register struct sockaddr
*gate
= rt
->rt_gateway
;
103 struct atm_pseudoioctl api
;
105 struct sockaddr_in
*sin
;
106 struct natmpcb
*npcb
= NULL
;
107 struct atm_pseudohdr
*aph
;
109 static struct sockaddr_dl null_sdl
= {sizeof(null_sdl
), AF_LINK
};
111 if (rt
->rt_flags
& RTF_GATEWAY
) /* link level requests only */
116 case RTM_RESOLVE
: /* resolve: only happens when cloning */
117 printf("atm_rtrequest: RTM_RESOLVE request detected?\n");
123 * route added by a command (e.g. ifconfig, route, arp...).
125 * first check to see if this is not a host route, in which
126 * case we are being called via "ifconfig" to set the address.
129 if ((rt
->rt_flags
& RTF_HOST
) == 0) {
130 rt_setgate(rt
,rt_key(rt
),(struct sockaddr
*)&null_sdl
);
131 gate
= rt
->rt_gateway
;
132 SDL(gate
)->sdl_type
= rt
->rt_ifp
->if_type
;
133 SDL(gate
)->sdl_index
= rt
->rt_ifp
->if_index
;
137 if ((rt
->rt_flags
& RTF_CLONING
) != 0) {
138 printf("atm_rtrequest: cloning route detected?\n");
141 if (gate
->sa_family
!= AF_LINK
||
142 gate
->sa_len
< sizeof(null_sdl
)) {
143 log(LOG_DEBUG
, "atm_rtrequest: bad gateway value");
148 if (rt
->rt_ifp
->if_ioctl
== NULL
) panic("atm null ioctl");
153 * let native ATM know we are using this VCI/VPI
156 sin
= (struct sockaddr_in
*) rt_key(rt
);
157 if (sin
->sin_family
!= AF_INET
)
159 aph
= (struct atm_pseudohdr
*) LLADDR(SDL(gate
));
160 npcb
= npcb_add(NULL
, rt
->rt_ifp
, ATM_PH_VCI(aph
),
164 npcb
->npcb_flags
|= NPCB_IP
;
165 npcb
->ipaddr
.s_addr
= sin
->sin_addr
.s_addr
;
166 /* XXX: move npcb to llinfo when ATM ARP is ready */
167 rt
->rt_llinfo
= (caddr_t
) npcb
;
168 rt
->rt_flags
|= RTF_LLINFO
;
171 * let the lower level know this circuit is active
173 bcopy(LLADDR(SDL(gate
)), &api
.aph
, sizeof(api
.aph
));
175 if (dlil_ioctl(0, rt
->rt_ifp
, SIOCATMENA
,
176 (caddr_t
)&api
) != 0) {
177 printf("atm: couldn't add VC\n");
181 SDL(gate
)->sdl_type
= rt
->rt_ifp
->if_type
;
182 SDL(gate
)->sdl_index
= rt
->rt_ifp
->if_index
;
189 npcb_free(npcb
, NPCB_DESTROY
);
190 rt
->rt_llinfo
= NULL
;
191 rt
->rt_flags
&= ~RTF_LLINFO
;
194 rtrequest(RTM_DELETE
, rt_key(rt
), (struct sockaddr
*)0,
195 rt_mask(rt
), 0, (struct rtentry
**) 0);
202 * tell native ATM we are done with this VC
205 if (rt
->rt_flags
& RTF_LLINFO
) {
206 npcb_free((struct natmpcb
*)rt
->rt_llinfo
,
208 rt
->rt_llinfo
= NULL
;
209 rt
->rt_flags
&= ~RTF_LLINFO
;
213 * tell the lower layer to disable this circuit
216 bcopy(LLADDR(SDL(gate
)), &api
.aph
, sizeof(api
.aph
));
218 dlil_ioctl(0, rt
->rt_ifp
, SIOCATMDIS
,
228 * [1] "rt" = the link level route to use (or null if need to look one up)
229 * [2] "m" = mbuf containing the data to be sent
230 * [3] "dst" = sockaddr_in (IP) address of dest.
232 * [4] "desten" = ATM pseudo header which we will fill in VPI/VCI info
234 * 0 == resolve FAILED; note that "m" gets m_freem'd in this case
235 * 1 == resolve OK; desten contains result
237 * XXX: will need more work if we wish to support ATMARP in the kernel,
238 * but this is enough for PVCs entered via the "route" command.
242 atmresolve(rt
, m
, dst
, desten
)
244 register struct rtentry
*rt
;
246 register struct sockaddr
*dst
;
247 register struct atm_pseudohdr
*desten
; /* OUT */
250 struct sockaddr_dl
*sdl
;
252 if (m
->m_flags
& (M_BCAST
|M_MCAST
)) {
253 log(LOG_INFO
, "atmresolve: BCAST/MCAST packet detected/dumped");
258 rt
= RTALLOC1(dst
, 0);
259 if (rt
== NULL
) goto bad
; /* failed */
260 rtunref(rt
); /* don't keep LL references */
261 if ((rt
->rt_flags
& RTF_GATEWAY
) != 0 ||
262 (rt
->rt_flags
& RTF_LLINFO
) == 0 ||
263 /* XXX: are we using LLINFO? */
264 rt
->rt_gateway
->sa_family
!= AF_LINK
) {
270 * note that rt_gateway is a sockaddr_dl which contains the
271 * atm_pseudohdr data structure for this route. we currently
272 * don't need any rt_llinfo info (but will if we want to support
273 * ATM ARP [c.f. if_ether.c]).
276 sdl
= SDL(rt
->rt_gateway
);
279 * Check the address family and length is valid, the address
280 * is resolved; otherwise, try to resolve.
284 if (sdl
->sdl_family
== AF_LINK
&& sdl
->sdl_alen
== sizeof(*desten
)) {
285 bcopy(LLADDR(sdl
), desten
, sdl
->sdl_alen
);
286 return(1); /* ok, go for it! */
290 * we got an entry, but it doesn't have valid link address
291 * info in it (it is prob. the interface route, which has
292 * sdl_alen == 0). dump packet. (fall through to "bad").