78 lines
2.4 KiB
Diff
78 lines
2.4 KiB
Diff
From ca9855d18c20c663991740bdfe7f8ab0f35ebccf Mon Sep 17 00:00:00 2001
|
|
From: Aichun Li <liaichun@huawei.com>
|
|
Date: Wed, 23 Dec 2020 22:48:14 +0800
|
|
Subject: [PATCH] add self mac check
|
|
|
|
Signed-off-by: Aichun Li <liaichun@huawei.com>
|
|
---
|
|
src/ndisc.c | 18 +++++++++++++-----
|
|
1 file changed, 13 insertions(+), 5 deletions(-)
|
|
|
|
diff --git a/src/ndisc.c b/src/ndisc.c
|
|
index 4373a17..bfd7cb7 100644
|
|
--- a/src/ndisc.c
|
|
+++ b/src/ndisc.c
|
|
@@ -253,7 +253,7 @@ buildsol (solicit_packet *ns, struct sockaddr_in6 *tgt, const char *ifname)
|
|
|
|
static int
|
|
parseadv (const uint8_t *buf, size_t len, const struct sockaddr_in6 *tgt,
|
|
- bool verbose)
|
|
+ bool verbose, const uint8_t *selfmac)
|
|
{
|
|
const struct nd_neighbor_advert *na =
|
|
(const struct nd_neighbor_advert *)buf;
|
|
@@ -295,6 +295,10 @@ parseadv (const uint8_t *buf, size_t len, const struct sockaddr_in6 *tgt,
|
|
/* Found! displays link-layer address */
|
|
ptr += 2;
|
|
optlen -= 2;
|
|
+ /* add self mac check */
|
|
+ if (memcmp(ptr, selfmac, optlen) == 0) {
|
|
+ return -1;
|
|
+ }
|
|
if (verbose)
|
|
fputs (_("Target link-layer address: "), stdout);
|
|
|
|
@@ -498,7 +502,7 @@ parsednssl (const uint8_t *opt)
|
|
|
|
static int
|
|
parseadv (const uint8_t *buf, size_t len, const struct sockaddr_in6 *tgt,
|
|
- bool verbose)
|
|
+ bool verbose, const uint8_t *selfmac)
|
|
{
|
|
const struct nd_router_advert *ra =
|
|
(const struct nd_router_advert *)buf;
|
|
@@ -670,7 +674,7 @@ recvfromLL (int fd, void *buf, size_t len, int flags,
|
|
|
|
static ssize_t
|
|
recvadv (int fd, const struct sockaddr_in6 *tgt, unsigned wait_ms,
|
|
- unsigned flags)
|
|
+ unsigned flags, const uint8_t *selfmac)
|
|
{
|
|
struct timespec end;
|
|
unsigned responses = 0;
|
|
@@ -730,7 +734,7 @@ recvadv (int fd, const struct sockaddr_in6 *tgt, unsigned wait_ms,
|
|
&& (addr.sin6_scope_id != tgt->sin6_scope_id))
|
|
continue;
|
|
|
|
- if (parseadv (buf.b, val, tgt, (flags & NDISC_VERBOSE) != 0) == 0)
|
|
+ if (parseadv (buf.b, val, tgt, (flags & NDISC_VERBOSE) != 0, selfmac) == 0)
|
|
{
|
|
if (flags & NDISC_VERBOSE)
|
|
{
|
|
@@ -824,7 +828,11 @@ ndisc (const char *name, const char *ifname, unsigned flags, unsigned retry,
|
|
retry--;
|
|
|
|
/* receives an Advertisement */
|
|
- ssize_t val = recvadv (fd, &tgt, wait_ms, flags);
|
|
+#ifndef RDISC
|
|
+ ssize_t val = recvadv (fd, &tgt, wait_ms, flags, packet.hw_addr);
|
|
+#else
|
|
+ ssize_t val = recvadv (fd, &tgt, wait_ms, flags, NULL);
|
|
+#endif
|
|
if (val > 0)
|
|
{
|
|
close (fd);
|
|
--
|
|
2.19.1
|
|
|