blob: f6f8eb6507c2cf2d618160e364693f5a32766b15 [file] [log] [blame]
Viacheslav Mitrofanovc6610e12022-12-02 12:18:01 +03001/* 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 */
16struct nd_msg {
17 struct icmp6hdr icmph;
18 struct in6_addr target;
19 __u8 opt[0];
20};
21
22/* struct echo_msg - ICMPv6 echo request/reply message format */
23struct echo_msg {
24 struct icmp6hdr icmph;
25 __u16 id;
26 __u16 sequence;
27};
28
29/* Neigbour Discovery option types */
30enum {
31 __ND_OPT_PREFIX_INFO_END = 0,
32 ND_OPT_SOURCE_LL_ADDR = 1,
33 ND_OPT_TARGET_LL_ADDR = 2,
34 ND_OPT_PREFIX_INFO = 3,
35 ND_OPT_REDIRECT_HDR = 4,
36 ND_OPT_MTU = 5,
37 __ND_OPT_MAX
38};
39
40/* IPv6 destination address of packet waiting for ND */
41extern struct in6_addr net_nd_sol_packet_ip6;
42/* MAC destination address of packet waiting for ND */
43extern uchar *net_nd_packet_mac;
44/* pointer to packet waiting to be transmitted after ND is resolved */
45extern uchar *net_nd_tx_packet;
46/* size of packet waiting to be transmitted */
47extern int net_nd_tx_packet_size;
48/* the timer for ND resolution */
49extern ulong net_nd_timer_start;
50/* the number of requests we have sent so far */
51extern int net_nd_try;
52
53#ifdef CONFIG_IPV6
54/**
55 * ndisc_init() - Make initial steps for ND state machine.
56 * Usually move variables into initial state.
57 */
58void ndisc_init(void);
59
60/**
61 * ndisc_receive() - Handle ND packet
62 *
63 * @et: pointer to incoming packet
64 * @ip6: pointer to IPv6 header
65 * @len: incoming packet length
66 * Return: 0 if handle successfully, -1 if unsupported/unknown ND packet type
67 */
68int ndisc_receive(struct ethernet_hdr *et, struct ip6_hdr *ip6, int len);
69
70/**
71 * ndisc_request() - Send ND request
72 */
73void ndisc_request(void);
74
75/**
76 * ndisc_init() - Check ND response timeout
77 *
78 * Return: 0 if no timeout, -1 otherwise
79 */
80int ndisc_timeout_check(void);
81#else
82static inline void ndisc_init(void)
83{
84}
85
86static inline int
87ndisc_receive(struct ethernet_hdr *et, struct ip6_hdr *ip6, int len)
88{
89 return -1;
90}
91
92static inline void ndisc_request(void)
93{
94}
95
96static inline int ndisc_timeout_check(void)
97{
98 return 0;
99}
100#endif
101
102#endif /* __NDISC_H__ */