Changeset View
Changeset View
Standalone View
Standalone View
sbin/ifconfig/af_inet6.c
Show First 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | |||||
#include "ifconfig_netlink.h" | #include "ifconfig_netlink.h" | ||||
static struct in6_ifreq in6_ridreq; | static struct in6_ifreq in6_ridreq; | ||||
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; | ||||
#ifdef WITHOUT_NETLINK | |||||
static int prefix(void *, int); | static int prefix(void *, int); | ||||
#endif | |||||
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; | extern char *f_inet6, *f_addr; | ||||
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); | ||||
▲ Show 20 Lines • Show All 72 Lines • ▼ Show 20 Lines | setip6eui64(const char *cmd, int dummy __unused, int s, | ||||
in6 = (struct in6_addr *)&in6_addreq.ifra_addr.sin6_addr; | in6 = (struct in6_addr *)&in6_addreq.ifra_addr.sin6_addr; | ||||
if (memcmp(&in6addr_any.s6_addr[8], &in6->s6_addr[8], 8) != 0) | if (memcmp(&in6addr_any.s6_addr[8], &in6->s6_addr[8], 8) != 0) | ||||
errx(EXIT_FAILURE, "interface index is already filled"); | errx(EXIT_FAILURE, "interface index is already filled"); | ||||
if (getifaddrs(&ifap) != 0) | if (getifaddrs(&ifap) != 0) | ||||
err(EXIT_FAILURE, "getifaddrs"); | err(EXIT_FAILURE, "getifaddrs"); | ||||
for (ifa = ifap; ifa; ifa = ifa->ifa_next) { | for (ifa = ifap; ifa; ifa = ifa->ifa_next) { | ||||
if (ifa->ifa_addr->sa_family == AF_INET6 && | if (ifa->ifa_addr->sa_family == AF_INET6 && | ||||
strcmp(ifa->ifa_name, name) == 0) { | strcmp(ifa->ifa_name, name) == 0) { | ||||
sin6 = (const struct sockaddr_in6 *)ifa->ifa_addr; | sin6 = (const struct sockaddr_in6 *)satosin6(ifa->ifa_addr); | ||||
if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) { | if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) { | ||||
lladdr = &sin6->sin6_addr; | lladdr = &sin6->sin6_addr; | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
if (!lladdr) | if (!lladdr) | ||||
errx(EXIT_FAILURE, "could not determine link local address"); | errx(EXIT_FAILURE, "could not determine link local address"); | ||||
▲ Show 20 Lines • Show All 167 Lines • ▼ Show 20 Lines | show_lifetime(struct ifa_cacheinfo *ci) | ||||
pl = (ci->ifa_prefered == ND6_INFINITE_LIFETIME) ? 0 : ci->ifa_prefered; | pl = (ci->ifa_prefered == ND6_INFINITE_LIFETIME) ? 0 : ci->ifa_prefered; | ||||
vl = (ci->ifa_valid == ND6_INFINITE_LIFETIME) ? 0 : ci->ifa_valid; | vl = (ci->ifa_valid == ND6_INFINITE_LIFETIME) ? 0 : ci->ifa_valid; | ||||
clock_gettime(CLOCK_MONOTONIC_FAST, &now); | clock_gettime(CLOCK_MONOTONIC_FAST, &now); | ||||
print_lifetime("pltime", pl + now.tv_sec, &now); | print_lifetime("pltime", pl + now.tv_sec, &now); | ||||
print_lifetime("vltime", vl + now.tv_sec, &now); | print_lifetime("vltime", vl + now.tv_sec, &now); | ||||
} | } | ||||
static struct sockaddr_in6 * | |||||
satosin6(struct sockaddr *sa) | |||||
{ | |||||
return ((struct sockaddr_in6 *)(void *)sa); | |||||
} | |||||
static void | static void | ||||
in6_status_nl(struct ifconfig_args *args __unused, struct io_handler *h, | in6_status_nl(struct ifconfig_args *args __unused, struct io_handler *h, | ||||
if_link_t *link, if_addr_t *ifa) | if_link_t *link, if_addr_t *ifa) | ||||
{ | { | ||||
int plen = ifa->ifa_prefixlen; | int plen = ifa->ifa_prefixlen; | ||||
uint32_t scopeid; | uint32_t scopeid; | ||||
if (ifa->ifa_local == NULL) { | if (ifa->ifa_local == NULL) { | ||||
Show All 16 Lines | in6_status_nl(struct ifconfig_args *args __unused, struct io_handler *h, | ||||
if (ifa->ifaf_vhid != 0) | if (ifa->ifaf_vhid != 0) | ||||
printf(" vhid %d", ifa->ifaf_vhid); | printf(" vhid %d", ifa->ifaf_vhid); | ||||
putchar('\n'); | putchar('\n'); | ||||
} | } | ||||
#endif | #endif | ||||
#define SIN6(x) ((struct sockaddr_in6 *) &(x)) | |||||
static struct sockaddr_in6 *sin6tab[] = { | static struct sockaddr_in6 *sin6tab[] = { | ||||
SIN6(in6_ridreq.ifr_addr), SIN6(in6_addreq.ifra_addr), | &in6_ridreq.ifr_addr, &in6_addreq.ifra_addr, | ||||
SIN6(in6_addreq.ifra_prefixmask), SIN6(in6_addreq.ifra_dstaddr) | &in6_addreq.ifra_prefixmask, &in6_addreq.ifra_dstaddr | ||||
}; | }; | ||||
static void | static void | ||||
in6_getprefix(const char *plen, int which) | in6_getprefix(const char *plen, int which) | ||||
{ | { | ||||
struct sockaddr_in6 *sin = sin6tab[which]; | struct sockaddr_in6 *sin = sin6tab[which]; | ||||
u_char *cp; | u_char *cp; | ||||
int len = atoi(plen); | int len = atoi(plen); | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | if (error != 0) { | ||||
errx(1, "%s: bad value", s); | errx(1, "%s: bad value", s); | ||||
} else { | } else { | ||||
bcopy(res->ai_addr, sin, res->ai_addrlen); | bcopy(res->ai_addr, sin, res->ai_addrlen); | ||||
freeaddrinfo(res); | freeaddrinfo(res); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
#ifdef WITHOUT_NETLINK | |||||
static int | static int | ||||
prefix(void *val, int size) | prefix(void *val, int size) | ||||
{ | { | ||||
u_char *name = (u_char *)val; | u_char *name = (u_char *)val; | ||||
int byte, bit, plen = 0; | int byte, bit, plen = 0; | ||||
for (byte = 0; byte < size; byte++, plen += 8) | for (byte = 0; byte < size; byte++, plen += 8) | ||||
if (name[byte] != 0xff) | if (name[byte] != 0xff) | ||||
break; | break; | ||||
if (byte == size) | if (byte == size) | ||||
return (plen); | return (plen); | ||||
for (bit = 7; bit != 0; bit--, plen++) | for (bit = 7; bit != 0; bit--, plen++) | ||||
if (!(name[byte] & (1 << bit))) | if (!(name[byte] & (1 << bit))) | ||||
break; | break; | ||||
for (; bit != 0; bit--) | for (; bit != 0; bit--) | ||||
if (name[byte] & (1 << bit)) | if (name[byte] & (1 << bit)) | ||||
return(0); | return(0); | ||||
byte++; | byte++; | ||||
for (; byte < size; byte++) | for (; byte < size; byte++) | ||||
if (name[byte]) | if (name[byte]) | ||||
return(0); | return(0); | ||||
return (plen); | return (plen); | ||||
} | } | ||||
#endif | |||||
static char * | static char * | ||||
sec2str(time_t total) | sec2str(time_t total) | ||||
{ | { | ||||
static char result[256]; | static char result[256]; | ||||
int days, hours, mins, secs; | int days, hours, mins, secs; | ||||
int first = 1; | int first = 1; | ||||
char *p = result; | char *p = result; | ||||
▲ Show 20 Lines • Show All 173 Lines • Show Last 20 Lines |