1 /* SPDX-License-Identifier: BSD-2-Clause */ 2 /* 3 * dhcpcd - DHCP client daemon 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 IPV4LL_H 30 #define IPV4LL_H 31 32 #define LINKLOCAL_ADDR 0xa9fe0000 33 #define LINKLOCAL_MASK IN_CLASSB_NET 34 #define LINKLOCAL_BCAST (LINKLOCAL_ADDR | ~LINKLOCAL_MASK) 35 36 #ifndef IN_LINKLOCAL 37 # define IN_LINKLOCAL(addr) ((addr & IN_CLASSB_NET) == LINKLOCAL_ADDR) 38 #endif 39 40 #ifdef IPV4LL 41 #include "arp.h" 42 43 struct ipv4ll_state { 44 struct in_addr pickedaddr; 45 struct ipv4_addr *addr; 46 char randomstate[128]; 47 bool seeded; 48 bool down; 49 size_t conflicts; 50 #ifndef KERNEL_RFC5227 51 struct arp_state *arp; 52 #endif 53 }; 54 55 #define IPV4LL_STATE(ifp) \ 56 ((struct ipv4ll_state *)(ifp)->if_data[IF_DATA_IPV4LL]) 57 #define IPV4LL_CSTATE(ifp) \ 58 ((const struct ipv4ll_state *)(ifp)->if_data[IF_DATA_IPV4LL]) 59 #define IPV4LL_STATE_RUNNING(ifp) \ 60 (IPV4LL_CSTATE((ifp)) && !IPV4LL_CSTATE((ifp))->down && \ 61 (IPV4LL_CSTATE((ifp))->addr != NULL)) 62 63 int ipv4ll_subnetroute(rb_tree_t *, struct interface *); 64 int ipv4ll_defaultroute(rb_tree_t *,struct interface *); 65 ssize_t ipv4ll_env(FILE *, const char *, const struct interface *); 66 void ipv4ll_start(void *); 67 void ipv4ll_claimed(void *); 68 void ipv4ll_handle_failure(void *); 69 struct ipv4_addr *ipv4ll_handleifa(int, struct ipv4_addr *, pid_t pid); 70 #ifdef HAVE_ROUTE_METRIC 71 int ipv4ll_recvrt(int, const struct rt *); 72 #endif 73 74 void ipv4ll_reset(struct interface *); 75 void ipv4ll_drop(struct interface *); 76 void ipv4ll_free(struct interface *); 77 #endif 78 79 #endif 80