lib/util Move set_socket_options() into common code.
authorAndrew Bartlett <abartlet@samba.org>
Mon, 2 May 2011 06:23:40 +0000 (16:23 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 3 May 2011 05:37:07 +0000 (07:37 +0200)
lib/util/util_net.c
lib/util/util_net.h
source3/lib/util_sock.c
source4/lib/socket/socket.c

index e80447128f41bf42e6af2f6e117afbaaaecc89aa..a8a05da1383b267430d77f89a48ca9de836d445f 100644 (file)
@@ -695,3 +695,164 @@ const char *client_socket_addr(int fd, char *addr, size_t addr_len)
 {
        return get_socket_addr(fd, addr, addr_len);
 }
+
+
+enum SOCK_OPT_TYPES {OPT_BOOL,OPT_INT,OPT_ON};
+
+typedef struct smb_socket_option {
+       const char *name;
+       int level;
+       int option;
+       int value;
+       int opttype;
+} smb_socket_option;
+
+static const smb_socket_option socket_options[] = {
+  {"SO_KEEPALIVE", SOL_SOCKET, SO_KEEPALIVE, 0, OPT_BOOL},
+  {"SO_REUSEADDR", SOL_SOCKET, SO_REUSEADDR, 0, OPT_BOOL},
+  {"SO_BROADCAST", SOL_SOCKET, SO_BROADCAST, 0, OPT_BOOL},
+#ifdef TCP_NODELAY
+  {"TCP_NODELAY", IPPROTO_TCP, TCP_NODELAY, 0, OPT_BOOL},
+#endif
+#ifdef TCP_KEEPCNT
+  {"TCP_KEEPCNT", IPPROTO_TCP, TCP_KEEPCNT, 0, OPT_INT},
+#endif
+#ifdef TCP_KEEPIDLE
+  {"TCP_KEEPIDLE", IPPROTO_TCP, TCP_KEEPIDLE, 0, OPT_INT},
+#endif
+#ifdef TCP_KEEPINTVL
+  {"TCP_KEEPINTVL", IPPROTO_TCP, TCP_KEEPINTVL, 0, OPT_INT},
+#endif
+#ifdef IPTOS_LOWDELAY
+  {"IPTOS_LOWDELAY", IPPROTO_IP, IP_TOS, IPTOS_LOWDELAY, OPT_ON},
+#endif
+#ifdef IPTOS_THROUGHPUT
+  {"IPTOS_THROUGHPUT", IPPROTO_IP, IP_TOS, IPTOS_THROUGHPUT, OPT_ON},
+#endif
+#ifdef SO_REUSEPORT
+  {"SO_REUSEPORT", SOL_SOCKET, SO_REUSEPORT, 0, OPT_BOOL},
+#endif
+#ifdef SO_SNDBUF
+  {"SO_SNDBUF", SOL_SOCKET, SO_SNDBUF, 0, OPT_INT},
+#endif
+#ifdef SO_RCVBUF
+  {"SO_RCVBUF", SOL_SOCKET, SO_RCVBUF, 0, OPT_INT},
+#endif
+#ifdef SO_SNDLOWAT
+  {"SO_SNDLOWAT", SOL_SOCKET, SO_SNDLOWAT, 0, OPT_INT},
+#endif
+#ifdef SO_RCVLOWAT
+  {"SO_RCVLOWAT", SOL_SOCKET, SO_RCVLOWAT, 0, OPT_INT},
+#endif
+#ifdef SO_SNDTIMEO
+  {"SO_SNDTIMEO", SOL_SOCKET, SO_SNDTIMEO, 0, OPT_INT},
+#endif
+#ifdef SO_RCVTIMEO
+  {"SO_RCVTIMEO", SOL_SOCKET, SO_RCVTIMEO, 0, OPT_INT},
+#endif
+#ifdef TCP_FASTACK
+  {"TCP_FASTACK", IPPROTO_TCP, TCP_FASTACK, 0, OPT_INT},
+#endif
+#ifdef TCP_QUICKACK
+  {"TCP_QUICKACK", IPPROTO_TCP, TCP_QUICKACK, 0, OPT_BOOL},
+#endif
+#ifdef TCP_KEEPALIVE_THRESHOLD
+  {"TCP_KEEPALIVE_THRESHOLD", IPPROTO_TCP, TCP_KEEPALIVE_THRESHOLD, 0, OPT_INT},
+#endif
+#ifdef TCP_KEEPALIVE_ABORT_THRESHOLD
+  {"TCP_KEEPALIVE_ABORT_THRESHOLD", IPPROTO_TCP, TCP_KEEPALIVE_ABORT_THRESHOLD, 0, OPT_INT},
+#endif
+  {NULL,0,0,0,0}};
+
+/****************************************************************************
+ Print socket options.
+****************************************************************************/
+
+static void print_socket_options(int s)
+{
+       int value;
+       socklen_t vlen = 4;
+       const smb_socket_option *p = &socket_options[0];
+
+       /* wrapped in if statement to prevent streams
+        * leak in SCO Openserver 5.0 */
+       /* reported on samba-technical  --jerry */
+       if ( DEBUGLEVEL >= 5 ) {
+               DEBUG(5,("Socket options:\n"));
+               for (; p->name != NULL; p++) {
+                       if (getsockopt(s, p->level, p->option,
+                                               (void *)&value, &vlen) == -1) {
+                               DEBUGADD(5,("\tCould not test socket option %s.\n",
+                                                       p->name));
+                       } else {
+                               DEBUGADD(5,("\t%s = %d\n",
+                                                       p->name,value));
+                       }
+               }
+       }
+ }
+
+/****************************************************************************
+ Set user socket options.
+****************************************************************************/
+
+void set_socket_options(int fd, const char *options)
+{
+       TALLOC_CTX *ctx = talloc_new(NULL);
+       char *tok;
+
+       while (next_token_talloc(ctx, &options, &tok," \t,")) {
+               int ret=0,i;
+               int value = 1;
+               char *p;
+               bool got_value = false;
+
+               if ((p = strchr_m(tok,'='))) {
+                       *p = 0;
+                       value = atoi(p+1);
+                       got_value = true;
+               }
+
+               for (i=0;socket_options[i].name;i++)
+                       if (strequal(socket_options[i].name,tok))
+                               break;
+
+               if (!socket_options[i].name) {
+                       DEBUG(0,("Unknown socket option %s\n",tok));
+                       continue;
+               }
+
+               switch (socket_options[i].opttype) {
+               case OPT_BOOL:
+               case OPT_INT:
+                       ret = setsockopt(fd,socket_options[i].level,
+                                       socket_options[i].option,
+                                       (char *)&value,sizeof(int));
+                       break;
+
+               case OPT_ON:
+                       if (got_value)
+                               DEBUG(0,("syntax error - %s "
+                                       "does not take a value\n",tok));
+
+                       {
+                               int on = socket_options[i].value;
+                               ret = setsockopt(fd,socket_options[i].level,
+                                       socket_options[i].option,
+                                       (char *)&on,sizeof(int));
+                       }
+                       break;
+               }
+
+               if (ret != 0) {
+                       /* be aware that some systems like Solaris return
+                        * EINVAL to a setsockopt() call when the client
+                        * sent a RST previously - no need to worry */
+                       DEBUG(2,("Failed to set socket option %s (Error %s)\n",
+                               tok, strerror(errno) ));
+               }
+       }
+
+       TALLOC_FREE(ctx);
+       print_socket_options(fd);
+}
index 71d1d1a6bd0b207687d64a1b1216ddc041573ed3..38b6d5a959d221faf040dd44671678b84cffa54d 100644 (file)
@@ -108,4 +108,6 @@ const char *client_name(int fd);
 int get_socket_port(int fd);
 const char *client_socket_addr(int fd, char *addr, size_t addr_len);
 
+void set_socket_options(int fd, const char *options);
+
 #endif /* _SAMBA_UTIL_NET_H_ */
index fa718590d7e8b9628a400ae565df4943619afa37..0e1bfc04d11530bc3626b0ecaf44795afc20dc67 100644 (file)
@@ -78,166 +78,6 @@ bool is_a_socket(int fd)
        return(getsockopt(fd, SOL_SOCKET, SO_TYPE, (char *)&v, &l) == 0);
 }
 
-enum SOCK_OPT_TYPES {OPT_BOOL,OPT_INT,OPT_ON};
-
-typedef struct smb_socket_option {
-       const char *name;
-       int level;
-       int option;
-       int value;
-       int opttype;
-} smb_socket_option;
-
-static const smb_socket_option socket_options[] = {
-  {"SO_KEEPALIVE", SOL_SOCKET, SO_KEEPALIVE, 0, OPT_BOOL},
-  {"SO_REUSEADDR", SOL_SOCKET, SO_REUSEADDR, 0, OPT_BOOL},
-  {"SO_BROADCAST", SOL_SOCKET, SO_BROADCAST, 0, OPT_BOOL},
-#ifdef TCP_NODELAY
-  {"TCP_NODELAY", IPPROTO_TCP, TCP_NODELAY, 0, OPT_BOOL},
-#endif
-#ifdef TCP_KEEPCNT
-  {"TCP_KEEPCNT", IPPROTO_TCP, TCP_KEEPCNT, 0, OPT_INT},
-#endif
-#ifdef TCP_KEEPIDLE
-  {"TCP_KEEPIDLE", IPPROTO_TCP, TCP_KEEPIDLE, 0, OPT_INT},
-#endif
-#ifdef TCP_KEEPINTVL
-  {"TCP_KEEPINTVL", IPPROTO_TCP, TCP_KEEPINTVL, 0, OPT_INT},
-#endif
-#ifdef IPTOS_LOWDELAY
-  {"IPTOS_LOWDELAY", IPPROTO_IP, IP_TOS, IPTOS_LOWDELAY, OPT_ON},
-#endif
-#ifdef IPTOS_THROUGHPUT
-  {"IPTOS_THROUGHPUT", IPPROTO_IP, IP_TOS, IPTOS_THROUGHPUT, OPT_ON},
-#endif
-#ifdef SO_REUSEPORT
-  {"SO_REUSEPORT", SOL_SOCKET, SO_REUSEPORT, 0, OPT_BOOL},
-#endif
-#ifdef SO_SNDBUF
-  {"SO_SNDBUF", SOL_SOCKET, SO_SNDBUF, 0, OPT_INT},
-#endif
-#ifdef SO_RCVBUF
-  {"SO_RCVBUF", SOL_SOCKET, SO_RCVBUF, 0, OPT_INT},
-#endif
-#ifdef SO_SNDLOWAT
-  {"SO_SNDLOWAT", SOL_SOCKET, SO_SNDLOWAT, 0, OPT_INT},
-#endif
-#ifdef SO_RCVLOWAT
-  {"SO_RCVLOWAT", SOL_SOCKET, SO_RCVLOWAT, 0, OPT_INT},
-#endif
-#ifdef SO_SNDTIMEO
-  {"SO_SNDTIMEO", SOL_SOCKET, SO_SNDTIMEO, 0, OPT_INT},
-#endif
-#ifdef SO_RCVTIMEO
-  {"SO_RCVTIMEO", SOL_SOCKET, SO_RCVTIMEO, 0, OPT_INT},
-#endif
-#ifdef TCP_FASTACK
-  {"TCP_FASTACK", IPPROTO_TCP, TCP_FASTACK, 0, OPT_INT},
-#endif
-#ifdef TCP_QUICKACK
-  {"TCP_QUICKACK", IPPROTO_TCP, TCP_QUICKACK, 0, OPT_BOOL},
-#endif
-#ifdef TCP_KEEPALIVE_THRESHOLD
-  {"TCP_KEEPALIVE_THRESHOLD", IPPROTO_TCP, TCP_KEEPALIVE_THRESHOLD, 0, OPT_INT},
-#endif
-#ifdef TCP_KEEPALIVE_ABORT_THRESHOLD
-  {"TCP_KEEPALIVE_ABORT_THRESHOLD", IPPROTO_TCP, TCP_KEEPALIVE_ABORT_THRESHOLD, 0, OPT_INT},
-#endif
-  {NULL,0,0,0,0}};
-
-/****************************************************************************
- Print socket options.
-****************************************************************************/
-
-static void print_socket_options(int s)
-{
-       int value;
-       socklen_t vlen = 4;
-       const smb_socket_option *p = &socket_options[0];
-
-       /* wrapped in if statement to prevent streams
-        * leak in SCO Openserver 5.0 */
-       /* reported on samba-technical  --jerry */
-       if ( DEBUGLEVEL >= 5 ) {
-               DEBUG(5,("Socket options:\n"));
-               for (; p->name != NULL; p++) {
-                       if (getsockopt(s, p->level, p->option,
-                                               (void *)&value, &vlen) == -1) {
-                               DEBUGADD(5,("\tCould not test socket option %s.\n",
-                                                       p->name));
-                       } else {
-                               DEBUGADD(5,("\t%s = %d\n",
-                                                       p->name,value));
-                       }
-               }
-       }
- }
-
-/****************************************************************************
- Set user socket options.
-****************************************************************************/
-
-void set_socket_options(int fd, const char *options)
-{
-       TALLOC_CTX *ctx = talloc_stackframe();
-       char *tok;
-
-       while (next_token_talloc(ctx, &options, &tok," \t,")) {
-               int ret=0,i;
-               int value = 1;
-               char *p;
-               bool got_value = false;
-
-               if ((p = strchr_m(tok,'='))) {
-                       *p = 0;
-                       value = atoi(p+1);
-                       got_value = true;
-               }
-
-               for (i=0;socket_options[i].name;i++)
-                       if (strequal(socket_options[i].name,tok))
-                               break;
-
-               if (!socket_options[i].name) {
-                       DEBUG(0,("Unknown socket option %s\n",tok));
-                       continue;
-               }
-
-               switch (socket_options[i].opttype) {
-               case OPT_BOOL:
-               case OPT_INT:
-                       ret = setsockopt(fd,socket_options[i].level,
-                                       socket_options[i].option,
-                                       (char *)&value,sizeof(int));
-                       break;
-
-               case OPT_ON:
-                       if (got_value)
-                               DEBUG(0,("syntax error - %s "
-                                       "does not take a value\n",tok));
-
-                       {
-                               int on = socket_options[i].value;
-                               ret = setsockopt(fd,socket_options[i].level,
-                                       socket_options[i].option,
-                                       (char *)&on,sizeof(int));
-                       }
-                       break;
-               }
-
-               if (ret != 0) {
-                       /* be aware that some systems like Solaris return
-                        * EINVAL to a setsockopt() call when the client
-                        * sent a RST previously - no need to worry */
-                       DEBUG(2,("Failed to set socket option %s (Error %s)\n",
-                               tok, strerror(errno) ));
-               }
-       }
-
-       TALLOC_FREE(ctx);
-       print_socket_options(fd);
-}
-
 /****************************************************************************
  Read from a socket.
 ****************************************************************************/
index a627fbe2a69fe20940717a03b68ed7f1ae3d4168..cecd1026d598951d32e5d1723dbbd950807d1518 100644 (file)
@@ -567,166 +567,6 @@ _PUBLIC_ const struct socket_ops *socket_getops_byname(const char *family, enum
        return NULL;
 }
 
-enum SOCK_OPT_TYPES {OPT_BOOL,OPT_INT,OPT_ON};
-
-typedef struct smb_socket_option {
-       const char *name;
-       int level;
-       int option;
-       int value;
-       int opttype;
-} smb_socket_option;
-
-static const smb_socket_option socket_options[] = {
-  {"SO_KEEPALIVE", SOL_SOCKET, SO_KEEPALIVE, 0, OPT_BOOL},
-  {"SO_REUSEADDR", SOL_SOCKET, SO_REUSEADDR, 0, OPT_BOOL},
-  {"SO_BROADCAST", SOL_SOCKET, SO_BROADCAST, 0, OPT_BOOL},
-#ifdef TCP_NODELAY
-  {"TCP_NODELAY", IPPROTO_TCP, TCP_NODELAY, 0, OPT_BOOL},
-#endif
-#ifdef TCP_KEEPCNT
-  {"TCP_KEEPCNT", IPPROTO_TCP, TCP_KEEPCNT, 0, OPT_INT},
-#endif
-#ifdef TCP_KEEPIDLE
-  {"TCP_KEEPIDLE", IPPROTO_TCP, TCP_KEEPIDLE, 0, OPT_INT},
-#endif
-#ifdef TCP_KEEPINTVL
-  {"TCP_KEEPINTVL", IPPROTO_TCP, TCP_KEEPINTVL, 0, OPT_INT},
-#endif
-#ifdef IPTOS_LOWDELAY
-  {"IPTOS_LOWDELAY", IPPROTO_IP, IP_TOS, IPTOS_LOWDELAY, OPT_ON},
-#endif
-#ifdef IPTOS_THROUGHPUT
-  {"IPTOS_THROUGHPUT", IPPROTO_IP, IP_TOS, IPTOS_THROUGHPUT, OPT_ON},
-#endif
-#ifdef SO_REUSEPORT
-  {"SO_REUSEPORT", SOL_SOCKET, SO_REUSEPORT, 0, OPT_BOOL},
-#endif
-#ifdef SO_SNDBUF
-  {"SO_SNDBUF", SOL_SOCKET, SO_SNDBUF, 0, OPT_INT},
-#endif
-#ifdef SO_RCVBUF
-  {"SO_RCVBUF", SOL_SOCKET, SO_RCVBUF, 0, OPT_INT},
-#endif
-#ifdef SO_SNDLOWAT
-  {"SO_SNDLOWAT", SOL_SOCKET, SO_SNDLOWAT, 0, OPT_INT},
-#endif
-#ifdef SO_RCVLOWAT
-  {"SO_RCVLOWAT", SOL_SOCKET, SO_RCVLOWAT, 0, OPT_INT},
-#endif
-#ifdef SO_SNDTIMEO
-  {"SO_SNDTIMEO", SOL_SOCKET, SO_SNDTIMEO, 0, OPT_INT},
-#endif
-#ifdef SO_RCVTIMEO
-  {"SO_RCVTIMEO", SOL_SOCKET, SO_RCVTIMEO, 0, OPT_INT},
-#endif
-#ifdef TCP_FASTACK
-  {"TCP_FASTACK", IPPROTO_TCP, TCP_FASTACK, 0, OPT_INT},
-#endif
-#ifdef TCP_QUICKACK
-  {"TCP_QUICKACK", IPPROTO_TCP, TCP_QUICKACK, 0, OPT_BOOL},
-#endif
-#ifdef TCP_KEEPALIVE_THRESHOLD
-  {"TCP_KEEPALIVE_THRESHOLD", IPPROTO_TCP, TCP_KEEPALIVE_THRESHOLD, 0, OPT_INT},
-#endif
-#ifdef TCP_KEEPALIVE_ABORT_THRESHOLD
-  {"TCP_KEEPALIVE_ABORT_THRESHOLD", IPPROTO_TCP, TCP_KEEPALIVE_ABORT_THRESHOLD, 0, OPT_INT},
-#endif
-  {NULL,0,0,0,0}};
-
-/****************************************************************************
- Print socket options.
-****************************************************************************/
-
-static void print_socket_options(int s)
-{
-       int value;
-       socklen_t vlen = 4;
-       const smb_socket_option *p = &socket_options[0];
-
-       /* wrapped in if statement to prevent streams
-        * leak in SCO Openserver 5.0 */
-       /* reported on samba-technical  --jerry */
-       if ( DEBUGLEVEL >= 5 ) {
-               DEBUG(5,("Socket options:\n"));
-               for (; p->name != NULL; p++) {
-                       if (getsockopt(s, p->level, p->option,
-                                               (void *)&value, &vlen) == -1) {
-                               DEBUGADD(5,("\tCould not test socket option %s.\n",
-                                                       p->name));
-                       } else {
-                               DEBUGADD(5,("\t%s = %d\n",
-                                                       p->name,value));
-                       }
-               }
-       }
- }
-
-/****************************************************************************
- Set user socket options.
-****************************************************************************/
-
-void set_socket_options(int fd, const char *options)
-{
-       TALLOC_CTX *ctx = talloc_new(NULL);
-       char *tok;
-
-       while (next_token_talloc(ctx, &options, &tok," \t,")) {
-               int ret=0,i;
-               int value = 1;
-               char *p;
-               bool got_value = false;
-
-               if ((p = strchr_m(tok,'='))) {
-                       *p = 0;
-                       value = atoi(p+1);
-                       got_value = true;
-               }
-
-               for (i=0;socket_options[i].name;i++)
-                       if (strequal(socket_options[i].name,tok))
-                               break;
-
-               if (!socket_options[i].name) {
-                       DEBUG(0,("Unknown socket option %s\n",tok));
-                       continue;
-               }
-
-               switch (socket_options[i].opttype) {
-               case OPT_BOOL:
-               case OPT_INT:
-                       ret = setsockopt(fd,socket_options[i].level,
-                                       socket_options[i].option,
-                                       (char *)&value,sizeof(int));
-                       break;
-
-               case OPT_ON:
-                       if (got_value)
-                               DEBUG(0,("syntax error - %s "
-                                       "does not take a value\n",tok));
-
-                       {
-                               int on = socket_options[i].value;
-                               ret = setsockopt(fd,socket_options[i].level,
-                                       socket_options[i].option,
-                                       (char *)&on,sizeof(int));
-                       }
-                       break;
-               }
-
-               if (ret != 0) {
-                       /* be aware that some systems like Solaris return
-                        * EINVAL to a setsockopt() call when the client
-                        * sent a RST previously - no need to worry */
-                       DEBUG(2,("Failed to set socket option %s (Error %s)\n",
-                               tok, strerror(errno) ));
-               }
-       }
-
-       TALLOC_FREE(ctx);
-       print_socket_options(fd);
-}
-
 /*
   set some flags on a socket 
  */