diff options
author | Martin Pieuchot <mpi@cvs.openbsd.org> | 2014-03-12 12:03:56 +0000 |
---|---|---|
committer | Martin Pieuchot <mpi@cvs.openbsd.org> | 2014-03-12 12:03:56 +0000 |
commit | 88d76b03ae05ca4c03666f56402d3079e59eb626 (patch) | |
tree | 8f814f684b1c97b0f6c5b42a41a50b6eb1ecf47f /sys | |
parent | 0a123fdb68214e34a0e616c7e271f81b35efb709 (diff) |
RTAX_IFP points to the "struct sockaddr_dl" corresponding to the
link-layer address of an interface. This ugly structure is used
to export the interface's name and index, not only the link-layer
address as its name might suggest.
So instead reaching this descriptor by forcing and abusing the
position of the link-layer "struct ifaddr" in the per-interface
list, use the if_sadl pointer directly.
ok mikeb@, henning@
Diffstat (limited to 'sys')
-rw-r--r-- | sys/net/route.c | 5 | ||||
-rw-r--r-- | sys/net/rtsock.c | 18 |
2 files changed, 11 insertions, 12 deletions
diff --git a/sys/net/route.c b/sys/net/route.c index 5479e5ac0fd..6a6c31c554f 100644 --- a/sys/net/route.c +++ b/sys/net/route.c @@ -1,4 +1,4 @@ -/* $OpenBSD: route.c,v 1.153 2014/02/12 12:50:13 mpi Exp $ */ +/* $OpenBSD: route.c,v 1.154 2014/03/12 12:03:55 mpi Exp $ */ /* $NetBSD: route.c,v 1.14 1996/02/13 22:00:46 christos Exp $ */ /* @@ -409,8 +409,7 @@ rt_sendmsg(struct rtentry *rt, int cmd, u_int rtableid) info.rti_info[RTAX_GATEWAY] = rt->rt_gateway; info.rti_info[RTAX_NETMASK] = rt_mask(rt); if (rt->rt_ifp != NULL) { - info.rti_info[RTAX_IFP] = - TAILQ_FIRST(&rt->rt_ifp->if_addrlist)->ifa_addr; + info.rti_info[RTAX_IFP] =(struct sockaddr *)rt->rt_ifp->if_sadl; info.rti_info[RTAX_IFA] = rt->rt_ifa->ifa_addr; } diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c index 9610e1e7721..ae41c80424b 100644 --- a/sys/net/rtsock.c +++ b/sys/net/rtsock.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtsock.c,v 1.139 2014/02/13 22:01:50 bluhm Exp $ */ +/* $OpenBSD: rtsock.c,v 1.140 2014/03/12 12:03:55 mpi Exp $ */ /* $NetBSD: rtsock.c,v 1.18 1996/03/29 00:32:10 cgd Exp $ */ /* @@ -706,7 +706,7 @@ report: if (rtm->rtm_addrs & (RTA_IFP | RTA_IFA) && (ifp = rt->rt_ifp) != NULL) { info.rti_info[RTAX_IFP] = - TAILQ_FIRST(&ifp->if_addrlist)->ifa_addr; + (struct sockaddr *)ifp->if_sadl; info.rti_info[RTAX_IFA] = rt->rt_ifa->ifa_addr; if (ifp->if_flags & IFF_POINTOPOINT) info.rti_info[RTAX_BRD] = @@ -1168,7 +1168,7 @@ rt_newaddrmsg(int cmd, struct ifaddr *ifa, int error, struct rtentry *rt) info.rti_info[RTAX_IFA] = sa = ifa->ifa_addr; info.rti_info[RTAX_IFP] = - TAILQ_FIRST(&ifp->if_addrlist)->ifa_addr; + (struct sockaddr *)ifp->if_sadl; info.rti_info[RTAX_NETMASK] = ifa->ifa_netmask; info.rti_info[RTAX_BRD] = ifa->ifa_dstaddr; if ((m = rt_msg1(ncmd, &info)) == NULL) @@ -1256,7 +1256,7 @@ sysctl_dumpentry(struct radix_node *rn, void *v, u_int id) info.rti_info[RTAX_NETMASK] = rt_mask(rt); if (rt->rt_ifp) { info.rti_info[RTAX_IFP] = - TAILQ_FIRST(&rt->rt_ifp->if_addrlist)->ifa_addr; + (struct sockaddr *)rt->rt_ifp->if_sadl; info.rti_info[RTAX_IFA] = rt->rt_ifa->ifa_addr; if (rt->rt_ifp->if_flags & IFF_POINTOPOINT) info.rti_info[RTAX_BRD] = rt->rt_ifa->ifa_dstaddr; @@ -1309,10 +1309,8 @@ sysctl_iflist(int af, struct walkarg *w) TAILQ_FOREACH(ifp, &ifnet, if_list) { if (w->w_arg && w->w_arg != ifp->if_index) continue; - ifa = TAILQ_FIRST(&ifp->if_addrlist); - if (!ifa) - continue; - info.rti_info[RTAX_IFP] = ifa->ifa_addr; + /* Copy the link-layer address first */ + info.rti_info[RTAX_IFP] = (struct sockaddr *)ifp->if_sadl; len = rt_msg2(RTM_IFINFO, RTM_VERSION, &info, 0, w); if (w->w_where && w->w_tmem && w->w_needed <= 0) { struct if_msghdr *ifm; @@ -1329,7 +1327,9 @@ sysctl_iflist(int af, struct walkarg *w) w->w_where += len; } info.rti_info[RTAX_IFP] = NULL; - while ((ifa = TAILQ_NEXT(ifa, ifa_list)) != NULL) { + TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_list) { + if (ifa->ifa_addr->sa_family == AF_LINK) + continue; if (af && af != ifa->ifa_addr->sa_family) continue; info.rti_info[RTAX_IFA] = ifa->ifa_addr; |