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