types.go 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. package dynamicrouting
  2. import (
  3. "encoding/json"
  4. "strconv"
  5. "strings"
  6. )
  7. // BGPInstance represents global BGP settings (/routing bgp instance)
  8. type BGPInstance struct {
  9. Enabled bool `json:"enabled"`
  10. AS uint32 `json:"as"`
  11. RouterID string `json:"router_id"`
  12. HoldTime int `json:"hold_time"` // Default 180
  13. KeepaliveTime int `json:"keepalive_time"` // Default 60
  14. RedistributeConnected bool `json:"redistribute_connected"`
  15. RedistributeStatic bool `json:"redistribute_static"`
  16. RedistributeOSPF bool `json:"redistribute_ospf"`
  17. Running bool `json:"running"`
  18. }
  19. // BGPPeer represents a BGP peer connection (/routing bgp connection / peer)
  20. type BGPPeer struct {
  21. ID string `json:"id"`
  22. Name string `json:"name"`
  23. Enabled bool `json:"enabled"`
  24. Comment string `json:"comment,omitempty"`
  25. Instance string `json:"instance,omitempty"`
  26. Template string `json:"template,omitempty"`
  27. LocalAS uint32 `json:"local_as,omitempty"` // Multi-Instance Local AS (if 0, uses global AS)
  28. RouterID string `json:"router_id,omitempty"`
  29. AFI string `json:"afi,omitempty"` // "ip", "ipv6"
  30. RemoteAddress string `json:"remote_address"`
  31. RemotePort int `json:"remote_port,omitempty"`
  32. RemoteAS uint32 `json:"remote_as"`
  33. RemoteAllowAS string `json:"remote_allow_as,omitempty"`
  34. LocalAddress string `json:"local_address,omitempty"`
  35. LocalPort int `json:"local_port,omitempty"`
  36. LocalRole string `json:"local_role,omitempty"` // ebgp, ibgp
  37. Password string `json:"password,omitempty"` // TCP MD5 Key
  38. Multihop bool `json:"multihop"`
  39. TxTTL int `json:"tx_ttl,omitempty"`
  40. RxMinTTL int `json:"rx_min_ttl,omitempty"`
  41. Connect bool `json:"connect"`
  42. Listen bool `json:"listen"`
  43. HoldTime int `json:"hold_time,omitempty"`
  44. KeepaliveTime int `json:"keepalive_time,omitempty"`
  45. UseBFD bool `json:"use_bfd,omitempty"`
  46. RoutingTable string `json:"routing_table,omitempty"`
  47. VRF string `json:"vrf,omitempty"`
  48. NoClientReflect bool `json:"no_client_reflect,omitempty"`
  49. RedistConnected bool `json:"redist_connected"`
  50. RedistStatic bool `json:"redist_static"`
  51. RedistOSPF bool `json:"redist_ospf"`
  52. RedistBGP bool `json:"redist_bgp"`
  53. RedistRIP bool `json:"redist_rip,omitempty"`
  54. RedistVPN bool `json:"redist_vpn,omitempty"`
  55. RedistDHCP bool `json:"redist_dhcp,omitempty"`
  56. RedistFantasy bool `json:"redist_fantasy,omitempty"`
  57. RedistModem bool `json:"redist_modem,omitempty"`
  58. RedistBgpMplsVpn bool `json:"redist_bgp_mpls_vpn,omitempty"`
  59. RedistSlaac bool `json:"redist_slaac,omitempty"`
  60. DefaultOriginate bool `json:"default_originate"`
  61. NetworkBlackhole bool `json:"network_blackhole,omitempty"`
  62. NoEarlyCut bool `json:"no_early_cut,omitempty"`
  63. KeepSentAttrs bool `json:"keep_sent_attrs,omitempty"`
  64. InputAffinity string `json:"input_affinity,omitempty"`
  65. OutputAffinity string `json:"output_affinity,omitempty"`
  66. NexthopChoice string `json:"nexthop_choice,omitempty"` // default, force-self
  67. NexthopSelf bool `json:"nexthop_self"`
  68. DefaultPrepend int `json:"default_prepend,omitempty"`
  69. AllowASIn int `json:"allow_as_in,omitempty"`
  70. RemovePrivateAS bool `json:"remove_private_as"`
  71. ASOverride bool `json:"as_override,omitempty"`
  72. IgnoreASPathLen bool `json:"ignore_as_path_len,omitempty"`
  73. InFilter string `json:"in_filter,omitempty"` // Routing Filter chain for incoming routes
  74. InAcceptNLRI string `json:"in_accept_nlri,omitempty"`
  75. InAcceptCommunities string `json:"in_accept_communities,omitempty"`
  76. InAcceptExtCommunities string `json:"in_accept_ext_communities,omitempty"`
  77. InAcceptLargeCommunities string `json:"in_accept_large_communities,omitempty"`
  78. InFilterCommunities string `json:"in_filter_communities,omitempty"`
  79. InFilterExtCommunities string `json:"in_filter_ext_communities,omitempty"`
  80. InFilterLargeCommunities string `json:"in_filter_large_communities,omitempty"`
  81. InFilterUnknown bool `json:"in_filter_unknown,omitempty"`
  82. OutFilter string `json:"out_filter,omitempty"` // Routing Filter chain for outgoing routes
  83. OutSelectionPolicy string `json:"out_selection_policy,omitempty"`
  84. OutputNetwork string `json:"output_network,omitempty"`
  85. OutputNetworks []string `json:"output_networks,omitempty"` // Dynamic [+] / [-] output networks
  86. Disabled bool `json:"disabled"`
  87. Passive bool `json:"passive"`
  88. // Runtime telemetry
  89. State string `json:"state,omitempty"` // Established, Active, Connect, Idle
  90. Uptime string `json:"uptime,omitempty"`
  91. PrefixReceived int `json:"prefix_received"`
  92. PrefixSent int `json:"prefix_sent"`
  93. }
  94. // BGPNetwork represents an advertised network (/routing bgp network)
  95. type BGPNetwork struct {
  96. ID string `json:"id"`
  97. Network string `json:"network"` // CIDR, e.g. 10.200.0.0/24
  98. Disabled bool `json:"disabled"`
  99. Comment string `json:"comment,omitempty"`
  100. }
  101. // BGPRoute represents an active BGP route
  102. type BGPRoute struct {
  103. Prefix string `json:"prefix"`
  104. NextHop string `json:"next_hop"`
  105. Metric int `json:"metric"`
  106. Weight int `json:"weight"`
  107. Path string `json:"path"`
  108. Origin string `json:"origin"`
  109. Best bool `json:"best"`
  110. }
  111. // OSPFInstance represents an OSPF instance (/routing ospf instance)
  112. type OSPFInstance struct {
  113. ID string `json:"id"`
  114. Name string `json:"name"` // Default "Default"
  115. Version int `json:"version"` // 2 or 3 (default 2)
  116. VRF string `json:"vrf"` // Default "main"
  117. RouterID string `json:"router_id"` // e.g. "10.42.62.254"
  118. RoutingTable string `json:"routing_table,omitempty"`// Default "main"
  119. Enabled bool `json:"enabled"`
  120. Disabled bool `json:"disabled"`
  121. Comment string `json:"comment,omitempty"`
  122. RedistributeConnected bool `json:"redistribute_connected"`
  123. RedistributeStatic bool `json:"redistribute_static"`
  124. RedistributeBGP bool `json:"redistribute_bgp"`
  125. RedistributeDefault bool `json:"redistribute_default"` // MikroTik redistribute-default
  126. OriginateDefault string `json:"originate_default,omitempty"` // "never", "if-installed", "always"
  127. DefaultMetric int `json:"default_metric"`
  128. Running bool `json:"running"`
  129. }
  130. // UnmarshalJSON supports both int (2, 3) and string ("2", "3", "ospfv2", "ospfv3") for Version.
  131. func (o *OSPFInstance) UnmarshalJSON(data []byte) error {
  132. type Alias OSPFInstance
  133. aux := struct {
  134. RawVersion interface{} `json:"version"`
  135. *Alias
  136. }{
  137. Alias: (*Alias)(o),
  138. }
  139. if err := json.Unmarshal(data, &aux); err != nil {
  140. return err
  141. }
  142. switch v := aux.RawVersion.(type) {
  143. case float64:
  144. o.Version = int(v)
  145. case int:
  146. o.Version = v
  147. case string:
  148. vStr := strings.ToLower(strings.TrimSpace(v))
  149. if strings.Contains(vStr, "3") || strings.Contains(vStr, "v3") || vStr == "ipv6" {
  150. o.Version = 3
  151. } else if strings.Contains(vStr, "2") || strings.Contains(vStr, "v2") || vStr == "ipv4" {
  152. o.Version = 2
  153. } else if parsed, err := strconv.Atoi(vStr); err == nil {
  154. o.Version = parsed
  155. }
  156. }
  157. if o.Version <= 0 {
  158. o.Version = 2
  159. }
  160. return nil
  161. }
  162. // OSPFArea represents an OSPF area (/routing ospf area)
  163. type OSPFArea struct {
  164. ID string `json:"id"`
  165. Name string `json:"name"` // Default "Default"
  166. Instance string `json:"instance,omitempty"` // Default "Default"
  167. AreaID string `json:"area_id"` // e.g. "0.0.0.0"
  168. AreaType string `json:"area_type"` // default, stub, nssa
  169. DefaultCost int `json:"default_cost,omitempty"`
  170. NoSummaries bool `json:"no_summaries,omitempty"`
  171. Disabled bool `json:"disabled"`
  172. Comment string `json:"comment,omitempty"`
  173. }
  174. // OSPFAreaRange represents an area range (/routing ospf area range)
  175. type OSPFAreaRange struct {
  176. ID string `json:"id"`
  177. Area string `json:"area"` // Area name or ID
  178. Prefix string `json:"prefix"` // CIDR e.g. "10.42.0.0/16"
  179. Cost int `json:"cost"`
  180. Advertise bool `json:"advertise"` // default true
  181. Disabled bool `json:"disabled"`
  182. Comment string `json:"comment,omitempty"`
  183. }
  184. // OSPFInterface represents an OSPF interface template (/routing ospf interface-template)
  185. type OSPFInterface struct {
  186. ID string `json:"id"`
  187. Interfaces string `json:"interfaces,omitempty"` // ether1, wlan1, all...
  188. Area string `json:"area"` // Area ID or name e.g. "Default" / "0.0.0.0"
  189. Networks string `json:"networks,omitempty"` // CIDR e.g. "10.42.36.244/30"
  190. NetworkType string `json:"network_type"` // broadcast, ptp, nbma, point-to-multipoint
  191. Cost int `json:"cost"` // Metric, default 1
  192. Priority int `json:"priority"` // Default 128
  193. HelloInterval int `json:"hello_interval"` // Default 10
  194. DeadInterval int `json:"dead_interval"` // Default 40
  195. Passive bool `json:"passive"`
  196. Auth string `json:"auth,omitempty"` // none, simple, md5
  197. AuthKey string `json:"auth_key,omitempty"`
  198. UseBFD bool `json:"use_bfd,omitempty"`
  199. Disabled bool `json:"disabled"`
  200. Comment string `json:"comment,omitempty"`
  201. // Backward compatibility aliases
  202. Network string `json:"network,omitempty"`
  203. Interface string `json:"interface,omitempty"`
  204. AuthType string `json:"auth_type,omitempty"`
  205. }
  206. // OSPFInterfaceLive represents dynamic live OSPF interface state (/routing ospf interface)
  207. type OSPFInterfaceLive struct {
  208. Flags string `json:"flags"` // "D" (dynamic)
  209. Interface string `json:"interface"` // e.g. "eth0"
  210. Address string `json:"address"` // e.g. "192.168.131.0/24"
  211. Area string `json:"area"` // e.g. "Default" or "0.0.0.0"
  212. InstanceID int `json:"instance_id"` // 0
  213. State string `json:"state"` // dr, backup, waiting, passive, ptp
  214. Cost int `json:"cost"`
  215. Priority int `json:"priority"`
  216. }
  217. // OSPFStaticNeighbor represents a static OSPF neighbor (/routing ospf static-neighbor)
  218. type OSPFStaticNeighbor struct {
  219. ID string `json:"id"`
  220. Address string `json:"address"`
  221. Area string `json:"area"`
  222. PollInterval int `json:"poll_interval"`
  223. Cost int `json:"cost"`
  224. Disabled bool `json:"disabled"`
  225. Comment string `json:"comment,omitempty"`
  226. }
  227. // OSPFNeighbor represents a live OSPF neighbor (/routing ospf neighbor)
  228. type OSPFNeighbor struct {
  229. Flags string `json:"flags"` // "D" (dynamic)
  230. Comment string `json:"comment,omitempty"`
  231. Instance string `json:"instance"` // "Default"
  232. Area string `json:"area"` // "Default"
  233. Address string `json:"address"` // "10.42.62.249"
  234. State string `json:"state"` // "Full"
  235. StateChanges int `json:"state_changes"` // e.g. 6
  236. NeighborID string `json:"neighbor_id,omitempty"`
  237. Interface string `json:"interface,omitempty"`
  238. DeadTimer string `json:"dead_timer,omitempty"`
  239. Priority int `json:"priority,omitempty"`
  240. }
  241. // OSPFLSA represents an LSA record in the Link-State Database (/routing ospf lsa)
  242. type OSPFLSA struct {
  243. Flags string `json:"flags"` // "D", "SD"
  244. Instance string `json:"instance"` // "Default"
  245. Area string `json:"area"` // "Default"
  246. Type string `json:"type"` // "router", "network", "as-external", "summary-net", "summary-asbr"
  247. Originator string `json:"originator"` // Router ID
  248. ID string `json:"id"` // LS ID
  249. Link string `json:"link"`
  250. LinkIndex int `json:"link_index"`
  251. Sequence string `json:"sequence"` // e.g. "8000006e"
  252. Age int `json:"age"` // seconds
  253. }
  254. // OSPFRoute represents an active OSPF route
  255. type OSPFRoute struct {
  256. Prefix string `json:"prefix"`
  257. RouteType string `json:"route_type"` // Intra-Area, Inter-Area, External
  258. Cost int `json:"cost"`
  259. Area string `json:"area"`
  260. NextHop string `json:"next_hop"`
  261. Interface string `json:"interface"`
  262. }
  263. // RoutingFilterRule represents a route filter rule (/routing filter rule)
  264. type RoutingFilterRule struct {
  265. ID string `json:"id"`
  266. Chain string `json:"chain"` // e.g. "bgp-in", "bgp-out", "isp-in"
  267. RuleOrder int `json:"rule_order"` // e.g. 10, 20, 30... Sequence number
  268. Rule string `json:"rule"` // RouterOS v7 rule script e.g. "if (dst in 10.0.0.0/8) { set bgp-local-pref 150; accept; }"
  269. Action string `json:"action"` // "accept" (permit), "discard" (deny), "reject", "passthrough"
  270. Prefix string `json:"prefix,omitempty"` // CIDR e.g. "10.0.0.0/8" or "0.0.0.0/0"
  271. PrefixLen string `json:"prefix_len,omitempty"` // e.g. "24-32", "ge 24 le 32", "24"
  272. MatchProtocol string `json:"match_protocol,omitempty"` // "any", "bgp", "ospf", "connected", "static"
  273. MatchASPath string `json:"match_as_path,omitempty"` // regex e.g. "^65000_"
  274. MatchCommunity string `json:"match_community,omitempty"`// e.g. "65001:100"
  275. SetLocalPref int `json:"set_local_pref,omitempty"` // BGP Local Preference
  276. SetMetric int `json:"set_metric,omitempty"` // BGP MED / OSPF Metric
  277. SetASPrepend int `json:"set_as_prepend,omitempty"` // AS Path prepend count
  278. SetCommunity string `json:"set_community,omitempty"` // Set BGP community
  279. SetNextHop string `json:"set_next_hop,omitempty"` // Custom Next Hop IP
  280. SetDistance int `json:"set_distance,omitempty"` // Administrative Distance
  281. Disabled bool `json:"disabled"`
  282. Comment string `json:"comment,omitempty"`
  283. }
  284. // RoutingFilterSelectRule represents a deprecated route selection rule (/routing filter select-rule)
  285. type RoutingFilterSelectRule struct {
  286. ID string `json:"id"`
  287. Chain string `json:"chain"`
  288. RuleOrder int `json:"rule_order"`
  289. Rule string `json:"rule"`
  290. Disabled bool `json:"disabled"`
  291. Comment string `json:"comment,omitempty"`
  292. }
  293. // RoutingFilterCommunityList represents a named community set (/routing filter community-list)
  294. type RoutingFilterCommunityList struct {
  295. ID string `json:"id"`
  296. Name string `json:"name"`
  297. Communities []string `json:"communities"`
  298. Regexp string `json:"regexp,omitempty"`
  299. Disabled bool `json:"disabled"`
  300. Comment string `json:"comment,omitempty"`
  301. }
  302. // RoutingFilterASList represents a named AS number list (/routing filter num-list)
  303. type RoutingFilterASList struct {
  304. ID string `json:"id"`
  305. Name string `json:"name"`
  306. Range string `json:"range"`
  307. Disabled bool `json:"disabled"`
  308. Comment string `json:"comment,omitempty"`
  309. }
  310. // RIPInstance represents a RIP routing instance (/routing rip instance)
  311. type RIPInstance struct {
  312. ID string `json:"id"`
  313. Name string `json:"name"` // e.g. "default"
  314. Version int `json:"version"` // 2 for IPv4, 1 for RIPng IPv6 (default 2)
  315. VRF string `json:"vrf,omitempty"` // default "main"
  316. RoutingTable string `json:"routing_table,omitempty"`// default "main"
  317. Enabled bool `json:"enabled"`
  318. Disabled bool `json:"disabled"`
  319. Comment string `json:"comment,omitempty"`
  320. RedistributeConnected bool `json:"redistribute_connected"`
  321. RedistributeStatic bool `json:"redistribute_static"`
  322. RedistributeOSPF bool `json:"redistribute_ospf"`
  323. RedistributeBGP bool `json:"redistribute_bgp"`
  324. RedistributeDefault bool `json:"redistribute_default"`
  325. DefaultMetric int `json:"default_metric"` // default 1
  326. UpdateTime int `json:"update_time"` // default 30
  327. TimeoutTime int `json:"timeout_time"` // default 180
  328. GarbageTime int `json:"garbage_time"` // default 120
  329. Running bool `json:"running"`
  330. }
  331. // UnmarshalJSON supports both int (2, 1) and string ("2", "1", "rip2", "ripng") for Version.
  332. func (r *RIPInstance) UnmarshalJSON(data []byte) error {
  333. type Alias RIPInstance
  334. aux := struct {
  335. RawVersion interface{} `json:"version"`
  336. *Alias
  337. }{
  338. Alias: (*Alias)(r),
  339. }
  340. if err := json.Unmarshal(data, &aux); err != nil {
  341. return err
  342. }
  343. switch v := aux.RawVersion.(type) {
  344. case float64:
  345. r.Version = int(v)
  346. case int:
  347. r.Version = v
  348. case string:
  349. vStr := strings.ToLower(strings.TrimSpace(v))
  350. if strings.Contains(vStr, "ng") || strings.Contains(vStr, "v1") || vStr == "1" || vStr == "ipv6" {
  351. r.Version = 1
  352. } else if strings.Contains(vStr, "2") || vStr == "ipv4" {
  353. r.Version = 2
  354. } else if parsed, err := strconv.Atoi(vStr); err == nil {
  355. r.Version = parsed
  356. }
  357. }
  358. if r.Version == 0 {
  359. r.Version = 2
  360. }
  361. return nil
  362. }
  363. // RIPInterface represents a RIP interface template (/routing rip interface)
  364. type RIPInterface struct {
  365. ID string `json:"id"`
  366. Instance string `json:"instance,omitempty"`
  367. Interface string `json:"interface"` // e.g. "eth0" or "*"
  368. Metric int `json:"metric"` // Metric/cost added (default 1)
  369. Mode string `json:"mode,omitempty"` // "multicast", "broadcast" (default multicast)
  370. Passive bool `json:"passive"`
  371. UseBFD bool `json:"use_bfd,omitempty"`
  372. Auth string `json:"auth,omitempty"` // "none", "simple", "md5"
  373. AuthKey string `json:"auth_key,omitempty"`
  374. Disabled bool `json:"disabled"`
  375. Comment string `json:"comment,omitempty"`
  376. }
  377. // RIPNeighbor represents an explicit RIP neighbor (/routing rip neighbor)
  378. type RIPNeighbor struct {
  379. ID string `json:"id"`
  380. Instance string `json:"instance,omitempty"`
  381. Address string `json:"address"` // Neighbor IP
  382. Interface string `json:"interface,omitempty"`
  383. Disabled bool `json:"disabled"`
  384. Comment string `json:"comment,omitempty"`
  385. }
  386. // RIPNeighborLive represents a live RIP neighbor detected by BIRD
  387. type RIPNeighborLive struct {
  388. Address string `json:"address"`
  389. Interface string `json:"interface"`
  390. Uptime string `json:"uptime"`
  391. LastSeen string `json:"last_seen"`
  392. }
  393. // RIPRoute represents an active RIP route learned or advertised
  394. type RIPRoute struct {
  395. Prefix string `json:"prefix"`
  396. NextHop string `json:"next_hop"`
  397. Metric int `json:"metric"`
  398. Interface string `json:"interface"`
  399. Uptime string `json:"uptime"`
  400. }
  401. // BFDInstance represents global BFD settings (/routing bfd instance)
  402. type BFDInstance struct {
  403. Enabled bool `json:"enabled"`
  404. Disabled bool `json:"disabled"`
  405. Comment string `json:"comment,omitempty"`
  406. Running bool `json:"running"`
  407. }
  408. // BFDInterface represents a BFD interface template (/routing bfd interface)
  409. type BFDInterface struct {
  410. ID string `json:"id"`
  411. Interface string `json:"interface"` // e.g. "eth0" or "*"
  412. MinRxInterval int `json:"min_rx_interval"` // ms, default 100
  413. MinTxInterval int `json:"min_tx_interval"` // ms, default 100
  414. IdleTxInterval int `json:"idle_tx_interval,omitempty"`// ms, default 1000
  415. Multiplier int `json:"multiplier"` // default 3
  416. Passive bool `json:"passive"`
  417. Auth string `json:"auth,omitempty"` // "none", "simple", "meticulous keyed sha1"
  418. AuthKey string `json:"auth_key,omitempty"`
  419. Disabled bool `json:"disabled"`
  420. Comment string `json:"comment,omitempty"`
  421. }
  422. // BFDNeighbor represents an explicit BFD neighbor / peer (/routing bfd peer)
  423. type BFDNeighbor struct {
  424. ID string `json:"id"`
  425. Address string `json:"address"`
  426. Interface string `json:"interface,omitempty"`
  427. LocalAddress string `json:"local_address,omitempty"`
  428. Multihop bool `json:"multihop"`
  429. Disabled bool `json:"disabled"`
  430. Comment string `json:"comment,omitempty"`
  431. }
  432. // BFDSession represents a live BFD session (/routing bfd session)
  433. type BFDSession struct {
  434. IP string `json:"ip"`
  435. Interface string `json:"interface"`
  436. State string `json:"state"` // "Up", "Down", "Init", "AdminDown"
  437. Since string `json:"since"`
  438. Interval string `json:"interval"`
  439. Timeout string `json:"timeout"`
  440. }
  441. // BabelInstance represents a Babel instance (/routing babel instance)
  442. type BabelInstance struct {
  443. ID string `json:"id"`
  444. Name string `json:"name"` // "default"
  445. RouterID string `json:"router_id,omitempty"`
  446. VRF string `json:"vrf,omitempty"`
  447. RoutingTable string `json:"routing_table,omitempty"`
  448. Enabled bool `json:"enabled"`
  449. Disabled bool `json:"disabled"`
  450. Comment string `json:"comment,omitempty"`
  451. RedistributeConnected bool `json:"redistribute_connected"`
  452. RedistributeStatic bool `json:"redistribute_static"`
  453. RedistributeOSPF bool `json:"redistribute_ospf"`
  454. RedistributeBGP bool `json:"redistribute_bgp"`
  455. RedistributeDefault bool `json:"redistribute_default"`
  456. DefaultMetric int `json:"default_metric"`
  457. Running bool `json:"running"`
  458. }
  459. // BabelInterface represents a Babel interface template (/routing babel interface)
  460. type BabelInterface struct {
  461. ID string `json:"id"`
  462. Instance string `json:"instance,omitempty"`
  463. Interface string `json:"interface"` // "eth0" or "*"
  464. Type string `json:"type,omitempty"` // "wired", "wireless" (default "wired")
  465. RxCost int `json:"rxcost,omitempty"` // default 10 or 96
  466. HelloInterval int `json:"hello_interval,omitempty"` // default 4 s
  467. UpdateInterval int `json:"update_interval,omitempty"` // default 16 s
  468. Auth string `json:"auth,omitempty"` // "none", "mac"
  469. AuthKey string `json:"auth_key,omitempty"`
  470. Disabled bool `json:"disabled"`
  471. Comment string `json:"comment,omitempty"`
  472. }
  473. // BabelNeighbor represents a live Babel neighbor (/routing babel neighbor)
  474. type BabelNeighbor struct {
  475. IP string `json:"ip"`
  476. Interface string `json:"interface"`
  477. Metric int `json:"metric"`
  478. Cost int `json:"cost,omitempty"`
  479. Routes int `json:"routes,omitempty"`
  480. Hellos int `json:"hellos,omitempty"`
  481. Uptime string `json:"uptime,omitempty"`
  482. Expires string `json:"expires,omitempty"`
  483. Auth string `json:"auth,omitempty"`
  484. RTT float64 `json:"rtt,omitempty"`
  485. }
  486. // BabelRoute represents an active Babel route (/routing babel route)
  487. type BabelRoute struct {
  488. Prefix string `json:"prefix"`
  489. NextHop string `json:"next_hop"`
  490. Metric int `json:"metric"`
  491. Interface string `json:"interface"`
  492. Flag string `json:"flag,omitempty"`
  493. Seqno int `json:"seqno,omitempty"`
  494. Expires string `json:"expires,omitempty"`
  495. }
  496. // BabelInterfaceLive represents a running Babel interface reported by BIRD (/routing babel interface)
  497. type BabelInterfaceLive struct {
  498. Instance string `json:"instance"`
  499. Interface string `json:"interface"`
  500. State string `json:"state"`
  501. Auth string `json:"auth"`
  502. RxCost int `json:"rxcost"`
  503. Neighbors int `json:"neighbors"`
  504. Timer string `json:"timer"`
  505. NextHopV4 string `json:"next_hop_v4"`
  506. NextHopV6 string `json:"next_hop_v6"`
  507. }
  508. // RAdvInstance represents an IPv6 Router Advertisement instance (/routing radv instance)
  509. type RAdvInstance struct {
  510. ID string `json:"id"`
  511. Name string `json:"name"` // "default"
  512. Enabled bool `json:"enabled"`
  513. Disabled bool `json:"disabled"`
  514. Comment string `json:"comment,omitempty"`
  515. Running bool `json:"running"`
  516. }
  517. // RAdvInterface represents a RAdv interface (/routing radv interface)
  518. type RAdvInterface struct {
  519. ID string `json:"id"`
  520. Instance string `json:"instance,omitempty"`
  521. Interface string `json:"interface"`
  522. MinRAInterval int `json:"min_ra_interval,omitempty"` // default 200 s
  523. MaxRAInterval int `json:"max_ra_interval,omitempty"` // default 600 s
  524. DefaultLifetime int `json:"default_lifetime,omitempty"` // default 1800 s
  525. HopLimit int `json:"hop_limit,omitempty"` // default 64
  526. Prefixes []string `json:"prefixes,omitempty"` // IPv6 prefixes e.g. ["2001:db8::/64"]
  527. RDNSS []string `json:"rdnss,omitempty"` // IPv6 DNS servers e.g. ["2001:4860:4860::8888"]
  528. Disabled bool `json:"disabled"`
  529. Comment string `json:"comment,omitempty"`
  530. }
  531. // DynamicRoutingSummary aggregates status for dashboard & badges
  532. type DynamicRoutingSummary struct {
  533. BGPEnabled bool `json:"bgp_enabled"`
  534. BGPRunning bool `json:"bgp_running"`
  535. BGPPeerCount int `json:"bgp_peer_count"`
  536. BGPEstablishedCount int `json:"bgp_established_count"`
  537. OSPFEnabled bool `json:"ospf_enabled"`
  538. OSPFRunning bool `json:"ospf_running"`
  539. OSPFNeighborCount int `json:"ospf_neighbor_count"`
  540. OSPFAdjacentCount int `json:"ospf_adjacent_count"`
  541. RIPEnabled bool `json:"rip_enabled"`
  542. RIPRunning bool `json:"rip_running"`
  543. RIPNeighborCount int `json:"rip_neighbor_count"`
  544. BFDEnabled bool `json:"bfd_enabled"`
  545. BFDRunning bool `json:"bfd_running"`
  546. BFDSessionCount int `json:"bfd_session_count"`
  547. BabelEnabled bool `json:"babel_enabled"`
  548. BabelRunning bool `json:"babel_running"`
  549. BabelNeighborCount int `json:"babel_neighbor_count"`
  550. RAdvEnabled bool `json:"radv_enabled"`
  551. RAdvRunning bool `json:"radv_running"`
  552. RoutingFilterCount int `json:"routing_filter_count"`
  553. }
  554. // DynamicConfig stores all dynamic routing data on disk
  555. type DynamicConfig struct {
  556. BGPInstance BGPInstance `json:"bgp_instance"`
  557. BGPPeers []BGPPeer `json:"bgp_peers"`
  558. BGPNetworks []BGPNetwork `json:"bgp_networks"`
  559. OSPFInstances []OSPFInstance `json:"ospf_instances"`
  560. OSPFInstance OSPFInstance `json:"ospf_instance"` // Backward compatibility
  561. OSPFAreas []OSPFArea `json:"ospf_areas"`
  562. OSPFAreaRanges []OSPFAreaRange `json:"ospf_area_ranges"`
  563. OSPFInterfaces []OSPFInterface `json:"ospf_interfaces"`
  564. OSPFStaticNbrs []OSPFStaticNeighbor `json:"ospf_static_nbrs"`
  565. RIPInstances []RIPInstance `json:"rip_instances"`
  566. RIPInterfaces []RIPInterface `json:"rip_interfaces"`
  567. RIPNeighbors []RIPNeighbor `json:"rip_neighbors"`
  568. BFDInstance BFDInstance `json:"bfd_instance"`
  569. BFDInterfaces []BFDInterface `json:"bfd_interfaces"`
  570. BFDNeighbors []BFDNeighbor `json:"bfd_neighbors"`
  571. BabelInstances []BabelInstance `json:"babel_instances"`
  572. BabelInterfaces []BabelInterface `json:"babel_interfaces"`
  573. RAdvInstances []RAdvInstance `json:"radv_instances"`
  574. RAdvInterfaces []RAdvInterface `json:"radv_interfaces"`
  575. RoutingFilters []RoutingFilterRule `json:"routing_filters"`
  576. RoutingSelectRules []RoutingFilterSelectRule `json:"routing_select_rules,omitempty"` // Deprecated: unused in BIRD 2
  577. RoutingCommunityLists []RoutingFilterCommunityList `json:"routing_community_lists"`
  578. RoutingASLists []RoutingFilterASList `json:"routing_as_lists"`
  579. }