xref: /openbsd/sbin/isakmpd/transport.h (revision a6445c1d)
1 /* $OpenBSD: transport.h,v 1.18 2006/06/02 19:35:55 hshoexer Exp $	 */
2 /* $EOM: transport.h,v 1.16 2000/07/17 18:57:59 provos Exp $	 */
3 
4 /*
5  * Copyright (c) 1998, 1999 Niklas Hallqvist.  All rights reserved.
6  * Copyright (c) 2001, 2004 H�kan Olsson.  All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 /*
30  * This code was written under funding by Ericsson Radio Systems.
31  */
32 
33 /*
34  * The transport module tries to separate out details concerning the
35  * actual transferral of ISAKMP messages to other parties.
36  */
37 
38 #ifndef _TRANSPORT_H_
39 #define _TRANSPORT_H_
40 
41 #include <sys/param.h>
42 #include <sys/queue.h>
43 #include <sys/types.h>
44 #include <sys/socket.h>
45 
46 #include "message.h"
47 
48 struct transport;
49 
50 LIST_HEAD(transport_list, transport) transport_list;
51 
52 /* This describes a transport "method" like UDP or similar.  */
53 struct transport_vtbl {
54 	/* All transport methods are linked together.  */
55 	LIST_ENTRY(transport_vtbl) link;
56 
57 	/* A textual name of the transport method.  */
58 	char           *name;
59 
60 	/* Create a transport instance of this method.  */
61 	struct transport *(*create) (char *);
62 
63 	/* Reinitialize specific transport.  */
64 	void            (*reinit) (void);
65 
66 	/* Remove a transport instance of this method.  */
67 	void            (*remove) (struct transport *);
68 
69 	/* Report status of given transport */
70 	void            (*report) (struct transport *);
71 
72 	/* Let the given transport set it's bit in the fd_set passed in.  */
73 	int             (*fd_set) (struct transport *, fd_set *, int);
74 
75 	/* Is the given transport ready for I/O?  */
76 	int             (*fd_isset) (struct transport *, fd_set *);
77 
78 	/*
79 	 * Read a message from the transport's incoming pipe and start
80 	 * handling it.
81          */
82 	void            (*handle_message) (struct transport *);
83 
84 	/* Send a message through the outgoing pipe.  */
85 	int             (*send_message) (struct message *, struct transport *);
86 
87 	/*
88 	 * Fill out a sockaddr structure with the transport's destination end's
89 	 * address info.
90          */
91 	void            (*get_dst) (struct transport *, struct sockaddr **);
92 
93 	/*
94 	 * Fill out a sockaddr structure with the transport's source end's
95 	 * address info.
96          */
97 	void            (*get_src) (struct transport *, struct sockaddr **);
98 
99 	/*
100 	 * Return a string with decoded src and dst information
101          */
102 	char           *(*decode_ids) (struct transport *);
103 
104 	/*
105 	 * Clone a transport for outbound use.
106 	 */
107 	struct transport *(*clone) (struct transport *, struct sockaddr *);
108 
109 	/*
110 	 * Locate the correct sendq to use for outbound messages.
111 	 */
112 	struct msg_head *(*get_queue) (struct message *);
113 };
114 
115 struct transport {
116 	/* All transports used are linked together.  */
117 	LIST_ENTRY(transport) link;
118 
119 	/* What transport method is this an instance of?  */
120 	struct transport_vtbl *vtbl;
121 
122 	/* The queue holding messages to send on this transport.  */
123 	struct msg_head sendq;
124 
125 	/*
126 	 * Prioritized send queue.  Messages in this queue will be transmitted
127 	 * before the normal sendq, they will also all be transmitted prior
128 	 * to a daemon shutdown.  Currently only used for DELETE notifications.
129          */
130 	struct msg_head prio_sendq;
131 
132 	/* Flags describing the transport.  */
133 	int             flags;
134 
135 	/* Reference counter.  */
136 	int             refcnt;
137 
138 	/* Pointer to parent virtual transport, if any.  */
139 	struct transport *virtual;
140 };
141 
142 /* Set if this is a transport we want to listen on.  */
143 #define TRANSPORT_LISTEN	1
144 /* Used for mark-and-sweep-type garbage collection of transports */
145 #define TRANSPORT_MARK		2
146 
147 extern struct transport *transport_create(char *, char *);
148 extern int      transport_fd_set(fd_set *);
149 extern void     transport_handle_messages(fd_set *);
150 extern void     transport_init(void);
151 extern void     transport_method_add(struct transport_vtbl *);
152 extern int      transport_pending_wfd_set(fd_set *);
153 extern int      transport_prio_sendqs_empty(void);
154 extern void     transport_reference(struct transport *);
155 extern void     transport_reinit(void);
156 extern void     transport_release(struct transport *);
157 extern void     transport_report(void);
158 extern void     transport_send_messages(fd_set *);
159 extern void     transport_setup(struct transport *, int);
160 #endif				/* _TRANSPORT_H_ */
161