Re: Small in6_addr2scopeid() tweak

2015-07-07 Thread Todd C. Miller
On Tue, 07 Jul 2015 15:56:35 +0200, Martin Pieuchot wrote:

 Now that packet headers include the interface index of their receiving
 interface, pass it directly to in6_addr2scopeid().
 
 This does not change anything with regards to the scopeid hack but it
 reduces the number of if_get().

OK, but you should update the comment preceding the in6_addr2scopeid()
function.  It's probably best to just remove the:

 * ifp - must not be NULL

 - todd



Small in6_addr2scopeid() tweak

2015-07-07 Thread Martin Pieuchot
Now that packet headers include the interface index of their receiving
interface, pass it directly to in6_addr2scopeid().

This does not change anything with regards to the scopeid hack but it
reduces the number of if_get().

Ok?

Index: netinet/udp_usrreq.c
===
RCS file: /cvs/src/sys/netinet/udp_usrreq.c,v
retrieving revision 1.202
diff -u -p -r1.202 udp_usrreq.c
--- netinet/udp_usrreq.c30 Jun 2015 15:30:17 -  1.202
+++ netinet/udp_usrreq.c7 Jul 2015 13:52:42 -
@@ -757,8 +757,8 @@ udp6_ctlinput(int cmd, struct sockaddr *
sa6.sin6_len = sizeof(sa6);
sa6.sin6_addr = *ip6cp-ip6c_finaldst;
/* XXX: assuming M is valid in this case */
-   sa6.sin6_scope_id = in6_addr2scopeid(
-   if_get(m-m_pkthdr.ph_ifidx), ip6cp-ip6c_finaldst);
+   sa6.sin6_scope_id = in6_addr2scopeid(m-m_pkthdr.ph_ifidx,
+   ip6cp-ip6c_finaldst);
if (in6_embedscope(ip6cp-ip6c_finaldst, sa6, NULL, NULL)) {
/* should be impossible */
return;
@@ -790,8 +790,8 @@ udp6_ctlinput(int cmd, struct sockaddr *
sa6_src.sin6_family = AF_INET6;
sa6_src.sin6_len = sizeof(sa6_src);
sa6_src.sin6_addr = ip6-ip6_src;
-   sa6_src.sin6_scope_id = in6_addr2scopeid(
-   if_get(m-m_pkthdr.ph_ifidx), ip6-ip6_src);
+   sa6_src.sin6_scope_id = in6_addr2scopeid(m-m_pkthdr.ph_ifidx,
+   ip6-ip6_src);
if (in6_embedscope(sa6_src.sin6_addr, sa6_src, NULL, NULL)) {
/* should be impossible */
return;
Index: netinet6/icmp6.c
===
RCS file: /cvs/src/sys/netinet6/icmp6.c,v
retrieving revision 1.160
diff -u -p -r1.160 icmp6.c
--- netinet6/icmp6.c30 Jun 2015 15:30:17 -  1.160
+++ netinet6/icmp6.c7 Jul 2015 13:52:42 -
@@ -928,8 +928,8 @@ icmp6_notify_error(struct mbuf *m, int o
icmp6dst.sin6_addr = eip6-ip6_dst;
else
icmp6dst.sin6_addr = *finaldst;
-   icmp6dst.sin6_scope_id = in6_addr2scopeid(
-   if_get(m-m_pkthdr.ph_ifidx), icmp6dst.sin6_addr);
+   icmp6dst.sin6_scope_id = in6_addr2scopeid(m-m_pkthdr.ph_ifidx,
+   icmp6dst.sin6_addr);
if (in6_embedscope(icmp6dst.sin6_addr, icmp6dst,
   NULL, NULL)) {
/* should be impossbile */
@@ -946,8 +946,8 @@ icmp6_notify_error(struct mbuf *m, int o
icmp6src.sin6_len = sizeof(struct sockaddr_in6);
icmp6src.sin6_family = AF_INET6;
icmp6src.sin6_addr = eip6-ip6_src;
-   icmp6src.sin6_scope_id = in6_addr2scopeid(
-   if_get(m-m_pkthdr.ph_ifidx), icmp6src.sin6_addr);
+   icmp6src.sin6_scope_id = in6_addr2scopeid(m-m_pkthdr.ph_ifidx,
+   icmp6src.sin6_addr);
if (in6_embedscope(icmp6src.sin6_addr, icmp6src,
   NULL, NULL)) {
/* should be impossbile */
@@ -1034,7 +1034,7 @@ icmp6_mtudisc_update(struct ip6ctlparam 
if (IN6_IS_ADDR_LINKLOCAL(dst)) {
sin6.sin6_addr.s6_addr16[1] = htons(m-m_pkthdr.ph_ifidx);
}
-   sin6.sin6_scope_id = in6_addr2scopeid(if_get(m-m_pkthdr.ph_ifidx),
+   sin6.sin6_scope_id = in6_addr2scopeid(m-m_pkthdr.ph_ifidx,
sin6.sin6_addr);
 
rt = icmp6_mtudisc_clone(sin6tosa(sin6), m-m_pkthdr.ph_rtableid);
@@ -1610,7 +1610,7 @@ icmp6_redirect_output(struct mbuf *m0, s
src_sa.sin6_len = sizeof(src_sa);
src_sa.sin6_addr = sip6-ip6_src;
/* we don't currently use sin6_scope_id, but eventually use it */
-   src_sa.sin6_scope_id = in6_addr2scopeid(ifp, sip6-ip6_src);
+   src_sa.sin6_scope_id = in6_addr2scopeid(ifp-if_index, sip6-ip6_src);
if (nd6_is_addr_neighbor(src_sa, ifp) == 0)
goto fail;
if (IN6_IS_ADDR_MULTICAST(sip6-ip6_dst))
Index: netinet6/in6.c
===
RCS file: /cvs/src/sys/netinet6/in6.c,v
retrieving revision 1.159
diff -u -p -r1.159 in6.c
--- netinet6/in6.c  8 Jun 2015 22:19:27 -   1.159
+++ netinet6/in6.c  7 Jul 2015 13:52:42 -
@@ -1671,7 +1671,7 @@ in6_addrscope(struct in6_addr *addr)
  */
 
 int
-in6_addr2scopeid(struct ifnet *ifp, struct in6_addr *addr)
+in6_addr2scopeid(unsigned int ifidx, struct in6_addr *addr)
 {
int scope = in6_addrscope(addr);
 
@@ -1679,7 +1679,7 @@ in6_addr2scopeid(struct ifnet *ifp, stru
case __IPV6_ADDR_SCOPE_INTFACELOCAL:
case __IPV6_ADDR_SCOPE_LINKLOCAL:
/* XXX: we do not distinguish between