]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netccitt/llc_input.c
aacbce91c7ea75a2a3fb2f8e3e7b91807fac7437
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
23 * Copyright (C) Dirk Husemann, Computer Science Department IV,
24 * University of Erlangen-Nuremberg, Germany, 1990, 1991, 1992
25 * Copyright (c) 1992, 1993
26 * The Regents of the University of California. All rights reserved.
28 * This code is derived from software contributed to Berkeley by
29 * Dirk Husemann and the Computer Science Department (IV) of
30 * the University of Erlangen-Nuremberg, Germany.
32 * Redistribution and use in source and binary forms, with or without
33 * modification, are permitted provided that the following conditions
35 * 1. Redistributions of source code must retain the above copyright
36 * notice, this list of conditions and the following disclaimer.
37 * 2. Redistributions in binary form must reproduce the above copyright
38 * notice, this list of conditions and the following disclaimer in the
39 * documentation and/or other materials provided with the distribution.
40 * 3. All advertising materials mentioning features or use of this software
41 * must display the following acknowledgement:
42 * This product includes software developed by the University of
43 * California, Berkeley and its contributors.
44 * 4. Neither the name of the University nor the names of its contributors
45 * may be used to endorse or promote products derived from this software
46 * without specific prior written permission.
48 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 * @(#)llc_input.c 8.1 (Berkeley) 6/10/93
63 #include <sys/param.h>
64 #include <sys/systm.h>
66 #include <sys/domain.h>
67 #include <sys/socket.h>
68 #include <sys/protosw.h>
69 #include <sys/errno.h>
71 #include <sys/kernel.h>
74 #include <net/if_dl.h>
75 #include <net/if_llc.h>
76 #include <net/route.h>
78 #include <netccitt/dll.h>
79 #include <netccitt/llc_var.h>
82 * This module implements LLC as specified by ISO 8802-2.
87 * llcintr() handles all LLC frames (except ISO CLNS ones for the time being)
88 * and tries to pass them on to the appropriate network layer entity.
93 register struct mbuf
*m
;
95 register int frame_kind
;
96 register u_char cmdrsp
;
97 struct llc_linkcb
*linkp
;
99 struct npaidbentry
*sapinfo
;
100 struct sdl_hdr
*sdlhdr
;
106 struct rtentry
*llrt
;
107 struct rtentry
*nlrt
;
111 IF_DEQUEUE(&llcintrq
, m
);
116 if ((m
->m_flags
& M_PKTHDR
) == 0)
117 panic("llcintr no HDR");
120 * Get ifp this packet was received on
122 ifp
= m
->m_pkthdr
.rcvif
;
124 sdlhdr
= mtod(m
, struct sdl_hdr
*);
127 * [Copied from net/ip_input.c]
129 * Check that the amount of data in the buffers is
130 * at least as much as the LLC header tells us.
131 * Trim mbufs if longer than expected.
132 * Drop packets if shorter than we think they are.
134 * Layout of mbuf chain at this point:
136 * +-------------------------------+----+ -\
137 * | sockaddr_dl src - sdlhdr_src | 20 | \
138 * +-------------------------------+----+ |
139 * | sockaddr_dl dst - sdlhdr_dst | 20 | > sizeof(struct sdl_hdr) == 44
140 * +-------------------------------+----+ |
141 * | LLC frame len - sdlhdr_len | 04 | /
142 * +-------------------------------+----+ -/
146 * +----------------------------+----+ -\
147 * | llc DSAP | 01 | \
148 * +----------------------------+----+ |
149 * | llc SSAP | 01 | |
150 * +----------------------------+----+ > sdlhdr_len
151 * | llc control | 01 | |
152 * +----------------------------+----+ |
156 * Thus the we expect to have exactly
157 * (sdlhdr->sdlhdr_len+sizeof(struct sdl_hdr)) in the mbuf chain
159 expected_len
= sdlhdr
->sdlhdr_len
+ sizeof(struct sdl_hdr
);
161 if (m
->m_pkthdr
.len
< expected_len
) {
165 if (m
->m_pkthdr
.len
> expected_len
) {
166 if (m
->m_len
== m
->m_pkthdr
.len
) {
167 m
->m_len
= expected_len
;
168 m
->m_pkthdr
.len
= expected_len
;
170 m_adj(m
, expected_len
- m
->m_pkthdr
.len
);
176 if (m
->m_len
> sizeof(struct sdl_hdr
))
177 frame
= mtod((struct mbuf
*)((struct sdl_hdr
*)(m
+1)),
179 else frame
= mtod(m
->m_next
, struct llc
*);
180 if (frame
== (struct llc
*) NULL
)
181 panic("llcintr no llc header");
184 * Now check for bogus I/S frame, i.e. those with a control
185 * field telling us they're an I/S frame yet their length
186 * is less than the established I/S frame length (DSAP + SSAP +
187 * control + N(R)&P/F = 4) --- we drop those suckers
189 if (((frame
->llc_control
& 0x03) != 0x03)
190 && ((expected_len
- sizeof(struct sdl_hdr
)) < LLC_ISFRAMELEN
)) {
192 printf("llc: hurz error\n");
197 * Get link control block for the addressed link connection.
198 * If there is none we take care of it later on.
200 cmdrsp
= (frame
->llc_ssap
& 0x01);
201 frame
->llc_ssap
&= ~0x01;
202 if (llrt
= rtalloc1((struct sockaddr
*)&sdlhdr
->sdlhdr_src
, 0))
205 else llrt
= npaidb_enter(&sdlhdr
->sdlhdr_src
, 0, 0, 0);
209 * We cannot do anything currently here as we
210 * don't `know' this link --- drop it
215 linkp
= ((struct npaidbentry
*)(llrt
->rt_llinfo
))->np_link
;
216 nlrt
= ((struct npaidbentry
*)(llrt
->rt_llinfo
))->np_rt
;
219 * If the link is not existing right now, we can try and look up
220 * the SAP info block.
222 if ((linkp
== 0) && frame
->llc_ssap
)
223 sapinfo
= llc_getsapinfo(frame
->llc_dsap
, ifp
);
226 * Handle XID and TEST frames
227 * XID: if DLSAP == 0, return type-of-services
230 * format-identifier-?
231 * if DLSAP != 0, locate sapcb and return
234 * format-identifier-?
235 * TEST: swap (snpah_dst, snpah_src) and return frame
237 * Also toggle the CMD/RESP bit
239 * Is this behaviour correct? Check ISO 8802-2 (90)!
241 frame_kind
= llc_decode(frame
, (struct llc_linkcb
*)0);
244 if (linkp
|| sapinfo
) {
246 frame
->llc_window
= linkp
->llcl_window
;
247 else frame
->llc_window
= sapinfo
->si_window
;
248 frame
->llc_fid
= 9; /* XXX */
249 frame
->llc_class
= sapinfo
->si_class
;
250 frame
->llc_ssap
= frame
->llc_dsap
;
252 frame
->llc_window
= 0;
254 frame
->llc_class
= 1;
255 frame
->llc_dsap
= frame
->llc_ssap
= 0;
260 sdl_swapaddr(&(mtod(m
, struct sdl_hdr
*)->sdlhdr_dst
),
261 &(mtod(m
, struct sdl_hdr
*)->sdlhdr_src
));
263 /* Now set the CMD/RESP bit */
264 frame
->llc_ssap
|= (cmdrsp
== 0x0 ? 0x1 : 0x0);
266 /* Ship it out again */
267 (*ifp
->if_output
)(ifp
, m
,
268 (struct sockaddr
*) &(mtod(m
, struct sdl_hdr
*)->sdlhdr_dst
),
269 (struct rtentry
*) 0);
274 * Create link control block in case it is not existing
276 if (linkp
== 0 && sapinfo
) {
277 if ((linkp
= llc_newlink(&sdlhdr
->sdlhdr_src
, ifp
, nlrt
,
278 (nlrt
== 0) ? 0 : nlrt
->rt_llinfo
,
280 printf("llcintr: couldn't create new link\n");
284 ((struct npaidbentry
*)llrt
->rt_llinfo
)->np_link
= linkp
;
285 } else if (linkp
== 0) {
286 /* The link is not known to us, drop the frame and continue */
292 * Drop SNPA header and get rid of empty mbuf at the
293 * front of the mbuf chain (I don't like 'em)
295 m_adj(m
, sizeof(struct sdl_hdr
));
297 * LLC_UFRAMELEN is sufficient, m_pullup() will pull up
298 * the min(m->m_len, maxprotohdr_len [=40]) thus doing
301 if ((m
= m_pullup(m
, LLC_UFRAMELEN
)))
303 * Pass it on thru the elements of procedure
305 llc_input(linkp
, m
, cmdrsp
);
311 * llc_input() --- We deal with the various incoming frames here.
312 * Basically we (indirectly) call the appropriate
313 * state handler function that's pointed to by
316 * The statehandler returns an action code ---
317 * further actions like
318 * o notify network layer
319 * o block further sending
322 * are then enacted accordingly.
324 llc_input(struct llc_linkcb
*linkp
, struct mbuf
*m
, u_char cmdrsp
)
330 struct ifnet
*ifp
= linkp
->llcl_if
;
332 if ((frame
= mtod(m
, struct llc
*)) == (struct llc
*) 0) {
336 pollfinal
= ((frame
->llc_control
& 0x03) == 0x03) ?
337 LLCGBITS(frame
->llc_control
, u_pf
) :
338 LLCGBITS(frame
->llc_control_ext
, s_pf
);
341 * first decode the frame
343 frame_kind
= llc_decode(frame
, linkp
);
345 switch (action
= llc_statehandler(linkp
, frame
, frame_kind
, cmdrsp
,
347 case LLC_DATA_INDICATION
:
348 m_adj(m
, LLC_ISFRAMELEN
);
349 if (m
= m_pullup(m
, NLHDRSIZEGUESS
)) {
350 m
->m_pkthdr
.rcvif
= (struct ifnet
*)linkp
->llcl_nlnext
;
351 (*linkp
->llcl_sapinfo
->si_input
)(m
);
356 /* release mbuf if not an info frame */
357 if (action
!= LLC_DATA_INDICATION
&& m
)
360 /* try to get frames out ... */
367 * This routine is called by configuration setup. It sets up a station control
368 * block and notifies all registered upper level protocols.
371 llc_ctlinput(int prc
, struct sockaddr
*addr
, caddr_t info
)
375 struct dll_ctlinfo
*ctlinfo
= (struct dll_ctlinfo
*)info
;
377 struct dllconfig
*config
;
379 struct rtentry
*nlrt
;
380 struct rtentry
*llrt
;
381 struct llc_linkcb
*linkp
;
384 /* info must point to something valid at all times */
388 if (prc
== PRC_IFUP
|| prc
== PRC_IFDOWN
) {
389 /* we use either this set ... */
390 ifa
= ifa_ifwithaddr(addr
);
391 ifp
= ifa
? ifa
->ifa_ifp
: 0;
395 sap
= ctlinfo
->dlcti_lsap
;
396 config
= ctlinfo
->dlcti_cfg
;
398 nlrt
= (struct rtentry
*) 0;
402 config
= (struct dllconfig
*) 0;
403 pcb
= ctlinfo
->dlcti_pcb
;
404 nlrt
= ctlinfo
->dlcti_rt
;
406 if ((llrt
= rtalloc1(nlrt
->rt_gateway
, 0)))
410 linkp
= ((struct npaidbentry
*)llrt
->rt_llinfo
)->np_link
;
415 (void) llc_setsapinfo(ifp
, addr
->sa_family
, sap
, config
);
419 register struct llc_linkcb
*linkp
;
420 register struct llc_linkcb
*nlinkp
;
424 * All links are accessible over the doubly linked list llccb_q
428 * A for-loop is not that great an idea as the linkp
429 * will get deleted by llc_timer()
432 while (LQVALID(linkp
)) {
433 nlinkp
= LQNEXT(linkp
);
434 if (linkp
->llcl_if
= ifp
) {
436 (void)llc_statehandler(linkp
, (struct llc
*)0,
437 NL_DISCONNECT_REQUEST
,
446 case PRC_CONNECT_REQUEST
:
448 if ((linkp
= llc_newlink((struct sockaddr_dl
*) nlrt
->rt_gateway
,
452 ((struct npaidbentry
*)llrt
->rt_llinfo
)->np_link
= linkp
;
454 (void)llc_statehandler(linkp
, (struct llc
*) 0,
455 NL_CONNECT_REQUEST
, 0, 1);
458 return ((caddr_t
)linkp
);
460 case PRC_DISCONNECT_REQUEST
:
462 panic("no link control block!");
465 (void)llc_statehandler(linkp
, (struct llc
*) 0,
466 NL_DISCONNECT_REQUEST
, 0, 1);
470 * The actual removal of the link control block is done by the
471 * cleaning neutrum (i.e. llc_timer()).
475 case PRC_RESET_REQUEST
:
477 panic("no link control block!");
480 (void)llc_statehandler(linkp
, (struct llc
*) 0,
481 NL_RESET_REQUEST
, 0, 1);