├── LICENSE ├── README.md ├── babeld-safe.conf ├── babeld.conf ├── bird-safe.conf ├── bird.conf ├── olsr2.conf └── rtod /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # rtod: Routing Tables of Death 2 | 3 | rtod allows for the rapid injection and removal of large numbers of 4 | distinct routes per host, as a means to test the capabilities of 5 | kernels, routing protocols, and routing daemons. 6 | 7 | Do NOT run this on a production network. DO read this documentation. 8 | 9 | The rtod script was developed to stress test kernel routing 10 | features, daemons, and protocols as a means to measure their 11 | behavior and make them better. 12 | 13 | rtod is as robust as I can make it - running it in more extreme 14 | modes tends to make tcp connections fail - so it has multiple means 15 | to clean up after itself automatically. You will certainly see 16 | network routing misbehave badly - and it might take 10s of 17 | minutes for the network to recover, but it will, eventually. Usually. 18 | Still, in addition to potentially disrupting your routing until many minutes after the test ends: 19 | 20 | - You may need to clean up nohup.out or kill off processes manually. 21 | 22 | - You can easily melt a processor. Or: destroy your flash if you are keeping extensive logging on it. 23 | 24 | - You might end up with other system critical processes, like network manager or odhcpd, hung or spinning madly. 25 | 26 | - You might run your kernel into the ground. 27 | 28 | - You might run out of memory and engage the oom killer on stuff you don't want killed. 29 | 30 | - You might get your whole network into a state where you have to power cycle every router simultaneously. 31 | 32 | - You might contribute to global warming. 33 | 34 | Be *careful* with this tool. Lest you think I'm being overly dire - I've already done all the above to myself while testing. I'm trying to make things better by adding compute bounds, testing under loads induced by flent, better error handling, and so on. 35 | 36 | # Setup 37 | 38 | rtod uses the unallocated fc::/8 ULA address space to do its damage. 39 | 40 | Make utterly sure your production network refuses to forward routes 41 | injected by this script. You can easily insert a number of routes 42 | far in excess of what most daemons, cpus, and protocols can handle. 43 | 44 | Sample conf files are provided for babeld for setup of both the 45 | routers under test and the routers that are not. I will add conf 46 | files for bird, olsr, bmx, etc as time goes by. 47 | 48 | Test on a small scale, first. Make absolutely sure nothing escapes. 49 | 50 | # Uses: standalone 51 | 52 | rtod's defaults are enough to mildly stress out most mesh networks. 53 | They add 256 routes for 600 seconds. This generally does no damage. 54 | 55 | These defaults are useful for reliably repeating routing behaviors 56 | that are expected and normal, and observing metric evolution 57 | elsewhere. 58 | 59 | ## rtod -r 1024 60 | 61 | This is close to the figure being used in several production mesh 62 | networks. This begins to stress out the cpu in mips routers. 63 | The route injection itself takes many seconds for the daemon 64 | to process. 65 | 66 | ## rtod -r 2048 67 | 68 | This starts to stress out local route distribution mechanisms 69 | over wifi multicast, and the protocol itself. 70 | 71 | Low end ARM and MIPs CPUs start getting warm. There is often 72 | a network burp while the router getting these routes sorts them out. 73 | 74 | Routers using slow multicast start dropping off the network. 75 | 76 | ## rtod -r 4096 77 | 78 | At this level the local network daemon tends to run out of cpu on 79 | just merging in the local kernel table. Other daemons interpreting 80 | the protocol begin to struggle also. 81 | 82 | Low end ARM and MIPs CPUs get very warm. In fact, so do low end 83 | X86_64 platforms like the pcengines apu2. 84 | 85 | Routers using slow multicast drop off the network completely. 86 | 87 | ## rtod -r 10000 88 | 89 | This tends to completely overburden the local daemon with "interesting" 90 | results on the rest of the network. Multicast becomes a huge 91 | bottleneck. Updates lag 10s of seconds, even minutes, behind. 92 | 93 | The injected router falls off the network, having partially announced 94 | its tables, while other daemons strain to keep up and re-announce what 95 | they got while its already become invalid. Many. Bad. Things. Happen. 96 | 97 | Did I mention you should not run this on a production network? 98 | 99 | In most of my tests thus far, anything above 2000 total routes begins 100 | to degrade the connectivity of a network severely. With some tuning, 101 | I've got babeld to about 5k routes but it is still barely hanging on 102 | at that level, 103 | 104 | ## rtod -r 64000 105 | 106 | Don't do this. 107 | 108 | # Uses: with other routers in the loop 109 | 110 | Given that I have many routers, I push tests to them via pdsh. With 111 | a smaller number of local route tables, they will generate 112 | distinct routes based on their hostnames, and not cpu bottleneck 113 | on getting routes out of the kernel. 114 | 115 | ```` 116 | pdsh -g chips rtod -r 128 # push out 512 routes total to my 4 "c.h.i.p"s. 117 | ```` 118 | 119 | This is a much better test of what actually happens with multiple routers 120 | in play, in multiple places, and more complex scenarios can be easily 121 | simulated. I have one with 32 simulated routers over a network diameter 122 | of 12 hops and 3k routes, for example. 123 | 124 | # Uses: Anycast emulation 125 | 126 | by supplying the -H option to each invocation, we can have all routers 127 | announce they have routes to the same host, and confuse them appropriately 128 | 129 | ```` 130 | pdsh -g chips rtod -r 256 -H mytest 131 | ```` 132 | 133 | # Additional command line parameters 134 | 135 | ## -K - the Killme command. 136 | 137 | This is used by rtod internally to make sure it 138 | kills itself off and flushes its routes. 139 | 140 | When used (often in desperation) at the command line, you can say: 141 | 142 | ```` 143 | rtod -K -t 0 144 | ```` 145 | 146 | To have it flush all routes immediately. 147 | 148 | ## -r routes 149 | 150 | Injects this number of routes, in the range 1-65534. 151 | 152 | ## -H hostname 153 | 154 | Specify a different hostname to use. The hostname is used to 155 | generate a md5 hash that is then turned into a usually distinct 156 | ipv6 address. 157 | 158 | ## -i IFACE 159 | 160 | You can setup an alternative interface to use that is not a dummy. 161 | 162 | If dummy interfaces are not available, and no iface is specified, 163 | the ip6-localnet interface is used. 164 | 165 | ## -p PROTO 166 | 167 | rtod uses a separate kernel protocol table to inject and manage 168 | routes and addresses. The default is proto 50, which is unallocated 169 | by the ietf and any other daemon I'm aware of. You can use any proto 170 | you want, but, you should not - unless you want to confuse them - 171 | inject routes into the kernel tables being managed by your daemons 172 | in the first place. 173 | 174 | This include static and boot routes as the rtod cleanup routine will wipe 175 | those out, too. 176 | 177 | ## -j jitter -J JITTER 178 | 179 | Unimplemented, but the intent is to have routes disappear and re-appear 180 | as if they were normally being lost and re-gained. 181 | 182 | ## -s Source specific offset 183 | 184 | -s offset 185 | 186 | must be a power of two, that will inject source specific routes for a 187 | subset of existing routes. 188 | 189 | Unimplemented, presently. 190 | 191 | ## -t expires (in seconds) 192 | 193 | The duration of the test before routes are flushed. 194 | 195 | ## -m metric 196 | 197 | Use a different metric to insert the routes than the default. 198 | 199 | Unimplemented. 200 | 201 | ## -M Random Metric Range 202 | 203 | Inject a random metric from 0 through -M when creating the 204 | routes. 205 | 206 | Unimplemented. 207 | 208 | ## -R route_table_dump_file 209 | 210 | Inject an exact duplicate (rapidly) of a file saved with 211 | 212 | ```` 213 | ip route save proto 50 > route_table_dump_file 214 | ```` 215 | 216 | via 217 | 218 | ```` 219 | ip route restore proto 50 < route_table_dump_file 220 | ```` 221 | 222 | de-implemented, as it has a flaw of not inserting the expires figure, 223 | and the whole point of rtod is to be able to survive abuse such 224 | as this. 225 | 226 | -------------------------------------------------------------------------------- /babeld-safe.conf: -------------------------------------------------------------------------------- 1 | # babeld safety tip for non-testbed routers 2 | # Make sure every gateway to your production network 3 | # ignores fc routes. Otherwise bad things can happen! 4 | 5 | # fcXX is used by rtod for test routes 6 | # with these two filters in place even the cheapest gw basically 7 | # ignores an rtod test. You might think fc::/8 would work. It doesn't. 8 | # use fc00::/8. 9 | 10 | in ip fc00::/8 ge 8 deny 11 | in src-ip fc00::/8 ge 8 deny 12 | 13 | # in ip a000::/8 ge 8 deny # core emulator uses "a" as a default 14 | 15 | # if you accidentally end up running rtod on this box 16 | 17 | redistribute ip fc00::/8 ge 8 deny 18 | redistribute ip fc00::/8 le 8 deny 19 | 20 | -------------------------------------------------------------------------------- /babeld.conf: -------------------------------------------------------------------------------- 1 | # For more information about this configuration file, refer to 2 | # babeld(8) 3 | # default enable-timestamps true 4 | redistribute proto 50 metric 128 5 | -------------------------------------------------------------------------------- /bird-safe.conf: -------------------------------------------------------------------------------- 1 | router id 62.168.0.1; 2 | 3 | # Enable debugging output 4 | debug protocols all; 5 | 6 | # Need to define table for ipv6 sadr (v4 is implicitly defined as 'master4') 7 | ipv6 sadr table tab1; 8 | 9 | # Listen to dev up/down events 10 | protocol device {} 11 | 12 | # Blacklisting and filtering from kernel 13 | define blacklist = [ 14 | fc::/8, 15 | a::/16, 16 | 127.0.0.0/8 17 | ]; 18 | 19 | filter import_filter 20 | { 21 | # Filter routes in blacklist 22 | if (net ~ blacklist) then reject "blacklisted"; 23 | # Only import kernel protocol 50 24 | #if (krt_source != 50) then reject "wrong protocol"; 25 | accept; 26 | } 27 | 28 | protocol kernel { 29 | ipv6 sadr { 30 | table tab1; 31 | export all; 32 | import filter import_filter; 33 | }; 34 | learn yes; 35 | } 36 | 37 | protocol kernel { 38 | ipv4 { 39 | export all; 40 | import filter import_filter; 41 | }; 42 | learn yes; 43 | } 44 | 45 | # Create routes subnets configured on interfaces 46 | protocol direct { 47 | ipv6 sadr; 48 | ipv4; 49 | } 50 | 51 | protocol babel { 52 | ipv6 sadr { 53 | table tab1; 54 | import all; 55 | # Set initial metric for all routes 56 | export filter { babel_metric = 128; accept; }; 57 | }; 58 | ipv4 { 59 | import all; 60 | # Set initial metric for all routes 61 | export filter { babel_metric = 128; accept; }; 62 | }; 63 | # Interfaces to listen on and their config 64 | interface "eth0" { type wired; }; 65 | interface "wlan0" { type wireless; }; 66 | } 67 | -------------------------------------------------------------------------------- /bird.conf: -------------------------------------------------------------------------------- 1 | router id 62.168.0.1; # change this for each router! 2 | 3 | # Enable debugging output 4 | debug protocols all; 5 | 6 | # Need to define table for ipv6 sadr (v4 is implicitly defined as 'master4') 7 | ipv6 sadr table tab1; 8 | 9 | # Listen to dev up/down events 10 | protocol device {} 11 | 12 | # Blacklisting and filtering from kernel 13 | define blacklist = [ 14 | a::/16, 15 | 127.0.0.0/8 16 | ]; 17 | 18 | filter import_filter 19 | { 20 | # Filter routes in blacklist 21 | if (net ~ blacklist) then reject "blacklisted"; 22 | # Only import kernel protocol 50 23 | #if (krt_source != 50) then reject "wrong protocol"; 24 | accept; 25 | } 26 | 27 | protocol kernel { 28 | ipv6 sadr { 29 | table tab1; 30 | export all; 31 | import filter import_filter; 32 | }; 33 | learn yes; 34 | } 35 | 36 | protocol kernel { 37 | ipv4 { 38 | export all; 39 | import filter import_filter; 40 | }; 41 | learn yes; 42 | } 43 | 44 | # Create routes subnets configured on interfaces 45 | protocol direct { 46 | ipv6 sadr; 47 | ipv4; 48 | } 49 | 50 | protocol babel { 51 | ipv6 sadr { 52 | table tab1; 53 | import all; 54 | # Set initial metric for all routes 55 | export filter { babel_metric = 128; accept; }; 56 | }; 57 | ipv4 { 58 | import all; 59 | # Set initial metric for all routes 60 | export filter { babel_metric = 128; accept; }; 61 | }; 62 | # Interfaces to listen on and their config 63 | interface "eth0" { type wired; }; 64 | interface "wlan0" { type wireless; }; 65 | } 66 | -------------------------------------------------------------------------------- /olsr2.conf: -------------------------------------------------------------------------------- 1 | # From Henning Rogge: 2 | # the "lan_import" plugin is your friend... I have used it to test 3 | # OLSRv2 (with 2 nodes) with 20k routes (10k IPv4 and 10k IPv6). Unless 4 | # I broke something since then I expect it to work. 5 | # Try to use the following snippet in the config: 6 | 7 | [lan_import=1] 8 | proto 50 9 | 10 | # This should add all local routes with proto 1234 as "locally attached 11 | # networks" (was called HNA in OLSRv1) to the local node, which means 12 | # all other nodes will build up routes towards the local node. 13 | 14 | # You can also use the "table" key of the same plugin to directly 15 | # import a routing table into Olsrd2. 16 | -------------------------------------------------------------------------------- /rtod: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # rtod "Routing tables of Death" 3 | # This script exercises the routing protocol and daemons involved by 4 | # injecting a definable number of ipv6 routes for a limited time. 5 | # The default is 256 routes for 10 minutes, using proto table 50 6 | # on a dummy interface of rtod0, using the unallocated fc::/8 ULA space. 7 | # It has an upper limit of 64k routes. 8 | 9 | # These variables can be overridden from the command line 10 | # You should not touch anything from here directly 11 | 12 | SELF=$0 13 | ARGS="$@" 14 | HOST="" 15 | EXPIRES=600 16 | ROUTES=256 17 | IFACE=rtod0 18 | PROTO=50 19 | NOEXPIRES=0 20 | KILLME=0 21 | JITTERE=0 22 | JITTERR=0 23 | RTABLE="" # external route table to recreate 24 | NOHUP=`which nohup` 25 | NODUMMY=0 26 | SS=0 27 | PLEN=64 # FIXME: a good idea to start testing variable length prefixes too 28 | 29 | # Randomize the starting point one day 30 | #R1=${RANDOM} 31 | #R2=${RANDOM} 32 | #R=`expr ${R1} \* ${R2}` 33 | 34 | # But for now: 35 | 36 | R=1 37 | 38 | export PREFIX PROTO IFACE ROUTES EXPIRES HOST KILLME 39 | export PLEN JITTERE JITTERR 40 | 41 | sanity_check() { 42 | if [ -z "$NOHUP" ] 43 | then 44 | NOHUP=`which sh` 45 | fi 46 | # There is seemingly no standard for getting the hostname 47 | if [ -z $HOST ] 48 | then 49 | if [ -z "$HOSTNAME" ] 50 | then 51 | HOST=`hostname -f` 52 | if [ -z "$HOST" ] 53 | then 54 | echo "Please set a hostname" 55 | exit 1 56 | fi 57 | else 58 | HOST=$HOSTNAME 59 | fi 60 | fi 61 | 62 | # Dummy interfaces are not standard 63 | # But: using a dummy interface leads to saner stats if available. 64 | 65 | ip link add ${IFACE}test type dummy 2> /dev/null 66 | if [ "$?" != "0" ] 67 | then 68 | NODUMMY=1 69 | echo "No dummy interface available, using lo" 70 | IFACE=lo 71 | # some systems don't even define that much. lo0? 72 | fi 73 | ip link del ${IFACE}test type dummy 2> /dev/null 74 | 75 | } 76 | 77 | setup() { 78 | 79 | if [ "$NODUMMY" = "0" ] 80 | then 81 | ip link add ${IFACE} type dummy 2> /dev/null 82 | ip link set $IFACE up 2> /dev/null 83 | fi 84 | 85 | # First add a covering route to add to the fun 86 | 87 | EXP2=$EXPIRES 88 | EXP3=$EXPIRES 89 | 90 | # and let it stick around less... 91 | 92 | if [ "$EXPIRES" -gt 200 ] 93 | then 94 | EXP2=`expr $EXP2 - 60` 95 | EXP3=`expr $EXPIRES - 120` 96 | fi 97 | 98 | # Does expires work? Expires is a really nice safety valve to have 99 | # but only works correctly in iproute 4.9 and above 100 | 101 | EXPIRESTR="expires $EXPIRES" 102 | 103 | ip -6 route replace ${PREFIX}:/48 dev $IFACE $EXPIRESTR \ 104 | proto $PROTO 2> /dev/null 105 | 106 | if [ "$?" -ne "0" ] 107 | then 108 | EXPIRESTR="" 109 | NOEXPIRES=1 110 | echo "no ip route expires support - falling back to $SELF -K" 111 | if [ $KILLME = 0 ] 112 | then 113 | $NOHUP "$SELF" -t $EXPIRES -i $IFACE -r $ROUTES -K $ARGS & 114 | fi 115 | ip -6 route replace ${PREFIX}:/48 dev $IFACE proto $PROTO 116 | ip -6 route replace ${PREFIX}:/56 dev $IFACE proto $PROTO 117 | ip -6 addr replace ${PREFIX}:1/48 dev $IFACE \ 118 | valid_lft $EXPIRES preferred_lft $EXPIRES noprefixroute 119 | ip -6 addr replace ${PREFIX}:2/64 dev $IFACE \ 120 | valid_lft $EXPIRES preferred_lft $EXPIRES 121 | else 122 | ip -6 route replace ${PREFIX}:/56 dev $IFACE expires $EXP3 proto $PROTO 123 | ip -6 addr replace ${PREFIX}:1/48 dev $IFACE \ 124 | valid_lft $EXPIRES preferred_lft $EXPIRES noprefixroute 125 | ip -6 addr replace ${PREFIX}:2/64 dev $IFACE \ 126 | valid_lft $EXPIRES preferred_lft $EXPIRES 127 | 128 | fi 129 | 130 | # Does source specific work? Requires IPV6SUBTREES in the kernel 131 | 132 | ip -6 route replace from ${PREFIX}:/48 via ${PREFIX}:1\ 133 | dev $IFACE $EXPIRESTR \ 134 | proto $PROTO 2> /dev/null 135 | 136 | if [ "$?" -ne "0" -a "$SS" -ne "0" ] 137 | then 138 | S1=$SS 139 | for i in `seq $R $ROUTERS` 140 | do 141 | S2=`expr $i % $S1` 142 | if [ $S2 = 0 ] 143 | then 144 | # FIXME, unfinished 145 | 146 | ip -6 route replace from ${PREFIX}:/$P2 \ 147 | via ${PREFIX}:1\ 148 | dev $IFACE $EXPIRESTR \ 149 | proto $PROTO 2> /dev/null 150 | fi 151 | done 152 | else 153 | echo "Please compile IPV6SUBTREES into your kernel" 154 | fi 155 | 156 | } 157 | 158 | teardown() { 159 | if [ "$IFACE" != "lo" ] 160 | then 161 | ifconfig $IFACE # get some stats 162 | ip link del $IFACE type dummy 2&1> /dev/null 163 | fi 164 | } 165 | 166 | del() { 167 | ip -6 route flush dev $IFACE proto $PROTO 168 | } 169 | 170 | 171 | teardownall() { 172 | del 173 | teardown 174 | exit 0 175 | } 176 | 177 | killme() { 178 | sleep $EXPIRES 179 | teardownall 180 | } 181 | 182 | # mainline seq supports printf, busybox does not 183 | 184 | add() { 185 | if [ "$NOEXPIRES" = "0" ] 186 | then 187 | for i in `seq $R $ROUTES` 188 | do 189 | local E2=`printf %x ${i}` 190 | ip -6 route replace ${PREFIX}${E2}::/$PLEN dev $IFACE \ 191 | proto $PROTO expires $EXPIRES 192 | done 193 | else 194 | for i in `seq $R $ROUTES` 195 | do 196 | local E2=`printf %x ${i}` 197 | ip -6 route replace ${PREFIX}${E2}::/$PLEN dev $IFACE \ 198 | proto $PROTO 199 | done 200 | fi 201 | } 202 | 203 | 204 | usage() { 205 | echo \ 206 | "rtod -r number_of_routes -t time_to_keep_them -p protocol table\n 207 | -s source specific -H host -K (killme) -m metric -i interface\n 208 | -M random metric max -j expire jitter -J renew jitter -F dumpfile" 209 | exit 1 210 | } 211 | 212 | # Kill our routes on an abort 213 | 214 | trap teardownall 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 215 | 216 | # main program 217 | 218 | while getopts "Is:H:Khr:t:n:i:m:p:j:J:R:" Option 219 | do 220 | case $Option in 221 | j) JITTERE=${OPTARG};; # unimplemented 222 | J) JITTERR=${OPTARG};; # unimplemented 223 | s) SS=${OPTARG};; # unimplemented 224 | I) INVALID=${OPTARG};; # install some invalid routes 225 | H) HOST=${OPTARG};; 226 | K) KILLME=1;; 227 | p) PROTO=${OPTARG};; 228 | t) EXPIRES=${OPTARG};; 229 | M) RANDMETRIC=${OPTARG};; # unimplemented 230 | m) METRIC=${OPTARG};; 231 | r) ROUTES=${OPTARG};; 232 | R) RTABLE=${OPTARG};; # unimplemented 233 | i) IFACE=${OPTARG};; 234 | h) usage ;; 235 | *) usage $E_OPTERROR;; # DEFAULT 236 | esac 237 | OPRIND=${OPTIND} 238 | done 239 | 240 | sanity_check 241 | 242 | # IPv6 Prefix generator 243 | # Crudely but consistently generate a random PREFIX 244 | # use the fc range to keep it clear 245 | 246 | a=`echo $HOST | md5sum` 247 | 248 | # You'd think the ietf standards would let you just 249 | # punch in a hex string without colons. But noooo.... 250 | # bash version: 251 | # PREFIX1=fc${a:0:2}:${a:3:4}:${a:7:4}: 252 | # universal version: 253 | 254 | PREFIX=fc`echo $a | awk \ 255 | '{print (substr($1,0,2)":"substr($1,4,4)":"substr($1,8,4)":")}'` 256 | 257 | if [ $KILLME = 1 ] 258 | then 259 | sleep $EXPIRES 260 | del 261 | teardown 262 | 263 | else 264 | echo "$HOST has $PREFIX from $R to $ROUTES \ 265 | for $EXPIRES sec" 266 | setup 267 | add 268 | fi 269 | 270 | if [ "$JITTERE" -ne 0 -o "$JITTERR" -ne 0 ] 271 | then 272 | : 273 | fi 274 | 275 | # Originally I had this exit entirely into the background 276 | # as I was regularly causing disconnects and monitoring with 277 | # nohup. Turns out lede doesn't have nohup. Or hostname 278 | 279 | wait 280 | 281 | # It seems possible to inject routes we cannot forward - because users can specify non - fe80 next hops 282 | # ip -6 route replace fc02:b738:e988::/62 from fc02:b738:e988::/48 via fe80::4493:14ff:fe70:954e dev eno1 proto 50 283 | #root@dancer:~/git/rtod# ip -6 route replace fc02:b738:e988::/62 from fc02:b738:e988::/48 via fc02:2:1::1 dev eno1 proto 50RTNETLINK answers: No route to host 284 | #But this will work, even if it is non-sensical in some respects 285 | #root@dancer:~/git/rtod# ip route add fc02:2:1::1 dev eno1 286 | #root@dancer:~/git/rtod# ip -6 route replace fc02:b738:e988::/62 from fc02:b738:e988::/48 via fc02:2:1::1 dev eno1 proto 50 287 | 288 | --------------------------------------------------------------------------------