Advertisement
Guest User

Untitled

a guest
May 5th, 2022
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.78 KB | None | 0 0
  1. diff --git a/logic/gateway.go b/logic/gateway.go
  2. index 3bac3f92..018ff394 100644
  3. --- a/logic/gateway.go
  4. +++ b/logic/gateway.go
  5. @@ -17,7 +17,7 @@ func CreateEgressGateway(gateway models.EgressGatewayRequest) (models.Node, erro
  6. if err != nil {
  7. return models.Node{}, err
  8. }
  9. - if node.OS != "linux" { // add in darwin later
  10. + if node.OS != "linux" && node.OS != "freebsd" { // add in darwin later
  11. return models.Node{}, errors.New(node.OS + " is unsupported for egress gateways")
  12. }
  13. err = ValidateEgressGateway(gateway)
  14. @@ -26,8 +26,14 @@ func CreateEgressGateway(gateway models.EgressGatewayRequest) (models.Node, erro
  15. }
  16. node.IsEgressGateway = "yes"
  17. node.EgressGatewayRanges = gateway.Ranges
  18. - postUpCmd := "iptables -A FORWARD -i " + node.Interface + " -j ACCEPT; iptables -A FORWARD -o " + node.Interface + " -j ACCEPT; iptables -t nat -A POSTROUTING -o " + gateway.Interface + " -j MASQUERADE"
  19. - postDownCmd := "iptables -D FORWARD -i " + node.Interface + " -j ACCEPT; iptables -D FORWARD -o " + node.Interface + " -j ACCEPT; iptables -t nat -D POSTROUTING -o " + gateway.Interface + " -j MASQUERADE"
  20. + if node.OS == "linux" {
  21. + postUpCmd := "iptables -A FORWARD -i " + node.Interface + " -j ACCEPT; iptables -A FORWARD -o " + node.Interface + " -j ACCEPT; iptables -t nat -A POSTROUTING -o " + gateway.Interface + " -j MASQUERADE"
  22. + postDownCmd := "iptables -D FORWARD -i " + node.Interface + " -j ACCEPT; iptables -D FORWARD -o " + node.Interface + " -j ACCEPT; iptables -t nat -D POSTROUTING -o " + gateway.Interface + " -j MASQUERADE"
  23. + }
  24. + if node.OS == "freebsd" {
  25. + node.PostUp = "kldload ipfw ; ipfw add 65000 nat ip from any to any in recv " + gateway.Interface + " ; ipfw add 65000 allow ip from any to any via " + gateway.Interface + " ; ipfw add 65000 allow ip from any to any"
  26. + node.PostDown = "ipfw delete 65000 ; kldunload ipfw"
  27. + }
  28. if gateway.PostUp != "" {
  29. postUpCmd = gateway.PostUp
  30. }
  31. @@ -89,8 +95,14 @@ func DeleteEgressGateway(network, nodeid string) (models.Node, error) {
  32. node.PostUp = ""
  33. node.PostDown = ""
  34. if node.IsIngressGateway == "yes" { // check if node is still an ingress gateway before completely deleting postdown/up rules
  35. - node.PostUp = "iptables -A FORWARD -i " + node.Interface + " -j ACCEPT; iptables -A FORWARD -o " + node.Interface + " -j ACCEPT; iptables -t nat -A POSTROUTING -o " + node.Interface + " -j MASQUERADE"
  36. - node.PostDown = "iptables -D FORWARD -i " + node.Interface + " -j ACCEPT; iptables -D FORWARD -o " + node.Interface + " -j ACCEPT; iptables -t nat -D POSTROUTING -o " + node.Interface + " -j MASQUERADE"
  37. + if node.OS == "linux" {
  38. + node.PostUp = "iptables -A FORWARD -i " + node.Interface + " -j ACCEPT; iptables -A FORWARD -o " + node.Interface + " -j ACCEPT; iptables -t nat -A POSTROUTING -o " + node.Interface + " -j MASQUERADE"
  39. + node.PostDown = "iptables -D FORWARD -i " + node.Interface + " -j ACCEPT; iptables -D FORWARD -o " + node.Interface + " -j ACCEPT; iptables -t nat -D POSTROUTING -o " + node.Interface + " -j MASQUERADE"
  40. + }
  41. + if node.OS == "freebsd" {
  42. + node.PostUp = "kldload ipfw ; ipfw add 65000 nat ip from any to any in recv " + gateway.Interface + " ; ipfw add 65000 allow ip from any to any via " + gateway.Interface + " ; ipfw add 65000 allow ip from any to any"
  43. + node.PostDown = "ipfw delete 65000 ; kldunload ipfw"
  44. + }
  45. }
  46. node.SetLastModified()
  47.  
  48. @@ -111,7 +123,7 @@ func DeleteEgressGateway(network, nodeid string) (models.Node, error) {
  49. func CreateIngressGateway(netid string, nodeid string) (models.Node, error) {
  50.  
  51. node, err := GetNodeByID(nodeid)
  52. - if node.OS != "linux" { // add in darwin later
  53. + if node.OS != "linux" && node.OS != "freebsd" { // add in darwin later
  54. return models.Node{}, errors.New(node.OS + " is unsupported for ingress gateways")
  55. }
  56.  
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement