From bf8f8d3937a3f88617a8c9d7986bf7eb1f418a84 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 12 Jun 2014 12:29:58 -0600 Subject: [PATCH] Raw sockets: Additional changes for error-free/warning-free compilation --- include/netpacket/packet.h | 2 +- net/Kconfig | 42 +++++++++++++++++++++----------------- net/bind.c | 31 +++++++++++++++++++--------- net/net_send_unbuffered.c | 2 +- net/recvfrom.c | 7 +++++-- net/uip/uip_pktconn.c | 27 ------------------------ 6 files changed, 51 insertions(+), 60 deletions(-) diff --git a/include/netpacket/packet.h b/include/netpacket/packet.h index be9076e657..522464ca68 100644 --- a/include/netpacket/packet.h +++ b/include/netpacket/packet.h @@ -55,7 +55,7 @@ struct sockaddr_ll { uint16_t sll_family; uint16_t sll_protocol; - sint16_t sll_ifindex; + int16_t sll_ifindex; }; #endif /* __INCLUDE_NETPACKET_PACKET_H */ diff --git a/net/Kconfig b/net/Kconfig index 0a5944b7f1..b251be9516 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -83,25 +83,6 @@ config NET_SOLINGER endif # NET_SOCKOPTS -config NET_PKT - bool "Socket packet socket support" - default n - ---help--- - Enable or disbale support for packet sockets. - Packet sockets allow receiving and transmitting frames without - a transport protocol in between. Frames received are copied into - a packet socket tap before they enter uIP. Data written into a - packet socket will bypass uIP altogether and be placed in the - transmission buffer of the network interface driver. - -if NET_PKT - -config NET_PKT_CONNS - int "Max packet sockets" - default 1 - -endif # NET_PKT - config NET_BUFSIZE int "Network packet buffer size (MTU)" default 1294 if !NET_SLIP && NET_IPv6 @@ -129,6 +110,29 @@ config NET_TCPURGDATA compiled in. Urgent data (out-of-band data) is a rarely used TCP feature that is very seldom would be required. +menu "Raw Socket Support" + +config NET_PKT + bool "Socket packet socket support" + default n + ---help--- + Enable or disable support for packet sockets. + + Packet sockets allow receiving and transmitting frames without + a transport protocol in between. Frames received are copied into + a packet socket tap before they enter uIP. Data written into a + packet socket will bypass uIP altogether and be placed in the + transmission buffer of the network interface driver. + +if NET_PKT + +config NET_PKT_CONNS + int "Max packet sockets" + default 1 + +endif # NET_PKT +endmenu # Packet Sockets + menu "TCP/IP Networking" config NET_TCP diff --git a/net/bind.c b/net/bind.c index 6de8443f86..48e0ad3af7 100644 --- a/net/bind.c +++ b/net/bind.c @@ -160,19 +160,30 @@ int psock_bind(FAR struct socket *psock, const struct sockaddr *addr, /* Verify that a valid address has been provided */ -#ifdef CONFIG_NET_IPv6 - if ((addr->sa_family != AF_PACKET && addr->sa_family != AF_INET6) || - (addr->sa_family == AF_PACKET && addrlen < sizeof(struct sockaddr_ll)) || - (addr->sa_family == AF_INET6 && addrlen < sizeof(struct sockaddr_in6))) -#else - if ((addr->sa_family != AF_PACKET && addr->sa_family != AF_INET) || - (addr->sa_family == AF_PACKET && addrlen < sizeof(struct sockaddr_ll)) || - (addr->sa_family == AF_INET && addrlen < sizeof(struct sockaddr_in))) + if ( + ( +#if defined(CONFIG_NET_PKT) + addr->sa_family != AF_PACKET && #endif - { +#if defined(CONFIG_NET_IPv6) + addr->sa_family != AF_INET6 +#else + addr->sa_family != AF_INET +#endif + ) || +#if defined(CONFIG_NET_PKT) + (addr->sa_family == AF_PACKET && addrlen < sizeof(struct sockaddr_ll)) || +#endif +#if defined(CONFIG_NET_IPv6) + (addr->sa_family == AF_INET6 && addrlen < sizeof(struct sockaddr_in6)) +#else + (addr->sa_family == AF_INET && addrlen < sizeof(struct sockaddr_in)) +#endif + ) + { err = EBADF; goto errout; - } + } /* Perform the binding depending on the protocol type */ diff --git a/net/net_send_unbuffered.c b/net/net_send_unbuffered.c index bcf40b72e5..375e362c5b 100644 --- a/net/net_send_unbuffered.c +++ b/net/net_send_unbuffered.c @@ -228,7 +228,7 @@ static ssize_t pktsend(FAR struct socket *psock, FAR const void *buf, struct send_s state; uip_lock_t save; int err; - int ret; + int ret = OK; /* Verify that the sockfd corresponds to valid, allocated socket */ diff --git a/net/recvfrom.c b/net/recvfrom.c index aaf6b9236c..efe8fe2724 100644 --- a/net/recvfrom.c +++ b/net/recvfrom.c @@ -558,7 +558,8 @@ static uint16_t recvfrom_pktinterrupt(FAR struct uip_driver_s *dev, ****************************************************************************/ #ifdef CONFIG_NET_TCP -static inline void recvfrom_tcpsender(struct uip_driver_s *dev, struct recvfrom_s *pstate) +static inline void recvfrom_tcpsender(FAR struct uip_driver_s *dev, + FAR struct recvfrom_s *pstate) { #ifdef CONFIG_NET_IPv6 FAR struct sockaddr_in6 *infrom = pstate->rf_from; @@ -1101,7 +1102,9 @@ static ssize_t pkt_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len, ret = -EBUSY; } +#if 0 /* Not used */ errout_with_state: +#endif uip_unlock(save); recvfrom_uninit(&state); return ret; @@ -1521,7 +1524,7 @@ ssize_t psock_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len, else #endif { - ndbg("ERROR: Unsupported socket type: %d\n", psock->s_type + ndbg("ERROR: Unsupported socket type: %d\n", psock->s_type); ret = -ENOSYS; } diff --git a/net/uip/uip_pktconn.c b/net/uip/uip_pktconn.c index 2bca680a10..7990cb6e9f 100644 --- a/net/uip/uip_pktconn.c +++ b/net/uip/uip_pktconn.c @@ -102,33 +102,6 @@ static inline void _uip_semtake(sem_t *sem) #define _uip_semgive(sem) sem_post(sem) -/**************************************************************************** - * Name: uip_find_conn() - * - * Description: - * Find the packet socket connection that uses this interface index - * number. Called only from user user level code, but with interrupts - * disabled. - * - ****************************************************************************/ - -static struct uip_pkt_conn *uip_find_conn(uint8_t ifindex) -{ - int i; - - /* Now search each connection structure. */ - - for (i = 0; i < CONFIG_NET_PKT_CONNS; i++) - { - if (g_pkt_connections[ i ].ifindex == ifindex) - { - return &g_pkt_connections[ i ]; - } - } - - return NULL; -} - /**************************************************************************** * Public Functions ****************************************************************************/