summaryrefslogtreecommitdiff
path: root/sys/net/pipex.h
blob: c8727efa715af494be68f6f17f9dac3a27c74eab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
/*	$OpenBSD: pipex.h,v 1.25 2020/07/17 08:57:27 mvs Exp $	*/

/*
 * Copyright (c) 2009 Internet Initiative Japan Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

#ifndef NET_PIPEX_H
#define NET_PIPEX_H 1

/*
 * Names for pipex sysctl objects
 */
#define PIPEXCTL_ENABLE		1
#define PIPEXCTL_INQ		2
#define PIPEXCTL_OUTQ		3
#define PIPEXCTL_MAXID		4

#define PIPEXCTL_NAMES { \
        { 0, 0 }, \
        { "enable", CTLTYPE_INT }, \
        { "inq", CTLTYPE_NODE }, \
        { "outq", CTLTYPE_NODE }, \
}

#define PIPEX_PROTO_L2TP		1	/* protocol L2TP */
#define PIPEX_PROTO_PPTP		2	/* protocol PPTP */
#define PIPEX_PROTO_PPPOE		3	/* protocol PPPoE */
#define PIPEX_MAX_LISTREQ		128	/* list request size */
#define	PIPEX_MPPE_KEYLEN		16

/* pipex_mppe */
struct pipex_mppe_req {
	int16_t	stateless;			/* mppe key mode.
						   1 for stateless */
	int16_t	keylenbits;			/* mppe key length(in bits)*/
	u_char	master_key[PIPEX_MPPE_KEYLEN];	/* mppe mastter key */
};

/* pipex statistics */
struct pipex_statistics {
	uint32_t ipackets;      /* packets received from tunnel */
	uint32_t ierrors;       /* error packets received from tunnel */
	uint64_t ibytes;        /* number of received bytes from tunnel */
	uint32_t opackets;      /* packets sent to tunnel */
	uint32_t oerrors;       /* error packets on sending to tunnel */
	uint64_t obytes;        /* number of sent bytes to tunnel */

	uint32_t idle_time;     /* idle time in seconds */
};

struct pipex_session_req {
	int		pr_protocol;		/* tunnel protocol  */
/*	u_int		pr_rdomain;	*/	/* rdomain id */
	uint16_t	pr_session_id;		/* session-id */
	uint16_t	pr_peer_session_id;	/* peer's session-id */
	uint32_t	pr_ppp_flags;	/* PPP configuration flags */
#define	PIPEX_PPP_ACFC_ACCEPTED		0x0001	/* ACFC accepted */
#define	PIPEX_PPP_PFC_ACCEPTED		0x0002	/* PFC accepted */
#define	PIPEX_PPP_ACFC_ENABLED		0x0004	/* ACFC enabled */
#define	PIPEX_PPP_PFC_ENABLED		0x0008	/* PFC enabled */
#define	PIPEX_PPP_MPPE_ACCEPTED		0x0010	/* MPPE accepted */
#define	PIPEX_PPP_MPPE_ENABLED		0x0020	/* MPPE enabled */
#define	PIPEX_PPP_MPPE_REQUIRED		0x0040	/* MPPE is required */
#define	PIPEX_PPP_HAS_ACF		0x0080	/* has ACF */
#define	PIPEX_PPP_ADJUST_TCPMSS		0x0100	/* do tcpmss adjustment */
#define	PIPEX_PPP_INGRESS_FILTER	0x0200	/* do ingress filter */
	int8_t		pr_ccp_id;		/* CCP current packet id */
	int		pr_ppp_id;		/* PPP Id. */
	uint16_t	pr_peer_mru;		/* Peer's MRU */
	uint32_t	pr_timeout_sec;		/* Idle Timer */

	struct in_addr	pr_ip_srcaddr;		/* local framed IP-Address */
	struct in_addr	pr_ip_address;		/* framed IP-Address */
	struct in_addr	pr_ip_netmask;		/* framed IP-Netmask */
	struct sockaddr_in6 pr_ip6_address;	/* framed IPv6-Address */
	int		pr_ip6_prefixlen;	/* framed IPv6-Prefixlen */
	union {
		struct {
			uint32_t snd_nxt;	/* send next */
			uint32_t rcv_nxt;	/* receive next */
			uint32_t snd_una;	/* unacked */
			uint32_t rcv_acked;	/* recv acked */
			int winsz;		/* window size */
			int maxwinsz;		/* max window size */
			int peer_maxwinsz;	/* peer's max window size */
		} pptp;
		struct {
			uint32_t option_flags;
#define	PIPEX_L2TP_USE_SEQUENCING	0x00000001

			uint16_t tunnel_id;	/* our tunnel-id */
			uint16_t peer_tunnel_id;/* peer's tunnel-id */
			uint32_t ns_nxt;	/* send next */
			uint32_t nr_nxt;	/* receive next */
			uint32_t ns_una;	/* unacked */
			uint32_t nr_acked;	/* recv acked */
			uint32_t ipsecflowinfo;	/* IPsec flow id for NAT-T */
		} l2tp;
		struct {
			char over_ifname[IF_NAMESIZE];	/* ethernet ifname */
		} pppoe;
	} pr_proto;
	struct sockaddr_storage  pr_peer_address;  /* peer address of tunnel */
	struct sockaddr_storage  pr_local_address; /* our address of tunnel */
	struct pipex_mppe_req    pr_mppe_recv;     /* mppe key for receive */
	struct pipex_mppe_req    pr_mppe_send;     /* mppe key for send */
};

struct pipex_session_stat_req {
	int                      psr_protocol;   /* tunnel protocol */
	uint16_t                 psr_session_id; /* session-id */
	struct pipex_statistics  psr_stat;       /* statistics */
};
struct pipex_session_close_req {
	int                      psr_protocol;   /* tunnel protocol */
	uint16_t                 psr_session_id; /* session-id */
	struct pipex_statistics  psr_stat;       /* statistics */
};
#define	pcr_protocol	psr_protocol
#define	pcr_session_id	psr_session_id
#define	pcr_stat	psr_stat

struct pipex_session_list_req {
	uint8_t	plr_flags;
#define	PIPEX_LISTREQ_MORE		0x01
	int	plr_ppp_id_count;		/* count of PPP id */
	int	plr_ppp_id[PIPEX_MAX_LISTREQ];	/* PPP id */
};

struct pipex_session_config_req {
	int		pcr_protocol;		/* tunnel protocol  */
	uint16_t	pcr_session_id;		/* session-id */
	int		pcr_ip_forward;		/* ip_forwarding on/off */
};

/* for pppx(4) */
struct pppx_hdr {
	u_int32_t	pppx_proto;	/* write: protocol in PIPEX_PROTO_ */
	u_int32_t	pppx_id;	/* write: session_id, read: ppp_id */
};

struct pipex_session_descr_req {
	int		pdr_protocol;		/* tunnel protocol */
	uint16_t	pdr_session_id;		/* session-id */
	char		pdr_descr[IFDESCRSIZE];	/* description */
};


/* PIPEX ioctls */
#define PIPEXSMODE	_IOW ('p',  1, int)
#define PIPEXGMODE	_IOR ('p',  2, int)
#define PIPEXASESSION	_IOW ('p',  3, struct pipex_session_req)
#define PIPEXDSESSION	_IOWR('p',  4, struct pipex_session_close_req)
#define PIPEXCSESSION	_IOW ('p',  5, struct pipex_session_config_req)
#define PIPEXGSTAT	_IOWR('p',  6, struct pipex_session_stat_req)
#define PIPEXGCLOSED	_IOR ('p',  7, struct pipex_session_list_req)
#define PIPEXSIFDESCR	_IOW ('p',  8, struct pipex_session_descr_req)

#ifdef _KERNEL
extern int	pipex_enable;

struct pipex_session;

/* pipex context for a interface
 *
 * Locks used to protect struct members:
 *      I       immutable after creation
 *      N       net lock
 */
struct pipex_iface_context {
	int	ifindex;		/* [I] outer interface index */
	u_int	pipexmode;		/* [N] pipex mode */
	/* [I] virtual pipex_session entry for multicast routing */
	struct pipex_session *multicast_session;
};

__BEGIN_DECLS
void                  pipex_init (void);
void                  pipex_iface_init (struct pipex_iface_context *, int);
void                  pipex_iface_fini (struct pipex_iface_context *);

int                   pipex_notify_close_session(struct pipex_session *session);
int                   pipex_notify_close_session_all(void);

struct mbuf           *pipex_output (struct mbuf *, int, int, struct pipex_iface_context *);
struct pipex_session  *pipex_pppoe_lookup_session (struct mbuf *);
struct mbuf           *pipex_pppoe_input (struct mbuf *, struct pipex_session *);
struct pipex_session  *pipex_pptp_lookup_session (struct mbuf *);
struct mbuf           *pipex_pptp_input (struct mbuf *, struct pipex_session *);
struct pipex_session  *pipex_pptp_userland_lookup_session_ipv4 (struct mbuf *, struct in_addr);
struct pipex_session  *pipex_pptp_userland_lookup_session_ipv6 (struct mbuf *, struct in6_addr);
struct pipex_session  *pipex_l2tp_userland_lookup_session(struct mbuf *, struct sockaddr *);
struct mbuf           *pipex_pptp_userland_output (struct mbuf *, struct pipex_session *);
struct pipex_session  *pipex_l2tp_lookup_session (struct mbuf *, int);
struct mbuf           *pipex_l2tp_input (struct mbuf *, int off, struct pipex_session *, uint32_t);
struct pipex_session  *pipex_l2tp_userland_lookup_session_ipv4 (struct mbuf *, struct in_addr);
struct pipex_session  *pipex_l2tp_userland_lookup_session_ipv6 (struct mbuf *, struct in6_addr);
struct mbuf           *pipex_l2tp_userland_output (struct mbuf *, struct pipex_session *);
int                   pipex_ioctl (struct pipex_iface_context *, u_long, caddr_t);
void                  pipex_session_init_mppe_recv(struct pipex_session *, int,
int, u_char *);
void                  pipex_session_init_mppe_send(struct pipex_session *, int,
int, u_char *);

__END_DECLS

#endif /* _KERNEL */
#endif