2 * Copyright (c) 2012 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@dragonflybsd.org>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * 3. Neither the name of The DragonFly Project nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific, prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #include "dmsg_local.h"
38 dmsg_basecmd_str(uint32_t cmd)
46 switch(cmd & DMSGF_PROTOS) {
69 snprintf(protobuf, sizeof(protobuf), "%x_",
70 (cmd & DMSGF_PROTOS) >> 20);
75 switch(cmd & (DMSGF_PROTOS |
93 case DMSG_LNK_VOLCONF:
97 if (cmd & DMSGF_DELETE)
106 snprintf(cmdbuf, sizeof(cmdbuf),
107 "%06x", (cmd & (DMSGF_PROTOS |
113 snprintf(buf, sizeof(buf), "%s%s", protostr, cmdstr);
118 dmsg_msg_str(dmsg_msg_t *msg)
121 static char buf[256];
125 const char *statestr;
133 if ((state = msg->state) != NULL) {
134 basecmd = (state->rxcmd & DMSGF_REPLY) ?
135 state->txcmd : state->rxcmd;
136 snprintf(statebuf, sizeof(statebuf),
137 " %s=%s,L=%s%s,R=%s%s",
138 ((state->txcmd & DMSGF_REPLY) ?
139 "rcvcmd" : "sndcmd"),
140 dmsg_basecmd_str(basecmd),
141 ((state->txcmd & DMSGF_CREATE) ? "C" : ""),
142 ((state->txcmd & DMSGF_DELETE) ? "D" : ""),
143 ((state->rxcmd & DMSGF_CREATE) ? "C" : ""),
144 ((state->rxcmd & DMSGF_DELETE) ? "D" : "")
154 switch(msg->any.head.error) {
158 case DMSG_IOQ_ERROR_SYNC:
159 errstr = "err=IOQ:NOSYNC";
161 case DMSG_IOQ_ERROR_EOF:
162 errstr = "err=IOQ:STREAMEOF";
164 case DMSG_IOQ_ERROR_SOCK:
165 errstr = "err=IOQ:SOCKERR";
167 case DMSG_IOQ_ERROR_FIELD:
168 errstr = "err=IOQ:BADFIELD";
170 case DMSG_IOQ_ERROR_HCRC:
171 errstr = "err=IOQ:BADHCRC";
173 case DMSG_IOQ_ERROR_XCRC:
174 errstr = "err=IOQ:BADXCRC";
176 case DMSG_IOQ_ERROR_ACRC:
177 errstr = "err=IOQ:BADACRC";
179 case DMSG_IOQ_ERROR_STATE:
180 errstr = "err=IOQ:BADSTATE";
182 case DMSG_IOQ_ERROR_NOPEER:
183 errstr = "err=IOQ:PEERCONFIG";
185 case DMSG_IOQ_ERROR_NORKEY:
186 errstr = "err=IOQ:BADRKEY";
188 case DMSG_IOQ_ERROR_NOLKEY:
189 errstr = "err=IOQ:BADLKEY";
191 case DMSG_IOQ_ERROR_KEYXCHGFAIL:
192 errstr = "err=IOQ:BADKEYXCHG";
194 case DMSG_IOQ_ERROR_KEYFMT:
195 errstr = "err=IOQ:BADFMT";
197 case DMSG_IOQ_ERROR_BADURANDOM:
198 errstr = "err=IOQ:BADRANDOM";
200 case DMSG_IOQ_ERROR_MSGSEQ:
201 errstr = "err=IOQ:BADSEQ";
203 case DMSG_IOQ_ERROR_EALREADY:
204 errstr = "err=IOQ:DUPMSG";
206 case DMSG_IOQ_ERROR_TRANS:
207 errstr = "err=IOQ:BADTRANS";
209 case DMSG_IOQ_ERROR_IVWRAP:
210 errstr = "err=IOQ:IVWRAP";
212 case DMSG_IOQ_ERROR_MACFAIL:
213 errstr = "err=IOQ:MACFAIL";
215 case DMSG_IOQ_ERROR_ALGO:
216 errstr = "err=IOQ:ALGOFAIL";
218 case DMSG_ERR_NOSUPP:
219 errstr = "err=NOSUPPORT";
222 snprintf(errbuf, sizeof(errbuf),
223 " err=%d", msg->any.head.error);
232 if (msg->any.head.cmd & (DMSGF_CREATE | DMSGF_DELETE |
233 DMSGF_ABORT | DMSGF_REPLY)) {
235 if (msg->any.head.cmd & DMSGF_CREATE)
237 if (msg->any.head.cmd & DMSGF_DELETE)
239 if (msg->any.head.cmd & DMSGF_REPLY)
241 if (msg->any.head.cmd & DMSGF_ABORT)
249 snprintf(buf, sizeof(buf),
250 "msg=%s%s %s id=%08x src=%08x tgt=%08x %s",
251 dmsg_basecmd_str(msg->any.head.cmd),
254 (uint32_t)(intmax_t)msg->any.head.msgid, /* for brevity */
255 (uint32_t)(intmax_t)msg->any.head.source, /* for brevity */
256 (uint32_t)(intmax_t)msg->any.head.target, /* for brevity */