mirror of
https://git.FreeBSD.org/src.git
synced 2025-01-05 12:56:08 +00:00
Add a per-interface-address pointer to a function that can be supplied
by a protocol, to detirmine if an address matches the net this address is part of. This is needed by protocols for which netmasks "just don't work", for example appletalk. Also add the code in appletalk to make use of this new feature. Thsi fixes one of the longest standing bugs in appletalk. The inability to talk to machines to which the path is via a router which is on a different net, but the same netrange, as your interface. Protocols that do not supply this function (e.g. IP) should not be affected.
This commit is contained in:
parent
1bf978ce42
commit
7ed8f465e7
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=28845
16
sys/net/if.c
16
sys/net/if.c
@ -31,7 +31,7 @@
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)if.c 8.3 (Berkeley) 1/4/94
|
||||
* $Id: if.c,v 1.49 1997/07/07 17:36:06 julian Exp $
|
||||
* $Id: if.c,v 1.50 1997/08/22 22:47:27 julian Exp $
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
@ -269,6 +269,18 @@ next: continue;
|
||||
&& equal(addr, ifa->ifa_dstaddr))
|
||||
return (ifa);
|
||||
} else {
|
||||
/*
|
||||
* if we have a special address handler,
|
||||
* then use it instead of the generic one.
|
||||
*/
|
||||
if (ifa->ifa_claim_addr) {
|
||||
if ((*ifa->ifa_claim_addr)(ifa, addr)) {
|
||||
return (ifa);
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Scan all the bits in the ifa's address.
|
||||
* If a bit dissagrees with what we are
|
||||
@ -576,7 +588,7 @@ ifioctl(so, cmd, data, p)
|
||||
case SIOCSIFPHYS:
|
||||
error = suser(p->p_ucred, &p->p_acflag);
|
||||
if (error)
|
||||
return error;
|
||||
return error;
|
||||
if (!ifp->if_ioctl)
|
||||
return EOPNOTSUPP;
|
||||
error = (*ifp->if_ioctl)(ifp, cmd, data);
|
||||
|
@ -31,7 +31,7 @@
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* From: @(#)if.h 8.1 (Berkeley) 6/10/93
|
||||
* $Id$
|
||||
* $Id: if_var.h,v 1.5 1997/02/22 09:41:10 peter Exp $
|
||||
*/
|
||||
|
||||
#ifndef _NET_IF_VAR_H_
|
||||
@ -254,6 +254,9 @@ struct ifaddr {
|
||||
#ifdef notdef
|
||||
struct rtentry *ifa_rt; /* XXXX for ROUTETOIF ????? */
|
||||
#endif
|
||||
int (*ifa_claim_addr) /* check if an addr goes to this if */
|
||||
__P((struct ifaddr *, struct sockaddr *));
|
||||
|
||||
};
|
||||
#define IFA_ROUTE RTF_UP /* route installed */
|
||||
|
||||
|
@ -36,6 +36,7 @@ static int aa_dosingleroute(struct ifaddr *ifa, struct at_addr *addr,
|
||||
static int at_scrub( struct ifnet *ifp, struct at_ifaddr *aa );
|
||||
static int at_ifinit( struct ifnet *ifp, struct at_ifaddr *aa,
|
||||
struct sockaddr_at *sat );
|
||||
static int aa_claim_addr(struct ifaddr *ifa, struct sockaddr *gw);
|
||||
|
||||
# define sateqaddr(a,b) ((a)->sat_len == (b)->sat_len && \
|
||||
(a)->sat_family == (b)->sat_family && \
|
||||
@ -137,7 +138,6 @@ at_control(struct socket *so, int cmd, caddr_t data,
|
||||
/*
|
||||
* If we failed to find an existing at_ifaddr entry, then we
|
||||
* allocate a fresh one.
|
||||
* XXX change this to use malloc
|
||||
*/
|
||||
if ( aa == (struct at_ifaddr *) 0 ) {
|
||||
aa0 = malloc(sizeof(struct at_ifaddr), M_IFADDR, M_WAITOK);
|
||||
@ -491,6 +491,12 @@ at_ifinit( ifp, aa, sat )
|
||||
AA_SAT( aa )->sat_addr.s_node = sat->sat_addr.s_node;
|
||||
}
|
||||
|
||||
/*
|
||||
* Copy the phase.
|
||||
*/
|
||||
AA_SAT( aa )->sat_range.r_netrange.nr_phase
|
||||
= ((aa->aa_flags & AFA_PHASE2) ? 2:1);
|
||||
|
||||
/*
|
||||
* step through the nets in the range
|
||||
* starting at the (possibly random) start point.
|
||||
@ -633,6 +639,11 @@ at_ifinit( ifp, aa, sat )
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* set the address of our "check if this addr is ours" routine.
|
||||
*/
|
||||
aa->aa_ifa.ifa_claim_addr = aa_claim_addr;
|
||||
|
||||
/*
|
||||
* of course if we can't add these routes we back out, but it's getting
|
||||
* risky by now XXX
|
||||
@ -834,3 +845,34 @@ aa_clean(void)
|
||||
|
||||
#endif
|
||||
|
||||
static int
|
||||
aa_claim_addr(struct ifaddr *ifa, struct sockaddr *gw0)
|
||||
{
|
||||
struct sockaddr_at *addr = (struct sockaddr_at *)ifa->ifa_addr;
|
||||
struct sockaddr_at *gw = (struct sockaddr_at *)gw0;
|
||||
|
||||
switch (gw->sat_range.r_netrange.nr_phase) {
|
||||
case 1:
|
||||
if(addr->sat_range.r_netrange.nr_phase == 1)
|
||||
return 1;
|
||||
case 0:
|
||||
case 2:
|
||||
/*
|
||||
* if it's our net (including 0),
|
||||
* or netranges are valid, and we are in the range,
|
||||
* then it's ours.
|
||||
*/
|
||||
if ((addr->sat_addr.s_net == gw->sat_addr.s_net)
|
||||
|| ((addr->sat_range.r_netrange.nr_lastnet)
|
||||
&& (gw->sat_addr.s_net
|
||||
>= addr->sat_range.r_netrange.nr_firstnet )
|
||||
&& (gw->sat_addr.s_net
|
||||
<= addr->sat_range.r_netrange.nr_lastnet ))) {
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
printf("atalk: bad phase\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -119,16 +119,32 @@ ddp_route( struct mbuf *m, struct route *ro)
|
||||
struct ifnet *ifp = NULL;
|
||||
u_short net;
|
||||
|
||||
if ( ro->ro_rt && ( ifp = ro->ro_rt->rt_ifp )) {
|
||||
net = satosat( ro->ro_rt->rt_gateway )->sat_addr.s_net;
|
||||
/*
|
||||
* if we have a route, find the ifa that refers to this route.
|
||||
* I.e The ifa used to get to the gateway.
|
||||
*/
|
||||
if ( (ro->ro_rt == NULL)
|
||||
|| ( ro->ro_rt->rt_ifa == NULL )
|
||||
|| ( (ifp = ro->ro_rt->rt_ifa->ifa_ifp) == NULL )) {
|
||||
rtalloc(ro);
|
||||
}
|
||||
if ( (ro->ro_rt != NULL)
|
||||
&& ( ro->ro_rt->rt_ifa )
|
||||
&& ( ifp = ro->ro_rt->rt_ifa->ifa_ifp )) {
|
||||
net = satosat(ro->ro_rt->rt_gateway)->sat_addr.s_net;
|
||||
for ( aa = at_ifaddr; aa; aa = aa->aa_next ) {
|
||||
if ( aa->aa_ifp == ifp &&
|
||||
if (((net == 0) || (aa->aa_ifp == ifp)) &&
|
||||
ntohs( net ) >= ntohs( aa->aa_firstnet ) &&
|
||||
ntohs( net ) <= ntohs( aa->aa_lastnet )) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
printf( "ddp_route: still have no valid route\n");
|
||||
m_freem( m );
|
||||
return( EINVAL );
|
||||
}
|
||||
|
||||
if ( aa == NULL ) {
|
||||
printf( "ddp_route: oops\n" );
|
||||
m_freem( m );
|
||||
|
Loading…
Reference in New Issue
Block a user