Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ETH_MAC indirection erratum #453

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions 3B2/3b2_ni.c
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ t_stat ni_setmac(UNIT *uptr, int32 val, CONST char* cptr, void* desc)
UNUSED(desc);

status = SCPE_OK;
status = eth_mac_scan_ex(&ni.macs[NI_NIC_MAC], cptr, uptr);
status = eth_mac_scan_ex(ni.macs[NI_NIC_MAC], cptr, uptr);

if (status == SCPE_OK) {
eth_filter(ni.eth, ni.filter_count, ni.macs, 0, 0);
Expand All @@ -577,7 +577,7 @@ t_stat ni_showmac(FILE* st, UNIT* uptr, int32 val, CONST void* desc)
UNUSED(val);
UNUSED(desc);

eth_mac_fmt(&ni.macs[NI_NIC_MAC], buffer);
eth_mac_fmt(ni.macs[NI_NIC_MAC], buffer);
fprintf(st, "MAC=%s", buffer);
return SCPE_OK;
}
Expand All @@ -591,12 +591,12 @@ t_stat ni_show_filters(FILE* st, UNIT* uptr, int32 val, CONST void* desc)
UNUSED(val);
UNUSED(desc);

eth_mac_fmt(&ni.macs[NI_NIC_MAC], buffer);
eth_mac_fmt(ni.macs[NI_NIC_MAC], buffer);
fprintf(st, "Physical Address=%s\n", buffer);
if (ni.filter_count > 0) {
fprintf(st, "Filters:\n");
for (i=0; i < ni.filter_count; i++) {
eth_mac_fmt((ETH_MAC *) ni.macs[i], buffer);
eth_mac_fmt(ni.macs[i], buffer);
fprintf(st, "[%2d]: %s\n", i, buffer);
}
fprintf(st, "\n");
Expand Down Expand Up @@ -948,7 +948,7 @@ t_stat ni_attach(UNIT *uptr, CONST char *cptr)
return status;
}

status = eth_check_address_conflict(ni.eth, &ni.macs[NI_NIC_MAC]);
status = eth_check_address_conflict(ni.eth, ni.macs[NI_NIC_MAC]);
if (status != SCPE_OK) {
sim_debug(DBG_ERR, &ni_dev, "ni_attach failure: mac check\n");
eth_close(ni.eth);
Expand Down
56 changes: 27 additions & 29 deletions PDP10/kl10_nia.c
Original file line number Diff line number Diff line change
Expand Up @@ -573,8 +573,8 @@ void nia_start()
nia_rh.wcr);
nia_data.pia = (int)(nia_rh.buf & 7);
nia_data.status |= NIA_MRN;
memcpy(&nia_data.macs[0], &nia_data.mac, sizeof (ETH_MAC));
memcpy(&nia_data.macs[1], &broadcast_ethaddr, sizeof(ETH_MAC));
eth_copy_mac(nia_data.macs[0], nia_data.mac);
eth_copy_mac(nia_data.macs[1], broadcast_ethaddr);
}

void nia_stop()
Expand Down Expand Up @@ -634,16 +634,14 @@ void nia_disable()
/*
* Copy a MAC address from string to memory word.
*/
void nia_cpy_mac(uint64 word1, uint64 word2, ETH_MAC *mac)
void nia_cpy_mac(uint64 word1, uint64 word2, ETH_MAC mac)
{
ETH_MAC m;
m[0] = (unsigned char)((word1 >> 28) & 0xff);
m[1] = (unsigned char)((word1 >> 20) & 0xff);
m[2] = (unsigned char)((word1 >> 12) & 0xff);
m[3] = (unsigned char)((word1 >> 4) & 0xff);
m[4] = (unsigned char)((word2 >> 28) & 0xff);
m[5] = (unsigned char)((word2 >> 20) & 0xff);
memcpy(mac, &m, sizeof(ETH_MAC));
mac[0] = (unsigned char)((word1 >> 28) & 0xff);
mac[1] = (unsigned char)((word1 >> 20) & 0xff);
mac[2] = (unsigned char)((word1 >> 12) & 0xff);
mac[3] = (unsigned char)((word1 >> 4) & 0xff);
mac[4] = (unsigned char)((word2 >> 28) & 0xff);
mac[5] = (unsigned char)((word2 >> 20) & 0xff);
}

/*
Expand Down Expand Up @@ -903,9 +901,9 @@ void nia_load_mcast()
t_addr addr = nia_data.mcast_addr;

/* Start with our own address. */
memcpy(&nia_data.macs[n], &nia_data.mac, sizeof (ETH_MAC));
eth_copy_mac(nia_data.macs[n], nia_data.mac);
n++;
memcpy(&nia_data.macs[n], &broadcast_ethaddr, sizeof (ETH_MAC));
eth_copy_mac(nia_data.macs[n], broadcast_ethaddr);
n++;
for (i = 0; i < 17; i++) {
uint64 word1, word2;
Expand All @@ -919,12 +917,12 @@ void nia_load_mcast()
return;
}
if (word2 & 1) {
nia_cpy_mac(word1, word2, &nia_data.macs[n]);
nia_cpy_mac(word1, word2, nia_data.macs[n]);
n++;
}
}
for(i = 0; i< n; i++) {
eth_mac_fmt(&nia_data.macs[i], buffer);
eth_mac_fmt(nia_data.macs[i], buffer);
sim_debug(DEBUG_DETAIL, &nia_dev, "NIA load mcast%d: %s\n",i,buffer);
}
nia_data.macs_n = n - 2;
Expand Down Expand Up @@ -1021,12 +1019,12 @@ void nia_packet_debug(struct nia_device *nia, const char *action,

if (!(nia_dev.dctrl & DEBUG_ARP))
return;
eth_mac_fmt(&arp->ethhdr.src, eth_src);
eth_mac_fmt(&arp->ethhdr.dest, eth_dst);
eth_mac_fmt(&arp->shwaddr, arp_shwaddr);
eth_mac_fmt(arp->ethhdr.src, eth_src);
eth_mac_fmt(arp->ethhdr.dest, eth_dst);
eth_mac_fmt(arp->shwaddr, arp_shwaddr);
memcpy(&in_addr, &arp->sipaddr, sizeof(in_addr));
strlcpy(arp_sipaddr, ipv4_inet_ntoa(in_addr), sizeof(arp_sipaddr));
eth_mac_fmt(&arp->dhwaddr, arp_dhwaddr);
eth_mac_fmt(arp->dhwaddr, arp_dhwaddr);
memcpy(&in_addr, &arp->dipaddr, sizeof(in_addr));
strlcpy(arp_dipaddr, ipv4_inet_ntoa(in_addr), sizeof(arp_dipaddr));
sim_debug(DEBUG_ARP, &nia_dev,
Expand Down Expand Up @@ -1142,10 +1140,10 @@ int nia_send_pkt(uint64 cmd)
nia_error(EBSERR);
return 0;
}
nia_cpy_mac(word1, word2, &dest);
memcpy(hdr->dest, dest, sizeof(ETH_MAC));
nia_cpy_mac(word1, word2, dest);
eth_copy_mac(hdr->dest, dest);
/* Copy our address over */
memcpy(hdr->src, nia_data.mac, sizeof(ETH_MAC));
eth_copy_mac(hdr->src, nia_data.mac);
/* Set packet length */
nia_data.snd_buff.len = len + sizeof(struct nia_eth_hdr);
/* Preappend length if asking for pad */
Expand Down Expand Up @@ -1319,7 +1317,7 @@ t_stat nia_cmd_srv(UNIT * uptr)
nia_error(EBSERR);
return SCPE_OK;
}
nia_cpy_mac(word1, word2, &nia_data.mac);
nia_cpy_mac(word1, word2, nia_data.mac);
if (Mem_read_word(nia_data.cmd_entry + 6, &word1, 0)) {
nia_error(EBSERR);
return SCPE_OK;
Expand All @@ -1331,7 +1329,7 @@ t_stat nia_cmd_srv(UNIT * uptr)
nia_data.prmsc = (int)(word1 & 1);
nia_data.h4000 = (int)((word1 & 2) != 0);
nia_data.amc = (int)((word1 & 4) != 0);
memcpy(&nia_data.macs[0], &nia_data.mac, sizeof (ETH_MAC));
eth_copy_mac(nia_data.macs[0], nia_data.mac);
if (nia_recv_uptr->flags & UNIT_ATT)
eth_filter (&nia_data.etherface, nia_data.macs_n + 2,
nia_data.macs, 0, 0);
Expand Down Expand Up @@ -1549,7 +1547,7 @@ t_stat nia_rec_srv(UNIT * uptr)
t_stat nia_show_mac (FILE* st, UNIT* uptr, int32 val, CONST void* desc)
{
char buffer[20];
eth_mac_fmt(&nia_data.mac, buffer);
eth_mac_fmt(nia_data.mac, buffer);
fprintf(st, "MAC=%s", buffer);
return SCPE_OK;
}
Expand All @@ -1561,7 +1559,7 @@ t_stat nia_set_mac (UNIT* uptr, int32 val, CONST char* cptr, void* desc)
if (!cptr) return SCPE_IERR;
if (uptr->flags & UNIT_ATT) return SCPE_ALATT;

status = eth_mac_scan_ex(&nia_data.mac, cptr, uptr);
status = eth_mac_scan_ex(nia_data.mac, cptr, uptr);
if (status != SCPE_OK)
return status;

Expand Down Expand Up @@ -1594,16 +1592,16 @@ t_stat nia_attach(UNIT* uptr, CONST char* cptr)
if (tptr == NULL) return SCPE_MEM;
strcpy(tptr, cptr);

memcpy(&nia_data.macs[0], &nia_data.mac, sizeof (ETH_MAC));
eth_copy_mac(nia_data.macs[0], nia_data.mac);
memcpy(&nia_data.macs[1], &broadcast_ethaddr, 6);
status = eth_open(&nia_data.etherface, cptr, &nia_dev, DEBUG_ETHER);
if (status != SCPE_OK) {
free(tptr);
return status;
}
eth_mac_fmt(&nia_data.mac, buf); /* format ethernet mac address */
eth_mac_fmt(nia_data.mac, buf); /* format ethernet mac address */
if (SCPE_OK != eth_check_address_conflict (&nia_data.etherface,
&nia_data.mac)) {
nia_data.mac)) {
eth_close(&nia_data.etherface);
free(tptr);
return sim_messagef (SCPE_NOATT,
Expand Down
52 changes: 26 additions & 26 deletions PDP10/kx10_imp.c
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ void imp_packet_in(struct imp_device *imp);
void imp_send_packet (struct imp_device *imp_data, int len);
void imp_free_packet(struct imp_device *imp, struct imp_packet *p);
struct imp_packet * imp_get_packet(struct imp_device *imp);
void imp_arp_update(struct imp_device *imp, in_addr_T ipaddr, ETH_MAC *ethaddr, int age);
void imp_arp_update(struct imp_device *imp, in_addr_T ipaddr, ETH_MAC ethaddr, int age);
void imp_arp_arpin(struct imp_device *imp, ETH_PACK *packet);
void imp_arp_arpout(struct imp_device *imp, in_addr_T ipaddr);
struct arp_entry * imp_arp_lookup(struct imp_device *imp, in_addr_T ipaddr);
Expand Down Expand Up @@ -1430,7 +1430,7 @@ imp_packet_in(struct imp_device *imp)
/* Process as IP if it is for us */
if (ip_hdr->ip_dst == imp_data.ip || ip_hdr->ip_dst == 0) {
/* Add mac address since we will probably need it later */
imp_arp_update(imp, ip_hdr->ip_src, &hdr->src, 0);
imp_arp_update(imp, ip_hdr->ip_src, hdr->src, 0);
/* Clear beginning of message */
memset(&imp->rbuffer[0], 0, 256);
imp->rbuffer[0] = 0xf;
Expand Down Expand Up @@ -1955,12 +1955,12 @@ void imp_packet_debug(struct imp_device *imp, const char *action, ETH_PACK *pack

if (!(imp_dev.dctrl & DEBUG_ARP))
return;
eth_mac_fmt(&arp->ethhdr.src, eth_src);
eth_mac_fmt(&arp->ethhdr.dest, eth_dst);
eth_mac_fmt(&arp->shwaddr, arp_shwaddr);
eth_mac_fmt(arp->ethhdr.src, eth_src);
eth_mac_fmt(arp->ethhdr.dest, eth_dst);
eth_mac_fmt(arp->shwaddr, arp_shwaddr);
memcpy(&in_addr, &arp->sipaddr, sizeof(in_addr));
strlcpy(arp_sipaddr, ipv4_inet_ntoa(in_addr), sizeof(arp_sipaddr));
eth_mac_fmt(&arp->dhwaddr, arp_dhwaddr);
eth_mac_fmt(arp->dhwaddr, arp_dhwaddr);
memcpy(&in_addr, &arp->dipaddr, sizeof(in_addr));
strlcpy(arp_dipaddr, ipv4_inet_ntoa(in_addr), sizeof(arp_dipaddr));
sim_debug(DEBUG_ARP, &imp_dev,
Expand Down Expand Up @@ -2013,7 +2013,7 @@ void imp_packet_debug(struct imp_device *imp, const char *action, ETH_PACK *pack
memcpy(&ipaddr, &dhcp->giaddr, sizeof(ipaddr));
sim_debug(DEBUG_DHCP, &imp_dev, ", giaddr=%s", ipv4_inet_ntoa(ipaddr));
}
eth_mac_fmt((ETH_MAC*)&dhcp->chaddr, mac_buf);
eth_mac_fmt(dhcp->chaddr, mac_buf);
sim_debug(DEBUG_DHCP, &imp_dev, ", chaddr=%s Options: ", mac_buf);
while (*opt != DHCP_OPTION_END) {
int opt_len;
Expand Down Expand Up @@ -2129,7 +2129,7 @@ void imp_write(struct imp_device *imp, ETH_PACK *packet) {
* Update the ARP table, first use free entry, else use oldest.
*/
void
imp_arp_update(struct imp_device *imp, in_addr_T ipaddr, ETH_MAC *ethaddr, int age)
imp_arp_update(struct imp_device *imp, in_addr_T ipaddr, ETH_MAC ethaddr, int age)
{
struct arp_entry *tabptr;
int i;
Expand All @@ -2141,8 +2141,8 @@ imp_arp_update(struct imp_device *imp, in_addr_T ipaddr, ETH_MAC *ethaddr, int a

if (tabptr->ipaddr != 0) {
if (tabptr->ipaddr == ipaddr) {
if (0 != memcmp(&tabptr->ethaddr, ethaddr, sizeof(ETH_MAC))) {
memcpy(&tabptr->ethaddr, ethaddr, sizeof(ETH_MAC));
if (0 != eth_mac_cmp(tabptr->ethaddr, ethaddr)) {
eth_copy_mac(tabptr->ethaddr, ethaddr);
eth_mac_fmt(ethaddr, mac_buf);
sim_debug(DEBUG_ARP, &imp_dev,
"updating entry for IP %s to %s\n",
Expand Down Expand Up @@ -2178,7 +2178,7 @@ imp_arp_update(struct imp_device *imp, in_addr_T ipaddr, ETH_MAC *ethaddr, int a
}

/* Now save the entry */
memcpy(&tabptr->ethaddr, ethaddr, sizeof(ETH_MAC));
eth_copy_mac(tabptr->ethaddr, ethaddr);
tabptr->ipaddr = ipaddr;
tabptr->age = age;
eth_mac_fmt(ethaddr, mac_buf);
Expand All @@ -2204,7 +2204,7 @@ void imp_arp_age(struct imp_device *imp)
if (tabptr->age > IMP_ARP_MAX_AGE) {
char mac_buf[20];

eth_mac_fmt(&tabptr->ethaddr, mac_buf);
eth_mac_fmt(tabptr->ethaddr, mac_buf);
sim_debug(DEBUG_ARP, &imp_dev,
"discarding ARP entry for IP %s %s after %d seconds\n",
ipv4_inet_ntoa(*((struct in_addr *)&tabptr->ipaddr)), mac_buf, IMP_ARP_MAX_AGE);
Expand Down Expand Up @@ -2232,7 +2232,7 @@ imp_arp_arpin(struct imp_device *imp, ETH_PACK *packet)
return;
arp = (struct arp_hdr *)(&packet->msg[0]);
op = ntohs(arp->opcode);
imp_arp_update(imp, arp->sipaddr, &arp->shwaddr, 0);
imp_arp_update(imp, arp->sipaddr, arp->shwaddr, 0);

switch (op) {
case ARP_REQUEST:
Expand All @@ -2249,7 +2249,7 @@ imp_arp_arpin(struct imp_device *imp, ETH_PACK *packet)
arp->ethhdr.type = htons(ETHTYPE_ARP);
packet->len = sizeof(struct arp_hdr);
imp_write(imp, packet);
eth_mac_fmt(&arp->dhwaddr, mac_buf);
eth_mac_fmt(arp->dhwaddr, mac_buf);
sim_debug(DEBUG_ARP, &imp_dev, "replied to received request for IP %s from %s\n",
ipv4_inet_ntoa(*((struct in_addr *)&imp->ip)), mac_buf);
}
Expand All @@ -2260,7 +2260,7 @@ imp_arp_arpin(struct imp_device *imp, ETH_PACK *packet)
if (arp->dipaddr == imp->ip) {
struct imp_packet *nq = NULL; /* New send queue */

eth_mac_fmt(&arp->shwaddr, mac_buf);
eth_mac_fmt(arp->shwaddr, mac_buf);
memcpy(&in_addr, &arp->sipaddr, sizeof(in_addr));
sim_debug(DEBUG_ARP, &imp_dev, "received reply for IP %s as %s\n",
ipv4_inet_ntoa(in_addr), mac_buf);
Expand Down Expand Up @@ -2351,12 +2351,12 @@ t_stat imp_set_arp (UNIT* uptr, int32 val, CONST char* cptr, void* desc)

cptr = get_glyph (cptr, abuf, '=');
if (cptr && *cptr) {
if (SCPE_OK != eth_mac_scan (&mac_addr, cptr)) /* scan string for mac, put in mac */
if (SCPE_OK != eth_mac_scan (mac_addr, cptr)) /* scan string for mac, put in mac */
return sim_messagef(SCPE_ARG, "Invalid MAC address: %s\n", abuf);
} else
return sim_messagef(SCPE_ARG, "MAC address empty\n");
if (ipv4_inet_aton (abuf, (struct in_addr *)&ip)) {
imp_arp_update(&imp_data, ip, &mac_addr, ARP_DONT_AGE);
imp_arp_update(&imp_data, ip, mac_addr, ARP_DONT_AGE);
return SCPE_OK;
}
return sim_messagef(SCPE_ARG, "Invalid IP Address: %s\n", abuf);
Expand All @@ -2377,7 +2377,7 @@ t_stat imp_show_arp (FILE *st, UNIT *uptr, int32 val, CONST void *desc)
if (tabptr->ipaddr == 0)
continue;

eth_mac_fmt(&tabptr->ethaddr, buf); /* format ethernet mac address */
eth_mac_fmt(tabptr->ethaddr, buf); /* format ethernet mac address */
if (tabptr->age == ARP_DONT_AGE)
fprintf (st, "%-17s%-19s%s\n",
ipv4_inet_ntoa(*((struct in_addr *)&tabptr->ipaddr)),
Expand Down Expand Up @@ -2457,7 +2457,7 @@ imp_do_send_dhcp(struct imp_device *imp,
packet->len = len + sizeof(struct ip_hdr);
imp_write(imp, packet);

eth_mac_fmt (&pkt->ethhdr.dest, mac_buf);
eth_mac_fmt (pkt->ethhdr.dest, mac_buf);
memcpy(&in_addr, &udp_hdr.ip_dst, sizeof(in_addr));
sim_debug(DEBUG_DHCP, &imp_dev,
"client sent %s packet to: %s:%d(%s)\n",
Expand Down Expand Up @@ -2574,7 +2574,7 @@ imp_do_dhcp_client(struct imp_device *imp, ETH_PACK *read_buffer)
}
}

eth_mac_fmt(&eth->src, mac_buf);
eth_mac_fmt(eth->src, mac_buf);
memcpy(&in_addr, &udp_hdr.ip_src, sizeof(in_addr));
sim_debug(DEBUG_DHCP, &imp_dev,
"client incoming %s packet: dhcp_state=%s - wait_time=%d from: %s:%d(%s)\n",
Expand Down Expand Up @@ -2617,7 +2617,7 @@ imp_do_dhcp_client(struct imp_device *imp, ETH_PACK *read_buffer)
break;
}
/* Record a static ARP for the DHCP server */
imp_arp_update(imp, dhcpip, &eth->src, ARP_DONT_AGE);
imp_arp_update(imp, dhcpip, eth->src, ARP_DONT_AGE);

/* Broadcast an ARP Reply with the assigned IP Address */
memset(&arp_pkt, 0, sizeof(ETH_PACK));
Expand Down Expand Up @@ -2948,7 +2948,7 @@ t_stat imp_show_mpx (FILE *st, UNIT *uptr, int32 val, CONST void *desc)
t_stat imp_show_mac (FILE* st, UNIT* uptr, int32 val, CONST void* desc)
{
char buffer[20];
eth_mac_fmt(&imp_data.mac, buffer);
eth_mac_fmt(imp_data.mac, buffer);
fprintf(st, "MAC=%s", buffer);
return SCPE_OK;
}
Expand All @@ -2960,7 +2960,7 @@ t_stat imp_set_mac (UNIT* uptr, int32 val, CONST char* cptr, void* desc)
if (!cptr) return SCPE_IERR;
if (uptr->flags & UNIT_ATT) return SCPE_ALATT;

status = eth_mac_scan_ex(&imp_data.mac, cptr, uptr);
status = eth_mac_scan_ex(imp_data.mac, cptr, uptr);
if (status != SCPE_OK)
return status;

Expand Down Expand Up @@ -3160,8 +3160,8 @@ t_stat imp_attach(UNIT* uptr, CONST char* cptr)
free(tptr);
return status;
}
eth_mac_fmt(&imp_data.mac, buf); /* format ethernet mac address */
if (SCPE_OK != eth_check_address_conflict (&imp_data.etherface, &imp_data.mac)) {
eth_mac_fmt(imp_data.mac, buf); /* format ethernet mac address */
if (SCPE_OK != eth_check_address_conflict (&imp_data.etherface, imp_data.mac)) {
eth_close(&imp_data.etherface);
free(tptr);
return sim_messagef (SCPE_NOATT, "%s: MAC Address Conflict on LAN for address %s\n",
Expand Down Expand Up @@ -3215,7 +3215,7 @@ t_stat imp_attach(UNIT* uptr, CONST char* cptr)
imp_arp_arpin(&imp_data, &read_buffer);
} while (read_buffer.len > 0);
if ((arp = imp_arp_lookup(&imp_data, imp_data.gwip)))
imp_arp_update(&imp_data, imp_data.gwip, &arp->ethaddr, ARP_DONT_AGE);
imp_arp_update(&imp_data, imp_data.gwip, arp->ethaddr, ARP_DONT_AGE);
}

eth_set_async (&imp_data.etherface, 0); /* Allow Asynchronous inbound packets */
Expand Down
Loading
Loading