Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 3d016ac in mainline


Ignore:
Timestamp:
2012-03-07T18:54:08Z (10 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master
Children:
0e25780
Parents:
f9d3dd4
Message:

Prototype sending of ARP requests.

Location:
uspace/srv/ethip
Files:
6 edited

Legend:

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

    rf9d3dd4 r3d016ac  
    4747#include "std.h"
    4848
     49/** Time to wait for ARP reply in microseconds */
     50#define ARP_REQUEST_TIMEOUT (3 * 1000 * 1000)
     51
    4952static int arp_send_packet(ethip_nic_t *nic, arp_eth_packet_t *packet);
    5053
     
    6467        log_msg(LVL_DEBUG, "ARP PDU decoded, opcode=%d, tpa=%x",
    6568            packet.opcode, packet.target_proto_addr.ipv4);
    66         if (packet.opcode == aop_request) {
    67                 log_msg(LVL_DEBUG, "ARP request");
    6869
    69                 laddr = ethip_nic_addr_find(nic, &packet.target_proto_addr);
    70                 if (laddr != NULL) {
    71                         log_msg(LVL_DEBUG, "Request on my address");
     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");
    7273
    73                         (void) atrans_add(&packet.sender_proto_addr,
    74                             &packet.sender_hw_addr);
     74                (void) atrans_add(&packet.sender_proto_addr,
     75                    &packet.sender_hw_addr);
    7576
    76                         reply.opcode = aop_reply;
    77                         reply.sender_hw_addr = nic->mac_addr;
     77                if (packet.opcode == aop_request) {
     78                        reply.opcode = aop_reply;
     79                        reply.sender_hw_addr = nic->mac_addr;
    7880                        reply.sender_proto_addr = laddr->addr;
    7981                        reply.target_hw_addr = packet.sender_hw_addr;
     
    8385                }
    8486        }
     87}
     88
     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)
     91{
     92        int rc;
     93        arp_eth_packet_t packet;
     94
     95        rc = atrans_lookup(ip_addr, mac_addr);
     96        if (rc == EOK)
     97                return EOK;
     98
     99        packet.opcode = aop_request;
     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
     105        rc = arp_send_packet(nic, &packet);
     106        if (rc != EOK)
     107                return rc;
     108
     109        (void) atrans_wait_timeout(ARP_REQUEST_TIMEOUT);
     110
     111        return atrans_lookup(ip_addr, mac_addr);
    85112}
    86113
  • uspace/srv/ethip/arp.h

    rf9d3dd4 r3d016ac  
    4242
    4343extern void arp_received(ethip_nic_t *, eth_frame_t *);
     44extern int arp_translate(ethip_nic_t *, iplink_srv_addr_t *,
     45    iplink_srv_addr_t *, mac48_addr_t *);
    4446
    4547#endif
  • uspace/srv/ethip/atrans.c

    rf9d3dd4 r3d016ac  
    4747static FIBRIL_MUTEX_INITIALIZE(atrans_list_lock);
    4848static LIST_INITIALIZE(atrans_list);
     49static FIBRIL_CONDVAR_INITIALIZE(atrans_cv);
    4950
    5051static ethip_atrans_t *atrans_find(iplink_srv_addr_t *ip_addr)
     
    8283        list_append(&atrans->atrans_list, &atrans_list);
    8384        fibril_mutex_unlock(&atrans_list_lock);
     85        fibril_condvar_broadcast(&atrans_cv);
    8486
    8587        return EOK;
     
    120122}
    121123
     124int atrans_wait_timeout(suseconds_t timeout)
     125{
     126        int rc;
     127
     128        fibril_mutex_lock(&atrans_list_lock);
     129        rc = fibril_condvar_wait_timeout(&atrans_cv, &atrans_list_lock,
     130            timeout);
     131        fibril_mutex_unlock(&atrans_list_lock);
     132
     133        return rc;
     134}
     135
    122136/** @}
    123137 */
  • uspace/srv/ethip/atrans.h

    rf9d3dd4 r3d016ac  
    4444extern int atrans_remove(iplink_srv_addr_t *);
    4545extern int atrans_lookup(iplink_srv_addr_t *, mac48_addr_t *);
     46extern int atrans_wait_timeout(suseconds_t);
    4647
    4748#endif
  • uspace/srv/ethip/ethip.c

    rf9d3dd4 r3d016ac  
    4646
    4747#include "arp.h"
    48 #include "atrans.h"
    4948#include "ethip.h"
    5049#include "ethip_nic.h"
     
    178177        log_msg(LVL_DEBUG, "ethip_send()");
    179178
    180         rc = atrans_lookup(&sdu->ldest, &dest_mac_addr);
     179        rc = arp_translate(nic, &sdu->lsrc, &sdu->ldest, &dest_mac_addr);
    181180        if (rc != EOK) {
    182181                log_msg(LVL_WARN, "Failed to look up IP address 0x%" PRIx32,
  • uspace/srv/ethip/ethip.h

    rf9d3dd4 r3d016ac  
    4343#include <loc.h>
    4444#include <sys/types.h>
     45
     46#define MAC48_BROADCAST 0xffffffffffff
    4547
    4648typedef struct {
Note: See TracChangeset for help on using the changeset viewer.