Lines Matching +full:use +full:- +full:rtm
1 /*-
2 * SPDX-License-Identifier: BSD-3-Clause
7 * Redistribution and use in source and binary forms, with or without
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
126 switch (sa->sa_family) { in print_sockaddr_buf()
128 inet_ntop(AF_INET, &((struct sockaddr_in *)sa)->sin_addr, in print_sockaddr_buf()
132 inet_ntop(AF_INET6, &((struct sockaddr_in6 *)sa)->sin6_addr, in print_sockaddr_buf()
136 snprintf(buf, bufsize, "unknown:%d", sa->sa_family); in print_sockaddr_buf()
154 -width, name); in print_addr()
156 protrusion = strlen(addr) - width; in print_addr()
160 snprintf(buf, sizeof(buf), "{[:%d}{:%s/%%-.*s}{]:} ", in print_addr()
161 -width, name); in print_addr()
175 xo_emit("{T:/%-*.*s} {T:/%-*.*s} {T:/%-*.*s} {T:/%-*.*s} {T:/%*.*s} " in print_nhop_header()
176 "{T:/%*.*s} {T:/%-*.*s} {T:/%*.*s} {T:/%*.*s} {T:/%*.*s} {T:/%*s}\n", in print_nhop_header()
182 wid_pksent, wid_pksent, "Use", in print_nhop_header()
189 xo_emit("{T:/%-*.*s} {T:/%-*.*s} {T:/%-*.*s} {T:/%-*.*s} {T:/%*.*s} " in print_nhop_header()
203 if (idx >= map->size) { in nhop_map_update()
206 if (map->size == 0) in nhop_map_update()
209 new_size = map->size * 2; in nhop_map_update()
214 if ((map->ptr = realloc(map->ptr, sz)) == NULL) in nhop_map_update()
217 memset(&map->ptr[map->size], 0, (new_size - map->size) * sizeof(struct nhop_entry)); in nhop_map_update()
218 map->size = new_size; in nhop_map_update()
221 strlcpy(map->ptr[idx].ifname, ifname, sizeof(map->ptr[idx].ifname)); in nhop_map_update()
222 strlcpy(map->ptr[idx].gw, gw, sizeof(map->ptr[idx].gw)); in nhop_map_update()
229 if (idx >= map->size) in nhop_get()
231 if (*map->ptr[idx].ifname == '\0') in nhop_get()
233 return &map->ptr[idx]; in nhop_get()
237 print_nhop_entry_sysctl(const char *name, struct rt_msghdr *rtm, struct nhop_external *nh) in print_nhop_entry_sysctl() argument
248 snprintf(buffer, sizeof(buffer), "{[:-%d}{:index/%%lu}{]:} ", wid_nhidx); in print_nhop_entry_sysctl()
249 //xo_emit("{t:index/%-lu} ", wid_nhidx, nh->nh_idx); in print_nhop_entry_sysctl()
250 xo_emit(buffer, nh->nh_idx); in print_nhop_entry_sysctl()
253 char *cp = nh_types[nh->nh_type]; in print_nhop_entry_sysctl()
257 if (nh->ifindex < (uint32_t)ifmap_size) { in print_nhop_entry_sysctl()
258 strlcpy(iface_name, ifmap[nh->ifindex].ifname, in print_nhop_entry_sysctl()
261 strlcpy(iface_name, "---", sizeof(iface_name)); in print_nhop_entry_sysctl()
264 na = (struct nhop_addrs *)((char *)nh + nh->nh_len); in print_nhop_entry_sysctl()
265 //inet_ntop(nh->nh_family, &nh->nh_src, src_addr, sizeof(src_addr)); in print_nhop_entry_sysctl()
267 sa_gw = (struct sockaddr *)((char *)na + na->gw_sa_off); in print_nhop_entry_sysctl()
268 sa_ifa = (struct sockaddr *)((char *)na + na->src_sa_off); in print_nhop_entry_sysctl()
271 if (nh->nh_flags & NHF_GATEWAY) { in print_nhop_entry_sysctl()
277 protrusion = print_addr("gateway", gw_addr, wid_dst - protrusion); in print_nhop_entry_sysctl()
279 nhop_map_update(&global_nhop_map, nh->nh_idx, gw_addr, iface_name); in print_nhop_entry_sysctl()
281 snprintf(buffer, sizeof(buffer), "{[:-%d}{:flags/%%s}{]:} ", in print_nhop_entry_sysctl()
282 wid_flags - protrusion); in print_nhop_entry_sysctl()
284 //p_nhflags(nh->nh_flags, buffer); in print_nhop_entry_sysctl()
285 print_flags_generic(rtm->rtm_flags, rt_bits, buffer, "rt_flags_pretty"); in print_nhop_entry_sysctl()
288 xo_emit("{t:use/%*lu} ", wid_pksent, nh->nh_pksent); in print_nhop_entry_sysctl()
289 xo_emit("{t:mtu/%*lu} ", wid_mtu, nh->nh_mtu); in print_nhop_entry_sysctl()
294 xo_emit("{t:interface-name/%*s}", wid_if, iface_name); in print_nhop_entry_sysctl()
296 xo_emit("{t:interface-name/%*.*s}", wid_if, wid_if, iface_name); in print_nhop_entry_sysctl()
299 if (nh->aifindex < (uint32_t)ifmap_size && nh->ifindex != nh->aifindex) { in print_nhop_entry_sysctl()
300 strlcpy(iface_name, ifmap[nh->aifindex].ifname, in print_nhop_entry_sysctl()
303 strlcpy(iface_name, "---", sizeof(iface_name)); in print_nhop_entry_sysctl()
306 xo_emit("{t:address-interface-name/%*s}", wid_if, iface_name); in print_nhop_entry_sysctl()
308 xo_emit("{t:refcount/%*lu} ", wid_refcnt, nh->nh_refcount); in print_nhop_entry_sysctl()
309 if (Wflag && nh->prepend_len) { in print_nhop_entry_sysctl()
310 int max_bytes = MIN(nh->prepend_len, sizeof(buffer) / 2 - 1); in print_nhop_entry_sysctl()
312 snprintf(&buffer[i * 2], 3, "%02X", nh->nh_prepend[i]); in print_nhop_entry_sysctl()
313 xo_emit(" {:nhop-prepend/%*s}", wid_prepend, buffer); in print_nhop_entry_sysctl()
328 if (a->idx > b->idx) in cmp_nh_idx()
330 else if (a->idx < b->idx) in cmp_nh_idx()
331 return (-1); in cmp_nh_idx()
341 struct rt_msghdr *rtm; in dump_nhops_sysctl() local
369 for (next = buf; next < lim; next += rtm->rtm_msglen) { in dump_nhops_sysctl()
370 rtm = (struct rt_msghdr *)next; in dump_nhops_sysctl()
371 if (rtm->rtm_version != RTM_VERSION) in dump_nhops_sysctl()
379 nh = (struct nhop_external *)(rtm + 1); in dump_nhops_sysctl()
380 nh_map[nh_count].idx = nh->nh_idx; in dump_nhops_sysctl()
381 nh_map[nh_count].rtm = rtm; in dump_nhops_sysctl()
387 nd->nh_buf = buf; in dump_nhops_sysctl()
388 nd->nh_count = nh_count; in dump_nhops_sysctl()
389 nd->nh_map = nh_map; in dump_nhops_sysctl()
398 struct rt_msghdr *rtm; in print_nhops_sysctl() local
402 xo_open_container("nhop-table"); in print_nhops_sysctl()
403 xo_open_list("rt-family"); in print_nhops_sysctl()
405 nh = (struct nhop_external *)(nd.nh_map[0].rtm + 1); in print_nhops_sysctl()
406 fam = nh->nh_family; in print_nhops_sysctl()
417 xo_open_instance("rt-family"); in print_nhops_sysctl()
419 xo_open_list("nh-entry"); in print_nhops_sysctl()
424 rtm = nd.nh_map[i].rtm; in print_nhops_sysctl()
425 nh = (struct nhop_external *)(rtm + 1); in print_nhops_sysctl()
426 print_nhop_entry_sysctl("nh-entry", rtm, nh); in print_nhops_sysctl()
429 xo_close_list("nh-entry"); in print_nhops_sysctl()
430 xo_close_instance("rt-family"); in print_nhops_sysctl()
432 xo_close_list("rt-family"); in print_nhops_sysctl()
433 xo_close_container("nhop-table"); in print_nhops_sysctl()
446 for (p = nh_bits; p->b_mask; p++) in p_nhflags()
447 if (p->b_mask & f) in p_nhflags()
448 xo_emit("{le:nh_flags_pretty/%s}", p->b_name); in p_nhflags()
459 if (fibnum == -1 && in nhops_print()
460 sysctlbyname("net.my_fibnum", &fibnum, &intsize, NULL, 0) == -1) in nhops_print()
462 if (sysctlbyname("net.fibs", &numfibs, &intsize, NULL, 0) == -1) in nhops_print()
464 if (fibnum < 0 || fibnum > numfibs - 1) in nhops_print()
469 xo_open_container("route-nhop-information"); in nhops_print()
475 xo_close_container("route-nhop-information"); in nhops_print()