1139749Simp/*-
226159Sse * Copyright (c) 2022 Alexander V. Chernikov <melifaro@FreeBSD.org>
326159Sse *
426159Sse * Redistribution and use in source and binary forms, with or without
526159Sse * modification, are permitted provided that the following conditions
626159Sse * are met:
726159Sse * 1. Redistributions of source code must retain the above copyright
826159Sse *    notice, this list of conditions and the following disclaimer.
926159Sse * 2. Redistributions in binary form must reproduce the above copyright
1026159Sse *    notice, this list of conditions and the following disclaimer in the
1126159Sse *    documentation and/or other materials provided with the distribution.
1226159Sse * 3. Neither the name of the University nor the names of its contributors
1326159Sse *    may be used to endorse or promote products derived from this software
1426159Sse *    without specific prior written permission.
1526159Sse *
1626159Sse * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
1726159Sse * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1826159Sse * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1926159Sse * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2026159Sse * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2126159Sse * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2226159Sse * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2326159Sse * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2426159Sse * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2526159Sse * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2650477Speter * SUCH DAMAGE.
2726159Sse */
2826159Sse
296100Sse#ifndef _NETLINK_NETLINK_DEBUG_H_
3039231Sgibbs#define	_NETLINK_NETLINK_DEBUG_H_
31165217Sjhb
3239231Sgibbs#ifdef _KERNEL
3339231Sgibbs
3439231Sgibbs#define	_DEBUG_SYSCTL_OID	_net_netlink_debug
3526159Sse#include <net/route/route_debug.h>
36165217Sjhb
37165217SjhbSYSCTL_DECL(_net_netlink_debug);
38165217Sjhb
396100Sse/*
40163805Simp * Generic debug
416100Sse * [nl_domain] func_name: debug text
42120063Sscottl */
43120063Sscottl#define	NL_LOG	RT_LOG
44120063Sscottl
45214122Sjkim/*
46214122Sjkim * Logging for events specific for particular process
47214122Sjkim * Example: [nl_domain] PID 4834 fdump_sa: unsupported family: 45
48120063Sscottl */
49220195Sjhb#define	NL_RAW_PID_LOG(_l, _pid, _fmt, ...)	NL_RAW_PID_LOG_##_l(_l, _pid, _fmt, ## __VA_ARGS__)
50220195Sjhb#define	_NL_RAW_PID_LOG(_l, _pid, _fmt, ...)	if (_DEBUG_PASS_MSG(_l)) {	\
51220195Sjhb	_output("[" DEBUG_PREFIX_NAME "] PID %u %s: " _fmt "\n", _pid, __func__, ##__VA_ARGS__); \
52220195Sjhb}
53220195Sjhb
54220195Sjhb#define	NLP_LOG(_l, _nlp, _fmt, ...)	NL_RAW_PID_LOG_##_l(_l, nlp_get_pid(_nlp), _fmt, ## __VA_ARGS__)
55220195Sjhb
56220195Sjhb#if DEBUG_MAX_LEVEL>=LOG_DEBUG3
57163163Sjmg#define	NL_RAW_PID_LOG_LOG_DEBUG3	_NL_RAW_PID_LOG
58163163Sjmg#else
59163163Sjmg#define	NL_RAW_PID_LOG_LOG_DEBUG3(_l, _pid, _fmt, ...)
60262134Sjhb#endif
61163163Sjmg#if DEBUG_MAX_LEVEL>=LOG_DEBUG2
62163163Sjmg#define	NL_RAW_PID_LOG_LOG_DEBUG2	_NL_RAW_PID_LOG
63163163Sjmg#else
64163163Sjmg#define	NL_RAW_PID_LOG_LOG_DEBUG2(_l, _pid, _fmt, ...)
65163163Sjmg#endif
66163163Sjmg#if DEBUG_MAX_LEVEL>=LOG_DEBUG
67163163Sjmg#define	NL_RAW_PID_LOG_LOG_DEBUG	_NL_RAW_PID_LOG
68163163Sjmg#else
69163163Sjmg#define	NL_RAW_PID_LOG_LOG_DEBUG(_l, _pid, _fmt, ...)
70163163Sjmg#endif
71163163Sjmg#if DEBUG_MAX_LEVEL>=LOG_INFO
72167909Sjhb#define	NL_RAW_PID_LOG_LOG_INFO	_NL_RAW_PID_LOG
73163163Sjmg#else
74163163Sjmg#define	NL_RAW_PID_LOG_LOG_INFO(_l, _pid, _fmt, ...)
75163163Sjmg#endif
76163163Sjmg#define	NL_RAW_PID_LOG_LOG_NOTICE	_NL_RAW_PID_LOG
77163163Sjmg#define	NL_RAW_PID_LOG_LOG_ERR         _NL_RAW_PID_LOG
78163163Sjmg#define	NL_RAW_PID_LOG_LOG_WARNING	_NL_RAW_PID_LOG
79163163Sjmg
80120063Sscottl
81120063Sscottl
82120063Sscottl#endif
83164264Sjhb#endif
84120063Sscottl