Merge pull request #111316 from higebu/add-gobgpd

This commit is contained in:
Martin Weinelt 2021-04-09 17:17:07 +02:00 committed by GitHub
commit f882b057be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 173 additions and 0 deletions

View file

@ -680,6 +680,7 @@
./services/networking/gnunet.nix
./services/networking/go-neb.nix
./services/networking/go-shadowsocks2.nix
./services/networking/gobgpd.nix
./services/networking/gogoclient.nix
./services/networking/gvpe.nix
./services/networking/hans.nix

View file

@ -0,0 +1,64 @@
{ config, pkgs, lib, ... }:
with lib;
let
cfg = config.services.gobgpd;
format = pkgs.formats.toml { };
confFile = format.generate "gobgpd.conf" cfg.settings;
in {
options.services.gobgpd = {
enable = mkEnableOption "GoBGP Routing Daemon";
settings = mkOption {
type = format.type;
default = { };
description = ''
GoBGP configuration. Refer to
<link xlink:href="https://github.com/osrg/gobgp#documentation"/>
for details on supported values.
'';
example = literalExample ''
{
global = {
config = {
as = 64512;
router-id = "192.168.255.1";
};
};
neighbors = [
{
config = {
neighbor-address = "10.0.255.1";
peer-as = 65001;
};
}
{
config = {
neighbor-address = "10.0.255.2";
peer-as = 65002;
};
}
];
}
'';
};
};
config = mkIf cfg.enable {
environment.systemPackages = [ pkgs.gobgpd ];
systemd.services.gobgpd = {
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
description = "GoBGP Routing Daemon";
serviceConfig = {
Type = "notify";
ExecStartPre = "${pkgs.gobgpd}/bin/gobgpd -f ${confFile} -d";
ExecStart = "${pkgs.gobgpd}/bin/gobgpd -f ${confFile} --sdnotify";
ExecReload = "${pkgs.gobgpd}/bin/gobgpd -r";
DynamicUser = true;
AmbientCapabilities = "cap_net_bind_service";
};
};
};
}

View file

@ -138,6 +138,7 @@ in
gnome3 = handleTest ./gnome3.nix {};
gnome3-xorg = handleTest ./gnome3-xorg.nix {};
go-neb = handleTest ./go-neb.nix {};
gobgpd = handleTest ./gobgpd.nix {};
gocd-agent = handleTest ./gocd-agent.nix {};
gocd-server = handleTest ./gocd-server.nix {};
google-oslogin = handleTest ./google-oslogin {};

71
nixos/tests/gobgpd.nix Normal file
View file

@ -0,0 +1,71 @@
import ./make-test-python.nix ({ pkgs, ... }:
let
ifAddr = node: iface: (pkgs.lib.head node.config.networking.interfaces.${iface}.ipv4.addresses).address;
in {
name = "gobgpd";
meta = with pkgs.lib.maintainers; { maintainers = [ higebu ]; };
nodes = {
node1 = { nodes, ... }: {
environment.systemPackages = [ pkgs.gobgp ];
networking.firewall.allowedTCPPorts = [ 179 ];
services.gobgpd = {
enable = true;
settings = {
global = {
config = {
as = 64512;
router-id = "192.168.255.1";
};
};
neighbors = [{
config = {
neighbor-address = ifAddr nodes.node2 "eth1";
peer-as = 64513;
};
}];
};
};
};
node2 = { nodes, ... }: {
environment.systemPackages = [ pkgs.gobgp ];
networking.firewall.allowedTCPPorts = [ 179 ];
services.gobgpd = {
enable = true;
settings = {
global = {
config = {
as = 64513;
router-id = "192.168.255.2";
};
};
neighbors = [{
config = {
neighbor-address = ifAddr nodes.node1 "eth1";
peer-as = 64512;
};
}];
};
};
};
};
testScript = { nodes, ... }: let
addr1 = ifAddr nodes.node1 "eth1";
addr2 = ifAddr nodes.node2 "eth1";
in
''
start_all()
for node in node1, node2:
with subtest("should start gobgpd node"):
node.wait_for_unit("gobgpd.service")
with subtest("should open port 179"):
node.wait_for_open_port(179)
with subtest("should show neighbors by gobgp cli and BGP state should be ESTABLISHED"):
node1.wait_until_succeeds("gobgp neighbor ${addr2} | grep -q ESTABLISHED")
node2.wait_until_succeeds("gobgp neighbor ${addr1} | grep -q ESTABLISHED")
'';
})

View file

@ -0,0 +1,34 @@
{ buildGoModule, fetchFromGitHub, lib }:
buildGoModule rec {
pname = "gobgpd";
version = "2.26.0";
src = fetchFromGitHub {
owner = "osrg";
repo = "gobgp";
rev = "v${version}";
sha256 = "10fq74hv3vmcq58i3w67ic370925vl9wl6khcmy3f2vg60i962di";
};
vendorSha256 = "0dmd4r6x76jn8pyvp47x4llzc2wij5m9lchgyaagcb5sfdgbns9x";
postConfigure = ''
export CGO_ENABLED=0
'';
buildFlagsArray = ''
-ldflags=
-s -w -extldflags '-static'
'';
subPackages = [ "cmd/gobgpd" ];
meta = with lib; {
description = "BGP implemented in Go";
homepage = "https://osrg.github.io/gobgp/";
changelog = "https://github.com/osrg/gobgp/releases/tag/v${version}";
license = licenses.asl20;
maintainers = with maintainers; [ higebu ];
};
}

View file

@ -18413,6 +18413,8 @@ in
gobetween = callPackage ../servers/gobetween { };
gobgpd = callPackage ../servers/misc/gobgpd { };
graph-cli = callPackage ../tools/graphics/graph-cli { };
h2o = callPackage ../servers/http/h2o { };