Changes in uspace/srv/net/ethip/arp.c [02a09ed:69a93df7] in mainline
- File:
-
- 1 edited
-
uspace/srv/net/ethip/arp.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/ethip/arp.c
r02a09ed r69a93df7 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 { 57 log_msg(LOG_DEFAULT, LVL_DEBUG, "arp_received()"); 58 56 int rc; 59 57 arp_eth_packet_t packet; 60 int rc = arp_pdu_decode(frame->data, frame->size, &packet); 58 arp_eth_packet_t reply; 59 ethip_link_addr_t *laddr; 60 61 log_msg(LVL_DEBUG, "arp_received()"); 62 63 rc = arp_pdu_decode(frame->data, frame->size, &packet); 61 64 if (rc != EOK) 62 65 return; 63 64 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); 66 67 log_msg(LVL_DEBUG, "ARP PDU decoded, opcode=%d, tpa=%x", 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(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 int rc = atrans_lookup(ip_addr, mac_addr); 92 int rc; 93 arp_eth_packet_t packet; 94 95 rc = atrans_lookup(ip_addr, mac_addr); 101 96 if (rc == EOK) 102 97 return EOK; 103 104 arp_eth_packet_t packet; 105 98 106 99 packet.opcode = aop_request; 107 addr48(nic->mac_addr, packet.sender_hw_addr);108 packet.sender_proto_addr = src_addr;109 addr48(addr48_broadcast, packet.target_hw_addr);110 packet.target_proto_addr = ip_addr;111 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 112 105 rc = arp_send_packet(nic, &packet); 113 106 if (rc != EOK) 114 107 return rc; 115 108 116 109 (void) atrans_wait_timeout(ARP_REQUEST_TIMEOUT); 117 110 118 111 return atrans_lookup(ip_addr, mac_addr); 119 112 } … … 129 122 size_t fsize; 130 123 131 log_msg(L OG_DEFAULT, LVL_DEBUG, "arp_send_packet()");124 log_msg(LVL_DEBUG, "arp_send_packet()"); 132 125 133 126 rc = arp_pdu_encode(packet, &pdata, &psize); … … 135 128 return rc; 136 129 137 addr48(packet->target_hw_addr, frame.dest);138 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; 139 132 frame.etype_len = ETYPE_ARP; 140 133 frame.data = pdata;
Note:
See TracChangeset
for help on using the changeset viewer.
