Changes in uspace/srv/net/ethip/arp.c [695b6ff:a1a101d] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/ethip/arp.c
r695b6ff ra1a101d 38 38 #include <io/log.h> 39 39 #include <inet/iplink_srv.h> 40 #include <inet/addr.h>41 40 #include <stdlib.h> 42 #include <net/socket_codes.h> 41 43 42 #include "arp.h" 44 43 #include "atrans.h" … … 55 54 void arp_received(ethip_nic_t *nic, eth_frame_t *frame) 56 55 { 56 int rc; 57 arp_eth_packet_t packet; 58 arp_eth_packet_t reply; 59 ethip_link_addr_t *laddr; 60 57 61 log_msg(LOG_DEFAULT, LVL_DEBUG, "arp_received()"); 58 59 arp_eth_packet_t packet; 60 int rc = arp_pdu_decode(frame->data, frame->size, &packet); 62 63 rc = arp_pdu_decode(frame->data, frame->size, &packet); 61 64 if (rc != EOK) 62 65 return; 63 66 64 67 log_msg(LOG_DEFAULT, LVL_DEBUG, "ARP PDU decoded, opcode=%d, tpa=%x", 65 packet.opcode, packet.target_proto_addr); 66 67 inet_addr_t addr; 68 inet_addr_set(packet.target_proto_addr, &addr); 69 70 ethip_link_addr_t *laddr = ethip_nic_addr_find(nic, &addr); 71 if (laddr == NULL) 72 return; 73 74 addr32_t laddr_v4; 75 uint16_t laddr_af = inet_addr_get(&laddr->addr, &laddr_v4, NULL); 76 if (laddr_af != AF_INET) 77 return; 78 79 log_msg(LOG_DEFAULT, LVL_DEBUG, "Request/reply to my address"); 80 81 (void) atrans_add(packet.sender_proto_addr, 82 packet.sender_hw_addr); 83 84 if (packet.opcode == aop_request) { 85 arp_eth_packet_t reply; 86 87 reply.opcode = aop_reply; 88 addr48(nic->mac_addr, reply.sender_hw_addr); 89 reply.sender_proto_addr = laddr_v4; 90 addr48(packet.sender_hw_addr, reply.target_hw_addr); 91 reply.target_proto_addr = packet.sender_proto_addr; 92 93 arp_send_packet(nic, &reply); 68 packet.opcode, packet.target_proto_addr.ipv4); 69 70 laddr = ethip_nic_addr_find(nic, &packet.target_proto_addr); 71 if (laddr != NULL) { 72 log_msg(LOG_DEFAULT, LVL_DEBUG, "Request/reply to my address"); 73 74 (void) atrans_add(&packet.sender_proto_addr, 75 &packet.sender_hw_addr); 76 77 if (packet.opcode == aop_request) { 78 reply.opcode = aop_reply; 79 reply.sender_hw_addr = nic->mac_addr; 80 reply.sender_proto_addr = laddr->addr; 81 reply.target_hw_addr = packet.sender_hw_addr; 82 reply.target_proto_addr = packet.sender_proto_addr; 83 84 arp_send_packet(nic, &reply); 85 } 94 86 } 95 87 } 96 88 97 int arp_translate(ethip_nic_t *nic, addr32_t src_addr, addr32_t ip_addr,98 addr48_tmac_addr)89 int arp_translate(ethip_nic_t *nic, iplink_srv_addr_t *src_addr, 90 iplink_srv_addr_t *ip_addr, mac48_addr_t *mac_addr) 99 91 { 100 /* Broadcast address */ 101 if (ip_addr == addr32_broadcast_all_hosts) { 102 addr48(addr48_broadcast, mac_addr); 103 return EOK; 104 } 92 int rc; 93 arp_eth_packet_t packet; 105 94 106 intrc = atrans_lookup(ip_addr, mac_addr);95 rc = atrans_lookup(ip_addr, mac_addr); 107 96 if (rc == EOK) 108 97 return EOK; 109 110 arp_eth_packet_t packet; 111 98 112 99 packet.opcode = aop_request; 113 addr48(nic->mac_addr, packet.sender_hw_addr);114 packet.sender_proto_addr = src_addr;115 addr48(addr48_broadcast, packet.target_hw_addr);116 packet.target_proto_addr = ip_addr;117 100 packet.sender_hw_addr = nic->mac_addr; 101 packet.sender_proto_addr = *src_addr; 102 packet.target_hw_addr.addr = MAC48_BROADCAST; 103 packet.target_proto_addr = *ip_addr; 104 118 105 rc = arp_send_packet(nic, &packet); 119 106 if (rc != EOK) 120 107 return rc; 121 108 122 109 (void) atrans_wait_timeout(ARP_REQUEST_TIMEOUT); 123 110 124 111 return atrans_lookup(ip_addr, mac_addr); 125 112 } … … 141 128 return rc; 142 129 143 addr48(packet->target_hw_addr, frame.dest);144 addr48(packet->sender_hw_addr, frame.src);130 frame.dest.addr = packet->target_hw_addr.addr; 131 frame.src.addr = packet->sender_hw_addr.addr; 145 132 frame.etype_len = ETYPE_ARP; 146 133 frame.data = pdata;
Note:
See TracChangeset
for help on using the changeset viewer.