summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--.travis.yml10
-rw-r--r--gobgpd/main.go76
-rw-r--r--gobgpd/util.go103
-rw-r--r--gobgpd/util_windows.go24
-rw-r--r--server/sockopt_bsd.go1
-rw-r--r--zebra/zapi_windows.go38
6 files changed, 180 insertions, 72 deletions
diff --git a/.travis.yml b/.travis.yml
index bd3c9dae..38aa9baa 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -34,6 +34,16 @@ matrix:
install: go get -t ./...
script: go test ./...
- go: 1.7
+ install: go get -t ./...
+ script: cd gobgpd && go build
+ env:
+ - GOOS=windows
+ - go: 1.7
+ install: go get -t ./...
+ script: cd gobgpd && go build
+ env:
+ - GOOS=freebsd
+ - go: 1.7
os: osx
before_install: true
install: go get -t ./...
diff --git a/gobgpd/main.go b/gobgpd/main.go
index 4ee76bd7..68afcb23 100644
--- a/gobgpd/main.go
+++ b/gobgpd/main.go
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2016 Nippon Telegraph and Telephone Corporation.
+// Copyright (C) 2014-2017 Nippon Telegraph and Telephone Corporation.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -17,7 +17,6 @@ package main
import (
log "github.com/Sirupsen/logrus"
- "github.com/Sirupsen/logrus/hooks/syslog"
"github.com/jessevdk/go-flags"
p "github.com/kr/pretty"
api "github.com/osrg/gobgp/api"
@@ -26,20 +25,17 @@ import (
"github.com/osrg/gobgp/server"
"github.com/osrg/gobgp/table"
"io/ioutil"
- "log/syslog"
"net/http"
_ "net/http/pprof"
"os"
"os/signal"
"runtime"
- "runtime/debug"
- "strings"
"syscall"
)
func main() {
sigCh := make(chan os.Signal, 1)
- signal.Notify(sigCh, syscall.SIGTERM, syscall.SIGUSR1)
+ signal.Notify(sigCh, syscall.SIGTERM)
var opts struct {
ConfigFile string `short:"f" long:"config-file" description:"specifying a config file"`
@@ -93,64 +89,8 @@ func main() {
}
if opts.UseSyslog != "" {
- dst := strings.SplitN(opts.UseSyslog, ":", 2)
- network := ""
- addr := ""
- if len(dst) == 2 {
- network = dst[0]
- addr = dst[1]
- }
-
- facility := syslog.Priority(0)
- switch opts.Facility {
- case "kern":
- facility = syslog.LOG_KERN
- case "user":
- facility = syslog.LOG_USER
- case "mail":
- facility = syslog.LOG_MAIL
- case "daemon":
- facility = syslog.LOG_DAEMON
- case "auth":
- facility = syslog.LOG_AUTH
- case "syslog":
- facility = syslog.LOG_SYSLOG
- case "lpr":
- facility = syslog.LOG_LPR
- case "news":
- facility = syslog.LOG_NEWS
- case "uucp":
- facility = syslog.LOG_UUCP
- case "cron":
- facility = syslog.LOG_CRON
- case "authpriv":
- facility = syslog.LOG_AUTHPRIV
- case "ftp":
- facility = syslog.LOG_FTP
- case "local0":
- facility = syslog.LOG_LOCAL0
- case "local1":
- facility = syslog.LOG_LOCAL1
- case "local2":
- facility = syslog.LOG_LOCAL2
- case "local3":
- facility = syslog.LOG_LOCAL3
- case "local4":
- facility = syslog.LOG_LOCAL4
- case "local5":
- facility = syslog.LOG_LOCAL5
- case "local6":
- facility = syslog.LOG_LOCAL6
- case "local7":
- facility = syslog.LOG_LOCAL7
- }
-
- hook, err := logrus_syslog.NewSyslogHook(network, addr, syslog.LOG_INFO|facility, "bgpd")
- if err != nil {
+ if err := addSyslogHook(opts.UseSyslog, opts.Facility); err != nil {
log.Error("Unable to connect to syslog daemon, ", opts.UseSyslog)
- os.Exit(1)
- } else {
- log.AddHook(hook)
}
}
@@ -312,14 +252,8 @@ func main() {
if updatePolicy {
bgpServer.SoftResetIn("", bgp.RouteFamily(0))
}
- case sig := <-sigCh:
- switch sig {
- case syscall.SIGKILL, syscall.SIGTERM:
- bgpServer.Shutdown()
- case syscall.SIGUSR1:
- runtime.GC()
- debug.FreeOSMemory()
- }
+ case <-sigCh:
+ bgpServer.Shutdown()
}
}
}
diff --git a/gobgpd/util.go b/gobgpd/util.go
new file mode 100644
index 00000000..577363d3
--- /dev/null
+++ b/gobgpd/util.go
@@ -0,0 +1,103 @@
+// Copyright (C) 2017 Nippon Telegraph and Telephone Corporation.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+// implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// +build !windows
+
+package main
+
+import (
+ "log/syslog"
+ "os"
+ "os/signal"
+ "runtime"
+ "runtime/debug"
+ "strings"
+ "syscall"
+
+ log "github.com/Sirupsen/logrus"
+ "github.com/Sirupsen/logrus/hooks/syslog"
+)
+
+func init() {
+ go func() {
+ sigCh := make(chan os.Signal, 1)
+ signal.Notify(sigCh, syscall.SIGUSR1)
+ for range sigCh {
+ runtime.GC()
+ debug.FreeOSMemory()
+ }
+ }()
+}
+
+func addSyslogHook(host, facility string) error {
+ dst := strings.SplitN(host, ":", 2)
+ network := ""
+ addr := ""
+ if len(dst) == 2 {
+ network = dst[0]
+ addr = dst[1]
+ }
+
+ priority := syslog.Priority(0)
+ switch facility {
+ case "kern":
+ priority = syslog.LOG_KERN
+ case "user":
+ priority = syslog.LOG_USER
+ case "mail":
+ priority = syslog.LOG_MAIL
+ case "daemon":
+ priority = syslog.LOG_DAEMON
+ case "auth":
+ priority = syslog.LOG_AUTH
+ case "syslog":
+ priority = syslog.LOG_SYSLOG
+ case "lpr":
+ priority = syslog.LOG_LPR
+ case "news":
+ priority = syslog.LOG_NEWS
+ case "uucp":
+ priority = syslog.LOG_UUCP
+ case "cron":
+ priority = syslog.LOG_CRON
+ case "authpriv":
+ priority = syslog.LOG_AUTHPRIV
+ case "ftp":
+ priority = syslog.LOG_FTP
+ case "local0":
+ priority = syslog.LOG_LOCAL0
+ case "local1":
+ priority = syslog.LOG_LOCAL1
+ case "local2":
+ priority = syslog.LOG_LOCAL2
+ case "local3":
+ priority = syslog.LOG_LOCAL3
+ case "local4":
+ priority = syslog.LOG_LOCAL4
+ case "local5":
+ priority = syslog.LOG_LOCAL5
+ case "local6":
+ priority = syslog.LOG_LOCAL6
+ case "local7":
+ priority = syslog.LOG_LOCAL7
+ }
+
+ hook, err := logrus_syslog.NewSyslogHook(network, addr, syslog.LOG_INFO|priority, "bgpd")
+ if err != nil {
+ return err
+ }
+ log.AddHook(hook)
+ return nil
+}
diff --git a/gobgpd/util_windows.go b/gobgpd/util_windows.go
new file mode 100644
index 00000000..56c5bc2f
--- /dev/null
+++ b/gobgpd/util_windows.go
@@ -0,0 +1,24 @@
+// Copyright (C) 2017 Nippon Telegraph and Telephone Corporation.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+// implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package main
+
+import (
+ "errors"
+)
+
+func addSyslogHook(_, _ string) error {
+ return errors.New("syslog is not supported on this OS")
+}
diff --git a/server/sockopt_bsd.go b/server/sockopt_bsd.go
index 8fac5165..62514edb 100644
--- a/server/sockopt_bsd.go
+++ b/server/sockopt_bsd.go
@@ -22,7 +22,6 @@ import (
"os"
"strings"
"syscall"
- "unsafe"
)
const (
diff --git a/zebra/zapi_windows.go b/zebra/zapi_windows.go
new file mode 100644
index 00000000..d55525db
--- /dev/null
+++ b/zebra/zapi_windows.go
@@ -0,0 +1,38 @@
+// Copyright (C) 2014, 2015 Nippon Telegraph and Telephone Corporation.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+// implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package zebra
+
+import (
+ "strings"
+ "syscall"
+)
+
+func intfflag2string(flag uint64) string {
+ ss := make([]string, 0, 10)
+ if flag&syscall.IFF_UP > 0 {
+ ss = append(ss, "UP")
+ }
+ if flag&syscall.IFF_BROADCAST > 0 {
+ ss = append(ss, "BROADCAST")
+ }
+ if flag&syscall.IFF_LOOPBACK > 0 {
+ ss = append(ss, "LOOPBACK")
+ }
+ if flag&syscall.IFF_MULTICAST > 0 {
+ ss = append(ss, "MULTICAST")
+ }
+ return strings.Join(ss, " | ")
+}