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