| 59 | } |
| 60 | |
| 61 | func (m nexthopStateCache) applyToPathList(paths []*table.Path) []*table.Path { |
| 62 | updated := make([]*table.Path, 0, len(paths)) |
| 63 | for _, path := range paths { |
| 64 | if path == nil || path.IsWithdraw { |
| 65 | continue |
| 66 | } |
| 67 | metric, ok := m[path.GetNexthop()] |
| 68 | if !ok { |
| 69 | continue |
| 70 | } |
| 71 | isNexthopInvalid := metric == math.MaxUint32 |
| 72 | if isNexthopInvalid && path.IsNexthopInvalid { |
| 73 | // Path is already correctly marked as invalid; nothing to do. |
| 74 | continue |
| 75 | } |
| 76 | med, err := path.GetMed() |
| 77 | if !isNexthopInvalid && err == nil && med == metric && !path.IsNexthopInvalid { |
| 78 | // Path MED already reflects the current nexthop metric; nothing to do. |
| 79 | continue |
| 80 | } |
| 81 | newPath := path.Clone(false) |
| 82 | if isNexthopInvalid { |
| 83 | newPath.IsNexthopInvalid = true |
| 84 | } else { |
| 85 | newPath.IsNexthopInvalid = false |
| 86 | if err := newPath.SetMed(int64(metric), true); err != nil { |
| 87 | continue |
| 88 | } |
| 89 | } |
| 90 | updated = append(updated, newPath) |
| 91 | } |
| 92 | return updated |
| 93 | } |
| 94 | |
| 95 | func (m nexthopStateCache) updateByNexthopUpdate(body *zebra.NexthopUpdateBody) (updated bool) { |
| 96 | if len(body.Nexthops) == 0 { |