ndp: Remove unneeded eh_source parameter

ndp() takes a parameter giving the ethernet source address of the packet
it is to respond to, which it uses to determine the destination address to
send the reply packet to.

This is not necessary, because the address will always be the guest's
MAC address.  Even if the guest has just changed MAC address, then either
tap_handler_passt() or tap_handler_pasta() - which are the only call paths
leading to ndp() will have updated c->mac_guest with the new value.

So, remove the parameter, and just use c->mac_guest, making it more
consistent with other paths where we construct packets to send inwards.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
David Gibson 2022-10-19 11:43:54 +11:00 committed by Stefano Brivio
parent 9d8dd8b6f4
commit cb1edae3b5
3 changed files with 4 additions and 7 deletions

6
ndp.c
View file

@ -41,13 +41,11 @@
* ndp() - Check for NDP solicitations, reply as needed * ndp() - Check for NDP solicitations, reply as needed
* @c: Execution context * @c: Execution context
* @ih: ICMPv6 header * @ih: ICMPv6 header
* @eh_source: Source Ethernet address
* @saddr Source IPv6 address * @saddr Source IPv6 address
* *
* Return: 0 if not handled here, 1 if handled, -1 on failure * Return: 0 if not handled here, 1 if handled, -1 on failure
*/ */
int ndp(struct ctx *c, const struct icmp6hdr *ih, int ndp(struct ctx *c, const struct icmp6hdr *ih, const struct in6_addr *saddr)
const unsigned char *eh_source, const struct in6_addr *saddr)
{ {
char buf[BUFSIZ] = { 0 }; char buf[BUFSIZ] = { 0 };
struct ipv6hdr *ip6hr; struct ipv6hdr *ip6hr;
@ -196,7 +194,7 @@ dns_done:
ip6hr->hop_limit = 255; ip6hr->hop_limit = 255;
len += sizeof(*ehr) + sizeof(*ip6hr) + sizeof(*ihr); len += sizeof(*ehr) + sizeof(*ip6hr) + sizeof(*ihr);
memcpy(ehr->h_dest, eh_source, ETH_ALEN); memcpy(ehr->h_dest, c->mac_guest, ETH_ALEN);
memcpy(ehr->h_source, c->mac, ETH_ALEN); memcpy(ehr->h_source, c->mac, ETH_ALEN);
ehr->h_proto = htons(ETH_P_IPV6); ehr->h_proto = htons(ETH_P_IPV6);

3
ndp.h
View file

@ -6,7 +6,6 @@
#ifndef NDP_H #ifndef NDP_H
#define NDP_H #define NDP_H
int ndp(struct ctx *c, const struct icmp6hdr *ih, int ndp(struct ctx *c, const struct icmp6hdr *ih, const struct in6_addr *saddr);
const unsigned char *eh_source, const struct in6_addr *saddr);
#endif /* NDP_H */ #endif /* NDP_H */

2
tap.c
View file

@ -576,7 +576,7 @@ resume:
if (l4_len < sizeof(struct icmp6hdr)) if (l4_len < sizeof(struct icmp6hdr))
continue; continue;
if (ndp(c, (struct icmp6hdr *)l4h, eh->h_source, saddr)) if (ndp(c, (struct icmp6hdr *)l4h, saddr))
continue; continue;
tap_packet_debug(NULL, ip6h, NULL, proto, NULL, 1); tap_packet_debug(NULL, ip6h, NULL, proto, NULL, 1);