routes_test.go 36 KB

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