mirror of
https://passt.top/passt
synced 2024-12-22 13:45:32 +00:00
treewide: Rename MAC address fields for clarity
c->mac isn't a great name, because it doesn't say whose mac address it is and it's not necessarily obvious in all the contexts we use it. Since this is specifically the address that we (passt/pasta) use on the tap interface, rename it to "our_tap_mac". Rename the "mac_guest" field to "guest_mac" to be grammatically consistent. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
parent
066e69986b
commit
905ecd2b0b
4
arp.c
4
arp.c
@ -72,7 +72,7 @@ int arp(const struct ctx *c, const struct pool *p)
|
||||
|
||||
ah->ar_op = htons(ARPOP_REPLY);
|
||||
memcpy(am->tha, am->sha, sizeof(am->tha));
|
||||
memcpy(am->sha, c->mac, sizeof(am->sha));
|
||||
memcpy(am->sha, c->our_tap_mac, sizeof(am->sha));
|
||||
|
||||
memcpy(swap, am->tip, sizeof(am->tip));
|
||||
memcpy(am->tip, am->sip, sizeof(am->tip));
|
||||
@ -80,7 +80,7 @@ int arp(const struct ctx *c, const struct pool *p)
|
||||
|
||||
l2len = sizeof(*eh) + sizeof(*ah) + sizeof(*am);
|
||||
memcpy(eh->h_dest, eh->h_source, sizeof(eh->h_dest));
|
||||
memcpy(eh->h_source, c->mac, sizeof(eh->h_source));
|
||||
memcpy(eh->h_source, c->our_tap_mac, sizeof(eh->h_source));
|
||||
|
||||
tap_send_single(c, eh, l2len);
|
||||
|
||||
|
10
conf.c
10
conf.c
@ -956,7 +956,7 @@ static void conf_print(const struct ctx *c)
|
||||
info("Namespace interface: %s", c->pasta_ifn);
|
||||
|
||||
info("MAC:");
|
||||
info(" host: %s", eth_ntop(c->mac, bufmac, sizeof(bufmac)));
|
||||
info(" host: %s", eth_ntop(c->our_tap_mac, bufmac, sizeof(bufmac)));
|
||||
|
||||
if (c->ifi4) {
|
||||
if (!c->no_dhcp) {
|
||||
@ -1289,7 +1289,7 @@ void conf(struct ctx *c, int argc, char **argv)
|
||||
if (c->mode != MODE_PASTA)
|
||||
die("--ns-mac-addr is for pasta mode only");
|
||||
|
||||
parse_mac(c->mac_guest, optarg);
|
||||
parse_mac(c->guest_mac, optarg);
|
||||
break;
|
||||
case 5:
|
||||
if (c->mode != MODE_PASTA)
|
||||
@ -1500,7 +1500,7 @@ void conf(struct ctx *c, int argc, char **argv)
|
||||
|
||||
break;
|
||||
case 'M':
|
||||
parse_mac(c->mac, optarg);
|
||||
parse_mac(c->our_tap_mac, optarg);
|
||||
break;
|
||||
case 'g':
|
||||
if (inet_pton(AF_INET6, optarg, &c->ip6.gw) &&
|
||||
@ -1629,9 +1629,9 @@ void conf(struct ctx *c, int argc, char **argv)
|
||||
|
||||
nl_sock_init(c, false);
|
||||
if (!v6_only)
|
||||
c->ifi4 = conf_ip4(ifi4, &c->ip4, c->mac);
|
||||
c->ifi4 = conf_ip4(ifi4, &c->ip4, c->our_tap_mac);
|
||||
if (!v4_only)
|
||||
c->ifi6 = conf_ip6(ifi6, &c->ip6, c->mac);
|
||||
c->ifi6 = conf_ip6(ifi6, &c->ip6, c->our_tap_mac);
|
||||
if ((!c->ifi4 && !c->ifi6) ||
|
||||
(*c->ip4.ifname_out && !c->ifi4) ||
|
||||
(*c->ip6.ifname_out && !c->ifi6))
|
||||
|
6
dhcpv6.c
6
dhcpv6.c
@ -574,8 +574,10 @@ void dhcpv6_init(const struct ctx *c)
|
||||
resp.server_id.duid_time = duid_time;
|
||||
resp_not_on_link.server_id.duid_time = duid_time;
|
||||
|
||||
memcpy(resp.server_id.duid_lladdr, c->mac, sizeof(c->mac));
|
||||
memcpy(resp_not_on_link.server_id.duid_lladdr, c->mac, sizeof(c->mac));
|
||||
memcpy(resp.server_id.duid_lladdr,
|
||||
c->our_tap_mac, sizeof(c->our_tap_mac));
|
||||
memcpy(resp_not_on_link.server_id.duid_lladdr,
|
||||
c->our_tap_mac, sizeof(c->our_tap_mac));
|
||||
|
||||
resp.ia_addr.addr = c->ip6.addr;
|
||||
}
|
||||
|
4
ndp.c
4
ndp.c
@ -247,7 +247,7 @@ int ndp(struct ctx *c, const struct icmp6hdr *ih, const struct in6_addr *saddr,
|
||||
|
||||
memcpy(&na.target_addr, &ns->target_addr,
|
||||
sizeof(na.target_addr));
|
||||
memcpy(na.target_l2_addr.mac, c->mac, ETH_ALEN);
|
||||
memcpy(na.target_l2_addr.mac, c->our_tap_mac, ETH_ALEN);
|
||||
|
||||
} else if (ih->icmp6_type == RS) {
|
||||
size_t dns_s_len = 0;
|
||||
@ -331,7 +331,7 @@ int ndp(struct ctx *c, const struct icmp6hdr *ih, const struct in6_addr *saddr,
|
||||
}
|
||||
|
||||
dns_done:
|
||||
memcpy(&ra.source_ll.mac, c->mac, ETH_ALEN);
|
||||
memcpy(&ra.source_ll.mac, c->our_tap_mac, ETH_ALEN);
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
|
2
passt.c
2
passt.c
@ -272,7 +272,7 @@ int main(int argc, char **argv)
|
||||
if ((!c.no_udp && udp_init(&c)) || (!c.no_tcp && tcp_init(&c)))
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
proto_update_l2_buf(c.mac_guest, c.mac);
|
||||
proto_update_l2_buf(c.guest_mac, c.our_tap_mac);
|
||||
|
||||
if (c.ifi4 && !c.no_dhcp)
|
||||
dhcp_init();
|
||||
|
8
passt.h
8
passt.h
@ -172,8 +172,8 @@ struct ip6_ctx {
|
||||
* @epollfd: File descriptor for epoll instance
|
||||
* @fd_tap_listen: File descriptor for listening AF_UNIX socket, if any
|
||||
* @fd_tap: AF_UNIX socket, tuntap device, or pre-opened socket
|
||||
* @mac: Host MAC address
|
||||
* @mac_guest: MAC address of guest or namespace, seen or configured
|
||||
* @our_tap_mac: Pasta/passt's MAC on the tap link
|
||||
* @guest_mac: MAC address of guest or namespace, seen or configured
|
||||
* @hash_secret: 128-bit secret for siphash functions
|
||||
* @ifi4: Index of template interface for IPv4, 0 if IPv4 disabled
|
||||
* @ip: IPv4 configuration
|
||||
@ -226,8 +226,8 @@ struct ctx {
|
||||
int epollfd;
|
||||
int fd_tap_listen;
|
||||
int fd_tap;
|
||||
unsigned char mac[ETH_ALEN];
|
||||
unsigned char mac_guest[ETH_ALEN];
|
||||
unsigned char our_tap_mac[ETH_ALEN];
|
||||
unsigned char guest_mac[ETH_ALEN];
|
||||
uint64_t hash_secret[2];
|
||||
|
||||
unsigned int ifi4;
|
||||
|
8
pasta.c
8
pasta.c
@ -294,10 +294,10 @@ void pasta_ns_conf(struct ctx *c)
|
||||
strerror(-rc));
|
||||
|
||||
/* Get or set MAC in target namespace */
|
||||
if (MAC_IS_ZERO(c->mac_guest))
|
||||
nl_link_get_mac(nl_sock_ns, c->pasta_ifi, c->mac_guest);
|
||||
if (MAC_IS_ZERO(c->guest_mac))
|
||||
nl_link_get_mac(nl_sock_ns, c->pasta_ifi, c->guest_mac);
|
||||
else
|
||||
rc = nl_link_set_mac(nl_sock_ns, c->pasta_ifi, c->mac_guest);
|
||||
rc = nl_link_set_mac(nl_sock_ns, c->pasta_ifi, c->guest_mac);
|
||||
if (rc < 0)
|
||||
die("Couldn't set MAC address in namespace: %s",
|
||||
strerror(-rc));
|
||||
@ -392,7 +392,7 @@ void pasta_ns_conf(struct ctx *c)
|
||||
}
|
||||
}
|
||||
|
||||
proto_update_l2_buf(c->mac_guest, NULL);
|
||||
proto_update_l2_buf(c->guest_mac, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
12
tap.c
12
tap.c
@ -118,8 +118,8 @@ static void *tap_push_l2h(const struct ctx *c, void *buf, uint16_t proto)
|
||||
struct ethhdr *eh = (struct ethhdr *)buf;
|
||||
|
||||
/* TODO: ARP table lookup */
|
||||
memcpy(eh->h_dest, c->mac_guest, ETH_ALEN);
|
||||
memcpy(eh->h_source, c->mac, ETH_ALEN);
|
||||
memcpy(eh->h_dest, c->guest_mac, ETH_ALEN);
|
||||
memcpy(eh->h_source, c->our_tap_mac, ETH_ALEN);
|
||||
eh->h_proto = ntohs(proto);
|
||||
return eh + 1;
|
||||
}
|
||||
@ -946,9 +946,9 @@ void tap_add_packet(struct ctx *c, ssize_t l2len, char *p)
|
||||
|
||||
eh = (struct ethhdr *)p;
|
||||
|
||||
if (memcmp(c->mac_guest, eh->h_source, ETH_ALEN)) {
|
||||
memcpy(c->mac_guest, eh->h_source, ETH_ALEN);
|
||||
proto_update_l2_buf(c->mac_guest, NULL);
|
||||
if (memcmp(c->guest_mac, eh->h_source, ETH_ALEN)) {
|
||||
memcpy(c->guest_mac, eh->h_source, ETH_ALEN);
|
||||
proto_update_l2_buf(c->guest_mac, NULL);
|
||||
}
|
||||
|
||||
switch (ntohs(eh->h_proto)) {
|
||||
@ -1337,6 +1337,6 @@ void tap_sock_init(struct ctx *c)
|
||||
* sends us packets. Use the broadcast address so that our
|
||||
* first packets will reach it.
|
||||
*/
|
||||
memset(&c->mac_guest, 0xff, sizeof(c->mac_guest));
|
||||
memset(&c->guest_mac, 0xff, sizeof(c->guest_mac));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user