sgx_socket.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #ifndef _SGX_SOCKET_H
  6. #define _SGX_SOCKET_H
  7. #include "sgx_file.h"
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. /* For setsockopt(2) */
  12. #define SOL_SOCKET 1
  13. #define SO_DEBUG 1
  14. #define SO_REUSEADDR 2
  15. #define SO_TYPE 3
  16. #define SO_ERROR 4
  17. #define SO_DONTROUTE 5
  18. #define SO_BROADCAST 6
  19. #define SO_SNDBUF 7
  20. #define SO_RCVBUF 8
  21. #define SO_SNDBUFFORCE 32
  22. #define SO_RCVBUFFORCE 33
  23. #define SO_KEEPALIVE 9
  24. #define SO_OOBINLINE 10
  25. #define SO_NO_CHECK 11
  26. #define SO_PRIORITY 12
  27. #define SO_LINGER 13
  28. #define SO_BSDCOMPAT 14
  29. #define SO_REUSEPORT 15
  30. #define SO_PASSCRED 16
  31. #define SO_PEERCRED 17
  32. #define SO_RCVLOWAT 18
  33. #define SO_SNDLOWAT 19
  34. #define SO_RCVTIMEO_OLD 20
  35. #define SO_SNDTIMEO_OLD 21
  36. /* User-settable options (used with setsockopt) */
  37. #define TCP_NODELAY 1 /* Don't delay send to coalesce packets */
  38. #define TCP_MAXSEG 2 /* Set maximum segment size */
  39. #define TCP_CORK 3 /* Control sending of partial frames */
  40. #define TCP_KEEPIDLE 4 /* Start keeplives after this period */
  41. #define TCP_KEEPINTVL 5 /* Interval between keepalives */
  42. #define TCP_KEEPCNT 6 /* Number of keepalives before death */
  43. #define TCP_SYNCNT 7 /* Number of SYN retransmits */
  44. #define TCP_LINGER2 8 /* Life time of orphaned FIN-WAIT-2 state */
  45. #define TCP_DEFER_ACCEPT 9 /* Wake up listener only when data arrive */
  46. #define TCP_WINDOW_CLAMP 10 /* Bound advertised window */
  47. #define TCP_INFO 11 /* Information about this connection. */
  48. #define TCP_QUICKACK 12 /* Bock/reenable quick ACKs. */
  49. #define TCP_CONGESTION 13 /* Congestion control algorithm. */
  50. #define TCP_MD5SIG 14 /* TCP MD5 Signature (RFC2385) */
  51. #define TCP_COOKIE_TRANSACTIONS 15 /* TCP Cookie Transactions */
  52. #define TCP_THIN_LINEAR_TIMEOUTS 16 /* Use linear timeouts for thin streams*/
  53. #define TCP_THIN_DUPACK 17 /* Fast retrans. after 1 dupack */
  54. #define TCP_USER_TIMEOUT 18 /* How long for loss retry before timeout */
  55. #define TCP_REPAIR 19 /* TCP sock is under repair right now */
  56. #define TCP_REPAIR_QUEUE 20 /* Set TCP queue to repair */
  57. #define TCP_QUEUE_SEQ 21 /* Set sequence number of repaired queue. */
  58. #define TCP_REPAIR_OPTIONS 22 /* Repair TCP connection options */
  59. #define TCP_FASTOPEN 23 /* Enable FastOpen on listeners */
  60. #define TCP_TIMESTAMP 24 /* TCP time stamp */
  61. #define TCP_NOTSENT_LOWAT \
  62. 25 /* Limit number of unsent bytes in write queue. \
  63. */
  64. #define TCP_CC_INFO 26 /* Get Congestion Control (optional) info. */
  65. #define TCP_SAVE_SYN 27 /* Record SYN headers for new connections. */
  66. #define TCP_SAVED_SYN 28 /* Get SYN headers recorded for connection. */
  67. #define TCP_REPAIR_WINDOW 29 /* Get/set window parameters. */
  68. #define TCP_FASTOPEN_CONNECT 30 /* Attempt FastOpen with connect. */
  69. #define TCP_ULP 31 /* Attach a ULP to a TCP connection. */
  70. #define TCP_MD5SIG_EXT 32 /* TCP MD5 Signature with extensions. */
  71. #define TCP_FASTOPEN_KEY 33 /* Set the key for Fast Open (cookie). */
  72. #define TCP_FASTOPEN_NO_COOKIE 34 /* Enable TFO without a TFO cookie. */
  73. #define TCP_ZEROCOPY_RECEIVE 35
  74. #define TCP_INQ 36 /* Notify bytes available to read as a cmsg on read. */
  75. #define TCP_CM_INQ TCP_INQ
  76. #define TCP_TX_DELAY 37 /* Delay outgoing packets by XX usec. */
  77. /* Standard well-defined IP protocols. */
  78. #define IPPROTO_IP 0 /* Dummy protocol for TCP. */
  79. #define IPPROTO_ICMP 1 /* Internet Control Message Protocol. */
  80. #define IPPROTO_IGMP 2 /* Internet Group Management Protocol. */
  81. #define IPPROTO_IPIP 4 /* IPIP tunnels (older KA9Q tunnels use 94). */
  82. #define IPPROTO_TCP 6 /* Transmission Control Protocol. */
  83. #define IPPROTO_EGP 8 /* Exterior Gateway Protocol. */
  84. #define IPPROTO_PUP 12 /* PUP protocol. */
  85. #define IPPROTO_UDP 17 /* User Datagram Protocol. */
  86. #define IPPROTO_IDP 22 /* XNS IDP protocol. */
  87. #define IPPROTO_TP 29 /* SO Transport Protocol Class 4. */
  88. #define IPPROTO_DCCP 33 /* Datagram Congestion Control Protocol. */
  89. #define IPPROTO_IPV6 41 /* IPv6 header. */
  90. #define IPPROTO_RSVP 46 /* Reservation Protocol. */
  91. #define IPPROTO_GRE 47 /* General Routing Encapsulation. */
  92. #define IPPROTO_ESP 50 /* encapsulating security payload. */
  93. #define IPPROTO_AH 51 /* authentication header. */
  94. #define IPPROTO_MTP 92 /* Multicast Transport Protocol. */
  95. #define IPPROTO_BEETPH 94 /* IP option pseudo header for BEET. */
  96. #define IPPROTO_ENCAP 98 /* Encapsulation Header. */
  97. #define IPPROTO_PIM 103 /* Protocol Independent Multicast. */
  98. #define IPPROTO_COMP 108 /* Compression Header Protocol. */
  99. #define IPPROTO_SCTP 132 /* Stream Control Transmission Protocol. */
  100. #define IPPROTO_UDPLITE 136 /* UDP-Lite protocol. */
  101. #define IPPROTO_MPLS 137 /* MPLS in IP. */
  102. #define IPPROTO_RAW 255 /* Raw IP packets. */
  103. #define IP_ROUTER_ALERT 5 /* bool */
  104. #define IP_PKTINFO 8 /* bool */
  105. #define IP_PKTOPTIONS 9
  106. #define IP_PMTUDISC 10 /* obsolete name? */
  107. #define IP_MTU_DISCOVER 10 /* int; see below */
  108. #define IP_RECVERR 11 /* bool */
  109. #define IP_RECVTTL 12 /* bool */
  110. #define IP_RECVTOS 13 /* bool */
  111. #define IP_MTU 14 /* int */
  112. #define IP_FREEBIND 15
  113. #define IP_IPSEC_POLICY 16
  114. #define IP_XFRM_POLICY 17
  115. #define IP_PASSSEC 18
  116. #define IP_TRANSPARENT 19
  117. #define IP_MULTICAST_ALL 49 /* bool */
  118. /* TProxy original addresses */
  119. #define IP_ORIGDSTADDR 20
  120. #define IP_RECVORIGDSTADDR IP_ORIGDSTADDR
  121. #define IP_MINTTL 21
  122. #define IP_NODEFRAG 22
  123. #define IP_CHECKSUM 23
  124. #define IP_BIND_ADDRESS_NO_PORT 24
  125. #define IP_RECVFRAGSIZE 25
  126. #define IP_PMTUDISC_DONT 0
  127. #define IP_PMTUDISC_WANT 1
  128. #define IP_PMTUDISC_DO 2
  129. #define IP_PMTUDISC_PROBE 3
  130. #define IP_PMTUDISC_INTERFACE 4
  131. #define IP_PMTUDISC_OMIT 5
  132. #define IP_MULTICAST_IF 32
  133. #define IP_MULTICAST_TTL 33
  134. #define IP_MULTICAST_LOOP 34
  135. #define IP_ADD_MEMBERSHIP 35
  136. #define IP_DROP_MEMBERSHIP 36
  137. #define IP_UNBLOCK_SOURCE 37
  138. #define IP_BLOCK_SOURCE 38
  139. #define IP_ADD_SOURCE_MEMBERSHIP 39
  140. #define IP_DROP_SOURCE_MEMBERSHIP 40
  141. #define IP_MSFILTER 41
  142. #define IP_MULTICAST_ALL 49
  143. #define IP_UNICAST_IF 50
  144. #define IPV6_ADDRFORM 1
  145. #define IPV6_2292PKTINFO 2
  146. #define IPV6_2292HOPOPTS 3
  147. #define IPV6_2292DSTOPTS 4
  148. #define IPV6_2292RTHDR 5
  149. #define IPV6_2292PKTOPTIONS 6
  150. #define IPV6_CHECKSUM 7
  151. #define IPV6_2292HOPLIMIT 8
  152. #define SCM_SRCRT IPV6_RXSRCRT
  153. #define IPV6_NEXTHOP 9
  154. #define IPV6_AUTHHDR 10
  155. #define IPV6_UNICAST_HOPS 16
  156. #define IPV6_MULTICAST_IF 17
  157. #define IPV6_MULTICAST_HOPS 18
  158. #define IPV6_MULTICAST_LOOP 19
  159. #define IPV6_JOIN_GROUP 20
  160. #define IPV6_LEAVE_GROUP 21
  161. #define IPV6_ROUTER_ALERT 22
  162. #define IPV6_MTU_DISCOVER 23
  163. #define IPV6_MTU 24
  164. #define IPV6_RECVERR 25
  165. #define IPV6_V6ONLY 26
  166. #define IPV6_JOIN_ANYCAST 27
  167. #define IPV6_LEAVE_ANYCAST 28
  168. #define IPV6_MULTICAST_ALL 29
  169. #define IPV6_ROUTER_ALERT_ISOLATE 30
  170. #define IPV6_IPSEC_POLICY 34
  171. #define IPV6_XFRM_POLICY 35
  172. #define IPV6_HDRINCL 36
  173. /* Advanced API (RFC3542) (1). */
  174. #define IPV6_RECVPKTINFO 49
  175. #define IPV6_PKTINFO 50
  176. #define IPV6_RECVHOPLIMIT 51
  177. #define IPV6_HOPLIMIT 52
  178. #define IPV6_RECVHOPOPTS 53
  179. #define IPV6_HOPOPTS 54
  180. #define IPV6_RTHDRDSTOPTS 55
  181. #define IPV6_RECVRTHDR 56
  182. #define IPV6_RTHDR 57
  183. #define IPV6_RECVDSTOPTS 58
  184. #define IPV6_DSTOPTS 59
  185. #define IPV6_RECVPATHMTU 60
  186. #define IPV6_PATHMTU 61
  187. #define IPV6_DONTFRAG 62
  188. /* Advanced API (RFC3542) (2). */
  189. #define IPV6_RECVTCLASS 66
  190. #define IPV6_TCLASS 67
  191. #define IPV6_AUTOFLOWLABEL 70
  192. /* RFC5014. */
  193. #define IPV6_ADDR_PREFERENCES 72
  194. /* RFC5082. */
  195. #define IPV6_MINHOPCOUNT 73
  196. #define IPV6_ORIGDSTADDR 74
  197. #define IPV6_RECVORIGDSTADDR IPV6_ORIGDSTADDR
  198. #define IPV6_TRANSPARENT 75
  199. #define IPV6_UNICAST_IF 76
  200. #define IPV6_RECVFRAGSIZE 77
  201. #define IPV6_FREEBIND 78
  202. #define SOCK_STREAM 1
  203. #define SOCK_DGRAM 2
  204. #define MSG_OOB 0x0001
  205. #define MSG_PEEK 0x0002
  206. #define MSG_DONTROUTE 0x0004
  207. #define MSG_CTRUNC 0x0008
  208. #define MSG_PROXY 0x0010
  209. #define MSG_TRUNC 0x0020
  210. #define MSG_DONTWAIT 0x0040
  211. #define MSG_EOR 0x0080
  212. #define MSG_WAITALL 0x0100
  213. #define MSG_FIN 0x0200
  214. #define MSG_SYN 0x0400
  215. #define MSG_CONFIRM 0x0800
  216. #define MSG_RST 0x1000
  217. #define MSG_ERRQUEUE 0x2000
  218. #define MSG_NOSIGNAL 0x4000
  219. #define MSG_MORE 0x8000
  220. #define MSG_WAITFORONE 0x10000
  221. #define MSG_BATCH 0x40000
  222. #define MSG_FASTOPEN 0x20000000
  223. #define MSG_CMSG_CLOEXEC 0x40000000
  224. #define SHUT_RD 0
  225. #define SHUT_WR 1
  226. #define SHUT_RDWR 2
  227. /* Address families. */
  228. #define AF_INET 2 /* IP protocol family. */
  229. #define AF_INET6 10 /* IP version 6. */
  230. /* Standard well-defined IP protocols. */
  231. #define IPPROTO_TCP 6 /* Transmission Control Protocol. */
  232. /* Types of sockets. */
  233. #define SOCK_DGRAM \
  234. 2 /* Connectionless, unreliable datagrams of fixed maximum length. */
  235. struct msghdr {
  236. void *msg_name;
  237. socklen_t msg_namelen;
  238. struct iovec *msg_iov;
  239. int msg_iovlen;
  240. void *msg_control;
  241. socklen_t msg_controllen;
  242. int msg_flags;
  243. };
  244. /* Internet address. */
  245. struct in_addr {
  246. uint32_t s_addr;
  247. };
  248. typedef struct in_addr in_addr_t;
  249. /* Structure describing an Internet socket address. */
  250. #define __SOCK_SIZE__ 16 /* sizeof(struct sockaddr) */
  251. struct sockaddr_in {
  252. uint16_t sin_family;
  253. uint16_t sin_port; /* Port number. */
  254. struct in_addr sin_addr; /* Internet address. */
  255. /* Pad to size of `struct sockaddr'. */
  256. unsigned char__pad[__SOCK_SIZE__ - sizeof(uint16_t) - sizeof(uint16_t)
  257. - sizeof(struct in_addr)];
  258. };
  259. /* Structure used to manipulate the SO_LINGER option. */
  260. struct linger {
  261. int l_onoff; /* Nonzero to linger on close. */
  262. int l_linger; /* Time to linger. */
  263. };
  264. /* Structure describing a generic socket address. */
  265. struct sockaddr {
  266. unsigned short int sa_family; /* Common data: address family and length. */
  267. char sa_data[14]; /* Address data. */
  268. };
  269. uint32_t
  270. ntohl(uint32_t value);
  271. uint32_t
  272. htonl(uint32_t value);
  273. uint16_t
  274. htons(uint16_t value);
  275. int
  276. socket(int domain, int type, int protocol);
  277. int
  278. getsockopt(int sockfd, int level, int optname, void *optval, socklen_t *optlen);
  279. int
  280. setsockopt(int sockfd, int level, int optname, const void *optval,
  281. socklen_t optlen);
  282. ssize_t
  283. sendmsg(int sockfd, const struct msghdr *msg, int flags);
  284. ssize_t
  285. recvmsg(int sockfd, struct msghdr *msg, int flags);
  286. int
  287. shutdown(int sockfd, int how);
  288. #ifdef __cplusplus
  289. }
  290. #endif
  291. #endif /* end of _SGX_SOCKET_H */