Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/net Add packet filtering to tun(4) interfaces.



details:   https://anonhg.NetBSD.org/src/rev/c7ff4de9bae8
branches:  trunk
changeset: 321446:c7ff4de9bae8
user:      tih <tih%NetBSD.org@localhost>
date:      Fri Mar 16 17:12:04 2018 +0000

description:
Add packet filtering to tun(4) interfaces.

Calls to pfil_run_hooks() were missing in if_tun.c.  This meant that
filtering configuration could be added to e.g. /etc/npf.conf, but
would be ignored, because the filter never saw the packets.  This
change adds the required calls.

While here, correct the return value from tun_output(): it's been
returning 0 regardless of any error condition present, but will now
correctly propagate such information upward.

Thanks to maxv for guidance!

OK: christos, martin

diffstat:

 sys/net/if_tun.c |  20 +++++++++++++++-----
 1 files changed, 15 insertions(+), 5 deletions(-)

diffs (56 lines):

diff -r dc5ce7402d60 -r c7ff4de9bae8 sys/net/if_tun.c
--- a/sys/net/if_tun.c  Fri Mar 16 17:00:35 2018 +0000
+++ b/sys/net/if_tun.c  Fri Mar 16 17:12:04 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_tun.c,v 1.142 2017/12/06 07:40:16 ozaki-r Exp $     */
+/*     $NetBSD: if_tun.c,v 1.143 2018/03/16 17:12:04 tih Exp $ */
 
 /*
  * Copyright (c) 1988, Julian Onions <jpo%cs.nott.ac.uk@localhost>
@@ -19,7 +19,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_tun.c,v 1.142 2017/12/06 07:40:16 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_tun.c,v 1.143 2018/03/16 17:12:04 tih Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -555,6 +555,11 @@
 
        bpf_mtap_af(ifp, dst->sa_family, m0);
 
+       if ((error = pfil_run_hooks(ifp->if_pfil, &m0, ifp, PFIL_OUT)) != 0)
+               goto out;
+       if (m0 == NULL)
+               goto out;
+
        switch(dst->sa_family) {
 #ifdef INET6
        case AF_INET6:
@@ -624,10 +629,10 @@
 
        mutex_exit(&tp->tun_lock);
 out:
-       if (error && m0) {
+       if (error && m0)
                m_freem(m0);
-       }
-       return 0;
+
+       return error;
 }
 
 static void
@@ -941,6 +946,11 @@
 
        bpf_mtap_af(ifp, dst.sa_family, top);
 
+       if ((error = pfil_run_hooks(ifp->if_pfil, &top, ifp, PFIL_IN)) != 0)
+               goto out0;
+       if (top == NULL)
+               goto out0;
+
        mutex_enter(&tp->tun_lock);
        if ((tp->tun_flags & TUN_INITED) == 0) {
                /* Interface was destroyed */



Home | Main Index | Thread Index | Old Index