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 */ 16struct nd_msg { 17 struct icmp6hdr icmph; 18 struct in6_addr target; 19 __u8 opt[0]; 20}; 21 22/* struct rs_msg - ICMPv6 Router Solicitation message format */ 23struct rs_msg { 24 struct icmp6hdr icmph; 25 __u8 opt[0]; 26}; 27 28/* struct ra_msg - ICMPv6 Router Advertisement message format */ 29struct ra_msg { 30 struct icmp6hdr icmph; 31 __u32 reachable_time; 32 __u32 retransmission_timer; 33 __u8 opt[0]; 34}; 35 36/* struct echo_msg - ICMPv6 echo request/reply message format */ 37struct echo_msg { 38 struct icmp6hdr icmph; 39 __u16 id; 40 __u16 sequence; 41}; 42 43/* Neigbour Discovery option types */ 44enum { 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 */ 55extern struct in6_addr net_nd_sol_packet_ip6; 56/* MAC destination address of packet waiting for ND */ 57extern uchar *net_nd_packet_mac; 58/* pointer to packet waiting to be transmitted after ND is resolved */ 59extern uchar *net_nd_tx_packet; 60/* size of packet waiting to be transmitted */ 61extern int net_nd_tx_packet_size; 62/* the timer for ND resolution */ 63extern ulong net_nd_timer_start; 64/* the number of requests we have sent so far */ 65extern 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 */ 72void ndisc_init(void); 73 74/* 75 * ip6_send_rs() - Send IPv6 Router Solicitation Message 76 */ 77void ip6_send_rs(void); 78 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 */ 87int ndisc_receive(struct ethernet_hdr *et, struct ip6_hdr *ip6, int len); 88 89/** 90 * ndisc_request() - Send ND request 91 */ 92void ndisc_request(void); 93 94/** 95 * ndisc_init() - Check ND response timeout 96 * 97 * Return: 0 if no timeout, -1 otherwise 98 */ 99int ndisc_timeout_check(void); 100bool validate_ra(struct ip6_hdr *ip6); 101int process_ra(struct ip6_hdr *ip6, int len); 102#else 103static inline void ndisc_init(void) 104{ 105} 106 107static inline int 108ndisc_receive(struct ethernet_hdr *et, struct ip6_hdr *ip6, int len) 109{ 110 return -1; 111} 112 113static inline void ndisc_request(void) 114{ 115} 116 117static inline int ndisc_timeout_check(void) 118{ 119 return 0; 120} 121 122static inline void ip6_send_rs(void) 123{ 124} 125 126static inline bool validate_ra(struct ip6_hdr *ip6) 127{ 128 return true; 129} 130 131static inline int process_ra(struct ip6_hdr *ip6, int len) 132{ 133 return 0; 134} 135#endif 136 137#endif /* __NDISC_H__ */ 138