Mercurial > hg > dhcpcd
annotate src/route.c @ 5535:a0d828e25482 draft
Add --noconfigure option
With this set dhcpcd will not configure anything on the host.
The expectation is that a 3rd party script will instead.
| author | Roy Marples <roy@marples.name> |
|---|---|
| date | Wed, 04 Nov 2020 14:18:48 +0000 |
| parents | 30603cb789ea |
| children | ddb1318a21e8 |
| 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 |
|
5406
c03103d18249
route: Ensure IPv4LL routes always come last in priority
Roy Marples <roy@marples.name>
parents:
5133
diff
changeset
|
171 #ifdef INET |
|
c03103d18249
route: Ensure IPv4LL routes always come last in priority
Roy Marples <roy@marples.name>
parents:
5133
diff
changeset
|
172 /* IPv4LL routes always come last */ |
| 5407 | 173 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
|
174 return -1; |
| 5407 | 175 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
|
176 return 1; |
|
c03103d18249
route: Ensure IPv4LL routes always come last in priority
Roy Marples <roy@marples.name>
parents:
5133
diff
changeset
|
177 #endif |
|
c03103d18249
route: Ensure IPv4LL routes always come last in priority
Roy Marples <roy@marples.name>
parents:
5133
diff
changeset
|
178 |
|
4522
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
179 /* Lower metric interfaces come first. */ |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
180 c = (int)(ifp1->metric - ifp2->metric); |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
181 if (c != 0) |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
182 return c; |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
183 |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
184 /* 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
|
185 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
|
186 } |
|
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
187 |
|
4392
af390080e632
route: replace rt_find with rb_tree_find_node
Roy Marples <roy@marples.name>
parents:
4391
diff
changeset
|
188 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
|
189 .rbto_compare_nodes = rt_compare_os, |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
190 .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
|
191 .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
|
192 .rbto_context = NULL |
|
4392
af390080e632
route: replace rt_find with rb_tree_find_node
Roy Marples <roy@marples.name>
parents:
4391
diff
changeset
|
193 }; |
|
af390080e632
route: replace rt_find with rb_tree_find_node
Roy Marples <roy@marples.name>
parents:
4391
diff
changeset
|
194 |
|
4629
06b0dbf7a171
route: Just compare order when adding routes from options.
Roy Marples <roy@marples.name>
parents:
4599
diff
changeset
|
195 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
|
196 .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
|
197 .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
|
198 .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
|
199 .rbto_context = NULL |
|
06b0dbf7a171
route: Just compare order when adding routes from options.
Roy Marples <roy@marples.name>
parents:
4599
diff
changeset
|
200 }; |
|
06b0dbf7a171
route: Just compare order when adding routes from options.
Roy Marples <roy@marples.name>
parents:
4599
diff
changeset
|
201 |
|
4522
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
202 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
|
203 .rbto_compare_nodes = rt_compare_proto, |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
204 .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
|
205 .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
|
206 .rbto_context = NULL |
|
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
207 }; |
|
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
208 |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4396
diff
changeset
|
209 #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
|
210 static int |
|
af390080e632
route: replace rt_find with rb_tree_find_node
Roy Marples <roy@marples.name>
parents:
4391
diff
changeset
|
211 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
|
212 { |
|
af390080e632
route: replace rt_find with rb_tree_find_node
Roy Marples <roy@marples.name>
parents:
4391
diff
changeset
|
213 |
|
4395
41bab8a02727
OpenBSD: Fix segfaults when deleting MPATH routes
Roy Marples <roy@marples.name>
parents:
4392
diff
changeset
|
214 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
|
215 } |
|
af390080e632
route: replace rt_find with rb_tree_find_node
Roy Marples <roy@marples.name>
parents:
4391
diff
changeset
|
216 |
|
af390080e632
route: replace rt_find with rb_tree_find_node
Roy Marples <roy@marples.name>
parents:
4391
diff
changeset
|
217 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
|
218 .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
|
219 .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
|
220 .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
|
221 .rbto_context = NULL |
|
af390080e632
route: replace rt_find with rb_tree_find_node
Roy Marples <roy@marples.name>
parents:
4391
diff
changeset
|
222 }; |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4396
diff
changeset
|
223 #endif |
|
4392
af390080e632
route: replace rt_find with rb_tree_find_node
Roy Marples <roy@marples.name>
parents:
4391
diff
changeset
|
224 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
225 void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
226 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
|
227 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
228 |
|
4392
af390080e632
route: replace rt_find with rb_tree_find_node
Roy Marples <roy@marples.name>
parents:
4391
diff
changeset
|
229 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
|
230 #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
|
231 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
|
232 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
233 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
234 |
|
4522
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
235 bool |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
236 rt_is_default(const struct rt *rt) |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
237 { |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
238 |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
239 return sa_is_unspecified(&rt->rt_dest) && |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
240 sa_is_unspecified(&rt->rt_netmask); |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
241 } |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
242 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
243 static void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
244 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
|
245 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
246 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
|
247 int prefix; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
248 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
|
249 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
|
250 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
251 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
|
252 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
|
253 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
254 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
|
255 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
|
256 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
|
257 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
|
258 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
|
259 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
260 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
|
261 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
|
262 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
|
263 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
|
264 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
|
265 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
|
266 ifname, cmd, dest, gateway); |
|
4522
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
267 } 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
|
268 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
|
269 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
|
270 ifname, cmd); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
271 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
|
272 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
|
273 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
|
274 } 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
|
275 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
|
276 ifname, cmd, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
277 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
|
278 dest, prefix); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
279 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
|
280 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
|
281 ifname, cmd, |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
282 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
|
283 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
|
284 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
285 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
286 void |
|
4379
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
287 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
|
288 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
289 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
|
290 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
291 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
|
292 return; |
|
4249
c30233f8cca3
routes: allow a head clear with a context
Roy Marples <roy@marples.name>
parents:
4248
diff
changeset
|
293 assert(ctx != NULL); |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4396
diff
changeset
|
294 #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
|
295 assert(&ctx->froutes != rts); |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4396
diff
changeset
|
296 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
297 |
|
4379
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
298 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
|
299 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
|
300 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
|
301 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
|
302 continue; |
|
4379
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
303 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
|
304 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
|
305 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
306 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
307 |
|
4249
c30233f8cca3
routes: allow a head clear with a context
Roy Marples <roy@marples.name>
parents:
4248
diff
changeset
|
308 void |
|
4379
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
309 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
|
310 { |
|
c30233f8cca3
routes: allow a head clear with a context
Roy Marples <roy@marples.name>
parents:
4248
diff
changeset
|
311 struct rt *rt; |
|
c30233f8cca3
routes: allow a head clear with a context
Roy Marples <roy@marples.name>
parents:
4248
diff
changeset
|
312 |
|
4379
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
313 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
|
314 return; |
|
c30233f8cca3
routes: allow a head clear with a context
Roy Marples <roy@marples.name>
parents:
4248
diff
changeset
|
315 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
|
316 } |
|
c30233f8cca3
routes: allow a head clear with a context
Roy Marples <roy@marples.name>
parents:
4248
diff
changeset
|
317 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
318 static void |
|
4379
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
319 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
|
320 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
321 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
|
322 |
|
4379
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
323 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
|
324 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
|
325 free(rt); |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
326 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
327 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
328 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
329 void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
330 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
|
331 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
332 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
333 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
|
334 rt_headfree(&ctx->routes); |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4396
diff
changeset
|
335 #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
|
336 rt_headfree(&ctx->froutes); |
|
4404
6c1ae8d24811
route: Guard free route list stats
Roy Marples <roy@marples.name>
parents:
4402
diff
changeset
|
337 #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
|
338 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
|
339 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
|
340 logdebugx("maximum route free list size %zu", mroutes); |
|
6c1ae8d24811
route: Guard free route list stats
Roy Marples <roy@marples.name>
parents:
4402
diff
changeset
|
341 #endif |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4396
diff
changeset
|
342 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
343 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
344 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
345 struct rt * |
|
4248
2844dbb214b5
options: allow static routes to be configured on the command line
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
346 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
|
347 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
348 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
|
349 |
|
4248
2844dbb214b5
options: allow static routes to be configured on the command line
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
350 assert(ctx != NULL); |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4396
diff
changeset
|
351 #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
|
352 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
|
353 rb_tree_remove_node(&ctx->froutes, rt); |
|
4404
6c1ae8d24811
route: Guard free route list stats
Roy Marples <roy@marples.name>
parents:
4402
diff
changeset
|
354 #ifdef RT_FREE_ROUTE_TABLE_STATS |
|
6c1ae8d24811
route: Guard free route list stats
Roy Marples <roy@marples.name>
parents:
4402
diff
changeset
|
355 croutes--; |
|
4402
72c7bfdd522b
route: report usage data when using a free list
Roy Marples <roy@marples.name>
parents:
4401
diff
changeset
|
356 nroutes++; |
|
4404
6c1ae8d24811
route: Guard free route list stats
Roy Marples <roy@marples.name>
parents:
4402
diff
changeset
|
357 #endif |
|
4402
72c7bfdd522b
route: report usage data when using a free list
Roy Marples <roy@marples.name>
parents:
4401
diff
changeset
|
358 } else |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4396
diff
changeset
|
359 #endif |
|
5133
fe2c149bb04d
route: revert prior change to rt_new0
Roy Marples <roy@marples.name>
parents:
5130
diff
changeset
|
360 if ((rt = malloc(sizeof(*rt))) == NULL) { |
| 4010 | 361 logerr(__func__); |
|
5133
fe2c149bb04d
route: revert prior change to rt_new0
Roy Marples <roy@marples.name>
parents:
5130
diff
changeset
|
362 return NULL; |
|
fe2c149bb04d
route: revert prior change to rt_new0
Roy Marples <roy@marples.name>
parents:
5130
diff
changeset
|
363 } |
|
fe2c149bb04d
route: revert prior change to rt_new0
Roy Marples <roy@marples.name>
parents:
5130
diff
changeset
|
364 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
|
365 return rt; |
|
2844dbb214b5
options: allow static routes to be configured on the command line
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
366 } |
|
2844dbb214b5
options: allow static routes to be configured on the command line
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
367 |
|
2844dbb214b5
options: allow static routes to be configured on the command line
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
368 void |
|
2844dbb214b5
options: allow static routes to be configured on the command line
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
369 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
|
370 { |
|
2844dbb214b5
options: allow static routes to be configured on the command line
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
371 |
|
2844dbb214b5
options: allow static routes to be configured on the command line
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
372 assert(rt != NULL); |
|
2844dbb214b5
options: allow static routes to be configured on the command line
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
373 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
|
374 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
|
375 #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
|
376 rt->rt_metric = ifp->metric; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
377 #endif |
|
4248
2844dbb214b5
options: allow static routes to be configured on the command line
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
378 } |
|
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 struct rt * |
|
2844dbb214b5
options: allow static routes to be configured on the command line
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
381 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
|
382 { |
|
2844dbb214b5
options: allow static routes to be configured on the command line
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
383 struct rt *rt; |
|
2844dbb214b5
options: allow static routes to be configured on the command line
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
384 |
|
2844dbb214b5
options: allow static routes to be configured on the command line
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
385 assert(ifp != NULL); |
|
2844dbb214b5
options: allow static routes to be configured on the command line
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
386 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
|
387 return NULL; |
|
2844dbb214b5
options: allow static routes to be configured on the command line
Roy Marples <roy@marples.name>
parents:
4197
diff
changeset
|
388 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
|
389 return rt; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
390 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
391 |
|
4522
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
392 struct rt * |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
393 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
|
394 { |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
395 |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
396 rt->rt_order = ctx->rt_order++; |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
397 if (rb_tree_insert_node(tree, rt) == rt) |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
398 return rt; |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
399 |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
400 rt_free(rt); |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
401 return NULL; |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
402 } |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
403 |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
404 struct rt * |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
405 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
|
406 { |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
407 |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
408 assert (rt->rt_ifp != NULL); |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
409 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
|
410 } |
|
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
411 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
412 void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
413 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
|
414 { |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4396
diff
changeset
|
415 #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
|
416 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
|
417 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
418 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
|
419 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
|
420 free(rt); |
|
1d09f6293928
Fix a memory NULL deference when freeing static routes at exit.
Roy Marples <roy@marples.name>
parents:
4553
diff
changeset
|
421 return; |
|
1d09f6293928
Fix a memory NULL deference when freeing static routes at exit.
Roy Marples <roy@marples.name>
parents:
4553
diff
changeset
|
422 } |
|
4379
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
423 |
|
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
424 ctx = rt->rt_ifp->ctx; |
|
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
425 rb_tree_insert_node(&ctx->froutes, rt); |
|
4404
6c1ae8d24811
route: Guard free route list stats
Roy Marples <roy@marples.name>
parents:
4402
diff
changeset
|
426 #ifdef RT_FREE_ROUTE_TABLE_STATS |
|
6c1ae8d24811
route: Guard free route list stats
Roy Marples <roy@marples.name>
parents:
4402
diff
changeset
|
427 croutes++; |
|
4402
72c7bfdd522b
route: report usage data when using a free list
Roy Marples <roy@marples.name>
parents:
4401
diff
changeset
|
428 froutes++; |
|
4404
6c1ae8d24811
route: Guard free route list stats
Roy Marples <roy@marples.name>
parents:
4402
diff
changeset
|
429 if (croutes > mroutes) |
|
6c1ae8d24811
route: Guard free route list stats
Roy Marples <roy@marples.name>
parents:
4402
diff
changeset
|
430 mroutes = croutes; |
|
6c1ae8d24811
route: Guard free route list stats
Roy Marples <roy@marples.name>
parents:
4402
diff
changeset
|
431 #endif |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4396
diff
changeset
|
432 #else |
|
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4396
diff
changeset
|
433 free(rt); |
|
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4396
diff
changeset
|
434 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
435 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
436 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
437 void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
438 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
|
439 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
440 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
|
441 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
|
442 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
443 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
|
444 return; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
445 ctx = ifp->ctx; |
|
4379
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
446 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
|
447 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
|
448 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
|
449 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
|
450 } |
|
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 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
453 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
454 /* 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
|
455 * 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
|
456 void |
|
4421
1c0d24d49b16
route: log which pid deletes routes
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
457 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
|
458 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
459 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
|
460 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
|
461 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
462 assert(rt != NULL); |
|
4391
95487c75e685
route: sprinkle more assert
Roy Marples <roy@marples.name>
parents:
4389
diff
changeset
|
463 assert(rt->rt_ifp != NULL); |
|
95487c75e685
route: sprinkle more assert
Roy Marples <roy@marples.name>
parents:
4389
diff
changeset
|
464 assert(rt->rt_ifp->ctx != NULL); |
|
95487c75e685
route: sprinkle more assert
Roy Marples <roy@marples.name>
parents:
4389
diff
changeset
|
465 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
466 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
|
467 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
468 switch(cmd) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
469 case RTM_DELETE: |
|
4392
af390080e632
route: replace rt_find with rb_tree_find_node
Roy Marples <roy@marples.name>
parents:
4391
diff
changeset
|
470 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
|
471 if (f != NULL) { |
|
4421
1c0d24d49b16
route: log which pid deletes routes
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
472 char buf[32]; |
|
1c0d24d49b16
route: log which pid deletes routes
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
473 |
|
4379
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
474 rb_tree_remove_node(&ctx->routes, f); |
|
4421
1c0d24d49b16
route: log which pid deletes routes
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
475 snprintf(buf, sizeof(buf), "pid %d deleted", pid); |
|
1c0d24d49b16
route: log which pid deletes routes
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
476 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
|
477 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
|
478 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
479 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
480 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
481 |
|
4378
005070cd0510
Linux: Fix compile without IPv4LL
Roy Marples <roy@marples.name>
parents:
4333
diff
changeset
|
482 #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
|
483 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
|
484 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
|
485 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
486 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
487 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
488 static bool |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4396
diff
changeset
|
489 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
|
490 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
491 struct dhcpcd_ctx *ctx; |
|
4515
768ba28719eb
route: Fix stamping on existing kernel routes
Roy Marples <roy@marples.name>
parents:
4447
diff
changeset
|
492 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
|
493 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
494 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
|
495 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
|
496 |
| 4067 | 497 /* |
| 498 * Don't install a gateway if not asked to. | |
| 499 * This option is mainly for VPN users who want their VPN to be the | |
| 500 * default route. | |
| 501 * Because VPN's generally don't care about route management | |
| 502 * beyond their own, a longer term solution would be to remove this | |
| 503 * and get the VPN to inject the default route into dhcpcd somehow. | |
| 504 */ | |
| 505 if (((nrt->rt_ifp->active && | |
| 506 !(nrt->rt_ifp->options->options & DHCPCD_GATEWAY)) || | |
| 507 (!nrt->rt_ifp->active && !(ctx->options & DHCPCD_GATEWAY))) && | |
| 508 sa_is_unspecified(&nrt->rt_dest) && | |
| 509 sa_is_unspecified(&nrt->rt_netmask)) | |
| 510 return false; | |
| 511 | |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
512 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
|
513 |
|
4515
768ba28719eb
route: Fix stamping on existing kernel routes
Roy Marples <roy@marples.name>
parents:
4447
diff
changeset
|
514 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
|
515 if (ort == NULL) { |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4396
diff
changeset
|
516 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
|
517 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
|
518 ((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
|
519 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
|
520 (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
|
521 #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
|
522 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
|
523 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
524 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
|
525 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
526 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
|
527 return true; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
528 change = true; |
|
4515
768ba28719eb
route: Fix stamping on existing kernel routes
Roy Marples <roy@marples.name>
parents:
4447
diff
changeset
|
529 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
|
530 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
531 } 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
|
532 !(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
|
533 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
|
534 #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
|
535 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
|
536 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
537 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
|
538 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
|
539 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
|
540 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
541 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
|
542 return true; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
543 change = true; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
544 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
545 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
546 #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
|
547 /* 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
|
548 * 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
|
549 * 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
|
550 * 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
|
551 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
|
552 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
|
553 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
554 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
555 if (change) { |
|
4515
768ba28719eb
route: Fix stamping on existing kernel routes
Roy Marples <roy@marples.name>
parents:
4447
diff
changeset
|
556 if (if_route(RTM_CHANGE, nrt) != -1) { |
|
768ba28719eb
route: Fix stamping on existing kernel routes
Roy Marples <roy@marples.name>
parents:
4447
diff
changeset
|
557 result = true; |
|
768ba28719eb
route: Fix stamping on existing kernel routes
Roy Marples <roy@marples.name>
parents:
4447
diff
changeset
|
558 goto out; |
|
768ba28719eb
route: Fix stamping on existing kernel routes
Roy Marples <roy@marples.name>
parents:
4447
diff
changeset
|
559 } |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
560 if (errno != ESRCH) |
| 4010 | 561 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
|
562 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
563 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
564 #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
|
565 /* 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
|
566 * 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
|
567 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
|
568 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
|
569 if (if_route(RTM_DELETE, ort) == -1 && errno != ESRCH) |
| 4010 | 570 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
|
571 } |
|
4515
768ba28719eb
route: Fix stamping on existing kernel routes
Roy Marples <roy@marples.name>
parents:
4447
diff
changeset
|
572 result = true; |
|
768ba28719eb
route: Fix stamping on existing kernel routes
Roy Marples <roy@marples.name>
parents:
4447
diff
changeset
|
573 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
|
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 /* 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
|
577 * 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
|
578 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
|
579 goto logerr; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
580 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
581 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
582 /* 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
|
583 * 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
|
584 #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
|
585 errno = 0; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
586 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
587 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
|
588 if (if_route(RTM_DELETE, ort) == -1 && errno != ESRCH) |
| 4010 | 589 logerr("if_route (DEL)"); |
|
4515
768ba28719eb
route: Fix stamping on existing kernel routes
Roy Marples <roy@marples.name>
parents:
4447
diff
changeset
|
590 else |
|
768ba28719eb
route: Fix stamping on existing kernel routes
Roy Marples <roy@marples.name>
parents:
4447
diff
changeset
|
591 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
|
592 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
593 #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
|
594 /* 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
|
595 * 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
|
596 * 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
|
597 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
|
598 for (;;) { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
599 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
|
600 break; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
601 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
602 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
603 #endif |
|
4515
768ba28719eb
route: Fix stamping on existing kernel routes
Roy Marples <roy@marples.name>
parents:
4447
diff
changeset
|
604 |
|
4741
e4cddf743a39
route: Don't log error when adding a route which already exists
Roy Marples <roy@marples.name>
parents:
4648
diff
changeset
|
605 /* 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
|
606 * 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
|
607 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
|
608 result = true; |
|
768ba28719eb
route: Fix stamping on existing kernel routes
Roy Marples <roy@marples.name>
parents:
4447
diff
changeset
|
609 goto out; |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4396
diff
changeset
|
610 } |
|
4515
768ba28719eb
route: Fix stamping on existing kernel routes
Roy Marples <roy@marples.name>
parents:
4447
diff
changeset
|
611 |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
612 #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
|
613 logerr: |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
614 #endif |
| 4010 | 615 logerr("if_route (ADD)"); |
|
4515
768ba28719eb
route: Fix stamping on existing kernel routes
Roy Marples <roy@marples.name>
parents:
4447
diff
changeset
|
616 |
|
768ba28719eb
route: Fix stamping on existing kernel routes
Roy Marples <roy@marples.name>
parents:
4447
diff
changeset
|
617 out: |
|
768ba28719eb
route: Fix stamping on existing kernel routes
Roy Marples <roy@marples.name>
parents:
4447
diff
changeset
|
618 if (kroute) { |
|
768ba28719eb
route: Fix stamping on existing kernel routes
Roy Marples <roy@marples.name>
parents:
4447
diff
changeset
|
619 rb_tree_remove_node(kroutes, ort); |
|
768ba28719eb
route: Fix stamping on existing kernel routes
Roy Marples <roy@marples.name>
parents:
4447
diff
changeset
|
620 rt_free(ort); |
|
768ba28719eb
route: Fix stamping on existing kernel routes
Roy Marples <roy@marples.name>
parents:
4447
diff
changeset
|
621 } |
|
768ba28719eb
route: Fix stamping on existing kernel routes
Roy Marples <roy@marples.name>
parents:
4447
diff
changeset
|
622 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
|
623 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
624 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
625 static bool |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
626 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
|
627 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
628 int retval; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
629 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
630 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
|
631 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
|
632 if (!retval && errno != ENOENT && errno != ESRCH) |
| 4010 | 633 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
|
634 return retval; |
|
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_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
|
639 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
640 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
641 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
|
642 #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
|
643 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
|
644 #endif |
|
4142
6b945412fa08
Fix checking gateways in route comparison.
Roy Marples <roy@marples.name>
parents:
4067
diff
changeset
|
645 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
|
646 } |
|
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 static bool |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4396
diff
changeset
|
649 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
|
650 { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
651 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
|
652 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
|
653 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
654 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
|
655 /* 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
|
656 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
|
657 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
|
658 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
|
659 return true; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
660 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
|
661 !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
|
662 (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
|
663 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
|
664 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
|
665 { |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4396
diff
changeset
|
666 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
|
667 return false; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
668 } |
|
4379
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
669 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
|
670 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
|
671 } else { |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
672 if (rt->rt_dflags & RTDF_FAKE) { |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4396
diff
changeset
|
673 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
|
674 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
|
675 return false; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
676 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
|
677 return false; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
678 } else { |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4396
diff
changeset
|
679 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
|
680 return false; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
681 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
682 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
683 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
684 return true; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
685 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
686 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
687 void |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
688 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
|
689 { |
| 4447 | 690 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
|
691 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
|
692 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
|
693 |
|
4522
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
694 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
|
695 rb_tree_init(&added, &rt_compare_os_ops); |
| 4447 | 696 rb_tree_init(&kroutes, &rt_compare_os_ops); |
| 697 if_initrt(ctx, &kroutes, af); | |
|
4522
e2582c7c7e1d
route: Use order from message / config
Roy Marples <roy@marples.name>
parents:
4518
diff
changeset
|
698 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
|
699 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
|
700 |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
701 #ifdef INET |
|
5057
a5fd2097d40f
BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
702 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
|
703 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
|
704 #endif |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
705 #ifdef INET6 |
|
5057
a5fd2097d40f
BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
706 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
|
707 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
|
708 #endif |
|
5057
a5fd2097d40f
BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
709 |
|
a5fd2097d40f
BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
710 #ifdef BSD |
|
a5fd2097d40f
BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
711 /* Rewind the miss filter */ |
|
a5fd2097d40f
BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
712 ctx->rt_missfilterlen = 0; |
|
a5fd2097d40f
BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
713 #endif |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
714 |
|
4379
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
715 RB_TREE_FOREACH_SAFE(rt, &routes, rtn) { |
| 5535 | 716 if (rt->rt_ifp && rt->rt_ifp->options && |
| 717 !(rt->rt_ifp->options->options & DHCPCD_CONFIGURE)) | |
| 718 continue; | |
|
5057
a5fd2097d40f
BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
719 #ifdef BSD |
|
a5fd2097d40f
BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
720 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
|
721 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
|
722 logerr("if_missfilter"); |
|
a5fd2097d40f
BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
723 #endif |
|
4553
8289f982fb87
route: Compare AF_UNSPEC family when cleaning old routes
Roy Marples <roy@marples.name>
parents:
4548
diff
changeset
|
724 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
|
725 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
|
726 (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
|
727 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
|
728 continue; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
729 /* 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
|
730 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
|
731 continue; |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4396
diff
changeset
|
732 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
|
733 rb_tree_remove_node(&routes, rt); |
|
4396
5bdea847921d
route: Free route when failing to insert.
Roy Marples <roy@marples.name>
parents:
4395
diff
changeset
|
734 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
|
735 errno = EEXIST; |
|
5bdea847921d
route: Free route when failing to insert.
Roy Marples <roy@marples.name>
parents:
4395
diff
changeset
|
736 logerr(__func__); |
|
5bdea847921d
route: Free route when failing to insert.
Roy Marples <roy@marples.name>
parents:
4395
diff
changeset
|
737 rt_free(rt); |
|
5bdea847921d
route: Free route when failing to insert.
Roy Marples <roy@marples.name>
parents:
4395
diff
changeset
|
738 } |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
739 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
740 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
741 |
|
5057
a5fd2097d40f
BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
742 #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
|
743 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
|
744 logerr("if_missfilter_apply"); |
|
a5fd2097d40f
BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
745 #endif |
|
a5fd2097d40f
BSD: Add support for RO_MISSFILTER route(4) socket option
Roy Marples <roy@marples.name>
parents:
4922
diff
changeset
|
746 |
|
4143
bb9bb396ab37
Don't special case not deleteing the IPv6 default route.
Roy Marples <roy@marples.name>
parents:
4142
diff
changeset
|
747 /* 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
|
748 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
|
749 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
|
750 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
|
751 (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
|
752 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
|
753 continue; |
|
4379
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
754 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
|
755 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
|
756 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
|
757 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
|
758 ctx->options; |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
759 if ((o & |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
760 (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
|
761 (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
|
762 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
|
763 } |
|
4379
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
764 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
|
765 } |
|
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
766 |
|
4392
af390080e632
route: replace rt_find with rb_tree_find_node
Roy Marples <roy@marples.name>
parents:
4391
diff
changeset
|
767 /* 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
|
768 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
|
769 rb_tree_remove_node(&added, rt); |
|
4396
5bdea847921d
route: Free route when failing to insert.
Roy Marples <roy@marples.name>
parents:
4395
diff
changeset
|
770 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
|
771 errno = EEXIST; |
|
5bdea847921d
route: Free route when failing to insert.
Roy Marples <roy@marples.name>
parents:
4395
diff
changeset
|
772 logerr(__func__); |
|
5bdea847921d
route: Free route when failing to insert.
Roy Marples <roy@marples.name>
parents:
4395
diff
changeset
|
773 rt_free(rt); |
|
5bdea847921d
route: Free route when failing to insert.
Roy Marples <roy@marples.name>
parents:
4395
diff
changeset
|
774 } |
|
4379
e9573d5cbf1e
Replace route TAILQ macros with rbtree(3) from NetBSD.
Roy Marples <roy@marples.name>
parents:
4378
diff
changeset
|
775 } |
|
4149
fce599d14e9a
Free any allocated routes if we failed to allocate some.
Roy Marples <roy@marples.name>
parents:
4143
diff
changeset
|
776 |
|
fce599d14e9a
Free any allocated routes if we failed to allocate some.
Roy Marples <roy@marples.name>
parents:
4143
diff
changeset
|
777 getfail: |
|
3932
e802a4235d75
Move the source files along with dev, crypt and comapt into src dir.
Roy Marples <roy@marples.name>
parents:
diff
changeset
|
778 rt_headclear(&routes, AF_UNSPEC); |
|
4400
2d6a2c8c6b56
route: Remove kroutes and make froutes optional
Roy Marples <roy@marples.name>
parents:
4396
diff
changeset
|
779 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
|
780 } |
