1204076Spjd/*-
2330449Seadler * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3330449Seadler *
4204076Spjd * Copyright (c) 2009-2010 The FreeBSD Foundation
5204076Spjd * All rights reserved.
6204076Spjd *
7204076Spjd * This software was developed by Pawel Jakub Dawidek under sponsorship from
8204076Spjd * the FreeBSD Foundation.
9204076Spjd *
10204076Spjd * Redistribution and use in source and binary forms, with or without
11204076Spjd * modification, are permitted provided that the following conditions
12204076Spjd * are met:
13204076Spjd * 1. Redistributions of source code must retain the above copyright
14204076Spjd *    notice, this list of conditions and the following disclaimer.
15204076Spjd * 2. Redistributions in binary form must reproduce the above copyright
16204076Spjd *    notice, this list of conditions and the following disclaimer in the
17204076Spjd *    documentation and/or other materials provided with the distribution.
18204076Spjd *
19204076Spjd * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
20204076Spjd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21204076Spjd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22204076Spjd * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
23204076Spjd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24204076Spjd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25204076Spjd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26204076Spjd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27204076Spjd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28204076Spjd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29204076Spjd * SUCH DAMAGE.
30204076Spjd *
31204076Spjd * $FreeBSD: stable/11/sbin/hastd/proto_impl.h 330449 2018-03-05 07:26:05Z eadler $
32204076Spjd */
33204076Spjd
34204076Spjd#ifndef	_PROTO_IMPL_H_
35204076Spjd#define	_PROTO_IMPL_H_
36204076Spjd
37204076Spjd#include <sys/queue.h>
38204076Spjd
39204076Spjd#include <stdbool.h>	/* bool */
40204076Spjd#include <stdlib.h>	/* size_t */
41204076Spjd
42204076Spjd#define	__constructor	__attribute__((constructor))
43204076Spjd
44219873Spjdtypedef int prt_client_t(const char *, const char *, void **);
45219873Spjdtypedef int prt_connect_t(void *, int);
46219873Spjdtypedef int prt_connect_wait_t(void *, int);
47219873Spjdtypedef int prt_server_t(const char *, void **);
48219873Spjdtypedef int prt_accept_t(void *, void **);
49219873Spjdtypedef int prt_wrap_t(int, bool, void **);
50219873Spjdtypedef int prt_send_t(void *, const unsigned char *, size_t, int);
51219873Spjdtypedef int prt_recv_t(void *, unsigned char *, size_t, int *);
52219873Spjdtypedef int prt_descriptor_t(const void *);
53219873Spjdtypedef bool prt_address_match_t(const void *, const char *);
54219873Spjdtypedef void prt_local_address_t(const void *, char *, size_t);
55219873Spjdtypedef void prt_remote_address_t(const void *, char *, size_t);
56219873Spjdtypedef void prt_close_t(void *);
57204076Spjd
58219873Spjdstruct proto {
59219873Spjd	const char		*prt_name;
60219873Spjd	prt_client_t		*prt_client;
61219873Spjd	prt_connect_t		*prt_connect;
62219873Spjd	prt_connect_wait_t	*prt_connect_wait;
63219873Spjd	prt_server_t		*prt_server;
64219873Spjd	prt_accept_t		*prt_accept;
65219873Spjd	prt_wrap_t		*prt_wrap;
66219873Spjd	prt_send_t		*prt_send;
67219873Spjd	prt_recv_t		*prt_recv;
68219873Spjd	prt_descriptor_t	*prt_descriptor;
69219873Spjd	prt_address_match_t	*prt_address_match;
70219873Spjd	prt_local_address_t	*prt_local_address;
71219873Spjd	prt_remote_address_t	*prt_remote_address;
72219873Spjd	prt_close_t		*prt_close;
73219873Spjd	TAILQ_ENTRY(proto)	 prt_next;
74204076Spjd};
75204076Spjd
76219873Spjdvoid proto_register(struct proto *proto, bool isdefault);
77204076Spjd
78218194Spjdint proto_common_send(int sock, const unsigned char *data, size_t size, int fd);
79218194Spjdint proto_common_recv(int sock, unsigned char *data, size_t size, int *fdp);
80204076Spjd
81204076Spjd#endif	/* !_PROTO_IMPL_H_ */
82