(logger *slog.Logger, global *oc.Global, info *PeerInfo, original *Path)
| 231 | } |
| 232 | |
| 233 | func 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 { |
searching dependent graphs…