Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F144331014
D40440.id122894.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
D40440.id122894.diff
View Options
diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c
--- a/sbin/ifconfig/ifconfig.c
+++ b/sbin/ifconfig/ifconfig.c
@@ -111,8 +111,8 @@
char *f_inet, *f_inet6, *f_ether, *f_addr;
#ifdef WITHOUT_NETLINK
-static void list_interfaces_ioctl(struct ifconfig_args *args);
-static void status(struct ifconfig_args *args, const struct sockaddr_dl *sdl,
+static void list_interfaces_ioctl(if_ctx *ctx);
+static void status(if_ctx *ctx, const struct sockaddr_dl *sdl,
struct ifaddrs *ifa);
#endif
static _Noreturn void usage(void);
@@ -422,12 +422,12 @@
}
static void
-list_interfaces(struct ifconfig_args *args)
+list_interfaces(if_ctx *ctx)
{
#ifdef WITHOUT_NETLINK
- list_interfaces_ioctl(args);
+ list_interfaces_ioctl(ctx);
#else
- list_interfaces_nl(args);
+ list_interfaces_nl(ctx->args);
#endif
}
@@ -571,19 +571,13 @@
}
static int
-ifconfig_wrapper(struct ifconfig_args *args, int iscreate,
+ifconfig_wrapper(if_ctx *ctx, int iscreate,
const struct afswtch *uafp)
{
- struct ifconfig_context ctx = {
- .args = args,
- .io_s = -1,
- .ifname = args->ifname,
- };
-
#ifdef WITHOUT_NETLINK
- return (ifconfig(&ctx, iscreate, uafp));
+ return (ifconfig(ctx, iscreate, uafp));
#else
- return (ifconfig_wrapper_nl(&ctx, iscreate, uafp));
+ return (ifconfig_wrapper_nl(ctx, iscreate, uafp));
#endif
}
@@ -616,6 +610,11 @@
struct ifconfig_args _args = {};
struct ifconfig_args *args = &_args;
+ struct ifconfig_context ctx = {
+ .args = args,
+ .io_s = -1,
+ };
+
f_inet = f_inet6 = f_ether = f_addr = NULL;
lifh = ifconfig_open();
@@ -647,6 +646,7 @@
if (!args->all && !args->namesonly) {
/* not listing, need an argument */
args->ifname = args_pop(args);
+ ctx.ifname = args->ifname;
/* check and maybe load support for this interface */
ifmaybeload(args, args->ifname);
@@ -662,7 +662,7 @@
if (isnametoolong(args->ifname))
errx(1, "%s: cloning name too long",
args->ifname);
- ifconfig_wrapper(args, 1, NULL);
+ ifconfig_wrapper(&ctx, 1, NULL);
exit(exit_code);
}
#ifdef JAIL
@@ -675,7 +675,7 @@
if (isnametoolong(args->ifname))
errx(1, "%s: interface name too long",
args->ifname);
- ifconfig_wrapper(args, 0, NULL);
+ ifconfig_wrapper(&ctx, 0, NULL);
exit(exit_code);
}
#endif
@@ -714,14 +714,14 @@
if (!(((flags & IFF_CANTCONFIG) != 0) ||
(args->downonly && (flags & IFF_UP) != 0) ||
(args->uponly && (flags & IFF_UP) == 0)))
- ifconfig_wrapper(args, 0, args->afp);
+ ifconfig_wrapper(&ctx, 0, args->afp);
}
goto done;
}
args->allfamilies = args->afp == NULL;
- list_interfaces(args);
+ list_interfaces(&ctx);
done:
freeformat();
@@ -771,13 +771,14 @@
}
static void
-list_interfaces_ioctl(struct ifconfig_args *args)
+list_interfaces_ioctl(if_ctx *ctx)
{
struct ifa_queue q = TAILQ_HEAD_INITIALIZER(q);
struct ifaddrs *ifap, *sifap, *ifa;
struct ifa_order_elt *cur, *tmp;
char *namecp = NULL;
int ifindex;
+ struct ifconfig_args *args = ctx->args;
if (getifaddrs(&ifap) != 0)
err(EXIT_FAILURE, "getifaddrs");
@@ -840,9 +841,9 @@
ifindex++;
if (args->argc > 0)
- ifconfig_wrapper(args, 0, args->afp);
+ ifconfig_wrapper(ctx, 0, args->afp);
else
- status(args, sdl, ifa);
+ status(ctx, sdl, ifa);
}
if (args->namesonly)
printf("\n");
@@ -1717,11 +1718,12 @@
* specified, show only it; otherwise, show them all.
*/
static void
-status(struct ifconfig_args *args, const struct sockaddr_dl *sdl,
+status(if_ctx *ctx, const struct sockaddr_dl *sdl,
struct ifaddrs *ifa)
{
struct ifaddrs *ift;
- int s;
+ int s, old_s;
+ struct ifconfig_args *args = ctx->args;
bool allfamilies = args->afp == NULL;
char *ifname = ifa->ifa_name;
@@ -1735,12 +1737,8 @@
s = socket(ifr.ifr_addr.sa_family, SOCK_DGRAM, 0);
if (s < 0)
err(1, "socket(family %u,SOCK_DGRAM)", ifr.ifr_addr.sa_family);
-
- struct ifconfig_context _ctx = {
- .io_s = s,
- .ifname = ifname,
- };
- struct ifconfig_context *ctx = &_ctx;
+ old_s = ctx->io_s;
+ ctx->io_s = s;
printf("%s: ", ifname);
printb("flags", ifa->ifa_flags, IFFBITS);
@@ -1794,6 +1792,7 @@
sfp_status(ctx);
close(s);
+ ctx->io_s = old_s;
return;
}
#endif
diff --git a/sbin/ifconfig/ifconfig_netlink.c b/sbin/ifconfig/ifconfig_netlink.c
--- a/sbin/ifconfig/ifconfig_netlink.c
+++ b/sbin/ifconfig/ifconfig_netlink.c
@@ -134,6 +134,7 @@
int error = ifconfig(ctx, iscreate, uafp);
snl_free(&ss);
+ ctx->io_ss = NULL;
return (error);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Feb 8, 9:31 PM (9 h, 12 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
28500303
Default Alt Text
D40440.id122894.diff (4 KB)
Attached To
Mode
D40440: ifconfig: start ifconfig context from main()
Attached
Detach File
Event Timeline
Log In to Comment