1 /* 2 * dhcpcd - IPv6 ND handling 3 * SPDX-License-Identifier: BSD-2-Clause 4 * Copyright (c) 2006-2025 Roy Marples <roy (at) 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 /* rfc4191 */ 41 struct routeinfo { 42 TAILQ_ENTRY(routeinfo) next; 43 struct in6_addr prefix; 44 uint8_t prefix_len; 45 uint32_t lifetime; 46 uint8_t flags; 47 struct timespec acquired; 48 char sprefix[INET6_ADDRSTRLEN]; 49 }; 50 51 TAILQ_HEAD(routeinfohead, routeinfo); 52 53 struct ra { 54 TAILQ_ENTRY(ra) next; 55 struct interface *iface; 56 struct in6_addr from; 57 char sfrom[INET6_ADDRSTRLEN]; 58 uint8_t *data; 59 size_t data_len; 60 struct timespec acquired; 61 uint8_t flags; 62 uint32_t lifetime; 63 uint32_t reachable; 64 uint32_t retrans; 65 uint32_t mtu; 66 uint8_t hoplimit; 67 struct ipv6_addrhead addrs; 68 struct routeinfohead rinfos; 69 bool hasdns; 70 bool expired; 71 bool willexpire; 72 bool doexpire; 73 bool isreachable; 74 }; 75 76 TAILQ_HEAD(ra_head, ra); 77 78 struct rs_state { 79 struct nd_router_solicit *rs; 80 size_t rslen; 81 int rsprobes; 82 uint32_t retrans; 83 #ifdef __sun 84 int nd_fd; 85 #endif 86 }; 87 88 #define RS_STATE(a) ((struct rs_state *)(ifp)->if_data[IF_DATA_IPV6ND]) 89 #define RS_CSTATE(a) ((const struct rs_state *)(ifp)->if_data[IF_DATA_IPV6ND]) 90 #define RS_STATE_RUNNING(a) (ipv6nd_hasra((a)) && ipv6nd_dadcompleted((a))) 91 92 #ifndef MAX_RTR_SOLICITATION_DELAY 93 #define MAX_RTR_SOLICITATION_DELAY 1 /* seconds */ 94 #define MAX_UNICAST_SOLICIT 3 /* 3 transmissions */ 95 #define RTR_SOLICITATION_INTERVAL 4 /* seconds */ 96 #define MAX_RTR_SOLICITATIONS 3 /* times */ 97 #define MAX_NEIGHBOR_ADVERTISEMENT 3 /* 3 transmissions */ 98 99 #ifndef IPV6_DEFHLIM 100 #define IPV6_DEFHLIM 64 101 #endif 102 #endif 103 104 /* On carrier up, expire known routers after RTR_CARRIER_EXPIRE seconds. */ 105 #define RTR_CARRIER_EXPIRE \ 106 (MAX_RTR_SOLICITATION_DELAY + \ 107 (MAX_RTR_SOLICITATIONS + 1) * RTR_SOLICITATION_INTERVAL) 108 109 #define MAX_REACHABLE_TIME 3600000 /* milliseconds */ 110 #define REACHABLE_TIME 30000 /* milliseconds */ 111 #define RETRANS_TIMER 1000 /* milliseconds */ 112 #define DELAY_FIRST_PROBE_TIME 5 /* seconds */ 113 114 #define MIN_EXTENDED_VLTIME 7200 /* seconds */ 115 116 int ipv6nd_open(bool); 117 #ifdef __sun 118 int ipv6nd_openif(unsigned int); 119 #endif 120 void ipv6nd_recvmsg(struct dhcpcd_ctx *, struct msghdr *); 121 int ipv6nd_rtpref(uint8_t); 122 void ipv6nd_printoptions(const struct dhcpcd_ctx *, const struct dhcp_opt *, 123 size_t); 124 void ipv6nd_startrs(struct interface *); 125 ssize_t ipv6nd_env(FILE *, const struct interface *); 126 const struct ipv6_addr *ipv6nd_iffindaddr(const struct interface *ifp, 127 const struct in6_addr *addr, unsigned int flags); 128 struct ipv6_addr *ipv6nd_findaddr(struct dhcpcd_ctx *, const struct in6_addr *, 129 unsigned int); 130 struct ipv6_addr *ipv6nd_iffindprefix(struct interface *, 131 const struct in6_addr *, uint8_t); 132 ssize_t ipv6nd_free(struct interface *); 133 void ipv6nd_expirera(void *arg); 134 bool ipv6nd_hasralifetime(const struct interface *, bool); 135 #define ipv6nd_hasra(i) ipv6nd_hasralifetime((i), false) 136 bool ipv6nd_hasradhcp(const struct interface *, bool); 137 void ipv6nd_handleifa(int, struct ipv6_addr *, pid_t); 138 int ipv6nd_dadcompleted(const struct interface *); 139 void ipv6nd_advertise(struct ipv6_addr *); 140 void ipv6nd_startexpire(struct interface *); 141 void ipv6nd_drop(struct interface *); 142 void ipv6nd_neighbour(struct dhcpcd_ctx *, struct in6_addr *, bool); 143 void ipv6nd_abort(struct interface *); 144 #endif /* INET6 */ 145 146 #endif /* IPV6ND_H */ 147