git: 0d2684e15e41 - main - IfAPI: Add some more accessors
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 31 Jan 2023 20:03:19 UTC
The branch main has been updated by jhibbits:
URL: https://cgit.FreeBSD.org/src/commit/?id=0d2684e15e415cef652e0f75e88962a674bffe04
commit 0d2684e15e415cef652e0f75e88962a674bffe04
Author: Justin Hibbits <jhibbits@FreeBSD.org>
AuthorDate: 2023-01-24 21:12:08 +0000
Commit: Justin Hibbits <jhibbits@FreeBSD.org>
CommitDate: 2023-01-31 20:02:17 +0000
IfAPI: Add some more accessors
Summary:
* if_setreassignfn for wireguard.
* if_getinputfn() and if_getstartfn() for various drivers. Use the
function descriptor typedefs for these and the setters.
* vlantrunk accessor. This is used by VLAN_CAPABILITIES() used by
several drivers, as well as directly by mxge(4).
* if_pcp member accessor, used by cxgbe.
* accessors for netmap adapter.
Sponsored by: Juniper Networks, Inc.
Reviewed By: glebius
Differential Revision: https://reviews.freebsd.org/D38202
---
sys/net/if.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++
sys/net/if_private.h | 3 +-
sys/net/if_var.h | 24 ++++++++++--
sys/net/if_vlan_var.h | 4 +-
4 files changed, 126 insertions(+), 7 deletions(-)
diff --git a/sys/net/if.c b/sys/net/if.c
index 1a42b562190d..ac8b6963172d 100644
--- a/sys/net/if.c
+++ b/sys/net/if.c
@@ -4616,6 +4616,18 @@ if_setsendqlen(if_t ifp, int tx_desc_count)
return (0);
}
+void
+if_setnetmapadapter(if_t ifp, struct netmap_adapter *na)
+{
+ ifp->if_netmap = na;
+}
+
+struct netmap_adapter *
+if_getnetmapadapter(if_t ifp)
+{
+ return (ifp->if_netmap);
+}
+
int
if_vlantrunkinuse(if_t ifp)
{
@@ -4759,6 +4771,12 @@ if_setinputfn(if_t ifp, if_input_fn_t input_fn)
((struct ifnet *)ifp)->if_input = input_fn;
}
+if_input_fn_t
+if_getinputfn(if_t ifp)
+{
+ return (ifp->if_input);
+}
+
void
if_setioctlfn(if_t ifp, if_ioctl_fn_t ioctl_fn)
{
@@ -4777,12 +4795,24 @@ if_setstartfn(if_t ifp, if_start_fn_t start_fn)
((struct ifnet *)ifp)->if_start = (void *)start_fn;
}
+if_start_fn_t
+if_getstartfn(if_t ifp)
+{
+ return (ifp->if_start);
+}
+
void
if_settransmitfn(if_t ifp, if_transmit_fn_t start_fn)
{
((struct ifnet *)ifp)->if_transmit = start_fn;
}
+if_transmit_fn_t
+if_gettransmitfn(if_t ifp)
+{
+ return (ifp->if_transmit);
+}
+
void
if_setqflushfn(if_t ifp, if_qflush_fn_t flush_fn)
{
@@ -4803,6 +4833,18 @@ if_setgetcounterfn(if_t ifp, if_get_counter_t fn)
ifp->if_get_counter = fn;
}
+void
+if_setreassignfn(if_t ifp, if_reassign_fn_t fn)
+{
+ ifp->if_reassign = fn;
+}
+
+void
+if_setratelimitqueryfn(if_t ifp, if_ratelimit_query_t fn)
+{
+ ifp->if_ratelimit_query = fn;
+}
+
void
if_setdebugnet_methods(if_t ifp, struct debugnet_methods *m)
{
@@ -4839,6 +4881,66 @@ if_setllsoftc(if_t ifp, void *llsoftc)
ifp->if_llsoftc = llsoftc;
};
+int
+if_getlinkstate(if_t ifp)
+{
+ return (ifp->if_link_state);
+}
+
+const uint8_t *
+if_getbroadcastaddr(if_t ifp)
+{
+ return (ifp->if_broadcastaddr);
+}
+
+int
+if_getnumadomain(if_t ifp)
+{
+ return (ifp->if_numa_domain);
+}
+
+uint64_t
+if_getcounter(if_t ifp, ift_counter counter)
+{
+ return (ifp->if_get_counter(ifp, counter));
+}
+
+struct vnet *
+if_getvnet(if_t ifp)
+{
+ return (ifp->if_vnet);
+}
+
+void *
+if_getafdata(if_t ifp, int af)
+{
+ return (ifp->if_afdata[af]);
+}
+
+u_int
+if_getfib(if_t ifp)
+{
+ return (ifp->if_fib);
+}
+
+struct bpf_if *
+if_getbpf(if_t ifp)
+{
+ return (ifp->if_bpf);
+}
+
+struct ifvlantrunk *
+if_getvlantrunk(if_t ifp)
+{
+ return (ifp->if_vlantrunk);
+}
+
+uint8_t
+if_getpcp(if_t ifp)
+{
+ return (ifp->if_pcp);
+}
+
#ifdef DDB
static void
if_show_ifnet(struct ifnet *ifp)
diff --git a/sys/net/if_private.h b/sys/net/if_private.h
index 70212e79d077..64ebf83f5850 100644
--- a/sys/net/if_private.h
+++ b/sys/net/if_private.h
@@ -135,8 +135,7 @@ struct ifnet {
if_qflush_fn_t if_qflush; /* flush any queue */
if_transmit_fn_t if_transmit; /* initiate output routine */
- void (*if_reassign) /* reassign to vnet routine */
- (struct ifnet *, struct vnet *, char *);
+ if_reassign_fn_t if_reassign; /* reassign to vnet routine */
if_get_counter_t if_get_counter; /* get counter values */
int (*if_requestencap) /* make link header from request */
(struct ifnet *, struct if_encap_req *);
diff --git a/sys/net/if_var.h b/sys/net/if_var.h
index 3b293cdff26f..be7a5f059a7e 100644
--- a/sys/net/if_var.h
+++ b/sys/net/if_var.h
@@ -133,6 +133,7 @@ typedef int (*if_output_fn_t)
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 void (*if_reassign_fn_t)(struct ifnet *, struct vnet *, char *);
struct ifnet_hw_tsomax {
u_int tsomaxbytes; /* TSO total burst length limit in bytes */
@@ -590,6 +591,7 @@ 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_getlinkstate(if_t ifp);
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);
@@ -600,12 +602,16 @@ void *if_getsoftc(if_t ifp);
int if_setflags(if_t ifp, int flags);
void if_setllsoftc(if_t ifp, void *softc);
void *if_getllsoftc(if_t ifp);
+u_int if_getfib(if_t ifp);
int if_gethwaddr(const if_t ifp, struct ifreq *);
+const uint8_t *if_getbroadcastaddr(const if_t ifp);
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_setflags(if_t ifp, int flags);
int if_getflags(const if_t ifp);
+int if_getnumadomain(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);
@@ -615,6 +621,8 @@ 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);
+void if_setnetmapadapter(if_t ifp, struct netmap_adapter *na);
+struct netmap_adapter *if_getnetmapadapter(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);
@@ -624,14 +632,20 @@ 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);
+struct vnet *if_getvnet(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, void *ctx);
+uint64_t if_getcounter(if_t ifp, ift_counter counter);
struct label *if_getmaclabel(if_t ifp);
void if_setmaclabel(if_t ifp, struct label *label);
+struct bpf_if *if_getbpf(if_t ifp);
+uint8_t if_getpcp(if_t ifp);
+struct ifvlantrunk *if_getvlantrunk(if_t ifp);
+void *if_getafdata(if_t ifp, int);
/*
* Traversing through interface address lists.
@@ -651,15 +665,19 @@ 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);
+if_input_fn_t if_getinputfn(if_t ifp);
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_setoutputfn(if_t ifp, if_output_fn_t);
+void if_setstartfn(if_t ifp, if_start_fn_t);
+if_start_fn_t if_getstartfn(if_t ifp);
void if_settransmitfn(if_t ifp, if_transmit_fn_t);
+if_transmit_fn_t if_gettransmitfn(if_t ifp);
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);
void if_setdebugnet_methods(struct ifnet *, struct debugnet_methods *);
+void if_setreassignfn(if_t ifp, if_reassign_fn_t);
+void if_setratelimitqueryfn(if_t ifp, if_ratelimit_query_t);
/* TSO */
void if_hw_tsomax_common(if_t ifp, struct ifnet_hw_tsomax *);
diff --git a/sys/net/if_vlan_var.h b/sys/net/if_vlan_var.h
index b383d0898c9a..fb05cddc03bd 100644
--- a/sys/net/if_vlan_var.h
+++ b/sys/net/if_vlan_var.h
@@ -138,7 +138,7 @@ struct ether_8021q_tag {
};
#define VLAN_CAPABILITIES(_ifp) do { \
- if ((_ifp)->if_vlantrunk != NULL) \
+ if (if_getvlantrunk(_ifp) != NULL) \
(*vlan_trunk_cap_p)(_ifp); \
} while (0)
@@ -154,7 +154,7 @@ struct ether_8021q_tag {
(if_gettype(_ifp) == IFT_L2VLAN ? \
(*vlan_setcookie_p)((_ifp), (_cookie)) : EINVAL)
#define VLAN_DEVAT(_ifp, _vid) \
- ((_ifp)->if_vlantrunk != NULL ? (*vlan_devat_p)((_ifp), (_vid)) : NULL)
+ (if_getvlantrunk(_ifp) != NULL ? (*vlan_devat_p)((_ifp), (_vid)) : NULL)
extern void (*vlan_trunk_cap_p)(struct ifnet *);
extern struct ifnet *(*vlan_trunkdev_p)(struct ifnet *);