summaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2016-08-03 04:27:33 +0000
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2017-04-04 22:07:46 +0900
commitbba54bdaa14c1a4c13245548757b38a89531fd9b (patch)
treeee8b87c207dc489d64f0a6e55c2bca0ede3f20bf /server
parent00f8406cb6a207341ea4f68a8fa294f31eb7bc7b (diff)
skip asn negotiation for BGP unnumbered peers
since BGP unnumbered peers are typically trusted, skip asn negotiation for easy configuration. from configuration file: ```toml [[neighbors]] [[neighbors.config]] neighbor-interface = "eth0" ``` from cli: ``` $ gobgp neighbor add interface eth0 ``` Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'server')
-rw-r--r--server/fsm.go24
-rw-r--r--server/peer.go2
-rw-r--r--server/server.go58
-rw-r--r--server/server_test.go4
4 files changed, 57 insertions, 31 deletions
diff --git a/server/fsm.go b/server/fsm.go
index e680f8ec..f623f399 100644
--- a/server/fsm.go
+++ b/server/fsm.go
@@ -474,9 +474,9 @@ func (h *FSMHandler) active() (bgp.FSMState, FsmStateReason) {
break
}
fsm.conn = conn
- if fsm.pConf.Config.PeerType == config.PEER_TYPE_EXTERNAL {
+ if fsm.pConf.Config.PeerAs != 0 && fsm.pConf.Config.PeerType == config.PEER_TYPE_EXTERNAL {
ttl := 1
- if fsm.pConf.EbgpMultihop.Config.Enabled == true {
+ if fsm.pConf.EbgpMultihop.Config.Enabled {
ttl = int(fsm.pConf.EbgpMultihop.Config.MultihopTtl)
}
if ttl != 0 {
@@ -844,11 +844,29 @@ func (h *FSMHandler) opensent() (bgp.FSMState, FsmStateReason) {
if m.Header.Type == bgp.BGP_MSG_OPEN {
fsm.recvOpen = m
body := m.Body.(*bgp.BGPOpen)
- err := bgp.ValidateOpenMsg(body, fsm.pConf.Config.PeerAs)
+ peerAs, err := bgp.ValidateOpenMsg(body, fsm.pConf.Config.PeerAs)
if err != nil {
fsm.sendNotificationFromErrorMsg(err.(*bgp.MessageError))
return bgp.BGP_FSM_IDLE, FSM_INVALID_MSG
}
+
+ // ASN negotiation was skipped
+ if fsm.pConf.Config.PeerAs == 0 {
+ typ := config.PEER_TYPE_EXTERNAL
+ if fsm.peerInfo.LocalAS == peerAs {
+ typ = config.PEER_TYPE_INTERNAL
+ }
+ fsm.pConf.State.PeerType = typ
+ log.WithFields(log.Fields{
+ "Topic": "Peer",
+ "Key": fsm.pConf.Config.NeighborAddress,
+ "State": fsm.state.String(),
+ }).Infof("skiped asn negotiation: peer-as: %d, peer-type: %s", peerAs, typ)
+ } else {
+ fsm.pConf.State.PeerType = fsm.pConf.Config.PeerType
+ }
+ fsm.pConf.State.PeerAs = peerAs
+ fsm.peerInfo.AS = peerAs
fsm.peerInfo.ID = body.ID
fsm.capMap, fsm.rfMap = open2Cap(body, fsm.pConf)
diff --git a/server/peer.go b/server/peer.go
index 96e014db..15029bd6 100644
--- a/server/peer.go
+++ b/server/peer.go
@@ -69,7 +69,7 @@ func (peer *Peer) TableID() string {
}
func (peer *Peer) isIBGPPeer() bool {
- return peer.fsm.pConf.Config.PeerAs == peer.fsm.gConf.Config.As
+ return peer.fsm.pConf.State.PeerAs == peer.fsm.gConf.Config.As
}
func (peer *Peer) isRouteServerClient() bool {
diff --git a/server/server.go b/server/server.go
index 8260e566..5238c33b 100644
--- a/server/server.go
+++ b/server/server.go
@@ -288,7 +288,7 @@ func sendFsmOutgoingMsg(peer *Peer, paths []*table.Path, notification *bgp.BGPMe
func isASLoop(peer *Peer, path *table.Path) bool {
for _, as := range path.GetAsList() {
- if as == peer.fsm.pConf.Config.PeerAs {
+ if as == peer.fsm.pConf.State.PeerAs {
return true
}
}
@@ -329,7 +329,7 @@ func filterpath(peer *Peer, path, old *table.Path) *table.Path {
ignore = true
info := path.GetSource()
//if the path comes from eBGP peer
- if info.AS != peer.fsm.pConf.Config.PeerAs {
+ if info.AS != peer.fsm.pConf.State.PeerAs {
ignore = false
}
// RFC4456 8. Avoiding Routing Information Loops
@@ -509,18 +509,19 @@ func createWatchEventPeerState(peer *Peer) *WatchEventPeerState {
sentOpen := buildopen(peer.fsm.gConf, peer.fsm.pConf)
recvOpen := peer.fsm.recvOpen
return &WatchEventPeerState{
- PeerAS: peer.fsm.peerInfo.AS,
- LocalAS: peer.fsm.peerInfo.LocalAS,
- PeerAddress: peer.fsm.peerInfo.Address,
- LocalAddress: net.ParseIP(laddr),
- PeerPort: rport,
- LocalPort: lport,
- PeerID: peer.fsm.peerInfo.ID,
- SentOpen: sentOpen,
- RecvOpen: recvOpen,
- State: peer.fsm.state,
- AdminState: peer.fsm.adminState,
- Timestamp: time.Now(),
+ PeerAS: peer.fsm.peerInfo.AS,
+ LocalAS: peer.fsm.peerInfo.LocalAS,
+ PeerAddress: peer.fsm.peerInfo.Address,
+ LocalAddress: net.ParseIP(laddr),
+ PeerPort: rport,
+ LocalPort: lport,
+ PeerID: peer.fsm.peerInfo.ID,
+ SentOpen: sentOpen,
+ RecvOpen: recvOpen,
+ State: peer.fsm.state,
+ AdminState: peer.fsm.adminState,
+ Timestamp: time.Now(),
+ PeerInterface: peer.fsm.pConf.Config.NeighborInterface,
}
}
@@ -687,6 +688,10 @@ func (server *BgpServer) handleFSMMessage(peer *Peer, e *FsmMsg) {
peer.prefixLimitWarned = make(map[bgp.RouteFamily]bool)
peer.DropAll(drop)
server.dropPeerAllRoutes(peer, drop)
+ if peer.fsm.pConf.Config.PeerAs == 0 {
+ peer.fsm.pConf.State.PeerAs = 0
+ peer.fsm.peerInfo.AS = 0
+ }
} else if peer.fsm.pConf.GracefulRestart.State.PeerRestarting && nextState == bgp.BGP_FSM_IDLE {
if peer.fsm.pConf.GracefulRestart.State.LongLivedEnabled {
llgr, no_llgr := peer.llgrFamilies()
@@ -2114,18 +2119,19 @@ type WatchEventUpdate struct {
}
type WatchEventPeerState struct {
- PeerAS uint32
- LocalAS uint32
- PeerAddress net.IP
- LocalAddress net.IP
- PeerPort uint16
- LocalPort uint16
- PeerID net.IP
- SentOpen *bgp.BGPMessage
- RecvOpen *bgp.BGPMessage
- State bgp.FSMState
- AdminState AdminState
- Timestamp time.Time
+ PeerAS uint32
+ LocalAS uint32
+ PeerAddress net.IP
+ LocalAddress net.IP
+ PeerPort uint16
+ LocalPort uint16
+ PeerID net.IP
+ SentOpen *bgp.BGPMessage
+ RecvOpen *bgp.BGPMessage
+ State bgp.FSMState
+ AdminState AdminState
+ Timestamp time.Time
+ PeerInterface string
}
type WatchEventAdjIn struct {
diff --git a/server/server_test.go b/server/server_test.go
index 3c343b9e..8f5fcc4d 100644
--- a/server/server_test.go
+++ b/server/server_test.go
@@ -185,9 +185,11 @@ func TestNumGoroutineWithAddDeleteNeighbor(t *testing.T) {
}
func newPeerandInfo(myAs, as uint32, address string, rib *table.TableManager) (*Peer, *table.PeerInfo) {
+ nConf := &config.Neighbor{Config: config.NeighborConfig{PeerAs: as, NeighborAddress: address}}
+ config.SetDefaultNeighborConfigValues(nConf, myAs)
p := NewPeer(
&config.Global{Config: config.GlobalConfig{As: myAs}},
- &config.Neighbor{Config: config.NeighborConfig{PeerAs: as, NeighborAddress: address}},
+ nConf,
rib,
&table.RoutingPolicy{})
for _, f := range rib.GetRFlist() {