aboutgitcodebugslistschat
path: root/ndp.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2022-10-19 11:43:55 +1100
committerStefano Brivio <sbrivio@redhat.com>2022-10-19 03:34:53 +0200
commitdb07804d26fbd0d350d4d1c90dd9a43c5e4d9f93 (patch)
treea5014e180ac27764b7c7f4f8e5b52814784c8c46 /ndp.c
parentcb1edae3b5cac6df68116ebce8e4194d4153d688 (diff)
downloadpasst-db07804d26fbd0d350d4d1c90dd9a43c5e4d9f93.tar
passt-db07804d26fbd0d350d4d1c90dd9a43c5e4d9f93.tar.gz
passt-db07804d26fbd0d350d4d1c90dd9a43c5e4d9f93.tar.bz2
passt-db07804d26fbd0d350d4d1c90dd9a43c5e4d9f93.tar.lz
passt-db07804d26fbd0d350d4d1c90dd9a43c5e4d9f93.tar.xz
passt-db07804d26fbd0d350d4d1c90dd9a43c5e4d9f93.tar.zst
passt-db07804d26fbd0d350d4d1c90dd9a43c5e4d9f93.zip
ndp: Use tap_icmp6_send() helper
We send ICMPv6 packets to the guest from both icmp.c and from ndp.c. The case in ndp() manually constructs L2 and IPv6 headers, unlike the version in icmp.c which uses the tap_icmp6_send() helper from tap.c Now that we've broaded the parameters of tap_icmp6_send() we can use it in ndp() as well saving some duplicated logic. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'ndp.c')
-rw-r--r--ndp.c21
1 files changed, 4 insertions, 17 deletions
diff --git a/ndp.c b/ndp.c
index f96b4b7..80e1f19 100644
--- a/ndp.c
+++ b/ndp.c
@@ -47,6 +47,7 @@
*/
int ndp(struct ctx *c, const struct icmp6hdr *ih, const struct in6_addr *saddr)
{
+ const struct in6_addr *rsaddr; /* src addr for reply */
char buf[BUFSIZ] = { 0 };
struct ipv6hdr *ip6hr;
struct icmp6hdr *ihr;
@@ -180,26 +181,12 @@ dns_done:
else
c->ip6.addr_seen = *saddr;
- ip6hr->daddr = *saddr;
if (IN6_IS_ADDR_LINKLOCAL(&c->ip6.gw))
- ip6hr->saddr = c->ip6.gw;
+ rsaddr = &c->ip6.gw;
else
- ip6hr->saddr = c->ip6.addr_ll;
+ rsaddr = &c->ip6.addr_ll;
- ip6hr->payload_len = htons(sizeof(*ihr) + len);
- csum_icmp6(ihr, &ip6hr->saddr, &ip6hr->daddr, ihr + 1, len);
-
- ip6hr->version = 6;
- ip6hr->nexthdr = IPPROTO_ICMPV6;
- ip6hr->hop_limit = 255;
-
- len += sizeof(*ehr) + sizeof(*ip6hr) + sizeof(*ihr);
- memcpy(ehr->h_dest, c->mac_guest, ETH_ALEN);
- memcpy(ehr->h_source, c->mac, ETH_ALEN);
- ehr->h_proto = htons(ETH_P_IPV6);
-
- if (tap_send(c, ehr, len) < 0)
- perror("NDP: send");
+ tap_icmp6_send(c, rsaddr, saddr, ihr, len + sizeof(*ihr));
return 1;
}