1/*
2 * dhcpcd - route management
3 * Copyright (c) 2006-2019 Roy Marples <roy@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 ROUTE_H
29#define ROUTE_H
30
31#include <sys/socket.h>
32#include <net/route.h>
33
34#include <stdbool.h>
35
36#include "dhcpcd.h"
37#include "sa.h"
38
39/* Some systems have route metrics.
40 * OpenBSD route priority is not this. */
41#ifndef HAVE_ROUTE_METRIC
42# if defined(__linux__)
43# define HAVE_ROUTE_METRIC 1
44# endif
45#endif
46
47#if defined(__OpenBSD__) || defined (__sun)
48# define ROUTE_PER_GATEWAY
49/* XXX dhcpcd doesn't really support this yet.
50 * But that's generally OK if only dhcpcd is managing routes. */
51#endif
52
53/* OpenBSD defines this as a "convienience" ..... we work around it. */
54#ifdef __OpenBSD__
55#undef rt_mtu
56#endif
57
58struct rt {
59 TAILQ_ENTRY(rt) rt_next;
60 union sa_ss rt_ss_dest;
61#define rt_dest rt_ss_dest.sa
62 union sa_ss rt_ss_netmask;
63#define rt_netmask rt_ss_netmask.sa
64 union sa_ss rt_ss_gateway;
65#define rt_gateway rt_ss_gateway.sa
66 struct interface *rt_ifp;
67 union sa_ss rt_ss_ifa;
68#define rt_ifa rt_ss_ifa.sa
69 unsigned int rt_flags;
70 unsigned int rt_mtu;
71#ifdef HAVE_ROUTE_METRIC
72 unsigned int rt_metric;
73#endif
74 unsigned int rt_dflags;
75#define RTDF_INIT 0x01 /* Generated by if_initrt() */
76#define RTDF_IFA_ROUTE 0x02 /* Address generated route */
77#define RTDF_FAKE 0x04 /* Maybe us on lease reboot */
78#define RTDF_RA 0x08 /* Router Advertisement */
79#define RTDF_DHCP 0x10 /* DHCP route */
80#define RTDF_STATIC 0x20 /* Configured in dhcpcd */
81};
82TAILQ_HEAD(rt_head, rt);
83
84void rt_init(struct dhcpcd_ctx *);
85void rt_dispose(struct dhcpcd_ctx *);
86struct rt * rt_find(struct rt_head *, const struct rt *);
87void rt_free(struct rt *);
88void rt_freeif(struct interface *);
89void rt_headclear0(struct dhcpcd_ctx *, struct rt_head *, int);
90void rt_headclear(struct rt_head *, int);
91void rt_headfreeif(struct rt_head *);
92struct rt * rt_new0(struct dhcpcd_ctx *);
93void rt_setif(struct rt *, struct interface *);
94struct rt * rt_new(struct interface *);
95void rt_recvrt(int, const struct rt *, pid_t);
96void rt_build(struct dhcpcd_ctx *, int);
97
98#endif
99