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