MCPcopy Create free account
hub / github.com/F-Stack/f-stack / print_nhgroup_entry_sysctl

Function print_nhgroup_entry_sysctl

tools/netstat/nhgrp.c:118–178  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

116
117
118static void
119print_nhgroup_entry_sysctl(const char *name, struct rt_msghdr *rtm,
120 struct nhgrp_external *nhge)
121{
122 char buffer[128];
123 struct nhop_entry *ne;
124 struct nhgrp_nhop_external *ext_cp, *ext_dp;
125 struct nhgrp_container *nhg_cp, *nhg_dp;
126
127 nhg_cp = (struct nhgrp_container *)(nhge + 1);
128 if (nhg_cp->nhgc_type != NHG_C_TYPE_CNHOPS || nhg_cp->nhgc_subtype != 0)
129 return;
130 ext_cp = (struct nhgrp_nhop_external *)(nhg_cp + 1);
131
132 nhg_dp = (struct nhgrp_container *)((char *)nhg_cp + nhg_cp->nhgc_len);
133 if (nhg_dp->nhgc_type != NHG_C_TYPE_DNHOPS || nhg_dp->nhgc_subtype != 0)
134 return;
135 ext_dp = (struct nhgrp_nhop_external *)(nhg_dp + 1);
136
137 xo_open_instance(name);
138
139 snprintf(buffer, sizeof(buffer), "{[:-%d}{:nhgrp-index/%%lu}{]:} ", wid_nhidx);
140
141 xo_emit(buffer, nhge->nhg_idx);
142
143 /* nhidx */
144 print_padding('-', wid_nhidx);
145 /* weight */
146 print_padding('-', wid_nhidx);
147 /* slots */
148 print_padding('-', wid_nhidx);
149 print_padding('-', wid_gw);
150 print_padding('-', wid_if);
151 xo_emit("{t:nhg-refcnt/%*lu}", wid_refcnt, nhge->nhg_refcount);
152 xo_emit("\n");
153
154 xo_open_list("nhop-weights");
155 for (uint32_t i = 0; i < nhg_cp->nhgc_count; i++) {
156 /* TODO: optimize slots calculations */
157 uint32_t slots = 0;
158 for (uint32_t sidx = 0; sidx < nhg_dp->nhgc_count; sidx++) {
159 if (ext_dp[sidx].nh_idx == ext_cp[i].nh_idx)
160 slots++;
161 }
162 xo_open_instance("nhop-weight");
163 print_padding(' ', wid_nhidx);
164 // nh index
165 xo_emit("{t:nh-index/%*lu}", wid_nhidx, ext_cp[i].nh_idx);
166 xo_emit("{t:nh-weight/%*lu}", wid_nhidx, ext_cp[i].nh_weight);
167 xo_emit("{t:nh-slots/%*lu}", wid_nhidx, slots);
168 ne = nhop_get(&global_nhop_map, ext_cp[i].nh_idx);
169 if (ne != NULL) {
170 xo_emit("{t:nh-gw/%*.*s}", wid_gw, wid_gw, ne->gw);
171 xo_emit("{t:nh-interface/%*.*s}", wid_if, wid_if, ne->ifname);
172 }
173 xo_emit("\n");
174 xo_close_instance("nhop-weight");
175 }

Callers 1

print_nhgrp_sysctlFunction · 0.85

Calls 8

xo_open_instanceFunction · 0.85
snprintfFunction · 0.85
xo_emitFunction · 0.85
print_paddingFunction · 0.85
xo_open_listFunction · 0.85
xo_close_instanceFunction · 0.85
xo_close_listFunction · 0.85
nhop_getFunction · 0.70

Tested by

no test coverage detected