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

Function newPathFromIPRouteMessage

pkg/server/zclient.go:293–348  ·  view source on GitHub ↗
(logger *slog.Logger, m *zebra.Message, version uint8, software zebra.Software)

Source from the content-addressed store, hash-verified

291}
292
293func newPathFromIPRouteMessage(logger *slog.Logger, m *zebra.Message, version uint8, software zebra.Software) *table.Path {
294 header := m.Header
295 body := m.Body.(*zebra.IPRouteBody)
296 family := body.Family(logger, version, software)
297 isWithdraw := body.IsWithdraw(version, software)
298
299 var nlri bgp.NLRI
300 pattr := make([]bgp.PathAttributeInterface, 0)
301 origin := bgp.NewPathAttributeOrigin(bgp.BGP_ORIGIN_ATTR_TYPE_IGP)
302 pattr = append(pattr, origin)
303
304 logger.Debug("create path from ip route message",
305 slog.String("Topic", "Zebra"),
306 slog.String("RouteType", body.Type.String()),
307 slog.String("Flag", body.Flags.String(version, software)),
308 slog.Any("Message", body.Message),
309 slog.Int("Family", int(body.Prefix.Family)),
310 slog.String("Prefix", body.Prefix.Prefix.String()),
311 slog.Int("PrefixLength", int(body.Prefix.PrefixLen)),
312 slog.Any("Nexthop", body.Nexthops),
313 slog.Uint64("Metric", uint64(body.Metric)),
314 slog.Int("Distance", int(body.Distance)),
315 slog.Uint64("Mtu", uint64(body.Mtu)),
316 slog.String("api", header.Command.String()),
317 )
318
319 nlri, _ = bgp.NewIPAddrPrefix(netip.MustParsePrefix(fmt.Sprintf("%s/%d", body.Prefix.Prefix.String(), body.Prefix.PrefixLen)))
320 switch family {
321 case bgp.RF_IPv4_UC:
322 if len(body.Nexthops) > 0 {
323 pa, _ := bgp.NewPathAttributeNextHop(netip.MustParseAddr(body.Nexthops[0].Gate.String()))
324 pattr = append(pattr, pa)
325 }
326 case bgp.RF_IPv6_UC:
327 if len(body.Nexthops) > 0 {
328 nexthop, err := netip.ParseAddr(body.Nexthops[0].Gate.String())
329 if err == nil {
330 attr, _ := bgp.NewPathAttributeMpReachNLRI(family, []bgp.PathNLRI{{NLRI: nlri}}, nexthop)
331 pattr = append(pattr, attr)
332 }
333 }
334 default:
335 logger.Error("unsupport address family",
336 slog.String("Topic", "Zebra"),
337 slog.Int("Family", int(family)),
338 )
339 return nil
340 }
341
342 med := bgp.NewPathAttributeMultiExitDisc(body.Metric)
343 pattr = append(pattr, med)
344
345 path := table.NewPath(family, nil, bgp.PathNLRI{NLRI: nlri}, isWithdraw, pattr, time.Now(), false)
346 path.SetIsFromExternal(true)
347 return path
348}
349
350type mplsLabelParameter struct {

Callers 2

loopMethod · 0.85

Calls 11

SetIsFromExternalMethod · 0.95
NewPathAttributeOriginFunction · 0.92
NewIPAddrPrefixFunction · 0.92
NewPathAttributeNextHopFunction · 0.92
NewPathFunction · 0.92
FamilyMethod · 0.80
IsWithdrawMethod · 0.80
ErrorMethod · 0.80
StringMethod · 0.65

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…