net/netfilter/nf_log.c
Source file repositories/reference/linux-study-clean/net/netfilter/nf_log.c
File Facts
- System
- Linux kernel
- Corpus path
net/netfilter/nf_log.c- Extension
.c- Size
- 13277 bytes
- Lines
- 601
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/init.hlinux/module.hlinux/proc_fs.hlinux/skbuff.hlinux/netfilter.hlinux/seq_file.hnet/protocol.hnet/netfilter/nf_log.hnf_internals.h
Detected Declarations
struct nf_log_buffunction nf_log_setfunction nf_log_unsetfunction nf_log_registerfunction nf_log_unregisterfunction nf_log_is_registeredfunction nf_log_bind_pffunction nf_log_unbind_pffunction nf_logger_find_getfunction nf_logger_putfunction nf_log_packetfunction nf_log_tracefunction nf_log_buf_closefunction seq_stopfunction seq_showfunction nf_log_proc_dostringfunction netfilter_log_sysctl_initfunction netfilter_log_sysctl_exitfunction netfilter_log_sysctl_initfunction netfilter_log_sysctl_exitfunction nf_log_net_exitfunction netfilter_log_initexport sysctl_nf_log_all_netnsexport nf_log_setexport nf_log_unsetexport nf_log_registerexport nf_log_unregisterexport nf_log_is_registeredexport nf_log_bind_pfexport nf_log_unbind_pfexport nf_logger_find_getexport nf_logger_putexport nf_log_packetexport nf_log_traceexport nf_log_buf_addexport nf_log_buf_openexport nf_log_buf_close
Annotated Snippet
struct nf_log_buf {
unsigned int count;
char buf[S_SIZE + 1];
};
static struct nf_log_buf emergency, *emergency_ptr = &emergency;
__printf(2, 3) int nf_log_buf_add(struct nf_log_buf *m, const char *f, ...)
{
va_list args;
int len;
if (likely(m->count < S_SIZE)) {
va_start(args, f);
len = vsnprintf(m->buf + m->count, S_SIZE - m->count, f, args);
va_end(args);
if (likely(m->count + len < S_SIZE)) {
m->count += len;
return 0;
}
}
m->count = S_SIZE;
printk_once(KERN_ERR KBUILD_MODNAME " please increase S_SIZE\n");
return -1;
}
EXPORT_SYMBOL_GPL(nf_log_buf_add);
struct nf_log_buf *nf_log_buf_open(void)
{
struct nf_log_buf *m = kmalloc_obj(*m, GFP_ATOMIC);
if (unlikely(!m)) {
local_bh_disable();
do {
m = xchg(&emergency_ptr, NULL);
} while (!m);
}
m->count = 0;
return m;
}
EXPORT_SYMBOL_GPL(nf_log_buf_open);
void nf_log_buf_close(struct nf_log_buf *m)
{
m->buf[m->count] = 0;
printk("%s\n", m->buf);
if (likely(m != &emergency))
kfree(m);
else {
emergency_ptr = m;
local_bh_enable();
}
}
EXPORT_SYMBOL_GPL(nf_log_buf_close);
#ifdef CONFIG_PROC_FS
static void *seq_start(struct seq_file *seq, loff_t *pos)
{
struct net *net = seq_file_net(seq);
mutex_lock(&nf_log_mutex);
if (*pos >= ARRAY_SIZE(net->nf.nf_loggers))
return NULL;
return pos;
}
static void *seq_next(struct seq_file *s, void *v, loff_t *pos)
{
struct net *net = seq_file_net(s);
(*pos)++;
if (*pos >= ARRAY_SIZE(net->nf.nf_loggers))
return NULL;
return pos;
}
static void seq_stop(struct seq_file *s, void *v)
{
mutex_unlock(&nf_log_mutex);
}
static int seq_show(struct seq_file *s, void *v)
{
loff_t *pos = v;
const struct nf_logger *logger;
int i;
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/init.h`, `linux/module.h`, `linux/proc_fs.h`, `linux/skbuff.h`, `linux/netfilter.h`, `linux/seq_file.h`, `net/protocol.h`.
- Detected declarations: `struct nf_log_buf`, `function nf_log_set`, `function nf_log_unset`, `function nf_log_register`, `function nf_log_unregister`, `function nf_log_is_registered`, `function nf_log_bind_pf`, `function nf_log_unbind_pf`, `function nf_logger_find_get`, `function nf_logger_put`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.