1 /* $OpenBSD: pipex.h,v 1.20 2015/12/05 16:09:09 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_INQ 2 37 #define PIPEXCTL_OUTQ 3 38 #define PIPEXCTL_MAXID 4 39 40 #define PIPEXCTL_NAMES { \ 41 { 0, 0 }, \ 42 { "enable", CTLTYPE_INT }, \ 43 { "inq", CTLTYPE_NODE }, \ 44 { "outq", CTLTYPE_NODE }, \ 45 } 46 47 #define PIPEX_PROTO_L2TP 1 /* protocol L2TP */ 48 #define PIPEX_PROTO_PPTP 2 /* protocol PPTP */ 49 #define PIPEX_PROTO_PPPOE 3 /* protocol PPPoE */ 50 #define PIPEX_MAX_LISTREQ 128 /* list request size */ 51 #define PIPEX_MPPE_KEYLEN 16 52 53 /* pipex_mppe */ 54 struct pipex_mppe_req { 55 int16_t stateless; /* mppe key mode. 56 1 for stateless */ 57 int16_t keylenbits; /* mppe key length(in bits)*/ 58 u_char master_key[PIPEX_MPPE_KEYLEN]; /* mppe mastter key */ 59 }; 60 61 /* pipex statistics */ 62 struct pipex_statistics { 63 uint32_t ipackets; /* packets received from tunnel */ 64 uint32_t ierrors; /* error packets received from tunnel */ 65 uint64_t ibytes; /* number of received bytes from tunnel */ 66 uint32_t opackets; /* packets sent to tunnel */ 67 uint32_t oerrors; /* error packets on sending to tunnel */ 68 uint64_t obytes; /* number of sent bytes to tunnel */ 69 70 uint32_t idle_time; /* idle time in seconds */ 71 }; 72 73 struct pipex_session_req { 74 int pr_protocol; /* tunnel protocol */ 75 /* u_int pr_rdomain; */ /* rdomain id */ 76 uint16_t pr_session_id; /* session-id */ 77 uint16_t pr_peer_session_id; /* peer's session-id */ 78 uint32_t pr_ppp_flags; /* PPP configuration flags */ 79 #define PIPEX_PPP_ACFC_ACCEPTED 0x0001 /* ACFC accepted */ 80 #define PIPEX_PPP_PFC_ACCEPTED 0x0002 /* PFC accepted */ 81 #define PIPEX_PPP_ACFC_ENABLED 0x0004 /* ACFC enabled */ 82 #define PIPEX_PPP_PFC_ENABLED 0x0008 /* PFC enabled */ 83 #define PIPEX_PPP_MPPE_ACCEPTED 0x0010 /* MPPE accepted */ 84 #define PIPEX_PPP_MPPE_ENABLED 0x0020 /* MPPE enabled */ 85 #define PIPEX_PPP_MPPE_REQUIRED 0x0040 /* MPPE is required */ 86 #define PIPEX_PPP_HAS_ACF 0x0080 /* has ACF */ 87 #define PIPEX_PPP_ADJUST_TCPMSS 0x0100 /* do tcpmss adjustment */ 88 #define PIPEX_PPP_INGRESS_FILTER 0x0200 /* do ingress filter */ 89 int8_t pr_ccp_id; /* CCP current packet id */ 90 int pr_ppp_id; /* PPP Id. */ 91 uint16_t pr_peer_mru; /* Peer's MRU */ 92 uint32_t pr_timeout_sec; /* Idle Timer */ 93 94 struct in_addr pr_ip_srcaddr; /* local framed IP-Address */ 95 struct in_addr pr_ip_address; /* framed IP-Address */ 96 struct in_addr pr_ip_netmask; /* framed IP-Netmask */ 97 struct sockaddr_in6 pr_ip6_address; /* framed IPv6-Address */ 98 int pr_ip6_prefixlen; /* framed IPv6-Prefixlen */ 99 union { 100 struct { 101 uint32_t snd_nxt; /* send next */ 102 uint32_t rcv_nxt; /* receive next */ 103 uint32_t snd_una; /* unacked */ 104 uint32_t rcv_acked; /* recv acked */ 105 int winsz; /* window size */ 106 int maxwinsz; /* max window size */ 107 int peer_maxwinsz; /* peer's max window size */ 108 } pptp; 109 struct { 110 uint32_t option_flags; 111 #define PIPEX_L2TP_USE_SEQUENCING 0x00000001 112 113 uint16_t tunnel_id; /* our tunnel-id */ 114 uint16_t peer_tunnel_id;/* peer's tunnel-id */ 115 uint32_t ns_nxt; /* send next */ 116 uint32_t nr_nxt; /* receive next */ 117 uint32_t ns_una; /* unacked */ 118 uint32_t nr_acked; /* recv acked */ 119 uint32_t ipsecflowinfo; /* IPsec flow id for NAT-T */ 120 } l2tp; 121 struct { 122 char over_ifname[IF_NAMESIZE]; /* ethernet ifname */ 123 } pppoe; 124 } pr_proto; 125 struct sockaddr_storage pr_peer_address; /* peer address of tunnel */ 126 struct sockaddr_storage pr_local_address; /* our address of tunnel */ 127 struct pipex_mppe_req pr_mppe_recv; /* mppe key for receive */ 128 struct pipex_mppe_req pr_mppe_send; /* mppe key for send */ 129 }; 130 131 struct pipex_session_stat_req { 132 int psr_protocol; /* tunnel protocol */ 133 uint16_t psr_session_id; /* session-id */ 134 struct pipex_statistics psr_stat; /* statistics */ 135 }; 136 struct pipex_session_close_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 pcr_protocol psr_protocol 142 #define pcr_session_id psr_session_id 143 #define pcr_stat psr_stat 144 145 struct pipex_session_list_req { 146 uint8_t plr_flags; 147 #define PIPEX_LISTREQ_MORE 0x01 148 int plr_ppp_id_count; /* count of PPP id */ 149 int plr_ppp_id[PIPEX_MAX_LISTREQ]; /* PPP id */ 150 }; 151 152 struct pipex_session_config_req { 153 int pcr_protocol; /* tunnel protocol */ 154 uint16_t pcr_session_id; /* session-id */ 155 int pcr_ip_forward; /* ip_forwarding on/off */ 156 }; 157 158 /* for pppx(4) */ 159 struct pppx_hdr { 160 u_int32_t pppx_proto; /* write: protocol in PIPEX_PROTO_ */ 161 u_int32_t pppx_id; /* write: session_id, read: ppp_id */ 162 }; 163 164 struct pipex_session_descr_req { 165 int pdr_protocol; /* tunnel protocol */ 166 uint16_t pdr_session_id; /* session-id */ 167 char pdr_descr[IFDESCRSIZE]; /* description */ 168 }; 169 170 171 /* PIPEX ioctls */ 172 #define PIPEXSMODE _IOW ('p', 1, int) 173 #define PIPEXGMODE _IOR ('p', 2, int) 174 #define PIPEXASESSION _IOW ('p', 3, struct pipex_session_req) 175 #define PIPEXDSESSION _IOWR('p', 4, struct pipex_session_close_req) 176 #define PIPEXCSESSION _IOW ('p', 5, struct pipex_session_config_req) 177 #define PIPEXGSTAT _IOWR('p', 6, struct pipex_session_stat_req) 178 #define PIPEXGCLOSED _IOR ('p', 7, struct pipex_session_list_req) 179 #define PIPEXSIFDESCR _IOW ('p', 8, struct pipex_session_descr_req) 180 181 #ifdef _KERNEL 182 extern int pipex_enable; 183 184 struct pipex_session; 185 186 /* pipex context for a interface. */ 187 struct pipex_iface_context { 188 struct ifnet *ifnet_this; /* outer interface */ 189 u_int pipexmode; /* pipex mode */ 190 /* virtual pipex_session entry for multicast routing */ 191 struct pipex_session *multicast_session; 192 }; 193 194 __BEGIN_DECLS 195 void pipex_init (void); 196 void pipex_iface_init (struct pipex_iface_context *, struct ifnet *); 197 void pipex_iface_fini (struct pipex_iface_context *); 198 199 int pipex_notify_close_session(struct pipex_session *session); 200 int pipex_notify_close_session_all(void); 201 202 struct mbuf *pipex_output (struct mbuf *, int, int, struct pipex_iface_context *); 203 struct pipex_session *pipex_pppoe_lookup_session (struct mbuf *); 204 struct pipex_session *pipex_pppoe_lookup_session (struct mbuf *); 205 struct mbuf *pipex_pppoe_input (struct mbuf *, struct pipex_session *); 206 struct pipex_session *pipex_pptp_lookup_session (struct mbuf *); 207 struct mbuf *pipex_pptp_input (struct mbuf *, struct pipex_session *); 208 struct pipex_session *pipex_pptp_userland_lookup_session_ipv4 (struct mbuf *, struct in_addr); 209 struct pipex_session *pipex_pptp_userland_lookup_session_ipv6 (struct mbuf *, struct in6_addr); 210 struct pipex_session *pipex_l2tp_userland_lookup_session(struct mbuf *, struct sockaddr *); 211 struct mbuf *pipex_pptp_userland_output (struct mbuf *, struct pipex_session *); 212 struct pipex_session *pipex_l2tp_lookup_session (struct mbuf *, int); 213 struct mbuf *pipex_l2tp_input (struct mbuf *, int off, struct pipex_session *, uint32_t); 214 struct pipex_session *pipex_l2tp_userland_lookup_session_ipv4 (struct mbuf *, struct in_addr); 215 struct pipex_session *pipex_l2tp_userland_lookup_session_ipv6 (struct mbuf *, struct in6_addr); 216 struct mbuf *pipex_l2tp_userland_output (struct mbuf *, struct pipex_session *); 217 int pipex_ioctl (struct pipex_iface_context *, u_long, caddr_t); 218 void pipex_session_init_mppe_recv(struct pipex_session *, int, 219 int, u_char *); 220 void pipex_session_init_mppe_send(struct pipex_session *, int, 221 int, u_char *); 222 223 __END_DECLS 224 225 #endif /* _KERNEL */ 226 #endif 227