diff --git a/sys/altq/altq_cbq.c b/sys/altq/altq_cbq.c index d85d0c8c7d68a..c6e1da5f7cf91 100644 --- a/sys/altq/altq_cbq.c +++ b/sys/altq/altq_cbq.c @@ -37,7 +37,7 @@ __KERNEL_RCSID(0, "$NetBSD: altq_cbq.c,v 1.41 2024/09/26 02:39:09 ozaki-r Exp $" #ifdef _KERNEL_OPT #include "opt_altq.h" #include "opt_inet.h" -#include "pf.h" +#include "npf.h" #endif #ifdef ALTQ_CBQ /* cbq is enabled by ALTQ_CBQ option in opt_altq.h */ @@ -59,8 +59,8 @@ __KERNEL_RCSID(0, "$NetBSD: altq_cbq.c,v 1.41 2024/09/26 02:39:09 ozaki-r Exp $" #include #include -#if NPF > 0 -#include +#if NNPF > 0 +#include #endif #include #include @@ -242,9 +242,9 @@ get_class_stats(class_stats_t *statsp, struct rm_class *cl) #endif } -#if NPF > 0 +#if NNPF > 0 int -cbq_pfattach(struct pf_altq *a) +cbq_pfattach(struct npf_altq *a) { struct ifnet *ifp; int s, error; @@ -259,7 +259,7 @@ cbq_pfattach(struct pf_altq *a) } int -cbq_add_altq(struct pf_altq *a) +cbq_add_altq(struct npf_altq *a) { cbq_state_t *cbqp; struct ifnet *ifp; @@ -285,7 +285,7 @@ cbq_add_altq(struct pf_altq *a) } int -cbq_remove_altq(struct pf_altq *a) +cbq_remove_altq(struct npf_altq *a) { cbq_state_t *cbqp; @@ -308,7 +308,7 @@ cbq_remove_altq(struct pf_altq *a) #define NSEC_TO_PSEC(s) ((uint64_t)(s) * 1000) int -cbq_add_queue(struct pf_altq *a) +cbq_add_queue(struct npf_altq *a) { struct rm_class *borrow, *parent; cbq_state_t *cbqp; @@ -415,7 +415,7 @@ cbq_add_queue(struct pf_altq *a) } int -cbq_remove_queue(struct pf_altq *a) +cbq_remove_queue(struct npf_altq *a) { struct rm_class *cl; cbq_state_t *cbqp; @@ -451,7 +451,7 @@ cbq_remove_queue(struct pf_altq *a) } int -cbq_getqstats(struct pf_altq *a, void *ubuf, int *nbytes) +cbq_getqstats(struct npf_altq *a, void *ubuf, int *nbytes) { cbq_state_t *cbqp; struct rm_class *cl; @@ -475,7 +475,7 @@ cbq_getqstats(struct pf_altq *a, void *ubuf, int *nbytes) *nbytes = sizeof(stats); return (0); } -#endif /* NPF > 0 */ +#endif /* NNPF > 0 */ /* * int diff --git a/sys/altq/altq_hfsc.c b/sys/altq/altq_hfsc.c index c1feeada4b4f5..adbbb6a829f45 100644 --- a/sys/altq/altq_hfsc.c +++ b/sys/altq/altq_hfsc.c @@ -48,7 +48,7 @@ __KERNEL_RCSID(0, "$NetBSD: altq_hfsc.c,v 1.30 2021/09/21 14:30:15 christos Exp #ifdef _KERNEL_OPT #include "opt_altq.h" #include "opt_inet.h" -#include "pf.h" +#include "npf.h" #endif #ifdef ALTQ_HFSC /* hfsc is enabled by ALTQ_HFSC option in opt_altq.h */ @@ -70,8 +70,8 @@ __KERNEL_RCSID(0, "$NetBSD: altq_hfsc.c,v 1.30 2021/09/21 14:30:15 christos Exp #include #include -#if NPF > 0 -#include +#if NNPF > 0 +#include #endif #include #include @@ -173,9 +173,9 @@ altqdev_decl(hfsc); static struct hfsc_if *hif_list = NULL; #endif /* ALTQ3_COMPAT */ -#if NPF > 0 +#if NNPF > 0 int -hfsc_pfattach(struct pf_altq *a) +hfsc_pfattach(struct npf_altq *a) { struct ifnet *ifp; int s, error; @@ -190,7 +190,7 @@ hfsc_pfattach(struct pf_altq *a) } int -hfsc_add_altq(struct pf_altq *a) +hfsc_add_altq(struct npf_altq *a) { struct hfsc_if *hif; struct ifnet *ifp; @@ -219,7 +219,7 @@ hfsc_add_altq(struct pf_altq *a) } int -hfsc_remove_altq(struct pf_altq *a) +hfsc_remove_altq(struct npf_altq *a) { struct hfsc_if *hif; @@ -238,7 +238,7 @@ hfsc_remove_altq(struct pf_altq *a) } int -hfsc_add_queue(struct pf_altq *a) +hfsc_add_queue(struct npf_altq *a) { struct hfsc_if *hif; struct hfsc_class *cl, *parent; @@ -281,7 +281,7 @@ hfsc_add_queue(struct pf_altq *a) } int -hfsc_remove_queue(struct pf_altq *a) +hfsc_remove_queue(struct npf_altq *a) { struct hfsc_if *hif; struct hfsc_class *cl; @@ -296,7 +296,7 @@ hfsc_remove_queue(struct pf_altq *a) } int -hfsc_getqstats(struct pf_altq *a, void *ubuf, int *nbytes) +hfsc_getqstats(struct npf_altq *a, void *ubuf, int *nbytes) { struct hfsc_if *hif; struct hfsc_class *cl; @@ -320,7 +320,7 @@ hfsc_getqstats(struct pf_altq *a, void *ubuf, int *nbytes) *nbytes = sizeof(stats); return (0); } -#endif /* NPF > 0 */ +#endif /* NNPF > 0 */ /* * bring the interface back to the initial state by discarding diff --git a/sys/altq/altq_priq.c b/sys/altq/altq_priq.c index b8505ba7a9158..9f3edf245ba97 100644 --- a/sys/altq/altq_priq.c +++ b/sys/altq/altq_priq.c @@ -36,7 +36,7 @@ __KERNEL_RCSID(0, "$NetBSD: altq_priq.c,v 1.28 2021/09/21 14:30:15 christos Exp #ifdef _KERNEL_OPT #include "opt_altq.h" #include "opt_inet.h" -#include "pf.h" +#include "npf.h" #endif #ifdef ALTQ_PRIQ /* priq is enabled by ALTQ_PRIQ option in opt_altq.h */ @@ -56,8 +56,8 @@ __KERNEL_RCSID(0, "$NetBSD: altq_priq.c,v 1.28 2021/09/21 14:30:15 christos Exp #include #include -#if NPF > 0 -#include +#if NNPF > 0 +#include #endif #include #include @@ -105,9 +105,9 @@ altqdev_decl(priq); static struct priq_if *pif_list = NULL; #endif /* ALTQ3_COMPAT */ -#if NPF > 0 +#if NNPF > 0 int -priq_pfattach(struct pf_altq *a) +priq_pfattach(struct npf_altq *a) { struct ifnet *ifp; int s, error; @@ -122,7 +122,7 @@ priq_pfattach(struct pf_altq *a) } int -priq_add_altq(struct pf_altq *a) +priq_add_altq(struct npf_altq *a) { struct priq_if *pif; struct ifnet *ifp; @@ -146,7 +146,7 @@ priq_add_altq(struct pf_altq *a) } int -priq_remove_altq(struct pf_altq *a) +priq_remove_altq(struct npf_altq *a) { struct priq_if *pif; @@ -161,7 +161,7 @@ priq_remove_altq(struct pf_altq *a) } int -priq_add_queue(struct pf_altq *a) +priq_add_queue(struct npf_altq *a) { struct priq_if *pif; struct priq_class *cl; @@ -188,7 +188,7 @@ priq_add_queue(struct pf_altq *a) } int -priq_remove_queue(struct pf_altq *a) +priq_remove_queue(struct npf_altq *a) { struct priq_if *pif; struct priq_class *cl; @@ -203,7 +203,7 @@ priq_remove_queue(struct pf_altq *a) } int -priq_getqstats(struct pf_altq *a, void *ubuf, int *nbytes) +priq_getqstats(struct npf_altq *a, void *ubuf, int *nbytes) { struct priq_if *pif; struct priq_class *cl; @@ -227,7 +227,7 @@ priq_getqstats(struct pf_altq *a, void *ubuf, int *nbytes) *nbytes = sizeof(stats); return (0); } -#endif /* NPF > 0 */ +#endif /* NNPF > 0 */ /* * bring the interface back to the initial state by discarding diff --git a/sys/altq/altq_subr.c b/sys/altq/altq_subr.c index 5c0c57b587f79..a6a6cd7cc6817 100644 --- a/sys/altq/altq_subr.c +++ b/sys/altq/altq_subr.c @@ -33,7 +33,7 @@ __KERNEL_RCSID(0, "$NetBSD: altq_subr.c,v 1.33 2017/03/14 09:03:08 ozaki-r Exp $ #ifdef _KERNEL_OPT #include "opt_altq.h" #include "opt_inet.h" -#include "pf.h" +#include "npf.h" #endif #include @@ -62,8 +62,8 @@ __KERNEL_RCSID(0, "$NetBSD: altq_subr.c,v 1.33 2017/03/14 09:03:08 ozaki-r Exp $ #include #include -#if NPF > 0 -#include +#if NNPF > 0 +#include #endif #include #ifdef ALTQ3_COMPAT @@ -400,13 +400,13 @@ tbr_get(struct ifaltq *ifq, struct tb_profile *profile) return (0); } -#if NPF > 0 +#if NNPF > 0 /* * attach a discipline to the interface. if one already exists, it is * overridden. */ int -altq_pfattach(struct pf_altq *a) +altq_pfattach(struct npf_altq *a) { int error = 0; @@ -441,7 +441,7 @@ altq_pfattach(struct pf_altq *a) * discipline. */ int -altq_pfdetach(struct pf_altq *a) +altq_pfdetach(struct npf_altq *a) { struct ifnet *ifp; int s, error = 0; @@ -467,7 +467,7 @@ altq_pfdetach(struct pf_altq *a) * add a discipline or a queue */ int -altq_add(struct pf_altq *a) +altq_add(struct npf_altq *a) { int error = 0; @@ -506,7 +506,7 @@ altq_add(struct pf_altq *a) * remove a discipline or a queue */ int -altq_remove(struct pf_altq *a) +altq_remove(struct npf_altq *a) { int error = 0; @@ -540,7 +540,7 @@ altq_remove(struct pf_altq *a) * add a queue to the discipline */ int -altq_add_queue(struct pf_altq *a) +altq_add_queue(struct npf_altq *a) { int error = 0; @@ -571,7 +571,7 @@ altq_add_queue(struct pf_altq *a) * remove a queue from the discipline */ int -altq_remove_queue(struct pf_altq *a) +altq_remove_queue(struct npf_altq *a) { int error = 0; @@ -602,7 +602,7 @@ altq_remove_queue(struct pf_altq *a) * get queue statistics */ int -altq_getqstats(struct pf_altq *a, void *ubuf, int *nbytes) +altq_getqstats(struct npf_altq *a, void *ubuf, int *nbytes) { int error = 0; @@ -628,7 +628,7 @@ altq_getqstats(struct pf_altq *a, void *ubuf, int *nbytes) return (error); } -#endif /* NPF > 0 */ +#endif /* NNPF > 0 */ /* * read and write diffserv field in IPv4 or IPv6 header diff --git a/sys/modules/npf/npf.h b/sys/modules/npf/npf.h new file mode 100644 index 0000000000000..8945345e2890c --- /dev/null +++ b/sys/modules/npf/npf.h @@ -0,0 +1 @@ +#define NNPF 1 \ No newline at end of file diff --git a/sys/net/npf/files.npf b/sys/net/npf/files.npf index 80727f79f5d39..c6346153abc69 100644 --- a/sys/net/npf/files.npf +++ b/sys/net/npf/files.npf @@ -10,7 +10,7 @@ defpseudo npf: ifnet, libnv # Core -file net/npf/npf.c npf +file net/npf/npf.c npf needs-flag file net/npf/npf_conf.c npf file net/npf/npf_ctl.c npf file net/npf/npf_handler.c npf diff --git a/sys/net/npf/npf_altq.h b/sys/net/npf/npf_altq.h new file mode 100644 index 0000000000000..bd46ae3e48f7a --- /dev/null +++ b/sys/net/npf/npf_altq.h @@ -0,0 +1,107 @@ +/* NetBSD */ +/*- + * Copyright (c) 2024 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Emmanuel Nyarko. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#include +#ifndef NPF_ALTQ_H_ +#define NPF_ALTQ_H_ + +#ifndef IFNAMSIZ +#define IFNAMSIZ 16 +#endif +/* queueing flags */ +#ifndef NPF_QNAME_SIZE +#define NPF_QNAME_SIZE 64 +#endif +#ifndef TAGID_MAX +#define TAGID_MAX 50000 +#endif +#ifndef NPF_TAG_NAME_SIZE +#define NPF_TAG_NAME_SIZE 64 +#endif + +/* + * options defined on the cbq, priq and hfsc when configuring them + */ +struct npf_cbq_opts { + uint32_t minburst; + uint32_t maxburst; + uint32_t pktsize; + uint32_t maxpktsize; + uint32_t ns_per_byte; + uint32_t maxidle; + int minidle; + uint32_t offtime; + int flags; +}; + +struct npf_priq_opts { + int flags; +}; + +struct npf_hfsc_opts { + /* real-time service curve */ + uint32_t rtsc_m1; /* slope of the 1st segment in bps */ + uint32_t rtsc_d; /* the x-projection of m1 in msec */ + uint32_t rtsc_m2; /* slope of the 2nd segment in bps */ + /* link-sharing service curve */ + uint32_t lssc_m1; + uint32_t lssc_d; + uint32_t lssc_m2; + /* upper-limit service curve */ + uint32_t ulsc_m1; + uint32_t ulsc_d; + uint32_t ulsc_m2; + int flags; +}; + +/* entries for our tail queue for our altqs */ +struct npf_altq { + char ifname[IFNAMSIZ]; + void *altq_disc; /* discipline-specific state */ + TAILQ_ENTRY(npf_altq) entries; + /* scheduler spec */ + uint8_t scheduler; /* scheduler type */ + uint16_t tbrsize; /* tokenbucket regulator size */ + uint32_t ifbandwidth; /* interface bandwidth */ + /* queue spec */ + char qname[NPF_QNAME_SIZE]; /* queue name */ + char parent[NPF_QNAME_SIZE]; /* parent name */ + uint32_t parent_qid; /* parent queue id */ + uint32_t bandwidth; /* queue bandwidth */ + uint8_t priority; /* priority */ + uint16_t qlimit; /* queue size limit */ + uint16_t flags; /* misc flags */ + union { + struct npf_cbq_opts cbq_opts; + struct npf_priq_opts priq_opts; + struct npf_hfsc_opts hfsc_opts; + } pq_u; + u_int32_t qid; /* return value */ +}; +#endif /* NPF_ALTQ_H_ */