From 80ccc5210845400c949e71d42240d88e853210f2 Mon Sep 17 00:00:00 2001 From: ozaki-r Date: Mon, 30 Oct 2017 03:02:35 +0000 Subject: [PATCH] Fix npfclt reload on rump kernels It fails because npfctl cannot get an errno when it calls ioctl to the (rump) kernel; npfctl (libnpf) expects that an errno is returned via proplib, however, the rump library of npf doesn't so. It happens because of mishandlings of complicate npf kernel options. PR kern/52643 --- sys/net/npf/npf_ctl.c | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/sys/net/npf/npf_ctl.c b/sys/net/npf/npf_ctl.c index b1af2d347acb..02e12ef3a312 100644 --- a/sys/net/npf/npf_ctl.c +++ b/sys/net/npf/npf_ctl.c @@ -1,4 +1,4 @@ -/* $NetBSD: npf_ctl.c,v 1.48 2017/05/17 18:56:12 christos Exp $ */ +/* $NetBSD: npf_ctl.c,v 1.49 2017/10/30 03:02:35 ozaki-r Exp $ */ /*- * Copyright (c) 2009-2014 The NetBSD Foundation, Inc. @@ -38,7 +38,7 @@ #ifdef _KERNEL #include -__KERNEL_RCSID(0, "$NetBSD: npf_ctl.c,v 1.48 2017/05/17 18:56:12 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: npf_ctl.c,v 1.49 2017/10/30 03:02:35 ozaki-r Exp $"); #include #include @@ -630,15 +630,31 @@ fail: if (tblset) { npf_tableset_destroy(tblset); } - prop_object_release(npf_dict); - - /* Error report. */ -#if !defined(_NPF_TESTING) && !defined(_NPF_STANDALONE) - prop_dictionary_set_int32(errdict, "errno", error); - prop_dictionary_copyout_ioctl(pref, cmd, errdict); - prop_object_release(errdict); - error = 0; +#if defined(_NPF_TESTING) || defined(_NPF_STANDALONE) + /* Free only if allocated by prop_dictionary_copyin_ioctl_size. */ + if (!npfctl_testing) #endif + prop_object_release(npf_dict); + + /* + * - _NPF_STANDALONE doesn't require to set prop. + * - For _NPF_TESTING, if npfctl_testing, setting prop isn't needed, + * otherwise it's needed. + */ +#ifndef _NPF_STANDALONE +#ifdef _NPF_TESTING + if (!npfctl_testing) { +#endif + /* Error report. */ + prop_dictionary_set_int32(errdict, "errno", error); + prop_dictionary_copyout_ioctl(pref, cmd, errdict); + error = 0; +#ifdef _NPF_TESTING + } +#endif +#endif /* _NPF_STANDALONE */ + prop_object_release(errdict); + return error; }