linux(4): Improve netlink diagnostics

Add some missing netlink_family definitions and produce vaguely
human-readable error messages for those definitions, like we used to do for
just ROUTE and KOBJECT_UEVENTS.

Additionally, if we know it's a netfilter socket but didn't find it in the
table, fall back to printing that instead of the generic handler ("socket
domain 16, ...").

No change to the emulator correctness, just mildly improved diagnostics for
gaps.
This commit is contained in:
Conrad Meyer 2020-11-03 19:50:42 +00:00
parent 19647e76fc
commit 9e47480e94
2 changed files with 41 additions and 17 deletions

View File

@ -60,8 +60,14 @@ struct l_sockaddr {
#define LINUX_AF_INET6 10
#define LINUX_AF_NETLINK 16
#define LINUX_NETLINK_ROUTE 0
#define LINUX_NETLINK_UEVENT 15
#define LINUX_NETLINK_ROUTE 0
#define LINUX_NETLINK_SOCK_DIAG 4
#define LINUX_NETLINK_NFLOG 5
#define LINUX_NETLINK_SELINUX 7
#define LINUX_NETLINK_AUDIT 9
#define LINUX_NETLINK_FIB_LOOKUP 10
#define LINUX_NETLINK_NETFILTER 12
#define LINUX_NETLINK_KOBJECT_UEVENT 15
/*
* net device flags

View File

@ -502,6 +502,17 @@ linux_sendto_hdrincl(struct thread *td, struct linux_sendto_args *linux_args)
return (error);
}
static const char *linux_netlink_names[] = {
[LINUX_NETLINK_ROUTE] = "ROUTE",
[LINUX_NETLINK_SOCK_DIAG] = "SOCK_DIAG",
[LINUX_NETLINK_NFLOG] = "NFLOG",
[LINUX_NETLINK_SELINUX] = "SELINUX",
[LINUX_NETLINK_AUDIT] = "AUDIT",
[LINUX_NETLINK_FIB_LOOKUP] = "FIB_LOOKUP",
[LINUX_NETLINK_NETFILTER] = "NETFILTER",
[LINUX_NETLINK_KOBJECT_UEVENT] = "KOBJECT_UEVENT",
};
int
linux_socket(struct thread *td, struct linux_socket_args *args)
{
@ -516,22 +527,29 @@ linux_socket(struct thread *td, struct linux_socket_args *args)
return (retval_socket);
domain = linux_to_bsd_domain(args->domain);
if (domain == -1) {
if (args->domain == LINUX_AF_NETLINK &&
args->protocol == LINUX_NETLINK_ROUTE) {
linux_msg(curthread,
"unsupported socket(AF_NETLINK, %d, NETLINK_ROUTE)", type);
return (EAFNOSUPPORT);
/* Mask off SOCK_NONBLOCK / CLOEXEC for error messages. */
type = args->type & LINUX_SOCK_TYPE_MASK;
if (args->domain == LINUX_AF_NETLINK) {
const char *nl_name;
if (args->protocol >= 0 &&
args->protocol < nitems(linux_netlink_names))
nl_name = linux_netlink_names[args->protocol];
else
nl_name = NULL;
if (nl_name != NULL)
linux_msg(curthread,
"unsupported socket(AF_NETLINK, %d, "
"NETLINK_%s)", type, nl_name);
else
linux_msg(curthread,
"unsupported socket(AF_NETLINK, %d, %d)",
type, args->protocol);
} else {
linux_msg(curthread, "unsupported socket domain %d, "
"type %d, protocol %d", args->domain, type,
args->protocol);
}
if (args->domain == LINUX_AF_NETLINK &&
args->protocol == LINUX_NETLINK_UEVENT) {
linux_msg(curthread,
"unsupported socket(AF_NETLINK, %d, NETLINK_UEVENT)", type);
return (EAFNOSUPPORT);
}
linux_msg(curthread, "unsupported socket domain %d, type %d, protocol %d",
args->domain, args->type & LINUX_SOCK_TYPE_MASK, args->protocol);
return (EAFNOSUPPORT);
}