()
| 407 | } |
| 408 | |
| 409 | func (z *zebraClient) loop() { |
| 410 | w := z.server.watch([]WatchOption{ |
| 411 | WatchBestPath(true), |
| 412 | WatchPostUpdate(true, "", ""), |
| 413 | }...) |
| 414 | defer w.Stop() |
| 415 | |
| 416 | for { |
| 417 | select { |
| 418 | case <-z.dead: |
| 419 | return |
| 420 | case msg := <-z.client.Receive(): |
| 421 | if msg == nil { |
| 422 | break |
| 423 | } |
| 424 | switch body := msg.Body.(type) { |
| 425 | case *zebra.IPRouteBody: |
| 426 | if path := newPathFromIPRouteMessage(z.server.logger, msg, z.client.Version, z.client.Software); path != nil { |
| 427 | if err := z.server.addPathStream("", []*table.Path{path}); err != nil { |
| 428 | z.server.logger.Error("failed to add path from zebra", |
| 429 | slog.String("Topic", "Zebra"), |
| 430 | slog.Any("Path", path), |
| 431 | slog.String("Error", err.Error()), |
| 432 | ) |
| 433 | } |
| 434 | } |
| 435 | case *zebra.NexthopUpdateBody: |
| 436 | z.cacheLock.Lock() |
| 437 | updated := z.nexthopCache.updateByNexthopUpdate(body) |
| 438 | z.cacheLock.Unlock() |
| 439 | if !updated { |
| 440 | continue |
| 441 | } |
| 442 | paths := z.getPathListWithNexthopUpdate(body) |
| 443 | if len(paths) == 0 { |
| 444 | // If there is no path bound for the given nexthop, send |
| 445 | // NEXTHOP_UNREGISTER message. |
| 446 | z.cacheLock.Lock() |
| 447 | delete(z.nexthopCache, body.Prefix.Prefix) |
| 448 | z.cacheLock.Unlock() |
| 449 | err := z.client.SendNexthopRegister(msg.Header.VrfID, newNexthopUnregisterBody(uint16(body.Prefix.Family), body.Prefix.Prefix), true) |
| 450 | if err != nil { |
| 451 | z.server.logger.Error("failed to send nexthop unregister", |
| 452 | slog.String("Topic", "Zebra"), |
| 453 | slog.String("Error", err.Error()), |
| 454 | ) |
| 455 | } |
| 456 | continue |
| 457 | } |
| 458 | z.updatePathByNexthopCache(paths) |
| 459 | case *zebra.GetLabelChunkBody: |
| 460 | z.server.logger.Debug("zebra GetLabelChunkBody is received", |
| 461 | slog.String("Topic", "Zebra"), |
| 462 | slog.Int("Start", int(body.Start)), |
| 463 | slog.Int("End", int(body.End)), |
| 464 | ) |
| 465 | startEnd := uint64(body.Start)<<32 | uint64(body.End) |
| 466 | z.mplsLabel.maps[startEnd] = table.NewBitmap(int(body.End - body.Start + 1)) |
no test coverage detected