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