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