netgraph: macfilter: small fixes

Two issues:
- The DEBUG macro defined is in direct conflict with the DEBUG kernel
  option, which broke the -LINT build[0]
- Building with NG_MACFILTER_DEBUG did not compile on LP64 systems due to
  using %d for sizeof().

Reported by:	Jenkins[0]
This commit is contained in:
Kyle Evans 2020-12-09 15:28:56 +00:00
parent 3309fa7403
commit 02354beae7

View File

@ -76,9 +76,9 @@ MALLOC_DEFINE(M_NETGRAPH_MACFILTER, "netgraph_macfilter", "netgraph macfilter no
#define MACTABLE_BLOCKSIZE 128 /* block size for incrementing table */ #define MACTABLE_BLOCKSIZE 128 /* block size for incrementing table */
#ifdef NG_MACFILTER_DEBUG #ifdef NG_MACFILTER_DEBUG
#define DEBUG(fmt, ...) printf("%s:%d: " fmt "\n", __FUNCTION__, __LINE__, __VA_ARGS__) #define MACFILTER_DEBUG(fmt, ...) printf("%s:%d: " fmt "\n", __FUNCTION__, __LINE__, __VA_ARGS__)
#else #else
#define DEBUG(fmt, ...) #define MACFILTER_DEBUG(fmt, ...)
#endif #endif
#define MAC_FMT "%02x:%02x:%02x:%02x:%02x:%02x" #define MAC_FMT "%02x:%02x:%02x:%02x:%02x:%02x"
#define MAC_S_ARGS(v) (v)[0], (v)[1], (v)[2], (v)[3], (v)[4], (v)[5] #define MAC_S_ARGS(v) (v)[0], (v)[1], (v)[2], (v)[3], (v)[4], (v)[5]
@ -148,7 +148,7 @@ macfilter_get_upper_hook_count(const struct ng_parse_type *type,
const struct ngm_macfilter_hooks *const ngm_hooks = const struct ngm_macfilter_hooks *const ngm_hooks =
(const struct ngm_macfilter_hooks *)(buf - OFFSETOF(struct ngm_macfilter_hooks, hooks)); (const struct ngm_macfilter_hooks *)(buf - OFFSETOF(struct ngm_macfilter_hooks, hooks));
DEBUG("buf %p, ngm_hooks %p, n %d", buf, ngm_hooks, ngm_hooks->n); MACFILTER_DEBUG("buf %p, ngm_hooks %p, n %d", buf, ngm_hooks, ngm_hooks->n);
return ngm_hooks->n; return ngm_hooks->n;
} }
@ -294,7 +294,7 @@ macfilter_mactable_resize(macfilter_p mfp)
n = mfp->mf_mac_allocated + MACTABLE_BLOCKSIZE; n = mfp->mf_mac_allocated + MACTABLE_BLOCKSIZE;
if (n != mfp->mf_mac_allocated) { if (n != mfp->mf_mac_allocated) {
DEBUG("used=%d allocated=%d->%d", MACFILTER_DEBUG("used=%d allocated=%d->%d",
mfp->mf_mac_used, mfp->mf_mac_allocated, n); mfp->mf_mac_used, mfp->mf_mac_allocated, n);
mf_mac_p mfp_new = realloc(mfp->mf_macs, mf_mac_p mfp_new = realloc(mfp->mf_macs,
@ -410,7 +410,7 @@ macfilter_mactable_change(macfilter_p mfp, u_char *ether, int hookid)
mf_mac_p mf_macs = mfp->mf_macs; mf_mac_p mf_macs = mfp->mf_macs;
DEBUG("ether=" MAC_FMT " found=%d i=%d ether=" MAC_FMT " hookid=%d->%d used=%d allocated=%d", MACFILTER_DEBUG("ether=" MAC_FMT " found=%d i=%d ether=" MAC_FMT " hookid=%d->%d used=%d allocated=%d",
MAC_S_ARGS(ether), found, i, MAC_S_ARGS(mf_macs[i].ether), MAC_S_ARGS(ether), found, i, MAC_S_ARGS(mf_macs[i].ether),
(found? mf_macs[i].hookid:NG_MACFILTER_HOOK_DEFAULT_ID), hookid, (found? mf_macs[i].hookid:NG_MACFILTER_HOOK_DEFAULT_ID), hookid,
mfp->mf_mac_used, mfp->mf_mac_allocated); mfp->mf_mac_used, mfp->mf_mac_allocated);
@ -493,7 +493,7 @@ macfilter_find_hook(macfilter_p mfp, const char *hookname)
static int static int
macfilter_direct(macfilter_p mfp, struct ngm_macfilter_direct *md) macfilter_direct(macfilter_p mfp, struct ngm_macfilter_direct *md)
{ {
DEBUG("ether=" MAC_FMT " hook=%s", MACFILTER_DEBUG("ether=" MAC_FMT " hook=%s",
MAC_S_ARGS(md->ether), md->hookname); MAC_S_ARGS(md->ether), md->hookname);
int hookid = macfilter_find_hook(mfp, md->hookname); int hookid = macfilter_find_hook(mfp, md->hookname);
@ -506,7 +506,7 @@ macfilter_direct(macfilter_p mfp, struct ngm_macfilter_direct *md)
static int static int
macfilter_direct_hookid(macfilter_p mfp, struct ngm_macfilter_direct_hookid *mdi) macfilter_direct_hookid(macfilter_p mfp, struct ngm_macfilter_direct_hookid *mdi)
{ {
DEBUG("ether=" MAC_FMT " hookid=%d", MACFILTER_DEBUG("ether=" MAC_FMT " hookid=%d",
MAC_S_ARGS(mdi->ether), mdi->hookid); MAC_S_ARGS(mdi->ether), mdi->hookid);
if (mdi->hookid >= mfp->mf_upper_cnt) if (mdi->hookid >= mfp->mf_upper_cnt)
@ -545,13 +545,13 @@ macfilter_ether_output(hook_p hook, macfilter_p mfp, struct mbuf *m, hook_p *nex
mf_macs[i].bytes_out += m->m_len - ETHER_HDR_LEN; mf_macs[i].bytes_out += m->m_len - ETHER_HDR_LEN;
#ifdef NG_MACFILTER_DEBUG_RECVDATA #ifdef NG_MACFILTER_DEBUG_RECVDATA
DEBUG("ether=" MAC_FMT " len=%db->%lldb: bytes: %s -> %s", MACFILTER_DEBUG("ether=" MAC_FMT " len=%db->%lldb: bytes: %s -> %s",
MAC_S_ARGS(ether), m->m_len - ETHER_HDR_LEN, mf_macs[i].bytes_out, MAC_S_ARGS(ether), m->m_len - ETHER_HDR_LEN, mf_macs[i].bytes_out,
NG_HOOK_NAME(hook), NG_HOOK_NAME(*next_hook)); NG_HOOK_NAME(hook), NG_HOOK_NAME(*next_hook));
#endif #endif
} else { } else {
#ifdef NG_MACFILTER_DEBUG_RECVDATA #ifdef NG_MACFILTER_DEBUG_RECVDATA
DEBUG("ether=" MAC_FMT " len=%db->?b: bytes: %s->%s", MACFILTER_DEBUG("ether=" MAC_FMT " len=%db->?b: bytes: %s->%s",
MAC_S_ARGS(ether), m->m_len - ETHER_HDR_LEN, MAC_S_ARGS(ether), m->m_len - ETHER_HDR_LEN,
NG_HOOK_NAME(hook), NG_HOOK_NAME(*next_hook)); NG_HOOK_NAME(hook), NG_HOOK_NAME(*next_hook));
#endif #endif
@ -587,13 +587,13 @@ macfilter_ether_input(hook_p hook, macfilter_p mfp, struct mbuf *m, hook_p *next
hookid = mf_macs[i].hookid; hookid = mf_macs[i].hookid;
#ifdef NG_MACFILTER_DEBUG_RECVDATA #ifdef NG_MACFILTER_DEBUG_RECVDATA
DEBUG("ether=" MAC_FMT " len=%db->%lldb: bytes: %s->%s", MACFILTER_DEBUG("ether=" MAC_FMT " len=%db->%lldb: bytes: %s->%s",
MAC_S_ARGS(ether), m->m_len - ETHER_HDR_LEN, mf_macs[i].bytes_in, MAC_S_ARGS(ether), m->m_len - ETHER_HDR_LEN, mf_macs[i].bytes_in,
NG_HOOK_NAME(hook), NG_HOOK_NAME(*next_hook)); NG_HOOK_NAME(hook), NG_HOOK_NAME(*next_hook));
#endif #endif
} else { } else {
#ifdef NG_MACFILTER_DEBUG_RECVDATA #ifdef NG_MACFILTER_DEBUG_RECVDATA
DEBUG("ether=" MAC_FMT " len=%db->?b: bytes: %s->%s", MACFILTER_DEBUG("ether=" MAC_FMT " len=%db->?b: bytes: %s->%s",
MAC_S_ARGS(ether), m->m_len - ETHER_HDR_LEN, MAC_S_ARGS(ether), m->m_len - ETHER_HDR_LEN,
NG_HOOK_NAME(hook), NG_HOOK_NAME(*next_hook)); NG_HOOK_NAME(hook), NG_HOOK_NAME(*next_hook));
#endif #endif
@ -642,7 +642,7 @@ ng_macfilter_newhook(node_p node, hook_p hook, const char *hookname)
{ {
const macfilter_p mfp = NG_NODE_PRIVATE(node); const macfilter_p mfp = NG_NODE_PRIVATE(node);
DEBUG("%s", hookname); MACFILTER_DEBUG("%s", hookname);
if (strcmp(hookname, NG_MACFILTER_HOOK_ETHER) == 0) { if (strcmp(hookname, NG_MACFILTER_HOOK_ETHER) == 0) {
mfp->mf_ether_hook = hook; mfp->mf_ether_hook = hook;
@ -657,7 +657,7 @@ ng_macfilter_newhook(node_p node, hook_p hook, const char *hookname)
} }
if (hookid >= mfp->mf_upper_cnt) { if (hookid >= mfp->mf_upper_cnt) {
DEBUG("upper cnt %d -> %d", mfp->mf_upper_cnt, hookid + 1); MACFILTER_DEBUG("upper cnt %d -> %d", mfp->mf_upper_cnt, hookid + 1);
mfp->mf_upper_cnt = hookid + 1; mfp->mf_upper_cnt = hookid + 1;
mfp->mf_upper = realloc(mfp->mf_upper, mfp->mf_upper = realloc(mfp->mf_upper,
@ -700,7 +700,7 @@ ng_macfilter_rcvmsg(node_p node, item_p item, hook_p lasthook)
case NGM_MACFILTER_DIRECT: case NGM_MACFILTER_DIRECT:
if (msg->header.arglen != sizeof(struct ngm_macfilter_direct)) { if (msg->header.arglen != sizeof(struct ngm_macfilter_direct)) {
DEBUG("direct: wrong type length (%d, expected %d)", MACFILTER_DEBUG("direct: wrong type length (%d, expected %zu)",
msg->header.arglen, sizeof(struct ngm_macfilter_direct)); msg->header.arglen, sizeof(struct ngm_macfilter_direct));
error = EINVAL; error = EINVAL;
break; break;
@ -710,7 +710,7 @@ ng_macfilter_rcvmsg(node_p node, item_p item, hook_p lasthook)
break; break;
case NGM_MACFILTER_DIRECT_HOOKID: case NGM_MACFILTER_DIRECT_HOOKID:
if (msg->header.arglen != sizeof(struct ngm_macfilter_direct_hookid)) { if (msg->header.arglen != sizeof(struct ngm_macfilter_direct_hookid)) {
DEBUG("direct hookid: wrong type length (%d, expected %d)", MACFILTER_DEBUG("direct hookid: wrong type length (%d, expected %zu)",
msg->header.arglen, sizeof(struct ngm_macfilter_direct)); msg->header.arglen, sizeof(struct ngm_macfilter_direct));
error = EINVAL; error = EINVAL;
break; break;
@ -793,7 +793,7 @@ ng_macfilter_rcvdata(hook_p hook, item_p item)
struct mbuf *m; struct mbuf *m;
m = NGI_M(item); /* 'item' still owns it. We are peeking */ m = NGI_M(item); /* 'item' still owns it. We are peeking */
DEBUG("%s", NG_HOOK_NAME(hook)); MACFILTER_DEBUG("%s", NG_HOOK_NAME(hook));
if (hook == mfp->mf_ether_hook) if (hook == mfp->mf_ether_hook)
error = macfilter_ether_input(hook, mfp, m, &next_hook); error = macfilter_ether_input(hook, mfp, m, &next_hook);
@ -820,7 +820,7 @@ ng_macfilter_disconnect(hook_p hook)
if (mfp->mf_ether_hook == hook) { if (mfp->mf_ether_hook == hook) {
mfp->mf_ether_hook = NULL; mfp->mf_ether_hook = NULL;
DEBUG("%s", NG_HOOK_NAME(hook)); MACFILTER_DEBUG("%s", NG_HOOK_NAME(hook));
} else { } else {
int hookid; int hookid;
@ -833,7 +833,7 @@ ng_macfilter_disconnect(hook_p hook)
#else #else
int cnt = macfilter_mactable_remove_by_hookid(mfp, hookid); int cnt = macfilter_mactable_remove_by_hookid(mfp, hookid);
DEBUG("%s: removed %d MACs", NG_HOOK_NAME(hook), cnt); MACFILTER_DEBUG("%s: removed %d MACs", NG_HOOK_NAME(hook), cnt);
#endif #endif
break; break;
} }
@ -844,7 +844,7 @@ ng_macfilter_disconnect(hook_p hook)
for (--hookid; hookid >= 0 && mfp->mf_upper[hookid] == NULL; hookid--) for (--hookid; hookid >= 0 && mfp->mf_upper[hookid] == NULL; hookid--)
; ;
DEBUG("upper cnt %d -> %d", mfp->mf_upper_cnt, hookid + 1); MACFILTER_DEBUG("upper cnt %d -> %d", mfp->mf_upper_cnt, hookid + 1);
mfp->mf_upper_cnt = hookid + 1; mfp->mf_upper_cnt = hookid + 1;
mfp->mf_upper = realloc(mfp->mf_upper, mfp->mf_upper = realloc(mfp->mf_upper,
sizeof(mfp->mf_upper[0])*mfp->mf_upper_cnt, sizeof(mfp->mf_upper[0])*mfp->mf_upper_cnt,