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