Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / netinet / if_atm.c
blob7dfb8c5088ac7f1d74657cb13d0004c709595333
1 /* $NetBSD: if_atm.c,v 1.30 2009/03/18 17:06:52 cegger Exp $ */
3 /*
5 * Copyright (c) 1996 Charles D. Cranor and Washington University.
6 * All rights reserved.
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.
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 $");
42 #include "opt_inet.h"
43 #include "opt_natm.h"
45 #if defined(INET) || defined(INET6)
47 #include <sys/param.h>
48 #include <sys/systm.h>
49 #include <sys/malloc.h>
50 #include <sys/mbuf.h>
51 #include <sys/socket.h>
52 #include <sys/time.h>
53 #include <sys/kernel.h>
54 #include <sys/errno.h>
55 #include <sys/ioctl.h>
56 #include <sys/syslog.h>
57 #include <sys/proc.h>
59 #include <net/if.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>
70 #ifdef NATM
71 #include <netnatm/natm.h>
72 #endif
76 * atm_rtrequest: handle ATM rt request (in support of generic code)
77 * inputs: "req" = request code
78 * "rt" = route entry
79 * "sa" = sockaddr
82 void
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;
87 #ifdef NATM
88 const struct sockaddr_in *sin;
89 struct natmpcb *npcb = NULL;
90 const struct atm_pseudohdr *aph;
91 #endif
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 */
97 return;
99 switch (req) {
101 case RTM_RESOLVE: /* resolve: only happens when cloning */
102 printf("atm_rtrequest: RTM_RESOLVE request detected?\n");
103 break;
105 case RTM_ADD:
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) {
115 union {
116 struct sockaddr sa;
117 struct sockaddr_dl sdl;
118 struct sockaddr_storage ss;
119 } u;
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;
126 break;
129 if ((rt->rt_flags & RTF_CLONING) != 0) {
130 printf("atm_rtrequest: cloning route detected?\n");
131 break;
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");
136 break;
139 #ifdef DIAGNOSTIC
140 if (rt->rt_ifp->if_ioctl == NULL) panic("atm null ioctl");
141 #endif
143 #ifdef NATM
145 * let native ATM know we are using this VCI/VPI
146 * (i.e. reserve it)
148 sin = satocsin(rt_getkey(rt));
149 if (sin->sin_family != AF_INET)
150 goto failed;
151 aph = (const struct atm_pseudohdr *)CLLADDR(satosdl(gate));
152 npcb = npcb_add(NULL, rt->rt_ifp, ATM_PH_VCI(aph),
153 ATM_PH_VPI(aph));
154 if (npcb == NULL)
155 goto failed;
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;
161 #endif
163 * let the lower level know this circuit is active
165 memcpy(&api.aph, CLLADDR(satocsdl(gate)), sizeof(api.aph));
166 api.rxhand = NULL;
167 if (rt->rt_ifp->if_ioctl(rt->rt_ifp, SIOCATMENA, &api) != 0) {
168 printf("atm: couldn't add VC\n");
169 goto failed;
172 satosdl(gate)->sdl_type = rt->rt_ifp->if_type;
173 satosdl(gate)->sdl_index = rt->rt_ifp->if_index;
175 break;
177 failed:
178 #ifdef NATM
179 if (npcb) {
180 npcb_free(npcb, NPCB_DESTROY);
181 rt->rt_llinfo = NULL;
182 rt->rt_flags &= ~RTF_LLINFO;
184 #endif
185 rtrequest(RTM_DELETE, rt_getkey(rt), NULL,
186 rt_mask(rt), 0, NULL);
187 break;
189 case RTM_DELETE:
191 #ifdef NATM
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,
198 NPCB_DESTROY);
199 rt->rt_llinfo = NULL;
200 rt->rt_flags &= ~RTF_LLINFO;
202 #endif
204 * tell the lower layer to disable this circuit
207 memcpy(&api.aph, CLLADDR(satocsdl(gate)), sizeof(api.aph));
208 api.rxhand = NULL;
209 (void)rt->rt_ifp->if_ioctl(rt->rt_ifp, SIOCATMDIS, &api);
211 break;
216 * atmresolve:
217 * inputs:
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.
221 * output:
222 * [4] "desten" = ATM pseudo header which we will fill in VPI/VCI info
223 * return:
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");
239 goto bad;
242 if (rt == NULL) {
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) {
250 goto bad;
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").
280 bad:
281 m_freem(m);
282 return (0);
284 #endif /* INET */