Index: net/if.c =================================================================== RCS file: /cvs/src/sys/net/if.c,v retrieving revision 1.322 diff -u -p -r1.322 if.c --- net/if.c 18 Mar 2015 12:23:15 -0000 1.322 +++ net/if.c 20 Mar 2015 13:05:58 -0000 @@ -2132,6 +2132,28 @@ sysctl_ifq(int *name, u_int namelen, voi /* NOTREACHED */ } +int +sysctl_niq(int *name, u_int namelen, void *oldp, size_t *oldlenp, + void *newp, size_t newlen, struct niqueue *niq) +{ + /* 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, niq_len(niq))); + case IFQCTL_MAXLEN: + return (sysctl_int(oldp, oldlenp, newp, newlen, + &niq->ni_q.mq_maxlen)); /* XXX */ + case IFQCTL_DROPS: + return (sysctl_rdint(oldp, oldlenp, newp, niq_drops(niq))); + default: + return (EOPNOTSUPP); + } + /* NOTREACHED */ +} + void ifa_add(struct ifnet *ifp, struct ifaddr *ifa) { @@ -2350,4 +2372,43 @@ if_rxr_ioctl(struct if_rxrinfo *ifri, co ifr.ifr_info = *rxr; return (if_rxr_info_ioctl(ifri, 1, &ifr)); +} + +/* + * Network stack input queues. + */ + +void +niq_init(struct niqueue *niq, u_int maxlen, u_int isr) +{ + mq_init(&niq->ni_q, maxlen, IPL_NET); + niq->ni_isr = isr; +} + +int +niq_enqueue(struct niqueue *niq, struct mbuf *m) +{ + int rv; + + rv = mq_enqueue(&niq->ni_q, m); + if (rv == 0) + schednetisr(niq->ni_isr); + else + if_congestion(); + + return (rv); +} + +int +niq_enlist(struct niqueue *niq, struct mbuf_list *ml) +{ + int rv; + + rv = mq_enlist(&niq->ni_q, ml); + if (rv == 0) + schednetisr(niq->ni_isr); + else + if_congestion(); + + return (rv); } Index: net/if_var.h =================================================================== RCS file: /cvs/src/sys/net/if_var.h,v retrieving revision 1.21 diff -u -p -r1.21 if_var.h --- net/if_var.h 18 Mar 2015 12:23:15 -0000 1.21 +++ net/if_var.h 20 Mar 2015 13:05:58 -0000 @@ -37,6 +37,7 @@ #define _NET_IF_VAR_H_ #include +#include #ifdef _KERNEL #include #endif @@ -68,8 +69,6 @@ #include -struct mbuf; -struct mbuf_list; struct proc; struct rtentry; struct socket; @@ -391,6 +390,28 @@ do { \ #define IF_WIRED_DEFAULT_PRIORITY 0 #define IF_WIRELESS_DEFAULT_PRIORITY 4 +/* + * Network stack input queues. + */ +struct niqueue { + struct mbuf_queue ni_q; + u_int ni_isr; +}; + +#define NIQUEUE_INITIALIZER(_len, _isr) \ + { MBUF_QUEUE_INITIALIZER((_len), IPL_NET), (_isr) } + +void niq_init(struct niqueue *, u_int, u_int); +int niq_enqueue(struct niqueue *, struct mbuf *); +int niq_enlist(struct niqueue *, struct mbuf_list *); + +#define niq_dequeue(_q) mq_dequeue(&(_q)->ni_q) +#define niq_dechain(_q) mq_dechain(&(_q)->ni_q) +#define niq_delist(_q, _ml) mq_delist(&(_q)->ni_q, (_ml)) +#define niq_filter(_q, _f, _c) mq_filter(&(_q)->ni_q, (_f), (_c)) +#define niq_len(_q) mq_len(&(_q)->ni_q) +#define niq_drops(_q) mq_drops(&(_q)->ni_q) + extern struct ifnet_head ifnet; extern struct ifnet *lo0ifp; @@ -423,6 +444,8 @@ int if_clone_destroy(const char *); int sysctl_ifq(int *, u_int, void *, size_t *, void *, size_t, struct ifqueue *); +int sysctl_niq(int *, u_int, void *, size_t *, void *, size_t, + struct niqueue *); int loioctl(struct ifnet *, u_long, caddr_t); void loopattach(int);