Changeset View
Changeset View
Standalone View
Standalone View
sbin/ifconfig/ifconfig.c
Show All 38 Lines | |||||
static const char rcsid[] = | static const char rcsid[] = | ||||
"$FreeBSD$"; | "$FreeBSD$"; | ||||
#endif /* not lint */ | #endif /* not lint */ | ||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include <sys/ioctl.h> | #include <sys/ioctl.h> | ||||
#include <sys/module.h> | #include <sys/module.h> | ||||
#include <sys/linker.h> | #include <sys/linker.h> | ||||
#include <sys/nv.h> | |||||
#include <sys/queue.h> | #include <sys/queue.h> | ||||
#include <sys/socket.h> | #include <sys/socket.h> | ||||
#include <sys/time.h> | #include <sys/time.h> | ||||
#include <net/ethernet.h> | #include <net/ethernet.h> | ||||
#include <net/if.h> | #include <net/if.h> | ||||
#include <net/if_dl.h> | #include <net/if_dl.h> | ||||
#include <net/if_types.h> | #include <net/if_types.h> | ||||
▲ Show 20 Lines • Show All 931 Lines • ▼ Show 20 Lines | if (p->c_parameter == NEXTARG && p->c_u.c_func) { | ||||
if (argv[1] != NULL) | if (argv[1] != NULL) | ||||
argc--, argv++; | argc--, argv++; | ||||
} else if (p->c_parameter == NEXTARG2 && p->c_u.c_func2) { | } else if (p->c_parameter == NEXTARG2 && p->c_u.c_func2) { | ||||
if (argc < 3) | if (argc < 3) | ||||
errx(1, "'%s' requires 2 arguments", | errx(1, "'%s' requires 2 arguments", | ||||
p->c_name); | p->c_name); | ||||
p->c_u.c_func2(argv[1], argv[2], s, afp); | p->c_u.c_func2(argv[1], argv[2], s, afp); | ||||
argc -= 2, argv += 2; | argc -= 2, argv += 2; | ||||
} else if (p->c_parameter == SPARAM && p->c_u.c_func3) { | |||||
p->c_u.c_func3(*argv, p->c_sparameter, s, afp); | |||||
} else if (p->c_u.c_func) | } else if (p->c_u.c_func) | ||||
p->c_u.c_func(*argv, p->c_parameter, s, afp); | p->c_u.c_func(*argv, p->c_parameter, s, afp); | ||||
argc--, argv++; | argc--, argv++; | ||||
} | } | ||||
/* | /* | ||||
* Do any post argument processing required by the address family. | * Do any post argument processing required by the address family. | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 244 Lines • ▼ Show 20 Lines | setifcap(const char *vname, int value, int s, const struct afswtch *afp) | ||||
/* Check for no change in capabilities. */ | /* Check for no change in capabilities. */ | ||||
if (ifr.ifr_curcap == flags) | if (ifr.ifr_curcap == flags) | ||||
return; | return; | ||||
ifr.ifr_reqcap = flags; | ifr.ifr_reqcap = flags; | ||||
if (ioctl(s, SIOCSIFCAP, (caddr_t)&ifr) < 0) | if (ioctl(s, SIOCSIFCAP, (caddr_t)&ifr) < 0) | ||||
Perror(vname); | Perror(vname); | ||||
} | } | ||||
void | |||||
setifcapnv(const char *vname, const char *arg, int s, const struct afswtch *afp) | |||||
{ | |||||
nvlist_t *nvcap; | |||||
void *buf; | |||||
char *marg, *mopt; | |||||
size_t nvbuflen; | |||||
bool neg; | |||||
if (ioctl(s, SIOCGIFCAP, (caddr_t)&ifr) < 0) | |||||
Perror("ioctl (SIOCGIFCAP)"); | |||||
if ((ifr.ifr_curcap & IFCAP_NV) == 0) { | |||||
warnx("IFCAP_NV not supported"); | |||||
return; /* Not exit() */ | |||||
} | |||||
marg = strdup(arg); | |||||
if (marg == NULL) | |||||
Perror("strdup"); | |||||
nvcap = nvlist_create(0); | |||||
if (nvcap == NULL) | |||||
Perror("nvlist_create"); | |||||
while ((mopt = strsep(&marg, ",")) != NULL) { | |||||
neg = *mopt == '-'; | |||||
if (neg) | |||||
mopt++; | |||||
if (strcmp(mopt, "rxtls") == 0) { | |||||
nvlist_add_bool(nvcap, "rxtls4", !neg); | |||||
nvlist_add_bool(nvcap, "rxtls6", !neg); | |||||
} else { | |||||
nvlist_add_bool(nvcap, mopt, !neg); | |||||
} | |||||
} | |||||
buf = nvlist_pack(nvcap, &nvbuflen); | |||||
if (buf == NULL) { | |||||
errx(1, "nvlist_pack error"); | |||||
exit(1); | |||||
} | |||||
ifr.ifr_cap_nv.buf_length = ifr.ifr_cap_nv.length = nvbuflen; | |||||
ifr.ifr_cap_nv.buffer = buf; | |||||
if (ioctl(s, SIOCSIFCAPNV, (caddr_t)&ifr) < 0) | |||||
Perror(vname); | |||||
free(buf); | |||||
nvlist_destroy(nvcap); | |||||
free(marg); | |||||
} | |||||
static void | static void | ||||
setifmetric(const char *val, int dummy __unused, int s, | setifmetric(const char *val, int dummy __unused, int s, | ||||
const struct afswtch *afp) | const struct afswtch *afp) | ||||
{ | { | ||||
strlcpy(ifr.ifr_name, name, sizeof (ifr.ifr_name)); | strlcpy(ifr.ifr_name, name, sizeof (ifr.ifr_name)); | ||||
ifr.ifr_metric = atoi(val); | ifr.ifr_metric = atoi(val); | ||||
if (ioctl(s, SIOCSIFMETRIC, (caddr_t)&ifr) < 0) | if (ioctl(s, SIOCSIFMETRIC, (caddr_t)&ifr) < 0) | ||||
err(1, "ioctl SIOCSIFMETRIC (set metric)"); | err(1, "ioctl SIOCSIFMETRIC (set metric)"); | ||||
▲ Show 20 Lines • Show All 108 Lines • ▼ Show 20 Lines | |||||
* Print the status of the interface. If an address family was | * Print the status of the interface. If an address family was | ||||
* specified, show only it; otherwise, show them all. | * specified, show only it; otherwise, show them all. | ||||
*/ | */ | ||||
static void | static void | ||||
status(const struct afswtch *afp, const struct sockaddr_dl *sdl, | status(const struct afswtch *afp, const struct sockaddr_dl *sdl, | ||||
struct ifaddrs *ifa) | struct ifaddrs *ifa) | ||||
{ | { | ||||
struct ifaddrs *ift; | struct ifaddrs *ift; | ||||
int allfamilies, s; | |||||
struct ifstat ifs; | struct ifstat ifs; | ||||
nvlist_t *nvcap; | |||||
const char *nvname; | |||||
void *buf, *cookie; | |||||
int allfamilies, s, type; | |||||
bool first, val; | |||||
if (afp == NULL) { | if (afp == NULL) { | ||||
allfamilies = 1; | allfamilies = 1; | ||||
ifr.ifr_addr.sa_family = AF_LOCAL; | ifr.ifr_addr.sa_family = AF_LOCAL; | ||||
} else { | } else { | ||||
allfamilies = 0; | allfamilies = 0; | ||||
ifr.ifr_addr.sa_family = | ifr.ifr_addr.sa_family = | ||||
afp->af_af == AF_LINK ? AF_LOCAL : afp->af_af; | afp->af_af == AF_LINK ? AF_LOCAL : afp->af_af; | ||||
Show All 28 Lines | if ((descr = reallocf(descr, descrlen)) != NULL) { | ||||
} | } | ||||
} else | } else | ||||
warn("unable to allocate memory for interface" | warn("unable to allocate memory for interface" | ||||
"description"); | "description"); | ||||
break; | break; | ||||
} | } | ||||
if (ioctl(s, SIOCGIFCAP, (caddr_t)&ifr) == 0) { | if (ioctl(s, SIOCGIFCAP, (caddr_t)&ifr) == 0) { | ||||
if (ifr.ifr_curcap != 0) { | if ((ifr.ifr_curcap & IFCAP_NV) != 0) { | ||||
buf = malloc(IFR_CAP_NV_MAXBUFSIZE); | |||||
if (buf == NULL) | |||||
Perror("malloc"); | |||||
ifr.ifr_cap_nv.buffer = buf; | |||||
ifr.ifr_cap_nv.buf_length = IFR_CAP_NV_MAXBUFSIZE; | |||||
if (ioctl(s, SIOCGIFCAPNV, (caddr_t)&ifr) != 0) | |||||
Perror("ioctl (SIOCGIFCAPNV)"); | |||||
nvcap = nvlist_unpack(ifr.ifr_cap_nv.buffer, | |||||
ifr.ifr_cap_nv.length, 0); | |||||
if (nvcap == NULL) | |||||
Perror("nvlist_unpack"); | |||||
printf("\toptions"); | |||||
cookie = NULL; | |||||
for (first = true;; first = false) { | |||||
nvname = nvlist_next(nvcap, &type, &cookie); | |||||
if (nvname == NULL) { | |||||
printf("\n"); | |||||
break; | |||||
} | |||||
if (type == NV_TYPE_BOOL) { | |||||
val = nvlist_get_bool(nvcap, nvname); | |||||
if (val) { | |||||
printf("%c%s", | |||||
first ? ' ' : ',', nvname); | |||||
} | |||||
} | |||||
} | |||||
nvlist_destroy(nvcap); | |||||
free(buf); | |||||
if (ioctl(s, SIOCGIFCAP, (caddr_t)&ifr) != 0) | |||||
Perror("ioctl (SIOCGIFCAP)"); | |||||
} else if (ifr.ifr_curcap != 0) { | |||||
jhb: This only seems to handle the 'options=' line but not the 'capabilities=' line? It seems like… | |||||
Done Inline ActionsHmm, this is still not addressed. That is, you still won't show "new" capabilities in the capabilities line. capabilities corresponds to if_capabilities whereas options corresponds to if_capenable and both are extended. I think what you want instead is to do something like: if (ioctl(s, SIOCGIFCAP, ...) == 0) { if ((ifr.ifr_curcap & IFCAP_NV != 0) { ... ioctl(s, SIOCGIFCAPNV, ...); ... printf("\toptions"); cookie = NULL; for (first = true; ;; first = false) { nvname = nvlist_next(...); ... } if (supmedia) { printf("\tcapabilities"); cookie = NULL; for (first = true; first = false) { nvame = nvlist_next(...); if (nvame == NULL) { ... } if (type == NV_TYPE_BOOL) { printf("%c%s", first ? ' ' : ',', nvname); } } nvlist_destroy(nvcap); free(buf); } } else { if (ifr.ifr_curcap != 0) { printb("\toptions", ifr.ifr_curcap, IFCAPBITS); putchar('\n'); } if (supmedia && ifr.ifr_reqcap != 0) { printb("\tcapabilties", ifr.ifr_reqcap, IFCAPBITS); putchar('\n'); } } jhb: Hmm, this is still not addressed. That is, you still won't show "new" capabilities in the… | |||||
printb("\toptions", ifr.ifr_curcap, IFCAPBITS); | printb("\toptions", ifr.ifr_curcap, IFCAPBITS); | ||||
putchar('\n'); | putchar('\n'); | ||||
} | } | ||||
if (supmedia && ifr.ifr_reqcap != 0) { | if (supmedia && ifr.ifr_reqcap != 0) { | ||||
printb("\tcapabilities", ifr.ifr_reqcap, IFCAPBITS); | printb("\tcapabilities", ifr.ifr_reqcap, IFCAPBITS); | ||||
putchar('\n'); | putchar('\n'); | ||||
} | } | ||||
Done Inline ActionsWhitespace changes here could be skipped. hselasky: Whitespace changes here could be skipped. | |||||
Done Inline ActionsHow so? Patch moves the block under the nested 'else'. kib: How so? Patch moves the block under the nested 'else'. | |||||
Done Inline ActionsYou wrapped a long line, but it is not important. hselasky: You wrapped a long line, but it is not important. | |||||
} | } | ||||
tunnel_status(s); | tunnel_status(s); | ||||
for (ift = ifa; ift != NULL; ift = ift->ifa_next) { | for (ift = ifa; ift != NULL; ift = ift->ifa_next) { | ||||
if (ift->ifa_addr == NULL) | if (ift->ifa_addr == NULL) | ||||
continue; | continue; | ||||
if (strcmp(ifa->ifa_name, ift->ifa_name) != 0) | if (strcmp(ifa->ifa_name, ift->ifa_name) != 0) | ||||
▲ Show 20 Lines • Show All 249 Lines • ▼ Show 20 Lines | #endif | ||||
DEF_CMD("tso", IFCAP_TSO, setifcap), | DEF_CMD("tso", IFCAP_TSO, setifcap), | ||||
DEF_CMD("-tso", -IFCAP_TSO, setifcap), | DEF_CMD("-tso", -IFCAP_TSO, setifcap), | ||||
DEF_CMD("toe", IFCAP_TOE, setifcap), | DEF_CMD("toe", IFCAP_TOE, setifcap), | ||||
DEF_CMD("-toe", -IFCAP_TOE, setifcap), | DEF_CMD("-toe", -IFCAP_TOE, setifcap), | ||||
DEF_CMD("lro", IFCAP_LRO, setifcap), | DEF_CMD("lro", IFCAP_LRO, setifcap), | ||||
DEF_CMD("-lro", -IFCAP_LRO, setifcap), | DEF_CMD("-lro", -IFCAP_LRO, setifcap), | ||||
DEF_CMD("txtls", IFCAP_TXTLS, setifcap), | DEF_CMD("txtls", IFCAP_TXTLS, setifcap), | ||||
DEF_CMD("-txtls", -IFCAP_TXTLS, setifcap), | DEF_CMD("-txtls", -IFCAP_TXTLS, setifcap), | ||||
DEF_CMD_SARG("rxtls", IFCAP2_RXTLS4_NAME "," IFCAP2_RXTLS6_NAME, | |||||
setifcapnv), | |||||
DEF_CMD_SARG("-rxtls", "-"IFCAP2_RXTLS4_NAME ",-" IFCAP2_RXTLS6_NAME, | |||||
setifcapnv), | |||||
DEF_CMD("wol", IFCAP_WOL, setifcap), | DEF_CMD("wol", IFCAP_WOL, setifcap), | ||||
DEF_CMD("-wol", -IFCAP_WOL, setifcap), | DEF_CMD("-wol", -IFCAP_WOL, setifcap), | ||||
DEF_CMD("wol_ucast", IFCAP_WOL_UCAST, setifcap), | DEF_CMD("wol_ucast", IFCAP_WOL_UCAST, setifcap), | ||||
DEF_CMD("-wol_ucast", -IFCAP_WOL_UCAST, setifcap), | DEF_CMD("-wol_ucast", -IFCAP_WOL_UCAST, setifcap), | ||||
DEF_CMD("wol_mcast", IFCAP_WOL_MCAST, setifcap), | DEF_CMD("wol_mcast", IFCAP_WOL_MCAST, setifcap), | ||||
DEF_CMD("-wol_mcast", -IFCAP_WOL_MCAST, setifcap), | DEF_CMD("-wol_mcast", -IFCAP_WOL_MCAST, setifcap), | ||||
DEF_CMD("wol_magic", IFCAP_WOL_MAGIC, setifcap), | DEF_CMD("wol_magic", IFCAP_WOL_MAGIC, setifcap), | ||||
DEF_CMD("-wol_magic", -IFCAP_WOL_MAGIC, setifcap), | DEF_CMD("-wol_magic", -IFCAP_WOL_MAGIC, setifcap), | ||||
Show All 21 Lines |
This only seems to handle the 'options=' line but not the 'capabilities=' line? It seems like you want to subsume the capabilites= line into here as well.