Deleted Added
full compact
proto.c (218194) proto.c (219818)
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>
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 218194 2011-02-02 15:53:09Z pjd $");
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
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 *addr, struct proto_conn **connp, int side)
108proto_common_setup(const char *srcaddr, const char *dstaddr,
109 struct proto_conn **connp, int side)
109{
110 struct hast_proto *proto;
111 struct proto_conn *conn;
112 void *ctx;
113 int ret;
114
115 PJDLOG_ASSERT(side == PROTO_SIDE_CLIENT ||
116 side == PROTO_SIDE_SERVER_LISTEN);
117
118 TAILQ_FOREACH(proto, &protos, hp_next) {
119 if (side == PROTO_SIDE_CLIENT) {
120 if (proto->hp_client == NULL)
121 ret = -1;
122 else
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
123 ret = proto->hp_client(addr, &ctx);
124 ret = proto->hp_client(srcaddr, dstaddr, &ctx);
124 } else /* if (side == PROTO_SIDE_SERVER_LISTEN) */ {
125 if (proto->hp_server == NULL)
126 ret = -1;
127 else
125 } else /* if (side == PROTO_SIDE_SERVER_LISTEN) */ {
126 if (proto->hp_server == NULL)
127 ret = -1;
128 else
128 ret = proto->hp_server(addr, &ctx);
129 ret = proto->hp_server(dstaddr, &ctx);
129 }
130 /*
131 * ret == 0 - success
130 }
131 /*
132 * ret == 0 - success
132 * ret == -1 - addr is not for this protocol
133 * ret == -1 - dstaddr is not for this protocol
133 * ret > 0 - right protocol, but an error occured
134 */
135 if (ret >= 0)
136 break;
137 }
138 if (proto == NULL) {
139 /* Unrecognized address. */
140 errno = EINVAL;

--- 13 unchanged lines hidden (view full) ---

154 }
155 conn->pc_ctx = ctx;
156 *connp = conn;
157
158 return (0);
159}
160
161int
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
162proto_client(const char *addr, struct proto_conn **connp)
163proto_client(const char *srcaddr, const char *dstaddr,
164 struct proto_conn **connp)
163{
164
165{
166
165 return (proto_common_setup(addr, connp, PROTO_SIDE_CLIENT));
167 return (proto_common_setup(srcaddr, dstaddr, connp, PROTO_SIDE_CLIENT));
166}
167
168int
169proto_connect(struct proto_conn *conn, int timeout)
170{
171 int ret;
172
173 PJDLOG_ASSERT(conn != NULL);

--- 32 unchanged lines hidden (view full) ---

206
207 return (0);
208}
209
210int
211proto_server(const char *addr, struct proto_conn **connp)
212{
213
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
214 return (proto_common_setup(addr, connp, PROTO_SIDE_SERVER_LISTEN));
216 return (proto_common_setup(NULL, addr, connp, PROTO_SIDE_SERVER_LISTEN));
215}
216
217int
218proto_accept(struct proto_conn *conn, struct proto_conn **newconnp)
219{
220 struct proto_conn *newconn;
221 int ret;
222

--- 222 unchanged lines hidden ---
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 ---