git: ef27f784697c - main - ifconfig(8): show parent device for USB Ethernet interfaces

From: Li-Wen Hsu <lwhsu_at_FreeBSD.org>
Date: Sun, 27 Sep 2026 19:31:38 UTC
The branch main has been updated by lwhsu:

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

commit ef27f784697c4f9d95a0d343b1001028714f4687
Author:     Li-Wen Hsu <lwhsu@FreeBSD.org>
AuthorDate: 2026-09-27 19:31:12 +0000
Commit:     Li-Wen Hsu <lwhsu@FreeBSD.org>
CommitDate: 2026-09-27 19:31:12 +0000

    ifconfig(8): show parent device for USB Ethernet interfaces
    
    Report net.ue.<unit>.%parent as "parent interface", consistent with
    wlan(4):
    
      # ifconfig ue0
      ue0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
              ether 00:00:5e:00:53:2a
              inet 192.0.2.10/24 broadcast 192.0.2.255
              parent interface: ure0
              media: Ethernet autoselect (2500Base-T <full-duplex>)
              status: active
    
    Reviewed by:    aokblast
    MFC after:      2 weeks
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D59060
---
 sbin/ifconfig/Makefile |  4 ++++
 sbin/ifconfig/ifue.c   | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 66 insertions(+)

diff --git a/sbin/ifconfig/Makefile b/sbin/ifconfig/Makefile
index fa3cc26a3023..b5824803c402 100644
--- a/sbin/ifconfig/Makefile
+++ b/sbin/ifconfig/Makefile
@@ -43,6 +43,10 @@ SRCS+=	ifieee80211.c		# SIOC[GS]IEEE80211 support
 LIBADD+=	80211
 .endif
 
+.if ${MK_USB} != "no"
+SRCS+=	ifue.c
+.endif
+
 SRCS+=	carp.c			# SIOC[GS]VH support
 SRCS+=	ifgroup.c		# ...
 .if ${MK_PF} != "no"
diff --git a/sbin/ifconfig/ifue.c b/sbin/ifconfig/ifue.c
new file mode 100644
index 000000000000..7908db71a2e4
--- /dev/null
+++ b/sbin/ifconfig/ifue.c
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2026 The FreeBSD Foundation
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * This software was developed by Li-Wen Hsu <lwhsu@FreeBSD.org>
+ * under sponsorship from the FreeBSD Foundation.
+ */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/sysctl.h>
+
+#include <net/if.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "ifconfig.h"
+
+#define	UE_DRIVER_NAME	"ue"
+
+static void
+ue_status(if_ctx *ctx)
+{
+	char mibname[32];	/* "net.ue.<unit>.%parent" */
+	char parent[IFNAMSIZ];
+	char *drivername;
+	size_t parentlen;
+	u_int unit;
+	char c;
+
+	/* Use the orig name so it keeps working after interface renaming. */
+	if (ifconfig_get_orig_name(lifh, ctx->ifname, &drivername) != 0)
+		return;
+	if (sscanf(drivername, UE_DRIVER_NAME "%u%c", &unit, &c) != 1)
+		goto out;
+
+	if (snprintf(mibname, sizeof(mibname),
+	    "net." UE_DRIVER_NAME ".%u.%%parent", unit) >= (int)sizeof(mibname))
+		goto out;
+
+	parentlen = sizeof(parent);
+	if (sysctlbyname(mibname, parent, &parentlen, NULL, 0) != 0)
+		goto out;
+
+	printf("\tparent interface: %s\n", parent);
+out:
+	free(drivername);
+}
+
+static struct afswtch af_ue = {
+	.af_name	= "af_ue",
+	.af_af		= AF_UNSPEC,
+	.af_other_status = ue_status,
+};
+
+static __constructor void
+ue_ctor(void)
+{
+	af_register(&af_ue);
+}