1 /* $NetBSD: if_atm.c,v 1.30 2009/03/18 17:06:52 cegger 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.
36 * IP <=> ATM address resolution.
39 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: if_atm.c,v 1.30 2009/03/18 17:06:52 cegger Exp $");
45 #if defined(INET) || defined(INET6)
47 #include <sys/param.h>
48 #include <sys/systm.h>
49 #include <sys/malloc.h>
51 #include <sys/socket.h>
53 #include <sys/kernel.h>
54 #include <sys/errno.h>
55 #include <sys/ioctl.h>
56 #include <sys/syslog.h>
60 #include <net/if_dl.h>
61 #include <net/route.h>
62 #include <net/if_atm.h>
64 #include <netinet/in.h>
65 #include <netinet/in_systm.h>
66 #include <netinet/in_var.h>
67 #include <netinet/ip.h>
68 #include <netinet/if_atm.h>
71 #include <netnatm/natm.h>
76 * atm_rtrequest: handle ATM rt request (in support of generic code)
77 * inputs: "req" = request code
83 atm_rtrequest(int req
, struct rtentry
*rt
, const struct rt_addrinfo
*info
)
85 struct sockaddr
*gate
= rt
->rt_gateway
;
86 struct atm_pseudoioctl api
;
88 const struct sockaddr_in
*sin
;
89 struct natmpcb
*npcb
= NULL
;
90 const struct atm_pseudohdr
*aph
;
92 const struct ifnet
*ifp
= rt
->rt_ifp
;
93 uint8_t namelen
= strlen(ifp
->if_xname
);
94 uint8_t addrlen
= ifp
->if_addrlen
;
96 if (rt
->rt_flags
& RTF_GATEWAY
) /* link level requests only */
101 case RTM_RESOLVE
: /* resolve: only happens when cloning */
102 printf("atm_rtrequest: RTM_RESOLVE request detected?\n");
108 * route added by a command (e.g. ifconfig, route, arp...).
110 * first check to see if this is not a host route, in which
111 * case we are being called via "ifconfig" to set the address.
114 if ((rt
->rt_flags
& RTF_HOST
) == 0) {
117 struct sockaddr_dl sdl
;
118 struct sockaddr_storage ss
;
121 sockaddr_dl_init(&u
.sdl
, sizeof(u
.ss
),
122 ifp
->if_index
, ifp
->if_type
,
123 NULL
, namelen
, NULL
, addrlen
);
124 rt_setgate(rt
, &u
.sa
);
125 gate
= rt
->rt_gateway
;
129 if ((rt
->rt_flags
& RTF_CLONING
) != 0) {
130 printf("atm_rtrequest: cloning route detected?\n");
133 if (gate
->sa_family
!= AF_LINK
||
134 gate
->sa_len
< sockaddr_dl_measure(namelen
, addrlen
)) {
135 log(LOG_DEBUG
, "atm_rtrequest: bad gateway value");
140 if (rt
->rt_ifp
->if_ioctl
== NULL
) panic("atm null ioctl");
145 * let native ATM know we are using this VCI/VPI
148 sin
= satocsin(rt_getkey(rt
));
149 if (sin
->sin_family
!= AF_INET
)
151 aph
= (const struct atm_pseudohdr
*)CLLADDR(satosdl(gate
));
152 npcb
= npcb_add(NULL
, rt
->rt_ifp
, ATM_PH_VCI(aph
),
156 npcb
->npcb_flags
|= NPCB_IP
;
157 npcb
->ipaddr
.s_addr
= sin
->sin_addr
.s_addr
;
158 /* XXX: move npcb to llinfo when ATM ARP is ready */
159 rt
->rt_llinfo
= (void *) npcb
;
160 rt
->rt_flags
|= RTF_LLINFO
;
163 * let the lower level know this circuit is active
165 memcpy(&api
.aph
, CLLADDR(satocsdl(gate
)), sizeof(api
.aph
));
167 if (rt
->rt_ifp
->if_ioctl(rt
->rt_ifp
, SIOCATMENA
, &api
) != 0) {
168 printf("atm: couldn't add VC\n");
172 satosdl(gate
)->sdl_type
= rt
->rt_ifp
->if_type
;
173 satosdl(gate
)->sdl_index
= rt
->rt_ifp
->if_index
;
180 npcb_free(npcb
, NPCB_DESTROY
);
181 rt
->rt_llinfo
= NULL
;
182 rt
->rt_flags
&= ~RTF_LLINFO
;
185 rtrequest(RTM_DELETE
, rt_getkey(rt
), NULL
,
186 rt_mask(rt
), 0, NULL
);
193 * tell native ATM we are done with this VC
196 if (rt
->rt_flags
& RTF_LLINFO
) {
197 npcb_free((struct natmpcb
*)rt
->rt_llinfo
,
199 rt
->rt_llinfo
= NULL
;
200 rt
->rt_flags
&= ~RTF_LLINFO
;
204 * tell the lower layer to disable this circuit
207 memcpy(&api
.aph
, CLLADDR(satocsdl(gate
)), sizeof(api
.aph
));
209 (void)rt
->rt_ifp
->if_ioctl(rt
->rt_ifp
, SIOCATMDIS
, &api
);
218 * [1] "rt" = the link level route to use (or null if need to look one up)
219 * [2] "m" = mbuf containing the data to be sent
220 * [3] "dst" = sockaddr_in (IP) address of dest.
222 * [4] "desten" = ATM pseudo header which we will fill in VPI/VCI info
224 * 0 == resolve FAILED; note that "m" gets m_freem'd in this case
225 * 1 == resolve OK; desten contains result
227 * XXX: will need more work if we wish to support ATMARP in the kernel,
228 * but this is enough for PVCs entered via the "route" command.
232 atmresolve(struct rtentry
*rt
, struct mbuf
*m
, const struct sockaddr
*dst
,
233 struct atm_pseudohdr
*desten
/* OUT */)
235 const struct sockaddr_dl
*sdl
;
237 if (m
->m_flags
& (M_BCAST
|M_MCAST
)) {
238 log(LOG_INFO
, "atmresolve: BCAST/MCAST packet detected/dumped");
243 rt
= RTALLOC1(dst
, 0);
244 if (rt
== NULL
) goto bad
; /* failed */
245 rt
->rt_refcnt
--; /* don't keep LL references */
246 if ((rt
->rt_flags
& RTF_GATEWAY
) != 0 ||
247 (rt
->rt_flags
& RTF_LLINFO
) == 0 ||
248 /* XXX: are we using LLINFO? */
249 rt
->rt_gateway
->sa_family
!= AF_LINK
) {
255 * note that rt_gateway is a sockaddr_dl which contains the
256 * atm_pseudohdr data structure for this route. we currently
257 * don't need any rt_llinfo info (but will if we want to support
258 * ATM ARP [c.f. if_ether.c]).
261 sdl
= satocsdl(rt
->rt_gateway
);
264 * Check the address family and length is valid, the address
265 * is resolved; otherwise, try to resolve.
269 if (sdl
->sdl_family
== AF_LINK
&& sdl
->sdl_alen
== sizeof(*desten
)) {
270 memcpy(desten
, CLLADDR(sdl
), sdl
->sdl_alen
);
271 return (1); /* ok, go for it! */
275 * we got an entry, but it doesn't have valid link address
276 * info in it (it is prob. the interface route, which has
277 * sdl_alen == 0). dump packet. (fall through to "bad").