ipv6: Replace the ipv6 specific mac_addr_t type with the generic MacAddress.

Change-Id: Ia4835c78bd5c3d6cac4f4fd6ba1dd7ea8d818efd
diff --git a/src/net/ipv6/inet6.c b/src/net/ipv6/inet6.c
index 6eb6e81..3caf3d0 100644
--- a/src/net/ipv6/inet6.c
+++ b/src/net/ipv6/inet6.c
@@ -25,10 +25,10 @@
 // Convert MAC Address to IPv6 Link Local Address.
 // aa:bb:cc:dd:ee:ff => FF80::aabb:ccFF:FEdd:eeff
 // Bit 2 (U/L) of the mac is inverted.
-void ll6addr_from_mac(ip6_addr *_ip, const mac_addr *_mac)
+void ll6addr_from_mac(ip6_addr *_ip, const MacAddress *_mac)
 {
 	uint8_t *ip = _ip->x;
-	const uint8_t *mac = _mac->x;
+	const uint8_t *mac = _mac->octet;
 
 	memset(ip, 0, IP6_ADDR_LEN);
 
@@ -47,10 +47,10 @@
 
 // Convert MAC Address to IPv6 Solicit Neighbor Multicast Address.
 // aa:bb:cc:dd:ee:ff -> FF02::1:FFdd:eeff
-void snmaddr_from_mac(ip6_addr *_ip, const mac_addr *_mac)
+void snmaddr_from_mac(ip6_addr *_ip, const MacAddress *_mac)
 {
 	uint8_t *ip = _ip->x;
-	const uint8_t *mac = _mac->x;
+	const uint8_t *mac = _mac->octet;
 
 	ip[0] = 0xFF;
 	ip[1] = 0x02;
@@ -63,10 +63,10 @@
 }
 
 // Convert IPv6 Multicast Address to Ethernet Multicast Address.
-void multicast_from_ip6(mac_addr *_mac, const ip6_addr *_ip6)
+void multicast_from_ip6(MacAddress *_mac, const ip6_addr *_ip6)
 {
 	const uint8_t *ip = _ip6->x;
-	uint8_t *mac = _mac->x;
+	uint8_t *mac = _mac->octet;
 	mac[0] = 0x33;
 	mac[1] = 0x33;
 	mac[2] = ip[12];
@@ -76,38 +76,39 @@
 }
 
 // Ip6 stack configuration.
-mac_addr ll_mac_addr;
+MacAddress ll_mac_addr;
 ip6_addr ll_ip6_addr;
-mac_addr snm_mac_addr;
+MacAddress snm_mac_addr;
 ip6_addr snm_ip6_addr;
 
 // Cache for the last source addresses we've seen.
-static mac_addr rx_mac_addr;
+static MacAddress rx_mac_addr;
 static ip6_addr rx_ip6_addr;
 
 void ip6_init(const void *macaddr)
 {
 	// Save our ethernet MAC and synthesize link layer addresses.
-	memcpy(&ll_mac_addr, macaddr, 6);
+	memcpy(&ll_mac_addr, macaddr, sizeof(ll_mac_addr));
 	ll6addr_from_mac(&ll_ip6_addr, &ll_mac_addr);
 	snmaddr_from_mac(&snm_ip6_addr, &ll_mac_addr);
 	multicast_from_ip6(&snm_mac_addr, &snm_ip6_addr);
 
 	eth_add_mcast_filter(&snm_mac_addr);
 
-	mac_addr all;
+	MacAddress all;
 	multicast_from_ip6(&all, &ip6_ll_all_nodes);
 	eth_add_mcast_filter(&all);
 
 	printf("macaddr: %02x:%02x:%02x:%02x:%02x:%02x\n",
-	       ll_mac_addr.x[0], ll_mac_addr.x[1], ll_mac_addr.x[2],
-	       ll_mac_addr.x[3], ll_mac_addr.x[4], ll_mac_addr.x[5]);
+	       ll_mac_addr.octet[0], ll_mac_addr.octet[1],
+	       ll_mac_addr.octet[2], ll_mac_addr.octet[3],
+	       ll_mac_addr.octet[4], ll_mac_addr.octet[5]);
 	char tmp[IP6TOAMAX];
 	printf("ip6addr: %s\n", ip6toa(tmp, &ll_ip6_addr));
 	printf("snmaddr: %s\n", ip6toa(tmp, &snm_ip6_addr));
 }
 
-static int resolve_ip6(mac_addr *_mac, const ip6_addr *_ip)
+static int resolve_ip6(MacAddress *_mac, const ip6_addr *_ip)
 {
 	const uint8_t *ip = _ip->x;
 
@@ -173,16 +174,16 @@
 static int ip6_setup(ip6_pkt *p, const ip6_addr *daddr,
 		     size_t length, uint8_t type)
 {
-	mac_addr dmac;
+	MacAddress dmac;
 
 	if (resolve_ip6(&dmac, daddr))
 		return -1;
 
 	// Ethernet header.
-	memcpy(p->eth + 2, &dmac, ETH_ADDR_LEN);
-	memcpy(p->eth + 8, &ll_mac_addr, ETH_ADDR_LEN);
-	p->eth[14] = (ETH_IP6 >> 8) & 0xFF;
-	p->eth[15] = ETH_IP6 & 0xFF;
+	memcpy(p->eth + 2, &dmac, sizeof(dmac));
+	memcpy(p->eth + 8, &ll_mac_addr, sizeof(ll_mac_addr));
+	p->eth[14] = (EthType_Ipv6 >> 8) & 0xFF;
+	p->eth[15] = EthType_Ipv6 & 0xFF;
 
 	// Ip6 header.
 	p->ip6.ver_tc_flow = 0x60; // v=6, tc=0, flow=0
@@ -316,7 +317,7 @@
 		memcpy(msg.hdr.target, &ll_ip6_addr, IP6_ADDR_LEN);
 		msg.opt[0] = NDP_N_TGT_LL_ADDR;
 		msg.opt[1] = 1;
-		memcpy(msg.opt + 2, &ll_mac_addr, ETH_ADDR_LEN);
+		memcpy(msg.opt + 2, &ll_mac_addr, sizeof(ll_mac_addr));
 
 		icmp6_send(&msg, sizeof(msg), (void *)ip->src);
 		return;
@@ -368,7 +369,7 @@
 	}
 
 	// stash the sender's info to simplify replies
-	memcpy(&rx_mac_addr, (uint8_t *)_data + 6, ETH_ADDR_LEN);
+	memcpy(&rx_mac_addr, (uint8_t *)_data + 6, sizeof(rx_mac_addr));
 	memcpy(&rx_ip6_addr, ip->src, IP6_ADDR_LEN);
 
 	if (ip->next_header == HDR_ICMP6) {
diff --git a/src/net/ipv6/inet6.h b/src/net/ipv6/inet6.h
index cbb260a..e10b59b 100644
--- a/src/net/ipv6/inet6.h
+++ b/src/net/ipv6/inet6.h
@@ -5,14 +5,14 @@
 #ifndef __NET_IPV6_INET6_H__
 #define __NET_IPV6_INET6_H__
 
-typedef struct mac_addr_t mac_addr;
+#include "net/ethernet.h"
+
 typedef struct ip6_addr_t ip6_addr;
 typedef struct ip6_hdr_t ip6_hdr;
 typedef struct udp_hdr_t udp_hdr;
 typedef struct icmp6_hdr_t icmp6_hdr;
 typedef struct ndp_n_hdr_t ndp_n_hdr;
 
-#define ETH_ADDR_LEN 6
 #define ETH_HDR_LEN 14
 #define ETH_MTU 1514
 
@@ -23,10 +23,6 @@
 
 #define UDP_HDR_LEN 8
 
-struct mac_addr_t {
-	uint8_t x[ETH_ADDR_LEN];
-} __attribute__((packed));
-
 struct ip6_addr_t {
 	uint8_t x[IP6_ADDR_LEN];
 } __attribute__((packed));
@@ -127,7 +123,7 @@
 void *eth_get_buffer(size_t len);
 void eth_put_buffer(void *ptr);
 int eth_send(void *data, size_t len);
-int eth_add_mcast_filter(const mac_addr *addr);
+int eth_add_mcast_filter(const MacAddress *addr);
 
 // call to transmit a UDP packet
 int udp6_send(const void *data, size_t len,
diff --git a/src/net/ipv6/ipv6.c b/src/net/ipv6/ipv6.c
index 781faf3..dfc0384 100644
--- a/src/net/ipv6/ipv6.c
+++ b/src/net/ipv6/ipv6.c
@@ -175,7 +175,7 @@
 	return ret;
 }
 
-int eth_add_mcast_filter(const mac_addr *addr)
+int eth_add_mcast_filter(const MacAddress *addr)
 {
 	return 0;
 }