ip.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 2010,2011 Free Software Foundation, Inc.
  4. *
  5. * GRUB is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * GRUB is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef GRUB_NET_IP_HEADER
  19. #define GRUB_NET_IP_HEADER 1
  20. #include <grub/misc.h>
  21. #include <grub/net.h>
  22. typedef enum grub_net_ip_protocol
  23. {
  24. GRUB_NET_IP_ICMP = 1,
  25. GRUB_NET_IP_TCP = 6,
  26. GRUB_NET_IP_UDP = 17,
  27. GRUB_NET_IP_ICMPV6 = 58
  28. } grub_net_ip_protocol_t;
  29. #define GRUB_NET_IP_BROADCAST 0xFFFFFFFF
  30. static inline grub_uint64_t
  31. grub_net_ipv6_get_id (const grub_net_link_level_address_t *addr)
  32. {
  33. return grub_cpu_to_be64 (((grub_uint64_t) (addr->mac[0] ^ 2) << 56)
  34. | ((grub_uint64_t) addr->mac[1] << 48)
  35. | ((grub_uint64_t) addr->mac[2] << 40)
  36. | 0xfffe000000ULL
  37. | ((grub_uint64_t) addr->mac[3] << 16)
  38. | ((grub_uint64_t) addr->mac[4] << 8)
  39. | ((grub_uint64_t) addr->mac[5]));
  40. }
  41. grub_uint16_t grub_net_ip_chksum(void *ipv, grub_size_t len);
  42. grub_err_t
  43. grub_net_recv_ip_packets (struct grub_net_buff *nb,
  44. struct grub_net_card *card,
  45. const grub_net_link_level_address_t *hwaddress,
  46. const grub_net_link_level_address_t *src_hwaddress,
  47. grub_uint16_t *vlantag);
  48. grub_err_t
  49. grub_net_send_ip_packet (struct grub_net_network_level_interface *inf,
  50. const grub_net_network_level_address_t *target,
  51. const grub_net_link_level_address_t *ll_target_addr,
  52. struct grub_net_buff *nb,
  53. grub_net_ip_protocol_t proto);
  54. grub_err_t
  55. grub_net_recv_icmp_packet (struct grub_net_buff *nb,
  56. struct grub_net_network_level_interface *inf,
  57. const grub_net_link_level_address_t *ll_src,
  58. const grub_net_network_level_address_t *src);
  59. grub_err_t
  60. grub_net_recv_icmp6_packet (struct grub_net_buff *nb,
  61. struct grub_net_card *card,
  62. struct grub_net_network_level_interface *inf,
  63. const grub_net_link_level_address_t *ll_src,
  64. const grub_net_network_level_address_t *source,
  65. const grub_net_network_level_address_t *dest,
  66. grub_uint8_t ttl);
  67. grub_err_t
  68. grub_net_recv_udp_packet (struct grub_net_buff *nb,
  69. struct grub_net_network_level_interface *inf,
  70. const grub_net_network_level_address_t *src);
  71. grub_err_t
  72. grub_net_recv_tcp_packet (struct grub_net_buff *nb,
  73. struct grub_net_network_level_interface *inf,
  74. const grub_net_network_level_address_t *source);
  75. grub_uint16_t
  76. grub_net_ip_transport_checksum (struct grub_net_buff *nb,
  77. grub_uint16_t proto,
  78. const grub_net_network_level_address_t *src,
  79. const grub_net_network_level_address_t *dst);
  80. struct grub_net_network_level_interface *
  81. grub_net_ipv6_get_link_local (struct grub_net_card *card,
  82. const grub_net_link_level_address_t *hwaddr);
  83. grub_err_t
  84. grub_net_icmp6_send_request (struct grub_net_network_level_interface *inf,
  85. const grub_net_network_level_address_t *proto_addr);
  86. grub_err_t
  87. grub_net_icmp6_send_router_solicit (struct grub_net_network_level_interface *inf);
  88. #endif