Subject: carp(4) patch
To: None <tech-net@netbsd.org>
From: David Young <dyoung@pobox.com>
List: tech-net
Date: 06/08/2007 21:54:50
--W/nzBZO5zC0uMSeA
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
I am trying to hide the radix-trie implementation of our forwarding
table from our networking code. Here is what I have done with carp(4).
Look ok? Is anyone able to test really quick?
Dave
--
David Young OJC Technologies
dyoung@ojctech.com Urbana, IL * (217) 278-3933 ext 24
--W/nzBZO5zC0uMSeA
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="carp.patch"
Index: sys/net/route.c
===================================================================
RCS file: /cvsroot/src/sys/net/route.c,v
retrieving revision 1.91
diff -p -u -u -p -r1.91 route.c
--- sys/net/route.c 6 May 2007 02:17:54 -0000 1.91
+++ sys/net/route.c 9 Jun 2007 02:52:15 -0000
@@ -797,10 +794,20 @@ rtrequest1(int req, struct rt_addrinfo *
}
if ((rt->rt_flags & RTF_CLONING) != 0) {
/* clean up any cloned children */
rtflushclone(rnh, rt);
}
rtflushall(dst->sa_family);
break;
+ case RTM_GET:
+ rn = rnh->rnh_lookup(dst, netmask, rnh);
+ if (rn == NULL || (rn->rn_flags & RNF_ROOT) != 0)
+ senderr(ESRCH);
+ if (ret_nrt != NULL) {
+ rt = (struct rtentry *)rn;
+ *ret_nrt = rt;
+ rt->rt_refcnt++;
+ }
+ break;
}
bad:
splx(s);
Index: sys/netinet/ip_carp.c
===================================================================
RCS file: /cvsroot/src/sys/netinet/ip_carp.c,v
retrieving revision 1.12
diff -p -u -u -p -r1.12 ip_carp.c
--- sys/netinet/ip_carp.c 4 Mar 2007 06:03:20 -0000 1.12
+++ sys/netinet/ip_carp.c 9 Jun 2007 02:50:22 -0000
@@ -346,9 +346,6 @@ carp_setroute(struct carp_softc *sc, int
int count = 0;
struct sockaddr sa;
struct rtentry *rt;
- struct radix_node_head *rnh =
- rt_tables[ifa->ifa_addr->sa_family];
- struct radix_node *rn;
int hr_otherif, nr_ourif;
/*
@@ -371,18 +368,24 @@ carp_setroute(struct carp_softc *sc, int
ifa->ifa_addr, ifa->ifa_netmask,
RTF_HOST, NULL);
- /* Check for our address on another interface */
- rn = rnh->rnh_matchaddr(ifa->ifa_addr, rnh);
- rt = (struct rtentry *)rn;
+ rt = NULL;
+ (void)rtrequest(RTM_GET, ifa->ifa_addr, ifa->ifa_addr,
+ ifa->ifa_netmask, RTF_HOST, &rt);
hr_otherif = (rt && rt->rt_ifp != &sc->sc_if &&
rt->rt_flags & (RTF_CLONING|RTF_CLONED));
+ if (rt != NULL) {
+ RTFREE(rt);
+ rt = NULL;
+ }
/* Check for a network route on our interface */
bcopy(ifa->ifa_addr, &sa, sizeof(sa));
satosin(&sa)->sin_addr.s_addr = satosin(ifa->ifa_netmask
)->sin_addr.s_addr & satosin(&sa)->sin_addr.s_addr;
- rn = rnh->rnh_lookup(&sa, ifa->ifa_netmask, rnh);
- rt = (struct rtentry *)rn;
+
+ rt = NULL;
+ (void)rtrequest(RTM_GET, &sa, ifa->ifa_addr,
+ ifa->ifa_netmask, 0, &rt);
nr_ourif = (rt && rt->rt_ifp == &sc->sc_if);
switch (cmd) {
@@ -416,6 +419,10 @@ carp_setroute(struct carp_softc *sc, int
default:
break;
}
+ if (rt != NULL) {
+ RTFREE(rt);
+ rt = NULL;
+ }
break;
}
--W/nzBZO5zC0uMSeA--