IPQ_SET_MODE(3)

okay bestie, welcome to IPQ_SET_MODE(3), straight out of the Linux Programmer's Manual β€” section 3, obvi. this is the group-chat translation, but every fact is still here. no cap. πŸ’–

✨ NAME ✨

ipq_set_mode β€” set the ip_queue queuing mode. slay.

πŸ“œ SYNOPSIS πŸ“œ

#include <linux/netfilter.h>
#include <libipq.h>

int ipq_set_mode(const struct ipq_handle *h, uint8_t mode, size_t range);

πŸ’… DESCRIPTION πŸ’…

so the ipq_set_mode function is literally sending a message to the kernel ip_queue module. it's telling it whether packet metadata only, or packet payloads as well as metadata, should be copied to userspace. the way that this one little call controls the whole queue vibe? obsessed. ✨

the h parameter is a context handle β€” and bestie, it must previously have been returned successfully from a call to ipq_create_handle. no random handle, okay? 🫢

the mode parameter must be one of:

  • IPQ_COPY_META β€” copy only packet metadata to userspace.
  • IPQ_COPY_PACKET β€” copy packet metadata and packet payloads to userspace.

the range parameter is used to specify how many bytes of the payload to copy to userspace. important: it is only valid for IPQ_COPY_PACKET mode, and is otherwise ignored. the maximum useful value for range is 65535 β€” greater values will be clamped to this by ip_queue. so don't try to be extra, she will clamp you. πŸ™ˆ

ipq_set_mode is usually used immediately following ipq_create_handle to enable the flow of packets to userspace. like, right after. main character timing. πŸ‘‘

note bestie: the underlying Netlink messaging transport is connectionless, so the ip_queue module does not know that a userspace application is ready to communicate until it receives a message such as this. it's giving "no handshake, just vibes" β€” so you gotta send the message. πŸ’€

🌈 RETURN VALUE 🌈

on failure, -1 is returned.

on success, a non-zero positive value is returned. yes, positive and non-zero. she's not doing zero on success. πŸ‘‘

🚨 ERRORS 🚨

on failure, a descriptive error message will be available via the ipq_errstr function. so if it flops, ipq_errstr has the tea. 🍡

🩺 DIAGNOSTICS 🩺

a relatively common failure may occur if the ip_queue module is not loaded. oop β€” module missing? that'll do it. in this case, the following code excerpt:

status = ipq_set_mode(h, IPQ_COPY_META, 0);
if (status < 0) {
     ipq_perror("myapp");
     ipq_destroy_handle(h);
     exit(1);
}

would generate the following output:

myapp: Failed to send netlink message: Connection refused

πŸ› BUGS πŸ›

None known. not a single one. she's booked and blessed. πŸ’…

πŸ‘‘ AUTHOR πŸ‘‘

James Morris <jmorris@intercode.com.au> β€” this icon.

Copyright (c) 2000-2001 Netfilter Core Team.

Distributed under the GNU General Public License.

πŸ”— SEE ALSO πŸ”—

libipq(3), iptables(8) β€” go read those too bestie. πŸ’–


mwah πŸ’‹ this iconic page is from Linux iptables 1.2, dated 16 October 2001, and the title is IPQ_SET_MODE(3) β€” catch u later bestie! πŸ«ΆπŸ’–

πŸ“¦ where this page comes from