bpf_trace_filter: support bpf filter optimization and dump
[vpp.git] / src / vppinfra / socket.c
index ef0eaae..2abf2b2 100644 (file)
@@ -226,7 +226,7 @@ static clib_error_t *
 default_socket_recvmsg (clib_socket_t * s, void *msg, int msglen,
                        int fds[], int num_fds)
 {
-#ifdef CLIB_LINUX
+#if CLIB_LINUX
   char ctl[CMSG_SPACE (sizeof (int) * num_fds) +
           CMSG_SPACE (sizeof (struct ucred))];
   struct ucred *cr = 0;
@@ -261,7 +261,7 @@ default_socket_recvmsg (clib_socket_t * s, void *msg, int msglen,
     {
       if (cmsg->cmsg_level == SOL_SOCKET)
        {
-#ifdef CLIB_LINUX
+#if CLIB_LINUX
          if (cmsg->cmsg_type == SCM_CREDENTIALS)
            {
              cr = (struct ucred *) CMSG_DATA (cmsg);
@@ -314,11 +314,13 @@ static const struct
     .family = AF_INET,
     .type = CLIB_SOCKET_TYPE_INET,
     .skip_prefix = 1 },
+#if CLIB_LINUX
   { .prefix = "abstract:",
     .family = AF_UNIX,
     .type = CLIB_SOCKET_TYPE_LINUX_ABSTRACT,
     .skip_prefix = 1,
     .is_local = 1 },
+#endif /* CLIB_LINUX */
   { .prefix = "/",
     .family = AF_UNIX,
     .type = CLIB_SOCKET_TYPE_UNIX,
@@ -671,11 +673,24 @@ clib_socket_init (clib_socket_t *s)
        }
 #endif
 
-      if (need_bind && bind (s->fd, sa, addr_len) < 0)
+      if (need_bind)
        {
-         err =
-           clib_error_return_unix (0, "bind (fd %d, '%s')", s->fd, s->config);
-         goto done;
+         int bind_ret;
+         if (sa->sa_family == AF_UNIX && s->allow_group_write)
+           {
+             mode_t def_restrictions = umask (S_IWOTH);
+             bind_ret = bind (s->fd, sa, addr_len);
+             umask (def_restrictions);
+           }
+         else
+           bind_ret = bind (s->fd, sa, addr_len);
+
+         if (bind_ret < 0)
+           {
+             err = clib_error_return_unix (0, "bind (fd %d, '%s')", s->fd,
+                                           s->config);
+             goto done;
+           }
        }
 
       if (listen (s->fd, 5) < 0)
@@ -684,16 +699,6 @@ clib_socket_init (clib_socket_t *s)
                                        s->config);
          goto done;
        }
-
-      if (s->local_only && s->allow_group_write)
-       {
-         if (fchmod (s->fd, S_IWGRP) < 0)
-           {
-             err = clib_error_return_unix (
-               0, "fchmod (fd %d, '%s', mode S_IWGRP)", s->fd, s->config);
-             goto done;
-           }
-       }
     }
   else
     {
@@ -732,7 +737,7 @@ done:
 #if CLIB_LINUX
   if (netns_fd != -1)
     {
-      setns (CLONE_NEWNET, netns_fd);
+      setns (netns_fd, CLONE_NEWNET);
       close (netns_fd);
     }
 #endif