Mercurial > hg > dhcpcd
annotate src/route.c @ 5577:4da45107d87a draft
script: Use rt_proto_add to ensure no duplicate interfaces on OpenBSD
OpenBSD allows matching priorities, so we need to take the interfaces
in the order given to ensure uniqueness.
| author | Roy Marples <roy@marples.name> |
|---|---|
| date | Mon, 18 Jan 2021 11:31:05 +0000 |
| parents | 4fe5c2a71254 |
| children |
| rev | line source |
|---|---|
|
4548
c7df03794de3
Add SPDX identifiers to all dhcpcd source files.
Yegor Yefremov <yegorslists@googlemail.com>
parents:
4522
diff
changeset
|
1 /* SPDX-License-Identifier: BSD-2-Clause */ |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
2 /* |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
3 * dhcpcd - route management |
| 4922 | 4 * Copyright (c) 2006-2020 Roy Marples <roy@marples.name> |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
5 * All rights reserved |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
6 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
7 * Redistribution and use in source and binary forms, with or without |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
8 * modification, are permitted provided that the following conditions |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
9 * are met: |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
10 * 1. Redistributions of source code must retain the above copyright |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
11 * notice, this list of conditions and the following disclaimer. |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
12 * 2. Redistributions in binary form must reproduce the above copyright |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
13 * notice, this list of conditions and the following disclaimer in the |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
14 * documentation and/or other materials provided with the distribution. |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
15 * |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
26 * SUCH DAMAGE. |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
27 */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
28 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
29 #include <assert.h> |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
30 #include <ctype.h> |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
31 #include <errno.h> |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
32 #include <stdbool.h> |
|
4379
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
33 #include <stddef.h> |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
34 #include <stdlib.h> |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
35 #include <string.h> |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
36 #include <unistd.h> |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
37 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
38 #include "config.h" |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
39 #include "common.h" |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
40 #include "dhcpcd.h" |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
41 #include "if.h" |
|
4648
16b119f7fc39
inet6: Don't install a default route if no global address
Roy Marples <roy@marples.name>
parents:
4629
diff
changeset
|
42 #include "if-options.h" |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
43 #include "ipv4.h" |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
44 #include "ipv4ll.h" |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
45 #include "ipv6.h" |
| 4010 | 46 #include "logerr.h" |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
47 #include "route.h" |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
48 #include "sa.h" |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
49 |
| 4389 | 50 /* Needed for NetBSD-6, 7 and 8. */ |
| 51 #ifndef RB_TREE_FOREACH_SAFE | |
| 52 #ifndef RB_TREE_PREV | |
| 53 #define RB_TREE_NEXT(T, N) rb_tree_iterate((T), (N), RB_DIR_RIGHT) | |
| 54 #define RB_TREE_PREV(T, N) rb_tree_iterate((T), (N), RB_DIR_LEFT) | |
| 55 #endif | |
| 56 #define RB_TREE_FOREACH_SAFE(N, T, S) \ | |
| 57 for ((N) = RB_TREE_MIN(T); \ | |
| 58 (N) && ((S) = RB_TREE_NEXT((T), (N)), 1); \ | |
| 59 (N) = (S)) | |
| 60 #define RB_TREE_FOREACH_REVERSE_SAFE(N, T, S) \ | |
| 61 for ((N) = RB_TREE_MAX(T); \ | |
| 62 (N) && ((S) = RB_TREE_PREV((T), (N)), 1); \ | |
| 63 (N) = (S)) | |
| 64 #endif | |
| 65 | |
|
4404
6c1ae8d24811
route: Guard free route list stats
Roy Marples <roy@marples.name>
parents:
4402
diff
changeset
|
66 #ifdef RT_FREE_ROUTE_TABLE_STATS |
|
6c1ae8d24811
route: Guard free route list stats
Roy Marples <roy@marples.name>
parents:
4402
diff
changeset
|
67 static size_t croutes; |
|
4402
72c7bfdd522b
route: report usage data when using a free list
Roy Marples <roy@marples.name>
parents:
4401
diff
changeset
|
68 static size_t nroutes; |
|
72c7bfdd522b
route: report usage data when using a free list
Roy Marples <roy@marples.name>
parents:
4401
diff
changeset
|
69 static size_t froutes; |
|
4404
6c1ae8d24811
route: Guard free route list stats
Roy Marples <roy@marples.name>
parents:
4402
diff
changeset
|
70 static size_t mroutes; |
|
4402
72c7bfdd522b
route: report usage data when using a free list
Roy Marples <roy@marples.name>
parents:
4401
diff
changeset
|
71 #endif |
|
72c7bfdd522b
route: report usage data when using a free list
Roy Marples <roy@marples.name>
parents:
4401
diff
changeset
|
72 |
|
4518
e523b7420583
route: Fix OS route comparison
Roy Marples <roy@marples.name>
parents:
4515
diff
changeset
|
73 static void |
|
e523b7420583
route: Fix OS route comparison
Roy Marples <roy@marples.name>
parents:
4515
diff
changeset
|
74 rt_maskedaddr(struct sockaddr *dst, |
|
e523b7420583
route: Fix OS route comparison
Roy Marples <roy@marples.name>
parents:
4515
diff
changeset
|
75 const struct sockaddr *addr, const struct sockaddr *netmask) |
|
e523b7420583
route: Fix OS route comparison
Roy Marples <roy@marples.name>
parents:
4515
diff
changeset
|
76 { |
|
e523b7420583
route: Fix OS route comparison
Roy Marples <roy@marples.name>
parents:
4515
diff
changeset
|
77 const char *addrp = addr->sa_data, *netmaskp = netmask->sa_data; |
|
e523b7420583
route: Fix OS route comparison
Roy Marples <roy@marples.name>
parents:
4515
diff
changeset
|
78 char *dstp = dst->sa_data; |
|
e523b7420583
route: Fix OS route comparison
Roy Marples <roy@marples.name>
parents:
4515
diff
changeset
|
79 const char *addre = (char *)dst + sa_len(addr); |
|
e523b7420583
route: Fix OS route comparison
Roy Marples <roy@marples.name>
parents:
4515
diff
changeset
|
80 const char *netmaske = (char *)dst + MIN(sa_len(addr), sa_len(netmask)); |
|
e523b7420583
route: Fix OS route comparison
Roy Marples <roy@marples.name>
parents:
4515
diff
changeset
|
81 |
|
e523b7420583
route: Fix OS route comparison
Roy Marples <roy@marples.name>
parents:
4515
diff
changeset
|
82 dst->sa_family = addr->sa_family; |
|
e523b7420583
route: Fix OS route comparison
Roy Marples <roy@marples.name>
parents:
4515
diff
changeset
|
83 #ifdef HAVE_SA_LEN |
|
e523b7420583
route: Fix OS route comparison
Roy Marples <roy@marples.name>
parents:
4515
diff
changeset
|
84 dst->sa_len = addr->sa_len; |
|
e523b7420583
route: Fix OS route comparison
Roy Marples <roy@marples.name>
parents:
4515
diff
changeset
|
85 #endif |
|
e523b7420583
route: Fix OS route comparison
Roy Marples <roy@marples.name>
parents:
4515
diff
changeset
|
86 |
|
e523b7420583
route: Fix OS route comparison
Roy Marples <roy@marples.name>
parents:
4515
diff
changeset
|
87 if (sa_is_unspecified(netmask)) { |
|
e523b7420583
route: Fix OS route comparison
Roy Marples <roy@marples.name>
parents:
4515
diff
changeset
|
88 if (addre > dstp) |
|
e523b7420583
route: Fix OS route comparison
Roy Marples <roy@marples.name>
parents:
4515
diff
changeset
|
89 memcpy(dstp, addrp, (size_t)(addre - dstp)); |
|
e523b7420583
route: Fix OS route comparison
Roy Marples <roy@marples.name>
parents:
4515
diff
changeset
|
90 return; |
|
e523b7420583
route: Fix OS route comparison
Roy Marples <roy@marples.name>
parents:
4515
diff
changeset
|
91 } |
|
e523b7420583
route: Fix OS route comparison
Roy Marples <roy@marples.name>
parents:
4515
diff
changeset
|
92 |
|
e523b7420583
route: Fix OS route comparison
Roy Marples <roy@marples.name>
parents:
4515
diff
changeset
|
93 while (dstp < netmaske) |
|
e523b7420583
route: Fix OS route comparison
Roy Marples <roy@marples.name>
parents:
4515
diff
changeset
|
94 *dstp++ = *addrp++ & *netmaskp++; |
|
e523b7420583
route: Fix OS route comparison
Roy Marples <roy@marples.name>
parents:
4515
diff
changeset
|
95 if (dstp < addre) |
|
e523b7420583
route: Fix OS route comparison
Roy Marples <roy@marples.name>
parents:
4515
diff
changeset
|
96 memset(dstp, 0, (size_t)(addre - dstp)); |
|
e523b7420583
route: Fix OS route comparison
Roy Marples <roy@marples.name>
parents:
4515
diff
changeset
|
97 } |
|
e523b7420583
route: Fix OS route comparison
Roy Marples <roy@marples.name>
parents:
4515
diff
changeset
|
98 |
|
4522
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
99 int |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
100 rt_cmp_dest(const struct rt *rt1, const struct rt *rt2) |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
101 { |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
102 union sa_ss ma1 = { .sa.sa_family = AF_UNSPEC }; |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
103 union sa_ss ma2 = { .sa.sa_family = AF_UNSPEC }; |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
104 |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
105 rt_maskedaddr(&ma1.sa, &rt1->rt_dest, &rt1->rt_netmask); |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
106 rt_maskedaddr(&ma2.sa, &rt2->rt_dest, &rt2->rt_netmask); |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
107 return sa_cmp(&ma1.sa, &ma2.sa); |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
108 } |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
109 |
|
4294
95fa4f3d6b1a
Some systems mark a host route using RTF_HOST and some use an
Roy Marples <roy@marples.name>
parents:
4261
diff
changeset
|
110 /* |
|
95fa4f3d6b1a
Some systems mark a host route using RTF_HOST and some use an
Roy Marples <roy@marples.name>
parents:
4261
diff
changeset
|
111 * On some systems, host routes have no need for a netmask. |
|
95fa4f3d6b1a
Some systems mark a host route using RTF_HOST and some use an
Roy Marples <roy@marples.name>
parents:
4261
diff
changeset
|
112 * However DHCP specifies host routes using an all-ones netmask. |
|
95fa4f3d6b1a
Some systems mark a host route using RTF_HOST and some use an
Roy Marples <roy@marples.name>
parents:
4261
diff
changeset
|
113 * This handy function allows easy comparison when the two |
|
95fa4f3d6b1a
Some systems mark a host route using RTF_HOST and some use an
Roy Marples <roy@marples.name>
parents:
4261
diff
changeset
|
114 * differ. |
|
95fa4f3d6b1a
Some systems mark a host route using RTF_HOST and some use an
Roy Marples <roy@marples.name>
parents:
4261
diff
changeset
|
115 */ |
|
95fa4f3d6b1a
Some systems mark a host route using RTF_HOST and some use an
Roy Marples <roy@marples.name>
parents:
4261
diff
changeset
|
116 static int |
|
95fa4f3d6b1a
Some systems mark a host route using RTF_HOST and some use an
Roy Marples <roy@marples.name>
parents:
4261
diff
changeset
|
117 rt_cmp_netmask(const struct rt *rt1, const struct rt *rt2) |
|
95fa4f3d6b1a
Some systems mark a host route using RTF_HOST and some use an
Roy Marples <roy@marples.name>
parents:
4261
diff
changeset
|
118 { |
|
95fa4f3d6b1a
Some systems mark a host route using RTF_HOST and some use an
Roy Marples <roy@marples.name>
parents:
4261
diff
changeset
|
119 |
|
95fa4f3d6b1a
Some systems mark a host route using RTF_HOST and some use an
Roy Marples <roy@marples.name>
parents:
4261
diff
changeset
|
120 if (rt1->rt_flags & RTF_HOST && rt2->rt_flags & RTF_HOST) |
|
95fa4f3d6b1a
Some systems mark a host route using RTF_HOST and some use an
Roy Marples <roy@marples.name>
parents:
4261
diff
changeset
|
121 return 0; |
|
95fa4f3d6b1a
Some systems mark a host route using RTF_HOST and some use an
Roy Marples <roy@marples.name>
parents:
4261
diff
changeset
|
122 return sa_cmp(&rt1->rt_netmask, &rt2->rt_netmask); |
|
95fa4f3d6b1a
Some systems mark a host route using RTF_HOST and some use an
Roy Marples <roy@marples.name>
parents:
4261
diff
changeset
|
123 } |
|
95fa4f3d6b1a
Some systems mark a host route using RTF_HOST and some use an
Roy Marples <roy@marples.name>
parents:
4261
diff
changeset
|
124 |
|
4522
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
125 static int |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
126 rt_compare_os(__unused void *context, const void *node1, const void *node2) |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
127 { |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
128 const struct rt *rt1 = node1, *rt2 = node2; |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
129 int c; |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
130 |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
131 /* Sort by masked destination. */ |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
132 c = rt_cmp_dest(rt1, rt2); |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
133 if (c != 0) |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
134 return c; |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
135 |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
136 #ifdef HAVE_ROUTE_METRIC |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
137 c = (int)(rt1->rt_ifp->metric - rt2->rt_ifp->metric); |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
138 #endif |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
139 return c; |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
140 } |
|
4392
af390080e632
route: replace rt_find with rb_tree_find_node
Roy Marples <roy@marples.name>
parents:
4391
diff
changeset
|
141 |
|
af390080e632
route: replace rt_find with rb_tree_find_node
Roy Marples <roy@marples.name>
parents:
4391
diff
changeset
|
142 static int |
|
4629
06b0dbf7a171
route: Just compare order when adding routes from options.
Roy Marples <roy@marples.name>
parents:
4599
diff
changeset
|
143 rt_compare_list(__unused void *context, const void *node1, const void *node2) |
|
06b0dbf7a171
route: Just compare order when adding routes from options.
Roy Marples <roy@marples.name>
parents:
4599
diff
changeset
|
144 { |
|
06b0dbf7a171
route: Just compare order when adding routes from options.
Roy Marples <roy@marples.name>
parents:
4599
diff
changeset
|
145 const struct rt *rt1 = node1, *rt2 = node2; |
|
06b0dbf7a171
route: Just compare order when adding routes from options.
Roy Marples <roy@marples.name>
parents:
4599
diff
changeset
|
146 |
|
06b0dbf7a171
route: Just compare order when adding routes from options.
Roy Marples <roy@marples.name>
parents:
4599
diff
changeset
|
147 if (rt1->rt_order > rt2->rt_order) |
|
06b0dbf7a171
route: Just compare order when adding routes from options.
Roy Marples <roy@marples.name>
parents:
4599
diff
changeset
|
148 return 1; |
|
06b0dbf7a171
route: Just compare order when adding routes from options.
Roy Marples <roy@marples.name>
parents:
4599
diff
changeset
|
149 if (rt1->rt_order < rt2->rt_order) |
|
06b0dbf7a171
route: Just compare order when adding routes from options.
Roy Marples <roy@marples.name>
parents:
4599
diff
changeset
|
150 return -1; |
|
06b0dbf7a171
route: Just compare order when adding routes from options.
Roy Marples <roy@marples.name>
parents:
4599
diff
changeset
|
151 return 0; |
|
06b0dbf7a171
route: Just compare order when adding routes from options.
Roy Marples <roy@marples.name>
parents:
4599
diff
changeset
|
152 } |
|
06b0dbf7a171
route: Just compare order when adding routes from options.
Roy Marples <roy@marples.name>
parents:
4599
diff
changeset
|
153 |
|
06b0dbf7a171
route: Just compare order when adding routes from options.
Roy Marples <roy@marples.name>
parents:
4599
diff
changeset
|
154 static int |
|
06b0dbf7a171
route: Just compare order when adding routes from options.
Roy Marples <roy@marples.name>
parents:
4599
diff
changeset
|
155 rt_compare_proto(void *context, const void *node1, const void *node2) |
|
4379
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
156 { |
|
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
157 const struct rt *rt1 = node1, *rt2 = node2; |
|
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
158 int c; |
|
4414
126f7acde2eb
route: prefer interfaces with a carrier
Roy Marples <roy@marples.name>
parents:
4404
diff
changeset
|
159 struct interface *ifp1, *ifp2; |
|
4379
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
160 |
|
4522
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
161 assert(rt1->rt_ifp != NULL); |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
162 assert(rt2->rt_ifp != NULL); |
|
4414
126f7acde2eb
route: prefer interfaces with a carrier
Roy Marples <roy@marples.name>
parents:
4404
diff
changeset
|
163 ifp1 = rt1->rt_ifp; |
|
126f7acde2eb
route: prefer interfaces with a carrier
Roy Marples <roy@marples.name>
parents:
4404
diff
changeset
|
164 ifp2 = rt2->rt_ifp; |
|
126f7acde2eb
route: prefer interfaces with a carrier
Roy Marples <roy@marples.name>
parents:
4404
diff
changeset
|
165 |
|
4522
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
166 /* Prefer interfaces with a carrier. */ |
|
4414
126f7acde2eb
route: prefer interfaces with a carrier
Roy Marples <roy@marples.name>
parents:
4404
diff
changeset
|
167 c = ifp1->carrier - ifp2->carrier; |
|
126f7acde2eb
route: prefer interfaces with a carrier
Roy Marples <roy@marples.name>
parents:
4404
diff
changeset
|
168 if (c != 0) |
|
126f7acde2eb
route: prefer interfaces with a carrier
Roy Marples <roy@marples.name>
parents:
4404
diff
changeset
|
169 return -c; |
|
126f7acde2eb
route: prefer interfaces with a carrier
Roy Marples <roy@marples.name>
parents:
4404
diff
changeset
|
170 |
|
5567
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5546
diff
changeset
|
171 /* Prefer roaming over non roaming if both carriers are down. */ |
|
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5546
diff
changeset
|
172 if (ifp1->carrier == LINK_DOWN && ifp2->carrier == LINK_DOWN) { |
|
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5546
diff
changeset
|
173 bool roam1 = if_roaming(ifp1); |
|
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5546
diff
changeset
|
174 bool roam2 = if_roaming(ifp2); |
|
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5546
diff
changeset
|
175 |
|
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5546
diff
changeset
|
176 if (roam1 != roam2) |
|
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5546
diff
changeset
|
177 return roam1 ? 1 : -1; |
|
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5546
diff
changeset
|
178 } |
|
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5546
diff
changeset
|
179 |
|
5406
c03103d18249
route: Ensure IPv4LL routes always come last in priority
Roy Marples <roy@marples.name>
parents:
5133
diff
changeset
|
180 #ifdef INET |
|
c03103d18249
route: Ensure IPv4LL routes always come last in priority
Roy Marples <roy@marples.name>
parents:
5133
diff
changeset
|
181 /* IPv4LL routes always come last */ |
| 5407 | 182 if (rt1->rt_dflags & RTDF_IPV4LL && !(rt2->rt_dflags & RTDF_IPV4LL)) |
|
5406
c03103d18249
route: Ensure IPv4LL routes always come last in priority
Roy Marples <roy@marples.name>
parents:
5133
diff
changeset
|
183 return -1; |
| 5407 | 184 else if (!(rt1->rt_dflags & RTDF_IPV4LL) && rt2->rt_dflags & RTDF_IPV4LL) |
|
5406
c03103d18249
route: Ensure IPv4LL routes always come last in priority
Roy Marples <roy@marples.name>
parents:
5133
diff
changeset
|
185 return 1; |
|
c03103d18249
route: Ensure IPv4LL routes always come last in priority
Roy Marples <roy@marples.name>
parents:
5133
diff
changeset
|
186 #endif |
|
c03103d18249
route: Ensure IPv4LL routes always come last in priority
Roy Marples <roy@marples.name>
parents:
5133
diff
changeset
|
187 |
|
4522
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
188 /* Lower metric interfaces come first. */ |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
189 c = (int)(ifp1->metric - ifp2->metric); |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
190 if (c != 0) |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
191 return c; |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
192 |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
193 /* Finally the order in which the route was given to us. */ |
|
4629
06b0dbf7a171
route: Just compare order when adding routes from options.
Roy Marples <roy@marples.name>
parents:
4599
diff
changeset
|
194 return rt_compare_list(context, rt1, rt2); |
|
4379
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
195 } |
|
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
196 |
|
4392
af390080e632
route: replace rt_find with rb_tree_find_node
Roy Marples <roy@marples.name>
parents:
4391
diff
changeset
|
197 static const rb_tree_ops_t rt_compare_os_ops = { |
|
4522
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
198 .rbto_compare_nodes = rt_compare_os, |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
199 .rbto_compare_key = rt_compare_os, |
|
4392
af390080e632
route: replace rt_find with rb_tree_find_node
Roy Marples <roy@marples.name>
parents:
4391
diff
changeset
|
200 .rbto_node_offset = offsetof(struct rt, rt_tree), |
|
4522
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
201 .rbto_context = NULL |
|
4392
af390080e632
route: replace rt_find with rb_tree_find_node
Roy Marples <roy@marples.name>
parents:
4391
diff
changeset
|
202 }; |
|
af390080e632
route: replace rt_find with rb_tree_find_node
Roy Marples <roy@marples.name>
parents:
4391
diff
changeset
|
203 |
|
4629
06b0dbf7a171
route: Just compare order when adding routes from options.
Roy Marples <roy@marples.name>
parents:
4599
diff
changeset
|
204 const rb_tree_ops_t rt_compare_list_ops = { |
|
06b0dbf7a171
route: Just compare order when adding routes from options.
Roy Marples <roy@marples.name>
parents:
4599
diff
changeset
|
205 .rbto_compare_nodes = rt_compare_list, |
|
06b0dbf7a171
route: Just compare order when adding routes from options.
Roy Marples <roy@marples.name>
parents:
4599
diff
changeset
|
206 .rbto_compare_key = rt_compare_list, |
|
06b0dbf7a171
route: Just compare order when adding routes from options.
Roy Marples <roy@marples.name>
parents:
4599
diff
changeset
|
207 .rbto_node_offset = offsetof(struct rt, rt_tree), |
|
06b0dbf7a171
route: Just compare order when adding routes from options.
Roy Marples <roy@marples.name>
parents:
4599
diff
changeset
|
208 .rbto_context = NULL |
|
06b0dbf7a171
route: Just compare order when adding routes from options.
Roy Marples <roy@marples.name>
parents:
4599
diff
changeset
|
209 }; |
|
06b0dbf7a171
route: Just compare order when adding routes from options.
Roy Marples <roy@marples.name>
parents:
4599
diff
changeset
|
210 |
|
4522
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
211 const rb_tree_ops_t rt_compare_proto_ops = { |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
212 .rbto_compare_nodes = rt_compare_proto, |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
213 .rbto_compare_key = rt_compare_proto, |
|
4379
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
214 .rbto_node_offset = offsetof(struct rt, rt_tree), |
|
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
215 .rbto_context = NULL |
|
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
216 }; |
|
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
217 |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4396
diff
changeset
|
218 #ifdef RT_FREE_ROUTE_TABLE |
|
4392
af390080e632
route: replace rt_find with rb_tree_find_node
Roy Marples <roy@marples.name>
parents:
4391
diff
changeset
|
219 static int |
|
af390080e632
route: replace rt_find with rb_tree_find_node
Roy Marples <roy@marples.name>
parents:
4391
diff
changeset
|
220 rt_compare_free(__unused void *context, const void *node1, const void *node2) |
|
af390080e632
route: replace rt_find with rb_tree_find_node
Roy Marples <roy@marples.name>
parents:
4391
diff
changeset
|
221 { |
|
af390080e632
route: replace rt_find with rb_tree_find_node
Roy Marples <roy@marples.name>
parents:
4391
diff
changeset
|
222 |
|
4395
41bab8a02727
OpenBSD: Fix segfaults when deleting MPATH routes
Roy Marples <roy@marples.name>
parents:
4392
diff
changeset
|
223 return node1 == node2 ? 0 : node1 < node2 ? -1 : 1; |
|
4392
af390080e632
route: replace rt_find with rb_tree_find_node
Roy Marples <roy@marples.name>
parents:
4391
diff
changeset
|
224 } |
|
af390080e632
route: replace rt_find with rb_tree_find_node
Roy Marples <roy@marples.name>
parents:
4391
diff
changeset
|
225 |
|
af390080e632
route: replace rt_find with rb_tree_find_node
Roy Marples <roy@marples.name>
parents:
4391
diff
changeset
|
226 static const rb_tree_ops_t rt_compare_free_ops = { |
|
af390080e632
route: replace rt_find with rb_tree_find_node
Roy Marples <roy@marples.name>
parents:
4391
diff
changeset
|
227 .rbto_compare_nodes = rt_compare_free, |
|
af390080e632
route: replace rt_find with rb_tree_find_node
Roy Marples <roy@marples.name>
parents:
4391
diff
changeset
|
228 .rbto_compare_key = rt_compare_free, |
|
af390080e632
route: replace rt_find with rb_tree_find_node
Roy Marples <roy@marples.name>
parents:
4391
diff
changeset
|
229 .rbto_node_offset = offsetof(struct rt, rt_tree), |
|
af390080e632
route: replace rt_find with rb_tree_find_node
Roy Marples <roy@marples.name>
parents:
4391
diff
changeset
|
230 .rbto_context = NULL |
|
af390080e632
route: replace rt_find with rb_tree_find_node
Roy Marples <roy@marples.name>
parents:
4391
diff
changeset
|
231 }; |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4396
diff
changeset
|
232 #endif |
|
4392
af390080e632
route: replace rt_find with rb_tree_find_node
Roy Marples <roy@marples.name>
parents:
4391
diff
changeset
|
233 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
234 void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
235 rt_init(struct dhcpcd_ctx *ctx) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
236 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
237 |
|
4392
af390080e632
route: replace rt_find with rb_tree_find_node
Roy Marples <roy@marples.name>
parents:
4391
diff
changeset
|
238 rb_tree_init(&ctx->routes, &rt_compare_os_ops); |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4396
diff
changeset
|
239 #ifdef RT_FREE_ROUTE_TABLE |
|
4392
af390080e632
route: replace rt_find with rb_tree_find_node
Roy Marples <roy@marples.name>
parents:
4391
diff
changeset
|
240 rb_tree_init(&ctx->froutes, &rt_compare_free_ops); |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4396
diff
changeset
|
241 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
242 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
243 |
|
4522
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
244 bool |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
245 rt_is_default(const struct rt *rt) |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
246 { |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
247 |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
248 return sa_is_unspecified(&rt->rt_dest) && |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
249 sa_is_unspecified(&rt->rt_netmask); |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
250 } |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
251 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
252 static void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
253 rt_desc(const char *cmd, const struct rt *rt) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
254 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
255 char dest[INET_MAX_ADDRSTRLEN], gateway[INET_MAX_ADDRSTRLEN]; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
256 int prefix; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
257 const char *ifname; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
258 bool gateway_unspec; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
259 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
260 assert(cmd != NULL); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
261 assert(rt != NULL); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
262 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
263 sa_addrtop(&rt->rt_dest, dest, sizeof(dest)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
264 prefix = sa_toprefix(&rt->rt_netmask); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
265 sa_addrtop(&rt->rt_gateway, gateway, sizeof(gateway)); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
266 gateway_unspec = sa_is_unspecified(&rt->rt_gateway); |
|
4294
95fa4f3d6b1a
Some systems mark a host route using RTF_HOST and some use an
Roy Marples <roy@marples.name>
parents:
4261
diff
changeset
|
267 ifname = rt->rt_ifp == NULL ? "(null)" : rt->rt_ifp->name; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
268 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
269 if (rt->rt_flags & RTF_HOST) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
270 if (gateway_unspec) |
|
4024
0984f93d896e
To be consitent, do the same to loginfo as we just did for logdebug.
Roy Marples <roy@marples.name>
parents:
4010
diff
changeset
|
271 loginfox("%s: %s host route to %s", |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
272 ifname, cmd, dest); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
273 else |
|
4024
0984f93d896e
To be consitent, do the same to loginfo as we just did for logdebug.
Roy Marples <roy@marples.name>
parents:
4010
diff
changeset
|
274 loginfox("%s: %s host route to %s via %s", |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
275 ifname, cmd, dest, gateway); |
|
4522
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
276 } else if (rt_is_default(rt)) { |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
277 if (gateway_unspec) |
|
4024
0984f93d896e
To be consitent, do the same to loginfo as we just did for logdebug.
Roy Marples <roy@marples.name>
parents:
4010
diff
changeset
|
278 loginfox("%s: %s default route", |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
279 ifname, cmd); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
280 else |
|
4024
0984f93d896e
To be consitent, do the same to loginfo as we just did for logdebug.
Roy Marples <roy@marples.name>
parents:
4010
diff
changeset
|
281 loginfox("%s: %s default route via %s", |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
282 ifname, cmd, gateway); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
283 } else if (gateway_unspec) |
|
4024
0984f93d896e
To be consitent, do the same to loginfo as we just did for logdebug.
Roy Marples <roy@marples.name>
parents:
4010
diff
changeset
|
284 loginfox("%s: %s%s route to %s/%d", |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
285 ifname, cmd, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
286 rt->rt_flags & RTF_REJECT ? " reject" : "", |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
287 dest, prefix); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
288 else |
|
4024
0984f93d896e
To be consitent, do the same to loginfo as we just did for logdebug.
Roy Marples <roy@marples.name>
parents:
4010
diff
changeset
|
289 loginfox("%s: %s%s route to %s/%d via %s", |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
290 ifname, cmd, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
291 rt->rt_flags & RTF_REJECT ? " reject" : "", |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
292 dest, prefix, gateway); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
293 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
294 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
295 void |
|
4379
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
296 rt_headclear0(struct dhcpcd_ctx *ctx, rb_tree_t *rts, int af) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
297 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
298 struct rt *rt, *rtn; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
299 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
300 if (rts == NULL) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
301 return; |
|
4249
c30233f8cca3
routes: allow a head clear with a context
Roy Marples <roy@marples.name>
parents:
4248
diff
changeset
|
302 assert(ctx != NULL); |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4396
diff
changeset
|
303 #ifdef RT_FREE_ROUTE_TABLE |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
304 assert(&ctx->froutes != rts); |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4396
diff
changeset
|
305 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
306 |
|
4379
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
307 RB_TREE_FOREACH_SAFE(rt, rts, rtn) { |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
308 if (af != AF_UNSPEC && |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
309 rt->rt_dest.sa_family != af && |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
310 rt->rt_gateway.sa_family != af) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
311 continue; |
|
4379
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
312 rb_tree_remove_node(rts, rt); |
|
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
313 rt_free(rt); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
314 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
315 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
316 |
|
4249
c30233f8cca3
routes: allow a head clear with a context
Roy Marples <roy@marples.name>
parents:
4248
diff
changeset
|
317 void |
|
4379
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
318 rt_headclear(rb_tree_t *rts, int af) |
|
4249
c30233f8cca3
routes: allow a head clear with a context
Roy Marples <roy@marples.name>
parents:
4248
diff
changeset
|
319 { |
|
c30233f8cca3
routes: allow a head clear with a context
Roy Marples <roy@marples.name>
parents:
4248
diff
changeset
|
320 struct rt *rt; |
|
c30233f8cca3
routes: allow a head clear with a context
Roy Marples <roy@marples.name>
parents:
4248
diff
changeset
|
321 |
|
4379
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
322 if (rts == NULL || (rt = RB_TREE_MIN(rts)) == NULL) |
|
4249
c30233f8cca3
routes: allow a head clear with a context
Roy Marples <roy@marples.name>
parents:
4248
diff
changeset
|
323 return; |
|
c30233f8cca3
routes: allow a head clear with a context
Roy Marples <roy@marples.name>
parents:
4248
diff
changeset
|
324 rt_headclear0(rt->rt_ifp->ctx, rts, af); |
|
c30233f8cca3
routes: allow a head clear with a context
Roy Marples <roy@marples.name>
parents:
4248
diff
changeset
|
325 } |
|
c30233f8cca3
routes: allow a head clear with a context
Roy Marples <roy@marples.name>
parents:
4248
diff
changeset
|
326 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
327 static void |
|
4379
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
328 rt_headfree(rb_tree_t *rts) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
329 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
330 struct rt *rt; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
331 |
|
4379
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
332 while ((rt = RB_TREE_MIN(rts)) != NULL) { |
|
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
333 rb_tree_remove_node(rts, rt); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
334 free(rt); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
335 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
336 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
337 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
338 void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
339 rt_dispose(struct dhcpcd_ctx *ctx) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
340 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
341 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
342 assert(ctx != NULL); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
343 rt_headfree(&ctx->routes); |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4396
diff
changeset
|
344 #ifdef RT_FREE_ROUTE_TABLE |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
345 rt_headfree(&ctx->froutes); |
|
4404
6c1ae8d24811
route: Guard free route list stats
Roy Marples <roy@marples.name>
parents:
4402
diff
changeset
|
346 #ifdef RT_FREE_ROUTE_TABLE_STATS |
|
4402
72c7bfdd522b
route: report usage data when using a free list
Roy Marples <roy@marples.name>
parents:
4401
diff
changeset
|
347 logdebugx("free route list used %zu times", froutes); |
|
4404
6c1ae8d24811
route: Guard free route list stats
Roy Marples <roy@marples.name>
parents:
4402
diff
changeset
|
348 logdebugx("new routes from route free list %zu", nroutes); |
|
6c1ae8d24811
route: Guard free route list stats
Roy Marples <roy@marples.name>
parents:
4402
diff
changeset
|
349 logdebugx("maximum route free list size %zu", mroutes); |
|
6c1ae8d24811
route: Guard free route list stats
Roy Marples <roy@marples.name>
parents:
4402
diff
changeset
|
350 #endif |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4396
diff
changeset
|
351 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
352 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
353 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
354 struct rt * |
|
4248
2844dbb214b5
options: allow static routes to be configured on the command line
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
355 rt_new0(struct dhcpcd_ctx *ctx) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
356 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
357 struct rt *rt; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
358 |
|
4248
2844dbb214b5
options: allow static routes to be configured on the command line
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
359 assert(ctx != NULL); |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4396
diff
changeset
|
360 #ifdef RT_FREE_ROUTE_TABLE |
|
4402
72c7bfdd522b
route: report usage data when using a free list
Roy Marples <roy@marples.name>
parents:
4401
diff
changeset
|
361 if ((rt = RB_TREE_MIN(&ctx->froutes)) != NULL) { |
|
4379
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
362 rb_tree_remove_node(&ctx->froutes, rt); |
|
4404
6c1ae8d24811
route: Guard free route list stats
Roy Marples <roy@marples.name>
parents:
4402
diff
changeset
|
363 #ifdef RT_FREE_ROUTE_TABLE_STATS |
|
6c1ae8d24811
route: Guard free route list stats
Roy Marples <roy@marples.name>
parents:
4402
diff
changeset
|
364 croutes--; |
|
4402
72c7bfdd522b
route: report usage data when using a free list
Roy Marples <roy@marples.name>
parents:
4401
diff
changeset
|
365 nroutes++; |
|
4404
6c1ae8d24811
route: Guard free route list stats
Roy Marples <roy@marples.name>
parents:
4402
diff
changeset
|
366 #endif |
|
4402
72c7bfdd522b
route: report usage data when using a free list
Roy Marples <roy@marples.name>
parents:
4401
diff
changeset
|
367 } else |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4396
diff
changeset
|
368 #endif |
|
5133
fe2c149bb04d
route: revert prior change to rt_new0
Roy Marples <roy@marples.name>
parents:
5130
diff
changeset
|
369 if ((rt = malloc(sizeof(*rt))) == NULL) { |
| 4010 | 370 logerr(__func__); |
|
5133
fe2c149bb04d
route: revert prior change to rt_new0
Roy Marples <roy@marples.name>
parents:
5130
diff
changeset
|
371 return NULL; |
|
fe2c149bb04d
route: revert prior change to rt_new0
Roy Marples <roy@marples.name>
parents:
5130
diff
changeset
|
372 } |
|
fe2c149bb04d
route: revert prior change to rt_new0
Roy Marples <roy@marples.name>
parents:
5130
diff
changeset
|
373 memset(rt, 0, sizeof(*rt)); |
|
4248
2844dbb214b5
options: allow static routes to be configured on the command line
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
374 return rt; |
|
2844dbb214b5
options: allow static routes to be configured on the command line
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
375 } |
|
2844dbb214b5
options: allow static routes to be configured on the command line
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
376 |
|
2844dbb214b5
options: allow static routes to be configured on the command line
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
377 void |
|
2844dbb214b5
options: allow static routes to be configured on the command line
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
378 rt_setif(struct rt *rt, struct interface *ifp) |
|
2844dbb214b5
options: allow static routes to be configured on the command line
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
379 { |
|
2844dbb214b5
options: allow static routes to be configured on the command line
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
380 |
|
2844dbb214b5
options: allow static routes to be configured on the command line
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
381 assert(rt != NULL); |
|
2844dbb214b5
options: allow static routes to be configured on the command line
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
382 assert(ifp != NULL); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
383 rt->rt_ifp = ifp; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
384 #ifdef HAVE_ROUTE_METRIC |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
385 rt->rt_metric = ifp->metric; |
|
5567
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5546
diff
changeset
|
386 if (if_roaming(ifp)) |
|
4fe5c2a71254
hooks: add NOCARRIER_ROAMING reason
Roy Marples <roy@marples.name>
parents:
5546
diff
changeset
|
387 rt->rt_metric += RTMETRIC_ROAM; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
388 #endif |
|
4248
2844dbb214b5
options: allow static routes to be configured on the command line
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
389 } |
|
2844dbb214b5
options: allow static routes to be configured on the command line
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
390 |
|
2844dbb214b5
options: allow static routes to be configured on the command line
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
391 struct rt * |
|
2844dbb214b5
options: allow static routes to be configured on the command line
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
392 rt_new(struct interface *ifp) |
|
2844dbb214b5
options: allow static routes to be configured on the command line
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
393 { |
|
2844dbb214b5
options: allow static routes to be configured on the command line
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
394 struct rt *rt; |
|
2844dbb214b5
options: allow static routes to be configured on the command line
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
395 |
|
2844dbb214b5
options: allow static routes to be configured on the command line
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
396 assert(ifp != NULL); |
|
2844dbb214b5
options: allow static routes to be configured on the command line
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
397 if ((rt = rt_new0(ifp->ctx)) == NULL) |
|
2844dbb214b5
options: allow static routes to be configured on the command line
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
398 return NULL; |
|
2844dbb214b5
options: allow static routes to be configured on the command line
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
399 rt_setif(rt, ifp); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
400 return rt; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
401 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
402 |
|
4522
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
403 struct rt * |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
404 rt_proto_add_ctx(rb_tree_t *tree, struct rt *rt, struct dhcpcd_ctx *ctx) |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
405 { |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
406 |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
407 rt->rt_order = ctx->rt_order++; |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
408 if (rb_tree_insert_node(tree, rt) == rt) |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
409 return rt; |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
410 |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
411 rt_free(rt); |
|
5577
4da45107d87a
script: Use rt_proto_add to ensure no duplicate interfaces on OpenBSD
Roy Marples <roy@marples.name>
parents:
5567
diff
changeset
|
412 errno = EEXIST; |
|
4522
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
413 return NULL; |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
414 } |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
415 |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
416 struct rt * |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
417 rt_proto_add(rb_tree_t *tree, struct rt *rt) |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
418 { |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
419 |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
420 assert (rt->rt_ifp != NULL); |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
421 return rt_proto_add_ctx(tree, rt, rt->rt_ifp->ctx); |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
422 } |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
423 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
424 void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
425 rt_free(struct rt *rt) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
426 { |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4396
diff
changeset
|
427 #ifdef RT_FREE_ROUTE_TABLE |
|
4379
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
428 struct dhcpcd_ctx *ctx; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
429 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
430 assert(rt != NULL); |
|
4599
1d09f6293928
Fix a memory NULL deference when freeing static routes at exit.
Roy Marples <roy@marples.name>
parents:
4553
diff
changeset
|
431 if (rt->rt_ifp == NULL) { |
|
1d09f6293928
Fix a memory NULL deference when freeing static routes at exit.
Roy Marples <roy@marples.name>
parents:
4553
diff
changeset
|
432 free(rt); |
|
1d09f6293928
Fix a memory NULL deference when freeing static routes at exit.
Roy Marples <roy@marples.name>
parents:
4553
diff
changeset
|
433 return; |
|
1d09f6293928
Fix a memory NULL deference when freeing static routes at exit.
Roy Marples <roy@marples.name>
parents:
4553
diff
changeset
|
434 } |
|
4379
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
435 |
|
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
436 ctx = rt->rt_ifp->ctx; |
|
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
437 rb_tree_insert_node(&ctx->froutes, rt); |
|
4404
6c1ae8d24811
route: Guard free route list stats
Roy Marples <roy@marples.name>
parents:
4402
diff
changeset
|
438 #ifdef RT_FREE_ROUTE_TABLE_STATS |
|
6c1ae8d24811
route: Guard free route list stats
Roy Marples <roy@marples.name>
parents:
4402
diff
changeset
|
439 croutes++; |
|
4402
72c7bfdd522b
route: report usage data when using a free list
Roy Marples <roy@marples.name>
parents:
4401
diff
changeset
|
440 froutes++; |
|
4404
6c1ae8d24811
route: Guard free route list stats
Roy Marples <roy@marples.name>
parents:
4402
diff
changeset
|
441 if (croutes > mroutes) |
|
6c1ae8d24811
route: Guard free route list stats
Roy Marples <roy@marples.name>
parents:
4402
diff
changeset
|
442 mroutes = croutes; |
|
6c1ae8d24811
route: Guard free route list stats
Roy Marples <roy@marples.name>
parents:
4402
diff
changeset
|
443 #endif |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4396
diff
changeset
|
444 #else |
|
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4396
diff
changeset
|
445 free(rt); |
|
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4396
diff
changeset
|
446 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
447 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
448 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
449 void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
450 rt_freeif(struct interface *ifp) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
451 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
452 struct dhcpcd_ctx *ctx; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
453 struct rt *rt, *rtn; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
454 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
455 if (ifp == NULL) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
456 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
457 ctx = ifp->ctx; |
|
4379
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
458 RB_TREE_FOREACH_SAFE(rt, &ctx->routes, rtn) { |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
459 if (rt->rt_ifp == ifp) { |
|
4379
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
460 rb_tree_remove_node(&ctx->routes, rt); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
461 rt_free(rt); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
462 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
463 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
464 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
465 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
466 /* If something other than dhcpcd removes a route, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
467 * we need to remove it from our internal table. */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
468 void |
|
4421
1c0d24d49b16
route: log which pid deletes routes
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
469 rt_recvrt(int cmd, const struct rt *rt, pid_t pid) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
470 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
471 struct dhcpcd_ctx *ctx; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
472 struct rt *f; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
473 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
474 assert(rt != NULL); |
|
4391
95487c75e685
route: sprinkle more assert
Roy Marples <roy@marples.name>
parents:
4389
diff
changeset
|
475 assert(rt->rt_ifp != NULL); |
|
95487c75e685
route: sprinkle more assert
Roy Marples <roy@marples.name>
parents:
4389
diff
changeset
|
476 assert(rt->rt_ifp->ctx != NULL); |
|
95487c75e685
route: sprinkle more assert
Roy Marples <roy@marples.name>
parents:
4389
diff
changeset
|
477 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
478 ctx = rt->rt_ifp->ctx; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
479 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
480 switch(cmd) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
481 case RTM_DELETE: |
|
4392
af390080e632
route: replace rt_find with rb_tree_find_node
Roy Marples <roy@marples.name>
parents:
4391
diff
changeset
|
482 f = rb_tree_find_node(&ctx->routes, rt); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
483 if (f != NULL) { |
|
4421
1c0d24d49b16
route: log which pid deletes routes
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
484 char buf[32]; |
|
1c0d24d49b16
route: log which pid deletes routes
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
485 |
|
4379
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
486 rb_tree_remove_node(&ctx->routes, f); |
|
4421
1c0d24d49b16
route: log which pid deletes routes
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
487 snprintf(buf, sizeof(buf), "pid %d deleted", pid); |
|
1c0d24d49b16
route: log which pid deletes routes
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
488 rt_desc(buf, f); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
489 rt_free(f); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
490 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
491 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
492 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
493 |
|
4378
005070cd0510
Linux: Fix compile without IPv4LL
Roy Marples <roy@marples.name>
parents:
4333
diff
changeset
|
494 #if defined(IPV4LL) && defined(HAVE_ROUTE_METRIC) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
495 if (rt->rt_dest.sa_family == AF_INET) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
496 ipv4ll_recvrt(cmd, rt); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
497 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
498 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
499 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
500 static bool |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4396
diff
changeset
|
501 rt_add(rb_tree_t *kroutes, struct rt *nrt, struct rt *ort) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
502 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
503 struct dhcpcd_ctx *ctx; |
|
4515
768ba28719eb
route: Fix stamping on existing kernel routes
Roy Marples <roy@marples.name>
parents:
4447
diff
changeset
|
504 bool change, kroute, result; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
505 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
506 assert(nrt != NULL); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
507 ctx = nrt->rt_ifp->ctx; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
508 |
| 4067 | 509 /* |
| 510 * Don't install a gateway if not asked to. | |
| 511 * This option is mainly for VPN users who want their VPN to be the | |
| 512 * default route. | |
| 513 * Because VPN's generally don't care about route management | |
| 514 * beyond their own, a longer term solution would be to remove this | |
| 515 * and get the VPN to inject the default route into dhcpcd somehow. | |
| 516 */ | |
| 517 if (((nrt->rt_ifp->active && | |
| 518 !(nrt->rt_ifp->options->options & DHCPCD_GATEWAY)) || | |
| 519 (!nrt->rt_ifp->active && !(ctx->options & DHCPCD_GATEWAY))) && | |
| 520 sa_is_unspecified(&nrt->rt_dest) && | |
| 521 sa_is_unspecified(&nrt->rt_netmask)) | |
| 522 return false; | |
| 523 | |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
524 rt_desc(ort == NULL ? "adding" : "changing", nrt); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
525 |
|
4515
768ba28719eb
route: Fix stamping on existing kernel routes
Roy Marples <roy@marples.name>
parents:
4447
diff
changeset
|
526 change = kroute = result = false; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
527 if (ort == NULL) { |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4396
diff
changeset
|
528 ort = rb_tree_find_node(kroutes, nrt); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
529 if (ort != NULL && |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
530 ((ort->rt_flags & RTF_REJECT && |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
531 nrt->rt_flags & RTF_REJECT) || |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
532 (ort->rt_ifp == nrt->rt_ifp && |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
533 #ifdef HAVE_ROUTE_METRIC |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
534 ort->rt_metric == nrt->rt_metric && |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
535 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
536 sa_cmp(&ort->rt_gateway, &nrt->rt_gateway) == 0))) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
537 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
538 if (ort->rt_mtu == nrt->rt_mtu) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
539 return true; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
540 change = true; |
|
4515
768ba28719eb
route: Fix stamping on existing kernel routes
Roy Marples <roy@marples.name>
parents:
4447
diff
changeset
|
541 kroute = true; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
542 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
543 } else if (ort->rt_dflags & RTDF_FAKE && |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
544 !(nrt->rt_dflags & RTDF_FAKE) && |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
545 ort->rt_ifp == nrt->rt_ifp && |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
546 #ifdef HAVE_ROUTE_METRIC |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
547 ort->rt_metric == nrt->rt_metric && |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
548 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
549 sa_cmp(&ort->rt_dest, &nrt->rt_dest) == 0 && |
|
4294
95fa4f3d6b1a
Some systems mark a host route using RTF_HOST and some use an
Roy Marples <roy@marples.name>
parents:
4261
diff
changeset
|
550 rt_cmp_netmask(ort, nrt) == 0 && |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
551 sa_cmp(&ort->rt_gateway, &nrt->rt_gateway) == 0) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
552 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
553 if (ort->rt_mtu == nrt->rt_mtu) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
554 return true; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
555 change = true; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
556 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
557 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
558 #ifdef RTF_CLONING |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
559 /* BSD can set routes to be cloning routes. |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
560 * Cloned routes inherit the parent flags. |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
561 * As such, we need to delete and re-add the route to flush children |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
562 * to correct the flags. */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
563 if (change && ort != NULL && ort->rt_flags & RTF_CLONING) |
|
4261
3879ca166a05
routing: Fix case when cloning route changes but needs to be replaced.
Roy Marples <roy@marples.name>
parents:
4249
diff
changeset
|
564 change = false; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
565 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
566 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
567 if (change) { |
|
4515
768ba28719eb
route: Fix stamping on existing kernel routes
Roy Marples <roy@marples.name>
parents:
4447
diff
changeset
|
568 if (if_route(RTM_CHANGE, nrt) != -1) { |
|
768ba28719eb
route: Fix stamping on existing kernel routes
Roy Marples <roy@marples.name>
parents:
4447
diff
changeset
|
569 result = true; |
|
768ba28719eb
route: Fix stamping on existing kernel routes
Roy Marples <roy@marples.name>
parents:
4447
diff
changeset
|
570 goto out; |
|
768ba28719eb
route: Fix stamping on existing kernel routes
Roy Marples <roy@marples.name>
parents:
4447
diff
changeset
|
571 } |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
572 if (errno != ESRCH) |
| 4010 | 573 logerr("if_route (CHG)"); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
574 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
575 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
576 #ifdef HAVE_ROUTE_METRIC |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
577 /* With route metrics, we can safely add the new route before |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
578 * deleting the old route. */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
579 if (if_route(RTM_ADD, nrt) != -1) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
580 if (ort != NULL) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
581 if (if_route(RTM_DELETE, ort) == -1 && errno != ESRCH) |
| 4010 | 582 logerr("if_route (DEL)"); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
583 } |
|
4515
768ba28719eb
route: Fix stamping on existing kernel routes
Roy Marples <roy@marples.name>
parents:
4447
diff
changeset
|
584 result = true; |
|
768ba28719eb
route: Fix stamping on existing kernel routes
Roy Marples <roy@marples.name>
parents:
4447
diff
changeset
|
585 goto out; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
586 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
587 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
588 /* If the kernel claims the route exists we need to rip out the |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
589 * old one first. */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
590 if (errno != EEXIST || ort == NULL) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
591 goto logerr; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
592 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
593 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
594 /* No route metrics, we need to delete the old route before |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
595 * adding the new one. */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
596 #ifdef ROUTE_PER_GATEWAY |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
597 errno = 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
598 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
599 if (ort != NULL) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
600 if (if_route(RTM_DELETE, ort) == -1 && errno != ESRCH) |
| 4010 | 601 logerr("if_route (DEL)"); |
|
4515
768ba28719eb
route: Fix stamping on existing kernel routes
Roy Marples <roy@marples.name>
parents:
4447
diff
changeset
|
602 else |
|
768ba28719eb
route: Fix stamping on existing kernel routes
Roy Marples <roy@marples.name>
parents:
4447
diff
changeset
|
603 kroute = false; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
604 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
605 #ifdef ROUTE_PER_GATEWAY |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
606 /* The OS allows many routes to the same dest with different gateways. |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
607 * dhcpcd does not support this yet, so for the time being just keep on |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
608 * deleting the route until there is an error. */ |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
609 if (ort != NULL && errno == 0) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
610 for (;;) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
611 if (if_route(RTM_DELETE, ort) == -1) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
612 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
613 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
614 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
615 #endif |
|
4515
768ba28719eb
route: Fix stamping on existing kernel routes
Roy Marples <roy@marples.name>
parents:
4447
diff
changeset
|
616 |
|
4741
e4cddf743a39
route: Don't log error when adding a route which already exists
Roy Marples <roy@marples.name>
parents:
4648
diff
changeset
|
617 /* Shouldn't need to check for EEXIST, but some kernels don't |
|
e4cddf743a39
route: Don't log error when adding a route which already exists
Roy Marples <roy@marples.name>
parents:
4648
diff
changeset
|
618 * dump the subnet route just after we added the address. */ |
|
e4cddf743a39
route: Don't log error when adding a route which already exists
Roy Marples <roy@marples.name>
parents:
4648
diff
changeset
|
619 if (if_route(RTM_ADD, nrt) != -1 || errno == EEXIST) { |
|
4515
768ba28719eb
route: Fix stamping on existing kernel routes
Roy Marples <roy@marples.name>
parents:
4447
diff
changeset
|
620 result = true; |
|
768ba28719eb
route: Fix stamping on existing kernel routes
Roy Marples <roy@marples.name>
parents:
4447
diff
changeset
|
621 goto out; |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4396
diff
changeset
|
622 } |
|
4515
768ba28719eb
route: Fix stamping on existing kernel routes
Roy Marples <roy@marples.name>
parents:
4447
diff
changeset
|
623 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
624 #ifdef HAVE_ROUTE_METRIC |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
625 logerr: |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
626 #endif |
| 4010 | 627 logerr("if_route (ADD)"); |
|
4515
768ba28719eb
route: Fix stamping on existing kernel routes
Roy Marples <roy@marples.name>
parents:
4447
diff
changeset
|
628 |
|
768ba28719eb
route: Fix stamping on existing kernel routes
Roy Marples <roy@marples.name>
parents:
4447
diff
changeset
|
629 out: |
|
768ba28719eb
route: Fix stamping on existing kernel routes
Roy Marples <roy@marples.name>
parents:
4447
diff
changeset
|
630 if (kroute) { |
|
768ba28719eb
route: Fix stamping on existing kernel routes
Roy Marples <roy@marples.name>
parents:
4447
diff
changeset
|
631 rb_tree_remove_node(kroutes, ort); |
|
768ba28719eb
route: Fix stamping on existing kernel routes
Roy Marples <roy@marples.name>
parents:
4447
diff
changeset
|
632 rt_free(ort); |
|
768ba28719eb
route: Fix stamping on existing kernel routes
Roy Marples <roy@marples.name>
parents:
4447
diff
changeset
|
633 } |
|
768ba28719eb
route: Fix stamping on existing kernel routes
Roy Marples <roy@marples.name>
parents:
4447
diff
changeset
|
634 return result; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
635 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
636 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
637 static bool |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
638 rt_delete(struct rt *rt) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
639 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
640 int retval; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
641 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
642 rt_desc("deleting", rt); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
643 retval = if_route(RTM_DELETE, rt) == -1 ? false : true; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
644 if (!retval && errno != ENOENT && errno != ESRCH) |
| 4010 | 645 logerr(__func__); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
646 return retval; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
647 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
648 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
649 static bool |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
650 rt_cmp(const struct rt *r1, const struct rt *r2) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
651 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
652 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
653 return (r1->rt_ifp == r2->rt_ifp && |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
654 #ifdef HAVE_ROUTE_METRIC |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
655 r1->rt_metric == r2->rt_metric && |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
656 #endif |
|
4142
6b945412fa08
Fix checking gateways in route comparison.
Roy Marples <roy@marples.name>
parents:
4067
diff
changeset
|
657 sa_cmp(&r1->rt_gateway, &r2->rt_gateway) == 0); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
658 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
659 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
660 static bool |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4396
diff
changeset
|
661 rt_doroute(rb_tree_t *kroutes, struct rt *rt) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
662 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
663 struct dhcpcd_ctx *ctx; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
664 struct rt *or; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
665 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
666 ctx = rt->rt_ifp->ctx; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
667 /* Do we already manage it? */ |
|
4392
af390080e632
route: replace rt_find with rb_tree_find_node
Roy Marples <roy@marples.name>
parents:
4391
diff
changeset
|
668 or = rb_tree_find_node(&ctx->routes, rt); |
|
af390080e632
route: replace rt_find with rb_tree_find_node
Roy Marples <roy@marples.name>
parents:
4391
diff
changeset
|
669 if (or != NULL) { |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
670 if (rt->rt_dflags & RTDF_FAKE) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
671 return true; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
672 if (or->rt_dflags & RTDF_FAKE || |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
673 !rt_cmp(rt, or) || |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
674 (rt->rt_ifa.sa_family != AF_UNSPEC && |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
675 sa_cmp(&or->rt_ifa, &rt->rt_ifa) != 0) || |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
676 or->rt_mtu != rt->rt_mtu) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
677 { |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4396
diff
changeset
|
678 if (!rt_add(kroutes, rt, or)) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
679 return false; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
680 } |
|
4379
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
681 rb_tree_remove_node(&ctx->routes, or); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
682 rt_free(or); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
683 } else { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
684 if (rt->rt_dflags & RTDF_FAKE) { |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4396
diff
changeset
|
685 or = rb_tree_find_node(kroutes, rt); |
|
4392
af390080e632
route: replace rt_find with rb_tree_find_node
Roy Marples <roy@marples.name>
parents:
4391
diff
changeset
|
686 if (or == NULL) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
687 return false; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
688 if (!rt_cmp(rt, or)) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
689 return false; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
690 } else { |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4396
diff
changeset
|
691 if (!rt_add(kroutes, rt, NULL)) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
692 return false; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
693 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
694 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
695 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
696 return true; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
697 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
698 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
699 void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
700 rt_build(struct dhcpcd_ctx *ctx, int af) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
701 { |
| 4447 | 702 rb_tree_t routes, added, kroutes; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
703 struct rt *rt, *rtn; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
704 unsigned long long o; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
705 |
|
4522
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
706 rb_tree_init(&routes, &rt_compare_proto_ops); |
|
4392
af390080e632
route: replace rt_find with rb_tree_find_node
Roy Marples <roy@marples.name>
parents:
4391
diff
changeset
|
707 rb_tree_init(&added, &rt_compare_os_ops); |
| 4447 | 708 rb_tree_init(&kroutes, &rt_compare_os_ops); |
| 709 if_initrt(ctx, &kroutes, af); | |
|
4522
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
710 ctx->rt_order = 0; |
|
4648
16b119f7fc39
inet6: Don't install a default route if no global address
Roy Marples <roy@marples.name>
parents:
4629
diff
changeset
|
711 ctx->options |= DHCPCD_RTBUILD; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
712 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
713 #ifdef INET |
|
5057
a5fd2097d40f
BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
714 if (!inet_getroutes(ctx, &routes)) |
|
a5fd2097d40f
BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
715 goto getfail; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
716 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
717 #ifdef INET6 |
|
5057
a5fd2097d40f
BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
718 if (!inet6_getroutes(ctx, &routes)) |
|
a5fd2097d40f
BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
719 goto getfail; |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
720 #endif |
|
5057
a5fd2097d40f
BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
721 |
|
a5fd2097d40f
BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
722 #ifdef BSD |
|
a5fd2097d40f
BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
723 /* Rewind the miss filter */ |
|
a5fd2097d40f
BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
724 ctx->rt_missfilterlen = 0; |
|
a5fd2097d40f
BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
725 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
726 |
|
4379
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
727 RB_TREE_FOREACH_SAFE(rt, &routes, rtn) { |
|
5546
08426e8a98a7
DHCP6: Delegated activations work once more
Roy Marples <roy@marples.name>
parents:
5545
diff
changeset
|
728 if (rt->rt_ifp->active) { |
|
08426e8a98a7
DHCP6: Delegated activations work once more
Roy Marples <roy@marples.name>
parents:
5545
diff
changeset
|
729 if (!(rt->rt_ifp->options->options & DHCPCD_CONFIGURE)) |
|
08426e8a98a7
DHCP6: Delegated activations work once more
Roy Marples <roy@marples.name>
parents:
5545
diff
changeset
|
730 continue; |
|
08426e8a98a7
DHCP6: Delegated activations work once more
Roy Marples <roy@marples.name>
parents:
5545
diff
changeset
|
731 } else if (!(ctx->options & DHCPCD_CONFIGURE)) |
| 5535 | 732 continue; |
|
5057
a5fd2097d40f
BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
733 #ifdef BSD |
|
a5fd2097d40f
BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
734 if (rt_is_default(rt) && |
|
a5fd2097d40f
BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
735 if_missfilter(rt->rt_ifp, &rt->rt_gateway) == -1) |
|
a5fd2097d40f
BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
736 logerr("if_missfilter"); |
|
a5fd2097d40f
BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
737 #endif |
|
4553
8289f982fb87
route: Compare AF_UNSPEC family when cleaning old routes
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
738 if ((rt->rt_dest.sa_family != af && |
|
8289f982fb87
route: Compare AF_UNSPEC family when cleaning old routes
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
739 rt->rt_dest.sa_family != AF_UNSPEC) || |
|
8289f982fb87
route: Compare AF_UNSPEC family when cleaning old routes
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
740 (rt->rt_gateway.sa_family != af && |
|
8289f982fb87
route: Compare AF_UNSPEC family when cleaning old routes
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
741 rt->rt_gateway.sa_family != AF_UNSPEC)) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
742 continue; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
743 /* Is this route already in our table? */ |
|
4392
af390080e632
route: replace rt_find with rb_tree_find_node
Roy Marples <roy@marples.name>
parents:
4391
diff
changeset
|
744 if (rb_tree_find_node(&added, rt) != NULL) |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
745 continue; |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4396
diff
changeset
|
746 if (rt_doroute(&kroutes, rt)) { |
|
4379
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
747 rb_tree_remove_node(&routes, rt); |
|
4396
5bdea847921d
route: Free route when failing to insert.
Roy Marples <roy@marples.name>
parents:
4395
diff
changeset
|
748 if (rb_tree_insert_node(&added, rt) != rt) { |
|
5bdea847921d
route: Free route when failing to insert.
Roy Marples <roy@marples.name>
parents:
4395
diff
changeset
|
749 errno = EEXIST; |
|
5bdea847921d
route: Free route when failing to insert.
Roy Marples <roy@marples.name>
parents:
4395
diff
changeset
|
750 logerr(__func__); |
|
5bdea847921d
route: Free route when failing to insert.
Roy Marples <roy@marples.name>
parents:
4395
diff
changeset
|
751 rt_free(rt); |
|
5bdea847921d
route: Free route when failing to insert.
Roy Marples <roy@marples.name>
parents:
4395
diff
changeset
|
752 } |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
753 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
754 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
755 |
|
5057
a5fd2097d40f
BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
756 #ifdef BSD |
|
5098
4c4e3cc28061
BSD: Don't warn if the OS does not support miss filtering.
Roy Marples <roy@marples.name>
parents:
5057
diff
changeset
|
757 if (if_missfilter_apply(ctx) == -1 && errno != ENOTSUP) |
|
5057
a5fd2097d40f
BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
758 logerr("if_missfilter_apply"); |
|
a5fd2097d40f
BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
759 #endif |
|
a5fd2097d40f
BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
760 |
|
4143
bb9bb396ab37
Don't special case not deleteing the IPv6 default route.
Roy Marples <roy@marples.name>
parents:
4142
diff
changeset
|
761 /* Remove old routes we used to manage. */ |
|
4553
8289f982fb87
route: Compare AF_UNSPEC family when cleaning old routes
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
762 RB_TREE_FOREACH_REVERSE_SAFE(rt, &ctx->routes, rtn) { |
|
8289f982fb87
route: Compare AF_UNSPEC family when cleaning old routes
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
763 if ((rt->rt_dest.sa_family != af && |
|
8289f982fb87
route: Compare AF_UNSPEC family when cleaning old routes
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
764 rt->rt_dest.sa_family != AF_UNSPEC) || |
|
8289f982fb87
route: Compare AF_UNSPEC family when cleaning old routes
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
765 (rt->rt_gateway.sa_family != af && |
|
8289f982fb87
route: Compare AF_UNSPEC family when cleaning old routes
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
766 rt->rt_gateway.sa_family != AF_UNSPEC)) |
|
8289f982fb87
route: Compare AF_UNSPEC family when cleaning old routes
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
767 continue; |
|
4379
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
768 rb_tree_remove_node(&ctx->routes, rt); |
|
4553
8289f982fb87
route: Compare AF_UNSPEC family when cleaning old routes
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
769 if (rb_tree_find_node(&added, rt) == NULL) { |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
770 o = rt->rt_ifp->options ? |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
771 rt->rt_ifp->options->options : |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
772 ctx->options; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
773 if ((o & |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
774 (DHCPCD_EXITING | DHCPCD_PERSISTENT)) != |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
775 (DHCPCD_EXITING | DHCPCD_PERSISTENT)) |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
776 rt_delete(rt); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
777 } |
|
4379
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
778 rt_free(rt); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
779 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
780 |
|
4392
af390080e632
route: replace rt_find with rb_tree_find_node
Roy Marples <roy@marples.name>
parents:
4391
diff
changeset
|
781 /* XXX This needs to be optimised. */ |
|
4379
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
782 while ((rt = RB_TREE_MIN(&added)) != NULL) { |
|
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
783 rb_tree_remove_node(&added, rt); |
|
4396
5bdea847921d
route: Free route when failing to insert.
Roy Marples <roy@marples.name>
parents:
4395
diff
changeset
|
784 if (rb_tree_insert_node(&ctx->routes, rt) != rt) { |
|
5bdea847921d
route: Free route when failing to insert.
Roy Marples <roy@marples.name>
parents:
4395
diff
changeset
|
785 errno = EEXIST; |
|
5bdea847921d
route: Free route when failing to insert.
Roy Marples <roy@marples.name>
parents:
4395
diff
changeset
|
786 logerr(__func__); |
|
5bdea847921d
route: Free route when failing to insert.
Roy Marples <roy@marples.name>
parents:
4395
diff
changeset
|
787 rt_free(rt); |
|
5bdea847921d
route: Free route when failing to insert.
Roy Marples <roy@marples.name>
parents:
4395
diff
changeset
|
788 } |
|
4379
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
789 } |
|
4149
fce599d14e9a
Free any allocated routes if we failed to allocate some.
Roy Marples <roy@marples.name>
parents:
4143
diff
changeset
|
790 |
|
fce599d14e9a
Free any allocated routes if we failed to allocate some.
Roy Marples <roy@marples.name>
parents:
4143
diff
changeset
|
791 getfail: |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
792 rt_headclear(&routes, AF_UNSPEC); |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4396
diff
changeset
|
793 rt_headclear(&kroutes, AF_UNSPEC); |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
794 } |
