"Fossies" - the Fresh Open Source Software Archive

Member "open-iscsi-2.1.0/iscsiuio/src/uip/uip_arp.h" (14 Nov 2019, 6096 Bytes) of package /linux/misc/open-iscsi-2.1.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "uip_arp.h" see the Fossies "Dox" file reference documentation.

    1 /**
    2  * \addtogroup uip
    3  * @{
    4  */
    5 
    6 /**
    7  * \addtogroup uiparp
    8  * @{
    9  */
   10 
   11 /**
   12  * \file
   13  * Macros and definitions for the ARP module.
   14  * \author Adam Dunkels <adam@dunkels.com>
   15  */
   16 
   17 /*
   18  * Copyright (c) 2001-2003, Adam Dunkels.
   19  * All rights reserved.
   20  *
   21  * Redistribution and use in source and binary forms, with or without
   22  * modification, are permitted provided that the following conditions
   23  * are met:
   24  * 1. Redistributions of source code must retain the above copyright
   25  *    notice, this list of conditions and the following disclaimer.
   26  * 2. Redistributions in binary form must reproduce the above copyright
   27  *    notice, this list of conditions and the following disclaimer in the
   28  *    documentation and/or other materials provided with the distribution.
   29  * 3. The name of the author may not be used to endorse or promote
   30  *    products derived from this software without specific prior
   31  *    written permission.
   32  *
   33  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
   34  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
   35  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   36  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
   37  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   38  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
   39  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   40  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
   41  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
   42  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
   43  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   44  *
   45  * This file is part of the uIP TCP/IP stack.
   46  *
   47  *
   48  */
   49 
   50 #ifndef __UIP_ARP_H__
   51 #define __UIP_ARP_H__
   52 
   53 #include "packet.h"
   54 #include "uip.h"
   55 #include "uip_eth.h"
   56 
   57 #define ARP_REQUEST 1
   58 #define ARP_REPLY   2
   59 
   60 #define ARP_HWTYPE_ETH 1
   61 
   62 struct __attribute__ ((__packed__)) arp_hdr {
   63     u16_t hwtype;
   64     u16_t protocol;
   65     u8_t hwlen;
   66     u8_t protolen;
   67     u16_t opcode;
   68     struct uip_eth_addr shwaddr;
   69     u16_t sipaddr[2];
   70     struct uip_eth_addr dhwaddr;
   71     u16_t dipaddr[2];
   72 };
   73 
   74 struct __attribute__ ((__packed__)) ip_hdr {
   75     /* IP header. */
   76     u8_t vhl, tos, len[2], ipid[2], ipoffset[2], ttl, proto;
   77     u16_t ipchksum;
   78     u16_t srcipaddr[2], destipaddr[2];
   79 };
   80 
   81 struct __attribute__ ((__packed__)) ethip_hdr {
   82     struct uip_eth_hdr ethhdr;
   83     /* IP header. */
   84     u8_t vhl, tos, len[2], ipid[2], ipoffset[2], ttl, proto;
   85     u16_t ipchksum;
   86     u16_t srcipaddr[2], destipaddr[2];
   87 };
   88 
   89 struct arp_entry {
   90     u16_t ipaddr[2];
   91     struct uip_eth_addr ethaddr;
   92     u8_t time;
   93 };
   94 
   95 /* The uip_arp_init() function must be called before any of the other
   96    ARP functions. */
   97 void uip_arp_init(void);
   98 
   99 /* The uip_arp_ipin() function should be called whenever an IP packet
  100    arrives from the Ethernet. This function refreshes the ARP table or
  101    inserts a new mapping if none exists. The function assumes that an
  102    IP packet with an Ethernet header is present in the uip_buf buffer
  103    and that the length of the packet is in the uip_len variable. */
  104 /*void uip_arp_ipin(void);*/
  105 /* #define uip_arp_ipin() */
  106 void uip_arp_ipin(struct uip_stack *ustack, struct packet *pkt);
  107 
  108 /* The uip_arp_arpin() should be called when an ARP packet is received
  109    by the Ethernet driver. This function also assumes that the
  110    Ethernet frame is present in the uip_buf buffer. When the
  111    uip_arp_arpin() function returns, the contents of the uip_buf
  112    buffer should be sent out on the Ethernet if the uip_len variable
  113    is > 0. */
  114 void uip_arp_arpin(nic_interface_t *nic_iface,
  115            struct uip_stack *ustack, struct packet *pkt);
  116 
  117 typedef enum {
  118     ARP_SENT = 1,
  119     ETH_HEADER_APPEDEND = 2,
  120 } arp_out_t;
  121 
  122 typedef enum {
  123     LOCAL_BROADCAST = 1,
  124     NONLOCAL_BROADCAST = 2,
  125 } dest_ipv4_addr_t;
  126 
  127 typedef enum {
  128     IS_IN_ARP_TABLE = 1,
  129     NOT_IN_ARP_TABLE = 2,
  130 } arp_table_query_t;
  131 
  132 dest_ipv4_addr_t
  133 uip_determine_dest_ipv4_addr(struct uip_stack *ustack, u16_t *ipaddr);
  134 arp_out_t is_in_arp_table(u16_t *ipaddr, struct arp_entry **tabptr);
  135 
  136 void uip_build_arp_request(struct uip_stack *ustack, u16_t *ipaddr);
  137 
  138 void
  139 uip_build_eth_header(struct uip_stack *ustack,
  140              u16_t *ipaddr,
  141              struct arp_entry *tabptr,
  142              struct packet *pkt, u16_t vlan_id);
  143 
  144 /* The uip_arp_out() function should be called when an IP packet
  145    should be sent out on the Ethernet. This function creates an
  146    Ethernet header before the IP header in the uip_buf buffer. The
  147    Ethernet header will have the correct Ethernet MAC destination
  148    address filled in if an ARP table entry for the destination IP
  149    address (or the IP address of the default router) is present. If no
  150    such table entry is found, the IP packet is overwritten with an ARP
  151    request and we rely on TCP to retransmit the packet that was
  152    overwritten. In any case, the uip_len variable holds the length of
  153    the Ethernet frame that should be transmitted. */
  154 arp_out_t uip_arp_out(struct uip_stack *ustack);
  155 
  156 /* The uip_arp_timer() function should be called every ten seconds. It
  157    is responsible for flushing old entries in the ARP table. */
  158 void uip_arp_timer(void);
  159 
  160 int uip_lookup_arp_entry(uint32_t ip_addr, uint8_t *mac_addr);
  161 
  162 /** @} */
  163 
  164 /**
  165  * \addtogroup uipconffunc
  166  * @{
  167  */
  168 
  169 /**
  170  * Specifiy the Ethernet MAC address.
  171  *
  172  * The ARP code needs to know the MAC address of the Ethernet card in
  173  * order to be able to respond to ARP queries and to generate working
  174  * Ethernet headers.
  175  *
  176  * \note This macro only specifies the Ethernet MAC address to the ARP
  177  * code. It cannot be used to change the MAC address of the Ethernet
  178  * card.
  179  *
  180  * \param eaddr A pointer to a struct uip_eth_addr containing the
  181  * Ethernet MAC address of the Ethernet card.
  182  *
  183  * \hideinitializer
  184  */
  185 #define uip_setethaddr(eaddr)   do {                         \
  186                     uip_ethaddr.addr[0] = eaddr.addr[0]; \
  187                     uip_ethaddr.addr[1] = eaddr.addr[1]; \
  188                     uip_ethaddr.addr[2] = eaddr.addr[2]; \
  189                     uip_ethaddr.addr[3] = eaddr.addr[3]; \
  190                     uip_ethaddr.addr[4] = eaddr.addr[4]; \
  191                     uip_ethaddr.addr[5] = eaddr.addr[5]; \
  192                 } while (0)
  193 
  194 /** @} */
  195 /** @} */
  196 
  197 #endif /* __UIP_ARP_H__ */