ndp.c (121471) | ndp.c (122615) |
---|---|
1/* $FreeBSD: head/usr.sbin/ndp/ndp.c 121471 2003-10-24 18:00:17Z ume $ */ 2/* $KAME: ndp.c,v 1.65 2001/05/08 04:36:34 itojun Exp $ */ | 1/* $FreeBSD: head/usr.sbin/ndp/ndp.c 122615 2003-11-13 16:02:44Z ume $ */ 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 10 * are met: --- 95 unchanged lines hidden (view full) --- 106#include <nlist.h> 107#include <stdio.h> 108#include <string.h> 109#include <paths.h> 110#include <err.h> 111#include <stdlib.h> 112#include <fcntl.h> 113#include <unistd.h> | 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 10 * are met: --- 95 unchanged lines hidden (view full) --- 106#include <nlist.h> 107#include <stdio.h> 108#include <string.h> 109#include <paths.h> 110#include <err.h> 111#include <stdlib.h> 112#include <fcntl.h> 113#include <unistd.h> |
114#include <err.h> |
|
114#include "gmt2local.h" 115 116/* packing rule for routing socket */ 117#define ROUNDUP(a) \ 118 ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long)) 119#define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len)) 120 121static pid_t pid; | 115#include "gmt2local.h" 116 117/* packing rule for routing socket */ 118#define ROUNDUP(a) \ 119 ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long)) 120#define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len)) 121 122static pid_t pid; |
122static int cflag; | |
123static int nflag; 124static int tflag; 125static int32_t thiszone; /* time difference with gmt */ 126static int s = -1; 127static int repeat = 0; 128 129char ntop_buf[INET6_ADDRSTRLEN]; /* inet_ntop() */ 130char host_buf[NI_MAXHOST]; /* getnameinfo() */ 131char ifix_buf[IFNAMSIZ]; /* if_indextoname() */ 132 133int main __P((int, char **)); 134int file __P((char *)); 135void getsocket __P((void)); 136int set __P((int, char **)); 137void get __P((char *)); 138int delete __P((char *)); | 123static int nflag; 124static int tflag; 125static int32_t thiszone; /* time difference with gmt */ 126static int s = -1; 127static int repeat = 0; 128 129char ntop_buf[INET6_ADDRSTRLEN]; /* inet_ntop() */ 130char host_buf[NI_MAXHOST]; /* getnameinfo() */ 131char ifix_buf[IFNAMSIZ]; /* if_indextoname() */ 132 133int main __P((int, char **)); 134int file __P((char *)); 135void getsocket __P((void)); 136int set __P((int, char **)); 137void get __P((char *)); 138int delete __P((char *)); |
139void dump __P((struct in6_addr *)); 140static struct in6_nbrinfo *getnbrinfo __P((struct in6_addr *addr, 141 int ifindex, int)); | 139void dump __P((struct in6_addr *, int)); 140static struct in6_nbrinfo *getnbrinfo __P((struct in6_addr *, int, int)); |
142static char *ether_str __P((struct sockaddr_dl *)); 143int ndp_ether_aton __P((char *, u_char *)); 144void usage __P((void)); 145int rtmsg __P((int)); | 141static char *ether_str __P((struct sockaddr_dl *)); 142int ndp_ether_aton __P((char *, u_char *)); 143void usage __P((void)); 144int rtmsg __P((int)); |
146void ifinfo __P((int, char **)); | 145void ifinfo __P((char *, int, char **)); |
147void rtrlist __P((void)); 148void plist __P((void)); 149void pfx_flush __P((void)); 150void rtrlist __P((void)); 151void rtr_flush __P((void)); 152void harmonize_rtr __P((void)); 153#ifdef SIOCSDEFIFACE_IN6 /* XXX: check SIOCGDEFIFACE_IN6 as well? */ 154static void getdefif __P((void)); 155static void setdefif __P((char *)); 156#endif | 146void rtrlist __P((void)); 147void plist __P((void)); 148void pfx_flush __P((void)); 149void rtrlist __P((void)); 150void rtr_flush __P((void)); 151void harmonize_rtr __P((void)); 152#ifdef SIOCSDEFIFACE_IN6 /* XXX: check SIOCGDEFIFACE_IN6 as well? */ 153static void getdefif __P((void)); 154static void setdefif __P((char *)); 155#endif |
157static char *sec2str __P((time_t t)); 158static char *ether_str __P((struct sockaddr_dl *sdl)); | 156static char *sec2str __P((time_t)); 157static char *ether_str __P((struct sockaddr_dl *)); |
159static void ts_print __P((const struct timeval *)); 160 | 158static void ts_print __P((const struct timeval *)); 159 |
160#ifdef ICMPV6CTL_ND6_DRLIST |
|
161static char *rtpref_str[] = { 162 "medium", /* 00 */ 163 "high", /* 01 */ 164 "rsv", /* 10 */ 165 "low" /* 11 */ 166}; | 161static char *rtpref_str[] = { 162 "medium", /* 00 */ 163 "high", /* 01 */ 164 "rsv", /* 10 */ 165 "low" /* 11 */ 166}; |
167#endif |
|
167 | 168 |
169int mode = 0; 170char *arg = NULL; 171 |
|
168int 169main(argc, argv) 170 int argc; 171 char **argv; 172{ 173 int ch; | 172int 173main(argc, argv) 174 int argc; 175 char **argv; 176{ 177 int ch; |
174 int aflag = 0, dflag = 0, sflag = 0, Hflag = 0, 175 pflag = 0, rflag = 0, Pflag = 0, Rflag = 0; | |
176 177 pid = getpid(); 178 thiszone = gmt2local(0); | 178 179 pid = getpid(); 180 thiszone = gmt2local(0); |
179 while ((ch = getopt(argc, argv, "acndfIilprstA:HPR")) != -1) | 181 while ((ch = getopt(argc, argv, "acd:f:Ii:nprstA:HPR")) != -1) |
180 switch (ch) { 181 case 'a': | 182 switch (ch) { 183 case 'a': |
182 aflag = 1; 183 break; | |
184 case 'c': | 184 case 'c': |
185 cflag = 1; | 185 case 'p': 186 case 'r': 187 case 'H': 188 case 'P': 189 case 'R': 190 case 's': 191 case 'I': 192 if (mode) { 193 usage(); 194 /*NOTREACHED*/ 195 } 196 mode = ch; 197 arg = NULL; |
186 break; 187 case 'd': | 198 break; 199 case 'd': |
188 dflag = 1; 189 break; 190 case 'I': 191#ifdef SIOCSDEFIFACE_IN6 /* XXX: check SIOCGDEFIFACE_IN6 as well? */ 192 if (argc > 2) 193 setdefif(argv[2]); 194 getdefif(); /* always call it to print the result */ 195 exit(0); 196#else 197 errx(1, "not supported yet"); 198 /*NOTREACHED*/ 199#endif | 200 case 'f': |
200 case 'i' : | 201 case 'i' : |
201 argc -= optind; 202 argv += optind; 203 if (argc < 1) | 202 if (mode) { |
204 usage(); | 203 usage(); |
205 ifinfo(argc, argv); 206 exit(0); | 204 /*NOTREACHED*/ 205 } 206 mode = ch; 207 arg = optarg; 208 break; |
207 case 'n': 208 nflag = 1; | 209 case 'n': 210 nflag = 1; |
209 continue; 210 case 'p': 211 pflag = 1; | |
212 break; | 211 break; |
213 case 'f' : 214 if (argc != 3) 215 usage(); 216 file(argv[2]); 217 exit(0); 218 case 'l' : 219 /* obsolete, ignored */ 220 break; 221 case 'r' : 222 rflag = 1; 223 break; 224 case 's': 225 sflag = 1; 226 break; | |
227 case 't': 228 tflag = 1; 229 break; 230 case 'A': | 212 case 't': 213 tflag = 1; 214 break; 215 case 'A': |
231 aflag = 1; | 216 if (mode) { 217 usage(); 218 /*NOTREACHED*/ 219 } 220 mode = 'a'; |
232 repeat = atoi(optarg); | 221 repeat = atoi(optarg); |
233 if (repeat < 0) | 222 if (repeat < 0) { |
234 usage(); | 223 usage(); |
224 /*NOTREACHED*/ 225 } |
|
235 break; | 226 break; |
236 case 'H' : 237 Hflag = 1; 238 break; 239 case 'P': 240 Pflag = 1; 241 break; 242 case 'R': 243 Rflag = 1; 244 break; | |
245 default: 246 usage(); 247 } 248 249 argc -= optind; 250 argv += optind; 251 | 227 default: 228 usage(); 229 } 230 231 argc -= optind; 232 argv += optind; 233 |
252 if (aflag || cflag) { 253 dump(0); 254 exit(0); 255 } 256 if (dflag) { 257 if (argc != 1) | 234 switch (mode) { 235 case 'a': 236 case 'c': 237 if (argc != 0) { |
258 usage(); | 238 usage(); |
259 delete(argv[0]); 260 exit(0); 261 } 262 if (pflag) { | 239 /*NOTREACHED*/ 240 } 241 dump(0, mode == 'c'); 242 break; 243 case 'd': 244 if (argc != 0) { 245 usage(); 246 /*NOTREACHED*/ 247 } 248 delete(arg); 249 break; 250 case 'I': 251#ifdef SIOCSDEFIFACE_IN6 /* XXX: check SIOCGDEFIFACE_IN6 as well? */ 252 if (argc > 1) { 253 usage(); 254 /*NOTREACHED*/ 255 } else if (argc == 1) { 256 if (strcmp(*argv, "delete") == 0 || 257 if_nametoindex(*argv)) 258 setdefif(*argv); 259 else 260 errx(1, "invalid interface %s", *argv); 261 } 262 getdefif(); /* always call it to print the result */ 263 break; 264#else 265 errx(1, "not supported yet"); 266 /*NOTREACHED*/ 267#endif 268 case 'p': 269 if (argc != 0) { 270 usage(); 271 /*NOTREACHED*/ 272 } |
263 plist(); | 273 plist(); |
264 exit(0); 265 } 266 if (rflag) { | 274 break; 275 case 'i': 276 ifinfo(arg, argc, argv); 277 break; 278 case 'r': 279 if (argc != 0) { 280 usage(); 281 /*NOTREACHED*/ 282 } |
267 rtrlist(); | 283 rtrlist(); |
268 exit(0); 269 } 270 if (sflag) { | 284 break; 285 case 's': |
271 if (argc < 2 || argc > 4) 272 usage(); 273 exit(set(argc, argv) ? 1 : 0); | 286 if (argc < 2 || argc > 4) 287 usage(); 288 exit(set(argc, argv) ? 1 : 0); |
274 } 275 if (Hflag) { | 289 case 'H': 290 if (argc != 0) { 291 usage(); 292 /*NOTREACHED*/ 293 } |
276 harmonize_rtr(); | 294 harmonize_rtr(); |
277 exit(0); 278 } 279 if (Pflag) { | 295 break; 296 case 'P': 297 if (argc != 0) { 298 usage(); 299 /*NOTREACHED*/ 300 } |
280 pfx_flush(); | 301 pfx_flush(); |
281 exit(0); 282 } 283 if (Rflag) { | 302 break; 303 case 'R': 304 if (argc != 0) { 305 usage(); 306 /*NOTREACHED*/ 307 } |
284 rtr_flush(); | 308 rtr_flush(); |
285 exit(0); | 309 break; 310 case 0: 311 if (argc != 1) { 312 usage(); 313 /*NOTREACHED*/ 314 } 315 get(argv[0]); 316 break; |
286 } | 317 } |
287 288 if (argc != 1) 289 usage(); 290 get(argv[0]); | |
291 exit(0); 292} 293 294/* 295 * Process a file to set standard ndp entries 296 */ 297int 298file(name) --- 9 unchanged lines hidden (view full) --- 308 } 309 args[0] = &arg[0][0]; 310 args[1] = &arg[1][0]; 311 args[2] = &arg[2][0]; 312 args[3] = &arg[3][0]; 313 args[4] = &arg[4][0]; 314 retval = 0; 315 while (fgets(line, 100, fp) != NULL) { | 318 exit(0); 319} 320 321/* 322 * Process a file to set standard ndp entries 323 */ 324int 325file(name) --- 9 unchanged lines hidden (view full) --- 335 } 336 args[0] = &arg[0][0]; 337 args[1] = &arg[1][0]; 338 args[2] = &arg[2][0]; 339 args[3] = &arg[3][0]; 340 args[4] = &arg[4][0]; 341 retval = 0; 342 while (fgets(line, 100, fp) != NULL) { |
316 i = sscanf(line, "%s %s %s %s %s", arg[0], arg[1], arg[2], 317 arg[3], arg[4]); | 343 i = sscanf(line, "%49s %49s %49s %49s %49s", 344 arg[0], arg[1], arg[2], arg[3], arg[4]); |
318 if (i < 2) { 319 fprintf(stderr, "ndp: bad line: %s\n", line); 320 retval = 1; 321 continue; 322 } 323 if (set(i, args)) 324 retval = 1; 325 } --- 77 unchanged lines hidden (view full) --- 403 errx(1, "RTM_GET(%s) failed", host); 404 /* NOTREACHED */ 405 } 406 sin = (struct sockaddr_in6 *)(rtm + 1); 407 sdl = (struct sockaddr_dl *)(ROUNDUP(sin->sin6_len) + (char *)sin); 408 if (IN6_ARE_ADDR_EQUAL(&sin->sin6_addr, &sin_m.sin6_addr)) { 409 if (sdl->sdl_family == AF_LINK && 410 (rtm->rtm_flags & RTF_LLINFO) && | 345 if (i < 2) { 346 fprintf(stderr, "ndp: bad line: %s\n", line); 347 retval = 1; 348 continue; 349 } 350 if (set(i, args)) 351 retval = 1; 352 } --- 77 unchanged lines hidden (view full) --- 430 errx(1, "RTM_GET(%s) failed", host); 431 /* NOTREACHED */ 432 } 433 sin = (struct sockaddr_in6 *)(rtm + 1); 434 sdl = (struct sockaddr_dl *)(ROUNDUP(sin->sin6_len) + (char *)sin); 435 if (IN6_ARE_ADDR_EQUAL(&sin->sin6_addr, &sin_m.sin6_addr)) { 436 if (sdl->sdl_family == AF_LINK && 437 (rtm->rtm_flags & RTF_LLINFO) && |
411 !(rtm->rtm_flags & RTF_GATEWAY)) switch (sdl->sdl_type) { 412 case IFT_ETHER: case IFT_FDDI: case IFT_ISO88023: 413 case IFT_ISO88024: case IFT_ISO88025: 414 goto overwrite; | 438 !(rtm->rtm_flags & RTF_GATEWAY)) { 439 switch (sdl->sdl_type) { 440 case IFT_ETHER: case IFT_FDDI: case IFT_ISO88023: 441 case IFT_ISO88024: case IFT_ISO88025: 442 goto overwrite; 443 } |
415 } 416 /* 417 * IPv4 arp command retries with sin_other = SIN_PROXY here. 418 */ 419 fprintf(stderr, "set: cannot configure a new entry\n"); 420 return 1; 421 } 422 --- 29 unchanged lines hidden (view full) --- 452 } 453 sin->sin6_addr = ((struct sockaddr_in6 *)res->ai_addr)->sin6_addr; 454#ifdef __KAME__ 455 if (IN6_IS_ADDR_LINKLOCAL(&sin->sin6_addr)) { 456 *(u_int16_t *)&sin->sin6_addr.s6_addr[2] = 457 htons(((struct sockaddr_in6 *)res->ai_addr)->sin6_scope_id); 458 } 459#endif | 444 } 445 /* 446 * IPv4 arp command retries with sin_other = SIN_PROXY here. 447 */ 448 fprintf(stderr, "set: cannot configure a new entry\n"); 449 return 1; 450 } 451 --- 29 unchanged lines hidden (view full) --- 481 } 482 sin->sin6_addr = ((struct sockaddr_in6 *)res->ai_addr)->sin6_addr; 483#ifdef __KAME__ 484 if (IN6_IS_ADDR_LINKLOCAL(&sin->sin6_addr)) { 485 *(u_int16_t *)&sin->sin6_addr.s6_addr[2] = 486 htons(((struct sockaddr_in6 *)res->ai_addr)->sin6_scope_id); 487 } 488#endif |
460 dump(&sin->sin6_addr); | 489 dump(&sin->sin6_addr, 0); |
461 if (found_entry == 0) { 462 getnameinfo((struct sockaddr *)sin, sin->sin6_len, host_buf, 463 sizeof(host_buf), NULL ,0, 464 (nflag ? NI_NUMERICHOST : 0)); 465 printf("%s (%s) -- no entry\n", host, host_buf); 466 exit(1); 467 } 468} --- 67 unchanged lines hidden (view full) --- 536 sizeof(host_buf), NULL, 0, 537 (nflag ? NI_NUMERICHOST : 0)); 538 printf("%s (%s) deleted\n", host, host_buf); 539 } 540 541 return 0; 542} 543 | 490 if (found_entry == 0) { 491 getnameinfo((struct sockaddr *)sin, sin->sin6_len, host_buf, 492 sizeof(host_buf), NULL ,0, 493 (nflag ? NI_NUMERICHOST : 0)); 494 printf("%s (%s) -- no entry\n", host, host_buf); 495 exit(1); 496 } 497} --- 67 unchanged lines hidden (view full) --- 565 sizeof(host_buf), NULL, 0, 566 (nflag ? NI_NUMERICHOST : 0)); 567 printf("%s (%s) deleted\n", host, host_buf); 568 } 569 570 return 0; 571} 572 |
544#define W_ADDR 31 | 573#define W_ADDR 36 |
545#define W_LL 17 546#define W_IF 6 547 548/* 549 * Dump the entire neighbor cache 550 */ 551void | 574#define W_LL 17 575#define W_IF 6 576 577/* 578 * Dump the entire neighbor cache 579 */ 580void |
552dump(addr) | 581dump(addr, cflag) |
553 struct in6_addr *addr; | 582 struct in6_addr *addr; |
583 int cflag; |
|
554{ 555 int mib[6]; 556 size_t needed; 557 char *lim, *buf, *next; 558 struct rt_msghdr *rtm; 559 struct sockaddr_in6 *sin; 560 struct sockaddr_dl *sdl; 561 extern int h_errno; 562 struct in6_nbrinfo *nbi; 563 struct timeval time; 564 int addrwidth; 565 int llwidth; 566 int ifwidth; 567 char flgbuf[8]; 568 char *ifname; 569 570 /* Print header */ 571 if (!tflag && !cflag) | 584{ 585 int mib[6]; 586 size_t needed; 587 char *lim, *buf, *next; 588 struct rt_msghdr *rtm; 589 struct sockaddr_in6 *sin; 590 struct sockaddr_dl *sdl; 591 extern int h_errno; 592 struct in6_nbrinfo *nbi; 593 struct timeval time; 594 int addrwidth; 595 int llwidth; 596 int ifwidth; 597 char flgbuf[8]; 598 char *ifname; 599 600 /* Print header */ 601 if (!tflag && !cflag) |
572 printf("%-*.*s %-*.*s %*.*s %-9.9s %2s %4s %4s\n", | 602 printf("%-*.*s %-*.*s %*.*s %-9.9s %1s %5s\n", |
573 W_ADDR, W_ADDR, "Neighbor", W_LL, W_LL, "Linklayer Address", | 603 W_ADDR, W_ADDR, "Neighbor", W_LL, W_LL, "Linklayer Address", |
574 W_IF, W_IF, "Netif", "Expire", "St", "Flgs", "Prbs"); | 604 W_IF, W_IF, "Netif", "Expire", "S", "Flags"); |
575 576again:; 577 mib[0] = CTL_NET; 578 mib[1] = PF_ROUTE; 579 mib[2] = 0; 580 mib[3] = AF_INET6; 581 mib[4] = NET_RT_FLAGS; 582 mib[5] = RTF_LLINFO; --- 26 unchanged lines hidden (view full) --- 609 * that advertises all routes that have the GATEWAY flag. 610 * Thus, KAME kernel intentionally does not set the LINK flag. 611 * What is to be fixed is not ndp, but such routing software 612 * (and the kernel workaround)... 613 */ 614 if (sdl->sdl_family != AF_LINK) 615 continue; 616 | 605 606again:; 607 mib[0] = CTL_NET; 608 mib[1] = PF_ROUTE; 609 mib[2] = 0; 610 mib[3] = AF_INET6; 611 mib[4] = NET_RT_FLAGS; 612 mib[5] = RTF_LLINFO; --- 26 unchanged lines hidden (view full) --- 639 * that advertises all routes that have the GATEWAY flag. 640 * Thus, KAME kernel intentionally does not set the LINK flag. 641 * What is to be fixed is not ndp, but such routing software 642 * (and the kernel workaround)... 643 */ 644 if (sdl->sdl_family != AF_LINK) 645 continue; 646 |
647 if (!(rtm->rtm_flags & RTF_HOST)) 648 continue; 649 |
|
617 if (addr) { 618 if (!IN6_ARE_ADDR_EQUAL(addr, &sin->sin6_addr)) 619 continue; 620 found_entry = 1; 621 } else if (IN6_IS_ADDR_MULTICAST(&sin->sin6_addr)) 622 continue; 623 if (IN6_IS_ADDR_LINKLOCAL(&sin->sin6_addr) || 624 IN6_IS_ADDR_MC_LINKLOCAL(&sin->sin6_addr)) { 625 /* XXX: should scope id be filled in the kernel? */ 626 if (sin->sin6_scope_id == 0) 627 sin->sin6_scope_id = sdl->sdl_index; 628#ifdef __KAME__ 629 /* KAME specific hack; removed the embedded id */ 630 *(u_int16_t *)&sin->sin6_addr.s6_addr[2] = 0; 631#endif 632 } 633 getnameinfo((struct sockaddr *)sin, sin->sin6_len, host_buf, 634 sizeof(host_buf), NULL, 0, (nflag ? NI_NUMERICHOST : 0)); | 650 if (addr) { 651 if (!IN6_ARE_ADDR_EQUAL(addr, &sin->sin6_addr)) 652 continue; 653 found_entry = 1; 654 } else if (IN6_IS_ADDR_MULTICAST(&sin->sin6_addr)) 655 continue; 656 if (IN6_IS_ADDR_LINKLOCAL(&sin->sin6_addr) || 657 IN6_IS_ADDR_MC_LINKLOCAL(&sin->sin6_addr)) { 658 /* XXX: should scope id be filled in the kernel? */ 659 if (sin->sin6_scope_id == 0) 660 sin->sin6_scope_id = sdl->sdl_index; 661#ifdef __KAME__ 662 /* KAME specific hack; removed the embedded id */ 663 *(u_int16_t *)&sin->sin6_addr.s6_addr[2] = 0; 664#endif 665 } 666 getnameinfo((struct sockaddr *)sin, sin->sin6_len, host_buf, 667 sizeof(host_buf), NULL, 0, (nflag ? NI_NUMERICHOST : 0)); |
635 if (cflag == 1) { | 668 if (cflag) { |
636#ifdef RTF_WASCLONED 637 if (rtm->rtm_flags & RTF_WASCLONED) 638 delete(host_buf); | 669#ifdef RTF_WASCLONED 670 if (rtm->rtm_flags & RTF_WASCLONED) 671 delete(host_buf); |
672#elif defined(RTF_CLONED) 673 if (rtm->rtm_flags & RTF_CLONED) 674 delete(host_buf); |
|
639#else 640 delete(host_buf); 641#endif 642 continue; 643 } 644 gettimeofday(&time, 0); 645 if (tflag) 646 ts_print(&time); --- 55 unchanged lines hidden (view full) --- 702 } 703 704 isrouter = nbi->isrouter; 705 prbs = nbi->asked; 706 } else { 707 warnx("failed to get neighbor information"); 708 printf(" "); 709 } | 675#else 676 delete(host_buf); 677#endif 678 continue; 679 } 680 gettimeofday(&time, 0); 681 if (tflag) 682 ts_print(&time); --- 55 unchanged lines hidden (view full) --- 738 } 739 740 isrouter = nbi->isrouter; 741 prbs = nbi->asked; 742 } else { 743 warnx("failed to get neighbor information"); 744 printf(" "); 745 } |
710 putchar(' '); | |
711 712 /* 713 * other flags. R: router, P: proxy, W: ?? 714 */ 715 if ((rtm->rtm_addrs & RTA_NETMASK) == 0) { 716 snprintf(flgbuf, sizeof(flgbuf), "%s%s", 717 isrouter ? "R" : "", 718 (rtm->rtm_flags & RTF_ANNOUNCE) ? "p" : ""); 719 } else { 720 sin = (struct sockaddr_in6 *) 721 (sdl->sdl_len + (char *)sdl); | 746 747 /* 748 * other flags. R: router, P: proxy, W: ?? 749 */ 750 if ((rtm->rtm_addrs & RTA_NETMASK) == 0) { 751 snprintf(flgbuf, sizeof(flgbuf), "%s%s", 752 isrouter ? "R" : "", 753 (rtm->rtm_flags & RTF_ANNOUNCE) ? "p" : ""); 754 } else { 755 sin = (struct sockaddr_in6 *) 756 (sdl->sdl_len + (char *)sdl); |
757#if 0 /* W and P are mystery even for us */ |
|
722 snprintf(flgbuf, sizeof(flgbuf), "%s%s%s%s", 723 isrouter ? "R" : "", 724 !IN6_IS_ADDR_UNSPECIFIED(&sin->sin6_addr) ? "P" : "", 725 (sin->sin6_len != sizeof(struct sockaddr_in6)) ? "W" : "", 726 (rtm->rtm_flags & RTF_ANNOUNCE) ? "p" : ""); | 758 snprintf(flgbuf, sizeof(flgbuf), "%s%s%s%s", 759 isrouter ? "R" : "", 760 !IN6_IS_ADDR_UNSPECIFIED(&sin->sin6_addr) ? "P" : "", 761 (sin->sin6_len != sizeof(struct sockaddr_in6)) ? "W" : "", 762 (rtm->rtm_flags & RTF_ANNOUNCE) ? "p" : ""); |
763#else 764 snprintf(flgbuf, sizeof(flgbuf), "%s%s", 765 isrouter ? "R" : "", 766 (rtm->rtm_flags & RTF_ANNOUNCE) ? "p" : ""); 767#endif |
|
727 } | 768 } |
728 printf(" %-4.4s", flgbuf); | 769 printf(" %s", flgbuf); |
729 730 if (prbs) | 770 771 if (prbs) |
731 printf(" %4d", prbs); | 772 printf(" %d", prbs); |
732 733 printf("\n"); 734 } 735 if (buf != NULL) 736 free(buf); 737 738 if (repeat) { 739 printf("\n"); --- 61 unchanged lines hidden (view full) --- 801 for (i = 0; i < 6; i++) 802 n[i] = o[i]; 803 return (0); 804} 805 806void 807usage() 808{ | 773 774 printf("\n"); 775 } 776 if (buf != NULL) 777 free(buf); 778 779 if (repeat) { 780 printf("\n"); --- 61 unchanged lines hidden (view full) --- 842 for (i = 0; i < 6; i++) 843 n[i] = o[i]; 844 return (0); 845} 846 847void 848usage() 849{ |
809 printf("usage: ndp hostname\n"); 810 printf(" ndp -a[nt]\n"); | 850 printf("usage: ndp [-nt] hostname\n"); 851 printf(" ndp [-nt] -a | -c | -p | -r | -H | -P | -R\n"); |
811 printf(" ndp [-nt] -A wait\n"); | 852 printf(" ndp [-nt] -A wait\n"); |
812 printf(" ndp -c[nt]\n"); 813 printf(" ndp -d[nt] hostname\n"); 814 printf(" ndp -f[nt] filename\n"); 815 printf(" ndp -i interface [flags...]\n"); | 853 printf(" ndp [-nt] -d hostname\n"); 854 printf(" ndp [-nt] -f filename\n"); 855 printf(" ndp [-nt] -i interface [flags...]\n"); |
816#ifdef SIOCSDEFIFACE_IN6 | 856#ifdef SIOCSDEFIFACE_IN6 |
817 printf(" ndp -I [interface|delete]\n"); | 857 printf(" ndp [-nt] -I [interface|delete]\n"); |
818#endif | 858#endif |
819 printf(" ndp -p\n"); 820 printf(" ndp -r\n"); 821 printf(" ndp -s hostname ether_addr [temp] [proxy]\n"); 822 printf(" ndp -H\n"); 823 printf(" ndp -P\n"); 824 printf(" ndp -R\n"); | 859 printf(" ndp [-nt] -s nodename etheraddr [temp] [proxy]\n"); |
825 exit(1); 826} 827 828int 829rtmsg(cmd) 830 int cmd; 831{ 832 static int seq; --- 10 unchanged lines hidden (view full) --- 843 rtm->rtm_version = RTM_VERSION; 844 845 switch (cmd) { 846 default: 847 fprintf(stderr, "ndp: internal wrong cmd\n"); 848 exit(1); 849 case RTM_ADD: 850 rtm->rtm_addrs |= RTA_GATEWAY; | 860 exit(1); 861} 862 863int 864rtmsg(cmd) 865 int cmd; 866{ 867 static int seq; --- 10 unchanged lines hidden (view full) --- 878 rtm->rtm_version = RTM_VERSION; 879 880 switch (cmd) { 881 default: 882 fprintf(stderr, "ndp: internal wrong cmd\n"); 883 exit(1); 884 case RTM_ADD: 885 rtm->rtm_addrs |= RTA_GATEWAY; |
851 rtm->rtm_rmx.rmx_expire = expire_time; 852 rtm->rtm_inits = RTV_EXPIRE; | 886 if (expire_time) { 887 rtm->rtm_rmx.rmx_expire = expire_time; 888 rtm->rtm_inits = RTV_EXPIRE; 889 } |
853 rtm->rtm_flags |= (RTF_HOST | RTF_STATIC); 854 if (rtm->rtm_flags & RTF_ANNOUNCE) { 855 rtm->rtm_flags &= ~RTF_HOST; 856 rtm->rtm_flags |= RTA_NETMASK; 857 } 858 /* FALLTHROUGH */ 859 case RTM_GET: 860 rtm->rtm_addrs |= RTA_DST; --- 23 unchanged lines hidden (view full) --- 884 } while (l > 0 && (rtm->rtm_seq != seq || rtm->rtm_pid != pid)); 885 if (l < 0) 886 (void) fprintf(stderr, "ndp: read from routing socket: %s\n", 887 strerror(errno)); 888 return (0); 889} 890 891void | 890 rtm->rtm_flags |= (RTF_HOST | RTF_STATIC); 891 if (rtm->rtm_flags & RTF_ANNOUNCE) { 892 rtm->rtm_flags &= ~RTF_HOST; 893 rtm->rtm_flags |= RTA_NETMASK; 894 } 895 /* FALLTHROUGH */ 896 case RTM_GET: 897 rtm->rtm_addrs |= RTA_DST; --- 23 unchanged lines hidden (view full) --- 921 } while (l > 0 && (rtm->rtm_seq != seq || rtm->rtm_pid != pid)); 922 if (l < 0) 923 (void) fprintf(stderr, "ndp: read from routing socket: %s\n", 924 strerror(errno)); 925 return (0); 926} 927 928void |
892ifinfo(argc, argv) | 929ifinfo(ifname, argc, argv) 930 char *ifname; |
893 int argc; 894 char **argv; 895{ 896 struct in6_ndireq nd; 897 int i, s; | 931 int argc; 932 char **argv; 933{ 934 struct in6_ndireq nd; 935 int i, s; |
898 char *ifname = argv[0]; | |
899 u_int32_t newflags; 900#ifdef IPV6CTL_USETEMPADDR 901 u_int8_t nullbuf[8]; 902#endif 903 904 if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) { 905 err(1, "socket"); 906 /* NOTREACHED */ 907 } 908 bzero(&nd, sizeof(nd)); 909 strlcpy(nd.ifname, ifname, sizeof(nd.ifname)); 910 if (ioctl(s, SIOCGIFINFO_IN6, (caddr_t)&nd) < 0) { 911 err(1, "ioctl(SIOCGIFINFO_IN6)"); 912 /* NOTREACHED */ | 936 u_int32_t newflags; 937#ifdef IPV6CTL_USETEMPADDR 938 u_int8_t nullbuf[8]; 939#endif 940 941 if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) { 942 err(1, "socket"); 943 /* NOTREACHED */ 944 } 945 bzero(&nd, sizeof(nd)); 946 strlcpy(nd.ifname, ifname, sizeof(nd.ifname)); 947 if (ioctl(s, SIOCGIFINFO_IN6, (caddr_t)&nd) < 0) { 948 err(1, "ioctl(SIOCGIFINFO_IN6)"); 949 /* NOTREACHED */ |
913 } | 950 } |
914#define ND nd.ndi 915 newflags = ND.flags; | 951#define ND nd.ndi 952 newflags = ND.flags; |
916 for (i = 1; i < argc; i++) { | 953 for (i = 0; i < argc; i++) { |
917 int clear = 0; 918 char *cp = argv[i]; 919 920 if (*cp == '-') { 921 clear = 1; 922 cp++; 923 } 924 --- 5 unchanged lines hidden (view full) --- 930 else\ 931 newflags |= (f);\ 932 }\ 933 } while (0) 934 SETFLAG("nud", ND6_IFF_PERFORMNUD); 935#ifdef ND6_IFF_ACCEPT_RTADV 936 SETFLAG("accept_rtadv", ND6_IFF_ACCEPT_RTADV); 937#endif | 954 int clear = 0; 955 char *cp = argv[i]; 956 957 if (*cp == '-') { 958 clear = 1; 959 cp++; 960 } 961 --- 5 unchanged lines hidden (view full) --- 967 else\ 968 newflags |= (f);\ 969 }\ 970 } while (0) 971 SETFLAG("nud", ND6_IFF_PERFORMNUD); 972#ifdef ND6_IFF_ACCEPT_RTADV 973 SETFLAG("accept_rtadv", ND6_IFF_ACCEPT_RTADV); 974#endif |
975#ifdef ND6_IFF_PREFER_SOURCE 976 SETFLAG("prefer_source", ND6_IFF_PREFER_SOURCE); 977#endif |
|
938 939 ND.flags = newflags; 940 if (ioctl(s, SIOCSIFINFO_FLAGS, (caddr_t)&nd) < 0) { 941 err(1, "ioctl(SIOCSIFINFO_FLAGS)"); 942 /* NOTREACHED */ 943 } 944#undef SETFLAG 945 } --- 39 unchanged lines hidden (view full) --- 985 if (ND.flags) { 986 printf("\nFlags: "); 987 if ((ND.flags & ND6_IFF_PERFORMNUD)) 988 printf("nud "); 989#ifdef ND6_IFF_ACCEPT_RTADV 990 if ((ND.flags & ND6_IFF_ACCEPT_RTADV)) 991 printf("accept_rtadv "); 992#endif | 978 979 ND.flags = newflags; 980 if (ioctl(s, SIOCSIFINFO_FLAGS, (caddr_t)&nd) < 0) { 981 err(1, "ioctl(SIOCSIFINFO_FLAGS)"); 982 /* NOTREACHED */ 983 } 984#undef SETFLAG 985 } --- 39 unchanged lines hidden (view full) --- 1025 if (ND.flags) { 1026 printf("\nFlags: "); 1027 if ((ND.flags & ND6_IFF_PERFORMNUD)) 1028 printf("nud "); 1029#ifdef ND6_IFF_ACCEPT_RTADV 1030 if ((ND.flags & ND6_IFF_ACCEPT_RTADV)) 1031 printf("accept_rtadv "); 1032#endif |
993} | 1033#ifdef ND6_IFF_PREFER_SOURCE 1034 if ((ND.flags & ND6_IFF_PREFER_SOURCE)) 1035 printf("prefer_source "); 1036#endif 1037 } |
994 putc('\n', stdout); 995#undef ND 996 997 close(s); 998} 999 1000#ifndef ND_RA_FLAG_RTPREF_MASK /* XXX: just for compilation on *BSD release */ 1001#define ND_RA_FLAG_RTPREF_MASK 0x18 /* 00011000 */ --- 146 unchanged lines hidden (view full) --- 1148 (p->flags & NDPRF_HOME) != 0 ? "H" : "" 1149#else 1150 "" 1151#endif 1152 ); 1153 if (p->vltime == ND6_INFINITE_LIFETIME) 1154 printf(" vltime=infinity"); 1155 else | 1038 putc('\n', stdout); 1039#undef ND 1040 1041 close(s); 1042} 1043 1044#ifndef ND_RA_FLAG_RTPREF_MASK /* XXX: just for compilation on *BSD release */ 1045#define ND_RA_FLAG_RTPREF_MASK 0x18 /* 00011000 */ --- 146 unchanged lines hidden (view full) --- 1192 (p->flags & NDPRF_HOME) != 0 ? "H" : "" 1193#else 1194 "" 1195#endif 1196 ); 1197 if (p->vltime == ND6_INFINITE_LIFETIME) 1198 printf(" vltime=infinity"); 1199 else |
1156 printf(" vltime=%ld", (long)p->vltime); | 1200 printf(" vltime=%lu", (unsigned long)p->vltime); |
1157 if (p->pltime == ND6_INFINITE_LIFETIME) 1158 printf(", pltime=infinity"); 1159 else | 1201 if (p->pltime == ND6_INFINITE_LIFETIME) 1202 printf(", pltime=infinity"); 1203 else |
1160 printf(", pltime=%ld", (long)p->pltime); | 1204 printf(", pltime=%lu", (unsigned long)p->pltime); |
1161 if (p->expire == 0) 1162 printf(", expire=Never"); 1163 else if (p->expire >= time.tv_sec) 1164 printf(", expire=%s", 1165 sec2str(p->expire - time.tv_sec)); 1166 else 1167 printf(", expired"); 1168 printf(", ref=%d", p->refcnt); 1169 printf("\n"); 1170 /* 1171 * "advertising router" list is meaningful only if the prefix 1172 * information is from RA. 1173 */ 1174 if (p->advrtrs) { 1175 int j; 1176 struct sockaddr_in6 *sin6; 1177 | 1205 if (p->expire == 0) 1206 printf(", expire=Never"); 1207 else if (p->expire >= time.tv_sec) 1208 printf(", expire=%s", 1209 sec2str(p->expire - time.tv_sec)); 1210 else 1211 printf(", expired"); 1212 printf(", ref=%d", p->refcnt); 1213 printf("\n"); 1214 /* 1215 * "advertising router" list is meaningful only if the prefix 1216 * information is from RA. 1217 */ 1218 if (p->advrtrs) { 1219 int j; 1220 struct sockaddr_in6 *sin6; 1221 |
1178 sin6 = (struct sockaddr_in6 *)(p + 1); | 1222 sin6 = advrtr; |
1179 printf(" advertised by\n"); 1180 for (j = 0; j < p->advrtrs; j++) { 1181 struct in6_nbrinfo *nbi; 1182 1183 if (getnameinfo((struct sockaddr *)sin6, 1184 sin6->sin6_len, namebuf, sizeof(namebuf), 1185 NULL, 0, ninflags) != 0) 1186 strlcpy(namebuf, "?", sizeof(namebuf)); --- 101 unchanged lines hidden (view full) --- 1288#else 1289 printf("flags=%s%s", 1290 PR.raflags.onlink ? "L" : "", 1291 PR.raflags.autonomous ? "A" : ""); 1292#endif 1293 if (PR.vltime == ND6_INFINITE_LIFETIME) 1294 printf(" vltime=infinity"); 1295 else | 1223 printf(" advertised by\n"); 1224 for (j = 0; j < p->advrtrs; j++) { 1225 struct in6_nbrinfo *nbi; 1226 1227 if (getnameinfo((struct sockaddr *)sin6, 1228 sin6->sin6_len, namebuf, sizeof(namebuf), 1229 NULL, 0, ninflags) != 0) 1230 strlcpy(namebuf, "?", sizeof(namebuf)); --- 101 unchanged lines hidden (view full) --- 1332#else 1333 printf("flags=%s%s", 1334 PR.raflags.onlink ? "L" : "", 1335 PR.raflags.autonomous ? "A" : ""); 1336#endif 1337 if (PR.vltime == ND6_INFINITE_LIFETIME) 1338 printf(" vltime=infinity"); 1339 else |
1296 printf(" vltime=%ld", (long)PR.vltime); | 1340 printf(" vltime=%lu", PR.vltime); |
1297 if (PR.pltime == ND6_INFINITE_LIFETIME) 1298 printf(", pltime=infinity"); 1299 else | 1341 if (PR.pltime == ND6_INFINITE_LIFETIME) 1342 printf(", pltime=infinity"); 1343 else |
1300 printf(", pltime=%ld", (long)PR.pltime); | 1344 printf(", pltime=%lu", PR.pltime); |
1301 if (PR.expire == 0) 1302 printf(", expire=Never"); 1303 else if (PR.expire >= time.tv_sec) 1304 printf(", expire=%s", 1305 sec2str(PR.expire - time.tv_sec)); 1306 else 1307 printf(", expired"); 1308#ifdef NDPRF_ONLINK --- 229 unchanged lines hidden --- | 1345 if (PR.expire == 0) 1346 printf(", expire=Never"); 1347 else if (PR.expire >= time.tv_sec) 1348 printf(", expire=%s", 1349 sec2str(PR.expire - time.tv_sec)); 1350 else 1351 printf(", expired"); 1352#ifdef NDPRF_ONLINK --- 229 unchanged lines hidden --- |