in6_embedscope() needs to lose some weight. Remove the last argument. In all but two calls NULL is passed and in the other 2 cases the ifp is only used to maybe feed it to in6_selecthlim() to select the hoplimit for the link. Since in6_embedscope() only works on link-local addresses it does not matter what hop limit we select since the destination is directly reachable. This makes our lives a lot easier.
OK? -- :wq Claudio Index: net/pfkeyv2_convert.c =================================================================== RCS file: /cvs/src/sys/net/pfkeyv2_convert.c,v retrieving revision 1.54 diff -u -p -r1.54 pfkeyv2_convert.c --- net/pfkeyv2_convert.c 11 Jun 2015 15:59:17 -0000 1.54 +++ net/pfkeyv2_convert.c 10 Sep 2015 19:12:38 -0000 @@ -483,9 +483,9 @@ import_flow(struct sockaddr_encap *flow, #ifdef INET6 case AF_INET6: in6_embedscope(&src->sin6.sin6_addr, &src->sin6, - NULL, NULL); + NULL); in6_embedscope(&dst->sin6.sin6_addr, &dst->sin6, - NULL, NULL); + NULL); /* netmask handling */ rt_maskedcopy(&src->sa, &src->sa, &srcmask->sa); Index: net/pipex.c =================================================================== RCS file: /cvs/src/sys/net/pipex.c,v retrieving revision 1.76 diff -u -p -r1.76 pipex.c --- net/pipex.c 10 Sep 2015 17:52:05 -0000 1.76 +++ net/pipex.c 10 Sep 2015 19:12:38 -0000 @@ -1976,7 +1976,7 @@ pipex_l2tp_output(struct mbuf *m0, struc ip6->ip6_nxt = IPPROTO_UDP; ip6->ip6_src = session->local.sin6.sin6_addr; (void)in6_embedscope(&ip6->ip6_dst, - &session->peer.sin6, NULL, NULL); + &session->peer.sin6, NULL); /* ip6->ip6_plen will be filled in ip6_output. */ if (ip6_output(m0, NULL, NULL, 0, NULL, NULL, NULL) != 0) { Index: netinet/ip_ipip.c =================================================================== RCS file: /cvs/src/sys/netinet/ip_ipip.c,v retrieving revision 1.66 diff -u -p -r1.66 ip_ipip.c --- netinet/ip_ipip.c 9 Sep 2015 20:19:26 -0000 1.66 +++ netinet/ip_ipip.c 10 Sep 2015 19:12:38 -0000 @@ -517,8 +517,8 @@ ipip_output(struct mbuf *m, struct tdb * ip6o->ip6_vfc |= IPV6_VERSION; ip6o->ip6_plen = htons(m->m_pkthdr.len - sizeof(*ip6o)); ip6o->ip6_hlim = ip_defttl; - in6_embedscope(&ip6o->ip6_src, &tdb->tdb_src.sin6, NULL, NULL); - in6_embedscope(&ip6o->ip6_dst, &tdb->tdb_dst.sin6, NULL, NULL); + in6_embedscope(&ip6o->ip6_src, &tdb->tdb_src.sin6, NULL); + in6_embedscope(&ip6o->ip6_dst, &tdb->tdb_dst.sin6, NULL); if (tp == IPVERSION) { /* Save ECN notification */ Index: netinet/tcp_usrreq.c =================================================================== RCS file: /cvs/src/sys/netinet/tcp_usrreq.c,v retrieving revision 1.127 diff -u -p -r1.127 tcp_usrreq.c --- netinet/tcp_usrreq.c 27 Aug 2015 17:10:45 -0000 1.127 +++ netinet/tcp_usrreq.c 10 Sep 2015 19:12:38 -0000 @@ -794,11 +794,11 @@ tcp_ident(void *oldp, size_t *oldlenp, v #ifdef INET6 case AF_INET6: fin6 = (struct sockaddr_in6 *)&tir.faddr; - error = in6_embedscope(&f6, fin6, NULL, NULL); + error = in6_embedscope(&f6, fin6, NULL); if (error) return EINVAL; /*?*/ lin6 = (struct sockaddr_in6 *)&tir.laddr; - error = in6_embedscope(&l6, lin6, NULL, NULL); + error = in6_embedscope(&l6, lin6, NULL); if (error) return EINVAL; /*?*/ break; Index: netinet/udp_usrreq.c =================================================================== RCS file: /cvs/src/sys/netinet/udp_usrreq.c,v retrieving revision 1.206 diff -u -p -r1.206 udp_usrreq.c --- netinet/udp_usrreq.c 10 Sep 2015 17:52:05 -0000 1.206 +++ netinet/udp_usrreq.c 10 Sep 2015 19:12:38 -0000 @@ -742,7 +742,7 @@ udp6_ctlinput(int cmd, struct sockaddr * cmdarg = NULL; /* XXX: translate addresses into internal form */ sa6 = *satosin6(sa); - if (in6_embedscope(&sa6.sin6_addr, &sa6, NULL, NULL)) { + if (in6_embedscope(&sa6.sin6_addr, &sa6, NULL)) { /* should be impossible */ return; } @@ -756,14 +756,14 @@ udp6_ctlinput(int cmd, struct sockaddr * /* XXX: assuming M is valid in this case */ sa6.sin6_scope_id = in6_addr2scopeid(m->m_pkthdr.ph_ifidx, ip6cp->ip6c_finaldst); - if (in6_embedscope(ip6cp->ip6c_finaldst, &sa6, NULL, NULL)) { + if (in6_embedscope(ip6cp->ip6c_finaldst, &sa6, NULL)) { /* should be impossible */ return; } } else { /* XXX: translate addresses into internal form */ sa6 = *satosin6(sa); - if (in6_embedscope(&sa6.sin6_addr, &sa6, NULL, NULL)) { + if (in6_embedscope(&sa6.sin6_addr, &sa6, NULL)) { /* should be impossible */ return; } @@ -789,7 +789,7 @@ udp6_ctlinput(int cmd, struct sockaddr * sa6_src.sin6_addr = 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)) { + if (in6_embedscope(&sa6_src.sin6_addr, &sa6_src, NULL)) { /* should be impossible */ return; } Index: netinet6/icmp6.c =================================================================== RCS file: /cvs/src/sys/netinet6/icmp6.c,v retrieving revision 1.165 diff -u -p -r1.165 icmp6.c --- netinet6/icmp6.c 10 Sep 2015 17:52:05 -0000 1.165 +++ netinet6/icmp6.c 10 Sep 2015 19:12:38 -0000 @@ -908,8 +908,7 @@ icmp6_notify_error(struct mbuf *m, int o icmp6dst.sin6_addr = *finaldst; icmp6dst.sin6_scope_id = in6_addr2scopeid(m->m_pkthdr.ph_ifidx, &icmp6dst.sin6_addr); - if (in6_embedscope(&icmp6dst.sin6_addr, &icmp6dst, - NULL, NULL)) { + if (in6_embedscope(&icmp6dst.sin6_addr, &icmp6dst, NULL)) { /* should be impossbile */ nd6log((LOG_DEBUG, "icmp6_notify_error: in6_embedscope failed\n")); @@ -926,8 +925,7 @@ icmp6_notify_error(struct mbuf *m, int o icmp6src.sin6_addr = eip6->ip6_src; icmp6src.sin6_scope_id = in6_addr2scopeid(m->m_pkthdr.ph_ifidx, &icmp6src.sin6_addr); - if (in6_embedscope(&icmp6src.sin6_addr, &icmp6src, - NULL, NULL)) { + if (in6_embedscope(&icmp6src.sin6_addr, &icmp6src, NULL)) { /* should be impossbile */ nd6log((LOG_DEBUG, "icmp6_notify_error: in6_embedscope failed\n")); @@ -1217,13 +1215,13 @@ icmp6_reflect(struct mbuf *m, size_t off sa6_src.sin6_len = sizeof(sa6_src); sa6_src.sin6_addr = ip6->ip6_dst; in6_recoverscope(&sa6_src, &ip6->ip6_dst); - in6_embedscope(&ip6->ip6_dst, &sa6_src, NULL, NULL); + in6_embedscope(&ip6->ip6_dst, &sa6_src, NULL); bzero(&sa6_dst, sizeof(sa6_dst)); sa6_dst.sin6_family = AF_INET6; sa6_dst.sin6_len = sizeof(sa6_dst); sa6_dst.sin6_addr = t; in6_recoverscope(&sa6_dst, &t); - in6_embedscope(&t, &sa6_dst, NULL, NULL); + in6_embedscope(&t, &sa6_dst, NULL); /* * If the incoming packet was addressed directly to us (i.e. unicast), Index: netinet6/in6.h =================================================================== RCS file: /cvs/src/sys/netinet6/in6.h,v retrieving revision 1.84 diff -u -p -r1.84 in6.h --- netinet6/in6.h 10 Sep 2015 17:52:05 -0000 1.84 +++ netinet6/in6.h 10 Sep 2015 19:12:38 -0000 @@ -436,7 +436,7 @@ int in6_mask2len(struct in6_addr *, u_ch struct inpcb; int in6_embedscope(struct in6_addr *, const struct sockaddr_in6 *, - struct inpcb *, struct ifnet **); + struct inpcb *); void in6_recoverscope(struct sockaddr_in6 *, const struct in6_addr *); void in6_clearscope(struct in6_addr *); Index: netinet6/in6_pcb.c =================================================================== RCS file: /cvs/src/sys/netinet6/in6_pcb.c,v retrieving revision 1.71 diff -u -p -r1.71 in6_pcb.c --- netinet6/in6_pcb.c 10 Sep 2015 17:52:05 -0000 1.71 +++ netinet6/in6_pcb.c 10 Sep 2015 19:12:38 -0000 @@ -194,7 +194,7 @@ in6_pcbbind(struct inpcb *inp, struct mb return EAFNOSUPPORT; /* KAME hack: embed scopeid */ - if (in6_embedscope(&sin6->sin6_addr, sin6, inp, NULL) != 0) + if (in6_embedscope(&sin6->sin6_addr, sin6, inp) != 0) return EINVAL; /* this must be cleared for ifa_ifwithaddr() */ sin6->sin6_scope_id = 0; @@ -418,7 +418,7 @@ in6_pcbconnect(struct inpcb *inp, struct sin6 = &tmp; /* KAME hack: embed scopeid */ - if (in6_embedscope(&sin6->sin6_addr, sin6, inp, &ifp) != 0) + if (in6_embedscope(&sin6->sin6_addr, sin6, inp) != 0) return EINVAL; /* this must be cleared for ifa_ifwithaddr() */ sin6->sin6_scope_id = 0; Index: netinet6/in6_src.c =================================================================== RCS file: /cvs/src/sys/netinet6/in6_src.c,v retrieving revision 1.56 diff -u -p -r1.56 in6_src.c --- netinet6/in6_src.c 10 Sep 2015 17:52:05 -0000 1.56 +++ netinet6/in6_src.c 10 Sep 2015 19:12:38 -0000 @@ -586,15 +586,13 @@ in6_selecthlim(struct inpcb *in6p, struc */ int in6_embedscope(struct in6_addr *in6, const struct sockaddr_in6 *sin6, - struct inpcb *in6p, struct ifnet **ifpp) + struct inpcb *in6p) { struct ifnet *ifp = NULL; u_int32_t scopeid; *in6 = sin6->sin6_addr; scopeid = sin6->sin6_scope_id; - if (ifpp) - *ifpp = NULL; /* * don't try to read sin6->sin6_addr beyond here, since the caller may @@ -616,8 +614,8 @@ in6_embedscope(struct in6_addr *in6, con return ENXIO; /* XXX EINVAL? */ in6->s6_addr16[1] = htons(pi->ipi6_ifindex); } else if (in6p && IN6_IS_ADDR_MULTICAST(in6) && - in6p->inp_moptions6 && - (ifp = if_get(in6p->inp_moptions6->im6o_ifidx))) { + in6p->inp_moptions6 && + (ifp = if_get(in6p->inp_moptions6->im6o_ifidx))) { in6->s6_addr16[1] = htons(ifp->if_index); } else if (scopeid) { ifp = if_get(scopeid); @@ -626,9 +624,7 @@ in6_embedscope(struct in6_addr *in6, con /*XXX assignment to 16bit from 32bit variable */ in6->s6_addr16[1] = htons(scopeid & 0xffff); } - - if (ifpp) - *ifpp = ifp; + if_put(ifp); } return 0; Index: netinet6/raw_ip6.c =================================================================== RCS file: /cvs/src/sys/netinet6/raw_ip6.c,v retrieving revision 1.82 diff -u -p -r1.82 raw_ip6.c --- netinet6/raw_ip6.c 10 Sep 2015 17:52:05 -0000 1.82 +++ netinet6/raw_ip6.c 10 Sep 2015 19:12:38 -0000 @@ -402,7 +402,7 @@ rip6_output(struct mbuf *m, ...) /* KAME hack: embed scopeid */ origoptp = in6p->inp_outputopts6; in6p->inp_outputopts6 = optp; - if (in6_embedscope(&ip6->ip6_dst, dstsock, in6p, &oifp) != 0) { + if (in6_embedscope(&ip6->ip6_dst, dstsock, in6p) != 0) { error = EINVAL; goto bad; } Index: netinet6/udp6_output.c =================================================================== RCS file: /cvs/src/sys/netinet6/udp6_output.c,v retrieving revision 1.35 diff -u -p -r1.35 udp6_output.c --- netinet6/udp6_output.c 8 Jun 2015 22:19:28 -0000 1.35 +++ netinet6/udp6_output.c 10 Sep 2015 19:12:38 -0000 @@ -151,7 +151,7 @@ udp6_output(struct inpcb *in6p, struct m fport = sin6->sin6_port; /* allow 0 port */ /* KAME hack: embed scopeid */ - if (in6_embedscope(&sin6->sin6_addr, sin6, in6p, NULL) != 0) { + if (in6_embedscope(&sin6->sin6_addr, sin6, in6p) != 0) { error = EINVAL; goto release; }