1/*- 2 * Copyright (c) 2009-2010 The FreeBSD Foundation 3 * All rights reserved. 4 * 5 * This software was developed by Pawel Jakub Dawidek under sponsorship from 6 * the FreeBSD Foundation. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 14 unchanged lines hidden (view full) --- 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30#include <sys/cdefs.h> |
31__FBSDID("$FreeBSD: head/sbin/hastd/proto.c 219818 2011-03-21 08:54:59Z pjd $"); |
32 33#include <sys/types.h> 34#include <sys/queue.h> 35#include <sys/socket.h> 36 37#include <errno.h> 38#include <stdint.h> 39#include <string.h> --- 60 unchanged lines hidden (view full) --- 100 conn->pc_side == PROTO_SIDE_SERVER_WORK); 101 PJDLOG_ASSERT(conn->pc_proto != NULL); 102 103 bzero(conn, sizeof(*conn)); 104 free(conn); 105} 106 107static int |
108proto_common_setup(const char *srcaddr, const char *dstaddr, 109 struct proto_conn **connp, int side) |
110{ 111 struct hast_proto *proto; 112 struct proto_conn *conn; 113 void *ctx; 114 int ret; 115 116 PJDLOG_ASSERT(side == PROTO_SIDE_CLIENT || 117 side == PROTO_SIDE_SERVER_LISTEN); 118 119 TAILQ_FOREACH(proto, &protos, hp_next) { 120 if (side == PROTO_SIDE_CLIENT) { 121 if (proto->hp_client == NULL) 122 ret = -1; 123 else |
124 ret = proto->hp_client(srcaddr, dstaddr, &ctx); |
125 } else /* if (side == PROTO_SIDE_SERVER_LISTEN) */ { 126 if (proto->hp_server == NULL) 127 ret = -1; 128 else |
129 ret = proto->hp_server(dstaddr, &ctx); |
130 } 131 /* 132 * ret == 0 - success |
133 * ret == -1 - dstaddr is not for this protocol |
134 * ret > 0 - right protocol, but an error occured 135 */ 136 if (ret >= 0) 137 break; 138 } 139 if (proto == NULL) { 140 /* Unrecognized address. */ 141 errno = EINVAL; --- 13 unchanged lines hidden (view full) --- 155 } 156 conn->pc_ctx = ctx; 157 *connp = conn; 158 159 return (0); 160} 161 162int |
163proto_client(const char *srcaddr, const char *dstaddr, 164 struct proto_conn **connp) |
165{ 166 |
167 return (proto_common_setup(srcaddr, dstaddr, connp, PROTO_SIDE_CLIENT)); |
168} 169 170int 171proto_connect(struct proto_conn *conn, int timeout) 172{ 173 int ret; 174 175 PJDLOG_ASSERT(conn != NULL); --- 32 unchanged lines hidden (view full) --- 208 209 return (0); 210} 211 212int 213proto_server(const char *addr, struct proto_conn **connp) 214{ 215 |
216 return (proto_common_setup(NULL, addr, connp, PROTO_SIDE_SERVER_LISTEN)); |
217} 218 219int 220proto_accept(struct proto_conn *conn, struct proto_conn **newconnp) 221{ 222 struct proto_conn *newconn; 223 int ret; 224 --- 222 unchanged lines hidden --- |