diff options
Diffstat (limited to 'pkg/server')
-rw-r--r-- | pkg/server/fsm.go | 14 | ||||
-rw-r--r-- | pkg/server/server.go | 24 | ||||
-rw-r--r-- | pkg/server/sockopt.go | 20 | ||||
-rw-r--r-- | pkg/server/sockopt_bsd.go | 8 | ||||
-rw-r--r-- | pkg/server/sockopt_linux.go | 36 | ||||
-rw-r--r-- | pkg/server/sockopt_linux_test.go | 2 | ||||
-rw-r--r-- | pkg/server/sockopt_openbsd.go | 28 |
7 files changed, 65 insertions, 67 deletions
diff --git a/pkg/server/fsm.go b/pkg/server/fsm.go index 8496d3b3..4830feb2 100644 --- a/pkg/server/fsm.go +++ b/pkg/server/fsm.go @@ -435,7 +435,7 @@ func (fsm *FSM) connectLoop() error { return } var conn net.Conn - d := TCPDialer{ + d := tcpDialer{ Dialer: net.Dialer{ LocalAddr: laddr, Timeout: time.Duration(MIN_CONNECT_RETRY-1) * time.Second, @@ -443,12 +443,12 @@ func (fsm *FSM) connectLoop() error { AuthPassword: fsm.pConf.Config.AuthPassword, } if fsm.pConf.TtlSecurity.Config.Enabled { - d.Ttl = 255 - d.TtlMin = fsm.pConf.TtlSecurity.Config.TtlMin + d.TTL = 255 + d.TTLMin = fsm.pConf.TtlSecurity.Config.TtlMin } else if fsm.pConf.Config.PeerAs != 0 && fsm.pConf.Config.PeerType == config.PEER_TYPE_EXTERNAL { - d.Ttl = 1 + d.TTL = 1 if fsm.pConf.EbgpMultihop.Config.Enabled { - d.Ttl = fsm.pConf.EbgpMultihop.Config.MultihopTtl + d.TTL = fsm.pConf.EbgpMultihop.Config.MultihopTtl } } conn, err = d.DialTCP(addr, port) @@ -634,7 +634,7 @@ func (h *FSMHandler) active() (bgp.FSMState, *FsmStateReason) { ttl = int(fsm.pConf.Transport.Config.Ttl) } if ttl != 0 { - if err := SetTcpTTLSockopt(conn.(*net.TCPConn), ttl); err != nil { + if err := setTCPTTLSockopt(conn.(*net.TCPConn), ttl); err != nil { log.WithFields(log.Fields{ "Topic": "Peer", "Key": fsm.pConf.Config.NeighborAddress, @@ -643,7 +643,7 @@ func (h *FSMHandler) active() (bgp.FSMState, *FsmStateReason) { } } if ttlMin != 0 { - if err := SetTcpMinTTLSockopt(conn.(*net.TCPConn), ttlMin); err != nil { + if err := setTCPMinTTLSockopt(conn.(*net.TCPConn), ttlMin); err != nil { log.WithFields(log.Fields{ "Topic": "Peer", "Key": fsm.pConf.Config.NeighborAddress, diff --git a/pkg/server/server.go b/pkg/server/server.go index e36ff26d..33c892aa 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -36,23 +36,21 @@ import ( "github.com/osrg/gobgp/pkg/packet/bgp" ) -type TCPListener struct { +type tcpListener struct { l *net.TCPListener ch chan struct{} } -func (l *TCPListener) Close() error { +func (l *tcpListener) Close() error { if err := l.l.Close(); err != nil { return err } - select { - case <-l.ch: - } + <-l.ch return nil } // avoid mapped IPv6 address -func NewTCPListener(address string, port uint32, ch chan *net.TCPConn) (*TCPListener, error) { +func newTCPListener(address string, port uint32, ch chan *net.TCPConn) (*tcpListener, error) { proto := "tcp4" if ip := net.ParseIP(address); ip == nil { return nil, fmt.Errorf("can't listen on %s", address) @@ -70,7 +68,7 @@ func NewTCPListener(address string, port uint32, ch chan *net.TCPConn) (*TCPList } // Note: Set TTL=255 for incoming connection listener in order to accept // connection in case for the neighbor has TTL Security settings. - if err := SetListenTcpTTLSockopt(l, 255); err != nil { + if err := setListenTCPTTLSockopt(l, 255); err != nil { log.WithFields(log.Fields{ "Topic": "Peer", "Key": addr, @@ -92,7 +90,7 @@ func NewTCPListener(address string, port uint32, ch chan *net.TCPConn) (*TCPList ch <- conn } }() - return &TCPListener{ + return &tcpListener{ l: l, ch: closeCh, }, nil @@ -106,7 +104,7 @@ type BgpServer struct { mgmtCh chan *mgmtOp policy *table.RoutingPolicy - listeners []*TCPListener + listeners []*tcpListener neighborMap map[string]*Peer peerGroupMap map[string]*PeerGroup globalRib *table.TableManager @@ -184,7 +182,7 @@ func (s *BgpServer) mgmtOperation(f func() error, checkActive bool) (err error) } func (server *BgpServer) Serve() { - server.listeners = make([]*TCPListener, 0, 2) + server.listeners = make([]*tcpListener, 0, 2) server.fsmincomingCh = channels.NewInfiniteChannel() server.fsmStateCh = make(chan *FsmMsg, 4096) @@ -1936,7 +1934,7 @@ func (s *BgpServer) StartBgp(ctx context.Context, r *api.StartBgpRequest) error if c.Config.Port > 0 { acceptCh := make(chan *net.TCPConn, 4096) for _, addr := range c.Config.LocalAddressList { - l, err := NewTCPListener(addr, uint32(c.Config.Port), acceptCh) + l, err := newTCPListener(addr, uint32(c.Config.Port), acceptCh) if err != nil { return err } @@ -2546,7 +2544,7 @@ func (server *BgpServer) addNeighbor(c *config.Neighbor) error { if server.bgpConfig.Global.Config.Port > 0 { for _, l := range server.Listeners(addr) { if c.Config.AuthPassword != "" { - if err := SetTcpMD5SigSockopt(l, addr, c.Config.AuthPassword); err != nil { + if err := setTCPMD5SigSockopt(l, addr, c.Config.AuthPassword); err != nil { log.WithFields(log.Fields{ "Topic": "Peer", "Key": addr, @@ -2644,7 +2642,7 @@ func (server *BgpServer) deleteNeighbor(c *config.Neighbor, code, subcode uint8) return fmt.Errorf("Can't delete a peer configuration for %s", addr) } for _, l := range server.Listeners(addr) { - if err := SetTcpMD5SigSockopt(l, addr, ""); err != nil { + if err := setTCPMD5SigSockopt(l, addr, ""); err != nil { log.WithFields(log.Fields{ "Topic": "Peer", "Key": addr, diff --git a/pkg/server/sockopt.go b/pkg/server/sockopt.go index e1c9c467..8061f41a 100644 --- a/pkg/server/sockopt.go +++ b/pkg/server/sockopt.go @@ -23,49 +23,49 @@ import ( log "github.com/sirupsen/logrus" ) -func SetTcpMD5SigSockopt(l *net.TCPListener, address string, key string) error { +func setTCPMD5SigSockopt(l *net.TCPListener, address string, key string) error { return setTcpMD5SigSockopt(l, address, key) } -func SetListenTcpTTLSockopt(l *net.TCPListener, ttl int) error { +func setListenTCPTTLSockopt(l *net.TCPListener, ttl int) error { return setListenTcpTTLSockopt(l, ttl) } -func SetTcpTTLSockopt(conn *net.TCPConn, ttl int) error { +func setTCPTTLSockopt(conn *net.TCPConn, ttl int) error { return setTcpTTLSockopt(conn, ttl) } -func SetTcpMinTTLSockopt(conn *net.TCPConn, ttl int) error { +func setTCPMinTTLSockopt(conn *net.TCPConn, ttl int) error { return setTcpMinTTLSockopt(conn, ttl) } -type TCPDialer struct { +type tcpDialer struct { net.Dialer // MD5 authentication password. AuthPassword string // The TTL value to set outgoing connection. - Ttl uint8 + TTL uint8 // The minimum TTL value for incoming packets. - TtlMin uint8 + TTLMin uint8 } -func (d *TCPDialer) DialTCP(addr string, port int) (*net.TCPConn, error) { +func (d *tcpDialer) DialTCP(addr string, port int) (*net.TCPConn, error) { if d.AuthPassword != "" { log.WithFields(log.Fields{ "Topic": "Peer", "Key": addr, }).Warn("setting md5 for active connection is not supported") } - if d.Ttl != 0 { + if d.TTL != 0 { log.WithFields(log.Fields{ "Topic": "Peer", "Key": addr, }).Warn("setting ttl for active connection is not supported") } - if d.TtlMin != 0 { + if d.TTLMin != 0 { log.WithFields(log.Fields{ "Topic": "Peer", "Key": addr, diff --git a/pkg/server/sockopt_bsd.go b/pkg/server/sockopt_bsd.go index 488a203e..fe7a6134 100644 --- a/pkg/server/sockopt_bsd.go +++ b/pkg/server/sockopt_bsd.go @@ -22,8 +22,8 @@ import ( ) const ( - TCP_MD5SIG = 0x10 // TCP MD5 Signature (RFC2385) - IPV6_MINHOPCOUNT = 73 // Generalized TTL Security Mechanism (RFC5082) + tcpMD5SIG = 0x10 // TCP MD5 Signature (RFC2385) + ipv6MinHopCount = 73 // Generalized TTL Security Mechanism (RFC5082) ) func setTcpMD5SigSockopt(l *net.TCPListener, address string, key string) error { @@ -32,7 +32,7 @@ func setTcpMD5SigSockopt(l *net.TCPListener, address string, key string) error { return err } // always enable and assumes that the configuration is done by setkey() - return setsockOptInt(sc, syscall.IPPROTO_TCP, TCP_MD5SIG, 1) + return setsockOptInt(sc, syscall.IPPROTO_TCP, tcpMD5SIG, 1) } func setListenTcpTTLSockopt(l *net.TCPListener, ttl int) error { @@ -63,7 +63,7 @@ func setTcpMinTTLSockopt(conn *net.TCPConn, ttl int) error { name := syscall.IP_MINTTL if family == syscall.AF_INET6 { level = syscall.IPPROTO_IPV6 - name = IPV6_MINHOPCOUNT + name = ipv6MinHopCount } return setsockOptInt(sc, level, name, ttl) } diff --git a/pkg/server/sockopt_linux.go b/pkg/server/sockopt_linux.go index 152e97de..ac2ecdb2 100644 --- a/pkg/server/sockopt_linux.go +++ b/pkg/server/sockopt_linux.go @@ -25,8 +25,8 @@ import ( ) const ( - TCP_MD5SIG = 14 // TCP MD5 Signature (RFC2385) - IPV6_MINHOPCOUNT = 73 // Generalized TTL Security Mechanism (RFC5082) + tcpMD5SIG = 14 // TCP MD5 Signature (RFC2385) + ipv6MinHopCount = 73 // Generalized TTL Security Mechanism (RFC5082) ) type tcpmd5sig struct { @@ -57,7 +57,7 @@ func buildTcpMD5Sig(address string, key string) (tcpmd5sig, error) { return t, nil } -func SetTcpMD5SigSockopt(l *net.TCPListener, address string, key string) error { +func setTCPMD5SigSockopt(l *net.TCPListener, address string, key string) error { t, err := buildTcpMD5Sig(address, key) if err != nil { return err @@ -68,10 +68,10 @@ func SetTcpMD5SigSockopt(l *net.TCPListener, address string, key string) error { if err != nil { return err } - return setsockOptString(sc, syscall.IPPROTO_TCP, TCP_MD5SIG, string(b[:])) + return setsockOptString(sc, syscall.IPPROTO_TCP, tcpMD5SIG, string(b[:])) } -func SetListenTcpTTLSockopt(l *net.TCPListener, ttl int) error { +func setListenTCPTTLSockopt(l *net.TCPListener, ttl int) error { family := extractFamilyFromTCPListener(l) sc, err := l.SyscallConn() if err != nil { @@ -80,7 +80,7 @@ func SetListenTcpTTLSockopt(l *net.TCPListener, ttl int) error { return setsockoptIpTtl(sc, family, ttl) } -func SetTcpTTLSockopt(conn *net.TCPConn, ttl int) error { +func setTCPTTLSockopt(conn *net.TCPConn, ttl int) error { family := extractFamilyFromTCPConn(conn) sc, err := conn.SyscallConn() if err != nil { @@ -89,7 +89,7 @@ func SetTcpTTLSockopt(conn *net.TCPConn, ttl int) error { return setsockoptIpTtl(sc, family, ttl) } -func SetTcpMinTTLSockopt(conn *net.TCPConn, ttl int) error { +func setTCPMinTTLSockopt(conn *net.TCPConn, ttl int) error { family := extractFamilyFromTCPConn(conn) sc, err := conn.SyscallConn() if err != nil { @@ -99,7 +99,7 @@ func SetTcpMinTTLSockopt(conn *net.TCPConn, ttl int) error { name := syscall.IP_MINTTL if family == syscall.AF_INET6 { level = syscall.IPPROTO_IPV6 - name = IPV6_MINHOPCOUNT + name = ipv6MinHopCount } return setsockOptInt(sc, level, name, ttl) } @@ -110,7 +110,7 @@ func setsockoptTcpMD5Sig(fd int, address string, key string) error { return err } b := *(*[unsafe.Sizeof(t)]byte)(unsafe.Pointer(&t)) - return os.NewSyscallError("setsockopt", syscall.SetsockoptString(fd, syscall.IPPROTO_TCP, TCP_MD5SIG, string(b[:]))) + return os.NewSyscallError("setsockopt", syscall.SetsockoptString(fd, syscall.IPPROTO_TCP, tcpMD5SIG, string(b[:]))) } func setsockoptIpTtl2(fd int, family int, value int) error { @@ -128,25 +128,25 @@ func setsockoptIpMinTtl(fd int, family int, value int) error { name := syscall.IP_MINTTL if family == syscall.AF_INET6 { level = syscall.IPPROTO_IPV6 - name = IPV6_MINHOPCOUNT + name = ipv6MinHopCount } return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(fd, level, name, value)) } -type TCPDialer struct { +type tcpDialer struct { net.Dialer // MD5 authentication password. AuthPassword string // The TTL value to set outgoing connection. - Ttl uint8 + TTL uint8 // The minimum TTL value for incoming packets. - TtlMin uint8 + TTLMin uint8 } -func (d *TCPDialer) DialTCP(addr string, port int) (*net.TCPConn, error) { +func (d *tcpDialer) DialTCP(addr string, port int) (*net.TCPConn, error) { var family int var ra, la syscall.Sockaddr @@ -214,14 +214,14 @@ func (d *TCPDialer) DialTCP(addr string, port int) (*net.TCPConn, error) { } } - if d.Ttl != 0 { - if err = setsockoptIpTtl2(fd, family, int(d.Ttl)); err != nil { + if d.TTL != 0 { + if err = setsockoptIpTtl2(fd, family, int(d.TTL)); err != nil { return nil, err } } - if d.TtlMin != 0 { - if err = setsockoptIpMinTtl(fd, family, int(d.Ttl)); err != nil { + if d.TTLMin != 0 { + if err = setsockoptIpMinTtl(fd, family, int(d.TTL)); err != nil { return nil, err } } diff --git a/pkg/server/sockopt_linux_test.go b/pkg/server/sockopt_linux_test.go index a08e7fc7..ca72a98f 100644 --- a/pkg/server/sockopt_linux_test.go +++ b/pkg/server/sockopt_linux_test.go @@ -88,7 +88,7 @@ func Test_DialTCP_FDleak(t *testing.T) { for i := 0; i < 10; i++ { laddr, _ := net.ResolveTCPAddr("tcp", net.JoinHostPort("127.0.0.1", "0")) - d := TCPDialer{ + d := tcpDialer{ Dialer: net.Dialer{ LocalAddr: laddr, Timeout: 1 * time.Second, diff --git a/pkg/server/sockopt_openbsd.go b/pkg/server/sockopt_openbsd.go index 4b7dc816..dcee33a2 100644 --- a/pkg/server/sockopt_openbsd.go +++ b/pkg/server/sockopt_openbsd.go @@ -348,12 +348,12 @@ func saDelete(address string) error { } const ( - TCP_MD5SIG = 0x4 // TCP MD5 Signature (RFC2385) - IPV6_MINHOPCOUNT = 73 // Generalized TTL Security Mechanism (RFC5082) + tcpMD5SIG = 0x4 // TCP MD5 Signature (RFC2385) + ipv6MinHopCount = 73 // Generalized TTL Security Mechanism (RFC5082) ) func setsockoptTcpMD5Sig(sc syscall.RawConn, address string, key string) error { - if err := setsockOptInt(sc, syscall.IPPROTO_TCP, TCP_MD5SIG, 1); err != nil { + if err := setsockOptInt(sc, syscall.IPPROTO_TCP, tcpMD5SIG, 1); err != nil { return err } if len(key) > 0 { @@ -362,7 +362,7 @@ func setsockoptTcpMD5Sig(sc syscall.RawConn, address string, key string) error { return saDelete(address) } -func SetTcpMD5SigSockopt(l *net.TCPListener, address string, key string) error { +func setTCPMD5SigSockopt(l *net.TCPListener, address string, key string) error { sc, err := l.SyscallConn() if err != nil { return err @@ -370,7 +370,7 @@ func SetTcpMD5SigSockopt(l *net.TCPListener, address string, key string) error { return setsockoptTcpMD5Sig(sc, address, key) } -func SetListenTcpTTLSockopt(l *net.TCPListener, ttl int) error { +func setListenTCPTTLSockopt(l *net.TCPListener, ttl int) error { family := extractFamilyFromTCPListener(l) sc, err := l.SyscallConn() if err != nil { @@ -379,7 +379,7 @@ func SetListenTcpTTLSockopt(l *net.TCPListener, ttl int) error { return setsockoptIpTtl(sc, family, ttl) } -func SetTcpTTLSockopt(conn *net.TCPConn, ttl int) error { +func setTCPTTLSockopt(conn *net.TCPConn, ttl int) error { family := extractFamilyFromTCPConn(conn) sc, err := conn.SyscallConn() if err != nil { @@ -388,7 +388,7 @@ func SetTcpTTLSockopt(conn *net.TCPConn, ttl int) error { return setsockoptIpTtl(sc, family, ttl) } -func SetTcpMinTTLSockopt(conn *net.TCPConn, ttl int) error { +func setTCPMinTTLSockopt(conn *net.TCPConn, ttl int) error { family := extractFamilyFromTCPConn(conn) sc, err := conn.SyscallConn() if err != nil { @@ -398,38 +398,38 @@ func SetTcpMinTTLSockopt(conn *net.TCPConn, ttl int) error { name := syscall.IP_MINTTL if family == syscall.AF_INET6 { level = syscall.IPPROTO_IPV6 - name = IPV6_MINHOPCOUNT + name = ipv6MinHopCount } return setsockOptInt(sc, level, name, ttl) } -type TCPDialer struct { +type tcpDialer struct { net.Dialer // MD5 authentication password. AuthPassword string // The TTL value to set outgoing connection. - Ttl uint8 + TTL uint8 // The minimum TTL value for incoming packets. - TtlMin uint8 + TTLMin uint8 } -func (d *TCPDialer) DialTCP(addr string, port int) (*net.TCPConn, error) { +func (d *tcpDialer) DialTCP(addr string, port int) (*net.TCPConn, error) { if d.AuthPassword != "" { log.WithFields(log.Fields{ "Topic": "Peer", "Key": addr, }).Warn("setting md5 for active connection is not supported") } - if d.Ttl != 0 { + if d.TTL != 0 { log.WithFields(log.Fields{ "Topic": "Peer", "Key": addr, }).Warn("setting ttl for active connection is not supported") } - if d.TtlMin != 0 { + if d.TTLMin != 0 { log.WithFields(log.Fields{ "Topic": "Peer", "Key": addr, |