af_inet6.c (301059) | af_inet6.c (301185) |
---|---|
1/* 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 15 unchanged lines hidden (view full) --- 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30#ifndef lint 31static const char rcsid[] = | 1/* 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 15 unchanged lines hidden (view full) --- 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30#ifndef lint 31static const char rcsid[] = |
32 "$FreeBSD: head/sbin/ifconfig/af_inet6.c 301059 2016-05-31 17:30:08Z allanjude $"; | 32 "$FreeBSD: head/sbin/ifconfig/af_inet6.c 301185 2016-06-02 03:16:02Z allanjude $"; |
33#endif /* not lint */ 34 35#include <sys/param.h> 36#include <sys/ioctl.h> 37#include <sys/socket.h> 38#include <net/if.h> 39 40#include <err.h> --- 19 unchanged lines hidden (view full) --- 60static struct in6_aliasreq in6_addreq = 61 { .ifra_flags = 0, 62 .ifra_lifetime = { 0, 0, ND6_INFINITE_LIFETIME, ND6_INFINITE_LIFETIME } }; 63static int ip6lifetime; 64 65static int prefix(void *, int); 66static char *sec2str(time_t); 67static int explicit_prefix = 0; | 33#endif /* not lint */ 34 35#include <sys/param.h> 36#include <sys/ioctl.h> 37#include <sys/socket.h> 38#include <net/if.h> 39 40#include <err.h> --- 19 unchanged lines hidden (view full) --- 60static struct in6_aliasreq in6_addreq = 61 { .ifra_flags = 0, 62 .ifra_lifetime = { 0, 0, ND6_INFINITE_LIFETIME, ND6_INFINITE_LIFETIME } }; 63static int ip6lifetime; 64 65static int prefix(void *, int); 66static char *sec2str(time_t); 67static int explicit_prefix = 0; |
68extern char *f_inet6, *f_addr, *f_scope; | 68extern char *f_inet6, *f_addr; |
69 70extern void setnd6flags(const char *, int, int, const struct afswtch *); 71extern void setnd6defif(const char *, int, int, const struct afswtch *); 72extern void nd6_status(int); 73 | 69 70extern void setnd6flags(const char *, int, int, const struct afswtch *); 71extern void setnd6defif(const char *, int, int, const struct afswtch *); 72extern void nd6_status(int); 73 |
74static char addr_buf[MAXHOSTNAMELEN *2 + 1]; /*for getnameinfo()*/ | 74static char addr_buf[NI_MAXHOST]; /*for getnameinfo()*/ |
75 76static void 77setifprefixlen(const char *addr, int dummy __unused, int s, 78 const struct afswtch *afp) 79{ 80 if (afp->af_getprefix != NULL) 81 afp->af_getprefix(addr, MASK); 82 explicit_prefix = 1; --- 85 unchanged lines hidden (view full) --- 168 169static void 170in6_status(int s __unused, const struct ifaddrs *ifa) 171{ 172 struct sockaddr_in6 *sin, null_sin; 173 struct in6_ifreq ifr6; 174 int s6; 175 u_int32_t flags6; | 75 76static void 77setifprefixlen(const char *addr, int dummy __unused, int s, 78 const struct afswtch *afp) 79{ 80 if (afp->af_getprefix != NULL) 81 afp->af_getprefix(addr, MASK); 82 explicit_prefix = 1; --- 85 unchanged lines hidden (view full) --- 168 169static void 170in6_status(int s __unused, const struct ifaddrs *ifa) 171{ 172 struct sockaddr_in6 *sin, null_sin; 173 struct in6_ifreq ifr6; 174 int s6; 175 u_int32_t flags6; |
176 const u_int16_t *a; | |
177 struct in6_addrlifetime lifetime; 178 struct timespec now; | 176 struct in6_addrlifetime lifetime; 177 struct timespec now; |
179 int error, n_flags, i; | 178 int error, n_flags; |
180 181 clock_gettime(CLOCK_MONOTONIC_FAST, &now); 182 183 memset(&null_sin, 0, sizeof(null_sin)); 184 185 sin = (struct sockaddr_in6 *)ifa->ifa_addr; 186 if (sin == NULL) 187 return; --- 15 unchanged lines hidden (view full) --- 203 if (ioctl(s6, SIOCGIFALIFETIME_IN6, &ifr6) < 0) { 204 warn("ioctl(SIOCGIFALIFETIME_IN6)"); 205 close(s6); 206 return; 207 } 208 lifetime = ifr6.ifr_ifru.ifru_lifetime; 209 close(s6); 210 | 179 180 clock_gettime(CLOCK_MONOTONIC_FAST, &now); 181 182 memset(&null_sin, 0, sizeof(null_sin)); 183 184 sin = (struct sockaddr_in6 *)ifa->ifa_addr; 185 if (sin == NULL) 186 return; --- 15 unchanged lines hidden (view full) --- 202 if (ioctl(s6, SIOCGIFALIFETIME_IN6, &ifr6) < 0) { 203 warn("ioctl(SIOCGIFALIFETIME_IN6)"); 204 close(s6); 205 return; 206 } 207 lifetime = ifr6.ifr_ifru.ifru_lifetime; 208 close(s6); 209 |
211 if (f_addr != NULL && strcmp(f_addr, "full") == 0) { 212 a = (const u_int16_t *)&sin->sin6_addr; 213 printf("\tinet6 "); 214 for (i = 0; i < 8; i++) { 215 printf("%04hx", ntohs(*(a + i))); 216 if (i < 7) 217 printf(":"); 218 } 219 } else { 220 if (f_addr != NULL && strcmp(f_addr, "fqdn") == 0) 221 n_flags = 0; 222 else if (f_addr != NULL && strcmp(f_addr, "host") == 0) 223 n_flags = NI_NOFQDN; 224 else 225 n_flags = NI_NUMERICHOST; 226 error = getnameinfo((struct sockaddr *)sin, sin->sin6_len, 227 addr_buf, sizeof(addr_buf), NULL, 0, 228 n_flags); 229 if (error != 0 || 230 (f_scope != NULL && strcmp(f_scope, "none") == 0)) 231 inet_ntop(AF_INET6, &sin->sin6_addr, addr_buf, 232 sizeof(addr_buf)); 233 printf("\tinet6 %s", addr_buf); 234 } | 210 if (f_addr != NULL && strcmp(f_addr, "fqdn") == 0) 211 n_flags = 0; 212 else if (f_addr != NULL && strcmp(f_addr, "host") == 0) 213 n_flags = NI_NOFQDN; 214 else 215 n_flags = NI_NUMERICHOST; 216 error = getnameinfo((struct sockaddr *)sin, sin->sin6_len, 217 addr_buf, sizeof(addr_buf), NULL, 0, 218 n_flags); 219 if (error != 0) 220 inet_ntop(AF_INET6, &sin->sin6_addr, addr_buf, 221 sizeof(addr_buf)); 222 printf("\tinet6 %s", addr_buf); |
235 236 if (ifa->ifa_flags & IFF_POINTOPOINT) { 237 sin = (struct sockaddr_in6 *)ifa->ifa_dstaddr; 238 /* 239 * some of the interfaces do not have valid destination 240 * address. 241 */ 242 if (sin != NULL && sin->sin6_family == AF_INET6) { --- 32 unchanged lines hidden (view full) --- 275 printf("deprecated "); 276 if ((flags6 & IN6_IFF_AUTOCONF) != 0) 277 printf("autoconf "); 278 if ((flags6 & IN6_IFF_TEMPORARY) != 0) 279 printf("temporary "); 280 if ((flags6 & IN6_IFF_PREFER_SOURCE) != 0) 281 printf("prefer_source "); 282 | 223 224 if (ifa->ifa_flags & IFF_POINTOPOINT) { 225 sin = (struct sockaddr_in6 *)ifa->ifa_dstaddr; 226 /* 227 * some of the interfaces do not have valid destination 228 * address. 229 */ 230 if (sin != NULL && sin->sin6_family == AF_INET6) { --- 32 unchanged lines hidden (view full) --- 263 printf("deprecated "); 264 if ((flags6 & IN6_IFF_AUTOCONF) != 0) 265 printf("autoconf "); 266 if ((flags6 & IN6_IFF_TEMPORARY) != 0) 267 printf("temporary "); 268 if ((flags6 & IN6_IFF_PREFER_SOURCE) != 0) 269 printf("prefer_source "); 270 |
283 if ((f_scope == NULL || strcmp(f_scope, "none") != 0) && 284 ((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_scope_id) | 271 if (((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_scope_id) |
285 printf("scopeid 0x%x ", 286 ((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_scope_id); 287 288 if (ip6lifetime && (lifetime.ia6t_preferred || lifetime.ia6t_expire)) { 289 printf("pltime "); 290 if (lifetime.ia6t_preferred) { 291 printf("%s ", lifetime.ia6t_preferred < now.tv_sec 292 ? "0" : --- 268 unchanged lines hidden --- | 272 printf("scopeid 0x%x ", 273 ((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_scope_id); 274 275 if (ip6lifetime && (lifetime.ia6t_preferred || lifetime.ia6t_expire)) { 276 printf("pltime "); 277 if (lifetime.ia6t_preferred) { 278 printf("%s ", lifetime.ia6t_preferred < now.tv_sec 279 ? "0" : --- 268 unchanged lines hidden --- |