1 /* $NetBSD: ipv6nd.h,v 1.13 2015/07/09 10:15:34 roy Exp $ */ 2 3 /* 4 * dhcpcd - DHCP client daemon 5 * Copyright (c) 2006-2015 Roy Marples <roy@marples.name> 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 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30 #ifndef IPV6ND_H 31 #define IPV6ND_H 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 unsigned char *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 uint8_t no_public_warned; 56 }; 57 58 TAILQ_HEAD(ra_head, ra); 59 60 struct rs_state { 61 unsigned char *rs; 62 size_t rslen; 63 int rsprobes; 64 }; 65 66 #define RS_STATE(a) ((struct rs_state *)(ifp)->if_data[IF_DATA_IPV6ND]) 67 #define RS_STATE_RUNNING(a) (ipv6nd_hasra((a)) && ipv6nd_dadcompleted((a))) 68 69 #define ND_CFIRST_OPTION(m) \ 70 ((const struct nd_opt_hdr *) \ 71 ((const uint8_t *)(m)->data + sizeof(struct nd_router_advert))) 72 #define ND_OPTION_LEN(o) ((size_t)((o)->nd_opt_len * 8) - \ 73 sizeof(struct nd_opt_hdr)) 74 #define ND_CNEXT_OPTION(o) \ 75 ((const struct nd_opt_hdr *)((const uint8_t *)(o) + \ 76 (size_t)((o)->nd_opt_len * 8))) 77 #define ND_COPTION_DATA(o) \ 78 ((const uint8_t *)(o) + sizeof(struct nd_opt_hdr)) 79 80 #define MAX_RTR_SOLICITATION_DELAY 1 /* seconds */ 81 #define MAX_UNICAST_SOLICIT 3 /* 3 transmissions */ 82 #define RTR_SOLICITATION_INTERVAL 4 /* seconds */ 83 #define MAX_RTR_SOLICITATIONS 3 /* times */ 84 85 /* On carrier up, expire known routers after RTR_CARRIER_EXPIRE seconds. */ 86 #define RTR_CARRIER_EXPIRE \ 87 (MAX_RTR_SOLICITATION_DELAY + \ 88 (MAX_RTR_SOLICITATIONS + 1) * \ 89 RTR_SOLICITATION_INTERVAL) 90 91 #define MAX_REACHABLE_TIME 3600000 /* milliseconds */ 92 #define REACHABLE_TIME 30000 /* milliseconds */ 93 #define RETRANS_TIMER 1000 /* milliseconds */ 94 #define DELAY_FIRST_PROBE_TIME 5 /* seconds */ 95 96 #define IPV6ND_REACHABLE (1 << 0) 97 #define IPV6ND_ROUTER (1 << 1) 98 99 #ifdef INET6 100 void ipv6nd_printoptions(const struct dhcpcd_ctx *, 101 const struct dhcp_opt *, size_t); 102 void ipv6nd_startrs(struct interface *); 103 ssize_t ipv6nd_env(char **, const char *, const struct interface *); 104 const struct ipv6_addr *ipv6nd_iffindaddr(const struct interface *ifp, 105 const struct in6_addr *addr, short flags); 106 struct ipv6_addr *ipv6nd_findaddr(struct dhcpcd_ctx *, 107 const struct in6_addr *, short); 108 void ipv6nd_freedrop_ra(struct ra *, int); 109 #define ipv6nd_free_ra(ra) ipv6nd_freedrop_ra((ra), 0) 110 #define ipv6nd_drop_ra(ra) ipv6nd_freedrop_ra((ra), 1) 111 ssize_t ipv6nd_free(struct interface *); 112 void ipv6nd_expirera(void *arg); 113 int ipv6nd_hasra(const struct interface *); 114 int ipv6nd_hasradhcp(const struct interface *); 115 void ipv6nd_runignoredra(struct interface *); 116 void ipv6nd_handleifa(struct dhcpcd_ctx *, int, 117 const char *, const struct in6_addr *, int); 118 int ipv6nd_dadcompleted(const struct interface *); 119 void ipv6nd_expire(struct interface *, uint32_t); 120 void ipv6nd_drop(struct interface *); 121 void ipv6nd_neighbour(struct dhcpcd_ctx *, struct in6_addr *, int); 122 #else 123 #define ipv6nd_startrs(a) {} 124 #define ipv6nd_free(a) {} 125 #define ipv6nd_hasra(a) (0) 126 #define ipv6nd_dadcompleted(a) (0) 127 #define ipv6nd_drop(a) {} 128 #define ipv6nd_expire(a, b) {} 129 #endif 130 131 #endif 132