Home | History | Annotate | Line # | Download | only in rtadvd
rtadvd.h revision 1.10.42.1
      1 /*	$NetBSD: rtadvd.h,v 1.10.42.1 2012/04/17 00:09:53 yamt 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 ALLNODES "ff02::1"
     34 #define ALLROUTERS_LINK "ff02::2"
     35 #define ALLROUTERS_SITE "ff05::2"
     36 
     37 #define IN6ADDR_SITELOCAL_ALLROUTERS_INIT \
     38 	{{{ 0xff, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
     39  	    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }}}
     40 
     41 //extern struct sockaddr_in6 sin6_linklocal_allnodes;
     42 //extern struct sockaddr_in6 sin6_linklocal_allrouters;
     43 extern struct sockaddr_in6 sin6_sitelocal_allrouters;
     44 
     45 /* protocol constants and default values */
     46 #define DEF_MAXRTRADVINTERVAL 600
     47 #define DEF_ADVLINKMTU 0
     48 #define DEF_ADVREACHABLETIME 0
     49 #define DEF_ADVRETRANSTIMER 0
     50 #define DEF_ADVCURHOPLIMIT 64
     51 #define DEF_ADVVALIDLIFETIME 2592000
     52 #define DEF_ADVPREFERREDLIFETIME 604800
     53 
     54 #define MAXROUTERLIFETIME 9000
     55 #define MIN_MAXINTERVAL 4
     56 #define MAX_MAXINTERVAL 1800
     57 #define MIN_MININTERVAL 3
     58 #define MAXREACHABLETIME 3600000
     59 
     60 #define MAX_INITIAL_RTR_ADVERT_INTERVAL  16
     61 #define MAX_INITIAL_RTR_ADVERTISEMENTS    3
     62 #define MAX_FINAL_RTR_ADVERTISEMENTS      3
     63 #define MIN_DELAY_BETWEEN_RAS             3
     64 #define MAX_RA_DELAY_TIME                 500000 /* usec */
     65 
     66 #define PREFIX_FROM_KERNEL 1
     67 #define PREFIX_FROM_CONFIG 2
     68 #define PREFIX_FROM_DYNAMIC 3
     69 
     70 struct prefix {
     71 	TAILQ_ENTRY(prefix) next;
     72 
     73 	struct rainfo *rainfo;	/* back pointer to the interface */
     74 
     75 	struct rtadvd_timer *timer; /* expiration timer.  used when a prefix
     76 				     * derived from the kernel is deleted.
     77 				     */
     78 
     79 	uint32_t validlifetime; /* AdvValidLifetime */
     80 	long	vltimeexpire;	/* expiration of vltime; decrement case only */
     81 	uint32_t preflifetime;	/* AdvPreferredLifetime */
     82 	long	pltimeexpire;	/* expiration of pltime; decrement case only */
     83 	uint16_t onlinkflg;	/* bool: AdvOnLinkFlag */
     84 	uint16_t autoconfflg;	/* bool: AdvAutonomousFlag */
     85 	int prefixlen;
     86 	int origin;		/* from kernel or config */
     87 	struct in6_addr prefix;
     88 };
     89 
     90 struct rtinfo {
     91 	TAILQ_ENTRY(rtinfo) next;
     92 
     93 	uint32_t ltime;	/* route lifetime */
     94 	uint16_t rtpref;		/* route preference */
     95 	int prefixlen;
     96 	struct in6_addr prefix;
     97 };
     98 
     99 struct rdnss_addr {
    100 	TAILQ_ENTRY(rdnss_addr) next;
    101 
    102 	struct in6_addr addr;
    103 };
    104 
    105 struct rdnss {
    106 	TAILQ_ENTRY(rdnss) next;
    107 
    108 	TAILQ_HEAD(, rdnss_addr) list;
    109 	uint32_t lifetime;
    110 };
    111 
    112 struct dnssl_domain {
    113 	TAILQ_ENTRY(dnssl_domain) next;
    114 
    115 	int len;
    116 	char domain[256];
    117 };
    118 
    119 struct dnssl {
    120 	TAILQ_ENTRY(dnssl) next;
    121 
    122 	TAILQ_HEAD(, dnssl_domain) list;
    123 	uint32_t lifetime;
    124 };
    125 
    126 struct soliciter {
    127 	TAILQ_ENTRY(soliciter) next;
    128 
    129 	struct sockaddr_in6 addr;
    130 };
    131 
    132 struct	rainfo {
    133 	TAILQ_ENTRY(rainfo) next;
    134 
    135 	/* timer related parameters */
    136 	struct rtadvd_timer *timer;
    137 	int initcounter; /* counter for the first few advertisements */
    138 	struct timeval lastsent; /* timestamp when the latest RA was sent */
    139 	int waiting;		/* number of RS waiting for RA */
    140 
    141 	/* interface information */
    142 	uint16_t	ifindex;
    143 	int	advlinkopt;	/* bool: whether include link-layer addr opt */
    144 	struct sockaddr_dl *sdl;
    145 	char	ifname[16];
    146 	uint32_t	phymtu;		/* mtu of the physical interface */
    147 
    148 	/* Router configuration variables */
    149 	uint16_t	lifetime;	/* AdvDefaultLifetime */
    150 	uint16_t	maxinterval;	/* MaxRtrAdvInterval */
    151 	uint16_t	mininterval;	/* MinRtrAdvInterval */
    152 	int 	managedflg;	/* AdvManagedFlag */
    153 	int	otherflg;	/* AdvOtherConfigFlag */
    154 
    155 	int	rtpref;		/* router preference */
    156 	uint32_t linkmtu;	/* AdvLinkMTU */
    157 	uint32_t reachabletime; /* AdvReachableTime */
    158 	uint32_t retranstimer;	/* AdvRetransTimer */
    159 	uint16_t	hoplimit;	/* AdvCurHopLimit */
    160 	TAILQ_HEAD(, prefix) prefix;	/* AdvPrefixList(link head) */
    161 	int	pfxs;
    162 	uint16_t	clockskew;/* used for consisitency check of lifetimes */
    163 
    164 	TAILQ_HEAD(, rtinfo) route;
    165 	TAILQ_HEAD(, rdnss) rdnss;	/* RDNSS list */
    166 	TAILQ_HEAD(, dnssl) dnssl;	/* DNS Search List */
    167 
    168 	/* actual RA packet data and its length */
    169 	size_t ra_datalen;
    170 	char *ra_data;
    171 
    172 	/* statistics */
    173 	uint64_t raoutput;	/* number of RAs sent */
    174 	uint64_t rainput;	/* number of RAs received */
    175 	uint64_t rainconsistent; /* number of RAs inconsistent with ours */
    176 	uint64_t rsinput;	/* number of RSs received */
    177 
    178 	/* info about soliciter */
    179 	TAILQ_HEAD(, soliciter) soliciter;	/* recent solication source */
    180 };
    181 
    182 extern TAILQ_HEAD(ralist_head_t, rainfo) ralist;
    183 
    184 struct rtadvd_timer *ra_timeout(void *);
    185 void ra_timer_update(void *, struct timeval *);
    186 
    187 int prefix_match(struct in6_addr *, int, struct in6_addr *, int);
    188 struct rainfo *if_indextorainfo(unsigned int);
    189 struct prefix *find_prefix(struct rainfo *, struct in6_addr *, int);
    190