| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: rtsock.c,v 1.213 2017/06/01 02:45:14 chs Exp $ */ | | 1 | /* $NetBSD: rtsock.c,v 1.214 2017/06/15 02:51:45 ozaki-r Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. | | 4 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -51,27 +51,27 @@ | | | @@ -51,27 +51,27 @@ |
51 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | | 51 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
52 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 52 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
53 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 53 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
54 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 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 | | 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 | | 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 | | 57 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
58 | * SUCH DAMAGE. | | 58 | * SUCH DAMAGE. |
59 | * | | 59 | * |
60 | * @(#)rtsock.c 8.7 (Berkeley) 10/12/95 | | 60 | * @(#)rtsock.c 8.7 (Berkeley) 10/12/95 |
61 | */ | | 61 | */ |
62 | | | 62 | |
63 | #include <sys/cdefs.h> | | 63 | #include <sys/cdefs.h> |
64 | __KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.213 2017/06/01 02:45:14 chs Exp $"); | | 64 | __KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.214 2017/06/15 02:51:45 ozaki-r Exp $"); |
65 | | | 65 | |
66 | #ifdef _KERNEL_OPT | | 66 | #ifdef _KERNEL_OPT |
67 | #include "opt_inet.h" | | 67 | #include "opt_inet.h" |
68 | #include "opt_mpls.h" | | 68 | #include "opt_mpls.h" |
69 | #include "opt_compat_netbsd.h" | | 69 | #include "opt_compat_netbsd.h" |
70 | #include "opt_sctp.h" | | 70 | #include "opt_sctp.h" |
71 | #include "opt_net_mpsafe.h" | | 71 | #include "opt_net_mpsafe.h" |
72 | #endif | | 72 | #endif |
73 | | | 73 | |
74 | #include <sys/param.h> | | 74 | #include <sys/param.h> |
75 | #include <sys/systm.h> | | 75 | #include <sys/systm.h> |
76 | #include <sys/proc.h> | | 76 | #include <sys/proc.h> |
77 | #include <sys/socket.h> | | 77 | #include <sys/socket.h> |
| @@ -526,32 +526,31 @@ route_get_sdl(const struct ifnet *ifp, c | | | @@ -526,32 +526,31 @@ route_get_sdl(const struct ifnet *ifp, c |
526 | KASSERT(a != NULL); | | 526 | KASSERT(a != NULL); |
527 | | | 527 | |
528 | if (la != NULL) { | | 528 | if (la != NULL) { |
529 | *flags = la->la_flags; | | 529 | *flags = la->la_flags; |
530 | LLE_RUNLOCK(la); | | 530 | LLE_RUNLOCK(la); |
531 | } | | 531 | } |
532 | } | | 532 | } |
533 | | | 533 | |
534 | static int | | 534 | static int |
535 | route_output_report(struct rtentry *rt, struct rt_addrinfo *info, | | 535 | route_output_report(struct rtentry *rt, struct rt_addrinfo *info, |
536 | struct rt_xmsghdr *rtm, struct rt_xmsghdr **new_rtm) | | 536 | struct rt_xmsghdr *rtm, struct rt_xmsghdr **new_rtm) |
537 | { | | 537 | { |
538 | int len; | | 538 | int len; |
539 | struct ifnet *ifp; | | | |
540 | | | 539 | |
541 | if ((rtm->rtm_addrs & (RTA_IFP | RTA_IFA)) == 0) | | 540 | if (rtm->rtm_addrs & (RTA_IFP | RTA_IFA)) { |
542 | ; | | | |
543 | else if ((ifp = rt->rt_ifp) != NULL) { | | | |
544 | const struct ifaddr *rtifa; | | 541 | const struct ifaddr *rtifa; |
| | | 542 | const struct ifnet *ifp = rt->rt_ifp; |
| | | 543 | |
545 | info->rti_info[RTAX_IFP] = ifp->if_dl->ifa_addr; | | 544 | info->rti_info[RTAX_IFP] = ifp->if_dl->ifa_addr; |
546 | /* rtifa used to be simply rt->rt_ifa. | | 545 | /* rtifa used to be simply rt->rt_ifa. |
547 | * If rt->rt_ifa != NULL, then | | 546 | * If rt->rt_ifa != NULL, then |
548 | * rt_get_ifa() != NULL. So this | | 547 | * rt_get_ifa() != NULL. So this |
549 | * ought to still be safe. --dyoung | | 548 | * ought to still be safe. --dyoung |
550 | */ | | 549 | */ |
551 | rtifa = rt_get_ifa(rt); | | 550 | rtifa = rt_get_ifa(rt); |
552 | info->rti_info[RTAX_IFA] = rtifa->ifa_addr; | | 551 | info->rti_info[RTAX_IFA] = rtifa->ifa_addr; |
553 | #ifdef RTSOCK_DEBUG | | 552 | #ifdef RTSOCK_DEBUG |
554 | if (info->rti_info[RTAX_IFA]->sa_family == AF_INET) { | | 553 | if (info->rti_info[RTAX_IFA]->sa_family == AF_INET) { |
555 | char ibuf[INET_ADDRSTRLEN]; | | 554 | char ibuf[INET_ADDRSTRLEN]; |
556 | char abuf[INET_ADDRSTRLEN]; | | 555 | char abuf[INET_ADDRSTRLEN]; |
557 | printf("%s: copying out RTAX_IFA %s " | | 556 | printf("%s: copying out RTAX_IFA %s " |
| @@ -559,29 +558,26 @@ route_output_report(struct rtentry *rt, | | | @@ -559,29 +558,26 @@ route_output_report(struct rtentry *rt, |
559 | "ifa_getifa %p ifa_seqno %p\n", | | 558 | "ifa_getifa %p ifa_seqno %p\n", |
560 | __func__, | | 559 | __func__, |
561 | RT_IN_PRINT(info, ibuf, RTAX_IFA), | | 560 | RT_IN_PRINT(info, ibuf, RTAX_IFA), |
562 | RT_IN_PRINT(info, abuf, RTAX_DST), | | 561 | RT_IN_PRINT(info, abuf, RTAX_DST), |
563 | (void *)rtifa->ifa_getifa, | | 562 | (void *)rtifa->ifa_getifa, |
564 | rtifa->ifa_seqno); | | 563 | rtifa->ifa_seqno); |
565 | } | | 564 | } |
566 | #endif /* RTSOCK_DEBUG */ | | 565 | #endif /* RTSOCK_DEBUG */ |
567 | if (ifp->if_flags & IFF_POINTOPOINT) | | 566 | if (ifp->if_flags & IFF_POINTOPOINT) |
568 | info->rti_info[RTAX_BRD] = rtifa->ifa_dstaddr; | | 567 | info->rti_info[RTAX_BRD] = rtifa->ifa_dstaddr; |
569 | else | | 568 | else |
570 | info->rti_info[RTAX_BRD] = NULL; | | 569 | info->rti_info[RTAX_BRD] = NULL; |
571 | rtm->rtm_index = ifp->if_index; | | 570 | rtm->rtm_index = ifp->if_index; |
572 | } else { | | | |
573 | info->rti_info[RTAX_IFP] = NULL; | | | |
574 | info->rti_info[RTAX_IFA] = NULL; | | | |
575 | } | | 571 | } |
576 | (void)rt_msg2(rtm->rtm_type, info, NULL, NULL, &len); | | 572 | (void)rt_msg2(rtm->rtm_type, info, NULL, NULL, &len); |
577 | if (len > rtm->rtm_msglen) { | | 573 | if (len > rtm->rtm_msglen) { |
578 | struct rt_xmsghdr *old_rtm = rtm; | | 574 | struct rt_xmsghdr *old_rtm = rtm; |
579 | R_Malloc(*new_rtm, struct rt_xmsghdr *, len); | | 575 | R_Malloc(*new_rtm, struct rt_xmsghdr *, len); |
580 | if (*new_rtm == NULL) | | 576 | if (*new_rtm == NULL) |
581 | return ENOBUFS; | | 577 | return ENOBUFS; |
582 | (void)memcpy(*new_rtm, old_rtm, old_rtm->rtm_msglen); | | 578 | (void)memcpy(*new_rtm, old_rtm, old_rtm->rtm_msglen); |
583 | rtm = *new_rtm; | | 579 | rtm = *new_rtm; |
584 | } | | 580 | } |
585 | (void)rt_msg2(rtm->rtm_type, info, rtm, NULL, 0); | | 581 | (void)rt_msg2(rtm->rtm_type, info, rtm, NULL, 0); |
586 | rtm->rtm_flags = rt->rt_flags; | | 582 | rtm->rtm_flags = rt->rt_flags; |
587 | rtm_setmetrics(rt, rtm); | | 583 | rtm_setmetrics(rt, rtm); |