| 1 | /* | 
| 2 |  * dhcpcd - IPv6 ND handling | 
| 3 |  * Copyright (c) 2006-2019 Roy Marples <roy@marples.name> | 
| 4 |  * All rights reserved | 
| 5 |  | 
| 6 |  * Redistribution and use in source and binary forms, with or without | 
| 7 |  * modification, are permitted provided that the following conditions | 
| 8 |  * are met: | 
| 9 |  * 1. Redistributions of source code must retain the above copyright | 
| 10 |  *    notice, this list of conditions and the following disclaimer. | 
| 11 |  * 2. Redistributions in binary form must reproduce the above copyright | 
| 12 |  *    notice, this list of conditions and the following disclaimer in the | 
| 13 |  *    documentation and/or other materials provided with the distribution. | 
| 14 |  * | 
| 15 |  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | 
| 16 |  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 
| 17 |  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 
| 18 |  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | 
| 19 |  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 
| 20 |  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 
| 21 |  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 
| 22 |  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 
| 23 |  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 
| 24 |  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 
| 25 |  * SUCH DAMAGE. | 
| 26 |  */ | 
| 27 |  | 
| 28 | #ifndef IPV6ND_H | 
| 29 | #define IPV6ND_H | 
| 30 |  | 
| 31 | #ifdef INET6 | 
| 32 |  | 
| 33 | #include <time.h> | 
| 34 |  | 
| 35 | #include "config.h" | 
| 36 | #include "dhcpcd.h" | 
| 37 | #include "ipv6.h" | 
| 38 |  | 
| 39 | struct ra { | 
| 40 | 	TAILQ_ENTRY(ra) next; | 
| 41 | 	struct interface *iface; | 
| 42 | 	struct in6_addr from; | 
| 43 | 	char sfrom[INET6_ADDRSTRLEN]; | 
| 44 | 	uint8_t *data; | 
| 45 | 	size_t data_len; | 
| 46 | 	struct timespec acquired; | 
| 47 | 	unsigned char flags; | 
| 48 | 	uint32_t lifetime; | 
| 49 | 	uint32_t reachable; | 
| 50 | 	uint32_t retrans; | 
| 51 | 	uint32_t mtu; | 
| 52 | 	struct ipv6_addrhead addrs; | 
| 53 | 	uint8_t hasdns; | 
| 54 | 	uint8_t expired; | 
| 55 | }; | 
| 56 |  | 
| 57 | TAILQ_HEAD(ra_head, ra); | 
| 58 |  | 
| 59 | struct rs_state { | 
| 60 | 	struct nd_router_solicit *rs; | 
| 61 | 	size_t rslen; | 
| 62 | 	int rsprobes; | 
| 63 | 	uint32_t retrans; | 
| 64 | #ifdef __sun | 
| 65 | 	int nd_fd; | 
| 66 | #endif | 
| 67 | }; | 
| 68 |  | 
| 69 | #define	RS_STATE(a) ((struct rs_state *)(ifp)->if_data[IF_DATA_IPV6ND]) | 
| 70 | #define	RS_CSTATE(a) ((const struct rs_state *)(ifp)->if_data[IF_DATA_IPV6ND]) | 
| 71 | #define	RS_STATE_RUNNING(a) (ipv6nd_hasra((a)) && ipv6nd_dadcompleted((a))) | 
| 72 |  | 
| 73 | #ifndef MAX_RTR_SOLICITATION_DELAY | 
| 74 | #define	MAX_RTR_SOLICITATION_DELAY	1	/* seconds */ | 
| 75 | #define	MAX_UNICAST_SOLICIT		3	/* 3 transmissions */ | 
| 76 | #define	RTR_SOLICITATION_INTERVAL	4	/* seconds */ | 
| 77 | #define	MAX_RTR_SOLICITATIONS		3	/* times */ | 
| 78 | #define	MAX_NEIGHBOR_ADVERTISEMENT	3	/* 3 transmissions */ | 
| 79 | #endif | 
| 80 |  | 
| 81 | /* On carrier up, expire known routers after RTR_CARRIER_EXPIRE seconds. */ | 
| 82 | #define RTR_CARRIER_EXPIRE		\ | 
| 83 |     (MAX_RTR_SOLICITATION_DELAY +	\ | 
| 84 |     (MAX_RTR_SOLICITATIONS + 1) *	\ | 
| 85 |     RTR_SOLICITATION_INTERVAL) | 
| 86 |  | 
| 87 | #define	MAX_REACHABLE_TIME		3600000	/* milliseconds */ | 
| 88 | #define	REACHABLE_TIME			30000	/* milliseconds */ | 
| 89 | #define	RETRANS_TIMER			1000	/* milliseconds */ | 
| 90 | #define	DELAY_FIRST_PROBE_TIME		5	/* seconds */ | 
| 91 |  | 
| 92 | #define	IPV6ND_REACHABLE		(1 << 0) | 
| 93 | #define	IPV6ND_ROUTER			(1 << 1) | 
| 94 |  | 
| 95 | void ipv6nd_printoptions(const struct dhcpcd_ctx *, | 
| 96 |     const struct dhcp_opt *, size_t); | 
| 97 | void ipv6nd_startrs(struct interface *); | 
| 98 | ssize_t ipv6nd_env(char **, const char *, const struct interface *); | 
| 99 | const struct ipv6_addr *ipv6nd_iffindaddr(const struct interface *ifp, | 
| 100 |     const struct in6_addr *addr, unsigned int flags); | 
| 101 | struct ipv6_addr *ipv6nd_findaddr(struct dhcpcd_ctx *, | 
| 102 |     const struct in6_addr *, unsigned int); | 
| 103 | ssize_t ipv6nd_free(struct interface *); | 
| 104 | void ipv6nd_expirera(void *arg); | 
| 105 | int ipv6nd_hasra(const struct interface *); | 
| 106 | int ipv6nd_hasradhcp(const struct interface *); | 
| 107 | void ipv6nd_handleifa(int, struct ipv6_addr *, pid_t); | 
| 108 | int ipv6nd_dadcompleted(const struct interface *); | 
| 109 | void ipv6nd_advertise(struct ipv6_addr *); | 
| 110 | void ipv6nd_expire(struct interface *, uint32_t); | 
| 111 | void ipv6nd_drop(struct interface *); | 
| 112 | void ipv6nd_neighbour(struct dhcpcd_ctx *, struct in6_addr *, int); | 
| 113 | #endif /* INET6 */ | 
| 114 |  | 
| 115 | #endif /* IPV6ND_H */ | 
| 116 |  |