dns_query(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… dns_query(9) β€” like, the Kernel API Manual page for dns_query, bestie ✨

Okay so picture this: you're deep in kernel land, and you need to actually resolve a DNS name from inside the kernel. Not from userspace, not with some janky workaround β€” from the kernel. That's what dns_query is for, and honestly? It ate. 🫢


✨ NAME ✨

dns_query β€” query the DNS, obviously πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

int dns_query (struct net *net , const char *type , const char *name ,
size_t namelen , const char *options , char **_result , time64_t
*_expiry , bool invalidate );

That's the whole vibe right there. Eight arguments. Count 'em. πŸ”₯


πŸ¦‹ ARGUMENTS πŸ¦‹

Okay bestie, here's the tea on every single one of these:

  • net β€” the network namespace you wanna operate in. Like, which network world are we doing this in? That one. 🌈
  • type β€” the query type. Or NULL if you just want a straight hostβ†’IP lookup, no fancy stuff. πŸ™ˆ
  • name β€” the name to look up. The thing we're actually curious about. πŸ”
  • namelen β€” length of name. Yes, it's separate. Yes, you have to pass it. πŸ’€
  • options β€” request options. Or NULL if there are no options, which honestly? Fair. ✨
  • _result β€” where the returned data goes. Or NULL, if you're just vibing and don't need the data back. πŸ’œ
  • _expiry β€” where to store the result's expiry time. Or NULL if you don't care when it goes stale. ⏰
  • invalidate β€” <hotpink>always invalidate the key after use</hotpink>. Like, always. That's the whole flag. Periodt. πŸ‘‘

🌸 DESCRIPTION 🌸

So here's what actually happens: the data gets returned in the pointer at *result β€” if you provided one β€” and guess what, bestie, the caller is responsible for freeing it. That's you. You're the caller. You free it. No cap. 😭

The description you pass should be of the form:

"[<query_type>:]<domain_name>"

and the options need to be appropriate for the query type you requested β€” like, don't just throw random options at a type that doesn't understand them, that's not the move. πŸ™ˆ

And if no query_type is given? Then the query is a straight hostname β†’ IP address lookup. Simple. Clean. Iconic. ✨

The DNS resolution lookup itself is performed by upcalling to userspace by way of requesting a key of type dns_resolver. So like, the kernel pops its head up, asks userspace real nice, userspace handles it, and the answer comes back down. Teamwork, honestly. 🫢

On success it returns the size of the result. Otherwise? A -ve error code. So if the number you get back is negative, that's your sign something went sideways. πŸ’€

πŸ”₯ SEE ALSO πŸ”₯

  • Kernel file ./net/dns_resolver/dns_query.c β€” go read the source, bestie, it's right there πŸ‘€

And that's the page!! πŸ’– Cute lil sign-off time: this gem lives over in ./net/dns_resolver, dated October 2026, so if you're reading it in some other timeline... wyd. πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from