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