Lines Matching +full:- +full:- +full:pretty
2 * nlsock.c - netlink socket
21 switch (nlhdr->nlmsg_type) { in ctrl_msg_summary()
27 if (nlhdr->nlmsg_len < NLMSG_HDRLEN + sizeof(*nlerr)) { in ctrl_msg_summary()
32 printf(" errno=%d\n", nlerr->error); in ctrl_msg_summary()
41 printf(" type %u\n", nlhdr->nlmsg_type); in ctrl_msg_summary()
47 bool outgoing, bool pretty) in genl_msg_summary() argument
49 if (nlhdr->nlmsg_type == ethnl_fam) { in genl_msg_summary()
55 if (nlhdr->nlmsg_len < NLMSG_HDRLEN + GENL_HDRLEN) { in genl_msg_summary()
63 if (ghdr->cmd < n_desc && msg_desc[ghdr->cmd].name) in genl_msg_summary()
64 printf(" %s", msg_desc[ghdr->cmd].name); in genl_msg_summary()
66 printf(" cmd %u", ghdr->cmd); in genl_msg_summary()
69 if (pretty) in genl_msg_summary()
74 if (nlhdr->nlmsg_type == GENL_ID_CTRL) { in genl_msg_summary()
75 printf(" genl-ctrl\n"); in genl_msg_summary()
76 if (pretty) in genl_msg_summary()
81 if (pretty) in genl_msg_summary()
86 static void rtnl_msg_summary(const struct nlmsghdr *nlhdr, bool pretty) in rtnl_msg_summary() argument
88 unsigned int type = nlhdr->nlmsg_type; in rtnl_msg_summary()
95 if (pretty) in rtnl_msg_summary()
100 int nl_fam, bool outgoing, bool pretty) in debug_msg_summary() argument
102 printf(" msg length %u", nlhdr->nlmsg_len); in debug_msg_summary()
104 if (nlhdr->nlmsg_type < NLMSG_MIN_TYPE) { in debug_msg_summary()
111 genl_msg_summary(nlhdr, ethnl_fam, outgoing, pretty); in debug_msg_summary()
114 rtnl_msg_summary(nlhdr, pretty); in debug_msg_summary()
126 uint32_t debug = nlsk->nlctx->ctx->debug; in debug_msg()
128 bool summary, dump, pretty; in debug_msg() local
135 pretty = debug_on(debug, DEBUG_NL_PRETTY_MSG); in debug_msg()
138 switch(nlsk->nl_fam) { in debug_msg()
153 debug_msg_summary(nlhdr, nlsk->nlctx->ethnl_fam, in debug_msg()
154 nlsk->nl_fam, outgoing, pretty); in debug_msg()
156 mnl_nlmsg_fprintf(stdout, nlhdr, nlhdr->nlmsg_len, in debug_msg()
164 * nlsock_process_ack() - process NLMSG_ERROR message from kernel
167 * @suppress_nlerr: 0 show all errors, 1 silence -EOPNOTSUPP, 2 silence all
172 unsigned int suppress_nlerr, bool pretty) in nlsock_process_ack() argument
181 if ((len < NLMSG_HDRLEN + sizeof(*nlerr)) || (len < nlhdr->nlmsg_len)) in nlsock_process_ack()
182 return -EFAULT; in nlsock_process_ack()
185 (suppress_nlerr && nlerr->error == -EOPNOTSUPP); in nlsock_process_ack()
186 if (silent || !(nlhdr->nlmsg_flags & NLM_F_ACK_TLVS)) in nlsock_process_ack()
190 if (!(nlhdr->nlmsg_flags & NLM_F_CAPPED)) in nlsock_process_ack()
191 tlv_offset += MNL_ALIGN(mnl_nlmsg_get_payload_len(&nlerr->msg)); in nlsock_process_ack()
199 nlerr->error ? "error" : "warning", msg); in nlsock_process_ack()
200 if (!pretty && tb[NLMSGERR_ATTR_OFFS]) in nlsock_process_ack()
209 if (nlerr->error && !silent) { in nlsock_process_ack()
210 errno = -nlerr->error; in nlsock_process_ack()
213 if (pretty && !(nlhdr->nlmsg_flags & NLM_F_CAPPED) && in nlsock_process_ack()
214 nlhdr->nlmsg_len >= NLMSG_HDRLEN + nlerr->msg.nlmsg_len) { in nlsock_process_ack()
217 pretty_print_genlmsg(&nlerr->msg, ethnl_umsg_desc, in nlsock_process_ack()
220 return nlerr->error; in nlsock_process_ack()
224 * nlsock_process_reply() - process reply packet(s) from kernel
237 struct nl_msg_buff *msgbuff = &nlsk->msgbuff; in nlsock_process_reply()
246 buff = msgbuff->buff; in nlsock_process_reply()
249 len = mnl_socket_recvfrom(nlsk->sk, buff, msgbuff->size); in nlsock_process_reply()
251 return (len ? -EFAULT : 0); in nlsock_process_reply()
254 return -EFAULT; in nlsock_process_reply()
257 if (nlhdr->nlmsg_type == NLMSG_ERROR) { in nlsock_process_reply()
258 unsigned int suppress = nlsk->nlctx->suppress_nlerr; in nlsock_process_reply()
259 bool pretty; in nlsock_process_reply() local
261 pretty = debug_on(nlsk->nlctx->ctx->debug, in nlsock_process_reply()
263 return nlsock_process_ack(nlhdr, len, suppress, pretty); in nlsock_process_reply()
266 msgbuff->nlhdr = nlhdr; in nlsock_process_reply()
267 msgbuff->genlhdr = mnl_nlmsg_get_payload(nlhdr); in nlsock_process_reply()
268 msgbuff->payload = in nlsock_process_reply()
270 ret = mnl_cb_run(buff, len, nlsk->seq, nlsk->port, reply_cb, in nlsock_process_reply()
281 struct nl_context *nlctx = nlsk->nlctx; in nlsock_prep_get_request()
282 const char *devname = nlctx->ctx->devname; in nlsock_prep_get_request()
289 nlctx->is_dump = !devname; in nlsock_prep_get_request()
291 ret = msg_init(nlctx, &nlsk->msgbuff, nlcmd, nlm_flags); in nlsock_prep_get_request()
294 if (ethnla_fill_header_phy(&nlsk->msgbuff, hdr_attrtype, devname, in nlsock_prep_get_request()
295 nlctx->ctx->phy_index, flags)) in nlsock_prep_get_request()
296 return -EMSGSIZE; in nlsock_prep_get_request()
302 * nlsock_prep_filtered_dump_request() - Initialize a filtered DUMP request
317 struct nl_context *nlctx = nlsk->nlctx; in nlsock_prep_filtered_dump_request()
318 const char *devname = nlctx->ctx->devname; in nlsock_prep_filtered_dump_request()
322 nlctx->is_dump = true; in nlsock_prep_filtered_dump_request()
328 ret = msg_init(nlctx, &nlsk->msgbuff, nlcmd, nlm_flags); in nlsock_prep_filtered_dump_request()
332 if (ethnla_fill_header(&nlsk->msgbuff, hdr_attrtype, devname, flags)) in nlsock_prep_filtered_dump_request()
333 return -EMSGSIZE; in nlsock_prep_filtered_dump_request()
340 * nlsock_sendmsg() - send a netlink message to kernel
348 struct nl_msg_buff *msgbuff = altbuff ?: &nlsk->msgbuff; in nlsock_sendmsg()
349 struct nlmsghdr *nlhdr = msgbuff->nlhdr; in nlsock_sendmsg()
351 nlhdr->nlmsg_seq = ++nlsk->seq; in nlsock_sendmsg()
352 debug_msg(nlsk, msgbuff->buff, nlhdr->nlmsg_len, true); in nlsock_sendmsg()
353 return mnl_socket_sendto(nlsk->sk, nlhdr, nlhdr->nlmsg_len); in nlsock_sendmsg()
358 * nlsock_send_get_request() - send request and process reply
373 ret = nlsock_process_reply(nlsk, cb, nlsk->nlctx); in nlsock_send_get_request()
377 return nlsk->nlctx->exit_code ?: 1; in nlsock_send_get_request()
381 * nlsock_init() - allocate and initialize netlink socket
400 return -ENOMEM; in nlsock_init()
401 nlsk->nlctx = nlctx; in nlsock_init()
402 msgbuff_init(&nlsk->msgbuff); in nlsock_init()
404 ret = -ECONNREFUSED; in nlsock_init()
405 nlsk->sk = mnl_socket_open(nl_fam); in nlsock_init()
406 if (!nlsk->sk) in nlsock_init()
409 mnl_socket_setsockopt(nlsk->sk, NETLINK_EXT_ACK, &val, sizeof(val)); in nlsock_init()
410 ret = mnl_socket_bind(nlsk->sk, 0, MNL_SOCKET_AUTOPID); in nlsock_init()
413 nlsk->port = mnl_socket_get_portid(nlsk->sk); in nlsock_init()
414 nlsk->nl_fam = nl_fam; in nlsock_init()
420 if (nlsk->sk) in nlsock_init()
421 mnl_socket_close(nlsk->sk); in nlsock_init()
423 msgbuff_done(&nlsk->msgbuff); in nlsock_init()
429 * nlsock_done() - destroy a netlink socket
438 if (nlsk->sk) in nlsock_done()
439 mnl_socket_close(nlsk->sk); in nlsock_done()
440 msgbuff_done(&nlsk->msgbuff); in nlsock_done()