MCPcopy
hub / github.com/osrg/gobgp / UpdatePathAttrs

Function UpdatePathAttrs

internal/pkg/table/path.go:233–352  ·  view source on GitHub ↗
(logger *slog.Logger, global *oc.Global, info *PeerInfo, original *Path)

Source from the content-addressed store, hash-verified

231}
232
233func UpdatePathAttrs(logger *slog.Logger, global *oc.Global, info *PeerInfo, original *Path) *Path {
234 if info.RouteServerClient {
235 return original
236 }
237 path := original.Clone(original.IsWithdraw)
238
239 for _, a := range path.GetPathAttrs() {
240 if _, y := bgp.PathAttrFlags[a.GetType()]; !y {
241 if a.GetFlags()&bgp.BGP_ATTR_FLAG_TRANSITIVE == 0 {
242 path.delPathAttr(a.GetType())
243 }
244 } else {
245 switch a.GetType() {
246 case bgp.BGP_ATTR_TYPE_CLUSTER_LIST, bgp.BGP_ATTR_TYPE_ORIGINATOR_ID:
247 if info.PeerType != oc.PEER_TYPE_INTERNAL || !info.RouteReflectorClient {
248 // send these attributes to only rr clients
249 path.delPathAttr(a.GetType())
250 }
251 }
252 }
253 }
254
255 localAddress := info.LocalAddress
256 nexthop := path.GetNexthop()
257 switch info.PeerType {
258 case oc.PEER_TYPE_EXTERNAL:
259 // NEXTHOP handling
260 if !path.IsLocal() || nexthop.IsUnspecified() {
261 path.SetNexthop(localAddress)
262 }
263
264 // remove-private-as handling
265 path.RemovePrivateAS(info.LocalAS, info.RemovePrivateAs)
266
267 // AS_PATH handling
268 confed := global.IsConfederationMember(info.AS)
269 path.PrependAsn(info.LocalAS, 1, confed)
270 if !confed {
271 path.removeConfedAs()
272 }
273
274 // MED Handling
275 if med := path.getPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC); med != nil && !path.IsLocal() {
276 path.delPathAttr(bgp.BGP_ATTR_TYPE_MULTI_EXIT_DISC)
277 }
278 case oc.PEER_TYPE_INTERNAL:
279 // NEXTHOP handling for iBGP
280 // if the path generated locally set local address as nexthop.
281 // if not, don't modify it.
282 // TODO: NEXT-HOP-SELF support
283 if path.IsLocal() && nexthop.IsUnspecified() {
284 path.SetNexthop(localAddress)
285 }
286
287 // AS_PATH handling for iBGP
288 // if the path has AS_PATH path attribute, don't modify it.
289 // if not, attach *empty* AS_PATH path attribute.
290 if nh := path.getPathAttr(bgp.BGP_ATTR_TYPE_AS_PATH); nh == nil {

Calls 15

GetPathAttrsMethod · 0.80
delPathAttrMethod · 0.80
IsLocalMethod · 0.80
SetNexthopMethod · 0.80
RemovePrivateASMethod · 0.80
IsConfederationMemberMethod · 0.80
PrependAsnMethod · 0.80
removeConfedAsMethod · 0.80
getPathAttrMethod · 0.80

Used in the wild real call sites across dependent graphs

searching dependent graphs…