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