1 1.21 christos /* $NetBSD: rtadvd.h,v 1.21 2021/03/22 18:41:11 christos Exp $ */ 2 1.10 rpaulo /* $KAME: rtadvd.h,v 1.30 2005/10/17 14:40:02 suz Exp $ */ 3 1.2 itojun 4 1.1 itojun /* 5 1.1 itojun * Copyright (C) 1998 WIDE Project. 6 1.1 itojun * All rights reserved. 7 1.16 roy * 8 1.1 itojun * Redistribution and use in source and binary forms, with or without 9 1.1 itojun * modification, are permitted provided that the following conditions 10 1.1 itojun * are met: 11 1.1 itojun * 1. Redistributions of source code must retain the above copyright 12 1.1 itojun * notice, this list of conditions and the following disclaimer. 13 1.1 itojun * 2. Redistributions in binary form must reproduce the above copyright 14 1.1 itojun * notice, this list of conditions and the following disclaimer in the 15 1.1 itojun * documentation and/or other materials provided with the distribution. 16 1.1 itojun * 3. Neither the name of the project nor the names of its contributors 17 1.1 itojun * may be used to endorse or promote products derived from this software 18 1.1 itojun * without specific prior written permission. 19 1.16 roy * 20 1.1 itojun * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 21 1.1 itojun * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 1.1 itojun * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 1.1 itojun * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 24 1.1 itojun * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 1.1 itojun * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 1.1 itojun * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 1.1 itojun * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 1.1 itojun * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 1.1 itojun * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 1.1 itojun * SUCH DAMAGE. 31 1.1 itojun */ 32 1.1 itojun 33 1.18 roy #define RTADVD_USER "_rtadvd" 34 1.13 roy 35 1.18 roy #define ALLNODES "ff02::1" 36 1.18 roy #define ALLROUTERS_LINK "ff02::2" 37 1.18 roy #define ALLROUTERS_SITE "ff05::2" 38 1.11 roy 39 1.11 roy #define IN6ADDR_SITELOCAL_ALLROUTERS_INIT \ 40 1.11 roy {{{ 0xff, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ 41 1.16 roy 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }}} 42 1.11 roy 43 1.11 roy //extern struct sockaddr_in6 sin6_linklocal_allnodes; 44 1.11 roy //extern struct sockaddr_in6 sin6_linklocal_allrouters; 45 1.11 roy extern struct sockaddr_in6 sin6_sitelocal_allrouters; 46 1.1 itojun 47 1.1 itojun /* protocol constants and default values */ 48 1.18 roy #define DEF_MAXRTRADVINTERVAL 600 49 1.18 roy #define DEF_ADVLINKMTU 0 50 1.18 roy #define DEF_ADVREACHABLETIME 0 51 1.18 roy #define DEF_ADVRETRANSTIMER 0 52 1.18 roy #define DEF_ADVCURHOPLIMIT 64 53 1.18 roy #define DEF_ADVVALIDLIFETIME 2592000 54 1.18 roy #define DEF_ADVPREFERREDLIFETIME 604800 55 1.18 roy #define DEF_ADVROUTERLIFETIME 1800 56 1.18 roy 57 1.19 roy #define MAXROUTERLIFETIME 65535 /* RFC 8319 */ 58 1.18 roy #define MIN_MAXINTERVAL 4 59 1.19 roy #define MAX_MAXINTERVAL 65535 /* RFC 8319 */ 60 1.18 roy #define MIN_MININTERVAL 3 61 1.18 roy #define MAXREACHABLETIME 3600000 62 1.18 roy 63 1.18 roy #define MAX_INITIAL_RTR_ADVERT_INTERVAL 16 64 1.18 roy #define MAX_INITIAL_RTR_ADVERTISEMENTS 3 65 1.18 roy #define MAX_FINAL_RTR_ADVERTISEMENTS 3 66 1.18 roy #define MIN_DELAY_BETWEEN_RAS 3 67 1.18 roy #define MAX_RA_DELAY_TIME 500000000 /* nsec */ 68 1.18 roy 69 1.18 roy #define PREFIX_FROM_KERNEL 1 70 1.18 roy #define PREFIX_FROM_CONFIG 2 71 1.18 roy #define PREFIX_FROM_DYNAMIC 3 72 1.4 itojun 73 1.1 itojun struct prefix { 74 1.11 roy TAILQ_ENTRY(prefix) next; 75 1.1 itojun 76 1.10 rpaulo struct rainfo *rainfo; /* back pointer to the interface */ 77 1.10 rpaulo 78 1.10 rpaulo struct rtadvd_timer *timer; /* expiration timer. used when a prefix 79 1.10 rpaulo * derived from the kernel is deleted. 80 1.10 rpaulo */ 81 1.10 rpaulo 82 1.11 roy uint32_t validlifetime; /* AdvValidLifetime */ 83 1.6 itojun long vltimeexpire; /* expiration of vltime; decrement case only */ 84 1.11 roy uint32_t preflifetime; /* AdvPreferredLifetime */ 85 1.6 itojun long pltimeexpire; /* expiration of pltime; decrement case only */ 86 1.11 roy uint16_t onlinkflg; /* bool: AdvOnLinkFlag */ 87 1.11 roy uint16_t autoconfflg; /* bool: AdvAutonomousFlag */ 88 1.4 itojun int prefixlen; 89 1.10 rpaulo int origin; /* from kernel or config */ 90 1.1 itojun struct in6_addr prefix; 91 1.1 itojun }; 92 1.1 itojun 93 1.10 rpaulo struct rtinfo { 94 1.11 roy TAILQ_ENTRY(rtinfo) next; 95 1.10 rpaulo 96 1.11 roy uint32_t ltime; /* route lifetime */ 97 1.11 roy uint16_t rtpref; /* route preference */ 98 1.10 rpaulo int prefixlen; 99 1.10 rpaulo struct in6_addr prefix; 100 1.10 rpaulo }; 101 1.11 roy 102 1.11 roy struct rdnss_addr { 103 1.11 roy TAILQ_ENTRY(rdnss_addr) next; 104 1.11 roy 105 1.11 roy struct in6_addr addr; 106 1.11 roy }; 107 1.11 roy 108 1.11 roy struct rdnss { 109 1.11 roy TAILQ_ENTRY(rdnss) next; 110 1.11 roy 111 1.11 roy TAILQ_HEAD(, rdnss_addr) list; 112 1.11 roy uint32_t lifetime; 113 1.11 roy }; 114 1.11 roy 115 1.11 roy struct dnssl_domain { 116 1.11 roy TAILQ_ENTRY(dnssl_domain) next; 117 1.11 roy 118 1.11 roy int len; 119 1.11 roy char domain[256]; 120 1.11 roy }; 121 1.11 roy 122 1.11 roy struct dnssl { 123 1.11 roy TAILQ_ENTRY(dnssl) next; 124 1.11 roy 125 1.11 roy TAILQ_HEAD(, dnssl_domain) list; 126 1.11 roy uint32_t lifetime; 127 1.11 roy }; 128 1.9 itojun 129 1.5 itojun struct soliciter { 130 1.11 roy TAILQ_ENTRY(soliciter) next; 131 1.11 roy 132 1.5 itojun struct sockaddr_in6 addr; 133 1.5 itojun }; 134 1.5 itojun 135 1.1 itojun struct rainfo { 136 1.11 roy TAILQ_ENTRY(rainfo) next; 137 1.1 itojun 138 1.1 itojun /* timer related parameters */ 139 1.17 roy struct rtadvd_timer *timer; /* unsolicited RA timer */ 140 1.17 roy struct rtadvd_timer *timer_sol; /* solicited RA timer */ 141 1.1 itojun int initcounter; /* counter for the first few advertisements */ 142 1.14 roy struct timespec lastsent; /* timestamp when the latest RA was sent */ 143 1.1 itojun int waiting; /* number of RS waiting for RA */ 144 1.12 roy struct rainfo *leaving; /* the config which is leaving */ 145 1.12 roy struct rainfo *leaving_for; /* the new config to activate */ 146 1.12 roy int leaving_adv; /* number of RA left to send */ 147 1.1 itojun 148 1.1 itojun /* interface information */ 149 1.11 roy uint16_t ifindex; 150 1.12 roy int ifflags; 151 1.1 itojun int advlinkopt; /* bool: whether include link-layer addr opt */ 152 1.1 itojun struct sockaddr_dl *sdl; 153 1.1 itojun char ifname[16]; 154 1.11 roy uint32_t phymtu; /* mtu of the physical interface */ 155 1.1 itojun 156 1.1 itojun /* Router configuration variables */ 157 1.11 roy uint16_t lifetime; /* AdvDefaultLifetime */ 158 1.11 roy uint16_t maxinterval; /* MaxRtrAdvInterval */ 159 1.11 roy uint16_t mininterval; /* MinRtrAdvInterval */ 160 1.16 roy int managedflg; /* AdvManagedFlag */ 161 1.1 itojun int otherflg; /* AdvOtherConfigFlag */ 162 1.10 rpaulo 163 1.9 itojun int rtpref; /* router preference */ 164 1.11 roy uint32_t linkmtu; /* AdvLinkMTU */ 165 1.11 roy uint32_t reachabletime; /* AdvReachableTime */ 166 1.11 roy uint32_t retranstimer; /* AdvRetransTimer */ 167 1.11 roy uint16_t hoplimit; /* AdvCurHopLimit */ 168 1.11 roy TAILQ_HEAD(, prefix) prefix; /* AdvPrefixList(link head) */ 169 1.11 roy int pfxs; 170 1.11 roy uint16_t clockskew;/* used for consisitency check of lifetimes */ 171 1.11 roy 172 1.11 roy TAILQ_HEAD(, rtinfo) route; 173 1.11 roy TAILQ_HEAD(, rdnss) rdnss; /* RDNSS list */ 174 1.11 roy TAILQ_HEAD(, dnssl) dnssl; /* DNS Search List */ 175 1.3 itojun 176 1.1 itojun /* actual RA packet data and its length */ 177 1.1 itojun size_t ra_datalen; 178 1.11 roy char *ra_data; 179 1.4 itojun 180 1.4 itojun /* statistics */ 181 1.11 roy uint64_t raoutput; /* number of RAs sent */ 182 1.11 roy uint64_t rainput; /* number of RAs received */ 183 1.11 roy uint64_t rainconsistent; /* number of RAs inconsistent with ours */ 184 1.11 roy uint64_t rsinput; /* number of RSs received */ 185 1.5 itojun 186 1.5 itojun /* info about soliciter */ 187 1.11 roy TAILQ_HEAD(, soliciter) soliciter; /* recent solication source */ 188 1.1 itojun }; 189 1.1 itojun 190 1.11 roy extern TAILQ_HEAD(ralist_head_t, rainfo) ralist; 191 1.3 itojun 192 1.11 roy struct rtadvd_timer *ra_timeout(void *); 193 1.17 roy struct rtadvd_timer *ra_timeout_sol(void *); 194 1.14 roy void ra_timer_update(void *, struct timespec *); 195 1.17 roy void ra_timer_set_short_delay(struct rainfo *, struct rtadvd_timer *); 196 1.6 itojun 197 1.11 roy int prefix_match(struct in6_addr *, int, struct in6_addr *, int); 198 1.11 roy struct rainfo *if_indextorainfo(unsigned int); 199 1.21 christos struct prefix *find_prefix(struct rainfo *, const struct in6_addr *, int); 200 1.20 roy 201 1.20 roy extern int Cflag; 202