When outputting, search for the sending address on the sending interface

rather than blindly picking the first matcing address from any interface
when testing source address validity.

This allows another interface to have the same address, but be detached.
This commit is contained in:
roy 2017-07-03 16:43:01 +00:00
parent e8c03fc557
commit c02f483da3
1 changed files with 7 additions and 5 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: ip_output.c,v 1.279 2017/05/12 17:53:54 ryo Exp $ */
/* $NetBSD: ip_output.c,v 1.280 2017/07/03 16:43:01 roy Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@ -91,7 +91,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.279 2017/05/12 17:53:54 ryo Exp $");
__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.280 2017/07/03 16:43:01 roy Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@ -236,6 +236,7 @@ ip_output(struct mbuf *m0, struct mbuf *opt, struct route *ro, int flags,
struct route iproute;
const struct sockaddr_in *dst;
struct in_ifaddr *ia = NULL;
struct ifaddr *ifa;
int isbroadcast;
int sw_csum;
u_long mtu;
@ -315,8 +316,6 @@ ip_output(struct mbuf *m0, struct mbuf *opt, struct route *ro, int flags,
* If routing to interface only, short circuit routing lookup.
*/
if (flags & IP_ROUTETOIF) {
struct ifaddr *ifa;
ifa = ifa_ifwithladdr_psref(sintocsa(dst), &psref_ia);
if (ifa == NULL) {
IP_STATINC(IP_STAT_NOROUTE);
@ -612,7 +611,10 @@ sendit:
* validity
*/
KASSERT(ia == NULL);
ia = in_get_ia_psref(ip->ip_src, &psref_ia);
sockaddr_in_init(&u.dst4, &ip->ip_src, 0);
ifa = ifaof_ifpforaddr_psref(&u.dst, ifp, &psref_ia);
if (ifa != NULL)
ia = ifatoia(ifa);
/*
* Ensure we only send from a valid address.