You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

if_arp.h 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #ifndef _IPXE_IF_ARP_H
  2. #define _IPXE_IF_ARP_H
  3. /** @file
  4. *
  5. * Address Resolution Protocol constants and types
  6. *
  7. */
  8. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  9. #include <stdint.h>
  10. /* ARP protocol HARDWARE identifiers. */
  11. #define ARPHRD_NETROM 0 /**< from KA9Q: NET/ROM pseudo */
  12. #define ARPHRD_ETHER 1 /**< Ethernet 10Mbps */
  13. #define ARPHRD_EETHER 2 /**< Experimental Ethernet */
  14. #define ARPHRD_AX25 3 /**< AX.25 Level 2 */
  15. #define ARPHRD_PRONET 4 /**< PROnet token ring */
  16. #define ARPHRD_CHAOS 5 /**< Chaosnet */
  17. #define ARPHRD_IEEE802 6 /**< IEEE 802.2 Ethernet/TR/TB */
  18. #define ARPHRD_ARCNET 7 /**< ARCnet */
  19. #define ARPHRD_APPLETLK 8 /**< APPLEtalk */
  20. #define ARPHRD_DLCI 15 /**< Frame Relay DLCI */
  21. #define ARPHRD_ATM 19 /**< ATM */
  22. #define ARPHRD_METRICOM 23 /**< Metricom STRIP (new IANA id) */
  23. #define ARPHRD_IEEE1394 24 /**< IEEE 1394 IPv4 - RFC 2734 */
  24. #define ARPHRD_EUI64 27 /**< EUI-64 */
  25. #define ARPHRD_INFINIBAND 32 /**< InfiniBand */
  26. /* ARP protocol opcodes. */
  27. #define ARPOP_REQUEST 1 /**< ARP request */
  28. #define ARPOP_REPLY 2 /**< ARP reply */
  29. #define ARPOP_RREQUEST 3 /**< RARP request */
  30. #define ARPOP_RREPLY 4 /**< RARP reply */
  31. #define ARPOP_InREQUEST 8 /**< InARP request */
  32. #define ARPOP_InREPLY 9 /**< InARP reply */
  33. #define ARPOP_NAK 10 /**< (ATM)ARP NAK */
  34. /**
  35. * An ARP header
  36. *
  37. * This contains only the fixed-size portions of an ARP header; for
  38. * other fields use the arp_{sender,target}_{ha,pa} family of
  39. * functions.
  40. */
  41. struct arphdr {
  42. /** Link-layer protocol
  43. *
  44. * This is an ARPHRD_XXX constant
  45. */
  46. uint16_t ar_hrd;
  47. /** Network-layer protocol
  48. *
  49. * This is, for Ethernet, an ETH_P_XXX constant.
  50. */
  51. uint16_t ar_pro;
  52. /** Link-layer address length */
  53. uint8_t ar_hln;
  54. /** Network-layer address length */
  55. uint8_t ar_pln;
  56. /** ARP opcode */
  57. uint16_t ar_op;
  58. } __attribute__ (( packed ));
  59. /** ARP packet sender hardware address
  60. *
  61. * @v arphdr ARP header
  62. * @ret ar_sha Sender hardware address
  63. */
  64. static inline void * arp_sender_ha ( struct arphdr *arphdr ) {
  65. return ( ( ( void * ) arphdr ) + sizeof ( *arphdr ) );
  66. }
  67. /** ARP packet sender protocol address
  68. *
  69. * @v arphdr ARP header
  70. * @ret ar_spa Sender protocol address
  71. */
  72. static inline void * arp_sender_pa ( struct arphdr *arphdr ) {
  73. return ( arp_sender_ha ( arphdr ) + arphdr->ar_hln );
  74. }
  75. /** ARP packet target hardware address
  76. *
  77. * @v arphdr ARP header
  78. * @ret ar_tha Target hardware address
  79. */
  80. static inline void * arp_target_ha ( struct arphdr *arphdr ) {
  81. return ( arp_sender_pa ( arphdr ) + arphdr->ar_pln );
  82. }
  83. /** ARP packet target protocol address
  84. *
  85. * @v arphdr ARP header
  86. * @ret ar_tpa Target protocol address
  87. */
  88. static inline void * arp_target_pa ( struct arphdr *arphdr ) {
  89. return ( arp_target_ha ( arphdr ) + arphdr->ar_hln );
  90. }
  91. /** ARP packet length
  92. *
  93. * @v arphdr ARP header
  94. * @ret len Length (including header)
  95. */
  96. static inline size_t arp_len ( struct arphdr *arphdr ) {
  97. return ( sizeof ( *arphdr ) +
  98. ( 2 * ( arphdr->ar_hln + arphdr->ar_pln ) ) );
  99. }
  100. #endif /* _IPXE_IF_ARP_H */