FreeBSD/Linux Kernel Cross Reference
sys/netinet/if_atm.c
1 /* $NetBSD: if_atm.c,v 1.17 2005/02/02 21:41:01 perry 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
35 /*
36 * IP <=> ATM address resolution.
37 */
38
39 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: if_atm.c,v 1.17 2005/02/02 21:41:01 perry Exp $");
41
42 #include "opt_inet.h"
43 #include "opt_natm.h"
44
45 #if defined(INET) || defined(INET6)
46
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>
58
59 #include <net/if.h>
60 #include <net/if_dl.h>
61 #include <net/route.h>
62 #include <net/if_atm.h>
63
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>
69
70 #ifdef NATM
71 #include <netnatm/natm.h>
72 #endif
73
74
75 #define SDL(s) ((struct sockaddr_dl *)s)
76
77 /*
78 * atm_rtrequest: handle ATM rt request (in support of generic code)
79 * inputs: "req" = request code
80 * "rt" = route entry
81 * "sa" = sockaddr
82 */
83
84 void
85 atm_rtrequest(int req, struct rtentry *rt, struct rt_addrinfo *info)
86 {
87 struct sockaddr *gate = rt->rt_gateway;
88 struct atm_pseudoioctl api;
89 #ifdef NATM
90 struct sockaddr_in *sin;
91 struct natmpcb *npcb = NULL;
92 struct atm_pseudohdr *aph;
93 #endif
94 static struct sockaddr_dl null_sdl = {sizeof(null_sdl), AF_LINK};
95
96 if (rt->rt_flags & RTF_GATEWAY) /* link level requests only */
97 return;
98
99 switch (req) {
100
101 case RTM_RESOLVE: /* resolve: only happens when cloning */
102 printf("atm_rtrequest: RTM_RESOLVE request detected?\n");
103 break;
104
105 case RTM_ADD:
106
107 /*
108 * route added by a command (e.g. ifconfig, route, arp...).
109 *
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.
112 */
113
114 if ((rt->rt_flags & RTF_HOST) == 0) {
115 rt_setgate(rt,rt_key(rt),(struct sockaddr *)&null_sdl);
116 gate = rt->rt_gateway;
117 SDL(gate)->sdl_type = rt->rt_ifp->if_type;
118 SDL(gate)->sdl_index = rt->rt_ifp->if_index;
119 break;
120 }
121
122 if ((rt->rt_flags & RTF_CLONING) != 0) {
123 printf("atm_rtrequest: cloning route detected?\n");
124 break;
125 }
126 if (gate->sa_family != AF_LINK ||
127 gate->sa_len < sizeof(null_sdl)) {
128 log(LOG_DEBUG, "atm_rtrequest: bad gateway value");
129 break;
130 }
131
132 #ifdef DIAGNOSTIC
133 if (rt->rt_ifp->if_ioctl == NULL) panic("atm null ioctl");
134 #endif
135
136 #ifdef NATM
137 /*
138 * let native ATM know we are using this VCI/VPI
139 * (i.e. reserve it)
140 */
141 sin = (struct sockaddr_in *) rt_key(rt);
142 if (sin->sin_family != AF_INET)
143 goto failed;
144 aph = (struct atm_pseudohdr *) LLADDR(SDL(gate));
145 npcb = npcb_add(NULL, rt->rt_ifp, ATM_PH_VCI(aph),
146 ATM_PH_VPI(aph));
147 if (npcb == NULL)
148 goto failed;
149 npcb->npcb_flags |= NPCB_IP;
150 npcb->ipaddr.s_addr = sin->sin_addr.s_addr;
151 /* XXX: move npcb to llinfo when ATM ARP is ready */
152 rt->rt_llinfo = (caddr_t) npcb;
153 rt->rt_flags |= RTF_LLINFO;
154 #endif
155 /*
156 * let the lower level know this circuit is active
157 */
158 bcopy(LLADDR(SDL(gate)), &api.aph, sizeof(api.aph));
159 api.rxhand = NULL;
160 if (rt->rt_ifp->if_ioctl(rt->rt_ifp, SIOCATMENA,
161 (caddr_t)&api) != 0) {
162 printf("atm: couldn't add VC\n");
163 goto failed;
164 }
165
166 SDL(gate)->sdl_type = rt->rt_ifp->if_type;
167 SDL(gate)->sdl_index = rt->rt_ifp->if_index;
168
169 break;
170
171 failed:
172 #ifdef NATM
173 if (npcb) {
174 npcb_free(npcb, NPCB_DESTROY);
175 rt->rt_llinfo = NULL;
176 rt->rt_flags &= ~RTF_LLINFO;
177 }
178 #endif
179 rtrequest(RTM_DELETE, rt_key(rt), (struct sockaddr *)0,
180 rt_mask(rt), 0, (struct rtentry **) 0);
181 break;
182
183 case RTM_DELETE:
184
185 #ifdef NATM
186 /*
187 * tell native ATM we are done with this VC
188 */
189
190 if (rt->rt_flags & RTF_LLINFO) {
191 npcb_free((struct natmpcb *)rt->rt_llinfo,
192 NPCB_DESTROY);
193 rt->rt_llinfo = NULL;
194 rt->rt_flags &= ~RTF_LLINFO;
195 }
196 #endif
197 /*
198 * tell the lower layer to disable this circuit
199 */
200
201 bcopy(LLADDR(SDL(gate)), &api.aph, sizeof(api.aph));
202 api.rxhand = NULL;
203 (void)rt->rt_ifp->if_ioctl(rt->rt_ifp, SIOCATMDIS,
204 (caddr_t)&api);
205
206 break;
207 }
208 }
209
210 /*
211 * atmresolve:
212 * inputs:
213 * [1] "rt" = the link level route to use (or null if need to look one up)
214 * [2] "m" = mbuf containing the data to be sent
215 * [3] "dst" = sockaddr_in (IP) address of dest.
216 * output:
217 * [4] "desten" = ATM pseudo header which we will fill in VPI/VCI info
218 * return:
219 * 0 == resolve FAILED; note that "m" gets m_freem'd in this case
220 * 1 == resolve OK; desten contains result
221 *
222 * XXX: will need more work if we wish to support ATMARP in the kernel,
223 * but this is enough for PVCs entered via the "route" command.
224 */
225
226 int
227 atmresolve(struct rtentry *rt, struct mbuf *m, struct sockaddr *dst,
228 struct atm_pseudohdr *desten /* OUT */)
229 {
230 struct sockaddr_dl *sdl;
231
232 if (m->m_flags & (M_BCAST|M_MCAST)) {
233 log(LOG_INFO, "atmresolve: BCAST/MCAST packet detected/dumped");
234 goto bad;
235 }
236
237 if (rt == NULL) {
238 rt = RTALLOC1(dst, 0);
239 if (rt == NULL) goto bad; /* failed */
240 rt->rt_refcnt--; /* don't keep LL references */
241 if ((rt->rt_flags & RTF_GATEWAY) != 0 ||
242 (rt->rt_flags & RTF_LLINFO) == 0 ||
243 /* XXX: are we using LLINFO? */
244 rt->rt_gateway->sa_family != AF_LINK) {
245 goto bad;
246 }
247 }
248
249 /*
250 * note that rt_gateway is a sockaddr_dl which contains the
251 * atm_pseudohdr data structure for this route. we currently
252 * don't need any rt_llinfo info (but will if we want to support
253 * ATM ARP [c.f. if_ether.c]).
254 */
255
256 sdl = SDL(rt->rt_gateway);
257
258 /*
259 * Check the address family and length is valid, the address
260 * is resolved; otherwise, try to resolve.
261 */
262
263
264 if (sdl->sdl_family == AF_LINK && sdl->sdl_alen == sizeof(*desten)) {
265 bcopy(LLADDR(sdl), desten, sdl->sdl_alen);
266 return (1); /* ok, go for it! */
267 }
268
269 /*
270 * we got an entry, but it doesn't have valid link address
271 * info in it (it is prob. the interface route, which has
272 * sdl_alen == 0). dump packet. (fall through to "bad").
273 */
274
275 bad:
276 m_freem(m);
277 return (0);
278 }
279 #endif /* INET */
Cache object: 72a288538d069f2b73f8551f492b805e
|