git: ae3301084da1 - main - Revert "ifnet/API: Move the IfAPI from if_var.h to if.h"

From: Justin Hibbits <jhibbits_at_FreeBSD.org>
Date: Fri, 13 Jan 2023 02:32:54 UTC
The branch main has been updated by jhibbits:

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

commit ae3301084da1a0e643a7589930186d67f0910b65
Author:     Justin Hibbits <jhibbits@FreeBSD.org>
AuthorDate: 2023-01-13 00:18:40 +0000
Commit:     Justin Hibbits <jhibbits@FreeBSD.org>
CommitDate: 2023-01-13 02:29:19 +0000

    Revert "ifnet/API: Move the IfAPI from if_var.h to if.h"
    
    <net/if.h> should be a fully user-facing header, so these APIs don't
    belong there.  Revert and will find another approach.
    
    This reverts commit fe33e0ab83d1fbc3c5cd4a2591ba0036e47b1fec.
    
    Fixes:          fe33e0ab83d1
    Sponsored by:   Juniper Networks, Inc.
---
 sys/net/if.h     | 157 -------------------------------------------------------
 sys/net/if_var.h | 145 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 145 insertions(+), 157 deletions(-)

diff --git a/sys/net/if.h b/sys/net/if.h
index b46cc0fa4747..888e7d5d7320 100644
--- a/sys/net/if.h
+++ b/sys/net/if.h
@@ -657,169 +657,12 @@ struct ifdownreason {
 
 typedef struct ifnet * if_t;
 
-union if_snd_tag_alloc_params;
-union if_snd_tag_query_params;
-union if_snd_tag_modify_params;
-
-typedef enum {
-	IFCOUNTER_IPACKETS = 0,
-	IFCOUNTER_IERRORS,
-	IFCOUNTER_OPACKETS,
-	IFCOUNTER_OERRORS,
-	IFCOUNTER_COLLISIONS,
-	IFCOUNTER_IBYTES,
-	IFCOUNTER_OBYTES,
-	IFCOUNTER_IMCASTS,
-	IFCOUNTER_OMCASTS,
-	IFCOUNTER_IQDROPS,
-	IFCOUNTER_OQDROPS,
-	IFCOUNTER_NOPROTO,
-	IFCOUNTERS /* Array size. */
-} ift_counter;
-
-
-struct mbuf;
-struct route;
-struct m_snd_tag;
-
-typedef	void (*if_start_fn_t)(if_t);
-typedef	int (*if_ioctl_fn_t)(if_t, u_long, caddr_t);
-typedef	void (*if_init_fn_t)(void *);
-typedef	void (*if_input_fn_t)(if_t, struct mbuf *);
-typedef	int (*if_output_fn_t)
-    (if_t, struct mbuf *, const struct sockaddr *, struct route *);
-typedef void (*if_qflush_fn_t)(if_t);
-typedef int (*if_transmit_fn_t)(if_t, struct mbuf *);
-typedef	uint64_t (*if_get_counter_t)(if_t, ift_counter);
-
-typedef int (if_snd_tag_alloc_t)(if_t, union if_snd_tag_alloc_params *,
-    struct m_snd_tag **);
-typedef int (if_snd_tag_modify_t)(struct m_snd_tag *, union if_snd_tag_modify_params *);
-typedef int (if_snd_tag_query_t)(struct m_snd_tag *, union if_snd_tag_query_params *);
-typedef void (if_snd_tag_free_t)(struct m_snd_tag *);
-typedef struct m_snd_tag *(if_next_send_tag_t)(struct m_snd_tag *);
-
 #ifdef _KERNEL
-
 #ifdef MALLOC_DECLARE
 MALLOC_DECLARE(M_IFADDR);
 MALLOC_DECLARE(M_IFMADDR);
 #endif
 
-struct	ifnet* if_alloc(u_char);
-struct	ifnet* if_alloc_dev(u_char, device_t dev);
-void	if_attach(if_t);
-void	if_free(if_t);
-void	if_initname(if_t, const char *, int);
-void	if_down(if_t);
-void	if_link_state_change(if_t, int);
-int	if_printf(if_t, const char *, ...) __printflike(2, 3);
-
-uint64_t if_get_counter_default(if_t, ift_counter);
-void	if_inc_counter(if_t, ift_counter, int64_t);
-
-uint64_t if_setbaudrate(if_t ifp, uint64_t baudrate);
-uint64_t if_getbaudrate(const if_t ifp);
-int if_setcapabilities(if_t ifp, int capabilities);
-int if_setcapabilitiesbit(if_t ifp, int setbit, int clearbit);
-int if_getcapabilities(const if_t ifp);
-int if_togglecapenable(if_t ifp, int togglecap);
-int if_setcapenable(if_t ifp, int capenable);
-int if_setcapenablebit(if_t ifp, int setcap, int clearcap);
-int if_getcapenable(const if_t ifp);
-int if_getdunit(const if_t ifp);
-int if_getindex(const if_t ifp);
-const char *if_getdname(const if_t ifp);
-void if_setdname(if_t ifp, const char *name);
-const char *if_name(if_t ifp);
-int if_setname(if_t ifp, const char *name);
-void if_setdescr(if_t ifp, char *descrbuf);
-char *if_allocdescr(size_t sz, int malloc_flag);
-void if_freedescr(char *descrbuf);
-int if_getalloctype(const if_t ifp);
-int if_setdev(if_t ifp, void *dev);
-int if_setdrvflagbits(if_t ifp, int if_setflags, int clear_flags);
-int if_getdrvflags(const if_t ifp);
-int if_setdrvflags(if_t ifp, int flags);
-int if_clearhwassist(if_t ifp);
-int if_sethwassistbits(if_t ifp, int toset, int toclear);
-int if_sethwassist(if_t ifp, int hwassist_bit);
-int if_gethwassist(const if_t ifp);
-int if_togglehwassist(if_t ifp, int toggle_bits);
-int if_setsoftc(if_t ifp, void *softc);
-void *if_getsoftc(if_t ifp);
-int if_setflags(if_t ifp, int flags);
-int if_gethwaddr(const if_t ifp, struct ifreq *);
-int if_setmtu(if_t ifp, int mtu);
-int if_getmtu(const if_t ifp);
-int if_getmtu_family(const if_t ifp, int family);
-int if_setflagbits(if_t ifp, int set, int clear);
-int if_getflags(const if_t ifp);
-int if_sendq_empty(if_t ifp);
-int if_setsendqready(if_t ifp);
-int if_setsendqlen(if_t ifp, int tx_desc_count);
-int if_sethwtsomax(if_t ifp, u_int if_hw_tsomax);
-int if_sethwtsomaxsegcount(if_t ifp, u_int if_hw_tsomaxsegcount);
-int if_sethwtsomaxsegsize(if_t ifp, u_int if_hw_tsomaxsegsize);
-u_int if_gethwtsomax(const if_t ifp);
-u_int if_gethwtsomaxsegcount(const if_t ifp);
-u_int if_gethwtsomaxsegsize(const if_t ifp);
-int if_input(if_t ifp, struct mbuf* sendmp);
-int if_sendq_prepend(if_t ifp, struct mbuf *m);
-struct mbuf *if_dequeue(if_t ifp);
-int if_setifheaderlen(if_t ifp, int len);
-void if_setrcvif(struct mbuf *m, if_t ifp);
-void if_setvtag(struct mbuf *m, u_int16_t tag);
-u_int16_t if_getvtag(struct mbuf *m);
-int if_vlantrunkinuse(if_t ifp);
-caddr_t if_getlladdr(const if_t ifp);
-void *if_gethandle(u_char);
-void if_bpfmtap(if_t ifp, struct mbuf *m);
-void if_etherbpfmtap(if_t ifp, struct mbuf *m);
-void if_vlancap(if_t ifp);
-int if_transmit(if_t ifp, struct mbuf *m);
-int if_init(if_t ifp);
-
-/*
- * Traversing through interface address lists.
- */
-struct sockaddr_dl;
-typedef u_int iflladdr_cb_t(void *, struct sockaddr_dl *, u_int);
-u_int if_foreach_lladdr(if_t, iflladdr_cb_t, void *);
-u_int if_foreach_llmaddr(if_t, iflladdr_cb_t, void *);
-u_int if_lladdr_count(if_t);
-u_int if_llmaddr_count(if_t);
-
-int if_getamcount(const if_t ifp);
-struct ifaddr * if_getifaddr(const if_t ifp);
-typedef u_int if_addr_cb_t(void *, struct ifaddr *, u_int);
-u_int if_foreach_addr_type(if_t ifp, int type, if_addr_cb_t cb, void *cb_arg);
-
-/* Functions */
-void if_setinitfn(if_t ifp, if_init_fn_t);
-void if_setinputfn(if_t ifp, if_input_fn_t);
-void if_setioctlfn(if_t ifp, if_ioctl_fn_t);
-void if_setoutputfn(if_t ifp, int(*)
-    (if_t, struct mbuf *, const struct sockaddr *, struct route *));
-void if_setstartfn(if_t ifp, void (*)(if_t));
-void if_settransmitfn(if_t ifp, if_transmit_fn_t);
-void if_setqflushfn(if_t ifp, if_qflush_fn_t);
-void if_setgetcounterfn(if_t ifp, if_get_counter_t);
-void if_setsndtagallocfn(if_t ifp, if_snd_tag_alloc_t);
-
-/* accessors for struct ifreq */
-void *ifr_data_get_ptr(void *ifrp);
-void *ifr_buffer_get_buffer(void *data);
-size_t ifr_buffer_get_length(void *data);
-
-#ifdef DEVICE_POLLING
-enum poll_cmd { POLL_ONLY, POLL_AND_CHECK_STATUS };
-
-typedef	int poll_handler_t(if_t ifp, enum poll_cmd cmd, int count);
-int    ether_poll_register(poll_handler_t *h, if_t ifp);
-int    ether_poll_deregister(if_t ifp);
-#endif /* DEVICE_POLLING */
-
 extern struct sx ifnet_detach_sxlock;
 
 struct nvlist;
diff --git a/sys/net/if_var.h b/sys/net/if_var.h
index 1aaabc8e3124..2712ac74a09d 100644
--- a/sys/net/if_var.h
+++ b/sys/net/if_var.h
@@ -108,6 +108,32 @@ VNET_DECLARE(struct hhook_head *, ipsec_hhh_out[HHOOK_IPSEC_COUNT]);
 #define	V_ipsec_hhh_out	VNET(ipsec_hhh_out)
 #endif /* _KERNEL */
 
+typedef enum {
+	IFCOUNTER_IPACKETS = 0,
+	IFCOUNTER_IERRORS,
+	IFCOUNTER_OPACKETS,
+	IFCOUNTER_OERRORS,
+	IFCOUNTER_COLLISIONS,
+	IFCOUNTER_IBYTES,
+	IFCOUNTER_OBYTES,
+	IFCOUNTER_IMCASTS,
+	IFCOUNTER_OMCASTS,
+	IFCOUNTER_IQDROPS,
+	IFCOUNTER_OQDROPS,
+	IFCOUNTER_NOPROTO,
+	IFCOUNTERS /* Array size. */
+} ift_counter;
+
+typedef	void (*if_start_fn_t)(if_t);
+typedef	int (*if_ioctl_fn_t)(if_t, u_long, caddr_t);
+typedef	void (*if_init_fn_t)(void *);
+typedef	void (*if_input_fn_t)(struct ifnet *, struct mbuf *);
+typedef	int (*if_output_fn_t)
+    (struct ifnet *, struct mbuf *, const struct sockaddr *, struct route *);
+typedef void (*if_qflush_fn_t)(if_t);
+typedef int (*if_transmit_fn_t)(if_t, struct mbuf *);
+typedef	uint64_t (*if_get_counter_t)(if_t, ift_counter);
+
 struct ifnet_hw_tsomax {
 	u_int	tsomaxbytes;	/* TSO total burst length limit in bytes */
 	u_int	tsomaxsegcount;	/* TSO maximum segment count */
@@ -248,6 +274,13 @@ union if_snd_tag_query_params {
 	struct if_snd_tag_rate_limit_params tls_rate_limit;
 };
 
+typedef int (if_snd_tag_alloc_t)(struct ifnet *, union if_snd_tag_alloc_params *,
+    struct m_snd_tag **);
+typedef int (if_snd_tag_modify_t)(struct m_snd_tag *, union if_snd_tag_modify_params *);
+typedef int (if_snd_tag_query_t)(struct m_snd_tag *, union if_snd_tag_query_params *);
+typedef void (if_snd_tag_free_t)(struct m_snd_tag *);
+typedef struct m_snd_tag *(if_next_send_tag_t)(struct m_snd_tag *);
+
 struct if_snd_tag_sw {
 	if_snd_tag_modify_t *snd_tag_modify;
 	if_snd_tag_query_t *snd_tag_query;
@@ -634,6 +667,9 @@ int	if_addgroup(struct ifnet *, const char *);
 int	if_delgroup(struct ifnet *, const char *);
 int	if_addmulti(struct ifnet *, struct sockaddr *, struct ifmultiaddr **);
 int	if_allmulti(struct ifnet *, int);
+struct	ifnet* if_alloc(u_char);
+struct	ifnet* if_alloc_dev(u_char, device_t dev);
+void	if_attach(struct ifnet *);
 void	if_dead(struct ifnet *);
 int	if_delmulti(struct ifnet *, struct sockaddr *);
 void	if_delmulti_ifma(struct ifmultiaddr *);
@@ -641,9 +677,14 @@ void	if_delmulti_ifma_flags(struct ifmultiaddr *, int flags);
 void	if_detach(struct ifnet *);
 void	if_purgeaddrs(struct ifnet *);
 void	if_delallmulti(struct ifnet *);
+void	if_down(struct ifnet *);
 struct ifmultiaddr *
 	if_findmulti(struct ifnet *, const struct sockaddr *);
 void	if_freemulti(struct ifmultiaddr *ifma);
+void	if_free(struct ifnet *);
+void	if_initname(struct ifnet *, const char *, int);
+void	if_link_state_change(struct ifnet *, int);
+int	if_printf(struct ifnet *, const char *, ...) __printflike(2, 3);
 int	if_log(struct ifnet *, int, const char *, ...) __printflike(3, 4);
 void	if_ref(struct ifnet *);
 void	if_rele(struct ifnet *);
@@ -677,16 +718,120 @@ typedef	void if_com_free_t(void *com, u_char type);
 void	if_register_com_alloc(u_char type, if_com_alloc_t *a, if_com_free_t *f);
 void	if_deregister_com_alloc(u_char type);
 void	if_data_copy(struct ifnet *, struct if_data *);
+uint64_t if_get_counter_default(struct ifnet *, ift_counter);
+void	if_inc_counter(struct ifnet *, ift_counter, int64_t);
 
 #define IF_LLADDR(ifp)							\
     LLADDR((struct sockaddr_dl *)((ifp)->if_addr->ifa_addr))
 
+uint64_t if_setbaudrate(if_t ifp, uint64_t baudrate);
+uint64_t if_getbaudrate(const if_t ifp);
+int if_setcapabilities(if_t ifp, int capabilities);
+int if_setcapabilitiesbit(if_t ifp, int setbit, int clearbit);
+int if_getcapabilities(const if_t ifp);
+int if_togglecapenable(if_t ifp, int togglecap);
+int if_setcapenable(if_t ifp, int capenable);
+int if_setcapenablebit(if_t ifp, int setcap, int clearcap);
+int if_getcapenable(const if_t ifp);
+int if_getdunit(const if_t ifp);
+int if_getindex(const if_t ifp);
+const char *if_getdname(const if_t ifp);
+void if_setdname(if_t ifp, const char *name);
+const char *if_name(if_t ifp);
+int if_setname(if_t ifp, const char *name);
+void if_setdescr(if_t ifp, char *descrbuf);
+char *if_allocdescr(size_t sz, int malloc_flag);
+void if_freedescr(char *descrbuf);
+int if_getalloctype(const if_t ifp);
+int if_setdev(if_t ifp, void *dev);
+int if_setdrvflagbits(if_t ifp, int if_setflags, int clear_flags);
+int if_getdrvflags(const if_t ifp);
+int if_setdrvflags(if_t ifp, int flags);
+int if_clearhwassist(if_t ifp);
+int if_sethwassistbits(if_t ifp, int toset, int toclear);
+int if_sethwassist(if_t ifp, int hwassist_bit);
+int if_gethwassist(const if_t ifp);
+int if_togglehwassist(if_t ifp, int toggle_bits);
+int if_setsoftc(if_t ifp, void *softc);
+void *if_getsoftc(if_t ifp);
+int if_setflags(if_t ifp, int flags);
+int if_gethwaddr(const if_t ifp, struct ifreq *);
+int if_setmtu(if_t ifp, int mtu);
+int if_getmtu(const if_t ifp);
+int if_getmtu_family(const if_t ifp, int family);
+int if_setflagbits(if_t ifp, int set, int clear);
+int if_getflags(const if_t ifp);
+int if_sendq_empty(if_t ifp);
+int if_setsendqready(if_t ifp);
+int if_setsendqlen(if_t ifp, int tx_desc_count);
+int if_sethwtsomax(if_t ifp, u_int if_hw_tsomax);
+int if_sethwtsomaxsegcount(if_t ifp, u_int if_hw_tsomaxsegcount);
+int if_sethwtsomaxsegsize(if_t ifp, u_int if_hw_tsomaxsegsize);
+u_int if_gethwtsomax(const if_t ifp);
+u_int if_gethwtsomaxsegcount(const if_t ifp);
+u_int if_gethwtsomaxsegsize(const if_t ifp);
+int if_input(if_t ifp, struct mbuf* sendmp);
+int if_sendq_prepend(if_t ifp, struct mbuf *m);
+struct mbuf *if_dequeue(if_t ifp);
+int if_setifheaderlen(if_t ifp, int len);
+void if_setrcvif(struct mbuf *m, if_t ifp);
+void if_setvtag(struct mbuf *m, u_int16_t tag);
+u_int16_t if_getvtag(struct mbuf *m);
+int if_vlantrunkinuse(if_t ifp);
+caddr_t if_getlladdr(const if_t ifp);
+void *if_gethandle(u_char);
+void if_bpfmtap(if_t ifp, struct mbuf *m);
+void if_etherbpfmtap(if_t ifp, struct mbuf *m);
+void if_vlancap(if_t ifp);
+int if_transmit(if_t ifp, struct mbuf *m);
+int if_init(if_t ifp);
+
+/*
+ * Traversing through interface address lists.
+ */
+struct sockaddr_dl;
+typedef u_int iflladdr_cb_t(void *, struct sockaddr_dl *, u_int);
+u_int if_foreach_lladdr(if_t, iflladdr_cb_t, void *);
+u_int if_foreach_llmaddr(if_t, iflladdr_cb_t, void *);
+u_int if_lladdr_count(if_t);
+u_int if_llmaddr_count(if_t);
+
+int if_getamcount(const if_t ifp);
+struct ifaddr * if_getifaddr(const if_t ifp);
+typedef u_int if_addr_cb_t(void *, struct ifaddr *, u_int);
+u_int if_foreach_addr_type(if_t ifp, int type, if_addr_cb_t cb, void *cb_arg);
+
+/* Functions */
+void if_setinitfn(if_t ifp, if_init_fn_t);
+void if_setinputfn(if_t ifp, if_input_fn_t);
+void if_setioctlfn(if_t ifp, if_ioctl_fn_t);
+void if_setoutputfn(if_t ifp, int(*)
+    (if_t, struct mbuf *, const struct sockaddr *, struct route *));
+void if_setstartfn(if_t ifp, void (*)(if_t));
+void if_settransmitfn(if_t ifp, if_transmit_fn_t);
+void if_setqflushfn(if_t ifp, if_qflush_fn_t);
+void if_setgetcounterfn(if_t ifp, if_get_counter_t);
+void if_setsndtagallocfn(if_t ifp, if_snd_tag_alloc_t);
+
 /* TSO */
 void if_hw_tsomax_common(if_t ifp, struct ifnet_hw_tsomax *);
 int if_hw_tsomax_update(if_t ifp, struct ifnet_hw_tsomax *);
 
+/* accessors for struct ifreq */
+void *ifr_data_get_ptr(void *ifrp);
+void *ifr_buffer_get_buffer(void *data);
+size_t ifr_buffer_get_length(void *data);
+
 int ifhwioctl(u_long, struct ifnet *, caddr_t, struct thread *);
 
+#ifdef DEVICE_POLLING
+enum poll_cmd { POLL_ONLY, POLL_AND_CHECK_STATUS };
+
+typedef	int poll_handler_t(if_t ifp, enum poll_cmd cmd, int count);
+int    ether_poll_register(poll_handler_t *h, if_t ifp);
+int    ether_poll_deregister(if_t ifp);
+#endif /* DEVICE_POLLING */
+
 #endif /* _KERNEL */
 
 #include <net/ifq.h>	/* XXXAO: temporary unconditional include */