vxlan: Add support for socket ioctls SIOC[SG]TUNFIB

Submitted by: Luiz Amaral <email@luiz.eng.br>
PR: 244004
Differential Revision:	https://reviews.freebsd.org/D32820
MFC after:	2 weeks
This commit is contained in:
Zhenlei Huang 2022-07-08 18:12:14 +00:00 committed by Alexander V. Chernikov
parent 9e9ba3cdbe
commit 7f7a804ae0
2 changed files with 28 additions and 4 deletions

View File

@ -520,9 +520,10 @@ Specify tunnel FIB.
A FIB
.Ar fib_number
is assigned to all packets encapsulated by tunnel interface, e.g.,
.Xr gif 4
.Xr gif 4 ,
.Xr gre 4
and
.Xr gre 4 .
.Xr vxlan 4 .
.It Cm maclabel Ar label
If Mandatory Access Control support is enabled in the kernel,
set the MAC label to

View File

@ -163,6 +163,7 @@ struct vxlan_statistics {
struct vxlan_softc {
struct ifnet *vxl_ifp;
int vxl_reqcap;
u_int vxl_fibnum;
struct vxlan_socket *vxl_sock;
uint32_t vxl_vni;
union vxlan_sockaddr vxl_src_addr;
@ -2329,6 +2330,7 @@ vxlan_ioctl_drvspec(struct vxlan_softc *sc, struct ifdrv *ifd, int get)
static int
vxlan_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
{
struct rm_priotracker tracker;
struct vxlan_softc *sc;
struct ifreq *ifr;
struct ifdrv *ifd;
@ -2378,6 +2380,25 @@ vxlan_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
VXLAN_WUNLOCK(sc);
break;
case SIOCGTUNFIB:
VXLAN_RLOCK(sc, &tracker);
ifr->ifr_fib = sc->vxl_fibnum;
VXLAN_RUNLOCK(sc, &tracker);
break;
case SIOCSTUNFIB:
if ((error = priv_check(curthread, PRIV_NET_VXLAN)) != 0)
break;
if (ifr->ifr_fib >= rt_numfibs)
error = EINVAL;
else {
VXLAN_WLOCK(sc);
sc->vxl_fibnum = ifr->ifr_fib;
VXLAN_WUNLOCK(sc);
}
break;
default:
error = ether_ioctl(ifp, cmd, data);
break;
@ -2533,7 +2554,7 @@ vxlan_encap4(struct vxlan_softc *sc, const union vxlan_sockaddr *fvxlsa,
sin->sin_family = AF_INET;
sin->sin_len = sizeof(*sin);
sin->sin_addr = ip->ip_dst;
ro->ro_nh = fib4_lookup(RT_DEFAULT_FIB, ip->ip_dst, 0, NHR_NONE,
ro->ro_nh = fib4_lookup(M_GETFIB(m), ip->ip_dst, 0, NHR_NONE,
0);
if (ro->ro_nh == NULL) {
m_freem(m);
@ -2645,7 +2666,7 @@ vxlan_encap6(struct vxlan_softc *sc, const union vxlan_sockaddr *fvxlsa,
sin6->sin6_family = AF_INET6;
sin6->sin6_len = sizeof(*sin6);
sin6->sin6_addr = ip6->ip6_dst;
ro->ro_nh = fib6_lookup(RT_DEFAULT_FIB, &ip6->ip6_dst, 0,
ro->ro_nh = fib6_lookup(M_GETFIB(m), &ip6->ip6_dst, 0,
NHR_NONE, 0);
if (ro->ro_nh == NULL) {
m_freem(m);
@ -2722,6 +2743,7 @@ vxlan_transmit(struct ifnet *ifp, struct mbuf *m)
ETHER_BPF_MTAP(ifp, m);
VXLAN_RLOCK(sc, &tracker);
M_SETFIB(m, sc->vxl_fibnum);
if ((ifp->if_drv_flags & IFF_DRV_RUNNING) == 0) {
VXLAN_RUNLOCK(sc, &tracker);
m_freem(m);
@ -3181,6 +3203,7 @@ vxlan_clone_create(struct if_clone *ifc, int unit, caddr_t params)
sc = malloc(sizeof(struct vxlan_softc), M_VXLAN, M_WAITOK | M_ZERO);
sc->vxl_unit = unit;
sc->vxl_fibnum = curthread->td_proc->p_fibnum;
vxlan_set_default_config(sc);
error = vxlan_stats_alloc(sc);
if (error != 0)