routes_test.go 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207
  1. // Copyright 2019 the Kilo authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package mesh
  15. import (
  16. "testing"
  17. "github.com/kylelemons/godebug/pretty"
  18. "github.com/vishvananda/netlink"
  19. "golang.org/x/sys/unix"
  20. "github.com/squat/kilo/pkg/encapsulation"
  21. )
  22. func TestRoutes(t *testing.T) {
  23. nodes, peers, key, port := setup(t)
  24. kiloIface := 0
  25. privIface := 1
  26. tunlIface := 2
  27. mustTopoForGranularityAndHost := func(granularity Granularity, hostname string) *Topology {
  28. return mustTopo(t, nodes, peers, granularity, hostname, port, key, DefaultKiloSubnet, 0)
  29. }
  30. for _, tc := range []struct {
  31. name string
  32. local bool
  33. topology *Topology
  34. strategy encapsulation.Strategy
  35. routes []*netlink.Route
  36. rules []*netlink.Rule
  37. }{
  38. {
  39. name: "logical from a",
  40. topology: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name),
  41. strategy: encapsulation.Never,
  42. routes: []*netlink.Route{
  43. {
  44. Dst: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).segments[1].cidrs[0],
  45. Flags: int(netlink.FLAG_ONLINK),
  46. Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).segments[1].wireGuardIP,
  47. LinkIndex: kiloIface,
  48. Src: nodes["a"].InternalIP.IP,
  49. Protocol: unix.RTPROT_STATIC,
  50. },
  51. {
  52. Dst: oneAddressCIDR(nodes["b"].InternalIP.IP),
  53. Flags: int(netlink.FLAG_ONLINK),
  54. Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).segments[1].wireGuardIP,
  55. LinkIndex: kiloIface,
  56. Src: nodes["a"].InternalIP.IP,
  57. Protocol: unix.RTPROT_STATIC,
  58. },
  59. {
  60. Dst: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).segments[1].cidrs[1],
  61. Flags: int(netlink.FLAG_ONLINK),
  62. Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).segments[1].wireGuardIP,
  63. LinkIndex: kiloIface,
  64. Src: nodes["a"].InternalIP.IP,
  65. Protocol: unix.RTPROT_STATIC,
  66. },
  67. {
  68. Dst: oneAddressCIDR(nodes["c"].InternalIP.IP),
  69. Flags: int(netlink.FLAG_ONLINK),
  70. Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).segments[1].wireGuardIP,
  71. LinkIndex: kiloIface,
  72. Src: nodes["a"].InternalIP.IP,
  73. Protocol: unix.RTPROT_STATIC,
  74. },
  75. {
  76. Dst: &nodes["b"].AllowedLocationIPs[0],
  77. Flags: int(netlink.FLAG_ONLINK),
  78. Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).segments[1].wireGuardIP,
  79. LinkIndex: kiloIface,
  80. Src: nodes["a"].InternalIP.IP,
  81. Protocol: unix.RTPROT_STATIC,
  82. },
  83. {
  84. Dst: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).segments[2].cidrs[0],
  85. Flags: int(netlink.FLAG_ONLINK),
  86. Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).segments[2].wireGuardIP,
  87. LinkIndex: kiloIface,
  88. Src: nodes["a"].InternalIP.IP,
  89. Protocol: unix.RTPROT_STATIC,
  90. },
  91. {
  92. Dst: &peers["a"].AllowedIPs[0],
  93. LinkIndex: kiloIface,
  94. Src: nodes["a"].InternalIP.IP,
  95. Protocol: unix.RTPROT_STATIC,
  96. },
  97. {
  98. Dst: &peers["a"].AllowedIPs[1],
  99. LinkIndex: kiloIface,
  100. Src: nodes["a"].InternalIP.IP,
  101. Protocol: unix.RTPROT_STATIC,
  102. },
  103. {
  104. Dst: &peers["b"].AllowedIPs[0],
  105. LinkIndex: kiloIface,
  106. Src: nodes["a"].InternalIP.IP,
  107. Protocol: unix.RTPROT_STATIC,
  108. },
  109. },
  110. },
  111. {
  112. name: "logical from b",
  113. topology: mustTopoForGranularityAndHost(LogicalGranularity, nodes["b"].Name),
  114. strategy: encapsulation.Never,
  115. routes: []*netlink.Route{
  116. {
  117. Dst: mustTopoForGranularityAndHost(LogicalGranularity, nodes["b"].Name).segments[0].cidrs[0],
  118. Flags: int(netlink.FLAG_ONLINK),
  119. Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["b"].Name).segments[0].wireGuardIP,
  120. LinkIndex: kiloIface,
  121. Src: nodes["b"].InternalIP.IP,
  122. Protocol: unix.RTPROT_STATIC,
  123. },
  124. {
  125. Dst: oneAddressCIDR(nodes["a"].InternalIP.IP),
  126. Flags: int(netlink.FLAG_ONLINK),
  127. Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["b"].Name).segments[0].wireGuardIP,
  128. LinkIndex: kiloIface,
  129. Src: nodes["b"].InternalIP.IP,
  130. Protocol: unix.RTPROT_STATIC,
  131. },
  132. {
  133. Dst: mustTopoForGranularityAndHost(LogicalGranularity, nodes["b"].Name).segments[2].cidrs[0],
  134. Flags: int(netlink.FLAG_ONLINK),
  135. Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["b"].Name).segments[2].wireGuardIP,
  136. LinkIndex: kiloIface,
  137. Src: nodes["b"].InternalIP.IP,
  138. Protocol: unix.RTPROT_STATIC,
  139. },
  140. {
  141. Dst: &peers["a"].AllowedIPs[0],
  142. LinkIndex: kiloIface,
  143. Src: nodes["b"].InternalIP.IP,
  144. Protocol: unix.RTPROT_STATIC,
  145. },
  146. {
  147. Dst: &peers["a"].AllowedIPs[1],
  148. LinkIndex: kiloIface,
  149. Src: nodes["b"].InternalIP.IP,
  150. Protocol: unix.RTPROT_STATIC,
  151. },
  152. {
  153. Dst: &peers["b"].AllowedIPs[0],
  154. LinkIndex: kiloIface,
  155. Src: nodes["b"].InternalIP.IP,
  156. Protocol: unix.RTPROT_STATIC,
  157. },
  158. },
  159. },
  160. {
  161. name: "logical from c",
  162. topology: mustTopoForGranularityAndHost(LogicalGranularity, nodes["c"].Name),
  163. strategy: encapsulation.Never,
  164. routes: []*netlink.Route{
  165. {
  166. Dst: oneAddressCIDR(mustTopoForGranularityAndHost(LogicalGranularity, nodes["c"].Name).segments[0].wireGuardIP),
  167. Flags: int(netlink.FLAG_ONLINK),
  168. Gw: nodes["b"].InternalIP.IP,
  169. LinkIndex: privIface,
  170. Protocol: unix.RTPROT_STATIC,
  171. },
  172. {
  173. Dst: mustTopoForGranularityAndHost(LogicalGranularity, nodes["c"].Name).segments[0].cidrs[0],
  174. Flags: int(netlink.FLAG_ONLINK),
  175. Gw: nodes["b"].InternalIP.IP,
  176. LinkIndex: privIface,
  177. Protocol: unix.RTPROT_STATIC,
  178. },
  179. {
  180. Dst: oneAddressCIDR(nodes["a"].InternalIP.IP),
  181. Flags: int(netlink.FLAG_ONLINK),
  182. Gw: nodes["b"].InternalIP.IP,
  183. LinkIndex: privIface,
  184. Protocol: unix.RTPROT_STATIC,
  185. },
  186. {
  187. Dst: oneAddressCIDR(mustTopoForGranularityAndHost(LogicalGranularity, nodes["c"].Name).segments[1].wireGuardIP),
  188. Flags: int(netlink.FLAG_ONLINK),
  189. Gw: nodes["b"].InternalIP.IP,
  190. LinkIndex: privIface,
  191. Protocol: unix.RTPROT_STATIC,
  192. },
  193. {
  194. Dst: oneAddressCIDR(mustTopoForGranularityAndHost(LogicalGranularity, nodes["c"].Name).segments[2].wireGuardIP),
  195. Flags: int(netlink.FLAG_ONLINK),
  196. Gw: nodes["b"].InternalIP.IP,
  197. LinkIndex: privIface,
  198. Protocol: unix.RTPROT_STATIC,
  199. },
  200. {
  201. Dst: mustTopoForGranularityAndHost(LogicalGranularity, nodes["c"].Name).segments[2].cidrs[0],
  202. Flags: int(netlink.FLAG_ONLINK),
  203. Gw: nodes["b"].InternalIP.IP,
  204. LinkIndex: privIface,
  205. Protocol: unix.RTPROT_STATIC,
  206. },
  207. {
  208. Dst: &peers["a"].AllowedIPs[0],
  209. Flags: int(netlink.FLAG_ONLINK),
  210. Gw: nodes["b"].InternalIP.IP,
  211. LinkIndex: privIface,
  212. Protocol: unix.RTPROT_STATIC,
  213. },
  214. {
  215. Dst: &peers["a"].AllowedIPs[1],
  216. Flags: int(netlink.FLAG_ONLINK),
  217. Gw: nodes["b"].InternalIP.IP,
  218. LinkIndex: privIface,
  219. Protocol: unix.RTPROT_STATIC,
  220. },
  221. {
  222. Dst: &peers["b"].AllowedIPs[0],
  223. Flags: int(netlink.FLAG_ONLINK),
  224. Gw: nodes["b"].InternalIP.IP,
  225. LinkIndex: privIface,
  226. Protocol: unix.RTPROT_STATIC,
  227. },
  228. },
  229. },
  230. {
  231. name: "logical from d",
  232. topology: mustTopoForGranularityAndHost(LogicalGranularity, nodes["d"].Name),
  233. strategy: encapsulation.Never,
  234. routes: []*netlink.Route{
  235. {
  236. Dst: mustTopoForGranularityAndHost(LogicalGranularity, nodes["d"].Name).segments[0].cidrs[0],
  237. Flags: int(netlink.FLAG_ONLINK),
  238. Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["d"].Name).segments[0].wireGuardIP,
  239. LinkIndex: kiloIface,
  240. Protocol: unix.RTPROT_STATIC,
  241. },
  242. {
  243. Dst: oneAddressCIDR(nodes["a"].InternalIP.IP),
  244. Flags: int(netlink.FLAG_ONLINK),
  245. Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["d"].Name).segments[0].wireGuardIP,
  246. LinkIndex: kiloIface,
  247. Protocol: unix.RTPROT_STATIC,
  248. },
  249. {
  250. Dst: mustTopoForGranularityAndHost(LogicalGranularity, nodes["d"].Name).segments[1].cidrs[0],
  251. Flags: int(netlink.FLAG_ONLINK),
  252. Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["d"].Name).segments[1].wireGuardIP,
  253. LinkIndex: kiloIface,
  254. Protocol: unix.RTPROT_STATIC,
  255. },
  256. {
  257. Dst: oneAddressCIDR(nodes["b"].InternalIP.IP),
  258. Flags: int(netlink.FLAG_ONLINK),
  259. Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["d"].Name).segments[1].wireGuardIP,
  260. LinkIndex: kiloIface,
  261. Protocol: unix.RTPROT_STATIC,
  262. },
  263. {
  264. Dst: mustTopoForGranularityAndHost(LogicalGranularity, nodes["d"].Name).segments[1].cidrs[1],
  265. Flags: int(netlink.FLAG_ONLINK),
  266. Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["d"].Name).segments[1].wireGuardIP,
  267. LinkIndex: kiloIface,
  268. Protocol: unix.RTPROT_STATIC,
  269. },
  270. {
  271. Dst: oneAddressCIDR(nodes["c"].InternalIP.IP),
  272. Flags: int(netlink.FLAG_ONLINK),
  273. Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["d"].Name).segments[1].wireGuardIP,
  274. LinkIndex: kiloIface,
  275. Protocol: unix.RTPROT_STATIC,
  276. },
  277. {
  278. Dst: &nodes["b"].AllowedLocationIPs[0],
  279. Flags: int(netlink.FLAG_ONLINK),
  280. Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["d"].Name).segments[1].wireGuardIP,
  281. LinkIndex: kiloIface,
  282. Protocol: unix.RTPROT_STATIC,
  283. },
  284. {
  285. Dst: &peers["a"].AllowedIPs[0],
  286. LinkIndex: kiloIface,
  287. Protocol: unix.RTPROT_STATIC,
  288. },
  289. {
  290. Dst: &peers["a"].AllowedIPs[1],
  291. LinkIndex: kiloIface,
  292. Protocol: unix.RTPROT_STATIC,
  293. },
  294. {
  295. Dst: &peers["b"].AllowedIPs[0],
  296. LinkIndex: kiloIface,
  297. Protocol: unix.RTPROT_STATIC,
  298. },
  299. },
  300. },
  301. {
  302. name: "full from a",
  303. topology: mustTopoForGranularityAndHost(FullGranularity, nodes["a"].Name),
  304. strategy: encapsulation.Never,
  305. routes: []*netlink.Route{
  306. {
  307. Dst: mustTopoForGranularityAndHost(FullGranularity, nodes["a"].Name).segments[1].cidrs[0],
  308. Flags: int(netlink.FLAG_ONLINK),
  309. Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["a"].Name).segments[1].wireGuardIP,
  310. LinkIndex: kiloIface,
  311. Src: nodes["a"].InternalIP.IP,
  312. Protocol: unix.RTPROT_STATIC,
  313. },
  314. {
  315. Dst: oneAddressCIDR(nodes["b"].InternalIP.IP),
  316. Flags: int(netlink.FLAG_ONLINK),
  317. Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["a"].Name).segments[1].wireGuardIP,
  318. LinkIndex: kiloIface,
  319. Src: nodes["a"].InternalIP.IP,
  320. Protocol: unix.RTPROT_STATIC,
  321. },
  322. {
  323. Dst: &nodes["b"].AllowedLocationIPs[0],
  324. Flags: int(netlink.FLAG_ONLINK),
  325. Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["a"].Name).segments[1].wireGuardIP,
  326. LinkIndex: kiloIface,
  327. Src: nodes["a"].InternalIP.IP,
  328. Protocol: unix.RTPROT_STATIC,
  329. },
  330. {
  331. Dst: mustTopoForGranularityAndHost(FullGranularity, nodes["a"].Name).segments[2].cidrs[0],
  332. Flags: int(netlink.FLAG_ONLINK),
  333. Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["a"].Name).segments[2].wireGuardIP,
  334. LinkIndex: kiloIface,
  335. Src: nodes["a"].InternalIP.IP,
  336. Protocol: unix.RTPROT_STATIC,
  337. },
  338. {
  339. Dst: oneAddressCIDR(nodes["c"].InternalIP.IP),
  340. Flags: int(netlink.FLAG_ONLINK),
  341. Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["a"].Name).segments[2].wireGuardIP,
  342. LinkIndex: kiloIface,
  343. Src: nodes["a"].InternalIP.IP,
  344. Protocol: unix.RTPROT_STATIC,
  345. },
  346. {
  347. Dst: mustTopoForGranularityAndHost(FullGranularity, nodes["a"].Name).segments[3].cidrs[0],
  348. Flags: int(netlink.FLAG_ONLINK),
  349. Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["a"].Name).segments[3].wireGuardIP,
  350. LinkIndex: kiloIface,
  351. Src: nodes["a"].InternalIP.IP,
  352. Protocol: unix.RTPROT_STATIC,
  353. },
  354. {
  355. Dst: &peers["a"].AllowedIPs[0],
  356. LinkIndex: kiloIface,
  357. Src: nodes["a"].InternalIP.IP,
  358. Protocol: unix.RTPROT_STATIC,
  359. },
  360. {
  361. Dst: &peers["a"].AllowedIPs[1],
  362. LinkIndex: kiloIface,
  363. Src: nodes["a"].InternalIP.IP,
  364. Protocol: unix.RTPROT_STATIC,
  365. },
  366. {
  367. Dst: &peers["b"].AllowedIPs[0],
  368. LinkIndex: kiloIface,
  369. Src: nodes["a"].InternalIP.IP,
  370. Protocol: unix.RTPROT_STATIC,
  371. },
  372. },
  373. },
  374. {
  375. name: "full from b",
  376. topology: mustTopoForGranularityAndHost(FullGranularity, nodes["b"].Name),
  377. strategy: encapsulation.Never,
  378. routes: []*netlink.Route{
  379. {
  380. Dst: mustTopoForGranularityAndHost(FullGranularity, nodes["b"].Name).segments[0].cidrs[0],
  381. Flags: int(netlink.FLAG_ONLINK),
  382. Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["b"].Name).segments[0].wireGuardIP,
  383. LinkIndex: kiloIface,
  384. Src: nodes["b"].InternalIP.IP,
  385. Protocol: unix.RTPROT_STATIC,
  386. },
  387. {
  388. Dst: oneAddressCIDR(nodes["a"].InternalIP.IP),
  389. Flags: int(netlink.FLAG_ONLINK),
  390. Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["b"].Name).segments[0].wireGuardIP,
  391. LinkIndex: kiloIface,
  392. Src: nodes["b"].InternalIP.IP,
  393. Protocol: unix.RTPROT_STATIC,
  394. },
  395. {
  396. Dst: mustTopoForGranularityAndHost(FullGranularity, nodes["b"].Name).segments[2].cidrs[0],
  397. Flags: int(netlink.FLAG_ONLINK),
  398. Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["b"].Name).segments[2].wireGuardIP,
  399. LinkIndex: kiloIface,
  400. Src: nodes["b"].InternalIP.IP,
  401. Protocol: unix.RTPROT_STATIC,
  402. },
  403. {
  404. Dst: oneAddressCIDR(nodes["c"].InternalIP.IP),
  405. Flags: int(netlink.FLAG_ONLINK),
  406. Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["b"].Name).segments[2].wireGuardIP,
  407. LinkIndex: kiloIface,
  408. Src: nodes["b"].InternalIP.IP,
  409. Protocol: unix.RTPROT_STATIC,
  410. },
  411. {
  412. Dst: mustTopoForGranularityAndHost(FullGranularity, nodes["b"].Name).segments[3].cidrs[0],
  413. Flags: int(netlink.FLAG_ONLINK),
  414. Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["b"].Name).segments[3].wireGuardIP,
  415. LinkIndex: kiloIface,
  416. Src: nodes["b"].InternalIP.IP,
  417. Protocol: unix.RTPROT_STATIC,
  418. },
  419. {
  420. Dst: &peers["a"].AllowedIPs[0],
  421. LinkIndex: kiloIface,
  422. Src: nodes["b"].InternalIP.IP,
  423. Protocol: unix.RTPROT_STATIC,
  424. },
  425. {
  426. Dst: &peers["a"].AllowedIPs[1],
  427. LinkIndex: kiloIface,
  428. Src: nodes["b"].InternalIP.IP,
  429. Protocol: unix.RTPROT_STATIC,
  430. },
  431. {
  432. Dst: &peers["b"].AllowedIPs[0],
  433. LinkIndex: kiloIface,
  434. Src: nodes["b"].InternalIP.IP,
  435. Protocol: unix.RTPROT_STATIC,
  436. },
  437. },
  438. },
  439. {
  440. name: "full from c",
  441. topology: mustTopoForGranularityAndHost(FullGranularity, nodes["c"].Name),
  442. strategy: encapsulation.Never,
  443. routes: []*netlink.Route{
  444. {
  445. Dst: mustTopoForGranularityAndHost(FullGranularity, nodes["c"].Name).segments[0].cidrs[0],
  446. Flags: int(netlink.FLAG_ONLINK),
  447. Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["c"].Name).segments[0].wireGuardIP,
  448. LinkIndex: kiloIface,
  449. Src: nodes["c"].InternalIP.IP,
  450. Protocol: unix.RTPROT_STATIC,
  451. },
  452. {
  453. Dst: oneAddressCIDR(nodes["a"].InternalIP.IP),
  454. Flags: int(netlink.FLAG_ONLINK),
  455. Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["c"].Name).segments[0].wireGuardIP,
  456. LinkIndex: kiloIface,
  457. Src: nodes["c"].InternalIP.IP,
  458. Protocol: unix.RTPROT_STATIC,
  459. },
  460. {
  461. Dst: mustTopoForGranularityAndHost(FullGranularity, nodes["c"].Name).segments[1].cidrs[0],
  462. Flags: int(netlink.FLAG_ONLINK),
  463. Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["c"].Name).segments[1].wireGuardIP,
  464. LinkIndex: kiloIface,
  465. Src: nodes["c"].InternalIP.IP,
  466. Protocol: unix.RTPROT_STATIC,
  467. },
  468. {
  469. Dst: oneAddressCIDR(nodes["b"].InternalIP.IP),
  470. Flags: int(netlink.FLAG_ONLINK),
  471. Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["c"].Name).segments[1].wireGuardIP,
  472. LinkIndex: kiloIface,
  473. Src: nodes["c"].InternalIP.IP,
  474. Protocol: unix.RTPROT_STATIC,
  475. },
  476. {
  477. Dst: &nodes["b"].AllowedLocationIPs[0],
  478. Flags: int(netlink.FLAG_ONLINK),
  479. Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["c"].Name).segments[1].wireGuardIP,
  480. LinkIndex: kiloIface,
  481. Src: nodes["c"].InternalIP.IP,
  482. Protocol: unix.RTPROT_STATIC,
  483. },
  484. {
  485. Dst: mustTopoForGranularityAndHost(FullGranularity, nodes["c"].Name).segments[3].cidrs[0],
  486. Flags: int(netlink.FLAG_ONLINK),
  487. Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["c"].Name).segments[3].wireGuardIP,
  488. LinkIndex: kiloIface,
  489. Src: nodes["c"].InternalIP.IP,
  490. Protocol: unix.RTPROT_STATIC,
  491. },
  492. {
  493. Dst: &peers["a"].AllowedIPs[0],
  494. LinkIndex: kiloIface,
  495. Src: nodes["c"].InternalIP.IP,
  496. Protocol: unix.RTPROT_STATIC,
  497. },
  498. {
  499. Dst: &peers["a"].AllowedIPs[1],
  500. LinkIndex: kiloIface,
  501. Src: nodes["c"].InternalIP.IP,
  502. Protocol: unix.RTPROT_STATIC,
  503. },
  504. {
  505. Dst: &peers["b"].AllowedIPs[0],
  506. LinkIndex: kiloIface,
  507. Src: nodes["c"].InternalIP.IP,
  508. Protocol: unix.RTPROT_STATIC,
  509. },
  510. },
  511. },
  512. {
  513. name: "logical from a local",
  514. local: true,
  515. topology: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name),
  516. strategy: encapsulation.Never,
  517. routes: []*netlink.Route{
  518. {
  519. Dst: nodes["b"].Subnet,
  520. Flags: int(netlink.FLAG_ONLINK),
  521. Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).segments[1].wireGuardIP,
  522. LinkIndex: kiloIface,
  523. Src: nodes["a"].InternalIP.IP,
  524. Protocol: unix.RTPROT_STATIC,
  525. },
  526. {
  527. Dst: oneAddressCIDR(nodes["b"].InternalIP.IP),
  528. Flags: int(netlink.FLAG_ONLINK),
  529. Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).segments[1].wireGuardIP,
  530. LinkIndex: kiloIface,
  531. Src: nodes["a"].InternalIP.IP,
  532. Protocol: unix.RTPROT_STATIC,
  533. },
  534. {
  535. Dst: nodes["c"].Subnet,
  536. Flags: int(netlink.FLAG_ONLINK),
  537. Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).segments[1].wireGuardIP,
  538. LinkIndex: kiloIface,
  539. Src: nodes["a"].InternalIP.IP,
  540. Protocol: unix.RTPROT_STATIC,
  541. },
  542. {
  543. Dst: oneAddressCIDR(nodes["c"].InternalIP.IP),
  544. Flags: int(netlink.FLAG_ONLINK),
  545. Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).segments[1].wireGuardIP,
  546. LinkIndex: kiloIface,
  547. Src: nodes["a"].InternalIP.IP,
  548. Protocol: unix.RTPROT_STATIC,
  549. },
  550. {
  551. Dst: &nodes["b"].AllowedLocationIPs[0],
  552. Flags: int(netlink.FLAG_ONLINK),
  553. Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).segments[1].wireGuardIP,
  554. LinkIndex: kiloIface,
  555. Src: nodes["a"].InternalIP.IP,
  556. Protocol: unix.RTPROT_STATIC,
  557. },
  558. {
  559. Dst: nodes["d"].Subnet,
  560. Flags: int(netlink.FLAG_ONLINK),
  561. Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).segments[2].wireGuardIP,
  562. LinkIndex: kiloIface,
  563. Src: nodes["a"].InternalIP.IP,
  564. Protocol: unix.RTPROT_STATIC,
  565. },
  566. {
  567. Dst: &peers["a"].AllowedIPs[0],
  568. LinkIndex: kiloIface,
  569. Src: nodes["a"].InternalIP.IP,
  570. Protocol: unix.RTPROT_STATIC,
  571. },
  572. {
  573. Dst: &peers["a"].AllowedIPs[1],
  574. LinkIndex: kiloIface,
  575. Src: nodes["a"].InternalIP.IP,
  576. Protocol: unix.RTPROT_STATIC,
  577. },
  578. {
  579. Dst: &peers["b"].AllowedIPs[0],
  580. LinkIndex: kiloIface,
  581. Src: nodes["a"].InternalIP.IP,
  582. Protocol: unix.RTPROT_STATIC,
  583. },
  584. },
  585. },
  586. {
  587. name: "logical from a local always",
  588. local: true,
  589. topology: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name),
  590. strategy: encapsulation.Always,
  591. routes: []*netlink.Route{
  592. {
  593. Dst: nodes["b"].Subnet,
  594. Flags: int(netlink.FLAG_ONLINK),
  595. Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).segments[1].wireGuardIP,
  596. LinkIndex: kiloIface,
  597. Src: nodes["a"].InternalIP.IP,
  598. Protocol: unix.RTPROT_STATIC,
  599. },
  600. {
  601. Dst: oneAddressCIDR(nodes["b"].InternalIP.IP),
  602. Flags: int(netlink.FLAG_ONLINK),
  603. Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).segments[1].wireGuardIP,
  604. LinkIndex: kiloIface,
  605. Src: nodes["a"].InternalIP.IP,
  606. Protocol: unix.RTPROT_STATIC,
  607. },
  608. {
  609. Dst: nodes["c"].Subnet,
  610. Flags: int(netlink.FLAG_ONLINK),
  611. Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).segments[1].wireGuardIP,
  612. LinkIndex: kiloIface,
  613. Src: nodes["a"].InternalIP.IP,
  614. Protocol: unix.RTPROT_STATIC,
  615. },
  616. {
  617. Dst: oneAddressCIDR(nodes["c"].InternalIP.IP),
  618. Flags: int(netlink.FLAG_ONLINK),
  619. Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).segments[1].wireGuardIP,
  620. LinkIndex: kiloIface,
  621. Src: nodes["a"].InternalIP.IP,
  622. Protocol: unix.RTPROT_STATIC,
  623. },
  624. {
  625. Dst: &nodes["b"].AllowedLocationIPs[0],
  626. Flags: int(netlink.FLAG_ONLINK),
  627. Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).segments[1].wireGuardIP,
  628. LinkIndex: kiloIface,
  629. Src: nodes["a"].InternalIP.IP,
  630. Protocol: unix.RTPROT_STATIC,
  631. },
  632. {
  633. Dst: nodes["d"].Subnet,
  634. Flags: int(netlink.FLAG_ONLINK),
  635. Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["a"].Name).segments[2].wireGuardIP,
  636. LinkIndex: kiloIface,
  637. Src: nodes["a"].InternalIP.IP,
  638. Protocol: unix.RTPROT_STATIC,
  639. },
  640. {
  641. Dst: &peers["a"].AllowedIPs[0],
  642. LinkIndex: kiloIface,
  643. Src: nodes["a"].InternalIP.IP,
  644. Protocol: unix.RTPROT_STATIC,
  645. },
  646. {
  647. Dst: &peers["a"].AllowedIPs[1],
  648. LinkIndex: kiloIface,
  649. Src: nodes["a"].InternalIP.IP,
  650. Protocol: unix.RTPROT_STATIC,
  651. },
  652. {
  653. Dst: &peers["b"].AllowedIPs[0],
  654. LinkIndex: kiloIface,
  655. Src: nodes["a"].InternalIP.IP,
  656. Protocol: unix.RTPROT_STATIC,
  657. },
  658. },
  659. },
  660. {
  661. name: "logical from b local",
  662. local: true,
  663. topology: mustTopoForGranularityAndHost(LogicalGranularity, nodes["b"].Name),
  664. strategy: encapsulation.Never,
  665. routes: []*netlink.Route{
  666. {
  667. Dst: nodes["a"].Subnet,
  668. Flags: int(netlink.FLAG_ONLINK),
  669. Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["b"].Name).segments[0].wireGuardIP,
  670. LinkIndex: kiloIface,
  671. Src: nodes["b"].InternalIP.IP,
  672. Protocol: unix.RTPROT_STATIC,
  673. },
  674. {
  675. Dst: oneAddressCIDR(nodes["a"].InternalIP.IP),
  676. Flags: int(netlink.FLAG_ONLINK),
  677. Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["b"].Name).segments[0].wireGuardIP,
  678. LinkIndex: kiloIface,
  679. Src: nodes["b"].InternalIP.IP,
  680. Protocol: unix.RTPROT_STATIC,
  681. },
  682. {
  683. Dst: nodes["c"].Subnet,
  684. Flags: int(netlink.FLAG_ONLINK),
  685. Gw: nodes["c"].InternalIP.IP,
  686. LinkIndex: privIface,
  687. Protocol: unix.RTPROT_STATIC,
  688. },
  689. {
  690. Dst: nodes["d"].Subnet,
  691. Flags: int(netlink.FLAG_ONLINK),
  692. Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["b"].Name).segments[2].wireGuardIP,
  693. LinkIndex: kiloIface,
  694. Src: nodes["b"].InternalIP.IP,
  695. Protocol: unix.RTPROT_STATIC,
  696. },
  697. {
  698. Dst: &peers["a"].AllowedIPs[0],
  699. LinkIndex: kiloIface,
  700. Src: nodes["b"].InternalIP.IP,
  701. Protocol: unix.RTPROT_STATIC,
  702. },
  703. {
  704. Dst: &peers["a"].AllowedIPs[1],
  705. LinkIndex: kiloIface,
  706. Src: nodes["b"].InternalIP.IP,
  707. Protocol: unix.RTPROT_STATIC,
  708. },
  709. {
  710. Dst: &peers["b"].AllowedIPs[0],
  711. LinkIndex: kiloIface,
  712. Src: nodes["b"].InternalIP.IP,
  713. Protocol: unix.RTPROT_STATIC,
  714. },
  715. },
  716. },
  717. {
  718. name: "logical from b local always",
  719. local: true,
  720. topology: mustTopoForGranularityAndHost(LogicalGranularity, nodes["b"].Name),
  721. strategy: encapsulation.Always,
  722. routes: []*netlink.Route{
  723. {
  724. Dst: nodes["a"].Subnet,
  725. Flags: int(netlink.FLAG_ONLINK),
  726. Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["b"].Name).segments[0].wireGuardIP,
  727. LinkIndex: kiloIface,
  728. Src: nodes["b"].InternalIP.IP,
  729. Protocol: unix.RTPROT_STATIC,
  730. },
  731. {
  732. Dst: oneAddressCIDR(nodes["a"].InternalIP.IP),
  733. Flags: int(netlink.FLAG_ONLINK),
  734. Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["b"].Name).segments[0].wireGuardIP,
  735. LinkIndex: kiloIface,
  736. Src: nodes["b"].InternalIP.IP,
  737. Protocol: unix.RTPROT_STATIC,
  738. },
  739. {
  740. Dst: nodes["c"].Subnet,
  741. Flags: int(netlink.FLAG_ONLINK),
  742. Gw: nodes["c"].InternalIP.IP,
  743. LinkIndex: tunlIface,
  744. Src: nodes["b"].InternalIP.IP,
  745. Protocol: unix.RTPROT_STATIC,
  746. },
  747. {
  748. Dst: oneAddressCIDR(nodes["c"].InternalIP.IP),
  749. Flags: int(netlink.FLAG_ONLINK),
  750. Gw: nodes["c"].InternalIP.IP,
  751. LinkIndex: tunlIface,
  752. Src: nodes["b"].InternalIP.IP,
  753. Protocol: unix.RTPROT_STATIC,
  754. Table: kiloTableIndex,
  755. },
  756. {
  757. Dst: nodes["d"].Subnet,
  758. Flags: int(netlink.FLAG_ONLINK),
  759. Gw: mustTopoForGranularityAndHost(LogicalGranularity, nodes["b"].Name).segments[2].wireGuardIP,
  760. LinkIndex: kiloIface,
  761. Src: nodes["b"].InternalIP.IP,
  762. Protocol: unix.RTPROT_STATIC,
  763. },
  764. {
  765. Dst: &peers["a"].AllowedIPs[0],
  766. LinkIndex: kiloIface,
  767. Src: nodes["b"].InternalIP.IP,
  768. Protocol: unix.RTPROT_STATIC,
  769. },
  770. {
  771. Dst: &peers["a"].AllowedIPs[1],
  772. LinkIndex: kiloIface,
  773. Src: nodes["b"].InternalIP.IP,
  774. Protocol: unix.RTPROT_STATIC,
  775. },
  776. {
  777. Dst: &peers["b"].AllowedIPs[0],
  778. LinkIndex: kiloIface,
  779. Src: nodes["b"].InternalIP.IP,
  780. Protocol: unix.RTPROT_STATIC,
  781. },
  782. },
  783. rules: []*netlink.Rule{
  784. defaultRule(&netlink.Rule{
  785. Src: nodes["b"].Subnet,
  786. Dst: nodes["c"].InternalIP,
  787. Table: kiloTableIndex,
  788. }),
  789. defaultRule(&netlink.Rule{
  790. Dst: nodes["c"].InternalIP,
  791. IifName: DefaultKiloInterface,
  792. Table: kiloTableIndex,
  793. }),
  794. },
  795. },
  796. {
  797. name: "logical from c local",
  798. local: true,
  799. topology: mustTopoForGranularityAndHost(LogicalGranularity, nodes["c"].Name),
  800. strategy: encapsulation.Never,
  801. routes: []*netlink.Route{
  802. {
  803. Dst: oneAddressCIDR(mustTopoForGranularityAndHost(LogicalGranularity, nodes["c"].Name).segments[0].wireGuardIP),
  804. Flags: int(netlink.FLAG_ONLINK),
  805. Gw: nodes["b"].InternalIP.IP,
  806. LinkIndex: privIface,
  807. Protocol: unix.RTPROT_STATIC,
  808. },
  809. {
  810. Dst: nodes["a"].Subnet,
  811. Flags: int(netlink.FLAG_ONLINK),
  812. Gw: nodes["b"].InternalIP.IP,
  813. LinkIndex: privIface,
  814. Protocol: unix.RTPROT_STATIC,
  815. },
  816. {
  817. Dst: oneAddressCIDR(nodes["a"].InternalIP.IP),
  818. Flags: int(netlink.FLAG_ONLINK),
  819. Gw: nodes["b"].InternalIP.IP,
  820. LinkIndex: privIface,
  821. Protocol: unix.RTPROT_STATIC,
  822. },
  823. {
  824. Dst: oneAddressCIDR(mustTopoForGranularityAndHost(LogicalGranularity, nodes["c"].Name).segments[1].wireGuardIP),
  825. Flags: int(netlink.FLAG_ONLINK),
  826. Gw: nodes["b"].InternalIP.IP,
  827. LinkIndex: privIface,
  828. Protocol: unix.RTPROT_STATIC,
  829. },
  830. {
  831. Dst: nodes["b"].Subnet,
  832. Flags: int(netlink.FLAG_ONLINK),
  833. Gw: nodes["b"].InternalIP.IP,
  834. LinkIndex: privIface,
  835. Protocol: unix.RTPROT_STATIC,
  836. },
  837. {
  838. Dst: oneAddressCIDR(mustTopoForGranularityAndHost(LogicalGranularity, nodes["c"].Name).segments[2].wireGuardIP),
  839. Flags: int(netlink.FLAG_ONLINK),
  840. Gw: nodes["b"].InternalIP.IP,
  841. LinkIndex: privIface,
  842. Protocol: unix.RTPROT_STATIC,
  843. },
  844. {
  845. Dst: nodes["d"].Subnet,
  846. Flags: int(netlink.FLAG_ONLINK),
  847. Gw: nodes["b"].InternalIP.IP,
  848. LinkIndex: privIface,
  849. Protocol: unix.RTPROT_STATIC,
  850. },
  851. {
  852. Dst: &peers["a"].AllowedIPs[0],
  853. Flags: int(netlink.FLAG_ONLINK),
  854. Gw: nodes["b"].InternalIP.IP,
  855. LinkIndex: privIface,
  856. Protocol: unix.RTPROT_STATIC,
  857. },
  858. {
  859. Dst: &peers["a"].AllowedIPs[1],
  860. Flags: int(netlink.FLAG_ONLINK),
  861. Gw: nodes["b"].InternalIP.IP,
  862. LinkIndex: privIface,
  863. Protocol: unix.RTPROT_STATIC,
  864. },
  865. {
  866. Dst: &peers["b"].AllowedIPs[0],
  867. Flags: int(netlink.FLAG_ONLINK),
  868. Gw: nodes["b"].InternalIP.IP,
  869. LinkIndex: privIface,
  870. Protocol: unix.RTPROT_STATIC,
  871. },
  872. },
  873. },
  874. {
  875. name: "logical from c local always",
  876. local: true,
  877. topology: mustTopoForGranularityAndHost(LogicalGranularity, nodes["c"].Name),
  878. strategy: encapsulation.Always,
  879. routes: []*netlink.Route{
  880. {
  881. Dst: oneAddressCIDR(mustTopoForGranularityAndHost(LogicalGranularity, nodes["c"].Name).segments[0].wireGuardIP),
  882. Flags: int(netlink.FLAG_ONLINK),
  883. Gw: nodes["b"].InternalIP.IP,
  884. LinkIndex: tunlIface,
  885. Src: nodes["c"].InternalIP.IP,
  886. Protocol: unix.RTPROT_STATIC,
  887. },
  888. {
  889. Dst: nodes["a"].Subnet,
  890. Flags: int(netlink.FLAG_ONLINK),
  891. Gw: nodes["b"].InternalIP.IP,
  892. LinkIndex: tunlIface,
  893. Src: nodes["c"].InternalIP.IP,
  894. Protocol: unix.RTPROT_STATIC,
  895. },
  896. {
  897. Dst: oneAddressCIDR(nodes["a"].InternalIP.IP),
  898. Flags: int(netlink.FLAG_ONLINK),
  899. Gw: nodes["b"].InternalIP.IP,
  900. LinkIndex: tunlIface,
  901. Src: nodes["c"].InternalIP.IP,
  902. Protocol: unix.RTPROT_STATIC,
  903. },
  904. {
  905. Dst: oneAddressCIDR(mustTopoForGranularityAndHost(LogicalGranularity, nodes["c"].Name).segments[1].wireGuardIP),
  906. Flags: int(netlink.FLAG_ONLINK),
  907. Gw: nodes["b"].InternalIP.IP,
  908. LinkIndex: tunlIface,
  909. Src: nodes["c"].InternalIP.IP,
  910. Protocol: unix.RTPROT_STATIC,
  911. },
  912. {
  913. Dst: nodes["b"].Subnet,
  914. Flags: int(netlink.FLAG_ONLINK),
  915. Gw: nodes["b"].InternalIP.IP,
  916. LinkIndex: tunlIface,
  917. Src: nodes["c"].InternalIP.IP,
  918. Protocol: unix.RTPROT_STATIC,
  919. },
  920. {
  921. Dst: nodes["b"].InternalIP,
  922. Flags: int(netlink.FLAG_ONLINK),
  923. Gw: nodes["b"].InternalIP.IP,
  924. LinkIndex: tunlIface,
  925. Src: nodes["c"].InternalIP.IP,
  926. Protocol: unix.RTPROT_STATIC,
  927. Table: kiloTableIndex,
  928. },
  929. {
  930. Dst: oneAddressCIDR(mustTopoForGranularityAndHost(LogicalGranularity, nodes["c"].Name).segments[2].wireGuardIP),
  931. Flags: int(netlink.FLAG_ONLINK),
  932. Gw: nodes["b"].InternalIP.IP,
  933. LinkIndex: tunlIface,
  934. Src: nodes["c"].InternalIP.IP,
  935. Protocol: unix.RTPROT_STATIC,
  936. },
  937. {
  938. Dst: nodes["d"].Subnet,
  939. Flags: int(netlink.FLAG_ONLINK),
  940. Gw: nodes["b"].InternalIP.IP,
  941. LinkIndex: tunlIface,
  942. Src: nodes["c"].InternalIP.IP,
  943. Protocol: unix.RTPROT_STATIC,
  944. },
  945. {
  946. Dst: &peers["a"].AllowedIPs[0],
  947. Flags: int(netlink.FLAG_ONLINK),
  948. Gw: nodes["b"].InternalIP.IP,
  949. LinkIndex: tunlIface,
  950. Src: nodes["c"].InternalIP.IP,
  951. Protocol: unix.RTPROT_STATIC,
  952. },
  953. {
  954. Dst: &peers["a"].AllowedIPs[1],
  955. Flags: int(netlink.FLAG_ONLINK),
  956. Gw: nodes["b"].InternalIP.IP,
  957. LinkIndex: tunlIface,
  958. Src: nodes["c"].InternalIP.IP,
  959. Protocol: unix.RTPROT_STATIC,
  960. },
  961. {
  962. Dst: &peers["b"].AllowedIPs[0],
  963. Flags: int(netlink.FLAG_ONLINK),
  964. Gw: nodes["b"].InternalIP.IP,
  965. LinkIndex: tunlIface,
  966. Src: nodes["c"].InternalIP.IP,
  967. Protocol: unix.RTPROT_STATIC,
  968. },
  969. },
  970. rules: []*netlink.Rule{
  971. defaultRule(&netlink.Rule{
  972. Src: nodes["c"].Subnet,
  973. Dst: nodes["b"].InternalIP,
  974. Table: kiloTableIndex,
  975. }),
  976. },
  977. },
  978. {
  979. name: "full from a local",
  980. local: true,
  981. topology: mustTopoForGranularityAndHost(FullGranularity, nodes["a"].Name),
  982. strategy: encapsulation.Never,
  983. routes: []*netlink.Route{
  984. {
  985. Dst: nodes["b"].Subnet,
  986. Flags: int(netlink.FLAG_ONLINK),
  987. Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["a"].Name).segments[1].wireGuardIP,
  988. LinkIndex: kiloIface,
  989. Src: nodes["a"].InternalIP.IP,
  990. Protocol: unix.RTPROT_STATIC,
  991. },
  992. {
  993. Dst: oneAddressCIDR(nodes["b"].InternalIP.IP),
  994. Flags: int(netlink.FLAG_ONLINK),
  995. Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["a"].Name).segments[1].wireGuardIP,
  996. LinkIndex: kiloIface,
  997. Src: nodes["a"].InternalIP.IP,
  998. Protocol: unix.RTPROT_STATIC,
  999. },
  1000. {
  1001. Dst: &nodes["b"].AllowedLocationIPs[0],
  1002. Flags: int(netlink.FLAG_ONLINK),
  1003. Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["a"].Name).segments[1].wireGuardIP,
  1004. LinkIndex: kiloIface,
  1005. Src: nodes["a"].InternalIP.IP,
  1006. Protocol: unix.RTPROT_STATIC,
  1007. },
  1008. {
  1009. Dst: nodes["c"].Subnet,
  1010. Flags: int(netlink.FLAG_ONLINK),
  1011. Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["a"].Name).segments[2].wireGuardIP,
  1012. LinkIndex: kiloIface,
  1013. Src: nodes["a"].InternalIP.IP,
  1014. Protocol: unix.RTPROT_STATIC,
  1015. },
  1016. {
  1017. Dst: oneAddressCIDR(nodes["c"].InternalIP.IP),
  1018. Flags: int(netlink.FLAG_ONLINK),
  1019. Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["a"].Name).segments[2].wireGuardIP,
  1020. LinkIndex: kiloIface,
  1021. Src: nodes["a"].InternalIP.IP,
  1022. Protocol: unix.RTPROT_STATIC,
  1023. },
  1024. {
  1025. Dst: nodes["d"].Subnet,
  1026. Flags: int(netlink.FLAG_ONLINK),
  1027. Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["a"].Name).segments[3].wireGuardIP,
  1028. LinkIndex: kiloIface,
  1029. Src: nodes["a"].InternalIP.IP,
  1030. Protocol: unix.RTPROT_STATIC,
  1031. },
  1032. {
  1033. Dst: &peers["a"].AllowedIPs[0],
  1034. LinkIndex: kiloIface,
  1035. Src: nodes["a"].InternalIP.IP,
  1036. Protocol: unix.RTPROT_STATIC,
  1037. },
  1038. {
  1039. Dst: &peers["a"].AllowedIPs[1],
  1040. LinkIndex: kiloIface,
  1041. Src: nodes["a"].InternalIP.IP,
  1042. Protocol: unix.RTPROT_STATIC,
  1043. },
  1044. {
  1045. Dst: &peers["b"].AllowedIPs[0],
  1046. LinkIndex: kiloIface,
  1047. Src: nodes["a"].InternalIP.IP,
  1048. Protocol: unix.RTPROT_STATIC,
  1049. },
  1050. },
  1051. },
  1052. {
  1053. name: "full from b local",
  1054. local: true,
  1055. topology: mustTopoForGranularityAndHost(FullGranularity, nodes["b"].Name),
  1056. strategy: encapsulation.Never,
  1057. routes: []*netlink.Route{
  1058. {
  1059. Dst: nodes["a"].Subnet,
  1060. Flags: int(netlink.FLAG_ONLINK),
  1061. Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["b"].Name).segments[0].wireGuardIP,
  1062. LinkIndex: kiloIface,
  1063. Src: nodes["b"].InternalIP.IP,
  1064. Protocol: unix.RTPROT_STATIC,
  1065. },
  1066. {
  1067. Dst: oneAddressCIDR(nodes["a"].InternalIP.IP),
  1068. Flags: int(netlink.FLAG_ONLINK),
  1069. Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["b"].Name).segments[0].wireGuardIP,
  1070. LinkIndex: kiloIface,
  1071. Src: nodes["b"].InternalIP.IP,
  1072. Protocol: unix.RTPROT_STATIC,
  1073. },
  1074. {
  1075. Dst: nodes["c"].Subnet,
  1076. Flags: int(netlink.FLAG_ONLINK),
  1077. Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["b"].Name).segments[2].wireGuardIP,
  1078. LinkIndex: kiloIface,
  1079. Src: nodes["b"].InternalIP.IP,
  1080. Protocol: unix.RTPROT_STATIC,
  1081. },
  1082. {
  1083. Dst: oneAddressCIDR(nodes["c"].InternalIP.IP),
  1084. Flags: int(netlink.FLAG_ONLINK),
  1085. Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["b"].Name).segments[2].wireGuardIP,
  1086. LinkIndex: kiloIface,
  1087. Src: nodes["b"].InternalIP.IP,
  1088. Protocol: unix.RTPROT_STATIC,
  1089. },
  1090. {
  1091. Dst: nodes["d"].Subnet,
  1092. Flags: int(netlink.FLAG_ONLINK),
  1093. Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["b"].Name).segments[3].wireGuardIP,
  1094. LinkIndex: kiloIface,
  1095. Src: nodes["b"].InternalIP.IP,
  1096. Protocol: unix.RTPROT_STATIC,
  1097. },
  1098. {
  1099. Dst: &peers["a"].AllowedIPs[0],
  1100. LinkIndex: kiloIface,
  1101. Src: nodes["b"].InternalIP.IP,
  1102. Protocol: unix.RTPROT_STATIC,
  1103. },
  1104. {
  1105. Dst: &peers["a"].AllowedIPs[1],
  1106. LinkIndex: kiloIface,
  1107. Src: nodes["b"].InternalIP.IP,
  1108. Protocol: unix.RTPROT_STATIC,
  1109. },
  1110. {
  1111. Dst: &peers["b"].AllowedIPs[0],
  1112. LinkIndex: kiloIface,
  1113. Src: nodes["b"].InternalIP.IP,
  1114. Protocol: unix.RTPROT_STATIC,
  1115. },
  1116. },
  1117. },
  1118. {
  1119. name: "full from c local",
  1120. local: true,
  1121. topology: mustTopoForGranularityAndHost(FullGranularity, nodes["c"].Name),
  1122. strategy: encapsulation.Never,
  1123. routes: []*netlink.Route{
  1124. {
  1125. Dst: nodes["a"].Subnet,
  1126. Flags: int(netlink.FLAG_ONLINK),
  1127. Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["c"].Name).segments[0].wireGuardIP,
  1128. LinkIndex: kiloIface,
  1129. Src: nodes["c"].InternalIP.IP,
  1130. Protocol: unix.RTPROT_STATIC,
  1131. },
  1132. {
  1133. Dst: oneAddressCIDR(nodes["a"].InternalIP.IP),
  1134. Flags: int(netlink.FLAG_ONLINK),
  1135. Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["c"].Name).segments[0].wireGuardIP,
  1136. LinkIndex: kiloIface,
  1137. Src: nodes["c"].InternalIP.IP,
  1138. Protocol: unix.RTPROT_STATIC,
  1139. },
  1140. {
  1141. Dst: nodes["b"].Subnet,
  1142. Flags: int(netlink.FLAG_ONLINK),
  1143. Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["c"].Name).segments[1].wireGuardIP,
  1144. LinkIndex: kiloIface,
  1145. Src: nodes["c"].InternalIP.IP,
  1146. Protocol: unix.RTPROT_STATIC,
  1147. },
  1148. {
  1149. Dst: oneAddressCIDR(nodes["b"].InternalIP.IP),
  1150. Flags: int(netlink.FLAG_ONLINK),
  1151. Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["c"].Name).segments[1].wireGuardIP,
  1152. LinkIndex: kiloIface,
  1153. Src: nodes["c"].InternalIP.IP,
  1154. Protocol: unix.RTPROT_STATIC,
  1155. },
  1156. {
  1157. Dst: &nodes["b"].AllowedLocationIPs[0],
  1158. Flags: int(netlink.FLAG_ONLINK),
  1159. Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["c"].Name).segments[1].wireGuardIP,
  1160. LinkIndex: kiloIface,
  1161. Src: nodes["c"].InternalIP.IP,
  1162. Protocol: unix.RTPROT_STATIC,
  1163. },
  1164. {
  1165. Dst: nodes["d"].Subnet,
  1166. Flags: int(netlink.FLAG_ONLINK),
  1167. Gw: mustTopoForGranularityAndHost(FullGranularity, nodes["c"].Name).segments[3].wireGuardIP,
  1168. LinkIndex: kiloIface,
  1169. Src: nodes["c"].InternalIP.IP,
  1170. Protocol: unix.RTPROT_STATIC,
  1171. },
  1172. {
  1173. Dst: &peers["a"].AllowedIPs[0],
  1174. LinkIndex: kiloIface,
  1175. Src: nodes["c"].InternalIP.IP,
  1176. Protocol: unix.RTPROT_STATIC,
  1177. },
  1178. {
  1179. Dst: &peers["a"].AllowedIPs[1],
  1180. LinkIndex: kiloIface,
  1181. Src: nodes["c"].InternalIP.IP,
  1182. Protocol: unix.RTPROT_STATIC,
  1183. },
  1184. {
  1185. Dst: &peers["b"].AllowedIPs[0],
  1186. LinkIndex: kiloIface,
  1187. Src: nodes["c"].InternalIP.IP,
  1188. Protocol: unix.RTPROT_STATIC,
  1189. },
  1190. },
  1191. },
  1192. } {
  1193. routes, rules := tc.topology.Routes(DefaultKiloInterface, kiloIface, privIface, tunlIface, tc.local, encapsulation.NewIPIP(tc.strategy))
  1194. if diff := pretty.Compare(routes, tc.routes); diff != "" {
  1195. t.Errorf("test case %q: got diff: %v", tc.name, diff)
  1196. }
  1197. if diff := pretty.Compare(rules, tc.rules); diff != "" {
  1198. t.Errorf("test case %q: got diff: %v", tc.name, diff)
  1199. }
  1200. }
  1201. }