On Mon, May 30, 2016 at 02:46:18PM +0200, Martin Pieuchot wrote:
> Here's a corrected version of the previous diff that got backed out.
>
> The idea is still to stop calling nd6_output() with a NULL ``rt''
> argument in order to always use the same code path when inserting
> routes.
>
> ok?
OK bluhm@
>
> Index: net/pf.c
> ===================================================================
> RCS file: /cvs/src/sys/net/pf.c,v
> retrieving revision 1.973
> diff -u -p -r1.973 pf.c
> --- net/pf.c 28 May 2016 12:04:33 -0000 1.973
> +++ net/pf.c 30 May 2016 12:42:46 -0000
> @@ -5665,11 +5665,13 @@ pf_route6(struct mbuf **m, struct pf_rul
> {
> struct mbuf *m0;
> struct sockaddr_in6 *dst, sin6;
> + struct rtentry *rt = NULL;
> struct ip6_hdr *ip6;
> struct ifnet *ifp = NULL;
> struct pf_addr naddr;
> struct pf_src_node *sns[PF_SN_MAX];
> struct m_tag *mtag;
> + unsigned int rtableid;
>
> if (m == NULL || *m == NULL || r == NULL ||
> (dir != PF_IN && dir != PF_OUT) || oifp == NULL)
> @@ -5702,6 +5704,7 @@ pf_route6(struct mbuf **m, struct pf_rul
> dst->sin6_family = AF_INET6;
> dst->sin6_len = sizeof(*dst);
> dst->sin6_addr = ip6->ip6_dst;
> + rtableid = m0->m_pkthdr.ph_rtableid;
>
> if (!r->rt) {
> m0->m_pkthdr.pf.flags |= PF_TAG_GENERATED;
> @@ -5754,7 +5757,13 @@ pf_route6(struct mbuf **m, struct pf_rul
> if ((mtag = m_tag_find(m0, PACKET_TAG_PF_REASSEMBLED, NULL))) {
> (void) pf_refragment6(&m0, mtag, dst, ifp);
> } else if ((u_long)m0->m_pkthdr.len <= ifp->if_mtu) {
> - nd6_output(ifp, m0, dst, NULL);
> + rt = rtalloc(sin6tosa(dst), RT_RESOLVE, rtableid);
> + if (rt == NULL) {
> + ip6stat.ip6s_noroute++;
> + goto bad;
> + }
> + nd6_output(ifp, m0, dst, rt);
> + rtfree(rt);
> } else {
> icmp6_error(m0, ICMP6_PACKET_TOO_BIG, 0, ifp->if_mtu);
> }
> Index: net/pf_norm.c
> ===================================================================
> RCS file: /cvs/src/sys/net/pf_norm.c,v
> retrieving revision 1.185
> diff -u -p -r1.185 pf_norm.c
> --- net/pf_norm.c 28 May 2016 12:04:33 -0000 1.185
> +++ net/pf_norm.c 30 May 2016 04:33:01 -0000
> @@ -687,6 +687,7 @@ pf_refragment6(struct mbuf **m0, struct
> {
> struct mbuf *m = *m0, *t;
> struct pf_fragment_tag *ftag = (struct pf_fragment_tag *)(mtag + 1);
> + struct rtentry *rt = NULL;
> u_int32_t mtu;
> u_int16_t hdrlen, extoff, maxlen;
> u_int8_t proto;
> @@ -742,6 +743,16 @@ pf_refragment6(struct mbuf **m0, struct
> DPFPRINTF(LOG_NOTICE, "refragment error %d", error);
> action = PF_DROP;
> }
> +
> + if (ifp != NULL) {
> + rt = rtalloc(sin6tosa(dst), RT_RESOLVE,
> + m->m_pkthdr.ph_rtableid);
> + if (rt == NULL) {
> + ip6stat.ip6s_noroute++;
> + error = -1;
> + }
> + }
> +
> for (t = m; m; m = t) {
> t = m->m_nextpkt;
> m->m_nextpkt = NULL;
> @@ -750,7 +761,7 @@ pf_refragment6(struct mbuf **m0, struct
> if (ifp == NULL) {
> ip6_forward(m, 0);
> } else if ((u_long)m->m_pkthdr.len <= ifp->if_mtu) {
> - nd6_output(ifp, m, dst, NULL);
> + nd6_output(ifp, m, dst, rt);
> } else {
> icmp6_error(m, ICMP6_PACKET_TOO_BIG, 0,
> ifp->if_mtu);
> @@ -759,6 +770,7 @@ pf_refragment6(struct mbuf **m0, struct
> m_freem(m);
> }
> }
> + rtfree(rt);
>
> return (action);
> }