From 02adfc59c18f863f648c4a849fb0b3eaabeb3447 Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Tue, 22 Mar 2016 07:05:19 +0100 Subject: [PATCH] netgraph: prevent panic during attach to-non ethernet devices PR: https://forum.opnsense.org/index.php?topic=2385 (cherry picked from commit 56b3d8393e8f7d2e6bbd7753e2c8e3e5925f9b11) (cherry picked from commit 6edfc6fe9dd8d52d976150d705c508928b32a7b9) (cherry picked from commit 9b57a3748815dc71889d30f6280fbe105a18c750) --- sys/netgraph/ng_base.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/sys/netgraph/ng_base.c b/sys/netgraph/ng_base.c index 026c98309fb..e99997dab68 100644 --- a/sys/netgraph/ng_base.c +++ b/sys/netgraph/ng_base.c @@ -66,6 +66,7 @@ #include #include +#include #include #include @@ -2923,10 +2924,15 @@ ng_generic_msg(node_p here, item_p item, hook_p lasthook) case NGM_ETHER_ATTACH: { - struct ifnet *ifp; - ifp = ifunit((char *)msg->data); - if (ifp && ng_ether_attach_p != NULL) { - ng_ether_attach_p(ifp); + struct ifnet *ifp = ifunit((char *)msg->data); + + if (ng_ether_attach_p) { + if (ifp && (ifp->if_type == IFT_ETHER || + ifp->if_type == IFT_L2VLAN)) { + ng_ether_attach_p(ifp); + } else { + error = ENOENT; + } } break;