This diff modifies divert_packet() to increment the divs_errors counter
on if_get failure so that users will be aware of it via netstat(1).

The same thing is done for divert6_packet().

While here, it also modifies divert_output() to move m_freem(m) below
divstat_inc(divs_errors).  This is purely for consistency since all the
other divert_* functions increment the divstat counters before m_freem.
divert6_output() already does this so there is no need to make the same
change there.

ok?


Index: netinet/ip_divert.c
===================================================================
RCS file: /cvs/src/sys/netinet/ip_divert.c,v
retrieving revision 1.61
diff -u -p -r1.61 ip_divert.c
--- netinet/ip_divert.c 4 Feb 2019 21:40:52 -0000       1.61
+++ netinet/ip_divert.c 24 Mar 2019 23:39:58 -0000
@@ -163,8 +163,8 @@ divert_output(struct inpcb *inp, struct 
        return (error);
 
 fail:
-       m_freem(m);
        divstat_inc(divs_errors);
+       m_freem(m);
        return (error ? error : EINVAL);
 }
 
@@ -199,6 +199,7 @@ divert_packet(struct mbuf *m, int dir, u
 
                ifp = if_get(m->m_pkthdr.ph_ifidx);
                if (ifp == NULL) {
+                       divstat_inc(divs_errors);
                        m_freem(m);
                        return (0);
                }
Index: netinet6/ip6_divert.c
===================================================================
RCS file: /cvs/src/sys/netinet6/ip6_divert.c,v
retrieving revision 1.59
diff -u -p -r1.59 ip6_divert.c
--- netinet6/ip6_divert.c       4 Feb 2019 21:40:52 -0000       1.59
+++ netinet6/ip6_divert.c       24 Mar 2019 23:39:03 -0000
@@ -205,6 +205,7 @@ divert6_packet(struct mbuf *m, int dir, 
 
                ifp = if_get(m->m_pkthdr.ph_ifidx);
                if (ifp == NULL) {
+                       div6stat_inc(div6s_errors);
                        m_freem(m);
                        return (0);
                }

Reply via email to