Deleted Added
full compact
arp.c (201202) arp.c (201282)
1/*
2 * Copyright (c) 1984, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Sun Microsystems, Inc.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 28 unchanged lines hidden (view full) ---

37 The Regents of the University of California. All rights reserved.\n";
38#endif /* not lint */
39
40#ifndef lint
41static char const sccsid[] = "@(#)from: arp.c 8.2 (Berkeley) 1/2/94";
42#endif /* not lint */
43#endif
44#include <sys/cdefs.h>
1/*
2 * Copyright (c) 1984, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Sun Microsystems, Inc.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 28 unchanged lines hidden (view full) ---

37 The Regents of the University of California. All rights reserved.\n";
38#endif /* not lint */
39
40#ifndef lint
41static char const sccsid[] = "@(#)from: arp.c 8.2 (Berkeley) 1/2/94";
42#endif /* not lint */
43#endif
44#include <sys/cdefs.h>
45__FBSDID("$FreeBSD: head/usr.sbin/arp/arp.c 201202 2009-12-29 15:48:04Z jhb $");
45__FBSDID("$FreeBSD: head/usr.sbin/arp/arp.c 201282 2009-12-30 21:35:34Z qingli $");
46
47/*
48 * arp - display, set, and delete arp table entries
49 */
50
51
52#include <sys/param.h>
53#include <sys/file.h>

--- 267 unchanged lines hidden (view full) ---

321 struct timeval tv;
322 gettimeofday(&tv, 0);
323 expire_time = tv.tv_sec + 20 * 60;
324 } else if (strncmp(argv[0], "pub", 3) == 0) {
325 flags |= RTF_ANNOUNCE;
326 doing_proxy = 1;
327 if (argc && strncmp(argv[1], "only", 3) == 0) {
328 proxy_only = 1;
46
47/*
48 * arp - display, set, and delete arp table entries
49 */
50
51
52#include <sys/param.h>
53#include <sys/file.h>

--- 267 unchanged lines hidden (view full) ---

321 struct timeval tv;
322 gettimeofday(&tv, 0);
323 expire_time = tv.tv_sec + 20 * 60;
324 } else if (strncmp(argv[0], "pub", 3) == 0) {
325 flags |= RTF_ANNOUNCE;
326 doing_proxy = 1;
327 if (argc && strncmp(argv[1], "only", 3) == 0) {
328 proxy_only = 1;
329 dst->sin_other = SIN_PROXY;
330 argc--; argv++;
331 }
332 } else if (strncmp(argv[0], "blackhole", 9) == 0) {
333 if (flags & RTF_REJECT) {
334 printf("Choose one of blackhole or reject, not both.\n");
335 }
336 flags |= RTF_BLACKHOLE;
337 } else if (strncmp(argv[0], "reject", 6) == 0) {

--- 22 unchanged lines hidden (view full) ---

360 if (ea1 == NULL) {
361 warnx("invalid Ethernet address '%s'", eaddr);
362 return (1);
363 } else {
364 *ea = *ea1;
365 sdl_m.sdl_alen = ETHER_ADDR_LEN;
366 }
367 }
329 argc--; argv++;
330 }
331 } else if (strncmp(argv[0], "blackhole", 9) == 0) {
332 if (flags & RTF_REJECT) {
333 printf("Choose one of blackhole or reject, not both.\n");
334 }
335 flags |= RTF_BLACKHOLE;
336 } else if (strncmp(argv[0], "reject", 6) == 0) {

--- 22 unchanged lines hidden (view full) ---

359 if (ea1 == NULL) {
360 warnx("invalid Ethernet address '%s'", eaddr);
361 return (1);
362 } else {
363 *ea = *ea1;
364 sdl_m.sdl_alen = ETHER_ADDR_LEN;
365 }
366 }
368 for (;;) { /* try at most twice */
369 rtm = rtmsg(RTM_GET, dst, &sdl_m);
370 if (rtm == NULL) {
371 warn("%s", host);
372 return (1);
373 }
374 addr = (struct sockaddr_inarp *)(rtm + 1);
375 sdl = (struct sockaddr_dl *)(SA_SIZE(addr) + (char *)addr);
376 if (addr->sin_addr.s_addr != dst->sin_addr.s_addr)
377 break;
378 if (sdl->sdl_family == AF_LINK &&
379 !(rtm->rtm_flags & RTF_GATEWAY) &&
380 valid_type(sdl->sdl_type) )
381 break;
382 if (doing_proxy == 0) {
383 printf("set: can only proxy for %s\n", host);
384 return (1);
385 }
386 if (dst->sin_other & SIN_PROXY) {
387 printf("set: proxy entry exists for non 802 device\n");
388 return (1);
389 }
390 dst->sin_other = SIN_PROXY;
391 proxy_only = 1;
367
368 /*
369 * In the case a proxy-arp entry is being added for
370 * a remote end point, the RTF_ANNOUNCE flag in the
371 * RTM_GET command is an indication to the kernel
372 * routing code that the interface associated with
373 * the prefix route covering the local end of the
374 * PPP link should be returned, on which ARP applies.
375 */
376 rtm = rtmsg(RTM_GET, dst, &sdl_m);
377 if (rtm == NULL) {
378 warn("%s", host);
379 return (1);
392 }
380 }
381 addr = (struct sockaddr_inarp *)(rtm + 1);
382 sdl = (struct sockaddr_dl *)(SA_SIZE(addr) + (char *)addr);
383 if (addr->sin_addr.s_addr == dst->sin_addr.s_addr) {
384 printf("set: proxy entry exists for non 802 device\n");
385 return (1);
386 }
393
387
394 if (sdl->sdl_family != AF_LINK) {
388 if ((sdl->sdl_family != AF_LINK) ||
389 (rtm->rtm_flags & RTF_GATEWAY) ||
390 !valid_type(sdl->sdl_type)) {
395 printf("cannot intuit interface index and type for %s\n", host);
396 return (1);
397 }
398 sdl_m.sdl_type = sdl->sdl_type;
399 sdl_m.sdl_index = sdl->sdl_index;
400 return (rtmsg(RTM_ADD, dst, &sdl_m) == NULL);
401}
402

--- 28 unchanged lines hidden (view full) ---

431 struct sockaddr_inarp *addr, *dst;
432 struct rt_msghdr *rtm;
433 struct sockaddr_dl *sdl;
434 struct sockaddr_dl sdl_m;
435
436 dst = getaddr(host);
437 if (dst == NULL)
438 return (1);
391 printf("cannot intuit interface index and type for %s\n", host);
392 return (1);
393 }
394 sdl_m.sdl_type = sdl->sdl_type;
395 sdl_m.sdl_index = sdl->sdl_index;
396 return (rtmsg(RTM_ADD, dst, &sdl_m) == NULL);
397}
398

--- 28 unchanged lines hidden (view full) ---

427 struct sockaddr_inarp *addr, *dst;
428 struct rt_msghdr *rtm;
429 struct sockaddr_dl *sdl;
430 struct sockaddr_dl sdl_m;
431
432 dst = getaddr(host);
433 if (dst == NULL)
434 return (1);
439 dst->sin_other = do_proxy;
440
441 /*
435
436 /*
437 * Perform a regular entry delete first.
438 */
439 flags &= ~RTF_ANNOUNCE;
440
441 /*
442 * setup the data structure to notify the kernel
443 * it is the ARP entry the RTM_GET is interested
444 * in
445 */
446 bzero(&sdl_m, sizeof(sdl_m));
447 sdl_m.sdl_len = sizeof(sdl_m);
448 sdl_m.sdl_family = AF_LINK;
449

--- 16 unchanged lines hidden (view full) ---

466 */
467 if (sdl->sdl_family == AF_LINK &&
468 !(rtm->rtm_flags & RTF_GATEWAY) &&
469 valid_type(sdl->sdl_type) ) {
470 addr->sin_addr.s_addr = dst->sin_addr.s_addr;
471 break;
472 }
473
442 * setup the data structure to notify the kernel
443 * it is the ARP entry the RTM_GET is interested
444 * in
445 */
446 bzero(&sdl_m, sizeof(sdl_m));
447 sdl_m.sdl_len = sizeof(sdl_m);
448 sdl_m.sdl_family = AF_LINK;
449

--- 16 unchanged lines hidden (view full) ---

466 */
467 if (sdl->sdl_family == AF_LINK &&
468 !(rtm->rtm_flags & RTF_GATEWAY) &&
469 valid_type(sdl->sdl_type) ) {
470 addr->sin_addr.s_addr = dst->sin_addr.s_addr;
471 break;
472 }
473
474 if (dst->sin_other & SIN_PROXY) {
474 /*
475 * Regualar entry delete failed, now check if there
476 * is a proxy-arp entry to remove.
477 */
478 if (flags & RTF_ANNOUNCE) {
475 fprintf(stderr, "delete: cannot locate %s\n",host);
476 return (1);
477 }
479 fprintf(stderr, "delete: cannot locate %s\n",host);
480 return (1);
481 }
478 dst->sin_other = SIN_PROXY;
482
483 flags |= RTF_ANNOUNCE;
479 }
480 rtm->rtm_flags |= RTF_LLDATA;
481 if (rtmsg(RTM_DELETE, dst, NULL) != NULL) {
482 printf("%s (%s) deleted\n", host, inet_ntoa(addr->sin_addr));
483 return (0);
484 }
485 return (1);
486}
487
484 }
485 rtm->rtm_flags |= RTF_LLDATA;
486 if (rtmsg(RTM_DELETE, dst, NULL) != NULL) {
487 printf("%s (%s) deleted\n", host, inet_ntoa(addr->sin_addr));
488 return (0);
489 }
490 return (1);
491}
492
493
488/*
489 * Search the arp table and do some action on matching entries
490 */
491static int
492search(u_long addr, action_fn *action)
493{
494 int mib[6];
495 size_t needed;

--- 351 unchanged lines hidden ---
494/*
495 * Search the arp table and do some action on matching entries
496 */
497static int
498search(u_long addr, action_fn *action)
499{
500 int mib[6];
501 size_t needed;

--- 351 unchanged lines hidden ---