Home | History | Annotate | Download | only in dhcpcd-6.8.2
      1 /*
      2  * dhcpcd - DHCP client daemon
      3  * Copyright (c) 2006-2015 Roy Marples <roy (at) 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 IPV4_H
     29 #define IPV4_H
     30 
     31 #include "dhcpcd.h"
     32 
     33 #ifdef IN_IFF_TENTATIVE
     34 #define IN_IFF_NOTUSEABLE \
     35         (IN_IFF_TENTATIVE | IN_IFF_DUPLICATED | IN_IFF_DETACHED)
     36 #endif
     37 
     38 struct rt {
     39 	TAILQ_ENTRY(rt) next;
     40 	struct in_addr dest;
     41 	struct in_addr net;
     42 	struct in_addr gate;
     43 	const struct interface *iface;
     44 #ifdef HAVE_ROUTE_METRIC
     45 	unsigned int metric;
     46 #endif
     47 	struct in_addr src;
     48 	unsigned int flags;
     49 };
     50 TAILQ_HEAD(rt_head, rt);
     51 
     52 struct ipv4_addr {
     53 	TAILQ_ENTRY(ipv4_addr) next;
     54 	struct in_addr addr;
     55 	struct in_addr net;
     56 	struct in_addr dst;
     57 	struct interface *iface;
     58 	int addr_flags;
     59 };
     60 TAILQ_HEAD(ipv4_addrhead, ipv4_addr);
     61 
     62 struct ipv4_state {
     63 	struct ipv4_addrhead addrs;
     64 	struct rt_head routes;
     65 };
     66 
     67 #define IPV4_STATE(ifp)							       \
     68 	((struct ipv4_state *)(ifp)->if_data[IF_DATA_IPV4])
     69 #define IPV4_CSTATE(ifp)						       \
     70 	((const struct ipv4_state *)(ifp)->if_data[IF_DATA_IPV4])
     71 
     72 #ifdef INET
     73 int ipv4_init(struct dhcpcd_ctx *);
     74 int ipv4_ifcmp(const struct interface *, const struct interface *);
     75 uint8_t inet_ntocidr(struct in_addr);
     76 int inet_cidrtoaddr(int, struct in_addr *);
     77 uint32_t ipv4_getnetmask(uint32_t);
     78 int ipv4_addrexists(struct dhcpcd_ctx *, const struct in_addr *);
     79 
     80 #define STATE_ADDED		0x01
     81 #define STATE_FAKE		0x02
     82 
     83 void ipv4_buildroutes(struct dhcpcd_ctx *);
     84 void ipv4_finaliseaddr(struct interface *);
     85 int ipv4_deladdr(struct interface *ifp, const struct in_addr *,
     86     const struct in_addr *);
     87 void ipv4_applyaddr(void *);
     88 int ipv4_handlert(struct dhcpcd_ctx *, int, struct rt *);
     89 void ipv4_freerts(struct rt_head *);
     90 
     91 struct ipv4_addr *ipv4_iffindaddr(struct interface *,
     92     const struct in_addr *, const struct in_addr *);
     93 struct ipv4_addr *ipv4_iffindlladdr(struct interface *);
     94 struct ipv4_addr *ipv4_findaddr(struct dhcpcd_ctx *, const struct in_addr *);
     95 void ipv4_handleifa(struct dhcpcd_ctx *, int, struct if_head *, const char *,
     96     const struct in_addr *, const struct in_addr *, const struct in_addr *,
     97     int);
     98 
     99 void ipv4_freeroutes(struct rt_head *);
    100 
    101 void ipv4_free(struct interface *);
    102 void ipv4_ctxfree(struct dhcpcd_ctx *);
    103 #else
    104 #define ipv4_init(a) (-1)
    105 #define ipv4_sortinterfaces(a) {}
    106 #define ipv4_applyaddr(a) {}
    107 #define ipv4_freeroutes(a) {}
    108 #define ipv4_free(a) {}
    109 #define ipv4_ctxfree(a) {}
    110 #define ipv4_addrexists(a, b) (0)
    111 #endif
    112 
    113 #endif
    114