On Wed, Oct 11, 2017 at 02:58:21PM +0200, Martin Pieuchot wrote:
> sysctl_mq() messes with 'struct mbuf_queue' internals, so keep it in
> kern/uipc_mbuf.c with the rest of the mq* functions.
I wonder whether it should be called mq_sysctl() as it will be
located in the mq_ namespace. A grep for _sysctl and sysctl_ shows
that we are rather inconsistent in naming, so commit it either way.
> ok?
OK bluhm@
> Index: net/if.c
> ===================================================================
> RCS file: /cvs/src/sys/net/if.c,v
> retrieving revision 1.514
> diff -u -p -r1.514 if.c
> --- net/if.c 11 Oct 2017 07:57:27 -0000 1.514
> +++ net/if.c 11 Oct 2017 12:56:18 -0000
> @@ -82,7 +82,6 @@
> #include <sys/kernel.h>
> #include <sys/ioctl.h>
> #include <sys/domain.h>
> -#include <sys/sysctl.h>
> #include <sys/task.h>
> #include <sys/atomic.h>
> #include <sys/proc.h>
> @@ -2654,38 +2653,6 @@ ifpromisc(struct ifnet *ifp, int pswitch
> }
> ifr.ifr_flags = ifp->if_flags;
> return ((*ifp->if_ioctl)(ifp, SIOCSIFFLAGS, (caddr_t)&ifr));
> -}
> -
> -/* XXX move to kern/uipc_mbuf.c */
> -int
> -sysctl_mq(int *name, u_int namelen, void *oldp, size_t *oldlenp,
> - void *newp, size_t newlen, struct mbuf_queue *mq)
> -{
> - unsigned int maxlen;
> - int error;
> -
> - /* All sysctl names at this level are terminal. */
> - if (namelen != 1)
> - return (ENOTDIR);
> -
> - switch (name[0]) {
> - case IFQCTL_LEN:
> - return (sysctl_rdint(oldp, oldlenp, newp, mq_len(mq)));
> - case IFQCTL_MAXLEN:
> - maxlen = mq->mq_maxlen;
> - error = sysctl_int(oldp, oldlenp, newp, newlen, &maxlen);
> - if (!error && maxlen != mq->mq_maxlen) {
> - mtx_enter(&mq->mq_mtx);
> - mq->mq_maxlen = maxlen;
> - mtx_leave(&mq->mq_mtx);
> - }
> - return (error);
> - case IFQCTL_DROPS:
> - return (sysctl_rdint(oldp, oldlenp, newp, mq_drops(mq)));
> - default:
> - return (EOPNOTSUPP);
> - }
> - /* NOTREACHED */
> }
>
> void
> Index: net/if_var.h
> ===================================================================
> RCS file: /cvs/src/sys/net/if_var.h,v
> retrieving revision 1.81
> diff -u -p -r1.81 if_var.h
> --- net/if_var.h 8 May 2017 08:46:39 -0000 1.81
> +++ net/if_var.h 11 Oct 2017 12:56:18 -0000
> @@ -324,9 +324,6 @@ int if_clone_destroy(const char *);
> struct if_clone *
> if_clone_lookup(const char *, int *);
>
> -int sysctl_mq(int *, u_int, void *, size_t *, void *, size_t,
> - struct mbuf_queue *);
> -
> void ifa_add(struct ifnet *, struct ifaddr *);
> void ifa_del(struct ifnet *, struct ifaddr *);
> void ifa_update_broadaddr(struct ifnet *, struct ifaddr *,
> Index: kern/uipc_mbuf.c
> ===================================================================
> RCS file: /cvs/src/sys/kern/uipc_mbuf.c,v
> retrieving revision 1.249
> diff -u -p -r1.249 uipc_mbuf.c
> --- kern/uipc_mbuf.c 15 Sep 2017 18:13:05 -0000 1.249
> +++ kern/uipc_mbuf.c 11 Oct 2017 12:56:19 -0000
> @@ -84,6 +84,7 @@
> #include <sys/protosw.h>
> #include <sys/pool.h>
> #include <sys/percpu.h>
> +#include <sys/sysctl.h>
>
> #include <sys/socket.h>
> #include <sys/socketvar.h>
> @@ -1648,4 +1649,35 @@ mq_purge(struct mbuf_queue *mq)
> mq_delist(mq, &ml);
>
> return (ml_purge(&ml));
> +}
> +
> +int
> +sysctl_mq(int *name, u_int namelen, void *oldp, size_t *oldlenp,
> + void *newp, size_t newlen, struct mbuf_queue *mq)
> +{
> + unsigned int maxlen;
> + int error;
> +
> + /* All sysctl names at this level are terminal. */
> + if (namelen != 1)
> + return (ENOTDIR);
> +
> + switch (name[0]) {
> + case IFQCTL_LEN:
> + return (sysctl_rdint(oldp, oldlenp, newp, mq_len(mq)));
> + case IFQCTL_MAXLEN:
> + maxlen = mq->mq_maxlen;
> + error = sysctl_int(oldp, oldlenp, newp, newlen, &maxlen);
> + if (!error && maxlen != mq->mq_maxlen) {
> + mtx_enter(&mq->mq_mtx);
> + mq->mq_maxlen = maxlen;
> + mtx_leave(&mq->mq_mtx);
> + }
> + return (error);
> + case IFQCTL_DROPS:
> + return (sysctl_rdint(oldp, oldlenp, newp, mq_drops(mq)));
> + default:
> + return (EOPNOTSUPP);
> + }
> + /* NOTREACHED */
> }
> Index: sys/sysctl.h
> ===================================================================
> RCS file: /cvs/src/sys/sys/sysctl.h,v
> retrieving revision 1.174
> diff -u -p -r1.174 sysctl.h
> --- sys/sysctl.h 14 Jun 2017 03:00:40 -0000 1.174
> +++ sys/sysctl.h 11 Oct 2017 12:56:21 -0000
> @@ -936,6 +936,9 @@ int sysctl_rdstruct(void *, size_t *, vo
> int sysctl_struct(void *, size_t *, void *, size_t, void *, size_t);
> int sysctl_file(int *, u_int, char *, size_t *, struct proc *);
> int sysctl_doproc(int *, u_int, char *, size_t *);
> +struct mbuf_queue;
> +int sysctl_mq(int *, u_int, void *, size_t *, void *, size_t,
> + struct mbuf_queue *);
> struct rtentry;
> struct walkarg;
> int sysctl_dumpentry(struct rtentry *, void *, unsigned int);