1 /* $OpenBSD: pipex.h,v 1.12 2012/04/04 04:31:38 yasuoka Exp $ */ 2 3 /* 4 * Copyright (c) 2009 Internet Initiative Japan Inc. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29 #ifndef NET_PIPEX_H 30 #define NET_PIPEX_H 1 31 32 /* 33 * Names for pipex sysctl objects 34 */ 35 #define PIPEXCTL_ENABLE 1 36 #define PIPEXCTL_MAXID 2 37 38 #define PIPEXCTL_NAMES { \ 39 { 0, 0 }, \ 40 { "enable", CTLTYPE_INT }, \ 41 } 42 43 #define PIPEXCTL_VARS { \ 44 NULL, \ 45 &pipex_enable \ 46 NULL \ 47 } 48 49 #define PIPEX_ENABLE 1 50 #define PIPEX_DISABLE 0 51 52 #define PIPEX_PROTO_L2TP 0x0001 /* protocol L2TP */ 53 #define PIPEX_PROTO_PPTP 0x0002 /* protocol pptp */ 54 #define PIPEX_PROTO_PPPOE 0x0003 /* protocol pppoe */ 55 #define PIPEX_MAX_LISTREQ 128 /* list request size */ 56 #define PIPEX_MPPE_KEYLEN 16 57 58 /* pipex_mppe */ 59 struct pipex_mppe_req { 60 int16_t stateless; /* mppe key mode */ 61 int16_t keylenbits; /* mppe key length(in bits)*/ 62 u_char master_key[PIPEX_MPPE_KEYLEN]; /* mppe mastter key */ 63 }; 64 65 /* pppac ip-extension forwarded statistics */ 66 struct pipex_statistics { 67 uint32_t ipackets; /* tunnel to network */ 68 uint32_t ierrors; /* tunnel to network */ 69 uint64_t ibytes; /* tunnel to network */ 70 uint32_t opackets; /* network to tunnel */ 71 uint32_t oerrors; /* network to tunnel */ 72 uint64_t obytes; /* network to tunnel */ 73 74 uint32_t idle_time; /* idle timer */ 75 }; 76 77 struct pipex_session_req { 78 int pr_protocol; /* tunnel protocol */ 79 /* u_int pr_rdomain; */ /* rdomain id */ 80 uint16_t pr_session_id; /* session-id */ 81 uint16_t pr_peer_session_id; /* peer's session-id */ 82 uint32_t pr_ppp_flags; /* PPP configuration flags */ 83 #define PIPEX_PPP_ACFC_ACCEPTED 0x00000001 84 #define PIPEX_PPP_PFC_ACCEPTED 0x00000002 85 #define PIPEX_PPP_ACFC_ENABLED 0x00000004 86 #define PIPEX_PPP_PFC_ENABLED 0x00000008 87 #define PIPEX_PPP_MPPE_ACCEPTED 0x00000010 88 #define PIPEX_PPP_MPPE_ENABLED 0x00000020 89 #define PIPEX_PPP_MPPE_REQUIRED 0x00000040 90 #define PIPEX_PPP_HAS_ACF 0x00000080 91 #define PIPEX_PPP_ADJUST_TCPMSS 0x00000100 92 #define PIPEX_PPP_INGRESS_FILTER 0x00000200 93 int8_t pr_ccp_id; /* CCP current packet id */ 94 int pr_ppp_id; /* PPP Id. */ 95 uint16_t pr_peer_mru; /* Peer's MRU */ 96 uint16_t pr_timeout_sec; /* Idle Timer */ 97 98 struct in_addr pr_ip_srcaddr; /* local framed IP-Address */ 99 struct in_addr pr_ip_address; /* framed IP-Address */ 100 struct in_addr pr_ip_netmask; /* framed IP-Netmask */ 101 struct sockaddr_in6 pr_ip6_address; /* framed IPv6-Address */ 102 int pr_ip6_prefixlen; /* framed IPv6-Prefixlen */ 103 union { 104 struct { 105 uint32_t snd_nxt; /* send next */ 106 uint32_t rcv_nxt; /* receive next */ 107 uint32_t snd_una; /* unacked */ 108 uint32_t rcv_acked; /* recv acked */ 109 int winsz; /* window size */ 110 int maxwinsz; /* max window size */ 111 int peer_maxwinsz; /* peer's max window size */ 112 } pptp; 113 struct { 114 /* select protocol options: 1 for enable */ 115 uint32_t option_flags; 116 #define PIPEX_L2TP_USE_SEQUENCING 0x00000001 117 118 /* session keys */ 119 uint16_t tunnel_id; /* our tunnel-id */ 120 uint16_t peer_tunnel_id;/* peer's tunnel-id */ 121 uint32_t ns_nxt; /* send next */ 122 uint32_t nr_nxt; /* receive next */ 123 uint32_t ns_una; /* unacked */ 124 uint32_t nr_acked; /* recv acked */ 125 } l2tp; 126 struct { 127 char over_ifname[IF_NAMESIZE]; /* ethernet i/f name */ 128 } pppoe; 129 } pr_proto; 130 struct sockaddr_storage peer_address; 131 struct sockaddr_storage local_address; 132 struct pipex_mppe_req pr_mppe_recv; 133 struct pipex_mppe_req pr_mppe_send; 134 }; 135 136 struct pipex_session_stat_req { 137 int psr_protocol; /* tunnel protocol */ 138 uint16_t psr_session_id; /* session-id */ 139 struct pipex_statistics psr_stat; /* statistics */ 140 }; 141 #define pipex_session_close_req pipex_session_stat_req 142 #define pcr_protocol psr_protocol 143 #define pcr_session_id psr_session_id 144 #define pcr_stat psr_stat 145 146 struct pipex_session_list_req { 147 uint8_t plr_flags; 148 #define PIPEX_LISTREQ_NONE 0x00 149 #define PIPEX_LISTREQ_MORE 0x01 150 int plr_ppp_id_count; /* count of PPP id */ 151 int plr_ppp_id[PIPEX_MAX_LISTREQ]; /* PPP id */ 152 }; 153 154 struct pipex_session_config_req { 155 int pcr_protocol; /* tunnel protocol */ 156 uint16_t pcr_session_id; /* session-id */ 157 int pcr_ip_forward; /* ip_forwarding on/off */ 158 }; 159 160 /* for pppx(4) */ 161 struct pppx_hdr { 162 u_int32_t pppx_proto; 163 u_int32_t pppx_id; 164 }; 165 166 struct pipex_session_descr_req { 167 int pdr_protocol; /* tunnel protocol */ 168 uint16_t pdr_session_id; /* session-id */ 169 char pdr_descr[IFDESCRSIZE]; /* description */ 170 }; 171 172 173 /* PIPEX ioctls */ 174 #define PIPEXSMODE _IOW ('p', 1, int) 175 #define PIPEXGMODE _IOR ('p', 2, int) 176 #define PIPEXASESSION _IOW ('p', 3, struct pipex_session_req) 177 #define PIPEXDSESSION _IOWR('p', 4, struct pipex_session_close_req) 178 #define PIPEXCSESSION _IOW ('p', 5, struct pipex_session_config_req) 179 #define PIPEXGSTAT _IOWR('p', 6, struct pipex_session_stat_req) 180 #define PIPEXGCLOSED _IOR ('p', 7, struct pipex_session_list_req) 181 #define PIPEXSIFDESCR _IOW ('p', 8, struct pipex_session_descr_req) 182 183 #ifdef _KERNEL 184 extern int pipex_enable; 185 186 struct pipex_session; 187 188 /* pipex context for a interface. */ 189 struct pipex_iface_context { 190 struct ifnet *ifnet_this; /* outer interface */ 191 u_int pipexmode; /* pppac ipex mode */ 192 /* virtual pipex_session entry for multicast routing */ 193 struct pipex_session *multicast_session; 194 }; 195 #include <sys/cdefs.h> 196 __BEGIN_DECLS 197 void pipex_init (void); 198 void pipex_iface_init (struct pipex_iface_context *, struct ifnet *); 199 void pipex_iface_start (struct pipex_iface_context *); 200 void pipex_iface_stop (struct pipex_iface_context *); 201 202 int pipex_notify_close_session(struct pipex_session *session); 203 int pipex_notify_close_session_all(void); 204 205 struct mbuf *pipex_output (struct mbuf *, int, int, struct pipex_iface_context *); 206 struct pipex_session *pipex_pppoe_lookup_session (struct mbuf *); 207 struct pipex_session *pipex_pppoe_lookup_session (struct mbuf *); 208 struct mbuf *pipex_pppoe_input (struct mbuf *, struct pipex_session *); 209 struct pipex_session *pipex_pptp_lookup_session (struct mbuf *); 210 struct mbuf *pipex_pptp_input (struct mbuf *, struct pipex_session *); 211 struct pipex_session *pipex_pptp_userland_lookup_session_ipv4 (struct mbuf *, struct in_addr); 212 struct pipex_session *pipex_pptp_userland_lookup_session_ipv6 (struct mbuf *, struct in6_addr); 213 struct pipex_session *pipex_l2tp_userland_lookup_session(struct mbuf *, struct sockaddr *); 214 struct mbuf *pipex_pptp_userland_output (struct mbuf *, struct pipex_session *); 215 struct pipex_session *pipex_l2tp_lookup_session (struct mbuf *, int); 216 struct mbuf *pipex_l2tp_input (struct mbuf *, int off, struct pipex_session *); 217 struct pipex_session *pipex_l2tp_userland_lookup_session_ipv4 (struct mbuf *, struct in_addr); 218 struct pipex_session *pipex_l2tp_userland_lookup_session_ipv6 (struct mbuf *, struct in6_addr); 219 struct mbuf *pipex_l2tp_userland_output (struct mbuf *, struct pipex_session *); 220 int pipex_ioctl (struct pipex_iface_context *, int, caddr_t); 221 void pipex_session_init_mppe_recv(struct pipex_session *, int, 222 int, u_char *); 223 void pipex_session_init_mppe_send(struct pipex_session *, int, 224 int, u_char *); 225 226 __END_DECLS 227 228 #endif /* _KERNEL */ 229 #endif 230