Skip to content

Commit

Permalink
This main goals of this project are:
Browse files Browse the repository at this point in the history
1. separating L2 tables (ARP, NDP) from the L3 routing tables
2. removing as much locking dependencies among these layers as
   possible to allow for some parallelism in the search operations
3. simplify the logic in the routing code,

The most notable end result is the obsolescent of the route
cloning (RTF_CLONING) concept, which translated into code reduction
in both IPv4 ARP and IPv6 NDP related modules, and size reduction in
struct rtentry{}. The change in design obsoletes the semantics of
RTF_CLONING, RTF_WASCLONE and RTF_LLINFO routing flags. The userland
applications such as "arp" and "ndp" have been modified to reflect
those changes. The output from "netstat -r" shows only the routing
entries.

Quite a few developers have contributed to this project in the
past: Glebius Smirnoff, Luigi Rizzo, Alessandro Cerri, and
Andre Oppermann. And most recently:

- Kip Macy revised the locking code completely, thus completing
  the last piece of the puzzle, Kip has also been conducting
  active functional testing
- Sam Leffler has helped me improving/refactoring the code, and
  provided valuable reviews
- Julian Elischer setup the perforce tree for me and has helped
  me maintaining that branch before the svn conversion
  • Loading branch information
qingli authored and qingli committed Dec 15, 2008
1 parent 664c3ae commit ec826ad
Show file tree
Hide file tree
Showing 66 changed files with 1,636 additions and 2,471 deletions.
9 changes: 9 additions & 0 deletions UPDATING
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ NOTE TO PEOPLE WHO THINK THAT FreeBSD 8.x IS SLOW:
to maximize performance. (To disable malloc debugging, run
ln -s aj /etc/malloc.conf.)

20081214:
__FreeBSD_version 800059 incorporates the new arp-v2 rewrite.
RTF_CLONING, RTF_LLINFO and RTF_WASCLONED flags are eliminated.
The new code reduced struct rtentry{} by 16 bytes on 32-bit
architecture and 40 bytes on 64-bit architecture. The userland
applications "arp" and "ndp" have been updated accordingly.
The output from "netstat -r" shows only routing entries and
none of the L2 information.

20081130:
__FreeBSD_version 800057 marks the switchover from the
binary ath hal to source code. Users must add the line:
Expand Down
83 changes: 9 additions & 74 deletions contrib/bsnmp/snmp_mibII/mibII.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ static void *route_fd;
/* if-index allocator */
static uint32_t next_if_index = 1;

/* re-fetch arp table */
static int update_arp;
/* currently fetching the arp table */
static int in_update_arp;

/* OR registrations */
Expand Down Expand Up @@ -910,36 +909,6 @@ mib_find_ifa(struct in_addr addr)
return (NULL);
}

/*
* Process a new ARP entry
*/
static void
process_arp(const struct rt_msghdr *rtm, const struct sockaddr_dl *sdl,
const struct sockaddr_in *sa)
{
struct mibif *ifp;
struct mibarp *at;

/* IP arp table entry */
if (sdl->sdl_alen == 0) {
update_arp = 1;
return;
}
if ((ifp = mib_find_if_sys(sdl->sdl_index)) == NULL)
return;
/* have a valid entry */
if ((at = mib_find_arp(ifp, sa->sin_addr)) == NULL &&
(at = mib_arp_create(ifp, sa->sin_addr,
sdl->sdl_data + sdl->sdl_nlen, sdl->sdl_alen)) == NULL)
return;

if (rtm->rtm_rmx.rmx_expire == 0)
at->flags |= MIBARP_PERM;
else
at->flags &= ~MIBARP_PERM;
at->flags |= MIBARP_FOUND;
}

/*
* Handle a routing socket message.
*/
Expand Down Expand Up @@ -1080,46 +1049,12 @@ handle_rtmsg(struct rt_msghdr *rtm)
}
break;
#endif

case RTM_GET:
mib_extract_addrs(rtm->rtm_addrs, (u_char *)(rtm + 1), addrs);
if (rtm->rtm_flags & RTF_LLINFO) {
if (addrs[RTAX_DST] == NULL ||
addrs[RTAX_GATEWAY] == NULL ||
addrs[RTAX_DST]->sa_family != AF_INET ||
addrs[RTAX_GATEWAY]->sa_family != AF_LINK)
break;
process_arp(rtm,
(struct sockaddr_dl *)(void *)addrs[RTAX_GATEWAY],
(struct sockaddr_in *)(void *)addrs[RTAX_DST]);
} else {
if (rtm->rtm_errno == 0 && (rtm->rtm_flags & RTF_UP))
mib_sroute_process(rtm, addrs[RTAX_GATEWAY],
addrs[RTAX_DST], addrs[RTAX_NETMASK]);
}
break;

case RTM_ADD:
mib_extract_addrs(rtm->rtm_addrs, (u_char *)(rtm + 1), addrs);
if (rtm->rtm_flags & RTF_LLINFO) {
if (addrs[RTAX_DST] == NULL ||
addrs[RTAX_GATEWAY] == NULL ||
addrs[RTAX_DST]->sa_family != AF_INET ||
addrs[RTAX_GATEWAY]->sa_family != AF_LINK)
break;
process_arp(rtm,
(struct sockaddr_dl *)(void *)addrs[RTAX_GATEWAY],
(struct sockaddr_in *)(void *)addrs[RTAX_DST]);
} else {
if (rtm->rtm_errno == 0 && (rtm->rtm_flags & RTF_UP))
mib_sroute_process(rtm, addrs[RTAX_GATEWAY],
addrs[RTAX_DST], addrs[RTAX_NETMASK]);
}
break;

case RTM_DELETE:
mib_extract_addrs(rtm->rtm_addrs, (u_char *)(rtm + 1), addrs);
if (rtm->rtm_errno == 0 && !(rtm->rtm_flags & RTF_LLINFO))

if (rtm->rtm_errno == 0 && (rtm->rtm_flags & RTF_UP))
mib_sroute_process(rtm, addrs[RTAX_GATEWAY],
addrs[RTAX_DST], addrs[RTAX_NETMASK]);
break;
Expand Down Expand Up @@ -1289,7 +1224,8 @@ update_ifa_info(void)

/*
* Update arp table
*/
*
*/
void
mib_arp_update(void)
{
Expand All @@ -1305,11 +1241,11 @@ mib_arp_update(void)
TAILQ_FOREACH(at, &mibarp_list, link)
at->flags &= ~MIBARP_FOUND;

if ((buf = mib_fetch_rtab(AF_INET, NET_RT_FLAGS, RTF_LLINFO, &needed)) == NULL) {
if ((buf = mib_fetch_rtab(AF_INET, NET_RT_FLAGS, 0, &needed)) == NULL) {
in_update_arp = 0;
return;
}

next = buf;
while (next < buf + needed) {
rtm = (struct rt_msghdr *)(void *)next;
Expand All @@ -1326,7 +1262,6 @@ mib_arp_update(void)
at = at1;
}
mibarpticks = get_ticks();
update_arp = 0;
in_update_arp = 0;
}

Expand Down Expand Up @@ -1634,8 +1569,8 @@ mibII_idle(void)
mib_arp_update();
mib_iflist_bad = 0;
}
if (update_arp)
mib_arp_update();

mib_arp_update();
}


Expand Down
3 changes: 1 addition & 2 deletions contrib/bsnmp/snmp_mibII/mibII_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,7 @@ mib_sroute_process(struct rt_msghdr *rtm, struct sockaddr *gw,
memcpy(r->index, key.index, sizeof(r->index));
r->ifindex = (ifp == NULL) ? 0 : ifp->index;

r->type = (rtm->rtm_flags & RTF_LLINFO) ? 3 :
(rtm->rtm_flags & RTF_REJECT) ? 2 : 4;
r->type = (rtm->rtm_flags & RTF_REJECT) ? 2 : 4;

/* cannot really know, what protocol it runs */
r->proto = (rtm->rtm_flags & RTF_LOCAL) ? 2 :
Expand Down
5 changes: 5 additions & 0 deletions contrib/ipfilter/ipsend/44arp.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,12 @@ char *addr, *eaddr;
mib[2] = 0;
mib[3] = AF_INET;
mib[4] = NET_RT_FLAGS;
#ifdef RTF_LLINFO
mib[5] = RTF_LLINFO;
#else
mib[5] = 0;
#endif

if (sysctl(mib, 6, NULL, &needed, NULL, 0) == -1)
{
perror("route-sysctl-estimate");
Expand Down
4 changes: 2 additions & 2 deletions lib/libstand/if_ether.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ struct ifqueue arpintrq;
void arpwhohas(struct arpcom *, struct in_addr *);
void arpintr(void);
int arpresolve(struct arpcom *,
struct rtentry *, struct mbuf *, struct sockaddr *, u_char *);
struct rtentry *, struct mbuf *, struct sockaddr *, u_char *, struct llentry **);
void arp_ifinit(struct arpcom *, struct ifaddr *);
void arp_rtrequest(int, struct rtentry *, struct sockaddr *);

Expand Down Expand Up @@ -233,7 +233,7 @@ struct ether_multistep {
#ifdef _KERNEL
void arp_rtrequest(int, struct rtentry *, struct sockaddr *);
int arpresolve(struct arpcom *, struct rtentry *, struct mbuf *,
struct sockaddr *, u_char *);
struct sockaddr *, u_char *, struct llentry **);
void arpintr(void);
int arpioctl(u_long, caddr_t);
void arp_ifinit(struct arpcom *, struct ifaddr *);
Expand Down
1 change: 0 additions & 1 deletion libexec/bootpd/rtmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ int bsd_arp_set(ia, eaddr, len)
sdl = (struct sockaddr_dl *)(sin->sin_len + (char *)sin);
if (sin->sin_addr.s_addr == sin_m.sin_addr.s_addr) {
if (sdl->sdl_family == AF_LINK &&
(rtm->rtm_flags & RTF_LLINFO) &&
!(rtm->rtm_flags & RTF_GATEWAY)) switch (sdl->sdl_type) {
case IFT_ETHER: case IFT_FDDI: case IFT_ISO88023:
case IFT_ISO88024: case IFT_ISO88025:
Expand Down
4 changes: 0 additions & 4 deletions release/picobsd/tinyware/ns/ns.c
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,6 @@ print_routing(char *proto)
rtm = (struct rt_msghdr *)next;
sa = (struct sockaddr *)(rtm + 1);
get_rtaddrs(rtm->rtm_addrs, sa, rti_info);
if (rtm->rtm_flags & RTF_WASCLONED) {
if ((rtm->rtm_flags & RTF_LLINFO) == 0)
continue;
}
if ((sa = rti_info[RTAX_DST]) != NULL) {
sprintf(fbuf, "%s", sock_ntop(sa, sa->sa_len));
if (((sa1 = rti_info[RTAX_NETMASK]) != NULL)
Expand Down
6 changes: 0 additions & 6 deletions sbin/route/route.c
Original file line number Diff line number Diff line change
Expand Up @@ -605,9 +605,6 @@ newroute(argc, argv)
case K_NOSTATIC:
flags &= ~RTF_STATIC;
break;
case K_LLINFO:
flags |= RTF_LLINFO;
break;
case K_LOCK:
locking = 1;
break;
Expand All @@ -632,9 +629,6 @@ newroute(argc, argv)
case K_PROXY:
proxy = 1;
break;
case K_CLONING:
flags |= RTF_CLONING;
break;
case K_XRESOLVE:
flags |= RTF_XRESOLVE;
break;
Expand Down
7 changes: 5 additions & 2 deletions sbin/routed/table.c
Original file line number Diff line number Diff line change
Expand Up @@ -1103,12 +1103,13 @@ flush_kern(void)
|| INFO_DST(&info)->sa_family != AF_INET)
continue;

#if defined (RTF_LLINFO)
/* ignore ARP table entries on systems with a merged route
* and ARP table.
*/
if (rtm->rtm_flags & RTF_LLINFO)
continue;

#endif
#if defined(RTF_WASCLONED) && defined(__FreeBSD__)
/* ignore cloned routes
*/
Expand Down Expand Up @@ -1261,11 +1262,13 @@ read_rt(void)
continue;
}

#if defined(RTF_LLINFO)
if (m.r.rtm.rtm_flags & RTF_LLINFO) {
trace_act("ignore ARP %s", str);
continue;
}

#endif

#if defined(RTF_WASCLONED) && defined(__FreeBSD__)
if (m.r.rtm.rtm_flags & RTF_WASCLONED) {
trace_act("ignore cloned %s", str);
Expand Down
4 changes: 2 additions & 2 deletions share/man/man4/route.4
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ Messages include:
#define RTM_REDIRECT 0x6 /* Told to use different route */
#define RTM_MISS 0x7 /* Lookup failed on this address */
#define RTM_LOCK 0x8 /* fix specified metrics */
#define RTM_RESOLVE 0xb /* request to resolve dst to LL addr */
#define RTM_RESOLVE 0xb /* request to resolve dst to LL addr - unused */
#define RTM_NEWADDR 0xc /* address being added to iface */
#define RTM_DELADDR 0xd /* address being removed from iface */
#define RTM_IFINFO 0xe /* iface going up/down etc. */
Expand Down Expand Up @@ -308,7 +308,7 @@ Specifiers for which addresses are present in the messages are:
#define RTA_DST 0x1 /* destination sockaddr present */
#define RTA_GATEWAY 0x2 /* gateway sockaddr present */
#define RTA_NETMASK 0x4 /* netmask sockaddr present */
#define RTA_GENMASK 0x8 /* cloning mask sockaddr present */
#define RTA_GENMASK 0x8 /* cloning mask sockaddr present - unused */
#define RTA_IFP 0x10 /* interface name sockaddr present */
#define RTA_IFA 0x20 /* interface addr sockaddr present */
#define RTA_AUTHOR 0x40 /* sockaddr for author of redirect */
Expand Down
46 changes: 10 additions & 36 deletions share/man/man9/rtalloc.9
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
.\" SUCH DAMAGE.
.\"
.\" $FreeBSD$
.Dd October 11, 2004
.\"
.Dd December 11, 2008
.Os
.Dt RTALLOC 9
.Sh NAME
Expand Down Expand Up @@ -64,21 +65,6 @@ certain protocol\- and interface-specific actions to take place.
.\" XXX - -mdoc should contain a standard request for getting em and
.\" en dashes.
.Pp
When a route with the flag
.Dv RTF_CLONING
is retrieved, and the action of this flag is not masked, the
.Nm
facility automatically generates a new route using information in the
old route as a template, and
sends an
.Dv RTM_RESOLVE
message to the appropriate interface-address route-management routine
.Pq Fn ifa->ifa_rtrequest .
This generated route is called
.Em cloned ,
and has
.Dv RTF_WASCLONED
flag set.
.Dv RTF_PRCLONING
flag is obsolete and thus ignored by facility.
If the
Expand Down Expand Up @@ -123,22 +109,19 @@ field.
.Pp
The
.Fn rtalloc_ign
interface can be used when the default actions of
.Fn rtalloc
in the presence of the
.Dv RTF_CLONING
flag is undesired.
interface can be used when the caller does not want to receive
the returned
.Fa rtentry
locked.
The
.Fa ro
argument is the same as
.Fn rtalloc ,
but there is additionally a
.Fa flags
argument, which lists the flags in the route which are to be
.Em ignored
(in most cases this is
.Dv RTF_CLONING
flag).
argument, which is now only used to pass
.Dv RTF_RNH_LOCKED
indicating that the radix tree lock is already held.
Both
.Fn rtalloc
and
Expand All @@ -163,16 +146,7 @@ directly as the
argument.
The second argument,
.Fa report ,
controls whether
.Dv RTM_RESOLVE
requests are sent to the lower layers when an
.Dv RTF_CLONING
or
.Dv RTF_PRCLONING
route is cloned.
Ordinarily a value of one should be passed, except
in the processing of those lower layers which use the cloning
facility.
controls whether the lower layers are notified when a lookup fails.
The third argument,
.Fa flags ,
is a set of flags to ignore, as in
Expand Down
Loading

0 comments on commit ec826ad

Please sign in to comment.