1 /* 2 * dhcpcd - IPv6 ND handling 3 * Copyright (c) 2006-2018 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 #include <time.h> 32 33 #include "config.h" 34 #include "dhcpcd.h" 35 #include "ipv6.h" 36 37 struct ra { 38 TAILQ_ENTRY(ra) next; 39 struct interface *iface; 40 struct in6_addr from; 41 char sfrom[INET6_ADDRSTRLEN]; 42 uint8_t *data; 43 size_t data_len; 44 struct timespec acquired; 45 unsigned char flags; 46 uint32_t lifetime; 47 uint32_t reachable; 48 uint32_t retrans; 49 uint32_t mtu; 50 struct ipv6_addrhead addrs; 51 uint8_t hasdns; 52 uint8_t expired; 53 }; 54 55 TAILQ_HEAD(ra_head, ra); 56 57 struct rs_state { 58 struct nd_router_solicit *rs; 59 size_t rslen; 60 int rsprobes; 61 }; 62 63 #define RS_STATE(a) ((struct rs_state *)(ifp)->if_data[IF_DATA_IPV6ND]) 64 #define RS_STATE_RUNNING(a) (ipv6nd_hasra((a)) && ipv6nd_dadcompleted((a))) 65 66 #ifndef MAX_RTR_SOLICITATION_DELAY 67 #define MAX_RTR_SOLICITATION_DELAY 1 /* seconds */ 68 #define MAX_UNICAST_SOLICIT 3 /* 3 transmissions */ 69 #define RTR_SOLICITATION_INTERVAL 4 /* seconds */ 70 #define MAX_RTR_SOLICITATIONS 3 /* times */ 71 #endif 72 73 /* On carrier up, expire known routers after RTR_CARRIER_EXPIRE seconds. */ 74 #define RTR_CARRIER_EXPIRE \ 75 (MAX_RTR_SOLICITATION_DELAY + \ 76 (MAX_RTR_SOLICITATIONS + 1) * \ 77 RTR_SOLICITATION_INTERVAL) 78 79 #define MAX_REACHABLE_TIME 3600000 /* milliseconds */ 80 #define REACHABLE_TIME 30000 /* milliseconds */ 81 #define RETRANS_TIMER 1000 /* milliseconds */ 82 #define DELAY_FIRST_PROBE_TIME 5 /* seconds */ 83 84 #define IPV6ND_REACHABLE (1 << 0) 85 #define IPV6ND_ROUTER (1 << 1) 86 87 #ifdef INET6 88 void ipv6nd_printoptions(const struct dhcpcd_ctx *, 89 const struct dhcp_opt *, size_t); 90 void ipv6nd_startrs(struct interface *); 91 ssize_t ipv6nd_env(char **, const char *, const struct interface *); 92 const struct ipv6_addr *ipv6nd_iffindaddr(const struct interface *ifp, 93 const struct in6_addr *addr, unsigned int flags); 94 struct ipv6_addr *ipv6nd_findaddr(struct dhcpcd_ctx *, 95 const struct in6_addr *, unsigned int); 96 ssize_t ipv6nd_free(struct interface *); 97 void ipv6nd_expirera(void *arg); 98 int ipv6nd_hasra(const struct interface *); 99 int ipv6nd_hasradhcp(const struct interface *); 100 void ipv6nd_handleifa(int, struct ipv6_addr *, pid_t); 101 int ipv6nd_dadcompleted(const struct interface *); 102 void ipv6nd_expire(struct interface *, uint32_t); 103 void ipv6nd_drop(struct interface *); 104 void ipv6nd_neighbour(struct dhcpcd_ctx *, struct in6_addr *, int); 105 #else 106 #define ipv6nd_startrs(a) {} 107 #define ipv6nd_free(a) {} 108 #define ipv6nd_hasra(a) (0) 109 #define ipv6nd_dadcompleted(a) (0) 110 #define ipv6nd_expire(a, b) {} 111 #endif 112 113 #endif 114