diff --git a/sbin/ifconfig/af_inet.c b/sbin/ifconfig/af_inet.c --- a/sbin/ifconfig/af_inet.c +++ b/sbin/ifconfig/af_inet.c @@ -347,7 +347,7 @@ struct snl_state *ss = ctx->io_ss; bool found = false; - uint32_t ifindex = if_nametoindex_nl(ss, name); + uint32_t ifindex = if_nametoindex_nl(ss, ctx->ifname); if (ifindex == 0) { /* No interface with the desired name, nothing to delete */ return (EADDRNOTAVAIL); @@ -417,7 +417,7 @@ ifahdr->ifa_family = AF_INET; ifahdr->ifa_prefixlen = pdata->addr.plen; - ifahdr->ifa_index = if_nametoindex_nl(ctx->io_ss, name); + ifahdr->ifa_index = if_nametoindex_nl(ctx->io_ss, ctx->ifname); snl_add_msg_attr_ip4(&nw, IFA_LOCAL, &pdata->addr.addr); if (action == NL_RTM_NEWADDR && pdata->dst_addr.addrset) @@ -498,7 +498,7 @@ const struct sockaddr *sa = (const struct sockaddr *) &ifr.ifr_addr; memset(&ifr, 0, sizeof(ifr)); - strlcpy(ifr.ifr_name, name, IFNAMSIZ); + strlcpy(ifr.ifr_name, ctx->ifname, IFNAMSIZ); if (ioctl_ctx(ctx, SIOCGIFPSRCADDR, (caddr_t)&ifr) < 0) return; @@ -523,7 +523,7 @@ struct in_aliasreq addreq; memset(&addreq, 0, sizeof(addreq)); - strlcpy(addreq.ifra_name, name, IFNAMSIZ); + strlcpy(addreq.ifra_name, ctx->ifname, IFNAMSIZ); memcpy(&addreq.ifra_addr, srcres->ai_addr, srcres->ai_addr->sa_len); memcpy(&addreq.ifra_dstaddr, dstres->ai_addr, dstres->ai_addr->sa_len); diff --git a/sbin/ifconfig/af_inet6.c b/sbin/ifconfig/af_inet6.c --- a/sbin/ifconfig/af_inet6.c +++ b/sbin/ifconfig/af_inet6.c @@ -199,7 +199,7 @@ err(EXIT_FAILURE, "getifaddrs"); for (ifa = ifap; ifa; ifa = ifa->ifa_next) { if (ifa->ifa_addr->sa_family == AF_INET6 && - strcmp(ifa->ifa_name, name) == 0) { + strcmp(ifa->ifa_name, ctx->ifname) == 0) { sin6 = (const struct sockaddr_in6 *)satosin6(ifa->ifa_addr); if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) { lladdr = &sin6->sin6_addr; @@ -477,7 +477,7 @@ ifahdr->ifa_family = AF_INET6; ifahdr->ifa_prefixlen = pdata->addr.plen; - ifahdr->ifa_index = if_nametoindex_nl(ctx->io_ss, name); + ifahdr->ifa_index = if_nametoindex_nl(ctx->io_ss, ctx->ifname); snl_add_msg_attr_ip6(&nw, IFA_LOCAL, &pdata->addr.addr); if (action == NL_RTM_NEWADDR && pdata->dst_addr.set) @@ -655,7 +655,7 @@ const struct sockaddr *sa = (const struct sockaddr *) &in6_ifr.ifr_addr; memset(&in6_ifr, 0, sizeof(in6_ifr)); - strlcpy(in6_ifr.ifr_name, name, sizeof(in6_ifr.ifr_name)); + strlcpy(in6_ifr.ifr_name, ctx->ifname, sizeof(in6_ifr.ifr_name)); if (ioctl_ctx(ctx, SIOCGIFPSRCADDR_IN6, (caddr_t)&in6_ifr) < 0) return; @@ -682,7 +682,7 @@ struct in6_aliasreq in6_addreq; memset(&in6_addreq, 0, sizeof(in6_addreq)); - strlcpy(in6_addreq.ifra_name, name, sizeof(in6_addreq.ifra_name)); + strlcpy(in6_addreq.ifra_name, ctx->ifname, sizeof(in6_addreq.ifra_name)); memcpy(&in6_addreq.ifra_addr, srcres->ai_addr, srcres->ai_addr->sa_len); memcpy(&in6_addreq.ifra_dstaddr, dstres->ai_addr, dstres->ai_addr->sa_len); diff --git a/sbin/ifconfig/carp.c b/sbin/ifconfig/carp.c --- a/sbin/ifconfig/carp.c +++ b/sbin/ifconfig/carp.c @@ -76,7 +76,7 @@ struct ifconfig_carp carpr[CARP_MAXVHID]; char addr_buf[NI_MAXHOST]; - if (ifconfig_carp_get_info(lifh, name, carpr, CARP_MAXVHID) == -1) + if (ifconfig_carp_get_info(lifh, ctx->ifname, carpr, CARP_MAXVHID) == -1) return; for (size_t i = 0; i < carpr[0].carpr_count; i++) { @@ -114,11 +114,11 @@ } static void -setcarp_callback(if_ctx *ctx __unused, void *arg __unused) +setcarp_callback(if_ctx *ctx, void *arg __unused) { struct ifconfig_carp carpr = { }; - if (ifconfig_carp_get_vhid(lifh, name, &carpr, carpr_vhid) == -1) { + if (ifconfig_carp_get_vhid(lifh, ctx->ifname, &carpr, carpr_vhid) == -1) { if (ifconfig_err_errno(lifh) != ENOENT) return; } @@ -139,7 +139,7 @@ memcpy(&carpr.carpr_addr6, &carp_addr6, sizeof(carp_addr6)); - if (ifconfig_carp_set_info(lifh, name, &carpr)) + if (ifconfig_carp_set_info(lifh, ctx->ifname, &carpr)) err(1, "SIOCSVH"); } diff --git a/sbin/ifconfig/ifbridge.c b/sbin/ifconfig/ifbridge.c --- a/sbin/ifconfig/ifbridge.c +++ b/sbin/ifconfig/ifbridge.c @@ -85,28 +85,26 @@ } static int -do_cmd(int sock, u_long op, void *arg, size_t argsize, int set) +do_cmd(if_ctx *ctx, u_long op, void *arg, size_t argsize, int set) { - struct ifdrv ifd; + struct ifdrv ifd = {}; - memset(&ifd, 0, sizeof(ifd)); - - strlcpy(ifd.ifd_name, name, sizeof(ifd.ifd_name)); + strlcpy(ifd.ifd_name, ctx->ifname, sizeof(ifd.ifd_name)); ifd.ifd_cmd = op; ifd.ifd_len = argsize; ifd.ifd_data = arg; - return (ioctl(sock, set ? SIOCSDRVSPEC : SIOCGDRVSPEC, &ifd)); + return (ioctl_ctx(ctx, set ? SIOCSDRVSPEC : SIOCGDRVSPEC, &ifd)); } static void -do_bridgeflag(int sock, const char *ifs, int flag, int set) +do_bridgeflag(if_ctx *ctx, const char *ifs, int flag, int set) { struct ifbreq req; strlcpy(req.ifbr_ifsname, ifs, sizeof(req.ifbr_ifsname)); - if (do_cmd(sock, BRDGGIFFLGS, &req, sizeof(req), 0) < 0) + if (do_cmd(ctx, BRDGGIFFLGS, &req, sizeof(req), 0) < 0) err(1, "unable to get bridge flags"); if (set) @@ -114,12 +112,12 @@ else req.ifbr_ifsflags &= ~flag; - if (do_cmd(sock, BRDGSIFFLGS, &req, sizeof(req), 1) < 0) + if (do_cmd(ctx, BRDGSIFFLGS, &req, sizeof(req), 1) < 0) err(1, "unable to set bridge flags"); } static void -bridge_addresses(int s, const char *prefix) +bridge_addresses(if_ctx *ctx, const char *prefix) { struct ifbaconf ifbac; struct ifbareq *ifba; @@ -133,7 +131,7 @@ err(1, "unable to allocate address buffer"); ifbac.ifbac_len = len; ifbac.ifbac_buf = inbuf = ninbuf; - if (do_cmd(s, BRDGRTS, &ifbac, sizeof(ifbac), 0) < 0) + if (do_cmd(ctx, BRDGRTS, &ifbac, sizeof(ifbac), 0) < 0) err(1, "unable to get address cache"); if ((ifbac.ifbac_len + sizeof(*ifba)) < len) break; @@ -154,7 +152,7 @@ } static void -bridge_status(if_ctx *ctx __unused) +bridge_status(if_ctx *ctx) { struct ifconfig_bridge_status *bridge; struct ifbropreq *params; @@ -162,7 +160,7 @@ uint8_t lladdr[ETHER_ADDR_LEN]; uint16_t bprio; - if (ifconfig_bridge_get_bridge_status(lifh, name, &bridge) == -1) + if (ifconfig_bridge_get_bridge_status(lifh, ctx->ifname, &bridge) == -1) return; params = bridge->params; @@ -231,7 +229,7 @@ memset(&req, 0, sizeof(req)); strlcpy(req.ifbr_ifsname, val, sizeof(req.ifbr_ifsname)); - if (do_cmd(ctx->io_s, BRDGADD, &req, sizeof(req), 1) < 0) + if (do_cmd(ctx, BRDGADD, &req, sizeof(req), 1) < 0) err(1, "BRDGADD %s", val); } @@ -242,7 +240,7 @@ memset(&req, 0, sizeof(req)); strlcpy(req.ifbr_ifsname, val, sizeof(req.ifbr_ifsname)); - if (do_cmd(ctx->io_s, BRDGDEL, &req, sizeof(req), 1) < 0) + if (do_cmd(ctx, BRDGDEL, &req, sizeof(req), 1) < 0) err(1, "BRDGDEL %s", val); } @@ -250,42 +248,42 @@ setbridge_discover(if_ctx *ctx, const char *val, int dummy __unused) { - do_bridgeflag(ctx->io_s, val, IFBIF_DISCOVER, 1); + do_bridgeflag(ctx, val, IFBIF_DISCOVER, 1); } static void unsetbridge_discover(if_ctx *ctx, const char *val, int dummy __unused) { - do_bridgeflag(ctx->io_s, val, IFBIF_DISCOVER, 0); + do_bridgeflag(ctx, val, IFBIF_DISCOVER, 0); } static void setbridge_learn(if_ctx *ctx, const char *val, int dummy __unused) { - do_bridgeflag(ctx->io_s, val, IFBIF_LEARNING, 1); + do_bridgeflag(ctx, val, IFBIF_LEARNING, 1); } static void unsetbridge_learn(if_ctx *ctx, const char *val, int dummy __unused) { - do_bridgeflag(ctx->io_s, val, IFBIF_LEARNING, 0); + do_bridgeflag(ctx, val, IFBIF_LEARNING, 0); } static void setbridge_sticky(if_ctx *ctx, const char *val, int dummy __unused) { - do_bridgeflag(ctx->io_s, val, IFBIF_STICKY, 1); + do_bridgeflag(ctx, val, IFBIF_STICKY, 1); } static void unsetbridge_sticky(if_ctx *ctx, const char *val, int dummy __unused) { - do_bridgeflag(ctx->io_s, val, IFBIF_STICKY, 0); + do_bridgeflag(ctx, val, IFBIF_STICKY, 0); } static void @@ -295,7 +293,7 @@ memset(&req, 0, sizeof(req)); strlcpy(req.ifbr_ifsname, val, sizeof(req.ifbr_ifsname)); - if (do_cmd(ctx->io_s, BRDGADDS, &req, sizeof(req), 1) < 0) + if (do_cmd(ctx, BRDGADDS, &req, sizeof(req), 1) < 0) err(1, "BRDGADDS %s", val); } @@ -306,7 +304,7 @@ memset(&req, 0, sizeof(req)); strlcpy(req.ifbr_ifsname, val, sizeof(req.ifbr_ifsname)); - if (do_cmd(ctx->io_s, BRDGDELS, &req, sizeof(req), 1) < 0) + if (do_cmd(ctx, BRDGDELS, &req, sizeof(req), 1) < 0) err(1, "BRDGDELS %s", val); } @@ -314,62 +312,62 @@ setbridge_stp(if_ctx *ctx, const char *val, int dummy __unused) { - do_bridgeflag(ctx->io_s, val, IFBIF_STP, 1); + do_bridgeflag(ctx, val, IFBIF_STP, 1); } static void unsetbridge_stp(if_ctx *ctx, const char *val, int dummy __unused) { - do_bridgeflag(ctx->io_s, val, IFBIF_STP, 0); + do_bridgeflag(ctx, val, IFBIF_STP, 0); } static void setbridge_edge(if_ctx *ctx, const char *val, int dummy __unused) { - do_bridgeflag(ctx->io_s, val, IFBIF_BSTP_EDGE, 1); + do_bridgeflag(ctx, val, IFBIF_BSTP_EDGE, 1); } static void unsetbridge_edge(if_ctx *ctx, const char *val, int dummy __unused) { - do_bridgeflag(ctx->io_s, val, IFBIF_BSTP_EDGE, 0); + do_bridgeflag(ctx, val, IFBIF_BSTP_EDGE, 0); } static void setbridge_autoedge(if_ctx *ctx, const char *val, int dummy __unused) { - do_bridgeflag(ctx->io_s, val, IFBIF_BSTP_AUTOEDGE, 1); + do_bridgeflag(ctx, val, IFBIF_BSTP_AUTOEDGE, 1); } static void unsetbridge_autoedge(if_ctx *ctx, const char *val, int dummy __unused) { - do_bridgeflag(ctx->io_s, val, IFBIF_BSTP_AUTOEDGE, 0); + do_bridgeflag(ctx, val, IFBIF_BSTP_AUTOEDGE, 0); } static void setbridge_ptp(if_ctx *ctx, const char *val, int dummy __unused) { - do_bridgeflag(ctx->io_s, val, IFBIF_BSTP_PTP, 1); + do_bridgeflag(ctx, val, IFBIF_BSTP_PTP, 1); } static void unsetbridge_ptp(if_ctx *ctx, const char *val, int dummy __unused) { - do_bridgeflag(ctx->io_s, val, IFBIF_BSTP_PTP, 0); + do_bridgeflag(ctx, val, IFBIF_BSTP_PTP, 0); } static void setbridge_autoptp(if_ctx *ctx, const char *val, int dummy __unused) { - do_bridgeflag(ctx->io_s, val, IFBIF_BSTP_AUTOPTP, 1); + do_bridgeflag(ctx, val, IFBIF_BSTP_AUTOPTP, 1); } static void unsetbridge_autoptp(if_ctx *ctx, const char *val, int dummy __unused) { - do_bridgeflag(ctx->io_s, val, IFBIF_BSTP_AUTOPTP, 0); + do_bridgeflag(ctx, val, IFBIF_BSTP_AUTOPTP, 0); } static void @@ -379,7 +377,7 @@ memset(&req, 0, sizeof(req)); req.ifbr_ifsflags = IFBF_FLUSHDYN; - if (do_cmd(ctx->io_s, BRDGFLUSH, &req, sizeof(req), 1) < 0) + if (do_cmd(ctx, BRDGFLUSH, &req, sizeof(req), 1) < 0) err(1, "BRDGFLUSH"); } @@ -390,7 +388,7 @@ memset(&req, 0, sizeof(req)); req.ifbr_ifsflags = IFBF_FLUSHALL; - if (do_cmd(ctx->io_s, BRDGFLUSH, &req, sizeof(req), 1) < 0) + if (do_cmd(ctx, BRDGFLUSH, &req, sizeof(req), 1) < 0) err(1, "BRDGFLUSH"); } @@ -411,7 +409,7 @@ req.ifba_flags = IFBAF_STATIC; req.ifba_vlan = 1; /* XXX allow user to specify */ - if (do_cmd(ctx->io_s, BRDGSADDR, &req, sizeof(req), 1) < 0) + if (do_cmd(ctx, BRDGSADDR, &req, sizeof(req), 1) < 0) err(1, "BRDGSADDR %s", val); } @@ -429,7 +427,7 @@ memcpy(req.ifba_dst, ea->octet, sizeof(req.ifba_dst)); - if (do_cmd(ctx->io_s, BRDGDADDR, &req, sizeof(req), 1) < 0) + if (do_cmd(ctx, BRDGDADDR, &req, sizeof(req), 1) < 0) err(1, "BRDGDADDR %s", val); } @@ -437,7 +435,7 @@ setbridge_addr(if_ctx *ctx, const char *val __unused, int dummy __unused) { - bridge_addresses(ctx->io_s, ""); + bridge_addresses(ctx, ""); } static void @@ -451,7 +449,7 @@ param.ifbrp_csize = val & 0xffffffff; - if (do_cmd(ctx->io_s, BRDGSCACHE, ¶m, sizeof(param), 1) < 0) + if (do_cmd(ctx, BRDGSCACHE, ¶m, sizeof(param), 1) < 0) err(1, "BRDGSCACHE %s", arg); } @@ -466,7 +464,7 @@ param.ifbrp_hellotime = val & 0xff; - if (do_cmd(ctx->io_s, BRDGSHT, ¶m, sizeof(param), 1) < 0) + if (do_cmd(ctx, BRDGSHT, ¶m, sizeof(param), 1) < 0) err(1, "BRDGSHT %s", arg); } @@ -481,7 +479,7 @@ param.ifbrp_fwddelay = val & 0xff; - if (do_cmd(ctx->io_s, BRDGSFD, ¶m, sizeof(param), 1) < 0) + if (do_cmd(ctx, BRDGSFD, ¶m, sizeof(param), 1) < 0) err(1, "BRDGSFD %s", arg); } @@ -496,7 +494,7 @@ param.ifbrp_maxage = val & 0xff; - if (do_cmd(ctx->io_s, BRDGSMA, ¶m, sizeof(param), 1) < 0) + if (do_cmd(ctx, BRDGSMA, ¶m, sizeof(param), 1) < 0) err(1, "BRDGSMA %s", arg); } @@ -511,7 +509,7 @@ param.ifbrp_prio = val & 0xffff; - if (do_cmd(ctx->io_s, BRDGSPRI, ¶m, sizeof(param), 1) < 0) + if (do_cmd(ctx, BRDGSPRI, ¶m, sizeof(param), 1) < 0) err(1, "BRDGSPRI %s", arg); } @@ -528,7 +526,7 @@ errx(1, "unknown stp protocol"); } - if (do_cmd(ctx->io_s, BRDGSPROTO, ¶m, sizeof(param), 1) < 0) + if (do_cmd(ctx, BRDGSPROTO, ¶m, sizeof(param), 1) < 0) err(1, "BRDGSPROTO %s", arg); } @@ -543,7 +541,7 @@ param.ifbrp_txhc = val & 0xff; - if (do_cmd(ctx->io_s, BRDGSTXHC, ¶m, sizeof(param), 1) < 0) + if (do_cmd(ctx, BRDGSTXHC, ¶m, sizeof(param), 1) < 0) err(1, "BRDGSTXHC %s", arg); } @@ -561,7 +559,7 @@ strlcpy(req.ifbr_ifsname, ifn, sizeof(req.ifbr_ifsname)); req.ifbr_priority = val & 0xff; - if (do_cmd(ctx->io_s, BRDGSIFPRIO, &req, sizeof(req), 1) < 0) + if (do_cmd(ctx, BRDGSIFPRIO, &req, sizeof(req), 1) < 0) err(1, "BRDGSIFPRIO %s", pri); } @@ -579,7 +577,7 @@ strlcpy(req.ifbr_ifsname, ifn, sizeof(req.ifbr_ifsname)); req.ifbr_path_cost = val; - if (do_cmd(ctx->io_s, BRDGSIFCOST, &req, sizeof(req), 1) < 0) + if (do_cmd(ctx, BRDGSIFCOST, &req, sizeof(req), 1) < 0) err(1, "BRDGSIFCOST %s", cost); } @@ -597,7 +595,7 @@ strlcpy(req.ifbr_ifsname, ifn, sizeof(req.ifbr_ifsname)); req.ifbr_addrmax = val & 0xffffffff; - if (do_cmd(ctx->io_s, BRDGSIFAMAX, &req, sizeof(req), 1) < 0) + if (do_cmd(ctx, BRDGSIFAMAX, &req, sizeof(req), 1) < 0) err(1, "BRDGSIFAMAX %s", arg); } @@ -612,7 +610,7 @@ param.ifbrp_ctime = val & 0xffffffff; - if (do_cmd(ctx->io_s, BRDGSTO, ¶m, sizeof(param), 1) < 0) + if (do_cmd(ctx, BRDGSTO, ¶m, sizeof(param), 1) < 0) err(1, "BRDGSTO %s", arg); } @@ -620,14 +618,14 @@ setbridge_private(if_ctx *ctx, const char *val, int dummy __unused) { - do_bridgeflag(ctx->io_s, val, IFBIF_PRIVATE, 1); + do_bridgeflag(ctx, val, IFBIF_PRIVATE, 1); } static void unsetbridge_private(if_ctx *ctx, const char *val, int dummy __unused) { - do_bridgeflag(ctx->io_s, val, IFBIF_PRIVATE, 0); + do_bridgeflag(ctx, val, IFBIF_PRIVATE, 0); } static struct cmd bridge_cmds[] = { diff --git a/sbin/ifconfig/ifclone.c b/sbin/ifconfig/ifclone.c --- a/sbin/ifconfig/ifclone.c +++ b/sbin/ifconfig/ifclone.c @@ -123,7 +123,7 @@ struct ifreq ifr = {}; struct clone_defcb *dcp; - strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); + strlcpy(ifr.ifr_name, ctx->ifname, sizeof(ifr.ifr_name)); /* Try to find a default callback by filter */ SLIST_FOREACH(dcp, &clone_defcbh, next) { @@ -159,7 +159,7 @@ static void clone_destroy(if_ctx *ctx, const char *cmd __unused, int d __unused) { - strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); + strlcpy(ifr.ifr_name, ctx->ifname, sizeof(ifr.ifr_name)); if (ioctl(ctx->io_s, SIOCIFDESTROY, &ifr) < 0) err(1, "SIOCIFDESTROY"); } diff --git a/sbin/ifconfig/ifconfig.h b/sbin/ifconfig/ifconfig.h --- a/sbin/ifconfig/ifconfig.h +++ b/sbin/ifconfig/ifconfig.h @@ -60,7 +60,7 @@ const struct afswtch *afp; int io_s; /* fd to use for ioctl() */ struct snl_state *io_ss; /* NETLINK_ROUTE socket */ - char *ifname; /* Current interface name */ + const char *ifname; /* Current interface name */ char _ifname_storage_ioctl[IFNAMSIZ]; }; typedef struct ifconfig_context if_ctx; @@ -251,7 +251,6 @@ extern ifconfig_handle_t *lifh; extern struct ifreq ifr; -extern char name[IFNAMSIZ]; /* name of interface */ extern int allmedia; extern int newaddr; extern int exit_code; @@ -282,12 +281,12 @@ void tunnel_status(if_ctx *ctx); struct afswtch *af_getbyfamily(int af); void af_other_status(if_ctx *ctx); -void print_ifstatus(int s); +void print_ifstatus(if_ctx *ctx); void print_metric(int s); /* Netlink-related functions */ void list_interfaces_nl(struct ifconfig_args *args); -int ifconfig_wrapper_nl(struct ifconfig_args *args, int iscreate, +int ifconfig_wrapper_nl(if_ctx *ctx, int iscreate, const struct afswtch *uafp); uint32_t if_nametoindex_nl(struct snl_state *ss, const char *ifname); @@ -295,7 +294,7 @@ * XXX expose this so modules that need to know of any pending * operations on ifmedia can avoid cmd line ordering confusion. */ -struct ifmediareq *ifmedia_getstate(void); +struct ifmediareq *ifmedia_getstate(if_ctx *ctx); void print_vhid(const struct ifaddrs *, const char *); diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c --- a/sbin/ifconfig/ifconfig.c +++ b/sbin/ifconfig/ifconfig.c @@ -92,7 +92,7 @@ */ struct ifreq ifr; -char name[IFNAMSIZ]; +//char name[IFNAMSIZ]; #ifdef WITHOUT_NETLINK static char *descr = NULL; static size_t descrlen = 64; @@ -576,15 +576,16 @@ ifconfig_wrapper(struct ifconfig_args *args, int iscreate, const struct afswtch *uafp) { -#ifdef WITHOUT_NETLINK struct ifconfig_context ctx = { .args = args, .io_s = -1, + .ifname = args->ifname, }; +#ifdef WITHOUT_NETLINK return (ifconfig(&ctx, iscreate, uafp)); #else - return (ifconfig_wrapper_nl(args, iscreate, uafp)); + return (ifconfig_wrapper_nl(&ctx, iscreate, uafp)); #endif } @@ -600,11 +601,16 @@ return (false); } +static bool +isnametoolong(const char *ifname) +{ + return (strlen(ifname) >= IFNAMSIZ); +} + int main(int ac, char *av[]) { char *envformat; - size_t iflen; int flags; #ifdef JAIL int jid; @@ -654,8 +660,7 @@ * to find the interface. */ if (isargcreate(arg)) { - iflen = strlcpy(name, args->ifname, sizeof(name)); - if (iflen >= sizeof(name)) + if (isnametoolong(args->ifname)) errx(1, "%s: cloning name too long", args->ifname); ifconfig_wrapper(args, 1, NULL); @@ -668,8 +673,7 @@ * to find the interface as it lives in another vnet. */ if (arg != NULL && (strcmp(arg, "-vnet") == 0)) { - iflen = strlcpy(name, args->ifname, sizeof(name)); - if (iflen >= sizeof(name)) + if (isnametoolong(args->ifname)) errx(1, "%s: interface name too long", args->ifname); ifconfig_wrapper(args, 0, NULL); @@ -704,11 +708,10 @@ * system address list */ if ((args->argc > 0) && (args->ifname != NULL)) { - iflen = strlcpy(name, args->ifname, sizeof(name)); - if (iflen >= sizeof(name)) { + if (isnametoolong(args->ifname)) warnx("%s: interface name too long, skipping", args->ifname); - } else { - flags = getifflags(name, -1, false); + else { + flags = getifflags(args->ifname, -1, false); if (!(((flags & IFF_CANTCONFIG) != 0) || (args->downonly && (flags & IFF_UP) != 0) || (args->uponly && (flags & IFF_UP) == 0))) @@ -776,7 +779,6 @@ struct ifa_order_elt *cur, *tmp; char *namecp = NULL; int ifindex; - size_t iflen; if (getifaddrs(&ifap) != 0) err(EXIT_FAILURE, "getifaddrs"); @@ -810,8 +812,7 @@ sdl = NULL; if (cp != NULL && strcmp(cp, ifa->ifa_name) == 0 && !args->namesonly) continue; - iflen = strlcpy(name, ifa->ifa_name, sizeof(name)); - if (iflen >= sizeof(name)) { + if (isnametoolong(ifa->ifa_name)) { warnx("%s: interface name too long, skipping", ifa->ifa_name); continue; @@ -834,7 +835,7 @@ ifindex++; if (ifindex > 1) printf(" "); - fputs(name, stdout); + fputs(cp, stdout); continue; } ifindex++; @@ -1044,7 +1045,7 @@ { struct ifreq *req = (struct ifreq *)data; - strlcpy(req->ifr_name, name, sizeof(req->ifr_name)); + strlcpy(req->ifr_name, ctx->ifname, sizeof(req->ifr_name)); if (ioctl_ctx(ctx, action, req) == 0) return (0); return (errno); @@ -1057,7 +1058,7 @@ if (afp->af_exec == NULL) { warnx("interface %s cannot change %s addresses!", - name, afp->af_name); + ctx->ifname, afp->af_name); clearaddr = 0; return; } @@ -1076,7 +1077,7 @@ { if (afp->af_exec == NULL) { warnx("interface %s cannot change %s addresses!", - name, afp->af_name); + ctx->ifname, afp->af_name); newaddr = 0; return; } @@ -1100,10 +1101,11 @@ struct ifconfig_context _ctx = { .args = orig_ctx->args, .io_ss = orig_ctx->io_ss, + .ifname = orig_ctx->ifname, }; struct ifconfig_context *ctx = &_ctx; - strlcpy(ifr.ifr_name, name, sizeof ifr.ifr_name); + strlcpy(ifr.ifr_name, ctx->ifname, sizeof ifr.ifr_name); afp = NULL; if (uafp != NULL) afp = uafp; @@ -1209,7 +1211,7 @@ * Do any post argument processing required by the address family. */ if (afp->af_postproc != NULL) - afp->af_postproc(ctx, newaddr, getifflags(name, s, true)); + afp->af_postproc(ctx, newaddr, getifflags(ctx->ifname, s, true)); /* * Do deferred callbacks registered while processing * command-line arguments. @@ -1394,14 +1396,14 @@ struct ifreq my_ifr; int flags; - flags = getifflags(name, ctx->io_s, false); + flags = getifflags(ctx->ifname, ctx->io_s, false); if (value < 0) { value = -value; flags &= ~value; } else flags |= value; memset(&my_ifr, 0, sizeof(my_ifr)); - (void) strlcpy(my_ifr.ifr_name, name, sizeof(my_ifr.ifr_name)); + strlcpy(my_ifr.ifr_name, ctx->ifname, sizeof(my_ifr.ifr_name)); my_ifr.ifr_flags = flags & 0xffff; my_ifr.ifr_flagshigh = flags >> 16; if (ioctl(ctx->io_s, SIOCSIFFLAGS, (caddr_t)&my_ifr) < 0) @@ -1482,7 +1484,7 @@ static void setifmetric(if_ctx *ctx, const char *val, int dummy __unused) { - strlcpy(ifr.ifr_name, name, sizeof (ifr.ifr_name)); + strlcpy(ifr.ifr_name, ctx->ifname, sizeof (ifr.ifr_name)); ifr.ifr_metric = atoi(val); if (ioctl(ctx->io_s, SIOCSIFMETRIC, (caddr_t)&ifr) < 0) err(1, "ioctl SIOCSIFMETRIC (set metric)"); @@ -1491,7 +1493,7 @@ static void setifmtu(if_ctx *ctx, const char *val, int dummy __unused) { - strlcpy(ifr.ifr_name, name, sizeof (ifr.ifr_name)); + strlcpy(ifr.ifr_name, ctx->ifname, sizeof (ifr.ifr_name)); ifr.ifr_mtu = atoi(val); if (ioctl(ctx->io_s, SIOCSIFMTU, (caddr_t)&ifr) < 0) err(1, "ioctl SIOCSIFMTU (set mtu)"); @@ -1527,7 +1529,7 @@ { char *newname; - strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); + strlcpy(ifr.ifr_name, ctx->ifname, sizeof(ifr.ifr_name)); newname = strdup(val); if (newname == NULL) @@ -1546,7 +1548,7 @@ { char *newdescr; - strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); + strlcpy(ifr.ifr_name, ctx->ifname, sizeof(ifr.ifr_name)); ifr.ifr_buffer.length = strlen(val) + 1; if (ifr.ifr_buffer.length == 1) { @@ -1663,12 +1665,12 @@ } void -print_ifstatus(int s) +print_ifstatus(if_ctx *ctx) { struct ifstat ifs; - strlcpy(ifs.ifs_name, name, sizeof ifs.ifs_name); - if (ioctl(s, SIOCGIFSTATUS, &ifs) == 0) + strlcpy(ifs.ifs_name, ctx->ifname, sizeof ifs.ifs_name); + if (ioctl_ctx(ctx, SIOCGIFSTATUS, &ifs) == 0) printf("%s", ifs.ascii); } @@ -1722,22 +1724,26 @@ struct ifaddrs *ift; int s; bool allfamilies = args->afp == NULL; + char *ifname = ifa->ifa_name; if (args->afp == NULL) ifr.ifr_addr.sa_family = AF_LOCAL; else ifr.ifr_addr.sa_family = args->afp->af_af == AF_LINK ? AF_LOCAL : args->afp->af_af; - strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); + strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); 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 }, *ctx; - ctx = &_ctx; + struct ifconfig_context _ctx = { + .io_s = s, + .ifname = ifname, + }; + struct ifconfig_context *ctx = &_ctx; - printf("%s: ", name); + printf("%s: ", ifname); printb("flags", ifa->ifa_flags, IFFBITS); print_metric(s); print_mtu(s); @@ -1784,7 +1790,7 @@ else if (args->afp->af_other_status != NULL) args->afp->af_other_status(ctx); - print_ifstatus(s); + print_ifstatus(ctx); if (args->verbose > 0) sfp_status(ctx); 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 @@ -123,19 +123,15 @@ } int -ifconfig_wrapper_nl(struct ifconfig_args *args, int iscreate, +ifconfig_wrapper_nl(if_ctx *ctx, int iscreate, const struct afswtch *uafp) { struct snl_state ss = {}; - struct ifconfig_context ctx = { - .args = args, - .io_s = -1, - .io_ss = &ss, - }; nl_init_socket(&ss); + ctx->io_ss = &ss; - int error = ifconfig(&ctx, iscreate, uafp); + int error = ifconfig(ctx, iscreate, uafp); snl_free(&ss); @@ -396,7 +392,7 @@ else if (args->afp->af_other_status != NULL) args->afp->af_other_status(ctx); - print_ifstatus(ctx->io_s); + print_ifstatus(ctx); if (args->verbose > 0) sfp_status(ctx); } @@ -411,16 +407,6 @@ return (s); } -static void -set_global_ifname(if_link_t *link) -{ - size_t iflen = strlcpy(name, link->ifla_ifname, sizeof(name)); - - if (iflen >= sizeof(name)) - errx(1, "%s: cloning name too long", link->ifla_ifname); - strlcpy(ifr.ifr_name, link->ifla_ifname, sizeof(ifr.ifr_name)); -} - void list_interfaces_nl(struct ifconfig_args *args) { @@ -452,7 +438,7 @@ if (!match_iface(args, iface)) continue; - set_global_ifname(&iface->link); + ctx->ifname = iface->link.ifla_ifname; if (args->namesonly) { if (num++ != 0) diff --git a/sbin/ifconfig/iffib.c b/sbin/ifconfig/iffib.c --- a/sbin/ifconfig/iffib.c +++ b/sbin/ifconfig/iffib.c @@ -51,13 +51,13 @@ struct ifreq ifr; memset(&ifr, 0, sizeof(ifr)); - strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); + strlcpy(ifr.ifr_name, ctx->ifname, sizeof(ifr.ifr_name)); if (ioctl_ctx(ctx, SIOCGIFFIB, (caddr_t)&ifr) == 0 && ifr.ifr_fib != RT_DEFAULT_FIB) printf("\tfib: %u\n", ifr.ifr_fib); memset(&ifr, 0, sizeof(ifr)); - strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); + strlcpy(ifr.ifr_name, ctx->ifname, sizeof(ifr.ifr_name)); if (ioctl_ctx(ctx, SIOCGTUNFIB, (caddr_t)&ifr) == 0 && ifr.ifr_fib != RT_DEFAULT_FIB) printf("\ttunnelfib: %u\n", ifr.ifr_fib); @@ -75,7 +75,7 @@ return; } - strlcpy(ifr.ifr_name, name, sizeof (ifr.ifr_name)); + strlcpy(ifr.ifr_name, ctx->ifname, sizeof (ifr.ifr_name)); ifr.ifr_fib = fib; if (ioctl(ctx->io_s, SIOCSIFFIB, (caddr_t)&ifr) < 0) warn("ioctl (SIOCSIFFIB)"); @@ -93,7 +93,7 @@ return; } - strlcpy(ifr.ifr_name, name, sizeof (ifr.ifr_name)); + strlcpy(ifr.ifr_name, ctx->ifname, sizeof (ifr.ifr_name)); ifr.ifr_fib = fib; if (ioctl(ctx->io_s, SIOCSTUNFIB, (caddr_t)&ifr) < 0) warn("ioctl (SIOCSTUNFIB)"); diff --git a/sbin/ifconfig/ifgre.c b/sbin/ifconfig/ifgre.c --- a/sbin/ifconfig/ifgre.c +++ b/sbin/ifconfig/ifgre.c @@ -73,7 +73,7 @@ { uint32_t grekey = strtol(val, NULL, 0); - strlcpy(ifr.ifr_name, name, sizeof (ifr.ifr_name)); + strlcpy(ifr.ifr_name, ctx->ifname, sizeof (ifr.ifr_name)); ifr.ifr_data = (caddr_t)&grekey; if (ioctl(ctx->io_s, GRESKEY, (caddr_t)&ifr) < 0) warn("ioctl (set grekey)"); @@ -84,7 +84,7 @@ { uint32_t udpport = strtol(val, NULL, 0); - strlcpy(ifr.ifr_name, name, sizeof (ifr.ifr_name)); + strlcpy(ifr.ifr_name, ctx->ifname, sizeof (ifr.ifr_name)); ifr.ifr_data = (caddr_t)&udpport; if (ioctl(ctx->io_s, GRESPORT, (caddr_t)&ifr) < 0) warn("ioctl (set udpport)"); diff --git a/sbin/ifconfig/ifgroup.c b/sbin/ifconfig/ifgroup.c --- a/sbin/ifconfig/ifgroup.c +++ b/sbin/ifconfig/ifgroup.c @@ -50,10 +50,9 @@ static void setifgroup(if_ctx *ctx, const char *group_name, int dummy __unused) { - struct ifgroupreq ifgr; + struct ifgroupreq ifgr = {}; - memset(&ifgr, 0, sizeof(ifgr)); - strlcpy(ifgr.ifgr_name, name, IFNAMSIZ); + strlcpy(ifgr.ifgr_name, ctx->ifname, IFNAMSIZ); if (group_name[0] && isdigit(group_name[strlen(group_name) - 1])) errx(1, "setifgroup: group names may not end in a digit"); @@ -67,10 +66,9 @@ static void unsetifgroup(if_ctx *ctx, const char *group_name, int dummy __unused) { - struct ifgroupreq ifgr; + struct ifgroupreq ifgr = {}; - memset(&ifgr, 0, sizeof(ifgr)); - strlcpy(ifgr.ifgr_name, name, IFNAMSIZ); + strlcpy(ifgr.ifgr_name, ctx->ifname, IFNAMSIZ); if (group_name[0] && isdigit(group_name[strlen(group_name) - 1])) errx(1, "unsetifgroup: group names may not end in a digit"); @@ -82,12 +80,12 @@ } static void -getifgroups(if_ctx *ctx __unused) +getifgroups(if_ctx *ctx) { struct ifgroupreq ifgr; size_t cnt; - if (ifconfig_get_groups(lifh, name, &ifgr) == -1) + if (ifconfig_get_groups(lifh, ctx->ifname, &ifgr) == -1) return; cnt = 0; diff --git a/sbin/ifconfig/ifieee80211.c b/sbin/ifconfig/ifieee80211.c --- a/sbin/ifconfig/ifieee80211.c +++ b/sbin/ifconfig/ifieee80211.c @@ -173,15 +173,15 @@ [IEEE80211_MODE_VHT_5GHZ] = "11ac", }; -static void set80211(int s, int type, int val, int len, void *data); -static int get80211(int s, int type, void *data, int len); -static int get80211len(int s, int type, void *data, int len, int *plen); -static int get80211val(int s, int type, int *val); +static void set80211(if_ctx *ctx, int type, int val, int len, void *data); +static int get80211(if_ctx *ctx, int type, void *data, int len); +static int get80211len(if_ctx *ctx, int type, void *data, int len, int *plen); +static int get80211val(if_ctx *ctx, int type, int *val); static const char *get_string(const char *val, const char *sep, u_int8_t *buf, int *lenp); static void print_string(const u_int8_t *buf, int len); static void print_regdomain(const struct ieee80211_regdomain *, int); -static void print_channels(int, const struct ieee80211req_chaninfo *, +static void print_channels(if_ctx *, const struct ieee80211req_chaninfo *, int allchans, int verbose); static void regdomain_makechannels(if_ctx *, struct ieee80211_regdomain_req *, const struct ieee80211_devcaps_req *); @@ -201,11 +201,11 @@ static int gothtconf = 0; static void -gethtconf(int s) +gethtconf(if_ctx *ctx) { if (gothtconf) return; - if (get80211val(s, IEEE80211_IOC_HTCONF, &htconf) < 0) + if (get80211val(ctx, IEEE80211_IOC_HTCONF, &htconf) < 0) warn("unable to get HT configuration information"); gothtconf = 1; } @@ -215,11 +215,11 @@ static int gotvhtconf = 0; static void -getvhtconf(int s) +getvhtconf(if_ctx *ctx) { if (gotvhtconf) return; - if (get80211val(s, IEEE80211_IOC_VHTCONF, &vhtconf) < 0) + if (get80211val(ctx, IEEE80211_IOC_VHTCONF, &vhtconf) < 0) warn("unable to get VHT configuration information"); gotvhtconf = 1; } @@ -229,19 +229,19 @@ * to handle mapping between frequency and IEEE channel number. */ static void -getchaninfo(int s) +getchaninfo(if_ctx *ctx) { if (chaninfo != NULL) return; chaninfo = malloc(IEEE80211_CHANINFO_SIZE(MAXCHAN)); if (chaninfo == NULL) errx(1, "no space for channel list"); - if (get80211(s, IEEE80211_IOC_CHANINFO, chaninfo, + if (get80211(ctx, IEEE80211_IOC_CHANINFO, chaninfo, IEEE80211_CHANINFO_SIZE(MAXCHAN)) < 0) err(1, "unable to get channel information"); - ifmr = ifmedia_getstate(); - gethtconf(s); - getvhtconf(s); + ifmr = ifmedia_getstate(ctx); + gethtconf(ctx); + getvhtconf(ctx); } static struct regdata * @@ -387,16 +387,16 @@ } static const struct ieee80211_channel * -getcurchan(int s) +getcurchan(if_ctx *ctx) { if (gotcurchan) return &curchan; - if (get80211(s, IEEE80211_IOC_CURCHAN, &curchan, sizeof(curchan)) < 0) { + if (get80211(ctx, IEEE80211_IOC_CURCHAN, &curchan, sizeof(curchan)) < 0) { int val; /* fall back to legacy ioctl */ - if (get80211val(s, IEEE80211_IOC_CHANNEL, &val) < 0) + if (get80211val(ctx, IEEE80211_IOC_CHANNEL, &val) < 0) err(-1, "cannot figure out current channel"); - getchaninfo(s); + getchaninfo(ctx); mapchan(&curchan, val, 0); } gotcurchan = 1; @@ -436,11 +436,11 @@ } static void -getroam(int s) +getroam(if_ctx *ctx) { if (gotroam) return; - if (get80211(s, IEEE80211_IOC_ROAM, + if (get80211(ctx, IEEE80211_IOC_ROAM, &roamparams, sizeof(roamparams)) < 0) err(1, "unable to get roaming parameters"); gotroam = 1; @@ -450,15 +450,15 @@ setroam_cb(if_ctx *ctx, void *arg) { struct ieee80211_roamparams_req *roam = arg; - set80211(ctx->io_s, IEEE80211_IOC_ROAM, 0, sizeof(*roam), roam); + set80211(ctx, IEEE80211_IOC_ROAM, 0, sizeof(*roam), roam); } static void -gettxparams(int s) +gettxparams(if_ctx *ctx) { if (gottxparams) return; - if (get80211(s, IEEE80211_IOC_TXPARAMS, + if (get80211(ctx, IEEE80211_IOC_TXPARAMS, &txparams, sizeof(txparams)) < 0) err(1, "unable to get transmit parameters"); gottxparams = 1; @@ -468,24 +468,24 @@ settxparams_cb(if_ctx *ctx, void *arg) { struct ieee80211_txparams_req *txp = arg; - set80211(ctx->io_s, IEEE80211_IOC_TXPARAMS, 0, sizeof(*txp), txp); + set80211(ctx, IEEE80211_IOC_TXPARAMS, 0, sizeof(*txp), txp); } static void -getregdomain(int s) +getregdomain(if_ctx *ctx) { if (gotregdomain) return; - if (get80211(s, IEEE80211_IOC_REGDOMAIN, + if (get80211(ctx, IEEE80211_IOC_REGDOMAIN, ®domain, sizeof(regdomain)) < 0) err(1, "unable to get regulatory domain info"); gotregdomain = 1; } static void -getdevcaps(int s, struct ieee80211_devcaps_req *dc) +getdevcaps(if_ctx *ctx, struct ieee80211_devcaps_req *dc) { - if (get80211(s, IEEE80211_IOC_DEVCAPS, dc, + if (get80211(ctx, IEEE80211_IOC_DEVCAPS, dc, IEEE80211_DEVCAPS_SPACE(dc)) < 0) err(1, "unable to get device capabilities"); } @@ -545,7 +545,7 @@ if (dc == NULL) errx(1, "no space for device capabilities"); dc->dc_chaninfo.ic_nchans = MAXCHAN; - getdevcaps(ctx->io_s, dc); + getdevcaps(ctx, dc); #if 0 if (verbose) { printf("drivercaps: 0x%x\n", dc->dc_drivercaps); @@ -576,11 +576,11 @@ errx(1, "no space for channel list"); memcpy(chaninfo, &req->chaninfo, IEEE80211_CHANINFO_SPACE(&req->chaninfo)); - print_channels(ctx->io_s, &req->chaninfo, 1/*allchans*/, 1/*verbose*/); + print_channels(ctx, &req->chaninfo, 1/*allchans*/, 1/*verbose*/); } if (req->chaninfo.ic_nchans == 0) errx(1, "no channels calculated"); - set80211(ctx->io_s, IEEE80211_IOC_REGDOMAIN, 0, + set80211(ctx, IEEE80211_IOC_REGDOMAIN, 0, IEEE80211_REGDOMAIN_SPACE(req), req); free(req); free(dc); @@ -620,7 +620,7 @@ if (get_string(val, NULL, data, &len) == NULL) exit(1); - set80211(ctx->io_s, IEEE80211_IOC_SSID, ssid, len, data); + set80211(ctx, IEEE80211_IOC_SSID, ssid, len, data); } static void @@ -634,7 +634,7 @@ if (get_string(val, NULL, data, &len) == NULL) exit(1); - set80211(ctx->io_s, IEEE80211_IOC_MESH_ID, 0, len, data); + set80211(ctx, IEEE80211_IOC_MESH_ID, 0, len, data); } static void @@ -647,7 +647,7 @@ len = sizeof(data); get_string(val, NULL, data, &len); - set80211(ctx->io_s, IEEE80211_IOC_STATIONNAME, 0, len, data); + set80211(ctx, IEEE80211_IOC_STATIONNAME, 0, len, data); } /* @@ -806,7 +806,7 @@ } static void -getchannel(int s, struct ieee80211_channel *chan, const char *val) +getchannel(if_ctx *ctx, struct ieee80211_channel *chan, const char *val) { unsigned int v, flags; char *eptr; @@ -816,7 +816,7 @@ chan->ic_freq = IEEE80211_CHAN_ANY; return; } - getchaninfo(s); + getchaninfo(ctx); errno = 0; v = strtol(val, &eptr, 10); if (val[0] == '\0' || val == eptr || errno == ERANGE || @@ -836,22 +836,20 @@ set80211channel(if_ctx *ctx, const char *val, int dummy __unused) { struct ieee80211_channel chan; - int s = ctx->io_s; - getchannel(s, &chan, val); - set80211(s, IEEE80211_IOC_CURCHAN, 0, sizeof(chan), &chan); + getchannel(ctx, &chan, val); + set80211(ctx, IEEE80211_IOC_CURCHAN, 0, sizeof(chan), &chan); } static void set80211chanswitch(if_ctx *ctx, const char *val, int dummy __unused) { struct ieee80211_chanswitch_req csr; - int s = ctx->io_s; - getchannel(s, &csr.csa_chan, val); + getchannel(ctx, &csr.csa_chan, val); csr.csa_mode = 1; csr.csa_count = 5; - set80211(s, IEEE80211_IOC_CHANSWITCH, 0, sizeof(csr), &csr); + set80211(ctx, IEEE80211_IOC_CHANSWITCH, 0, sizeof(csr), &csr); } static void @@ -873,7 +871,7 @@ errx(1, "unknown authmode"); } - set80211(ctx->io_s, IEEE80211_IOC_AUTHMODE, mode, 0, NULL); + set80211(ctx, IEEE80211_IOC_AUTHMODE, mode, 0, NULL); } static void @@ -895,26 +893,24 @@ errx(1, "unknown powersavemode"); } - set80211(ctx->io_s, IEEE80211_IOC_POWERSAVE, mode, 0, NULL); + set80211(ctx, IEEE80211_IOC_POWERSAVE, mode, 0, NULL); } static void set80211powersave(if_ctx *ctx, const char *val __unused, int d) { - int s = ctx->io_s; - if (d == 0) - set80211(s, IEEE80211_IOC_POWERSAVE, IEEE80211_POWERSAVE_OFF, + set80211(ctx, IEEE80211_IOC_POWERSAVE, IEEE80211_POWERSAVE_OFF, 0, NULL); else - set80211(s, IEEE80211_IOC_POWERSAVE, IEEE80211_POWERSAVE_ON, + set80211(ctx, IEEE80211_IOC_POWERSAVE, IEEE80211_POWERSAVE_ON, 0, NULL); } static void set80211powersavesleep(if_ctx *ctx, const char *val, int dummy __unused) { - set80211(ctx->io_s, IEEE80211_IOC_POWERSAVESLEEP, atoi(val), 0, NULL); + set80211(ctx, IEEE80211_IOC_POWERSAVESLEEP, atoi(val), 0, NULL); } static void @@ -932,13 +928,13 @@ errx(1, "unknown wep mode"); } - set80211(ctx->io_s, IEEE80211_IOC_WEP, mode, 0, NULL); + set80211(ctx, IEEE80211_IOC_WEP, mode, 0, NULL); } static void set80211wep(if_ctx *ctx, const char *val __unused, int d) { - set80211(ctx->io_s, IEEE80211_IOC_WEP, d, 0, NULL); + set80211(ctx, IEEE80211_IOC_WEP, d, 0, NULL); } static int @@ -950,12 +946,10 @@ static void set80211weptxkey(if_ctx *ctx, const char *val, int dummy __unused) { - int s = ctx->io_s; - if (isundefarg(val)) - set80211(s, IEEE80211_IOC_WEPTXKEY, IEEE80211_KEYIX_NONE, 0, NULL); + set80211(ctx, IEEE80211_IOC_WEPTXKEY, IEEE80211_KEYIX_NONE, 0, NULL); else - set80211(s, IEEE80211_IOC_WEPTXKEY, atoi(val)-1, 0, NULL); + set80211(ctx, IEEE80211_IOC_WEPTXKEY, atoi(val)-1, 0, NULL); } static void @@ -964,7 +958,6 @@ int key = 0; int len; u_int8_t data[IEEE80211_KEYBUF_SIZE]; - int s = ctx->io_s; if (isdigit((int)val[0]) && val[1] == ':') { key = atoi(val)-1; @@ -975,7 +968,7 @@ len = sizeof(data); get_string(val, NULL, data, &len); - set80211(s, IEEE80211_IOC_WEPKEY, key, len, data); + set80211(ctx, IEEE80211_IOC_WEPKEY, key, len, data); } /* @@ -989,9 +982,8 @@ int txkey; int i, len; u_int8_t data[IEEE80211_KEYBUF_SIZE]; - int s = ctx->io_s; - set80211(s, IEEE80211_IOC_WEP, IEEE80211_WEP_ON, 0, NULL); + set80211(ctx, IEEE80211_IOC_WEP, IEEE80211_WEP_ON, 0, NULL); if (isdigit((int)val[0]) && val[1] == ':') { txkey = val[0]-'0'-1; @@ -1004,7 +996,7 @@ if (val == NULL) exit(1); - set80211(s, IEEE80211_IOC_WEPKEY, i, len, data); + set80211(ctx, IEEE80211_IOC_WEPKEY, i, len, data); } } else { bzero(data, sizeof(data)); @@ -1012,20 +1004,20 @@ get_string(val, NULL, data, &len); txkey = 0; - set80211(s, IEEE80211_IOC_WEPKEY, 0, len, data); + set80211(ctx, IEEE80211_IOC_WEPKEY, 0, len, data); bzero(data, sizeof(data)); for (i = 1; i < 4; i++) - set80211(s, IEEE80211_IOC_WEPKEY, i, 0, data); + set80211(ctx, IEEE80211_IOC_WEPKEY, i, 0, data); } - set80211(s, IEEE80211_IOC_WEPTXKEY, txkey, 0, NULL); + set80211(ctx, IEEE80211_IOC_WEPTXKEY, txkey, 0, NULL); } static void set80211rtsthreshold(if_ctx *ctx, const char *val, int dummy __unused) { - set80211(ctx->io_s, IEEE80211_IOC_RTSTHRESHOLD, + set80211(ctx, IEEE80211_IOC_RTSTHRESHOLD, isundefarg(val) ? IEEE80211_RTS_MAX : atoi(val), 0, NULL); } @@ -1044,7 +1036,7 @@ errx(1, "unknown protection mode"); } - set80211(ctx->io_s, IEEE80211_IOC_PROTMODE, mode, 0, NULL); + set80211(ctx, IEEE80211_IOC_PROTMODE, mode, 0, NULL); } static void @@ -1060,7 +1052,7 @@ errx(1, "unknown protection mode"); } - set80211(ctx->io_s, IEEE80211_IOC_HTPROTMODE, mode, 0, NULL); + set80211(ctx, IEEE80211_IOC_HTPROTMODE, mode, 0, NULL); } static void @@ -1072,7 +1064,7 @@ txpow = (int) (2*v); if (txpow != 2*v) errx(-1, "invalid tx power (must be .5 dBm units)"); - set80211(ctx->io_s, IEEE80211_IOC_TXPOWER, txpow, 0, NULL); + set80211(ctx, IEEE80211_IOC_TXPOWER, txpow, 0, NULL); } #define IEEE80211_ROAMING_DEVICE 0 @@ -1093,37 +1085,37 @@ } else { errx(1, "unknown roaming mode"); } - set80211(ctx->io_s, IEEE80211_IOC_ROAMING, mode, 0, NULL); + set80211(ctx, IEEE80211_IOC_ROAMING, mode, 0, NULL); } static void set80211wme(if_ctx *ctx, const char *val __unused, int d) { - set80211(ctx->io_s, IEEE80211_IOC_WME, d, 0, NULL); + set80211(ctx, IEEE80211_IOC_WME, d, 0, NULL); } static void set80211hidessid(if_ctx *ctx, const char *val __unused, int d) { - set80211(ctx->io_s, IEEE80211_IOC_HIDESSID, d, 0, NULL); + set80211(ctx, IEEE80211_IOC_HIDESSID, d, 0, NULL); } static void set80211apbridge(if_ctx *ctx, const char *val __unused, int d) { - set80211(ctx->io_s, IEEE80211_IOC_APBRIDGE, d, 0, NULL); + set80211(ctx, IEEE80211_IOC_APBRIDGE, d, 0, NULL); } static void set80211fastframes(if_ctx *ctx, const char *val __unused, int d) { - set80211(ctx->io_s, IEEE80211_IOC_FF, d, 0, NULL); + set80211(ctx, IEEE80211_IOC_FF, d, 0, NULL); } static void set80211dturbo(if_ctx *ctx, const char *val __unused, int d) { - set80211(ctx->io_s, IEEE80211_IOC_TURBOP, d, 0, NULL); + set80211(ctx, IEEE80211_IOC_TURBOP, d, 0, NULL); } static void @@ -1131,7 +1123,6 @@ { struct ieee80211req_chanlist chanlist; char *temp, *cp, *tp; - int s = ctx->io_s; temp = malloc(strlen(val) + 1); if (temp == NULL) @@ -1175,16 +1166,13 @@ break; cp = tp; } - set80211(s, IEEE80211_IOC_CHANLIST, 0, sizeof(chanlist), &chanlist); + set80211(ctx, IEEE80211_IOC_CHANLIST, 0, sizeof(chanlist), &chanlist); free(temp); } static void set80211bssid(if_ctx *ctx, const char *val, int dummy __unused) { - int s = ctx->io_s; - - if (!isanyarg(val)) { char *temp; struct sockaddr_dl sdl; @@ -1199,12 +1187,12 @@ free(temp); if (sdl.sdl_alen != IEEE80211_ADDR_LEN) errx(1, "malformed link-level address"); - set80211(s, IEEE80211_IOC_BSSID, 0, + set80211(ctx, IEEE80211_IOC_BSSID, 0, IEEE80211_ADDR_LEN, LLADDR(&sdl)); } else { uint8_t zerobssid[IEEE80211_ADDR_LEN]; memset(zerobssid, 0, sizeof(zerobssid)); - set80211(s, IEEE80211_IOC_BSSID, 0, + set80211(ctx, IEEE80211_IOC_BSSID, 0, IEEE80211_ADDR_LEN, zerobssid); } } @@ -1226,92 +1214,92 @@ static void set80211cwmin(if_ctx *ctx, const char *ac, const char *val) { - set80211(ctx->io_s, IEEE80211_IOC_WME_CWMIN, atoi(val), getac(ac), NULL); + set80211(ctx, IEEE80211_IOC_WME_CWMIN, atoi(val), getac(ac), NULL); } static void set80211cwmax(if_ctx *ctx, const char *ac, const char *val) { - set80211(ctx->io_s, IEEE80211_IOC_WME_CWMAX, atoi(val), getac(ac), NULL); + set80211(ctx, IEEE80211_IOC_WME_CWMAX, atoi(val), getac(ac), NULL); } static void set80211aifs(if_ctx *ctx, const char *ac, const char *val) { - set80211(ctx->io_s, IEEE80211_IOC_WME_AIFS, atoi(val), getac(ac), NULL); + set80211(ctx, IEEE80211_IOC_WME_AIFS, atoi(val), getac(ac), NULL); } static void set80211txoplimit(if_ctx *ctx, const char *ac, const char *val) { - set80211(ctx->io_s, IEEE80211_IOC_WME_TXOPLIMIT, atoi(val), getac(ac), NULL); + set80211(ctx, IEEE80211_IOC_WME_TXOPLIMIT, atoi(val), getac(ac), NULL); } static void set80211acm(if_ctx *ctx, const char *ac, int dummy __unused) { - set80211(ctx->io_s, IEEE80211_IOC_WME_ACM, 1, getac(ac), NULL); + set80211(ctx, IEEE80211_IOC_WME_ACM, 1, getac(ac), NULL); } static void set80211noacm(if_ctx *ctx, const char *ac, int dummy __unused) { - set80211(ctx->io_s, IEEE80211_IOC_WME_ACM, 0, getac(ac), NULL); + set80211(ctx, IEEE80211_IOC_WME_ACM, 0, getac(ac), NULL); } static void set80211ackpolicy(if_ctx *ctx, const char *ac, int dummy __unused) { - set80211(ctx->io_s, IEEE80211_IOC_WME_ACKPOLICY, 1, getac(ac), NULL); + set80211(ctx, IEEE80211_IOC_WME_ACKPOLICY, 1, getac(ac), NULL); } static void set80211noackpolicy(if_ctx *ctx, const char *ac, int dummy __unused) { - set80211(ctx->io_s, IEEE80211_IOC_WME_ACKPOLICY, 0, getac(ac), NULL); + set80211(ctx, IEEE80211_IOC_WME_ACKPOLICY, 0, getac(ac), NULL); } static void set80211bsscwmin(if_ctx *ctx, const char *ac, const char *val) { - set80211(ctx->io_s, IEEE80211_IOC_WME_CWMIN, atoi(val), + set80211(ctx, IEEE80211_IOC_WME_CWMIN, atoi(val), getac(ac)|IEEE80211_WMEPARAM_BSS, NULL); } static void set80211bsscwmax(if_ctx *ctx, const char *ac, const char *val) { - set80211(ctx->io_s, IEEE80211_IOC_WME_CWMAX, atoi(val), + set80211(ctx, IEEE80211_IOC_WME_CWMAX, atoi(val), getac(ac)|IEEE80211_WMEPARAM_BSS, NULL); } static void set80211bssaifs(if_ctx *ctx, const char *ac, const char *val) { - set80211(ctx->io_s, IEEE80211_IOC_WME_AIFS, atoi(val), + set80211(ctx, IEEE80211_IOC_WME_AIFS, atoi(val), getac(ac)|IEEE80211_WMEPARAM_BSS, NULL); } static void set80211bsstxoplimit(if_ctx *ctx, const char *ac, const char *val) { - set80211(ctx->io_s, IEEE80211_IOC_WME_TXOPLIMIT, atoi(val), + set80211(ctx, IEEE80211_IOC_WME_TXOPLIMIT, atoi(val), getac(ac)|IEEE80211_WMEPARAM_BSS, NULL); } static void set80211dtimperiod(if_ctx *ctx, const char *val, int dummy __unused) { - set80211(ctx->io_s, IEEE80211_IOC_DTIM_PERIOD, atoi(val), 0, NULL); + set80211(ctx, IEEE80211_IOC_DTIM_PERIOD, atoi(val), 0, NULL); } static void set80211bintval(if_ctx *ctx, const char *val, int dummy __unused) { - set80211(ctx->io_s, IEEE80211_IOC_BEACON_INTERVAL, atoi(val), 0, NULL); + set80211(ctx, IEEE80211_IOC_BEACON_INTERVAL, atoi(val), 0, NULL); } static void -set80211macmac(int s, int op, const char *val) +set80211macmac(if_ctx *ctx, int op, const char *val) { char *temp; struct sockaddr_dl sdl; @@ -1326,19 +1314,19 @@ free(temp); if (sdl.sdl_alen != IEEE80211_ADDR_LEN) errx(1, "malformed link-level address"); - set80211(s, op, 0, IEEE80211_ADDR_LEN, LLADDR(&sdl)); + set80211(ctx, op, 0, IEEE80211_ADDR_LEN, LLADDR(&sdl)); } static void set80211addmac(if_ctx *ctx, const char *val, int dummy __unused) { - set80211macmac(ctx->io_s, IEEE80211_IOC_ADDMAC, val); + set80211macmac(ctx, IEEE80211_IOC_ADDMAC, val); } static void set80211delmac(if_ctx *ctx, const char *val, int dummy __unused) { - set80211macmac(ctx->io_s, IEEE80211_IOC_DELMAC, val); + set80211macmac(ctx, IEEE80211_IOC_DELMAC, val); } static void @@ -1362,17 +1350,17 @@ mlme.im_op = IEEE80211_MLME_DEAUTH; mlme.im_reason = IEEE80211_REASON_AUTH_EXPIRE; memcpy(mlme.im_macaddr, LLADDR(&sdl), IEEE80211_ADDR_LEN); - set80211(ctx->io_s, IEEE80211_IOC_MLME, 0, sizeof(mlme), &mlme); + set80211(ctx, IEEE80211_IOC_MLME, 0, sizeof(mlme), &mlme); } static void set80211maccmd(if_ctx *ctx, const char *val __unused, int d) { - set80211(ctx->io_s, IEEE80211_IOC_MACCMD, d, 0, NULL); + set80211(ctx, IEEE80211_IOC_MACCMD, d, 0, NULL); } static void -set80211meshrtmac(int s, int req, const char *val) +set80211meshrtmac(if_ctx *ctx, int req, const char *val) { char *temp; struct sockaddr_dl sdl; @@ -1387,26 +1375,26 @@ free(temp); if (sdl.sdl_alen != IEEE80211_ADDR_LEN) errx(1, "malformed link-level address"); - set80211(s, IEEE80211_IOC_MESH_RTCMD, req, + set80211(ctx, IEEE80211_IOC_MESH_RTCMD, req, IEEE80211_ADDR_LEN, LLADDR(&sdl)); } static void set80211addmeshrt(if_ctx *ctx, const char *val, int dummy __unused) { - set80211meshrtmac(ctx->io_s, IEEE80211_MESH_RTCMD_ADD, val); + set80211meshrtmac(ctx, IEEE80211_MESH_RTCMD_ADD, val); } static void set80211delmeshrt(if_ctx *ctx, const char *val, int dummy __unused) { - set80211meshrtmac(ctx->io_s, IEEE80211_MESH_RTCMD_DELETE, val); + set80211meshrtmac(ctx, IEEE80211_MESH_RTCMD_DELETE, val); } static void set80211meshrtcmd(if_ctx *ctx, const char *val __unused, int d) { - set80211(ctx->io_s, IEEE80211_IOC_MESH_RTCMD, d, 0, NULL); + set80211(ctx, IEEE80211_IOC_MESH_RTCMD, d, 0, NULL); } static void @@ -1422,73 +1410,73 @@ mode = IEEE80211_HWMP_ROOTMODE_RANN; else mode = IEEE80211_HWMP_ROOTMODE_DISABLED; - set80211(ctx->io_s, IEEE80211_IOC_HWMP_ROOTMODE, mode, 0, NULL); + set80211(ctx, IEEE80211_IOC_HWMP_ROOTMODE, mode, 0, NULL); } static void set80211hwmpmaxhops(if_ctx *ctx, const char *val, int dummy __unused) { - set80211(ctx->io_s, IEEE80211_IOC_HWMP_MAXHOPS, atoi(val), 0, NULL); + set80211(ctx, IEEE80211_IOC_HWMP_MAXHOPS, atoi(val), 0, NULL); } static void set80211pureg(if_ctx *ctx, const char *val __unused, int d) { - set80211(ctx->io_s, IEEE80211_IOC_PUREG, d, 0, NULL); + set80211(ctx, IEEE80211_IOC_PUREG, d, 0, NULL); } static void set80211quiet(if_ctx *ctx, const char *val __unused, int d) { - set80211(ctx->io_s, IEEE80211_IOC_QUIET, d, 0, NULL); + set80211(ctx, IEEE80211_IOC_QUIET, d, 0, NULL); } static void set80211quietperiod(if_ctx *ctx, const char *val, int dummy __unused) { - set80211(ctx->io_s, IEEE80211_IOC_QUIET_PERIOD, atoi(val), 0, NULL); + set80211(ctx, IEEE80211_IOC_QUIET_PERIOD, atoi(val), 0, NULL); } static void set80211quietcount(if_ctx *ctx, const char *val, int dummy __unused) { - set80211(ctx->io_s, IEEE80211_IOC_QUIET_COUNT, atoi(val), 0, NULL); + set80211(ctx, IEEE80211_IOC_QUIET_COUNT, atoi(val), 0, NULL); } static void set80211quietduration(if_ctx *ctx, const char *val, int dummy __unused) { - set80211(ctx->io_s, IEEE80211_IOC_QUIET_DUR, atoi(val), 0, NULL); + set80211(ctx, IEEE80211_IOC_QUIET_DUR, atoi(val), 0, NULL); } static void set80211quietoffset(if_ctx *ctx, const char *val, int dummy __unused) { - set80211(ctx->io_s, IEEE80211_IOC_QUIET_OFFSET, atoi(val), 0, NULL); + set80211(ctx, IEEE80211_IOC_QUIET_OFFSET, atoi(val), 0, NULL); } static void set80211bgscan(if_ctx *ctx, const char *val __unused, int d) { - set80211(ctx->io_s, IEEE80211_IOC_BGSCAN, d, 0, NULL); + set80211(ctx, IEEE80211_IOC_BGSCAN, d, 0, NULL); } static void set80211bgscanidle(if_ctx *ctx, const char *val, int dummy __unused) { - set80211(ctx->io_s, IEEE80211_IOC_BGSCAN_IDLE, atoi(val), 0, NULL); + set80211(ctx, IEEE80211_IOC_BGSCAN_IDLE, atoi(val), 0, NULL); } static void set80211bgscanintvl(if_ctx *ctx, const char *val, int dummy __unused) { - set80211(ctx->io_s, IEEE80211_IOC_BGSCAN_INTERVAL, atoi(val), 0, NULL); + set80211(ctx, IEEE80211_IOC_BGSCAN_INTERVAL, atoi(val), 0, NULL); } static void set80211scanvalid(if_ctx *ctx, const char *val, int dummy __unused) { - set80211(ctx->io_s, IEEE80211_IOC_SCANVALID, atoi(val), 0, NULL); + set80211(ctx, IEEE80211_IOC_SCANVALID, atoi(val), 0, NULL); } /* @@ -1632,15 +1620,14 @@ { double v = atof(val); int rssi, flags; - int s = ctx->io_s; rssi = (int) (2*v); if (rssi != 2*v) errx(-1, "invalid rssi (must be .5 dBm units)"); flags = getmodeflags(val); - getroam(s); + getroam(ctx); if (flags == 0) { /* NB: no flags => current channel */ - flags = getcurchan(s)->ic_flags; + flags = getcurchan(ctx)->ic_flags; _APPLY1(flags, roamparams, rssi, rssi); } else _APPLY(flags, roamparams, rssi, rssi); @@ -1663,13 +1650,12 @@ set80211roamrate(if_ctx *ctx, const char *val, int dummy __unused) { int rate, flags; - int s = ctx->io_s; rate = getrate(val, "roam"); flags = getmodeflags(val); - getroam(s); + getroam(ctx); if (flags == 0) { /* NB: no flags => current channel */ - flags = getcurchan(s)->ic_flags; + flags = getcurchan(ctx)->ic_flags; _APPLY_RATE1(flags, roamparams, rate, rate); } else _APPLY_RATE(flags, roamparams, rate, rate); @@ -1680,13 +1666,12 @@ set80211mcastrate(if_ctx *ctx, const char *val, int dummy __unused) { int rate, flags; - int s = ctx->io_s; rate = getrate(val, "mcast"); flags = getmodeflags(val); - gettxparams(s); + gettxparams(ctx); if (flags == 0) { /* NB: no flags => current channel */ - flags = getcurchan(s)->ic_flags; + flags = getcurchan(ctx)->ic_flags; _APPLY_RATE1(flags, txparams, mcastrate, rate); } else _APPLY_RATE(flags, txparams, mcastrate, rate); @@ -1697,13 +1682,12 @@ set80211mgtrate(if_ctx *ctx, const char *val, int dummy __unused) { int rate, flags; - int s = ctx->io_s; rate = getrate(val, "mgmt"); flags = getmodeflags(val); - gettxparams(s); + gettxparams(ctx); if (flags == 0) { /* NB: no flags => current channel */ - flags = getcurchan(s)->ic_flags; + flags = getcurchan(ctx)->ic_flags; _APPLY_RATE1(flags, txparams, mgmtrate, rate); } else _APPLY_RATE(flags, txparams, mgmtrate, rate); @@ -1714,13 +1698,12 @@ set80211ucastrate(if_ctx *ctx, const char *val, int dummy __unused) { int flags; - int s = ctx->io_s; - gettxparams(s); + gettxparams(ctx); flags = getmodeflags(val); if (isanyarg(val)) { if (flags == 0) { /* NB: no flags => current channel */ - flags = getcurchan(s)->ic_flags; + flags = getcurchan(ctx)->ic_flags; _APPLY1(flags, txparams, ucastrate, IEEE80211_FIXED_RATE_NONE); } else @@ -1729,7 +1712,7 @@ } else { int rate = getrate(val, "ucast"); if (flags == 0) { /* NB: no flags => current channel */ - flags = getcurchan(s)->ic_flags; + flags = getcurchan(ctx)->ic_flags; _APPLY_RATE1(flags, txparams, ucastrate, rate); } else _APPLY_RATE(flags, txparams, ucastrate, rate); @@ -1741,12 +1724,11 @@ set80211maxretry(if_ctx *ctx, const char *val, int dummy __unused) { int v = atoi(val), flags; - int s = ctx->io_s; flags = getmodeflags(val); - gettxparams(s); + gettxparams(ctx); if (flags == 0) { /* NB: no flags => current channel */ - flags = getcurchan(s)->ic_flags; + flags = getcurchan(ctx)->ic_flags; _APPLY1(flags, txparams, maxretry, v); } else _APPLY(flags, txparams, maxretry, v); @@ -1758,39 +1740,39 @@ static void set80211fragthreshold(if_ctx *ctx, const char *val, int dummy __unused) { - set80211(ctx->io_s, IEEE80211_IOC_FRAGTHRESHOLD, + set80211(ctx, IEEE80211_IOC_FRAGTHRESHOLD, isundefarg(val) ? IEEE80211_FRAG_MAX : atoi(val), 0, NULL); } static void set80211bmissthreshold(if_ctx *ctx, const char *val, int dummy __unused) { - set80211(ctx->io_s, IEEE80211_IOC_BMISSTHRESHOLD, + set80211(ctx, IEEE80211_IOC_BMISSTHRESHOLD, isundefarg(val) ? IEEE80211_HWBMISS_MAX : atoi(val), 0, NULL); } static void set80211burst(if_ctx *ctx, const char *val __unused, int d) { - set80211(ctx->io_s, IEEE80211_IOC_BURST, d, 0, NULL); + set80211(ctx, IEEE80211_IOC_BURST, d, 0, NULL); } static void set80211doth(if_ctx *ctx, const char *val __unused, int d) { - set80211(ctx->io_s, IEEE80211_IOC_DOTH, d, 0, NULL); + set80211(ctx, IEEE80211_IOC_DOTH, d, 0, NULL); } static void set80211dfs(if_ctx *ctx, const char *val __unused, int d) { - set80211(ctx->io_s, IEEE80211_IOC_DFS, d, 0, NULL); + set80211(ctx, IEEE80211_IOC_DFS, d, 0, NULL); } static void set80211shortgi(if_ctx *ctx, const char *val __unused, int d) { - set80211(ctx->io_s, IEEE80211_IOC_SHORTGI, + set80211(ctx, IEEE80211_IOC_SHORTGI, d ? (IEEE80211_HTCAP_SHORTGI20 | IEEE80211_HTCAP_SHORTGI40) : 0, 0, NULL); } @@ -1800,54 +1782,51 @@ set80211ampdu(if_ctx *ctx, const char *val __unused, int d) { int ampdu; - int s = ctx->io_s; - if (get80211val(s, IEEE80211_IOC_AMPDU, &du) < 0) + if (get80211val(ctx, IEEE80211_IOC_AMPDU, &du) < 0) errx(-1, "cannot set AMPDU setting"); if (d < 0) { d = -d; ampdu &= ~d; } else ampdu |= d; - set80211(s, IEEE80211_IOC_AMPDU, ampdu, 0, NULL); + set80211(ctx, IEEE80211_IOC_AMPDU, ampdu, 0, NULL); } static void set80211stbc(if_ctx *ctx, const char *val __unused, int d) { int stbc; - int s = ctx->io_s; - if (get80211val(s, IEEE80211_IOC_STBC, &stbc) < 0) + if (get80211val(ctx, IEEE80211_IOC_STBC, &stbc) < 0) errx(-1, "cannot set STBC setting"); if (d < 0) { d = -d; stbc &= ~d; } else stbc |= d; - set80211(s, IEEE80211_IOC_STBC, stbc, 0, NULL); + set80211(ctx, IEEE80211_IOC_STBC, stbc, 0, NULL); } static void set80211ldpc(if_ctx *ctx, const char *val __unused, int d) { - int s = ctx->io_s; int ldpc; - if (get80211val(s, IEEE80211_IOC_LDPC, &ldpc) < 0) + if (get80211val(ctx, IEEE80211_IOC_LDPC, &ldpc) < 0) errx(-1, "cannot set LDPC setting"); if (d < 0) { d = -d; ldpc &= ~d; } else ldpc |= d; - set80211(s, IEEE80211_IOC_LDPC, ldpc, 0, NULL); + set80211(ctx, IEEE80211_IOC_LDPC, ldpc, 0, NULL); } static void set80211uapsd(if_ctx *ctx, const char *val __unused, int d) { - set80211(ctx->io_s, IEEE80211_IOC_UAPSD, d, 0, NULL); + set80211(ctx, IEEE80211_IOC_UAPSD, d, 0, NULL); } static void @@ -1875,7 +1854,7 @@ default: errx(-1, "invalid A-MPDU limit %s", val); } - set80211(ctx->io_s, IEEE80211_IOC_AMPDU_LIMIT, v, 0, NULL); + set80211(ctx, IEEE80211_IOC_AMPDU_LIMIT, v, 0, NULL); } /* XXX 11ac density/size is different */ @@ -1914,7 +1893,7 @@ default: errx(-1, "invalid A-MPDU density %s", val); } - set80211(ctx->io_s, IEEE80211_IOC_AMPDU_DENSITY, v, 0, NULL); + set80211(ctx, IEEE80211_IOC_AMPDU_DENSITY, v, 0, NULL); } static void @@ -1922,83 +1901,81 @@ { int amsdu; - if (get80211val(ctx->io_s, IEEE80211_IOC_AMSDU, &amsdu) < 0) + if (get80211val(ctx, IEEE80211_IOC_AMSDU, &amsdu) < 0) err(-1, "cannot get AMSDU setting"); if (d < 0) { d = -d; amsdu &= ~d; } else amsdu |= d; - set80211(ctx->io_s, IEEE80211_IOC_AMSDU, amsdu, 0, NULL); + set80211(ctx, IEEE80211_IOC_AMSDU, amsdu, 0, NULL); } static void set80211amsdulimit(if_ctx *ctx, const char *val, int dummy __unused) { - set80211(ctx->io_s, IEEE80211_IOC_AMSDU_LIMIT, atoi(val), 0, NULL); + set80211(ctx, IEEE80211_IOC_AMSDU_LIMIT, atoi(val), 0, NULL); } static void set80211puren(if_ctx *ctx, const char *val __unused, int d) { - set80211(ctx->io_s, IEEE80211_IOC_PUREN, d, 0, NULL); + set80211(ctx, IEEE80211_IOC_PUREN, d, 0, NULL); } static void set80211htcompat(if_ctx *ctx, const char *val __unused, int d) { - set80211(ctx->io_s, IEEE80211_IOC_HTCOMPAT, d, 0, NULL); + set80211(ctx, IEEE80211_IOC_HTCOMPAT, d, 0, NULL); } static void set80211htconf(if_ctx *ctx, const char *val __unused, int d) { - set80211(ctx->io_s, IEEE80211_IOC_HTCONF, d, 0, NULL); + set80211(ctx, IEEE80211_IOC_HTCONF, d, 0, NULL); htconf = d; } static void set80211dwds(if_ctx *ctx, const char *val __unused, int d) { - set80211(ctx->io_s, IEEE80211_IOC_DWDS, d, 0, NULL); + set80211(ctx, IEEE80211_IOC_DWDS, d, 0, NULL); } static void set80211inact(if_ctx *ctx, const char *val __unused, int d) { - set80211(ctx->io_s, IEEE80211_IOC_INACTIVITY, d, 0, NULL); + set80211(ctx, IEEE80211_IOC_INACTIVITY, d, 0, NULL); } static void set80211tsn(if_ctx *ctx, const char *val __unused, int d) { - set80211(ctx->io_s, IEEE80211_IOC_TSN, d, 0, NULL); + set80211(ctx, IEEE80211_IOC_TSN, d, 0, NULL); } static void set80211dotd(if_ctx *ctx, const char *val __unused, int d) { - set80211(ctx->io_s, IEEE80211_IOC_DOTD, d, 0, NULL); + set80211(ctx, IEEE80211_IOC_DOTD, d, 0, NULL); } static void set80211smps(if_ctx *ctx, const char *val __unused, int d) { - set80211(ctx->io_s, IEEE80211_IOC_SMPS, d, 0, NULL); + set80211(ctx, IEEE80211_IOC_SMPS, d, 0, NULL); } static void set80211rifs(if_ctx *ctx, const char *val __unused, int d) { - set80211(ctx->io_s, IEEE80211_IOC_RIFS, d, 0, NULL); + set80211(ctx, IEEE80211_IOC_RIFS, d, 0, NULL); } static void set80211vhtconf(if_ctx *ctx, const char *val __unused, int d) { - int s = ctx->io_s; - - if (get80211val(s, IEEE80211_IOC_VHTCONF, &vhtconf) < 0) + if (get80211val(ctx, IEEE80211_IOC_VHTCONF, &vhtconf) < 0) errx(-1, "cannot set VHT setting"); printf("%s: vhtconf=0x%08x, d=%d\n", __func__, vhtconf, d); if (d < 0) { @@ -2007,55 +1984,55 @@ } else vhtconf |= d; printf("%s: vhtconf is now 0x%08x\n", __func__, vhtconf); - set80211(ctx->io_s, IEEE80211_IOC_VHTCONF, vhtconf, 0, NULL); + set80211(ctx, IEEE80211_IOC_VHTCONF, vhtconf, 0, NULL); } static void set80211tdmaslot(if_ctx *ctx, const char *val, int dummy __unused) { - set80211(ctx->io_s, IEEE80211_IOC_TDMA_SLOT, atoi(val), 0, NULL); + set80211(ctx, IEEE80211_IOC_TDMA_SLOT, atoi(val), 0, NULL); } static void set80211tdmaslotcnt(if_ctx *ctx, const char *val, int dummy __unused) { - set80211(ctx->io_s, IEEE80211_IOC_TDMA_SLOTCNT, atoi(val), 0, NULL); + set80211(ctx, IEEE80211_IOC_TDMA_SLOTCNT, atoi(val), 0, NULL); } static void set80211tdmaslotlen(if_ctx *ctx, const char *val, int dummy __unused) { - set80211(ctx->io_s, IEEE80211_IOC_TDMA_SLOTLEN, atoi(val), 0, NULL); + set80211(ctx, IEEE80211_IOC_TDMA_SLOTLEN, atoi(val), 0, NULL); } static void set80211tdmabintval(if_ctx *ctx, const char *val, int dummy __unused) { - set80211(ctx->io_s, IEEE80211_IOC_TDMA_BINTERVAL, atoi(val), 0, NULL); + set80211(ctx, IEEE80211_IOC_TDMA_BINTERVAL, atoi(val), 0, NULL); } static void set80211meshttl(if_ctx *ctx, const char *val, int dummy __unused) { - set80211(ctx->io_s, IEEE80211_IOC_MESH_TTL, atoi(val), 0, NULL); + set80211(ctx, IEEE80211_IOC_MESH_TTL, atoi(val), 0, NULL); } static void set80211meshforward(if_ctx *ctx, const char *val __unused, int d) { - set80211(ctx->io_s, IEEE80211_IOC_MESH_FWRD, d, 0, NULL); + set80211(ctx, IEEE80211_IOC_MESH_FWRD, d, 0, NULL); } static void set80211meshgate(if_ctx *ctx, const char *val __unused, int d) { - set80211(ctx->io_s, IEEE80211_IOC_MESH_GATE, d, 0, NULL); + set80211(ctx, IEEE80211_IOC_MESH_GATE, d, 0, NULL); } static void set80211meshpeering(if_ctx *ctx, const char *val __unused, int d) { - set80211(ctx->io_s, IEEE80211_IOC_MESH_AP, d, 0, NULL); + set80211(ctx, IEEE80211_IOC_MESH_AP, d, 0, NULL); } static void @@ -2064,7 +2041,7 @@ char v[12]; memcpy(v, val, sizeof(v)); - set80211(ctx->io_s, IEEE80211_IOC_MESH_PR_METRIC, 0, 0, v); + set80211(ctx, IEEE80211_IOC_MESH_PR_METRIC, 0, 0, v); } static void @@ -2073,7 +2050,7 @@ char v[12]; memcpy(v, val, sizeof(v)); - set80211(ctx->io_s, IEEE80211_IOC_MESH_PR_PATH, 0, 0, v); + set80211(ctx, IEEE80211_IOC_MESH_PR_PATH, 0, 0, v); } static int @@ -2530,7 +2507,7 @@ if (eptr == val || rd == NULL) errx(1, "unknown regdomain %s", val); } - getregdomain(ctx->io_s); + getregdomain(ctx); regdomain.regdomain = rd->sku; if (regdomain.country == 0 && rd->cc != NULL) { /* @@ -2558,7 +2535,7 @@ if (eptr == val || cc == NULL) errx(1, "unknown ISO country code %s", val); } - getregdomain(ctx->io_s); + getregdomain(ctx); regdomain.regdomain = cc->rd->sku; regdomain.country = cc->code; regdomain.isocc[0] = cc->isoname[0]; @@ -2569,7 +2546,7 @@ static void set80211location(if_ctx *ctx, const char *val __unused, int d) { - getregdomain(ctx->io_s); + getregdomain(ctx); regdomain.location = d; callback_register(setregdomain_cb, ®domain); } @@ -2577,7 +2554,7 @@ static void set80211ecm(if_ctx *ctx, const char *val __unused, int d) { - getregdomain(ctx->io_s); + getregdomain(ctx); regdomain.ecm = d; callback_register(setregdomain_cb, ®domain); } @@ -3758,12 +3735,12 @@ const uint8_t *cp; int len, idlen; - if (get80211len(ctx->io_s, IEEE80211_IOC_SCAN_RESULTS, buf, sizeof(buf), &len) < 0) + if (get80211len(ctx, IEEE80211_IOC_SCAN_RESULTS, buf, sizeof(buf), &len) < 0) errx(1, "unable to get scan results"); if (len < (int)sizeof(struct ieee80211req_scan_result)) return; - getchaninfo(ctx->io_s); + getchaninfo(ctx); printf("%-*.*s %-17.17s %4s %4s %-7s %3s %4s\n" , IEEE80211_NWID_LEN, IEEE80211_NWID_LEN, "SSID/MESH ID" @@ -3808,7 +3785,7 @@ } static void -scan_and_wait(int s) +scan_and_wait(if_ctx *ctx) { struct ieee80211_scan_req sr; struct ieee80211req ireq; @@ -3819,8 +3796,8 @@ perror("socket(PF_ROUTE,SOCK_RAW)"); return; } - (void) memset(&ireq, 0, sizeof(ireq)); - (void) strlcpy(ireq.i_name, name, sizeof(ireq.i_name)); + memset(&ireq, 0, sizeof(ireq)); + strlcpy(ireq.i_name, ctx->ifname, sizeof(ireq.i_name)); ireq.i_type = IEEE80211_IOC_SCAN_REQ; memset(&sr, 0, sizeof(sr)); @@ -3838,7 +3815,7 @@ * possible errors from net80211, even if no new scan could be * started there might still be a valid scan cache. */ - if (ioctl(s, SIOCS80211, &ireq) == 0) { + if (ioctl_ctx(ctx, SIOCS80211, &ireq) == 0) { char buf[2048]; struct if_announcemsghdr *ifan; struct rt_msghdr *rtm; @@ -3861,11 +3838,11 @@ static void set80211scan(if_ctx *ctx, const char *val __unused, int dummy __unused) { - scan_and_wait(ctx->io_s); + scan_and_wait(ctx); list_scan(ctx); } -static enum ieee80211_opmode get80211opmode(int s); +static enum ieee80211_opmode get80211opmode(if_ctx *ctx); static int gettxseq(const struct ieee80211req_sta_info *si) @@ -3904,8 +3881,7 @@ struct ieee80211req_sta_req req; uint8_t buf[24*1024]; } u; - int s = ctx->io_s; - enum ieee80211_opmode opmode = get80211opmode(s); + enum ieee80211_opmode opmode = get80211opmode(ctx); const uint8_t *cp; int len; @@ -3915,15 +3891,15 @@ /* * Get information about the associated AP. */ - (void) get80211(s, IEEE80211_IOC_BSSID, + (void) get80211(ctx, IEEE80211_IOC_BSSID, u.req.is_u.macaddr, IEEE80211_ADDR_LEN); } - if (get80211len(s, IEEE80211_IOC_STA_INFO, &u, sizeof(u), &len) < 0) + if (get80211len(ctx, IEEE80211_IOC_STA_INFO, &u, sizeof(u), &len) < 0) errx(1, "unable to get station information"); if (len < (int)sizeof(struct ieee80211req_sta_info)) return; - getchaninfo(s); + getchaninfo(ctx); if (opmode == IEEE80211_M_MBSS) printf("%-17.17s %4s %5s %5s %7s %4s %4s %4s %6s %6s\n" @@ -4126,7 +4102,7 @@ } static void -print_channels(int s, const struct ieee80211req_chaninfo *chans, +print_channels(if_ctx *ctx, const struct ieee80211req_chaninfo *chans, int allchans, int verb) { struct ieee80211req_chaninfo *achans; @@ -4142,7 +4118,7 @@ if (!allchans) { struct ieee80211req_chanlist active; - if (get80211(s, IEEE80211_IOC_CHANLIST, &active, sizeof(active)) < 0) + if (get80211(ctx, IEEE80211_IOC_CHANLIST, &active, sizeof(active)) < 0) errx(1, "unable to get active channel list"); for (i = 0; i < chans->ic_nchans; i++) { c = &chans->ic_chans[i]; @@ -4197,8 +4173,8 @@ static void list_channels(if_ctx *ctx, int allchans) { - getchaninfo(ctx->io_s); - print_channels(ctx->io_s, chaninfo, allchans, ctx->args->verbose); + getchaninfo(ctx); + print_channels(ctx, chaninfo, allchans, ctx->args->verbose); } static void @@ -4228,7 +4204,7 @@ struct ieee80211_channel *c, *prev; unsigned int i, half; - getchaninfo(ctx->io_s); + getchaninfo(ctx); achans = malloc(IEEE80211_CHANINFO_SPACE(chaninfo)); if (achans == NULL) errx(1, "no space for active channel list"); @@ -4282,7 +4258,6 @@ { struct ieee80211_devcaps_req *dc; const int verbose = ctx->args->verbose; - int s = ctx->io_s; if (verbose) dc = malloc(IEEE80211_DEVCAPS_SIZE(MAXCHAN)); @@ -4291,7 +4266,7 @@ if (dc == NULL) errx(1, "no space for device capabilities"); dc->dc_chaninfo.ic_nchans = verbose ? MAXCHAN : 1; - getdevcaps(s, dc); + getdevcaps(ctx, dc); printb("drivercaps", dc->dc_drivercaps, IEEE80211_C_BITS); if (dc->dc_cryptocaps != 0 || verbose) { putchar('\n'); @@ -4309,21 +4284,20 @@ putchar('\n'); if (verbose) { chaninfo = &dc->dc_chaninfo; /* XXX */ - print_channels(s, &dc->dc_chaninfo, 1/*allchans*/, verbose); + print_channels(ctx, &dc->dc_chaninfo, 1/*allchans*/, verbose); } free(dc); } static int -get80211wme(int s, int param, int ac, int *val) +get80211wme(if_ctx *ctx, int param, int ac, int *val) { - struct ieee80211req ireq; + struct ieee80211req ireq = {}; - (void) memset(&ireq, 0, sizeof(ireq)); - (void) strlcpy(ireq.i_name, name, sizeof(ireq.i_name)); + strlcpy(ireq.i_name, ctx->ifname, sizeof(ireq.i_name)); ireq.i_type = param; ireq.i_len = ac; - if (ioctl(s, SIOCG80211, &ireq) < 0) { + if (ioctl_ctx(ctx, SIOCG80211, &ireq) < 0) { warn("cannot get WME parameter %d, ac %d%s", param, ac & IEEE80211_WMEPARAM_VAL, ac & IEEE80211_WMEPARAM_BSS ? " (BSS)" : ""); @@ -4337,20 +4311,19 @@ list_wme_aci(if_ctx *ctx, const char *tag, int ac) { int val; - int s = ctx->io_s; printf("\t%s", tag); /* show WME BSS parameters */ - if (get80211wme(s, IEEE80211_IOC_WME_CWMIN, ac, &val) != -1) + if (get80211wme(ctx, IEEE80211_IOC_WME_CWMIN, ac, &val) != -1) printf(" cwmin %2u", val); - if (get80211wme(s, IEEE80211_IOC_WME_CWMAX, ac, &val) != -1) + if (get80211wme(ctx, IEEE80211_IOC_WME_CWMAX, ac, &val) != -1) printf(" cwmax %2u", val); - if (get80211wme(s, IEEE80211_IOC_WME_AIFS, ac, &val) != -1) + if (get80211wme(ctx, IEEE80211_IOC_WME_AIFS, ac, &val) != -1) printf(" aifs %2u", val); - if (get80211wme(s, IEEE80211_IOC_WME_TXOPLIMIT, ac, &val) != -1) + if (get80211wme(ctx, IEEE80211_IOC_WME_TXOPLIMIT, ac, &val) != -1) printf(" txopLimit %3u", val); - if (get80211wme(s, IEEE80211_IOC_WME_ACM, ac, &val) != -1) { + if (get80211wme(ctx, IEEE80211_IOC_WME_ACM, ac, &val) != -1) { if (val) printf(" acm"); else if (ctx->args->verbose) @@ -4358,7 +4331,7 @@ } /* !BSS only */ if ((ac & IEEE80211_WMEPARAM_BSS) == 0) { - if (get80211wme(s, IEEE80211_IOC_WME_ACKPOLICY, ac, &val) != -1) { + if (get80211wme(ctx, IEEE80211_IOC_WME_ACKPOLICY, ac, &val) != -1) { if (!val) printf(" -ack"); else if (ctx->args->verbose) @@ -4396,12 +4369,12 @@ } static void -list_roam(int s) +list_roam(if_ctx *ctx) { const struct ieee80211_roamparam *rp; int mode; - getroam(s); + getroam(ctx); for (mode = IEEE80211_MODE_11A; mode < IEEE80211_MODE_MAX; mode++) { rp = &roamparams.params[mode]; if (rp->rssi == 0 && rp->rate == 0) @@ -4445,12 +4418,12 @@ } static void -list_txparams(int s) +list_txparams(if_ctx *ctx) { const struct ieee80211_txparam *tp; int mode; - gettxparams(s); + gettxparams(ctx); for (mode = IEEE80211_MODE_11A; mode < IEEE80211_MODE_MAX; mode++) { tp = &txparams.params[mode]; if (tp->mgmtrate == 0 && tp->mcastrate == 0) @@ -4520,14 +4493,13 @@ static void list_mac(if_ctx *ctx) { - struct ieee80211req ireq; + struct ieee80211req ireq = {}; struct ieee80211req_maclist *acllist; int i, nacls, policy, len; uint8_t *data; char c; - (void) memset(&ireq, 0, sizeof(ireq)); - (void) strlcpy(ireq.i_name, name, sizeof(ireq.i_name)); /* XXX ?? */ + strlcpy(ireq.i_name, ctx->ifname, sizeof(ireq.i_name)); /* XXX ?? */ ireq.i_type = IEEE80211_IOC_MACCMD; ireq.i_val = IEEE80211_MACCMD_POLICY; if (ioctl_ctx(ctx, SIOCG80211, &ireq) < 0) { @@ -4614,33 +4586,30 @@ static void list_regdomain(if_ctx *ctx, int channelsalso) { - int s = ctx->io_s; - - getregdomain(s); + getregdomain(ctx); if (channelsalso) { - getchaninfo(s); + getchaninfo(ctx); spacer = ':'; print_regdomain(®domain, 1); LINE_BREAK(); - print_channels(s, chaninfo, 1/*allchans*/, 1/*verbose*/); + print_channels(ctx, chaninfo, 1/*allchans*/, 1/*verbose*/); } else print_regdomain(®domain, ctx->args->verbose); } static void -list_mesh(int s) +list_mesh(if_ctx *ctx) { - struct ieee80211req ireq; + struct ieee80211req ireq = {}; struct ieee80211req_mesh_route routes[128]; struct ieee80211req_mesh_route *rt; - (void) memset(&ireq, 0, sizeof(ireq)); - (void) strlcpy(ireq.i_name, name, sizeof(ireq.i_name)); + strlcpy(ireq.i_name, ctx->ifname, sizeof(ireq.i_name)); ireq.i_type = IEEE80211_IOC_MESH_RTCMD; ireq.i_val = IEEE80211_MESH_RTCMD_LIST; ireq.i_data = &routes; ireq.i_len = sizeof(routes); - if (ioctl(s, SIOCG80211, &ireq) < 0) + if (ioctl_ctx(ctx, SIOCG80211, &ireq) < 0) err(1, "unable to get the Mesh routing table"); printf("%-17.17s %-17.17s %4s %4s %4s %6s %s\n" @@ -4698,30 +4667,29 @@ else if (iseq(arg, "txpow")) list_txpow(ctx); else if (iseq(arg, "roam")) - list_roam(s); + list_roam(ctx); else if (iseq(arg, "txparam") || iseq(arg, "txparm")) - list_txparams(s); + list_txparams(ctx); else if (iseq(arg, "regdomain")) list_regdomain(ctx, 1); else if (iseq(arg, "countries")) list_countries(); else if (iseq(arg, "mesh")) - list_mesh(s); + list_mesh(ctx); else - errx(1, "Don't know how to list %s for %s", arg, name); + errx(1, "Don't know how to list %s for %s", arg, ctx->ifname); LINE_BREAK(); #undef iseq } static enum ieee80211_opmode -get80211opmode(int s) +get80211opmode(if_ctx *ctx) { - struct ifmediareq ifmr; + struct ifmediareq ifmr = {}; - (void) memset(&ifmr, 0, sizeof(ifmr)); - (void) strlcpy(ifmr.ifm_name, name, sizeof(ifmr.ifm_name)); + strlcpy(ifmr.ifm_name, ctx->ifname, sizeof(ifmr.ifm_name)); - if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) >= 0) { + if (ioctl_ctx(ctx, SIOCGIFMEDIA, (caddr_t)&ifmr) >= 0) { if (ifmr.ifm_current & IFM_IEEE80211_ADHOC) { if (ifmr.ifm_current & IFM_FLAG0) return IEEE80211_M_AHDEMO; @@ -4862,34 +4830,32 @@ } static int -getid(int s, int ix, void *data, size_t len, int *plen, int mesh) +getid(if_ctx *ctx, int ix, void *data, size_t len, int *plen, int mesh) { - struct ieee80211req ireq; + struct ieee80211req ireq = {}; - (void) memset(&ireq, 0, sizeof(ireq)); - (void) strlcpy(ireq.i_name, name, sizeof(ireq.i_name)); + strlcpy(ireq.i_name, ctx->ifname, sizeof(ireq.i_name)); ireq.i_type = (!mesh) ? IEEE80211_IOC_SSID : IEEE80211_IOC_MESH_ID; ireq.i_val = ix; ireq.i_data = data; ireq.i_len = len; - if (ioctl(s, SIOCG80211, &ireq) < 0) + if (ioctl_ctx(ctx, SIOCG80211, &ireq) < 0) return -1; *plen = ireq.i_len; return 0; } static int -getdevicename(int s, void *data, size_t len, int *plen) +getdevicename(if_ctx *ctx, void *data, size_t len, int *plen) { - struct ieee80211req ireq; + struct ieee80211req ireq = {}; - (void) memset(&ireq, 0, sizeof(ireq)); - (void) strlcpy(ireq.i_name, name, sizeof(ireq.i_name)); + strlcpy(ireq.i_name, ctx->ifname, sizeof(ireq.i_name)); ireq.i_type = IEEE80211_IOC_IC_NAME; ireq.i_val = -1; ireq.i_data = data; ireq.i_len = len; - if (ioctl(s, SIOCG80211, &ireq) < 0) + if (ioctl_ctx(ctx, SIOCG80211, &ireq) < 0) return (-1); *plen = ireq.i_len; return (0); @@ -4900,7 +4866,7 @@ { int s = ctx->io_s; static const uint8_t zerobssid[IEEE80211_ADDR_LEN]; - enum ieee80211_opmode opmode = get80211opmode(s); + enum ieee80211_opmode opmode = get80211opmode(ctx); int i, num, wpa, wme, bgscan, bgscaninterval, val, len, wepmode; uint8_t data[32]; const struct ieee80211_channel *c; @@ -4908,7 +4874,7 @@ const struct ieee80211_txparam *tp; const int verbose = ctx->args->verbose; - if (getid(s, -1, data, sizeof(data), &len, 0) < 0) { + if (getid(ctx, -1, data, sizeof(data), &len, 0) < 0) { /* If we can't get the SSID, this isn't an 802.11 device. */ return; } @@ -4926,15 +4892,15 @@ printf("\t"); if (opmode == IEEE80211_M_MBSS) { printf("meshid "); - getid(s, 0, data, sizeof(data), &len, 1); + getid(ctx, 0, data, sizeof(data), &len, 1); print_string(data, len); } else { - if (get80211val(s, IEEE80211_IOC_NUMSSIDS, &num) < 0) + if (get80211val(ctx, IEEE80211_IOC_NUMSSIDS, &num) < 0) num = 0; printf("ssid "); if (num > 1) { for (i = 0; i < num; i++) { - if (getid(s, i, data, sizeof(data), &len, 0) >= 0 && len > 0) { + if (getid(ctx, i, data, sizeof(data), &len, 0) >= 0 && len > 0) { printf(" %d:", i + 1); print_string(data, len); } @@ -4942,7 +4908,7 @@ } else print_string(data, len); } - c = getcurchan(s); + c = getcurchan(ctx); if (c->ic_freq != IEEE80211_CHAN_ANY) { char buf[14]; printf(" channel %d (%u MHz%s)", c->ic_ieee, c->ic_freq, @@ -4950,13 +4916,13 @@ } else if (verbose) printf(" channel UNDEF"); - if (get80211(s, IEEE80211_IOC_BSSID, data, IEEE80211_ADDR_LEN) >= 0 && + if (get80211(ctx, IEEE80211_IOC_BSSID, data, IEEE80211_ADDR_LEN) >= 0 && (memcmp(data, zerobssid, sizeof(zerobssid)) != 0 || verbose)) { printf(" bssid %s", ether_ntoa((struct ether_addr *)data)); printbssidname((struct ether_addr *)data); } - if (get80211len(s, IEEE80211_IOC_STATIONNAME, data, sizeof(data), &len) != -1) { + if (get80211len(ctx, IEEE80211_IOC_STATIONNAME, data, sizeof(data), &len) != -1) { printf("\n\tstationname "); print_string(data, len); } @@ -4967,7 +4933,7 @@ list_regdomain(ctx, 0); wpa = 0; - if (get80211val(s, IEEE80211_IOC_AUTHMODE, &val) != -1) { + if (get80211val(ctx, IEEE80211_IOC_AUTHMODE, &val) != -1) { switch (val) { case IEEE80211_AUTH_NONE: LINE_CHECK("authmode NONE"); @@ -4982,7 +4948,7 @@ LINE_CHECK("authmode 802.1x"); break; case IEEE80211_AUTH_WPA: - if (get80211val(s, IEEE80211_IOC_WPA, &wpa) < 0) + if (get80211val(ctx, IEEE80211_IOC_WPA, &wpa) < 0) wpa = 1; /* default to WPA1 */ switch (wpa) { case 2: @@ -5006,13 +4972,13 @@ } if (wpa || verbose) { - if (get80211val(s, IEEE80211_IOC_WPS, &val) != -1) { + if (get80211val(ctx, IEEE80211_IOC_WPS, &val) != -1) { if (val) LINE_CHECK("wps"); else if (verbose) LINE_CHECK("-wps"); } - if (get80211val(s, IEEE80211_IOC_TSN, &val) != -1) { + if (get80211val(ctx, IEEE80211_IOC_TSN, &val) != -1) { if (val) LINE_CHECK("tsn"); else if (verbose) @@ -5057,7 +5023,7 @@ #endif } - if (get80211val(s, IEEE80211_IOC_WEP, &wepmode) != -1 && + if (get80211val(ctx, IEEE80211_IOC_WEP, &wepmode) != -1 && wepmode != IEEE80211_WEP_NOSUP) { switch (wepmode) { @@ -5080,7 +5046,7 @@ * to print WEP status. */ - if (get80211val(s, IEEE80211_IOC_WEPTXKEY, &val) < 0) { + if (get80211val(ctx, IEEE80211_IOC_WEPTXKEY, &val) < 0) { warn("WEP support, but no tx key!"); goto end; } @@ -5089,7 +5055,7 @@ else if (wepmode != IEEE80211_WEP_OFF || verbose) LINE_CHECK("deftxkey UNDEF"); - if (get80211val(s, IEEE80211_IOC_NUMWEPKEYS, &num) < 0) { + if (get80211val(ctx, IEEE80211_IOC_NUMWEPKEYS, &num) < 0) { warn("WEP support, but no NUMWEPKEYS support!"); goto end; } @@ -5099,7 +5065,7 @@ memset(&ik, 0, sizeof(ik)); ik.ik_keyix = i; - if (get80211(s, IEEE80211_IOC_WPAKEY, &ik, sizeof(ik)) < 0) { + if (get80211(ctx, IEEE80211_IOC_WPAKEY, &ik, sizeof(ik)) < 0) { warn("WEP support, but can get keys!"); goto end; } @@ -5115,7 +5081,7 @@ ; } - if (get80211val(s, IEEE80211_IOC_POWERSAVE, &val) != -1 && + if (get80211val(ctx, IEEE80211_IOC_POWERSAVE, &val) != -1 && val != IEEE80211_POWERSAVE_NOSUP ) { if (val != IEEE80211_POWERSAVE_OFF || verbose) { switch (val) { @@ -5132,47 +5098,47 @@ LINE_CHECK("powersavemode PSP-CAM"); break; } - if (get80211val(s, IEEE80211_IOC_POWERSAVESLEEP, &val) != -1) + if (get80211val(ctx, IEEE80211_IOC_POWERSAVESLEEP, &val) != -1) LINE_CHECK("powersavesleep %d", val); } } - if (get80211val(s, IEEE80211_IOC_TXPOWER, &val) != -1) { + if (get80211val(ctx, IEEE80211_IOC_TXPOWER, &val) != -1) { if (val & 1) LINE_CHECK("txpower %d.5", val/2); else LINE_CHECK("txpower %d", val/2); } if (verbose) { - if (get80211val(s, IEEE80211_IOC_TXPOWMAX, &val) != -1) + if (get80211val(ctx, IEEE80211_IOC_TXPOWMAX, &val) != -1) LINE_CHECK("txpowmax %.1f", val/2.); } - if (get80211val(s, IEEE80211_IOC_DOTD, &val) != -1) { + if (get80211val(ctx, IEEE80211_IOC_DOTD, &val) != -1) { if (val) LINE_CHECK("dotd"); else if (verbose) LINE_CHECK("-dotd"); } - if (get80211val(s, IEEE80211_IOC_RTSTHRESHOLD, &val) != -1) { + if (get80211val(ctx, IEEE80211_IOC_RTSTHRESHOLD, &val) != -1) { if (val != IEEE80211_RTS_MAX || verbose) LINE_CHECK("rtsthreshold %d", val); } - if (get80211val(s, IEEE80211_IOC_FRAGTHRESHOLD, &val) != -1) { + if (get80211val(ctx, IEEE80211_IOC_FRAGTHRESHOLD, &val) != -1) { if (val != IEEE80211_FRAG_MAX || verbose) LINE_CHECK("fragthreshold %d", val); } if (opmode == IEEE80211_M_STA || verbose) { - if (get80211val(s, IEEE80211_IOC_BMISSTHRESHOLD, &val) != -1) { + if (get80211val(ctx, IEEE80211_IOC_BMISSTHRESHOLD, &val) != -1) { if (val != IEEE80211_HWBMISS_MAX || verbose) LINE_CHECK("bmiss %d", val); } } if (!verbose) { - gettxparams(s); + gettxparams(ctx); tp = &txparams.params[chan2mode(c)]; printrate("ucastrate", tp->ucastrate, IEEE80211_FIXED_RATE_NONE, IEEE80211_FIXED_RATE_NONE); @@ -5184,19 +5150,19 @@ LINE_CHECK("maxretry %d", tp->maxretry); } else { LINE_BREAK(); - list_txparams(s); + list_txparams(ctx); } bgscaninterval = -1; - (void) get80211val(s, IEEE80211_IOC_BGSCAN_INTERVAL, &bgscaninterval); + (void) get80211val(ctx, IEEE80211_IOC_BGSCAN_INTERVAL, &bgscaninterval); - if (get80211val(s, IEEE80211_IOC_SCANVALID, &val) != -1) { + if (get80211val(ctx, IEEE80211_IOC_SCANVALID, &val) != -1) { if (val != bgscaninterval || verbose) LINE_CHECK("scanvalid %u", val); } bgscan = 0; - if (get80211val(s, IEEE80211_IOC_BGSCAN, &bgscan) != -1) { + if (get80211val(ctx, IEEE80211_IOC_BGSCAN, &bgscan) != -1) { if (bgscan) LINE_CHECK("bgscan"); else if (verbose) @@ -5205,10 +5171,10 @@ if (bgscan || verbose) { if (bgscaninterval != -1) LINE_CHECK("bgscanintvl %u", bgscaninterval); - if (get80211val(s, IEEE80211_IOC_BGSCAN_IDLE, &val) != -1) + if (get80211val(ctx, IEEE80211_IOC_BGSCAN_IDLE, &val) != -1) LINE_CHECK("bgscanidle %u", val); if (!verbose) { - getroam(s); + getroam(ctx); rp = &roamparams.params[chan2mode(c)]; if (rp->rssi & 1) LINE_CHECK("roam:rssi %u.5", rp->rssi/2); @@ -5219,19 +5185,19 @@ get_rate_value(rp->rate)); } else { LINE_BREAK(); - list_roam(s); + list_roam(ctx); LINE_BREAK(); } } if (IEEE80211_IS_CHAN_ANYG(c) || verbose) { - if (get80211val(s, IEEE80211_IOC_PUREG, &val) != -1) { + if (get80211val(ctx, IEEE80211_IOC_PUREG, &val) != -1) { if (val) LINE_CHECK("pureg"); else if (verbose) LINE_CHECK("-pureg"); } - if (get80211val(s, IEEE80211_IOC_PROTMODE, &val) != -1) { + if (get80211val(ctx, IEEE80211_IOC_PROTMODE, &val) != -1) { switch (val) { case IEEE80211_PROTMODE_OFF: LINE_CHECK("protmode OFF"); @@ -5250,7 +5216,7 @@ } if (IEEE80211_IS_CHAN_HT(c) || verbose) { - gethtconf(s); + gethtconf(ctx); switch (htconf & 3) { case 0: case 2: @@ -5264,13 +5230,13 @@ LINE_CHECK("ht"); break; } - if (get80211val(s, IEEE80211_IOC_HTCOMPAT, &val) != -1) { + if (get80211val(ctx, IEEE80211_IOC_HTCOMPAT, &val) != -1) { if (!val) LINE_CHECK("-htcompat"); else if (verbose) LINE_CHECK("htcompat"); } - if (get80211val(s, IEEE80211_IOC_AMPDU, &val) != -1) { + if (get80211val(ctx, IEEE80211_IOC_AMPDU, &val) != -1) { switch (val) { case 0: LINE_CHECK("-ampdu"); @@ -5288,7 +5254,7 @@ } } /* XXX 11ac density/size is different */ - if (get80211val(s, IEEE80211_IOC_AMPDU_LIMIT, &val) != -1) { + if (get80211val(ctx, IEEE80211_IOC_AMPDU_LIMIT, &val) != -1) { switch (val) { case IEEE80211_HTCAP_MAXRXAMPDU_8K: LINE_CHECK("ampdulimit 8k"); @@ -5305,7 +5271,7 @@ } } /* XXX 11ac density/size is different */ - if (get80211val(s, IEEE80211_IOC_AMPDU_DENSITY, &val) != -1) { + if (get80211val(ctx, IEEE80211_IOC_AMPDU_DENSITY, &val) != -1) { switch (val) { case IEEE80211_HTCAP_MPDUDENSITY_NA: if (verbose) @@ -5334,7 +5300,7 @@ break; } } - if (get80211val(s, IEEE80211_IOC_AMSDU, &val) != -1) { + if (get80211val(ctx, IEEE80211_IOC_AMSDU, &val) != -1) { switch (val) { case 0: LINE_CHECK("-amsdu"); @@ -5352,13 +5318,13 @@ } } /* XXX amsdu limit */ - if (get80211val(s, IEEE80211_IOC_SHORTGI, &val) != -1) { + if (get80211val(ctx, IEEE80211_IOC_SHORTGI, &val) != -1) { if (val) LINE_CHECK("shortgi"); else if (verbose) LINE_CHECK("-shortgi"); } - if (get80211val(s, IEEE80211_IOC_HTPROTMODE, &val) != -1) { + if (get80211val(ctx, IEEE80211_IOC_HTPROTMODE, &val) != -1) { if (val == IEEE80211_PROTMODE_OFF) LINE_CHECK("htprotmode OFF"); else if (val != IEEE80211_PROTMODE_RTSCTS) @@ -5366,13 +5332,13 @@ else if (verbose) LINE_CHECK("htprotmode RTSCTS"); } - if (get80211val(s, IEEE80211_IOC_PUREN, &val) != -1) { + if (get80211val(ctx, IEEE80211_IOC_PUREN, &val) != -1) { if (val) LINE_CHECK("puren"); else if (verbose) LINE_CHECK("-puren"); } - if (get80211val(s, IEEE80211_IOC_SMPS, &val) != -1) { + if (get80211val(ctx, IEEE80211_IOC_SMPS, &val) != -1) { if (val == IEEE80211_HTCAP_SMPS_DYNAMIC) LINE_CHECK("smpsdyn"); else if (val == IEEE80211_HTCAP_SMPS_ENA) @@ -5380,7 +5346,7 @@ else if (verbose) LINE_CHECK("-smps"); } - if (get80211val(s, IEEE80211_IOC_RIFS, &val) != -1) { + if (get80211val(ctx, IEEE80211_IOC_RIFS, &val) != -1) { if (val) LINE_CHECK("rifs"); else if (verbose) @@ -5388,7 +5354,7 @@ } /* XXX VHT STBC? */ - if (get80211val(s, IEEE80211_IOC_STBC, &val) != -1) { + if (get80211val(ctx, IEEE80211_IOC_STBC, &val) != -1) { switch (val) { case 0: LINE_CHECK("-stbc"); @@ -5405,7 +5371,7 @@ break; } } - if (get80211val(s, IEEE80211_IOC_LDPC, &val) != -1) { + if (get80211val(ctx, IEEE80211_IOC_LDPC, &val) != -1) { switch (val) { case 0: LINE_CHECK("-ldpc"); @@ -5422,7 +5388,7 @@ break; } } - if (get80211val(s, IEEE80211_IOC_UAPSD, &val) != -1) { + if (get80211val(ctx, IEEE80211_IOC_UAPSD, &val) != -1) { switch (val) { case 0: LINE_CHECK("-uapsd"); @@ -5435,7 +5401,7 @@ } if (IEEE80211_IS_CHAN_VHT(c) || verbose) { - getvhtconf(s); + getvhtconf(ctx); if (vhtconf & IEEE80211_FVHT_VHT) LINE_CHECK("vht"); else @@ -5458,7 +5424,7 @@ LINE_CHECK("-vht80p80"); } - if (get80211val(s, IEEE80211_IOC_WME, &wme) != -1) { + if (get80211val(ctx, IEEE80211_IOC_WME, &wme) != -1) { if (wme) LINE_CHECK("wme"); else if (verbose) @@ -5466,26 +5432,26 @@ } else wme = 0; - if (get80211val(s, IEEE80211_IOC_BURST, &val) != -1) { + if (get80211val(ctx, IEEE80211_IOC_BURST, &val) != -1) { if (val) LINE_CHECK("burst"); else if (verbose) LINE_CHECK("-burst"); } - if (get80211val(s, IEEE80211_IOC_FF, &val) != -1) { + if (get80211val(ctx, IEEE80211_IOC_FF, &val) != -1) { if (val) LINE_CHECK("ff"); else if (verbose) LINE_CHECK("-ff"); } - if (get80211val(s, IEEE80211_IOC_TURBOP, &val) != -1) { + if (get80211val(ctx, IEEE80211_IOC_TURBOP, &val) != -1) { if (val) LINE_CHECK("dturbo"); else if (verbose) LINE_CHECK("-dturbo"); } - if (get80211val(s, IEEE80211_IOC_DWDS, &val) != -1) { + if (get80211val(ctx, IEEE80211_IOC_DWDS, &val) != -1) { if (val) LINE_CHECK("dwds"); else if (verbose) @@ -5493,41 +5459,41 @@ } if (opmode == IEEE80211_M_HOSTAP) { - if (get80211val(s, IEEE80211_IOC_HIDESSID, &val) != -1) { + if (get80211val(ctx, IEEE80211_IOC_HIDESSID, &val) != -1) { if (val) LINE_CHECK("hidessid"); else if (verbose) LINE_CHECK("-hidessid"); } - if (get80211val(s, IEEE80211_IOC_APBRIDGE, &val) != -1) { + if (get80211val(ctx, IEEE80211_IOC_APBRIDGE, &val) != -1) { if (!val) LINE_CHECK("-apbridge"); else if (verbose) LINE_CHECK("apbridge"); } - if (get80211val(s, IEEE80211_IOC_DTIM_PERIOD, &val) != -1) + if (get80211val(ctx, IEEE80211_IOC_DTIM_PERIOD, &val) != -1) LINE_CHECK("dtimperiod %u", val); - if (get80211val(s, IEEE80211_IOC_DOTH, &val) != -1) { + if (get80211val(ctx, IEEE80211_IOC_DOTH, &val) != -1) { if (!val) LINE_CHECK("-doth"); else if (verbose) LINE_CHECK("doth"); } - if (get80211val(s, IEEE80211_IOC_DFS, &val) != -1) { + if (get80211val(ctx, IEEE80211_IOC_DFS, &val) != -1) { if (!val) LINE_CHECK("-dfs"); else if (verbose) LINE_CHECK("dfs"); } - if (get80211val(s, IEEE80211_IOC_INACTIVITY, &val) != -1) { + if (get80211val(ctx, IEEE80211_IOC_INACTIVITY, &val) != -1) { if (!val) LINE_CHECK("-inact"); else if (verbose) LINE_CHECK("inact"); } } else { - if (get80211val(s, IEEE80211_IOC_ROAMING, &val) != -1) { + if (get80211val(ctx, IEEE80211_IOC_ROAMING, &val) != -1) { if (val != IEEE80211_ROAMING_AUTO || verbose) { switch (val) { case IEEE80211_ROAMING_DEVICE: @@ -5549,15 +5515,15 @@ } if (opmode == IEEE80211_M_AHDEMO) { - if (get80211val(s, IEEE80211_IOC_TDMA_SLOT, &val) != -1) + if (get80211val(ctx, IEEE80211_IOC_TDMA_SLOT, &val) != -1) LINE_CHECK("tdmaslot %u", val); - if (get80211val(s, IEEE80211_IOC_TDMA_SLOTCNT, &val) != -1) + if (get80211val(ctx, IEEE80211_IOC_TDMA_SLOTCNT, &val) != -1) LINE_CHECK("tdmaslotcnt %u", val); - if (get80211val(s, IEEE80211_IOC_TDMA_SLOTLEN, &val) != -1) + if (get80211val(ctx, IEEE80211_IOC_TDMA_SLOTLEN, &val) != -1) LINE_CHECK("tdmaslotlen %u", val); - if (get80211val(s, IEEE80211_IOC_TDMA_BINTERVAL, &val) != -1) + if (get80211val(ctx, IEEE80211_IOC_TDMA_BINTERVAL, &val) != -1) LINE_CHECK("tdmabintval %u", val); - } else if (get80211val(s, IEEE80211_IOC_BEACON_INTERVAL, &val) != -1) { + } else if (get80211val(ctx, IEEE80211_IOC_BEACON_INTERVAL, &val) != -1) { /* XXX default define not visible */ if (val != 100 || verbose) LINE_CHECK("bintval %u", val); @@ -5569,38 +5535,38 @@ } if (opmode == IEEE80211_M_MBSS) { - if (get80211val(s, IEEE80211_IOC_MESH_TTL, &val) != -1) { + if (get80211val(ctx, IEEE80211_IOC_MESH_TTL, &val) != -1) { LINE_CHECK("meshttl %u", val); } - if (get80211val(s, IEEE80211_IOC_MESH_AP, &val) != -1) { + if (get80211val(ctx, IEEE80211_IOC_MESH_AP, &val) != -1) { if (val) LINE_CHECK("meshpeering"); else LINE_CHECK("-meshpeering"); } - if (get80211val(s, IEEE80211_IOC_MESH_FWRD, &val) != -1) { + if (get80211val(ctx, IEEE80211_IOC_MESH_FWRD, &val) != -1) { if (val) LINE_CHECK("meshforward"); else LINE_CHECK("-meshforward"); } - if (get80211val(s, IEEE80211_IOC_MESH_GATE, &val) != -1) { + if (get80211val(ctx, IEEE80211_IOC_MESH_GATE, &val) != -1) { if (val) LINE_CHECK("meshgate"); else LINE_CHECK("-meshgate"); } - if (get80211len(s, IEEE80211_IOC_MESH_PR_METRIC, data, 12, + if (get80211len(ctx, IEEE80211_IOC_MESH_PR_METRIC, data, 12, &len) != -1) { data[len] = '\0'; LINE_CHECK("meshmetric %s", data); } - if (get80211len(s, IEEE80211_IOC_MESH_PR_PATH, data, 12, + if (get80211len(ctx, IEEE80211_IOC_MESH_PR_PATH, data, 12, &len) != -1) { data[len] = '\0'; LINE_CHECK("meshpath %s", data); } - if (get80211val(s, IEEE80211_IOC_HWMP_ROOTMODE, &val) != -1) { + if (get80211val(ctx, IEEE80211_IOC_HWMP_ROOTMODE, &val) != -1) { switch (val) { case IEEE80211_HWMP_ROOTMODE_DISABLED: LINE_CHECK("hwmprootmode DISABLED"); @@ -5619,14 +5585,14 @@ break; } } - if (get80211val(s, IEEE80211_IOC_HWMP_MAXHOPS, &val) != -1) { + if (get80211val(ctx, IEEE80211_IOC_HWMP_MAXHOPS, &val) != -1) { LINE_CHECK("hwmpmaxhops %u", val); } } LINE_BREAK(); - if (getdevicename(s, data, sizeof(data), &len) < 0) + if (getdevicename(ctx, data, sizeof(data), &len) < 0) return; LINE_CHECK("parent interface: %s", data); @@ -5634,32 +5600,32 @@ } static int -get80211(int s, int type, void *data, int len) +get80211(if_ctx *ctx, int type, void *data, int len) { - return (lib80211_get80211(s, name, type, data, len)); + return (lib80211_get80211(ctx->io_s, ctx->ifname, type, data, len)); } static int -get80211len(int s, int type, void *data, int len, int *plen) +get80211len(if_ctx *ctx, int type, void *data, int len, int *plen) { - return (lib80211_get80211len(s, name, type, data, len, plen)); + return (lib80211_get80211len(ctx->io_s, ctx->ifname, type, data, len, plen)); } static int -get80211val(int s, int type, int *val) +get80211val(if_ctx *ctx, int type, int *val) { - return (lib80211_get80211val(s, name, type, val)); + return (lib80211_get80211val(ctx->io_s, ctx->ifname, type, val)); } static void -set80211(int s, int type, int val, int len, void *data) +set80211(if_ctx *ctx, int type, int val, int len, void *data) { int ret; - ret = lib80211_set80211(s, name, type, val, len, data); + ret = lib80211_set80211(ctx->io_s, ctx->ifname, type, val, len, data); if (ret < 0) err(1, "SIOCS80211"); } @@ -5763,7 +5729,7 @@ regdomain.country != CTRY_DEFAULT) return; - getregdomain(ctx->io_s); + getregdomain(ctx); /* Check if it was already set by the driver. */ if (regdomain.regdomain != 0 || @@ -5843,7 +5809,7 @@ } static void -set80211clone_wlanmode(if_ctx *ctx __unused, const char *arg, int dummy __unused) +set80211clone_wlanmode(if_ctx *ctx, const char *arg, int dummy __unused) { #define iseq(a,b) (strncasecmp(a,b,sizeof(b)-1) == 0) if (iseq(arg, "sta")) @@ -5864,7 +5830,7 @@ } else if (iseq(arg, "mesh") || iseq(arg, "mp")) /* mesh point */ params.icp_opmode = IEEE80211_M_MBSS; else - errx(1, "Don't know to create %s for %s", arg, name); + errx(1, "Don't know to create %s for %s", arg, ctx->ifname); #undef iseq } diff --git a/sbin/ifconfig/ifipsec.c b/sbin/ifconfig/ifipsec.c --- a/sbin/ifconfig/ifipsec.c +++ b/sbin/ifconfig/ifipsec.c @@ -72,7 +72,7 @@ warn("Invalid reqid value %s", val); return; } - strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); + strlcpy(ifr.ifr_name, ctx->ifname, sizeof(ifr.ifr_name)); ifr.ifr_data = (char *)&v; if (ioctl_ctx(ctx, IPSECSREQID, &ifr) == -1) { warn("ioctl(IPSECSREQID)"); diff --git a/sbin/ifconfig/iflagg.c b/sbin/ifconfig/iflagg.c --- a/sbin/ifconfig/iflagg.c +++ b/sbin/ifconfig/iflagg.c @@ -41,10 +41,9 @@ static void setlaggport(if_ctx *ctx, const char *val, int dummy __unused) { - struct lagg_reqport rp; + struct lagg_reqport rp = {}; - bzero(&rp, sizeof(rp)); - strlcpy(rp.rp_ifname, name, sizeof(rp.rp_ifname)); + strlcpy(rp.rp_ifname, ctx->ifname, sizeof(rp.rp_ifname)); strlcpy(rp.rp_portname, val, sizeof(rp.rp_portname)); /* @@ -55,7 +54,7 @@ */ if (ioctl_ctx(ctx, SIOCSLAGGPORT, &rp) && errno != EEXIST) { warnx("%s %s: SIOCSLAGGPORT: %s", - name, val, strerror(errno)); + ctx->ifname, val, strerror(errno)); exit_code = 1; } } @@ -63,10 +62,9 @@ static void unsetlaggport(if_ctx *ctx, const char *val, int dummy __unused) { - struct lagg_reqport rp; + struct lagg_reqport rp = {}; - bzero(&rp, sizeof(rp)); - strlcpy(rp.rp_ifname, name, sizeof(rp.rp_ifname)); + strlcpy(rp.rp_ifname, ctx->ifname, sizeof(rp.rp_ifname)); strlcpy(rp.rp_portname, val, sizeof(rp.rp_portname)); if (ioctl_ctx(ctx, SIOCSLAGGDELPORT, &rp)) @@ -91,7 +89,7 @@ if (ra.ra_proto == LAGG_PROTO_MAX) errx(1, "Invalid aggregation protocol: %s", val); - strlcpy(ra.ra_ifname, name, sizeof(ra.ra_ifname)); + strlcpy(ra.ra_ifname, ctx->ifname, sizeof(ra.ra_ifname)); if (ioctl_ctx(ctx, SIOCSLAGG, &ra) != 0) err(1, "SIOCSLAGG"); } @@ -99,11 +97,10 @@ static void setlaggflowidshift(if_ctx *ctx, const char *val, int dummy __unused) { - struct lagg_reqopts ro; + struct lagg_reqopts ro = {}; - bzero(&ro, sizeof(ro)); ro.ro_opts = LAGG_OPT_FLOWIDSHIFT; - strlcpy(ro.ro_ifname, name, sizeof(ro.ro_ifname)); + strlcpy(ro.ro_ifname, ctx->ifname, sizeof(ro.ro_ifname)); ro.ro_flowid_shift = (int)strtol(val, NULL, 10); if (ro.ro_flowid_shift & ~LAGG_OPT_FLOWIDSHIFT_MASK) errx(1, "Invalid flowid_shift option: %s", val); @@ -115,10 +112,9 @@ static void setlaggrr_limit(if_ctx *ctx, const char *val, int dummy __unused) { - struct lagg_reqopts ro; + struct lagg_reqopts ro = {}; - bzero(&ro, sizeof(ro)); - strlcpy(ro.ro_ifname, name, sizeof(ro.ro_ifname)); + strlcpy(ro.ro_ifname, ctx->ifname, sizeof(ro.ro_ifname)); ro.ro_opts = LAGG_OPT_RR_LIMIT; ro.ro_bkt = (uint32_t)strtoul(val, NULL, 10); if (ro.ro_bkt == 0) @@ -131,9 +127,8 @@ static void setlaggsetopt(if_ctx *ctx, const char *val __unused, int d) { - struct lagg_reqopts ro; + struct lagg_reqopts ro = {}; - bzero(&ro, sizeof(ro)); ro.ro_opts = d; switch (ro.ro_opts) { case LAGG_OPT_USE_FLOWID: @@ -152,7 +147,7 @@ default: err(1, "Invalid lagg option"); } - strlcpy(ro.ro_ifname, name, sizeof(ro.ro_ifname)); + strlcpy(ro.ro_ifname, ctx->ifname, sizeof(ro.ro_ifname)); if (ioctl_ctx(ctx, SIOCSLAGGOPTS, &ro) != 0) err(1, "SIOCSLAGGOPTS"); @@ -181,7 +176,7 @@ if (rf.rf_flags == 0) errx(1, "No lagghash options supplied"); - strlcpy(rf.rf_ifname, name, sizeof(rf.rf_ifname)); + strlcpy(rf.rf_ifname, ctx->ifname, sizeof(rf.rf_ifname)); if (ioctl_ctx(ctx, SIOCSLAGGHASH, &rf)) err(1, "SIOCSLAGGHASH"); } @@ -227,7 +222,7 @@ const char *proto; const int verbose = ctx->args->verbose; - if (ifconfig_lagg_get_lagg_status(lifh, name, &lagg) == -1) + if (ifconfig_lagg_get_lagg_status(lifh, ctx->ifname, &lagg) == -1) return; ra = lagg->ra; diff --git a/sbin/ifconfig/ifmac.c b/sbin/ifconfig/ifmac.c --- a/sbin/ifconfig/ifmac.c +++ b/sbin/ifconfig/ifmac.c @@ -59,7 +59,7 @@ char *label_text; memset(&ifr, 0, sizeof(ifr)); - strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); + strlcpy(ifr.ifr_name, ctx->ifname, sizeof(ifr.ifr_name)); if (mac_prepare_ifnet_label(&label) == -1) return; @@ -92,7 +92,7 @@ } memset(&ifr, 0, sizeof(ifr)); - strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); + strlcpy(ifr.ifr_name, ctx->ifname, sizeof(ifr.ifr_name)); ifr.ifr_ifru.ifru_data = (void *)label; error = ioctl(ctx->io_s, SIOCSIFMAC, &ifr); diff --git a/sbin/ifconfig/ifmedia.c b/sbin/ifconfig/ifmedia.c --- a/sbin/ifconfig/ifmedia.c +++ b/sbin/ifconfig/ifmedia.c @@ -98,15 +98,15 @@ static void print_media_ifconfig(ifmedia_t); static void -media_status(if_ctx *ctx __unused) +media_status(if_ctx *ctx) { struct ifmediareq *ifmr; - if (ifconfig_media_get_mediareq(lifh, name, &ifmr) == -1) + if (ifconfig_media_get_mediareq(lifh, ctx->ifname, &ifmr) == -1) return; if (ifmr->ifm_count == 0) { - warnx("%s: no media types?", name); + warnx("%s: no media types?", ctx->ifname); goto free; } @@ -128,7 +128,7 @@ status = ifconfig_media_get_status(ifmr); printf("\tstatus: %s", status); if (strcmp(status, "no carrier") == 0 && - ifconfig_media_get_downreason(lifh, name, &ifdr) == 0) { + ifconfig_media_get_downreason(lifh, ctx->ifname, &ifdr) == 0) { switch (ifdr.ifdr_reason) { case IFDR_REASON_MSG: printf(" (%s)", ifdr.ifdr_msg); @@ -157,19 +157,19 @@ } struct ifmediareq * -ifmedia_getstate(void) +ifmedia_getstate(if_ctx *ctx) { static struct ifmediareq *ifmr = NULL; if (ifmr != NULL) return (ifmr); - if (ifconfig_media_get_mediareq(lifh, name, &ifmr) == -1) + if (ifconfig_media_get_mediareq(lifh, ctx->ifname, &ifmr) == -1) errc(1, ifconfig_err_errno(lifh), - "%s: ifconfig_media_get_mediareq", name); + "%s: ifconfig_media_get_mediareq", ctx->ifname); if (ifmr->ifm_count == 0) - errx(1, "%s: no media types?", name); + errx(1, "%s: no media types?", ctx->ifname); return (ifmr); } @@ -195,7 +195,7 @@ struct ifmediareq *ifmr; int subtype; - ifmr = ifmedia_getstate(); + ifmr = ifmedia_getstate(ctx); /* * We are primarily concerned with the top-level type. @@ -208,7 +208,7 @@ */ subtype = get_media_subtype(ifmr->ifm_ulist[0], val); - strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); + strlcpy(ifr.ifr_name, ctx->ifname, sizeof(ifr.ifr_name)); ifr.ifr_media = (ifmr->ifm_current & IFM_IMASK) | IFM_TYPE(ifmr->ifm_ulist[0]) | subtype; @@ -236,11 +236,11 @@ struct ifmediareq *ifmr; ifmedia_t options; - ifmr = ifmedia_getstate(); + ifmr = ifmedia_getstate(ctx); options = get_media_options(ifmr->ifm_ulist[0], val); - strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); + strlcpy(ifr.ifr_name, ctx->ifname, sizeof(ifr.ifr_name)); ifr.ifr_media = ifmr->ifm_current; if (clear) ifr.ifr_media &= ~options; @@ -261,13 +261,13 @@ struct ifmediareq *ifmr; int inst; - ifmr = ifmedia_getstate(); + ifmr = ifmedia_getstate(ctx); inst = atoi(val); if (inst < 0 || inst > (int)IFM_INST_MAX) errx(1, "invalid media instance: %s", val); - strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); + strlcpy(ifr.ifr_name, ctx->ifname, sizeof(ifr.ifr_name)); ifr.ifr_media = (ifmr->ifm_current & ~IFM_IMASK) | inst << IFM_ISHIFT; ifmr->ifm_current = ifr.ifr_media; @@ -280,11 +280,11 @@ struct ifmediareq *ifmr; int mode; - ifmr = ifmedia_getstate(); + ifmr = ifmedia_getstate(ctx); mode = get_media_mode(ifmr->ifm_ulist[0], val); - strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); + strlcpy(ifr.ifr_name, ctx->ifname, sizeof(ifr.ifr_name)); ifr.ifr_media = (ifmr->ifm_current & ~IFM_MMASK) | mode; ifmr->ifm_current = ifr.ifr_media; diff --git a/sbin/ifconfig/sfp.c b/sbin/ifconfig/sfp.c --- a/sbin/ifconfig/sfp.c +++ b/sbin/ifconfig/sfp.c @@ -64,7 +64,7 @@ size_t channel_count; int verbose = ctx->args->verbose; - if (ifconfig_sfp_get_sfp_info(lifh, name, &info) == -1) + if (ifconfig_sfp_get_sfp_info(lifh, ctx->ifname, &info) == -1) return; ifconfig_sfp_get_sfp_info_strings(&info, &strings); @@ -74,7 +74,7 @@ ifconfig_sfp_physical_spec(&info, &strings), strings.sfp_conn); - if (ifconfig_sfp_get_sfp_vendor_info(lifh, name, &vendor_info) == -1) + if (ifconfig_sfp_get_sfp_vendor_info(lifh, ctx->ifname, &vendor_info) == -1) return; printf("\tvendor: %s PN: %s SN: %s DATE: %s\n", @@ -94,7 +94,7 @@ } } - if (ifconfig_sfp_get_sfp_status(lifh, name, &status) == 0) { + if (ifconfig_sfp_get_sfp_status(lifh, ctx->ifname, &status) == 0) { if (ifconfig_sfp_id_is_qsfp(info.sfp_id) && verbose > 1) printf("\tnominal bitrate: %u Mbps\n", status.bitrate); printf("\tmodule temperature: %.2f C voltage: %.2f Volts\n", @@ -113,7 +113,7 @@ if (verbose > 2) { struct ifconfig_sfp_dump dump; - if (ifconfig_sfp_get_sfp_dump(lifh, name, &dump) == -1) + if (ifconfig_sfp_get_sfp_dump(lifh, ctx->ifname, &dump) == -1) return; if (ifconfig_sfp_id_is_qsfp(info.sfp_id)) {