Start working task #14494: Implement SO_BINDTODEVICE

Implement setsockopt. TODO: getsockopt
This commit is contained in:
Dirk Ziegelmeier 2017-05-02 13:18:29 +02:00
parent eab2ae5d78
commit c7e3519f46
3 changed files with 61 additions and 22 deletions

View File

@ -2920,6 +2920,38 @@ lwip_setsockopt_impl(int s, int level, int optname, const void *optval, socklen_
} }
break; break;
#endif /* LWIP_UDP */ #endif /* LWIP_UDP */
case SO_BINDTODEVICE:
{
struct ifreq *iface;
struct netif* n = NULL;
LWIP_SOCKOPT_CHECK_OPTLEN_CONN(sock, optlen, struct ifreq);
iface = (struct ifreq*)optval;
if (iface->ifr_name[0] != 0) {
n = netif_find(iface->ifr_name);
if (n == NULL) {
done_socket(sock);
return ENODEV;
}
}
switch (NETCONNTYPE_GROUP(netconn_type(sock->conn)))
{
case NETCONN_TCP:
tcp_bind_netif(sock->conn->pcb.tcp, n);
break;
case NETCONN_UDP:
udp_bind_netif(sock->conn->pcb.udp, n);
break;
case NETCONN_RAW:
raw_bind_netif(sock->conn->pcb.raw, n);
break;
default:
break;
}
}
break;
default: default:
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, SOL_SOCKET, UNIMPL: optname=0x%x, ..)\n", LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, SOL_SOCKET, UNIMPL: optname=0x%x, ..)\n",
s, optname)); s, optname));

View File

@ -58,7 +58,7 @@ extern "C" {
#if !LWIP_TCPIP_CORE_LOCKING #if !LWIP_TCPIP_CORE_LOCKING
/** Maximum optlen used by setsockopt/getsockopt */ /** Maximum optlen used by setsockopt/getsockopt */
#define LWIP_SETGETSOCKOPT_MAXOPTLEN 16 #define LWIP_SETGETSOCKOPT_MAXOPTLEN LWIP_MAX(16, sizeof(struct ifreq))
/** This struct is used to pass data to the set/getsockopt_internal /** This struct is used to pass data to the set/getsockopt_internal
* functions running in tcpip_thread context (only a void* is allowed) */ * functions running in tcpip_thread context (only a void* is allowed) */

View File

@ -44,6 +44,7 @@
#if LWIP_SOCKET /* don't build if not configured for use in lwipopts.h */ #if LWIP_SOCKET /* don't build if not configured for use in lwipopts.h */
#include "lwip/ip_addr.h" #include "lwip/ip_addr.h"
#include "lwip/netif.h"
#include "lwip/err.h" #include "lwip/err.h"
#include "lwip/inet.h" #include "lwip/inet.h"
#include "lwip/errno.h" #include "lwip/errno.h"
@ -175,6 +176,12 @@ will need to increase long long */
#define CMSG_LEN(length) (ALIGN_D(sizeof(struct cmsghdr)) + \ #define CMSG_LEN(length) (ALIGN_D(sizeof(struct cmsghdr)) + \
length) length)
/* Set socket options argument */
#define IFNAMSIZ NETIF_NAMESIZE
struct ifreq {
char ifr_name[IFNAMSIZ]; /* Interface name */
};
/* Socket protocol types (TCP/UDP/RAW) */ /* Socket protocol types (TCP/UDP/RAW) */
#define SOCK_STREAM 1 #define SOCK_STREAM 1
#define SOCK_DGRAM 2 #define SOCK_DGRAM 2
@ -209,7 +216,7 @@ will need to increase long long */
#define SO_TYPE 0x1008 /* get socket type */ #define SO_TYPE 0x1008 /* get socket type */
#define SO_CONTIMEO 0x1009 /* Unimplemented: connect timeout */ #define SO_CONTIMEO 0x1009 /* Unimplemented: connect timeout */
#define SO_NO_CHECK 0x100a /* don't create UDP checksum */ #define SO_NO_CHECK 0x100a /* don't create UDP checksum */
#define SO_BINDTODEVICE 0x100b /* bind to device */
/* /*
* Structure used for manipulating linger option. * Structure used for manipulating linger option.