xref: /openbsd/sys/net/pipex.h (revision 3d8817e4)
1 /*	$OpenBSD: pipex.h,v 1.8 2011/04/02 11:52:44 dlg 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 #define PIPEX_ENABLE			1
33 #define PIPEX_DISABLE			0
34 
35 #define PIPEX_PROTO_L2TP		0x0001  /* protocol L2TP */
36 #define PIPEX_PROTO_PPTP		0x0002	/* protocol pptp */
37 #define PIPEX_PROTO_PPPOE		0x0003	/* protocol pppoe */
38 #define PIPEX_MAX_LISTREQ		128	/* list request size */
39 #define	PIPEX_MPPE_KEYLEN		16
40 
41 /* pipex_mppe */
42 struct pipex_mppe_req {
43 	int16_t	stateless;			/* mppe key mode */
44 	int16_t	keylenbits;			/* mppe key length(in bits)*/
45 	u_char	master_key[PIPEX_MPPE_KEYLEN];	/* mppe mastter key */
46 };
47 
48 /* pppac ip-extension forwarded statistics */
49 struct pipex_statistics {
50 	uint32_t ipackets;			/* tunnel to network */
51 	uint32_t ierrors;			/* tunnel to network */
52 	uint64_t ibytes;			/* tunnel to network */
53 	uint32_t opackets;			/* network to tunnel */
54 	uint32_t oerrors;			/* network to tunnel */
55 	uint64_t obytes;			/* network to tunnel */
56 
57 	uint32_t idle_time;			/* idle timer */
58 };
59 
60 struct pipex_session_req {
61 	int		pr_protocol;		/* tunnel protocol  */
62 /*	u_int		pr_rdomain;	*/	/* rdomain id */
63 	uint16_t	pr_session_id;		/* session-id */
64 	uint16_t	pr_peer_session_id;	/* peer's session-id */
65 	uint32_t	pr_ppp_flags;	/* PPP configuration flags */
66 #define	PIPEX_PPP_ACFC_ACCEPTED		0x00000001
67 #define	PIPEX_PPP_PFC_ACCEPTED		0x00000002
68 #define	PIPEX_PPP_ACFC_ENABLED		0x00000004
69 #define	PIPEX_PPP_PFC_ENABLED		0x00000008
70 #define	PIPEX_PPP_MPPE_ACCEPTED		0x00000010
71 #define	PIPEX_PPP_MPPE_ENABLED		0x00000020
72 #define	PIPEX_PPP_MPPE_REQUIRED		0x00000040
73 #define	PIPEX_PPP_HAS_ACF		0x00000080
74 #define	PIPEX_PPP_ADJUST_TCPMSS		0x00000100
75 	int8_t		pr_ccp_id;		/* CCP current packet id */
76 	int		pr_ppp_id;		/* PPP Id. */
77 	uint16_t	pr_peer_mru; 		/* Peer's MRU */
78 	uint16_t	pr_timeout_sec; 	/* Idle Timer */
79 
80 	struct in_addr	pr_ip_srcaddr;		/* local framed IP-Address */
81 	struct in_addr	pr_ip_address;		/* framed IP-Address */
82 	struct in_addr	pr_ip_netmask;		/* framed IP-Netmask */
83 	struct sockaddr_in6 pr_ip6_address;	/* framed IPv6-Address */
84 	int		pr_ip6_prefixlen;	/* framed IPv6-Prefixlen */
85 	union {
86 		struct {
87 			uint32_t snd_nxt;	/* send next */
88 			uint32_t rcv_nxt;	/* receive next */
89 			uint32_t snd_una;	/* unacked */
90 			uint32_t rcv_acked;	/* recv acked */
91 			int winsz;		/* window size */
92 			int maxwinsz;		/* max window size */
93 			int peer_maxwinsz;	/* peer's max window size */
94 		} pptp;
95 		struct {
96 			/* select protocol options: 1 for enable */
97 			uint32_t option_flags;
98 #define	PIPEX_L2TP_USE_SEQUENCING	0x00000001
99 
100 			/* session keys */
101 			uint16_t tunnel_id;	/* our tunnel-id */
102 			uint16_t peer_tunnel_id;/* peer's tunnel-id */
103 			uint32_t ns_nxt;	/* send next */
104 			uint32_t nr_nxt;	/* receive next */
105 			uint32_t ns_una;	/* unacked */
106 			uint32_t nr_acked;	/* recv acked */
107 		} l2tp;
108 		struct {
109 			char over_ifname[IF_NAMESIZE]; 	/* ethernet i/f name */
110 		} pppoe;
111 	} pr_proto;
112 	struct sockaddr_storage		peer_address;
113 	struct sockaddr_storage		local_address;
114 	struct pipex_mppe_req pr_mppe_recv;
115 	struct pipex_mppe_req pr_mppe_send;
116 };
117 
118 struct pipex_session_stat_req {
119 	int		psr_protocol;		/* tunnel protocol  */
120 	uint16_t	psr_session_id;		/* session-id */
121 	struct pipex_statistics psr_stat;	/* statistics */
122 };
123 #define pipex_session_close_req		pipex_session_stat_req
124 #define	pcr_protocol	psr_protocol
125 #define	pcr_session_id	psr_session_id
126 #define	pcr_stat	psr_stat
127 
128 struct pipex_session_list_req {
129 	uint8_t	plr_flags;
130 #define	PIPEX_LISTREQ_NONE		0x00
131 #define	PIPEX_LISTREQ_MORE		0x01
132 	int	plr_ppp_id_count;		/* count of PPP id */
133 	int	plr_ppp_id[PIPEX_MAX_LISTREQ];	/* PPP id */
134 };
135 
136 struct pipex_session_config_req {
137 	int		pcr_protocol;		/* tunnel protocol  */
138 	uint16_t	pcr_session_id;		/* session-id */
139 	int		pcr_ip_forward;		/* ip_forwarding on/off */
140 };
141 
142 /* for pppx(4) */
143 struct pppx_hdr {
144 	u_int32_t	pppx_proto;
145 	u_int32_t	pppx_id;
146 };
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 
154 
155 /* PIPEX ioctls */
156 #define PIPEXSMODE	_IOW ('p',  1, int)
157 #define PIPEXGMODE	_IOR ('p',  2, int)
158 #define PIPEXASESSION	_IOW ('p',  3, struct pipex_session_req)
159 #define PIPEXDSESSION	_IOWR('p',  4, struct pipex_session_close_req)
160 #define PIPEXCSESSION	_IOW ('p',  5, struct pipex_session_config_req)
161 #define PIPEXGSTAT	_IOWR('p',  6, struct pipex_session_stat_req)
162 #define PIPEXGCLOSED	_IOR ('p',  7, struct pipex_session_list_req)
163 #define PIPEXSIFDESCR	_IOW ('p',  8, struct pipex_session_descr_req)
164 
165 #ifdef _KERNEL
166 
167 struct pipex_session;
168 
169 /* pipex context for a interface. */
170 struct pipex_iface_context {
171 	struct	ifnet *ifnet_this;	/* outer interface */
172 	u_int	pipexmode;		/* pppac ipex mode */
173 	/* virtual pipex_session entry for multicast routing */
174 	struct pipex_session *multicast_session;
175 };
176 #include <sys/cdefs.h>
177 __BEGIN_DECLS
178 void                  pipex_init (void);
179 void                  pipex_iface_init (struct pipex_iface_context *, struct ifnet *);
180 void                  pipex_iface_start (struct pipex_iface_context *);
181 void                  pipex_iface_stop (struct pipex_iface_context *);
182 
183 int                   pipex_notify_close_session(struct pipex_session *session);
184 int                   pipex_notify_close_session_all(void);
185 
186 struct mbuf           *pipex_output (struct mbuf *, int, int, struct pipex_iface_context *);
187 struct pipex_session  *pipex_pppoe_lookup_session (struct mbuf *);
188 struct pipex_session  *pipex_pppoe_lookup_session (struct mbuf *);
189 struct mbuf           *pipex_pppoe_input (struct mbuf *, struct pipex_session *);
190 struct pipex_session  *pipex_pptp_lookup_session (struct mbuf *);
191 struct mbuf           *pipex_pptp_input (struct mbuf *, struct pipex_session *);
192 struct pipex_session  *pipex_pptp_userland_lookup_session_ipv4 (struct mbuf *, struct in_addr);
193 struct pipex_session  *pipex_pptp_userland_lookup_session_ipv6 (struct mbuf *, struct in6_addr);
194 struct mbuf           *pipex_pptp_userland_output (struct mbuf *, struct pipex_session *);
195 struct pipex_session  *pipex_l2tp_lookup_session (struct mbuf *, int);
196 struct mbuf           *pipex_l2tp_input (struct mbuf *, int off, struct pipex_session *);
197 struct pipex_session  *pipex_l2tp_userland_lookup_session_ipv4 (struct mbuf *, struct in_addr);
198 struct pipex_session  *pipex_l2tp_userland_lookup_session_ipv6 (struct mbuf *, struct in6_addr);
199 struct mbuf           *pipex_l2tp_userland_output (struct mbuf *, struct pipex_session *);
200 int                   pipex_ioctl (struct pipex_iface_context *, int, caddr_t);
201 __END_DECLS
202 
203 #endif /* _KERNEL */
204 #endif
205