aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--share/man/man4/epair.422
-rw-r--r--sys/net/if_epair.c35
2 files changed, 48 insertions, 9 deletions
diff --git a/share/man/man4/epair.4 b/share/man/man4/epair.4
index 4bcb54c936cb..342b15b5612a 100644
--- a/share/man/man4/epair.4
+++ b/share/man/man4/epair.4
@@ -25,7 +25,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd March 18, 2015
+.Dd August 12, 2025
.Dt EPAIR 4
.Os
.Sh NAME
@@ -79,12 +79,24 @@ and
Like any other Ethernet interface, an
.Nm
needs to have a network address.
-Each
+If the tunable
+.Va net.link.epair.ether_gen_addr Ns
+=0, each
.Nm
-will be assigned a locally administered address by default,
+will be assigned a random locally administered address,
that is only guaranteed to be unique within one network stack.
-To change the default addresses one may use the SIOCSIFADDR ioctl(2) or
-ifconfig(8) utility.
+The tunable
+.Va net.link.epair.ether_gen_addr Ns
+=1 will generate a stable MAC address with
+.Fx
+OUI using
+.Xr ether_gen_addr 9 .
+This tunable defaults to 1 in
+.Fx 15.0 and might be removed in
+.Fx 16.0 .
+To change the default addresses one may use the SIOCSIFADDR
+.Xr ioctl 2 or
+.Xr ifconfig 8 utility.
.Pp
The basic intent is to provide connectivity between two virtual
network stack instances.
diff --git a/sys/net/if_epair.c b/sys/net/if_epair.c
index 988930998dad..e7327ec71a42 100644
--- a/sys/net/if_epair.c
+++ b/sys/net/if_epair.c
@@ -58,6 +58,7 @@
#include <sys/smp.h>
#include <sys/socket.h>
#include <sys/sockio.h>
+#include <sys/sysctl.h>
#include <sys/taskqueue.h>
#include <net/bpf.h>
@@ -96,6 +97,15 @@ static unsigned int next_index = 0;
#define EPAIR_LOCK() mtx_lock(&epair_n_index_mtx)
#define EPAIR_UNLOCK() mtx_unlock(&epair_n_index_mtx)
+SYSCTL_DECL(_net_link);
+static SYSCTL_NODE(_net_link, OID_AUTO, epair, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,
+ "Pair of virtual cross-over connected Ethernet-like interfaces");
+
+static bool use_ether_gen_addr = false;
+SYSCTL_BOOL(_net_link_epair, OID_AUTO, ether_gen_addr, CTLFLAG_RWTUN,
+ &use_ether_gen_addr, false,
+ "Generate MAC with FreeBSD OUI using ether_gen_addr(9)");
+
struct epair_softc;
struct epair_queue {
struct mtx mtx;
@@ -495,15 +505,29 @@ epair_clone_match(struct if_clone *ifc, const char *name)
}
static void
+epair_generate_mac_byname(struct epair_softc *sc, uint8_t eaddr[])
+{
+ struct ether_addr gen_eaddr;
+ int i;
+
+ ether_gen_addr_byname(if_name(sc->ifp), &gen_eaddr);
+ for (i = 0; i < ETHER_ADDR_LEN; i++)
+ eaddr[i] = gen_eaddr.octet[i];
+}
+
+static void
epair_clone_add(struct if_clone *ifc, struct epair_softc *scb)
{
struct ifnet *ifp;
uint8_t eaddr[ETHER_ADDR_LEN]; /* 00:00:00:00:00:00 */
ifp = scb->ifp;
- /* Copy epairNa etheraddr and change the last byte. */
- memcpy(eaddr, scb->oifp->if_hw_addr, ETHER_ADDR_LEN);
- eaddr[5] = 0x0b;
+ if (!use_ether_gen_addr) {
+ /* Copy epairNa etheraddr and change the last byte. */
+ memcpy(eaddr, scb->oifp->if_hw_addr, ETHER_ADDR_LEN);
+ eaddr[5] = 0x0b;
+ } else
+ epair_generate_mac_byname(scb, eaddr);
ether_ifattach(ifp, eaddr);
if_clone_addif(ifc, ifp);
@@ -718,7 +742,10 @@ epair_clone_create(struct if_clone *ifc, char *name, size_t len,
/* Finish initialization of interface <n>a. */
ifp = sca->ifp;
epair_setup_ifp(sca, name, unit);
- epair_generate_mac(sca, eaddr);
+ if (!use_ether_gen_addr)
+ epair_generate_mac(sca, eaddr);
+ else
+ epair_generate_mac_byname(sca, eaddr);
ether_ifattach(ifp, eaddr);