Skip to content

Commit 5ccb9e9

Browse files
committed
mctp monitor: Dump IFLA_MCTP attributes
IFLA_AF_SPEC attributes will be split by protocol. IFLA_MCTP_NET and IFLA_MCTP_PHYS_BINDING attributes are decoded and printed. Example ... attr IFLA_AF_SPEC (0x1a) family 45 AF_MCTP: attr IFLA_MCTP_NET (0x1): 6 attr IFLA_MCTP_PHYS_BINDING (0x2): 0 ... Signed-off-by: Matt Johnston <matt@codeconstruct.com.au>
1 parent 890f81d commit 5ccb9e9

1 file changed

Lines changed: 70 additions & 1 deletion

File tree

src/mctp.c

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,82 @@ static const char *rtattr_name(enum attrgroup group, unsigned int type)
158158
return attrnames[group].names[type];
159159
}
160160

161+
static void dump_print_u32(void *val, size_t len, const char *attr_name,
162+
uint32_t attr_type, const char *prefix)
163+
{
164+
printf("%sattr %s (0x%x): ", prefix, attr_name, attr_type);
165+
166+
uint32_t v;
167+
if (len == sizeof(v)) {
168+
memcpy(&v, val, sizeof(v));
169+
printf("%u\n", v);
170+
} else {
171+
printf("Bad value\n");
172+
}
173+
}
174+
175+
static void dump_print_u8(void *val, size_t len, const char *attr_name,
176+
uint32_t attr_type, const char *prefix)
177+
{
178+
printf("%sattr %s (0x%x): ", prefix, attr_name, attr_type);
179+
180+
uint8_t v;
181+
if (len == sizeof(v)) {
182+
memcpy(&v, val, sizeof(v));
183+
printf("%u\n", v);
184+
} else {
185+
printf("Bad value\n");
186+
}
187+
}
188+
189+
static void dump_ifla_af_mctp(struct rtattr *rta, size_t len)
190+
{
191+
for (; RTA_OK(rta, len); rta = RTA_NEXT(rta, len)) {
192+
switch (rta->rta_type) {
193+
case IFLA_MCTP_NET:
194+
dump_print_u32(RTA_DATA(rta), RTA_PAYLOAD(rta),
195+
"IFLA_MCTP_NET", IFLA_MCTP_NET, " ");
196+
break;
197+
case IFLA_MCTP_PHYS_BINDING:
198+
dump_print_u8(RTA_DATA(rta), RTA_PAYLOAD(rta),
199+
"IFLA_MCTP_PHYS_BINDING",
200+
IFLA_MCTP_PHYS_BINDING, " ");
201+
break;
202+
default:
203+
printf(" Unknown MCTP link attribute 0x%x\n",
204+
rta->rta_type);
205+
mctp_hexdump(RTA_DATA(rta), RTA_PAYLOAD(rta), " ");
206+
}
207+
}
208+
}
209+
210+
static void dump_ifla_af_spec(struct rtattr *rta, size_t len)
211+
{
212+
for (; RTA_OK(rta, len); rta = RTA_NEXT(rta, len)) {
213+
if (rta->rta_type == AF_MCTP) {
214+
printf(" family %d AF_MCTP:\n", rta->rta_type);
215+
dump_ifla_af_mctp(RTA_DATA(rta), RTA_PAYLOAD(rta));
216+
} else {
217+
printf(" family %d:\n", rta->rta_type);
218+
mctp_hexdump(RTA_DATA(rta), RTA_PAYLOAD(rta), " ");
219+
}
220+
}
221+
}
222+
161223
static void dump_rtnlmsg_attrs(enum attrgroup group, struct rtattr *rta,
162224
size_t len)
163225
{
164226
for (; RTA_OK(rta, len); rta = RTA_NEXT(rta, len)) {
165227
printf("attr %s (0x%x)\n", rtattr_name(group, rta->rta_type),
166228
rta->rta_type);
167-
mctp_hexdump(RTA_DATA(rta), RTA_PAYLOAD(rta), " ");
229+
switch (rta->rta_type) {
230+
case IFLA_AF_SPEC:
231+
dump_ifla_af_spec(RTA_DATA(rta), RTA_PAYLOAD(rta));
232+
break;
233+
default:
234+
mctp_hexdump(RTA_DATA(rta), RTA_PAYLOAD(rta), " ");
235+
break;
236+
}
168237
}
169238
}
170239

0 commit comments

Comments
 (0)