示例#1
0
static int
arp_find(Conn_t *conn)
{
  Reg_t *tmp;
  Lecdb_t *ltmp;
  
  Debug_unit(&conn_unit, "Arp_find called");
  dump_conn(conn);

  Debug_unit(&conn_unit,"Arping for:");
  dump_addr(&control_packet->target);
  dump_printf(EL_CONT,"\n");

  /* If requested multicast /broadcast address, respond with BUS address */
  if (is_multicast(&control_packet->target)) {
    tmp = mem_alloc(&conn_unit, sizeof(Reg_t));
    memcpy(&tmp->atm_address, get_var_addr(&conn_unit, "S6"), 
	   sizeof(AtmAddr_t));
    Debug_unit(&conn_unit,"Arp for multicast address");
    send_arp_response(conn->sfd, control_packet,
		      LE_STATUS_SUCCESS, tmp);
    return 1;
  }

  /* Check lecid */
  ltmp = leciddb_find(control_packet->lecid);
  if (!ltmp) {
    send_arp_response(conn->sfd, control_packet,
		      LE_STATUS_BAD_LECID, NULL);
    return 1;
  }
  tmp = regdb_find_mac(control_packet->target);
  if (tmp) {
    Debug_unit(&conn_unit,"Address in databases");
    /* Send response */
    send_arp_response(conn->sfd, control_packet,
		      LE_STATUS_SUCCESS,
		      tmp);
    return 1;
  }
  forward_arp_request(control_packet, proxylist);
  return 1;
}
示例#2
0
int handle_arp_packet(struct sr_instance * sr, uint8_t * packet, unsigned int len ){

      int res;

      struct sr_arp_hdr *arp_hdr = (struct sr_arp_hdr *)(packet + sizeof(sr_ethernet_hdr_t));
      int arp_op = ntohs(arp_hdr->ar_op);

      /* check to see if the target IP belongs to one of our routers */
      struct sr_if* assoc_iface = validate_ip(sr->if_list, arp_hdr->ar_tip); 

      if (!assoc_iface){
            /* if its not one of ours, ignore it */
            
            return -1;
      }

      if (arp_op == arp_op_request){ 
            /* this is an incoming request */
           

            res = send_arp_response(sr, assoc_iface,  packet,  len);

            if (res != 0){
                  fprintf(stderr, "bad send_arp_response\n");
                  return -1;
            }


      } else if (arp_op == arp_op_reply) { 
            /* this is an incoming reply */
            

            res = handle_arp_reply(sr, packet, len);
            if (res != 0){
               
                  return -1;
            }
      } else { 
            /* bad arp_op type */
          
            return -1;
      }
      return 0;
}