in.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. //
  2. // Copyright 2026 Aarav Ravindra Kharade
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. /* Copyright (C) 1991-2026 Free Software Foundation, Inc.
  17. This file is part of the GNU C Library.
  18. The GNU C Library is free software; you can redistribute it and/or
  19. modify it under the terms of the GNU Lesser General Public
  20. License as published by the Free Software Foundation; either
  21. version 2.1 of the License, or (at your option) any later version.
  22. The GNU C Library is distributed in the hope that it will be useful,
  23. but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  25. Lesser General Public License for more details.
  26. You should have received a copy of the GNU Lesser General Public
  27. License along with the GNU C Library; if not, see
  28. <https://www.gnu.org/licenses/>. */
  29. /* Linux version. */
  30. #ifndef _NETINET_IN_H
  31. # error "Never use <bits/in.h> directly; include <netinet/in.h> instead."
  32. #endif
  33. /* If the application has already included linux/in6.h from a linux-based
  34. kernel then we will not define the IPv6 IPPROTO_* defines, in6_addr (nor the
  35. defines), sockaddr_in6, or ipv6_mreq. Same for in6_ptkinfo or ip6_mtuinfo
  36. in linux/ipv6.h. The ABI used by the linux-kernel and glibc match exactly.
  37. Neither the linux kernel nor glibc should break this ABI without coordination.
  38. In upstream kernel 56c176c9 the _UAPI prefix was stripped so we need to check
  39. for _LINUX_IN6_H and _IPV6_H now, and keep checking the old versions for
  40. maximum backwards compatibility. */
  41. #if defined _UAPI_LINUX_IN6_H \
  42. || defined _UAPI_IPV6_H \
  43. || defined _LINUX_IN6_H \
  44. || defined _IPV6_H
  45. /* This is not quite the same API since the kernel always defines s6_addr16 and
  46. s6_addr32. This is not a violation of POSIX since POSIX says "at least the
  47. following member" and that holds true. */
  48. # define __USE_KERNEL_IPV6_DEFS 1
  49. #else
  50. # define __USE_KERNEL_IPV6_DEFS 0
  51. #endif
  52. /* Options for use with `getsockopt' and `setsockopt' at the IP level.
  53. The first word in the comment at the right is the data type used;
  54. "bool" means a boolean value stored in an `int'. */
  55. #define IP_OPTIONS 4 /* ip_opts; IP per-packet options. */
  56. #define IP_HDRINCL 3 /* int; Header is included with data. */
  57. #define IP_TOS 1 /* int; IP type of service and precedence. */
  58. #define IP_TTL 2 /* int; IP time to live. */
  59. #define IP_RECVOPTS 6 /* bool; Receive all IP options w/datagram. */
  60. /* For BSD compatibility. */
  61. #define IP_RECVRETOPTS IP_RETOPTS /* bool; Receive IP options for response. */
  62. #define IP_RETOPTS 7 /* ip_opts; Set/get IP per-packet options. */
  63. #define IP_MULTICAST_IF 32 /* in_addr; set/get IP multicast i/f */
  64. #define IP_MULTICAST_TTL 33 /* unsigned char; set/get IP multicast ttl */
  65. #define IP_MULTICAST_LOOP 34 /* bool; set/get IP multicast loopback */
  66. #define IP_ADD_MEMBERSHIP 35 /* ip_mreq; add an IP group membership */
  67. #define IP_DROP_MEMBERSHIP 36 /* ip_mreq; drop an IP group membership */
  68. #define IP_UNBLOCK_SOURCE 37 /* ip_mreq_source: unblock data from source */
  69. #define IP_BLOCK_SOURCE 38 /* ip_mreq_source: block data from source */
  70. #define IP_ADD_SOURCE_MEMBERSHIP 39 /* ip_mreq_source: join source group */
  71. #define IP_DROP_SOURCE_MEMBERSHIP 40 /* ip_mreq_source: leave source group */
  72. #define IP_MSFILTER 41
  73. #ifdef __USE_MISC
  74. # define MCAST_JOIN_GROUP 42 /* group_req: join any-source group */
  75. # define MCAST_BLOCK_SOURCE 43 /* group_source_req: block from given group */
  76. # define MCAST_UNBLOCK_SOURCE 44 /* group_source_req: unblock from given group*/
  77. # define MCAST_LEAVE_GROUP 45 /* group_req: leave any-source group */
  78. # define MCAST_JOIN_SOURCE_GROUP 46 /* group_source_req: join source-spec gr */
  79. # define MCAST_LEAVE_SOURCE_GROUP 47 /* group_source_req: leave source-spec gr*/
  80. # define MCAST_MSFILTER 48
  81. # define IP_MULTICAST_ALL 49
  82. # define IP_UNICAST_IF 50
  83. # define MCAST_EXCLUDE 0
  84. # define MCAST_INCLUDE 1
  85. #endif
  86. #define IP_ROUTER_ALERT 5 /* bool */
  87. #define IP_PKTINFO 8 /* bool */
  88. #define IP_PKTOPTIONS 9
  89. #define IP_PMTUDISC 10 /* obsolete name? */
  90. #define IP_MTU_DISCOVER 10 /* int; see below */
  91. #define IP_RECVERR 11 /* bool */
  92. #define IP_RECVTTL 12 /* bool */
  93. #define IP_RECVTOS 13 /* bool */
  94. #define IP_MTU 14 /* int */
  95. #define IP_FREEBIND 15
  96. #define IP_IPSEC_POLICY 16
  97. #define IP_XFRM_POLICY 17
  98. #define IP_PASSSEC 18
  99. #define IP_TRANSPARENT 19
  100. #define IP_MULTICAST_ALL 49 /* bool */
  101. /* TProxy original addresses */
  102. #define IP_ORIGDSTADDR 20
  103. #define IP_RECVORIGDSTADDR IP_ORIGDSTADDR
  104. #define IP_MINTTL 21
  105. #define IP_NODEFRAG 22
  106. #define IP_CHECKSUM 23
  107. #define IP_BIND_ADDRESS_NO_PORT 24
  108. #define IP_RECVFRAGSIZE 25
  109. #define IP_RECVERR_RFC4884 26
  110. /* IP_MTU_DISCOVER arguments. */
  111. #define IP_PMTUDISC_DONT 0 /* Never send DF frames. */
  112. #define IP_PMTUDISC_WANT 1 /* Use per route hints. */
  113. #define IP_PMTUDISC_DO 2 /* Always DF. */
  114. #define IP_PMTUDISC_PROBE 3 /* Ignore dst pmtu. */
  115. /* Always use interface mtu (ignores dst pmtu) but don't set DF flag.
  116. Also incoming ICMP frag_needed notifications will be ignored on
  117. this socket to prevent accepting spoofed ones. */
  118. #define IP_PMTUDISC_INTERFACE 4
  119. /* Like IP_PMTUDISC_INTERFACE but allow packets to be fragmented. */
  120. #define IP_PMTUDISC_OMIT 5
  121. #define IP_MULTICAST_IF 32
  122. #define IP_MULTICAST_TTL 33
  123. #define IP_MULTICAST_LOOP 34
  124. #define IP_ADD_MEMBERSHIP 35
  125. #define IP_DROP_MEMBERSHIP 36
  126. #define IP_UNBLOCK_SOURCE 37
  127. #define IP_BLOCK_SOURCE 38
  128. #define IP_ADD_SOURCE_MEMBERSHIP 39
  129. #define IP_DROP_SOURCE_MEMBERSHIP 40
  130. #define IP_MSFILTER 41
  131. #define IP_MULTICAST_ALL 49
  132. #define IP_UNICAST_IF 50
  133. #define IP_LOCAL_PORT_RANGE 51
  134. #define IP_PROTOCOL 52
  135. /* To select the IP level. */
  136. #define SOL_IP 0
  137. #define IP_DEFAULT_MULTICAST_TTL 1
  138. #define IP_DEFAULT_MULTICAST_LOOP 1
  139. #define IP_MAX_MEMBERSHIPS 20
  140. #ifdef __USE_MISC
  141. /* Structure used to describe IP options for IP_OPTIONS and IP_RETOPTS.
  142. The `ip_dst' field is used for the first-hop gateway when using a
  143. source route (this gets put into the header proper). */
  144. struct ip_opts
  145. {
  146. struct in_addr ip_dst; /* First hop; zero without source route. */
  147. char ip_opts[40]; /* Actually variable in size. */
  148. };
  149. /* Structure used for IP_PKTINFO. */
  150. struct in_pktinfo
  151. {
  152. int ipi_ifindex; /* Interface index */
  153. struct in_addr ipi_spec_dst; /* Routing destination address */
  154. struct in_addr ipi_addr; /* Header destination address */
  155. };
  156. #endif
  157. /* Options for use with `getsockopt' and `setsockopt' at the IPv6 level.
  158. The first word in the comment at the right is the data type used;
  159. "bool" means a boolean value stored in an `int'. */
  160. #define IPV6_ADDRFORM 1
  161. #define IPV6_2292PKTINFO 2
  162. #define IPV6_2292HOPOPTS 3
  163. #define IPV6_2292DSTOPTS 4
  164. #define IPV6_2292RTHDR 5
  165. #define IPV6_2292PKTOPTIONS 6
  166. #define IPV6_CHECKSUM 7
  167. #define IPV6_2292HOPLIMIT 8
  168. #define SCM_SRCRT IPV6_RXSRCRT
  169. #define IPV6_NEXTHOP 9
  170. #define IPV6_AUTHHDR 10
  171. #define IPV6_UNICAST_HOPS 16
  172. #define IPV6_MULTICAST_IF 17
  173. #define IPV6_MULTICAST_HOPS 18
  174. #define IPV6_MULTICAST_LOOP 19
  175. #define IPV6_JOIN_GROUP 20
  176. #define IPV6_LEAVE_GROUP 21
  177. #define IPV6_ROUTER_ALERT 22
  178. #define IPV6_MTU_DISCOVER 23
  179. #define IPV6_MTU 24
  180. #define IPV6_RECVERR 25
  181. #define IPV6_V6ONLY 26
  182. #define IPV6_JOIN_ANYCAST 27
  183. #define IPV6_LEAVE_ANYCAST 28
  184. #define IPV6_MULTICAST_ALL 29
  185. #define IPV6_ROUTER_ALERT_ISOLATE 30
  186. #define IPV6_RECVERR_RFC4884 31
  187. #define IPV6_IPSEC_POLICY 34
  188. #define IPV6_XFRM_POLICY 35
  189. #define IPV6_HDRINCL 36
  190. /* Advanced API (RFC3542) (1). */
  191. #define IPV6_RECVPKTINFO 49
  192. #define IPV6_PKTINFO 50
  193. #define IPV6_RECVHOPLIMIT 51
  194. #define IPV6_HOPLIMIT 52
  195. #define IPV6_RECVHOPOPTS 53
  196. #define IPV6_HOPOPTS 54
  197. #define IPV6_RTHDRDSTOPTS 55
  198. #define IPV6_RECVRTHDR 56
  199. #define IPV6_RTHDR 57
  200. #define IPV6_RECVDSTOPTS 58
  201. #define IPV6_DSTOPTS 59
  202. #define IPV6_RECVPATHMTU 60
  203. #define IPV6_PATHMTU 61
  204. #define IPV6_DONTFRAG 62
  205. /* Advanced API (RFC3542) (2). */
  206. #define IPV6_RECVTCLASS 66
  207. #define IPV6_TCLASS 67
  208. #define IPV6_AUTOFLOWLABEL 70
  209. /* RFC5014. */
  210. #define IPV6_ADDR_PREFERENCES 72
  211. /* RFC5082. */
  212. #define IPV6_MINHOPCOUNT 73
  213. #define IPV6_ORIGDSTADDR 74
  214. #define IPV6_RECVORIGDSTADDR IPV6_ORIGDSTADDR
  215. #define IPV6_TRANSPARENT 75
  216. #define IPV6_UNICAST_IF 76
  217. #define IPV6_RECVFRAGSIZE 77
  218. #define IPV6_FREEBIND 78
  219. /* Obsolete synonyms for the above. */
  220. #if !__USE_KERNEL_IPV6_DEFS
  221. # define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP
  222. # define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP
  223. #endif
  224. #define IPV6_RXHOPOPTS IPV6_HOPOPTS
  225. #define IPV6_RXDSTOPTS IPV6_DSTOPTS
  226. /* IPV6_MTU_DISCOVER values. */
  227. #define IPV6_PMTUDISC_DONT 0 /* Never send DF frames. */
  228. #define IPV6_PMTUDISC_WANT 1 /* Use per route hints. */
  229. #define IPV6_PMTUDISC_DO 2 /* Always DF. */
  230. #define IPV6_PMTUDISC_PROBE 3 /* Ignore dst pmtu. */
  231. #define IPV6_PMTUDISC_INTERFACE 4 /* See IP_PMTUDISC_INTERFACE. */
  232. #define IPV6_PMTUDISC_OMIT 5 /* See IP_PMTUDISC_OMIT. */
  233. /* Socket level values for IPv6. */
  234. #define SOL_IPV6 41
  235. #define SOL_ICMPV6 58
  236. /* Routing header options for IPv6. */
  237. #define IPV6_RTHDR_LOOSE 0 /* Hop doesn't need to be neighbour. */
  238. #define IPV6_RTHDR_STRICT 1 /* Hop must be a neighbour. */
  239. #define IPV6_RTHDR_TYPE_0 0 /* IPv6 Routing header type 0. */