ndisc.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright (C) 2013 Allied Telesis Labs NZ
  4. * Chris Packham, <judge.packham@gmail.com>
  5. *
  6. * Copyright (C) 2022 YADRO
  7. * Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com>
  8. */
  9. #ifndef __NDISC_H__
  10. #define __NDISC_H__
  11. #include <ndisc.h>
  12. /* struct nd_msg - ICMPv6 Neighbour Discovery message format */
  13. struct nd_msg {
  14. struct icmp6hdr icmph;
  15. struct in6_addr target;
  16. __u8 opt[0];
  17. };
  18. /* struct rs_msg - ICMPv6 Router Solicitation message format */
  19. struct rs_msg {
  20. struct icmp6hdr icmph;
  21. __u8 opt[0];
  22. };
  23. /* struct ra_msg - ICMPv6 Router Advertisement message format */
  24. struct ra_msg {
  25. struct icmp6hdr icmph;
  26. __u32 reachable_time;
  27. __u32 retransmission_timer;
  28. __u8 opt[0];
  29. };
  30. /* struct echo_msg - ICMPv6 echo request/reply message format */
  31. struct echo_msg {
  32. struct icmp6hdr icmph;
  33. __u16 id;
  34. __u16 sequence;
  35. };
  36. /* Neigbour Discovery option types */
  37. enum {
  38. __ND_OPT_PREFIX_INFO_END = 0,
  39. ND_OPT_SOURCE_LL_ADDR = 1,
  40. ND_OPT_TARGET_LL_ADDR = 2,
  41. ND_OPT_PREFIX_INFO = 3,
  42. ND_OPT_REDIRECT_HDR = 4,
  43. ND_OPT_MTU = 5,
  44. __ND_OPT_MAX
  45. };
  46. /* IPv6 destination address of packet waiting for ND */
  47. extern struct in6_addr net_nd_sol_packet_ip6;
  48. /* MAC destination address of packet waiting for ND */
  49. extern uchar *net_nd_packet_mac;
  50. /* pointer to packet waiting to be transmitted after ND is resolved */
  51. extern uchar *net_nd_tx_packet;
  52. /* size of packet waiting to be transmitted */
  53. extern int net_nd_tx_packet_size;
  54. /* the timer for ND resolution */
  55. extern ulong net_nd_timer_start;
  56. /* the number of requests we have sent so far */
  57. extern int net_nd_try;
  58. #ifdef CONFIG_IPV6
  59. /**
  60. * ndisc_init() - Make initial steps for ND state machine.
  61. * Usually move variables into initial state.
  62. */
  63. void ndisc_init(void);
  64. /*
  65. * ip6_send_rs() - Send IPv6 Router Solicitation Message
  66. */
  67. void ip6_send_rs(void);
  68. /**
  69. * ndisc_receive() - Handle ND packet
  70. *
  71. * @et: pointer to incoming packet
  72. * @ip6: pointer to IPv6 header
  73. * @len: incoming packet length
  74. * Return: 0 if handle successfully, -1 if unsupported/unknown ND packet type
  75. */
  76. int ndisc_receive(struct ethernet_hdr *et, struct ip6_hdr *ip6, int len);
  77. /**
  78. * ndisc_request() - Send ND request
  79. */
  80. void ndisc_request(void);
  81. /**
  82. * ndisc_init() - Check ND response timeout
  83. *
  84. * Return: 0 if no timeout, -1 otherwise
  85. */
  86. int ndisc_timeout_check(void);
  87. bool validate_ra(struct ip6_hdr *ip6);
  88. int process_ra(struct ip6_hdr *ip6, int len);
  89. #else
  90. static inline void ndisc_init(void)
  91. {
  92. }
  93. static inline int
  94. ndisc_receive(struct ethernet_hdr *et, struct ip6_hdr *ip6, int len)
  95. {
  96. return -1;
  97. }
  98. static inline void ndisc_request(void)
  99. {
  100. }
  101. static inline int ndisc_timeout_check(void)
  102. {
  103. return 0;
  104. }
  105. static inline void ip6_send_rs(void)
  106. {
  107. }
  108. static inline bool validate_ra(struct ip6_hdr *ip6)
  109. {
  110. return true;
  111. }
  112. static inline int process_ra(struct ip6_hdr *ip6, int len)
  113. {
  114. return 0;
  115. }
  116. #endif
  117. #endif /* __NDISC_H__ */