if_gre.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /* $OpenBSD: if_gre.h,v 1.13 2010/06/26 19:49:54 claudio Exp $ */
  2. /* $NetBSD: if_gre.h,v 1.5 1999/11/19 20:41:19 thorpej Exp $ */
  3. /*
  4. * Copyright (c) 1998 The NetBSD Foundation, Inc.
  5. * All rights reserved
  6. *
  7. * This code is derived from software contributed to The NetBSD Foundation
  8. * by Heiko W.Rupp <hwr@pilhuhn.de>
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in the
  17. * documentation and/or other materials provided with the distribution.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  20. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  21. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  22. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
  23. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  24. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  25. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  26. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  27. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  28. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  29. * POSSIBILITY OF SUCH DAMAGE.
  30. */
  31. #ifndef _NET_IF_GRE_H
  32. #define _NET_IF_GRE_H
  33. struct gre_softc {
  34. struct ifnet sc_if;
  35. LIST_ENTRY(gre_softc) sc_list;
  36. struct timeout sc_ka_hold;
  37. struct timeout sc_ka_snd;
  38. struct in_addr g_src; /* source address of gre packets */
  39. struct in_addr g_dst; /* destination address of gre packets */
  40. struct route route; /* routing entry that determines, where
  41. an encapsulated packet should go */
  42. u_int g_rtableid; /* routing table used for the tunnel */
  43. int gre_unit;
  44. int gre_flags;
  45. int sc_ka_timout;
  46. int sc_ka_holdmax;
  47. int sc_ka_holdcnt;
  48. int sc_ka_cnt;
  49. u_char g_proto; /* protocol of encapsulator */
  50. u_char sc_ka_state;
  51. #define GRE_STATE_UKNWN 0
  52. #define GRE_STATE_DOWN 1
  53. #define GRE_STATE_HOLD 2
  54. #define GRE_STATE_UP 3
  55. };
  56. struct gre_h {
  57. u_int16_t flags; /* GRE flags */
  58. u_int16_t ptype; /* protocol type of payload typically
  59. Ether protocol type*/
  60. /*
  61. * from here on: fields are optional, presence indicated by flags
  62. *
  63. u_int_16 checksum checksum (one-complements of GRE header
  64. and payload
  65. Present if (ck_pres | rt_pres == 1).
  66. Valid if (ck_pres == 1).
  67. u_int_16 offset offset from start of routing filed to
  68. first octet of active SRE (see below).
  69. Present if (ck_pres | rt_pres == 1).
  70. Valid if (rt_pres == 1).
  71. u_int_32 key inserted by encapsulator e.g. for
  72. authentication
  73. Present if (key_pres ==1 ).
  74. u_int_32 seq_num Sequence number to allow for packet order
  75. Present if (seq_pres ==1 ).
  76. struct gre_sre[] routing Routing fileds (see below)
  77. Present if (rt_pres == 1)
  78. */
  79. } __packed;
  80. struct greip {
  81. struct ip gi_i;
  82. struct gre_h gi_g;
  83. } __packed;
  84. #define gi_pr gi_i.ip_p
  85. #define gi_len gi_i.ip_len
  86. #define gi_src gi_i.ip_src
  87. #define gi_dst gi_i.ip_dst
  88. #define gi_ptype gi_g.ptype
  89. #define gi_flags gi_g.flags
  90. #define GRE_CP 0x8000 /* Checksum Present */
  91. #define GRE_RP 0x4000 /* Routing Present */
  92. #define GRE_KP 0x2000 /* Key Present */
  93. #define GRE_SP 0x1000 /* Sequence Present */
  94. #define GRE_SS 0x0800 /* Strict Source Route */
  95. /* gre_sre defines a Source route Entry. These are needed if packets
  96. * should be routed over more than one tunnel hop by hop
  97. */
  98. struct gre_sre {
  99. u_int16_t sre_family; /* address family */
  100. u_char sre_offset; /* offset to first octet of active entry */
  101. u_char sre_length; /* number of octets in the SRE.
  102. sre_lengthl==0 -> last entry. */
  103. u_char *sre_rtinfo; /* the routing information */
  104. };
  105. struct greioctl {
  106. int unit;
  107. struct in_addr addr;
  108. };
  109. /* for mobile encaps */
  110. struct mobile_h {
  111. u_int16_t proto; /* protocol and S-bit */
  112. u_int16_t hcrc; /* header checksum */
  113. u_int32_t odst; /* original destination address */
  114. u_int32_t osrc; /* original source addr, if S-bit set */
  115. } __packed;
  116. struct mobip_h {
  117. struct ip mi;
  118. struct mobile_h mh;
  119. } __packed;
  120. #define MOB_H_SIZ_S (sizeof(struct mobile_h) - sizeof(u_int32_t))
  121. #define MOB_H_SIZ_L (sizeof(struct mobile_h))
  122. #define MOB_H_SBIT 0x0080
  123. /*
  124. * ioctls needed to manipulate the interface
  125. */
  126. #ifdef _KERNEL
  127. extern LIST_HEAD(gre_softc_head, gre_softc) gre_softc_list;
  128. extern int gre_allow;
  129. extern int gre_wccp;
  130. extern int ip_mobile_allow;
  131. void greattach(int);
  132. int gre_ioctl(struct ifnet *, u_long, caddr_t);
  133. int gre_output(struct ifnet *, struct mbuf *, struct sockaddr *,
  134. struct rtentry *);
  135. u_int16_t gre_in_cksum(u_int16_t *, u_int);
  136. void gre_recv_keepalive(struct gre_softc *);
  137. #endif /* _KERNEL */
  138. #endif /* _NET_IF_GRE_H_ */