inet6: Make some private members static and prefixed into a namespace.
Change-Id: I4e369f64fdba7241b2f7c12168115e91bf69cf59
diff --git a/src/net/ipv6/inet6.c b/src/net/ipv6/inet6.c
index f2fc064..ca2f546 100644
--- a/src/net/ipv6/inet6.c
+++ b/src/net/ipv6/inet6.c
@@ -19,7 +19,7 @@
// 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(Ipv6Address *_ip, const MacAddress *_mac)
+static void inet6_ll6addr_from_mac(Ipv6Address *_ip, const MacAddress *_mac)
{
uint8_t *ip = _ip->x;
const uint8_t *mac = _mac->octet;
@@ -41,7 +41,7 @@
// Convert MAC Address to IPv6 Solicit Neighbor Multicast Address.
// aa:bb:cc:dd:ee:ff -> FF02::1:FFdd:eeff
-void snmaddr_from_mac(Ipv6Address *_ip, const MacAddress *_mac)
+static void inet6_snmaddr_from_mac(Ipv6Address *_ip, const MacAddress *_mac)
{
uint8_t *ip = _ip->x;
const uint8_t *mac = _mac->octet;
@@ -57,7 +57,8 @@
}
// Convert IPv6 Multicast Address to Ethernet Multicast Address.
-void multicast_from_ipv6(MacAddress *_mac, const Ipv6Address *_ipv6)
+static void inet6_multicast_from_ipv6(MacAddress *_mac,
+ const Ipv6Address *_ipv6)
{
const uint8_t *ip = _ipv6->x;
uint8_t *mac = _mac->octet;
@@ -70,14 +71,14 @@
}
// Ip6 stack configuration.
-MacAddress ll_mac_addr;
-Ipv6Address ll_ipv6_addr;
-MacAddress snm_mac_addr;
-Ipv6Address snm_ipv6_addr;
+static MacAddress inet6_ll_mac_addr;
+static Ipv6Address inet6_ll_ip_addr;
+static MacAddress inet6_snm_mac_addr;
+static Ipv6Address inet6_snm_ip_addr;
// Cache for the last source addresses we've seen.
-static MacAddress rx_mac_addr;
-static Ipv6Address rx_ipv6_addr;
+static MacAddress inet6_rx_mac_addr;
+static Ipv6Address inet6_rx_ip_addr;
static void ipv6_print_addr(void *ipv6addr)
{
@@ -136,25 +137,25 @@
void ipv6_init(const void *macaddr)
{
// Save our ethernet MAC and synthesize link layer addresses.
- memcpy(&ll_mac_addr, macaddr, sizeof(ll_mac_addr));
- ll6addr_from_mac(&ll_ipv6_addr, &ll_mac_addr);
- snmaddr_from_mac(&snm_ipv6_addr, &ll_mac_addr);
- multicast_from_ipv6(&snm_mac_addr, &snm_ipv6_addr);
+ memcpy(&inet6_ll_mac_addr, macaddr, sizeof(inet6_ll_mac_addr));
+ inet6_ll6addr_from_mac(&inet6_ll_ip_addr, &inet6_ll_mac_addr);
+ inet6_snmaddr_from_mac(&inet6_snm_ip_addr, &inet6_ll_mac_addr);
+ inet6_multicast_from_ipv6(&inet6_snm_mac_addr, &inet6_snm_ip_addr);
- eth_add_mcast_filter(&snm_mac_addr);
+ eth_add_mcast_filter(&inet6_snm_mac_addr);
MacAddress all;
- multicast_from_ipv6(&all, &Ipv6LlAllNodes);
+ inet6_multicast_from_ipv6(&all, &Ipv6LlAllNodes);
eth_add_mcast_filter(&all);
printf("macaddr: %02x:%02x:%02x:%02x:%02x:%02x\n",
- 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]);
+ inet6_ll_mac_addr.octet[0], inet6_ll_mac_addr.octet[1],
+ inet6_ll_mac_addr.octet[2], inet6_ll_mac_addr.octet[3],
+ inet6_ll_mac_addr.octet[4], inet6_ll_mac_addr.octet[5]);
printf("ipv6addr: ");
- ipv6_print_addr(&ll_ipv6_addr);
+ ipv6_print_addr(&inet6_ll_ip_addr);
printf("\nsnmaddr: ");
- ipv6_print_addr(&snm_ipv6_addr);
+ ipv6_print_addr(&inet6_snm_ip_addr);
printf("\n");
}
@@ -164,14 +165,14 @@
// Multicast addresses are a simple transform.
if (ip[0] == 0xFF) {
- multicast_from_ipv6(_mac, _ip);
+ inet6_multicast_from_ipv6(_mac, _ip);
return 0;
}
// Trying to send to the IP that we last received a packet from?
// Assume their mac address has not changed.
- if (memcmp(_ip, &rx_ipv6_addr, sizeof(rx_ipv6_addr)) == 0) {
- memcpy(_mac, &rx_mac_addr, sizeof(rx_mac_addr));
+ if (memcmp(_ip, &inet6_rx_ip_addr, sizeof(inet6_rx_ip_addr)) == 0) {
+ memcpy(_mac, &inet6_rx_mac_addr, sizeof(inet6_rx_mac_addr));
return 0;
}
@@ -247,7 +248,7 @@
// Ethernet header.
memcpy(p->eth + 2, &dmac, sizeof(dmac));
- memcpy(p->eth + 8, &ll_mac_addr, sizeof(ll_mac_addr));
+ memcpy(p->eth + 8, &inet6_ll_mac_addr, sizeof(inet6_ll_mac_addr));
p->eth[14] = (EthType_Ipv6 >> 8) & 0xFF;
p->eth[15] = EthType_Ipv6 & 0xFF;
@@ -256,7 +257,7 @@
p->ipv6.length = htonw(length);
p->ipv6.next_header = type;
p->ipv6.hop_limit = 255;
- memcpy(p->ipv6.src, &ll_ipv6_addr, sizeof(Ipv6Address));
+ memcpy(p->ipv6.src, &inet6_ll_ip_addr, sizeof(Ipv6Address));
memcpy(p->ipv6.dst, daddr, sizeof(Ipv6Address));
return 0;
@@ -357,7 +358,7 @@
return ret;
}
-void _udpv6_recv(Ipv6Hdr *ip, void *_data, size_t len)
+static void _udpv6_recv(Ipv6Hdr *ip, void *_data, size_t len)
{
UdpHdr *udp = _data;
uint16_t sum, n;
@@ -403,7 +404,7 @@
uint8_t options[0];
} NdpNHdr;
-void icmpv6_recv(NetDevice *dev, Ipv6Hdr *ip, void *_data, size_t len)
+static void icmpv6_recv(NetDevice *dev, Ipv6Hdr *ip, void *_data, size_t len)
{
Icmp6Hdr *icmp = _data;
if (icmp->checksum == 0)
@@ -427,17 +428,18 @@
printf("error: Bogus NDP Message\n");
if (ndp->code != 0)
printf("error: Bogus NDP Code\n");
- if (memcmp(ndp->target, &ll_ipv6_addr, Ipv6_AddrLen))
+ if (memcmp(ndp->target, &inet6_ll_ip_addr, Ipv6_AddrLen))
printf("error: NDP Not For Me\n");
msg.hdr.type = Icmpv6_NdpNAdvertise;
msg.hdr.code = 0;
msg.hdr.checksum = 0;
msg.hdr.flags = 0x60; // (S)olicited and (O)verride flags.
- memcpy(msg.hdr.target, &ll_ipv6_addr, Ipv6_AddrLen);
+ memcpy(msg.hdr.target, &inet6_ll_ip_addr, Ipv6_AddrLen);
msg.opt[0] = NdpNTgtLlAddr;
msg.opt[1] = 1;
- memcpy(msg.opt + 2, &ll_mac_addr, sizeof(ll_mac_addr));
+ memcpy(msg.opt + 2, &inet6_ll_mac_addr,
+ sizeof(inet6_ll_mac_addr));
icmpv6_send(dev, (void *)ip->src, &msg, sizeof(msg));
return;
@@ -477,14 +479,15 @@
len = n;
// Require that we are the destination.
- if (memcmp(&ll_ipv6_addr, ip->dst, Ipv6_AddrLen) &&
- memcmp(&snm_ipv6_addr, ip->dst, Ipv6_AddrLen)) {
+ if (memcmp(&inet6_ll_ip_addr, ip->dst, Ipv6_AddrLen) &&
+ memcmp(&inet6_snm_ip_addr, ip->dst, Ipv6_AddrLen)) {
return 1;
}
// Stash the sender's info to simplify replies.
- memcpy(&rx_mac_addr, (uint8_t *)_data + 6, sizeof(rx_mac_addr));
- memcpy(&rx_ipv6_addr, ip->src, Ipv6_AddrLen);
+ memcpy(&inet6_rx_mac_addr, (uint8_t *)_data + 6,
+ sizeof(inet6_rx_mac_addr));
+ memcpy(&inet6_rx_ip_addr, ip->src, Ipv6_AddrLen);
if (ip->next_header == HdrIcmpv6) {
icmpv6_recv(dev, ip, data, len);