improve tracing in freebsd_network compat library, better log spam.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40886 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Alexander von Gluck IV
2011-03-08 22:38:16 +00:00
parent 1d1031cf27
commit eadb4f9f20
+21 -35
View File
@@ -65,14 +65,16 @@
*/ */
#define IFMEDIA_DEBUG #define IFMEDIA_DEBUG
#ifdef IFMEDIA_DEBUG
# define TRACE(x...) dprintf("BSD_IFMEDIA_DEBUG: " x)
#else
# define TRACE(x...) ;
#endif
static struct ifmedia_entry *ifmedia_match(struct ifmedia *ifm, static struct ifmedia_entry *ifmedia_match(struct ifmedia *ifm,
int flags, int mask); int flags, int mask);
#ifdef IFMEDIA_DEBUG
int ifmedia_debug = 1;
static void ifmedia_printword(int); static void ifmedia_printword(int);
#endif
/* /*
* Initialize if_media struct for a specific interface instance. * Initialize if_media struct for a specific interface instance.
@@ -120,14 +122,12 @@ ifmedia_add(ifm, mword, data, aux)
register struct ifmedia_entry *entry; register struct ifmedia_entry *entry;
#ifdef IFMEDIA_DEBUG #ifdef IFMEDIA_DEBUG
if (ifmedia_debug) {
if (ifm == NULL) { if (ifm == NULL) {
printf("ifmedia_add: null ifm\n"); TRACE("ifmedia_add: null ifm\n");
return; return;
} }
printf("Adding entry for "); TRACE("ifmedia_add: Adding Entry...\n");
ifmedia_printword(mword); ifmedia_printword(mword);
}
#endif #endif
entry = kernel_malloc(sizeof(*entry), M_IFADDR, M_NOWAIT); entry = kernel_malloc(sizeof(*entry), M_IFADDR, M_NOWAIT);
@@ -176,19 +176,17 @@ ifmedia_set(ifm, target)
match = ifmedia_match(ifm, target, ifm->ifm_mask); match = ifmedia_match(ifm, target, ifm->ifm_mask);
if (match == NULL) { if (match == NULL) {
printf("ifmedia_set: no match for 0x%x/0x%x\n", TRACE("ifmedia_set: no match for 0x%x/0x%x\n",
target, ~ifm->ifm_mask); target, ~ifm->ifm_mask);
panic("ifmedia_set"); panic("ifmedia_set");
} }
ifm->ifm_cur = match; ifm->ifm_cur = match;
#ifdef IFMEDIA_DEBUG #ifdef IFMEDIA_DEBUG
if (ifmedia_debug) { TRACE("ifmedia_set: target ");
printf("ifmedia_set: target ");
ifmedia_printword(target); ifmedia_printword(target);
printf("ifmedia_set: setting to "); TRACE("ifmedia_set: setting to ");
ifmedia_printword(ifm->ifm_cur->ifm_media); ifmedia_printword(ifm->ifm_cur->ifm_media);
}
#endif #endif
} }
@@ -222,13 +220,8 @@ ifmedia_ioctl(ifp, ifr, ifm, cmd)
match = ifmedia_match(ifm, newmedia, ifm->ifm_mask); match = ifmedia_match(ifm, newmedia, ifm->ifm_mask);
if (match == NULL) { if (match == NULL) {
#ifdef IFMEDIA_DEBUG TRACE("ifmedia_ioctl: no media found for 0x%x\n",
if (ifmedia_debug) {
printf(
"ifmedia_ioctl: no media found for 0x%x\n",
newmedia); newmedia);
}
#endif
return (ENXIO); return (ENXIO);
} }
@@ -249,11 +242,9 @@ ifmedia_ioctl(ifp, ifr, ifm, cmd)
* driver can't switch. * driver can't switch.
*/ */
#ifdef IFMEDIA_DEBUG #ifdef IFMEDIA_DEBUG
if (ifmedia_debug) { TRACE("ifmedia_ioctl: switching %s to ",
printf("ifmedia_ioctl: switching %s to ",
ifp->if_xname); ifp->if_xname);
ifmedia_printword(match->ifm_media); ifmedia_printword(match->ifm_media);
}
#endif #endif
oldentry = ifm->ifm_cur; oldentry = ifm->ifm_cur;
oldmedia = ifm->ifm_media; oldmedia = ifm->ifm_media;
@@ -376,9 +367,9 @@ ifmedia_match(ifm, target, mask)
LIST_FOREACH(next, &ifm->ifm_list, ifm_list) { LIST_FOREACH(next, &ifm->ifm_list, ifm_list) {
if ((next->ifm_media & mask) == (target & mask)) { if ((next->ifm_media & mask) == (target & mask)) {
#if defined(IFMEDIA_DEBUG) || defined(DIAGNOSTIC) #ifdef IFMEDIA_DEBUG
if (match) { if (match) {
printf("ifmedia_match: multiple match for " TRACE("ifmedia_match: multiple match for "
"0x%x/0x%x\n", target, mask); "0x%x/0x%x\n", target, mask);
} }
#endif #endif
@@ -506,16 +497,16 @@ ifmedia_printword(ifmw)
if (IFM_TYPE(ifmw) == desc->ifmt_word) if (IFM_TYPE(ifmw) == desc->ifmt_word)
break; break;
if (desc->ifmt_string == NULL) { if (desc->ifmt_string == NULL) {
printf("<unknown type>\n"); TRACE(" Type: <unknown type>\n");
return; return;
} }
printf(desc->ifmt_string); TRACE(" Type: %s\n", desc->ifmt_string);
/* Any mode. */ /* Any mode. */
for (desc = ttos->modes; desc && desc->ifmt_string != NULL; desc++) for (desc = ttos->modes; desc && desc->ifmt_string != NULL; desc++)
if (IFM_MODE(ifmw) == desc->ifmt_word) { if (IFM_MODE(ifmw) == desc->ifmt_word) {
if (desc->ifmt_string != NULL) if (desc->ifmt_string != NULL)
printf(" mode %s", desc->ifmt_string); TRACE(" Mode: %s\n", desc->ifmt_string);
break; break;
} }
@@ -532,12 +523,12 @@ ifmedia_printword(ifmw)
if (IFM_SUBTYPE(ifmw) == desc->ifmt_word) if (IFM_SUBTYPE(ifmw) == desc->ifmt_word)
break; break;
if (desc->ifmt_string == NULL) { if (desc->ifmt_string == NULL) {
printf(" <unknown subtype>\n"); TRACE(" SubType: <unknown>\n");
return; return;
} }
got_subtype: got_subtype:
printf(" %s", desc->ifmt_string); TRACE(" SubType: %s\n", desc->ifmt_string);
/* /*
* Look for shared options. * Look for shared options.
@@ -545,9 +536,7 @@ ifmedia_printword(ifmw)
for (desc = ifm_shared_option_descriptions; for (desc = ifm_shared_option_descriptions;
desc->ifmt_string != NULL; desc++) { desc->ifmt_string != NULL; desc++) {
if (ifmw & desc->ifmt_word) { if (ifmw & desc->ifmt_word) {
if (seen_option == 0) TRACE(" Shared Option[%d]: %s\n", seen_option++,
printf(" <");
printf("%s%s", seen_option++ ? "," : "",
desc->ifmt_string); desc->ifmt_string);
} }
} }
@@ -557,12 +546,9 @@ ifmedia_printword(ifmw)
*/ */
for (desc = ttos->options; desc->ifmt_string != NULL; desc++) { for (desc = ttos->options; desc->ifmt_string != NULL; desc++) {
if (ifmw & desc->ifmt_word) { if (ifmw & desc->ifmt_word) {
if (seen_option == 0) TRACE(" SubType Option[%d]: %s\n", seen_option++,
printf(" <");
printf("%s%s", seen_option++ ? "," : "",
desc->ifmt_string); desc->ifmt_string);
} }
} }
printf("%s\n", seen_option ? ">" : "");
} }
#endif /* IFMEDIA_DEBUG */ #endif /* IFMEDIA_DEBUG */