The branch main has been updated by glebius:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=fe5a6266dde08cece15025c75a80a45d977c57c2

commit fe5a6266dde08cece15025c75a80a45d977c57c2
Author:     Gleb Smirnoff <gleb...@freebsd.org>
AuthorDate: 2025-02-03 07:08:05 +0000
Commit:     Gleb Smirnoff <gleb...@freebsd.org>
CommitDate: 2025-02-03 17:48:53 +0000

    protosw: this is a kernel only header, put back #ifdef _KERNEL
    
    The uncommented #ifdef _KERNEL originates from 1997 by wollman@ (see
    57bf258e3dc9e) with no clear original reason.  Since these old times two
    abusers of the header leak were created - libprocstat(3) and netstat(1).
    These two already have a lot of _WANT_FOO hacks, so satisfy them with
    _WANT_PROTOSW.
    
    While here, cleanup and sort forward declaraions.
---
 lib/libprocstat/libprocstat.c |  1 +
 sys/sys/protosw.h             | 26 ++++++++++----------------
 usr.bin/netstat/inet.c        |  1 +
 3 files changed, 12 insertions(+), 16 deletions(-)

diff --git a/lib/libprocstat/libprocstat.c b/lib/libprocstat/libprocstat.c
index b808085f5eed..90e4879ca05b 100644
--- a/lib/libprocstat/libprocstat.c
+++ b/lib/libprocstat/libprocstat.c
@@ -50,6 +50,7 @@
 #define        _WANT_SOCKET
 #include <sys/socketvar.h>
 #include <sys/domain.h>
+#define        _WANT_PROTOSW
 #include <sys/protosw.h>
 #include <sys/un.h>
 #define        _WANT_UNPCB
diff --git a/sys/sys/protosw.h b/sys/sys/protosw.h
index 941d377b1549..2f74148efa1d 100644
--- a/sys/sys/protosw.h
+++ b/sys/sys/protosw.h
@@ -31,19 +31,7 @@
 
 #ifndef _SYS_PROTOSW_H_
 #define _SYS_PROTOSW_H_
-
-#include <sys/_types.h>
-
-/* Forward declare these structures referenced from prototypes below. */
-struct kaiocb;
-struct mbuf;
-struct thread;
-struct sockaddr;
-struct socket;
-struct sockopt;
-enum shutdown_how;
-
-/*#ifdef _KERNEL*/
+#if defined(_KERNEL) || defined(_WANT_PROTOSW)
 /*
  * Protocol switch table.
  *
@@ -53,10 +41,17 @@ enum shutdown_how;
  * In retrospect, it would be a lot nicer to use an interface
  * similar to the vnode VOP interface.
  */
+struct socket;
+struct sockopt;
+struct thread;
+struct sockaddr;
 struct ifnet;
+struct mbuf;
 struct stat;
 struct ucred;
 struct uio;
+struct kaiocb;
+enum shutdown_how;
 
 /* USE THESE FOR YOUR PROTOTYPES ! */
 typedef int    pr_ctloutput_t(struct socket *, struct sockopt *);
@@ -144,7 +139,8 @@ struct protosw {
        pr_setsbopt_t   *pr_setsbopt;   /* Socket buffer ioctls */
        pr_chmod_t      *pr_chmod;      /* fchmod(2) */
 };
-/*#endif*/
+#endif /* defined(_KERNEL) || defined(_WANT_PROTOSW) */
+#ifdef _KERNEL
 
 /*
  * Values for pr_flags.
@@ -167,7 +163,6 @@ struct protosw {
 #define        PR_CAPATTACH    0x80            /* socket can attach in cap 
mode */
 #define        PR_SOCKBUF      0x100           /* private implementation of 
buffers */
 
-#ifdef _KERNEL
 struct domain *pffinddomain(int family);
 struct protosw *pffindproto(int family, int type, int proto);
 int protosw_register(struct domain *, struct protosw *);
@@ -177,5 +172,4 @@ int protosw_unregister(struct protosw *);
 extern struct domain inetdomain;
 extern struct domain inet6domain;
 #endif
-
 #endif
diff --git a/usr.bin/netstat/inet.c b/usr.bin/netstat/inet.c
index 5a5610ccb6c0..6065a2a7644c 100644
--- a/usr.bin/netstat/inet.c
+++ b/usr.bin/netstat/inet.c
@@ -30,6 +30,7 @@
 #include <sys/param.h>
 #include <sys/queue.h>
 #include <sys/domain.h>
+#define        _WANT_PROTOSW
 #include <sys/protosw.h>
 #include <sys/socket.h>
 #define        _WANT_SOCKET

Reply via email to