Changeset View
Changeset View
Standalone View
Standalone View
sbin/ifconfig/ifconfig.c
Show First 20 Lines • Show All 110 Lines • ▼ Show 20 Lines | static bool group_member(const char *ifname, const char *match, | ||||
const char *nomatch); | const char *nomatch); | ||||
static int ifconfig(int argc, char *const *argv, int iscreate, | static int ifconfig(int argc, char *const *argv, int iscreate, | ||||
const struct afswtch *afp); | const struct afswtch *afp); | ||||
static void status(const struct afswtch *afp, const struct sockaddr_dl *sdl, | static void status(const struct afswtch *afp, const struct sockaddr_dl *sdl, | ||||
struct ifaddrs *ifa); | struct ifaddrs *ifa); | ||||
static void tunnel_status(int s); | static void tunnel_status(int s); | ||||
static _Noreturn void usage(void); | static _Noreturn void usage(void); | ||||
static int getifflags(const char *ifname, int us); | static int getifflags(const char *ifname, int us, bool err_ok); | ||||
static struct afswtch *af_getbyname(const char *name); | static struct afswtch *af_getbyname(const char *name); | ||||
static struct afswtch *af_getbyfamily(int af); | static struct afswtch *af_getbyfamily(int af); | ||||
static void af_other_status(int); | static void af_other_status(int); | ||||
void printifnamemaybe(void); | void printifnamemaybe(void); | ||||
static struct option *opts = NULL; | static struct option *opts = NULL; | ||||
▲ Show 20 Lines • Show All 470 Lines • ▼ Show 20 Lines | #endif | ||||
* which doesn't require building, sorting, and searching the entire | * which doesn't require building, sorting, and searching the entire | ||||
* system address list | * system address list | ||||
*/ | */ | ||||
if ((argc > 0) && (ifname != NULL)) { | if ((argc > 0) && (ifname != NULL)) { | ||||
iflen = strlcpy(name, ifname, sizeof(name)); | iflen = strlcpy(name, ifname, sizeof(name)); | ||||
if (iflen >= sizeof(name)) { | if (iflen >= sizeof(name)) { | ||||
warnx("%s: interface name too long, skipping", ifname); | warnx("%s: interface name too long, skipping", ifname); | ||||
} else { | } else { | ||||
flags = getifflags(name, -1); | flags = getifflags(name, -1, false); | ||||
if (!(((flags & IFF_CANTCONFIG) != 0) || | if (!(((flags & IFF_CANTCONFIG) != 0) || | ||||
(downonly && (flags & IFF_UP) != 0) || | (downonly && (flags & IFF_UP) != 0) || | ||||
(uponly && (flags & IFF_UP) == 0))) | (uponly && (flags & IFF_UP) == 0))) | ||||
ifconfig(argc, argv, 0, afp); | ifconfig(argc, argv, 0, afp); | ||||
} | } | ||||
goto done; | goto done; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 380 Lines • ▼ Show 20 Lines | if (p->c_parameter == NEXTARG && 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. | ||||
*/ | */ | ||||
if (afp->af_postproc != NULL) | if (afp->af_postproc != NULL) | ||||
afp->af_postproc(s, afp); | afp->af_postproc(s, afp, newaddr, getifflags(name, s, true)); | ||||
/* | /* | ||||
* Do deferred callbacks registered while processing | * Do deferred callbacks registered while processing | ||||
* command-line arguments. | * command-line arguments. | ||||
*/ | */ | ||||
for (cb = callbacks; cb != NULL; cb = cb->cb_next) | for (cb = callbacks; cb != NULL; cb = cb->cb_next) | ||||
cb->cb_func(s, cb->cb_arg); | cb->cb_func(s, cb->cb_arg); | ||||
/* | /* | ||||
* Do deferred operations. | * Do deferred operations. | ||||
▲ Show 20 Lines • Show All 162 Lines • ▼ Show 20 Lines | |||||
setifdstaddr(const char *addr, int param __unused, int s, | setifdstaddr(const char *addr, int param __unused, int s, | ||||
const struct afswtch *afp) | const struct afswtch *afp) | ||||
{ | { | ||||
if (afp->af_getaddr != NULL) | if (afp->af_getaddr != NULL) | ||||
afp->af_getaddr(addr, DSTADDR); | afp->af_getaddr(addr, DSTADDR); | ||||
} | } | ||||
static int | static int | ||||
getifflags(const char *ifname, int us) | getifflags(const char *ifname, int us, bool err_ok) | ||||
bz: Can you make this a bool? | |||||
Done Inline ActionsGood suggestion, thanks. karels: Good suggestion, thanks. | |||||
{ | { | ||||
struct ifreq my_ifr; | struct ifreq my_ifr; | ||||
int s; | int s; | ||||
memset(&my_ifr, 0, sizeof(my_ifr)); | memset(&my_ifr, 0, sizeof(my_ifr)); | ||||
(void) strlcpy(my_ifr.ifr_name, ifname, sizeof(my_ifr.ifr_name)); | (void) strlcpy(my_ifr.ifr_name, ifname, sizeof(my_ifr.ifr_name)); | ||||
if (us < 0) { | if (us < 0) { | ||||
if ((s = socket(AF_LOCAL, SOCK_DGRAM, 0)) < 0) | if ((s = socket(AF_LOCAL, SOCK_DGRAM, 0)) < 0) | ||||
err(1, "socket(family AF_LOCAL,SOCK_DGRAM"); | err(1, "socket(family AF_LOCAL,SOCK_DGRAM"); | ||||
} else | } else | ||||
s = us; | s = us; | ||||
if (ioctl(s, SIOCGIFFLAGS, (caddr_t)&my_ifr) < 0) { | if (ioctl(s, SIOCGIFFLAGS, (caddr_t)&my_ifr) < 0) { | ||||
if (!err_ok) { | |||||
Perror("ioctl (SIOCGIFFLAGS)"); | Perror("ioctl (SIOCGIFFLAGS)"); | ||||
exit(1); | exit(1); | ||||
} | } | ||||
} | |||||
if (us < 0) | if (us < 0) | ||||
close(s); | close(s); | ||||
return ((my_ifr.ifr_flags & 0xffff) | (my_ifr.ifr_flagshigh << 16)); | return ((my_ifr.ifr_flags & 0xffff) | (my_ifr.ifr_flagshigh << 16)); | ||||
} | } | ||||
/* | /* | ||||
* Note: doing an SIOCIGIFFLAGS scribbles on the union portion | * Note: doing an SIOCIGIFFLAGS scribbles on the union portion | ||||
* of the ifreq structure, which may confuse other parts of ifconfig. | * of the ifreq structure, which may confuse other parts of ifconfig. | ||||
* Make a private copy so we can avoid that. | * Make a private copy so we can avoid that. | ||||
*/ | */ | ||||
static void | static void | ||||
setifflags(const char *vname, int value, int s, const struct afswtch *afp) | setifflags(const char *vname, int value, int s, const struct afswtch *afp) | ||||
{ | { | ||||
struct ifreq my_ifr; | struct ifreq my_ifr; | ||||
int flags; | int flags; | ||||
flags = getifflags(name, s); | flags = getifflags(name, s, false); | ||||
if (value < 0) { | if (value < 0) { | ||||
value = -value; | value = -value; | ||||
flags &= ~value; | flags &= ~value; | ||||
} else | } else | ||||
flags |= value; | flags |= value; | ||||
memset(&my_ifr, 0, sizeof(my_ifr)); | memset(&my_ifr, 0, sizeof(my_ifr)); | ||||
(void) strlcpy(my_ifr.ifr_name, name, sizeof(my_ifr.ifr_name)); | (void) strlcpy(my_ifr.ifr_name, name, sizeof(my_ifr.ifr_name)); | ||||
my_ifr.ifr_flags = flags & 0xffff; | my_ifr.ifr_flags = flags & 0xffff; | ||||
▲ Show 20 Lines • Show All 498 Lines • Show Last 20 Lines |
Can you make this a bool?