icmp6.c (108741) | icmp6.c (109623) |
---|---|
1/* $FreeBSD: head/sys/netinet6/icmp6.c 108741 2003-01-05 22:37:36Z sam $ */ | 1/* $FreeBSD: head/sys/netinet6/icmp6.c 109623 2003-01-21 08:56:16Z alfred $ */ |
2/* $KAME: icmp6.c,v 1.211 2001/04/04 05:56:20 itojun Exp $ */ 3 4/* 5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 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 --- 331 unchanged lines hidden (view full) --- 341 /* 342 * OK, ICMP6 can be generated. 343 */ 344 345 if (m->m_pkthdr.len >= ICMPV6_PLD_MAXLEN) 346 m_adj(m, ICMPV6_PLD_MAXLEN - m->m_pkthdr.len); 347 348 preplen = sizeof(struct ip6_hdr) + sizeof(struct icmp6_hdr); | 2/* $KAME: icmp6.c,v 1.211 2001/04/04 05:56:20 itojun Exp $ */ 3 4/* 5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 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 --- 331 unchanged lines hidden (view full) --- 341 /* 342 * OK, ICMP6 can be generated. 343 */ 344 345 if (m->m_pkthdr.len >= ICMPV6_PLD_MAXLEN) 346 m_adj(m, ICMPV6_PLD_MAXLEN - m->m_pkthdr.len); 347 348 preplen = sizeof(struct ip6_hdr) + sizeof(struct icmp6_hdr); |
349 M_PREPEND(m, preplen, M_DONTWAIT); | 349 M_PREPEND(m, preplen, M_NOWAIT); |
350 if (m && m->m_len < preplen) 351 m = m_pullup(m, preplen); 352 if (m == NULL) { 353 nd6log((LOG_DEBUG, "ENOBUFS in icmp6_error %d\n", __LINE__)); 354 return; 355 } 356 357 nip6 = mtod(m, struct ip6_hdr *); --- 199 unchanged lines hidden (view full) --- 557 * Prepare an internal mbuf. m_pullup() doesn't 558 * always copy the length we specified. 559 */ 560 if (maxlen >= MCLBYTES) { 561 /* Give up remote */ 562 m_freem(n0); 563 break; 564 } | 350 if (m && m->m_len < preplen) 351 m = m_pullup(m, preplen); 352 if (m == NULL) { 353 nd6log((LOG_DEBUG, "ENOBUFS in icmp6_error %d\n", __LINE__)); 354 return; 355 } 356 357 nip6 = mtod(m, struct ip6_hdr *); --- 199 unchanged lines hidden (view full) --- 557 * Prepare an internal mbuf. m_pullup() doesn't 558 * always copy the length we specified. 559 */ 560 if (maxlen >= MCLBYTES) { 561 /* Give up remote */ 562 m_freem(n0); 563 break; 564 } |
565 MGETHDR(n, M_DONTWAIT, n0->m_type); | 565 MGETHDR(n, M_NOWAIT, n0->m_type); |
566 if (n && maxlen >= MHLEN) { | 566 if (n && maxlen >= MHLEN) { |
567 MCLGET(n, M_DONTWAIT); | 567 MCLGET(n, M_NOWAIT); |
568 if ((n->m_flags & M_EXT) == 0) { 569 m_free(n); 570 n = NULL; 571 } 572 } 573 if (n == NULL) { 574 /* Give up remote */ 575 m_freem(n0); --- 42 unchanged lines hidden (view full) --- 618 case MLD_LISTENER_QUERY: 619 case MLD_LISTENER_REPORT: 620 if (icmp6len < sizeof(struct mld_hdr)) 621 goto badlen; 622 if (icmp6->icmp6_type == MLD_LISTENER_QUERY) /* XXX: ugly... */ 623 icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_mldquery); 624 else 625 icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_mldreport); | 568 if ((n->m_flags & M_EXT) == 0) { 569 m_free(n); 570 n = NULL; 571 } 572 } 573 if (n == NULL) { 574 /* Give up remote */ 575 m_freem(n0); --- 42 unchanged lines hidden (view full) --- 618 case MLD_LISTENER_QUERY: 619 case MLD_LISTENER_REPORT: 620 if (icmp6len < sizeof(struct mld_hdr)) 621 goto badlen; 622 if (icmp6->icmp6_type == MLD_LISTENER_QUERY) /* XXX: ugly... */ 623 icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_mldquery); 624 else 625 icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_mldreport); |
626 if ((n = m_copym(m, 0, M_COPYALL, M_DONTWAIT)) == NULL) { | 626 if ((n = m_copym(m, 0, M_COPYALL, M_NOWAIT)) == NULL) { |
627 /* give up local */ 628 mld6_input(m, off); 629 m = NULL; 630 goto freeit; 631 } 632 mld6_input(n, off); 633 /* m stays. */ 634 break; --- 44 unchanged lines hidden (view full) --- 679 680 if (code != 0) 681 goto badcode; 682 maxlen = sizeof(*nip6) + sizeof(*nicmp6) + 4; 683 if (maxlen >= MCLBYTES) { 684 /* Give up remote */ 685 break; 686 } | 627 /* give up local */ 628 mld6_input(m, off); 629 m = NULL; 630 goto freeit; 631 } 632 mld6_input(n, off); 633 /* m stays. */ 634 break; --- 44 unchanged lines hidden (view full) --- 679 680 if (code != 0) 681 goto badcode; 682 maxlen = sizeof(*nip6) + sizeof(*nicmp6) + 4; 683 if (maxlen >= MCLBYTES) { 684 /* Give up remote */ 685 break; 686 } |
687 MGETHDR(n, M_DONTWAIT, m->m_type); | 687 MGETHDR(n, M_NOWAIT, m->m_type); |
688 if (n && maxlen > MHLEN) { | 688 if (n && maxlen > MHLEN) { |
689 MCLGET(n, M_DONTWAIT); | 689 MCLGET(n, M_NOWAIT); |
690 if ((n->m_flags & M_EXT) == 0) { 691 m_free(n); 692 n = NULL; 693 } 694 } | 690 if ((n->m_flags & M_EXT) == 0) { 691 m_free(n); 692 n = NULL; 693 } 694 } |
695 if (!m_dup_pkthdr(n, m, M_DONTWAIT)) { | 695 if (!m_dup_pkthdr(n, m, M_NOWAIT)) { |
696 /* 697 * Previous code did a blind M_COPY_PKTHDR 698 * and said "just for rcvif". If true, then 699 * we could tolerate the dup failing (due to 700 * the deep copy of the tag chain). For now 701 * be conservative and just fail. 702 */ 703 m_free(n); --- 39 unchanged lines hidden (view full) --- 743 break; 744 745 case ND_ROUTER_SOLICIT: 746 icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_routersolicit); 747 if (code != 0) 748 goto badcode; 749 if (icmp6len < sizeof(struct nd_router_solicit)) 750 goto badlen; | 696 /* 697 * Previous code did a blind M_COPY_PKTHDR 698 * and said "just for rcvif". If true, then 699 * we could tolerate the dup failing (due to 700 * the deep copy of the tag chain). For now 701 * be conservative and just fail. 702 */ 703 m_free(n); --- 39 unchanged lines hidden (view full) --- 743 break; 744 745 case ND_ROUTER_SOLICIT: 746 icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_routersolicit); 747 if (code != 0) 748 goto badcode; 749 if (icmp6len < sizeof(struct nd_router_solicit)) 750 goto badlen; |
751 if ((n = m_copym(m, 0, M_COPYALL, M_DONTWAIT)) == NULL) { | 751 if ((n = m_copym(m, 0, M_COPYALL, M_NOWAIT)) == NULL) { |
752 /* give up local */ 753 nd6_rs_input(m, off, icmp6len); 754 m = NULL; 755 goto freeit; 756 } 757 nd6_rs_input(n, off, icmp6len); 758 /* m stays. */ 759 break; 760 761 case ND_ROUTER_ADVERT: 762 icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_routeradvert); 763 if (code != 0) 764 goto badcode; 765 if (icmp6len < sizeof(struct nd_router_advert)) 766 goto badlen; | 752 /* give up local */ 753 nd6_rs_input(m, off, icmp6len); 754 m = NULL; 755 goto freeit; 756 } 757 nd6_rs_input(n, off, icmp6len); 758 /* m stays. */ 759 break; 760 761 case ND_ROUTER_ADVERT: 762 icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_routeradvert); 763 if (code != 0) 764 goto badcode; 765 if (icmp6len < sizeof(struct nd_router_advert)) 766 goto badlen; |
767 if ((n = m_copym(m, 0, M_COPYALL, M_DONTWAIT)) == NULL) { | 767 if ((n = m_copym(m, 0, M_COPYALL, M_NOWAIT)) == NULL) { |
768 /* give up local */ 769 nd6_ra_input(m, off, icmp6len); 770 m = NULL; 771 goto freeit; 772 } 773 nd6_ra_input(n, off, icmp6len); 774 /* m stays. */ 775 break; 776 777 case ND_NEIGHBOR_SOLICIT: 778 icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_neighborsolicit); 779 if (code != 0) 780 goto badcode; 781 if (icmp6len < sizeof(struct nd_neighbor_solicit)) 782 goto badlen; | 768 /* give up local */ 769 nd6_ra_input(m, off, icmp6len); 770 m = NULL; 771 goto freeit; 772 } 773 nd6_ra_input(n, off, icmp6len); 774 /* m stays. */ 775 break; 776 777 case ND_NEIGHBOR_SOLICIT: 778 icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_neighborsolicit); 779 if (code != 0) 780 goto badcode; 781 if (icmp6len < sizeof(struct nd_neighbor_solicit)) 782 goto badlen; |
783 if ((n = m_copym(m, 0, M_COPYALL, M_DONTWAIT)) == NULL) { | 783 if ((n = m_copym(m, 0, M_COPYALL, M_NOWAIT)) == NULL) { |
784 /* give up local */ 785 nd6_ns_input(m, off, icmp6len); 786 m = NULL; 787 goto freeit; 788 } 789 nd6_ns_input(n, off, icmp6len); 790 /* m stays. */ 791 break; 792 793 case ND_NEIGHBOR_ADVERT: 794 icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_neighboradvert); 795 if (code != 0) 796 goto badcode; 797 if (icmp6len < sizeof(struct nd_neighbor_advert)) 798 goto badlen; | 784 /* give up local */ 785 nd6_ns_input(m, off, icmp6len); 786 m = NULL; 787 goto freeit; 788 } 789 nd6_ns_input(n, off, icmp6len); 790 /* m stays. */ 791 break; 792 793 case ND_NEIGHBOR_ADVERT: 794 icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_neighboradvert); 795 if (code != 0) 796 goto badcode; 797 if (icmp6len < sizeof(struct nd_neighbor_advert)) 798 goto badlen; |
799 if ((n = m_copym(m, 0, M_COPYALL, M_DONTWAIT)) == NULL) { | 799 if ((n = m_copym(m, 0, M_COPYALL, M_NOWAIT)) == NULL) { |
800 /* give up local */ 801 nd6_na_input(m, off, icmp6len); 802 m = NULL; 803 goto freeit; 804 } 805 nd6_na_input(n, off, icmp6len); 806 /* m stays. */ 807 break; 808 809 case ND_REDIRECT: 810 icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_redirect); 811 if (code != 0) 812 goto badcode; 813 if (icmp6len < sizeof(struct nd_redirect)) 814 goto badlen; | 800 /* give up local */ 801 nd6_na_input(m, off, icmp6len); 802 m = NULL; 803 goto freeit; 804 } 805 nd6_na_input(n, off, icmp6len); 806 /* m stays. */ 807 break; 808 809 case ND_REDIRECT: 810 icmp6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_redirect); 811 if (code != 0) 812 goto badcode; 813 if (icmp6len < sizeof(struct nd_redirect)) 814 goto badlen; |
815 if ((n = m_copym(m, 0, M_COPYALL, M_DONTWAIT)) == NULL) { | 815 if ((n = m_copym(m, 0, M_COPYALL, M_NOWAIT)) == NULL) { |
816 /* give up local */ 817 icmp6_redirect_input(m, off); 818 m = NULL; 819 goto freeit; 820 } 821 icmp6_redirect_input(n, off); 822 /* m stays. */ 823 break; --- 565 unchanged lines hidden (view full) --- 1389 qtype = NI_QTYPE_FQDN; 1390 /* XXX will append an mbuf */ 1391 replylen += offsetof(struct ni_reply_fqdn, ni_fqdn_namelen); 1392 oldfqdn++; 1393 break; 1394 } 1395 1396 /* allocate an mbuf to reply. */ | 816 /* give up local */ 817 icmp6_redirect_input(m, off); 818 m = NULL; 819 goto freeit; 820 } 821 icmp6_redirect_input(n, off); 822 /* m stays. */ 823 break; --- 565 unchanged lines hidden (view full) --- 1389 qtype = NI_QTYPE_FQDN; 1390 /* XXX will append an mbuf */ 1391 replylen += offsetof(struct ni_reply_fqdn, ni_fqdn_namelen); 1392 oldfqdn++; 1393 break; 1394 } 1395 1396 /* allocate an mbuf to reply. */ |
1397 MGETHDR(n, M_DONTWAIT, m->m_type); | 1397 MGETHDR(n, M_NOWAIT, m->m_type); |
1398 if (n == NULL) { 1399 m_freem(m); 1400 return(NULL); 1401 } 1402 M_MOVE_PKTHDR(n, m); /* just for recvif */ 1403 if (replylen > MHLEN) { 1404 if (replylen > MCLBYTES) { 1405 /* 1406 * XXX: should we try to allocate more? But MCLBYTES 1407 * is probably much larger than IPV6_MMTU... 1408 */ 1409 goto bad; 1410 } | 1398 if (n == NULL) { 1399 m_freem(m); 1400 return(NULL); 1401 } 1402 M_MOVE_PKTHDR(n, m); /* just for recvif */ 1403 if (replylen > MHLEN) { 1404 if (replylen > MCLBYTES) { 1405 /* 1406 * XXX: should we try to allocate more? But MCLBYTES 1407 * is probably much larger than IPV6_MMTU... 1408 */ 1409 goto bad; 1410 } |
1411 MCLGET(n, M_DONTWAIT); | 1411 MCLGET(n, M_NOWAIT); |
1412 if ((n->m_flags & M_EXT) == 0) { 1413 goto bad; 1414 } 1415 } 1416 n->m_pkthdr.len = n->m_len = replylen; 1417 1418 /* copy mbuf header and IPv6 + Node Information base headers */ 1419 bcopy(mtod(m, caddr_t), mtod(n, caddr_t), sizeof(struct ip6_hdr)); --- 82 unchanged lines hidden (view full) --- 1502 int i, len, nterm; 1503 1504 if (old) 1505 len = namelen + 1; 1506 else 1507 len = MCLBYTES; 1508 1509 /* because MAXHOSTNAMELEN is usually 256, we use cluster mbuf */ | 1412 if ((n->m_flags & M_EXT) == 0) { 1413 goto bad; 1414 } 1415 } 1416 n->m_pkthdr.len = n->m_len = replylen; 1417 1418 /* copy mbuf header and IPv6 + Node Information base headers */ 1419 bcopy(mtod(m, caddr_t), mtod(n, caddr_t), sizeof(struct ip6_hdr)); --- 82 unchanged lines hidden (view full) --- 1502 int i, len, nterm; 1503 1504 if (old) 1505 len = namelen + 1; 1506 else 1507 len = MCLBYTES; 1508 1509 /* because MAXHOSTNAMELEN is usually 256, we use cluster mbuf */ |
1510 MGET(m, M_DONTWAIT, MT_DATA); | 1510 MGET(m, M_NOWAIT, MT_DATA); |
1511 if (m && len > MLEN) { | 1511 if (m && len > MLEN) { |
1512 MCLGET(m, M_DONTWAIT); | 1512 MCLGET(m, M_NOWAIT); |
1513 if ((m->m_flags & M_EXT) == 0) 1514 goto fail; 1515 } 1516 if (!m) 1517 goto fail; 1518 m->m_next = NULL; 1519 1520 if (old) { --- 951 unchanged lines hidden (view full) --- 2472 /* 2473 * Since we are going to append up to 1280 bytes (= IPV6_MMTU), 2474 * we almost always ask for an mbuf cluster for simplicity. 2475 * (MHLEN < IPV6_MMTU is almost always true) 2476 */ 2477#if IPV6_MMTU >= MCLBYTES 2478# error assumption failed about IPV6_MMTU and MCLBYTES 2479#endif | 1513 if ((m->m_flags & M_EXT) == 0) 1514 goto fail; 1515 } 1516 if (!m) 1517 goto fail; 1518 m->m_next = NULL; 1519 1520 if (old) { --- 951 unchanged lines hidden (view full) --- 2472 /* 2473 * Since we are going to append up to 1280 bytes (= IPV6_MMTU), 2474 * we almost always ask for an mbuf cluster for simplicity. 2475 * (MHLEN < IPV6_MMTU is almost always true) 2476 */ 2477#if IPV6_MMTU >= MCLBYTES 2478# error assumption failed about IPV6_MMTU and MCLBYTES 2479#endif |
2480 MGETHDR(m, M_DONTWAIT, MT_HEADER); | 2480 MGETHDR(m, M_NOWAIT, MT_HEADER); |
2481 if (m && IPV6_MMTU >= MHLEN) | 2481 if (m && IPV6_MMTU >= MHLEN) |
2482 MCLGET(m, M_DONTWAIT); | 2482 MCLGET(m, M_NOWAIT); |
2483 if (!m) 2484 goto fail; 2485 m->m_pkthdr.rcvif = NULL; 2486 m->m_len = 0; 2487 maxlen = M_TRAILINGSPACE(m); 2488 maxlen = min(IPV6_MMTU, maxlen); 2489 /* just for safety */ 2490 if (maxlen < sizeof(struct ip6_hdr) + sizeof(struct icmp6_hdr) + --- 396 unchanged lines hidden --- | 2483 if (!m) 2484 goto fail; 2485 m->m_pkthdr.rcvif = NULL; 2486 m->m_len = 0; 2487 maxlen = M_TRAILINGSPACE(m); 2488 maxlen = min(IPV6_MMTU, maxlen); 2489 /* just for safety */ 2490 if (maxlen < sizeof(struct ip6_hdr) + sizeof(struct icmp6_hdr) + --- 396 unchanged lines hidden --- |