Skip to content

Commit

Permalink
more impls of util stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
ifd3f committed Apr 8, 2024
1 parent 1deb5e0 commit d4ff6d4
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 10 deletions.
24 changes: 24 additions & 0 deletions netconf/util-test.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@
'((set interfaces ethernet eth0 address dhcp)
(set interfaces ethernet eth0 hw-id "ab:cd:ef:gh:ij:kl")))

(check-equal?
(expand-command-tree
'(set interfaces ethernet eth0
[(address dhcp)
(hw-id "ab:cd:ef:gh:ij:kl")]))
'((set interfaces ethernet eth0 address dhcp)
(set interfaces ethernet eth0 hw-id "ab:cd:ef:gh:ij:kl")))

(check-equal?
(expand-command-tree
'(set policy route-map dn42-roa rule
Expand All @@ -38,6 +46,22 @@
(set policy route-map dn42-roa rule 30 action deny)
(set policy route-map dn42-roa rule 30 match rpki invalid)))

(check-equal?
(expand-command-tree
'(set policy route-map dn42-roa rule
[(10 (action permit)
(match rpki valid))
(20 (action permit)
(match rpki notfound))
(30 (action deny)
(match rpki invalid))]))
'((set policy route-map dn42-roa rule 10 action permit)
(set policy route-map dn42-roa rule 10 match rpki valid)
(set policy route-map dn42-roa rule 20 action permit)
(set policy route-map dn42-roa rule 20 match rpki notfound)
(set policy route-map dn42-roa rule 30 action deny)
(set policy route-map dn42-roa rule 30 match rpki invalid)))

(check-equal? (command->string '(set policy route-map dn42-roa rule 10 action permit))
"set policy route-map dn42-roa rule 10 action permit")
(check-equal? (command->string '(set interfaces ethernet eth0 hw-id "ab:cd:ef:gh:ij:kl"))
Expand Down
32 changes: 22 additions & 10 deletions netconf/util.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -82,22 +82,34 @@
public-key
endpoint))
(define-record-setter wireguard/peer)

(define (wireguard/peer:render-vyos r)
`(peer ,(wireguard/peer-name r) [(public-key (wireguard/peer-public-key r))
(allowed-ips "::/0")
(allowed-ips "0.0.0.0/0")
,@(match (wireguard/peer-endpoint r)
[(cons address port) `((address ,address) (port ,port))]
['() `()]
[_ (error "expected endpoint to be either nil or (cons address port)")])]))
`(peer ,(wireguard/peer-name r)
[(public-key (wireguard/peer-public-key r))
(allowed-ips "::/0")
(allowed-ips "0.0.0.0/0")
,@(match (wireguard/peer-endpoint r)
[(cons address port) `((address ,address) (port ,port))]
['() `()]
[_ (error "expected endpoint to be either nil or (cons address port)")])]))

(define-record-type bgp/link-local-peer
(link-ifname
(define-record-type bgp/link-local
(ifname
description
peer-address
peer-asn
peer-group))
(define-record-setter bgp/link-local-peer)
(define-record-setter bgp/link-local)

(define (bgp/link-local-peer:render-vyos r)
`[(delete protocols bgp neighbor (bgp/link-local-peer-address r))
(set protocols bgp neighbor ,(bgp/link-local-peer-address r)
[(description ,(bgp/link-local-description r))
(interface source-interface ,(bgp/link-local-ifname r))
(interface v6only)
(peer-group ,(bgp/link-local-ifname r))
(remote-as ,(bgp/link-local-peer-asn r))
(update-source ,(bgp/link-local-ifname r))])])

(define-record-type firewall/rule
(description
Expand Down

0 comments on commit d4ff6d4

Please sign in to comment.