if_fddisubr.c (93371) | if_fddisubr.c (93373) |
---|---|
1/* 2 * Copyright (c) 1995, 1996 3 * Matt Thomas <matt@3am-software.com>. All rights reserved. 4 * Copyright (c) 1982, 1989, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 19 unchanged lines hidden (view full) --- 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 * 35 * from: if_ethersubr.c,v 1.5 1994/12/13 22:31:45 wollman Exp | 1/* 2 * Copyright (c) 1995, 1996 3 * Matt Thomas <matt@3am-software.com>. All rights reserved. 4 * Copyright (c) 1982, 1989, 1993 5 * The Regents of the University of California. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 19 unchanged lines hidden (view full) --- 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 * 35 * from: if_ethersubr.c,v 1.5 1994/12/13 22:31:45 wollman Exp |
36 * $FreeBSD: head/sys/net/if_fddisubr.c 93371 2002-03-29 08:14:29Z mdodd $ | 36 * $FreeBSD: head/sys/net/if_fddisubr.c 93373 2002-03-29 08:51:42Z mdodd $ |
37 */ 38 39#include "opt_atalk.h" 40#include "opt_inet.h" 41#include "opt_inet6.h" 42#include "opt_ipx.h" 43 44#include <sys/param.h> 45#include <sys/systm.h> 46#include <sys/mbuf.h> 47#include <sys/socket.h> 48#include <sys/malloc.h> 49 50#include <net/if.h> 51#include <net/netisr.h> 52#include <net/route.h> 53#include <net/if_llc.h> 54#include <net/if_dl.h> 55#include <net/if_types.h> | 37 */ 38 39#include "opt_atalk.h" 40#include "opt_inet.h" 41#include "opt_inet6.h" 42#include "opt_ipx.h" 43 44#include <sys/param.h> 45#include <sys/systm.h> 46#include <sys/mbuf.h> 47#include <sys/socket.h> 48#include <sys/malloc.h> 49 50#include <net/if.h> 51#include <net/netisr.h> 52#include <net/route.h> 53#include <net/if_llc.h> 54#include <net/if_dl.h> 55#include <net/if_types.h> |
56#include <net/fddi.h> |
|
56 57#if defined(INET) || defined(INET6) 58#include <netinet/in.h> 59#include <netinet/in_var.h> 60#include <netinet/if_ether.h> 61#endif 62#ifdef INET6 63#include <netinet6/nd6.h> 64#endif | 57 58#if defined(INET) || defined(INET6) 59#include <netinet/in.h> 60#include <netinet/in_var.h> 61#include <netinet/if_ether.h> 62#endif 63#ifdef INET6 64#include <netinet6/nd6.h> 65#endif |
65#include <netinet/if_fddi.h> | |
66 67#ifdef IPX 68#include <netipx/ipx.h> 69#include <netipx/ipx_if.h> 70#endif 71 72#ifdef NS 73#include <netns/ns.h> --- 30 unchanged lines hidden (view full) --- 104fddi_output(ifp, m, dst, rt0) 105 struct ifnet *ifp; 106 struct mbuf *m; 107 struct sockaddr *dst; 108 struct rtentry *rt0; 109{ 110 u_int16_t type; 111 int loop_copy = 0, error = 0, hdrcmplt = 0; | 66 67#ifdef IPX 68#include <netipx/ipx.h> 69#include <netipx/ipx_if.h> 70#endif 71 72#ifdef NS 73#include <netns/ns.h> --- 30 unchanged lines hidden (view full) --- 104fddi_output(ifp, m, dst, rt0) 105 struct ifnet *ifp; 106 struct mbuf *m; 107 struct sockaddr *dst; 108 struct rtentry *rt0; 109{ 110 u_int16_t type; 111 int loop_copy = 0, error = 0, hdrcmplt = 0; |
112 u_char esrc[6], edst[6]; | 112 u_char esrc[FDDI_ADDR_LEN], edst[FDDI_ADDR_LEN]; |
113 struct rtentry *rt; 114 struct fddi_header *fh; 115 struct arpcom *ac = IFP2AC(ifp); 116 117 if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING)) 118 senderr(ENETDOWN); 119 getmicrotime(&ifp->if_lastchange); 120 if ((rt = rt0) != NULL) { --- 36 unchanged lines hidden (view full) --- 157 } 158 type = htons(ETHERTYPE_IPV6); 159 break; 160#endif 161#ifdef IPX 162 case AF_IPX: 163 type = htons(ETHERTYPE_IPX); 164 bcopy((caddr_t)&(((struct sockaddr_ipx *)dst)->sipx_addr.x_host), | 113 struct rtentry *rt; 114 struct fddi_header *fh; 115 struct arpcom *ac = IFP2AC(ifp); 116 117 if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING)) 118 senderr(ENETDOWN); 119 getmicrotime(&ifp->if_lastchange); 120 if ((rt = rt0) != NULL) { --- 36 unchanged lines hidden (view full) --- 157 } 158 type = htons(ETHERTYPE_IPV6); 159 break; 160#endif 161#ifdef IPX 162 case AF_IPX: 163 type = htons(ETHERTYPE_IPX); 164 bcopy((caddr_t)&(((struct sockaddr_ipx *)dst)->sipx_addr.x_host), |
165 (caddr_t)edst, sizeof (edst)); | 165 (caddr_t)edst, FDDI_ADDR_LEN); |
166 break; 167#endif 168#ifdef NETATALK 169 case AF_APPLETALK: { 170 struct at_ifaddr *aa; 171 if (!aarpresolve(ac, m, (struct sockaddr_at *)dst, edst)) 172 return (0); 173 /* --- 5 unchanged lines hidden (view full) --- 179 /* 180 * In the phase 2 case, we need to prepend an mbuf for the llc header. 181 * Since we must preserve the value of m, which is passed to us by 182 * value, we m_copy() the first mbuf, and use it for our llc header. 183 */ 184 if (aa->aa_flags & AFA_PHASE2) { 185 struct llc llc; 186 | 166 break; 167#endif 168#ifdef NETATALK 169 case AF_APPLETALK: { 170 struct at_ifaddr *aa; 171 if (!aarpresolve(ac, m, (struct sockaddr_at *)dst, edst)) 172 return (0); 173 /* --- 5 unchanged lines hidden (view full) --- 179 /* 180 * In the phase 2 case, we need to prepend an mbuf for the llc header. 181 * Since we must preserve the value of m, which is passed to us by 182 * value, we m_copy() the first mbuf, and use it for our llc header. 183 */ 184 if (aa->aa_flags & AFA_PHASE2) { 185 struct llc llc; 186 |
187 M_PREPEND(m, sizeof(struct llc), M_TRYWAIT); | 187 M_PREPEND(m, LLC_SNAPFRAMELEN, M_TRYWAIT); |
188 if (m == 0) 189 senderr(ENOBUFS); 190 llc.llc_dsap = llc.llc_ssap = LLC_SNAP_LSAP; 191 llc.llc_control = LLC_UI; 192 bcopy(at_org_code, llc.llc_snap.org_code, sizeof(at_org_code)); 193 llc.llc_snap.ether_type = htons(ETHERTYPE_AT); | 188 if (m == 0) 189 senderr(ENOBUFS); 190 llc.llc_dsap = llc.llc_ssap = LLC_SNAP_LSAP; 191 llc.llc_control = LLC_UI; 192 bcopy(at_org_code, llc.llc_snap.org_code, sizeof(at_org_code)); 193 llc.llc_snap.ether_type = htons(ETHERTYPE_AT); |
194 bcopy(&llc, mtod(m, caddr_t), sizeof(struct llc)); | 194 bcopy(&llc, mtod(m, caddr_t), LLC_SNAPFRAMELEN); |
195 type = 0; 196 } else { 197 type = htons(ETHERTYPE_AT); 198 } 199 break; 200 } 201#endif /* NETATALK */ 202#ifdef NS 203 case AF_NS: 204 type = htons(ETHERTYPE_NS); 205 bcopy((caddr_t)&(((struct sockaddr_ns *)dst)->sns_addr.x_host), | 195 type = 0; 196 } else { 197 type = htons(ETHERTYPE_AT); 198 } 199 break; 200 } 201#endif /* NETATALK */ 202#ifdef NS 203 case AF_NS: 204 type = htons(ETHERTYPE_NS); 205 bcopy((caddr_t)&(((struct sockaddr_ns *)dst)->sns_addr.x_host), |
206 (caddr_t)edst, sizeof (edst)); | 206 (caddr_t)edst, FDDI_ADDR_LEN); |
207 break; 208#endif 209 210 case pseudo_AF_HDRCMPLT: 211 { 212 struct ether_header *eh; 213 hdrcmplt = 1; 214 eh = (struct ether_header *)dst->sa_data; | 207 break; 208#endif 209 210 case pseudo_AF_HDRCMPLT: 211 { 212 struct ether_header *eh; 213 hdrcmplt = 1; 214 eh = (struct ether_header *)dst->sa_data; |
215 (void)memcpy((caddr_t)esrc, (caddr_t)eh->ether_shost, sizeof (esrc)); | 215 (void)memcpy((caddr_t)esrc, (caddr_t)eh->ether_shost, FDDI_ADDR_LEN); |
216 /* FALLTHROUGH */ 217 } 218 219 case AF_UNSPEC: 220 { 221 struct ether_header *eh; 222 loop_copy = -1; 223 eh = (struct ether_header *)dst->sa_data; | 216 /* FALLTHROUGH */ 217 } 218 219 case AF_UNSPEC: 220 { 221 struct ether_header *eh; 222 loop_copy = -1; 223 eh = (struct ether_header *)dst->sa_data; |
224 (void)memcpy((caddr_t)edst, (caddr_t)eh->ether_dhost, sizeof (edst)); | 224 (void)memcpy((caddr_t)edst, (caddr_t)eh->ether_dhost, FDDI_ADDR_LEN); |
225 if (*edst & 1) 226 m->m_flags |= (M_BCAST|M_MCAST); 227 type = eh->ether_type; 228 break; 229 } 230 231 case AF_IMPLINK: 232 { --- 31 unchanged lines hidden (view full) --- 264 default: 265 printf("%s%d: can't handle af%d\n", ifp->if_name, ifp->if_unit, 266 dst->sa_family); 267 senderr(EAFNOSUPPORT); 268 } 269 270 if (type != 0) { 271 struct llc *l; | 225 if (*edst & 1) 226 m->m_flags |= (M_BCAST|M_MCAST); 227 type = eh->ether_type; 228 break; 229 } 230 231 case AF_IMPLINK: 232 { --- 31 unchanged lines hidden (view full) --- 264 default: 265 printf("%s%d: can't handle af%d\n", ifp->if_name, ifp->if_unit, 266 dst->sa_family); 267 senderr(EAFNOSUPPORT); 268 } 269 270 if (type != 0) { 271 struct llc *l; |
272 M_PREPEND(m, sizeof (struct llc), M_DONTWAIT); | 272 M_PREPEND(m, LLC_SNAPFRAMELEN, M_DONTWAIT); |
273 if (m == 0) 274 senderr(ENOBUFS); 275 l = mtod(m, struct llc *); 276 l->llc_control = LLC_UI; 277 l->llc_dsap = l->llc_ssap = LLC_SNAP_LSAP; 278 l->llc_snap.org_code[0] = l->llc_snap.org_code[1] = l->llc_snap.org_code[2] = 0; 279 (void)memcpy((caddr_t) &l->llc_snap.ether_type, (caddr_t) &type, 280 sizeof(u_int16_t)); 281 } 282 283 /* 284 * Add local net header. If no space in first mbuf, 285 * allocate another. 286 */ | 273 if (m == 0) 274 senderr(ENOBUFS); 275 l = mtod(m, struct llc *); 276 l->llc_control = LLC_UI; 277 l->llc_dsap = l->llc_ssap = LLC_SNAP_LSAP; 278 l->llc_snap.org_code[0] = l->llc_snap.org_code[1] = l->llc_snap.org_code[2] = 0; 279 (void)memcpy((caddr_t) &l->llc_snap.ether_type, (caddr_t) &type, 280 sizeof(u_int16_t)); 281 } 282 283 /* 284 * Add local net header. If no space in first mbuf, 285 * allocate another. 286 */ |
287 M_PREPEND(m, sizeof (struct fddi_header), M_DONTWAIT); | 287 M_PREPEND(m, FDDI_HDR_LEN, M_DONTWAIT); |
288 if (m == 0) 289 senderr(ENOBUFS); 290 fh = mtod(m, struct fddi_header *); 291 fh->fddi_fc = FDDIFC_LLC_ASYNC|FDDIFC_LLC_PRIO4; | 288 if (m == 0) 289 senderr(ENOBUFS); 290 fh = mtod(m, struct fddi_header *); 291 fh->fddi_fc = FDDIFC_LLC_ASYNC|FDDIFC_LLC_PRIO4; |
292 (void)memcpy((caddr_t)fh->fddi_dhost, (caddr_t)edst, sizeof (edst)); | 292 (void)memcpy((caddr_t)fh->fddi_dhost, (caddr_t)edst, FDDI_ADDR_LEN); |
293 queue_it: 294 if (hdrcmplt) 295 (void)memcpy((caddr_t)fh->fddi_shost, (caddr_t)esrc, | 293 queue_it: 294 if (hdrcmplt) 295 (void)memcpy((caddr_t)fh->fddi_shost, (caddr_t)esrc, |
296 sizeof(fh->fddi_shost)); | 296 FDDI_ADDR_LEN); |
297 else 298 (void)memcpy((caddr_t)fh->fddi_shost, (caddr_t)ac->ac_enaddr, | 297 else 298 (void)memcpy((caddr_t)fh->fddi_shost, (caddr_t)ac->ac_enaddr, |
299 sizeof(fh->fddi_shost)); | 299 FDDI_ADDR_LEN); |
300 /* 301 * If a simplex interface, and the packet is being sent to our 302 * Ethernet address or a broadcast address, loopback a copy. 303 * XXX To make a simplex device behave exactly like a duplex 304 * device, we should copy in the case of sending to our own 305 * ethernet address (thus letting the original actually appear 306 * on the wire). However, we don't do that here for security 307 * reasons and compatibility with the original behavior. 308 */ 309 if ((ifp->if_flags & IFF_SIMPLEX) && 310 (loop_copy != -1)) { 311 if ((m->m_flags & M_BCAST) || loop_copy) { 312 struct mbuf *n = m_copy(m, 0, (int)M_COPYALL); 313 314 (void) if_simloop(ifp, | 300 /* 301 * If a simplex interface, and the packet is being sent to our 302 * Ethernet address or a broadcast address, loopback a copy. 303 * XXX To make a simplex device behave exactly like a duplex 304 * device, we should copy in the case of sending to our own 305 * ethernet address (thus letting the original actually appear 306 * on the wire). However, we don't do that here for security 307 * reasons and compatibility with the original behavior. 308 */ 309 if ((ifp->if_flags & IFF_SIMPLEX) && 310 (loop_copy != -1)) { 311 if ((m->m_flags & M_BCAST) || loop_copy) { 312 struct mbuf *n = m_copy(m, 0, (int)M_COPYALL); 313 314 (void) if_simloop(ifp, |
315 n, dst->sa_family, sizeof(struct fddi_header)); | 315 n, dst->sa_family, FDDI_HDR_LEN); |
316 } else if (bcmp(fh->fddi_dhost, | 316 } else if (bcmp(fh->fddi_dhost, |
317 fh->fddi_shost, sizeof(fh->fddi_shost)) == 0) { | 317 fh->fddi_shost, FDDI_ADDR_LEN) == 0) { |
318 (void) if_simloop(ifp, | 318 (void) if_simloop(ifp, |
319 m, dst->sa_family, sizeof(struct fddi_header)); | 319 m, dst->sa_family, FDDI_HDR_LEN); |
320 return (0); /* XXX */ 321 } 322 } 323 324 if (! IF_HANDOFF(&ifp->if_snd, m, ifp)) 325 senderr(ENOBUFS); 326 return (error); 327 --- 20 unchanged lines hidden (view full) --- 348 if ((ifp->if_flags & IFF_UP) == 0) { 349 m_freem(m); 350 return; 351 } 352 getmicrotime(&ifp->if_lastchange); 353 ifp->if_ibytes += m->m_pkthdr.len + sizeof (*fh); 354 if (fh->fddi_dhost[0] & 1) { 355 if (bcmp((caddr_t)fddibroadcastaddr, (caddr_t)fh->fddi_dhost, | 320 return (0); /* XXX */ 321 } 322 } 323 324 if (! IF_HANDOFF(&ifp->if_snd, m, ifp)) 325 senderr(ENOBUFS); 326 return (error); 327 --- 20 unchanged lines hidden (view full) --- 348 if ((ifp->if_flags & IFF_UP) == 0) { 349 m_freem(m); 350 return; 351 } 352 getmicrotime(&ifp->if_lastchange); 353 ifp->if_ibytes += m->m_pkthdr.len + sizeof (*fh); 354 if (fh->fddi_dhost[0] & 1) { 355 if (bcmp((caddr_t)fddibroadcastaddr, (caddr_t)fh->fddi_dhost, |
356 sizeof(fddibroadcastaddr)) == 0) | 356 FDDI_ADDR_LEN) == 0) |
357 m->m_flags |= M_BCAST; 358 else 359 m->m_flags |= M_MCAST; 360 ifp->if_imcasts++; 361 } else if ((ifp->if_flags & IFF_PROMISC) 362 && bcmp(IFP2AC(ifp)->ac_enaddr, (caddr_t)fh->fddi_dhost, | 357 m->m_flags |= M_BCAST; 358 else 359 m->m_flags |= M_MCAST; 360 ifp->if_imcasts++; 361 } else if ((ifp->if_flags & IFF_PROMISC) 362 && bcmp(IFP2AC(ifp)->ac_enaddr, (caddr_t)fh->fddi_dhost, |
363 sizeof(fh->fddi_dhost)) != 0) { | 363 FDDI_ADDR_LEN) != 0) { |
364 m_freem(m); 365 return; 366 } 367 368#ifdef M_LINK0 369 /* 370 * If this has a LLC priority of 0, then mark it so upper 371 * layers have a hint that it really came via a FDDI/Ethernet --- 11 unchanged lines hidden (view full) --- 383 u_int16_t type; 384 if (l->llc_control != LLC_UI || l->llc_ssap != LLC_SNAP_LSAP) 385 goto dropanyway; 386#ifdef NETATALK 387 if (Bcmp(&(l->llc_snap.org_code)[0], at_org_code, 388 sizeof(at_org_code)) == 0 && 389 ntohs(l->llc_snap.ether_type) == ETHERTYPE_AT) { 390 inq = &atintrq2; | 364 m_freem(m); 365 return; 366 } 367 368#ifdef M_LINK0 369 /* 370 * If this has a LLC priority of 0, then mark it so upper 371 * layers have a hint that it really came via a FDDI/Ethernet --- 11 unchanged lines hidden (view full) --- 383 u_int16_t type; 384 if (l->llc_control != LLC_UI || l->llc_ssap != LLC_SNAP_LSAP) 385 goto dropanyway; 386#ifdef NETATALK 387 if (Bcmp(&(l->llc_snap.org_code)[0], at_org_code, 388 sizeof(at_org_code)) == 0 && 389 ntohs(l->llc_snap.ether_type) == ETHERTYPE_AT) { 390 inq = &atintrq2; |
391 m_adj( m, sizeof( struct llc )); | 391 m_adj(m, LLC_SNAPFRAMELEN); |
392 schednetisr(NETISR_ATALK); 393 break; 394 } 395 396 if (Bcmp(&(l->llc_snap.org_code)[0], aarp_org_code, 397 sizeof(aarp_org_code)) == 0 && 398 ntohs(l->llc_snap.ether_type) == ETHERTYPE_AARP) { | 392 schednetisr(NETISR_ATALK); 393 break; 394 } 395 396 if (Bcmp(&(l->llc_snap.org_code)[0], aarp_org_code, 397 sizeof(aarp_org_code)) == 0 && 398 ntohs(l->llc_snap.ether_type) == ETHERTYPE_AARP) { |
399 m_adj( m, sizeof( struct llc )); | 399 m_adj(m, LLC_SNAPFRAMELEN); |
400 aarpinput(IFP2AC(ifp), m); /* XXX */ 401 return; 402 } 403#endif /* NETATALK */ 404 if (l->llc_snap.org_code[0] != 0 || l->llc_snap.org_code[1] != 0|| l->llc_snap.org_code[2] != 0) 405 goto dropanyway; 406 type = ntohs(l->llc_snap.ether_type); 407 m_adj(m, 8); --- 73 unchanged lines hidden (view full) --- 481void 482fddi_ifattach(ifp) 483 struct ifnet *ifp; 484{ 485 struct ifaddr *ifa; 486 struct sockaddr_dl *sdl; 487 488 ifp->if_type = IFT_FDDI; | 400 aarpinput(IFP2AC(ifp), m); /* XXX */ 401 return; 402 } 403#endif /* NETATALK */ 404 if (l->llc_snap.org_code[0] != 0 || l->llc_snap.org_code[1] != 0|| l->llc_snap.org_code[2] != 0) 405 goto dropanyway; 406 type = ntohs(l->llc_snap.ether_type); 407 m_adj(m, 8); --- 73 unchanged lines hidden (view full) --- 481void 482fddi_ifattach(ifp) 483 struct ifnet *ifp; 484{ 485 struct ifaddr *ifa; 486 struct sockaddr_dl *sdl; 487 488 ifp->if_type = IFT_FDDI; |
489 ifp->if_addrlen = 6; | 489 ifp->if_addrlen = FDDI_ADDR_LEN; |
490 ifp->if_hdrlen = 21; 491 ifp->if_mtu = FDDIMTU; 492 ifp->if_resolvemulti = fddi_resolvemulti; 493 ifp->if_baudrate = 100000000; 494#ifdef IFF_NOTRAILERS 495 ifp->if_flags |= IFF_NOTRAILERS; 496#endif 497 ifp->if_broadcastaddr = fddibroadcastaddr; --- 89 unchanged lines hidden --- | 490 ifp->if_hdrlen = 21; 491 ifp->if_mtu = FDDIMTU; 492 ifp->if_resolvemulti = fddi_resolvemulti; 493 ifp->if_baudrate = 100000000; 494#ifdef IFF_NOTRAILERS 495 ifp->if_flags |= IFF_NOTRAILERS; 496#endif 497 ifp->if_broadcastaddr = fddibroadcastaddr; --- 89 unchanged lines hidden --- |