From 13e8370e951b0f98f53aaec1eb7f2ca1ab17a106 Mon Sep 17 00:00:00 2001 From: Martin Pieuchot Date: Mon, 28 Nov 2016 14:14:40 +0000 Subject: Explicitly initialize rti_ifa when automagically adding a route. This will allow to strengthen checks when userland adds a route. ok phessler@, bluhm@ --- sys/netinet/ip_icmp.c | 3 ++- sys/netinet6/icmp6.c | 3 ++- sys/netinet6/in6.c | 8 ++++---- sys/netinet6/nd6.c | 7 ++++--- sys/netinet6/nd6_rtr.c | 3 ++- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/sys/netinet/ip_icmp.c b/sys/netinet/ip_icmp.c index 392728490b3..d5507922af0 100644 --- a/sys/netinet/ip_icmp.c +++ b/sys/netinet/ip_icmp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_icmp.c,v 1.156 2016/11/16 12:48:19 bluhm Exp $ */ +/* $OpenBSD: ip_icmp.c,v 1.157 2016/11/28 14:14:39 mpi Exp $ */ /* $NetBSD: ip_icmp.c,v 1.19 1996/02/13 23:42:22 christos Exp $ */ /* @@ -954,6 +954,7 @@ icmp_mtudisc_clone(struct in_addr dst, u_int rtableid) struct sockaddr_rtlabel sa_rl; memset(&info, 0, sizeof(info)); + info.rti_ifa = rt->rt_ifa; info.rti_flags = RTF_GATEWAY | RTF_HOST | RTF_DYNAMIC; info.rti_info[RTAX_DST] = sintosa(&sin); info.rti_info[RTAX_GATEWAY] = rt->rt_gateway; diff --git a/sys/netinet6/icmp6.c b/sys/netinet6/icmp6.c index 27e7ad6275a..56779adae21 100644 --- a/sys/netinet6/icmp6.c +++ b/sys/netinet6/icmp6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: icmp6.c,v 1.193 2016/11/16 12:48:19 bluhm Exp $ */ +/* $OpenBSD: icmp6.c,v 1.194 2016/11/28 14:14:39 mpi Exp $ */ /* $KAME: icmp6.c,v 1.217 2001/06/20 15:03:29 jinmei Exp $ */ /* @@ -1921,6 +1921,7 @@ icmp6_mtudisc_clone(struct sockaddr *dst, u_int rtableid) struct sockaddr_rtlabel sa_rl; memset(&info, 0, sizeof(info)); + info.rti_ifa = rt->rt_ifa; info.rti_flags = RTF_GATEWAY | RTF_HOST | RTF_DYNAMIC; info.rti_info[RTAX_DST] = dst; info.rti_info[RTAX_GATEWAY] = rt->rt_gateway; diff --git a/sys/netinet6/in6.c b/sys/netinet6/in6.c index 55d8d98f79d..8b9ff6da271 100644 --- a/sys/netinet6/in6.c +++ b/sys/netinet6/in6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: in6.c,v 1.194 2016/10/04 14:04:19 mpi Exp $ */ +/* $OpenBSD: in6.c,v 1.195 2016/11/28 14:14:39 mpi Exp $ */ /* $KAME: in6.c,v 1.372 2004/06/14 08:14:21 itojun Exp $ */ /* @@ -746,9 +746,7 @@ in6_update_ifa(struct ifnet *ifp, struct in6_aliasreq *ifra, */ rt = rtalloc(sin6tosa(&mltaddr), 0, ifp->if_rdomain); if (rt) { - /* - * 32bit came from "mltmask" - */ + /* 32bit came from "mltmask" */ if (memcmp(&mltaddr.sin6_addr, &satosin6(rt_key(rt))->sin6_addr, 32 / 8)) { @@ -760,6 +758,7 @@ in6_update_ifa(struct ifnet *ifp, struct in6_aliasreq *ifra, struct rt_addrinfo info; bzero(&info, sizeof(info)); + info.rti_ifa = &ia6->ia_ifa; info.rti_info[RTAX_DST] = sin6tosa(&mltaddr); info.rti_info[RTAX_GATEWAY] = sin6tosa(&ia6->ia_addr); info.rti_info[RTAX_NETMASK] = sin6tosa(&mltmask); @@ -816,6 +815,7 @@ in6_update_ifa(struct ifnet *ifp, struct in6_aliasreq *ifra, struct rt_addrinfo info; bzero(&info, sizeof(info)); + info.rti_ifa = &ia6->ia_ifa; info.rti_info[RTAX_DST] = sin6tosa(&mltaddr); info.rti_info[RTAX_GATEWAY] = sin6tosa(&ia6->ia_addr); info.rti_info[RTAX_NETMASK] = sin6tosa(&mltmask); diff --git a/sys/netinet6/nd6.c b/sys/netinet6/nd6.c index 960ef56cda7..707ca3c5894 100644 --- a/sys/netinet6/nd6.c +++ b/sys/netinet6/nd6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nd6.c,v 1.196 2016/11/28 13:59:51 mpi Exp $ */ +/* $OpenBSD: nd6.c,v 1.197 2016/11/28 14:14:39 mpi Exp $ */ /* $KAME: nd6.c,v 1.280 2002/06/08 19:52:07 itojun Exp $ */ /* @@ -583,6 +583,7 @@ nd6_lookup(struct in6_addr *addr6, int create, struct ifnet *ifp, if (rt == NULL) { if (create && ifp) { struct rt_addrinfo info; + struct ifaddr *ifa; int error; /* @@ -592,8 +593,7 @@ nd6_lookup(struct in6_addr *addr6, int create, struct ifnet *ifp, * This hack is necessary for a neighbor which can't * be covered by our own prefix. */ - struct ifaddr *ifa = - ifaof_ifpforaddr(sin6tosa(&sin6), ifp); + ifa = ifaof_ifpforaddr(sin6tosa(&sin6), ifp); if (ifa == NULL) return (NULL); @@ -604,6 +604,7 @@ nd6_lookup(struct in6_addr *addr6, int create, struct ifnet *ifp, * called in rtrequest. */ bzero(&info, sizeof(info)); + info.rti_ifa = ifa; info.rti_flags = RTF_HOST | RTF_LLINFO; info.rti_info[RTAX_DST] = sin6tosa(&sin6); info.rti_info[RTAX_GATEWAY] = sdltosa(ifp->if_sadl); diff --git a/sys/netinet6/nd6_rtr.c b/sys/netinet6/nd6_rtr.c index 4f45c10df8d..78e070b2499 100644 --- a/sys/netinet6/nd6_rtr.c +++ b/sys/netinet6/nd6_rtr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: nd6_rtr.c,v 1.152 2016/11/28 13:59:51 mpi Exp $ */ +/* $OpenBSD: nd6_rtr.c,v 1.153 2016/11/28 14:14:39 mpi Exp $ */ /* $KAME: nd6_rtr.c,v 1.97 2001/02/07 11:09:13 itojun Exp $ */ /* @@ -594,6 +594,7 @@ defrouter_addreq(struct nd_defrouter *new) gate.sin6_addr = new->rtaddr; gate.sin6_scope_id = 0; /* XXX */ + info.rti_ifa = NULL; info.rti_flags = RTF_GATEWAY; info.rti_info[RTAX_DST] = sin6tosa(&def); info.rti_info[RTAX_GATEWAY] = sin6tosa(&gate); -- cgit v1.2.3