(logger *slog.Logger, m *zebra.Message, version uint8, software zebra.Software)
| 291 | } |
| 292 | |
| 293 | func 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 | |
| 350 | type mplsLabelParameter struct { |
searching dependent graphs…