35 #include "ip64/ip64.h" 36 #include "ip64/ip64-eth.h" 37 #include "ip64/ip64-arp.h" 87 #define ARP_HWTYPE_ETH 1 96 {{0xff,0xff,0xff,0xff,0xff,0xff}};
100 static uint8_t arptime;
101 static uint8_t tmpage;
106 #define PRINTF(...) printf(__VA_ARGS__) 111 const uip_ipaddr_t uip_all_zeroes_addr;
124 memset(&arp_table[i].
ipaddr, 0, 4);
140 struct arp_entry *tabptr;
145 tabptr = &arp_table[i];
148 memset(&tabptr->ipaddr, 0, 4);
158 register struct arp_entry *tabptr = arp_table;
165 tabptr = &arp_table[i];
175 memcpy(tabptr->ethaddr.addr, ethaddr->addr, 6);
176 tabptr->time = arptime;
189 tabptr = &arp_table[i];
197 if(i == UIP_ARPTAB_SIZE) {
201 tabptr = &arp_table[i];
202 if(arptime - tabptr->time > tmpage) {
203 tmpage = arptime - tabptr->time;
208 tabptr = &arp_table[i];
213 uip_ip4addr_copy(&tabptr->ipaddr, ipaddr);
214 memcpy(tabptr->ethaddr.addr, ethaddr->addr, 6);
215 tabptr->time = arptime;
219 ip64_arp_arp_input(
const uint8_t *packet, uint16_t packet_len)
221 struct arp_hdr *arphdr = (
struct arp_hdr *)packet;
223 if(packet_len <
sizeof(
struct arp_hdr)) {
224 printf(
"ip64_arp_arp_input: len too small %d\n", packet_len);
228 switch(arphdr->opcode) {
232 printf(
"ip64_arp_arp_input: request for %d.%d.%d.%d (we are %d.%d.%d.%d)\n",
233 arphdr->dipaddr.u8[0], arphdr->dipaddr.u8[1],
234 arphdr->dipaddr.u8[2], arphdr->dipaddr.u8[3],
235 ip64_get_hostaddr()->u8[0], ip64_get_hostaddr()->u8[1],
236 ip64_get_hostaddr()->u8[2], ip64_get_hostaddr()->u8[3]);
241 arp_update(&arphdr->sipaddr, &arphdr->shwaddr);
245 memcpy(arphdr->dhwaddr.addr, arphdr->shwaddr.addr, 6);
248 memcpy(arphdr->ethhdr.dest.addr, arphdr->dhwaddr.addr, 6);
250 uip_ip4addr_copy(&arphdr->dipaddr, &arphdr->sipaddr);
251 uip_ip4addr_copy(&arphdr->sipaddr, ip64_get_hostaddr());
253 arphdr->ethhdr.type =
UIP_HTONS(IP64_ETH_TYPE_ARP);
254 return sizeof(
struct arp_hdr);
261 arp_update(&arphdr->sipaddr, &arphdr->shwaddr);
270 ip64_arp_check_cache(
const uint8_t *nlhdr)
272 struct ipv4_hdr *ipv4_hdr = (
struct ipv4_hdr *)nlhdr;
274 struct arp_entry *tabptr = arp_table;
276 printf(
"check cache %d.%d.%d.%d\n",
282 printf(
"Return 1\n");
284 }
else if(ipv4_hdr->destipaddr.u8[0] == 224) {
293 ip64_get_netmask())) {
297 uip_ip4addr_copy(&ipaddr, ip64_get_draddr());
300 uip_ip4addr_copy(&ipaddr, &ipv4_hdr->destipaddr);
309 if(i == UIP_ARPTAB_SIZE) {
318 ip64_arp_create_ethhdr(uint8_t *llhdr,
const uint8_t *nlhdr)
320 struct arp_entry *tabptr = arp_table;
321 struct ipv4_hdr *ipv4_hdr = (
struct ipv4_hdr *)nlhdr;
335 memcpy(ðhdr->dest.addr, &broadcast_ethaddr.addr, 6);
336 }
else if(ipv4_hdr->destipaddr.u8[0] == 224) {
338 ethhdr->dest.addr[0] = 0x01;
339 ethhdr->dest.addr[1] = 0x00;
340 ethhdr->dest.addr[2] = 0x5e;
341 ethhdr->dest.addr[3] = ipv4_hdr->destipaddr.u8[1];
342 ethhdr->dest.addr[4] = ipv4_hdr->destipaddr.u8[2];
343 ethhdr->dest.addr[5] = ipv4_hdr->destipaddr.u8[3];
350 ip64_get_netmask())) {
354 uip_ip4addr_copy(&ipaddr, ip64_get_draddr());
357 uip_ip4addr_copy(&ipaddr, &ipv4_hdr->destipaddr);
366 if(i == UIP_ARPTAB_SIZE) {
370 memcpy(ethhdr->dest.addr, tabptr->ethaddr.addr, 6);
375 ethhdr->type =
UIP_HTONS(IP64_ETH_TYPE_IP);
380 ip64_arp_create_arp_request(uint8_t *llhdr,
const uint8_t *nlhdr)
382 struct ipv4_hdr *ipv4_hdr = (
struct ipv4_hdr *)nlhdr;
383 struct arp_hdr *arp_hdr = (
struct arp_hdr *)llhdr;
388 ip64_get_netmask())) {
392 uip_ip4addr_copy(&ipaddr, ip64_get_draddr());
395 uip_ip4addr_copy(&ipaddr, &ipv4_hdr->destipaddr);
398 memset(arp_hdr->ethhdr.dest.addr, 0xff, 6);
399 memset(arp_hdr->dhwaddr.addr, 0x00, 6);
403 uip_ip4addr_copy(&arp_hdr->dipaddr, &ipaddr);
404 uip_ip4addr_copy(&arp_hdr->sipaddr, ip64_get_hostaddr());
405 arp_hdr->opcode =
UIP_HTONS(ARP_REQUEST);
406 arp_hdr->hwtype =
UIP_HTONS(ARP_HWTYPE_ETH);
407 arp_hdr->protocol =
UIP_HTONS(IP64_ETH_TYPE_IP);
409 arp_hdr->protolen = 4;
410 arp_hdr->ethhdr.type =
UIP_HTONS(IP64_ETH_TYPE_ARP);
414 return sizeof(
struct arp_hdr);
#define uip_ip4addr_cmp(addr1, addr2)
Compare two IP addresses.
#define UIP_ARP_MAXAGE
The maximum age of ARP table entries measured in 10ths of seconds.
static uip_ipaddr_t ipaddr
Pointer to prefix information option in uip_buf.
#define uip_ipaddr_maskcmp(addr1, addr2, mask)
Compare two IP addresses with netmasks.
#define uip_ipaddr_to_quad(a)
Convert an IP address to four bytes separated by commas.
Representation of an IP address.
#define uip_ipaddr(addr, addr0, addr1, addr2, addr3)
Construct an IP address from four bytes.
#define UIP_LLH_LEN
The link level header length.
#define uip_buf
Macro to access uip_aligned_buf as an array of bytes.
#define UIP_HTONS(n)
Convert 16-bit quantity from host byte order to network byte order.
#define UIP_ARPTAB_SIZE
The size of the ARP table.
void * uip_appdata
Pointer to the application data in the packet buffer.