35 */ 36 37#include <sys/param.h> 38#include <sys/systm.h> 39#include <sys/kernel.h> 40#include <sys/malloc.h> 41#include <sys/mbuf.h> 42#include <sys/protosw.h> 43#include <sys/socket.h> 44#include <sys/ioctl.h> 45#include <sys/errno.h> 46#include <sys/syslog.h> 47#include <sys/sysctl.h> 48 49#include <net/if.h> 50#include <net/netisr.h> 51#include <net/route.h> 52#include <net/if_llc.h> 53#include <net/if_dl.h> 54#include <net/if_types.h> 55 56#ifdef INET 57#include <netinet/in.h> 58#include <netinet/in_var.h> 59#endif 60#include <netinet/if_ether.h> 61 62#ifdef IPX 63#include <netipx/ipx.h> 64#include <netipx/ipx_if.h> 65#endif 66 67#ifdef NS 68#include <netns/ns.h> 69#include <netns/ns_if.h> 70#endif 71 72#ifdef ISO 73#include <netiso/argo_debug.h> 74#include <netiso/iso.h> 75#include <netiso/iso_var.h> 76#include <netiso/iso_snpac.h> 77#endif 78 79/*#ifdef LLC 80#include <netccitt/dll.h> 81#include <netccitt/llc_var.h> 82#endif*/ 83 84#if defined(LLC) && defined(CCITT) 85extern struct ifqueue pkintrq; 86#endif 87 88#ifdef NETATALK 89#include <netatalk/at.h> 90#include <netatalk/at_var.h> 91#include <netatalk/at_extern.h> 92 93#define llc_snap_org_code llc_un.type_snap.org_code 94#define llc_snap_ether_type llc_un.type_snap.ether_type 95 96extern u_char at_org_code[ 3 ]; 97extern u_char aarp_org_code[ 3 ]; 98#endif NETATALK 99 100u_char etherbroadcastaddr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; 101#define senderr(e) { error = (e); goto bad;} 102 103/* 104 * Ethernet output routine. 105 * Encapsulate a packet of type family for the local net. 106 * Use trailer local net encapsulation if enough data in first 107 * packet leaves a multiple of 512 bytes of data in remainder. 108 * Assumes that ifp is actually pointer to arpcom structure. 109 */ 110int 111ether_output(ifp, m0, dst, rt0) 112 register struct ifnet *ifp; 113 struct mbuf *m0; 114 struct sockaddr *dst; 115 struct rtentry *rt0; 116{ 117 short type; 118 int s, error = 0; 119 u_char edst[6]; 120 register struct mbuf *m = m0; 121 register struct rtentry *rt; 122 struct mbuf *mcopy = (struct mbuf *)0; 123 register struct ether_header *eh; 124 int off, len = m->m_pkthdr.len; 125 struct arpcom *ac = (struct arpcom *)ifp; 126#ifdef NETATALK 127 struct at_ifaddr *aa; 128#endif NETATALK 129 130 if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING)) 131 senderr(ENETDOWN); 132 ifp->if_lastchange = time; 133 rt = rt0; 134 if (rt) { 135 if ((rt->rt_flags & RTF_UP) == 0) { 136 rt0 = rt = rtalloc1(dst, 1, 0UL); 137 if (rt0) 138 rt->rt_refcnt--; 139 else 140 senderr(EHOSTUNREACH); 141 } 142 if (rt->rt_flags & RTF_GATEWAY) { 143 if (rt->rt_gwroute == 0) 144 goto lookup; 145 if (((rt = rt->rt_gwroute)->rt_flags & RTF_UP) == 0) { 146 rtfree(rt); rt = rt0; 147 lookup: rt->rt_gwroute = rtalloc1(rt->rt_gateway, 1, 148 0UL); 149 if ((rt = rt->rt_gwroute) == 0) 150 senderr(EHOSTUNREACH); 151 } 152 } 153 if (rt->rt_flags & RTF_REJECT) 154 if (rt->rt_rmx.rmx_expire == 0 || 155 time.tv_sec < rt->rt_rmx.rmx_expire) 156 senderr(rt == rt0 ? EHOSTDOWN : EHOSTUNREACH); 157 } 158 switch (dst->sa_family) { 159 160#ifdef INET 161 case AF_INET: 162 if (!arpresolve(ac, rt, m, dst, edst, rt0)) 163 return (0); /* if not yet resolved */ 164 /* If broadcasting on a simplex interface, loopback a copy */ 165 if ((m->m_flags & M_BCAST) && (ifp->if_flags & IFF_SIMPLEX)) 166 mcopy = m_copy(m, 0, (int)M_COPYALL); 167 off = m->m_pkthdr.len - m->m_len; 168 type = ETHERTYPE_IP; 169 break; 170#endif 171#ifdef IPX 172 case AF_IPX: 173 type = ETHERTYPE_IPX; 174 bcopy((caddr_t)&(((struct sockaddr_ipx *)dst)->sipx_addr.x_host), 175 (caddr_t)edst, sizeof (edst)); 176 if (!bcmp((caddr_t)edst, (caddr_t)&ipx_thishost, sizeof(edst))) 177 return (looutput(ifp, m, dst, rt)); 178 /* If broadcasting on a simplex interface, loopback a copy */ 179 if ((m->m_flags & M_BCAST) && (ifp->if_flags & IFF_SIMPLEX)) 180 mcopy = m_copy(m, 0, (int)M_COPYALL); 181 break; 182#endif 183#ifdef NETATALK 184 case AF_APPLETALK: 185 if (!aarpresolve(ac, m, (struct sockaddr_at *)dst, edst)) { 186#ifdef NETATALKDEBUG 187 extern char *prsockaddr(struct sockaddr *); 188 printf("aarpresolv: failed for %s\n", prsockaddr(dst)); 189#endif NETATALKDEBUG 190 return (0); 191 } 192 /* 193 * ifaddr is the first thing in at_ifaddr 194 */ 195 if ((aa = (struct at_ifaddr *)at_ifawithnet( 196 (struct sockaddr_at *)dst, ifp->if_addrlist)) 197 == 0) 198 goto bad; 199 200 /* 201 * In the phase 2 case, we need to prepend an mbuf for the llc header. 202 * Since we must preserve the value of m, which is passed to us by 203 * value, we m_copy() the first mbuf, and use it for our llc header. 204 */ 205 if ( aa->aa_flags & AFA_PHASE2 ) { 206 struct llc llc; 207 208 M_PREPEND(m, sizeof(struct llc), M_WAIT); 209 len += sizeof(struct llc); 210 llc.llc_dsap = llc.llc_ssap = LLC_SNAP_LSAP; 211 llc.llc_control = LLC_UI; 212 bcopy(at_org_code, llc.llc_snap_org_code, sizeof(at_org_code)); 213 llc.llc_snap_ether_type = htons( ETHERTYPE_AT ); 214 bcopy(&llc, mtod(m, caddr_t), sizeof(struct llc)); 215 type = m->m_pkthdr.len; 216 } else { 217 type = ETHERTYPE_AT; 218 } 219 break; 220#endif NETATALK 221#ifdef NS 222 case AF_NS: 223 type = ETHERTYPE_NS; 224 bcopy((caddr_t)&(((struct sockaddr_ns *)dst)->sns_addr.x_host), 225 (caddr_t)edst, sizeof (edst)); 226 if (!bcmp((caddr_t)edst, (caddr_t)&ns_thishost, sizeof(edst))) 227 return (looutput(ifp, m, dst, rt)); 228 /* If broadcasting on a simplex interface, loopback a copy */ 229 if ((m->m_flags & M_BCAST) && (ifp->if_flags & IFF_SIMPLEX)) 230 mcopy = m_copy(m, 0, (int)M_COPYALL); 231 break; 232#endif 233#ifdef ISO 234 case AF_ISO: { 235 int snpalen; 236 struct llc *l; 237 register struct sockaddr_dl *sdl; 238 239 if (rt && (sdl = (struct sockaddr_dl *)rt->rt_gateway) && 240 sdl->sdl_family == AF_LINK && sdl->sdl_alen > 0) { 241 bcopy(LLADDR(sdl), (caddr_t)edst, sizeof(edst)); 242 } else if (error = 243 iso_snparesolve(ifp, (struct sockaddr_iso *)dst, 244 (char *)edst, &snpalen)) 245 goto bad; /* Not Resolved */ 246 /* If broadcasting on a simplex interface, loopback a copy */ 247 if (*edst & 1) 248 m->m_flags |= (M_BCAST|M_MCAST); 249 if ((m->m_flags & M_BCAST) && (ifp->if_flags & IFF_SIMPLEX) && 250 (mcopy = m_copy(m, 0, (int)M_COPYALL))) { 251 M_PREPEND(mcopy, sizeof (*eh), M_DONTWAIT); 252 if (mcopy) { 253 eh = mtod(mcopy, struct ether_header *); 254 bcopy((caddr_t)edst, 255 (caddr_t)eh->ether_dhost, sizeof (edst)); 256 bcopy((caddr_t)ac->ac_enaddr, 257 (caddr_t)eh->ether_shost, sizeof (edst)); 258 } 259 } 260 M_PREPEND(m, 3, M_DONTWAIT); 261 if (m == NULL) 262 return (0); 263 type = m->m_pkthdr.len; 264 l = mtod(m, struct llc *); 265 l->llc_dsap = l->llc_ssap = LLC_ISO_LSAP; 266 l->llc_control = LLC_UI; 267 len += 3; 268 IFDEBUG(D_ETHER) 269 int i; 270 printf("unoutput: sending pkt to: "); 271 for (i=0; i<6; i++) 272 printf("%x ", edst[i] & 0xff); 273 printf("\n"); 274 ENDDEBUG 275 } break; 276#endif /* ISO */ 277#ifdef LLC 278/* case AF_NSAP: */ 279 case AF_CCITT: { 280 register struct sockaddr_dl *sdl = 281 (struct sockaddr_dl *) rt -> rt_gateway; 282 283 if (sdl && sdl->sdl_family == AF_LINK 284 && sdl->sdl_alen > 0) { 285 bcopy(LLADDR(sdl), (char *)edst, 286 sizeof(edst)); 287 } else goto bad; /* Not a link interface ? Funny ... */ 288 if ((ifp->if_flags & IFF_SIMPLEX) && (*edst & 1) && 289 (mcopy = m_copy(m, 0, (int)M_COPYALL))) { 290 M_PREPEND(mcopy, sizeof (*eh), M_DONTWAIT); 291 if (mcopy) { 292 eh = mtod(mcopy, struct ether_header *); 293 bcopy((caddr_t)edst, 294 (caddr_t)eh->ether_dhost, sizeof (edst)); 295 bcopy((caddr_t)ac->ac_enaddr, 296 (caddr_t)eh->ether_shost, sizeof (edst)); 297 } 298 } 299 type = m->m_pkthdr.len; 300#ifdef LLC_DEBUG 301 { 302 int i; 303 register struct llc *l = mtod(m, struct llc *); 304 305 printf("ether_output: sending LLC2 pkt to: "); 306 for (i=0; i<6; i++) 307 printf("%x ", edst[i] & 0xff); 308 printf(" len 0x%x dsap 0x%x ssap 0x%x control 0x%x\n", 309 type & 0xff, l->llc_dsap & 0xff, l->llc_ssap &0xff, 310 l->llc_control & 0xff); 311 312 } 313#endif /* LLC_DEBUG */ 314 } break; 315#endif /* LLC */ 316 317 case AF_UNSPEC: 318 eh = (struct ether_header *)dst->sa_data; 319 (void)memcpy(edst, eh->ether_dhost, sizeof (edst)); 320 type = eh->ether_type; 321 break; 322 323 default: 324 printf("%s%d: can't handle af%d\n", ifp->if_name, ifp->if_unit, 325 dst->sa_family); 326 senderr(EAFNOSUPPORT); 327 } 328 329 330 if (mcopy) 331 (void) looutput(ifp, mcopy, dst, rt); 332 /* 333 * Add local net header. If no space in first mbuf, 334 * allocate another. 335 */ 336 M_PREPEND(m, sizeof (struct ether_header), M_DONTWAIT); 337 if (m == 0) 338 senderr(ENOBUFS); 339 eh = mtod(m, struct ether_header *); 340 type = htons((u_short)type); 341 (void)memcpy(&eh->ether_type, &type, 342 sizeof(eh->ether_type)); 343 (void)memcpy(eh->ether_dhost, edst, sizeof (edst)); 344 (void)memcpy(eh->ether_shost, ac->ac_enaddr, 345 sizeof(eh->ether_shost)); 346 s = splimp(); 347 /* 348 * Queue message on interface, and start output if interface 349 * not yet active. 350 */ 351 if (IF_QFULL(&ifp->if_snd)) { 352 IF_DROP(&ifp->if_snd); 353 splx(s); 354 senderr(ENOBUFS); 355 } 356 IF_ENQUEUE(&ifp->if_snd, m); 357 if ((ifp->if_flags & IFF_OACTIVE) == 0) 358 (*ifp->if_start)(ifp); 359 splx(s); 360 ifp->if_obytes += len + sizeof (struct ether_header); 361 if (m->m_flags & M_MCAST) 362 ifp->if_omcasts++; 363 return (error); 364 365bad: 366 if (m) 367 m_freem(m); 368 return (error); 369} 370 371/* 372 * Process a received Ethernet packet; 373 * the packet is in the mbuf chain m without 374 * the ether header, which is provided separately. 375 */ 376void 377ether_input(ifp, eh, m) 378 struct ifnet *ifp; 379 register struct ether_header *eh; 380 struct mbuf *m; 381{ 382 register struct ifqueue *inq; 383 register struct llc *l; 384 u_short ether_type; 385 int s; 386 387 if ((ifp->if_flags & IFF_UP) == 0) { 388 m_freem(m); 389 return; 390 } 391 ifp->if_lastchange = time; 392 ifp->if_ibytes += m->m_pkthdr.len + sizeof (*eh); 393 if (bcmp((caddr_t)etherbroadcastaddr, (caddr_t)eh->ether_dhost, 394 sizeof(etherbroadcastaddr)) == 0) 395 m->m_flags |= M_BCAST; 396 else if (eh->ether_dhost[0] & 1) 397 m->m_flags |= M_MCAST; 398 if (m->m_flags & (M_BCAST|M_MCAST)) 399 ifp->if_imcasts++; 400 401 ether_type = ntohs(eh->ether_type); 402 403 switch (ether_type) { 404#ifdef INET 405 case ETHERTYPE_IP: 406 schednetisr(NETISR_IP); 407 inq = &ipintrq; 408 break; 409 410 case ETHERTYPE_ARP: 411 schednetisr(NETISR_ARP); 412 inq = &arpintrq; 413 break; 414#endif 415#ifdef IPX 416 case ETHERTYPE_IPX: 417 schednetisr(NETISR_IPX); 418 inq = &ipxintrq; 419 break; 420#endif 421#ifdef NS 422 case ETHERTYPE_NS: 423 schednetisr(NETISR_NS); 424 inq = &nsintrq; 425 break; 426#endif 427#ifdef NETATALK 428 case ETHERTYPE_AT: 429 schednetisr(NETISR_ATALK); 430 inq = &atintrq1; 431 break; 432 case ETHERTYPE_AARP: 433 /* probably this should be done with a NETISR as well */ 434 aarpinput((struct arpcom *)ifp, m); /* XXX */ 435 return; 436#endif NETATALK 437 default: 438#if defined (ISO) || defined (LLC) || defined(NETATALK) 439 if (ether_type > ETHERMTU) 440 goto dropanyway; 441 l = mtod(m, struct llc *); 442 switch (l->llc_dsap) { 443#ifdef NETATALK 444 case LLC_SNAP_LSAP: 445 switch (l->llc_control) { 446 case LLC_UI: 447 if (l->llc_ssap != LLC_SNAP_LSAP) 448 goto dropanyway; 449 450 if (Bcmp(&(l->llc_snap_org_code)[0], at_org_code, 451 sizeof(at_org_code)) == 0 && 452 ntohs(l->llc_snap_ether_type) == ETHERTYPE_AT) { 453 inq = &atintrq2; 454 m_adj( m, sizeof( struct llc )); 455 schednetisr(NETISR_ATALK); 456 break; 457 } 458 459 if (Bcmp(&(l->llc_snap_org_code)[0], aarp_org_code, 460 sizeof(aarp_org_code)) == 0 && 461 ntohs(l->llc_snap_ether_type) == ETHERTYPE_AARP) { 462 m_adj( m, sizeof( struct llc )); 463 aarpinput((struct arpcom *)ifp, m); /* XXX */ 464 return; 465 } 466 467 default: 468 goto dropanyway; 469 } 470 break; 471#endif NETATALK 472#ifdef ISO 473 case LLC_ISO_LSAP: 474 switch (l->llc_control) { 475 case LLC_UI: 476 /* LLC_UI_P forbidden in class 1 service */ 477 if ((l->llc_dsap == LLC_ISO_LSAP) && 478 (l->llc_ssap == LLC_ISO_LSAP)) { 479 /* LSAP for ISO */ 480 if (m->m_pkthdr.len > ether_type) 481 m_adj(m, ether_type - m->m_pkthdr.len); 482 m->m_data += 3; /* XXX */ 483 m->m_len -= 3; /* XXX */ 484 m->m_pkthdr.len -= 3; /* XXX */ 485 M_PREPEND(m, sizeof *eh, M_DONTWAIT); 486 if (m == 0) 487 return; 488 *mtod(m, struct ether_header *) = *eh; 489 IFDEBUG(D_ETHER) 490 printf("clnp packet"); 491 ENDDEBUG 492 schednetisr(NETISR_ISO); 493 inq = &clnlintrq; 494 break; 495 } 496 goto dropanyway; 497 498 case LLC_XID: 499 case LLC_XID_P: 500 if(m->m_len < 6) 501 goto dropanyway; 502 l->llc_window = 0; 503 l->llc_fid = 9; 504 l->llc_class = 1; 505 l->llc_dsap = l->llc_ssap = 0; 506 /* Fall through to */ 507 case LLC_TEST: 508 case LLC_TEST_P: 509 { 510 struct sockaddr sa; 511 register struct ether_header *eh2; 512 int i; 513 u_char c = l->llc_dsap; 514 515 l->llc_dsap = l->llc_ssap; 516 l->llc_ssap = c; 517 if (m->m_flags & (M_BCAST | M_MCAST)) 518 bcopy((caddr_t)ac->ac_enaddr, 519 (caddr_t)eh->ether_dhost, 6); 520 sa.sa_family = AF_UNSPEC; 521 sa.sa_len = sizeof(sa); 522 eh2 = (struct ether_header *)sa.sa_data; 523 for (i = 0; i < 6; i++) { 524 eh2->ether_shost[i] = c = eh->ether_dhost[i]; 525 eh2->ether_dhost[i] = 526 eh->ether_dhost[i] = eh->ether_shost[i]; 527 eh->ether_shost[i] = c; 528 } 529 ifp->if_output(ifp, m, &sa, NULL); 530 return; 531 } 532 default: 533 m_freem(m); 534 return; 535 } 536 break; 537#endif /* ISO */ 538#ifdef LLC 539 case LLC_X25_LSAP: 540 { 541 if (m->m_pkthdr.len > ether_type) 542 m_adj(m, ether_type - m->m_pkthdr.len); 543 M_PREPEND(m, sizeof(struct sdl_hdr) , M_DONTWAIT); 544 if (m == 0) 545 return; 546 if ( !sdl_sethdrif(ifp, eh->ether_shost, LLC_X25_LSAP, 547 eh->ether_dhost, LLC_X25_LSAP, 6, 548 mtod(m, struct sdl_hdr *))) 549 panic("ETHER cons addr failure"); 550 mtod(m, struct sdl_hdr *)->sdlhdr_len = ether_type; 551#ifdef LLC_DEBUG 552 printf("llc packet\n"); 553#endif /* LLC_DEBUG */ 554 schednetisr(NETISR_CCITT); 555 inq = &llcintrq; 556 break; 557 } 558#endif /* LLC */ 559 dropanyway: 560 default: 561 m_freem(m); 562 return; 563 } 564#else /* ISO || LLC || NETATALK */ 565 m_freem(m); 566 return; 567#endif /* ISO || LLC || NETATALK */ 568 } 569 570 s = splimp(); 571 if (IF_QFULL(inq)) { 572 IF_DROP(inq); 573 m_freem(m); 574 } else 575 IF_ENQUEUE(inq, m); 576 splx(s); 577} 578 579/* 580 * Perform common duties while attaching to interface list 581 */ 582void 583ether_ifattach(ifp) 584 register struct ifnet *ifp; 585{ 586 register struct ifaddr *ifa; 587 register struct sockaddr_dl *sdl; 588 589 ifp->if_type = IFT_ETHER; 590 ifp->if_addrlen = 6; 591 ifp->if_hdrlen = 14; 592 ifp->if_mtu = ETHERMTU;
|
595 for (ifa = ifp->if_addrlist; ifa; ifa = ifa->ifa_next) 596 if ((sdl = (struct sockaddr_dl *)ifa->ifa_addr) && 597 sdl->sdl_family == AF_LINK) { 598 sdl->sdl_type = IFT_ETHER; 599 sdl->sdl_alen = ifp->if_addrlen; 600 bcopy((caddr_t)((struct arpcom *)ifp)->ac_enaddr, 601 LLADDR(sdl), ifp->if_addrlen); 602 break; 603 } 604} 605 606static u_char ether_ipmulticast_min[6] = 607 { 0x01, 0x00, 0x5e, 0x00, 0x00, 0x00 }; 608static u_char ether_ipmulticast_max[6] = 609 { 0x01, 0x00, 0x5e, 0x7f, 0xff, 0xff }; 610/* 611 * Add an Ethernet multicast address or range of addresses to the list for a 612 * given interface. 613 */ 614int 615ether_addmulti(ifr, ac) 616 struct ifreq *ifr; 617 register struct arpcom *ac; 618{ 619 register struct ether_multi *enm; 620 struct sockaddr_in *sin; 621 u_char addrlo[6]; 622 u_char addrhi[6]; 623 int set_allmulti = 0; 624 int s = splimp(); 625 626 switch (ifr->ifr_addr.sa_family) { 627 628 case AF_UNSPEC: 629 bcopy(ifr->ifr_addr.sa_data, addrlo, 6); 630 bcopy(addrlo, addrhi, 6); 631 break; 632 633#ifdef INET 634 case AF_INET: 635 sin = (struct sockaddr_in *)&(ifr->ifr_addr); 636 if (sin->sin_addr.s_addr == INADDR_ANY) { 637 /* 638 * An IP address of INADDR_ANY means listen to all 639 * of the Ethernet multicast addresses used for IP. 640 * (This is for the sake of IP multicast routers.) 641 */ 642 bcopy(ether_ipmulticast_min, addrlo, 6); 643 bcopy(ether_ipmulticast_max, addrhi, 6); 644 set_allmulti = 1; 645 } 646 else { 647 ETHER_MAP_IP_MULTICAST(&sin->sin_addr, addrlo); 648 bcopy(addrlo, addrhi, 6); 649 } 650 break; 651#endif 652 653 default: 654 splx(s); 655 return (EAFNOSUPPORT); 656 } 657 658 /* 659 * Verify that we have valid Ethernet multicast addresses. 660 */ 661 if ((addrlo[0] & 0x01) != 1 || (addrhi[0] & 0x01) != 1) { 662 splx(s); 663 return (EINVAL); 664 } 665 /* 666 * See if the address range is already in the list. 667 */ 668 ETHER_LOOKUP_MULTI(addrlo, addrhi, ac, enm); 669 if (enm != NULL) { 670 /* 671 * Found it; just increment the reference count. 672 */ 673 ++enm->enm_refcount; 674 splx(s); 675 return (0); 676 } 677 /* 678 * New address or range; malloc a new multicast record 679 * and link it into the interface's multicast list. 680 */ 681 enm = (struct ether_multi *)malloc(sizeof(*enm), M_IFMADDR, M_NOWAIT); 682 if (enm == NULL) { 683 splx(s); 684 return (ENOBUFS); 685 } 686 bcopy(addrlo, enm->enm_addrlo, 6); 687 bcopy(addrhi, enm->enm_addrhi, 6); 688 enm->enm_ac = ac; 689 enm->enm_refcount = 1; 690 enm->enm_next = ac->ac_multiaddrs; 691 ac->ac_multiaddrs = enm; 692 ac->ac_multicnt++; 693 splx(s); 694 if (set_allmulti) 695 ac->ac_if.if_flags |= IFF_ALLMULTI; 696 697 /* 698 * Return ENETRESET to inform the driver that the list has changed 699 * and its reception filter should be adjusted accordingly. 700 */ 701 return (ENETRESET); 702} 703 704/* 705 * Delete a multicast address record. 706 */ 707int 708ether_delmulti(ifr, ac) 709 struct ifreq *ifr; 710 register struct arpcom *ac; 711{ 712 register struct ether_multi *enm; 713 register struct ether_multi **p; 714 struct sockaddr_in *sin; 715 u_char addrlo[6]; 716 u_char addrhi[6]; 717 int unset_allmulti = 0; 718 int s = splimp(); 719 720 switch (ifr->ifr_addr.sa_family) { 721 722 case AF_UNSPEC: 723 bcopy(ifr->ifr_addr.sa_data, addrlo, 6); 724 bcopy(addrlo, addrhi, 6); 725 break; 726 727#ifdef INET 728 case AF_INET: 729 sin = (struct sockaddr_in *)&(ifr->ifr_addr); 730 if (sin->sin_addr.s_addr == INADDR_ANY) { 731 /* 732 * An IP address of INADDR_ANY means stop listening 733 * to the range of Ethernet multicast addresses used 734 * for IP. 735 */ 736 bcopy(ether_ipmulticast_min, addrlo, 6); 737 bcopy(ether_ipmulticast_max, addrhi, 6); 738 unset_allmulti = 1; 739 } 740 else { 741 ETHER_MAP_IP_MULTICAST(&sin->sin_addr, addrlo); 742 bcopy(addrlo, addrhi, 6); 743 } 744 break; 745#endif 746 747 default: 748 splx(s); 749 return (EAFNOSUPPORT); 750 } 751 752 /* 753 * Look up the address in our list. 754 */ 755 ETHER_LOOKUP_MULTI(addrlo, addrhi, ac, enm); 756 if (enm == NULL) { 757 splx(s); 758 return (ENXIO); 759 } 760 if (--enm->enm_refcount != 0) { 761 /* 762 * Still some claims to this record. 763 */ 764 splx(s); 765 return (0); 766 } 767 /* 768 * No remaining claims to this record; unlink and free it. 769 */ 770 for (p = &enm->enm_ac->ac_multiaddrs; 771 *p != enm; 772 p = &(*p)->enm_next) 773 continue; 774 *p = (*p)->enm_next; 775 free(enm, M_IFMADDR); 776 ac->ac_multicnt--; 777 splx(s); 778 if (unset_allmulti) 779 ac->ac_if.if_flags &= ~IFF_ALLMULTI; 780 781 /* 782 * Return ENETRESET to inform the driver that the list has changed 783 * and its reception filter should be adjusted accordingly. 784 */ 785 return (ENETRESET); 786} 787 788SYSCTL_NODE(_net_link, IFT_ETHER, ether, CTLFLAG_RW, 0, "Ethernet");
|