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