ifconfig: remove global 'name' variable.
Consistenly use newly-added 'ctx->ifname' as the name of the current target interface. Reviewed By: kp Differential Revision: https://reviews.freebsd.org/D40438 MFC after: 2 weeks
This commit is contained in:
parent
c6f0602f23
commit
85e0016a97
@ -347,7 +347,7 @@ in_delete_first_nl(if_ctx *ctx)
|
||||
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 @@ in_exec_nl(if_ctx *ctx, unsigned long action, void *data)
|
||||
|
||||
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 @@ in_status_tunnel(if_ctx *ctx)
|
||||
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 @@ in_set_tunnel(if_ctx *ctx, struct addrinfo *srcres, struct addrinfo *dstres)
|
||||
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);
|
||||
|
||||
|
@ -199,7 +199,7 @@ setip6eui64(if_ctx *ctx, const char *cmd, int dummy __unused)
|
||||
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 @@ in6_exec_nl(if_ctx *ctx, unsigned long action, void *data)
|
||||
|
||||
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 @@ in6_status_tunnel(if_ctx *ctx)
|
||||
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 @@ in6_set_tunnel(if_ctx *ctx, struct addrinfo *srcres, struct addrinfo *dstres)
|
||||
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);
|
||||
|
@ -76,7 +76,7 @@ carp_status(if_ctx *ctx)
|
||||
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 @@ setcarp_vhid(if_ctx *ctx, const char *val, int dummy __unused)
|
||||
}
|
||||
|
||||
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 @@ setcarp_callback(if_ctx *ctx __unused, void *arg __unused)
|
||||
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");
|
||||
}
|
||||
|
||||
|
@ -85,28 +85,26 @@ get_val(const char *cp, u_long *valp)
|
||||
}
|
||||
|
||||
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 @@ do_bridgeflag(int sock, const char *ifs, int flag, int set)
|
||||
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 @@ bridge_addresses(int s, const char *prefix)
|
||||
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 @@ bridge_addresses(int s, const char *prefix)
|
||||
}
|
||||
|
||||
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 @@ bridge_status(if_ctx *ctx __unused)
|
||||
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 @@ setbridge_add(if_ctx *ctx, const char *val, int dummy __unused)
|
||||
|
||||
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 @@ setbridge_delete(if_ctx *ctx, const char *val, int dummy __unused)
|
||||
|
||||
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 @@ static void
|
||||
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 @@ setbridge_span(if_ctx *ctx, const char *val, int dummy __unused)
|
||||
|
||||
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 @@ unsetbridge_span(if_ctx *ctx, const char *val, int dummy __unused)
|
||||
|
||||
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 @@ static void
|
||||
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 @@ setbridge_flush(if_ctx *ctx, const char *val __unused, int dummy __unused)
|
||||
|
||||
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 @@ setbridge_flushall(if_ctx *ctx, const char *val __unused, int dummy __unused)
|
||||
|
||||
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 @@ setbridge_static(if_ctx *ctx, const char *val, const char *mac)
|
||||
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 @@ setbridge_deladdr(if_ctx *ctx, const char *val, int dummy __unused)
|
||||
|
||||
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 @@ static void
|
||||
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 @@ setbridge_maxaddr(if_ctx *ctx, const char *arg, int dummy __unused)
|
||||
|
||||
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 @@ setbridge_hellotime(if_ctx *ctx, const char *arg, int dummy __unused)
|
||||
|
||||
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 @@ setbridge_fwddelay(if_ctx *ctx, const char *arg, int dummy __unused)
|
||||
|
||||
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 @@ setbridge_maxage(if_ctx *ctx, const char *arg, int dummy __unused)
|
||||
|
||||
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 @@ setbridge_priority(if_ctx *ctx, const char *arg, int dummy __unused)
|
||||
|
||||
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 @@ setbridge_protocol(if_ctx *ctx, const char *arg, int dummy __unused)
|
||||
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 @@ setbridge_holdcount(if_ctx *ctx, const char *arg, int dummy __unused)
|
||||
|
||||
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 @@ setbridge_ifpriority(if_ctx *ctx, const char *ifn, const char *pri)
|
||||
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 @@ setbridge_ifpathcost(if_ctx *ctx, const char *ifn, const char *cost)
|
||||
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 @@ setbridge_ifmaxaddr(if_ctx *ctx, const char *ifn, const char *arg)
|
||||
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 @@ setbridge_timeout(if_ctx *ctx, const char *arg, int dummy __unused)
|
||||
|
||||
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 @@ static void
|
||||
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[] = {
|
||||
|
@ -123,7 +123,7 @@ ifclonecreate(if_ctx *ctx, void *arg __unused)
|
||||
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 @@ clone_create(if_ctx *ctx, const char *cmd __unused, int d __unused)
|
||||
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");
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ ifconfig_handle_t *lifh;
|
||||
*/
|
||||
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 @@ static int
|
||||
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 @@ isargcreate(const char *arg)
|
||||
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 @@ main(int ac, char *av[])
|
||||
* 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 @@ main(int ac, char *av[])
|
||||
* 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 @@ main(int ac, char *av[])
|
||||
* 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 @@ list_interfaces_ioctl(struct ifconfig_args *args)
|
||||
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 @@ list_interfaces_ioctl(struct ifconfig_args *args)
|
||||
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 @@ list_interfaces_ioctl(struct ifconfig_args *args)
|
||||
ifindex++;
|
||||
if (ifindex > 1)
|
||||
printf(" ");
|
||||
fputs(name, stdout);
|
||||
fputs(cp, stdout);
|
||||
continue;
|
||||
}
|
||||
ifindex++;
|
||||
@ -1044,7 +1045,7 @@ af_exec_ioctl(if_ctx *ctx, unsigned long action, void *data)
|
||||
{
|
||||
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 @@ delifaddr(if_ctx *ctx, const struct afswtch *afp)
|
||||
|
||||
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 @@ addifaddr(if_ctx *ctx, const struct afswtch *afp)
|
||||
{
|
||||
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 @@ ifconfig(if_ctx *orig_ctx, int iscreate, const struct afswtch *uafp)
|
||||
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 @@ ifconfig(if_ctx *orig_ctx, int iscreate, const struct afswtch *uafp)
|
||||
* 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 @@ setifflags(if_ctx *ctx, const char *vname, int value)
|
||||
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 @@ setifcapnv(if_ctx *ctx, const char *vname, const char *arg)
|
||||
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 @@ setifmetric(if_ctx *ctx, const char *val, int dummy __unused)
|
||||
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 @@ setifname(if_ctx *ctx, const char *val, int dummy __unused)
|
||||
{
|
||||
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 @@ setifdescr(if_ctx *ctx, const char *val, int dummy __unused)
|
||||
{
|
||||
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 @@ print_ifcap(struct ifconfig_args *args, int s)
|
||||
}
|
||||
|
||||
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 @@ status(struct ifconfig_args *args, const struct sockaddr_dl *sdl,
|
||||
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 @@ status(struct ifconfig_args *args, const struct sockaddr_dl *sdl,
|
||||
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);
|
||||
|
||||
|
@ -60,7 +60,7 @@ struct ifconfig_context {
|
||||
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 @@ void opt_register(struct option *);
|
||||
|
||||
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 print_ifcap(struct ifconfig_args *args, int s);
|
||||
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 @@ uint32_t if_nametoindex_nl(struct snl_state *ss, const char *ifname);
|
||||
* 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 *);
|
||||
|
||||
|
@ -123,19 +123,15 @@ nl_init_socket(struct snl_state *ss)
|
||||
}
|
||||
|
||||
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 @@ status_nl(if_ctx *ctx, struct iface *iface)
|
||||
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 @@ get_local_socket(void)
|
||||
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 @@ list_interfaces_nl(struct ifconfig_args *args)
|
||||
if (!match_iface(args, iface))
|
||||
continue;
|
||||
|
||||
set_global_ifname(&iface->link);
|
||||
ctx->ifname = iface->link.ifla_ifname;
|
||||
|
||||
if (args->namesonly) {
|
||||
if (num++ != 0)
|
||||
|
@ -51,13 +51,13 @@ fib_status(if_ctx *ctx)
|
||||
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 @@ setiffib(if_ctx *ctx, const char *val, int dummy __unused)
|
||||
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 @@ settunfib(if_ctx *ctx, const char *val, int dummy __unused)
|
||||
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)");
|
||||
|
@ -73,7 +73,7 @@ setifgrekey(if_ctx *ctx, const char *val, int dummy __unused)
|
||||
{
|
||||
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 @@ setifgreport(if_ctx *ctx, const char *val, int dummy __unused)
|
||||
{
|
||||
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)");
|
||||
|
@ -50,10 +50,9 @@ static const char rcsid[] =
|
||||
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 @@ setifgroup(if_ctx *ctx, const char *group_name, int dummy __unused)
|
||||
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 @@ unsetifgroup(if_ctx *ctx, const char *group_name, int dummy __unused)
|
||||
}
|
||||
|
||||
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;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -72,7 +72,7 @@ setreqid(if_ctx *ctx, const char *val, int dummy __unused)
|
||||
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)");
|
||||
|
@ -41,10 +41,9 @@ static char lacpbuf[120]; /* LACP peer '[(a,a,a),(p,p,p)]' */
|
||||
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 @@ setlaggport(if_ctx *ctx, const char *val, int dummy __unused)
|
||||
*/
|
||||
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 @@ setlaggport(if_ctx *ctx, const char *val, int dummy __unused)
|
||||
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 @@ setlaggproto(if_ctx *ctx, const char *val, int dummy __unused)
|
||||
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 @@ setlaggproto(if_ctx *ctx, const char *val, int dummy __unused)
|
||||
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 @@ setlaggflowidshift(if_ctx *ctx, const char *val, int dummy __unused)
|
||||
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 @@ setlaggrr_limit(if_ctx *ctx, const char *val, int dummy __unused)
|
||||
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 @@ setlaggsetopt(if_ctx *ctx, const char *val __unused, int d)
|
||||
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 @@ setlagghash(if_ctx *ctx, const char *val, int dummy __unused)
|
||||
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 @@ lagg_status(if_ctx *ctx)
|
||||
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;
|
||||
|
@ -59,7 +59,7 @@ maclabel_status(if_ctx *ctx)
|
||||
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 @@ setifmaclabel(if_ctx *ctx, const char *val, int d __unused)
|
||||
}
|
||||
|
||||
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);
|
||||
|
@ -98,15 +98,15 @@ static void print_media(ifmedia_t, bool);
|
||||
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 @@ media_status(if_ctx *ctx __unused)
|
||||
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 @@ media_status(if_ctx *ctx __unused)
|
||||
}
|
||||
|
||||
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 @@ setmedia(if_ctx *ctx, const char *val, int d __unused)
|
||||
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 @@ setmedia(if_ctx *ctx, const char *val, int d __unused)
|
||||
*/
|
||||
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 @@ domediaopt(if_ctx *ctx, const char *val, bool clear)
|
||||
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 @@ setmediainst(if_ctx *ctx, const char *val, int d __unused)
|
||||
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 @@ setmediamode(if_ctx *ctx, const char *val, int d __unused)
|
||||
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;
|
||||
|
@ -64,7 +64,7 @@ sfp_status(if_ctx *ctx)
|
||||
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 @@ sfp_status(if_ctx *ctx)
|
||||
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 @@ sfp_status(if_ctx *ctx)
|
||||
}
|
||||
}
|
||||
|
||||
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 @@ sfp_status(if_ctx *ctx)
|
||||
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)) {
|
||||
|
Loading…
Reference in New Issue
Block a user