1 /* $OpenBSD: transport.h,v 1.15 2004/06/20 15:24:05 ho 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 /* This describes a tranport "method" like UDP or similar.  */
51 struct transport_vtbl {
52 	/* All transport methods are linked together.  */
53 	LIST_ENTRY(transport_vtbl) link;
54 
55 	/* A textual name of the transport method.  */
56 	char           *name;
57 
58 	/* Create a transport instance of this method.  */
59 	struct transport *(*create) (char *);
60 
61 	/* Reinitialize specific transport.  */
62 	void            (*reinit) (void);
63 
64 	/* Remove a transport instance of this method.  */
65 	void            (*remove) (struct transport *);
66 
67 	/* Report status of given transport */
68 	void            (*report) (struct transport *);
69 
70 	/* Let the given transport set it's bit in the fd_set passed in.  */
71 	int             (*fd_set) (struct transport *, fd_set *, int);
72 
73 	/* Is the given transport ready for I/O?  */
74 	int             (*fd_isset) (struct transport *, fd_set *);
75 
76 	/*
77 	 * Read a message from the transport's incoming pipe and start
78 	 * handling it.
79          */
80 	void            (*handle_message) (struct transport *);
81 
82 	/* Send a message through the outgoing pipe.  */
83 	int             (*send_message) (struct message *, struct transport *);
84 
85 	/*
86 	 * Fill out a sockaddr structure with the transport's destination end's
87 	 * address info.
88          */
89 	void            (*get_dst) (struct transport *, struct sockaddr **);
90 
91 	/*
92 	 * Fill out a sockaddr structure with the transport's source end's
93 	 * address info.
94          */
95 	void            (*get_src) (struct transport *, struct sockaddr **);
96 
97 	/*
98 	 * Return a string with decoded src and dst information
99          */
100 	char           *(*decode_ids) (struct transport *);
101 
102 	/*
103 	 * Clone a transport for outbound use.
104 	 */
105 	struct transport *(*clone) (struct transport *, struct sockaddr *);
106 
107 	/*
108 	 * Locate the correct sendq to use for outbound messages.
109 	 */
110 	struct msg_head *(*get_queue) (struct message *);
111 };
112 
113 struct transport {
114 	/* All transports used are linked together.  */
115 	LIST_ENTRY(transport) link;
116 
117 	/* What transport method is this an instance of?  */
118 	struct transport_vtbl *vtbl;
119 
120 	/* The queue holding messages to send on this transport.  */
121 	struct msg_head sendq;
122 
123 	/*
124 	 * Prioritized send queue.  Messages in this queue will be transmitted
125 	 * before the normal sendq, they will also all be transmitted prior
126 	 * to a daemon shutdown.  Currently only used for DELETE notifications.
127          */
128 	struct msg_head prio_sendq;
129 
130 	/* Flags describing the transport.  */
131 	int             flags;
132 
133 	/* Reference counter.  */
134 	int             refcnt;
135 
136 	/* Pointer to parent virtual transport, if any.  */
137 	struct transport *virtual;
138 };
139 
140 /* Set if this is a transport we want to listen on.  */
141 #define TRANSPORT_LISTEN	1
142 /* Used for mark-and-sweep-type garbage collection of transports */
143 #define TRANSPORT_MARK		2
144 
145 extern struct transport *transport_create(char *, char *);
146 extern int      transport_fd_set(fd_set *);
147 extern void     transport_handle_messages(fd_set *);
148 extern void     transport_init(void);
149 extern void     transport_map(void (*) (struct transport *));
150 extern void     transport_method_add(struct transport_vtbl *);
151 extern int      transport_pending_wfd_set(fd_set *);
152 extern int      transport_prio_sendqs_empty(void);
153 extern void     transport_reference(struct transport *);
154 extern void     transport_reinit(void);
155 extern void     transport_release(struct transport *);
156 extern void     transport_report(void);
157 extern void     transport_send_messages(fd_set *);
158 extern void     transport_setup(struct transport *, int);
159 #endif				/* _TRANSPORT_H_ */
160