1 /* $NetBSD: if_atm.c,v 1.6 1996/10/13 02:03:01 christos Exp $ */
5 * Copyright (c) 1996 Charles D. Cranor and Washington University.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
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.
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.
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD$");
38 * IP <=> ATM address resolution.
41 #include "opt_inet6.h"
44 #if defined(INET) || defined(INET6)
46 #include <sys/param.h>
47 #include <sys/systm.h>
48 #include <sys/queue.h>
50 #include <sys/socket.h>
51 #include <sys/sockio.h>
52 #include <sys/syslog.h>
55 #include <net/if_dl.h>
56 #include <net/route.h>
57 #include <net/if_atm.h>
59 #include <netinet/in.h>
60 #include <netinet/if_atm.h>
63 #include <netnatm/natm.h>
66 #define SDL(s) ((struct sockaddr_dl *)s)
68 #define GET3BYTE(V, A, L) do { \
69 (V) = ((A)[0] << 16) | ((A)[1] << 8) | (A)[2]; \
74 #define GET2BYTE(V, A, L) do { \
75 (V) = ((A)[0] << 8) | (A)[1]; \
80 #define GET1BYTE(V, A, L) do { \
87 * atm_rtrequest: handle ATM rt request (in support of generic code)
88 * inputs: "req" = request code
90 * "info" = rt_addrinfo
93 atm_rtrequest(int req
, struct rtentry
*rt
, struct rt_addrinfo
*info
)
95 struct sockaddr
*gate
= rt
->rt_gateway
;
96 struct atmio_openvcc op
;
97 struct atmio_closevcc cl
;
101 struct sockaddr_in
*sin
;
102 struct natmpcb
*npcb
= NULL
;
104 static struct sockaddr_dl null_sdl
= {sizeof(null_sdl
), AF_LINK
};
106 if (rt
->rt_flags
& RTF_GATEWAY
) /* link level requests only */
111 case RTM_RESOLVE
: /* resolve: only happens when cloning */
112 printf("atm_rtrequest: RTM_RESOLVE request detected?\n");
117 * route added by a command (e.g. ifconfig, route, arp...).
119 * first check to see if this is not a host route, in which
120 * case we are being called via "ifconfig" to set the address.
122 if ((rt
->rt_flags
& RTF_HOST
) == 0) {
123 rt_setgate(rt
,rt_key(rt
),(struct sockaddr
*)&null_sdl
);
124 gate
= rt
->rt_gateway
;
125 SDL(gate
)->sdl_type
= rt
->rt_ifp
->if_type
;
126 SDL(gate
)->sdl_index
= rt
->rt_ifp
->if_index
;
130 if ((rt
->rt_flags
& RTF_CLONING
) != 0) {
131 printf("atm_rtrequest: cloning route detected?\n");
134 if (gate
->sa_family
!= AF_LINK
||
135 gate
->sa_len
< sizeof(null_sdl
)) {
136 log(LOG_DEBUG
, "atm_rtrequest: bad gateway value");
140 KASSERT(rt
->rt_ifp
->if_ioctl
!= NULL
,
141 ("atm_rtrequest: null ioctl"));
144 * Parse and verify the link level address as
150 bzero(&op
, sizeof(op
));
151 addr
= LLADDR(SDL(gate
));
152 alen
= SDL(gate
)->sdl_alen
;
154 printf("%s: bad link-level address\n", __func__
);
159 /* old type address */
160 GET1BYTE(op
.param
.flags
, addr
, alen
);
161 GET1BYTE(op
.param
.vpi
, addr
, alen
);
162 GET2BYTE(op
.param
.vci
, addr
, alen
);
163 op
.param
.traffic
= ATMIO_TRAFFIC_UBR
;
164 op
.param
.aal
= (op
.param
.flags
& ATM_PH_AAL5
) ?
165 ATMIO_AAL_5
: ATMIO_AAL_0
;
168 op
.param
.aal
= ATMIO_AAL_5
;
170 GET1BYTE(op
.param
.flags
, addr
, alen
);
171 op
.param
.flags
&= ATM_PH_LLCSNAP
;
173 GET1BYTE(op
.param
.vpi
, addr
, alen
);
174 GET2BYTE(op
.param
.vci
, addr
, alen
);
176 GET1BYTE(op
.param
.traffic
, addr
, alen
);
178 switch (op
.param
.traffic
) {
180 case ATMIO_TRAFFIC_UBR
:
182 GET3BYTE(op
.param
.tparam
.pcr
,
186 case ATMIO_TRAFFIC_CBR
:
189 GET3BYTE(op
.param
.tparam
.pcr
, addr
, alen
);
192 case ATMIO_TRAFFIC_VBR
:
195 GET3BYTE(op
.param
.tparam
.pcr
, addr
, alen
);
196 GET3BYTE(op
.param
.tparam
.scr
, addr
, alen
);
197 GET3BYTE(op
.param
.tparam
.mbs
, addr
, alen
);
200 case ATMIO_TRAFFIC_ABR
:
201 if (alen
< 4 * 3 + 2 + 1 * 2 + 3)
203 GET3BYTE(op
.param
.tparam
.pcr
, addr
, alen
);
204 GET3BYTE(op
.param
.tparam
.mcr
, addr
, alen
);
205 GET3BYTE(op
.param
.tparam
.icr
, addr
, alen
);
206 GET3BYTE(op
.param
.tparam
.tbe
, addr
, alen
);
207 GET1BYTE(op
.param
.tparam
.nrm
, addr
, alen
);
208 GET1BYTE(op
.param
.tparam
.trm
, addr
, alen
);
209 GET2BYTE(op
.param
.tparam
.adtf
, addr
, alen
);
210 GET1BYTE(op
.param
.tparam
.rif
, addr
, alen
);
211 GET1BYTE(op
.param
.tparam
.rdf
, addr
, alen
);
212 GET1BYTE(op
.param
.tparam
.cdf
, addr
, alen
);
217 printf("%s: bad traffic params\n", __func__
);
221 op
.param
.rmtu
= op
.param
.tmtu
= rt
->rt_ifp
->if_mtu
;
224 * let native ATM know we are using this VCI/VPI
227 sin
= (struct sockaddr_in
*) rt_key(rt
);
228 if (sin
->sin_family
!= AF_INET
)
230 npcb
= npcb_add(NULL
, rt
->rt_ifp
, op
.param
.vci
, op
.param
.vpi
);
233 npcb
->npcb_flags
|= NPCB_IP
;
234 npcb
->ipaddr
.s_addr
= sin
->sin_addr
.s_addr
;
235 /* XXX: move npcb to llinfo when ATM ARP is ready */
236 rt
->rt_llinfo
= (caddr_t
) npcb
;
237 rt
->rt_flags
|= RTF_LLINFO
;
240 * let the lower level know this circuit is active
243 op
.param
.flags
|= ATMIO_FLAG_ASYNC
;
244 if (rt
->rt_ifp
->if_ioctl(rt
->rt_ifp
, SIOCATMOPENVCC
,
245 (caddr_t
)&op
) != 0) {
246 printf("atm: couldn't add VC\n");
250 SDL(gate
)->sdl_type
= rt
->rt_ifp
->if_type
;
251 SDL(gate
)->sdl_index
= rt
->rt_ifp
->if_index
;
261 npcb_free(npcb
, NPCB_DESTROY
);
262 rt
->rt_llinfo
= NULL
;
263 rt
->rt_flags
&= ~RTF_LLINFO
;
267 /* mark as invalid. We cannot RTM_DELETE the route from
268 * here, because the recursive call to rtrequest1 does
269 * not really work. */
270 rt
->rt_flags
|= RTF_REJECT
;
276 * tell native ATM we are done with this VC
278 if (rt
->rt_flags
& RTF_LLINFO
) {
280 npcb_free((struct natmpcb
*)rt
->rt_llinfo
,
282 rt
->rt_llinfo
= NULL
;
283 rt
->rt_flags
&= ~RTF_LLINFO
;
288 * tell the lower layer to disable this circuit
290 bzero(&op
, sizeof(op
));
291 addr
= LLADDR(SDL(gate
));
294 cl
.vci
= *addr
++ << 8;
296 (void)rt
->rt_ifp
->if_ioctl(rt
->rt_ifp
, SIOCATMCLOSEVCC
,
305 * [1] "rt" = the link level route to use (or null if need to look one up)
306 * [2] "m" = mbuf containing the data to be sent
307 * [3] "dst" = sockaddr_in (IP) address of dest.
309 * [4] "desten" = ATM pseudo header which we will fill in VPI/VCI info
311 * 0 == resolve FAILED; note that "m" gets m_freem'd in this case
312 * 1 == resolve OK; desten contains result
314 * XXX: will need more work if we wish to support ATMARP in the kernel,
315 * but this is enough for PVCs entered via the "route" command.
318 atmresolve(struct rtentry
*rt
, struct mbuf
*m
, struct sockaddr
*dst
,
319 struct atm_pseudohdr
*desten
)
321 struct sockaddr_dl
*sdl
;
323 if (m
->m_flags
& (M_BCAST
| M_MCAST
)) {
325 "atmresolve: BCAST/MCAST packet detected/dumped\n");
330 rt
= RTALLOC1(dst
, 0); /* link level on table 0 XXX MRT */
332 goto bad
; /* failed */
333 RT_REMREF(rt
); /* don't keep LL references */
334 if ((rt
->rt_flags
& RTF_GATEWAY
) != 0 ||
335 (rt
->rt_flags
& RTF_LLINFO
) == 0 ||
336 /* XXX: are we using LLINFO? */
337 rt
->rt_gateway
->sa_family
!= AF_LINK
) {
345 * note that rt_gateway is a sockaddr_dl which contains the
346 * atm_pseudohdr data structure for this route. we currently
347 * don't need any rt_llinfo info (but will if we want to support
348 * ATM ARP [c.f. if_ether.c]).
350 sdl
= SDL(rt
->rt_gateway
);
353 * Check the address family and length is valid, the address
354 * is resolved; otherwise, try to resolve.
356 if (sdl
->sdl_family
== AF_LINK
&& sdl
->sdl_alen
>= sizeof(*desten
)) {
357 bcopy(LLADDR(sdl
), desten
, sizeof(*desten
));
358 return (1); /* ok, go for it! */
362 * we got an entry, but it doesn't have valid link address
363 * info in it (it is prob. the interface route, which has
364 * sdl_alen == 0). dump packet. (fall through to "bad").