Author: cem
Date: Tue Nov  3 19:50:42 2020
New Revision: 367303
URL: https://svnweb.freebsd.org/changeset/base/367303

Log:
  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.

Modified:
  head/sys/compat/linux/linux.h
  head/sys/compat/linux/linux_socket.c

Modified: head/sys/compat/linux/linux.h
==============================================================================
--- head/sys/compat/linux/linux.h       Tue Nov  3 19:14:03 2020        
(r367302)
+++ head/sys/compat/linux/linux.h       Tue Nov  3 19:50:42 2020        
(r367303)
@@ -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

Modified: head/sys/compat/linux/linux_socket.c
==============================================================================
--- head/sys/compat/linux/linux_socket.c        Tue Nov  3 19:14:03 2020        
(r367302)
+++ head/sys/compat/linux/linux_socket.c        Tue Nov  3 19:50:42 2020        
(r367303)
@@ -502,6 +502,17 @@ goout:
        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_ar
                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);
        }
 
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to