xref: /openbsd/sys/net/pipex.h (revision 8932bfb7)
1 /*	$OpenBSD: pipex.h,v 1.9 2011/07/08 18:30:17 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 	int8_t		pr_ccp_id;		/* CCP current packet id */
93 	int		pr_ppp_id;		/* PPP Id. */
94 	uint16_t	pr_peer_mru; 		/* Peer's MRU */
95 	uint16_t	pr_timeout_sec; 	/* Idle Timer */
96 
97 	struct in_addr	pr_ip_srcaddr;		/* local framed IP-Address */
98 	struct in_addr	pr_ip_address;		/* framed IP-Address */
99 	struct in_addr	pr_ip_netmask;		/* framed IP-Netmask */
100 	struct sockaddr_in6 pr_ip6_address;	/* framed IPv6-Address */
101 	int		pr_ip6_prefixlen;	/* framed IPv6-Prefixlen */
102 	union {
103 		struct {
104 			uint32_t snd_nxt;	/* send next */
105 			uint32_t rcv_nxt;	/* receive next */
106 			uint32_t snd_una;	/* unacked */
107 			uint32_t rcv_acked;	/* recv acked */
108 			int winsz;		/* window size */
109 			int maxwinsz;		/* max window size */
110 			int peer_maxwinsz;	/* peer's max window size */
111 		} pptp;
112 		struct {
113 			/* select protocol options: 1 for enable */
114 			uint32_t option_flags;
115 #define	PIPEX_L2TP_USE_SEQUENCING	0x00000001
116 
117 			/* session keys */
118 			uint16_t tunnel_id;	/* our tunnel-id */
119 			uint16_t peer_tunnel_id;/* peer's tunnel-id */
120 			uint32_t ns_nxt;	/* send next */
121 			uint32_t nr_nxt;	/* receive next */
122 			uint32_t ns_una;	/* unacked */
123 			uint32_t nr_acked;	/* recv acked */
124 		} l2tp;
125 		struct {
126 			char over_ifname[IF_NAMESIZE]; 	/* ethernet i/f name */
127 		} pppoe;
128 	} pr_proto;
129 	struct sockaddr_storage		peer_address;
130 	struct sockaddr_storage		local_address;
131 	struct pipex_mppe_req pr_mppe_recv;
132 	struct pipex_mppe_req pr_mppe_send;
133 };
134 
135 struct pipex_session_stat_req {
136 	int		psr_protocol;		/* tunnel protocol  */
137 	uint16_t	psr_session_id;		/* session-id */
138 	struct pipex_statistics psr_stat;	/* statistics */
139 };
140 #define pipex_session_close_req		pipex_session_stat_req
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_NONE		0x00
148 #define	PIPEX_LISTREQ_MORE		0x01
149 	int	plr_ppp_id_count;		/* count of PPP id */
150 	int	plr_ppp_id[PIPEX_MAX_LISTREQ];	/* PPP id */
151 };
152 
153 struct pipex_session_config_req {
154 	int		pcr_protocol;		/* tunnel protocol  */
155 	uint16_t	pcr_session_id;		/* session-id */
156 	int		pcr_ip_forward;		/* ip_forwarding on/off */
157 };
158 
159 /* for pppx(4) */
160 struct pppx_hdr {
161 	u_int32_t	pppx_proto;
162 	u_int32_t	pppx_id;
163 };
164 
165 struct pipex_session_descr_req {
166 	int		pdr_protocol;		/* tunnel protocol */
167 	uint16_t	pdr_session_id;		/* session-id */
168 	char		pdr_descr[IFDESCRSIZE];	/* description */
169 };
170 
171 
172 /* PIPEX ioctls */
173 #define PIPEXSMODE	_IOW ('p',  1, int)
174 #define PIPEXGMODE	_IOR ('p',  2, int)
175 #define PIPEXASESSION	_IOW ('p',  3, struct pipex_session_req)
176 #define PIPEXDSESSION	_IOWR('p',  4, struct pipex_session_close_req)
177 #define PIPEXCSESSION	_IOW ('p',  5, struct pipex_session_config_req)
178 #define PIPEXGSTAT	_IOWR('p',  6, struct pipex_session_stat_req)
179 #define PIPEXGCLOSED	_IOR ('p',  7, struct pipex_session_list_req)
180 #define PIPEXSIFDESCR	_IOW ('p',  8, struct pipex_session_descr_req)
181 
182 #ifdef _KERNEL
183 extern int	pipex_enable;
184 
185 struct pipex_session;
186 
187 /* pipex context for a interface. */
188 struct pipex_iface_context {
189 	struct	ifnet *ifnet_this;	/* outer interface */
190 	u_int	pipexmode;		/* pppac ipex mode */
191 	/* virtual pipex_session entry for multicast routing */
192 	struct pipex_session *multicast_session;
193 };
194 #include <sys/cdefs.h>
195 __BEGIN_DECLS
196 void                  pipex_init (void);
197 void                  pipex_iface_init (struct pipex_iface_context *, struct ifnet *);
198 void                  pipex_iface_start (struct pipex_iface_context *);
199 void                  pipex_iface_stop (struct pipex_iface_context *);
200 
201 int                   pipex_notify_close_session(struct pipex_session *session);
202 int                   pipex_notify_close_session_all(void);
203 
204 struct mbuf           *pipex_output (struct mbuf *, int, int, struct pipex_iface_context *);
205 struct pipex_session  *pipex_pppoe_lookup_session (struct mbuf *);
206 struct pipex_session  *pipex_pppoe_lookup_session (struct mbuf *);
207 struct mbuf           *pipex_pppoe_input (struct mbuf *, struct pipex_session *);
208 struct pipex_session  *pipex_pptp_lookup_session (struct mbuf *);
209 struct mbuf           *pipex_pptp_input (struct mbuf *, struct pipex_session *);
210 struct pipex_session  *pipex_pptp_userland_lookup_session_ipv4 (struct mbuf *, struct in_addr);
211 struct pipex_session  *pipex_pptp_userland_lookup_session_ipv6 (struct mbuf *, struct in6_addr);
212 struct mbuf           *pipex_pptp_userland_output (struct mbuf *, struct pipex_session *);
213 struct pipex_session  *pipex_l2tp_lookup_session (struct mbuf *, int);
214 struct mbuf           *pipex_l2tp_input (struct mbuf *, int off, struct pipex_session *);
215 struct pipex_session  *pipex_l2tp_userland_lookup_session_ipv4 (struct mbuf *, struct in_addr);
216 struct pipex_session  *pipex_l2tp_userland_lookup_session_ipv6 (struct mbuf *, struct in6_addr);
217 struct mbuf           *pipex_l2tp_userland_output (struct mbuf *, struct pipex_session *);
218 int                   pipex_ioctl (struct pipex_iface_context *, int, caddr_t);
219 __END_DECLS
220 
221 #endif /* _KERNEL */
222 #endif
223