This source file includes following definitions.
- atm_output
- atm_input
- atm_ifattach
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79 #include <sys/param.h>
80 #include <sys/systm.h>
81 #include <sys/kernel.h>
82 #include <sys/malloc.h>
83 #include <sys/mbuf.h>
84 #include <sys/protosw.h>
85 #include <sys/socket.h>
86 #include <sys/ioctl.h>
87 #include <sys/errno.h>
88 #include <sys/syslog.h>
89
90 #include <machine/cpu.h>
91
92 #include <net/if.h>
93 #include <net/netisr.h>
94 #include <net/route.h>
95 #include <net/if_dl.h>
96 #include <net/if_types.h>
97 #include <net/if_atm.h>
98
99 #include <netinet/in.h>
100 #include <netinet/if_atm.h>
101 #include <netinet/if_ether.h>
102 #if defined(INET) || defined(INET6)
103 #include <netinet/in_var.h>
104 #endif
105 #ifdef NATM
106 #include <netnatm/natm.h>
107 #endif
108
109 #ifdef INET6
110 #include <netinet6/in6_var.h>
111 #endif
112
113 #define senderr(e) { error = (e); goto bad;}
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130 int
131 atm_output(ifp, m0, dst, rt0)
132 struct ifnet *ifp;
133 struct mbuf *m0;
134 struct sockaddr *dst;
135 struct rtentry *rt0;
136 {
137 u_int16_t etype = 0;
138 int s, error = 0, sz, len;
139 struct atm_pseudohdr atmdst, *ad;
140 struct mbuf *m = m0;
141 struct rtentry *rt;
142 struct atmllc *atmllc;
143 u_int32_t atm_flags;
144
145 if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING))
146 senderr(ENETDOWN);
147
148
149
150
151 if ((rt = rt0) != NULL) {
152
153 if ((rt->rt_flags & RTF_UP) == 0) {
154 if ((rt0 = rt = RTALLOC1(dst, 0)) != NULL)
155 rt->rt_refcnt--;
156 else
157 senderr(EHOSTUNREACH);
158 }
159
160 if (rt->rt_flags & RTF_GATEWAY) {
161 if (rt->rt_gwroute == 0)
162 goto lookup;
163 if (((rt = rt->rt_gwroute)->rt_flags & RTF_UP) == 0) {
164 rtfree(rt); rt = rt0;
165 lookup: rt->rt_gwroute = RTALLOC1(rt->rt_gateway, 0);
166 if ((rt = rt->rt_gwroute) == 0)
167 senderr(EHOSTUNREACH);
168 }
169 }
170
171
172
173 }
174
175
176
177
178 if (dst) {
179 switch (dst->sa_family) {
180 #ifdef INET
181 case AF_INET:
182 #endif
183 #ifdef INET6
184 case AF_INET6:
185 #endif
186 #if defined(INET) || defined(INET6)
187 if (dst->sa_family == AF_INET)
188 etype = ETHERTYPE_IP;
189 else
190 etype = ETHERTYPE_IPV6;
191 if (!atmresolve(rt, m, dst, &atmdst)) {
192 m = NULL;
193
194 senderr(EHOSTUNREACH);
195
196
197 }
198 break;
199 #endif
200
201 default:
202 #if defined(__NetBSD__) || defined(__OpenBSD__)
203 printf("%s: can't handle af%d\n", ifp->if_xname,
204 dst->sa_family);
205 #elif defined(__FreeBSD__) || defined(__bsdi__)
206 printf("%s%d: can't handle af%d\n", ifp->if_name,
207 ifp->if_unit, dst->sa_family);
208 #endif
209 senderr(EAFNOSUPPORT);
210 }
211
212
213
214
215 sz = sizeof(atmdst);
216 atm_flags = ATM_PH_FLAGS(&atmdst);
217 if (atm_flags & ATM_PH_LLCSNAP) sz += 8;
218 M_PREPEND(m, sz, M_DONTWAIT);
219 if (m == 0)
220 senderr(ENOBUFS);
221 ad = mtod(m, struct atm_pseudohdr *);
222 *ad = atmdst;
223 if (atm_flags & ATM_PH_LLCSNAP) {
224 atmllc = (struct atmllc *)(ad + 1);
225 bcopy(ATMLLC_HDR, atmllc->llchdr,
226 sizeof(atmllc->llchdr));
227 ATM_LLC_SETTYPE(atmllc, etype);
228 }
229 }
230
231
232
233
234
235 len = m->m_pkthdr.len;
236 s = splnet();
237 IFQ_ENQUEUE(&ifp->if_snd, m, NULL, error);
238 if (error) {
239 splx(s);
240 return (error);
241 }
242 ifp->if_obytes += len;
243 if ((ifp->if_flags & IFF_OACTIVE) == 0)
244 (*ifp->if_start)(ifp);
245 splx(s);
246 return (error);
247
248 bad:
249 if (m)
250 m_freem(m);
251 return (error);
252 }
253
254
255
256
257
258 void
259 atm_input(ifp, ah, m, rxhand)
260 struct ifnet *ifp;
261 struct atm_pseudohdr *ah;
262 struct mbuf *m;
263 void *rxhand;
264 {
265 struct ifqueue *inq;
266 u_int16_t etype = ETHERTYPE_IP;
267 int s;
268
269 if ((ifp->if_flags & IFF_UP) == 0) {
270 m_freem(m);
271 return;
272 }
273 ifp->if_ibytes += m->m_pkthdr.len;
274
275 if (rxhand) {
276 #ifdef NATM
277 struct natmpcb *npcb = rxhand;
278 s = splnet();
279 npcb->npcb_inq++;
280 splx(s);
281 schednetisr(NETISR_NATM);
282 inq = &natmintrq;
283 m->m_pkthdr.rcvif = rxhand;
284 #else
285 printf("atm_input: NATM detected but not configured in kernel\n");
286 m_freem(m);
287 return;
288 #endif
289 } else {
290
291
292
293 if (ATM_PH_FLAGS(ah) & ATM_PH_LLCSNAP) {
294 struct atmllc *alc;
295 if (m->m_len < sizeof(*alc) &&
296 (m = m_pullup(m, sizeof(*alc))) == NULL)
297 return;
298 alc = mtod(m, struct atmllc *);
299 if (bcmp(alc, ATMLLC_HDR, 6)) {
300 #if defined(__NetBSD__) || defined(__OpenBSD__)
301 printf("%s: recv'd invalid LLC/SNAP frame [vp=%d,vc=%d]\n",
302 ifp->if_xname, ATM_PH_VPI(ah), ATM_PH_VCI(ah));
303 #elif defined(__FreeBSD__) || defined(__bsdi__)
304 printf("%s%d: recv'd invalid LLC/SNAP frame [vp=%d,vc=%d]\n",
305 ifp->if_name, ifp->if_unit, ATM_PH_VPI(ah), ATM_PH_VCI(ah));
306 #endif
307 m_freem(m);
308 return;
309 }
310 etype = ATM_LLC_TYPE(alc);
311 m_adj(m, sizeof(*alc));
312 }
313
314 switch (etype) {
315 #ifdef INET
316 case ETHERTYPE_IP:
317 schednetisr(NETISR_IP);
318 inq = &ipintrq;
319 break;
320 #endif
321 #ifdef INET6
322 case ETHERTYPE_IPV6:
323 schednetisr(NETISR_IPV6);
324 inq = &ip6intrq;
325 break;
326 #endif
327 default:
328 m_freem(m);
329 return;
330 }
331 }
332
333 s = splnet();
334 IF_INPUT_ENQUEUE(inq, m);
335 splx(s);
336 }
337
338
339
340
341 void
342 atm_ifattach(ifp)
343 struct ifnet *ifp;
344 {
345
346 ifp->if_type = IFT_ATM;
347 ifp->if_addrlen = 0;
348 ifp->if_hdrlen = 0;
349 ifp->if_mtu = ATMMTU;
350 ifp->if_output = atm_output;
351
352 if_alloc_sadl(ifp);
353 #ifdef notyet
354 bcopy(ifp->hw_addr, LLADDR(ifp->if_sadl), ifp->if_addrlen);
355 #endif
356 }