Browse Source

change: lwip集成的setopts和getopts改成封装lwip原有函数, 减少代码量

Wendal Chen 3 years ago
parent
commit
e47f490882
1 changed files with 13 additions and 609 deletions
  1. 13 609
      app/network/luat_network_lwip_tcpip_cb.c

+ 13 - 609
app/network/luat_network_lwip_tcpip_cb.c

@@ -7,6 +7,7 @@
 #include "luat_network_adapter.h"
 #include "lwip/tcpip.h"
 #include "lwip/udp.h"
+#include "lwip/sockets.h"
 
 #ifdef LUAT_USE_NETWORK
 
@@ -21,283 +22,7 @@
 #define SOCKET_BUF_LEN	(3 * TCP_MSS)
 #endif
 
-/* Socket protocol types (TCP/UDP/RAW) */
-#define SOCK_STREAM     1
-#define SOCK_DGRAM      2
-#define SOCK_RAW        3
-
-/*
- * Option flags per-socket. These must match the SOF_ flags in ip.h (checked in init.c)
- */
-#define SO_REUSEADDR   0x0004 /* Allow local address reuse */
-#define SO_KEEPALIVE   0x0008 /* keep connections alive */
-#define SO_BROADCAST   0x0020 /* permit to send and to receive broadcast messages (see IP_SOF_BROADCAST option) */
-
-
-/*
- * Additional options, not kept in so_options.
- */
-#define SO_DEBUG        0x0001 /* Unimplemented: turn on debugging info recording */
-#define SO_ACCEPTCONN   0x0002 /* socket has had listen() */
-#define SO_DONTROUTE    0x0010 /* Unimplemented: just use interface addresses */
-#define SO_USELOOPBACK  0x0040 /* Unimplemented: bypass hardware when possible */
-#define SO_LINGER       0x0080 /* linger on close if data present */
-#define SO_DONTLINGER   ((int)(~SO_LINGER))
-#define SO_OOBINLINE    0x0100 /* Unimplemented: leave received OOB data in line */
-#define SO_REUSEPORT    0x0200 /* Unimplemented: allow local address & port reuse */
-#define SO_SNDBUF       0x1001 /* Unimplemented: send buffer size */
-#define SO_RCVBUF       0x1002 /* receive buffer size */
-#define SO_SNDLOWAT     0x1003 /* Unimplemented: send low-water mark */
-#define SO_RCVLOWAT     0x1004 /* Unimplemented: receive low-water mark */
-#define SO_SNDTIMEO     0x1005 /* send timeout */
-#define SO_RCVTIMEO     0x1006 /* receive timeout */
-#define SO_ERROR        0x1007 /* get error status and clear */
-#define SO_TYPE         0x1008 /* get socket type */
-#define SO_CONTIMEO     0x1009 /* Unimplemented: connect timeout */
-#define SO_NO_CHECK     0x100a /* don't create UDP checksum */
-#define SO_BINDTODEVICE 0x100b /* bind to device */
-
-/*
- * Structure used for manipulating linger option.
- */
-/*
- * Level number for (get/set)sockopt() to apply to socket itself.
- */
-#define  SOL_SOCKET  0xfff    /* options for socket level */
-
-
-#define AF_UNSPEC       0
-#define AF_INET         2
-#if LWIP_IPV6
-#define AF_INET6        10
-#else /* LWIP_IPV6 */
-#define AF_INET6        AF_UNSPEC
-#endif /* LWIP_IPV6 */
-#define PF_INET         AF_INET
-#define PF_INET6        AF_INET6
-#define PF_UNSPEC       AF_UNSPEC
-
-#define IPPROTO_IP      0
-#define IPPROTO_ICMP    1
-#define IPPROTO_TCP     6
-#define IPPROTO_UDP     17
-#if LWIP_IPV6
-#define IPPROTO_IPV6    41
-#define IPPROTO_ICMPV6  58
-#endif /* LWIP_IPV6 */
-#define IPPROTO_UDPLITE 136
-#define IPPROTO_RAW     255
-
-/* Flags we can use with send and recv. */
-#define MSG_PEEK       0x01    /* Peeks at an incoming message */
-#define MSG_WAITALL    0x02    /* Unimplemented: Requests that the function block until the full amount of data requested can be returned */
-#define MSG_OOB        0x04    /* Unimplemented: Requests out-of-band data. The significance and semantics of out-of-band data are protocol-specific */
-#define MSG_DONTWAIT   0x08    /* Nonblocking i/o for this operation only */
-#define MSG_MORE       0x10    /* Sender will send more */
-#define MSG_NOSIGNAL   0x20    /* Uninmplemented: Requests not to send the SIGPIPE signal if an attempt to send is made on a stream-oriented socket that is no longer connected. */
-
-
-/*
- * Options for level IPPROTO_IP
- */
-#define IP_TOS             1
-#define IP_TTL             2
-#define IP_PKTINFO         8
-
-#if LWIP_TCP
-/*
- * Options for level IPPROTO_TCP
- */
-#define TCP_NODELAY    0x01    /* don't delay send to coalesce packets */
-#define TCP_KEEPALIVE  0x02    /* send KEEPALIVE probes when idle for pcb->keep_idle milliseconds */
-#define TCP_KEEPIDLE   0x03    /* set pcb->keep_idle  - Same as TCP_KEEPALIVE, but use seconds for get/setsockopt */
-#define TCP_KEEPINTVL  0x04    /* set pcb->keep_intvl - Use seconds for get/setsockopt */
-#define TCP_KEEPCNT    0x05    /* set pcb->keep_cnt   - Use number of probes sent for get/setsockopt */
-#endif /* LWIP_TCP */
-
-#if LWIP_IPV6
-/*
- * Options for level IPPROTO_IPV6
- */
-#define IPV6_CHECKSUM       7  /* RFC3542: calculate and insert the ICMPv6 checksum for raw sockets. */
-#define IPV6_V6ONLY         27 /* RFC3493: boolean control to restrict AF_INET6 sockets to IPv6 communications only. */
-#endif /* LWIP_IPV6 */
-
-#if LWIP_UDP && LWIP_UDPLITE
-/*
- * Options for level IPPROTO_UDPLITE
- */
-#define UDPLITE_SEND_CSCOV 0x01 /* sender checksum coverage */
-#define UDPLITE_RECV_CSCOV 0x02 /* minimal receiver checksum coverage */
-#endif /* LWIP_UDP && LWIP_UDPLITE*/
-
-
-#if LWIP_MULTICAST_TX_OPTIONS
-/*
- * Options and types for UDP multicast traffic handling
- */
-#define IP_MULTICAST_TTL   5
-#define IP_MULTICAST_IF    6
-#define IP_MULTICAST_LOOP  7
-#endif /* LWIP_MULTICAST_TX_OPTIONS */
-
-#if LWIP_IGMP
-/*
- * Options and types related to multicast membership
- */
-#define IP_ADD_MEMBERSHIP  3
-#define IP_DROP_MEMBERSHIP 4
-
-typedef struct ip_mreq {
-    struct in_addr imr_multiaddr; /* IP multicast address of group */
-    struct in_addr imr_interface; /* local IP address of interface */
-} ip_mreq;
-#endif /* LWIP_IGMP */
-
-
-#if LWIP_IPV6_MLD
-/*
- * Options and types related to IPv6 multicast membership
- */
-#define IPV6_JOIN_GROUP      12
-#define IPV6_ADD_MEMBERSHIP  IPV6_JOIN_GROUP
-#define IPV6_LEAVE_GROUP     13
-#define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP
-
-
-#endif /* LWIP_IPV6_MLD */
-
-/*
- * The Type of Service provides an indication of the abstract
- * parameters of the quality of service desired.  These parameters are
- * to be used to guide the selection of the actual service parameters
- * when transmitting a datagram through a particular network.  Several
- * networks offer service precedence, which somehow treats high
- * precedence traffic as more important than other traffic (generally
- * by accepting only traffic above a certain precedence at time of high
- * load).  The major choice is a three way tradeoff between low-delay,
- * high-reliability, and high-throughput.
- * The use of the Delay, Throughput, and Reliability indications may
- * increase the cost (in some sense) of the service.  In many networks
- * better performance for one of these parameters is coupled with worse
- * performance on another.  Except for very unusual cases at most two
- * of these three indications should be set.
- */
-#define IPTOS_TOS_MASK          0x1E
-#define IPTOS_TOS(tos)          ((tos) & IPTOS_TOS_MASK)
-#define IPTOS_LOWDELAY          0x10
-#define IPTOS_THROUGHPUT        0x08
-#define IPTOS_RELIABILITY       0x04
-#define IPTOS_LOWCOST           0x02
-#define IPTOS_MINCOST           IPTOS_LOWCOST
-
-/*
- * The Network Control precedence designation is intended to be used
- * within a network only.  The actual use and control of that
- * designation is up to each network. The Internetwork Control
- * designation is intended for use by gateway control originators only.
- * If the actual use of these precedence designations is of concern to
- * a particular network, it is the responsibility of that network to
- * control the access to, and use of, those precedence designations.
- */
-#define IPTOS_PREC_MASK                 0xe0
-#define IPTOS_PREC(tos)                ((tos) & IPTOS_PREC_MASK)
-#define IPTOS_PREC_NETCONTROL           0xe0
-#define IPTOS_PREC_INTERNETCONTROL      0xc0
-#define IPTOS_PREC_CRITIC_ECP           0xa0
-#define IPTOS_PREC_FLASHOVERRIDE        0x80
-#define IPTOS_PREC_FLASH                0x60
-#define IPTOS_PREC_IMMEDIATE            0x40
-#define IPTOS_PREC_PRIORITY             0x20
-#define IPTOS_PREC_ROUTINE              0x00
-
-
-/*
- * Commands for ioctlsocket(),  taken from the BSD file fcntl.h.
- * lwip_ioctl only supports FIONREAD and FIONBIO, for now
- *
- * Ioctl's have the command encoded in the lower word,
- * and the size of any in or out parameters in the upper
- * word.  The high 2 bits of the upper word are used
- * to encode the in/out status of the parameter; for now
- * we restrict parameters to at most 128 bytes.
- */
-#if !defined(FIONREAD) || !defined(FIONBIO)
-#define IOCPARM_MASK    0x7fU           /* parameters must be < 128 bytes */
-#define IOC_VOID        0x20000000UL    /* no parameters */
-#define IOC_OUT         0x40000000UL    /* copy out parameters */
-#define IOC_IN          0x80000000UL    /* copy in parameters */
-#define IOC_INOUT       (IOC_IN|IOC_OUT)
-                                        /* 0x20000000 distinguishes new &
-                                           old ioctl's */
-#define _IO(x,y)        ((long)(IOC_VOID|((x)<<8)|(y)))
-
-#define _IOR(x,y,t)     ((long)(IOC_OUT|((sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y)))
-
-#define _IOW(x,y,t)     ((long)(IOC_IN|((sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y)))
-#endif /* !defined(FIONREAD) || !defined(FIONBIO) */
-
-#ifndef FIONREAD
-#define FIONREAD    _IOR('f', 127, unsigned long) /* get # bytes to read */
-#endif
-#ifndef FIONBIO
-#define FIONBIO     _IOW('f', 126, unsigned long) /* set/clear non-blocking i/o */
-#endif
 
-/* Socket I/O Controls: unimplemented */
-#ifndef SIOCSHIWAT
-#define SIOCSHIWAT  _IOW('s',  0, unsigned long)  /* set high watermark */
-#define SIOCGHIWAT  _IOR('s',  1, unsigned long)  /* get high watermark */
-#define SIOCSLOWAT  _IOW('s',  2, unsigned long)  /* set low watermark */
-#define SIOCGLOWAT  _IOR('s',  3, unsigned long)  /* get low watermark */
-#define SIOCATMARK  _IOR('s',  7, unsigned long)  /* at oob mark? */
-#endif
-
-/* commands for fnctl */
-#ifndef F_GETFL
-#define F_GETFL 3
-#endif
-#ifndef F_SETFL
-#define F_SETFL 4
-#endif
-
-/* File status flags and file access modes for fnctl,
-   these are bits in an int. */
-#ifndef O_NONBLOCK
-#define O_NONBLOCK  1 /* nonblocking I/O */
-#endif
-#ifndef O_NDELAY
-#define O_NDELAY    O_NONBLOCK /* same as O_NONBLOCK, for compatibility */
-#endif
-#ifndef O_RDONLY
-#define O_RDONLY    2
-#endif
-#ifndef O_WRONLY
-#define O_WRONLY    4
-#endif
-#ifndef O_RDWR
-#define O_RDWR      (O_RDONLY|O_WRONLY)
-#endif
-
-static int
-lwip_sockopt_to_ipopt(int optname)
-{
-	/* Map SO_* values to our internal SOF_* values
-	* We should not rely on #defines in socket.h
-	* being in sync with ip.h.
-	*/
-	switch (optname) {
-	case SO_BROADCAST:
-		return SOF_BROADCAST;
-	case SO_KEEPALIVE:
-		return SOF_KEEPALIVE;
-	case SO_REUSEADDR:
-		return SOF_REUSEADDR;
-	default:
-		NET_DBG("Unknown socket option", 0);
-		return 0;
-	}
-}
 
 enum
 {
@@ -1530,339 +1255,6 @@ void net_lwip_socket_clean(int *vaild_socket_list, uint32_t num, void *user_data
 	}
 }
 
-static int net_lwip_getsockopt(int socket_id, uint64_t tag,  int level, int optname, void *optval, uint32_t *optlen, void *user_data)
-{
-	int result = net_lwip_check_socket(user_data, socket_id, tag);
-	if (result) return result;
-	for(int i = 0; i < 10; i++)
-	{
-		if (!prvlwip.socket[socket_id].pcb.ip)
-		{
-			platform_task_sleep(1);
-		}
-		else
-		{
-			break;
-		}
-	}
-
-	if (!prvlwip.socket[socket_id].pcb.ip)
-	{
-		NET_DBG("socket %d not create try later! %d, %d, %x, %d", socket_id, level, optname, optval, optlen);
-		return -1;
-	}
-	switch (level)
-	{
-
-	    /* Level: SOL_SOCKET */
-	case SOL_SOCKET:
-		switch (optname)
-		{
-
-#if LWIP_TCP
-		case SO_ACCEPTCONN:
-			if (!prvlwip.socket[socket_id].is_tcp) {
-				return -1;
-			}
-			if ((prvlwip.socket[socket_id].pcb.tcp != NULL) && (prvlwip.socket[socket_id].pcb.tcp->state == LISTEN)) {
-				*(int *)optval = 1;
-			} else {
-				*(int *)optval = 0;
-			}
-			break;
-#endif /* LWIP_TCP */
-
-	        /* The option flags */
-	    case SO_BROADCAST:
-	    case SO_KEEPALIVE:
-#if SO_REUSE
-	    case SO_REUSEADDR:
-#endif /* SO_REUSE */
-			if ((optname == SO_BROADCAST) && prvlwip.socket[socket_id].is_tcp) {
-				return -1;
-			}
-
-			optname = lwip_sockopt_to_ipopt(optname);
-			*(int *)optval = ip_get_option(prvlwip.socket[socket_id].pcb.ip, optname);
-			break;
-	    case SO_TYPE:
-	    	if (prvlwip.socket[socket_id].is_tcp)
-	    	{
-	    		*(int *)optval = SOCK_STREAM;
-	    	}
-	    	else
-	    	{
-	    		*(int *)optval = SOCK_DGRAM;
-	    	}
-	        break;
-
-	    case SO_ERROR:
-	    	return -1;
-	        break;
-	    default:
-			return -1;
-			break;
-		}  /* switch (optname) */
-		break;
-
-	    /* Level: IPPROTO_IP */
-	case IPPROTO_IP:
-		switch (optname) {
-	        case IP_TTL:
-				*(int *)optval = prvlwip.socket[socket_id].pcb.ip->ttl;
-				break;
-	        case IP_TOS:
-				*(int *)optval = prvlwip.socket[socket_id].pcb.ip->tos;
-				break;
-#if LWIP_IPV4 && LWIP_MULTICAST_TX_OPTIONS && LWIP_UDP
-	        case IP_MULTICAST_TTL:
-	        	if (prvlwip.socket[socket_id].is_tcp) return -1;
-				*(u8_t *)optval = udp_get_multicast_ttl(prvlwip.socket[socket_id].pcb.udp);
-
-				break;
-	        case IP_MULTICAST_IF:
-	        	if (prvlwip.socket[socket_id].is_tcp) return -1;
-	        	((struct in_addr *)optval)->s_addr = prvlwip.socket[socket_id].pcb.udp->mcast_ip4.addr;
-	        	break;
-	        case IP_MULTICAST_LOOP:
-	        	if (prvlwip.socket[socket_id].is_tcp) return -1;
-				if ((prvlwip.socket[socket_id].pcb.udp->flags & UDP_FLAGS_MULTICAST_LOOP) != 0) {
-					*(u8_t *)optval = 1;
-				} else {
-					*(u8_t *)optval = 0;
-				}
-				break;
-	#endif /* LWIP_IPV4 && LWIP_MULTICAST_TX_OPTIONS && LWIP_UDP */
-	        default:
-	        	return -1;
-		}  /* switch (optname) */
-		break;
-
-#if LWIP_TCP
-	    /* Level: IPPROTO_TCP */
-	case IPPROTO_TCP:
-	      /* Special case: all IPPROTO_TCP option take an int */
-		if (!prvlwip.socket[socket_id].is_tcp) return -1;
-		if (prvlwip.socket[socket_id].pcb.tcp->state == LISTEN) {
-			return -1;
-		}
-	    switch (optname) {
-			case TCP_NODELAY:
-				*(int *)optval = tcp_nagle_disabled(prvlwip.socket[socket_id].pcb.tcp);
-				break;
-			case TCP_KEEPALIVE:
-				*(int *)optval = (int)prvlwip.socket[socket_id].pcb.tcp->keep_idle;
-				break;
-
-#if LWIP_TCP_KEEPALIVE
-			case TCP_KEEPIDLE:
-				*(int *)optval = (int)(prvlwip.socket[socket_id].pcb.tcp->keep_idle / 1000);
-				break;
-			case TCP_KEEPINTVL:
-				*(int *)optval = (int)(prvlwip.socket[socket_id].pcb.tcp->keep_intvl / 1000);
-
-				break;
-			case TCP_KEEPCNT:
-				*(int *)optval = (int)prvlwip.socket[socket_id].pcb.tcp->keep_cnt;
-				break;
-#endif /* LWIP_TCP_KEEPALIVE */
-			default:
-				return -1;
-				break;
-		}  /* switch (optname) */
-		break;
-	#endif /* LWIP_TCP */
-
-	#if LWIP_UDP && LWIP_UDPLITE
-	    /* Level: IPPROTO_UDPLITE */
-	case IPPROTO_UDPLITE:
-	      /* Special case: all IPPROTO_UDPLITE option take an int */
-	      LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB(sock, *optlen, int);
-	      /* If this is no UDP lite socket, ignore any options. */
-	      if (!NETCONNTYPE_ISUDPLITE(netconn_type(sock->conn))) {
-	        done_socket(sock);
-	        return ENOPROTOOPT;
-	      }
-	      switch (optname) {
-	        case UDPLITE_SEND_CSCOV:
-	          *(int *)optval = prvlwip.socket[socket_id].pcb.udp->chksum_len_tx;
-	          LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_UDPLITE, UDPLITE_SEND_CSCOV) = %d\n",
-	                                      s, (*(int *)optval)) );
-	          break;
-	        case UDPLITE_RECV_CSCOV:
-	          *(int *)optval = prvlwip.socket[socket_id].pcb.udp->chksum_len_rx;
-	          LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_UDPLITE, UDPLITE_RECV_CSCOV) = %d\n",
-	                                      s, (*(int *)optval)) );
-	          break;
-	        default:
-	          LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_UDPLITE, UNIMPL: optname=0x%x, ..)\n",
-	                                      s, optname));
-	          err = ENOPROTOOPT;
-	          break;
-	      }  /* switch (optname) */
-	      break;
-	#endif /* LWIP_UDP */
-	    /* Level: IPPROTO_RAW */
-	case IPPROTO_RAW:
-		return -1;
-	default:
-		return -1;
-		break;
-	} /* switch (level) */
-
-	return 0;
-}
-static int net_lwip_setsockopt(int socket_id, uint64_t tag,  int level, int optname, const void *optval, uint32_t optlen, void *user_data)
-{
-	int result = net_lwip_check_socket(user_data, socket_id, tag);
-	if (result) return result;
-	for(int i = 0; i < 10; i++)
-	{
-		if (!prvlwip.socket[socket_id].pcb.ip)
-		{
-			platform_task_sleep(1);
-		}
-		else
-		{
-			break;
-		}
-	}
-
-	if (!prvlwip.socket[socket_id].pcb.ip)
-	{
-		NET_DBG("socket %d not create try later! %d, %d, %x, %d", socket_id, level, optname, optval, optlen);
-		return -1;
-	}
-	switch (level)
-	{
-
-	    /* Level: SOL_SOCKET */
-	case SOL_SOCKET:
-		switch (optname)
-		{
-
-		/* SO_ACCEPTCONN is get-only */
-
-		/* The option flags */
-		case SO_BROADCAST:
-		case SO_KEEPALIVE:
-#if SO_REUSE
-		case SO_REUSEADDR:
-#endif /* SO_REUSE */
-			if ((optname == SO_BROADCAST) &&
-			  (prvlwip.socket[socket_id].is_tcp)) {
-				return -1;
-			}
-
-			optname = lwip_sockopt_to_ipopt(optname);
-
-			if (*(const int *)optval) {
-				ip_set_option(prvlwip.socket[socket_id].pcb.ip, optname);
-			} else {
-				ip_reset_option(prvlwip.socket[socket_id].pcb.ip, optname);
-			}
-			break;
-		default:
-			return -1;
-	    }  /* switch (optname) */
-	    break;
-
-	    /* Level: IPPROTO_IP */
-	case IPPROTO_IP:
-	    switch (optname)
-	    {
-	    case IP_TTL:
-			prvlwip.socket[socket_id].pcb.ip->ttl = (u8_t)(*(const int *)optval);
-
-			break;
-	    case IP_TOS:
-	        prvlwip.socket[socket_id].pcb.ip->tos = (u8_t)(*(const int *)optval);
-	        break;
-#if LWIP_NETBUF_RECVINFO
-	    case IP_PKTINFO:
-
-			if (*(const int *)optval) {
-				prvlwip.socket[socket_id].flags |= NETCONN_FLAG_PKTINFO;
-			} else {
-				prvlwip.socket[socket_id].flags &= ~NETCONN_FLAG_PKTINFO;
-			}
-			break;
-#endif /* LWIP_NETBUF_RECVINFO */
-#if LWIP_IPV4 && LWIP_MULTICAST_TX_OPTIONS && LWIP_UDP
-		case IP_MULTICAST_TTL:
-			if (prvlwip.socket[socket_id].is_tcp) return -1;
-			udp_set_multicast_ttl(prvlwip.socket[socket_id].pcb.udp, (u8_t)(*(const u8_t *)optval));
-			break;
-		case IP_MULTICAST_IF:
-			if (prvlwip.socket[socket_id].is_tcp) return -1;
-			prvlwip.socket[socket_id].pcb.udp->mcast_ip4.addr = ((struct in_addr *)optval)->s_addr;
-			break;
-#endif /* LWIP_IPV4 && LWIP_MULTICAST_TX_OPTIONS && LWIP_UDP */
-		default:
-			return -1;
-			break;
-		}  /* switch (optname) */
-		break;
-
-#if LWIP_TCP
-	    /* Level: IPPROTO_TCP */
-	case IPPROTO_TCP:
-	      /* Special case: all IPPROTO_TCP option take an int */
-		if (!prvlwip.socket[socket_id].is_tcp) return -1;
-	    if (prvlwip.socket[socket_id].pcb.tcp->state == LISTEN) {
-	    	return -1;
-	    }
-		switch (optname)
-		{
-		case TCP_NODELAY:
-			if (*(const int *)optval) {
-				tcp_nagle_disable(prvlwip.socket[socket_id].pcb.tcp);
-			} else {
-				tcp_nagle_enable(prvlwip.socket[socket_id].pcb.tcp);
-			}
-			break;
-		case TCP_KEEPALIVE:
-			prvlwip.socket[socket_id].pcb.tcp->keep_idle = (u32_t)(*(const int *)optval);
-
-			break;
-
-#if LWIP_TCP_KEEPALIVE
-		case TCP_KEEPIDLE:
-			prvlwip.socket[socket_id].pcb.tcp->keep_idle = 1000 * (u32_t)(*(const int *)optval);
-			break;
-		case TCP_KEEPINTVL:
-			prvlwip.socket[socket_id].pcb.tcp->keep_intvl = 1000 * (u32_t)(*(const int *)optval);
-
-			break;
-		case TCP_KEEPCNT:
-			prvlwip.socket[socket_id].pcb.tcp->keep_cnt = (u32_t)(*(const int *)optval);
-
-			break;
-#endif /* LWIP_TCP_KEEPALIVE */
-		default:
-			return -1;
-			break;
-		}  /* switch (optname) */
-		break;
-#endif /* LWIP_TCP*/
-
-#if LWIP_IPV6
-	    /* Level: IPPROTO_IPV6 */
-	case IPPROTO_IPV6:
-		return -1;
-		break;
-#endif /* LWIP_IPV6 */
-
-
-	    /* Level: IPPROTO_RAW */
-	case IPPROTO_RAW:
-	    return -1;
-	    break;
-	default:
-		return -1;
-	}   /* switch (level) */
-	return 0;
-}
 
 
 static int net_lwip_get_local_ip_info(luat_ip_addr_t *ip, luat_ip_addr_t *submask, luat_ip_addr_t *gateway, void *user_data)
@@ -1944,6 +1336,18 @@ static void net_lwip_socket_set_callback(CBFuncEx_t cb_fun, void *param, void *u
 	prvlwip.user_data = param;
 }
 
+int net_lwip_getsockopt(int socket_id, uint64_t tag,  int level, int optname, void *optval, uint32_t *optlen, void *user_data) {
+	int result = net_lwip_check_socket(user_data, socket_id, tag);
+	if (result) return result;
+	return lwip_getsockopt(socket_id, level, optname, optval, optlen);
+}
+
+int net_lwip_setsockopt(int socket_id, uint64_t tag,  int level, int optname, const void *optval, uint32_t optlen, void *user_data) {
+	int result = net_lwip_check_socket(user_data, socket_id, tag);
+	if (result) return result;
+	return lwip_setsockopt(socket_id, level, optname, optval, optlen);
+}
+
 static network_adapter_info prv_net_lwip_adapter =
 {
 		.check_ready = net_lwip_check_ready,