Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/ethip/arp.c

    r02a09ed r69a93df7  
    3838#include <io/log.h>
    3939#include <inet/iplink_srv.h>
    40 #include <inet/addr.h>
    4140#include <stdlib.h>
    42 #include <net/socket_codes.h>
     41
    4342#include "arp.h"
    4443#include "atrans.h"
     
    5554void arp_received(ethip_nic_t *nic, eth_frame_t *frame)
    5655{
    57         log_msg(LOG_DEFAULT, LVL_DEBUG, "arp_received()");
    58        
     56        int rc;
    5957        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);
    6164        if (rc != EOK)
    6265                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                }
    9486        }
    9587}
    9688
    97 int arp_translate(ethip_nic_t *nic, addr32_t src_addr, addr32_t ip_addr,
    98     addr48_t mac_addr)
     89int arp_translate(ethip_nic_t *nic, iplink_srv_addr_t *src_addr,
     90    iplink_srv_addr_t *ip_addr, mac48_addr_t *mac_addr)
    9991{
    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);
    10196        if (rc == EOK)
    10297                return EOK;
    103        
    104         arp_eth_packet_t packet;
    105        
     98
    10699        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
    112105        rc = arp_send_packet(nic, &packet);
    113106        if (rc != EOK)
    114107                return rc;
    115        
     108
    116109        (void) atrans_wait_timeout(ARP_REQUEST_TIMEOUT);
    117        
     110
    118111        return atrans_lookup(ip_addr, mac_addr);
    119112}
     
    129122        size_t fsize;
    130123
    131         log_msg(LOG_DEFAULT, LVL_DEBUG, "arp_send_packet()");
     124        log_msg(LVL_DEBUG, "arp_send_packet()");
    132125
    133126        rc = arp_pdu_encode(packet, &pdata, &psize);
     
    135128                return rc;
    136129
    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;
    139132        frame.etype_len = ETYPE_ARP;
    140133        frame.data = pdata;
Note: See TracChangeset for help on using the changeset viewer.