Annotation of embedaddon/mpd/src/l2tp_ctrl.h, revision 1.1.1.2
1.1 misho 1:
2: /*
3: * Copyright (c) 2001-2002 Packet Design, LLC.
4: * All rights reserved.
5: *
6: * Subject to the following obligations and disclaimer of warranty,
7: * use and redistribution of this software, in source or object code
8: * forms, with or without modifications are expressly permitted by
9: * Packet Design; provided, however, that:
10: *
11: * (i) Any and all reproductions of the source or object code
12: * must include the copyright notice above and the following
13: * disclaimer of warranties; and
14: * (ii) No rights are granted, in any manner or form, to use
15: * Packet Design trademarks, including the mark "PACKET DESIGN"
16: * on advertising, endorsements, or otherwise except as such
17: * appears in the above copyright notice or in the software.
18: *
19: * THIS SOFTWARE IS BEING PROVIDED BY PACKET DESIGN "AS IS", AND
20: * TO THE MAXIMUM EXTENT PERMITTED BY LAW, PACKET DESIGN MAKES NO
21: * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING
22: * THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED
23: * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
24: * OR NON-INFRINGEMENT. PACKET DESIGN DOES NOT WARRANT, GUARANTEE,
25: * OR MAKE ANY REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS
26: * OF THE USE OF THIS SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY,
27: * RELIABILITY OR OTHERWISE. IN NO EVENT SHALL PACKET DESIGN BE
28: * LIABLE FOR ANY DAMAGES RESULTING FROM OR ARISING OUT OF ANY USE
29: * OF THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY DIRECT,
30: * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE, OR CONSEQUENTIAL
31: * DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, LOSS OF
32: * USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY THEORY OF
33: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
35: * THE USE OF THIS SOFTWARE, EVEN IF PACKET DESIGN IS ADVISED OF
36: * THE POSSIBILITY OF SUCH DAMAGE.
37: *
38: * Author: Archie Cobbs <archie@freebsd.org>
39: */
40:
41: #ifndef _PPP_L2TP_PDEL_PPP_PPP_L2TP_CTRL_H_
42: #define _PPP_L2TP_PDEL_PPP_PPP_L2TP_CTRL_H_
43:
44: /*
45: * API between L2TP 'control' and 'link' code. The control code handles
46: * the L2TP control connection. The link code handles plumbing netgraph,
47: * and interfacing with the PPP engine.
48: *
49: * Each control connection is represented by a 'struct ppp_l2tp_ctrl',
50: * and each session by a 'struct ppp_l2tp_sess'. The link side may store
51: * its own opaque pointer in these structures as well.
52: *
53: * The functions and callbacks are designed so that whenever either side
54: * declares a control connection or session 'terminated', then the other
55: * side (whose function is being called) must not refer to that object
56: * any more.
57: *
58: * It is presumed that the 'link' side has a mutex which is held while
59: * calling any of the 'control' side functions, and which is acquired
60: * first when any 'link' side functions are invoked. In other words,
61: * the control side is not reentrant (though see 'ppp_l2tp_initiated_t'
62: * for an exception).
63: */
64:
65: struct ppp_l2tp_ctrl; /* control connection structure */
66: struct ppp_l2tp_sess; /* call session structure */
67:
68: /************************************************************************
69: CONTROL -> LINK CALLBACK FUNCTIONS
70: ************************************************************************/
71:
72: /*
73: * This is called when a control connection gets connected state
74: *
75: * Arguments:
76: * ctrl Control connection
77: */
78: typedef void ppp_l2tp_ctrl_connected_t(struct ppp_l2tp_ctrl *ctrl);
79:
80: /*
81: * This is called when a control connection is terminated for any reason
82: * other than a call ppp_l2tp_ctrl_destroy().
83: *
84: * Arguments:
85: * ctrl Control connection
86: * result Result code (never zero)
87: * error Error code (if result == L2TP_RESULT_GENERAL, else zero)
88: * errmsg Error message string
89: */
90: typedef void ppp_l2tp_ctrl_terminated_t(struct ppp_l2tp_ctrl *ctrl,
91: u_int16_t result, u_int16_t error, const char *errmsg);
92:
93: /*
94: * This is called just before control connection is destroyed for any reason
95: * other than a call ppp_l2tp_ctrl_destroy().
96: *
97: * Arguments:
98: * ctrl Control connection
99: */
100: typedef void ppp_l2tp_ctrl_destroyed_t(struct ppp_l2tp_ctrl *ctrl);
101:
102: /*
103: * This callback is used to report the peer's initiating a new incoming
104: * or outgoing call.
105: *
106: * In the case of an incoming call, when/if the call eventually connects,
107: * the ppp_l2tp_connected_t callback will be called by the control side.
108: *
109: * In the case of an outgoing call, the link side is responsible for calling
110: * ppp_l2tp_connected() when/if the call is connected.
111: *
112: * This callback may choose to call ppp_l2tp_terminate() (to deny the call)
113: * or ppp_l2tp_connected() (to accept it immediately if outgoing) before
114: * returning.
115: *
116: * The link side is expected to plumb the netgraph session hook at this time.
117: *
118: * Arguments:
119: * ctrl Associated control connection
120: * sess Session structure
121: * out Non-zero to indicate outgoing call
122: * avps AVP's contained in the associated Outgoing-Call-Request
123: * or Incoming-Call-Request control message.
124: */
125: typedef void ppp_l2tp_initiated_t(struct ppp_l2tp_ctrl *ctrl,
126: struct ppp_l2tp_sess *sess, int out,
127: const struct ppp_l2tp_avp_list *avps,
128: u_char *include_length, u_char *enable_dseq);
129:
130: /*
131: * This callback is used to report successful connection of a remotely
132: * initiated incoming call (see ppp_l2tp_initiated_t) or a locally initiated
133: * outgoing call (see ppp_l2tp_initiate()). That is, we are acting as
134: * the LNS for this session.
135: *
136: * Arguments:
137: * sess Session structure
138: * avps AVP's contained in the associated Outgoing-Call-Connected
139: * or Incoming-Call-Connected control message.
140: */
141: typedef void ppp_l2tp_connected_t(struct ppp_l2tp_sess *sess,
142: const struct ppp_l2tp_avp_list *avps);
143:
144: /*
145: * This callback is called when any call, whether successfully connected
146: * or not, is terminated for any reason other than explict termination
147: * from the link side (via a call to either ppp_l2tp_terminate() or
148: * ppp_l2tp_ctrl_destroy()).
149: *
150: * Arguments:
151: * sess Session structure
152: * result Result code (never zero)
153: * error Error code (if result == L2TP_RESULT_GENERAL, else zero)
154: * errmsg Error message string
155: */
156: typedef void ppp_l2tp_terminated_t(struct ppp_l2tp_sess *sess,
157: u_int16_t result, u_int16_t error, const char *errmsg);
158:
159: /*
160: * This callback is used when the remote side sends a Set-Link-Info
161: * message. It is optional and may be NULL if not required.
162: *
163: * Arguments:
164: * sess Session structure
165: * xmit LAC's send ACCM
166: * recv LAC's receive ACCM
167: */
168: typedef void ppp_l2tp_set_link_info_t(struct ppp_l2tp_sess *sess,
169: u_int32_t xmit, u_int32_t recv);
170:
171: /*
172: * This callback is used when the remote side sends a WAN-Error-Notify
173: * message. It is optional and may be NULL if not required.
174: *
175: * Arguments:
176: * sess Session structure
177: * crc CRC errors
178: * frame Framing errors
179: * overrun Hardware overrun errors
180: * buffer Buffer overrun errors
181: * timeout Timeout errors
182: * align Alignment errors
183: */
184: typedef void ppp_l2tp_wan_error_notify_t(struct ppp_l2tp_sess *sess,
185: u_int32_t crc, u_int32_t frame, u_int32_t overrun,
186: u_int32_t buffer, u_int32_t timeout, u_int32_t align);
187:
188: /* Callback structure provided by the link side */
189: struct ppp_l2tp_ctrl_cb {
190: ppp_l2tp_ctrl_connected_t *ctrl_connected;
191: ppp_l2tp_ctrl_terminated_t *ctrl_terminated;
192: ppp_l2tp_ctrl_destroyed_t *ctrl_destroyed;
193: ppp_l2tp_initiated_t *initiated;
194: ppp_l2tp_connected_t *connected;
195: ppp_l2tp_terminated_t *terminated;
196: ppp_l2tp_set_link_info_t *set_link_info;
197: ppp_l2tp_wan_error_notify_t *wan_error_notify;
198: };
199:
200: /************************************************************************
201: LINK -> CONTROL FUNCTIONS
202: ************************************************************************/
203:
204: __BEGIN_DECLS
205:
206: /*
207: * This function creates a new control connection. If successful, the
208: * control code will create a ng_l2tp(4) node and fill in *nodep and
209: * the 'hook' buffer. The link code must then connect this hook to the
210: * appropriate L2TP packet delivery node before the next context switch.
211: *
212: * The control code guarantees exactly one call in the future to the
213: * ppp_l2tp_ctrl_terminated_t callback unless ppp_l2tp_ctrl_destroy()
214: * is called first.
215: *
216: * Arguments:
217: * ctx Event context for use by control code
218: * mutex Mutex for operation
219: * cb Pointer to link callback functions
220: * log Where to log stuff (if successful, the log is consumed)
221: * peer_id Unique identifier for peer (used for tie-breakers)
222: * initiate Whether to send a SCCRQ or just wait for one
223: * nodep Pointer to netgraph node ID variable
224: * hook Buffer for hook on L2TP netgraph node (size >= NG_HOOKSIZ)
225: * avps List of AVP's to include in the associated
226: * Start-Control-Connection-Request or
227: * Start-Control-Connection-Reply control message.
228: * secret Shared secret (or NULL if none required)
229: * seclen Length of shared secret (if secret != NULL)
230: *
231: * Returns NULL if failure (errno is set), otherwise a pointer to an
232: * opaque control connection object.
233: */
234: extern struct ppp_l2tp_ctrl *ppp_l2tp_ctrl_create(struct pevent_ctx *ctx,
235: pthread_mutex_t *mutex,
236: const struct ppp_l2tp_ctrl_cb *cb,
237: u_int32_t peer_id, ng_ID_t *nodep,
238: char *hook, const struct ppp_l2tp_avp_list *avps,
239: const void *secret, size_t seclen,
240: u_char hide_avps);
241:
242: /*
243: * This function initiates a new tunnel connection.
244: *
245: * Arguments:
246: * ctrl Control connection
247: *
248: * Returns:
249: * NULL Initiation failed, errno is set
250: * ctrl Control structure
251: */
252: extern struct ppp_l2tp_ctrl *ppp_l2tp_ctrl_initiate(struct ppp_l2tp_ctrl *ctrl);
253:
254: /*
255: * Close a control connection gracefully.
256: *
257: * All active sessions will be terminated, and eventually
258: * ppp_l2tp_ctrl_terminated_t will be called, assuming no
259: * intervening call to ppp_l2tp_ctrl_destroy() has been made.
260: *
261: * Arguments:
262: * ctrl Control connection structure
263: * result Result code (never zero)
264: * error Error code (if result == L2TP_RESULT_GENERAL, else zero)
265: * errmsg Error message string
266: */
267: extern void ppp_l2tp_ctrl_shutdown(struct ppp_l2tp_ctrl *ctrl,
268: u_int16_t result, u_int16_t error, const char *errmsg);
269:
270: /*
271: * Immediately destroy a control connection and all associated sessions.
272: * This does *not* result in any callbacks to the link side for either
273: * active sessions (ppp_l2tp_terminated_t) or the control connection
274: * itself (ppp_l2tp_ctrl_terminated_t).
275: *
276: * Upon return, *ctrlp will be set to NULL.
277: *
278: * Arguments:
279: * ctrlp Pointer to the control connection descriptor pointer
280: */
281: extern void ppp_l2tp_ctrl_destroy(struct ppp_l2tp_ctrl **ctrlp);
282:
283: /*
284: * Returns control connection status.
285: *
286: * Arguments:
287: * ctrlp Pointer to the control connection descriptor pointer
288: */
289: extern char * ppp_l2tp_ctrl_stats(struct ppp_l2tp_ctrl *ctrl,
290: char *buf, size_t buf_len);
291:
292: /*
293: * This function initiates a new session, either an as an incoming or
294: * outgoing call request to the peer.
295: *
296: * In the case of an incoming call, when/if the call eventually connects,
297: * ppp_l2tp_connected() must be called.
298: *
299: * In the case of an outgoing call, when/if the call eventually connects,
300: * the link's ppp_l2tp_connected_t callback will be invoked.
301: *
302: * The link side is expected to plumb the netgraph session hook at this time.
303: *
304: * Arguments:
305: * ctrl Control connection
306: * out Non-zero to indicate outgoing call
307: * avps List of AVP's to include in the associated
308: * Outgoing-Call-Request or Incoming-Call-Request
309: * control message.
310: *
311: * Returns:
312: * NULL Initiation failed, errno is set
313: * sess Session structure
314: */
315: extern struct ppp_l2tp_sess *ppp_l2tp_initiate(struct ppp_l2tp_ctrl *ctrl,
316: int out, u_char include_length, u_char enable_dseq,
317: const struct ppp_l2tp_avp_list *avps);
318:
319: /*
320: * This function is used to report successful connection of a remotely
321: * initiated outgoing call (see ppp_l2tp_initiated_t) or a locally initiated
322: * incoming call (see ppp_l2tp_initiate()). That is, we are acting as
323: * the LAC for this session.
324: *
325: * Note: if this function returns -1, no special action is required;
326: * the control side will close the connection gracefully as if
327: * ppp_l2tp_terminate() had been called.
328: *
329: * Arguments:
330: * sess Session structure
331: * avps List of AVP's to include in the associated
332: * Outgoing-Call-Connected or Incoming-Call-Connected
333: * control message.
334: *
335: * Returns:
336: * 0 Connection successful
337: * -1 Connection failed, errno is set
338: */
339: extern int ppp_l2tp_connected(struct ppp_l2tp_sess *sess,
340: const struct ppp_l2tp_avp_list *avps);
341:
342: /*
343: * This function terminates a session. The session may be in any state.
344: * The control code will *not* make any futher calls to link callbacks
345: * regarding this session, so the link should clean up any associated
346: * state.
347: *
348: * Arguments:
349: * sess Session structure
350: * result Result code (must not be zero)
351: * error Error code (if result == L2TP_RESULT_GENERAL, else zero)
352: * errmsg Error message string (optional; may be NULL)
353: */
354: extern void ppp_l2tp_terminate(struct ppp_l2tp_sess *sess,
355: u_int16_t result, u_int16_t error, const char *errmsg);
356:
357: /*
358: * This function is used to send the remote side a Set-Link-Info
359: * message.
360: *
361: * Arguments:
362: * sess Session structure
363: * xmit LAC's send ACCM
364: * recv LAC's receive ACCM
365: */
366: extern int ppp_l2tp_set_link_info(struct ppp_l2tp_sess *sess,
367: u_int32_t xmit, u_int32_t recv);
368:
369: /*
370: * Get or set the link side cookie corresponding to a control connection
371: * or a call session.
372: */
373: extern void *ppp_l2tp_ctrl_get_cookie(struct ppp_l2tp_ctrl *ctrl);
374: extern void ppp_l2tp_ctrl_set_cookie(struct ppp_l2tp_ctrl *ctrl,
375: void *cookie);
376: extern void *ppp_l2tp_sess_get_cookie(struct ppp_l2tp_sess *sess);
377: extern void ppp_l2tp_sess_set_cookie(struct ppp_l2tp_sess *sess,
378: void *cookie);
379:
380: /*
381: * Get session's Call Serial Number.
382: */
383: extern uint32_t ppp_l2tp_sess_get_serial(struct ppp_l2tp_sess *sess);
384:
385: /*
386: * Get the node ID and hook name for the hook that corresponds
387: * to a control connection's L2TP frames.
388: */
389: extern void ppp_l2tp_ctrl_get_hook(struct ppp_l2tp_ctrl *ctrl,
390: ng_ID_t *nodep, const char **hookp);
391:
392: /*
393: * Get local/remote hostnames.
394: */
395: extern int ppp_l2tp_ctrl_get_self_name(struct ppp_l2tp_ctrl *ctrl,
396: void *buf, size_t buf_len);
397: extern int ppp_l2tp_ctrl_get_peer_name(struct ppp_l2tp_ctrl *ctrl,
398: void *buf, size_t buf_len);
1.1.1.2 ! misho 399: extern char* ppp_l2tp_ctrl_get_peer_name_p(struct ppp_l2tp_ctrl *ctrl);
1.1 misho 400: /*
401: * Get the node ID and hook name for the hook that corresponds
402: * to a session's data packets.
403: */
404: extern void ppp_l2tp_sess_get_hook(struct ppp_l2tp_sess *sess,
405: ng_ID_t *nodep, const char **hookp);
406:
407: /*
408: * Informs that hook has been connected and temporal tee can be shutted down.
409: */
410: extern void ppp_l2tp_sess_hooked(struct ppp_l2tp_sess *sess);
411:
412: __END_DECLS
413:
414: #endif /* _PPP_L2TP_PDEL_PPP_PPP_L2TP_CTRL_H_ */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>