Changeset View
Changeset View
Standalone View
Standalone View
head/sbin/ifconfig/af_inet6.c
Show First 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | |||||
static struct in6_aliasreq in6_addreq = | static struct in6_aliasreq in6_addreq = | ||||
{ .ifra_flags = 0, | { .ifra_flags = 0, | ||||
.ifra_lifetime = { 0, 0, ND6_INFINITE_LIFETIME, ND6_INFINITE_LIFETIME } }; | .ifra_lifetime = { 0, 0, ND6_INFINITE_LIFETIME, ND6_INFINITE_LIFETIME } }; | ||||
static int ip6lifetime; | static int ip6lifetime; | ||||
static int prefix(void *, int); | static int prefix(void *, int); | ||||
static char *sec2str(time_t); | static char *sec2str(time_t); | ||||
static int explicit_prefix = 0; | static int explicit_prefix = 0; | ||||
extern char *f_inet6, *f_addr, *f_scope; | extern char *f_inet6, *f_addr; | ||||
hrs: Is there any practical use case of f_addr == "full" or f_scope?
I think we should conform to… | |||||
Not Done Inline ActionsI admit I was just looking to see what else I could do, to make something more robust, rather than just -c and -s for CIDR and subnet. Removed. allanjude: I admit I was just looking to see what else I could do, to make something more robust, rather… | |||||
extern void setnd6flags(const char *, int, int, const struct afswtch *); | extern void setnd6flags(const char *, int, int, const struct afswtch *); | ||||
extern void setnd6defif(const char *, int, int, const struct afswtch *); | extern void setnd6defif(const char *, int, int, const struct afswtch *); | ||||
extern void nd6_status(int); | extern void nd6_status(int); | ||||
static char addr_buf[MAXHOSTNAMELEN *2 + 1]; /*for getnameinfo()*/ | static char addr_buf[NI_MAXHOST]; /*for getnameinfo()*/ | ||||
static void | static void | ||||
setifprefixlen(const char *addr, int dummy __unused, int s, | setifprefixlen(const char *addr, int dummy __unused, int s, | ||||
const struct afswtch *afp) | const struct afswtch *afp) | ||||
{ | { | ||||
if (afp->af_getprefix != NULL) | if (afp->af_getprefix != NULL) | ||||
afp->af_getprefix(addr, MASK); | afp->af_getprefix(addr, MASK); | ||||
explicit_prefix = 1; | explicit_prefix = 1; | ||||
▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | |||||
static void | static void | ||||
in6_status(int s __unused, const struct ifaddrs *ifa) | in6_status(int s __unused, const struct ifaddrs *ifa) | ||||
{ | { | ||||
struct sockaddr_in6 *sin, null_sin; | struct sockaddr_in6 *sin, null_sin; | ||||
struct in6_ifreq ifr6; | struct in6_ifreq ifr6; | ||||
int s6; | int s6; | ||||
u_int32_t flags6; | u_int32_t flags6; | ||||
const u_int16_t *a; | |||||
struct in6_addrlifetime lifetime; | struct in6_addrlifetime lifetime; | ||||
struct timespec now; | struct timespec now; | ||||
int error, n_flags, i; | int error, n_flags; | ||||
clock_gettime(CLOCK_MONOTONIC_FAST, &now); | clock_gettime(CLOCK_MONOTONIC_FAST, &now); | ||||
memset(&null_sin, 0, sizeof(null_sin)); | memset(&null_sin, 0, sizeof(null_sin)); | ||||
sin = (struct sockaddr_in6 *)ifa->ifa_addr; | sin = (struct sockaddr_in6 *)ifa->ifa_addr; | ||||
if (sin == NULL) | if (sin == NULL) | ||||
return; | return; | ||||
Show All 15 Lines | in6_status(int s __unused, const struct ifaddrs *ifa) | ||||
if (ioctl(s6, SIOCGIFALIFETIME_IN6, &ifr6) < 0) { | if (ioctl(s6, SIOCGIFALIFETIME_IN6, &ifr6) < 0) { | ||||
warn("ioctl(SIOCGIFALIFETIME_IN6)"); | warn("ioctl(SIOCGIFALIFETIME_IN6)"); | ||||
close(s6); | close(s6); | ||||
return; | return; | ||||
} | } | ||||
lifetime = ifr6.ifr_ifru.ifru_lifetime; | lifetime = ifr6.ifr_ifru.ifru_lifetime; | ||||
close(s6); | close(s6); | ||||
if (f_addr != NULL && strcmp(f_addr, "full") == 0) { | |||||
a = (const u_int16_t *)&sin->sin6_addr; | |||||
printf("\tinet6 "); | |||||
for (i = 0; i < 8; i++) { | |||||
printf("%04hx", ntohs(*(a + i))); | |||||
if (i < 7) | |||||
printf(":"); | |||||
} | |||||
} else { | |||||
if (f_addr != NULL && strcmp(f_addr, "fqdn") == 0) | if (f_addr != NULL && strcmp(f_addr, "fqdn") == 0) | ||||
n_flags = 0; | n_flags = 0; | ||||
else if (f_addr != NULL && strcmp(f_addr, "host") == 0) | else if (f_addr != NULL && strcmp(f_addr, "host") == 0) | ||||
n_flags = NI_NOFQDN; | n_flags = NI_NOFQDN; | ||||
else | else | ||||
n_flags = NI_NUMERICHOST; | n_flags = NI_NUMERICHOST; | ||||
error = getnameinfo((struct sockaddr *)sin, sin->sin6_len, | error = getnameinfo((struct sockaddr *)sin, sin->sin6_len, | ||||
addr_buf, sizeof(addr_buf), NULL, 0, | addr_buf, sizeof(addr_buf), NULL, 0, | ||||
n_flags); | n_flags); | ||||
if (error != 0 || | if (error != 0) | ||||
(f_scope != NULL && strcmp(f_scope, "none") == 0)) | |||||
inet_ntop(AF_INET6, &sin->sin6_addr, addr_buf, | inet_ntop(AF_INET6, &sin->sin6_addr, addr_buf, | ||||
sizeof(addr_buf)); | sizeof(addr_buf)); | ||||
printf("\tinet6 %s", addr_buf); | printf("\tinet6 %s", addr_buf); | ||||
} | |||||
if (ifa->ifa_flags & IFF_POINTOPOINT) { | if (ifa->ifa_flags & IFF_POINTOPOINT) { | ||||
sin = (struct sockaddr_in6 *)ifa->ifa_dstaddr; | sin = (struct sockaddr_in6 *)ifa->ifa_dstaddr; | ||||
/* | /* | ||||
* some of the interfaces do not have valid destination | * some of the interfaces do not have valid destination | ||||
* address. | * address. | ||||
*/ | */ | ||||
if (sin != NULL && sin->sin6_family == AF_INET6) { | if (sin != NULL && sin->sin6_family == AF_INET6) { | ||||
Show All 32 Lines | if ((flags6 & IN6_IFF_DEPRECATED) != 0) | ||||
printf("deprecated "); | printf("deprecated "); | ||||
if ((flags6 & IN6_IFF_AUTOCONF) != 0) | if ((flags6 & IN6_IFF_AUTOCONF) != 0) | ||||
printf("autoconf "); | printf("autoconf "); | ||||
if ((flags6 & IN6_IFF_TEMPORARY) != 0) | if ((flags6 & IN6_IFF_TEMPORARY) != 0) | ||||
printf("temporary "); | printf("temporary "); | ||||
if ((flags6 & IN6_IFF_PREFER_SOURCE) != 0) | if ((flags6 & IN6_IFF_PREFER_SOURCE) != 0) | ||||
printf("prefer_source "); | printf("prefer_source "); | ||||
if ((f_scope == NULL || strcmp(f_scope, "none") != 0) && | if (((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_scope_id) | ||||
((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_scope_id) | |||||
printf("scopeid 0x%x ", | printf("scopeid 0x%x ", | ||||
((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_scope_id); | ((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_scope_id); | ||||
if (ip6lifetime && (lifetime.ia6t_preferred || lifetime.ia6t_expire)) { | if (ip6lifetime && (lifetime.ia6t_preferred || lifetime.ia6t_expire)) { | ||||
printf("pltime "); | printf("pltime "); | ||||
if (lifetime.ia6t_preferred) { | if (lifetime.ia6t_preferred) { | ||||
printf("%s ", lifetime.ia6t_preferred < now.tv_sec | printf("%s ", lifetime.ia6t_preferred < now.tv_sec | ||||
? "0" : | ? "0" : | ||||
▲ Show 20 Lines • Show All 268 Lines • Show Last 20 Lines |
Is there any practical use case of f_addr == "full" or f_scope?
I think we should conform to RFC 5952 about the leading zeros even if the fixed-width representation may look useful. And I cannot understand where f_scope == "none" is useful. A scope id is a part of a link-local scope address.