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