ndp.c (302408) | ndp.c (314041) |
---|---|
1/* $FreeBSD: stable/11/usr.sbin/ndp/ndp.c 292465 2015-12-19 09:18:01Z ume $ */ | 1/* $FreeBSD: stable/11/usr.sbin/ndp/ndp.c 314041 2017-02-21 12:45:56Z garga $ */ |
2/* $KAME: ndp.c,v 1.104 2003/06/27 07:48:39 itojun Exp $ */ 3 4/* 5 * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions --- 94 unchanged lines hidden (view full) --- 104#include <string.h> 105#include <paths.h> 106#include <err.h> 107#include <stdlib.h> 108#include <fcntl.h> 109#include <unistd.h> 110#include "gmt2local.h" 111 | 2/* $KAME: ndp.c,v 1.104 2003/06/27 07:48:39 itojun Exp $ */ 3 4/* 5 * Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions --- 94 unchanged lines hidden (view full) --- 104#include <string.h> 105#include <paths.h> 106#include <err.h> 107#include <stdlib.h> 108#include <fcntl.h> 109#include <unistd.h> 110#include "gmt2local.h" 111 |
112#define NEXTADDR(w, s) \ 113 if (rtm->rtm_addrs & (w)) { \ 114 bcopy((char *)&s, cp, sizeof(s)); cp += SA_SIZE(&s);} | 112#define NEXTADDR(w, s) \ 113 if (rtm->rtm_addrs & (w)) { \ 114 bcopy((char *)&s, cp, sizeof(s)); \ 115 cp += SA_SIZE(&s); \ 116 } |
115 | 117 |
116 | |
117static pid_t pid; 118static int nflag; 119static int tflag; 120static int32_t thiszone; /* time difference with gmt */ 121static int s = -1; 122static int repeat = 0; 123 124static char host_buf[NI_MAXHOST]; /* getnameinfo() */ --- 399 unchanged lines hidden (view full) --- 524 return 1; 525 } 526 527delete: 528 if (sdl->sdl_family != AF_LINK) { 529 printf("cannot locate %s\n", host); 530 return (1); 531 } | 118static pid_t pid; 119static int nflag; 120static int tflag; 121static int32_t thiszone; /* time difference with gmt */ 122static int s = -1; 123static int repeat = 0; 124 125static char host_buf[NI_MAXHOST]; /* getnameinfo() */ --- 399 unchanged lines hidden (view full) --- 525 return 1; 526 } 527 528delete: 529 if (sdl->sdl_family != AF_LINK) { 530 printf("cannot locate %s\n", host); 531 return (1); 532 } |
532 /* 533 * need to reinit the field because it has rt_key 534 * but we want the actual address 535 */ | 533 /* 534 * need to reinit the field because it has rt_key 535 * but we want the actual address 536 */ |
536 NEXTADDR(RTA_DST, sin_m); 537 rtm->rtm_flags |= RTF_LLDATA; 538 if (rtmsg(RTM_DELETE) == 0) { 539 getnameinfo((struct sockaddr *)sin, 540 sin->sin6_len, host_buf, 541 sizeof(host_buf), NULL, 0, 542 (nflag ? NI_NUMERICHOST : 0)); 543 printf("%s (%s) deleted\n", host, host_buf); --- 55 unchanged lines hidden (view full) --- 599 } else 600 buf = lim = NULL; 601 602 for (next = buf; next && next < lim; next += rtm->rtm_msglen) { 603 int isrouter = 0, prbs = 0; 604 605 rtm = (struct rt_msghdr *)next; 606 sin = (struct sockaddr_in6 *)(rtm + 1); | 537 NEXTADDR(RTA_DST, sin_m); 538 rtm->rtm_flags |= RTF_LLDATA; 539 if (rtmsg(RTM_DELETE) == 0) { 540 getnameinfo((struct sockaddr *)sin, 541 sin->sin6_len, host_buf, 542 sizeof(host_buf), NULL, 0, 543 (nflag ? NI_NUMERICHOST : 0)); 544 printf("%s (%s) deleted\n", host, host_buf); --- 55 unchanged lines hidden (view full) --- 600 } else 601 buf = lim = NULL; 602 603 for (next = buf; next && next < lim; next += rtm->rtm_msglen) { 604 int isrouter = 0, prbs = 0; 605 606 rtm = (struct rt_msghdr *)next; 607 sin = (struct sockaddr_in6 *)(rtm + 1); |
607 sdl = (struct sockaddr_dl *)((char *)sin + ALIGN(sin->sin6_len)); | 608 sdl = (struct sockaddr_dl *)((char *)sin + 609 ALIGN(sin->sin6_len)); |
608 609 /* 610 * Some OSes can produce a route that has the LINK flag but 611 * has a non-AF_LINK gateway (e.g. fe80::xx%lo0 on FreeBSD 612 * and BSD/OS, where xx is not the interface identifier on 613 * lo0). Such routes entry would annoy getnbrinfo() below, 614 * so we skip them. 615 * XXX: such routes should have the GATEWAY flag, not the --- 103 unchanged lines hidden (view full) --- 719 /* 720 * other flags. R: router, P: proxy, W: ?? 721 */ 722 if ((rtm->rtm_addrs & RTA_NETMASK) == 0) { 723 snprintf(flgbuf, sizeof(flgbuf), "%s%s", 724 isrouter ? "R" : "", 725 (rtm->rtm_flags & RTF_ANNOUNCE) ? "p" : ""); 726 } else { | 610 611 /* 612 * Some OSes can produce a route that has the LINK flag but 613 * has a non-AF_LINK gateway (e.g. fe80::xx%lo0 on FreeBSD 614 * and BSD/OS, where xx is not the interface identifier on 615 * lo0). Such routes entry would annoy getnbrinfo() below, 616 * so we skip them. 617 * XXX: such routes should have the GATEWAY flag, not the --- 103 unchanged lines hidden (view full) --- 721 /* 722 * other flags. R: router, P: proxy, W: ?? 723 */ 724 if ((rtm->rtm_addrs & RTA_NETMASK) == 0) { 725 snprintf(flgbuf, sizeof(flgbuf), "%s%s", 726 isrouter ? "R" : "", 727 (rtm->rtm_flags & RTF_ANNOUNCE) ? "p" : ""); 728 } else { |
727#if 0 /* W and P are mystery even for us */ | 729#if 0 /* W and P are mystery even for us */ |
728 sin = (struct sockaddr_in6 *) 729 (sdl->sdl_len + (char *)sdl); 730 snprintf(flgbuf, sizeof(flgbuf), "%s%s%s%s", 731 isrouter ? "R" : "", 732 !IN6_IS_ADDR_UNSPECIFIED(&sin->sin6_addr) ? "P" : "", 733 (sin->sin6_len != sizeof(struct sockaddr_in6)) ? "W" : "", 734 (rtm->rtm_flags & RTF_ANNOUNCE) ? "p" : ""); 735#else --- 114 unchanged lines hidden (view full) --- 850 exit(1); 851 case RTM_ADD: 852 rtm->rtm_addrs |= RTA_GATEWAY; 853 if (expire_time) { 854 rtm->rtm_rmx.rmx_expire = expire_time; 855 rtm->rtm_inits = RTV_EXPIRE; 856 } 857 rtm->rtm_flags |= (RTF_HOST | RTF_STATIC | RTF_LLDATA); | 730 sin = (struct sockaddr_in6 *) 731 (sdl->sdl_len + (char *)sdl); 732 snprintf(flgbuf, sizeof(flgbuf), "%s%s%s%s", 733 isrouter ? "R" : "", 734 !IN6_IS_ADDR_UNSPECIFIED(&sin->sin6_addr) ? "P" : "", 735 (sin->sin6_len != sizeof(struct sockaddr_in6)) ? "W" : "", 736 (rtm->rtm_flags & RTF_ANNOUNCE) ? "p" : ""); 737#else --- 114 unchanged lines hidden (view full) --- 852 exit(1); 853 case RTM_ADD: 854 rtm->rtm_addrs |= RTA_GATEWAY; 855 if (expire_time) { 856 rtm->rtm_rmx.rmx_expire = expire_time; 857 rtm->rtm_inits = RTV_EXPIRE; 858 } 859 rtm->rtm_flags |= (RTF_HOST | RTF_STATIC | RTF_LLDATA); |
858#if 0 /* we don't support ipv6addr/128 type proxying */ | 860#if 0 /* we don't support ipv6addr/128 type proxying */ |
859 if (rtm->rtm_flags & RTF_ANNOUNCE) { 860 rtm->rtm_flags &= ~RTF_HOST; 861 rtm->rtm_addrs |= RTA_NETMASK; 862 } 863#endif 864 /* FALLTHROUGH */ 865 case RTM_GET: 866 rtm->rtm_addrs |= RTA_DST; 867 } 868 869 NEXTADDR(RTA_DST, sin_m); 870 NEXTADDR(RTA_GATEWAY, sdl_m); | 861 if (rtm->rtm_flags & RTF_ANNOUNCE) { 862 rtm->rtm_flags &= ~RTF_HOST; 863 rtm->rtm_addrs |= RTA_NETMASK; 864 } 865#endif 866 /* FALLTHROUGH */ 867 case RTM_GET: 868 rtm->rtm_addrs |= RTA_DST; 869 } 870 871 NEXTADDR(RTA_DST, sin_m); 872 NEXTADDR(RTA_GATEWAY, sdl_m); |
871#if 0 /* we don't support ipv6addr/128 type proxying */ | 873#if 0 /* we don't support ipv6addr/128 type proxying */ |
872 memset(&so_mask.sin6_addr, 0xff, sizeof(so_mask.sin6_addr)); 873 NEXTADDR(RTA_NETMASK, so_mask); 874#endif 875 876 rtm->rtm_msglen = cp - (char *)&m_rtmsg; 877doit: 878 l = rtm->rtm_msglen; 879 rtm->rtm_seq = ++seq; --- 28 unchanged lines hidden (view full) --- 908 /* NOTREACHED */ 909 } 910 bzero(&nd, sizeof(nd)); 911 strlcpy(nd.ifname, ifname, sizeof(nd.ifname)); 912 if (ioctl(s, SIOCGIFINFO_IN6, (caddr_t)&nd) < 0) { 913 err(1, "ioctl(SIOCGIFINFO_IN6)"); 914 /* NOTREACHED */ 915 } | 874 memset(&so_mask.sin6_addr, 0xff, sizeof(so_mask.sin6_addr)); 875 NEXTADDR(RTA_NETMASK, so_mask); 876#endif 877 878 rtm->rtm_msglen = cp - (char *)&m_rtmsg; 879doit: 880 l = rtm->rtm_msglen; 881 rtm->rtm_seq = ++seq; --- 28 unchanged lines hidden (view full) --- 910 /* NOTREACHED */ 911 } 912 bzero(&nd, sizeof(nd)); 913 strlcpy(nd.ifname, ifname, sizeof(nd.ifname)); 914 if (ioctl(s, SIOCGIFINFO_IN6, (caddr_t)&nd) < 0) { 915 err(1, "ioctl(SIOCGIFINFO_IN6)"); 916 /* NOTREACHED */ 917 } |
916#define ND nd.ndi | 918#define ND nd.ndi |
917 newflags = ND.flags; 918 for (i = 0; i < argc; i++) { 919 int clear = 0; 920 char *cp = argv[i]; 921 922 if (*cp == '-') { 923 clear = 1; 924 cp++; 925 } 926 | 919 newflags = ND.flags; 920 for (i = 0; i < argc; i++) { 921 int clear = 0; 922 char *cp = argv[i]; 923 924 if (*cp == '-') { 925 clear = 1; 926 cp++; 927 } 928 |
927#define SETFLAG(s, f) \ 928 do {\ 929 if (strcmp(cp, (s)) == 0) {\ 930 if (clear)\ 931 newflags &= ~(f);\ 932 else\ 933 newflags |= (f);\ 934 }\ 935 } while (0) | 929#define SETFLAG(s, f) do { \ 930 if (strcmp(cp, (s)) == 0) { \ 931 if (clear) \ 932 newflags &= ~(f); \ 933 else \ 934 newflags |= (f); \ 935 } \ 936} while (0) |
936/* 937 * XXX: this macro is not 100% correct, in that it matches "nud" against 938 * "nudbogus". But we just let it go since this is minor. 939 */ | 937/* 938 * XXX: this macro is not 100% correct, in that it matches "nud" against 939 * "nudbogus". But we just let it go since this is minor. 940 */ |
940#define SETVALUE(f, v) \ 941 do { \ 942 char *valptr; \ 943 unsigned long newval; \ 944 v = 0; /* unspecified */ \ 945 if (strncmp(cp, f, strlen(f)) == 0) { \ 946 valptr = strchr(cp, '='); \ 947 if (valptr == NULL) \ 948 err(1, "syntax error in %s field", (f)); \ 949 errno = 0; \ 950 newval = strtoul(++valptr, NULL, 0); \ 951 if (errno) \ 952 err(1, "syntax error in %s's value", (f)); \ 953 v = newval; \ 954 } \ 955 } while (0) | 941#define SETVALUE(f, v) do { \ 942 char *valptr; \ 943 unsigned long newval; \ 944 v = 0; /* unspecified */ \ 945 if (strncmp(cp, f, strlen(f)) == 0) { \ 946 valptr = strchr(cp, '='); \ 947 if (valptr == NULL) \ 948 err(1, "syntax error in %s field", (f)); \ 949 errno = 0; \ 950 newval = strtoul(++valptr, NULL, 0); \ 951 if (errno) \ 952 err(1, "syntax error in %s's value", (f)); \ 953 v = newval; \ 954 } \ 955} while (0) |
956 957 SETFLAG("disabled", ND6_IFF_IFDISABLED); 958 SETFLAG("nud", ND6_IFF_PERFORMNUD); 959#ifdef ND6_IFF_ACCEPT_RTADV 960 SETFLAG("accept_rtadv", ND6_IFF_ACCEPT_RTADV); 961#endif 962#ifdef ND6_IFF_AUTO_LINKLOCAL 963 SETFLAG("auto_linklocal", ND6_IFF_AUTO_LINKLOCAL); --- 52 unchanged lines hidden (view full) --- 1016 break; 1017 default: 1018 errx(1, "impossible case for tempaddr display"); 1019 } 1020 for (j = 0; j < 8; j++) 1021 printf("%02x", rbuf[j]); 1022 } 1023 } | 956 957 SETFLAG("disabled", ND6_IFF_IFDISABLED); 958 SETFLAG("nud", ND6_IFF_PERFORMNUD); 959#ifdef ND6_IFF_ACCEPT_RTADV 960 SETFLAG("accept_rtadv", ND6_IFF_ACCEPT_RTADV); 961#endif 962#ifdef ND6_IFF_AUTO_LINKLOCAL 963 SETFLAG("auto_linklocal", ND6_IFF_AUTO_LINKLOCAL); --- 52 unchanged lines hidden (view full) --- 1016 break; 1017 default: 1018 errx(1, "impossible case for tempaddr display"); 1019 } 1020 for (j = 0; j < 8; j++) 1021 printf("%02x", rbuf[j]); 1022 } 1023 } |
1024#endif | 1024#endif /* IPV6CTL_USETEMPADDR */ |
1025 if (ND.flags) { 1026 printf("\nFlags: "); 1027#ifdef ND6_IFF_IFDISABLED 1028 if ((ND.flags & ND6_IFF_IFDISABLED)) 1029 printf("disabled "); 1030#endif 1031 if ((ND.flags & ND6_IFF_PERFORMNUD)) 1032 printf("nud "); --- 276 unchanged lines hidden (view full) --- 1309 if ((if_indextoname(ndifreq.ifindex, ifname)) == NULL) 1310 err(1, "failed to resolve ifname for index %lu", 1311 ndifreq.ifindex); 1312 printf("ND default interface = %s\n", ifname); 1313 } 1314 1315 close(s); 1316} | 1025 if (ND.flags) { 1026 printf("\nFlags: "); 1027#ifdef ND6_IFF_IFDISABLED 1028 if ((ND.flags & ND6_IFF_IFDISABLED)) 1029 printf("disabled "); 1030#endif 1031 if ((ND.flags & ND6_IFF_PERFORMNUD)) 1032 printf("nud "); --- 276 unchanged lines hidden (view full) --- 1309 if ((if_indextoname(ndifreq.ifindex, ifname)) == NULL) 1310 err(1, "failed to resolve ifname for index %lu", 1311 ndifreq.ifindex); 1312 printf("ND default interface = %s\n", ifname); 1313 } 1314 1315 close(s); 1316} |
1317#endif | 1317#endif /* SIOCSDEFIFACE_IN6 */ |
1318 1319static char * 1320sec2str(time_t total) 1321{ 1322 static char result[256]; 1323 int days, hours, mins, secs; 1324 int first = 1; 1325 char *p = result; --- 50 unchanged lines hidden --- | 1318 1319static char * 1320sec2str(time_t total) 1321{ 1322 static char result[256]; 1323 int days, hours, mins, secs; 1324 int first = 1; 1325 char *p = result; --- 50 unchanged lines hidden --- |