ndp.c (259169) | ndp.c (259171) |
---|---|
1/* $FreeBSD: head/usr.sbin/ndp/ndp.c 259169 2013-12-10 13:14:54Z ae $ */ | 1/* $FreeBSD: head/usr.sbin/ndp/ndp.c 259171 2013-12-10 13:34:28Z ae $ */ |
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/* packing rule for routing socket */ 113#define ROUNDUP(a) \ 114 ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long)) 115#define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len)) 116 | |
117#define NEXTADDR(w, s) \ 118 if (rtm->rtm_addrs & (w)) { \ 119 bcopy((char *)&s, cp, sizeof(s)); cp += SA_SIZE(&s);} 120 121 122static pid_t pid; 123static int nflag; 124static int tflag; --- 291 unchanged lines hidden (view full) --- 416 flags |= RTF_ANNOUNCE; 417 argv++; 418 } 419 if (rtmsg(RTM_GET) < 0) { 420 errx(1, "RTM_GET(%s) failed", host); 421 /* NOTREACHED */ 422 } 423 sin = (struct sockaddr_in6 *)(rtm + 1); | 112#define NEXTADDR(w, s) \ 113 if (rtm->rtm_addrs & (w)) { \ 114 bcopy((char *)&s, cp, sizeof(s)); cp += SA_SIZE(&s);} 115 116 117static pid_t pid; 118static int nflag; 119static int tflag; --- 291 unchanged lines hidden (view full) --- 411 flags |= RTF_ANNOUNCE; 412 argv++; 413 } 414 if (rtmsg(RTM_GET) < 0) { 415 errx(1, "RTM_GET(%s) failed", host); 416 /* NOTREACHED */ 417 } 418 sin = (struct sockaddr_in6 *)(rtm + 1); |
424 sdl = (struct sockaddr_dl *)(ROUNDUP(sin->sin6_len) + (char *)sin); | 419 sdl = (struct sockaddr_dl *)(ALIGN(sin->sin6_len) + (char *)sin); |
425 if (IN6_ARE_ADDR_EQUAL(&sin->sin6_addr, &sin_m.sin6_addr)) { 426 if (sdl->sdl_family == AF_LINK && 427 !(rtm->rtm_flags & RTF_GATEWAY)) { 428 switch (sdl->sdl_type) { 429 case IFT_ETHER: case IFT_FDDI: case IFT_ISO88023: 430 case IFT_ISO88024: case IFT_ISO88025: 431 case IFT_L2VLAN: case IFT_BRIDGE: 432 goto overwrite; --- 70 unchanged lines hidden (view full) --- 503 sin->sin6_addr = ((struct sockaddr_in6 *)res->ai_addr)->sin6_addr; 504 sin->sin6_scope_id = 505 ((struct sockaddr_in6 *)res->ai_addr)->sin6_scope_id; 506 if (rtmsg(RTM_GET) < 0) { 507 errx(1, "RTM_GET(%s) failed", host); 508 /* NOTREACHED */ 509 } 510 sin = (struct sockaddr_in6 *)(rtm + 1); | 420 if (IN6_ARE_ADDR_EQUAL(&sin->sin6_addr, &sin_m.sin6_addr)) { 421 if (sdl->sdl_family == AF_LINK && 422 !(rtm->rtm_flags & RTF_GATEWAY)) { 423 switch (sdl->sdl_type) { 424 case IFT_ETHER: case IFT_FDDI: case IFT_ISO88023: 425 case IFT_ISO88024: case IFT_ISO88025: 426 case IFT_L2VLAN: case IFT_BRIDGE: 427 goto overwrite; --- 70 unchanged lines hidden (view full) --- 498 sin->sin6_addr = ((struct sockaddr_in6 *)res->ai_addr)->sin6_addr; 499 sin->sin6_scope_id = 500 ((struct sockaddr_in6 *)res->ai_addr)->sin6_scope_id; 501 if (rtmsg(RTM_GET) < 0) { 502 errx(1, "RTM_GET(%s) failed", host); 503 /* NOTREACHED */ 504 } 505 sin = (struct sockaddr_in6 *)(rtm + 1); |
511 sdl = (struct sockaddr_dl *)(ROUNDUP(sin->sin6_len) + (char *)sin); | 506 sdl = (struct sockaddr_dl *)(ALIGN(sin->sin6_len) + (char *)sin); |
512 if (IN6_ARE_ADDR_EQUAL(&sin->sin6_addr, &sin_m.sin6_addr)) { 513 if (sdl->sdl_family == AF_LINK && 514 !(rtm->rtm_flags & RTF_GATEWAY)) { 515 goto delete; 516 } 517 fprintf(stderr, "delete: cannot delete non-NDP entry\n"); 518 return 1; 519 } --- 73 unchanged lines hidden (view full) --- 593 } else 594 buf = lim = NULL; 595 596 for (next = buf; next && next < lim; next += rtm->rtm_msglen) { 597 int isrouter = 0, prbs = 0; 598 599 rtm = (struct rt_msghdr *)next; 600 sin = (struct sockaddr_in6 *)(rtm + 1); | 507 if (IN6_ARE_ADDR_EQUAL(&sin->sin6_addr, &sin_m.sin6_addr)) { 508 if (sdl->sdl_family == AF_LINK && 509 !(rtm->rtm_flags & RTF_GATEWAY)) { 510 goto delete; 511 } 512 fprintf(stderr, "delete: cannot delete non-NDP entry\n"); 513 return 1; 514 } --- 73 unchanged lines hidden (view full) --- 588 } else 589 buf = lim = NULL; 590 591 for (next = buf; next && next < lim; next += rtm->rtm_msglen) { 592 int isrouter = 0, prbs = 0; 593 594 rtm = (struct rt_msghdr *)next; 595 sin = (struct sockaddr_in6 *)(rtm + 1); |
601 sdl = (struct sockaddr_dl *)((char *)sin + ROUNDUP(sin->sin6_len)); | 596 sdl = (struct sockaddr_dl *)((char *)sin + ALIGN(sin->sin6_len)); |
602 603 /* 604 * Some OSes can produce a route that has the LINK flag but 605 * has a non-AF_LINK gateway (e.g. fe80::xx%lo0 on FreeBSD 606 * and BSD/OS, where xx is not the interface identifier on 607 * lo0). Such routes entry would annoy getnbrinfo() below, 608 * so we skip them. 609 * XXX: such routes should have the GATEWAY flag, not the --- 962 unchanged lines hidden --- | 597 598 /* 599 * Some OSes can produce a route that has the LINK flag but 600 * has a non-AF_LINK gateway (e.g. fe80::xx%lo0 on FreeBSD 601 * and BSD/OS, where xx is not the interface identifier on 602 * lo0). Such routes entry would annoy getnbrinfo() below, 603 * so we skip them. 604 * XXX: such routes should have the GATEWAY flag, not the --- 962 unchanged lines hidden --- |