diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2015-01-27 16:39:30 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2015-01-27 16:39:30 -0600 |
commit | 61b664d452327affda4bc18e01aa97f8e9f1dcc1 (patch) | |
tree | cf48cd8f580c2e532b4d8ba0e1aba407845487ac | |
parent | 20190a89f724704d7a93e17163fbdfb1347b3aee (diff) | |
download | nuttx-61b664d452327affda4bc18e01aa97f8e9f1dcc1.tar.gz nuttx-61b664d452327affda4bc18e01aa97f8e9f1dcc1.tar.bz2 nuttx-61b664d452327affda4bc18e01aa97f8e9f1dcc1.zip |
Unix domain: A few fixes from early integration
-rw-r--r-- | apps/nshlib/nsh_netinit.c | 3 | ||||
-rw-r--r-- | nuttx/arch/sim/src/nuttx-names.dat | 2 | ||||
-rw-r--r-- | nuttx/net/local/local.h | 10 | ||||
-rw-r--r-- | nuttx/net/local/local_accept.c | 8 | ||||
-rw-r--r-- | nuttx/net/local/local_bind.c | 14 | ||||
-rw-r--r-- | nuttx/net/local/local_connect.c | 27 | ||||
-rw-r--r-- | nuttx/net/local/local_listen.c | 2 | ||||
-rw-r--r-- | nuttx/net/local/local_release.c | 4 | ||||
-rw-r--r-- | nuttx/net/socket/bind.c | 4 | ||||
-rw-r--r-- | nuttx/net/socket/connect.c | 12 | ||||
-rw-r--r-- | nuttx/net/socket/socket.c | 58 |
11 files changed, 104 insertions, 40 deletions
diff --git a/apps/nshlib/nsh_netinit.c b/apps/nshlib/nsh_netinit.c index 5a96aed6c..d2ea3520f 100644 --- a/apps/nshlib/nsh_netinit.c +++ b/apps/nshlib/nsh_netinit.c @@ -235,7 +235,8 @@ static void nsh_netinit_configure(void) /* Set the MAC address */ netlib_setmacaddr(NET_DEVNAME, mac); -#endif + +#endif /* CONFIG_NSH_NOMAC && CONFIG_NET_ETHERNET */ #ifdef CONFIG_NET_IPv4 /* Set up our host address */ diff --git a/nuttx/arch/sim/src/nuttx-names.dat b/nuttx/arch/sim/src/nuttx-names.dat index 9658cf644..bfd3c051c 100644 --- a/nuttx/arch/sim/src/nuttx-names.dat +++ b/nuttx/arch/sim/src/nuttx-names.dat @@ -1,3 +1,4 @@ +accept NXaccept calloc NXcalloc clock_gettime NXclock_gettime close NXclose @@ -13,6 +14,7 @@ fsync NXfsync gettimeofday NXgettimeofday ioctl NXioctl isatty NXisatty +listen NXlisten lseek NXlseek malloc NXmalloc malloc_init NXmalloc_init diff --git a/nuttx/net/local/local.h b/nuttx/net/local/local.h index f9b00382f..23a4ed8fe 100644 --- a/nuttx/net/local/local.h +++ b/nuttx/net/local/local.h @@ -128,7 +128,7 @@ struct local_conn_s /* Fields common to SOCK_STREAM and SOCK_DGRAM */ uint8_t lc_crefs; /* Reference counts on this instance */ - uint8_t lc_family; /* SOCK_STREAM or SOCK_DGRAM */ + uint8_t lc_proto; /* SOCK_STREAM or SOCK_DGRAM */ uint8_t lc_type; /* See enum local_type_e */ uint8_t lc_state; /* See enum local_state_e */ int16_t lc_infd; /* File descriptor of read-only FIFO (peers) */ @@ -228,7 +228,7 @@ FAR struct local_conn_s *local_alloc(void); void local_free(FAR struct local_conn_s *conn); /**************************************************************************** - * Name: local_bind + * Name: psock_local_bind * * Description: * This function implements the low-level parts of the standard local @@ -236,8 +236,8 @@ void local_free(FAR struct local_conn_s *conn); * ****************************************************************************/ -int local_bind(FAR struct local_conn_s *conn, - FAR const struct sockaddr *addr, socklen_t addrlen); +int psock_local_bind(FAR struct socket *psock, + FAR const struct sockaddr *addr, socklen_t addrlen); /**************************************************************************** * Name: local_connect @@ -246,7 +246,7 @@ int local_bind(FAR struct local_conn_s *conn, * This function sets up a new local connection. The function will * automatically allocate an unused local port for the new * connection. However, another port can be chosen by using the - * local_bind() call, after the local_connect() function has been + * psock_local_bind() call, after the local_connect() function has been * called. * * This function is called as part of the implementation of sendto diff --git a/nuttx/net/local/local_accept.c b/nuttx/net/local/local_accept.c index 1b6cbb9d3..2fd1b92d3 100644 --- a/nuttx/net/local/local_accept.c +++ b/nuttx/net/local/local_accept.c @@ -92,9 +92,9 @@ int psock_local_accept(FAR struct socket *psock, FAR struct sockaddr *addr, DEBUGASSERT(psock && psock->s_conn); server = (FAR struct local_conn_s *)psock->s_conn; - if (server->lc_family != SOCK_STREAM || + if (server->lc_proto != SOCK_STREAM || server->lc_state != LOCAL_STATE_LISTENING || - server->lc_type != LOCAL_TYPE_PATHNAME) + server->lc_type != LOCAL_TYPE_PATHNAME) { return -EOPNOTSUPP; } @@ -132,9 +132,9 @@ int psock_local_accept(FAR struct socket *psock, FAR struct sockaddr *addr, /* Initialize the new connection structure */ conn->lc_crefs = 1; - conn->lc_family = SOCK_STREAM; + conn->lc_proto = SOCK_STREAM; conn->lc_type = LOCAL_TYPE_PATHNAME; - conn->lc_state = LOCAL_STATE_CONNECTED; + conn->lc_state = LOCAL_STATE_CONNECTED; strncpy(conn->lc_path, client->lc_path, UNIX_PATH_MAX-1); conn->lc_path[UNIX_PATH_MAX-1] = '\0'; diff --git a/nuttx/net/local/local_bind.c b/nuttx/net/local/local_bind.c index 5a469f786..675b49516 100644 --- a/nuttx/net/local/local_bind.c +++ b/nuttx/net/local/local_bind.c @@ -44,6 +44,8 @@ #include <string.h> #include <assert.h> +#include <nuttx/net/net.h> + #include "local/local.h" /**************************************************************************** @@ -59,19 +61,23 @@ * ****************************************************************************/ -int local_bind(FAR struct local_conn_s *conn, - FAR const struct sockaddr *addr, socklen_t addrlen) +int psock_local_bind(FAR struct socket *psock, + FAR const struct sockaddr *addr, socklen_t addrlen) { + FAR struct local_conn_s *conn; FAR const struct sockaddr_un *unaddr = (FAR const struct sockaddr_un *)addr; int namelen; - DEBUGASSERT(conn && unaddr && unaddr->sun_family == AF_LOCAL && + DEBUGASSERT(psock && psock->s_conn && unaddr && + unaddr->sun_family == AF_LOCAL && addrlen >= sizeof(sa_family_t)); + conn = (FAR struct local_conn_s *)psock->s_conn; + /* Save the address family */ - conn->lc_family = unaddr->sun_family; + conn->lc_proto = psock->s_type; /* No determine the type of the Unix domain socket by comparing the size * of the address description. diff --git a/nuttx/net/local/local_connect.c b/nuttx/net/local/local_connect.c index 2f1190a20..c10de214a 100644 --- a/nuttx/net/local/local_connect.c +++ b/nuttx/net/local/local_connect.c @@ -225,6 +225,7 @@ errout_with_fifos: int local_connect(FAR struct local_conn_s *client, FAR const struct sockaddr *addr) { + FAR struct sockaddr_un *unaddr = (FAR struct sockaddr_un *)addr; FAR struct local_conn_s *conn; net_lock_t state; @@ -243,20 +244,16 @@ int local_connect(FAR struct local_conn_s *client, conn; conn = (FAR struct local_conn_s *)dq_next(&conn->lc_node)) { - /* Skip over connections that that have not yet been bound, - * are or a different address family, or are of a different type. + /* Anything in the listener list should be a stream socket in the + * istening state */ - if (conn->lc_state == LOCAL_STATE_UNBOUND || - conn->lc_family != client->lc_family || - conn->lc_type != client->lc_type) - { - continue; - } + DEBUGASSERT(conn->lc_state == LOCAL_STATE_LISTENING && + conn->lc_proto == SOCK_STREAM); - /* Handle according to the connection type */ + /* Handle according to the server connection type */ - switch (client->lc_type) + switch (conn->lc_type) { case LOCAL_TYPE_UNNAMED: /* A Unix socket that is not bound to any name */ case LOCAL_TYPE_ABSTRACT: /* lc_path is length zero */ @@ -269,11 +266,17 @@ int local_connect(FAR struct local_conn_s *client, case LOCAL_TYPE_PATHNAME: /* lc_path holds a null terminated string */ { - if (strncmp(client->lc_path, conn->lc_path, UNIX_PATH_MAX-1) == 0) + if (strncmp(conn->lc_path, unaddr->sun_path, UNIX_PATH_MAX-1) == 0) { + /* Bind the address and protocol */ + + client->lc_proto = conn->lc_proto; + strncpy(client->lc_path, unaddr->sun_path, UNIX_PATH_MAX-1); + client->lc_path[UNIX_PATH_MAX-1] = '\0'; + /* We have to do more for the SOCK_STREAM family */ - if (conn->lc_family == SOCK_STREAM) + if (conn->lc_proto == SOCK_STREAM) { return local_stream_connect(client, conn, state); } diff --git a/nuttx/net/local/local_listen.c b/nuttx/net/local/local_listen.c index 545908820..5de0d1232 100644 --- a/nuttx/net/local/local_listen.c +++ b/nuttx/net/local/local_listen.c @@ -89,7 +89,7 @@ int local_listen(FAR struct local_conn_s *server, int backlog) DEBUGASSERT(server); - if (server->lc_family != SOCK_STREAM || + if (server->lc_proto != SOCK_STREAM || server->lc_state == LOCAL_STATE_UNBOUND || server->lc_type != LOCAL_TYPE_PATHNAME) { diff --git a/nuttx/net/local/local_release.c b/nuttx/net/local/local_release.c index 51465a068..e9b9d0c76 100644 --- a/nuttx/net/local/local_release.c +++ b/nuttx/net/local/local_release.c @@ -85,7 +85,7 @@ int local_release(FAR struct local_conn_s *conn) if (conn->lc_state == LOCAL_STATE_CONNECTED || conn->lc_state == LOCAL_STATE_DISCONNECTED) { - DEBUGASSERT(conn->lc_family == SOCK_STREAM); + DEBUGASSERT(conn->lc_proto == SOCK_STREAM); /* Just free the connection structure */ } @@ -96,7 +96,7 @@ int local_release(FAR struct local_conn_s *conn) { FAR struct local_conn_s *client; - DEBUGASSERT(conn->lc_family == SOCK_STREAM); + DEBUGASSERT(conn->lc_proto == SOCK_STREAM); /* Are there still clients waiting for a connection to the server? */ diff --git a/nuttx/net/socket/bind.c b/nuttx/net/socket/bind.c index 6dc7de9ff..6407c0add 100644 --- a/nuttx/net/socket/bind.c +++ b/nuttx/net/socket/bind.c @@ -228,7 +228,7 @@ int psock_bind(FAR struct socket *psock, const struct sockaddr *addr, { /* Bind the Unix domain connection structure */ - ret = local_bind(psock->s_conn, addr, addrlen); + ret = psock_local_bind(psock, addr, addrlen); } #endif /* CONFIG_NET_LOCAL */ @@ -269,7 +269,7 @@ int psock_bind(FAR struct socket *psock, const struct sockaddr *addr, { /* Bind the Unix domain connection structure */ - ret = local_bind(psock->s_conn, addr, addrlen); + ret = psock_local_bind(psock, addr, addrlen); } #endif /* CONFIG_NET_LOCAL */ diff --git a/nuttx/net/socket/connect.c b/nuttx/net/socket/connect.c index 0cb84177d..9830fa55e 100644 --- a/nuttx/net/socket/connect.c +++ b/nuttx/net/socket/connect.c @@ -503,6 +503,18 @@ int psock_connect(FAR struct socket *psock, FAR const struct sockaddr *addr, break; #endif +#ifdef CONFIG_NET_LOCAL + case AF_LOCAL: + { + if (addrlen < sizeof(sa_family_t)) + { + err = EBADF; + goto errout; + } + } + break; +#endif + default: DEBUGPANIC(); err = EAFNOSUPPORT; diff --git a/nuttx/net/socket/socket.c b/nuttx/net/socket/socket.c index 427dd7016..7cec99427 100644 --- a/nuttx/net/socket/socket.c +++ b/nuttx/net/socket/socket.c @@ -292,27 +292,67 @@ int psock_socket(int domain, int type, int protocol, FAR struct socket *psock) switch (type) { -#ifdef CONFIG_NET_TCP +#if defined(CONFIG_NET_TCP) || defined(CONFIG_NET_LOCAL) case SOCK_STREAM: - if ((protocol != 0 && protocol != IPPROTO_TCP) || !dgramok) +#ifdef CONFIG_NET_TCP +#ifdef CONFIG_NET_LOCAL + if (ipdomain) +#endif { - err = EPROTONOSUPPORT; - goto errout; + if ((protocol != 0 && protocol != IPPROTO_TCP) || !dgramok) + { + err = EPROTONOSUPPORT; + goto errout; + } } +#endif /* CONFIG_NET_TCP */ + +#ifdef CONFIG_NET_LOCAL +#ifdef CONFIG_NET_TCP + else +#endif + { + if (protocol != 0 || !dgramok) + { + err = EPROTONOSUPPORT; + goto errout; + } + } +#endif /* CONFIG_NET_LOCAL */ break; +#endif /* CONFIG_NET_TCP || CONFIG_NET_LOCAL */ + +#if defined(CONFIG_NET_UDP) || defined(CONFIG_NET_LOCAL) + case SOCK_DGRAM: +#ifdef CONFIG_NET_UDP +#ifdef CONFIG_NET_LOCAL + if (ipdomain) #endif + { + if ((protocol != 0 && protocol != IPPROTO_UDP) || !dgramok) + { + err = EPROTONOSUPPORT; + goto errout; + } + } +#endif /* CONFIG_NET_UDP */ +#ifdef CONFIG_NET_LOCAL #ifdef CONFIG_NET_UDP - case SOCK_DGRAM: - if ((protocol != 0 && protocol != IPPROTO_UDP) || !dgramok) + else +#endif { - err = EPROTONOSUPPORT; - goto errout; + if (protocol != 0 || !dgramok) + { + err = EPROTONOSUPPORT; + goto errout; + } } +#endif /* CONFIG_NET_LOCAL */ break; -#endif +#endif /* CONFIG_NET_UDP || CONFIG_NET_LOCAL */ #ifdef CONFIG_NET_PKT case SOCK_RAW: |