pipex.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /* $OpenBSD: pipex.h,v 1.19 2014/10/21 10:52:53 yasuoka Exp $ */
  2. /*
  3. * Copyright (c) 2009 Internet Initiative Japan Inc.
  4. * 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. *
  15. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  16. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  18. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  19. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  21. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  22. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  23. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  24. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  25. * SUCH DAMAGE.
  26. */
  27. #ifndef NET_PIPEX_H
  28. #define NET_PIPEX_H 1
  29. /*
  30. * Names for pipex sysctl objects
  31. */
  32. #define PIPEXCTL_ENABLE 1
  33. #define PIPEXCTL_INQ 2
  34. #define PIPEXCTL_OUTQ 3
  35. #define PIPEXCTL_MAXID 4
  36. #define PIPEXCTL_NAMES { \
  37. { 0, 0 }, \
  38. { "enable", CTLTYPE_INT }, \
  39. { "inq", CTLTYPE_NODE }, \
  40. { "outq", CTLTYPE_NODE }, \
  41. }
  42. #define PIPEX_PROTO_L2TP 1 /* protocol L2TP */
  43. #define PIPEX_PROTO_PPTP 2 /* protocol PPTP */
  44. #define PIPEX_PROTO_PPPOE 3 /* protocol PPPoE */
  45. #define PIPEX_MAX_LISTREQ 128 /* list request size */
  46. #define PIPEX_MPPE_KEYLEN 16
  47. /* pipex_mppe */
  48. struct pipex_mppe_req {
  49. int16_t stateless; /* mppe key mode.
  50. 1 for stateless */
  51. int16_t keylenbits; /* mppe key length(in bits)*/
  52. u_char master_key[PIPEX_MPPE_KEYLEN]; /* mppe mastter key */
  53. };
  54. /* pipex statistics */
  55. struct pipex_statistics {
  56. uint32_t ipackets; /* packets received from tunnel */
  57. uint32_t ierrors; /* error packets received from tunnel */
  58. uint64_t ibytes; /* number of received bytes from tunnel */
  59. uint32_t opackets; /* packets sent to tunnel */
  60. uint32_t oerrors; /* error packets on sending to tunnel */
  61. uint64_t obytes; /* number of sent bytes to tunnel */
  62. uint32_t idle_time; /* idle time in seconds */
  63. };
  64. struct pipex_session_req {
  65. int pr_protocol; /* tunnel protocol */
  66. /* u_int pr_rdomain; */ /* rdomain id */
  67. uint16_t pr_session_id; /* session-id */
  68. uint16_t pr_peer_session_id; /* peer's session-id */
  69. uint32_t pr_ppp_flags; /* PPP configuration flags */
  70. #define PIPEX_PPP_ACFC_ACCEPTED 0x0001 /* ACFC accepted */
  71. #define PIPEX_PPP_PFC_ACCEPTED 0x0002 /* PFC accepted */
  72. #define PIPEX_PPP_ACFC_ENABLED 0x0004 /* ACFC enabled */
  73. #define PIPEX_PPP_PFC_ENABLED 0x0008 /* PFC enabled */
  74. #define PIPEX_PPP_MPPE_ACCEPTED 0x0010 /* MPPE accepted */
  75. #define PIPEX_PPP_MPPE_ENABLED 0x0020 /* MPPE enabled */
  76. #define PIPEX_PPP_MPPE_REQUIRED 0x0040 /* MPPE is required */
  77. #define PIPEX_PPP_HAS_ACF 0x0080 /* has ACF */
  78. #define PIPEX_PPP_ADJUST_TCPMSS 0x0100 /* do tcpmss adjustment */
  79. #define PIPEX_PPP_INGRESS_FILTER 0x0200 /* do ingress filter */
  80. int8_t pr_ccp_id; /* CCP current packet id */
  81. int pr_ppp_id; /* PPP Id. */
  82. uint16_t pr_peer_mru; /* Peer's MRU */
  83. uint32_t pr_timeout_sec; /* Idle Timer */
  84. struct in_addr pr_ip_srcaddr; /* local framed IP-Address */
  85. struct in_addr pr_ip_address; /* framed IP-Address */
  86. struct in_addr pr_ip_netmask; /* framed IP-Netmask */
  87. struct sockaddr_in6 pr_ip6_address; /* framed IPv6-Address */
  88. int pr_ip6_prefixlen; /* framed IPv6-Prefixlen */
  89. union {
  90. struct {
  91. uint32_t snd_nxt; /* send next */
  92. uint32_t rcv_nxt; /* receive next */
  93. uint32_t snd_una; /* unacked */
  94. uint32_t rcv_acked; /* recv acked */
  95. int winsz; /* window size */
  96. int maxwinsz; /* max window size */
  97. int peer_maxwinsz; /* peer's max window size */
  98. } pptp;
  99. struct {
  100. uint32_t option_flags;
  101. #define PIPEX_L2TP_USE_SEQUENCING 0x00000001
  102. uint16_t tunnel_id; /* our tunnel-id */
  103. uint16_t peer_tunnel_id;/* peer's tunnel-id */
  104. uint32_t ns_nxt; /* send next */
  105. uint32_t nr_nxt; /* receive next */
  106. uint32_t ns_una; /* unacked */
  107. uint32_t nr_acked; /* recv acked */
  108. uint32_t ipsecflowinfo; /* IPsec flow id for NAT-T */
  109. } l2tp;
  110. struct {
  111. char over_ifname[IF_NAMESIZE]; /* ethernet ifname */
  112. } pppoe;
  113. } pr_proto;
  114. struct sockaddr_storage pr_peer_address; /* peer address of tunnel */
  115. struct sockaddr_storage pr_local_address; /* our address of tunnel */
  116. struct pipex_mppe_req pr_mppe_recv; /* mppe key for receive */
  117. struct pipex_mppe_req pr_mppe_send; /* mppe key for send */
  118. };
  119. struct pipex_session_stat_req {
  120. int psr_protocol; /* tunnel protocol */
  121. uint16_t psr_session_id; /* session-id */
  122. struct pipex_statistics psr_stat; /* statistics */
  123. };
  124. struct pipex_session_close_req {
  125. int psr_protocol; /* tunnel protocol */
  126. uint16_t psr_session_id; /* session-id */
  127. struct pipex_statistics psr_stat; /* statistics */
  128. };
  129. #define pcr_protocol psr_protocol
  130. #define pcr_session_id psr_session_id
  131. #define pcr_stat psr_stat
  132. struct pipex_session_list_req {
  133. uint8_t plr_flags;
  134. #define PIPEX_LISTREQ_MORE 0x01
  135. int plr_ppp_id_count; /* count of PPP id */
  136. int plr_ppp_id[PIPEX_MAX_LISTREQ]; /* PPP id */
  137. };
  138. struct pipex_session_config_req {
  139. int pcr_protocol; /* tunnel protocol */
  140. uint16_t pcr_session_id; /* session-id */
  141. int pcr_ip_forward; /* ip_forwarding on/off */
  142. };
  143. /* for pppx(4) */
  144. struct pppx_hdr {
  145. u_int32_t pppx_proto;
  146. u_int32_t pppx_id;
  147. };
  148. struct pipex_session_descr_req {
  149. int pdr_protocol; /* tunnel protocol */
  150. uint16_t pdr_session_id; /* session-id */
  151. char pdr_descr[IFDESCRSIZE]; /* description */
  152. };
  153. /* PIPEX ioctls */
  154. #define PIPEXSMODE _IOW ('p', 1, int)
  155. #define PIPEXGMODE _IOR ('p', 2, int)
  156. #define PIPEXASESSION _IOW ('p', 3, struct pipex_session_req)
  157. #define PIPEXDSESSION _IOWR('p', 4, struct pipex_session_close_req)
  158. #define PIPEXCSESSION _IOW ('p', 5, struct pipex_session_config_req)
  159. #define PIPEXGSTAT _IOWR('p', 6, struct pipex_session_stat_req)
  160. #define PIPEXGCLOSED _IOR ('p', 7, struct pipex_session_list_req)
  161. #define PIPEXSIFDESCR _IOW ('p', 8, struct pipex_session_descr_req)
  162. #ifdef _KERNEL
  163. extern int pipex_enable;
  164. struct pipex_session;
  165. /* pipex context for a interface. */
  166. struct pipex_iface_context {
  167. struct ifnet *ifnet_this; /* outer interface */
  168. u_int pipexmode; /* pipex mode */
  169. /* virtual pipex_session entry for multicast routing */
  170. struct pipex_session *multicast_session;
  171. };
  172. __BEGIN_DECLS
  173. void pipex_init (void);
  174. void pipex_iface_init (struct pipex_iface_context *, struct ifnet *);
  175. void pipex_iface_fini (struct pipex_iface_context *);
  176. int pipex_notify_close_session(struct pipex_session *session);
  177. int pipex_notify_close_session_all(void);
  178. struct mbuf *pipex_output (struct mbuf *, int, int, struct pipex_iface_context *);
  179. struct pipex_session *pipex_pppoe_lookup_session (struct mbuf *);
  180. struct pipex_session *pipex_pppoe_lookup_session (struct mbuf *);
  181. struct mbuf *pipex_pppoe_input (struct mbuf *, struct pipex_session *);
  182. struct pipex_session *pipex_pptp_lookup_session (struct mbuf *);
  183. struct mbuf *pipex_pptp_input (struct mbuf *, struct pipex_session *);
  184. struct pipex_session *pipex_pptp_userland_lookup_session_ipv4 (struct mbuf *, struct in_addr);
  185. struct pipex_session *pipex_pptp_userland_lookup_session_ipv6 (struct mbuf *, struct in6_addr);
  186. struct pipex_session *pipex_l2tp_userland_lookup_session(struct mbuf *, struct sockaddr *);
  187. struct mbuf *pipex_pptp_userland_output (struct mbuf *, struct pipex_session *);
  188. struct pipex_session *pipex_l2tp_lookup_session (struct mbuf *, int);
  189. struct mbuf *pipex_l2tp_input (struct mbuf *, int off, struct pipex_session *, uint32_t);
  190. struct pipex_session *pipex_l2tp_userland_lookup_session_ipv4 (struct mbuf *, struct in_addr);
  191. struct pipex_session *pipex_l2tp_userland_lookup_session_ipv6 (struct mbuf *, struct in6_addr);
  192. struct mbuf *pipex_l2tp_userland_output (struct mbuf *, struct pipex_session *);
  193. int pipex_ioctl (struct pipex_iface_context *, u_long, caddr_t);
  194. void pipex_session_init_mppe_recv(struct pipex_session *, int,
  195. int, u_char *);
  196. void pipex_session_init_mppe_send(struct pipex_session *, int,
  197. int, u_char *);
  198. __END_DECLS
  199. #endif /* _KERNEL */
  200. #endif