PageRenderTime 28ms CodeModel.GetById 5ms RepoModel.GetById 1ms app.codeStats 0ms

sys/netinet/ip_var.h

http://www.minix3.org/
C Header | 232 lines | 149 code | 20 blank | 63 comment | 0 complexity | 7c928efedd77c0991a4542a534c886fb MD5 | raw file
Possible License(s): MIT, WTFPL, AGPL-1.0, BSD-3-Clause, GPL-3.0, LGPL-2.0, JSON, 0BSD
  1. /* $NetBSD: ip_var.h,v 1.97 2011/05/03 17:44:31 dyoung Exp $ */
  2. /*
  3. * Copyright (c) 1982, 1986, 1993
  4. * The Regents of the University of California. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. Neither the name of the University nor the names of its contributors
  15. * may be used to endorse or promote products derived from this software
  16. * without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  22. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  23. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  24. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  25. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  26. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  27. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  28. * SUCH DAMAGE.
  29. *
  30. * @(#)ip_var.h 8.2 (Berkeley) 1/9/95
  31. */
  32. #ifndef _NETINET_IP_VAR_H_
  33. #define _NETINET_IP_VAR_H_
  34. #include <sys/queue.h>
  35. #include <net/route.h>
  36. /*
  37. * Overlay for ip header used by other protocols (tcp, udp).
  38. */
  39. struct ipovly {
  40. u_int8_t ih_x1[9]; /* (unused) */
  41. u_int8_t ih_pr; /* protocol */
  42. u_int16_t ih_len; /* protocol length */
  43. struct in_addr ih_src; /* source internet address */
  44. struct in_addr ih_dst; /* destination internet address */
  45. } __packed;
  46. /*
  47. * IP sequence queue structure.
  48. *
  49. * XXX -- The following explains why the ipqe_m field is here, for TCP's use:
  50. * We want to avoid doing m_pullup on incoming packets but that
  51. * means avoiding dtom on the tcp reassembly code. That in turn means
  52. * keeping an mbuf pointer in the reassembly queue (since we might
  53. * have a cluster). As a quick hack, the source & destination
  54. * port numbers (which are no longer needed once we've located the
  55. * tcpcb) are overlayed with an mbuf pointer.
  56. */
  57. TAILQ_HEAD(ipqehead, ipqent);
  58. struct ipqent {
  59. TAILQ_ENTRY(ipqent) ipqe_q;
  60. union {
  61. struct ip *_ip;
  62. struct tcpiphdr *_tcp;
  63. } _ipqe_u1;
  64. struct mbuf *ipqe_m; /* point to first mbuf */
  65. struct mbuf *ipre_mlast; /* point to last mbuf */
  66. u_int8_t ipqe_mff; /* for IP fragmentation */
  67. /*
  68. * The following are used in TCP reassembly
  69. */
  70. TAILQ_ENTRY(ipqent) ipqe_timeq;
  71. u_int32_t ipqe_seq;
  72. u_int32_t ipqe_len;
  73. u_int32_t ipqe_flags;
  74. };
  75. #define ipqe_tcp _ipqe_u1._tcp
  76. /*
  77. * Structure stored in mbuf in inpcb.ip_options
  78. * and passed to ip_output when ip options are in use.
  79. * The actual length of the options (including ipopt_dst)
  80. * is in m_len.
  81. */
  82. #define MAX_IPOPTLEN 40
  83. struct ipoption {
  84. struct in_addr ipopt_dst; /* first-hop dst if source routed */
  85. int8_t ipopt_list[MAX_IPOPTLEN]; /* options proper */
  86. };
  87. /*
  88. * Structure attached to inpcb.ip_moptions and
  89. * passed to ip_output when IP multicast options are in use.
  90. */
  91. struct ip_moptions {
  92. struct ifnet *imo_multicast_ifp; /* ifp for outgoing multicasts */
  93. struct in_addr imo_multicast_addr; /* ifindex/addr on MULTICAST_IF */
  94. u_int8_t imo_multicast_ttl; /* TTL for outgoing multicasts */
  95. u_int8_t imo_multicast_loop; /* 1 => hear sends if a member */
  96. u_int16_t imo_num_memberships; /* no. memberships this socket */
  97. struct in_multi *imo_membership[IP_MAX_MEMBERSHIPS];
  98. };
  99. /*
  100. * IP statistics.
  101. * Each counter is an unsigned 64-bit value.
  102. */
  103. #define IP_STAT_TOTAL 0 /* total packets received */
  104. #define IP_STAT_BADSUM 1 /* checksum bad */
  105. #define IP_STAT_TOOSHORT 2 /* packet too short */
  106. #define IP_STAT_TOOSMALL 3 /* not enough data */
  107. #define IP_STAT_BADHLEN 4 /* ip header length < data size */
  108. #define IP_STAT_BADLEN 5 /* ip length < ip header length */
  109. #define IP_STAT_FRAGMENTS 6 /* fragments received */
  110. #define IP_STAT_FRAGDROPPED 7 /* frags dropped (dups, out of space) */
  111. #define IP_STAT_FRAGTIMEOUT 8 /* fragments timed out */
  112. #define IP_STAT_FORWARD 9 /* packets forwarded */
  113. #define IP_STAT_FASTFORWARD 10 /* packets fast forwarded */
  114. #define IP_STAT_CANTFORWARD 11 /* packets rcvd for unreachable dest */
  115. #define IP_STAT_REDIRECTSENT 12 /* packets forwareded on same net */
  116. #define IP_STAT_NOPROTO 13 /* unknown or unsupported protocol */
  117. #define IP_STAT_DELIVERED 14 /* datagrams delivered to upper level */
  118. #define IP_STAT_LOCALOUT 15 /* total ip packets generated here */
  119. #define IP_STAT_ODROPPED 16 /* lost packets due to nobufs, etc. */
  120. #define IP_STAT_REASSEMBLED 17 /* total packets reassembled ok */
  121. #define IP_STAT_FRAGMENTED 18 /* datagrams successfully fragmented */
  122. #define IP_STAT_OFRAGMENTS 19 /* output fragments created */
  123. #define IP_STAT_CANTFRAG 20 /* don't fragment flag was set, etc. */
  124. #define IP_STAT_BADOPTIONS 21 /* error in option processing */
  125. #define IP_STAT_NOROUTE 22 /* packets discarded due to no route */
  126. #define IP_STAT_BADVERS 23 /* ip version != 4 */
  127. #define IP_STAT_RAWOUT 24 /* total raw ip packets generated */
  128. #define IP_STAT_BADFRAGS 25 /* malformed fragments (bad length) */
  129. #define IP_STAT_RCVMEMDROP 26 /* frags dropped for lack of memory */
  130. #define IP_STAT_TOOLONG 27 /* ip length > max ip packet size */
  131. #define IP_STAT_NOGIF 28 /* no match gif found */
  132. #define IP_STAT_BADADDR 29 /* invalid address on header */
  133. #define IP_NSTATS 30
  134. #ifdef _KERNEL
  135. #ifdef _KERNEL_OPT
  136. #include "opt_gateway.h"
  137. #include "opt_mbuftrace.h"
  138. #endif
  139. /* flags passed to ip_output as last parameter */
  140. #define IP_FORWARDING 0x1 /* most of ip header exists */
  141. #define IP_RAWOUTPUT 0x2 /* raw ip header exists */
  142. #define IP_RETURNMTU 0x4 /* pass back mtu on EMSGSIZE */
  143. #define IP_NOIPNEWID 0x8 /* don't fill in ip_id */
  144. #define IP_ROUTETOIF SO_DONTROUTE /* bypass routing tables */
  145. #define IP_ALLOWBROADCAST SO_BROADCAST /* can send broadcast packets */
  146. #define IP_MTUDISC 0x0400 /* Path MTU Discovery; set DF */
  147. extern struct domain inetdomain;
  148. extern int ip_defttl; /* default IP ttl */
  149. extern int ipforwarding; /* ip forwarding */
  150. extern int ip_mtudisc; /* mtu discovery */
  151. extern int ip_mtudisc_timeout; /* seconds to timeout mtu discovery */
  152. extern int anonportmin; /* minimum ephemeral port */
  153. extern int anonportmax; /* maximum ephemeral port */
  154. extern int lowportmin; /* minimum reserved port */
  155. extern int lowportmax; /* maximum reserved port */
  156. extern int ip_do_loopback_cksum; /* do IP checksum on loopback? */
  157. extern struct rttimer_queue *ip_mtudisc_timeout_q;
  158. #ifdef MBUFTRACE
  159. extern struct mowner ip_rx_mowner;
  160. extern struct mowner ip_tx_mowner;
  161. #endif
  162. #ifdef GATEWAY
  163. extern int ip_maxflows;
  164. extern int ip_hashsize;
  165. #endif
  166. extern struct pool inmulti_pool;
  167. struct inpcb;
  168. struct sockopt;
  169. int ip_ctloutput(int, struct socket *, struct sockopt *);
  170. int ip_dooptions(struct mbuf *);
  171. void ip_drain(void);
  172. void ip_drainstub(void);
  173. void ip_forward(struct mbuf *, int);
  174. void ip_freemoptions(struct ip_moptions *);
  175. int ip_getmoptions(struct ip_moptions *, struct sockopt *);
  176. void ip_init(void);
  177. int ip_optcopy(struct ip *, struct ip *);
  178. u_int ip_optlen(struct inpcb *);
  179. int ip_output(struct mbuf *, ...);
  180. int ip_fragment(struct mbuf *, struct ifnet *, u_long);
  181. int ip_pcbopts(struct mbuf **, const struct sockopt *);
  182. void ip_reass_init(void);
  183. int ip_reass_packet(struct mbuf **, struct ip *);
  184. void ip_reass_slowtimo(void);
  185. void ip_reass_drain(void);
  186. struct in_ifaddr *
  187. ip_rtaddr(struct in_addr);
  188. void ip_savecontrol(struct inpcb *, struct mbuf **, struct ip *,
  189. struct mbuf *);
  190. int ip_setmoptions(struct ip_moptions **, const struct sockopt *);
  191. void ip_slowtimo(void);
  192. void ip_fasttimo(void);
  193. struct mbuf *
  194. ip_srcroute(void);
  195. int ip_sysctl(int *, u_int, void *, size_t *, void *, size_t);
  196. void ip_statinc(u_int);
  197. void ipintr(void);
  198. void * rip_ctlinput(int, const struct sockaddr *, void *);
  199. int rip_ctloutput(int, struct socket *, struct sockopt *);
  200. void rip_init(void);
  201. void rip_input(struct mbuf *, ...);
  202. int rip_output(struct mbuf *, ...);
  203. int rip_usrreq(struct socket *,
  204. int, struct mbuf *, struct mbuf *, struct mbuf *, struct lwp *);
  205. int ipflow_init(int);
  206. void ipflow_poolinit(void);
  207. void ipflow_prune(void);
  208. void ipflow_create(const struct route *, struct mbuf *);
  209. void ipflow_slowtimo(void);
  210. int ipflow_invalidate_all(int);
  211. #endif /* _KERNEL */
  212. #endif /* !_NETINET_IP_VAR_H_ */