1 /*
2 * Copyright (c) 2026 The FreeBSD Foundation
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 *
6 * This software was developed by Li-Wen Hsu <lwhsu@FreeBSD.org>
7 * under sponsorship from the FreeBSD Foundation.
8 */
9
10 #include <sys/types.h>
11 #include <sys/socket.h>
12 #include <sys/sysctl.h>
13
14 #include <net/if.h>
15
16 #include <stdio.h>
17 #include <stdlib.h>
18
19 #include "ifconfig.h"
20
21 #define UE_DRIVER_NAME "ue"
22
23 static void
ue_status(if_ctx * ctx)24 ue_status(if_ctx *ctx)
25 {
26 char mibname[32]; /* "net.ue.<unit>.%parent" */
27 char parent[IFNAMSIZ];
28 char *drivername;
29 size_t parentlen;
30 u_int unit;
31 char c;
32
33 /* Use the orig name so it keeps working after interface renaming. */
34 if (ifconfig_get_orig_name(lifh, ctx->ifname, &drivername) != 0)
35 return;
36 if (sscanf(drivername, UE_DRIVER_NAME "%u%c", &unit, &c) != 1)
37 goto out;
38
39 if (snprintf(mibname, sizeof(mibname),
40 "net." UE_DRIVER_NAME ".%u.%%parent", unit) >= (int)sizeof(mibname))
41 goto out;
42
43 parentlen = sizeof(parent);
44 if (sysctlbyname(mibname, parent, &parentlen, NULL, 0) != 0)
45 goto out;
46
47 printf("\tparent interface: %s\n", parent);
48 out:
49 free(drivername);
50 }
51
52 static struct afswtch af_ue = {
53 .af_name = "af_ue",
54 .af_af = AF_UNSPEC,
55 .af_other_status = ue_status,
56 };
57
58 static __constructor void
ue_ctor(void)59 ue_ctor(void)
60 {
61 af_register(&af_ue);
62 }
63