Path: blob/a-new-beginning/SharedDependencies/Sources/libslirp/include/ip6_icmp.h
2 views
/* SPDX-License-Identifier: BSD-3-Clause */1/*2* Copyright (c) 20133* Guillaume Subiron, Yann Bordenave, Serigne Modou Wagne.4*/56#ifndef SLIRP_IP6_ICMP_H7#define SLIRP_IP6_ICMP_H89/*10* Interface Control Message Protocol version 6 Definitions.11* Per RFC 4443, March 2006.12*13* Network Discover Protocol Definitions.14* Per RFC 4861, September 2007.15*/1617struct icmp6_echo { /* Echo Messages */18uint16_t id;19uint16_t seq_num;20};2122union icmp6_error_body {23uint32_t unused;24uint32_t pointer;25uint32_t mtu;26};2728/*29* NDP Messages30*/31struct ndp_rs { /* Router Solicitation Message */32uint32_t reserved;33};3435struct ndp_ra { /* Router Advertisement Message */36uint8_t chl; /* Cur Hop Limit */37#if (G_BYTE_ORDER == G_BIG_ENDIAN) && !defined(_MSC_VER)38uint8_t M : 1, O : 1, reserved : 6;39#else40uint8_t reserved : 6, O : 1, M : 1;41#endif42uint16_t lifetime; /* Router Lifetime */43uint32_t reach_time; /* Reachable Time */44uint32_t retrans_time; /* Retrans Timer */45};4647G_STATIC_ASSERT(sizeof(struct ndp_ra) == 12);4849struct ndp_ns { /* Neighbor Solicitation Message */50uint32_t reserved;51struct in6_addr target; /* Target Address */52};5354G_STATIC_ASSERT(sizeof(struct ndp_ns) == 20);5556struct ndp_na { /* Neighbor Advertisement Message */57#if (G_BYTE_ORDER == G_BIG_ENDIAN) && !defined(_MSC_VER)58uint8_t R : 1, /* Router Flag */59S : 1, /* Solicited Flag */60O : 1, /* Override Flag */61reserved_1 : 5;62#else63uint8_t reserved_1 : 5, O : 1, S : 1, R : 1;64#endif65uint8_t reserved_2;66uint16_t reserved_3;67struct in6_addr target; /* Target Address */68};6970G_STATIC_ASSERT(sizeof(struct ndp_na) == 20);7172struct ndp_redirect {73uint32_t reserved;74struct in6_addr target; /* Target Address */75struct in6_addr dest; /* Destination Address */76};7778G_STATIC_ASSERT(sizeof(struct ndp_redirect) == 36);7980/*81* Structure of an icmpv6 header.82*/83struct icmp6 {84uint8_t icmp6_type; /* type of message, see below */85uint8_t icmp6_code; /* type sub code */86uint16_t icmp6_cksum; /* ones complement cksum of struct */87union {88union icmp6_error_body error_body;89struct icmp6_echo echo;90struct ndp_rs ndp_rs;91struct ndp_ra ndp_ra;92struct ndp_ns ndp_ns;93struct ndp_na ndp_na;94struct ndp_redirect ndp_redirect;95} icmp6_body;96#define icmp6_err icmp6_body.error_body97#define icmp6_echo icmp6_body.echo98#define icmp6_id icmp6_body.echo.id99#define icmp6_seq icmp6_body.echo.seq_num100#define icmp6_nrs icmp6_body.ndp_rs101#define icmp6_nra icmp6_body.ndp_ra102#define icmp6_nns icmp6_body.ndp_ns103#define icmp6_nna icmp6_body.ndp_na104#define icmp6_redirect icmp6_body.ndp_redirect105};106107G_STATIC_ASSERT(sizeof(struct icmp6) == 40);108109#define ICMP6_MINLEN 4110#define ICMP6_ERROR_MINLEN 8111#define ICMP6_ECHO_MINLEN 8112#define ICMP6_NDP_RS_MINLEN 8113#define ICMP6_NDP_RA_MINLEN 16114#define ICMP6_NDP_NS_MINLEN 24115#define ICMP6_NDP_NA_MINLEN 24116#define ICMP6_NDP_REDIRECT_MINLEN 40117118/*119* NDP Options120*/121SLIRP_PACKED_BEGIN122struct ndpopt {123uint8_t ndpopt_type; /* Option type */124uint8_t ndpopt_len; /* /!\ In units of 8 octets */125union {126unsigned char linklayer_addr[6]; /* Source/Target Link-layer */127#define ndpopt_linklayer ndpopt_body.linklayer_addr128SLIRP_PACKED_BEGIN129struct prefixinfo { /* Prefix Information */130uint8_t prefix_length;131#if (G_BYTE_ORDER == G_BIG_ENDIAN) && !defined(_MSC_VER)132uint8_t L : 1, A : 1, reserved1 : 6;133#else134uint8_t reserved1 : 6, A : 1, L : 1;135#endif136uint32_t valid_lt; /* Valid Lifetime */137uint32_t pref_lt; /* Preferred Lifetime */138uint32_t reserved2;139struct in6_addr prefix;140} SLIRP_PACKED_END prefixinfo;141#define ndpopt_prefixinfo ndpopt_body.prefixinfo142SLIRP_PACKED_BEGIN143struct rdnss {144uint16_t reserved;145uint32_t lifetime;146struct in6_addr addr;147} SLIRP_PACKED_END rdnss;148#define ndpopt_rdnss ndpopt_body.rdnss149} ndpopt_body;150} SLIRP_PACKED_END;151152/* NDP options type */153#define NDPOPT_LINKLAYER_SOURCE 1 /* Source Link-Layer Address */154#define NDPOPT_LINKLAYER_TARGET 2 /* Target Link-Layer Address */155#define NDPOPT_PREFIX_INFO 3 /* Prefix Information */156#define NDPOPT_RDNSS 25 /* Recursive DNS Server Address */157158/* NDP options size, in octets. */159#define NDPOPT_LINKLAYER_LEN 8160#define NDPOPT_PREFIXINFO_LEN 32161#define NDPOPT_RDNSS_LEN 24162163/*164* Definition of type and code field values.165* Per https://www.iana.org/assignments/icmpv6-parameters/icmpv6-parameters.xml166* Last Updated 2012-11-12167*/168169/* Errors */170#define ICMP6_UNREACH 1 /* Destination Unreachable */171#define ICMP6_UNREACH_NO_ROUTE 0 /* no route to dest */172#define ICMP6_UNREACH_DEST_PROHIB 1 /* com with dest prohibited */173#define ICMP6_UNREACH_SCOPE 2 /* beyond scope of src addr */174#define ICMP6_UNREACH_ADDRESS 3 /* address unreachable */175#define ICMP6_UNREACH_PORT 4 /* port unreachable */176#define ICMP6_UNREACH_SRC_FAIL 5 /* src addr failed */177#define ICMP6_UNREACH_REJECT_ROUTE 6 /* reject route to dest */178#define ICMP6_UNREACH_SRC_HDR_ERROR 7 /* error in src routing header */179#define ICMP6_TOOBIG 2 /* Packet Too Big */180#define ICMP6_TIMXCEED 3 /* Time Exceeded */181#define ICMP6_TIMXCEED_INTRANS 0 /* hop limit exceeded in transit */182#define ICMP6_TIMXCEED_REASS 1 /* ttl=0 in reass */183#define ICMP6_PARAMPROB 4 /* Parameter Problem */184#define ICMP6_PARAMPROB_HDR_FIELD 0 /* err header field */185#define ICMP6_PARAMPROB_NXTHDR_TYPE 1 /* unrecognized Next Header type */186#define ICMP6_PARAMPROB_IPV6_OPT 2 /* unrecognized IPv6 option */187188/* Informational Messages */189#define ICMP6_ECHO_REQUEST 128 /* Echo Request */190#define ICMP6_ECHO_REPLY 129 /* Echo Reply */191#define ICMP6_NDP_RS 133 /* Router Solicitation (NDP) */192#define ICMP6_NDP_RA 134 /* Router Advertisement (NDP) */193#define ICMP6_NDP_NS 135 /* Neighbor Solicitation (NDP) */194#define ICMP6_NDP_NA 136 /* Neighbor Advertisement (NDP) */195#define ICMP6_NDP_REDIRECT 137 /* Redirect Message (NDP) */196197/*198* Router Configuration Variables (rfc4861#section-6)199*/200#define NDP_IsRouter 1201#define NDP_AdvSendAdvertisements 1202#define NDP_MaxRtrAdvInterval 600000203#define NDP_MinRtrAdvInterval \204((NDP_MaxRtrAdvInterval >= 9) ? NDP_MaxRtrAdvInterval / 3 : \205NDP_MaxRtrAdvInterval)206#define NDP_AdvManagedFlag 0207#define NDP_AdvOtherConfigFlag 0208#define NDP_AdvLinkMTU 0209#define NDP_AdvReachableTime 0210#define NDP_AdvRetransTime 0211#define NDP_AdvCurHopLimit 64212#define NDP_AdvDefaultLifetime ((3 * NDP_MaxRtrAdvInterval) / 1000)213#define NDP_AdvValidLifetime 86400214#define NDP_AdvOnLinkFlag 1215#define NDP_AdvPrefLifetime 14400216#define NDP_AdvAutonomousFlag 1217218/* Called from slirp_new, but after other initialization */219void icmp6_post_init(Slirp *slirp);220221/* Called from slirp_cleanup */222void icmp6_cleanup(Slirp *slirp);223224/* Process an ICMPv6 packet from the guest */225void icmp6_input(struct mbuf *);226227/* Send an ICMPv6 error related to the given packet, using the given ICMPv6 type and code, using the given source */228void icmp6_forward_error(struct mbuf *m, uint8_t type, uint8_t code, struct in6_addr *src);229230/* Similar to icmp6_forward_error, but use the link-local address as source */231void icmp6_send_error(struct mbuf *m, uint8_t type, uint8_t code);232233/* Forward the ICMP packet to the guest (probably a ping reply) */234void icmp6_reflect(struct mbuf *);235236/* Handle ICMP data from the ICMP socket, and forward it to the guest (using so_m as reference) */237void icmp6_receive(struct socket *so);238239/* Send a neighbour sollicitation, to resolve the given IPV6 address */240void ndp_send_ns(Slirp *slirp, struct in6_addr addr);241242/* Timer handler for router advertisement, to send it and reschedule the timer */243void ra_timer_handler(Slirp *slirp, void *unused);244245#endif246247248