summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Pieuchot <mpi@cvs.openbsd.org>2013-07-04 08:22:20 +0000
committerMartin Pieuchot <mpi@cvs.openbsd.org>2013-07-04 08:22:20 +0000
commit7b888444f73c10939da5e09e58c0d750db5a6426 (patch)
treecdfbd262ce4190d3edacf456ea4b8fb42e661097
parent2853d72618abd8407e6323f5090f60b69c1e6e5c (diff)
Rewrite the function used to determine if we do proxy ARP for one of
our addresses to reuse arplookup() and do only one list iteration. Looks ok to claudio@, ok mikeb@
-rw-r--r--sys/netinet/if_ether.c31
-rw-r--r--sys/netinet/if_ether.h3
-rw-r--r--sys/netinet/ip_input.c53
3 files changed, 34 insertions, 53 deletions
diff --git a/sys/netinet/if_ether.c b/sys/netinet/if_ether.c
index d2cd803b7b5..971c50844bc 100644
--- a/sys/netinet/if_ether.c
+++ b/sys/netinet/if_ether.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_ether.c,v 1.101 2013/03/28 23:10:05 tedu Exp $ */
+/* $OpenBSD: if_ether.c,v 1.102 2013/07/04 08:22:19 mpi Exp $ */
/* $NetBSD: if_ether.c,v 1.31 1996/05/11 12:59:58 mycroft Exp $ */
/*
@@ -853,6 +853,35 @@ arplookup(u_int32_t addr, int create, int proxy, u_int tableid)
return ((struct llinfo_arp *)rt->rt_llinfo);
}
+/*
+ * Check whether we do proxy ARP for this address and we point to ourselves.
+ */
+int
+arpproxy(struct in_addr in, u_int rdomain)
+{
+ struct llinfo_arp *la;
+ struct ifnet *ifp;
+ int found = 0;
+
+ la = arplookup(in.s_addr, 0, SIN_PROXY, rdomain);
+ if (la == NULL)
+ return (0);
+
+ TAILQ_FOREACH(ifp, &ifnet, if_list) {
+ if (ifp->if_rdomain != rdomain)
+ continue;
+
+ if (!bcmp(LLADDR((struct sockaddr_dl *)la->la_rt->rt_gateway),
+ LLADDR((struct sockaddr_dl *)ifp->if_lladdr->ifa_addr),
+ ETHER_ADDR_LEN)) {
+ found = 1;
+ break;
+ }
+ }
+
+ return (found);
+}
+
void
arp_ifinit(struct arpcom *ac, struct ifaddr *ifa)
{
diff --git a/sys/netinet/if_ether.h b/sys/netinet/if_ether.h
index 0b70ceb3f78..9c0d6a6344e 100644
--- a/sys/netinet/if_ether.h
+++ b/sys/netinet/if_ether.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_ether.h,v 1.49 2013/03/22 01:41:12 tedu Exp $ */
+/* $OpenBSD: if_ether.h,v 1.50 2013/07/04 08:22:19 mpi Exp $ */
/* $NetBSD: if_ether.h,v 1.22 1996/05/11 13:00:00 mycroft Exp $ */
/*
@@ -281,6 +281,7 @@ extern struct ifnet *revarp_ifp;
#endif /* NFSCLIENT */
void arprequest(struct ifnet *, u_int32_t *, u_int32_t *, u_int8_t *);
+int arpproxy(struct in_addr, u_int);
void revarpinput(struct mbuf *);
void in_revarpinput(struct mbuf *);
void revarprequest(struct ifnet *);
diff --git a/sys/netinet/ip_input.c b/sys/netinet/ip_input.c
index 01cc664f354..664afbfce34 100644
--- a/sys/netinet/ip_input.c
+++ b/sys/netinet/ip_input.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ip_input.c,v 1.213 2013/06/26 09:12:40 henning Exp $ */
+/* $OpenBSD: ip_input.c,v 1.214 2013/07/04 08:22:19 mpi Exp $ */
/* $NetBSD: ip_input.c,v 1.30 1996/03/16 23:53:58 christos Exp $ */
/*
@@ -158,7 +158,6 @@ static struct ip_srcrt {
} ip_srcrt;
void save_rte(u_char *, struct in_addr);
-int ip_weadvertise(u_int32_t, u_int);
/*
* IP initialization: fill in IP protocol switch table.
@@ -1288,53 +1287,6 @@ save_rte(u_char *option, struct in_addr dst)
}
/*
- * Check whether we do proxy ARP for this address and we point to ourselves.
- * Code shamelessly copied from arplookup().
- */
-int
-ip_weadvertise(u_int32_t addr, u_int rtableid)
-{
- struct rtentry *rt;
- struct ifnet *ifp;
- struct ifaddr *ifa;
- struct sockaddr_inarp sin;
-
- sin.sin_len = sizeof(sin);
- sin.sin_family = AF_INET;
- sin.sin_addr.s_addr = addr;
- sin.sin_other = SIN_PROXY;
- rt = rtalloc1((struct sockaddr *)&sin, 0, rtableid);
- if (rt == 0)
- return 0;
-
- if ((rt->rt_flags & RTF_GATEWAY) || (rt->rt_flags & RTF_LLINFO) == 0 ||
- rt->rt_gateway->sa_family != AF_LINK) {
- RTFREE(rt);
- return 0;
- }
-
- rtableid = rtable_l2(rtableid);
- TAILQ_FOREACH(ifp, &ifnet, if_list) {
- if (ifp->if_rdomain != rtableid)
- continue;
- TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_list) {
- if (ifa->ifa_addr->sa_family != rt->rt_gateway->sa_family)
- continue;
-
- if (!bcmp(LLADDR((struct sockaddr_dl *)ifa->ifa_addr),
- LLADDR((struct sockaddr_dl *)rt->rt_gateway),
- ETHER_ADDR_LEN)) {
- RTFREE(rt);
- return 1;
- }
- }
- }
-
- RTFREE(rt);
- return 0;
-}
-
-/*
* Retrieve incoming source route for use in replies,
* in the same form used by setsockopt.
* The first hop is placed before the options, will be removed later.
@@ -1534,8 +1486,7 @@ ip_forward(struct mbuf *m, int srcrt)
(rt->rt_flags & (RTF_DYNAMIC|RTF_MODIFIED)) == 0 &&
satosin(rt_key(rt))->sin_addr.s_addr != 0 &&
ipsendredirects && !srcrt &&
- !ip_weadvertise(satosin(rt_key(rt))->sin_addr.s_addr,
- m->m_pkthdr.rdomain)) {
+ !arpproxy(satosin(rt_key(rt))->sin_addr, m->m_pkthdr.rdomain)) {
if (rt->rt_ifa &&
(ip->ip_src.s_addr & ifatoia(rt->rt_ifa)->ia_netmask) ==
ifatoia(rt->rt_ifa)->ia_net) {