summaryrefslogtreecommitdiff
path: root/source4/lib/socket
diff options
context:
space:
mode:
Diffstat (limited to 'source4/lib/socket')
-rw-r--r--source4/lib/socket/access.c1
-rw-r--r--source4/lib/socket/config.m418
-rw-r--r--source4/lib/socket/config.mk43
-rw-r--r--source4/lib/socket/connect_multi.c48
-rw-r--r--source4/lib/socket/interface.c3
-rw-r--r--source4/lib/socket/netif.c3
-rw-r--r--source4/lib/socket/socket.c84
-rw-r--r--source4/lib/socket/socket.h11
-rw-r--r--source4/lib/socket/socket_ip.c3
-rw-r--r--source4/lib/socket/testsuite.c7
-rw-r--r--source4/lib/socket/wscript_build29
11 files changed, 153 insertions, 97 deletions
diff --git a/source4/lib/socket/access.c b/source4/lib/socket/access.c
index 42c42db365..ab39d63ef5 100644
--- a/source4/lib/socket/access.c
+++ b/source4/lib/socket/access.c
@@ -34,6 +34,7 @@
#include "system/network.h"
#include "lib/socket/socket.h"
#include "system/locale.h"
+#include "lib/util/util_net.h"
#define FAIL (-1)
#define ALLONES ((uint32_t)0xFFFFFFFF)
diff --git a/source4/lib/socket/config.m4 b/source4/lib/socket/config.m4
deleted file mode 100644
index fa987a1f46..0000000000
--- a/source4/lib/socket/config.m4
+++ /dev/null
@@ -1,18 +0,0 @@
-AC_CHECK_FUNCS(writev)
-AC_CHECK_FUNCS(readv)
-
-############################################
-# check for unix domain sockets
-# done by AC_LIBREPLACE_NETWORK_CHECKS
-SMB_ENABLE(socket_unix, NO)
-if test x"$libreplace_cv_HAVE_UNIXSOCKET" = x"yes"; then
- SMB_ENABLE(socket_unix, YES)
-fi
-
-############################################
-# check for ipv6
-# done by AC_LIBREPLACE_NETWORK_CHECKS
-SMB_ENABLE(socket_ipv6, NO)
-if test x"$libreplace_cv_HAVE_IPV6" = x"yes"; then
- SMB_ENABLE(socket_ipv6, YES)
-fi
diff --git a/source4/lib/socket/config.mk b/source4/lib/socket/config.mk
deleted file mode 100644
index ac515c8f6d..0000000000
--- a/source4/lib/socket/config.mk
+++ /dev/null
@@ -1,43 +0,0 @@
-##############################
-# Start SUBSYSTEM LIBNETIF
-[SUBSYSTEM::LIBNETIF]
-PRIVATE_DEPENDENCIES = LIBSAMBA-UTIL LIBREPLACE_NETWORK
-# End SUBSYSTEM LIBNETIF
-##############################
-
-LIBNETIF_OBJ_FILES = $(addprefix $(libsocketsrcdir)/, interface.o netif.o)
-
-$(eval $(call proto_header_template,$(libsocketsrcdir)/netif_proto.h,$(LIBNETIF_OBJ_FILES:.o=.c)))
-
-################################################
-# Start MODULE socket_ip
-[MODULE::socket_ip]
-SUBSYSTEM = samba_socket
-OUTPUT_TYPE = MERGED_OBJ
-PRIVATE_DEPENDENCIES = LIBSAMBA-ERRORS LIBREPLACE_NETWORK
-# End MODULE socket_ip
-################################################
-
-socket_ip_OBJ_FILES = $(libsocketsrcdir)/socket_ip.o
-
-################################################
-# Start MODULE socket_unix
-[MODULE::socket_unix]
-SUBSYSTEM = samba_socket
-OUTPUT_TYPE = MERGED_OBJ
-PRIVATE_DEPENDENCIES = LIBREPLACE_NETWORK
-# End MODULE socket_unix
-################################################
-
-socket_unix_OBJ_FILES = $(libsocketsrcdir)/socket_unix.o
-
-################################################
-# Start SUBSYSTEM SOCKET
-[SUBSYSTEM::samba_socket]
-PUBLIC_DEPENDENCIES = LIBTALLOC
-PRIVATE_DEPENDENCIES = SOCKET_WRAPPER LIBCLI_COMPOSITE LIBCLI_RESOLVE
-# End SUBSYSTEM SOCKET
-################################################
-
-samba_socket_OBJ_FILES = $(addprefix $(libsocketsrcdir)/, socket.o access.o connect_multi.o connect.o)
-
diff --git a/source4/lib/socket/connect_multi.c b/source4/lib/socket/connect_multi.c
index 68386ba565..300e5fb1e5 100644
--- a/source4/lib/socket/connect_multi.c
+++ b/source4/lib/socket/connect_multi.c
@@ -33,7 +33,7 @@
overall state
*/
struct connect_multi_state {
- const char *server_address;
+ struct socket_address *server_address;
int num_ports;
uint16_t *ports;
@@ -64,7 +64,7 @@ static void continue_one(struct composite_context *creq);
*/
_PUBLIC_ struct composite_context *socket_connect_multi_send(
TALLOC_CTX *mem_ctx,
- const char *server_address,
+ const char *server_name,
int num_server_ports,
uint16_t *server_ports,
struct resolve_context *resolve_ctx,
@@ -74,6 +74,9 @@ _PUBLIC_ struct composite_context *socket_connect_multi_send(
struct connect_multi_state *multi;
int i;
+ struct nbt_name name;
+ struct composite_context *creq;
+
result = talloc_zero(mem_ctx, struct composite_context);
if (result == NULL) return NULL;
result->state = COMPOSITE_STATE_IN_PROGRESS;
@@ -83,9 +86,6 @@ _PUBLIC_ struct composite_context *socket_connect_multi_send(
if (composite_nomem(multi, result)) goto failed;
result->private_data = multi;
- multi->server_address = talloc_strdup(multi, server_address);
- if (composite_nomem(multi->server_address, result)) goto failed;
-
multi->num_ports = num_server_ports;
multi->ports = talloc_array(multi, uint16_t, multi->num_ports);
if (composite_nomem(multi->ports, result)) goto failed;
@@ -94,30 +94,21 @@ _PUBLIC_ struct composite_context *socket_connect_multi_send(
multi->ports[i] = server_ports[i];
}
- if (!is_ipaddress(server_address)) {
- /*
- we don't want to do the name resolution separately
+ /*
+ we don't want to do the name resolution separately
for each port, so start it now, then only start on
the real sockets once we have an IP
- */
- struct nbt_name name;
- struct composite_context *creq;
- make_nbt_name_server(&name, server_address);
- creq = resolve_name_send(resolve_ctx, multi, &name, result->event_ctx);
- if (composite_nomem(creq, result)) goto failed;
- composite_continue(result, creq, continue_resolve_name, result);
- return result;
- }
+ */
+ make_nbt_name_server(&name, server_name);
- /* now we've setup the state we can process the first socket */
- connect_multi_next_socket(result);
+ creq = resolve_name_all_send(resolve_ctx, multi, 0, multi->ports[0], &name, result->event_ctx);
+ if (composite_nomem(creq, result)) goto failed;
- if (!NT_STATUS_IS_OK(result->status)) {
- goto failed;
- }
+ composite_continue(result, creq, continue_resolve_name, result);
return result;
+
failed:
composite_error(result, result->status);
return result;
@@ -148,11 +139,11 @@ static void connect_multi_next_socket(struct composite_context *result)
result->status = socket_create("ipv4", SOCKET_TYPE_STREAM, &state->sock, 0);
if (!composite_is_ok(result)) return;
- /* Form up the particular address we are interested in */
- state->addr = socket_address_from_strings(state, state->sock->backend_name,
- multi->server_address, multi->ports[next]);
+ state->addr = socket_address_copy(state, multi->server_address);
if (composite_nomem(state->addr, result)) return;
+ socket_address_set_port(state->addr, multi->ports[next]);
+
talloc_steal(state, state->sock);
creq = socket_connect_send(state->sock, NULL,
@@ -197,12 +188,13 @@ static void continue_resolve_name(struct composite_context *creq)
struct composite_context);
struct connect_multi_state *multi = talloc_get_type(result->private_data,
struct connect_multi_state);
- const char *addr;
+ struct socket_address **addr;
- result->status = resolve_name_recv(creq, multi, &addr);
+ result->status = resolve_name_all_recv(creq, multi, &addr, NULL);
if (!composite_is_ok(result)) return;
- multi->server_address = addr;
+ /* Let's just go for the first for now */
+ multi->server_address = addr[0];
connect_multi_next_socket(result);
}
diff --git a/source4/lib/socket/interface.c b/source4/lib/socket/interface.c
index af81804911..c4411b623c 100644
--- a/source4/lib/socket/interface.c
+++ b/source4/lib/socket/interface.c
@@ -22,6 +22,7 @@
#include "includes.h"
#include "system/network.h"
#include "lib/socket/netif.h"
+#include "../lib/util/util_net.h"
#include "../lib/util/dlinklist.h"
/** used for network interfaces */
@@ -93,7 +94,7 @@ static void add_interface(TALLOC_CTX *mem_ctx, struct in_addr ip, struct in_addr
DLIST_ADD_END(*interfaces, iface, struct interface *);
- DEBUG(2,("added interface ip=%s nmask=%s\n", iface->ip_s, iface->nmask_s));
+ DEBUG(3,("added interface ip=%s nmask=%s\n", iface->ip_s, iface->nmask_s));
}
diff --git a/source4/lib/socket/netif.c b/source4/lib/socket/netif.c
index bf410af441..e36f268bde 100644
--- a/source4/lib/socket/netif.c
+++ b/source4/lib/socket/netif.c
@@ -34,6 +34,7 @@
#include "includes.h"
#include "system/network.h"
#include "netif.h"
+#include "lib/util/tsort.h"
/****************************************************************************
Try the "standard" getifaddrs/freeifaddrs interfaces.
@@ -109,7 +110,7 @@ int get_interfaces(struct iface_struct *ifaces, int max_interfaces)
if (total <= 0) return total;
/* now we need to remove duplicates */
- qsort(ifaces, total, sizeof(ifaces[0]), QSORT_CAST iface_comp);
+ TYPESAFE_QSORT(ifaces, total, iface_comp);
for (i=1;i<total;) {
if (iface_comp(&ifaces[i-1], &ifaces[i]) == 0) {
diff --git a/source4/lib/socket/socket.c b/source4/lib/socket/socket.c
index 8e2f1683f2..4b5cecab34 100644
--- a/source4/lib/socket/socket.c
+++ b/source4/lib/socket/socket.c
@@ -24,6 +24,8 @@
#include "system/filesys.h"
#include "system/network.h"
#include "param/param.h"
+#include "../lib/tsocket/tsocket.h"
+#include "lib/util/util_net.h"
/*
auto-close sockets on free
@@ -344,6 +346,88 @@ _PUBLIC_ struct socket_address *socket_get_my_addr(struct socket_context *sock,
return sock->ops->fn_get_my_addr(sock, mem_ctx);
}
+_PUBLIC_ struct tsocket_address *socket_address_to_tsocket_address(TALLOC_CTX *mem_ctx,
+ const struct socket_address *a)
+{
+ struct tsocket_address *r;
+ int ret;
+
+ if (a->sockaddr) {
+ ret = tsocket_address_bsd_from_sockaddr(mem_ctx,
+ a->sockaddr,
+ a->sockaddrlen,
+ &r);
+ } else {
+ ret = tsocket_address_inet_from_strings(mem_ctx,
+ a->family,
+ a->addr,
+ a->port,
+ &r);
+ }
+
+ if (ret != 0) {
+ return NULL;
+ }
+
+ return r;
+}
+
+_PUBLIC_ void socket_address_set_port(struct socket_address *a,
+ uint16_t port)
+{
+ if (a->sockaddr) {
+ set_sockaddr_port(a->sockaddr, port);
+ } else {
+ a->port = port;
+ }
+
+}
+
+_PUBLIC_ struct socket_address *tsocket_address_to_socket_address(TALLOC_CTX *mem_ctx,
+ const struct tsocket_address *a)
+{
+ ssize_t ret;
+ struct sockaddr_storage ss;
+ size_t sslen = sizeof(ss);
+
+ ret = tsocket_address_bsd_sockaddr(a, (struct sockaddr *)(void *)&ss, sslen);
+ if (ret < 0) {
+ return NULL;
+ }
+
+ return socket_address_from_sockaddr(mem_ctx, (struct sockaddr *)(void *)&ss, ret);
+}
+
+_PUBLIC_ struct tsocket_address *socket_get_remote_addr(struct socket_context *sock, TALLOC_CTX *mem_ctx)
+{
+ struct socket_address *a;
+ struct tsocket_address *r;
+
+ a = socket_get_peer_addr(sock, mem_ctx);
+ if (a == NULL) {
+ return NULL;
+ }
+
+ r = socket_address_to_tsocket_address(mem_ctx, a);
+ talloc_free(a);
+ return r;
+}
+
+_PUBLIC_ struct tsocket_address *socket_get_local_addr(struct socket_context *sock, TALLOC_CTX *mem_ctx)
+{
+ struct socket_address *a;
+ struct tsocket_address *r;
+
+ a = socket_get_my_addr(sock, mem_ctx);
+ if (a == NULL) {
+ return NULL;
+ }
+
+ r = socket_address_to_tsocket_address(mem_ctx, a);
+ talloc_free(a);
+ return r;
+}
+
_PUBLIC_ int socket_get_fd(struct socket_context *sock)
{
if (!sock->ops->fn_get_fd) {
diff --git a/source4/lib/socket/socket.h b/source4/lib/socket/socket.h
index 0f469e5ceb..4a744797b3 100644
--- a/source4/lib/socket/socket.h
+++ b/source4/lib/socket/socket.h
@@ -127,6 +127,7 @@ struct socket_context {
};
struct resolve_context;
+struct tsocket_address;
/* prototypes */
NTSTATUS socket_create_with_ops(TALLOC_CTX *mem_ctx, const struct socket_ops *ops,
@@ -158,6 +159,12 @@ NTSTATUS socket_set_option(struct socket_context *sock, const char *option, cons
char *socket_get_peer_name(struct socket_context *sock, TALLOC_CTX *mem_ctx);
struct socket_address *socket_get_peer_addr(struct socket_context *sock, TALLOC_CTX *mem_ctx);
struct socket_address *socket_get_my_addr(struct socket_context *sock, TALLOC_CTX *mem_ctx);
+struct tsocket_address *socket_address_to_tsocket_address(TALLOC_CTX *mem_ctx,
+ const struct socket_address *a);
+struct socket_address *tsocket_address_to_socket_address(TALLOC_CTX *mem_ctx,
+ const struct tsocket_address *a);
+struct tsocket_address *socket_get_remote_addr(struct socket_context *sock, TALLOC_CTX *mem_ctx);
+struct tsocket_address *socket_get_local_addr(struct socket_context *sock, TALLOC_CTX *mem_ctx);
int socket_get_fd(struct socket_context *sock);
NTSTATUS socket_dup(struct socket_context *sock);
struct socket_address *socket_address_from_strings(TALLOC_CTX *mem_ctx,
@@ -167,6 +174,8 @@ struct socket_address *socket_address_from_strings(TALLOC_CTX *mem_ctx,
struct socket_address *socket_address_from_sockaddr(TALLOC_CTX *mem_ctx,
struct sockaddr *sockaddr,
size_t addrlen);
+_PUBLIC_ void socket_address_set_port(struct socket_address *a,
+ uint16_t port);
struct socket_address *socket_address_copy(TALLOC_CTX *mem_ctx,
const struct socket_address *oaddr);
const struct socket_ops *socket_getops_byname(const char *name, enum socket_type type);
@@ -206,7 +215,7 @@ NTSTATUS socket_connect_multi(TALLOC_CTX *mem_ctx, const char *server_address,
struct socket_context **result,
uint16_t *port);
void set_socket_options(int fd, const char *options);
-void socket_set_flags(struct socket_context *socket, unsigned flags);
+void socket_set_flags(struct socket_context *sock, unsigned flags);
void socket_tevent_fd_close_fn(struct tevent_context *ev,
struct tevent_fd *fde,
diff --git a/source4/lib/socket/socket_ip.c b/source4/lib/socket/socket_ip.c
index 89b310a23a..9a02f0184c 100644
--- a/source4/lib/socket/socket_ip.c
+++ b/source4/lib/socket/socket_ip.c
@@ -25,6 +25,7 @@
#include "system/filesys.h"
#include "lib/socket/socket.h"
#include "system/network.h"
+#include "lib/util/util_net.h"
static NTSTATUS ipv4_init(struct socket_context *sock)
{
@@ -711,7 +712,7 @@ static NTSTATUS ipv6_listen(struct socket_context *sock,
static NTSTATUS ipv6_tcp_accept(struct socket_context *sock, struct socket_context **new_sock)
{
- struct sockaddr_in cli_addr;
+ struct sockaddr_in6 cli_addr;
socklen_t cli_addr_len = sizeof(cli_addr);
int new_fd;
diff --git a/source4/lib/socket/testsuite.c b/source4/lib/socket/testsuite.c
index cba283f558..2489277433 100644
--- a/source4/lib/socket/testsuite.c
+++ b/source4/lib/socket/testsuite.c
@@ -42,7 +42,7 @@ static bool test_udp(struct torture_context *tctx)
TALLOC_CTX *mem_ctx = tctx;
struct interface *ifaces;
- load_interfaces(tctx, lp_interfaces(tctx->lp_ctx), &ifaces);
+ load_interfaces(tctx, lpcfg_interfaces(tctx->lp_ctx), &ifaces);
status = socket_create("ip", SOCKET_TYPE_DGRAM, &sock1, 0);
torture_assert_ntstatus_ok(tctx, status, "creating DGRAM IP socket 1");
@@ -135,7 +135,7 @@ static bool test_tcp(struct torture_context *tctx)
torture_assert_ntstatus_ok(tctx, status, "creating IP stream socket 1");
talloc_steal(mem_ctx, sock2);
- load_interfaces(tctx, lp_interfaces(tctx->lp_ctx), &ifaces);
+ load_interfaces(tctx, lpcfg_interfaces(tctx->lp_ctx), &ifaces);
localhost = socket_address_from_strings(sock1, sock1->backend_name,
iface_best_ip(ifaces, "127.0.0.1"), 0);
torture_assert(tctx, localhost, "Localhost not found");
@@ -188,8 +188,7 @@ static bool test_tcp(struct torture_context *tctx)
struct torture_suite *torture_local_socket(TALLOC_CTX *mem_ctx)
{
- struct torture_suite *suite = torture_suite_create(mem_ctx,
- "SOCKET");
+ struct torture_suite *suite = torture_suite_create(mem_ctx, "socket");
torture_suite_add_simple_test(suite, "udp", test_udp);
torture_suite_add_simple_test(suite, "tcp", test_tcp);
diff --git a/source4/lib/socket/wscript_build b/source4/lib/socket/wscript_build
new file mode 100644
index 0000000000..e2ff9b078a
--- /dev/null
+++ b/source4/lib/socket/wscript_build
@@ -0,0 +1,29 @@
+#!/usr/bin/env python
+
+bld.SAMBA_LIBRARY('netif',
+ source='interface.c netif.c',
+ autoproto='netif_proto.h',
+ deps='samba-util',
+ private_library=True
+ )
+
+bld.SAMBA_MODULE('socket_ip',
+ source='socket_ip.c',
+ subsystem='samba_socket',
+ deps='errors',
+ internal_module=True
+ )
+
+bld.SAMBA_MODULE('socket_unix',
+ source='socket_unix.c',
+ subsystem='samba_socket',
+ deps='talloc',
+ internal_module=True
+ )
+
+bld.SAMBA_SUBSYSTEM('samba_socket',
+ source='socket.c access.c connect_multi.c connect.c',
+ public_deps='talloc LIBTSOCKET',
+ deps='LIBCLI_COMPOSITE LIBCLI_RESOLVE socket_ip socket_unix'
+ )
+