Ref: zapi_nexthop_encode in lib/zclient.h of FRR7.3&FRR7.4&FRR7.5&FRR8
(version uint8, software Software, processFlag nexthopProcessFlag, message MessageFlag, apiFlag Flag)
| 2264 | |
| 2265 | // Ref: zapi_nexthop_encode in lib/zclient.h of FRR7.3&FRR7.4&FRR7.5&FRR8 |
| 2266 | func (n Nexthop) encode(version uint8, software Software, processFlag nexthopProcessFlag, message MessageFlag, apiFlag Flag) []byte { |
| 2267 | var buf []byte |
| 2268 | if processFlag&nexthopHasVrfID > 0 { |
| 2269 | tmpbuf := make([]byte, 4) |
| 2270 | binary.BigEndian.PutUint32(tmpbuf, n.VrfID) |
| 2271 | buf = append(buf, tmpbuf...) // frr: stream_putl(s, api_nh->vrf_id); |
| 2272 | } |
| 2273 | if processFlag&nexthopHasType > 0 { |
| 2274 | if n.Type == nexthopType(0) { |
| 2275 | n.Type = n.gateToType(version) |
| 2276 | } |
| 2277 | buf = append(buf, uint8(n.Type)) // frr: stream_putc(s, api_nh->type); |
| 2278 | } |
| 2279 | if processFlag&nexthopHasFlag > 0 { |
| 2280 | if n.LabelNum > 0 { |
| 2281 | n.flags |= zapiNexthopFlagLabel |
| 2282 | } |
| 2283 | if n.Weight > 0 { |
| 2284 | n.flags |= zapiNexthopFlagWeight |
| 2285 | } |
| 2286 | if n.backupNum > 0 { |
| 2287 | n.flags |= zapiNexthopFlagHasBackup |
| 2288 | } |
| 2289 | } |
| 2290 | if processFlag&nexthopHasFlag > 0 || processFlag&nexthopHasOnlink > 0 { |
| 2291 | // frr7.1, 7.2 has onlink, 7.3 has flag |
| 2292 | buf = append(buf, n.flags) // frr: stream_putc(s, nh_flags); |
| 2293 | } |
| 2294 | |
| 2295 | nhType := n.Type |
| 2296 | if processFlag&nexthopProcessIPToIPIFindex > 0 { |
| 2297 | nhType = nhType.ipToIPIFIndex() |
| 2298 | } |
| 2299 | if processFlag&nexthopProcessIFnameToIFindex > 0 { |
| 2300 | nhType = nhType.ifNameToIFIndex() |
| 2301 | } |
| 2302 | if nhType == nexthopTypeIPv4.toEach(version) || |
| 2303 | nhType == nexthopTypeIPv4IFIndex.toEach(version) { |
| 2304 | // frr: stream_put_in_addr(s, &api_nh->gate.ipv4); |
| 2305 | buf = append(buf, n.Gate.AsSlice()...) |
| 2306 | } else if nhType == nexthopTypeIPv6.toEach(version) || |
| 2307 | nhType == nexthopTypeIPv6IFIndex.toEach(version) { |
| 2308 | // frr: stream_write(s, (uint8_t *)&api_nh->gate.ipv6, 16); |
| 2309 | buf = append(buf, n.Gate.AsSlice()...) |
| 2310 | } |
| 2311 | if nhType == nexthopTypeIFIndex || |
| 2312 | nhType == nexthopTypeIPv4IFIndex.toEach(version) || |
| 2313 | nhType == nexthopTypeIPv6IFIndex.toEach(version) { |
| 2314 | tmpbuf := make([]byte, 4) |
| 2315 | binary.BigEndian.PutUint32(tmpbuf, n.Ifindex) |
| 2316 | buf = append(buf, tmpbuf...) // frr: stream_putl(s, api_nh->ifindex); |
| 2317 | } |
| 2318 | if nhType == nexthopTypeBlackhole.toEach(version) { // case NEXTHOP_TYPE_BLACKHOLE: |
| 2319 | // frr: stream_putc(s, api_nh->bh_type); |
| 2320 | buf = append(buf, n.blackholeType) |
| 2321 | } |
| 2322 | if n.flags&zapiNexthopFlagLabel > 0 || (message&MessageLabel > 0 && |
| 2323 | version == 5 || |
no test coverage detected